If you have ever felt the need to mount a Windows registry hive as a FUSE filesystem, Sergey Trubin’s hivexfs may be the project for you!
Tag Archives: hivex
libguestfs 1.12.6 for Debian
Thanks to the tireless work of Hilko Bengen, libguestfs 1.12.6 is now available as an official Debian package.
Also, you can compile hivex on Mac OS X and Windows, thanks to Alex Nelson and Gillen Daniel respectively.
Filed under Uncategorized
Ruby bindings for Hivex
Hivex is a library for reading and writing Windows Registry “hive” files. New in version 1.3.0 and Fedora 16 is the ability to access the library from Ruby.
As an example, first grab some hive files from a Windows virtual machine. The simplest way is using virt-copy-out:
# virt-copy-out -a win.img \
'win:c:\windows\system32\config' .
# ls config/
...
SOFTWARE
SYSTEM
...
Using the following Ruby script you can extract and display registry keys from the hive files:
#!/usr/bin/ruby
require 'hivex'
h = Hivex::open("config/SOFTWARE", {})
# Use this instead if you want to make changes:
# h = Hivex::open("config/SOFTWARE", { :write => 1 })
root = h.root()
node = h.node_get_child(root, "Microsoft")
if node.nil? then
puts "no HKLM\\SOFTWARE\\Microsoft node: Probably not the correct hive"
end
node = h.node_get_child(node, "Windows NT")
node = h.node_get_child(node, "CurrentVersion")
val = h.node_get_value(node, "ProductName")
hash = h.value_value(val)
puts "Windows product name:", hash[:value]
Filed under Uncategorized
Today, in other projects …
virt-top 1.0.6 – utility for displaying virtualization stats, like ‘top’
hivex 1.2.8 – library and tools for reading and writing Windows Registry hive files
Filed under Uncategorized
Tip: Change the background image in a Windows VM
Thanks to Tom Horsley who worked out how to do this for Windows XP guests (the technique is probably different for other versions of Windows).
Here is Tom’s script and here are more of his KVM tips.
Filed under Uncategorized
hivex 1.2.5 released
The latest version of hivex — the library for extracting and modifying Windows Registry hive files has been released. You can get the source from here.
I spent a lot of time examining real hive files from Windows machines and running the library under the awesome valgrind tool, and found one or two places where a corrupt hive file could cause hivex to read uninitialized memory. It’s not clear to me if these are security issues — I think they are not — but everyone is advised to upgrade to this version anyway.
hivex would be a great candidate for fuzz testing if anyone wants to try that.
Filed under Uncategorized
Tip: Code for getting DHCP address from a virtual machine disk image
Previously (1) and previously (2) I showed there are many different ways to get the IP address from a virtual machine.
The example below shows one way to use libguestfs and hivex from a C program (virt-dhcp-address) to get the DHCP address that a virtual machine has picked up.
Filed under Uncategorized
Tip: Another way to get the IP address of a virtual machine
In this earlier post several ways were discussed of getting the IP address of a virtual machine (specifically if the VM is acquiring a different address each time from DHCP).
Another way is to use virt-cat or virt-win-reg to grab the information out of the virtual machine itself.
When a VM acquires an IP address from DHCP then it writes the address to a log file, or in the Windows case updates the Windows Registry. The idea is simply that we’ll read the information from the VM’s log files or the Registry.
The details vary depending on the precise guest type, and probably we should wrap this up in a nice virt tool. But here’s how you would do it for Fedora/RHEL and Windows guests:
# virt-cat RHEL60x64 /var/log/messages | grep 'dhclient.*bound to' Mar 30 19:56:22 rhel60x64 dhclient: bound to 192.168.122.220 -- renewal in 1527 seconds. Mar 30 20:21:49 rhel60x64 dhclient: bound to 192.168.122.220 -- renewal in 1375 seconds. Mar 30 20:44:44 rhel60x64 dhclient: bound to 192.168.122.220 -- renewal in 1287 seconds. Mar 30 21:06:11 rhel60x64 dhclient: bound to 192.168.122.220 -- renewal in 1461 seconds.
# virt-win-reg Win7x32 \ 'HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\Tcpip\Parameters' | \ grep DhcpIPAddress "DhcpIPAddress"=hex(1):31,00,39,00,32,00,2e,00,31,00,36,00,38,00,2e,00,31,00,32,00,32,00,2e,00,31,00,37,00,38,00,00,00
In the Windows case you need to note that ControlSet001 isn’t always the right control set — consult this note in the virt-win-reg man page to find the correct way to do this. Furthermore virt-win-reg prints out the hex-encoded UTF16-LE string, which requires a little bit of conversion to produce a printable string (192.168.122.178 in this instance).
Update: To add to all the other methods from the previous post, and the method described above, Eric Blake also points out that nwfilter can sniff IP addresses used by VMs.
Filed under Uncategorized
Tip: List services in a Windows guest
The lengthy program after the fold uses libguestfs and hivex to list out the services from a Windows guest. You point it to a Windows guest and it will produce a rather long list, like this:
# ./services.pl WindowsGuest [...] SysMain: Path: %systemroot%\system32\svchost.exe -k LocalSystemNetworkRestricted Start flag: autoload Service type: Win32 service using svchost Error control: ignore TabletInputService: Path: %SystemRoot%\System32\svchost.exe -k LocalSystemNetworkRestricted Group: PlugPlay Start flag: load on demand Service type: Win32 service using svchost Error control: normal TapiSrv: Path: %SystemRoot%\System32\svchost.exe -k NetworkService Start flag: load on demand Service type: Win32 service using svchost Error control: normal TBS: Path: %SystemRoot%\System32\svchost.exe -k LocalServiceAndNoImpersonation Start flag: load on demand Service type: Win32 service using svchost Error control: normal Tcpip: Path: System32\drivers\tcpip.sys Group: PNP_TDI Start flag: boot loader Service type: kernel device driver Error control: normal TCPIP6 (Microsoft IPv6 Protocol Driver): Microsoft IPv6 Protocol Driver Path: system32\DRIVERS\tcpip.sys Start flag: load on demand Service type: kernel device driver Error control: normal tcpipreg (TCP/IP Registry Compatibility): Provides compatibility for legacy applications which interact with TCP/IP through the registry. If this service is stopped, certain applications may have impaired functionality. Path: System32\drivers\tcpipreg.sys Start flag: autoload Service type: kernel device driver Error control: normal [...]
Filed under Uncategorized
Use hivex from Python to read and write Windows Registry “hive” files
I added Python bindings to hivex today.
Here is an example using Python, libguestfs and hivex to download the user preferences registry from a Windows virtual machine and print out the Internet Explorer start page for a particular user. When you run it, it should print out something like:
User rjones's IE home page is http://go.microsoft.com/fwlink/?LinkId=69157
This example shows downloading and printing values, but libguestfs and hivex can also be used to make changes (but not to live guests).
#!/usr/bin/python
import guestfs
import hivex
# The name of a Windows virtual machine on this host. This
# example script makes some assumptions about the registry
# location and contents which only apply on Windows Vista
# and later versions.
windows_domain = "Win7x32"
# Username on the Windows VM.
username = "rjones"
# Use libguestfs to download the HKEY_CURRENT_USER hive.
g = guestfs.GuestFS ()
g.add_domain (windows_domain, readonly=1)
g.launch ()
roots = g.inspect_os ()
root = roots[0]
g.mount_ro (root, "/")
path = "/users/%s/ntuser.dat" % username
path = g.case_sensitive_path (path)
g.download (path, "/tmp/ntuser.dat")
# Use hivex to pull out a registry key.
h = hivex.Hivex ("/tmp/ntuser.dat")
key = h.root ()
key = h.node_get_child (key, "Software")
key = h.node_get_child (key, "Microsoft")
key = h.node_get_child (key, "Internet Explorer")
key = h.node_get_child (key, "Main")
val = h.node_get_value (key, "Start Page")
start_page = h.value_value (val)
#print start_page
# The registry key is encoded as UTF-16LE, so reencode it.
start_page = start_page[1].decode ('utf-16le').encode ('utf-8')
print "User %s's IE home page is %s" % (username, start_page)
Filed under Uncategorized
