文件类型鉴定与HEX编码分析

法国女足世界杯 7763

0x00 背景

近来处理webshell的时候,发现文件类型被篡改了,如何从HEX编码从判断是否为正常的文件,例如jpg是否为普通jpg还是合成了恶意代码的jpg,故需要分析文件头文件尾,进行一个简单的判断

0x01安装工具

相对来说,简单快捷的是安装notepad++,然后安装Hex-Editor插件。当前使用其他的,例如UltraEdit、winhex、IDA pro也是不错的选择。

notepad++下载地址:https://notepad-plus-plus.org/ 注意:请选择 Notepad++ Installer 32-bit x86,因为64位的软件无法直接安装Hex-Editor插件。

notepad++安装成功,选择【插件】- 【插件管理】,如下图

安装成功,重启notepad++即可。

0x02 文件头文件尾

1.图片文件

JPEG (jpg/jpe/jpeg) 文件头:FFD8FF 文件尾:FF D9

PNG (png) 文件头:89504E47 文件尾:AE 42 60 82

GIF (gif) 文件头:47494638 文件尾:00 3B

TIFF (tif), 文件头:49492A00 文件尾:

Windows Bitmap (bmp), 文件头:424D 文件尾:

ico(ico) 文件头:00 00 01 00

Adobe Photoshop (psd), 文件头:38425053 文件尾:

2.office文件

MS Word/Excel (xls.or.doc), 文件头:D0CF11E0

MS Access (mdb), 文件头:5374616E64617264204A

WordPerfect (wpd), 文件头:FF575043

Adobe Acrobat (pdf), 文件头:255044462D312E

application/vnd.visio(vsd) 文件头:d0cf11e0a1b11ae1

Email [thorough only] (eml), 文件头:44656C69766572792D646174653A

Outlook Express (dbx), 文件头:CFAD12FEC5FD746F

Outlook (pst), 文件头:2142444E

Rich Text Format (rtf), 文件头:7B5C727466

txt 文件(txt) , 文件头:Unicode:feff / Unicode big endian:fffe / UTF-8:efbbbf /ANSI编码是没有文件头的

3.压缩包文件

ZIP Archive (zip), 文件头:504B0304 文件尾:50 4B

RAR Archive (rar), 文件头:52617221

4.音频文件

Wave (wav), 文件头:57415645

audio(Audio), 文件头: 4D546864,

audio/x-aac(aac) 文件头:fff1 / fff9

4.视频文件

AVI (avi), 文件头:41564920

Real Audio (ram), 文件头:2E7261FD

Real Media (rm), 文件头:2E524D46

MPEG (mpg), 文件头:000001BA

MPEG (mpg), 文件头:000001B3

Quicktime (mov), 文件头:6D6F6F76

Windows Media (asf), 文件头:3026B2758E66CF11

MIDI (mid), 文件头:4D546864

5.代码文件

XML (xml), 文件头:3C3F786D6C 文件尾:

HTML (html), 文件头:68746D6C3E

Quicken (qdf), 文件头:AC9EBD8F

Windows Password (pwl), 文件头:E3828596

6.其他类型

windows证书文件(der) 文件头:30 82 03 C9

CAD (dwg), 文件头:41433130 文件尾:

Windows Shortcut (lnk) 文件头:4C000000

Windows reg, (reg) 文件头:5245474544495434

0x03 特征库

1、主要网站

https://file-extension.net/

2、分析工具:tridnet

本地分析:https://mark0.net/soft-tridnet.html

3、关键特征库

特征库:https://mark0.net/code-tridlib-e.html

特征库目录:https://mark0.net/soft-trid-deflist.html

本地特征库:https://mark0.net/download/triddefs_xml.7z

在线特征库:https://file-extension.net/seeker/

0x04 其他参考

