Skip to content

Commit

Permalink
Added mtr-packet subprocess
Browse files Browse the repository at this point in the history
The mtr-packet tool isolates the raw socket sending/receiving of
packets from the mtr user interface.  By isolating the socket
interactions to a separate process, we can be sure that any security
flaws in the user-interface code doesn't expose a raw socket
interface to an attacker attempting to escalate privileges.

This is a bare-bones implementation, only support ICMP,
only support IP version 4, and missing many of the probe customization
features available in mtr.  It will require some more work to reach
feature parity with the current mtr implementation.  But it's a start.

The include mtr-packet man page explains the protocol format
used to communicate with this new process.

Included is an automated test for mtr-packet, implemented using
Python's unittest module.  Though the code actually being tested
is implemented in C, Python make it easy to write test cases.
'make check' will test the current build.

An alternate code-path for Windows is included in the mtr-packet
tool.  The mechanism for sending and receiving network probes
is significantly different for Windows, as compared to Unix-like
operating systems, but the interface provided by mtr-packet is
the same.  'make dist-windows-bin' will make a Windows binary
distribution.  A Cygwin build environment is required, but the
resulting binary distribution doesn't require that Cygwin be
already installed.

Tested on:

Ubuntu 16.10, FreeBSD 11.0, MacOS 10.12.1 (Sierra), Windows 7

Since the code changes are significant, more esoteric operating
systems may require changes.
  • Loading branch information
matt-kimball committed Dec 1, 2016
1 parent 7e13a55 commit 5d26cb0
Show file tree
Hide file tree
Showing 37 changed files with 3,477 additions and 1,156 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -19,9 +19,11 @@ stamp-h1*

/autom4te.cache/
/.deps/
/packet/.deps/
/ChangeLog
/INSTALL
/mtr
/mtr-packet
/mtr.8

/mtr-*.tar.gz
77 changes: 70 additions & 7 deletions Makefile.am
@@ -1,27 +1,35 @@
EXTRA_DIST = SECURITY img/mtr_icon.xpm
EXTRA_DIST = \
SECURITY \
mtr.bat \
img/mtr_icon.xpm \
packet/testpacket.py \
packet/lint.sh

sbin_PROGRAMS = mtr
sbin_PROGRAMS = mtr mtr-packet
TESTS = packet/testpacket.py

PATHFILES =
CLEANFILES = $(PATHFILES)
EXTRA_DIST += $(PATHFILES:=.in)
edit_cmd = sed \
-e 's|@VERSION[@]|$(VERSION)|g'

$(PATHFILES): Makefile
%.8: $(srcdir)/%.8.in
@ rm -f $@ $@.tmp
$(AM_V_at) $(MKDIR_P) $$(dirname $@)
$(AM_V_GEN) srcdir=''; \
test -f ./$@.in || srcdir=$(srcdir)/; \
$(edit_cmd) $${srcdir}$@.in >$@.tmp
@ mv $@.tmp $@

dist_man_MANS = mtr.8
PATHFILES += mtr.8
$(PATHFILES): Makefile

dist_man_MANS = mtr.8 mtr-packet.8
PATHFILES += mtr.8 mtr-packet.8

install-exec-hook:
`setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/mtr` \
|| chmod u+s $(DESTDIR)$(sbindir)/mtr
`setcap cap_net_raw+ep $(DESTDIR)$(sbindir)/mtr-packet` \
|| chmod u+s $(DESTDIR)$(sbindir)/mtr-packet

mtr_SOURCES = mtr.c mtr.h \
net.c net.h \
Expand All @@ -32,6 +40,7 @@ mtr_SOURCES = mtr.c mtr.h \
report.c report.h \
select.c select.h \
utils.c utils.h \
packet/cmdparse.c packet/cmdparse.h \
mtr-curses.h \
img/mtr_icon.xpm \
mtr-gtk.h
Expand Down Expand Up @@ -65,6 +74,60 @@ mtr_INCLUDES = $(GLIB_CFLAGS) -I$(top_builddir) -I$(top_srcdir)
mtr_CFLAGS = $(GTK_CFLAGS) $(NCURSES_CFLAGS)
mtr_LDADD = $(GTK_LIBS) $(NCURSES_LIBS) $(RESOLV_LIBS)


