RCE Messageboard's Regroupment   Woodmann.com Swag Woodmann.com Swag Woodmann.com Swag

Go Back   RCE Messageboard's Regroupment > Blogs


To keep track of the posts in all our local blogs, subscribe to this RSS feed

To keep track of new threads (in all forums) of the RCE Messageboard, subscribe to this RSS feed

To keep track of all updates to the Collaborative RCE Tool Library, subscribe to this RSS feed

To get your own (reversing related) blog here, simply login and then click "Post to my Blog" below!


Native Application Development Blog
Old

Code Release page

Posted 09-07-2009 at 10:09 PM by BanMe (BanMe.From.Native_Development)

here is the current server code..minus the addition of the currently not working emulation of CSR_API_MESSAGE.

this is also another release of the client..both downloads below..
Attached Files
File Type: rar SIN32.rar (113.9 KB, 119 views)
File Type: rar affectionate.rar (446.6 KB, 115 views)
BanMe's Avatar
r3p0l3v3d n3v1rd
Views 359 Comments 6 BanMe is offline
Old

Binary-Auditing Solutions.

Posted 09-04-2009 at 12:39 AM by BanMe (BanMe.From.Native_Development)

I am Currently working on the C++ Fundementals,and will be presenting my solutions here. As the Downloads have just been released.. I currently dont have any solutions ready,but I'm working on the PH of Coffee and that solution should be ready tommorow..this will be updated soon with further posts and solutions soon, hopefully I will be able to complete 'most' solutions in code that only uses ntdll,but I know that not 'all solutions' will be allow me to take this route.

If you are also working on this line of learning,
Contact me and maybe we can do it together..

BanMe
BanMe's Avatar
r3p0l3v3d n3v1rd
Posted in Uncategorized
Views 379 Comments 9 BanMe is offline
Old

"Client" Unit Tests(some fun ones..)Indirect RtlCreateUserThread hooking..

Posted 08-29-2009 at 01:41 AM by BanMe (BanMe.From.Native_Development)
Updated 08-29-2009 at 01:51 AM by BanMe

