screenshot-service/Docker/run-analysis.sh

112 lines
2.4 KiB
Bash
Executable File

#!/bin/bash
export DISPLAY=:0
export SCALE_PREVIEW=true # make the previews really small so you only have a small idea of what the server sees
INPUT="$1"
ID=$2
unquote(){
echo $1 | sed 's/"//g'
}
echo $INPUT
URL=$(unquote $(echo $INPUT | jq .url))
DOMAINS=`node array-to-lines.js "$(echo $INPUT | jq .third_party_domains)"`
source ./utils.sh
source ./bloater.sh
PREVIEW="TRUE" # set to "TRUE" in order to enable automatic screenshots kept in preview.png
if [ "$PREVIEW" = "TRUE" ];
then
(while true; do
grab_screen_to_public $ID
sleep 0.7
done) &
refresher_pid=$!;
fi
ORIGIN_DOMAIN=$(sed -e 's/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/' <<< "$URL")
bloat_firefox "$DOMAINS"
grab bloat_firefox
click 1270 217 # the "trash" icon, so requests from plamienie don't appear in the screenshots
load_website "$URL" "$URL"
for i in 1 2 3 4 5 6 7
do
xdotool mousemove 28 812 # left side, middle
xdotool click 5 click 5 click 5 click 5 click 5 click 5 # scroll down
sleep 1
done;
keycombo Control_L Home
echo "{\"current_action\": \"Strona $ORIGIN_DOMAIN wczytana. Przygotowywanie do analizy...\"}"
grab load_website
open_network_inspector
grab open_network_inspector
declare -a pids;
pids=()
index=0
mkdir -p "/opt/static/$ID"
while IFS= read -r DOMAIN; do
if [ "$DOMAIN" = "" ]; then
continue
fi
echo "{\"current_action\": \"Skanowanie skryptów z domeny $DOMAIN...\"}"
network_inspector_search "domain:$DOMAIN " # can filter with more granularity: https://developer.mozilla.org/en-US/docs/Tools/Network_Monitor/request_list#filtering_by_properties
# grab ni_search
count=0
while network_inspector_has_more_entries
do
screenshot_and_annotate "$ID" $index "$DOMAIN" "$ORIGIN_DOMAIN" &
pids+=($!)
((index++))
while network_inspector_headers_need_scrolling
do
xdotool mousemove 2400 1000
echo "SCROLLING DOWN"
xdotool click 5 click 5 click 5 # scroll down
sleep 0.1
screenshot_and_annotate "$ID" $index "$DOMAIN" "$ORIGIN_DOMAIN" &
pids+=($!)
((index++))
done
network_inspector_next_entry
((count++))
if [ $count -gt 10 ]; then
break;
fi
done
done <<< "$DOMAINS"
if [ "$PREVIEW" = "TRUE" ];
then
kill $refresher_pid;
fi
echo "{\"current_action\": \"Kończenie...\"}"
for PID in "${pids[@]}"
do
wait $PID
done
kill -2 %%;
cleanup
echo "Done!"