[HITCON 2017]SSRFme
buu上的一个老题,又是不会做看wp的一天
给了源码
<?php
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$http_x_headers = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$_SERVER['REMOTE_ADDR'] = $http_x_headers[0];
}
echo $_SERVER["REMOTE_ADDR"];
$sandbox = "sandbox/" . md5("orange" . $_SERVER["REMOTE_ADDR"]);
@mkdir($sandbox);
@chdir($sandbox);
$data = shell_exec("GET " . escapeshellarg($_GET["url"]));
$info = pathinfo($_GET["filename"]);
$dir = str_replace(".", "", basename($info["dirname"]));
@mkdir($dir);
@chdir($dir);
@file_put_contents(basename($info["basename"]), $data);
highlight_file(__FILE__);
remote_addr就是用来创建一个沙盒的,然后用shell_exec执行一个GET命令,escapeshellarg会转义所有引号再在整个参数上加一个引号,防止了命令注入,就是说只能执行GET。
这个GET就是一个GET请求,可以使用file协议什么的,通过Perl实现(是我不懂的东西)
整体效果就是把GET请求到的东西写入我们对应的沙盒文件夹中。本来想写直接写一个PHP的shell的,但是靶机不能访问外网,并且估计也设置了沙盒中的PHP文件都不能解析之类的限制,而写文件的路径也被控制在了沙盒内,跳目录什么的也不太行