-
-
[分享]几个简单的windbg脚本
-
发表于: 2019-3-20 10:54 3765
-
翻到以前写过的几个windbg脚本,当时写得很痛苦,踩了些坑,现在改用windbg支持的js脚本好多了,再也不想写windbg脚本了。
x86为结尾的文件用于32位,x64为结尾的文件用于64位。
CreateFile开头的文件在用于文件名包含字符串test.txt时断下。
CreateProcess开头的文件用于在进程名或者进程命令行包含字符串calc时断下。
NtCreateFile开头的文件用于内核调试时文件名包含字符串test时断下。
CreateFileW_x86.txt
$$ bp kernel32!CreateFileW "$><d:\\script\\CreateFileW_x86.txt" .catch { .if($vvalid(poi(esp+4), 2)) { aS /mu ${/v:wFileName} poi(esp+4); .if($spat(@"${wFileName}", "*test.txt*")) { .printf "\n"; .printf @"0x%p : ${wFileName}", poi(esp+4); .printf "\n\n"; .leave; } } gc; }
CreateFileA_x86.txt
$$ bp kernel32!CreateFileA "$><d:\\script\\CreateFileA_x86.txt" .catch { .if($vvalid(poi(esp+4), 2)) { aS /ma ${/v:aFileName} poi(esp+4); .if($spat(@"${aFileName}", "*test.txt*")) { .printf "\n"; .printf @"0x%p : ${aFileName}", poi(esp+4); .printf "\n\n"; .leave; } } gc; }
CreateFileW_x64.txt
$$ bp kernel32!CreateFileW "$><d:\\script\\CreateFileW_x64.txt" .catch { .if($vvalid(rcx, 2)) { aS /mu ${/v:wFileName} rcx; .if($spat(@"${wFileName}", "*test.txt*")) { .printf "\n"; .printf @"0x%p : ${wFileName}", rcx; .printf "\n\n"; .leave; } } gc; }
CreateFileA_x64.txt
$$ bp kernel32!CreateFileA "$><d:\\script\\CreateFileA_x64.txt" .catch { .if($vvalid(rcx, 2)) { aS /ma ${/v:aFileName} rcx; .if($spat(@"${aFileName}", "*test.txt*")) { .printf "\n"; .printf @"0x%p : ${aFileName}", rcx; .printf "\n\n"; .leave; } } gc; }
CreateProcessW_x64.txt
$$ bp kernelbase!CreateProcessW "$><d:\\script\\CreateProcessW_x64.txt" .catch { .if($vvalid(rcx, 2)) { aS /mu ${/v:wApplicationName} rcx; .if($spat(@"${wApplicationName}", "*calc*")) { .printf "\n"; .printf @"ApplicationName 0x%p : ${wApplicationName}", rcx; .printf "\n\n"; .leave; } } .if($vvalid(rdx, 2)) { aS /mu ${/v:wCommandLine} rdx; .if($spat(@"${wCommandLine}", "*calc*")) { .printf "\n"; .printf @"CommandLine 0x%p : ${wCommandLine}", rdx; .printf "\n\n"; .leave; } } gc; }
CreateProcessW_x86.txt
NtCreateFile_x64.txt
$$ bp kernelbase!CreateProcessW "$><d:\\script\\CreateProcessW_x86.txt" .catch { .if($vvalid(poi(esp+0x4), 2)) { aS /mu ${/v:wApplicationName} poi(esp+0x4); .if($spat(@"${wApplicationName}", "*calc*")) { .printf "\n"; .printf @"ApplicationName 0x%p : ${wApplicationName}", poi(esp+0x4); .printf "\n\n"; .leave; } } .if($vvalid(poi(esp+0x8), 2)) { aS /mu ${/v:wCommandLine} poi(esp+0x8); .if($spat(@"${wCommandLine}", "*calc*")) { .printf "\n"; .printf @"CommandLine 0x%p : ${wCommandLine}", poi(esp+0x8); .printf "\n\n"; .leave; } } gc; }
$$ bp ntdll!NtCreateFile "$><d:\\script\\NtCreateFile_x64.txt" .catch { .if($vvalid(r8+0x10, 2) == 0) { gc; } .if($vvalid(poi(r8+0x10)+0x8, 2) == 0) { gc; } .if($vvalid(poi(poi(r8+0x10)+0x8), 2) == 0) { gc; } aS /mu ${/v:wFileName} poi(poi(r8+0x10)+0x8); .if($spat(@"${wFileName}", "*test*")) { .printf "\n"; .printf @"0x%p : ${wFileName}", poi(poi(r8+0x10)+0x8); .printf "\n\n"; .leave; } gc; }
NtCreateFile_x86.txt
$$ bp ntdll!NtCreateFile "$><d:\\script\\NtCreateFile_x86.txt" .catch { .if($vvalid(esp+0xc, 2) == 0) { gc; } .if($vvalid(poi(esp+0xc)+0x8, 2) == 0) { gc; } .if($vvalid(poi(poi(esp+0xc)+0x8)+0x4, 2) == 0) { gc; } .if($vvalid(poi(poi(poi(esp+0xc)+0x8)+0x4), 2) == 0) { gc; } aS /mu ${/v:wFileName} poi(poi(poi(esp+0xc)+0x8)+0x4); .if($spat(@"${wFileName}", "*test*")) { .printf "\n"; .printf @"0x%p : ${wFileName}", poi(poi(poi(esp+0xc)+0x8)+0x4); .printf "\n\n"; .leave; } gc; }
(1)执行脚本c:\1.txt
$$><c:\1.txt
(2)数据类型
数值
2进制 0x
8进制 0n
10进制 0t
16进制 0y
字符串
"hello windbg"
(3)变量
$t0-$t19
r $t0=0x123 赋值变量t0为0x123
r $t0 打印变量t0的值
r eax
r $t0=@eax 赋值变量t0为寄存器eax的值
(4)别名
固定名字别名
$u0-%u9
r $.u0="123" 赋值别名u0为"123"
.echo $u0 打印出u0
自定义别名
as /ma ${/v:test} 0x00010000 将0x00010000地址定义为一个别名test
.echo test 打印别名test的内容
al 列出所有的别名
ad ${/v:test} 删除别名test
/ma 参数指定的内存地址当作ASCII字符串
/mu 参数指定的内存地址当作UNICODE字符串
/msa 参数指定的内存地址当作ANSI_STRING字符串
/msu 参数指定的内存地址当作UNICODE_STRING字符串
/f 别名等于参数指定文件的内容
/e 别名等于参数指定的环境变量
al 显示已经定义的别名
ad 删除已经定义的别名
(5)表达式
求汇编表达式的值用?
求C++表达式的值用??
打印一个地址处指针所指向的字符串 dd poi(esp+4)
(6)语句
.if
.else
.elif
.for
.while
.break
.continue
.do
.printf 格式化输出
.block 语句块
$$ 注释
(7)内建函数
字符串比较
$scmp 区分大小写
$sicmp 不区分大小写
as /ma ${/v:test} 00010000
? $scmp("${test}","123456")
若打印出0,则00010000地址处的字符串为"123456",若打印出-1,则字符串不容
(8)
打印所有的CreateFileA调用参数和返回值:
bp kernel32!CreateFileA ".echo;.printf\"CreateFileA(%ma,%p,%p), ret=\",poi(esp+4),dwo(esp+8),dwo(esp+c);gu;.printf\"%N\",eax;.echo;g"
(9)
对CreateFileA如果第一个参数是c:\1212.txt就断下:
bp kernel32!CreateFileA "$<D:\\script_ascii.txt"
script_ascii.txt的内容如下:
as /ma ${/v:fname} poi(esp+4)
.if ($sicmp( "${fname}", "c:\1212.txt" ) = 0 ) {.echo ${fname}} .else {gc}
(10)
对CreateFileW如果第一个参数是c:\1212.txt就断下:
bp kernel32!CreateFileW "$<D:\\script_unicode.txt"
script_unicode.txt的内容如下:
as /mu ${/v:fname} poi(esp+4)
.if ($sicmp( "${fname}", "c:\1212.txt" ) = 0 ) {.echo ${fname}} .else {gc}
$$ bp user32!GetMessageW "$$>< d:\\windbg-scriptx86.txt"
$$ BOOL __stdcall GetMessageW(LPMSG lpMsg, HWND hWnd, UINT wMsgFilterMin, UINT wMsgFilterMax)
$$ MSG数据结构:
$$ struct tagMSG, 6 elements, 0x1c bytes
$$ +0x000 hwnd
$$ +0x004 message
$$ +0x008 wParam
$$ +0x00c lParam
$$ +0x010 time
$$ +0x014 pt
$$ +0x000 x
$$ +0x004 y
.if (@esi == 0x0)
{
g
}
.else
{
r $t0 = poi(@esi)
r $t1 = poi(@esi+0x04)
.if ($t0 == 0x19086E)
{
.if ($t1 == 0x0202)
{
.echo "hold WM_LBUTTONUP\r\n"
}
.else
{
g
}
}
.else
{
g
}
}
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!
最后于 2020-3-28 12:18
被TechForBad编辑
,原因:
赞赏
他的文章
- [下载] visual assist 2522 3323
- [原创]使用libfuzzer对msvc编译的程序进行白盒fuzz 4276
- [原创]利用CE的DBK驱动获取R0权限 23249
- [原创]某神的驱动进程保护 13068
- [原创]使用winafl对迅雷的torrent解析逻辑进行fuzz 24394
看原图
赞赏
雪币:
留言: