Skip to content

Commit ecae7f7

Browse files
Use buckets instead of prefixes.
Remove buckets from the configuration. Create a bucket for each data type collected.
1 parent 1a784ec commit ecae7f7

File tree

4 files changed

+25
-27
lines changed

4 files changed

+25
-27
lines changed

config.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ import (
1212

1313
type Keyword struct {
1414
Keyword string
15-
Prefix string
15+
Bucket string
1616
}
1717

1818
type Regex struct {
1919
Regex string
2020
compiled *regexp.Regexp
21-
Prefix string
21+
Bucket string
2222
Match string
2323
}
2424

@@ -27,7 +27,6 @@ type Config struct {
2727
db *bolt.DB
2828
Keywords []*Keyword // A list of keywords to search for in the data.
2929
Regexes []*Regex // A list of regular expressions to test against data.
30-
Buckets []string `json:"buckets"` // List of buckets we need to create.
3130
DbFile string `json:"database_file"` // File to use for the Store database.
3231
MaxSize int `json:"max_size"` // Do not save files larger than this many bytes.
3332
MaxTime int `json:"max_time"` // Max time, in seconds, to store previously downloaded keys.

config.json

+11-16
Original file line numberDiff line numberDiff line change
@@ -5,52 +5,47 @@
55
"database_file": "data/scrape.db",
66
"github_token": "github_api_token",
77
"save": true,
8-
"buckets": [
9-
"keywords",
10-
"regexes",
11-
"pastes"
12-
],
138
"regexes": [
149
{
1510
"regex": "^([a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]+):([^ ~/$|: ]+)",
16-
"prefix": "creds",
11+
"bucket": "creds",
1712
"match": "all"
1813
},
1914
{
2015
"regex": "[a-zA-Z0-9+_.-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}",
21-
"prefix": "email",
16+
"bucket": "email",
2217
"match": "all"
2318
},
2419
{
2520
"regex": "(?s)BEGIN (RSA|DSA|) PRIVATE KEY.*END (RSA|DSA|) PRIVATE KEY",
26-
"prefix": "privkey",
21+
"bucket": "privkey",
2722
"match": "all"
2823
},
2924
{
3025
"regex": "\\$[0-9]\\$[a-zA-Z0-9]+\\$[a-zA-Z0-9./=]+",
31-
"prefix": "pwhash",
26+
"bucket": "pwhash",
3227
"match": "all"
3328
},
3429
{
3530
"regex": "[a-zA-Z0-9]+::[a-zA-Z0-9]{10}:[a-z0-9]{32}:[a-z0-9-]+",
36-
"prefix": "pwhash",
31+
"bucket": "pwhash",
3732
"match": "all"
3833
},
3934
{
4035
"regex": "[a-zA-Z0-9-_]+:[0-9]+:[a-z0-9]{32}:[a-z0-9]{32}",
41-
"prefix": "pwhash",
36+
"bucket": "pwhash",
4237
"match": "all"
4338
},
4439
{
4540
"regex": "CVE-[0-9]{4}-[0-9]{4,5}",
46-
"prefix": "exploit",
41+
"bucket": "exploit",
4742
"match": "one"
4843
}
4944
],
5045
"keywords": [
51-
{"keyword": "`password`", "prefix": "sqlpass"},
52-
{"keyword": "proof of concept", "prefix": "exploit"},
53-
{"keyword": "remote code execution", "prefix": "exploit"},
54-
{"keyword": "fullz", "prefix": "carder"}
46+
{"keyword": "`password`", "bucket": "sqlpass"},
47+
{"keyword": "proof of concept", "bucket": "exploit"},
48+
{"keyword": "remote code execution", "bucket": "exploit"},
49+
{"keyword": "fullz", "bucket": "carder"}
5550
]
5651
}

process.go

+4-6
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,15 @@ func processRegexes(key, content string) {
3131
}
3232

3333
for k := range items {
34-
rKey := fmt.Sprintf("%s-%s-%d", r.Prefix, key, k)
35-
writeDB(conf.db, "regexes", rKey, []byte(items[k]))
34+
rKey := fmt.Sprintf("%s-%d", key, k)
35+
writeDB(conf.db, r.Bucket, rKey, []byte(items[k]))
3636
}
3737
case "one":
3838
match := r.compiled.FindString(content)
39-
rKey := fmt.Sprintf("%s-%s", r.Prefix, key)
4039

4140
if match != "" {
4241
save = true
43-
writeDB(conf.db, "regexes", rKey, []byte(match))
42+
writeDB(conf.db, r.Bucket, key, []byte(match))
4443
}
4544
default:
4645
}
@@ -55,11 +54,10 @@ func processKeywords(key, content string) {
5554
save := false
5655
for i, _ := range conf.Keywords {
5756
kwd := conf.Keywords[i]
58-
kwdKey := fmt.Sprintf("%s-%s", kwd.Prefix, key)
5957

6058
if strings.Contains(strings.ToLower(content), strings.ToLower(kwd.Keyword)) {
6159
save = true
62-
writeDB(conf.db, "keywords", kwdKey, []byte(key))
60+
writeDB(conf.db, kwd.Bucket, key, nil)
6361
}
6462
}
6563

store.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,14 @@ func getDBConn() *bolt.DB {
2525
func initDB() {
2626
db := getDBConn()
2727

28-
for _, bucket := range conf.Buckets {
29-
createBucket(db, bucket)
28+
createBucket(db, "pastes")
29+
30+
for _, kw := range conf.Keywords {
31+
createBucket(db, kw.Bucket)
32+
}
33+
34+
for _, re := range conf.Regexes {
35+
createBucket(db, re.Bucket)
3036
}
3137

3238
db.Close()

0 commit comments

Comments
 (0)