添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
相关文章推荐
会搭讪的皮蛋  ·  最大as3 ...·  5 月前    · 
讲道义的毛豆  ·  Ashish Sangwan - open ...·  8 月前    · 
绅士的鸡蛋面  ·  ModuleNotFoundError: ...·  10 月前    · 
讲道义的牛肉面  ·  Int32 Struct (System) ...·  1 年前    · 
  • 编译链接过程 ENTRY 选项指定入口函数,默认为 main
  • OEP 指定为 libc.lib 中的 mainCRTStartup(console)
  • mainCRTStartup 完成初始化后调用 main
  • 文件特征注意
  • 同步:触发(命中)关键行为时,发起行为的线程被阻塞,内核将行为的相关信息传递至应用层;
  • 异步:触发(命中)关键行为时,获取行为的相关信息后,不影响行为的继续执行,内核将行为的相关信息传递至应用层;
  • 行为的相关信息:
  • 行为发起者(进程文件路径)
  • 行为标识(防御标记的行为种类)
  • 行为目标(根据标识有所不同,如:进程创建类的,这里的目标会是被调用的进程文件路径)
  • ………………
  • 同步拦截用于威胁性较高的行为,如:进程创建、创建服务、启动服务、修改注册表项启动项……
  • 异步拦截用于信息通知、文件写完成……,如:进程退出
  • 防进程倍结束
  • 文件操作(创建、读写、删除)
  • 文件自保护
  • 注册表防御
  • 注册表操作(创建、修改、删除)
  • 创建、启动、修改 服务
  • 安装全局钩子
  • 防黑墙(远程木马)
  • 访问恶意链接
  • system - 驱动的载体,通过 Process Explorer 查看该进程,可查看到系统已加载的驱动
  • winlogon.exe - 管理用户的登录和注销
  • csrss.exe - Client/Server Runtime Server Subsystem,Win32 子系统的用户模式部分;在 Win7 结束该进程,系统直接 BSOD(Blue Screen Of Death)
  • lsass.exe - 本地安全和登陆策略 smss.exe - 会话管理子系统,负责启动用户会话
  • services.exe - 系统服务控制管理
  • svchost.exe - 从动态链接库(DLL)中运行的服务的通用主机进程名称;以服务的形式将 DLL 加载执行;
  • explorer.exe - 资源管理器(桌面)
  • mov eax,42h 对应内核里 SSDT 表所在的 index
  • mov edx,7FFE0300h 0x7ffe0000 存储 _KUSER_SHARED_DATA 结构体,用于应用层和内核层共享数据
  • 驱动使用的监控技术

  • 文件 - minifilter 文件过滤框架
  • 注册表 - Hook 内核或向系统注册回调函数,调用 CmRegisterCallbackEx 注册,需提供自己实现的回调函数()
  • 进程 - Hook 内核或向系统注册回调函数,调用 PsSetCreateProcessNotifyRoutine 注册,需提供自己实现的回调函数
  • 模块 - Hook 内核或向系统注册回调函数,调用 PsSetLoadImageNotifyRoutine 注册,需提供自己实现的回调函数
  • 网络 - tdi、ndis、wfp 网络过滤框架()
  • 其它 - 基于 x86 架构上基本可通过 Hook 内核进行大部分的监控,而 x64 只能基于系统回调实现
  • 文件过滤框架 https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs
  • 网络过滤框架 https://docs.microsoft.com/en-us/windows-hardware/drivers/network/windows-filtering-platform-callout-drivers2
  • Hook 技术

  • “注入”,通过修改目标进程,将代码指令写入至目标进程的内存并执行;
  • “钩子”,可对程序内关键函数或任意有效内存地址进行“安装”;大部分的“安装”对指定程序内的内存进行修改,与注入组合使用;
  • 微软提供的可用于多平台的“hook”库,提供:进程创建时的注入(模块)、指定函数 hook……

    DetourCreateProcessWithDlls - 创建指定进程,并将指定模块注入至目标进程(加载时机早)

    在修改导入表完成后,目前进程还处于“挂起”状态,后续调用“ResumeThread”后,系统按照标准的进程创建流程,遍历导入表将对应的模块进行加载(将模块映射至当前进程内存,并获取 AddressOfEntryPoint 调用入口点 DllEntry);

    进程的首个线程(进程初始化)ntdll!_LdrpInitialize –> ntdll!LdrpInitializeProcess –> ntdll!LdrpRunInitializeRoutines –> ntdll!LdrpCallInitRoutine TLS 回调比模块的 dllmain 执行时机更早

    typedef struct {
        PVOID *pTable; // Service Table Pointer
        PULONG pulTableCounter; // Table Item Counter. This table is only updated in checked builds.
        ULONG ulServiceCounter; // Number of services contained in this table.
        PUCHAR rguchParamTable; // Table containing the number of bytes of parameters the handler function takes.
    } SERVICE_TABLE;
    

    SSSDT(System Shadow Services Descriptor Table)

    typedef struct {
        PVOID *pTable; // Service Table Pointer
        PULONG pulTableCounter; // Table Item Counter. This table is only updated in checked builds.
        ULONG ulServiceCounter; // Number of services contained in this table.
        PUCHAR rguchParamTable; // Table containing the number of bytes of parameters the handler function takes.
    } SERVICE_TABLE;
    

    x86 \ x64 系统的区别

    防御基于 x86 架构上的监控实现,基本是以 hook(inline hook) + 注册系统回调实现的;但在 x64 构架上,微软引入 Driver Signature Enforcement + Kernel Patch Protection(PatchGuard,简称 PG) 安全机制,杜绝第三方驱动在系统关键“驱动”中进行的内存修改。因为 PG 的存在,无法继续使用 x86 的 hook 方式实现更多行为的监控,只能使用系统提供的标准回调;x86 hook 的方式可将 SSDT + SSSDT 里涉及到的各函数调用都进行监控,基本上涵盖了系统上所有的行为,而系统提供的标准回调,只有进程创建 / 退出、模块加载、注册表相关、文件、对象回调,所以,导致了一些在 x86 上可进行防御的行为,在 x64 上无效(或实现方法与 x86 不同);

    监控点的实现

    监控点实现(应用层)

  • 文件监控 ReadDirectoryChangesW
  • 应用层实现文件监控效果的函数(非回调),可对文件夹里的文件名变动、目录名变动、文件属性变动……进行监控
  • 1、有针对性的(传入的目录句柄),不是全局监控
  • 2、无法获取操作者,即无法知道是哪个进程发起对文件的修改行为
  • Detour https://github.com/microsoft/Detours
  • ReactOS https://github.com/reactos/reactos
  • 双机调试 VirtualKD https://sysprogs.com/legacy/virtualkd
  • Nt 源码
  • Through the looking glass: webcam interception and protection in kernel mode


    Figure 1: After driver installation.
  • Source Insight https://www.sourceinsight.com 或 看雪 \ 百度 破解版
  • CFF Explorer https://ntcore.com/?page_id=388 或 百度
  • ProcMon(SysinternalsSuite) https://docs.microsoft.com/zh-cn/sysinternals/downloads/sysinternals-suite
  • 文件重启删除

    文件重启删除 读取注册表 smss.exe 删除的。

  • svchost.exe HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Svchost\
  • %SystemRoot%\system32\svchost.exe -k RPCSS
  • File: %SystemRoot%\System32\RpcEpMap.dll
  • Registry key: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\RpcEptMapper
  • void KInstallFile::DeleteFile()
        if ( m_bFolder && ::PathFileExists(m_strInstallPath))
            KFunction::DeleteFolder(m_strInstallPath);
            TCHAR szFileFullPath[MAX_PATH];
            ::GetModuleFileName(NULL, szFileFullPath, MAX_PATH);
            if ( m_strInstallPath.Compare( szFileFullPath ) != 0 )
                KProcessManager::KillProcessByPath( m_strInstallPath );
                Sleep( 100 );
            if (::PathFileExists(m_strInstallPath) && !::DeleteFile( m_strInstallPath ))
                CString strTempFileName;
                strTempFileName.Format(_T("%s_%d_del"), m_strInstallPath, int(::GetTickCount()));
                if (::MoveFileEx(m_strInstallPath, strTempFileName, MOVEFILE_REPLACE_EXISTING))
                    ::MoveFileEx(strTempFileName, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
      
  • windbg
  • CFF-Explorer
  • 反汇编过程即二进制转汇编助记符,参考 intel 指令集手册。 X86 为变长指令(灵活),arm 为定长指令(高效)[ 4G 寻址问题 ]

  • https://docs.microsoft.com/en-us/windows-hardware/drivers/ifs
  • https://docs.microsoft.com/en-us/windows-hardware/drivers/network/windows-filtering-platform-callout-drivers2
  • https://github.com/microsoft/Detours
  • https://github.com/reactos/reactos
  • https://sysprogs.com/legacy/virtualkd
  • https://github.com/yuan-xy/pea-search/blob/master/filesearch/ntfs.cpp
  • https://www.virusbulletin.com/virusbulletin/2018/09/through-looking-glass-webcam-interception-and-protection-kernel-mode/
  • https://www.sourceinsight.com
  • https://ntcore.com/?page_id=388
  • https://docs.microsoft.com/zh-cn/sysinternals/downloads/sysinternals-suite
  • Hawkhai personal website and blog.
    Powered by Jekyll, netlify.com | GitHub | 本页打印版本 Sun & Ocean · WWW.SUNOCEAN.LIFE