Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 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.  
  23. except Exception, e:
  24. print e #"Error: " + str(e)
  25. return None
  26.  
  27. server = 'https://192.168.37.51'
  28. username = 'rapid7'
  29. password = 'password'
  30. token = ''
  31. cookie = ''
  32.  
  33. # First login to the server using the auth module with the login action. The
  34. # server's response will include a token and a cookie that needs to be used on
  35. # subsequent requests.
  36. input = {'username': username, 'password': password}
  37. resp = connect('auth', 'login', input)
  38. token = resp['token']
  39. cookie = resp['sessionID']
  40.  
  41. # After setting the token and cookie we can use the rest of the API as normal.
  42. # Query the SC server to get the first 10 critical and high vulnerabilities.
  43. filters = [{'filterName': 'severity',
  44. 'operator': '=',
  45. 'value': '4,3'}]
  46.  
  47. input = {'tool': 'vulndetails',
  48. 'sourceType': 'cumulative',
  49. 'filters': filters,
  50. 'startOffset': 0,
  51. 'endOffset': 10}
  52.  
  53. vulns = connect('vuln', 'query', input)
  54. for vuln in vulns['results']:
  55. print 'IP: ' + vuln['ip']
  56. print 'Name: ' + vuln['pluginName']
  57. print 'Severity: ' + vuln['severity']
  58. print
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement