VB.NET 从PEB->BeingDebugged标志位判断被调试

VB.NET 从PEB->BeingDebugged标志位判断被调试,第1张

概述说实在的我本是想从PEB中保存 调试对象句柄 的标志判断是 否被调试的,可惜搞了个多小时也没搞定 实在算不准偏移到底 是好多、当然可以在WinDbg在DT !PEB不过真的很麻烦,我在 网上找了一些PEB结构的声明,最后我再Nirsoft.NET上找到了 一个很全面地PEB结构声明,说实在话看的我不知所云、好吧 保存调试对象句柄的标志位为 ->ULONG SystemReserved[1]; 当

说实在的我本是想从PEB中保存 调试对象句柄 的标志位判断是

否被调试的,可惜搞了个多小时也没搞定 实在算不准偏移到底

是好多、当然可以在WinDbg在DT !PEB不过真的很麻烦,我

网上找了一些PEB结构的声明,最后我再Nirsoft.NET上找到了

一个很全面地PEB构声明,说实在话看的我不知所云、好吧

保存调试对象句柄的标为 ->ulONG SystemReserved[1];

当然我个体也只记得在什Reserved[1]中,毕竟我也是很久以

前看过点相关的资、当然从Reserved[1]中判断是否被调试也

有一定缺点,现在过保护驱动可以过掉 也就是说你不一定还能

查的出来、你们可参考下反调试技术揭秘上的资料,当然

兴趣可以研究!PEB / KernelStruct、它在某些时候的很有用

BeingDeBUGged 当进程被调试器附加时, *** 作系统会自动设置这

个标志位 一般来说 我们只需要在一个额外线程中循环定期检查

就可以了、当然如果要比较好的方法 可能是从HeapFlags判断了

不过都可以从上面的反调试技术揭秘中找到、

上面先通过NtqueryinformationProcess获取PBI(进程基类信息)

这个信息里面包含了,PEB入口点、宿主进程、退出代码、等

当然从PBI中获取PEB入口地址是比较亲民的做法,难道你要在

VB.NET中利用汇编从FS(标志段)寄存器中去获取到PEB吗?

在PEB入口点偏移0x2的位置是BeingDeBUGged、

示例代码:

imports System.Runtime.InteropServicesimports System.Text.RegularExpressionsModule MainModule    Declare Function NtqueryinformationProcess lib "ntdll.dll" (ProcessHandle As IntPtr,informationClass As Integer,ByRef Processinformation As PROCESS_BASIC_informatION,ProcessinformationLength As Integer,ReturnLength As Integer) As Integer    Declare Function GetCurrentProcess lib "kernel32.dll" () As IntPtr    <StructLayout(LayoutKind.Sequential)>    Structure PROCESS_BASIC_informatION        Public ExitStatus As Integer        Public PebBaseAddress As IntPtr        Public AffinityMask As Integer        Public BasePriority As Integer        Public UniqueProcessID As Integer        Public inheritedFromUniqueProcessID As Integer    End Structure    <StructLayout(LayoutKind.Sequential)>    Structure PEB        Public inheritedAddressspace As Byte        Public ReadImagefileExecoptions As Byte        Public BeingDeBUGged As Byte        Public SpareBool As Byte        Public Mutant As IntPtr        Public ImageBaseAddress As IntPtr        Public Ldr As IntPtr    End Structure    Const NulL As Integer = 0    Const STATUS_SUCCESS As Integer = NulL    Const SystemBasicinformation As Integer = 0    Sub Main()        Console.Writeline(IsDeBUGgerPresent())        DeBUGger.Break()    End Sub    Function IsDeBUGgerPresent() As Boolean        Dim pbi = New PROCESS_BASIC_informatION()        If (STATUS_SUCCESS <> NtqueryinformationProcess(GetCurrentProcess(),SystemBasicinformation,pbi,Marshal.SizeOf(pbi),NulL)) Then            Throw New Exception("Unable to get pbi.")        End If        Dim peb = CType(Marshal.PtrToStructure(pbi.PebBaseAddress,GetType(PEB)),PEB)        Return peb.BeingDeBUGged <> 0    End FunctionEnd Module
总结

以上是内存溢出为你收集整理的VB.NET 从PEB->BeingDebugged标志位判断被调试全部内容,希望文章能够帮你解决VB.NET 从PEB->BeingDebugged标志位判断被调试所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1268089.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-08
下一篇 2022-06-08

发表评论

登录后才能评论

评论列表(0条)

保存