~ubuntu-branches/ubuntu/precise/ettercap/precise

« back to all changes in this revision

Viewing changes to src/interface/ncurses/ec_interface_sniff_data.c

  • Committer: Bazaar Package Importer
  • Author(s): Murat Demirten
  • Date: 2003-06-21 19:57:18 UTC
  • Revision ID: james.westby@ubuntu.com-20030621195718-qqbbfk18e1djchd9
Tags: upstream-0.6.b
ImportĀ upstreamĀ versionĀ 0.6.b

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    ettercap -- ncurses interface for data sniffing-logging
 
3
 
 
4
    Copyright (C) 2001  ALoR <alor@users.sourceforge.net>, NaGA <crwm@freemail.it>
 
5
 
 
6
    This program is free software; you can redistribute it and/or modify
 
7
    it under the terms of the GNU General Public License as published by
 
8
    the Free Software Foundation; either version 2 of the License, or
 
9
    (at your option) any later version.
 
10
 
 
11
    This program is distributed in the hope that it will be useful,
 
12
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
    GNU General Public License for more details.
 
15
 
 
16
    You should have received a copy of the GNU General Public License
 
17
    along with this program; if not, write to the Free Software
 
18
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 
 
20
    $Id: ec_interface_sniff_data.c,v 1.6 2003/04/30 10:05:25 lordnaga Exp $
 
21
*/
 
22
 
 
23
#include <ec_main.h>
 
24
 
 
25
#ifdef HAVE_NCURSES  // don't compile if ncurses interface is not supported
 
26
 
 
27
#ifdef HAVE_NCURSES_H
 
28
   #include <ncurses.h>
 
29
#else
 
30
   #include <curses.h>
 
31
#endif
 
32
 
 
33
#include <sys/types.h>
 
34
#if defined(HAVE_SYS_POLL_H)
 
35
   #include <sys/poll.h>
 
36
#elif defined (HAVE_POLL_H)
 
37
   #include <poll.h>
 
38
#endif
 
39
 
 
40
#include <ec_interface.h>
 
41
#include <ec_interface_inject.h>
 
42
#include <ec_interface_plugins.h>
 
43
#include <ec_decodedata.h>
 
44
#include <ec_dissector.h>
 
45
#include <ec_illithid.h>
 
46
#include <ec_buffer.h>
 
47
#include <ec_inet_structures.h>
 
48
#include <ec_binder.h>
 
49
#include <ec_thread.h>
 
50
 
 
51
#define PAD_BUFFER 1000        // buffered lines for sniffing
 
52
 
 
53
 
 
54
#define BOTTOM_COLOR 1        // color schemes
 
55
#define TITLE_COLOR  2
 
56
#define MAIN_COLOR   3
 
57
#define POINT_COLOR  4
 
58
#define SEL_COLOR    5
 
59
#define HELP_COLOR   6
 
60
#define SNIFF_COLOR  6
 
61
 
 
62
#define KEY_TAB      '\t'     // they aren't defined in ncurses.h :(
 
63
#define KEY_RETURN   10
 
64
#define KEY_CTRL_L   12
 
65
 
 
66
#define ASCII_VIEW   0        // data in the sniffing windows...
 
67
#define HEX_VIEW     1
 
68
#define TEXT_VIEW    2
 
69
#define EBCDIC_VIEW  3
 
70
#define JOINED_VIEW  4
 
71
 
 
72
// protos...
 
73
 
 
74
void Interface_Sniff_Data_Run(char *ips, int psource, char *ipd, int pdest, char *macs, char *macd, char proto, char *type, short mode, int connection);
 
75
void Interface_Sniff_Data_Redraw(void);
 
76
void Interface_Sniff_Data_KeyTab(void);
 
77
void Interface_Sniff_Data_SniffData(void);
 
78
void Interface_Sniff_Data_LogToFile(char proto);
 
79
void Interface_Sniff_Data_Winch(void);
 
80
void Interface_Sniff_Data_Reset(void);
 
81
void Interface_Sniff_Data_StopCont(void);
 
82
void Interface_Sniff_Data_View(short mode);
 
83
void Interface_Sniff_Data_Scroll(short direction);
 
84
void Interface_Sniff_Data_DrawScroller(void);
 
85
void Interface_Sniff_Data_Inject(char proto, char *app);
 
86
void Interface_Sniff_Data_Kill(char proto);
 
87
void Interface_Sniff_Data_Bind(char proto, char *ipsource, char *ipdest);
 
88
u_short Interface_Sniff_Data_WaitPort(void);
 
89
 
 
90
// global variables
 
91
 
 
92
extern WINDOW *main_window, *bottom_window, *top_window;
 
93
WINDOW *data_source_win, *data_dest_win, *data_source, *data_dest;
 
94
WINDOW *win_pointer;
 
95
WINDOW *data_joined_win, *data_joined;
 
96
 
 
97
 
 
98
extern int W_MAINX1, W_MAINY1, W_MAINX2, W_MAINY2;
 
99
extern int W_BOTTOMY2;
 
100
 
 
101
extern int Conn_Pointer;
 
102
 
 
103
short log_source, log_dest, log_joined;
 
104
short view;
 
105
short stop = 0;
 
106
short inject = 0;
 
107
short joined = 0;
 
108
 
 
109
int inject_tod=0, inject_tos=0;
 
110
 
 
111
short scroll_yd = 0, scroll_ys = 0, scroll_yj = 0;
 
112
 
 
113
FILE *file_source, *file_dest, *file_joined;
 
114
 
 
115
char ipsource[16];
 
116
char ipdest[16];
 
117
u_short portsource;
 
118
u_short portdest;
 
119
 
 
120
pthread_t Binder_pid=0;
 
121
 
 
122
int Connection_Sniffed;
 
123
//---------------------------
 
124
 
 
125
void Interface_Sniff_Data_Winch(void)  // TODO better handling...
 
126
{
 
127
   DEBUG_MSG("Interface_Sniff_Data_Winch\tTODO");
 
128
 
 
129
   Interface_Sniff_Data_Redraw();
 
130
}
 
131
 
 
132
 
 
133
void Interface_Sniff_Data_Redraw(void)
 
134
{
 
135
 
 
136
   Interface_Redraw();
 
137
 
 
138
   DEBUG_MSG("Interface_Sniff_Data_Redraw");
 
139
 
 
140
   if (joined)
 
141
   {
 
142
      redrawwin(data_joined_win);
 
143
 
 
144
      wnoutrefresh(data_joined_win);
 
145
      pnoutrefresh(data_joined, scroll_yj, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
146
   }
 
147
   else
 
148
   {
 
149
      redrawwin(data_dest_win);
 
150
      redrawwin(data_source_win);
 
151
 
 
152
      wnoutrefresh(data_dest_win);
 
153
      wnoutrefresh(data_source_win);
 
154
      pnoutrefresh(data_source, scroll_ys, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
155
      pnoutrefresh(data_dest, scroll_yd, 0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
156
   }
 
157
 
 
158
   doupdate();
 
159
}
 
160
 
 
161
 
 
162
 
 
163
void Interface_Sniff_Data_KeyTab(void)
 
164
{
 
165
 
 
166
   if (joined) return;     // TAB isnt necessary in joined view
 
167
 
 
168
   win_pointer = (win_pointer == data_source_win) ? data_dest_win : data_source_win;
 
169
 
 
170
   wattroff(data_source_win, A_BOLD);
 
171
   wattroff(data_dest_win, A_BOLD);
 
172
 
 
173
   wattron(win_pointer, A_BOLD);
 
174
 
 
175
   box(data_source_win,ACS_VLINE,ACS_HLINE);
 
176
   box(data_dest_win,ACS_VLINE,ACS_HLINE);
 
177
 
 
178
   mvwprintw(data_source_win, 0, 1, "%s:%d", ipsource, portsource);
 
179
   mvwprintw(data_dest_win, 0, 1, "%s:%d", ipdest, portdest);
 
180
 
 
181
   Interface_Sniff_Data_DrawScroller();
 
182
 
 
183
   if (log_source) mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10, "LOGGED");
 
184
   if (log_dest) mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10, "LOGGED");
 
185
 
 
186
   switch(view)
 
187
   {
 
188
      case ASCII_VIEW:
 
189
                        mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "ASCII");
 
190
                        mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "ASCII");
 
191
                        break;
 
192
      case HEX_VIEW:
 
193
                        mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "HEX");
 
194
                        mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "HEX");
 
195
                        break;
 
196
      
 
197
      case EBCDIC_VIEW: 
 
198
                        mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "EBCDIC");
 
199
                        mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "EBCDIC");
 
200
                        break;
 
201
 
 
202
       case TEXT_VIEW:
 
203
                        mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "TEXT");
 
204
                        mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "TEXT");
 
205
                        break;
 
206
   }
 
207
 
 
208
   if (stop) mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "STOPPED");
 
209
   if (stop) mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "STOPPED");
 
210
 
 
211
   mvwprintw(win_pointer, 0, W_MAINX2 / 2 - 10, "active");
 
212
 
 
213
   redrawwin(data_dest_win);
 
214
   redrawwin(data_source_win);
 
215
 
 
216
   wnoutrefresh(data_dest_win);
 
217
   wnoutrefresh(data_source_win);
 
218
   pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
219
   pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
220
 
 
221
   doupdate();
 
222
 
 
223
}
 
224
 
 
225
 
 
226
 
 
227
 
 
228
void Interface_Sniff_Data_LogToFile(char proto)
 
229
{
 
230
   WINDOW *question_window;
 
231
   char question[100];
 
232
   char filename[60];
 
233
   char answer;
 
234
   time_t tt;
 
235
   struct tm *dd;
 
236
   char date[8];
 
237
 
 
238
   DEBUG_MSG("Interface_Sniff_Data_LogToFile");
 
239
 
 
240
   tt = time(NULL);
 
241
   dd = localtime(&tt);
 
242
 
 
243
   snprintf(date, sizeof(date), "%04d%02d%02d", dd->tm_year+1900, dd->tm_mon+1, dd->tm_mday);
 
244
 
 
245
   if (joined)
 
246
   {
 
247
      strcpy(question, "Do you want to log the trafic to this file ? (y/n)");
 
248
#ifdef CYGWIN      
 
249
      snprintf(filename, sizeof(filename), "%s-%c-%s[%d]-%s[%d]-FULL.log", date, proto, ipsource, portsource, ipdest, portdest);
 
250
#else
 
251
      snprintf(filename, sizeof(filename), "%s-%c-%s:%d-%s:%d-FULL.log", date, proto, ipsource, portsource, ipdest, portdest);
 
252
#endif
 
253
   }
 
254
   else
 
255
   {
 
256
      if (win_pointer == data_source_win)
 
257
      {
 
258
         strcpy(question, "Do you want to log SOURCE-to-DEST to this file ? (y/n)");
 
259
#ifdef CYGWIN      
 
260
         snprintf(filename, sizeof(filename), "%s-%c-%s[%d]-%s[%d].log", date, proto, ipsource, portsource, ipdest, portdest);
 
261
#else
 
262
         snprintf(filename, sizeof(filename), "%s-%c-%s:%d-%s:%d.log", date, proto, ipsource, portsource, ipdest, portdest);
 
263
#endif
 
264
      }
 
265
      else
 
266
      {
 
267
         strcpy(question, "Do you want to log DEST-to-SOURCE to this file ? (y/n)");
 
268
#ifdef CYGWIN      
 
269
         snprintf(filename, sizeof(filename), "%s-%c-%s[%d]-%s[%d].log", date, proto, ipdest, portdest, ipsource, portsource);
 
270
#else
 
271
         snprintf(filename, sizeof(filename), "%s-%c-%s:%d-%s:%d.log", date, proto, ipdest, portdest, ipsource, portsource);
 
272
#endif
 
273
      }
 
274
   }
 
275
 
 
276
   question_window = newwin(7, strlen(question) + 8,0,0);
 
277
   mvwin(question_window, W_MAINY1+(W_MAINY2-W_MAINY1)/2-2, W_MAINX2/2 - (strlen(question)+8)/2 );
 
278
   wbkgdset(question_window, COLOR_PAIR(TITLE_COLOR));
 
279
   wattron(question_window, A_BOLD);
 
280
   box(question_window,ACS_VLINE,ACS_HLINE);
 
281
   mvwprintw(question_window,  2, 4, "%s", question);
 
282
   wnoutrefresh(question_window);
 
283
   doupdate();
 
284
 
 
285
   wbkgdset(question_window, COLOR_PAIR(HELP_COLOR));
 
286
   if (joined) mvwprintw(question_window,  4, 2, "%s", filename);
 
287
   else mvwprintw(question_window,  4, 6, "%s", filename);
 
288
   answer = wgetch(question_window);
 
289
   delwin(question_window);
 
290
 
 
291
   if ( (answer == 'y') || (answer == 'Y') )
 
292
   {
 
293
      if (joined)
 
294
      {
 
295
         file_joined = fopen(filename, "a");
 
296
         if (file_joined == NULL)
 
297
            ERROR_MSG("fopen()");
 
298
         log_joined = 1;
 
299
         mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 - 15, "LOGGED");
 
300
      }
 
301
      else
 
302
      {
 
303
         if (win_pointer == data_source_win)
 
304
         {
 
305
            file_source = fopen(filename, "a");
 
306
            if (file_source == NULL)
 
307
               ERROR_MSG("fopen()");
 
308
            log_source = 1;
 
309
            mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10, "LOGGED");
 
310
         }
 
311
         else
 
312
         {
 
313
            file_dest = fopen(filename, "a");
 
314
            if (file_dest == NULL)
 
315
               ERROR_MSG("fopen()");
 
316
            log_dest = 1;
 
317
            mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10, "LOGGED");
 
318
         }
 
319
      }
 
320
   }
 
321
   else
 
322
   {
 
323
      if (joined)
 
324
      {
 
325
         if (log_joined) fclose(file_joined);
 
326
         log_joined = 0;
 
327
         wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 - 15);
 
328
         whline(data_joined_win, ACS_HLINE, 6);
 
329
      }
 
330
      else
 
331
      {
 
332
         if (win_pointer == data_source_win)
 
333
         {
 
334
            if (log_source) fclose(file_source);
 
335
            log_source = 0;
 
336
            wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10);
 
337
            whline(data_source_win, ACS_HLINE, 6);
 
338
         }
 
339
         else
 
340
         {
 
341
            if (log_dest) fclose(file_dest);
 
342
            log_dest = 0;
 
343
            wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, W_MAINX2 / 2 - 10);
 
344
            whline(data_dest_win, ACS_HLINE, 6);
 
345
         }
 
346
      }
 
347
   }
 
348
 
 
349
 
 
350
#ifdef DEBUG
 
351
   DEBUG_MSG("Interface_Sniff_Data_LogToFile returns -- %c", answer);
 
352
   if ( (answer == 'y') || (answer == 'Y') ) DEBUG_MSG("\t %s", filename);
 
353
#endif
 
354
 
 
355
   Interface_Sniff_Data_Redraw();
 
356
 
 
357
}
 
358
 
 
359
 
 
360
void Interface_Sniff_Data_StopCont(void)
 
361
{
 
362
   DEBUG_MSG("Interface_Sniff_Data_StopCont");
 
363
 
 
364
 
 
365
   if (stop == 0)
 
366
   {
 
367
      if (joined)
 
368
      {
 
369
         mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2, "STOPPED");
 
370
      }
 
371
      else
 
372
      {
 
373
         mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "STOPPED");
 
374
         mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "STOPPED");
 
375
      }
 
376
      stop = 1;
 
377
   }
 
378
   else
 
379
   {
 
380
      if (joined)
 
381
      {
 
382
         wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_joined_win, ACS_HLINE, 7);
 
383
      }
 
384
      else
 
385
      {
 
386
         wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_source_win, ACS_HLINE, 7);
 
387
         wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2); whline(data_dest_win, ACS_HLINE, 7);
 
388
      }
 
389
 
 
390
      Interface_Sniff_Data_View(view);
 
391
      stop = 0;
 
392
   }
 
393
 
 
394
 
 
395
   if (joined)
 
396
   {
 
397
      redrawwin(data_joined_win);
 
398
 
 
399
      wnoutrefresh(data_joined_win);
 
400
      pnoutrefresh(data_joined, scroll_yj, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
401
   }
 
402
   else
 
403
   {
 
404
      redrawwin(data_dest_win);
 
405
      redrawwin(data_source_win);
 
406
 
 
407
      wnoutrefresh(data_dest_win);
 
408
      wnoutrefresh(data_source_win);
 
409
      pnoutrefresh(data_source, scroll_ys, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
410
      pnoutrefresh(data_dest, scroll_yd, 0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
411
   }
 
412
 
 
413
   doupdate();
 
414
 
 
415
}
 
416
 
 
417
void Interface_Sniff_Data_Reset()
 
418
{
 
419
   if (Options.buflen) 
 
420
   {
 
421
       ConnBuffer_Flush(Conn_Between_Hosts[Connection_Sniffed].DataBuffer);
 
422
       if (!joined)
 
423
       {
 
424
           wclear(data_source);
 
425
           wclear(data_dest);
 
426
           wmove(data_source, scroll_ys, 0);
 
427
           wmove(data_dest, scroll_yd, 0);
 
428
       }
 
429
       else
 
430
       {
 
431
           wclear(data_joined);
 
432
           wmove(data_joined, scroll_yj, 0);
 
433
       }
 
434
   }
 
435
}
 
436
 
 
437
void Interface_Sniff_Data_View(short mode)
 
438
{
 
439
   DEBUG_MSG("Interface_Sniff_Data_View -- %d", mode);
 
440
      
 
441
   switch(mode)
 
442
   {
 
443
      case ASCII_VIEW:
 
444
                        if (joined)
 
445
                        {
 
446
                           wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_joined_win, ACS_HLINE, 7);
 
447
                           mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2, "ASCII");
 
448
                        }
 
449
                        else
 
450
                        {
 
451
                           wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_source_win, ACS_HLINE, 7);
 
452
                           wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2); whline(data_dest_win, ACS_HLINE, 7);
 
453
                           mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "ASCII");
 
454
                           mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "ASCII");
 
455
                        }
 
456
                        break;
 
457
 
 
458
      case HEX_VIEW:
 
459
                        if (joined)
 
460
                        {
 
461
                           wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_joined_win, ACS_HLINE, 7);
 
462
                           mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2, "HEX");
 
463
                        }
 
464
                        else
 
465
                        {
 
466
                           wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_source_win, ACS_HLINE, 7);
 
467
                           wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2); whline(data_dest_win, ACS_HLINE, 7);
 
468
                           mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "HEX");
 
469
                           mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "HEX");
 
470
                        }
 
471
                        break;
 
472
 
 
473
      case TEXT_VIEW:
 
474
                        if (joined)
 
475
                        {
 
476
                           wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_joined_win, ACS_HLINE, 7);
 
477
                           mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2, "TEXT");
 
478
                        }
 
479
                        else
 
480
                        {
 
481
                           wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_source_win, ACS_HLINE, 7);
 
482
                           wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2); whline(data_dest_win, ACS_HLINE, 7);
 
483
                           mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "TEXT");
 
484
                           mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "TEXT");
 
485
                        }
 
486
                        break;
 
487
      
 
488
      case EBCDIC_VIEW:
 
489
                        if (joined)
 
490
                        {
 
491
                           wmove(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_joined_win, ACS_HLINE, 7);
 
492
                           mvwprintw(data_joined_win, W_MAINY2 - W_MAINY1 - 4, 2, "EBCDIC");
 
493
                        }
 
494
                        else
 
495
                        {
 
496
                           wmove(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2);   whline(data_source_win, ACS_HLINE, 7);
 
497
                           wmove(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2); whline(data_dest_win, ACS_HLINE, 7);
 
498
                           mvwprintw(data_source_win, W_MAINY2 - W_MAINY1 - 4, 2, "EBCDIC");
 
499
                           mvwprintw(data_dest_win, W_MAINY2 - W_MAINY1 - 4, 2, "EBCDIC");
 
500
                        }
 
501
                        break;
 
502
 
 
503
      case JOINED_VIEW:
 
504
                        if (joined)
 
505
                        {
 
506
                           joined = 0;
 
507
                           delwin(data_joined_win);
 
508
                           delwin(data_joined);
 
509
 
 
510
                           redrawwin(main_window);
 
511
                           redrawwin(data_dest_win);
 
512
                           redrawwin(data_source_win);
 
513
 
 
514
                           wnoutrefresh(main_window);
 
515
                           wnoutrefresh(data_dest_win);
 
516
                           wnoutrefresh(data_source_win);
 
517
 
 
518
                           pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
519
                           pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
520
 
 
521
                           doupdate();
 
522
                        }
 
