返回列表 发帖

[讨论]编写实时监控程序

    偶的FTP不想让别人上传除图片以外的东西。。可Sevr U并没有提供文件类型过滤,所以偶想请教编程达人,怎么通过外挂程序实现这一功能!
谢谢!
以前偶申请过外国的空间,只能放*.cgi的文件。

[讨论]编写实时监控程序

呃,对不起,楼上的兄弟,偶打错字了,导致你的误会,对不起!
非常感谢两位热心的讨论,偶对编程了解不是太多,可以说一点都不懂,所以,哈哈,二位的代码偶是看不懂啊!只能从二位的讲解中揣摸一二。

TOP

[讨论]编写实时监控程序

[这个贴子最后由无条件为你在 2006/04/11 08:30pm 第 1 次编辑]

X86版主的程序太专业了,我看不懂也无法发表评论。如果我的言语有冒犯之处,恳请批评!

TOP

[讨论]编写实时监控程序

我记得ftp 中有2个 控制线程的,一个负责命令控制,一个负责数据传输.
关键是把那个命令控制的一些特殊的命令拦截并解析出来,然后再做相应的处理就应该可以的.

TOP

[讨论]编写实时监控程序

只是没拦对函数而已,不代表不实用哦:)

TOP

[讨论]编写实时监控程序

[这个贴子最后由chinanic在 2006/04/11 06:12pm 第 1 次编辑]

偶没误解什么哇,偶也想在外面买个实惠的空间,只是找了很多都不是很满意。
怪不得找不到,原来在上面去了,小眼拙,眼拙哇!

小生一时打错字,造成了莫大的误会,请兄弟原谅!

TOP

[讨论]编写实时监控程序

     楼上的朋友误解了,我只是问问,我不要,因为我有200M的网络空间,收费的,去年买的。用着不错!如果你需要上传文件我还可以帮忙。
     我觉得X86这种方法并不如我上次讲的那种方法好用,技术比我的强我承认,但不实用啊。
     找不到我的贴?我那个贴子固顶了。

TOP

[讨论]编写实时监控程序

下面引用由无条件为你2006/04/11 01:56pm 发表的内容:
API函数功能很强大。楼主不妨学学,很有趣的呢,我以前许多程序都是通过API来实现的。
     你的意思是只允许上传图片,其实这个不难实现。不过我告诉你,你是在徙劳,至少应该说是永远也达不到理想状态,或者说 ...

这位兄弟,偶一是想学点技术,二是解决目前应用上的安全问题,在学校估计还没几个有能耐乱搞的,偶的空间是学校的,卖不了钱,就是送你也不会要的,因为外网很难访问。。。。

TOP

[讨论]编写实时监控程序

下面引用由无条件为你2006/04/11 04:23pm 发表的内容:
X86的程序不错,不过我登录QQ前输入QQ的ID,结果弹出了好多的消息框。
这个程序编译的时候好像用的是DEBUG方式,所以生成的文件过大,我用C++编写程序的时候从来没有生成过这么大的文件,除非在程序中加入了另一 ...
一些复杂一点的程序,调用createfile的次数比较多,我保存一个画图也会弹出很多,
所以,真正想发挥作用的话,还是要复习下ftp的一些原理,然后针对他特有的一些程序行为进行监控和拦截.
呵呵,不过方法还是 一样,,大体就是这样的:)

TOP

[讨论]编写实时监控程序

是啊,也可以用那种方法,
发现了就及时删除!

TOP

[讨论]编写实时监控程序

下面引用由无条件为你2006/04/11 04:58pm 发表的内容:
关于监控指定目录的程序我上次不是写出来了吗?只不过效率不是太高,但可以定时运行,不用常常运行的。

兄弟,上次那帖子。。。哪去了???

TOP

[讨论]编写实时监控程序

