c - 我有一个像这样的 buffer 溢出分配,我将正确的变量设置为 1 (31) 的 HEX value 仍然没有,我该如何解决这个问题

如何使用 buffer 溢出 exploit 将正确的 value 设置为 1?当我没有传递任何内容时,脾气的 value 是 4D2,它是 1234 的十六进制,但是当我溢出 buffer 时,假设 10 A 后跟 1234 -> AAAAAAAAAA1234 脾气变成 0x34333231,我不不明白这个,有人可以帮忙吗?

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


int main(int argc, char **argv)
{
 volatile int correct = 0;
 volatile int tamper = 1234;
 char buffer[10];

 gets(buffer);

 if(strcmp(buffer, [REDACTED])==0) {
   correct = 1;
 }

 if(tamper!=1234) {
     printf("Alert! You hit the tamper switch!\n\n<!--correct = 0x%08x-->\n<!--tamper = 0x%08x-->\n", correct, tamper);
     exit(0);
 }

 if(correct==1) {
  printf("Login successful.\n\n<b>flag{REDACTED}</b>\n\nThe credentials to access this machine are \n\n<b>user:</b>REDACTED\n<b>password:</b>REDACTED\n");

 } else {
  printf("Sorry, password incorrect.\n\n<!--correct = 0x%08x-->\n<!--tamper = 0x%08x-->\n", correct, tamper);
 }

}

回答1

对于 exploit 这个程序(如果它是一个赋值,它肯定会被正确地编译为在 correct 之前有 buffer)你需要用 int value 1 覆盖正确。

1 的十六进制 value 是 0x1,1234 的十六进制 value 是 0x4D2

堆栈的结构必须是:

________________
       |                |
       |      0x1       |  correct (sizeof(int) = 4)
       |                |
       |________________|
       |                |
       |     0x4D2      |  tamper (sizeof(int) = 4)
       |                |
       |________________|
       |                |
       |                |
       |                |
       |                |
       |    gibberish   |  buffer (10 * sizeof(char) = 10)
       |                |
       |                |
       |                |
       |                |
       |________________|
       |                |
       ..................
       ..................
       ..................

不幸的是,您也必须注意字节顺序:0x1 将作为 0x01000000(x-86 架构)或 0x0100000000000000(x-86_64 架构)在内存中。 tamper 也一样。

注意:如果您不想自己转换 indianness,您可以在 pwntools 库中使用函数 p32p64

另请注意,tampercorrect 中的许多 values 将不可打印。

相似文章

r - 如何获得独家 date 范围?

我想要一个对象,它为我提供从1990-01-01到2021-12-31的每个月(或季度)的date范围,用冒号分隔。例如,在每月的情况下,第一个对象是1990-01-01:1990-01-31,第二个...

随机推荐

最新文章