Embed presentation
Download as PDF, PPTX







![© 2015 Adobe Systems Incorporated. All Rights Reserved. 8
Code Injection - Command-Line injection
▪ File paths based on user input is NOT OKAY
$user_id = $_GET['user_id'];
$file = "/some/path/config/$user_id.json";
require $file;
▪ Attackers can access filesystem using "upwards" paths
?user_id=../../../etc/passwd #](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-8-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 9
$user_id = $_GET['user_id'];
$pic = "/some/path/pictures/$user_id.jpg";
if (`ls $pic`) { ... }
Code Injection - Command-Line injection
▪ Avoid user input when executing on the command line
▪ Commands like exec, passthru, and system are often used to execute bash commands
?user_id=./ && rm -Rf ~/](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-9-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 10
$user_id = $_GET['user_id'];
$file = "/some/path/config/$user_id.json";
eval ("file_get_contents('$pic');");
Code Injection - Command-Line injection
▪ Avoid using dynamic code execution
▪ Commands like eval are used to dynamically evaluate PHP code
?user_id=foo');file_get_contents('etc/passwd](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-10-320.jpg)


![© 2015 Adobe Systems Incorporated. All Rights Reserved. 13
▪ Similar to code injection, but happens when user input is used as part of a SQL query
$search = $_GET['search'];
$sql = "SELECT * FROM students WHERE name = '$search'";
▪ Can be used to delete, corrupt, or steal data.
?search=';DROP ALL TABLES
?search=';UPDATE students SET name=jerkface
?search=foo' OR public=0
Code Injection - SQL injection](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-13-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 14
▪ SANITIZE YOUR INPUTS
▪ use "bound variables"
$search = $_GET['search'];
$sql = "SELECT * FROM students WHERE name = ?";
$statement = $pdo->prepare($sql, $search);
$statement->execute();
▪ Use ORMs / Database Abstraction Layers when possible
Code Injection - SQL injection](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-14-320.jpg)










The document discusses various web security threats, including cross-site scripting (XSS), code injection, cross-site request forgery (CSRF), and session hijacking, highlighting their mechanisms and how they can be exploited. It emphasizes the importance of proper input validation, user authentication, and secure password management to protect against these vulnerabilities. Additionally, it provides best practices to help mitigate these risks, such as using SSL, sanitizing inputs, and employing secure coding techniques.







![© 2015 Adobe Systems Incorporated. All Rights Reserved. 8
Code Injection - Command-Line injection
▪ File paths based on user input is NOT OKAY
$user_id = $_GET['user_id'];
$file = "/some/path/config/$user_id.json";
require $file;
▪ Attackers can access filesystem using "upwards" paths
?user_id=../../../etc/passwd #](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-8-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 9
$user_id = $_GET['user_id'];
$pic = "/some/path/pictures/$user_id.jpg";
if (`ls $pic`) { ... }
Code Injection - Command-Line injection
▪ Avoid user input when executing on the command line
▪ Commands like exec, passthru, and system are often used to execute bash commands
?user_id=./ && rm -Rf ~/](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-9-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 10
$user_id = $_GET['user_id'];
$file = "/some/path/config/$user_id.json";
eval ("file_get_contents('$pic');");
Code Injection - Command-Line injection
▪ Avoid using dynamic code execution
▪ Commands like eval are used to dynamically evaluate PHP code
?user_id=foo');file_get_contents('etc/passwd](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-10-320.jpg)


![© 2015 Adobe Systems Incorporated. All Rights Reserved. 13
▪ Similar to code injection, but happens when user input is used as part of a SQL query
$search = $_GET['search'];
$sql = "SELECT * FROM students WHERE name = '$search'";
▪ Can be used to delete, corrupt, or steal data.
?search=';DROP ALL TABLES
?search=';UPDATE students SET name=jerkface
?search=foo' OR public=0
Code Injection - SQL injection](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-13-320.jpg)
![© 2015 Adobe Systems Incorporated. All Rights Reserved. 14
▪ SANITIZE YOUR INPUTS
▪ use "bound variables"
$search = $_GET['search'];
$sql = "SELECT * FROM students WHERE name = ?";
$statement = $pdo->prepare($sql, $search);
$statement->execute();
▪ Use ORMs / Database Abstraction Layers when possible
Code Injection - SQL injection](https://image.slidesharecdn.com/websecurity101-150410114157-conversion-gate01/85/Web-Security-101-14-320.jpg)








