How to use fiddler to capture mobile phone packets and filters!

1. The difference between Fiddler and other packet capture tools

1. Although Firebug can capture packets, it is not powerful enough to analyze the detailed information of http requests. The function of simulating HTTP requests is not enough, and Firebug often requires “no refresh modification”. If the page is refreshed, all modifications will not be saved;

2. Wireshark is a general packet capture tool that can obtain HTTP and HTTPS, but it cannot decrypt HTTPS, so wireshark cannot understand the content in HTTPS, but if it is TCP or UDP protocol, you can use wireshark;

3. Httpwatch is also a commonly used http packet capture tool, but it only supports IE and Firefox browsers (other browsers may have corresponding plug-ins);

Fiddler is an HTTP proxy that uses local 127.0.0.1:8888. Any browser and application that can set the HTTP proxy to 127.0.0.1:8888 can use Fiddler.

2. How Fiddler works

Fiddler is an HTTP proxy located on the client and server sides. It is also one of the most commonly used http packet capture tools. It can record all HTTP requests between the client and the server. For specific HTTP requests, it can analyze the request data, set breakpoints, debug web applications, modify the requested data, and even modify the data returned by the server.

Since it is a proxy, that is to say: all requests from the client must first go through Fiddler and then be forwarded to the corresponding server. On the contrary, all responses from the server will first go through Fiddler and then be sent to the client. Therefore, the relationship between the web client and the server The request is shown in Figure 1:

Figure 1 (request process between web client and server)

Note: When using Fiddler, you need to set the browser’s proxy address before you can capture the browser’s data packets. What is very convenient is that after you start this tool, it will automatically set up the browser proxy for you. When you close it, it will restore the browser proxy. Of course, if you find that the browser proxy is not automatically set, you have to go to the browser to set the proxy yourself. (You can check how each browser sets the proxy on Baidu). Anyway, you must set the corresponding proxy, otherwise fiddler will not be able to capture the HTTP request.

Now I have also found a lot of test friends and created a communication group to share technology, sharing a lot of technical documents and video tutorials we collected.
If you don’t want to experience the feeling of not being able to find resources when studying on your own, having no one to answer your questions, and persisting for a few days before giving up.
You can join us to communicate. And there are many technical experts who have made certain achievements in automation, performance, security, test development, etc.
Share their experience, and also share many live lectures and technical salons
You can learn for free! Focus on it! Open source! ! !
QQ group number: 110685036 [password: csdn999]

3. Use fiddler to capture packets on mobile phones

1. Description

Network request data cannot be viewed directly on a mobile phone, and a packet capture tool is required. Fiddler is a free web debugging agent that can be used to record, view and debug http/https communications between mobile terminals and remote servers.

Fiddler does not have a mobile client and is installed on the PC. To capture packets from the program on the mobile phone, you need to make some configurations on the Fiddler on the PC and the mobile client.

2. Steps

2.1 PC side fiddler configuration—->According to HTTPS certificate

Many applications on mobile phones involve personal information and are encrypted using the relatively secure HTTPS. By default, fiddler only captures http sessions and not HTTPS messages. As a result, https web pages (such as Baidu) cannot be opened after opening fiddler.

Solution: Open Fiddler->Tool->Fiddler Options->HTTPS tab, check Capture HTTPS CONNECTs (capture HTTPS connections) and Decrypt HTTPS traffic (decrypt HTTPS requests), and install the certificate (if you use it for the first time without a certificate, a pop-up will appear Whether to trust the fiddler certificate and security prompt, just click yes).

2.2 PC side fiddler configuration—->Allow mobile phone to connect remotely

If you want to capture the communication data on the mobile phone, you need to connect the mobile phone to the Fiddler proxy, and Fiddler does not allow other devices to connect by default.

Solution: Click Fiddler->Tools -> Options, select Allow remote computers to connect in the Connections panel to allow other devices to connect (this operation requires restarting Fiddler to take effect)

2.3 Check computer IP

The computer IP address can be queried by entering ipconfig on the cmd command line.

2.4 Mobile phone configuration—->Connect to the network where the computer is located

You need to specify the proxy server on the mobile terminal (mobile phone or pad) as the IP address of the host where Fiddler is located (it needs to be on the same network). The default port is 8888.

Make sure that the mobile phone and the computer with fiddler installed are in the same LAN, and the mobile phone can ping the computer.

How to change the proxy of mobile wireless network: Open system settings-WLAN-long press the network connected by WiFi-click advanced options-select manual proxy, enter the fiddler’s computer IP address and port number as the host name, and save it.

2.5 Mobile phone configuration—->Mobile phone installation root certificate

You need to install the Fiddler root certificate on your mobile phone, because Fiddler uses its own generated certificate to re-sign network requests and decrypt https sessions. If you do not install the certificate, you can only capture HTTP requests.

Connect the mobile phone and computer to the same network, open the mobile browser, enter the Fiddler Server address http://ipv4.fiddler:8888/ (because fiddler is installed on the PC, the Fiddler Server address is the IP address of the PC, and bring the port number 8888 ,Mine is
http://192.168.0.128:8888/), jump to the Fiddler Echo Service certificate download page, click FiddlerRoot certificate download-name the certificate-install;

2.6 Packet capture test

Search on the mobile browser to see if there is a record in fiddler (as shown below, the packet capture is successful)

2.7 Restore phone status

After the packet capture is completed, you need to manually restore the phone state. The method is as follows (different models may have slight differences):
(1) Stop the computer’s network monitoring of the mobile phone: System Settings-WLAN, long press wifi to modify the network, find the agent in the advanced options, and remove the manual agent;
(2) Delete the certificate in the phone: Android System Settings System Device Security Trusted Credentials User, click on the certificate to delete;
(3) Delete the password on the mobile phone: mobile phone system-security-password, delete the system password.

4. Filters

Because there are many requests caught, we are dazzled. At this time, we can filter and only display the ones we want (as shown in the figure below, only the requests whose host is api-dev.XXXX.cn are displayed); we can also select the process. Name and port, only requests for that process are shown.

Hosts configuration instructions:

(1) The first item has three options and does not need to be changed:
“No zone filter”
“Show Only Intranet Hosts”
“Show Only Internet Hosts”
(2) The second option is to only monitor the following URLs. If you only monitor Baidu, fill in www.baidu.com in the input box below.
“No Host Filter” does not set hosts filtering
“Hide The Following Hosts” hides filtered domain names
“Show Only The Following Hosts” only displays filtered domain names
“Flag The Following Hosts” marks filtered domain names
(3) Enter the domain name that needs to be filtered in the text box. Use “;” semicolons to separate multiple domain names.

Fiddler will check the host set in the http header by default and force the domain name in the http address to be displayed.

Finally, I would like to thank everyone who has read my article carefully. Looking at the increase in fans and attention, there is always some courtesy. Although it is not a very valuable thing, if you can use it, you can take it directly!

Software testing interview document

We must study to find a high-paying job. The following interview questions are the latest interview materials from first-tier Internet companies such as Alibaba, Tencent, Byte, etc., and some Byte bosses have given authoritative answers. After finishing this set I believe everyone can find a satisfactory job based on the interview information.