1515
1616from mpt import functions
1717
18- __version__ = '0.7.33 '
18+ __version__ = '0.7.34 '
1919
2020from mpt import settings , logger
2121from mpt .config import Config
2222
23+ def create_default_pentest_folder_structure (pentest_dir ):
24+ os .makedirs (os .path .join (pentest_dir , settings .APP_FOLDER ))
25+ os .makedirs (os .path .join (pentest_dir , settings .BACKUP_FOLDER ))
26+ os .makedirs (os .path .join (pentest_dir , settings .SCREENSHOT_FOLDER ))
27+ os .makedirs (os .path .join (pentest_dir , settings .SOURCE_FOLDER ))
28+ os .makedirs (os .path .join (pentest_dir , settings .BURP_FOLDER ))
2329
2430def create_pentest_folder_with_absolute_path ():
2531 pentest_path = input ("Please put absolute path to pentest project folder: " )
@@ -30,8 +36,7 @@ def create_pentest_folder_with_absolute_path():
3036
3137 use_tool_dir = functions .yes_no ('Would you like to use this directory \" {}\" ? ' .format (pentest_path ))
3238 if use_tool_dir :
33- os .makedirs (os .path .join (pentest_path , settings .APP_FOLDER ))
34- os .makedirs (os .path .join (pentest_path , settings .BACKUP_FOLDER ))
39+ create_default_pentest_folder_structure (pentest_path )
3540 return pentest_path
3641 else :
3742 log .warn ("Setup canceled" )
@@ -47,19 +52,6 @@ def setup_pentest(apk):
4752 log .error ('File does not have required extension: apk' )
4853 sys .exit ()
4954
50- aapt_bin = settings .ANDROID_TOOLS ['aapt' ]['bin' ]
51-
52- # get package name and application label
53- # aapt dump badging <path-to-apk> | grep package
54- # aapt dump badging <path-to-apk> | grep -w "application-label:"
55- output = functions .run_command (f"{ aapt_bin } dump badging { apk_file } " )
56- output = "" .join (output )
57-
58- package_match = re .search (r"package: name='(.*?)'" , output )
59- application_label_match = re .search (r"application-label:'(.*?)'" , output )
60-
61- package = package_match .group (1 ) if package_match else None
62- application_label = application_label_match .group (1 ) if application_label_match else None
6355 pentest_path = os .path .join (os .getcwd (), settings .PENTEST_FOLDER )
6456
6557 # remove pentest folder, if exists
@@ -73,8 +65,7 @@ def setup_pentest(apk):
7365 if menu_entry_index == 0 :
7466 shutil .rmtree (pentest_path )
7567 log .debug (f"Folder { pentest_path } recreated" )
76- os .makedirs (os .path .join (pentest_path , settings .APP_FOLDER ))
77- os .makedirs (os .path .join (pentest_path , settings .BACKUP_FOLDER ))
68+ create_default_pentest_folder_structure (pentest_path )
7869 if menu_entry_index == 1 :
7970 pentest_path = create_pentest_folder_with_absolute_path ()
8071 if menu_entry_index == 2 :
@@ -90,8 +81,8 @@ def setup_pentest(apk):
9081 menu_entry_index = terminal_menu .show ()
9182
9283 if menu_entry_index == 0 :
93- os . makedirs ( os . path . join ( pentest_path , settings . APP_FOLDER ))
94- os . makedirs ( os . path . join ( pentest_path , settings . BACKUP_FOLDER ) )
84+ # create default folder structure
85+ create_default_pentest_folder_structure ( pentest_path )
9586 if menu_entry_index == 1 :
9687 pentest_path = create_pentest_folder_with_absolute_path ()
9788 # Skip setup
@@ -102,16 +93,36 @@ def setup_pentest(apk):
10293 if not os .path .isdir (pentest_path ):
10394 log .error ("Error: folder {} could not be created" .format (pentest_path ))
10495 sys .exit ()
105- # TODO print message before overwriting the folder
96+
10697 log .info ("Folder for security assessment {} created" .format (Fore .CYAN + settings .PENTEST_FOLDER + Style .RESET_ALL ))
10798
108- app_name = os .path .join (settings .APP_FOLDER , os .path .basename (apk_file ))
109- shutil .copy (apk_file , os .path .join (pentest_path , app_name ))
99+ # Replace masked characters with "_", fix errors with special chars in shell
100+ new_apk_filename = re .sub (r'[^\w.-]' , '_' , apk_file )
101+ if apk_file != new_apk_filename :
102+ log .warn (f"APK file renamed to { new_apk_filename } " )
103+ app_pentest_file_location = os .path .join (settings .APP_FOLDER , os .path .basename (new_apk_filename ))
104+ app_pentest_file = os .path .join (pentest_path , app_pentest_file_location )
105+ shutil .copy (apk_file , app_pentest_file )
106+
107+ # update apk information
108+
109+ # get package name and application label
110+ # aapt dump badging <path-to-apk> | grep package
111+ # aapt dump badging <path-to-apk> | grep -w "application-label:"
112+ aapt_bin = settings .ANDROID_TOOLS ['aapt' ]['bin' ]
113+ output = functions .run_command (f"{ aapt_bin } dump badging { app_pentest_file } " )
114+ output = "" .join (output )
115+
116+ package_match = re .search (r"package: name='(.*?)'" , output )
117+ application_label_match = re .search (r"application-label:'(.*?)'" , output )
118+
119+ package = package_match .group (1 ) if package_match else None
120+ application_label = application_label_match .group (1 ) if application_label_match else None
110121
111122 # update configuration
112123 conf = Config ()
113124 conf .update ('pentest-dir' , pentest_path )
114- conf .update ('app' , app_name )
125+ conf .update ('app' , app_pentest_file_location )
115126 conf .update ('package-name' , package )
116127 conf .update ('application-label' , application_label )
117128 conf .print ()
0 commit comments