• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

NathanGibbs3 / BASE / 584

pending completion
584

push

travis-ci-com

NathanGibbs3
20230412 Fix CI build breakage.
         Related Issue(s) #158

2 of 2 new or added lines in 1 file covered. (100.0%)

2594 of 16816 relevant lines covered (15.43%)

20.97 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/base_qry_alert.php
1
<?php
2
/*******************************************************************************
3
** Basic Analysis and Security Engine (BASE)
4
** Copyright (C) 2004 BASE Project Team
5
** Copyright (C) 2000 Carnegie Mellon University
6
**
7
** (see the file 'base_main.php' for license details)
8
**
9
** Project Leads: Kevin Johnson <kjohnson@secureideas.net>
10
** Built upon work by Roman Danyliw <rdd@cert.org>, <roman@danyliw.com>
11
**
12
** Purpose: displays a single alert   
13
**
14
** Input GET/POST variables
15
**   - caller
16
**   - submit:
17
********************************************************************************
18
** Authors:
19
********************************************************************************
20
** Kevin Johnson <kjohnson@secureideas.net
21
**
22
********************************************************************************
23
*/
24

25
include ("base_conf.php");
×
26
include_once ("$BASE_path/includes/base_constants.inc.php");
×
27
include ("$BASE_path/includes/base_include.inc.php");
×
28
include_once ("$BASE_path/base_db_common.php");
×
29
include_once ("$BASE_path/base_qry_common.php");
×
30
include_once ("$BASE_path/base_stat_common.php");
×
31

32
AuthorizedRole(10000);
×
33
$payload = FALSE;
×
34
$offset  = 0;
×
35
if ( isset($_GET['asciiclean']) ){ // Set cookie for packet display
×
36
        1 == $_GET['asciiclean'] ? setcookie('asciiclean', 'clean') : setcookie('asciiclean', 'normal');
×
37
}
38
$sf_portscan_flag = 0;
×
39

40
function PrintCleanURL(){
41
        // This function creates the url to display the cleaned up payload -- Kevin
42
        $query = CleanVariable($_SERVER["QUERY_STRING"], VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER);
×
43
        $sort_order=ImportHTTPVar("sort_order", VAR_LETTER | VAR_USCORE);
×
44
        $url = '<center><a href="base_qry_alert.php?' . $query;
×
45
        $url .= '&amp;sort_order='.urlencode($sort_order).'&amp;asciiclean=';
×
46
        if ( GetAsciiClean() ){ // Create link to non-cleaned payload display.
×
47
                $url.= '0">'._QANORMALD;
×
48
        }else{ // Create link to cleaned payload display.
×
49
                $url.= '1">'._QAPLAIND;
×
50
        }
51
        $url.= '</a></center>';
×
52
        return $url;
×
53
}
54

55
function PrintBinDownload( $db, $cid, $sid ){
56
        // Offering a URL to a download possibility:
57
        if ( GetAsciiClean() ){
×
58
                $tmp = 1;
×
59
        } else {
×
60
                $tmp = 0;
×
61
        }
62
        $query = CleanVariable($_SERVER["QUERY_STRING"], VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER);
×
63
        $url = '<center><a href="base_payload.php?' . $query;
×
64
        $url .= '&amp;download=1';
×
65
        $url .= '&amp;cid='.urlencode($cid).'&amp;sid='.urlencode($sid);
×
66
        $url .= '&amp;asciiclean=' . $tmp;
×
67
        $url.= '">Download of Payload</a></center>';
×
68
        return $url;
×
69
}
70

71
function PrintPcapDownload( $db, $cid, $sid ){
72
        if (!isset($db))
×
73
        {
74
                error_log("ERROR: \$db is NOT set.");
×
75
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db is NOT set. Ignoring.");
×
76
    $debug_str = "<BR><PRE>\n\n" . debug_print_backtrace() . "\n\n</PRE><BR>\n";
×
77
    ErrorMessage($debug_str);
×
78
        }
79

80

81
        if (!isset($db->DB))
×
82
        {
83
                error_log("ERROR: \$db->DB is NOT set.");
×
84
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db->DB is NOT set. Ignoring.");
×
85
    $debug_str = "<BR><PRE>\n\n" . debug_print_backtrace() . "\n\n</PRE><BR>\n";
×
86
    ErrorMessage($debug_str);
×
87
        }
88

89
        if (!is_array($db->DB->MetaColumnNames('data')))
×
90
        {
91
                error_log("ERROR: \$db->DB->MetaColumnNames('data') is NOT an array.");
×
92
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db->DB->MetaColumnNames('data') is NOT an array. Ignoring.");
×
93
                print "<BR><PRE>\n\n";
×
94
                debug_print_backtrace();
×
95
                print "\n\n" ;
×
96
                var_dump($db->DB->MetaColumnNames('data'));
×
97
                print "</PRE><BR>\n\n" ;
×
98
        }
99

100

101
   if ( !in_array("pcap_header", $db->DB->MetaColumnNames('data')) ||
×
102
        !in_array("data_header", $db->DB->MetaColumnNames('data'))) {
×
103
      $type = 3;
×
104
   } else {
×
105
      $type = 2;
×
106
   }
107

108
        if ( GetAsciiClean() ){
×
109
                $tmp = 1;
×
110
        } else {
×
111
                $tmp = 0;
×
112
        }
113
        $query = CleanVariable($_SERVER["QUERY_STRING"], VAR_PERIOD | VAR_DIGIT | VAR_PUNC | VAR_LETTER);
×
114
        $url = '<center><a href="base_payload.php?' . $query;
×
115
        $url .= '&amp;download='.urlencode($type);
×
116
        $url .= '&amp;cid='.urlencode($cid).'&amp;sid='.urlencode($sid);
×
117
        $url .= '&amp;asciiclean=' . $tmp;
×
118
        $url .= '">Download in pcap format</a></center>';
×
119
        return $url;
×
120
}
121

122
function PrintPacketLookupBrowseButtons( $seq, $sql, $db, &$p_b, &$n_b ){
123
        GLOBAL $debug_mode;
124
        $EMPfx = __FUNCTION__ . ': ';
×
125
        if ( !is_int($seq) ){ // Input Validation
×
126
                $seq = 0;
×
127
        }
128
        NLIO ("<!-- Single Alert Browsing Buttons -->");
×
129
        if ( $seq > 0 ){
×
130
                $start = $seq -1;
×
131
        }else{
×
132
                $start = $seq;
×
133
        }
134
        if ( $debug_mode > 0 ){
×
135
                ErrorMessage (
×
136
                        $EMPfx. "Execute SQL: $sql LIMIT $start, 3",'black',1
×
137
                );
138
        }
139
        $rs = $db->baseExecute($sql, $start, 3);
×
140
        if (
×
141
                $rs != false
142
                && $db->baseErrorMessage() == ''
×
143
                && $rs->baseRecordCount() > 0
×
144
        ){ // Error Check
145
                if ( $debug_mode > 1 ){
×
146
                        ErrorMessage (
×
147
                                $EMPfx. "Records: ".$rs->baseRecordCount(),'black', 1
×
148
                        );
149
                }
150
                if ( $seq == 0 ){
×
151
                        $p_b = '[ '._FIRST.' ]'."\n";
×
152
                }
153
                $Pfx = "<INPUT TYPE='submit' NAME='submit' VALUE='";
×
154
                for ( $i = $start; $i <= $seq + 1; $i++  ){
×
155
                        $row = $rs->baseFetchRow();
×
156
                        if ( $debug_mode > 1 ){
×
157
                                ErrorMessage ("# $i - $seq", 'black',1);
×
158
                                var_dump($row);
×
159
                        }
160
                        if ( $row == '' ){
×
161
                                $n_b = '[ '._LAST.' ]'."\n";
×
162
                                break;
×
163
                        }
164
                        $Sfx = '-('.$row[0].'-'.$row[1].")'>";
×
165
                        if ( $i == $seq - 1 ){
×
166
                                $p_b = $Pfx."&lt;&lt; "._PREVIOUS." #".($seq-1).$Sfx;
×
167
                        }elseif ( $i == $seq + 1 ){
×
168
                                $n_b = $Pfx."&gt;&gt; "._NEXT." #".($seq+1).$Sfx;
×
169
                        }
170
                }
171
                $rs->baseFreeRows();
×
172
                if ( $debug_mode > 1 ){
×
173
                        ErrorMessage ( $EMPfx. "Ret-P: ".XSSPrintSafe($p_b),'black',1 );
×
174
                        ErrorMessage ( $EMPfx. "Ret-N: ".XSSPrintSafe($n_b),'black',1 );
×
175
                }
176
        }else{
×
177
                ErrorMessage ($EMPfx. "BASE DB Error: ".$db->baseErrorMessage() == '');
×
178
        }
179
}
180

181
$sort_order = ImportHTTPVar( 'sort_order', VAR_LETTER | VAR_USCORE );
×
182
// Need to import $submit and set the $QUERY_STRING early to support the back
183
// button. Otherwise, the value of $submit will not be passed to the history.
184
//
185
// $submit can contain values in the form of  "#xx-(xx-xx)" and
186
// other "submit" values.
187
$submit = ImportHTTPVar(
×
188
        'submit', VAR_DIGIT | VAR_PUNC | VAR_LETTER,
×
189
        array(_SELECTED, _ALLONSCREEN, _ENTIREQUERY)
×
190
);
191
$_SERVER["QUERY_STRING"] = "submit=".rawurlencode($submit);
×
192

193
  $et = new EventTiming($debug_time_mode);
×
194
  $cs = new CriteriaState("base_qry_main.php", "&amp;new=1&amp;submit="._QUERYDBP);
×
195
  $cs->ReadState();
×
196

197
  $qs = new QueryState();
×
198
$qs->current_sort_order = $sort_order;
×
199

200
  $page_title = _ALERT;
×
201
  PrintBASESubHeader($page_title, $page_title, $cs->GetBackLink(), $refresh_all_pages);
×
202
$db = NewBASEDBConnection($DBlib_path, $DBtype); // Connect to Alert DB.
×
203
$db->baseDBConnect(
×
204
        $db_connect_method,$alert_dbname, $alert_host, $alert_port, $alert_user,
205
        $alert_password
206
);
207
UpdateAlertCache($db);
×
208
if ( class_exists('UILang') ){ // Issue 11 backport shim.
×
209
        $CPSig = $UIL->CWA['Sig'];
×
210
        $CPSA = $UIL->CPA['SrcAddr'];
×
211
        $CPDA = $UIL->CPA['DstAddr'];
×
212
        $CPTs = $UIL->CWA['Ts'];
×
213
}else{
×
214
        $CPSig = _SIGNATURE;
×
215
        $CPSA = _NBSOURCEADDR;
×
216
        $CPDA = _NBDESTADDR;
×
217
        $CPTs = _TIMESTAMP;
×
218
}
219

220
  PrintCriteria("");
×
221
  $criteria_clauses = ProcessCriteria();  
×
222

223
  $from = " FROM acid_event ".$criteria_clauses[0];
×
224
  $where = " WHERE ".$criteria_clauses[1];
×
225

226
  $qs->AddValidAction("ag_by_id");
×
227
  $qs->AddValidAction("ag_by_name");
×
228
  $qs->AddValidAction("add_new_ag");
×
229
  $qs->AddValidAction("del_alert");
×
230
  $qs->AddValidAction("email_alert");
×
231
  $qs->AddValidAction("email_alert2");
×
232
  $qs->AddValidAction("archive_alert");
×
233
  $qs->AddValidAction("archive_alert2");
×
234

235
  $qs->AddValidActionOp(_SELECTED);
×
236

237
  $qs->SetActionSQL($from.$where);
×
238
 
239
  $et->Mark("Initialization");
×
240

241
  $qs->RunAction($submit, PAGE_ALERT_DISPLAY, $db);
×
242
  $et->Mark("Alert Action");
×
243

244
  /* If get a valid (sid,cid) store it in $caller.  
245
   * But if $submit is returning from an alert action 
246
   * get the (sid,cid) back from $caller 
247
   */ 
248
  if ( $submit == _SELECTED )
×
249
     $submit = ImportHTTPVar("caller", VAR_DIGIT | VAR_PUNC);
×
250
  else
×
251
     $caller = $submit;
×
252

253
  /* Setup the Query Results Table -- However, this data structure is not
254
   * really used for output.  Rather, it duplicates the sort SQL set in
255
   *  base_qry_sqlcalls.php 
256
   */
257
  $qro = new QueryResultsOutput("");
×
258
        // Common SQL Strings
259
        $OB = ' ORDER BY';
×
260
        $qro->AddTitle($CPSig,
×
261
                "sig_a", " ", "$OB sig_name ASC",
×
262
                "sig_d", " ", "$OB sig_name DESC"
×
263
        );
264
        $qro->AddTitle($CPTs,
×
265
                "time_a", " ", "$OB timestamp ASC ",
×
266
                "time_d", " ", "$OB timestamp DESC "
×
267
        );
268
        $qro->AddTitle($CPSA,
×
269
                "sip_a", " ", "$OB ip_src ASC",
×
270
                "sip_d", " ", "$OB ip_src DESC"
×
271
        );
272
        $qro->AddTitle($CPDA,
×
273
                "dip_a", " ", "$OB ip_dst ASC",
×
274
                "dip_d", " ", "$OB ip_dst DESC"
×
275
        );
276
        $qro->AddTitle(_NBLAYER4,
×
277
                "proto_a", " ", "$OB ip_proto ASC",
×
278
                "proto_d", " ", "$OB ip_proto DESC"
×
279
        );
280

281
// Issue #168
282
$save_sql = "SELECT acid_event.sid, acid_event.cid";
×
283
$sqlPFX = $from.$where;
×
284
$sort_sql = $qro->GetSortSQL($qs->GetCurrentSort(), $qs->GetCurrentCannedQuerySort());
×
285
if ( !is_null($sort_sql) ){
×
286
        $sqlPFX = $sort_sql[0].$sqlPFX.$sort_sql[1];
×
287
}
288
$save_sql .= $sqlPFX;
×
289
GetQueryResultID($submit, $seq, $sid, $cid);
×
290
if ( $debug_mode > 0 ){
×
291
        if ( $qs->isCannedQuery() ){
×
292
                $CCF = 'Yes';
×
293
                $qs->PrintCannedQueryList();
×
294
        }else{
×
295
                $CCF = 'No';
×
296
        }
297
        print "Canned Query: $CCF <br/>";
×
298
        $qs->DumpState();
×
299
        print "SQL Saved: $save_sql <br/>";
×
300
        $TK = array ( 'submit', 'sid', 'cid', 'seq' );
×
301
        $DI = array();
×
302
        $DD = array();
×
303
        foreach ( $TK as $val ){
×
304
                array_push($DD, $val);
×
305
                array_push($DI, $$val);
×
306
        }
307
        DDT($DI,$DD,'Alert Lookup ','',25);
×
308
}
309

310
        // Verify (sid, cid) are extracted correctly.
