issue101:site_web_avec_infrastructure
Différences
Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
issue101:site_web_avec_infrastructure [2015/09/28 23:59] – créée d52fr | issue101:site_web_avec_infrastructure [2015/10/06 23:05] (Version actuelle) – d52fr | ||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | Now that that our Linux VM is built, we must add security for better server protection; this will be accomplished by using the Linux firewall capabilities. Afterwards, we will install a web server and set up additional security on the web server. | + | ====== SITE WEB AVEC INFRASTRUCTURE ====== |
- | Today we will focus on the Linux firewall. | + | **Now that that our Linux VM is built, |
- | A Firewall is basically a set of rules. As best practice, we'll use the “deny access” default rule – this means that unless specified otherwise, an incoming network packet will be dropped. | + | Maintenant que notre machine virtuelle Linux est construite, nous devons augmenter la sécurité pour améliorer la protection du serveur ; ce sera fait en utilisant les capacités du pare-feu Linux. Après cela, on installera un serveur Internet et on y implantera des sécurités additionnelles. |
- | External access to our server will be allowed under: | + | **Today we will focus on the Linux firewall. We will use iptables, standard Linux firewall functionality. |
+ | |||
+ | A Firewall is basically a set of rules. As best practice, we'll use the “deny access” default rule – this means that unless specified otherwise, an incoming network packet will be dropped.** | ||
+ | |||
+ | Aujourd' | ||
+ | |||
+ | Un pare-feu est essentiellement un ensemble de règles. Nous allons utiliser par défaut la règle « accès refusé » (deny access), c' | ||
+ | |||
+ | **External access to our server will be allowed under: | ||
• SSH - for remote control | • SSH - for remote control | ||
• HTTP -server web pages (our website) | • HTTP -server web pages (our website) | ||
- | Right now, anybody can try connecting to our server via SSH. Obviously, that will not be possible without the private key; however, we'd like to limit who can even try to connect to our server – this is just best practice and limits access to any additional potential hacks. | + | Right now, anybody can try connecting to our server via SSH. Obviously, that will not be possible without the private key; however, we'd like to limit who can even try to connect to our server – this is just best practice and limits access to any additional potential hacks.** |
- | For example – let's suppose you live in the US – it's probably a good idea to allow SSH connections only from the US (any SSH connection attempt from outside the US is not legitimate – it's not you!!! - so it should be banished). | + | L'accès depuis l'extérieur sur notre serveur sera autorisé sous : |
+ | • SSH - pour un contrôle à distance. | ||
+ | • HTTP - pour les pages Web du serveur | ||
- | In addition, we may decide we will not do business with specific countries – we will block any web access (HTTP) from these countries. In my example, I will choose Canada (note here – this is only an example, there is absolutely nothing wrong with Canada what.so.ever – I am just choosing a country which is a Democracy, this way, I know I won't get into trouble!!!). | + | En ce moment, n' |
- | Please note that checking | + | **For example – let's suppose you live in the US – it's probably a good idea to allow SSH connections only from the US (any SSH connection attempt |
- | Without getting into too much detail, the firewall rules can be set for incoming, outgoing, and forward | + | Par exemple, supposons que vous habitiez aux États-Unis – il est probablement judicieux de ne permettre des connections |
- | Since we are not forwarding anything, | + | **In addition, |
- | Step by step now | + | De plus, il se peut que vous décidiez de ne pas faire d' |
+ | |||
+ | **Please note that checking the incoming country is not foolproof – the source connection can spoof the IP address (or just VPN into a server from an unblocked country). Anyway – this is good protection against automatic bot scanners and will definitely help keep hackers away. | ||
+ | |||
+ | Without getting into too much detail, the firewall rules can be set for incoming, outgoing, and forward connections.** | ||
+ | |||
+ | Notez cependant que le contrôle du pays de provenance n'est pas absolument sûr. La connexion initiale peut utiliser une fausse adresse IP (ou passer par VPN dans un serveur situé dans un pays autorisé). Néanmoins, c'est une bonne protection contre les robots scanneurs et cela aidera de toute façon à éloigner les pirates. | ||
+ | |||
+ | Sans aller trop dans le détail, les règles du pare-feu peuvent être établies pour les connexions entrantes, sortantes et les transferts de connexion. | ||
+ | |||
+ | **Since we are not forwarding anything, we will just set rules for incoming (most important), outgoing (more later on why) and ignore forwarding (by default forwarding is disabled in the kernel anyway).** | ||
+ | |||
+ | Comme nous ne transférons rien, nous allons juste établir des règles pour le trafic entrant (le plus important) et le trafic sortant (j' | ||
+ | |||
+ | **Step by step now | ||
Quick reminder: only sudo (or root) can set up firewall rules. To switch to root, I recommend typing: | Quick reminder: only sudo (or root) can set up firewall rules. To switch to root, I recommend typing: | ||
+ | |||
+ | sudo su** | ||
+ | |||
+ | Étape par étape maintenant : | ||
+ | |||
+ | Petit rappel : seul sudo (ou root, l' | ||
sudo su | sudo su | ||
- | 1 – Reset any firewall rule and DROP any incoming connections: | + | **1 – Reset any firewall rule and DROP any incoming connections: |
Most distributions come with some type of firewall rules set up by default. (Centos & Suse do for sure – not totally sure about Ubuntu). | Most distributions come with some type of firewall rules set up by default. (Centos & Suse do for sure – not totally sure about Ubuntu). | ||
Ligne 38: | Ligne 68: | ||
And by default DROP any incoming connections: | And by default DROP any incoming connections: | ||
+ | |||
+ | iptables -P INPUT DROP** | ||
+ | |||
+ | 1 – réinitialiser le pare-feu et bloquer TOUT le trafic entrant : | ||
+ | |||
+ | La plupart des distributions sont livrées par défaut avec quelques règles de pare-feu (certainement pour ce qui concerne CentOS et Suse, j'en suis moins sûr pour Ubuntu). | ||
+ | |||
+ | Nous allons effacer toutes les règles pour pouvoir repartir de zéro : | ||
+ | |||
+ | iptables -F | ||
+ | |||
+ | iptables -X | ||
+ | |||
+ | Et par défaut nous allons bloquer (drop) tout trafic entrant : | ||
iptables -P INPUT DROP | iptables -P INPUT DROP | ||
- | 2 – Allow local connections (to localhost): | + | **2 – Allow local connections (to localhost): |
+ | |||
+ | 2 – Nous allons autoriser les connexions locales (à localhost) : | ||
iptables -A INPUT -i lo -p all -j ACCEPT | iptables -A INPUT -i lo -p all -j ACCEPT | ||
Ligne 47: | Ligne 93: | ||
iptables -A INPUT -m state --state RELATED, | iptables -A INPUT -m state --state RELATED, | ||
- | 3 – Block incoming connection if it originates from a specific country: | + | **3 – Block incoming connection if it originates from a specific country: |
There are several ways to check the country-of-origin of an incoming connection: | There are several ways to check the country-of-origin of an incoming connection: | ||
Ligne 53: | Ligne 99: | ||
• loading country blocks into ipset | • loading country blocks into ipset | ||
- | iptables with geoip is based on xtables-addons, | + | iptables with geoip is based on xtables-addons, |
+ | |||
+ | 3 – Bloquer le trafic entrant s'il provient d'un pays donné. | ||
+ | |||
+ | Il y a plusieurs manières de vérifier le pays d' | ||
+ | |||
+ | • iptables geoip, | ||
+ | • charger les blocs d' | ||
+ | |||
+ | iptables avec geoip est basé sur xtables-addons qui est une extension de iptables. Cela fonctionne assez bien. Toutefois ce n'est pas vraiment « standard », | ||
+ | |||
+ | **ipset is a companion application to iptables – it can load in-memory ranges of IP addresses, and iptables can leverage ipset to test if an IP is within this range. | ||
+ | |||
+ | As geo-localization, | ||
- | ipset is a companion | + | ipset est une application |
- | As geo-localization, I will choose | + | Donc, pour géo-localiser, j' |
sudo apt-get install ipset | sudo apt-get install ipset | ||
- | Let's summarize what we want to achieve here: | + | **Let's summarize what we want to achieve here: |
• Get the IP range block we want to forbid (country based). | • Get the IP range block we want to forbid (country based). | ||
• Load that range into ipset. | • Load that range into ipset. | ||
Ligne 70: | Ligne 129: | ||
• • If target is SSH, we must also check country of origin is USA (same as above – with ipset). | • • If target is SSH, we must also check country of origin is USA (same as above – with ipset). | ||
- | I hope you follow me here!!! | + | I hope you follow me here!!!** |
- | IP blocks by country can be found here: http:// | + | Résumons ce que nous cherchons à faire : |
+ | |||
+ | • Obtenir les plages d' | ||
+ | • Charger ces plages dans ipset. | ||
+ | • Ajouter une règle iptable qui vérifie que le pays d' | ||
+ | • Si oui, bloquer. | ||
+ | • Sinon : | ||
+ | • • Permettre si la cible est HTTP (une page Internet). | ||
+ | • • Si la cible est SSH, on doit alors aussi vérifier que le pays d' | ||
+ | |||
+ | J' | ||
+ | |||
+ | **IP blocks by country can be found here: http:// | ||
We'll get the blocks of US and Canada – either download the file or use wget: | We'll get the blocks of US and Canada – either download the file or use wget: | ||
Ligne 82: | Ligne 153: | ||
Now load the blocks into ipset' | Now load the blocks into ipset' | ||
Create an ipset bucket called myset_CANADA: | Create an ipset bucket called myset_CANADA: | ||
+ | ipset create myset_CANADA hash:net** | ||
+ | |||
+ | Les blocs d' | ||
+ | |||
+ | http:// | ||
+ | |||
+ | On obtiendra les blocs des USA et du Canada soit en téléchargeant le fichier, soit en utilisant wget : | ||
+ | |||
+ | wget http:// | ||
+ | |||
+ | wget http:// | ||
+ | |||
+ | Maintenant, chargeons ces blocs dans la mémoire d' | ||
+ | |||
+ | Créons une variable ipset appelée myset_CANADA : | ||
+ | |||
ipset create myset_CANADA hash:net | ipset create myset_CANADA hash:net | ||
+ | |||
- | Load the blocks corresponding to Canada into myset_CANADA: | + | **Load the blocks corresponding to Canada into myset_CANADA: |
for i in (cat ca-aggregated.zone); | for i in (cat ca-aggregated.zone); | ||
Same for US block range: | Same for US block range: | ||
+ | |||
+ | ipset create myset_US hash:net | ||
+ | |||
+ | for i in (cat us-aggregated.zone); | ||
+ | |||
+ | Chargeons les blocs correspondant au Canada dans myset_CANADA : | ||
+ | |||
+ | for i in (cat ca-aggregated.zone); | ||
+ | |||
+ | idem pour les USA : | ||
ipset create myset_US hash:net | ipset create myset_US hash:net | ||
Ligne 94: | Ligne 192: | ||
for i in (cat us-aggregated.zone); | for i in (cat us-aggregated.zone); | ||
- | Now we'll block anything coming from Canada (conjunction of iptables & ipset): | + | **Now we'll block anything coming from Canada (conjunction of iptables & ipset): |
iptables -A INPUT -m set --match-set myset_CANADA src -j DROP | iptables -A INPUT -m set --match-set myset_CANADA src -j DROP | ||
- | If the rule above is hit, the connection is dropped (-j DROP does that) and we exit the firewall. | + | If the rule above is hit, the connection is dropped (-j DROP does that) and we exit the firewall.** |
- | 4 – If we get up to here in the firewall chain | + | Maintenant nous allons bloquer tout ce qui vient du Canada (croisement de iptables et ipset) : |
+ | |||
+ | iptables -A INPUT -m set --match-set myset_CANADA src -j DROP | ||
+ | |||
+ | Si la règle ci-dessus est satisfaite, nous bloquons le trafic entrant (c'est le rôle de -j DROP) et nous sortons du pare-feu. | ||
+ | |||
+ | **4 – If we get up to here in the firewall chain | ||
We can accept any HTTP incoming connections: | We can accept any HTTP incoming connections: | ||
Ligne 106: | Ligne 210: | ||
iptables -A INPUT -p tcp --dport 80 -j ACCEPT | iptables -A INPUT -p tcp --dport 80 -j ACCEPT | ||
- | If rule above is hit (meaning “true”), | + | If rule above is hit (meaning “true”), |
- | 5 – If we get to here | + | 4 – Si nous arrivons jusque-là dans l' |
+ | |||
+ | Nous pouvons accepter toute requête entrante HTTP : | ||
+ | |||
+ | iptables -A INPUT -p tcp --dport 80 -j ACCEPT | ||
+ | |||
+ | Si la règle ci-dessus est satisfaite, la requête est acceptée (-j ACCEPT) et nous sortons du pare-feu. | ||
+ | |||
+ | **5 – If we get to here | ||
The source is not coming from Canada and it’s not an HTTP request. If the request in not SSH, drop the request and exit the firewall: | The source is not coming from Canada and it’s not an HTTP request. If the request in not SSH, drop the request and exit the firewall: | ||
+ | |||
+ | iptables -A INPUT -p tcp ! --dport 22 -j DROP** | ||
+ | |||
+ | 5 – Si nous arrivons jusqu' | ||
+ | |||
+ | La source ne vient pas du Canada et ce n'est pas une requête de type HTTP. Si la requête n'est pas du type SSH, il faut la bloquer et sortir du pare-feu : | ||
iptables -A INPUT -p tcp ! --dport 22 -j DROP | iptables -A INPUT -p tcp ! --dport 22 -j DROP | ||
- | 6 – If we've got this far | + | **6 – If we've got this far |
It is a SSH request (and not from Canada). Let's check if the source country is allowed (USA in our example). | It is a SSH request (and not from Canada). Let's check if the source country is allowed (USA in our example). | ||
Ligne 121: | Ligne 240: | ||
+ | |||
+ | iptables -A INPUT -j LOG --log-prefix " | ||
+ | |||
+ | |||
+ | iptables -A INPUT -m set --match-set myset_USA src -j ACCEPT** | ||
+ | |||
+ | 6 – Si nous sommes arrivés jusque-là | ||
+ | |||
+ | C'est une requête de type SSH (qui ne vient pas du Canada). Vérifions que le pays d' | ||
+ | |||
+ | Avant de l' | ||
iptables -A INPUT -j LOG --log-prefix " | iptables -A INPUT -j LOG --log-prefix " | ||
Ligne 126: | Ligne 256: | ||
iptables -A INPUT -m set --match-set myset_USA src -j ACCEPT | iptables -A INPUT -m set --match-set myset_USA src -j ACCEPT | ||
- | Just in case we missed anything, any connection arriving to the command above will be dropped (remember – we drop everything by default unless specified otherwise): | + | |
+ | **Just in case we missed anything, any connection arriving to the command above will be dropped (remember – we drop everything by default unless specified otherwise): | ||
+ | |||
+ | iptables -A INPUT -j DROP** | ||
+ | |||
+ | Au cas où nous aurions raté quelque chose, chaque connexion arrivant sur la commande ci-dessus sera bloquée (rappelez-vous : | ||
iptables -A INPUT -j DROP | iptables -A INPUT -j DROP | ||
- | It’s not mandatory – but we can add some additional security to the above rules. | + | **It’s not mandatory – but we can add some additional security to the above rules. |
Let's imagine that somebody really wants to hack your system by trying every combination of RSA key possible – that is called a brute-force-attack. No worries – with a 10K RSA key, it is probably not possible (note the word probably – when talking security, you cannot ever be sure!). | Let's imagine that somebody really wants to hack your system by trying every combination of RSA key possible – that is called a brute-force-attack. No worries – with a 10K RSA key, it is probably not possible (note the word probably – when talking security, you cannot ever be sure!). | ||
- | There is something we can do about that – if a specific IP tries to connect more than x times (let's make it 5) to our server on port 22, we can temporarily ban that IP address for a few minutes – let's make it 5 (300 seconds). So this means that an attacker can potentially try 5 combinations every 5 minutes. As you probably understand, brute force will not work at this pace!!! | + | There is something we can do about that – if a specific IP tries to connect more than x times (let's make it 5) to our server on port 22, we can temporarily ban that IP address for a few minutes – let's make it 5 (300 seconds). So this means that an attacker can potentially try 5 combinations every 5 minutes. As you probably understand, brute force will not work at this pace!!!** |
- | Below, we're telling iptables to keep track of connections to port 22 for 300 seconds. If a (failed) hit count gets to 5, the connection is denied for the next 5 minutes: | + | Ce n'est pas obligatoire, |
+ | |||
+ | Imaginons que quelqu' | ||
+ | |||
+ | On peut faire quelque chose contre cela : si une adresse IP spécifique essaie de se connecter plus de x fois (disons 5) à notre serveur sur le port 22, nous pouvons temporairement interdire cette adresse IP pendant quelques minutes, disons 5 (300 secondes). Ça veut donc dire pratiquement qu'un attaquant peut essayer 5 combinaisons toutes les 5 minutes. Comme vous le comprendrez certainement, | ||
+ | |||
+ | **Below, we're telling iptables to keep track of connections to port 22 for 300 seconds. If a (failed) hit count gets to 5, the connection is denied for the next 5 minutes: | ||
+ | |||
+ | iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --rsource | ||
+ | |||
+ | iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 5 --name DEFAULT --rsource -j DROP** | ||
+ | |||
+ | Ci-dessous, nous disons à iptables de conserver une trace des connexions sur le port 22 pendant 300 secondes. Si le nombre de requêtes (qui n'ont pas abouti) arrive à 5, alors le trafic [Ndt : pour cette IP] est rejeté pendant 5 minutes : | ||
iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --rsource | iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --set --name DEFAULT --rsource | ||
Ligne 142: | Ligne 289: | ||
iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 5 --name DEFAULT --rsource -j DROP | iptables -A INPUT -p tcp -m tcp --dport 22 -m state --state NEW -m recent --update --seconds 300 --hitcount 5 --name DEFAULT --rsource -j DROP | ||
- | Then, follow these with the same block-rules as before: | + | **Then, follow these with the same block-rules as before: |
+ | |||
+ | iptables -A INPUT -j LOG --log-prefix " | ||
+ | |||
+ | iptables -A INPUT -m set --match-set myset_USA src -j ACCEPT | ||
+ | |||
+ | iptables -A INPUT -j DROP | ||
+ | |||
+ | Careful – this rule also applies to yourself!** | ||
+ | |||
+ | On fait suivre cela du même ensemble de règles que précédemment : | ||
iptables -A INPUT -j LOG --log-prefix " | iptables -A INPUT -j LOG --log-prefix " | ||
Ligne 150: | Ligne 307: | ||
iptables -A INPUT -j DROP | iptables -A INPUT -j DROP | ||
- | Careful – this rule also applies to yourself! | + | Attention : cette règle s' |
- | More about logging and checking who tried to access the system... | + | **More about logging and checking who tried to access the system... |
This command will display any SSH connection attempt to your system: | This command will display any SSH connection attempt to your system: | ||
Ligne 158: | Ligne 315: | ||
cat / | cat / | ||
- | You will quickly get a hefty output (“quickly” means minutes of server up-time), which will not be easy to read. | + | You will quickly get a hefty output (“quickly” means minutes of server up-time), which will not be easy to read.** |
- | This revised version is probably more useful and will give the list of unique IP attempts – sorted by number of connection attempts: | + | Allons plus loin dans la liste et la vérification de ceux qui ont cherché à se connecter au système… |
+ | |||
+ | Cette commande va afficher toutes les tentatives de connexion à votre système : | ||
+ | |||
+ | cat / | ||
+ | |||
+ | Cela vous donnera très rapidement (« rapidement » voulant dire après quelques minutes d' | ||
+ | |||
+ | **This revised version is probably more useful and will give the list of unique IP attempts – sorted by number of connection attempts: | ||
cat / | cat / | ||
Ligne 170: | Ligne 335: | ||
• It sorts the list. | • It sorts the list. | ||
• It gets only the unique IPs, but counts the number of occurrences of each unique IP. | • It gets only the unique IPs, but counts the number of occurrences of each unique IP. | ||
- | • It sorts descending as numbers (sort -n). | + | • It sorts descending as numbers (sort -n).** |
- | The goal of this article is firewall and security. However, I strongly believe that security and scripting go hand-in-hand. Logging intrusion attempts is great but not using the data is useless. As you can see, a quick shell command was able to provide very useful information – extremely quickly. I can now, for example, ban the topmost 10 IPs who tried to log in to my system. | + | Cette version modifiée est certainement plus utile et vous donnera la liste des adresses IP qui ont tenté de se connecter, classée par nombre de tentatives de connexion : |
- | The following command will ban the IP 10.10.10.10 by inserting the rule on top of all rules (-I INPUT 1): | + | cat / |
+ | |||
+ | Une rapide explication de cette commande : | ||
+ | • Elle affiche le contenu du fichier / | ||
+ | • Elle ne conserve que les lignes où les mots clés « Accepted SSH » existent. | ||
+ | • Elle récupère le texte qui suit le mot clé « SRC= » (adresse IP de la connexion entrante). | ||
+ | • Elle ordonne la liste. | ||
+ | • Elle ne conserve que les adresses IP uniques, mais compte le nombre d’occurrences de chaque IP. | ||
+ | • Elle classe les nombres par ordre décroissant (sort -n). | ||
+ | |||
+ | **The goal of this article is firewall and security. However, I strongly believe that security and scripting go hand-in-hand. Logging intrusion attempts is great but not using the data is useless. As you can see, a quick shell command was able to provide very useful information – extremely quickly. I can now, for example, ban the topmost 10 IPs who tried to log in to my system.** | ||
+ | |||
+ | Le sujet de cet article est le pare-feu et la sécurité. Toutefois, je crois fermement que la sécurité et l' | ||
+ | |||
+ | **The following command will ban the IP 10.10.10.10 by inserting the rule on top of all rules (-I INPUT 1): | ||
iptables -I INPUT 1 -s 10.10.10.10 -j DROP | iptables -I INPUT 1 -s 10.10.10.10 -j DROP | ||
- | Have fun and please make sure not to ban… yourself! | + | Have fun and please make sure not to ban… yourself!** |
- | 7 – Output rules: | + | La commande suivante va interdire l' |
+ | |||
+ | iptables -I INPUT 1 -s 10.10.10.10 -j DROP | ||
+ | |||
+ | Amusez-vous et surtout faites attention de ne pas interdire… votre propre adresse ! | ||
+ | |||
+ | **7 – Output rules: | ||
Many times, firewalls will enforce rules only for incoming connections – meaning they’ll allow wide-open output traffic. This is not a good practice – imagine that a hacker gets to your computer and is able to install server software which could then create a tunnel via a random port to the attacker' | Many times, firewalls will enforce rules only for incoming connections – meaning they’ll allow wide-open output traffic. This is not a good practice – imagine that a hacker gets to your computer and is able to install server software which could then create a tunnel via a random port to the attacker' | ||
Ligne 187: | Ligne 372: | ||
• SSH (for our remote access), this is TCP port 22. | • SSH (for our remote access), this is TCP port 22. | ||
• HTTP and HTTPS (for web pages), these are ports 80 and 443. | • HTTP and HTTPS (for web pages), these are ports 80 and 443. | ||
- | • DNS (so our requests can be resolved!), this is port 53. | + | • DNS (so our requests can be resolved!), this is port 53.** |
+ | |||
+ | 7 – Règles concernant le trafic sortant | ||
+ | |||
+ | Très souvent, les pare-feu ne mettent en place des règles que pour le trafic entrant – ce qui signifie qu'ils ouvrent grandes les portes du trafic sortant. Ce n'est pas une bonne façon de faire ; imaginez qu'un pirate s' | ||
+ | |||
+ | Nous allons donc combler cette lacune aussi. Nous allons principalement donner accès au trafic sortant à : | ||
+ | • SSH (pour notre accès à distance), c'est le port TCP 22. | ||
+ | • HTTP et HTTPS (pour les pages Internet), ce sont les ports 80 et 443. | ||
+ | • DNS (pour que nos requêtes puissent aboutir !), c'est le port 53. | ||
- | You probably got the point: | + | **You probably got the point: |
• By default, DROP any output connections, | • By default, DROP any output connections, | ||
• Allow connection to localhost (the server itself). | • Allow connection to localhost (the server itself). | ||
- | • Allow SSH, DNS, HTTP & HTTPS. | + | • Allow SSH, DNS, HTTP & HTTPS.** |
+ | |||
+ | Vous avez probablement déjà compris : | ||
+ | • Par défaut, bloquer tout trafic sortant, à moins que nous ne l' | ||
+ | • Permettre des connexions à l' | ||
+ | • Permettre SSH, DNS, HTTP et HTTPS. | ||
iptables -P OUTPUT DROP | iptables -P OUTPUT DROP | ||
Ligne 210: | Ligne 409: | ||
iptables -A OUTPUT -j DROP | iptables -A OUTPUT -j DROP | ||
- | Let's put all this together... | + | **Let's put all this together... |
+ | |||
+ | First build the block of IP addresses. Run all below as root (or sudo):** | ||
+ | |||
+ | Passons à la pratique... | ||
- | First build the block of IP addresses. Run all below as root (or sudo): | + | D' |
apt-get install ipset | apt-get install ipset | ||
Ligne 220: | Ligne 423: | ||
wget http:// | wget http:// | ||
- | Now let's clean all firewall rules: | + | **Now let's clean all firewall rules:** |
+ | |||
+ | Maintenant il faut nettoyer toutes les règles existantes du pare-feu : | ||
iptables -X | iptables -X | ||
- | And make sure all rules were really deleted – you should see this: | + | **And make sure all rules were really deleted – you should see this:** |
- | Then add the firewall rules in a text file (see box on next page). | + | Et s' |
+ | |||
+ | |||
+ | **Then add the firewall rules in a text file (see box on next page). | ||
In order to test this out, I would recommend the following: | In order to test this out, I would recommend the following: | ||
• Use wget to get the blocks of IPs, and keep the files. | • Use wget to get the blocks of IPs, and keep the files. | ||
• Copy / paste the code above to a shell file (text file with extension .sh and make it executable with chmod +x [filename]). | • Copy / paste the code above to a shell file (text file with extension .sh and make it executable with chmod +x [filename]). | ||
- | • Run the file. For my example, I'll call this file / | + | • Run the file. For my example, I'll call this file / |
- | You should now have the firewall fully loaded and operational. | + | Vous devez alors écrire toutes les règles du pare-feu dans un fichier texte (voir l' |
+ | |||
+ | De façon à tester tout ceci, je recommanderais les choses suivantes : | ||
+ | • Utilisez wget pour obtenir les blocs d'IP et conservez les fichiers. | ||
+ | • Copiez/ | ||
+ | • Exécutez le fichier. Dans mon exemple, je l'ai appelé / | ||
+ | |||
+ | **You should now have the firewall fully loaded and operational. | ||
IMPORTANT – iptables -F resets the firewall and locks your ssh session out! | IMPORTANT – iptables -F resets the firewall and locks your ssh session out! | ||
- | When you run the file, your terminal will be “locked”. This is because we reset the firewall by blocking all rules by default. Just try connecting again to iceberg from another terminal. If it works – you should be all set, but, if you cannot, stop and restart the VM from the Digital Ocean panel. After the restart, the rules are not loaded, so you can fix that problem: For example, I allowed the US IP blocks because I live in the US, did you load the right blocks of IPs from where you live? | + | When you run the file, your terminal will be “locked”. This is because we reset the firewall by blocking all rules by default. Just try connecting again to iceberg from another terminal. If it works – you should be all set, but, if you cannot, stop and restart the VM from the Digital Ocean panel. After the restart, the rules are not loaded, so you can fix that problem: For example, I allowed the US IP blocks because I live in the US, did you load the right blocks of IPs from where you live?** |
- | I will now suppose everything worked well – we will then set both scripts to run at startup. | + | Maintenant le pare-feu doit être entièrement chargé et opérationnel. |
- | In ubuntu 14.04, edit and add both files to / | + | IMPORTANT – iptables -F remet le pare-feu à zéro et ferme votre session SSH ! |
- | Note the sleep 10 – we're telling iceberg to wait 10 seconds before running our scripts – this is to ensure that the network is up & running before we set up the firewall. | + | Quand vous lancez le fichier, votre terminal sera « verrouillé ». Cela est dû à la ré-initialisation du pare-feu en bloquant toutes les règles par défaut. Essayez juste de vous reconnecter à Iceberg depuis un autre terminal. Si cela fonctionne, vous devriez être opérationnel, |
- | I know a few of you may find the sleep 10 not optimal and would rather use upstart' | + | **I will now suppose everything worked well – we will then set both scripts |
- | Anyway, during your next reboot, you should be automatically all set, with a system pretty well protected against intrusions. | + | In ubuntu 14.04, edit and add both files to / |
+ | |||
+ | Je vais maintenant supposer que tout s'est bien passé. Nous allons ensuite mettre en place les deux scripts qui doivent s' | ||
+ | |||
+ | Dans Ubuntu 14.04, éditez et ajoutez les deux fichiers à / | ||
+ | |||
+ | **Note the sleep 10 – we're telling iceberg to wait 10 seconds before running our scripts – this is to ensure that the network is up & running before we set up the firewall. | ||
+ | |||
+ | I know a few of you may find the sleep 10 not optimal and would rather use upstart' | ||
+ | |||
+ | Notez l' | ||
+ | |||
+ | Je sais qu'un certain nombre d' | ||
+ | |||
+ | **Anyway, during your next reboot, you should be automatically all set, with a system pretty well protected against intrusions. | ||
If you'd like to confirm the scripts have been properly executed at startup, as root run this: | If you'd like to confirm the scripts have been properly executed at startup, as root run this: | ||
Ligne 256: | Ligne 485: | ||
- | Next month, we will install Apache (Web server) and secure Apache. | + | Next month, we will install Apache (Web server) and secure Apache.** |
+ | |||
+ | De toute façon, lors de votre prochain démarrage, vous devriez être automatiquement bien réglé avec un système plutôt bien protégé contre les intrusions. | ||
+ | |||
+ | Si vous voulez vous assurer que les scripts on été correctement exécutés, lancez cette instruction comme administrateur (root) : | ||
+ | |||
+ | iptables -L | ||
+ | |||
+ | Et vous devriez voir les règles du pare-feu apparaître à l' | ||
+ | Le mois prochain, nous installerons Apache (le serveur Internet) et nous le sécuriserons. |
issue101/site_web_avec_infrastructure.1443477571.txt.gz · Dernière modification : 2015/09/28 23:59 de d52fr