Simple TCP tunnel/fuzzer (last update: 2016-12-04, created: 2013-07-10) back to the list ↑
Because sometimes even my silkproxy is an overkill :)


#!/usr/bin/python
import threading
import socket
import random

class ThreadClass(threading.Thread):

  def __init__(self, s_src, s_dst, fuzz=False, thread_desc=""):
    threading.Thread.__init__(self)
    self.s_src = s_src
    self.s_dst = s_dst
    self.fuzz = fuzz
    self.thread_desc = thread_desc

  def run(self):
    print "%s: init" % self.thread_desc
    while True:
      d = self.s_src.recv(1024 * 1024)
      print "%s: recv->sending %u data" % (self.thread_desc, len(d))
      if not d:
        print "%s: exiting" % self.thread_desc
        break

      if self.fuzz and random.randint(0, 10) == 5:
        bit = random.choice([1,2,4,8,16,32,64,128])
        ridx = random.randint(0, len(d) - 1)
        print "%s: flipbitting bit %.2x at %x " % (self.thread_desc, bit, ridx)
        d = d[:ridx] + chr(ord(d[ridx]) ^ bit) + d[ridx+1:]

      self.s_dst.sendall(d)
    self.s_dst.close()
    self.s_src.close()

THIS IS THE PLACE YOU FILL OUT
TUNNEL = ("127.0.0.1", 33333)
DST    = ("127.0.0.1", 33332)
---

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(TUNNEL)
s.listen(1)
while True:
  s_src, s_src_addr = s.accept()
  print 'Connected by', s_src_addr

  s_dst = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  s_dst.connect(DST)  

YOU MIGHT WANT TO CHANGE True/False SETTINGS HERE
  ThreadClass(s_src, s_dst, True, "src->dst").start()
  ThreadClass(s_dst, s_src, False, "dst->src").start()
---


Tested on 2.6 or 2.7, something like that.
【 design & art by Xa / Gynvael Coldwind 】 【 logo font (birdman regular) by utopiafonts / Dale Harris 】