Download presentation
Presentation is loading. Please wait.
1
Fun With Thread Local Storage (part 2)
Peter Ferrie Senior Anti-virus Researcher 26 June, 2008 1
2
You Can Call Me Al Thread Local Storage callbacks were discovered in 2000. However, widespread use didn’t occur until 2004. Now, it should be the first place to look for code, since it runs before the main entrypoint. And that can make all the difference… Peter Ferrie, Microsoft Corporation 2
3
Empty! Entry Point Peter Ferrie, Microsoft Corporation 3
4
Empty! C3 RET Peter Ferrie, Microsoft Corporation 4
5
Empty! So the main file does nothing.
If we assume that the structure is normal, then we could check the thread local storage table. Just in case. Peter Ferrie, Microsoft Corporation 5
6
TLS is present (size doesn’t matter) Empty!
Peter Ferrie, Microsoft Corporation 6
7
Callback pointer Callback array Empty!
Peter Ferrie, Microsoft Corporation 7
8
Empty! So the search moves to the callbacks,
of which there is only one... or is there? Peter Ferrie, Microsoft Corporation 8
9
The One and Only Peter Ferrie, Microsoft Corporation 9
10
Maybe DllMain contains something interesting?
Am I Missing Something? CODE: push offset LibFileName ; "tls2" CODE: call j_LoadLibraryA CODE: A mov ds:TlsCallbacksEnd, eax Hmm, LoadLibrary("tls2") Maybe DllMain contains something interesting? Peter Ferrie, Microsoft Corporation 10
11
I Am Missing Something No, that’s not it.
Peter Ferrie, Microsoft Corporation 11
12
Let’s revisit the code:
Take 2 Let’s revisit the code: CODE: push offset LibFileName ; "tls2" CODE: call j_LoadLibraryA CODE: A mov ds:TlsCallbacksEnd, eax Peter Ferrie, Microsoft Corporation 12
13
It’s All About Image It’s the TlsCallBacks extended array trick again.
Q. What value does the new callback contain? A. The DLL’s imagebase. Q. DEP won’t let that run, right? A. … Peter Ferrie, Microsoft Corporation 13
14
Surprise! Peter Ferrie, Microsoft Corporation 14
15
Not OK Of course it will. You just have to ask nicely.
Or take a cue from a driver. Peter Ferrie, Microsoft Corporation 15
16
Chaotic-Evil When the SectionAlignment value is less than 4kb,
the file header is marked Writable and Executable (unless the last section characteristics override it). That turns the ImageBase into code. Peter Ferrie, Microsoft Corporation 16
17
Before So we go from this… Peter Ferrie, Microsoft Corporation 17
18
After To this… Peter Ferrie, Microsoft Corporation 18
19
Presto! Peter Ferrie, Microsoft Corporation 19
20
Just a little something to add to the workload.
Really Not OK Just a little something to add to the workload. Peter Ferrie, Microsoft Corporation 20
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.