Study Notes Weekly No.3(Use odbcconf to load dll & Get-Exports & ETW USB Keylogger)

Onedaysec
4 min read
0 views
docx image 1770017971916 0 5f5ff5815b

About:

  • Use odbcconf to load dll
  • Use powershell to get dll exports
  • Use Event Tracing for Windows to log keystrokes from USB keyboards

Contents:

  • Introduction to bypassing regsvr32 command-line interception via odbcconf dll loading
  • ExportsToC++ - A more convenient tool than ExportsToC++ for batch exporting dll functions
  • Implementing USB keyboard keystroke logging via ETW, with testing insights

0x01 Use odbcconf to load dll

---

Reference:

https://twitter.com/subTee/status/789459826367606784

Introduction

Introduction — technical illustration 1

As shown in the figure, a technique shared by Casey Smith on Twitter: if the code for executing regsvr32 to load a DLL is written in an .rsp file and then invoked via odbcconf.exe, it can bypass the interception of regsvr32 in the command line. This article will explain why this method can bypass the interception of regsvr32 in the command line.

odbcconf:

Used to configure ODBC drivers and data sources

For detailed instructions, see the following link:

https://msdn.microsoft.com/en-us/library/ee388579(v=vs.85).aspx

Usage as shown in the figure

Introduction — technical illustration 2

It is worth noting that odbcconf includes a function to register DLLs. I have previously introduced in the article 'Code Execution of Regsvr32.exe' how to develop a DLL that can be called by regsvr32. A test DLL was written for testing (details omitted here, not repeated).

Run in cmd:

odbcconf.exe /a {regsvr c:\test\odbcconf.dll}

As shown in the figure, the DLL is successfully called, and a dialog box pops up

Introduction — technical illustration 3

From a defender's perspective, to prevent the abuse of using regsvr32 to call DLLs, monitoring command line inputs (e.g., creating rules via EMET) is often chosen. If the command line includes the string 'regsvr', it will be intercepted.

Of course, the above operation contains the string 'regsvr' and will be intercepted.

Using Process Explorer to view the command line of the odbcconf process, it contains the string 'regsvr'

As shown in the figure

Introduction — technical illustration 4

However, another feature of odbcconf can be used to bypass this, which is the /F parameter

Usage:

odbcconf.exe /f my.rsp

my.rsp is the response file, which contains the operation to be executed:

REGSVR c:\test\odbcconf.dll

Note:

The absolute path of the DLL must be provided here

As shown in the figure, the DLL is successfully called and a dialog box pops up

Introduction — technical illustration 5

Using Process Explorer to view the command line again shows no regsvr characters

As shown in the figure

Introduction — technical illustration 6

NickTyrer shared his code based on this method, achieving the execution of PowerShell commands within the DLL. The address is as follows:

https://gist.github.com/NickTyrer/6ef02ce3fd623483137b45f65017352b

Before compiling the project, the following settings are required:

  • Set the compilation platform to x86 or x64
  • Install UnmanagedExports and System.Management.Automation

In the Visual Studio control panel, select TOOLS-Library Package Manager-Package Manager Console, and enter:

Install-Package UnmanagedExports

Install-Package System.Management.Automation

0x02 Use powershell to get dll exports

---

Reference:

https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Get-Exports.ps1

Introduction

In "Study-Notes-Weekly-No.1(Monitor-WMI-ExportsToC++-Use-DiskCleanup-bypass-UAC)", a tool for batch exporting DLL functions was introduced—ExportsToC++. Its operation requires .NET Framework 2.0 and the installation of Microsoft Visual Studio.

b33f@FuzzySecurity has improved upon this and open-sourced Get-Exports for PowerShell. Its features include no longer requiring the Microsoft Visual Studio development environment, being more convenient and faster, and supporting both 32-bit and 64-bit DLLs.

The test code is as follows:

Get-Exports -DllPath c:\Windows\system32\dimsjob.dll -ExportsToCpp C:\test\export.txt

After execution, as shown in the figure, it displays the exported function information

Introduction — technical illustration 7

Simultaneously generates usable C++ code and saves it under C:\test\export.txt, as shown in the figure

Introduction — technical illustration 8

0x03 Use Event Tracing for Windows to log keystrokes from USB keyboards

---

Reference:

https://www.cyberpointllc.com/srt/posts/srt-logging-keystrokes-with-event-tracing-for-windows-etw.html

Introduction

CyberPoint SRT introduced their novel application of ETW at Ruxcon, achieving keystroke logging from USB keyboards and releasing a test POC. This article will test it and analyze the testing insights.

