Browse Source

feat: filter of Brook proxy

master
Dnomd343 3 years ago
parent
commit
d17f9468e4
  1. 90
      ProxyFilter/Brook.py
  2. 3
      ProxyFilter/filter.py
  3. 42
      demo.py

90
ProxyFilter/Brook.py

@ -0,0 +1,90 @@
#!/usr/bin/python
# -*- coding:utf-8 -*-
from ProxyFilter import baseFunc
brookFilterRules = {
'rootObject': {
'remark': {
'optional': False,
'default': '',
'type': str,
'format': baseFunc.toStr
},
'server': {
'optional': True,
'type': str,
'format': baseFunc.toStrTidy,
'filter': baseFunc.isHost,
'errMsg': 'Illegal server address'
},
'port': {
'optional': True,
'type': int,
'format': baseFunc.toInt,
'filter': baseFunc.isPort,
'errMsg': 'Illegal port number'
},
'passwd': {
'optional': True,
'type': str,
'format': baseFunc.toStr
},
'ws': {
'optional': False,
'default': None,
'allowNone': True,
'type': 'wsObject'
}
},
'wsObject': {
'host': {
'optional': False,
'default': '',
'type': str,
'format': baseFunc.toStr
},
'path': {
'optional': False,
'default': '/',
'type': str,
'format': baseFunc.toStr
},
'secure': {
'optional': False,
'default': None,
'allowNone': True,
'type': 'secureObject'
}
},
'secureObject': {
'verify': {
'optional': False,
'default': True,
'type': bool,
'format': baseFunc.toBool
}
}
}
def brookFilter(rawInfo: dict, isExtra: bool) -> tuple[bool, str or dict]:
"""
Brook节点合法性检查
不合法:
return False, {reason}
合法:
return True, {
'type': 'brook',
...
}
"""
try:
if not isExtra: # 去除非必要参数
brookFilterRules['rootObject'].pop('remark')
return baseFunc.ruleFilter(rawInfo, brookFilterRules, {
'type': 'brook'
})
except:
return False, 'Unknown error'

3
ProxyFilter/filter.py

@ -7,6 +7,7 @@ from ProxyFilter import VMess
from ProxyFilter import VLESS
from ProxyFilter import Trojan
from ProxyFilter import TrojanGo
from ProxyFilter import Brook
def filte(raw: dict, isExtra: bool = False) -> tuple[bool, str or dict]:
"""
@ -37,6 +38,8 @@ def filte(raw: dict, isExtra: bool = False) -> tuple[bool, str or dict]:
return Trojan.trojanFilter(raw, isExtra)
elif raw['type'] == 'trojan-go':
return TrojanGo.trojanGoFilter(raw, isExtra)
elif raw['type'] == 'brook':
return Brook.brookFilter(raw, isExtra)
else:
return False, 'Unknown proxy type'
except:

42
demo.py

@ -5,32 +5,20 @@ import ProxyDecoder as Decoder
import ProxyFilter as Filter
import Check as Checker
# info = {
# 'type': 'trojan-go',
# 'server': '127.0.0.1',
# 'port': 12345,
# 'passwd': 'dnomd343',
# 'sni': 'local.343.re',
# 'plugin': {
# 'type': 'simple-tls',
# 'param': 'n=local.343.re;no-verify'
# }
# }
#
# status, ret = Filter.filte(info, isExtra = True)
# print(status)
# print(ret)
#
# data = Checker.proxyTest({
# 'check': ['http'],
# 'info': ret
# })
#
# print(data)
info = {
'type': 'brook',
'server': '127.0.0.1',
'port': '12345',
'passwd': 'dnomd343',
'ws': {
'host': 'local.343.re',
'path': '/test',
'secure': {
'verify': False
}
}
}
url = 'trojan-go://password1234@google.com/?sni=microsoft.com&type=ws&host=youtube.com&path=%2Fgo&encryption=ss%3Baes-256-gcm%3Afuckgfw&plugin=obfs-local%3Bobfs%3Dhttp%3Bobfs-host%3Dwww.bing.com#server%20name'
ret = Decoder.decode(url)
print(ret)
ret = Filter.filte(ret)
status, ret = Filter.filte(info)
print(status)
print(ret)

Loading…
Cancel
Save