Skip to content

Commit 24d677f

Browse files
authored
Merge pull request #306 from carbonblack/develop
Release 1.7.6 Bug Fix: Removed the requirement for an admin token to connect Bug Fix: Added sensor paginated query Library update: Updated version of lxml library
2 parents 048459b + 1e05974 commit 24d677f

27 files changed

+172
-164
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Python bindings for Carbon Black REST API
22

3-
**Latest Version: 1.7.5**
3+
**Latest Version: 1.7.6**
44

55
_**Notice**:_
66
* The Carbon Black Cloud portion of CBAPI has moved to https://github.com/carbonblack/carbon-black-cloud-sdk-python. Any future development and bug fixes for Carbon Black Cloud APIs will be made there. Carbon Black EDR and App Control will remain supported at CBAPI

docs/changelog.rst

+11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@ CbAPI Changelog
22
===============
33
.. top-of-changelog (DO NOT REMOVE THIS COMMENT)
44
5+
CbAPI 1.7.6 - Release Dec 20, 2021
6+
------------------------------------
7+
8+
Bug Fixes
9+
* Removed the requirement for an admin token to connect
10+
* Added sensor paginated query
11+
12+
General
13+
* Updated version of lxml library
14+
15+
516
CbAPI 1.7.5 - Released June 16, 2021
617
------------------------------------
718

docs/concepts.rst

+5-5
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,9 @@ Joining Model Objects
6262
---------------------
6363

6464
Many times, there are relationships between different Model Objects. To make navigating these relationships easy,
65-
cbapi provides special properties to "join" Model Objects together. For example, a :py:mod:`cbapi.response.models.Process`
66-
Model Object can reference the :py:mod:`cbapi.response.models.Sensor` or :py:mod:`cbapi.response.models.Binary`
67-
associated with this Process.
65+
cbapi provides special properties to "join" Model Objects together. For example, a
66+
:py:mod:`cbapi.response.models.Process` Model Object can reference the :py:mod:`cbapi.response.models.Sensor` or
67+
:py:mod:`cbapi.response.models.Binary` associated with this Process.
6868

6969
In this case, special "join" properties are provided for you. When you use one of these properties, cbapi will
7070
automatically retrieve the associated Model Object, if necessary.
@@ -186,8 +186,8 @@ represent these data types can be "created" in cbapi by using the ``create()`` m
186186

187187
If you attempt to create a Model Object that cannot be created, you will receive a :py:mod:`ApiError` exception.
188188

189-
Once a Model Object is created, it's blank (it has no data). You will need to set the required properties and then call the
190-
``.save()`` method::
189+
Once a Model Object is created, it's blank (it has no data). You will need to set the required properties and then call
190+
the ``.save()`` method::
191191

192192
>>> bh = cb.create(BannedHash)
193193
>>> bh.text = "Banned from API"

docs/conf.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
# The short X.Y version.
6262
version = u'1.7'
6363
# The full version, including alpha/beta/rc tags.
64-
release = u'1.7.5'
64+
release = u'1.7.6'
6565

6666
# The language for content autogenerated by Sphinx. Refer to documentation
6767
# for a list of supported languages.

docs/defense-api.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
.. _defense_api:
22

3-
CB Defense API
4-
==============
3+
Cloud Endpoint Standard API
4+
===========================
55

6-
This page documents the public interfaces exposed by cbapi when communicating with a CB Defense server.
6+
This page documents the public interfaces exposed by cbapi when communicating with a Cloud Endpoint Standard server.
77

88
Main Interface
99
--------------
1010

11-
To use cbapi with Carbon Black Defense, you will be using the CBDefenseAPI.
11+
To use cbapi with VMware Carbon Black Cloud Endpoint Standard, you will be using the CBDefenseAPI.
1212
The CBDefenseAPI object then exposes two main methods to select data on the Carbon Black server:
1313

1414
.. autoclass:: cbapi.psc.defense.rest_api.CbDefenseAPI

docs/getting-started.rst

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Getting Started
44
First, let's make sure that your API authentication tokens have been imported into cbapi. Once that's done, then read
55
on for the key concepts that will explain how to interact with Carbon Black APIs via cbapi.
66

