Recreate Authentication Via Exposed Session Secret

If we are able to get session secret, we can try to recreate this application cookie implementation to be able to recreate a cookie to bypass the authentication.

But at first let's choose and Cookie generating code as an example to work on

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:

Now we can replace our original cookie with the tampered cookie.

And Refresh The Page.

Last updated