本帖最后由 htpidk 于 2020-7-31 15:36 编辑
可以提取某个PE文件中作为资源存放的其他PE文件,例如提取外挂辅助或者病毒里的功能dll,具体看源码[C++] 纯文本查看 复制代码 class TiQu{
public:
TiQu(char*);
~TiQu();
int TQ();
char* buffer;
FILE* hf;
long len;
};
TiQu::TiQu(char* name){
hf=fopen(name,"rb+");
fseek(hf,0,SEEK_END);
len=ftell(hf);
buffer=new char[len];
fseek(hf,0,SEEK_SET);
fread(buffer,len,1,hf);
}
TiQu::~TiQu(){
fclose(hf);
delete[] buffer;
}
int TiQu::TQ(){
int numbers=0;//内含PE文件数量
char* PEstruct[10]={0};//存放内含的PE文件起始指针,假设文件里含有不超过10个PE文件
char* point=buffer;
do{
char M=*point;
char Z=*(point+1);
if(M=='M' && Z=='Z'){
int E_lfanew=*(int*)(point+0x3c);
if(E_lfanew>0 && E_lfanew<0x1000){//E_lfanew偏移一般很小,注意排除负数,因为读取出来的E_lfanew可能超过有符号整数范围变成负数
char P=*(point+E_lfanew);
char E=*(point+E_lfanew+1);
if(P=='P' && E=='E'){
PEstruct[numbers]=point;
numbers++;
}
}
}
point++;
}while(point<buffer+len);
//char text[30]={0};
//sprintf(text,"共找到%d个PE文件\r\n",numbers);
//MessageBox(NULL,text,"提示",MB_OK);
if(numbers>1){//如果有超过1个PE文件就提取
for(int i=1;i<numbers;++i){//从PEstruct[1]开始提取,PEstruct[0]是原文件PE结构
int E_lfanew=*(int*)(PEstruct[i]+0x3c);
PIMAGE_FILE_HEADER pfile=reinterpret_cast<PIMAGE_FILE_HEADER>(PEstruct[i]+E_lfanew+4);
WORD character=pfile->Characteristics;
int sectionnumbers=pfile->NumberOfSections;
PIMAGE_SECTION_HEADER psec=reinterpret_cast<PIMAGE_SECTION_HEADER>(PEstruct[i]+E_lfanew+sizeof(IMAGE_NT_HEADERS));
for(int j=1;j<sectionnumbers;++j){
psec++;
}
int pesize=psec->PointerToRawData+psec->SizeOfRawData;
char lujing[200]={0};
GetCurrentDirectory(200,lujing);
char filename[10]={0};
if((character&0x2000)==0x2000)
sprintf(filename,"\\%d.dll",i);
else
sprintf(filename,"\\%d.exe",i);
strcat(lujing,filename);
FILE* hfile=fopen(lujing,"wb+");
int error=GetLastError();
fwrite(PEstruct[i],pesize,1,hfile);
fclose(hfile);
std::cout<<"提取文件:"<<lujing<<"成功"<<std::endl;
}
}
return numbers;
}
int _tmain(int argc, _TCHAR* argv[])
{
char buffer[200]={0};
std::cout<<"请输入要提取的目标程序"<<std::endl;
std::cin>>buffer;
TiQu ceshi(buffer);
ceshi.TQ();
system("pause");
return 0;
}
|