Created
June 1, 2025 13:23
-
-
Save ljamel/da58617186f2cd7f2143974286db29b5 to your computer and use it in GitHub Desktop.
ldapsearchctf.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
# Supprime ancien container si existant | |
docker rm -f ldap-ctf 2>/dev/null || true | |
Création du serveur ldap crateldap.sh | |
# Lance OpenLDAP | |
docker run -d --name ldap-ctf -p 389:389 \ | |
-e LDAP_ORGANISATION="CTF LDAP" \ | |
-e LDAP_DOMAIN="ctf.local" \ | |
-e LDAP_ADMIN_PASSWORD="adminpass" \ | |
osixia/openldap:1.5.0 | |
echo "[*] Attente du démarrage du serveur LDAP (10s)..." | |
sleep 10 | |
# Import des données (unité organisationnelle + utilisateur flaguser) | |
docker exec -i ldap-ctf ldapadd -x -D "cn=admin,dc=ctf,dc=local" -w adminpass <<EOF | |
dn: ou=users,dc=ctf,dc=local | |
objectClass: organizationalUnit | |
ou: users | |
dn: uid=flaguser,ou=users,dc=ctf,dc=local | |
objectClass: inetOrgPerson | |
cn: Flag User | |
sn: User | |
uid: flaguser | |
description: le flag parl0n_p3u | |
userPassword: flagpassword | |
EOF | |
echo "[*] Création de l'ACL pour autoriser la lecture anonyme..." | |
# Créer un fichier LDIF pour modifier les ACL | |
cat <<EOF > modify-acl.ldif | |
dn: olcDatabase={1}mdb,cn=config | |
changetype: modify | |
replace: olcAccess | |
olcAccess: {0}to attrs=userPassword,shadowLastChange by self write by anonymous auth by dn="cn=admin,dc=ctf,dc=local" write by * none | |
olcAccess: {1}to * by self write by dn="cn=admin,dc=ctf,dc=local" write by * read | |
EOF | |
# Appliquer la modification des ACL | |
docker exec -i ldap-ctf ldapmodify -Y EXTERNAL -H ldapi:/// < modify-acl.ldif | |
echo "[*] Test de la recherche anonyme..." | |
docker exec ldap-ctf ldapsearch -x -b "dc=ctf,dc=local" "(uid=flaguser)" description |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment