<?phpinclude"mysqlDb.class.php";classctfshow{public$method;public$args;public$cursor;function__construct($method,$args){$this->method=$method;$this->args=$args;$this->getCursor();}functiongetCursor(){global$DEBUG;if(!$this->cursor)$this->cursor=MySql::getInstance();if($DEBUG){$sql="DROP TABLE IF EXISTS USERINFO";$this->cursor->Exec($sql);$sql="CREATE TABLE IF NOT EXISTS USERINFO (username VARCHAR(64),
password VARCHAR(64),role VARCHAR(256)) CHARACTER SET utf8";$this->cursor->Exec($sql);$sql="INSERT INTO USERINFO VALUES ('CTFSHOW', 'CTFSHOW', 'admin'), ('HHD', 'HXD', 'user')";$this->cursor->Exec($sql);}}functionlogin(){list($username,$password)=func_get_args();$sql=sprintf("SELECT * FROM USERINFO WHERE username='%s' AND password='%s'",$username,md5($password));$obj=$this->cursor->getRow($sql);$data=$obj['role'];if($data!=null){define('Happy',TRUE);$this->loadData($data);}else{$this->byebye("sorry!");}}functioncloseCursor(){$this->cursor=MySql::destroyInstance();}functionlookme(){highlight_file(__FILE__);}functionloadData($data){if(substr($data,0,2)!=='O:'){returnunserialize($data);}returnnull;}function__destruct(){$this->getCursor();if(in_array($this->method,array("login","lookme"))){@call_user_func_array(array($this,$this->method),$this->args);}else{$this->byebye("fuc***** hacker ?");}$this->closeCursor();}functionbyebye($msg){$this->closeCursor();header("Content-Type: application/json");die(json_encode(array("msg"=>$msg)));}}classHappy{public$file='flag.php';function__destruct(){if(!empty($this->file)){include$this->file;}}}functionezwaf($data){if(preg_match("/ctfshow/",$data)){die("Hacker !!!");}return$data;}if(isset($_GET["w_a_n"])){@unserialize(ezwaf($_GET["w_a_n"]));}else{newCTFSHOW("lookme",array());}
<?phpecho"Here are some key messages that are hidden but u can't read</br>u may try other ways to read this file to get hints";//You can only read the following(Files in the current directory),and only top 3 are necessary:
//ezwaf.php
//class.php
//index.php
//lookMe.php
/*class.php*/<?phperror_reporting(0);classLogin{protected$user_name;protected$pass_word;protected$admin;publicfunction__construct($username,$password){$this->user_name=$username;$this->pass_word=$password;if($this->user_name=='admin'&&$this->pass_word=='admin888'){$this->admin=1;}else{$this->admin=0;}}publicfunctioncheckStatus(){return$this->admin;}}classregister{protected$username;protected$password;protected$mobile;protected$mdPwd;publicfunction__construct($username,$password,$mobile){$this->username=$username;$this->password=$password;$this->mobile=$mobile;}publicfunction__toString(){return$this->mdPwd->pwd;}}classmagic{protected$username;publicfunction__get($key){if($this->username!=='admin'){die("what do you do?");}$this->getFlag($key);}publicfunctiongetFlag($key){echo$key."</br>";system("cat /flagg");}}classPersonalFunction{protected$username;protected$password;protected$func=array();publicfunction__construct($username,$password,$func="personalData"){$this->username=$username;$this->password=$password;$this->func[$func]=true;}publicfunctioncheckFunction(array$funcBars){$retData=null;$personalProperties=array_flip(['modifyPwd','InvitationCode','modifyAvatar','personalData',]);foreach($personalPropertiesas$item=>$num){foreach($funcBarsas$funcBar=>$stat){if(stristr($stat,$item)){$retData=true;}}}return$retData;}publicfunctiondoFunction($function){// TODO: 出题人提示:一个未完成的功能,不用管这个,单纯为了逻辑严密.
returntrue;}publicfunction__destruct(){$retData=$this->checkFunction($this->func);$this->doFunction($retData);}}
varexpress=require('express');varrouter=express.Router();vardb=require('mysql-promise')constmysql=require('mysql');constconnection=require("mysql");classDatabase{constructor(config){this.connection=mysql.createConnection(config);}query(sql,args){returnnewPromise((resolve,reject)=>{this.connection.query(sql,args,(err,rows)=>{if(err)returnreject(err);resolve(rows);});});}close(){returnnewPromise((resolve,reject)=>{this.connection.end(err=>{if(err)returnreject(err);resolve();});});}}constisObject=obj=>obj&&obj.constructor&&obj.constructor===Object;functionmerge(a,b){for(varattrinb){if(isObject(a[attr])&&isObject(b[attr])){merge(a[attr],b[attr]);}else{a[attr]=b[attr];}}returna}functionclone(a){returnmerge({},a);}router.get('/',function(req,res,next){console.log("index");//res.render('index', {title: 'HTML'});
})/* GET home page. */router.post('/',function(req,res,next){varbody=JSON.parse(JSON.stringify(req.body));if(body.host!=undefined){returnres.json({"msg":"fu** hacker!!!"})}varnum=0for(iinbody){num++;}if(num!=2){returnres.json({"msg":"fu** hacker!!!"})}else{if(body.username==undefined||body.password==undefined){returnres.json({"msg":"fu** hacker!!!"})}}varcopybody=clone(body)varhost=copybody.host==undefined?"localhost":copybody.hostvarflag="123432432432"varconfig={host:host,user:'root',password:'root',database:'users'};letdatabase=newDatabase(config);varuser=copybody.usernamevarpass=copybody.passwordfunctionisInValiCode(str){varreg=/-| |#|[\x00-\x2f]|[\x3a-\x3f]/;returnreg.test(str);}if(isInValiCode(user)){returnres.json({"msg":"no hacker!!!"})}letsomeRows,otherRows;database.query('select * from user where user= ? and passwd =?',[user,pass]).then(rows=>{if(1==rows[0].Id){res.json({"msg":flag})}}).then(rows=>{otherRows=rows;returndatabase.close();},err=>{returndatabase.close().then(()=>{throwerr;})}).then(()=>{res.json({"error":"err","msg":"user or pass err"})}).catch(err=>{res.json({"error":"err","msg":"user or pass err"})})});module.exports=router;