Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial test of ntfs ads table #2062

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions ee/tables/ntfs_ads_zone_id/zone_identifier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
//go:build windows
// +build windows

package ntfs_ads_zone_id

import (
"bytes"
"context"
"fmt"
"log/slog"
"path/filepath"
"strings"

"github.com/kolide/launcher/ee/allowedcmd"
"github.com/kolide/launcher/ee/dataflatten"
"github.com/kolide/launcher/ee/tables/dataflattentable"
"github.com/kolide/launcher/ee/tables/tablehelpers"
"github.com/osquery/osquery-go/plugin/table"
)

type Table struct {
slogger *slog.Logger
}

func TablePlugin(slogger *slog.Logger) *table.Plugin {
columns := dataflattentable.Columns(
table.TextColumn("path"),
)

t := &Table{
slogger: slogger.With("table", "kolide_ntfs_ads_zone_id"),
}

return table.NewPlugin("kolide_ntfs_ads_zone_id", columns, t.generate)
}

func (t *Table) generate(ctx context.Context, queryContext table.QueryContext) ([]map[string]string, error) {
var results []map[string]string

paths := tablehelpers.GetConstraints(queryContext, "path")
if len(paths) < 1 {
return nil, fmt.Errorf("kolide_ntfs_ads_zone_id requires at least one path to be specified")
}

for _, path := range paths {
for _, dataQuery := range tablehelpers.GetConstraints(queryContext, "query", tablehelpers.WithDefaults("*")) {
var output bytes.Buffer
if err := tablehelpers.Run(ctx, t.slogger, 30, allowedcmd.Powershell, []string{"Get-Content", "-Path", filepath.Clean(path), "-Stream", "Zone.Identifier", "-ErrorAction", "Ignore"}, &output, &output); err != nil {
t.slogger.Log(ctx, slog.LevelInfo, "failure running powershell get-content command", "err", err, "path", path)
continue
}

flattenOpts := []dataflatten.FlattenOpts{
dataflatten.WithSlogger(t.slogger),
dataflatten.WithQuery(strings.Split(dataQuery, "/")),
}

flattened, err := dataflatten.Ini(output.Bytes(), flattenOpts...)
if err != nil {
t.slogger.Log(ctx, slog.LevelInfo, "failure flattening output", "err", err)
continue
}

rowData := map[string]string{
"path": path,
}

results = append(results, dataflattentable.ToMap(flattened, dataQuery, rowData)...)
}
}

return results, nil
}
2 changes: 2 additions & 0 deletions pkg/osquery/table/platform_tables_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/kolide/launcher/ee/tables/dataflattentable"
"github.com/kolide/launcher/ee/tables/dsim_default_associations"
"github.com/kolide/launcher/ee/tables/execparsers/dsregcmd"
"github.com/kolide/launcher/ee/tables/ntfs_ads_zone_id"
"github.com/kolide/launcher/ee/tables/secedit"
"github.com/kolide/launcher/ee/tables/wifi_networks"
"github.com/kolide/launcher/ee/tables/windowsupdatetable"
Expand All @@ -21,6 +22,7 @@ func platformSpecificTables(slogger *slog.Logger, currentOsquerydBinaryPath stri
return []osquery.OsqueryPlugin{
ProgramIcons(),
dsim_default_associations.TablePlugin(slogger),
ntfs_ads_zone_id.TablePlugin(slogger),
secedit.TablePlugin(slogger),
wifi_networks.TablePlugin(slogger),
windowsupdatetable.TablePlugin(windowsupdatetable.UpdatesTable, slogger),
Expand Down
Loading