Created
April 29, 2025 11:12
-
-
Save sysraccoon/02f876774e90291350407c0ac526940a to your computer and use it in GitHub Desktop.
frida server bootstrap script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| set -e | |
| check_dependencies() { | |
| local missing=() | |
| command -v adb >/dev/null || missing+=("adb"); | |
| command -v curl >/dev/null || missing+=("curl"); | |
| command -v unxz >/dev/null || missing+=("unxz"); | |
| if [ ${#missing[@]} -gt 0 ]; then | |
| echo "[!] Missing dependencies: ${missing[*]}"; | |
| exit 1; | |
| fi | |
| } | |
| usage() { | |
| local script_name=$(basename $0) | |
| echo "Usage: $script_name [OPTIONS]"; | |
| echo "Options:"; | |
| echo " --version FRIDA_VERSION Specify Frida version (e.g. 16.0.0)"; | |
| echo " --arch ARCH Specify architecture (arm, arm64, x86, x86_64)"; | |
| echo " --help Show this help message"; | |
| echo ""; | |
| echo "Examples:"; | |
| echo " $script_name"; | |
| echo " $script_name --version 15.2.2"; | |
| echo " $script_name --version 16.0.0 --arch arm64"; | |
| exit 1; | |
| } | |
| main() { | |
| check_dependencies; | |
| while [[ $# -gt 0 ]]; do | |
| case $1 in | |
| --version) | |
| FRIDA_VERSION="$2"; | |
| shift 2; | |
| ;; | |
| --arch) | |
| ARCH="$2" | |
| shift 2; | |
| ;; | |
| --help) | |
| usage; | |
| ;; | |
| *) | |
| echo "Unknown option $1" >&2; | |
| usage; | |
| exit 1; | |
| ;; | |
| esac | |
| done | |
| local CACHE_DIR="${XDG_CACHE_HOME:-$HOME/.cache}/frida-server"; | |
| mkdir -p "${CACHE_DIR}" || { | |
| echo "[!] Failed to create cache directory"; | |
| exit 1; | |
| } | |
| if [ -z "$FRIDA_VERSION" ]; then | |
| FRIDA_VERSION=$(frida --version 2>/dev/null || | |
| curl -sL "https://api.github.com/repos/frida/frida/releases/latest" | | |
| grep -oP '"tag_name": "\K[^"]+'); | |
| fi | |
| if [ -z "$ARCH" ]; then | |
| ARCH=$(adb shell getprop ro.product.cpu.abi); | |
| case "${ARCH}" in | |
| arm64-v8a) ARCH="arm64";; | |
| armeabi-v7a|armeabi) ARCH="arm";; | |
| x86_64) ARCH="x86_64";; | |
| x86) ARCH="x86";; | |
| *) | |
| echo "[!] Unsupported architecture: ${ARCH}"; | |
| exit 1; | |
| ;; | |
| esac | |
| else | |
| case "${ARCH}" in | |
| arm64|arm|x86_64|x86) ;; | |
| *) | |
| echo "[!] Unsupported architecture: ${ARCH}"; | |
| exit 1; | |
| ;; | |
| esac | |
| fi | |
| local SERVER_FILE="frida-server-${FRIDA_VERSION}-android-${ARCH}.xz"; | |
| local CACHED_SERVER="${CACHE_DIR}/${SERVER_FILE}"; | |
| local EXTRACTED_NAME="frida-server-${FRIDA_VERSION}-android-${ARCH}"; | |
| local EXTRACTED_PATH="${CACHE_DIR}/${EXTRACTED_NAME}"; | |
| if [ ! -f "${EXTRACTED_PATH}" ]; then | |
| echo "[*] Downloading Frida server ${FRIDA_VERSION} for ${ARCH}..."; | |
| local DOWNLOAD_URL="https://github.com/frida/frida/releases/download/${FRIDA_VERSION}/${SERVER_FILE}"; | |
| if ! curl -sL -o "${CACHED_SERVER}" "${DOWNLOAD_URL}"; then | |
| echo "[!] Download failed"; | |
| exit 1; | |
| fi | |
| echo "[*] Extracting with unxz..." | |
| if ! unxz -f "${CACHED_SERVER}"; then | |
| echo "[!] Extraction failed"; | |
| exit 1; | |
| fi | |
| fi | |
| echo "[*] Pushing to device..."; | |
| adb push "${EXTRACTED_PATH}" "/data/local/tmp/frida-server" || { | |
| echo "[!] Push failed"; | |
| exit 1; | |
| } | |
| echo "[*] Checking root access..."; | |
| if adb shell "su 0 sh -c 'echo root_check'" | grep -q "root_check"; then | |
| echo "[+] Root access confirmed"; | |
| echo "[*] Starting frida-server as root..."; | |
| ! adb shell "su 0 sh -c 'chmod 755 /data/local/tmp/frida-server'"; | |
| ! adb shell "su 0 sh -c 'pkill -9 frida-server 2>/dev/null'"; | |
| ! adb shell "su 0 sh -c '/data/local/tmp/frida-server -D &'"; | |
| if adb shell "su 0 sh -c 'pgrep frida-server' >/dev/null"; then | |
| echo "[+] Success! frida server ${FRIDA_VERSION} running as root"; | |
| else | |
| echo "[!] Failed to start frida server"; | |
| fi | |
| else | |
| echo "[!] No root access"; | |
| exit 1; | |
| fi | |
| } | |
| main "$@"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment