Process
π§± 1. Set Up the LDAP Server
What you need:
- A running OpenLDAP server
- A web interface (PLA - phpLDAPadmin) to manually manage entries
Actions:
- Run an OpenLDAP Docker container (e.g.,
osixia/openldap) - Run a PLA Docker container and link it to the LDAP container
- Access PLA via browser to visually build your directory
Directory Structure (DIT):
Build a basic Directory Information Tree like this:
dc=example,dc=com
βββ ou=Friends
βββ uid=jdoe
β βββ cn: John Doe
β βββ telephoneNumber: 123-456-7890
βββ uid=asmith
βββ cn: Alice Smith
βββ telephoneNumber: 987-654-3210
π 2. Bind to the Server
What it means:
βBindingβ is like logging in. You authenticate to LDAP so you can read or modify the directory.
Steps:
- Connect to port
389on the server using a TCP socket - Craft a BindRequest using ASN.1/BER encoding manually
- Contains version (3), bind DN (e.g.
cn=admin,dc=example,dc=com), and password
- Contains version (3), bind DN (e.g.
- Send the BindRequest over the socket
- Wait for and parse the BindResponse to ensure login success
π 3. Query via SearchRequest
Objective:
Search for a friendβs record based on their UID (e.g., uid=jdoe) and retrieve their telephoneNumber.
Steps:
- Use the same socket connection from the bind step
- Construct a SearchRequest packet:
- Base DN:
ou=Friends,dc=example,dc=com - Scope: Subtree
- Filter: Equality filter
(uid=jdoe) - Attributes:
telephoneNumber
- Base DN:
- Encode all of that as a BER-encoded byte stream
- Send it through the socket
π© 4. Read and Parse the Response
What you'll get back:
An LDAPMessage that wraps one or more SearchResultEntry objects.
Each entry will include:
- Distinguished Name (DN)
- One or more attributes (e.g., telephoneNumber)
Steps:
- Read the raw bytes returned from the socket
- Parse them manually (byte or string-level operations)
- Look for the attribute name
telephoneNumberand extract the value next to it
π§ͺ 5. Display the Result
- Once the number is extracted, display it in the terminal
- If no result, show a βNot Foundβ message
π 6. Repeat
You should be able to run the program multiple times, input different UIDs, and get different results based on who exists in the LDAP directory.
β Summary of Steps
| Step | Action |
|---|---|
| 1 | Launch OpenLDAP + phpLDAPadmin via Docker |
| 2 | Use PLA to create users under ou=Friends |
| 3 | Open socket to LDAP server on port 389 |
| 4 | Send manual BindRequest with DN + password |
| 5 | Build and send a SearchRequest for uid=<name> |
| 6 | Read the SearchResponse, parse telephoneNumber |
| 7 | Print result to user |