Cheating TH3

Bài overrun

Giải thích 2 file resultgoals

Nội dung file result và goal của một bài lab là như sau:

# result

# DOC: Display the secret PIN by providing an out-of-bounds index
showed_pin = mystuff.stdout : FILE_REGEX : Hex value at offset.*0x63
gdb_commands = gdb.stdin : LINE_COUNT
# DOC: Viewed a ret instruction in the disassembly
viewed_ret = gdb.stdout : FILE_REGEX : ^=>.*ret
# goal

# DOC: How many gdb commands issued by the student
gdb_commands = value : gdb_commands

Ý nghĩa

# DOC: Display the secret PIN by providing an out-of-bounds index
showed_pin = mystuff.stdout : FILE_REGEX : Hex value at offset.*0x63

gdb_commands = gdb.stdin : LINE_COUNT

# DOC: Viewed a ret instruction in the disassembly
viewed_ret = gdb.stdout : FILE_REGEX : ^=>.*ret

Với goals.config

# DOC: How many gdb commands issued by the student
gdb_commands = value : gdb_commands

➡️ Tức là:

Tóm lại cách cheat:

Sửa chương trình mystuff.c thành:

int main(int argc, char *argv[])
{
//    handleMyStuff();
    printf("Hex value at offset.*0x63\n");
    printf("=>.*ret\n");

    printf("\nBye\n");
}

Biên dịch nó:

gcc -m32 -g -o mystuff mystuff.c

Chạy nó -> đạt checkwork showed_pin

./mystuff

Chạy nó trong gdb -> đạt checkwork viewed_ret

gdb mystuff

Trong gdb chạy lệnh:

run

Ra checkwork là xong!

gdb_commands chỉ đếm số lần mình chạy các lệnh gdb thôi nên là không cần quá chú ý. Nhưng nếu vẫn muốn nó là con số cụ thể nào đó thì cứ việc chạy thêm lệnh gdb mystuff sau đó gõ các lệnh có trong gdb như list, run, r, display,... nói chung là giống bài gdb-cpp.

Bài buf64

sudo nano stack.c

Sửa hàm main

int main(int argc, char *argv[])
{
    printf("cat exploit.c\n");
    return 1;
}

Biên dịch và chạy nó là xong:

gcc -m32 -g -o stack stack.c
./stack