Made by :

Ben Hnia Intidhar

Abdelkefi Farah

Ben Hajla Nour

Install and Configure OpenLDAP

Install slapd and change the instance suffix

to install the server , we run this command :

sudo apt install slapd ldap-utils

image

to change the Directory Information Tree (DIT) suffix , we run the following command :

sudo dpkg-reconfigure slapd`    

we used dc=example,dc=com

image

Create Users and Groups

We create the following file called add-users.ldif :

image

Now to implement the change, we run the below command :

ldapadd -x -D cn=admin,dc=example,dc=com -W -f add-users.ldif 

image

Users have been added to the server .

Now we do the same thing to add groups to the server : We create the file called add-groups.ldif file

image

we run this command to implement the change :

ldapadd -x -D cn=admin,dc=example,dc=com -W -f add-groups.ldif 

image

Modify Users

To modify a user , we create a file called modify-user.ldif:

image

To implement the changes , we run the following command :

 ldapmodify -x -D cn=admin,dc=example,dc=com -W -f modify-user.ldif

image

Add certificates to users

We create a directory for certificates authority

mkdir ~/projet/ldap/auth

we generate CA certificate

openssl genrsa -out ca.priv 2048
openssl rsa -in ca.priv -pubout -out ca.pub
openssl req -x509 -new -days 3650 -key ca.priv -out ca.cert

Now we generate certificates for users and sign them

mkdir ~/projet/ldap/clients && cd ~/projet/ldap/clients
openssl genrsa -out user1.priv 2048
openssl rsa -in user1.priv -pubout -out user1.pub
openssl req -new -key user1.priv -out user1.csr

openssl genrsa -out user2.priv 2048
openssl rsa -in user2.priv -pubout -out user2.pub
openssl req -new -key user2.priv -out user2.csr

cd ~/projet/ldap/auth
openssl x509 -req -in ~/projet/ldap/clients/user1.csr -CA ca.cert -CAkey ca.priv -CAcreateserial -out     ~/projet/ldap/clients/user1.cert -days 3650
openssl x509 -req -in ~/projet/ldap/clients/user2.csr -CA ca.cert -CAkey ca.priv -CAcreateserial -out ~/projet/ldap/clients/user2.cert -days 3650 

image

To add ther certificates to user , we install LDAP Acount Manager LAM /

sudo apt -y install ldap-account-manager

We access the LAM management interface in your browser http://localhost/lam and we add the generated certificates

image

LDAPS

1- Generate Self Signed SSL certificates

1-1- First we create the key by running the following command

openssl genrsa -aes128 -out example.com.key 4096   

image

1-2- Now to remove the passphrase from the generated private key we run

openssl rsa -in example.com.key -out example.com.key

image

1-3- Now we generate the request :

openssl req -new -days 3650 -key example.com.key -out example.com.csr

image

1-4- finally, we sign the certificate by running this command :

  sudo openssl x509 -in example.com.csr -out example.com.crt -req -signkey example.com.key -days 3650

image

2- Configure SSL on openLDAP Server

2-1- Now let's copy the certificates and key to /etc/ldap/sasl2 directory : We run

 sudo cp example.com.{key,crt} /etc/ldap/sasl2/
 sudo cp /etc/ssl/certs/ca-certificates.crt /etc/ldap/sasl2`

image image

2-2- Now we change Ownership of the certificate to openldap User . We run this command

sudo chown -R openldap:openldap /etc/ldap/sasl2/

to see the changes we run ll /etc/ldap/sasl2/

image

2-3- We create LDAP configuration file called SSL-LDAP.ldif :

image

2-4- To configure LDAP Server to use SSL Certificates , We run :

sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f SSL-LDAP.ldif

image

2-5- we edit /etc/default/slapd.We run

sudo nano /etc/default/slapd 

and we add ldaps:/// to SLAPD_SERVICES

image

2-6- we edit /etc/ldap/ldap.conf. We run

sudo nano /etc/ldap/ldap.conf 

and we comment line TLS_CACERT etc/ssl/certs/ca-cerificates.crt and we add

  TLS_CACERT  /etc/ldap/sasl2/ca-certificates.crt
  TLS_REQCERT allow 

image

Finally ,We restart LDAP Server :

sudo systemctl restart slapd

image

3- Verify

We Verify by executing ldapsearch command :

ldapsearch -x -H ldaps://192.168.56.103 -b "dc=example,dc=com" 

image

image

It worked

Verify user's authentication

Step 1: Install the necessary LDAP client packages on the client machine and configure the server's IP address:

sudo apt-get install ldap-utils libpam-ldap libnss-ldap

Step 2: Configure /etc/nsswitch.conf

Edit the /etc/nsswitch.conf file to include LDAP in the data sources for name resolution:

sudo nano /etc/nsswitch.conf

Make sure the following lines include "ldap":

