Question 316 of 509
Tools and Code AnalysiseasyMultiple SelectObjective-mapped

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.

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 — 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 →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 23, 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.