Advertisement
Guest User

Untitled

a guest
Feb 19th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import re
  5. import urllib2
  6. import base64
  7.  
  8. import logging # Help with debugging
  9.  
  10.  
  11. # Basic setup
  12. logging.basicConfig(filename='log.log', level=logging.DEBUG)
  13.  
  14. url = 'http://192.168.2.4:8080'
  15. url = 'http://localhost:5005'
  16.  
  17. username = 'admin'
  18. password = 'password' # Awkward. Should really just generate the cookie and use that
  19. encodedAuth = base64.encodestring(username + ':' + password).replace('\n', '')
  20.  
  21. hash = sys.argv[1]
  22. logging.debug(hash)
  23.  
  24. hash = 'AD196E2C1E4E12EC35CC7A45F3908D66D1F604B6'
  25.  
  26.  
  27. # Get token
  28. tokenURL = url + '/gui/token.html'
  29. tokenRequest = urllib2.Request(tokenURL)
  30. tokenRequest.add_header('Authorization', 'Basic %s' % encodedAuth)
  31. print tokenRequest.get_header('Authorization')
  32. logging.debug(tokenRequest)
  33.  
  34. tokenResponse = urllib2.urlopen(tokenRequest).read()
  35.  
  36. # print tokenResponse
  37.  
  38. toSearch = "<html><div id='token' style='display:none;'>(.*)</div></html>"
  39. tokenString = re.search(toSearch, tokenResponse).group(1)
  40.  
  41. tokenString = 'IxnsQ3j2E65f4cjzjpf1GvEMVs5aOS2DD1s4XJgtyLuz8uHk5Jcq6cYXqlYAAAAA'
  42.  
  43. print tokenString
  44. # http://$server:$port/gui/?action=$removeAction\&token=$token\&hash=${lineTokens[0]}
  45. # http://localhost:8080/gui/?token=rDEQ_K-ocFLGGXMVAkME9Kwg9a1aOS2DD1s4XJgtyLuz8uHk5Jcq6bEpqlYAAAAA&action=remove&hash=214E78C2E058448F7265061DDB1596774916D947
  46. # http://localhost:5005/gui/?token=IxnsQ3j2E65f4cjzjpf1GvEMVs5aOS2DD1s4XJgtyLuz8uHk5Jcq6cYXqlYAAAAA&action=remove&hash=AD196E2C1E4E12EC35CC7A45F3908D66D1F604B6
  47.  
  48.  
  49.  
  50. # Make action request
  51. actionURL = url + '/gui/?token=' + tokenString + '&action=remove&hash=' + hash
  52. print actionURL
  53. actionRequest = urllib2.Request(actionURL)
  54. actionRequest.add_header('Authorization', 'Basic %s' % encodedAuth)
  55.  
  56. actionResponse = urllib2.urlopen(actionRequest)
  57. logging.debug(actionURL)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement