Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Created August 15, 2022 17:06
Show Gist options
  • Save SmugZombie/3819f30ef60037bf621cc6547d5af8c8 to your computer and use it in GitHub Desktop.
Save SmugZombie/3819f30ef60037bf621cc6547d5af8c8 to your computer and use it in GitHub Desktop.
function defangPayload(payload){
const re = /((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w\-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/img;
const array = [...str.matchAll(re)];
for (let index = 0; index < array.length; index++) {
payload = payload.replace(array[index][0], array[index][0].replace(/\./g, "[.]"));
}
return payload;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment