Archiv für den Monat: Juni 2018

Create additional tool (arp-scan) for LibreELEC

I wanted my Rasperry Pi 2, which was running LibreELEC, to additionally scan for specific network devices. I didn’t want to change the LibreELEC, as I was very satisfied with it. So here’s how I managed to cross-compile on my linux box the tool `arp-scan`.

1.) Get the LibreELEC.tv-Source and compile an image.

Make sure that this works before continuing with anything else. I managed to compile the 9.0-devel version.

Instructions are given on the LibreELEC-Wiki

2.) Create the arp-scan directory and the package.mk

mkdir -p packages/tools/arp-scan
cat >packages/tools/arp-scan/package.mk <<EOF
################################################################################
#      This file is part of LibreELEC - https://libreelec.tv
#      Copyright (C) 2018-present Team LibreELEC
#
#  LibreELEC is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 2 of the License, or
#  (at your option) any later version.
#
#  LibreELEC is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with LibreELEC.  If not, see <http://www.gnu.org/licenses/>.
################################################################################
 
PKG_NAME="arp-scan"
PKG_VERSION="1.9"
PKG_ARCH="arm"
PKG_LICENSE="GPL"
PKG_SITE="http://www.nta-monitor.com/wiki/index.php/Arp-scan_Installation_Guide"
PKG_URL="https://github.com/royhills/arp-scan/releases/download/$PKG_VERSION/arp-scan-$PKG_VERSION.tar.gz"
PKG_DEPENDS_TARGET="toolchain zlib libpcap"
PKG_SECTION="tools"
PKG_SHORTDESC="arp-scan"
PKG_LONGDESC="The arp-scan utility"
PKG_TOOLCHAIN="auto"
 
post_patch() {
  rm $PKG_BUILD/configure
  cd $PKG_BUILD
  autoconf
}
EOF

3.) Add needed patches

To get a patch-File from a github-commit, you can just add `.patch` to the url and you’ll get a correct patchable diff.

mkdir -p packages/tools/arp-scan/patches

I needed the change for the cross compilation, but the author hadn’t released a new version yet, so I had to download and include the patch:

wget https://github.com/royhills/arp-scan/commit/f74edaf821f49652b7649ff6113fc6685d2c952a.patch -O packages/tools/arp-scan/patches/Assume-long-long-int-format-is-lld-if-cross-compiling.patch

Sadly this won’t help with the release file, as the configure script already exists. So we have to delete the configure-File to force the package-System to run „autoconf“. That’s the reason for the `post_patch()`-Section in the package.mk.

4.) Add ourself to the dependency tree

sed -i 's/PKG_DEPENDS_TARGET="toolchain connman netbase ethtool openssh"/PKG_DEPENDS_TARGET="toolchain connman netbase ethtool openssh arp-scan"/' ./packages/virtual/network/package.mk

5.) Copy resulting file to host
In this case, we have to copy the libpcap.a and the arp-scan binary, like this:

scp build.LibreELEC-RPi2.arm-9.0-devel/libpcap-1.7.4/.armv7ve-libreelec-linux-gnueabi/libpcap.a targethost:
scp build.LibreELEC-RPi2.arm-9.0-devel/arp-scan-1.9/.armv7ve-libreelec-linux-gnueabi/arp-scan targethost:

VirtualBox on Server

I wanted to create a headless VirtualBox on a remote server. I did this before but didn’t remember the correct sequence, so I thought I’d better save the work for the next time and write my steps down:

VMNAME="newvm"
mkdir -p "/opt/VirtualBox VMs/${VMNAME}"
cd "/opt/VirtualBox VMs/${VMNAME}"
# You may have to change the next line:
wget -nc http://releases.ubuntu.com/18.04/ubuntu-18.04-desktop-amd64.iso
# Create a disk size that would fit your operation system. Here I chose 32768 MB = 32 GB.
VBoxManage createhd --filename "${VMNAME}".vdi --size 32768
# Create the VM itself. The available ostypes can be listed by issuing 'VBoxManage list ostypes'
VBoxManage createvm --name "${VMNAME}" --ostype "Ubuntu_64" --register
# Add a SATA controller with the dynamic disk attached.
VBoxManage storagectl "${VMNAME}" --name "SATA Controller ${VMNAME}" --add sata --controller IntelAHCI
VBoxManage storageattach "${VMNAME}" --storagectl "SATA Controller ${VMNAME}" --port 0 --device 0 --type hdd --medium ${VMNAME}.vdi
# Add an IDE controller with a DVD drive attached, and the install ISO inserted into the drive:
VBoxManage storagectl "${VMNAME}" --name "IDE Controller ${VMNAME}" --add ide
VBoxManage storageattach "${VMNAME}" --storagectl "IDE Controller ${VMNAME}" --port 0 --device 0 --type dvddrive --medium ubuntu-18.04-live-server-amd64.iso
# Memory and graphics settings
VBoxManage modifyvm "${VMNAME}" --memory 4096 --vram 128
# If you want the network to be nat'ed:
VBoxManage modifyvm "${VMNAME}" --nic1 nat
 
# Disable audio
VBoxManage modifyvm "${VMNAME}" --audio none
 
# Enable ssh-access
VBoxManage modifyvm "${VMNAME}" --natpf1 "guestssh,tcp,127.0.0.1,60022,,22"
# If you ever want to remove this:
# VBoxManage modifyvm "${VMNAME}" --natpf1 delete "guestssh"
 
# Enable VRDE / You need this especially for the installation process
VBoxManage modifyvm "${VMNAME}" --vrde on
VBoxManage modifyvm "${VMNAME}" --vrdeaddress 127.0.0.1
 
# Extensionpack to access via RDP etc.
wget -nc https://download.virtualbox.org/virtualbox/5.2.12/Oracle_VM_VirtualBox_Extension_Pack-5.2.12.vbox-extpack
VBoxManage extpack install Oracle_VM_VirtualBox_Extension_Pack-5.2.12.vbox-extpack
 
 
# Bootup:
VBoxHeadless -s "${VMNAME}"
# It should be available via RDP on local port 3389.
 
# Shutdown (three methods, best to worst):
# 1.) Inside of the virtualbox
# 2.) virtual powerbutton
VBoxManage controlvm "${VMNAME}" acpipowerbutton
# 3.) virtual power off
VBoxManage controlvm "${VMNAME}" poweroff
 
# If the installation is complete, shutdown the VirtualBox and eject the iso:
VBoxManage storageattach "${VMNAME}" --storagectl "IDE Controller ${VMNAME}" --port 0 --device 0 --type dvddrive --medium none

If you want to secure your virtual machine even more (after logging into another openvpn, for example), you can use ufw, but remember that the connection comes from the VirtualBox Interface:

sudo ufw allow from 10.0.2.0/24 to any

Inspired by these posts on the internet:

  • https://www.perkin.org.uk/posts/create-virtualbox-vm-from-the-command-line.html
  • https://forums.virtualbox.org/viewtopic.php?f=6&t=65975
  • https://askubuntu.com/questions/42482/how-to-safely-shutdown-guest-os-in-virtualbox-using-command-line
  • http://arunnsblog.com/2010/07/20/nat-with-port-forwarding-for-virtual-box/
  • https://www.reddit.com/r/virtualbox/comments/5lze8p/remove_sound_card_with_vboxmanage/