Monday, 31 August 2015

Ethical Hacking - Module 3 : Scanning

                                          Scanning Life Cycle


1. Identify the Live Host

2. Identify the Open Port

3. Banner Grabbing :- Identify the services

4. Scanning beyond Firewall / IDS

5. Vulnerability Scanning

6. Drawing Network Topology

7. Using Proxy

Some more classification include

 Port Scanning: Open port and services
 Network Scanning: IP Address
 Vulnerability Scanning: Presence of known weaknesses

1. Identify Live Hosts

Ping sweep

# nmap -sn 192.168.13.*


A normal PING request sends out an ICMP echo request to the target host, which intern replies with an ICMP echo reply. 

Ping sweep is just a technique that can be used to find out which hosts are alive in a network or large number of IP addresses.
  
# nmap -sP 192.168.13.1-254



Ping Sweeping with fping command

you can also use fping command to do ping sweeping. You can install fping throuh yum. fping command is commonly used to send ICMP echo request to large number of hosts(ping sweep).

By default if you ping a large number of hosts using fping command, it assumes a host as unreachable if there no echo reply from the target host.

  

You can also mention the network address, or range of IP address as an argument to fping command, to do ping sweeping as shown below.

 
  
Ping Sweeping A network Which has blocked ICMP

Many network infrastructure security people block's ICMP traffic targeted to their network. Which will prevent ping Sweeping. So in such cases nmap tool has a good option to determine which hosts are alive in the network.

For achieving this, nmap uses TCP to scan the network instead of ICMP. It is called as tcp ping scan. it can be done the following way.

 
In the above method, what nmap does is to attempt making connection to port 80, and determines whether the host is alive.(it does not matter even if the port is not open on the target host. but traffic for that target port must be allowed in the network)the same thing can be achieved by using hping utility.

A firewalled host with blocked ICMP will not respond to the ICMP echo request. The obvious basic use of this scan is to find all active hosts on the network. This set of two commands gives a list of all active IP addresses in the 192.168.100.0/24 range:


# nmap -sP -n -oG hostlist 192.168.100.0/24 ## grep'able output file, hostlist
# cut -d " "-f2 hostlist > iplist    ## list of all active IPs in the target range, iplist
)

The ping scan uses only one packet for the request, and may get one packet in response, thus making it the fastest of all Nmap scan types, with the lowest footprint. The ping scan cannot be combined with other scan types.

Adv:
   Very difficult to trace — only two standard ICMP frames,

     which are very common in network traffic,are required to
       complete the scan.

   Root privilege not required to run the scan.


   Yields a device inventory by identifying active devices on the

    network.


2. Identify Open Ports


Below are the different kinds of scans for finding the open ports in a system,

 2.1 TCP Connect Scan

# nmap -sT -v 192.168.0.10

Requires Privileged Access: NO
Identifies TCP Ports: YES
Identifies UDP Ports: NO


The TCP connect() scan is named after the connect() call that's used by the operating system to initiate a TCP connection to a remote device. The TCP connect() scan uses a normal TCP connection to determine if a port is available. This scan method uses the same TCP handshake connection that every other TCP-based application uses on the network. 

 

As the trace file excerpt shows, the TCP connect() scan completed the TCP three-way handshake and then immediately sent a reset (RST) packet to close the connection.

Unlike the TCP SYN scan, the nmap output shows that very few raw packets were required for the TCP connect() process to complete:


# nmap -sT -v 192.168.0.10

Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2005-04-11 12:30 EDT
Initiating Connect() Scan against 192.168.0.10 [1663 ports] at 12:30
Discovered open port 3389/tcp on 192.168.0.10
Discovered open port 80/tcp on 192.168.0.10
Discovered open port 3306/tcp on 192.168.0.10
Discovered open port 445/tcp on 192.168.0.10
Discovered open port 139/tcp on 192.168.0.10
Discovered open port 520/tcp on 192.168.0.10
Discovered open port 135/tcp on 192.168.0.10
The Connect() Scan took 1.45s to scan 1663 total ports.
Host 192.168.0.10 appears to be up ... good.
Interesting ports on 192.168.0.10:
(The 1656 ports scanned but not shown below are in state: closed)
PORT     STATE SERVICE
80/tcp   open  http
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
520/tcp  open  efs
3306/tcp open  mysql
3389/tcp open  ms-term-serv
MAC Address: 00:30:48:11:AB:5A (Supermicro Computer)

