Skip to content

Commit ce1cd00

Browse files
committed
Add basic RTR example.
1 parent 4ff18e0 commit ce1cd00

File tree

2 files changed

+87
-0
lines changed

2 files changed

+87
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
This is a working standalone example of a program to run a basic read-only RTR command against a specific agent.
2+
3+
## Build
4+
```
5+
go get github.com/crowdstrike/gofalcon/examples/falcon_rtr_read_only_command
6+
```
7+
8+
## Setup Environment Variables
9+
```
10+
# Highly recommended to set at least the client ID and secret
11+
# as environment variables. Credentials should not be entered
12+
# on the command line, so as not to pollute the command history.
13+
export FALCON_CLIENT_ID="your_falcon_id"
14+
export FALCON_CLIENT_SECRET="your_falcon_secret"
15+
export FALCON_CLOUD="us-1, us-2, eu-1, us-gov-1, etc"
16+
17+
# AID and command are more likely to vary and are not sensitive,
18+
# so are a more natural fit for command line arguments.
19+
export FALCON_AGENT_ID="def"
20+
export FALCON_RTR_COMMAND="users"
21+
```
22+
23+
## Usage
24+
```
25+
$ FALCON_CLIENT_ID="abc" FALCON_CLIENT_SECRET="XYZ" FALCON_CLOUD=us-1 \
26+
falcon_rtr_read_only_command --aid "def" --cmd "users"
27+
```
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package main
2+
3+
import (
4+
"context"
5+
"flag"
6+
"fmt"
7+
"os"
8+
"strings"
9+
10+
"github.com/crowdstrike/gofalcon/falcon"
11+
"github.com/crowdstrike/gofalcon/pkg/falcon_util"
12+
)
13+
14+
func main() {
15+
clientId := flag.String("client-id", os.Getenv("FALCON_CLIENT_ID"), "Client ID for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_ID env)")
16+
clientSecret := flag.String("client-secret", os.Getenv("FALCON_CLIENT_SECRET"), "Client Secret for accessing CrowdStrike Falcon Platform (default taken from FALCON_CLIENT_SECRET)")
17+
clientCloud := flag.String("cloud", os.Getenv("FALCON_CLOUD"), "Falcon cloud abbreviation (us-1, us-2, eu-1, us-gov-1; default taken from FALCON_CLOUD)")
18+
aid := flag.String("aid", os.Getenv("FALCON_AGENT_ID"), "Falcon agent ID on which to run the command (default taken from FALCON_AGENT_ID)")
19+
cmd := flag.String("cmd", os.Getenv("FALCON_RTR_COMMAND"), "RTR command to run on the specified agent. (default taken from FALCON_RTR_COMMAND)")
20+
21+
flag.Parse()
22+
if *clientId == "" {
23+
*clientId = falcon_util.PromptUser(`Missing FALCON_CLIENT_ID environment variable. Please provide your OAuth2 API Client ID for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
24+
Falcon Client ID`)
25+
}
26+
if *clientSecret == "" {
27+
*clientSecret = falcon_util.PromptUser(`Missing FALCON_CLIENT_SECRET environment variable. Please provide your OAuth2 API Client Secret for authentication with CrowdStrike Falcon platform. Establishing and retrieving OAuth2 API credentials can be performed at https://falcon.crowdstrike.com/support/api-clients-and-keys.
28+
Falcon Client Secret`)
29+
}
30+
if *aid == "" {
31+
*aid = falcon_util.PromptUser(`Missing FALCON_AGENT_ID. Please provide the ID of the agent you would like to communicate with.
32+
Falcon agent ID`)
33+
}
34+
if *cmd == "" {
35+
*cmd = falcon_util.PromptUser(`Missing FALCON_RTR_COMMAND. Please provide the RTR command you would like to run. See https://falcon.crowdstrike.com/documentation/71/real-time-response-and-network-containment#rtr_commands for a list of RTR Read Only Analyst commands.
36+
Falcon RTR command`)
37+
}
38+
39+
client, err := falcon.NewRTR(&falcon.ApiConfig{
40+
ClientId: *clientId,
41+
ClientSecret: *clientSecret,
42+
Cloud: falcon.Cloud(*clientCloud),
43+
Context: context.Background(),
44+
})
45+
if err != nil {
46+
panic(err)
47+
}
48+
49+
session, err := client.NewSession(context.Background(), *aid)
50+
if err != nil {
51+
panic(falcon.ErrorExplain(err))
52+
}
53+
result, err := session.ExecuteAndWait(context.Background(), strings.Split(*cmd, " ")[0], *cmd)
54+
if err != nil {
55+
panic(falcon.ErrorExplain(err))
56+
}
57+
58+
json, _ := falcon_util.PrettyJson(result)
59+
fmt.Println(json)
60+
}

0 commit comments

Comments
 (0)