Browse Source

update: combine shadowsocks url decode

dev
dnomd343 2 years ago
parent
commit
1f8b3b4795
  1. 32
      Decoder/Shadowsocks.py
  2. 2
      Decoder/__init__.py
  3. 11
      test.py

32
Decoder/Shadowsocks.py

@ -2,34 +2,17 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# SIP002: https://shadowsocks.org/guide/sip002.html # SIP002: https://shadowsocks.org/guide/sip002.html
# Plain / Common: https://shadowsocks.org/guide/configs.html#uri-and-qr-code # SS Plain: https://shadowsocks.org/guide/configs.html#uri-and-qr-code
from Utils.Logger import logger from Utils.Logger import logger
from Utils.Common import urlDecode, b64Decode from Utils.Common import urlDecode, b64Decode
from Utils.Common import checkScheme, splitTag from Utils.Common import checkScheme, splitTag
def ssPlain(url: str) -> dict: def ss(url: str) -> dict:
""" """
FORMAT: ss://method:password@hostname:port[#TAG] FORMAT: ss://method:password@hostname:port[#TAG]
""" ss://BASE64-ENCODED-STRING-WITHOUT-PADDING[#TAG]
config = {
'type': 'ss',
'info': {}
}
info = config['info']
logger.debug('Shadowsocks plain url decode -> %s' % url)
url, config['name'] = splitTag(checkScheme(url, 'ss', 'Shadowsocks plain'), fromRight = True)
userinfo, url = url.rsplit('@', 1)
info['server'], info['port'] = url.rsplit(':', 1)
info['method'], info['passwd'] = userinfo.split(':', 1)
logger.debug('Shadowsocks plain url release -> %s' % config)
return config
def ssCommon(url: str) -> dict:
"""
FORMAT: ss://BASE64-ENCODED-STRING-WITHOUT-PADDING[#TAG]
base64('method:password@hostname:port') base64('method:password@hostname:port')
""" """
config = { config = {
@ -37,12 +20,15 @@ def ssCommon(url: str) -> dict:
'info': {} 'info': {}
} }
info = config['info'] info = config['info']
logger.debug('Shadowsocks common url decode -> %s' % url) logger.debug('Shadowsocks url decode -> %s' % url)
url, config['name'] = splitTag(checkScheme(url, 'ss', 'Shadowsocks common')) url, config['name'] = splitTag(checkScheme(url, 'ss', 'Shadowsocks'), fromRight = True)
try:
userinfo, url = b64Decode(url).rsplit('@', 1) userinfo, url = b64Decode(url).rsplit('@', 1)
except:
userinfo, url = url.rsplit('@', 1)
info['server'], info['port'] = url.rsplit(':', 1) info['server'], info['port'] = url.rsplit(':', 1)
info['method'], info['passwd'] = userinfo.split(':', 1) info['method'], info['passwd'] = userinfo.split(':', 1)
logger.debug('Shadowsocks common url release -> %s' % config) logger.debug('Shadowsocks url release -> %s' % config)
return config return config

2
Decoder/__init__.py

@ -3,4 +3,4 @@
from Decoder.VMess import v2rayN from Decoder.VMess import v2rayN
from Decoder.ShadowsocksR import ssr from Decoder.ShadowsocksR import ssr
from Decoder.Shadowsocks import ssPlain, ssCommon, sip002 from Decoder.Shadowsocks import ss, sip002

11
test.py

@ -8,10 +8,10 @@ import Decoder
from pprint import pprint from pprint import pprint
from Filter import Filter from Filter import Filter
# ret = Decoder.ssPlain('ss://aes-128-ctr:pa@ss#word@8.210.148.24:34326#ok%2Bfuck') # ret = Decoder.ss('ss://aes-128-ctr:pa@ss#word@8.210.148.24:34326#ok%2Bfuck')
# ret = Decoder.ssPlain('ss://aes-128-ctr:pa@ss#word@fc00::1:34326#ok%2Bfuck') # ret = Decoder.ss('ss://aes-128-ctr:pa@ss#word@fc00::1:34326#ok%2Bfuck')
# ret = Decoder.ssPlain('ss://aes-128-ctr:pa@ss#word@[fc00::1]:34326#ok%2Bfuck') # ret = Decoder.ss('ss://aes-128-ctr:pa@ss#word@[fc00::1]:34326#ok%2Bfuck')
# ret = Decoder.ssCommon('ss://YmYtY2ZiOnRlc3QvIUAjOkAxOTIuMTY4LjEwMC4xOjg4ODg#example-server') ret = Decoder.ss('ss://YmYtY2ZiOnRlc3QvIUAjOkAxOTIuMTY4LjEwMC4xOjg4ODg#example-server')
# ret = Decoder.sip002('ss://YWVzLTEyOC1nY206dGVzdA@192.168.100.1:8888#Example1') # ret = Decoder.sip002('ss://YWVzLTEyOC1nY206dGVzdA@192.168.100.1:8888#Example1')
# ret = Decoder.sip002('ss://2022-blake3-aes-256-gcm:YctPZ6U7xPPcU%2Bgp3u%2B0tx%2FtRizJN9K8y%2BuKlW2qjlI%3D@192.168.100.1:8888/?plugin=v2ray-plugin%3Bserver#Example3') # ret = Decoder.sip002('ss://2022-blake3-aes-256-gcm:YctPZ6U7xPPcU%2Bgp3u%2B0tx%2FtRizJN9K8y%2BuKlW2qjlI%3D@192.168.100.1:8888/?plugin=v2ray-plugin%3Bserver#Example3')
@ -19,8 +19,7 @@ from Filter import Filter
# ret = Decoder.ssr('ssr://ZmU4MDo6MTo2MDA0OmF1dGhfYWVzMTI4X21kNTphZXMtMjU2LWNmYjp0bHMxLjJfdGlja2V0X2F1dGg6Y0dGemMzZGsvP3Byb3RvcGFyYW09') # ret = Decoder.ssr('ssr://ZmU4MDo6MTo2MDA0OmF1dGhfYWVzMTI4X21kNTphZXMtMjU2LWNmYjp0bHMxLjJfdGlja2V0X2F1dGg6Y0dGemMzZGsvP3Byb3RvcGFyYW09')
# ret = Decoder.ssr('ssr://ZmU4MDo6MTo2MDA0OmF1dGhfYWVzMTI4X21kNTphZXMtMjU2LWNmYjp0bHMxLjJfdGlja2V0X2F1dGg6Y0dGemMzZGs') # ret = Decoder.ssr('ssr://ZmU4MDo6MTo2MDA0OmF1dGhfYWVzMTI4X21kNTphZXMtMjU2LWNmYjp0bHMxLjJfdGlja2V0X2F1dGg6Y0dGemMzZGs')
ret = Decoder.v2rayN('vmess://eyJhZGQiOiJmbnlkdXpheW92dnNxaTMyZ2kucTc1NDMudG9wIiwicHMiOiJ2MXzpppnmuK8wM3zljp_nlJ984piF4piF4piFICgyKSIsInNjeSI6ImF1dG8iLCJ0eXBlIjoiaHR0cCIsInNuaSI6IiIsInBhdGgiOiIvIiwicG9ydCI6MzgzMzcsInYiOjIsImhvc3QiOiJ4aGY0eHE3ZDVjYjRnc3kzeW1teWR3b2kuc2luYS5jbiIsInRscyI6IiIsImlkIjoiOTAxY2UyNTUtOTM2OS1kMWUyLTk1ODQtZGE1YTdqZjA1NDdrIiwibmV0IjoidGNwIiwiYWlkIjowfQ') # ret = Decoder.v2rayN('vmess://eyJhZGQiOiJmbnlkdXpheW92dnNxaTMyZ2kucTc1NDMudG9wIiwicHMiOiJ2MXzpppnmuK8wM3zljp_nlJ984piF4piF4piFICgyKSIsInNjeSI6ImF1dG8iLCJ0eXBlIjoiaHR0cCIsInNuaSI6IiIsInBhdGgiOiIvIiwicG9ydCI6MzgzMzcsInYiOjIsImhvc3QiOiJ4aGY0eHE3ZDVjYjRnc3kzeW1teWR3b2kuc2luYS5jbiIsInRscyI6IiIsImlkIjoiOTAxY2UyNTUtOTM2OS1kMWUyLTk1ODQtZGE1YTdqZjA1NDdrIiwibmV0IjoidGNwIiwiYWlkIjowfQ')
# ret = Decoder.v2rayN('vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIummmea4rzLnur8iLA0KICAiYWRkIjogIjExOS4yOC44OC4yMzAiLA0KICAicG9ydCI6ICI0NDMiLA0KICAiaWQiOiAiODRhOGU2ZDItMWFkMy00NjEyLTgzNjItYTdjMjNlOWU5MzEyIiwNCiAgImFpZCI6ICIwIiwNCiAgInNjeSI6ICJhdXRvIiwNCiAgIm5ldCI6ICJ3cyIsDQogICJ0eXBlIjogIm5vbmUiLA0KICAiaG9zdCI6ICJ0ZXN0LnNjdXRyb2JvdC5jb20iLA0KICAicGF0aCI6ICIvdm1lc3M/ZGVtbz10cnVlJmVkPTIwNDgmdGVzdD1vayIsDQogICJ0bHMiOiAidGxzIiwNCiAgInNuaSI6ICJoay5zY3V0cm9ib3QuY29tIiwNCiAgImFscG4iOiAiIg0KfQ==') # ret = Decoder.v2rayN('vmess://ew0KICAidiI6ICIyIiwNCiAgInBzIjogIummmea4rzLnur8iLA0KICAiYWRkIjogIjExOS4yOC44OC4yMzAiLA0KICAicG9ydCI6ICI0NDMiLA0KICAiaWQiOiAiODRhOGU2ZDItMWFkMy00NjEyLTgzNjItYTdjMjNlOWU5MzEyIiwNCiAgImFpZCI6ICIwIiwNCiAgInNjeSI6ICJhdXRvIiwNCiAgIm5ldCI6ICJ3cyIsDQogICJ0eXBlIjogIm5vbmUiLA0KICAiaG9zdCI6ICJ0ZXN0LnNjdXRyb2JvdC5jb20iLA0KICAicGF0aCI6ICIvdm1lc3M/ZGVtbz10cnVlJmVkPTIwNDgmdGVzdD1vayIsDQogICJ0bHMiOiAidGxzIiwNCiAgInNuaSI6ICJoay5zY3V0cm9ib3QuY29tIiwNCiAgImFscG4iOiAiIg0KfQ==')
# ret['info']['server'] = '[%s]' % ret['info']['server'] # ret['info']['server'] = '[%s]' % ret['info']['server']

Loading…
Cancel
Save