311
        if ( is_int($sid) && is_int($cid) && !($sid > 0 && $cid > 0) ){
×
312
                // Added is_int checks as Issue #5 fix. If the above call to
313
                // GetQueryResultID() fails, $sid & $cid will be defined but unset,
314
                // which makes them of type string on PHP 5.2x & of type NULL on PHP
315
                // 5.3+ See: https://travis-ci.org/NathanGibbs3/BASE/jobs/546765554
316
                // This should only occur in the test conditions for Issue #5. This
317
                // fix allows $sid, & $cid of any type except int to pass through
318
                // without exiting the app while under test.
319
                // Note if this breaks something in production.
320
                // Comment at: https://github.com/NathanGibbs3/BASE/issues/5
321
                FatalError(_QAINVPAIR." (".$sid.",".$cid.")");
×
322
        }else{
×
323
                if ( getenv('TRAVIS') && version_compare(PHP_VERSION, "5.3.0", "<") ){
×
324
                        // Issue #5 Test Shim
325
                        $sid = 1;
×
326
                        $cid = 1;
×
327
                }
328
        }
329
PrintPacketLookupBrowseButtons($seq, $save_sql, $db, $previous, $next);
×
330
  echo "<FORM METHOD=\"GET\" ACTION=\"base_qry_alert.php\">\n"; 
×
331
  echo "<CENTER>\n<B>"._ALERT." #".($seq)."</B><BR>\n$previous &nbsp&nbsp&nbsp\n$next\n</CENTER>\n";
×
332
  echo "<HR>\n";
×
333

334
  /* Make Selected */
335
  echo "\n<INPUT TYPE=\"hidden\" NAME=\"action_chk_lst[0]\" VALUE=\"$submit\">\n";
×
336

337
  /* Event */
338
  $sql2 = "SELECT signature, timestamp FROM acid_event WHERE sid='".filterSql($sid)."' AND cid='".filterSql($cid)."'";
×
339
        if ( $debug_mode > 0 ){
×
340
                print "<BR><BR>\n\n" . __FILE__ . ":" . __LINE__ . ": DEBUG: \$sql2 = \"$sql2\"<BR><BR>\n\n";
×
341
        }
342
  $result2 = $db->baseExecute($sql2);
×
343
  $myrow2 = $result2->baseFetchRow();
×
344
        if ( is_array($myrow2) ){
×
345
                if ( $myrow2[0] == "" ){
×
346
                        print '<center><b>'.returnErrorMessage(_QAALERTDELET).'</center></b>';
×
347
                }
348
                $Alert_Time = $myrow2[1];
×
349
                $Alert_Sig = $myrow2[0];
×
350
        }else{
×
351
                $Alert_Time = 'Testing';
×
352
                $Alert_Sig = 'Testing';
×
353
        }
354
  /* Get sensor parameters: */
355
  $sql4 = "SELECT hostname, interface, filter, encoding, detail FROM sensor  WHERE sid='".filterSql($sid)."'";
×
356
  $result4 = $db->baseExecute($sql4);
×
357
  $myrow4 = $result4->baseFetchRow();
×
358
  $result4->baseFreeRows();
×
359
        if ( is_array($myrow4) ){
×
360
                $Sensor_Name = $myrow4[0];
×
361
                if ( $myrow4[1] == "" ){
×
362
                        $Sensor_Int = "&nbsp;<I>"._NONE."</I>&nbsp;";
×
363
                }else{
×
364
                        $Sensor_Int = $myrow4[1];
×
365
                }
366
                if ( $myrow4[2] == "" ){
×
367
                        $Sensor_Filt = "&nbsp;<I>"._NONE."</I>&nbsp;";
×
368
                }else{
×
369
                        $Sensor_Filt = $myrow4[2];
×
370
                }
371
                $encoding = $myrow4[3];
×
372
                $detail = $myrow4[4];
×
373
        }else{
×
374
                $Sensor_Name = _NONE;
×
375
                $Sensor_Int = _NONE;
×
376
                $Sensor_Filt = _NONE;
×
377
                $encoding = 2;
×
378
                $detail = 1;
×
379
        }
380
  echo '
×
381
       <BLOCKQUOTE>
382
       <TABLE BORDER=1 width="90%">
383
          <TR><TD CLASS="metatitle" WIDTH=50 ALIGN=CENTER ROWSPAN=4>Meta
384
              <TD>
385
                  <TABLE BORDER=1 CELLPADDING=4>
386
                    <TR><TD CLASS="plfieldhdr" >'._ID.' #</TD>
387
                        <TD CLASS="plfieldhdr">'._CHRTTIME.'</TD>
388
                        <TD CLASS="plfieldhdr">'._QATRIGGERSIG.'</TD></TR>
389
                    <TR><TD CLASS="plfield">'.($sid." - ".$cid).'</TD>
390
                    <TD CLASS="plfield">'.htmlspecialchars($Alert_Time).'</TD>
×
391
                        <TD CLASS="plfield">'.(GetTagTriger(BuildSigByID($Alert_Sig, $db), $db, $sid, $cid)).'</TD></TR>
×
392
                  </TABLE>
393
              </TD>
394
           </TR>';
395

396
  echo '  <TR>
×
397
             <TD>
398
                <TABLE BORDER=1 CELLPADDING=4>
399
                  <TR><TD CLASS="metatitle" ALIGN=CENTER ROWSPAN=2>'._SENSOR.'</TD>
400
                       <TD class="plfieldhdr">',_SENSOR.' '._ADDRESS,'</TD>
×
401
                       <TD class="plfieldhdr">'._INTERFACE.'</TD>
402
                       <TD class="plfieldhdr">'._FILTER.'</TD>
403
                  </TR>
404
                  <TR><TD class="plfield">'.htmlspecialchars($Sensor_Name).'</TD>
×
405
                      <TD class="plfield">'.$Sensor_Int.'</TD>
406
                      <TD class="plfield">'.$Sensor_Filt.'</TD>
407
                  </TR>
408
                 </TABLE>     
409
          </TR>';
410

411
        if ( isset($resolve_IP) && $resolve_IP == 1 ){
×
412
     echo '  <TR>
×
413
              <TD>
414
                <TABLE BORDER=1 CELLPADDING=4>
415
                  <TR><TD CLASS="iptitle" ALIGN=CENTER ROWSPAN=2>FQDN</TD>
416
                       <TD class="plfieldhdr">'._SENSOR.' '._NAME.'</TD>
417
                  </TR>
418
                  <TR><TD class="plfield">';
419
     # Is this a dotted IPv4 address?
420
     $pattern = '/(\d{1,3}\.){3}\d{1,3}/';
×
421
     if (preg_match($pattern, $myrow4[0]))
×
422
     {
423
       echo baseGetHostByAddr($myrow4[0], $db, $dns_cache_lifetime);
×
424
     }
425
     else
×
426
     {
427
       echo $myrow4[0];
×
428
     }
429
     echo '           </TD>
×
430
                  </TR>
431
                 </TABLE>     
432
            </TR>';
433
        }
434
        $result4->baseFreeRows();
×
435
  $sql4 = "SELECT acid_ag_alert.ag_id, ag_name, ag_desc ".
×
436
          "FROM acid_ag_alert LEFT JOIN acid_ag ON acid_ag_alert.ag_id = acid_ag.ag_id ".
437
          "WHERE ag_sid='".$sid."' AND ag_cid='".$cid."'";
438
  $result4 = $db->baseExecute($sql4);
×
439
  $num = $result4->baseRecordCount();
×
440

441
  echo ' <TR>
×
442
           <TD>
443
             <TABLE BORDER=1 CELLPADDING=4>
444
               <TR><TD CLASS="metatitle" ALIGN=CENTER ROWSPAN='.($num+1).'>'._ALERTGROUP.'</TD>';
