dns-monitor 0.1.4 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9747d0406d551004a09261b0963a7404f2656cd8a33d0dcdc93be963cf84a70
4
- data.tar.gz: e6256a7d5182cdce76f44ce912438da8ac2b4ea53ec15249a3e69f9047bea3fb
3
+ metadata.gz: bc60a21af3be2fcd941068194c3a95e3e34f8ea61ca6904abb7b0df308de6d51
4
+ data.tar.gz: d050420fb42ee563d65b39cbec271faa914396b1f8b0d45fbc86b623bb3a86f2
5
5
  SHA512:
6
- metadata.gz: 681d88adfc5c206241bb672e7ee5eaff1f8b93e3093239867c159a603b894adc9fad9125b88cfb55ea1038c4f0927ebeae229da94e140ed9b7b29fcd52d54cd4
7
- data.tar.gz: 731dde7868fb67b0a5a1002a8d219df547328ef2fa976dce258639d158ac6e001b4859b4cdecfb8be5986e33d7fa194d7737178fd2fe612163167e6578dee2f2
6
+ metadata.gz: 6496e84804826037339fc58c12de60415b56e6c48239579ba288f6df13fddbe1a46b08db84313f918a3cfbcdda8cfd9bfb494e2edf8ce593744f8cec8663754d
7
+ data.tar.gz: b3c27dad480792ddbad45fb897935a8eca0e7b6069a2a829997615f361678d3a700227cbe2de31eb9b72e1748f7cea33be00824aec45578e3364ffc7e7722eb2
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- dns-monitor (0.1.3)
4
+ dns-monitor (0.1.6)
5
5
  easy_diff (~> 1.0.0)
6
6
  sqlite3 (~> 1.4.2)
7
7
 
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  # DNS::Monitor
2
2
 
3
- The point of this gem is to monitor your hosts for (unwanted) DNS changes. The executable `dns-monitor` file is designed to be run as a CRON job. It takes a return-delimited text file listing domain names, and checks an RDAP database (which you can specify) for JSON entries that match. You will get an error, optionally by GChat, if you encounter a changed entry.
3
+ [![Gem Version](https://badge.fury.io/rb/dns-monitor.svg)](https://badge.fury.io/rb/dns-monitor)
4
+
5
+ The point of this gem is to monitor your hosts for (unwanted) DNS changes. The `dns-monitor` app is designed to be run as a CRON job. It takes a return-delimited text file listing domain names, and checks an [RDAP](https://www.icann.org/rdap) database (which you can specify) for JSON entries that match. You will get an error, optionally by GChat, if you encounter a changed entry.
4
6
 
5
7
  If you don't think this is something you need, perhaps give [this article](https://krebsonsecurity.com/2019/02/a-deep-dive-on-the-recent-widespread-dns-hijacking-attacks/) a read.
6
8
 
@@ -1,6 +1,7 @@
1
1
  module DNS
2
2
  module Monitor
3
3
  class Check
4
+ # A "Check" is an encapsulated domain query result.
4
5
  def initialize(domain, status, diff={})
5
6
  @diff = diff
6
7
  @domain = domain
@@ -13,7 +13,7 @@ module DNS
13
13
  def check(domain, rdap)
14
14
  return if domain.nil? || rdap.nil?
15
15
 
16
- changes = diff(most_recent(domain).rdap, rdap)
16
+ changes = diff((most_recent(domain).rdap || '{}'), rdap)
17
17
 
18
18
  if changes.empty?
19
19
  Check.new domain, :ok
@@ -29,10 +29,13 @@ module DNS
29
29
  end
30
30
 
31
31
  # Compare two different RDAP values
32
- # NOTE: We have to do a JSON conversion because the values come
33
- # back from the server in arbitrary JSON key order.
32
+ # NOTE: We have to do a JSON conversion to compare instead of
33
+ # String, because the values come back from the server in arbitrary JSON
34
+ # key order.
34
35
  def diff(previous_rdap, rdap)
35
- JSON.parse(previous_rdap).easy_diff(JSON.parse(rdap)).last
36
+ # easy_diff returns [added, removed] hashes, we want "removed"
37
+ changes = JSON.parse(previous_rdap).easy_diff(JSON.parse(rdap)).last
38
+ filter_noisy_keys(changes)
36
39
  end
37
40
 
38
41
  # Return all entries for a given domain as a Domain struct
@@ -41,6 +44,19 @@ module DNS
41
44
  query {|db| db.execute(sql, [domain]) }.map{ |row| Domain.new(*row) }
42
45
  end
43
46
 
47
+ def filter_noisy_keys(changes)
48
+ # We get a lot of "last update of RDAP" events which aren't something
49
+ # we need notifications about. Remove those.
50
+ # WARNING: mutation follows
51
+ if changes.fetch('events', false)
52
+ changes['events'] = changes['events'].reject do |event|
53
+ event.fetch('eventAction', '').match?(/last update of RDAP/i)
54
+ end
55
+ changes.delete('events') if changes['events'].empty?
56
+ end
57
+ changes
58
+ end
59
+
44
60
  # Just the latest entry plz
45
61
  def most_recent(domain)
46
62
  entries(domain).first || Domain.new
@@ -1,10 +1,12 @@
1
1
  module DNS
2
2
  module Monitor
3
3
  class Runner
4
+ # The "Runner" is the back-end for the command-line utility
4
5
  def initialize(params)
5
6
  @params = params
6
7
  end
7
8
 
9
+ # This is the main action we do with this app - check all of the domains
8
10
  def check
9
11
  begin
10
12
  domains = File.read(@params[:domains_path]).split
@@ -31,6 +33,7 @@ module DNS
31
33
  end
32
34
  end
33
35
 
36
+ # This is an alternative app action - check the history for a particular domain.
34
37
  def entries
35
38
  STDOUT.puts db.entries(@params[:domain]).map{|row| row.to_parsed_h}.to_json
36
39
  end
@@ -1,5 +1,5 @@
1
1
  module DNS
2
2
  module Monitor
3
- VERSION = "0.1.4"
3
+ VERSION = "0.1.6"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dns-monitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Donald Merand
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-28 00:00:00.000000000 Z
11
+ date: 2020-01-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -126,7 +126,6 @@ files:
126
126
  - lib/dns/monitor/mandrill.rb
127
127
  - lib/dns/monitor/runner.rb
128
128
  - lib/dns/monitor/version.rb
129
- - test.sqlite3
130
129
  homepage: https://github.com/exploration/dns-monitor
131
130
  licenses:
132
131
  - MIT
Binary file