Skip to content

Commit db73bbf

Browse files
committed
added 2 more labs as gitmodules
* also improved hooking section
1 parent 8bcd7a1 commit db73bbf

File tree

8 files changed

+26
-16
lines changed

8 files changed

+26
-16
lines changed

.gitmodules

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,9 @@
44
[submodule "Section 1 - Basics/example_projects/lab-reversing-structures"]
55
path = Section 1 - Basics/example_projects/lab-reversing-structures
66
url = https://github.com/kotae4/lab-reversing-structures
7+
[submodule "Practical Experience - Labs & POCs/lab-esp-and-aimbot"]
8+
path = Practical Experience - Labs & POCs/lab-esp-and-aimbot
9+
url = https://github.com/kotae4/lab-esp-and-aimbot
10+
[submodule "Section 2 - Hooking/example_projects/lab-hooking-testbed"]
11+
path = Section 2 - Hooking/example_projects/lab-hooking-testbed
12+
url = https://github.com/kotae4/lab-hooking-testbed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,20 +122,20 @@ Example projects may be included in each section, but they are also linked to in
122122

123123
### (Work-In-Progress) Example Projects / Labs ###
124124

125-
1. Viewing data structures in memory and in a disassembler
126-
2. Basic manual mapper
127-
3. Aimbot + ESP quick rundown for assault cube
125+
- [x] Viewing data structures in memory and in a disassembler
126+
- [x] Basic manual mapper
127+
- [x] Aimbot + ESP quick rundown for assault cube
128128
<ol type="a">
129129
<li>internal and maybe external?</li>
130130
</ol>
131-
4. Aimbot + ESP quick rundown for an old quake engine game
132-
5. Aimbot + ESP quick rundown for a ue4 game
131+
- [ ] Aimbot + ESP quick rundown for an old quake engine game
132+
- [ ] Aimbot + ESP quick rundown for a ue4 game
133133
<ol type="a">
134134
<li>GObjects + GNames = GG</li>
135135
</ol>
136-
6. Aimbot + ESP quick rundown for a unity game
136+
- [ ] Aimbot + ESP quick rundown for a unity game
137137
<ol type="a">
138138
<li>mono backend vs il2cpp backend</li>
139139
</ol>
140-
7. Aimbot + ESP quick rundown for a cryengine (5?) game
141-
8. Converting assault cube hack to kernel-mode
140+
- [ ] Aimbot + ESP quick rundown for a cryengine (5?) game
141+
- [ ] Converting assault cube hack to kernel-mode

Section 1 - Basics/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Good resources for learning more: Windows Internals book, Intel Software Develop
5656
This guide assumes you have prior programming experience dealing with pointers. Don't sweat it if you mess them up sometimes. Everyone does. I mess up pointer arithmetic at least once per project. You should be comfortable with this exercise: given an address (eg; 0x410000) read the first 4 bytes. Bonus points if you can read the first 4 bits.
5757

5858
## x86 Assembly ##
59-
CPUs read bytes. Bytes are the words of their language. But just like our words have meaning, so to must their bytes. That is where 'instruction sets' come in.
59+
CPUs read bytes. Bytes are the words of their language. But just like our words have meaning, so too must their bytes. That is where 'instruction sets' come in.
6060
The x86 instruction set is the most common instruction set used by consumer CPUs.
6161
The x86 assembly *language* is a set of mnemonics that translate to x86-encoded instruction bytes.
6262
The human-readable `mov eax, 1` will compile to bytes `B801000000` and that's what will be stored on disk and eventually parsed by the CPU if executed.

Section 2 - Hooking/README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,25 @@ The art of making someone else's code execute your code instead.
55
## Inline Hooking ##
66

77
An inline hook is one in which a jmp to your hook function has been written over some instruction bytes in the target function (usually at the very top of the target function).
8-
Because you're overwriting instruction bytes that may be executed at any time you'll need to first suspend all threads other than your own. Furthermore, because CPUs like to cache things, it's also a good idea to flush the instruction cache after you've written your jmp instruction. Lastly, remember that bytes in the .text section usually have only RX page protection, so you'll need to modify the page protection to RWX, write your jmp, then set the page protection back to its original value.
9-
Furthermore, you should be aware that not all jmp instructions are the same. There are near and far jmps which have the further modifier of relative, or absolute indirect, or absolute. If you're working with a 32 bit address space, a near relative jmp should be fine, but if not then you should make sure that the distance between your target function and hook function isn't greater than the max offset of a near relative jmp. This is one case where you'll definitely want to refer to the intel SDM to find the specifics of each jmp encoding.
8+
Because you're overwriting instruction bytes that may be executed at any time you'll need to first suspend all threads other than your own, and, if their instruction pointer is within the address range that you're overwriting you'll need to relocate them (you'll need to copy the original bytes somewhere and point it to those at the same relative offset). Furthermore, because CPUs like to cache things, it's also a good idea to flush the instruction cache after you've written your jmp instruction. Lastly, remember that bytes in the .text section usually have only RX page protection, so you'll need to modify the page protection to RWX, write your jmp, then set the page protection back to its original value.<br>
9+
Additionally, you should be aware that not all jmp instructions are the same. There are near and far jmps which have the further modifier of relative, or absolute indirect, or absolute. If you're working with a 32 bit address space, a near relative jmp should be fine, but if not then you should make sure that the distance between your target function and hook function isn't greater than the max offset of a near relative jmp. This is one case where you'll definitely want to refer to the intel SDM to find the specifics of each jmp encoding.
1010

11-
### TO-DO ###
12-
Image of before and after control flow
11+
| ![inline-hook-with-trampoline](guide_images/inline-hook-with-trampoline.png) |
12+
|:--:|
13+
| <sub>Image: Before and after of an inline hook with trampoline function shown</sub> |
1314

1415
## Trampolines ##
1516

1617
Often you'll want to call the original function at some point in your hook function, but you'll find if you do that you'll eventually hit a stack overflow exception. Your hook calls your target which is hooked so execution winds back up in your hook which calls your target which... eventually, all those calls will exhaust the stack and generate that exception.
1718
So you have two options: either unhook your target function, call it, then re-hook it, or simply write a 'trampoline' and call your trampoline.
1819
A trampoline is simply a copy of the instructions that your hook overwrote in the target function followed by a jmp to the position in the target function just past your hook. This allows the full target function to execute without going into the infinite loop of jmp'ing to your hook.
19-
Of course, because instructions are just encoded bytes, how can you know which bytes comprise a full instruction? Or rather, where does one instruction end and the next begin? This is where you'll need to employ a disassembly engine. Popular ones include `hde` and `capstone`. You'll feed the disassembly engine the bytes and it'll feed you the instructions. With that, you should have all you need to write your trampoline. Again, though, make sure you're using the write jmp encoding in your trampoline.
20+
Of course, because instructions are just encoded bytes, how can you know which bytes comprise a full instruction? Or rather, where does one instruction end and the next begin? This is where you'll need to employ a disassembly engine. Popular ones include `hde` and `capstone`. You'll feed the disassembly engine the bytes and it'll feed you the instructions. With that, you should have all you need to write your trampoline. Again, though, make sure you're using the right jmp encoding in your trampoline.
2021

2122
Ah, this was written with inline hooks in mind but trampolines can be used for other types of hooks too. For example, if you have a hardware breakpoint set on the first instruction of the target function, your trampoline would need to have a copy of that instruction and then jmp to the second instruction of the target function. This will, again, allow you to call the original target function without it executing your hook function.
2223

23-
### TO-DO ###
24-
Image of before and after control flow of an inline hook, including the trampoline
24+
| ![inline-hook-with-trampoline-controlflow](guide_images/inline-hook-with-trampoline-controlflow.png) |
25+
|:--:|
26+
| <sub>Image: Control flow of an inline hook with trampoline</sub> |
2527

2628
## Virtual Method Table Hooking ##
2729

Loading
Loading

0 commit comments

Comments
 (0)