-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDemo-Script.ps1
97 lines (73 loc) · 3.83 KB
/
Demo-Script.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
Import-Module ./CarbonCLI/CarbonCLI.psm1
# $DebugPreference = 'Continue'
# Set-PsDebug -Trace 2
# List all available cmdlets
Get-Command -Module CarbonCLI
# Count the number of Carbon Black Cloud cmdlets
Get-Command -Module CarbonCLI | Measure-Object | Select-Object Count
# Establish a connection to a Carbon Black Cloud Endpoint
# Create a PSCredential object. Specify OrgId as a value for User and Token as a value for password when prompted.
$myCredentials = Get-Credential
$cbcServerOrg1 = Connect-CBCServer -Server https://defense.conferdeploy.net/ -Credential $myCredentials -Notes Org1
# Design principle on focus: Each cmdlet is documented as part of its codebase. Learn Carbon Black leveraging Get-Help cmdlet
Get-Help Connect-CbcServer -Full
# Retrieve devices, alerts, etc.
Get-Help Get-CbcDevice -Full
Get-CbcDevice
Get-Help Get-CbcAlert -Full
Get-CbcAlert
# Design principle on focus: In Powershell everything is an object. Carbon Black CLI has its own object model that losely mimics the underlying API model.
Get-CbcDevice | Get-Member
Get-CbcProcess | Get-Member
# Design principle on focus: There is a separation between the object model definition and the object presentation layer. Review Format.ps1xml !
Get-CbcDevice | Select-Object Id, Server, LastShutdownTime
# Design principle on focus: Working against multiple connections. Each connection is defined uniquely by a URI/Org pair.
$cbcServerOrg2 = Connect-CBCServer -Server https://defense.conferdeploy.net/ -Org ABCD1234 -Token ABCDEFGHIJKLMNO123456789/ABCD123456 -Notes Org2
# Retrieve alerts, devices from multiple connections.
Get-CbcAlerts -Server $cbcServerOrg2
Get-CbcAlerts
Get-CbcDevice
Get-CbcDevice | Select-Object Id, Server, SensorVersion
# Retrieve the Org1 devices only
Get-CbcDevice -Server $cbcServerOrg1
# Create a simple HTML report on LOW priority "Windows 10" devices
Get-CbcDevice -OS Windows -OSVersion "Windows 10 x64" -TargetPriority LOW | ConvertTo-Html | Out-File DeviceReport.html
# Server-side filtering using cmdlet filter params
Get-CbcDevice -OS Windows
Get-CbcDevice -OS Windows -OSVersion "Windows 10 x64"
Get-CbcDevice -OS Windows -OSVersion "Windows 10 x64" -TargetPriority LOW
# Client-side filtering. No filter param for sensor version
Get-CbcDevice | Where-Object {$_.SensorVersion -like "windows:3.9*"}
# Beyond reporting: Creating and manipulating objects in your CBC environment
Get-CbcDevice -OS Windows -OSVersion "Windows 10 x64" -TargetPriority LOW | Set-CbcDevice -QuarantineEnabled $true
Get-CbcDevice -OS Windows -OSVersion "Windows 10 x64" -TargetPriority LOW | Set-CbcDevice -QuarantineEnabled $false
Get-Help Set-CbcDevice -Full
# Get policies and update device policy
Get-CbcDevice
Get-CbcPolicy
Set-CbcDevice -Id 123456789 -PolicyId 12345
# Working with long running operations ( process search / observations search )
Get-CbcDevice
Get-CbcProcess -DeviceId 123456789
Get-CbcProcess -Query "process_name:power*"
$processSearchJob = Get-CbcProcess -Query "process_name:power*" -AsJob
Get-CbcJob $processSearchJob
Receive-CbcJob $processSearchJob
# Observations
Get-Help Get-CbcObservation -Full
Get-CbcObservation -EventType "netconn"
Get-CbcObservation -Query "event_type:netconn"
# Get observations for alert
Get-CbcAlert -Id "c295b8fc-0f5d-7193-3075-0301862c69b7" | Get-CbcObservation
# Create feed, report, ioc and then subscribe for that feed (create a watchlist)
# Create empty feed
$feed = New-CbcFeed -Name mydemo -ProviderUrl http://test.test/ -Summary summary -Category demo -Alertable $true
# Create empty report and add it to the feeed
$report = New-CbcReport -Feed $feed -Title myreport -Description description -Severity 5
# Create one IOC and add it to the created report
$Body = @{"match_type" = "equality"
"field" = "process_name"
"values" = @("googleupdate.exe")}
New-CbcIoc -Report $report -Body $Body
# Subscribe to that feed
New-CbcWatchlist -Feed $feed