Переполнение буфера для изменения адреса возврата - PullRequest
0 голосов
/ 24 мая 2018

Мне нужно изменить адрес возврата, чтобы я мог вызвать функцию print_good.Мне нужно значение смещения и шестнадцатеричное значение для хранения, чтобы сделать это.Смещение, которое я вычислил с помощью obj, равно 0xcd, которое было получено 0x40074e (функция put, который, я считаю, печатает, попробуйте снова) минус 400686 (адрес функции print_good, которую я хочу вызвать).Шестнадцатеричное значение, которое я считаю правильным, равно 400686, которое является адресом значения print_good.Помещение полученного значения смещения и полученного шестнадцатеричного значения не дает правильного ответа.

Я почти уверен, что шестнадцатеричное значение равно 0x400686, но поправьте меня, если я ошибаюсь.Значение смещения, которое я считаю, может быть отключено.

Мне дали код и исполняемый файл.Мне нужно найти пароль, который является значением смещения и шестнадцатеричным значением.Я получил адреса с помощью objdump и посмотрел его код.

Если вы хотите попробовать сами, вот файл для загрузки исполняемого файла: Исполняемый файл: https://www.mediafire.com/file/disui6pwcb55ing/Ch3_07_CanaryBypass

Код c: https://www.mediafire.com/file/yu3j3dxg476qy8c/Ch3_07_CanaryBypass.c

Код c, написанный здесь:

#include <stdio.h>
#include <signal.h>
#include <stdlib.h>
#define USERDEF 30

char msg[] =
"Stack canaries and non-executable stacks make stack exploitation difficult. Such\n"
"techniques, however, do not protect against return-oriented programming where\n"
"only the return addresses on the stack are targeted.  In this level, you control\n"
"a single write into a vulnerable buffer in the function prompt_user.  Overflow\n"
"the buffer to modify the return address beyond the stack canary so that it\n"
"points to a function of your choice.  The level will prompt you with an offset\n"
"(in decimal) from the beginning of the buffer that will be written into followed\n"
"by a hexadecimal value that will be written there (e.g. scanf(\"%d %x\");).\n"
"The program will then write the hexadecimal value to a location computed\n"
"using the offset.  To determine how close you are, examine the pointer\n"
"being used to write into the stack and how far away it is from the value\n"
"of $rsp when the retq instruction at the end of prompt_user is reached.\n\n";

void print_good() {
    printf("Good Job.\n");
    exit(0);
}

void print_msg() {
    printf("%s",msg);
}

void prompt_user() {
    char buffer[30];
    int offset;
    char *user_addr;
    char **over_addr;
    printf("Enter the password: ");
    scanf("%d %lx", &offset, (unsigned long *) &user_addr);
    over_addr = (char **) (buffer + offset);
    *over_addr = user_addr;
}

int main(int argc, char *argv[]) {
    print_msg();
    prompt_user();
    printf("Try again.\n");
    return 0;
}
...