> For the complete documentation index, see [llms.txt](https://riteshs4hu.gitbook.io/infosec-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://riteshs4hu.gitbook.io/infosec-notes/internal-and-external-network-sec/privilege-escalation/file-transfer-method/https-server.md).

# HTTPS Server

### HTTPS Server (Python + OpenSSL)

### Generate SSL Certificate and Key

```bash
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes
```

***

### Python HTTPS Server Script

```python
# https_server.py

import http.server
import socketserver
import ssl

PORT = 443
CERT_FILE = 'cert.pem'
KEY_FILE = 'key.pem'

ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
ssl_context.load_cert_chain(certfile=CERT_FILE, keyfile=KEY_FILE)

class MyRequestHandler(http.server.SimpleHTTPRequestHandler):
    def do_GET(self):
        super().do_GET()

with socketserver.TCPServer(('', PORT), MyRequestHandler) as httpd:
    httpd.socket = ssl_context.wrap_socket(httpd.socket, server_side=True)
    print(f'Serving on port {PORT} with HTTPS')
    httpd.serve_forever()
```

### Start Server

```bash
sudo python3 https_server.py
```
