-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2e80f2
commit 0be7012
Showing
5 changed files
with
101 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/aquasecurity/tracee/types/detect" | ||
"github.com/aquasecurity/tracee/types/protocol" | ||
"github.com/aquasecurity/tracee/types/trace" | ||
) | ||
|
||
type e2eDnsDataSource struct { | ||
cb detect.SignatureHandler | ||
dnsData detect.DataSource | ||
} | ||
|
||
func (sig *e2eDnsDataSource) Init(ctx detect.SignatureContext) error { | ||
sig.cb = ctx.Callback | ||
dnsData, ok := ctx.GetDataSource("tracee", "dns") | ||
if !ok { | ||
return fmt.Errorf("dns data source not registered") | ||
} | ||
if dnsData.Version() > 1 { | ||
return fmt.Errorf("dns data source version not supported, please update this signature") | ||
} | ||
sig.dnsData = dnsData | ||
return nil | ||
} | ||
|
||
func (sig *e2eDnsDataSource) GetMetadata() (detect.SignatureMetadata, error) { | ||
return detect.SignatureMetadata{ | ||
ID: "DNS_DATA_SOURCE", | ||
EventName: "DNS_DATA_SOURCE", | ||
Version: "0.1.0", | ||
Name: "DNS Data Source Test", | ||
Description: "Instrumentation events E2E Tests: DNS Data Source Test", | ||
Tags: []string{"e2e", "instrumentation"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eDnsDataSource) GetSelectedEvents() ([]detect.SignatureEventSelector, error) { | ||
return []detect.SignatureEventSelector{ | ||
{Source: "tracee", Name: "sched_process_exit"}, | ||
}, nil | ||
} | ||
|
||
func (sig *e2eDnsDataSource) OnEvent(event protocol.Event) error { | ||
eventObj, ok := event.Payload.(trace.Event) | ||
if !ok { | ||
return fmt.Errorf("failed to cast event's payload") | ||
} | ||
|
||
switch eventObj.EventName { | ||
case "sched_process_exit": | ||
if eventObj.Executable.Path != "/usr/bin/ping" { | ||
return nil // irrelevant code path | ||
} | ||
|
||
container, err := sig.dnsData.Get("google.com") | ||
if err != nil { | ||
return fmt.Errorf("failed to find container in data source: %v", err) | ||
} | ||
|
||
ipResults, ok := container["ip_results"].([]string) | ||
if !ok { | ||
return fmt.Errorf("failed to extract ip results") | ||
} | ||
|
||
if len(ipResults) < 1 { | ||
return fmt.Errorf("ip results were empty") | ||
} | ||
|
||
m, _ := sig.GetMetadata() | ||
|
||
sig.cb(detect.Finding{ | ||
SigMetadata: m, | ||
Event: event, | ||
Data: map[string]interface{}{}, | ||
}) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (sig *e2eDnsDataSource) OnSignal(s detect.Signal) error { | ||
return nil | ||
} | ||
|
||
func (sig *e2eDnsDataSource) Close() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/bin/bash | ||
|
||
exit_err() { | ||
echo -n "ERROR: " | ||
echo $@ | ||
exit 1 | ||
} | ||
|
||
ping -c 1 google.com > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters