Snort Rule Development
alert tcp any any -> any any (msg:"Possible Ursnif C2 Activity"; flow:established,to_server; content:"/images/", depth 12; content:"_2F"; content:"_2B"; content:"User-Agent|3a 20|Mozilla/4.0 (compatible|3b| MSIE 8.0|3b| Windows NT"; content:!"Accept"; content:!"Cookie|3a|"; content:!"Referer|3a|"; sid:1000002; rev:1;)
The Snort rule above is created to detect certain variations of Ursnif malware. However, the rule is inefficient as it misses HTTP sticky buffers. Let's break down the essential parts of this rule to understand how it works.
flow:established,to_server; ensures that this rule only matches established TCP connections where data is flowing from the client to the server.content:"/images/", depth 12; instructs Snort to look for the string /images/ within the first 12 bytes of the packet payload.content:"_2F"; and content:"_2B"; direct Snort to search for the strings _2F and _2B anywhere in the payload.content:"User-Agent|3a 20|Mozilla/4.0 (compatible|3b| MSIE 8.0|3b| Windows NT"; is looking for a specific User-Agent. The |3a 20| and |3b| in the rule are hexadecimal representations of the : and ; characters respectively.content:!"Accept"; content:!"Cookie|3a|"; content:!"Referer|3a|"; look for the absence of certain standard HTTP headers, such as Accept, Cookie: and Referer:. The ! indicates negation.The above rule is already incorporated in the local.rules file found in the /home/htb-student directory of this section's target. To test it, first, you need to uncomment the rule. Then, execute Snort on the ursnif.pcap file, which is located in the /home/htb-student/pcaps directory.
Snort Rule Development
alert http$HOME_NET any -> $EXTERNAL_NET any (msg:"OISF TROJAN Targeted AutoIt FileStealer/Downloader CnC Beacon"; flow:established,to_server; http_method; content:"POST"; http_uri; content:".php?profile="; http_client_body; content:"ddager=", depth 7; http_client_body; content:"&r1=", distance 0; http_header; content:!"Accept"; http_header; content:!"Referer|3a|"; sid:10000006; rev:1;)
The Snort rule above is designed to detect certain variations of malware used by the Patchwork APT. Please notice the use of HTTP sticky buffers in this rule. Let's break down the important parts of this rule to understand its workings.
flow:established,to_server;: This keyword is used to specify the direction of the traffic we are interested in. In this case, we're looking at established connections where the traffic is going from the client to the server.http_method; content:"POST";: We are looking for HTTP traffic where the method used is POST.http_uri; content:".php?profile=";: This specifies that we're looking for HTTP URIs that contain the string .php?profile=.http_client_body; content:"ddager=", depth 7;: We're examining the body of the HTTP request. Specifically, we're looking for the string ddager= within the first 7 bytes of the body.http_client_body; content:"&r1=", distance 0;: We're still examining the body of the HTTP request, but now we're looking for the string &r1= immediately following the previous content match.http_header; content:!"Accept"; http_header; content:!"Referer|3a|";: These conditions are looking for the absence of the Accept and Referer HTTP headers. The ! before the content means not, so we're looking for situations where these headers are not present.