Simple PWN - 0x15(Lab - heapmath)
tags: CTF PWN eductf
Version: Ubuntu 20.04
Original Code
1 | |
- It’s a test of
tcache and fastbinbackground, therefore, just execute it directly!!!
Questions
-
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19----------- ** tcache chall ** ----------- char *A = (char *) malloc(0x12); char *B = (char *) malloc(0x30); char *C = (char *) malloc(0x13); char *D = (char *) malloc(0x23); char *E = (char *) malloc(0x20); char *F = (char *) malloc(0x28); char *G = (char *) malloc(0x13); free(B); free(A); free(F); free(C); free(D); free(G); free(E); [chunk size] 0x20: G --> C --> A --> NULL (just send "G --> C --> A --> NULL") [chunk size] 0x30: ? [chunk size] 0x40: ?1
2
3
4
5
6
7
8
9Sol. First, try to compute every char malloc size A → $align(0x12 - 0x8 + 0x10) = 0x20$ B → $align(0x30 - 0x8 + 0x10) = 0x40$ C → $align(0x13 - 0x8 + 0x10) = 0x20$ D → $align(0x23 - 0x8 + 0x10) = 0x30$ E → $align(0x20 - 0x8 + 0x10) = 0x30$ F → $align(0x28 - 0x8 + 0x10) = 0x30$ G → $align(0x13 - 0x8 + 0x10) = 0x20$Then, the sequence of the free char is B→A→F→C→D→G→E, according to FILO ruls(stack)

1
2The sequence of 0x30: E --> D --> F --> NULL The sequence of 0x30: B --> NULL -
1
2
3----------- ** address chall ** ----------- assert( A == 0x563d3e2b72a0 ); F == ? (send as hex format, e.g. "0x563d3e2b72a0")Sol. Just accumulate the size
1
2
3
4
5
6
7A == 0x563d3e2b72a0 B == A + 0x20 == 0x563d3e2b72c0 C == B + 0x40 == 0x563d3e2b7300 D == C + 0x20 == 0x563d3e2b7320 E == D + 0x30 == 0x563d3e2b7350 <font color="FF0000">F == E + 0x30 == 0x563d3e2b7380</font> G == F + 0x30 == 0x563d3e2b73b0 -
1
2
3
4
5----------- ** index chall ** ----------- unsigned long *X = (unsigned long *) malloc(0x60); unsigned long *Y = (unsigned long *) malloc(0x60); Y[8] = 0xdeadbeef; X[?] == 0xdeadbeef (just send an integer, e.g. "8")1
2
3
4
5
6Sol. `X` has $align(0x60 - 0x8 + 0x10) = 0x70$ size of malloc address `Y` has $align(0x60 - 0x8 + 0x10) = 0x70$ size of malloc address In addition these two memory are connected together Thus, `X` has `7*2=14` 8 bytes and `0xdeadbeef` is at the 4th position of Y Therefore, the answer is <font color="FF0000">$14+8=22$</font>
-
1
2
3
4
5----------- ** tcache fd chall ** ----------- free(X); free(Y); assert( Y == 0x563d3e2b7440 ); fd of Y == ? (send as hex format, e.g. "0x563d3e2b7440")Sol. Just minus the size of Y From the last question, we can know that the memory space of
XandYare connected together, in addition, thefdofYpoint toX'sdata section
Thus, the answer is $0x563d3e2b7440 - 0x10 - 0x60 = 0x563d3e2b73d0$ -
1
2
3
4
5
6
7
8
9
10
11----------- ** fastbin fd chall (final) ** ----------- [*] Restore the chunk to X and Y Y = (unsigned long *) malloc(0x60); X = (unsigned long *) malloc(0x60); [*] Do something to fill up 0x70 tcache ... [*] finish free(X); free(Y); assert( Y == 0x563d3e2b7440 ); fd of Y == ? (send as hex format, e.g. "0x563d3e2b7440")Sol. When
$0x563d3e2b7440 - 0x10 - 0x70 = 0x563d3e2b73c0$tcacheis full, the free chunk will be put into other bin, such asfastbin. According to the lecture description offastbinstructure, the answer is