Nmap finished: 1 IP address (1 host up) scanned in 2.242 seconds
               Raw packets sent: 2 (68B) | Rcvd: 1 (46B)

Advantages of the TCP connect() Scan
No special privileges are required to run the TCP connect() scan. Nmap uses the operating system's normal method of connecting to remote devices via TCP before it tears down the connection with the RST packet. Because these are TCP-based methods that any user can employ, no additional rights or privileges are required.


Disadvantages of the TCP connect() Scan
The disadvantage of this scan is apparent when application connection logs are examined. Since the TCP connect() scan is completing a TCP connection, normal application processes immediately follow


When to use the TCP connect() Scan
Because this scan is so obvious when browsing through the application event logs, it might be considered the TCP scan of last resort. If privileged access isn't available and determination of open TCP ports is absolutely necessary, however, this scan may be the only method available.

The only option to the TCP connect() scan that does not require privileged access but still scans TCP ports is the FTP bounce attack (-b). Given the small number of susceptible FTP servers that will participate in a bounce attack, this option is becoming less viable.


Try not to use the connect() scan unless it's absolutely necessary. It's very obvious (in both network traces and in application log files), and it uses many more system and application resources than the SYN scan! 



  2.2 Sync Scan / half open / half connect / stealth scan


# nmap -sS -v 192.168.0.10

Requires Privileged Access: YES
Identifies TCP Ports: YES
Identifies UDP Ports: NO


The TCP SYN scan uses common methods of port-identification that allow nmap to gather information about open ports without completing the TCP handshake process. When an open port is identified, the TCP handshake is reset before it can be completed. This technique is often referred to as "half open" scanning.

If a scan type is not specified on the nmap command line and nmap currently has privileged access to the host (root or administrator), the TCP SYN scan is used by default.


TCP SYN Scan Operation
Most of the ports queried during the TCP SYN scan will probably be closed. These closed port responses to the TCP SYN frame will be met with a RST frame from the destination station.


 
If nmap receives an acknowledgment to a SYN request, then the port is open. Nmap then sends an RST to reset the session, and the handshake is never completed.

 
 

The nmap output shows the results of this TCP SYN scan. As expected, most of the packets sent during this scan were built using the operating system's raw sockets:

# nmap -sS -v 192.168.0.10

Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2005-04-11 12:25 EDT
Initiating SYN Stealth Scan against 192.168.0.10 [1663 ports] at 12:25
Discovered open port 80/tcp on 192.168.0.10
Discovered open port 3389/tcp on 192.168.0.10
Discovered open port 3306/tcp on 192.168.0.10
Discovered open port 139/tcp on 192.168.0.10
Discovered open port 135/tcp on 192.168.0.10
Discovered open port 520/tcp on 192.168.0.10
Discovered open port 445/tcp on 192.168.0.10
The SYN Stealth Scan took 1.35s to scan 1663 total ports.
Host 192.168.0.10 appears to be up ... good.
Interesting ports on 192.168.0.10:
(The 1656 ports scanned but not shown below are in state: closed)
PORT     STATE SERVICE
80/tcp   open  http
135/tcp  open  msrpc
139/tcp  open  netbios-ssn
445/tcp  open  microsoft-ds
520/tcp  open  efs
3306/tcp open  mysql
3389/tcp open  ms-term-serv
MAC Address: 00:30:48:11:AB:5A (Supermicro Computer)

Nmap finished: 1 IP address (1 host up) scanned in 2.117 seconds
  Raw packets sent: 1705 (68.2KB) | Rcvd: 1664 (76.5KB)


Advantages of the TCP SYN Scan
The TCP SYN scan never actually creates a TCP session, so isn't logged by the destination host's applications. This is a much "quieter" scan than the TCP connect() scan, and there's less visibility in the destination system's application logs since no sessions are ever initiated. Since an application session is never opened, the SYN scan is also less stressful to the application service.


Disadvantages of the TCP SYN Scan
The TCP SYN scan requires that nmap have privileged access to the system. Without privileged access, nmap can't create the raw packets necessary for this half-open connection process.


When to use the TCP SYN Scan
The SYN scan is a common scan when looking for open ports on a remote device, and its simple SYN methodology works on all operating systems. Because it only half-opens the TCP connections, it's considered a very 'clean' scan type.

The TCP SYN scan only provides open, closed, or filtered port information. To determine operating system or process version information, more intrusive scanning is required, such as the version scan (-sV) or the operating system fingerprinting (-O) option.


The TCP SYN scan is the most common scan to use because it works on all networks, across all operating systems, and it's invisible to applications. If the SYN scan didn't work, then TCP wouldn't work! 


  2.3 FIN Scan


# nmap -sF 192.168.100.100

The standard use of a FIN packet is to terminate the TCP connection — typically after the data transfer is complete. Instead of a SYN packet, Nmap initiates a FIN scan by using a FIN packet. Since there is no earlier communication between the scanning host and the target host, the target responds with an RST packet to reset the connection. However, by doing so, it reveals its presence.

Steath Scanning :- The FIN Scan(-sF), Xmas Tree Scan(-sX), and Null Scan(-sN), Sync scan(-sS)


The FIN scan's "stealth" frames are unusual because they are sent to a device without first going through the normal TCP handshaking. If a TCP session isn't active, the session certainly can't be formally closed!

In this FIN scan, TCP port 443 is closed so the remote station sends a RST frame response to the FIN packet:


 
 
 

The nmap output shows the open ports located with the FIN scan:

# nmap -sF -v 192.168.0.7

Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2005-04-23 21:17 EDT
Initiating FIN Scan against 192.168.0.7 [1663 ports] at 21:17
The FIN Scan took 1.51s to scan 1663 total ports.
Host 192.168.0.7 appears to be up ... good.
Interesting ports on 192.168.0.7:
(The 1654 ports scanned but not shown below are in state: closed)
PORT     STATE         SERVICE
21/tcp   open|filtered ftp
22/tcp   open|filtered ssh
23/tcp   open|filtered telnet
79/tcp   open|filtered finger
110/tcp  open|filtered pop3
111/tcp  open|filtered rpcbind
514/tcp  open|filtered shell
886/tcp  open|filtered unknown
2049/tcp open|filtered nfs
MAC Address: 00:03:47:6D:28:D7 (Intel)

Nmap finished: 1 IP address (1 host up) scanned in 2.276 seconds
               Raw packets sent: 1674 (66.9KB) | Rcvd: 1655 (76.1KB)
 
 
  2.4 Xmas Scan

# nmap -sX -v 192.168.0.7

The Xmas tree scan sends a TCP frame to a remote device with the URG, PUSH, and FIN flags set. This is called a Xmas tree scan because of the alternating bits turned on and off in the flags byte (00101001), much like the lights of a Christmas tree.









  2.5 Null scan

# nmap -sN -v 192.168.0.7 

The null scan turns off all flags, creating a lack of TCP flags that should never occur in the real world.



The null scan showed the same results as the FIN scan and the Xmas tree scan:


# nmap -sN -v 192.168.0.7

