返回列表 发帖

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

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

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

在你自己机器上就可以...
拦截createfilea和createfilew这两个api,然后对其参数进行判断,如果新建的文件后缀不是图片类型,就让他返回失败,否则则不管他.[br][br]-=-=-=-=- 以下内容由 x862006年04月11日 00:47pm 时添加 -=-=-=-=-
如果需要,而且是在自己机器上,可以帮你写一个:)

TOP

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

:14: 挺高深的。。。偶对API不熟悉的说,用VB行吗?

TOP

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

不高深,
用vb也要用api啊.
你是不是在本地机器了?是的话,偶待会儿把程序贴出来.
你把允许的图片类型帖出来咯...

TOP

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

     API函数功能很强大。楼主不妨学学,很有趣的呢,我以前许多程序都是通过API来实现的。
     你的意思是只允许上传图片,其实这个不难实现。不过我告诉你,你是在徙劳,至少应该说是永远也达不到理想状态,或者说你只能成功一半。我以前喜欢做网页木马,现在洗手不干了,给你这么解释吧:JPG图片可以集成木马程序,当然也可以代替HTML文件,这就是说,明明访问的是以JPG为扩展名的文件,但去执行的是一个网页文件,当然里面也可以加载任何东西了。
     不过,你限止一下还是好些,必定不是每个人都整天在搞病毒。
     楼主,看来你空间不少啊?出售的吗?20MB多少钱?

TOP

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

对于楼主的要求,偶分析得不够,
首先是作为一个ftp服务程序,与文件打交道的时候很多,如果单纯拦截createfile 的话,会给使用者带来一些麻烦,因为太多的功能需要使用这个函数,比如下载文件,管理文件等等.
不过我还是简单写了一个拦截createfile的,对于一些软件可以很好的拦截,但是对于ftp软件,由于本人机器上没有该程序,没有进行测试,你也 可以先试一下,就是运行后,输入你的ftp软件的进程id,然后每当你的ftp打开文件句柄的时候(比如创建文件,读文件,写文件,等等),都会弹出一个是否允许打开该句柄的对话框,点yes,则允许进行一些文件操作,否则就不允许进行这些操作了...
如果结果是那种,会谈出许多对话框的话,这样使用起来就会比较麻烦,你要一个一个地去点,这时候就需要对ftp的网络原理进行一些了解,才能抓住最关键的要点进行拦截,我想这样效率会比较高!

TOP

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

X86的程序不错,不过我登录QQ前输入QQ的ID,结果弹出了好多的消息框。
这个程序编译的时候好像用的是DEBUG方式,所以生成的文件过大,我用C++编写程序的时候从来没有生成过这么大的文件,除非在程序中加入了另一个程序。建议X86改为Release生成方式。

TOP

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

把源码贴出来好吗?

TOP

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

谢谢86的热心,但这样仅是对FTP的监控,并没有实现监控指定的目录。
PS:偶说的FTP是在本地,即应用在服务器上的FTP程序。

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

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

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

TOP

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

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

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

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

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

TOP

返回列表 回复 发帖