Command Injection: Chaining Commands

Command injectionExploitation

From PayloadsAllTheThings by Swissky and contributors, under the MIT licence. Shown as written; the title and classification are ours. Licences. Its authors can have this tip removed by writing to abuse@bugbountytips.org.

In many command-line interfaces, especially Unix-like systems, there are several characters that can be used to chain or manipulate commands.

  • ; (Semicolon): Allows you to execute multiple commands sequentially.

  • && (AND): Execute the second command only if the first command succeeds (returns a zero exit status).

  • || (OR): Execute the second command only if the first command fails (returns a non-zero exit status).

  • & (Background): Execute the command in the background, allowing the user to continue using the shell.

  • | (Pipe): Takes the output of the first command and uses it as the input for the second command.

powershell
command1; command2   # Execute command1 and then command2
command1 && command2 # Execute command2 only if command1 succeeds
command1 || command2 # Execute command2 only if command1 fails
command1 & command2  # Execute command1 in the background
command1 | command2  # Pipe the output of command1 into command2

Comments

No comments yet.