bqm 1.2.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/bin/bqm +50 -4
  3. data/data/query-sets.json +2 -1
  4. metadata +5 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 28bbff6c42f4653702f6e091868d7b54e83b461c3501a5eeffd5d423a04445e2
4
- data.tar.gz: dc65921e523353a6ab7ae6be055e901c9cb8d83c4fb1f2c7483e8029d2408903
3
+ metadata.gz: 4a7ea69f913278933cdcbae6a764b166d7990931ce1f68c1264f3c0127f548ad
4
+ data.tar.gz: 65a2b6a2aa1e78864e48671a2f8b5e4ce395fa0eaead13ce3098806cc6391ce9
5
5
  SHA512:
6
- metadata.gz: 2fe4cc56dd34eed52c1d817867bad75399a4df798a66f87d897141441fee53418e3d1e3d33818efb97c49c928156db66ff0874215977ec6c1972d43b4d2e6a9e
7
- data.tar.gz: 57b22d6b6724487fb7316b746c3fb6c3d0236de816a057cfafefb09e7321a80b27d5df77cd51b0f474a525ed62830486c7e1e478acaf7c5fdc4fd394478aecff
6
+ metadata.gz: be95aaeccf71fb47aac6179e3be127d5d456fc88e4f67b1798b46dfafcf24cba0220cc6c5569fba98acbd24b9ca2f6bde71adb2604e9b0d9e2e4afeb56bb743f
7
+ data.tar.gz: c752dc0e0d790b2b9e5337d5622cf05fd5d553558d7c3cb6654829ad54d8fb88157849e4d70c5a55589327c136dd2d442a857089d244923062953ba6b3a06f83
data/bin/bqm CHANGED
@@ -14,7 +14,8 @@ def find_dataset
14
14
  raise IOError, "The dataset file #{source_file} does not exist or is unreadable."
15
15
  end
16
16
 
17
- def merge(source)
17
+ # Merge remote sets defined in data/query-sets.json
18
+ def merge_remote(source)
18
19
  sets = get_datasets(source)
19
20
  queries = []
20
21
  sets.each do |s|
@@ -25,6 +26,24 @@ def merge(source)
25
26
  queries
26
27
  end
27
28
 
29
+ # Merge local sets provided by the user
30
+ def merge_local(sources)
31
+ queries = []
32
+ sources.each do |source|
33
+ if File.file?(source) && File.readable?(source)
34
+ begin
35
+ data = JSON.load_file(source)
36
+ rescue NoMethodError # ruby 2.7 retro-compatibility
37
+ data = JSON.parse(File.read(source))
38
+ end
39
+ queries += data['queries']
40
+ else
41
+ raise IOError, "The dataset file #{source} does not exist or is unreadable."
42
+ end
43
+ end
44
+ queries
45
+ end
46
+
28
47
  # Query class just for the sake of having custom comparison
29
48
  class BQMquery
30
49
  attr_accessor :data
@@ -59,7 +78,8 @@ def pretty_link(lst)
59
78
  end
60
79
 
61
80
  def get_datasets(source)
62
- begin # ruby 3.0+
81
+ # ruby 3.0+
82
+ begin
63
83
  src = JSON.load_file(source)
64
84
  rescue NoMethodError # ruby 2.7 retro-compatibility
65
85
  src = JSON.parse(File.read(source))
@@ -71,14 +91,20 @@ if __FILE__ == $PROGRAM_NAME
71
91
  source = find_dataset
72
92
 
73
93
  require 'optparse'
74
- options = {}
94
+ options = {
95
+ :'local-sets' => []
96
+ }
75
97
  OptionParser.new do |parser|
76
98
  parser.banner = 'Usage: bqm [options]'
77
99
 
78
100
  parser.on('-o', '--output-path PATH', 'Path where to store the query file')
79
101
  parser.on('-l', '--list', 'List available datasets')
102
+ parser.on('-i', '--local-sets FILE,...', Array, 'Local custom queries files') do |f|
103
+ options[:'local-sets'] += f
104
+ end
80
105
  parser.separator ''
81
106
  parser.separator 'Example: bqm -o ~/.config/bloodhound/customqueries.json'
107
+ parser.separator 'Example: bqm -o /tmp/customqueries.json -i /tmp/a.json,/tmp/b.json'
82
108
  end.parse!(into: options)
83
109
 
84
110
  out = options[:'output-path']
@@ -89,8 +115,28 @@ if __FILE__ == $PROGRAM_NAME
89
115
  puts l
90
116
  end
91
117
  elsif out
118
+ flags = {}
119
+ flags[:merge_actual] = false
120
+ if File.file?(out) && File.readable?(out)
121
+ puts "[+] The output path #{out} already exists"
122
+ puts '[?] Do you want to overwrite it? [y/n]'
123
+ if STDIN.gets.chomp == 'y'
124
+ puts '[?] What to do with the existing queries? (merge / discard) [m/d]'
125
+ flags[:merge_actual] = true if STDIN.gets.chomp == 'm'
126
+ else
127
+ exit
128
+ end
129
+ end
92
130
  puts '[+] Fetching and merging datasets'
93
- data = merge(source)
131
+ data = merge_remote(source)
132
+ local_set = options[:'local-sets']
133
+ if local_set
134
+ data += merge_local(local_set)
135
+ end
136
+ if flags[:'merge_actual']
137
+ puts '[+] Merging your existing queries'
138
+ data += JSON.parse(File.read(out))['queries']
139
+ end
94
140
  puts '[+] Removing duplicates'
95
141
  queries = deduplicate(data).map(&:data)
96
142
 
data/data/query-sets.json CHANGED
@@ -11,6 +11,7 @@
11
11
  "https://raw.githubusercontent.com/zeronetworks/BloodHound-Tools/main/CustomQueries/customqueries.json",
12
12
  "https://raw.githubusercontent.com/egypt/customqueries/master/customqueries.json",
13
13
  "https://raw.githubusercontent.com/trustedsec/CrackHound/main/customqueries.json",
14
- "https://raw.githubusercontent.com/aress31/bloodhound-utils/main/customqueries.json"
14
+ "https://raw.githubusercontent.com/aress31/bloodhound-utils/main/customqueries.json",
15
+ "https://raw.githubusercontent.com/ThePorgs/Exegol-images/main/sources/bloodhound/customqueries.json"
15
16
  ]
16
17
  }
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bqm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre ZANNI
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-01-26 00:00:00.000000000 Z
11
+ date: 2023-06-26 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Deduplicate custom BloudHound queries from different datasets and merge
14
14
  them in one customqueries.json file.
@@ -26,6 +26,8 @@ licenses:
26
26
  - MIT
27
27
  metadata:
28
28
  bug_tracker_uri: https://github.com/Acceis/bqm/issues
29
+ changelog_uri: https://github.com/Acceis/bqm/releases
30
+ documentation_uri: https://acceis.github.io/bqm/
29
31
  homepage_uri: https://github.com/Acceis/bqm
30
32
  source_code_uri: https://github.com/Acceis/bqm/
31
33
  rubygems_mfa_required: 'true'
@@ -40,7 +42,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
40
42
  version: 2.6.0
41
43
  - - "<"
42
44
  - !ruby/object:Gem::Version
43
- version: '3.3'
45
+ version: '4.0'
44
46
  required_rubygems_version: !ruby/object:Gem::Requirement
45
47
  requirements:
46
48
  - - ">="