Magic Number Validation
Magic Number Validation
Magic numbers are a more accurate way of determining the contents of a file, though they are by no means impossible to fake. The "magic number" of a file is a string of bytes at the very beginning of the file content that identifies the content. For example, a PNG file has these bytes at the very top of the file: 89 50 4E 47 0D 0A 1A 0A.
Unlike Windows, Unix systems use magic numbers to identify files. When dealing with file uploads, it is possible to check the magic number of the uploaded file to make sure it is safe to accept. This is not a guaranteed solution, but it's more effective than checking the file's extension.
Using curl: Send the File Directly to the Upload Point
Why use the webpage with the filter when you can send the file directly with a tool like curl? Posting the data straight to the page that handles the upload is another effective way to completely bypass a client-side filter. We won't cover this method in real depth here, but the syntax would look something like this:
curl -X POST -F "submit:<value>" -F "<file-parameter>:@<path-to-file>" <site>
To use this method, first intercept a successful upload (with Burp Suite or the browser console) to see the parameters being used, then slot those into the command above.