7-
Feel free to follow along with this document or watch the `Development Environment Setup video <https://developer.carbonblack.com/guide/enterprise-response/development-environment-video/>`_
7+
Feel free to follow along with this document or watch the
8+
`Development Environment Setup video <https://developer.carbonblack.com/guide/enterprise-response/development-environment-video/>`_
89
on the Developer Network website.
910

1011
API Authentication
@@ -36,7 +37,8 @@ Alternatively, if you're using Windows (change ``c:\python27`` if Python is inst
3637
This configuration script will walk you through entering your API credentials and will save them to your current user's
3738
credential file location, which is located in the ``.carbonblack`` directory in your user's home directory.
3839

39-
If using cbapi-psc, you will also be asked to provide an org key. An org key is required to access the Carbon Black Cloud, and can be found in the console under Settings -> API Keys.
40+
If using cbapi-psc, you will also be asked to provide an org key. An org key is required to access the Carbon Black
41+
Cloud, and can be found in the console under Settings -> API Keys.
4042

4143
Your First Query
4244
----------------

docs/index.rst

+11-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ This library provides a Pythonic layer to access the raw power of the REST APIs
1313

1414
>>> from cbapi.response import CbResponseAPI, Process, Binary, Sensor
1515
>>> #
16-
>>> # Create our CbAPI object
16+
>>> # Create our EDR API object
1717
>>> #
1818
>>> c = CbResponseAPI()
1919
>>> #
@@ -43,7 +43,7 @@ If you're a Carbon Black App Control customer (formerly CB Protection), you may
4343
>>> from cbapi.protection.models import FileInstance
4444
>>> from cbapi.protection import CbProtectionAPI
4545
>>> #
46-
>>> # Create our CB Protection API object
46+
>>> # Create our App Control API object
4747
>>> #
4848
>>> p = CbProtectionAPI()
4949
>>> #
@@ -65,7 +65,7 @@ As of version 1.2, CBAPI also supports Carbon Black Cloud Endpoint Standard (for
6565

6666
>>> from cbapi.psc.defense import *
6767
>>> #
68-
>>> # Create our CB Defense API object
68+
>>> # Create our Cloud Endpoint Standard API object
6969
>>> #
7070
>>> p = CbDefenseAPI()
7171
>>> #
@@ -116,7 +116,7 @@ Major Features
116116
API Credentials
117117
---------------
118118

119-
CBAPI version 0.9.0 enforces the use of credential files.
119+
CBAPI version 0.9.0 enforces the use of credential files.
120120

121121
In order to perform any queries via the API, you will need to get the API token for your CB user. See the documentation
122122
on the Developer Network website on how to acquire the API token for
@@ -130,13 +130,15 @@ Once you acquire your API token, place it in one of the default credentials file
130130
* ``~/.carbonblack/``
131131
* ``/current_working_directory/.carbonblack/``
132132

133-
For distinction between credentials of different Carbon Black products, use the following naming convention for your credentials files:
133+
For distinction between credentials of different Carbon Black products, use the following naming convention for your
134+
credentials files:
134135

135136
* ``credentials.psc`` for Carbon Black Cloud Endpoint Standard, Audit & Remediation, and Enterprise EDR (CB Defense, CB LiveOps, and CB ThreatHunter)
136137
* ``credentials.response`` for Carbon Black EDR (CB Response)
137138
* ``credentials.protection`` for Carbon Black App Control (CB Protection)
138139

139-
For example, if you use a Carbon Black Cloud product, you should have created a credentials file in one of these locations:
140+
For example, if you use a Carbon Black Cloud product, you should have created a credentials file in one of these
141+
locations:
140142

141143
* ``/etc/carbonblack/credentials.psc``
142144
* ``~/.carbonblack/credentials.psc``
@@ -188,8 +190,8 @@ The latest CBAPI for Python supports specifying API credentials in the following
188190
The `CBAPI_URL` envar holds the FQDN of the target, an EDR (CbR), CBD, or CbD/Carbon Black Cloud server specified just as they are in the
189191
configuration file format specified above.
190192

191-
The optional `CBAPI_SSL_VERIFY` envar can be used to control SSL validation(True/False or 0/1), which will default to ON when
192-
not explicitly set by the user.
193+
The optional `CBAPI_SSL_VERIFY` envar can be used to control SSL validation(True/False or 0/1), which will default to
194+
ON when not explicitly set by the user.
193195

194196
For environments where complex outbound network filters and proxy configurations are used (eg. anything other than
195197
an unauthenticated or basic password authenticated proxy) a prepared `requests.Session` object may be supplied as a
@@ -239,7 +241,7 @@ API Documentation
239241
-----------------
240242

241243
Once you have read the User Guide, you can view `examples on GitHub <https://github.com/carbonblack/cbapi-python/tree/master/examples>`_
242-
or try writing code of your own. You can use the full API documentation below to see all the methods available in CBAPI
244+
or try writing code of your own. You can use the full API documentation below to see all the methods available in CBAPI
243245
and unlock the full functionality of the SDK.
244246

245247
.. toctree::

docs/installation.rst

+1-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ https://www.python.org/ftp/python/3.6.4/python-3.6.4-amd64.exe.
3939
:alt: Windows installation options showing "Add python.exe to path"
4040
:align: right
4141

42-
Ensure that the "Add Python to PATH" option is
43-
checked.
42+
Ensure that the "Add Python to PATH" option is checked.
4443

4544
If for some reason you do not have pip installed, follow the instructions at this
4645
`handy guide <http://docs.python-guide.org/en/latest/starting/installation/>`_.
@@ -75,4 +74,3 @@ Once you have a copy of the source, you can install it in "development" mode int
7574
This will link the version of cbapi-python you checked out into your Python site-packages directory. Any changes you
7675
make to the checked out version of cbapi will be reflected in your local Python installation. This is a good choice
7776
if you are thinking of changing or developing on cbapi itself.
78-

docs/live-response.rst

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
CbAPI and Live Response
22
=======================
33

4-
Working with the CB Live Response REST API directly can be difficult. Thankfully, just like the rest of Carbon
4+
Working with the Live Response REST API directly can be difficult. Thankfully, just like the rest of Carbon
55
Black's REST APIs, cbapi provides Pythonic APIs to make working with the Live Response API much easier.
66

77
In addition to easy-to-use APIs to call into Live Response, cbapi also provides a "job-based" interface that allows
@@ -92,4 +92,3 @@ back from the endpoint, and submit the ``.run()`` method to the Live Response Jo
9292

9393
Your script resumes execution immediately after the call to ``.submit_job()``. The job(s) that you've submitted will
9494
be executed in a set of background threads managed by cbapi.
95-

docs/livequery-api.rst

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
.. _livequery_api:
22

33
CB LiveQuery API
4-
===================
4+
================
55

6-
This page documents the public interfaces exposed by cbapi when communicating with
7-
Carbon Black LiveQuery devices.
6+
This page documents the public interfaces exposed by cbapi when communicating with Carbon Black LiveQuery devices.
87

98
Main Interface
109
--------------
@@ -20,9 +19,8 @@ The LiveQuery API is used in two stages: run submission and result retrieval.
2019
Queries
2120
-------
2221

23-
The LiveQuery API uses QueryBuilder instances to construct structured
24-
or unstructured (i.e., raw string) queries. You can either construct these
25-
instances manually, or allow ``CbLiveQueryAPI.select()`` to do it for you:
22+
The LiveQuery API uses QueryBuilder instances to construct structured or unstructured (i.e., raw string) queries.
23+
You can either construct these instances manually, or allow ``CbLiveQueryAPI.select()`` to do it for you:
2624

2725
.. autoclass:: cbapi.psc.livequery.query.QueryBuilder
2826
:members:

docs/livequery-examples.rst

+12-7
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ Now that we've imported the necessary libraries, we can perform some queries on
1414
Create a Query Run
1515
----------------------------------
1616

17-
Let's create a Query Run. First, we specify which profile to use for authentication from our credentials.psc file and create the LiveQuery object.
17+
Let's create a Query Run. First, we specify which profile to use for authentication from our credentials.psc file and
18+
create the LiveQuery object.
1819

1920
>>> profile = "default'
2021
>>> cb = CbLiveQueryAPI(profile=profile)
2122

2223
Now, we specify the SQL query that we want to run, name of the run, device IDs, and device types.
2324

24-
2525
>>> sql = 'select * from logged_in_users;'
2626
>>> name_of_run = 'Selecting all logged in users'
2727
>>> device_ids = '1234567'
@@ -41,7 +41,8 @@ Finally, we submit the query and print the results.
4141

4242
This query should return all logged in Windows endpoints with a ``device_id`` of ``1234567``.
4343

44-
The same query can be executed with the example script `manage_run.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/manage_run.py>`_. ::
44+
The same query can be executed with the example script
45+
`manage_run.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/manage_run.py>`_. ::
4546

4647
python manage_run.py --profile default create --sql 'select * from logged_in_users;' --name 'Selecting all logged in users' --device_ids '1234567' --device_types 'WINDOWS'
4748

@@ -50,7 +51,8 @@ Other possible arguments to ``manage_run.py`` include ``--notify`` and ``--polic
5051
Get Query Run Status
5152
---------------------
5253

53-
Now that we've created a Query Run, let's check the status. If we haven't already authenticated with a credentials profile, we begin by specifying which profile to authenticate with.
54+
Now that we've created a Query Run, let's check the status. If we haven't already authenticated with a credentials
55+
profile, we begin by specifying which profile to authenticate with.
5456

5557
>>> profile = 'default'
5658
>>> cb = CbLiveQueryAPI(profile=profile)
@@ -61,11 +63,13 @@ Next, we select the run with the unique run ID.
6163
>>> run = cb.select(Run, run_id)
6264
>>> print(run)
6365

64-
This can also be accomplished with the example script `manage_run.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/manage_run.py>`_::
66+
This can also be accomplished with the example script
67+
`manage_run.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/manage_run.py>`_::
6568

6669
python manage_run.py --profile default --id a4oh4fqtmrr8uxrdj6mm0mbjsyhdhhvz
6770

68-
In addition, you can specify which order you want results returned. To change from the default ascending order, use the flag ``-d`` or ``--descending_results``::
71+
In addition, you can specify which order you want results returned. To change from the default ascending order, use
72+
the flag ``-d`` or ``--descending_results``::
6973

7074
python manage_run.py --profile default --id a4oh4fqtmrr8uxrdj6mm0mbjsyhdhhvz --descending_results
7175

@@ -105,6 +109,7 @@ Finally, we print the results.
105109
... print(result)
106110

107111

108-
You can also retrieve run results with the example script `run_search.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/run_search.py>`_::
112+
You can also retrieve run results with the example script
113+
`run_search.py <https://github.com/carbonblack/cbapi-python/blob/master/examples/livequery/run_search.py>`_::
109114

110115
python run_search.py --profile default --id a4oh4fqtmrr8uxrdj6mm0mbjsyhdhhvz --device_ids '1234567' --status 'matched'

docs/protection-api.rst

-3
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
Carbon Black App Control (CB Protection) API
44
===========================================
55

6-
This page documents the public interfaces exposed by cbapi when communicating with a Carbon Black App Control (Enterprise
7-
Protection) server.
8-
96
Main Interface
107
--------------
118

docs/psc-api.rst

+9-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
.. _psc_api:
22

3-
CB PSC API
4-
==========
3+
VMware Carbon Black Cloud API
4+
=============================
55

6-
This page documents the public interfaces exposed by cbapi when communicating with
7-
the Carbon Black Predictive Security Cloud (PSC).
6+
This page documents the public interfaces exposed by cbapi when communicating with the VMware Carbon Black Cloud.
87

98
Main Interface
109
--------------
1110

12-
To use cbapi with the Carbon Black PSC, you use CbPSCBaseAPI objects.
11+
To use cbapi with the VMware Carbon Black Cloud, you use CbPSCBaseAPI objects.
1312

1413
.. autoclass:: cbapi.psc.rest_api.CbPSCBaseAPI
1514
:members:
@@ -18,7 +17,7 @@ To use cbapi with the Carbon Black PSC, you use CbPSCBaseAPI objects.
1817
Device API
1918
----------
2019

21-
The PSC can be used to enumerate devices within your organization, and change their
20+
The Carbon Black Cloud can be used to enumerate devices within your organization, and change their
2221
status via a control request.
2322

2423
You can use the select() method on the CbPSCBaseAPI to create a query object for
@@ -45,12 +44,11 @@ Selects all devices running Linux from the current organization.
4544
Alerts API
4645
----------
4746

48-
Using the API, you can search for alerts within your organization, and dismiss or
49-
undismiss them, either individually or in bulk.
47+
Using the API, you can search for alerts within your organization, and dismiss or undismiss them, either individually
48+
or in bulk.
5049

51-
You can use the select() method on the CbPSCBaseAPI to create a query object for
52-
BaseAlert objects, which can be used to locate a list of alerts. You can also
53-
search for more specialized alert types:
50+
You can use the select() method on the CbPSCBaseAPI to create a query object for BaseAlert objects, which can be used
51+
to locate a list of alerts. You can also search for more specialized alert types:
5452

5553
* CBAnalyticsAlert - Alerts from CB Analytics
5654
* VMwareAlert - Alerts from VMware

docs/response-api.rst

-6
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,6 @@
33
EDR (CB Response) API
44
===============
55

6-
This page documents the public interfaces exposed by cbapi when communicating with a Carbon Black EDR (Enterprise
7-
Response) server.
8-
96
Main Interface
107
--------------
118

@@ -77,6 +74,3 @@ Process Operations
7774
.. automethod:: cbapi.live_response_api.CbLRSessionBase.kill_process
7875
.. automethod:: cbapi.live_response_api.CbLRSessionBase.create_process
7976
.. automethod:: cbapi.live_response_api.CbLRSessionBase.list_processes
80-
81-
82-

docs/response-examples.rst

+5-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
EDR (CB Response) API Examples
22
==============================
33

4-
Now that we've covered the basics, let's step through a few examples using the EDR (CB Response) API. In these examples,
5-
we will assume the following boilerplate code to enable logging and establish a connection to the "default"
6-
EDR (CB Response) server in our credential file::
7-
84
>>> import logging
95
>>> root = logging.getLogger()
106
>>> root.addHandler(logging.StreamHandler())
@@ -246,7 +242,7 @@ the command name ``cmd.exe``. Just add the ``.group_by("id")`` filter to your qu
246242
Feed and Watchlist Maintenance
247243
------------------------------
248244

249-
The cbapi provides several helper functions to assist in creating watchlists and
245+
The cbapi provides several helper functions to assist in creating watchlists and feeds.
250246

251247
Watchlists are simply saved Queries that are automatically run on the EDR (CB Response) server on a periodic basis. Results
252248
of the watchlist are tagged in the database and optionally trigger alerts. Therefore, a cbapi Query can easily be
@@ -295,9 +291,10 @@ The cbapi provides helper functions to manage alerts and threat reports in bulk.
295291
the ThreatReport and Alert Model Objects provide a few bulk operations to help manage large numbers of Threat Reports
296292
and Alerts, respectively.
297293

298-
To mark a large number of Threat Reports as false positives, create a query that matches the Reports you're interested in.
299-
For example, if every Report from the Feed named "SOC" that contains the word "FUZZYWOMBAT" in the report title should be
300-
considered a false positive (and no longer trigger Alerts), you can write the following code to do so::
294+
To mark a large number of Threat Reports as false positives, create a query that matches the Reports you're
295+
interested in. For example, if every Report from the Feed named "SOC" that contains the word "FUZZYWOMBAT" in the
296+
report title should be considered a false positive (and no longer trigger Alerts), you can write the following code
297+
to do so::
301298

302299
>>> feed = c.select(Feed).where("name:SOC").one()
303300
>>> report_query = feed.reports.where("title:FUZZYWOMBAT")
@@ -429,4 +426,3 @@ How about moving a sensor to a new Sensor Group::
429426
Sending HTTP PUT /api/v1/sensor/3 with {"boot_id": "2", "build_id": 2, "build_version_string": "005.002.000.60922", ...
430427
HTTP PUT /api/v1/sensor/3 took 0.087s (response 204)
431428
HTTP GET /api/v1/sensor/3 took 0.030s (response 200)
432-

0 commit comments

Comments
 (0)