mirror of https://github.com/dnomd343/ProxyC
Dnomd343
3 years ago
8 changed files with 388 additions and 277 deletions
@ -0,0 +1,163 @@ |
|||||
|
#!/usr/bin/python |
||||
|
# -*- coding:utf-8 -*- |
||||
|
|
||||
|
logLevel = 'warning' |
||||
|
|
||||
|
httpHeader = { |
||||
|
'type': 'http', |
||||
|
'request': { |
||||
|
'version': '1.1', |
||||
|
'method': 'GET', |
||||
|
'path': [], |
||||
|
'headers': { |
||||
|
'Host': [], |
||||
|
'User-Agent': [ |
||||
|
'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.75 Safari/537.36', |
||||
|
'Mozilla/5.0 (iPhone; CPU iPhone OS 10_0_2 like Mac OS X) AppleWebKit/601.1 (KHTML, like Gecko) CriOS/53.0.2785.109 Mobile/14A456 Safari/601.1.46' |
||||
|
], |
||||
|
'Accept-Encoding': [ |
||||
|
'gzip, deflate' |
||||
|
], |
||||
|
'Connection': [ |
||||
|
'keep-alive' |
||||
|
], |
||||
|
'Pragma': 'no-cache' |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
kcpSettings = { |
||||
|
'mtu': 1350, |
||||
|
'tti': 50, |
||||
|
'uplinkCapacity': 12, |
||||
|
'downlinkCapacity': 100, |
||||
|
'congestion': False, |
||||
|
'readBufferSize': 2, |
||||
|
'writeBufferSize': 2, |
||||
|
'header': {} |
||||
|
} |
||||
|
|
||||
|
def __secureConfig(secureInfo: dict or None) -> dict: # TLS加密传输配置 |
||||
|
if secureInfo is None: |
||||
|
return {} |
||||
|
tlsObject = { |
||||
|
'allowInsecure': not secureInfo['verify'], |
||||
|
'alpn': secureInfo['alpn'].split(',') |
||||
|
} |
||||
|
if secureInfo['sni'] != '': |
||||
|
tlsObject['serverName'] = secureInfo['sni'] |
||||
|
return { |
||||
|
'security': 'tls', |
||||
|
'tlsSettings': tlsObject |
||||
|
} |
||||
|
|
||||
|
def tcpConfig(streamInfo: dict, secureFunc) -> dict: # TCP传输方式配置 |
||||
|
tcpObject = {} |
||||
|
if streamInfo['obfs'] is not None: |
||||
|
httpHeader['request']['path'].append(streamInfo['obfs']['path']) |
||||
|
httpHeader['request']['headers']['Host'] = streamInfo['obfs']['host'].split(',') |
||||
|
tcpObject['header'] = httpHeader |
||||
|
return {**{ |
||||
|
'network': 'tcp', |
||||
|
'tcpSettings': tcpObject |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def kcpConfig(streamInfo: dict, secureFunc) -> dict: # mKCP传输方式配置 |
||||
|
kcpObject = kcpSettings |
||||
|
kcpObject['header']['type'] = streamInfo['obfs'] |
||||
|
if streamInfo['seed'] is not None: |
||||
|
kcpObject['seed'] = streamInfo['seed'] |
||||
|
return {**{ |
||||
|
'network': 'kcp', |
||||
|
'kcpSettings': kcpObject |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def wsConfig(streamInfo: dict, edInPath: bool, secureFunc) -> dict: # WebSocket传输方式配置 |
||||
|
wsObject = { |
||||
|
'path': streamInfo['path'] |
||||
|
} |
||||
|
if streamInfo['host'] != '': |
||||
|
wsObject['headers'] = {} |
||||
|
wsObject['headers']['Host'] = streamInfo['host'] |
||||
|
if streamInfo['ed'] is not None: |
||||
|
if not edInPath: |
||||
|
wsObject['maxEarlyData'] = streamInfo['ed'] |
||||
|
wsObject['earlyDataHeaderName'] = 'Sec-WebSocket-Protocol' |
||||
|
else: # ed参数写入路径 -> /...?ed=xxx |
||||
|
if wsObject['path'].find('?') == -1: # 原路径不带参数 |
||||
|
wsObject['path'] += '?ed=' + str(streamInfo['ed']) |
||||
|
else: |
||||
|
wsObject['path'] += '&ed=' + str(streamInfo['ed']) |
||||
|
return {**{ |
||||
|
'network': 'ws', |
||||
|
'wsSettings': wsObject |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def h2Config(streamInfo: dict, secureFunc) -> dict: # HTTP/2传输方式配置 |
||||
|
h2Object = { |
||||
|
'path': streamInfo['path'] |
||||
|
} |
||||
|
if streamInfo['host'] != '': |
||||
|
h2Object['host'] = streamInfo['host'].split(',') |
||||
|
return {**{ |
||||
|
'network': 'h2', |
||||
|
'httpSettings': h2Object |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def quicConfig(streamInfo: dict, secureFunc) -> dict: # QUIC传输方式配置 |
||||
|
return {**{ |
||||
|
'network': 'quic', |
||||
|
'quicSettings': { |
||||
|
'security': streamInfo['method'], |
||||
|
'key': streamInfo['passwd'], |
||||
|
'header': { |
||||
|
'type': streamInfo['obfs'] |
||||
|
} |
||||
|
} |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def grpcConfig(streamInfo: dict, secureFunc) -> dict: # gRPC传输方式配置 |
||||
|
return {**{ |
||||
|
'network': 'grpc', |
||||
|
'grpcSettings': { |
||||
|
'serviceName': streamInfo['service'] |
||||
|
} |
||||
|
}, **secureFunc(streamInfo['secure'])} |
||||
|
|
||||
|
def v2rayStreamConfig(streamInfo: dict) -> dict: # 生成v2ray传输方式配置 |
||||
|
streamType = streamInfo['type'] |
||||
|
if streamType == 'tcp': |
||||
|
return tcpConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'kcp': |
||||
|
return kcpConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'ws': |
||||
|
return wsConfig(streamInfo, False, __secureConfig) |
||||
|
elif streamType == 'h2': |
||||
|
return h2Config(streamInfo, __secureConfig) |
||||
|
elif streamType == 'quic': |
||||
|
return quicConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'grpc': |
||||
|
return grpcConfig(streamInfo, __secureConfig) |
||||
|
else: |
||||
|
raise Exception('Unknown stream type') |
||||
|
|
||||
|
def baseConfig(socksPort: int, outboundObject: dict) -> dict: # 基础配置生成 |
||||
|
return { |
||||
|
'log': { |
||||
|
'loglevel': logLevel |
||||
|
}, |
||||
|
'inbounds': [ |
||||
|
{ |
||||
|
'port': socksPort, |
||||
|
'listen': '127.0.0.1', |
||||
|
'protocol': 'socks', |
||||
|
'settings': { |
||||
|
'udp': True, |
||||
|
'auth': 'noauth' |
||||
|
} |
||||
|
} |
||||
|
], |
||||
|
'outbounds': [ |
||||
|
outboundObject |
||||
|
] |
||||
|
} |
@ -0,0 +1,46 @@ |
|||||
|
#!/usr/bin/python |
||||
|
# -*- coding:utf-8 -*- |
||||
|
|
||||
|
import json |
||||
|
from ProxyBuilder import Xray |
||||
|
|
||||
|
def load(proxyInfo: dict, socksPort: int, configFile: str) -> tuple[list, str, dict]: |
||||
|
""" |
||||
|
VLESS配置载入 |
||||
|
proxyInfo: 节点信息 |
||||
|
socksPort: 本地通讯端口 |
||||
|
configFile: 配置文件路径 |
||||
|
|
||||
|
return startCommand, fileContent, envVar |
||||
|
""" |
||||
|
user = { |
||||
|
'id': proxyInfo['id'], |
||||
|
'encryption': proxyInfo['method'] |
||||
|
} |
||||
|
if proxyInfo['stream']['secure'] is not None and proxyInfo['stream']['secure']['type'] == 'xtls': |
||||
|
flowType = proxyInfo['stream']['secure']['flow'] |
||||
|
if flowType == 'xtls-origin': |
||||
|
user['flow'] = 'xtls-rprx-origin' |
||||
|
elif flowType == 'xtls-direct': |
||||
|
user['flow'] = 'xtls-rprx-direct' |
||||
|
elif flowType == 'xtls-splice': |
||||
|
user['flow'] = 'xtls-rprx-splice' |
||||
|
else: |
||||
|
raise Exception('Unknown XTLS flow') |
||||
|
if proxyInfo['stream']['secure']['udp443']: |
||||
|
user['flow'] += '-udp443' |
||||
|
outboundConfig = { |
||||
|
'protocol': 'vless', |
||||
|
'settings': { |
||||
|
'vnext': [ |
||||
|
{ |
||||
|
'address': proxyInfo['server'], |
||||
|
'port': proxyInfo['port'], |
||||
|
'users': [user] |
||||
|
} |
||||
|
] |
||||
|
}, |
||||
|
'streamSettings': Xray.xrayStreamConfig(proxyInfo['stream']) |
||||
|
} |
||||
|
config = Xray.baseConfig(socksPort, outboundConfig) # VLESS节点配置 |
||||
|
return ['xray', '-c', configFile], json.dumps(config), {} |
@ -0,0 +1,45 @@ |
|||||
|
#!/usr/bin/python |
||||
|
# -*- coding:utf-8 -*- |
||||
|
|
||||
|
from ProxyBuilder import V2ray |
||||
|
|
||||
|
baseConfig = V2ray.baseConfig |
||||
|
|
||||
|
def __secureConfig(secureInfo: dict or None) -> dict: # TLS/XTLS加密传输配置 |
||||
|
if secureInfo is None: |
||||
|
return {} |
||||
|
secureObject = { |
||||
|
'allowInsecure': not secureInfo['verify'], |
||||
|
'alpn': secureInfo['alpn'].split(',') |
||||
|
} |
||||
|
if secureInfo['sni'] != '': |
||||
|
secureObject['serverName'] = secureInfo['sni'] |
||||
|
if secureInfo['type'] == 'tls': |
||||
|
return { |
||||
|
'security': 'tls', |
||||
|
'tlsSettings': secureObject |
||||
|
} |
||||
|
elif secureInfo['type'] == 'xtls': |
||||
|
return { |
||||
|
'security': 'xtls', |
||||
|
'xtlsSettings': secureObject |
||||
|
} |
||||
|
else: |
||||
|
raise Exception('Unknown secure type') |
||||
|
|
||||
|
def xrayStreamConfig(streamInfo: dict) -> dict: # 生成xray传输方式配置 |
||||
|
streamType = streamInfo['type'] |
||||
|
if streamType == 'tcp': |
||||
|
return V2ray.tcpConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'kcp': |
||||
|
return V2ray.kcpConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'ws': |
||||
|
return V2ray.wsConfig(streamInfo, True, __secureConfig) |
||||
|
elif streamType == 'h2': |
||||
|
return V2ray.h2Config(streamInfo, __secureConfig) |
||||
|
elif streamType == 'quic': |
||||
|
return V2ray.quicConfig(streamInfo, __secureConfig) |
||||
|
elif streamType == 'grpc': |
||||
|
return V2ray.grpcConfig(streamInfo, __secureConfig) |
||||
|
else: |
||||
|
raise Exception('Unknown stream type') |
@ -1,26 +1,49 @@ |
|||||
#!/usr/bin/python |
#!/usr/bin/python |
||||
# -*- coding:utf-8 -*- |
# -*- coding:utf-8 -*- |
||||
|
import copy |
||||
|
import time |
||||
|
|
||||
import ProxyFilter as Filter |
import ProxyFilter as Filter |
||||
|
import ProxyBuilder as Builder |
||||
|
|
||||
|
# info = { |
||||
|
# 'type': 'vless', |
||||
|
# 'server': '127.0.0.1', |
||||
|
# 'port': '12345', |
||||
|
# 'id': 'dnomd343', |
||||
|
# 'stream': { |
||||
|
# 'type': 'grpc', |
||||
|
# 'service': 'dnomd343', |
||||
|
# 'secure': { |
||||
|
# 'type': 'tls', |
||||
|
# 'sni': '', |
||||
|
# 'flow': 'xtls-origin', |
||||
|
# 'udp443': True |
||||
|
# } |
||||
|
# } |
||||
|
# } |
||||
|
# |
||||
|
# ret = Filter.filte(info) |
||||
|
# |
||||
|
# print(ret[0]) |
||||
|
# print(ret[1]) |
||||
|
|
||||
info = { |
info = { |
||||
'type': 'vless', |
'type': 'vless', |
||||
'server': '127.0.0.1', |
'server': '127.0.0.1', |
||||
'port': '12345', |
'port': '12345', |
||||
'id': 'dnomd343', |
'id': '58c0f2eb-5d47-45d0-8f5f-ebae5c2cfdd9', |
||||
'stream': { |
'stream': { |
||||
'type': 'grpc', |
'type': 'tcp', |
||||
'service': 'dnomd343', |
|
||||
'secure': { |
'secure': { |
||||
'type': 'tls', |
'type': 'xtls', |
||||
'sni': '', |
|
||||
'flow': 'xtls-origin', |
|
||||
'udp443': True |
'udp443': True |
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
ret = Filter.filte(info) |
info = copy.deepcopy(Filter.filte(info)[1]) |
||||
|
print(info) |
||||
print(ret[0]) |
Builder.build(info, '/tmp/ProxyC') |
||||
print(ret[1]) |
time.sleep(5) |
||||
|
Builder.destroy(info) |
||||
|
Loading…
Reference in new issue