Skip to content

Commit

Permalink
Path changes and variable name changes made
Browse files Browse the repository at this point in the history
  • Loading branch information
dscarson committed Feb 7, 2014
1 parent c08c01c commit 92ab1a7
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 40 deletions.
11 changes: 6 additions & 5 deletions scripts/openvas/generate_pass_openvas.sh
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
#!/usr/bin/env bash
OWTF_RootDir=$1

. $(pwd)/../../../../../../../scripts/openvas/openvas_init.sh
. $OWTF_RootDir/scripts/openvas/openvas_init.sh "$OWTF_RootDir"

passwd=$(date +%s | base64 | head -c 10) #/dev/urandom did not work when called from owtf script,otherwise it works fine
OWTF_OPENVAS_PASSWD=$(date +%s | base64 | head -c 10) #/dev/urandom did not work when called from owtf script,otherwise it works fine
#Let me know if there is a wayaround

update_config_setting "OPENVAS_PASS" "$passwd"
update_config_setting "OPENVAS_PASS" "$OWTF_OPENVAS_PASSWD"

if [ -d "/var/lib/openvas/users/admin" ]; then
openvasad -c remove_user -n admin
fi

passwd=$passwd expect -c 'log_user 0
OWTF_OPENVAS_PASSWD=$OWTF_OPENVAS_PASSWD expect -c 'log_user 0
spawn openvasad -c add_user -n admin -r Admin
sleep 1
expect "Enter password:"
send "$env(passwd)\n"
send "$env(OWTF_OPENVAS_PASSWD)\n"
sleep 1 '

echo
33 changes: 20 additions & 13 deletions scripts/openvas/openvas_init.sh
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
#!/usr/bin/env bash

CUR_DIR=$(pwd) # Remember current dir
OWTF_DIR="$CUR_DIR/../../../../../../../"
CONFIG_FILE="$OWTF_DIR/profiles/general/default.cfg"


OWTF_RootDir=$1
OWTF_CONFIG_FILE="$OWTF_RootDir/profiles/general/default.cfg"
HTML_FORMAT_ID="6c248850-1f62-11e1-b082-406186ea4fc5"



get_config_setting(){
grep $1 $CONFIG_FILE | cut -f2 -d' '
grep $1 $OWTF_CONFIG_FILE | cut -f2 -d' '
}

