Contents
- 1 How to protect against command execution attacks in shell?
- 2 When to use APIs or command execution attacks?
- 3 What happens if an attacker executes arbitrary code on your server?
- 4 What are the options in the command line?
- 5 Why do we use command line switches in Unix?
- 6 How to prevent PHP from executing shell commands?
How to protect against command execution attacks in shell?
If you use shell commands, be sure to scrub input values for potentially malicious characters: Even better, restrict input by testing it against a regular expression of known safe characters. (For example, alphanumeric characters.)
When to use APIs or command execution attacks?
Use APIs wherever possible – only use shell commands where absolutely necessary. This will reduce the number of attack vectors in your application, and will also simplify your codebase. Injection vulnerabilities occur when untrusted input is not sanitized correctly.
Why are there injection vulnerabilities in my shell?
Injection vulnerabilities occur when untrusted input is not sanitized correctly. If you use shell commands, be sure to scrub input values for potentially malicious characters:
What happens if an attacker executes arbitrary code on your server?
If an attacker can execute arbitrary code on your servers, your systems are almost certainly going to be compromised. You need to take great care when designing how your web server interacts with the underlying operating system.
What are the options in the command line?
In the original Unix tradition, command-line options are single letters preceded by a single hyphen. Mode-flag options that do not take following arguments can be ganged together; thus, if -aand -bare mode options, -abor -bais also correct and enables both.
How to distinguish command line options from ordinary arguments?
This is especially important for programs that function as pipes or filters. Three conventions for how to distinguish command-line options from ordinary arguments exist; the original Unix style, the GNU style, and the X toolkit style. In the original Unix tradition, command-line options are single letters preceded by a single hyphen.
Why do we use command line switches in Unix?
Unix tradition encourages the use of command-line switches to control programs, so that options can be specified from scripts. This is especially important for programs that function as pipes or filters.
How to prevent PHP from executing shell commands?
You can test that shell commands can still be executed using this trivial code: To truly restrict what shell commands can be executed by PHP you must utilize safe mode. You should be aware however that safe mode is deprecated in PHP 5.3 and will certainly be removed in a future version.
How to execute a command in the background?
You can execute any command in the background using the shell’s & command separator. Compare the behavior of the following two commands: If a job is already running and you need to use the terminal for other things, and you want the job to complete, you can use Ctrl – Z to suspend the job and bg to tell it to continue in the background: