From be414e57b308565b47a40a76d92fbb1a4b5e426c Mon Sep 17 00:00:00 2001 From: Simone Margaritelli Date: Wed, 30 Oct 2019 19:24:12 +0100 Subject: [PATCH] fix: builder now uses files provisioners and auto-update installs project data (ref #470) --- .../data/etc/systemd/system/bettercap.service | 14 ++ .../etc/systemd/system/pwnagotchi.service | 15 ++ .../etc/systemd/system/pwngrid-peer.service | 15 ++ builder/data/usr/bin/bettercap-launcher | 12 ++ builder/data/usr/bin/bootblink | 10 ++ builder/data/usr/bin/monstart | 2 + builder/data/usr/bin/monstop | 2 + builder/data/usr/bin/pwnagotchi-launcher | 15 ++ builder/pwnagotchi.json | 60 ++++++-- builder/pwnagotchi.yml | 138 +----------------- pwnagotchi/plugins/default/auto-update.py | 12 ++ 11 files changed, 149 insertions(+), 146 deletions(-) create mode 100644 builder/data/etc/systemd/system/bettercap.service create mode 100644 builder/data/etc/systemd/system/pwnagotchi.service create mode 100644 builder/data/etc/systemd/system/pwngrid-peer.service create mode 100755 builder/data/usr/bin/bettercap-launcher create mode 100755 builder/data/usr/bin/bootblink create mode 100755 builder/data/usr/bin/monstart create mode 100755 builder/data/usr/bin/monstop create mode 100755 builder/data/usr/bin/pwnagotchi-launcher diff --git a/builder/data/etc/systemd/system/bettercap.service b/builder/data/etc/systemd/system/bettercap.service new file mode 100644 index 0000000..1ba1fc6 --- /dev/null +++ b/builder/data/etc/systemd/system/bettercap.service @@ -0,0 +1,14 @@ +[Unit] +Description=bettercap api.rest service. +Documentation=https://bettercap.org +Wants=network.target + +[Service] +Type=simple +PermissionsStartOnly=true +ExecStart=/usr/bin/bettercap-launcher +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/builder/data/etc/systemd/system/pwnagotchi.service b/builder/data/etc/systemd/system/pwnagotchi.service new file mode 100644 index 0000000..c0071f3 --- /dev/null +++ b/builder/data/etc/systemd/system/pwnagotchi.service @@ -0,0 +1,15 @@ +[Unit] +Description=pwnagotchi Deep Reinforcement Learning instrumenting bettercap for WiFI pwning. +Documentation=https://pwnagotchi.ai +Wants=network.target +After=pwngrid-peer.service + +[Service] +Type=simple +PermissionsStartOnly=true +ExecStart=/usr/bin/pwnagotchi-launcher +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/builder/data/etc/systemd/system/pwngrid-peer.service b/builder/data/etc/systemd/system/pwngrid-peer.service new file mode 100644 index 0000000..76ad4b6 --- /dev/null +++ b/builder/data/etc/systemd/system/pwngrid-peer.service @@ -0,0 +1,15 @@ +[Unit] +Description=pwngrid peer service. +Documentation=https://pwnagotchi.ai +Wants=network.target +After=bettercap.service + +[Service] +Type=simple +PermissionsStartOnly=true +ExecStart=/usr/bin/pwngrid -keys /etc/pwnagotchi -address 127.0.0.1:8666 -client-token /root/.api-enrollment.json -wait -log /var/log/pwngrid-peer.log -iface mon0 +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target \ No newline at end of file diff --git a/builder/data/usr/bin/bettercap-launcher b/builder/data/usr/bin/bettercap-launcher new file mode 100755 index 0000000..29be33e --- /dev/null +++ b/builder/data/usr/bin/bettercap-launcher @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +/usr/bin/monstart +if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then + # if override file exists, go into auto mode + if [ -f /root/.pwnagotchi-auto ]; then + /usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0 + else + /usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0 + fi +else + /usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0 +fi diff --git a/builder/data/usr/bin/bootblink b/builder/data/usr/bin/bootblink new file mode 100755 index 0000000..7a3bbfd --- /dev/null +++ b/builder/data/usr/bin/bootblink @@ -0,0 +1,10 @@ +#!/usr/bin/env bash +for i in $(seq 1 "$1"); +do +echo 0 >/sys/class/leds/led0/brightness +sleep 0.3 +echo 1 >/sys/class/leds/led0/brightness +sleep 0.3 +done +echo 0 >/sys/class/leds/led0/brightness +sleep 0.3 \ No newline at end of file diff --git a/builder/data/usr/bin/monstart b/builder/data/usr/bin/monstart new file mode 100755 index 0000000..db86e4e --- /dev/null +++ b/builder/data/usr/bin/monstart @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up \ No newline at end of file diff --git a/builder/data/usr/bin/monstop b/builder/data/usr/bin/monstop new file mode 100755 index 0000000..f98cd2d --- /dev/null +++ b/builder/data/usr/bin/monstop @@ -0,0 +1,2 @@ +#!/usr/bin/env bash +ifconfig mon0 down && iw dev mon0 del \ No newline at end of file diff --git a/builder/data/usr/bin/pwnagotchi-launcher b/builder/data/usr/bin/pwnagotchi-launcher new file mode 100755 index 0000000..8042e9b --- /dev/null +++ b/builder/data/usr/bin/pwnagotchi-launcher @@ -0,0 +1,15 @@ +#!/usr/bin/env bash +# blink 10 times to signal ready state +/usr/bin/bootblink 10 & +# start a detached screen session with bettercap +if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then + # if override file exists, go into auto mode + if [ -f /root/.pwnagotchi-auto ]; then + rm /root/.pwnagotchi-auto + /usr/local/bin/pwnagotchi + else + /usr/local/bin/pwnagotchi --manual + fi +else + /usr/local/bin/pwnagotchi +fi \ No newline at end of file diff --git a/builder/pwnagotchi.json b/builder/pwnagotchi.json index d7ec0ca..ec08b60 100644 --- a/builder/pwnagotchi.json +++ b/builder/pwnagotchi.json @@ -1,12 +1,14 @@ { - "builders": [{ - "name": "pwnagotchi", - "type": "arm-image", - "iso_url" : "https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-07-12/2019-07-10-raspbian-buster-lite.zip", - "iso_checksum_type":"sha256", - "iso_checksum":"9e5cf24ce483bb96e7736ea75ca422e3560e7b455eee63dd28f66fa1825db70e", - "last_partition_extra_size" : 3221225472 - }], + "builders": [ + { + "name": "pwnagotchi", + "type": "arm-image", + "iso_url": "https://downloads.raspberrypi.org/raspbian_lite/images/raspbian_lite-2019-07-12/2019-07-10-raspbian-buster-lite.zip", + "iso_checksum_type": "sha256", + "iso_checksum": "9e5cf24ce483bb96e7736ea75ca422e3560e7b455eee63dd28f66fa1825db70e", + "last_partition_extra_size": 3221225472 + } + ], "provisioners": [ { "type": "shell", @@ -18,7 +20,7 @@ ] }, { - "type":"ansible-local", + "type": "ansible-local", "playbook_file": "pwnagotchi.yml", "command": "ANSIBLE_FORCE_COLOR=1 PYTHONUNBUFFERED=1 PWN_VERSION={{user `pwn_version`}} PWN_HOSTNAME={{user `pwn_hostname`}} ansible-playbook" }, @@ -27,6 +29,46 @@ "inline": [ "sed -i 's/^#\\(.+\\)/\\1/g' /etc/ld.so.preload" ] + }, + { + "type": "file", + "source": "data/usr/bin/bettercap-launcher", + "destination": "/usr/bin/bettercap-launcher" + }, + { + "type": "file", + "source": "data/usr/bin/pwnagotchi-launcher", + "destination": "/usr/bin/pwnagotchi-launcher" + }, + { + "type": "file", + "source": "data/usr/bin/monstop", + "destination": "/usr/bin/monstop" + }, + { + "type": "file", + "source": "data/usr/bin/bootblink", + "destination": "/usr/bin/bootblink" + }, + { + "type": "file", + "source": "data/usr/bin/monstart", + "destination": "/usr/bin/monstart" + }, + { + "type": "file", + "source": "data/etc/systemd/system/pwngrid-peer.service", + "destination": "/etc/systemd/system/pwngrid-peer.service" + }, + { + "type": "file", + "source": "data/etc/systemd/system/pwnagotchi.service", + "destination": "/etc/systemd/system/pwnagotchi.service" + }, + { + "type": "file", + "source": "data/etc/systemd/system/bettercap.service", + "destination": "/etc/systemd/system/bettercap.service" } ] } diff --git a/builder/pwnagotchi.yml b/builder/pwnagotchi.yml index 31dd7e9..41d2c30 100644 --- a/builder/pwnagotchi.yml +++ b/builder/pwnagotchi.yml @@ -279,77 +279,6 @@ remote_src: yes mode: 0755 - - name: create bootblink script - copy: - dest: /usr/bin/bootblink - mode: 0755 - content: | - #!/usr/bin/env bash - for i in $(seq 1 "$1"); - do - echo 0 >/sys/class/leds/led0/brightness - sleep 0.3 - echo 1 >/sys/class/leds/led0/brightness - sleep 0.3 - done - echo 0 >/sys/class/leds/led0/brightness - sleep 0.3 - - - name: create pwnagotchi-launcher script - copy: - dest: /usr/bin/pwnagotchi-launcher - mode: 0755 - content: | - #!/usr/bin/env bash - # blink 10 times to signal ready state - /usr/bin/bootblink 10 & - # start a detached screen session with bettercap - if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then - # if override file exists, go into auto mode - if [ -f /root/.pwnagotchi-auto ]; then - rm /root/.pwnagotchi-auto - /usr/local/bin/pwnagotchi - else - /usr/local/bin/pwnagotchi --manual - fi - else - /usr/local/bin/pwnagotchi - fi - - - name: create bettercap-launcher script - copy: - dest: /usr/bin/bettercap-launcher - mode: 0755 - content: | - #!/usr/bin/env bash - /usr/bin/monstart - if [[ $(ifconfig | grep usb0 | grep RUNNING) ]] || [[ !$(grep '1' /sys/class/net/eth0/carrier) ]]; then - # if override file exists, go into auto mode - if [ -f /root/.pwnagotchi-auto ]; then - /usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0 - else - /usr/bin/bettercap -no-colors -caplet pwnagotchi-manual -iface mon0 - fi - else - /usr/bin/bettercap -no-colors -caplet pwnagotchi-auto -iface mon0 - fi - - - name: create monstart script - copy: - dest: /usr/bin/monstart - mode: 0755 - content: | - #!/usr/bin/env bash - iw phy phy0 interface add mon0 type monitor && ifconfig mon0 up - - - name: create monstop script - copy: - dest: /usr/bin/monstop - mode: 0755 - content: | - #!/usr/bin/env bash - ifconfig mon0 down && iw dev mon0 del - - name: create hdmion script copy: dest: /usr/bin/hdmion @@ -471,7 +400,7 @@ copy: dest: /etc/motd content: | - (◕‿‿◕) {{pwnagotchi.hostname}} (pwnagotchi-{{pwnagotchi.version}}) + (◕‿‿◕) {{pwnagotchi.hostname}} Hi! I'm a pwnagotchi, please take good care of me! Here are some basic things you need to know to raise me properly! @@ -507,71 +436,6 @@ apt: autoremove: yes - - name: add pwngrid-peer service to systemd - copy: - dest: /etc/systemd/system/pwngrid-peer.service - content: | - [Unit] - Description=pwngrid peer service. - Documentation=https://pwnagotchi.ai - Wants=network.target - - [Service] - Type=simple - PermissionsStartOnly=true - ExecStart=/usr/bin/pwngrid -keys /etc/pwnagotchi -address 127.0.0.1:8666 -client-token /root/.api-enrollment.json -wait -log /var/log/pwngrid-peer.log -iface mon0 - Restart=always - RestartSec=30 - - [Install] - WantedBy=multi-user.target - notify: - - reload systemd services - - - name: add bettercap service to systemd - copy: - dest: /etc/systemd/system/bettercap.service - content: | - [Unit] - Description=bettercap api.rest service. - Documentation=https://bettercap.org - Wants=network.target - After=pwngrid.service - - [Service] - Type=simple - PermissionsStartOnly=true - ExecStart=/usr/bin/bettercap-launcher - Restart=always - RestartSec=30 - - [Install] - WantedBy=multi-user.target - notify: - - reload systemd services - - - name: add pwnagotchi service to systemd - copy: - dest: /etc/systemd/system/pwnagotchi.service - content: | - [Unit] - Description=pwnagotchi Deep Reinforcement Learning instrumenting bettercap for WiFI pwning. - Documentation=https://pwnagotchi.ai - Wants=network.target - After=bettercap.service - - [Service] - Type=simple - PermissionsStartOnly=true - ExecStart=/usr/bin/pwnagotchi-launcher - Restart=always - RestartSec=30 - - [Install] - WantedBy=multi-user.target - notify: - - reload systemd services - - name: enable services systemd: name: "{{ item }}" diff --git a/pwnagotchi/plugins/default/auto-update.py b/pwnagotchi/plugins/default/auto-update.py index e31210a..ba7f55c 100644 --- a/pwnagotchi/plugins/default/auto-update.py +++ b/pwnagotchi/plugins/default/auto-update.py @@ -145,6 +145,18 @@ def install(display, update): os.system("cd %s && pip3 install ." % source_path) + data_path = os.path.join(source_path, "builder/data") + for source in glob.glob("%s/**" % data_path, recursive=True): + if os.path.isfile(source): + dest = source.replace(data_path, '') + dest_path = os.path.dirname(dest) + if not os.path.isdir(dest_path): + os.makedirs(dest_path) + logging.info("[update] installing %s to %s ..." % (source, dest)) + os.system("mv '%s' '%s'" % (source, dest)) + + os.system("systemctl daemon-reload") + return True