-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkain.sh
174 lines (164 loc) · 5.93 KB
/
kain.sh
1
2
3
4
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
#!/bin/bash
usage() {
cat <<EOF
Usage: ${0##*/} [service] [file]
Services:
outlook If your eml was exported from Outlook.
gmail If your eml was exported from Gmail.
proton If your eml was exported from ProtonMail.
zimbra If your eml was exported from zimbra. Zimbra's files may show some errors.
EOF
}
if [[ -z $1 || $1 = @(-h|--help) ]]; then
usage
exit $(( $# ? 0 : 1 ))
fi
echo -e "\e[1;32m ____ __. .__"
echo -e " | |/ _|____ |__| ____"
echo -e " | < \__ \ | |/ \ "
echo -e " | | \ / __ \| | | \ "
echo -e " |____|__ (____ /__|___| /"
echo -e " \/ \/ \/"
echo -e " v1.3 eml parser"
# -------------------- #
# Outlook
# -------------------- #
if [ "$1" == "outlook" ]
then
from=$(grep "From: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mFROM\e[32m]\e[0m\t\t\t$from"
replyto=$(grep "Reply-To: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mReply-To\e[32m]\e[0m\t\t$replyto"
to=$(grep "To: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mTO\e[32m]\e[0m\t\t\t$to"
source_ip=$(grep spf $2 | head -n 1 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}")
echo -e "\e[32m[\e[0mIP\e[32m]\e[0m\t\t\t$source_ip"
spf=$(grep spf $2 | cut -d " " -f 2 | cut -d "=" -f 2)
if [ "$spf" == "pass" ]
then
echo -e "\e[32m[\e[0mSPF\e[32m]\t\t\t$spf"
else
echo -e "\e[31m[\e[0mSPF\e[31m]\t\t\e[31m$spf\e[0m"
fi
dmarc=$(grep dmarc $2 | cut -d ";" -f 2 | cut -d " " -f 1 | cut -d "=" -f 2)
if [ "$dmarc" == "pass" ]
then
echo -e "\e[32m[\e[0mDMARC\e[32m]\t\t\t$dmarc"
else
echo -e "\e[31m[\e[0mDMARC\e[31m]\t\t\t\e[31m$dmarc\e[0m"
fi
dkim=$(grep dkim $2 | cut -d " " -f 3 | cut -d "=" -f 2)
if [ "$dkim" == "pass" ]
then
echo -e "\e[32m[\e[0mDKIM\e[32m]\t\t\t$dkim"
else
echo -e "\e[31m[\e[0mDKIM\e[31m]\t\t\t\e[31m$dkim\e[0m"
fi
fi
# -------------------- #
# Gmail
# -------------------- #
if [ "$1" == "gmail" ]
then
from=$(grep "From: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mFROM\e[32m]\e[0m\t\t\t$from"
replyto=$(grep "Received: from" $2 | cut -d " " -f 3)
echo -e "\e[32m[\e[0mRF\e[32m]\e[0m\t\t$replyto"
to=$(grep "To: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mTO\e[32m]\e[0m\t\t\t$to"
source_ip=$(grep SPF $2 | head -n 1 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | head -n 1)
echo -e "\e[32m[\e[0mIP\e[32m]\e[0m\t\t\t$source_ip"
spf=$(grep spf $2 | cut -d " " -f 8 | head -n 1 | cut -d "=" -f 2)
if [ "$spf" == "pass" ]
then
echo -e "\e[32m[\e[0mSPF\e[32m]\t\t\t$spf"
else
echo -e "\e[31m[\e[0mSPF\e[31m]\t\t\e[31m$spf\e[0m"
fi
dmarc=$(grep dmarc $2 | head -n 1 | cut -d " " -f 8 | cut -d "=" -f 2)
if [ "$dmarc" == "pass" ]
then
echo -e "\e[32m[\e[0mDMARC\e[32m]\t\t\t$dmarc"
else
echo -e "\e[31m[\e[0mDMARC\e[31m]\t\t\t\e[31m$dmarc\e[0m"
fi
dkim=$(grep dkim= $2 | head -n 1 | cut -d " " -f 8 | cut -d "=" -f 2)
if [ "$dkim" == "pass" ]
then
echo -e "\e[32m[\e[0mDKIM\e[32m]\t\t\t$dkim"
else
echo -e "\e[31m[\e[0mDKIM\e[31m]\t\t\t\e[31m$dkim\e[0m"
fi
fi
# -------------------- #
# Zimbra
# -------------------- #
if [ "$1" == "zimbra" ]
then
from=$(grep "From: " $2 | cut -d " " -f 2 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mFROM\e[32m]\e[0m\t\t\t$from"
replyto=$(grep "From: " $2 | cut -d " " -f 3 | cut -d "<" -f 2 | cut -d ">" -f 1)
echo -e "\e[32m[\e[0mRP\e[32m]\e[0m\t\t$replyto"
to=$(grep "To: " $2 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mTO\e[32m]\e[0m\t\t\t$to"
source_ip=$(grep "Received: from" $2 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | sort | tail -n 1)
echo -e "\e[32m[\e[0mIP\e[32m]\e[0m\t\t\t$source_ip"
spf=$(grep "SPF_PASS=" $2 | cut -d "," -f 3 | cut -d "=" -f 2)
if [ "$spf" == "pass" ]
then
echo -e "\e[32m[\e[0mSPF\e[32m]\t\t\t$spf"
else
echo -e "\e[31m[\e[0mSPF\e[31m]\t\t\e[31m$spf\e[0m"
fi
dmarc=$(grep "DMARC" $2 | cut -d "," -f 1 | cut -d "=" -f 2)
if [ "$dmarc" == "1" ]
then
echo -e "\e[32m[\e[0mDMARC\e[32m]\t\t\t$dmarc"
else
echo -e "\e[31m[\e[0mDMARC\e[31m]\t\t\t\e[31m$dmarc\e[0m"
fi
dkim=$(grep "dkim=" $2 | cut -d " " -f 1 | cut -d "=" -f 2)
if [ "$dkim" == "pass" ]
then
echo -e "\e[32m[\e[0mDKIM\e[32m]\t\t\t$dkim"
else
echo -e "\e[31m[\e[0mDKIM\e[31m]\t\t\t\e[31m$dkim\e[0m"
fi
fi
# ------------------- #
# Proton Mail
# ------------------- #
if [ "$1" == "proton" ]
then
from=$(grep "From: " $2 | cut -d " " -f 2 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mFROM\e[32m]\e[0m\t\t\t$from"
replyto=$(grep "From: " $2 | cut -d " " -f 2)
echo -e "\e[32m[\e[0mRP\e[32m]\e[0m\t\t$replyto"
to=$(grep "for <" $2 | cut -d ";" -f 1 | head -n 1 | grep -E -o "\b[a-zA-Z0-9.-]+@[a-zA-Z0-9.-]+.[a-zA-Z0-9.-]+\b")
echo -e "\e[32m[\e[0mTO\e[32m]\e[0m\t\t\t$to"
source_ip=$(grep "Received: from" $2 | grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" | sort | tail -n 1)
echo -e "\e[32m[\e[0mIP\e[32m]\e[0m\t\t\t$source_ip"
spf=$(grep "spf=pass" $2 | cut -d " " -f 3 | cut -d "=" -f 2)
if [ "$spf" == "pass" ]
then
echo -e "\e[32m[\e[0mSPF\e[32m]\t\t\t$spf"
else
echo -e "\e[31m[\e[0mSPF\e[31m]\t\t\e[31m$spf\e[0m"
fi
dmarc=$(grep "dmarc" $2 | cut -d " " -f 3 | cut -d "=" -f 2)
if [ "$dmarc" == "pass" ]
then
echo -e "\e[32m[\e[0mDMARC\e[32m]\t\t\t$dmarc"
else
echo -e "\e[31m[\e[0mDMARC\e[31m]\t\t\t\e[31m$dmarc\e[0m"
fi
dkim=$(grep "dkim" $2 | head -n 1 | cut -d " " -f 3 | cut -d "=" -f 2)
if [ "$dkim" == "pass" ]
then
echo -e "\e[32m[\e[0mDKIM\e[32m]\t\t\t$dkim"
else
echo -e "\e[31m[\e[0mDKIM\e[31m]\t\t\t\e[31m$dkim\e[0m"
fi
fi
# End
echo -e "\e[0m"