cmd_resolver.cpp
上传用户:jinandeyu
上传日期:2007-01-05
资源大小:620k
文件大小:3k
源码类别:

远程控制编程

开发平台:

WINDOWS

  1. /*  Back Orifice 2000 - Remote Administration Suite
  2.     Copyright (C) 1999, Cult Of The Dead Cow
  3.     This program is free software; you can redistribute it and/or modify
  4.     it under the terms of the GNU General Public License as published by
  5.     the Free Software Foundation; either version 2 of the License, or
  6.     (at your option) any later version.
  7.     This program is distributed in the hope that it will be useful,
  8.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  9.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10.     GNU General Public License for more details.
  11.     You should have received a copy of the GNU General Public License
  12.     along with this program; if not, write to the Free Software
  13.     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. The author of this program may be contacted at dildog@l0pht.com. */
  15. #include<windows.h>
  16. #include<auth.h>
  17. #include<iohandler.h>
  18. #include<encryption.h>
  19. #include<commandloop.h>
  20. #include<bocomreg.h>
  21. #include<cmdcmd_resolver.h>
  22. #include<strhandle.h>
  23. int IssueHostent(CAuthSocket *cas_from, int comid, struct hostent *he)
  24. {
  25. char svBuffer[1024];
  26. // Print FQDN
  27. wsprintf(svBuffer,"Fully Qualified Domain Name: %.512sn",he->h_name);
  28. IssueAuthCommandReply(cas_from,comid,1,svBuffer);
  29. // Print Addresses
  30. int i;
  31. IssueAuthCommandReply(cas_from,comid,1,"IP Addresses:n");
  32. for(i=0;i<(he->h_length/4);i++) {
  33. wsprintf(svBuffer,"  %u.%u.%u.%un",
  34. *(BYTE *)(he->h_addr_list[i]),
  35. *((BYTE *)(he->h_addr_list[i])+1),
  36. *((BYTE *)(he->h_addr_list[i])+2),
  37. *((BYTE *)(he->h_addr_list[i])+3));
  38. IssueAuthCommandReply(cas_from,comid,1,svBuffer);
  39. }
  40. if(he->h_aliases!=NULL) {
  41. char **psvName;
  42. psvName=he->h_aliases;
  43. IssueAuthCommandReply(cas_from,comid,1,"Alternate Names:n");
  44. while(*psvName!=NULL) {
  45. wsprintf(svBuffer,"  %.512sn",*psvName);
  46. IssueAuthCommandReply(cas_from,comid,1,svBuffer);
  47. psvName++;
  48. }
  49. }
  50. return 0;
  51. }
  52. int CmdProc_ResolveHost(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  53. {
  54. struct hostent *he;
  55. he=gethostbyname(svArg2);
  56. if(he==NULL) {
  57. IssueAuthCommandReply(cas_from,comid,0,"Unable to resolve hostname.n");
  58. return 1;
  59. }
  60. IssueHostent(cas_from,comid,he);
  61. IssueAuthCommandReply(cas_from,comid,0,"End of hostname record.n");
  62. return 0;
  63. }
  64. int CmdProc_ResolveAddr(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  65. {
  66. char addr[4];
  67. char *svAddr,*svNext;
  68. int i;
  69. memset(addr,0,4);
  70. svAddr=svArg2;
  71. for(i=0;i<4;i++) {
  72. if(svAddr==NULL) break;
  73. svNext=BreakString(svAddr,".");
  74. addr[i]=atoi(svAddr);
  75. svAddr=svNext;
  76. }
  77. struct hostent *he;
  78. he=gethostbyaddr(addr,4,AF_INET);
  79. if(he==NULL) {
  80. IssueAuthCommandReply(cas_from,comid,0,"Unable to resolve host address.n");
  81. return 1;
  82. }
  83. IssueHostent(cas_from,comid,he);
  84. IssueAuthCommandReply(cas_from,comid,0,"End of hostname record.n");
  85. return 0;
  86. }