如何在Linux live CD中修复Windows注册表

如何在Linux live CD中修复Windows注册表

IT, 其他

在Online.net的Dedibox SC SATA 2016款独立服务器中仅提供TTY,也就是说在Rescue的时候也只能通过SSH/tty去调试,那么就会带来一些问题:无法使用没有配置过串口转发的WinPE。也就是说这款机器只能通过SSH进行紧急维修。

前几天在修改RDP端口后由于一些失误没有修改防火墙规则,最终导致重启后无法使用RDP功能。在这种既不能iKVM/IDRAC,又不能使用SSH的时候,我们如何维修这项错误呢?

我们需要以下的一些工具:

Linux Live CD(我这里使用的是online.net提供的ubuntu14.04 Rescue CD),ntfs-3g驱动,ntfsfix工具,chntpw工具。

首先明确一点,所有的防火墙规则,RDP端口等信息均存放于WINDOWS/System32/config/SYSTEM文件中,也有一些会存在SYSTEM.alt等文件中,但实际起效的就是SYSTEM文件。因此只要实现对这个文件的修改即可做到修复。

最简单的修复时直接复制一份正常工作的SYSTEM文件到相同位置,但是其问题就是,不能保证文件在不同电脑上的一致性,也就是说有可能因为一些不匹配导致更严重的后果,同时由于此文件牵涉相当多的系统设置,因此,直接用比较法去修改基本不现实。因此我们就需要linux下修改注册表的工具了。

chntpw工具本身是针对忘记Windows登录密码而编写的工具,通过修改注册表可以搞定这些问题。那么这个工具也就同样可以修改因为失误造成的注册表错误了。

那么第一步就是通过mount命令将Windows系统盘挂载到linux的挂载点下。(这里必须使用读写模式,因此需要ntfs-3g驱动)


#mkdir -p /media/windows
#mount -t ntfs-3g -o rw /dev/sda2 /media/windows

挂载完成后你可能会因为Windows没有安全卸除挂载,遇到无法挂载设备的情况。


Error mounting /dev/sda2 at /media/adam/Data: Command-line `mount -t "ntfs" -o "uhelper=udisks2,nodev,nosuid,uid=1000,gid=1000,dmask=0077,fmask=0177" "/dev/sda2" "/media/adam/Data"' exited with non-zero exit status 14: The disk contains an unclean file system (0, 0).
Metadata kept in Windows cache, refused to mount.
Failed to mount '/dev/sda2': Operation not permitted
The NTFS partition is in an unsafe state. Please resume and shutdown
Windows fully (no hibernation or fast restarting), or mount the volume
read-only with the 'ro' mount option.

那么这时候就可以通过ntfsfix处理。


#ntfsfix /dev/sda2
Mounting volume... OK
Processing of $MFT and $MFTMirr completed successfully.
Checking the alternate boot sector... OK
NTFS volume version is 3.1.
NTFS partition /dev/sda2 was processed successfully.

这时候再挂载则不会出现任何警告。
这里我们使用-e参数加载注册表

chntpw [OPTIONS] <samfile> [systemfile] [securityfile] [otherreghive] [...]
 -h          This message
 -u <user>   Username to change, Administrator is default
 -l          list all users in SAM file
 -i          Interactive. List users (as -l) then ask for username to change
 -e          Registry editor. Now with full write support!
 -d          Enter buffer debugger instead (hex editor), 
 -v          Be a little more verbose (for debuging)
 -L          For scripts, write names of changed files to /tmp/changed
 -N          No allocation mode. Only same length overwrites possible (very safe mode)
 -E          No expand mode, do not expand hive file (safe mode)
See readme file on how to get to the registry files, and what they are.
Source/binary freely distributable under GPL v2 license. See README for details.
NOTE: This program is somewhat hackish! You are on your own!

#chntpw -e /media/windows/Windows/System32/config/SYSTEM

编辑注册表信息可以使用以下命令


Simple registry editor:
hive [<n>]             - list loaded hives or switch to hive numer n
cd <key>               - change current key
ls | dir [<key>]       - show subkeys & values,
cat | type <value>     - show key value
dpi <value>            - show decoded DigitalProductId value
hex <value>            - hexdump of value data
ck [<keyname>]         - Show keys class data, if it has any
nk <keyname>           - add key
dk <keyname>           - delete key (must be empty)
ed <value>             - Edit value
nv <type#> <valuename> - Add value
dv <valuename>         - Delete value
delallv                - Delete all values in current key
rdel <keyname>         - Recursively delete key & subkeys
ek <filename> <prefix> <keyname>  - export key to <filename> (Windows .reg file format)
debug                  - enter buffer hexeditor
st [<hexaddr>]         - debug function: show struct info
q                      - quit


这里我们需要了解一些简单的关于注册表的知识:

首先是几个键值 ,其次就是ControlSet001、ControlSet002与CurrentControlSet的关系。

在注册表HKLM\system注册表项中包括用于windows启动的三个控件组(额外还可能存在一个备份控件组),在初始状态下,它们分别是ControlSet001、 ControlSet002以及CurrentControlSet。这些控件组中包含了操作系统配置的信息,比如服务、驱动、系统控制、枚举信息等等。

默认情况下,ControlSet001是系统真实的配置信息,但是为了避免序号混乱,windows启动时会从ControlSet001复制一份副 本,作为操作系统当前的配置信息,也就是CurrentControlSet。我们对于计算机配置所作的修改都是直接写入到 CurrentControlSet,在修改CurrentControlSet中,windows会用CurrentControlSet的内容覆盖掉ControlSet001,以 保证这两个控件组一致。

当操作系统每成功启动一次(指成功登录),它都将ControlSet001中的数据复制到 ControlSet002中。这样,ControlSet002就成了“最近一次成功启动的配置信息”。所以我们一般系统注册表中都只是有这三个控件组,并且序号都是current、001和002。

同时具体选择哪一个配置文件,会在Select键值中出现。在离线编辑的时候,仅存在ControlSet001、ControlSet002,我直接编辑实际生效的ControlSet001。


cd ControlSet001\Control\Terminal Server\WinStations\RDP-Tcp
ed PortNumber
0xd3d

最后按q退出编辑并且选择保存变化,完成后卸除挂在并重启windows系统,那么修复就完成了。
修复完成后则可以正常登录系统,重新配置防火墙规则。

 

Amefs, EFS, Linux
上一篇文章
QuickBox 折腾与简单总结
下一篇文章
三月的狮子 BDRip 制作感受

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

Fill out this field
Fill out this field
请输入有效的电子邮箱地址。

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据

keyboard_arrow_up