`
jinghuainfo
  • 浏览: 1525041 次
  • 性别: Icon_minigender_2
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

通过挂钩NtCreateSection监控可执行模块

 
阅读更多

<!-- [if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:PunctuationKerning /> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas /> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:Compatibility> <w:SpaceForUL /> <w:BalanceSingleByteDoubleByteWidth /> <w:DoNotLeaveBackslashAlone /> <w:ULTrailSpace /> <w:DoNotExpandShiftReturn /> <w:AdjustLineHeightInTable /> <w:BreakWrappedTables /> <w:SnapToGridInCell /> <w:WrapTextWithPunct /> <w:UseAsianBreakRules /> <w:DontGrowAutofit /> <w:UseFELayout /> </w:Compatibility> <w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel> </w:WordDocument> </xml><![endif]--><!-- [if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" LatentStyleCount="156"> </w:LatentStyles> </xml><![endif]--><!-- [if gte mso 10]> <mce:style><! /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:10.0pt; font-family:"Times New Roman"; mso-fareast-font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} table.MsoTableGrid {mso-style-name:网格型; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; border:solid windowtext 1.0pt; mso-border-alt:solid windowtext .5pt; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-border-insideh:.5pt solid windowtext; mso-border-insidev:.5pt solid windowtext; mso-para-margin:0cm; mso-para-margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.0pt; font-family:"Times New Roman"; mso-ansi-language:#0400; mso-fareast-language:#0400; mso-bidi-language:#0400;} --><!-- [endif]-->

通过挂钩 NtCreateSection 监控可执行模块

Win32 中,我们使用 CreateFileMapping 来创建映射文件对象,函数原型如下:

HANDLE CreateFileMapping(

HANDLE hFile, // handle to file to map

LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes

DWORD flProtect, // protection for mapping object

DWORD dwMaximumSizeHigh, // high-order 32 bits of object size

DWORD dwMaximumSizeLow, // low-order 32 bits of object size

LPCTSTR lpName // name of file-mapping object

);

这个函数会调用 Native Api(Ntdll.dll) 中的 ZwCreateSection NtCreateSection )函数,而后者又通过系统调用 Ntoskrnl.exe 中的 NtCreateSection 函数,其函数原型如下:

NTSTATUS

NtCreateSection(

OUT PHANDLE SectionHandle ,

IN ACCESS_MASK DesiredAccess ,

IN POBJECT_ATTRIBUTES ObjectAttributes OPTIONAL,

IN PLARGE_INTEGER MaximumSize OPTIONAL,

IN ULONG SectionPageProtection ,

IN ULONG AllocationAttributes ,

IN HANDLE FileHandle OPTIONAL

);

不仅是用户创建的映射文件, Windows 加载所有的可执行模块,包括 EXE 文件、 DLL 文件等都使用了此函数(博文《使用 Native Api 创建进程》就曾调用),只是在参数 SectionPageProtection AllocationAttributes 与普通的映射文件有所区别:

根据这个特点,我们可以通过挂钩 NtCreateSection 函数来截获所有将要加载的可执行模块的文件名称(关于如何获取文件名称,可以参看博文《获取文件对象的名称》)反馈给用户。用户根据文件路径、文件的 MD5 或其他信息来判断是否允许该模块的加载。

(AllocationAttributes == 0X1000000) && (SectionPageProtection & PAGE_EXECUTE)

参考文章:

1. Hooking the native API and controlling process creation on a system-wide basis

http://www.codeproject.com/KB/system/soviet_protector.aspx

2. 天书夜读

分享到:
评论

相关推荐

    监控准备运行的可执行文件

    监控准备运行的可执行文件:修改(NtCreateSection)SSDT索引号,(索引号从用户程序中得到)HOOK NtCreateSection()这个函数,然后通过文件句柄获得文件名,判断它是不是可执行文件,检测其属性与判断用户是否允许...

    Hook NtCreateSection的SSDT实现

    这个我学习天书夜读后的大作业。尽管SSDT没有前途了,不过还是可以玩玩的

    ntdll 32位

    ntdll 32位,可用于深度学习caffe封装 error LNK2019: 无法解析的外部符号 NtClose,该符号在函数 mdb_env_map 中被引用 D:\google-jar\liblmdb \mdb.obj error LNK2019: 无法解析的外部符号 NtCreateSection,...

    ntdll 64位

    ntdll 64位,可用于深度学习caffe封装 error LNK2019: 无法解析的外部符号 NtClose,该符号在函数 mdb_env_map 中被引用 D:\google-jar\liblmdb \mdb.obj error LNK2019: 无法解析的外部符号 NtCreateSection,该...

    UrbanBishopLocal:FuzzySecurity的UrbanBishop项目的端口,用于内联shellcode执行

    NtCreateSection用于创建一个节对象 NtMapViewOfSection创建一个具有RW权限的剖视图,我们可以将shellcode写入 Shellcode被写入截面视图 第二次调用NtMapViewOfSection会创建一个具有RX权限的剖面图 指向shellcode...

    ProcessHollowing

    SectionRemapLoader使用NtUnmapViewOfSection , NtCreateSection和NtMapViewOfSection来执行过程空心化。 这种方法要容易得多,但是需要磁盘上有一个有效的PE映像文件。 确保架构匹配。 SectionRemapLoader.exe以...

    fasm_packer.zip_NtMapViewOfSection_delphi packer_fasm_fasm下载_pac

    Simple packer, the loader is written in assembly (FASM) and the ...- Use of NtCreateSection/NtMapViewOfSection - The trick VirtualSize = SizeOfImage so that Windows don t steel our memory position.

Global site tag (gtag.js) - Google Analytics