gpt4 book ai didi

c - 为什么即使我遵循 "Hacking-The art of exploitation"书中的代码也无法使程序崩溃

转载 作者:IT王子 更新时间:2023-10-29 00:34:56 27 4
gpt4 key购买 nike

我正在遵循“Hacking-The art of exploitation”一书中的代码。书中定义的源代码随作者提供的光盘一起提供。我只是编译了预先编写的代码。根据这本书,如果我提供正确的密码,它应该授予我访问权限,如果我提供一个密码错误的大字符串,它也应该授予我访问权限,但它拒绝我。来源确实是如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int check_authentication(char *password) {
int auth_flag = 0;
char password_buffer[16];



strcpy(password_buffer, password);

if(strcmp(password_buffer, "brillig") == 0)
auth_flag = 1;
if(strcmp(password_buffer, "outgrabe") == 0)
auth_flag = 1;

return auth_flag;
}

int main(int argc, char *argv[]) {
if(argc < 2) {
printf("Usage: %s <password>\n", argv[0]);
exit(0);
}
if(check_authentication(argv[1])) {
printf("\n-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
printf(" Access Granted.\n");
printf("-=-=-=-=-=-=-=-=-=-=-=-=-=-\n");
} else {
printf("\nAccess Denied.\n");
}
}

最佳答案

添加:

printf("delta: %td\n", (char *) &auth_flag - password_buffer);

在您的check_authentication 函数中。

如果 delta 为负,则您的程序无法被利用。

否则使用 delta + 4 字符的参数来利用它。

关于c - 为什么即使我遵循 "Hacking-The art of exploitation"书中的代码也无法使程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28680602/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com