-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcheck-binary.sh
93 lines (80 loc) · 2.82 KB
/
check-binary.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/bin/bash
check_feature() {
local title=$1
local commands=$2
echo "[*] $title"
printf "%-15s | %s\n" "Function" "Value"
printf "%-15s | %s\n" "-----------" "----------------------------------"
for cmd in "${commands[@]}"; do
local function_name="${cmd##* }"
function_name="${function_name//\'/}" # remove quotes
output=$(eval $cmd)
if [ -z "$output" ]; then
printf "%-15s | %s\n" "$function_name" "N/F"
else
IFS=$'\n'
for line in $output; do
printf "%-15s | %s\n" "$function_name" "$line"
function_name=""
done
unset IFS
fi
printf "%-15s | %s\n" "-----------" "----------------------------------"
done
echo ""
}
if [ $# -eq 0 ]; then
echo "No binary provided. Usage: ./check.sh <binary>"
exit 1
fi
binary=$1
echo "[+] iOS Binary Security Analyzer"
echo "*N/F = Not Found"
echo ""
architecture=$(lipo -info "$binary")
architecture="${architecture##*: }"
echo "[*] Architecture :"
echo "$architecture"
echo ""
echo "------------------------------------------"
echo "---------------- SECURITY ----------------"
echo "------------------------------------------"
echo ""
# Check if the binary is encrypted
crypt_info=$(otool -arch all -Vl "$binary" | grep -A5 LC_ENCRYPT | grep -w cryptid)
if [[ $crypt_info = *"1"* ]]; then
echo "[+] Binary is encrypted :"
else
echo "[-] Binary is not encrypted :"
fi
echo $crypt_info
echo ""
# Perform the checks
check_feature "PIE (Position Idependant Executable)" "otool -hv $binary | grep PIE"
check_feature "Stack Canaries" "otool -I -v $binary | grep stack_chk"
check_feature "ARC (Automatic Reference Counting)" "otool -I -v $binary | grep _objc_"
echo "-----------------------------------------"
echo "---------------- INSECURE ---------------"
echo "-----------------------------------------"
echo ""
check_feature "Weak Cryptography (MD5)" "otool -I -v $binary | grep -w '_CC_MD5'"
check_feature "Weak Cryptography (SHA1)" "otool -I -v $binary | grep -w '_CC_SHA1'"
# The previous checks
functions=("_random" "_srand" "_rand" "_gets" "_memcpy" "_strncpy" "_strlen" "_vsnprintf" "_sscanf" "_strtok" "_alloca" "_sprintf" "_printf" "_vsprintf" "_malloc")
echo "[*] Unsafe and insecure functions"
printf "%-15s | %s\n" "Function" "Value"
printf "%-15s | %s\n" "-----------" "----------------------------------"
for function in "${functions[@]}"; do
output=$(otool -I -v $binary | grep -w $function)
if [ -z "$output" ]; then
printf "%-15s | %s\n" "$function" "N/F"
else
IFS=$'\n'
for line in $output; do
printf "%-15s | %s\n" "$function" "$line"
function=""
done
unset IFS
fi
printf "%-15s | %s\n" "-----------" "----------------------------------"
done