Total Pageviews

Thursday, 15 March 2018

成功利用Lightsocks-Python翻墙

一个轻量级网络混淆代理,基于 SOCKS5 协议,可用来代替 Shadowsocks。
  • 只专注于混淆,用最简单高效的混淆算法达到目的;
  • Python3.6 asyncio实现;
本项目为你也能写个 Shadowsocks程序- Lightsocks的Python实现。

安装

python版本需为最新的3.6。
(首先编译python3.6.4环境:
wget https://www.python.org/ftp/python/3.6.4/Python-3.6.4.tgz
tar zxvf Python-3.6.4.tgz
cd Python-3.6.4


./configure --prefix=/usr/local/python-3.6.4
make 
make install
echo 'export PATH=$PATH:/usr/local/python-3.6.4/bin' >> /etc/profile
. /etc/profile

至此python3.6.4环境就搭建好了)
 

git clone https://github.com/linw1995/lightsocks-python
cd lightsocks-python
pip3.6 install -r requirements.txt

使用

lsserver

用于运行在代理服务器的客户端,会还原混淆数据
$ python3.6 lsserver.py -h
usage: lsserver.py [-h] [--version] [--save CONFIG] [-c CONFIG]
                   [-s SERVER_ADDR] [-p SERVER_PORT] [-k PASSWORD] [--random]

A light tunnel proxy that helps you bypass firewalls

optional arguments:
  -h, --help      show this help message and exit
  --version       show version information

Proxy options:
  --save CONFIG   path to dump config
  -c CONFIG       path to config file
  -s SERVER_ADDR  server address, default: 0.0.0.0
  -p SERVER_PORT  server port, default: 8388
  -k PASSWORD     password
  --random        generate a random password to use
$ python3.6 lsserver.py --random --save config.json
generate random password
dump config file into 'config.json'
Listen to 0.0.0.0:8388

Please use:

lslocal -u "http://hostname:port/#一串字符"

to config lslocal
 
(命令python3.6 lsserver.py --random --save config.json是在前台运行的,此命令
会在当前目录下生成config.json文件。
暂时按ctl+c,退出运行此命令。然后,
nano config.json
把serverPort的值改为8488
不要修改password的值。然后运行:
python3.6 lsserver.py -c config.json
会显示:
Listen to 0.0.0.0:8488

Please use:

lslocal -u "http://hostname:port/#一串字符"

to config lslocal
 
这条命令python3.6 lsserver.py -c config.json也是在前台运行的,
暂时按ctl+c,退出运行此命令。我们可用systemd把该命令运行为service:
nano /etc/systemd/system/lightsocks-python.service
内容如下:
[Unit]
Description=lightsocks-python
After=network.target

[Service]
ExecStart=/usr/local/python-3.6.4/bin/python3.6 /root/lightsocks-python/lsserver.py -c /root/lightsocks-python/config.json
Restart=always

[Install]
WantedBy=multi-user.target 


启动lightsocks-python
systemctl daemon-reload 
systemctl start lightsocks-python
这其实就是以daemon(service)方式启动lightsocks-python程序
 
验证一下,有无进程占用8488端口:
root@ar:~# lsof -i:8488
COMMAND    PID USER   FD   TYPE     DEVICE SIZE/OFF NODE NAME
python3.6 4221 root    7u  IPv4 1021830669      0t0  TCP *:8488 (LISTEN)
root@ar:~# 
 
设置开机启动lightsocks-python
systemctl enable lightsocks-python
 
至此,lightsocks-python服务器端的配置已经全部完成. ) 
 

lslocal

用于运行在本地电脑的客户端,用于桥接本地浏览器和远程代理服务,传输前会混淆数据
$ python lslocal.py -h
usage: lslocal.py [-h] [--version] [--save CONFIG] [-c CONFIG] [-u URL]
                  [-s SERVER_ADDR] [-p SERVER_PORT] [-b LOCAL_ADDR]
                  [-l LOCAL_PORT] [-k PASSWORD]

A light tunnel proxy that helps you bypass firewalls

optional arguments:
  -h, --help      show this help message and exit
  --version       show version information

Proxy options:
  --save CONFIG   path to dump config
  -c CONFIG       path to config file
  -u URL          url contains server address, port and password
  -s SERVER_ADDR  server address
  -p SERVER_PORT  server port, default: 8388
  -b LOCAL_ADDR   local binding address, default: 127.0.0.1
  -l LOCAL_PORT   local port, default: 1080
  -k PASSWORD     password
$ python lslocal.py -u "http://remoteAddr:remotePort/#password" --save config.json
dump config file into 'config.json'
Listen to 127.0.0.1:1080
(在本地的mac机器上,
brew install python3 
git clone https://github.com/linw1995/lightsocks-python
cd lightsocks-python
pip3.6 install -r requirements.txt
python3.6 lslocal.py -u "http://your_vps_ip:8488/#一串字符" -l 1084
会显示:
Listen to 127.0.0.1:1084

上面的“一串字符"就是服务器上的/root/lightsocks-python/config.json文件里的password
的值。
 
客户端的命令行程序也可这样运行:
python3.6 lslocal.py -s server_ip -p 8488 -l 1084 -k 一串字符
 
然后设置本地机器上的浏览器的socks5代理服务器为127.0.0.1:1084 ,浏览器即可翻墙。)
 

项目地址 https://github.com/linw1995/lightsocks-python
https://github.com/linw1995/lightsocks-python/tree/master/lightsocks/core
里面的securesocket.py文件的内容有多处cipher字样,可见可能是做了加密处理
fork版:https://github.com/nanqinlang-mogic/lightsocks
---------
 
如果运行客户端命令后,遇到提示:'Too many open files',
请按ctl+c键,然后重新运行客户端命令:
python3.6 lslocal.py -u "http://your_vps_ip:8488/#一串字符" -l 1084或者:
python3.6 lslocal.py -s server_ip -p 8488 -l 1084 -k 一串字符
 
你可保存python3.6 lslocal.py -u "http://your_vps_ip:8488/#一串字符" -l 1084
为start.sh,以后运行sh start.sh就省事多了。
 
总结:此法Lightsocks-Python不如Lightsocks(go版)好用,Lightsocks(go版)不如
Lightsocks-nodejs好用。

No comments:

Post a Comment