Skip to content

Commit

Permalink
added flexibility in demo reset/populate data
Browse files Browse the repository at this point in the history
  • Loading branch information
mmguero committed Nov 30, 2022
1 parent 4e8e695 commit 5671755
Showing 1 changed file with 30 additions and 8 deletions.
38 changes: 30 additions & 8 deletions scripts/demo/reset_and_auto_populate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
# -x <maximum number of seconds to wait for idle state before continuing anyway>
# remaining parameters: PCAP file(s)

# Those PCAP files with FILENAMES (not path) prepended with '=' will not be time-adjusted. eg.,
# /home/ec2-user/artifacts/current/Cyberville.pcap - will be time-adjusted
# /home/ec2-user/artifacts/ctf/=ctfd.pcap - will NOT be time-adjusted
# The file itself shouldn't be named with a '=', it's just an indicator.
# That character will be removed before processing.

###############################################################################
# force bash
if [ -z "$BASH_VERSION" ]; then
Expand Down Expand Up @@ -194,17 +200,32 @@ if [[ -f "$MALCOLM_DOCKER_COMPOSE" ]] && \
pushd "$WORKDIR" >/dev/null 2>&1

PCAP_FILES_ADJUSTED=()
PCAP_FILES_NOT_ADJUSTED=()

if (( ${#PCAP_FILES[@]} > 0 )); then
for ((i = 0; i < ${#PCAP_FILES[@]}; i++)); do
PCAP_FILE_ABSOLUTE="$($REALPATH -e "${PCAP_FILES[$i]}")"
PCAP_FILE_ADJUSTED="$WORKDIR"/"$(basename "${PCAP_FILES[$i]}")"
PCAP_FILE_DIRNAME="$(dirname "${PCAP_FILES[$i]}")"
PCAP_FILE_BASENAME="$(basename "${PCAP_FILES[$i]}")"
if [[ "$PCAP_FILE_BASENAME" =~ ^= ]]; then
# don't time-adjust files prepended with =, remove the = from the filename and insert as-is
PCAP_FILE_BASENAME="${PCAP_FILE_BASENAME:1}"
PCAP_ADJUST="false"
else
PCAP_ADJUST="true"
fi
PCAP_FILE_ABSOLUTE="$($REALPATH -e "$PCAP_FILE_DIRNAME"/"$PCAP_FILE_BASENAME")"
PCAP_FILE_ADJUSTED="$WORKDIR"/"$PCAP_FILE_BASENAME"
cp $VERBOSE_FLAG "$PCAP_FILE_ABSOLUTE" "$PCAP_FILE_ADJUSTED"
[[ -f "$PCAP_FILE_ADJUSTED" ]] && \
PCAP_FILES_ADJUSTED+=("$PCAP_FILE_ADJUSTED")
if [[ -f "$PCAP_FILE_ADJUSTED" ]]; then
if [[ "$PCAP_ADJUST" == "true" ]]; then
PCAP_FILES_ADJUSTED+=("$PCAP_FILE_ADJUSTED")
else
PCAP_FILES_NOT_ADJUSTED+=("$PCAP_FILE_ADJUSTED")
fi
fi
done

[[ -n "$PCAP_ADJUST_SCRIPT" ]] && \
[[ -n "$PCAP_ADJUST_SCRIPT" ]] && (( ${#PCAP_FILES_ADJUSTED[@]} > 0 )) && \
"$PCAP_ADJUST_SCRIPT" $VERBOSE_FLAG \
--time "$PCAP_DATE" \
--relative "$PCAP_RELATIVE_ADJUST" \
Expand Down Expand Up @@ -244,9 +265,10 @@ if [[ -f "$MALCOLM_DOCKER_COMPOSE" ]] && \
done
sleep 30

if (( ${#PCAP_FILES_ADJUSTED[@]} > 0 )); then
# copy the adjusted PCAP file(s) to the Malcolm upload directory to be processed
cp $VERBOSE_FLAG "${PCAP_FILES_ADJUSTED[@]}" ./pcap/upload/
if (( ${#PCAP_FILES_ADJUSTED[@]} > 0 )) || (( ${#PCAP_FILES_NOT_ADJUSTED[@]} > 0 )); then
# copy the PCAP file(s) to the Malcolm upload directory to be processed
(( ${#PCAP_FILES_ADJUSTED[@]} > 0 )) && cp $VERBOSE_FLAG "${PCAP_FILES_ADJUSTED[@]}" ./pcap/upload/
(( ${#PCAP_FILES_NOT_ADJUSTED[@]} > 0 )) && cp $VERBOSE_FLAG "${PCAP_FILES_NOT_ADJUSTED[@]}" ./pcap/upload/

if (( $PCAP_PROCESS_IDLE_SECONDS > 0 )); then
# wait for processing to finish out (count becomes "idle", no longer increasing)
Expand Down

0 comments on commit 5671755

Please sign in to comment.