24

Could someone please give me a high level explanation how they are able to monitor every single registry access?

http://technet.microsoft.com/en-us/sysinternals/bb896645

Enough detail so that i could google around the various sub-topics and try to write my own one? I know they've used some sort of dll injection/API hooking, but i'm unsure how they reached all the kernel mode activity.

Tom
  • 419
  • 1
  • 5
  • 7
  • 9
    basically mark russinovich can do absolutely anything he wants he's god like!! – David Heffernan Jan 28 '11 at 23:25
  • Well there is no big deal of it. If you go to the linux world you will find mush powerful tool that does mush more. `gdb`, `lsof`, `strace`, `cat|echo /proc/{pretty mush every thing you need to know}`, ... and guess what you can read the source – mathk Jan 28 '11 at 23:28
  • 3
    @mathk how would you write a windows registry monitor in linux? – David Heffernan Jan 29 '11 at 00:05
  • @David Heffernan : Well there is no such thing as registry on linux so you question does not make really sense. Beside that you can use D-Bus : http://www.freedesktop.org/wiki/Software/dbus for the kind of job your are implying, or use /proc/fschange depending. – mathk Jan 29 '11 at 00:12
  • @mathk: Yes, Linux works in a different way, which means it's easier to do some tasks, and it's much more open. Do you have a point beyond that? (hint: "eh, Linux does this better" is not the right answer for *every* question about Windows - even if you'd be correct, it's hardly useful to the OP) As for registry - ever heard of gconf? Yes, technically it's a part of GNOME, but it looks a lot like a port of Windows registry (I'm not convinced that it's a Good Thing). – Piskvor left the building Jan 29 '11 at 07:19
  • @mathk I know perfectly well that the registry is a Windows thing. My question was posed to illustrate the absurdity of your original comment. What you say may be true, or not, but it didn't deal with the topic at hand. – David Heffernan Jan 29 '11 at 08:39
  • @Piskvor and @David Heffernan. I don't pretend to give any answer there. That is why I add a comment. Beside my comment just point the fact the if someone is willing to learn about OS stuff and other he will learn more with free and open source software. – mathk Jan 29 '11 at 14:56
  • @mathk: Not necessarily. With Procexp, I have learned much about Windows (and programs for Windows); I doubt there's an open-source tool for Windows with comparable functionality (I know the Cygwin stack, but as it is above all a *compatibility* layer, it had to make some compromises). [Piskvor realizes he's been trolled] – Piskvor left the building Jan 30 '11 at 13:28

1 Answers1

23

It loads a virtual driver on startup which does the monitoring on a low-level. So it doesn't have to inject anything in other processes.

On http://www.decuslib.com/decus/vmslt00a/nt/filemon.htm there's a short explanation about how FileMon, one of ProcMon's predecessors, works.

How Filemon Works

For the Windows 9x driver, the heart of Filemon is in the virtual device driver, Filevxd.vxd. It is dynamically loaded, and in its initialization it installs a file system filter via the VxD service, IFSMGR_InstallFileSystemApiHook, to insert itself onto the call chain of all file system requests. On Windows NT the heart of Filemon is a file system driver driver that creates and attaches filter device objects to target file system device objects so that Filemon will see all IRPs and FastIO requests directed at drives.

When Filemon sees an open, create or close call, it updates an internal hash table that serves as the mapping between internal file handles and file path names. Whenever it sees calls that are handle based, it looks up the handle in the hash table to obtain the full name for display. If a handle-based access references a file opened before Filemon started, Filemon will fail to find the mapping in it hash table and will simply present the handle's value instead.

Information on accesses is dumped into an ASCII buffer that is periodically copied up to the GUI for it to print in its listbox.

Likewise, Regmon another predecessor is similar:

How Regmon Works

The heart of Regmon on Windows 9x is in the virtual device driver, Regvxd.vxd. It is dynamically loaded, and in its initialization it uses VxD service hooking (see our May 1996 Dr. Dobb's Journal article on VxD service hooking for more information) to insert itself onto the call chain of 16 registry access functions in the Windows 95 kernel (Virtual Machine Manager). All registry activity, be it from 16-bit programs, Win32 applications, or device drivers, are directed at these routines, so Regmon catches all registry activity taking place on a machine.

On Windows NT the Regmon loads a device driver that uses a technique we developed for NT called system-call hooking. When a user-mode component makes a privileged system call, control is transfered to a software interrupt handler in NTOSKRNL.EXE (the core of the Windows NT operating system). This handler takes a system call number, which is passed in a machine register, and indexes into a system service table to find the address of the NT function that will handle the request. By replacing entries in this table with pointers to hooking functions, it is possible to intercept and replace, augment, or monitor NT system services. Regmon, which obviously hooks just the Registry-related services, is merely one example of this capability in action.

When Regmon sees an open, create or close call, it updates an internal hash table that serves as the mapping between key handles and registry path names. Whenever it sees calls that are handle based, it looks up the handle in the hash table to obtain the full name for display. If a handle-based access references a key opened before Regmon started, Regmon will fail to find the mapping in it hash table and will simply present the key's value instead.

Information on accesses is dumped into an ASCII buffer that is periodically copied up to the GUI for it to print in its listbox.

If you like reading code, here's the source code of FileMon and RegMon: http://www.wasm.ru/baixado.php?mode=tool&id=283 (from http://forum.sysinternals.com/topic8038_page1.html)

StayOnTarget
  • 11,743
  • 10
  • 52
  • 81
ThiefMaster
  • 310,957
  • 84
  • 592
  • 636
  • 4
    You can get it from wasm.ru on Internet Archive: https://web.archive.org/web/20050221211220/http://wasm.ru/baixado.php?mode=tool&id=283 – Jason Oct 19 '16 at 14:00