Files
Mobile-Security-Framework-M…/scripts/update_android_permissions.py
T
Ajin Abraham 6e329c0d3f [HOTFIX] bs4 malformed xml parsing + xml namespace detection (#2248)
* Use BeautifulSoup4 to prettify malformed XML
* Detect non standard XML namespace in AndroidManifest.xml (Fixes : https://github.com/MobSF/Mobile-Security-Framework-MobSF/issues/2198) 
* Updated android permissions list
* Updated android permission update check script
2023-08-26 18:32:07 -07:00

60 lines
1.9 KiB
Python

#!/usr/bin/env python3
import re
import requests
from bs4 import BeautifulSoup as Soup
from bs4 import element
ANDROID_PERMISSION_DOCS_URL = ('https://developer.android.com/'
'reference/android/Manifest.permission')
response = requests.get(ANDROID_PERMISSION_DOCS_URL)
content = Soup(response.content, 'html.parser')
online_permissions = {}
# grab all the permissions from the online docs
permission_divs = content.find_all(
'div', {'data-version-added': re.compile(r'\d*')})
for pd in permission_divs:
permission_name = pd.find('h3').contents[0]
if permission_name in ['Constants', 'Manifest.permission']:
continue
try:
protection_level = re.search(
r'Protection level\: (\w+)', str(pd)).groups()[0]
except AttributeError:
protection_level = 'normal'
desc = []
for a in pd.find('p').contents:
if type(a) is element.NavigableString:
desc.append(str(a).strip().replace(
'\n', '').replace('\t', '').replace('\xa0', ''))
elif type(a) is element.Tag:
if 'Protection level:' in a.text:
break
desc.append(str(a.text).strip().replace(
'\n', '').replace('\t', '').replace('\xa0', ''))
description = ' '.join(desc)
online_permissions[permission_name] = [protection_level,
'',
description]
# check the permissions we currently have in dvm_permissions.py
DVM_PERMISSIONS = {}
eval(compile(open('../mobsf/StaticAnalyzer/views/'
'android/dvm_permissions.py').read(),
'<string>',
'exec'))
MANIFEST_PERMISSIONS = DVM_PERMISSIONS['MANIFEST_PERMISSION']
for permission_name in online_permissions:
if permission_name in MANIFEST_PERMISSIONS.keys():
continue
print('\'{}\': {},'.format(permission_name, str(
online_permissions[permission_name])))