code called before RtlCreateUserThread ..
Code:
if(InitUserHooks(ClientView))
{
	Status = RtlCreateUserThread(NtCurrentProcess(),0,0,0,0,0,(PUSER_THREAD_START_ROUTINE)wtf,0,&PortHandle,&Cid);
}
InitUserHooks..
Code:
BOOL InitUserHooks(PORT_VIEW CodeView)
{
	ULONG Addr_BaseThreadStart = 0;
	ULONG Addr_BaseThreadStartThunk = 0;
	ULONG Addr_LdrInitializeThread = 0;
	ULONG Addr_LdrCallInitRoutine = 0;
	BYTE SigBaseThread[7] = { 0x33,0xED,0x53,0x50,0x6A,0x00,0xE9 };
	BYTE SigLdrInitializeThread[9] = { 0x6A, 0x02, 0xFF, 0x76, 0x10, 0xFF, 0x75, 0xE0, 0xE8 };
	BYTE CodBaseThread[2] = { 0x00,0x00};
	BYTE CodLdrCallInit[5] = { 0x00,0x00};
	NTSTATUS Status = 0;
	ULONG NumOfBytes = 2;
	PVOID pfnOrigin = 0;
	int i;
	GetProcessModules();
	for(i = 0;i<20;i++)
	{
		if(wcscmp((PWSTR)Array_ModName[i], L"ntdll.dll") == 0)
			break;
	}
	Addr_LdrInitializeThread = SigSeek_FindCode((DWORD)Array_ModHandle[i],((DWORD)Array_ModHandle[i]+Array_ModSize[i]),sizeof(SigLdrInitializeThread),(DWORD*)&SigLdrInitializeThread);
	if(Addr_LdrInitializeThread)
	{
		__asm
		{
			mov ebx,[eax+0x9]
			add ebx,eax
			add ebx,0xd
			mov Addr_LdrCallInitRoutine,ebx
		}
	}
	else
	{
		return FALSE;
	}
	for(i = 0;i<20;i++)
	{
		if(wcscmp((PWSTR)Array_ModName[i], L"kernel32.dll") == 0)
			break;
	}
	Addr_BaseThreadStartThunk = SigSeek_FindCode((DWORD)Array_ModHandle[i],((DWORD)Array_ModHandle[i]+Array_ModSize[i]),sizeof(SigBaseThread),(DWORD*)&SigBaseThread);
	if(Addr_BaseThreadStartThunk)
	{
		// extract the address of kernel32.BaseThreadStart() from jmp instruction
		// destination = code location + jump offset + 5
		__asm
		{
			mov ebx, [eax+7]
			add ebx, eax // code location
			add ebx, 6 // 
			add ebx, 5
			mov Addr_BaseThreadStart, ebx
		}
	}
	else
	{
		return FALSE;
	}
	ULONG Hook_LdrCallInitRoutine = ((ULONG)CodeView.ViewBase);
	if(Native_HotPatchAddrEx(Addr_LdrCallInitRoutine,Hook_LdrCallInitRoutine,0x1DEB,1,&pfnOrigin))
	{
		return TRUE;
	}
	return FALSE;
}
Native_HotPatchAddrEx
Code:
bool Native_HotPatchAddrEx(ULONG oldProc, ULONG newProc,WORD Code,ULONG NumOfNop, void**ppOrigFn)
{
	bool bRet = false;
    ULONG oldProtect = NULL;
	ULONG pLongJump = 0;
	ULONG pLongJumpAdr = 0;
	ULONG ProtectSize = 2;
	ULONG ProtectAddr = oldProc;
	BYTE Nop = 0x90;
	if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&ProtectAddr, &ProtectSize, PAGE_EXECUTE_READWRITE, &oldProtect)))
	{
		return bRet;
	}
	WORD *pJumpBack = (WORD*)oldProc;
	__asm
	{
		lea ecx,Code
		inc ecx
		mov al,byte ptr[ecx];
		movzx ecx,al
		cmp ecx,0
		je Failed 
		push ecx
		add oldProc,ecx
		push oldProc
		pop ProtectAddr
		mov ProtectSize,5
	}
	if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&ProtectAddr,&ProtectSize,PAGE_EXECUTE_READWRITE,&oldProtect)))
	{
		return bRet;
	}
	__asm
	{
		pop ecx
		push oldProc
		pop pLongJump
		inc oldProc
		push oldProc		
		pop pLongJumpAdr
		dec oldProc
		sub oldProc,ecx
	 	
	}
	if(*pJumpBack != 0xFF8B)
	{
		__asm
		{
			add oldProc,2
			mov edi,oldProc
			lea esi,Nop
			mov ecx,NumOfNop
			rep movsb
			sub oldProc,2
		}
	}
    *(BYTE*)pLongJump = 0xE9;    // long jmp
    *(ULONG*)pLongJumpAdr = (newProc - oldProc)-0x22;    // 
    *pJumpBack = 0x1beb;        // short jump back -7 (back 5, plus two for this jump)
    if (ppOrigFn)
	{
		*ppOrigFn = ((BYTE*)oldProc);
		bRet = true;
	}
  	//if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&pLongJump, &ProtectSize, oldProtect, &oldProtect)))
	//{
	//	return bRet;
	//}
Failed:
	return bRet;
}
LdrpCallInitRoutine after hooking..
Code:
_LdrpCallInitRoutine@16:
  jmp         _LdrpCallInitRoutine@16+1Dh (7C901193h) 
  nop              
  push        esi  
  push        edi  
  push        ebx  
  mov         esi,esp 
  push        dword ptr [ebp+14h] 
  push        dword ptr [ebp+10h] 
  push        dword ptr [ebp+0Ch] 
  call        dword ptr [ebp+8] 
  mov         esp,esi 
  pop         ebx  
  pop         edi  
  pop         esi  
  pop         ebp  
  ret         10h  
  jmp         01570000
