在这篇文章中,我将向读者分享一些WinDbg剧本,它们在逆向采用了反调试技能的歹意软件的时刻,异常有效——至多对我来讲异常有效。固然,我不是Windows内核方面的专家,以是一方面在剧本中不免会发明差错,另一方面,我正在做的工作确切异常猖狂,以是极有可能会对计算机形成侵害。
这些剧本适用于WinDbg(不是当地的)内核调试。您必要一台机械来运转WinDbg,并将其衔接到被调试的另一台机械上。就我而言,我应用Windows主机来运转WinDbg,而后用它来调试VMware机械(我应用VirtualKD作为调试器衔接,由于这样的话,衔接速率要快得多),固然,您也能够应用其余设置装备摆设。
对于情况的搭设,列位能够参考以下文章:
VirtualKD – Installation
Starting with Windows Kernel Exploitation – part 1 – setting up the lab
Setting Up Kernel-Mode Debugging of a Virtual Machine Manually
好了,上面开端对各个剧本一一先容。
Anti-rdtsc-trick 剧本
参数:$$>a
剧本:
anti_antidebug_rdtsc.wdbg
无关这个技能的信息在互联网上有许多。应用它,您能够读取pafish代码:
https://github.com/a0rtega/pafish/blob/master/pafish/cpu.c
有一些对象会装置一个驱动程序来对于它。 WinDbg剧本以类似的办法工作,但它不必要驱动程序,它能够同时在x86和x64中运转(不知道能否有响应的对象能够在64位上应用)。
它的工作道理:它启用cr4的标记2(TSD光阴戳禁用)。RDTSC是一种特权指令。以后,它会启用Windbg中的响应选项,以便在用户形式异常产生时停下来(gflag + sue + soe,gflags 0x20000001)。
而后它开端捕捉0xc0000096异常(履行特权指令)。经由过程这类办法,当应用程序履行RDTSC时,会产生异常,而windbg则会捕捉该异常。这时候,剧本会反省RDTSC的内容,0x310f。 假如是RDTSC指令,则跳过该指令,ip = ip + 2。 末了,它实现以下设置工作:edx = 0,eax = last_counter + 1。对于履行RDTSC的应用程序来讲,将看到RDTSC每履行一次,响应的值就增1。
剧本:
$$set rdtsc as priv instruction, then catch
$$exceptions for priv instructions and skip
$$rdtsc(eip=eip+2) and set edx:eax = last rdtsc
$$returned value +1
$$use $t9 for counter
r $t9 = 0
$$rdtsc = privileged instruction
r cr4 = cr4 | 4
$$Stop on exception
!gflag +soe
$$Stop on unhandled user-mode exception
!gflag +sue
$$disable access violation (we have enabled exception
$$in user mode, and access violation will cause lot of
$$exceptions)
sxd av
$$we enable to catch privileged instructions execution
$$(we have converted rdtsc in priv ins with cr4)
$$in this moment we check if it is rdtsc, and in this case,
$$we jump over the instruction and we set eax=0 edx=0
sxe -c ".if((poi(eip)&0x0000ffff)==0x310f){.printf \"rdtsc\r\n\";r eip = eip+2;r eax=@$t9;r edx=0;r $t9=@$t9+1; gh;}" c0000096
对运转中过程重命名的剧本
参数: $$>a
剧本:
change_process_name.wdbg
假如咱们想给一个过程更名的话,则必要改动EPROCESS-> SeAuditProcessCreationInfo.ImageFileName:
该剧本必要以过程的主映像的称号作为其参数。它应用该imagename搜刮过程,找到后,改动其称号末了一个字母,具体来讲就是将响应的编码+1。比方:
$$>a
就本例来讲,该剧本将重命名vmtoolsd.exe - > vmtoolse.exe。 当歹意软件搜刮这个过程时,就找不到它了。然则,重命名的过程能够继承运转而不会呈现任何成绩。
剧本:
aS stage @$t19
.block
{
.sympath "SRV*c:\symcache*http://msdl.microsoft.com/download/symbols";
.reload
}
.block
{
r stage = 2
.printf "xxxx"
.foreach (processes_tok { !process /m ${$arg1} 0 0 })
{
.if($scmp("${processes_tok}","PROCESS")==0)
{
.if(${stage}==2)
{
$$stage==2 is used to skip the first apparition of
$$PROCESS string in the results of !process 0 0
r stage = 0