523
                        else
 
524
                        {
 
525
                           joined = 1;
 
526
 
 
527
                           data_joined_win = newwin(W_MAINY2 - W_MAINY1 - 3, W_MAINX2 - 4, W_MAINY1 + 2, 2);
 
528
                           data_joined = newpad(PAD_BUFFER, W_MAINX2 - 6);
 
529
 
 
530
                           wbkgdset(data_joined_win, COLOR_PAIR(SNIFF_COLOR));
 
531
                           wattron(data_joined_win, A_BOLD);
 
532
                           box(data_joined_win, ACS_VLINE, ACS_HLINE);
 
533
                           mvwprintw(data_joined_win, 0, 1, "%s:%d - %s:%d", ipsource, portsource, ipdest, portdest);
 
534
                           scroll_yj = PAD_BUFFER - (W_MAINY2-10);
 
535
                           mvwprintw(data_joined_win, 0, W_MAINX2 - 15, "JOINED");
 
536
                           scrollok(data_joined_win, TRUE);
 
537
                           wmove(data_joined, scroll_yj, 0);
 
538
 
 
539
                           scrollok(data_joined, TRUE);
 
540
 
 
541
                           wnoutrefresh(data_joined_win);
 
542
                           pnoutrefresh(data_joined, scroll_yj, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
543
                           doupdate();
 
544
 
 
545
                           Interface_Sniff_Data_DrawScroller();
 
546
                           Interface_Sniff_Data_View(ASCII_VIEW);
 
547
 
 
548
                        }
 
549
 
 
550
                        return;
 
551
                        break;
 
552
   }
 
553
 
 
554
   view = mode;
 
555
 
 
556
   if (joined)
 
