What ARE magic numbers you ask? Well... 7 is apparently lucky but it's definitely not magic... The magic number Wiki explains them to be numbers at the beginning of a file that outlines what that file is. This Wiki page will also give you some examples of magic numbers for various file formats.
Yeah but who cares?! ....yeah... I mean if you have something that's checking these numbers in a file upload area... you COULD bypass any back end file validation and get something uploaded that maybe shouldn't... just saying...
Viewing a files Magic Number
Using xxd (a linux hex editor), we can view the files magic numbers by using the below:
└─$ xxd spoil.png | head
00000000: 8950 4e47 0d0a 1a0a 0000 000d 4948 4452 .PNG........IHDR
00000010: 0000 0320 0000 0320 0806 0000 00db 7006 ... ... ......p.
00000020: 6800 0000 0173 5247 4200 aece 1ce9 0000 h....sRGB.......
00000030: 0009 7048 5973 0000 0ec4 0000 0ec4 0195 ..pHYs..........
00000040: 2b0e 1b00 0020 0049 4441 5478 9cec dd79 +.... .IDATx...y
00000050: 9c9c 559d eff1 cf79 9e5a bb7a 5f92 7477 ..U....y.Z.z_.tw
00000060: f640 4802 0920 1150 c420 bba2 88a8 805c .@H.. .P. .....\
00000070: 1906 7c5d 64c0 79e9 752e 03ce 38e3 0e8e ..|]d.y.u...8...
00000080: 2f75 e63a 23ea 8c0c e830 8e03 6470 c191 /u.:#....0..dp..
00000090: cd80 880c 4b20 0909 184c 42b6 4ed2 e9f4 ....K ...LB.N...
Here we can see the first few numbers (as outlined on the wiki page) are for a PNG file
OK so what... now what?
Changing a files Magic Number
Changing the files magic number is as simple as editing it with a simple hex editor. I like 'hexedit' in linux. It's a command line tool and very easy to make changes with. It looks something like this when up and running:
![](https://static.wixstatic.com/media/b4353b_92800e032eb34e2f860b75636f352c55~mv2.png/v1/fill/w_78,h_25,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/b4353b_92800e032eb34e2f860b75636f352c55~mv2.png)
Simply, start typing where the curser is and you're making changes. Hit ctrl+x when you're done and it'll prompt you to save it.