簡體   English   中英

Mitmproxy在一個腳本中篡改GET和POST請求/響應

[英]Mitmproxy tampering GET and POST request/response in one script

對某個網址( http://test.com )的POST請求如下:

{

"messageType": "OK",
"city": {
    "Name": "Paris",
    "Views": {
        "1231": {
            "id": 4234,
             "enableView": false
        },
    },
    "Views": [5447, 8457],
    "messages": [{
        "id": "message_6443",
        "eTag": 756754338
    }]
},
"client": {
    "Id": 53,
    "email": "test@test.us",
    "firstName": "test",
    "lastName": "test",
    "id": 52352352,
    "uuid": "5631f-grdeh4",
    "isAdmin": false,

我需要攔截它並將“isAdmin”更改為true。

對某個網址( https://test.com/profiles/ {Random_Numbers} / id})的GET請求有一個'響應'[decode gzip] JSON

{
"id": 0, 
"Code": "Admin", 
"display": "RRRR"
}

我需要將“id”值更改為5。

所以基本上我需要編寫一個可以完成這兩個的腳本。

到目前為止,我已嘗試在Github中獲取示例代碼的幫助,但我沒有預期的結果。 (我是一個完整的菜鳥:\\)並希望有人可以幫助我開始。 提前致謝!

編輯:根據Github中的示例代碼,modify_response_body.py:

from libmproxy.protocol.http import decoded

def start(context, argv):
  if len(argv) != 3:
   raise ValueError('Usage: -s "modify-response-body.py old new"')
    context.old, context.new = argv[1], argv[2]


def response(context, flow):
    with decoded(flow.response):  # automatically decode gzipped responses.
      flow.response.content = flow.response.content.replace(context.old, context.new)`

我如何為我的senario實現這個?

可能使用libmproxy獲取http請求和響應可能是一個更好的主意。

您發布的腳本和Python的JSON模塊應該讓您走得很遠:

def response(context, flow):
    if flow.request.url == "...": # optionally filter based on some criteria...
        with decoded(flow.response):  # automatically decode gzipped responses.
            data = json.loads(flow.response.content)
            data["foo"] = "bar"
            flow.response.content = json.dumps(data)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM