Enumeration and System Hacking Basics
Enumeration and System Hacking Basics
The “Do I Know This Already?” quiz enables you to assess whether you should
read this entire chapter thoroughly or jump to the “Exam Preparation Tasks”
section. If you are in doubt about your answers to these questions or your own
assessment of your knowledge of the topics, read the entire chapter. Table 4-
1 lists the major headings in this chapter and their corresponding “Do I Know
This Already?” quiz questions. You can find the answers in Appendix A,
“Answers to the ‘Do I Know This Already?’ Quizzes and Review Questions.”
Caution
1. Password sniffing
2. Dumpster diving
3. Password injection
4. Software keylogger
2. When reviewing a Windows domain, you are able to extract some account
information. A RID of 500 is associated with what account?
1. A user account
2. The first user’s account
3. The guest account
4. The administrator account
3. During enumeration, what port may specifically indicate a Windows
computer that perhaps is sharing files or printing resources in the network?
1. 110
2. 111
3. 25
4. 445
4. During enumeration, what tool can help you discover Windows systems
running NetBIOS?
1. nbtscan
2. Burp Suite
3. John the Ripper
4. Hashcat
5. Which of the following is a tool commonly used for password cracking?
1. Hyena
2. John the Ripper
3. LCP
4. IAM tool kit
6. Which type of password cracking makes use of the space/time memory
trade-off?
1. Dictionary attack
2. Rainbow table
3. Rule
4. Hybrid
7. Microsoft uses various techniques to protect user account information. The
second layer of security on the SAM file is known as what?
1. Encoding
2. Obscuring
3. SYSKEY
4. Salting
8. Which format stores Windows passwords in a 14-character field?
1. NTLMv2
2. Kerberos
3. Salted
4. LAN Manager
9. Which of the following matches the common padding found on the end of
short Windows LAN Manager (LM) passwords?
1. 1404EE
2. EE4403
3. EEEEEE
4. 1902DD
10. If you were going to enumerate DNS, which of the following tools could you
use?
1. Route print
2. ARP -A
3. Nslookup
4. Ipconfig
Foundation Topics
Enumeration
Enumeration can be described as an in-depth analysis of targeted computers.
Enumeration is performed by actively connecting to each system to identify
the user accounts, system accounts, services, and other system details.
Enumeration is the process of actively querying or connecting to a target
system to acquire information on NetBIOS/LDAP, SNMP, UNIX/Linux
operation, NTP servers, SMTP servers, and DNS servers. These topics are
discussed next.
Windows Enumeration
Figure 4-1 shows the basic model that Windows uses for protective rings.
Figure 4-1 Windows Architecture
With the Windows architecture, you can see that there are two basic modes:
user mode (ring 3) and kernel mode (ring 0). User mode has restrictions,
whereas kernel mode allows full access to all resources. This is an important
concept for the ethical hacker to contemplate because antivirus and analysis
tools can detect hacking tools and code that run in user mode. However, if
code can be deployed on a Windows system to run in kernel mode, it can hide
itself from user mode detection and will be harder to detect and eradicate. All
the code that runs on a Windows computer must run in the context of an
account. The system account can perform kernel-mode activities. The privilege
level of the account you hold determines your ability to execute code on a
system. Hackers always want to run code at the highest possible privilege.
Windows uses the following two types of identifiers to help keep track of a
user’s security rights and identity:
S-1-5-21-1607980848-492894223-1202660629-500
S for security id
1 Revision level
1607980848 SA
492894223 SA domain id
1202660629 SA
500 User id
Focus your attention on the last line of text in this example. The user ID
specifies the specific user, as shown in Table 4-2.
User ID Code
Admin 500
Guest 501
Kerberos 502
First user 1000
This table shows that the administrator account has a RID of 500 by default,
the guest has a RID of 501, and the first user account has a RID of 1000. Each
new user gets the next available RID. This information is important because
simply renaming an account will not prevent someone from discovering key
accounts. This is similar to the way that Linux controls access for users and
system processes through an assigned user ID (UID) and a group ID (GID) that
is found in the /etc/passwd file. On a related topic, let’s look at some other
important security components of Microsoft Windows that will help you
understand the enumeration process.
Tip
You should be able to correlate specific user accounts and RIDs for the exam,
such as 500 = administrator.
Windows Security
This table lists key ports and protocols that Microsoft systems use. When
you’re performing a port scan or attempting to identify a system, finding these
open ports will signal that you might be dealing with a Microsoft system. After
these ports have been identified, you can begin to further enumerate each
system.
Tip
SMB was designed to make it possible for users to share files and folders,
although InterProcess Communication (IPC$) offers a default share on
Windows systems. This share, the IPC$, was used to support named pipes that
programs use for interprocess (or process-to-process) communications.
Because named pipes can be redirected over the network to connect local and
remote systems, they also enable remote administration. As you might think,
this can be a problem.
A null session occurs when you log in to a system with no user ID and
password at all. In legacy Windows versions, such as Windows 2003, a null
session could be set up using the net command.
There’s an entire host of net commands. A few are discussed here, but for a
more complete list, just type net from the command line and the /? syntax
after any of the commands for which you would like more information.
Even though you may not see the IPC$ share when looking for shared drives
and folders, that doesn’t mean that it is not there. For example, if you have
identified open ports 135, 139, and 445 on targeted systems, you might attempt
the net view /domain command as demonstrated in Example 4-1.
Example 4-1 Viewing IPC$ Share with the net view /domain Command
Domain
SALES
MARKETING
ACCOUNTING
Notice that these net commands are quite handy. They have identified the
sales, marketing, and accounting groups. To query any specific domain group,
just use the net command again in the form of net view
/domain:domain_name as demonstrated in Example 4-2.
\\sedna
\\faraway
\\charon
You can take a closer look at any one system by using the net view \\
system_name command as demonstrated in Example 4-3.
-----------------------------------------------------
CDRW Disk
D Disk
Payroll Disk
Printer Disk
Temp Disk
Now that you have completed some basic groundwork, let’s move on to
enumerating user details, account information, weak passwords, and so
on. IPC$ is further exploited for these activities. Specifically, you will need to
set up a null session. You can do so manually with the net command:
Note
With a net use \\ computer name\ ipc$ "" /u:"" command executed, you’re
primed to start hacking at the system. Some of the tools discussed in this
section, such as DumpSec and Hyena, require that you have a null session
established before you attempt to use them. DumpSec is a Windows-based
graphical user interface (GUI) enumeration tool from SomarSoft. It enables
you to remotely connect to Windows machines and dump account details,
share permissions, and user information.
Let’s assume that you want to do a quick scan to enumerate all the hosts in a
given network/subnet that are running NetBIOS. For this task you can use the
tool nbtscan, as demonstrated in Example 4-4.
#nbtscan -r [Link]/24
address
--------------------------------------------------------------
--------
--------
00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00
00:00:00:00:00:00
30:05:5c:00:cb:6e
00:00:00:00:00:00
Several systems are discovered in the network. A few servers such as the
computers with the names POSEIDON, HP7B4BD5, and BRN30055C00CB6E
have been discovered. You can do something similar with Nmap using
different NSE scripts, such as those demonstrated in Example 4-5 using the
Linux locate command.
Example 4-5 Using the Linux locate Command to Find NSE Scripts
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
/usr/share/nmap/scripts/[Link]
Some of these NSE scripts not only allow you to perform basic NetBIOS
enumeration but also attempt to discover devices affected by different SMB-
related vulnerabilities.
Because you now know that a server is running NetBIOS with the IP address
[Link], you can do a quick Nmap scan using the SMB share enumeration
script, as demonstrated in Example 4-6.
Example 4-6 Nmap Scan Using the SMB Share Enumeration Script
[Link]
| smb-enum-shares:
| account_used: guest
| \\[Link]\IPC$:
| Type: STYPE_IPC_HIDDEN
| Users: 1
| Path: C:\tmp
| \\[Link]\shared1:
| Type: STYPE_DISKTREE
| Comment: shared1
| Users: 0
| Path: C:\shared1
| \\[Link]\disk4:
| Type: STYPE_DISKTREE
| Comment: disk4
| Users: 0
| Path: C:\disk4
| Anonymous access: <none>
| \\[Link]\disk8:
| Type: STYPE_DISKTREE
| Comment: disk8
| Users: 1
| Path: C:\disk8
| \\[Link]\print$:
| Type: STYPE_DISKTREE
| Users: 0
| Path: C:\var\lib\samba\printers
Several SMB shares are enumerated in the system (shared1, disk4, and disk8).
It looks as though the server is a Linux (Debian) system. To further enumerate
its NetBIOS configuration, you can use the tool enum4linux, as demonstrated
in Example 4-7.
Example 4-7 enum4linux Output
#enum4linux [Link]
enum4linux/ )
==========================
| Target Information |
==========================
bin, none
====================================================
====================================================
============================================
Elections
=====================================
=====================================
===========================================
| Getting domain SID for [Link] |
===========================================
======================================
| OS information on [Link] |
======================================
platform_id : 500
os version : 6.1
=============================
| Users on [Link] |
=============================
index: 0x1 RID: 0x3e8 acb: 0x00000010 Account: root Name:
root
Desc:
user:[root] rid:[0x3e8]
=========================================
=========================================
NT_STATUS_OBJECT_NAME_NOT_FOUND listing \*
====================================================
====================================================
[+] POSEIDON
[+] Builtin
After running the enum4linux utility, you can see additional information
about the configuration and users in the system. It looks as though the system
allows the user root to be able to connect to the server via SMB. This is a
security issue, and an attacker could take advantage of this weak configuration
to potentially compromise the system.
# msfconsole
msf6 > use auxiliary/scanner/netbios/nbname
CIDR identifier, or
'file:<path>'
threads
THREADS => 20
hosts)
Mac:00:00:00:00:00:00
Mac:00:00:00:00:00:00
Addresses:([Link]) Mac:3c:2a:f4:18:17:dc
Addresses:([Link]) Mac:00:00:00:00:00:00
Names:(BRN30055C00CB6E) Addresses:([Link])
Mac:30:05:5c:00:cb:6e
[+] [Link] [MACBOOKPRO-E47A] OS:Unix Names:
(MACBOOKPRO-E47A)
Addresses:([Link]) Mac:00:00:00:00:00:00
Addresses:([Link]) Mac:00:00:00:00:00:00
The output in Example 4-8 reveals the details about each of the hosts that were
enumerated with the tools described earlier in this section. However, you can
also see the enumeration of the underlying operating system type (i.e.,
Windows, Linux/UNIX).
Hyena is a GUI-based tool used to show logon names, shares, IP addresses, and
other account information. It can extract SID, RID, comments, full names, and
so on. From the earlier discussion about SIDs on Windows machines, you
know that the administrator account on the machine ends in 500. Therefore,
you can use Hyena to discover the SIDs for the usernames found in your
enumeration and discover who has administrative access.
Many tools can be used for enumeration. The ones described here should give
you an idea of what this category of tool can do. The following tools also
perform the same type of enumeration:
SNMP version 3 offers data encryption and authentication. Both versions 1 and
2 are still in use, but they are clear-text protocols that provide only weak
security through the use of community strings. The default community strings
are public and private and are transmitted in clear text. If the community
strings have not been changed or if someone can sniff the community strings,
that person then has more than enough to enumerate the vulnerable devices.
Note
SNMP versions 1 and 2 use default community strings of public and private.
Devices that are SNMP enabled share a lot of information about each device
that probably should not be shared with unauthorized parties. SNMP
enumeration tools can be found in both Windows and Linux. Several are
mentioned here:
Earlier in this chapter, you learned how to use the Nmap scanner. You can
leverage Nmap Scripting Engine (NSE) scripts to gather information from
SNMP-enabled devices and to brute-force weak credentials. In Kali Linux, the
NSE scripts are located at /usr/share/nmap/scripts by default.
Example 4-9 shows the available SNMP-related NSE scripts in a Kali Linux
system.
# ls -1 snmp*
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
In addition to NSE scripts, you can also use the snmp-check tool to perform an
“SNMP walk” to gather information on devices configured for SNMP. SNMP
walk (or the associated command snmpwalk) is an SNMP application used to
query a network device for information. Example 4-10 shows an excerpt of the
output of the snmp-check tool enumerating multiple elements of a pfSense
firewall. pfSense is an open source firewall that provides support for legacy
SNMP versions, and you should avoid using this feature in pfSense.
Hostname : [Link]
Default TTL : 64
Interface : [ up ] vtnet0
Id : 1
Type : ethernet-csmacd
MTU : 1500
In octets : 762638291
Interface : [ up ] em0
Id : 2
Type : ethernet-csmacd
Speed : 1000 Mbps
MTU : 1500
In octets : 133663054
Interface : [ up ] em1
Id : 3
Type : ethernet-csmacd
MTU : 1500
In octets : 0
Interface : [ up ] lo0
Id : 5
Type : softwareLoopback
Speed : 0 Mbps
MTU : 16384
In octets : 15887866
Id : 6
Mac Address : :::::
Type : unknown
Speed : 0 Mbps
MTU : 33160
In octets : 0
Id : 7
Type : unknown
Speed : 0 Mbps
MTU : 1500
In octets : 0
Out octets : 0
Id IP Address Netmask
Broadcast
1 [Link] [Link] 0
2 [Link] [Link] 1
5 [Link] [Link] 1
3 [Link] [Link] 1
1 [Link] [Link] 1
[Link] 53 [Link] 0
listen
[Link] 80 [Link] 0
listen
[Link] 0
[Link] 53
[Link] 67
[Link] 123
[Link] 161
[Link] 514
[Link] 123
[Link] 123
[Link] 123
[Link] 123
[*] Processes:
Id Status Name
Path Parameters
1 runnable kernel
2 runnable init
/
sbin/init --
3 runnable crypto
4 runnable crypto
returns 0
5 runnable crypto
returns 1
6 runnable crypto
returns 2
7 runnable crypto
returns 3
8 runnable cam
9 runnable soaiod1
10 runnable soaiod2
11 runnable audit
12 running idle
13 running intr
14 running ng_queue
15 running geom
16 running sequencer
00
17 running usb
18 running soaiod3
19 running soaiod4
20 running
sctp_iterator
21 running pf purge
22 running
rand_harvestq
23 running pagedaemon
24 running vmdaemon
25 running pagezero
As you can see, SNMP can provide very detailed information about the
underlying system architecture, configuration, and network settings that can
be very beneficial for an attacker.
Tip
Always change default passwords! As a best practice, you should also limit
SNMP access to only trusted hosts and block UDP port 161 to any untrusted
system. Another best practice is to use SNMPv3 instead of older versions. In
modern network devices, NETCONF and RESTCONF are more secure solutions
than SNMP.
Linux/UNIX Enumeration
After any type of Linux or UNIX system is found, further probing is still
required to determine what it’s running. Although exploiting Windows-
specific services might be out of the question, you can still exploit services
such as Finger, rwho, rusers, and Simple Mail Transfer Protocol (SMTP) to
learn more.
Rwho and rusers are remote-procedure call (RPC) services that can give
information about the various users on the system. Running rpcinfo -p against
the system will allow an attacker to learn the status of rwho and rusers. Rusers
depends on the rwho daemon. It lists the users logged in to all local machines,
in whois format (hostnames, usernames).
Although not commonly seen anymore, Finger is a program that tells you the
name associated with an email address. It might also tell you whether users
are currently logged in at their system or their most recent login session, and
possibly other information, depending on the data that is maintained about
users on that computer. Finger originated as part of BSD UNIX.
Another potential tool to use for enumeration is SMTP, which sometimes can
be helpful in identifying users. Attackers gain this information by using the
SMTP vrfy (verify) and expn (expand) commands. These commands can be
used to guess users on the system. Simply input the names, and if the user
exists, you receive an RFC 822 email address with the @ sign. If the user
doesn’t exist, you receive a “user unknown” error message. Although a
username is not enough for access, it is half of what’s needed to get into most
systems. If a default password is being used, the attacker may be able to gain
easy access. Attackers might also look to see if a syslog server is present on
UDP port 514.
Some of the techniques used to exploit Linux systems include the following:
You can use basic tools such as the Linux showmount command to enumerate
NFS configurations and shares, as demonstrated in Example 4-11.
[Link]:/disk10
[Link]:/disk4
[Link]:/disk8
[Link]:/disk10
[Link]:/disk4
[Link]:/disk8
[Link]:/disk10
[Link]:/disk4
[Link]:/disk8
[Link]:/disk10
[Link]:/disk4
[Link]:/disk8
In Example 4-11, all the NFS shares in the server with the IP address
[Link] are shown, along with information about all the clients connected
to the server ([Link], [Link], [Link], and [Link]).
Tip
For several best practices and tips on how to harden an NFS implementation,
see [Link]
NTP Enumeration
jitter
==============================================================
=========
[Link].n .POOL. 16 p - 64 0 0.000
0.000
0.000
0.000
0.000
0.000
5.101
0.000
0.145
0.000
-4.170 0.000
[Link] [Link] 3 u 1 64 1 14.643
-1.944
0.000
0.000
0.000
SMTP Enumeration
Attackers may leverage insecure SMTP servers to send spam and conduct
phishing and other email-based attacks. SMTP is a server-to-server protocol,
which is different from client/server protocols such as POP3 or IMAP.
Tip
Before you can understand how to exploit email protocol vulnerabilities (such
as SMTP-based vulnerabilities), you must familiarize yourself with the
standard TCP ports used in the different email protocols. The following TCP
ports are used in the most common email protocols:
TCP port 25: The default port used in SMTP for nonencrypted
communications.
TCP port 587: The Secure SMTP (SSMTP) protocol for encrypted
communications, as defined in RFC 2487, using STARTTLS. Mail user
agents (MUAs) use TCP port 587 for email submission. STARTTLS can
also be used over TCP port 25 in some implementations.
TCP port 110: The default port used by the POP3 protocol in
nonencrypted communications.
TCP port 995: The default port used by the POP3 protocol in
encrypted communications.
TCP port 143: The default port used by the IMAP protocol in
nonencrypted communications.
TCP port 993: The default port used by the IMAP protocol in
encrypted (SSL/ TLS) communications.
SMTP open relay is the term used for an email server that accepts and relays
(that is, sends) emails from any user. It is possible to abuse these
configurations to send spoofed emails, spam, phishing, and other email-related
scams. Nmap has an NSE script to test for open relay configurations. The
details about the script are available
at [Link] Example 4-13 shows
how you can use the script against an email server ([Link]).
telnet [Link] 25
Trying [Link]...
Connected to [Link].
VRFY sys
recipient table
VRFY root
VRFY omar
#smtp-user-enum
( -t host | -T file-of-targets )
options are:
-d Debugging output
-v Verbose
ball.
Examples:
enum )
----------------------------------------------------------
| Scan Information
|
----------------------------------------------------------
Mode ..................... VRFY
1 results.
Most modern email servers disable the VRFY and EXPN commands. It is
highly recommended that you disable these SMTP commands. Modern
firewalls also help protect and block any attempts at SMTP connections using
these commands.
Voice over IP (VoIP) uses a set of specific ports. VoIP’s main use of the Session
Initiation Protocol (SIP) uses ports 2000, 2001, 5050, and 5061. A scan for these
ports can be used to determine whether VoIP is being used. After ports are
identified, an attacker might launch a distributed denial-of-service (DDoS)
attack, launch a spoofing attack, or even attempt to eavesdrop.
Table 4-4 lists additional enumeration techniques and tools for other common
protocols.
IPsec and You can use the ike-scan tool to enumerate and discover
the Internet devices configured for IPsec/IKE. You can download ike-scan
Key from the following GitHub
Exchange repository: [Link] The
(IKE) documentation can be accessed
protocol at [Link]
scan_Documentation.
FTP You can enumerate a server that is running FTP by using the
basic Linux and Windows ftp command or by using tools like
Nmap with NSE scripts like [Link], [Link], ftp-
[Link], [Link], [Link], ftp-
[Link], [Link], and ftp-vuln-cve2010-
[Link].
BGP BGP is the protocol that most Internet service providers use
to route traffic on the Internet. BGP leverages autonomous
system numbers (ASNs) for different operations. IANA
assigns AS numbers to different organizations. You can
enumerate ASNs by using the Whois tool or by using websites
such as the BGP toolkit from Hurricane Electric
at [Link]
DNS Enumeration
Domain Name System (DNS) enumeration is the process of locating all
information about DNS. This can include identifying internal and external DNS
servers; performing lookups of DNS records for information such as
usernames, computer names, and IP addresses of potential target systems; and
performing zone transfers. Much of this activity was demonstrated in Chapter
3, “Footprinting, Reconnaissance, and Scanning.” The most straightforward
way is to use Nslookup or attempt a DNS zone transfer to copy the entire zone
file for the domain from the DNS server.
One of the unique attributes of Microsoft Windows is that when a client can’t
resolve a hostname using DNS, it will resort to the Link-Local Multicast Name
Resolution (LLMNR) protocol. LLMNR is used to resolve both IPv4 and IPv6
addresses. If LLMNR fails, NetBIOS will be used. NetBIOS functions in a similar
way as LLMNR; the big difference between the two is NetBIOS works over IPv4
only.
When LLMNR or NetBIOS are used to resolve a request, any host on the
network who knows the IP of the host being asked about can reply. Even if a
host replies to one of these requests with incorrect information, it will still be
regarded as legitimate. What this means is that the service can be spoofed. A
number of attack tools have been developed that will reply to all these queries
in the hope of receiving sensitive information. The primary defense against
these two attacks is to disable these services.
Enumeration Countermeasures
Table 4-5 includes a few security best practices that can help you protect your
systems from being easily enumerated by attackers.
Protocol Countermeasure
System Hacking
System hacking is a big step because you are no longer simply scanning and
enumerating a system. At this point, you are attempting to gain access. Things
start to change because this stage is about breaking and entering into the
targeted system. Previous steps, such as footprinting, scanning, and
enumeration, are all considered pre-attack stages. As stated, before you begin,
make sure that you have permission to perform these activities on other
people’s systems.
The primary goal of the system hacking stage is to authenticate to the remote
host with the highest level of access. This section covers some common
nontechnical and technical password attacks against authentication systems.
Attackers are always looking for easy ways to gain access to systems. Hacking
authentication systems is getting harder because most organizations have
upped their game, using strong authentication and improving auditing
controls. That is one reason why nontechnical attacks remain so popular. Basic
techniques include the following:
Technical password attacks require some use of technology. These attacks also
build on the information you have obtained in previous steps. Tools used
during enumeration, such as Hyena, Network Performance Monitor, and
Nbtstat, may have returned some valuable clues about specific accounts. By
now, you may even have account names, know who is the administrator,
know whether there is a lockout policy, and even know the names of open
shares. Technical password attack techniques discussed here include the
following:
Password guessing
Automated password guessing
Password sniffing
Keylogging
Note
Password Guessing
Guessing usernames and passwords requires that you review your findings.
Remember that good documentation is always needed during a penetration
test, so make sure that you have recorded all your previous activities. When
password guessing is successful, it is usually because people like to use easy-to-
remember words and phrases. A diligent penetration tester or attacker will
look for subtle clues throughout the enumeration process to key in on—
probably words or phrases the account holder might have used for a
password. There are also tools and online pwned password repositories that
can be used to look up breached passwords. Recon-ng is a full-featured
reconnaissance tool that features a pwned lookup. There are also sites with
searchable databases of pwned accounts, such as Have I Been Pwned?
at [Link] Have I Been Pwned? is shown in Figure 4-2.
If you are attempting to guess a user’s password, consider what you know
about that individual, such as what his hobbies are, and try related passwords.
If the account holder is not known to you, focus on accounts that
Because you may want to set up a method of trying each account once or twice
for weak passwords, you might consider looping the process. You can perform
automated password guessing by constructing a simple loop using the
Windows command shell. It is based on the standard net use syntax. The steps
are as follows:
%i /u:%j
Note
Make sure that you identify whether there is a password lockout policy
because you might have only two or three tries before the account is locked.
Otherwise, you might inadvertently cause a denial of service (DoS) if you lock
out all the users.
Password Sniffing
One such technique is to pass the hash. Passing the hash enables the hacker to
authenticate to a remote server by using the underlying NTLM and/or LM hash
of a user’s password, instead of using the associated plaintext password.
Mimikatz is a pass-the-hash application that enables an attacker to
authenticate to a remote server using the LM/NTLM hash of a user’s password,
eliminating the need to crack/brute-force the hashes to obtain the clear-text
password. Because Windows does not salt passwords, they remain static in
LSASS from session to session until the password is changed. If the password is
stored in LSASS and the attacker can obtain a password hash, it can be
functionally equivalent to obtaining the clear-text password. Rather than
attempting to crack the hash, attackers can simply replay them to gain
unauthorized access. You can download this pass-the-hash toolkit
at [Link]
Note
Although tools like pass the hash are very powerful in the right environment,
keep in mind that the default setting in Windows 8 and Windows 10 is to not
store plaintext passwords in LSASS.
Tip
If none of the options discussed previously are feasible, there is still keystroke
logging, which is discussed next.
Keylogging
Hardware keystroke loggers are usually installed while users are away from
their desks and are completely undetectable, except for their physical
presence. When was the last time you looked at the back of your computer?
Even then, they can be overlooked because they resemble a keyboard
extension cable or adapter. KeyGhost Ltd ([Link] has a
large collection. Some hardware keyloggers use Wi-Fi, which means that after
the keylogger is deployed, the attacker does not have to retrieve the device and
can communicate with it remotely via wireless or Bluetooth connection.
Software keystroke loggers sit between the operating system and the
keyboard. Most of these software programs are simple, but some are more
complex and can even email the logged keystrokes back to a preconfigured
address. What they all have in common is that they operate in stealth mode
and can grab all the text a user enters. Table 4-6 lists some common keystroke
loggers.
Product URL
Tip
If the attacker can gain access to a Windows system as a standard user, the
next step is privilege escalation. Two good examples include Spectre and
Meltdown. These tools take advantage of vulnerabilities found in CPUs from
AMD and Intel. If an attacker can exploit Spectre, she can read adjacent
memory locations of a process and access information for which she is not
authorized. If Meltdown is exploited, the attacker can escalate privileges by
forcing an unprivileged process to read adjacent memory locations. This step
is required because standard user accounts are limited; to be in full control,
administrator access is needed. This might not always be an easy task because
privilege-escalation tools must be executed on the victim’s system. How do you
get the victim to help you exploit a vulnerability? Common techniques include
the following:
Note
Privilege escalation is not just for Windows. In MacOS, when applications are
loading an external dynamic library, the loader searches in multiple
directories. If an attacker can inject a malicious library into one of these
directories, that library can potentially be executed.
Exploiting an Application
Sometimes a hacker can get lucky and exploit a built-in application. For
example, when you press the Shift key five or more times, Windows opens
StickyKeys options for you. The resulting dialog box that appears is an
interface to enable the use of StickyKeys, which is a Windows feature to aid
physically disabled users. There is nothing wrong with the use of this feature.
The only problem is how it is implemented. If an attacker can gain access, it
might be possible to replace [Link] with [Link]. After replacing the file,
you can invoke the command prompt and execute [Link] and
commands with full access to the computer.
The reason this attack works is that it slips through all of Windows’ protection
checks. Windows first checks whether the .exe is digitally signed, which
[Link] is. Next, it checks that the .exe is located in the system directory
(%systemroot%\system32), thus validating integrity level and administrator
permissions. Windows then checks to make sure the executable is on its
internal list of Windows protected system files and known to be part of the OS,
which [Link] is and therefore passes. Consequently, Windows thinks that it
is launching the accessibility feature StickyKeys, but instead, it is launching
shellcode running as LocalSystem.
Exploits can many times be used to help for good just as much as for bad. For
example, you can use the StickyKeys exploit if you ever need to reset a
Windows password. First, boot up from a thumb drive or an external media
device with a bootable version of Linux such as Kali Linux or Parrot Security
OS. Next, access the system’s hard drive and go to the Windows\System32
folder. Find the file [Link] and rename it sethc_1.exe, and then make a copy
of [Link] and rename a copy [Link]. Now reboot the computer without
Kali Linux.
After the system boots and you are at the login screen, press the Shift key five
times, and you will get a command prompt. Your level of access is as local
system administrator. At this point, you can either reset your password from
the command line or add a user with administrative rights.
What is a buffer overflow? It is like trying to pour a liter of your favorite soda
into a 12-ounce cup! Buffers have a finite amount of space allocated for any
one task. For example, if you allocate a 24-character buffer and then attempt
to stuff 32 characters into it, you’re going to have a real problem.
A buffer is a temporary data storage area whose length is defined in the
program that creates it or by the operating system. Ideally, programs should
be written to check that you cannot stuff 32 characters into a 24-character
buffer. However, this type of error checking does not always occur. Error
checking is really nothing more than making sure that buffers accept only the
correct type and amount of information required.
# include <stdio.h>
return 0;
This simple “Hello World!” program might not be vulnerable, but it doesn’t
take much more than this for a buffer overflow to occur. Table 4-7 lists
functions in the C language that are vulnerable to buffer overflows.
Function Description
strcpy Copies the content pointed by src to dest, stopping after the
terminating null character is copied
gets Reads a line from the standard input stream stdin and stores it
in a buffer
scanf Reads data from the standard input (stdin) and stores it in the
locations given by arguments
memcpy Copies num bytes from the src buffer to memory location
pointed to by destination
It’s not just these functions that cause buffer-overflow troubles for
programmers; the practice of making assumptions is another source. It is
really easy for programmers to assume that users will enter the right kind of
data or the right amount of data, leaving the door open to hackers to cause
buffer overflows. Really high-level programming languages, such as Perl, are
more immune to such problems, but the C language provides little protection
against such problems. Assembly language also provides little protection. Even
if most of your program is written in another language, many library routines
are written in C or C++, so you might not have as complete protection from
buffer overflows as you think.
Java is another application that has been exploited in several attacks. One
example is the Java watering-hole attacks. Stack-based buffer overflows in the
Java Stored Procedure infrastructure allow remotely authenticated users to
execute arbitrary code by leveraging certain CONNECT and EXECUTE
privileges.
Tip
Note
Attackers can steal the SAM through physical or logical access. If physical
access is possible, the SAM can be obtained from the NT ERD (Emergency
Repair Disk) from C:\winnt\repair\sam. Newer versions of Windows place a
backup copy in C:\winnt\repair\regback\sam, although SYSKEY prevents this
from easily being cracked. One final note here is that you can always reset the
passwords. If you have physical access, you can use tools such as LINNT and
NTFSDOS to gain access. NTFSDOS can mount any NTFS partition as a logical
drive. NTFSDOS is a read-only network file system driver for DOS/Windows. If
loaded onto a CD or thumb drive, it makes a powerful access tool. Logical
access presents some easier possibilities. The Windows SAM database is in a
binary format, so it’s not easy to directly inspect. Tools such as PWdump and
LCP can be used to extract and crack SAM. Before we examine those programs,
let’s briefly review how Windows encrypts passwords and authenticates users.
Windows Authentication Types
Bart: 1001:
B79135112A43EC2AAD3B431404EE:
DEAC47322ABERTE67D9C08A7958A:
Homer: 1002:
B83A4FB0461F70A3B435B51404EE:
GFAWERTB7FFE33E43A2402D8DA37:
Notice how each entry has been extracted in two separate character fields. As
you can see, the first half of each portion of the hash ends with 1404EE. That is
the padding, and it is how password-cracking programs know the length of the
LM password. It also aids in password-cracking time. Just consider the original
Dilbert! example. If extracted, one seven-character field will hold Dilbert,
whereas the other has only one character (!).
Password Yes No No
Tip
Tools such as FGdump and PWdump are other good password-extraction tools.
You can find download links to PWdump
at [Link] This command-
line tool can bypass SYSKEY encryption if you have administrative access.
PWdump works by a process of dynamic link library (DLL) injection. This
allows the program to hijack a privileged process. PWdump8, the current
version, was expanded to allow remote access to the victim system. The
program is shown here:
Completed.
FD02A1237LSS80CC22D98644FE0:
F2477A14LK4DFF4F2AC3E3207FE0:
EEAC47322ABERTE67D9C08A7958A:
BFAWERTB7FFE33E43A2402D8DA37
With the hashed passwords safely stored in the text file, the next step is to
perform a password crack. Historically, three basic types of password cracking
exist: dictionary, hybrid, and brute-force attacks.
A dictionary password attack pulls words from the dictionary or word lists to
attempt to discover a user’s password. A dictionary attack uses a predefined
dictionary to look for a match between the encrypted password and the
encrypted dictionary word. Many times, dictionary attacks will recover a
user’s password in a short period of time if simple dictionary words are used.
A hybrid attack uses a dictionary or a word list and then prepends and
appends characters and numbers to dictionary words in an attempt to crack
the user’s password. These programs are comparatively smart because they
can manipulate a word and use its variations. For example, take the
word password. A hybrid password audit would attempt variations such as
1password, password1, p@ssword, pa44w0rd, and so on. Hybrid attacks might
add some time to the password-cracking process, but they increase the odds of
successfully cracking an ordinary word that has had some variation added to
it.
Tools such as Hashcat, LCP, Cain and Abel, and John the Ripper can all perform
dictionary, hybrid, and brute-force password cracking. The most popular are
explained in the following list:
Cain and Abel is a multipurpose tool that can perform a variety of
tasks, including password cracking, Windows enumeration, and
Voice over IP (VoIP) sniffing. The password-cracking portion of the
program can perform dictionary/brute-force attacks and can use
precomputed rainbow tables.
John the Ripper is another great password-auditing tool. It can
run in Linux and Windows systems. It can crack most common
passwords, including Kerberos AFS and Windows hashes. A
graphical unit interface (GUI) for John the Ripper is called Johnny.
Also, a large number of add-on modules are available for John the
Ripper that can enable it to crack OpenVMS passwords, Windows
credentials cache, and MySQL passwords. Just remember that the
cracked passwords are not case sensitive and might not represent the
real mixed-case password. A determined attacker can overcome this
small hindrance. Figure 4-3 shows an example of using John the
Ripper to crack the password of the admin user. The password hash
is stored in a file called pwned_hash. John the Ripper uses a wordlist
(a list of passwords) called my_wordlist. This is an example of a post-
exploitation activity. The attacker already has access to the
compromised system and is able to steal the admin password (stored
in the file named pwned_hash. Password cracking is often done
offline using systems that have good computing resources (including
one or more GPUs).
my_wordlist
==============================================================
=========
======================================================
allocatable), 4MCU
rotates
Rules: 1
* Zero-Byte
* Early-Skip
* Not-Salted
* Not-Iterated
* Single-Hash
* Single-Salt
* Raw-Hash
* Filename..: my_wordlist
* Passwords.: 3545
* Bytes.....: 25602
* Keyspace..: 3545
Session..........: hashcat
Status...........: Cracked
[Link]........: MD5
[Link]......: 303bd261b07719193707e447d0f8b60a
#cat cracked_password.txt
303bd261b07719193707e447d0f8b60a:capt1nmurica
Years ago, dictionary, hybrid, and brute-force attacks were the primary
methods used to recover passwords or attempt to crack them. Many
passwords were considered secure just because of the time it would take to
crack them. This time factor was what made these passwords seem secure. If
given enough time, the password could be cracked, but it might take several
months. A relatively new approach to password cracking has changed this
belief. It works by means of a rainbow table. The Rainbow Crack technique is
the implementation of Philippe Oechslin’s faster time-memory trade-off
technique. It works by precomputing all possible passwords in advance. After
this time-consuming process is complete, the passwords and their
corresponding encrypted values are stored in a file called a rainbow table. An
encrypted password can be quickly compared to the values stored in the table
and cracked within a few seconds. RainbowCrack and Ophcrack are examples
of two such programs.
For the exam, you should understand how both Windows and Linux
passwords are structured.
Linux requires that user accounts have a password, but by default it will not
prevent you from leaving one set as blank. During installation, Linux gives the
user the choice of setting the password encryption standard. Most versions of
Linux, such as Fedora and others, use message digest algorithm 5 (MD5) by
default. If you choose not to use MD5, you can choose Data Encryption
Standard (DES); be aware, however, that it limits passwords to eight
alphanumeric characters. Linux also includes the /etc/shadow file for
additional password security. Take a look at an entry from an /etc/shadow file
here:
root:$1$Gjt/eO.e$pKFFRe9QRb4NLvSrJodFy.:0:0:root:/root:/bin/
bash
Moving the passwords to the shadow file makes it less likely that the encrypted
password can be decrypted because only the root user has access to the
shadow file. The format of the password file is as follows:
Account_name:Password:Last:Min:Max:Warn:Expire:Disable:Reserve
d
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:
daemon:x:2:2:daemon:/sbin:
adm:x:3:4:adm:/var/adm:
lp:x:4:7:lp:/var/spool/lpd:
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:
news:x:9:13:news:/var/spool/news:
operator:x:11:0:operator:/root:
gopher:x:13:30:gopher:/usr/lib/gopher-data:
ftp:x:14:50:FTP User:/home/ftp:
named:x:25:25:Named:/var/named:/bin/false
john:x:500:500:John:/home/jn:/bin/bash
ohmar:x:501:501:Clement:/cd/:/bin/csh
betty:x:502:502:Betty:/home/bd:/bin/pop
mike:x:503:503:Mike:/home/mg:/bin/bash
Notice that the second field has an X (mike:x:503). The reason is that the
passwords have been shadowed. Because so many hacking tools are Linux
only, you should know some basic Linux commands so you can navigate
distributions such as Kali. Table 4-9 describes some of these basic commands.
Command Description
Cat Lists the contents of a file
cd Changes directory
cp Copies content
rm Removes a file
Even if an attacker was able to access your passwords, Linux systems provide
another layer of security in that they salt passwords. Salts are needed to add a
layer of randomness to the passwords. Because MD5 is a hashing algorithm, if
you were to use secret for your password and another user used secret for his
password, encrypted values would look the same. A salt can be one of 4,096
values, and it helps further scramble the password. Under Linux, the MD5
password is 32 characters long and begins with $1$. The characters between
the second and third $ represent the salt. In the previous example, that value
is Gjt/eO.e. Passwords created in this way are considered to be one-way. That
is, there is no easy way to reverse the process.
The shadow file isn’t the only way to help guard against attackers who try to
bypass the authentication process. There are other, more advanced ways to
protect resources. If a new authentication scheme is going to be used, you
need a way to alert applications to this fact without having to rewrite every
piece of code already developed. The answer to this challenge is the use of
pluggable authentication modules (PAMs). PAMs enable a program designer to
forgo the worry of the types of authentication that will be performed and
concentrate on the application itself. FreeBSD, Linux, Solaris, and others use
PAMs. The role of a PAM is to control the interaction between the user and
authentication. This might be Telnet, FTP, logging in to the console, or
changing a password. PAMs support stronger authentication schemes, such as
Kerberos, S/Key, and RADIUS. The directory that holds the configuration file
and modules specific to a PAM is in /etc/pam.d/.
Tip
#john -test
Review the results of the FreeBSD MD5 and NT LM DES benchmarks. The
cracks per second (c/s) difference between these two is a factor of more than
500, which means that a complete brute-force attack will take more than 500
times longer against password hashes on a FreeBSD system than against a
Windows system. Which one of those systems would you rather hold critical
data?
Tip
Regardless of the OS, the steps that can be taken to protect passwords come
back to the analogy of toothbrushes: “They should be changed often, not
shared with others, and used only by you!”
Auditing Disabled
Clearing the log file: The attacker will also attempt to clear the
log. Tools such as Winzapper, Evidence Eliminator, and ELSave can
be used. ELSave will remove all entries from the logs, except one
entry that shows the logs were cleared. You use it as demonstrated
in Example 4-21.
Example 4-21 Clearing Log Files with ELSave
$ [Link] -h
usage: elsave [-s \\server] [-l log] [-F file] [-C] [-q]
path to
log.
Rootkits
After an attacker is on a Linux system and has made himself root, he will be
concerned with maintaining access and covering his tracks. One of the best
ways to maintain access is with a rootkit. A rootkit contains a set of tools and
replacement executables for many of the operating system’s critical
components. Once installed, a rootkit can be used to hide evidence of the
attacker’s presence and to give the attacker backdoor access to the system.
Rootkits require root access, but in return, they give the attacker complete
control of the system. The attacker can come and go at will and hide his
activities from the administrator. Rootkits can contain log cleaners that
attempt to remove all traces of an attacker’s presence from the log files.
Make sure that you can describe a kernel rootkit and how it differs from an
application rootkit.
According to an article published by the German paper Der Spiegel, the NSA
has modified the firmware of some computers and network gear to include
hardware rootkits. Firmware rootkits offer many advantages in that they use
persistent malware built in to the computer or hardware, such as a laptop or
router. This technique enables the placement of malware that can survive a
total operating system wipe and reinstallation.
How these rootkits are initially installed remains unclear. It could be with help
of the device manufacturer or by interdiction. This simply means that the
device/system is diverted during shipping to locations where the surveillance
components are installed.
With this said, many have also accused the Chinese, the Russians, and many
other countries of using these same techniques. The takeaway for the security
professional should be that firmware rootkits are among the most difficult to
detect and to remove.
How should you, as an ethical hacker, respond if you believe that a system has
been compromised and has had a rootkit installed? Your first action will most
likely be to remove the infected host from the network. An attacker who
knows that he has been discovered might decide to trash the system in an
attempt to cover his tracks. After isolating the host from the network, you can
then begin the process of auditing the system and performing some forensic
research. A number of tools enable you to detect rootkits. Most work by one or
more of the following techniques: integritybased detection, signature-based
detection, cross-view detection, and heuristic detection. Tools that you can use
to audit suspected rootkit attacks include the following:
File Hiding
The streams are a security concern because an attacker can use these streams
to hide files on a system. ADSs provide hackers with a means of hiding
malware or hacking tools on a system to later be executed without being
detected by the system administrator. Because the streams are almost
completely hidden, they represent a near-perfect hiding spot on a file system,
enabling the attacker to hide his tools until he needs to use them at a later
date. An ADS is essentially files that can be executed. To delete a stream, you
must delete its pointer first or copy the pointer file to a FAT file system. That
will delete the stream because FAT cannot support ADS. To create an ADS,
issue the following command:
Erase [Link]
All the hacker must do to retrieve the contents of the deleted file is to type the
following:
Start c:\[Link]:[Link]
This will execute the ADS and open the secret file. Tools that can detect
streamed files include the following:
One final step for the attacker is to gain a command prompt on the victim’s
system. This enables the attacker to actually be the owner of the box. Tools
that allow the attacker to have a command prompt on the system include
Psexec, Remoxec, and Netcat. After the attacker has a command prompt on the
victim’s computer, he will usually restart the methodology, looking for other
internal targets to attack and compromise. At this point, the methodology is
complete. As shown in Figure 4-4, the attacker has come full circle.
Summary
In this chapter, you learned about Windows and Linux OS enumeration and
system hacking. Enumeration of Windows systems can be aided by SMB,
the IPC$ share, SMTP, SNMP, and DNS. Each offers opportunities for the
attacker to learn more about the network and systems he is preparing to
attack. The goal of enumeration is to gather enough information to map the
attack surface, which is a collection of potential entry points. It might be a
buffer overflow, an unsecure application, such as SNMPv1 or 2, or even a weak
password that is easily guessed.
System hacking represents a turning point, which is the point at which the
attacker is no longer probing but is actually attacking the systems and
attempting to break in. System hacking might start with a low-level account.
One key component of system hacking is escalation of privilege, which is the
act of exploiting a bug, design flaw, or configuration oversight to gain elevated
access. The attacker’s overall goal is to own the system. After spending time
gaining access, the attacker will want long-term control of the computer or
network. After an attacker penetrates and controls one computer, he rarely
stops there. He will typically work to cover his tracks and remove any log
entries. Besides redirecting sensitive information, stealing proprietary data,
and establishing backdoors, attackers will most likely use the compromised
system to spread their illegal activities to other computers. If any one system is
compromised, the entire domain is at risk. The best defense is a good offense.
Don’t give the attacker any type of foothold.
As mentioned in the section “How to Use This Book” in the Introduction, you
have several choices for exam preparation: the exercises here, Chapter 12,
“Final Preparation,” and the exam simulation questions in the Pearson Test
Prep Software Online.
Review the most important topics in this chapter, noted with the Key Topic
icon in the outer margin of the page. Table 4-10 lists a reference of these key
topics and the page numbers on which each is found.
brute-force attack
dictionary attack
Exercise
In this exercise, you use NTFS file streaming to effectively hide files in an NTFS
environment.
Step [Link] a directory listing again and record the free space results:
___________
Step [Link] anything changed? You should have noticed that free space has
been reduced. The reason is that you streamed [Link] behind [Link].
Step [Link] the following from the command line:
Click here to view code image
Start c:\ test\ [Link]:[Link]
Step [Link] you notice what happened? Your hacked file, [Link], should
have popped open on the screen. The file is completely hidden, as it is
streamed behind [Link].
Step [Link] LNS from the command line. The program should detect the
streamed file [Link]. File streaming is a powerful way to hide information
and make it hard to detect.
Review Questions
S-1-5-21-343818398-789336058-1343024091-501
Name is Elon
Domain is Tesla
1. Ring 0
2. Ring 1
3. Ring 2
4. Ring 3
7. SNMP is a protocol used to query hosts and other network devices about
their network status. One of its key features is its use of network agents to
collect and store management information, such as the number of error
packets received by a managed device. Which of the following makes it a great
target for hackers?
1. NTLMv1
2. NTLMv2
3. LM
4. Kerberos
9. Which of the following tools can be used to clear the Windows logs?
1. Auditpol
2. ELSave
3. PWdump
4. Cain and Abel
10. What is one of the disadvantages of using John the Ripper?
1. Rainbow tables
2. Dictionary cracks
3. Hybrid cracks
4. Brute-force cracks
13. Why would an attacker scan for port 445?
1. To attempt to cause DoS of the NetBIOS SMB service on the victim
system
2. To scan for file and print sharing on the victim system
3. To scan for SMB services and verify that the system is Windows
OS
4. To scan for NetBIOS services and verify that the system is truly a
Windows NT server
14. Which of the following types of biometric systems is considered the most
accurate?
1. Fingerprint scanning
2. Iris scanning
3. Voice scanning
4. Palm scanning
15. You are trying to establish a null session to a target system. Which is the
correct syntax?
1. user/password
2. abc123/passw0rd
3. Password/administrator
4. Public/private
17. You have gained access to a system. You would now like to hide a file that
will be hidden and streamed behind another. Which of the following file
systems is required?
1. CDFS
2. NTFS
3. FAT
4. FAT32
18. Which of the following types of rootkits would be found at ring 0?
1. Software
2. Library
3. Application
4. Kernel
19. You are about to target a Linux server and would like to attempt access to
the passwords. In which of the following folders would you find them?
1. /etc
2. /sbin
3. /ect
4. /var
20. Which of the following protocols uses UDP port 514?
1. Syslog
2. NetBIOS
3. Finger
4. LDAP
Suggested Reading and Resources
[Link]
security: How to harden Windows
[Link] Mimikatz
tool module for Pass-the-hash attacks