Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. !/usr/bin/env python
  2.  
  3. import urllib2
  4. import urllib
  5. import json
  6.  
  7. def connect(module, action, input={}):
  8. data = {'module': module,
  9. 'action': action,
  10. 'input': json.dumps(input),
  11. 'token': token,
  12. 'request_id': 1}
  13.  
  14. headers = {'Cookie': 'TNS_SESSIONID=' + cookie}
  15.  
  16. url = server + '/request.php'
  17. try:
  18. request = urllib2.Request(url, urllib.urlencode(data), headers)
  19. response = urllib2.urlopen(request)
  20. content = json.loads(response.read())
  21. return content['response']
  22. except Exception, e:
  23. print "Error: " + str(e)
  24. return None
  25. server = 'https://192.168.37.51'
  26. username = 'rapid7'
  27. password = 'password'
  28. token = ''
  29. cookie = ''
  30.  
  31. '''First login to the server using the auth module with the login action. The
  32. server's response will include a token and a cookie that needs to be used on
  33. subsequent requests.
  34. '''
  35.  
  36. input = {'username': username, 'password': password}
  37. resp = connect('auth', 'login', input)
  38. token = resp['token']
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement