Archive

Archives pour la catégorie ‘Réseau’

Outil keychain

14/02/2024 Comments off

I. Introduction

Ce guide ou « cookbook » est orienté pour des distributions de type Debian (dont Ubuntu fait partie), sachant que le principe reste identique sur d’autres distributions Linux. La connexion SSH de chacune des deux machines doit être préalablement configurée et fonctionnelle.

La connexion d’un client SSH vers un serveur SSH est fonction (d’au moins) trois paramètres principaux :

  • l’utilisateur distant ;
  • l’adresse de la machine distante ;
  • le port utilisé pour la connexion.

On appellera « machine A » ou « client » la machine cliente depuis laquelle on cherchera à se connecter sur le serveur SSH de la « machine B ». Les utilisateurs de chaque machine seront nommés respectivement user_a et user_b.

Un tutoriel spécifique à la mise en place d’une connexion SSH se trouve ici.

L’installation du chainage de clés par keychain permettra à l’utilisateur user_a de la machine cliente « machine A » de se connecter sur la « machine B » en tant que user_b sans entrer de mot de passe ou de passphrase.

L’intérêt principal est d’éviter d’entrer un mot de passe ou une passphrase à chaque connexion SSH mais seulement une fois, lors du lancement de votre « machine A », et pas du tout pour vos shells en tâches de fond.

Une application possible est de pouvoir utiliser les ressources du serveur SSH au travers de scripts shell. Par exemple, les scripts de sauvegarde (avec les commandes scp ou rsync utilisant elles-mêmes le protocole SSH) d’une « machine A » vers une « machine B » pourront alors être lancés en tâches de fond (cronjob) sans avoir à se soucier de quoi que ce soit. Presque le bonheur ! On verra comment réaliser cela dans un exemple en fin de ce tutoriel.

Attention cependant à conserver une configuration sécurisée, notamment si vous êtes plusieurs utilisateurs sur la même machine cliente. En particulier, l’utilisateur root ne doit jamais disposer de ce mode de connexion « automatisée ».

Attention cependant à conserver une configuration sécurisée, notamment si vous êtes plusieurs utilisateurs sur la même machine cliente. En particulier, l’utilisateur root ne doit jamais disposer de ce mode de connexion « automatisée ».

Tout le tutoriel est réalisé en ligne de commande mais ces manipulations sont également possibles en mode graphique.

II. Prérequis

L’utilisateur root est requis pour la plupart des installations ci-dessous, même si je n’évoque ou n’explicite pas l’utilisation de « sudo », à envisager dans le cas des distributions Ubuntu. Les utilisateurs user_a et user_b devront exister sur chacune des deux machines, disposer de leurs répertoires HOME (man adduser) respectifs, et idéalement être autorisés à exécuter du script bash (vous pouvez vérifier que c’est le cas dans /etc/passwd).

Attention cependant à conserver une configuration sécurisée, notamment si vous êtes plusieurs utilisateurs sur la même machine cliente. En particulier, l’utilisateur root ne doit jamais disposer de ce mode de connexion « automatisée ».

Exemple sur la machine A

sudo adduser user_a cat /etc/passwd #... d'autres utilisateurs listés user_a:x:1003:1003:,,,:/home/user_a:/bin/bash

II-A. Installer les paquets nécessaires

Machine A : ligne de commande en tant que root

aptitude install ssh openssh-client keychain

Machine B : ligne de commande en tant que root

aptitude install ssh openssh-client keychain
  1. S’il s’agit d’une réinstallation, pensez bien à stopper tous les processus SSH et « purger » l’installation existante avant de procéder à la réinstallation (man aptitude),
  2. aptitude a disparu des installations standards depuis la version ubuntu 10.10. Il faut donc l’installer si vous êtes dans ce cas (avec sudo apt-get pour les « ubuntistes« ).

Lire la suite…

Categories: Réseau, Système Tags: ,

How to Use RSA Key for SSH Authentication

12/02/2024 Comments off

If your daily activity requires loging in a lot of Linux systems through SSH, you will be happy to know (if you don’t already) that there’s a way to allow secure, authenticated remote access, file transfer, and command execution without having to remember passwords for each individual host you connect.

The $HOME/.ssh/authorized_keys file contains the RSA keys allowed for RSA authentication. Each line contains one key, which consists of the following fields: options, bits, exponent, modulus and comment. The first field is optional, bits, exponent and modulus fields give the RSA key and the last field isn’t used at all in the authentication process, but it will be somewhat convenient to the user, for instance to know which key is for which machine.

Before we start, make sure your computer has a ssh client installed and the remote Linux system has ssh installed and sshd running, with RSA authentication enabled (RSAAuthentication yes in /etc/ssh/sshd_config).

Lire la suite…

Categories: Réseau, Système Tags: , ,

IPtables dans Webmin

10/02/2024 Comments off

Lorsque vous utilisez Webmin pour administrer votre serveur, les paramètres de votre firewall iptables sont visibles et manageables depuis la console Webmin.

Toutefois, les règles iptables présentées par Webmin sont celles qui ont été préalablement sauvées par /sbin/iptables-save dans le fichier que vous avez choisi.

Donc si vous utilisez un script depuis le shell pour changer les règles de iptables, ce ne seront pas ces règles que Webmin vous présentera mais celles que vous avez sauvées préalablement avec Webmin.When using Webmin as an administration tool, iptables rules visible for Webmin are those previously saved through Webmin.

So when you use a shell script to change iptables rules on the fly, these rules won’t be the ones Webmin present to you.

The solution is to use:

iptables-save > the_file_used_by_webmin_last_time_you_backed_up_rules

