Professional Documents
Culture Documents
Lecture Notes for 91.561 UMass Lowell Computer Science David Martin
Secure Shell
Not really a shell Originally replacement for rcommands
Encryption Good authentication
Generally, interactive secure sessions
Login Remote command execution Port and X forwarding Authentication forwarding Flow control Terminal handling Signal propagation Compression
Secure Shell
Program versus protocol versus company Will concentrate on SSH-2 protocol
Mercury, Saturn ssh command is OpenSSH_3.1p1, SSH protocols 1.5/2.0 scp, sftp commands
SSH Layers
SSH application User authentication Connection management
Transport protocol
1. Introduction (from draft-ietf-secsh-transport-15.txt) The SSH transport layer is a secure low level transport protocol. It provides strong encryption, cryptographic host authentication, and integrity protection. Authentication in this protocol level is hostbased; this protocol does not perform user authentication. A higher level protocol for user authentication can be designed on top of this protocol. ... Key exchange method, public key algorithm, symmetric encryption algorithm, message authentication algorithm, and hash algorithm are all negotiated. It is expected that in most environments, only 2 round-trips will be needed for full key exchange, server authentication, service request, and acceptance notification of service request. The worst case is 3 round-trips.
Example session
% telnet mercury 22 SSH-1.5-foo vs SSH-2.0-foo % ssh v mercury (Host keys) (User authentication methods)
4.3 Encryption
An encryption algorithm and a key will be negotiated during the key exchange. When encryption is in effect, the packet length, padding length, payload and padding fields of each packet MUST be encrypted with the given algorithm. The encrypted data in all packets sent in one direction SHOULD be considered a single data stream. For example, initialization vectors SHOULD be passed from the end of one packet to the beginning of the next packet. All ciphers SHOULD use keys with an effective key length of 128 bits or more. The ciphers in each direction MUST run independently of each other, and implementations MUST allow independently choosing the algorithm for each direction (if multiple algorithms are allowed by local policy). 3des-cbc blowfish-cbc ... aes256-cbc REQUIRED RECOMMENDED OPTIONAL three-key 3DES in CBC mode Blowfish in CBC mode AES (Rijndael), CBC, 256-bit key
User authentication
rhosts (severely deprecated; v 1 only)
Network layer tests only
Passwords
Protocol sends username/password as unit, not interactively
But chained connections
Public keys
Authentication agent forwarding with A
Connection Management
Think of an embedded set of TCP streams Each has:
Local and remote ID Window size Max packet size (bulk vs interactive)
VPNs
Can run PPP connection over SSH A bit convoluted, but it works
Project 3
Would handle confidentiality, integrity, and authentication Not sure which toolkit to suggest though; openssh?
Interesting attacks
The user authentication protocol is subject to man-in-the-middle attacks if the encryption is disabled. [Secsh-arch] Herbivore keystroke analysis (Usenix Security 2001)
50x advantage over brute force
deattack.c bug
Taken from CORE-SDI, http://www1.corest.com/common/showdoc.php?idxseccion=10&idx=81 Technical Description - Exploit/Concept Code: Most SSH distributions incorporated the file deattack.c released by CORE SDI in 1998. The file implements an algorithm to detect attempts to exploit the CRC-32 compensation attack by passing the ssh packets received from the network to the detect_attack() function in deattack.c ... /* detect_attack Detects a crc32 compensation attack on a packet */ int detect_attack(unsigned char *buf, word32 len, unsigned char *IV) { static word16 *h = (word16 *) NULL; static word16 n = HASH_MINSIZE / HASH_ENTRYSIZE; register word32 i, j; word32 l; ... buf is the ssh packet received, len is the length of that packet. The received packet is comprised of several blocks of cipher text of size SSH_BLOCKSIZE and each of them is checked against the others to verify that different packets dont have the same CRC value, such behavior is symptom of an attack. The detection is done using a hash table that is dynamically allocated based on the size of the received packet.
deattack.c continued
... for (l = n; l < HASH_FACTOR(len / SSH_BLOCKSIZE); l = l << 2); if (h == NULL) { debug("Installing crc compensation attack detector."); n = l; h = (word16 *) xmalloc(n * sizeof(word16)); } else ... Due to the improper declaration of 'n' above (it should be a word32) by sending crafted large ssh packets (length > 2^16) it is possible to make the vulnerable code perform a call to xmalloc() with an argument of 0, which will return a pointer into the program's address space. It is worth mentioning that existing standards promote two possible behaviors for malloc() when it is called with an argument of 0: - Failure, returning NULL - Success, returning a valid address pointing at a zero-sized object. Most modern systems implement the later behaviors and are thus vulnerable. Systems which have the older behaviors will abort the connection due to checks within xmalloc() It is then possible to abuse the following code to in order write to arbitrary memory locations in the program (ssh server or client) address space, thus allowing an attacker to execute arbitrary code on the vulnerable machine
deattack.c continued
for (c = buf, j = 0; c < (buf + len); c += SSH_BLOCKSIZE, j++) { for (i = HASH(c) & (n - 1); h[i] != HASH_UNUSED; i = (i + 1) & (n - 1)) { if (h[i] == HASH_IV) { if (!CMP(c, IV)) { if (check_crc(c, buf, len, IV)) return (DEATTACK_DETECTED); else break; } } else if (!CMP(c, buf + h[i] * SSH_BLOCKSIZE)) { if (check_crc(c, buf, len, IV)) return (DEATTACK_DETECTED); else break; } } h[i] = j; } A would-be attacker does not need to authenticate to the SSH server first or to have the packets encrypted in a meaningful way to perform the attack. Even if that was the case, the session key used for encrypting is chosen by the ssh client and it is therefore trivial to implement an exploit (in the sense of the cryptography knowledge required to do it). However, a small degree of knowledge in exploit code development would be needed to implement a working exploit.
Biggest Problem?
Host keys
Works right out of the box What happens when key changes?
ssh.fi version: warning, type y to continue openssh version: error, instruction on how to fix