├── README.md └── dropbox_ul.py /README.md: -------------------------------------------------------------------------------- 1 | Dropbox api plugin for pwnagotchi. 2 | Compatible with v1.5.3 and above which uses toml for configuration instead of yml 3 | 4 | # dropbox app console steps 5 | Create an app for dropbox @ https://www.dropbox.com/developers/apps/create. 6 | 7 | generate and copy app token from your app console. 8 | 9 | copy the path/folder name. 10 | 11 | # Steps to make this plugins work on pwnagotchi 1.5.3. and above using toml config 12 | copy dropbox_ul.py to /home/pi/pwnplugins 13 | 14 | edit main config.toml in pwnagotchi device with 15 | 16 | main.custom_plugins = "/home/pi/pwnplugins" 17 | 18 | main.plugins.dropbox_ul.enabled = true 19 | 20 | main.plugins.dropbox_ul.app_token = "token generated in app console" 21 | 22 | main.plugins.dropbox_ul.path = "/path or folder name made in app console" 23 | -------------------------------------------------------------------------------- /dropbox_ul.py: -------------------------------------------------------------------------------- 1 | import os 2 | import logging 3 | import threading 4 | import requests 5 | import json 6 | 7 | from pwnagotchi.utils import StatusFile 8 | from pwnagotchi import plugins 9 | from json.decoder import JSONDecodeError 10 | 11 | 12 | class dropbox(plugins.Plugin): 13 | __author__ = 'menglish99@gmail.com' 14 | __version__ = '0.0.1' 15 | __license__ = 'GPL3' 16 | __description__ = 'This plugin automatically uploads handshakes to a dropbox app' 17 | 18 | def __init__(self): 19 | self.ready = False 20 | self.lock = threading.Lock() 21 | try: 22 | self.report = StatusFile('/root/.dropbox_ul_uploads', data_format='json') 23 | except JSONDecodeError as json_err: 24 | os.remove("/root/.dropbox_ul_uploads") 25 | self.report = StatusFile('/root/.dropbox_ul_uploads', data_format='json') 26 | 27 | self.options = dict() 28 | self.skip = list() 29 | 30 | def _upload_to_dropbox(self, path, timeout=30): 31 | """ 32 | Uploads the file to dropbox 33 | """ 34 | head, tail = os.path.split(path) 35 | destFile = self.options['path'] + '/' + tail 36 | dbOpts = {'path': destFile, 'mode': 'add','autorename': True,'mute': False,'strict_conflict': False} 37 | 38 | headers = { 39 | 'Authorization': 'Bearer ' + self.options['app_token'], 40 | 'Dropbox-API-Arg': json.dumps(dbOpts), 41 | 'Content-Type': 'application/octet-stream', 42 | } 43 | data = open(path, 'rb').read() 44 | 45 | try: 46 | response = requests.post('https://content.dropboxapi.com/2/files/upload', headers=headers, data=data) 47 | logging.error(response) 48 | except requests.exceptions.RequestException as e: 49 | logging.error(f"OHC: Got an exception while uploading {path} -> {e}") 50 | raise e 51 | 52 | 53 | def on_loaded(self): 54 | """ 55 | Gets called when the plugin gets loaded 56 | """ 57 | if 'app_token' not in self.options or ('app_token' in self.options and self.options['app_token'] is None): 58 | logging.error("dropbox_ul: APP-TOKEN isn't set.") 59 | return 60 | logging.info(" [dropbox_ul] plugin loaded") 61 | self.ready = True 62 | 63 | def on_internet_available(self, agent): 64 | """ 65 | Called in manual mode when there's internet connectivity 66 | """ 67 | with self.lock: 68 | if self.ready: 69 | config = agent.config() 70 | display = agent.view() 71 | reported = self.report.data_field_or('reported', default=list()) 72 | 73 | handshake_dir = config['bettercap']['handshakes'] 74 | handshake_filenames = os.listdir(handshake_dir) 75 | handshake_paths = [os.path.join(handshake_dir, filename) for filename in handshake_filenames if 76 | filename.endswith('.pcap')] 77 | handshake_new = set(handshake_paths) - set(reported) - set(self.skip) 78 | 79 | if handshake_new: 80 | logging.info("dropbox_ul: Internet connectivity detected. Uploading new handshakes") 81 | 82 | for idx, handshake in enumerate(handshake_new): 83 | display.set('status', f"Uploading handshake to dropbox ({idx + 1}/{len(handshake_new)})") 84 | display.update(force=True) 85 | try: 86 | self._upload_to_dropbox(handshake) 87 | reported.append(handshake) 88 | self.report.update(data={'reported': reported}) 89 | logging.info("dropbox_ul: Successfully uploaded %s", handshake) 90 | except requests.exceptions.RequestException as req_e: 91 | self.skip.append(handshake) 92 | logging.error("dropbox_ul: %s", req_e) 93 | continue 94 | except OSError as os_e: 95 | logging.error("dropbox_ul: %s", os_e) 96 | continue 97 | 98 | 99 | --------------------------------------------------------------------------------