我们有一段代码来说明缓冲区溢出绕过密码哈希的危险。我破解密码的输入由通过命令行输入的一串十六进制字符组成,如下所示:
echo -ne "\xab\x94\x44..." | ./checkPassword
这在 checkPassword 中解析为:
scanf("%29s", password);
然后我用以下两者打印密码:
printf("\n%s", password):
和
for (i=0; i<29; i++) {
printf("%c ", password[i]);
}
使用 scanf 通过 checkPassword 捕获输入字符串。我非常确定我用来生成破解字符串“\x...”的方法是正确的。然而,我注意到有时我仍然无法绕过密码。在打印出 checkPassword 读取的输入字符串后,我注意到诸如\xc 之类的字符被解释为\x00,如果它们没有被解释,我就会绕过密码。我还没有找到任何解决或解释这个问题的方法。有人有什么想法吗?感谢您的建议
编辑:提供更多代码。
EDIT2:\xc 还意味着程序忽略它后面的任何字符。这不是导致问题的唯一字符,但我认为它们似乎都是“<\xc”。不幸的是,仅仅禁止小于该值的值实际上并不可行,因为我无法直接控制字符本身。
最佳答案
scanf 在空白符号处停止:
http://www.cplusplus.com/reference/cstdio/scanf/
s String of characters Any number of non-whitespace characters, stopping at the first whitespace character found. A terminating null character is automatically added at the end of the stored sequence.
http://www.cplusplus.com/reference/cctype/isspace/
For the "C" locale, white-space characters are any of:
' ' (0x20) space (SPC)
'\t' (0x09) horizontal tab (TAB)
'\n' (0x0a) newline (LF)
'\v' (0x0b) vertical tab (VT)
'\f' (0x0c) feed (FF)
'\r' (0x0d) carriage return (CR)
关于c - 非空十六进制字符输入在 C 中解释为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42939457/