English 中文(简体)
采用n法的缓冲外溢
原标题:Buffer overflow using snprintf
  • 时间:2012-04-11 19:55:43
  •  标签:
  • c
  • buffer

这是一个任务,但我对基本理解有问题。

弱势法典:

int choc(char *arg)
{
  char buf[400];
  snprintf(buf, sizeof buf, arg);
  return 0;
}

我的理解是,一个动力需要是一种模式,它将随着我希望执行的法典的地址而超出返回地址。 但是,我难以确定模式。

因此,说明形式的内容需要:

  1. the address of the return instruction, which I need to overwrite
  2. A list of %x
  3. The value which I would write on the return address. This would be the address of the code I want to execute.

为了获得返回地址,我只需要看一下右翼的训令的地址? 百分比的目的是什么? 我如何把守则的论述编码成正文,我想以说明形式执行?

A test I did: Using gdb I found that the address of my buf is 0xbffffba0. I generated arg to be "xa0xfbxffxbf_%x.%x.%n"; Shouldn t this write some value to the start of the buff at the address 0xbffffba0? However I get a segfault. What am I doing wrong?

Any help would be appreciated!

问题回答

<xa0xfbxffxbf>>不应成为泡沫的地址,而应作为收益地址的所在地点(这是你希望超高标准的价值)。 你们不得不用 g子找到这一价值。

然后,你需要把一定比例的百分位放在你的格式中,这样你的百分比就能够读到这个数值,并写到你指定的地址。 你们还需要使用正确的外地规模,这样,百分比实际上将写上正确的数值。

Vulnerability you are trying to exploit is called format string vulnerability. For further investigation on this topic I would recommend THIS link or book called "Hacking: art of exploitating".

从夸张中读取价值通常是不够的。 一些平台处理空间随机化安全特征,这将造成特定物体的地址在节目中有所不同。 相反,你想弄清,返回地址存放在哪里(与<条码>snprintf呼号有关),并在那里超标。 这非常具体。 你们的平台是什么?

采用夸张的方式,在组装一级通过该职能守则,并在<代码>return之前检查点。 确保打脚石和返回地址像你认为应该看。 这应该使你知道问题在哪里。 此外,你还可以在<代码>return <<>>>/code>之前,尝试手工修改与变换的标签,以核实你重新瞄准的所在地实际上是返回地址。

The answer is no, you don t just need the address of the ret instruction. What you actually need is the location in memory that the ret instruction loads. Have a look at this diagram:

http://post.queensu.ca/~trd/377/tut5/stack.html

你们的目标是超越回返地址。

我走了前面,并试图起草一个简短的方案,以显示这一点(未来)。

<>Update: 我有坏消息。 我可以这样说。 我写:

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

void bar()
{
    printf("Bar function
");
}

void foo()
{
    void (**p)(void);
    asm volatile("movl %%ebp, %0
	" : "=r"(p) : : "%0");
    p += 1;
    *p = bar;
}

int main()
{
    foo();
    return 0;
}

造成部分错,而无需印刷bar()中的句子。 我期望安理会工作......现在我会像你一样感到困惑。 是否有任何人解释为什么在我的法典中实施<条码>条码>。





相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签