rapid7 / nexpose-client-python

DEPRECATED : Rapid7 Nexpose API client library written in Python
https://www.rapid7.com/
BSD 3-Clause "New" or "Revised" License
25 stars 20 forks source link

GetFilteredAssets fails with "HTTP Error 500: Internal Server Error" #5

Closed santsys closed 7 years ago

santsys commented 7 years ago

Expected Behavior

The call to GetFilteredAssets should return a list of assets matching the specified criteria.

Current Behavior

The call to GetFilteredAssets returns with the following error.

  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1395, in GetFilteredAssets
    result = self.ExecuteGetRecords('data/asset/filterAssets', filter_or_criteria_or_criterion)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1201, in ExecuteGetRecords
    raw_data = self.ExecuteFormPost(sub_url, filter_data)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1176, in ExecuteFormPost
    return ExecuteWithPostData_FORM(self._session_id, self._URI_root, sub_url, self.timeout, post_data)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 96, in ExecuteWithPostData_FORM
    return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, lambda: 'POST')
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 52, in ExecuteWebRequest
    response = OpenWebRequest(uri, post_data, headers, timeout, get_method)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 48, in OpenWebRequest
    response = urllib2.urlopen(request, timeout=timeout)
  File "W:\Python27\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "W:\Python27\lib\urllib2.py", line 435, in open
    response = meth(req, response)
  File "W:\Python27\lib\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "W:\Python27\lib\urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "W:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "W:\Python27\lib\urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error

Python code that reproduces the issue:

SESSION = nexpose.NexposeSession.Create(host, port, user, pwd)
SESSION.Open()

n_criteria = Criterion.Create(nexpose.Criteria.RISK_SCORE, nexpose.Criteria.GREATER_THAN, minRiskScore)
n_filter = AssetFilter(n_criteria)
n_assets = SESSION.GetFilteredAssets(n_filter)

Context

Attempting to get a list of all assets that have been scanned and have a risk score over a certain value.

Your Environment

gschneider-r7 commented 7 years ago

Haven't had a chance to try this myself yet, but are you able to capture the error log message from nsc.log @santsys? You can find it at [install path]/nsc/logs/nsc.log and you should see an error message with something like Unexpected error occurred with a stack trace. If you can please post it here. Thanks!

santsys commented 7 years ago

@gschneider-r7 I don't see a nsc folder and there doesn't appear to be a nsc.log file on my system (that I can find anyways).

This is the stack trace I get from within my application. If there is something you want me to run to get more details, just let me know. Happy to do so.

File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1395, in GetFilteredAssets
    result = self.ExecuteGetRecords('data/asset/filterAssets', filter_or_criteria_or_criterion)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1201, in ExecuteGetRecords
    raw_data = self.ExecuteFormPost(sub_url, filter_data)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 1176, in ExecuteFormPost
    return ExecuteWithPostData_FORM(self._session_id, self._URI_root, sub_url, self.timeout, post_data)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 96, in ExecuteWithPostData_FORM
    return ExecuteWebRequest(uri + sub_url, post_data, headers, timeout, lambda: 'POST')
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 52, in ExecuteWebRequest
    response = OpenWebRequest(uri, post_data, headers, timeout, get_method)
  File "W:\Python27\lib\site-packages\nexpose\nexpose.py", line 48, in OpenWebRequest
    response = urllib2.urlopen(request, timeout=timeout)
  File "W:\Python27\lib\urllib2.py", line 154, in urlopen
    return opener.open(url, data, timeout)
  File "W:\Python27\lib\urllib2.py", line 435, in open
    response = meth(req, response)
  File "W:\Python27\lib\urllib2.py", line 548, in http_response
    'http', request, response, code, msg, hdrs)
  File "W:\Python27\lib\urllib2.py", line 473, in error
    return self._call_chain(*args)
  File "W:\Python27\lib\urllib2.py", line 407, in _call_chain
    result = func(*args)
  File "W:\Python27\lib\urllib2.py", line 556, in http_error_default
    raise HTTPError(req.get_full_url(), code, msg, hdrs, fp)
HTTPError: HTTP Error 500: Internal Server Error

Thanks.

gschneider-r7 commented 7 years ago

Oh sorry I meant the nsc.log from your Nexpose console. It should have a log with stack trace about what caused a 500 error to occur.

I can run this myself later to see what's going on.

santsys commented 7 years ago

@gschneider-r7 Ahh, I'm not sure how to get that info from the console... If it's available from the web UI I can pull it, but I don't have access to the server it's running on. If you have more details, or some instructions somewhere, I an take a look. Thanks!

gschneider-r7 commented 7 years ago

Fix has been merged and a new release, 0.1.1, will be pushed shortly.