Skip to content

Commit a49bc08

Browse files
committed
feat: add build script, release key and prepare for automation
1 parent 7127db8 commit a49bc08

5 files changed

Lines changed: 84 additions & 0 deletions

File tree

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ The following applications are currently available:
77
| Application | Description |
88
|-----------------|---------------------------------------------------------------------|
99
| Hidden Activity | A simple application with an hidden activity that contains the flag |
10+
11+
Every sample app has the following:
12+
- a placeholder flag set to `DROIDGROUND_FLAG_PLACEHOLDER`
13+
- a `config.json` file in the root of the app directory that specifies:
14+
1. The file(s) that contain the placeholder flag
15+
2. The actual flag
16+
17+
Using this info the *GitHub action* can build **two versions** of each app (one with the placeholder flag and one with the actual flag).
18+
This simulates what should happen in a real CTF event, where the player are given the placeholder version while the real one is installed on the device accessible through *DroidGround*.
19+
20+
If you want to build them on your own you can use the `build.sh` script provided here in the root of the repo.

build.sh

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
read -p "Keystore path [./release-key.jks]: " USER_KEYSTORE_PATH
6+
KEYSTORE_PATH="${USER_KEYSTORE_PATH:-./release-key.jks}"
7+
KEYSTORE_ABS_PATH=$(realpath $KEYSTORE_PATH)
8+
9+
if [[ ! -f "$KEYSTORE_ABS_PATH" ]]; then
10+
echo "Keystore file not found at: $KEYSTORE_ABS_PATH"
11+
exit 1
12+
fi
13+
14+
echo "Enter keystore credentials:"
15+
read -p "Key alias: " KEY_ALIAS
16+
read -s -p "Keystore password: " KEYSTORE_PASSWORD; echo
17+
18+
rm -rf build
19+
mkdir -p build
20+
for appdir in */ ; do
21+
if [[ -f "$appdir/config.json" && -f "$appdir/gradlew" ]]; then
22+
echo "===================================="
23+
echo "Building app in: $appdir"
24+
25+
cd "$appdir"
26+
27+
# Read config
28+
FLAG=$(jq -r '.flag' config.json)
29+
FILES=$(jq -r '.files[]' config.json)
30+
31+
# Placeholder build
32+
echo "Building placeholder version..."
33+
./gradlew clean assembleRelease \
34+
-Pandroid.injected.signing.store.file=$KEYSTORE_ABS_PATH \
35+
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \
36+
-Pandroid.injected.signing.key.alias=$KEY_ALIAS \
37+
-Pandroid.injected.signing.key.password=$KEYSTORE_PASSWORD
38+
39+
cp app/build/outputs/apk/release/app-release.apk "../build/${appdir%/}-placeholder.apk"
40+
41+
echo -e "\n\n"
42+
# Flagged build
43+
echo "Replacing placeholder string with actual flag..."
44+
for file in $FILES; do
45+
echo "Modifying file: $file"
46+
sed -i "s/DROIDGROUND_FLAG_PLACEHOLDER/${FLAG//\//\\/}/g" "$file"
47+
done
48+
49+
echo ""
50+
echo "Building flagged version..."
51+
./gradlew clean assembleRelease \
52+
-Pandroid.injected.signing.store.file=$KEYSTORE_ABS_PATH \
53+
-Pandroid.injected.signing.store.password=$KEYSTORE_PASSWORD \
54+
-Pandroid.injected.signing.key.alias=$KEY_ALIAS \
55+
-Pandroid.injected.signing.key.password=$KEYSTORE_PASSWORD
56+
57+
cp app/build/outputs/apk/release/app-release.apk "../build/${appdir%/}-flag.apk"
58+
59+
echo "Restoring modified source files..."
60+
git restore .
61+
62+
cd ..
63+
echo "Finished building: $appdir"
64+
echo
65+
fi
66+
done
67+
68+
echo "All builds complete. APKs are in the \"build\" folder."

hidden-activity/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"flag": "FLAG{just_4_h1dd3n_4ct1v1ty}",
3+
"files": ["./app/src/main/java/com/droidground/hiddenactivity/HiddenActivity.kt"]
4+
}

release-key.jks

2.72 KB
Binary file not shown.

0 commit comments

Comments
 (0)