Search code examples
encryptionhashsql-injectioncode-injectiontheory

Can keys or hashes trigger an injection attack?


Can hashes or keys generated (either intentionally or accidentally) that would trigger an injection attack? For example, if the hash or key was generated as something like SELECT%0d*%0dFROM%0dWHEREVER, could this cause an injection attack? I am aware with current technologies and standards, any decent protection will protect against all input, hashes and keys included, so it almost surely wouldn't effect any systems in reality.

Yes, I have been informed this is the wrong location for this type of question. Yes, I am now aware of where to put it next time.


Solution

  • In theory, I suppose it's possible that the result of a hash function would result in a specific sequence of bytes that happens to be SQL syntax, either when used as raw binary bytes or if encoded in the range of printable ASCII characters (values 0x20 through 0x7F).

    But it would be a hard task to come up with an input string that produced that exact result when hashed.

    The result of a hash function is always of fixed length, depending on the hash algorithm and options. So you would need to have an attack query in mind that fit in that fixed length exactly, and then you would need to find the input that hashed to that string exactly.

    Also, the method for defending against such an attack is the same as defending against any other SQL injection attack: use query parameters. Any unsafe content, no matter if it is the result of a hash function or not, is able to effect an SQL injection if it is kept separate from the SQL syntax.

    I think there are other means of attack that would be easier and more effective. Social hacking is still the most general-purpose means of attack, and can get around just about any security defense.