While pointing out a SQL injection flaw on another question, I was able to show that an arbitrary sha1 hash could be inserted into a query such that it would be taken for a real hash, and was therefore able to login assuming the dummy hash was used. I could inject an ORDER BY but then wanted to make sure the hash I was using as an example was likely to come out at the top.

From my understanding, 0000000...0 should be a valid possible output from the hash function but, of course, finding the associated input is non-trivial.

In any case, it got me wondering. Is there any way - except brute force or downloading a rainbow table - to find a hash that would sort before an arbitrary point (say before 99% of passwords =~ in the first 1.46150x10^46)

I suspect the answer is no but would like confirmation.

  • Perhaps better suited at crypto.SE since no programming is involved.
    – ntoskrnl
    Commented Mar 25, 2014 at 20:54
  • 1
    Bitcoin mining is very similar to this: The goal it to find an x for which SHA256(SHA256(x)) starts with enough leading zero bits. Commented Mar 26, 2014 at 8:47
  • @CodesInChaos Fascinating. I never took the time to look intop what bitcoin was doing under the hood. Thanks very much
    – Basic
    Commented Mar 26, 2014 at 9:17

1 Answer 1


If there is a method faster than brute force, it represents a weakness in the hash function. Essentially what you're looking for is a modified preimage attack, just for a group of hash values rather than a single value.

  • From the link... "By definition, an ideal hash function is such that the fastest way to compute a first or second preimage is through a brute force attack". That pretty much hits the nail on the head. Thanks for the reference.
    – Basic
    Commented Mar 26, 2014 at 8:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .