Android手机如何用Charles抓包HTTPS接口

对Charles的安装和使用,这里就不重复介绍了,之前有介绍Charles工具

本文重点介绍在Android手机上如何配置抓包环境

1.获取Charles配置

去Help -> SSL Proxying -> Install Charles Root Certificate on a Mobile Device or Remote Browser 查看配置。

2.将手机和电脑连上同一个局域网

3.为手机网络设置手动代理

ip和端口参数已经在第一步获取

4.用手机浏览器下载证书安装

浏览器进入chls.pro/ssl下载证书,下载的.pem格式证书。当设备无法识别时,需要手动将后缀名改为.crt,然后到浏览器的下载管理中选择安装就可以了。

安装后,到设置 -> 安全 -> 信任的凭证 可以看到刚安装的证书

5.抓包

Charles中右键对应HTTPS,选择Enable SSL Proxying启动代理。然后清空Structure,重新请求接口就能看到抓包的数据。

到这里,你会发现并不是所有HTTPS都能抓取,Android7.0 之后默认不信任用户添加到系统的CA证书。

解决方案:

这里就不展开了,除非你要搞逆向。

6.对自己的项目抓包

针对我们自己的Android项目,要抓包HTTPS我们可以在网络完全配置中进行设置。

到 res -> xml 创建一个network-security-config.xml文件,配置如下。

Kotlin 复制代码
<network-security-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
</network-security-config>

然后,到清单文件为application配置networkSecurityConfig。

Kotlin 复制代码
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
 
    <uses-permission android:name="android.permission.INTERNET" />
 
    <application android:networkSecurityConfig="@xml/network_security_config" >
 
    </application>
 
</manifest>

注意:在开发设置 cleartextTrafficPermitted="true" 来允许明文流量,便于我们抓包。但在发布应用时,为了提高应用的安全性,通常建议禁用明文流量。

相关推荐
ftpeak2 天前
从零开始使用 axum-server 构建 HTTP/HTTPS 服务
网络·http·https·rust·web·web app
00后程序员张2 天前
详细解析苹果iOS应用上架到App Store的完整步骤与指南
android·ios·小程序·https·uni-app·iphone·webview
weixin_456904273 天前
使用HTTPS 服务在浏览器端使用摄像头的方式解析
网络协议·http·https
不会叫的狼3 天前
HTTPS + 域名 + 双向证书认证(下)
https
DoWhatUWant3 天前
域格YM310 X09移芯CAT1模组HTTPS连接服务器
服务器·网络协议·https
Whisper_Yu4 天前
计算机网络(一)基础概念
计算机网络·http·https·信息与通信
m0_749299954 天前
HTTP与HTTPS
网络协议·http·https
2501_916007475 天前
Transporter App 使用全流程详解:iOS 应用 ipa 上传工具、 uni-app 应用发布指南
android·ios·小程序·https·uni-app·iphone·webview
2501_915909065 天前
HTTPS 错误解析,常见 HTTPS 抓包失败、443 端口错误与 iOS 抓包调试全攻略
android·网络协议·ios·小程序·https·uni-app·iphone
乖女子@@@6 天前
协议_https协议
http·https·iphone