【问题标题】:How to convert a hex address from a char buffer to be written to memory如何将字符缓冲区中的十六进制地址转换为写入内存
【发布时间】:2015-08-03 19:59:07
【问题描述】:

所以我在这里得到了这个函数,它是从主函数调用的:

void overflow(char *arg)
{
    char buf[1369];

    strcpy (buf, arg);

    printf ("Thank you for contacting customer service. You are so important to us that we wrote a program to serve you.\n");
    printf ("Please hold for %u minutes while I drop your call\n", (int)strlen(buf));

    return;
} 

字符串*arg 来自argv[1]

当我做类似的事情时:


./overflow1 aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa29390408

堆栈如下所示:


0xffffce80: 0x07    0x00    0x00    0x61    0x61    0x61    0x61    0x61
0xffffce88: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffce90: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffce98: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcea0: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcea8: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffceb0: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffceb8: 0x61    0x61    0x61    0x61    0x61    0x61    0x61    0x61
0xffffcec0: 0x61    0x61    0x32    0x39    0x33    0x39    0x30    0x34
0xffffcec8: 0x30    0x38

那么我如何获得:

0x32 0x39 0x33 0x39 0x30 0x34 0x30 0x38

成为:

29 39 04 08 ?

我确实意识到这需要从实际的十六进制值转换为字母数字值,例如 08,但网络上的每个字符串工具都没有给我任何结果,因为 08 不是 ascii/字母数字值。

【问题讨论】:

  • 这里可能有点混乱,但这不是我想要做的。问题是我需要内存插槽显示“0x29”而不是“0x32 0x39”,这似乎以2和9的形式写入内存,即四个字节,但我试图将“0x29”写为一个字节
  • 您需要将 ASCII 字符值 0x29(或十进制 29?)发送到输入流。
  • int main(int argc, char **argv) { customerservice (argv[1]); printf ("我们自然无法完成您的通话。再见!\n");返回0;是的 0x29 在 ascii 字母表中作为字符 ')' 存在,但根据:unit-conversion.info/texttools/hexadecimal 在此工具中键入 08 什么也没有,表明 08 不作为字母数字字符存在。所以我不确定如何实现这一点。不,这只是 c 和汇编
  • argv[0] 只是看起来的程序名称,argv[1] 包含作为参数给出的所有内容。因此,如果我输入“./overflow1 aaaaaa”,它将用 0x61 0x61 0x61 0x61 0x61 0x61 填充内存。唯一的问题似乎是找到似乎不存在的 0x08 和 0x04 的字母数字值。
  • 因为 strlen 的返回值将始终 >= 0 并且由于格式标识符是 "%u" (unsigned int) 它看起来是这样的:' (int)strlen(buf));'应该是:' (unsigned)strlen(buf));'

标签: c string assembly hex buffer


【解决方案1】:

如果你想将任意字节作为参数发送给命令,你必须在你的 shell 中对它们进行转义。例如,在 bash 中,您可以这样做:

echo $'a\x09b\x33c'

它会显示:

a       b3c

因为 bash 将 $'' 构造中的 \xHH(两个十六进制数字)解释为单字节十六进制值。 0x09 是制表符,0x33 是数字 3。

【讨论】:

  • "\x08" 应该是 "\x8" 无法相信这有多简单,但感谢您的回答,请记住这一点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-07-26
  • 2016-03-14
  • 2012-02-20
  • 2019-11-26
  • 2023-03-05
  • 2012-09-13
相关资源
最近更新 更多