A forum for reverse engineering, OS internals and malware analysis 

Forum for discussion about kernel-mode development.
 #9940  by rkhunter
 Mon Nov 28, 2011 12:19 am
In ring0 if you need read sectors, use SRB packets and IRP_MJ_SCSI request to disk port driver (the lowest level).
TDL has a lot of versions to counteract the low-level reading sectors. These methods have changed many times since the newly added detections. Look TDL history at corresponding topics. Moreover, each av-product solves this problem in its own way (from truly detection, ending heuristic methods).
 #9941  by Tigzy
 Mon Nov 28, 2011 6:26 am
Thanks for the pointers RKHunter ;)

What is SRB paquets? I can't find any reference on it on Google.
Do you have some documentation or maybe code snippets available?

EDIT: To send specific IRP request, my driver need to be filter driver? Or this can be done from any driver ?
Last edited by Tigzy on Mon Nov 28, 2011 6:30 am, edited 1 time in total.
 #9942  by EP_X0FF
 Mon Nov 28, 2011 6:29 am
Tigzy wrote:Thanks for the pointers RKHunter ;)

What is SRB paquets? I can't find any reference on it on Google.
Do you have some documentation or maybe code snippets available?
http://msdn.microsoft.com/en-us/library ... s.85).aspx

for examples see WDK
 #9948  by Tigzy
 Mon Nov 28, 2011 10:22 am
If I'm right, all I need to do is

- Create and allocate IRP with IoBuildDeviceIoControlRequest
- Send it down to the disk driver with IoCallDriver
- Get the IRP when returns and read it

Is this true?
 #9952  by Vrtule
 Mon Nov 28, 2011 11:23 am
There were leaked source code of an antirootkit tool some time ago. If I remember correctly, it was clone of IceSword and thee were also code responsible for low-level disk access. I can search my hard drive and upload the source, when I get home.
 #9953  by EP_X0FF
 Mon Nov 28, 2011 11:27 am
Vrtule wrote:There were leaked source code of an antirootkit tool some time ago. If I remember correctly, it was clone of IceSword and thee were also code responsible for low-level disk access. I can search my hard drive and upload the source, when I get home.
It's KsBinSword IceSword clone.

http://www.kernelmode.info/forum/viewto ... word#p4052
 #9956  by Tigzy
 Mon Nov 28, 2011 1:29 pm
Hello again.

Seems that little code works!
I guess this isn't powerful, but this is a beginning...

What about TLD? is it strong enough?
Code: Select all
void readSector()
{
	UNICODE_STRING	diskdevice;
	PFILE_OBJECT	pFileObj = NULL;
	PDEVICE_OBJECT	pDevObj  = NULL;
	PIRP			pIrp = NULL;
	IO_STATUS_BLOCK	ioStatus;
	NTSTATUS		status, returnStatus;
	LARGE_INTEGER	lDiskOffset;
	KEVENT			Event;
	CHAR			*sBuf; //Buffer
	SIZE_T			size = 512; //Sector size
	int 			i = 0;

	
	RtlInitUnicodeString(&diskdevice, L"\\Device\\Harddisk0\\DR0");
	
	// Get device object
	status = IoGetDeviceObjectPointer(&diskdevice, FILE_ALL_ACCESS, &pFileObj, &pDevObj);
	
	if (!NT_SUCCESS(status)) 
	{
		DbgPrint("IoGetDeviceObjectPointer Failed\n");
	} 
	
	else 
	{
		DbgPrint("IoGetDeviceObjectPointer Succceded");
		lDiskOffset.QuadPart = 0;
		
		// Allocate buffer
		sBuf = ExAllocatePool(NonPagedPool, size);		
		if (!sBuf) 
		{
			ObDereferenceObject(pFileObj);
			DbgPrint("Not enough ressources\n");
			return STATUS_INSUFFICIENT_RESOURCES;
		}
		
		KeInitializeEvent(&Event, NotificationEvent, FALSE);
		memset(sBuf, 'C', size);
		
		// Build IRP
		pIrp = IoBuildSynchronousFsdRequest(IRP_MJ_READ, pDevObj, sBuf, size, &lDiskOffset, &Event, &ioStatus);		
		if (!pIrp) 
		{
			ExFreePool(sBuf);
			ObDereferenceObject(pFileObj);		
			DbgPrint("Not enough ressources\n");			
			return STATUS_INSUFFICIENT_RESOURCES;
		}
		
		// Call disk driver
		status = IoCallDriver(pDevObj, pIrp);
		
		// Wait response
		if (status == STATUS_PENDING) 
		{
			DbgPrint("waiting response\n");
			returnStatus = KeWaitForSingleObject(&Event, Executive, KernelMode, FALSE,	NULL);
			DbgPrint("Read status : 0x%x\n", returnStatus);

			// Print buffer
			for (i = 0 ; i < size ; i++)
			{
				DbgPrint("%c", sBuf[i]);
			}
			DbgPrint("\n");
			
			status = ioStatus.Status;
		}
		
		//--- Dereference PFile / free ressources
		ExFreePool(sBuf);
		ObDereferenceObject(pFileObj);
	}
}
mbrDumpGMER.png
mbrDumpGMER.png (20.17 KiB) Viewed 323 times
dumpWithMyCode.png
dumpWithMyCode.png (22.79 KiB) Viewed 323 times
  • 1
  • 2
  • 3
  • 4
  • 5
  • 7