Recreate Authentication Via Exposed Session Secret
Let's have a look at the source code:
app.config.update(dict(
SECRET_KEY= "e5ac-4ebf-03e5-9e29-a3f562e10b22",
SESSION_COOKIE_HTTPONLY = True
))
@app.route("/login", methods=['GET', 'POST'])
def login():
sqli = Classes()
if request.method == "POST":
values = sqli.getUser(request.form['username'])
if values:
if values[0][2] == request.form['password']:
session['userId'] = values[0][0]
session['secret'] = app.config['SECRET_KEY']
session['loggedin'] = True
pref = sqli.getApi(values[0][0])
api = pref[0][0]
return render_template("loggedin.html", api = api)
return render_template("index.html")
else:
pref = sqli.getApi(session['userId'])
api = pref[0][0]
return render_template("loggedin.html", api = api)
Exploitation:
We can start building our malicious server.
Save the snippet above to > evil_server.py and run the commands below to install some dependencies. Of course you can also run your app on whatever service you want it does not have to be python flask.
Save the following snippet code into /templates/evil.html
We are ready to start our server:
Save the snippet above to > evil_server.js and run the commands below to install some dependencies. Of course you can also run your app on whatever service you want it does not have to be nodeJs express.
Save the following snippet code into /views/evil.js
We are ready to start our server:
Now we can replace our original cookie with the tampered cookie.
And Refresh The Page.
Last updated