Pages

Thursday, 30 July 2015

每个人都应该有属于自己的VPN协议

既然有些技术是基于协议识别的和DPI的,为什么不自己创造一种VPN协议呢?
一个及其简单的原型,需要配合squid和国外VPS使用,欢迎来信索取使用方式。

01
02
03
04
05
06
07
08
09
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#!/usr/bin/env python
import sys
import socket
import threading
import time
help_msg ="""
Info:
pysectunnel forwards encrypted data from local_port to sink_port on sink_host.
Usage:
pysectunnel local_port sink_host sink_port
"""
LOGGING=0
LOG_LEVEL=1
def log(log_level, log_str):
if LOGGING:
if log_level <= LOG_LEVEL:
print '%s:%s' % (time.ctime(), log_str)
sys.stdout.flush()
def encrypt_data(data):
encrypted_data=[]
for i in range(len(data)):
encrypted_data.append( chr(ord(data[i]) ^ 0x17) )
return ''.join(encrypted_data)
class TunnelThread(threading.Thread):
def __init__(self, local_sc, sink_sc, encrypt_enable):
threading.Thread.__init__(self)
self.local_sc = local_sc
self.sink_sc = sink_sc
log(1, 'Creating new tunnel thread %s ( %s -> %s )' % ( self,self.local_sc.getpeername(), self.sink_sc.getpeername() ) )
def run(self):
while True:
try:
data = self.local_sc.recv(1024)
if not data:
break
encrypted_data = encrypt_data(data)
self.sink_sc.sendall(encrypted_data)
except:
break
log(1, 'Terminating tunnel thread %s' % self)
class TunnelManager:
def __init__(self, local_port, sink_host, sink_port):
self.local_port = int(local_port)
self.sink_host = sink_host
self.sink_port = int(sink_port)
print 'Initializing PySecTunnel...'
def work(self):
print 'PySecTunnel working...'
manager_sc = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
manager_sc.bind(('0.0.0.0', self.local_port))
manager_sc.listen(5)
while True:
local_sc, address = manager_sc.accept()
print 'Accepted connection from %s:%s' % address
sink_sc = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
try:
sink_sc.connect( ( self.sink_host, self.sink_port ) )
log (1, 'Creating new tunnel thread %s ( %s -> %s )' % (self, local_sc.getpeername(), sink_sc.getpeername() ) )
except:
log(0, 'Error connecting')
TunnelThread( local_sc, sink_sc, 0 ).start()
TunnelThread( sink_sc, local_sc, 1 ).start()
def main():
if len(sys.argv) != 4:
print help_msg
return 1
local_port = sys.argv[1]
sink_host = sys.argv[2]
sink_port = sys.argv[3]
tunnel_manager = TunnelManager(local_port, sink_host, sink_port)
tunnel_manager.work()
return 0
if __name__=='__main__':
sys.exit(main())
原文http://strongbaby.me/papa/?p=215
--------------------------------------------------------
本地:python 111.py 本地代理端口 vps地址 9999
服务器:python 111.py 9999 localhost 3128
加密:异或0×17
不知是否有理解错?