445
  
446
  if ( $num > 0 )
×
447
     echo '        <TD class="plfieldhdr">'._ID.'</TD>
×
448
                   <TD class="plfieldhdr">'._NAME.'</TD>
449
                   <TD class="plfieldhdr">'._DESC.'</TD></TR>';  
450
  else
×
451
     echo '        <TD>&nbsp;&nbsp;<I>'._NONE.'</I>&nbsp;</TD></TR>';
×
452

453
  for ($i = 0; $i < $num; $i++)
×
454
  {
455
     $myrow4 = $result4->baseFetchRow();
×
456

457
     echo '    <TR><TD class="plfield">'.htmlspecialchars($myrow4[0]).'</TD>
×
458
                   <TD class="plfield">'.htmlspecialchars($myrow4[1]).'</TD>
×
459
                   <TD class="plfield">'.htmlspecialchars($myrow4[2]).'</TD>
×
460
               </TR>';
461
  }
462
  echo '      </TABLE>';
×
463
  $result4->baseFreeRows();
×
464

465
  echo '   </TR>
×
466
        </TABLE>';
467
  $result2->baseFreeRows();
×
468

469
  /* IP */
470
  $sql2 = "SELECT ip_src, ip_dst, ".
×
471
          "ip_ver, ip_hlen, ip_tos, ip_len, ip_id, ip_flags, ip_off, ip_ttl, ip_csum, ip_proto". 
472
          " FROM iphdr  WHERE sid='".$sid."' AND cid='".$cid."'";
473

474
  $result2 = $db->baseExecute($sql2);
×
475
  $myrow2 = $result2->baseFetchRow();
×
476

477
  $layer4_proto = -1;
×
478
        if ( is_array($myrow2) ){
×
479
                $IP_Src = $myrow2[0];
×
480
        }else{
×
481
                $IP_Src = '';
×
482
        }
483
        if ( $IP_Src != '' ){
×
484
  $sql3 = "SELECT * FROM opt  WHERE sid='".$sid."' AND cid='".$cid."' AND opt_proto='0'";
×
485
  $result3 = $db->baseExecute($sql3);
×
486
  $num_opt = $result3->baseRecordCount();
×
487

488
  echo '
×
489
       <TABLE BORDER=1 WIDTH="90%">
490
          <TR><TD CLASS="iptitle" WIDTH=50 ROWSPAN=3 ALIGN=CENTER>IP';
491
  echo '      <TD>';
×
492
  echo '         <TABLE BORDER=1 CELLPADDING=2>';
×
493
  echo '            <TR><TD class="plfieldhdr">'._NBSOURCEADDR.'</TD>
×
494
                        <TD class="plfieldhdr">&nbsp;'._NBDESTADDR.'&nbsp</TD>
495
                        <TD class="plfieldhdr">Ver</TD>
496
                        <TD class="plfieldhdr">Hdr Len</TD>
497
                        <TD class="plfieldhdr">TOS</TD>
498
                        <TD class="plfieldhdr">'._LENGTH.'</TD>
499
                        <TD class="plfieldhdr">'._ID.'</TD>
500
                        <TD class="plfieldhdr">fragment</TD>
501
                        <TD class="plfieldhdr">offset</TD>
502
                        <TD class="plfieldhdr">TTL</TD>
503
                        <TD class="plfieldhdr">chksum</TD></TR>';
504
  echo '             <TR><TD class="plfield">
×
505
                       <A HREF="base_stat_ipaddr.php?ip='.baseLong2IP($myrow2[0]).'&amp;netmask=32">'.
×
506
                            baseLong2IP($myrow2[0]).'</A></TD>';
×
507
  echo '                 <TD class="plfield">
×
508
                         <A HREF="base_stat_ipaddr.php?ip='.baseLong2IP($myrow2[1]).'&amp;netmask=32">'.
×
509
                            baseLong2IP($myrow2[1]).'</A></TD>';
×
510
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[2]).'</TD>';
×
511
  echo '                 <TD class="plfield">'.($myrow2[3] << 2).'</TD>';    /* ihl is in 32 bit words, must be multiplied by 4 to show in bytes */
×
512
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[4]).'</TD>';
×
513
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[5]).'</TD>';
×
514
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[6]).'</TD>';
×
515
  echo '                 <TD class="plfield">';
×
516
  if ($myrow2[7] == 1)
×
517
        echo 'yes';
×
518
  else
×
519
        echo 'no';
×
520
  echo                                                           '</TD>';
×
521
  list( , $my_offset, ) = unpack("n", pack("S", $myrow2[8]));
×
522
  echo '                 <TD class="plfield">'. ($my_offset * 8) .'</TD>';
×
523
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[9]).'</TD>';
×
524
  echo '                 <TD class="plfield">'.htmlspecialchars($myrow2[10]).'<BR>= 0x'.dechex($myrow2[10]).'</TD></TR>';
×
525
  echo '         </TABLE>';
×
526

527
        if ( isset($resolve_IP) && $resolve_IP == 1 ){
×
528
     echo '  <TR>
×
529
              <TD>
530
                <TABLE BORDER=1 CELLPADDING=4>
531
                  <TR><TD CLASS="iptitle" ALIGN=CENTER ROWSPAN=2>FQDN</TD>
532
                       <TD class="plfieldhdr">'._SOURCENAME.'</TD>
533
                       <TD class="plfieldhdr">'._DESTNAME.'</TD>
534
                  </TR>
535
                  <TR><TD class="plfield">'.
536
                      (baseGetHostByAddr(baseLong2IP($myrow2[0]),
×
537
                                        $db, $dns_cache_lifetime)).'</TD>
538
                      <TD class="plfield">'.
539
                      (baseGetHostByAddr(baseLong2IP($myrow2[1]),
×
540
                                         $db, $dns_cache_lifetime)).'</TD>
541
                  </TR>
542
                 </TABLE>     
543
            </TR>';
544
        }
545
  echo '  <TR>';
×
546
  echo '      <TD>';
×
547
  echo '         <TABLE BORDER=1 CELLPADDING=4>';
×
548
  echo '           <TR><TD CLASS="iptitle" ALIGN=CENTER ROWSPAN='.(($num_opt != 0) ? ($num_opt+1) : 1).'>'._OPTIONS.'</TD>';
×
549

550
  $layer4_proto = $myrow2[11];
×
551

552
  if ( $num_opt > 0 )
×
553
  {
554
     echo '            <TD></TD>
×
555
                       <TD class="plfieldhdr">'._CODE.'</TD>
556
                       <TD class="plfieldhdr">'._LENGTH.'</TD>
557
                       <TD class="plfieldhdr" ALIGN=CENTER>'._DATA.'</TD>';
558

559
     for ( $i = 0; $i < $num_opt; $i++)
×
560
     {
561
         $myrow3 = $result3->baseFetchRow();
×
562
         echo '    <TR><TD>#'.($i+1).'</TD>';
×
563
         echo '        <TD class="plfield">'.IPOption2str($myrow3[4]).'</TD>';
×
564
         echo '        <TD class="plfield">'.htmlspecialchars($myrow3[5]).'</TD>';
×
565
         echo '        <TD class="plfield">';
×
566
         if ($myrow3[6] != "" )
×
567
           echo $myrow3[6];
×
568
         else
×
569
           echo '&nbsp;';
×
570
         echo '</TD></TR>';
×
571
     }
572
   }
573
   else
×
574
   {
575
     echo '             <TD> &nbsp&nbsp&nbsp <I>'._NONE.' </I></TD></TR>';
×
576
   }
577
      echo '         </TABLE></TD></TR>';  
×
578
                       
579

580
  echo '</TABLE>';
