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

既然有些技术是基于协议识别的和DPI的,为什么不自己创造一种VPN协议呢?

一个及其简单的原型,需要配合squid和国外VPS使用,欢迎来信索取使用方式。


#!/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())

《每个人都应该有属于自己的VPN协议》上有8条评论

发表评论

电子邮件地址不会被公开。 必填项已用*标注