Skip to content

Commit 50aad3e

Browse files
committed
- Adding '-tifeeds' parameter to summarize the ThreatDB Feeds currently stored.
1 parent b6235b0 commit 50aad3e

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

helpers/threatIntel.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ type threatsCatReport struct {
3333
count int
3434
}
3535

36+
type feedReport struct {
37+
url string
38+
name string
39+
}
40+
3641
type iPCheckResults struct {
3742
feed_name string
3843
category string
@@ -73,6 +78,42 @@ func SummarizeThreatDB(logger zerolog.Logger) {
7378
}
7479
}
7580

81+
func SummarizeThreatFeeds(logger zerolog.Logger) {
82+
db, err := OpenDBConnection(logger)
83+
logger.Info().Msg("Summarizing ThreatDB Feeds")
84+
if err != nil {
85+
logger.Error().Msg("Could not initialize access to threat DB!")
86+
return
87+
}
88+
query := "SELECT COUNT(*) FROM feeds"
89+
rows, err := db.Query(query)
90+
if err != nil {
91+
logger.Error().Msg(err.Error())
92+
return
93+
}
94+
var feedCount string
95+
for rows.Next() {
96+
err = rows.Scan(&feedCount)
97+
}
98+
rows.Close()
99+
logger.Info().Msgf("Total Feeds: %v", feedCount)
100+
101+
query_types := "SELECT feed_url, feed_name FROM feeds"
102+
rows_types, err := db.Query(query_types)
103+
if err != nil {
104+
logger.Error().Msg(err.Error())
105+
return
106+
}
107+
for rows_types.Next() {
108+
tmp := feedReport{}
109+
if err := rows_types.Scan(&tmp.url, &tmp.name); err != nil {
110+
logger.Error().Msg(err.Error())
111+
return
112+
}
113+
logger.Info().Msgf("Feed Name: %v, URL: %v", tmp.name, tmp.url)
114+
}
115+
}
116+
76117
func BuildThreatDB(arguments map[string]any, logger zerolog.Logger) error {
77118
// First check if the db exists - if not, initialize the database
78119
// Table name: ips

main.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ func parseArgs(logger zerolog.Logger) (map[string]any, error) {
5050
intelfile := flag.String("intelfile", "", "The path to a local text file to be added to the threat intelligence database. Must also specify the 'type' of intel using -inteltype as well as the name via -intelname")
5151
inteltype := flag.String("inteltype", "", "A string-based identifier that will appear when matches occur - tor, suspicious, proxy, etc - something to identify what type of file we are ingesting. Must also specify the file via -intelfile and name via -intelname.")
5252
summarizeti := flag.Bool("summarizeti", false, "Summarize the contents of the ThreatDB, if it exists.")
53+
tifeeds := flag.Bool("tifeeds", false, "See all currently ingested Threat Indicator Feeds")
5354
fullparse := flag.Bool("fullparse", false, "If specified, will scan entire files for all possible keys to use in CSV rather than generalizing messages into an entire column - increases processing time. Use to expand JSON blobs inside columnar data with -jsoncol to provide the name of the column.")
5455
updategeo := flag.Bool("updategeo", false, "Update local MaxMind databases, even if they are detected.")
5556
passthrough := flag.Bool("passthrough", false, "Skip all enrichment steps - only perform log conversion to CSV")
@@ -89,6 +90,7 @@ func parseArgs(logger zerolog.Logger) (map[string]any, error) {
8990
"inteltype": *inteltype,
9091
"intelname": *intelname,
9192
"summarizeti": *summarizeti,
93+
"tifeeds": *tifeeds,
9294
"fullparse": *fullparse,
9395
"updategeo": *updategeo,
9496
"passthrough": *passthrough,
@@ -516,6 +518,16 @@ func main() {
516518
return
517519
}
518520

521+
if arguments["tifeeds"].(bool) {
522+
_, err := os.Stat(helpers.ThreatDBFile)
523+
if errors.Is(err, os.ErrNotExist) {
524+
logger.Error().Msg(err.Error())
525+
} else {
526+
helpers.SummarizeThreatFeeds(logger)
527+
}
528+
return
529+
}
530+
519531
if arguments["useti"].(bool) {
520532
_, err := os.Stat(helpers.ThreatDBFile)
521533
if errors.Is(err, os.ErrNotExist) {

0 commit comments

Comments
 (0)