3

I'm trying to figure out how an ARM-Based device running Busybox Linux is storing hashes for users in a configuration file. Basically, the system allows you to backup the entire configuration to a file. Within this file I can see the hashes for one of the default accounts - admin.

If I configure the admin password to be test, I get this hash in the output file:

3785a9c61b587f2ff0dd7132db844f14

Being a 32 character hash, I suspect it's MD5. I know from testing that if I configure one of the other built-in accounts to have the same password, the hash is different. So it seems that whatever the hashing algorithm, it probably does something like concatenate the username and password together before hashing.

I've tried a bunch of combinations, and am thinking I might just have to try brute force. Seeing as i know the username and password, I suppose I could do a custom dictionary attack or something.

Any suggestions ?

  • Maybe the password ist salted with the user name, maybe with something else. If you set the password for the same user to the same password a few times in a row, is it always the same, or different? – Guntram Blohm Nov 11 '14 at 6:29
  • Yes, the hash is always the same for a specific user, for a given password. It's also the same between systems - you can take the configuration saved from one unit, and upload it to another. – 59e12ca75b3d Nov 11 '14 at 7:22
  • 1
    The best bet would be to find whatever program is generating this hash and RE it. – Igor Skochinsky Nov 11 '14 at 15:22
  • @IgorSkochinsky isn't BusyBox open source? Potentially the version in question is modified but still – user45891 Nov 11 '14 at 17:10
  • 1
    @user45891: I don't think BusyBox is the program generating these config files. – Igor Skochinsky Nov 12 '14 at 0:03
3

I took a little Perl program that i'd written a while ago when i had a similar problem, and changed it to match your data. This is supposed to generate all permutations of "test:admin", which any character as the separator, and including all abbreviations (to handle the case that only a few bytes from the username are taken).

I got around 50 results beginning in 3785a9, but none with 3785a9c6. So, this seems to rule out the case that (a part of) the username is concatenated to the password, possibly with a separator character, and the MD5 of the result is computed. But of course, they might use MD4 or something else that produces 16 bytes. They might xor the user with the password first. They might read the MD5 backwards. Lots of possibilities to make it harder to find out the algorithm.

If you can find out which binary creates the password in the first place, try to run signsrch on it, this might help in finding the algorithm it uses.

If you want to try a few more things with my perl program, here it is. Took about 1 hour on 1 core on a Xeon E5. There's a few things that you can optimize, but i supposed it doesn't make much sense to spend 30 minutes to make the program run 5 minutes faster.

#!/usr/bin/perl

use Digest::MD5 qw(md5_hex);
use List::Util qw(shuffle);
use strict;
use warnings;

$|=1;

my @admintest=(split("", "admintest"), ":", chr(127));
# my @admintest=(split("", "abc"), ":", chr(127));

my $n=0;

permute("", @admintest);

sub permute {
        my $str=shift;
        my @letters=@_;
        my $str2;

        for (my $i=0; $i<=$#letters; $i++) {
                if ($letters[$i] eq chr(127)) {
                        tryseparatorsonstring($str);
                        return;
                }
                $str2=$str.$letters[$i];
                permute($str2, @letters[0..$i-1], @letters[$i+1..$#letters]);
        }
}
print "\n";

sub tryseparatorsonstring {
        my $str=shift;
        if ($str =~ /:/) {
                for (my $sep=0; $sep<128; $sep++) {
                        my $str2=$str;
                        $str2=~s/:/chr($sep)/ge;
                        trystring($str2, $sep);
                }
        } else {
                trystring($str, "");
        }
}

sub trystring {
        my $str=shift;
        my $sep=shift;
        my $pass=md5_hex($str);
        print "$n\t$str\t$sep\t$pass\n" if $pass =~ /^3785a9/;
        if (++$n%1_000_000==0) {
                printf "%dM\r", $n/1_000_000;
        }
        # print "$str\n";
}

exit 0;
  • Thanks for that. I guess that crosses a few options off the list. I did manage to root the device and get access to the binary, i'll try and find it again and try signsrch. – 59e12ca75b3d Nov 12 '14 at 0:09
2

I would advise you to look for an hash identification software. You can find several freely available on Internet. For example:

I tried your sample with HashTag and it seems to be an MD5 algorithm with several type of settings, but more you will provide signatures to it, more it will be accurate.

$> HashTag.py -sh 3785a9c61b587f2ff0dd7132db844f14

Hash: 3785a9c61b587f2ff0dd7132db844f14

[*] MD5 - Hashcat Mode 0
[*] NTLM - Hashcat Mode 1000
[*] MD4 - Hashcat Mode 900
[*] LM - Hashcat Mode 3000
[*] MD5(HMAC)
[*] MD4(HMAC)
[*] Haval-128(HMAC)
[*] RipeMD-128(HMAC)
[*] Tiger-128(HMAC)
[*] Snefru-128(HMAC)
[*] MD2(HMAC)
[*] MD5(ZipMonster)
[*] MD5(HMAC(Wordpress))
[*] Skein-256(128)
[*] Skein-512(128)
[*] md5($pass.$salt) - Hashcat Mode 10
[*] md5($pass.$salt.$pass)
[*] md5($pass.md5($pass))
[*] md5($salt.$pass) - Hashcat Mode 20
[*] md5($salt.$pass.$salt) - Hashcat Mode 3810
[*] md5($salt.$pass.$username)
[*] md5($salt.'-'.md5($pass))
[*] md5($salt.md5($pass)) - Hashcat Mode 3710
... [cut] ...
  • +1 for pointing out how many different algorithms produce the same kind of hash. – Guntram Blohm Nov 11 '14 at 14:54
  • Thanks, i've given it a run with a few more hashes, and they all produce the same result. – 59e12ca75b3d Nov 12 '14 at 0:08
  • The best way would be to find the software that creates new password entries in the system and reverse it a bit (just focusing on the methods used to create these hashes). And, if you can create new password, then it will be a clear text attack (much easier). On another hand, you can also try to find the software that is validating the passwords (probably hidden in the PAM modules). – perror Nov 12 '14 at 7:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.