Qualys Client

See the official Qualys API documentation here: VM API.

See the official Qualys Cloud Agent API documentation here: CA API.

class bibt.qualys.classes.Client(user, password, url)[source]

Creates a bibt.qualys.Client object, which may be used to make Qualys API calls using the same set of credentials.

Parameters:
  • user (str) – The Qualys username with which to authenticate.

  • password (str) – The password for the provided account username.

  • url (str) – The root domain for Qualys, e.g. "https://qualysapi.qg1.apps.qualys.com".

close()[source]

Cleanly closes the HTTP session with Qualys and sets self.session to None (making this Client unusable).

delete_report_result(report_id)[source]

Deletes a report result from Qualys by its ID.

Parameters:

report_id (str) – The report reference ID, e.g. "report/123456789.12345"

delete_scan_result(scan_ref)[source]

Deletes a scan result from Qualys by its reference ID.

Parameters:

scan_ref (str) – The scan reference ID, e.g. "scan/123456789.12345"

get_report_result(report_title, parse_xml_to_json=True, force_list=('ASSET_GROUP_TITLE', 'VULN_INFO'))[source]

Given a report title, fetches the most recent report result.

Parameters:
  • report_title (str) – The report title for which to search.

  • parse_xml_to_json (bool) – Whether or not to parse an XML report to JSON. If the report is in any other format, this is ignored.

  • force_list (tuple) – A tuple of keys to force into list format when parsing the returned XML into lists and dictionaries. Only relevant when the report format is XML and parse_xml_to_json==True, otherwise this is ignored. Defaults to ("ASSET_GROUP_TITLE", "VULN_INFO").

Return (str, str):

A tuple of (output_format, data) where output_format is the configured report output format, e.g. “XML”, “HTML”, “CSV”, etc.

get_scan_result(scan_title, output_format='json_extended', mode='extended', refactor_json_data=True)[source]

Given a scan title, will fetch the most recent scan result.

Parameters:
  • scan_title (str) – The title of the scan, e.g. “VLAN 100 Scan”.

  • output_format (str) – The output format of the scan results. Must be one of: “csv”, “json”, “csv_extended”, “json_extended”. Defaults to bibt.qualys.params.DEFAULT_SCAN_RESULT_OUTPUT_FORMAT.

  • mode (str) – Must be one of “brief” or “extended”. Specifies the level of detail per result for Qualys to return. Defaults to bibt.qualys.params.DEFAULT_SCAN_RESULT_MODE.

  • refactor_json_data (bool) – Whether or not to refactor “json_extended” scan result data into a more organized format. By default, Qualys returns a list of dictionaries, where: the first two dictionaries cover request metadata and scan result metadata respectively; the last dictionary includes special notes about the scan run; and each of the dictionaries in the middle contain result data per host. If this option is set to True, the data will be reformated to a dictionary with the keys: "request_metadata": {}, "scan_metadata": {}, "scan_notes": {}, and "results": [{}, {}]. Defaults to True.

Raises:

Exception – If no scan result is found for the given title.

Return list OR dict OR str:

THe scan result data.

list_reports(state='Finished', force_list=None)[source]

List all reports in Qualys.

Parameters:
  • state (str) – The state of reports to return. Set to None to return all reports. Defaults to "Finished".

  • force_list (tuple) – A tuple of keys to force into list format when parsing the returned XML into lists and dictionaries. Defaults to None.

Return list:

A list of dicts, containing metadata for all Qualys reports.

list_scan_schedules(force_list=('ASSET_GROUP_TITLE',))[source]

List all configured scan schedules in Qualys.

Parameters:

force_list (tuple) – A tuple of keys to force into list format when parsing the returned XML into lists and dictionaries. Defaults to ("ASSET_GROUP_TITLE",).

Return list:

A list of dicts, containing metadata for all scan schedules.

list_scans(state='Finished', force_list=None)[source]

List all scans in Qualys.

Parameters:
  • state (str) – The state of scans to return. Set to None to return all scans. Defaults to "Finished".

  • force_list (tuple) – A tuple of keys to force into list format when parsing the returned XML into lists and dictionaries. Defaults to None.

Return list:

A list of dicts, containing metadata for all Qualys scans.