# Implementing brute force attacks on hash values in Javascript

I'm working for my bachelor thesis at the end of which I aim to implement a proof-of-concept Javascript-based hash cracker. The idea is to work like this: Users can submit a hash value along with information about the used algorithm. (Other) users can also click on a button on the website in order to participate in the cracking process. The server's task is to accept and split the submitted 'orders' into ranges, depending on the number of available workers. The ranges are then sent to the clients who clicked said button.

I am currently stuck with the big question of how to actually implement this brute force function. So my main problem now is that, frankly, I'm not really that settled in Javascript yet. For starters, I would just use a hardcoded character set: alpha-numeric, lower and upper case, no special characters. Problem is I honestly have absolutely NO clue of how to actually implement the function that would try out al the character combinations, on how to program that. I can imagine using a normal array containing the charset, then two strings. One string would contain the range, the other will contain the tried combinations. So I would somehow have to iterate through the charset array and the strings maybe with cascaded for-loops or something, but I'm really stuck with the question of 'how' exactly :). I don't expect any of you to actually provide me with the full source code for such a function (unless you want to of course), but I'd really appreciate some hints or explanations on how to implement such a brute force function. I'd also not bother about performance or optimized coding at this point, but rather about comprehensive coding, or whatever you might want to call it.

-

First define the space of potential passwords. Then number them sequentially.

For instance, suppose that you define the possible passwords as "sequences of eight letters and digits". This is an alphabet of 62 signs (26 lowercase letters, 26 uppercase letters, 10 digits). So there are 628 = 218340105584896 passwords to try. Passwords are easily mapped to integers in the 0..218340105584895 range by considering the passwords to be a base-62 representation (i.e. 'a' is 0, 'b' is 1,... 'z' is 25, 'A' is 26,... 'Z' is 51, '0' is 52... and '9' is 61). Now that the potential passwords are just integers in a consecutive sequence, it is easy to distribute ranges.

Of course, performance of hash function implemented in Javascript will be very disappointing. A single PC with a good GPU can try more MD5 passwords than 1000 clients who use Javascript. You might want to make versions which use Java and/or .NET (Silverlight): these programming languages have much more muscle (not quite as good as C, but at least in the same magnitude order).

Edit: from your comment, I understand that you also wish to keep the target hash somewhat private, and not send it to the cracking machines. This forces the cracking machines to send back all their hashes (or part thereof) to the server, and you will have a bandwidth problem. Each cracking machine could send back, say, only the first two bytes of each computed hash; the server then knows which password candidates match the target hash on the first two bytes. This would reduce the problem by a factor 65536, and then the server can finish the work itself (retesting the matching candidates on its own CPU). However, with a 10 MBytes/s incoming bandwidth, you would be able to receive only about 5 millions hashes per second, and if you target a "simple" hash (like a single iteration of MD5), then this is very poor performance (the server alone, on its own CPU, can test many more passwords per second). This would be a valid scheme for a slow hash (like bcrypt) where each cracking machine will be able to compute a hundred hashes per second at most (but then, you really do not want to use Javascript...).

-
Thanks for your help here, for some reason I never thought of simply defining the search space. Idk why but I always thought I have to split the actual has value...Yes I agree: the performance will not be pretty. Using Javascript for this is one criteria for my thesis, and I guess it is because js is way more widespread than, say Silverlight. There are also nexto to no compatibility issues here, since js works in all browsers today, unless of course it's turned off. – slagjoeyoco Sep 6 '12 at 23:49
So defining the search range would work perfectly with normal strings, but there is one problem left: I have to hash the result of the client's calculation after EVERY try since I only have the original hash value to match it with...correct me if I'm wrong, but afaik the hash values will always be different since the client will never be able to calculate the whole clear text when it's just processing a part of the search space...I'm wondering right now if it's even possiblem to split the search space on a hash value. – slagjoeyoco Sep 6 '12 at 23:54

First of all it sounds like you need to formulate a cracking strategy, and to do that you should look at what tools hackers are using. Here is a nice blog post of someone who cracked 122 million hashes. He also links to a large list of real password hashes that you could use for your thesis. I think all of these hashes are unsalted, so that makes things easier.

RainbowCrack and JohnTheRipper are tools that have been around for a long time and are popular tools for breaking hashes. But what you are doing is pretty different, its more cloud-like in that its breaking up a large task to be completed by a large number of nodes. There are cloud cracking tools like Cryptohaze that look promising.

-
Hi and thank you for your help. Yes the part about splitting the hashes into ranges in order to distribute the task among my nodes is also a problem right now, but I'd rather focus on the main problem described above. Sorry for the confusion. The blog you've mentioned is in fact really interesting as it links to great sources for word lists and hash values for later testing, but I'm afraid it doesn't help with my current problem of "how to implement a brute-forcing functionality". I know in general of how brute forcing works, but I have no idea of how to do that in terms of programming... – slagjoeyoco Sep 5 '12 at 20:41
@slagjoeyoco if it is simply just dividing up labor you should try asking that question to SO, and leave out the part that you are using this for cracking hashes. – rook Sep 6 '12 at 0:23
well the problem is that this is not only about how to divide labor, since A) I'm looking for ways to actually implement a brute-forcing function as described in my question, and B) I'm not looking on how to divide mere clear-text strings, but on how to split the search space for hash values among several working clients. – slagjoeyoco Sep 6 '12 at 23:57