Code in "Shared" Mapped View (originates in server)..
Code:
		XOR ECX,ECX
QSFRA:
		MOV EAX,[ESP+(ECX*0x4)]
		CMP EAX,0x7c900000
		JL IncStack
		CMP EAX,0x7cA00000
		JG IncStack
RDUNOP:
		CMP WORD PTR [EAX],0x406a
		JE FAS
	    SUB EAX,1
		JMP RDUNOP
FAS:
		PUSH EBP
		MOV EBP,ESP
		MOV EAX,0x7c901179
		JMP EAX
IncStack:
		INC ECX
		JMP QSFRA
		ret
code executed after call of RtlCreateUserThread by LdrpCallInitRoutine..

Code:
__DllMainCRTStartupForGS@12:
  mov         edi,edi 
  push        ebp  
  mov         ebp,esp 
  cmp         dword ptr [ebp+0Ch],1 
  je          __DllMainCRTStartupForGS@12+0Bh (7C9222FAh) 
  xor         eax,eax 
  inc         eax  
  pop         ebp  
  ret         0Ch
hmm
Code:
_BaseDllInitialize@12:
  mov         edi,edi 
  push        ebp  
  mov         ebp,esp 
  cmp         dword ptr [ebp+0Ch],1 
  je          _BaseDllInitialize@12+0Bh (7C818A92h) 
  pop         ebp  
  nop              
  nop              
  nop              
  nop              
  nop              
__BaseDllInitialize@12:
  mov         edi,edi 
  push        ebp  
  mov         ebp,esp 
  sub         esp,424h 
  mov         eax,dword ptr [___security_cookie (7C8856CCh)] 
  mov         ecx,dword ptr [ebp+8] 
  push        ebx  
  push        esi  
  push        edi  
  xor         edi,edi 
  mov         dword ptr [ebp-4],eax 
  mov         dword ptr [ebp-424h],ecx 
  mov         dword ptr [ebp-414h],edi 
  mov         eax,dword ptr fs:[00000018h] 
  mov         eax,dword ptr [eax+30h] 
  mov         eax,dword ptr [eax+1D4h] 
  mov         dword ptr [_SessionId (7C8856E4h)],eax 
  mov         dword ptr [_BaseDllHandle (7C885054h)],ecx 
  mov         eax,dword ptr fs:[00000018h] 
  mov         ebx,dword ptr [eax+30h] 
  mov         eax,dword ptr [ebp+0Ch] 
  sub         eax,edi 
  mov         dword ptr [ebp-420h],ebx 
  je          7C81CAF4 
  dec         eax  
  je          __BaseDllInitialize@12+89h (7C8185EDh) 
  dec         eax  
  jne         __BaseDllInitialize@12+61h (7C80C177h) 
  push        edi  
  push        2    
  call        _ConDllInitialize@8 (7C80B777h) 
  test        al,al 
  je          __BaseDllInitialize@12+82h (7C82B7ECh) 
  mov         al,1 
  mov         ecx,dword ptr [ebp-4] 
  pop         edi  
  pop         esi  
  pop         ebx  
  call        @__security_check_cookie@4 (7C8097AAh) 
  leave            
  ret         0Ch
then goes on to deactivate Activation Context, it also leaves Ldr Critical Section..and then finally ZwTestAlert.. which calls the routine of RtlCreateUserThread..hope some of this was 'fun' .. ;p

regards BanMe
BanMe's Avatar
r3p0l3v3d n3v1rd
Posted in Uncategorized
Views 414 Comments 11 BanMe is offline
Old

placing a "hotpatch" where it doesnt belong..

Posted 07-22-2009 at 11:26 PM by BanMe (BanMe.From.Native_Development)
Updated 07-27-2009 at 11:47 PM by BanMe (Updated..to suite my purpose..)

had to work this one out myself..

its nothing to special except that its just more versatile the saks654's function..allowing hotpatchs on non mov edi,edi functions also it provides a method for nopping those pesky leftovers..

I hope you enjoy it

