5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
# File 'lib/phisher_phinder/sender_extractor.rb', line 5
def (mail)
auth_senders = {
hosts: [],
email_addresses: []
}
processed_authservs = []
authentication_results = mail.[:authentication_results]
if authentication_results.any?
= authentication_results.first
= authentication_results[1..-1]
auth_senders[:hosts] << {
entry_type: :ip,
host: [:spf].first[:ip],
spf: {present: true, trusted: true}
}
auth_senders[:email_addresses] << {
email_address: [:spf].first[:from],
spf: {present: true, trusted: true, result: [:spf].first[:result]},
}
processed_authservs << [:authserv_id]
.each do ||
next if processed_authservs.include? [:authserv_id]
auth_senders[:hosts] << {entry_type: :ip, host: [:spf].first[:ip], spf: {present: true, trusted: false}}
unless auth_senders[:email_addresses].find { |entry| entry[:email_address] == [:spf].first[:from] }
auth_senders[:email_addresses] << {
email_address: [:spf].first[:from],
spf: {present: true, trusted: false, result: [:spf].first[:result]},
}
end
end
end
tracing_senders = []
mail.[:received].each do ||
if tracing_senders.empty?
if [:sender] && [:sender][:ip] == trusted_auth_sender_ip(auth_senders)
tracing_senders << [:sender]
end
next
end
if [:sender] && [:recipient] == tracing_senders.last[:host]
tracing_senders << [:sender]
else
break
end
end
{
authentication_senders: auth_senders,
tracing_senders: tracing_senders
}
end
|