Added ChatOps scripts
This commit is contained in:
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_build - builds PDF quotes and reports from XML files
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.11
|
||||
DOCBUILDER=/usr/local/bin/docbuilder.py
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $GITWEB ] && GITWEB=https://${GITSERVER}
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
BRANCH=master
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && TARGET=$1
|
||||
[[ ! -z $2 ]] && REPO=$2
|
||||
|
||||
# Reading positional parms is a bit ugly, shifting parms or getopt would be nicer
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
NAMESPACE=$3
|
||||
else
|
||||
PARMS=$3
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $4 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$4
|
||||
else
|
||||
PARMS="$PARMS $4"
|
||||
fi
|
||||
fi
|
||||
if [[ $# -ge 5 ]]; then
|
||||
shift 4
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offer or even offer,
|
||||
# this function retains backward compatibility - v0.1
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.2
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone -b $BRANCH --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables - v0.2
|
||||
preflight_checks() {
|
||||
if ([[ $TARGET != "quote" ]] && [[ $TARGET != "report" ]]) || [ -z $REPO ]; then
|
||||
echo "Usage: build quote|report REPOSITORY [NAMESPACE [BRANCH] [-v]"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $DOCBUILDER ]; then
|
||||
echo "[-] this script needs docbuilder.py ($DOCBUILDER)"
|
||||
fi
|
||||
}
|
||||
|
||||
build() {
|
||||
if [ ! -d source ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
pushd source &>/dev/null
|
||||
backwards_compatible
|
||||
targetpdf=target/$TARGET-latest.pdf
|
||||
$DOCBUILDER -c -i $TARGET.xml -o ../$targetpdf -x ../xslt/generate_$TARGET.xsl $PARMS
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "[-] Sorry, failed to parse $TARGET. Use \`builder $TARGET $REPO $NAMESPACE $BRANCH -v\` for more information."
|
||||
exit 1
|
||||
fi
|
||||
popd &>/dev/null
|
||||
if [ ! -f $targetpdf ]; then
|
||||
echo "[-] hmmm... failed to build PDF file (could not find $targetpdf)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add target/$TARGET-latest.pdf
|
||||
git add target/waiver_?*.pdf &>/dev/null
|
||||
git commit -q -m "$targetpdf proudly manufactured using ChatOps" &>/dev/null
|
||||
git push -q >/dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "builder v$VERSION - Rocking your world, one build at a time..."
|
||||
clone_repo
|
||||
build
|
||||
add_to_repo
|
||||
echo "[+] listo! Check out $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$targetpdf"
|
||||
exit 0
|
||||
@@ -0,0 +1,131 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_convert - converts gitlab issues into XML files
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.2
|
||||
CONVERTER=/usr/local/bin/gitlab-to-pentext.py
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITLABCLI ] && GITLABCLI=gitlab
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
BRANCH=master
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
# Reading parms is a bit ugly, shifting parms or actually using getopt would be nicer
|
||||
if [[ ! -z $2 ]]; then
|
||||
if [[ ! $2 == -* ]]; then
|
||||
NAMESPACE=$2
|
||||
else
|
||||
PARMS=$2
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$3
|
||||
else
|
||||
PARMS="$PARMS $3"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $# -ge 4 ]]; then
|
||||
shift 3
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.2
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone -b $BRANCH --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables - v0.2
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "[-] repository name needed"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $CONVERTER ]; then
|
||||
echo "[-] this script needs gitlab-to-pentext.py ($CONVERTER)"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
get_id() {
|
||||
project_id=$($GITLABCLI project search --query $REPO|awk '/id:/{print $2}')
|
||||
if [ -z $project_id ]; then
|
||||
echo "[-] could not find $REPO in gitlab"
|
||||
exit
|
||||
fi
|
||||
return $project_id
|
||||
}
|
||||
|
||||
convert() {
|
||||
$CONVERTER --issues $project_id -y
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add * &>/dev/null
|
||||
git commit -q -m "Converted gitlab (non) findings to XML using ChatOps" &>/dev/null
|
||||
git push -q >/dev/null
|
||||
}
|
||||
|
||||
validate() {
|
||||
if [ ! -d source ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
$VALIDATOR $PARMS
|
||||
if [[ -f project-vocabulary.pws ]]; then
|
||||
git add project-vocabulary.pws
|
||||
git commit -q -m 'Added spellcheck vocabulary using ChatOps' >/dev/null
|
||||
git push -q >/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "convert v$VERSION - Convert all the things!"
|
||||
get_id
|
||||
clone_repo
|
||||
convert
|
||||
add_to_repo
|
||||
echo "[+] Listo!"
|
||||
@@ -0,0 +1,126 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_invoice - builds PDF invoices from quotes
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.5
|
||||
DOCBUILDER=/usr/local/bin/docbuilder.py
|
||||
TEMPLOC=$(mktemp -d)
|
||||
DATESTAMP=$(date +"%Y-%m-%d")
|
||||
INVOICE="00/000"
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $GITWEB ] && GITWEB=https://${GITSERVER}
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
BRANCH=master
|
||||
TARGET=quote
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
[[ ! -z $2 ]] && INVOICE=$2
|
||||
|
||||
# Reading positional parms is a bit ugly, shifting parms or getopt would be nicer
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
NAMESPACE=$3
|
||||
else
|
||||
PARMS=$3
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $4 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$4
|
||||
else
|
||||
PARMS="$PARMS $4"
|
||||
fi
|
||||
fi
|
||||
if [[ $# -ge 5 ]]; then
|
||||
shift 4
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.2
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone -b $BRANCH --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables - v0.2
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "Usage: invoice REPOSITORY [INVOICE_NUMBER [NAMESPACE [BRANCH]]] [-v]"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $DOCBUILDER ]; then
|
||||
echo "[-] this script needs docbuilder.py ($DOCBUILDER)"
|
||||
fi
|
||||
}
|
||||
|
||||
build() {
|
||||
if [ ! -d source ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
pushd source &>/dev/null
|
||||
backwards_compatible
|
||||
targetpdf=target/invoice-latest.pdf
|
||||
$DOCBUILDER -c -i $TARGET.xml -o ../$targetpdf -x ../xslt/generate_invoice.xsl -invoice "$INVOICE" -date $DATESTAMP --fop ../target/invoice.fo $PARMS
|
||||
if [[ $? -ne 0 ]]; then
|
||||
echo "[-] Sorry, failed to generate $targetpdf"
|
||||
exit 1
|
||||
fi
|
||||
popd &>/dev/null
|
||||
if [ ! -f target/invoice-latest.pdf ]; then
|
||||
echo "[-] hmmm... failed to build PDF file (could not find $targetpdf)"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add target/invoice-latest.pdf
|
||||
git commit -q -m "Invoice $INVOICE automatically generated using ChatOps" &>/dev/null
|
||||
git push -q >/dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "invoice v$VERSION - Congrats, another project from conception to ka-CHING"
|
||||
clone_repo
|
||||
build
|
||||
add_to_repo
|
||||
echo "[+] listo! Check out $GITWEB/$NAMESPACE/$REPO/raw/$BRANCH/$targetpdf"
|
||||
@@ -0,0 +1,160 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_pentest - sets up a pentest repo with PenText based on a quote repo
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
# John Sinteur
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.7
|
||||
SAXON=/usr/local/bin/saxon/saxon9he.jar
|
||||
TEMPLATEREPO=ssh://git@gitlab.local/peter/templates
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITLABCLI ] && GITLABCLI=gitlab
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
[ -z $PENTEXTREPO ] && PENTEXTREPO=https://github.com/radicallyopensecurity/templates
|
||||
|
||||
TEMPLOC=$(mktemp -d)
|
||||
pentext=$(echo $PENTEXTREPO|awk -F '/' '{print $5}')
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
[[ ! -z $2 ]] && NAMESPACE=$2
|
||||
BRANCH=master
|
||||
TARGET=quote
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
# remove repo if not finished successfully
|
||||
if [ -z $finished ] && [ ! -z $project_id ]; then
|
||||
$GITLABCLI project delete --id $project_id
|
||||
echo "[-] deleted project $project_id"
|
||||
fi
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.3
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "[-] repository name needed (without leading pen- or off-)"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $SAXON ]; then
|
||||
echo "[-] this script needs saxon ($SAXON)"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_repo() {
|
||||
project_id=$($GITLABCLI project create --name $REPO --issues-enabled true --wiki-enabled true --snippets-enabled true --wall-enabled true --merge-requests-enabled true 2>/dev/null| awk '/id:/{print $2}')
|
||||
if [ ! -z $project_id ]; then
|
||||
echo "[+] successfully created gitlab project $REPO with id ${project_id}"
|
||||
$GITLABCLI project-label create --project-id ${project_id} --name documentation --color "#0000FF" &>/dev/null
|
||||
$GITLABCLI project-label create --project-id ${project_id} --name finding --color "#00c800" &>/dev/null
|
||||
$GITLABCLI project-label create --project-id ${project_id} --name lead --color "#e4d700" &>/dev/null
|
||||
$GITLABCLI project-label create --project-id ${project_id} --name non-finding --color "#c80000" &>/dev/null
|
||||
$GITLABCLI project-label create --project-id ${project_id} --name future-work --color "#f8b7b2" &>/dev/null
|
||||
$GITLABCLI project-issue create --project-id ${project_id} --description "Please drop all your positive/negative comments here, so that we can keep on improving our processes. It is important that we learn from <b>what</b>. No need for namecalling, <b>who</b> is unimportant <br /> <h2>Thumbs up</h2> <h2>Improvement</h2><h2>Not project related</h2><h2>Project related</h2>" --title "Retrospective: add your feedback HERE" &> /dev/null
|
||||
else
|
||||
echo "[-] could not create repo $NAMESPACE/$REPO"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Add standard templates using global (!) variables - v0.2
|
||||
add_templates() {
|
||||
[ -d $TEMPLOC/$pentext ] && rm -rf $TEMPLOC/$pentext &>/dev/null
|
||||
pushd $TEMPLOC 1>/dev/null && git clone --depth=1 $PENTEXTREPO &>/dev/null && popd 1>/dev/null
|
||||
|
||||
if [ ! -d $TEMPLOC/$pentext ]; then
|
||||
echo "[-] could not clone (and therefore add) pentext repo $TEMPLATEREPO"
|
||||
exit 1
|
||||
else
|
||||
clone_repo
|
||||
# copy the framework
|
||||
cp -r $TEMPLOC/$pentext/xml/* .
|
||||
# remove the docs
|
||||
rm -r doc &>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
grab_offer() {
|
||||
pushd source &>/dev/null
|
||||
backwards_compatible
|
||||
if [ ! -f $TARGET.xml ]; then
|
||||
echo "[-] could not find $TARGET.xml"
|
||||
exit
|
||||
fi
|
||||
cp client_info.xml $TEMPLOC/client_info.xml
|
||||
cp $TARGET.xml $TEMPLOC/quote.xml
|
||||
}
|
||||
|
||||
convert_report() {
|
||||
cp $TEMPLOC/quote.xml source/quote.xml
|
||||
cp $TEMPLOC/client_info.xml source/client_info.xml
|
||||
pushd source &>/dev/null
|
||||
java -jar $SAXON -s:quote.xml -xsl:../xslt/off2rep.xsl -o:report.xml
|
||||
if [ ! -f report.xml ]; then
|
||||
echo "[-] hmmm... failed to convert quote into report.xml"
|
||||
exit 1
|
||||
fi
|
||||
popd &>/dev/null
|
||||
mkdir -p findings/ &>/dev/null
|
||||
mkdir -p non-findings/ &>/dev/null
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add * &>/dev/null
|
||||
git commit -q -m "Initialized pentest repository with PenText using ChatOps" &> /dev/null
|
||||
git push -q > /dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "startpentest v${VERSION} - Ready for some ACTION?"
|
||||
ORIGREPO=$REPO
|
||||
REPO=off-$ORIGREPO
|
||||
clone_repo
|
||||
grab_offer
|
||||
REPO=pen-${ORIGREPO}
|
||||
setup_repo
|
||||
add_templates
|
||||
convert_report
|
||||
add_to_repo
|
||||
|
||||
echo "[+] listo!"
|
||||
finished=true
|
||||
@@ -0,0 +1,90 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_quickscope - converts a quickscope into a quotation
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
# John Sinteur
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.3
|
||||
SAXON=/usr/local/bin/saxon/saxon9he.jar
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
[[ ! -z $2 ]] && NAMESPACE=$2
|
||||
[[ ! -z $3 ]] && BRANCH=$3 || BRANCH=master
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.2
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "Usage: quickscope REPOSITORY [NAMESPACE]"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $SAXON ]; then
|
||||
echo "[-] this script needs saxon ($SAXON)"
|
||||
fi
|
||||
}
|
||||
|
||||
convert_quickscope() {
|
||||
if [ ! -f $TEMPLOC/$REPO/source/quickscope.xml ] || [ ! -f $TEMPLOC/$REPO/xslt/qs2offerte.xsl ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
java -jar $SAXON -s:$TEMPLOC/$REPO/source/quickscope.xml -xsl:$TEMPLOC/$REPO/xslt/qs2offerte.xsl -o:$TEMPLOC/$REPO/source/offerte.xml
|
||||
if [ ! -f $TEMPLOC/$REPO/source/offerte.xml ]; then
|
||||
echo "[-] failed to parse quote"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add source/offerte.xml &>/dev/null
|
||||
git commit -q -m "Created quickscope using ChatOps" &>/dev/null
|
||||
git push -q >/dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "quickscope v${VERSION} - Rockin' and scoping'..."
|
||||
clone_repo
|
||||
convert_quickscope
|
||||
add_to_repo
|
||||
echo "[+] listo!"
|
||||
exit 0
|
||||
@@ -0,0 +1,112 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_quote - sets up a quote gitlab repository using PenText
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
# John Sinteur
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.6
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITLABCLI ] && GITLABCLI=gitlab
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
[ -z $PENTEXTREPO ] && PENTEXTREPO=https://github.com/radicallyopensecurity/templates
|
||||
PREFIX="off-"
|
||||
pentext=$(echo $PENTEXTREPO|awk -F '/' '{print $5}')
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$PREFIX$1
|
||||
REPO=${REPO,,} # follow git specs: lowercase
|
||||
[[ ! -z $2 ]] && NAMESPACE=$2
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
# remove repo if not finished successfully
|
||||
if [ -z $finished ] && [ ! -z $project_id ]; then
|
||||
$GITLABCLI project delete --id $project_id
|
||||
echo "[-] deleted project $project_id"
|
||||
fi
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.3
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "Usage: startquote PROJECT_NAME"
|
||||
exit
|
||||
fi
|
||||
if ! which $GITLABCLI &>/dev/null; then
|
||||
echo "[-] this script needs the gitlab command line interface (python-gitlab)"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_repo() {
|
||||
project_id=$($GITLABCLI project create --name $REPO --issues-enabled true --wiki-enabled true --snippets-enabled true --wall-enabled true --merge-requests-enabled true 2>/dev/null| awk '/id:/{print $2}')
|
||||
if [ ! -z $project_id ]; then
|
||||
echo "[+] successfully created gitlab project $REPO with id ${project_id}"
|
||||
else
|
||||
echo "[-] could not create repo $NAMESPACE/$REPO"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Add standard templates using global (!) variables - v0.2
|
||||
add_templates() {
|
||||
[ -d $TEMPLOC/$pentext ] && rm -rf $TEMPLOC/$pentext &>/dev/null
|
||||
pushd $TEMPLOC 1>/dev/null && git clone --depth=1 $PENTEXTREPO &>/dev/null && popd 1>/dev/null
|
||||
|
||||
if [ ! -d $TEMPLOC/$pentext ]; then
|
||||
echo "[-] could not clone (and therefore add) pentext repo $TEMPLATEREPO"
|
||||
exit 1
|
||||
else
|
||||
clone_repo
|
||||
# copy the framework
|
||||
cp -r $TEMPLOC/$pentext/xml/* .
|
||||
# remove the docs
|
||||
rm -r doc &>/dev/null
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
git add * &>/dev/null
|
||||
git commit -q -m "Initialized quote repository with PenText using ChatOps" &>/dev/null
|
||||
git push -q > /dev/null
|
||||
}
|
||||
|
||||
preflight_checks
|
||||
echo "startquote v${VERSION} - Humbly setting up your quote framework..."
|
||||
setup_repo
|
||||
add_templates
|
||||
add_to_repo
|
||||
echo "[+] listo!"
|
||||
finished=true
|
||||
@@ -0,0 +1,113 @@
|
||||
#!/bin/bash
|
||||
|
||||
# handler_validate - validates quotes and reports
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.3
|
||||
VALIDATOR=/usr/local/bin/validate_report.py
|
||||
TEMPLOC=$(mktemp -d)
|
||||
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
BRANCH=master
|
||||
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
# Reading parms is a bit ugly, shifting parms or actually using getopt would be nicer
|
||||
if [[ ! -z $2 ]]; then
|
||||
if [[ ! $2 == -* ]]; then
|
||||
NAMESPACE=$2
|
||||
else
|
||||
PARMS=$2
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$3
|
||||
else
|
||||
PARMS="$PARMS $3"
|
||||
fi
|
||||
fi
|
||||
if [[ $# -ge 4 ]]; then
|
||||
shift 3
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.3
|
||||
clone_repo() {
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/${REPO}.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/${REPO}"
|
||||
exit 1
|
||||
else
|
||||
cd $REPO
|
||||
fi
|
||||
}
|
||||
|
||||
# Preflight checks using global (!) variables - v0.2
|
||||
preflight_checks() {
|
||||
if [ -z $REPO ]; then
|
||||
echo "[-] repository name needed"
|
||||
exit
|
||||
fi
|
||||
if [ ! -f $VALIDATOR ]; then
|
||||
echo "[-] this script needs validate_report.py ($VALIDATOR)"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
|
||||
validate() {
|
||||
if [ ! -d source ]; then
|
||||
echo "[-] missing necessary pentext framework files"
|
||||
exit 1
|
||||
fi
|
||||
$VALIDATOR $PARMS
|
||||
}
|
||||
|
||||
# Add changed files to the repository
|
||||
add_to_repo() {
|
||||
git add * &>/dev/null
|
||||
git commit -q -m "validate fixed some files using ChatOps" &>/dev/null
|
||||
git push -q > /dev/null
|
||||
}
|
||||
|
||||
|
||||
preflight_checks
|
||||
echo "validate v$VERSION - Validating all of your needs..."
|
||||
clone_repo
|
||||
validate
|
||||
add_to_repo
|
||||
# Don't Listo! here, as the validate script tells the user that
|
||||
@@ -0,0 +1,167 @@
|
||||
#!/bin/bash
|
||||
|
||||
# test_pentext - tests the PenText toolchain
|
||||
#
|
||||
# This script is part of the PenText framework
|
||||
# https://pentext.org
|
||||
#
|
||||
# Copyright (C) 2016 Radically Open Security
|
||||
# https://www.radicallyopensecurity.com
|
||||
#
|
||||
# Author(s): Peter Mosmans
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, either version 3 of the License, or
|
||||
# (at your option) any later version.
|
||||
|
||||
|
||||
VERSION=0.5
|
||||
DOCBUILDER=/usr/local/bin/docbuilder.py
|
||||
VALIDATOR=/usr/local/bin/validate_report.py
|
||||
SAXON=/usr/local/bin/saxon/saxon9he.jar
|
||||
|
||||
# These variables should be set environment-specific
|
||||
[ -z $GITLABCLI ] && GITLABCLI=gitlab
|
||||
[ -z $GITSERVER ] && GITSERVER=gitlab.local
|
||||
[ -z $GITWEB ] && GITWEB=https://$GITSERVER
|
||||
[ -z $NAMESPACE ] && NAMESPACE=ros
|
||||
[ -z $PENTEXTREPO ] && PENTEXTREPO=https://github.com/radicallyopensecurity/templates
|
||||
|
||||
TEMPLOC=$(mktemp -d)
|
||||
BRANCH=master
|
||||
reponame=test-pentext-$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 10 | head -n 1)
|
||||
pentext=$(echo $PENTEXTREPO|awk -F '/' '{print $5}')
|
||||
# Read standard 'command line' variables
|
||||
[[ ! -z $1 ]] && REPO=$1
|
||||
# Reading parms is a bit ugly, shifting parms or actually using getopt would be nicer
|
||||
if [[ ! -z $2 ]]; then
|
||||
if [[ ! $2 == -* ]]; then
|
||||
NAMESPACE=$2
|
||||
else
|
||||
PARMS=$2
|
||||
fi
|
||||
fi
|
||||
if [[ ! -z $3 ]]; then
|
||||
if [[ ! $3 == -* ]]; then
|
||||
BRANCH=$3
|
||||
else
|
||||
PARMS="$PARMS $3"
|
||||
fi
|
||||
fi
|
||||
if [[ $# -ge 4 ]]; then
|
||||
shift 3
|
||||
PARMS="$PARMS $@"
|
||||
fi
|
||||
|
||||
trap cleanup EXIT QUIT
|
||||
|
||||
# Make sure that the temporary files are always removed
|
||||
cleanup() {
|
||||
trap '' EXIT INT QUIT
|
||||
[ -d $TEMPLOC ] && rm -rf $TEMPLOC &>/dev/null
|
||||
|
||||
exit
|
||||
}
|
||||
|
||||
# As quote used to be called offerte or offer,
|
||||
# this function retains backward compatibility - v0.2
|
||||
backwards_compatible() {
|
||||
if [[ $TARGET == "quote" ]] && [ ! -f $TARGET.xml ]; then
|
||||
TARGET="offerte"
|
||||
fi
|
||||
}
|
||||
|
||||
setup_repo() {
|
||||
echo "[*] testing gitlab command line interface..."
|
||||
REPO=${reponame,,} # lowercase, but of course
|
||||
project_id=$($GITLABCLI project create --name $REPO --issues-enabled true --wiki-enabled true --snippets-enabled true --wall-enabled true --merge-requests-enabled true| awk '/id:/{print $2}')
|
||||
if [ ! -z $project_id ]; then
|
||||
echo "[+] successfully created test gitlab project with id ${project_id}"
|
||||
else
|
||||
echo "[-] could not create repo $reponame - is the .python-gitlab.cfg configuration corrent ?"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Clones repo using global (!) variables - v0.3
|
||||
clone_repo() {
|
||||
echo "[*] testing gitlab SSH access using ssh://git@${GITSERVER}/${NAMESPACE}..."
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 -q ssh://git@${GITSERVER}/${NAMESPACE}/$REPO.git &>/dev/null
|
||||
if [ ! -d $TEMPLOC/$REPO ]; then
|
||||
echo "[-] could not clone repo ${NAMESPACE}/$reponame - is the namespace correct ?"
|
||||
exit 1
|
||||
else
|
||||
echo "[+] successfully cloned repo using namespace ${NAMESPACE}"
|
||||
fi
|
||||
cd $TEMPLOC/$REPO
|
||||
}
|
||||
|
||||
# Preflight checks
|
||||
preflight_checks() {
|
||||
echo "The following variables will be used: "
|
||||
echo "DOCBUILDER=$DOCBUILDER (location of docbuilder.py)"
|
||||
echo "GITLABCLI=$GITLABCLI (command line gitlab interface)"
|
||||
echo "GITSERVER=$GITSERVER (git server)"
|
||||
echo "GITWEB=$GITWEB (webinterface of git server)"
|
||||
echo "NAMESPACE=$NAMESPACE (namespace of repositories)"
|
||||
echo "PENTEXTREPO=$PENTEXTREPO (location of pentext repo)"
|
||||
echo "SAXON=$SAXON (saxon binary)"
|
||||
echo "VALIDATOR=$VALIDATOR (location of validate_report.py)"
|
||||
echo "[*] testing binaries..."
|
||||
[ ! -f $VALIDATOR ] && echo "[-] validate_report.py ($VALIDATOR) is missing (necessary for validate)"
|
||||
[ ! -f $DOCBUILDER ] && echo "[-] docbuilder.py ($DOCBUILDER) is missing (necessary for build)"
|
||||
[ ! -f $SAXON ] && echo "[-] saxon ($SAXON) is missing (necessary for invoice)"
|
||||
which java &> /dev/null || echo "[-] java is missing (necessary for saxon)"
|
||||
if ! which $GITLABCLI &>/dev/null && [ ! -f $GITLABCLI ]; then
|
||||
echo "[-] gitlab ($GITLABCLI) is missing, required for startquote and startpentest"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
add_to_repo() {
|
||||
echo "[*] testing add to repo"
|
||||
echo "commit test" > testcommit
|
||||
git add testcommit
|
||||
git commit -q -m "test_pentext testcommit"
|
||||
git push -q
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "[-] failed adding stuff to repo"
|
||||
fi
|
||||
}
|
||||
|
||||
delete_repo() {
|
||||
if [ ! -z $project_id ]; then
|
||||
$GITLABCLI project delete --id $project_id &>/dev/null
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "[+] successfully deleted testproject $project_id"
|
||||
else
|
||||
echo "[-] hmmm... failed deleting testproject $project_id"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
clone_pentext() {
|
||||
echo "[*] testing access to PenText repo $PENTEXTREPO..."
|
||||
pushd $TEMPLOC 1>/dev/null
|
||||
git clone --depth=1 $PENTEXTREPO &>/dev/null
|
||||
popd 1>/dev/null
|
||||
|
||||
if [ ! -d $TEMPLOC/$pentext ]; then
|
||||
echo "[-] could not clone repo $TEMPLATEREPO..."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# preflight_checks
|
||||
echo "test_pentext v$VERSION - Testing the PenText toolchain"
|
||||
preflight_checks
|
||||
setup_repo
|
||||
clone_repo
|
||||
add_to_repo
|
||||
delete_repo
|
||||
clone_pentext
|
||||
echo "[+] all tests successful. Good to go!"
|
||||
Reference in New Issue
Block a user