douxing1353 2014-03-28 14:33
浏览 66
已采纳

这个preg_replace示例是否可以以任何方式利用?

Is this code explotable in any way?

<?
$arg=$_REQUEST['arg'];
preg_replace("/([0-9]+)(.+)/e",'list($var,$var2)=array("$1","$2")',$arg);
echo "$var - $var2";
?>

Is it possible to use special characters or some other method to inject code?

I'm using similar code in some projects and I just want to make sure that it is safe.

  • 写回答

2条回答 默认 最新

  • dongxiao0449 2014-03-28 14:39
    关注

    Using

    (.+)
    

    with /e parameter is always exploitable because it allows any language constructions there.

    Example exploit code:

    $test = new test();
    $test->setSuperSecret();
    $test->exploitableExpression();
    
    class test
    {
        private $mySuperSecretVariable;
        public function exploitableExpression()
        {
            $arg= '1234$this->mySuperSecretVariable';
            preg_replace("/([0-9]+)(.+)/e",'list($var,$var2)=array("$1","$2")',$arg);
            var_dump($var,$var2);
        }
        public function setSuperSecret()
        {
            $this->mySuperSecretVariable = 'SECRET!';
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助