Starting nmap 3.81 ( http://www.insecure.org/nmap/ ) at 2005-04-23 21:19 EDT
Initiating NULL Scan against 192.168.0.7 [1663 ports] at 21:19
The NULL Scan took 1.42s to scan 1663 total ports.
Host 192.168.0.7 appears to be up ... good.
Interesting ports on 192.168.0.7:
(The 1654 ports scanned but not shown below are in state: closed)
PORT     STATE         SERVICE
21/tcp   open|filtered ftp
22/tcp   open|filtered ssh
23/tcp   open|filtered telnet
79/tcp   open|filtered finger
110/tcp  open|filtered pop3
111/tcp  open|filtered rpcbind
514/tcp  open|filtered shell
886/tcp  open|filtered unknown
2049/tcp open|filtered nfs
MAC Address: 00:03:47:6D:28:D7 (Intel)

Nmap finished: 1 IP address (1 host up) scanned in 2.251 seconds
               Raw packets sent: 1674 (66.9KB) | Rcvd: 1655 (76.1KB)

 
Refer rest of the document in 
Ethical Hacking - Module3: Scanning2 .........

Ethical Hacking - Module2: Footpringint & Reconnaissance (Information Gathering)


Footprinting is classified into two Passive & Active Information Gathering.

Foot Printing Pen Testing Steps:

Step1: Get proper Authorization.

Step2: Define the scope of the assessment.

Step3: Perform Footprinting through Search Engines.
    google, aol, bing other site etc

Step4: Perform Website Footprinting.
    telnet, Paros prox, Burp Suite, firebug, httrack

Step5: Perform Email Footprinting.
Email headers, eMailTrackerPro, Paraben E-mail Examiner, PoliteMail

Step6: Gather Competitive Intelligence.
    Info about products, customers, competitors and technologies
      using Internet.

Step7: Perform Google hacking.
    GoogleHackingDatabase(GHDB), Check for google hack operators

Step8: Perform WHOIS Footprinting
    whois, domain lookup table, country whois.

Step9: Perform DNS Footprinting.
    dnsstuff.com, dnswatch.info

Step10: Perform Network Footprinting.
    ARIN whois, NeoTrace, VisualRoute, taceroute,
    www.pathanalyzer.com

Step11: Perform Footprinting through Social Engineering.
    eavesdropping, shoulder surfing, dumpster diving etc etc

Step12: Perform Footprinting through Social Networking sites.
    Faceboot,linkedin,google+ etc etc, Ip Grabber

Step13: Document all the findings

FootPrinting Tools: Maltego / domain name analyzer pro / web data extractor

Ethical Hacking - Module1 : Introduction to Ethical Hacking

Essential Hacking Terminologies


Hack value - Often adduced as the reason or motivation for expending effort toward a seemingly useless goal, the point being that the accomplished goal is a hack.

Exploit - An exploit is a defined way to "breach" the "Security" of an IT system through vulnerability. The term Exploit is used when any kind of attack has taken place on a system or network. An Exploit also be a 'malicious s/w' or 'commands' that can cause unanticipated behavior.

Vulnerability - A vulnerability is a "weakness in design" which allows an attacker to reduce a system's information assurance. It’s a loop hole, Limitation or Weakness that becomes a source for an attacker. Vulnerability is the intersection of three elements: a system susceptibility or flaw, attacker access to the flaw, and attacker capability to exploit the flaw.

Target Of Evaluation - A product or component that is identified / subjected to a required security evaluation. This helps the evaluator understand the functioning, technology and vulnerabilities of a particular system or product.

Zero-day Attacks - Exploit software flaws before they are publically disclosed. Zero day attacks are difficult to prevent because they exploit unknown vulnerabilities, for which there are no patches and no antivirus or "Intrusion-Detection-Signatures" they wrote.

Daisy Chaining - Process where a hacker gains entry into a computer or network and then uses it to gain access to another, they usually complete their task and then backtrack to cover their tracks by destroying logs etc.

Double File Extensions - Another easy trick on the filename is to add two extensions to it. This is often combined with long filenames to show only the first extension, such as “Madonna.jpg.exe
Dropper - A dropper is a malicious file used to install malicious code on a computer. Downloader Trojans are sometimes also called droppers.

Back door – a hole deliberately placed by designers into a security system. Hackers use back doors to get into a system.
Bit bucket – the universal data dump. Lost, deleted, or destroyed data ends up here.

Bot - A bot is malicious code that acts like a remotely controlled “robot” for an attacker, with other Trojan and Worm capabilities.
Boot Sector Virus - A boot sector virus is malcode that spreads in the wild by copying itself to the Master Boot Record (MBR) of a hard disk and boot sectors of floppy disks.

Black hats – A criminal hacker who causes damage and breaks the law by hacking.

Backdoor Trojans - Backdoor Trojans provide an attacker with full remote access to a computer. If one code is detected a new private undetected code may have been installed on the computer to maintain access and control. Backdoor Trojans first had “fun stuff” options to open the CD tray, flash the lights on the keyboard, and mess with the mind of a victim. Today they may include a remote C&C server that tracks how many infections per country and log files by IP address. Trojans are sometimes specialized, only grabbing online gaming credentials or software license keys.

Cracker – someone who breaks into a security system. Many hackers separate themselves from crackers because crackers are often tied to organized crime rings.

Cyber Terrorists - who create fear by large-scale disruption of computer network?

Deep magic – a special technique central to a program.

Hacker – a person who is able to break into a computer’s system without permission.

Hacking run – a hacking session that lasts in an excess of eight to ten hours.

Foo – term used as a sample name for programs and files.
File Infector - File infector, mostly a historical term, generally refers to viruses that infect files.

Fake Related Extension - File extensions can be faked – that file with an .mp3 extension may actually be an executable program. Hackers can fake file extensions by abusing a special Unicode character, forcing text to be displayed in reverse order. Windows also hides file extensions by default, which is another way novice users can be deceived – a file with a name like picture.jpg.exe will appear as a harmless JPEG image file.

Fake Icon - Fake icons are often given to files to make a credibility to the users.

Gray hat – a hacker who sometimes hacks illegally and sometimes hacks “legally”. Who use both offensive & defensive.
KISS Principle – acronym for “Keep It Simple Stupid,” used to control development complexity by hackers.

Kluge – a clever programming trick that works for the wrong reason.
Keylogger - Keylogger is a type of Trojan used to capture data keylogged on a system. It may also include sophisticated Trojans that can capture all keystrokes and take pictures of the screen at specific points in time to steal online credentials and other sensitive information. It may also refer to physical keylogger devices that can be placed in line between keyboards and a computer to steal sensitive information. An example of a physical keylogger device is KeyGhost, available at http://www.keyghost.com/keylogger/.
Lots of MIPS but no I/O – describes a system that has a lot of processing power, but a bottlenecked input/output.

Logic Bomb - A logic bomb is a type of Trojan that typically executes a destructive routine when certain conditions are met, such as date and time.

Long File Extensions - Long file extensions have been around for many years. On Windows NTFS based operating systems, the filename can be up to 255 characters long (http://en.wikipedia.org/wiki/Filename). Filenames that are very long are abbreviated with three dots “...,” concealing the true extension of the file.

Macro Viruses - Macro viruses are spreading within Microsoft Office software. They are created within Visual Basic for Applications or WordBasic, and spread through Office documents such as DOC files.
Munge – a rewrite of a routine, data structure, or whole program.
Netiquette – the standards of politeness across the internet; not often observed by hackers.

Phreaking – the science of cracking a phone network.

Polymorphic - Polymorphic viruses assume many (poly) shapes and forms (morphic) by encrypting code differently with each infection.

Payload - A payload is the primary action of a malicious code attack. A payload refers to the component of a computer virus that executes a malicious activity. It is the part of the transmitted data which is the fundamental purpose of the transmission.

Proof of Concept - Proof of concept (POC) is a functional code used to prove exploitation or functionality. POCs are sometimes created by authors of exploits to prove that exploitation of a vulnerability is possible.

Script kiddie – a “copycat hacker” who copies other hacker’s techniques without creating anything of their own. An unskilled hacker.

Security through obscurity – hacker term for a common way of dealing with security holes where they are ignored and not documented with the hope nobody finds them.

Sneaker – an individual hired to break into places with the purpose of testing their security.

Spaghetti code – code that has a complex and tangled control structure.

Spy Hackers - Individuals employed by organization to penetrate and gain trade secret of the competitor.

State Sponsored Hackers - Individuals employed by governments to penetrate and gain top-secret information and to damage information systems of other governments.

Suicide Hacker - Individual who aims to bring down critical infrastructure for a cause, and are not worried about facing jail terms or any other kind of punishment.

Time bomb – program that is set to trigger once certain conditions are reached.

Trojan horse – program that disguises itself as one thing but once inside a computer, it actually does something else. Most often, they are damaging (viruses), but not all are.

Trojan - A Trojan is a malicious software that masquerades as something it is not. It does not replicate. One of the most common Trojans in the wild in 2008 is downloader Trojans from generic family names like Agent, Small, and Deaf.

White hats – a hacker who is considered “nice” i.e. when he hacks, he informs the owner he has done it. Using for defensive purpose, which used for security purposes.

Vaporware – term used by hackers referring to products released in advance of their official release date.

Wetware – phrase referring to humans on the other end of a computer system.

Virus – a self-replicating program that inserts itself into computer systems and causes damage. A virus is a malicious software that infects a host file to spread. It is commonly used in a general sense to refer to all sorts of malcode, but this is not technically accurate.


Voodoo programming – the use by guess of an obscure system that someone doesn’t really understand; i.e., whether it works or doesn’t work, the user has no real idea why.

Vulcan nerve pinch – a keyboard combination that forces a soft-boot.
Wedged – a point where a system is stuck; different from a crash, where the system is nonfunctioning.

Wizard – person who completely understands how a program or process works.

Worm - A worm is malicious software that creates a copy of itself (or clones itself) to spread. For example, a mass-mailing worm sends out copies of itself via e-mail. Some individuals prefer to call worms any code that traverses across a network through various means.

Vector - The vector of attack is how transmission of malcode takes place, such as e-mail, a link sent to an instant messenger user, or a hostile Web site attempting to exploit vulnerable software on a remote host. An attack vector is a path or means by which a hacker (or cracker) can gain access to a computer or network server in order to deliver a payload or malicious outcome.

The vector is where the malcode comes from, which can be a form of media transfer such as e-mail or P2P networks, or exploitation combined with Web browsing.

For example, default view settings of Windows do not show the true extension of a file. “report.doc” may only appear as “report” to the end user. Various methods exist to then trick users into thinking malicious files are safe, exploiting this default behavior of Windows, when it is actually malicious.

Peer-to-Peer Networks - Peer-to-peer (P2P) networks involve hosts sharing files with one another, either directly or through a centralized P2P server. However, risk escalates to more than 75% on average once a user starts to search for terms like famous women used in social engineering, like “Paris,” or pornography related terms and illegal terms like “warez” and “crack.”

Internet Relay Chat (IRC) - was a big part of how people “chatted” or communicated near the turn of the century. Today, social networking sites and forums are dominating the scene as IRC falls into the background. IRC is still used by thousands daily and has similar threats to several years ago. It is common to receive spammed messages within IRC chat rooms, private messages from bots by bad actors, and more. Sometimes bad actors attempt to exploit vulnerable software (chat clients) or may send malcode through IRC to the user via links or files directly through a DCC connection.

False positive - monitoring triggered an event but nothing was actually wrong, and in doing so the monitoring has incorrectly identified benign communications as a danger.
True positive - the monitoring system recognized an exploit event correctly.

True negative - the monitoring system has not recognized benign traffic as cause for concern. In other words, it does nothing when nothing needs to be done. This is good.

Tuning - customizing a monitoring system to your environment.
Promiscuous interface - a network interface that collects and processes all of the packets sent to it regardless of the destination MAC address.


Signature - a -- String of characters or activities found within processes or data communications that describes a known system attack. Some monitoring systems identify attacks by means of a signature.

IDS can alert to these conditions by matching known conditions (signatures) with unknown but suspect conditions (anomalies).

--> Confidentiality—unauthorized access may breach confidentiality
--> Integrity—corruption due to an attack destabilizes integrity
--> Availability—denial of service keeps data from being available
Hostile Codecs (Zlob) / E-Mail / Web-Based Attacks / Brute Force Attacks / Instant Messaging / Adware / Spyware / Potentially Unwanted Programs

Hacktivism
Hacktivism is an act of promoting a political agenda by hacking especially by defacing or disabling website. Hacktivism is motivated by revenge,political or social reasons, ideolog etc


Pre-Attack Phase


Hacking Phases / Hacking Life Cycle : 

The various phases involved in hacking are:

* Reconnaissance / Information Gathering / Foot Printing

* Scanning

* Gaining Access

* Maintaining Access

* Clearing Tracks


Types of Security Policies

A Security Policy is a document that contains information on the way the company plans to protect its information assets from known and unknown threats. These policies help to maintain the confidentially, availability and integrity of information.


Four types of policies are:

Promiscuous Policy: No restrictions on internet or remote access

Permissive Policy: Policy begins wide open and only known dangerous services/attacks blocked, which makes it difficult to keep up with current exploits.

Prudent Policy: It provides maximum security while allowing known but necessary dangers. It blocks all services and only safe/necessary services are enabled individually; everything is logged.

Paranoid Policy: It forbids everything, no internet connection, or severely limited internet usage.