|
三、操作系统启动过程中相关操作
关注了一下NT的启动过程,想了解系统在启动的时候是如何执行上面提到的移动或者删除行为的。
在初始化内核阶段,ntoskrnl.exe从NTLDR手中接管了控制权,在最后一步,Session Manager启动了Windows XP的高级子系统以及服务,Session Manager启动控制所有输入、输出设备以及访问显示器屏幕的Win32子系统以及Winlogon进程,初始化内核完毕。
Session Manager实际上就是smss.exe,我们经常可以在内存进程中看到他的身影。反汇编的时候,在sub_48584D01中看到XP有考虑识别的CPU有:
0 x86
1 MIPS
2 ALPHA
3 PPC
4 IA64
5 ALPHA64
other UNKNOWN
我在smss.exe里面找到了PendingFileRenameOperations,可见应该是此文件负责了在引导的时候执行其中的文件移动操作。只可惜,我没有找到何处调用了PendingFileRenameOperations,反汇编功底不佳啊。
从sysinternals.com中看到一段关于Session Manager调用PendingFileRenameOperations的话
[http://www.sysinternals.com/ntw2k/info/regboot.shtml]
After you pass the point in the log where boot and system driver initialization is complete you’ll begin to see records created by the smss.exe process, which is called the Session Manager. Session Manager is the first user-mode process launched during a boot. You’ll see it immediately check to see if there are any rename operations it should perform before the system is up and running by looking at the value HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations. Next you’ll see it determine what DOS device mappings it should create (e.g. COM1, LPT1), what environment variables are defined, what DLL’s it "knows about" (standard DLLs in the system32 directory), and which protected subsystems it should start (e.g. OS/2, POSIX).
Session Manager typically launches Chkdsk (autocheck.exe), which is specified in the Session Manager’s BootExecute value along with direction to run other boot-time native applications. After Autocheck finishes Session Manager starts Winlogon and the Win32 subsystem (CSRSS.EXE). Both of these generate interleaved Registry accesses as they start up concurrently. Winlogon can be seen querying the .Default key’s display settings, including colors and mouse settings under HKU\.Default\Control Panel. The .Default key’s contents are user preferences that are active when no one is logged in, and Winlogon uses them for the screen on which it displays the logon dialog box.
不过这个和微软所说的先Autochk,然后再PendingFileRenameOperations,不同。
从另一份文档中(http://freehost02.websamba.com/brittanyfoo/BootProcess.html),提到了初始化进程问题:
Smss 的主线程进行以下的初始化步骤:
1、创建 LPC 端口对象( \SmApiPort )和两个等待客户请求的线程。客户请求包括装载一个新的子系统或者创建一个会话等。
2、为 MS-DOS 设备名,如 COM1 和 LPT1 定义符号链接。
3、如果安装了终端服务(Terminal Services),在对象管理器的名字空间创建 \Sessions 目录。
4、运行 HKLM\SYSTEM\CurrentControlSet\ Control\Session Manager\BootExecute 定义的程序,典型的是运行 Autochk (Chkdsk在引导其间的版本)。
5、按照 HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations 的指令,进行延迟文件改名操作。挂起文件删除在 PendingFileRenameOperations2 。
6、打开已知的 DLL 。
7、创建另外的分页文件。
8、初始化注册表。配置管理器刷新注册表, 为HKLM\SAM, HKLM\SECURITY, 和 HKLM\SOFTWARE 关键字装载注册文件。HKLM\SYSTEM\ CurrentControlSet\Control\hivelist 在硬盘上搜索注册表文件,配置管理器在 \Winnt\System32\Config 寻找。
9、创建系统环境变量。
10、装载Win32子系统内核模式部分(Win32k.sys)。Smss 在 HKLM\SYSTEM\CurrentControlSet\Control\Session Manager 下寻找 Win32k.sys 和其它要装载组件的路径,确定它们的位置。Win32k.sys 中的初始化代码使用视频驱动程序,屏幕的分辨率转换到缺省概貌文件定义的值。因此,屏幕从引导视频驱动程序使用的VGA模式转到系统选择的缺省的分辨率。
11、启动子系统进程,包括 Csrss 。
12、启动登陆进程 (Winlogon) 。
13、为调试事件信息创建LPC口(DbgSsApiPort 和 DbgUiApiPort),并创建监听这些口的线程。
这个算是描述最清楚的了。
四、总结
至此,对替换正在使用中的文件有了初步的理解。
既MoveFileExW -> MoveFileWithProgressW -> BasepMoveFileDelayed -> HKLM\System\CurrentControlSet\Control\Session Manager\PendingFileRenameOperations
然后,ntldr引导,ntoskrnl.exe结果引导权,启动smss.exe(Session Manager),在Autochk之后,检查PendingFileRenameOperations,然后执行其中的文件替换操作。最后smss启动Winlogon进程,允许用户登录。
因此此种方法可以替换几乎所有的系统文件,因为smss是系统的第一个UserMode的进程,此时被使用的文件极少,不可能有人在它之前占用文件。
如果是替换系统文件的话,比如smss.exe,就使用微软的办法,先把smss.exe移动到临时文件夹去,然后把新的smss.exe放到正确的目录中。把临时文件家里的smss.exe移动到NULL,并且是MOVEFILE_DELAY_UNTIL_REBOOT。这样如果系统重新启动的话,自然使用的是新的smss.exe,然后它再把临时文件夹里的垃圾清除掉即可。其实此时不清除,等起来之后再清除也是可以的了,因为已经没有东西在占用那个临时文件夹里的垃圾了。
如果是替换普通应用程序的话,只需要重新启动应用程序即可,因为此时应用程序目录里的东西已经为新的文件了。重新启动只不过是为了删除那个临时文件夹里的垃圾而已。
| 没有路由密码权限时的鸽子上线方 | 08-23 |
| 完全解析网页后门和挂马 | 04-02 |
| 真实的网络攻击取证纪实 | 03-27 |
| 利用404错误页面挂马 | 03-21 |
| 解密风暴 | 03-21 |
| 社会工程学在黑客中的应用 | 01-02 |
| 轻轻松松解密各种网页木马 | 12-21 |
| SA权限无xp_cmdshell时取权限又一 | 12-14 |
| sqlserver2005中恢复xp_cmdshell | 11-10 |
| 实现无net.exe和net1.exe添加系统 | 10-26 |
| 用U盘轻松去除XP管理员密码 | 10-26 |
| 教你多种保护措施限用移动硬盘 | 10-09 |