我正在编写一个脚本,该脚本将搜索linux目录(从根目录开始(并根据文件扩展名识别特定文件。我想将这些文件转储到一个新的文本文件(例如testFile.txt(中,然后根据通用密码列表运行每个文件(基于文件路径(,以确保严格使用密码。我创建了一堆带有所需扩展名的测试目录和伪文件,我的搜索脚本运行得很好。我能够成功地找到所有正确的文件并将它们放入testFile.txt中,然而,当涉及到测试受密码保护的文件时,我不确定从哪里开始。。。任何建议都将不胜感激。到目前为止,我已经在下面包含了我写的脚本:
#!/bin/bash
#This script, in theory, should search an entire linux instance for files with extensions
#.p12, .jks, .pfx, .pem, .ppk. Any found files will be saved to a text doc. For each file in said
#doc, we will attempt to open the file with a list of generic passwds. If there are any
#successes, we will save that file and the passwd to a different flag doc to be addressed.
#This should search a named directory for the file extensions and save to output file
find / -name *.p12 -o -name *.jks > keytoolFile.txt
#As a test, iterate over the output file and name them
keyFile=$(cat keytoolFile.txt)
for line in $keyFile; do
echo -e "$linen"
keytool -list -keystore $line
done
#This next bit should go through the next set of file extensions and test them
find / -name *.pfx -o -name *.pem -o -name *.ppk > sshFile.txt
textFile=$(cat sshFile.txt)
for line in $textFile; do
echo -e "$linen"
ssh-keygen -y -f $line
done
编辑
为了改进它,我在上面的代码中添加了一些内容,但是,在添加逻辑时仍然存在问题。我想让它运行命令(取决于文件扩展名(,该命令应该提示输入密码。要测试的密码将存储在一个单独的文本文件中,我希望脚本遍历每个密码,试图找到一个有效的密码。如果它成功地进行了身份验证,那么我希望它将文件路径和密码转储到最终的文本文档中。
现在它要求手动输入密码,如果尝试失败,它就会继续前进。如果有任何关于如何添加此逻辑的提示,我们将不胜感激。
#!/bin/bash
#This script, in theory, should search an entire linux instance for files with extensions
#.p12, .jks, .pfx, .pem, .ppk. Any found files will be saved to a text doc. For each file in said
#doc, we will attempt to open the file with a list of generic passwds. If there are any
#successes, we will save that file and the passwd to a different flag doc to be addressed.
#This should search a named directory for the file extensions and save to output file
find / -name *.p12 -o -name *.jks > keytoolFile.txt
#As a test, iterate over the output file and name them
keyFile=$(cat keytoolFile.txt)
passFile=$(cat pass.txt)
for i in $keyFile; do
for j in $passFile; do
echo -e "Attempting $j on $i"
keytool -list -keystore $line -storepass $j
done
done
#This next bit should go through the next set of file extensions and test them
find / -name *.pfx -o -name *.pem -o -name *.ppk > sshFile.txt
hostFile=$(cat sshFile.txt)
passFile=$(cat pass.txt)
for i in $hostFile; do
for j in $passFile; do
echo -e "Attempting $j on $i"
ssh-keygen -f -y $i -P $j
done
done
我现在的问题是,我在keytool操作过程中遇到了一个"非法选项"错误。。。它似乎对密码进行了很好的迭代,但不知何故,它不断地获取文件中的第一个密码,并试图以某种方式将其作为选项传递。。。
Attempting 1qaz)OKM2wsx(IJN on <path/to/file/file.p12
Illegal option: 1qaz!QAZ2wsx@WSX
不要那样做。当试图从文件中读取名称列表时,会出现太多问题(例如,如果任何名称包含嵌入的换行符,则很难将其与两个不同的名称区分开来(。相反,只需创建一个单独测试文件的脚本,并从find调用它。例如,如果你把你的脚本放在/path/to/validate
中,你可以做:
find "$HOME" ( -name '*.p12 '-o -name '*.jks' -o -name '*.pfx'
-o -name '*.pem' -o -name '*.ppk' ) -exec /path/to/validate {} ;