From 3cc31686c268442ca409b68e5ec84e863cbe594c Mon Sep 17 00:00:00 2001
From: root <root@RossDebian>
Date: Sat, 12 Oct 2019 14:46:25 +0100
Subject: [PATCH] cleancap plugin added

---
 pwnagotchi/defaults.yml                |  2 +
 pwnagotchi/plugins/default/cleancap.py | 55 ++++++++++++++++++++++++++
 2 files changed, 57 insertions(+)
 create mode 100644 pwnagotchi/plugins/default/cleancap.py

diff --git a/pwnagotchi/defaults.yml b/pwnagotchi/defaults.yml
index e6787c7..e2f72f0 100644
--- a/pwnagotchi/defaults.yml
+++ b/pwnagotchi/defaults.yml
@@ -58,6 +58,8 @@ main:
       quickdic:
         enabled: false
         wordlist_folder: /opt/wordlists/
+      cleancap:
+        enabled: false
     # monitor interface to use
     iface: mon0
     # command to run to bring the mon interface up in case it's not up already
diff --git a/pwnagotchi/plugins/default/cleancap.py b/pwnagotchi/plugins/default/cleancap.py
new file mode 100644
index 0000000..ae48840
--- /dev/null
+++ b/pwnagotchi/plugins/default/cleancap.py
@@ -0,0 +1,55 @@
+__author__ = 'pwnagotchi [at] rossmarks [dot] uk'
+__version__ = '1.0.0'
+__name__ = 'cleancap'
+__license__ = 'GPL3'
+__description__ = 'confirm pcap contains handshake/PMKID or delete it'
+
+'''
+Aircrack-ng needed, to install:
+> apt-get install aircrack-ng
+'''
+
+import logging
+import subprocess
+import string
+import re
+
+OPTIONS = dict()
+
+def on_loaded():
+    logging.info("cleancap plugin loaded")
+
+def on_handshake(agent, filename, access_point, client_station):
+    display = agent._view
+    todelete = 0
+
+    result = subprocess.run(('/usr/bin/aircrack-ng '+ filename +' | grep "1 handshake" | awk \'{print $2}\''),shell=True, stdout=subprocess.PIPE)
+    result = result.stdout.decode('utf-8').translate({ord(c) :None for c in string.whitespace})
+    if result:
+        logging.info("[cleancap] contains handshake")
+    else:
+        todetele = 1
+
+    if todelete == 0:
+        result = subprocess.run(('/usr/bin/aircrack-ng '+ filename +' | grep "PMKID" | awk \'{print $2}\''),shell=True, stdout=subprocess.PIPE)
+        result = result.stdout.decode('utf-8').translate({ord(c) :None for c in string.whitespace})
+        if result:
+            logging.info("[cleancap] contains PMKID")
+        else:
+            todetele = 1
+
+    if todelete == 1:
+        set_text("uncrackable pcap")
+        display.update(force=True)
+
+text_to_set = "";
+def set_text(text):
+    global text_to_set
+    text_to_set = text
+
+def on_ui_update(ui):
+    global text_to_set
+    if text_to_set:
+        ui.set('face', "(>.<)")
+        ui.set('status', text_to_set)
+        text_to_set = ""