Question 30 of 509
Tools and Code AnalysishardMultiple ChoiceObjective-mapped

Quick Answer

The answer is to add a conditional statement that checks for HTTP status codes 302 or 200 and prints the successful credentials. This improvement directly addresses the core problem of the password spraying script output: a raw, continuous stream of HTTP codes that is impossible to interpret at scale. By wrapping the curl command in an if-then condition, the tester transforms meaningless numbers into actionable intelligence, immediately isolating the valid user/password pair. On the CompTIA PenTest+ PT0-002 exam, this scenario tests your understanding of output parsing and conditional logic in Bash automation, a common trap being that testers focus on speeding up the spray rather than filtering results. The key insight is that a 302 redirect often indicates a successful authentication in web applications, while a 200 can also signal a valid session. Remember the memory tip: “Catch the redirect, print the creds” — if you see a 302 or 200, you’ve found your entry point.

PT0-002 Tools and Code Analysis Practice Question

This PT0-002 practice question tests your understanding of tools and code analysis. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. 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 is analyzing a Bash script that automates a password spraying attack. The script contains the following loop: 'for user in $(cat users.txt); do for pass in $(cat passwords.txt); do curl -s -o /dev/null -w "%{http_code}" --data "user=$user&pass=$pass" http://target/login; done; done'. The script runs but the output is a continuous stream of HTTP status codes that are hard to interpret. Which improvement would most effectively help the tester identify a successful login?

Question 1hardmultiple choice
Full question →

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

Add a conditional statement that checks if the HTTP status code is 302 (redirect) or 200, and if so, prints the successful credentials.

Option C is correct because the script currently outputs a raw stream of HTTP status codes with no context. Adding a conditional to check for 302 (redirect, often indicating a successful login) or 200 (OK) and printing the corresponding credentials allows the tester to immediately identify which user/password pair succeeded, turning an unreadable output into actionable intelligence.

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.

  • Add a delay with 'sleep 1' between requests to avoid rate limiting.

    Why it's wrong here

    Rate limiting avoidance is useful, but it does not help in interpreting the output to find successful logins.

  • Pipe the output to 'grep -v 200' to exclude any responses that are not 200 OK.

    Why it's wrong here

    This would exclude 200 responses but might also miss redirects (302) which are common indicators of success.

  • Add a conditional statement that checks if the HTTP status code is 302 (redirect) or 200, and if so, prints the successful credentials.

    Why this is correct

    This directly identifies successful login attempts by checking for common success status codes and outputting the credentials.

    Related concept

    Read the scenario before looking for a memorised answer.

  • Use 'curl -v' to see the full response headers.

    Why it's wrong here

    Verbose output shows more information but still requires manual inspection; it does not automatically identify success.

Common exam traps

Common exam trap: answer the scenario, not the keyword

The trap here is that candidates assume filtering out 200 codes (Option B) will reveal successes, but they overlook that many real-world login flows use a 302 redirect for success, making 'grep -v 200' ineffective or misleading.

Trap categories for this question

  • Command / output trap

    Rate limiting avoidance is useful, but it does not help in interpreting the output to find successful logins.

Detailed technical explanation

How to think about this question

In password spraying attacks, web applications often return HTTP 302 Found after successful authentication to redirect the user to a dashboard, while 200 OK might indicate the login page itself or a successful AJAX login. The curl command with '-w "%{http_code}"' outputs only the status code, so without context the tester cannot correlate codes to credentials. A conditional that prints the user and pass when a success code is detected transforms the output into a targeted credential discovery tool.

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 SOC analyst notices unusual lateral movement in the network at 2 AM. The IR playbook dictates: identify and contain (isolate the affected machine), then eradicate (remove the malware), then recover (restore from backup), then document. Skipping containment before eradication risks the attacker regaining access. Questions like this test the sequence and rationale of incident response phases.

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: Add a conditional statement that checks if the HTTP status code is 302 (redirect) or 200, and if so, prints the successful credentials. — Option C is correct because the script currently outputs a raw stream of HTTP status codes with no context. Adding a conditional to check for 302 (redirect, often indicating a successful login) or 200 (OK) and printing the corresponding credentials allows the tester to immediately identify which user/password pair succeeded, turning an unreadable output into actionable intelligence.

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.

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.