6

安装 shadowsocks-libev启用 obfs 混淆

 3 years ago
source link: https://www.meirenji.info/2019/03/19/%E5%AE%89%E8%A3%85-shadowsocks-libev%E5%90%AF%E7%94%A8-obfs-%E6%B7%B7%E6%B7%86/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

安装 shadowsocks-libev启用 obfs 混淆

发表于 2019-03-19

| 分类于 科学上网

| 0 Comments

编译和安装 ss-libev

该版本的特点是内存占用小(600k左右),低 CPU 消耗,甚至可以安装在基于 OpenWRT 的路由器上。

相比原版Shadowsocks,libev(c#)版本提供了更多的特性支持;而关于ShadowsocksR(Python),

Shadowsocks-libev率先支持AEAD Cipher,并向ShadowsocksR学习引进了Obfs(Simple-Obfs),且提供稳定的周期性更新;

长远来看,ShadowsocksR更倾向于向none加密化和Obfs化发展,而Shadowsocks-libev则倾向于向强化Cipher的方向发展,两者有不同的侧重点。

简单来说,ShadowsocksR更侧重消除特征以更好穿过GFW,而Shadowsocks-libev则追求更高的安全性.并无优劣之分

加密,以下是四种常见的AEAD Cipher,相较OTA Cipher而言AEAD Cipher极大降低了被主动探测的风险,故推荐使用AEAD Cipher

aes-128-gcm
aes-192-gcm
aes-256-gcm
chacha20-ietf-poly1305

以及几种常用的OTA Cipher方式

rc4-md5
aes-128-cfb
aes-128-ctr

关于AEAD Cipher的选择,需要注意的是,虽然ARM早在2015就收购了Shadowsocks-libev依赖的加密库之一mbed tls,但至今mbed tls并未对ARMv8做出实质性的优化,导致AES GCM系Cipher在较新的64位移动设备上性能低下。相关的几种Cipher测试数据如下(From Blankwonder)

开启 bbr

yum install git vim wget -y
yum install epel-release -y
yum install gcc gettext autoconf libtool automake make pcre-devel asciidoc xmlto c-ares-devel libev-devel libsodium-devel mbedtls-devel -y

下载 shadowsocks-libev 的源代码:

git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init --recursive
./autogen.sh && ./configure --prefix=/usr && make
make install
  • 仅使用 shadowsocks-libev
mkdir -p /etc/shadowsocks-libev
vim /etc/shadowsocks-libev/config.json
/etc/shadowsocks-libev/config.json

{
"server":"0.0.0.0",
"server_port":自定端口号,
"local_port":1080,
"password":"自定密码",
"timeout":60,
"method":"aes-256-gcm"
}

如想要同时启用 ipv4 和 ipv6 ,则 config.json 应为

/etc/shadowsocks-libev/config.json

{
"server":["::0","0.0.0.0"],
"server_port":自定端口号,
"local_port":1080,
"password":"自定密码",
"timeout":60,
"method":"aes-256-gcm"
}

编译和安装 simple-obfs

yum install zlib-devel openssl-devel -y

git clone https://github.com/shadowsocks/simple-obfs.git
cd simple-obfs
git submodule update --init --recursive
./autogen.sh
./configure && make
make install

使用带 obfs 混淆的 shadowsocks-libev

/etc/shadowsocks-libev/config.json

{
"server":["::0","0.0.0.0"],
"server_port":自定端口号,
"local_port":1080,
"password":"自定密码",
"timeout":60,
"method":"aes-256-gcm",
"plugin":"obfs-server",
"plugin_opts":"obfs=tls"
}
{
"server":"0.0.0.0",
"server_port":443,
"local_port":1080,
"password":"********",
"timeout":600,
"method":"chacha20-ietf-poly1305",
"fast_open":true,
"plugin": "obfs-server",
"plugin_opts": "obfs=tls;obfs-host=iosapps.itunes.apple.com"
}
/etc/systemd/system/shadowsocks.service

[Unit]
Description=Shadowsocks Server
After=network.target

[Service]
ExecStart=/usr/bin/ss-server -c /etc/shadowsocks-libev/config.json -u
Restart=on-abort

[Install]
WantedBy=multi-user.target

Windows 客户端的使用方法:

下载后,解压出来的文件一定要和 Windows 客户端的 exe 文件放在同一文件夹下

插件:obfs-local
插件选项:obfs=tls
插件参数:obfs-host=www.bing.com

插件选项和插件参数根据你服务端上的配置选择用 http 或者 tls,obfs-host 随便你用什么网址都行

*混淆方式,主要分为tls,http两种,相比http,tls更具隐蔽性

*混淆域名,使用混淆时伪装的域名,一般选择大型企业,流量出入较大、CDN等未被墙的域名作为混淆域名(如伪装的特定端口下的IP或域名来免流),常用的混淆域名有这些

cloudfront.com
cloudflare.com
itunes.apple.com
www.icloud.com
ajax.microsoft.com
apps.bdimg.com

Shadowsocks for Windows 不支持TCP Fast Open,但是simple-obfs的服务端和客户端都支持,是 –fast-open 参数。

因此,你只需要在服务端关闭shadowsocks-libev的TCP Fast Open,然后开启simple-obfs的TCP Fast Open,并在客户端的simple-obfs中启用 –fast-open 即可。

服务器端的配置文件除了原有内容,应该附加:

"plugin":"obfs-server",
"plugin_opts":"obfs=tls;fast-open=true"

## 客户端的配置文件除了原有内容,应该附加:

"plugin": "obfs-local",
"plugin_opts": "obfs=tls",
"plugin_args": "obfs-host=www.bing.com;fast-open=true",


ps -ef | grep -v grep | grep "server"

关闭防火墙

systemctl stop shadowsocks

在 shadowsocks-libev 目录下:

git pull
./configure
make
make install
在 simple-obfs 目录下:

git pull
./configure
make
make install
systemctl start shadowsocks

多用户设置

{
“server”:”your_server_ip”,
“local_address”: “127.0.0.1”,
“local_port”:1080,
“port_password”:{
“8989”:”password0”,
“9001”:”password1”,
“9002”:”password2”,
“9003”:”password3”,
“9004”:”password4”
},
“timeout”:300,
“method”:”aes-256-cfb”,
“fast_open”: true
}

基于kvm架构vps的优化这方面SS给出了非常详尽的优化指南,主要有:优化内核参数,开启TCP Fast Open

  • TCP Fast Open

主要通过第一次TCP握手后服务器产生Cookie作为后续TCP连接的认证信息,客户端通过TCP再次连接到服务器时,可以在SYN报文携带数据(RFC793),降低了握手频率,可避免恶意攻击并大幅降低网络延迟(参考);

## 如果 TCPFastOpenPassive 在增长,表示接受到了fast open的tcp连接

grep '^TcpExt:' /proc/net/netstat | cut -d ' ' -f 91-96 | column -t
echo "net.ipv4.tcp_fastopen = 3" >> /etc/sysctl.conf

#运行以上命令,设置IPv4下的TFO默认为开启状态

sysctl -e -p

#运行以上命令,应用配置

#将网络拥塞队列算法设置为性能和延迟最佳的fq_codel
net.core.default_qdisc = fq

net.ipv4.tcp_congestion_control = bbr

net.ipv4.tcp_fastopen = 3
  • TCP优化: 修改文件句柄数限制

限制用户档案的体积大小,提高系统稳定性

修改vi /etc/security/limits.conf文件,加入

*               soft    nofile           512000 #用户档案警告体积大小(bytes)
* hard nofile 1024000 #用户档案最大体积大小(bytes)

修改vi /etc/profile文件,加入

ulimit -SHn 1024000

然后重启服务器执行ulimit -n,查询返回1024000即可。

TCP的各种优化

涉及内核控制,TCP包大小,TCP转发,连接超时等优化

net.core.rmem_max = 12582912
#设置内核接收Socket的最大长度(bytes)
net.core.wmem_max = 12582912
#设置内核发送Socket的最大长度(bytes)
net.ipv4.tcp_rmem = 10240 87380 12582912
#设置TCP Socket接收长度的最小值,预留值,最大值(bytes)
net.ipv4.tcp_rmem = 10240 87380 12582912
#设置TCP Socket发送长度的最小值,预留值,最大值(bytes)
net.ipv4.ip_forward = 1
#开启所有网络设备的IPv4流量转发,用于支持IPv4的正常访问
net.ipv4.tcp_syncookies = 1
#开启SYN Cookie,用于防范SYN队列溢出后可能收到的攻击
net.ipv4.tcp_tw_reuse = 1
#允许将等待中的Socket重新用于新的TCP连接,提高TCP性能
net.ipv4.tcp_tw_recycle = 0
#禁止将等待中的Socket快速回收,提高TCP的稳定性
net.ipv4.tcp_fin_timeout = 30
#设置客户端断开Sockets连接后TCP在FIN等待状态的实际(s),保证性能
net.ipv4.tcp_keepalive_time = 1200
#设置TCP发送keepalive数据包的频率,影响TCP链接保留时间(s),保证性能
net.ipv4.tcp_mtu_probing = 1
#开启TCP层的MTU主动探测,提高网络速度
net.ipv4.conf.all.accept_source_route = 1
net.ipv4.conf.default.accept_source_route = 1
#允许接收IPv4环境下带有路由信息的数据包,保证安全性
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
#拒绝接收来自IPv4的ICMP重定向消息,保证安全性
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.lo.send_redirects = 0
#禁止发送在IPv4下的ICMP重定向消息,保证安全性
net.ipv4.conf.all.rp_filter = 0
net.ipv4.conf.default.rp_filter = 0
net.ipv4.conf.lo.rp_filter = 0
#关闭反向路径回溯进行源地址验证(RFC1812),提高性能
net.ipv4.icmp_echo_ignore_broadcasts = 1
#忽略所有ICMP ECHO请求的广播,保证安全性
net.ipv4.icmp_ignore_bogus_error_responses = 1
#忽略违背RFC1122标准的伪造广播帧,保证安全性
net.ipv6.conf.all.accept_source_route = 1
net.ipv6.conf.default.accept_source_route = 1
#允许接收IPv6环境下带有路由信息的数据包,保证安全性
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
#禁止接收来自IPv6下的ICMPv6重定向消息,保证安全性
net.ipv6.conf.all.autoconf = 1
#开启自动设定本地连接地址,用于支持IPv6地址的正常分配
net.ipv6.conf.all.forwarding = 1
#开启所有网络设备的IPv6流量转发,用于支持IPv6的正常访问
  • Web Server的伪装(使用TCP80或TCP443为端口的Shadowsocks服务器效果更佳)

可以使用nginx来构建一个网站服务器,用于隐藏Shadowsocks服务器的特征,防止Shadowsocks服务器被运营商或防火墙的主动探测发现;使用以下命令配置Apache服务器

yum install epel-release
yum install nginx
systemctl start nginx

# If you are running a firewall, run the following commands to allow HTTP and HTTPS traffic:

firewall-cmd --permanent --zone=public --add-service=http
firewall-cmd --permanent --zone=public --add-service=https
firewall-cmd --reload
Shadowsocks(R) 数据流本身就是一种无明显特征的 TCP 数据流。使用混淆实际上都是在增加 Shadowsocks(R) 数据流的特征。

如果防火墙可以抓取并详细分析仿真 TLS 握手数据包的每个字段,应该很容易可以判断出服务器是否提供了 Shadowsocks(R) 服务。

相比 Shadowsocks TLS 混淆,我认为ShadowsocksR TLS 混淆数据包的特征更明显。因为 ShadowsocksR TLS 混淆握手包的固定字段比较多,而且看起来还有很多错误。

所以我觉得 Shadowsocks TLS 混淆比 ShadowsocksR TLS 混淆更安全。
以下是我的一些使用建议:

如果不混淆的 Shadowsocks(R) 流不被丢弃/限速,那么请不要使用混淆。

如果不需要端口复用,那么请不要使用混淆。

如果 Shadowsocks(R) 流很不幸被丢弃/限速了,请尝试更换为知名端口(如 80、443)

如果非要使用混淆,那么请使用 Shadowsocks,而不要使用 ShadowsocksR,并将服务开放在 443 端口上

参考文档:

CentOS 7 下编译并安装 shadowsocks-libev 并启用 obfs 混淆

如何安装和配置simple-obfs服务端

shadowsocks-libev一键安装脚本

个人分析 Shadowsocks(R) TLS 混淆的安全性

如今我这样科学上网

Centos7开启bbr加速

VPS创建需要做的一些事

如何在Linux VPS上使用Best Trace?在VPS上查看回程

Shadowsocks优化篇

linux TCP Fast Open开启和测试

shadowsocks-windows支持tcp fastopen了是吗


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK