Why do sites offer an MD5 hash of a file? How does that help you verify the integrity/source of the file? Wouldn't paying attention to your URL be enough security?
It helps to verify that once you are done downloading the file, that you have the same file that is sitting on their server.
After running your local file through a hash function, if the slightest difference is found between your copy and theirs, it will result in you getting a different hash than what they have posted.
An MD5 hash doesn't protect you if the site gets hacked because the MD5 sum an be changed as well by the hacker. A GPG signature (in a separate file) would protect against this if you have a copy of the public key that you've gotten from somewhere else, or verified that it's the correct key by checking the signatures on the key.
What an MD5 hash is good for is making sure the file didn't get corrupted in the download process. TCP checksums don't all of the errors that could occur while your file is in transit (though those errors are rare), and I have seen an ISO image get corrupted during the download process before.
Security is one (important) thing, but I think it is also to make sure you downloaded the file in its entirety.
Well in theory both files should produce the same hash if they are exactly the same (though collisions do occur).
You can provide it easily with a server side language, such as ol' trusty PHP...
It offers a defence against a possible man-in-the-middle attack. Suppose a malicious party had somehow been able to hijack the request for the file, but had not been able to alter the text of the web page itself. The MITM would be able to get you to download a different sequence of bytes, but would not be able to make the hash of his file match the hash quoted on the qweb page, that of the real file.
There are several reasons:
- a Man-in-the-Middle attack could possible alter your download and inject a virus or trojan or other malicious code in the download
- It's also possible that some corruption occurred in the bitstream while downloading and the downloaded file might be broken.
- There might be a proxy server involved which might cutoff the connection early.
- Some older browser couldn't download files bigger than 2GB, so downloading bigger files would also mean a corrupted download.
- It also allows a user to check if the "same" file on a mirror server is really the same file and not an altered version.
Sometimes, files transferred may be corrupt, either intentionally by an attacker or due to a faulty connection.
Cryptographic hash functions (such as MD5) are designed to change if there's a change in the original file. As such, you can detect such alterations.
Note that, if you want protection against intentional modification (made by an attacker), you need a way to verify that the reference hash you obtained is correct and from a trusted source (e.g. signature via PGP or X.509 certificates for example). You may also need a better hash algorithm (e.g. SHA-1, SHA-256), as collisions attacks have been demonstrated against MD5.