Thursday, February 1. 2007Loading drivers and Native applications from kernel mode, without touching registry
"How to load driver without touching registry from kernel mode", this is asked almost always.Today,
I will give you an insight into how Windows loads its driver and then will document a new method to load a driver without touching registry. This is required because even if you exploit kernel vulnerabilities, you still cannot load any driver because almost all existing Antivirus solutions hijack the NTOSkrnl API's ( which let you write to specific registry locations, load drivers etc). The first method to load driver is given below: Windows NT loads drivers using the following function ZwLoadDriver. Its declaration is as follows: NTSTATUS ZwLoadDriver (IN PUNICODE_STRING DriverServiceName); DriverServiceName: Pointer to a counted Unicode string that The Second Method is given below: After Windows 2000 start's up, It starts loading the special driver It actually loads by the following kernel API ZwSetSystemInformation. This API is used to set system information such as page file, loads the above driver, file cache( information working set) etc. It is actually implemented as follows: ZwSetSystemInformation( it's internally implemented as follows: Switch (SystemInformationClass) Case 1: call entrypoint(driverobject,NULL) ; break ; These 2 are the only known method of loading drivers. Here is the third method. (No antivirus solution currently hijacks it so it is safe). As seen above ZwSetSysteminformation loadimage function to load driver into memory and then calls its entry point. Now we will briefly analyze the parameters and functionality of MmLoadSystemImage MmLoadSystemImage(UNICODE STRING Imagepath, UNICODE STRING prefix optional,UNICODE STRING basename optional, ImagePath is a fully qualified NT style pathname basename is the name system shows after module has been loaded unknown is unknown *imagehandle is the handle to section(it's already referenced, so you will have dereference it at unload) *baseaddress is the address at which image has been loaded in kernel memory This function actually loads the image in memory, resolves imports,loads dependencies, etc. In Windbg,u can find the address of above function using "d MmLoadSystemImage" (of course ,symbols are required) NOTE:- MmLoadSystemimage internally calls and checks the image after Thee MmloadSystemimage works as follows: (PseudoCode) 1) traverse existing module list to check whether it has been alredy loaded 3) try to open file using Zwopenfile,if file cannot be opened,just return with error code So, now we have a function which loads image in memory, but what Here is the assembly code (kernel mode assembly code). it has been __asm { ;below code loads the driver in memory ;paramters as always are passed in reverse mov edi, 0x805c03ae ;MmLoadSystemImage address function on Win XP SP0 English version,(OS and SP dependent data) ;since driver has loaded successfully call its init function both parameters are passed 0 drivernotloaded: ret ; Here data and/or variables are stored ; This is the driver to load including path name ;DosDevices@:hooka.sys length 48 ;it's used to store driver base address ;it is used to store Stack location ;structure used for unicode strings in memory } //asm code ends here NOTE: - These API's or functions are not exported by NTOSKRNL, but That's all about loading a driver from kernel mode without touching registry. Have fun! Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
No comments
The author does not allow comments to this entry
|
NavigationSyndicate This BlogBlog Administration |
