shadowTLS/README.md
2022-10-16 12:25:40 +08:00

95 lines
2.9 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Shadow-TLS
### TLS伪装代理 -- 包装任意TCP连接为真正合法域名的TLS连接
## 基本原理
给审计设备表演一个访问指定网站的TLS握手,在后续的加密流量中传输自定义的数据,由于握手的证书是真实的证书,对审计设备(防火墙/上网行为分析/零信任网关)而言本次TCP连接是访问指定网站的HTTPS流量
## 使用场景
- 在有域名白名单的情况下需要将流量转发出去
- 审计设备会验证TLS证书合法性,自签证书无法通过审计设备的场景
## 使用方法
- 服务端示例:
监听端口443,收到请求后先创造到www.apple.com的TLS握手,随后转发本地的8888端口流量到客户端
```shell
./shadowtls server -l 0.0.0.0:443 -f www.apple.com:443 -t 127.0.0.1:8888
```
- 客户端示例:
```shell
./shadowtls client -l 0.0.0.0:11222 -s 145.142.63.32:443 -d www.apple.com
```
## 探测防御
- 设置参数密码-p 可开启探测防御功能,服务端检测到非被客户端发起的请求后将会作为标准的SNI代理服务器,转发用于伪装源站的所有流量,对主动探测者而言这台服务器是指定网站的官方服务器
- 若被大量请求可能造成服务器产生大量流量,注意风控
- 引入utls组件,伪装TLS ClientHello指纹为Chrome 102版本,进一步对抗探测
## 流量加密
- 设置加密密钥参数-k 可启用流量加密,密钥长度必须为16,24或32个字符
## 已知限制
- 若审计软件会对HTTPS证书进行替换使用审计软件自签的证书,本工具将不再适用
## 使用Nginx将本服务和其他443端口服务并存
- 编译带有stream和stream_ssl_preread模块的nginx
- 参考以下配置
```nginx
stream {
map $ssl_preread_server_name $backend_pool {
www.apple.com shadow;
defalut local_server;
}
upstream shadow{
server 127.0.2.1:2443;
}
upstream local_server{
server 127.0.2.1:8443;
}
server {
listen 443;
ssl_preread on;
proxy_bind $remote_addr transparent; # 加了这个才能传递客户端IP
proxy_pass $backend_pool;
proxy_connect_timeout 15s;
proxy_timeout 15s;
proxy_next_upstream_timeout 15s;
}
}
http {
...
server {
listen 127.0.2.1:8443 ssl http2;
server_name file.evan.run;
charset utf-8;
ssl_certificate cert.crt;
ssl_certificate_key private.key;
port_in_redirect off; #重要阻止nginx重定向到此Server listen的端口
location / {
root /root/file;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
}
}
}
```
- 添加策略路由:
```shell
ip rule add from 127.0.2.1 lookup 61
ip route add local 0.0.0.0/0 dev lo table 61
```
## 特别说明
- 感谢v2ex网友ihciah的思路灵感.
- 仅供技术研究,请勿用于非法用途.