Tag Archives: xml

Decoding the Windows Event Log using guestfish

The Windows Event Log system is Windows’ centralized way of capturing log messages from the operating system and a wide variety of applications.

In all versions of Windows the messages are stored in binary files and normally you can only read these using Microsoft’s proprietary Event Viewer program. In Windows Vista, Microsoft overhauled the entire messaging system and changed the binary format. Luckily a German computer forensics researcher named Andreas Schuster reverse engineered the format [PDF] and wrote a small GPL’d program called EvtxParser [download dir] which can decode it.

We can use guestfish (or libguestfs) along with EvtxParser to easily look at the events in any Windows Vista / 2008 / 7 virtual machine.

Firstly download EvtxParser. You don’t need to install it (indeed, it doesn’t come with any build system so you can’t install it without some effort). You do need to install a few supporting Perl modules though:

# yum install perl-Digest-CRC perl-DateTime \
    perl-Carp-Assert perl-CPAN tidy
# cpan install Data::Hexify

Also the Perl scripts in the EvtxParser zip file aren’t all executable, so chmod them:

$ chmod +x *.pl

Now grab some *.evtx files from your Windows Vista (or later) system. They are stored in the /Windows/System32/winevt/Logs/ directory:

# guestfish --ro -i -d WindowsGuest
><fs> ll win:/Windows/System32/winevt/Logs
total 10540
drwxrwxrwx 1 root root   28672 Oct  1  2010 .
drwxrwxrwx 1 root root       0 Jul 14  2009 ..
-rwxrwxrwx 2 root root 1118208 Dec 23 18:22 Application.evtx
-rwxrwxrwx 2 root root   69632 Sep 19  2010 HardwareEvents.evtx
-rwxrwxrwx 2 root root   69632 Sep 19  2010 Internet Explorer.evtx
-rwxrwxrwx 2 root root   69632 Sep 19  2010 Key Management Service.evtx
-rwxrwxrwx 2 root root   69632 Sep 19  2010 Media Center.evtx
[and many more]
><fs> download win:/Windows/System32/winevt/Logs/System.evtx /tmp/System.evtx
><fs> exit

You can directly dump the files you have downloaded as XML to reveal the events inside them.

$ ./evtxdump.pl /tmp/System.evtx | tidy -xml -indent -quiet | less

This gives me a 40,000 line XML document(!) As a representative sample, the last event is the shutdown event from when I shut the VM off last time:

  <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
      <Provider Name="Service Control Manager"
      EventSourceName="Service Control Manager" />
      <EventID Qualifiers="16384">7036</EventID>
      <TimeCreated SystemTime="2010-12-23T18:22:58.4980Z" />
      <Correlation />
      <Execution ProcessID="456" ThreadID="1748" />
      <Security />
      <Data Name="param1">Power</Data>
      <Data Name="param2">stopped</Data>

A tip for reading these: the key field is the EventID. For example, EventID 1074 is a user-initiated clean shutdown.


Filed under Uncategorized

Stay classy, Microsoft

I thought when I was looking at the Windows Registry I’d seen it all … until today when I found that the Windows 7 installation CD contains what seems like a registry that directly encodes an XML schema document.


If you have a Win7 install CD, it is /sources/schema.dat. After passing it through hivexregedit –export you get:

Windows Registry Editor Version 5.00









(and on for 1,355 lines)

Leave a comment

Filed under Uncategorized

Display an XML doc from the command line

Leading me down the garden path today, how to quickly display an XML document … graphically, from the command line?

This doesn’t work:

$ virt-inspector --xml RHEL54.img | firefox -

Creating a temporary file is possible, but ugly.

Then I was tipped off that you can create and pass a data: URI to Firefox.

There is no existing command line tool to generate data URIs, but we can write one in 3 lines of shell script:

#!/bin/sh -
echo -n data:$1\;
uuencode -m notused | tail -n +2 | tr -d '\n'


$ cat > /tmp/test.html
$ datauri text/html < /tmp/test.html

This also doesn’t work. There are two problems: the XML generated by virt-inspector is too long for a data URI, and in any case Firefox seems to ignore the data URI although I’m sure I’m constructing it correctly. Maybe it’s a security or configuration issue?

Well, good idea, but let’s go back to the temporary file idea. Bash process substitution might have worked:

$ firefox <(virt-inspector --xml RHEL54.img)

but Firefox’s frankly stupid session management crap gets in the way because this command expands to something like:

$ firefox /proc/self/fd/123

and the new firefox process passes the non-portable /proc/self path to the currently running instance of Firefox which doesn’t have the same view of /proc/self.

So we are finally left with:

$ firefox $(f=`mktemp -u`;
            virt-inspector --xml RHEL54.img > $f.xml;
            echo $f.xml)

which is fugly and unsafe.

If only there was a less insane tool to display XML, but being XML I guess insane goes with the territory.


Filed under Uncategorized

XML or S-expressions?

I was writing a little program to track monthly outgoings. “Only” £30/month for internet access or whatever can quickly add up …

But what format should I save the data in? XML is heavyweight and redundant compared to S-expressions, compare:

<outgoing rate="monthly">
  (rate monthly)
  (price 30.)
  (name "Internet"))

(Update: fixed XML x 2)

One difference I always notice is the redundancy of attributes like rate=”monthly”. S-expressions let you decide to make the attribute structured, but with XML you’re stuck with a simple string unless you make an incompatible change to the schema.

Another difference is that S-expressions are typed. 30 is a float and “Internet” is a string. XML is all just strings, which sucks when your language is typed.

On the other hand this article makes a good argument that XML is not (and is better than) S-expressions. More debate here.

A killer feature of OCaml is the sexplib syntax extension which makes S-expressions really easy. You just define any OCaml type in the usual way, and add with sexp after it, and that magically generates serializer and deserializer functions for your type, so you can slurp your data into and out of S-expression files effortlessly. A page of boilerplate disappears in just two words. That’s probably the reason why I’ll go with S-expressions for this.


Filed under Uncategorized

Use libguestfs to view devices and filesystems in a VM

Here is a small C program (examples/to-xml.c) which uses libguestfs to examine a virtual machine and produce a little XML display of the partitions, LVM data and filesystems within the virtual machine.

This XML is fanciful. Is there a standard XML description for this sort of thing?


$ examples/to-xml RHEL52PV32-tmp.img | tidy -xml -i -q
    <device dev="/dev/sda">
        <partition dev="/dev/sda1">
          <fs type="ext3">
        <partition dev="/dev/sda2">
          <physvol />
    <volgroup name="VolGroup00">
      <logvol name="/dev/VolGroup00/LogVol00">
        <fs type="ext3">
      <logvol name="/dev/VolGroup00/LogVol01">
        <linux-swap />

Leave a comment

Filed under Uncategorized