#!/bin/bash # Install Strawberry on macOS from a build tree (builddir/). Run as root: # sudo ./scripts/install.sh (or: make macos-install) # # Endpoint Security (exec events, exec prevention, file watch) needs, at run # time: root (the launchd job runs as root), the # com.apple.developer.endpoint-security.client entitlement, and Full Disk # Access for /usr/local/bin/strawberry. An ad hoc signature (the default) # carries the entitlement only with SIP disabled; with SIP enabled the binary # is signed without it and the daemon polls libproc (detection only). # # Environment: # SIGN_IDENTITY codesign identity (default "-": ad hoc) # ENTITLEMENTS entitlements file (default: chosen from SIP state) set -euo pipefail cd "$(dirname "$0")/.." . ./scripts/install_common.sh if [ "$(uname -s)" != "Darwin" ]; then echo "macos_install.sh is for macOS; use scripts/install.sh on Linux" >&2 exit 1 fi if [ "$EUID" -ne 0 ]; then echo "Please run as root (sudo)" >&2 exit 1 fi if [ ! -x builddir/src/strawberry ]; then echo "Error: builddir/src/strawberry not found; build first (make build)" >&2 exit 1 fi SIGN_IDENTITY="${SIGN_IDENTITY:--}" PREFIX=/usr/local BIN="$PREFIX/bin/strawberry" CONF=/etc/strawberry/strawberry.conf STATE=/var/db/strawberry DAEMONS=/Library/LaunchDaemons JOBS="com.strawberry.daemon com.strawberry.update" echo "=== Strawberry Security Scanner installation (macOS) ===" echo # Access group: members read findings and use the app's controls. if ! dscl . -read /Groups/strawberry >/dev/null 2>&1; then echo "Creating 'strawberry' group..." dseditgroup -o create -r "Strawberry scanner" strawberry fi GID=$(dscl . -read /Groups/strawberry PrimaryGroupID | awk '{print $2}') # The rule updater downloads untrusted content; it runs as this user, which # owns only the feeds directory. if ! dscl . -read /Users/_strawberry >/dev/null 2>&1; then echo "Creating '_strawberry' user (rule updater)..." used=$(dscl . -list /Users UniqueID | awk '{print $2}') uid="" for id in $(seq 300 499); do if ! grep -qx "$id" <<< "$used"; then uid=$id break fi done if [ -z "$uid" ]; then echo "Error: no free UID in 300-499 for _strawberry" >&2 exit 1 fi dscl . -create /Users/_strawberry dscl . -create /Users/_strawberry UniqueID "$uid" dscl . -create /Users/_strawberry PrimaryGroupID "$GID" dscl . -create /Users/_strawberry UserShell /usr/bin/false dscl . -create /Users/_strawberry NFSHomeDirectory /var/empty dscl . -create /Users/_strawberry RealName "Strawberry rule updater" dscl . -create /Users/_strawberry Password '*' dscl . -create /Users/_strawberry IsHidden 1 dscacheutil -flushcache fi # Rules are root-only (anyone who can edit them can blind the scanner); # evidence is readable by the strawberry group only. echo "Creating directories..." install -d -m 0755 /etc/strawberry install -d -m 0700 /etc/strawberry/rules install -d -m 0750 -o root -g strawberry "$STATE" install -d -m 0750 -o _strawberry -g strawberry "$STATE/feeds" # Feeds fetched by an earlier install ran as root. chown -R _strawberry:strawberry "$STATE/feeds" install -d -m 0750 -o root -g strawberry /var/run/strawberry f="$STATE/database.db" if [ -f "$f" ]; then chgrp strawberry "$f" && chmod 0640 "$f" elif [ -d "$f" ]; then chgrp -R strawberry "$f" chmod 0750 "$f" [ -d "$f/evidence" ] && chmod 0750 "$f/evidence" fi for log in /var/log/strawberry.log:root /var/log/strawberry-update.log:_strawberry; do [ -f "${log%%:*}" ] || : > "${log%%:*}" chown "${log#*:}:strawberry" "${log%%:*}" chmod 0640 "${log%%:*}" done if [ -f "$CONF" ]; then echo " keeping existing $CONF" else echo "Installing configuration..." # macOS has no /run; evidence lives in /var/db/strawberry. # (enable_bpf_monitoring stays on: it enables process monitoring, which # uses Endpoint Security or libproc here.) sed -e "s#^db_path=\$#db_path=$STATE/database.db#" \ -e 's#^pid_file=/run/#pid_file=/var/run/#' \ -e 's#^control_socket_path=/run/#control_socket_path=/var/run/#' \ config/strawberry.conf > "$CONF.tmp" for key in "db_path=$STATE/" "pid_file=/var/run/" "control_socket_path=/var/run/"; do grep -q "^$key" "$CONF.tmp" || echo "Warning: config/strawberry.conf has no '$key' line; check $CONF" done install -m 0644 "$CONF.tmp" "$CONF" rm -f "$CONF.tmp" fi if [ -f config/example_rules.yar ]; then install -m 0600 config/example_rules.yar /etc/strawberry/rules/example_rules.yar fi echo "Installing binaries..." install -d -m 0755 "$PREFIX/bin" install -m 0755 builddir/src/strawberry "$BIN" # An ad hoc signature carrying the ES entitlement is killed at launch while # SIP is on, so sign without it there. sip=$(csrutil status 2>/dev/null || true) es_entitled=yes if [ -z "${ENTITLEMENTS:-}" ]; then ENTITLEMENTS=packaging/macos/strawberry.entitlements if [ "$SIGN_IDENTITY" = "-" ] && [[ "$sip" == *enabled* ]]; then ENTITLEMENTS=packaging/macos/strawberry-base.entitlements es_entitled=no fi fi codesign --force --options runtime --entitlements "$ENTITLEMENTS" --sign "$SIGN_IDENTITY" "$BIN" if ! "$BIN" help >/dev/null 2>&1; then if [ "$ENTITLEMENTS" != packaging/macos/strawberry-base.entitlements ]; then echo "Warning: $BIN does not launch with $ENTITLEMENTS (entitlement not granted for this" echo " signature); re-signing without Endpoint Security." codesign --force --options runtime --entitlements packaging/macos/strawberry-base.entitlements \ --sign "$SIGN_IDENTITY" "$BIN" es_entitled=no fi if ! "$BIN" help >/dev/null 2>&1; then echo "Error: $BIN does not launch after signing; check: $BIN help" >&2 exit 1 fi fi install_completions "$BIN" install_traces "$PREFIX" if [ -x builddir/mcp/strawberry-mcp ]; then install -m 0755 builddir/mcp/strawberry-mcp "$PREFIX/bin/strawberry-mcp" fi if [ -x builddir/app/strawberry-tray ]; then install -m 0755 builddir/app/strawberry-tray "$PREFIX/bin/strawberry-tray" fi # Hashes of the job files written into a persistence location (written # first): the daemon records these writes as evidence, not findings. manifest_args=() for job in $JOBS; do manifest_args+=("packaging/macos/$job.plist" "$DAEMONS/$job.plist") done write_installed_manifest "$STATE/installed-files.sha256" wheel "${manifest_args[@]}" echo "Installing launchd jobs..." for job in $JOBS; do install -m 0644 -o root -g wheel "packaging/macos/$job.plist" "$DAEMONS/$job.plist" launchctl bootout "system/$job" 2>/dev/null || true # bootout returns before the old job is gone; bootstrap fails until then. for attempt in 1 2 3 4 5; do if launchctl bootstrap system "$DAEMONS/$job.plist" 2>/dev/null; then break fi if [ "$attempt" -eq 5 ]; then echo "Error: launchctl bootstrap system $DAEMONS/$job.plist failed" >&2 exit 1 fi sleep 1 done done if [ -n "${SUDO_USER:-}" ] && [ "$SUDO_USER" != "root" ]; then if dseditgroup -o checkmember -m "$SUDO_USER" strawberry >/dev/null 2>&1; then echo "User '$SUDO_USER' is already in the strawberry group." elif [ -t 0 ]; then read -r -p "Add '$SUDO_USER' to the strawberry group (view findings, use controls)? [y/N] " answer if [ "$answer" = "y" ] || [ "$answer" = "Y" ]; then dseditgroup -o edit -a "$SUDO_USER" -t user strawberry echo "Added. Open a new login session for it to take effect." fi else echo "To use the CLI and app: sudo dseditgroup -o edit -a $SUDO_USER -t user strawberry" fi fi echo echo "Installation complete. The daemon and the rule updater are running under launchd." echo if [ "$es_entitled" = no ]; then echo "Endpoint Security: off (ad hoc signature with SIP enabled). The daemon polls" echo " libproc: detection only, no exec prevention or file watch. For ES, sign with an" echo " identity Apple granted the entitlement: SIGN_IDENTITY='Developer ID Application: ...'" else echo "Endpoint Security: grant Full Disk Access to $BIN" echo " (System Settings > Privacy & Security > Full Disk Access), then:" echo " sudo launchctl kickstart -k system/com.strawberry.daemon" fi echo echo "Status: strawberry status" echo "Configuration: $CONF" echo "State/Data: $STATE/" echo "YARA rules: /etc/strawberry/rules/" echo "Logs: /var/log/strawberry.log, /var/log/strawberry-update.log"