mtr_packet_SOURCES = \
packet/packet.c \
packet/cmdparse.c packet/cmdparse.h \
packet/command.c packet/command.h \
packet/platform.h \
packet/probe.c packet/probe.h \
packet/protocols.h \
packet/timeval.c packet/timeval.h \
packet/wait.h


if CYGWIN

mtr_packet_SOURCES += \
packet/command_cygwin.c packet/command_cygwin.h \
packet/probe_cygwin.c packet/probe_cygwin.h \
packet/wait_cygwin.c
mtr_packet_LDADD = -lcygwin -licmp -lws2_32

dist_windows_aux = \
$(srcdir)/mtr.bat \
$(srcdir)/AUTHORS \
$(srcdir)/COPYING \
$(srcdir)/README \
$(srcdir)/NEWS

distwindir = $(distdir)-win-$(host_cpu)

# Bundle necessary files for a Windows binary distribution
distdir-win: $(dist_windows_aux) mtr.exe mtr-packet.exe
rm -fr $(distwindir)
mkdir -p $(distwindir) $(distwindir)/bin $(distwindir)/terminfo
cp $(dist_windows_aux) -t $(distwindir)
cp mtr.exe mtr-packet.exe -t $(distwindir)/bin
ldd mtr.exe | grep -v cygdrive | awk '{ print $$3 }' | xargs cp -t $(distwindir)/bin
cp `find /usr/share/terminfo -name cygwin | xargs dirname` -r $(distwindir)/terminfo

# Zip up a Windows binary distribution
dist-windows-bin: distdir-win
rm -f $(distwindir).zip
zip -rq $(distwindir).zip $(distwindir)
rm -fr $(distwindir)

else # if CYGWIN

mtr_packet_SOURCES += \
packet/command_unix.c packet/command_unix.h \
packet/probe_unix.c packet/probe_unix.h \
packet/wait_unix.c

endif # if CYGWIN


if BUILD_BASH_COMPLETION
dist_bashcompletion_DATA = bash-completion/mtr
endif
3 changes: 1 addition & 2 deletions bootstrap.sh
Expand Up @@ -3,5 +3,4 @@
aclocal $ACLOCAL_OPTS
autoheader
automake --add-missing --copy --foreign
autoconf

autoconf --force
3 changes: 3 additions & 0 deletions configure.ac
Expand Up @@ -17,6 +17,7 @@ m4_ifdef([AM_SILENT_RULES],
[AM_SILENT_RULES([yes])],
[AC_SUBST([AM_DEFAULT_VERBOSITY], [1])])

AC_CANONICAL_HOST
AC_PROG_CC

# Check pkg-config availability.
Expand All @@ -29,6 +30,8 @@ before running ./bootstrap.sh again.])
])
PKG_PROG_PKG_CONFIG

AM_CONDITIONAL([CYGWIN], [test "$host_os" = cygwin])

# Check bytes in types.
AC_CHECK_SIZEOF([unsigned char], [1])
AC_CHECK_SIZEOF([unsigned short], [2])
Expand Down
7 changes: 6 additions & 1 deletion display.c
Expand Up @@ -21,6 +21,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <time.h>

#include "mtr.h"
#include "display.h"
Expand Down Expand Up @@ -107,8 +108,12 @@ extern void display_open(struct mtr_ctl *ctl)
}


extern void display_close(struct mtr_ctl *ctl, time_t now)
extern void display_close(struct mtr_ctl *ctl)
{
time_t now;

now = time(NULL);

switch(ctl->DisplayMode) {
case DisplayReport:
report_close(ctl);
Expand Down
2 changes: 1 addition & 1 deletion display.h
Expand Up @@ -53,7 +53,7 @@ enum {
/* Prototypes for display.c */
extern void display_detect(struct mtr_ctl *ctl, int *argc, char ***argv);
extern void display_open(struct mtr_ctl *ctl);
extern void display_close(struct mtr_ctl *ctl, time_t now);
extern void display_close(struct mtr_ctl *ctl);
extern void display_redraw(struct mtr_ctl *ctl);
extern void display_rawxmit(struct mtr_ctl *ctl, int hostnum, int seq);
extern void display_rawping(struct mtr_ctl *ctl, int hostnum, int msec, int seq);
Expand Down

0 comments on commit 5d26cb0

Please sign in to comment.