Closed Thread
Results 1 to 5 of 5

Thread: Registry Watching

  1. #1
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Registry Watching

    At work, someone wrote a virus that infects flash drives. Whenever one of these flash drives is inserted into a computer, the CD key as well as passwords and other sensitive information is retrieved and either stored on the flash drive or transmitted somewhere (I don't know).

    I'm trying to write a virus killer for this - is there any way for my program to watch a few registry keys and be notified by Windows when they are read from or written to? Standard hooks won't cut it.

    This is for Windows XP, to be written in either C++ or VBScript, another language if necessary.

    And no, our anti-virus software doesn't catch it.

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Location
    Advertising world
    Posts
    Many

     
  3. #2
    Join Date
    Jul 2006
    Posts
    16,491
    Blog Entries
    75
    Rep Power
    143

    Re: Registry Watching

    Well, autorun should be disabled for all flash media. RegMon can help you out, as can WinPooch. A decent firewall should block it from transmitting any data.
    Programming is a branch of mathematics.
    My CodeCall Blog | My Personal Blog

  4. #3
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Registry Watching

    Thanks for your suggestion. Yes, RegMon is nice, but it has some problems.
    1) It's not embedable and would require installation on every single computer in the school.
    2) You can't watch every computer and kill processes as necessary remotely. There are too many computers.

    What I intend to write will be a single program on the main server that will be run on every login and monitor the users' computers until they log off. If any suspicious activity is detected, it will send the user id to the administrator and kill the infecting processes.

  5. #4
    Join Date
    Oct 2007
    Location
    /dev/null
    Posts
    4,513
    Blog Entries
    8
    Rep Power
    59

    Re: Registry Watching

    After a lot of research, I finally found the answer buried on MSDN. There are a few steps involved:

    Write a virtual device driver that does the following:
    1) Call CmRegisterCallback to register your watching function with the system.
    2) For every registry operation, your function will be called. Filter out the calls you don't need to handle first so you won't slow the system down.
    3) Return STATUS_SUCCESS for successful calls, and an error value of your choice (such as ERROR_ACCESS_DENIED) to block a registry operation.
    4) When done, call CmUnRegisterCallback to remove your hooking function.

    (Keep in mind that the following will work only in Windows.)

    Code:
    #include <windows.h>
    #include <wdm.h>
    #include <ntddk.h>
    #include <ntifs.h>
    
    //declaration for the watching callback function
    NTSTATUS RegWatcher(LPVOID,LPVOID,LPVOID);
    
    NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING pRegistryPath)
    {
        uint64_t    qwHookId;
        //do some stuff here...
        //now set the registry hook
        CmRegisterCallback(RegWatcher,NULL,&qwHookId);
        //wait until the driver is unloaded...
        //now remove the hook.
        CmUnRegisterCallback(&qwHookId);
    }
    
    NTSTATUS RegWatcher(LPVOID lpData, LPVOID lpRegCallType, LPVOID lpCallData)
    {
        //we only care about registry reads in this example
        REG_NOTIFY_CLASS *calltype = (REG_NOTIFY_CLASS *)lpRegCallType;
        if(*calltype != REG_NOTIFY_CLASS::RegNtQueryKey)
            return STATUS_SUCCESS;
        //caught a registry read, continue processing
        //deny access for some reason
        return ERROR_ACCESS_DENIED;
    }

  6. #5
    barrye is offline Newbie
    Join Date
    Mar 2009
    Posts
    14
    Rep Power
    0

    Re: Registry Watching

    You need to hook Registry key write and read in kernel level to watch the registry key access. I remember there is a source code in wenpoint security info web site. But I could not find now. You can do a search.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Registry hex to text?
    By ahmed in forum The Lounge
    Replies: 5
    Last Post: 08-09-2011, 05:37 PM
  2. How do i add the following registry keys
    By iluxon4ik in forum General Programming
    Replies: 2
    Last Post: 03-11-2010, 05:54 PM
  3. About EnableDHCP registry
    By chesschi in forum Managed C++
    Replies: 1
    Last Post: 01-11-2009, 10:28 PM
  4. Registry?
    By MarkA in forum Linux/Unix General
    Replies: 5
    Last Post: 12-10-2008, 05:15 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts