Skip to content

Commit

Permalink
tools: globalmitm
Browse files Browse the repository at this point in the history
  • Loading branch information
rev1si0n committed Jul 24, 2022
1 parent 05097cd commit e49673f
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
21 changes: 20 additions & 1 deletion tools/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ test.pem # 用于加密客户端与服务端通信的证书

## startmitm.py

启动中间人,这将会完全自动的在设备上开启全局的中间人代理,你就可以截获大部分APP的 http/s 流量,当然,也包括 DNS 请求。
启动中间人,这将会完全自动的在设备上开启全局的中间人,你就可以截获应用的 http/s 流量,当然,也包括 DNS 请求。

首先确保当前电脑与设备在同一个网段,192.168.1.2 为运行了 lamda 的手机设备。
其次,确保你已在命令行验证 mitmproxy 已安装成功(在命令行输入 `mitmdump` 进行验证)。
Expand Down Expand Up @@ -154,3 +154,22 @@ python3 discover.py
```bash
bash emu-install 192.168.1.2
```

## globalmitm/

用于分析需要使用代理才能访问的应用的流量,是一个整合的 docker 镜像,需要支持 UDP 协议的 shadowsocks 服务,请自行获取该服务。
因为 Windows/Mac 上的 docker 实现问题,此镜像必须配合 `Linux` 系列系统使用。

镜像已经构建并上传至 dockerhub,你也可以自行构建。

首先拼接代理为以下链接格式

```bash
ss://加密算法:密码@地址:端口
```

现在执行命令

```bash
docker run --rm -it --net host -e SS=ss://加密算法:密码@地址:端口 rev1si0n/mitm 192.168.x.x
```
31 changes: 31 additions & 0 deletions tools/globalmitm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM debian:bullseye-slim

ENV PYPIMIRROR=https://mirrors.ustc.edu.cn/pypi/web/simple
ENV SS=https://github.com/shadowsocks/go-shadowsocks2/releases/download/v0.1.5/shadowsocks2-linux.gz
ENV SOURCESMIRROR=mirrors.ustc.edu.cn

RUN sed -i "s/deb.debian.org/${SOURCESMIRROR}/g" /etc/apt/sources.list
RUN sed -i "s|security.debian.org/debian-security|${SOURCESMIRROR}/debian-security|g" /etc/apt/sources.list

RUN apt-get update && apt-get -y upgrade
RUN apt install -y git adb wget privoxy python3 python3-pip

COPY entry /usr/bin/mitm
RUN chmod 755 /usr/bin/mitm

WORKDIR /tmp

RUN git clone https://github.com/rev1si0n/lamda
RUN pip3 install -i ${PYPIMIRROR} -r lamda/tools/requirements.txt
RUN pip3 install -i ${PYPIMIRROR} packaging

RUN cp lamda/tools/startmitm.py /usr/bin
RUN chmod 755 /usr/bin/startmitm.py

RUN wget ${SS} -O - | gzip -d> /usr/bin/go-shadowsocks2
RUN chmod 755 /usr/bin/go-shadowsocks2

RUN ( timeout 5 mitmdump; exit 0 ) && rm -rf lamda

WORKDIR /root
ENTRYPOINT [ "mitm" ]
57 changes: 57 additions & 0 deletions tools/globalmitm/entry
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
export GRPC_DNS_RESOLVER=native
IP=${1:-}
if [ -z "${IP}" ]; then
exit 1
fi

DNS=$(((RANDOM % 10000) + 10000))
SOCKS5=$(((RANDOM % 10000) + 10000))
HTTP=$(((RANDOM % 10000) + 10000))
WEB=${WEBPORT:-1234}

if [ ! -z "${SS}" ]; then
cat <<EOL >/etc/privoxy/config
confdir /etc/privoxy
logdir /tmp
actionsfile user.action
filterfile user.filter
debug 1
hostname zeus
listen-address 0.0.0.0:${HTTP}
forward-socks5 / 127.0.0.1:${SOCKS5} .
toggle 0
enable-remote-toggle 0
enable-remote-http-toggle 0
enable-edit-actions 0
enforce-blocks 0
EOL

PIDS=
go-shadowsocks2 -c ${SS} -verbose \
-socks 127.0.0.1:${SOCKS5} -u \
-udptun 127.0.0.1:${DNS}=8.8.8.8:53 \
-tcptun 127.0.0.1:${DNS}=8.8.8.8:53 &
PIDS="$PIDS $!"
privoxy --no-daemon /etc/privoxy/config &
PIDS="$PIDS $!"

trap "kill -9 ${PIDS} 2>/dev/null" SIGINT SIGTERM
startmitm.py ${IP} --set dns_server=true \
--set dns_mode=reverse:127.0.0.1:${DNS} \
--mode upstream:http://127.0.0.1:${HTTP} \
--set block_global=false \
--web-host=0.0.0.0 \
--web-port=${WEB} \
${@: 2:999}
else
startmitm.py ${IP} --set block_global=false \
--web-host=0.0.0.0 \
--web-port=${WEB} \
${@: 2:999}
fi
exit 0
3 changes: 2 additions & 1 deletion tools/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lamda>=3.0.0,<4.0.0
mitmproxy>6.0.0
mitmproxy>6.0.0
packaging

0 comments on commit e49673f

Please sign in to comment.