
- •Network Intrusion Detection, Third Edition
- •Table of Contents
- •Copyright
- •About the Authors
- •About the Technical Reviewers
- •Acknowledgments
- •Tell Us What You Think
- •Introduction
- •Chapter 1. IP Concepts
- •Layers
- •Data Flow
- •Packaging (Beyond Paper or Plastic)
- •Bits, Bytes, and Packets
- •Encapsulation Revisited
- •Interpretation of the Layers
- •Addresses
- •Physical Addresses, Media Access Controller Addresses
- •Logical Addresses, IP Addresses
- •Subnet Masks
- •Service Ports
- •IP Protocols
- •Domain Name System
- •Routing: How You Get There from Here
- •Summary
- •Chapter 2. Introduction to TCPdump and TCP
- •TCPdump
- •TCPdump Behavior
- •Filters
- •Binary Collection
- •TCPdump Output
- •Absolute and Relative Sequence Numbers
- •Dumping in Hexadecimal
- •Introduction to TCP
- •Establishing a TCP Connection
- •Server and Client Ports
- •Connection Termination
- •The Graceful Method
- •The Abrupt Method
- •Data Transfer
- •What's the Bottom Line?
- •TCP Gone Awry
- •An ACK Scan
- •A Telnet Scan?
- •TCP Session Hijacking
- •Summary
- •Chapter 3. Fragmentation
- •Theory of Fragmentation
- •All Aboard the Fragment Train
- •The Fragment Dining Car
- •The Fragment Caboose
- •Viewing Fragmentation Using TCPdump
- •Fragmentation and Packet-Filtering Devices
- •The Don't Fragment Flag
- •Malicious Fragmentation
- •TCP Header Fragments
- •Teardrop
- •Summary
- •Chapter 4. ICMP
- •ICMP Theory
- •Why Do You Need ICMP?
- •Where Does ICMP Fit In?
- •Understanding ICMP
- •Summary of ICMP Theory
- •Mapping Techniques
- •Tireless Mapper
- •Efficient Mapper
- •Clever Mapper
- •Cerebral Mapper
- •Summary of Mapping
- •Normal ICMP Activity
- •Host Unreachable
- •Port Unreachable
- •Admin Prohibited
- •Need to Frag
- •Time Exceeded In-Transit
- •Embedded Information in ICMP Error Messages
- •Summary of Normal ICMP
- •Malicious ICMP Activity
- •Smurf Attack
- •Tribe Flood Network
- •WinFreeze
- •Loki
- •Unsolicited ICMP Echo Replies
- •Theory 1: Spoofing
- •Theory 2: TFN
- •Theory 3: Loki
- •Summary of Malicious ICMP Traffic
- •To Block or Not to Block
- •Unrequited ICMP Echo Requests
- •Kiss traceroute Goodbye
- •Silence of the LANs
- •Broken Path MTU Discovery
- •Summary
- •Chapter 5. Stimulus and Response
- •The Expected
- •Request for Comments
- •TCP Stimulus-Response
- •Destination Host Listens on Requested Port
- •Destination Host Not Listening on Requested Port
- •Destination Host Doesn't Exist
- •Destination Port Blocked
- •Destination Port Blocked, Router Doesn't Respond
- •UDP Stimulus-Response
- •Destination Host Listening on Requested Port
- •Destination Host Not Listening on Requested Port
- •Windows tracert
- •TCPdump of tracert
- •Protocol Benders
- •Active FTP
- •Passive FTP
- •UNIX Traceroute
- •Summary of Expected Behavior and Protocol Benders
- •Abnormal Stimuli
- •Evasion Stimulus, Lack of Response
- •Evil Stimulus, Fatal Response
- •No Stimulus, All Response
- •Unconventional Stimulus, Operating System Identifying Response
- •Bogus "Reserved" TCP Flags
- •Anomalous TCP Flag Combinations
- •No TCP Flags
- •Summary of Abnormal Stimuli
- •Summary
- •Chapter 6. DNS
- •Back to Basics: DNS Theory
- •The Structure of DNS
- •Steppin' Out on the Internet
- •DNS Resolution Process
- •TCPdump Output of Resolution
- •Strange TCPdump Notation
- •Caching: Been There, Done That
- •Reverse Lookups
- •Master and Slave Name Servers
- •Zone Transfers
- •Summary of DNS Theory
- •Using DNS for Reconnaissance
- •The nslookup Command
- •Name That Name Server
- •HINFO: Snooping for Details
- •List Zone Map Information
- •Tainting DNS Responses
- •A Weak Link
- •Cache Poisoning
- •Summary
- •Part II: Traffic Analysis
- •Chapter 7. Packet Dissection Using TCPdump
- •Why Learn to Do Packet Dissection?
- •Sidestep DNS Queries
- •Normal Query
- •Evasive Query
- •Introduction to Packet Dissection Using TCPdump
- •Where Does the IP Stop and the Embedded Protocol Begin?
- •Other Length Fields
- •The IP Datagram Length
- •Increasing the Snaplen
- •Dissecting the Whole Packet
- •Freeware Tools for Packet Dissection
- •Ethereal
- •tcpshow
- •Summary
- •Chapter 8. Examining IP Header Fields
- •Insertion and Evasion Attacks
- •Insertion Attacks
- •Evasion Attacks
- •IP Header Fields
- •IP Version Number
- •Protocol Number
- •The Don't Fragment (DF) Flag
- •The More Fragments (MF) Flag
- •Mapping Using Incomplete Fragments
- •IP Numbers
- •IP Identification Number
- •Time to Live (TTL)
- •Looking at the IP ID and TTL Values Together to Discover Spoofing
- •IP Checksums
- •Summary
- •Chapter 9. Examining Embedded Protocol Header Fields
- •Ports
- •TCP Checksums
- •TCP Sequence Numbers
- •Acknowledgement Numbers
- •TCP Flags
- •TCP Corruption
- •ECN Flag Bits
- •Operating System Fingerprinting
- •Retransmissions
- •Using Retransmissions Against a Hostile Host—LaBrea Tarpit Version 1
- •TCP Window Size
- •LaBrea Version 2
- •Ports
- •UDP Port Scanning
- •UDP Length Field
- •ICMP
- •Type and Code
- •Identification and Sequence Numbers
- •Misuse of ICMP Identification and Sequence Numbers
- •Summary
- •Chapter 10. Real-World Analysis
- •You've Been Hacked!
- •Netbus Scan
- •How Slow Can you Go?
- •RingZero Worm
- •Summary
- •Chapter 11. Mystery Traffic
- •The Event in a Nutshell
- •The Traffic
- •DDoS or Scan
- •Source Hosts
- •Destination Hosts
- •Scanning Rates
- •Fingerprinting Participant Hosts
- •Arriving TTL Values
- •TCP Window Size
- •TCP Options
- •TCP Retries
- •Summary
- •Part III: Filters/Rules for Network Monitoring
- •Chapter 12. Writing TCPdump Filters
- •The Mechanics of Writing TCPdump Filters
- •Bit Masking
- •Preserving and Discarding Individual Bits
- •Creating the Mask
- •Putting It All Together
- •TCPdump IP Filters
- •Detecting Traffic to the Broadcast Addresses
- •Detecting Fragmentation
- •TCPdump UDP Filters
- •TCPdump TCP Filters
- •Filters for Examining TCP Flags
- •Detecting Data on SYN Connections
- •Summary
- •Chapter 13. Introduction to Snort and Snort Rules
- •An Overview of Running Snort
- •Snort Rules
- •Snort Rule Anatomy
- •Rule Header Fields
- •The Action Field
- •The Protocol Field
- •The Source and Destination IP Address Fields
- •The Source and Destination Port Field
- •Direction Indicator
- •Summary
- •Chapter 14. Snort Rules - Part II
- •Format of Snort Options
- •Rule Options
- •Msg Option
- •Logto Option
- •Ttl Option
- •Id Option
- •Dsize Option
- •Sequence Option
- •Acknowledgement Option
- •Itype and Icode Options
- •Flags Option
- •Content Option
- •Offset Option
- •Depth Option
- •Nocase Option
- •Regex Option
- •Session Option
- •Resp Option
- •Tag Option
- •Putting It All Together
- •Summary
- •Part IV: Intrusion Infrastructure
- •Chapter 15. Mitnick Attack
- •Exploiting TCP
- •IP Weaknesses
- •SYN Flooding
- •Covering His Tracks
- •Identifying Trust Relationships
- •Examining Network Traces
- •Setting Up the System Compromise?
- •Detecting the Mitnick Attack
- •Trust Relationship
- •Port Scan
- •Host Scan
- •Connections to Dangerous Ports
- •TCP Wrappers
- •Tripwire
- •Preventing the Mitnick Attack
- •Summary
- •Chapter 16. Architectural Issues
- •Events of Interest
- •Limits to Observation
- •Human Factors Limit Detects
- •Limitations Caused by the Analyst
- •Limitations Caused by the CIRTs
- •Severity
- •Criticality
- •Lethality
- •Countermeasures
- •Calculating Severity
- •Scanning for Trojans
- •Analysis
- •Severity
- •Host Scan Against FTP
- •Analysis
- •Severity
- •Sensor Placement
- •Outside Firewall
- •Sensors Inside Firewall
- •Both Inside and Outside Firewall
- •Analyst Console
- •Faster Console
- •False Positive Management
- •Display Filters
- •Mark as Analyzed
- •Drill Down
- •Correlation
- •Better Reporting
- •Event-Detection Reports
- •Weekly/Monthly Summary Reports
- •Summary
- •Chapter 17. Organizational Issues
- •Organizational Security Model
- •Security Policy
- •Industry Practice for Due Care
- •Security Infrastructure
- •Implementing Priority Countermeasures
- •Periodic Reviews
- •Implementing Incident Handling
- •Defining Risk
- •Risk
- •Accepting the Risk
- •Trojan Version
- •Malicious Connections
- •Mitigating or Reducing the Risk
- •Network Attack
- •Snatch and Run
- •Transferring the Risk
- •Defining the Threat
- •Recognition of Uncertainty
- •Risk Management Is Dollar Driven
- •How Risky Is a Risk?
- •Quantitative Risk Assessment
- •Qualitative Risk Assessments
- •Why They Don't Work
- •Summary
- •Chapter 18. Automated and Manual Response
- •Automated Response
- •Architectural Issues
- •Response at the Internet Connection
- •Internal Firewalls
- •Host-Based Defenses
- •Throttling
- •Drop Connection
- •Shun
- •Proactive Shunning
- •Islanding
- •Reset
- •Honeypot
- •Proxy System
- •Empty System
- •Honeypot Summary
- •Manual Response
- •Containment
- •Freeze the Scene
- •Sample Fax Form
- •On-Site Containment
- •Site Survey
- •System Containment
- •Hot Search
- •Eradication
- •Recovery
- •Lessons Learned
- •Summary
- •Chapter 19. Business Case for Intrusion Detection
- •Part One: Management Issues
- •Bang for the Buck
- •The Expenditure Is Finite
- •Technology Used to Destabilize
- •Network Impacts
- •IDS Behavioral Modification
- •The Policy
- •Part of a Larger Strategy
- •Part Two: Threats and Vulnerabilities
- •Threat Assessment and Analysis
- •Threat Vectors
- •Threat Determination
- •Asset Identification
- •Valuation
- •Vulnerability Analysis
- •Risk Evaluation
- •Part Three: Tradeoffs and Recommended Solution
- •Identify What Is in Place
- •Identify Your Recommendations
- •Identify Options for Countermeasures
- •Cost-Benefit Analysis
- •Follow-On Steps
- •Repeat the Executive Summary
- •Summary
- •Chapter 20. Future Directions
- •Increasing Threat
- •Improved Targeting
- •How the Threat Will Be Manifested
- •Defending Against the Threat
- •Skills Versus Tools
- •Analysts Skill Set
- •Improved Tools
- •Defense in Depth
- •Emerging Techniques
- •Virus Industry Revisited
- •Smart Auditors
- •Summary
- •Part V: Appendixes
- •Appendix A. Exploits and Scans to Apply Exploits
- •False Positives
- •All Response, No Stimulus
- •Scan or Response?
- •SYN Floods
- •Valid SYN Flood
- •False Positive SYN Flood
- •Back Orifice?
- •IMAP Exploits
- •10143 Signature Source Port IMAP
- •111 Signature IMAP
- •Source Port 0, SYN and FIN Set
- •Source Port 65535 and SYN FIN Set
- •DNS Zone Followed by 0, SYN FIN Targeting NFS
- •Scans to Apply Exploits
- •mscan
- •Son of mscan
- •Access Builder?
- •Single Exploit, Portmap
- •rexec
- •Targeting SGI Systems?
- •Discard
- •Weird Web Scans
- •IP-Proto-191
- •Summary
- •Appendix B. Denial of Service
- •Brute-Force Denial-of-Service Traces
- •Smurf
- •Directed Broadcast
- •Echo-Chargen
- •Elegant Kills
- •Teardrop
- •Land Attack
- •We're Doomed
- •nmap
- •Distributed Denial-of-Service Attacks
- •Intro to DDoS
- •DDoS Software
- •Trinoo
- •Stacheldraht
- •Summary
- •Appendix C. Detection of Intelligence Gathering
- •Network and Host Mapping
- •Host Scan Using UDP Echo Requests
- •Netmask-Based Broadcasts
- •Port Scan
- •Scanning for a Particular Port
- •Complex Script, Possible Compromise
- •"Random" Port Scan
- •Database Correlation Report
- •SNMP/ICMP
- •FTP Bounce
- •NetBIOS-Specific Traces
- •A Visit from a Web Server
- •Null Session
- •Stealth Attacks
- •Explicit Stealth Mapping Techniques
- •FIN Scan
- •Inverse Mapping
- •Answers to Domain Queries
- •Answers to Domain Queries, Part 2
- •Fragments, Just Fragments
- •Measuring Response Time
- •Echo Requests
- •Actual DNS Queries
- •Probe on UDP Port 33434
- •3DNS to TCP Port 53
- •Worms as Information Gatherers
- •Pretty Park Worm
- •RingZero
- •Summary

