CTOCIO IT专家网

天极传媒 比特网 | 天极网 | IT专家网 | IT商网 | 52PK游戏网 | 手机天极 | IT分众 |
IT专家网搜索

网络安全,安全,网络安全设备,信息安全产品,网络安全新闻,信息安全市场分析,黑客攻防,防黑反黑技巧,黑客,网络安全技术,网络安全方案,病毒播报,最新病毒库,攻防技巧,入侵渗透,新闻,思科,Juniper,天融信,瑞星,金山,江民,卡巴斯基,赛门铁克, 趋势,绿盟科技,联想网御,MCAFEE,安氏,冰峰网络,网络入侵,木马,病毒,病毒分析,木马分析,样本分析,木马样本分析,病毒样本分析,杀毒软件

您现在的位置: IT专家网 > 安全子站 > 安全技巧

怎样写远程缓冲区溢出漏洞利用程序

作者: 佚名,  出处:IT专家网论坛整理, 责任编辑: 张帅, 
2007-12-18 10:29
  缓冲溢出漏洞前面笔者已经介绍过,这里笔者将详细介绍如何来写远程缓冲区溢出漏洞来利用程序,这里仅做参考……

      假设有一个有漏洞的服务器程序(vulnerable.c). 然后写一个exploit 来利用该漏洞,这样将能得到一个远程shell。

  一、理解有漏洞程序:

      #include
  #include
  #include
  #define BUFFER_SIZE 1024
  #define NAME_SIZE 2048
  int handling(int c)
  {
  char buffer[BUFFER_SIZE], name[NAME_SIZE];
  int bytes;
  strcpy(buffer, "My name is: ");
  bytes = send(c, buffer, strlen(buffer), 0);
  if (bytes == -1)
  return -1;
  bytes = recv(c, name, sizeof(name), 0);
  if (bytes == -1)
  return -1;
  name[bytes - 1] = ’\0’;
  sprintf(buffer, "Hello %s, nice to meet you!\r\n", name);
  bytes = send(c, buffer, strlen(buffer), 0);
  if (bytes == -1)
  return -1;
  return 0;
  }
  int main(int argc, char *argv[])
  {
  int s, c, cli_size;
  struct sockaddr_in srv, cli;
  if (argc != 2)
  {
  fprintf(stderr, "usage: %s port\n", argv[0]);
  return 1;
  }
  s = socket(AF_INET, SOCK_STREAM, 0);
  if (s == -1)
  {
  perror("socket() failed");
  return 2;
  }
  srv.sin_addr.s_addr = INADDR_ANY;
  srv.sin_port = htons( (unsigned short int) atol(argv[1]));
  srv.sin_family = AF_INET;
  if (bind(s, &srv, sizeof(srv)) == -1)
  {
  perror("bind() failed");
  return 3;
  }
  if (listen(s, 3) == -1)
  {
  perror("listen() failed");
  return 4;
  }
  for(;;)
  {
  c = accept(s, &cli, &cli_size);
  if (c == -1)
  {
  perror("accept() failed");
  return 5;
  }
  printf("client from %s", inet_ntoa(cli.sin_addr));
  if (handling(c) == -1)
  fprintf(stderr, "%s: handling() failed", argv[0]);
  close(c);
  }
  return 0;
  }

  下面将编译并运行该程序:

      user@linux:~/ > gcc vulnerable.c -o vulnerable
  user@linux:~/ > ./vulnerable 8080
  ../vulnerable 8080 说明你能在8080端口运行该项服务
  user@linux~/ > gdb vulnerable
  GNU gdb 4.18
  Copyright 1998 Free Software Foundation, Inc.
  GDB is free software, covered by the GNU General Public License, and you are
  welcome to change it and/or distribute copies of it under certain conditions.
  Type "show copying" to see the conditions.
  There is absolutely no warranty for GDB. Type "show warranty" for details.
  This GDB was configured as "i386-suse-linux"...
  (gdb) run 8080
  Starting program: /home/user/directory/vulnerable 8080

  现在该程序监听8080端口并等待连接。

      user@linux:~/ > telnet localhost 8080
  Trying ::1...
  telnet: connect to address ::1: Connection refused
  Trying 127.0.0.1...
  Connected to localhost.
  Escape character is ’^]’.
  My name is: Robin
  , nice to meet you!
  Connection closed by foreign host.
  user@linux:~/ >

  看来没有什么破绽,但是这时gdb会在屏幕上显示:

  client from 127.0.0.1 0xbffff28c (访地址因不同机器类型而异)

共3页。 1 2 3 :

网友评论

笔名 
请您注意:遵守国家有关法律、法规,尊重网上道德,承担一切因您的行为而直接或间接引起的法律责任。    IT专家网友拥有管理笔名和留言的一切权利。
  • 周排行榜
  • 月排行榜

邮件订阅


天极服务 | 关于我们 | 网站律师 | 加入我们 | 联系我们 | 广告业务 | 友情链接 | 我要挑错
All Rights Reserved, Copyright 2004-2007, ChinaByte
渝ICP证B2-20030003号 如有意见请与我们联系 powered by 天极内容管理平台CMS4i