- A
Improper error handling
No try-except block is present, so exceptions may leak stack traces.
- B
SQL injection
User input is concatenated directly into the SQL query without sanitization.
- C
Cross-site scripting (XSS)
Why wrong: The code does not output data to a browser, so XSS is not present.
- D
Command injection
Why wrong: There is no system command execution based on user input.
- E
Path traversal
Why wrong: No file path manipulation occurs in the code.
Quick Answer
The correct answer is SQL injection and improper error handling. The code directly concatenates user input into the SQL query string, allowing an attacker to break out of the intended syntax and execute arbitrary database commands, which is the classic SQL injection vulnerability. Additionally, the code lacks any try-except block or exception handling around the database operation, so if the query fails—for example, due to a malformed injection attempt—the resulting unhandled error stack trace could leak database schema details or other sensitive information to the user. On the CompTIA PenTest+ PT0-002 exam, this pairing tests your ability to identify both input validation flaws and insecure error disclosure in a single code review scenario; a common trap is to focus only on the obvious injection and overlook the missing exception handling. Remember the mnemonic “Inject and Leak”—if user input is concatenated into a query and no error handling exists, you have both a vector to attack and a channel to gather intel.
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 is reviewing Python code for a web application and finds the following snippet:
import sqlite3 def get_user(username):
conn = sqlite3.connect('users.db') cursor = conn.cursor() query = "SELECT * FROM users WHERE username = '" + username + "'" cursor.execute(query)
return cursor.fetchall()
Which TWO of the following vulnerabilities are present in this code? (Select TWO.)
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
Improper error handling
Option A is correct because the code concatenates user input directly into an SQL query, allowing SQL injection. Option E is correct because the code does not handle exceptions; if the database query fails, unhandled exceptions could reveal sensitive information. Options B, C, and D are not present because there is no output to a browser (XSS), no system command execution (command injection), and no file path manipulation (path traversal).
Key principle: NAT direction and interface roles matter as much as the IP address mapping. Inside/outside designation controls which traffic is translated.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✓
Improper error handling
Why this is correct
No try-except block is present, so exceptions may leak stack traces.
Related concept
Static NAT maps one inside address to one outside address.
- ✓
SQL injection
Why this is correct
User input is concatenated directly into the SQL query without sanitization.
Related concept
Static NAT maps one inside address to one outside address.
- ✗
Cross-site scripting (XSS)
Why it's wrong here
The code does not output data to a browser, so XSS is not present.
- ✗
Command injection
Why it's wrong here
There is no system command execution based on user input.
- ✗
Path traversal
Why it's wrong here
No file path manipulation occurs in the code.
Common exam traps
Common exam trap: NAT rules depend on direction and matching traffic
NAT is not only about the public address. The inside/outside interface roles and the ACL or rule that matches traffic are just as important.
Trap categories for this question
Command / output trap
The code does not output data to a browser, so XSS is not present.
Detailed technical explanation
How to think about this question
NAT questions usually test address translation, overload/PAT behaviour, static mappings and whether the right traffic is being translated. Read the interface direction and address terms carefully.
KKey Concepts to Remember
- Static NAT maps one inside address to one outside address.
- PAT allows many inside hosts to share one public address using ports.
- Inside local and inside global describe the private and translated addresses.
- NAT ACLs identify traffic for translation, not always security filtering.
TExam Day Tips
- Identify inside and outside interfaces first.
- Check whether the scenario needs static NAT, dynamic NAT or PAT.
- Do not confuse NAT matching ACLs with normal packet-filtering intent.
Key takeaway
NAT direction and interface roles matter as much as the IP address mapping. Inside/outside designation controls which traffic is translated.
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.
Review the four NAT address types (inside local, inside global, outside local, outside global), PAT port overload, and static vs dynamic NAT use cases. Then practise related PT0-002 NAT questions on configuration and troubleshooting.
- →
Tools and Code Analysis — study guide chapter
Learn the concepts, then practise the questions
- →
Tools and Code Analysis practice questions
Targeted practice on this topic area only
- →
All PT0-002 questions
509 questions across all exam domains
- →
CompTIA PenTest+ PT0-002 study guide
Full concept coverage aligned to exam objectives
- →
PT0-002 practice test guide
How to use practice tests most effectively before exam day
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.
Planning and Scoping practice questions
Practise PT0-002 questions linked to Planning and Scoping.
Information Gathering and Vulnerability Scanning practice questions
Practise PT0-002 questions linked to Information Gathering and Vulnerability Scanning.
Attacks and Exploits practice questions
Practise PT0-002 questions linked to Attacks and Exploits.
Reporting and Communication practice questions
Practise PT0-002 questions linked to Reporting and Communication.
Tools and Code Analysis practice questions
Practise PT0-002 questions linked to Tools and Code Analysis.
PT0-002 fundamentals practice questions
Practise PT0-002 questions linked to PT0-002 fundamentals.
PT0-002 scenario practice questions
Practise PT0-002 questions linked to PT0-002 scenario.
PT0-002 troubleshooting practice questions
Practise PT0-002 questions linked to PT0-002 troubleshooting.
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 — Static NAT maps one inside address to one outside address..
What is the correct answer to this question?
The correct answer is: Improper error handling — Option A is correct because the code concatenates user input directly into an SQL query, allowing SQL injection. Option E is correct because the code does not handle exceptions; if the database query fails, unhandled exceptions could reveal sensitive information. Options B, C, and D are not present because there is no output to a browser (XSS), no system command execution (command injection), and no file path manipulation (path traversal).
What should I do if I get this PT0-002 question wrong?
Review the four NAT address types (inside local, inside global, outside local, outside global), PAT port overload, and static vs dynamic NAT use cases. Then practise related PT0-002 NAT questions on configuration and troubleshooting.
What is the key concept behind this question?
Static NAT maps one inside address to one outside address.
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 →
Last reviewed: Jun 23, 2026
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.
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.
Sign in to join the discussion.