aboutsummaryrefslogtreecommitdiff
path: root/operating-systems/linux/passwords.sh
blob: 61d0f9340788d46980429ae54e865a42f0e5b268 (plain) (blame)
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
#!/bin/bash

# Function to extract and format password complexity parameters from /etc/pam.d/system-auth
extract_password_params() {
    echo "Checking /etc/pam.d/system-auth for password parameters..."
    
    if [ -f /etc/pam.d/system-auth ]; then
        # Extract the line containing the password complexity parameters
        param_line=$(grep -E 'difok=.* minlen=.* dcredit=.* ocredit=.* ucredit=.* lcredit=.* minclass=.* maxsequence=.*' /etc/pam.d/system-auth)
        
        if [ -n "$param_line" ]; then
            echo "Password complexity parameters found:"
            echo "$param_line"
            echo ""
            
            # Extract individual parameters using regex
            minlen=$(echo "$param_line" | grep -oP 'minlen=\K\d+')
            lcredit=$(echo "$param_line" | grep -oP 'lcredit=\K\d+')
            ucredit=$(echo "$param_line" | grep -oP 'ucredit=\K\d+')
            dcredit=$(echo "$param_line" | grep -oP 'dcredit=\K\d+')
            ocredit=$(echo "$param_line" | grep -oP 'ocredit=\K\d+')
            minclass=$(echo "$param_line" | grep -oP 'minclass=\K\d+')
            
            # Note: These parameters might not be present in the same line, so we set default values if not found
            remember=$(grep -oP 'remember=\K\d+' /etc/pam.d/system-auth || echo "N/A")
            retry=$(grep -oP 'retry=\K\d+' /etc/pam.d/system-auth || echo "N/A")
            unlock_time=$(grep -oP 'unlock_time=\K\d+' /etc/pam.d/system-auth || echo "N/A")
            
            # Format the extracted parameters into a table
            echo "Formatted Password Complexity Parameters:"
            echo "---------------------------------------------------"
            echo -e "Minlen     : $minlen characters"
            echo -e "Lcredit    : $lcredit lowercase"
            echo -e "Ucredit    : $ucredit uppercase"
            echo -e "Dcredit    : $dcredit numbers"
            echo -e "Ocredit    : $ocredit special"
            echo -e "Remember   : $remember password history"
            echo -e "Minclass   : $minclass character types"
            echo -e "Retry      : $retry incorrect passwords"
            echo -e "Unlock_time: $unlock_time seconds until unlocked"
        else
            echo "No password complexity parameters found in /etc/pam.d/system-auth."
        fi
    else
        echo "/etc/pam.d/system-auth file not found."
    fi
}

# Function to analyze /etc/login.defs
analyze_login_defs() {
    echo "Analyzing /etc/login.defs..."
    if [ -f /etc/login.defs ]; then
        echo "Contents of /etc/login.defs:"
        cat /etc/login.defs
        echo ""
        
        # Analysis
        echo "Login restrictions and parameters in /etc/login.defs:"
        grep -E 'PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_MIN_LEN|PASS_WARN_AGE|UID_MIN|UID_MAX|GID_MIN|GID_MAX|LOGIN_RETRIES|LOGIN_TIMEOUT|UID|GID' /etc/login.defs
        echo ""
    else
        echo "/etc/login.defs file not found."
    fi
}

# Main script execution
echo "Starting analysis of authentication and login parameters..."
extract_password_params
analyze_login_defs
echo "Analysis complete."