Sunday, April 29, 2018

systemd and rc.local

Once again while in systemd land I discovered something, how to re-re-enable rc.local. Granted, from what I’ve read rc.local should really go the way of the dodo but I don’t feel like writing the new systemd stuff.

Link here.

To summarize it up:

The solution 

As you can see from above, The unit file have no [Install] section. As such Systemd can not enable it. First we need to create a file:

sudo vi /etc/systemd/system/rc-local.service

Then add the following content to it.

[Unit]
Description=/etc/rc.local Compatibility
ConditionPathExists=/etc/rc.local

[Service]
Type=forking
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

[Install]
WantedBy=multi-user.target

Save and close the file. Make sure /etc/rc.local file is executable.

sudo chmod +x /etc/rc.local

After that, enable the service on system boot:

sudo systemctl enable rc-local

Output:

Created symlink from /etc/systemd/system/multi-user.target.wants/rc-local.service to /etc/systemd/system/rc-local.service.

Now start the service and check its status:

sudo systemctl start rc-local.service
sudo systemctl status rc-local.service

Kali default runlevel

As I’m customizing the Kali image for my pen bot I once again came across the hell that is systemd, what would have been rc.local is now of course a steaming pile of systemd stuff. The same goes for the default run level since init is now a thing of the past, this Stack Exchange answer was helpful. You can no longer just set the initdefault level in /etc/inittab.

Debian as-shipped boots towards the graphical target. You can see this yourself:
$ ls -l /etc/systemd/system/default.target...No such file or directory
$ ls -l /lib/systemd/system/default.target... /lib/systemd/system/default.target -> graphical.target

So to boot towards the multiuser target all you need do is to put in own target:
$ cd /etc/systemd/system/
$ sudo ln -s /lib/systemd/system/multi-user.target default.target


It is highly recommended not to mess with the manual symlink-ing, but rather use appropriate options of the systemctl command. In this case, to set the default target you should run:
# systemctl set-default multi-user.target

Saturday, April 28, 2018

OpenVPN server on a Raspberry Pi

I am in the middle of configuring a Raspberry Pi 3 to act as an OpenVPN server for my remote pen test bots to use as Command and Control (C2). Ultimately C2 will run in AWS but for now I'm prototyping at home using my crappy Comcast connection. The first issue to get around is the lack of a static IP for the clients to connect to so I'm setting up NoIP as the dynamic DNS for this, here's what I've done.

Step one, go to www.no-ip.com and create a free account. Once that’s done create a hostname for your dynamic connection.

Step two, obtain and install the No-Ip Linux client on the Pi like this:

cd /usr/local/src/
wget http://www.no-ip.com/client/linux/noip-duc-linux.tar.gz
tar xvf noip-duc-linux.tar.gz
cd noip-2.1.9.1/
make install

This leaves /usr/local/bin/noip2 in place, run it and you will be prompted to enter the username/password for the noip account created in step 1, this will create /usr/local/etc/no-ip2.conf

Step three, create an init script. Edit a file /etc/init.d/noip2 and add the following contents to it:

#!/bin/sh
# /etc/init.d/noip2

# Supplied by no-ip.com
# Modified for Debian GNU/Linux by Eivind L. Rygge <eivind@rygge.org>
# Updated by David Courtney to not use pidfile 130130 for Debian 6.
# Updated again by David Courtney to "LSBize" the script for Debian 7.

### BEGIN INIT INFO
# Provides: noip2
# Required-Start: networking
# Required-Stop:
# Should-Start:
# Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start noip2 at boot time
# Description: Start noip2 at boot time
### END INIT INFO

# . /etc/rc.d/init.d/functions # uncomment/modify for your killproc

DAEMON=/usr/local/bin/noip2
NAME=noip2

test -x $DAEMON || exit 0

case "$1" in
start)
echo -n "Starting dynamic address update: "
start-stop-daemon --start --exec $DAEMON
echo "noip2."
;;
stop)
echo -n "Shutting down dynamic address update:"
start-stop-daemon --stop --oknodo --retry 30 --exec $DAEMON
echo "noip2."
;;

restart)
echo -n "Restarting dynamic address update: "
start-stop-daemon --stop --oknodo --retry 30 --exec $DAEMON
start-stop-daemon --start --exec $DAEMON
echo "noip2."
;;

