forked from panther-labs/panther-analysis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaws_password_unused.py
34 lines (26 loc) · 1.02 KB
/
aws_password_unused.py
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
import datetime
from panther_oss_helpers import resolve_timestamp_string
TIMEOUT_DAYS = datetime.timedelta(days=90)
DEFAULT_TIME = "0001-01-01T00:00:00Z"
def aged_out(timestamp):
datetime_ts = resolve_timestamp_string(timestamp)
if not datetime_ts:
return False
return (datetime.datetime.now() - datetime_ts) > TIMEOUT_DAYS
def policy(resource):
# If a user is less than 4 hours old, it may not have a credential report generated yet.
# It will be re-scanned periodically until a credential report is found, at which point this
# policy will be properly evaluated.
report = resource.get("CredentialReport")
if not report:
return True
if report.get("PasswordEnabled"):
if report.get("PasswordLastUsed") != DEFAULT_TIME and aged_out(
report.get("PasswordLastUsed")
):
return False
if report.get("PasswordLastUsed") == DEFAULT_TIME and aged_out(
report.get("PasswordLastChanged")
):
return False
return True