fiddler抓取摩拜單車資料包

weixin_34208283發表於2017-09-07

Fiddler是一個http協議除錯代理工具,它能夠記錄並檢查所有你的電腦和網際網路之間的http通訊,設定斷點,檢視所有的"進出"Fiddler的資料(指cookie,html,js,css等檔案,這些都可以讓你胡亂修改的意思)。 Fiddler 要比其他的網路偵錯程式要更加簡單,因為它不僅僅暴露http通訊還提供了一個使用者友好的格式。---摘自《360百科》
Fiddler方便作為中間http代理伺服器擷取客戶端傳送的資料包。下面要做的是用用Fiddler抓取ios裝置中摩拜單車的單車資料以及API,截止到現在摩拜單車官方APi已經使用HTTPS進行通訊。下面從Fiddler安裝HTTPS證書到獲取API的過程。

  • 1.安裝Fiddler4抓包工具
    • 因為官方軟體下載速度比較慢,所以在360軟體庫下載Fiddler安裝過程很簡單純粹下一步。
4003936-7d0bf24e98db00c7.jpg
1-1
  • 2.設定Fiddler抓取HTTPS資料包。
    • 1.安裝成功之後,啟動Fiddler進入軟體介面。
4003936-fd193a6355051da3.png
1-2
    1. 選擇tools->options->https和tools->options->connections,然後按下圖紅線勾上和設定。
4003936-9b28300fe290900e.PNG
1-3
4003936-feb6594ce1935776.PNG
1-4
  • 3.完成上述操作之後,要fiddler對ios裝置的https通訊轉包,還要下載https證書,fiddler預設的https證書對ios和android裝置不起作用。可能出現彈窗,安裝root certificate not successful。所以現在我們需要下載fiddlercertmaker來手動生成證書。雙擊之後,自動生成證書,然後重新啟動fiddler,下載如圖所示:
4003936-db91a87b439b3832.PNG
1-5
  • 4.要抓取蘋果裝置的https資料包,必須使fiddler的PC和蘋果裝置處於同一區域網。小編選擇的是在PC上下載WIFI大師,然後用蘋果裝置連線上PC的WIFI熱點。在Fiddler中通過檢視PC本機的無線網路IP地址。如圖所所標誌的紅點,例如是192.168.144.1:
4003936-dad051de35cc50e7.png
1-6
  • 5.在蘋果裝置上連線上WIFI熱點,然後設定連線上的WIFI熱點的HTTP代理。伺服器填寫192.168.144.1(即是上一步驟的IP地址),埠即是FIddler預設設定的8888如圖所示:
4003936-4e430bd90d73e54a.PNG
1-7
  • 3.完成了上述安裝設定之後,FIddler便可以擷取裝置上的資料包。摩拜單車提供了APP和微信小程式的形式。接下來我們用Fiddler獲取摩拜單車小程式的資料包。啟動微信小程式摩拜單車,如下圖所示:
4003936-f27a4416f312e399.jpg
1-8
  • 4.分析FIddler擷取到的https資料包,發現摩拜單車小程式返回json資料(自己特意跑到離自己最近的一輛單車判斷資料是否準確)


    4003936-e51381d13fa45d7f.png
    1-9
  • 5.返回的資料格式如下所示:
{
    "code": 0,
    "message": "",
    "biketype": 0,
    "object": [
        {
            "distId": "8716553834",
            "distX": 113.4142452697025,
            "distY": 22.4783592035906,
            "distNum": 1,
            "distance": "41",
            "bikeIds": "8716553834#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "7916517766",
            "distX": 113.41417330141317,
            "distY": 22.47836822434858,
            "distNum": 1,
            "distance": "45",
            "bikeIds": "7916517766#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "7916519370",
            "distX": 113.41419828863238,
            "distY": 22.478338217567746,
            "distNum": 1,
            "distance": "46",
            "bikeIds": "7916519370#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716545672",
            "distX": 113.41444624074846,
            "distY": 22.47924413138211,
            "distNum": 1,
            "distance": "66",
            "bikeIds": "8716545672#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716024668",
            "distX": 113.41460007492316,
            "distY": 22.47779710575838,
            "distNum": 1,
            "distance": "95",
            "bikeIds": "8716024668#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716554099",
            "distX": 113.41427520879347,
            "distY": 22.477644205805277,
            "distNum": 1,
            "distance": "114",
            "bikeIds": "8716554099#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8620893676",
            "distX": 113.4156226249094,
            "distY": 22.478363758786166,
            "distNum": 1,
            "distance": "119",
            "bikeIds": "8620893676#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716533121",
            "distX": 113.41536766747214,
            "distY": 22.47710986723533,
            "distNum": 1,
            "distance": "193",
            "bikeIds": "8716533121#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716549326",
            "distX": 113.41684593355554,
            "distY": 22.47778230097752,
            "distNum": 1,
            "distance": "259",
            "bikeIds": "8716549326#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8620891799",
            "distX": 113.41364669427747,
            "distY": 22.480952336205316,
            "distNum": 1,
            "distance": "270",
            "bikeIds": "8620891799#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "7916521052",
            "distX": 113.41201320576842,
            "distY": 22.47972072439544,
            "distNum": 1,
            "distance": "282",
            "bikeIds": "7916521052#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8621236540",
            "distX": 113.41201020767474,
            "distY": 22.479734724787814,
            "distNum": 1,
            "distance": "283",
            "bikeIds": "8621236540#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8620934431",
            "distX": 113.4126610487278,
            "distY": 22.480656579073916,
            "distNum": 1,
            "distance": "292",
            "bikeIds": "8620934431#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8716540529",
            "distX": 113.41313488560849,
            "distY": 22.48081746752051,
            "distNum": 1,
            "distance": "279",
            "bikeIds": "8716540529#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        },
        {
            "distId": "8620846122",
            "distX": 113.41152328833927,
            "distY": 22.478678827375827,
            "distNum": 1,
            "distance": "306",
            "bikeIds": "8620846122#",
            "biketype": 1,
            "type": 0,
            "boundary": null
        }
    ]
}
4003936-fbe9aba00cbb8f3f.PNG
1-10

本文參考《博誠資料》摩拜單車爬蟲解析——找到API
馬興草fiddler手機https抓包

相關文章