Android https 抓包指南

zailushang發表於2020-12-28

為何寫本文:

雖然過去有過多次抓包經驗,但是長時間不做了,有些坑還是難以避免,比較浪費時間。所以沉澱一篇小白指南貼,節約時間。

如果要完成Android https的抓包和解析,需要完成兩步:搭建代理服務和手機端配置。

1、代理服務

本文以AnyProxy為例。
AnyProxy 是完全可以靈活配置的代理伺服器。它支援 https明文代理 ,且提供了 Web 介面便於觀測請求情況,同時支援二次開發,可以用 JavaScript 來控制代理的全部流程,搭建前端個性化除錯環境。

(1)安裝Anyproxy

網上文章非常多,本文參考:代理伺服器 AnyProxy

(2)配置https

原理:AnyProxy 解析 Https 的原理是自制根證照 rootCA 在終端信任這份證照之後,再用它簽發各個域名的二級證照,此時二級證照可以重新對各個頁面進行解析。

A. 生成 rootCA

# 最新版本生成方法
$ anyproxy-ca

也可掃描anyproxy web頁面下載

B. 開啟並信任 rootCA.crt

生成命令執行後會彈出證照所在目錄,或者根據提示找到該目錄後,雙擊開啟。

信任證照:

(3)以支援https方式啟動anyproxy

$ anyproxy --intercept
# 簡寫
$ anyproxy -i

2、手機端

(1)安裝.crt證照

正確的安裝方法有2個:

A. 設定——WiFi——高階設定——安裝證照

B. 設定——更多設定——系統安全——從SD卡安裝裡

(2)手機設定代理

A. Wi-Fi中設定

B. adb設定(親測有效)

# 設定全域性命令
adb shell settings put global http_proxy 代理IP地址:埠號

# 移除代理資訊
adb shell settings delete global http_proxy
adb shell settings delete global global_http_proxy_host
adb shell settings delete global global_http_proxy_port
adb reboot

C. 通過第三方app設定代理(暫時不建議,親測安卓實體機配置失敗)

原始碼地址
下載apk後,安裝到手機
設定代理:

# 通過執行以下命令設定代理
adb shell am start -n tk.elevenk.proxysetter/.MainActivity
# 引數說明
-e host <host> # The host ip or address for the proxy
-e port <port> # The port for the proxy
-e ssid <ssid> # The SSID of the wifi network to set proxy on(optional, will apply on the first one if empty)
-e key <shared key> # The password/key for the wifi network
-e bypass <bypass string> # The bypass string to use for proxy settings
-e reset-wifi <boolean> # Whether or not to reset the wifi settings. This flag will tell
# the tool to forget all connected networks, make a new
# network config with the SSID and key given, and then
# attempt to connect to the wifi network. If no key is given,
# the wifi network is assumed to be unprotected/open
-e clear <boolean> # A flag that will clear the proxy settings for the given SSID

常用命令:

# 在開放的 wifi 網路上設定代理,重置 wifireset-wifi true
adb shell am start -n tk.elevenk.proxysetter/.MainActivity -e host <Proxy IP> -e port <Proxy Port> -e ssid <Wifi Name> -e reset-wifi true

# 用密碼設定 wifi 網路代理
adb shell am start -n tk.elevenk.proxysetter/.MainActivity -e host <Proxy IP> -e port <Proxy Port> -e ssid <Wifi Name> -e key <Wifi pwd>

# 清除代理伺服器的 SSID
adb shell am start -n tk.elevenk.proxysetter/.MainActivity -e ssid <ssid> -e clear true

相關文章