15
15
16
16
from mpt import functions
17
17
18
- __version__ = '0.7.33 '
18
+ __version__ = '0.7.34 '
19
19
20
20
from mpt import settings , logger
21
21
from mpt .config import Config
22
22
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 ))
23
29
24
30
def create_pentest_folder_with_absolute_path ():
25
31
pentest_path = input ("Please put absolute path to pentest project folder: " )
@@ -30,8 +36,7 @@ def create_pentest_folder_with_absolute_path():
30
36
31
37
use_tool_dir = functions .yes_no ('Would you like to use this directory \" {}\" ? ' .format (pentest_path ))
32
38
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 )
35
40
return pentest_path
36
41
else :
37
42
log .warn ("Setup canceled" )
@@ -47,19 +52,6 @@ def setup_pentest(apk):
47
52
log .error ('File does not have required extension: apk' )
48
53
sys .exit ()
49
54
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
63
55
pentest_path = os .path .join (os .getcwd (), settings .PENTEST_FOLDER )
64
56
65
57
# remove pentest folder, if exists
@@ -73,8 +65,7 @@ def setup_pentest(apk):
73
65
if menu_entry_index == 0 :
74
66
shutil .rmtree (pentest_path )
75
67
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 )
78
69
if menu_entry_index == 1 :
79
70
pentest_path = create_pentest_folder_with_absolute_path ()
80
71
if menu_entry_index == 2 :
@@ -90,8 +81,8 @@ def setup_pentest(apk):
90
81
menu_entry_index = terminal_menu .show ()
91
82
92
83
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 )
95
86
if menu_entry_index == 1 :
96
87
pentest_path = create_pentest_folder_with_absolute_path ()
97
88
# Skip setup
@@ -102,16 +93,36 @@ def setup_pentest(apk):
102
93
if not os .path .isdir (pentest_path ):
103
94
log .error ("Error: folder {} could not be created" .format (pentest_path ))
104
95
sys .exit ()
105
- # TODO print message before overwriting the folder
96
+
106
97
log .info ("Folder for security assessment {} created" .format (Fore .CYAN + settings .PENTEST_FOLDER + Style .RESET_ALL ))
107
98
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
110
121
111
122
# update configuration
112
123
conf = Config ()
113
124
conf .update ('pentest-dir' , pentest_path )
114
- conf .update ('app' , app_name )
125
+ conf .update ('app' , app_pentest_file_location )
115
126
conf .update ('package-name' , package )
116
127
conf .update ('application-label' , application_label )
117
128
conf .print ()
0 commit comments