Skip to content

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

License

Notifications You must be signed in to change notification settings

player-alex/ActiveXPatchLibrary

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Œ 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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages