|
|
|
菜鸟请教简单加壳问题
好的,我这就贴啊。我是怕大家不耐烦看。 .data szFilter db "PE files(*.exe, *.dll)", 0, "*.exe;*.dll", 0, "All files(*.*)", 0, "*.*", 0, 0 szCaption db "test packer by thirdlee", 0 szOpenFileErr db "打开文件失败!", 0 szNotPEFile db "该文件不是PE文件!", 0 szSectionName db ".lee", 0 szModified db "这个文件已经被我修改过了。", 0 szBackup db ".bak", 0 szMemErr db "申请内存失败!", 0 szOver db "修改完毕!", 0 szEncryptSec db ".text", 0 pShellMap dd 0 pSecMap dd 0 dwSecOffset dd 0 dwSecSize dd 0 dwSecVirtualAddr dd 0 dwRWSize dd 1024*60 dwCount dd 0 .data? ofn OPENFILENAME <> hInst dd ? szFileName db MAX_PATH dup (?) hFile HANDLE ? dosh IMAGE_DOS_HEADER <> nth IMAGE_NT_HEADERS32 <> sech IMAGE_SECTION_HEADER <> szFileBackup db MAX_PATH dup (?) .code main: ;获取实例句柄 invoke GetModuleHandle, eax mov hInst, eax ;填充打开文件对话框的结构体 mov ofn.hInstance, eax mov ofn.lStructSize, sizeof ofn mov ofn.lpstrFilter, offset szFilter mov ofn.lpstrFile, offset szFileName ;用来保存选中的文件名(含路径) mov ofn.nMaxFile, sizeof szFileName ;调用通用的打开文件对话框 invoke GetOpenFileName, offset ofn .if eax == 0 invoke ExitProcess, 0 .endif ;打开文件 invoke CreateFile, offset szFileName, GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ \ or FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL .if eax == INVALID_HANDLE_VALUE invoke MessageBox, NULL, offset szOpenFileErr, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif mov hFile, eax invoke ReadFile, hFile, offset dosh, sizeof IMAGE_DOS_HEADER, esp, 0 .if dosh.e_magic != IMAGE_DOS_SIGNATURE invoke CloseHandle, hFile invoke MessageBox, NULL, offset szNotPEFile, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif invoke SetFilePointer, hFile, dosh.e_lfanew, NULL, FILE_BEGIN invoke ReadFile, hFile, offset nth, sizeof IMAGE_NT_HEADERS32, esp, 0 .if nth.Signature != IMAGE_NT_SIGNATURE invoke CloseHandle, hFile invoke MessageBox, NULL, offset szNotPEFile, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif movzx ecx, nth.FileHeader.NumberOfSections xor ebx, ebx xor edx, edx ReadSection: push ecx push ebx push edx invoke ReadFile, hFile, offset sech, sizeof IMAGE_SECTION_HEADER, esp, 0 invoke lstrcmp, offset szSectionName, offset sech.Name1 .if eax == 0 invoke CloseHandle, hFile invoke MessageBox, NULL, offset szModified, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif ;获取要加密节的相关信息 invoke lstrcmp, offset szEncryptSec, offset sech.Name1 .if eax == 0 push sech.PointerToRawData pop dwSecOffset push sech.SizeOfRawData pop dwSecSize mov dwSecSize, 10h push sech.VirtualAddress pop dwSecVirtualAddr mov eax, nth.OptionalHeader.ImageBase add dwSecVirtualAddr, eax mov sech.Characteristics, 0E00000E0h mov eax, sizeof IMAGE_SECTION_HEADER neg eax invoke SetFilePointer, hFile, eax, NULL, FILE_CURRENT invoke WriteFile, hFile, offset sech, sizeof IMAGE_SECTION_HEADER, esp, 0 .endif pop edx mov eax, sech.PointerToRawData add eax, sech.SizeOfRawData mov edx, eax pop ebx mov eax, sech.VirtualAddress add eax, sech.Misc.VirtualSize mov ebx, eax pop ecx dec ecx .if ecx > 0 jmp ReadSection .endif pushad ;这个文件没有被改过,在改之前先备份 invoke lstrcpy, offset szFileBackup, offset szFileName invoke lstrcat, offset szFileBackup, offset szBackup invoke CopyFile, offset szFileName, offset szFileBackup, FALSE ;给新加的节赋名称 invoke lstrcpy, offset sech.Name1, offset szSectionName popad mov eax, ShellSize mov sech.Misc.VirtualSize, eax mov sech.VirtualAddress, ebx mov sech.PointerToRawData, edx mov sech.SizeOfRawData, eax mov sech.PointerToRelocations, ecx mov sech.PointerToLinenumbers, ecx mov dword ptr sech.NumberOfRelocations, ecx ;文件按块对齐 xor edx, edx mov eax, sech.SizeOfRawData mov ebx, 1ffh idiv ebx .if edx != 0 sub edx, 200h neg edx add sech.SizeOfRawData, edx .endif ;节对齐 mov ebx, sech.VirtualAddress mov edx, 00000fffh and ebx, edx .if ebx != 0 sub ebx, 1000h neg ebx add sech.VirtualAddress, ebx .endif ;修改节属性 mov sech.Characteristics, 0E00000E0h ;写入新的节头信息 invoke WriteFile, hFile, offset sech, sizeof IMAGE_SECTION_HEADER, esp, 0 ;申请内存来读第一个节数据 invoke VirtualAlloc, NULL, dwSecSize, MEM_COMMIT, PAGE_READWRITE .if eax == NULL invoke CloseHandle, hFile invoke MessageBox, NULL, offset szMemErr, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif mov pSecMap, eax ;读入第一个节 push 0 pop dwCount invoke SetFilePointer, hFile, dwSecOffset, NULL, FILE_BEGIN mov eax, dwSecSize xor edx,edx idiv dwRWSize mov ecx, eax mov eax, pSecMap add eax, dwCount @@ReadSecData: .if ecx > 0 push edx invoke ReadFile, hFile, eax, dwRWSize, esp, 0 pop edx add eax, dwRWSize dec ecx jmp @@ReadSecData .endif .if edx != 0 invoke ReadFile, hFile, eax, edx, esp, 0 .endif ;对读出的数据进行加密处理 push 0 pop dwCount mov ecx, dwSecSize mov eax, pSecMap add eax, dwCount @@Crypt: xor byte ptr [eax], 1 inc eax loop @@Crypt ;把数据写回去 push 0 pop dwCount invoke SetFilePointer, hFile, dwSecOffset, NULL, FILE_BEGIN mov eax, dwSecSize xor edx, edx idiv dwRWSize mov ecx, eax mov eax, pSecMap add eax, dwCount @@WriteSecData: .if ecx > 0 push edx invoke WriteFile, hFile, eax, dwRWSize, esp, 0 pop edx add eax, dwRWSize dec ecx jmp @@WriteSecData .endif .if edx != 0 invoke WriteFile, hFile, eax, edx, esp, 0 .endif ;释放申请的内存空间 invoke VirtualFree, pSecMap, 0, MEM_RELEASE inc nth.FileHeader.NumberOfSections mov eax, sech.Misc.VirtualSize add nth.OptionalHeader.SizeOfImage, eax mov edx, 00000fffh and eax, edx .if eax != 0 sub eax, 1000h neg eax add nth.OptionalHeader.SizeOfImage, eax .endif ;去掉bound import ;(88)表示11*8, 即 DataDirectory[11] push 0 pop nth.OptionalHeader.DataDirectory(88).VirtualAddress ;拷贝壳代码 invoke VirtualAlloc, NULL, ShellSize, MEM_COMMIT, PAGE_READWRITE .if eax == NULL invoke CloseHandle, hFile invoke MessageBox, NULL, offset szMemErr, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 .endif mov pShellMap, eax push dwSecVirtualAddr push dwSecSize mov ecx, ShellSize mov esi, ShellStart mov edi, offset pShellMap rep movsb pop dwSecSize pop dwSecVirtualAddr ;保存旧入口地址 mov eax, dword ptr nth.OptionalHeader.AddressOfEntryPoint add eax, dword ptr nth.OptionalHeader.ImageBase mov ebx, offset OldOep - offset ShellStart add ebx, offset pShellMap mov dword ptr[ebx], eax ;保存第一个节表的虚拟地址 mov eax, dwSecVirtualAddr mov ebx, offset SecStart - offset ShellStart add ebx, offset pShellMap mov dword ptr [ebx], eax ;保存第一个节的大小 mov eax, dwSecSize mov ebx, offset SecSize - offset ShellStart add ebx, offset pShellMap mov dword ptr [ebx], eax ;写入新的入口地址 mov eax, sech.VirtualAddress add eax, ShellCodeStart - ShellStart + 4 mov nth.OptionalHeader.AddressOfEntryPoint, eax invoke SetFilePointer, hFile, dosh.e_lfanew, NULL, FILE_BEGIN invoke WriteFile, hFile, offset nth, sizeof IMAGE_NT_HEADERS32, esp, 0 mov eax, sech.PointerToRawData push eax invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN mov eax, ShellSize invoke WriteFile, hFile, offset pShellMap, eax, esp, 0 invoke VirtualFree, pShellMap, 0, MEM_RELEASE pop eax add eax, sech.SizeOfRawData dec eax invoke SetFilePointer, hFile, eax, NULL, FILE_BEGIN invoke WriteFile, hFile, offset szCaption, 1, esp, 0 invoke CloseHandle, hFile invoke MessageBox, NULL, offset szOver, offset szCaption, MB_OK or MB_ICONINFORMATION invoke ExitProcess, 0 end main |
|
菜鸟请教简单加壳问题
改了节属性后就可以了。 但又遇到一个非常奇怪的问题,我对.text节的前16个字节分别加1,在外壳里不作任何处理,被加壳的程序可以正常运行,如果在外壳里对这16个字节分别减1,则不能正常运行。我用ultraedit看了加壳前后的两个可执行程序,相应位置的16个字节确实存在1的差异。但是用softICE调试时发现内存里的相应位置的值是加1前的值,所以做减1操作反而使它不对了。 简而言之,就是原来是C8,加1后用ultraedit看是C9,用softICE调试发现值还是C8,因此外壳中不作减1处理反而能正常运行。我是给notepad.exe做加壳的。 |
|
菜鸟请教简单加壳问题
那个SecStart是被加壳程序的一个节首地址,我是想将一个被加壳程序的某个节全部内容按字节与一个数进行异或,将被加壳程序的入口地址,节首地址和大小存入外壳,然后从外壳开始执行,就是从节首地址开始,再异或回来,然后跳到原入口地址执行,就是这样。必须要该引入表吗?这样是不行的是吧?我没有改节属性,我改一下试试。 |
|
有没有完全用C/C++实现的加壳源代码?
正是针对x86的二进制可执行文件进行代码混淆,增加反汇编的难度以及阅读反汇编代码的难度。不知有没有搞头啊? 接触汇编没多久(一个多月),以前都是搞C/C++的。单条汇编指令都还认识,长篇大论的汇编指令就头大,见笑啊。。。 有搞过目标代码混淆的大侠们,还请不吝赐教,传授点经验啊。谢谢先! |
|
有没有完全用C/C++实现的加壳源代码?
原来看雪大哥也是这么认为啊。这两天我也一直在想这个问题,但是导师要我搞什么代码混淆啊,目标代码的混淆,不是时下流行的中间代码或源代码混淆,不知看雪大哥对这个有什么建议? |
|
有没有完全用C/C++实现的加壳源代码?
找到了。谢谢。不好意思啊,最近看书看得有点烦。 还问一个,书上讲的花指令好象是在壳之前插入的是吧?能不能在.text中任意插入花指令呢?(当然是在不影响上下文要用到的寄存器的值的情况下),其实我想问的是如果任意插入后,程序中的某些 调用,跳转指令 所指向的地址是不是有可能因为新插入指令而发生变化,是不是要逐一修改过来?有没有这样做过? |
操作理由
RANk
{{ user_info.golds == '' ? 0 : user_info.golds }}
雪币
{{ experience }}
课程经验
{{ score }}
学习收益
{{study_duration_fmt}}
学习时长
基本信息
荣誉称号:
{{ honorary_title }}
能力排名:
No.{{ rank_num }}
等 级:
LV{{ rank_lv-100 }}
活跃值:
在线值:
浏览人数:{{ visits }}
最近活跃:{{ last_active_time }}
注册时间:{{ user_info.create_date_jsonfmt }}
勋章
兑换勋章
证书
证书查询 >
能力值