local hook_LdrInitializeThunk = 0
local hprocess = nil
function StrongOD方法附加(PID)
if 1 == 1 then
hprocess = ffi.C.OpenProcess( 0x001FFFFF, 0, tonumber(PID))
local Code = "\xcc\x90\xc3"
local Buf = ffi.C.VirtualAllocEx(hprocess,nil,#Code,win.MEM_COMMIT,win.PAGE_EXECUTE_READWRITE);
if Buf == nil then
print("DbgBreakPoint 失败:" .. win.ErrorMessage(ffi.C.GetLastError()))
end
local ret,err = win.WriteMemory(hprocess,Buf,Code)
if ret ~= 1 then
print(err)
end
local DbgUiIssueRemoteBreakin = ptonumber(win.ntdll.DbgUiIssueRemoteBreakin) + 0x15
print("DbgUiIssueRemoteBreakin",bit.tohex(DbgUiIssueRemoteBreakin))
if DbgUiIssueRemoteBreakin != 0 then
local lpflOldProtect = ffi.new("DWORD[1]")
local ret = ffi.C.VirtualProtect(ffi.cast("void *",DbgUiIssueRemoteBreakin),5,win.PAGE_EXECUTE_READWRITE,lpflOldProtect)
-- local ptr = ffi.cast("char *",跳过创建远程线程地址)
-- ffi.copy(ptr,"\xeb\x16",2)
ffi.cast("DWORD *",DbgUiIssueRemoteBreakin)[0] = ptonumber(Buf)
end
local LdrInitializeThunk = win.ntdll.LdrInitializeThunk
if LdrInitializeThunk!= nil then
--保存字节
-- print("hook LdrInitializeThunk",LdrInitializeThunk)
local lpflOldProtect = ffi.new("DWORD[1]")
local ret = ffi.C.VirtualProtect(ffi.cast("void *",LdrInitializeThunk),5,win.PAGE_EXECUTE_READWRITE,lpflOldProtect)
local trampolineaddr = LdrInitializeThunk
local jmptoaddr = ptonumber(Buf) - ptonumber(trampolineaddr) - 5
local jmpcode = ffi.new("char[5]",0xe9)
ffi.cast("int *",jmpcode + 1)[0] = jmptoaddr
win.WriteMemory(hprocess,trampolineaddr,ffi.string(jmpcode,5))
hook_LdrInitializeThunk = ptonumber(trampolineaddr)
end
end
end
function _NtDebugActiveProcess(PID) --
--修改 代码禁止创建远程线程
local paddr = ptonumber(win.ntdll.DbgUiDebugActiveProcess) + 0x1e
if paddr then
print("跳过创建远程线程地址",bit.tohex(paddr))
local lpflOldProtect = ffi.new("DWORD[1]")
local ret = ffi.C.VirtualProtect(ffi.cast("void *",paddr),5,win.PAGE_EXECUTE_READWRITE,lpflOldProtect)
local ptr = ffi.cast("char *",paddr)
ffi.copy(ptr,"\xeb\x16",2)
StrongOD方法附加(PID)
end
return oNtDebugActiveProcess(PID)
end