老规矩,上源代码
if(isset($_POST['submit'])){
if($_POST['username']!=null && $_POST['password']!=null){
//这里没有使用预编译方式,而是使用的拼接SQL,所以需要手动转义防止SQL注入
$username=escape($link, $_POST['username']);
$password=escape($link, $_POST['password']);
$query="select * from users where username='$username' and password=md5('$password')";
$result=execute($link, $query);
if(mysqli_num_rows($result)==1){
$data=mysqli_fetch_assoc($result);
//登录时,生成cookie,1个小时有效期,供其他页面判断
setcookie('ant[uname]',$_POST['username'],time()+3600);
setcookie('ant[pw]',sha1(md5($_POST['password'])),time()+3600);
header("location:xss_reflected_post.php");
// echo '"<script>windows.location.href="xss_reflected_post.php"</script>';
}else{
$html ="<p>username or password error!</p>";
}
}else{
$html ="<p>please input username and password!</p>";
}
}
这个是登录框的代码,需要登陆成功后,才有xss,用户名:admin,密码:123456
代码的话,只是加了个cookie,和xss漏洞关系不是很大,就不讲了。
xss相关代码
if(isset($_POST['submit'])){
if(empty($_POST['message'])){
$html.="<p class='notice'>输入'kobe'试试-_-</p>";
}else{
//下面直接将前端输入的参数原封不动的输出了,出现xss
if($_POST['message']=='kobe'){
$html.="<p class='notice'>愿你和{$_POST['message']}一样,永远年轻,永远热血沸腾!</p><img src='{$PIKA_ROOT_DIR}assets/images/nbaplayer/kobe.png' />";
}else{
$html.="<p class='notice'>who is {$_POST['message']},i don't care!</p>";
}
}
}
<div id="xssr_main">
<p class="xssr_title">Which NBA player do you like?</p>
<form method="post">
<input class="xssr_in" type="text" name="message" />
<input class="xssr_submit" type="submit" name="submit" value="submit" />
</form>
<br />
你已经登陆成功,<a href="xss_reflected_post.php?logout=1">退出登陆</a> <br />
</div>
和上一关是一样,甚至这一个还没有长度限制,只是get变成了post而已。
就不细讲了。