1

I have a script that I'm writing where I'm trying to get OpenVAS OMP to be fully automated. The script is supposed to be able to get ask what type of scans, ip, name, comment, output type. It gets through all the menus and then displays the following:

Failed to read response.
Starting Scan
Failed to start task.
Failed to read response.
get-report requires one argument.

I have it echo starting scan, but the rest of them I'm unsure of how they are coming up and why. When I run each command outside the script, they do work, so I'm guessing it's something with how it's reading the variables. Code follows, any help is greatly appreciated.

#!/bin/sh

mkdir openvastmp 
cd openvastmp

echo "--------------------------------"
echo "----DamOS OpenVAS Automation----"
echo "------Select Type of Scan-------"
echo ""
echo "[1] Full and Fast"
echo "[2] Full and Fast Ultimate"
echo "[3] Full and very Deep"
echo "[4] Full and very Deep Ultimate"
echo "[5] Exit"
echo ""
echo "--------------------------------"

read -p "Please select an option: " m

if [ $m -eq 5 ]; then
exit 0;

elif [ $m -eq 1 ]; then
type="daba56c8-73ec-11df-a475-002264764cea"

elif [ $m -eq 2 ]; then
type="698f691e-7489-11df-9d8c-002264764cea"

elif [ $m -eq 3 ]; then
type="708f25c4-7489-11df-8094-002264764cea"

elif [ $m -eq 4 ]; then 
type="74db13d6-7489-11df-91b9-002264764cea"

fi
clear

echo "" #remove this line after
echo "--------------------------------" 
echo "----DamOS OpenVAS Automation----" 
echo "-----------Target Info----------"
read -p "Enter the IP of the target machine: " a
read -p "Enter the name you want the target stored as: " b
read -p "Enter what you would like to name the scan: " d
read -p "Enter a comment for the scan (not required): " e

omp -u user -w password --xml='
<create_target>
<name>'$b'</name>
<hosts>'$a'</hosts>
</create_target>'

echo "--------------------------------"
echo "----DamOS OpenVAS Automation----" 
echo "-------Report Output Type-------" 
echo "[1] HTML"
echo "[2] PDF"
echo "[3] Text"
echo "[4] XML"
echo "[5] Quit"
read -p "Select your desired report output format: " c

if [ $c -eq 5 ]; then
exit 0;
elif [ $c -eq 1 ]; then
report="6c248850-1f62-11e1-b082-406186ea4fc5"
ext=html
elif [ $c -eq 2 ]; then
report="c402cc3e-b531-11e1-9163-406186ea4fc5"
ext=pdf
elif [ $c -eq 3 ]; then
report="a3810a62-1f62-11e1-9219-406186ea4fc5"
ext=txt
elif [ $c -eq 4 ]; then 
report="a994b278-1f62-11e1-96ac-406186ea4fc5"
ext=xml
fi
clear

omp -u user -w password -T | grep $b > target
targetid=$(head -c 36 target)

omp -u user -w password -iX '
<create_task>
<name>'$d'</name>
<comment>'$e'</comment>
<config id='$type'/>
<target id='$targetid'/>
</create_task>'

#omp -u user -w password -C -n $d -m $e -c $type -t $targetid

omp -u user -w password -G | grep $b > scan
scanid=$(head -c 36 scan)

echo "Starting Scan"
#omp -u user -w password --xml='<start_task task_id='$scanid'/>'
omp -u user -w password -S $scanid

omp -u user -w password -G | grep Done > isdone

while [ ! -s isdone ];
do
    rm isdone
    sleep 5
    omp -u user -w password -G | grep Done > isdone
done

omp -u user -w password -iX '<get_tasks task_id='$scanid' details="1"/>' | grep     'report id' > reportid

reportid=$(awk '{print substr($0,22,64)}' reportid)

omp -u user -w password --get-report $reportid --format $report > $d.$ext

omp -u user -w password -D $scanid

omp -u user -w password -X '<delete_target target_id="'$targetid'"/>'

cd .. && rm -rf openvastmp
Josh Jolly
  • 11,258
  • 2
  • 39
  • 55
DJP
  • 11
  • 1
  • 3
  • When you use the `-xml` flag, you put your shell variables inside single quotes, which won't be expanded by the shell into their actual values but will be treated as literal. What happens if you replace these with double quotes? – Josh Jolly Apr 02 '14 at 13:32
  • The single quotes after the xml tag or around the variables? – DJP Apr 02 '14 at 13:53
  • Both! I'm also curious which `omp` command gives the `Failed to read response.` error – Josh Jolly Apr 02 '14 at 14:00
  • I'll give it a shot, I've got meetings for a bit now but I'll let you know once I get back to real work. And I'll let you know what gives those errors. – DJP Apr 02 '14 at 14:02
  • So I actually knew what the Failed to read response errors are. They're actually when the system is piping data to files, since it doesn't see the response code. – DJP Apr 02 '14 at 18:05
  • When I replace it with double quotes, I'm getting the same responses out of the system – DJP Apr 02 '14 at 18:36

1 Answers1

1

When you use XML code, it does not understand $a, $b as variables, but as strings $a, $b. I had the same trouble in my code. If you pass the variables before the XML code you won't have problems.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
maneo
  • 11
  • 1