From 108ce0a0abc27c15c19aba8ee387175a4f8126fa Mon Sep 17 00:00:00 2001 From: Justin Bastress Date: Fri, 18 Jan 2019 13:33:23 -0500 Subject: [PATCH] use jp on path (and get/build it if not available) --- integration_tests/ipp/test.sh | 16 ++++++++-------- integration_tests/mysql/test.sh | 2 +- integration_tests/ntp/test.sh | 8 ++++---- integration_tests/pop3/test.sh | 2 +- integration_tests/smtp/test.sh | 2 +- integration_tests/test.sh | 7 ++++++- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/integration_tests/ipp/test.sh b/integration_tests/ipp/test.sh index ca3e62d..5eca45a 100755 --- a/integration_tests/ipp/test.sh +++ b/integration_tests/ipp/test.sh @@ -17,9 +17,9 @@ function test_cups() { CONTAINER_NAME="zgrab_ipp_cups" $ZGRAB_ROOT/docker-runner/docker-run.sh ipp --timeout 3s --verbose > "$OUTPUT_ROOT/cups.json" # FIXME: No good reason to use a tmp file & saved file, b/c I'm not testing any failure states yet #CONTAINER_NAME="zgrab_ipp_cups" $ZGRAB_ROOT/docker-runner/docker-run.sh ipp --timeout 3 --verbose > out.tmp - major=$($ZGRAB_ROOT/jp -u data.ipp.result.version_major < "$OUTPUT_ROOT/cups.json") - minor=$($ZGRAB_ROOT/jp -u data.ipp.result.version_minor < "$OUTPUT_ROOT/cups.json") - cups=$($ZGRAB_ROOT/jp -u data.ipp.result.cups_version < "$OUTPUT_ROOT/cups.json") + major=$(jp -u data.ipp.result.version_major < "$OUTPUT_ROOT/cups.json") + minor=$(jp -u data.ipp.result.version_minor < "$OUTPUT_ROOT/cups.json") + cups=$(jp -u data.ipp.result.cups_version < "$OUTPUT_ROOT/cups.json") rm -f out.tmp if ! [ $major = "2" ]; then echo "ipp/test: Incorrect major version. Expected 2, got $major" @@ -41,12 +41,12 @@ function test_cups_tls() { CONTAINER_NAME="zgrab_ipp_cups-tls" $ZGRAB_ROOT/docker-runner/docker-run.sh ipp --timeout 3s --ipps --verbose > "$OUTPUT_ROOT/cups-tls.json" # FIXME: No good reason to use a tmp file & saved file, b/c I'm not testing any failure states yet #CONTAINER_NAME="zgrab_ipp_cups-tls" $ZGRAB_ROOT/docker-runner/docker-run.sh ipp --timeout 3 --ipps --verbose > out.tmp - major=$($ZGRAB_ROOT/jp -u data.ipp.result.version_major < "$OUTPUT_ROOT/cups-tls.json") - minor=$($ZGRAB_ROOT/jp -u data.ipp.result.version_minor < "$OUTPUT_ROOT/cups-tls.json") - response=$($ZGRAB_ROOT/jp -u data.ipp.result.response < "$OUTPUT_ROOT/cups-tls.json") - cups=$($ZGRAB_ROOT/jp -u data.ipp.result.cups_version < "$OUTPUT_ROOT/cups-tls.json") + major=$(jp -u data.ipp.result.version_major < "$OUTPUT_ROOT/cups-tls.json") + minor=$(jp -u data.ipp.result.version_minor < "$OUTPUT_ROOT/cups-tls.json") + response=$(jp -u data.ipp.result.response < "$OUTPUT_ROOT/cups-tls.json") + cups=$(jp -u data.ipp.result.cups_version < "$OUTPUT_ROOT/cups-tls.json") # TODO: Check for a particular field in the tls object, since it may be safer - tls=$($ZGRAB_ROOT/jp -u data.ipp.result.tls < "$OUTPUT_ROOT/cups-tls.json") + tls=$(jp -u data.ipp.result.tls < "$OUTPUT_ROOT/cups-tls.json") #rm -f out.tmp if ! [ $major = "2" ]; then echo "ipp/test: Incorrect major version. Expected 2, got $major" diff --git a/integration_tests/mysql/test.sh b/integration_tests/mysql/test.sh index 351d35e..fe62f46 100755 --- a/integration_tests/mysql/test.sh +++ b/integration_tests/mysql/test.sh @@ -20,7 +20,7 @@ function doTest() { OUTPUT_FILE="$ZGRAB_OUTPUT/mysql/$MYSQL_VERSION.json" echo "mysql/test: Testing MySQL Version $MYSQL_VERSION..." CONTAINER_NAME=$CONTAINER_NAME $ZGRAB_ROOT/docker-runner/docker-run.sh mysql --timeout 10s > $OUTPUT_FILE - SERVER_VERSION=$($ZGRAB_ROOT/jp -u data.mysql.result.server_version < $OUTPUT_FILE) + SERVER_VERSION=$(jp -u data.mysql.result.server_version < $OUTPUT_FILE) if [[ "$SERVER_VERSION" == "$MYSQL_VERSION."* ]]; then echo "mysql/test: Server version matches expected version: $SERVER_VERSION == $MYSQL_VERSION.*" else diff --git a/integration_tests/ntp/test.sh b/integration_tests/ntp/test.sh index 3a36560..bfc1343 100755 --- a/integration_tests/ntp/test.sh +++ b/integration_tests/ntp/test.sh @@ -19,8 +19,8 @@ function test_openntp() { # Don't drop this in the standard output root, since it will not have status = success CONTAINER_NAME="zgrab_ntp_openntp" $ZGRAB_ROOT/docker-runner/docker-run.sh ntp --timeout 3s --monlist > out.tmp - time=$($ZGRAB_ROOT/jp -u data.ntp.result.time < out.tmp) - version=$($ZGRAB_ROOT/jp -u data.ntp.result.version < out.tmp) + time=$(jp -u data.ntp.result.time < out.tmp) + version=$(jp -u data.ntp.result.version < out.tmp) rm -f out.tmp if [ $time = "null" ]; then echo "ntp/test: Failed to get partial result from monlist on openntp (time = null)" @@ -36,8 +36,8 @@ function test_bad_req() { code=$1 expected_error=$2 CONTAINER_NAME="zgrab_ntp_4.2.6" $ZGRAB_ROOT/docker-runner/docker-run.sh ntp --timeout 3s --monlist --request-code $code --skip-get-time > out.tmp - status=$($ZGRAB_ROOT/jp -u data.ntp.status < out.tmp) - error=$($ZGRAB_ROOT/jp -u data.ntp.error < out.tmp) + status=$(jp -u data.ntp.status < out.tmp) + error=$(jp -u data.ntp.error < out.tmp) rm -f out.tmp if ! [ $status = "application-error" ]; then echo "ntp/test: Got error '$error', expected '$expected_error' on $code" diff --git a/integration_tests/pop3/test.sh b/integration_tests/pop3/test.sh index 421184c..b28129d 100755 --- a/integration_tests/pop3/test.sh +++ b/integration_tests/pop3/test.sh @@ -25,7 +25,7 @@ status=0 for field in $FIELDS; do for file in $(find $OUTPUT_ROOT -iname "*$field*.json"); do echo "check $file for $field" - RESULT=$($ZGRAB_ROOT/jp data.pop3.result.$field < $file) + RESULT=$(jp data.pop3.result.$field < $file) if [ "$RESULT" = "null" ]; then echo "Did not find $field in $file [[" cat $file diff --git a/integration_tests/smtp/test.sh b/integration_tests/smtp/test.sh index 1547092..ad08cad 100755 --- a/integration_tests/smtp/test.sh +++ b/integration_tests/smtp/test.sh @@ -26,7 +26,7 @@ status=0 for field in $FIELDS; do for file in $(find $OUTPUT_ROOT -iname "*$field*.json"); do echo "check $file for $field" - RESULT=$($ZGRAB_ROOT/jp data.smtp.result.$field < $file) + RESULT=$(jp data.smtp.result.$field < $file) if [ "$RESULT" = "null" ]; then echo "Did not find $field in $file [[" cat $file diff --git a/integration_tests/test.sh b/integration_tests/test.sh index 7de616f..4c61ff5 100755 --- a/integration_tests/test.sh +++ b/integration_tests/test.sh @@ -33,6 +33,11 @@ cd "$ZGRAB_ROOT" ZGRAB_OUTPUT="zgrab-output" +if ! which jp; then + go get github.com/jmespath/jp && go build github.com/jmespath/jp + export PATH=$PATH:$GOPATH/bin +fi + pushd integration_tests for mod in $(ls); do if [ ".template" != "$mod" ] && [ -d "$mod" ] && ( [ -z $TEST_MODULES ] || [ $mod = *"$TEST_MODULES"* ]); then @@ -79,7 +84,7 @@ for protocol in $(ls $ZGRAB_OUTPUT); do fi status=1 else - scan_status=$(./jp -u data.${protocol}.status < $target) + scan_status=$(jp -u data.${protocol}.status < $target) if ! [ $scan_status = "success" ]; then echo "Scan returned success=$scan_status for $protocol/$outfile" err="scan failure(${scan_status})@$protocol/$outfile"