*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac
exit 0

Install it to run at startup using the command: update-rc.d noip2 defaults the run it via service noip2 start. You can check it via the command service noip2 status, you should be good to go.

Friday, January 12, 2018

Kali Pi Linux plus Mana

One to try:

https://dantheiotman.com/2017/11/21/using-re4sons-kali-pi-the-mana-toolkit-on-a-raspberry-pi-3/

malDuino

Another interesting bad USB key:

https://shop.malduino.com/

Thursday, January 4, 2018

Raspberry Pi Pentest

I've been in the process of building out a Raspberry Pi 3 with Kali ARM Linux that can run some of the Kali included security tools, namely OpenVAS and Metasploit. After getting it installed, which I'll document more when it's ready, I got OpenVAS working but when I ran Metasploit I received the following:

       =[ metasploit v4.16.28-dev                         ]
+ -- --=[ 1715 exploits - 984 auxiliary - 300 post        ]
+ -- --=[ 507 payloads - 40 encoders - 10 nops            ]
+ -- --=[ Free Metasploit Pro trial: http://r-7.co/trymsp ]

/usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``': Cannot allocate memory - infocmp (Errno::ENOMEM)
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/activesupport-4.2.10/lib/active_support/core_ext/kernel/agnostics.rb:7:in ``'
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:1815:in `get_term_capabilities'
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:2027:in `_rl_init_terminal_io'
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:2564:in `readline_initialize_everything'
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:3849:in `rl_initialize'
from /usr/share/metasploit-framework/vendor/bundle/ruby/2.3.0/gems/rb-readline-0.5.5/lib/rbreadline.rb:4868:in `readline'
from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:162:in `readline_with_output'
from /usr/share/metasploit-framework/lib/rex/ui/text/input/readline.rb:100:in `pgets'
from /usr/share/metasploit-framework/lib/rex/ui/text/shell.rb:189:in `run'
from /usr/share/metasploit-framework/lib/metasploit/framework/command/console.rb:48:in `start'
from /usr/share/metasploit-framework/lib/metasploit/framework/command/base.rb:82:in `start'
from /usr/bin/msfconsole:48:in `<main>'

The Raspberry Pi 3 only has 1GB of RAM and around 750MB of it was being used by the OS and OpenVAS, Metasploit couldn't get enough. I'm considering moving to an ODROID-C2 that has 2GB of RAM but that would require a new Kali image. While watching htop as msfconsole fired up I noticed that the Kali ARM dist doesn't have a swap partition or file so there's no swap space.

You can see this by running the 'free' command:

root@pi2222:/home/support# free
              total        used        free      shared  buff/cache   available
Mem:         949568      470544       68604       42588      410420      420912
Swap:             0           0           0

Run the following to create a 1GB swap file in /var and add it to the OS. Increase the dd command to 2000 to make it a 2GB file.

root@pi2222:~# cd /var
root@pi2222:/var# ls
backups  cache lib  local  lock  log  mail  opt  run  spool  tmp  www
root@pi2222:/var# touch swap.img
root@pi2222:/var# chmod 600 swap.img
root@pi2222:/var# dd if=/dev/zero of=/var/swap.img bs=1024k count=1000
1000+0 records in
1000+0 records out
1048576000 bytes (1.0 GB, 1000 MiB) copied, 94.6194 s, 11.1 MB/s
root@pi2222:/var# mkswap /var/swap.img
Setting up swapspace version 1, size = 1000 MiB (1048571904 bytes)
no label, UUID=91f5050f-ca7e-4fe8-9fc5-21ac5aecb478
root@pi2222:/var# swapon /var/swap.img

Now we have swap space:

root@pi2222:/var# free
              total        used        free      shared  buff/cache   available
Mem:         949568      468852       11584       42588      469132      422628
Swap:       1023996           0     1023996

Now msfconsole works, albeit a little slowly, so we'll see how it goes. I might just try an ODROID-C2 to see how it works, it has more cores and is 64-bit as well but is also double the cost of a Raspberry Pi 3.

Special thanks to this page for guidance on how to do this: https://www.optiv.com/blog/create-a-budget-friendly-virtual-private-server-with-a-metasploit-instance

Wednesday, January 3, 2018

Current Audible Reading List

Title You Never Forget Your First: A Biography of George Washington A Self-Made Man: The Politica...