mkogg.py: Fix 'self.get_mp4_metadata(self, source)'
[blog.git] / posts / known_hosts.mdwn
1 [OpenSSH][] stores lists of [[SSH]] public keys in `known_hosts`
2 files, so it can verify that the host you're logging into is the host
3 you expect and not a man-in-the-middle attacker.  To reduce the risk
4 of [island-hopping attacks][hop], OpenSSH has a `HashKnownHosts yes`
5 option to store [HMAC][]-[SHA1][] encrypted versions of host names and
6 IPs in your `known_hosts` files rather than the clear text.  This
7 makes it harder for an attacker to use the information stored in your
8 `known_hosts`.  However, it also makes it harder for *you* to use that
9 information.
10
11 I was digging through my `known_hosts` file yesterday compiling a list
12 of servers where I have login accounts.  I keep better track of these
13 things recently (using [[GPG|PGP]] to symmetrically encrypt the list),
14 but my `known_hosts` file predates my quality-accounting phase.
15 Anyhow, I wrote up some simple tools to make reverse-engineering a
16 `known_hosts` file a bit less painful.
17
18 You can use your [[monkeysphere]] keyring to see if you recognize any
19 of the public keys.  This avoids having to deal with the hashed names
20 at all, but assumes none of your servers are sharing keys.
21 [[Monkeysphere/unhash-known-hosts.sh]] automates this:
22
23     $ unhash-known-hosts.sh path/to/known_hosts
24     GnuPG ID 01234567 (ssh://server.example.net) matches |1|Bvjsg3lqJJ/M9rTYz1HfY+T/RoM=|DhZlGg3GFMWtVcjz4LNfJ8afi7w=
25     did not match |1|vug6FlX6GCaIIzkv3wS3zftQyyw=|PdMYEIaWTzHCv/4ZhNiR2DD6E0A=
26     ...
27
28 Once you've got the low-hanging fruit out of the way, you can get a
29 list of the high-hanging fruit:
30
31     $ unhash-known-hosts.sh path/to/known_hosts | sed -n 's/^did not match //p' > unknown_hosts
32
33 Start guessing with [[SSH/crack_known_hosts.py]]!  IPs are usually a
34 good starting point, because any host in your `known_hosts` file must
35 have an entry for its IP.
36
37     $ crack_known_hosts.py --known-hosts unknown_hosts --ip 192.168.*.*
38
39 You can also run a full scan of alphanumeric entries up to a specified
40 length (this gets slow quickly, which is, after all, why you hashed
41 the entries in the fiest place).
42
43     $ crack_known_hosts.py --known-hosts unknown_hosts --alphanum 16
44
45 Removing entries from `unknown_hosts` as you crack them will make
46 future `crack_known_hosts.py` attempts on that file faster.
47
48 Once you've cracked one name, you can use
49 [[SSH/unique_known_hosts.py]] to find other entries that share the
50 same key.
51
52     $ unique_known_hosts.py path/to/known_hosts
53
54 And there you have it.  Happy cracking! ;).
55
56 [OpenSSH]: http://www.openssh.com/
57 [hop]: http://itso.iu.edu/Hashing_the_OpenSSH_known__hosts_File
58 [HMAC]: http://en.wikipedia.org/wiki/HMAC
59 [SHA1]: http://en.wikipedia.org/wiki/SHA-1
60
61 [[!tag tags/linux]]
62 [[!tag tags/tools]]