简体   繁体   English

Bash grep, awk o Z177544AA797AF6F322F8CAA5E80E7F 反向查找

[英]Bash grep, awk o sed to reverse find

I am creating a script to look for commonly used patterns in a password.Although I have security policies in the hosting panel, servers have been outdated due to incompatibilities.我正在创建一个脚本来查找密码中的常用模式。虽然我在托管面板中有安全策略,但由于不兼容,服务器已经过时。

Example, into the file words.txt, i put in there, the word test , when i execute grep -c test123 words.txt .例如,在文件 words.txt 中,我在其中输入单词test ,当我执行grep -c test123 words.txt When I look for that pattern I need it to find it but I think that with the command grep it won't work for me.当我寻找该模式时,我需要它来找到它,但我认为使用命令grep它对我不起作用。

Script:脚本:

EMAILPASS=`/root/info.sh -c usera | grep @`

for PAR in ${EMAILPASS} ; do

EMAIL=$(echo "${PAR}" | grep @ | cut -f1 -d:)
PASS=$(echo "${PAR}" | cut -d: -f 2)
PASS="${PASS,,}"
FINDSTRING=$(grep -ic "${PASS}" /root/words.txt)

echo -e ""
echo -e "Validating password ${EMAIL}"
echo -e ""


if [ $FINDSTRING -ge 1 ] ; then
echo "Insecre"
else
echo "Secure"
fi

the current output of the command is as follows当前output的命令如下

# grep -c test123 /root/words.txt
0

I think grep is not good for what I need, maybe someone can help me.我认为 grep 不适合我的需要,也许有人可以帮助我。

I could also use awk or sed but I can't find an option to help me.我也可以使用 awk 或 sed 但我找不到可以帮助我的选项。

Regardsm问候

Reverse your application.反转您的申请。

echo test123 | grep -f words.txt

Each line of the text file will be used as a pattern to test against the input.文本文件的每一行都将用作测试输入的模式。

edit编辑

Apparently you actually do want to see if the whole password is an actual word, rather than just checking to see if it's based on a dictionary word.显然,您实际上确实想查看整个密码是否是一个实际单词,而不仅仅是检查它是否基于字典单词。 That's considerably less secure, but easy enough to do.这是相当不安全的,但很容易做到。 The logic you have will not report test123 as insecure unless the whole passwword is an exact match for a word in the dictionary.除非整个密码与字典中的单词完全匹配,否则您拥有的逻辑不会将test123报告为不安全。

You said you were putting test in the dictionary and using test123 as the password, so I assumed you were looking for passwords based on dictionary words, which was the structure I suggested above.您说您将test放入字典并使用test123作为密码,所以我假设您正在根据字典单词查找密码,这是我上面建议的结构。 Will include as commented alternate lines below.将包括如下注释的备用行。

Also, since you're doing a case insensitive search, why bother to downcase the password?此外,既然您正在进行不区分大小写的搜索,为什么还要费心将密码小写?

declare -l pass                          # set as always lowecase

would do it, but there's no need.会这样做,但没有必要。

Likewise, unless you are using it again later, it isn't necessary to put everything into a variable first, such as the grep results.同样,除非您稍后再次使用它,否则没有必要先将所有内容放入变量中,例如grep结果。 Try to remove anything not needed -- less is more.尝试删除任何不需要的东西——少即是多。

Finally, since we aren't catching the grep output in a variable and testing that, I threw it away with -q .最后,由于我们没有在变量中捕获grep output 并对其进行测试,因此我使用-q将其丢弃。 All we need to see is whether it found anything, and the return code, checked by the if , tells us that.我们只需要看看它是否找到了任何东西,并且由if检查的返回码告诉我们这一点。

/root/info.sh -c usera | grep @ |        # only lines with at signs
  while IFS="$IFS:" read email pass      # parse on read with IFS
  do printf "\n%s\n\n" "Validating password for '$email'"
     if grep -qi "$pass" /root/words.txt # exact search (-q = quiet)
    #if grep -qif /root/words.txt <<< "$pass" # 'based on' search
     then echo "Insecure"
     else echo "Secure"                  # well....
     fi
  done

I think a better paradigm might be to just report the problematic ones and be silent for those that seem ok, but that's up to you.我认为更好的范例可能是只报告有问题的,而对那些看起来不错的保持沉默,但这取决于你。

Questions?问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM