题目来源:buuctf [SUCTF 2019]Upload Labs 2
目录
一、打开靶机,分析信息
还配有源码,环境靶场得文件上传漏洞,要考虑是不是有什么后缀名过滤
二、解题思路
step 1:分析源码
1.登陆页面源码admin.php 查flag方式
<?php
include 'config.php';
//定义一个名为Ad的类,包含多个公共属性
class Ad{
public $cmd;//存储要执行的系统命令
public $clazz;//要实例化的类名
public $func1;
public $func2;
public $func3;//要调用的类方法名
public $instance;//存储的实例
public $arg1;
public $arg2;
public $arg3;//分别作为$func1、$func2、$func3方法的参数
//构造函数__construct,在创建Ad类的实例时被调用,用于初始化类的属性
function __construct($cmd, $clazz, $func1, $func2, $func3, $arg1, $arg2, $arg3){
$this->cmd = $cmd;
$this->clazz = $clazz;
$this->func1 = $func1;
$this->func2 = $func2;
$this->func3 = $func3;
$this->arg1 = $arg1;
$this->arg2 = $arg2;
$this->arg3 = $arg3;
}
//check方法使用PHP的反射机制来完成下面的操作
function check(){
$reflect = new ReflectionClass($this->clazz);//创建一个ReflectionClass对象,用于获取$this->clazz指定的类的信息。
$this->instance = $reflect->newInstanceArgs();//使用反射类的newInstanceArgs方法创建$this->clazz类的实例,并将其赋值给$this->instance。
$reflectionMethod = new ReflectionMethod($this->clazz, $this->func1);
$reflectionMethod->invoke($this->instance, $this->arg1);
$reflectionMethod = new ReflectionMethod($this->clazz, $this->func2);
$reflectionMethod->invoke($this->instance, $this->arg2);
$reflectionMethod = new ReflectionMethod($this->clazz, $this->func3);
$reflectionMethod->invoke($this->instance, $this->arg3);
}
//析构函数在对象销毁时自动调用,这里使用system函数执行$this->cmd存储的系统命令。
function __destruct(){
system($this->cmd);
}
}
//主程序逻辑:
//首先检查请求的 IP 地址是否为127.0.0.1&