len
|
0x4000 0001
|
|---|---|
sizeof(item)
|
0x10
|
total_size
|
0x4 0000 0010
|
total_size
|
0x0000 0010
|
/* adapted from https://project-zero.issues.chromium.org/issues/42451651
Windows Kernel bug! */
char *FormatNumber(char *source, short source_len) {
unsigned short dest_size = source_len * 6;
char *dest = malloc(dest_size);
char *p = dest;
for (unsigned short i = 0; < source_len; i += 1) {
*p++ = "0123456789ABCDEF"[*source >> 4];
*p++ = "0123456789ABCDEF"[*source & 0xF];
*p++ = ' ';
source++;
}
}
source_len
|
0x2AAB
|
|---|---|
dest_size
|
0x1 0002
|
dest_size
|
0x0002
|
result: write 8 bytes after buffer
via https://blog.chromium.org/2012/05/tale-of-two-pwnies-part-1.html
void vulnerable() {
int items[100];
int count;
bool success =
try_read_input(&count);
if (!success) { ... }
int bytes = count * sizeof(items[0]);
if (bytes >= sizeof(items)) {
printf("cannot handle that many\n"); return;
}
for (int i = 0; i < count; i += 1) {
if (!try_read_input(&items[i])) {
printf("preature end of input\n"); return;
}
}
process_items(items);
}Q: what first input number?
Q: how to encode return address replacement?
looks like it should detect overflow?
clang 22.1 -O assembly:
missing found_overflow() call!
-fsanitize=undefined:test.c:…: runtime error: signed integer overflow: 2147483646 * 5 cannot be represented in type ‘int’
-ftrapv:Aborted (core dumped)
-fsanitize=undefined or -ftrapv: NO ERROR
in debug mode:
thread 'main' panicked at src/main.rs:1:29:
attempt to multiply with overflow
in release mode:
18446744073709551594
18446744073709551615 20
18446744073709551615==usize::MAX
None Some(30)
18446744073709551594 20
18446744073709551594==usize::MAX-21