0

how do i get/capture the query strings of POST method and turn into dictionary in python? this is the content of request.txt file. FYI the query strings parameter may varies depend on the request file.


POST /login HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Firefox/62.0
Content-Type: application/x-www-form-urlencoded
Referer: http://localhost/login
Cookie: __cfduid=dcd3e07532; XSRF-TOKEN=eyJpdiIyYzc0In0%3D; key_session=eyJpdiI6IFmZCJ9

_token=VCXB1YcU3ti&email=testmail%40gmail.com&password=pass12345

this is my code:

from urllib.parse import urlparse, parse_qs

#read last line
with open("request.txt", "r") as file:
    first_line = file.readline()
    for last_line in file:
        pass

Is there any best ways to get the query string using split or other ways? without refering to last line in request.txt file? thanks a lot

5
  • is that output came from Acunetix ? Commented Apr 28, 2020 at 5:54
  • your question isn't clear for me ? do you just want to read the last line of any output file came from burp-suite into a dict ? Commented Apr 28, 2020 at 6:27
  • @αԋɱҽԃαмєяιcαη. my goal is to parse the query strings into dict. i want to send the query strings as payloads to the request.post . my current way is by reading last line from the request.txt file(burp output), however, what if there are any other lines after the query strings? So, my current way didnt work. hope answer ur question Commented Apr 28, 2020 at 6:33
  • are the query string is usually came after Cookie or the first blank line ? Commented Apr 28, 2020 at 6:37
  • @αԋɱҽԃαмєяιcαη it came after first blank line Commented Apr 28, 2020 at 6:38

1 Answer 1

1
from urllib import parse

with open("data.txt") as f:
    lines = f.readlines()
    goal = lines[lines.index("\n")+1]
    print(dict(parse.parse_qsl(parse.urlsplit(goal).path)))

Output:

{'_token': 'VCXB1YcU3ti', 'email': '[email protected]', 'password': 'pass12345'}     
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.