dsniff  2.4b2
About: A collection of tools for network auditing
  Fossies Dox: dsniff-2.4b2.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

dsniff.c
Go to the documentation of this file.
1 /*
2  * dsniff.c
3  *
4  * Password sniffer, because DrHoney wanted one.
5  *
6  * This is intended for demonstration purposes and educational use only.
7  *
8  * Copyright (c) 2000 Dug Song <dugsong@monkey.org>
9  *
10  * $Id: dsniff.c,v 1.69 2001/03/15 08:33:03 dugsong Exp $
11  */
12 
13 #include "config.h"
14 
15 #include <sys/types.h>
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <signal.h>
21 #include <err.h>
22 #include <libnet.h>
23 #include <nids.h>
24 #include <pcap.h>
25 
26 #include "options.h"
27 #include "pathnames.h"
28 #include "pcaputil.h"
29 #include "trigger.h"
30 #include "record.h"
31 #include "version.h"
32 
33 #define MAX_LINES 6
34 #define MIN_SNAPLEN 1024
35 
36 int Opt_client = 0;
37 int Opt_debug = 0;
38 u_short Opt_dns = 1;
39 int Opt_magic = 0;
40 int Opt_read = 0;
41 int Opt_write = 0;
44 
45 static void
46 usage(void)
47 {
48  fprintf(stderr, "Version: " VERSION "\n"
49  "Usage: dsniff [-cdmn] [-i interface] [-s snaplen] [-f services]\n"
50  " [-t trigger[,...]] [-r|-w savefile] [expression]\n");
51  exit(1);
52 }
53 
54 static void
55 sig_hup(int sig)
56 {
57  trigger_dump();
58 }
59 
60 static void
61 sig_die(int sig)
62 {
63  record_close();
64  exit(0);
65 }
66 
67 static void
68 null_syslog(int type, int errnum, struct ip *iph, void *data)
69 {
70 }
71 
72 int
73 main(int argc, char *argv[])
74 {
75  extern char *optarg;
76  extern int optind;
77  char *services, *savefile, *triggers;
78  int c;
79 
80  services = savefile = triggers = NULL;
81 
82  while ((c = getopt(argc, argv, "cdf:i:mnr:s:t:w:h?V")) != -1) {
83  switch (c) {
84  case 'c':
85  Opt_client = 1;
86  break;
87  case 'd':
88  Opt_debug++;
89  break;
90  case 'f':
91  services = optarg;
92  break;
93  case 'i':
94  nids_params.device = optarg;
95  break;
96  case 'm':
97  Opt_magic = 1;
98  break;
99  case 'n':
100  Opt_dns = 0;
101  break;
102  case 'r':
103  Opt_read = 1;
104  savefile = optarg;
105  break;
106  case 's':
107  if ((Opt_snaplen = atoi(optarg)) == 0)
108  usage();
109  break;
110  case 't':
111  triggers = optarg;
112  break;
113  case 'w':
114  Opt_write = 1;
115  savefile = optarg;
116  break;
117  default:
118  usage();
119  }
120  }
121  argc -= optind;
122  argv += optind;
123 
124  if (Opt_read && Opt_write)
125  usage();
126 
127  if (!record_init(savefile))
128  err(1, "record_init");
129 
130  signal(SIGHUP, sig_hup);
131  signal(SIGINT, sig_die);
132  signal(SIGTERM, sig_die);
133 
134  if (Opt_read) {
135  record_dump();
136  record_close();
137  exit(0);
138  }
139 
140  if (argc != 0)
141  nids_params.pcap_filter = copy_argv(argv);
142  nids_params.scan_num_hosts = 0;
143  nids_params.syslog = null_syslog;
144 
145  if (!nids_init()) {
146  record_close();
147  errx(1, "nids_init: %s", nids_errbuf);
148  }
149  if (Opt_magic) {
151  }
152  if (triggers) {
153  trigger_init_list(triggers);
154  }
155  if (services == NULL) {
156  services = DSNIFF_LIBDIR DSNIFF_SERVICES;
157  }
158  trigger_init_services(services);
159 
160  nids_register_ip(trigger_ip);
161  nids_register_ip(trigger_udp);
162 
163  if (Opt_client) {
164  nids_register_ip(trigger_tcp_raw);
165  signal(SIGALRM, trigger_tcp_raw_timeout);
167  }
168  else nids_register_tcp(trigger_tcp);
169 
170  if (nids_params.pcap_filter != NULL) {
171  warnx("listening on %s [%s]", nids_params.device,
172  nids_params.pcap_filter);
173  }
174  else warnx("listening on %s", nids_params.device);
175 
176  nids_run();
177 
178  /* NOTREACHED */
179 
180  exit(0);
181 }
trigger_tcp_raw_timeout
void trigger_tcp_raw_timeout(int signal)
Definition: trigger.c:520
Opt_magic
int Opt_magic
Definition: dsniff.c:39
Opt_write
int Opt_write
Definition: dsniff.c:41
MAX_LINES
#define MAX_LINES
Definition: dsniff.c:33
warnx
void warnx(const char *fmt,...)
Definition: err.c:89
trigger_tcp
void trigger_tcp(struct tcp_stream *ts, void **conn_save)
Definition: trigger.c:388
trigger_init_services
void trigger_init_services(char *services)
Definition: trigger.c:567
pcaputil.h
Opt_debug
int Opt_debug
Definition: dsniff.c:37
main
int main(int argc, char *argv[])
Definition: dsniff.c:73
options.h
version.h
record.h
DSNIFF_MAGIC
#define DSNIFF_MAGIC
Definition: pathnames.h:19
Opt_dns
u_short Opt_dns
Definition: dsniff.c:38
trigger_dump
void trigger_dump(void)
Definition: trigger.c:247
record_close
void record_close(void)
Definition: record.c:207
trigger_init_magic
void trigger_init_magic(char *filename)
Definition: trigger.c:547
trigger_init_list
void trigger_init_list(char *list)
Definition: trigger.c:553
Opt_client
int Opt_client
Definition: dsniff.c:36
null_syslog
static void null_syslog(int type, int errnum, struct ip *iph, void *data)
Definition: dsniff.c:68
Opt_lines
int Opt_lines
Definition: dsniff.c:43
sig_hup
static void sig_hup(int sig)
Definition: dsniff.c:55
err.h
VERSION
#define VERSION
Definition: version.h:1
err
void err(int eval, const char *fmt,...)
Definition: err.c:47
sig_die
static void sig_die(int sig)
Definition: dsniff.c:61
TRIGGER_TCP_RAW_TIMEOUT
#define TRIGGER_TCP_RAW_TIMEOUT
Definition: trigger.h:14
copy_argv
char * copy_argv(char **argv)
Definition: pcaputil.c:101
errx
void errx(int eval, const char *fmt,...)
Definition: err.c:76
MIN_SNAPLEN
#define MIN_SNAPLEN
Definition: dsniff.c:34
usage
static void usage(void)
Definition: dsniff.c:46
Opt_snaplen
int Opt_snaplen
Definition: dsniff.c:42
Opt_read
int Opt_read
Definition: dsniff.c:40
trigger.h
DSNIFF_LIBDIR
#define DSNIFF_LIBDIR
Definition: pathnames.h:15
trigger_udp
void trigger_udp(struct libnet_ipv4_hdr *ip)
Definition: trigger.c:308
record_dump
void record_dump(void)
Definition: record.c:140
config.h
trigger_tcp_raw
void trigger_tcp_raw(struct libnet_ipv4_hdr *ip)
Definition: trigger.c:440
pathnames.h
trigger_ip
void trigger_ip(struct libnet_ipv4_hdr *ip)
Definition: trigger.c:279
record_init
int record_init(char *file)
Definition: record.c:158
DSNIFF_SERVICES
#define DSNIFF_SERVICES
Definition: pathnames.h:18