import os import pickle import base64 import hashlib from flask import Flask,request,session,render_template,redirect from Users import Users from waf import waf
@app.route('/',methods=['GET','POST']) @app.route('/index.php',methods=['GET','POST']) def index(): if not session or not session.get('username'): return redirect("login.php") if request.method=="POST" and 'file' in request.files and(filename:=waf(request.files['file'])): filepath=os.path.join("./uploads",filename) request.files['file'].save(filepath) return"File upload success! Path: <a href='pic.php?pic="+filename+"'>"+filepath+"</a>." return render_template("index.html")
@app.route('/login.php',methods=['GET','POST']) def login(): if request.method=="POST" and (username:=request.form.get('username')) and (password:=request.form.get('password')): iftype(username)==str and type(password)==str and users.login(username,password): session['username']=username return"Login success! <a href='/'>Click here to redirect.</a>" else: return"Login fail!" return render_template("login.html")
@app.route('/register.php',methods=['GET','POST']) def register(): if request.method=="POST" and (username:=request.form.get('username')) and (password:=request.form.get('password')): iftype(username)==str and type(password)==str and not username.isnumeric() and users.register(username,password): return"Register successs! Your username is {username} with hash: {{users.passwords[{username}]}}.".format(username=username).format(users=users) else: return"Register fail!" return render_template("register.html")
@app.route('/pic.php',methods=['GET','POST']) def pic(): if not session or not session.get('username'): return redirect("login.php") if (pic:=request.args.get('pic')) and os.path.isfile(filepath:="./uploads/"+pic.replace("../","")): if session.get('username')=="admin": return pickle.load(open(filepath,"rb")) else: return'''<img src="data:image/png;base64,'''+base64.b64encode(open(filepath,"rb").read()).decode()+'''">''' res="<h1>files in ./uploads/</h1><br>" for f in os.listdir("./uploads"): res+="<a href='pic.php?pic="+f+"'>./uploads/"+f+"</a><br>" return res
if __name__ == '__main__': app.run(host='0.0.0.0', port=80) import hashlib
classUsers: passwords={}
def register(self,username,password): if username in self.passwords: return False iflen(self.passwords)>=3: for u in list(self.passwords.keys()): if u!="admin": del self.passwords[u] self.passwords[username]=hashlib.md5(password.encode()).hexdigest() return True
def login(self,username,password): if username in self.passwords and self.passwords[username]==hashlib.md5(password.encode()).hexdigest(): return True return False import os from werkzeug.utils import secure_filename
for b in [b"\n",b"\r",b"\\",b"base",b"builtin",b"code",b"command",b"eval",b"exec",b"flag",b"global",b"os",b"output",b"popen",b"pty",b"repeat",b"run",b"setstate",b"spawn",b"subprocess",b"sys",b"system",b"timeit"]: if b in content: return False