to retrieve the exact actual state of iptables rules.

Monitoring Ubuntu Desktops and Servers Using Monit

08/02/2024 Comments off

monit is a utility for managing and monitoring, processes, files, directories and devices on a UNIX system. Monit conducts automatic maintenance and repair and can execute meaningful causal actions in error situations.

Monit Features

  • Daemon mode – poll programs at a specified interval
  • Monitoring modes – active, passive or manual
  • Start, stop and restart of programs
  • Group and manage groups of programs
  • Process dependency definition
  • Logging to syslog or own logfile
  • Configuration – comprehensive controlfile
  • Runtime and TCP/IP port checking (tcp and udp)
  • SSL support for port checking
  • Unix domain socket checking
  • Process status and process timeout
  • Process cpu usage
  • Process memory usage
  • Process zombie check
  • Check the systems load average
  • Check a file or directory timestamp
  • Alert, stop or restart a process based on its characteristics
  • MD5 checksum for programs started and stopped by monit
  • Alert notification for program timeout, restart, checksum, stop resource and timestamp error
  • Flexible and customizable email alert messages
  • Protocol verification. HTTP, FTP, SMTP, POP, IMAP, NNTP, SSH, DWP,LDAPv2 and LDAPv3
  • An http interface with optional SSL support to make monit accessible from a webbrowser

Lire la suite…

Punching holes into firewalls

07/02/2024 Comments off

5b3f38bb3b78c6acd6bbfe3dfb33a470-pearlsquareFirewalls are heavily used to secure private networks (home or corporate). Usually, they are used to protect the network from:

  • intrusions from outsiders
  • misuse from insiders

In a TCP/IP environment, the typical corporate firewall configuration is to block everything (both incoming and outgoing), and give access to the internet only through a HTTP proxy. The proxy usually has filtering capabilities (censors URLs and file types), and access to the proxy often requires credentials (login/password). This gives greater contol to the network administrator over what and who is going in and out of the network.

Still, this should not considered a ultimate weapon, and network administrators should not rely on the firewalls only.

Encapsulation is the basis of networking. For example, HTTP is encapsulated by TCP, TCP is encapsulated by IP, and IP is often encapsulated in PPP or Ethernet.
Encapsulating protocols in an unsual way is often reffered as tunnelling.

As soon as you let a single protocol out, tunelling allows to let anything go through this protocol, and thus through the firewall.

This paper demonstrates how to encapsulate any TCP-based protocol (SMTP, POP3, NNTP, telnet…) into HTTP, thus bypassing the firewall protection/censorship (depending on your point of view)

A word of warning:

In many countries and corporate environments, bypassing a firewall is forbidden and exposes you to sanctions, redundancy, legal proceedings and – in some countries – death penalty.
You are warned.

Nevertheless, in some countries this kind of firewall/proxy bypassing is the only way to ensure free speech (such as China or United Arab Emirates where the government severly censors the internet and where firewall bypassing is a national sport.)

Now you known what you’re doing, let’s move on.


The problem

Say you want to fetch your mail from your ISP mail server. You usually simply connect to port 110 on the POP server of your ISP.

punch1

 

Trouble: there is a Big Bad firewall which blocks everything.

punch2

Well… it does not exactly block everything: it lets HTTP out through a proxy.
Let’s encapsulate our POP3 connection into HTTP.


The tools

We need:

  • A computer on the internet which has unrestricted access to the internet, such as a home ADSL computer.
  • GNU HTTP Tunnel (http://www.nocrew.org/software/httptunnel.html). It encapsulates TCP into HTTP requests.
  • SSH is a secure shell (http://www.openssh.com). It provides secure (and compressed) channels between two hosts using SSL. Besides providing a shell (like telnet), it also provides file copy (scp) and TCP port forwarding (tunnelling). We will use the port forwarding feature.

 

Why not use GNU HTTP Tunnel alone ?

In principle, only HTTP Tunnel is necessary. But this is not desirable:

  • the tunnel is public: anyone can use your tunnel. Your could be held liable for what anybody has done with your tunnel.
  • the tunnel is cleartext: anyone can spy on your connection. Your passwords (SMTP, POP3, telnet…) are transmitted in clear text.
  • the tunnel is not protected: anyone can alter the datastream.
  • you have to run a new instance of the HTTP Tunnel client and the server for each new tunnel you want to set up.

This is where ssh come in. ssh provides:

  • authentication (only authorised users can use the tunnel)
  • privacy (no one can spy on what’s going through the tunnel)
  • integrity (no one can tamper data going through the tunnel)
  • easy tunnel set-up (you can create a new tunnel with a single ssh command on the client side).

These tools are available on Unix/Linux and Windows environments.

 

The whole chain

Let’s see how this works. Here is the full chain:

punch3

Technically speaking, once this chain is established, connecting to OfficeComputer:800 is identical to connecting to pop3server:110.
The mail client will not see the difference.

  • On the office computer:
    • TCP data sent to port 800 is encrypted by ssh, which forwards data to port 900.
    • ssh stream sent to port 900 is chunked in individual HTTP requests by the HTTP Tunnel client and sent to the home computer through the proxy.
  • On the home computer:
    • the HTTP Tunnel server receives HTTP requests, decapsulates and re-assembles the ssh stream and forwards it to port 22 (to the ssh server).
    • the ssh server decrypts the datastream and forwards it to the pop3server on port 110.

As TCP is a bi-directionnaly datastream, once established, the TCP connection can pass data back and forth through the HTTP proxy.

Lire la suite…

Categories: Réseau, Sécurité Tags: ,