4.Represent each hex character as an increasing power of 16 (160 through 163).
5.Multiply each base by exponent and add all individual products.
163 |
162 |
161 |
160 |
0 |
0 |
5 |
4 |
5*161 + 4*160 = 84
In the previous example, we are looking at the length field. We have 4 hex characters because the length is a 16-bit field. We really only need to label the two rightmost hex characters because they are non-zero. After we do this, we find we have a 4 in the 160 position; this is really the 1's position meaning we have 4*1 or 4. The next character of 5 is in the 161 position. So, we multiply 5*16 for a product of 80. We add these two products together to get the final result of 84.
TCP Header Length
Like the IP header, the TCP header can also have options. Also, like the IP header length, the TCP header length is found in a nibble that is a representation of 32-bit words. This value, like the IP header length value, must be multiplied by 4 to get the TCP header length. A TCP header with no options is 20 bytes long. The TCP header length is found in the high-order nibble of the 12th byte offset of the TCP header. This is an important value because it determines where the TCP header stops and where the TCP payload begins.
Here is standard output followed by the hex output from a TCP header with no TCP options:
15:43:40.705372 1.2.3.4.63220 > 4.3.2.1.139: S 776342897:776342897(0) win 3072
4500 0028 e34f 0000 3a06 e534 0102 0304
0403 0201 <f6f4 008b 2e46 0d71 0000 0000
5002 0c00 b85f 0000>
The TCP segment is delimited by the less than and greater than signs. The highlighted value is the TCP header length, and as expected, we find a 5. After we multiply that by 4, we get a standard TCP header of 20 bytes.
Now, look at the hex output for a TCP header with TCP options:
15:48:24.620314 1.2.3.4.3088 > 4.3.2.1:139 S 1212214992:1212214992(0) win 32120 <mss 1460,sackOK,timestamp 7748460 0,nop,wscale 0> (DF)
4500 003c 11a8 4000 4006 70c8 0102 0304
0102 0304 <0c10 008b 4840 eed0 0000 0000 a002 7d78 92b4 0000 0204 05b4 0402 080a 0076 3b6c 0000 0000 0103 0300>
You see that it has a TCP header length of 0xa, which is a decimal 10. This value multiplied by 4 indicates a TCP header length of 40 bytes. If you look at the standard TCPdump output before the hex dump, you see that this TCP header includes such options as maximum segment size of 1460, selective acknowledgement (sackOK), timestamp, a nop (no operation) to pad to a 4-byte boundary, and a window scale (wscale). These options need to be stored in the TCP header.
Increasing the Snaplen
Here's a question: Why do you only see 54 bytes of output in the following hex output displayed even though the default number of bytes capture is 68? Check it out:
4500 0054 064b 0000 4001 bc12 c0a8 8f05 c0a8 8f65 0800 620a 850a 0000 889f 4b39 510f 0100 0809 0a0b 0c0d 0e0f 1011 1213 1415 1617 1819
The answer is that TCPdump captures 14 bytes of the Ethernet frame header, yet it does not display them unless explicitly directed. To display the captured frame header use the command tcpdump –e:
20:55:48.520619 0:10:b5:39:c6:93 0:10:b5:39:c6:9a ip 102 192.168.143.5 > 192.168.143.101: icmp: echo request
There will be times that you will be interested in examining the frame header. One of the reasons for this would be to identify the source MAC address to try to determine where the packet came from—a host or perhaps a router.
In the previous output, which uses Ethernet encapsulation defined by RFC 894, the bolded text is a result of the –e option. First, you see the source and destination MAC addresses (source MAC of 0:10:b5:39:c6:93 and destination MAC address of 0:10:b5:39:c6:9a). You might be thinking that these are bogus MAC addresses because they are so close together, but they are genuine MAC addresses. These are two Compaq PCs ordered at the same time. The MAC addresses are followed by the type of packet that follows the frame header. Some of the types of traffic you are likely to see are IP, ARP, and RARP (reverse ARP). These fields are all stored in the frame header. The final displayed field is the length, in bytes, of the entire frame including the frame header and the data in the encapsulated frame header. In this case, it is a frame header of 14 bytes and a following IP datagram of 88 bytes to give 102. A value of 0x0800 in the type field indicates an IP datagram follows the frame header. The IP packet must be at least 46 bytes in length and the frame length information is not contained anywhere in the Ethernet RFC 894 frame header. The snapshot length, or snaplen for short, is the number of bytes that TCPdump collects. The default snaplen of 68 bytes is usually enough to capture the IP header, embedded protocol header, and some data. But, if there are many options, either IP header options or TCP options, all of the headers might not be captured.
If you want to increase the default snaplen, use the –s TCPdump command line option. As a test case, let's say we want to capture the entire datagram for each record we read or process on an Ethernet network. In this case, we need to increase the snaplen to the maximum size of the datagram plus the frame header. Ethernet has a maximum transmission unit of 1500. If you add 14 bytes for the frame header, the snaplen must be 1514 bytes—tcpdump –s 1514. Now, to check if we've collected the entire datagram, we run TCPdump with a snaplen of 1514:
4500 0054 064b 0000 4001 bc12 c0a8 8f05
c0a8 8f65 0800 620a 850a 0000 889f 4b39 510f 0100 0809 0a0b 0c0d 0e0f 1011 1213
1415 1617 1819 1a1b 1c1d 1e1f 2021 2223
2425 2627 2829 2a2b 2c2d 2e2f 3031 3233
3435 3637
If we dump the collected record in hexadecimal, we find we've collected more than the default 54 bytes. The actual datagram length is found in the 2nd and 3rd bytes offset of the IP header. We discover a hex 54 in this field, which we recently computed is a decimal 84 bytes. And, we see that we've collected all 84 bytes.
Dissecting the Whole Packet
We have covered all the fundamentals required to dissect a packet. Okay, get the scalpel out and let's see if we can attempt a couple of IP packet dissections. Here's a short review of what we need to do to accomplish our dissection:
●Identify the embedded protocol in the packet. This is found in the 9th byte offset of the IP header.
●Determine what the embedded protocol is based on the value found.
●Identify where the header(s) stop(s), and examine the IP header length.
Tells where the IP header stops and the embedded protocol begins.
●Examine the embedded protocol header length
Tells where the embedded protocol payload begins.
One of the first steps in discovering what type of activity is embedded in the datagram is to discern the embedded protocol. Remember, you have an IP header and you will find the embedded protocol in the 9th byte offset into the IP header. Remember that the most common values you will see here are 01 for an embedded ICMP message, 06 for an embedded TCP segment, and a hex 11 or decimal 17 for an embedded UDP datagram.
After you've discovered this, you need to know how many bytes are in the IP header. Usually, this is 20 bytes, but it can be more if there are IP options. The IP header length field is found in the low-order nibble of the 0 byte offset of the IP header. Remember that this is expressed as a 32-bit word, so this value has to be multiplied by 4 to translate to bytes. If you count off this number of bytes into the IP header, you will discover where the IP header stops and the embedded protocol begins.
Next, you need to examine the embedded protocol. You'll have to get the proper header configuration for the protocol and translate the values that you find in the hexadecimal output. For UDP, the header length remains static at 8 and the payload follows. But, a header has a different format depending if the protocol is ICMP, TCP, or UDP.
TCP header lengths can vary, so you'll have to find the TCP header length field. This is 12 bytes offset into the TCP header, specifically, the high-order nibble. Again, like the IP header length, this is expressed as a 32-bit word and the value will have to be multiplied by 4 to convert it to bytes. This informs you where the TCP header stops and the payload starts.
Here is the hex dump of our specimen for dissection:
4500 0054 f23b 4000 ff01 d121 0102 0304
0403 0201 0000 9f00 d646 0000 b4cb 863a 56af 0e00 0809 0a0b 0c0d 0e0f 1011 1213
1415 1617 1819 1a1b 1c1d 1e1f 2021 2223
2425 2627 2829 2a2b 2c2d 2e2f 3031 3233
3435 3637 0000 4e00
Let's approach this in two different parts. In the first part, we'll attempt to discover the