get_progress_status(){
Expand All @@ -20,22 +21,28 @@ get_service_port(){
}

update_config_setting(){
echo "$1: "$2>> $CONFIG_FILE
echo "$1: "$2>> $OWTF_CONFIG_FILE

}

CONFIG_ID=$(get_config_setting "OPENVAS_CONFIG_ID")
PGSAD=$(get_config_setting "OPENVAS_GSAD_PORT")
OWTF_CONFIG_ID=$(get_config_setting "OPENVAS_CONFIG_ID")
OWTF_PGSAD=$(get_config_setting "OPENVAS_GSAD_PORT")
OWTF_GSAD_IP=$(get_config_setting "OPENVAS_GSAD_IP")

if [[ "$OWTF_CONFIG_ID" = "" ]]
then
OWTF_CONFIG_ID="daba56c8-73ec-11df-a475-002264764cea"
update_config_setting "OPENVAS_CONFIG_ID" "$OWTF_CONFIG_ID"
fi

if [[ "$CONFIG_ID" = "" ]]
if [[ "$OWTF_PGSAD" = "" ]]
then
CONFIG_ID="daba56c8-73ec-11df-a475-002264764cea"
update_config_setting "OPENVAS_CONFIG_ID" "$CONFIG_ID"
OWTF_PGSAD="9392"
update_config_setting "OPENVAS_GSAD_PORT" "$OWTF_PGSAD"
fi

if [[ "$PGSAD" = "" ]]
if [[ "$OWTF_GSAD_IP" = "" ]]
then
PGSAD="9392"
update_config_setting "OPENVAS_GSAD_PORT" "$PGSAD"
OWTF_GSAD_IP="127.0.0.1"
update_config_setting "OPENVAS_GSAD_IP" "127.0.0.1"
fi
11 changes: 6 additions & 5 deletions scripts/openvas/openvas_quick_check.sh
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#!/usr/bin/env bash
. $(pwd)/../../../../../../../scripts/openvas/openvas_init.sh
OWTF_RootDir=$1
. $OWTF_RootDir/scripts/openvas/openvas_init.sh $OWTF_RootDir

PORT=$(get_service_port "openvas")
OWTF_OPENVAS_PORT=$(get_service_port "openvas")

#Port-check doesn't always work as openvassd is sometimes the single process running (without openvasmd and openvasad)
#same thing happens for gsad, so it is better to check for each one

if [ "$PORT" = "" ]; then
if [ "$OWTF_OPENVAS_PORT" = "" ]; then
pkill -9 gsad
sleep 1
echo "Starting OpenVas Services (Loading plugins may take time,please be patient !)"
Expand All @@ -23,7 +24,7 @@ if [ "$PORT" = "" ]; then
sleep 1
openvasad
sleep 2
gsad --http-only --listen=127.0.0.1 -p $PGSAD
gsad --http-only --listen=$OWTF_GSAD_IP -p $OWTF_PGSAD
sleep 10
else
if [ "$(get_service_port "openvassd")" = "" ]; then
Expand All @@ -40,7 +41,7 @@ else
fi
if [ "$(get_service_port "gsad")" = "" ];then

gsad --http-only --listen=127.0.0.1 -p $PGSAD
gsad --http-only --listen=$OWTF_GSAD_IP -p $OWTF_PGSAD
sleep 5
fi

Expand Down
38 changes: 21 additions & 17 deletions scripts/openvas/run_openvas_for_url.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

. $(pwd)/../../../../../../../scripts/openvas/openvas_init.sh

URL=$1

OWTF_RootDir=$2

. $OWTF_RootDir/scripts/openvas/openvas_init.sh "$OWTF_RootDir"



CLEAN_URL=$(echo $URL |sed -e 's/^http:\/\///g' -e 's/^https:\/\///g')

DATE=$(date +%F_%R_%S | sed 's/:/_/g')
Expand All @@ -40,14 +44,14 @@ OUTFILE="OpenVAS_Main_Report_$DATE"

echo

$OWTF_DIR/scripts/openvas/openvas_quick_check.sh
$OWTF_RootDir/scripts/openvas/openvas_quick_check.sh $OWTF_RootDir

passwd=$(get_config_setting "OPENVAS_PASS")
OWTF_OPENVAS_PASSWD=$(get_config_setting "OPENVAS_PASS")

if [[ "$passwd" = "" ]]
if [[ "$OWTF_OPENVAS_PASSWD" = "" ]]
then
$OWTF_DIR/scripts/openvas/generate_pass_openvas.sh
passwd=$(get_config_setting "OPENVAS_PASS")
$OWTF_RootDir/scripts/openvas/generate_pass_openvas.sh $OWTF_RootDir
OWTF_OPENVAS_PASSWD=$(get_config_setting "OPENVAS_PASS")
fi


Expand All @@ -56,7 +60,7 @@ echo "Runnig OpenVAS Plugin.."
echo ""

#Creating target
TARGET_ID=$(omp -u admin -w $passwd -iX '<create_target><name>'OWTF_Target_$CLEAN_URL'</name><hosts>'$CLEAN_URL'</hosts></create_target>' | sed 's/ *//g'|cut -f2 -d'"')
TARGET_ID=$(omp -u admin -w $OWTF_OPENVAS_PASSWD -iX '<create_target><name>'OWTF_Target_$CLEAN_URL'</name><hosts>'$CLEAN_URL'</hosts></create_target>' | sed 's/ *//g'|cut -f2 -d'"')

if [[ $TARGET_ID = *Targetexistsalready* ]]; then
echo -e "Target already exists\nExiting from OpenVAS.."
Expand All @@ -83,8 +87,8 @@ echo "###--------------Target Created : OWTF_Target_$CLEAN_URL..."

#Task creation

TASK_ID=$(omp -u admin -w $passwd --xml="<create_task><name>OWTF_Task_$CLEAN_URL</name>
<config id=\"$CONFIG_ID\"/>
TASK_ID=$(omp -u admin -w $OWTF_OPENVAS_PASSWD --xml="<create_task><name>OWTF_Task_$CLEAN_URL</name>
<config id=\"$OWTF_CONFIG_ID\"/>
<target id=\"$TARGET_ID\"/>
</create_task>" | sed 's/ *//g'|cut -f2 -d'"')

Expand All @@ -93,7 +97,7 @@ echo "###--------------Task Created : OWTF_Task_$CLEAN_URL..."

#getting report id

REPORT_ID=$(omp -u admin -w $passwd --xml="<start_task task_id=\"$TASK_ID\"/>" | sed 's/ *//g'|cut -f3 -d'>' |cut -f1 -d'<')
REPORT_ID=$(omp -u admin -w $OWTF_OPENVAS_PASSWD --xml="<start_task task_id=\"$TASK_ID\"/>" | sed 's/ *//g'|cut -f3 -d'>' |cut -f1 -d'<')

echo "###-------------------------------------------------------------------###"
echo "###--------------Task Started-----------------------------------------###"
Expand All @@ -107,23 +111,23 @@ echo -e "\n"



STATUS=$(get_progress_status $passwd $TASK_ID)
STATUS=$(get_progress_status $OWTF_OPENVAS_PASSWD $TASK_ID)

echo "In Progress...Hang tight !!"
echo "(You can check your status of progress by going to http://127.0.0.1:$PGSAD and logging in
echo "(You can check your status of progress by going to http://$OWTF_GSAD_IP:$OWTF_PGSAD and logging in
with the username 'admin' and the password and then going to tasks tab in scan management)".
while [[ $STATUS != *Done* ]]
do
sleep 1
STATUS=$(get_progress_status $passwd $TASK_ID)
STATUS=$(get_progress_status $OWTF_OPENVAS_PASSWD $TASK_ID)
if [[ $STATUS = *Stopped* ]];then
break
fi
done

#deleting the task

omp -u admin -w $passwd --delete-task $TASK_ID
omp -u admin -w $OWTF_OPENVAS_PASSWD --delete-task $TASK_ID

echo -e "\n"
echo -n "###------------------Done !-------------------------------------------###"
Expand All @@ -133,11 +137,11 @@ echo "###--------------Status Check Complete--------------------------------###"
echo "###-------------------------------------------------------------------###"


echo "###--------------Creating report in $DIR"...
echo "###--------------Creating report in $(pwd)"...

#get report

omp -u admin -w $passwd --get-report $REPORT_ID --format $HTML_FORMAT_ID > $OUTFILE.html
omp -u admin -w $OWTF_OPENVAS_PASSWD --get-report $REPORT_ID --format $HTML_FORMAT_ID > $OUTFILE.html

echo "###-------------------------------------------------------------------###"
echo "###--------------Report Generated-------------------------------------###"
Expand Down

0 comments on commit 92ab1a7

Please sign in to comment.