进一步学习

来源:互联网 发布:配电柜电路图软件 编辑:程序博客网 时间:2024/04/29 13:25

    以下是一段简单的进程保护程序,这个程序如果看懂了,也就不难理解为什么在计算机中毒的时候某些进程无法关掉的情况了.这个其实很简单,用到的都是一些WINDOWS的API函数,没有用到更深入的东西.通过这个程序也可以进一步学习和巩固进程快照的应用.同时在昨天也初步学习了一下WIN32汇编语言,熟练掌握这门语言也是通往信息安全专家的必经之路.

    今天也学习了PE文件结构及其简单的指令修改方法.明白了许多,理解了许多.

//进程保护

#include <windows.h>
#include <tlhelp32.h>
#include <iostream.h>

void main()
{
 int T2Flag;
 PROCESSENTRY32 pe32;
 pe32.dwSize = sizeof(pe32);
 cout<<"Test1 begins to Run and is now inspecting Test2"<<endl<<endl;
 while(1)
 {
  T2Flag = 0;
  HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
  if(hProcessSnap == INVALID_HANDLE_VALUE)
  {
   cout<<"CreateToolhelp32Snapshot 调用失败"<<endl;
   return;
  }
  BOOL bMore = ::Process32First(hProcessSnap,&pe32);
  while(bMore)
  {
   if(strcmp(pe32.szExeFile,"test2.exe") == 0)
   {
    T2Flag = 1;
    break;
   }
   bMore = ::Process32Next(hProcessSnap,&pe32);
  }
  if(T2Flag == 0)
  {
   WinExec("C://Program Files//Microsoft Visual Studio//MyProjects//test2//Debug//test2.exe",
    SW_SHOW);
   cout<<"Test1 Creates Test2 process!"<<endl;
  }
  CloseHandle(hProcessSnap);
  hProcessSnap = INVALID_HANDLE_VALUE;
  Sleep(10);
 }

//WIN32程序代码

.386
.model flat,stdcall
option casemap:none
include /masm32/include/windows.inc
include /masm32/include/kernel32.inc
include /masm32/include/user32.inc
includelib /masm32/lib/kernel32.lib
includelib /masm32/lib/user32.lib
.data
 text1 db "一个简单的win32汇编程序",0
 text2  db "使用MASM32",0
.code
start:
   invoke MessageBox,NULL,offset text1,offset text2,MB_OK
   invoke ExitProcess,NULL
end start

原创粉丝点击