×
581
  $result3->baseFreeRows();
×
582
  }
583
  $result2->baseFreeRows();
×
584

585

586
  /* If we have FLoP's (Fast Logging Project for Snort) extended 
587
   * database schema then we can show mac addresses from `data_header`
588
   * field from `data` table
589
   */
590
        if (!isset($db))
×
591
        {
592
                error_log("ERROR: \$db is NOT set.");
×
593
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db is NOT set. Ignoring.");
×
594
    $debug_str = "<BR><PRE>\n\n" . debug_print_backtrace() . "\n\n</PRE><BR>\n";
×
595
    ErrorMessage($debug_str);
×
596
        }
597

598

599
        if (!isset($db->DB))
×
600
        {
601
                error_log("ERROR: \$db->DB is NOT set.");
×
602
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db->DB is NOT set. Ignoring.");
×
603
    $debug_str = "<BR><PRE>\n\n" . debug_print_backtrace() . "\n\n</PRE><BR>\n";
×
604
    ErrorMessage($debug_str);
×
605
        }
606

607
        if (!is_array($db->DB->MetaColumnNames('data')))
×
608
        {
609
                error_log("ERROR: \$db->DB->MetaColumnNames('data') is NOT an array.");
×
610
                ErrorMessage(__FILE__ . ":" . __LINE__ . ": db->DB->MetaColumnNames('data') is NOT an array. Ignoring.");
×
611
    print "<BR><PRE>\n\n";
×
612
                debug_print_backtrace();
×
613
                print "\n\n" ;
×
614
                var_dump($db->DB->MetaColumnNames('data'));
×
615
                print "</PRE><BR>\n\n" ;
×
616
        }
617

618

619
  if (in_array("data_header", $db->DB->MetaColumnNames('data'))) {
×
620

621
     $sql5 = "SELECT data_header FROM data WHERE sid='$sid' AND cid='$cid'";
×
622
     $result5 = $db->baseExecute($sql5);
×
623
     $myrow5 = $result5->baseFetchRow();
×
624
     $result5->baseFreeRows();
×
625

626
    if (is_array($myrow5))
×
627
    {
628
      if ( $debug_mode > 0 ) {
×
629
        echo "&lt;debug&gt;<BR>";
×
630
        echo "Encoding: $encoding<BR>";
×
631
        echo "Data header: &lt;$myrow5[0]&gt;<BR>";
×
632
        echo "strlen: " . strlen($myrow5[0]);
×
633
        echo "<br>Base64 decoded: &lt;" . base64_decode($myrow5[0]) . "&gt;<BR>";
×
634
        echo "strlen: " . strlen(base64_decode($myrow5[0]));
×
635
        echo "<br>bin2hex: &lt;" . bin2hex(base64_decode($myrow5[0])) . "&gt;<BR>";
×
636
        echo "strlen: " . strlen(bin2hex(base64_decode($myrow5[0])));
×
637
        echo "<BR>&lt;/debug&gt;<BR>";
×
638
      }
639

640
      /* 0 == hex, 1 == base64, 2 == ascii; cf. snort-2.4.4/src/plugbase.h */
641
      if ($encoding == 0) {
×
642
               $t = $myrow5[0];
×
643
      } elseif ($encoding == 1) {
×
644
               $t = bin2hex(base64_decode($myrow5[0]));
×
645
      } else {
×
646
        echo "<BR><BR>This type of encoding is not supported. Please use either hex oder ";
×
647
        echo "base64 encoding. Do not use ascii, because ascii encoding loses data.<BR><BR>";
×
648
      }
649

650
      /* from here on $t is in hex format, even if original encoding was base64 */
651

652
      /* "MACDAD" (ascii code in hex: 4d 41 43 44 41 44) is a key word used by
653
       * sfPortscan, rather than a real MAC address; cf. 
654
       * snort-2.6.0/doc/README.sfportscan
655
       * snort-2.6.0/src/preprocessors/spp_sfportscan.c
656
       * snort-2.6.0/src/preprocessors/flow/portscan/flowps_snort.c */
657
      if ( strlen($t) >= 24 && strncmp($t, '4d41434441444d4143444144', 24) != 0) 
×
658
      {
659
        $dst_mac = $t[0].$t[1].':'.$t[2].$t[3].':'.$t[4].$t[5].':'.$t[6].$t[7].':'.$t[8].$t[9].':'.$t[10].$t[11];
×
660
        $src_mac = $t[12].$t[13].':'.$t[14].$t[15].':'.$t[16].$t[17].':'.$t[18].$t[19].':'.$t[20].$t[21].':'.$t[22].$t[23];
×
661

662
        echo '
×
663
             <TABLE BORDER=1 WIDTH="90%">
664
                <TR><TD CLASS="iptitle" WIDTH=50 ROWSPAN=3 ALIGN=CENTER>MAC';
665
        echo '      <TD>';
×
666
        echo '         <TABLE BORDER=1 CELLPADDING=2>';
×
667
        echo '            <TR><TD class="plfieldhdr">'._NBSOURCEADDR.'</TD>
×
668
                              <TD class="plfieldhdr">&nbsp;'._NBDESTADDR.'&nbsp</TD></TR>
669
                          <TR><TD>'. $src_mac .'</TD>
670
                              <TD>'. $dst_mac .'</TD></TR>
671
                          <TR><TD>'. GetVendor($src_mac) .'</TD>
×
672
                              <TD>'. GetVendor($dst_mac) .'</TD></TR>';
×
673
        echo '         </TABLE>';
×
674
        echo '</TABLE></TD></TR>';
×
675
      }
676
      else
×
677
      {
678
        /* "MACDAD" indicates that this is an sfportscan packet.  This means
679
           the database does NOT contain a real packet.  Therefore 
680
           building a pcap file won't be possible. */
681
        $sf_portscan_flag = 1;
×
682
      }
683
    }
684
  }
685

686

687
  /* TCP */
688
  if ( $layer4_proto == "6" )  
×
689
  {
690
     $sql2 = "SELECT tcp_sport, tcp_dport, tcp_seq, tcp_ack, tcp_off, tcp_res, tcp_flags, tcp_win, ".
×
691
             "       tcp_csum, tcp_urp FROM tcphdr  WHERE sid='".$sid."' AND cid='".$cid."'";
692
     $result2 = $db->baseExecute($sql2);
×
693
     $myrow2 = $result2->baseFetchRow();
×
694

695
     $sql3 = "SELECT * FROM opt  WHERE sid='".$sid."' AND cid='".$cid."' AND opt_proto='6'";
×
696
     $result3 = $db->baseExecute($sql3);
×
697
     $num_opt = $result3->baseRecordCount();
×
698

699
      echo '
×
700
           <TABLE BORDER=1 WIDTH="90%">
701
              <TR><TD CLASS="layer4title" WIDTH=50 ROWSPAN=2 ALIGN=CENTER>TCP';
702
      echo '      <TD>';
×
703
      echo '         <TABLE BORDER=1 CELLPADDING=2>';
×
704
      echo '            <TR><TD class="plfieldhdr">'._SHORTSOURCE.'<BR> '._PORT.'</TD>
×
705
                            <TD class="plfieldhdr"> '._SHORTDEST.'<BR> &nbsp '._PORT.' &nbsp</TD>
706
                            <TD class="plfieldhdr">R<BR>1</TD>
707
                            <TD class="plfieldhdr">R<BR>0</TD>
708
                            <TD class="plfieldhdr">U<BR>R<BR>G</TD>
709
                            <TD class="plfieldhdr">A<BR>C<BR>K</TD>
710
                            <TD class="plfieldhdr">P<BR>S<BR>H</TD>
711
                            <TD class="plfieldhdr">R<BR>S<BR>T</TD>
712
                            <TD class="plfieldhdr">S<BR>Y<BR>N</TD>
713
                            <TD class="plfieldhdr">F<BR>I<BR>N</TD>
714
                            <TD class="plfieldhdr">seq #</TD>
715
                            <TD class="plfieldhdr">ack</TD>
716
                            <TD class="plfieldhdr">offset</TD>
717
                            <TD class="plfieldhdr">res</TD>
718
                            <TD class="plfieldhdr">window</TD>
719
                            <TD class="plfieldhdr">urp</TD>
720
                            <TD class="plfieldhdr">chksum</TD></TR>';
721
      $src_port = $myrow2[0].'<BR>';
×
722
      foreach ($external_port_link as $name => $baseurl) {
×
723
           $src_port = $src_port.'[<A HREF="'.$baseurl.$myrow2[0].'" TARGET="_ACID_PORT_">'.$name.'</A>] ';
×
724
      }
725
      $dst_port = $myrow2[1].'<BR>';
×
726
      foreach ($external_port_link as $name => $baseurl) {
×
727
           $dst_port = $dst_port.'[<A HREF="'.$baseurl.$myrow2[1].'" TARGET="_ACID_PORT_">'.$name.'</A>] ';
×
728
      } 
729
      echo '            <TR><TD class="plfield">'.$src_port.'</TD>';
×
730
      echo '                <TD class="plfield">'.$dst_port.'</TD>';
×
731
      echo '                <TD class="plfield">';
×
732
      if ( ($myrow2[6] & 128) != 0 )
×
733
           echo 'X';
×
734
      else
×
735
           echo '&nbsp;';
×
736
      echo '                    </TD><TD class="plfield">';
×
737
      if ( ($myrow2[6] & 64 ) != 0 )
×
738
           echo 'X';
×
739
      else
×
740
           echo '&nbsp;';
×
741
      echo '                    </TD><TD class="plfield">';
×
742
      if ( ($myrow2[6] & 32) != 0 )
×
743
           echo 'X';
×
744
      else
×
745
           echo '&nbsp;';
×
746
      echo '                    </TD><TD class="plfield">';
×
747
      if ( ($myrow2[6] & 16 ) != 0 )
×
748
           echo 'X';
×
749
      else
×
750
           echo '&nbsp;';
×
751
      echo '                    </TD><TD class="plfield">';
×
752
      if ( ($myrow2[6] & 8) != 0 )
×
753
           echo 'X';
×
754
      else
×
755
           echo '&nbsp;';
×
756
      echo '                    </TD><TD class="plfield">';
×
757
      if ( ($myrow2[6] & 4 ) != 0 )
×
758
           echo 'X';
×
759
      else
×
760
           echo '&nbsp;';
×
761
      echo '                    </TD><TD class="plfield">';
×
762
      if ( ($myrow2[6] & 2 ) != 0 )
×
763
           echo 'X';
×
764
      else
×
765
           echo '&nbsp;';
×
766
      echo '                    </TD><TD class="plfield">';
×
767
      if ( ($myrow2[6] & 1 ) != 0 )
×
768
           echo 'X';
×
769
      else
×
770
           echo '&nbsp;';
×
771
      echo '                    </TD>';
×
772
     
773
      echo '                <TD class="plfield">'.$myrow2[2].'</TD>';    
×
774
      echo '                <TD class="plfield">'.$myrow2[3].'</TD>';
×
775

776
        /* data offset is in 32 bit words, cf. RFC 793, 3.1 (= p. 16), 
777
         * PrintTCPHeader() in snort-2.6.0/src/log.c
778
         * DecodeTCP() in snort-2.6.0/src/decode.c
779
         * #define TCP_OFFSET(tcph) in snort-2.6.0/src/decode.h
780
         * Database() in snort-2.6.0/src/output-plugins/spo_database.c */
781
      echo '                <TD class="plfield">'. ($myrow2[4] << 2) .'</TD>';
×
782
      echo '                <TD class="plfield">'.$myrow2[5].'</TD>';
×
783
      echo '                <TD class="plfield">'.$myrow2[7].'</TD>';
×
784
      echo '                <TD class="plfield">'.$myrow2[9].'</TD>';
×
785
      echo '                <TD class="plfield">'.$myrow2[8].'<BR>=<BR>0x'.dechex($myrow2[8]).'</TD></TR>';
×
786
      echo '         </TABLE></TR>';
×
787
      echo '  <TR>';
×
788
      echo '      <TD>';
×
789
      echo '         <TABLE BORDER=1 CELLPADDING=4>';
×
790
      echo '           <TR><TD CLASS="layer4title" ALIGN=CENTER ROWSPAN='.(($num_opt != 0) ? ($num_opt+1) : 1).'>'._OPTIONS.'</TD>';
×
791

792
      if ( $num_opt != 0)
×
793
      {
794
         echo '            <TD></TD>
×
795
                           <TD class="plfieldhdr">'._CODE.'</TD>
796
                           <TD class="plfieldhdr">'._LENGTH.'</TD>
797
                           <TD class="plfieldhdr">'._DATA.'</TD>';
798

799
         /* Check which kind of encoding is used: */
800
         $sql4 = 'SELECT encoding FROM sensor WHERE sid='.$sid;
×
801
         $result4 = $db->baseExecute($sql4);
×
802
         $myrow4 = $result4->baseFetchRow();
×
803
         $result4->baseFreeRows();
×
804

805
         for ( $i = 0; $i < $num_opt; $i++)
×
806
         {
807
             $myrow3 = $result3->baseFetchRow();
×
808
             echo '    <TR><TD class="plfield">#'.($i+1).'</TD>';
×
809
             echo '        <TD class="plfield">'.TCPOption2str($myrow3[4]).'</TD>';
×
810
             echo '        <TD class="plfield">'.$myrow3[5].'</TD>';
×
811
             echo '        <TD class="plfield">';
×
812

813
             if ($myrow4[0] == 1) 
×
814
             /* base64 encoding */
815
             {
816
               if ($myrow3[5] > 0)
×
817
               {
818
                 $mystr = bin2hex(base64_decode($myrow3[6]));
×
819
                 for ($j = 0; $j < $myrow3[5] * 2; $j = $j + 2)
×
820
                 {
821
                   echo $mystr[$j];
×
822
                   echo $mystr[$j + 1];
×
823
                   echo '&nbsp;';
×
824
                 }
825
                 echo '<BR>';
×
826
                 if (TCPOption2str($myrow3[4]) == "(8) TS")
×
827
                 /* timestamp: cf. RFC 1323, 3.2 */
828
                 {
829
                         /* TSval */
830
                         $tmpstr = "";
×
831
                         for ($j = 0; $j < 8; $j++)
×
832
                         {
833
                                 $tmpstr = $tmpstr . $mystr[$j];
×
834
                         }
835
                         $TSval = hexdec($tmpstr);
×
836
                         echo '        TSval: ' . $TSval . '<BR>';
×
837

838
                         /* TSecr */
839
                         $tmpstr = "";
×
840
                         for ($j = 8; $j < 16; $j++)
×
841
                         {
842
                           $tmpstr = $tmpstr . $mystr[$j];
×
843
                         }
844
                         $TSecr = hexdec($tmpstr);
×
845
                         echo '        TSecr: ' . $TSecr . '<BR>';
×
846
                 }
847
                 
848
                 echo '        </TD></TR>';
×
849
               }
850
               else
×
851
               {
852
                 echo '{No data}</TD></TR>';
×
853
               }
854
             }
855
             else
×
856
             {
857
               /* hexadecimal encoding (and ASCII) */
858
               if ($myrow3[6] != "" )
×
859
                 echo $myrow3[6];
×
860
               else
×
861
                 echo '&nbsp;';
×
862
               echo '</TD></TR>';
×
863
             }
864
         }
865
      }
866
      else
×
867
      {
868
         echo '             <TD class="plfield"> &nbsp;&nbsp;&nbsp; <I>'._NONE.' </I></TD></TR>';
×
869
      }
870
      echo '         </TABLE></TD></TR>';                       
×
871

872
      echo '</TABLE>';
×
873

874
      $result2->baseFreeRows();
×
875
      $result3->baseFreeRows();
×
876
  }
