diff --git a/README.md b/README.md index 20f29e4..b9a5d38 100644 --- a/README.md +++ b/README.md @@ -6,15 +6,43 @@ Displays the most recent cracked password on the Pwnagotchi display. It currentl # Installation +## Via installation script + +This script will execute the same steps as the manual installation. + +1. SSH into your Pwnagotchi and run the following command: +``` bash +git clone https://github.com/c-nagy/pwnagotchi-display-password-plugin +cd pwnagotchi-display-password-plugin +``` +2. Run the installation script as root: +``` bash +sudo ./install.sh + +``` +It will install the plugin to your configured `main.custom_plugins` variable on `/etc/pwnagotchi/config.toml`. If you don't have a `main.custom_plugins` variable, it will add it to the end of the file and then ask you to declare it + +3. Reboot the Pwnagotchi daemon to ensure all changes are applied, you can do so with the following command: +``` bash +sudo systemctl restart pwnagotchi +``` + +This also allow you to update the plugin by running ```git pull``` on the plugin repo directory. + +## Manual + 1. SSH into your Pwnagotchi and create a new folder for third-party Pwnagotchi plugins. I use `/root/custom_plugins/` but it doesn't really matter: `mkdir /root/custom_plugins/` -1. Grab the `display-password.py` and `display-password.toml` file from this Github repo and put it into that custom plugins directory. -1. Edit `/etc/pwnagotchi/config.toml` and change the `main.custom_plugins` variable to point to the custom plugins directory you just created: `main.custom_plugins = "/root/custom_plugins/"` -1. In the same `/etc/pwnagotchi/config.toml` file, add the following lines to enable the plugin: +2. Grab the `display-password.py` and `display-password.toml` file from this Github repo and put it into that custom plugins directory. +3. Edit `/etc/pwnagotchi/config.toml` and change the `main.custom_plugins` variable to point to the custom plugins directory you just created: `main.custom_plugins = "/root/custom_plugins/"` +4. In the same `/etc/pwnagotchi/config.toml` file, add the following lines to enable the plugin: ``` main.plugins.display-password.enabled = true main.plugins.display-password.orientation = "horizontal" ``` -Once the above steps are completed, reboot the Pwnagotchi to ensure all changes are applied. +Once the above steps are completed, reboot the Pwnagotchi daemon to ensure all changes are applied, you can do so with the following command: +``` bash +sudo systemctl restart pwnagotchi +``` # Screenshot: diff --git a/display-password.py b/display-password.py index fbc6aac..f4e65ea 100644 --- a/display-password.py +++ b/display-password.py @@ -1,65 +1,89 @@ -# display-password shows recently cracked passwords on the pwnagotchi display -# -# -############################################################### -# -# Inspired by, and code shamelessly yoinked from -# the pwnagotchi memtemp.py plugin by https://github.com/xenDE -# -############################################################### from pwnagotchi.ui.components import LabeledValue from pwnagotchi.ui.view import BLACK import pwnagotchi.ui.fonts as fonts import pwnagotchi.plugins as plugins -import pwnagotchi import logging import os class DisplayPassword(plugins.Plugin): - __author__ = '@nagy_craig' - __version__ = '1.0.0' - __license__ = 'GPL3' - __description__ = 'A plugin to display recently cracked passwords' + __author__ = "@nagy_craig" + __version__ = "1.0.0" + __license__ = "GPL3" + __description__ = "A plugin to display recently cracked passwords" def on_loaded(self): logging.info("display-password loaded") def on_ui_setup(self, ui): - if ui.is_waveshare_v2(): - h_pos = (0, 95) - v_pos = (180, 61) - elif ui.is_waveshare_v1(): - h_pos = (0, 95) - v_pos = (170, 61) - elif ui.is_waveshare144lcd(): - h_pos = (0, 92) - v_pos = (78, 67) - elif ui.is_inky(): - h_pos = (0, 83) - v_pos = (165, 54) - elif ui.is_waveshare27inch(): - h_pos = (0, 153) - v_pos = (216, 122) - else: - h_pos = (0, 91) - v_pos = (180, 61) + try: + if ui.is_waveshare_v2(): + h_pos = (0, 95) + v_pos = (180, 61) + elif ui.is_waveshare_v1(): + h_pos = (0, 95) + v_pos = (170, 61) + elif ui.is_waveshare144lcd(): + h_pos = (0, 92) + v_pos = (78, 67) + elif ui.is_inky(): + h_pos = (0, 83) + v_pos = (165, 54) + elif ui.is_waveshare2in7(): + h_pos = (0, 153) + v_pos = (216, 122) + elif ui.is_waveshare1in54V2(): + h_pos = (0, 92) + v_pos = (70, 170) + else: + h_pos = (0, 91) + v_pos = (180, 61) - if self.options['orientation'] == "vertical": - ui.add_element('display-password', LabeledValue(color=BLACK, label='', value='', - position=v_pos, - label_font=fonts.Bold, text_font=fonts.Small)) - else: - # default to horizontal - ui.add_element('display-password', LabeledValue(color=BLACK, label='', value='', - position=h_pos, - label_font=fonts.Bold, text_font=fonts.Small)) + if self.options["orientation"] == "vertical": + selected_position = v_pos + else: + selected_position = h_pos + + if self.options["position"]: + try: + position_values = str(self.options["position"]).split(",") + position_x = int(position_values[0]) + position_y = int(position_values[1]) + selected_position = (position_x, position_y) + except Exception as e: + logging.error(f"Error reading configuration: {e}") + + ui.add_element( + "display-password", + LabeledValue( + color=BLACK, + label="", + value="", + position=selected_position, + label_font=fonts.Bold, + text_font=fonts.Small, + ), + ) + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") def on_unload(self, ui): - with ui._lock: - ui.remove_element('display-password') + try: + with ui._lock: + ui.remove_element("display-password") + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") def on_ui_update(self, ui): - last_line = 'tail -n 1 /root/handshakes/wpa-sec.cracked.potfile | awk -F: \'{print $3 " - " $4}\'' - ui.set('display-password', - "%s" % (os.popen(last_line).read().rstrip())) + logging.debug("[DISPLAY-PASSWORD] Actualizando UI") + try: + for file in os.listdir("/root/handshakes"): + if file.endswith(".potfile"): + with open(f"/root/handshakes/{file}", "r") as file: + lines = file.readlines() + if len(lines) > 0: + last_line = lines[-1].split(":")[2:] + last_line = ":".join(last_line) + ui.set("display-password", f"{last_line}") + except Exception as e: + logging.error(f"[DISPLAY-PASSWORD] {e}") diff --git a/display-password.toml b/display-password.toml index 2fa8d81..76e1d72 100644 --- a/display-password.toml +++ b/display-password.toml @@ -1,2 +1,3 @@ main.plugins.display-password.enabled = true -main.plugins.display-password.orientation = "horizontal" \ No newline at end of file +main.plugins.display-password.orientation = "horizontal" +main.plugins.display-password.position = "30,160" diff --git a/install.sh b/install.sh new file mode 100755 index 0000000..b134923 --- /dev/null +++ b/install.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +set -e + +CONFIG_FILE="/etc/pwnagotchi/config.toml" + +function user_sleep() { + sleep 0.5 +} + +function check_toml_key_exists() { + local key="$1" + local config_file="$2" + + if grep -q "^${key}" "$config_file"; then + echo "[ + ] The '$key' already exists on $config_file." + else + echo "[ ~ ] Creating '$key' on $config_file." + echo "${key} = true " >>"$config_file" + fi +} + +function edit_configuration_values() { + local key="$1" + local value="$2" + local config_file="$3" + + # Escape slashes and dots in the value to avoid issues with sed + value=$(echo "$value" | sed 's/\//\\\//g') + value=$(echo "$value" | sed 's/\./\\\./g') + # If the value is true, replace it with the lowercase version and without quotes + if [ "$value" = "true" ]; then + sed -i "s/^${key} = .*/${key} = ${value}/" "$config_file" + else + # Use sed to insert or replace the configuration value + sed -i "/^${key}/c ${key} = \"${value}\"" "$config_file" + fi + +} + +function modify_config_files() { + orientation="$1" + # TODO If you know a simple method to write on toml files, please submit a change + check_toml_key_exists "main.plugins.display-password.enabled" "$CONFIG_FILE" + check_toml_key_exists "main.plugins.display-password.orientation" "$CONFIG_FILE" + + # Set the configuration values + edit_configuration_values "main.plugins.display-password.enabled" true "$CONFIG_FILE" + edit_configuration_values "main.plugins.display-password.orientation" "$orientation" "$CONFIG_FILE" +} + +function get_installation_path() { + check_toml_key_exists "main.custom_plugins" "$CONFIG_FILE" + installation_dir=$(awk '/^main.custom_plugins = / {print $3}' "$CONFIG_FILE") + if [ -z "${installation_dir//\"/}" ] || [ "$installation_dir" = true ]; then + echo "[ ! ] The installation directory was not found in the configuration file" + read -r -p "Please enter the installation directory, press Enter to set '/usr/local/share/pwnagotchi/custom-plugins' or specify yours with absolute path: " installation_dir + fi + if [ -z "${installation_dir//\"/}" ]; then + installation_dir="/usr/local/share/pwnagotchi/custom-plugins" + fi + edit_configuration_values "main.custom_plugins" "${installation_dir}" "$CONFIG_FILE" + installation_dir="${installation_dir//\"/}" +} + +# Main + +# Check that the script is running as root + +if [ "$EUID" -ne 0 ]; then + echo "[ ! ] This script need to be run as root" + exit 0 +fi +echo "[ + ] Getting installation path..." +get_installation_path +echo "[ + ] Creating symbolic link to ${installation_dir}" +ln -sf "$(pwd)/display-password.py" "${installation_dir}/display-password.py" +echo "[ + ] Backing up configuration files..." +cp "${CONFIG_FILE}" "${CONFIG_FILE}.bak" +read -r -p "Do you want the horizontal or vertical orientation? [H/v] " orientation +if [ "${orientation^^}" = "V" ]; then + orientation="vertical" +else + orientation="horizontal" +fi +echo "[ ~ ] Modifying configuration files..." +modify_config_files $orientation +echo "[ * ] Done! Please restart your pwnagotchi daemon to apply changes" +echo "[ * ] You can do so with" +echo "[ > ] sudo systemctl restart pwnagotchi"