From 5ec2535bc164af8ba18393a03ba71a5456378573 Mon Sep 17 00:00:00 2001 From: Dallas Winger Date: Thu, 29 Aug 2024 09:01:54 -0400 Subject: [PATCH 1/2] set NTP for UPDATE_* scripts. Fail if curl fails --- usr/bin/UPDATE_FIRMWARE | 16 +++++++++++++++- usr/bin/UPDATE_PAYLOADS | 23 ++++++++++++++++++----- 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/usr/bin/UPDATE_FIRMWARE b/usr/bin/UPDATE_FIRMWARE index c1d57ee..d5f8cb2 100755 --- a/usr/bin/UPDATE_FIRMWARE +++ b/usr/bin/UPDATE_FIRMWARE @@ -126,17 +126,31 @@ check_for_upgrade() { echo "" echo "Please do not power off the device!" curl -sL https://downloads.hak5.org/api/devices/sharkjack/firmwares/$remote_version-stable -o "/tmp/upgrade-$remote_version.bin" - execute_upgrade + status=$? + if [ $status -eq 0 ]; then + execute_upgrade + else + echo "failed to fetch upgrade file" + exit 1 + fi else echo "Your device is up-to-date." exit 0 fi } +update_time() { + echo "Ensuring system time is correct" + + ntpd -q -p 1.openwrt.pool.ntp.org +} + main() { echo "Checking internet connection" check_for_internet + update_time + check_for_upgrade } diff --git a/usr/bin/UPDATE_PAYLOADS b/usr/bin/UPDATE_PAYLOADS index a8284a3..3546282 100755 --- a/usr/bin/UPDATE_PAYLOADS +++ b/usr/bin/UPDATE_PAYLOADS @@ -19,19 +19,32 @@ update_payloads() { echo "Downloading payloads repository..." curl -sL $MASTER_URL -o /tmp/payloads-sync.tar.gz + status=$? + if [ $status -eq 0 ]; then + mkdir /tmp/payloads-sync + tar -xzf /tmp/payloads-sync.tar.gz -C /tmp/payloads-sync - mkdir /tmp/payloads-sync - tar -xzf /tmp/payloads-sync.tar.gz -C /tmp/payloads-sync + cp -r /tmp/payloads-sync/sharkjack-payloads-master/payloads/library /root/payload/ - cp -r /tmp/payloads-sync/sharkjack-payloads-master/payloads/library /root/payload/ + cleanup_tmp - cleanup_tmp + echo "Successfully syncronized payloads repository." + else + echo "failed to fetch payloads" + exit 1 + fi +} - echo "Successfully syncronized payloads repository." +update_time() { + echo "Ensuring system time is correct" + + ntpd -q -p 1.openwrt.pool.ntp.org } + main() { check_for_internet + update_time update_payloads } From b0c2e96ea27f8ff4d23cac8ddae4429eee8b798a Mon Sep 17 00:00:00 2001 From: Dallas Winger Date: Thu, 29 Aug 2024 11:12:50 -0400 Subject: [PATCH 2/2] ensure DNS works, per dark_pyrro suggestion --- usr/bin/UPDATE_FIRMWARE | 5 +++++ usr/bin/UPDATE_PAYLOADS | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/usr/bin/UPDATE_FIRMWARE b/usr/bin/UPDATE_FIRMWARE index d5f8cb2..2f7de18 100755 --- a/usr/bin/UPDATE_FIRMWARE +++ b/usr/bin/UPDATE_FIRMWARE @@ -101,6 +101,11 @@ check_for_internet() { echo "You must have an internet connection to check for updates." exit 0 fi + + if ! ping -q -c 1 -W 1 google.com &>/dev/null 2>&1; then + echo "You must have an internet connection with working DNS to check for updates." + exit 0 + fi } check_for_upgrade() { diff --git a/usr/bin/UPDATE_PAYLOADS b/usr/bin/UPDATE_PAYLOADS index 3546282..fde5c89 100755 --- a/usr/bin/UPDATE_PAYLOADS +++ b/usr/bin/UPDATE_PAYLOADS @@ -7,6 +7,11 @@ check_for_internet() { echo "You must have an internet connection to sync the payload libraries." exit 0 fi + + if ! ping -q -c 1 -W 1 google.com &>/dev/null 2>&1; then + echo "You must have an internet connection with working DNS to check for updates." + exit 0 + fi } cleanup_tmp() {