[Boxp-cvs] boxp/srv_control cmd_serverctrl.cpp,NONE,1.1 cmd_serverctrl.h,NONE,1.1 cmd_simple.cpp,NON
Status: Beta
Brought to you by:
j_aroche
From: Javier A. \(RA\) <j_a...@us...> - 2004-09-10 22:09:12
|
Update of /cvsroot/boxp/boxp/srv_control In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16929/srv_control Added Files: cmd_serverctrl.cpp cmd_serverctrl.h cmd_simple.cpp cmd_simple.h main.cpp main.h srv_control.dsp Log Message: Initial Import Javier Aroche --- NEW FILE: srv_control.dsp --- # Microsoft Developer Studio Project File - Name="srv_control" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=srv_control - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "srv_control.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "srv_control.mak" CFG="srv_control - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "srv_control - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "srv_control - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "" # PROP Scc_LocalPath "" CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "srv_control - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "..\Exes\plugins" # PROP Intermediate_Dir "Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SRV_CONTROL_EXPORTS" /YX /FD /c # ADD CPP /nologo /Gz /Zp1 /MT /W3 /O1 /I ".\include" /I "..\boxp\include" /I "..\bogui\include" /I "..\bocfg\include" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SRV_CONTROL_EXPORTS" /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "NDEBUG" # ADD RSC /l 0x409 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 # ADD LINK32 kernel32.lib user32.lib /nologo /base:"0x09280000" /entry:"DllMain@12" /dll /pdb:none /machine:I386 /nodefaultlib /implib:".\Release\srv_control.lib" /OPT:NOWIN98 !ELSEIF "$(CFG)" == "srv_control - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "..\Exes\plugins" # PROP Intermediate_Dir "Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SRV_CONTROL_EXPORTS" /YX /FD /GZ /c # ADD CPP /nologo /Gz /Zp1 /MTd /W3 /Gm /Zi /Od /I ".\include" /I "..\boxp\include" /I "..\bogui\include" /I "..\bocfg\include" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "SRV_CONTROL_EXPORTS" /FD /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x409 /d "_DEBUG" # ADD RSC /l 0x409 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 kernel32.lib user32.lib /nologo /base:"0x09280000" /entry:"DllMain@12" /dll /incremental:no /pdb:".\Debug\srv_control.pdb" /debug /machine:I386 /nodefaultlib /out:"..\Exes\plugins/_srv_control.dll" /implib:".\Debug\srv_control.lib" /pdbtype:sept # SUBTRACT LINK32 /pdb:none !ENDIF # Begin Target # Name "srv_control - Win32 Release" # Name "srv_control - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE=.\cmd_serverctrl.cpp # End Source File # Begin Source File SOURCE=.\cmd_simple.cpp # End Source File # Begin Source File SOURCE=.\main.cpp # End Source File # Begin Source File SOURCE=..\boxp\plug.def # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Group "support headers" # PROP Default_Filter "" # Begin Source File SOURCE=..\boxp\include\plugins.h # End Source File # Begin Source File SOURCE=..\boxp\include\srv_linkage.h # End Source File # End Group # Begin Source File SOURCE=.\cmd_serverctrl.h # End Source File # Begin Source File SOURCE=.\cmd_simple.h # End Source File # Begin Source File SOURCE=.\main.h # End Source File # End Group # End Target # End Project --- NEW FILE: main.cpp --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #include <srv_linkage.h> #include <bosrv.h> #include "cmd_serverctrl.h" #include "cmd_simple.h" #include "main.h" // ------------ Variables --------------------------------- HINSTANCE g_hInstance; BOOL g_bActive; int g_nCmdNum[16]; CTRL_STR *str = NULL; // ------------- Strings ---------------------------------- char g_sCtrlStrings[]={ "delete\0" "Simple\0" "Server Control\0" // commands "Ping\0" "Shutdown Server\0" "Restart Server\0" "Load Plugin As Image\0" "Load Plugin\0" "List Plugins\0" "Remove Plugin\0" "Start Command Socket\0" "List Command Sockets\0" "Stop Command Socket\0" "List Configuration Variables\0" "Set Variable Value\0" "List Threads\0" "Stop Thread\0" "Start Thread\0" "Suspend Thread\0" // arguments "Type 'DELETE' to ERADICATE\0" "Plugin Filename\0" "Plugin #\0" "[NETMOD][,ENC][,AUTH]\0" "[Bind Str]\0" "Command Socket #\0" "Variable #\0" "New Value\0" "Thread ID\0" "Thread Name\0" "Suspend=0, Resume=1\0" // commands replies "Hello %.255s. I'm here.\n\0" ">>Eradicating BOXP server<<\n\0" "Shutting down BOXP server.\n\0" "Restarting BOXP server.\nYou will need to reconnect.\n\0" "Couldn't open plugin dll file.\n\0" "Memory allocation error.\n\0" "Plugin could not be added.\n\0" "Plugin added successfully.\n\0" "Plugin added as Image successfully.\n\0" "Plugin List:\n\0" "End Of Plugins List.\n\0" "Invalid plugin number.\n\0" "Plugin could not be removed\n\0" "Plugin removed successfully.\n\0" "Command socket #%d created on: %.256s\n\0" "Error creating command socket.\n\0" "Command Sockets:\n\0" "End Command Socket List.\n\0" "Command socket closed.\n\0" "Command socket already closed.\n\0" "Command socket does not exist.\n\0" "Configuration Variables:\n\0" "End Configuration Variables List.\n\0" "Bad Variable number.\n\0" "Variable value changed.\n\0" "Threads:\n\0" "End threads list.\n\0" "Running\0" "Suspended\0" "Stoped\0" "Bad thread ID.\n\0" "Thread stoped.\n\0" "Couldn't found thread name.\n\0" "Thread already started.\n\0" "Couldn't Start Thread.\n\0" "Plugin Thread \"%.30s\" started.\n\0" "Thread suspended.\n\0" "Thread resumed.\n\0" }; // ------------- Function Implementations ------------------ BOOL WINAPI DllMain(HINSTANCE hInst, ULONG ul_reason_for_call, LPVOID lpReserved) { // Do NOT perform configuration or initialization here switch (ul_reason_for_call) { case DLL_PROCESS_ATTACH: g_hInstance=hInst; break; } return TRUE; } // Called when the Plugin is loaded. bool BOAPI InitPlugin ( GS *gs, PI *pi ) { if ( gs->nSize != sizeof(GS) ) return false; SRV *srv = gs->srv; g_bActive=TRUE; if ( srv ) { if ( srv->nSize != sizeof(SRV) ) return false; // alloc strings memory str = (CTRL_STR *)gs->fct.malloc( sizeof(CTRL_STR), gs ); if ( str==NULL ) return false; // load strings addresses str->Space = (char *) gs->fct.malloc( sizeof(g_sCtrlStrings), gs ); if ( str->Space==NULL ) { gs->fct.free( str, gs ); return false; } gs->fct.memcpy(str->Space,g_sCtrlStrings,sizeof(g_sCtrlStrings)); gs->fct.LoadStrings(gs, &str->sDelete, str->Space ); // Update plugin info pi->pStrings = g_sCtrlStrings; pi->nStrings = sizeof(g_sCtrlStrings); pi->pStrs = (void *) &str->sDelete; // Simple services g_nCmdNum[0]=srv->RegCommand(gs,CmdProc_Ping,NULL,str->sfolsimple ,str->sCmdping,NULL,NULL,NULL,BF_READONLY); // Server control commands // server control g_nCmdNum[1] =srv->RegCommand(gs,CmdProc_ShutdownServer, NULL, str->sfolcontrol, str->sCmdshut , NULL, str->sArg2shut, NULL, BF_WRITE|BF_ADMIN ); g_nCmdNum[2] =srv->RegCommand(gs,CmdProc_RestartServer, NULL, str->sfolcontrol, str->sCmdrestart, NULL, NULL, NULL,BF_WRITE|BF_ADMIN ); // plugins g_nCmdNum[3] =srv->RegCommand(gs,CmdProc_LoadPluginDllAsImage,NULL, str->sfolcontrol,str->sCmdloadimg,NULL, str->sArg2plgfile, NULL, BF_WRITE|BF_ADMIN ); g_nCmdNum[4] =srv->RegCommand(gs,CmdProc_LoadPluginDll, NULL, str->sfolcontrol, str->sCmdload , NULL, str->sArg2plgfile, NULL, BF_WRITE|BF_ADMIN ); g_nCmdNum[5] =srv->RegCommand(gs,CmdProc_ListPluginDlls, NULL, str->sfolcontrol, str->sCmdlistplg, NULL, NULL, NULL, BF_READONLY|BF_ADMIN ); g_nCmdNum[6] =srv->RegCommand(gs,CmdProc_RemovePluginDll, NULL, str->sfolcontrol, str->sCmdremvplg, str->sArg1plgnum, NULL, NULL, BF_WRITE|BF_ADMIN ); // sockets g_nCmdNum[7] =srv->RegCommand(gs,CmdProc_StartCommandSocket,NULL, str->sfolcontrol, str->sCmdstarsck, NULL, str->sArg2ioencauth, str->sArg3bindstr, BF_WRITE|BF_ADMIN ); g_nCmdNum[8] =srv->RegCommand(gs,CmdProc_ListCommandSockets,NULL, str->sfolcontrol, str->sCmdlistsck, NULL, NULL, NULL, BF_READONLY|BF_ADMIN ); g_nCmdNum[9] =srv->RegCommand(gs,CmdProc_StopCommandSocket, NULL, str->sfolcontrol, str->sCmdstopsck, str->sArg1scknum, NULL, NULL, BF_WRITE|BF_ADMIN ); // config vars (by javier aroche) g_nCmdNum[10]=srv->RegCommand(gs,CmdProc_ListCfgVars, NULL, str->sfolcontrol, str->sCmdlistvar, NULL, NULL, NULL, BF_READONLY|BF_ADMIN ); g_nCmdNum[11]=srv->RegCommand(gs,CmdProc_SetCfgVal, NULL, str->sfolcontrol, str->sCmdsetvarv, str->sArg1varnum, str->sArg2newval, NULL, BF_WRITE|BF_ADMIN ); // threads (by javier aroche) g_nCmdNum[12]=srv->RegCommand(gs,CmdProc_ListThreads, NULL, str->sfolcontrol, str->sCmdlstthre, NULL, NULL, NULL, BF_READONLY|BF_ADMIN ); g_nCmdNum[13]=srv->RegCommand(gs,CmdProc_StopThread, NULL, str->sfolcontrol, str->sCmdstopthr, NULL, str->sArg2thrid, NULL, BF_WRITE|BF_ADMIN ); g_nCmdNum[14]=srv->RegCommand(gs,CmdProc_StartThread, NULL, str->sfolcontrol, str->sCmdstrtthr, NULL, str->sArg2thrname, NULL, BF_WRITE|BF_ADMIN ); g_nCmdNum[15]=srv->RegCommand(gs,CmdProc_SuspendThread, NULL, str->sfolcontrol, str->sCmdsuspthr, str->sArg1suspthr, str->sArg2thrid, NULL, BF_WRITE|BF_ADMIN ); } else return false; return true; } // Called when the plugin is unloaded. void BOAPI DelPlugin ( GS *gs ) { g_bActive=FALSE; if (gs->srv==NULL) return; for(int i=0; i<16; i++) { gs->srv->UnregCommand(gs,g_nCmdNum[i]); } gs->fct.free( str->Space,gs ); gs->fct.free( str, gs ); str=NULL; } // Called to get plugin information bool BOAPI PlugVer ( PLUGIN_INFO *pv ) { pv->wVerLo = 0; pv->wVerHi = 1; pv->wHiBOVer = 1; pv->wLoBOVer = 00; pv->svID = "SRVCONTROL\0"; pv->svName = "srv_control.dll"; pv->svDesc = "BOXP Server Control"; pv->pConfigStr = NULL; pv->nConfigLen = 0; pv->bRunAsThread= false; pv->Flags = PF_SRV; pv->Type = PLG_CMD; return true; } --- NEW FILE: cmd_serverctrl.cpp --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #include <bosrv.h> #include <srv_linkage.h> #include "main.h" #include "cmd_serverctrl.h" bool BOAPI CmdProc_ShutdownServer ( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { if(gs->api.plstrcmpi(svArg2,str->sDelete)==0) { gs->gv.bDelete = true; gs->fct.IssueAuthCmdReply(gs, ctx, 0, str->sRpleradicate); } gs->fct.IssueAuthCmdReply(gs, ctx, 0, str->sRplshut ); gs->gv.bIsBoxpRun = false; gs->gv.bIsBoxpReset = false; return true; } bool BOAPI CmdProc_RestartServer( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { gs->fct.IssueAuthCmdReply(gs, ctx, BCC_NOERR, str->sRplrestart ); gs->gv.bIsBoxpRun = false; gs->gv.bIsBoxpReset = true; return true; } bool BOAPI CmdProc_LoadPluginDllAsImage( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { FCT *fct = &gs->fct; API *api = &gs->api; HANDLE hFile=api->pCreateFile(svArg2,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL); if(hFile==INVALID_HANDLE_VALUE) { gs->fct.IssueAuthCmdReply(gs, ctx,BCC_ERR,str->sRplerropen ); return false; } DWORD nSize,dwBytes; nSize = api->pGetFileSize( hFile, NULL ); // Alloc memory space void *buf=fct->malloc(nSize,gs); if(buf==NULL) { api->pCloseHandle( hFile ); fct->IssueAuthCmdReply(gs, ctx,BCC_ERR,str->sRplerrmem ); return false; } // Read file. api->pReadFile( hFile,buf,nSize,&dwBytes,NULL ); if ( dwBytes<nSize ) { api->pCloseHandle(hFile); fct->free(buf,gs); fct->IssueAuthCmdReply(gs, ctx,BCC_ERR,str->sRplerrplug ); return false; } // add plugin to FrameWork if(fct->AddPlugin(gs,buf,NULL)==-1) { api->pCloseHandle(hFile); fct->free(buf,gs); fct->IssueAuthCmdReply(gs, ctx,BCC_ERR,str->sRplerrplug ); return false; } api->pCloseHandle(hFile); fct->free(buf,gs); fct->IssueAuthCmdReply(gs, ctx,BCC_QUERY,str->sRplplugaddimg ); return true; } bool BOAPI CmdProc_LoadPluginDll( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { if(gs->fct.AddPlugin(gs,NULL,svArg2)==-1) { gs->fct.IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrplug ); return false; } gs->fct.IssueAuthCmdReply(gs,ctx,BCC_QUERY,str->sRplplugadd ); return true; } bool BOAPI CmdProc_ListPluginDlls( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; API *api = &gs->api; gs->fct.IssueAuthCmdReply( gs,ctx,0,str->sRplplglist ); api->pEnterCriticalSection( &gv->g_PluginsCrit ); for (DWORD i=0; i<gv->nPluginCount; i++) { char svLine[1024]; PLUGIN_INFO *pi; pi = gv->PlugInfo[i]; api->pwsprintf(svLine,"%2d: %.256s (%.500s)\n",i,pi->svName,pi->svDesc); gs->fct.IssueAuthCmdReply(gs,ctx,0,svLine); } api->pLeaveCriticalSection( &gv->g_PluginsCrit ); gs->fct.IssueAuthCmdReply( gs,ctx,0,str->sRplplglistend ); return true; } bool BOAPI CmdProc_RemovePluginDll( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { // Is a good plugin index? if( nArg1>=gs->gv.nPluginCount ) { gs->fct.IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrbadplg ); return false; } if(gs->fct.RemovePlugin(gs,nArg1)==false) { gs->fct.IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrremplg ); return false; } gs->fct.IssueAuthCmdReply(gs,ctx,BCC_QUERY,str->sRplremplg ); return true; } bool BOAPI CmdProc_StartCommandSocket( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { FCT *fct = &gs->fct; SRV *srv = gs->srv; API *api = &gs->api; char *svBindStr =fct->GetCfgStr(gs,gs->gv.pStrConfig,gs->str.scfg_InitBindStr); char *svNetMod =fct->GetCfgStr(gs,gs->gv.pStrConfig,gs->str.scfg_InitNet); char *svEnc =fct->GetCfgStr(gs,gs->gv.pStrConfig,gs->str.scfg_InitEnc); char *svAuth =fct->GetCfgStr(gs,gs->gv.pStrConfig,gs->str.scfg_InitAuth); char *svParam; svParam=svArg2; if(svParam!=NULL) { if(svParam[0]!='\0') svNetMod=svParam; svParam=fct->BreakString(svNetMod,",",gs); if(svParam!=NULL) { if(svParam[0]!='\0') svEnc=svParam; svParam=fct->BreakString(svEnc,",",gs); if(svParam!=NULL) { if(svParam[0]!='\0') svAuth=svParam; } } } if(svArg3!=NULL) { if(svArg3[0]!='\0') svBindStr=svArg3; } AuthSocket *pSock=fct->ListenAuthSocket(gs,NULL,ctx->cas->GetUserID(ctx->cas),NULL,svBindStr,svNetMod,svEnc,svAuth,NULL); if(((int)pSock)>0 && (srv->nCommCount)<MAX_COMMAND_SOCKETS) { api->pWaitForSingleObject( srv->hCommMutex, INFINITE ); srv->pCommSock[srv->nCommCount]=pSock; (srv->nCommCount)++; api->pReleaseMutex( srv->hCommMutex ); char svMsg[512],svAddr[256]; pSock->GetConnectAddr(pSock,svAddr,256); api->pwsprintf(svMsg, str->sRplscknew,(srv->nCommCount)-1,svAddr); fct->IssueAuthCmdReply(gs,ctx,0,svMsg); } else { fct->IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrscknew); } return true; } bool BOAPI CmdProc_ListCommandSockets( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { FCT *fct = &gs->fct; SRV *srv = gs->srv; API *api = &gs->api; int i,pos; fct->IssueAuthCmdReply(gs,ctx,0,str->sRplscklist); for(i=0; i<(srv->nCommCount); i++) { char svMsg[512]; char svAddr[256]; char svAuth[10], svIO[10], svEnc[10], *txt; api->pWaitForSingleObject( srv->hCommMutex, INFINITE ); AuthSocket *pSock=srv->pCommSock[i]; pSock->GetConnectAddr(pSock,svAddr,256); // Auth engine txt = pSock->m_pAE->pQuery(); pos = fct->InString( txt, ":" ); fct->strncpy( svAuth, txt, min(10,pos) ); svAuth[min(10,pos)]='\0'; // IO engine txt = pSock->m_pIOE->pQuery(); pos = fct->InString( txt, ":" ); fct->strncpy( svIO, txt, min(10,pos) ); svIO[min(10,pos)]='\0'; // Encryption engine txt = pSock->m_pEE->pQuery(); pos = fct->InString( txt, ":" ); fct->strncpy( svEnc, txt, min(10,pos) ); svEnc[min(10,pos)]='\0'; api->pReleaseMutex( srv->hCommMutex ); gs->api.pwsprintf(svMsg,"%d: %.256s [%s - %s - %s]\n",i,svAddr,svAuth,svIO,svEnc); fct->IssueAuthCmdReply(gs,ctx,0,svMsg); } fct->IssueAuthCmdReply(gs,ctx,0,str->sRplscklistend); return true; } bool BOAPI CmdProc_StopCommandSocket( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { FCT *fct = &gs->fct; SRV *srv = gs->srv; API *api = &gs->api; if(nArg1>=0 && nArg1<(DWORD) srv->nCommCount) { api->pWaitForSingleObject( srv->hCommMutex, INFINITE ); AuthSocket *pSock=srv->pCommSock[nArg1]; if(pSock!=NULL) { fct->memcpy(srv->pCommSock+nArg1,srv->pCommSock+nArg1+1, sizeof(AuthSocket *) * ((srv->nCommCount)-(nArg1+1))); (srv->nCommCount)--; srv->pCommSock[(srv->nCommCount)]=NULL; if(pSock->Close(pSock)==0) fct->IssueAuthCmdReply( gs,ctx,0,str->sRplsckclose ); else fct->IssueAuthCmdReply( gs,ctx,0,str->sRplsckclosedone ); return true; } api->pReleaseMutex( srv->hCommMutex ); } fct->IssueAuthCmdReply( gs,ctx,BCC_ERR,str->sRplerrsckclose ); return true; } // New Commands by J. Aroche (C) 2003 - 2004 ------------------------------ bool BOAPI CmdProc_ListCfgVars( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct = &gs->fct; VARIABLE_INFO *vi; DWORD i; fct->IssueAuthCmdReply( gs,ctx,0,str->sRplcfglist ); for(i=0; i<gv->nPlugVars; i++) { char svMsg[612]; vi = gv->pPlugVars[i]; gs->api.pwsprintf(svMsg,"%d - %s >> %s[%c]:\"%s\"\n",i,vi->svCategory, vi->svVarName,vi->VarType,vi->svVarValue ); fct->IssueAuthCmdReply( gs,ctx,0,svMsg ); } fct->IssueAuthCmdReply( gs,ctx,0,str->sRplcfglistend ); return true; } bool BOAPI CmdProc_SetCfgVal( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct = &gs->fct; if ( nArg1 > gv->nPlugVars ) { fct->IssueAuthCmdReply( gs,ctx,BCC_ERR,str->sRplerrvarid ); return false; } fct->SetCfgValue( gs, nArg1, svArg2 ); fct->IssueAuthCmdReply( gs,ctx,0,str->sRplvarval ); return true; } bool BOAPI CmdProc_ListThreads( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct = &gs->fct; API *api = &gs->api; TI *ti; int i,n=0; DWORD code; char buf[100], *sStatus; // List Plugins Threads. fct->IssueAuthCmdReply( gs,ctx,0,str->sRplthrlist ); api->pEnterCriticalSection( &gv->g_PluginsCrit ); for ( i=0; i<gv->nPluginCount; i++ ) { if ( gv->PlugInfo[i]->bRunAsThread ) { ti = &gv->PlugInfo[i]->ti; // Still running? // esta corriendo? code=0; GetExitCodeThread(ti->hThread,&code); if ( code==STILL_ACTIVE && !ti->bStatus ) sStatus = "Running"; else if ( ti->bStatus ) sStatus = "Suspended"; else sStatus = "Stoped"; api->pwsprintf( buf, "%d. (%x) \"%.80s\": %s\n",n++,ti->dwThreadID,ti->svID,sStatus ); fct->IssueAuthCmdReply(gs,ctx,0,buf); } } api->pLeaveCriticalSection( &gv->g_PluginsCrit ); // List additional threads api->pEnterCriticalSection( &gv->g_ThreadsCrit ); for ( i=0; i<gv->nThreads; i++ ) { ti = gv->pThreadInfo[i]; // Still running? // esta corriendo? code=0; api->pGetExitCodeThread(ti->hThread,&code); if ( code==STILL_ACTIVE && !ti->bStatus ) sStatus = str->sRplthrrun; else if ( ti->bStatus ) sStatus = str->sRplthrsus; else sStatus = str->sRplthrstop; api->pwsprintf( buf, "%d. (%x) \"%.80s\": %s\n",n++,ti->dwThreadID,ti->svID,sStatus ); fct->IssueAuthCmdReply(gs,ctx,0,buf); } api->pLeaveCriticalSection( &gv->g_ThreadsCrit ); fct->IssueAuthCmdReply(gs,ctx,0,str->sRplthrlistend); return true; } bool BOAPI CmdProc_StopThread( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct= &gs->fct; API *api= &gs->api; TI *ti = NULL; DWORD tid,i; if (svArg2==NULL || *svArg2==0) return false; tid=fct->atodw( svArg2 ); if ( tid==0 ) { fct->IssueAuthCmdReply( gs,ctx,0,str->sRplerrthrid ); return false; } // find thread id in plugins threads api->pEnterCriticalSection( &gv->g_PluginsCrit ); for (i=0; i<gv->nPluginCount; i++) { if ( gv->PlugInfo[i]->bRunAsThread ) { ti = &gv->PlugInfo[i]->ti; if ( ti->dwThreadID==tid ) break; } } api->pLeaveCriticalSection( &gv->g_PluginsCrit ); // find the thread list api->pEnterCriticalSection( &gv->g_ThreadsCrit ); if ( i==gv->nPluginCount ) { for (i=0; i<gv->nThreads; i++) { ti = gv->pThreadInfo[i]; if ( ti->dwThreadID==tid ) break; } } api->pLeaveCriticalSection( &gv->g_ThreadsCrit ); // bad id, move away... if ( ti==NULL ) { fct->IssueAuthCmdReply(gs,ctx,0,str->sRplerrthrid); return false; } // ok, now stop thread. fct->StopThread( gs, ti ); fct->IssueAuthCmdReply( gs,ctx,0,str->sRplthrstop2 ); return true; } bool BOAPI CmdProc_StartThread( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct= &gs->fct; API *api= &gs->api; TI *ti = NULL; DWORD i,len; if (svArg2==NULL || *svArg2==0) return false; // Find Thread Name // find thread id in plugins threads len=fct->strlen(svArg2); api->pEnterCriticalSection( &gv->g_PluginsCrit ); for (i=0; i<gv->nPluginCount; i++) { if ( gv->PlugInfo[i]->bRunAsThread ) { ti = &gv->PlugInfo[i]->ti; // is this thread? if (fct->strncmp(ti->svID,svArg2,len)==0) break; } } api->pLeaveCriticalSection( &gv->g_PluginsCrit ); if (i==gv->nPluginCount) { fct->IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrthrname); return false; } if ( ti->bRunThread==true ) { fct->IssueAuthCmdReply(gs,ctx,BCC_ERR,str->sRplerrthrstart ); return false; } ti->bRunThread = true; ti->gs = gs; ti->hThread = api->pCreateThread( NULL, 0, (LPTHREAD_START_ROUTINE) ti->pThreadFunc, ti, 0, &ti->dwThreadID ); if ( ti->hThread==NULL ) { ti->bRunThread = false; fct->IssueAuthCmdReply( gs, ctx, BCC_ERR, str->sRplerrthrini ); return false; } char buf[60]; api->pwsprintf(buf, str->sRplthrstart,ti->svID); fct->IssueAuthCmdReply(gs,ctx,0,buf); return true; } bool BOAPI CmdProc_SuspendThread( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { VARS *gv = &gs->gv; FCT *fct= &gs->fct; API *api= &gs->api; TI *ti = NULL; DWORD tid,i; if (svArg2==NULL || *svArg2==0) return false; tid=fct->atodw(svArg2); if ( tid==0 ) { fct->IssueAuthCmdReply(gs,ctx,0,str->sRplerrthrid); return false; } // find thread id in plugins threads api->pEnterCriticalSection( &gv->g_PluginsCrit ); for (i=0; i<gv->nPluginCount; i++) { if ( gv->PlugInfo[i]->bRunAsThread ) { ti = &gv->PlugInfo[i]->ti; if ( ti->dwThreadID==tid ) break; } } api->pLeaveCriticalSection( &gv->g_PluginsCrit ); // find the thread list api->pEnterCriticalSection( &gv->g_ThreadsCrit ); if ( i==gv->nPluginCount ) { for (i=0; i<gv->nThreads; i++) { ti = gv->pThreadInfo[i]; if ( ti->dwThreadID==tid ) break; } } api->pLeaveCriticalSection( &gv->g_ThreadsCrit ); // bad id, move away... if ( ti==NULL ) { fct->IssueAuthCmdReply(gs,ctx,0,str->sRplerrthrid); return false; } if ( nArg1==0 && !ti->bStatus ) { // Suspend now. api->pSuspendThread( ti->hThread ); ti->bStatus=true; fct->IssueAuthCmdReply(gs,ctx,0,str->sRplthrsus2); } else if ( nArg1==1 && ti->bStatus ){ // Resume now api->pResumeThread( ti->hThread ); ti->bStatus=false; fct->IssueAuthCmdReply(gs,ctx,0,str->sRplthrres); } return true; } --- NEW FILE: main.h --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #ifndef __INC_MAIN_H #define __INC_MAIN_H #include<windows.h> #include <datatype.h> // ------------- Structures -------------------------------- // srv_control strings structures typedef struct { char *Space; // memory pointer. char *sDelete; // Msg: "delete" char *sfolsimple; // Folder commnad: "Simple" char *sfolcontrol; // Folder command: "Server Control" char *sCmdping; // Command: "Ping" char *sCmdshut; // Command: "Shutdown Server" char *sCmdrestart; // Command: "Restart Server" char *sCmdloadimg; // Commnad: "Load Plugin As Image" char *sCmdload; // Command: "Load Plugin" char *sCmdlistplg; // Command: "List Plugins" char *sCmdremvplg; // Command: "Remove Plugin" char *sCmdstarsck; // Command: "Start Command Socket" char *sCmdlistsck; // Commnad: "List Command Sockets" char *sCmdstopsck; // Command: "Stop Command Socket" char *sCmdlistvar; // Command: "List Configuration Variables" char *sCmdsetvarv; // Command: "Set Variable Value" char *sCmdlstthre; // Command: "List Threads" char *sCmdstopthr; // Command: "Stop Thread" char *sCmdstrtthr; // Command: "Start Thread" char *sCmdsuspthr; // Command: "Suspend Thread" char *sArg2shut; // Argument2: "Type 'DELETE' to ERADICATE" char *sArg2plgfile; // Argument2: "Plugin Filename" char *sArg1plgnum; // Argument1: "Plugin #" char *sArg2ioencauth; // Argmuent2: "[NETMOD][,ENC][,AUTH]" char *sArg3bindstr; // Argument3: "[Bind Str]" char *sArg1scknum; // Argument1: "Command Socket #" char *sArg1varnum; // Argument1: "Variable #" char *sArg2newval; // Argument2: "New Value" char *sArg2thrid; // Argument2: "Thread ID" char *sArg2thrname; // Argument2: "Thread Name" char *sArg1suspthr; // Argument1: "Suspend=0, Resume=1" char *sRplping; // Reply: "Hello %.255s. I'm here." char *sRpleradicate; // Reply: "Eradicating BOXP server" char *sRplshut; // Reply: "Shutting down BOXP server" char *sRplrestart; // Reply: "Restarting BOXP server" char *sRplerropen; // Reply: "Couldn't open plugin dll" char *sRplerrmem; // Reply: "Memory allocation error" char *sRplerrplug; // Reply: "Plugin could not be added" char *sRplplugadd; // Reply: "Plugin added successfully" char *sRplplugaddimg; // Reply: "Plugin added as Image successfully" char *sRplplglist; // Reply: "Plugin List:" char *sRplplglistend; // Reply: "End Of Plugins List" char *sRplerrbadplg; // Reply: "Invalid plugin number" char *sRplerrremplg; // Reply: "Plugin could not be removed" char *sRplremplg; // Reply: "Plugin removed successfully" char *sRplscknew; // Reply: "Command socket #%d created on: %.256s" char *sRplerrscknew; // Reply: "Error creating command socket" char *sRplscklist; // Reply: "Command Sockets:" char *sRplscklistend; // Reply: "End Command Socket List" char *sRplsckclose; // Reply: "Command socket closed" char *sRplsckclosedone; // Reply: "Command socket already closed" char *sRplerrsckclose; // Reply: "Command socket does not exist" char *sRplcfglist; // Reply: "Configuration Variables" char *sRplcfglistend; // Reply: "End Configuration Variables List" char *sRplerrvarid; // Reply: "Bad Variable number" char *sRplvarval; // Reply: "Variable value changed" char *sRplthrlist; // Reply: "Threads:" char *sRplthrlistend; // Reply: "End threads list" char *sRplthrrun; // Reply: "Running" char *sRplthrsus; // Reply: "Suspended" char *sRplthrstop; // Reply: "Stoped" char *sRplerrthrid; // Reply: "Bad thread ID" char *sRplthrstop2; // Reply: "Thread stoped" char *sRplerrthrname; // Reply: "Couldn't found thread name" char *sRplerrthrstart; // Reply: "Thread already started" char *sRplerrthrini; // Reply: "Couldn't Start Thread" char *sRplthrstart; // Reply: "Plugin Thread \"%.30s\" started" char *sRplthrsus2; // Reply: "Thread suspended" char *sRplthrres; // Reply: "Thread resumed" } CTRL_STR; // ------------- Function Implementations ------------------ extern HINSTANCE g_hInstance; extern BOOL g_bActive; extern CTRL_STR *str; #endif --- NEW FILE: cmd_simple.h --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #ifndef __INC_CMD_SIMPLE_H #define __INC_CMD_SIMPLE_H bool BOAPI CmdProc_Ping( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); #endif --- NEW FILE: cmd_serverctrl.h --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #ifndef __INC_CMD_SERVERCTRL_H #define __INC_CMD_SERVERCTRL_H #include <datatype.h> bool BOAPI CmdProc_ShutdownServer ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_RestartServer ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_LoadPluginDll ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_LoadPluginDllAsImage ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_ListPluginDlls ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_RemovePluginDll ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_StartCommandSocket( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_ListCommandSockets( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_StopCommandSocket( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_ListCfgVars ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_SetCfgVal ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_ListThreads ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_StopThread ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_StartThread ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); bool BOAPI CmdProc_SuspendThread ( struct GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ); #endif --- NEW FILE: cmd_simple.cpp --- /* Back Orifice XP - Remote Administration Suite Copyright (C) 2,003 - 2,004 BOXP Developers Team This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA > Autor: DilDog, dildog at users dot sourceforge dot net > Editor: Javier Aroche, j_aroche at users dot sourceforge dot net (10-Jul-03) */ #include <srv_linkage.h> #include "main.h" bool BOAPI CmdProc_Ping( GS *gs, BOCMD_CTX *ctx, DWORD nArg1, char *svArg2, char *svArg3 ) { char svLine[512]; char svAddr[256]; ctx->cas->GetRemoteAddr(ctx->cas,svAddr,256); gs->api.pwsprintf(svLine,str->sRplping,svAddr); gs->fct.IssueAuthCmdReply(gs,ctx, 0, svLine); return 0; } |