如何使用 Applescript 故意损坏文件
How to intentionally corrupt a file with Applescript
我想做的基本上是粉碎文件。我最近参加了公司的安全协议会议,其中一位发言人向我们展示了他如何恢复放入垃圾文件夹然后从硬盘驱动器清空的文件。作为 IT 团队的新人,他们问我是否可以找到 "shred" 文件的方法。基本上我想做的是:
-drag/send 一个文件到 folder/applet:
-让 AppleScript 在文本编辑中打开文件:
-使用 "randomly" 生成的 ASCII 字符串(见下文)到 encrypt/corrupt 文本:
-保存文件,然后用"remove"shell脚本删除:
- 如果可能的话,想办法立即重写驱动器中先前包含该文件的部分:
这就是我目前所拥有的。它只是从我以前做过的项目中拼凑出来的,有些是在网上找的。
--this is the "random" generator
set passphrase to ""
repeat with x from 1 to 100
set randomChar to ASCII character (random number from 50 to 100)
set passphrase to passphrase & randomChar
end repeat
--end generator
tell application "Finder"
set sel to selection
if sel is not {} then
set als to sel's item 1 as alias
set aPath to POSIX path of als
set oldPath to aPath & ".old"
set oldPath2 to quoted form of oldPath
set aPath2 to quoted form of aPath
--display dialog "Enter a password for encryption" default answer "password"
set password1 to passphrase
set scRi to "openssl des3 -in " & oldPath2 & " -out " & aPath2 & " -k " & quoted form of password1
set RenameToOld to "mv " & aPath2 & " " & oldPath2
set DeleteOld to "srm " & oldPath2
--display dialog scRi
tell application "Terminal"
activate
do shell script (RenameToOld)
do shell script (scRi)
do shell script (DeleteOld)
end tell
end if
end tell
end open
抱歉,如果间距不对。我一直收到错误消息,指出变量 "passphrase" 未定义,即使我多次尝试修复它。它似乎破坏了它所传递的任何文件,但我不知道为什么或如何。如果有人能弄清楚如何让它工作,我将不胜感激。
srm
命令以及 Finder 的安全删除选项在 10.12 中消失了。 Apple 明智地取消了它们,因为它们不能在 SSD 上运行,也不会破坏以前写入或备份的副本。作为新的 IT 人员,您确实需要在承担任何与安全相关的责任之前进行自我教育。另见:Security Theater.
我想做的基本上是粉碎文件。我最近参加了公司的安全协议会议,其中一位发言人向我们展示了他如何恢复放入垃圾文件夹然后从硬盘驱动器清空的文件。作为 IT 团队的新人,他们问我是否可以找到 "shred" 文件的方法。基本上我想做的是:
-drag/send 一个文件到 folder/applet:
-让 AppleScript 在文本编辑中打开文件:
-使用 "randomly" 生成的 ASCII 字符串(见下文)到 encrypt/corrupt 文本:
-保存文件,然后用"remove"shell脚本删除:
- 如果可能的话,想办法立即重写驱动器中先前包含该文件的部分:
这就是我目前所拥有的。它只是从我以前做过的项目中拼凑出来的,有些是在网上找的。
--this is the "random" generator
set passphrase to ""
repeat with x from 1 to 100
set randomChar to ASCII character (random number from 50 to 100)
set passphrase to passphrase & randomChar
end repeat
--end generator
tell application "Finder"
set sel to selection
if sel is not {} then
set als to sel's item 1 as alias
set aPath to POSIX path of als
set oldPath to aPath & ".old"
set oldPath2 to quoted form of oldPath
set aPath2 to quoted form of aPath
--display dialog "Enter a password for encryption" default answer "password"
set password1 to passphrase
set scRi to "openssl des3 -in " & oldPath2 & " -out " & aPath2 & " -k " & quoted form of password1
set RenameToOld to "mv " & aPath2 & " " & oldPath2
set DeleteOld to "srm " & oldPath2
--display dialog scRi
tell application "Terminal"
activate
do shell script (RenameToOld)
do shell script (scRi)
do shell script (DeleteOld)
end tell
end if
end tell
end open
抱歉,如果间距不对。我一直收到错误消息,指出变量 "passphrase" 未定义,即使我多次尝试修复它。它似乎破坏了它所传递的任何文件,但我不知道为什么或如何。如果有人能弄清楚如何让它工作,我将不胜感激。
srm
命令以及 Finder 的安全删除选项在 10.12 中消失了。 Apple 明智地取消了它们,因为它们不能在 SSD 上运行,也不会破坏以前写入或备份的副本。作为新的 IT 人员,您确实需要在承担任何与安全相关的责任之前进行自我教育。另见:Security Theater.