7. System Hacking P.2_2ad0c1123a157cef39bbb0278f15e389
7. System Hacking P.2_2ad0c1123a157cef39bbb0278f15e389
SYSTEM HACKING
(PART - 2)
ITOP
Maintaining Access
• After gaining access and escalating privileges on the target system, attackers try to maintain their access
for further exploitation of the target system or make the compromised system a launchpad from which to
attack other systems in the network.
• Attackers remotely execute malicious applications such as keyloggers, spyware, and other malicious
programs to maintain their access to the target system and steal critical information such as usernames and
passwords.
• Attackers hide their malicious programs or files using rootkits, steganography, NTFS data streams, etc. to
maintain their access to the target system.
Maintaining Access: Executing Applications
• Once attackers gain higher privileges in the target system by trying various privilege escalation attempts,
they may attempt to execute a malicious application by exploiting a vulnerability to execute arbitrary code.
• By executing malicious applications, the attacker can steal personal information, gain unauthorized access
to system resources, crack passwords, capture screenshots, install a backdoor for maintaining easy
access, etc.
Maintaining Access: Executing Applications
- Backdoors: Program designed to deny or disrupt the operation, gather information that leads to exploitation or loss
- Keyloggers: These can be hardware or software. In either case, the objective is to record each keystroke made on
- Spyware: Spy software may capture screenshots and send them to a specified location defined by the hacker. For
this purpose, attackers have to maintain access to victims’ computers. After deriving all the requisite information from
the victim’s computer, the attacker installs several backdoors to maintain easy access to it in the future.
Remote Code Execution Techniques:
Exploitation for Client Execution
• Remote code execution techniques are various tactics that can be used by attackers to execute
malicious code on a remote system. These techniques are often performed after compromising
a system initially and further expanding access to remote systems present on the target
network.
• Some examples of remote code execution techniques are as follows:
Web-Browser-Based Exploitation
• Attackers target web browsers through spearphishing links and drive-by compromise. The remote systems
can be compromised through normal web browsing or through several users who are targeted victims of
spearphishing links to attacker-controlled sites used to exploit the web browser.
• This type of exploitation does not need user intervention for execution.
Office-Applications-Based Exploitation
• Attackers target common office applications such as Microsoft Office through different variants of
spearphishing. Emails containing links to malicious files are directly sent to the end-users for downloading.
To run the exploit, end-users are required to open a malicious document or file.
Remote Code Execution Techniques:
Scheduled Task
Scheduled Task
• Scheduled tasks allow users to perform routine tasks chosen for a computer automatically. There are two
utilities, at and schtasks, that can be used along with Windows Task Scheduler to execute specific code or
script at a scheduled date and time. Using task scheduling, attackers can execute malicious programs at
system startup, or schedule it for a specific date and time to maintain access to the target system and
further perform remote code execution to gain admin-level privileges to the remote system.
Remote Code Execution Techniques:
Service Execution
Service Execution
• System services are programs that run and operate at the backend of an OS. Attackers run binary files or
commands that can communicate with Windows system services such as Service Control Manager. This
code execution technique is performed by creating a new service or by modifying an existing service at the
time of privilege escalation or maintaining access.
Tools for Executing Applications
RemoteExec
Source: https://www.isdecisions.com
• RemoteExec remotely installs applications,
executes programs/scripts, and updates files and
folders on Windows systems throughout the
network.
• This allows an attacker to modify the registry,
change local admin passwords, disable local
accounts, and copy/ update/delete files and
folders.
• As shown in the screenshot, attackers use the
RemoteExec tool to remotely execute files by
selecting the target OS and the file to be executed.
Tools for Executing Applications
• Pupy (https://github.com)
• PsExec (https://docs.microsoft.com)
Keylogger
• Keyloggers are software programs or hardware devices that record the keys struck on the computer keyboard
(also called keystroke logging) of an individual computer user or a network of computers.
• It records almost all the keystrokes on a keyboard of a user and saves the recorded information in a text file.
• As keyloggers hide their processes and interface, the target is unaware of the keylogging. Offices and
industries use keyloggers to monitor employees’ computer activities, and they can also be used in home
environments for parents to monitor children’s Internet activities.
Keylogger
Keylogger
A keylogger can:
• Record every keystroke typed on the user’s keyboard
• Capture screenshots at regular intervals, showing user activity such as typed characters or clicked mouse
buttons
• Track the activities of users by logging Window titles, names of launched applications, and other information
• Monitor the online activity of users by recording addresses of the websites visited and with keywords entered
• Record all login names, bank and credit card numbers, and passwords, including hidden passwords or data
displayed in asterisks or blank spaces
• Record online chat conversations Make unauthorized copies of both outgoing and incoming email messages
Types of Keystroke Loggers
• Keyloggers save captured keystrokes to a file for reading later, or transmit them to a place where the attacker
can access it.
• As these programs record all the keystrokes that are provided through a keyboard, they can capture
passwords, credit card numbers, email addresses, names, postal addresses, and phone numbers. Keyloggers
can capture information before it is encrypted. This gives the attacker access to passphrases and other “well-
hidden” information.
Types of Keystroke Loggers
Hardware Keyloggers
• PS/2 keylogger
• USB keylogger
• Wi-Fi keylogger
• Bluetooth keylogger
• Hardware keylogger
How to Defend against Keyloggers
• Do not click on links in unsolicited or dubious emails that may direct you to malicious sites.
• Use keystroke interference software that insert randomized characters into every keystroke.
How to Defend against Keyloggers
• Keep your hardware systems secure in a locked environment and frequently check the keyboard cables for attached connectors,
USB port, and computer games such as the PS2 that may have been used to install keylogger software.
• Use software that frequently scan and monitor changes in your system or network.
• Install a host-based IDS, which can monitor your system and disable the installation of keyloggers.
• Use one-time password (OTP) or other authentication mechanisms such as two-step or multi-step verification to authenticate
users.
• Enable application whitelisting to block downloading or installing of unwanted software such as keyloggers.
design of these loggers helps them to detect software keyloggers. Many large organizations, financial institutions,
online gaming industries, and individuals use anti-keyloggers to protect their privacy while using systems.
• This software prevents a keylogger from logging every keystroke typed by the victim, and thus keeps all personal
information safe and secure. An anti-keylogger scans a computer and detects and removes keystroke logger
software. If the software (anti-keylogger) finds any keystroke-logging program on your computer, it immediately
Zemana AntiLogger
Source: https://www.zemana.com
fingerprint.
Anti-Keyloggers
• GuardedID (https://www.strikeforcecpg.com)
• KeyScrambler (https://www.qfxsoftware.com)
• Ghostpress (https://schiffer.tech)
• All files contain a set of attributes. There are different fields in the file attributes. The first field determines the
format of the file if it is a hidden, archive, or read-only file. The other field describes the time of the file creation,
access, and its original length. The functions GetFileAttributesExA() and GetFileInformationByHandle() are
used for the aforementioned purposes. ATTRIB.exe displays or changes the file attributes. An attacker can
hide or even change the attributes of a victim’s files so that the attacker can access them.
Rootkits
Objectives of a rootkit:
• To gather sensitive data, network traffic, etc. from the system for which attackers might be restricted or have no
access
• To store other malicious programs on the system and act as a server resource for bot updates
Types of Rootkits
There are six types of rootkits available:
1. Hypervisor-Level Rootkit:
• Attackers create hypervisor-level rootkits by exploiting hardware features such as Intel VT and AMD-V. These rootkits run in
Ring-1 and host the OS of the target machine as a virtual machine, thereby intercepting all hardware calls made by the
target OS. This kind of rootkit works by modifying the system’s boot sequence so that it is loaded instead of the original
2. Hardware/Firmware Rootkit:
• Hardware/firmware rootkits use devices or platform firmware to create a persistent malware image in hardware, such as a
hard drive, system BIOS, or network card. The rootkit hides in firmware as the users do not inspect it for code integrity. A
firmware rootkit implies the use of creating a permanent delusion of rootkit malware.
Types of Rootkits
3. Kernel-Level Rootkit:
• The kernel is the core of an OS. A kernel-level rootkit runs in Ring-0 with the highest OS privileges. These cover backdoors on
the computer and are created by writing additional code, or by substituting portions of kernel code with modified code via device
drivers in Windows or loadable kernel modules in Linux. If the kit’s code contains mistakes or bugs, kernel-level rootkits affect
the stability of the system. These have the same privileges as the OS; hence, they are difficult to detect and can intercept or
4. Boot-Loader-Level Rootkit:
• Boot-loader-level rootkits (bootkits) function either by modifying the legitimate boot loader or replacing it with another one. The
bootkit can activate even before the OS starts. Therefore, bootkits are serious threats to security because they facilitate the
• An application-level/user-mode rootkit runs in Ring-3 as a user along with other applications in the system. It
exploits the standard behavior of APIs. It operates inside the victim’s computer by replacing the standard
application files (application binaries) with rootkits or by modifying the behavior of present applications with
6. Library-Level Rootkits
• Library-level rootkits work high up in the OS, and they usually patch, hook, or supplant system calls with backdoor
versions to keep the attacker unknown. They replace the original system calls with fake ones to hide information
System hooking is the process of changing and replacing the original function pointer with a pointer provided by the
rootkit in stealth mode. Inline function hooking is a technique in which a rootkit changes some of the bytes of a
function inside the core system DLLs (kernel32.dll and ntdll.dll), placing an instruction so that any process calls hit
the rootkit first.
Popular Rootkits
The following are some of the most popular rootkits:
LoJax
Source: https://www.welivesecurity.com
• LoJax is a type of UEFI rootkit that is widely used by attackers to perform cyber-attacks. LoJax is created to inject
malware into the system and is automatically executed whenever the system starts up. It exploits UEFI, which
acts as an interface between the OS and the firmware. It is extremely challenging to detect LoJax as it evades
traditional security controls and maintains its persistence even after OS reinstallation or hard disk replacement.
Popular Rootkits
Scranos
Source: https://www.bitdefender.com
• Scranos is a trojanized rootkit that masquerades as cracked software or a legitimate application, such as anti-
malware, a video player, or an ebook reader, to infect systems and perform data exfiltration that damages the
• When this rootkit executed, a rootkit driver is automatically installed, which then starts installing other malicious
components into the system. Apart from installing malicious components, Scranos also interacts with various
Source: http://www.pill.horse
• Horse Pill is a proof of concept of a ramdisk-based containerizing rootkit. It resides inside “initrd,” and before the
actual init starts running, it puts it into a mount and PID namespace that allows it to run covert processes and
storage. This also allows it to run covert networking systems, such as DNS tunnels.
Popular Rootkits
Necurs
Source: https://www.f-secure.com
• Necurs is a kernel-mode driver component that can be used by an attacker (or added as a component to
another malicious program) to perform unauthorized actions to take control of an OS, without alerting the
system’s security mechanisms. Necurs contains backdoor functionality, which allows remote access and control
• It also allows the monitoring and filtering of network activity and has been observed to send spam and install
• Integrity-based detection can be regarded as a substitute for both signature-based and heuristic-based
detection. Initially, the user runs tools such as Tripware and AIDE on a clean system. These tools create a
baseline of clean system files and store them in a database. Integrity-based detection functions by comparing a
current filesystem, boot records, or memory snapshot with that trusted baseline. They detect the evidence or
presence of malicious activity based on dissimilarities between the current and baseline snapshots.
Detecting Rootkits
Signature-Based Detection
• Signature-based detection methods work as rootkit fingerprints. They compare the characteristics of all system
processes and executable files with a database of known rootkit fingerprints. It can compare a sequence of
bytes from a file with another sequence of bytes that belong to a malicious program. The method mostly scans
system files. It can easily detect invisible rootkits by scanning the kernel memory. The success of signature-
based detection is lower owing to the rootkit’s tendency to hide files by interrupting the execution path of the
detection software.
Detecting Rootkits
Heuristic/Behavior-Based Detection
• Heuristic-based detection works by identifying deviations in normal OS patterns or behaviors. This type of
detection is also known as behavioral detection. Heuristic detection can identify new, previously unidentified
rootkits by recognizing deviants in “normal” system patterns or behaviors. Execution path hooking is one such
• The runtime execution path profiling technique compares runtime execution path profiling of all system
processes and executable files. The rootkit adds a new code near to a routine’s execution path to destabilize it.
The method hooks several instructions executed before and after a certain routine, as these can be significantly
different.
Detecting Rootkits
Alternative Trusted Medium
• The alternative trusted medium technique is the most reliable method used for detecting rootkits at the OS level.
In this technique, the infected system is shut down and then booted from alternative trusted media, such as a
bootable CD-ROM or USB flash drive. After booting, the OS storage is checked to find traces of the rootkit,
which can further be removed, to restore the system to its normal state.
Detecting Rootkits
Analyzing Memory Dumps
• In memory dump analysis, the volatile memory (RAM) of the suspected system is dumped and analyzed to
detect the rootkit in the system. Using this technique, one can create a static snapshot of a single process,
system kernel, or the entire system. To detect a rootkit, the entire system memory is dumped to analyze and
capture active rootkits. This memory dump can further be used to perform offline forensic analysis. Creating
1. Run "dir /s /b /ah" and "dir /s /b /a-h" inside the potentially infected OS and save the results.
2. Boot into a clean CD, run "dir /s /b /ah" and "dir /s /b /a-h" on the same drive, and save the obtained results.
3. Run the latest version of the WinMerge tool on the two sets of results to detect file-hiding ghostware (i.e.,
format.
4. Run regedit.exe.
7. c:\windows\system32\config\software c:\windows\system32\config\system.
8. Export these registry hives in text file format. (The registry hives are stored in binary format and Steps 6 and 7
9. Launch the WinMerge tool from the CD and compare the two sets of results to detect file-hiding malware (i.e.,
• Regularly verify the integrity of system files using cryptographically strong digital fingerprint technologies
• Do not install unnecessary applications, and disable the features and services not in use
Anti-Rootkits
GMER
Source: http://www.gmer.net
• Stinger (https://www.mcafee.com)
• TDSSKiller (https://usa.kaspersky.com)
• Steganography refers to the art of hiding data “behind” other data without the knowledge of the victim. Thus,
steganography hides the existence of a message. It replaces bits of unused data into ordinary files, such as
graphics, sound, text, audio, and video with other surreptitious bits.
• The hidden data can be in the form of plaintext or ciphertext, and sometimes, an image. Utilizing a graphic
image as a cover is the most popular method to conceal the data in files. Unlike encryption, the detection of
• Thus, steganography techniques are widely used for malicious purposes. For example, attackers can hide a
keylogger inside a legitimate image; thus, when the victim clicks on the image, the keylogger captures the
victim’s keystrokes.
What is Steganography?
• Attackers also use steganography to hide information when encryption is not feasible. In terms of security, it
hides the file in an encrypted format, so that even if the attacker decrypts it, the message will remain hidden.
Attackers can insert information such as source code for a hacking tool, a list of compromised servers, plans
• Covering tracks is one of the main stages during system hacking. In this stage, the attacker tries to hide and
avoid being detected or “traced out” by covering all “tracks,” or logs, generated while accessing the target
network or computer. We now look at how the attacker removes traces of an attack on a target computer.
• Erasing evidence is a must for any attacker who would like to remain obscure. It is a method used to evade
a traceback. It starts with erasing the contaminated logs and possible error messages generated in the
attack process. The attacker makes changes to the system configuration such that it does not log the future
activities.
Clearing Tracks: Covering Tracks
• Attackers must make the system appear as it did before access was gained and a backdoor was
established. This allows them to change any file attributes back to their original state. The information listed,
such as file size and date, is just attribute information contained in the file.
• Protection against attackers trying to cover their tracks by changing file information can be difficult. However,
it is possible to detect whether an attacker has done so by calculating the file’s cryptographic hash. This type
• Attackers may not wish to delete an entire log to cover their tracks, as doing so may require admin
privileges. If attackers can delete only attack event logs, they will still be able to escape detection
Techniques Used for Covering Tracks
The main activities that an attacker performs toward removing his/her traces on a computer are as follows:
• Clearing Logs: An attacker clears/deletes the system log entries corresponding to his/her activities.
• Manipulating Logs: An attacker manipulates logs in such a way that he/she will not be caught in legal
action.
• Covering Tracks on the Network: An attacker uses techniques such as reverse HTTP shells, reverse ICMP
tunnels, DNS tunneling, and TCP parameters to cover tracks on the network.
Techniques Used for Covering Tracks
• Covering Tracks on the OS: An attacker uses NTFS streams to hide and cover malicious files in the target
system.
• Deleting Files: An attacker uses a command-line tool such as Cipher.exe to delete the data and prevent
• Disabling Windows Functionality: An attacker disables Windows functionality such as last access
timestamp, hibernation, virtual memory, system restore points, etc. to cover tracks
Disabling Auditing: Auditpol
Source: https://docs.microsoft.com
• One of the first steps for an attacker who has command-line capability is to determine the auditing status of
the target system, locate sensitive files (such as password files), and implant automatic information-
• Windows records certain events to the event log (or associated syslog). The log can be set to send alerts
(email, SMS, etc.) to the system administrator. Therefore, the attacker will want to know the auditing status
of the system he/she is trying to compromise before proceeding with his/her plans.
Disabling Auditing: Auditpol
This will make changes in the various logs that might register the attacker’s actions. He/she can choose to hide
Attackers can use AuditPol to view defined auditing settings on the target computer, running the following
Clear_Event_Viewer_Logs.bat is a utility that can be used to wipe out the logs of the target system. This utility
can be run through command prompt, PowerShell, and using a BAT file to delete security, system, and
application logs. Attackers might use this utility to wipe out the logs as one method of covering their tracks on
3. Right-click or press and hold on the .bat file and click/tap on Run as administrator.
Clearing Logs
follows.
Windows system:
Metasploit Framework.
Source: https://docs.microsoft.com
Using the Clear-EventLog command, the attacker can clear all the PowerShell event logs from local or remote
computers:
2. Use the following command to clear the entries from the PowerShell event log on the local or remote
3. Use the following command to clear specific multiple log types from local or remote systems:
(This command clears all the log entries in Microsoft Office Diagnostics (ODiag) and Microsoft Office Sessions
4. Use the following command to clear all the logs on the specified systems, and then display the event log list:
>wevtutil el
>wevtutil cl <log_name>
As shown in the screenshot, the attacker can view the list of event
logs using the wevtutil utility and clear the system, application, and
corresponding to their activities on both Windows and Linux computers. The steps to clear event logs on Windows and
For Windows
• Navigate to Start Control Panel System and Security Administrative Tools double-click Event Viewer
• Delete the all the log entries logged while compromising the system
For Linux
Navigate to the /var/log directory on the Linux system Open the plaintext file containing log messages with text
editor /var/log/messages Delete all the log entries logged while compromising the system
Covering Tracks on a Network
• An attacker starts this attack by first infecting a victim’s machine with malicious code, and thereby installing a
reverse HTTP shell on the victim’s system. This reverse HTTP shell is programmed in such a way that it asks
for commands to an external master, which controls the reverse HTTP shell on a regular basis. This type of
traffic is considered normal by an organization’s network perimeter security controls like DMZ, firewall, etc.
• HTTP GET commands, whereas the attacker behaves like a web server and responds to the requests. Once
the previous commands are executed, the results are sent in the next web request.
• All the other users in the network can normally access the Internet; therefore, the traffic between the attacker
• Internet Control Message Protocol (ICMP) tunneling is a technique in which an attacker uses ICMP echo and
reply packets as carriers of TCP payload, to stealthily access or control a system. This method can be used to
easily bypass firewall rules, because most organizations have security mechanisms that only check incoming
• An attacker first configures the local client to connect with the victim. The victim’s system is triggered to
encapsulate a TCP payload in an ICMP echo packet, which is forwarded to the proxy server. The proxy server
de-encapsulates and extracts the TCP payload, and then sends it to the attacker.
Covering Tracks on a Network
• Attackers can use DNS tunneling to encode malicious content or data of other programs within DNS queries
and replies. DNS tunneling usually includes data payload that can be added to the victim’s DNS server to create
• Attackers can employ this backchannel to exfiltrate stolen, confidential, or sensitive information from the server.
• Attackers perform DNS tunneling in various stages; first, they compromise an internal system to create a
connection with an external network. Then, they use that compromised system as a command and control
server to remotely access the system and transfer files covertly from within to outside the network.
Covering Tracks on a Network
TCP parameters can be used by the attacker to distribute the payload and to create covert channels. Some of the TCP
• IP Identification Field: This is an easy approach in which a payload is transferred bitwise over an established
session between two systems. In this approach, one character is encapsulated per packet.
• TCP Acknowledgement Number: This approach is quite difficult as it uses a bounce server that receives packets
from the victim and sends it to an attacker. Here, one hidden character is relayed by the bounce server per packet.
• TCP Initial Sequence Number: This method also does not require an established connection between the two
systems. Here, one hidden character is encapsulated per SYN request and reset packet.
Covering Tracks on an OS
UNIX
• Files in UNIX can be hidden just by appending a dot (.) in front of a file name. In UNIX, each directory is
subdivided into two directories: current directory (.) and parent directory (..). Attackers give these a similar name
like “. ” (with a space after . ). These hidden files are usually placed in /dev, /tmp, and /etc.
• An attacker can also edit the log files to cover their tracks. However, sometimes, using this technique of hiding
files, an attacker can leave his/her trace behind because the command he/she used to open a file will be
recorded in a .bash_history file. A smart attacker knows how to overcome such a problem; he/she does so by
• Conduct a periodic audit on IT systems to ensure logging functionality is in accordance with the security policy
• Ensure new events do not overwrite old entries in the log files when the storage limit is exceeded
• Configure appropriate and minimal permissions necessary to read and write log files stored on critical systems
• Maintain a separate logging server on the DMZ, so that all the critical servers, such as the DNS server, mail
server, web server, etc., forward and store their logs on that server
Defending against Covering Tracks
• Encrypt the log files stored on the system, so that altering them is not possible without an appropriate
decryption key
• Set log files to “append only” mode to prevent unauthorized deletion of log entries