我最近在工作中遇到了一个问题,客户的 Windows 10 PC 失去了对域的信任。 用户是一名高管,他的计算机的障碍会影响实时的关键任务任务。 他在参加会议时给了我 30 分钟来解决问题。
不用说,我在职业生涯中多次遇到过这个问题。 使用 Windows 7/8/10 安装介质重置管理员密码、将 PC 从域中移除并重新加入它是一个简单的修复。 不幸的是,这一次没有奏效。 经过 20 分钟的网上搜索和扫描 Microsoft Docs 没有成功,我转向我的开发机器运行 Fedora 并希望找到解决方案。
通过 dnf 搜索,我找到了一个名为 chntpw:
$ dnf search windows | grep password
根据总结,chntpw 将“更改 Windows SAM 文件中的密码”。
当时我几乎不知道这个实用程序的功能比摘要中解释的要多。 因此,本文将介绍我使用 chntpw 和 Fedora 工作站实时启动 USB。 本文还将介绍用于基本用户管理的 chntpw 的一些功能。
安装和设置
如果启动直播媒体后PC可以上网,请从官方安装chntpw Fedora 存储库:
$ sudo dnf install chntpw
如果您无法访问互联网,别担心! Fedora Workstation Live 启动媒体具有开箱即用安装的所有依赖项,因此我们只需要软件包。 您可以找到适合您的构建 Fedora 版本来自 Fedora 项目的小司 地点。 您可以使用另一台计算机下载该实用程序并使用 USB 拇指驱动器或其他形式的媒体来复制包。
首先,我们需要创建 Fedora 现场 USB 记忆棒。 如果您需要说明,请参阅有关如何制作 Fedora USB记忆棒是一个很好的参考。
创建密钥后,关闭 Windows PC,如果 USB 密钥是在另一台计算机上创建的,请插入拇指驱动器,然后打开 PC — 确保从 USB 驱动器启动。 实时媒体启动后,选择“尝试 Fedora”并打开终端应用程序。
此外,我们需要挂载 Windows 驱动器来访问这些文件。 Enter 使用以下命令查看所有具有 NTFS 文件系统的驱动器分区:
$ sudo blkid | grep ntfs
大多数硬盘驱动器分配给 /dev/sdaX,其中 X 是分区号——虚拟驱动器可能分配给 /dev/vdX,一些较新的驱动器(如 SSD)使用 /dev/nvmeX。 为了这 example Windows C 驱动器分配给 /dev/sda2。 要安装驱动器,请输入:
$ sudo mount /dev/sda2 /mnt
Fedora Workstation 包含开箱即用的 ntfs-3g 和 ntfsprogs 软件包。 如果您使用的是没有开箱即用 NTFS 的旋转,您可以从官方安装这两个包 Fedora 存储库:
$ sudo dnf install ntfs-3g ntfsprogs
安装驱动器后,导航到 SAM 文件的位置并验证它是否存在:
$ cd /mnt/Windows/System32/config
$ ls | grep SAM
SAM
SAM.LOG1
SAM.LOG2
清除或重置密码
现在是时候开始工作了。 帮助标志 -H 提供我们需要了解的有关此实用程序以及如何使用它的所有信息:
$ chntpw -h
chntpw: change password of a user in a Windows SAM file,
or invoke registry editor. Should handle both 32 and 64 bit windows and
all version from NT3.x to Win8.1
chntpw [OPTIONS] [systemfile] [securityfile] [otherreghive] […]
-h This message
-u Username or RID (0x3e9 for example) to interactively edit
-l list all users in SAM file and exit
-i Interactive Menu system
-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)
Usernames can be given as name or RID (in hex with 0x first)
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!
使用 -l 参数以显示它从 SAM 文件中读取的用户列表:
$ sudo chntpw -l SAM
chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <SystemRootSystem32ConfigSAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 346/37816 blocks/bytes, unused: 23/7016 blocks/bytes.
| RID -|---------- Username ------------| Admin? |- Lock? --|
| 01f4 | Administrator | ADMIN | dis/lock |
| 01f7 | DefaultAccount | | dis/lock |
| 03e8 | defaultuser0 | | dis/lock |
| 01f5 | Guest | | dis/lock |
| 03ea | sysadm | ADMIN | |
| 01f8 | WDAGUtilityAccount | | dis/lock |
| 03e9 | WinUser | | |
现在我们有了一个 Windows 用户列表,我们可以编辑该帐户。 使用 -u 参数后跟用户名和 SAM 文件的名称。 为了这 example,编辑 sysadm 帐户:
$ sudo chntpw -u sysadm SAM
chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <SystemRootSystem32ConfigSAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 346/37816 blocks/bytes, unused: 23/7016 blocks/bytes.
================= USER EDIT ====================
RID : 1002 [03ea]
Username: sysadm
fullname: SysADM
comment :
homedir :
00000220 = Administrators (which has 2 members)
Account bits: 0x0010 =
[ ] Disabled | [ ] Homedir req. | [ ] Passwd not req. |
[ ] Temp. duplicate | [X] Normal account | [ ] NMS account |
[ ] Domain trust ac | [ ] Wks trust act. | [ ] Srv trust act |
[ ] Pwd don't expir | [ ] Auto lockout | [ ] (unknown 0x08) |
[ ] (unknown 0x10) | [ ] (unknown 0x20) | [ ] (unknown 0x40) |
Failed login count: 0, while max tries is: 0
Total login count: 0
- - - User Edit Menu:
1 - Clear (blank) user password
(2 - Unlock and enable user account) [seems unlocked already]
3 - Promote user (make user an administrator)
4 - Add user to a group
5 - Remove user from a group
q - Quit editing user, back to user select
Select: [q] >
要清除密码,请按 1 并输入。 如果成功,您将看到以下消息:
...
Select: [q] > 1
Password cleared!
================= USER EDIT ====================
RID : 1002 [03ea]
Username: sysadm
fullname: SysADM
comment :
homedir :
00000220 = Administrators (which has 2 members)
Account bits: 0x0010 =
[ ] Disabled | [ ] Homedir req. | [ ] Passwd not req. |
[ ] Temp. duplicate | [X] Normal account | [ ] NMS account |
[ ] Domain trust ac | [ ] Wks trust act. | [ ] Srv trust act |
[ ] Pwd don't expir | [ ] Auto lockout | [ ] (unknown 0x08) |
[ ] (unknown 0x10) | [ ] (unknown 0x20) | [ ] (unknown 0x40) |
Failed login count: 0, while max tries is: 0
Total login count: 0
** No NT MD4 hash found. This user probably has a BLANK password!
** No LANMAN hash found either. Try login with no password!
...
通过重复验证更改:
$ sudo chntpw -l SAM
chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <SystemRootSystem32ConfigSAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 346/37816 blocks/bytes, unused: 23/7016 blocks/bytes.
| RID -|---------- Username ------------| Admin? |- Lock? --|
| 01f4 | Administrator | ADMIN | dis/lock |
| 01f7 | DefaultAccount | | dis/lock |
| 03e8 | defaultuser0 | | dis/lock |
| 01f5 | Guest | | dis/lock |
| 03ea | sysadm | ADMIN | *BLANK* |
| 01f8 | WDAGUtilityAccount | | dis/lock |
| 03e9 | WinUser | | |
...
锁?” 列现在为 sysadm 用户显示 BLANK。 类型 q 退出并 是的 将更改写入 SAM 文件。 将机器重新启动到 Windows 并使用没有密码的帐户(在本例中为 sysadm)登录。
特征
此外,chntpw 可以执行基本的 Windows 用户管理任务。 它具有将用户提升到管理员组、解锁帐户、查看和修改组成员资格以及编辑注册表的能力。
交互式菜单
chntpw 有一个易于使用的交互式菜单来指导您完成整个过程。 使用 -一世 启动交互式菜单的参数:
$ chntpw -i SAM
chntpw version 1.00 140201, (c) Petter N Hagen
Hive name (from header): <SystemRootSystem32ConfigSAM>
ROOT KEY at offset: 0x001020 * Subkey indexing type is: 686c
File size 65536 [10000] bytes, containing 7 pages (+ 1 headerpage)
Used for data: 346/37816 blocks/bytes, unused: 23/7016 blocks/bytes.
<>========<> chntpw Main Interactive Menu <>========<>
Loaded hives:
1 - Edit user data and passwords
2 - List groups
- - -
9 - Registry editor, now with full write support!
q - Quit (you will be asked if there is something to save)
组和帐户成员资格
要显示组列表并查看其成员,请选择选项 2 从交互式菜单中:
...
What to do? [1] -> 2
Also list group members? [n] y
=== Group # 220 : Administrators
0 | 01f4 | Administrator |
1 | 03ea | sysadm |
=== Group # 221 : Users
0 | 0004 | NT AUTHORITYINTERACTIVE |
1 | 000b | NT AUTHORITYAuthenticated Users |
2 | 03e8 | defaultuser0 |
3 | 03e9 | WinUser |
=== Group # 222 : Guests
0 | 01f5 | Guest |
=== Group # 223 : Power Users
...
=== Group # 247 : Device Owners
将用户添加到管理员组
要提升具有管理权限的用户,请按 1 编辑帐户,然后 3 推广用户:
...
Select: [q] > 3
=== PROMOTE USER
Will add the user to the administrator group (0x220)
and to the users group (0x221). That should usually be
what is needed to log in and get administrator rights.
Also, remove the user from the guest group (0x222), since
it may forbid logins.
(To add or remove user from other groups, please other menu selections)
Note: You may get some errors if the user is already member of some
of these groups, but that is no problem.
Do it? (y/n) [n] : y
Adding to 0x220 (Administrators) …
sam_put_user_grpids: success exit
Adding to 0x221 (Users) …
sam_put_user_grpids: success exit
Removing from 0x222 (Guests) …
remove_user_from_grp: NOTE: group not in users list of groups, may mean user not member at all. Safe. Continuing.
remove_user_from_grp: NOTE: user not in groups list of users, may mean user was not member at all. Does not matter, continuing.
sam_put_user_grpids: success exit
Promotion DONE!
编辑 Windows 注册表
当然,chntpw 最值得注意,也是最强大的功能是能够编辑注册表并写入它。 选择 9 从交互式菜单中:
...
What to do? [1] -> 9
Simple registry editor. ? for help.
> ?
Simple registry editor:
hive [] - list loaded hives or switch to hive number
cd - change current key
ls | dir [] - show subkeys & values,
cat | type - show key value
dpi - show decoded DigitalProductId value
hex - hexdump of value data
ck [] - Show keys class data, if it has any
nk - add key
dk - delete key (must be empty)
ed - Edit value
nv - Add value
dv - Delete value
delallv - Delete all values in current key
rdel - Recursively delete key & subkeys
ek - export key to (Windows .reg file format)
debug - enter buffer hexeditor
st [] - debug function: show struct info
q - quit
寻求帮助
正如我们之前看到的, -H 参数允许我们快速访问 chntpw 可用选项的参考指南。 手册页包含详细信息,可以通过以下方式访问:
$ man chntpw
此外,如果您对更实际的方法感兴趣,请启动虚拟机。 视窗服务器 2019 评估期为 180 天,并且 Windows Hyper-V 服务器 2019 是无限的。 创建 Windows 来宾 VM 将提供修改管理员帐户以进行测试和学习的基础知识。 有关快速创建来宾 VM 的帮助,请参阅文章 Gnome Boxes 中的虚拟化入门。
结论
chntpw 对 Linux 管理员和 IT 专业人员来说是一个隐藏的宝石。 虽然是一个快速重置 Windows 帐户密码的好工具,但它也可用于解决和修改本地 Windows 帐户,并提供一种严肃的感觉。 不过,这可能只是解决问题的工具之一。 如果您遇到此问题并有替代解决方案,请随时将其放在下面的评论中。
该工具与许多其他“黑客”工具一样,承担着道德责任。 甚至 chntpw 声明:
注意:这个程序有点骇人听闻! 你只能靠自己!
使用此类程序时,我们应该记住运行时显示的消息中概述的三个法令 sudo 首次:
- 尊重他人的隐私。
- 打字前三思。
- 拥有权利的同时也被赋予了重大的责任。