Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| securite [2025/05/19 14:34] – [PFSENSE] huracan | securite [2025/12/15 11:22] (Version actuelle) – [COMMANDES] huracan | ||
|---|---|---|---|
| Ligne 81: | Ligne 81: | ||
| ===== HARDENING LINUX ===== | ===== HARDENING LINUX ===== | ||
| + | |||
| + | ==== HARDENING HACKMD ==== | ||
| [[https:// | [[https:// | ||
| Ligne 179: | Ligne 181: | ||
| Sceller et vérifier l’intégrité des fichiers | Sceller et vérifier l’intégrité des fichiers | ||
| Protéger la base de données des scellés | Protéger la base de données des scellés | ||
| + | |||
| + | |||
| + | ==== HARDENING TECMINT ==== | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | - 1 Securing Network Access with UFW (Uncomplicated Firewall) | ||
| + | |||
| + | In most Ubuntu installations, | ||
| + | |||
| + | sudo apt update && sudo apt install ufw -y | ||
| + | sudo ufw enable | ||
| + | |||
| + | Deny Unwanted Services | ||
| + | |||
| + | To block all incoming traffic by default and only allow specific ports, configure UFW to deny all incoming traffic, except for the services you explicitly allow: | ||
| + | |||
| + | sudo ufw default deny incoming | ||
| + | sudo ufw default allow outgoing | ||
| + | |||
| + | Allow Essential Services | ||
| + | |||
| + | To allow essential services such as SSH (for remote management), | ||
| + | |||
| + | sudo ufw allow ssh | ||
| + | sudo ufw allow http | ||
| + | sudo ufw allow https | ||
| + | |||
| + | Rate Limiting (Prevent Brute Force Attacks) | ||
| + | |||
| + | To further protect your server from brute-force attacks, you can use UFW’s rate limiting feature, which limits the number of SSH connection attempts a client can make in a given time period. | ||
| + | |||
| + | sudo ufw limit ssh | ||
| + | |||
| + | This command allows SSH connections, | ||
| + | |||
| + | - 2 Blocking Brute Force Attacks with Fail2ban | ||
| + | |||
| + | Fail2ban is an essential tool for protecting your server against brute-force attacks by monitoring log files for repeated failed login attempts and blocks the offending IP addresses. | ||
| + | |||
| + | Fail2ban can be installed from the default Ubuntu repositories: | ||
| + | |||
| + | sudo apt install fail2ban | ||
| + | |||
| + | The default configuration file for Fail2ban is located in / | ||
| + | |||
| + | sudo cp / | ||
| + | |||
| + | Now, open the jail.local file for editing: | ||
| + | |||
| + | sudo nano / | ||
| + | |||
| + | Ensure that the [sshd] section is enabled (uncomment the lines) to protect your SSH service and modify the following options: | ||
| + | |||
| + | enabled: Set this to true to activate SSH protection. | ||
| + | port: Specify the port SSH is running on (default is 22). | ||
| + | maxretry: Define the maximum number of failed login attempts before banning an IP address. | ||
| + | bantime: Define the duration of the ban (in seconds). | ||
| + | findtime: Set the time frame in which the failed attempts are counted. | ||
| + | |||
| + | For example: | ||
| + | |||
| + | [sshd] | ||
| + | enabled = true | ||
| + | port = ssh | ||
| + | maxretry = 5 | ||
| + | bantime = 3600 # Ban IP for 1 hour | ||
| + | findtime = 600 # Count attempts within 10 minutes | ||
| + | |||
| + | Once you have saved your changes, restart Fail2ban to apply the new configurations. | ||
| + | |||
| + | sudo systemctl restart fail2ban | ||
| + | |||
| + | To check the status of Fail2ban and see the active jails: | ||
| + | |||
| + | sudo systemctl restart fail2ban | ||
| + | sudo fail2ban-client status sshd | ||
| + | |||
| + | Fail2ban is now actively protecting your server from brute-force SSH login attempts. | ||
| + | |||
| + | - 3 Using AppArmor for Application Security | ||
| + | |||
| + | AppArmor is a Mandatory Access Control (MAC) system that provides an additional layer of security by enforcing policies for individual applications. | ||
| + | |||
| + | In most Ubuntu installations, | ||
| + | |||
| + | sudo systemctl enable apparmor | ||
| + | sudo systemctl start apparmor | ||
| + | |||
| + | Create Custom AppArmor Profiles | ||
| + | |||
| + | AppArmor profiles define what system resources an application can access; by default, AppArmor profiles are applied to many applications in Ubuntu, and you can find the profiles in the / | ||
| + | |||
| + | You can view which profiles are currently loaded by running: | ||
| + | |||
| + | sudo apparmor_status | ||
| + | |||
| + | If you have a custom application that needs a specific profile, you can create a new one or modify an existing one. | ||
| + | |||
| + | sudo aa-genprof / | ||
| + | |||
| + | Once the profile is created, you can enforce the profile: | ||
| + | |||
| + | sudo aa-enforce / | ||
| + | |||
| + | Enforcing or Complain Mode | ||
| + | |||
| + | AppArmor operates in two modes: enforce and complain. | ||
| + | |||
| + | In enforce mode, the profile is strictly enforced, and any violation will result in the application being blocked. | ||
| + | In complain mode, violations are logged but not enforced, making it a useful mode for testing profiles. | ||
| + | |||
| + | To change the mode of a profile: | ||
| + | |||
| + | sudo aa-enforce / | ||
| + | sudo aa-complain / | ||
| + | |||
| + | Auditing with AppArmor | ||
| + | |||
| + | AppArmor generates logs that provide insight into its enforcement actions; these logs can be found in `/ | ||
| + | |||
| + | sudo journalctl -xe | grep apparmor | ||
| + | |||
| + | - 4 Additional Security Best Practices | ||
| + | |||
| + | Beyond using UFW, Fail2ban, and AppArmor, there are other important steps you can take to further harden your server: | ||
| + | Regularly Update Your Ubuntu | ||
| + | |||
| + | Ensure that your system and all installed packages are up to date to protect against vulnerabilities: | ||
| + | |||
| + | sudo apt update && sudo apt upgrade -y | ||
| + | sudo apt dist-upgrade -y | ||
| + | |||
| + | Enable automatic security updates to keep your server protected: | ||
| + | |||
| + | sudo apt install unattended-upgrades | ||
| + | |||
| + | Disable Unused Services | ||
| + | |||
| + | Any service or application that you do not need should be disabled to reduce the attack surface. However, before disabling services, it’s important to identify which ones are running on your server using the systemctl command: | ||
| + | |||
| + | sudo systemctl list-units --type=service | ||
| + | |||
| + | Once you’ve identified the unnecessary services, you can disable them to prevent the service from starting automatically on boot, thereby reducing the attack surface. | ||
| + | |||
| + | sudo systemctl disable service-name | ||
| + | |||
| + | Use SSH Key Authentication | ||
| + | |||
| + | For improved SSH security, use SSH key pairs for authentication and disable password-based login. | ||
| + | |||
| + | ssh-keygen -t rsa -b 4096 | ||
| + | ssh-copy-id user@your-server-ip | ||
| + | |||
| + | Next, edit the SSH configuration file to disable password-based logins: | ||
| + | |||
| + | sudo nano / | ||
| + | |||
| + | Set PasswordAuthentication no, then restart SSH: | ||
| + | |||
| + | sudo systemctl restart ssh | ||
| + | |||
| + | Now, only SSH key authentication will be allowed, increasing the security of your server. | ||
| ---- | ---- | ||
| Ligne 364: | Ligne 529: | ||
| Plusieurs options permettent de contrôler la quantité de détails affichés : | Plusieurs options permettent de contrôler la quantité de détails affichés : | ||
| - | |||
| * v : augmente la verbosité et affiche plus d’informations sur les paquets, comme le Time-to-Live (TTL) et le type de service. | * v : augmente la verbosité et affiche plus d’informations sur les paquets, comme le Time-to-Live (TTL) et le type de service. | ||
| * vv : niveau de verbosité encore plus élevé, montrant par exemple les noms de domaine pour les adresses IP. | * vv : niveau de verbosité encore plus élevé, montrant par exemple les noms de domaine pour les adresses IP. | ||
| * vvv : verbosité maximale pour une capture encore plus détaillée. | * vvv : verbosité maximale pour une capture encore plus détaillée. | ||
| + | |||
| + | | Flag | Description | ||
| + | | -i < | ||
| + | | -n | N’effectuez pas de résolution DNS inversée sur les adresses IP | | ||
| + | | -w < | ||
| + | | -s | Durée de capture: quantité de données à capturer à partir de chaque image | | ||
| + | | -c < | ||
| + | | -p | Ne mettez pas l’interface en mode promiscuité | ||
| + | | -v | Mode Verbose (bavard) | ||
| + | | -e | Imprimer l’en-tête de la couche de liaison sur chaque ligne | | ||
| + | |||
| + | | Valeur | ||
| + | | S | SYN | Initialisation de la connexion | ||
| + | | F | FIN | Connexion terminée | ||
| + | | P | PUSH | Data push | | ||
| + | | R | RST | Réinitialisation de la connexion | ||
| + | | . | ACK | Acquittement de la connexion | ||
| + | | E | ECE | ECN Echo (gestion congestion) | ||
| + | | W | CWR | Congestion Window Reduced | ||
| exemple: | exemple: | ||
| Ligne 379: | Ligne 562: | ||
| -A => pour entête (Attention mdp en clair pour non LDAPS) | -A => pour entête (Attention mdp en clair pour non LDAPS) | ||
| + | |||
| + | === Autre exemple === | ||
| + | |||
| + | #tcpdump -i ens33 -nn -s0 -v port 443 | ||
| + | | ||
| + | • -i : Sélectionnez l’interface sur laquelle la capture doit avoir lieu, | ||
| + | ce sera souvent une carte Ethernet ou un adaptateur sans fil, | ||
| + | mais pourrait également être un vlan ou quelque chose de plus inhabituel. | ||
| + | Pas toujours nécessaire s’il n’y a qu’une seule carte réseau. | ||
| + | • -nn : un seul (n) ne résoudra pas les noms d’hôte. | ||
| + | Un double (nn) ne résoudra pas les noms d’hôte ou les ports. | ||
| + | Ceci est pratique non seulement pour visualiser les numéros IP / port, | ||
| + | mais également lors de la capture d’une grande quantité de données, car la résolution du nom ralentira la capture. | ||
| + | • -s0 : longueur de capture, est la taille du paquet à capturer. | ||
| + | -s0 définira la taille sur illimité – utilisez ceci si vous voulez capturer tout le trafic. | ||
| + | Nécessaire si vous souhaitez extraire des binaires / fichiers du trafic réseau. | ||
| + | • -v: Verbose, l’utilisation de (-v) ou (-vv) augmente la quantité de détails affichés dans la sortie, | ||
| + | affichant souvent des informations plus spécifiques au protocole. | ||
| + | • port 443 : il s’agit d’un filtre de port commun pour capturer uniquement le trafic sur le port 80, | ||
| + | | ||
| + | |||
| === Limiter le nombre de paquets capturés === | === Limiter le nombre de paquets capturés === | ||
| Ligne 391: | Ligne 595: | ||
| #tcpdump src 192.168.1.1 | #tcpdump src 192.168.1.1 | ||
| + | |||
| + | === Subnet source : capturer les paquets provenant d’un subnet spécifique : === | ||
| + | |||
| + | #tcpdump src net 192.168.1.0/ | ||
| === Adresse IP de destination : capturer les paquets allant vers une adresse spécifique : === | === Adresse IP de destination : capturer les paquets allant vers une adresse spécifique : === | ||
| Ligne 558: | Ligne 766: | ||
| [[https:// | [[https:// | ||
| + | |||
| + | 0- Liste scan subnet: | ||
| + | |||
| + | #nmap -sn 192.168.1.1 -oG - | awk '/ | ||
| 1- Scanner un seul host : | 1- Scanner un seul host : | ||