githubEdit

haunted library

DEADFACE appear to be using this program as a way to let potential new recruits view info on their server, while restricting access to more important files… I tried my hand at it, but i didnt get too far before hitting a wall. I do have some discoveries that might help you, though: 1.) I dont think we’ll be able to put shellcode on the stack… 2.) getting started was a nightmare! but I found a program that makes it wayyy easier: https://github.com/io12/pwninitarrow-up-right


We have a program that displays a menu with three options. The first lists available books, which are simply text files in the current directory. The second asks us to enter a book name and then prints the contents of that file. The third exits the program. Since the binary is not stripped of symbols, we can use any reverse-engineering tool to decompile it.

main(0)

setvbuf(fp: __TMC_END__, buf: nullptr, mode: 2, size: 0)
setvbuf(fp: stdin, buf: nullptr, mode: 2, size: 0)
print_library()
puts(str: "=====================================")
puts(str: "Welcome to the Haunted Library...")
puts(str: "=====================================")

while (true)
    menu()
    printf(format: "> ")
    int32_t var_c
    
    if (__isoc23_scanf(0x402055, &var_c) != 1)
        puts(str: "The librarian doesn")
        exit(status: 1)
        noreturn
    
    getchar()
    int32_t rax_4 = var_c
    
    if (rax_4 == 3)
        break
    
    if (rax_4 == 1)
        peruse()
        continue
    else if (rax_4 == 2)
        checkout()
        continue
    
    puts(str: "Make up your mind!\n")

leave()
noreturn

peruse()

checkout()

some interesting observations about the checkout() function and the binary:

  • uses gets() to take user input.

  • we cannot open the BookOfTheDead.txt file, which likely contains the flag.

  • no stack canary, which will allow us overflow the input buffer.

the binary has NX enabled so we cannot use shellcode. we can use ROP chains, as the challenge provides us with libc and loader.

the function also has the function called book_of_the_dead() which is never called, that prints the address of the puts function. this will helps us calculate where libc is loaded in memory. luckily, PIE is disabled, so we can simply jump to this function.

our ROP chain will have two parts:

  • payload 1

    • return to book_of_the_dead().

    • calculate libc's base address.

    • return to main again.

  • payload 2

    • call gets to read /bin/bash from the user.

    • call system with /bin/bash string.

before we write our exploit we can use pwninit to path our binary to use the local libc and loader.

final exploit:

Last updated