Skip to content

Commit 315ea2c

Browse files
committed
initial commit - 0.9.1
1 parent 9c2b425 commit 315ea2c

File tree

168 files changed

+28113
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

168 files changed

+28113
-14
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,7 @@ target/
6060

6161
#Ipython Notebook
6262
.ipynb_checkpoints
63+
64+
.idea/
65+
*.ipynb
66+
.DS_Store

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Changelog
2+
3+
## Changes since 0.8.0
4+
5+
cbapi 0.9.0 has been completely rewritten from 0.8.0.
6+
7+
Backwards compatibility with old scripts is maintained through the `cbapi.legacy` module. Old scripts that import
8+
`cbapi.CbApi` directly will continue to work. Once cbapi 1.0 is released, the old `CbApi` will be deprecated and
9+
removed entirely no earlier than January 2017.
10+
11+
New scripts should use the `cbapi.CbEnterpriseResponseAPI` (for Carbon Black "Enterprise Response") and
12+
`cbapi.CbEnterpriseProtectAPI` (for Carbon Black "Enterprise Protection" / former Bit9) API entry points.

LICENSE

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,42 @@ The MIT License (MIT)
22

33
Copyright (c) 2016 Carbon Black
44

5-
Permission is hereby granted, free of charge, to any person obtaining a copy
6-
of this software and associated documentation files (the "Software"), to deal
7-
in the Software without restriction, including without limitation the rights
8-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9-
copies of the Software, and to permit persons to whom the Software is
10-
furnished to do so, subject to the following conditions:
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
1111

1212
The above copyright notice and this permission notice shall be included in all
1313
copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21+
22+
23+
24+
This software was based on cbapi2, whose license is included below:
25+
26+
Copyright (c) 2015 Red Canary
27+
28+
Permission is hereby granted, free of charge, to any person obtaining a copy of
29+
this software and associated documentation files (the "Software"), to deal in
30+
the Software without restriction, including without limitation the rights to
31+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
32+
the Software, and to permit persons to whom the Software is furnished to do so,
33+
subject to the following conditions:
34+
35+
The above copyright notice and this permission notice shall be included in all
36+
copies or substantial portions of the Software.
37+
38+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
40+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
41+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
42+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
43+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
recursive-include examples *.py *.txt
2+
recursive-include src/cbapi *.yaml

README.md

100644100755
Lines changed: 111 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,111 @@
1-
# cbapi-python
2-
Carbon Black API - Python language bindings
1+
# Python bindings for Carbon Black REST API
2+
3+
https://www.bit9.com/solutions/carbon-black/
4+
5+
## Support
6+
7+
If you have questions on the Carbon Black API or these API Bindings, please contact us at dev-support@carbonblack.com.
8+
Also review the documentation and guides available on the
9+
[Carbon Black Developer Network website](http://developer.carbonblack.com)
10+
11+
## Requirements
12+
13+
The new cbapi is designed to work on Python 2.6.6 and above (including 3.x).
14+
All requirements are installed as part of `pip install`.
15+
The legacy cbapi (`cbapi.CbApi`) and legacy bit9api (`cbapi.bit9Api`) are still compatible with Python 2.x only.
16+
17+
## Backwards Compatibility
18+
19+
Backwards compatibility with old scripts is maintained through the `cbapi.legacy` module. Old scripts that import
20+
`cbapi.CbApi` directly will continue to work. Once cbapi 2.0.0 is released, the old `CbApi` will be deprecated and
21+
removed entirely no earlier than January 2017.
22+
23+
New scripts should use the `cbapi.CbEnterpriseResponseAPI` (for Carbon Black "Enterprise Response") and
24+
`cbapi.CbEnterpriseProtectionAPI` (for Carbon Black "Enterprise Protection" / former Bit9) API entry points.
25+
26+
## Getting Started
27+
28+
### Development
29+
30+
Prerequisites:
31+
32+
```
33+
pip install py-lru-cache
34+
pip install attrdict
35+
pip install six
36+
pip install total-ordering
37+
```
38+
39+
### Installation
40+
41+
pip install cbapi
42+
43+
### Sample Code
44+
45+
**Carbon Black Enterprise Response**
46+
47+
from cbapi.response.models import Process, Binary, Sensor, Feed, Watchlist, Investigation
48+
from cbapi.response.rest_api import CbEnterpriseResponseAPI
49+
50+
import logging
51+
logging.basicConfig(level=logging.DEBUG)
52+
53+
c=CbEnterpriseResponseAPI()
54+
55+
# read the first four bytes of the notepad.exe associated with the first process instance of notepad running
56+
c.select(Process).where('process_name:notepad.exe').first().binary.file.read(4)
57+
58+
# if you want a specific ID, you can put it straight into the .select() call:
59+
binary = c.select(Binary, "24DA05ADE2A978E199875DA0D859E7EB")
60+
61+
# isolate all sensors who ran notepad.exe
62+
sensors = set()
63+
for proc in c.select(Process).where('process_name:notepad.exe'):
64+
sensors.add(proc.sensor)
65+
66+
for s in sensors:
67+
s.network_isolation_enabled = True
68+
s.save()
69+
70+
71+
**Carbon Black Enterprise Protection**
72+
73+
from cbapi.protection.models import *
74+
from cbapi.protection.rest_api import CbEnterpriseProtectionAPI
75+
76+
p=CbEnterpriseProtectionAPI()
77+
78+
# Select the first file instance
79+
fi = p.select(FileInstance).first()
80+
81+
# print that computer's hostname
82+
fi.computer.name
83+
84+
# change the policy ID
85+
fi.computer.policyId = 3
86+
fi.computer.save()
87+
88+
89+
### API Token
90+
91+
In order to perform any queries via the API, you will need to get the API token for your Cb user. See the documentation
92+
on the Developer Network website on how to acquire the API token for
93+
[Enterprise Response](http://developer.carbonblack.com/reference/enterprise-response/authentication/) or
94+
[Enterprise Protection](http://developer.carbonblack.com/reference/enterprise-protection/authentication/)
95+
96+
Once you acquire your API token, place it in one of the default credentials file locations:
97+
98+
* `/etc/carbonblack/credentials.response` (or `.protection` for Cb Enterprise Protection)
99+
* `~/.carbonblack/credentials.response`
100+
* (current working directory) `.carbonblack/credentials.response`
101+
102+
Credentials found in a later path will overwrite earlier ones.
103+
104+
The credential file is stored as an INI file:
105+
106+
```
107+
[default]
108+
url=https://localhost
109+
token=abcdef0123456789abcdef
110+
ssl_verify=False
111+
```

0 commit comments

Comments
 (0)