Mime Type(Content-Type)文件扩展名签名video/3gpp3gp00 00 00 14 66 74 79 7000 00 00 14 66 74 79 7000 00 00 20 66 74 79 7000 00 00 20 66 74 79 70video/mp4mp400 00 00 14 66 74 79 70 69 73 6f 6d00 00 00 18 66 74 79 7000 00 00 1c 66 74 79 70video/3gpp23g200 00 00 14 66 74 79 7000 00 00 20 66 74 79 70video/x-m4vm4v00 00 00 18 66 74 79 70audio/mp4m4a00 00 00 20 66 74 79 70 4d 34 41image/x-iconico00 00 01 00application/x-futuresplashspl00 00 01 00video/mpegmpg00 00 01 b300 00 01 bavideo/x-ms-vobvob00 00 01 baapplication/vnd.lotus-1-2-312300 00 1a 00 05 10 04application/vnd.quark.quarkxpressqxd00 00 49 49 58 50 5200 00 4d 4d 58 50 52application/x-font-ttfttf00 01 00 00 00application/x-msmoneymny00 01 00 00 4d 53 49 53 41 4d 20 44 61 74 61 62 61 73 65application/x-msaccessmdb00 01 00 00 53 74 61 6e 64 61 72 64 20 4a 65 74 20 44 42video/x-flifli00 11image/x-rgbrgb01 da 01 01 00 03application/xml-dtddtd07 64 74 32 64 64 74 64image/x-pcxpcx0a 02 01 010a 03 01 010a 05 01 01application/msworddoc0d 44 4f 43dotcf 11 e0 a1 b1 1a e1 00 d0 cf 11 e0 a1 b1 1a e1 db a5 2d 00application/vnd.ms-workswks0e 57 4b 53wpsff 00 02 00 04 04 05 54 d0 cf 11 e0 a1 b1 1a e1application/vnd.nitfntf1a 00 0030 31 4f 52 44 4e 41 4e4e 49 54 46 30application/vnd.lotus-notesnsf1a 00 00 04 00 004e 45 53 4d 1a 01application/x-freearcarc1a 021a 031a 041a 081a 0941 72 43 01video/webmwebm1a 45 df a3video/x-matroskamkv1a 45 df a3 93 42 82 88application/x-msdownloadmsi23 20comd0 cf 11 e0 a1 b1 1a e1dll4d 5aexee8 e9 ebaudio/silksil23 21 53 49 4c 4b 0aapplication/postscripteps25 21 50 53 2d 41 64 6fc5 d0 d3 c6application/pdfpdf25 50 44 46application/vnd.fdffdf25 50 44 46application/mac-binhex40hqx28 54 68 69 73 20 66 69text/plainlog00 2a 2a 2a 20 20 49 6e 73application/vnd.rn-realmediarm2e 52 4d 46application/vnd.rn-realmedia-vbrrmvb2e 52 4d 46audio/x-pn-realaudiora2e 52 4d 46 00 00 00 12ram2e 72 61 fd 00 72 74 73 70 3a 2f 2faudio/basicau2e 73 6e 6464 6e 73 2eapplication/vnd.epson.msfmsf2f 2f 20 3c 21 2d 2d 20 3c 6d 64 62 3a 6d 6f 72 6b 3a 7aapplication/vnd.ms-pki.seccatcat30video/x-ms-asfasf30 26 b2 75 8e 66 cf 11asx3caudio/x-ms-wmawma30 26 b2 75 8e 66 cf 11video/x-ms-wmvwmv30 26 b2 75 8e 66 cf 11application/x-mswritewri31 be32 bebe 00 00 00 abapplication/x-7z-compressed7z37 7a bc af 27 1cimage/vnd.adobe.photoshoppsd38 42 50 53application/xmlxml3c 3f 78 6d 6c 20 76 65 72 73 69 6f 6e 3d 22 31 2e 30 22 3f 3eapplication/vnd.framemakerfm3c 4d 61 6b 65 72 46 69application/vnd.mifmif3c 4d 61 6b 65 72 46 6956 65 72 73 69 6f 6e 20application/gpx+xmlgpx3c 67 70 78 20 76 65 72 73 69 6f 6e 3d 22 31 2eapplication/winhlphlp3f 5f 03 004c 4e 02 00image/vnd.dwgdwg41 43 31 30application/vnd.lotus-organizerorg41 4f 4c 56 4d 31 30 30text/x-vcardvcf42 45 47 49 4e 3a 56 43application/octet-streambin42 4c 49 32 32 33dms44 4d 53 21mar4d 41 52 31 00 4d 41 52 43 4d 41 72 30 00image/bmpbmp42 4dapplication/x-mobipocket-ebookprc42 4f 4f 4b 4d 4f 42 49application/x-bzip2bz242 5a 68application/x-iso9660-imageiso43 44 30 30 31application/mac-compactprocpt43 50 54 37 46 49 4c 4543 50 54 46 49 4c 45application/x-shockwave-flashswf43 57 5346 57 535a 57 53application/x-cdlinkvcd45 4e 54 52 59 56 43 44image/vnd.ms-modimdi45 50video/x-flvflv46 4c 56audio/x-aiffaiff46 4f 52 4d 00message/rfc822eml46 72 6f 6d52 65 74 75 72 6e 2d 5058 2dimage/gifgif47 49 46 38image/tifftif49 20 49tiff49 49 2a 00 4d 4d 00 2a 4d 4d 00 2baudio/mpegmp349 44 33application/vnd.ms-cab-compressedcab49 53 63 284d 53 43 46application/vnd.ms-htmlhelpchm49 54 53 46application/java-archivejar4a 41 52 43 53 0050 4b 03 0450 4b 03 04 14 00 08 005f 27 a8 89application/x-ms-shortcutlnk4c 00 00 00 01 14 02 00application/x-tgifobj4c 0180application/vnd.palmpdb4d 2d 57 20 50 6f 63 6b4d 69 63 72 6f 73 6f 66 74 20 43 2f 43 2b 2b 2073 6d 5f73 7a 65 7aac ed 00 05 73 72 00 12application/vnd.tcpdump.pcapdmp4d 44 4d 50 93 a7cap50 41 47 45 44 55 52 54 53 53 58 43 50 00application/vnd.smafmmf4d 4d 4d 44 00 00audio/midimid4d 54 68 64midi52 49 46 46rmi application/vnd.rim.codcod4e 61 6d 65 3a 20audio/oggoga4f 67 67 53 00 02 00 00oggvideo/oggogv4f 67 67 53 00 02 00 00application/oggogx4f 67 67 53 00 02 00 00image/x-portable-graymappgm50 35 0aapplication/zipzip50 4b 03 0450 4b 03 0450 4b 03 04 14 00 01 0050 4b 05 0650 4b 07 08application/vnd.openxmlformats-officedocument.wordprocessingml.documentdocx50 4b 03 0450 4b 03 04 14 00 06 00application/vnd.openxmlformats-officedocument.presentationml.presentationpptx50 4b 03 0450 4b 03 04 14 00 06 00application/vnd.openxmlformats-officedocument.spreadsheetml.sheetxlsx50 4b 03 0450 4b 03 04 14 00 06 00application/vnd.google-earth.kmzkmz50 4b 03 04application/vnd.kde.kwordkwd50 4b 03 04application/vnd.oasis.opendocument.textodt50 4b 03 04application/vnd.oasis.opendocument.presentationodp50 4b 03 04application/vnd.oasis.opendocument.text-templateott50 4b 03 04application/vnd.sun.xml.calcsxc50 4b 03 0450 4b 03 04application/vnd.sun.xml.drawsxd50 4b 03 04application/vnd.sun.xml.impresssxi50 4b 03 04application/vnd.sun.xml.writersxw50 4b 03 04application/x-msmetafilewmz50 4b 03 04wmfd7 cd c6 9aapplication/x-xpinstallxpi50 4b 03 04application/vnd.ms-xpsdocumentxps50 4b 03 04application/epub+zipepub50 4b 03 04 0a 00 02 00image/x-cmxcmx52 49 46 46video/x-msvideoavi52 49 46 46audio/x-wavwav52 49 46 46image/webpwebp52 49 46 46application/x-rar-compressedrar52 61 72 21 1a 07 00application/x-stuffitsit53 49 54 21 0053 74 75 66 66 49 74 20application/vnd.yamaha.smaf-phrasespf53 50 46 49 00application/vnd.lotus-wordprolwp57 6f 72 64 50 72 6fapplication/pls+xmlpls5b 70 6c 61 79 6c 69 73 74 5daudio/x-cafcaf63 61 66 66application/x-cshcsh63 75 73 68 00 00 00 02application/pkcs10p1064 00 00 00audio/x-flacflac66 4c 61 43 00 00 00 22application/pkix-attr-certac72 69 66 66application/x-apple-diskimagedmg78 01 73 0d 62 62 60application/vnd.xaraxar78 61 72 21application/rtfrtf7b 5c 72 74 66 31image/pngpng89 50 4e 47 0d 0a 1a 0aapplication/applixwareaw8a 01 09 00 00 00 e1 08application/java-vmclassca fe ba beapplication/vnd.ms-powerpointppsd0 cf 11 e0 a1 b1 1a e1pptapplication/vnd.ms-excelxlad0 cf 11 e0 a1 b1 1a e1xlsaudio/adpcmadpd0 cf 11 e0 a1 b1 1a e1application/vnd.lotus-approachaprd0 cf 11 e0 a1 b1 1a e1application/x-mspublisherpubd0 cf 11 e0 a1 b1 1a e1application/vnd.visiovsdd0 cf 11 e0 a1 b1 1a e1application/x-xzxzfd 37 7a 58 5a 00application/vnd.wordperfectwpdff 57 50 43image/jpegjpeff d8 ffjpegjpgaudio/x-aacaacff f1ff f9欢迎大家分享更好的思路,热切期待^^_^^ !!!