Created
July 24, 2023 23:06
-
-
Save s1037989/2817a552b453b8a2ad6aaed246ad5191 to your computer and use it in GitHub Desktop.
Brute force FIPS HMAC Key extract from binaries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# This allows modifying a library with, e.g., patchelf and updating the FIPS-required .libXXX.hmac | |
# to ensure that the library can be loaded on a FIPS-enabled system. | |
# $ extract-hmackey libcrypto.so.1.1 '^[A-Za-z0-9 ]+$' '.\{16,64\}' | |
# orboDeJITITejsirpADONivirpUkvarP | |
# success | |
# $ extract-hmackey libcrypto.so.1.1 '^a$' '.\{16,64\}' | |
# fail | |
# $ extract-hmackey libcrypto.so.1.1 '^[A-Za-z0-9 ]+$' '.\{32\}' | |
# orboDeJITITejsirpADONivirpUkvarP | |
# success | |
# Set the lib to extract the FIPS HMAC Key | |
export LIB="$1" | |
# Set the regex to reduce the list of strings to try | |
export REGEX="$2" | |
# Set the length range to reduce the list of strings to try | |
export LEN="$3" | |
# Run thru the list of reduced-set strings and check it against the known .hmac | |
strings $LIB | sort -ru | grep -P "$REGEX" | grep -x "$LEN" | HMAC=$(<.$LIB.hmac) perl -Mojo -MDigest::SHA=hmac_sha256_hex -E 'BEGIN{$|=1;$main::lib=f($ENV{LIB})->slurp}END{exit !$main::exit} @_=<STDIN>; my $c=0; foreach (@_) { $c++; chomp; printf "%s/%s\r", $c, $#_; my $hmac = hmac_sha256_hex($main::lib, $_); printf "\r%-64s\n", $_ and $main::exit=1 and exit if $hmac eq $ENV{HMAC} }' && echo success || echo fail |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment