Created
June 4, 2021 15:25
-
-
Save ngregoire/d4fc1542052e3722358377dc620a6c60 to your computer and use it in GitHub Desktop.
Simple Burp extension using performAction()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package burp | |
@Suppress("unused") // Remove IDE warning, as this class will be used by burp anyway | |
class BurpExtender : IBurpExtender, ISessionHandlingAction { | |
private lateinit var cb : IBurpExtenderCallbacks | |
override fun registerExtenderCallbacks(callbacks: IBurpExtenderCallbacks) { | |
val extensionName = "A basic Kotlin template" | |
// Expose callbacks | |
this.cb = callbacks | |
// Define the extension name | |
cb.setExtensionName(extensionName) | |
// Register as a session handling action | |
cb.registerSessionHandlingAction(this) | |
} | |
override fun getActionName(): String { | |
return("Update UA") | |
} | |
override fun performAction(currentRequest: IHttpRequestResponse, macroItems: Array<IHttpRequestResponse>?) { | |
// Parse the request | |
val reqInfo = cb.helpers.analyzeRequest(currentRequest) | |
// Get the original | |
val originalBody = currentRequest.request.copyOfRange(reqInfo.bodyOffset, currentRequest.request.size) | |
val originalHeaders = reqInfo.headers | |
// Define what to change | |
val headerName = "User-Agent:" | |
val marker = "userId = agarri_fr" | |
// Iterate through headers | |
val newHeaders = mutableListOf<String>() | |
for (originalHeader in originalHeaders) { | |
val newHeader = | |
// Edit the targeted header | |
if (originalHeader.startsWith(headerName)) { "$originalHeader - $marker" } | |
// Simply copy other ones | |
else { originalHeader } | |
newHeaders.add(newHeader) | |
} | |
// May be useful when debugging | |
// cb.printOutput(headers.joinToString()) | |
// Build the modified request | |
currentRequest.request = cb.helpers.buildHttpMessage(newHeaders, originalBody) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment