1# Example rules for using the file handling and extraction functionality in Suricata. 2# 3# For storing files make sure you enable the "file" output. 4# Also, make sure you read the comments that go with it in the suricata.yaml file. 5 6# Alert on files with jpg or bmp extensions 7#alert http any any -> any any (msg:"FILEEXT JPG file claimed"; fileext:"jpg"; sid:1; rev:1;) 8#alert http any any -> any any (msg:"FILEEXT BMP file claimed"; fileext:"bmp"; sid:3; rev:1;) 9 10# Store all files with jpg or pdf extension. 11#alert http any any -> any any (msg:"FILESTORE jpg"; flow:established,to_server; fileext:"jpg"; filestore; sid:6; rev:1;) 12#alert http any any -> any any (msg:"FILESTORE pdf"; flow:established,to_server; fileext:"pdf"; filestore; sid:8; rev:1;) 13 14# Store all PDF files, regardless of their name. 15#alert http any any -> any any (msg:"FILEMAGIC pdf"; flow:established,to_server; filemagic:"PDF document"; filestore; sid:9; rev:1;) 16 17# Same for JPEG's. 18#alert http any any -> any any (msg:"FILEMAGIC jpg(1)"; flow:established,to_server; filemagic:"JPEG image data"; filestore; sid:10; rev:1;) 19#alert http any any -> any any (msg:"FILEMAGIC jpg(2)"; flow:established,to_server; filemagic:"JFIF"; filestore; sid:11; rev:1;) 20 21# Unually short file 22#alert http any any -> any any (msg:"FILEMAGIC short"; flow:established,to_server; filemagic:"very short file (no magic)"; filestore; sid:12; rev:1;) 23 24# Simply store all files we encounter, no alerts. 25#alert http any any -> any any (msg:"FILE store all"; filestore; noalert; sid:15; rev:1;) 26 27# Store all JPG files, don't alert. 28#alert http any any -> any any (msg:"FILE magic"; filemagic:"JFIF"; filestore; noalert; sid:16; rev:1;) 29#alert http any any -> any any (msg:"FILE magic"; filemagic:"GIF"; filestore; noalert; sid:23; rev:1;) 30#alert http any any -> any any (msg:"FILE magic"; filemagic:"PNG"; filestore; noalert; sid:17; rev:1;) 31 32# Store all Windows executables 33#alert http any any -> any any (msg:"FILE magic -- windows"; flow:established,to_client; filemagic:"executable for MS Windows"; filestore; sid:18; rev:1;) 34 35# Alert on PNG with 1x1 pixels (tracking) 36#alert http any any -> any any (msg:"FILE tracking PNG (1x1 pixel) (1)"; filemagic:"PNG image data, 1 x 1,"; sid:19; rev:1;) 37#alert http any any -> any any (msg:"FILE tracking PNG (1x1 pixel) (2)"; filemagic:"PNG image data, 1 x 1|00|"; sid:20; rev:1;) 38 39# Alert on GIF with 1x1 pixels (tracking) 40# The pattern matches on |00| which is the end of the magic buffer, this way we won't match on 1 x 128. 41#alert http any any -> any any (msg:"FILE tracking GIF (1x1 pixel)"; filemagic:"GIF image data, version 89a, 1 x 1|00|"; sid:21; rev:1;) 42 43# Alert and store pdf attachment but not pdf file 44#alert http any any -> any any (msg:"FILE pdf claimed, but not pdf"; flow:established,to_client; fileext:"pdf"; filemagic:!"PDF document"; filestore; sid:22; rev:1;) 45 46# Alert and store files over SMTP 47#alert smtp any any -> any any (msg:"File Found over SMTP and stored"; filestore; sid:27; rev:1;) 48 49# Alert and store files from black list checksum: md5 or sha1 or sha256 50#alert http any any -> any any (msg:"Black list checksum match and extract MD5"; filemd5:fileextraction-chksum.list; filestore; sid:28; rev:1;) 51#alert http any any -> any any (msg:"Black list checksum match and extract SHA1"; filesha1:fileextraction-chksum.list; filestore; sid:29; rev:1;) 52#alert http any any -> any any (msg:"Black list checksum match and extract SHA256"; filesha256:fileextraction-chksum.list; filestore; sid:30; rev:1;) 53 54# Alert and store files over FTP 55#alert ftp-data any any -> any any (msg:"File Found within FTP and stored"; filestore; filename:"password"; ftpdata_command:stor; sid:31; rev:1;) 56 57# Alert and store files over SMB (with RUST activated) 58#alert smb any any -> any any (msg:"File Found over SMB and stored"; filestore; sid:32; rev:1;) 59 60# Alert and store files over NFS (with RUST activated) 61#alert nfs any any -> any any (msg:"File found within NFS and stored"; filestore; sid:33; rev:1;) 62