Skip to content

Instantly share code, notes, and snippets.

@RoseSecurity
Last active November 16, 2023 20:06
Show Gist options
  • Save RoseSecurity/b5b7a03def992fd2614e38b7dc867f20 to your computer and use it in GitHub Desktop.
Save RoseSecurity/b5b7a03def992fd2614e38b7dc867f20 to your computer and use it in GitHub Desktop.
This script creates a basic Flask web application that serves a fake HTML page at the root route /. It has additional routes for /healthz and /callback. The /healthz route returns a simple "Healthy" response for healthchecks. The main logic is in the /callback route. It checks the request User-Agent header and if it exactly matches a specific Ch…
FROM python:3.12-slim
WORKDIR /redirector_app
# Copy the current directory contents
ADD . /redirector_app
# Install flask
RUN pip install flask
# Make TCP 443 available
EXPOSE 443
# Ensure container is healthy
HEALTHCHECK --interval=30s --timeout=3s \
CMD curl -f http://localhost/healthz || exit 1
# Run when the container launches
CMD ["python3", "redirector.py"]
from flask import Flask, request, redirect
app = Flask(__name__)
@app.route('/')
def index():
return '''
<html>
<head>
<title>Redirection Website</title>
</head>
<body>
<h1>Welcome to my redirector website!</h1>
</body>
</html>
'''
@app.route('/healthz')
def healthcheck():
return "Healthy"
@app.route('/callback')
def callback():
user_agent = request.headers.get('User-Agent')
if user_agent == 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36':
return redirect('http://10.0.0.2')
if __name__ == '__main__':
app.run(port=443)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment