呵呵... 既然是作业题那就应该自己做才有成就感么;)
溢出目前最通常的也就两种, 一种是Stack Overflow (堆栈溢出), 一种是Format String Overflow(格式字串溢
出?), 中文名不清楚... 原理我相信你们老师已经教过你了吧.

随便分析一下, 这个小程序如果要有溢出型漏洞, 利用方法只有用户传入的args[0], args[1], 对吧? 在linux下写个程序调用这
个小程序的system call有2种方式:

第一种:
system("/path/path/prog args0 args1");

第二种:
...
  args[0] = "args1";
  args[1] = "args2";
  ...
  env[0] = "USER=root";  //环境变量
  env[1] = NULL;
  ...

execve(TARGETPATH, args, env);

明显第二种方式才适合你;)
然后我们看看那个程序在哪些地方用到了args[0]和args[1]呢, 首先是那个Usage, 不过很遗憾用了%s, 这样是没法格式化字符串溢
出了(至少我目前所知没办法)

继续看, atoi(argv[1]) 恩.... 怎么样, 你怎么能保证这个argv[1]是一个正常"\0"的string呢, 不过暂时好像没
见谁能利用这个函数, 最多指向一个垃圾地址导致segmentation fault吧
继续: strcmp(argv[1], "0")  还好吧.. 虽然没有检查边界... 但是一个字节是做不了什么的XD

再来:  fprintf(stderr, argv[1]);  囧... 这次居然不用 %s 了啊... Format String
Overflow 可行! 溢出吧-o-溢出吧~~~

至于如何利用这种问题写expolit的, 自己找找吧, 很多的,如果没有我可以把我的一个发过来....-_-
好像直接在googlegroups里面发贴不能加附件.. 恩....

On 9月27日, 下午9时43分, Raullen <[EMAIL PROTECTED]> wrote:
> 以下是源代码,至少有一个security问题 可以导致溢出 得到rootshell
> 平台式Linux 标准C函数库
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <syslog.h>
>
> int main(int argc, char **argv)
> {
>     int max;
>     char *composites;
>     int curprime = 0, curcomp = 0;
>
>     if (argc < 2) {
>         fprintf(stderr, "Usage: %s max\nOutputs the primes from 2 to max\n",
>             argv[0]);
>         return 1;
>     }
>
>     max = atoi(argv[1]);
>     printf("%ld\n",max);
>     if (max == 0 && strcmp(argv[1], "0")) {
>         /* argv[1] wasn't a number */
>         fprintf(stderr, "Supplied argument not a number: ");
>         fprintf(stderr, argv[1]);
>         fprintf(stderr, "\n");
>         return 1;
>     }
>     if (max < 2 || max > 1000000) {
>         fprintf(stderr, "Supplied argument out of range.\n");
>         return 1;
>     }
>     composites = calloc(1,max+1);
>     /* 0 and 1 are not prime */
>     composites[0] = composites[1] = 1;
>
>     while(1) {
>         /* Find the smallest number not yet marked as composite */
>         do {
>             ++curprime;
>         } while (curprime <= max && composites[curprime]);
>
>         if (curprime > max) {
>             /* We're done */
>             return 0;
>         }
>
>         printf("%d\n", curprime);
>         /* Mark all multiples of curprime as composite */
>         curcomp = 2*curprime;
>         while (curcomp <= max) {
>             composites[curcomp] = 1;
>             curcomp += curprime;
>         }
>     }
>
> }
--~--~---------~--~----~------------~-------~--~----~
 要向邮件组发送邮件,请发到 [email protected]
 要退订此邮件,请发邮件至 [EMAIL PROTECTED]
-~----------~----~----~----~------~----~------~--~---

回复