557
   {
 
558
      redrawwin(data_joined_win);
 
559
 
 
560
      wnoutrefresh(data_joined_win);
 
561
      pnoutrefresh(data_joined, scroll_yj, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
562
   }
 
563
   else
 
564
   {
 
565
      redrawwin(data_dest_win);
 
566
      redrawwin(data_source_win);
 
567
 
 
568
      wnoutrefresh(data_dest_win);
 
569
      wnoutrefresh(data_source_win);
 
570
      pnoutrefresh(data_source, scroll_ys, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
571
      pnoutrefresh(data_dest, scroll_yd, 0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
572
   }
 
573
 
 
574
   doupdate();
 
575
 
 
576
}
 
577
 
 
578
 
 
579
 
 
580
void Interface_Sniff_Data_SniffData(void)
 
581
{
 
582
   SNIFFED_DATA data_from_illithid;
 
583
   int datalen;
 
584
 
 
585
   if (Options.buflen)
 
586
       datalen = ConnBuffer_Get(Conn_Between_Hosts[Connection_Sniffed].DataBuffer, &data_from_illithid, sizeof(SNIFFED_DATA));
 
587
   else
 
588
       datalen = Buffer_Get(pipe_with_illithid_data, &data_from_illithid, sizeof(SNIFFED_DATA));
 
589
   
 
590
   if (datalen<=0)
 
591
   {
 
592
       usleep(1);
 
593
       return;
 
594
   }
 
595
 
 
596
   if (binder_pipe != -1 && Binder_pid)
 
597
       Buffer_Put(binder_pipe, &data_from_illithid, sizeof(SNIFFED_DATA));
 
598
 
 
599
   if (joined)
 
600
   {
 
601
      if (log_joined) { write(fileno(file_joined), &data_from_illithid.data, data_from_illithid.datasize); fflush(file_joined);}
 
602
      if (!stop)
 
603
      {
 
604
         if ( current_illithid_data.source_ip == data_from_illithid.fast_source_ip)
 
605
            wbkgdset(data_joined, COLOR_PAIR(TITLE_COLOR));
 
606
         else
 
607
            wbkgdset(data_joined, COLOR_PAIR(BOTTOM_COLOR));
 
608
 
 
609
         switch (view)
 
610
         {
 
611
            case ASCII_VIEW:
 
612
                           wprintw(data_joined, "%s", Decodedata_GetAsciiData(data_from_illithid.data, data_from_illithid.datasize));
 
613
                           pnoutrefresh(data_joined, scroll_yj,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
614
                           break;
 
615
 
 
616
            case TEXT_VIEW:
 
617
                           wprintw(data_joined, "%s", Decodedata_GetTextData(data_from_illithid.data, data_from_illithid.datasize));
 
618
                           pnoutrefresh(data_joined, scroll_yj,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
619
                           break;
 
620
 
 
621
            case EBCDIC_VIEW:
 
622
                           wprintw(data_joined, "%s", Decodedata_GetEBCDICData(data_from_illithid.data, data_from_illithid.datasize));
 
623
                           pnoutrefresh(data_joined, scroll_yj,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
624
                           break;
 
625
 
 
626
            case HEX_VIEW:
 
627
                           if (data_from_illithid.proto == 'T') {
 
628
                              wprintw(data_joined, "\n> S %lx A %lx (%s) <\n%s",
 
629
                                                data_from_illithid.seq,
 
630
                                                data_from_illithid.ack_seq,
 
631
                                                Decodedata_TCPFlags(data_from_illithid.flags),
 
632
                                                Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, (joined) ? W_MAINX2 : W_MAINX2/2 - 4));
 
633
                           } else
 
634
                              wprintw(data_joined, "%s", Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, (joined) ? W_MAINX2 : W_MAINX2/2 - 4));
 
635
 
 
636
                           pnoutrefresh(data_joined, scroll_yj,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
637
                           break;
 
638
         }
 
639
      }
 
640
   }
 
641
   else if ( current_illithid_data.source_ip == data_from_illithid.fast_source_ip)
 
642
   {
 
643
      if (log_source) { write(fileno(file_source), &data_from_illithid.data, data_from_illithid.datasize); fflush(file_source);}
 
644
      if (!stop)
 
645
         switch (view)
 
646
         {
 
647
            case ASCII_VIEW:
 
648
                           wprintw(data_source, "%s", Decodedata_GetAsciiData(data_from_illithid.data, data_from_illithid.datasize));
 
649
                           pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
650
                           break;
 
651
 
 
652
            case TEXT_VIEW:
 
653
                           wprintw(data_source, "%s", Decodedata_GetTextData(data_from_illithid.data, data_from_illithid.datasize));
 
654
                           pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
655
                           break;
 
656
 
 
657
            case EBCDIC_VIEW:
 
658
                           wprintw(data_source, "%s", Decodedata_GetEBCDICData(data_from_illithid.data, data_from_illithid.datasize));
 
659
                           pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
660
                           break;
 
661
        
 
662
            case HEX_VIEW:
 
663
                           if (data_from_illithid.proto == 'T')
 
664
                              wprintw(data_source, "\n> S %lx A %lx (%s) <\n%s",
 
665
                                                data_from_illithid.seq,
 
666
                                                data_from_illithid.ack_seq,
 
667
                                                Decodedata_TCPFlags(data_from_illithid.flags),
 
668
                                                Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, W_MAINX2/2 - 4));
 
669
                           else
 
670
                              wprintw(data_source, "%s", Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, W_MAINX2/2 - 4));
 
671
 
 
672
                           pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
673
                           break;
 
674
         }
 
675
   }
 
676
   else
 
677
   {
 
678
      if (log_dest) { write(fileno(file_dest), &data_from_illithid.data, data_from_illithid.datasize); fflush(file_dest);}
 
679
      if (!stop)
 
680
         switch (view)
 
681
         {
 
682
            case ASCII_VIEW:
 
683
                           wprintw(data_dest, "%s", Decodedata_GetAsciiData(data_from_illithid.data, data_from_illithid.datasize));
 
684
                           pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
685
                           break;
 
686
 
 
687
            case TEXT_VIEW:
 
688
                           wprintw(data_dest, "%s", Decodedata_GetTextData(data_from_illithid.data, data_from_illithid.datasize));
 
689
                           pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
690
                           break;
 
691
            
 
692
            case EBCDIC_VIEW:
 
693
                           wprintw(data_dest, "%s", Decodedata_GetEBCDICData(data_from_illithid.data, data_from_illithid.datasize));
 
694
                           pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
695
                           break;
 
696
 
 
697
            case HEX_VIEW:
 
698
                           if (data_from_illithid.proto == 'T')
 
699
                              wprintw(data_dest, "\n> S %lx A %lx (%s) <\n%s",
 
700
                                                data_from_illithid.seq,
 
701
                                                data_from_illithid.ack_seq,
 
702
                                                Decodedata_TCPFlags(data_from_illithid.flags),
 
703
                                                Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, W_MAINX2/2 - 4));
 
704
                           else
 
705
                              wprintw(data_dest, "%s", Decodedata_GetHexData(data_from_illithid.data, data_from_illithid.datasize, W_MAINX2/2 - 4));
 
706
 
 
707
                           pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
708
                           break;
 
709
         }
 
710
   }
 
711
 
 
712
   doupdate();
 
713
}
 
714
 
 
715
 
 
716
void Interface_Sniff_Data_DrawScroller(void)
 
717
{
 
718
   short sheight = (W_MAINY2-10)*(W_MAINY2-10)/PAD_BUFFER;
 
719
   short svpos = (W_MAINY2-6)*scroll_ys/PAD_BUFFER;
 
720
   short dvpos = (W_MAINY2-6)*scroll_yd/PAD_BUFFER;
 
721
   short jvpos = (W_MAINY2-6)*scroll_yj/PAD_BUFFER;
 
722
 
 
723
   sheight = (sheight < 1) ? 1 : sheight;
 
724
 
 
725
   svpos = (svpos == 0) ? 1 : svpos;
 
726
   svpos = (svpos > W_MAINY2-9-sheight) ? W_MAINY2-9-sheight : svpos;
 
727
 
 
728
   dvpos = (dvpos == 0) ? 1 : dvpos;
 
729
   dvpos = (dvpos > W_MAINY2-9-sheight) ? W_MAINY2-9-sheight : dvpos;
 
730
 
 
731
   jvpos = (jvpos == 0) ? 1 : jvpos;
 
732
   jvpos = (jvpos > W_MAINY2-9-sheight) ? W_MAINY2-9-sheight : jvpos;
 
733
 
 
734
   wattron(win_pointer, A_BOLD);
 
735
 
 
736
   if (joined)
 
737
   {
 
738
      wmove(data_joined_win, 1, W_MAINX2 - 5);
 
739
      wvline(data_joined_win, ACS_VLINE, W_MAINY2-10);
 
740
      wattron(data_joined_win, A_REVERSE);
 
741
      wmove(data_joined_win, jvpos, W_MAINX2 - 5);
 
742
      wvline(data_joined_win, ' ', sheight);
 
743
      wnoutrefresh(data_joined_win);
 
744
      wattroff(data_joined_win, A_REVERSE);
 
745
   }
 
746
   else
 
747
   {
 
748
      wmove(data_source_win, 1, W_MAINX2 / 2 - 3);
 
749
      wvline(data_source_win, ACS_VLINE, W_MAINY2-10);
 
750
      wattron(data_source_win, A_REVERSE);
 
751
      wmove(data_source_win, svpos, W_MAINX2 / 2 - 3);
 
752
      wvline(data_source_win, ' ', sheight);
 
753
      wnoutrefresh(data_source_win);
 
754
      wattroff(data_source_win, A_REVERSE);
 
755
 
 
756
      wmove(data_dest_win, 1, W_MAINX2 / 2 - 3);
 
757
      wvline(data_dest_win, ACS_VLINE, W_MAINY2-10);
 
758
      wattron(data_dest_win, A_REVERSE);
 
759
      wmove(data_dest_win, dvpos, W_MAINX2 / 2 - 3);
 
760
      wvline(data_dest_win, ' ', sheight);
 
761
      wnoutrefresh(data_dest_win);
 
762
      wattroff(data_dest_win, A_REVERSE);
 
763
   }
 
764
 
 
765
}
 
766
 
 
767
 
 
768
void Interface_Sniff_Data_Scroll(short direction)
 
769
{
 
770
 
 
771
   if (joined)
 
772
   {
 
773
      scroll_yj += direction;
 
774
      scroll_yj = (scroll_yj < 0) ? 0 : scroll_yj;
 
775
      scroll_yj = (scroll_yj > PAD_BUFFER - (W_MAINY2-10)) ? PAD_BUFFER - (W_MAINY2-10) : scroll_yj;
 
776
      pnoutrefresh(data_joined, scroll_yj, 0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 - 4);
 
777
      Interface_Sniff_Data_DrawScroller();
 
778
   }
 
779
   else
 
780
   {
 
781
 
 
782
      if (win_pointer == data_source_win)
 
783
      {
 
784
         scroll_ys += direction;
 
785
         scroll_ys = (scroll_ys < 0) ? 0 : scroll_ys;
 
786
         scroll_ys = (scroll_ys > PAD_BUFFER - (W_MAINY2-10)) ? PAD_BUFFER - (W_MAINY2-10) : scroll_ys;
 
787
         pnoutrefresh(data_source, scroll_ys,0, W_MAINY1 + 3, 3, W_MAINY2 - 3 , W_MAINX2 / 2 - 2);
 
788
         Interface_Sniff_Data_DrawScroller();
 
789
      }
 
790
      else
 
791
      {
 
792
         scroll_yd += direction;
 
793
         scroll_yd = (scroll_yd < 0) ? 0 : scroll_yd;
 
794
         scroll_yd = (scroll_yd > PAD_BUFFER - (W_MAINY2-10)) ? PAD_BUFFER - (W_MAINY2-10) : scroll_yd;
 
795
         pnoutrefresh(data_dest, scroll_yd,0, W_MAINY1 + 3, W_MAINX2 / 2 + 2, W_MAINY2 - 3 , W_MAINX2 - 2);
 
796
         Interface_Sniff_Data_DrawScroller();
 
797
      }
 
798
   }
 
799
 
 
800
   doupdate();
 
801
}
 
802
 
 
803
 
 
804
 
 
805
void Interface_Sniff_Data_Inject(char proto, char *app)
 
806
{
 
807
 
 
808
   INJECTED_DATA inject_data;
 
809
   int data_len;
 
810
 
 
811
   DEBUG_MSG("Interface_Sniff_Data_Inject");
 
812
 
 
813
   if (joined)
 
814
   {
 
815
      Interface_PopUp("Injection is not possible while in JOINED view");
 
816
      Interface_Sniff_Data_Redraw();
 
817
      return;
 
818
   }
 
819
 
 
820
   memset(&inject_data, 0, sizeof(INJECTED_DATA));
 
821
 
 
822
   data_len = Interface_Inject_Run(inject_data.data, proto, app);
 
823
   Interface_Sniff_Data_Redraw();
 
824
 
 
825
   inject_data.proto = proto;
 
826
   inject_data.datalen = data_len;
 
827
 
 
828
   if (data_len)
 
829
   {
 
830
      inject = 1;  // on exit the connection must be RSTted
 
831
 
 
832
      if (win_pointer == data_dest_win)
 
833
      {
 
834
         DEBUG_MSG("Interface_Sniff_Data_Inject -- INJECT -- %s", ipdest);
 
835
         inject_data.source_ip = inet_addr(ipsource);
 
836
         inject_data.dest_ip = inet_addr(ipdest);
 
837
         inject_data.source_port = htons(portsource);
 
838
         inject_data.dest_port = htons(portdest);
 
839
         write(pipe_inject[1], &inject_data, sizeof(INJECTED_DATA));
 
840
         wmove(bottom_window, 1, 30);
 
841
         wbkgdset(bottom_window, COLOR_PAIR(BOTTOM_COLOR));
 
842
         wprintw(bottom_window, "%d ", inject_tos += data_len);
 
843
         wbkgdset(bottom_window, COLOR_PAIR(SNIFF_COLOR));
 
844
         wprintw(bottom_window, "chars injected to %s", ipsource);
 
845
      }
 
846
      else
 
847
      {
 
848
         DEBUG_MSG("Interface_Sniff_Data_Inject -- INJECT -- %s", ipsource);
 
849
         inject_data.source_ip = inet_addr(ipdest);
 
850
         inject_data.dest_ip = inet_addr(ipsource);
 
851
         inject_data.source_port = htons(portdest);
 
852
         inject_data.dest_port = htons(portsource);
 
853
         write(pipe_inject[1], &inject_data, sizeof(INJECTED_DATA));
 
854
         wmove(bottom_window, 0, 30);
 
855
         wbkgdset(bottom_window, COLOR_PAIR(BOTTOM_COLOR));
 
856
         wprintw(bottom_window, "%d ", inject_tod += data_len);
 
857
         wbkgdset(bottom_window, COLOR_PAIR(SNIFF_COLOR));
 
858
         wprintw(bottom_window, "chars injected to %s", ipdest);
 
859
      }
 
860
   }
 
861
 
 
862
   wnoutrefresh(bottom_window);
 
863
 
 
864
   doupdate();
 
865
 
 
866
}
 
867
 
 
868
 
 
869
 
 
870
 
 
871
void Interface_Sniff_Data_Kill(char proto)
 
872
{
 
873
   KILL_DATA kill_data;
 
874
 
 
875
   if (proto == 'U')
 
876
   {
 
877
      Interface_PopUp("Trying to kill an UDP connection ?!? Hey Kiddie, go home !!");
 
878
      return;
 
879
   }
 
880
 
 
881
   DEBUG_MSG("Interface_Sniff_Data_Kill -- %s:%d -> %s:%d ", ipsource, portsource, ipdest, portdest);
 
882
 
 
883
   kill_data.source_ip = inet_addr(ipsource);
 
884
   kill_data.dest_ip = inet_addr(ipdest);
 
885
   kill_data.source_port = htons(portsource);
 
886
   kill_data.dest_port = htons(portdest);
 
887
   write(pipe_kill[1], &kill_data, sizeof(KILL_DATA));
 
888
 
 
889
   strcpy(Conn_Between_Hosts[Conn_Pointer].status, "KILLED");
 
890
 
 
891
   Interface_PopUp("Connection KILLED !!");
 
892
 
 
893
}
 
894
 
 
895
u_short Interface_Sniff_Data_WaitPort(void)
 
896
{
 
897
   while(Global_Binder_Port==0)
 
898
      usleep(500);
 
899
   return (Global_Binder_Port);
 
900
}
 
901
 
 
902
void Interface_Sniff_Data_Bind(char proto, char *ipsource, char *ipdest)
 
903
{
 
904
   u_long s_ip, d_ip;
 
905
                     
 
906
   if (joined) {
 
907
      Interface_PopUp("Can't bind while in joined view");
 
908
      return;
 
909
   }
 
910
           
 
911
   if (proto != 'T') {
 
912
      Interface_PopUp("You can only bind TCP connections");
 
913
      return;
 
914
   }
 
915
           
 
916
   if (binder_pipe == -1)
 
917
      binder_pipe = Buffer_Create(1.0e6);
 
918
           
 
919
   s_ip = inet_addr(ipsource);
 
920
   d_ip = inet_addr(ipdest);
 
921
               
 
922
   if (Binder_pid) ECThread_destroy(Binder_pid); 
 
923
   
 
924
   Global_Binder_Port = 0;
 
925
         
 
926
   if (win_pointer != data_source_win) { 
 
927
           Binder_pid = Binder_Start(s_ip, d_ip, portsource, portdest, proto);
 
928
      Interface_PopUp("Binded Connection D-to-S on port %d", Interface_Sniff_Data_WaitPort());
 
929
   } else {
 
930
      Binder_pid = Binder_Start(d_ip, s_ip, portdest, portsource, proto);
 
931
      Interface_PopUp("Binded Connection S-to-D on port %d", Interface_Sniff_Data_WaitPort());
 
932
   }
 
933
 
 
934
}
 
935
 
 
936
 
 
937
 
 
938
void Interface_Sniff_Data_Run(char *ips, int psource, char *ipd, int pdest, char *macs, char *macd, char proto, char *type, short mode, int connection)
 
939
{
 
940
   int KeyPress;
 
941
   int dimY = W_MAINY2 - W_MAINY1 - 3;
 
942
   int dimX = W_MAINX2 / 2 - 2;
 
943
#if defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H)
 
944
   struct pollfd poll_fd;
 
945
#else
 
946
   fd_set msk_fd;
 
947
   struct timeval TimeOut;
 
948
#endif
 
949
   struct in_addr addr;
 
950
   char macsource[20];
 
951
   char macdest[20];
 
952
   char app[18];
 
953
   
 
954
   Connection_Sniffed = connection;
 
955
   if (Options.buflen) ConnBuffer_Flush(Conn_Between_Hosts[Connection_Sniffed].DataBuffer);
 
956
 
 
957
   strlcpy(ipsource, ips, sizeof(ipsource));     // save locally because other threads can
 
958
   strlcpy(ipdest, ipd, sizeof(ipdest));         // realloc the array containing these values
 
959
   portsource = psource;
 
960
   portdest = pdest;
 
961
 
 
962
   strlcpy(macsource, macs, sizeof(macsource));
 
963
   strlcpy(macdest, macd, sizeof(macdest));
 
964
   strlcpy(app, type, sizeof(app));
 
965
 
 
966
   DEBUG_MSG("Interface_Sniff_Data_Run -- %d -- %c [%s:%d] [%s:%d] [%s] [%s]", mode, proto, ipsource, portsource, ipdest, portdest, macsource, macdest );
 
967
 
 
968
   data_source_win = newwin(dimY, dimX, W_MAINY1 + 2, 2);
 
969
   data_dest_win = newwin(dimY, dimX, W_MAINY1 + 2, W_MAINX2 / 2 + 1);
 
970
   data_source = newpad(PAD_BUFFER, dimX - 2);
 
971
   data_dest = newpad(PAD_BUFFER, dimX - 2);
 
972
 
 
973
   win_pointer = data_source_win;
 
974
 
 
975
   wbkgdset(data_source_win, COLOR_PAIR(SNIFF_COLOR));
 
976
   wbkgdset(data_dest_win, COLOR_PAIR(SNIFF_COLOR));
 
977
   wattron(data_source_win, A_BOLD);
 
978
 
 
979
   box(data_source_win,ACS_VLINE,ACS_HLINE);
 
980
   box(data_dest_win,ACS_VLINE,ACS_HLINE);
 
981
 
 
982
   mvwprintw(data_source_win, 0, 1, "%s:%d", ipsource, portsource);
 
983
   mvwprintw(data_dest_win, 0, 1, "%s:%d", ipdest, portdest);
 
984
 
 
985
   mvwprintw(data_source_win, 0, W_MAINX2 / 2 - 10, "active");
 
986
 
 
987
   scrollok(data_source, TRUE);
 
988
   scrollok(data_dest, TRUE);
 
989
 
 
990
   scroll_yd = PAD_BUFFER - (W_MAINY2-10);
 
991
   scroll_ys = PAD_BUFFER - (W_MAINY2-10);
 
992
 
 
993
   wmove(data_source, scroll_ys, 0);
 
994
   wmove(data_dest, scroll_yd, 0);
 
995
 
 
996
   wbkgdset(main_window, COLOR_PAIR(MAIN_COLOR));
 
997
 
 
998
   Interface_Sniff_Data_DrawScroller();
 
999
 
 
1000
   werase(main_window);
 
1001
   werase(bottom_window);
 
1002
 
 
1003
   wmove(bottom_window, 0, 1);
 
1004
   wbkgdset(bottom_window, COLOR_PAIR(SNIFF_COLOR));
 
1005
   wprintw(bottom_window, "Protocol: ");
 
1006
   wbkgdset(bottom_window, COLOR_PAIR(BOTTOM_COLOR));
 
1007
   if (proto == 'T')
 
1008
      wprintw(bottom_window, "TCP");
 
1009
   else
 
1010
      wprintw(bottom_window, "UDP");
 
1011
   wmove(bottom_window, 1, 1);
 
1012
   wbkgdset(bottom_window, COLOR_PAIR(SNIFF_COLOR));
 
1013
   wprintw(bottom_window, "Application: ");
 
1014
   wbkgdset(bottom_window, COLOR_PAIR(BOTTOM_COLOR));
 
1015
   wprintw(bottom_window, "%s", app);
 
1016
 
 
1017
   redrawwin(main_window);
 
1018
   wnoutrefresh(main_window);
 
1019
   wnoutrefresh(bottom_window);
 
1020
 
 
1021
   wnoutrefresh(data_source_win);
 
1022
   wnoutrefresh(data_dest_win);
 
1023
   doupdate();
 
1024
 
 
1025
   if (Options.hexview)
 
1026
   {
 
1027
      view = HEX_VIEW;
 
1028
      Options.hexview = 0;
 
1029
   }
 
1030
 
 
1031
   Interface_Sniff_Data_View(view);    // default view
 
1032
 
 
1033
#if defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H)
 
1034
   poll_fd.fd = 0;
 
1035
   poll_fd.events = POLLIN;
 
1036
#else
 
1037
   memset(&TimeOut, 0, sizeof(TimeOut));  //  timeout = 0
 
1038
   FD_ZERO(&msk_fd);
 
1039
#endif
 
1040
 
 
1041
   current_illithid_data.proto = proto;
 
1042
   current_illithid_data.source_port = portsource;
 
1043
   current_illithid_data.dest_port = portdest;
 
1044
 
 
1045
   if (inet_aton(ipsource, &addr))
 
1046
      current_illithid_data.source_ip = ntohl(addr.s_addr);
 
1047
   if (inet_aton(ipdest, &addr))
 
1048
      current_illithid_data.dest_ip =  ntohl(addr.s_addr);
 
1049
 
 
1050
   if (!Options.buflen) Buffer_Flush(pipe_with_illithid_data);
 
1051
 
 
1052
   LOOP {
 
1053
 
 
1054
      Interface_Sniff_Data_SniffData();
 
1055
 
 
1056
#ifdef PERMIT_PLUGINS
 
1057
      Interface_Plugins_PluginOutput();
 
1058
#endif
 
1059
 
 
1060
#if defined(HAVE_SYS_POLL_H) || defined(HAVE_POLL_H)
 
1061
      poll(&poll_fd, 1, 1);
 
1062
      if (poll_fd.revents & POLLIN)
 
1063
#else
 
1064
      FD_SET(0, &msk_fd);
 
1065
      select(FOPEN_MAX, &msk_fd, (fd_set *) 0, (fd_set *) 0, &TimeOut);
 
1066
      if (FD_ISSET(0, &msk_fd))
 
1067
#endif
 
1068
      {
 
1069
 
 
1070
#ifdef PERMIT_PLUGINS
 
1071
         Interface_Plugins_HidePluginOutput();
 
1072
#endif
 
1073
 
 
1074
         KeyPress = wgetch(main_window);
 
1075
 
 
1076
         switch (KeyPress)
 
1077
         {
 
1078
            case KEY_DOWN:
 
1079
                  Interface_Sniff_Data_Scroll( +1 );
 
1080
                  break;
 
1081
 
 
1082
            case KEY_UP:
 
1083
                  Interface_Sniff_Data_Scroll( -1 );
 
1084
                  break;
 
1085
 
 
1086
            case KEY_NPAGE:
 
1087
                  Interface_Sniff_Data_Scroll( W_MAINY2-10 );     //PGDOWN
 
1088
                  break;
 
1089
 
 
1090
            case KEY_PPAGE:
 
1091
                  Interface_Sniff_Data_Scroll( -(W_MAINY2-10) );  //PGUP
 
1092
                  break;
 
1093
 
 
1094
            case 'L':
 
1095
            case 'l':
 
1096
                  Interface_Sniff_Data_LogToFile(proto);
 
1097
                  Interface_Sniff_Data_Reset();
 
1098
                  break;
 
1099
 
 
1100
            case 'A':
 
1101
            case 'a':
 
1102
                  Interface_Sniff_Data_View(ASCII_VIEW);
 
1103
                  Interface_Sniff_Data_Reset();
 
1104
                  break;
 
1105
 
 
1106
            case 'X':
 
1107
            case 'x':
 
1108
                  Interface_Sniff_Data_View(HEX_VIEW);
 
1109
                  Interface_Sniff_Data_Reset();
 
1110
                  break;
 
1111
 
 
1112
            case 'T':
 
1113
            case 't':
 
1114
                  Interface_Sniff_Data_View(TEXT_VIEW);
 
1115
                  Interface_Sniff_Data_Reset();
 
1116
                  break;
 
1117
 
 
1118
            case 'J':
 
1119
            case 'j':
 
1120
                  Interface_Sniff_Data_View(JOINED_VIEW);
 
1121
                  Interface_Sniff_Data_Reset();
 
1122
                  break;
 
1123
 
 
1124
            case 'E':
 
1125
            case 'e':
 
1126
                  Interface_Sniff_Data_View(EBCDIC_VIEW);
 
1127
                  Interface_Sniff_Data_Reset();
 
1128
                  break;
 
1129
 
 
1130
            case 'S':
 
1131
            case 's':
 
1132
                  Interface_Sniff_Data_StopCont();
 
1133
                  break;
 
1134
 
 
1135
            case 'I':
 
1136
            case 'i':
 
1137
                  if ( mode == ARPBASED )
 
1138
                  {
 
1139
                     if (strstr(app, "ssh") || strstr(app, "SSH") || strstr(app, "HTTPS"))
 
1140
                     {
 
1141
                        Interface_PopUp("You CAN'T inject in a crypted connection !!");
 
1142
                        Interface_Sniff_Data_Redraw();
 
1143
                     }
 
1144
                     else
 
1145
                        Interface_Sniff_Data_Inject(proto, app);
 
1146
                  }
 
1147
                  else
 
1148
                  {
 
1149
                     Interface_PopUp("Characters injection is only supported in ARP Based mode !!");
 
1150
                     Interface_Sniff_Data_Redraw();
 
1151
                  }
 
1152
                  break;
 
1153
 
 
1154
            case 'F':
 
1155
            case 'f':
 
1156
                  Interface_Inject_SetFilter(mode);
 
1157
                  Interface_Sniff_Data_Redraw();
 
1158
                  break;
 
1159
 
 
1160
            case 'K':
 
1161
            case 'k':
 
1162
                  Interface_Sniff_Data_Kill(proto);
 
1163
                  Interface_Sniff_Data_Redraw();
 
1164
                  break;
 
1165
 
 
1166
            case KEY_TAB:
 
1167
                  Interface_Sniff_Data_KeyTab();
 
1168
                  break;
 
1169
 
 
1170
            case KEY_CTRL_L:  // CTRL+L refresh the screen
 
1171
                  Interface_Sniff_Data_Redraw();
 
1172
                  break;
 
1173
 
 
1174
#ifdef PERMIT_PLUGINS
 
1175
            case 'P':
 
1176
            case 'p':
 
1177
                     Interface_Plugins_Run();
 
1178
                     Interface_Sniff_Data_Redraw();
 
1179
                     break;
 
1180
#endif
 
1181
            case 'B':
 
1182
            case 'b':
 
1183
                     Interface_Sniff_Data_Bind(proto, ipsource, ipdest);
 
1184
                     Interface_Sniff_Data_Redraw();
 
1185
                     break;
 
1186
 
 
1187
            case KEY_F(1):
 
1188
            case 'H':
 
1189
            case 'h':{
 
1190
                        static char *help[] = {
 
1191
                        "[qQ][F10] - quit (and stop sniffing)",
 
1192
                        "[tab]     - switch between windows",
 
1193
                        "[pgUp]    - scroll back (as well as UpArrow)",
 
1194
                        "[pgDw]    - scroll forward (as well as DownArrow)",
 
1195
                        "[iI]      - inject characters in the connection",
 
1196
                        "[fF]      - set/edit filters chains",
 
1197
#ifdef PERMIT_PLUGINS
 
1198
                        "[pP]      - run a plugin",
 
1199
#endif
 
1200
                        "[kK]      - kill the connection (be careful !)",
 
1201
                        "[aA]      - ASCII view",
 
1202
                        "[xX]      - HEX view",
 
1203
                        "[tT]      - TEXT (readable chars) only view",
 
1204
                        "[eE]      - EBCDIC view",
 
1205
                        "[jJ]      - join the two windows",
 
1206
                        "[sS]      - stop/cont the sniff (only visualization)",
 
1207
                        "[lL]      - Log to file",
 
1208
                        "[bB]      - Bind the sniffed data to a port",
 
1209
                        NULL};
 
1210
                        Interface_HelpWindow(help);
 
1211
                     }
 
1212
                     Interface_Sniff_Data_Redraw();
 
1213
                  break;
 
1214
 
 
1215
            case KEY_F(10):
 
1216
            case 'Q':
 
1217
            case 'q':
 
1218
                     if (log_dest) fclose(file_dest);
 
1219
                     if (log_source) fclose(file_source);
 
1220
                     if (log_joined) fclose(file_joined);
 
1221
                     if (Binder_pid) ECThread_destroy(Binder_pid);    
 
1222
                     Binder_pid = 0;
 
1223
                     log_dest = log_source = log_joined = 0;
 
1224
                     stop = 0;
 
1225
                     inject_tod=0; inject_tos=0;  // reset counter
 
1226
                     delwin(data_source_win);
 
1227
                     data_source_win = NULL;    // for winching (see ec_signal.c)
 
1228
                     wbkgdset(bottom_window, COLOR_PAIR(BOTTOM_COLOR));
 
1229
                     wmove(top_window, 2, 55);
 
1230
                     whline(top_window, ' ', 20);
 
1231
                     if (joined)
 
1232
                     {
 
1233
                        delwin(data_joined_win);
 
1234
                        delwin(data_joined);
 
1235
                        joined = 0;
 
1236
                     }
 
1237
                     delwin(data_dest_win);
 
1238
                     delwin(data_source);
 
1239
                     delwin(data_dest);
 
1240
                     werase(bottom_window);
 
1241
                     wnoutrefresh(top_window);
 
1242
                     wnoutrefresh(bottom_window);
 
1243
                     wnoutrefresh(main_window);
 
1244
                     doupdate();
 
1245
                     DEBUG_MSG("Interface_Sniff_Data_End");
 
1246
                     return;
 
1247
                  break;
 
1248
         }
 
1249
      }
 
1250
 
 
1251
   }
 
1252
 
 
1253
}
 
1254
 
 
1255
 
 
1256
 
 
1257
#endif
 
1258
 
 
1259
/* EOF */
 
1260
 
 
1261
// vim:ts=3:expandtab
 
1262