Skip to content

Commit 6d23849

Browse files
committed
fixed issue with special chars und added new folder structure
1 parent 7887a9a commit 6d23849

File tree

3 files changed

+41
-25
lines changed

3 files changed

+41
-25
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# ChangeLog
22

3+
### 0.7.34
4+
- BUGFIX: fixed issue with special chars in apk filename
5+
- ADDED: new pentest folder structure
6+
37
### 0.7.33
48
- CHANGE: Minor changes
59

mpt/console.py

Lines changed: 35 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,17 @@
1515

1616
from mpt import functions
1717

18-
__version__ = '0.7.33'
18+
__version__ = '0.7.34'
1919

2020
from mpt import settings, logger
2121
from 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

2430
def 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()

mpt/settings.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
APP_FOLDER = "app"
1111
BACKUP_FOLDER = "backup"
1212
SCREENSHOT_FOLDER = "screenshots"
13-
SOURCE_FOLDER = os.path.join(APP_FOLDER, "source")
13+
SOURCE_FOLDER = "source"
14+
BURP_FOLDER = "burp"
1415
FRIDA_BIN = "frida-server"
1516
TEMP_DIR = "/tmp/local-mpt/"
1617
BROWSER = 'chromium'

0 commit comments

Comments
 (0)