Advertisement
Guest User

Untitled

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