简体   繁体   English

Notesearch利用异常(黑客:剥削艺术)

[英]The Notesearch Exploit anomalies (Hacking: Art of Exploitation)

This question is about the exploit for the program notesearch on pg 121 of the book Hacking: Art of Exploitation 2nd Edition. 这个问题是关于“黑客:剥削艺术”第二版第121页上的程序笔记研究的漏洞利用。

There is something I do not understand in the exploit: 在漏洞利用中有一些我不理解的东西:

When the System executes the ./notesearch 'xyz....' the argument 'xyz...' overflows the string buffer in the child program thereby overwriting the return address....that much is clear. 当系统执行./notesearch'xyz ....'时,参数'xyz ...'溢出子程序中的字符串缓冲区,从而覆盖返回地址....这很清楚。

The assumption here is that the notesearch program's stack frame comes ontop of the calling exploit's Stack frame. 这里的假设是notesearch程序的堆栈帧位于调用exploit的Stack帧之上。 This holds true when the compiled versions exist on the same system. 当编译版本存在于同一系统上时,这也适用。

My first question is 1. Will this work even as a remote hack? 我的第一个问题是1.这是否会像远程黑客一样工作?

My second question is 2. Since the buffer has been used to overwrite all variables including and beyond the return address, how does the notesearch program work as intended? 我的第二个问题是2.由于缓冲区已用于覆盖包括返回地址在内的所有变量,因此notesearch程序如何按预期工作? Variables like "printing" etc which sit in this stackframe and decide whether messages are printed or not all seem to work fine. 像“打印”等变量位于这个堆栈框架中并决定是否打印消息似乎都能正常工作。 Even though the calling functions sit ontop of the relevant stackframe, where the string buffer which is being flooded sits, there are certain key variables whioch would have been overwritten. 即使调用函数位于相关堆栈帧的顶部,其中正在被泛洪的字符串缓冲区位于其中,也存在某些将被覆盖的关键变量。

Question no. 问题没有。 3. Given that String buffer is part of a new stack frame pushed in after execution of notesearch starts, the buffer overwrites all the given variables in that notesearch program. 3.鉴于String缓冲区是在执行notesearch开始后推入的新堆栈帧的一部分,缓冲区将覆盖该notesearch程序中的所有给定变量。 Also the buffer is the value for the search string. 缓冲区也是搜索字符串的值。 By the program logic since the search string does not match with message, the program should not output details of the User messages. 由于程序逻辑由于搜索字符串与消息不匹配,因此程序不应输出用户消息的详细信息。 In this case, the messages appear. 在这种情况下,会显示消息。 I want to know why? 我想知道为什么?

(For reference: the book is http://www.tinker.tv/download/hacking2_sample.pdf and the code is downloadable for free from http://www.nostarch.com/hacking2.htm .) (供参考:本书是http://www.tinker.tv/download/hacking2_sample.pdf ,代码可从http://www.nostarch.com/hacking2.htm免费下载。)

Keep reading the book; 继续读这本书; another example is given on page 122, and then there's plenty of explanatory text that tells all about the exploits. 另一个例子在第122页给出,然后有大量的解释性文本告诉所有有关漏洞的内容。

Here's the relevant part of notesearch 's code: 这是notesearch代码的相关部分:

int main(int argc, char *argv[]) {
    int userid, printing=1, fd; // file descriptor
    char searchstring[100];

    if(argc > 1)                        // If there is an arg
        strcpy(searchstring, argv[1]);   //   that is the search string
    else                                // otherwise
        searchstring[0] = 0;             //   search string is empty

    userid = getuid();
    fd = open(FILENAME, O_RDONLY);   // open the file for read-only access

You wrote: 你写了:

The assumption here is that the notesearch program's stack frame comes ontop of the calling exploit's Stack frame. 这里的假设是notesearch程序的堆栈帧位于调用exploit的Stack帧之上。

No, that's wrong. 不,那是错的。 There is only one stack frame that's relevant here: the stack frame of the main() function in notesearch . 这里只有一个堆栈框架相关: notesearch main()函数的堆栈框架。 The fact that we invoke ./notesearch xyz... via a system() call inside exploit_notesearch is irrelevant; 我们调用的事实./notesearch xyz...通过一个system()内调用exploit_notesearch是无关紧要的; we could just as well invoke ./notesearch xyz... directly on the bash command line, or trick some other process (such as, you know, bash ) into executing it on our behalf. 我们也可以直接在bash命令行上调用./notesearch xyz... ,或者欺骗其他一些进程(例如,你知道, bash )代表我们执行它。

  1. Will this work even as a remote hack? 即使是远程黑客,这还能工作吗?

Of course. 当然。

  1. Since the buffer has been used to overwrite all variables including and beyond the return address, how does the notesearch program work as intended? 由于缓冲区已被用于覆盖包括返回地址在内的所有变量,因此notesearch程序如何按预期工作?

Well, it doesn't really work as intended. 嗯,它并没有真正按预期工作。 Look at the output again: 再看一下输出:

reader@hacking:~/booksrc $ gcc exploit_notesearch.c
reader@hacking:~/booksrc $ ./a.out
[DEBUG] found a 34 byte note for user id 999
[DEBUG] found a 41 byte note for user id 999
-------[ end of note data ]-------
sh-3.2#

Giving you a shell clearly doesn't count as "working as intended". 明确给你一个壳不算“按预期工作”。 But even before that, the program claims to find notes for userid 999 in /var/notes , which might indicate that it's a little bit confused. 但即便在此之前,该程序声称在/var/notes找到了用户ID 999的/var/notes ,这可能表明它有点混乱。 In our role as the malicious hacker, we don't care about this garbage output from the notesearch program; 在我们作为恶意黑客的角色中,我们并不关心来自notesearch程序的垃圾输出; all we care about is that it eventually reaches the end of main() and returns to our shellcode, giving us access to the shell. 我们关心的是它最终到达main()的末尾并返回我们的shellcode,让我们可以访问shell。

But, if you're wondering how we managed to overwrite the return address without overwriting local variables userid , printing , and fd , there are at least three obvious possibilities: 但是,如果您想知道我们如何设法覆盖返回地址而不覆盖本地变量useridprintingfd ,那么至少有三种显而易见的可能性:

A. Maybe those variables are allocated below searchstring on the stack. searchstring 可能这些变量是在堆栈上的searchstring下面分配的。

B. Maybe those variables are allocated in registers instead of on the stack. B.也许这些变量是在寄存器中而不是在堆栈中分配的。

C. Overwhelmingly likely, those variables are being overwritten, but their initial values simply don't matter to the program. C.很大可能,这些变量覆盖,但其初始值根本无关紧要的程序。 For example, userid can get any value at all, because that garbage value will immediately be overwritten with getuid() on the next line. 例如, userid可以获取任何值,因为该垃圾值将立即被下一行的getuid()覆盖。 The only variable whose initial value matters is printing . 初始值很重要的唯一变量是printing And even printing changes the behavior of the program only if it happens to get the value 0 — and it can't get the value 0 , because the data we're copying in consists entirely of non-zero bytes, by design. 甚至printing只有在碰巧得到值0时才改变程序的行为 - 它不能得到值0 ,因为我们复制的数据完全由非零字节组成。

I think you don't really understand what is buffer overflow. 我想你真的不明白什么是缓冲区溢出。 That searchstring variable is originally located on stack for 100 bytes. 该searchstring变量最初位于堆栈上100个字节。 Now you are copying a large chunk of buffer into searchstring without checking the length of it. 现在,您将一大块缓冲区复制到searchstring中,而不检查它的长度。 Therefore the buffer overflows to other parts of the stack frame of the notesearch's main function. 因此缓冲区溢出到notesearch主函数的堆栈帧的其他部分。 The return address is also overwritten. 返回地址也会被覆盖。 That's how it works. 这就是它的工作原理。

I think that the most important assumption here is that the notesearch stack is similar to that of exploit_notesearch . 我认为这里最重要的假设是notesearch堆栈类似于 exploit_notesearch That is why he uses an exploit_notesearch local variable (unsigned int i) to calculate ret . 这就是为什么他使用exploit_notesearch局部变量(unsigned int i)来计算ret He assumes (of course, knowing the source code of notesearch) that when both programs are loaded in memory they will have similar frame addresses (around 0xffff7..) Of course, the 2 programs does not share memory, they are different processes. 他假设(当然,知道notesearch的源代码),当两个程序都加载到内存中时,它们将具有相似的帧地址(大约为0xffff7 ..)当然,2个程序不共享内存,它们是不同的进程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在“黑客:剥削的艺术”中的exploit_notesearch 程序中出现分段错误? - Why do I get a segmentation fault in the exploit_notesearch program from “Hacking: The Art of Exploitation”? Hacking - The Art of Exploitation:调试缓冲区溢出示例 - Hacking - The Art of Exploitation: debugging buffer overflow example scanf的输出格式有误(黑客:剥削的范例艺术) - Malformed output with scanf (Hacking: The Art of Exploitation Example) 《黑客:剥削的艺术》中的基于堆栈的溢出代码 - Stack-based overflow code from Hacking: The Art of Exploitation “黑客:剥削的艺术”:为什么示例程序仅适用于gcc而不适用于-m32? - “Hacking: The Art of Exploitation”: why does example program work with just gcc but not with -m32? stat.h 文件访问文件描述符 open() 黑客攻击的艺术 - stat.h file access file descriptors open() Hacking The Art of Exploitation 为什么即使我遵循“黑客 - 剥削艺术”一书中的代码,我也无法崩溃程序 - Why I can't crash the program even though I am following codes from book “Hacking-The art of exploitation” linux缓冲区溢出-剥削的艺术到老? - linux buffer overflow - Art of Exploitation To Old? 试图从“剥削艺术”中理解char_array2.c的例子 - Trying to understand example char_array2.c from “the art of exploitation” 在64位Ubuntu上的利用 - exploitation on 64 bit Ubuntu
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM