Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


Preventing dlls to be injected
Goto page 1, 2, 3  Next
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sat Mar 07, 2009 8:53 pm    Post subject: Preventing dlls to be injected Reply with quote

Can I prevent dlls from being injected into my process?
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sat Mar 07, 2009 8:58 pm    Post subject: Reply with quote

traverse module list and check for what is in there ?

http://msdn.microsoft.com/en-us/library/ms686849(VS.85).aspx
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sat Mar 07, 2009 10:35 pm    Post subject: Reply with quote

there are several methods which have been used in the past to this all have there weakness's

http://www.rootkit.com/blog.php?newsid=640

another method put forth is to travers the PEB find the LoaderLock and pass that handle to RtlEnterCriticalSection.. but that method is i guess controversial and not work mentioning,though it is available on rootkit.com if your interested.

still yet another method would be to hook LdrLoadDll and compare name against list of dll's.. NtCreateSection and again check file name by file handle..im sure theres more hooks you could use..
but failing a hooking method(cause of vista) detection is pretty straight forward..you could use Module32First and Module32Next or ZwQueryInformationProcess and traverse the list's (although this is suseptable to PEB module hiding)its unlikly you will expience that, and detection is pretty simple though none to effective i suppose..

kind regards BanMe..
Back to top
View user's profile Send private message MSN Messenger
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Sun Mar 08, 2009 10:08 am    Post subject: Reply with quote

Just hook LdrLoadDll and check the DLL name. Create a white-list of all the libraries your application will load normally. If the newly loaded DLL is not on that white-list, just return FALSE and set an error like ERROR_ACCESS_DENIED.
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sun Mar 08, 2009 1:01 pm    Post subject: Reply with quote

I hooked ZwOpenProcess via r0... Do I hook LdrLoadDll via r3 or r0?
Back to top
View user's profile Send private message
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Mar 08, 2009 2:19 pm    Post subject: Reply with quote

Hook LoadLibrary.
Back to top
View user's profile Send private message
Slugsnack
Grandmaster Cheater Supreme
Reputation: 71

Joined: 24 Jan 2007
Posts: 1857

PostPosted: Sun Mar 08, 2009 3:37 pm    Post subject: Reply with quote

is ldrloaddll a r3 or r0 api..
Back to top
View user's profile Send private message
rapion124
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Mar 2007
Posts: 1095

PostPosted: Sun Mar 08, 2009 3:40 pm    Post subject: Reply with quote

LdrLoadDll is ring3. It's exported by ntdll.dll.
Back to top
View user's profile Send private message
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sun Mar 08, 2009 3:45 pm    Post subject: Reply with quote

dnsi0 wrote:
Hook LoadLibrary.


Well, do I just hook LoadLibrary for my process for every process?
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Mar 08, 2009 3:46 pm    Post subject: Reply with quote

lets see why dnsio's advice is bad..(pls no offense) just using what you said as stepping stone to explain the matter at hand...:]

lets say you Hook LoadLibraryA...

LoadLibraryA converts the ascii to unicode and calls LoadLibraryW..
so LoadLibraryA is bad, because calling LoadLibraryW directly bypass's you hook.. in fact hooking any ascii function with a unicode counterpart is bad (including Ex functions)..so now were onto LoadLibraryW..which internally calls LoadLibraryExW so hooking LoadLibraryW is not to secure either.. so we must dig deeper into LoadLibraryExW to find a focus point for all (calls) to LoadLibrary(A/W(Ex(A/W)) and this leads us to LdrLoadDll inside LoadLibraryExW.. and this is the reason why i suggested using it..though im sure its probally under a different guise in other Windows versions it should be easily found if one looks Smile

regards BanMe
Back to top
View user's profile Send private message MSN Messenger
dnsi0
I post too much
Reputation: 0

Joined: 04 Jan 2007
Posts: 2674

PostPosted: Sun Mar 08, 2009 4:19 pm    Post subject: Reply with quote

