Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for downloading other file extentions with handshakes-dl.py #27

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 27 additions & 15 deletions handshakes-dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@
TEMPLATE = """
{% extends "base.html" %}
{% set active_page = "handshakes" %}

{% block title %}
{{ title }}
{% endblock %}

{% block styles %}
{{ super() }}
<style>
Expand All @@ -34,7 +32,6 @@
var shakeList = document.getElementById('list');
var filter = document.getElementById('filter');
var filterVal = filter.value.toUpperCase();

filter.onkeyup = function() {
document.body.style.cursor = 'progress';
var table, tr, tds, td, i, txtValue;
Expand All @@ -50,24 +47,30 @@
}
document.body.style.cursor = 'default';
}

{% endblock %}

{% block content %}
<input type="text" id="filter" placeholder="Search for ..." title="Type in a filter">
<ul id="list" data-role="listview" style="list-style-type:disc;">
{% for handshake in handshakes %}
<li class="file">
<a href="/plugins/handshakes-dl/{{handshake}}">{{handshake}}</a>
</li>
{% for ext in handshake.ext %}
<li class="file">
<a href="/plugins/handshakes-dl/{{handshake.name}}{{ext}}">{{handshake.name}}{{ext}}</a>
</li>
{% endfor %}
{% endfor %}
</ul>
{% endblock %}
"""

class handshakes:
def __init__(self, name, path, ext):
self.name = name
self.path = path
self.ext = ext

class HandshakesDL(plugins.Plugin):
__author__ = 'me@sayakb.com'
__version__ = '0.2.1'
__version__ = '0.2.2'
__license__ = 'GPL3'
__description__ = 'Download handshake captures from web-ui.'

Expand All @@ -86,16 +89,25 @@ def on_webhook(self, path, request):
return "Plugin not ready"

if path == "/" or not path:
handshakes = glob.glob(os.path.join(self.config['bettercap']['handshakes'], "*.pcap"))
handshakes = [os.path.basename(path)[:-5] for path in handshakes]
pcapfiles = glob.glob(os.path.join(self.config['bettercap']['handshakes'], "*.pcap"))

data = []
for path in pcapfiles:
name = os.path.basename(path)[:-5]
fullpathNoExt = path[:-5]
possibleExt = ['.2500', '.16800', '.22000']
foundExt = ['.pcap']
for ext in possibleExt:
if os.path.isfile(fullpathNoExt + ext):
foundExt.append(ext)
data.append(handshakes(name, fullpathNoExt, foundExt))
return render_template_string(TEMPLATE,
title="Handshakes | " + pwnagotchi.name(),
handshakes=handshakes)

handshakes=data)
else:
dir = self.config['bettercap']['handshakes']
try:
logging.info(f"[HandshakesDL] serving {dir}/{path}.pcap")
return send_from_directory(directory=dir, filename=path+'.pcap', as_attachment=True)
logging.info(f"[HandshakesDL] serving {dir}/{path}")
return send_from_directory(directory=dir, filename=path, as_attachment=True)
except FileNotFoundError:
abort(404)