new: fixed rsa identity generation and implemented api enrollment plugin

This commit is contained in:
Simone Margaritelli
2019-10-06 23:25:02 +02:00
parent 107eb57f26
commit 1c251fc093
16 changed files with 127 additions and 27 deletions

View File

@ -0,0 +1,51 @@
__author__ = 'evilsocket@gmail.com'
__version__ = '1.0.0'
__name__ = 'api'
__license__ = 'GPL3'
__description__ = 'This plugin signals the unit cryptographic identity to api.pwnagotchi.ai'
import logging
import json
import requests
import pwnagotchi
from pwnagotchi.utils import StatusFile
OPTIONS = dict()
READY = False
STATUS = StatusFile('/root/.api-enrollment.json')
def on_loaded():
logging.info("api plugin loaded.")
def on_internet_available(ui, keypair, config, log):
global STATUS
if STATUS.newer_then_minutes(10):
return
try:
logging.info("api: signign enrollment request ...")
identity = "%s@%s" % (pwnagotchi.name(), keypair.fingerprint)
_, signature_b64 = keypair.sign(identity)
api_address = 'https://api.pwnagotchi.ai/api/v1/unit/enroll'
enroll = {
'identity': identity,
'public_key': keypair.pub_key_pem_b64,
'signature': signature_b64
}
logging.info("api: enrolling unit to %s ..." % api_address)
r = requests.post(api_address, json=enroll)
if r.status_code == 200:
token = r.json()
logging.info("api: enrolled")
STATUS.update(data=json.dumps(token))
else:
logging.error("error %d: %s" % (r.status_code, r.json()))
except Exception as e:
logging.exception("error while enrolling the unit")

View File

@ -33,7 +33,7 @@ def on_loaded():
logging.info("AUTO-BACKUP: Successfuly loaded.")
def on_internet_available(display, config, log):
def on_internet_available(display, keypair, config, log):
global STATUS
if READY:

View File

@ -23,7 +23,7 @@ def on_loaded():
READY = True
def on_internet_available(display, config, log):
def on_internet_available(display, keypair, config, log):
global STATUS
if READY:

View File

@ -20,7 +20,7 @@ def on_loaded():
# called in manual mode when there's internet connectivity
def on_internet_available(ui, config, log):
def on_internet_available(ui, keypair, config, log):
pass

View File

@ -55,7 +55,7 @@ def _upload_to_ohc(path, timeout=30):
raise e
def on_internet_available(display, config, log):
def on_internet_available(display, keypair, config, log):
"""
Called in manual mode when there's internet connectivity
"""

View File

@ -14,7 +14,7 @@ def on_loaded():
# called in manual mode when there's internet connectivity
def on_internet_available(ui, config, log):
def on_internet_available(ui, keypair, config, log):
if log.is_new() and log.handshakes > 0:
try:
import tweepy

View File

@ -12,7 +12,6 @@ import csv
from datetime import datetime
import requests
from pwnagotchi.mesh.wifi import freq_to_channel
from scapy.all import RadioTap, Dot11Elt, Dot11Beacon, rdpcap, Scapy_Exception, Dot11, Dot11ProbeResp, Dot11AssoReq, Dot11ReassoReq, Dot11EltRSN, Dot11EltVendorSpecific, Dot11EltMicrosoftWPA
READY = False
ALREADY_UPLOADED = None
@ -26,6 +25,8 @@ AKMSUITE_TYPES = {
}
def _handle_packet(packet, result):
from scapy.all import RadioTap, Dot11Elt, Dot11Beacon, rdpcap, Scapy_Exception, Dot11, Dot11ProbeResp, Dot11AssoReq, \
Dot11ReassoReq, Dot11EltRSN, Dot11EltVendorSpecific, Dot11EltMicrosoftWPA
"""
Analyze each packet and extract the data from Dot11 layers
"""
@ -76,6 +77,8 @@ def _handle_packet(packet, result):
def _analyze_pcap(pcap):
from scapy.all import RadioTap, Dot11Elt, Dot11Beacon, rdpcap, Scapy_Exception, Dot11, Dot11ProbeResp, Dot11AssoReq, \
Dot11ReassoReq, Dot11EltRSN, Dot11EltVendorSpecific, Dot11EltMicrosoftWPA
"""
Iterate over the packets and extract data
"""
@ -192,7 +195,9 @@ def _send_to_wigle(lines, api_key, timeout=30):
raise re_e
def on_internet_available(display, config, log):
def on_internet_available(display, keypair, config, log):
from scapy.all import RadioTap, Dot11Elt, Dot11Beacon, rdpcap, Scapy_Exception, Dot11, Dot11ProbeResp, Dot11AssoReq, \
Dot11ReassoReq, Dot11EltRSN, Dot11EltVendorSpecific, Dot11EltMicrosoftWPA
"""
Called in manual mode when there's internet connectivity
"""

View File

@ -54,7 +54,7 @@ def _upload_to_wpasec(path, timeout=30):
raise e
def on_internet_available(display, config, log):
def on_internet_available(display, keypair, config, log):
"""
Called in manual mode when there's internet connectivity
"""