How to change magic numbers
Last updated
Last updated
let's use the Linux file
command to check the file type of our shell:
As expected, the command tells us that the filetype is PHP. Keep this in mind as we proceed with the explanation.
We can see that the magic number we've chosen is four bytes long, so let's open up the reverse shell script and add four random characters on the first line. These characters do not matter, so for this example we'll just use four "A"s:
Save the file and exit. Next we're going to reopen the file in hexeditor
(which comes by default on Kali), or any other tool which allows you to see and edit the shell as hex. In hexeditor the file looks like this:
Note the four bytes in the red box: they are all 41
, which is the hex code for a capital "A" -- exactly what we added at the top of the file previously.
Change this to the magic number we found earlier for JPEG files: FF D8 FF DB
Now if we save and exit the file (Ctrl + x), we can use file
once again, and see that we have successfully spoofed the filetype of our shell: