- Web Penetration Testing with Kali Linux
- Joseph Muniz Aamir Lakhani
- 5407字
- 2021-08-04 10:16:50
Initial research
Reconnaissance should begin with learning as much as possible about people and business associated with the target. Sun Tzu is credited with the phrase, "know your enemy" in the book, The Art of War. As a Penetration Tester, you need to know your target. If your target happens to be a website, you should look at all aspects of that website. It will give you a better understanding of how the site is maintained and run. Great Reconnaissance returns more possible vulnerabilities.
It is scary how much information is available on public sources. We have found the unimaginable, such as classified documents, passwords, vulnerability reports, undesirable photography, and access to security cameras. Many Penetration Testing project objectives start with leveraging information off public sources. Here are some starting points for gathering information from public sources.
Company website
There is a lot of valuable information that can be obtained from a target's website. Most corporate websites list their executive team, public figures, and members from recruiting and human resource contacts. These can become targets for other search efforts and social engineering attacks.
More valuable information can be obtained by looking at what other companies are listed as partners, current job postings, business information, and security policies. Reconnaissance on a high-valued partner can be as important as the primary target, because partners may provide a new source for obtaining intelligence. An example is compromising a contracted resource that manages the helpdesk at a target's headquarters.
The Robots.txt
file is publicly available and found on websites that gives instructions to web robots (also known as search engine spiders), about what is and not visible using the Robots Exclusion Protocol. The Disallow: /
statement tells a browser not to visit a source; however, a Disallow can be ignored by giving a researcher intelligence on what a target hopes to not disclose to the public.
To view the Robots.txt
file, find the Robots.txt
file in the root directory of a target website. For example, adding the Robots.txt
file to Facebook would look as shown in the following screenshot:

Web history sources
There are archived versions of most public websites available on sources such as the WayBack Machine at archive.org. Interesting information can be found in an older version of a target's website, such as outdated organizational charts, phone numbers, customer intelligence, systems information listed in fields, such as view source
or /robots.txt
, older business partnerships, vulnerabilities fixed in later versions, and other useful data, the target doesn't want on the current website version. It is important to understand that the publicly available information is hard to remove completely, making historical sources a valuable place for Reconnaissance research.
To access the WayBack Machine, open up the web browser and navigate to http://archive.org, you will see the Internet Archive WayBack Machine in the middle of the page, as shown in the following screenshot:

Type the URL you would like to browse and see if any archives have been captured. A history of the archive can be viewed here, as shown in the following screenshot:

As a Penetration Tester, this is a valuable tool, because it doesn't leave evidence of Reconnaissance on your target. In fact, your target is never even touched using this tool. All the information has been archived online in the Wayback Machine. The next two screenshots show www.lancope.com in 2002 compared to 2013:


Regional Internet Registries (RIRs)
RIR is an organization that manages the allocation and registration of IP resources within a particular region of the world. There are five major RIRs: the USA, Canada, and parts of the Caribbean region can be found at www.arin.net. You can gather information on a target such as Lancope, as seen in the following screenshot:

Electronic Data Gathering, Analysis, and Retrieval (EDGAR)
The EDGAR database contains registration statements, periodic reports, and other forms of information on companies since 1994. Companies in the United States of America are required by law to file, and all information is publicly available. The following two screenshots show public documents found while searching Lancope:


