HTB bountyhunter

一、常规扫描后发现一个漏洞悬赏页面

image-20231018133629188

抓包发现传输内容加密,发现是base64+url加密

image-20231018133746427

解码后是xml传输,自然想到了xxe(xml实体注入)

XXE漏洞发生在应用程序解析XML输入时,没有禁止外部实体的加载,导致可加载恶意外部文件

image-20231018133818429

payload如下

image-20231012160338596

image-20231012160406712

测试下可以连接

image-20231012161009903

image-20231012160927023

读取db.php

image-20231018135125761

image-20231012183117943

image-20231012183147891

得到数据库账号密码,猜测也可能是ssh的密码。连接了下成功

image-20231012184009664

查看特权指令,发现是一个py脚本

image-20231017093413597

二、代码审计

#Skytrain Inc Ticket Validation System 0.1
#Do not distribute this file.

def load_file(loc):
    if loc.endswith(".md"):
        return open(loc, 'r')
    else:
        print("Wrong file type.")
        exit()

def evaluate(ticketFile):
    #Evaluates a ticket to check for ireggularities.
    code_line = None
    for i,x in enumerate(ticketFile.readlines()):
        if i == 0:
            if not x.startswith("# Skytrain Inc"):
                return False
            continue
        if i == 1:
            if not x.startswith("## Ticket to "):
                return False
            print(f"Destination: {' '.join(x.strip().split(' ')[3:])}")
            continue

        if x.startswith("__Ticket Code:__"):
            code_line = i+1
            continue

        if code_line and i == code_line:
            if not x.startswith("**"):
                return False
            ticketCode = x.replace("**", "").split("+")[0]
            if int(ticketCode) % 7 == 4:
                validationNumber = eval(x.replace("**", ""))
                if validationNumber > 100:
                    return True
                else:
                    return False
    return False

def main():
    fileName = input("Please enter the path to the ticket file.\n")
    ticket = load_file(fileName)
    #DEBUG print(ticket)
    result = evaluate(ticket)
    if (result):
        print("Valid ticket.")
    else:
        print("Invalid ticket.")
    ticket.close

main()

image-20231017093455776

image-20231017093542454

提权成功

image-20231017093605609