BanMe wrote:
lets see why dnsio's advice is bad..(pls no offense) just using what you said as stepping stone to explain the matter at hand...:]

lets say you Hook LoadLibraryA...

LoadLibraryA converts the ascii to unicode and calls LoadLibraryW..
so LoadLibraryA is bad, because calling LoadLibraryW directly bypass's you hook.. in fact hooking any ascii function with a unicode counterpart is bad (including Ex functions)..so now were onto LoadLibraryW..which internally calls LoadLibraryExW so hooking LoadLibraryW is not to secure either.. so we must dig deeper into LoadLibraryExW to find a focus point for all (calls) to LoadLibrary(A/W(Ex(A/W)) and this leads us to LdrLoadDll inside LoadLibraryExW.. and this is the reason why i suggested using it..though im sure its probally under a different guise in other Windows versions it should be easily found if one looks Smile

regards BanMe


Wow... Your right... Hook the thingy right before kernel mode will hook all the other functions. Yea my advice was crap.
Back to top
View user's profile Send private message
Stylo
Grandmaster Cheater Supreme
Reputation: 3

Joined: 16 May 2007
Posts: 1073
Location: Israel

PostPosted: Sun Mar 08, 2009 4:58 pm    Post subject: Reply with quote

hooking api can be done in you're program or is it must done in kernel mode driver?
cuz i know that you can load the api address into your program and force the api call to jump to some code in your program but it doesn't block it from using it ?!
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Mar 08, 2009 6:05 pm    Post subject: Reply with quote

Hooking or Code redirection comes in many forms especially in usermode
,something like this should be done in usermode..in the "program" itself without the need of a kernelmode driver.. sadly as i am saying this i will tell you its not a full proof method one can load a dll without calling LdrLoadDll..(im pretty sure its not called with ManuelMapping..pls correct me if im wrong) also one can still hook hop it with a detection schema and generalized hook hopping code..so i say if your on XP or lower hook LdrLoadDll NtCreateSection BaseThreadStartThunk(or LdrInitializeThunk) and this should be a somewhat decent tactic to employ..did a lil more digging with symbols loaded and could even going a few steps Further by hooking LdrpLoadDll LdrpMapDll and the ones that looks the most interesting to me LdrpCheckForLoadedDll and LdrpRunInitializationRoutines

regards BanMe

oh forgot about the OP ...
yes sensa just in your process... ;}
Back to top
View user's profile Send private message MSN Messenger
&Vage
Grandmaster Cheater Supreme
Reputation: 0

Joined: 25 Jul 2008
Posts: 1053

PostPosted: Sun Mar 08, 2009 8:32 pm    Post subject: Reply with quote

Ok, so I hooked ZwOpenProcess since you must get the handle of a process to DllInject; CreateRemoteThread, WriteProcessMemory... Correct? But now it also blocks sound for that application Neutral
Back to top
View user's profile Send private message
BanMe
Master Cheater
Reputation: 0

Joined: 29 Nov 2005
Posts: 375
Location: Farmington NH, USA

PostPosted: Sun Mar 08, 2009 9:02 pm    Post subject: Reply with quote

... im lost.. why would you hook ZwOpenProcess to get a handle to the process? i dont picture the Process calling OpenProcess on itself sorry..
if your in the process(be it Dll injection or thread Injection or w/e) you can use a pseudo handle returned GetCurrent Process.. my guess if that you are trying to gloablly hook ZwOpenProcess to prevent the use OpenProcess on your PID.. DarkByte gave example on how to bypass such a move on this site infact.. though i cant remember where i can remember how he said to bypass something like this..pass in a xor PID,0x1337 then somewhere after function prolog place and your hook (for integrity checking if you implement it..) place another hook to rexor the PID back to targeted Process..and to be honest i have no clue about your sound..(maybe its unplugged)

regards BanMe
Back to top
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page 1, 2, 3  Next
Page 1 of 3

 
Jump to:  
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
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites