Zend PHP 5.3 Certification Exam
Functions and Arrays
Object Oriented Programming
Data Format & Types
Strings and Patterns
Databases and SQL
Web Features 1
Which of the following functions can you use to mitigate a command injection attack?
Each correct answer represents a complete solution. Choose two.
Answer options C and B are correct.
You can use either the escapeshellcmd() or escapeshellarg() function to mitigate a command injection attack. The escapeshellcmd() function escapes all of the shell metacharacters and control operators within a string. It decreases the risks involved in allowing user input to be passed to the shell, by escaping all metacharacters and control operators with backslashes. Hence, it is used to overcome command injection attacks. The escapeshellarg() function is used to convert a scalar value into a single-quote delimited string that can be used safely as a single argument for a shell command. It converts the existing single quotes (') value to the '\''. In this way, this sequence temporarily ends the single-quoted string and inserts a literal single quote, and then resumes the string. Since the data passed through escapeshellarg() can safely be used as a single argument, it can be used to mitigate the command injection attack.
Command injection attack
A command injection attack is used to inject and execute commands specified by the attacker in a vulnerable application. The application, which executes unwanted system commands, is like a virtual system shell. The attacker may use it as any authorized system user. However, commands are executed with the same privileges and environment as the application has. Command injection attacks are possible in most cases because of lack of correct input data validation, which can be manipulated by the attacker.
Answer options A and D are incorrect. The htmlentities() and strip_tags() PHP functions can be used to overcome cross site scripting attacks since these functions attempt to remove all valid HTML and PHP tags.
Cross site scripting (XSS) attack
A cross site scripting attack works in the following manner:
The attacker identifies a Web site that has one or more XSS bugs, for example, a Web site that echoes the contents of a querystring.
The attacker crafts a special URL that includes a malformed and malicious querystring containing HTML and PHP script.
The attacker finds a victim and gets the victim to click on a link that includes the malformed querystring. This could simply be a link to another Web page, or a link in an HTML e-mail.
Once the victim clicks the link, the victim's browser makes a GET request to the vulnerable server, bypassing the malicious querystring.
The vulnerable server echoes the malicious querystring back to the victim's browser, and the browser executes the PHP Script embedded in the response.
© 2013 Zend PHP Certification Exam