Skip to content

Instantly share code, notes, and snippets.

@SmugZombie
Created August 15, 2022 17:07
Show Gist options
  • Save SmugZombie/7aed85a580faaebe64f8a78a25bb2c28 to your computer and use it in GitHub Desktop.
Save SmugZombie/7aed85a580faaebe64f8a78a25bb2c28 to your computer and use it in GitHub Desktop.
<?php
function defangPayload($payload){
$re = '/((([A-Za-z]{3,9}:(?:\/\/)?)(?:[-;:&=\+\$,\w]+@)?[A-Za-z0-9.-]+|(?:www.|[-;:&=\+\$,\w]+@)[A-Za-z0-9.-]+)((?:\/[\+~%\/.\w\-_]*)?\??(?:[-\+=&;%@.\w_]*)#?(?:[\w]*))?)/im';
preg_match_all($re, $payload, $matches, PREG_SET_ORDER, 0);
foreach ($matches as $key => $value) {
$payload = str_replace($value[0], preg_replace('/\./', "[.]", $value[0]), $payload);
}
return $payload;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment