#include #define CANARY "in_the_coal_mine"
struct {
char buffer[1024];
char canary[sizeof(CANARY)];
} temp = { "buffer", CANARY };
int main(void)
{
struct hostent resbuf;
struct hostent *result;
int herrno; int retval;
size_t len = sizeof(temp.buffer) - 16*sizeof(unsigned char) - 2*sizeof(char *) - 1;
char name[sizeof(temp.buffer)];
memset(name, '0', len);
name[len] = '\0';
retval = gethostbyname_r(name, &resbuf, temp.buffer, sizeof(temp.buffer), &result, &herrno);
if (strcmp(temp.canary, CANARY) != 0)
{
puts("vulnerable");
exit(EXIT_SUCCESS);
}
if (retval == ERANGE)
{
puts("not vulnerable");
exit(EXIT_SUCCESS);
}
puts("should not happen");
exit(EXIT_FAILURE);
}
将上述代码保存为ghost.c文件
编译:gcc ghost.c -o ghost
执行:./ghost
返回Not vulnerable, 表示不存在此漏洞:
返回 Vulnerable ,表示存在漏洞:
--Linux 6环境下执行成功
选择2.18以上版本升级
1、mkdir /root/glibc
2、把glibc-2.20.tar.gz上传到 /root/glibc
3、cd /root/glibc