Hi,
A basic example usage would be -
alert http any any -> any any (msg:"FILEMAGIC pdf"; filemagic:"PDF document"; sid:123456789; rev:1;)
The standard libmagic/file utility is being used by Suricata to determine the magic ( file magic numbers -
https://en.wikipedia.org/wiki/List_of_file_signatures)
Note: The version of that utility differs by OS/OS version itself.
Ex:
root@LTS-64-1:~ # file /usr/bin/suricata
/usr/bin/suricata: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=6d2465f965b8c188d51d5c27866269de0059683a, stripped
root@LTS-64-1:~ #
Usually the compiled database is located in /usr/share/file/magic.mgc
Also according to "man libmagic":
"/usr/share/misc/magic The non-compiled default magic database.
/usr/share/misc/magic.mgc The compiled default magic database."
Where from and in what order that magic.mgc is loaded on your system you can check with - strace file - and see the order of loading (example using the root user):
root@LTS-64-1:~ # strace file
...
...
stat("/root/.magic.mgc", 0x7ffee3aa7560) = -1 ENOENT (No such file or directory)
stat("/root/.magic", 0x7ffee3aa7560) = -1 ENOENT (No such file or directory)
open("/etc/magic.mgc", O_RDONLY) = -1 ENOENT (No such file or directory)
stat("/etc/magic", {st_mode=S_IFREG|0644, st_size=111, ...}) = 0
open("/etc/magic", O_RDONLY) = 3
fstat(3, {st_mode=S_IFREG|0644, st_size=111, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fbce1a45000
read(3, "# Magic local data for file(1) c"..., 4096) = 111
read(3, "", 4096) = 0
close(3) = 0
munmap(0x7fbce1a45000, 4096) = 0
open("/usr/share/misc/magic.mgc", O_RDONLY) = 3
...
...
As to a complete list of the different file types/magic - I am not sure where to find a full "readable" list. If I need to create a rule based on the file magic info of a particular file type - I would first look it up with the file utility and then based on that info create the rule - ex:
root@LTS-64-1:~ # file /opt/NetworkMiner_1-6-1/NetworkMiner.exe
/opt/NetworkMiner_1-6-1/NetworkMiner.exe: PE32 executable (GUI) Intel 80386 Mono/.Net assembly, for MS Windows
root@LTS-64-1:~ #
alert http any any -> any any (msg:"FILEMAGIC exe - PE32 executable (GUI) Intel for MS Windows "; filemagic:"PE32 executable"; sid:123456789; rev:2;)
Thanks