Jump to content

Using Loops and Openvas

blaze1993

Hi all

 

Hoping someone can help.

I am trying to automate an openvas scan.

I have created an IP text file and I am trying to input this into the openvas cli.

 

Each ip within the file is on a separate line and I need the command to be run on each IP on each line if that makes sense.

 

My code is below;

 

while read ip

do

echo "$ip"

done < ip-test.txt

TARGET_RETURN=$(omp -u admin -w admin -h 127.0.01 -p 9390 --xml="<create_target><name>tar$ip</name><hosts>$ip</hosts></create_target>")

echo $TARGET_RETURN

echo "$TARGET_RETURN" | grep -m1 'resource created' || exit 1 

 

function sindex {  

    x="${1%%$2*}"

    [[ $x = $1 ]] && echo -1 || echo ${#x}

}

T_ID_INDEX=$(sindex "$TARGET_RETURN" "id=")  

T_ID_INDEX=$((T_ID_INDEX + 4))  

T_ID=${TARGET_RETURN:T_ID_INDEX:36}  

C_ID=$(omp -h 127.0.0.1 -p 9390 -u admin -w admin -g | grep -i "Full and fast")  

C_ID=${C_ID:0:36} 

echo "creating task"

# Create task

T_ID=$(omp -u admin -w admin -h 127.0.0.1 -p 9390 -C -n "$ip" --target="$T_ID" --config="$C_ID")  

echo "running task"

# Start task

R_ID=$(omp -u admin -w admin -h 127.0.0.1 -p 9390 -S "$T_ID")  

echo "generating report"

F_ID=$(omp -u admin -w admin -h 127.0.0.1 -p 9390 -F | grep -i "HTML")  

F_ID=${F_ID:0:36}  

omp -u admin -w admin -h 127.0.0.1 -p 9390 -R "$R_ID" -f "$F_ID" > ./$ip-report.html  

 

Link to comment
Share on other sites

Link to post
Share on other sites

Issue now fixed. 

Moved the done part of the loop to the bottom.

 

Simple when I thought about it!

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×