877

878
  /* UDP */
879
  if ( $layer4_proto == "17" )
×
880
  {
881

882
     $sql2 = "SELECT * FROM udphdr  WHERE sid='".$sid."' AND cid='".$cid."'";
×
883
     $result2 = $db->baseExecute($sql2);
×
884
     $myrow2 = $result2->baseFetchRow();
×
885

886
     echo '
×
887
           <TABLE BORDER=1 WIDTH="90%">
888
              <TR><TD CLASS="layer4title" WIDTH=50 ROWSPAN=2 ALIGN=CENTER>UDP</TD>';
889
     echo '      <TD>';
×
890
     echo '         <TABLE BORDER=1 CELLPADDING=2>';
×
891
     echo '            <TR><TD class="plfieldhdr">'._SOURCEPORT.'</TD>
×
892
                            <TD class="plfieldhdr">'._DESTPORT.'</TD>
893
                            <TD class="plfieldhdr">'._LENGTH.'</TD></TR>';
894

895
     $src_port = $myrow2[2].'<BR>';
×
896
     foreach ($external_port_link as $name => $baseurl) {
×
897
        $src_port = $src_port.'[<A HREF="'.$baseurl.$myrow2[2].'" TARGET="_ACID_PORT_">'.$name.'</A>] ';
×
898
     }
899
    
900
     $dst_port = $myrow2[3].'<BR>';
×
901
     foreach ($external_port_link as $name => $baseurl) {
×
902
        $dst_port = $dst_port.'[<A HREF="'.$baseurl.$myrow2[3].'" TARGET="_ACID_PORT_">'.$name.'</A>] ';
×
903
     } 
904

905
     echo '            <TR><TD class="plfield">'.$src_port.'</TD>';
×
906
     echo '                <TD class="plfield">'.$dst_port.'</TD>';
×
907
     echo '                <TD class="plfield">'.$myrow2[4].'</TD></TR>';
×
908
     echo '         </TABLE></TD></TR>';
×
909
     echo '</TABLE>';
×
910

911
     $result2->baseFreeRows();
×
912
  }
913

914
  /* ICMP */
915
  if ( $layer4_proto == "1" )
×
916
  {
917
     $sql2 = "SELECT icmp_type, icmp_code, icmp_csum, icmp_id, icmp_seq FROM icmphdr ".
×
918
             "WHERE sid='".$sid."' AND cid='".$cid."'";
919
     $result2 = $db->baseExecute($sql2);
×
920
     $myrow2 = $result2->baseFetchRow();
×
921
     $ICMPitype = $myrow2[0];
×
922
     $ICMPicode = $myrow2[1];
×
923

924

925
     echo '
×
926
           <TABLE BORDER=1 WIDTH="90%">
927
              <TR><TD class="layer4title" WIDTH=50 ROWSPAN=2 ALIGN=CENTER>ICMP';
928
     echo '      <TD>';
×
929
     echo '         <TABLE BORDER=1 CELLPADDING=2>';
×
930
     echo '            <TR><TD class="plfieldhdr">'._TYPE.'</TD>
×
931
                           <TD class="plfieldhdr">'._CODE.'</TD>
932
                           <TD class="plfieldhdr">checksum</TD>';
933
                if ($ICMPitype == "5") {
×
934
                 echo '                <TD class="plfieldhdr">gateway address</TD>';
×
935
     echo '                <TD class="plfieldhdr">gateway hostname</TD>';
×
936
                } else {
×
937
     echo '                <TD class="plfieldhdr">'._ID.'</TD>
×
938
                           <TD class="plfieldhdr">seq #</TD>';
939
                }
940

941
                 echo '            </TR>';
×
942
     echo '            <TR><TD class="plfield">('.$myrow2[0].') '.ICMPType2str($myrow2[0]).'</TD>';
×
943
     echo '                <TD class="plfield">('.$myrow2[1].') '.ICMPCode2str($myrow2[0],$myrow2[1]).'</TD>';
×
944
     echo '                <TD class="plfield">'.$myrow2[2].'<BR>=<BR>0x'. dechex($myrow2[2])  .'</TD>';
×
945

946
                if ($ICMPitype == "5") {
×
947
                 $gateway_numeric_ip = (integer)($myrow2[3] / 256) . "." . ($myrow2[3] % 256) . ".". (integer)($myrow2[4] / 256) . "." . ($myrow2[4] % 256);
×
948
                 $gateway_hostname = basegetHostByAddr($gateway_numeric_ip, $db, $dns_cache_lifetime); 
×
949

950
     echo '                <TD class="plfield"><A HREF="base_stat_ipaddr.php?ip=' . $gateway_numeric_ip . '&amp;netmask=32" TARGET="_PL_SIP">' . $gateway_numeric_ip . '</A></TD>';
×
951
                 echo '                <TD class="plfield">' . $gateway_hostname   . '</TD>';
×
952
                } else {
×
953
     echo '                <TD class="plfield">'.$myrow2[3].'</TD>';
×
954
     echo '                <TD class="plfield">'.$myrow2[4].'</TD>';
×
955
                }
956

957
     echo '            </TR>';
×
958
     echo '         </TABLE>';
×
959
     echo '</TABLE>';
×
960

961
     
962

963
     $result2->baseFreeRows();
×
964
  }
965

966
  /* Print the Payload */
967
  $sql2 = "SELECT data_payload FROM data WHERE sid='".$sid."' AND cid='".$cid."'";
×
968
  $result2 = $db->baseExecute($sql2);
×
969
  $myrow2 = $result2->baseFetchRow();
×
970
  $result2->baseFreeRows();
×
971
  !empty($myrow2) ? $payload = $myrow2[0] : '';
×
972

973
  echo '
×
974
        <TABLE BORDER=1 WIDTH="90%">
975
           <TR><TD class="payloadtitle" WIDTH=50 ROWSPAN=2 ALIGN=CENTER>Payload';
976
           echo("<br><br>".PrintCleanURL());
×
977
           echo("<br>".PrintBinDownload($db, $cid, $sid));
×
978
           if ($sf_portscan_flag != 1)
×
979
           {
980
             echo("<br>".PrintPcapDownload($db, $cid, $sid));
×
981
           }
982
           else
×
983
           {
984
             echo "<br>(Download in pcap format is NOT possible with portscan data)";
×
985
           }
986
  echo '       <TD>';
×
987

988
  if ( $payload )
