Skip to content

Instantly share code, notes, and snippets.

@z00sts
Last active January 8, 2025 13:00
Show Gist options
  • Save z00sts/0722b194527f7346fde25c6a6703acd6 to your computer and use it in GitHub Desktop.
Save z00sts/0722b194527f7346fde25c6a6703acd6 to your computer and use it in GitHub Desktop.
import os
from flask import (Flask, redirect, render_template, request,
send_from_directory, url_for)
app = Flask(__name__)
@app.route('/')
def index():
print('Request for index page received')
return render_template('index.html')
@app.route('/favicon.ico')
def favicon():
return send_from_directory(os.path.join(app.root_path, 'static'),
'favicon.ico', mimetype='image/vnd.microsoft.icon')
###############################################
# positive case
@app.route('/redirect_a/api/v3', methods=['GET'])
def redirect_a_v3():
print("redirect_a_v3")
return redirect(url_for('redirect_a'))
@app.route('/redirect_a', methods=['GET'])
def redirect_a():
print("redirect_a")
return redirect(url_for('redirect_b'))
@app.route('/redirect_b', methods=['GET'])
def redirect_b():
print("redirect_b")
return redirect(url_for('redirect_c'))
@app.route('/redirect_c', methods=['GET'])
def redirect_c():
print("redirect_c")
return redirect(url_for('index'))
###############################################
###############################################
# infinite redirects
@app.route('/redirect_infi/api/v3', methods=['GET'])
def redirect_infi_api_v3():
print("redirect_infi_api_v3")
return redirect(url_for('redirect_infi_1'))
@app.route('/redirect_infi', methods=['GET'])
def redirect_infi_1():
print("redirect_infi_1")
return redirect(url_for('redirect_infi_2'))
@app.route('/redirect_infi_2', methods=['GET'])
def redirect_infi_2():
print("redirect_infi_2")
return redirect(url_for('redirect_infi_1'))
###############################################
###############################################
# redirect to internal IP
@app.route('/redirect_x/api/v3', methods=['GET'])
def redirect_x_api_v3():
print("redirect_x_api_v3")
return redirect(url_for('redirect_x'))
@app.route('/redirect_x', methods=['GET'])
def redirect_x():
print("redirect_x")
return redirect(url_for('redirect_z'))
@app.route('/redirect_z', methods=['GET'])
def redirect_z():
print("redirect_z")
return redirect(url_for('redirect_internal_ip'))
@app.route('/redirect_internal_ip', methods=['GET'])
def redirect_internal_ip():
print("redirect_internal_ip")
return redirect('http://127.0.0.1/internal/api')
################################################
###############################################
# redirect to internal IP 2
@app.route('/redirect_x2/api/v3', methods=['GET'])
def redirect_x2_api_v3():
print("redirect_x2_api_v3")
return redirect(url_for('redirect_x2'))
@app.route('/redirect_x2', methods=['GET'])
def redirect_x2():
print("redirect_x2")
return redirect(url_for('redirect_z2'))
@app.route('/redirect_z2', methods=['GET'])
def redirect_z2():
print("redirect_z2")
return redirect(url_for('redirect_internal_ip_2'))
@app.route('/redirect_internal_ip_2', methods=['GET'])
def redirect_internal_ip_2():
print("redirect_internal_ip_2")
return redirect('http://169.254.169.254')
################################################
@app.route('/hello', methods=['POST'])
def hello():
name = request.form.get('name')
if name:
print('Request for hello page received with name=%s' % name)
return render_template('hello.html', name = name)
else:
print('Request for hello page received with no name or blank name -- redirecting')
return redirect(url_for('index'))
if __name__ == '__main__':
app.run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment