From 0d2948b660efe64d9bb5ef32257eb3883a3c1c33 Mon Sep 17 00:00:00 2001 From: Moritz Warning Date: Thu, 17 May 2018 23:44:10 +0200 Subject: [PATCH] device-observatory: add new package Shows network/wireless activity on a local website to increase awareness for privacy and security matters. Signed-off-by: Moritz Warning --- utils/device-observatory/Makefile | 36 ++++++++++ .../files/etc/config/device-observatory | 26 ++++++++ .../files/etc/init.d/device-observatory | 66 +++++++++++++++++++ 3 files changed, 128 insertions(+) create mode 100644 utils/device-observatory/Makefile create mode 100644 utils/device-observatory/files/etc/config/device-observatory create mode 100755 utils/device-observatory/files/etc/init.d/device-observatory diff --git a/utils/device-observatory/Makefile b/utils/device-observatory/Makefile new file mode 100644 index 000000000..8f0103ce7 --- /dev/null +++ b/utils/device-observatory/Makefile @@ -0,0 +1,36 @@ +include $(TOPDIR)/rules.mk + +PKG_NAME:=device-observatory +PKG_VERSION:=1.2.0 +PKG_RELEASE:=1 + +PKG_LICENSE:=GPL-3.0+ + +PKG_SOURCE_URL:=https://codeload.github.com/mwarning/device-observatory/tar.gz/v$(PKG_VERSION)? +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.gz +PKG_HASH:=83b3f362f154a427abbd3af31b3c2dda9983cdc15f6b833d804727ef0fbdc72e + +include $(INCLUDE_DIR)/package.mk + +define Package/device-observatory + SECTION:=utils + CATEGORY:=Utilities + TITLE:=device-observatory + MAINTAINER:=Moritz Warning + URL:=https://github.com/mwarning/device-observatory/ + DEPENDS:=+iw +libpcap +libmicrohttpd-no-ssl +endef + +define Package/device-observatory/description + Show information about connected devices and connections to increase security awareness. +endef + +define Package/device-observatory/install + $(CP) files/* $(1) + $(INSTALL_DIR) $(1)/usr/bin + $(INSTALL_BIN) $(PKG_BUILD_DIR)/device-observatory $(1)/usr/bin/ + $(INSTALL_DIR) $(1)/usr/share/device-observatory + $(INSTALL_DATA) $(PKG_BUILD_DIR)/misc/macdb.txt $(1)/usr/share/device-observatory/macdb.txt +endef + +$(eval $(call BuildPackage,device-observatory)) diff --git a/utils/device-observatory/files/etc/config/device-observatory b/utils/device-observatory/files/etc/config/device-observatory new file mode 100644 index 000000000..b3d80c099 --- /dev/null +++ b/utils/device-observatory/files/etc/config/device-observatory @@ -0,0 +1,26 @@ + +config setup + list dev 'wlan0' + list mdev 'mon0' + + option mac_db '/usr/share/device-observatory/macdb.txt' + option port_db '/etc/services' + + # Optional JSON output into file +# option json_output '/tmp/device-observatory.json' + + # Time after which a device is removed from the record + option device_timeout 3600 + + # Create monitoring interface mon0 based on physical interface wifi phy0. + # See 'iw dev' output for a list of interfaces. + list create_monitor 'mon0' + + # Track router itself as device + option track_localhost 0 + + # Set to 0 to disable webserver + option webserver_port 8080 + + # Not needed, all necessary files are included +# option webserver_path '/www' diff --git a/utils/device-observatory/files/etc/init.d/device-observatory b/utils/device-observatory/files/etc/init.d/device-observatory new file mode 100755 index 000000000..1405e363f --- /dev/null +++ b/utils/device-observatory/files/etc/init.d/device-observatory @@ -0,0 +1,66 @@ +#!/bin/sh /etc/rc.common + +START=90 +USE_PROCD=1 +PROG=/usr/bin/device-observatory +OPTS="" + + +boot() { + local dev="$(uci get -q device-observatory.@setup[0].dev | cut -d ' ' -f 1)" + + # Wait for interface to be up + ubus -t 15 wait_for network.interface network.${dev:-localhost} 2>/dev/null + rc_procd start_service +} + +xappend() { + local name="$2" value="$1" + OPTS="$OPTS --${name//_/-} ${value//'/\\'}" +} + +append_opts() { + local name value cfg="$1"; shift + for name in $*; do + config_get value "$cfg" "$name" + [ -n "$value" ] && xappend "$value" "$name" + done +} + +append_opts_list() { + local name cfg="$1"; shift + for name in $*; do + config_list_foreach "$cfg" "$name" xappend "$name" + done +} + +create_monitor_interface() { + local ifce="$1" n=$(echo -n "$1" | tail -c 1) + + if [ ! -d "/sys/class/net/$ifce/" ]; then + iw phy "phy$n" interface add "$ifce" type monitor + ip link set dev "$ifce" up + fi +} + +start_instance() { + local cfg="$1" + + OPTS="" + + config_list_foreach "$cfg" "create_monitor" create_monitor_interface "create_monitor" + + append_opts_list "$cfg" dev mdev + append_opts "$cfg" mac_db port_db json_output device_timeout webserver_port webserver_path track_localhost + + procd_open_instance + procd_set_param command $PROG $OPTS + procd_set_param stderr 1 + procd_set_param stdout 0 + procd_close_instance +} + +start_service() { + config_load 'device-observatory' + config_foreach start_instance 'setup' +}