From d0ce5a1725f3aaeea5e67def969eb4772a9250af Mon Sep 17 00:00:00 2001 From: "Ajin.Abraham" Date: Sat, 2 Dec 2023 14:28:02 -0800 Subject: [PATCH] code QA --- mobsf/DynamicAnalyzer/views/android/analysis.py | 7 +++---- mobsf/DynamicAnalyzer/views/ios/analysis.py | 2 +- mobsf/MobSF/utils.py | 11 +++++++++++ mobsf/StaticAnalyzer/views/common/shared_func.py | 14 +++----------- 4 files changed, 18 insertions(+), 16 deletions(-) diff --git a/mobsf/DynamicAnalyzer/views/android/analysis.py b/mobsf/DynamicAnalyzer/views/android/analysis.py index 29c1e70b6b..d1a36f905d 100644 --- a/mobsf/DynamicAnalyzer/views/android/analysis.py +++ b/mobsf/DynamicAnalyzer/views/android/analysis.py @@ -8,6 +8,8 @@ from pathlib import Path from mobsf.MobSF.utils import ( + EMAIL_REGEX, + URL_REGEX, is_file_exists, python_list, ) @@ -18,10 +20,7 @@ from mobsf.MalwareAnalyzer.views.MalwareDomainCheck import ( MalwareDomainCheck, ) -from mobsf.StaticAnalyzer.views.common.shared_func import ( - EMAIL_REGEX, - URL_REGEX, -) + logger = logging.getLogger(__name__) diff --git a/mobsf/DynamicAnalyzer/views/ios/analysis.py b/mobsf/DynamicAnalyzer/views/ios/analysis.py index c916bf0ab0..6a9eb348e4 100644 --- a/mobsf/DynamicAnalyzer/views/ios/analysis.py +++ b/mobsf/DynamicAnalyzer/views/ios/analysis.py @@ -5,7 +5,7 @@ import re from pathlib import Path -from mobsf.StaticAnalyzer.views.common.shared_func import ( +from mobsf.MobSF.utils import ( EMAIL_REGEX, URL_REGEX, ) diff --git a/mobsf/MobSF/utils.py b/mobsf/MobSF/utils.py index f2f84b9b92..e15b2067c1 100755 --- a/mobsf/MobSF/utils.py +++ b/mobsf/MobSF/utils.py @@ -35,6 +35,17 @@ ADB_PATH = None BASE64_REGEX = re.compile(r'^[-A-Za-z0-9+/]*={0,3}$') MD5_REGEX = re.compile(r'^[0-9a-f]{32}$') +# Regex to capture strings between quotes or tag +STRINGS_REGEX = re.compile(r'(?<=\")(.+?)(?=\")|(?<=\)(.+?)(?=\<)') +# MobSF Custom regex to catch maximum URI like strings +URL_REGEX = re.compile( + ( + r'((?:https?://|s?ftps?://|' + r'file://|javascript:|data:|www\d{0,3}[.])' + r'[\w().=/;,#:@?&~*+!$%\'{}-]+)' + ), + re.UNICODE) +EMAIL_REGEX = re.compile(r'[\w+.-]{1,20}@[\w-]{1,20}\.[\w]{2,10}') class Color(object): diff --git a/mobsf/StaticAnalyzer/views/common/shared_func.py b/mobsf/StaticAnalyzer/views/common/shared_func.py index 69ff375eff..67bfe41bf3 100755 --- a/mobsf/StaticAnalyzer/views/common/shared_func.py +++ b/mobsf/StaticAnalyzer/views/common/shared_func.py @@ -24,6 +24,9 @@ from mobsf.MobSF import settings from mobsf.MobSF.utils import ( + EMAIL_REGEX, + STRINGS_REGEX, + URL_REGEX, is_md5, print_n_send_error_response, upstream_proxy, @@ -37,17 +40,6 @@ logger = logging.getLogger(__name__) -# Regex to capture strings between quotes or tag -STRINGS_REGEX = re.compile(r'(?<=\")(.+?)(?=\")|(?<=\)(.+?)(?=\<)') -# MobSF Custom regex to catch maximum URI like strings -URL_REGEX = re.compile( - ( - r'((?:https?://|s?ftps?://|' - r'file://|javascript:|data:|www\d{0,3}[.])' - r'[\w().=/;,#:@?&~*+!$%\'{}-]+)' - ), - re.UNICODE) -EMAIL_REGEX = re.compile(r'[\w+.-]{1,20}@[\w-]{1,20}\.[\w]{2,10}') def hash_gen(app_path) -> tuple: