Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F21590282
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
8 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/android/conf/analyze.sh b/android/conf/analyze.sh
index 1fcf1af..5e8e1b5 100644
--- a/android/conf/analyze.sh
+++ b/android/conf/analyze.sh
@@ -1,129 +1,133 @@
#!/bin/bash
set -x
if (( $# != 1 )); then
echo "Usage: $0 <uuid>"
exit 1
fi
cd "/shared_buffer/app/$1/"
# shellcheck source=./signature_checking/utils.sh
source /conf/signature_checking/utils.sh
# shellcheck source=./restart_mitmproxy.sh
source /conf/restart_mitmproxy.sh
adid_requests_before=$(bash /conf/get_number_of_adid_requests.sh)
list_before=$(adb shell pm list packages | cut -d: -f2 | sort)
apks=( "/shared_buffer/app/$1/"*.apk )
is_downloaded_by_id=0
+is_downloaded_from_google_play=0
if [ -f "/shared_buffer/app/$1/app_name" ]; then
expected_package_id="$(cat "/shared_buffer/app/$1/app_name")"
if ! download_apk_apkpure "$expected_package_id"; then
echo "Failed to download an apk with a package id of $expected_package_id. Retrying from Google Play."
- download_apk_apkpure --google-play "$expected_package_id"
+ if ! download_apk_apkpure --google-play "$expected_package_id"; then
+ echo "Failed to download an apk with a package id of $expected_package_id via Google Play"
+ exit 1
+ fi
+ is_downloaded_from_google_play=1
fi
is_downloaded_by_id=1
apks=( "/shared_buffer/app/$1/output/$expected_package_id/"*.apk )
fi
if [ "${#apks[@]}" == 0 ]; then
echo "No apks found to scan"
exit 1
fi
ADID_PERM_REQUIRED=0
for apk in "${apks[@]}"; do
if ! perms=$( $(aapt_path) dump permissions "$apk" 2> /dev/null); then
echo "Warning: 'aapt dump permissions' failed for $apk"
exit 1
fi
grep -xqF "uses-permission: name='com.google.android.gms.permission.AD_ID'" <<< "$perms" && ADID_PERM_REQUIRED=1 || :
grep -xqF "uses-permission: name='android.permission.ACCESS_ADSERVICES_AD_ID'" <<< "$perms" && ADID_PERM_REQUIRED=1 || :
done
if [ $is_downloaded_by_id = 0 ]; then
for apk in "${apks[@]}"; do
if ! check_valid_apk "$apk"; then
echo "Something is wrong with an apk signature"
exit 2
fi
done
fi
if ! adb install-multiple -r "${apks[@]}"; then
echo "Failed to install the app (apkpure)"
- if [[ $is_downloaded_by_id == 1 ]]; then
- rm -rf "/shared_buffer/app/$1/output/$expected_package_id/"
+ if [[ $is_downloaded_by_id == 1 && $is_downloaded_from_google_play == 0 ]]; then
if ! download_apk_apkpure --google-play "$expected_package_id"; then
echo "Failed to download an app from google play"
fi
apks=( "/shared_buffer/app/$1/output/$expected_package_id/"*.apk )
if ! adb install-multiple -r "${apks[@]}"; then
echo "Failed to install the app from google-play"
fi
else
exit 1
fi
fi
list_after=$(adb shell pm list packages | cut -d: -f2 | sort)
readarray -t new_packages < <(comm -13 <(echo "$list_before") <(echo "$list_after"))
function cleanup() {
for pkg in "${new_packages[@]}"; do
adb uninstall "$pkg" || true
done
# shellcheck source=./restart_mitmproxy.sh
source /conf/restart_mitmproxy.sh
}
trap cleanup EXIT
if (( ${#new_packages[@]} != 1 )); then
echo "Got ${#new_packages[@]} new packages, expected 1"
exit 1
fi
new_app_id=${new_packages[0]}
#Exit status:
# 124 if COMMAND times out, and --preserve-status is not specified
# 125 if the timeout command itself fails
# 126 if COMMAND is found but cannot be invoked
# 127 if COMMAND cannot be found
# 137 if COMMAND (or timeout itself) is sent the KILL (9) signal (128+9)
# - the exit status of COMMAND otherwise
exit_status=0
timeout 20s bash /conf/start_frida_app.sh "$new_app_id" || exit_status=$?
if (( exit_status != 124 )); then
echo "The application has exited too early"
cleanup
exit 1
fi
adid_requests_after=$(bash /conf/get_number_of_adid_requests.sh)
cat > "/shared_buffer/app/$1/requests_before_after" << EOF
requests_before: ${adid_requests_before}
requests_after: ${adid_requests_after}
EOF
echo -n $((adid_requests_after - adid_requests_before)) > "/shared_buffer/app/$1/requested_adid"
bash /conf/screenshot.sh > "/shared_buffer/app/$1/screenshot"
curl -q http://mitmproxy:9111/get_har -o "/shared_buffer/app/$1/har"
bash /conf/get_adid.sh | tr -d '\n' > "/shared_buffer/app/$1/adid"
echo "$ADID_PERM_REQUIRED" > "/shared_buffer/app/$1/adid_perm_required"
diff --git a/android/conf/signature_checking/utils.sh b/android/conf/signature_checking/utils.sh
index 5094a9b..d5d2374 100644
--- a/android/conf/signature_checking/utils.sh
+++ b/android/conf/signature_checking/utils.sh
@@ -1,138 +1,155 @@
#!/bin/bash
set -o pipefail
shopt -s nullglob
set -e
PATH="$PATH":~/.cargo/bin
aapt_path() {
if aapt2 version &> /dev/null; then
echo -n "aapt2"
elif /usr/bin/aapt2 version &> /dev/null; then
echo -n "/usr/bin/aapt2"
else
echo "No sutable aapt version found" >&2
exit 1
fi
}
package_name() {
if [[ $# != 1 || ! -f $1 ]]; then
echo "Usage: $0 <file.apk>"
echo "Get's the apk id"
exit 1
fi
$(aapt_path) dump badging "$1" | grep 'package: '| sed "s/.* name='//; s/'.*//"
}
download_apk_apkpure() {
if [[ ! ( $# == 1 || ( $# == 2 && $1 == "--google-play" ) ) ]]; then
echo "Usage: $0 [--google-play] <package-name>" >&2
echo "This tries to download an apk with the same package name to output/<package-name>/<name>.[x]apk" >&2
exit 1
fi
if [[ $1 == "--google-play" ]]; then
use_google_play=1
package_name=$2
+ tag="google_play_tag"
else
use_google_play=0
package_name=$1
+ output_dir="output/$package_name/"
+ tag="apkpure_tag"
fi
-
output_dir="output/$package_name/"
- if [ -d "$output_dir" ]; then
+ tag="$output_dir/$tag"
+
+ if [ -f "$tag" ]; then
echo "Using a chached version of $package_name" >&2
return;
fi
+ rm -rf "$output_dir"
mkdir -p "$output_dir"
if [[ $use_google_play == 0 ]]; then
apkeep -a "$package_name" "$output_dir" 2> /dev/null || :
else
- # For now, hardcode the architecture to be
+ if [[ $package_name == *@* ]]; then
+ echo "Trying to download a versioned package using google-play: $package_name" >&2
+ exit 1
+ fi
+
if [[ $(uname -m) == "x86_64" ]]; then
arch="x86_64"
else
arch="arm64-v8a"
fi
apkeep -a "$package_name" -d google-play \
-o arch=$arch,split_apk=true \
-t $(cat /run/secrets/apkeep_gplay_token) \
-e $(cat /run/secrets/apkeep_gplay_email) \
--accept-tos \
"$output_dir" 2> /dev/null || :
# It puts it in a weird directory this time
mv "$output_dir"/*/* "$output_dir" || :
fi
downloaded_files=( "$output_dir"/* )
if [ "${#downloaded_files[@]}" = 0 ]; then
echo "Failed to download $package_name" >&2
rm -rf "$output_dir"
return 1
fi
(cd "$output_dir" && unzip ./*.xapk) || echo "No xapks detected" >&2
echo "Downloaded $package_name" >&2
+ touch "$tag"
echo "$output_dir"/*.apk
-
+ return 0
}
apk_cert() {
apksigner verify --print-certs --verbose -Werr "$1" | grep -Eo '^Signer .* certificate SHA-1 digest: .*$' | awk -F' ' '{print $NF}' | sort
}
apk_signatures_cmp() {
if [[ $# != 2 || ! -f "$1" || ! -f "$2" ]]; then
echo "Usage: $0 <file1>.apk <file2>.apk"
fi
mapfile -t certs1 < <(apk_cert "$1")
mapfile -t certs2 < <(apk_cert "$2")
echo "${certs1[@]}"
echo "${certs2[@]}"
for c1 in "${certs1[@]}"; do
for c2 in "${certs2[@]}"; do
if [[ "$c1" == "$c2" ]]; then
echo Found a match!
return 0
fi
done
done
echo No signatures matched
return 1
}
check_valid_apk() {
if [[ $# != 1 || ! -f "$1" ]]; then
echo "Usage: $0 <apk_to_test>.apk"
fi
input_apk=$1
apk_package_name="$(package_name "$1")"
- download_apk_apkpure "$apk_package_name"
+ if ! download_apk_apkpure "$apk_package_name"; then
+ echo "Failed to download a reference apk, re-trying from google-play"
+ if ! download_apk_apkpure --google-play "$apk_package_name"; then
+ echo "Failed to download a reference apk, exiting..."
+ return 1
+ fi
+ return 1
+ fi
possible_apks=( "output/$apk_package_name/"*.apk )
reference_apk=""
if [[ "${#possible_apks[@]}" != 0 ]]; then
echo "Processing a .apk"
reference_apk="${possible_apks[0]}"
else
echo "no reference .apk found"
return 1
fi
if ! apk_signatures_cmp "$input_apk" "$reference_apk"; then
echo "Invalid apk, signatures didn't match"
return 1
fi
echo "valid apk $input_apk"
return 0
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Nov 9, 14:08 (1 h, 30 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1182291
Default Alt Text
(8 KB)
Attached To
Mode
R134 rentgen-android
Attached
Detach File
Event Timeline