A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #11452  by AmrThabet
 Sun Feb 05, 2012 8:15 pm
Hello everyone,

I'm AmrThabet ... I'm a malware researcher, Rootkit Researcher and system developer

I'm writing a Rootkit Development Framework ( I mean with rootkits : filter drivers and so on ... not malware)

This Framework will gives you these things:
---------------------------------------------------
1) Full Object Oriented Interface (as much as I can) to develop your rootkit. This Interface gives you the ability to work with different types of rootkits in one driver without any interference (Irp Multi-Dispatcher and many more).

2) easy to use ... without the need to write 1000 of lines to begin writing your FileSystem Filter or read a huge book to hook just a function. make you focus on your goal while writing your rootkit.

3) Supports SSDT Hooking, Filter Device Drivers, DKOM rookits with a database of all needed offsets of the opaque structures for most versions

4) Supports FileSystem Filters (with Attaching to Newly Attached Volumes) and Supporting TDI Client, Server and Sniffer

5) Supports APC Injection (still I didn't program it)

6) Has a FileManager, RegistryManager, User-Mode Communication Protocol (class in kernel-mode and another in user-mode to support working with this protocol)

7) Has a string class (to work well with unicode strings) has features like searching, splitting and many more (still not developed)
------------------------------

Also ... it should have a user interface like Metasploit ... that has all open source rootkits that uses the RDF (Rootkit Development Framework) inside.

This project will not become for me ... it will be free and open-source for whole people need to join ... I want to build a big community for it.

What do you think? ;)
 #11465  by EP_X0FF
 Mon Feb 06, 2012 3:06 pm
Hello,

perhaps you can show something that already implemented to get more valuable feedback?
with a database of all needed offsets of the opaque structures for most versions
Something automated (instead of total fingerprinting) would be more interesting.

Classes? Or pseudoclasses? Personally I don't like classes in case of drivers or system programming in a whole.

And mainly, is there x64 support?
 #11468  by xdeadcode
 Mon Feb 06, 2012 7:16 pm
Hi AmrThabet,

Well from one point of view any kind of known techniques does not give any 'valuable' input for rootkits, since good rootkit is one that can't be detected by existing soft and in most cases it uses some unknown techniques for hiding or self defending.
On the other hand in most rootkit cases it also need some 'standard' ways for itself and this can save a lot of time. Also this kind of a classes/frmk can be useful in any kind of system dev, so summarizing give us this code :D

Cheers.
 #11508  by AmrThabet
 Wed Feb 08, 2012 1:30 pm
Thanks everyone for your reply

I'm still in the development of the framework and I'm still sharing the idea to see what do you think about the main idea ... and how we could develop it to make everyone happy

First I want to say, it's not related with rootkits for malware ... I mean the kernel-mode applications that gives you the total control of the OS ... could be for firewalls or antiviruses or parental control ... or could be for penetration testing like IP spoofing or KernelBot or sniffer or anything like that.Like Ollybone ... it's in my opinion a rootkit ... it uses the Kernel-Mode to do things that he can't do in the user-mode.

The second is, I saw many kernel-mode developers waste their time on writing a standard code like in the Filesystem Filters or NDIS or TDI or anything ... and face dozens of bluescreens and all of these things and don't have time for the main goal of their rootkit. or they take the FsFilter code that created by microsoft or NDIS passthru from the WDK to modify it and begin using it. this raise another problem ... what if they decide to use the two with each other (FsFilter and Passthru) or they need to monitor the keystroke with a FileSystem Filter ... how they will modify the FsFilter of Microsoft. so they face a huge problem.

So,a development framework could solve the problem. they will automate all this shit standard code for you so no waste of time. If you need to use a new technique or use a standard technique for something ... you can focus on your needs ... spend all your time on the main goal of your rootkit and waste time any more.
Also, the framework will solve the problem of using Filesystem filter with keystroke monitor ... the two receives IRPs in the major functions. but you have a dispatcher for these IRPs. there's a dispatcher detects which thing this IRP related to ... if this IRP related to FsFilter ... so it will call to the appreciate function for handling the IRP and so on. so it's very easy to use Key Monitor with Sniffer with Filesystem Filter with more than one control device driver without any interference :)

The Third thing, after rootkit.com went down ... I decided to build a new community for rootkits ... help the beginners with articles and an easy to use Framework and also help the Pentesters with customizable rootkits like metasploit for exploits.
I need to create an application contains all the open source rootkits inside and recollect them again (after rootkit.com it becomes hard to see the open source rootkits in the internet). and create a community for rootkit developers to learn from each other and raise their creativity. I really hope to see new techniques like the Art of Bootkits or anything ... and I really hope to collect all of these creative developers and all of these open source rootkits in one community and one application. Don't waste your time again in Standard code, everything becomes easy ... just create and develop.

is it support x64? still not ... you can make it support ... the application is not for me ... for all developers ... if anyone need to help his friends in the rootkit field .. just join and add to it.

is it a demo? still under development ... still in the middle ... I need your advices to develop it as you need :)

That's an example code of a rootkit implemented in it (just an example)
Code: Select all
//just shit namespaces :(

using namespace RDF;
using namespace RDF::FileManager;
using namespace RDF::RegistryManager;


SSDTDevice* Amr;                          //a Device Class used for SSDT Hooking
FileFilterDevice* Amr2;                   //a Device That used in Filesystem Filters

PDRIVER_OBJECT DriverObject;              //your driver

typedef NTSTATUS ZwSetValueKeyPtr(
            IN HANDLE KeyHandle,
            IN PUNICODE_STRING ValueName,
            IN ULONG TitleIndex OPTIONAL,
            IN ULONG Type,
            IN PVOID Data,
            IN ULONG DataSize
            );
            
ZwSetValueKeyPtr* oldZwSetValueKey;


int _cdecl MJCreate(FileFilterDevice* FFDevice,__in PDEVICE_OBJECT DeviceObject,__in PIRP Irp); // a decleration for a the Create Major Function of the Filesystem Filter

//------------------------------------------------------------------
NTSTATUS newZwSetValueKey(IN HANDLE KeyHandle,IN PUNICODE_STRING ValueName,IN ULONG TitleIndex OPTIONAL,IN ULONG Type,IN PVOID Data,IN ULONG DataSize)
{   
    DbgPrint("Yes %wZ\n",ValueName);
    return (*oldZwSetValueKey)(KeyHandle,ValueName,TitleIndex,Type,Data,DataSize);
}
//------------------------------------------------------------------

NTSTATUS Driver::DriverMain(IN PDRIVER_OBJECT pDriverObject,IN PUNICODE_STRING theRegistryPath){
      DbgPrint("HideProc DriverEntry Called\n");
      DriverObject = pDriverObject;
      
      //Creating the class in memory and add it to the Driver chain of the devices inside it.
      Amr2=(FileFilterDevice*)CreateClass(sizeof(FileFilterDevice));
      Amr2->Initialize(this);
      AddDevice(Amr2);
      
      Amr=(SSDTDevice*)CreateClass(sizeof(SSDTDevice));
      Amr->Initialize(this);
      AddDevice(Amr);
      
      //Create The Control Devices ... optional (you could have more than one control device for your driver)
       
      Amr->CreateDevice(L"\\Device\\rootkit03",L"\\DosDevices\\rootkit03");
      Amr2->CreateDevice(L"\\Device\\rootkit02",L"\\DosDevices\\rootkit02");
      
      int old = Amr->GetRealAddress(L"ZwSetValueKey");             //Get the Address of this function from the SSDT
      DbgPrint("Real Address : 0x%x",old);
      SetValue(oldZwSetValueKey,old);                              //save the old address 
      Amr->AttachTo(L"ZwSetValueKey",(DWORD)newZwSetValueKey);     //change the address of this function in the SSDT Table (HOOKED)

      
      Amr->UserComm.Write(1,STATUS_SUCCESS,"I'm the Kernel Mode",sizeof("I'm the Kernel Mode"));    //very easy to write to the User-Mode :)
      
      Amr2->BeginHooking(true);                                    //Hook the whole volumes in the Filesystems and the Newly Attached devices (you have the ability 
                                                                   //to attach to one of them or two ... you have the ability to cutomize
      
      // Set the Create Major Function for filesystem Filter to our function.
      SetValue(Amr2->FilteredMajorFunction[IRP_MJ_CREATE].PreModification,MJCreate);
      
      //this code uses the FileManager to read file from the disk (like user-mode applications :) )
      //don't worry about IRQL ... it creates a system thread to handle the read and write ... and your thread will wait until your read or write finish
      
      FileToRead* readfile = (FileToRead*)CreateClass(sizeof(FileToRead));
      NTSTATUS ntStatus = readfile->open(L"\\DosDevices\\c:\\KeyLog2dfdfdf.txt");
      if (ntStatus != STATUS_SUCCESS)DbgPrint("02.cpp : Failed To ReadFile");
      else DbgPrint("02.cpp : ReadFile Opened Successfully");
      char* data;
      DWORD size;
      readfile->read(data,size);
      DbgPrint("FileData at : %x ... and FileSize is : %x",data,size);
      DbgPrint("Text: %s",data);
      readfile->close();
      
      //And that's for writing a file :)
      FileToWrite* s = (FileToWrite*)CreateClass(sizeof(FileToWrite));
      s->open(L"\\DosDevices\\c:\\NewData.txt",false);
      s->write("I'm Happy ... From KernelMode\n",strlen("I'm Happy ... From KernelMode\n"));
      s->close();
      
      //Reading a registry entry ... very easy. 
      char* buf = RegRead(L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion",L"ProgramFilesDir",size);
      //if(buf != 0)DbgPrint("Registry Read : %x",buf);
      
      s = (FileToWrite*)CreateClass(sizeof(FileToWrite));
      s->open(L"\\DosDevices\\c:\\Reg.txt",false);
      s->write(buf,size);
      s->close();
      
      //Write to registry 
      RegWrite(L"\\Registry\\Machine\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion",L"AmrThabet",(char*)L"AmrThabet",REG_SZ,strlen("AmrThabet")*2);
      return STATUS_SUCCESS;
}

VOID Driver::DriverUnload()
{
    Amr->Detach();
}
int _cdecl MJCreate(FileFilterDevice* FFDevice,__in PDEVICE_OBJECT DeviceObject,__in PIRP Irp)
{
    PFILE_OBJECT pFileObject = IoGetCurrentIrpStackLocation(Irp)->FileObject;
    DbgPrint("File Created !!!");         
    DbgPrint("%wZ\n", &pFileObject->FileName);
    return FILTER_SKIP;
}
I waiting for your replies :)
 #11520  by EP_X0FF
 Thu Feb 09, 2012 7:51 am
I don't know how it looks for everyone else, but for me it looks like a mess of C++. Perhaps you should consider more deeper level of abstraction in your classes. Also it does not looks like "rootkit" framework, but more like driver development framework + set of simple system hacks. Additionally you can forget about hooking on x64. Modern rootkits do not have to use it.
 #11522  by Brock
 Thu Feb 09, 2012 10:46 am
Just my opinion, not saying it's correct at all, but... this looks to me like that of a framework solely for simplifying common kernel mode tasks and not so much advanced operations for such a "framework" to be useful for automating lower level programming services. There already exists enough "wrappers" and higher-level layers of abstraction which are publicly available, perhaps not unified yet they still exist individually as separate packages. Your framework must provide something that current frameworks do not in order for it to be deemed desirable
 #11527  by AmrThabet
 Thu Feb 09, 2012 1:00 pm
It's just a simple fast example ... about OOP ... you can inherit the classes and create classes ... you can use more OOP

Thanks for all your valuable comments..

So,what do you think? how I could create a real "framework" for rootkits? could you give me advices?
 #11528  by Brock
 Thu Feb 09, 2012 1:04 pm
More encapsulation of underlying objects such as (DISK) etc. Perhaps, better foundation classes with more available methods? (I) Think that you're on to something nice, but this depends on what you're exposing essentially. Regardless, good job for what it's worth ;) By the way, I'd focus on ring0 <-> ring3 communication as well ;)