在x次失败的登录尝试后,是否可以自动格式化/删除我的SSD?


9

在iOS上,可以选择让设备在10次失败的登录尝试后删除所有数据。我如何在macOS上具有相同的选项,以便在x尝试登录我的用户帐户失败后,我的SSD可以删除/重新格式化?

Answers:


6

使用板载工具(并且不使用通过iCloud进行的“通过Mac查找我的Mac”和“远程擦除Mac”之类的外部服务),diskutil ...由于磁盘繁忙,因此无法擦除或重新格式化启动卷。


您可以通过以下方式删除用户文件夹:

下面的方法使用密码策略,并且根据用户登录功能的状态,启动守护程序和该守护程序调用的bash脚本将删除用户文件夹。

  1. 在您的桌面上创建密码策略plist:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>policyCategoryAuthentication</key>
        <array>
            <dict>
                <key>policyContent</key>
                <string>(policyAttributeFailedAuthentications &lt; policyAttributeMaximumFailedAuthentications) or (policyAttributeCurrentTime &gt; policyAttributeLastFailedAuthenticationTime + autoEnableInSeconds)</string>
                <key>policyIdentifier</key>
                <string>com.apple.maximumFailedLoginAttempts</string>
                <key>policyParameters</key>
                <dict>
                    <key>autoEnableInSeconds</key>
                    <integer>31536000</integer>
                    <key>policyAttributeMaximumFailedAuthentications</key>
                    <integer>10</integer>
                </dict>
            </dict>
        </array>
    </dict>
    </plist>
    

    10次​​失败的登录尝试31536000秒(=一年)后,将禁用用户登录功能。

  2. 创建一个bash脚本rmuserdir.sh

    #!/bin/bash
    
    PWPOL=$(pwpolicy -u username authentication-allowed)
    
    if [[ $PWPOL == 'User <username> is not allowed to authenticate: Failed global policy "com.apple.maximumFailedLoginAttempts"'  ]]
    
    then rm -fR /Users/username
    
    fi
    

    在/ usr / local / bin /中并使其可执行。将字符串username替换为用户名,但是将尖括号放在if语句中!

  3. 在/ Library / LaunchDaemons /中创建一个启动守护进程org.userdirrm.plist,其内容为:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
        <key>Label</key>
        <string>org.userdirrm</string>
        <key>ProgramArguments</key>
        <array>
            <string>/bin/bash</string>
            <string>/usr/local/bin/rmuserdir.sh</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>StandardErrorPath</key>
        <string>/tmp/org.userdirrm.stderr</string>
        <key>StandardOutPath</key>
        <string>/tmp/org.userdirrm.stdout</string>
        <key>StartInterval</key>
        <integer>60</integer>
    </dict>
    </plist>
    

    文件所有者和组必须是root用户:wheel和文件许可必须是644。守护程序将每60秒运行一次。您可以通过更改键StartInterval中的整数来进行调整。

  4. 导入密码策略:

    pwpolicy setaccountpolicies ~/Desktop/pwpolicy.plist
    

    您必须输入您的(authenticator = admin)密码。

  5. 启动守护程序:

    sudo launchctl load /Library/LaunchDaemons/org.userdirrm.plist
    

您可以通过以下方式测试设置:创建存根用户,临时更改bash脚本中的用户名,并输入错误的密码以尝试使用此存根用户登录。您可以暂时在密码策略中将失败的登录尝试次数减少至3,以缩短测试时间。

调整:

  • 在shell脚本中添加(rm)-P选项:

    删除常规文件之前将其覆盖。在删除文件之前,文件将被覆盖3次,首先是字节模式0xff,然后是0x00,然后又是0xff。

  • 尝试删除根文件夹而不是用户文件夹:

    rm -fR /
    

    要么

    rm -fRP /
    

    受SIP保护的文件不会被删除/覆盖!要同时删除/删除/覆盖它们,您必须禁用SIP。

  • 尝试从较旧的OS X安装中获取二进制srm,将其添加到High Sierra并在bash脚本而不是rm中使用。二进制srm安全删除文件或目录。检查man srm其他选项(我尚未测试过)。

在我看来,可以通过引导至单用户模式,使用launchctl启动opendirectory(在强制性文件系统检查并将引导卷安装到/之后)并使用删除所有密码策略来规避上述方法pwpolicy -clearaccountpolicies

因此,不建议格式化或擦除磁盘或文件夹以“获得安全性”。而是使用FileVault2加密您的主卷,并为所有用户使用正确的密码。


总共10次失败的登录尝试?可以连续十次吗?
安德烈·阿劳霍

@AndreAraujo只是对存根用户进行测试;-)
klanomath

我已经做了!效果很好!谢谢!
安德烈·阿劳霍

@AndreAraujo如果密码很短,并且输入密码并按回车键需要一秒钟,则可能需要等待50秒钟,直到删除用户文件夹。所述rmuserdir.sh每60秒只运行...和60秒- 10×1秒= 50秒。
klanomath '19

我与存根用户一起测试了许多情况,现在我为用户打开了电源。但是我更改了一些配置,在600秒(10分钟)内更改了工作,并在84600秒内更改了autoEnableInSeconds。因此,如果我的女儿或妻子错误地尝试了一些操作,则有一些时间可以采取行动!
安德烈·阿劳霍
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.