Package: dawgmon
dawgmon - Dawg the Hallway MonitorSUMMARYThe name of this tool is based upon an episode (season 10, episode 10) of SouthPark in which Cartman is Dawg the Hallway Monitor patrolling the hallways ofhis school.  It's a tool which helps one to monitor changes which have takenplace on a Linux-based system since the previous time the tool was ran.One way to use it is to use something like the included sample cronjob to rundawgmon on a regular interval and email the results to the systemadministrator. This can help with identifying machines upon which nefariousthings are happening and monitor who's installing what and where. Please notethat any serious kernel backdoor will easily be able to hide itself from thistool and as such it's just one added tool in one's toolkit but it should notrelied upon for full security monitoring of Linux machines. It's just one extraoption in one's toolbox.The other way it's useful is by generating a baseline before installing a pieceof software. Then after installing this piece of software one will run the toolagain and then it's easy to see which changes were made on the system. Anexample after establishing a baseline and then installing virtualbox on amachine might yield something like this:# ./dawgmon -gfA1 change detected (0 warnings)+ systemd property NNames changed from 259 to 261# apt install virtualbox-5.1[...]# ./dawgmon -gfA33 changes detected (0 warnings)+ size of file /etc/group changed from 937 to 954+ file /etc/group got modified on 2017-09-14 19:29:51.804811 +0200+ size of file /etc/group- changed from 934 to 937+ file /etc/group- got modified on 2017-09-14 19:29:14.000000 +0200+ file /etc/gshadow got modified on 2017-09-14 19:29:51.812811 +0200+ size of file /etc/gshadow- changed from 777 to 794+ size of file /etc/mailcap changed from 40777 to 41063+ file /etc/mailcap got modified on 2017-09-14 19:29:51.632812 +0200+ file /etc/systemd/system/multi-user.target.wants/vboxautostart-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=49)+ file /etc/systemd/system/multi-user.target.wants/vboxballoonctrl-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=51)+ file /etc/systemd/system/multi-user.target.wants/vboxdrv.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=35)+ file /etc/systemd/system/multi-user.target.wants/vboxweb-service.service got created (owner=root, group=root, perm=lrwxrwxrwx, size=43)+ file /etc/udev/rules.d/60-vboxdrv.rules got created (owner=root, group=root, perm=-rw-r--r--, size=747)+ group vboxusers added+ package virtualbox-5.1 is to be installed+ suid binary /usr/lib/virtualbox/VBoxHeadless got created (owner=root, group=root, perm=-r-s--x--x, size=158304)+ suid binary /usr/lib/virtualbox/VBoxNetAdpCtl got created (owner=root, group=root, perm=-r-s--x--x, size=23144)+ suid binary /usr/lib/virtualbox/VBoxNetDHCP got created (owner=root, group=root, perm=-r-s--x--x, size=158304)+ suid binary /usr/lib/virtualbox/VBoxNetNAT got created (owner=root, group=root, perm=-r-s--x--x, size=158304)+ suid binary /usr/lib/virtualbox/VBoxSDL got created (owner=root, group=root, perm=-r-s--x--x, size=158296)+ suid binary /usr/lib/virtualbox/VBoxVolInfo got created (owner=root, group=root, perm=-r-s--x--x, size=10472)+ suid binary /usr/lib/virtualbox/VirtualBox got created (owner=root, group=root, perm=-r-s--x--x, size=158304)+ i-node for listening UNIX socket /run/systemd/private changed from 3428734 to 3452848+ systemd property NInstalledJobs changed from 8392199 to 3238035463+ systemd property NNames changed from 261 to 263+ systemd unit file vboxautostart-service.service added+ systemd unit file vboxballoonctrl-service.service added+ systemd unit file vboxdrv.service added+ systemd unit file vboxweb-service.service added+ systemd unit 'vboxautostart-service.service' added+ systemd unit 'vboxballoonctrl-service.service' added+ systemd unit 'vboxdrv.service' added+ systemd unit 'vboxweb-service.service' addedThe above helps with now doing a thorough security review of virtualbox. Theinstalled suid binaries are obvious points of entry and the run services areinteresting.Another example run which correctly detects TCP ports opening and closing:# ./dawgmon -gfA0 changes detected (0 warnings)# nc -l -p 4455 &[1] 12489# ./dawgmon -gfA1 change detected (0 warnings)+ port 4455 tcp opened# fgnc -l -p 4455^C# ./dawgmon -gfA1 change detected (0 warnings)+ port 4455 tcp closed#The tool is not meant for complete accuracy. There are very seriousrecommendations normally to not rely on the output of GNU core-utils such as lsfor tool input. In other words; one should rarely build tools to parse and relyon this type of output as it can change all the time. Realistically the outputof these tools is relatively stable as a lot of people and automatic toolsalready rely on their outputs for all kinds of purposes.However the tradeoff for dawgmon is the following; we would need to implement alot of logic to do file system monitoring ourselves, build complex binariesthat include libraries to do the parsing and monitoring of block devices, thenetwork interfaces and what not more. This will also make the tool way morecomplex and less maintainable. On projects right now one can add a new commandincluding change detection in very little time as the main dawgmon tool alreadytakes care of caching, executing the command and then supplying the previousand current output when running a comparision to a command implementation. Thismeans that on time-constrained projects one can very quickly add a new commandand run analysises including those new commands.A command can be added by simply inheriting from the Command class. This classis defined in commands/__init__.py. That file contains also the master list ofcommands (and the order in which they're executed when doing a full analysis).Then the properties like 'name', 'shell', 'command' and 'desc' will have to beset and two methods 'parse()' and 'compare()' will have to be implemented.Enough commands are included to get a good idea on how to implement and add newones.USAGEFor best results run the tool as root. For help type -h/--help and for versioninformation type -v/--version.A main action will always have to be specified. These actions are:-A: analyze the system-C: compare cache entries-E: list available commands-L: list cache entries# runs an analysisdawgmon -A# runs an analysis but only with a few commandsdawgmon -A -e list_suids -e list_tcpudp_ports# shows the list of available commandsdawgmon -E# shows available cache entries for comparisondawgmon -L# compare old cache entry 3 with new cache entry 5dawgmon -C 3 5Further options to help with the analysis are:-d: show debug output-e: execute a specific command (can be used multiple times)-f: force a run without warning about running as root-g: colorize the output-l: location of the database cache to use-m: maximum amount of cache entries to allow in cache (if cache has moreentries than this amount it will truncate the database)-t: do not output timestamp information per detected anomaly.For more usage information run the tool with -h.LIMITATIONSThe tool parses output of commandline tools and relies on GNU core-utilsspecific options for some of it.  There's no specific reason why this tool andthe command implementations cannot be quickly ported to other operating systemssuch as the BSD's but right now no Operating System detection is taking placenor is there a classification of commands based on Operating System supportbeing done. That would have to be implemented first.Regarding the finding of pipes, UNIX sockets, files in /boot, /etc and more oneshould note that the usage of -xdev passed to 'find' means that not allfilesystems mounted under the start directory will be traversed. This meansthat for example /boot will be properly scanned but /boot/efi might not be.Some smarter approach will have to be used here in the future.The timestamps when doing a current analysis might be a bit confusing. Bydefault a timestamp for a warning, normal or debug anomaly message will be thetimestamp of its generation time (as can be seen in commands/__init__.py). Theanomalies are generated after a full commandline scan has been done. So theoutput upon which this detection works was generated earlier and subsequentlythe timestamps for individual anomalies show a time after the time of the scan.When comparing cache entries the timestamp of the scan is being used to outputthe time at which the detection happend as that makes logically simply moresense.ABOUTAll rights reserved. Copyright (C) 2017-2019 by Anvil Ventures Inc.For licensing information see LICENSE.For more information contact Vincent Berg <gvb@anvilventures.com>To find updated source code or to contribute patches go to the following URL:https://github.com/anvilventures/dawgmon/