HAKATEMIA
35First exposure to vulnerabilities

Hack into a website

Easy15MIN
EXERCISES

Practice what you learned

LAB · TASK #56a2118e-c2ff-4f0c-9fd8-1b41dac55b001

Mission

VIDEOYOUTUBE

Customer Security Ltd has hired you to test the security of their internal management system. Your task is to find vulnerabilities in the application and break into the system.

The client also agreed to send you part of the system source code, but not everything.

PY
1#!/usr/bin/python3
2
3# Kirjasto tietokannan hallintaan
4from moduulit import tietokanta
5
6# Flask verkkosivu kirjastot
7from flask import Flask, render_template, redirect, request
8from flask import make_response
9
10app = Flask(__name__)
11haku = tietokanta.Haku()
12
13@app.route("/")
14def juuri():
15  # Haetaan tunniste evaste
16  tunniste = request.cookies.get('tunniste')
17  # Jos tunniste on oikea, kayttaja on kirjautunut
18  if tunniste == "ADMIN1":
19    # Haetaan hallintanakyman tiedot 
20    tiedot = haku.haeTiedot()
21    return render_template("hallinta.html", tiedot=tiedot)
22  # Muuten ohjataan kirjautumaan
23  else:
24    return redirect("/login")
25
26@app.route("/login", methods=["GET","POST"])
27def kirjaudu():
28  if request.method == "GET":
29    failed = request.args.get("vaarin")
30    return render_template("kirjaudu.html", failed=failed)
31  elif request.method == "POST":
32    # Varmistetaan, etta tunnukset ovat oikein
33    kayttaja = request.form.get("kayttaja")
34    salasana = request.form.get("salasana")
35    oikein = haku.varmistaTunnus(kayttaja, salasana)
36    if oikein:
37      # asetetaan istuntotunniste
38      vastaus = make_response("blank.html")
39      vastaus.set_cookie("tunniste", "ADMIN1")
40      return vastaus
41    else:
42      return redirect("/login?vaarin=kylla")
43
44
45if __name__ == '__main__':
46  app.run(debug=False, host='0.0.0.0')

If the task feels difficult and doesn't seem to be solvable, we recommend also exploring the Python programming as well as Web development basics -course.

Hint

Exercises

Flag

Find the flag from the lab environment and enter it below.

Hakatemia Pro

Learn to hack — start here

Hundreds of interactive courses, virtual labs and CTF challenges in your browser. Start a free trial — no card required.