Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
2cbb09b
feat(Installation script): Simple bash script installation
nothingbutlucas Feb 8, 2024
2e58c3a
refactor(Formatting): Just simple formatting
nothingbutlucas Feb 8, 2024
0cbac58
feat(*potfile): All potfiles are welcome!
nothingbutlucas Feb 8, 2024
e2cca6e
refactor(Try, except, logs, position): Added logs, and some try excep…
nothingbutlucas Feb 10, 2024
872097e
refactor(repeated code): refactor some repeteated code
nothingbutlucas Feb 10, 2024
bc3617f
fix(Root installation): Installation script needs to be runned as root
nothingbutlucas Feb 10, 2024
74584f8
fix(installation script): Values on toml
nothingbutlucas Feb 10, 2024
0269854
fix(installation script): If the value is true, its not a string
nothingbutlucas Feb 10, 2024
20d53fe
feat(installation script): Added choose between vertical and horizontal
nothingbutlucas Feb 10, 2024
7154fb6
fix(installation script): Any case selection
nothingbutlucas Feb 10, 2024
12ee34a
feat(installation script): configurable custom plugins directory
nothingbutlucas Feb 10, 2024
6e25baf
fix(installation script): Changed default installation path
nothingbutlucas Feb 10, 2024
57205d3
fix(installation script): Remove double quotes from path
nothingbutlucas Feb 10, 2024
863d557
fix(installation script): Always remove double quotes from installati…
nothingbutlucas Feb 10, 2024
7145217
fix(installation script): Default path is with - not _
nothingbutlucas Feb 10, 2024
a52b154
feat(installation script): Add the value, key of custom plugins on co…
nothingbutlucas Feb 10, 2024
38f91ef
fix(installation script): Forgot to delete test variable jeje
nothingbutlucas Feb 10, 2024
b816934
feat(README): Added the automated installation script option.
nothingbutlucas Feb 10, 2024
1852e40
feat(config): Configurable position
nothingbutlucas Feb 27, 2024
964f23c
fix(position): Position configuration with str
nothingbutlucas Feb 27, 2024
f93ed3c
fix(position): Fix validation on position
nothingbutlucas Feb 27, 2024
c633377
fix(position): Delete de git differences
nothingbutlucas Feb 27, 2024
682686b
feat(Configurable Position): Add position on .toml
nothingbutlucas Feb 27, 2024
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
36 changes: 32 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
116 changes: 70 additions & 46 deletions display-password.py
Original file line number Diff line number Diff line change
@@ -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}")
3 changes: 2 additions & 1 deletion display-password.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
main.plugins.display-password.enabled = true
main.plugins.display-password.orientation = "horizontal"
main.plugins.display-password.orientation = "horizontal"
main.plugins.display-password.position = "30,160"
90 changes: 90 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -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"