Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out email addresses in responses #32

Merged
46 changes: 46 additions & 0 deletions Proxy/HTTP/EmailHighlighter.bambda
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Script to Filter Out Email Addresses in Responses and Highlight Them if Found
* @author Tur24Tur / BugBountyzip (https://github.com/BugBountyzip)
**/

boolean manualColorHighlightEnabled = true;

// Set of file extensions to ignore
Set<String> ignoredExtensions = Set.of("mp4", "mp3", "png", "gif", "jpg", "jpeg", "css", "pdf");

if (!requestResponse.hasResponse()) {
return false;
}

// Retrieve the URL from the request part of the requestResponse object
String requestUrl = requestResponse.request().url().toString();


for (String ext : ignoredExtensions) {
// Check if the URL ends with any of the ignored file extensions
if (requestUrl.toLowerCase().endsWith("." + ext)) {
return false;
}
}

// Extract the response body as a string and remove any leading and trailing whitespace
var body = requestResponse.response().bodyToString().trim();


String emailRegexPattern = "\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.(?!jpeg|png|jpg|gif|webp)[A-Z|a-z]{2,7}\\b";
Pattern emailPattern = Pattern.compile(emailRegexPattern);

// Create a matcher to find email addresses in the response body
Matcher emailMatcher = emailPattern.matcher(body);
if (emailMatcher.find()) {
if (manualColorHighlightEnabled) {

requestResponse.annotations().setHighlightColor(HighlightColor.GREEN);
// Add a note indicating that an email was found
requestResponse.annotations().setNotes("Email Found!: " + emailMatcher.group());
}
return true;
}


return false;