Exploit Writing
Table of Contents
Code Snippets
Starting Template
Useful imports
Using the requests library
requests librarySending the simplest HTTP request
Specifying different HTTP methods
Reading the HTTP response
Sending data as a query string in the URL (Using params argument)
Sending data as a query string in the body (Using data argument)
Sending data as a JSON in the body (Using json argument)
Sending a file in the body (Using files argument)
Setting HTTP headers (Using headers argument)
Setting HTTP cookies (Using cookies argument)
Disabling following of 3XX redirects (Using allow_redirects argument)
Interacting with an unverified HTTPS server (Using verify argument)
Sending request through a HTTP proxy (Using proxies argument)
Creating a Session
Setting persistent cookies
Setting persistent headers
Troubleshooting
Use Wireshark and filter for HTTP requests
Open Wireshark
Select the VPN interface (e.g
tun0)Enter
httpinto the filter bar.
Print contents of the HTTP request
Proxy HTTP request through Burp Suite and inspect
Open Burp Suite
Navigate to "Proxy" Tab and set "Intercept" to "On".
Reusable code
Serving files via HTTP
Stealing HTTP cookies
Speeding up SQL injections
Tips
Perform a sanity check after every HTTP request using assert
assertCatch whether a webshell is indeed uploaded before attempting to trigger it
Catch whether authentication is sucessful before exploiting authenticated features
Example:
Print meaning messages after each step
Action being started/finished OR
Cookies/tokens/files/values that were retrieved
Example:
Separate each exploitation step into its own function
Example:
Create a global Session object so it does not need to be explictly passed to each function call
Session object so it does not need to be explictly passed to each function callCreate a global BASE_URL string and construct the required URLs from it
BASE_URL string and construct the required URLs from itTo force all HTTP requests to go through Burp Suite without the use of the proxies argument , set the HTTP_PROXY / HTTPS_PROXY environment variable when running
proxies argument , set the HTTP_PROXY / HTTPS_PROXY environment variable when runningApply encoding/decoding scheme(s) to enable safe transmission of payloads
Base64
Hexadecimal
Use """ to create the payload string if it contains both single (') and double quotes (")
""" to create the payload string if it contains both single (') and double quotes (")Example:
Speed up SQL injections using multithreading
Hardcode an authenticated user's cookie when developing exploits for authenticated features
Especially if a lot of time-consuming steps had to be done to obtain an authenticated session
Example:
Avoid using f-strings (f"") or str.format if the payload contains too many curly braces ({})
f"") or str.format if the payload contains too many curly braces ({})Doubling each curly brace just to escape them can be troublesome and error-prone. Instead use simple placeholders and do a .replace()!
Example:
Last updated