漏洞分析之thinkPHP反序列化:这就是黑客的世界吗( 三 )

toArray中前面是哪两个foreach我们不需要管,基本上不会干扰到我们整个利用链,我们把注意力放到对$this->append的遍历上,结合poc我们知道this->append的值为["axin"=>["calc.exe","calc"]],所以$key为axin,$name为["calc.exe","calc"],那么就会进入第一个if分支,跟进getRelation
public function getRelation($name = null){   if (is_null($name)) {       return $this->relation;   } elseif (array_key_exists($name, $this->relation)) {       return $this->relation[$name];   }   return;}反正最后的结果就是返回null了,也就是$relation为null,接着$key进入了getAttr(),跟进:
public function getAttr($name, &$item = null)    {        try {            $notFound = false;            $value    = $this->getData($name);        } catch (InvalidArgumentException $e) {            $notFound = true;            $value    = null;        }        // 检测属性获取器        $fieldName = Loader::parseName($name);        $method    = 'get' . Loader::parseName($name, 1) . 'Attr';        if (isset($this->withAttr[$fieldName])) {            if ($notFound && $relation = $this->isRelationAttr($name)) {                $modelRelation = $this->$relation();                $value         = $this->getRelationData($modelRelation);            }            $closure = $this->withAttr[$fieldName];            $value   = $closure($value, $this->data);        } elseif (method_exists($this, $method)) {            if ($notFound && $relation = $this->isRelationAttr($name)) {                $modelRelation = $this->$relation();                $value         = $this->getRelationData($modelRelation);            }            $value = $this->$method($value, $this->data);        } elseif (isset($this->type[$name])) {            // 类型转换            $value = $this->readTransform($value, $this->type[$name]);        } elseif ($this->autoWriteTimestamp && in_array($name, [$this->createTime, $this->updateTime])) {            if (is_string($this->autoWriteTimestamp) && in_array(strtolower($this->autoWriteTimestamp), [                'datetime',                'date',                'timestamp',            ])) {                $value = $this->formatDateTime($this->dateFormat, $value);            } else {                $value = $this->formatDateTime($this->dateFormat, $value, true);            }        } elseif ($notFound) {            $value = $this->getRelationAttribute($name, $item);        }        return $value;    }


推荐阅读