Skip to content

Instantly share code, notes, and snippets.

@packmad
Last active November 11, 2016 14:12
Show Gist options
  • Save packmad/3e9f77d2de62a000e80e0a56e01cf944 to your computer and use it in GitHub Desktop.
Save packmad/3e9f77d2de62a000e80e0a56e01cf944 to your computer and use it in GitHub Desktop.
Calculate most used but not dangerous Android permissions
import itertools
# https://developer.android.com/guide/topics/security/permissions.html#normal-dangerous
group_dangerous = {
"CALENDAR": {"READ_CALENDAR", "WRITE_CALENDAR"},
"CAMERA": {"CAMERA"},
"CONTACTS": {"READ_CONTACTS", "WRITE_CONTACTS", "GET_ACCOUNTS"},
"LOCATION": {"ACCESS_FINE_LOCATION", "ACCESS_COARSE_LOCATION"},
"MICROPHONE": {"RECORD_AUDIO"},
"PHONE": {"READ_PHONE_STATE", "CALL_PHONE", "READ_CALL_LOG", "WRITE_CALL_LOG", "ADD_VOICEMAIL", "USE_SIP",
"PROCESS_OUTGOING_CALLS"},
"SENSORS": {"BODY_SENSORS"},
"SMS": {"SEND_SMS", "RECEIVE_SMS", "READ_SMS", "RECEIVE_WAP_PUSH", "RECEIVE_MMS"},
"STORAGE": {"READ_EXTERNAL_STORAGE", "WRITE_EXTERNAL_STORAGE"}
}
mu_malware = {"INTERNET", "READ_PHONE_STATE", "ACCESS_NETWORK_STATE", "WRITE_EXTERNAL_STORAGE", "SEND_SMS",
"ACCESS_WIFI_STATE", "RECEIVE_BOOT_COMPLETED", "ACCESS_COARSE_LOCATION", "RECEIVE_SMS", "WAKE_LOCK",
"READ_SMS", "VIBRATE", "ACCESS_FINE_LOCATION", "CHANGE_WIFI_STATE", "READ_CONTACTS"}
mu_gplay = {"INTERNET", "ACCESS_NETWORK_STATE", "WRITE_EXTERNAL_STORAGE", "ACCESS_WIFI_STATE", "WAKE_LOCK",
"READ_PHONE_STATE", "VIBRATE", "GET_ACCOUNTS", "ACCESS_COARSE_LOCATION", "READ_EXTERNAL_STORAGE",
"ACCESS_FINE_LOCATION", "RECEIVE_BOOT_COMPLETED", "CAMERA", "GET_TASKS", "READ_CONTACTS"}
mu_aptoide = {"INTERNET", "ACCESS_NETWORK_STATE", "WRITE_EXTERNAL_STORAGE", "WAKE_LOCK", "ACCESS_WIFI_STATE",
"READ_PHONE_STATE", "VIBRATE", "RECEIVE_BOOT_COMPLETED", "READ_EXTERNAL_STORAGE", "GET_ACCOUNTS",
"ACCESS_COARSE_LOCATION", "ACCESS_FINE_LOCATION", "GET_TASKS", "CAMERA", "READ_CONTACTS"}
mu_uptodown = {"INTERNET", "ACCESS_NETWORK_STATE", "WRITE_EXTERNAL_STORAGE", "WAKE_LOCK", "ACCESS_WIFI_STATE",
"READ_PHONE_STATE", "VIBRATE", "GET_ACCOUNTS", "READ_EXTERNAL_STORAGE", "ACCESS_COARSE_LOCATION",
"RECEIVE_BOOT_COMPLETED", "ACCESS_FINE_LOCATION", "CAMERA", "GET_TASKS", "READ_CONTACTS"}
mu = set().union(mu_malware).union(mu_gplay).union(mu_aptoide).union(mu_uptodown)
dangerous = {item for sub in list(itertools.chain(group_dangerous.values())) for item in sub}
mu_dangerous = mu.intersection(dangerous)
mu_not_dangerous = mu-dangerous
dangerous_not_mu = dangerous-mu
print("Most used: " + str(mu))
print("Dangerous: " + str(dangerous))
print("Most used and dangerous: " + str(mu_dangerous))
print("Dangerous not most used: " + str(dangerous_not_mu))
print("Most used not dangerous: " + str(mu_not_dangerous))
@packmad
Copy link
Author

packmad commented Nov 10, 2016

Most used: {'VIBRATE', 'READ_SMS', 'READ_CONTACTS', 'GET_TASKS', 'RECEIVE_SMS', 'RECEIVE_BOOT_COMPLETED', 'GET_ACCOUNTS', 'CHANGE_WIFI_STATE', 'SEND_SMS', 'WRITE_EXTERNAL_STORAGE', 'ACCESS_FINE_LOCATION', 'ACCESS_NETWORK_STATE', 'READ_EXTERNAL_STORAGE', 'WAKE_LOCK', 'ACCESS_WIFI_STATE', 'CAMERA', 'READ_PHONE_STATE', 'ACCESS_COARSE_LOCATION', 'INTERNET'}
Dangerous: {'PROCESS_OUTGOING_CALLS', 'READ_CONTACTS', 'RECEIVE_SMS', 'GET_ACCOUNTS', 'USE_SIP', 'BODY_SENSORS', 'WRITE_CONTACTS', 'SEND_SMS', 'READ_CALENDAR', 'WRITE_EXTERNAL_STORAGE', 'WRITE_CALL_LOG', 'READ_EXTERNAL_STORAGE', 'ADD_VOICEMAIL', 'READ_SMS', 'RECEIVE_MMS', 'RECORD_AUDIO', 'RECEIVE_WAP_PUSH', 'CALL_PHONE', 'READ_PHONE_STATE', 'ACCESS_FINE_LOCATION', 'WRITE_CALENDAR', 'CAMERA', 'READ_CALL_LOG', 'ACCESS_COARSE_LOCATION'}
Most used and dangerous: {'SEND_SMS', 'READ_SMS', 'WRITE_EXTERNAL_STORAGE', 'ACCESS_FINE_LOCATION', 'READ_CONTACTS', 'RECEIVE_SMS', 'READ_EXTERNAL_STORAGE', 'GET_ACCOUNTS', 'CAMERA', 'READ_PHONE_STATE', 'ACCESS_COARSE_LOCATION'}
Dangerous not most used: {'WRITE_CONTACTS', 'RECEIVE_MMS', 'READ_CALENDAR', 'PROCESS_OUTGOING_CALLS', 'READ_CALL_LOG', 'WRITE_CALL_LOG', 'RECORD_AUDIO', 'RECEIVE_WAP_PUSH', 'WRITE_CALENDAR', 'USE_SIP', 'BODY_SENSORS', 'CALL_PHONE', 'ADD_VOICEMAIL'}
Most used not dangerous: {'VIBRATE', 'ACCESS_NETWORK_STATE', 'GET_TASKS', 'RECEIVE_BOOT_COMPLETED', 'WAKE_LOCK', 'ACCESS_WIFI_STATE', 'CHANGE_WIFI_STATE', 'INTERNET'}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment