Lab 0: Environment Verification
Prerequisites: Chapter 4 (The Lab) complete — all tools installed per the chapter instructions. Estimated time: 15 minutes. Chapter reference: Chapter 4 — The Lab.
This lab confirms that every component of your lab environment is installed, configured, and working together. No attacking, no patching, no payloads. Just verification. If something is misconfigured, this is where you find out — not halfway through a patching operation when a cryptic error sends you chasing the wrong problem for an hour.
Run every step in order. Do not skip ahead. Each step builds on the previous one, and the final health check script assumes everything before it passed.
Step 1: Verify Java
Section titled “Step 1: Verify Java”The patch-tool runs on the JVM. You need Java 11 or higher.
java --versionExpected output:
openjdk 17.0.10 2024-01-16OpenJDK Runtime Environment (build 17.0.10+7)OpenJDK 64-Bit Server VM (build 17.0.10+7, mixed mode)Your version numbers will differ. What matters: the major version (the first number) must be 11 or higher. Java 17 and 21 are both confirmed working.
If it fails:
command not found— Java is not installed or not on your PATH. Revisit Chapter 4.- Version below 11 — Install a newer JDK.
brew install openjdk@17on macOS,sudo apt install openjdk-17-jdkon Ubuntu.
Record the version number. You will need it for the health check at the end.
Step 2: Verify Android SDK Tools
Section titled “Step 2: Verify Android SDK Tools”You need adb (from platform-tools) and zipalign (from build-tools).
adb versionExpected output:
Android Debug Bridge version 1.0.41Now verify build-tools are accessible:
ls $ANDROID_HOME/build-tools/You should see at least one version directory (e.g., 34.0.0 or 36.0.0). If ANDROID_HOME is not set, that is your problem — add export ANDROID_HOME=~/Library/Android/sdk (macOS) or export ANDROID_HOME=~/Android/Sdk (Linux) to your shell profile and source it.
If adb fails:
- Ensure
$ANDROID_HOME/platform-toolsis on your PATH. - Run
source ~/.zshrc(or~/.bashrc) after editing.
Step 3: Verify the Emulator
Section titled “Step 3: Verify the Emulator”Boot your emulator if it is not already running:
emulator -avd RedTeamLab &Wait 15-30 seconds for it to fully boot, then check connectivity:
adb devicesExpected output:
List of devices attachedemulator-5554 deviceThe critical word is device. If you see offline or unauthorized, wait another 15 seconds and try again. If it persists:
adb kill-server && adb start-serveradb devicesIf the emulator will not boot:
- Run
emulator -accel-checkto verify hardware acceleration. - On Apple Silicon: ensure you are using an ARM system image, not x86_64.
- On Linux: ensure KVM is enabled (
sudo apt install qemu-kvm).
Step 4: Verify apktool
Section titled “Step 4: Verify apktool”apktool --versionExpected output:
2.9.3Any version 2.9.0 or higher works. Version 3.0.1 is also confirmed. Older versions may fail to decode modern APKs with newer resource table formats.
If it fails:
command not found— Install it:brew install apktool(macOS) orsudo apt install apktool(Linux).
Step 5: Verify the Patch-Tool
Section titled “Step 5: Verify the Patch-Tool”From the project root (where patch-tool.jar lives):
cd /path/to/android-red-teamjava -jar patch-tool.jar --helpExpected output:
The first line should show the tool name and version, followed by usage information listing all available options (--out, --work-dir, --app-class, etc.).
If it fails:
Unable to access jarfile— You are not in the project root, orpatch-tool.jarwas not built. The JAR lives at the project root, not insidematerials/.UnsupportedClassVersionError— Your Java is too old. Go back to Step 1.
Step 6: Verify Device Storage Access
Section titled “Step 6: Verify Device Storage Access”Push a test file to the emulator to confirm adb push works and storage is accessible:
echo "lab0-health-check" > /tmp/lab0-test.txtadb push /tmp/lab0-test.txt /sdcard/lab0-test.txtExpected output:
/tmp/lab0-test.txt: 1 file pushed, 0 skipped.Now verify it arrived:
adb shell cat /sdcard/lab0-test.txtExpected output:
lab0-health-checkClean up:
adb shell rm /sdcard/lab0-test.txtrm /tmp/lab0-test.txtIf the push fails:
error: no devices/emulators found— The emulator is not running or adb lost its connection. Go back to Step 3.Permission denied— Rare on emulators. Check that the emulator image is not a production (non-Google APIs) image.
Step 7: Verify the Target APK Exists
Section titled “Step 7: Verify the Target APK Exists”ls -lh materials/targets/target-kyc-basic.apkExpected output:
A file listing showing the APK at approximately 48 MB. If the file does not exist, you need to build it per the instructions in Chapter 4.
Step 8: Run the Full Health Check
Section titled “Step 8: Run the Full Health Check”Run this script from the project root. It consolidates every check into a single PASS/FAIL report.
#!/usr/bin/env bash# lab0-health-check.sh -- Lab environment verification# Run from the project root (where patch-tool.jar lives)
set -uo pipefail
PASS=0FAIL=0WARN=0
check() { local label="$1" local cmd="$2" local result result=$(eval "$cmd" 2>&1) if [ $? -eq 0 ] && [ -n "$result" ]; then echo " [PASS] $label: $result" ((PASS++)) else echo " [FAIL] $label" ((FAIL++)) fi}
echo ""echo "=========================================="echo " LAB 0: ENVIRONMENT HEALTH CHECK"echo " $(date +%Y-%m-%d\ %H:%M)"echo "=========================================="echo ""
echo "--- Host Tools ---"check "Java" "java --version 2>&1 | head -1"check "adb" "adb version 2>&1 | head -1"check "apktool" "apktool --version 2>&1 | head -1"check "patch-tool" "java -jar patch-tool.jar --help 2>&1 | head -1"
echo ""echo "--- Android SDK ---"check "ANDROID_HOME set" "echo \$ANDROID_HOME"check "build-tools present" "ls \$ANDROID_HOME/build-tools/ 2>&1 | head -1"
echo ""echo "--- Device Connectivity ---"DEVICE_COUNT=$(adb devices 2>/dev/null | grep -c 'device$')if [ "$DEVICE_COUNT" -gt 0 ]; then echo " [PASS] Emulator/device: $DEVICE_COUNT device(s) connected" ((PASS++))else echo " [FAIL] Emulator/device: no devices connected" ((FAIL++))fi
echo ""echo "--- Storage Access ---"echo "lab0-verify" > /tmp/lab0-verify.txtadb push /tmp/lab0-verify.txt /sdcard/lab0-verify.txt >/dev/null 2>&1STORAGE_CHECK=$(adb shell cat /sdcard/lab0-verify.txt 2>/dev/null)if [ "$STORAGE_CHECK" = "lab0-verify" ]; then echo " [PASS] Push/pull to /sdcard/" ((PASS++))else echo " [FAIL] Push/pull to /sdcard/" ((FAIL++))fiadb shell rm /sdcard/lab0-verify.txt 2>/dev/nullrm -f /tmp/lab0-verify.txt
echo ""echo "--- Target APK ---"if [ -f "materials/targets/target-kyc-basic.apk" ]; then SIZE=$(ls -lh materials/targets/target-kyc-basic.apk | awk '{print $5}') echo " [PASS] target-kyc-basic.apk present ($SIZE)" ((PASS++))else echo " [FAIL] target-kyc-basic.apk not found" ((FAIL++))fi
echo ""echo "=========================================="echo " Results: $PASS passed, $FAIL failed"echo "=========================================="
if [ "$FAIL" -eq 0 ]; then echo "" echo " ALL CHECKS PASSED. Your lab is ready." echo ""else echo "" echo " FIX THE FAILURES ABOVE BEFORE CONTINUING." echo " Refer to Chapter 4 troubleshooting section." echo ""fiSave this as lab0-health-check.sh, make it executable, and run it:
chmod +x lab0-health-check.sh./lab0-health-check.shIf the materials kit includes materials/scripts/lab-health-check.sh, you can run that instead — it performs the same checks with additional detail.
Expected Final Output
Section titled “Expected Final Output”A passing health check looks like this:
========================================== LAB 0: ENVIRONMENT HEALTH CHECK 2026-03-16 14:30==========================================
--- Host Tools --- [PASS] Java: openjdk 17.0.10 2024-01-16 [PASS] adb: Android Debug Bridge version 1.0.41 [PASS] apktool: 2.9.3 [PASS] patch-tool: patch-tool v1.0
--- Android SDK --- [PASS] ANDROID_HOME set: /Users/you/Library/Android/sdk [PASS] build-tools present: 36.0.0
--- Device Connectivity --- [PASS] Emulator/device: 1 device(s) connected
--- Storage Access --- [PASS] Push/pull to /sdcard/
--- Target APK --- [PASS] target-kyc-basic.apk present (48M)
========================================== Results: 9 passed, 0 failed==========================================
ALL CHECKS PASSED. Your lab is ready.Every line must show [PASS]. Any [FAIL] means something is broken. Fix it before moving to Lab 1.
Deliverable
Section titled “Deliverable”Take a screenshot of the health check output showing all checks passed. This screenshot is your evidence that the lab environment is operational.
Success Criteria
Section titled “Success Criteria”-
java --versionreturns 11 or higher -
adb devicesshows at least one device with statusdevice -
apktool --versionreturns 2.9.0 or higher -
java -jar patch-tool.jar --helpprints usage information -
adb pushandadb shell catround-trip a test file successfully -
target-kyc-basic.apkexists inmaterials/targets/ - Health check script reports 0 failures
What You Just Demonstrated
Section titled “What You Just Demonstrated”You confirmed that every tool in the chain is installed, reachable, and at a compatible version. You proved that the host machine can communicate with the emulator over adb, that storage operations work end-to-end, and that the patch-tool JAR is functional. This is the foundation. Every lab that follows assumes this baseline is solid. If you hit problems later, come back here first — re-run the health check to rule out environment issues before debugging anything else.