mediummultiple choiceObjective-mapped

A penetration tester is reviewing a Python script that attempts to exploit a command injection vulnerability. The script uses the 'subprocess' module with the 'shell=True' argument. Which of the following code changes would be MOST effective to reduce the risk of unintended consequences when executing system commands?

Question 1mediummultiple choice
Full question →

A penetration tester is reviewing a Python script that attempts to exploit a command injection vulnerability. The script uses the 'subprocess' module with the 'shell=True' argument. Which of the following code changes would be MOST effective to reduce the risk of unintended consequences when executing system commands?

Answer choices

Why each option matters

Good practice is not just finding the correct option. The wrong answers often show the exact trap the exam wants you to fall into.

A

Distractor review

Replace subprocess with os.system()

os.system() also uses a shell and is even less secure than subprocess with shell=True.

B

Distractor review

Use the 'shlex.quote()' function to sanitize user input before passing to subprocess

While sanitization helps, it is still prone to bypasses and does not eliminate the risk as effectively as avoiding the shell entirely.

C

Best answer

Avoid using shell=True and pass the command as a list of arguments

When shell=True is omitted and the command is a list, subprocess executes the command directly without invoking a shell, eliminating shell injection.

D

Distractor review

Use the 'exec()' function to run the command

exec() is a Python built-in that executes dynamically generated Python code, not system commands, and is also dangerous.

Common exam trap

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.

Technical deep dive

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.

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.

More questions from this exam

Keep practising from the same exam bank, or move into a focused topic page if this question exposed a weak area.

FAQ

Questions learners often ask

What does this PT0-002 question test?

Static NAT maps one inside address to one outside address.

What is the correct answer to this question?

The correct answer is: Avoid using shell=True and pass the command as a list of arguments — Using subprocess with shell=True is dangerous because it passes the command string straight to a shell, making it vulnerable to injection. The safest approach is to avoid shell=True entirely and pass the command as a list of arguments, which bypasses the shell and prevents interpretation of special characters. Sanitization with shlex.quote() is an option but less robust than eliminating the shell.

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

Then try more questions from the same exam bank and focus on understanding why the wrong options are tempting.

Discussion

Loading comments…

Sign in to join the discussion.