下面引用由x862006/04/11 04:55pm 发表的内容: #include
#include
#include
#pragma comment(lib, "psapi.lib")
#pragma comment(lib, "ws2_32.lib" ...
强!还用到了汇编。我看我还是不看了,看也看不懂了。。。

TOP

[讨论]编写实时监控程序

下面引用由chinanic2006/04/11 04:52pm 发表的内容:
谢谢86的热心,但这样仅是对FTP的监控,并没有实现监控指定的目录。
PS:偶说的FTP是在本地,即应用在服务器上的FTP程序。
监视指定的程序啊,比如你的ftp服务软件,这样他在创建任何文件的时候(比如对方append一个文件,他都会使用createfile),就会拦截,然后会弹出对话框询问是否允许创建.跟目录没有关系.

TOP

[讨论]编写实时监控程序

关于监控指定目录的程序我上次不是写出来了吗?只不过效率不是太高,但可以定时运行,不用常常运行的。

TOP

[讨论]编写实时监控程序

#include #include #include #pragma comment(lib, "psapi.lib") #pragma comment(lib, "ws2_32.lib") typedef struct _RemoteParam { DWORD dwCreateFile; DWORD dwMessageBox; DWORD dwGetCurrentProcess; DWORD dwWriteProcessMemory; unsigned char szOldCode[10]; DWORD FunAddr; } RemoteParam, * PRemoteParam; typedef HANDLE (__stdcall * PFN_CREATEFILE)(LPCTSTR,DWORD,DWORD,LPSECURITY_ATTRIBUTES,DWORD,DWORD,HANDLE); typedef int (__stdcall * PFN_MESSAGEBOX)(HWND, LPCTSTR, LPCTSTR, DWORD); typedef BOOL (__stdcall * PFN_WRITEPROCESSMEMORY)(HANDLE,LPVOID,LPCVOID,SIZE_T,SIZE_T*); typedef HANDLE (__stdcall * PFN_GETCURRENTPROCESS)(void); #define PROCESSNUM 128 #define MYMESSAGEBOX "MessageBoxW" #define MYCREATEFILE "CreateFileW" void HookCreateFile(LPVOID lParam) { RemoteParam* pRP = (RemoteParam*)lParam; DWORD NextIpAddr = 0; DWORD dwParamaAddr = 0; HANDLE RetFpHdl = INVALID_HANDLE_VALUE; LPCTSTR lpFileName; DWORD dwDesiredAccess; DWORD dwShareMode; LPSECURITY_ATTRIBUTES lpSecurityAttributes; DWORD dwCreationDisposition; DWORD dwFlagsAndAttributes; HANDLE hTemplateFile; PFN_CREATEFILE pfnCreatefile = (PFN_CREATEFILE)pRP->dwCreateFile; __asm { MOV EAX,[EBP+8] MOV [dwParamaAddr], EAX MOV EAX,[EBP+12] MOV [NextIpAddr], EAX MOV EAX,[EBP+16] MOV [lpFileName], EAX MOV EAX,[EBP+20] MOV [dwDesiredAccess],EAX MOV EAX,[EBP+24] MOV [dwShareMode],EAX MOV EAX,[EBP+28] MOV [lpSecurityAttributes],EAX MOV EAX,[EBP+32] MOV [dwCreationDisposition],EAX MOV EAX,[EBP+36] MOV [dwFlagsAndAttributes],EAX MOV EAX,[EBP+40] MOV [hTemplateFile],EAX } PFN_MESSAGEBOX pfnMessageBox = (PFN_MESSAGEBOX)pRP->dwMessageBox; int allowFlag = pfnMessageBox(NULL, lpFileName, NULL, MB_ICONINFORMATION | MB_YESNO); if(allowFlag == IDYES) { unsigned char szNewCode[10]; int PramaAddr = (int)dwParamaAddr; szNewCode[4] = PramaAddr>>24; szNewCode[3] = (PramaAddr<<8)>>24; szNewCode[2] = (PramaAddr<<16)>>24; szNewCode[1] = (PramaAddr<<24)>>24; szNewCode[0] = 0x68; int funaddr = (int)pRP->FunAddr - (int)pfnCreatefile - 10 ; szNewCode[9] = funaddr>>24; szNewCode[8] = (funaddr<<8)>>24; szNewCode[7] = (funaddr<<16)>>24; szNewCode[6] = (funaddr<<24)>>24; szNewCode[5] = 0xE8; PFN_GETCURRENTPROCESS pfnGetCurrentProcess = (PFN_GETCURRENTPROCESS)pRP->dwGetCurrentProcess; PFN_WRITEPROCESSMEMORY pfnWriteProcessMemory = (PFN_WRITEPROCESSMEMORY)pRP->dwWriteProcessMemory; pfnWriteProcessMemory(pfnGetCurrentProcess(), (LPVOID)pfnCreatefile, (LPCVOID)pRP->szOldCode, 10, NULL); RetFpHdl = pfnCreatefile(lpFileName, dwDesiredAccess, dwShareMode, lpSecurityAttributes, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile); pfnWriteProcessMemory(pfnGetCurrentProcess(), (LPVOID)pfnCreatefile, (LPCVOID)szNewCode, 10, NULL); } __asm {POP EDI POP ESI POP EBX MOV EDX, [NextIpAddr] MOV EAX, [RetFpHdl] MOV ESP, EBP POP EBP ADD ESP, 28H PUSH EDX RET } } BOOL AdjustProcessPrivileges(LPCSTR szPrivilegesName) { HANDLE hToken; TOKEN_PRIVILEGES tkp; if(!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken)) { return FALSE; } if(!LookupPrivilegeValue(NULL,szPrivilegesName, &tkp.Privileges[0].Luid)) { CloseHandle(hToken); return FALSE; } tkp.PrivilegeCount = 1; tkp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED; if(!AdjustTokenPrivileges(hToken,FALSE,&tkp,sizeof(tkp),NULL,NULL)) { CloseHandle(hToken); return FALSE; } CloseHandle(hToken); return TRUE; } void printProcessNameByPid( DWORD ProcessId ) { HANDLE pHd; HMODULE pHmod; char ProcessName[MAX_PATH] = "unknown"; DWORD cbNeeded; pHd = OpenProcess( PROCESS_ALL_ACCESS, FALSE, ProcessId ); if(pHd == NULL) return; if(!EnumProcessModules( pHd, &pHmod, sizeof(pHmod), &cbNeeded)) return; if(!GetModuleFileNameEx( pHd, pHmod, ProcessName, MAX_PATH)) return; printf( "%d\t%s\n", ProcessId, ProcessName); CloseHandle( pHd ); return; } int main(void) { if(!AdjustProcessPrivileges(SE_DEBUG_NAME)) { printf("AdjustProcessPrivileges Error!\n"); return -1; } DWORD Pids[PROCESSNUM]; DWORD dwProcessNum = 0; if(!EnumProcesses(Pids, sizeof(Pids), &dwProcessNum)) { printf("EnumProcess Error!\n"); return -1; } for( DWORD num = 0; num < (dwProcessNum / sizeof(DWORD)); num++) printProcessNameByPid(Pids[num]); printf("\nAll %d processes running. \n", dwProcessNum / sizeof(DWORD)); DWORD dwPid = 0; printf("\n请输入要拦截的进程id:"); scanf("%d", &dwPid); HANDLE hTargetProcess = OpenProcess(PROCESS_ALL_ACCESS, FALSE, dwPid); if(hTargetProcess == NULL) { printf("OpenProcess Error!\n"); return -1; } DWORD dwFunAddr = (DWORD)VirtualAllocEx(hTargetProcess, NULL, 8192, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if((LPVOID)dwFunAddr == NULL) { printf("申请线程内存失败!\n"); CloseHandle(hTargetProcess); return -1; } DWORD dwPramaAddr = (DWORD)VirtualAllocEx(hTargetProcess, NULL, sizeof(RemoteParam), MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); if((LPVOID)dwPramaAddr == NULL) { printf("申请参数内存失败!\n"); CloseHandle(hTargetProcess); return -1; } printf("\n线程内存地址:%.8x\n" "参数内存地址:%.8x\n", dwFunAddr, dwPramaAddr); RemoteParam RParam; ZeroMemory(&RParam, sizeof(RParam)); HMODULE hKernel32 = LoadLibrary("kernel32.dll"); HMODULE hUser32 = LoadLibrary("user32.dll"); RParam.dwCreateFile = (DWORD)GetProcAddress(hKernel32, MYCREATEFILE); RParam.dwGetCurrentProcess = (DWORD)GetProcAddress(hKernel32, "GetCurrentProcess"); RParam.dwWriteProcessMemory = (DWORD)GetProcAddress(hKernel32, "WriteProcessMemory"); RParam.dwMessageBox = (DWORD)GetProcAddress(hUser32, MYMESSAGEBOX); unsigned char oldcode[10]; unsigned char newcode[10]; int praadd = (int)dwPramaAddr; int threadadd = (int)dwFunAddr; newcode[4] = praadd>>24; newcode[3] = (praadd<<8)>>24; newcode[2] = (praadd<<16)>>24; newcode[1] = (praadd<<24)>>24; newcode[0] = 0x68; int offsetaddr = threadadd - (int)RParam.dwCreateFile - 10 ; newcode[9] = offsetaddr>>24; newcode[8] = (offsetaddr<<8)>>24; newcode[7] = (offsetaddr<<16)>>24; newcode[6] = (offsetaddr<<24)>>24; newcode[5] = 0xE8; printf("NewCode:"); for(int j = 0; j < 10; j++) printf("0x%.2x ",newcode[j]); printf("\n\n"); if(!ReadProcessMemory(GetCurrentProcess(), (LPCVOID)RParam.dwCreateFile, oldcode, 10, &dwPid)) { printf("read error"); CloseHandle(hTargetProcess); FreeLibrary(hKernel32); return -1; } strcat((char*)RParam.szOldCode, (char*)oldcode); RParam.FunAddr = dwFunAddr; printf( "RParam.dwCreate文件:%.8x\n" "RParam.dwMessageBox:%.8x\n" "RParam.dwGetCurrentProcess:%.8x\n" "RParam.dwWriteProcessMemory:%.8x\n" "RParam.FunAddr:%.8x\n", RParam.dwCreateFile, RParam.dwMessageBox, RParam.dwGetCurrentProcess, RParam.dwWriteProcessMemory, RParam.FunAddr); printf("RParam.szOldCode:"); for( int i = 0; i< 10; i++) printf("0x%.2x ", RParam.szOldCode); printf("\n"); if(!WriteProcessMemory(hTargetProcess, (LPVOID)dwFunAddr, (LPVOID)&HookCreateFile, 8192, &dwPid)) { printf("WriteRemoteProcessesMemory Error!\n"); CloseHandle(hTargetProcess); FreeLibrary(hKernel32); return -1; } if(!WriteProcessMemory(hTargetProcess, (LPVOID)dwPramaAddr, (LPVOID)&RParam, sizeof(RemoteParam), &dwPid)) { printf("WriteRemoteProcessesMemory Error!\n"); CloseHandle(hTargetProcess); FreeLibrary(hKernel32); return -1; } if(!WriteProcessMemory(hTargetProcess, (LPVOID)RParam.dwCreateFile, (LPVOID)newcode, 10, &dwPid)) { printf("WriteRemoteProcessesMemory Error!\n"); CloseHandle(hTargetProcess); FreeLibrary(hKernel32); return -1; } printf("\nThat';s all, good luck :)\n"); CloseHandle(hTargetProcess); FreeLibrary(hKernel32); return 0; }

TOP

返回列表 回复 发帖