Social media resources
Social media is everywhere, and in most cases, publicly accessible. Most people have a Facebook, LinkedIn, blogs, or other forms of cloud accounts containing valuable information. This information can be used as a means of social engineering intelligence from a target's current or previous staff. An example is searching Glassdoor.com to identify previous employees that are disgruntled, based on feedback.
There are many people finding web resources such as Maltego (found in Kali Linux) that can comb popular social media, public records, and job recruiting websites to fingerprint an individual based on limited information, such as a first and last name. A researcher could gather information such as everywhere an individual has lived, done business, people with which they socialize, special interests, favorite sport teams, and other useful data for future research and social engineering attacks.
Trust
Most people are naturally trusting and assume information posted on public sources is real. To test this concept, the writers of this book created a fake person through social media and pretended to be a new hire for a target company. The fake person would become friends with associates of our target, post fake holiday cards that are linked to a BeEF system designed to compromise vulnerable Internet browsers (using BeEF is covered later in this book), and captured sensitive information from compromised systems. We were able to map out the entire organization, obtain network information, and even had hardware shipped to us without an internal e-mail or phone number. Our fake person, Emily Williams isn't real, yet received job offers, was provided inside information, and access to events hosted by the target. Information is power, and people will give it to a requester who seems like they can be trusted.
More information on this project can be found at: http://www.thesecurityblogger.com/?p=1903
Job postings
Job postings contain a wealth of knowledge about a target's environment. Job listings can provide details on what type of systems are installed, who manages them, how large the staff is, and the staff's skill level. Human Resource representatives are typically eager to share information with a potential new hire, which can be used as an avenue to inside information. An example is targeting a job posting for a Oracle developer to understand the hardware, version of Oracle, names of existing and previous administrators, existing operation issues, security gaps, and methods to access such as asking "can administrators work from home, and how do they access the systems?"
Another avenue to review is a job's expected salary, benefits, and turnover rate on popular job boards. These trends may uncover new vectors for attack. Glassdoor.com is an example of a popular source for this type of data.
Location
The investment in cyber security for a target can typically be determined based on the level of physical security. One would assume a building with fences and armed guards would have a higher investment in cyber security than a target located within a public building. Online mapping sources such as Google maps can help identify where physical security is implemented, and trends on how people move to and from the target. Other areas of interest are identifying where a Penetration Tester could camp out to scan for wireless networks, and possible methods to bypass access controls, such as attire and badges used to obtain physical access.
Shodan
Shodan is a search engine that can identify a specific device, such as computer, router, server, using a variety of filters, such as metadata from system banners. For example, you can search for a specific system, such as a Cisco 3850, running a version of software such as IOS Version 15.0(1)EX.
The following example is a use case searching for any SCADA system with public Internet access, which in theory isn't supposed to exist however, Shodan can show this is not necessarily true. SCADA systems control things like power management and water treatment, so identifying public accessible systems is extremely bad!

Google hacking
Google hacking is the most common form of search engine Reconnaissance of web applications. Google hacking uses advanced operations in the Google search engine to locate specific strings of text within search results. Search filters can zero in on specific versions of vulnerable web applications such as Powered by Apache in the intitle:"index of"
operator or identify log files such as ws_ftp.log
, containing sensitive IP information. The following few screenshots demonstrate using a Google search for Linksys to find publicly available Linksys cameras. The first screenshot shows the search command followed by some example results from issuing the search. The last screenshot shows a camera feed that could be found using this technique.



Some example search queries are as follows:
- Identifies sensitive documents:
intext: classified top secret
- Identifies Linksys Camera Management GUIs (caution: you may not like what you find):
inurl:main.cgi
- Identifies Nessus reports to find vulnerable systems:
inurl:NESSUSXXXXXXXX
For more information on Google hacking, check out a very good book titled Google Hacking for Penetration Testers by Johnny Long, as well as his website at http://johnny.ihackstuff.com.
Google Hacking Database
The Google Hacking Database (GHDB) created by Johnny Long of Hackers For Charity (http://www.hackersforcharity.org/), is the definitive source for Google search queries. Searches for usernames, passwords, vulnerable systems, and exploits have been captured and categorized by Google hacking aficionados. The aficionados who have categorized the Google searches are affectingly known as Google dorks.
To access the GHDB, navigate to http://www.exploit-db.com/google-dorks/. You will see the latest GHDB searches listed on the web page. You can click on any of the search queries yourself.

You will find different categories of searches at the bottom of the page that have been saved. In the following example, we scroll to the category Vulnerable Files and select the query ionCube Loader Wizard.


We can select the search query, and it will bring us to Google, performing the same search query.

The preceding example shows Google has found a few results. The ionCube Loader is apparently not configured or misconfigured. The ionCube Loader is actually a great piece of software that protects software written in PHP from being viewed or changed from unlicensed computers. However, in this case, administrators left the default wizard running without any configuration.

When we click on the first link, we get the home screen to configure the software.
The GHDB essentially turns Google into a limited web application scanner for a Penetration Tester. In this case, good software that can increase security can now potentially be used against a web server by an attacker.
Researching networks
Many people do not understand the true purpose of researching the network of a target prior to launching an attack. Amateur Penetration Testers understand the need to pick a target before they can perform a Penetration Test. After all, a Penetration Tester needs someplace at which to point their arsenal of tools. Many amateurs will run Nmap, ping sweeps, or other noisy tools to determine what targets are available disrupting the environment, which later yields poor results.
Network Reconnaissance is about selecting a target. A seasoned network security professional will tell you good Reconnaissance is about selecting a quality target, spending the majority of their time watching, rather than acting. The first step of every Penetration Test is accurately finding and selecting quality targets.
Tip
From a client's viewpoint, Penetration Testers will encounter individuals that gain satisfaction in stopping Penetration Testers to prove their value as employees, as well as how well prepared they are for cyber attacks. It is highly recommended that a professional Penetration Tester does not get into a conflict with a client's staff while penetration services are being performed. A Penetration Tester should focus on security awareness, and reveal what vulnerabilities exist with the least amount of interaction with a target's staff during a service engagement.
The following are the best available tools in Kali for web application Reconnaissance. Other tools may be available for web applications or different target types however, the focus of this chapter is enabling a reader for evaluating web application-based targets.
HTTrack – clone a website
HTTrack is a tool built into Kali. The purpose of HTTrack is to copy a website. It allows a Penetration Tester to look at the entire content of a website, all its pages, and files offline, and in their own controlled environment. In addition, we will use HTTrack for social engineering attacks in later chapters. Having a copy of a website could be used to develop fake phishing websites, which can be incorporated in other Penetration Testing toolsets.
To use HTTrack, open a Terminal window and type in apt-get install httrack
as shown in the following screenshot.
Note
Some versions of Kali do not have this built-in.

You will want to create a directory to store your copied website. The following screenshot shows a directory created named mywebsites
using the mkdir
command.

To start HTTrack, type httrack
in the command window and give the project a name, as shown in the following screenshot:

The next step is to select a directory to save the website. The example in the following screenshot shows the folder created in the previous step /root/mywebsites
, used for the directory:

Enter the URL of the site you want to capture. The example in the following screenshot shows www.drchaos.com. This can be any website. Most attacks use a website accessed by clients from your target, such as popular social media websites or the target's internal websites.
The next two options are presented regarding what you want to do with the captured site. Option 2 is the easiest method, which is a mirror website with a wizard as shown in the following screenshot:

Next, you can specify if you want to use a proxy to launch the attack. You can also specify what type of files you want to download (the example in the following screenshot shows *
for all files). You can also define any command line options or flags you might want to set. The example in the following screenshot shows no additional options.
Before httrack
runs, it will display the command that it is running. You can use this command in the future if you want to run httrack without going through the wizard again. The following two screenshots show hhtrack
cloning www.drchaos.com:


After you are done cloning the website, navigate to the directory where you saved it. Inside, you will find all your files and webpages, as shown in the following screenshot:

You are now ready to research your target's website and possibly build a customized penetration tool or exploit user access to a cloned website.
ICMP Reconnaissance techniques
The ping
and traceroute
commands are good ways to find out basic information about your target. When information travels across networks, it usually does not go directly from source to destination. It usually traverses through several systems, such as routers, firewalls, and other computer systems before it gets to its destination. The traceroute
command identifies each system the data travels across, along with the time it takes for the data to move between systems. The tool is installed in every modern operating system. For most high-value targets, the ping
and traceroute
commands will most likely be disabled, and excessive use of these services will most likely trigger alerts on network security systems. Many firewalls or other systems are set up not to respond to number B24RYE routes. If systems do respond to traceroute
, using this too excessively can trigger security events. These tools are noisy, and when used indiscriminately, they will set off alarms and logs. If your goal is to be stealthy, you have just been defeated, giving your target an opportunity to set up and deploy counter measures against your Penetration Test.
An ICMP sweep simply sends out an echo request and looks for a reply. If a reply is returned, then, as a Penetration Tester, you know there is a possible target. The problem with ICMP scans is that ICMP is usually blocked by most firewalls. That means any scans from outside going to an internal target network will be blocked by an ICMP scanner.
The ping
command is the most basic way to start an ICMP sweep. You simply type in ping
followed by a hostname or IP address to see what will respond to the ICMP echo request. The following screenshot shows a ping of www.google.com:

If you get any responses back, you will know that your host is alive. If you get any timeouts, your ICMP request is being blocked, or no destination host has received your request.
The problem with the ping
command is that it only allows you to use ICMP to check on one host at a time. The fping
command will allow you ping multiple hosts with a single command. It will also let you read a file with multiple hostnames or IP addresses and send them using ICMP echo requests packets.
To use the fping
command to run an ICMP sweep on a network, issue the following command:
fping-asg network/host bits fping -asg 10.0.1.0/24
Although the a
flag will return the results via IP address of live hosts only, the s
flag displays statistics about the scan, the g
flag sets fping
in quite mode, which means it does show the user the status of each scan, only the summary when it has completed.
Note
The Nmap provides similar results as the fping
command.
DNS Reconnaissance techniques
Most high-value targets have a DNS name associated to an application. DNS names make it easier for users to access a particular service and add a layer of professionalism to their system. For example, if you want to access Google for information, you could open a browser and type in 74.125.227.101
or type www.google.com
.
DNS information about a particular target can be extremely useful to a Penetration Tester. DNS allows a Penetration Tester to map out systems and subdomains. Older DNS attacks transfer a zone file from an authoritative DNS, allowing the tester to examine the full contents of the zone file to identify potential targets. Unfortunately, most DNS servers today do not allow unauthenticated zone transfers. However, all is not lost! DNS by its very nature is a service that responds to queries; therefore, an attacker could use a word list query containing hundreds of names with a DNS server. This attack vector is an extremely time consuming task; however, most aspects can be automated.
Dig (domain information groper) is one the most popular and widely used DNS Reconnaissance tools. It queries DNS servers. To use Dig, open a command prompt and type dig
and hostname, where hostname represents the target domain. Dig will use your operating systems default DNS settings to query the hostname. You can also configure Dig to query custom DNS servers by adding @<IP>
to the command. The example in the following screenshot illustrates using Dig on www.cloudcentrics.com.

The -t
option in Dig will delegate a DNS zone to use the authoritative name servers. We type dig -t ns cloudcentrics.com
in the example in the following screenshot:

We see from the results we have two authoritative DNS servers for the domain www.cloudcentrics.com; they are ns3681.hostgator.com
and ns3682.hostgator.com
.
Congratulations, you have just found the authoritative DNS server for your target DNS.
DNS target identification
Now that you have found the authoritative DNS servers for a domain, you might want to see what hosts have entries on that domain. For example, the domain drchaos.com may have several hosts. such as cloud.drchaos.com
, mail. drchaos.com
, sharepoint.drchaos.com
. These all could be potential applications and potentially high value targets.
Before we randomly start choosing hosts, we should query the DNS server to see what entries exist. The best way to do that is to ask the DNS server to tell us. If the DNS server is configured to allow zone transfers, it will give us a copy of all its entries.
Kali ships with a tool named Fierce. Fierce will check to see if the DNS server allows zone transfers. If zone transfers are permitted, Fierce will execute a zone transfer and inform the user of the entries. If the DNS server does not allow zone transfers, Fierce can be configured to brute force host names on a DNS server. Fierce is designed as a Reconnaissance tool before you use a tool that requires you to know IP addresses, such as Nmap.
To use Fierce, navigate to Information Gathering | DNS Analysis | Fierce. Fierce will load into a terminal window as shown in the following screenshot.

To run the Fierce
script, type the following command:
fierce.pl -dns thesecurityblogger.com

The domain thesecurityblogger.com, shown in the preceding screenshot, has a few hosts associated with it. We have accomplished our task. However, you can see Fierce failed at completing a zone transfer. Fierce will try and brute force a zone transfer using a word list or dictionary file if you have one defined. We did not, because the goal of this section is to determine what hosts exist on the domain, not necessarily at this point carry out a zone transfer attack. However, if your goal is more inclusive than targeting web applications, you may want to explore this further on your own.
We can now target a particular host and use tools like Nmap to proceed further in mapping out our target. An important aspect of using Fierce is selecting a target using very little network traffic, which is important for avoiding detection. We will use Nmap to gather more information about our target later in this chapter.
Maltego – Information Gathering graphs
Maltego is a Reconnaissance tool built into Kali developed by Paterva. It is a multipurpose Reconnaissance tool that can gather information using open and public information on the Internet. It has some built-in DNS Reconnaissance, but goes much deeper into fingerprinting your target and gathering intelligence on them. It takes the information and displays the results in a graph for analysis.
To start Maltego, navigate to Application menu in Kali, and click on the Kali menu. Then select Information Gathering | DNS Analysis | Maltego.
The first step when you launch Maltego is to register it. You cannot use the application without registration.

When you complete registration, you will be able to install Maltego and start using the application.

Maltego has numerous methods of gathering information. The best way to use Maltego is to take advantage of the startup wizard to select the type of information you want to gather. Experienced users may want to start with a blank graph or skip the wizard all together. The power of Maltego is that it lets you visually observe the relationship between a domain, organization, and people. You can focus around a specific organization, or look at an organization and its related partnerships from DNS queries.
Depending on the scan options chosen, Maltego will let you perform the following tasks:
- Associate an e-mail address to a person
- Associate websites to a person
- Verify an e-mail address
- Gather details from Twitter, including geolocation of pictures
Most of the features are self-explanatory and include how they are used under the feature description. Maltego is used commonly to gather information and sometimes used as the first step during a social engineering attack.

Nmap
Nmap stands for Network Mapper, and is used to scan hosts and services on a network. Nmap has advanced features that can detect different applications running on systems as well as services and OS fingerprinting features. It is one of the most widely used network scanners making it very effective, but also very detectable. We recommend using Nmap in very specific situations to avoid triggering a target's defense systems.
For more information on how to use Nmap, see http://nmap.org/.
Additionally, Kali comes loaded with Zenmap. Zenmap gives Nmap a graphical user interface (GUI) to run commands. Although there are many purists who will tell you the command-line version is the best version because of its speed and flexibility, Zenmap has come a long way and has incorporated most of the Nmap features. Zenmap also offers exclusive features not offered in Nmap, such as developing graphical representations of a scan, which can be used later by other reporting systems.
To open Zenmap, go to the Backtrack menu. Navigate to Information Mapping | DNS Analysis, and launch Zenmap.

You will notice under the Profile menu that there are several options to determine what type of scan you would like to run, as shown in the following screenshot:

The first step is creating a new profile. A profile in Zenmap allows a Penetration Tester to create what type of scan to execute and what different options to include. Navigate to the Profile menu and select New Profile or Command to create a new profile, as shown in the following screenshot:

When you select New Profile or Command, the profile editor will launch. You will need to give your profile a descriptive name. For example, you can call the profile My First Scan
or anything else you would like.
Optionally, you can give the profile a description. During your course of using Zenmap you will probably create many profiles and make multiple scans. A natural reflex may be to delete profiles post execution. Here is a word of advice: profiles don't take any space and come handy when you want to recreate something. We recommend being extremely descriptive in profile names and come up with a standard naming method. I start all my profile description with the date, time, description of my location, my target network scan location, and customer name.

When you completed your description, click on the Scan tab. In the Targets section, you will add what hosts or networks you would like to scan. This field can take a range of IP addresses (10.0.1.1-255) or it can take a network in CIDR format (10.0.1.0/24).
You can see option -A is selected by default to enable aggressive scanning. Aggressive scanning will enable OS detection (-O), version detection (-sV), script scanning (-sC) and traceroute (--traceroute). Essentially, aggressive scanning allows a user to turn on multiple flags without the need of having to remember them.
Aggressive scan is considered intrusive, meaning it will be detected by most security devices. An aggressive scan may go unnoticed if your target is an extremely specific host, but regardless of the situation, it's recommended you have the permission to scan before using this or scanning option. As a reminder, completing the ACK in the three-way handshake with an unauthorized system is considered illegal by the US standards.
We can use the information we received from our DNS Reconnaissance exercise to target a very specific host. Before we do that, let's set a few common options first.

Click on the Ping tab. Select the -Pn flag option so Nmap will not ping the host first. When this flag is not set, Nmap will ping your target hosts and networks. Default settings only perform scans on hosts that are considered alive or reachable. The -Pn flag tells Nmap to scan a host even without a ping response. Although this makes the scan considerably more lengthy, the –Pn flag allows Nmap to avoid a common problem of not receiving a ping response when the ping requests are blocked by security defenses.

Save changes made by clicking on the Save Changes button in the lower-right hand corner. Once saved, select the Scan button on the top-right side of the screen to start the scan. Notice your options and target that you configured in the profile editor are listed.

The network Topology tab will give you a quick look at how your scan on the target network was completed, and if you had to cross any routers. In this example, you see the scan stayed local to the network.
The Hosts tab will give a list of the hosts discovered.

When a host is selected, Zenmap will display a detailed list of the hosts, their operating systems, and common services. In the following screenshot, you can see one of our hosts is a satellite DVR/receiver combo.

If you look at the scan window, you will not only see what ports are open on specific hosts, but also what applications are running on those hosts. Notice that Nmap can determine things, such as a server is running IIS 5.0 as a web server over port 80. The scan results will yield the IP address of the server, the operating system the server is running, as well as the web applications running on the host. Penetration Testers will find these results valuable when they are searching for exploits against this host.
.

It is now possible for you to concentrate your efforts on the target's running web services or port 80, because it is open.
Zenmap is the best way to get output from Nmap scans. Zenmap offers a rich graphical user interface that displays scans that can be exported into different formats, such as text or Microsoft Excel.
Although there are many ways to get outputs from Nmap (for example, the authors in this book prefer the command-line techniques) we have included this technique because it is constantly referenced in many web penetration standards and is a common way for people to use it.

In addition, several places in GUI for Zenmap allow the user to export graphics and certain parts of the report in CSV files or image files. These exports are extremely valuable when creating reports.

FOCA – website metadata Reconnaissance
Did you know every time you create a document, such as a Microsoft PowerPoint presentation, Microsoft Word document, or PDF, metadata is left in the document?
What is metadata? Metadata is data about data. It is descriptive information about a particular data set, object, or resource, including how it is formatted as well as when and by whom it was collected. Metadata can be useful to Penetration Testers, because it contains information about the system where the file was created, such as:
- Name of users logged into the system
- Software that created the document
- OS of the system that created the document
FOCA is a security-auditing tool that will examine metadata from domains. You can have FOCA use search engines to find files on domains or use local files.
FOCA is built into Kali; however, the version is dated. Best practice is downloading the newest version. FOCA has traditionally been a Windows tool, and the newer versions may be only available for Windows.
The latest version of FOCA can be downloaded at: http://www.informatica64.com/DownloadFOCA (use Google Translate to see the page in English).
You will need to give your e-mail address at the bottom of the screen. You will receive an e-mail with the download link. You will also receive updates when FOCA has new releases.
- The first thing to do after launching FOCA is create a new project, as shown in the following screenshots:.
Tip
We recommend keeping all project files in one place. You should create a new folder for each project.
- Once you name your project and decide where you want to store the project files, click on the Create button, as shown in the following screenshot:
- Next thing to do is save your project file. Once you saved the project, click on the Search All button so FOCA will use search engines to scan for documents. Optionally, you can use local documents as well.
- Right-click on the file and select the Download option, as shown in the following screenshot:
- Right-click on the file and select the Extract Metadata option, as shown in the following screenshot:
- Right-click on the file and select the Analyze Metadata option, as shown in the following screenshot:
In the following screenshot, you can see two people opened this document.

You can also determine Microsoft Office for the Mac and Adobe Photoshop were used to create this document as shown in the following screenshot:

In many cases, attackers will be able to see much more information and gather intelligence about a target.
FOCA allows the user to save and index a copy of all the metadata. In addition, each type of metadata file can be saved and copied. This gives a Penetration Tester a wealth of information. Screenshots are usually used to give an overview of the indexed files, along with a listing of all individual files. Finally, FOCA will allow a Penetration Tester to download individual files that can be used as examples.
- Hands-On Machine Learning with scikit:learn and Scientific Python Toolkits
- C語言程序設計(第2 版)
- 兩周自制腳本語言
- Linux核心技術從小白到大牛
- INSTANT Weka How-to
- Hadoop+Spark大數據分析實戰(zhàn)
- Web全棧工程師的自我修養(yǎng)
- Internet of Things with Intel Galileo
- 老“碼”識途
- 零基礎學Java程序設計
- 零基礎輕松學SQL Server 2016
- Building Serverless Applications with Python
- Instant PHP Web Scraping
- Python機器學習之金融風險管理
- Learning Ionic