Set Up a Local HTTPS Server
In this step, we will set up a simple HTTPS server using Python's built-in http.server
module with SSL/TLS enabled. This will allow us to simulate a secure server environment for testing Hydra's SSL capabilities.
First, we need to generate a self-signed certificate and key. This certificate will be used to encrypt the communication between the client (Hydra) and the server. Open your terminal and navigate to the ~/project
directory:
cd ~/project
Now, use the openssl
command to generate the certificate and key:
openssl req -new -x509 -keyout key.pem -out cert.pem -days 365 -nodes
You will be prompted to enter some information about the certificate. You can leave most of the fields blank by pressing Enter. A common name is required, you can enter localhost
.
Generating a RSA private key
+++++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [AU]:
State or Province Name (full name) [Some-State]:
Locality Name (eg, city) []:
Organization Name (eg, company) [Internet Widgits Pty Ltd]:
Organizational Unit Name (eg, section) []:
Common Name (e.g. server FQDN or YOUR name) []:localhost
Email Address []:
This command creates two files: key.pem
(the private key) and cert.pem
(the certificate).
Now, let's create a Python script for our HTTPS server. We'll use the nano
text editor to create and edit the script:
nano https_server.py
Copy and paste the following code into the editor:
import http.server
import ssl
import os
## Create the HTTP server
httpd = http.server.HTTPServer(('127.0.0.1', 443), http.server.SimpleHTTPRequestHandler)
## Create SSL context
ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile='cert.pem', keyfile='key.pem')
## Wrap the socket with SSL
httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)
print("Serving HTTPS on 127.0.0.1 port 443 (https://127.0.0.1:443/) ...")
httpd.serve_forever()
To save the file in nano:
- Press
Ctrl + X
to exit
- Press
Y
to confirm saving
- Press
Enter
to confirm the filename
Now you can run the HTTPS server using:
python3 https_server.py
You should see output similar to:
Serving HTTPS on 127.0.0.1 port 443 (https://127.0.0.1:443/) ...
Leave this terminal window running. This is your HTTPS server. In the next steps, we will use Hydra to attempt to crack the authentication.
IMPORTANT: Remember to keep the original terminal window running with the HTTPS server. Do not close it, as we'll need it for the next steps.