Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5179e018e2 | ||
|
|
af6c6f3f23 | ||
|
|
5c05a74727 | ||
|
|
53a7e4d0e4 | ||
|
|
5e476843ec | ||
|
|
32a6b8fd7a | ||
|
|
9fe2f4ef16 | ||
|
|
f7316c0047 | ||
|
|
cc36de5a2f | ||
|
|
4312eb9e58 | ||
|
|
eb94bd1cc3 | ||
|
|
f29bfb0cc7 | ||
|
|
80b8bd7014 | ||
|
|
a4b0ea5b8f | ||
|
|
e582b2b929 | ||
|
|
3d03dbf716 | ||
|
|
1becc9362d | ||
|
|
ebfd1486d8 | ||
|
|
6eadfca78e | ||
|
|
3294a92a61 | ||
|
|
2711002142 | ||
|
|
18da3554ff | ||
|
|
a5fc1c7e5f | ||
|
|
8b2deb01d8 | ||
|
|
176e97bb45 | ||
|
|
b6efc0efd9 | ||
|
|
4598e09b78 | ||
|
|
363965c364 | ||
|
|
a90c354f42 | ||
|
|
69d1d876bc | ||
|
|
ae57ebde68 | ||
|
|
09f8f1ccc8 | ||
|
|
b12ba5383c | ||
|
|
0bc0117cd7 | ||
|
|
85cbac127d | ||
|
|
f7a63a0ad7 | ||
|
|
a3faf2c5fb | ||
|
|
d01ef02b5a | ||
|
|
1db1e4f4e9 | ||
|
|
510dc64bf2 | ||
|
|
8be120518b | ||
|
|
e7984930d1 | ||
|
|
b8f1825776 | ||
|
|
dde25f89e1 | ||
|
|
98f73e44d0 | ||
|
|
e0189ab1de | ||
|
|
e68b3e430b | ||
|
|
bac675d7f6 | ||
|
|
291adf8b85 |
+1
-1
@@ -38,7 +38,6 @@ run_test python tests/test.py --with-coverage -c tests/aes-cfb8.json
|
|||||||
run_test python tests/test.py --with-coverage -c tests/rc4-md5.json
|
run_test python tests/test.py --with-coverage -c tests/rc4-md5.json
|
||||||
run_test python tests/test.py --with-coverage -c tests/salsa20.json
|
run_test python tests/test.py --with-coverage -c tests/salsa20.json
|
||||||
run_test python tests/test.py --with-coverage -c tests/chacha20.json
|
run_test python tests/test.py --with-coverage -c tests/chacha20.json
|
||||||
run_test python tests/test.py --with-coverage -c tests/salsa20-ctr.json
|
|
||||||
run_test python tests/test.py --with-coverage -c tests/table.json
|
run_test python tests/test.py --with-coverage -c tests/table.json
|
||||||
run_test python tests/test.py --with-coverage -c tests/server-multi-ports.json
|
run_test python tests/test.py --with-coverage -c tests/server-multi-ports.json
|
||||||
run_test python tests/test.py --with-coverage -s tests/server-multi-passwd.json -c tests/server-multi-passwd-client-side.json
|
run_test python tests/test.py --with-coverage -s tests/server-multi-passwd.json -c tests/server-multi-passwd-client-side.json
|
||||||
@@ -46,6 +45,7 @@ run_test python tests/test.py --with-coverage -c tests/workers.json
|
|||||||
run_test python tests/test.py --with-coverage -s tests/ipv6.json -c tests/ipv6-client-side.json
|
run_test python tests/test.py --with-coverage -s tests/ipv6.json -c tests/ipv6-client-side.json
|
||||||
run_test python tests/test.py --with-coverage -b "-m rc4-md5 -k testrc4 -s 127.0.0.1 -p 8388 -q" -a "-m rc4-md5 -k testrc4 -s 127.0.0.1 -p 8388 -l 1081 -vv"
|
run_test python tests/test.py --with-coverage -b "-m rc4-md5 -k testrc4 -s 127.0.0.1 -p 8388 -q" -a "-m rc4-md5 -k testrc4 -s 127.0.0.1 -p 8388 -l 1081 -vv"
|
||||||
run_test python tests/test.py --with-coverage -b "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 --workers 1" -a "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 -l 1081 -t 30 -qq -b 127.0.0.1"
|
run_test python tests/test.py --with-coverage -b "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 --workers 1" -a "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 -l 1081 -t 30 -qq -b 127.0.0.1"
|
||||||
|
run_test python tests/test.py --with-coverage --should-fail --url="http://127.0.0.1/" -b "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 --forbidden-ip=127.0.0.1,::1,8.8.8.8" -a "-m aes-256-cfb -k testrc4 -s 127.0.0.1 -p 8388 -l 1081 -t 30 -b 127.0.0.1"
|
||||||
|
|
||||||
if [ -f /proc/sys/net/ipv4/tcp_fastopen ] ; then
|
if [ -f /proc/sys/net/ipv4/tcp_fastopen ] ; then
|
||||||
if [ 3 -eq `cat /proc/sys/net/ipv4/tcp_fastopen` ] ; then
|
if [ 3 -eq `cat /proc/sys/net/ipv4/tcp_fastopen` ] ; then
|
||||||
|
|||||||
+2
-2
@@ -9,10 +9,10 @@ cache:
|
|||||||
- dante-1.4.0
|
- dante-1.4.0
|
||||||
before_install:
|
before_install:
|
||||||
- sudo apt-get update -qq
|
- sudo apt-get update -qq
|
||||||
- sudo apt-get install -qq build-essential libssl-dev swig python-m2crypto python-numpy dnsutils iproute nginx bc
|
- sudo apt-get install -qq build-essential dnsutils iproute nginx bc
|
||||||
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
|
- sudo dd if=/dev/urandom of=/usr/share/nginx/www/file bs=1M count=10
|
||||||
- sudo service nginx restart
|
- sudo service nginx restart
|
||||||
- pip install m2crypto salsa20 pep8 pyflakes nose coverage
|
- pip install pep8 pyflakes nose coverage
|
||||||
- sudo tests/socksify/install.sh
|
- sudo tests/socksify/install.sh
|
||||||
- sudo tests/libsodium/install.sh
|
- sudo tests/libsodium/install.sh
|
||||||
- sudo tests/setup_tc.sh
|
- sudo tests/setup_tc.sh
|
||||||
|
|||||||
@@ -1,3 +1,14 @@
|
|||||||
|
2.6.4 2015-01-14
|
||||||
|
- Also search lib* when searching libraries
|
||||||
|
|
||||||
|
2.6.3 2015-01-12
|
||||||
|
- Support --forbidden-ip to ban some IP, i.e. localhost
|
||||||
|
- Search OpenSSL and libsodium harder
|
||||||
|
- Now works on OpenWRT
|
||||||
|
|
||||||
|
2.6.2 2015-01-03
|
||||||
|
- Log client IP
|
||||||
|
|
||||||
2.6.1 2014-12-26
|
2.6.1 2014-12-26
|
||||||
- Fix a problem with TCP Fast Open on local side
|
- Fix a problem with TCP Fast Open on local side
|
||||||
- Fix sometimes daemon_start returns wrong exit status
|
- Fix sometimes daemon_start returns wrong exit status
|
||||||
|
|||||||
+17
-28
@@ -1,38 +1,27 @@
|
|||||||
How to contribute
|
How to Contribute
|
||||||
=================
|
=================
|
||||||
|
|
||||||
在你提交问题前,请先[自行诊断]一下。提交时附上诊断过程中的问题和下列结果,
|
Pull Requests
|
||||||
否则如果我们无法重现你的问题,也就不能帮助你。
|
-------------
|
||||||
|
|
||||||
Before you submit issues, please read [Troubleshooting] and take a few minutes
|
1. Pull requests are welcome. If you would like to add a large feature
|
||||||
to read this guide.
|
or make a significant change, make sure to open an issue to discuss with
|
||||||
|
people first.
|
||||||
问题反馈
|
2. Follow PEP8.
|
||||||
-------
|
3. Make sure to pass the unit tests. Write unit tests for new modules if
|
||||||
|
needed.
|
||||||
请提交下面的信息:
|
|
||||||
|
|
||||||
1. 你是如何搭建环境的?(操作系统,Shadowsocks 版本)
|
|
||||||
2. 操作步骤是什么?
|
|
||||||
3. 浏览器里的现象是什么?一直转菊花,还是有提示错误?
|
|
||||||
4. 发生错误时,客户端和服务端最后一部分日志。
|
|
||||||
5. 其它你认为可能和问题有关的信息。
|
|
||||||
|
|
||||||
如果你不清楚其中某条的含义, 可以直接跳过那一条。
|
|
||||||
|
|
||||||
Issues
|
Issues
|
||||||
------
|
------
|
||||||
|
|
||||||
Please include the following information in your submission:
|
1. Only bugs and feature requests are accepted here.
|
||||||
|
2. We'll only work on important features. If the feature you're asking only
|
||||||
|
benefits a few people, you'd better implement the feature yourself and send us
|
||||||
|
a pull request, or ask some of your friends to do so.
|
||||||
|
3. We don't answer questions of any other types here. Since very few people
|
||||||
|
are watching the issue tracker here, you'll probably get no help from here.
|
||||||
|
Read [Troubleshooting] and get help from forums or [mailing lists].
|
||||||
|
|
||||||
1. How did you set up your environment? (OS, version of Shadowsocks)
|
|
||||||
2. Steps to reproduce the problem.
|
|
||||||
3. What happened in your browser? Just no response, or any error message?
|
|
||||||
4. 10 lines of log on the local side of shadowsocks when the error happened.
|
|
||||||
5. 10 lines of log on the server side of shadowsocks when the error happened.
|
|
||||||
6. Any other useful information.
|
|
||||||
|
|
||||||
Skip any of them if you don't know its meaning.
|
|
||||||
|
|
||||||
[Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
|
[Troubleshooting]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
|
||||||
[自行诊断]: https://github.com/clowwindy/shadowsocks/wiki/Troubleshooting
|
[mailing lists]: https://groups.google.com/forum/#!forum/shadowsocks
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
Shadowsocks
|
Shadowsocks
|
||||||
|
|
||||||
Copyright (c) 2014 clowwindy
|
Copyright (c) 2012-2015 clowwindy
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -7,104 +7,51 @@ shadowsocks
|
|||||||
|
|
||||||
A fast tunnel proxy that helps you bypass firewalls.
|
A fast tunnel proxy that helps you bypass firewalls.
|
||||||
|
|
||||||
[中文说明][Chinese Readme]
|
Server
|
||||||
|
------
|
||||||
|
|
||||||
Install
|
### Install
|
||||||
-------
|
|
||||||
|
|
||||||
You'll have a client on your local side, and setup a server on a
|
|
||||||
remote server.
|
|
||||||
|
|
||||||
### Client
|
|
||||||
|
|
||||||
* [Windows] / [OS X]
|
|
||||||
* [Android] / [iOS]
|
|
||||||
* [OpenWRT]
|
|
||||||
|
|
||||||
### Server
|
|
||||||
|
|
||||||
#### Debian / Ubuntu:
|
#### Debian / Ubuntu:
|
||||||
|
|
||||||
apt-get install python-pip
|
apt-get install python-pip
|
||||||
pip install shadowsocks
|
pip install shadowsocks
|
||||||
|
|
||||||
Or simply `apt-get install shadowsocks` if you have [Debian sid] in your
|
|
||||||
source list.
|
|
||||||
|
|
||||||
#### CentOS:
|
#### CentOS:
|
||||||
|
|
||||||
yum install python-setuptools
|
yum install python-setuptools && easy_install pip
|
||||||
easy_install pip
|
|
||||||
pip install shadowsocks
|
pip install shadowsocks
|
||||||
|
|
||||||
#### Windows:
|
#### Windows:
|
||||||
|
|
||||||
Download [OpenSSL for Windows] and install. Then install shadowsocks via
|
See [Install Server on Windows]
|
||||||
easy_install and pip as Linux. If you don't know how to use them, you can
|
|
||||||
directly download [the package], and use `python shadowsocks/server.py`
|
|
||||||
instead of `ssserver` command below.
|
|
||||||
|
|
||||||
Configuration
|
### Usage
|
||||||
-------------
|
|
||||||
|
|
||||||
On your server create a config file `/etc/shadowsocks.json`.
|
ssserver -p 8000 -k password -m rc4-md5
|
||||||
Example:
|
|
||||||
|
|
||||||
{
|
|
||||||
"server":"my_server_ip",
|
|
||||||
"server_port":8388,
|
|
||||||
"local_address": "127.0.0.1",
|
|
||||||
"local_port":1080,
|
|
||||||
"password":"mypassword",
|
|
||||||
"timeout":300,
|
|
||||||
"method":"aes-256-cfb",
|
|
||||||
"fast_open": false
|
|
||||||
}
|
|
||||||
|
|
||||||
Explanation of the fields:
|
|
||||||
|
|
||||||
| Name | Explanation |
|
|
||||||
| ------------- | ----------------------------------------------- |
|
|
||||||
| server | the address your server listens |
|
|
||||||
| server_port | server port |
|
|
||||||
| local_address | the address your local listens |
|
|
||||||
| local_port | local port |
|
|
||||||
| password | password used for encryption |
|
|
||||||
| timeout | in seconds |
|
|
||||||
| method | default: "aes-256-cfb", see [Encryption] |
|
|
||||||
| fast_open | use [TCP_FASTOPEN], true / false |
|
|
||||||
| workers | number of workers, available on Unix/Linux |
|
|
||||||
|
|
||||||
On your server:
|
|
||||||
|
|
||||||
To run in the foreground:
|
|
||||||
|
|
||||||
ssserver -c /etc/shadowsocks.json
|
|
||||||
|
|
||||||
To run in the background:
|
To run in the background:
|
||||||
|
|
||||||
ssserver -c /etc/shadowsocks.json -d start
|
ssserver -p 8000 -k password -m rc4-md5 -d start
|
||||||
ssserver -c /etc/shadowsocks.json -d stop
|
ssserver -p 8000 -k password -m rc4-md5 -d stop
|
||||||
|
|
||||||
On your client machine, use the same configuration as your server. Check the
|
Check all the options via `-h`. You can also use a [Configuration] file
|
||||||
README of your client for more information.
|
instead.
|
||||||
|
|
||||||
Command Line Options
|
Client
|
||||||
--------------------
|
------
|
||||||
|
|
||||||
Check the options via `-h`.You can use args to override settings from
|
* [Windows] / [OS X]
|
||||||
`config.json`.
|
* [Android] / [iOS]
|
||||||
|
* [OpenWRT]
|
||||||
|
|
||||||
sslocal -s server_name -p server_port -l local_port -k password -m bf-cfb
|
Use GUI clients on your local PC/phones. Check the README of your client
|
||||||
ssserver -p server_port -k password -m bf-cfb --workers 2
|
for more information.
|
||||||
ssserver -c /etc/shadowsocks/config.json -d start --pid-file=/tmp/shadowsocks.pid
|
|
||||||
ssserver -c /etc/shadowsocks/config.json -d stop --pid-file=/tmp/shadowsocks.pid
|
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
You can find all the documentation in the wiki:
|
You can find all the documentation in the [Wiki].
|
||||||
https://github.com/shadowsocks/shadowsocks/wiki
|
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
@@ -118,23 +65,22 @@ Bugs and Issues
|
|||||||
* [Mailing list]
|
* [Mailing list]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[Android]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#android
|
[Android]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#android
|
||||||
[Build Status]: https://img.shields.io/travis/shadowsocks/shadowsocks/master.svg?style=flat
|
[Build Status]: https://img.shields.io/travis/shadowsocks/shadowsocks/master.svg?style=flat
|
||||||
[Chinese Readme]: https://github.com/shadowsocks/shadowsocks/wiki/Shadowsocks-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E
|
[Configuration]: https://github.com/shadowsocks/shadowsocks/wiki/Configuration-via-Config-File
|
||||||
[Coverage Status]: http://192.81.132.184/result/shadowsocks
|
[Coverage Status]: https://jenkins.shadowvpn.org/result/shadowsocks
|
||||||
[Coverage]: http://192.81.132.184/job/Shadowsocks/ws/htmlcov/index.html
|
[Coverage]: https://jenkins.shadowvpn.org/job/Shadowsocks/ws/htmlcov/index.html
|
||||||
[Debian sid]: https://packages.debian.org/unstable/python/shadowsocks
|
[Debian sid]: https://packages.debian.org/unstable/python/shadowsocks
|
||||||
[the package]: https://pypi.python.org/pypi/shadowsocks
|
|
||||||
[Encryption]: https://github.com/shadowsocks/shadowsocks/wiki/Encryption
|
|
||||||
[iOS]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help
|
[iOS]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help
|
||||||
[Issue Tracker]: https://github.com/shadowsocks/shadowsocks/issues?state=open
|
[Issue Tracker]: https://github.com/shadowsocks/shadowsocks/issues?state=open
|
||||||
[Mailing list]: http://groups.google.com/group/shadowsocks
|
[Install Server on Windows]: https://github.com/shadowsocks/shadowsocks/wiki/Install-Shadowsocks-Server-on-Windows
|
||||||
[OpenSSL for Windows]: http://slproweb.com/products/Win32OpenSSL.html
|
[Mailing list]: https://groups.google.com/group/shadowsocks
|
||||||
[OpenWRT]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#openwrt
|
[OpenWRT]: https://github.com/shadowsocks/openwrt-shadowsocks
|
||||||
[OS X]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help
|
[OS X]: https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help
|
||||||
[PyPI]: https://pypi.python.org/pypi/shadowsocks
|
[PyPI]: https://pypi.python.org/pypi/shadowsocks
|
||||||
[PyPI version]: https://img.shields.io/pypi/v/shadowsocks.svg?style=flat
|
[PyPI version]: https://img.shields.io/pypi/v/shadowsocks.svg?style=flat
|
||||||
[TCP_FASTOPEN]: https://github.com/shadowsocks/shadowsocks/wiki/TCP-Fast-Open
|
|
||||||
[Travis CI]: https://travis-ci.org/shadowsocks/shadowsocks
|
[Travis CI]: https://travis-ci.org/shadowsocks/shadowsocks
|
||||||
[Troubleshooting]: https://github.com/shadowsocks/shadowsocks/wiki/Troubleshooting
|
[Troubleshooting]: https://github.com/shadowsocks/shadowsocks/wiki/Troubleshooting
|
||||||
|
[Wiki]: https://github.com/shadowsocks/shadowsocks/wiki
|
||||||
[Windows]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#windows
|
[Windows]: https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#windows
|
||||||
|
|||||||
+29
-95
@@ -5,26 +5,11 @@ shadowsocks
|
|||||||
|
|
||||||
A fast tunnel proxy that helps you bypass firewalls.
|
A fast tunnel proxy that helps you bypass firewalls.
|
||||||
|
|
||||||
`中文说明 <https://github.com/shadowsocks/shadowsocks/wiki/Shadowsocks-%E4%BD%BF%E7%94%A8%E8%AF%B4%E6%98%8E>`__
|
Server
|
||||||
|
------
|
||||||
|
|
||||||
Install
|
Install
|
||||||
-------
|
~~~~~~~
|
||||||
|
|
||||||
You'll have a client on your local side, and setup a server on a remote
|
|
||||||
server.
|
|
||||||
|
|
||||||
Client
|
|
||||||
~~~~~~
|
|
||||||
|
|
||||||
- `Windows <https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#windows>`__
|
|
||||||
/ `OS
|
|
||||||
X <https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help>`__
|
|
||||||
- `Android <https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#android>`__
|
|
||||||
/ `iOS <https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help>`__
|
|
||||||
- `OpenWRT <https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#openwrt>`__
|
|
||||||
|
|
||||||
Server
|
|
||||||
~~~~~~
|
|
||||||
|
|
||||||
Debian / Ubuntu:
|
Debian / Ubuntu:
|
||||||
^^^^^^^^^^^^^^^^
|
^^^^^^^^^^^^^^^^
|
||||||
@@ -34,107 +19,56 @@ Debian / Ubuntu:
|
|||||||
apt-get install python-pip
|
apt-get install python-pip
|
||||||
pip install shadowsocks
|
pip install shadowsocks
|
||||||
|
|
||||||
Or simply ``apt-get install shadowsocks`` if you have `Debian
|
|
||||||
sid <https://packages.debian.org/unstable/python/shadowsocks>`__ in your
|
|
||||||
source list.
|
|
||||||
|
|
||||||
CentOS:
|
CentOS:
|
||||||
^^^^^^^
|
^^^^^^^
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
yum install python-setuptools
|
yum install python-setuptools && easy_install pip
|
||||||
easy_install pip
|
|
||||||
pip install shadowsocks
|
pip install shadowsocks
|
||||||
|
|
||||||
Windows:
|
Windows:
|
||||||
^^^^^^^^
|
^^^^^^^^
|
||||||
|
|
||||||
Download `OpenSSL for
|
See `Install Server on
|
||||||
Windows <http://slproweb.com/products/Win32OpenSSL.html>`__ and install.
|
Windows <https://github.com/shadowsocks/shadowsocks/wiki/Install-Shadowsocks-Server-on-Windows>`__
|
||||||
Then install shadowsocks via easy\_install and pip as Linux. If you
|
|
||||||
don't know how to use them, you can directly download `the
|
|
||||||
package <https://pypi.python.org/pypi/shadowsocks>`__, and use
|
|
||||||
``python shadowsocks/server.py`` instead of ``ssserver`` command below.
|
|
||||||
|
|
||||||
Configuration
|
Usage
|
||||||
-------------
|
~~~~~
|
||||||
|
|
||||||
On your server create a config file ``/etc/shadowsocks.json``. Example:
|
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
{
|
ssserver -p 8000 -k password -m rc4-md5
|
||||||
"server":"my_server_ip",
|
|
||||||
"server_port":8388,
|
|
||||||
"local_address": "127.0.0.1",
|
|
||||||
"local_port":1080,
|
|
||||||
"password":"mypassword",
|
|
||||||
"timeout":300,
|
|
||||||
"method":"aes-256-cfb",
|
|
||||||
"fast_open": false
|
|
||||||
}
|
|
||||||
|
|
||||||
Explanation of the fields:
|
|
||||||
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| Name | Explanation |
|
|
||||||
+==================+===========================================================================================================+
|
|
||||||
| server | the address your server listens |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| server\_port | server port |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| local\_address | the address your local listens |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| local\_port | local port |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| password | password used for encryption |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| timeout | in seconds |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| method | default: "aes-256-cfb", see `Encryption <https://github.com/shadowsocks/shadowsocks/wiki/Encryption>`__ |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| fast\_open | use `TCP\_FASTOPEN <https://github.com/shadowsocks/shadowsocks/wiki/TCP-Fast-Open>`__, true / false |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
| workers | number of workers, available on Unix/Linux |
|
|
||||||
+------------------+-----------------------------------------------------------------------------------------------------------+
|
|
||||||
|
|
||||||
On your server:
|
|
||||||
|
|
||||||
To run in the foreground:
|
|
||||||
|
|
||||||
::
|
|
||||||
|
|
||||||
ssserver -c /etc/shadowsocks.json
|
|
||||||
|
|
||||||
To run in the background:
|
To run in the background:
|
||||||
|
|
||||||
::
|
::
|
||||||
|
|
||||||
ssserver -c /etc/shadowsocks.json -d start
|
ssserver -p 8000 -k password -m rc4-md5 -d start
|
||||||
ssserver -c /etc/shadowsocks.json -d stop
|
ssserver -p 8000 -k password -m rc4-md5 -d stop
|
||||||
|
|
||||||
On your client machine, use the same configuration as your server. Check
|
Check all the options via ``-h``. You can also use a
|
||||||
the README of your client for more information.
|
`Configuration <https://github.com/shadowsocks/shadowsocks/wiki/Configuration-via-Config-File>`__
|
||||||
|
file instead.
|
||||||
|
|
||||||
Command Line Options
|
Client
|
||||||
--------------------
|
------
|
||||||
|
|
||||||
Check the options via ``-h``.You can use args to override settings from
|
- `Windows <https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#windows>`__
|
||||||
``config.json``.
|
/ `OS
|
||||||
|
X <https://github.com/shadowsocks/shadowsocks-iOS/wiki/Shadowsocks-for-OSX-Help>`__
|
||||||
|
- `Android <https://github.com/shadowsocks/shadowsocks/wiki/Ports-and-Clients#android>`__
|
||||||
|
/ `iOS <https://github.com/shadowsocks/shadowsocks-iOS/wiki/Help>`__
|
||||||
|
- `OpenWRT <https://github.com/shadowsocks/openwrt-shadowsocks>`__
|
||||||
|
|
||||||
::
|
Use GUI clients on your local PC/phones. Check the README of your client
|
||||||
|
for more information.
|
||||||
sslocal -s server_name -p server_port -l local_port -k password -m bf-cfb
|
|
||||||
ssserver -p server_port -k password -m bf-cfb --workers 2
|
|
||||||
ssserver -c /etc/shadowsocks/config.json -d start --pid-file=/tmp/shadowsocks.pid
|
|
||||||
ssserver -c /etc/shadowsocks/config.json -d stop --pid-file=/tmp/shadowsocks.pid
|
|
||||||
|
|
||||||
Documentation
|
Documentation
|
||||||
-------------
|
-------------
|
||||||
|
|
||||||
You can find all the documentation in the wiki:
|
You can find all the documentation in the
|
||||||
https://github.com/shadowsocks/shadowsocks/wiki
|
`Wiki <https://github.com/shadowsocks/shadowsocks/wiki>`__.
|
||||||
|
|
||||||
License
|
License
|
||||||
-------
|
-------
|
||||||
@@ -147,11 +81,11 @@ Bugs and Issues
|
|||||||
- `Troubleshooting <https://github.com/shadowsocks/shadowsocks/wiki/Troubleshooting>`__
|
- `Troubleshooting <https://github.com/shadowsocks/shadowsocks/wiki/Troubleshooting>`__
|
||||||
- `Issue
|
- `Issue
|
||||||
Tracker <https://github.com/shadowsocks/shadowsocks/issues?state=open>`__
|
Tracker <https://github.com/shadowsocks/shadowsocks/issues?state=open>`__
|
||||||
- `Mailing list <http://groups.google.com/group/shadowsocks>`__
|
- `Mailing list <https://groups.google.com/group/shadowsocks>`__
|
||||||
|
|
||||||
.. |PyPI version| image:: https://img.shields.io/pypi/v/shadowsocks.svg?style=flat
|
.. |PyPI version| image:: https://img.shields.io/pypi/v/shadowsocks.svg?style=flat
|
||||||
:target: https://pypi.python.org/pypi/shadowsocks
|
:target: https://pypi.python.org/pypi/shadowsocks
|
||||||
.. |Build Status| image:: https://img.shields.io/travis/shadowsocks/shadowsocks/master.svg?style=flat
|
.. |Build Status| image:: https://img.shields.io/travis/shadowsocks/shadowsocks/master.svg?style=flat
|
||||||
:target: https://travis-ci.org/shadowsocks/shadowsocks
|
:target: https://travis-ci.org/shadowsocks/shadowsocks
|
||||||
.. |Coverage Status| image:: http://192.81.132.184/result/shadowsocks
|
.. |Coverage Status| image:: https://jenkins.shadowvpn.org/result/shadowsocks
|
||||||
:target: http://192.81.132.184/job/Shadowsocks/ws/htmlcov/index.html
|
:target: https://jenkins.shadowvpn.org/job/Shadowsocks/ws/htmlcov/index.html
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ with codecs.open('README.rst', encoding='utf-8') as f:
|
|||||||
|
|
||||||
setup(
|
setup(
|
||||||
name="shadowsocks",
|
name="shadowsocks",
|
||||||
version="2.6.1",
|
version="2.6.4",
|
||||||
license='MIT',
|
license='MIT',
|
||||||
description="A fast tunnel proxy that help you get through firewalls",
|
description="A fast tunnel proxy that help you get through firewalls",
|
||||||
author='clowwindy',
|
author='clowwindy',
|
||||||
|
|||||||
@@ -1,119 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# Copyright (c) 2014 clowwindy
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
# SOFTWARE.
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, \
|
|
||||||
with_statement
|
|
||||||
|
|
||||||
import sys
|
|
||||||
import logging
|
|
||||||
|
|
||||||
__all__ = ['ciphers']
|
|
||||||
|
|
||||||
has_m2 = True
|
|
||||||
try:
|
|
||||||
__import__('M2Crypto')
|
|
||||||
except ImportError:
|
|
||||||
has_m2 = False
|
|
||||||
if bytes != str:
|
|
||||||
has_m2 = False
|
|
||||||
|
|
||||||
|
|
||||||
def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None, i=1,
|
|
||||||
padding=1):
|
|
||||||
|
|
||||||
import M2Crypto.EVP
|
|
||||||
return M2Crypto.EVP.Cipher(alg.replace('-', '_'), key, iv, op,
|
|
||||||
key_as_bytes=0, d='md5', salt=None, i=1,
|
|
||||||
padding=1)
|
|
||||||
|
|
||||||
|
|
||||||
def err(alg, key, iv, op, key_as_bytes=0, d=None, salt=None, i=1, padding=1):
|
|
||||||
logging.error(('M2Crypto is required to use %s, please run'
|
|
||||||
' `apt-get install python-m2crypto`') % alg)
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
if has_m2:
|
|
||||||
ciphers = {
|
|
||||||
b'aes-128-cfb': (16, 16, create_cipher),
|
|
||||||
b'aes-192-cfb': (24, 16, create_cipher),
|
|
||||||
b'aes-256-cfb': (32, 16, create_cipher),
|
|
||||||
b'bf-cfb': (16, 8, create_cipher),
|
|
||||||
b'camellia-128-cfb': (16, 16, create_cipher),
|
|
||||||
b'camellia-192-cfb': (24, 16, create_cipher),
|
|
||||||
b'camellia-256-cfb': (32, 16, create_cipher),
|
|
||||||
b'cast5-cfb': (16, 8, create_cipher),
|
|
||||||
b'des-cfb': (8, 8, create_cipher),
|
|
||||||
b'idea-cfb': (16, 8, create_cipher),
|
|
||||||
b'rc2-cfb': (16, 8, create_cipher),
|
|
||||||
b'rc4': (16, 0, create_cipher),
|
|
||||||
b'seed-cfb': (16, 16, create_cipher),
|
|
||||||
}
|
|
||||||
else:
|
|
||||||
ciphers = {}
|
|
||||||
|
|
||||||
|
|
||||||
def run_method(method):
|
|
||||||
from shadowsocks.crypto import util
|
|
||||||
|
|
||||||
cipher = create_cipher(method, b'k' * 32, b'i' * 16, 1)
|
|
||||||
decipher = create_cipher(method, b'k' * 32, b'i' * 16, 0)
|
|
||||||
|
|
||||||
util.run_cipher(cipher, decipher)
|
|
||||||
|
|
||||||
|
|
||||||
def check_env():
|
|
||||||
# skip this test on pypy and Python 3
|
|
||||||
try:
|
|
||||||
import __pypy__
|
|
||||||
del __pypy__
|
|
||||||
from nose.plugins.skip import SkipTest
|
|
||||||
raise SkipTest
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
if bytes != str:
|
|
||||||
from nose.plugins.skip import SkipTest
|
|
||||||
raise SkipTest
|
|
||||||
|
|
||||||
|
|
||||||
def test_aes_128_cfb():
|
|
||||||
check_env()
|
|
||||||
run_method(b'aes-128-cfb')
|
|
||||||
|
|
||||||
|
|
||||||
def test_aes_256_cfb():
|
|
||||||
check_env()
|
|
||||||
run_method(b'aes-256-cfb')
|
|
||||||
|
|
||||||
|
|
||||||
def test_bf_cfb():
|
|
||||||
check_env()
|
|
||||||
run_method(b'bf-cfb')
|
|
||||||
|
|
||||||
|
|
||||||
def test_rc4():
|
|
||||||
check_env()
|
|
||||||
run_method(b'rc4')
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test_aes_128_cfb()
|
|
||||||
@@ -23,10 +23,11 @@
|
|||||||
from __future__ import absolute_import, division, print_function, \
|
from __future__ import absolute_import, division, print_function, \
|
||||||
with_statement
|
with_statement
|
||||||
|
|
||||||
import logging
|
from ctypes import c_char_p, c_int, c_long, byref,\
|
||||||
from ctypes import CDLL, c_char_p, c_int, c_long, byref,\
|
|
||||||
create_string_buffer, c_void_p
|
create_string_buffer, c_void_p
|
||||||
|
|
||||||
|
from shadowsocks.crypto import util
|
||||||
|
|
||||||
__all__ = ['ciphers']
|
__all__ = ['ciphers']
|
||||||
|
|
||||||
libcrypto = None
|
libcrypto = None
|
||||||
@@ -38,15 +39,12 @@ buf_size = 2048
|
|||||||
def load_openssl():
|
def load_openssl():
|
||||||
global loaded, libcrypto, buf
|
global loaded, libcrypto, buf
|
||||||
|
|
||||||
from ctypes.util import find_library
|
libcrypto = util.find_library(('crypto', 'eay32'),
|
||||||
for p in ('crypto', 'eay32', 'libeay32'):
|
'EVP_get_cipherbyname',
|
||||||
libcrypto_path = find_library(p)
|
'libcrypto')
|
||||||
if libcrypto_path:
|
if libcrypto is None:
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise Exception('libcrypto(OpenSSL) not found')
|
raise Exception('libcrypto(OpenSSL) not found')
|
||||||
logging.info('loading libcrypto from %s', libcrypto_path)
|
|
||||||
libcrypto = CDLL(libcrypto_path)
|
|
||||||
libcrypto.EVP_get_cipherbyname.restype = c_void_p
|
libcrypto.EVP_get_cipherbyname.restype = c_void_p
|
||||||
libcrypto.EVP_CIPHER_CTX_new.restype = c_void_p
|
libcrypto.EVP_CIPHER_CTX_new.restype = c_void_p
|
||||||
|
|
||||||
@@ -76,11 +74,11 @@ def load_cipher(cipher_name):
|
|||||||
return None
|
return None
|
||||||
|
|
||||||
|
|
||||||
class CtypesCrypto(object):
|
class OpenSSLCrypto(object):
|
||||||
def __init__(self, cipher_name, key, iv, op):
|
def __init__(self, cipher_name, key, iv, op):
|
||||||
|
self._ctx = None
|
||||||
if not loaded:
|
if not loaded:
|
||||||
load_openssl()
|
load_openssl()
|
||||||
self._ctx = None
|
|
||||||
cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
|
cipher = libcrypto.EVP_get_cipherbyname(cipher_name)
|
||||||
if not cipher:
|
if not cipher:
|
||||||
cipher = load_cipher(cipher_name)
|
cipher = load_cipher(cipher_name)
|
||||||
@@ -119,39 +117,38 @@ class CtypesCrypto(object):
|
|||||||
|
|
||||||
|
|
||||||
ciphers = {
|
ciphers = {
|
||||||
b'aes-128-cfb': (16, 16, CtypesCrypto),
|
b'aes-128-cfb': (16, 16, OpenSSLCrypto),
|
||||||
b'aes-192-cfb': (24, 16, CtypesCrypto),
|
b'aes-192-cfb': (24, 16, OpenSSLCrypto),
|
||||||
b'aes-256-cfb': (32, 16, CtypesCrypto),
|
b'aes-256-cfb': (32, 16, OpenSSLCrypto),
|
||||||
b'aes-128-ofb': (16, 16, CtypesCrypto),
|
b'aes-128-ofb': (16, 16, OpenSSLCrypto),
|
||||||
b'aes-192-ofb': (24, 16, CtypesCrypto),
|
b'aes-192-ofb': (24, 16, OpenSSLCrypto),
|
||||||
b'aes-256-ofb': (32, 16, CtypesCrypto),
|
b'aes-256-ofb': (32, 16, OpenSSLCrypto),
|
||||||
b'aes-128-ctr': (16, 16, CtypesCrypto),
|
b'aes-128-ctr': (16, 16, OpenSSLCrypto),
|
||||||
b'aes-192-ctr': (24, 16, CtypesCrypto),
|
b'aes-192-ctr': (24, 16, OpenSSLCrypto),
|
||||||
b'aes-256-ctr': (32, 16, CtypesCrypto),
|
b'aes-256-ctr': (32, 16, OpenSSLCrypto),
|
||||||
b'aes-128-cfb8': (16, 16, CtypesCrypto),
|
b'aes-128-cfb8': (16, 16, OpenSSLCrypto),
|
||||||
b'aes-192-cfb8': (24, 16, CtypesCrypto),
|
b'aes-192-cfb8': (24, 16, OpenSSLCrypto),
|
||||||
b'aes-256-cfb8': (32, 16, CtypesCrypto),
|
b'aes-256-cfb8': (32, 16, OpenSSLCrypto),
|
||||||
b'aes-128-cfb1': (16, 16, CtypesCrypto),
|
b'aes-128-cfb1': (16, 16, OpenSSLCrypto),
|
||||||
b'aes-192-cfb1': (24, 16, CtypesCrypto),
|
b'aes-192-cfb1': (24, 16, OpenSSLCrypto),
|
||||||
b'aes-256-cfb1': (32, 16, CtypesCrypto),
|
b'aes-256-cfb1': (32, 16, OpenSSLCrypto),
|
||||||
b'bf-cfb': (16, 8, CtypesCrypto),
|
b'bf-cfb': (16, 8, OpenSSLCrypto),
|
||||||
b'camellia-128-cfb': (16, 16, CtypesCrypto),
|
b'camellia-128-cfb': (16, 16, OpenSSLCrypto),
|
||||||
b'camellia-192-cfb': (24, 16, CtypesCrypto),
|
b'camellia-192-cfb': (24, 16, OpenSSLCrypto),
|
||||||
b'camellia-256-cfb': (32, 16, CtypesCrypto),
|
b'camellia-256-cfb': (32, 16, OpenSSLCrypto),
|
||||||
b'cast5-cfb': (16, 8, CtypesCrypto),
|
b'cast5-cfb': (16, 8, OpenSSLCrypto),
|
||||||
b'des-cfb': (8, 8, CtypesCrypto),
|
b'des-cfb': (8, 8, OpenSSLCrypto),
|
||||||
b'idea-cfb': (16, 8, CtypesCrypto),
|
b'idea-cfb': (16, 8, OpenSSLCrypto),
|
||||||
b'rc2-cfb': (16, 8, CtypesCrypto),
|
b'rc2-cfb': (16, 8, OpenSSLCrypto),
|
||||||
b'rc4': (16, 0, CtypesCrypto),
|
b'rc4': (16, 0, OpenSSLCrypto),
|
||||||
b'seed-cfb': (16, 16, CtypesCrypto),
|
b'seed-cfb': (16, 16, OpenSSLCrypto),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def run_method(method):
|
def run_method(method):
|
||||||
from shadowsocks.crypto import util
|
|
||||||
|
|
||||||
cipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 1)
|
cipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 1)
|
||||||
decipher = CtypesCrypto(method, b'k' * 32, b'i' * 16, 0)
|
decipher = OpenSSLCrypto(method, b'k' * 32, b'i' * 16, 0)
|
||||||
|
|
||||||
util.run_cipher(cipher, decipher)
|
util.run_cipher(cipher, decipher)
|
||||||
|
|
||||||
@@ -25,6 +25,7 @@ from __future__ import absolute_import, division, print_function, \
|
|||||||
|
|
||||||
import hashlib
|
import hashlib
|
||||||
|
|
||||||
|
from shadowsocks.crypto import openssl
|
||||||
|
|
||||||
__all__ = ['ciphers']
|
__all__ = ['ciphers']
|
||||||
|
|
||||||
@@ -35,15 +36,7 @@ def create_cipher(alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
|
|||||||
md5.update(key)
|
md5.update(key)
|
||||||
md5.update(iv)
|
md5.update(iv)
|
||||||
rc4_key = md5.digest()
|
rc4_key = md5.digest()
|
||||||
|
return openssl.OpenSSLCrypto(b'rc4', rc4_key, b'', op)
|
||||||
try:
|
|
||||||
from shadowsocks.crypto import ctypes_openssl
|
|
||||||
return ctypes_openssl.CtypesCrypto(b'rc4', rc4_key, b'', op)
|
|
||||||
except:
|
|
||||||
import M2Crypto.EVP
|
|
||||||
return M2Crypto.EVP.Cipher(b'rc4', rc4_key, b'', op,
|
|
||||||
key_as_bytes=0, d='md5', salt=None, i=1,
|
|
||||||
padding=1)
|
|
||||||
|
|
||||||
|
|
||||||
ciphers = {
|
ciphers = {
|
||||||
|
|||||||
@@ -1,140 +0,0 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
# Copyright (c) 2014 clowwindy
|
|
||||||
#
|
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
|
||||||
# in the Software without restriction, including without limitation the rights
|
|
||||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
# copies of the Software, and to permit persons to whom the Software is
|
|
||||||
# furnished to do so, subject to the following conditions:
|
|
||||||
#
|
|
||||||
# The above copyright notice and this permission notice shall be included in
|
|
||||||
# all copies or substantial portions of the Software.
|
|
||||||
#
|
|
||||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
# SOFTWARE.
|
|
||||||
|
|
||||||
from __future__ import absolute_import, division, print_function, \
|
|
||||||
with_statement
|
|
||||||
|
|
||||||
import struct
|
|
||||||
import logging
|
|
||||||
import sys
|
|
||||||
|
|
||||||
slow_xor = False
|
|
||||||
imported = False
|
|
||||||
|
|
||||||
salsa20 = None
|
|
||||||
numpy = None
|
|
||||||
|
|
||||||
BLOCK_SIZE = 16384
|
|
||||||
|
|
||||||
|
|
||||||
def run_imports():
|
|
||||||
global imported, slow_xor, salsa20, numpy
|
|
||||||
if not imported:
|
|
||||||
imported = True
|
|
||||||
try:
|
|
||||||
numpy = __import__('numpy')
|
|
||||||
except ImportError:
|
|
||||||
logging.error('can not import numpy, using SLOW XOR')
|
|
||||||
logging.error('please install numpy if you use salsa20')
|
|
||||||
slow_xor = True
|
|
||||||
try:
|
|
||||||
salsa20 = __import__('salsa20')
|
|
||||||
except ImportError:
|
|
||||||
logging.error('you have to install salsa20 before you use salsa20')
|
|
||||||
sys.exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def numpy_xor(a, b):
|
|
||||||
if slow_xor:
|
|
||||||
return py_xor_str(a, b)
|
|
||||||
dtype = numpy.byte
|
|
||||||
if len(a) % 4 == 0:
|
|
||||||
dtype = numpy.uint32
|
|
||||||
elif len(a) % 2 == 0:
|
|
||||||
dtype = numpy.uint16
|
|
||||||
|
|
||||||
ab = numpy.frombuffer(a, dtype=dtype)
|
|
||||||
bb = numpy.frombuffer(b, dtype=dtype)
|
|
||||||
c = numpy.bitwise_xor(ab, bb)
|
|
||||||
r = c.tostring()
|
|
||||||
return r
|
|
||||||
|
|
||||||
|
|
||||||
def py_xor_str(a, b):
|
|
||||||
c = []
|
|
||||||
if bytes == str:
|
|
||||||
for i in range(0, len(a)):
|
|
||||||
c.append(chr(ord(a[i]) ^ ord(b[i])))
|
|
||||||
return ''.join(c)
|
|
||||||
else:
|
|
||||||
for i in range(0, len(a)):
|
|
||||||
c.append(a[i] ^ b[i])
|
|
||||||
return bytes(c)
|
|
||||||
|
|
||||||
|
|
||||||
class Salsa20Cipher(object):
|
|
||||||
"""a salsa20 CTR implemetation, provides m2crypto like cipher API"""
|
|
||||||
|
|
||||||
def __init__(self, alg, key, iv, op, key_as_bytes=0, d=None, salt=None,
|
|
||||||
i=1, padding=1):
|
|
||||||
run_imports()
|
|
||||||
if alg != b'salsa20-ctr':
|
|
||||||
raise Exception('unknown algorithm')
|
|
||||||
self._key = key
|
|
||||||
self._nonce = struct.unpack('<Q', iv)[0]
|
|
||||||
self._pos = 0
|
|
||||||
self._next_stream()
|
|
||||||
|
|
||||||
def _next_stream(self):
|
|
||||||
self._nonce &= 0xFFFFFFFFFFFFFFFF
|
|
||||||
self._stream = salsa20.Salsa20_keystream(BLOCK_SIZE,
|
|
||||||
struct.pack('<Q',
|
|
||||||
self._nonce),
|
|
||||||
self._key)
|
|
||||||
self._nonce += 1
|
|
||||||
|
|
||||||
def update(self, data):
|
|
||||||
results = []
|
|
||||||
while True:
|
|
||||||
remain = BLOCK_SIZE - self._pos
|
|
||||||
cur_data = data[:remain]
|
|
||||||
cur_data_len = len(cur_data)
|
|
||||||
cur_stream = self._stream[self._pos:self._pos + cur_data_len]
|
|
||||||
self._pos = self._pos + cur_data_len
|
|
||||||
data = data[remain:]
|
|
||||||
|
|
||||||
results.append(numpy_xor(cur_data, cur_stream))
|
|
||||||
|
|
||||||
if self._pos >= BLOCK_SIZE:
|
|
||||||
self._next_stream()
|
|
||||||
self._pos = 0
|
|
||||||
if not data:
|
|
||||||
break
|
|
||||||
return b''.join(results)
|
|
||||||
|
|
||||||
|
|
||||||
ciphers = {
|
|
||||||
b'salsa20-ctr': (32, 8, Salsa20Cipher),
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
def test():
|
|
||||||
from shadowsocks.crypto import util
|
|
||||||
|
|
||||||
cipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)
|
|
||||||
decipher = Salsa20Cipher(b'salsa20-ctr', b'k' * 32, b'i' * 8, 1)
|
|
||||||
|
|
||||||
util.run_cipher(cipher, decipher)
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
|
||||||
test()
|
|
||||||
@@ -23,10 +23,11 @@
|
|||||||
from __future__ import absolute_import, division, print_function, \
|
from __future__ import absolute_import, division, print_function, \
|
||||||
with_statement
|
with_statement
|
||||||
|
|
||||||
import logging
|
from ctypes import c_char_p, c_int, c_ulonglong, byref, \
|
||||||
from ctypes import CDLL, c_char_p, c_int, c_ulonglong, byref, \
|
|
||||||
create_string_buffer, c_void_p
|
create_string_buffer, c_void_p
|
||||||
|
|
||||||
|
from shadowsocks.crypto import util
|
||||||
|
|
||||||
__all__ = ['ciphers']
|
__all__ = ['ciphers']
|
||||||
|
|
||||||
libsodium = None
|
libsodium = None
|
||||||
@@ -41,16 +42,11 @@ BLOCK_SIZE = 64
|
|||||||
def load_libsodium():
|
def load_libsodium():
|
||||||
global loaded, libsodium, buf
|
global loaded, libsodium, buf
|
||||||
|
|
||||||
from ctypes.util import find_library
|
libsodium = util.find_library('sodium', 'crypto_stream_salsa20_xor_ic',
|
||||||
for p in ('sodium', 'libsodium'):
|
'libsodium')
|
||||||
libsodium_path = find_library(p)
|
if libsodium is None:
|
||||||
if libsodium_path:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
raise Exception('libsodium not found')
|
raise Exception('libsodium not found')
|
||||||
logging.info('loading libsodium from %s', libsodium_path)
|
|
||||||
libsodium = CDLL(libsodium_path)
|
|
||||||
libsodium.sodium_init.restype = c_int
|
|
||||||
libsodium.crypto_stream_salsa20_xor_ic.restype = c_int
|
libsodium.crypto_stream_salsa20_xor_ic.restype = c_int
|
||||||
libsodium.crypto_stream_salsa20_xor_ic.argtypes = (c_void_p, c_char_p,
|
libsodium.crypto_stream_salsa20_xor_ic.argtypes = (c_void_p, c_char_p,
|
||||||
c_ulonglong,
|
c_ulonglong,
|
||||||
@@ -62,13 +58,11 @@ def load_libsodium():
|
|||||||
c_char_p, c_ulonglong,
|
c_char_p, c_ulonglong,
|
||||||
c_char_p)
|
c_char_p)
|
||||||
|
|
||||||
libsodium.sodium_init()
|
|
||||||
|
|
||||||
buf = create_string_buffer(buf_size)
|
buf = create_string_buffer(buf_size)
|
||||||
loaded = True
|
loaded = True
|
||||||
|
|
||||||
|
|
||||||
class Salsa20Crypto(object):
|
class SodiumCrypto(object):
|
||||||
def __init__(self, cipher_name, key, iv, op):
|
def __init__(self, cipher_name, key, iv, op):
|
||||||
if not loaded:
|
if not loaded:
|
||||||
load_libsodium()
|
load_libsodium()
|
||||||
@@ -107,25 +101,22 @@ class Salsa20Crypto(object):
|
|||||||
|
|
||||||
|
|
||||||
ciphers = {
|
ciphers = {
|
||||||
b'salsa20': (32, 8, Salsa20Crypto),
|
b'salsa20': (32, 8, SodiumCrypto),
|
||||||
b'chacha20': (32, 8, Salsa20Crypto),
|
b'chacha20': (32, 8, SodiumCrypto),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def test_salsa20():
|
def test_salsa20():
|
||||||
from shadowsocks.crypto import util
|
cipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 1)
|
||||||
|
decipher = SodiumCrypto(b'salsa20', b'k' * 32, b'i' * 16, 0)
|
||||||
cipher = Salsa20Crypto(b'salsa20', b'k' * 32, b'i' * 16, 1)
|
|
||||||
decipher = Salsa20Crypto(b'salsa20', b'k' * 32, b'i' * 16, 0)
|
|
||||||
|
|
||||||
util.run_cipher(cipher, decipher)
|
util.run_cipher(cipher, decipher)
|
||||||
|
|
||||||
|
|
||||||
def test_chacha20():
|
def test_chacha20():
|
||||||
from shadowsocks.crypto import util
|
|
||||||
|
|
||||||
cipher = Salsa20Crypto(b'chacha20', b'k' * 32, b'i' * 16, 1)
|
cipher = SodiumCrypto(b'chacha20', b'k' * 32, b'i' * 16, 1)
|
||||||
decipher = Salsa20Crypto(b'chacha20', b'k' * 32, b'i' * 16, 0)
|
decipher = SodiumCrypto(b'chacha20', b'k' * 32, b'i' * 16, 0)
|
||||||
|
|
||||||
util.run_cipher(cipher, decipher)
|
util.run_cipher(cipher, decipher)
|
||||||
|
|
||||||
@@ -20,6 +20,62 @@
|
|||||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
# SOFTWARE.
|
# SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function, \
|
||||||
|
with_statement
|
||||||
|
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
|
def find_library(possible_lib_names, search_symbol, library_name):
|
||||||
|
import ctypes.util
|
||||||
|
from ctypes import CDLL
|
||||||
|
|
||||||
|
paths = []
|
||||||
|
|
||||||
|
if type(possible_lib_names) not in (list, tuple):
|
||||||
|
possible_lib_names = [possible_lib_names]
|
||||||
|
|
||||||
|
lib_names = []
|
||||||
|
for lib_name in possible_lib_names:
|
||||||
|
lib_names.append(lib_name)
|
||||||
|
lib_names.append('lib' + lib_name)
|
||||||
|
|
||||||
|
for name in lib_names:
|
||||||
|
path = ctypes.util.find_library(name)
|
||||||
|
if path:
|
||||||
|
paths.append(path)
|
||||||
|
|
||||||
|
if not paths:
|
||||||
|
# We may get here when find_library fails because, for example,
|
||||||
|
# the user does not have sufficient privileges to access those
|
||||||
|
# tools underlying find_library on linux.
|
||||||
|
import glob
|
||||||
|
|
||||||
|
for name in lib_names:
|
||||||
|
patterns = [
|
||||||
|
'/usr/local/lib*/lib%s.*' % name,
|
||||||
|
'/usr/lib*/lib%s.*' % name,
|
||||||
|
'lib%s.*' % name,
|
||||||
|
'%s.dll' % name,
|
||||||
|
'lib%s.dll' % name]
|
||||||
|
|
||||||
|
for pat in patterns:
|
||||||
|
files = glob.glob(pat)
|
||||||
|
if files:
|
||||||
|
paths.extend(files)
|
||||||
|
for path in paths:
|
||||||
|
try:
|
||||||
|
lib = CDLL(path)
|
||||||
|
if hasattr(lib, search_symbol):
|
||||||
|
logging.info('loading %s from %s', library_name, path)
|
||||||
|
return lib
|
||||||
|
else:
|
||||||
|
logging.warn('can\'t find symbol %s in %s', search_symbol,
|
||||||
|
path)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def run_cipher(cipher, decipher):
|
def run_cipher(cipher, decipher):
|
||||||
from os import urandom
|
from os import urandom
|
||||||
@@ -49,3 +105,19 @@ def run_cipher(cipher, decipher):
|
|||||||
end = time.time()
|
end = time.time()
|
||||||
print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start)))
|
print('speed: %d bytes/s' % (BLOCK_SIZE * rounds / (end - start)))
|
||||||
assert b''.join(results) == plain
|
assert b''.join(results) == plain
|
||||||
|
|
||||||
|
|
||||||
|
def test_find_library():
|
||||||
|
assert find_library('c', 'strcpy', 'libc') is not None
|
||||||
|
assert find_library(['c'], 'strcpy', 'libc') is not None
|
||||||
|
assert find_library(('c',), 'strcpy', 'libc') is not None
|
||||||
|
assert find_library(('crypto', 'eay32'), 'EVP_CipherUpdate',
|
||||||
|
'libcrypto') is not None
|
||||||
|
assert find_library('notexist', 'strcpy', 'libnotexist') is None
|
||||||
|
assert find_library('c', 'symbol_not_exist', 'c') is None
|
||||||
|
assert find_library(('notexist', 'c', 'crypto', 'eay32'),
|
||||||
|
'EVP_CipherUpdate', 'libc') is not None
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_find_library()
|
||||||
|
|||||||
+4
-12
@@ -28,26 +28,18 @@ import sys
|
|||||||
import hashlib
|
import hashlib
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from shadowsocks.crypto import m2, rc4_md5, salsa20_ctr,\
|
from shadowsocks.crypto import rc4_md5, openssl, sodium, table
|
||||||
ctypes_openssl, ctypes_libsodium, table
|
|
||||||
|
|
||||||
|
|
||||||
method_supported = {}
|
method_supported = {}
|
||||||
method_supported.update(rc4_md5.ciphers)
|
method_supported.update(rc4_md5.ciphers)
|
||||||
method_supported.update(salsa20_ctr.ciphers)
|
method_supported.update(openssl.ciphers)
|
||||||
method_supported.update(ctypes_openssl.ciphers)
|
method_supported.update(sodium.ciphers)
|
||||||
method_supported.update(ctypes_libsodium.ciphers)
|
|
||||||
# let M2Crypto override ctypes_openssl
|
|
||||||
method_supported.update(m2.ciphers)
|
|
||||||
method_supported.update(table.ciphers)
|
method_supported.update(table.ciphers)
|
||||||
|
|
||||||
|
|
||||||
def random_string(length):
|
def random_string(length):
|
||||||
try:
|
return os.urandom(length)
|
||||||
import M2Crypto.Rand
|
|
||||||
return M2Crypto.Rand.rand_bytes(length)
|
|
||||||
except ImportError:
|
|
||||||
return os.urandom(length)
|
|
||||||
|
|
||||||
|
|
||||||
cached_keys = {}
|
cached_keys = {}
|
||||||
|
|||||||
@@ -232,8 +232,9 @@ class EventLoop(object):
|
|||||||
logging.error(e)
|
logging.error(e)
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
for handler in self._handlers_to_remove:
|
if self._handlers_to_remove:
|
||||||
self._handlers.remove(handler)
|
for handler in self._handlers_to_remove:
|
||||||
|
self._handlers.remove(handler)
|
||||||
self._handlers_to_remove = []
|
self._handlers_to_remove = []
|
||||||
self._iterating = False
|
self._iterating = False
|
||||||
|
|
||||||
|
|||||||
+20
-5
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/python
|
#!/usr/bin/python
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2014 clowwindy
|
# Copyright (c) 2015 clowwindy
|
||||||
#
|
#
|
||||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
# of this software and associated documentation files (the "Software"), to deal
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
@@ -121,7 +121,12 @@ class TCPRelayHandler(object):
|
|||||||
self._data_to_write_to_remote = []
|
self._data_to_write_to_remote = []
|
||||||
self._upstream_status = WAIT_STATUS_READING
|
self._upstream_status = WAIT_STATUS_READING
|
||||||
self._downstream_status = WAIT_STATUS_INIT
|
self._downstream_status = WAIT_STATUS_INIT
|
||||||
|
self._client_address = local_sock.getpeername()[:2]
|
||||||
self._remote_address = None
|
self._remote_address = None
|
||||||
|
if 'forbidden_ip' in config:
|
||||||
|
self._forbidden_iplist = config['forbidden_ip']
|
||||||
|
else:
|
||||||
|
self._forbidden_iplist = None
|
||||||
if is_local:
|
if is_local:
|
||||||
self._chosen_server = self._get_a_server()
|
self._chosen_server = self._get_a_server()
|
||||||
fd_to_handlers[local_sock.fileno()] = self
|
fd_to_handlers[local_sock.fileno()] = self
|
||||||
@@ -294,8 +299,9 @@ class TCPRelayHandler(object):
|
|||||||
if header_result is None:
|
if header_result is None:
|
||||||
raise Exception('can not parse header')
|
raise Exception('can not parse header')
|
||||||
addrtype, remote_addr, remote_port, header_length = header_result
|
addrtype, remote_addr, remote_port, header_length = header_result
|
||||||
logging.info('connecting %s:%d' % (common.to_str(remote_addr),
|
logging.info('connecting %s:%d from %s:%d' %
|
||||||
remote_port))
|
(common.to_str(remote_addr), remote_port,
|
||||||
|
self._client_address[0], self._client_address[1]))
|
||||||
self._remote_address = (remote_addr, remote_port)
|
self._remote_address = (remote_addr, remote_port)
|
||||||
# pause reading
|
# pause reading
|
||||||
self._update_stream(STREAM_UP, WAIT_STATUS_WRITING)
|
self._update_stream(STREAM_UP, WAIT_STATUS_WRITING)
|
||||||
@@ -317,7 +323,7 @@ class TCPRelayHandler(object):
|
|||||||
self._dns_resolver.resolve(remote_addr,
|
self._dns_resolver.resolve(remote_addr,
|
||||||
self._handle_dns_resolved)
|
self._handle_dns_resolved)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logging.error(e)
|
self._log_error(e)
|
||||||
if self._config['verbose']:
|
if self._config['verbose']:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
# TODO use logging when debug completed
|
# TODO use logging when debug completed
|
||||||
@@ -329,6 +335,10 @@ class TCPRelayHandler(object):
|
|||||||
if len(addrs) == 0:
|
if len(addrs) == 0:
|
||||||
raise Exception("getaddrinfo failed for %s:%d" % (ip, port))
|
raise Exception("getaddrinfo failed for %s:%d" % (ip, port))
|
||||||
af, socktype, proto, canonname, sa = addrs[0]
|
af, socktype, proto, canonname, sa = addrs[0]
|
||||||
|
if self._forbidden_iplist:
|
||||||
|
if common.to_str(sa[0]) in self._forbidden_iplist:
|
||||||
|
raise Exception('IP %s is in forbidden list, reject' %
|
||||||
|
common.to_str(sa[0]))
|
||||||
remote_sock = socket.socket(af, socktype, proto)
|
remote_sock = socket.socket(af, socktype, proto)
|
||||||
self._remote_sock = remote_sock
|
self._remote_sock = remote_sock
|
||||||
self._fd_to_handlers[remote_sock.fileno()] = self
|
self._fd_to_handlers[remote_sock.fileno()] = self
|
||||||
@@ -338,12 +348,13 @@ class TCPRelayHandler(object):
|
|||||||
|
|
||||||
def _handle_dns_resolved(self, result, error):
|
def _handle_dns_resolved(self, result, error):
|
||||||
if error:
|
if error:
|
||||||
logging.error(error)
|
self._log_error(error)
|
||||||
self.destroy()
|
self.destroy()
|
||||||
return
|
return
|
||||||
if result:
|
if result:
|
||||||
ip = result[1]
|
ip = result[1]
|
||||||
if ip:
|
if ip:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
self._stage = STAGE_CONNECTING
|
self._stage = STAGE_CONNECTING
|
||||||
remote_addr = ip
|
remote_addr = ip
|
||||||
@@ -507,6 +518,10 @@ class TCPRelayHandler(object):
|
|||||||
else:
|
else:
|
||||||
logging.warn('unknown socket')
|
logging.warn('unknown socket')
|
||||||
|
|
||||||
|
def _log_error(self, e):
|
||||||
|
logging.error('%s when handling connection from %s:%d' %
|
||||||
|
(e, self._client_address[0], self._client_address[1]))
|
||||||
|
|
||||||
def destroy(self):
|
def destroy(self):
|
||||||
# destroy the handler and release any resources
|
# destroy the handler and release any resources
|
||||||
# promises:
|
# promises:
|
||||||
|
|||||||
@@ -112,6 +112,10 @@ class UDPRelay(object):
|
|||||||
self._closed = False
|
self._closed = False
|
||||||
self._last_time = time.time()
|
self._last_time = time.time()
|
||||||
self._sockets = set()
|
self._sockets = set()
|
||||||
|
if 'forbidden_ip' in config:
|
||||||
|
self._forbidden_iplist = config['forbidden_ip']
|
||||||
|
else:
|
||||||
|
self._forbidden_iplist = None
|
||||||
|
|
||||||
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0,
|
addrs = socket.getaddrinfo(self._listen_addr, self._listen_port, 0,
|
||||||
socket.SOCK_DGRAM, socket.SOL_UDP)
|
socket.SOCK_DGRAM, socket.SOL_UDP)
|
||||||
@@ -178,6 +182,12 @@ class UDPRelay(object):
|
|||||||
socket.SOCK_DGRAM, socket.SOL_UDP)
|
socket.SOCK_DGRAM, socket.SOL_UDP)
|
||||||
if addrs:
|
if addrs:
|
||||||
af, socktype, proto, canonname, sa = addrs[0]
|
af, socktype, proto, canonname, sa = addrs[0]
|
||||||
|
if self._forbidden_iplist:
|
||||||
|
if common.to_str(sa[0]) in self._forbidden_iplist:
|
||||||
|
logging.debug('IP %s is in forbidden list, drop' %
|
||||||
|
common.to_str(sa[0]))
|
||||||
|
# drop
|
||||||
|
return
|
||||||
client = socket.socket(af, socktype, proto)
|
client = socket.socket(af, socktype, proto)
|
||||||
client.setblocking(False)
|
client.setblocking(False)
|
||||||
self._cache[key] = client
|
self._cache[key] = client
|
||||||
|
|||||||
@@ -100,7 +100,8 @@ def get_config(is_local):
|
|||||||
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=']
|
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=']
|
||||||
else:
|
else:
|
||||||
shortopts = 'hd:s:p:k:m:c:t:vq'
|
shortopts = 'hd:s:p:k:m:c:t:vq'
|
||||||
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=']
|
longopts = ['help', 'fast-open', 'pid-file=', 'log-file=', 'workers=',
|
||||||
|
'forbidden-ip=']
|
||||||
try:
|
try:
|
||||||
config_path = find_config()
|
config_path = find_config()
|
||||||
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
optlist, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
|
||||||
@@ -146,6 +147,8 @@ def get_config(is_local):
|
|||||||
config['fast_open'] = True
|
config['fast_open'] = True
|
||||||
elif key == '--workers':
|
elif key == '--workers':
|
||||||
config['workers'] = int(value)
|
config['workers'] = int(value)
|
||||||
|
elif key == '--forbidden-ip':
|
||||||
|
config['forbidden_ip'] = to_str(value).split(',')
|
||||||
elif key in ('-h', '--help'):
|
elif key in ('-h', '--help'):
|
||||||
if is_local:
|
if is_local:
|
||||||
print_local_help()
|
print_local_help()
|
||||||
@@ -172,7 +175,7 @@ def get_config(is_local):
|
|||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
config['password'] = config.get('password', '')
|
config['password'] = config.get('password', '')
|
||||||
config['method'] = config.get('method', 'aes-256-cfb')
|
config['method'] = config.get('method', b'aes-256-cfb')
|
||||||
config['port_password'] = config.get('port_password', None)
|
config['port_password'] = config.get('port_password', None)
|
||||||
config['timeout'] = int(config.get('timeout', 300))
|
config['timeout'] = int(config.get('timeout', 300))
|
||||||
config['fast_open'] = config.get('fast_open', False)
|
config['fast_open'] = config.get('fast_open', False)
|
||||||
@@ -264,7 +267,7 @@ General options:
|
|||||||
-v, -vv verbose mode
|
-v, -vv verbose mode
|
||||||
-q, -qq quiet mode, only show warnings/errors
|
-q, -qq quiet mode, only show warnings/errors
|
||||||
|
|
||||||
Online help: <https://github.com/clowwindy/shadowsocks>
|
Online help: <https://github.com/shadowsocks/shadowsocks>
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
@@ -286,6 +289,7 @@ Proxy options:
|
|||||||
-t TIMEOUT timeout in seconds, default: 300
|
-t TIMEOUT timeout in seconds, default: 300
|
||||||
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
|
--fast-open use TCP_FASTOPEN, requires Linux 3.7+
|
||||||
--workers WORKERS number of workers, available on Unix/Linux
|
--workers WORKERS number of workers, available on Unix/Linux
|
||||||
|
--forbidden-ip IPLIST comma seperated IP list forbidden to connect
|
||||||
|
|
||||||
General options:
|
General options:
|
||||||
-d start/stop/restart daemon mode
|
-d start/stop/restart daemon mode
|
||||||
@@ -294,7 +298,7 @@ General options:
|
|||||||
-v, -vv verbose mode
|
-v, -vv verbose mode
|
||||||
-q, -qq quiet mode, only show warnings/errors
|
-q, -qq quiet mode, only show warnings/errors
|
||||||
|
|
||||||
Online help: <https://github.com/clowwindy/shadowsocks>
|
Online help: <https://github.com/shadowsocks/shadowsocks>
|
||||||
''')
|
''')
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+21
-8
@@ -40,6 +40,9 @@ parser.add_argument('-s', '--server-conf', type=str, default=None)
|
|||||||
parser.add_argument('-a', '--client-args', type=str, default=None)
|
parser.add_argument('-a', '--client-args', type=str, default=None)
|
||||||
parser.add_argument('-b', '--server-args', type=str, default=None)
|
parser.add_argument('-b', '--server-args', type=str, default=None)
|
||||||
parser.add_argument('--with-coverage', action='store_true', default=None)
|
parser.add_argument('--with-coverage', action='store_true', default=None)
|
||||||
|
parser.add_argument('--should-fail', action='store_true', default=None)
|
||||||
|
parser.add_argument('--url', type=str, default='http://www.example.com/')
|
||||||
|
parser.add_argument('--dns', type=str, default='8.8.8.8')
|
||||||
|
|
||||||
config = parser.parse_args()
|
config = parser.parse_args()
|
||||||
|
|
||||||
@@ -94,7 +97,7 @@ try:
|
|||||||
stage = 5
|
stage = 5
|
||||||
if bytes != str:
|
if bytes != str:
|
||||||
line = str(line, 'utf8')
|
line = str(line, 'utf8')
|
||||||
sys.stdout.write(line)
|
sys.stderr.write(line)
|
||||||
if line.find('starting local') >= 0:
|
if line.find('starting local') >= 0:
|
||||||
local_ready = True
|
local_ready = True
|
||||||
if line.find('starting server') >= 0:
|
if line.find('starting server') >= 0:
|
||||||
@@ -103,7 +106,7 @@ try:
|
|||||||
if stage == 1:
|
if stage == 1:
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
p3 = Popen(['curl', 'http://www.example.com/', '-v', '-L',
|
p3 = Popen(['curl', config.url, '-v', '-L',
|
||||||
'--socks5-hostname', '127.0.0.1:1081',
|
'--socks5-hostname', '127.0.0.1:1081',
|
||||||
'-m', '15', '--connect-timeout', '10'],
|
'-m', '15', '--connect-timeout', '10'],
|
||||||
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
||||||
@@ -118,9 +121,14 @@ try:
|
|||||||
fdset.remove(p3.stdout)
|
fdset.remove(p3.stdout)
|
||||||
fdset.remove(p3.stderr)
|
fdset.remove(p3.stderr)
|
||||||
r = p3.wait()
|
r = p3.wait()
|
||||||
if r != 0:
|
if config.should_fail:
|
||||||
sys.exit(1)
|
if r == 0:
|
||||||
p4 = Popen(['socksify', 'dig', '@8.8.8.8', 'www.google.com'],
|
sys.exit(1)
|
||||||
|
else:
|
||||||
|
if r != 0:
|
||||||
|
sys.exit(1)
|
||||||
|
p4 = Popen(['socksify', 'dig', '@%s' % config.dns,
|
||||||
|
'www.google.com'],
|
||||||
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=True)
|
||||||
if p4 is not None:
|
if p4 is not None:
|
||||||
fdset.append(p4.stdout)
|
fdset.append(p4.stdout)
|
||||||
@@ -131,9 +139,14 @@ try:
|
|||||||
|
|
||||||
if stage == 5:
|
if stage == 5:
|
||||||
r = p4.wait()
|
r = p4.wait()
|
||||||
if r != 0:
|
if config.should_fail:
|
||||||
sys.exit(1)
|
if r == 0:
|
||||||
print('test passed')
|
sys.exit(1)
|
||||||
|
print('test passed (expecting failure)')
|
||||||
|
else:
|
||||||
|
if r != 0:
|
||||||
|
sys.exit(1)
|
||||||
|
print('test passed')
|
||||||
break
|
break
|
||||||
finally:
|
finally:
|
||||||
for p in [p1, p2]:
|
for p in [p1, p2]:
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
Useful Tools
|
||||||
|
===========
|
||||||
|
|
||||||
|
autoban.py
|
||||||
|
----------
|
||||||
|
|
||||||
|
Automatically ban IPs that try to brute force crack the server.
|
||||||
|
|
||||||
|
See https://github.com/shadowsocks/shadowsocks/wiki/Ban-Brute-Force-Crackers
|
||||||
Executable
+51
@@ -0,0 +1,51 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
# Copyright (c) 2015 clowwindy
|
||||||
|
#
|
||||||
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
# of this software and associated documentation files (the "Software"), to deal
|
||||||
|
# in the Software without restriction, including without limitation the rights
|
||||||
|
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
# copies of the Software, and to permit persons to whom the Software is
|
||||||
|
# furnished to do so, subject to the following conditions:
|
||||||
|
#
|
||||||
|
# The above copyright notice and this permission notice shall be included in
|
||||||
|
# all copies or substantial portions of the Software.
|
||||||
|
#
|
||||||
|
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
# SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import absolute_import, division, print_function, \
|
||||||
|
with_statement
|
||||||
|
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser(description='See README')
|
||||||
|
parser.add_argument('-c', '--count', default=3, type=int,
|
||||||
|
help='with how many failure times it should be '
|
||||||
|
'considered as an attack')
|
||||||
|
config = parser.parse_args()
|
||||||
|
ips = {}
|
||||||
|
banned = set()
|
||||||
|
for line in sys.stdin:
|
||||||
|
if 'can not parse header when' in line:
|
||||||
|
ip = line.split()[-1].split(':')[0]
|
||||||
|
if ip not in ips:
|
||||||
|
ips[ip] = 1
|
||||||
|
print(ip)
|
||||||
|
else:
|
||||||
|
ips[ip] += 1
|
||||||
|
if ip not in banned and ips[ip] >= config.count:
|
||||||
|
banned.add(ip)
|
||||||
|
cmd = 'iptables -A INPUT -s %s -j DROP' % ip
|
||||||
|
print(cmd, file=sys.stderr)
|
||||||
|
os.system(cmd)
|
||||||
Reference in New Issue
Block a user