Skip to content

Instantly share code, notes, and snippets.

@redmcg
Last active January 17, 2020 06:29
Show Gist options
  • Save redmcg/571bc4f1f67aeb1cf016af278205c12f to your computer and use it in GitHub Desktop.
Save redmcg/571bc4f1f67aeb1cf016af278205c12f to your computer and use it in GitHub Desktop.

Revisions

  1. redmcg revised this gist Jan 17, 2020. 1 changed file with 29 additions and 0 deletions.
    29 changes: 29 additions & 0 deletions findHostName2.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,29 @@
    #!/usr/bin/env bash

    host=$1

    awk -v host=$host '
    function pad_key(pad, i, val) {
    for (i = 0; i < 64; i++) {
    val = sprintf("%s%02x", val, xor(strtonum("0x" substr(hexkey, i*2+1, 2)), pad))
    }
    return val
    }
    /^|1/ {
    split($1, a, /\|/)
    key=a[3]
    hmac=a[4]
    "echo " key " | base64 -d | xxd -p " | getline hexkey
    o_key_pad = pad_key(0x5c)
    i_key_pad = pad_key(0x36)
    "bash -c '\''cat <(echo -n " o_key_pad " | xxd -r -p) <(cat <(echo -n " i_key_pad " | xxd -r -p) <(echo -n " host ") | sha1sum | xxd -r -p) | sha1sum | xxd -r -p | base64'\''" | getline myhmac
    if (hmac == myhmac) {
    print "# Host " host " found: line " NR
    print
    }
    }' ~/.ssh/known_hosts
  2. redmcg revised this gist Jan 17, 2020. 1 changed file with 13 additions and 1 deletion.
    14 changes: 13 additions & 1 deletion findHostName.sh
    Original file line number Diff line number Diff line change
    @@ -2,4 +2,16 @@

    host=$1

    awk -v host=$host ' /^|1/ { split($1, a, /\|/); key=a[3]; hmac=a[4]; "echo -n " host " | openssl sha1 -mac HMAC -macopt hexkey:$(echo " key " | base64 -d | xxd -p) -binary | base64" | getline myhmac; if (hmac == myhmac) { print "# Host " host " found: line " NR; print $0 } } ' ~/.ssh/known_hosts
    awk -v host=$host '
    /^|1/ {
    split($1, a, /\|/)
    key=a[3]
    hmac=a[4]
    "echo -n " host " | openssl sha1 -mac HMAC -macopt hexkey:$(echo " key " | base64 -d | xxd -p) -binary | base64" | getline myhmac
    if (hmac == myhmac) {
    print "# Host " host " found: line " NR
    print
    }
    }' ~/.ssh/known_hosts
  3. redmcg created this gist Jan 17, 2020.
    5 changes: 5 additions & 0 deletions findHostName.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,5 @@
    #!/usr/bin/env bash

    host=$1

    awk -v host=$host ' /^|1/ { split($1, a, /\|/); key=a[3]; hmac=a[4]; "echo -n " host " | openssl sha1 -mac HMAC -macopt hexkey:$(echo " key " | base64 -d | xxd -p) -binary | base64" | getline myhmac; if (hmac == myhmac) { print "# Host " host " found: line " NR; print $0 } } ' ~/.ssh/known_hosts