×
989
  {
990
     /* print the packet based on encoding type */
991
     PrintPacketPayload($payload, $encoding, 1);
×
992

993
     if ( $layer4_proto == "1" )
×
994
     {
995
          if ( /* IF ICMP source quench */ 
×
996
               ($ICMPitype == "4" && $ICMPicode == "0") ||
997
               /* IF ICMP redirect */
998
               ($ICMPitype == "5") ||
999
               /* IF ICMP parameter problem */
1000
               ($ICMPitype == "12" && $ICMPicode == "0") ||
1001
               /* IF ( network, host, port unreachable OR 
1002
               frag needed OR network admin prohibited OR filtered) */
1003
               ($ICMPitype == "3" || $ICMPitype == "11" ) &&
1004
               $ICMPicode == "0" || $ICMPicode == "1" ||
1005
               $ICMPicode == "3" || $ICMPicode == "4" || 
1006
               $ICMPicode == "9" || $ICMPicode == "13" )
1007
          {
1008
              /* 0 == hex, 1 == base64, 2 == ascii; cf. snort-2.4.4/src/plugbase.h */
1009
              if ($encoding == 1) {
×
1010
                 /* encoding is base64 */
1011
                 $work = bin2hex(base64_decode(str_replace("\n","",$payload)));
×
1012
              } else {
×
1013
                 /* assuming that encoding is hex */
1014
                 $work = str_replace("\n","",$payload);
×
1015
              }
1016

1017

1018

1019

1020

1021

1022
              /* 
1023
               *  - depending on how the packet logged, 32-bits of NULL padding after
1024
               *    the checksum may still be present.
1025
               */
1026
              if ( substr($work, 0, 8) == "00000000" ) {
×
1027
                 $offset = 8;
×
1028
                                                        }
1029
              /* for dest. unreachable, frag needed and DF bit set indent the padding
1030
               * of MTU of next hop
1031
               */
1032
              else if ( ($ICMPitype == "3") && ($ICMPicode == "4") ) {
×
1033
                 $offset += 8;
×
1034
              }
1035
            
1036

1037
              $icmp_proto = hexdec($work[18+$offset].$work[19+$offset]);
×
1038

1039
              $payload_ip_checksum = "0x" . 
×
1040
                          ($work[20 + $offset] . $work[21 + $offset]) .
×
1041
                          ($work[22 + $offset] . $work[23 + $offset]); 
×
1042

1043
              $icmp_src = hexdec($work[24+$offset].$work[25+$offset]).".".
×
1044
                          hexdec($work[26+$offset].$work[27+$offset]).".".
×
1045
                          hexdec($work[28+$offset].$work[29+$offset]).".".
×
1046
                          hexdec($work[30+$offset].$work[31+$offset]);
×
1047
              $icmp_dst = hexdec($work[32+$offset].$work[33+$offset]).".".
×
1048
                          hexdec($work[34+$offset].$work[35+$offset]).".".
×
1049
                          hexdec($work[36+$offset].$work[37+$offset]).".".
×
1050
                          hexdec($work[38+$offset].$work[39+$offset]);
×
1051
              
1052
              
1053

1054

1055

1056
              $hdr_offset = ($work[$offset+1]) * 8 + $offset;
×
1057
              $icmp_src_port = hexdec($work[$hdr_offset].$work[$hdr_offset+1].$work[$hdr_offset+2].$work[$hdr_offset+3]);
×
1058
              $icmp_dst_port = hexdec($work[$hdr_offset+4].$work[$hdr_offset+5].$work[$hdr_offset+6].$work[$hdr_offset+7]);
×
1059

1060

1061
              if ($ICMPitype == "5") {
×
1062
                 $seq_no_hex = ($work[ 8 + $hdr_offset]) . ($work[ 9 + $hdr_offset]) .
×
1063
                               ($work[10 + $hdr_offset]) . ($work[11 + $hdr_offset]) .
×
1064
                               ($work[12 + $hdr_offset]) . ($work[13 + $hdr_offset]) .
×
1065
                               ($work[14 + $hdr_offset]) . ($work[15 + $hdr_offset]);
×
1066
                 $seq_no = hexdec($seq_no_hex);
×
1067
              }
1068

1069

1070
 
1071
              echo '<TABLE BORDER=1>';
×
1072
              echo '<TR>';
×
1073
              
1074
              echo '<TD class="plfieldhdr">Protocol</TD>';
×
1075
              echo '<TD class="plfieldhdr">Org.Source<BR>IP</TD>';
×
1076
              echo '<TD class="plfieldhdr">Org.Source<BR>Name</TD>';
×
1077

1078
              if ( $icmp_proto == "6" || $icmp_proto == "17" ) {
×
1079
                 echo '<TD class="plfieldhdr">Org.Source<BR>Port</TD>';
×
1080
              }
1081

1082
              echo '<TD class="plfieldhdr">Org.Destination<BR>IP</TD>';
×
1083
              echo '<TD class="plfieldhdr">Org.Destination<BR>Name</TD>';
×
1084

1085
              if ( $icmp_proto == "6" || $icmp_proto == "17" ) {
×
1086
                 echo '<TD class="plfieldhdr">Org.Destination<BR>Port</TD>';
×
1087
              }
1088

1089
              if ( $ICMPitype == "5" ) {
×
1090
                 echo '<TD class="plfieldhdr">IP Hdr Checksum</TD>';
×
1091
                 echo '<TD class="plfieldhdr">Sequence Number</TD>';
×
1092
              }
1093

1094
              echo '</TR>';
×
1095
              echo '<TR>';
×
1096

1097
              
1098
              
1099
              echo '<TD class="plfield">'.IPProto2Str($icmp_proto).'</TD>';
×
1100
              echo '<TD class="plfield">';
×
1101
              echo '<A HREF="base_stat_ipaddr.php?ip='.$icmp_src.'&amp;netmask=32" TARGET="_PL_SIP">'.$icmp_src.'</A></TD>';
×
1102
              echo '<TD class="plfield">'.baseGetHostByAddr($icmp_src, $db, $dns_cache_lifetime).'</TD>';
×
1103

1104
              if ( $icmp_proto == "6" || $icmp_proto == "17" ) {
×
1105
                 echo '<TD class="plfield">'.$icmp_src_port.'</TD>';
×
1106
              }
1107

1108
              echo '<TD class="plfield">';
×
1109
              echo '<A HREF="base_stat_ipaddr.php?ip='.$icmp_dst.'&amp;netmask=32" TARGET="_PL_DIP">'.$icmp_dst.'</A></TD>';
×
1110
              echo '<TD class="plfield">'.baseGetHostByAddr($icmp_dst, $db, $dns_cache_lifetime).'</TD>';
×
1111

1112
              if ( $icmp_proto == "6" || $icmp_proto == "17" ) {
×
1113
                 echo '<TD class="plfield">'.$icmp_dst_port.'</TD>';
×
1114
              }
1115

1116
              if ($ICMPitype == "5") {
×
1117
                echo '<TD class="plfield">' . $payload_ip_checksum . '</TD>';
×
1118
                echo '<TD class="plfield">' . $seq_no . '</TD>';
×
1119
              }
1120

1121
              echo '</TR>';
×
1122
              echo '</TABLE>';
×
1123
         }
1124
     }
1125
  }
1126
  else
×
1127
  {
1128
     /* Don't have payload so lets print out why by checking the detail level */
1129

1130
     /* if have fast detail level */
1131
     if ( $detail == "0" )
×
1132
        echo '<BR> &nbsp <I>'._QANOPAYLOAD.'</I><BR>';
×
1133
     else
×
1134
        echo '<BR> &nbsp <I>'._NONE.' </I><BR>';
×
1135
  }
1136

1137
  echo '</TABLE></BLOCKQUOTE><P>';
×
1138

1139
  echo "<CENTER>$previous &nbsp&nbsp&nbsp $next</CENTER>";
×
1140

1141
  $qs->PrintAlertActionButtons();
×
1142
  $qs->SaveState();
×
1143
  ExportHTTPVar("caller", $caller);
×
1144
ExportHTTPVar("sort_order", $sort_order);
×
1145
  echo "\n</FORM>\n";
×
1146
$et->Mark("Get Query Elements");
×
1147
PrintBASESubFooter();
×
1148
?>
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc