Showing posts with label Network Analysis. Show all posts
Showing posts with label Network Analysis. Show all posts

Monday, March 20, 2017

Cyber Security Analyst (Part 3 of 3)

Writing Snort Signatures

This series will cover analyzing the common data types found in cyber security incidents; Netflow,  Domain(s) & IP address(es), PCAP. The format of the posts will be as follows Background information, Concepts & Techniques, Tools, and Recommended reading and/or videos.


Background
Intrusion Detection Systems (IDS) perform network packet inspection for predefined criteria. Its capabilities are to alert and/or collect Packet Capture (PCAP) data related to the predefined criteria.

Overview
For the purpose of this blog we are going to be reviewing the Snort IDS. The information in this blog is design to help people create Snort signatures.

 When creating snort rules remember that you might not have complete inbound/outbound traffic sensor coverage of your network. The longer the duration of PCAP collection the larger the file.  Include documentation on why you are collecting/alerting on the information provided in your signature. Have a set review period for when you will re-evaluate the effectiveness of the signature based on the data collected and its false positive to true positive ratio.

Operators[1]
  • \ - used to indicate the end of a line.
  • Negation "!" - tells Snort to match any IP address except the one indicated by the listed IP address.
  • [] - are used in the "Rules Action" section to define a set.
  • () - the contents inside the parenthesis are the "Rule Options" section.
  • Range ":" - used to define a range of numbers for the rule to take action on. The start of the range goes on the left of the : The end on the right side.
  • Directional "->" - indicates the orientation or direction of the traffic that the rule applies to.
  • BiDirectional "<>" - tells Snort to consider the address/port pairs in either the source or destination orientation.

Basics
  • Most rules are single line.
  • To do multiple line rules use the backslash \ to end the line.
  • Rule are divided into two logical section, "Rule header" and "Rule Options".
  • Rule Header: contains the rule's action, protocol, source and destination IP addresses and netmask, and the source and destination ports information. The text up to the first parenthesis is the rule header.
  • Rule Option: contains alert messages and information on which parts of the packet should be inspected to determine if the rule actions should be taken. The contents enclosed in the parenthesis contains the rule options.
  • (Best Practices) Separate the "Rule header" and "Rule options" onto separate lines making it easier to view both sections.


Rule Components

Rule Header = (Action + Protocol + SourceIP + Source Port) Directional or BiDirectional notation (destIP + destport)

Rule Options = Message + Flow + Reference + Classtype + sid/rev

Snort  Rule equation = Rule Header + Rule Options



Rule Creation Steps

1. Rule action
  • Rule action(s) take effect on one of the supported protocols the user can specify.

  • There are 5 default "Rule Actions" available to in Snort:
  • Alert - generate an alert using the selected alert method, and then log the packet.
  • Log - log the packet.
  • Pass - ignore the packet.
  • Activate-alert and then turn on another dynamic rule.
  • Dynamic - remain idle until activated by an activate rule, then act as a log rule.

2. Protocols
  • After the "Rule Action" is chosen the next field in the rule is the "Protocol"
  • Snort analyzes the following protocols TCP, UDP, ICMP, and IP.

3. IP Address

  • The keyword "any" may be used to define any address.
  • Write IP addresses in numeric four octate format and include a CIDR block. 
  • (i.e. xxx.xxx.xxx.xxx/24)
  • CIDR block indicates the netmask (range of IP addresses) that should be applied to the rule's address and any incoming packets that are tested against the rule.

4. Port Numbers
  • After the "Protocol" is chosen the next field in the rule is the "Port Number".
  • The keyword "any" may be used to define any port number.

5. The Direction Operator
  • Directional -> - indicates the orientation or direction of the traffic that the rule applies to.
  • BiDirectional <> - tells Snort to consider the address/port pairs in either the source or destination orientation.


Detection Options[1]
Content
Allows the user to set rules that search for specific content in the packet payload and trigger response based on that data. Whenever a content option pattern match is performed, the Boyer-Moore pattern match function is called and the (rather computationally expensive) test is performed against the packet contents. If data exactly matching the argument data string is contained anywhere within the packets payload, the test is successful and the remainder of the rule option tests are performed.
Be aware that this test is case sensitive.
Options:
  • nocase
    • Used to specify that the Snort should look for the specific pattern, ignoring case.
  • rawbytes
    • Used to look at the raw packet data, ignoring any decoding that was done by pre-processors.
  • depth
    • Used to specify how far into a packet Snort should search for the specified pattern based on a chosen byte value.
    • only values greater than or equal to the pattern length can be searched. The minimum byte value is 1 and the maximum byte value is 65535.
    • Syntax:
      • depth: [<number>|<var_name>]
  • offset
    • Used to specify where to start searching for a pattern within a packet based on a chosen byte value.
    • The byte ranges from -65535 to 65535.
    • Syntax:
      • offset:[<number>|<var_name>]
  • distance
    • Used to specify how far into a packet Snort should ignore before starting to search for the specified pattern relative to the end of the previous pattern match.
    • syntax:
    • distance:[<byte_count>|<var_name>]
  • within
    • Used to make sure that at most N bytes are between pattern matches using the content keyword.
    • Syntax:
      • within:[<byte_count>|<var_name>]
  • http_client_body
    • Used to restrict the search to the body of an HTTP client request.
    • Syntax:
      • http_client_body


References
1. Snort


Social Media
Facebook:
https://www.facebook.com/BDavisCS/

Twitter:
@BDavis_CyberSec


Wednesday, March 1, 2017

Cyber Security Analyst (Part 2 of 3)

PCAP Data Analysis

This series will cover analyzing the common data types found in cyber security incidents; Netflow,  Domain(s) & IP address(es), PCAP. The format of the posts will be as follows Background information, Concepts & Techniques, Tools, and Recommended reading and/or videos.



The information in this blog is design to help people analyzing PCAP data. There are many programs which can automate the manipulation and organization of PCAP data for the end user. I believe it is always a good idea to know how to perform these task manually because every environment will be different. For the purpose of this blog post we'll be covering the use of open source PCAP analysis tool Wireshark.


Tools
The list tool is a free open source tool for Linux and Windows:



Background
Having a working understanding of the PCAP filters are essential to being able to read PCAP data.

A. Wireshark  Filters [1]
1. HTTP header information
  • Description: used to analyze the packet HTTP header information
  • Syntax:
    • http."option"
    • Commonly used "option(s)"
      • http.user_agent
      • http.response
      • http.connection
  2. TCP session information
  • Description: used to analyze the packet TCP session information
  • Syntax:
    • tcp."option(s)"
    • Commonly used "option(s)"
      • tcp.analysis.flags
      • tcp.flags
      • tcp.srcport
3. SSL connection
  • Description: used to determine if an SSL connection was established.
  • Syntax
    •  
    • Commonly used "option(s)"
      • ssl.handshake
4.  System communications
  • Description: used to determine who the system is trying to communicate with and how often.
  • Syntax:
    • dns."option(s)"."option(s)"
    • Commonly used "option(s)"
      • dns.qry.name
      • dns.resp.addr
      • dns.resp.name
5. Text search
  • Description: used to search for specific text inside of a packet.
  • Syntax:
    • frame contains "text"
    • Common text to search for
      • "Dos"
      • ".exe"



Concepts & Techniques
Two things to look for in PCAP when looking for signs of potential malicious activity are magic numbers and Base64.

A. Magic Numbers [2]
Common in programs across many operating systems. Magic numbers implement strongly typed data and are a form of in-band signaling to the controlling program that reads the data type(s) at program run-times. Detecting such constraints in files is a simple and effective way of distinguishing between many file formats and can yield further run-time information.
  • GIF image file:
    • ASCII cod 
      • "GIF89a" (47 49 46 38 39 61) 
      • "GIF87a" (47 49 46 38 37 61)
  • JPEG image file:
    • Begins with "FF D8" and ends with "FF D9"
  • Postscript file:
    • start with "%!" (25 21)
  • MS-DOS exe file:
    • start with 
      • "MZ" (4D 5A)
      • "ZM" (5A 4D) - is NOT as common
B. Base64 [3]
A group of similar encoding schemes that represent binary data in an ASCII string format by translating it into a Radix-64 representation. Base64 encoding schemes are commonly used when there is a need to encode binary that needs to be stored and transferred over media that are designed to deal with textual data. This is done to ensure that the data remains intact without modification during transport.
  • Characters [A-Z], [a-z],[0-9],[+],[/]
  • Padding: 
    • "==" indicates last group contained only 1 bytes. 
    • "=" indicates that it contained 2 bytes.




References 
  1. Wireshark Filters
  2. Magic Numbers
  3. Base64




Recommended Reading and/or Videos
  • Real Digital Forensics: Computer Security and Incident Response by Keith J. Jones, Richard Bejtlich, and Curtis W. Rose.
  • Extrusion Detection: Security Monitoring for Internal Intrusions by Richard Bejtlich, foreword by Marcus Ranum.
 
Social Media
Facebook:
https://www.facebook.com/BDavisCS/

Twitter:
@BDavis_CyberSec

Sunday, January 22, 2017

Cyber Security Analyst (Part 1 of 3)

Netflow Data Analysis
This series will cover analyzing the common data types found in cyber security incidents; Netflow,  Domain(s) & IP address(es), PCAP. The format of the posts will be as follows Background information, Concepts & Techniques, Tools, and Recommended reading and/or videos. 



The information in this blog is design to help people analyzing Netflow data. There are many programs which can automate the manipulation and organization of Netflow data for the end user. I believe it is always a good idea to know how to perform these task manually because every environment will be different.



Background
Having a working understanding of the Threeway Handshake, Session Flags, Port Numbers, and Domain Name System (DNS) are essential to being able to read Netflow data.

A. Threeway Handshake
  • Threeway Handshake is used to establish a connection between a client and a server. 
  • Client is a device which request services. 
  • Server is a provider of services to clients. 
  • Threeway Handshake Process: 
    1. Client sends a "SYN" flag to the server  
    2. Server responses with "SYN-ACK"   
    3. Client sends a "ACK" flag  
    4. The connection is now complete. 

B. Session Flags [1]
  • URG (1 bit)  indicates that the Urgent pointer field is significant 
  • ACK (1 bit)  indicates that the Acknowledgment field is significant. All packets after the initial SYN packet sent by the client should have this flag set. 
  • PSH (1 bit)  Push function. Asks to push the buffered data to the receiving application. 
  • RST (1 bit)  Reset the connection SYN (1 bit)  Synchronize sequence numbers. Only the first packet sent from each end should have this flag set. Some other flags change meaning based on this flag, and some are only valid for when it is set, and others when it is clear. 
  • FIN (1 bit)  No more data from sender

C. Port Numbers [2]
  • Port Numbers can be linked to certain applications and services to give one a better idea of the type of activity which is occurring during the communication they are observing. 
  • Port number: 1 - 1023 well know server services. 
  • Port numbers 1024 - 5000 ephemeral port numbers. 
  • An ephemeral port is a short-lived transport protocol port for Internet Protocol (IP) communications allocated automatically from a predefined range by the TCP/IP software.


D.  Domain Naming System (DNS)
  • DNS interactions are required for all internet activity.
  • DNS Process:
    1. Client issues a DNS query.
    2. A DNS Server accepts the query.
    3. If the first DNS server does not know the answer to the query request, then it will ask additional DNS servers.
    4. When the DNS server receives the answer to the DNS query, it returns the Domain to the client.



Concepts & Techniques
The Netflow data is used to confirm activity through correlation of information across different mediums. For example correlating network traffic with system logs to determine what the system was doing at the specific point in time. When analyzing Netflow data keep the following in mind:
  • Netflow data can be queried like a database.
  • Organize the data according to the "Time" field preferably the start time option. 
  • You may not be able to see the complete session due to network a lack of network coverage.
  • Go back a week or a month from the initial date of the suspicious traffic in order to try and establish a normal behavioral pattern to compare the infected system to. 
  • A few common attacks that can be observed in Netflow:
    • Beaconing
    • DDoS
    • TCP Reset attack
 

Tools
The list tools are free open source tools for Linux and Windows respectively:
These tools will allow you to capture Netflow data from the network interface of your PC. I recommend practicing observing the Netflow data from your PC while it is idle in order to see which services are continuously communicating with the internet and browsing the web.


Recommended Reading and/or Videos
  • Real Digital Forensics: Computer Security and Incident Response by Keith J. Jones, Richard Bejtlich, and Curtis W. Rose.
  • Extrusion Detection: Security Monitoring for Internal Intrusions by Richard Bejtlich, foreword by Marcus Ranum.



References 
  1. Transmission Control Protocol
  2. Ephemeral Port
Social Media
Facebook:
https://www.facebook.com/BDavisCS/

Twitter:
@BDavis_CyberSec