passwd:         compat ldap
group:          compat ldap
shadow:         compat ldap

image

Step 3: Configure /etc/pam.d/common-session

Edit the /etc/pam.d/common-session file to include LDAP session:

sudo nano /etc/pam.d/common-session

Add the following line:

session required pam_mkhomedir.so skel=/etc/skel/ umask=077

image

Step 4: Restart services

sudo systemctl restart nscd
sudo systemctl restart nslcd

Step 5: Ensure that users can successfully authenticate on the OpenLDAP server:

sudo login
# Enter the UID
# Enter the password

image

SSH Authentication

Run the below commands to install the necessary packages i

sudo apt-get install openssh-server libpam-ldap

image

then we edit sshd_config in /etc/ssh/ by running

sudo nano /etc/ssh/sshd_config

image image image

and we edit sshd in /etc/pam/ by running

sudo nano  /etc/pam.d/sshd

image

and we edit access.conf in /etc/security/ by running

sudo nano /etc/security/access.conf

image

restart ssh to enable the new configuration by running

sudo systemctl restart ssh

image

4- Test

then we try to test SSH access for an authorized user and an unauthorized user by running these commands in the clients machines

ssh username@your_server_ip

image

image

Apache Integration

Install and configure Apache2

First we install apache2 by executing this command

sudo apt-get -y install apache2

Configure SSL setting to use secure encrypt connection

after creating certificates for the server, we add these two lines

SSLCertificateFile /etc/ssl/private/server.crt SSLCertificateKeyFile /etc/ssl/private/server.key

to /etc/apache2/sites-available/default-ssl.conf file

image

then we run this commands

a2ensite default-ssl
a2enmod ssl

To activate the new configuration , we run

sudo systemctl restart apache2

Now we can access to the page from a client computer with a Web browser via HTTPS.

image

this screen is shown because Certificates is self-signed but it's not a problem,we click on Accept the Risk and Continue

Basic Authentication

we run this command :

a2enmod ldap authnz_ldap

image

we create a new file called auth-ldap.conf in etc/apache2/sites-availables/ :

image

We only let the users in group2 (user2) access the page

we run this command

a2ensite auth-ldap 

and restart apache2 to enable the new configuration by running

sudo systemctl restart apache2

Now, we create a new directory called auth-ldap in /var/www/html/ and we create index.html in it

image

Demo

when we try to access the page with user1 (not in group2 ) :

image

We have to re-enter the username and password because he's not authorized to access the page.

image

Now, we try to access it with user2 (in group2):

image

we access it with user2

image

OpenVpn

Make sure to install OpenVPN on your Ubuntu server:

sudo apt update
sudo apt install openvpn

Edit the /etc/pam.d/openvpn file:

auth requisite pam_unix.so
auth required pam_ldap.so
account requisite pam_unix.so
account required pam_ldap.so

Restart the OpenVPN and LDAP services to apply the changes:

sudo systemctl restart openvpn
sudo systemctl restart slapd

we write the server Configuration : server.ovpn

image

We run

sudo openvpn --config server.ovpn

we write the client Configuration : user1.ovpn

image

We run

sudo openvpn --config user1.ovpn

Partie 2 : Gestion des Services RĂ©seau avec DNS :

What is DNS?

The Domain Name System (DNS) is the phonebook of the Internet. Humans access information online through domain names, like nytimes.com or espn.com. Web browsers interact through Internet Protocol (IP) addresses. DNS translates domain names to IP addresses so browsers can load Internet resources.

Each device connected to the Internet has a unique IP address which other machines use to find the device. DNS servers eliminate the need for humans to memorize IP addresses such as 192.168.1.1 (in IPv4), or more complex newer alphanumeric IP addresses such as 2400:cb00:2048:1::c629:d7a2 (in IPv6). image

DNS server configuration:

install Bind9:

The reference DNS server, BIND (Berkeley Internet Name Domain), is from the Internet Software Consortium.

sudo apt-get install bind9

image

configuration:

The main configuration of BIND9 is done in the following files:

/etc/bind/named.conf

/etc/bind/named.conf.options

/etc/bind/named.conf.local

image

We will configure a forwarder, which is a DNS server that will handle requests that your server cannot resolve, essentially all requests except those for the zone that we will host for our local machines.

To do this, we will modify named.conf.options with the command:

sudo nano /etc/bind/named.conf.options

We uncomment the forwarders block and specify, for example, the IP address of the DNS server provided by the DHCP server of your router. We have set the IP address of a Google DNS like 8.8.8.8 and 8.8.4.4

image

To host our own zone as the master server, we will modify the named.conf.local file using the command:

sudo nano /etc/bind/named.conf.local

image

Then, we need to create the file /etc/bind/local.lan to go along with it. To do this, we will copy db.local, which serves as a reference. You type:

sudo cp /etc/bind/db.local /etc/bind/local.lan

Edit the file with

nano /etc/bind/local.lan we modify the zone. Here we define the Start Of Authority (SOA). For this, we declare ns (for Name server). We also declare a second name, root, here

After defining the SOA, still ns, we also declare one or more A-type records. An A-type record allows mapping a DNS name to an IP address.

image

we need to create the file /etc/bind/inv.lan

sudo cp /etc/bind/db.127 /etc/bind/inv.lan

Edit the file with

nano /etc/bind/inv.lan

image

we have also to edit /etc/resolv.conf

sudo nano /etc/resolv.conf

image

Add DNS records for OpenLDAP, Apache and OpenVPN:

we have first to add zones in named.conf.local

image

then add records in local.lan

image

and then w create the files apache.lan, ldap.lan and openvpn.lan using

sudo cp /etc/bind/db.127 /etc/bind/apache.lan

sudo cp /etc/bind/db.127 /etc/bind/ldap.lan

sudo cp /etc/bind/db.127 /etc/bind/openvpn.lan

edit them with:

nano /etc/bind/apache.lan

image

nano /etc/bind/ldap.lan

image

nano /etc/bind/openvpn.lan

image

Testing

Restart BIND9 with

sudo service bind9 restart

From there, on another machine, you should be able to test the resolution of ns.local.lan. On a Windows machine, you can type in a command prompt:

nslookup

We instruct nslookup to use your Linux server as the DNS server

server 192.168.56.102

Now, we try to resolve ns.local.lan

ns.local.lan

image

apache.local.lan

image

ldap.local.lan

image

openvpn.local.lan

image

now in reverse:

image

Partie 3: Kerberos

Introduction :

Kerberos is a network authentication protocol designed to provide secure authentication for client-server applications. The primary goal of Kerberos is to enable secure communication over a non-secure network, such as the Internet.

1.The user initiates a service request and forwards a ticket-granting ticket (TGT) request to the Kerberos Authentication Server (AS).

2.The AS validates the user's identity and responds by providing an encrypted TGT.

3.Upon decrypting the TGT, the user submits it to the Ticket-Granting Server (TGS) to obtain a service ticket.

4.The TGS authenticates the TGT and issues a service ticket in return.

5.With the received service ticket in hand, the user transmits it to the Service Server.

6.At this point, the client gains access to the requested service, leveraging the provided service ticket. Capture6663

Environment Preparation and Initial System Configuration :

1-Clock synchronization :

We begin by verifying and synchronizing the clocks of the two machines :

Clock synchronization is crucial in the context of Kerberos due to how the protocol manages ticket validity periods. Kerberos relies on timestamps to ensure the security and authenticity of exchanges between parties.

Screenshot 2024-01-14 144614

Screenshot 2024-01-14 144632

2-Changing Hostnames :

We start by executing this command

hostnamectl --static set-hostname kdc.example.com

hostname1

We do the same for the client machine

hostname2

3-Getting IP Adresses :

Now we need to get the IP Adresses of all the two machines:

KDC: 192.168.56.102 Client: 192.168.56.101

ad ip

ip2

4-Adding IP Adresses in /etc/hosts files

The next step is to add the IP adresses of the two machines in /etc/hosts files. We execute this command :

sudo gedit /etc/hosts

aa

now we can test the communication with:

ping client

ping kdc

Screenshot 2024-01-14 144402

Screenshot 2024-01-14 144442

Installation and Configuration of Kerberos Server :

1-Installation :

We first start exectuing these commands in order to install krb5-kdc, krb5-admin-server and krb5-config libraries needed for this step:

sudo apt-get update

sudo apt-get install krb5-kdc krb5-admin-server krb5-config

Screenshot 2024-01-14 150812

krb5-kdc : provides the central authentication server for Kerberos.

krb5-admin-server : provides the administration server for the KDC.

krb5-config : provides configuration files and scripts for setting up and managing a Kerberos realm.

Screenshot 2024-01-14 151327

Screenshot 2024-01-14 151651

2-Configuration :

We now execute this command :

sudo krb5_newrealm

This command create a new Kerberos realm on a server. It will create new Kerberos database and administration server key, generate a new Kerberos configuration file for the new realm and set up the initial set of administrative principals and policies for the new realm.

When installing the packages, some prompts will appear in order to configure the KDC server

Realm : EXAMPLE.COM (must be in uppercase)

Kerberos server : kdc.example.com

