nerdexam
CompTIA

PT0-001 · Question #250

During an engagement an unsecure direct object reference vulnerability was discovered that allows the extraction of highly sensitive PII. The tester is required to extract and then exfil the…

The correct answer is D. url += i. In Python, concatenating a string with an integer using += raises a TypeError, which would halt the script before any requests are made.

Attacks and exploits

Question

During an engagement an unsecure direct object reference vulnerability was discovered that allows the extraction of highly sensitive PII. The tester is required to extract and then exfil the information from a web application with identifiers 1 through 1000 inclusive. When running the following script, an error is encountered:

Which of the following lines of code is causing the problem?

Options

  • Breq = requests.get(url)
  • Cif req.status ==200:
  • Durl += i

How the community answered

(16 responses)
  • B
    13% (2)
  • C
    25% (4)
  • D
    63% (10)

Why each option

In Python, concatenating a string with an integer using += raises a TypeError, which would halt the script before any requests are made.

Breq = requests.get(url)

`requests.get(url)` is a valid and correct method call that performs an HTTP GET request, and would not cause an error on its own.

Cif req.status ==200:

`req.status` is an incorrect attribute name - the correct attribute is `req.status_code` - but this AttributeError would only be reached after the request succeeds, making it a secondary issue and not the root cause.

Durl += iCorrect

The line `url += i` attempts to concatenate a string (url) with an integer (i from a numeric range), which raises a `TypeError: can only concatenate str (not 'int') to str` in Python. This is a type mismatch error that occurs before the HTTP request is ever sent. The fix is to cast i to a string using `str(i)` or an f-string.

Concept tested: Python type error in IDOR automation script

Source: https://docs.python-requests.org/en/latest/user/quickstart/

Topics

#IDOR#Python scripting#web scraping#type error

Community Discussion

No community discussion yet for this question.

Full PT0-001 Practice