dmarcer 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/dmarcer.gemspec +34 -0
- data/exe/dmarcer +6 -0
- data/lib/dmarcer.rb +172 -0
- data/lib/dmarcer/version.rb +3 -0
- metadata +101 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b38f09817cdcfe4184c0f24ab25501664282c3e9
|
4
|
+
data.tar.gz: fef58c42d88eb1171d374356bb82100e87830d51
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7ca376c1fd9b111fb2adaf88f1c6124a41d14e9afd7a3456163a154c6d989e930ec436d23260b585331c5493cf2b0433ce84a3c29ccb0a4a79ce5dee0396a3b9
|
7
|
+
data.tar.gz: d18a31b4f9fd087ee7c33de750513d69572c640ec287ecdd2487ac1705dec4b72038b6f7d2e1895763f4fb26736ba7e45f055be538e6427ff4afdbb8c9f9fc2c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Eric Herot
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Dmarcer
|
2
|
+
|
3
|
+
A tool for parsing out DMARC XML reports and printing useful data about where non-compliant emails came from and what "from" headers they included.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install it using:
|
8
|
+
|
9
|
+
$ gem install dmarcer
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Run it with your XML DMARC report as the argument:
|
14
|
+
|
15
|
+
$ dmarcer /path/to/report.xml
|
16
|
+
|
17
|
+
## Development
|
18
|
+
|
19
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
20
|
+
|
21
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/evertrue/dmarcer/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "dmarcer"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/dmarcer.gemspec
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'dmarcer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "dmarcer"
|
8
|
+
spec.version = Dmarcer::VERSION
|
9
|
+
spec.authors = ["Eric Herot"]
|
10
|
+
spec.email = ["eric.github@herot.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Parse an XML DMARC summary}
|
13
|
+
spec.description = spec.summary
|
14
|
+
spec.homepage = "http://blog.evertrue.com"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
if spec.respond_to?(:metadata)
|
20
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
21
|
+
else
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_dependency 'nokogiri'
|
31
|
+
|
32
|
+
spec.add_development_dependency "bundler", "~> 1.9"
|
33
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
34
|
+
end
|
data/exe/dmarcer
ADDED
data/lib/dmarcer.rb
ADDED
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'dmarcer/version'
|
2
|
+
require 'nokogiri'
|
3
|
+
require 'resolv'
|
4
|
+
|
5
|
+
module Dmarcer
|
6
|
+
class Parser
|
7
|
+
def initialize(input_file)
|
8
|
+
@input_file = input_file
|
9
|
+
end
|
10
|
+
|
11
|
+
def record_by_identifier(identifier)
|
12
|
+
data.record.select { |r| r.identifiers.header_from.content == identifier }
|
13
|
+
end
|
14
|
+
|
15
|
+
def identifiers
|
16
|
+
data.record.map { |r| r.identifiers.header_from.content }.uniq.sort
|
17
|
+
end
|
18
|
+
|
19
|
+
def org_name
|
20
|
+
data.report_metadata.org_name.content
|
21
|
+
end
|
22
|
+
|
23
|
+
def date_range
|
24
|
+
t_begin = Time.at(data.report_metadata.date_range.begin.content.to_i)
|
25
|
+
t_end = Time.at(data.report_metadata.date_range.end.content.to_i)
|
26
|
+
t_begin..t_end
|
27
|
+
end
|
28
|
+
|
29
|
+
def id
|
30
|
+
data.report_metadata.report_id.content
|
31
|
+
end
|
32
|
+
|
33
|
+
def records
|
34
|
+
@records ||= @data.record.map { |r| Record.new r }
|
35
|
+
end
|
36
|
+
|
37
|
+
def dkim_auth_failure_records
|
38
|
+
records.select { |r| r.auth_failed_dkim_domains.any? }
|
39
|
+
end
|
40
|
+
|
41
|
+
def spf_auth_failure_records
|
42
|
+
records.select { |r| r.auth_failed_spf_domains.any? }
|
43
|
+
end
|
44
|
+
|
45
|
+
def spf_domain_ip_hash
|
46
|
+
spf_auth_failure_records.each_with_object({}) do |r, m|
|
47
|
+
r.auth_failed_spf_domains.each do |d|
|
48
|
+
if m[d]
|
49
|
+
m[d] << r.source_ip
|
50
|
+
else
|
51
|
+
m[d] = [r.source_ip]
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def print_report
|
58
|
+
puts "Report Organization: #{org_name}"
|
59
|
+
puts "Report ID: #{id}"
|
60
|
+
puts "Date Range: #{date_range}"
|
61
|
+
puts ''
|
62
|
+
puts '------------------ SPF Failures ------------------'
|
63
|
+
# spf_auth_failure_records.each do |r|
|
64
|
+
# puts "Source IP: #{r.source_ip} (#{lookup(r.source_ip)})"
|
65
|
+
# puts "Auth failed SPF domains: #{r.auth_failed_spf_domains.join(', ')}"
|
66
|
+
# puts ''
|
67
|
+
# end
|
68
|
+
spf_domain_ip_hash.each do |domain, ips|
|
69
|
+
puts domain
|
70
|
+
ips.each { |ip| puts " #{lookup(ip)} [#{ip}]" }
|
71
|
+
puts ''
|
72
|
+
end
|
73
|
+
puts '------------------ DKIM Failures ------------------'
|
74
|
+
dkim_auth_failure_records.each do |r|
|
75
|
+
puts "Source IP: #{r.source_ip} (#{lookup(r.source_ip)})"
|
76
|
+
unless r.auth_failed_dkim_domains == ['evertrue.com']
|
77
|
+
puts "Auth failed DKIM domains: #{r.auth_failed_dkim_domains.join(', ')}"
|
78
|
+
puts ''
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
private
|
84
|
+
|
85
|
+
def lookup(ip)
|
86
|
+
return Resolv.getname(ip) if ip !~ Resolv::IPv6::Regex
|
87
|
+
'err IPv6 address'
|
88
|
+
rescue Resolv::ResolvError
|
89
|
+
nil
|
90
|
+
end
|
91
|
+
|
92
|
+
def data
|
93
|
+
@data ||= Nokogiri::Slop(File.read(@input_file)).feedback
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
class Record
|
98
|
+
attr_accessor :data
|
99
|
+
|
100
|
+
def initialize(data)
|
101
|
+
@data = data
|
102
|
+
end
|
103
|
+
|
104
|
+
def spf?
|
105
|
+
@data.auth_results.respond_to?('spf')
|
106
|
+
end
|
107
|
+
|
108
|
+
def dkim?
|
109
|
+
@data.auth_results.respond_to?('dkim')
|
110
|
+
end
|
111
|
+
|
112
|
+
def source_ip
|
113
|
+
@data.row.source_ip.content
|
114
|
+
end
|
115
|
+
|
116
|
+
def header_from
|
117
|
+
@data.identifiers.header_from.content
|
118
|
+
end
|
119
|
+
|
120
|
+
def count
|
121
|
+
@data.row.count
|
122
|
+
end
|
123
|
+
|
124
|
+
def dkim_domains
|
125
|
+
domains_by_record_type(:dkim)
|
126
|
+
end
|
127
|
+
|
128
|
+
def spf_domains
|
129
|
+
domains_by_record_type(:spf)
|
130
|
+
end
|
131
|
+
|
132
|
+
def auth_failed_dkim_domains
|
133
|
+
auth_failure_domains_by_record_type(:dkim)
|
134
|
+
end
|
135
|
+
|
136
|
+
def auth_failed_spf_domains
|
137
|
+
auth_failure_domains_by_record_type(:spf)
|
138
|
+
end
|
139
|
+
|
140
|
+
def policy_eval
|
141
|
+
p = @data.row.policy_evaluated
|
142
|
+
{
|
143
|
+
disposition: p.disposition.content,
|
144
|
+
dkim: p.dkim.content,
|
145
|
+
spf: p.spf.content
|
146
|
+
}
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def domains_by_record_type(type)
|
152
|
+
# rubocop:disable Metrics/LineLength
|
153
|
+
return [] unless @data.auth_results.respond_to?(type)
|
154
|
+
return [@data.auth_results.send(type).domain.content] if @data.auth_results.send(type).respond_to?('domain')
|
155
|
+
@data.auth_results.send(type).map { |r| r.domain.content }.uniq.sort
|
156
|
+
# rubocop:enable Metrics/LineLength
|
157
|
+
end
|
158
|
+
|
159
|
+
def auth_failure_domains_by_record_type(type)
|
160
|
+
# rubocop:disable Metrics/LineLength
|
161
|
+
return [] unless @data.auth_results.respond_to?(type)
|
162
|
+
if @data.auth_results.send(type).respond_to?('result') &&
|
163
|
+
@data.auth_results.send(type).result.content != 'pass'
|
164
|
+
return [@data.auth_results.send(type).domain.content]
|
165
|
+
end
|
166
|
+
@data.auth_results.send(type)
|
167
|
+
.select { |r| r.respond_to?(type) && r.send(type).result.content != 'pass' }
|
168
|
+
.map { |r| r.domain.content }.uniq.sort
|
169
|
+
# rubocop:enable Metrics/LineLength
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
metadata
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dmarcer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Eric Herot
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-13 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: nokogiri
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.9'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.9'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description: Parse an XML DMARC summary
|
56
|
+
email:
|
57
|
+
- eric.github@herot.com
|
58
|
+
executables:
|
59
|
+
- dmarcer
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- ".gitignore"
|
64
|
+
- ".rspec"
|
65
|
+
- ".travis.yml"
|
66
|
+
- Gemfile
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- dmarcer.gemspec
|
73
|
+
- exe/dmarcer
|
74
|
+
- lib/dmarcer.rb
|
75
|
+
- lib/dmarcer/version.rb
|
76
|
+
homepage: http://blog.evertrue.com
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata:
|
80
|
+
allowed_push_host: https://rubygems.org
|
81
|
+
post_install_message:
|
82
|
+
rdoc_options: []
|
83
|
+
require_paths:
|
84
|
+
- lib
|
85
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
requirements: []
|
96
|
+
rubyforge_project:
|
97
|
+
rubygems_version: 2.4.5
|
98
|
+
signing_key:
|
99
|
+
specification_version: 4
|
100
|
+
summary: Parse an XML DMARC summary
|
101
|
+
test_files: []
|