Permalink
Browse files

fix a security breach and optimize code

  • Loading branch information...
wanjunzh committed Dec 21, 2017
1 parent 3809116 commit f674f7dfe719b41da1fd502f2f17f34d31d0a1d0
Showing with 58 additions and 105 deletions.
  1. +8 −25 README.md
  2. +11 −28 README_zh.md
  3. BIN img/edit-autoproxy-server.png
  4. +39 −52 ssct
View
@@ -7,7 +7,7 @@ A wrapper tool for [shadowsocks](https://github.com/shadowsocks/shadowsocks) to
## Quick start
### Automatically connect
The easiest way to run this tool is just type `ssct` in terminal, and ssct will acquire available shadowsocks servers from [ishadowsocks](http://ss.ishadowx.com) and connect to it automatically.
The easiest way to run this tool is just type `ssct` in terminal, and ssct will acquire available shadowsocks servers from [ishadowsocks](https://global.ishadowx.net) and connect to it automatically.
### Connect to a specific server
@@ -33,45 +33,31 @@ ssct -s <server_addr> -p <server_port> -l <local_port> -k <password> -m <method>
### Requirements
1 Install shadowsocks
1 Install shadowsocks and requests (Required)
```
# for python2
pip install shadowsocks
# for python3
pip3 install shadowsocks
pip3 install requests
```
**Note:** You can also install shadowsocks with system package manager (apt, yum, dnf, etc) or just chrome app version [shadowsocks](https://chrome.google.com/webstore/detail/shadowsocks/fnhhahhihediajgefcnlpdmnogndblbi?utm_source=chrome-app-launcher-info-dialog). However, the chrom app version can't connect automatically.
2 Install python3 modules
2 Install prettytable (Optional)
```
pip3 install requests
pip3 install prettytable
```
**Note:** The module `prettytable` is optional, but would be better if installed.
### Configuration for google chrome
### Configuration for chrome and firefox
1. Install chrome extension [SwitchyOmega](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif).
1. Install extension Proxy SwitchyOmega ([Chrome version](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif), [Firefox version](https://addons.mozilla.org/en-US/firefox/addon/switchyomega/)).
2. Open the options of SwitchyOmega, and configure as below.
![set switchyomega proxy](img/config-swithyomega.png)
3. List servers and select one to connect, or just type `ssct` to connect automatically.
![start ssct](img/start-ssct.png)
4. Select proxy option in chrome and enjoy it.
4. Select proxy option in chrome or firefox and enjoy it.
![select proxy option](img/chrome-proxy.png)
### Configuration for firefox
1. Install firefox extension [AutoProxy](https://addons.mozilla.org/en-us/firefox/addon/autoproxy).
2. AotoProxy preferences: Proxy Server --> Edit proxy server, and add shadowsocks item.
![edit proxy server](img/edit-autoproxy-server.png)
3. Start ssct and select the shadowsocks proxy.
**Note:** For detail help [here](https://autoproxy.org/getting_started).
## More options
```
@@ -80,11 +66,8 @@ optional arguments:
ssct options:
-n <num> connect server number
--ss <ss> path to shadowsocks, assumed in the PATH
--list list all ss servers
--stop stop running servers
--version show program's version number and exit
--morehelp show this help message and exit
shadowsocks options:
-c <config> path to config file
@@ -108,4 +91,4 @@ Connect to the available server automatically without any argument.
## LICENSE
Permission is hereby granted, free of charge, to any person, without any restriction.
Permission is hereby granted, free of charge, to any person, without any restriction.
View
@@ -9,23 +9,23 @@
### 自动连接
直接在终端执行`ssct``ssct`会自动从 [ishadowsocks](http://ss.ishadowx.com) 获取服务器信息并自动连接。
直接在终端执行`ssct``ssct`会自动从 [ishadowsocks](https://global.ishadowx.net) 获取服务器信息并自动连接。
### 连接特定服务器
### 连接指定服务器
首先获取可用的服务器信息
首先获取可用的服务器信息
```
ssct --list
```
然后连接特定服务器。
然后连接指定服务器
```
ssct -n 5
```
另外,也可以连接已有的其它服务器。
另外,也可连接其它已知服务器
```
ssct -s <server_addr> -p <server_port> -l <local_port> -k <password> -m <method>
@@ -35,45 +35,31 @@ ssct -s <server_addr> -p <server_port> -l <local_port> -k <password> -m <method>
### 依赖解决
1 安装 shadowsocks
1 安装必选模块
```
# for python2
pip install shadowsocks
# for python3
pip3 install shadowsocks
pip3 install requests
```
**Note:** shadowsocks 也可以通过系统包管理器安装 (apt, yum, dnf, etc) 或者安装 chrome app 版本 [shadowsocks](https://chrome.google.com/webstore/detail/shadowsocks/fnhhahhihediajgefcnlpdmnogndblbi?utm_source=chrome-app-launcher-info-dialog)。但 chrome app 版本需手动填写服务器信息。
2 安装 python3 模块
2 安装可选模块
```
pip3 install requests
pip3 install prettytable
```
**Note:** `prettytable`模块不是必须,但会使`--list`显示结果更友好。
### 谷歌浏览器配置
### 浏览器配置
1. 安装扩展程序 [SwitchyOmega](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif)。
1. 安装扩展程序 Proxy SwitchyOmega ([Chrome版](https://chrome.google.com/webstore/detail/proxy-switchyomega/padekgcemlokbadohgkifijomclgjgif)、[Firefox版](https://addons.mozilla.org/en-US/firefox/addon/switchyomega/))。
2. 打开 SwitchyOmega 选项并作如下配置。
![set switchyomega proxy](img/config-swithyomega.png)
3. 获取所有服务器信息并连接,也可以通过`ssct`自动连接。
![start ssct](img/start-ssct.png)
4. 在谷歌浏览器中选择 proxy 代理。
4. 以 Chrome 为例,在浏览器中选择 proxy 代理。
![select proxy option](img/chrome-proxy.png)
### 火狐浏览器配置
1. 安装扩展程序 [AutoProxy](https://addons.mozilla.org/en-us/firefox/addon/autoproxy)。
2. 打开 AotoProxy 选项,编辑服务器信息并添加 shadowsocks。
![edit proxy server](img/edit-autoproxy-server.png)
3. 启动 ssct 并选择 shadowsocks 代理。
**Note:** 关于 AutoProxy,[更多帮助信息](https://autoproxy.org/getting_started)。
## 更多参数
```
@@ -82,11 +68,8 @@ optional arguments:
ssct options:
-n <num> connect server number
--ss <ss> path to shadowsocks, assumed in the PATH
--list list all ss servers
--stop stop running servers
--version show program's version number and exit
--morehelp show this help message and exit
shadowsocks options:
-c <config> path to config file
View
Binary file not shown.
View
91 ssct
@@ -6,44 +6,15 @@ A wrapper tool for shadowsocks to consistently bypass firewalls.
import re
import sys
import requests
import argparse
from subprocess import check_call, CalledProcessError
parser = argparse.ArgumentParser(description='A wrapper tool for shadowsocks to consistently bypass firewalls.', formatter_class=argparse.RawTextHelpFormatter, add_help=True, epilog='Connect to the available server automatically without any argument.')
ssctoptions = parser.add_argument_group('ssct options')
ssctoptions.add_argument('-n', dest='num', metavar='<num>', type=int, default=0, help='connect server number')
ssctoptions.add_argument('--ss', dest='ss', metavar='<ss>', default='sslocal', help='path to shadowsocks, assumed in the PATH')
ssctoptions.add_argument('--list', action='store_true', help='list all ss servers')
ssctoptions.add_argument('--stop', action='store_true', help='stop running servers')
# ssctoptions.add_argument('-x', action='store_true', help='set system socks proxy')
ssctoptions.add_argument('--version', action='version', version='%(prog)s 0.5.0')
ssctoptions.add_argument('--morehelp', action='store_true', help='show this help message and exit')
ssoptions = parser.add_argument_group('shadowsocks options')
ssoptions.add_argument('-c', dest='config', metavar='<config>', type=argparse.FileType(), help='path to config file')
ssoptions.add_argument('-s', dest='server_addr', metavar='<addr>', help='server address, auto crawl online')
ssoptions.add_argument('-p', dest='server_port', metavar='<port>', type=int, help='server port, auto crawl online')
ssoptions.add_argument('-b', dest='local_addr', metavar='<addr>', default='127.0.0.1', help='local binding address [default: %(default)s]')
ssoptions.add_argument('-l', dest='local_port', metavar='<port>', type=int, default=1080, help='local port [default: %(default)s]')
ssoptions.add_argument('-k', dest='password', metavar='<password>', help='password, auto crawl online')
ssoptions.add_argument('-m', dest='method', metavar='<method>', help='encryption method, auto crawl online')
ssoptions.add_argument('-t', dest='timeout', metavar='<timeout>', type=int, default=300, help='timeout in seconds [default: %(default)s]')
ssoptions.add_argument('--fast-open', action='store_true', help='use TCP_FASTOPEN, requires Linux 3.7+')
ssoptions.add_argument('-d', dest='daemon', metavar='<daemon>', choices=['start', 'stop', 'restart'], help='daemon mode, one of start, stop and restart')
ssoptions.add_argument('--pid-file', dest='pidfile', metavar='<file>', type=argparse.FileType('w'), help='pid file for daemon mode')
ssoptions.add_argument('--log-file', dest='logfile', metavar='<file>', type=argparse.FileType('w'), help='log file for daemon mode')
ssoptions.add_argument('--user', dest='user', metavar='<user>', help='username to run as')
ssoptions.add_argument('-v', '-vv', action='store_true', help='verbose mode')
ssoptions.add_argument('-q', '-qq', action='store_true', help='quiet mode, only show warnings/errors')
args = parser.parse_args()
args.morehelp and sys.exit(parser.print_help()) # to preserve compatibility with old version
import requests
from shadowsocks.local import main
class Shadowsocks(object):
def __init__(self):
self.url = 'http://ss.ishadowx.com'
self.url = 'https://global.ishadowx.net'
self.servers = self.crawl_servers(self.url)
def crawl_servers(self, url):
@@ -79,18 +50,41 @@ class Shadowsocks(object):
elif not self.servers[num - 1][2]:
sys.exit('\033[1;31mError:\033[0m this server is temporarily unavailable.\nTry \'--list\' for more available servers.')
try:
sss = '{} -s {} -p {} -k {} -m {} {}'.format(args.ss, self.servers[num - 1][0], self.servers[num - 1][1], self.servers[num - 1][2], self.servers[num - 1][3], ssopt)
print(sss)
try:
check_call(sss, shell=True)
except CalledProcessError:
sys.exit()
sys.argv = 'sslocal -s {} -p {} -k {} -m {} {}'.format(self.servers[num - 1][0], self.servers[num - 1][1], self.servers[num - 1][2], self.servers[num - 1][3], ssopt).split()
sys.exit(main())
except KeyboardInterrupt:
sys.exit('\nKeyboard interrupt received, exiting.')
except Exception as e:
sys.exit(e)
def get_args():
parser = argparse.ArgumentParser(description='A wrapper tool for shadowsocks to consistently bypass firewalls.', formatter_class=argparse.RawTextHelpFormatter, add_help=True, epilog='Connect to the available server automatically without any argument.')
ssctoptions = parser.add_argument_group('ssct options')
ssctoptions.add_argument('-n', dest='num', metavar='<num>', type=int, default=0, help='connect server number')
ssctoptions.add_argument('--list', action='store_true', help='list all ss servers')
# ssctoptions.add_argument('-x', action='store_true', help='set system socks proxy')
ssctoptions.add_argument('--version', action='version', version='%(prog)s 0.6.0')
ssoptions = parser.add_argument_group('shadowsocks options')
ssoptions.add_argument('-c', dest='config', metavar='<config>', type=argparse.FileType(), help='path to config file')
ssoptions.add_argument('-s', dest='server_addr', metavar='<addr>', help='server address, auto crawl online')
ssoptions.add_argument('-p', dest='server_port', metavar='<port>', type=int, help='server port, auto crawl online')
ssoptions.add_argument('-b', dest='local_addr', metavar='<addr>', default='127.0.0.1', help='local binding address [default: %(default)s]')
ssoptions.add_argument('-l', dest='local_port', metavar='<port>', type=int, default=1080, help='local port [default: %(default)s]')
ssoptions.add_argument('-k', dest='password', metavar='<password>', help='password, auto crawl online')
ssoptions.add_argument('-m', dest='method', metavar='<method>', help='encryption method, auto crawl online')
ssoptions.add_argument('-t', dest='timeout', metavar='<timeout>', type=int, default=300, help='timeout in seconds [default: %(default)s]')
ssoptions.add_argument('--fast-open', action='store_true', help='use TCP_FASTOPEN, requires Linux 3.7+')
ssoptions.add_argument('-d', dest='daemon', metavar='<daemon>', choices=['start', 'stop', 'restart'], help='daemon mode, one of start, stop and restart')
ssoptions.add_argument('--pid-file', dest='pidfile', metavar='<file>', type=argparse.FileType('w'), help='pid file for daemon mode')
ssoptions.add_argument('--log-file', dest='logfile', metavar='<file>', type=argparse.FileType('w'), help='log file for daemon mode')
ssoptions.add_argument('--user', dest='user', metavar='<user>', help='username to run as')
ssoptions.add_argument('-v', '-vv', action='store_true', help='verbose mode')
ssoptions.add_argument('-q', '-qq', action='store_true', help='quiet mode, only show warnings/errors')
args = parser.parse_args()
return args
def get_ssopt(args):
ssopt = ''
ssopt += args.config and '-c {} '.format(args.config.name) or ''
@@ -112,26 +106,19 @@ def get_ssopt(args):
if __name__ == '__main__':
args = get_args()
ssopt = get_ssopt(args)
if args.list:
Shadowsocks().list_servers()
elif args.stop:
try:
check_call(['killall', args.ss])
except CalledProcessError:
sys.exit()
elif set(ssopt.split()).intersection({'-c', '-s', '-p', '-k', '-m'}):
if '-c' in ssopt or '-s' in ssopt and '-k' in ssopt:
try:
check_call('{} {}'.format(args.ss, ssopt), shell=True)
except CalledProcessError:
sys.exit()
sys.argv = 'sslocal {}'.format(ssopt).split()
sys.exit(main())
elif not set(ssopt.split()).intersection({'-c', '-s', '-k'}):
sys.exit('\033[1;31mError:\033[0m config not specified\nTry \'--morehelp\' for more information.')
sys.exit('\033[1;31mError:\033[0m config not specified\nTry \'-h\' for more information.')
elif '-s' not in ssopt:
sys.exit('\033[1;31mError:\033[0m server addr not specified\nTry \'--morehelp\' for more information.')
sys.exit('\033[1;31mError:\033[0m server addr not specified\nTry \'-h\' for more information.')
elif '-k' not in ssopt:
sys.exit('\033[1;31mError:\033[0m password not specified\nTry \'--morehelp\' for more information.')
sys.exit('\033[1;31mError:\033[0m password not specified\nTry \'-h\' for more information.')
else:
num = args.num and int(args.num) or 0
Shadowsocks().connect(ssopt, num)
Shadowsocks().connect(ssopt, args.num)

0 comments on commit f674f7d

Please sign in to comment.