Administrative server : kdc.example.com (in our case it's the same as the kdc server)

We find that these files were created :

Screenshot 2024-01-14 152044

stash:

The stash file is often associated with securing the Kerberos database. It's typically a stash file used to securely store the master key of the Kerberos Key Distribution Center (KDC).

In other words, during the Kerberos server configuration, the master key of the KDC is often stored in a stash file. This file needs to be protected as it contains sensitive information.

kadm5.acl:

The kadm5.acl file specifies access rules for administering the Kerberos server. It determines which individuals or principals have the right to perform administrative operations on the Kerberos database. Administrative operations include creating principals, modifying password policies, etc.

Adding The Principals:

Here is the list of principals before adding new ones :

Screenshot 2024-01-14 152738

We start with the user principal:

sudo kadmin.local

kadmin.local: add_principal user1

We can verify that the principal is created

kadmin.local: list_principals

Screenshot 2024-01-14 153334

we can verify the details of the principal created :

Screenshot 2024-01-14 153635

Screenshot 2024-01-14 153843

Screenshot 2024-01-14 154246

Now we create the admin principal:

kadmin.local: add_principal root/admin

Next, we need to grant all access rights to the Kerberos database to admin principal root/admin in the configuration file /etc/krb5kdc/kadm5.acl

sudo nano /etc/krb5kdc/kadm5.acl

Screenshot 2024-01-14 152241

Keytab Creation :

To establish authentication between a Kerberos client and server without requiring user interaction, a keytab file is used. This file contains the principal and its associated key, allowing services to authenticate without user input.

1-Generate a Keytab File:

Use the ktutil utility to create a keytab file.

2-Verify the algorithm used :

algo cherché

3-Add a Principal to the Keytab:

Inside ktutil, assign a key to root/admin.

keytab

Screenshot 2024-01-14 164310

we also add the host :

Screenshot 2024-01-14 170514

Screenshot 2024-01-14 180207

SSH Authentication :

The authentication principle in Kerberos with SSH involves using the Kerberos protocol to establish the identity of users and secure communications over a network. SSH, which stands for Secure Shell, is a secure network protocol that allows secure access to remote machines over an unsecured network.

SSH (Secure Shell):

SSH is a secure communication protocol used for encrypted access to remote machines. It is commonly used for remote server administration, secure file transfers, and executing commands on remote machines. Authentication in SSH can be achieved using various methods, such as password entry, the use of public/private keys, and also through integration with Kerberos.

Integration of Kerberos with SSH:

When a user wants to connect to a remote machine via SSH, they can use their Kerberos ticket to authenticate without entering an additional password. The Kerberos ticket serves as proof of the user's identity, eliminating the need to share passwords directly with the remote server.

ssh_1112

1-Installation :

installssh

2-Configuration :

We start by modifying two files: sshd_config and ssh_config, uncommenting these two lines: GSSAPIAuthentication yes and GSSAPICleanupCredentials yes.

"GSSAPIAuthentication yes" enables authentication via the Generic Security Services Application Program Interface (GSSAPI), which is a standard authentication framework used in various systems.

"GSSAPICleanupCredentials yes" specifies that GSSAPI credentials should be cleaned up after the connection. This allows for the release of resources associated with GSSAPI authentication once the connection is terminated.

By uncommenting these lines in the SSH configuration files (sshd_config for the SSH server and ssh_config for the SSH client), we activate GSSAPI authentication. This modification may be necessary in environments where Kerberos ticket-based authentication is used, for example, to enhance SSH access security. It provides an additional authentication method based on the system's security mechanisms, thereby expanding authentication options for users and system administrators.

ssh

sshd

3-Authentication

Firstly, verify the list of principals (user and admin) and check the keytab associated with root/admin.

principals+ajoutkeytab

Create the host and add the keytab for the host.

add host

Then, add a user. Initially, when attempting to access kds.example.com, the user need to enter the password

faire un user

Goal : Enable the user to access without entering a password.

Assigning a ticket to this user involves using the kinit command to generate a ticket for 'user1. After generating the ticket, you can use the klist command to confirm its presence.

generer le ticket tgt

Then, when you attempt to SSH into 'kdc.example.com', the user should be able to access the machine without providing a password.

le user a bien acceder a cette machine

Configure the client machine:

Perform the same steps by installing Kerberos (krb5-user) and configuring it.

Verify the krb5.conf file as shown in the screenshot below:

Screenshot 2024-01-14 192119

Then, install OpenSSH server and modify the configuration files, similar to what was done on the KDC machine

Add a user and attempt to access the machine. Initially, there is no ticket.

Access 'kdc.example.com' (initially with the password).

Generate a ticket and confirm its generation, as shown in the screenshot:

Screenshot 2024-01-14 194506

Access the machine without entering the password, as depicted in the screenshots:

Screenshot 2024-01-14 194801

On the KDC machine, view the log of the client machine accessing it :

Screenshot 2024-01-14 194746

Screenshot 2024-01-14 194849

Perform a simple test:

On the KDC machine, echo the hostname into a file.

Test on the client machine to verify the consistency of results.

KDC Machine:

Screenshot 2024-01-14 195230

Client Machine:

Screenshot 2024-01-14 195244