™ 1YEAR UPGRADE BUYER PROTECTION PLAN UPDATED BESTSELLER! The Only Way to Stop a Hacker is to Think Like One David R. Mirza Ahmad Ido Dubrawsky Hal Flynn Joseph “Kingpin” Grand Robert Graham Norris L. Johnson, Jr. K2 Dan “Effugas” Kaminsky F. William Lynch Steve W. Manzuik Ryan Permeh Ken Pfeil Rain Forest Puppy Ryan Russell Technical Editor UPDATED BESTSELLER! 194_HP_Net2e_FC 2/22/02 10:01 AM Page 1 solutions@syngress.com With more than 1,500,000 copies of our MCSE, MCSD, CompTIA, and Cisco study guides in print, we continue to look for ways we can better serve the information needs of our readers. One way we do that is by listening. Readers like yourself have been telling us they want an Internet-based ser- vice that would extend and enhance the value of our books. Based on reader feedback and our own strategic plan, we have created a Web site that we hope will exceed your expectations. Solutions@syngress.com is an interactive treasure trove of useful infor- mation focusing on our book topics and related technologies. The site offers the following features: ■ One-year warranty against content obsolescence due to vendor product upgrades. You can access online updates for any affected chapters. ■ “Ask the Author” customer query forms that enable you to post questions to our authors and editors. ■ Exclusive monthly mailings in which our experts provide answers to reader queries and clear explanations of complex material. ■ Regularly updated links to sites specially selected by our editors for readers desiring additional reliable information on key topics. Best of all, the book you’re now holding is your key to this amazing site. Just go to www.syngress.com/solutions, and keep this book handy when you register to verify your purchase. Thank you for giving us the opportunity to serve your needs. And be sure to let us know if there’s anything else we can do to help you get the maximum value from your investment. We’re listening. www.syngress.com/solutions 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page i 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page ii 1YEAR UPGRADE BUYER PROTECTION PLAN David R. Mirza Ahmad Ido Dubrawsky Hal Flynn Joseph “Kingpin” Grand Robert Graham Norris L. Johnson, Jr. K2 Dan “Effugas” Kaminsky F. William Lynch Steve W. Manzuik Ryan Permeh Ken Pfeil Rain Forest Puppy Ryan Russell Technical Editor 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page iii Syngress Publishing, Inc., the author(s), and any person or firm involved in the writing, editing, or production (collectively “Makers”) of this book (“the Work”) do not guarantee or warrant the results to be obtained from the Work. There is no guarantee of any kind, expressed or implied, regarding the Work or its contents.The Work is sold AS IS and WITHOUT WARRANTY. You may have other legal rights, which vary from state to state. In no event will Makers be liable to you for damages, including any loss of profits, lost savings, or other incidental or consequential damages arising out from the Work or its contents. Because some states do not allow the exclusion or limitation of liability for consequential or incidental damages, the above limitation may not apply to you. You should always use reasonable care, including backup and other appropriate precautions, when working with computers, networks, data, and files. Syngress Media®, Syngress®,“Career Advancement Through Skill Enhancement®,” and “Ask the Author UPDATE®,” are registered trademarks of Syngress Publishing, Inc. “Mission Critical™,”“Hack Proofing™,” and “The Only Way to Stop a Hacker is to Think Like One™” are trademarks of Syngress Publishing, Inc. Brands and product names mentioned in this book are trademarks or service marks of their respective companies. KEY SERIAL NUMBER 001 D7Y4T945T5 002 AKTRT4MW34 003 VMB663N54N 004 SGD34B39KA 005 87U8Q26NVH 006 N4D4RNTEM4 007 2HBVHTR46T 008 ZPB9R5653R 009 J6N5M4BRAS 010 5T6YH2TZFC PUBLISHED BY Syngress Publishing, Inc. 800 Hingham Street Rockland, MA 02370 Hack Proofing Your Network, Second Edition Copyright © 2002 by Syngress Publishing, Inc.All rights reserved. Printed in the United States of America. Except as permitted under the Copyright Act of 1976, no part of this publication may be reproduced or distributed in any form or by any means, or stored in a database or retrieval system, without the prior written permission of the publisher, with the exception that the program listings may be entered, stored, and executed in a computer system, but they may not be reproduced for publication. Printed in the United States of America 1 2 3 4 5 6 7 8 9 0 ISBN: 1-928994-70-9 Technical Editor: Ryan Russell Cover Designer: Michael Kavish Acquisitions Editor: Catherine B. Nolan Page Layout and Art by: Shannon Tozier Developmental Editor: Kate Glennon Indexer: Robert Saigh Distributed by Publishers Group West in the United States and Jaguar Book Group in Canada. 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page iv v Acknowledgments v We would like to acknowledge the following people for their kindness and support in making this book possible. Ralph Troupe, Rhonda St. John, and the team at Callisma for their invaluable insight into the challenges of designing, deploying and supporting world-class enterprise networks. Karen Cross, Lance Tilford, Meaghan Cunningham, Kim Wylie, Harry Kirchner, Kevin Votel, Kent Anderson, Frida Yara, Bill Getz, Jon Mayes, John Mesjak, Peg O’Donnell, Sandra Patterson, Betty Redmond, Roy Remer, Ron Shapiro, Patricia Kelly,Andrea Tetrick, Jennifer Pascal, Doug Reil, and David Dahl of Publishers Group West for sharing their incredible marketing experience and expertise. Jacquie Shanahan and AnnHelen Lindeholm of Elsevier Science for making certain that our vision remains worldwide in scope. Annabel Dent and Paul Barry of Harcourt Australia for all their help. David Buckland,Wendi Wong, Marie Chieng, Lucy Chong, Leslie Lim,Audrey Gan, and Joseph Chan of Transquest Publishers for the enthusiasm with which they receive our books. Kwon Sung June at Acorn Publishing for his support. Ethan Atkin at Cranbury International for his help in expanding the Syngress program. Jackie Gross, Gayle Voycey,Alexia Penny, Anik Robitaille, Craig Siddall, Darlene Morrow, Iolanda Miller, Jane Mackay, and Marie Skelly at Jackie Gross & Associates for all their help and enthusiasm representing our product in Canada. Lois Fraser, Connie McMenemy, Shannon Russell and the rest of the great folks at Jaguar Book Group for their help with distribution of Syngress books in Canada. From Ryan Russell I would like to dedicate my work to my wonderful wife and children, without whom none of this would be worth doing. I love you Sara, Happy Valentine’s Day! I would also like to thank Brian Martin for his assistance in tech editing, and of course the authors who took the time to write the book. Special thanks go out to those authors who worked on the first edition, before anyone had any idea that it would do well or how it would come out. 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page v Contributors Dan “Effugas” Kaminsky (CISSP) worked for two years at Cisco Systems designing security infrastructure for large-scale network monitoring systems. Dan has delivered presentations at several major industry conferences including Linuxworld, DEF CON, and the Black Hat Briefings, and he also contributes actively to OpenSSH, one of the more significant cryptographic systems in use today. Dan founded the cross-disciplinary DoxPara Research (www.doxpara.com) in 1997, seeking to integrate psychological and techno- logical theory to create more effective systems for non-ideal but very real environments in the field. He is based in Silicon Valley, presently studying Operation and Management of Information Systems at Santa Clara University in California. Rain Forest Puppy is a security research and development consultant for a Midwest-based security consulting company. RFP has been working in R&D and coding in various languages for over seven years.While the Web is his primary hobby focus point, he has also played in other realms including: Linux kernel security patches, lockdown of various Windows and UNIX operating systems, and the development of honeypots and other attack alert tools. In the past he’s reported on SQL tampering and common CGI prob- lems, and has contributed security tools (like whisker) to the information security community. Ken Pfeil is the Security Program Manager for Identix Inc.’s information technology security division. Ken started with Identix following his position as Chief Information Security Officer for Miradiant Global Network, Inc. Ken has over 14 years of IT and security experience, having served with such companies as Microsoft, Dell, and Merrill Lynch.While employed at Microsoft, Ken co-authored Microsoft’s “Best Practices for Enterprise Security” whitepaper series, and is the founder of “The NT Toolbox”Web site. He currently covers new security risks and vulnerabilities for Windows and .Net magazines’ Security Administrator publication, and was the resident expert for multiplatform integration and security issues for “The Windows 2000 Experts Journal.” vi 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page vi vii Joseph “Kingpin” Grand is a Boston-based electrical engineer and product designer. His pioneering hardware and security research has been published in various academic and industry journals. He has lectured widely on security product design and analysis, portable devices, and digital foren- sics. In addition to testifying before the United States Senate Governmental Affairs, Joseph has presented his research at the United States Naval Post Graduate School Center for INFOSEC Studies and Research, the USENIX Security Symposium, and the IBM Thomas J.Watson Research Center. Joseph was a long-time researcher with the L0pht hacker think tank. He holds a Bachelor’s of Science in Computer Engineering from Boston University in Boston, Massachusetts. K2 is a security engineer. He works on a variety of systems ranging from UNIX to all other operating systems. He has spent a lot of time working through security issues wherever they exist; core kernels, networking ser- vices, or binary protections. K2 is a member of w00w00 and is a con- tributing member of The Honeynet Project. He would like to thank Anya for all her help and support throughout the year. David M. Ahmad is Threat Analysis Manager for SecurityFocus and mod- erator of the Bugtraq mailing list. SecurityFocus is the leading provider of security intelligence services. David has played a key role in the develop- ment of the vulnerability database at SecurityFocus.The focus of this duty has been the analysis of software vulnerabilities and the methods used to exploit them. David became the moderator of Bugtraq, the well-known computer security mailing list in 2001. He currently resides in Calgary, Alberta, Canada with his family. F. William Lynch (SCSA, CCNA, LPI-I, MCSE, MCP, Linux+,A+) is co- author for Hack Proofing Sun Solaris 8 (ISBN: 1-928994-44-X), also pub- lished by Syngress Publishing. He is an independent security and systems administration consultant and specializes in firewalls, virtual private net- works, security auditing, documentation, and systems performance analysis. William has served as a consultant to multinational corporations and the Federal government including the Centers for Disease Control and Prevention headquarters in Atlanta, Georgia as well as various airbases of the USAF. He is also the founder and director of the MRTG-PME project, 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page vii viii which uses the MRTG engine to track systems performance of various UNIX-like operating systems.William holds a Bachelor’s degree in Chemical Engineering from the University of Dayton in Dayton, Ohio and a Masters of Business Administration from Regis University in Denver, Colorado. Hal Flynn is a Threat Analyst at SecurityFocus, the leading provider of Security Intelligence Services for Business. Hal functions as a Senior Analyst, performing research and analysis of vulnerabilities, malicious code, and net- work attacks. He provides the SecurityFocus team with UNIX and Network expertise. He is also the manager of the UNIX Focus Area and moderator of the Focus-Sun, Focus-Linux, Focus-BSD, and Focus- GeneralUnix mailing lists. Hal has worked the field in jobs as varied as the Senior Systems and Network Administrator of an Internet Service Provider, to contracting the United States Defense Information Systems Agency, to Enterprise-level con- sulting for Sprint. He is also a veteran of the United States Navy Hospital Corps, having served a tour with the 2nd Marine Division at Camp Lejeune, North Carolina as a Fleet Marine Force Corpsman. Hal is mobile, living between sunny Phoenix,Arizona and wintry Calgary,Alberta, Canada. Rooted in the South, he still calls Montgomery,Alabama home. Ryan Permeh is a developer and researcher with eEye Digital Security. He works on the Retina and SecureIIS product lines and leads the reverse engi- neering and custom exploitation efforts for eEye’s research team. Ryan was behind the initital analysis of the CodeRed worm, and has developed many proof of concept exploits provided to vendors and the security community. Ryan has experience in NT, UNIX, systems and application programming as well as large-scale secure network deployment and maintenance. Ryan currently lives and works in sunny Orange County, California. Ryan would like to offer special thanks to Riley Hassel for his assistance in providing the Linux exploitation of a sample buffer overflow. He would also like to thank the rest of the eEye team, Greg Hoglund, and Ryan Russell, for the original foundation ideas included in his chapter. Norris L. Johnson, Jr. (MCSE, MCT, CTT+,A+, Network +) is a tech- nology trainer and owner of a consulting company in the Seattle-Tacoma 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page viii ix area. His consultancies have included deployments and security planning for local firms and public agencies, as well as providing services to other local computer firms in need of problem solving and solutions for their clients. He specializes in Windows NT 4.0,Windows 2000, and Windows XP issues, providing planning, implementation, and integration services. In addition to consulting work, Norris provides technical training for clients and teaches for area community and technical colleges. He co-authored Configuring and Troubleshooting Windows XP Professional (Syngress Publishing, ISBN: 1- 92899480-6), and performed technical edits on Hack Proofing Windows 2000 Server (ISBN: 1-931836-49-3) and Windows 2000 Active Directory, Second Edition (ISBN: 1-928994-60-1). Norris holds a Bachelor’s degree from Washington State University. He is deeply appreciative of the support of his wife Cindy and three sons in helping to maintain his focus and efforts toward computer training and education. Ido Dubrawsky (CCNA, SCSA) is a Network Security Engineer and a member of Cisco’s Secure Consulting Services in Austin,Texas. He currently conducts security posture assessments for clients as well as provides technical consulting for security design reviews. His strengths include Cisco routers and switches, PIX firewall, Solaris systems, and freeware intrusion detection systems. Ido holds a Bachelor’s and a Master’s degree from the University of Texas at Austin and is a member of USENIX and SAGE. He has written several articles covering Solaris security and network security for Sysadmin magazine as well as SecurityFocus. He lives in Austin,Texas with his family. Robert Graham has been developing sniffers since 1990, where he wrote most of the protocol decodes for the ProTools protocol-analyzer, including real-time tools for password sniffing and Telnet session spying. Robert worked for Network General between 1994 and 1998 where he rewrote all of the protocol-decodes for the Sniffer protocol-analyzer. He founded Network ICE in 1998 and created the BlackICE network-snifing intrusion detection system. He is now the chief architect at Internet Security Systems in charge of the design for the RealSecure IDS. Steve Manzuik (MCP) was most recently a Manager in Ernst & Young’s Security and Technology Solutions practice specializing in profiling services. 194_HPYN2e_FM.qxd 2/15/02 2:36 PM Page ix [...]... File-Comparison Tools Using the fc Tool Using the diff Command Working with Hex Editors Hackman [N] Curses Hexedit Hex Workshop xv 93 95 96 99 10 0 10 0 10 1 10 1 10 2 10 2 10 4 10 4 10 5 10 5 10 5 10 6 10 6 10 6 11 0 11 2 11 3 12 0 12 5 12 6 12 8 12 9 13 0 13 1 13 2 13 2 13 5 13 6 13 9 14 3 14 3 14 3 14 5 14 6 14 7 14 8 14 9 19 4_HPYN2e_toc.qxd xvi 2 /15 /02 2:56 PM Page xvi Contents Utilizing File System Monitoring Tools Doing It The Hard... Key Improperly Stored Private or Secret Keys Understanding Amateur Cryptography Attempts Classifying the Ciphertext 15 0 15 0 15 1 15 3 15 4 15 5 15 7 15 7 15 9 16 0 16 1 16 2 16 5 16 6 16 6 16 7 16 7 16 9 17 0 17 0 17 2 17 3 17 4 17 4 17 6 17 7 17 7 17 8 18 0 18 1 18 2 18 3 18 3 18 4 18 5 18 6 18 8 18 9 19 4_HPYN2e_toc.qxd 2 /15 /02 2:56 PM Page xvii Contents Frequency Analysis Ciphertext Relative Length Analysis Similar Plaintext Analysis... Hack Proofing Your Web Applications (ISBN: 1- 928994- 31- 8) Hack Proofing Sun Solaris 8 (ISBN: 1- 928994-44-X) Hack Proofing Linux (ISBN: 1- 928994-34-2) xxix 19 4_HPYN2e_FrmAu.qxd xxx 2 /15 /02 2:25 PM Page xxx Foreword v 1. 5 Hack Proofing Windows 2000 Server (ISBN: 1- 9 318 36-49-3) Hack Proofing Your Wireless Network (ISBN: 1- 928994-59-8) Hack Proofing ColdFusion 5.0 (ISBN: 1- 928994-77-6) And there are more to come.These... Starter Kit Advanced Kit Example: Hacking the iButton Authentication Token Experimenting with the Device Reverse-engineering the “Random” Response Example: Hacking the NetStructure 711 0 E-commerce Accelerator xxv 586 589 593 598 600 606 609 610 610 611 613 615 615 615 617 618 620 623 624 624 627 627 628 629 630 6 31 632 634 634 635 637 638 639 642 19 4_HPYN2e_toc.qxd xxvi 2 /15 /02 2:56 PM Page xxvi Contents... Discovering Network and System Problems Use the Source Untaint Data by Filtering It Escaping Characters Is Not Always Enough Perl Cold Fusion/Cold Fusion Markup Language (CFML) ASP PHP Protecting Your SQL Queries Silently Removing versus Alerting on Bad Data Invalid Input Function Token Substitution Utilizing the Available Safety Features in Your Programming Language xvii 18 9 19 0 19 0 19 1 19 1 19 1 19 5 19 5 19 7 19 9... Storms Playing MITM for Encrypted Communications Man-in-the-Middle Attacks Dsniff Other Hijacking 408 408 410 411 411 414 415 416 416 420 425 430 430 4 31 433 434 435 436 19 4_HPYN2e_toc.qxd xxii 2 /15 /02 2:56 PM Page xxii Contents Summary Solutions Fast Track Frequently Asked Questions Chapter 12 Spoofing: Attacks on Trusted Identity Tools & Traps… Perfect Forward Secrecy: SSL’s Dirty Little Secret The... with a Random Format String Writing a Format String Exploit xix 268 268 269 2 81 282 293 303 303 304 306 306 307 307 310 310 311 313 314 314 317 319 320 322 326 327 328 329 329 330 332 333 335 335 335 336 340 344 19 4_HPYN2e_toc.qxd xx 2 /15 /02 2:56 PM Page xx Contents Summary Solutions Fast Track Frequently Asked Questions Chapter 10 Sniffing Ethereal Capture Preferences Introduction What Is Sniffing? How... (Port 21) Monitoring POP (Port 11 0) Monitoring IMAP (Port 14 3) Monitoring NNTP (Port 11 9) Monitoring rexec (Port 512 ) Monitoring rlogin (Port 513 ) Monitoring X 11 (Port 6000+) Monitoring NFS File Handles Capturing Windows NT Authentication Information Capturing Other Network Traffic Monitoring SMTP (Port 25) Monitoring HTTP (Port 80) Popular Sniffing Software Ethereal Network Associates Sniffer Pro NT Network. .. Protect Them In Order for a System to Begin to Be Considered Secure, It Must Undergo an Independent Security Audit Security through Obscurity Does Not Work 1 2 2 3 4 6 8 8 11 12 12 14 15 18 20 22 24 24 26 26 27 28 30 32 35 37 xiii 19 4_HPYN2e_toc.qxd xiv 2 /15 /02 2:56 PM Page xiv Contents Summary Solutions Fast Track Frequently Asked Questions Chapter 3 Classes of Attack There are seven classes of attacks:... Go Through?” Deployability: “How Painful Is This to Get Up and Running?” Flexibility: “What Can We Use This for, Anyway?” xxiii 468 470 470 4 71 4 71 473 474 474 476 476 478 486 486 487 488 510 511 518 519 523 527 528 530 532 532 533 534 19 4_HPYN2e_toc.qxd xxiv 2 /15 /02 2:56 PM Contents Primary questions for privacy of communications include the following: s s Page xxiv Can anyone else monitor the traffic . Analysis 18 9 Ciphertext Relative Length Analysis 19 0 Similar Plaintext Analysis 19 0 Monoalphabetic Ciphers 19 1 Other Ways to Hide Information 19 1 XOR 19 1 UUEncode 19 5 Base64 19 5 Compression 19 7 Summary. Techniques 11 3 Disassemblers, Decompilers, and Debuggers 12 0 Black Box Testing 12 5 Chips 12 6 Summary 12 8 Solutions Fast Track 12 9 Frequently Asked Questions 13 0 Chapter 5 Diffing 13 1 Introduction 13 2 What. Research Methodologies 10 0 Source Code Research 10 1 Searching For Error-Prone Functions 10 1 Line-By-Line Review 10 2 Discovery Through Difference 10 2 Binary Research 10 4 Tracing Binaries 10 4 Debuggers 10 5 Guideline-Based