好吧,我们给出下面的代码更改变量的值:通过堆栈
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <string.h>
#include "callstack.h"
#include "tweetIt.h"
#include "badguy2.c"
static char *correctPassword = "ceriaslyserious";
char *message = NULL;
int validateSanity(char *password) {
for(int i=0;i<strlen(password);i++)
if(!isalpha(password[i]))
return 0;
unsigned int magic = 0x12345678;
return badguy(password);
}
int validate(char *password) {
printf("--Validating something\n", password);
if (strlen(password) > 128) return 0;
char *passwordCopy = malloc(strlen(password) + 1);
strcpy(passwordCopy, password);
return validateSanity(passwordCopy);
}
int check(char *password, char *expectedPassword) {
return (strcmp(password, expectedPassword) == 0);
}
int main() {
char *password = "wrongpassword";
unsigned int magic = 0xABCDE;
char *expectedPassword = correctPassword;
if (!validate(password)) {
printf("--Invalid password!\n");
return 1;
}
if (check(password, expectedPassword)) {
if (message == NULL) {
printf("--No message!\n");
return 1;
} else {
tweetIt(message, strlen(message));
printf("--Message sent.\n");
}
} else {
printf("--Incorrect password!\n");
}
return 0;
}
我们应该欺骗main
发送到使用功能badguy
鸣叫。在badguy中,我们与前面的问题有一个偏差,这是main
中password
的声明与传递给badguy
的参数之间的差异。我们已经指示我们使用此偏移量来查找主要的correctPassword
和password
的地址,并操作password
至correctPassword
中的值,所以当密码检查发生时,它被认为是合法的。我在计算如何使用此偏移量来查找地址并从那里继续时遇到一些问题。
不,你不应该,投票是匿名的,对问题的评论评论被认为是噪音。今后请不要这样做。 – casperOne
http://en.wikipedia.org/wiki/Call_stack也许检查调用堆栈的结构可能会有所帮助。 :) 这些信息都在调用堆栈中,所以只需找到正确的偏移量即可获得所需的信息。 –
在main中没有获得原始'password'的值只是从'badguy'口令中减去我的偏移量?这似乎并没有提供正确的结果,尽管这对我来说合乎逻辑。 –