embedded protocol and the length of the IP header. We see that the embedded protocol is ICMP because we have a 0x01 value (bolded) in the protocol field 9 bytes offset into the IP header. That indicates that an ICMP echo reply message follows the IP header (last 2 bytes of 0201). Because the IP header is 20 bytes, we discover where the IP header stops and the ICMP header and data begin. The ICMP header begins at the 2 bytes 0000 following the final 2 bytes of the IP header.
In our second step of dissection, we need to examine the ICMP message header. Remember that each individual character you see in the hex output represents a nibble or 4 bits. So, two hex characters are one byte. Use Figure 7.2 to assist in decoding the ICMP message.
Figure 7.2. ICMP header layout.
When examining ICMP, the ICMP header format can vary depending on the ICMP message type and code. The first two bytes of the ICMP header are really pertinent when trying to assess what type of ICMP message you have. These are the message type and message code fields. There are many possible different values for these fields that can be found at www.iana.org/assignments/icmp-protocols; however, we see a very common one in the above record. An ICMP message with a type of 00 and a code of 00 is an ICMP echo reply. The standard TCPdump
output for this output is as follows:
1.2.3.4 > 4.3.2.1: icmp: echo reply (DF)
Let's try one more exercise in packet dissection:
4500 0030 df3c 4000 8006 633f 0102 0304
0403 0201 0b64 0015 48f3 05b1 0000 0000
7002 2000 50b6 0000 0204 05b4 0101 0402
This is a different protocol than ICMP. What is of most interest is the embedded protocol destination port. This tells you the purpose of this particular packet. Although the TCP and UDP headers are different, they share a similar characteristic of having the source port in bytes 0 and 1 offset of the embedded header and the destination port in bytes 2 and 3 offset of the embedded header.
Once again, we find an IP datagram with a 20-byte IP header. But, this time we find that we have TCP as the embedded protocol as ascertained by looking at the bolded protocol field in the previous hex dump.
The significant piece of information that helps us assess the function of the TCP segment is the destination port. This is found in the bolded value of 0015 positioned in offset bytes 2 and 3 of the TCP header.
We determine that the decimal translation is port 21, which is ftp. The destination port field has