Code:
bool Native_HotPatchAddrEx(ULONG oldProc, ULONG newProc,WORD Code,ULONG NumOfNop, void**ppOrigFn)
{
	bool bRet = false;
    ULONG oldProtect = NULL;
	ULONG pLongJump = 0;
	ULONG pLongJumpAdr = 0;
	ULONG ProtectSize = 2;
	ULONG ProtectAddr = oldProc;
	BYTE Nop = 0x90;
	if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&ProtectAddr, &ProtectSize, PAGE_EXECUTE_READWRITE, &oldProtect)))
	{
		return bRet;
	}
	WORD *pJumpBack = (WORD*)oldProc;
	__asm
	{
		lea ecx,Code
		inc ecx
		mov al,byte ptr[ecx];
		movzx ecx,al
		cmp ecx,0
		je Failed 
		push ecx
		add oldProc,ecx
		push oldProc
		pop ProtectAddr
		mov ProtectSize,5
	}
	if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&ProtectAddr,&ProtectSize,PAGE_EXECUTE_READWRITE,&oldProtect)))
	{
		return bRet;
	}
	__asm
	{
		pop ecx
		push oldProc
		pop pLongJump
		inc oldProc
		push oldProc		
		pop pLongJumpAdr
		dec oldProc
		sub oldProc,ecx
	}
	if(*pJumpBack != 0xFF8B)
	{
		__asm
		{
			add oldProc,2
			mov edi,oldProc
			lea esi,Nop
			mov ecx,NumOfNop
			rep movsb
			sub oldProc,2
		}
	}
    *(BYTE*)pLongJump = 0xE9;    // long jmp
    *(ULONG*)pLongJumpAdr = ((ULONG)newProc)-((DWORD)oldProc);    // 
    *pJumpBack = Code;        // short jump back -7 (back 5, plus two for this jump)
    if (ppOrigFn)
	{
		*ppOrigFn = ((BYTE*)oldProc);
		bRet = true;
	}
  	//if(!NT_SUCCESS(NtProtectVirtualMemory(NtCurrentProcess(),(PVOID*)&pLongJump, &ProtectSize, oldProtect, &oldProtect)))
	//{
	//	return bRet;
	//}
Failed:
	return bRet;
}
This code is highly specialize to deal with the intricies of hot patching function with nop padding only located below the function..not like the last one that patched the nop padding above a function..please take this into account when using it if you can..;P

regards BanMe
BanMe's Avatar
r3p0l3v3d n3v1rd
Posted in Uncategorized
Views 425 Comments 0 BanMe is offline
Old

why Opcode0x90's "dll Injection shield" fails against RtlCreateUserThead

Posted 07-22-2009 at 08:23 PM by BanMe (BanMe.From.Native_Development)
Updated 07-22-2009 at 08:36 PM by BanMe

I've still got alot of bugs to work out in the server..and I need to implement a way to do multiple hooks from the shared section and also develop a way to request new 'plugable code' without deleting the previous plugin loaded into the mapped section..and figure out why after 3 client connections to a "reusable" thread the it mysteriously blows up..

but enough about problems on with this post..

put Simply RtlCreateUserThread does not call Into BaseThreadStartThunk. to remedy this and improve upon opcode0x90's 'Dll Shield' I am placing my hook on LdrpCallInitRoutine which then in turn call's BaseThreadStartThunk (if CreateThread or CreateRemoteThread.)
In the Call to RtlCreateUserThread LdrpCallInitRoutine calls the passed in function directly. so placing a hook here covers CreateThread CreateRemoteThread RtlCreateUserThread NtCreateThread..you get it..

doing this during runtime can prevent all 'injected' threads from executing..placing a hook\breakpoint here 'pre' runtime will capture the 'Main' thread during initialization after tls has executed but w/e..also jmping over the call to ZwTestAlert Will prevent a Thread from being directed to the BaseThreadStartThunk routine.

hehe more fun and research for me

regards BanMe
BanMe's Avatar
r3p0l3v3d n3v1rd
Posted in Uncategorized
Views 442 Comments 8 BanMe is offline
Old

Ideas and concepts: behind the Sin32 Subsystem

Posted 06-27-2009 at 08:31 PM by BanMe (BanMe.From.Native_Development)
Updated 06-27-2009 at 11:38 PM by BanMe

Main Goals of the subsystem is to:

A.utilize resources wisely, reuse threads,make permanent synchronization events work,research by reading and coding and testing and recoding and then retesting..repeat. also making a easily adjustable environment and dynamic environment capable of acting suitable to the user's need without much work by him/her.

B:
Act as either a intercept between Win32 and csrss or as csrss. there are various ways to do this Ill discuss them very lil cause there very well documented everywhere..(books,web,ect..)
but the ways i can think of is

1. replace CsrApiPort with our port handle.
In my opinion this is lame...and incomplete.. but combined with 2..

2. replacing all string ascii and unicode that contain CsrApiPortName in with my PortName.doing it this way has various benefits that should be obvious to some.. if I replace all the Name References then I can become the sole holder of a csrss API port Handle..essentialy like becoming a bottle neck...

This can be done in ntdll by hotpatching or binary modification/wfp bypassing or dynamic conditional runtime hooking..

3. the 3rd way is to become csrss..ie Load Before csrss and the win32 subsystem, similar to the effects of "BootExecue" option but a bit more proactive and we have the chance to do preinitialization of data and apply the Patching Engine's instructions located in the Registry
I would love to hear any of your ideas..other then the ZwRequestWaitReplyPort hook one, that I didnt mention above

C:
Provide a subsystem that uses a Plugable shared section between the client(win32 Process) and the "server" subsystem..
Plugin's include but are not in any way limited to
1. Software BreakPoint Manager

2. Patching Engine capable of generating hookhops to bypass malicious hooks,Function Tree Mapping also to avoid hooks,Dynamic Hotpatching of ntdll functions that allow it, also uses multiple hooking implementations to obtain the same effect but be usable under various circumstances. Hooks can be placed in alot of locations, and the effects can be emulated or directly implemented, emulated by using NtRead/WriteProcessMemory (old school..) or directly implemented by Queueing a APC to a Client Thread currently "listening" and then connect to that thread..this should instantly execute the APC and viola effect achieved. more on this in the up and coming documentation release... sometime in the near to late future..

3. Pre-Runtime Branch Disasmbly. Alot of credits to darawk on that one(no real help from him but his code was all the help I really needed, as im using his IsEndPoint function used in GetFunctionLength,albiet somewhat differently, but still the base is his..

4. Runtime Stack Snapping and Context Capturing... (some code on this in next release of the server) 1.02a

many more plugin are going to be implement..
(currently try to make WinSock work in Native Mode..)

B.2:
Implement a Custom RPC mechanism that is controlable from either a gui or a console application to communicate with both client and server.this can be done by stripping out the HEADER of PORT_MESSAGE and rewrapping it in a Custom structure.. and then create functions the work with the structures..

the plugin framework will have to be implemented for dynamic subsystem behaviors but that feature is secondary now..

C:
lastly is to Provide a stable approach for NT/2k/XP and maybe even 32/64 bit vista,but that requires alot more time, and quadruples the amount of research.., So I am just focusing solely on XP(sp2 ~ sp3)..
BanMe's Avatar
r3p0l3v3d n3v1rd
Posted in Uncategorized
Views 625 Comments 0 BanMe is offline

Just in case...Please update your bookmarks to http://woodmann.cjb.net
Direct link : http://71.6.196.237/forum/

Some Useful Places
Fravia's Searchlores
Fravia's Original Reversing Site
Krobars Collection of tutorials
OllyStuph OllyDbg Resources
A complete searchable archive of the forum in .CHM format is available (updated Jan 3, 2009)
here (25.8 Mb zip)
Please do not ask for cracks, instead read this.

Started 10 May 1999

All times are GMT -5. The time now is 11:40 AM.


Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.