/ActiveXPatchLibrary

A PoC DLL injection library for runtime hooking of ActiveX controls with UDP command interface built with Microsoft Detours ๐Ÿ”Œ

Primary LanguageC++Apache License 2.0Apache-2.0

๐Ÿ”Œ ActiveXPatchLibrary

C++ Platform License Type

A Windows DLL injection library for runtime hooking of ActiveX controls ๐ŸŽฏ


โœจ Features

  • ๐Ÿช Function Hooking - Intercepts specific ActiveX control methods using Microsoft Detours
  • ๐Ÿ“ Runtime Caption Modification - Dynamically modifies the caption text of ImhLabel controls
  • ๐ŸŒ UDP Command Interface - Receives commands via UDP on port 1305 to update caption text
  • ๐Ÿ–ฅ๏ธ Console Debug Output - Provides real-time logging of intercepted function calls
  • ๐Ÿ”„ Clean Hook/Unhook - Properly restores original functions on DLL detachment

๐Ÿ“‹ Overview

ActiveXPatchLibrary is a Proof of Concept (PoC) dynamic library that intercepts and modifies function calls of ActiveX controls. Specifically, it targets the ImhLabel ActiveX control (mhLbl.dll) and provides runtime patching capabilities through a UDP-based communication interface.

๐Ÿ—๏ธ Architecture

The library consists of four main components:

Component File Description
๐ŸŽฏ Main Hook Engine src/main.cpp Manages the DLL lifecycle and function hooking
๐ŸŒ UDP Server inc/UdpServer.h Listens for external commands on UDP port 1305
๐Ÿ› ๏ธ Utility Functions inc/Utils.h Provides string conversion and console setup utilities
๐Ÿ“ฆ ActiveX Interface inc/ImhLabel.h Defines the ImhLabel COM interface with RVA offsets

โš™๏ธ How It Works

  1. ๐Ÿ’‰ The DLL is injected into a target process using the Detours library
  2. ๐Ÿš€ On DLL_PROCESS_ATTACH, it:
    • Sets up a debug console ๐Ÿ–ฅ๏ธ
    • Hooks the SetCaption method of ImhLabel control at RVA offset 0x4c4d ๐Ÿช
    • Starts a UDP server on port 1305 ๐ŸŒ
  3. ๐Ÿ”„ When SetCaption is called on any ImhLabel control:
    • The original caption is intercepted and logged ๐Ÿ“Š
    • If a new caption has been received via UDP, it replaces the original โœ๏ธ
    • Otherwise, the original caption is passed through unchanged โžก๏ธ
  4. ๐Ÿงน On DLL_PROCESS_DETACH, all hooks are removed cleanly

๐Ÿ”ง Building

Prerequisites ๐Ÿ“ฆ

  • ๐Ÿ› ๏ธ Visual Studio 2022 (Platform Toolset v143)
  • ๐ŸชŸ Windows SDK 10.0
  • ๐Ÿ”— Microsoft Detours (included as git submodule)

Build Steps ๐Ÿš€

Step 1: Clone the repository with submodules ๐Ÿ“ฅ

git clone --recursive https://github.com/yourusername/ActiveXPatchLibrary.git
cd ActiveXPatchLibrary

Step 2: If you already cloned without submodules ๐Ÿ”„

git submodule update --init --recursive

Step 3: Open in Visual Studio ๐Ÿ“‚

Open ActiveXPatchLibrary/ActiveXPatchLibrary.sln in Visual Studio

Step 4: Build the solution ๐Ÿ—๏ธ

  • Configuration: Release
  • Platform: Win32
  • Output: DLL library

๐Ÿš€ Usage

Injecting the DLL ๐Ÿ’‰

Use the Detours withdll.exe utility or your preferred DLL injection method:

withdll.exe /d:ActiveXPatchLibrary.dll target_application.exe

Sending Commands ๐Ÿ“ค

Send UTF-8 encoded text via UDP to localhost:1305 to change the caption:

Using netcat ๐Ÿฑ

echo "New Caption Text" | nc -u localhost 1305

Using PowerShell ๐Ÿ’ 

$udpClient = New-Object System.Net.Sockets.UdpClient
$bytes = [System.Text.Encoding]::UTF8.GetBytes("New Caption Text")
$udpClient.Send($bytes, $bytes.Length, "localhost", 1305)
$udpClient.Close()

Using Python ๐Ÿ

import socket

sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.sendto("New Caption Text".encode('utf-8'), ('localhost', 1305))
sock.close()

โš™๏ธ Configuration

Key configuration parameters can be found in src/main.cpp:

Parameter Default Value Description
BIND_PORT 1305 UDP server listening port
PATCH_TABLE See below Maps function names to RVA offsets

Patch Table Structure ๐Ÿ“‹

std::map<std::string, std::pair<uintptr_t, uintptr_t>> PATCH_TABLE = {
    {
        "SetCaption",
        {
            (uintptr_t)((BYTE*)GetModuleHandleW(L"mhLbl.dll") + 0x4c4d),
            (uintptr_t)(&NewSetCaption)
        }
    },
};

๐Ÿ“ Project Structure

