Question 75 of 509
Tools and Code AnalysismediumMultiple ChoiceObjective-mapped

Quick Answer

The correct choice is to URL-encode the payload using `urllib.parse.quote()`, because the penetration tester’s script was sending raw characters like dots and slashes, which the web application did not interpret as directory traversal sequences. By applying `urllib.parse.quote()` to the payload, the dots become `%2e` and slashes become `%2f`, transforming `../../etc/passwd` into the properly encoded format that the application expects, thereby eliminating false negatives. On the CompTIA PenTest+ PT0-002 exam, this question tests your understanding of how web servers and filters often require URL encoding for directory traversal attacks, and a common trap is assuming raw payloads always work—many applications decode only percent-encoded input. A helpful memory tip: think of “quote” as “quote the dots and slashes” to bypass filters, and remember that `urllib.parse.quote()` is your go-to for encoding path traversal strings in Python.

PT0-002 Tools and Code Analysis Practice Question

This PT0-002 practice question tests your understanding of tools and code analysis. The scenario asks you to isolate a root cause — eliminate options that address a different problem before choosing. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.

A penetration tester writes a Python script to test for directory traversal vulnerabilities in a web application. The script uses the requests library to send a payload like '../../etc/passwd' and checks if the response contains the string 'root:'. However, the tester notices many false negatives because the application requires URL encoding of the dots and slashes. Which code modification would BEST improve the detection rate?

Clue words in this question

Noticing these words before you look at the options changes how you read each choice.

  • Clue: "best"

    Why it matters: Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

Question 1mediummultiple choice
Study the full Python automation breakdown →

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

URL-encode the payload using urllib.parse.quote()

Option B is correct because the penetration tester's script is failing to detect directory traversal vulnerabilities due to the web application requiring URL-encoded characters. By using `urllib.parse.quote()` to URL-encode the dots and slashes in the payload (e.g., `%2e%2e%2f` for `../`), the request matches the application's expected input format, reducing false negatives. This directly addresses the root cause—encoding—rather than adding more payloads or changing the detection method.

Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Increase the number of payloads in the list

    Why it's wrong here

    More payloads might cover more cases, but if encoding is the root cause, this alone won't fix the false negatives.

  • URL-encode the payload using urllib.parse.quote()

    Why this is correct

    Proper URL encoding ensures the payload is correctly interpreted by the server, matching common attack vectors.

    Clue confirmation

    The clue word "best" in the question point toward this answer.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Check the HTTP status code instead of response content

    Why it's wrong here

    Status codes alone do not indicate successful traversal; the server may return a 200 OK for error messages too.

  • Use raw sockets to send HTTP requests manually

    Why it's wrong here

    Raw sockets add complexity and do not inherently solve encoding issues; the requests library handles HTTP properly.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates may think adding more payloads (Option A) or checking status codes (Option C) will solve the detection issue, but the core problem is the lack of proper encoding to match the application's input handling, which is a common oversight in web application testing.

Detailed technical explanation

How to think about this question

URL encoding is governed by RFC 3986, where characters like `.` and `/` are percent-encoded to `%2e` and `%2f` respectively, ensuring they are interpreted as literal characters rather than path separators in HTTP requests. In real-world scenarios, web servers or WAFs may decode the payload at different layers, so double-encoding (e.g., `%252e%252f`) might be necessary if the application decodes input before validation. The `urllib.parse.quote()` function by default does not encode `/`, so the tester must use `safe=''` to ensure all relevant characters are encoded.

KKey Concepts to Remember

  • Read the scenario before looking for a memorised answer.
  • Find the constraint that changes the correct option.
  • Eliminate answers that are true in general but not in this case.

TExam Day Tips

  • Watch for words such as best, first, most likely and least administrative effort.
  • Review why wrong options are wrong, not only why the correct option is correct.

Key takeaway

Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.

Real-world example

How this comes up in practice

A developer is choosing between AES-256 (symmetric) and RSA-2048 (asymmetric) for encrypting a large file that will be sent to a partner. Symmetric encryption is fast but requires key exchange; asymmetric is slower but solves the key distribution problem. A hybrid approach — encrypt the file with AES, encrypt the AES key with RSA — is standard. Questions like this test whether you understand when each approach applies.

What to study next

Got this wrong? Here's your next step.

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Related practice questions

Related PT0-002 practice-question pages

Use these pages to review the topic behind this question. This is how one missed question becomes focused revision.

Practice this exam

Start a free PT0-002 practice session

Short sessions build daily habit. Longer sessions build exam-day stamina. Try a timed session to simulate real conditions.

FAQ

Questions learners often ask

What does this PT0-002 question test?

Tools and Code Analysis — This question tests Tools and Code Analysis — Read the scenario before looking for a memorised answer..

What is the correct answer to this question?

The correct answer is: URL-encode the payload using urllib.parse.quote() — Option B is correct because the penetration tester's script is failing to detect directory traversal vulnerabilities due to the web application requiring URL-encoded characters. By using `urllib.parse.quote()` to URL-encode the dots and slashes in the payload (e.g., `%2e%2e%2f` for `../`), the request matches the application's expected input format, reducing false negatives. This directly addresses the root cause—encoding—rather than adding more payloads or changing the detection method.

What should I do if I get this PT0-002 question wrong?

Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.

Are there clue words in this question I should notice?

Yes — watch for: "best". Signals that multiple options may be partially correct. Choose the option that most directly solves the exact problem described, not the one that sounds most complete.

What is the key concept behind this question?

Read the scenario before looking for a memorised answer.

About these practice questions

Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 11, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

This PT0-002 practice question is part of Courseiva's free CompTIA certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PT0-002 exam.