Autres
AideEnLigne
CahierDeBrouillon
Présentation
Administration

MesLectures
[Articles publiés]
[Blog Affordance]
[LibreOffice en ligne]
[Journal d'Ophelia]
[Kim Khal]

Informations
[Rue 89]

DNS etc
[Robtex]
Logins
Votre ID: 111
Nom:
Login utilisateur
Mot de passe éditeur

NotesSSH

Différence (depuis la version majeure précédente) (modification mineure)

Ajouté: 0a1,5
+SSH-audit to configure sshd-config


:a python script to verify all algos https://github.com/arthepsy/ssh-audit
:autre doc sur les algo à utiliser/éviter https://www.guillaume-leduc.fr/securiser-secure-shell-ssh.html


Modifié: 42c47
What I found on a stackexchange forum (a sketch is worth a thousand words). Here is a link to the forum topic: http://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot. There was two superb sketches:
What I found on a stackexchange forum (a sketch is worth a thousand words). Here is a link to the forum topic: http://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot. There were two superb sketches:

Modifié: 50c55,71
2016-11-21 09:21:33 -- Cmic



Explanations:

local: -L Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.

ssh -L sourcePort:forwardToHost?:onPort connectToHost? means: connect with ssh to connectToHost?, and forward
all connection attempts to the local sourcePort to port onPort on the machine called forwardToHost?,
which can be reached from the connectToHost? machine.

remote: -R Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.

ssh -R sourcePort:forwardToHost?:onPort connectToHost? means: connect with ssh to connectToHost?, and forward
all connection attempts to the remote sourcePort to port onPort on the machine called forwardToHost?,
which can be reached from your local machine.

2016-11-21 09:21:33 -- Cmic

Modifié: 56c77
*Sur macinterne compiler corkscrew
*Sur macinterne compiler corkscrew : https://github.com/bryanpkc/corkscrew/

Modifié: 134,138c155,156
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent \
--set

iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent \
--update --seconds 60 --hitcount 4 -j DROP
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP

Ajouté: 142a161,172
Or use this config:

# Regle log ssh drop :
iptables -N SSH_DROP
iptables -A SSH_DROP -m limit --limit 1/s -j LOG --log-prefix '[fw drop -> Attack ssh] : '
iptables -A SSH_DROP -j DROP
# Regles anti-brute force :
iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m recent --update --seconds 60 --hitcount 4 --name SSH -j SSH_DROP
iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m recent --set --name SSH
iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m state --state NEW -j ACCEPT

FIXME: dans les 3 regles ci-dessus, -A INPUT -d ${IP_EXT} ce sera pas plutot -A INPUT -s ${IP_EXT} ??

Modifié: 146,148c176
Installer sshguard http://www.sshguard.net/‎; . Blocage de ssh si nb d'accès trop important par unité de temps. Possibilite de whiteliste.

Testé OK sur FreeBSD? 9.0.
Installer sshguard http://www.sshguard.net/ Blocage de ssh si nb d'accès trop important par unité de temps. Possibilite de whitelister. Testé OK sur FreeBSD? 9.0.

Ajouté: 163a192,199
Ou encore
ssh -NTCD 8890 cmic@nico.be
-N Do not execute a remote command
-T Disable pseudo-terminal allocation
-C Requests compression of all data
-D <port>
-D


Ajouté: 167a204,206

Voir aussi https://linuxize.com/post/how-to-setup-ssh-socks-tunnel-for-private-browsing/
et https://blog.gwlab.page/vpn-over-ssh-the-socks-proxy-8a8d7bdc7028

+SSH-audit to configure sshd-config

a python script to verify all algos https://github.com/arthepsy/ssh-audit
autre doc sur les algo à utiliser/éviter https://www.guillaume-leduc.fr/securiser-secure-shell-ssh.html
+Les clefs publique/privées

Génération d'un couple privé/public

 prompt>ssh-keygen -t rsa
 prompt> ...

Genération sur stdout de la clef publique

 prompt>ssh-keygen -y
 Enter file in which the key is (/home/cmic/.ssh/id_rsa): 
 Enter passphrase: 
 ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAIEAou8RMHFoX6J0wH9N33rGmS?
 AiyBiCEs0rAy9znwOIBxdtcTsWvVSXyF0ZW2IGzUrVZLdfAcs3BKXrn9CM?
 d2Iqarl7tpc+B1Z+LdGId1WpTRNh1I1bL5Bo29OKDZr?+vknTDM7xELQbRm?
 7qtAkwMRRCxty7JEaM3ostEBgLGgN9Fek?=

Genération sur stdout de la clef publique SECSH Public Key File Format

 prompt>ssh-keygen -e
 Enter file in which the key is (/home/cmic/.ssh/id_rsa): 
 - BEGIN SSH2 PUBLIC KEY -
 Comment: "1024-bit RSA, converted from OpenSSH? by cmic@zombie"
 AAAAB3NzaC1yc2EAAAABIwAAAIEAou8RMHFoX6J0wH9N33rGmSAiyBiCEs0rAy9znwOIBx?
 dtcTsWvVSXyF0ZW2IGzUrVZLdfAcs3BKXrn9CMd2Iqarl7tpc?+B1Z+LdGId1WpTRNh1I1b?
 L5Bo29OKDZr+vknTDM7xELQbRm7qtAkwMRRCxty7JEaM3ostEBgLGgN9Fek?=
 - END SSH2 PUBLIC KEY -

Génération de l'empreinte (fingerprint)

 prompt>ssh-keygen -l
 Enter file in which the key is (/home/cmic/.ssh/id_rsa): 
 1024 e5:91:e7:8b:08:d1:ea:de:00:fc:31:26:d0:a0:f9:31 /home/cmic/.ssh/id_rsa.pub

Génération de bubble table digest

 prompt>ssh-keygen -B
 Enter file in which the key is (/home/cmic/.ssh/id_rsa): 
 1024 xehil-refyr-zoreg-zakoh-hepyh-pipeb-netyn-bahur-dogid-loloc-laxix    /home/cmic/.ssh/id_rsa.pub

Configuration des algo et test de OpenSSH?

https://linuxfr.org/news/openssh-configuration-des-algorithmes-de-cryptographie
+Port forwarding
What I found on a stackexchange forum (a sketch is worth a thousand words). Here is a link to the forum topic: http://unix.stackexchange.com/questions/115897/whats-ssh-port-forwarding-and-whats-the-difference-between-ssh-local-and-remot. There were two superb sketches:


Explanations:

local: -L Specifies that the given port on the local (client) host is to be forwarded to the given host and port on the remote side.

 ssh -L sourcePort:forwardToHost?:onPort connectToHost? means: connect with ssh to connectToHost?, and forward 
 all connection  attempts to the local sourcePort to port onPort on the machine called forwardToHost?, 
 which can be reached from the connectToHost? machine.

remote: -R Specifies that the given port on the remote (server) host is to be forwarded to the given host and port on the local side.

 ssh -R sourcePort:forwardToHost?:onPort connectToHost? means: connect with ssh to connectToHost?, and forward 
 all connection attempts to the remote sourcePort to port onPort on the machine called forwardToHost?, 
 which can be reached from your local machine.

2016-11-21 09:21:33 -- Cmic


+SSH tunneling thru http proxy

  • Sur macinterne compiler corkscrew : https://github.com/bryanpkc/corkscrew/
  • Sur macexterne (tcp/ip # 123.123.123.123), lancer un sshd sur le port 443.
  • Sur mactexterne, prévoir de maintenir la connexion ouverte (Parametres ClientAliveInterval? et ClientAliveMax? dans /etc/sshd_config)

  • Sur macinterne, dans ~/.ssh/config. Adresse proxy http interne: 172.21.16.1

 host macexterne
        ProxyCommand? /home/cmic/bin/corkscrew 172.21.16.1 8080 123.123.123.123 443

  • puis lancer la connexion :

 cmic@macinterne>ssh -R 2222:localhost:22 macexterne
 cmic@macexterne's password: ****
 ...
 cmic@macexterne>

  • utiliser le tunnel depuis macexterne :

 cmic@macexterne>ssh localhost -p 2222
 cmic@macinterne's password: ******
 cmic@macinterne>
 ....
 cmic@macinterne>exit
 cmic@macexterne>

+SSH reverse tunneling

On veut accéder en SSH a un PC connecté en Wifi. depuis une client Linux IP 138.47.99.99

Destination en WiFi? (192.168.20.55) <- Source Linux (138.47.99.99)

1. On lance une session SSH depuis la destination vers la source :

 prompt_destination> ssh -R 19999:localhost:22 sourceuser@138.47.99.99 # port 19999 ou autre port > 1024.

2. Depuis le poste source, on accède au PC destination a travers le tunnel SSH :

 prompt_source> ssh localhost -p 19999

+Utilisation de SSH agent
  1. generer un jeu de clefs avec ssh-keygen et la protéger avec un mot de passe
  2. copier la clef publique sur la machine distante
 prompt>cat ./ssh/id_rsa.pub | ssh user@machineA 'cat - >> /home/user/.ssh/authorized_keys
3.lancer l'agent (une socket va être créee a l'écoute de ssh et les variables d'environnement SSH_AUTH_SOCK et SSH_AGENT_PID vont être crées)
 prompt>eval 'ssh-agent'
4.ajouter la clef privée à ssh-agent
 prompt>ssh-add
5.se connecter a machineA sans taper le mot de passe de la clef privée... Eventuellement, arreter ssh-agent en faisant ssh-agent -k
+SSH thru port knocking
Not tested

 $IPT -N stage1
 $IPT -A stage1 -m recent --remove --name knock
 $IPT -A stage1 -p tcp --dport 3456 -m recent --set --name knock2

 $IPT -N stage2
 $IPT -A stage2 -m recent --remove --name knock2
 $IPT -A stage2 -p tcp --dport 2345 -m recent --set --name heaven

 $IPT -N door
 $IPT -A door -m recent --rcheck --seconds 5 --name knock2 -j stage2
 $IPT -A door -m recent --rcheck --seconds 5 --name knock -j stage1
 $IPT -A door -p tcp --dport 1234 -m recent --set --name knock

 $IPT -A INPUT -m --state ESTABLISHED,RELATED -j ACCEPT
 $IPT -A INPUT -p tcp --dport 22 -m recent --rcheck --seconds 5 --name heaven -j ACCEPT
 $IPT -A INPUT -p tcp --syn -j doo

+Stop SSH brute force logins w iptables

Insert these 2 rules :

 iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --set
 iptables -I INPUT -p tcp --dport 22 -i eth0 -m state --state NEW -m recent --update --seconds 60 --hitcount 4 -j DROP

  • The first rule sets a counter for NEW connections to port 22
  • the second rule updates the "circular" counter for a maximum count of 4 attempts during 60 seconds. Otherwise, the connection is dropped.

Or use this config:

 # Regle log ssh drop :
 iptables -N SSH_DROP
 iptables -A SSH_DROP -m limit --limit 1/s -j LOG --log-prefix '[fw drop -> Attack ssh] : '
 iptables -A SSH_DROP -j DROP
 # Regles anti-brute force :
 iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m recent --update --seconds 60 --hitcount 4 --name SSH -j SSH_DROP
 iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m recent --set --name SSH
 iptables -A INPUT -d ${IP_EXT} -p tcp --dport ${PORT_SSH} -m state --state NEW -j ACCEPT

FIXME: dans les 3 regles ci-dessus, -A INPUT -d ${IP_EXT} ce sera pas plutot -A INPUT -s ${IP_EXT} ??

+Stop SSH brute force logins w sshgards

Installer sshguard http://www.sshguard.net/ Blocage de ssh si nb d'accès trop important par unité de temps. Possibilite de whitelister. Testé OK sur FreeBSD? 9.0.

+Stop SSH brute force (and DNS brute force) logins w phrel
Use this C script under Linux. Requires iptables, SNMP, .. http://www.digitalgenesis.com/software/phrel/
+Utilisation de sshfs (au lieu de NFS)
  • installer ssfs
  • le serveur nacre partage /usr/public
  • sur la machine stack:
 prompt-cmic>sshfs nacre:/usr/public /mnt -o idmap=cmic

idmap mappe le user id du serveur vers le client.

+ssh proxy
 prompt-cmic>ssh -D 8890 cmic@nico.be

Ou encore

  ssh -NTCD 8890 cmic@nico.be
 -N Do not execute a remote command
 -T Disable pseudo-terminal allocation
 -C Requests compression of all data
 -D <port>
 -D 

Ensuite, utiliser le proxy SOCKS (SOCKS V5) de Firefox avec proxy:localhost, port: 8890. Toujours dans Firefox, dans about:config :

 network.proxy.socks_remote_dns user set boolean true

Voir aussi https://linuxize.com/post/how-to-setup-ssh-socks-tunnel-for-private-browsing/ et https://blog.gwlab.page/vpn-over-ssh-the-socks-proxy-8a8d7bdc7028

+Utilisation de ~/.ssh/config
Au lieu de la ligne de commande :
 prompt-cmic>ssh -p12345 cmic@nacre.net -i ~/.ssh/clef-privee

Mettre ceci dans ~/.ssh/config :

 Host nacre
     User cmic
     Port 12345
     IdentityFile? ~/.ssh/clef-privee
     HostName? nacre.net
Et ensuite, utiliser ssh :
 prompt-cmic>ssh nacre
+Partage de connexions (controlpath) not tested
A placer dans ~/.ssh/config
 Host nacre
    Controlmaster auto
    Controlpath ~/.ssh/ssh-%r@%h:%p.sock
A la premiere connexion, une socket sera cree dans ~/.ssh . Cette socket sera utilisee pour tout commande ssh (scp, sfcp, rsync, ..)
+ssh pour se connecter a travers une autre connexion ssh

  • Placer ces lignes dans .ssh/config pour acceder directement a 'host2' qui est situe sur un reseau prive uniquement disponible depuis 'host1'. NB: -T disable tty allocation). Utilisation de netcat.

  Host host2
      ProxyCommand? ssh -T host1 'nc %h %p'
  	  HostName? host2

  • Autre utilisation : J'ai acces a hostA, mais pas a hostB ; mais hostB a ma clef publique, et hostA peut acceder a hostB. On peut alors par exemple copier vers hostB a travers hostA en faisant :

 prompt-hostC> tar -c /rep/fichiers | ssh -A user@hostA "ssh -A user@hostB tar xf -"
NB: -A Enables forwarding of the authentication agent connection.
+rsync and ssh
Using rsync over ssh without giving your password. http://ramblings.narrabilis.com/using-rsync-with-ssh
+SSH on another ports