Browse Source

feat: filter of Trojan-Go

master
dnomd343 2 years ago
parent
commit
d0a9a6da67
  1. 2
      Filter/Shadowsocks.py
  2. 107
      Filter/TrojanGo.py
  3. 26
      demo.py

2
Filter/Shadowsocks.py

@ -36,6 +36,6 @@ ssObject = rulesFilter({
'default': None, 'default': None,
'allowNone': True, 'allowNone': True,
'type': pluginObject, 'type': pluginObject,
'errMsg': 'Invalid pluginObject' 'errMsg': 'Invalid plugin options'
} }
}) })

107
Filter/TrojanGo.py

@ -0,0 +1,107 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from Basis.Filter import rulesFilter
from Filter.Plugin import pluginObject
from Basis.Constant import trojanGoMethods
from Basis.Functions import isHost, isPort
from Basis.Functions import toInt, toStr, toStrTidy, toBool
ssObject = rulesFilter({
'method': {
'optional': True,
'default': 'aes-128-gcm',
'type': str,
'format': lambda s: toStrTidy(s).replace('_', '-'),
'filter': lambda s: s in trojanGoMethods,
'errMsg': 'Unknown Shadowsocks method'
},
'passwd': {
'optional': True,
'default': '',
'type': str,
'format': toStr,
'errMsg': 'Invalid Shadowsocks password'
}
})
wsObject = rulesFilter({
'host': {
'optional': True,
'default': '',
'type': str,
'format': toStrTidy,
'errMsg': 'Invalid WebSocket host'
},
'path': {
'optional': True,
'default': '/',
'type': str,
'format': lambda s: toStr(s).strip(),
'errMsg': 'Invalid WebSocket path'
}
})
trojanGoObject = rulesFilter({
'server': {
'type': str,
'format': toStrTidy,
'filter': isHost,
'errMsg': 'Invalid server address'
},
'port': {
'type': int,
'format': toInt,
'filter': isPort,
'errMsg': 'Invalid port number'
},
'passwd': {
'type': str,
'format': toStr,
'errMsg': 'Invalid password content'
},
'sni': {
'optional': True,
'default': '',
'type': str,
'format': toStrTidy,
'errMsg': 'Invalid SNI content'
},
'alpn': {
'optional': True,
'default': None,
'allowNone': True,
'type': str,
'format': lambda s: toStrTidy(s).replace(' ', ''), # remove space
'filter': lambda s: s in ['h2', 'http/1.1', 'h2,http/1.1'],
'errMsg': 'Invalid alpn option'
},
'verify': {
'optional': True,
'default': True,
'type': bool,
'format': toBool,
'errMsg': 'Invalid verify option'
},
'ws': {
'optional': True,
'default': None,
'allowNone': True,
'type': wsObject,
'errMsg': 'Invalid WebSocket options'
},
'ss': {
'optional': True,
'default': None,
'allowNone': True,
'type': ssObject,
'errMsg': 'Invalid Shadowsocks options'
},
'plugin': {
'optional': True,
'default': None,
'allowNone': True,
'type': pluginObject,
'errMsg': 'Invalid plugin options'
}
})

26
demo.py

@ -8,12 +8,14 @@ from Filter.ShadowsocksR import ssrObject
from Filter.VMess import vmessObject from Filter.VMess import vmessObject
from Filter.VLESS import vlessObject from Filter.VLESS import vlessObject
from Filter.Trojan import trojanObject from Filter.Trojan import trojanObject
from Filter.TrojanGo import trojanGoObject
# pprint(ssObject, sort_dicts = False) # pprint(ssObject, sort_dicts = False)
# pprint(ssrObject, sort_dicts = False) # pprint(ssrObject, sort_dicts = False)
# pprint(vmessObject, sort_dicts = False) # pprint(vmessObject, sort_dicts = False)
# pprint(vlessObject, sort_dicts = False) # pprint(vlessObject, sort_dicts = False)
# pprint(trojanObject, sort_dicts = False) # pprint(trojanObject, sort_dicts = False)
# pprint(trojanGoObject, sort_dicts = False)
# pprint(filterObject, sort_dicts = False) # pprint(filterObject, sort_dicts = False)
ssProxy = { ssProxy = {
@ -103,9 +105,31 @@ trojanProxy = {
} }
} }
trojanGoProxy = {
'server': '1.1.1.1',
'port': 12345,
'passwd': 'dnomd343',
'sni': '343.re',
'alpn': ' h2',
'verify': 'FALSE',
'ws': {
'host': 'dnomd343.top',
'path': '/test',
},
'ss': {
'method': 'chacha20-ietf-poly1305',
'passwd': 'dnomd343',
},
'plugin': {
'type': 'go-quiet',
'param': 123
}
}
# ret = Filter(ssProxy, ssObject) # ret = Filter(ssProxy, ssObject)
# ret = Filter(ssrProxy, ssrObject) # ret = Filter(ssrProxy, ssrObject)
# ret = Filter(vmessProxy, vmessObject) # ret = Filter(vmessProxy, vmessObject)
# ret = Filter(vlessProxy, vlessObject) # ret = Filter(vlessProxy, vlessObject)
ret = Filter(trojanProxy, trojanObject) # ret = Filter(trojanProxy, trojanObject)
ret = Filter(trojanGoProxy, trojanGoObject)
pprint(ret, sort_dicts = False) pprint(ret, sort_dicts = False)

Loading…
Cancel
Save