Cobra Forum

Other Discussion and Support => Tutorials => Topic started by: mahesh on Dec 01, 2023, 07:00 AM

Title: Scripting windows registry offline editing! (Updated)
Post by: mahesh on Dec 01, 2023, 07:00 AM
I've spent most of today figuring out how to use chntpw to modify an offline windows registry non-interactively. There is an *ancient* tutorial here that doesn't seem to work anymore, but it got me on the right track.

The key to making chntpw function non-interactively is a "Here document" or a section of a bash script that can pass successive commands, interactively, into a tool. The section of the script then closes the interactive tool, thus completing its task without requiring user interaction. Here is an updated version of the 10 year old tutorial.

The following example code will execute chntpw interactively, move it into the specified location in the hive, ls out the values within and then quit:

Code:
#!/bin/bash
#REMEMBER TO SUDO ME!
ntfs-3g /dev/sda2 /mnt/sda2
cd /mnt/sda2/Windows/System32/config
#Run the following 'Here Document' for all commands between CommandsIndicatorString
chntpw -e SOFTWARE<<- CommandsIndicatorString
cd Microsoft\Windows NT
ls
q
CommandsIndicatorString
A few things of note:


Here is a quick guide to some of the chntpw command flag options (from here):

for nv <type> <valuename> (adding a value to a key) the list of <types> from chntpw is as follows:


USE THE TOOL MANUALLY BEFORE TRYING TO SCRIPT ANYTHING! It's very important to test all your commands and your syntax before trying to script it. Be sure to back up / export the target registry hive before modifying so that there is a clean copy on hand in case of disaster.

Hope this helps someone else fight the good fight!