-
Notifications
You must be signed in to change notification settings - Fork 11
/
local.py
executable file
·74 lines (69 loc) · 2.33 KB
/
local.py
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/usr/bin/python
import socket, sys, select, threading, socks, config
from toolkit import *
class ProxyThread(threading.Thread):
def set_socks(self, client_sock, server_sock):
self.server_sock = server_sock
self.client_sock = client_sock
def run(self):
while True:
end = False
try:
socks = select.select([self.client_sock, self.server_sock], [], [], 3)[0]
except:
end = True
else:
for sock in socks:
try:
data = sock.recv(1024)
except:
end = True
else:
if not data:
end = True
else:
try:
if sock is self.client_sock:
self.server_sock.sendall(xor(data))
else:
self.client_sock.sendall(xor(data))
except:
end = True
if end:
try:
self.clien_sock.close()
except:
pass
try:
self.server_sock.close()
except:
pass
break
try:
servsock = socket.socket()
servsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
servsock.bind(config.local_bind_addr)
servsock.listen(1000)
print "--> " + "%s:%s" % config.local_bind_addr + " --> " + "%s:%s" % config.server_proxy_addr + " -->"
while True:
while True:
try:
sock = None
sock = select.select([servsock], [], [], 3)[0]
except KeyboardInterrupt:
raise
except:
raise
else:
if sock:
break
client_sock, client_addr = servsock.accept()
# socks_ret = socks.accept(client_sock)
server_sock = socket.socket()
server_sock.connect(config.server_proxy_addr)
proxy = ProxyThread()
proxy.daemon = True
proxy.set_socks(client_sock, server_sock)
proxy.start()
except KeyboardInterrupt:
print