--- driftnet-0.1.6.orig/driftnet.h +++ driftnet-0.1.6/driftnet.h @@ -25,7 +25,7 @@ * Characterise types of media which we can extract. */ enum mediatype { m_image = 1, m_audio = 2 }; -#define NMEDIATYPES 3 /* keep up to date with media.c */ +#define NMEDIATYPES 4 /* keep up to date with media.c */ /* struct datablock: * Represents an extent in a captured stream. */ @@ -60,6 +60,7 @@ /* media.c */ void connection_extract_media(connection c, const enum mediatype T); +int is_driftnet_file(char *filename); #define TMPNAMELEN 64 --- driftnet-0.1.6.orig/display.c +++ driftnet-0.1.6/display.c @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -301,7 +302,7 @@ int nimgs = 0; if (!path) - path = malloc(strlen(tmpdir) + 34); + path = malloc(strlen(tmpdir) + 64); /* We are sent messages continaing the length of the filename, then the * length of the file, then the filename. */ @@ -408,7 +409,7 @@ /* mouse button press/release for saving images */ gtk_signal_connect(GTK_OBJECT(darea), "button_press_event", GTK_SIGNAL_FUNC(button_press_event), NULL); - gtk_signal_connect(GTK_OBJECT(darea), "button_press_event", GTK_SIGNAL_FUNC(button_release_event), NULL); + gtk_signal_connect(GTK_OBJECT(darea), "button_release_event", GTK_SIGNAL_FUNC(button_release_event), NULL); gtk_widget_show_all(window); --- driftnet-0.1.6.orig/png.c +++ driftnet-0.1.6/png.c @@ -6,5 +6,137 @@ * */ +#ifndef NO_DISPLAY_WINDOW + static const char rcsid[] = "$Id: png.c,v 1.3 2002/06/10 21:25:48 chris Exp $"; +#include +#include +#include "img.h" + +struct png_state { + png_structp png; + png_infop info; + int depth; + int color; +}; + +static void png_done(img I) { + struct png_state *p = I->us; + if (p) { + png_destroy_read_struct(&p->png, &p->info, 0); + free(p); + } +} + +/* png_catch_error: */ +/* Catch errors signalled by libpng, clean up and go on. */ +void png_catch_error(png_structp png_ptr, png_const_charp error_msg) { + jmp_buf *jmpbuf_ptr; + + fprintf(stderr, "libpng error: %s (skipping image).\n", error_msg); + fflush(stderr); + + jmpbuf_ptr=png_jmpbuf(png_ptr); + if (jmpbuf_ptr==NULL) { + fprintf(stderr, "libpng unrecoverable error, terminating.\n"); + fflush(stderr); + exit(20); + } + + longjmp(jmpbuf_ptr, 1); +} + +/* png_load_hdr: + * Load the header of a PNG file. */ +int png_load_hdr(img I) { + struct png_state *p = calloc(sizeof(struct png_state), 1); + if (p == 0) { + I->err = IE_HDRFORMAT; + return 0; + } + I->us = p; + p->png = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, png_catch_error, NULL); + if (p->png == 0) { + png_done(I); + I->err = IE_HDRFORMAT; + return 0; + } + + if (setjmp(png_jmpbuf(p->png))) { + png_done(I); + I->err = IE_HDRFORMAT; + return 0; + } + + p->info = png_create_info_struct(p->png); + if (p->info == 0) { + png_done(I); + I->err = IE_HDRFORMAT; + return 0; + } + png_init_io(p->png, I->fp); + png_read_info(p->png, p->info); + png_get_IHDR(p->png, p->info, + (png_uint_32 *)&I->width, (png_uint_32 *)&I->height, + &p->depth, &p->color, 0, 0, 0); + switch (p->color) { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: + case PNG_COLOR_TYPE_PALETTE: + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: + return 1; + default: + png_done(I); + I->err = IE_IMGFORMAT; + return 0; + } +} + +/* png_abort_load: + * Abort loading a PNG after the header is done. */ +int png_abort_load(img I) { + png_done(I); + return 1; +} + +/* png_load_img: + * Read a PNG file into an image. */ +int png_load_img(img I) { + struct png_state *p = I->us; + img_alloc(I); + switch (p->depth) { + case 8: + break; + case 16: + png_set_strip_16(p->png); + break; + default: + png_set_packing(p->png); + break; + } + switch (p->color) { + case PNG_COLOR_TYPE_GRAY: + case PNG_COLOR_TYPE_GRAY_ALPHA: + png_set_gray_to_rgb(p->png); + break; + case PNG_COLOR_TYPE_PALETTE: + png_set_palette_to_rgb(p->png); + break; + case PNG_COLOR_TYPE_RGB: + case PNG_COLOR_TYPE_RGB_ALPHA: + break; + default: + png_done(I); + return 0; + } + if (!(p->color & PNG_COLOR_MASK_ALPHA)) + png_set_filler(p->png, 0xFF, PNG_FILLER_AFTER); + png_read_update_info(p->png, p->info); + png_read_image(p->png, (png_bytep *)I->data); + png_done(I); + return 1; +} + +#endif /* !NO_DISPLAY_WINDOW */ --- driftnet-0.1.6.orig/img.c +++ driftnet-0.1.6/img.c @@ -38,6 +38,12 @@ int jpeg_load_img(img I); int jpeg_save_img(const img I, FILE *fp); +/* png.c */ +int png_load_hdr(img I); +int png_abort_load(img I); +int png_load_img(img I); +int png_save_img(const img I, FILE *fp); + #if 0 /* raw.c */ int raw_load_img(img I); @@ -59,8 +65,8 @@ */ {gif, ".gif\0", gif_load_hdr, gif_abort_load, gif_load_img, NULL}, {jpeg, ".jpg\0.jpeg\0", jpeg_load_hdr, jpeg_abort_load, jpeg_load_img, jpeg_save_img}, + {png, ".png\0", png_load_hdr, png_abort_load, png_load_img, NULL}, /* - {png, ".png\0", png_load_hdr, png_abort_load, png_load_img, png_save_img}, {raw, "", NULL, raw_load_img, NULL, raw_save_img}, */ }; @@ -105,6 +111,7 @@ * Free memory associated with an image object. */ void img_delete(img I) { + if (I->fp) fclose(I->fp); if (I->data) free(I->data); free(I); } --- driftnet-0.1.6.orig/image.c +++ driftnet-0.1.6/image.c @@ -12,6 +12,7 @@ #include #include #include +#include /* memstr: * Locate needle, of length n_len, in haystack, of length h_len, returning NULL. @@ -218,6 +219,40 @@ return jpeghdr; } +/* + * See http://www.libpng.org/pub/png/spec/1.2/PNG-Structure.html + */ +unsigned char *find_png_image(const unsigned char *data, const size_t len, unsigned char **pngdata, size_t *pnglen) { + unsigned char *pnghdr, *block; + + *pngdata = NULL; + + if (len < 8) return (unsigned char*)data; + + pnghdr = memstr(data, len, "\x89PNG\r\n\x1a\n", 8); + if (!pnghdr) return (unsigned char*)(data + len - 8); + block = pnghdr + 8; + /* + * Scan sequence of chunks. + * We need at least enough space for 3 ints: the length, type, and CRC. + */ + while (block + 12 <= data + len) { + extern unsigned int ntohl(unsigned int); + unsigned int length = ntohl(*(unsigned int *)block); + unsigned char *chunk_type = block + 4; + block += 12; + if (memcmp(chunk_type, "IEND", 4) == 0) { + if (length != 0) /* corrupt */ + return pnghdr + 8; + *pngdata = pnghdr; + *pnglen = block - pnghdr; + return block; + } + block += length; + } + return pnghdr; +} + #if 0 #include #include --- driftnet-0.1.6.orig/playaudio.c +++ driftnet-0.1.6/playaudio.c @@ -166,7 +166,7 @@ * Main loop of child process which keeps an MPEG player running. */ static void mpeg_player_manager(void) { extern sig_atomic_t foad; /* in driftnet.c */ - struct sigaction sa = {0}; + struct sigaction sa = {{0}}; pid_t mpeg_pid; sa.sa_handler = SIG_DFL; --- driftnet-0.1.6.orig/driftnet.c +++ driftnet-0.1.6/driftnet.c @@ -88,9 +88,7 @@ buf = malloc(buflen = strlen(tmpdir) + 64); while ((de = readdir(d))) { - char *p; - p = strrchr(de->d_name, '.'); - if (!tmpdir_specified || (p && strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpeg") == 0 || strcmp(p, ".gif") == 0 || strcmp(p, ".mp3") == 0))) { + if (!tmpdir_specified || is_driftnet_file(de->d_name)) { if (buflen < strlen(tmpdir) + strlen(de->d_name) + 1) buf = realloc(buf, buflen = strlen(tmpdir) + strlen(de->d_name) + 64); @@ -584,12 +582,11 @@ } } else { /* need to make a temporary directory. */ - for (;;) { - tmpdir = strdup(tmpnam(NULL)); - if (mkdir(tmpdir, 0700) == 0) - break; - free(tmpdir); - } + tmpdir = mkdtemp(strdup("/tmp/driftnet-XXXXXX")); + if (!tmpdir) { + perror(PROGNAME": mkdtemp"); + return -1; + } } if (verbose) @@ -647,7 +644,7 @@ return -1; case -1: - perror(PROGNAME "fork"); + perror(PROGNAME": fork"); return -1; default: --- driftnet-0.1.6.orig/media.c +++ driftnet-0.1.6/media.c @@ -27,6 +27,7 @@ /* image.c */ unsigned char *find_gif_image(const unsigned char *data, const size_t len, unsigned char **gifdata, size_t *giflen); unsigned char *find_jpeg_image(const unsigned char *data, const size_t len, unsigned char **jpegdata, size_t *jpeglen); +unsigned char *find_png_image(const unsigned char *data, const size_t len, unsigned char **pngdata, size_t *pnglen); /* audio.c */ unsigned char *find_mpeg_stream(const unsigned char *data, const size_t len, unsigned char **mpegdata, size_t *mpeglen); @@ -34,6 +35,16 @@ /* playaudio.c */ void mpeg_submit_chunk(const unsigned char *data, const size_t len); +int is_driftnet_file(char *filename) { + if (strncmp(filename, "driftnet-", 9) != 0) return 0; + char *p = strrchr(filename, '.'); + if (p == 0) return 0; + return (strcmp(p, ".jpeg") == 0 || + strcmp(p, ".gif") == 0 || + strcmp(p, ".png") == 0 || + strcmp(p, ".mp3") == 0); +} + /* count_temporary_files: * How many of our files remain in the temporary directory? We do this a * maximum of once every five seconds. */ @@ -47,9 +58,7 @@ d = opendir(tmpdir); if (d) { while ((de = readdir(d))) { - char *p; - p = strrchr(de->d_name, '.'); - if (p && (strncmp(de->d_name, "driftnet-", 9) == 0 && (strcmp(p, ".jpeg") == 0 || strcmp(p, ".gif") == 0 || strcmp(p, ".mp3") == 0))) + if (is_driftnet_file(de->d_name)) ++num; } closedir(d); @@ -98,6 +107,7 @@ } driver[NMEDIATYPES] = { { "gif", m_image, find_gif_image, dispatch_image }, { "jpeg", m_image, find_jpeg_image, dispatch_image }, + { "png", m_image, find_png_image, dispatch_image }, { "mpeg", m_audio, find_mpeg_stream, dispatch_mpeg_audio } }; --- driftnet-0.1.6.orig/Makefile +++ driftnet-0.1.6/Makefile @@ -31,8 +31,10 @@ # Optional C compiler and linker flags. Typical driftnet builds have support # for displaying captured images in an X window, and need the following flags: -CFLAGS += `gtk-config --cflags` -LDLIBS += -ljpeg -lungif `gtk-config --libs` +CFLAGS += `pkg-config --cflags gtk+-2.0` `pkg-config --cflags libpng` + +#LDLIBS += -ljpeg -lungif `pkg-config --libs gtk+-2.0` `pkg-config --libs libpng` +LDLIBS += -ljpeg -lgif `pkg-config --libs gtk+-2.0` `pkg-config --libs libpng` # Alternatively, you can build a version of driftnet which can only be used # in `adjunct' mode as the back end for some other image-processing program. To @@ -74,7 +76,8 @@ default: driftnet driftnet.1 -driftnet: depend $(OBJS) +#driftnet: depend $(OBJS) +driftnet: $(OBJS) $(CC) -o driftnet $(OBJS) $(LDFLAGS) $(LDLIBS) driftnet.1: driftnet.1.in Makefile @@ -101,7 +104,7 @@ tar cvzf driftnet-$(VERSION).tar.gz driftnet-$(VERSION) rm -rf driftnet-$(VERSION) mv driftnet-$(VERSION).tar.gz .. - + depend: endianness makedepend -- $(CFLAGS) `cat endianness` -- $(SRCS) touch depend --- driftnet-0.1.6.orig/debian/manpages +++ driftnet-0.1.6/debian/manpages @@ -0,0 +1 @@ +driftnet.1 --- driftnet-0.1.6.orig/debian/menu +++ driftnet-0.1.6/debian/menu @@ -0,0 +1,2 @@ +?package(driftnet):needs="X11" section="Applications/Network/Monitoring"\ + title="Driftnet" command="/usr/bin/driftnet" --- driftnet-0.1.6.orig/debian/copyright +++ driftnet-0.1.6/debian/copyright @@ -0,0 +1,11 @@ +This package was debianized by Ian Eure on +Sat, 1 Sep 2001 14:47:51 -0700. It has then been adopted by +Christoph Haas . + +It was downloaded from + +Copyright © 2001 Chris Lightfoot +All rights reserved. + +The software is licensed under the terms of the GNU General Public License +which you can find on your Debian system at /usr/share/common-licenses/GPL --- driftnet-0.1.6.orig/debian/compat +++ driftnet-0.1.6/debian/compat @@ -0,0 +1 @@ +5 --- driftnet-0.1.6.orig/debian/driftnet.desktop +++ driftnet-0.1.6/debian/driftnet.desktop @@ -0,0 +1,10 @@ +[Desktop Entry] +Version=1.0 +Encoding=UTF-8 +Name=Driftnet +Comment=Picks out and displays images from network traffic +Exec=driftnet +Icon=driftnet +Type=Application +Categories=Network;Monitor; + --- driftnet-0.1.6.orig/debian/rules +++ driftnet-0.1.6/debian/rules @@ -0,0 +1,67 @@ +#!/usr/bin/make -f +# Sample debian/rules that uses debhelper. +# GNU copyright 1997 to 1999 by Joey Hess. + +# Uncomment this to turn on verbose mode. +#export DH_VERBOSE=1 + +build: build-stamp +build-stamp: + dh_testdir + + # Add here commands to compile the package. + + # skip makedepend and all its warnings + touch depend + + $(MAKE) + + touch build-stamp + +clean: + dh_testdir + dh_testroot + rm -f build-stamp + + # Add here commands to clean up after the build process. + [ ! -f Makefile ] || $(MAKE) clean + + dh_clean + +install: build + dh_testdir + dh_testroot + dh_clean -k + dh_installdirs + # Add here commands to install the package into debian/driftnet + dh_install driftnet usr/bin + dh_install debian/driftnet.desktop /usr/share/applications + +# Build architecture-independent files here. +binary-indep: build install +# We have nothing to do by default. + +# Build architecture-dependent files here. +binary-arch: build install + dh_testdir + dh_testroot + dh_installdocs + dh_installexamples + dh_installmenu + dh_installcron + dh_installman + dh_installinfo + dh_installchangelogs CHANGES + dh_desktop + dh_link + dh_strip + dh_compress + dh_fixperms + dh_installdeb + dh_shlibdeps + dh_gencontrol + dh_md5sums + dh_builddeb + +binary: binary-indep binary-arch +.PHONY: build clean binary-indep binary-arch binary install --- driftnet-0.1.6.orig/debian/control +++ driftnet-0.1.6/debian/control @@ -0,0 +1,20 @@ +Source: driftnet +Section: admin +Priority: extra +Maintainer: Christoph Haas +Build-Depends: debhelper (>> 5.0), libgtk2.0-dev, libpcap-dev, libjpeg62-dev, libgif-dev, libpng12-dev, xutils-dev +Standards-Version: 3.8.0 +Homepage: http://www.ex-parrot.com/~chris/driftnet/ + +Package: driftnet +Architecture: any +Depends: ${shlibs:Depends} +Description: Picks out and displays images from network traffic + Inspired by EtherPEG, Driftnet is a program which listens to network + traffic and picks out images from TCP streams it observes. It is + interesting to run it on a host which sees a lot of web traffic. + . + (Obviously, this is an invasion of privacy of a fairly blatant sort. + Also, if you are possessed of Victorian sensibilities, and share an + unswitched network with others who are not, you should probably not + use it.) --- driftnet-0.1.6.orig/debian/changelog +++ driftnet-0.1.6/debian/changelog @@ -0,0 +1,129 @@ +driftnet (0.1.6-9) unstable; urgency=low + + * Deal with libpng errors more gracefully (closes: #494750) + [Patch kindly provided by Adam Sjøgren] + + -- Christoph Haas Fri, 15 Aug 2008 23:28:25 +0200 + +driftnet (0.1.6-8) unstable; urgency=low + + * Fixed desktop and menu file + * Patched the build system (from Ubuntu patch) (closes: #459799) + * New policy/standards version 3.7.3 + + -- Christoph Haas Sat, 09 Feb 2008 10:24:57 +0100 + +driftnet (0.1.6-7) unstable; urgency=low + + * New maintainer. (closes: #390820) + + -- Christoph Haas Tue, 10 Oct 2006 21:49:35 +0200 + +driftnet (0.1.6-6) unstable; urgency=low + + * Added .desktop file, from Ubuntu. + (Closes: #375511) + + -- Steve Kemp Thu, 26 June 2006 16:12:04 +0000 + +driftnet (0.1.6-5) unstable; urgency=low + + * Make sure each image file is closed after loading. + (Closes: #337400) + * Updated standards version to 3.7.2, no changes. + + -- Steve Kemp Thu, 12 May 2006 15:57:43 +0000 + +driftnet (0.1.6-4) unstable; urgency=low + + * More changes from Eric Cooper: + * Fixed button_press/release code that broke with gtk2 + * Added support for PNG image capture (Closes: #301695) + + -- Steve Kemp Thu, 11 Aug 2005 06:54:36 +0000 + +driftnet (0.1.6-3) unstable; urgency=low + + * Standards-Version 3.6.2 + * Use gtk2 + * Use mkdtemp instead of insecure tmpnam + * Minor changes to avoid gcc warnings + + -- Eric Cooper Sat, 6 Aug 2005 16:10:40 -0400 + +driftnet (0.1.6-2) unstable; urgency=low + + * New maintainer. + * Updated standards version to 3.6.1 + (The only necessary change was to quote some entries in the menu file). + + -- Steve Kemp Wed, 23 Jun 2004 11:38:21 +0000 + +driftnet (0.1.6-1) unstable; urgency=low + + * New upstream version. (closes: #154566) + * Roll in changes from NMU (closes: #166475, #156195). + * New Standards-Version 3.5.8. + + -- Ian Eure Thu, 20 Feb 2003 13:49:11 -0800 + +driftnet (0.1.4-5.2) unstable; urgency=low + + * NMU + * Build against libungif4. (closes: #166475) + + -- Michael Fedrowitz Sun, 24 Nov 2002 22:52:32 +0100 + +driftnet (0.1.4-5.1) unstable; urgency=low + + * Non maintainer upload + * Rebuilt with new libpcap to remove dependency on libpcap0, which I + got removed from unstable by accident. Sorry about this... + + -- Torsten Landschoff Sat, 10 Aug 2002 11:36:49 +0200 + +driftnet (0.1.4-5) unstable; urgency=low + + * Fix manpage. (Closes: #150601) + + -- Ian Eure Mon, 24 Jun 2002 09:53:59 -0700 + +driftnet (0.1.4-4) unstable; urgency=low + + * add menu entry. + * remove debian/*.ex files. + + -- Ian Eure Wed, 28 Nov 2001 14:58:03 -0800 + +driftnet (0.1.4-3) unstable; urgency=low + + * apply patch to fix int != char problem on ppc. (closes: #112925) + + -- Ian Eure Fri, 12 Oct 2001 18:50:10 -0700 + +driftnet (0.1.4-2) unstable; urgency=low + + * add xutils to build-depends. (closes: #111865) + + -- Ian Eure Wed, 12 Sep 2001 15:12:39 -0700 + +driftnet (0.1.4-1) unstable; urgency=low + + * new upstream release (closes: #111940) + + -- Ian Eure Tue, 11 Sep 2001 02:52:04 -0700 + +driftnet (0.1.3-2) unstable; urgency=low + + * fix build-depends to include xlibs-dev. he he, whoops. + (closes: #111865) + + -- Ian Eure Mon, 10 Sep 2001 14:51:37 -0700 + +driftnet (0.1.3-1) unstable; urgency=low + + * Initial Release. (closes: #110904) + + -- Ian Eure Mon, 3 Sep 2001 17:12:09 -0700 + + --- driftnet-0.1.6.orig/debian/docs +++ driftnet-0.1.6/debian/docs @@ -0,0 +1,2 @@ +README +TODO