Openvas OMP的Bash脚本

Openvas OMP的Bash脚本,bash,shell,variables,sh,openvas,Bash,Shell,Variables,Sh,Openvas,我正在编写一个脚本,试图让OpenVAS OMP完全自动化。脚本应该能够获取并询问扫描类型、ip、名称、注释和输出类型。它通过所有菜单,然后显示以下内容: Failed to read response. Starting Scan Failed to start task. Failed to read response. get-report requires one argument. 我有它的回声开始扫描,但其余的我不确定他们是如何来的,为什么。当我在脚本之外运行每个命令时,它们确实起

我正在编写一个脚本,试图让OpenVAS OMP完全自动化。脚本应该能够获取并询问扫描类型、ip、名称、注释和输出类型。它通过所有菜单,然后显示以下内容:

Failed to read response.
Starting Scan
Failed to start task.
Failed to read response.
get-report requires one argument.
我有它的回声开始扫描,但其余的我不确定他们是如何来的,为什么。当我在脚本之外运行每个命令时,它们确实起作用,所以我猜这与它读取变量的方式有关。代码如下,非常感谢您的帮助

#!/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
#/垃圾箱/垃圾箱
mkdir openvastmp
cd openvastmp
回声“-------------------------------------”
echo“---DamOS OpenVAS自动化--”
echo“-----选择扫描类型------”
回声“”
回显“[1]完整且快速”
echo“[2]全面快速终极版”
回声“[3]饱满而深沉”
echo“[4]完整且非常深沉的终极版”
回显“[5]退出”
回声“”
回声“-------------------------------------”
阅读-p“请选择一个选项:”m
如果[$m-等式5];然后
出口0;
elif[$m-等式1];然后
type=“daba56c8-73ec-11df-a475-002264764cea”
elif[$m-等式2];然后
type=“698f691e-7489-11df-9d8c-002264764cea”
elif[$m-等式3];然后
type=“708f25c4-7489-11df-8094-002264764cea”
elif[$m-等式4];然后
type=“74db13d6-7489-11df-91b9-002264764cea”
fi
清楚的
echo“”#在后面删除此行
回声“-------------------------------------”
echo“---DamOS OpenVAS自动化--”
回显“-------目标信息-----------”
读取-p“输入目标机器的IP:”a
read-p“输入您希望目标存储为的名称:”b
read-p“输入扫描的名称:”d
阅读-p“输入扫描注释(非必需):”e
omp-u user-w密码--xml='0
“$b”
“$a”
'
回声“-------------------------------------”
echo“---DamOS OpenVAS自动化--”
echo“-----报告输出类型--------”
echo“[1]HTML”
echo“[2]PDF”
回显“[3]文本”
echo“[4]XML”
回显“[5]退出”
阅读-p“选择所需的报告输出格式:”c
如果[$c-等式5];然后
出口0;
elif[$c-等式1];然后
报告=“6c248850-1f62-11e1-b082-406186ea4fc5”
ext=html
elif[$c-等式2];然后
报告=“c402cc3e-b531-11e1-9163-406186ea4fc5”
ext=pdf
elif[$c-等式3];然后
报告=“a3810a62-1f62-11e1-9219-406186ea4fc5”
ext=txt
elif[$c-等式4];然后
报告=“a994b278-1f62-11e1-96ac-406186ea4fc5”
ext=xml
fi
清楚的
omp-u user-w password-T | grep$b>target
targetid=$(总目-c 36目标)
omp-u用户-w密码-iX'
“$d”
“$e”
'
#omp-u用户-w密码-C-n$d-m$e-C$type-t$targetid
omp-u用户-w密码-G | grep$b>扫描
扫描ID=$(头部-c 36扫描)
回波“开始扫描”
#omp-u user-w密码--xml=''
omp-u用户-w密码-S$scanid
omp-u user-w password-G | grep Done>isdone
而[!-s isdone];
做
rm isdone
睡眠5
omp-u user-w password-G | grep Done>isdone
完成
omp-u用户-w密码-iX''| grep'报告id'>reportid
reportid=$(awk'{print substr($0,22,64)}'reportid)
omp-u用户-w密码--获取报告$reportid--格式$report>$d.$ext
omp-u用户-w密码-D$scanid
omp-u用户-w密码-X“”
光盘&&rm-rf openvastmp

使用XML代码时,它不会将
$a
$b
理解为变量,而是理解为字符串
$a
$b
。我的代码也有同样的问题。如果在XML代码之前传递变量,则不会出现问题。

当使用
-XML
标志时,将shell变量放在单引号内,单引号不会被shell扩展为实际值,但会被视为文本。如果用双引号替换它们会发生什么?xml标记后的单引号或变量周围的单引号?两者都有!我也很好奇哪个
omp
命令给出了
读取失败的响应。
错误我会试一试,我现在有一段时间要开会,但一旦我回到实际工作中,我会告诉你的。我会让你知道是什么导致了这些错误,所以我知道失败读取响应错误是什么。它们实际上是在系统将数据传输到文件时出现的,因为它看不到响应代码。