Skip to content

Commit b84f0f9

Browse files
committed
v1-prerelease
1 parent 25e5293 commit b84f0f9

File tree

5 files changed

+145
-5
lines changed

5 files changed

+145
-5
lines changed

CHANGELOG.md

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,32 @@
22

33
All notable changes to this project will be documented in this file.
44

5+
<br><br>
56

6-
## Unreleased - feature/loadremote
7+
## EXPERIMENTAL FEATURE - feature/targetid
8+
9+
**Commit**: [e95c0ed](https://github.com/xfhg/intercept/commit/e95c0ed)
10+
11+
**Branch** [feature/loadremote](https://github.com/xfhg/intercept/tree/feature/targetid)
12+
13+
**Summary**: Fingerprint hosts for reporting --experimental
14+
15+
### Breaking
16+
- Properties on Final SARIF report key names corrected to kebab case.
17+
18+
### Added
19+
- Added Global hostData & hostFingerprint
20+
- Added "host-data" & "host-fingerprint" to Final SARIF Report
21+
22+
### Changed
23+
- Properties on Final SARIF report key names corrected to kebab case.
24+
25+
### Removed
26+
- None
27+
28+
<br><br><br><br>
29+
30+
## FEATURE - feature/loadremote
731

832
**Commit**: [e95c0ed](https://github.com/xfhg/intercept/commit/e95c0ed)
933

cmd/policy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,12 @@ type Config struct {
2626
ReportSchedule string `yaml:"report_schedule"`
2727
} `yaml:"Flags"`
2828
Metadata struct {
29+
HostOS string `yaml:"host_os,omitempty"`
30+
HostMAC string `yaml:"host_mac,omitempty"`
31+
HostARCH string `yaml:"host_arch,omitempty"`
32+
HostNAME string `yaml:"host_name,omitempty"`
33+
HostFingerprint string `yaml:"host_fingerprint,omitempty"`
34+
HostInfo string `yaml:"host_info,omitempty"`
2935
MsgExitClean string `yaml:"MsgExitClean"`
3036
MsgExitWarning string `yaml:"MsgExitWarning"`
3137
MsgExitCritical string `yaml:"MsgExitCritical"`

cmd/root.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ var (
2020
silentMode bool
2121
nologMode bool
2222

23+
hostData string
24+
hostFingerprint string
25+
2326
buildVersion string
2427
buildSignature string
2528

@@ -94,8 +97,30 @@ func setupLogging() {
9497
log = zerolog.New(output).With().Timestamp().Logger()
9598

9699
if experimentalMode {
100+
101+
// ----------------------------------------------
102+
// ---------------------------------------------- EXPERIMENTAL log caller debug
103+
// ----------------------------------------------
104+
97105
log = zerolog.New(output).With().Timestamp().Logger().With().Caller().Logger()
98106
// log = zerolog.New(output).With().Timestamp().Logger().With().Str("id", intercept_run_id).Logger()
107+
108+
// ----------------------------------------------
109+
// ---------------------------------------------- EXPERIMENTAL feature/targetid
110+
// ----------------------------------------------
111+
112+
hostInfo, err := GetHostInfo()
113+
if err != nil {
114+
log.Error().Msgf("Error gathering host info: %v\n", err)
115+
}
116+
117+
hostData, hostFingerprint, err := FingerprintHost(hostInfo)
118+
if err != nil {
119+
log.Error().Msgf("Error generating fingerprint: %v\n", err)
120+
}
121+
log.Info().Msgf("Host Data: %s", hostData)
122+
log.Info().Msgf("Host Fingerprint: %s", hostFingerprint)
123+
99124
}
100125
if silentMode {
101126

cmd/sarif.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -545,13 +545,15 @@ func MergeSARIFReports(commandLine string, perf Performance, isScheduled bool) (
545545
ExecutionSuccessful: true,
546546
CommandLine: commandLine,
547547
Properties: map[string]string{
548-
"run_id": intercept_run_id,
549-
"start_time": perf.StartTime.Format(time.RFC3339),
550-
"end_time": perf.EndTime.Format(time.RFC3339),
551-
"execution_time_ms": fmt.Sprintf("%d", perf.Delta.Milliseconds()),
548+
"run-id": intercept_run_id,
549+
"start-time": perf.StartTime.Format(time.RFC3339),
550+
"end-time": perf.EndTime.Format(time.RFC3339),
551+
"execution-time-ms": fmt.Sprintf("%d", perf.Delta.Milliseconds()),
552552
"environment": environment,
553553
"debug": fmt.Sprintf("%v", debugOutput),
554554
"report-timestamp": timestamp,
555+
"host-data": hostData,
556+
"host-fingerprint": hostFingerprint,
555557
},
556558
},
557559
},

cmd/watch.go

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,27 @@
11
package cmd
22

33
import (
4+
"crypto/sha256"
5+
"encoding/hex"
46
"fmt"
7+
"net"
8+
"os"
9+
"runtime"
10+
"strings"
511
"time"
612

713
"github.com/fsnotify/fsnotify"
814
"github.com/segmentio/ksuid"
915
)
1016

17+
type HostInfo struct {
18+
Hostname string
19+
OS string
20+
Architecture string
21+
IPs []string
22+
MAC string
23+
}
24+
1125
func watchPaths(paths ...string) {
1226
if len(paths) < 1 {
1327
log.Fatal().Msg("must specify at least one path to watch")
@@ -95,3 +109,72 @@ func processEvent(e fsnotify.Event) {
95109
log.Error().Msgf("Policy not found in cache, watcher event [%s] didn't trigger policy process for: %s", e.Op.String(), e.Name)
96110
}
97111
}
112+
113+
func GetHostInfo() (*HostInfo, error) {
114+
hostInfo := &HostInfo{}
115+
116+
// Get hostname
117+
hostname, err := os.Hostname()
118+
if err != nil {
119+
return nil, fmt.Errorf("failed to get hostname: %v", err)
120+
}
121+
hostInfo.Hostname = hostname
122+
123+
// Get OS and architecture
124+
hostInfo.OS = runtime.GOOS
125+
hostInfo.Architecture = runtime.GOARCH
126+
127+
// Get IPs and MAC addresses
128+
interfaces, err := net.Interfaces()
129+
if err != nil {
130+
return nil, fmt.Errorf("failed to get network interfaces: %v", err)
131+
}
132+
133+
for _, iface := range interfaces {
134+
if iface.Flags&net.FlagUp == 0 {
135+
continue // ignore interfaces that are down
136+
}
137+
138+
addrs, err := iface.Addrs()
139+
if err != nil {
140+
return nil, fmt.Errorf("failed to get addresses for interface %v: %v", iface.Name, err)
141+
}
142+
143+
for _, addr := range addrs {
144+
ip, _, err := net.ParseCIDR(addr.String())
145+
if err != nil {
146+
return nil, fmt.Errorf("failed to parse IP address %v: %v", addr.String(), err)
147+
}
148+
149+
if ip.IsLoopback() {
150+
continue // ignore loopback addresses
151+
}
152+
153+
hostInfo.IPs = append(hostInfo.IPs, ip.String())
154+
}
155+
// main MAC
156+
if iface.Flags&net.FlagUp != 0 && iface.HardwareAddr.String() != "" {
157+
hostInfo.MAC = iface.HardwareAddr.String()
158+
}
159+
160+
}
161+
162+
return hostInfo, nil
163+
}
164+
165+
// FingerprintHost generates a fingerprint for the host using its identifiable information
166+
func FingerprintHost(hostInfo *HostInfo) (string, string, error) {
167+
data := strings.Join([]string{
168+
hostInfo.MAC,
169+
hostInfo.OS,
170+
hostInfo.Architecture,
171+
hostInfo.Hostname,
172+
}, "|")
173+
hash := sha256.New()
174+
_, err := hash.Write([]byte(data))
175+
if err != nil {
176+
return "", "", fmt.Errorf("failed to generate hash: %v", err)
177+
}
178+
fingerprint := hex.EncodeToString(hash.Sum(nil))
179+
return data, fingerprint, nil
180+
}

0 commit comments

Comments
 (0)