基于SSH的HTTP/HTTPS代理。
go install github.com/justmao945/mallory/cmd/mallory@latest默认路径为 $HOME/.config/mallory.json,可在启动程序时设置
mallory -config path/to/config.json
内容:
id_rsa 是我们的私钥文件路径,可通过 ssh-keygen 生成local_smart 是提供HTTP代理的本地地址,支持对目标主机进行智能检测local_normal 类似于 local_smart,但所有流量都通过远程SSH服务器发送,不进行目标主机检测remote 是SSH服务器的远程地址blocked 是需要使用代理的域名列表,其他域名将直接连接到其服务器{
"id_rsa": "$HOME/.ssh/id_rsa",
"local_smart": ":1315",
"local_normal": ":1316",
"remote": "ssh://[email protected]:22",
"blocked": [
"angularjs.org",
"golang.org",
"google.com",
"google.co.jp",
"googleapis.com",
"googleusercontent.com",
"google-analytics.com",
"gstatic.com",
"twitter.com",
"youtube.com"
]
}
配置文件中的阻止列表在更新时会自动重新加载,也可以手动操作:
# 发送信号以重新加载
kill -USR2 <mallory的PID>
# 或通过发送HTTP请求使用reload命令
mallory -reload
localhost 端口 1315,配合阻止列表使用http_proxy 和 https_proxy 为 localhost:1316mallory -suffix www.google.com
# 安装:go get github.com/justmao945/mallory/cmd/forward
# 所有通过端口20022的流量将被转发到 destination.com:22
forward -network tcp -listen :20022 -forward destination.com:22
# 现在你可以通过 localhost:20022 SSH 到 destination:22
ssh root@localhost -p 20022
假设有如下配置文件:
$ cat mallory.json
{
"id_rsa": "/tmp/id_rsa",
"local_smart": ":1315",
"local_normal": ":1316",
"remote": "ssh://[email protected]:22"
}
你可以运行容器 (zoobab/mallory),挂载配置文件、SSH密钥,并映射两个端口:
$ docker run -v $PWD/mallory.json:/root/.config/mallory.json -p 1316:1316 -p 1315:1315 -v $PWD/.ssh/id_rsa:/tmp/id_rsa zoobab/mallory
mallory: 2020/03/30 16:51:10 main.go:22: Starting...
mallory: 2020/03/30 16:51:10 main.go:23: PID: 1
mallory: 2020/03/30 16:51:10 config.go:103: Loading: /root/.config/mallory.json
mallory: 2020/03/30 16:51:10 main.go:30: Connecting remote SSH server: ssh://[email protected]:22
mallory: 2020/03/30 16:51:10 main.go:38: Local normal HTTP proxy: :1316
mallory: 2020/03/30 16:51:10 main.go:48: Local smart HTTP proxy: :1315
我的使用场景是通过SSH堡垒机连接到Kubernetes集群(Openshift):
$ export http_proxy=http://localhost:1316
$ export https_proxy=https://localhost:1316
$ oc login https://master.mycluster.zoobab.com:8443
Authentication required for https://master.mycluster.zoobab.com:8443 (openshift)
Username: bhenrion
Password:
Login successful.