ETW:

  • Abbreviation for Event Tracing for Windows
  • Provides a mechanism for tracing and recording event objects created by user-mode applications and kernel-mode drivers
  • Typically used to assist administrators and developers in troubleshooting and measuring system and application performance
  • Public information shows there is currently no known method to implement keylogging using ETW

Some learning materials about ETW:

https://randomascii.wordpress.com/2015/09/24/etw-central/

POC download address:

https://github.com/CyberPoint/Ruxcon2016ETW/tree/master/KeyloggerPOC

Note:

This POC has been detected by antivirus software, testing requires whitelisting

Requirements:

  • Windows 7 (USB 2.0)
  • Windows 8+ (USB 2.0 and USB 3.0)
  • Run with administrator privileges

Note:

Does not support PS/2 interface keyboards

Test environment:

  • Win8.1 x86
  • vs2013
  • Install .NET Framework 4.5.2
  • Install-Package Microsoft.Diagnostics.Tracing.TraceEvent
  • USB 2.0 keyboard

Run exe with administrator privileges, record test as shown in figure

Introduction — technical illustration 9

The biggest shortcoming of the POC:

  • Recording has latency
  • Unstable, often reports error [!] ignoring non-usb keyboard device: 0xFFFFFFFF8CFF6070

There is still a long way from POC to tool, but this approach is worth learning, the ETW utilization method is worth summarizing, looking forward to CyberPoint SRT's follow-up articles

Related Questions & Answers

Why does the ETW USB keylogger POC require Windows 8+ for USB 3.0 support and administrator privileges?

USB 3.0 support was added in Windows 8 because the kernel-mode ETW provider for USB keyboards evolved with the operating system. Administrator privileges are necessary to access the ETW session and kernel-level events. The POC's dependencies and setup are detailed in [Study Notes Weekly No.3](/news/study-notes-weekly-no-3-use-odbcconf-to-load-dll-get-exports-etw-usb-keylogger). Understanding these requirements is crucial for both implementing and defending against such ETW-based monitoring techniques.

What is the purpose of using odbcconf.exe with a response file to load a DLL that executes PowerShell commands?

NickTyrer extended odbcconf's DLL loading capability to execute PowerShell commands within the loaded DLL, using UnmanagedExports and System.Management.Automation. This allows stealthy code execution without triggering command-line detection of `regsvr` strings. For compilation instructions and details, refer to [Study Notes Weekly No.3](/news/study-notes-weekly-no-3-use-odbcconf-to-load-dll-get-exports-etw-usb-keylogger). This technique fits into the broader family of application whitelisting bypasses, such as [using tracker.exe to load DLLs](/news/study-notes-weekly-no-4-use-tracker-to-load-dll-use-csi-to-bypass-umci-execute-c-from-xslt-file).

How does the ETW-based USB keylogger POC work and what are its limitations?

The POC uses Event Tracing for Windows (ETW) to capture keystrokes from USB keyboards by leveraging kernel-mode event providers. It requires administrator privileges and works on Windows 7+ with USB 2.0 or 3.0 (not PS/2). Major limitations include recording latency, instability, and error messages like 'ignoring non-usb keyboard device'. The full technique is described in [Study Notes Weekly No.3](/news/study-notes-weekly-no-3-use-odbcconf-to-load-dll-get-exports-etw-usb-keylogger). ETW keylogging is a novel approach compared to other application whitelisting bypass methods such as [using BGInfo](/news/study-notes-of-using-bginfo-to-bypass-application-whitelisting).

What advantages does the Get-Exports PowerShell script offer over ExportsToC++ for extracting DLL exports?

Get-Exports, developed by b33f@FuzzySecurity, eliminates the need for Microsoft Visual Studio and .NET Framework 2.0, making it more convenient and faster. It supports both 32-bit and 64-bit DLLs and generates usable C++ code directly. This script was introduced in [Study Notes Weekly No.3](/news/study-notes-weekly-no-3-use-odbcconf-to-load-dll-get-exports-etw-usb-keylogger) as an improvement over the earlier ExportsToC++ tool.

How can odbcconf.exe be used to bypass command-line monitoring of regsvr32 when loading DLLs?

By using the `/f` parameter of odbcconf.exe, you can pass a response file (`.rsp`) containing the `REGSVR` command with the DLL path. This avoids having the `regsvr` string in the command-line arguments visible to monitoring tools. For more details, see [Study Notes Weekly No.3(Use odbcconf to load dll & Get-Exports & ETW USB Keylogger)](/news/study-notes-weekly-no-3-use-odbcconf-to-load-dll-get-exports-etw-usb-keylogger). This technique is similar to other bypass methods like [using sdclt.exe to bypass UAC](/news/study-notes-of-using-sdclt-exe-to-bypass-uac) that also leverage alternate execution paths.

Continue Reading