Blizzhackers

Return of the Jedi

* Login   * Register    * FAQ    * Search

Join us on IRC: #bh@irc.synirc.net (or Mibbit Web IRC)


MuleFactory


It is currently Wed May 22, 2013 9:55 pm


All times are UTC [ DST ]





Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Return value
PostPosted: Tue Feb 14, 2012 4:00 pm 
 
User Gold
User Gold
User avatar

Joined: Sat Jul 28, 2007 1:44 pm
Location: Dänemark
I'm trying to call a function with the appropriate arguments inside a process remotely and somehow retrieve the return value which the function outputs. So far i'm capable of calling a function with arguments, like this.


   DWORD read;
   BYTE AsmStub[] = {
   0x68, 00,00,00,00,
   0xB8, 00,00,00,00, // MOV EAX, 0x00
   0xFF, 0xD0,         // Call Eax
   0xC3,
   };
   

   *(DWORD*)&AsmStub[1] = ;
   *(DWORD*)&AsmStub[6] = ;

   LPVOID Address = VirtualAllocEx(handle, NULL, sizeof(AsmStub), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
   WriteProcessMemory(handle, Address, AsmStub, sizeof(AsmStub), &read);
   HANDLE pHandle = CreateRemoteThread(handle, NULL, sizeof(DWORD), (LPTHREAD_START_ROUTINE)Address, NULL, NULL, NULL);
   WaitForSingleObject(pHandle,INFINITE);
   CloseHandle(pHandle);
   VirtualFreeEx(handle, (LPVOID)Address, sizeof(AsmStub), MEM_RELEASE);


I'm aware that the credit for this apporach belongs to someone else.

So how can i achieve the return value?

Top
 Profile  
 Post subject: Re: Return value
PostPosted: Tue Feb 14, 2012 5:40 pm 
 
BHDev
BHDev
User avatar

Joined: Mon Jul 13, 2009 5:13 pm
Location: Denmark
   WaitForSingleObject(pHandle,INFINITE);
   DWORD nReturnCode;
   GetExitCodeThread(pHandle,&nReturnCode); //return value is stored in nReturnCode now.
   CloseHandle(pHandle);

:)

_________________
Autumn, Itemdumper & D2ExtraImage

Top
 Profile  
 Post subject: Re: Return value
PostPosted: Thu Feb 16, 2012 1:20 pm 
 
User Gold
User Gold
User avatar

Joined: Sat Jul 28, 2007 1:44 pm
Location: Dänemark
Thanks for the suggestion, Shaggi :) However, I'm not able to fetch any value from it other than 0xcccccccc which should indicate that the variable is on the stack as declared, but not initialized. So i don't think GetExitCodeThread() is providing any info. Do i need to pass any security attributes to CreateRemoteThread() in order to grab it? I've already loaded the common LoadSeDebugPrivilege() for the process. I'm kinda lost...

Top
 Profile  
 Post subject: Re: Return value
PostPosted: Thu Feb 16, 2012 2:15 pm 
 
BHDev
BHDev
User avatar

Joined: Mon Jul 13, 2009 5:13 pm
Location: Denmark
Thanks for the suggestion, Shaggi :) However, I'm not able to fetch any value from it other than 0xcccccccc which should indicate that the variable is on the stack as declared, but not initialized. So i don't think GetExitCodeThread() is providing any info. Do i need to pass any security attributes to CreateRemoteThread() in order to grab it? I've already loaded the common LoadSeDebugPrivilege() for the process. I'm kinda lost...

After your little stub returns, what remains in eax is what getexitcodethread returns - the value of eax. You are sure your function returns in eax? Ie. not floating point values or something?
Yes, 0xCCCCCCCC usually means uninitialized variables in debug versions (at least from msvc, that is). Therefore you should probably look at your functions signature, and check whether it's correct, it seems like you are messing with the stack. Did you write the function that you are trying to call?

_________________
Autumn, Itemdumper & D2ExtraImage

Top
 Profile  
 Post subject: Re: Return value
PostPosted: Wed Feb 22, 2012 3:22 pm 
 
Moderator
Moderator
User avatar

Joined: Thu Apr 30, 2009 12:31 pm
Location: %scrdir%
just FYI, your asm is wrong, any thread entry has the sig (under 32bit windows):
DWORD __stdcall (void*)

your asm doesn't clean up the void* param pushed to the thread entry, this will probably lead to your thread triggering an exception or such, which is probably why you can't get the exit code

_________________
Learn C++, not Crap++ http://tinyurl.com/so-cxxbooks
Hackito Ergo Sum
Cthulhon: No, I am a dancer. I am in charge of popping and locking.

Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
cron