# Pi02w, DrS nexmon, stable_baselines3, pwnagotchi # Install Raspberry Pi OS LITE 64-bit # Installed 64-bit Raspberry pi OS LITE from Raspberry Pi Imager menu # # # Linux 6.1.21-v8+ #1642 SMP PREEMPT Mon Apr 3 17:24:16 BST 2023 aarch64 GNU/Linux # # not sure if these holds are strictly necessary, but OK for now # until nexmon works on newer kernels # sudo apt-mark hold raspberrypi-kernel sudo apt install raspberrypi-kernel-headers sudo apt-mark hold raspberrypi-kernel-headers sudo apt -y update sudo apt -y upgrade # on pizeroW: # real 10m22.326s # user 4m47.330s # sys 2m49.348s # follow this to have enough swap to build bettercap # https://qengineering.eu/install-64-os-on-raspberry-pi-zero-2.html # # Not removing the old swap.. just add the big one for now.... #sudo /etc/init.d/dphys-swapfile stop #sudo apt-get -y remove --purge dphys-swapfile #sudo rm /var/swap sudo fallocate -l 4G /var/swapfile sudo chmod 600 /var/swapfile sudo mkswap /var/swapfile # start the swap service sudo swapon /var/swapfile # make the service permantent sudo bash -c 'cat >> /etc/fstab' < /tmp/dependencies << EOF time rsync vim wget screen git build-essential dkms python3-pip python3-smbus unzip gawk flex bison libopenmpi-dev libatlas-base-dev libelf-dev libopenjp2-7 libtiff5 tcpdump lsof libgstreamer1.0-0 libavcodec58 libavformat58 libswscale5 libusb-1.0-0-dev libnetfilter-queue-dev libopenmpi3 dphys-swapfile libdbus-1-dev libdbus-glib-1-dev liblapack-dev libhdf5-dev libc-ares-dev libeigen3-dev fonts-dejavu fonts-dejavu-core fonts-dejavu-extra python3-pil python3-smbus libfuse-dev libatlas-base-dev libopenblas-dev libblas-dev bc libgl1-mesa-glx libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev libffi-dev zlib1g-dev fonts-freefont-ttf fbi python3-flask python3-flask-cors python3-flaskext.wtf EOF # load them in groups of 5. quicker than individual, but doesn't fail all of them # if one goes wrong. cat /tmp/dependencies | xargs -n5 sudo apt install -y # now build libpcap, if PizeroW if [ $(uname -m) = "armv6l" ]; then cd ~/git git clone https://github.com/the-tcpdump-group/libpcap.git cd libpcap git checkout libpcap-1.9 sudo apt install flex bison ./configure make sudo make install sudo apt-mark hold libpcap-dev libpcap0.8 libpcap0.8-dev fi # RNDIS # # Skip RNDIS on pi3, pi4, others when you will use ethernet instead of # usb/otg/RNDIS to connect to a desktop computer # # Set up RNDIS (/boot/config.txt, cmdline.txt mods # # use_eem=0 lets RNDIS work properly with Macs # host_addr= and dev_adder= make it show up as the same MAC every time # instead of being a "brand new RNDIS device that needs to be configured # on the host" every reboot # # if you modify the MACs in those lines, and change the IP range, you could # have multiple RNDIS pwnies connected to the same host at the same time # # like change the host and dev macs on a second pwny, configure the host side # of "Ethernet 12" or whatever it is as 10.69.0.1 instead of 10.0.0.1, and change # /etc/network/interfaces.d/usb0-cfg on the pwny like: # # allow-hotplug usb0 # iface usb0 inet static # address 10.69.0.2 # netmask 255.255.255.0 # network 10.69.0.0 # broadcast 10.0.0.255 # gateway 10.69.0.1 # # and then (in theory) the computer should see one pwny on 10.0.0.2 and the # other on 10.69.0.2. They might not be able to see each other # sudo sh -c "echo 'dtoverlay=dwc2' >>/boot/config.txt" sudo sh -c "echo -n ' modules-load=dwc2,g_ether' >>/boot/cmdline.txt" sudo sh -c "echo -n 'options g_ether use_eem=0 host_addr=f0:0d:ba:be:f0:0d dev_addr=58:70:77:6e:79:58' >/etc/modprobe.d/g_ether.conf" sudo bash -c 'cat >> /etc/network/interfaces.d/usb0-cfg' <>~/.bashrc source ~/.bashrc else # try apt sudo apt install golang fi go version # see that it installed # Bettercap # # build latest source instead of a release cd ~/git git clone https://github.com/bettercap/bettercap.git cd bettercap time make build # real 3m44.282s # user 4m57.521s # sys 1m6.948s sudo mv bettercap /usr/bin ## install the caplets and the web ui in /usr/local/share/bettercap and quit sudo bettercap -eval "caplets.update; ui.update; quit" -iface wlan0 || exit # moved monitor mode check to after bettercap install. for some reason bettercap # now needs an UP interface specified or it won't install caplets. # so do the mon0 stuff after bettercap updates stuff, and use wlan0 # # If bettercap dies saying "Interface Not Up" change the interface above to # one that is up. Use mon0 after you run the few lines below.... # copy manu caplet over auto, so bettercap http UI is always available sudo cp /usr/local/share/bettercap/caplets/pwnagotchi-manual.cap /usr/local/share/bettercap/caplets/pwnagotchi-auto.cap # check monitor mode nexutil -V # shows installed version, or errors if default system driver sudo iw phy `iw dev wlan0 info | gawk '/wiphy/ {printf "phy" $2}'` interface add mon0 type monitor sudo ifconfig wlan0 down && sudo ifconfig mon0 up sudo tcpdump -i mon0 # see if it sees stuff, ^C to stop it # PWNGrid # # depends on libpcap versions installed above # # if built from scratch, pwngrid needs to be run with environment variable set #. LD_PRELOAD=/usr/local/lib/libpcap.so # if [ $(uname -m) = “aarch64” ]; then export PWNGRID_PKG=pwngrid_linux_aarch64_v1.10.3.zip else export PWNGRID_PKG=pwngrid_linux_armhf_v1.10.3.zip fi wget https://github.com/evilsocket/pwngrid/releases/download/v1.10.3/$PWNGRID_PKG unzip $PWNGRID_PKG sudo mv pwngrid /usr/bin/ ## generate the keypair time sudo pwngrid -generate -keys /etc/pwnagotchi # on Pi0w: # real 1m36.621s # user 1m33.891s # sys 0m1.042s # And now for something completely different... # STABLE-BASELINES3 and PYTORCH # cd ~ sudo apt install python3-pip # just in case ### install torch 64-bit binary # # On Raspberry pi, pytorch and stable_baselines3 will # install directly from default pip repository, and no longer # need the separate install, but keeping it for historical # reasons, or if you get an error at the requirements.txt step # ### sudo pip3 install torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cpu ### sudo pip install stable_baselines3 # no "[extra]" # PWNAGOTCHI ###sudo raspi-config # enable SPI interface # or run this... i think it kind of does the same thing # armbian is different. use armbian-config # if ! grep "^dtparam=spi=on" /boot/config.txt; then echo "dtparam=spi=on" | sudo tee -a /boot/config.txt sudo dtparam spi=on # enable it now, instead of a reboot. works on raspbian fi # clone your fave pwnagotchi repository # I haven't checked in the changes yet to a branch in github, so # just copy it, and apply the patches below. they probably work # on other dists, too cd ~/git git clone https://github.com/Sniffleupagus/pwnagotchi-snflpgs.git cd pwnagotchi-snflpgs # more packages needed for torch sudo apt install cpuinfo libsleef3 # # requirements.txt for torch and stable-baselines3 # # all of the versions are ">whatever" leftover version #s from # the origial. The > should install the latest versions available # cat > requirements.txt << EOF pycryptodome>=3.9.4 requests>=2.21.0 PyYAML>=5.3.1 scapy>=2.4.3 tweepy>=3.7.0 file-read-backwards>=2.0.0 inky>=1.2.0 smbus2>=0.3.0 Pillow>=5.4.1 spidev>=3.4 gast>=0.2.2 flask>=1.0.2 flask-cors>=3.0.7 flask-wtf>=0.14.3 dbus-python>=1.2.12 toml>=0.10.0 python-dateutil>=2.8.1 websockets>=8.1 gym shimmy>=0.2.1 jinja2==2.11.3 MarkupSafe==1.1.1 EOF # handful of dependencies # try installing apt-versions first for i in $(grep -v ^# requirements.txt | cut -d \> -f 1); do sudo apt -y install python3-$i; done sudo apt -y install python3-yaml python3-pil python3-flaskext.wtf python3-dbus python3-dateutil python3-pandas python3-matplotlib python3-cloudpickle python3-networkx python3-sympy python3-requests # add torch and stable-baselines3 to requirements after the apt updating to skip the old versions cat >>requirements.txt << EOF torch>=2.0.1 torchvision>=0.15.2 stable-baselines3==1.8.0 EOF # then the pip versions sudo pip install -r requirements.txt # upgrade numpy to a later version than apt installs pip install --upgrade numpy sudo ln -s `pwd`/bin/pwnagotchi /usr/local/bin sudo ln -s `pwd`/pwnagotchi /usr/local/lib/python3.9/dist-packages/pwnagotchi sudo mkdir -p /usr/local/share/pwnagotchi/custom-plugins # set up /etc/pwnagotchi/config.toml # # probably change the name, web.username, web.password # # led off, because the Led device isn't /sys/class/leds/led0, its the longer name # personality.deauth = false, because injection crashes nexmon driver # sudo bash -c 'cat > /etc/pwnagotchi/config.toml' << EOF main.name = "new_ai_CHANGEME" main.custom_plugins = "/usr/local/share/pwnagotchi/custom-plugins" main.plugins.led.enabled = false personality.deauth = false ui.display.enabled = false ui.web.username = "pwny" ui.web.password = "pwny1234" EOF # this patches default.toml to remove ai.params that are no longer used # - alpha,epsilon and lr_schedule not used in the MlpPolicy # they are leftover from MlpLstmPolicy # # deuath and advertise disabled to trigger less nexmon bugs # # generated by: # diff --git a/pwnagotchi/defaults.toml b/pwnagotchi/defaults.toml patch pwnagotchi/defaults.toml < 140 for ch in self._supported_channels) + self._extended_spectrum = any(ch > 150 for ch in self._supported_channels) self._histogram_size, self._observation_shape = featurizer.describe(self._extended_spectrum) Environment.params += [ EOP ########## end edits for gym.py ############# # system configuration from pwnagotchi sourcecode builder/data directory # # Install all of the support scripts into # /usr/bin # /etc/systemd/system # /etc/network/interfaces.d # # and probably others... # for file in `find builder/data -type f`; do dest=${file#builder/data} if [ -s $dest ]; then echo File $dest exists. Skipping else echo Copying $file to $dest sudo cp -p $file $dest fi done # enable all of the services sudo systemctl enable bettercap sudo systemctl enable pwngrid-peer sudo systemctl enable pwnagotchi echo hold onto your butts sudo sync sudo reboot