Port Forwarding
To continue the security talks I decided to show you all how to create unpartisan port forwarded. This daemon will allow eleven constant active connections. Just make sure that your destination is able to interrupt the data properly. Also, I should note that you should use this via spawning a new process and kill it by killing the process id, PID. This is the best way. If you are a windows muchacho, then I am not sure how to help you :/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | #!/usr/bin/env python # # all modules in the stdlib # import socket import sys import thread def main(setup, error): sys.stderr = file(error, 'a') for settings in parse(setup): thread.start_new_thread(server, settings) lock = thread.allocate_lock() lock.acquire() lock.acquire() def parse(setup): settings = list() for line in file(setup): parts = line.split() settings.append((parts[0], int(parts[1]), int(parts[2]))) return settings def server(*settings): try: dock_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) dock_socket.bind(('', settings[2])) dock_socket.listen(5) while True: client_socket = dock_socket.accept()[0] server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) server_socket.connect((settings[0], settings[1])) thread.start_new_thread(forward, (client_socket, server_socket)) thread.start_new_thread(forward, (server_socket, client_socket)) finally: thread.start_new_thread(server, settings) def forward(source, destination): string = ' ' while string: string = source.recv(1024) if string: destination.sendall(string) else: source.shutdown(socket.SHUT_RD) destination.shutdown(socket.SHUT_WR) if __name__ == '__main__': main('proxy.cfg', 'error.log') |



you bohbah!