1

I'm currently working on setting up automatized pentest reporting. The scripts I set up perform TLS and other security checks to see if the application is secure in these aspects yes or no. Currently use the testssl.sh application (which can be found here: https://testssl.sh/) to perform these checks. I then output the findings to a csv file and created a script that greps the file in question and based on what is found, he will mention something is wrong or is correct. Seeing as I have performed a check and all values were correct, I apply invert greps to say that whenever the value cannot be found in the file, then he needs to perform a certain action.

At first I thought the script I was working on was working, however, when testing another site, the output generated is not correct. Things that are missing should be mentioned, however, when I invert grep only one term without placing OR statements in between the large amounts of things that need to be checked it seems to work.

I have tried all sorts of grep types to get a constant output, but no luck so far. So far, I have tried the following:

if grep -v -e "NULLciphersnoencryptionnotoffered" -e "AnonymousNULLCiphersnoauthenticationnotoffered" -e "ExportcipherswoADHNULLnotoffered" -e "LOW64BitDESencryptionwoexportnotoffered|" -e "Weak128BitciphersSEEDIDEARC24notoffered" -e "TripleDESCiphersMediumnotoffered" -e "HighencryptionAESCamellianoAEADoffered" -e "StrongencryptionAEADciphersoffered" ./resultaten/tls-cipher-suites-ng.csv; then
        echo 'This is wrong' >> ../CH-40-Scans.tex
else
    echo 'This is correct.' >> ../CH-40-Scans.tex
fi

What I see is that the above does not show This is wrong, but This is correct, while the following does trigger:

if ! grep -q -i "ipv6enabled" ./resultaten/tls-vulnerabilities-new-def.csv; then
    echo '\item This is wrong.' >> ../CH-40-Scans.tex
fi

I already replaced the -e with the | variant, but I am not having luck so far on finding a consistent working method (also tried things as egrep). Is there another way to get this working? I don't mind using things such as Java or PHP or whatever to get this working, so if those are needed to create something consistent that would be fine.

I would gladly hear anything I could try to get a trustworthy working fix.

FuzzyAmi
  • 7,543
  • 6
  • 45
  • 79
JeanB
  • 13
  • 3
  • You have a pipe symbol in `"LOW64BitDESencryptionwoexportnotoffered|"`; I suppose that is intentional? –  Jul 26 '19 at 11:57
  • Something I missed, just removed it, but still having issues. Also having issues within other scripts when using something similar as mentioned above. – JeanB Jul 26 '19 at 12:01
  • The first grep expression should also have -q. –  Jul 26 '19 at 12:08
  • Added the -q, but unfortunately this did not make a difference. – JeanB Jul 26 '19 at 12:17
  • Send output to /dev/null: `grep .... >/dev/null`. –  Jul 26 '19 at 12:21
  • Are there empty lines in the csv? Lines with just whitespace? –  Jul 26 '19 at 12:22
  • Please add a tag 'grep' to your question. –  Jul 26 '19 at 12:43
  • You showed us 2 scripts and told us they don't do what you want but you didn't tell us what you DO want so any answer you get will be based on us guessing at what it is you're trying to do and so YMMV with how robust the resulting scripts are. Please post some concise, testable sample input and expected output plus a clear statement of your needs. – Ed Morton Jul 27 '19 at 16:52
  • btw - avoid negatives when writing any condition. Instead of `if grep -v X; then foo; else bar` or `if ! grep X; then foo; else bar` use `if grep X; then bar; else foo`. The resulting logic will be much clearer and greatly reduces the odds of you introducing a really obscure double negative. – Ed Morton Jul 27 '19 at 16:54

2 Answers2

1

I don't know what it is you're trying to do but try these:

if awk '/NULLciphersnoencryptionnotoffered/ || \
       /AnonymousNULLCiphersnoauthenticationnotoffered/ || \
       /StrongencryptionAEADciphersoffered/ { f=1; exit }
       END { exit !f }' ./resultaten/tls-cipher-suites-ng.csv; then
    echo 'Present'
else
    echo 'Absent'
fi

if awk -v RS='^$' '/NULLciphersnoencryptionnotoffered/ && \
       /AnonymousNULLCiphersnoauthenticationnotoffered/ && \
       /StrongencryptionAEADciphersoffered/ { f=1 }
       END { exit !f }' ./resultaten/tls-cipher-suites-ng.csv; then
    echo 'Present'
else
    echo 'Absent'
fi

The first one will exit success if any of the "strings" are present, the second one will exit success if all of them are present. That second one requires GNU awk for multi-char RS.

Ed Morton
  • 188,023
  • 17
  • 78
  • 185
0

This works, and may serve as an example (note I have commented out the redirection to /dev/null)

$> cat script
#!/bin/bash

e1="$1"
e2="$2"

if grep -v -e "$e1" -e "$e2" infile #>/dev/null
then
    echo "found at least one line without the string(s)"
else
    echo "found NO lines without all the string(s)!"
fi

$> cat infile
nabucco
aida
il trovatore

$> script a b
found NO lines without all the string(s)!

$> script z b
aida
trovatore
found at least one line without the string(s)
  • Thanks for the code. Gave it a whirl, but I do notice that whenever one item is true, the true statement is given. However, we want it the other way around. Whenever everything has been found within the file it should go true. Whenever it finds one value that does not comply, a false has to be generated. – JeanB Jul 26 '19 at 14:01
  • That is exactly what my example does. –  Jul 26 '19 at 15:04
  • Btw. you ought to be specific in your comments: "whenever one item is true" is an unclear statement, esp. in the current context. Your comment seems to contradict itself. –  Jul 26 '19 at 15:06
  • Please add a tag 'grep' to your question. –  Jul 26 '19 at 15:06
  • My apologies, tried to make it as clear as possible, hopefully you understand what I meant now, If not, let me know. – JeanB Jul 26 '19 at 17:29
  • If you want to test if ***any*** of those terms are missing in entries, you should use something like: `if egrep -v -e "NULLciphersnoencryptionnotoffered|AnonymousNULLCiphersnoauthenticationnotoffered|ExportcipherswoADHNULLnotoffered|LOW64BitDESencryptionwoexportnotoffered|Weak128BitciphersSEEDIDEARC24notoffered|TripleDESCiphersMediumnotoffered|HighencryptionAESCamellianoAEADoffered|StrongencryptionAEADciphersoffered" `. –  Jul 26 '19 at 17:47