简体   繁体   English

从编译的C ++代码中提取int数组

[英]Extracting int array from compiled C++ code

Is it possible for an attacker to get integer arrays from your compiled code? 攻击者是否有可能从编译的代码中获取整数数组?

Like how the attacker can get strings from your code using the strings command. 就像攻击者如何使用strings命令从代码中获取字符串一样。

Yes. 是。 A quick example with main.c : main.c一个简单的例子:

int main(void) {
        int vars[8] = {0,1,2,3,4,5,6,7};
}

Then gcc -O0 main.c -o main to disable optimization so our unused array isn't removed. 然后使用gcc -O0 main.c -o main禁用优化,以便不删除未使用的数组。 Then if you simply disassemble it: 然后,如果您只是将其拆卸:

0000000000400474 <main>:
  400474:       55                      push   %rbp
  400475:       48 89 e5                mov    %rsp,%rbp
  400478:       c7 45 e0 00 00 00 00    movl   $0x0,-0x20(%rbp)
  40047f:       c7 45 e4 01 00 00 00    movl   $0x1,-0x1c(%rbp)
  400486:       c7 45 e8 02 00 00 00    movl   $0x2,-0x18(%rbp)
  40048d:       c7 45 ec 03 00 00 00    movl   $0x3,-0x14(%rbp)
  400494:       c7 45 f0 04 00 00 00    movl   $0x4,-0x10(%rbp)
  40049b:       c7 45 f4 05 00 00 00    movl   $0x5,-0xc(%rbp)
  4004a2:       c7 45 f8 06 00 00 00    movl   $0x6,-0x8(%rbp)
  4004a9:       c7 45 fc 07 00 00 00    movl   $0x7,-0x4(%rbp)

It makes logical sense, if you have data in your code and your program uses it, then the data must exist somewhere. 从逻辑上讲,如果代码中包含数据,并且程序使用它,则数据必须存在于某处。

It is possible, I recommend you to open a executable file after compiled with notepad++ or notepad, and maybe you see something as: 有可能,我建议您在用notepad ++或notepad编译后打开一个可执行文件,也许您会看到以下内容:

使用记事本++打开的.exe文件,请查看Hello world语句

But why this is so simple with strings and not with vectors? 但是,为什么用字符串而不用矢量这么简单呢? Because strings are usually just made by alfphanumeric letters and so on, just seen them inside of binary files we found tham, an array of int will be inside of your code as raw data but eye seen them is hard since they are not (obligatorily) printed characters, but if you use a disassembling program it is as easy to find strings as other arrays. 因为字符串通常只是由字母数字字母组成,依此类推,只是在我们发现tham的二进制文件中看到过它们,所以int数组将作为原始数据出现在您的代码中,但是很难看清它们,因为它们不是(强制性的)打印的字符,但是如果使用反汇编程序,则与其他数组一样容易找到字符串。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM