killchain-compendium/exploit/buffer_overflow/docs/amd64.md

57 lines
1.2 KiB
Markdown
Raw Normal View History

2021-08-23 01:13:54 +02:00
# amd64
* `rax` return value, caller saved.
2021-11-08 21:24:23 +01:00
* `rbx` base register (used for mem basepointer)
* `rcx` counter register
2021-08-23 01:13:54 +02:00
* `r10`, `r11` are caller saved.
* `rbx`, `r12`, `r13`, `r14` are callee saved
2021-11-08 21:24:23 +01:00
* `rdx` data register
2021-08-23 01:13:54 +02:00
* `rbp` is also callee saved(and can be optionally used as a frame pointer)
* `rsp` is callee saved
2021-11-08 21:24:23 +01:00
* `rip` next instruction pointer
2021-08-23 01:13:54 +02:00
## Function argument registers
* `rdi`,`rsi`,`rdx`,`rcx`,`r8 `,`r9 `, called saved.
* Further function args are stored inside its stack frame.
## Overwriting Variables and Padding
* Overwrite an atomic variable behind a buffer
```C
int main ( int argc, char ** argv ) {
int var = 0
char buffer[12];
gets(buffer);
[...]
}
```
* Stack layout
```
Bottom
+------------------+
2021-11-08 21:24:23 +01:00
| Saved registers |
2021-08-23 01:13:54 +02:00
+------------------+
| int var |
+------------------+
| char buffer [11] |
| ... |
| ... |
| ... |
| char buffer [0] |
+------------------+
| char ** argv |
+------------------+
| char argc |
+------------------+
Top
```
* Watch out! I.e., a 12 byte array is padded to system memory allocation size.
```
+-------------+----+
|12 byte array| 4b |
+-------------+----+
0 12 16 byte
```