ActiveXPatchLibrary/
โ”œโ”€โ”€ ActiveXPatchLibrary/
โ”‚   โ”œโ”€โ”€ inc/
โ”‚   โ”‚   โ”œโ”€โ”€ ImhLabel.h        # ๐Ÿ“ฆ ActiveX control interface definition
โ”‚   โ”‚   โ”œโ”€โ”€ UdpServer.h       # ๐ŸŒ UDP server implementation
โ”‚   โ”‚   โ””โ”€โ”€ Utils.h           # ๐Ÿ› ๏ธ Utility functions
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ””โ”€โ”€ main.cpp          # ๐ŸŽฏ Main DLL entry point and hooking logic
โ”‚   โ”œโ”€โ”€ ActiveXPatchLibrary.sln
โ”‚   โ””โ”€โ”€ ActiveXPatchLibrary.vcxproj
โ”œโ”€โ”€ Detours/                  # ๐Ÿ”— Microsoft Detours (git submodule)
โ”œโ”€โ”€ LICENSE                   # ๐Ÿ“„ Apache License 2.0
โ””โ”€โ”€ README.md                # ๐Ÿ“– This file

๐Ÿ” Technical Details

Hooked Functions ๐Ÿช

Function RVA Offset Description
SetCaption 0x4c4d Sets the caption/text of the label control

Dependencies ๐Ÿ“ฆ

Dependency Purpose
Microsoft Detours Function interception and hooking framework
Winsock2 UDP socket communication
Windows COM BSTR string handling

COM Interface Details ๐Ÿ”Œ

The ImhLabel interface is defined with the following key methods:

  • SetCaption (0x4c4d) - Sets the label text
  • GetCaption (0x4ed9) - Retrieves the label text
  • SetForeColor (0x4e65) - Sets the foreground color
  • SetBackColor (0x4ca7) - Sets the background color

๐Ÿ”’ Security Considerations

โš ๏ธ Important: This library is designed for defensive security purposes such as:

  • โœ… Security research and analysis
  • โœ… Debugging and testing ActiveX controls
  • โœ… Automated testing frameworks
  • โœ… Reverse engineering for compatibility

โŒ Do not use this tool for:

  • Unauthorized modification of software
  • Malicious purposes
  • Violation of software licenses or terms of service

๐Ÿ“„ License

Licensed under the Apache License, Version 2.0. See LICENSE for full text.

Copyright 2024 ActiveXPatchLibrary Contributors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.

๐Ÿ™ Acknowledgments

โš ๏ธ Troubleshooting

๐Ÿšซ DLL fails to load
  • โœ… Ensure all dependencies (Detours) are properly built
  • โœ… Check that the target process architecture matches the DLL (x86)
  • โœ… Verify you have proper permissions to inject into the target process
  • โœ… Check Windows Defender or antivirus isn't blocking the DLL
โŒ Function hooks not working
  • โœ… Verify mhLbl.dll is loaded in the target process
  • โœ… Confirm the RVA offsets match your version of mhLbl.dll
  • โœ… Use a tool like PE Explorer or IDA Pro to verify offsets if needed
  • โœ… Check the console output for "Patched:" messages
๐ŸŒ UDP commands not received
  • โœ… Check firewall settings allow UDP port 1305
  • โœ… Verify the console window shows "UDP Echo Server is running"
  • โœ… Ensure you're sending to the correct IP (localhost/127.0.0.1)
  • โœ… Try using a network monitoring tool like Wireshark to debug
๐Ÿ–ฅ๏ธ Console window not appearing
  • โœ… Ensure Utils::SetupConsole() is being called in F:/workspace/ActiveXPatchLibrary/ActiveXPatchLibrary/src/main.cpp:126
  • โœ… Check if the target process has permission to create console windows
  • โœ… Try running the target application as Administrator
๐Ÿ’ฅ Application crashes after injection
  • โœ… Verify RVA offsets are correct for your mhLbl.dll version
  • โœ… Check for conflicts with other hooks or security software
  • โœ… Ensure the DLL was built with the correct configuration (Release/Win32)
  • โœ… Look for error messages in the console before the crash

๐Ÿ› ๏ธ Development

Code Style ๐Ÿ“

  • ๐Ÿ”ค Naming: Use camelCase for functions, PascalCase for classes
  • ๐Ÿ“ Indentation: 4 spaces
  • ๐Ÿ’ฌ Comments: Document all hooked functions and RVA offsets

Adding New Hooks ๐Ÿช

  1. Find the RVA offset using a disassembler (IDA Pro, Ghidra, x64dbg)
  2. Add to ImhLabel.h with the method signature
  3. Create a new hook function in main.cpp
  4. Add to PATCH_TABLE with the offset and hook function
  5. Test thoroughly to ensure stability

Debugging Tips ๐Ÿ›

  • ๐Ÿ–ฅ๏ธ Watch the console output for hook confirmation messages
  • ๐Ÿ“Š Use Process Monitor to track DLL loading and function calls
  • ๐Ÿ” Attach a debugger (x64dbg/WinDbg) to the target process
  • ๐Ÿ“ Enable verbose logging in your hook functions