Похожие презентации:
Fun With Thread Local Storage (part 3)
1.
Fun With Thread Local Storage (part 3)Peter Ferrie
Senior Anti-virus Researcher
2 July, 2008
1
2.
You Can Call Me AlThread 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.
Empty!TLS is present
(size doesn’t matter)
Peter Ferrie, Microsoft Corporation
6
7.
Empty!Callback pointer
Peter Ferrie, Microsoft Corporation
Callback array
7
8.
Empty!So the search moves to the callbacks,
of which there is only one, but it looks peculiar.
It’s not a virtual address.
Peter Ferrie, Microsoft Corporation
8
9.
The One and OnlyPeter Ferrie, Microsoft Corporation
9
10.
Imported TLS callbacksWe know that the TLS callback array can be altered at runtime.
We know that the TLS callbacks can point outside of the image.
Now we are looking at a new way to achieve that.
Imports are resolved before TLS callbacks are called.
So TLS callbacks can be imported addresses!
Let’s check the import table.
Peter Ferrie, Microsoft Corporation
10
11.
The Search Goes OnTLS3.DLL
Peter Ferrie, Microsoft Corporation
11
12.
The Search Goes Ona
Peter Ferrie, Microsoft Corporation
12
13.
The Search Goes OnSo the search moves to TLS3.DLL,
and the mysterious function called ‘a’.
Peter Ferrie, Microsoft Corporation
13
14.
‘A’ functionPeter Ferrie, Microsoft Corporation
14
15.
The ‘Aha’ MomentSo that’s how it’s done.
If we let it run…
Peter Ferrie, Microsoft Corporation
15
16.
Surprise!Peter Ferrie, Microsoft Corporation
16
17.
Not OKThe code runs.
Peter Ferrie, Microsoft Corporation
17
18.
Really Not OKJust a little something to add to the workload.
Peter Ferrie, Microsoft Corporation
18