Dataset Preview
The full dataset viewer is not available (click to read why). Only showing a preview of the rows.
The dataset generation failed
Error code: DatasetGenerationError
Exception: TypeError
Message: Couldn't cast array of type
list<item: struct<page_number: int64, text: string>>
to
{'page_number': Value(dtype='int64', id=None), 'text': Value(dtype='string', id=None)}
Traceback: Traceback (most recent call last):
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/builder.py", line 1870, in _prepare_split_single
writer.write_table(table)
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/arrow_writer.py", line 622, in write_table
pa_table = table_cast(pa_table, self._schema)
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 2292, in table_cast
return cast_table_to_schema(table, schema)
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 2245, in cast_table_to_schema
arrays = [
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 2246, in <listcomp>
cast_array_to_feature(
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 1795, in wrapper
return pa.chunked_array([func(chunk, *args, **kwargs) for chunk in array.chunks])
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 1795, in <listcomp>
return pa.chunked_array([func(chunk, *args, **kwargs) for chunk in array.chunks])
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/table.py", line 2108, in cast_array_to_feature
raise TypeError(f"Couldn't cast array of type\n{_short_str(array.type)}\nto\n{_short_str(feature)}")
TypeError: Couldn't cast array of type
list<item: struct<page_number: int64, text: string>>
to
{'page_number': Value(dtype='int64', id=None), 'text': Value(dtype='string', id=None)}
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 1417, in compute_config_parquet_and_info_response
parquet_operations = convert_to_parquet(builder)
File "/src/services/worker/src/worker/job_runners/config/parquet_and_info.py", line 1049, in convert_to_parquet
builder.download_and_prepare(
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/builder.py", line 924, in download_and_prepare
self._download_and_prepare(
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/builder.py", line 1000, in _download_and_prepare
self._prepare_split(split_generator, **prepare_split_kwargs)
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/builder.py", line 1741, in _prepare_split
for job_id, done, content in self._prepare_split_single(
File "/src/services/worker/.venv/lib/python3.9/site-packages/datasets/builder.py", line 1897, in _prepare_split_single
raise DatasetGenerationError("An error occurred while generating the dataset") from e
datasets.exceptions.DatasetGenerationError: An error occurred while generating the datasetNeed help to make the dataset viewer work? Make sure to review how to configure the dataset viewer, and open a discussion for direct support.
pages
dict |
|---|
{
"page_number": 1,
"text": ""
}
|
{
"page_number": 2,
"text": "The Basics of hacking \nand penetration testing\n"
}
|
{
"page_number": 3,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 4,
"text": "The Basics of Hacking \nand Penetration Testing\nEthical Hacking and Penetration \nTesting Made Easy\nPatrick Engebretson\nTechnical Editor\nJames Broad\n \nAmsterdam • Boston • Heidelberg • London • New York \nOxford • Paris • San Diego • San Francisco \nSingapore • Sydney • Tokyo \nSyngress Press is an imprint of Elsevier\n"
}
|
{
"page_number": 5,
"text": "For information on all Syngress publications visit our website at www.syngress.com\nAcquiring Editor: Angelina Ward\nDevelopment Editor: Heather Scherer\nProject Manager: Jessica Vaughan\nDesigner: Alisa Andreola\nSyngress is an imprint of Elsevier\n225 Wyman Street, Waltham, MA 02451, USA\n© 2011 Elsevier Inc. All rights reserved\nNo part of this publication may be reproduced or transmitted in any form or by any means, electronic \nor mechanical, including photocopying, recording, or any information storage and retrieval system, \nwithout permission in writing from the publisher. Details on how to seek permission, further \ninformation about the Publisher’s permissions policies and our arrangements with organizations such \nas the Copyright Clearance Center and the Copyright Licensing Agency, can be found at our \nwebsite: www.elsevier.com/permissions.\nThis book and the individual contributions contained in it are protected under copyright by the \nPublisher (other than as may be noted herein).\nNotices\nKnowledge and best practice in this field are constantly changing. As new research and experience \nbroaden our understanding, changes in research methods or professional practices, may become necessary. \nPractitioners and researchers must always rely on their own experience and knowledge in evaluating \nand using any information or methods described herein. In using such information or methods they should be \nmindful of their own safety and the safety of others, including parties for whom they have a professional \nresponsibility.\nTo the fullest extent of the law, neither the Publisher nor the authors, contributors, or editors, assume \nany liability for any injury and/or damage to persons or property as a matter of products liability, \nnegligence or otherwise, or from any use or operation of any methods, products, instructions, or \nideas contained in the material herein.\nLibrary of Congress Cataloging-in-Publication Data\nEngebretson, Pat (Patrick Henry), 1974-\n The basics of hacking and penetration testing : ethical hacking and penetration testing made easy / Patrick \nEngebretson.\n p. cm. – (Syngress basics series)\n Includes bibliographical references and index.\n ISBN 978-1-59749-655-1 (alk. paper)\n 1. Computer security. 2. Computer hackers. 3. Computer software–Testing. 4. Computer crimes– \nPrevention. I. Title.\n QA76.9.A25E5443 2010\n 005.8–dc23\t\n2011018388\nBritish Library Cataloguing-in-Publication Data\nA catalogue record for this book is available from the British Library\nISBN: 978-1-59749-655-1\nPrinted in the United States of America\n11 12 13 14 15 10 9 8 7 6 5 4 3 2 1\n"
}
|
{
"page_number": 6,
"text": "This book is dedicated to God, Lorianna, Maggie, and Molly. You are the steel \ncables that bind me. I love you.\nDedication\nv\n"
}
|
{
"page_number": 7,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 8,
"text": "ACKNOWLEDGMENTS...............................................................................ix\nABOUT THE AUTHOR................................................................................xi\nABOUT THE TECHNICAL EDITOR............................................................. xiii\nINTRODUCTION....................................................................................... xv\nCHAPTER 1\t What is Penetration Testing?.................................................1\nCHAPTER 2\t Reconnaissance..................................................................15\nCHAPTER 3\t Scanning.............................................................................43\nCHAPTER 4\t Exploitation.........................................................................65\nCHAPTER 5\t Web-based Exploitation.....................................................107\nCHAPTER 6\t Maintaining Access with Backdoors and Rootkits...............127\nCHAPTER 7\t Wrapping Up the Penetration Test......................................145\nINDEX...................................................................................................157\nContents\nvii\n"
}
|
{
"page_number": 9,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 10,
"text": "Like most people, I have a list. The list is made up of life goals and dreams—\nthings I would like to accomplish at some point in my life. Some of the \nitems on the list are big, some small, some well-defined, stable, and concrete, \nwhereas others are more transient and ambiguous—like early morning fog \non the Lutsen Mountains, constantly changing and moving, sometimes even \ndisappearing altogether only to reappear at a later date and time. Obviously, \nthe list is not a stone tablet; it changes and updates as I move through life. A \nfew things, however, have never moved off the list; they stand as the Mount \nRushmore’s in my life. Hundreds of feet high, carved into solid granite. Never \nchanging. Always there. They gracefully weather the storms and vicissitudes of \nlife and simply wait to be crossed off. Some are nobler, some are egotistical, \nand some are even whimsical. I have had the good fortune in my life to be able \nto cross off many of the items on my list. Even the big ones. This book repre-\nsents the crossing off of one of my “Rushmore” items. A presidential face to be \nsure (although I am not sure which face it actually represents!).\nAs with most things in life, this book, the end product that you see, is the cul-\nmination of many people’s efforts and energies. So while I do get to cross this \noff my list, and while my name appears on the cover, please do not take that \nto mean that this book is my sole creation. Without the dedication, support, \nhelp, and advice from everyone involved, there is no doubt you would not be \nreading these words right now. Writing a proper “Acknowledgments” section \nby truly listing everyone involved would fill many, many pages—below you \nwill find a simple attempt to say thanks. I apologize in advance if I forgot to \nmention anyone.\nMy Wife\nWhat can I say that would justify or somehow verbalize what you mean to me? \nThere is no doubt that this book is as much an effort on your part as mine. You \ngave me the wings of encouragement to fly and the dedication of long lonely \ndays and nights while I worked on it. You never complained, never resisted, \nand were never upset when I needed more from you. Every man should be so \nlucky. I am who I am because of you. Thank you.\nMy Girls\nTo my little Liebchens—you are the light of my life! I apologize for all early \nmornings, late nights, and long weekends. Bring on the sunroom, Little People, \nAcknowledgments\nix\n"
}
|
{
"page_number": 11,
"text": "Acknowledgments\nx\nMary and Joseph, princesses, Barbie’s, and the Pirate Ship! Daddy loves you \nmore than life itself.\nMy Family\nThanks to my mother and father for the gift of education and teaching me to \nunderstand the value of hard work and dedication to a project. Thanks also to \nmy other mother, who dedicated countless hours to reading and correcting my \ninitial rough drafts.\nTo the Syngress Team\nThanks for the opportunity! Thanks to the editing team; I appreciate all the \nhard work and dedication you gave to this project. Special thanks to Angelina \nWard who ultimately earned a green light for the project, to Heather Scherer, \nmy editor, for the countless hours and assistance, and to James Broad for the \nexcellent eye and great suggestions throughout the technical review process.\nTo keep up with news and happenings about the book, or other security-\nrelated content, feel free to follow: pengebretson on Twitter or visit my home\npage: http://homepages.dsu.edu/pengebretson\n"
}
|
{
"page_number": 12,
"text": "Dr. Patrick Engebretson obtained his Doctor of Science degree with a spe-\ncialization in information security from Dakota State University. He currently \nserves as an assistant professor of information assurance and also works as a \nsenior penetration tester for a security firm in the Midwest. His research inter-\nests include penetration testing, hacking, intrusion detection, exploitation, \nhoney pots, and malware. In the past several years, he has published many \npeer-reviewed journal and conference papers in these areas. He has been \ninvited by the Department of Homeland Security to share his research at the \nSoftware Assurance Forum in Washington, DC, and has also spoken at Black \nHat in Las Vegas. He regularly attends advanced exploitation and penetration \ntesting trainings from industry-recognized professionals and holds several cer-\ntifications. He teaches graduate and undergraduate courses in penetration test-\ning, wireless security, and intrusion detection, and advanced exploitation.\nxi\nAbout the Author\n"
}
|
{
"page_number": 13,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 14,
"text": "xiii\nJames Broad (CISSP, C|EH, C)PTS, Security, MBA) is the President and \nowner of Cyber-Recon, LLC, where he and his team of consultants special-\nize in Information Security, Information Assurance, and Certification and \nAccreditation and offer other security consultancy services to corporate and gov-\nernment clients.\nAs a security professional with over 20 years of real-world IT experience, James \nis an expert in many areas of IT security, specializing in security engineering, \npenetration testing, and vulnerability analysis and research. He has provided \nsecurity services in the Nation’s most critical sectors including defense, law \nenforcement, intelligence, finance, and healthcare.\nJames has a Master’s of Business Administration degree with specialization in \nInformation Technology (MBA/IT) from the Ken Blanchard College of Business, \nBachelor’s degrees in Computer Programming and Security Management from \nSouthwestern University and is currently a Doctoral Learner pursuing a Ph.D. \nin Information Security from Capella University. He is a member of ISSA and \n(ISC) 2®. James currently resides in Stafford, Virginia with his family: Deanne, \nMicheal, and Temara.\nAbout the \nTechnical Editor\nxiii\n"
}
|
{
"page_number": 15,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 16,
"text": "I suppose there are several questions that may be running through your head \nas you contemplate reading this book: Who is the intended audience for this \nbook? How is this book different from book ‘x’ (insert your favorite title here)? \nWhy should I buy it? Because these are all fair questions and I am asking you \nto plunk down your hard-earned cash, it is important to provide some answers \nto these questions.\nFor people who are interested in learning about hacking and penetration test-\ning, walking into a well-stocked bookstore can be as confusing as searching \nfor “hacking” books at amazon.com. Initially, there appears to be an almost \nendless selection to choose from. Most large bookstores have several shelves \ndedicated to computer security books. They include books on programming \nsecurity, web application security, rootkits and malware, penetration testing, \nand, of course, hacking. However, even the hacking books seem to vary in con-\ntent and subject matter. Some books focus on using tools but do not discuss \nhow these tools fit together. Other books focus on hacking a particular subject \nbut lack the broad picture.\nThis book is intended to address these issues. It is meant to be a single starting \npoint for anyone interested in the topics of hacking or penetration testing. The \nbook will certainly cover specific tools and topics but will also examine how \nthe tools fit together and how they rely on one another to be successful.\nWho is the intended audience for this book?\nThis book is meant to be a very gentle yet thorough guide to the world of hack-\ning and penetration testing. It is specifically aimed at helping you master the \nbasic steps needed to complete a hack or penetration test without overwhelm-\ning you. By the time you finish this book, you will have a solid understanding \nof the penetration testing process and you will be comfortable with the basic \ntools needed to complete the job.\nSpecifically, this book is aimed at people who are new to the world of hack-\ning and penetration testing, for those with little or no previous experience, for \nthose who are frustrated by the inability to see the big picture (how the various \ntools and phases fit together), or for those looking to expand their knowledge \nof offensive security.\nIn short this book is written for anyone who is interested in computer secu-\nrity, hacking, or penetration testing but has no prior experience and is not sure \nwhere to begin. A colleague and I call this concept “zero entry hacking” (ZEH), \nxv\nIntroduction\n"
}
|
{
"page_number": 17,
"text": "Introduction\nxvi\nmuch like modern-day swimming pools. Zero entry pools gradually slope from \nthe dry end to the deep end, allowing swimmers to wade in without feeling \noverwhelmed or without having a fear of drowning. The “zero entry” concept \nallows everyone the ability to use the pool regardless of age or swimming abil-\nity. This book employs a similar technique. ZEH is designed to expose you to \nthe basic concepts without overwhelming you. Completion of ZEH will pre-\npare you for advanced courses and books.\nHow is this book different from book ‘x’?\nWhen not spending time with my family, there are two things I enjoy doing: \nreading and hacking. Most of the time, I combine these hobbies by reading \nabout hacking. As a professor and a penetration tester, you can imagine that my \nbookshelf is lined with many books on hacking, security, and penetration test-\ning. As with most things in life, the quality and value of every book is different. \nSome books are excellent resources that have been used so many times that the \nbindings are literally falling apart. Others are less helpful and remain in nearly \nnew condition. A book that does a good job of explaining the details without \nlosing the reader is worth its weight in gold. Unfortunately, most of my per-\nsonal favorites, those that are worn and tattered, are either very lengthy (500 \npages) or very focused (an in-depth guide to a single topic). Neither of these is \na bad thing; in fact, quite the opposite, it is the level of detail and the clarity of \nthe authors’ explanation that make them so great. But at the same time, a very \nlarge tome focused on a detailed subject of security can seem overwhelming to \nnewcomers.\nUnfortunately, as a beginner trying to break into the security field and learn \nthe basics of hacking, tackling one of these books can be both daunting and \nconfusing. This book is different from other publications in two ways. First, it \nis meant for beginners; recall the concept of “zero entry.” If you have never per-\nformed any type of hacking or you have used a few tools but are not quite sure \nwhat to do next (or how to interpret the results of the tool), this book is for \nyou. The goal is not to bury you with details but to present a broad overview of \nthe entire field.\nNaturally, the book will still cover each of the major tools needed to complete \nthe steps in a penetration test, but it will not stop to examine all the in-depth \nor additional functionality for each of these tools. This will be helpful from the \nstandpoint that it will focus on the basics, and in most cases allow us to avoid \nconfusion caused by advanced features or minor differences in tool versions.\nFor example, when we discuss port scanning, the chapter will discuss how to \nrun the basic scans with the very popular port scanner Nmap. Because the book \nfocuses on the basics, it becomes less important exactly which version of Nmap \nthe user is running. Running a SYN scan using Nmap is exactly the same regard-\nless of whether you are conducting your scan with Nmap version 2 or version 5. \nThis technique will be employed as often as possible, doing so should allow the \n"
}
|
{
"page_number": 18,
"text": "Introduction \nxvii\nreader to learn Nmap (or any tool) without having to worry about the changes \nin functionality that often accompany advanced features in version changes.\nThe goal of this book is to provide general knowledge that will allow you to \ntackle advanced topics and books. Remember, once you have a firm grasp of \nthe basics, you can always go back and learn the specific details and advanced \nfeatures of a tool. In addition, each chapter will end with a list of suggested \ntools and topics that are outside the scope of this book but can be used for fur-\nther study and to advance your knowledge.\nBeyond just being written for beginners, this book actually presents the infor-\nmation in a very unique way. All the tools and techniques we use in this book \nwill be carried out in a specific order against a small number of related targets \n(all target machines will belong to the same subnet, and the reader will be able \nto easily recreate this “target” network to follow along). Readers will be shown \nhow to interpret tool output and how to utilize that output to continue the \nattack from one chapter to the next.\nThe use of a sequential and singular rolling example throughout the book will \nhelp readers see the big picture and better comprehend how the various tools \nand phases fit together. This is different from many other books on the mar-\nket today, which often discuss various tools and attacks but fail to explain how \nthose tools can be effectively chained together. Presenting information in a \nway that shows the user how to clearly move from one phase to another will \nprovide valuable experience and allow the reader to complete an entire pene-\ntration test by simply following along with the examples in the book. This con-\ncept should allow the reader to get a clear understanding of the fundamental \nknowledge while learning how the various tools and phases connect.\nWhy should I buy this book?\nEven though the immediate answers to this question are highlighted in the \npreceding sections, below you will find a condensed list of reasons:\nn\t You want to learn more about hacking and penetration testing but you are \nunsure of where to start.\nn\t You have dabbled in hacking and penetration testing but you are not sure \nhow all the pieces fit together.\nn\t You want to learn more about the tools and processes that are used by \nhackers and penetration testers to gain access to networks and systems.\nn\t You are looking for a good place to start building offensive security \nknowledge.\nn\t You enjoy a challenge.\n"
}
|
{
"page_number": 19,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 20,
"text": "1\nINTRODUCTION\nPenetration testing can be defined as a legal and authorized attempt to locate \nand successfully exploit computer systems for the purpose of making those sys-\ntems more secure. The process includes probing for vulnerabilities as well as \nproviding proof of concept (POC) attacks to demonstrate the vulnerabilities \nare real. Proper penetration testing always ends with specific recommendations \nfor addressing and fixing the issues that were discovered during the test. On \nthe whole, this process is used to help secure computers and networks against \nfuture attacks.\nPenetration testing is also known as\nn\t Pen Testing\nn\t PT\nn\t Hacking\nn\t Ethical Hacking\nn\t White Hat Hacking\nIt is important to spend a few moments discussing the difference between pen-\netration testing and vulnerability assessment. Many people (and vendors) in \nthe security community incorrectly use these terms interchangeably. A vulner-\nability assessment is the process of reviewing services and systems for poten-\ntial security issues, whereas a penetration test actually performs exploitation \nand POC attacks to prove that a security issue exists. Penetration tests go a step \nWhat Is Penetration \nTesting?\nCHAPTER 1\nInformation in This Chapter:\nn\t Introduction to Backtrack Linux: Tools. Lots of Tools\nn\t Working with Backtrack: Starting the Engine\nn\t The Use and Creation of a Hacking Lab\nn\t Phases of a Penetration Test\n"
}
|
{
"page_number": 21,
"text": "The Basics of Hacking and Penetration Testing\n2\nbeyond vulnerability assessments by simulating hacker activity and delivering \nlive payloads. In this book, we will cover the process of vulnerability assess-\nment as one of the steps utilized to complete a penetration test.\nSetting the Stage\nUnderstanding all the various players and positions in the world of hacking \nand penetration testing is central to comprehending the big picture. Let us start \nby painting the picture with broad brush strokes. Please understand that the \nfollowing is a gross oversimplification; however, it should help you see the dif-\nferences between the various groups of people involved.\nIt may help to consider the Star Wars universe where there are two sides of the \n“force”: Jedis and Siths. Good vs. Evil. Both sides have access to an incredible \npower. One side uses its power to protect and serve, whereas the other side uses \nit for personal gain and exploitation.\nLearning to hack is much like learning to use the force (or so I imagine!). The \nmore you learn, the more power you have. Eventually, you will have to decide \nwhether you will use your power for good or bad. There is a classic poster from \nthe Star Wars Episode I movie that depicts Anakin as a young boy. If you look \nclosely at Anakin’s shadow in the poster, you will see it is the outline of Darth \nVader. Try searching the Internet for “Anakin Darth Vader shadow” to see it. \nUnderstanding why this poster has appeal is critical. As a boy, Anakin had no \naspirations of becoming Darth Vader, but it happened nonetheless.\nIt is probably safe to assume that very few people get into hacking to become \na super villain. The problem is that journey to the darkside is a slippery slope. \nHowever, if you want to be great, have the respect of your peers, and be gain-\nfully employed in the security workforce, you need to commit yourself to using \nyour powers to protect and serve. Having a felony on your record is a one-way \nticket to another profession. It is true that there is currently a shortage of quali-\nfied security experts, but even so, not many employers today are willing to take \na chance, especially if those crimes involve computers.\nIn the pen testing world, it is not uncommon to hear the terms “white hat” and \n“black hat” to describe the Jedis and Siths. Throughout this book, the terms \n“white hat,” “ethical hacker,” or “penetration tester” will be used interchange-\nably to describe the Jedis. The Siths will be referred to as “black hats,” “crack-\ners,” or “malicious attackers.”\nIt is important to note that ethical hackers complete many of the same activi-\nties with many of the same tools as malicious attackers. In nearly every situ-\nation, an ethical hacker should strive to act and think like a real black hat \nhacker. The closer the penetration test simulates a real-world attack, the more \nvalue it provides to the customer paying for the PT.\nPlease note how the previous paragraph says “in nearly every situation.” Even \nthough white hats complete many of the same tasks with many of the same \ntools, there is a world of difference between the two sides. At its core, these \n"
}
|
{
"page_number": 22,
"text": "What Is Penetration Testing? CHAPTER 1\n3\ndifferences can be boiled down to three key points: authorization, motivation, \nand intent. It should be stressed that these points are not all inclusive, but they \ncan be useful in determining if an activity is ethical or not.\nThe first and simplest way to differentiate between white hats and black hats is \nauthorization. Authorization is the process of obtaining approval before con-\nducting any tests or attacks. Once authorization is obtained, both the penetra-\ntion tester and the company being audited need to agree upon the scope of the \ntest. The scope includes specific information about the resources and systems \nto be included in the test. The scope explicitly defines the authorized targets \nfor the penetration tester. It is important that both sides fully understand the \nauthorization and scope of the PT. White hats must always respect the autho-\nrization and remain within the scope of the test. Black hats will have no such \nconstraints on the target list.\nThe second way to differentiate between an ethical hacker and a malicious \nhacker is through examination of the attacker’s motivation. If the attacker is \nmotivated or driven by personal gain, including profit through extortion or \nother devious methods of collecting money from the victim, revenge, fame, or \nthe like, he or she should be considered a black hat. However, if the attacker \nis preauthorized and his or her motivation is to help the organization and \nimprove their security, he or she can be considered a white hat.\nFinally, if the intent is to provide the organization a realistic attack simula-\ntion so that the company can improve its security through early discovery and \nmitigation of vulnerabilities, the attacker should be considered a white hat. \nIt is also important to comprehend the critical nature of keeping PT findings \nconfidential. Ethical hackers will never share sensitive information discovered \nduring the process of a penetration testing with anyone other than the client. \nHowever, if the intent is to leverage information for personal profit or gain, the \nattacker should be considered a black hat.\nINTRODUCTION TO BACKTRACK LINUX: \nTOOLS. LOTS OF TOOLS\nA few years back, the open discussion or teaching of hacking techniques was \nconsidered a bit taboo. Fortunately, times have changed and people are begin-\nning to understand the value of offensive security. Offensive security is now \nbeing embraced by organizations regardless of size or industries. Governments \nare also getting serious about offensive security. Many governments have gone \non record stating they are actively building and developing offensive security \ncapabilities.\nUltimately, penetration testing should play an important role in the overall \nsecurity of your organization. Just as policies, risk assessments, business con-\ntinuity planning, and disaster recovery have become integral components in \nkeeping your organization safe and secure, penetration testing needs to be \nincluded in your overall security plan as well. Penetration testing allows you \n"
}
|
{
"page_number": 23,
"text": "The Basics of Hacking and Penetration Testing\n4\nto view your organization through the eyes of the enemy. This process can lead \nto many surprising discoveries and give you the time needed to patch your sys-\ntems before a real attacker can strike.\nOne of the great things about learning how to hack today is the plethora and \navailability of good tools to perform your craft. Not only are the tools read-\nily available, but many of them are stable with several years of development \nbehind them. Maybe even more important to many of you is the fact that most \nof these tools are available free of charge. For the purpose of this book, every \ntool covered will be free.\nIt is one thing to know a tool is free, it is another to find, compile, and install \neach of the tools required to complete even a basic penetration test. Although \nthis process is quite simple on today’s modern Linux OS’s, it can still be a bit \ndaunting for newcomers. Most people who start are usually more interested in \nlearning how to use the tools than they are in searching the vast corners of the \nInternet locating and installing tools.\nTo be fair, you really should learn how to manually compile and install soft-\nware on a Linux machine; or at the very least, you should become familiar with \napt-get (or the like).\nMore Advanced\nAPT, short for Advanced Package Tool, is a package management system. APT allows \nyou to quickly and easily install, update, and remove software from the command \nline. Aside from its simplicity, one of the best things about APT is the fact that it \nautomatically resolves dependency issues for you. This means that if the package \nyou are installing requires additional software, APT will automatically locate and \ninstall the additional software. This is a massive improvement over the old days of \n“dependency hell.”\nInstalling software with APT is very straightforward. For example, let us assume you want \nto install the classic network-mapping tool Cheops. Once you know the name of the \npackage you want to install, from the command line you can run apt-get install \nfollowed by the name of the software you want to install. It is always a good idea to run \napt-get update before installing software. This will ensure that you are getting the \nlatest version available. To install Cheops, we would issue the following commands:\napt-get update\napt-get install cheops\nBefore the package is installed, you will be shown how much disk space will be used \nand you will be asked if you want to continue. To install your new software, you can \ntype “Y” and hit the enter key.\nIf you prefer not to use the command line, there are several GUIs available for \ninteracting with APT. The most popular graphical front end is currently Aptitude. \nAdditional package managers are outside the scope of this book.\n"
}
|
{
"page_number": 24,
"text": "What Is Penetration Testing? CHAPTER 1\n5\nA basic understanding of Linux will be beneficial and will pay you mountains \nof dividends in the long run. For the purpose of this book, there will be no \nassumption that you have prior Linux experience, but do yourself a favor and \ncommit yourself to becoming a Linux guru someday. Take a class, read a book, \nor just explore on your own. Trust me, you will thank me later. If you are inter-\nested in penetration testing or hacking, there is no way of getting around the \nneed to know Linux.\nFortunately, the security community is a very active and very giving group. \nThere are several organizations that have worked tirelessly to create various \nsecurity-specific Linux distributions. A distribution, or “distro” for short, is basi-\ncally a flavor, type, or brand of Linux.\nAmong the most well known of these penetration testing distributions is one \ncalled “Backtrack.” Backtrack Linux is your one-stop shop for learning hacking \nand performing penetration testing. Backtrack Linux reminds me of that scene \nin the first Matrix movie where Tank asks Neo “What do you need besides a \nmiracle?” Neo responds with “Guns. Lots of Guns.” At this point in the movie, \nrows and rows of guns slide into view. Every gun imaginable is available for \nNeo and Trinity: handguns, rifles, shotguns, semiautomatic, automatic, big and \nsmall from pistols to explosives, an endless supply of different weapons from \nwhich to choose. That is a similar experience most newcomers have when they \nfirst boot up Backtrack. “Tools. Lots of Tools.”\nBacktrack Linux is a hacker’s dream come true. The entire distribution is built \nfrom the ground up for penetration testers. The distribution comes preloaded \nwith hundreds of security tools that are installed, configured, and ready to \nbe used. Best of all, Backtrack is free! You can get your copy at http://www.\nBacktrack-linux.org/downloads/.\nNavigating to the Backtrack link will allow you to choose from either an .iso or \na VMware image. If you choose to download the .iso, you will need to burn the \n.iso to a DVD. If you are unsure of how to complete this process, please Google \n“burning an iso.” Once you have completed the burning process, you will have \na bootable DVD. In most cases, starting Backtrack from a bootable DVD is as \nsimple as putting the DVD into the drive and restarting the machine. In some \ninstances, you may have to change the boot order in the BIOS so that the opti-\ncal drive has the highest boot priority.\nIf you choose to download the VMware image, you will also need software \ncapable of opening and deploying or running the image. Luckily enough, there \nare several good tools for accomplishing this task. Depending on your prefer-\nence, you can use VMware’s VMware Player, Sun Microsystem’s VirtualBox, or \nMicrosoft’s Virtual PC. In reality, if you do not like any of those options, there \nare many other software options capable of running a VM image. You simply \nneed to choose one that you are comfortable with.\nEach of the three virtualization options listed above are available free of charge \nand will provide you with the ability to run VM images. You will need to \n"
}
|
{
"page_number": 25,
"text": "The Basics of Hacking and Penetration Testing\n6\ndecide which version is best for you. This book will rely heavily on the use of \na Backtrack VMware image and VMware Player. At the time of writing, VMware \nPlayer was available at: http://www.vmware.com/products/player/. You will \nneed to register for an account to download the software, but the registration \nprocess is simple and free.\nIf you are unsure of which option to choose, it is suggested that you go the \nVMware route. Not only is this another good technology to learn, but using \nVMs will allow you to set up an entire penetration testing lab on a single \nmachine. If that machine is a laptop, you essentially have a “travelling” PT lab \nso you can practice your skills anytime, anywhere.\nIf you choose to run Backtrack using the bootable DVD, shortly after the sys-\ntem starts, you will be presented with a menu list. You will need to review the \nlist carefully, as it contains several different options. The first couple of options \nare used to set some basic information about your system’s screen resolution. \nIf you are having trouble getting Backtrack to boot, be sure to choose the “Start \nBacktrack in Safe Graphical Mode.” The menu contains several other options, \nbut these are outside the scope of this book. To select the desired boot option, \nsimply use the arrow keys to highlight the appropriate row and hit the enter \nkey to confirm your selection. Figure 1.1 shows an example of the Backtrack \nboot screen.\nThe use of Backtrack is not required to work through this book or to learn the \nbasics of hacking. Any version of Linux will do fine. The major advantage of \nusing Backtrack is that all the tools are preloaded for you. If you choose to use \na different version of Linux, you will need to install the tools before reading \nthe chapter. It is also important to remember that because this book focuses on \nthe basics, it does not matter which version of Backtrack you are using. All the \ntools we will explore and use in this book are available in every version.\nWORKING WITH BACKTRACK: STARTING THE ENGINE\nRegardless of whether you choose to run Backtrack as a VM or boot to a Live \nDVD, once the initial system is loaded you will be presented with a log-in \nprompt. The default username is root and the default password is toor.\nFIGURE 1.1\nA Screenshot Showing the Boot Options When Using the Live DVD.\n"
}
|
{
"page_number": 26,
"text": "What Is Penetration Testing? CHAPTER 1\n7\nNotice the default password is simply “root” spelled backward. This default \nusername and password combination has been in use since Backtrack 1, and \nmost likely it will remain in use for future versions. At this point, you should \nbe logged into the system and should be presented with “root@bt:~#” \nprompt. Although it is possible to run many of the tools we will discuss in this \nbook directly from the terminal, it is often easier for newcomers to make use \nof the X Window System. You can start the GUI by typing the following com-\nmand after the “root@bt~#” prompt:\nstartx\nAfter typing this command and hitting the Enter key, X will begin to load. This \nenvironment should seem vaguely familiar to most computer users. Once it \nhas completely loaded, you will see a desktop, icons, a task bar, and a system \ntray. Just like Microsoft Windows, you can interact with these items by moving \nyour mouse cursor and clicking on the desired object.\nMost of the programs we will use in this book will be run out of the termi-\nnal. You can start a terminal session by either clicking on the black box located \nin the lower left in the taskbar, or by typing the following command into the \nlauncher as shown in Figure 1.2.\nkonsole\nUnlike Microsoft Windows or many of the modern-day Linux OS’s, by default, \nBacktrack does not come with networking enabled. This setup is by design. \nAs a penetration tester, we often try to maintain a stealthy or undetected pres-\nence. Nothing screams “LOOK AT ME!! LOOK AT ME!! I’M HERE!!!” like a \ncomputer that starts up and instantly begins spewing network traffic by broad-\ncasting requests for a DHCP server and IP address. To avoid this issue, the net-\nworking interfaces of your Backtrack machine are turned down (off) by default.\nThe easiest way to enable networking is through the terminal. Open a terminal \nwindow by clicking on the terminal icon as shown by the leftmost arrow in \nFigure 1.2. Once the terminal opens, enter the following command:\nifconfig –a\nThis command will list all the available interfaces for your machine. At a \nminimum, most machines will include an eth0 and a lo interface. The “lo” \nFIGURE 1.2\nTwo Ways to Launch the Konsole (Terminal).\n"
}
|
{
"page_number": 27,
"text": "The Basics of Hacking and Penetration Testing\n8\ninterface is your loopback interface. The “eth0” is your first ethernet card. \nDepending on your hardware, you may have additional interfaces or differ-\nent interface numbers listed. If you are running Backtrack through a VM, your \nmain interface will usually be eth0.\nTo turn the network card on, you enter the following command into a terminal \nwindow:\nifconfig eth0 up\nLet us examine this command in more detail; “ifconfig” is a Linux command \nthat means “I want to configure a network interface.” As we already know, \n“eth0” is the first network device on our system (remember computers often \nstart counting at 0 not 1), and the keyword “up” is used to activate the inter-\nface. So we can roughly translate the command you entered as “I want to con-\nfigure the first interface to be turned on.”\nNow that the interface is turned on, we need to get an IP address. There are \ntwo basic ways to complete this task. Our first option is to assign the address \nmanually by appending the desired IP address to the end of the previous com-\nmand. For example, if we wanted to assign our network card an IP address of \n192.168.1.23, we would type:\nifconfig eth0 up 192.168.1.23\nAt this point, the machine will have an IP address but will still need a gateway \nand Domain Name System (DNS) server. A simple Google search for “setting \nup nic linux” will show you how to enter that information. You can always \ncheck to see if your commands worked by issuing the following command into \na terminal window:\nifconfig\nRunning this will allow you to see the current settings for your network inter-\nfaces. Because this is a beginner’s guide and for the sake of simplicity, we will \nassume that stealth is not a concern at the moment. In that case, the easiest \nway to get an address is to use DHCP. To assign an address through DHCP, you \nsimply issue the command:\ndhclient eth0\nPlease note, this assumes you have already successfully run the command to \nturn up your network interface (eth0 in this case).\nNow that we have successfully assigned an IP address, the last thing to address \nis how to turn off Backtrack. As with most things in Linux, there are multiple \nways to accomplish this task. One of the easiest ways is to enter the following \ncommand into a terminal window:\npoweroff\nYou can also substitute the poweroff command with the reboot command if \nyou would prefer to restart the system rather than shut it down.\n"
}
|
{
"page_number": 28,
"text": "What Is Penetration Testing? CHAPTER 1\n9\nBefore proceeding, you should take several minutes to review and practice all \nthe steps highlighted thus far including\nn\t Power on/Start up Backtrack\nn\t Log in with the default user name and password\nn\t Start X (the windows GUI)\nn\t View all the network interfaces on your machine\nn\t Turn up (on) the desired network interface\nn\t Assign an IP address manually\nn\t View the manually assigned IP address\nn\t Assign an IP address through DHCP\nn\t View the dynamically assigned address\nn\t Reboot the machine using the command line interface\nn\t Poweroff the machine using the command line interface\nTHE USE AND CREATION OF A HACKING LAB\nEvery ethical hacker must have a place to practice and explore. Most newcomers \nare confused about how they can learn to use hacking tools without breaking the \nlaw or attacking unauthorized targets. This is most often accomplished through \nthe creation of a personal “hacking lab.” A hacking lab is a sandboxed environ-\nment where your traffic and attacks have no chance of escaping or reaching unau-\nthorized and unintended targets. In this environment, you are free to explore \nall the various tools and techniques without fear that some traffic or attack will \nescape your network. At a minimum, the lab is set up to contain at least two \nmachines: one attacker and one victim. In other configurations, several victim \nmachines can be deployed simultaneously to simulate a more realistic network.\nThe proper use and setup of a hacking lab is vital because one of the most \neffective means to learn something is by doing that thing. Learning and master-\ning the basics of penetration testing is no different.\nThe single most crucial point of any hacker lab is the isolation of the network. \nYou must configure your lab network in such a way that it is impossible for \ntraffic to escape or travel outside of the network. Mistakes happen and even \nthe most careful people can fat-finger or mistype an IP address. It is a simple \nmistake to mistype a single digit in an IP address, but that mistake can have \ndrastic consequences for you and your future. It would be a shame (and more \nimportantly illegal) for you to run a series of scans and attacks against what \nyou thought was your hacker lab target with an IP address of 172.16.1.1 only to \nfind out later that you actually entered the IP address as 122.16.1.1.\nThe simplest and most effective way to create a sandboxed or isolated environ-\nment is to physically unplug or disconnect your network from the Internet. If \nyou are using physical machines, it is best to rely on hardwired Ethernet cables \nand switches to route traffic. Also be sure to double- and triple-check that all of \nyour wireless NICs are turned off. Always carefully inspect and review your net-\nwork for potential leaks before continuing.\n"
}
|
{
"page_number": 29,
"text": "The Basics of Hacking and Penetration Testing\n10\nAlthough the use of physical machines to create a hacking lab is an accept-\nable solution, the use of virtual machines provides several key benefits. First, \ngiven today’s processing power, it is easy to set up and create a mini hacking \nlab on a single machine or laptop. In most cases, an average machine can run \ntwo or three virtual machines simultaneously because our targets can be set \nup using minimal resources. Even running on a laptop, it is possible to run \ntwo virtual machines at the same time. The added benefit of using a laptop is \nthe fact that your lab is portable. With the cheap cost of external storage today, \nit is easily possible to pack hundreds of virtual machines on a single external \nhard drive; these can be easily transported and set up in a matter of minutes. \nAnytime you are interested in practicing your skills or exploring a new tool, \nsimply open up Backtrack and deploy a VM as a target. Setting up a lab like this \ngives you the ability to quickly plug-and-play with various operating systems \nand configurations.\nAnother benefit of using virtual machines in your pen testing lab is the fact \nthat it is very simple to sandbox your entire system. Simply turn off the wire-\nless card and unplug the cable from the Internet. Your physical machine and \nvirtual machines will still be able to communicate with each other and you can \nbe certain that no attack traffic will leave your physical machine.\nIn general, penetration testing is a destructive process. Many of the tools and \nexploits we run can cause damage or take systems offline. In some cases, it is \neasier to reinstall the OS or program rather than attempt to repair it. This is \nanother area where VMs shine. Rather than having to physically reinstall a pro-\ngram like SQL server or even an entire operating system, the VM can be quickly \nreset or restored to its original configuration.\nPHASES OF A PENETRATION TEST\nLike most things, the overall process of penetration testing can be broken \ndown into a series of steps or phases. When put together, these steps form a \ncomprehensive methodology for completing a penetration test. Careful review \nof unclassified incident response reports or breech disclosures supports the \nidea that most black hat hackers also follow a process when attacking a target. \nThe use of an organized approach is important because it not only keeps the \npenetration tester focused and moving forward but also allows the results or \noutput from each step to be used in the ensuing steps.\nThe use of a methodology allows you to break down a complex process into a \nseries of smaller more manageable tasks. Understanding and following a meth-\nodology is an important step in mastering the basics of hacking. Depending \non the literature or class you are taking, this methodology usually contains \nbetween four and seven steps or phases. Although the overall names or num-\nber of steps can vary between methodologies, the important thing is that \nthe process provides a complete overview of the penetration testing process. \n"
}
|
{
"page_number": 30,
"text": "What Is Penetration Testing? CHAPTER 1\n11\nFor example, some methodologies use the term “Information Gathering,” \nwhereas others call the same process “Reconnaissance.” For the purpose of this \nbook, we will focus on the activities of the phase rather than the name. After \nyou have mastered the basics, you can review the various penetration testing \nmethodologies and choose one that you like best.\nTo keep things simple, we will use a four-step process to explore and learn \npenetration testing. If you search around and examine other methodologies \n(which is important to do), you may find processes that include more or less \nsteps than we are using as well as different names for each of the phases. It \nis important to understand that although the specific terminology may differ, \nmost solid penetration testing methodologies cover the same topics.\nThere is one exception to this rule: the final step in many hacking methodolo-\ngies is a phase called “hiding,” “covering your tracks,” or “removing evidence.” \nBecause this book focuses on understanding the basics, it will not be included \nin this methodology. Once you have a solid understanding of the basics, you \ncan go on to explore and learn more about this phase.\nThe remainder of this book will be dedicated to reviewing and teaching the fol-\nlowing steps: Reconnaissance, Scanning, Exploitation, and Maintaining Access. \nSometimes, it helps to visualize these steps as an inverted triangle. Figure 1.3 \ndemonstrates this approach. The reason we use an inverted triangle is because \nthe outcome of initial phases is very broad. As we move down into each phase, \nwe continue to drill down to very specific details.\nThe inverted triangle works well because it represents our journey from the \nbroad to the specific. For example, as we work through the reconnaissance \nphase, it is important to cast our nets as wide as possible. Every detail and every \npiece of information about our target is collected and stored. The penetration \ntesting world is full of many great examples when a seemingly trivial piece of \nReconnaissance\nPort Scanning\nVulnerability Scanning\nScanning\nExploitation\nMaintaining Access\nFIGURE 1.3\nZero Entry Hacking Penetration (ZEH) Testing Methodology.\n"
}
|
{
"page_number": 31,
"text": "The Basics of Hacking and Penetration Testing\n12\ninformation was collected in the initial phase and later turned out to be a cru-\ncial component for successfully completing an exploit and gaining access to \nthe system. In later phases, we begin to drill down and focus on more specific \ndetails of the target. Where is the target located? What is the IP address? What \noperating system is the target running? What services and versions of software \nare running on the system? As you can see, each of these questions becomes \nincreasingly more detailed and granular.\nIt is also important to understand the order of each step. The order in which \nwe conduct the steps is very important because the result or output of one step \nneeds to be used in the step below it. You need to understand more than just \nhow to simply run the security tools in this book. Understanding the proper \nsequence in which they are run is vital to performing a comprehensive and \nrealistic penetration test.\nFor example, many newcomers skip the Reconnaissance phase and go straight \nto exploiting their target. Not completing steps 1 and 2 will leave you with a \nsignificantly smaller target list and attack vector on each target. In other words, \nyou become a one-trick-pony. Although knowing how to use a single tool \nmight be impressive to your friends and family, it is not to the security commu-\nnity and professionals who take their job seriously.\nIt may also be helpful for newcomers to think of the steps we will cover as a \ncircle. It is very rare to find critical systems exposed directly to the Internet in \ntoday’s world. In many cases, penetration testers must access and penetrate a \nseries of related targets before they have a path to reach the original target. In \nthese cases, each of the steps is often repeated. Figure 1.4 introduces the meth-\nodology as a cyclical process.\nFIGURE 1.4\nCyclical Representation of the ZEH Methodology.\n"
}
|
{
"page_number": 32,
"text": "What Is Penetration Testing? CHAPTER 1\n13\nZero Entry Hacking: A Four-Step Model\nLet us briefly review each of the four steps that will be covered so you have a \nsolid understanding of them. The first step in any penetration test is “recon-\nnaissance.” This phase deals with information gathering about the target. As \nwas mentioned previously, the more information you collect on your target, \nthe more likely you are to succeed in later steps. Reconnaissance will be dis-\ncussed in detail in Chapter 2.\nRegardless of the information you had to begin with, after completing in-\ndepth reconnaissance you should have a list of target IP addresses that can be \nscanned. The second step in our methodology can be broken out into two dis-\ntinct activities. The first activity we conduct is port scanning. Once we have fin-\nished with port scanning, we will have a list of open ports and potential service \nrunning on each of the targets. The second activity in the scanning phase is vul-\nnerability scanning. Vulnerability scanning is the process of locating and iden-\ntifying specific weaknesses in the software and services of our targets.\nWith the results from step 2 in hand, we continue to the “exploitation” phase. \nOnce we know exactly what ports are open, what services are running on those \nports, and what vulnerabilities are associated with those services, we can begin \nto attack our target. This is the phase that most newcomers associate with \n“real” hacking. Exploitation can involve lots of different techniques, tools, and \ncode. We will review a few of the most common tools in Chapter 4. The ulti-\nmate goal of exploitation is to have administrative access (complete control) \nover the target machine.\nThe final phase we will examine is “maintaining access.” Oftentimes, the \npayloads delivered in the exploitation phase provide us with only tempo-\nrary access to the system. Because most payloads are not persistent, we need \nto create a more permanent backdoor to the system. This process allows our \nadministrative access to survive program closures and even reboots. As an ethi-\ncal hacker, we must be very careful about the use and implementation of this \nphase. We will discuss how to complete this step as well as the ethical implica-\ntions of using backdoor or remote control software.\nAlthough not included as a formal step in the penetration testing methodol-\nogy, the final (and arguably the most important) activity of every PT is the \nreport. Regardless of the amount of time and planning you put into conduct-\ning the penetration test, the client will often judge your work and effectiveness \non the basis of the quality of your report. The final PT report should include all \nthe relevant information uncovered in your test and explain in detail how the \ntest was conducted and what was done during the test. Whenever possible, mit-\nigations and solutions should be presented for the security issues you uncov-\nered. Finally, an executive summary should be included in every PT report. The \npurpose of this summary is to provide a simple one- to two-page, nontechni-\ncal overview of your findings. This report should highlight and briefly sum-\nmarize the most critical issues your test uncovered. It is vital that this report \n"
}
|
{
"page_number": 33,
"text": "The Basics of Hacking and Penetration Testing\n14\nbe readable (and comprehendible) by both technical and nontechnical person-\nnel. It is important not to fill the executive summary with too many technical \ndetails; that is the purpose of the detailed report.\nCHAPTER REVIEW\nThis chapter introduced the concept of penetration testing and hacking as a \nmeans of securing systems. It also discussed the various roles and charac-\nters that take part in the hacking scene. The chapter examined the basics of \nBacktrack Linux including how to boot up, login, start X, get an IP address, \nand shutdown. We talked about how to set up your own isolated PT lab so you \nhave a place to practice without fear of breaking the law and we wrapped up by \nreviewing the steps of a penetration test.\nIt should be noted that there are several alternatives to Backtrack. At some \npoint, you may want to review and explore these other distributions. Matriux \nis similar to Backtrack but also includes a Windows binary directory that can be \nused and accessed directly from a Windows machine. Fedora Security Spin is a \ncollection of security-related tools built off of the Fedora distribution. KATANA \nis a multi-boot DVD that gathers a number of different tools and distributions \ninto a single location. Finally, you may want to explore the classic STD distri-\nbution as well as Pentoo and Blackbuntu. There are many other Linux pen-\netration testing distributions—a simple Google search for “Linux Penetration \nTesting Distributions” will provide you with a plethora of options. You could \nalso spend some time building and customizing your own Linux distribution \nby collecting and installing tools as your hacking career progresses.\nSUMMARY\nThis chapter introduced the concept of penetration testing and ethical hack-\ning. A special “basics only,” four-step methodology including Reconnaissance, \nScanning, Exploitation, and Maintaining Access was presented and explained. \nInformation for setting up and using Backtrack Linux including configuring \na network connection and issuing commands in a terminal window was pre-\nsented. The use and creation of a penetration testing lab was outlined. This will \nallow you to practice your skills in a safe and sandboxed environment. It will \nalso allow for completing and following along with the examples detailed in this \nbook.\n"
}
|
{
"page_number": 34,
"text": "15\nReconnaissance\nCHAPTER 2\nInformation in This Chapter:\nn\t HTTrack: Website Copier\nn\t Google Directives—Practicing Your Google-Fu\nn\t The Harvester: Discovering and Leveraging E-mail Addresses\nn\t Whois\nn\t Netcraft\nn\t Host\nn\t Extracting Information from DNS\nn\t Extracting Information from E-mail Servers\nn\t MetaGooFil\nn\t Social Engineering\nn\t Sifting through the Intel to Finding Attackable Targets\n"
}
|
{
"page_number": 35,
"text": "The Basics of Hacking and Penetration Testing\n16\nIntroduction\nIn most cases people who attend hacking workshops or classes have a basic \nunderstanding of a few security tools. Typically, these students have used a \nport scanner to examine a system or maybe they have used Wireshark to exam-\nine network traffic. Some have even played around with exploit tools like \nMetasploit. Unfortunately, most beginners do not understand how these tools \nfit into the grand scheme of a penetration test. As a result, their knowledge is \nincomplete. Following a methodology ensures that you have a plan and know \nwhat to do next.\nTo stress the importance of using and following a methodology, it is often ben-\neficial to describe a scenario that helps demonstrate both the importance of \nthis step and the value of following a complete methodology when conducting \na penetration test.\nAssume you are an ethical penetration tester working for a security \ncompany. Your boss walks over to your office and hands you a piece of \npaper. “I just got off the phone with the CEO of that company. He wants \nmy best employee to Pen Test his company – that’s you. Our Legal \nDepartment will be sending you an email confirming we have all of the \nproper authorizations and insurance”. You nod, accepting the job. He \nleaves. You flip over the paper, a single word is written on the paper, \n“Syngress.” It’s a company you’ve never heard of before, and no other \ninformation is written on the paper.\nWhat now?\nThe first step in every job is research. The more thoroughly you prepare for a \ntask, the more likely you are to succeed. The guys who created Backtrack Linux \nare fond of quoting Abraham Lincoln who said, “If I had six hours to chop \ndown a tree, I’d spend the first four of them sharpening my axe.” This is a per-\nfect introduction to both penetration testing and the reconnaissance phase.\nReconnaissance, also known as information gathering, is arguably the most \nimportant of the four phases we will discuss. The more time you spend col-\nlecting information on your target, the more likely you are to be successful in \nthe later phases. Ironically, recon is also one of the most overlooked, underuti-\nlized, and misunderstood steps in PT methodologies today.\nIt is possible that this phase is overlooked because newcomers are never for-\nmally introduced to the concept, its rewards, or how the results of good infor-\nmation gathering can be vital in later steps. It is also possible that this phase is \noverlooked because it is the least “technical.” Oftentimes, people who are new \nto hacking tend to view this phase as boring and unchallenging. Nothing could \nbe further from the truth.\nAlthough it is true that there are very few good, automated tools that can be \nused to complete recon, once you understand the basics it is like an entirely \nnew way of looking at the world. A good information gatherer is made up of \nequal parts: hacker, social engineer, and private investigator. Aside from the lack \n"
}
|
{
"page_number": 36,
"text": "Reconnaissance CHAPTER 2\n17\nof tools, the absence of well-defined rules of engagement also distinguishes this \nphase from all others. This is in stark contrast to the remaining steps in our \nmethodology. For example, when we discuss scanning in Chapter 3, there is a \nspecific order and a clear series of steps that need to be followed in order to \nproperly port scan a target.\nLearning how to conduct digital reconnaissance is a valuable skill for anyone \nliving in today’s world. For penetration testers and hackers, it is invaluable. \nThe penetration testing world is filled with great examples and stories of how \ngood recon single-handedly allowed the tester to fully compromise a network \nor system.\nConsider the following example: assume we have two different criminals who \nare planning to rob a bank. The first criminal buys a gun and runs into the \nfirst bank he finds yelling “HANDS UP! GIVE ME ALL YOUR MONEY!” It is \nnot hard to imagine that the scene would be complete chaos and even if the \nbungling burglar managed to get away, it probably would not take long for the \npolice to find him, arrest him, and send him to prison. Contrast this to nearly \nevery Hollywood movie in existence today where criminals spend months \nplanning, scheming, organizing, and reviewing details before the heist. They \nspend time getting weapons anonymously, planning escape routes, and review-\ning schematics of the building. They visit the bank to determine the position of \nthe security cameras, make note of the guards, and determine when the bank \nhas the most money or is the most vulnerable. Clearly, the second criminal has \nthe better chance of getting away with the money.\nIt should be obvious that the difference between these two examples is prepa-\nration and homework. Hacking and penetration testing is the same—you can-\nnot just get an IP address and start running Metasploit (well you can, but you \nare probably not going to be very effective).\nRecall the example used to begin this chapter. You had been assigned to \ncomplete a penetration test but were given very little information to go on. \nAs a matter of fact, you were given only the company name, one word. The \nmillion-dollar question for every aspiring hacker is, “How do I go from a single \ncompany name to owning the systems inside the network?” When we begin, \nwe know virtually nothing about the organization; we do not know their web-\nsite, physical address, or number of employees. We do not know their public \nIP addresses or internal IP schemes; we know nothing about the technology \ndeployed, operating systems used, or defenses.\nStep 1 begins by conducting a thorough search of public information. The great \nthing about this phase is that in most cases, we can gather a significant amount \nof data without ever sending a single packet to the target. Although it should \nbe pointed out that some tools or techniques used in reconnaissance do in fact \nsend information directly to the target, it is important to know the difference \nbetween which tools do and which tools do not touch the target. There are two \nmain goals in this phase: first, we need to gather as much information as pos-\nsible about the target; second, we need to sort through all the information gath-\nered and create a list of attackable IP addresses.\n"
}
|
{
"page_number": 37,
"text": "The Basics of Hacking and Penetration Testing\n18\nIn Chapter 1, it was pointed out that a major difference between black hat and \nwhite hat attackers is authorization. Step 1 provides us with a prime example of \nthis. Both types of hackers conduct exhaustive reconnaissance on their targets. \nUnfortunately, malicious hackers are bound by neither scope nor authorization.\nWhen ethical hackers conduct research, they are required to stay within \nthe confines of the test. During the information gathering process, it is not \nunheard-of for a hacker to uncover a vulnerable system that is related to the tar-\nget but not owned by the target. Even if the related target could provide access \ninto the original organization, without prior authorization, a white hat hacker \nis not allowed to use or explore this option. For example, let us assume that \nyou are doing a penetration test against a company and you determine that \ntheir web server (which contains customer records) is outsourced or managed \nby a third party. If you find a serious vulnerability on the customer’s website, \nbut you have not been explicitly authorized to test and use the website, you \nmust ignore it. The black hat attackers are bound by no such rules and will use \nany means possible to access the target systems. In most cases, because you \nwere not authorized to test and examine these outside systems, you will not be \nable to provide a lot of detail; however, your final report must include as much \ninformation as possible about any systems that you believe put the organiza-\ntion at risk.\nTo be successful at reconnaissance, you must have a strategy. Nearly all facets \nof information gathering leverage the power of the Internet. A typical strategy \nneeds to include both active and passive reconnaissance.\nActive reconnaissance includes interacting directly with the target. It is important \nto note that during this process, the target may record our IP address and log \nour activity.\nPassive reconnaissance makes use of the vast amount of information available \non the web. When we are conducting passive reconnaissance, we are not inter-\nacting directly with the target and as such, the target has no way of knowing, \nrecording, or logging our activity.\nAs mentioned, the goal of reconnaissance is to collect as much information as \npossible on your target. At this point in the penetration test, no detail should \nbe overlooked regardless of how innocuous it may seem. While you are gath-\nering information, it is important to keep your data in a central location. \nWhenever possible, it is helpful to keep the information in electronic format. \nThis allows for quick and accurate searches later on. Every hacker is a bit dif-\nferent and there are still several hackers who prefer to print out all the infor-\nmation they gather. Each piece of paper is carefully cataloged and stored in a \nfolder. If you are going to use the traditional paper method, be sure to carefully \norganize your records. Paper-based information gathering binders on a single \ntarget can quickly grow to several hundred pages.\nIn most cases, the first activity is to locate the target’s website. In our example, \nwe would use a search engine to look for “Syngress.”\n"
}
|
{
"page_number": 38,
"text": "Reconnaissance CHAPTER 2\n19\nHTTrack: Website Copier\nTypically, we begin step 1 by closely reviewing the target’s website. In some \ncases, we may actually use a tool called HTTrack to make a page-by-page copy \nof the website. HTTrack is a free utility that creates an identical, off-line copy \nof the target website. The copied website will include all the pages, links, pic-\ntures, and code from the original website; however, it will reside on your local \nFIGURE 2.1\nAccessing the Newly Installed HTTrack.\nAdditional Resources\nIt is important to understand that the more time you spend navigating and exploring \nthe target website, the more likely it is that your activity can be tracked or traced \n(even if you are simply browsing the site). Remember anytime you interact directly \nwith a resource owned by the target, there is a chance you will leave a digital \nfingerprint behind.\nAdvanced penetration testers can also run automated tools to extract additional or \nhidden information from a local copy of a website.\nHTTrack can be downloaded directly from the company’s website at: http://www.\nhttrack.com/. Installing for Windows is as simple as downloading the installer .exe \nand clicking next. If you want to install HTTrack in Backtrack, you can connect to the \nInternet as we described in Chapter 1, open a terminal, and type:\napt-get install webhttrack\nOnce the program is installed in, you can find it by clicking: Kstart → Internet → \nWebHTTrack Website Copier, as shown in Figure 2.1.\nThe “Kstart” is the small dragon icon in the lower left of the screen. This provides you \naccess to many of the tools included with Backtrack. The Kstart button is similar to \nthe Windows or Start button found in many Microsoft operating systems.\n"
}
|
{
"page_number": 39,
"text": "The Basics of Hacking and Penetration Testing\n20\ncomputer. Utilizing a website copying tool like HTTrack allows us to explore \nand thoroughly mine the website “off-line” without having to spend additional \ntime traipsing around on the company’s web server.\nAfter we have installed the program, we need to run it against our target. Please \nbe aware that this activity is easy to trace and considered highly offensive. Never \nrun this tool without prior authorization. Once HTTrack is started, we are pre-\nsented with a number of web pages that allow us to set up and customize the \ncopy process. Each page allows us to change various aspects of the program \nincluding language (English is default), project name, the location where we \nwill store the copied website, and the web address of the site you would like \nto copy. You can work your way through each of these pages by making the \ndesired changes to each option and clicking the “Next” button. The final page \nwill include a “Start” button, click this when you are ready to begin making a \ncopy of your target’s website. The amount of time it takes for this process to \ncomplete will depend on the size of your target’s website. Once HTTrack has \nfinished copying the target website, it will present you with a webpage allow-\ning you to “Browse the Mirrored Website” in a browser or navigate to the path \nwhere the site was stored.\nWhether you make a copy of the target website or you simply browse the tar-\nget in real time, it is important to pay attention to details. You should begin \nby closely reviewing and recording all the information you find on the target’s \nwebsite. Oftentimes, with very little digging you will be able to make some sig-\nnificant findings including physical address and locations, phone numbers, \ne-mail addresses, hours of operation, business relationships (partnerships), \nemployee names, social media connections, and other public tidbits.\nOftentimes when conducting a penetration test, it is important to pay spe-\ncial attention to things like “News” or “Announcements.” Companies are \noften proud of their achievements and unintentionally leak useful informa-\ntion through these stories. Company mergers and acquisitions can also yield \nvaluable data; this is especially important for expanding the scope and adding \nadditional targets to our penetration test. Even the smoothest of acquisitions \ncreates change and disarray in an organization. There is always a transition \nperiod when companies merge. This transition period provides us with unique \nopportunities to take advantage of the change and confusion. Even if merger \nis old news or goes off without a hitch, the information still provides value by \ngiving us additional targets. Merged or sibling companies should be authorized \nand included in the original target list, as they provide a potential gateway into \nthe organization.\nFinally, it is important to search and review any open job postings for the tar-\nget company. Job postings often reveal very detailed information about the \ntechnology being used by an organization. Many times you will find specific \nhardware and software listed on the job opening. Do not forget to search for \nyour target in the nationwide job banks as well. For example, assume you \ncome across a job requisition looking for a Network Administrator with Cisco \n"
}
|
{
"page_number": 40,
"text": "Reconnaissance CHAPTER 2\n21\nASA experience. From this post, you can draw some immediate conclusions \nand make some educated guesses. First, you can be certain that the company \neither uses, or is about to use, a Cisco ASA firewall. Second, depending on the \nsize of the organization, you may be able to infer that the company does not \nhave, or is about to lose, someone with knowledge of how to properly use and \nconfigure a Cisco ASA firewall. In either case, you have gained valuable knowl-\nedge about the technology in place.\nIn most cases, once we have thoroughly examined the target’s website, we \nshould have a solid understanding of the target including who they are, what \nthey do, and where they are located.\nArmed with this basic information about the target, we move into passive \nreconnaissance. It is very difficult, if not impossible, for a company to deter-\nmine when a hacker or penetration tester is conducting passive reconnaissance. \nThis activity offers a low-risk, high-reward situation for attackers. Recall that \npassive reconnaissance is conducted without ever sending a single packet to \nthe target systems. Our weapon of choice to perform this task is the Internet. \nWe begin by performing exhaustive searches of our target in the various search \nengines available.\nAlthough there are many great search engines available today, when covering \nthe basics of hacking and penetration testing, we will focus on Google. Google \nis very, very good at its job. There is a reason why the company’s stock trades \nfor $400$600 a share. Spiders from the company aggressively and repeatedly \nscour all corners of the Internet cataloging information and send it back to the \nGoogle. The company is so efficient at its job, that oftentimes hackers can per-\nform an entire penetration test using nothing but Google.\nAt Defcon 13 Johnny Long rocked the hacker community by giving a talk titled \n“Google Hacking for Penetration Testers.” This talk was followed up by a book \nthat dove even deeper into the art of Google Hacking.\nAlthough we would not dive into the specifics of Google Hacking, a solid \nunderstanding of how to properly use Google is vital to becoming a skilled \npenetration tester. If you ask people, “How do you use Google?” they typically \nrespond by saying, “Well it’s simple…You fire up a web browser, navigate to \nGoogle, and type what you’re searching for in the box.”\nAdditional Resources\nIf you are interested in penetration testing, it is highly suggested that you watch the \nvideo and buy the book. You can see the video for free online (check the Defcon \nmedia archive), and the book is published by Syngress and available nearly anywhere. \nJohnny’s discoveries have changed penetration testing and security forever. Johnny’s \nmaterial is awesome and well worth your time.\n"
}
|
{
"page_number": 41,
"text": "The Basics of Hacking and Penetration Testing\n22\nAlthough this answer is fine for 99 percent of the planet, it is not good enough \nfor aspiring hackers. You have to learn to search in a smarter way and maxi-\nmize the return results. In short, you must cultivate your Google-Fu. Learning \nhow to properly use a search engine like Google will save you time and allow \nyou to find the hidden gems that are buried in the trillions of web pages on the \nInternet today.\nGoogle directives—practicing your \nGoogle-Fu\nLuckily for us, Google provides “directives” that are easy to use and help us get \nthe most out of every search. These directives are keywords that enable us to \nmore accurately extract information from the Google Index.\nConsider the following example: assume you are looking for information on \nthe Dakota State University website (dsu.edu) about me. The simplest way to \nperform this search is to enter the following terms (without the quotes) in a \nGoogle search box: “pat engebretson dsu.” This search will yield a fair number \nof hits. However of the first 50 websites returned, only four were pulled directly \nfrom the DSU website.\nBy utilizing Google directives, we can force the Google Index to do our bid-\nding. In the example above we know both the target website and the keywords \nwe want to search. More specifically, we are interested in forcing Google to \nreturn only results that are pulled directly from the target (dsu.edu) domain. In \nthis case, our best choice is to utilize the “site:” directive. Using the “site:” direc-\ntive forces Google to return only hits that contain the keywords we used and \ncome directly from the specified website.\nTo properly use a Google directive, you need three things:\n1.\t The name of the directive you want to use\n2.\t A colon\n3.\t The term you want to use in the directive\nAfter you have entered the three pieces of information above, you can search \nas you normally would. To utilize the “site:” directive, we need to enter the fol-\nlowing into a Google search box:\nsite:domain term(s) to search\nNote that there is no space between the directive, colon, and domain. In our \nearlier example we wanted to conduct a search for Pat Engebretson on the DSU \nwebsite. To accomplish this, we would enter the following command into the \nGoogle search bar:\nsite:dsu.edu pat engebretson\nRunning this search provides us with drastically different results than our ini-\ntial attempt. First, we have trimmed the overall number of hits from 600 \n"
}
|
{
"page_number": 42,
"text": "Reconnaissance CHAPTER 2\n23\nto about 50. There is little doubt that a person can sort through and gather \ninformation from 50 hits much quicker than 600. Second and possibly more \nimportantly, every single returned result comes directly from the target website. \nUtilizing the “site:” directive is a great way to search a specific target and look \nfor additional information. This directive allows you to avoid search overload \nand to focus your search.\nAnother good Google directive to use is “intitle:” or “allintitle:”. Adding either \nof these to your search causes only websites that have your search words in the \ntitle of the webpage to be returned. The difference between “intitle:” and “allin-\ntitle:” is straightforward. “allintitle:” will only return websites that contain all \nthe keywords in the web page title. The “intitle:” directive will return any page \nwhose title contains at least one of the keywords you entered.\nA classic example of putting the “allintitle:” Google hack to work is to perform \nthe following search:\nallintitle:index of\nPerforming this search will allow us to view a list of any directories that have \nbeen indexed and are available via the web server. This is often a great place to \ngather reconnaissance on your target.\nIf we want to search for sites that contain specific words in the URL, we can \nuse the “inurl:” directive. For example, we can issue the following command to \nlocate potentially interesting pages on our target’s web page:\ninurl:admin\nThis search can be extremely useful in revealing administrative or configuration \npages on your target’s website.\nIt can also be very valuable to search the Google cache rather than the target’s \nwebsite. This process not only reduces your digital footprints on the target’s \nserver, making it harder to catch you, it also provides a hacker with the occa-\nsional opportunity to view web pages and files that have been removed from \nthe original website. The Google cache contains a stripped-down copy of each \nwebsite that the Google bots have spidered. It is important to understand that \nthe cache contains both the code used to build the site and many of the files \nthat were discovered during the spidering process. These files can be PDFs, MS \nOffice documents like Word and Excel, text files, and more.\nIt is not uncommon today for information to be placed on the Internet \nby mistake. Consider the following example. Suppose you are a network \nAlert!\nIt is worth noting that all searches in Google are case insensitive so “pat,” “Pat,” and \n“PAT” will all return the same results!\n"
}
|
{
"page_number": 43,
"text": "The Basics of Hacking and Penetration Testing\n24\nadministrator for a company. You use MS Excel to create a simple workbook \ncontaining all the IP addresses, computer names, and locations of the PCs in \nyour network. Rather than carrying this Excel spreadsheet around, you decide \nto publish it to the intranet where it will be accessible only by people within \nyour organization. However, rather than publishing this document to the \nintranet website, you mistakenly publish it to the company Internet website. \nIf the Google bots spider your site before you take this file down, it is possible \nthe document will live on in the Google cache even after you have removed it \nfrom your site. As a result, it is important to search the Google cache too.\nWe can use the cache: directive to limit our search results and show only infor-\nmation pulled directly from the Google cache. The following search will pro-\nvide us with the cached version of the Syngress homepage:\ncache:syngress.com\nIt is important that you understand that clicking on any of the URLs will bring \nyou to the live website, not the cached version. If you want to view specific \ncached pages, you will need to modify your search.\nThe last directive we will cover here is “filetype:”. We can utilize “filetype:” to \nsearch for specific file extensions. This is extremely useful for finding specific \ntypes of files on your target’s website. For example, to return only hits that con-\ntain PDF documents, you would issue the following command:\nfiletype:pdf\nThis powerful directive is a great way to find links to specific files like .doc, xlsx, \nppt, txt, and many more. Your options are nearly limitless.\nFor additional power, we can combine multiple directives into the same search. \nFor example, if we want to find all the PowerPoint presentations on the DSU \nwebsite, you would enter the following command into the search box:\nsite:dsu.edu filetype:ppt\nIn this case, every result that is returned is a PPT file and comes directly from \nthe dsu.edu domain! Figure 2.2 shows a screenshot of two searches: the first \nFIGURE 2.2\nThe Power of Google Directives.\n"
}
|
{
"page_number": 44,
"text": "Reconnaissance CHAPTER 2\n25\nutilizes Google directives and the second shows the results from a traditional \nsearch. Utilizing Google directives has drastically reduced the number of hits \n(by 33,364!).\nThere are many other types of directives and Google hacks that you should \nbecome familiar with. Along with Google, it is important that you become \nefficient with several other search engines as well. Oftentimes, different search \nengines will provide different results, even when you search for the same key-\nwords. As a penetration tester conducting reconnaissance, you want to be as \nthorough as possible.\nAs a final warning, it should be pointed out that these passive searches are only \npassive as long as you are searching. Once you make a connection with the \ntarget system (by clicking on any of the links), you are back to active mode. Be \naware that active reconnaissance without prior authorization is likely an illegal \nactivity.\nOnce you have thoroughly reviewed the target’s web page and conducted \nexhaustive searches utilizing Google and other search engines, it is important to \nexplore other corners of the Internet. Newsgroups and Bulletin Board Systems \nlike UseNet and Google Groups can be very useful for gathering information \nabout a target. It is not uncommon for people to use these discussion boards \nto post and receive help with technical issues. Unfortunately (or fortunately, \ndepending on which side of the coin you are looking at), employees often \npost very detailed questions including sensitive and confidential information. \nFor example, consider a network administrator who is having trouble getting \nhis firewall properly configured. It is not uncommon to witness discussions \non public forums where these admins will post entire sections of their config \nfiles. To make matters worse, many people post using their company e-mail \naddresses. This information is a virtual gold mine for an attacker.\nEven if our network admin is smart enough not to post detailed configuration \nfiles, it is hard to get support from the community without inadvertently leak-\ning some information. Reading even carefully scrubbed posts will often reveal \nspecific software version, hardware models, current configuration information, \nand the like about internal systems. All this information should be filed away \nfor future use.\nPublic forums are an excellent way to share information and receive technical \nhelp. However, when using these resources, be careful to use a slightly more \nanonymous e-mail address like Gmail or Hotmail, rather than your corporate \naddress.\nThe explosive growth in social media like Facebook, MySpace, and Twitter pro-\nvides us with new avenues to mine data about our targets. When performing \nreconnaissance, it is a good idea to use these sites to our advantage. Consider \nthe following fictitious example: You are conducting a penetration test against \na small company. Your reconnaissance has led you to discover that the network \nadministrator for the company has a Twitter and Facebook account. Utilizing a \n"
}
|
{
"page_number": 45,
"text": "The Basics of Hacking and Penetration Testing\n26\nlittle social engineering you befriend the unsuspecting admin and follow him \non both Facebook and Twitter. After a few weeks of boring posts, you strike the \njackpot. He makes a post on Facebook that says “Great. Firewalled died with-\nout warning today. New one being sent over-night. Looks like I’ll be pulling an \nall-nighter tomorrow to get things back to normal.”\nAnother example would be a PC tech who posts, “Problem with latest \nMicrosoft patch, had to uninstall. Will call MS in the morning.”\nOr even the following, “Just finished the annual budget process. Looks like I’m \nstuck with that Server 2000 for another year.”\nAlthough these examples may seem a bit over the top, you will be surprised \nat the amount of information you can collect by simply monitoring what \nemployees post online.\nThe Harvester: discovering and \nleveraging e-mail addresses\nAn excellent tool to use in reconnaissance is The Harvester. The Harvester is \na simple but highly effective Python script written by Christian Martorella at \nEdge Security. This tool allows us to quickly and accurately catalog both e-mail \naddresses and subdomains that are directly related to our target.\nIt is important to always use the latest version of the Harvester as many search \nengines regularly update and change their systems. Even subtle changes to a \nsearch engine’s behavior can render automated tools ineffective. In some cases, \nsearch engines will actually filter the results before returning information to \nyou. Many search engines also employ throttling techniques that will attempt \nto prevent you from running automated searches.\nThe Harvester can be used to search Google, Bing, and PGP servers for e-mails, \nhosts, and subdomains. It can also search LinkedIn for user names. Most peo-\nple assume their e-mail address is benign. We have already discussed the dan-\ngers of posting to public forums using your corporate e-mail address; however, \nthere are additional hazards you should be aware of. Let us assume during your \nreconnaissance you discover the e-mail address of an employee from your tar-\nget organization. By twisting and manipulating the information before the “@” \nsymbol, we should be able to create a series of potential network usernames. \nIt is not uncommon for organizations to use the exact same user names and \ne-mail addresses (before the “@” symbol). With a handful of prospective user-\nnames, we can attempt to brute force our way into any services, like SSH, VPNs, \nor FTP, that we (will) discover during the next step 2 (scanning).\nThe Harvester is built into Backtrack. To access the Harvester, use the following \nsteps:\n1.\t Click on the KStart dragon, located in the lower left corner of your screen.\n2.\t Highlight “Backtrack” at the top of the menu.\n"
}
|
{
"page_number": 46,
"text": "Reconnaissance CHAPTER 2\n27\n3.\t Highlight “Information Gathering.”\n4.\t Highlight “All.”\n5.\t Select “TheHarvester” (note, tools are listed in alphabetical order).\nYou can also open a terminal window and navigate to the Harvester directory \nby issuing the following command:\ncd /pentest/enumeration/google/theharvester\nRegardless of whether you have downloaded the Harvester or used the ver-\nsion installed in Backtrack, we will use it to collect additional information \nabout our target. Be sure you are in theHarvester folder and run the following \ncommand:\n./theHarvester.py –d syngress.com –l 10 –b google\nThis command will search for e-mails, subdomains, and hosts that belong to \nsyngress.com. Figure 2.3 shows our results.\nBefore discussing the results of our tool, let us examine the command a little \ncloser. “./theHarvester.py” is used to invoke the tool. A lowercase “–d” is \nused to specify the target domain. A lowercase “–l” (that is an L not a 1) is \nused to limit the number of results returned to us. In this case, the tool was \ninstructed to return only 10 results. The “–b“ is used to specify what public \nrepository we want to search. We can choose among Google, Bing, PGP, or \nLinkedIn—for this example, we chose to search using Google.\nNow that you fully understand the command that was run, let us take a look at \nthe results.\nAs you can see, the Harvester was effective in locating at least two e-mail \naddresses that could be of value to us. Please note, the e-mail addresses in the \nscreenshot have been circled and obfuscated. The Harvester was also successful \nAdditional Resources\nIf you are using an operating system other than Backtrack, you can download the tool \ndirectly from Edge Security at: http://www.edge-security.com. Once you have got it \ndownloaded, you can unpack the downloaded tar file by running the following command \nin a terminal:\ntar xf theHarvester\nPlease note the capital “H” that is used when untarring the code. Linux is case \nsensitive, so the operating system sees a difference between “theHarvester” and \n“theharvester.” You will need to pay attention to the executable to determine if you \nshould use a capital or lowercase “h.” If the cases do not match exactly, you will \ntypically get a message saying “no such file or directory.” This is a good indication that \nyou have mistyped the name of the file.\n"
}
|
{
"page_number": 47,
"text": "The Basics of Hacking and Penetration Testing\n28\nin finding at least two additional subdomains. Both “booksite.syngress.com” \nand “ebook__www.syngress.com” need to be fully recon’d. We simply add these \nnew domains to our target list and begin the reconnaissance process again.\nStep 1 of reconnaissance is very cyclical because in-depth reconnaissance often \nleads to the discovery of new targets, which, in turn, leads to additional recon-\nnaissance. As a result, the amount of time to complete this phase will vary \nfrom several hours to several weeks. Remember, a determined malicious hacker \nunderstands not only the power of good reconnaissance but also that of a \nnearly limitless amount of time. As an aspiring penetration tester, you should \ndevote as much time as possible to practicing and conducting information \ngathering.\nWhois\nA very simple but effective means for collecting additional information about \nour target is Whois. The Whois service allows us to access specific information \nabout our target including the IP addresses or host names of the company’s \nDomain Name Systems (DNS) servers and contact information usually con-\ntaining an address and phone number.\nWhois is built into the Linux operating system. The simplest way to use this \nservice is to open a terminal and enter the following command:\nwhois target_domain\nFIGURE 2.3\nOutput of the Harvester.\n"
}
|
{
"page_number": 48,
"text": "Reconnaissance CHAPTER 2\n29\nFor example, to find out information about Syngress, we would issue the fol-\nlowing command: “whois syngress.com.” Figure 2.4 shows a partial output \nfrom the result of this tool.\nIt is important to record all the information and pay special attention to the \nDNS servers. If the DNS servers are listed by name only, as shown in Figure \n2.4, we will use the Host command to translate those names into IP addresses. \nWe will discuss the host command in the next section. You can also use a web \nbrowser to search Whois. By navigating to http://www.whois.net, you can \nsearch for your target in the “WHOIS Lookup” box as shown in Figure 2.5.\nAgain it is important to closely review the information you are presented with. \nSometimes, the output will not provide many details. We can often access \nthese additional details by querying the specific whois server listed in the out-\nput of our original search. Figure 2.6 shows an example of this.\nFIGURE 2.4\nPartial Output from a Whois Query.\nFIGURE 2.5\nWhois.net—A Web-Based Lookup Tool.\n"
}
|
{
"page_number": 49,
"text": "The Basics of Hacking and Penetration Testing\n30\nWe can conduct a further whois search by following the link provided in the \n“Referral URL:” field. You may have to search the webpage for a link to their \nWhois service. By using Safename’s whois service, we can extract a significantly \nlarger amount of information as shown here:\nThe Registry database contains ONLY .COM, .NET, .EDU domains and\nRegistrars.[whois.safenames.net]\nSafenames Whois Server Version 2.0\nDomain Name: SYNGRESS.COM\n [REGISTRANT]\n Organisation Name: Elsevier Ltd\n Contact Name: Domain Manager\n Address Line 1: The Boulevard\n Address Line 2: Langford Lane, Kidlington\n City/Town: Oxfordshire\n State/Province:\n Zip/Postcode: OX5 1GB\n Country: UK\n Telephone: 44 (18658) 43830\n Fax: 44 (18658) 53333\n Email: domainsupport@elsevier.com\n [ADMIN]\n Organisation Name: Safenames Ltd\n Contact Name: International Domain Administrator\n Address Line 1: PO Box 5085\n Address Line 2:\n City/Town: Milton Keynes MLO\n State/Province: Bucks\n Zip/Postcode: MK6 3ZE\n Country: UK\n Telephone: 44 (19082) 00022\n Fax: 44 (19083) 25192\n Email: hostmaster@safenames.net\nFIGURE 2.6\nWhois Output Showing Where to Go for Additional Details.\n"
}
|
{
"page_number": 50,
"text": "Reconnaissance CHAPTER 2\n31\n [TECHNICAL]\n Organisation Name: International Domain Tech\n Contact Name: International Domain Tech\n Address Line 1: PO Box 5085\n Address Line 2:\n City/Town: Milton Keynes MLO\n State/Province: Bucks\n Zip/Postcode: MK6 3ZE\n Country: UK\n Telephone: 44 (19082) 00022\n Fax: 44 (19083) 25192\n Email: tec@safenames.net\nNetcraft\nAnother great source of information is Netcraft. You can visit their site at \nhttp://news.netcraft.com. Start by searching for your target in the “What’s that \nsite Running?” textbox as shown in Figure 2.7.\nNetcraft will return any websites it is aware of that contain your search words. \nIn our example we are presented with three sites: syngress.com, www.syngress.\ncom, and booksite.syngress.com. If any of these sites have escaped our previous \nsearches, it is important to add them to our potential target list. The returned \nresults page will allow us to click on a “Site Report.” Viewing the site report \nshould provide us with some valuable information as shown in Figure 2.8.\nAs you can see, the site report provides us with some great information about \nour target including the IP address and OS of the web server as well as the DNS \nserver. Once again all this information should be cataloged and recorded.\nHost\nOftentimes, our reconnaissance efforts will result in host names rather than IP \naddresses. When this occurs, we can use the “host” tool to perform a transla-\ntion for us. The host tool is built into Backtrack. We can access it by opening a \nterminal and typing:\nroot@bt~# host target_hostname\nFIGURE 2.7\nNetcraft Search Option.\n"
}
|
{
"page_number": 51,
"text": "The Basics of Hacking and Penetration Testing\n32\nIn our previous searches, we uncovered a DNS server with the host name “ns1.\ndreamhost.com.” To translate this into an IP address, we would enter the fol-\nlowing command in a terminal:\nhost ns1.dreamhost.com\nFigure 2.9 shows the result of this tool.\nThe host command can also be used in reverse. It can be used to translate IP \naddresses into host names. To perform this task, simply enter:\nroot@bt~# host IP address\nUsing the “-a” switch will provide you with verbose output and possibly reveal \nadditional information about your target. It is well worth your time to review \nthe “host” documentation and help files. You can do so by issuing the “man \nhost” command in a terminal window. This help file will allow you to become \nfamiliar with the various options that can be used to provide additional func-\ntionality to the “host” tool.\nExtracting information from DNS\nDNS servers are an excellent target for hackers and penetration testers. They \nusually contain information that is considered highly valuable to attackers. \nDNS is a core component of both our local networks and the Internet. Among \nFIGURE 2.9\nHost Command Output.\nFIGURE 2.8\nSite Report for Syngress.com.\n"
}
|
{
"page_number": 52,
"text": "Reconnaissance CHAPTER 2\n33\nother things, DNS is responsible for the process of translating domain names \nto IP addresses. As humans, it is much easier for us to remember “google.com” \nrather than http://74.125.95.105. However, machines prefer the reverse. DNS \nserves as the middle man to perform this translation process.\nAs penetration testers, it is important to focus on the DNS servers that belong \nto our target. The reason is simple. In order for DNS to function properly, it \nneeds to be aware of both the IP address and the corresponding domain \nname of each computer on its network. In terms of reconnaissance, gaining \nfull access to a company’s DNS server is like finding a pot of gold at the end \nof a rainbow. Or maybe, more accurately, it is like finding a blueprint to the \norganization. But in this case the blueprint contains a full listing of internal \nIP addresses that belong to our target. Remember one of the key elements of \ninformation gathering is to collect IP addresses that belong to the target.\nAside from the pot of gold, another reason why picking on DNS is so enjoy-\nable is that in many cases these servers tend to operate on the “if it isn’t broke, \ndon’t touch it” principle.\nInexperienced network administrators often regard their DNS servers with sus-\npicion and mistrust. Oftentimes, they choose to ignore the box completely \nbecause they do not fully understand it. As a result touching, patching, updat-\ning, or changing configurations on the DNS server is often a low priority. Add \nthis to the fact that most DNS servers appear to be very stable (as long as the \nadministrator is not monkeying with it) and you have a recipe for a security \ndisaster. These admins wrongly learn early in their career that the less they \nmess with their DNS servers, the less trouble it seemed to cause them.\nAs a penetration tester, given the number of misconfigured and unpatched \nDNS servers that abound today, it is natural to assume that many current net-\nwork admins operate under this same principle.\nIf the above statements are true in even a small number of organizations, we \nare left with valuable targets that have a high probability of being unpatched \nor out of date. So the next logical question becomes, how do we access this \nvirtual pot of gold? Before we can begin the process of examining a DNS server, \nwe need an IP address. Earlier in our reconnaissance, we came across several \nreferences to DNS. Some of these references were by host names, whereas oth-\ners were by IP addresses. Using the host command, we can translate any host \nnames into IP addresses and add these IPs to the potential target list. Again, \nyou must be sure to double- and triple-check that the IP you collect is within \nyour authorized scope before continuing.\nNow that we have a list of DNS IP addresses that belong to or serve our tar-\nget we can begin the process of interrogating DNS to extract information. \nAlthough it is becoming more rare to find, one of our first tasks when interact-\ning with a target DNS is to attempt a zone transfer.\nRemember DNS servers contain a series of records that match up the IP address \nand host name for all the devices that the servers are aware of. Many networks \n"
}
|
{
"page_number": 53,
"text": "The Basics of Hacking and Penetration Testing\n34\ndeploy multiple DNS servers for the sake of redundancy or load balancing. As \na result, DNS servers need a way to share information. This “sharing” process \noccurs through the use of a zone transfer. During a zone transfer, also com-\nmonly referred to as AXFR, one DNS server will send all the host-to-IP map-\npings it contains to another DNS server. This process allows multiple DNS \nservers to stay in sync.\nEven if we are unsuccessful in performing a zone transfer, we should still spend \ntime investigating any DNS servers that fall within our authorized scope.\nNS Lookup\nThe first tool we will use to examine DSN is NS Lookup. NS Lookup is a tool \nthat can be used to query DNS servers and potentially obtain records about \nthe various hosts of which it is aware. NS Lookup is built into many versions \nof Linux including Backtrack and is even available via the Windows command \nprompt! NS Lookup operates very similarly between the various operating sys-\ntems; however, you should always review the specifics for your particular sys-\ntem. You can do so in Linux by reviewing the NS Lookup man pages. This is \naccomplished by opening a terminal and typing:\nroot@bt~# man nslookup\nNS Lookup is a tool that can be run in interactive mode. This simply means we \nwill first invoke the program and then feed it the particular switches we need \nto make it function properly. We begin using NS Lookup by opening a termi-\nnal and entering:\nroot@bt~# nslookup\nBy issuing the “nslookup” command, we start the NS Lookup tool from the \noperating system. After typing “nslookup” and hitting enter, your usual “#” \nprompt will be replaced with a “>” prompt. At this point you can enter the \nadditional information required for NS Lookup to function.\nWe begin feeding commands to NS Lookup by entering the “server” keyword \nand an IP address of the DNS server you want to query. An example follows:\nserver 8.8.8.8\nNS Lookup will simply accept the command and present you with another “>” \nprompt. Next, we specify the type of record we are looking for. During the recon-\nnaissance process, there are many types of records that you may be interested in. \nFor a complete listing of the various DNS record types and their description, you \ncan use your newly acquired Google skills! If you are looking for general infor-\nmation, you should set the type to any by using the keyword “any”:\nset type any\nIf you are looking for specific information from the DNS server such as the IP \naddress of the mail server that handles e-mail for the target organization, we \nwould use the “set type mx”.\n"
}
|
{
"page_number": 54,
"text": "Reconnaissance CHAPTER 2\n35\nWe wrap up our initial DNS interrogation with NS Lookup by entering the tar-\nget domain after the next “>” prompt.\nSuppose you wanted to know what mail server is used to handle the e-mail for \nSyngress. In a previous example, we determined that one of Syngress’s name \nservers was “ns1.dreamhost.com”. Here again we can use the host tool to \nquickly determine what IP address is associated with ns1.dreamhost.com. With \nthis information in hand, we can use NS Lookup to query DNS and find mail \nserver for Syngress. Figure 2.10 shows an example of this process; the name of \nthe e-mail server has been highlighted (in the bottom right of the screenshot) \nand now needs to be added to our potential target list.\nDig\nAnother great tool for extracting information from DNS is “dig.” To work with \ndig, we simply open a terminal and enter the following command:\ndig @target_ip\nNaturally, you will need to replace the “target_ip” with the actual IP \naddress of your target. Among other things, dig makes it very simple to \nattempt a zone transfer. Recall that a zone transfer is used to pull multiple \nrecords from a DNS server. In some cases, a zone transfer can result in the tar-\nget DNS server sending all the records it contains. This is especially valuable if \nyour target does not distinguish between internal and external IPs when con-\nducting a zone transfer. We can attempt a zone transfer with dig by using the \n“–t AXFR” switch.\nIf we wanted to attempt a zone transfer against a fictitious DNS server with an \nIP address of 192.168.1.23 and a domain name of “example.com” we would \nissue the following command in a terminal window:\ndig @192.168.1.23 example.com –t AXFR\nFIGURE 2.10\nUsing Host and NS Lookup to Determine the E-mail Server of Our Target.\n"
}
|
{
"page_number": 55,
"text": "The Basics of Hacking and Penetration Testing\n36\nIf zone transfers are allowed and not restricted, you will be presented with a \nlisting of host and IP addresses from the target DNS server that relate to your \ntarget domain.\nBacktrack has many additional tools that can be used to interact with DNS. \nThese tools should be explored and utilized once you have a solid understand-\ning of how DNS works. Please see the end of this chapter for a brief discussion \nof some additional tools you may want to use when conducting a penetration \ntest involving DNS.\nExtracting information from e-mail servers\nE-mail servers can provide a wealth of information for hackers and penetration \ntesters. In many ways, e-mail is like a revolving door to your target’s organiza-\ntion. Assuming your target is hosting their own e-mail server, this is often a \ngreat place to attack. It is important to remember, “You can’t block what you \nmust let in.” In other words, for e-mail to function properly, external traffic \nmust pass through your border devices like routers and firewalls, to an internal \nmachine, typically somewhere inside your protected networks.\nAs a result of this, we can often gather significant pieces of information by \ninteracting directly with the e-mail sever. One of the first things to do when \nattempting to recon an e-mail server is to send an e-mail to the organization \nwith an empty .bat file or a nonmalicious .exe file like calc.exe. In this case, the \ngoal is to send a message to the target e-mail server inside the organization in \nthe hope of having the e-mail server inspect, and then reject the message.\nOnce the rejected message is returned back to us, we can attempt to extract \ninformation about the target e-mail server. In many cases, the body of the \nmessage will include a precanned write-up explaining that the server does \nnot accept e-mails with potentially dangerous extensions. This message often \nindicates the specific vendor and version of antivirus that was used to scan the \ne-mail. As an attacker this is a great piece of information to have.\nHaving a return message from a target e-mail server also allows us to inspect \nthe headers of the e-mail. Inspecting the Internet headers will often allow us to \nextract some basic information about the e-mail server, including IP addresses \nand the specific software versions or brand of e-mail server running. Knowing \nthe IP address and software versions can be incredibly useful when we move \ninto the exploitation phase (step 3).\nMetaGooFil\nAnother excellent information gathering tools is “MetaGooFil.” MetaGooFil is \na metadata extraction tool that is written by the same folks who brought us \nthe Harvester. Metadata is often defined as data about data. When you create a \ndocument like Microsoft Word or a PowerPoint presentation, additional data \nis created and stored within your file. This data often includes various pieces of \ninformation that describe the document including the file name, the file size, \n"
}
|
{
"page_number": 56,
"text": "Reconnaissance CHAPTER 2\n37\nthe file owner or username of the person who created the file, and the location \nor path where the file was saved. This process occurs automatically without any \nuser input or interaction.\nThe ability of an attacker to read this information may present some unique \ninsights into the target organization including usernames, system names, files \nshares, and other goodies. MetaGooFil is a tool that scours the Internet look-\ning for documents that belong to your target. After finding these documents, \nMetaGooFil downloads them and attempts to extract useful metadata.\nMetaGooFil is built into Backtrack and can be found by navigating to the \nInformation Gathering section off of the Backtrack option in the All Programs \nmenu. Likewise, you can open a terminal window and enter the following \ncommand:\ncd /pentest/enumeration/google/metagoofil\nAfter navigating to the MetaGooFil directory, it is a good idea to create a \n“files” folder. The purpose of this folder is to hold all the target files that will \nbe downloaded; this keeps the original directory clean. You can create a new \nfolder by entering:\nmkdir files\nWith this directory setup, you can run MetaGooFil by issuing the following \ncommand:\n./metagoofil.py -d syngress.com –f all -o results –t files\nLet us examine the details of this command. “./metagoofil.py” is used to \ninvoke the MetaGooFil python script. Do not forget to put the “./” in front \nof the command. The “–d” switch is used to specify the target domain to be \nsearched. The “–f” switch is used to specify which type or types of files you want \nMetaGooFil to attempt to locate. Utilizing the “all” switch will force MetaGooFil \nto locate and download all the different format types that it can process includ-\ning ppt, pdf, xls, odp, docx and others. You can also specify individual file types \nto limit the returned results. We use the “–o” switch to specify the name of the \nreport that MetaGooFil will generate for us. Lastly we specify the folder where we \nwant to store each of the files that MetaGooFil locates and downloads. In an ear-\nlier step we created a “files” directory; as a result, our command “–f files” will \nsave each of the discovered documents into this folder.\nWhile the output from MetaGooFil against Syngress reveals nothing, below \nyou will find a sample of the tool’s output from a recent penetration test that \nclearly provides additional value and should be included with our reconnais-\nsance data.\nC:\\Documents and Settings\\dennisl\\My Documents\\\nThis example is rich with information. First, it provides us with a valid net-\nwork username “dennisl.” Second, it clearly shows that Dennis uses a Windows \nmachine.\n"
}
|
{
"page_number": 57,
"text": "The Basics of Hacking and Penetration Testing\n38\nSocial engineering\nNo discussion of reconnaissance would be complete without including social \nengineering. Many people would argue that social engineering is one of the \nmost simple and effective means for gathering information about a target.\nSocial engineering is the process of exploiting the “human” weakness that is \ninherent in every organization. When utilizing social engineering, the attacker’s \ngoal is to get an employee to divulge some information that should be kept \nconfidential.\nLet us assume you are conducting a penetration test on an organization. \nDuring your early reconnaissance, you discover an e-mail address for one of \nthe company’s sales people. You understand that sales people are highly likely \nto return product inquiry e-mails. As a result, you sent an e-mail from an anon-\nymous address feigning interest in a particular product. In reality, you did not \ncare about the product. The real purpose of sending the e-mail is to get a reply \nfrom the sales person so you can review the e-mail headers contained in the \nresponse. This process will allow you to gather additional information about \nthe company’s internal e-mail servers.\nLet us take our social engineering example one step further. Suppose our sales-\nman’s name is Ben Owned (we found this information during our reconnais-\nsance of the company website and in the signature of his e-mail response). \nLet us assume that in this example, when you sent the employee the product \ninquiry e-mail, you received an automatic reply with the notification that Ben \nOwned was “currently out of the office travelling overseas” and “would be \ngone for two weeks with only limited e-mail access.”\nA classic example of social engineering would be to impersonate Ben Owned \nand call the target company’s tech support number asking for help resetting \nyour password because you are overseas and cannot access your webmail. If \nyou are lucky, the tech support people will believe your story and reset the \npassword. Assuming they use the same password, you now have access to Ben \nOwned’s e-mail and other network resources like VPN for remote access, or \nFTP for uploading sales figures and customer orders.\nSocial engineering, like reconnaissance in general, takes both time and prac-\ntice. Not everyone makes a good social engineer. In order to be successful, you \nmust be supremely confident, knowledgeable of the situation, and flexible \nenough to go “off script.” If you are conducting social engineering over the \nphone, it can be extremely helpful to have detailed and well-written notes in \ncase you are asked about some obscure detail.\nAnother example of social engineering is to leave USB thumb drives or CDs at \nthe target organization. The thumb drives should be distributed to several loca-\ntions in or near the organization. The parking lot, the lobby, the bathroom, \nand an employee’s desk are all great “drop” locations. It is human nature for \nmost people to insert the thumb drive or CD into their PC just to see what is \n"
}
|
{
"page_number": 58,
"text": "Reconnaissance CHAPTER 2\n39\non the drive. In this example though, the thumb drive or CD is preloaded with \na self-executing backdoor program that automatically launches when the drive \nis inserted into the computer. The backdoor is capable of bypassing the com-\npany firewall and will dial home to the attacker’s computer, leaving the target \nexposed and giving the attacker a clear channel into the organization. We will \ndiscuss the topic of backdoors in Chapter 6.\nSifting through the Intel to find attackable \ntargets\nOnce you have completed the steps above, you need to schedule some time \nto closely review all the reconnaissance and information you have gathered. \nIn most cases, even light reconnaissance should produce a mountain of data. \nOnce the reconnaissance step is completed, you should have a solid under-\nstanding of your target including the organization, structure, and even technol-\nogies deployed inside the company.\nWhile conducting the review process, it is a good idea to create a single list that \ncan be used as a central repository for recording IP addresses. You should also \nkeep separate lists that are dedicated to e-mail addresses, host names, and URLs.\nUnfortunately, most of the data you collected will not be directly attackable. \nDuring the process of reviewing your findings, be sure to transform any rele-\nvant, non-IP-based information, into an IP address. Using Google and the host \ncommand you should be able to extract additional IPs that relate to your tar-\nget. Add these to the IP list.\nAfter we have thoroughly reviewed the collected reconnaissance and trans-\nformed the data into attackable targets, we should have a list of IPs that \neither belong to, serve, or are related to the target. As always, it is important \nto remember your authorized scope because not all the IPs we collect will be \nwithin that range. As a result, the final step in reconnaissance is to review the \nIP list you just created and either contact the company to determine if you can \nincrease the scope of the pen test or remove the IP address from your list.\nAt this point you will be left with a list of IP addresses that you are authorized \nto attack. Do not discard or underestimate all the nonattackable information \nyou have gathered. In each of the remaining steps, we will be reviewing and \nextracting information from step 1.\nHow do I practice this step?\nNow that you have a solid understanding of the basic tools and techniques \nused to conduct reconnaissance, you will need to practice everything that was \ncovered. There are many ways to go about practicing this step. One simple and \neffective idea is to make a list of companies by reading a newspaper. If you do \nnot have access to a newspaper, any popular news website will do, like www.\ncnn.com, www.msnbc.com, etc.\n"
}
|
{
"page_number": 59,
"text": "The Basics of Hacking and Penetration Testing\n40\nWhile making a list of potential targets to conduct reconnaissance on, try to \nfocus on company names that you have not heard of before. Any good news-\npaper or website should contain dozens of companies that you are unfamil-\niar with. One note of caution here, YOU MUST BE SURE NOT TO DO ANY \nACTIVE RECONNAISSANCE! Obviously, you have not been authorized in any \nway to perform the active techniques we covered in this chapter. However, you \ncan still practice gathering information through the passive techniques we dis-\ncussed. This will allow you to refine and sharpen your skills. It will also pro-\nvide you with an opportunity to develop a system for cataloging, organizing, \nand reviewing the data you collect. Remember, while this may be the “least” \ntechnical phase, it has the potential for the best returns.\nWhere do I go from here?\nOnce you have practiced and mastered the basics of reconnaissance, you will \nbe armed with enough information and skill to tackle advanced topics in infor-\nmation gathering. The following is a list of tools and techniques that will take \nyour information-gathering ability to the next level:\nn\t Search Engine Directives for Sites Other Than Google:\nl\t Now that your Google-Fu is strong, you need to master this technique \nusing other search engines. Most modern search engines include direc-\ntives or other ways to complete advanced searches. Remember you should \nnever rely on a single search engine to do all of your reconnaissance. \nSearching for the same keywords in different search engines often returns \ndrastically different and surprisingly useful results.\nn\t Search Engine Assessment Tool (SEAT)\nl\t SEAT is a great tool to use for quickly querying several different search \nengines in a single pass. This tool automates much of the manual labor \nrequired when performing reconnaissance across several different search \nengines. SEAT is built into Backtrack and available from its creator at \nwww.midnightresearch.com. Their site even includes useful “how to” \nvideos for using SEAT.\nn\t Johnny Long’s Google Hacking Database (GHDB)\nl\t This is a single repository for some of the most effective and feared \nGoogle Hacks in existence today! It has already been mentioned and \nshould go without saying but DO NOT RUN THESE QUERIES AGAINST \nUNAUTHORIZED TARGETS! You can find the GHDB at http://www.\nhackersforcharity.org/ghdb. While you are there, take a minute to read \nabout Hackers for Charity and Johnny’s efforts with the “food for work” \nprogram.\nn\t Google Hacking for Penetration Testers, 2nd edition, Syngress\nl\t Johnny’s Google Hacking book is a must-read for all penetration testers.\nn\t Paterva’s Maltego CE\nl\t Maltego is a very powerful tool that aggregates information from pub-\nlic databases and provides shockingly accurate details about your tar-\nget organization. These details can be technical in nature, such as the \n"
}
|
{
"page_number": 60,
"text": "Reconnaissance CHAPTER 2\n41\nlocation or IP address of your firewall, or they can be personal, such as \nthe physical location of your currently (travelling) salesman. Learning to \nmaster Maltego takes a little effort but is well worth your time. A free \nversion is available in Backtrack.\nSummary\nInformation gathering is the first step in any penetration test or hack. Even \nthough this phase is less technical than most, its importance should not be \noverlooked. The more information you are able to collect, the better your \nchances of success in later phases of the penetration test. At first, the amount of \ninformation that can be gathered on your target can seem a bit overwhelming, \nbut with a good documentation process, the proper use of tools, and further \npractice you will soon master the art of reconnaissance.\n"
}
|
{
"page_number": 61,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 62,
"text": "43\nIntroduction\nOnce step 1 has been completed, you should have a solid understanding of \nour target and a detailed collection of gathered information. This data mainly \nincludes our collection of IP addresses. Recall that one of the final steps in \nreconnaissance was to create a list of IP addresses that both belonged to the \ntarget and that we were authorized to attack. This list is the key to transition-\ning from step 1 to step 2. In step 1, we mapped our gathered information to \nScanning\nCHAPTER 3\nInformation in This Chapter:\nn\t Pings and Ping Sweeps\nn\t Port Scanning\nn\t Vulnerability Scanning\n"
}
|
{
"page_number": 63,
"text": "The Basics of Hacking and Penetration Testing\n44\nattackable IP addresses. In step 2, we will map IP addresses to open ports and \nservices.\nIt is important to understand that it is the job of most networks to allow at \nleast some communication to flow into and out of their borders. Networks \nthat exist in complete isolation with no Internet connection, no services like \ne-mail or web traffic, are very rare today. Each service, connection, or potential \nconnection to another network provides a potential foothold for an attacker. \nScanning is the process of identifying live systems and the services that exist on \nthose systems.\nStep 2 begins by breaking the scanning process into three distinct phases:\n2.1\t Determining if a system is alive\n2.2\t Port scanning the system\n2.3\t Scanning the system for vulnerabilities\nLater in this chapter we will discuss tools that combine these phases into a sin-\ngle process; however, for the purpose of introducing and learning new mate-\nrial, it is best to cover them separately.\nStep 2.1 is the process of determining whether a target system is turned on and \ncapable of communicating or interacting with our machine. This step is the \nleast reliable and we should always continue with steps 2.2 and 2.3 regardless \nof the outcome of this test. Regardless, it is still important to conduct this step \nand make note of any machines that respond as alive.\nStep 2.2 is the process of identifying the specific ports and services running a \nparticular host.\nSimply defined, ports provide a way or location for software and networks to \ncommunicate with hardware like a computer. A port is a data connection that \nallows a computer to exchange information with other computers, software, or \ndevices. Prior to the interconnection of computers and networks, information \nwas passed between machines through the use of physical media like floppy \ndrives. Once computers were connected to a network, they needed an efficient \nmeans for communicating with each other. Ports were the answer. The use of \nmultiple ports allows for simultaneous communication without the need \nto wait.\nTo further clarify this point for those of you who are unfamiliar with ports and \ncomputers, it may be helpful to consider the following analogy: Think of your \ncomputer as a house. There are many different ways that a person can enter the \nhouse. Each of the different ways to enter your house (computer) is like a com-\nputer port. Just like a port on a computer, all the entryways allow traffic to flow \ninto and out of your home.\nImagine a house with unique numbers over each of the potential entry points. \nMost people will use the front door. However, the owners may come in \nthrough the garage door. Sometimes, people enter the house from a backdoor \n"
}
|
{
"page_number": 64,
"text": "Scanning CHAPTER 3\n45\nTable 3.1 Common Port Numbers and Their Corresponding Service\nPort Number\nService\n20\nFTP data transfer\n21\nFTP control\n22\nSSH\n23\nTelnet\n25\nSMTP (e-mail)\n53\nDNS\n80\nHTTP\n443\nHTTPS\nor sliding glass door off the deck. An unconventional person may climb \nthrough a window or attempt to squeeze through the doggie door!\nRegardless of how you get into your house, each of these examples corresponds \nnicely with the analogy of computers and ports. Recall that ports are like gate-\nways to your computer. Some ports are more common and receive lots of traf-\nfic (just like your front door); others are more obscure and rarely used (by \nhumans) like the doggie door.\nMany common network services run on standard port numbers and can give \nattackers an indication as to the function of the target system. Table 3.1 pro-\nvides a list of common ports and their corresponding services.\nObviously, there are many more ports and services. However, this list serves as \na basic introduction to common ports that are utilized by organizations today. \nYou will see these services repeatedly as you begin to port scan your targets.\nWe need to pay special attention to the discovery of any open ports on our \ntarget systems. You should make detailed notes and save the output of any tool \nrun in step 2.2. Remember every open port is a potential gateway into the tar-\nget system.\nThe final step in scanning is step 2.3, vulnerability scanning. Vulnerability \nscanning is the process of locating and identifying known weaknesses in the \nservices and software running on a target machine. The discovery of known \nvulnerabilities on a target system can be like finding the pot of gold at the end \nof a rainbow. Many systems today can be exploited directly with little or no \nskill when a machine is discovered to have a known vulnerability.\nIt is important to mention that there is a difference in the severity of various \nvulnerabilities. Some vulnerabilities may present little opportunities for an \nattacker, whereas others will allow you to completely take over and control a \nmachine with a single click of a button. We will discuss the various levels of \nvulnerabilities in more detail later in the chapter.\nIn the past, I have had several clients ask me to attempt to gain access to some \nsensitive server on an internal network. Obviously in these cases, the final \nTable 3.1\n"
}
|
{
"page_number": 65,
"text": "The Basics of Hacking and Penetration Testing\n46\ntarget is not directly accessible via the Internet. Whether we are going after \nsome supersecret internal machine or simply attempting to gain access to a \nnetwork, we usually begin by scanning the perimeter devices. The reason for \nthis is simple, we start at the perimeter because most of the information we \nhave from step 1 belongs to perimeter devices. Also, with many of today’s tech-\nnologies and architectures, it is not always possible to reach directly into a net-\nwork. As a result, we often employ a hacking methodology where we chain a \nseries of machines together in order to reach our final target. First we conquer a \nperimeter device, then we move to an internal machine.\nPerimeter devices are computers, servers, routers, firewalls, or other equipment, \nwhich sit at the outer edge of a protected network. These devices serve as an \nintermediary between protected internal resources and external networks like \nthe Internet.\nAs previously mentioned, we often begin by scanning the perimeter devices \nto look for weaknesses or vulnerabilities that will allow us to gain entry into \nthe network. Once we have successfully gained access (which we will discuss \nin Chapter 4), the scanning process can be repeated from the newly owned \nmachine, in order to find additional targets. This cyclical process allows us to \ncreate a very detailed internal network map and discover the critical infrastruc-\nture hiding behind the corporate firewall.\nPings and ping sweeps\nA ping is a special type of network packet called an ICMP packet. Pings work \nby sending specific types of network traffic, called ICMP Echo Request pack-\nets, to a specific interface on a computer or network device. If the device (and \nthe attached network card) that received the ping packet is turned on and not \nrestricted from responding, the receiving machine will respond back to the \noriginating machine with an Echo Reply packet. Aside from telling us that \na host is alive and accepting traffic, pings provide other valuable information \nincluding the total time it took for the packet to travel to the target and return. \nPings also report traffic loss that can be used to gauge the reliability of a net-\nwork connection. Figure 3.1 shows an example of the ping command.\nThe first line in Figure 3.1 shows the ping command being issued. Please note, \nthis particular screenshot was taken from a Windows machine. All modern ver-\nsions of Linux and Windows include the ping command. The major difference \nbetween the Linux and Windows version is that by default the Windows ping \ncommand will send four Echo Request packets and automatically terminate, \nwhereas the Linux ping command will continue to send Echo Request com-\nmands until you force it to stop. On a Linux system, you can force a ping com-\nmand to stop sending packets by using the CNTLC combination.\nLet us focus our attention on the third line that starts with “Reply from.” This \nline is telling us that our ICMP Echo Request packet successfully reached the IP \naddress of 64.233.167.99 and that the IP address sent a Reply packet back to \n"
}
|
{
"page_number": 66,
"text": "Scanning CHAPTER 3\n47\nour machine. The “bytes32” in the line indicate the size of the packet being \nsent. The “time26 ms” is telling you how long the entire round trip took for \nthe packets to travel to and from the target. The “TTL240” is a Time To Live \nvalue; this is used to determine the maximum number of hops the packet will \ntake before automatically expiring.\nNow that you have a basic understanding of how the ping command works, let \nus see how we leverage this tool as a hacker. Because we know that pings can \nbe useful in determining if a host is alive, we can use the ping tool as a host \ndiscovery service. Unfortunately, pinging every potential machine on even a \nsmall network would be highly inefficient. Fortunately for us, there are several \ntools that allow us to conduct ping sweeps. A ping sweep is a series of pings \nthat are automatically sent to a range of IP addresses, rather than manually \nentering the individual target’s address.\nThe simplest way to run a ping sweep is with a tool called FPing. FPing is built \ninto Backtrack and is run from the terminal. The tool can also be downloaded \nfor Windows. The easiest way to run FPing is to open terminal window and \ntype the following: fping –a –g 172.16.45.1 172.16.45.254>hosts.txt. \nThe “–a” switch is used to show only the live hosts in our output. This makes \nour final report much cleaner and easier to read. The “–g” is used to specify \nthe range of IP addresses we want to sweep. You need to enter both the begin-\nning and the ending IP addresses. In this example, we scanned all the IPs from \n172.16.45.1 to 172.16.45.254. The “>” character is used to pipe the output to \na file, and the hosts.txt is used to specify the name of the file our results will be \nsaved to. There are many other switches that can be used to change the func-\ntionality of the FPing command. You can view them all by entering the follow-\ning command in a terminal window:\nman fping\nFIGURE 3.1\nAn Example of the Ping Command.\n"
}
|
{
"page_number": 67,
"text": "The Basics of Hacking and Penetration Testing\n48\nOnce you have run the command above, you can open the hosts.txt file that \nwas created to find a list of target machines that responded to our pings. These \nIP addresses should be added to your target list for later investigation. It is \nimportant to remember that not every host will respond to ping requests; some \nhosts may be firewalled or otherwise blocking ping packets.\nPort scanning\nNow that you have a list of targets, we can continue our examination by scan-\nning the ports on each of the IP addresses we found. Recall that the goal of port \nscanning is to identify which ports are open and determine what services are \navailable on our target system. A service is a specific job or task that the com-\nputer performs like e-mail, FTP, printing, or providing web pages. Port scanning \nis like knocking on the various doors and windows of a house and seeing who \nanswers. For example if we find that port 80 is open, we can attempt a connec-\ntion to the port and oftentimes get specific information about the web server \nthat is listening on that port.\nThere are a total of 65,536 (0–65,535) ports on every computer. Ports can be \neither TCP or UDP depending on the service utilizing the port or nature of the \ncommunication occurring on the port. We scan computers to see what ports \nare in use or open. This gives us a better picture of the purpose of the machine, \nwhich, in turn, gives us a better idea about how to attack the box.\nIf you had to choose only one tool to conduct port scanning, you would \nundoubtedly choose Nmap. Nmap was written by Gordon “Fyodor” Lyon and \nis available for free from www.insecure.org and is built into many of today’s \nLinux distributions including Backtrack. Although it is possible to run Nmap \nfrom a graphical user interface (GUI), we are going to focus on using the termi-\nnal to run our port scans.\nPeople who are new to security and hacking often ask why they should learn \nto use the command line or terminal version of a tool rather than relying on a \nGUI. These same people often complain that using the terminal is not as easy. \nThe response is very simple. First, using the command line version of a tool will \nallow you to learn the switches and options that change the behavior of your \ntool. This gives you more flexibility, more granular control, and a better under-\nstanding of the tool you are running. Second (and maybe more importantly), \nrarely does hacking work like it is portrayed in the movies. Finally, the com-\nmand line can be scripted. Scripting and automation become key when you \nwant to advance your skillset to the next level.\nRemember the movie Swordfish where Hugh Jackman is creating a virus? He is \ndancing and drinking wine, and apparently building a virus in a very graphical, \nGUI-driven way. The point is that this is just not realistic. Most people who are \nnew to hacking assume that hacking is a very GUI-oriented task: that once you \ntake over a machine you are presented with a desktop and control of the mouse \nand screen. Although this scenario is possible, it is rarely the case. In most jobs, \n"
}
|
{
"page_number": 68,
"text": "Scanning CHAPTER 3\n49\nyour main goal will be to get an administrative shell or backdoor access to the \nmachine. This shell is literally a terminal that allows you to control the target PC \nfrom the command line. It looks and feels just like the terminals that we have \nbeen working with, except a remote shell allows you to enter the commands \non your computer terminal and have them executed on the target machine. So \nlearning the command line version of your tools is critical because once you \nhave control of a machine you will need to upload your tools and interact with \nthe target through a command prompt, not through a GUI.\nLet us assume you still refuse to learn the command line. Let us also assume \nthat with the use of several tools you were able to gain access to a target system. \nWhen you gain access to that system, you will not be presented with a GUI but \nrather with a command prompt. If you do not know how to copy files, add \nusers, modify documents, and make other changes through the command line, \nyour work of owning the target will have been in vain. You will be stuck, like \nMoses who was able to see the promised land but not allowed to enter!\nWhen we conduct a port scan, our tool will literally create a packet and send \nit to each designated port on the machine. The goal is to determine what kind \nof a response we get from the target port. Different types of port scans can pro-\nduce different results. It is important to understand the type of scan you are \nrunning as well as the expected output of that scan.\nThe Three-Way Handshake\nWhen two machines on any given network want to communicate using TCP, \nthey do so by completing the three-way handshake. This process is very similar \nto a phone conversation (at least before everyone had caller ID!). When you \nwant to talk to someone on the phone, you pick up the phone and dial the \nnumber, the receiver picks up the ringing phone not knowing who the caller \nis and says “Hello?,” the original caller then introduces himself by saying “Hi, \nthis is John!” In response to this, the original receiver will often acknowledge \nthe caller by saying “Oh, hi John!” At this point both people have enough \ninformation for the conversation to continue as normal.\nComputers work much the same way. When two computers want to talk, they \ngo through a similar process. The first computer connects to the second com-\nputer by sending a SYN packet to a specified port number. If the second com-\nputer is listening, it will respond with a SYN/ACK. When the first computer \nreceives the SYN/ACK, it replies with an ACK packet. At this point, the two \nmachines can communicate normally. In our phone example above, the origi-\nnal dialer is like sending the SYN packet. The receiver picking up the phone \nand saying “Hello?” is like the SYN/ACK packet and the original caller intro-\nducing himself is like the ACK packet.\nUsing Nmap to Perform a TCP Connect Scan\nThe first scan we will look at is called the TCP Connect scan. This scan is often \nconsidered the most basic and stable of all the port scans because Nmap \n"
}
|
{
"page_number": 69,
"text": "The Basics of Hacking and Penetration Testing\n50\nattempts to complete the three-way handshake on each port specified in the \nNmap command. Because this scan actually completes the three-way hand-\nshake and then tears down the connection gracefully, there is little chance that \nyou will flood the target system and cause it to crash.\nIf you do not specify a specific port range Nmap will scan the 1,000 most com-\nmon ports. Unless you are in a great hurry, it is always recommended specify-\ning all ports. The reason is that oftentimes crafty administrators will attempt \nto obscure a service by running it on a nonstandard port. You can scan all the \nports by specifying “-p-” when running Nmap. Using the “–PN” switch with \nevery Nmap scan is recommended. Utilizing the “–PN” switch will cause Nmap \nto disable host discovery and force the tool to scan every system as if it were \nalive. This is extremely useful for discovering additional systems and ports that \notherwise may be missed.\nTo run a TCP connect, we issue the following command from a terminal:\nnmap –sT -p- -PN 172.16.45.135\nTake a moment to review this command. The first word “nmap” causes the \nNmap port scanner to start. The second command “–sT” tells Nmap to run \na TCP Connect scan. Specifically, to break this switch down even further, the \n“-s” is used to tell Nmap what kind of scan we want to run. The “-T” in the \n“-sT” is used to run a scan type of TCP Connect. We use the “-p-” to tell \nNmap to scan all the ports not just the default 1,000. We use the “–PN” switch \nto skip the host discovery phase and scan all the addresses as if the system were \nalive and responding to ping requests. Finally, we specify the target IP address; \nobviously, your target’s IP address will be different from the one shown in the \nscreenshot! Figure 3.2 shows the TCP Connect Nmap scan and the output that \nwas received when run against the target.\nOftentimes, we need to run our scans against an entire subnet, or range of IP \naddresses. When this is the case, we can instruct Nmap to scan a continuous \nrange of IPs by simply appending the last octet of the ending IP address onto \nthe scan like so:\nnmap –sT -p- -PN 172.16.45.1-254\nFIGURE 3.2\nTCP Connect Scan and Results.\n"
}
|
{
"page_number": 70,
"text": "Scanning CHAPTER 3\n51\nIssuing this command will cause Nmap to port scan all the hosts between the \nIP addresses 172.16.45.1 and 172.16.45.254. Just like ping sweeps, this is a \nvery powerful technique that can greatly improve the productivity of your scan-\nning life!\nIf you need to scan a series of hosts that are not in sequential order, you can \ncreate a text file and list each host IP address on a single line. Then add the \n“–iL path_to_the_text_file” switch to your Nmap command. Doing this \nallows you to scan all of your target hosts from a single command. Whenever \npossible, always try to create a single text file containing all of your target IPs. \nMost of the tools we discuss have a switch or mechanism for loading this text \nfile, which saves the effort or retyping, but more importantly, reduces the num-\nber of times you will type each IP address and therefore reduces the chance \nthat you will fat-finger the IP address and scan the wrong target.\nUsing Nmap to Perform a SYN Scan\nThe SYN Scan is arguably the most popular Nmap port scan. There are many \nreasons for its popularity, including the fact that it happens to be the default \nNmap scan. If you run the Nmap command without specifying a scan type \n(using the –s switch), Nmap will use the SYN scan by default.\nAside from the fact that the SYN scan is the default choice, it is also popular \nbecause it is faster than the TCP connect scan and yet remains quite safe, with \nlittle chance of DOS’ing or crashing the target system. SYN scans are faster \nbecause rather than completing the entire three-way handshake, it only com-\npletes the first two steps.\nIn a SYN scan, the scanning machine sends a SYN packet to the target and the \ntarget responds with a SYN/ACK (assuming the port is in use and not filtered) \njust like it did when we ran a TCP Connect scan. However, at this point, rather \nthan sending the traditional ACK packet, the scanning machine sends an RST \n(reset) packet to the target. The reset packet tells the target machine to disre-\ngard any previous packets and close the connection between the two machines. \nIt should be clear that the speed advantage of the SYN scan over the TCP \nConnect scan comes from the fact that there are less packets sent between the \nhosts when using a SYN scan rather than a TCP Connect scan. Although a few \npackets may not sound like a big advantage, it can add up quickly when scan-\nning multiple hosts.\nIf we consider the example of comparing the three-way handshake to a phone \ncall, SYN scans would be like calling someone up, having the receiver pick up \nthe phone and saying “Hello?”, and then simply hanging up on the person \nwithout a single word.\nAnother advantage to the SYN scan is that in some instances, it provides a level \nof obscurity or stealth. Because of this feature, the SYN scan is often referred \nto as the “Stealth Scan.” The stealth portion of this scan comes from the fact \nthat because the three-way handshake is never fully completed, the official \n"
}
|
{
"page_number": 71,
"text": "The Basics of Hacking and Penetration Testing\n52\nconnection was never 100 percent established. There are applications and log \nfiles that require the completion of the three-way handshake before they begin \nrecording activity. As a result, if a log file only records completed connections \nand the SYN scan never officially completes a single connection, this scan may \nbe undetected by some applications. Please note, this is the exception and not \nthe rule. All modern firewalls and intrusion detection systems in use today will \ndetect and report a SYN scan!\nBecause the SYN scan is the default Nmap scan, we do not technically need \nto specify the scan type with the “–s” switch. However, because this book \nfocuses on the basics, it is worth the effort to get into the habit of specifying \nyour scan type.\nTo run a SYN scan, you can open a terminal window and issue the following \ncommand:\nnmap –sS -p- -PN 172.16.45.135\nThis command is exactly the same as the previous example with one excep-\ntion—rather than using an “–sT” we used an “–sS.” This instructs Nmap to run \na SYN scan rather than a TCP Connect scan. The scan types are easy to remem-\nber because a TCP Connect scan begins with the letter “T,” whereas the SYN \nscan begins with the letter “S.” Each of the other switches was explained in the \nsection above. Please review the “Using Nmap to Complete a TCP Connect \nScan” for a detailed breakdown of the switches in this command. Figure 3.3 \nshows the output of a SYN scan against our target.\nTake a moment to compare the total run time between the two scans in Figures \n3.2 and 3.3. Even in our simple environment against a single host, the SYN \nscan completed its execution faster.\nUsing Nmap to Perform UDP Scans\nOne of the most common port scanning mistakes of new penetration testers is \nthat they overlook UDP. These aspiring hackers oftentimes fire up Nmap, run a \nsingle scan (typically a SYN scan), and move onto vulnerability scanning. Do \nnot neglect to scan UDP ports! Failing to scan your target for open UDP ports \nFIGURE 3.3\nSYN Scan and Results.\n"
}
|
{
"page_number": 72,
"text": "Scanning CHAPTER 3\n53\nis like reading the Cliff Notes version of a book. You will probably have a solid \nunderstanding of the story, but you arre likely to miss many of the details.\nIt is important to understand that both TCP Connect scans and SYN scans use \nTCP as the basis for their communication. TCP is an acronym for Transmission \nControl Protocol. UDP is an acronym for User Datagram Protocol. Computers \ncan communicate with one another using either TCP or UDP; however, there \nare several key differences between the two protocols.\nTCP is considered a “connection oriented protocol” because it requires that the \ncommunication between both the sender and the receiver stays in sync. This \nprocess ensures that the packets sent from one computer to another arrive at \nthe receiver intact and in the order they were sent. On the other hand, UDP \nis said to be “connectionless” because the sender simply sends packets to the \nreceiver with no mechanism for ensuring that the packets arrive at the desti-\nnation. There are many advantages and disadvantages to each of the protocols \nincluding speed, reliability, and error checking. To truly master port scanning, \nyou will need to have a solid understanding of these protocols. Take some time \nand learn about each of them.\nRecall that earlier the three-way handshake process was described by compar-\ning the process to a phone call. The three-way handshake is a key component \nof TCP communication that allows the sender and the receiver to stay in sync. \nBecause UDP is connectionless, this type of communication is most often com-\npared to dropping a letter in a mailbox. In most cases, the sender simply writes \nan address on an envelope, puts a stamp on the letter, and puts the letter in the \nmailbox. Eventually, the mailman comes along and picks up the letter where \nit is entered into the mail routing system. In this example, there is no return \nreceipt or delivery confirmation for the sender. Once the mailman takes the let-\nter, the sender has no guarantee that the letter will get to its final destination.\nNow that you have a very simple understanding of the difference between \nTCP and UDP, it is important to remember that not every service utilizes TCP. \nSeveral prominent services make use of UPD including DHCP, DNS (for indi-\nvidual lookups), SNMP, and TFTP. One of the most important traits for a pen-\netration tester to have is thoroughness. It will be quite embarrassing to you if \nyou overlook or miss a service because you forgot to run a UDP scan against \nyour target.\nBoth the TCP Connect scan and the SYN scan use TCP as the basis for their \nscanning techniques. If we want to discover services utilizing UDP, we need to \ninstruct Nmap to create scans using UDP packets. Fortunately, Nmap makes \nthis process very simple. To run a UDP scan against our target, we would enter \nthe following command in a terminal:\nnmap –sU 172.16.45.129\nNotice the difference between this command and the others we have learned. \nFirst, we specify the Nmap UDP scan by using the “–sU” command. Astute \nreaders will also notice that the “-p-“ and the “–PN” switches have been \n"
}
|
{
"page_number": 73,
"text": "The Basics of Hacking and Penetration Testing\n54\ndropped from the scan. The reason for this is simple. UDP scans are very slow; \nrunning even a basic UDP scan on the default 1,000 ports can take 20–30 min-\nutes. You may also notice that the IP address has changed. In this example, we \nare scanning a Linux machine with the TFTP service running. This will allow us \nto see the UPD scan with results. Figure 3.4 shows the output of the scan.\nIt is important to remember that UDP communication does not require a \nresponse from the receiver. If the target machine does not send back a reply \nsaying a packet was received, how can Nmap differentiate between an open \nport and a filtered (firewalled) port? In other words, if a service is available \nand accepting UDP packets, the normal behavior for this service is to simply \naccept the packet but not send a message back to the receiver saying “GOT IT!” \nLikewise, a common firewall strategy is to simply absorb the packet and not \nsend a response packet back to the sender. In this example, even though one \npacket went through and one packet was blocked, because no packets were \nreturned to the sender, there is no way of knowing if the packet was accepted \nby a service or dropped by the firewall.\nThis conundrum makes it very difficult for Nmap to determine if a UDP port \nis open or filtered. As a result when Nmap does not receive a response from a \nUDP scan, it returns the following message for the port “open | filtered.” It is \nimportant to note that on rare occasions a UDP service will send a response \nback to the original source. In these cases, Nmap is smart enough to under-\nstand that there is clearly a service listening and responding to requests and \nwill mark those ports as “open.”\nAs was discussed earlier, oftentimes people who are new to port scanning over-\nlook UDP scans. This is probably due in part to the fact that most ordinary \nUDP port scans provide very little information and mark nearly every port as \n“open | filtered.” After seeing the same output on several different hosts, it is \neasy to become disillusioned with UDP scans. However, all is not lost! The fine \nfolks who wrote Nmap provide us with a way to draw more accurate results \nfrom our UDP scans.\nFIGURE 3.4\nUPD Scan Command and Result.\n"
}
|
{
"page_number": 74,
"text": "Scanning CHAPTER 3\n55\nTo elicit a more useful response from our target, we can add the “–sV” switch \nto our UDP scan. The “–sV” switch is used for version scanning but, in this \ncase, can also help us narrow the results of our UPD scan.\nWhen version scanning is enabled, Nmap sends additional probes to every \n“open | filtered” port that is reported by the scan. These additional probes \nattempt to identify services by sending specifically crafted packets. These spe-\ncially crafted packets are often much more successful in provoking a response \nfrom the target. Oftentimes, this will change the reported results from “open | \nfiltered” to “open.”\nAs mentioned above, the simplest way to add version scanning to a UDP probe \nis to include the “–sV” switch. Please note that because we are already using \nthe “–sU” switch to specify the type of scan, we can simply append the capital \nV onto the back of the “–sU.” As a result, our new command becomes:\nnmap –sUV 172.16.45.135\nUsing Nmap to Perform an Xmas Scan\nIn the computer world, an RFC is a document that contains either notes or \nthe technical specifications covering a given technology or standard. RFCs can \nprovide us with a tremendous amount of detail about the inner workings of a \nparticular system. Because RFCs describe the technical details of how a system \nshould work, attackers and hackers will often review RFCs looking for potential \nweaknesses or loopholes described in the documentation. Xmas Tree scans and \nNull scans exploit just such a loophole.\nXmas Tree scans get their name from the fact that the FIN, PSH, and URG \npacket flags are set to “on”; as a result, the packet has so many flags turned on \nand the packet is often described as being “lit up like a Christmas tree.” Given \nwhat we already know about TCP communications and the three-way hand-\nshake, it should be clear that an Xmas Tree packet is highly unusual because nei-\nther the SYN nor ACK flags are set. However, this unusual packet has a purpose. \nIf the system we are scanning has followed the TCP RFC implementation, we \ncan send one of these unusual packets to determine the current state of the port.\nThe TCP RFC says that if a closed port receives a packet that does not have a \nSYN, ACK, or RST flag set (i.e., the type of packet that is created from an Xmas \nTree scan), the port should respond with an RST packet of its own. Furthermore, \nthe RFC states that if the port is open and it receives a packet without a SYN, \nACK, or RST flag set the packet should be ignored. Take a moment to reread the \nlast two sentences, as they are critical to understanding the response we get from \nthese scans.\nAssuming the operating system of the target fully complies with the TCP RFC, \nNmap is able to determine the port state without completing or even initiating \na connection on the target system. The word “assuming” was used because not \nevery operating system on the market today is fully RFC compliant. In general, \nthe Xmas Tree and Null scans work against Unix and Linux machines but not \n"
}
|
{
"page_number": 75,
"text": "The Basics of Hacking and Penetration Testing\n56\nWindows. As a result, Xmas Tree and Null scans are rather ineffective against \nMicrosoft targets.\nTo execute an Xmas Tree scan, we simply replace the “-sU” switch from our last \nexample with an “-sX.” To run the full scan in the terminal, we would enter:\nnmap –sX -p- -PN 172.16.45.129\nFigure 3.5 shows the command and output of an Xmas Tree scan against a \nLinux target.\nUsing Nmap to Perform Null Scans\nNull scans, like Xmas Tree scans, are probes made with packets that violate tra-\nditional TCP communication. In many ways, the Null scan is the exact oppo-\nsite of a Xmas Tree scan because the Null scan utilizes packets that are devoid \nof any flags (completely empty).\nTarget systems will respond to Null scans in the exact same way they respond \nto Xmas Tree scans. Specifically, an open port on the target system will send \nno response back to Nmap, whereas a closed port will respond with an RST \npacket. It is important to remember that these scans are only reliable for oper-\nating systems that comply 100 percent with the TCP RFC.\nOne of the main advantages of running Xmas Tree and Null scans is that \nin some cases, you are able to bypass simple filters and Access Control Lists \n(ACLs). Some of these primitive filters work by blocking inbound SYN packets. \nThe thought with this type of filter is that by preventing the SYN packet from \nentering the system, it is not possible for the three-way handshake to occur. If \nthe three-way handshake does not occur, there can be no TCP communication \nstreams between the systems, or more precisely, no TCP communications can \nbe originated from outside of the filter.\nIt is important to understand that neither the Xmas Tree nor the Null scans \nseek to establish any type of communication channel. The whole goal of these \nscans is to determine if a port is open or closed.\nFIGURE 3.5\nXmas Tree Scan Command and Result.\n"
}
|
{
"page_number": 76,
"text": "Scanning CHAPTER 3\n57\nWith the previous two paragraphs in mind, consider the following example. \nAssume that our Network Admin Ben Owned puts a simple firewall in front \nof his system to prevent anyone outside of his network from connecting to \nthe system. The firewall works by simply dropping any external communica-\ntions that begin with a SYN packet. Ben hires his buddy, the ethical hacker, to \nscan his system. The ethical hacker’s initial TCP Connect scans show nothing. \nHowever, being a seasoned penetration tester, the ethical hacker follows up his \ninitial scan with UDP, Xmas Tree, and Null scans. The ethical hacker smiles \nwhen he discovers that both his Xmas Tree scans and Null scans reveal open \nports on Ben’s system.\nThis scenario is possible because Nmap creates packets without the SYN flag \nset. Because the filter is only dropping incoming packets with the SYN flag, the \nXmas Tree and Null packets are allowed through. To run a Null scan, we issue \nthe following command in a terminal:\nnmap –sN -p- -PN 172.16.45.129\nPort Scanning Wrap Up\nNow that we have covered the basics of port scanning, there are a few addi-\ntional switches that need to be covered. These switches provide additional \nfunctionality that may be useful to you as you progress in your penetration \ntesting career.\nAs mentioned earlier, the “-sV” switch is used for version scanning. When con-\nducting version scanning, Nmap sends probes to the open port in an attempt \nto determine specific information about the service that is listening. When \npossible, Nmap will provide details about the service including version num-\nbers and other banner information. This information should be recorded in \nyour notes. It is recommended that you use the “-sV” switch whenever possi-\nble, especially on unusual or unexpected ports, because a wily administrator \nmay have moved his web server to port 34567 in an attempt to obscure the \nservice.\nNmap includes an option to change the speed of your port scan. This is done \nwith the “-T” switch. The timing switch ranges on a numeric scale from 0 to 5, \nwith 0 being the slowest scan and 5 being the fastest. Timing options are useful \nif you are attempting to avoid detection by sending your scan more slowly; or \nif you have a large number of IPs to scan and you have a limited time to com-\nplete the scan where faster scans would be more appropriate. Please be aware \nthat by using the fastest scans possible, Nmap may provide less accurate results.\nLastly, the “-O” switch can be useful for fingerprinting the operating system. \nThis is handy for determining if the target you are attacking is a Windows, \nLinux, or other type of machine. Knowing the operating system of your target \nwill save you time by allowing you to focus your attacks to known weaknesses \nof that system. There is no use in exploring exploits for a Linux machine if your \ntarget is running Windows.\n"
}
|
{
"page_number": 77,
"text": "The Basics of Hacking and Penetration Testing\n58\nOnce we have completed port scanning our target, we should have a list of \nopen ports and services. This information should be documented and reviewed \nclosely. While reviewing the Nmap output, you should take a few moments to \nattempt to log into any remote access services that were discovered in your port \nscan. The next chapter will address running a brute force tool to attempt to log \nin. For the time being, you can attempt to log in using default usernames and \npasswords. You could also try logging in using any information, usernames, or \ne-mail addresses you found during reconnaissance. It is possible to complete a \npenetration test by simply discovering an open remote connection and logging \ninto the box with a default username and password. Telnet and SSH are great \nremote services that you should always try to connect to. You can do this from \nthe command line by typing:\ntelnet target_ip\nssh root@target_ip\nIn this example, the “target_ip” is the IP address of your victim. Most likely \nthese will fail, but on the rare occasion when you are successful, these are an \nabsolute home run.\nVulnerability scanning\nNow that we have a list of IPs, open ports, and services on each machine, it \nis time to scan the targets for vulnerabilities. A vulnerability is a weakness in \nthe software or system configuration that can be exploited. Vulnerabilities \ncan come in many forms but most often they are associated with missing \npatches. Vendors often release patches to fix a known problem or vulnerability. \nUnpatched software and systems often lead to quick penetration tests because \nsome vulnerabilities allow remote code execution. Remote code execution is \ndefinitely one of the holy grails of hacking.\nIt is important to understand this step as the results will feed directly into step \n3 where we will gain access to the system. To scan systems for vulnerabilities, \nwe will use a vulnerability scanner. There are several good scanners available to \nyou but for this book we will be focusing on Nessus.\nNessus is a great tool and available for free, for a home user, from their website. \nYou can download a full-fledged version of Nessus and get a key for free. If you \nare going to use Nessus in a corporate environment, you will need to sign up \nfor the Professional Feed rather than the Home Feed. The Professional Feed will \nrun you about $100 a month. We will be using the Home version for this book.\nInstalling Nessus is very straightforward. It will run on either Linux or Windows. \nNessus runs using a client/server architecture. Once set up, the server runs quietly \nin the background, and you interact with the server through a browser. To install \nNessus, you need to complete the following steps:\n1.\t Download the installer from www.nessus.org.\n2.\t Register for a key on the Nessus website by submitting your e-mail address. \nThe Nessus crew will e-mail you a unique product key that can be used to \nregister the product.\n"
}
|
{
"page_number": 78,
"text": "Scanning CHAPTER 3\n59\n3.\t Install the program.\n4.\t Create a Nessus user to access the system.\n5.\t Update the plug-ins.\nOne of the key components of Nessus is the plug-ins. A plug-in is a small \nblock of code that is sent to the target machine to check for a known vulner-\nability. Nessus has literally thousands of plug-ins. These will need to be down-\nloaded the first time you start the program. The default installation will set up \nNessus to automatically update the plug-ins for you.\nOnce you have installed the Nessus server, you can access it by opening a \nbrowser and entering https://127.0.0.1:8834 in the URL (assuming you are \naccessing Nessus on the same computer you installed the server on). Do not \nforget the “https” in the URL as Nessus uses a secure connection when com-\nmunicating with the server. You will be prompted with a log-in screen. You \ncan use the username and password you created when installing the program. \nOnce you log into the program, you will be presented with a screen similar to \nFigure 3.6.\nBefore we can use Nessus, we need to set up a scan policy. You can do this \nby clicking on the “Policies” tab at the top of the web page. To set up a scan \npolicy, you need to provide a name. If you are going to set up multiple policies, \nyou should also enter a description. Please take a minute to review Figure 3.6 \nand notice there is a check in the box next to “Safe Checks.”\nWhen setting up Nessus for the first time, it is common to create two \npolicies: one with the “Safe Checks” checked and the other with the “Safe \nChecks” unchecked. The reason for this is simple. Some plug-ins and checks \nare considered dangerous because they check for the vulnerability by attempt-\ning to actually exploit the system. Be aware that removing the “Safe Checks” \nFIGURE 3.6\nScreenshot of Nessus.\n"
}
|
{
"page_number": 79,
"text": "The Basics of Hacking and Penetration Testing\n60\ncheck has the potential to cause network and system disruptions or even take \nsystems off-line. By setting up one policy with the “Safe Checks” enabled and \none with the “Safe Checks” disabled, you can avoid unintentional network \ndisruptions.\nThere are many options that you can use to customize your scan. For the pur-\npose of this book, we will use the defaults. Take a moment to review the vari-\nous options by clicking “Next” in the lower right. This will take you through \neach of the remaining pages where you can set additional options for your \nscan.\nOnce your scan is set, you can save it by clicking on the “Submit” button that \nwill appear after you have reviewed each of the scan option pages. You only \nneed to set up your scan policy one time. Once your scan has been submitted, \nyou will be able to use that policy to perform vulnerability scans against your \ntarget.\nNow that you have a scan policy set up, you can run a scan against your target. \nTo set up a scan, you need to click on the “Scans” link located in the top menu. \nYou can enter individual addresses to scan a single target or a list of IPs to scan \nmultiple hosts. Figure 3.7 shows the “Scan” screen.\nFIGURE 3.7\nSetting up the Nessus Scan.\n"
}
|
{
"page_number": 80,
"text": "Scanning CHAPTER 3\n61\nYou need to enter a name for the scan, select a policy, and enter the IP address \nof your targets. You can enter your target IP addresses individually in the “Scan \nTargets” box or if you have your target IP addresses saved to a text file, you can \nuse the “Browse…” button to locate and load it. Once your options are set, you \ncan click on the “Launch Scan” button in the lower right. Nessus will provide \nyou with information about the progress of your scan while it is running.\nWhen Nessus finishes the scan, you will be able to review the results by click-\ning on the “Reports” link in the menu bar. The report will provide you with a \ndetailed listing of all the vulnerabilities that Nessus discovered. We are espe-\ncially interested in vulnerabilities labeled as High. You should take time to \nclosely review the report and make detailed notes about the system. We will \nuse these results in the next step to gain access to the system.\nOnce we have completed port scanning and vulnerability scanning for each \nof our targets, we should have enough information to begin attacking the \nsystem.\nHow do I practice this step?\nThe easiest way to practice port scanning is to set up two machines or use \nvirtual machines. You should work your way through each of the options \nand scan types that we covered in this chapter. Pay special attention to the out-\nput from each scan. You should run scans against both Linux and Windows \nboxes.\nYou will probably want to add some services or programs to the target system \nso that you can be sure you will have open ports. Installing and starting FTP, a \nweb server, telnet, or SSH will work nicely.\nWhen a person is first learning about port scanning, one of the best ways to \npractice is to pick a subnet and hide an IP address in the network. After hid-\ning the target in the subnet, the goal is to locate the target. Once the target has \nbeen located, the next step is to conduct a full port scan of the system.\nTo assist with the scenario described above, a simple script has been created, \nwhich can be used to “hide” your system in a given subnet. The code is meant \nto be run on a Linux machine. Feel free to modify it by changing the IP address \nso that it will work on your network. The script generates a random num-\nber between 1 and 254. This number is to be used as the final octet in the IP \naddress. Once the random IP address is created, the script applies the address \nto the machine.\nRunning this script will allow you to become familiar with the tools and tech-\nniques we covered in this chapter. You can enter the script into a text editor \nand save the file as IP_Gen.sh.\n"
}
|
{
"page_number": 81,
"text": "The Basics of Hacking and Penetration Testing\n62\n#!/bin/bash\necho \"Setting up the victim machine, this will take just a \nmoment...\"\nifconfig eth0 down\nifconfig eth0 172.16.45.$((( $RANDOM %254) 1)) up\n# uncomment the following lines by removing the #, to start up \nservices on your victim\n# please note, you may need to change the location / path depending \non your distro\n#/etc/init.d/ssh start\n# note, you may have to generate your SSH key using sshd-generate\n#/etc/init.d/apache2 start\n#/etc/init.d/atftpd start\necho \"This victim machine is now setup.\"\necho \"The IP address is somewhere in the 172.16.45.0/24 network.\"\necho \"You may now close this window and begin your attack...Good \nluck!\"\nYou will need to use a terminal to navigate to the directory where you created \nthe file. You need to make the file executable before you can run it. You can do \nthis by typing:\nchmod 755 IP_Gen.sh\nTo run the script, you type the following command into a terminal:\n./IP_Gen.sh\nThe script should run and provide you with a message saying the victim \nmachine is all set up. Using the script above you will be able to practice locat-\ning and scanning a target machine.\nWhere do I go from here?\nOnce you have mastered the basics of Nmap and Nessus, you should dig into \nthe advanced options for both tools. This chapter only scratched the surface \nof both of these fine tools. Insecure.org is a great resource for learning more \nabout Nmap. You should dedicate time to exploring and learning all of the var-\nious switches and options. Likewise, Nessus has a plethora of additional fea-\ntures. Take time to review the various scans and policy options.\nAfter you are comfortable with the advanced features of these tools, you should \nlook at other scanners as well. There are dozens of good port scanners avail-\nable. Pick a few, install them, and learn their features. There are several com-\nmercial products that you should become familiar with; these products are not \nexclusively vulnerability scanners (they are much more), but Core Impact and \nSaint both provide excellent vulnerability assessment components, although \nboth of these tools will cost you actual cash.\n"
}
|
{
"page_number": 82,
"text": "Scanning CHAPTER 3\n63\nSummary\nThis chapter focused on step 2 that consists mainly of scanning. The chapter \nstarted with a brief overview of pings and ping sweeps before moving into the \nspecifics of scanning. The topic of scanning is further broken down into two \ndistinct types including port scanning and vulnerability scanning. The port \nscanner Nmap was introduced and several different types of scans were dis-\ncussed. Actual examples and outputs of the various scans were demonstrated \nas well as the interpretation of the Nmap output. The concept of vulnerability \nscanning was introduced through the use of Nessus. Practical examples were \npresented and discussed throughout the chapter.\n"
}
|
{
"page_number": 83,
"text": "This page intentionally left blank\n"
}
|
{
"page_number": 84,
"text": "65\nIntroduction\nExploitation is the process of gaining control over a system. This process can \ntake many different forms but for the purpose of this book the end goal always \nremains the same: administrative-level access to the computer. In many ways, \nExploitation\nCHAPTER 4\nInformation in This Chapter:\nn\t Gaining Access to Remote Services with Medusa\nn\t Metasploit: Hacking Hugh Jackman Style!\nn\t John the Ripper: King of the Password Crackers\nn\t Password Resetting: Kind of Like Driving a Bulldozer through the Side of a \nBuilding\nn\t Sniffing Network Traffic\nn\t Macof: Making Chicken Salad Out of Chicken Sh*t\nn\t Fast-Track Autopwn: Breaking Out the M-60\n"
}
|
{
"page_number": 85,
"text": "The Basics of Hacking and Penetration Testing\n66\nexploitation is the attempt to turn the target machine into a puppet that will \nexecute your commands and do your bidding. Just to be clear, exploitation is \nthe process of launching an exploit. An exploit is the realization of a vulner-\nability. Exploits are issues or bugs in the software code that allow a hacker or \nattacker to alter the original functionality of the software.\nOf all the steps we cover, exploitation is probably the step aspiring hackers \nare most interested in. It certainly gets a lot of attention because this phase \ninvolves many of the traditional activities that people associate with “hacking” \nand penetration testing. There are volumes of books that are dedicated to the \nprocess of exploitation. Unfortunately, there are also volumes of misinforma-\ntion regarding step 3. Stories from Hollywood and urban legends of famed \nhacker exploits have tainted the mind of many newcomers. However, this does \nnot mean that exploitation is any less exciting or exhilarating. On the contrary, \nexploitation is still my favorite step, even if there is a little less “shock and awe” \nthan portrayed in a typical hacker movie. But when completed successfully, \nexploitation remains simply breathtaking.\nOf all the steps we discuss, exploitation is probably the least well defined and \nmost open to interpretation. When combined, these two qualities often bring \nchaos and confusion to people trying to learn penetration testing and hacking. \nThe lack of order and structure in a penetration test often leads to frustration \nand failure. It is not uncommon for a novice to read about a new tool, or lis-\nten to a speaker talk about some advanced technique that can be used to gain \naccess to a system, and want to jump directly to step 3 (exploitation). However, \nit is important to remember that penetration testing is more than just exploi-\ntation. Fortunately by following the process identified in this book or by any \nother solid penetration testing methodology, you can alleviate many of these \nissues.\nBecause this book focuses on the basics, and as a final warning, it is critical to \nstress the importance of completing steps 1 and 2 prior to conducting exploi-\ntation. It can be tempting to bypass reconnaissance and scanning and jump \ndirectly to Chapter 4. That is OK for now, but if you are ever going to advance \nyour skills beyond the script kiddie level, you will need to master the other \nsteps as well. The failure to do so will not only severely limit your ability to \ngrow as a penetration tester but will also eventually stunt your growth as an \nexploitation expert. Reconnaissance and scanning will help to bring order and \ndirection to exploitation.\nOK. Now that the speech is over, let us put away the soapbox and get to the \nbusiness at hand: exploitation. As mentioned earlier, exploitation is the most \nfree-flowing phase we will cover. The reason for this is simple; each system is \ndifferent and each target is unique. Depending on a multitude of factors, your \nattack vectors will vary from target to target. Different operating systems, dif-\nferent services, and different processes require different types of attacks. Skilled \nattackers have to understand the nuances of each system they are attempting \nto exploit. As your skills continue to progress from Padawan to Jedi, you will \n"
}
|
{
"page_number": 86,
"text": "Exploitation CHAPTER 4\n67\nneed to expand your knowledge of systems and their exploits. Eventually, you \nwill learn how to create custom exploits.\nYou can use the previous step’s output as a guide for where to begin your \nexploitation attempts. The output from scanning should be used to help shape, \nfocus, and direct your attacks.\nGaining access to remote services with \nMedusa\nWhen reviewing the output from step 2, always make special notes of IP \naddresses that include some type of remote access service. SSH, Telnet, FTP, PC \nAnywhere, and VNC are popular choices because gaining access to these ser-\nvices often results in the complete owning of that target. Upon discovery of one \nof these services, hackers typically turn to an “online password cracker.” Online \npassword crackers work by attempting to brute force their way into a system by \ntrying an exhaustive list of passwords and/or username combinations.\nWhen using online password crackers, the potential for success can be greatly \nincreased if you combine this attack with information gathered from step 1. \nSpecifically you should be sure to include any usernames or passwords you \ndiscovered. The process of online password cracking literally requires the \nattacking program to send a username and a password to the target. If either \nthe username or password is incorrect, the attack program will be presented \nwith an error message and the log-in will fail. The password cracker will then \nsend the next username and password combination. This process continues \nuntil the program is either successful in finding a login/password combo or \nit exhausts all the guesses. On the whole, even though computers are great at \nrepetitive tasks like this, the process is rather slow.\nYou should be aware that some remote access systems employ a password \nthrottling technique that can limit the number of unsuccessful log-ins you are \nallowed. In these instances either your IP address can be blocked or the user-\nname can be locked out.\nThere are many different tools that can be used for online password cracking. \nTwo of the most popular tools are Medusa and Hydra. These tools are very \nsimilar in nature. In this book, the focus will be on Medusa, but it is strongly \nencouraged that you become familiar with Hydra as well.\nMedusa is described as a parallel log-in brute forcer that attempts to gain access \nto remote authentication services. Medusa is capable of authenticating with \na large number of remote services including AFP, FTP, HTTP, IMAP, MS-SQL, \nMySQL, NetWare NCP, NNTP, PcAnywhere, POP3, REXEC, RLOGIN, SMTP-\nAUTH, SNMP, SSHv2, Telnet, VNC, Web Form, and more.\nIn order to use Medusa, you need several pieces of information including \nthe target IP address, a username or username list that you are attempting to \nlog in as, a password or dictionary file containing multiple passwords to use \n"
}
|
{
"page_number": 87,
"text": "The Basics of Hacking and Penetration Testing\n68\nwhen logging in, and the name of the service you are attempting to authenti-\ncate with.\nOne of the requirements listed above is a dictionary list. A password dictionary \nis a file that contains a list of potential passwords. These lists are often referred \nto as dictionaries because they contain thousands or even millions of individual \nwords. People often use plain English words or some small variation like a 1 for \nan i, or a 5 for an s when they create passwords. Password lists attempt to collect \nas many of these words as possible. Some hackers and penetration testers spend \nyears building password dictionaries that grow to gigabytes in size. A good dic-\ntionary can be extremely useful but often requires a lot of time and attention to \nkeep clean. Clean dictionaries are streamlined and free of duplication.\nThere are plenty of small wordlists that can be downloaded from the Internet \nand serve as a good starting point for building your own personal password \ndictionary. There are also tools available that will build dictionaries for us. \nHowever, fortunately, the fine folks at Backtrack have already included a few \nword lists for us to use. You can find these dictionaries in the /pentest/pass-\nwords/wordlists directory. There is also a small list included with the John \nthe Ripper located at: /pentest/passwords/jtr/password.lst.\nOnce you have your password dictionary, you need to decide if you are going \nto attempt to log in as a single user or if you want to supply a list of potential \nusers. If your reconnaissance efforts were rewarded with a list of usernames, \nyou may want to start with those. If you were unsuccessful in gathering user-\nnames and passwords, you may want to focus on the results of the e-mail \naddresses you collected with The Harvester. Remember the first part of an \ne-mail address can often be used to generate a working domain username.\nAssume that during your penetration test you were unable to find any domain \nusernames. However, The Harvester was able to dig up the e-mail address ben.\nowned@example.com. When using Medusa, one option is to create a list of \npotential usernames based on the e-mail address. These would include ben.\nowned, benowned, bowned, ownedb, and several other combinations derived \nfrom the e-mail address. After creating a list of 5–10 usernames, it is possible to \nfeed this list into Medusa and attempt to brute force my way into the remote \nauthentication service.\nNow that we have a target IP address with some remote authentication ser-\nvice (we will assume SSH for this example), a password dictionary, and at least \none username, we are ready to run Medusa. In order to execute the attack, you \nopen a terminal and issue the following command:\nmedusa –h target_ip –u username –P path_to_password_dictionary –M \nauthentication_service_to_attack\nTake a moment to examine this command in more detail; you will need to cus-\ntomize the information for your target:\nThe first keyword “medusa” is used to start the brute forcing program.\n“-h” is used to specify the IP address of the target host.\n"
}
|
{
"page_number": 88,
"text": "Exploitation CHAPTER 4\n69\nThe “-u” is used to denote a single username that Medusa will use to \nattempt log-ins.\nIf you generated a list of usernames and would like to attempt to log in \nwith each of the names on the list, you can issue a capital “-U” followed by \nthe path to the username file.\nLikewise, the lowercase “-p” is used to specify a single password, whereas a \ncapital “-P” is used to specify an entire list containing multiple passwords. \nThe “-P” needs to be followed by the actual location or path to the diction-\nary file.\nThe “-M” switch is used to specify which service we want to attack.\nTo clarify this attack, let us continue with the example we set up earlier. \nSuppose we have been hired to conduct a penetration test against the com-\npany “Example.com.” During our information gathering with MetaGooFil, we \nuncover the username of “ownedb” and an IP address of 172.16.45.129. After \nport scanning the target, we discover that the server is running SSH on port 22. \nMoving to step 3, one of the first things to do is to attempt to brute force our \nway into the server. After firing up Backtrack and opening a terminal, we issue \nthe following command:\nmedusa –h 172.16.45.129 –u ownedb –P /pentest/passwords/wordlists/\ndarkc0de.lst –M ssh\nFigure 4.1 shows the command and its associated output.\nFIGURE 4.1\nUsing Medusa to Brute Force into SSH.\n"
}
|
{
"page_number": 89,
"text": "The Basics of Hacking and Penetration Testing\n70\nThe first line shows the command we issued; the second line is an informa-\ntional banner that is displayed when the program begins. The remaining lines \nshow a series of log-in attempts with the username “ownedb” and various pass-\nwords beginning with “[1B].” Notice on the 11th log-in attempt Medusa is suc-\ncessful in accessing the system with a username of “ownedb” and a password of \n“!power.” At this point we would be able to remotely log in as the user.\nDepending on the level of engagement and goals identified in your authoriza-\ntion and agreement form, you may be done with the penetration test at this \npoint. Congratulations! You just completed your first penetration test and suc-\ncessfully gained access to a remote system.\nAlthough it is not always quite that easy, you will be surprised at how many \ntimes a simple tactic like this works and allows you full access and control of a \nremote system.\nMetasploit: hacking, Hugh Jackman Style!\nOf all the tools discussed in this book, Metasploit is my favorite. In many ways, \nit is the quintessential hacker tool. It is powerful, flexible, free, and loaded \nwith awesomeness. It is without a doubt the coolest offensive tool covered in \nthis book and in some cases it even allows you to hack like Hugh Jackman in \nSwordfish! Seriously, it is that good. If you ever get a chance to meet HD Moore \nor any of the other original Metasploit crew, buy them a beer, shake their hand, \nand say thanks, because Metasploit is ALL that and more.\nIn 2004, at Defcon 12, HD Moore and spoonm rocked the world when they \ngave a talk titled “Metasploit: Hacking Like in the Movies.” This presentation \nfocused on “exploit frameworks.” An exploit framework is formal structure for \ndeveloping and launching exploits. Frameworks assist the development process \nby providing organization and guidelines for how the various pieces are assem-\nbled and interact with each other.\nMetasploit actually started out as a network game, but its full potential was \nrealized when it was transformed into a full-fledged exploit tool. Metasploit \nactually contains a suite of tools including some great anti-forensics stuff; \nhowever, the project is probably best known for the Metasploit Framework \ncomponent.\nAlert!\nIf you are having problems getting Medusa (or any of the tools covered in this book) \nto run on your version of Backtrack, it may be helpful to reinstall the program as we \ndiscussed in Chapter 1. You can reinstall Medusa with the following commands:\napt-get update\napt-get install medusa\n"
}
|
{
"page_number": 90,
"text": "Exploitation CHAPTER 4\n71\nBefore the release of Metasploit, security researchers had two main choices: \nthey could develop custom code by piecing together various exploits and pay-\nloads or they could invest in one of the two commercially available exploit \nframeworks, CORE Impact or ImunitySec’s CANVAS. Both Impact and CANVAS \nwere great choices and highly successful in their own right. Unfortunately, the \ncost to license and use these products meant many security researchers did not \nhave access to them.\nMetasploit was different from everything else because for the first time hack-\ners and penetration testers had access to a truly open source exploit framework. \nThis meant that for the first time everyone could access, collaborate, develop, \nand share exploits for free. It also meant that exploits could be developed in an \nalmost factory-like assembly line approach. The assembly line approach allowed \nhackers and penetration testers to build exploits based on their own needs.\nMetasploit allows you to select the target and choose from a wide variety of \npayloads. The payloads are interchangeable and not tied to a specific exploit. A \npayload is the “additional functionality” or change in behavior that you want \nto accomplish on the target machine. It is the answer to the question: “What \ndo I want to do now that I have control of the machine?” Metasploit’s most \npopular payloads include adding new users, opening backdoors, and installing \nnew software onto a target machine. The full list of Metasploit payloads will be \ncovered shortly.\nBefore we begin covering the details of how to use Metasploit, it is important \nto understand the distinction between Metasploit and a vulnerability scanner. \nIn most instances, when we use a vulnerability scanner, the scanner will only \ncheck to see if a system is vulnerable. This occurs in a very passive way with little \nchance of any unintentional damage or disruption to the target. Metasploit and \nother frameworks are exploitation tools. These tools do not perform tests; these \ntools are used to complete the actual exploitation of the target. Vulnerability \nscanners look for and report potential weaknesses. Metasploit attempts to actu-\nally exploit the systems it scans. Make sure you understand this.\nIn 2009, Rapid 7 purchased Metasploit. HD Moore spent a considerable \namount of time putting people at ease and reassuring everyone that Metasploit \nwould remain free. Although several great commercial products have since been \nreleased including Metasploit Express and Metasploit Pro, HD has been true to \nhis word and the original Metasploit project remains free. In fact, the purchase \nof Metasploit by Rapid 7 has been a huge boost to the Metasploit project. The \nopen source project is clearly benefitting from the commercial tool push with \nadditional full-time developers and staff. The rate at which new exploits and \nfunctionality is being added is staggering. We will focus on the basics here, but \nyou will want to stay on top of latest developments going forward.\nMetasploit can be downloaded for free by clicking on the Framework link \nlocated at http://www.metasploit.com. If you are using Backtrack, Metasploit \nis already installed for you. There are several different ways to interact with \n"
}
|
{
"page_number": 91,
"text": "The Basics of Hacking and Penetration Testing\n72\nMetasploit, but this book will focus on using the menu-driven, non-GUI, \ntext-based system called the Msfconsole. Once you understand the basics, \nthe Msfconsole is fast, friendly, intuitive, and easy to use. When possible, you \nshould avoid the Msfweb or Msfgui versions especially when first learning.\nWe can access the Msfconsole by either opening a terminal window and \nentering:\n/pentest/exploits/framework3/msfconsole\nThe Msfconsole can also be accessed through the menu by clicking on the \nK-Start dragon, and navigating to: Backtrack → Penetration → Metasploit \nExploitation Framework → Framework Version 3 → Msfconsole.\nStarting the Msfconsole takes between 10 and 30 seconds, so do not panic if \nnothing happens for a few moments. Eventually Metasploit will start by pre-\nsenting you with a welcome banner and an “msf” command prompt. There \nare several different Metasploit banners that are rotated and displayed at ran-\ndom so if your screen looks different from Figure 4.2, that is normal. The \nimportant thing is that you get the msf console. The initial Metasploit screen \nis shown in Figure 4.2.\nPlease notice, when Metasploit first loads, it shows you the number of exploits, \npayloads, encoders, and nops available. It also shows you how many days have \npassed since your last update. Because of Metasploit’s rapid growth and official \nfunding, it is vital that you keep Metasploit up-to-date. This is easily accom-\nplished by entering the following command after the “msf” prompt: msfup-\ndate. Get into the habit of running this command often.\nNow that Metasploit is updated, let us begin exploring the awesomeness of this \ntool. In order to use Metasploit a target must be identified, and exploit must be \nFIGURE 4.2\nInitial Metasploit Screen.\n"
}
|
End of preview.
No dataset card yet
- Downloads last month
- -