1
1
def is_spoofable (domain , p , aspf , spf_record , spf_all , spf_includes , sp , pct ):
2
2
"""This function takes in DMARC and SPF data for a domain, as well as subdomain policy and percentage options,
3
- and determines if the domain is vulnerable to email spoofing. The function returns an integer value indicating
4
- the class of vulnerability.
5
- ID Handler:
6
- 0: Indicates that spoofing is possible for the domain.
7
- 1: Indicates that subdomain spoofing is possible for the domain.
8
- 2: Indicates that organizational domain spoofing is possible for the domain.
9
- 3: Indicates that spoofing might be possible for the domain.
10
- 4: Indicates that spoofing might be possible (mailbox dependent) for the domain.
11
- 5: Indicates that organizational domain spoofing may be possible for the domain.
12
- 6: Indicates that subdomain spoofing might be possible (mailbox dependent) for the domain.
13
- 7: Indicates that subdomain spoofing is possible, and organizational domain spoofing might be possible.
14
- 8: Indicates that spoofing is not possible for the domain.
3
+ and determines if the domain is vulnerable to email spoofing. The function returns an integer value indicating
4
+ the class of vulnerability.
5
+ ID Handler:
6
+ 0: Indicates that spoofing is possible for the domain.
7
+ 1: Indicates that subdomain spoofing is possible for the domain.
8
+ 2: Indicates that organizational domain spoofing is possible for the domain.
9
+ 3: Indicates that spoofing might be possible for the domain.
10
+ 4: Indicates that spoofing might be possible (mailbox dependent) for the domain.
11
+ 5: Indicates that organizational domain spoofing may be possible for the domain.
12
+ 6: Indicates that subdomain spoofing might be possible (mailbox dependent) for the domain.
13
+ 7: Indicates that subdomain spoofing is possible, and organizational domain spoofing might be possible.
14
+ 8: Indicates that spoofing is not possible for the domain.
15
15
"""
16
16
try :
17
17
if pct and int (pct ) != 100 :
18
18
return 3
19
19
elif spf_record is None :
20
- return 0 if p is None else 8
20
+ if p is None :
21
+ return 0
22
+ else :
23
+ return 8
21
24
elif spf_includes > 10 and p is None :
22
25
return 0
23
26
elif spf_all == "2many" :
24
- return 3 if p == "none" else 8
27
+ if p == "none" :
28
+ return 3
29
+ else :
30
+ return 8
25
31
elif spf_all and p is None :
26
32
return 0
27
33
elif spf_all == "-all" :
28
- if p == "none" :
29
- if aspf == "r" and (sp == "reject" or sp == "quarantine" ):
30
- return 2
31
- elif aspf is None and (sp == "reject" or sp == "quarantine" ):
32
- return 5
33
- elif aspf is None and sp == "none" :
34
- return 7
35
- elif (aspf == "r" or aspf is None ) and sp is None :
36
- return 4
37
- else :
38
- return 8
39
- elif p and aspf and sp == "none" :
34
+ if p and aspf and sp == "none" :
40
35
return 1
41
36
elif aspf is None and sp == "none" :
42
37
return 1
38
+ elif p == "none" and (aspf == "r" or aspf is None ) and sp is None :
39
+ return 4
40
+ elif p == "none" and aspf == "r" and (sp == "reject" or sp == "quarentine" ):
41
+ return 2
42
+ elif p == "none" and aspf is None and (sp == "reject" or sp == "quarentine" ):
43
+ return 5
44
+ elif p == "none" and aspf is None and sp == "none" :
45
+ return 7
43
46
else :
44
47
return 8
45
48
elif spf_all == "~all" :
46
- if p == "none" :
47
- if sp == "reject" or sp == "quarantine" :
48
- return 2
49
- elif sp is None :
50
- return 0
51
- elif sp == "none" :
52
- return 7
53
- else :
54
- return 8
55
- elif (p == "reject" or p == "quarantine" ) and (aspf is None or aspf ) and sp == "none" :
49
+ if p == "none" and sp == "reject" or sp == "quarentine" :
50
+ return 2
51
+ elif p == "none" and sp is None :
52
+ return 0
53
+ elif p == "none" and sp == "none" :
54
+ return 7
55
+ elif (p == "reject" or p == "quarentine" ) and aspf is None and sp == "none" :
56
+ return 1
57
+ elif (p == "reject" or p == "quarentine" ) and aspf and sp == "none" :
56
58
return 1
57
59
else :
58
60
return 8
59
61
elif spf_all == "?all" :
60
- if p == "none" :
61
- if (aspf == "r" or aspf is None ) and sp is None :
62
- return 6
63
- elif aspf == "r" and sp == "none" :
64
- return 7
65
- elif (aspf == "s" or aspf is None ) and sp == "none" :
66
- return 7
67
- elif aspf and (sp == "reject" or sp == "quarantine" ):
68
- return 5
69
- elif aspf is None and sp == "reject" :
70
- return 5
71
- else :
72
- return 8
73
- elif (p == "reject" or p == "quarantine" ) and (aspf is None or aspf ) and sp == "none" :
62
+ if (p == "reject" or p == "quarentine" ) and aspf and sp == "none" :
63
+ return 6
64
+ elif (p == "reject" or p == "quarentine" ) and aspf is None and sp == "none" :
65
+ return 6
66
+ elif p == "none" and aspf == "r" and sp is None :
67
+ return 0
68
+ elif p == "none" and aspf == "r" and sp == "none" :
69
+ return 7
70
+ elif p == "none" and aspf == "s" or None and sp == "none" :
71
+ return 7
72
+ elif p == "none" and aspf == "s" or None and sp is None :
74
73
return 6
74
+ elif p == "none" and aspf and (sp == "reject" or sp == "quarentine" ):
75
+ return 5
76
+ elif p == "none" and aspf is None and sp == "reject" :
77
+ return 5
75
78
else :
76
79
return 8
77
80
else :
78
81
return 8
79
- except Exception as e :
80
- print ("An error occurred: " , e )
81
- print ("Open an issue with your testcase." )
82
+ except :
83
+ print ("If you hit this error message, Open an issue with your testcase." )
0 commit comments