不同 return 的 Burpsuite 转发器和 python 请求

Different return of Burpsuite repeater and python requests

出于我公司的安全考虑,我删除了 URL。但我认为它们对于理解问题并不重要。

当我使用 Burpsuite 创建 post 时,post 被正确执行,like this print. 请求如下所示:

POST /upload/1 HTTP/1.1
Host: URL REMOVED
Connection: close
Content-Length: 0
sec-ch-ua: "Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"
Accept: application/json, text/plain, */*
sec-ch-ua-mobile: ?0
x-access-token: TOKEN REMOVED
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Origin: URL REMOVED
Sec-Fetch-Site: same-site
Sec-Fetch-Mode: cors
Sec-Fetch-Dest: empty
Referer: URL REMOVED
Accept-Encoding: gzip, deflate
Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7

BurpSuite 中的答案如下所示:

HTTP/1.1 200 OK
Date: Mon, 25 Jan 2021 15:28:46 GMT
Server: Apache
X-DNS-Prefetch-Control: off
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15552000; includeSubDomains
X-Download-Options: noopen
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Access-Control-Allow-Origin: *
Content-Type: application/json; charset=utf-8
Content-Length: 86
ETag: W/"56-bL6Iw6mpmbZmkXyESXWzn8xcLXc"
Connection: close

{"status":{"type":"success","message":"success","code":200,"error":false},"data":"Ok"}

但是当我尝试使用 python 请求执行相同的 post 时,我收到 401 错误。代码如下:

import requests
import json
#DESAFIO 2

url_post = 'URL REMOVED'
parametros_post = {
    "Host": "URL REMOVED",
    "Connection": "close",
    "Content-Length": 0,
    "sec-ch-ua": '"Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
    "Accept": "application/json, text/plain, */*",
    "sec-ch-ua-mobile": "?0",
    "x-access-token": "TOKEN REMOVED",
    "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36",
    "Content-Type": "application/x-www-form-urlencoded",
    "Origin": "URL",
    "Sec-Fetch-Site": "same-site",
    "Sec-Fetch-Mode": "cors",
    "Sec-Fetch-Dest": "empty",
    "Referer": "URL REMOVED",
    "Accept-Encoding": "gzip, deflate",
    "Accept-Language": "pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7"
}
headers_post = {}
r = requests.post(url_post, data = json.dumps(parametros_post), headers = headers_post)

print(r.json())

他python的return代码如下:

{'status': {'type': 'AppError', 'message': 'Please log in.', 'error': True, 'code': 401}}

我对两种请求方式使用相同的用户代理和相同的 headers。 我该怎么做才能让它在 python 上运行?

您发送的请求如下所示:

您的脚本在请求 body 中的 json 中发送这些 headers,但这些是请求 headers。 您应该将它们发送为 headers.

此更改请求之后如下所示:

您可以使用 Burp Comparer 比较您的请求,您只需要通过 Burp 代理发送您的请求,如示例中 8040 是 Burp 代理。在 Comparer window 中,您将看到您的请求的外观,并且更容易注意到问题所在。