假设我有这种代码:
// In revision.c
char *path_name(const struct name_path *path, const char *name) // by design, name_path->len is a 32 bits int, but this doesn’t concern name
{
const struct name_path *p;
char *n, *m;
int nlen = strlen(name); // the size is converted to a positive number (the correct size was allocated previously with an unsigned long). I got 705804100
int len = nlen + 1;
for (p = path; p; p = p->up) { //loop is skipped (except in another case fixed since 2.7.1)
if (p->elem_len)
len += p->elem_len + 1;
}
n = xmalloc(len); // if len is negative, it will also be converted to a negative 64 bits integer *(which explains it is normally trying to allocate serveral Pb of ram most of the time)* which will be read as positive after that. // but this isn’t the run case that is interesting here.
m = n + len - (nlen + 1); // the size of m is lower than name
strcpy(m, name); // strcpy rely on the null terminating character. The result is written in an unallocated memory from heap. This is the definition of heap overflow enabling server side remote code execution if name[] contains assembly, and have the correct size. This open the way to defeat canaries aslr, and nx combined see http://security.stackexchange.com/q/20497/36301#comment182004_20550
for (p = path; p; p = p->up) {
if (p->elem_len) {
m -= p->elem_len + 1;
memcpy(m, p->elem, p->elem_len);
m[p->elem_len] = '/';
}
}
return n;
}是否会出现系统在保持远程代码执行路径完全关闭 时发生溢出的情况?
git数据库( git树)中精心编制的路径应该包含用于执行远程代码执行的二进制代码。但是,路径不能包含nul字节(因为它被用作git树中的分隔符)。
如果需要具体案例,则为Ubuntu,linux版本<3.16,所有安全保护都启用(我指的是nx和dep合并,但金丝雀除外)。该体系结构为x86_64。libc是滑翔的一个旧版本(但安全补丁)。
现在,创建一个证明应该更容易。
发布于 2016-02-25 20:19:01
缓冲区溢出(“写”类)只有当攻击者能够安排溢出到用于其他事情的其他字节时,才能给攻击者带来任何优势。在任何时候,进程都在一个地址空间中运行,其中大部分是未分配的。如果溢出的缓冲区位于地址空间的末尾,或者后面只有未使用的字节,然后是未映射的页,则溢出将无助于攻击者。
我记得在rlogin 4.1.4 (sparc系统)上使用SunOS命令行工具的情况。它是根suid,如果术语环境变量包含超过64个字符的字符串,则可以将其用于分段错误。然而,过载的缓冲区位于数据部分的末尾,除了该缓冲区之外,没有什么可以覆盖的。
不过,请注意,malloc()可以在每个分配的块之前和之后使用额外的字节来跟踪分配了哪些块。根据malloc()的实现,修改这些字节可能对攻击者有帮助,也可能无助于攻击者。底线是,虽然某些缓冲区溢出无法被利用,但通常很难确保缓冲区溢出不能被利用。更安全的假设是,任何缓冲区溢出都会导致严重的后果,而不允许它们发生。
发布于 2016-02-25 20:15:18
并非所有缓冲区溢出都会导致远程代码执行。这取决于如何分配缓冲区,以及是否可以由攻击者控制指令指针。是否有可能执行远程代码有很多因素。
https://security.stackexchange.com/questions/115769
复制相似问题