Intrusion Detection Systems with Snort Advanced IDS Techniques Using Snort, Apache, Mysql, PHP, and ACID
Total Page:16
File Type:pdf, Size:1020Kb
Intrusion Detection Systems with Snort Advanced IDS Techniques Using Snort, Apache, MySQL, PHP, and ACID perens_series.fm Page 1 Thursday, April 10, 2003 1:43 AM BRUCE PERENS’ OPEN SOURCE SERIES ◆ Managing Linux Systems with Webmin: System Administration and Module Development Jamie Cameron ◆ Implementing CIFS: The Common Internet File System Christopher R. Hertel ◆ Embedded Software Development with eCos Anthony J. Massa ◆ The Linux Development Platform: Configuring, Using, and Maintaining a Complete Programming Environment Rafeeq Ur Rehman, Christopher Paul ◆ Intrusion Detection Systems with Snort: Advanced IDS Techniques with Snort, Apache, MySQL, PHP, and ACID Rafeeq Ur Rehman Intrusion Detection Systems with Snort Advanced IDS Techniques Using Snort, Apache, MySQL, PHP, and ACID Rafeeq Ur Rehman Prentice Hall PTR Upper Saddle River, New Jersey 07458 www.phptr.com Library of Congress Cataloging-in-Publication Data A CIP catalog record for this book can be obtained from the Library of Congress. Editorial/production supervision: Mary Sudul Cover design director: Jerry Votta Cover design: DesignSource Manufacturing manager: Maura Zaldivar Acquisitions editor: Jill Harry Editorial assistant: Noreen Regina Marketing manager: Dan DePasquale © 2003 Pearson Education, Inc. Publishing as Prentice Hall PTR Upper Saddle River, New Jersey 07458 This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at <http://www.opencontent.org/openpub/>). Prentice Hall books are widely used by corporations and government agencies for training, marketing, and resale. The publisher offers discounts on this book when ordered in bulk quantities. For more information, contact Corporate Sales Department, Phone: 800-382-3419; FAX: 201-236-7141; E-mail: [email protected] Or write: Prentice Hall PTR, Corporate Sales Dept., One Lake Street, Upper Saddle River, NJ 07458. Other product or company names mentioned herein are the trademarks or registered trademarks of their respective owners. Printed in the United States of America 1st Printing ISBN 0-13-140733-3 Pearson Education LTD. Pearson Education Australia PTY, Limited Pearson Education Singapore, Pte. Ltd. Pearson Education North Asia Ltd. Pearson Education Canada, Ltd. Pearson Educación de Mexico, S.A. de C.V. Pearson Education — Japan Pearson Education Malaysia, Pte. Ltd. To open source and free software developers C ONTENTS Chapter 1 Introduction to Intrusion Detection and Snort 1 1.1 What is Intrusion Detection? 5 1.1.1 Some Definitions 6 1.1.2 Where IDS Should be Placed in Network Topology 8 1.1.3 Honey Pots 9 1.1.4 Security Zones and Levels of Trust 10 1.2 IDS Policy 10 1.3 Components of Snort 12 1.3.1 Packet Decoder 13 1.3.2 Preprocessors 13 1.3.3 The Detection Engine 14 1.3.4 Logging and Alerting System 15 1.3.5 Output Modules 15 1.4 Dealing with Switches 16 1.5 TCP Stream Follow Up 18 1.6 Supported Platforms 18 1.7 How to Protect IDS Itself 19 1.7.1 Snort on Stealth Interface 20 1.7.2 Snort with no IP Address Interface 20 1.8 References 21 vii viii Contents Chapter 2 Installing Snort and Getting Started 23 2.1 Snort Installation Scenarios 24 2.1.1 Test Installation 24 2.1.2 Single Sensor Production IDS 24 2.1.3 Single Sensor with Network Management System Integration 25 2.1.4 Single Sensor with Database and Web Interface 25 2.1.5 Multiple Snort Sensors with Centralized Database 26 2.2 Installing Snort 28 2.2.1 Installing Snort from the RPM Package 28 2.2.2 Installing Snort from Source Code 29 2.2.3 Errors While Starting Snort 43 2.2.4 Testing Snort 43 2.2.5 Running Snort on a Non-Default Interface 51 2.2.6 Automatic Startup and Shutdown 52 2.3 Running Snort on Multiple Network Interfaces 54 2.4 Snort Command Line Options 55 2.5 Step-By-Step Procedure to Compile and Install Snort From Source Code 56 2.6 Location of Snort Files 56 2.7 Snort Modes 58 2.7.1 Network Sniffer Mode 58 2.7.2 Network Intrusion Detection Mode 65 2.8 Snort Alert Modes 66 2.8.1 Fast Mode 67 2.8.2 Full Mode 68 2.8.3 UNIX Socket Mode 68 2.8.4 No Alert Mode 69 2.8.5 Sending Alerts to Syslog 69 2.8.6 Sending Alerts to SNMP 69 2.8.7 Sending Alerts to Windows 70 2.9 Running Snort in Stealth Mode 71 2.10 References 73 Chapter 3 Working with Snort Rules 75 3.1 TCP/IP Network Layers 76 3.2 The First Bad Rule 77 3.3 CIDR 78 3.4 Structure of a Rule 79 Contents ix 3.5 Rule Headers 81 3.5.1 Rule Actions 81 3.5.2 Protocols 83 3.5.3 Address 84 3.5.4 Port Number 86 3.5.5 Direction 88 3.6 Rule Options 88 3.6.1 The ack Keyword 89 3.6.2 The classtype Keyword 89 3.6.3 The content Keyword 93 3.6.4 The offset Keyword 94 3.6.5 The depth Keyword 95 3.6.6 The content-list Keyword 95 3.6.7 The dsize Keyword 95 3.6.8 The flags Keyword 96 3.6.9 The fragbits Keyword 97 3.6.10 The icmp_id Keyword 98 3.6.11 The icmp_seq Keyword 98 3.6.12 The itype Keyword 98 3.6.13 The icode Keyword 99 3.6.14 The id Keyword 100 3.6.15 The ipopts Keyword 100 3.6.16 The ip_proto Keyword 101 3.6.17 The logto Keyword 102 3.6.18 The msg Keyword 103 3.6.19 The nocase Keyword 103 3.6.20 The priority Keyword 103 3.6.21 The react Keyword 104 3.6.22 The reference Keyword 104 3.6.23 The resp Keyword 105 3.6.24 The rev Keyword 107 3.6.25 The rpc Keyword 107 3.6.26 The sameip Keyword 108 3.6.27 The seq Keyword 108 3.6.28 The flow Keyword 108 3.6.29 The session Keyword 109 3.6.30 The sid Keyword 110 3.6.31 The tag Keyword 110 3.6.32 The tos Keyword 111 3.6.33 The ttl Keyword 111 x Contents 3.6.34 The uricontent Keyword 111 3.7 The Snort Configuration File 112 3.7.1 Using Variables in Rules 112 3.7.2 The config Directives 114 3.7.3 Preprocessor Configuration 116 3.7.4 Output Module Configuration 116 3.7.5 Defining New Action Types 117 3.7.6 Rules Configuration 117 3.7.7 Include Files 117 3.7.8 Sample snort.conf File 118 3.8 Order of Rules Based upon Action 119 3.9 Automatically Updating Snort Rules 120 3.9.1 The Simple Method 120 3.9.2 The Sophisticated and Complex Method 122 3.10 Default Snort Rules and Classes 125 3.10.1 The local.rules File 127 3.11 Sample Default Rules 127 3.11.1 Checking su Attempts from a Telnet Session 127 3.11.2 Checking for Incorrect Login on Telnet Sessions 128 3.12 Writing Good Rules 128 3.13 References 129 Chapter 4 Plugins, Preprocessors and Output Modules 131 4.1 Preprocessors 132 4.1.1 HTTP Decode 133 4.1.2 Port Scanning 134 4.1.3 The frag2 Module 135 4.1.4 The stream4 Module 136 4.1.5 The spade Module 137 4.1.6 ARP Spoofing 138 4.2 Output Modules 139 4.2.1 The alert_syslog Output Module 140 4.2.1 The alert_full Output Module 143 4.2.1 The alert_fast Output Module 143 4.2.1 The alert_smb Module 143 4.2.1 The log_tcpdump Output Module 144 4.2.1 The XML Output Module 146 4.2.1 Logging to Databases 150 4.2.1 CSV Output Module 151 Contents xi 4.2.1 Unified Logging Output Module 153 4.2.1 SNMP Traps Output Module 154 4.2.1 Log Null Output Module 155 4.3 Using BPF Fileters 155 4.4 References 156 Chapter 5 Using Snort with MySQL 157 5.1 Making Snort Work with MySQL 160 5.1.1 Step 1: Snort Compilations with MySQL Support 161 5.1.1 Step 2: Install MySQL 161 5.1.1 Step 3: Creating Snort Database in MySQL 161 5.1.1 Step 4: Creating MySQL User and Granting Permissions to User and Setting Password 163 5.1.1 Step 5: Creating Tables in the Snort Database 164 5.1.1 Step 6: Modify snort.conf Configuration File 170 5.1.1 Step 7: Starting Snort with Database Support 171 5.1.1 Step 8: Logging to Database 172 5.2 Secure Logging to Remote Databases Securely Using Stunnel 174 5.3 Snort Database Maintenance 175 5.3.1 Archiving the Database 175 5.3.2 Using Sledge Hammer: Drop the Database 176 5.4 References 176 Chapter 6 Using ACID and SnortSnarf with Snort 177 6.1 What is ACID? 178 6.2 Installation and Configuration 179 6.3 Using ACID 184 6.3.1 ACID Main Page 188 6.3.2 Listing Protocol Data 189 6.3.3 Alert Details 191 6.3.4 Searching 192 6.3.5 Searching whois Databases 197 6.3.6 Generating Graphs 198 6.3.7 Archiving Snort Data 198 6.3.8 ACID Tables 201 6.4 SnortSnarf 202 6.5 Barnyard 207 6.6 References 207 xii Contents Chapter 7 Miscellaneous Tools 209 7.1 SnortSam 210 7.2 IDS Policy Manager 212 7.3 Securing the ACID Web Console 217 7.3.1 Using a Private Network 217 7.3.2 Blocking Access to the Web Server on the Firewall 218 7.3.3 Using iptables 218 7.4 Easy IDS 218 7.5 References 219 Appendix A Introduction to tcpdump 221 Appendix B Getting Started with MySQL 223 Appendix C Packet Header Formats 237 Appendix D Glossary 243 Appendix E SNML DTD 245 Index 251 C HAPTER 1 Introduction to Intrusion Detection and Snort ecurity is a big issue for all networks in today’s enterprise environ- Sment.