03 - Performing Security Assessments
03 - Performing Security Assessments
Ahmed Sultan
Senior Technical Instructor
ahmedsultan.me/about
1
Outlines
Labs
Lab 1: Exploring the Lab Environment
Lab 2: Scanning and Identifying Network Nodes
Lab 3: Intercepting and Interpreting Network Traffic with Packet Sniffing Tools
Lab 4: Analyzing the Results of a Credentialed Vulnerability Scan
• Basic topology discovery tasks can be accomplished using the command line tools
built into Windows and Linux.
• The following tools report the IP configuration and test connectivity on the local
network segment or subnet:
✓ ipconfig—show the configuration assigned to network interface(s) in Windows.
✓ ifconfig—show the configuration assigned to network interface(s) in Linux.
✓ ping—probe a host on a particular IP address or host name using Internet Control Message
Protocol (ICMP), You can use ping with a simple script to perform a sweep of all the IP
addresses in a subnet.
✓ arp—display the local machine's Address Resolution Protocol (ARP) cache. The ARP cache
shows the MAC address of the interface associated with each IP address the local host has
communicated with recently.
• For more information about commands, including syntax usage, look up the
command in an online resource for Windows (docs.microsoft.com/en-
us/windows-server/administration/windows-commands/windows-commands) or
Linux (linux.die.net/man).
• In Linux, commands such as ifconfig, arp, route, and traceroute are deprecated
and the utilities have not been updated for some years, The iproute2 suite of
tools supply replacements for these commands
(digitalocean.com/community/tutorials/how-to-use-iproute2-tools-to-manage-
network-configuration-on-a-linux-vps).
• The following tools can be used to test the routing configuration and connectivity
with remote hosts and networks:
✓ route—view and configure the host's local routing table. Most end systems use a default
route to forward all traffic for remote networks via a gateway router.
✓ tracert—uses ICMP probes to report the round trip time (RTT) for hops between the local
host and a host on a remote network, tracert is the Windows version of the tool.
✓ traceroute—performs route discovery from a Linux host, traceroute uses UDP probes
rather than ICMP, by default.
✓ pathping—provides statistics for latency and packet loss along a route over a longer
measuring period, pathping is a Windows tool; the equivalent on Linux is mtr.
• Scanning a network using tools such as ping is time consuming and non-stealthy,
and does not return detailed results.
• Most topology discovery is performed using a dedicated IP scanner tool.
• An IP scanner performs host discovery and identifies how the hosts are
connected together in an internetwork.
• The Nmap Security Scanner (nmap.org) is one of the most popular open-source IP
scanners.
• Nmap can use diverse methods of host discovery, some of which can operate
stealthily and serve to defeat security mechanisms such as firewalls and intrusion
detection.
• The tool is open-source software with packages for most versions of Windows,
Linux, and macOS, It can be operated with a command line or via a GUI (Zenmap).
• The basic syntax of an Nmap command is to give the IP subnet (or IP host
address) to scan.
• When used without switches like this, the default behavior of Nmap is to ping
and send a TCP ACK packet to ports 80 and 443 to determine whether a host is
present.
• On a local network segment, Nmap will also perform ARP and ND (Neighbor
Discovery) sweeps.
• If a host is detected, Nmap performs a port scan against that host to determine
which services it is running.
• Having identified active IP hosts on the network and gained an idea of the
network topology, the next step in network reconnaissance is to work out which
operating systems are in use, which network services each host is running, and, if
possible, which application software is underpinning those services.
• This process is described as service discovery.
• Service discovery can also be used defensively, to probe potential rogue systems
and identify the presence of unauthorized network service ports.
• When Nmap completes a host discovery scan, it will report on the state of each
port scanned for each IP address in the scope.
• At this point, you can run additional service discovery scans against one or more
of the active IP addresses.
• Some of the principal options for service discovery scans are:
✓ TCP SYN (-sS)—this is a fast technique also referred to as half-open scanning, as the scanning
host requests a connection without acknowledging it, The target's response to the scan's SYN
packet identifies the port state.
✓ UDP scans (-sU)—scan UDP ports, As these do not use ACKs, Nmap needs to wait for a
response or timeout to determine the port state, so UDP scanning can take a long time, A
UDP scan can be combined with a TCP scan.
✓ Port range (-p)—by default, Nmap scans 1000 commonly used ports, as listed in its
configuration file, Use the -p argument to specify a port range.
• When services are discovered, you can use Nmap with the -sV or -A switch to
probe a host more intensively to discover the following information:
✓ Protocol—do not assume that a port is being used for its "well known" application protocol.
Nmap can scan traffic to verify whether it matches the expected signature (HTTP, DNS, SMTP,
and so on).
✓ Application name and version—the software operating the port, such as Apache web server
or Internet Information Services (IIS) web server.
✓ OS type and version—use the -O switch to enable OS fingerprinting (or -A to use both OS
fingerprinting and version discovery).
✓ Device type—not all network devices are PCs, Nmap can identify switches and routers or
other types of networked devices, such as NAS boxes, printers, and webcams.
• Basic service discovery tasks can also be performed using tools built into the
Windows and Linux operating systems:
✓ netstat—show the state of TCP/UDP ports on the local machine, The same command is
used on both Windows and Linux, though with different options syntax.
• Basic service discovery tasks can also be performed using tools built into the
Windows and Linux operating systems (cont.)
✓ nslookup/dig—query name records for a given ___domain using a particular DNS resolver
under Windows (nslookup) or Linux (dig).
• theHarvester
✓ theHarvester is a tool for gathering open-source intelligence (OSINT) for a particular ___domain
or company name (github.com/laramies/theHarvester).
✓ It works by scanning multiple public data sources to gather emails, names, subdomains, IPs,
URLs and other relevant data.
• dnsenum
✓ While you can use tools such as dig and whois to query name records and hosting details and
to check that external DNS services are not leaking too much information.
✓ a tool such as dnsenum packages a number of tests into a single query
(github.com/fwaeytens/dnsenum).
✓ As well as hosting information and name records, dnsenum can try to work out the IP address
ranges that are in use.
• scanless
✓ Port scanning is difficult to conceal from detection systems, unless it is performed slowly and
results are gathered over an extended period.
✓ Another option is to disguise the source of probes, To that end, scanless is a tool that uses
third-party sites (github.com/vesche/scanless).
✓ This sort of tool is also useful in a defensive sense, by scanning for ports and services that are
open but shouldn't be.
• curl
✓ curl is a command line client for performing data transfers over many types of protocol, This
tool can be used to submit HTTP GET, POST, and PUT requests as part of web application
vulnerability testing, curl supports many other data transfer protocols, including FTP, IMAP,
LDAP, POP3, SMB, and SMTP.
• Nessus
✓ The list of services and version information that a host is running can be cross-checked
against lists of known software vulnerabilities, This type of scanning is usually performed
using automated tools.
✓ Nessus, produced by Tenable Network Security (tenable.com/products/nessus/nessus-
professional), is one of the best-known commercial vulnerability scanners.
✓ It is available in on-premises (Nessus Manager) and cloud (Tenable Cloud) versions, as well as
a Nessus Professional version, designed for smaller networks.
✓ The product is free to use for home users but paid for on a subscription basis for enterprises.
✓ As a previously open-source program, Nessus also supplies the source code for many other
scanners.
• Packet and protocol analysis depends on a sniffer tool to capture and decode the
frames of data.
• Network traffic can be captured from a host or from a network segment.
• Using a host means that only traffic directed at that host is captured.
• Capturing from a network segment can be performed by a switched port
analyzer (SPAN) port (or mirror port).
• This means that a network switch is configured to copy frames passing over
designated source ports to a destination port, which the packet sniffer is
connected to.
• Sniffing can also be performed over a network cable segment by using a test
access port (TAP).
• This means that a device is inserted in the cabling to copy frames passing over it.
• Typically, sniffers are placed inside a firewall or close to a server of particular
importance.
• The idea is usually to identify malicious traffic that has managed to get past the
firewall.
• A single sniffer can generate an exceptionally large amount of data, so you cannot
just put multiple sensors everywhere in the network without provisioning the
resources to manage them properly.
• Depending on network size and resources, one or just a few sensors will be
deployed to monitor key assets or network paths.
• tcpdump
✓ is a command line packet capture utility for Linux (linux.die.net/man/8/tcpdump).
✓ The basic syntax of the command is tcpdump -i eth0, where eth0 is the interface to listen
on.
✓ The utility will then display captured packets until halted manually (Ctrl+C).
✓ Frames can be saved to a .pcap file using the -w option.
✓ Alternatively, you can open a pcap file using the -r option.
• tcpdump is often used with some sort of filter expression to reduce the number
of frames that are captured:
✓ Type—filter by host, net, port, or portrange.
✓ Direction—filter by source (src) or destination (dst) parameters (host, network, or port).
✓ Protocol—filter by a named protocol rather than port number (for example, arp, icmp, ip,
ip6, tcp, udp, and so on).
✓ and (&&)
✓ or (||)
✓ not (!)
For Example:
tcpdump -i eth0 "src host 10.1.0.100 and (dst port 53 or dst port 80)"
• You can apply a capture filter using the same expression syntax as tcpdump
(though the expression can be built via the GUI tools too).
• You can save the output to a .pcap file or load a file for analysis.
• Wireshark supports very powerful display filters
(wiki.wireshark.org/DisplayFilters) that can be applied to a live capture or to a
capture file.
• You can also adjust the coloring rules (wiki.wireshark.org/ColoringRules), which
control the row shading and font color for each frame.
• Another useful option is to use the Follow TCP Stream context command to
reconstruct the packet contents for a TCP session.
hping
• is an open-source spoofing tool that provides a penetration tester with the ability to craft
network packets to exploit vulnerable firewalls and IDSs, hping can perform the following
types of test:
✓ Host/port detection and firewall testing—like Nmap, hping can be used to probe IP addresses
and TCP/UDP ports for responses.
✓ Traceroute—if ICMP is blocked on a local network, hping offers alternative ways of mapping
out network routes, hping can use arbitrary packet formats, such as probing DNS ports using
TCP or UDP, to perform traces.
✓ Denial of service (DoS)—hping can be used to perform flood-based DoS attacks from
randomized source Ips, This can be used in a test environment to determine how well a
firewall, IDS, or load balancer responds to such attacks.
tcpreplay
• As the name suggests, tcpreplay takes previously captured traffic that has been saved to
a .pcap file and replays it through a network interface (linux.die.net/man/1/tcpreplay).
• Optionally, fields in the capture can be changed, such as substituting MAC or IP
addresses.
• tcpreplay is useful for analysis purposes.
• If you have captured suspect traffic, you can replay it through a monitored network
interface to test intrusion detection rules.
• A remote access trojan (RAT) is malware that gives an adversary the means of
remotely accessing the network.
• From the perspective of security posture assessment, a penetration tester might
want to try to establish this sort of connection and attempt to send corporate
information over the channel (data exfiltration).
• If security controls are working properly, this attempt should be defeated (or at
least detected).
• The custom exploit module can then be injected into the target system.
• The framework may also be able to obfuscate the code so that it can be injected
past an intrusion detection system or antivirus software.
• The best-known exploit framework is Metasploit (metasploit.com).
• The platform is open-source software, now maintained by Rapid7.
• There is a free framework (command line) community edition with installation
packages for Linux and Windows.
• Rapid7 produces pro and express commercial editions of the framework and it
can be closely integrated with the Nexpose vulnerability scanner.
• One simple but effective tool for testing connectivity is Netcat (nc), available for
both Windows and Linux.
• Netcat can be used for port scanning and fingerprinting.
• For example, the following command attempts to connect to the HTTP port on a
server and return any banner by sending the "head" HTTP keyword:
• The following command connects to the listener and grants access to the
terminal:
nc 10.1.0.1 666
• Used the other way around, Netcat can be used to receive files.
• For example, on the target system the attacker runs the following:
• On the handler (IP 10.1.0.192), the attacker receives the file using the following
command:
Lab 3: Intercepting and Interpreting Network Traffic with Packet Sniffing Tools
Default Settings
✓Relying on the manufacturer default settings when deploying an appliance or software
applications is one example of weak configuration.
✓It is not sufficient to rely on the vendor to ship products in a default-secure
configuration, though many now do.
✓Default settings may leave unsecure interfaces enabled that allow an attacker to
compromise the device.
✓Network appliances with weak settings can allow attackers to move through the network
unhindered and snoop on traffic.
Open Permissions
✓Open permissions refers to provisioning data files or applications without differentiating
access rights for user groups.
✓Permissions systems can be complex and it is easy to make mistakes, such as permitting
unauthenticated guests to view confidential data files, or allowing write access when
only read access is appropriate.
Unsecure Protocols
✓An unsecure protocol is one that transfers data as cleartext; that is, the protocol does not
use encryption for data protection.
✓Lack of encryption also means that there is no secure way to authenticate the endpoints.
✓This allows an attacker to intercept and modify communications, acting as man-in-the-
middle (MITM).
Weak Encryption
✓Encryption algorithms protect data when it is stored on disk or transferred over a
network.
✓Encrypted data should only be accessible to someone with the correct decryption key.
✓Weak encryption vulnerabilities allow unauthorized access to data.
Errors
✓Weakly configured applications may display unformatted error messages under certain
conditions.
✓These error messages can be revealing to threat actors probing for vulnerabilities and
coding mistakes.
✓Secure coding practices should ensure that if an application fails, it does so "gracefully"
without revealing information that could assist the development of an exploit.
• The first phase of scanning might be to run a detection scan to discover hosts on
a particular IP subnet.
• In the next phase of scanning, a target range of hosts is probed to detect running
services, patch level, security configuration and policies, network shares, unused
accounts, weak passwords, antivirus configuration, and so on.
• Each scanner is configured with a database of known software and configuration
vulnerabilities.
• The tool compiles a report about each vulnerability in its database that was found
to be present on each host.
• Each identified vulnerability is categorized and assigned an impact warning.
• The NVD supplements the CVE descriptions with additional analysis, a criticality
metric, calculated using the Common Vulnerability Scoring System (CVSS), plus
fix information.
• CVSS metrics generate a score from 0 to 10 based on characteristics of the
vulnerability, such as whether it can be triggered remotely or needs local access,
whether user intervention is required, and so on.
Score Description
0.1+ Low
4.0+ Medium
7.0+ High
9.0+ Critical
1. Black box
✓(or unknown environment)—the consultant is given no privileged information about the
network and its security systems.
✓This type of test would require the tester to perform a reconnaissance phase.
✓Black box tests are useful for simulating the behavior of an external threat.
2. White box
✓(or known environment)—the consultant is given complete access to information about
the network.
✓This type of test is sometimes conducted as a follow-up to a black box test to fully
evaluate flaws discovered during the black box test.
✓The tester skips the reconnaissance phase in this type of test.
✓White box tests are useful for simulating the behavior of a privileged insider threat.
3. Gray box
✓(or partially known environment)—the consultant is given some information.
✓typically, this would resemble the knowledge of junior or non-IT staff to model particular
types of insider threats.
✓This type of test requires partial reconnaissance on the part of the tester.
✓Gray box tests are useful for simulating the behavior of an unprivileged insider threat.