Command Injection
Command Injection occurs when user input is concatenated into system commands executed by the application. In CTF challenges, this often grants full control over the server environment.
import subprocess
def process_file(filename):
return subprocess.check_output(['cat', filename])
filename = input('Enter a filename: ')
print(process_file(filename))
filename = "file.txt; ls"
Resulting command:
cat file.txt; ls
- Chain commands with
;,&&, or|. - Use blind command injection (e.g.,
ping -c 1 <collaborator>) to confirm execution. - Try OS-specific payloads if Linux/Windows detection is uncertain.