Skip to content

Commit

Permalink
Optimizing downloads
Browse files Browse the repository at this point in the history
  • Loading branch information
ajinabraham committed Nov 24, 2024
1 parent 6522360 commit 9008214
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 13 deletions.
12 changes: 2 additions & 10 deletions mobsf/MobSF/views/home.py
Original file line number Diff line number Diff line change
Expand Up @@ -480,15 +480,13 @@ def download(request):

@login_required
def generate_download(request):
"""Generate downloads for uploaded binaries/source."""
"""Generate downloads for smali/java zip."""
try:
binary = ('apk', 'ipa', 'jar', 'aar', 'so', 'dylib', 'a')
source = ('smali', 'java')
logger.info('Generating Downloads')
md5 = request.GET['hash']
file_type = request.GET['file_type']
if (not is_md5(md5)
or file_type not in binary + source):
or file_type not in ('smali', 'java')):
msg = 'Invalid download type or hash'
logger.exception(msg)
return print_n_send_error_response(request, msg)
Expand All @@ -509,12 +507,6 @@ def generate_download(request):
shutil.make_archive(
dwd_file.as_posix(), 'zip', directory.as_posix())
file_name = f'{md5}-smali.zip'
elif file_type in binary:
# Binaries
file_name = f'{md5}.{file_type}'
src = app_dir / file_name
dst = dwd_dir / file_name
shutil.copy2(src.as_posix(), dst.as_posix())
return redirect(f'/download/{file_name}')
except Exception:
msg = 'Generating Downloads'
Expand Down
4 changes: 2 additions & 2 deletions mobsf/templates/static_analysis/android_binary_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ <h3>{{exported_count.exported_providers}} / {{ providers | length }}</h3>
</p>
<p> <a href="{% url 'static_analyzer' checksum=md5 %}?rescan=1" class="btn btn-info" role="button"><i class="fa fa-sync"></i> Rescan</a>
{% if app_type in 'so' %}
<a href="{% url 'generate_downloads' %}?hash={{ md5 }}&amp;file_type={{ app_type }}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {{ app_type | upper}}</a>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {{ app_type | upper}}</a>
{% endif %}
{% if app_type not in 'so' %}
<a id="supbtn" onclick="list_suppressions()" role="button" class="btn btn-primary" data-target="#sup_list" data-toggle="modal" href="#"><i class="fa fa-table" aria-hidden="true"></i> Manage Suppressions</a>
Expand Down Expand Up @@ -659,7 +659,7 @@ <h3>{{exported_count.exported_providers}} / {{ providers | length }}</h3>
{% if app_type not in 'jar,aar' %}
<a href="{% url 'generate_downloads' %}?hash={{ md5 }}&amp;file_type=smali" class="btn btn-warning"> <i class="fa fa-download"></i> Download Smali Code</a>
{% endif %}
<a href="{% url 'generate_downloads' %}?hash={{ md5 }}&amp;file_type={{ app_type }}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {{ app_type | upper}}</a>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {{ app_type | upper}}</a>

</p>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,6 +502,7 @@ <h3>{{exported_count.exported_providers}} / {{ providers | length }}</h3>
<a target="_blank" href="{% url "manifest_view" checksum=md5 %}?type={{ app_type }}" role="button" class="btn btn-primary"><i class="fa fa-eye"></i> View AndroidManifest.xml</a>
<a href="{% url "tree_view" %}?md5={{ md5 }}&amp;type=java" class="btn btn-info" role="button"><i class="fa fa-code"></i> View Source</a>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target=".scan-logs-mdl"><i class="fa fa-list" aria-hidden="true"></i> Scan Logs</button>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download ZIP</a>
</p>
</div>
</div><!-- /.card -->
Expand Down
2 changes: 1 addition & 1 deletion mobsf/templates/static_analysis/ios_binary_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ <h5 class="card-title"></h5>
{% if app_type not in 'Dylib,A' %}
<a target="_blank" href="{% url 'view_file_ios' %}?file=classdump.txt&amp;md5={{ md5 }}&amp;type=ios" class="btn btn-warning" role="button"><i class="fa fa-code"></i> View Class Dump</a>
{% endif %}
<a href="{% url 'generate_downloads' %}?hash={{ md5 }}&amp;file_type={% if app_type in 'Dylib' %}dylib{% elif app_type in 'A' %}a{% else %}ipa{% endif %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {% if app_type in 'Dylib' %}DYLIB{% elif app_type in 'A' %}A{% else %}IPA{% endif %}</a>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download {% if app_type in 'Dylib' %}DYLIB{% elif app_type in 'A' %}A{% else %}IPA{% endif %}</a>
</p>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions mobsf/templates/static_analysis/ios_source_analysis.html
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,7 @@ <h5 class="card-title"></h5>
<a id="supbtn" onclick="list_suppressions()" role="button" class="btn btn-primary" data-target="#sup_list" data-toggle="modal" href="#"><i class="fa fa-table"></i> Manage Suppressions</a>
<a data-target="#mplist" role="button" class="btn btn-primary" data-toggle="modal" href="#"><i class="fa fa-eye"></i> View Info.plist</a>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target=".scan-logs-mdl"><i class="fa fa-list" aria-hidden="true"></i> Scan Logs</button>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download ZIP</a>
</p>
</div>
</div><!-- /.card -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ <h5 class="card-title"></h5>
<a href="{% url 'static_analyzer_windows' checksum=md5 %}?rescan=1" class="btn btn-info" role="button"><i class="fa fa-sync"></i> Rescan</a>
<a href="#" data-target="#mstrings" role="button" class="btn btn-primary" data-toggle="modal"><i class="fa fa-table"></i> View Strings</a>
<button type="button" class="btn btn-warning" data-toggle="modal" data-target=".scan-logs-mdl"><i class="fa fa-list" aria-hidden="true"></i> Scan Logs</button>
<a href="{% url "download_binary" checksum=md5 %}" class="btn btn-warning"> <i class="fa fa-download"></i> Download APPX</a>
</p>
</div>
</div><!-- /.card -->
Expand Down

0 comments on commit 9008214

Please sign in to comment.