Giter Club home page Giter Club logo

dbghider's Introduction

DBGHider

DBGHider is an IDA Pro 7.x plugin written in Python. It aims to hide IDA Winddows debugger from processes.

DBGHider uses idaapi.DBG_Hooks to hook the debugger:

  1. Patch PEB (Process Environment Block) and WoW PEB in function dbg_process_start.
  2. Hook functions, such as NtClose, in function dbg_library_load.

Hooking

DBGHider uses two ways to hook functions: conditional breakpoint and inline hook.

Conditional Breakpoint

IDA Windows debugger supports conditional breakpoint. It allows you to attach a piece of python code to a breakpoint. If the code return True, the proccess suspends at the breakpoint. Otherwise, the process continues.

DBGHider adds a conditional breakpoint at each function you want to hook. And it attachs your code to each breakpoint.

Here is an example for NtClose.

import idautils
import idaapi
handle = idaapi.get_dword(idautils.cpu.esp + 4)
if handle >= 0x1000:
    ret_addr = idaapi.get_dword(idautils.cpu.esp)
    idautils.cpu.eax = 0
    idautils.cpu.esp = idautils.cpu.esp + 8
    idautils.cpu.eip = ret_addr
return False

However, this hooking method has an disadvantage. Some processes check 0xCC at API entry points before calling it.

Inline Hook

To implement inline hook, DBGHider moves one or more instructions at the function entry to somewhere else, then substitues the originals instruction with a jmp 0xhhhhhhhh instruction. And DBGHider writes your hooking code to 0xhhhhhhhh. Your code need to decide what to do, do something then return or execute the normal function. If you decide to execute the normal function, the saved instructions need to be executed first and then jump back.

Here is an example for NtClose.

The original NtClose:

.text:4B2E95D0 ; __stdcall NtClose(x)
.text:4B2E95D0                 public _NtClose@4
.text:4B2E95D0 _NtClose@4      proc near
.text:4B2E95D0                 mov     eax, 3000Fh
.text:4B2E95D5                 mov     edx, offset _Wow64SystemServiceCall@0
.text:4B2E95DA                 call    edx ; Wow64SystemServiceCall()
.text:4B2E95DC                 retn    4
.text:4B2E95DC _NtClose@4      endp

The NtClose being hooked:

.text:4B2E95D0 ; __stdcall NtClose(x)
.text:4B2E95D0                 public _NtClose@4
.text:4B2E95D0 _NtClose@4      proc near
.text:4B2E95D0                 jmp     ntclose_hook
.text:4B2E95D5                 mov     edx, offset _Wow64SystemServiceCall@0
.text:4B2E95DA                 call    edx
.text:4B2E95DC                 retn    4
.text:4B2E95DC _NtClose@4      endp

You hooking code.

ntclose_hook:
    mov     eax, [esp + 4]
    cmp     eax, 0x1000
    jl      jmp_back
    xor     eax, eax
    ret     4
jmp_back:
    mov     eax, 0x3000F
    jmp     0x4B2E95D5

Pleate note that you just need to write the code before jmp_back. The rest is generated by DBGHider automatically.

You can change the hooking method by changing the global variable bpt_hook to True or False.

Install

DBGHider uses keystone to assemble inline hook code. So you need to install keystone python module first, then just copy DBGHider.py to <IDADIR>/plugins/.

TODO

  • hooking more functions. DBGHder only hooks NtClose and NtQueryInformationProcess for now.
  • adding support for x64 process.
  • adding configuration
  • adding UI

If you can help, please do.

dbghider's People

Contributors

iweizime avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.