Skip to content

Instantly share code, notes, and snippets.

@Mic92
Created July 29, 2015 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 Mic92/5ef08e8d535d42a13360 to your computer and use it in GitHub Desktop.
Save Mic92/5ef08e8d535d42a13360 to your computer and use it in GitHub Desktop.
from libmproxy.protocol.http import decoded
import socket
import select
import threading
TCP_IP = '127.0.0.1'
TCP_PORT = 10000
BUFFER_SIZE = 1024
listen = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen.bind((TCP_IP, TCP_PORT))
listen.listen(1)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((TCP_IP, TCP_PORT))
def process():
while True:
try:
select.select([listen], [listen], [])
conn, addr = listen.accept()
while True:
data = conn.recv(BUFFER_SIZE)
if not data: break
except:
pass
t = threading.Thread(target=process)
t.start()
def response(context, flow):
if flow.response.headers.get_first("content-type", "").startswith("image"):
with decoded(flow.response):
try:
s.send(flow.response.content)
except:
s.connect((TCP_IP, TCP_PORT))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment