diff -Naur acid/acid_action.inc acidfp/acid_action.inc --- acid/acid_action.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_action.inc 2003-12-17 14:16:39.000000000 -0500 @@ -114,7 +114,9 @@ echo "==== ACTION ======
context = $context

"; - set_time_limit($max_script_runtime); + if ( ini_get("safe_mode") != true ) + set_time_limit($max_script_runtime); + if ($action_op == "Selected") { /* on packet lookup, only examine the first packet */ @@ -243,6 +245,7 @@ { $action_desc["ag_by_id"] = "ADD to AG (by ID)"; $action_desc["ag_by_name"] = "Add to AG (by Name)"; + $action_desc["add_new_ag"] = "Create AG (by Name)"; $action_desc["clear_alert"] = "Clear from AG"; $action_desc["del_alert"] = "Delete alert(s)"; $action_desc["email_alert"] = "Email alert(s) (full)"; @@ -275,7 +278,8 @@ else if ($action == "clear_alert") $action_desc = "CLEAR"; else if ($action == "archive_alert") $action_desc = "ARCHIVE-copy"; else if ($action == "archive_alert2") $action_desc = "ARCHIVE-move"; - + else if ($action == "add_new_ag") $action_desc = "ADD-New-AG"; + if ( $action == "" ) return; @@ -363,8 +367,8 @@ else if ( $context == PAGE_STAT_SENSOR ) { if ( !isset($action_lst[$j]) ) $tmp = -1; else $tmp = $action_lst[$j]; - $sql = "SELECT sid, cid FROM acid_event WHERE sid=".$tmp; /*$alert_del[$j];*/ - $sql2 = "SELECT count(sid) FROM acid_event WHERE sid=".$tmp; /*$alert_del[$j];*/ + $sql = "SELECT sid, cid FROM acid_event WHERE sid='".$tmp."'"; /*$alert_del[$j];*/ + $sql2 = "SELECT count(sid) FROM acid_event WHERE sid='".$tmp."'"; /*$alert_del[$j];*/ } /* Single Alert listing */ //if ( $context == PAGE_ALERT_DISPLAY ) @@ -560,6 +564,77 @@ /* none */ } +/* ADD NEW AG (by Name) *************************************/ +function Action_add_new_ag_pre($action_arg, $action_param, $db) +/* + * $action_arg: New AG name + */ +{ + if($action_arg == "") + $ag_name = "AG_".date("Y-m-d_H:i:s", time()); + else + $ag_name = $action_arg; + + $ag_id = CreateAG($db, $ag_name, ""); + + return $ag_id; +} + +function Action_add_new_ag_Op($sid, $cid, $db, $action_arg, &$ctx) +{ + /* Add alerts to new AG */ + $ag_id = $ctx; + $retval = Action_ag_by_id_Op($sid, $cid, $db, $ag_id, $ctx); + + /* Check the return code, if an error occurs we need to remove + * the AG created in the Pre-action section. Rollback would be + * a better option, but for now we'll just delete. + */ + if($retval == 0) + { + $sql = "DELETE FROM acid_ag WHERE ag_id='".$ag_id."'"; + $db->acidExecute($sql, -1, -1, false); + + if($db->acidErrorMessage() != "") + ErrorMessage("Failed to remove new AG"); + } + + return $retval; +} + +function Action_add_new_ag_Post($action_arg, &$action_ctx, $db, &$num_alert, $action_cnt) +{ + $sql = "SELECT COUNT(ag_id) FROM acid_ag_alert WHERE ag_id='".$action_ctx."'"; + + $result = $db->acidExecute($sql, -1, -1, false); + + if($db->acidErrorMessage() != "") + { + ErrorMessage("Could not stat AG".$action_ctx); + return 0; + } + + $cnt = $result->acidRecordCount(); + $result->acidFreeRows(); + + /* If no alerts were inserted, remove the new AG */ + if($cnt <= 0) { + $sql = "DELETE FROM acid_ag WHERE ag_id='".$action_ctx."'"; + $db->acidExecute($sql, -1, -1, false); + + if($db->acidErrorMessage() != "") + ErrorMessage("Failed to remove new AG"); + } + else + { + /* Add was successful, so redirect user to AG edit page */ + echo ''; + } +} + /* DELETE **************************************************/ function Action_del_alert_pre($action_arg, $action_param, $db) { @@ -610,7 +685,7 @@ $mail_subject = $action_email_subject; $mail_content = $action_email_msg. - "Generated by ACID v$ACID_VERSION on ".date("D F d, Y H:i:s",time())."\n"; + "Generated by ACID v$ACID_VERSION on ".date("r",time())."\n"; $mail_recip = $action_arg; $mail_header = "From: ".$action_email_from; @@ -703,7 +778,7 @@ for ( $j = 0; $j < count($clear_table_list); $j++ ) { $sql2 = "DELETE FROM ".$clear_table_list[$j]. - " WHERE ag_sid=".$sid." AND ag_cid=".$cid." AND ag_id=".$action_arg;//$ctx; + " WHERE ag_sid='".$sid."' AND ag_cid='".$cid."' AND ag_id='".$action_arg."'";//$ctx; $db->acidExecute($sql2); if ( $db->acidErrorMessage() != "" ) @@ -794,7 +869,7 @@ { $result = $db->acidExecute("SELECT sig_class_id, sig_priority, sig_rev, sig_sid FROM signature - WHERE sig_id = ".$sig); + WHERE sig_id = '".$sig."'"); $row = $result->acidFetchRow(); $sig_class_id = $row[0]; $sig_class_name = GetSigClassName($sig_class_id, $db); @@ -806,7 +881,7 @@ $MAX_REF_CNT = 6; $sig_reference = array($MAX_REF_CNT); $sig_reference_cnt = 0; - $sql = "SELECT ref_id FROM sig_reference WHERE sig_id=".$sig; + $sql = "SELECT ref_id FROM sig_reference WHERE sig_id='".$sig."'"; $tmp_result = $db->acidExecute($sql); while ( (($tmp_row = $tmp_result->acidFetchRow()) != "") && @@ -815,7 +890,7 @@ $ref_id = $tmp_row[0]; $sql = "SELECT ref_system_id, ref_tag FROM reference ". - "WHERE ref_id=".$ref_id; + "WHERE ref_id='".$ref_id."'"; $tmp_result2 = $db->acidExecute($sql); $tmp_row2 = $tmp_result2->acidFetchRow(); @@ -839,7 +914,7 @@ ip_dst, ip_ver, ip_hlen, ip_tos, ip_len, ip_id, ip_flags, ip_off, ip_ttl, ip_proto, ip_csum ". - "FROM iphdr WHERE sid=$sid AND cid=$cid"; + "FROM iphdr WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); $tmp_row = $tmp_result->acidFetchRow(); if ( $tmp_row ) @@ -865,7 +940,7 @@ { $sql = "SELECT tcp_sport, tcp_dport, tcp_seq, tcp_ack, tcp_off, tcp_res, tcp_flags, tcp_win, tcp_csum, tcp_urp ". - "FROM tcphdr WHERE sid=$sid AND cid=$cid"; + "FROM tcphdr WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); $tmp_row = $tmp_result->acidFetchRow(); $sql = "INSERT INTO tcphdr (sid,cid, @@ -881,7 +956,7 @@ else if ( $ip_proto == 17 ) { $sql = "SELECT udp_sport, udp_dport, udp_len, udp_csum ". - "FROM udphdr WHERE sid=$sid AND cid=$cid"; + "FROM udphdr WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); $tmp_row = $tmp_result->acidFetchRow(); $sql = "INSERT INTO udphdr (sid,cid, udp_sport, udp_dport, ". @@ -894,7 +969,7 @@ else if ( $ip_proto == 1 ) { $sql = "SELECT icmp_type, icmp_code, icmp_csum, icmp_id, icmp_seq ". - "FROM icmphdr WHERE sid=$sid AND cid=$cid"; + "FROM icmphdr WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); $tmp_row = $tmp_result->acidFetchRow(); $sql = "INSERT INTO icmphdr (sid,cid,icmp_type,icmp_code,". @@ -905,7 +980,7 @@ $insert_sql[$sql_cnt++] = $sql; } - $sql = "SELECT data_payload FROM data WHERE sid=$sid AND cid=$cid"; + $sql = "SELECT data_payload FROM data WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); $tmp_row = $tmp_result->acidFetchRow(); if ( $tmp_row ) @@ -917,7 +992,7 @@ } $sql = "SELECT optid, opt_proto, opt_code, opt_len, opt_data ". - "FROM opt WHERE sid=$sid AND cid=$cid"; + "FROM opt WHERE sid='$sid' AND cid='$cid'"; $tmp_result = $db->acidExecute($sql); while ( (($tmp_row = $tmp_result->acidFetchRow()) != "") @@ -1173,13 +1248,17 @@ $del_cnt = 0; + if ( ($GLOBALS['use_referential_integrity'] == 1) && + ($GLOBALS['DBtype'] != "mysql") ) + $del_table_list = array ("event"); + for ( $k = 0; $k < count($del_table_list); $k++ ) { /* If trying to add to an ACID table append ag_ to the fields */ if ( strstr($del_table_list[$k], "acid_ag") == "" ) - $sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE sid=".$sid." AND cid=".$cid; + $sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE sid='".$sid."' AND cid='".$cid."'"; else - $sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE ag_sid=".$sid." AND ag_cid=".$cid; + $sql2 = "DELETE FROM ".$del_table_list[$k]." WHERE ag_sid='".$sid."' AND ag_cid='".$cid."'"; $db->acidExecute($sql2); diff -Naur acid/acid_ag_common.php acidfp/acid_ag_common.php --- acid/acid_ag_common.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_ag_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -72,4 +72,39 @@ } } -?> +function CreateAG($db, $ag_name, $ag_desc) +{ + $sql = "INSERT INTO acid_ag (ag_name, ag_desc) VALUES ('".$ag_name."','".$ag_desc."');"; + $db->acidExecute($sql, -1, -1, false); + + if ( $db->acidErrorMessage() != "" ) + FatalError("Error Inserting new AG"); + + $ag_id = $db->acidInsertID(); + /* The following code is a kludge and can cause errors. Since it is not possible + * to determine the last insert ID of the AG, we requery the DB to ascertain the ID + * by matching on the ag_name and ag_desc. -- rdd (1/23/2001) + * + * Modified code to only run the kludge if the dbtype is postgres. Created a function + * to use the actual insertid function if available and return -1 if no -- srh (02/01/2001) + * + * Transaction support is neccessary to get this absolutely correct, because using + * an insert_id might break in a multi-user environment. -- rdd (02/07/2001) + */ + if ( $ag_id == -1 ) + { + $tmp_sql = "SELECT ag_id FROM acid_ag WHERE ag_name='".$ag_name."' AND ". + "ag_desc='".$ag_desc."'"; + if ($db->DB_type == "mssql") + $tmp_sql = "SELECT ag_id FROM acid_ag WHERE ag_name='".$ag_name."' AND ". + "ag_desc LIKE '".MssqlKludgeValue($ag_desc)."'"; + $tmp_result = $db->acidExecute(); + $myrow = $tmp_result->acidFetchRow(); + $ag_id = $myrow[0]; + $tmp_result->acidFreeRows(); + } + + return $ag_id; +} + +?> \ No newline at end of file diff -Naur acid/acid_ag_main.php acidfp/acid_ag_main.php --- acid/acid_ag_main.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_ag_main.php 2003-12-17 14:16:39.000000000 -0500 @@ -34,7 +34,10 @@ $submit = ImportHTTPVar("submit"); $ag_action = ImportHTTPVar("ag_action"); $ag_id = ImportHTTPVar("ag_id"); - + $ag_name = ImportHTTPVar("ag_name"); + $ag_desc = ImportHTTPVar("ag_desc"); + + //$qs->MoveView($submit); /* increment the view if neccessary */ $page_title = "Alert Group (AG) Maintenance"; @@ -82,7 +85,7 @@ $qs->AddValidActionOp("ALL on Screen"); $qs->AddValidActionOp("Entire Query"); - $qs->SetActionSQL("SELECT ag_sid, ag_cid FROM acid_ag_alert WHERE ag_id=".$ag_id); + $qs->SetActionSQL("SELECT ag_sid, ag_cid FROM acid_ag_alert WHERE ag_id='".$ag_id."'"); $et->Mark("Initialization"); $qs->RunAction($submit, PAGE_QRY_AG, $db); @@ -102,41 +105,13 @@ { if ( $ag_action == "create" ) { - $sql = "INSERT INTO acid_ag (ag_name, ag_desc) VALUES ('".$ag_name."','".$ag_desc."');"; - $db->acidExecute($sql, -1, -1, false); - - if ( $db->acidErrorMessage() != "" ) - FatalError("Error Inserting new AG"); - - $ag_id = $db->acidInsertID(); - /* The following code is a kludge and can cause errors. Since it is not possible - * to determine the last insert ID of the AG, we requery the DB to ascertain the ID - * by matching on the ag_name and ag_desc. -- rdd (1/23/2001) - * - * Modified code to only run the kludge if the dbtype is postgres. Created a function - * to use the actual insertid function if available and return -1 if no -- srh (02/01/2001) - * - * Transaction support is neccessary to get this absolutely correct, because using - * an insert_id might break in a multi-user environment. -- rdd (02/07/2001) - */ - if ( $ag_id == -1 ) - { - $tmp_sql = "SELECT ag_id FROM acid_ag WHERE ag_name='".$ag_name."' AND ". - "ag_desc='".$ag_desc."'"; - if ($db->DB_type == "mssql") - $tmp_sql = "SELECT ag_id FROM acid_ag WHERE ag_name='".$ag_name."' AND ". - "ag_desc LIKE '".MssqlKludgeValue($ag_desc)."'"; - $tmp_result = $db->acidExecute(); - $myrow = $tmp_result->acidFetchRow(); - $ag_id = $myrow[0]; - $tmp_result->acidFreeRows(); - } + $ag_id = CreateAG($db, $ag_name, $ag_desc); $ag_action = "view"; } else if ( $ag_action == "save" ) { $sql = "UPDATE acid_ag SET ag_name='".$ag_name."', ag_desc='".$ag_desc."' ". - "WHERE ag_id=".$ag_id; + "WHERE ag_id='".$ag_id."'"; $db->acidExecute($sql, -1, -1, false); if ( $db->acidErrorMessage() != "" ) @@ -147,13 +122,13 @@ else if ( $ag_action == "delete_confirm" ) { /* Delete the packet list associated with the AG */ - $sql = "DELETE FROM acid_ag_alert WHERE ag_id=".$ag_id; + $sql = "DELETE FROM acid_ag_alert WHERE ag_id='".$ag_id."'"; $db->acidExecute($sql, -1, -1, false); if ( $db->acidErrorMessage() != "" ) FatalError("Error deleting packet list for the AG: ".$sql); /* Delete the AG */ - $sql = "DELETE FROM acid_ag WHERE ag_id=".$ag_id; + $sql = "DELETE FROM acid_ag WHERE ag_id='".$ag_id."'"; $db->acidExecute($sql, -1, -1, false); if ( $db->acidErrorMessage() != "" ) FatalError("Error deleting the AG".$sql); @@ -161,7 +136,7 @@ else if ( $ag_action == "clear_confirm" ) { /* Delete the packet list associated with the AG */ - $sql = "DELETE FROM acid_ag_alert WHERE ag_id=".$ag_id; + $sql = "DELETE FROM acid_ag_alert WHERE ag_id='".$ag_id."'"; $db->acidExecute($sql, -1, -1, false); if ( $db->acidErrorMessage() != "" ) FatalError("Error deleting packet list for the AG: ".$sql); @@ -179,7 +154,7 @@ { /* Re-Query the information to print the AG info out */ if ( $ag_id > 0) - $sql = "SELECT ag_id, ag_name, ag_desc FROM acid_ag WHERE ag_id=".$ag_id; + $sql = "SELECT ag_id, ag_name, ag_desc FROM acid_ag WHERE ag_id='".$ag_id."'"; else $sql = "SELECT ag_id, ag_name, ag_desc FROM acid_ag WHERE ag_name='".$ag_name."'"; @@ -229,7 +204,7 @@ $myrow = $result->acidFetchRow(); /* count the number of alerts in the AG */ - $result2 = $db->acidExecute("SELECT count(ag_cid) FROM acid_ag_alert WHERE ag_id=".$myrow[0]); + $result2 = $db->acidExecute("SELECT count(ag_cid) FROM acid_ag_alert WHERE ag_id='".$myrow[0]."'"); $myrow2 = $result2->acidFetchRow(); $num_alerts = $myrow2[0]; $result2->acidFreeRows(); @@ -355,13 +330,13 @@ if ( $ag_action == "view" && $submit != "" ) { /* Calculate the Number of Alerts */ - $cnt_sql = "SELECT count(ag_sid) FROM acid_ag_alert WHERE ag_id=".$ag_id; + $cnt_sql = "SELECT count(ag_sid) FROM acid_ag_alert WHERE ag_id='".$ag_id."'"; $save_sql = "SELECT acid_event.sid, acid_event.cid, signature, timestamp, ". "ip_src, ip_dst, ip_proto ". "FROM acid_event ". "LEFT JOIN acid_ag_alert ON acid_event.sid=ag_sid AND acid_event.cid=ag_cid ". - "WHERE acid_event.cid > 0 AND ag_id = ".$ag_id; + "WHERE acid_event.cid > '0' AND ag_id = '".$ag_id."'"; $printing_ag = true; $ag = $ag_id; diff -Naur acid/acid_cache.inc acidfp/acid_cache.inc --- acid/acid_cache.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_cache.inc 2003-12-17 14:16:39.000000000 -0500 @@ -89,7 +89,7 @@ $sql = "SELECT signature, timestamp, ip_src, ip_dst, ip_proto FROM event ". "LEFT JOIN iphdr ON (event.sid=iphdr.sid AND event.cid = iphdr.cid) ". - "WHERE (event.sid=".$sid." AND event.cid=".$cid.") ORDER BY event.cid"; + "WHERE (event.sid='".$sid."' AND event.cid='".$cid."') ORDER BY event.cid"; $result = $db->acidExecute($sql); @@ -106,7 +106,7 @@ if ( $ip_proto == TCP ) { $result = $db->acidExecute("SELECT tcp_sport, tcp_dport FROM - tcphdr WHERE sid=".$sid." AND cid=".$cid); + tcphdr WHERE sid='".$sid."' AND cid='".$cid."'"); $row = $result->acidFetchRow(); if ( $row ) { @@ -119,7 +119,7 @@ else if ( $ip_proto == UDP ) { $result = $db->acidExecute("SELECT udp_sport, udp_dport FROM - udphdr WHERE sid=".$sid." AND cid=".$cid); + udphdr WHERE sid='".$sid."' AND cid='".$cid."'"); $row = $result->acidFetchRow(); if ( $row ) { @@ -134,10 +134,10 @@ if ( $db->acidGetDBVersion() >= 103 ) $result = $db->acidExecute("SELECT sig_name, sig_class_id, sig_priority ". " FROM signature ". - "WHERE sig_id = ".$signature); + "WHERE sig_id = '".$signature."'"); else $result = $db->acidExecute("SELECT sig_name FROM signature ". - "WHERE sig_id = ".$signature); + "WHERE sig_id = '".$signature."'"); $row = $result->acidFetchRow(); if ( $row ) { @@ -344,13 +344,13 @@ $sid = $sid_row[0]; /* Get highest CID for a given sensor */ - $cid_lst = $db->acidExecute("SELECT MAX(cid) FROM event WHERE sid=".$sid); + $cid_lst = $db->acidExecute("SELECT MAX(cid) FROM event WHERE sid='".$sid."'"); $cid_row = $cid_lst->acidFetchRow(); $cid = $cid_row[0]; if ( $cid == NULL ) $cid = 0; /* Get highest CID for a given sensor in the cache */ - $ccid_lst = $db->acidExecute("SELECT MAX(cid) FROM acid_event WHERE sid=".$sid); + $ccid_lst = $db->acidExecute("SELECT MAX(cid) FROM acid_event WHERE sid='".$sid."'"); $ccid_row = $ccid_lst->acidFetchRow(); $ccid = $ccid_row[0]; if ( $ccid == NULL ) $ccid = 0; @@ -367,7 +367,7 @@ CacheSensor($sid, $ccid, $db); $updated_cache_cnt += EventCntBySensor($sid, $db) - $before_cnt; - //$uncached_sql = "SELECT cid FROM event WHERE (sid=".$sid." AND cid > ".$ccid.")". + //$uncached_sql = "SELECT cid FROM event WHERE (sid='".$sid."' AND cid > '".$ccid."')". " ORDER BY sid, cid"; //echo $uncached_sql; //$uncached_lst = $db->acidExecute($uncached_sql); diff -Naur acid/acid_common.php acidfp/acid_common.php --- acid/acid_common.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -28,7 +28,7 @@ { $name = ""; - $temp_sql = "SELECT sid, hostname, interface, filter FROM sensor WHERE sid=".$sid; + $temp_sql = "SELECT sid, hostname, interface, filter FROM sensor WHERE sid='".$sid."'"; $tmp_result = $db->acidExecute($temp_sql); if ( $tmp_result ) { diff -Naur acid/acid_conf.php acidfp/acid_conf.php --- acid/acid_conf.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_conf.php 2003-12-17 14:17:10.000000000 -0500 @@ -1,6 +1,6 @@ array("http://www.securityfocus.com/bid/", ""), + "snort" => array("http://www.snort.org/snort-db/sid.html?sid=", ""), + "cve" => array("http://cve.mitre.org/cgi-bin/cvename.cgi?name=", ""), + "arachnids" => array("http://www.whitehats.com/info/ids", ""), + "mcafee" => array("http://vil.nai.com/vil/content/v_", ".htm"), + "icat" => array("http://icat.nist.gov/icat.cfm?cvename=", "")); /* Email Alert action * diff -Naur acid/acid_constants.inc acidfp/acid_constants.inc --- acid/acid_constants.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_constants.inc 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: application constants @@ -43,4 +43,19 @@ define("DB_CONNECT", 2); define("DB_PCONNECT", 1); +/* */ +define("VAR_DIGIT", 1); +define("VAR_LETTER", 2); +define("VAR_ULETTER", 4); +define("VAR_LLETTER", 8); +define("VAR_ALPHA", 16); +define("VAR_PUNC", 32); +define("VAR_SPACE", 64); +define("VAR_FSLASH", 128); +define("VAR_PERIOD", 256); +define("VAR_OPERATOR", 512); +define("VAR_OPAREN", 1024); /* ( */ +define("VAR_CPAREN", 2048); /* ) */ +define("VAR_USCORE", 4096); +define("VAR_AT", 8192); ?> diff -Naur acid/acid_db_common.php acidfp/acid_db_common.php --- acid/acid_db_common.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_db_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,14 +4,13 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * - * Purpose: + * Purpose: database schema manipulation * */ - function createDBIndex($db, $table, $field, $index_name) { $sql = 'CREATE INDEX '.$index_name.' ON '.$table.' ('.$field.')'; @@ -115,7 +114,7 @@ { $ip32 = acidIP2long($ip); - $result = $db->acidExecute("SELECT signature FROM acid_event (ip_src=$ip32) OR (ip_dst=$ip32)"); + $result = $db->acidExecute("SELECT signature FROM acid_event (ip_src='$ip32') OR (ip_dst='$ip32')"); while ( $myrow = $result->acidFetchRow() ) $sig[] = $myrow[0]; @@ -130,7 +129,7 @@ $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT count(ip_src) FROM acid_event WHERE ". - "(ip_src=$ip32) OR (ip_dst=$ip32)"); + "(ip_src='$ip32') OR (ip_dst='$ip32')"); $myrow = $result->acidFetchRow(); $event_cnt = $myrow[0]; @@ -143,7 +142,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT DISTINCT signature FROM acid_event WHERE ". - "(ip_src=$ip32) OR (ip_dst=$ip32)"); + "(ip_src='$ip32') OR (ip_dst='$ip32')"); while ($myrow = $result->acidFetchRow()) $sig[] = $myrow[0]; @@ -157,7 +156,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT DISTINCT signature FROM acid_event WHERE ". - "(ip_src=$ip32) OR (ip_dst=$ip32)"); + "(ip_src='$ip32') OR (ip_dst='$ip32')"); while ($myrow = $result->acidFetchRow()) $sig[] = $myrow[0]; @@ -171,7 +170,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT count(signature) FROM acid_event WHERE ". - "( (ip_src=$ip32 OR ip_dst=$ip32) AND signature='$current_event')"); + "( (ip_src='$ip32' OR ip_dst='$ip32') AND signature='$current_event')"); $myrow = $result->acidFetchRow(); $tmp = $myrow[0]; @@ -184,7 +183,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT DISTINCT sid FROM acid_event WHERE ". - "( (ip_src=$ip32 OR ip_dst=$ip32) AND signature='$current_event')"); + "( (ip_src='$ip32' OR ip_dst='$ip32') AND signature='$current_event')"); while ($myrow = $result->acidFetchRow()) $sid[] = $myrow[0]; @@ -199,7 +198,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT min(timestamp) FROM acid_event WHERE ". - "((ip_src=$ip32 OR ip_dst=$ip32) AND signature = '$current_event');"); + "((ip_src='$ip32' OR ip_dst='$ip32') AND signature = '$current_event');"); $myrow = $result->acidFetchRow(); $start_time = $myrow[0]; @@ -211,7 +210,7 @@ { $ip32 = acidIP2long($ip); $result = $db->acidExecute("SELECT max(timestamp) FROM acid_event WHERE ". - "((ip_src=$ip32 OR ip_dst=$ip32) AND signature = '$current_event');"); + "((ip_src='$ip32' OR ip_dst='$ip32') AND signature = '$current_event');"); $myrow = $result->acidFetchRow(); $stop_time = $myrow[0]; diff -Naur acid/acid_db.inc acidfp/acid_db.inc --- acid/acid_db.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_db.inc 2003-12-17 14:16:39.000000000 -0500 @@ -40,7 +40,7 @@ function acidConnect($database, $host, $port, $username, $password) { - GLOBAL $sql_trace_mode, $sql_trace_file, $PHP_SELF; + GLOBAL $sql_trace_mode, $sql_trace_file, $HTTP_SERVER_VARS; $this->DB = NewADOConnection(); $this->DB_name = $database; @@ -98,7 +98,7 @@ fwrite($this->sql_trace, "\n--------------------------------------------------------------------------------\n"); fwrite($this->sql_trace, "Connect [".$this->DB_type."] ".$database."@".$host.":".$port." as ".$username."\n"); - fwrite($this->sql_trace, "[".date ("M d Y H:i:s", time())."] ".$PHP_SELF." - db version ".$this->version); + fwrite($this->sql_trace, "[".date ("M d Y H:i:s", time())."] ".$HTTP_SERVER_VARS["PHP_SELF"]." - db version ".$this->version); fwrite($this->sql_trace, "\n--------------------------------------------------------------------------------\n\n"); fflush($this->sql_trace); @@ -109,7 +109,7 @@ function acidPConnect($database, $host, $port, $username, $password) { - GLOBAL $sql_trace_mode, $sql_trace_file, $PHP_SELF; + GLOBAL $sql_trace_mode, $sql_trace_file, $HTTP_SERVER_VARS; $this->DB = NewADOConnection(); $this->DB_name = $database; @@ -167,7 +167,7 @@ fwrite($this->sql_trace, "\n--------------------------------------------------------------------------------\n"); fwrite($this->sql_trace, "PConnect [".$this->DB_type."] ".$database."@".$host.":".$port." as ".$username."\n"); - fwrite($this->sql_trace, "[".date ("M d Y H:i:s", time())."] ".$PHP_SELF." - db version ".$this->version); + fwrite($this->sql_trace, "[".date ("M d Y H:i:s", time())."] ".$HTTP_SERVER_VARS["PHP_SELF"]." - db version ".$this->version); fwrite($this->sql_trace, "\n--------------------------------------------------------------------------------\n\n"); fflush($this->sql_trace); @@ -558,20 +558,20 @@ { echo "Invalid Database Type Specified". "

The variable \$DBtype in acid_conf.php was set to the ". - "unrecognized database type of '$type'. Only the following databases are ". + "unrecognized database type of '$type'. Only the following databases are ". "supported: ". "

                 MySQL         : 'mysql'
                 PostgreSQL    : 'postgres'
                 MS SQL Server : 'mssql'
              
"; - die(); + die(); } /* Export ADODB_DIR for use by ADODB */ define('ADODB_DIR', $path); $GLOBALS['ADODB_DIR'] = $path; - + $last_char = substr($path, strlen($path)-1, 1); if ( $debug_mode > 1 ) @@ -615,4 +615,55 @@ return $mssql_kludge; } +function RepairDBTables($db) +{ +/* + if ( $db->DB_type == "mysql" ) + { + $sql = "REPAIR TABLE event, data, iphdr, tcphdr, udphdr, icmphdr, opt, sensor, detail, acid_ag, acid_ag_alert, encoding, acid_event "; + if ( $db->acidGetDBversion() >= 100 ) + { + $sql = $sql.", reference, reference_system, schema, sig_class, sig_reference"; + } + + $sql = $sql." QUICK"; + } + else if ( $db->DB_type == "postgres" ) + $sql = "VACUUM VERBOSE ANALYSE"; + else + return "This function not supported by your database type"; + + $result = $db->acidExecute($sql); + + $tmp_str = ""; + if ( $db->DB_type == "mysql" ) + { + echo "Fetching data"; + $tmp_str = ''; + $tmp_str = $tmp_str.''; + + while($myrow = $result->acidFetchRow()) + { + $tmp_str = $tmp_str.''. + ''. + ''; + } + $tmp_str = $tmp_str.'
TableTypeMessage
'.$myrow[0].''.$myrow[2].''.$myrow[3].'
'; + + //$tmp_str = $tmp_str.'

'; + $result->acidFreeRows(); + } + else if ( $db->DB_type == "postgres") + { + $tmp_str = "

Repair Complete

"; + $result->acidFreeRows(); + } + + echo "
";
+  echo $tmp_str;
+  echo "
"; + return $tmp_str; +*/ +} + ?> diff -Naur acid/acid_footer.html acidfp/acid_footer.html --- acid/acid_footer.html 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_footer.html 2003-12-17 14:16:39.000000000 -0500 @@ -1,3 +1,3 @@ -ACID v0.9.6b21 ( +ACID v0.9.6b23 ( by Roman Danyliw as part of the AirCERT project )
diff -Naur acid/acid_graph_common.php acidfp/acid_graph_common.php --- acid/acid_graph_common.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_graph_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: extracts and calculates the data to plot @@ -45,8 +45,8 @@ '"

Check the Graphing abstraction library variable $ChartLib_path'. ' in acid_conf.php

- The underlying graphing library currently used is PHPlot, that can be downloaded - at http://www.phplot.com. Without this + The underlying graphing library currently used is JPGraph, that can be downloaded + at http://www.aditus.nu/jpgraph/index.php. Without this library no graphing operations can be performed.'; die(); @@ -54,26 +54,43 @@ } function LoadGraphingLib($path) -{ - $last_char = substr($path, strlen($path)-1, 1); +{ + $libs = array ("jpgraph.php", + "jpgraph_line.php", + "jpgraph_bar.php", + "jpgraph_canvas.php", + "jpgraph_error.php", + "jpgraph_log.php", + "jpgraph_pie.php", + "jpgraph_pie3d.php", + "jpgraph_scatter.php", + "jpgraph_radar.php" ); - if ( $last_char == "\\" || $last_char == "/" ) - { - VerifyGraphingLib($path."phplot.php"); - include($path."phplot.php"); - } - else if ( strstr($path,"/") || $path == "" ) + for ( $i = 0; $i < count($libs); $i++ ) { - VerifyGraphingLib($path."/phplot.php"); - include($path."/phplot.php"); - } - else if ( strstr($path,"\\") ) - { - VerifyGraphingLib($path."\\phplot.php"); - include($path."\\phplot.php"); + $last_char = substr($path, strlen($path)-1, 1); + + if ( $last_char == "\\" || $last_char == "/" ) + { + VerifyGraphingLib($path.$libs[$i]); + include( $path.$libs[$i] ); + } + else if ( strstr($path,"/") || $path == "" ) + { + VerifyGraphingLib($path."/".$libs[$i]); + include($path."/".$libs[$i]); + } + else if ( strstr($path,"\\") ) + { + VerifyGraphingLib($path."\\".$libs[$i]); + include($path."\\".$libs[$i]); + } + else + { + echo "ERROR: Unable to load graphing library file:".$libs[$i]; + return; + } } - else - echo "ERROR: Unable to load graphing library"; } /* Generates the required SQL from the chart time criteria */ @@ -318,7 +335,7 @@ function GetIPDataSet(&$xdata, $chart_type, $data_source, $min_threshold, $criteria) { - GLOBAL $db, $debug_mode; + GLOBAL $db, $debug_mode; if ( $chart_type == 6 ) $sql = "SELECT DISTINCT ip_src, COUNT(acid_event.cid) ". @@ -352,7 +369,7 @@ function GetPortDataSet(&$xdata, $chart_type, $data_source, $min_threshold, $criteria) { - GLOBAL $db, $debug_mode; + GLOBAL $db, $debug_mode; if ( ($chart_type == 8) || ($chart_type == 9) ) $sql = "SELECT DISTINCT layer4_dport, COUNT(acid_event.cid) ". @@ -386,13 +403,12 @@ function GetClassificationDataSet(&$xdata, $chart_type, $data_source, $min_threshold, $criteria) { - GLOBAL $db, $debug_mode; - - + GLOBAL $db, $debug_mode; + $sql = "SELECT DISTINCT sig_class_id, COUNT(acid_event.cid) ". "FROM acid_event ".$criteria[0]. - "WHERE ".$criteria[1]." AND layer4_dport is NOT NULL ". - "GROUP BY sig_class_id ORDER BY sig_class_id"; + "WHERE ".$criteria[1]. /* " AND layer4_dport is NOT NULL ". */ + " GROUP BY sig_class_id ORDER BY sig_class_id"; if ( $debug_mode > 0) echo $sql."
"; @@ -405,9 +421,38 @@ { $xdata[$cnt][0] = strip_tags(GetSigClassName($myrow[0], $db)); $xdata[$cnt][1] = $myrow[1]; - //$xdata[0][1] = $xdata[1][1] = 50; - //$xdata[0][0] = 20; - //$xdata[1][0] = 80; + ++$cnt; + } + } + + $result->acidFreeRows(); + return $cnt; +} + +function GetSensorDataSet(&$xdata, $chart_type, $data_source, $min_threshold, $criteria) +{ + GLOBAL $db, $debug_mode; + + $sql = "SELECT DISTINCT acid_event.sid, COUNT(acid_event.cid) ". + "FROM acid_event ".$criteria[0]. + "WHERE ".$criteria[1]. + " GROUP BY acid_event.sid ORDER BY acid_event.sid"; + + if ( $debug_mode > 0) echo $sql."
"; + + $result = $db->acidExecute($sql); + + $cnt = 0; + while ( $myrow = $result->acidFetchRow() ) + { + if ( $myrow[1] >= $min_threshold ) + { + $result2 = $db->acidExecute("SELECT hostname FROM sensor where sid=".$myrow[0]); + $sensor_name = $result2->acidFetchRow(); + $xdata[$cnt][0] = $sensor_name[0]; + $result2->acidFreeRows(); + + $xdata[$cnt][1] = $myrow[1]; ++$cnt; } } diff -Naur acid/acid_graph_display.php acidfp/acid_graph_display.php --- acid/acid_graph_display.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_graph_display.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: Displays the actual .GIF/.PNG/.TIFF image @@ -13,6 +13,7 @@ * Input GET/POST variables * - width: chart width * - height: chart width + * - pmargin0-3: plot margins * - title: chart title * - xaxis_label: x-axis label * - yaxis_label: y-axis label @@ -23,105 +24,120 @@ */ include ("acid_conf.php"); + include ("acid_state_common.inc"); include ("acid_graph_common.php"); session_start(); - session_register('xdata'); - LoadGraphingLib($ChartLib_path); - - /* Verifies that the chart width is not too small - * - * algorithm: width >= const + number_of_points * factor - */ - $width_const = 50; - $width_factor = 10; - - if ( $width < ($width_const + count ($data) * $width_factor)) { - $width = $width_const + count ($data) * $width_factor; - } + $xdata = $HTTP_SESSION_VARS['xdata']; + $width = ImportHTTPVar("width"); + $height = ImportHTTPVar("height"); + $pmargin0 = ImportHTTPVar("pmargin0"); + $pmargin1 = ImportHTTPVar("pmargin1"); + $pmargin2 = ImportHTTPVar("pmargin2"); + $pmargin3 = ImportHTTPVar("pmargin3"); + $title = ImportHTTPVar("title"); + $xaxis_label = ImportHTTPVar("xaxis_label"); + $yaxis_label = ImportHTTPVar("yaxis_label"); + $yaxis_scale = ImportHTTPVar("yaxis_scale"); + $xaxis_grid = ImportHTTPVar("xaxis_grid"); + $yaxis_grid = ImportHTTPVar("yaxis_grid"); + $rotate_xaxis_lbl = ImportHTTPVar("rotate_xaxis_lbl"); + $style = ImportHTTPVar("style"); - $graph = new PHPlot($width, $height); - $graph->SetIsInline("0"); - $graph->SetBrowserCache("0"); - - /* Allocate enough space for the X,Y-axis data label */ - $x_maxlength = 10; /* 10 is the PHP default size */ + LoadGraphingLib($ChartLib_path); - /* Create the data array */ + /* Create the data and label array */ for ($i = 0; $i < count($xdata); $i++) { - if ( $style != "pie" ) - { - $xdata_graph[$i] = array($xdata[$i][0], $xdata[$i][1]); - } - else - { - $xdata[$i] = array( count($data)+1 ); - $xdata[$i][0] = $datalbl[$i]; - for ( $j = 1; $j < $i; $j++) - $xdata[$i][$j] = 0; - $xdata[$i][$i+1] = $data[$i]; - - $legend[$i] = $datalbl[$i]; - } - - if (strlen($xdata[$i][0]) > $x_maxlength) - { - // if the label is too small, expand the label size to fit - $x_maxlength = strlen($xdata[$i][0]); - } + $xlabel[$i] = $xdata[$i][0]; + $ydata[$i] = $xdata[$i][1]; } - $graph->SetDataType("text-data"); - $graph->SetPlotType($style); - + if ( $style == "pie" ) + $graph = new PieGraph($width, $height); + else + $graph = new Graph($width, $height); + + /* Set Margins */ + $graph->img->SetMargin($pmargin0,$pmargin1,$pmargin2,$pmargin3); + $graph->img->SetAntiAliasing(); + + //$graph->SetShadow(); + + /* Set Plot type */ switch($style) { - case "bars": - $graph->SetDataType("text-data"); - break; - case "linepoints": - $graph->SetDataType("text-data"); + case "bar": + $plot[0] = new BarPlot($ydata); break; case "pie": - $graph->SetDataType("text-data"); - $graph->SetLegend($legend); + $plot[0] = new PiePlot3D($ydata); break; - case "thinbarline": - $graph->SetDataType("data-data"); + case "line": + $plot[0] = new LinePlot($ydata); break; } - /* read the X-axis labels as text */ - $graph->SetXGridLabelType ("title"); + //$plot[0]->SetColor("#000000"); + + if ( ($style == "bar") || ($style == "line") ) + { + /* Set Scale */ + if ( $yaxis_scale == 1 ) + $graph->SetScale("textlog"); + else + $graph->SetScale("textlin"); + + $plot[0]->SetFillColor("#BE0505"); + //$plot[0]->SetFillColor($GLOBALS['chart_bar_color_default']); + + /* Set Gridlines */ + if ( $xaxis_grid == 1 ) + $graph->xgrid->Show(true); + else + $graph->xgrid->Show(false); + + if ( $yaxis_grid == 1 ) + $graph->ygrid->Show(true); + else + $graph->ygrid->Show(false); + + /* Set Axis Labels */ + $graph->xaxis->title->Set($xaxis_label); + $graph->yaxis->title->Set($yaxis_label); + + //$graph->xaxis->SetFont(FF_ARIAL,FS_NORMAL,11); + + $graph->xaxis->SetTickLabels($xlabel); + + if ( $rotate_xaxis_lbl == 1 ) + $graph->xaxis->SetLabelAngle(90); + } + + if ( $style == "pie" ) + { + $plot[0]->SetLegends($xlabel); + } + + //$plot[0]->ShowValue(true); + //$plot[0]->SetShadow(); + + /* Set Title */ + //$graph->title->SetFont(FF_COMIC,FS_NORMAL,18); + $graph->title->Set($title); + + + $graph->Add($plot[0]); + + $graph->Stroke(); +?> + + + + + + - $graph->SetPrecisionY(0); - $graph->SetPrecisionX(0); - $graph->SetBackgroundColor($chart_bg_color_default); - $graph->SetLightGridColor($chart_lgrid_color_default); - /* Check if need to rotate X-Axis label */ - if ( $rotate_xaxis_lbl == 1 ) - $graph->SetXDataLabelAngle(90); - - $graph->SetFileFormat($chart_file_format); - //$graph->SetUseTTF("0"); - - /* Set y-axis scale */ - if ( $yaxis_scale == 1 ) - $graph->SetYScaleType("log"); - - $graph->SetXDataLabelMaxlength($x_maxlength); - $graph->SetDrawYGrid("1"); - $graph->SetDataValues($xdata_graph); - $graph->SetXLabel($xaxis_label); - $graph->SetYLabel($yaxis_label); - $graph->SetTitle($title); - $graph->SetDataColors( array( $chart_bar_color_default ), - array("black") ); - //$graph->SetBackgroundColor("grey"); - $graph->DrawGraph(); - //$graph->DrawLegend(100, 100, ''); -?> \ No newline at end of file diff -Naur acid/acid_graph_form.php acidfp/acid_graph_form.php --- acid/acid_graph_form.php 1969-12-31 19:00:00.000000000 -0500 +++ acidfp/acid_graph_form.php 2003-12-17 14:16:39.000000000 -0500 @@ -0,0 +1,214 @@ +, + * + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University + * (see the file 'acid_main.php' for license details) + * + * Purpose: displays form for graphing + */ + + echo '

'; + + echo ' + + '; + + echo ' +
'; + + echo 'Chart Title:   +
'; + + echo 'Chart Type:  + '; + + // Do you need other periods? Simply add them! + echo '  Chart Period:  +
'; + + echo '  Size: (width x height) +   +  x +   +   
'; + + echo '  Plot Margins: (left x right x top x bottom) +   +  x +   +  x +   +  x +   +   
'; + + echo '  Plot type:    + bar    + line    + pie '; + + echo '
Chart Begin:  + + + + '; + + echo '
Chart End:     + + + + '; + + echo '
+   
+
+ + + + + + + + + +
X AxisY Axis
+ Data Source:   +
'. + /**/ + 'Minimum Threshold Value ( >= ): + +    +
+ +   + Rotate Axis Labels (90 degrees)
+ +   + Show X-axis grid-lines
+ Display X-axis label every + +   data points +
+   + Y-axis logarithmic
+   + Show Y-axis grid-lines +
'; + + echo '


'; + +?> diff -Naur acid/acid_graph_main.php acidfp/acid_graph_main.php --- acid/acid_graph_main.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_graph_main.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: @@ -27,9 +27,12 @@ $cs->ReadState(); session_start(); - session_register('xdata'); $submit = ImportHTTPVar("submit"); + + $height = ImportHTTPVar("height"); + $width = ImportHTTPVar("width"); + $user_chart_title = ImportHTTPVar("user_chart_title"); $data_source = ImportHTTPVar("data_source"); $chart_type = ImportHTTPVar("chart_type"); $chart_interval = ImportHTTPVar("chart_interval"); @@ -46,6 +49,19 @@ $chart_style = ImportHTTPVar("chart_style"); $rotate_xaxis_lbl = ImportHTTPVar("rotate_xaxis_lbl"); + $yaxis_scale = ImportHTTPVar("yaxis_scale"); + $xaxis_grid = ImportHTTPVar("xaxis_grid"); + $yaxis_grid = ImportHTTPVar("yaxis_grid"); + + $pmargin0 = ImportHTTPVar("pmargin0"); + $pmargin1 = ImportHTTPVar("pmargin1"); + $pmargin2 = ImportHTTPVar("pmargin2"); + $pmargin3 = ImportHTTPVar("pmargin3"); + + $xaxis_label_inc = ImportHTTPVar("xaxis_label_inc"); + + $min_size = ImportHTTPVar("min_size"); + $aggregate_type = ImportHTTPVar("aggregate_type"); $page_title = "Graph Alert Data"; PrintACIDSubHeader($page_title, $page_title, $cs->GetBackLink()); @@ -60,19 +76,21 @@ if ( $event_cache_auto_update == 1 ) UpdateAlertCache($db); ?> -
- - - '; - - echo ''; - echo '
Chart Title:   -
'; - - echo 'Chart Type:  - '; - - // Do you need other periods? Simply add them! - echo '  Chart Period:  -
'; - - echo '  Size: (width x height) -   -  x -   -   '; - echo 'Graph type:    - bar    - thin bar    - line    - '; - - echo '
Chart Begin:  - - - - '; - - echo '
Chart End:     - - - - '; - - - - echo '
-   
-
- - - - - - - - - -
X AxisY Axis
- Data Source:   -
'. - /**/ - 'Minimum Threshold Value ( >= ): - -    - -   - Rotate Axis Labels (90 degrees)
- Display X-axis label every - -   data points -
-  Y-axis logarithmic -
'; - - echo '
- -


'; + include("acid_graph_form.php"); $data_pnt_cnt = 0; /* Error Conditions */ @@ -299,7 +142,7 @@ { $criteria[0] = "LEFT JOIN acid_ag_alert ". "ON (acid_event.sid=acid_ag_alert.ag_sid AND acid_event.cid=acid_ag_alert.ag_cid) "; - $criteria[1] = "ag_id = $data_source"; + $criteria[1] = "acid_ag_alert.ag_id = $data_source"; if ( $time_constraint != NULL ) $criteria[1] = $criteria[1].$time_constraint; @@ -395,6 +238,15 @@ $data_pnt_cnt = GetClassificationDataSet($xdata, $chart_type, $data_source, $min_size, $criteria); break; } + case 13: // Sensor vs. Num Alerts + { + $chart_title = "Sensor vs. Number of Alerts"; + $xaxis_label = "Sensor"; + $yaxis_label = "Alert Occurrences"; + + $data_pnt_cnt = GetSensorDataSet($xdata, $chart_type, $data_source, $min_size, $criteria); + break; + } } if ( $data_pnt_cnt > 0 ) @@ -444,15 +296,20 @@ '; + $HTTP_SESSION_VARS['xdata'] = $xdata; echo "
"; + "&yaxis_scale=".$yaxis_scale. + "&xaxis_grid=".$xaxis_grid. + "&yaxis_grid=".$yaxis_grid. + "&style=".$chart_style."\">"; echo ' diff -Naur acid/acid_log_error.inc acidfp/acid_log_error.inc --- acid/acid_log_error.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_log_error.inc 2003-12-17 14:16:39.000000000 -0500 @@ -32,12 +32,27 @@ GLOBAL $HTTP_SERVER_VARS, $DBtype, $ADODB_vers, $HTTP_SESSION_VARS; $tmp = session_encode(); + + if ( isset($HTTP_SERVER_VARS['HTTP_REFERER']) ) + $http_referer = $HTTP_SERVER_VARS['HTTP_REFERER']; + else + $http_referer = ""; + if ( isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']) ) + $http_user_agent = $HTTP_SERVER_VARS['HTTP_USER_AGENT']; + else + $http_user_agent = ""; + + if ( isset($HTTP_SERVER_VARS['SERVER_SOFTWARE']) ) + $server_software = $HTTP_SERVER_VARS['SERVER_SOFTWARE']; + else + $server_software = ""; + echo "
-         URL: '".$HTTP_SERVER_VARS["PHP_SELF"]."' (referred by: '".$HTTP_SERVER_VARS["HTTP_REFERER"]."')
+         URL: '".$HTTP_SERVER_VARS["PHP_SELF"]."' (referred by: '".$http_referer."')
          PARAMETERS: '".$HTTP_SERVER_VARS["QUERY_STRING"]."
-         CLIENT: ".$HTTP_SERVER_VARS["HTTP_USER_AGENT"]."
-         SERVER: ".$HTTP_SERVER_VARS["SERVER_SOFTWARE"]."
+         CLIENT: ".$http_user_agent."
+         SERVER: ".$server_software."
          SERVER HW: ".php_uname()."
          DATABASE TYPE: $DBtype  DB ABSTRACTION VERSION: $ADODB_vers
          PHP VERSION: ".phpversion()."  PHP API: ".php_sapi_name()."
@@ -55,4 +70,4 @@
    echo "
"; } -?> +?> \ No newline at end of file diff -Naur acid/acid_main.php acidfp/acid_main.php --- acid/acid_main.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_main.php 2003-12-17 14:17:10.000000000 -0500 @@ -49,8 +49,14 @@ include_once("acid_db_common.php"); RegisterGlobalState(); - InitGlobalState(); - PreserveHistory(); + //InitGlobalState(); + + /* Initialize the history */ + $HTTP_SESSION_VARS = NULL; + InitArray($HTTP_SESSION_VARS['back_list'], 1, 3, ""); + $HTTP_SESSION_VARS['back_list_cnt'] = 0; + + PushHistory(); ?> @@ -138,7 +144,7 @@

  • Search -
  • Graph Alert data (EXPERIMENTAL) +
  • Graph Alert data 

  • Snapshot @@ -196,7 +202,7 @@ echo ' - -
    +
  • Most recent Alerts: any protocol, @@ -217,6 +223,10 @@ ?>
  • Most recent Unique Alerts +
  • Network Fingerprints: most recent;  + by address,  + port,  + service 

  • Last Source Ports: @@ -249,7 +259,7 @@
  • +
  • Most frequent Alerts diff -Naur acid/acid_maintenance.php acidfp/acid_maintenance.php --- acid/acid_maintenance.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_maintenance.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: status and event/dns/whois cache maintenance @@ -42,8 +42,10 @@ if ( $debug_mode > 0 ) echo "submit = '$submit'

    "; - set_time_limit($max_script_runtime); + if ( ini_get("safe_mode") != true ) + set_time_limit($max_script_runtime); + $repair_output = NULL; if ( $submit == "Update Alert Cache" ) { UpdateAlertCache($db); @@ -71,14 +73,18 @@ DropWhoisCache($db); UpdateWhoisCache($db); } + else if ( $submit == "Repair Tables") + { + $repair_output = RepairDBTables($db); + } echo ' -
    PHP build
    - CLIENT: '.$HTTP_USER_AGENT.'
    - SERVER: '.$SERVER_SOFTWARE.'
    + CLIENT: '.$HTTP_SERVER_VARS['HTTP_USER_AGENT'].'
    + SERVER: '.$HTTP_SERVER_VARS['SERVER_SOFTWARE'].'
    SERVER HW: '.php_uname().'
    PHP VERSION: '.phpversion().'
    PHP API: '.php_sapi_name().'
    '; @@ -134,10 +140,15 @@ ALERT DB Name: $alert_dbname
    ARCHIVE DB Name: $archive_dbname
    + "; + + echo $repair_output; + + echo '

    "; +

  • '; echo ''; } -function qroPrintEntry($value) +function qroPrintEntry($value, $halign="center", $valign="top", $passthru="") { - echo "
    diff -Naur acid/acid_net.inc acidfp/acid_net.inc --- acid/acid_net.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_net.inc 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: TCP/IP network routines @@ -17,7 +17,7 @@ * Purpose: convert a text string IPv4 address into its 32-bit numeric * equivalent * - * Arguments: $IP_str => dotted IPv4 address string (e.g. 1.2.3.4) + :* Arguments: $IP_str => dotted IPv4 address string (e.g. 1.2.3.4) * * Returns: 32-bit integer equivalent of the dotted address * (e.g. 255.255.255.255 => 4294967295 ) @@ -143,7 +143,7 @@ $current_time = date("Y-m-d H:i:s",$current_unixtime); $sql = "SELECT ipc_ip,ipc_fqdn,".$db->acidSQL_UNIXTIME("(ipc_dns_timestamp)", "","").",ipc_dns_timestamp". " FROM acid_ip_cache ". - " WHERE ipc_ip = $ip32 "; + " WHERE ipc_ip = '$ip32' "; $result = $db->acidExecute($sql); $ip_cache = $result->acidFetchRow(); @@ -160,7 +160,8 @@ } else /* cache hit */ { - if ( ( ($ip_cache[2] / 60)+$cache_lifetime ) <= ($current_unixtime / 60) ) + if ( (( ($ip_cache[2] / 60)+$cache_lifetime ) <= ($current_unixtime / 60)) && + ($ip_cache[2] != "") ) { /* valid entry */ if ( ($ip_cache[2] != "") && ($ip_cache[2] != 0) ) @@ -176,7 +177,7 @@ /* Update entry in cache regardless of whether can resolve */ $sql = "UPDATE acid_ip_cache SET ipc_fqdn='$tmp', ". - " ipc_dns_timestamp='$current_time' WHERE ipc_ip=$ip32"; + " ipc_dns_timestamp='$current_time' WHERE ipc_ip='$ip32'"; $db->acidExecute($sql); } } @@ -209,7 +210,7 @@ $current_time = date("Y-m-d H:i:s",$current_unixtime); $sql = "SELECT ipc_ip,ipc_whois,".$db->acidSQL_UNIXTIME("(ipc_whois_timestamp)", "","").",ipc_whois_timestamp". " FROM acid_ip_cache ". - " WHERE ipc_ip = $ip32 "; + " WHERE ipc_ip = '$ip32' "; $result = $db->acidExecute($sql); $whois_cache = $result->acidFetchRow(); @@ -247,7 +248,7 @@ /* Update entry in cache regardless of whether can resolve */ $sql = "UPDATE acid_ip_cache SET ipc_whois='".getSafeSQLString($tmp)."', ". - " ipc_whois_timestamp='$current_time' WHERE ipc_ip=$ip32"; + " ipc_whois_timestamp='$current_time' WHERE ipc_ip='$ip32'"; $db->acidExecute($sql); } } diff -Naur acid/acid_output_html.inc acidfp/acid_output_html.inc --- acid/acid_output_html.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_output_html.inc 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2001 Carnegie Mellon University + * Copyright (C) 2001,2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: Prints or generates HTML to display @@ -15,7 +15,8 @@ GLOBAL $debug_mode, $ACID_VERSION, $html_no_cache, $max_script_runtime; - set_time_limit($max_script_runtime); + if ( ini_get("safe_mode") != true ) + set_time_limit($max_script_runtime); echo ' @@ -96,11 +97,11 @@ function PrintFreshPage($refresh_stat_page, $stat_page_refresh_time) { - GLOBAL $PHP_SELF; + GLOBAL $HTTP_SERVER_VARS; if ( $refresh_stat_page ) echo ''."\n"; + '"; URL="'.$HTTP_SERVER_VARS["PHP_SELF"].'";>'."\n"; } function chk_select($stored_value, $current_value) diff -Naur acid/acid_output_query.inc acidfp/acid_output_query.inc --- acid/acid_output_query.inc 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_output_query.inc 2003-12-17 14:16:39.000000000 -0500 @@ -134,9 +134,9 @@ echo '
    \n". + echo "\n". "   \n". " $value\n". "   \n". diff -Naur acid/acid_qry_alert.php acidfp/acid_qry_alert.php --- acid/acid_qry_alert.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_qry_alert.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2001 Carnegie Mellon University + * Copyright (C) 2001,2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: displays a single alert @@ -55,7 +55,7 @@ * to the history. */ $submit = ImportHTTPVar("submit"); - $QUERY_STRING = "submit=".rawurlencode($submit); + $HTTP_SERVER_VARS["QUERY_STRING"] = "submit=".rawurlencode($submit); $et = new EventTiming($debug_time_mode); $cs = new CriteriaState("acid_qry_alert.php"); @@ -79,6 +79,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); @@ -205,7 +206,7 @@ $sql4 = "SELECT acid_ag_alert.ag_id, ag_name, ag_desc ". "FROM acid_ag_alert LEFT JOIN acid_ag ON acid_ag_alert.ag_id = acid_ag.ag_id ". - "WHERE ag_sid=".$sid." AND ag_cid=".$cid; + "WHERE ag_sid='".$sid."' AND ag_cid='".$cid."'"; $result4 = $db->acidExecute($sql4); $num = $result4->acidRecordCount(); @@ -540,11 +541,16 @@ $work = str_replace("\n","",$myrow2[0]); /* - * depending on how the packet logged, 32-bits of NULL padding after - * the checksum may still be present. + * - depending on how the packet logged, 32-bits of NULL padding after + * the checksum may still be present. */ if ( substr($work, 0, 8) == "00000000" ) $offset = 8; + /* for dest. unreachable, frag needed and DF bit set indent the padding + * of MTU of next hop + */ + else if ( ($ICMPitype == "3") && ($ICMPicode == "4") ) + $offset += 8; $icmp_src = hexdec($work[24+$offset].$work[25+$offset]).".". hexdec($work[26+$offset].$work[27+$offset]).".". @@ -556,7 +562,7 @@ hexdec($work[38+$offset].$work[39+$offset]); $icmp_proto = hexdec($work[18+$offset].$work[19+$offset]); - $hdr_offset = ($work[$offset+1]) * 8 + offset; + $hdr_offset = ($work[$offset+1]) * 8 + $offset; $icmp_src_port = hexdec($work[$hdr_offset].$work[$hdr_offset+1].$work[$hdr_offset+2].$work[$hdr_offset+3]); $icmp_dst_port = hexdec($work[$hdr_offset+4].$work[$hdr_offset+5].$work[$hdr_offset+6].$work[$hdr_offset+7]); diff -Naur acid/acid_qry_common.php acidfp/acid_qry_common.php --- acid/acid_qry_common.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_qry_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -5,7 +5,7 @@ * Author: Roman Danyliw , * MSSQL support by Charles Hand * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * Portions Copyright (C) 2001 Iowa National Guard * (see the file 'acid_main.php' for license details) * @@ -17,67 +17,52 @@ function PrintCriteriaState() { - GLOBAL $time, $time_cnt, - $sig, $sig_type, - $sensor, - $ag, - $ip_addr, $ip_addrs, $ip_addr_cnt, - $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, - $tcp_flags, - $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, - $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $data, $data_cnt, - $layer4, $MAX_ROWS, - $new, $submit, $sort_order, $num_result_rows, - $current_view, $caller, $action, $action_arg, - $sort_order, $debug_mode; - - if ( $debug_mode >= 2 ) - { - echo "
    ";
    -  echo "sensor: $sensor
    \n - AG: $ag
    \n - signature"; - print_r($sig); - echo "
    time ($time_cnt):
    "; - print_r($time); - echo "
    IP addresses ($ip_addr_cnt):
    "; - print_r($ip_addr); - echo "
    ===================================================
    "; - print_r($ip_addrs); - echo "
    IP fields ($ip_field_cnt):
    "; - print_r($ip_field); - echo "
    TCP ports ($tcp_port_cnt):
    "; - print_r($tcp_port); - echo "
    TCP flags:
    "; - print_r($tcp_flags); - echo "
    TCP field ($tcp_field_cnt):
    "; - print_r($tcp_field); - echo "
    UDP ports ($udp_port_cnt):
    "; - print_r($udp_port); - echo "
    UDP field ($udp_field_cnt):
    "; - print_r($udp_field); - echo "
    ICMP field ($icmp_field_cnt):
    "; - print_r($icmp_field); - echo "
    Data ($data_cnt):
    "; - print_r($data); - echo "
    "; - } - - if ( $debug_mode >= 1 ) - { - echo "
    -        new: '$new'   
    -        submit: '$submit'
    -        sort_order: '$sort_order'
    -        num_result_rows: '$num_result_rows'  current_view: '$current_view'
    -        layer4: '$layer4'  caller: '$caller'
    -        action: '$action'  action_arg: '$action_arg'
    -        
    "; - } + GLOBAL $HTTP_SESSION_VARS, $layer4, + $new, $submit, $sort_order, $num_result_rows, + $current_view, $caller, $action, $action_arg, + $sort_order; + + if ( $GLOBALS['debug_mode'] >= 2 ) + { + echo "
    ";
    +      echo "sensor: ".$HTTP_SESSION_VARS['sensor']."
    \n". + "AG: ".$HTTP_SESSION_VARS['ag']."
    \n". + "signature\n"; + print_r($HTTP_SESSION_VARS['sig']); + echo "
    time (".$HTTP_SESSION_VARS['time_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['time']); + echo "
    IP addresses (".$HTTP_SESSION_VARS['ip_addr_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['ip_addr']); + echo "
    IP fields (".$HTTP_SESSION_VARS['ip_field_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['ip_field']); + echo "
    TCP ports (".$HTTP_SESSION_VARS['tcp_port_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['tcp_port']); + echo "
    TCP flags:
    "; + print_r($HTTP_SESSION_VARS['tcp_flags']); + echo "
    TCP field (".$HTTP_SESSION_VARS['tcp_field_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['tcp_field']); + echo "
    UDP ports (".$HTTP_SESSION_VARS['udp_port_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['udp_port']); + echo "
    UDP field (".$HTTP_SESSION_VARS['udp_field_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['udp_field']); + echo "
    ICMP field (".$HTTP_SESSION_VARS['icmp_field_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['icmp_field']); + echo "
    Data (".$HTTP_SESSION_VARS['data_cnt']."):
    "; + print_r($HTTP_SESSION_VARS['data']); + echo "
    "; + } + + if ( $GLOBALS['debug_mode'] >= 1 ) + { + echo "
    +            new: '$new'   
    +            submit: '$submit'
    +            sort_order: '$sort_order'
    +            num_result_rows: '$num_result_rows'  current_view: '$current_view'
    +            layer4: '$layer4'  caller: '$caller'
    +            action: '$action'  action_arg: '$action_arg'
    +            
    "; + } } function FieldRows2sql($field, $cnt, &$s_sql) @@ -88,8 +73,8 @@ $tmp = ""; if ( $field[$i][3] != "" && $field[$i][1] != " ") { - $tmp = $field[$i][0]." ".$field[$i][1]." ".$field[$i][2]."". - $field[$i][3]."".$field[$i][4]." ".$field[$i][5]; + $tmp = $field[$i][0]." ".$field[$i][1]." ".$field[$i][2]." '". + $field[$i][3]."' ".$field[$i][4]." ".$field[$i][5]; } else { @@ -139,7 +124,7 @@ for ( $i = 0; $i < $cnt; $i++ ) { $tmp = ""; - if ( $field[$i][1] != " " && $field[$i][1] != "") + if ( isset($field[$i]) && $field[$i][1] != " " && $field[$i][1] != "") { $op = $field[$i][1]; @@ -250,12 +235,15 @@ } else { - if ( ($field[$i][2] != " " || $field[$i][3] != "" || $field[$i][4] != " ") && + if ( isset($field[$i]) ) + { + if ( ($field[$i][2] != " " || $field[$i][3] != "" || $field[$i][4] != " ") && $field[$i][1] == " ") - ErrorMessage("Criteria warning: A date/time value of '". - $field[$i][2]."-".$field[$i][3]."-".$field[$i][4]." ". - $field[$i][5].":".$field[6].":".$field[7]."' was entered - but no operator was selected."); + ErrorMessage("Criteria warning: A date/time value of '". + $field[$i][2]."-".$field[$i][3]."-".$field[$i][4]." ". + $field[$i][5].":".$field[6].":".$field[7]."' was entered + but no operator was selected."); + } } if ( $i > 0 && $field[$i-1][9] == ' ' && $field[$i-1][4] != " ") @@ -357,54 +345,10 @@ function PrintCriteria($caller) { - GLOBAL $db, $cs, $last_num_alerts, $time, $time_cnt, $sig, $sig_type, - $sensor, $ag, $sig_class, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $save_criteria; - - /* Generate the Criteria entered into a human readable form */ - $human_fields["ip_src"] = "Source Address"; - $human_fields["ip_dst"] = "Dest. Address"; - $human_fields["ip_both"] = "Source or Dest. Address"; - $human_fields["ip_ttl"] = "TTL"; - $human_fields["ip_tos"] = "TOS"; - $human_fields["ip_id"] = "ID"; - $human_fields["ip_off"] = "offset"; - $human_fields["ip_len"] = "length"; - $human_fields["ip_csum"] = "chksum"; - $human_fields["layer4_sport"] = "source port"; - $human_fields["layer4_dport"] = "dest port"; - $human_fields[""] = ""; - $human_fields["tcp_win"] = "window"; - $human_fields["tcp_urp"] = "urp"; - $human_fields["tcp_seq"] = "seq #"; - $human_fields["tcp_ack"] = "ack"; - $human_fields["tcp_off"] = "offset"; - $human_fields["tcp_res"] = "res"; - $human_fields["tcp_csum"] = "chksum"; - $human_fields["udp_len"] = "length"; - $human_fields["udp_csum"] = "chksum"; - $human_fields["icmp_type"] = "type"; - $human_fields["icmp_code"] = "code"; - $human_fields["icmp_csum"] = "chksum"; - $human_fields["icmp_id"] = "id"; - $human_fields["icmp_seq"] = "seq"; - $human_fields["LIKE"] = "contains"; - $human_fields["="] = "="; - $human_fields["1"] = "F"; - $human_fields["2"] = "S"; - $human_fields["4"] = "R"; - $human_fields["8"] = "P"; - $human_fields["16"] = "A"; - $human_fields["32"] = "U"; - $human_fields["64"] = "[R0]"; - $human_fields["128"] = "[R1]"; + GLOBAL $db, $cs, $last_num_alerts, + $save_criteria; - //$save_criteria = ' Queried DB on : '.date("D F d, Y H:i:s",time()).' + /* Generate the Criteria entered into a human readable form */ $save_criteria = ' @@ -430,85 +374,15 @@ return; } -// if ( $have_meta == 1 ) -// { $tmp_len = strlen($save_criteria); - if ( $sensor != " " && $sensor != "" ) - $save_criteria = $save_criteria.'Sensor = ['.$sensor.'] '. - GetSensorName($sensor, $db). - $cs->GetClearCriteriaString("sensor").'
    '; - - if ( $ag != " " && $ag != "" ) - $save_criteria = $save_criteria.'Alert Group = ['.$ag.'] '.GetAGNameByID($ag, $db). - $cs->GetClearCriteriaString("ag").'
    '; - - if ( $sig[0] != " " && $sig[1] != "" ) - { - if ( $sig[0] == '=' && $sig[2] == '!=' ) - $tmp_human = '!='; - else if ( $sig[0] == '=' && $sig[2] == '=' ) - $tmp_human = '='; - else if ( $sig[0] == 'LIKE' && $sig[2] == '!=' ) - $tmp_human = ' does not contain '; - else if ( $sig[0] == 'LIKE' && $sig[2] == '=' ) - $tmp_human = ' contains '; - - $save_criteria = $save_criteria.'Signature '.$tmp_human.' "'; - if ( ($db->acidGetDBVersion() >= 100) && $sig_type == 1 ) - $save_criteria = $save_criteria.BuildSigByID($sig[1], $db).'" '. - $cs->GetClearCriteriaString("sig"); - else - $save_criteria = $save_criteria.$sig[1]. - $cs->GetClearCriteriaString("sig"); - - $save_criteria = $save_criteria.'
    '; - } - - if ( $db->acidGetDBVersion() >= 103 ) - { - if ( $sig_class != " " && $sig_class != "" ) - { - if ( $sig_class == "null") - $save_criteria = $save_criteria.'Signature Classification = '. - 'unclassified
    '; - else - $save_criteria = $save_criteria.'Signature Classification = '. - GetSigClassName($sig_class, $db). - $cs->GetClearCriteriaString("sig_class").'
    '; - } - } - - $tmp_len2 = strlen($save_criteria); - for ($i = 0; $i < $time_cnt; $i++) - { - if ( $time[$i][1] != " " ) - { - $save_criteria = $save_criteria.''.$time[$i][0].' time '.$time[$i][1].' [ '; - - /* date */ - if ( $time[$i][2] == " " && $time[$i][3] == "" && $time[$i][4] == " " ) - $save_criteria = $save_criteria." any date"; - else - $save_criteria = $save_criteria.(($time[$i][2] == " ") ? "* / " : $time[$i][2]." / "). - (($time[$i][3] == "" ) ? "* / " : $time[$i][3]." / "). - (($time[$i][4] == " ") ? "* " : $time[$i][4]." "); - $save_criteria = $save_criteria.'] ['; - /* time */ - if ( $time[$i][5] == "" && $time[$i][6] == "" && $time[$i][7] == "" ) - $save_criteria = $save_criteria."any time"; - else - $save_criteria = $save_criteria.(($time[$i][5] == "") ? "* : " : $time[$i][5]." : "). - (($time[$i][6] == "") ? "* : " : $time[$i][6]." : "). - (($time[$i][7] == "") ? "* " : $time[$i][7]." "); - $save_criteria = $save_criteria.$time[$i][8].$time[$i][9]; - $save_criteria = $save_criteria.']'; - $save_criteria = $save_criteria.'
    '; - } - } - if ( $tmp_len2 < strlen($save_criteria) ) - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("time"); + $save_criteria = $save_criteria.$cs->criteria['sensor']->Description(); + $save_criteria = $save_criteria.$cs->criteria['sig']->Description(); + $save_criteria = $save_criteria.$cs->criteria['sig_class']->Description(); + $save_criteria = $save_criteria.$cs->criteria['sig_priority']->Description(); + $save_criteria = $save_criteria.$cs->criteria['ag']->Description(); + $save_criteria = $save_criteria.$cs->criteria['time']->Description(); if ( $tmp_len == strlen($save_criteria) ) $save_criteria = $save_criteria.'    any '; @@ -519,114 +393,28 @@ '; - if ( $layer4 == "TCP" ) - { - $save_criteria = $save_criteria.' - - - '; } - else if ( $layer4 == "UDP" ) + else if ( $cs->criteria['layer4']->Get() == "UDP" ) { - $save_criteria = $save_criteria.' - - - '; } - else if ( $layer4 == "ICMP" ) + else if ( $cs->criteria['layer4']->Get() == "ICMP" ) { - $save_criteria = $save_criteria.' - - - '; } - else { - $save_criteria = $save_criteria.' - - - '; + $save_criteria = $save_criteria.'    none '; } /* Payload ************** */ @@ -715,26 +456,9 @@ '. '
    IP Criteria '; -// if ( $have_ip == 1 ) -// { - $tmp_len = strlen($save_criteria); - $have_criteria = 0; - for ( $i = 0; $i < $ip_addr_cnt; $i++ ) - { - $tmp = ""; - if ( isset($ip_addr[$i][3]) && $ip_addr[$i][3] != "" ) - { - $tmp = $tmp.$ip_addr[$i][3]; - if ( $ip_addr[$i][4] != "" ) - { - $tmp = $tmp.".".$ip_addr[$i][4]; - if ( $ip_addr[$i][5] != "" ) - { - $tmp = $tmp.".".$ip_addr[$i][5]; - if ( $ip_addr[$i][6] != "" ) - { - if ( ($ip_addr[$i][3].".".$ip_addr[$i][4].".". - $ip_addr[$i][5].".".$ip_addr[$i][6]) == NULL_IP) - $tmp = " unknown "; - else - $tmp = $tmp.".".$ip_addr[$i][6]; - } - else - $tmp = $tmp.'.*'; - } - else - $tmp = $tmp.'.*.*'; - } - else - $tmp = $tmp.'.*.*.*'; - } - /* Make sure that the IP isn't blank */ - if ( $tmp != "" ) - { - $mask = ""; - if ( $ip_addr[$i][10] != "" ) - $mask = "/".$ip_addr[$i][10]; - - $save_criteria = $save_criteria.$ip_addr[$i][0]. - $human_fields[($ip_addr[$i][1])].' '.$ip_addr[$i][2]. - ' '.$tmp.' '.$ip_addr[$i][8].' '.$ip_addr[$i][9].$mask. - $cs->GetClearCriteriaString("ip_addr")."
    "; - } - } - - $tmp_len2 = strlen($save_criteria); - for ( $i = 0; $i < $ip_field_cnt; $i++ ) - { - if ($ip_field[$i][1] != " " && $ip_field[$i][3] != "" ) - $save_criteria = $save_criteria.$ip_field[$i][0].$human_fields[($ip_field[$i][1])].' '. - $ip_field[$i][2].' '.$ip_field[$i][3].$ip_field[$i][4].' '.$ip_field[$i][5]; - } - if ( $tmp_len2 < strlen($save_criteria) ) - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("ip_field"); - - if ( $tmp_len == strlen($save_criteria) ) - $save_criteria = $save_criteria.'    any '; + if ( !$cs->criteria['ip_addr']->isEmpty() || !$cs->criteria['ip_field']->isEmpty() ) + { + $save_criteria = $save_criteria.$cs->criteria['ip_addr']->Description(); + $save_criteria = $save_criteria.$cs->criteria['ip_field']->Description(); + } + else + $save_criteria = $save_criteria.'    any '; $save_criteria = $save_criteria.'  
    TCP Criteria'; + $save_criteria = $save_criteria.'
    '; + $save_criteria = $save_criteria.$cs->criteria['layer4']->Description(); + $save_criteria = $save_criteria.''; - if ( $have_tcp == 1 ) + if ( $cs->criteria['layer4']->Get() == "TCP" ) + { + if ( !$cs->criteria['tcp_port']->isEmpty() || !$cs->criteria['tcp_flags']->isEmpty() || !$cs->criteria['tcp_field']->isEmpty() ) { - $have_criteria = 0; - for ( $i = 0; $i < $tcp_port_cnt; $i++ ) - { - if ($tcp_port[$i][1] != " " && $tcp_port[$i][3] != "" ) - { - $save_criteria = $save_criteria.$tcp_port[$i][0].$human_fields[($tcp_port[$i][1])].' '. - $tcp_port[$i][2].' '.$tcp_port[$i][3].$tcp_port[$i][4].' '.$tcp_port[$i][5]; - $have_criteria++; - } - } - - if ( $have_criteria > 0 ) - $save_criteria = $save_criteria. $cs->GetClearCriteriaString("tcp_port").'
    '; - - if ( isset($tcp_flags[$i][0]) && ($tcp_flags[$i][0] != " ") && ($tcp_flags[$i][0] != "") ) - { - $save_criteria = $save_criteria.'flags '.$tcp_flags[0].' '; - for ( $i = 8; $i >=1; $i-- ) - if ( $tcp_flags[$i] == "" ) - $save_criteria = $save_criteria.'-'; - else - $save_criteria = $save_criteria.$human_fields[($tcp_flags[$i])]; - $save_criteria = $save_criteria. - $cs->GetClearCriteriaString("tcp_flags").'
    '; - } - - $have_criteria = 0; - for ( $i = 0; $i < $tcp_field_cnt; $i++ ) - if ($tcp_field[$i][1] != " " && $tcp_field[$i][3] != "" ) - { - $save_criteria = $save_criteria.$tcp_field[$i][0].$human_fields[($tcp_field[$i][1])].' '. - $tcp_field[$i][2].' '.$tcp_field[$i][3].$tcp_field[$i][4].' '.$tcp_field[$i][5]; - $have_criteria = 1; - } - if ( $have_criteria ) - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("tcp_field"); + $save_criteria = $save_criteria.$cs->criteria['tcp_port']->Description(); + $save_criteria = $save_criteria.$cs->criteria['tcp_flags']->Description(); + $save_criteria = $save_criteria.$cs->criteria['tcp_field']->Description(); } else $save_criteria = $save_criteria.'    any '; @@ -634,43 +422,12 @@ $save_criteria = $save_criteria.'  
    UDP Criteria'; - - if ( $have_udp == 1 ) + if ( !$cs->criteria['udp_port']->isEmpty() || !$cs->criteria['udp_field']->isEmpty() ) { - - $have_criteria = 0; - for ( $i = 0; $i < $udp_port_cnt; $i++ ) - { - if ($udp_port[$i][1] != " " && $udp_port[$i][3] != "" ) - { - $save_criteria = $save_criteria.$udp_port[$i][0].$human_fields[($udp_port[$i][1])].' '. - $udp_port[$i][2].' '.$udp_port[$i][3].$udp_port[$i][4].' '.$udp_port[$i][5]; - $have_criteria = 1; - } - } - - if ($have_criteria) - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("udp_port").'
    '; - - $have_criteria = 0; - for ( $i = 0; $i < $udp_field_cnt; $i++ ) - { - if ($udp_field[$i][1] != " " && $udp_field[$i][3] != "" ) - { - $save_criteria = $save_criteria.$udp_field[$i][0].$human_fields[($udp_field[$i][1])].' '. - $udp_field[$i][2].' '.$udp_field[$i][3].$udp_field[$i][4].' '.$udp_field[$i][5]; - $have_criteria = 1; - } - } - - if ( $have_criteria ) - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("udp_field"); + $save_criteria = $save_criteria.$cs->criteria['udp_port']->Description(); + $save_criteria = $save_criteria.$cs->criteria['udp_field']->Description(); } else $save_criteria = $save_criteria.'    any '; @@ -678,36 +435,20 @@ $save_criteria = $save_criteria.'  
    ICMP Criteria'; - - if ( $have_icmp == 1 ) + if ( !$cs->criteria['icmp_field']->isEmpty() ) { - for ( $i = 0; $i < $icmp_field_cnt; $i++ ) - { - if ($icmp_field[$i][1] != " " && $icmp_field[$i][3] != "" ) - $save_criteria = $save_criteria.$icmp_field[$i][0].$human_fields[($icmp_field[$i][1])].' '. - $icmp_field[$i][2].' '.$icmp_field[$i][3].$icmp_field[$i][4].' '.$icmp_field[$i][5]; - } - - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("icmp_field"); + $save_criteria = $save_criteria.$cs->criteria['icmp_field']->Description(); } else $save_criteria = $save_criteria.'    any '; $save_criteria = $save_criteria.'  
    Layer 4 Criteria    none
    Payload Criteria '; - if ( $have_data == 1 ) - { - if ( $data_encode[0] != " " && $data_encode[1] != " ") - { - $save_criteria = $save_criteria.' (data encoded as '.$data_encode[0]; - $save_criteria = $save_criteria.' => '.$data_encode[1]; - $save_criteria = $save_criteria.')
    '; - } - else - $save_criteria = $save_criteria.' (no data conversion, assuming criteria in DB native encoding)
    '; - - for ( $i = 0; $i < $data_cnt; $i++ ) - { - if ($data[$i][1] != " " && $data[$i][2] != "" ) - $save_criteria = $save_criteria.$data[$i][0].$data[$i][1].' "'.$data[$i][2]. - '" '.$data[$i][3].' '.$data[$i][4]; - } - - $save_criteria = $save_criteria.$cs->GetClearCriteriaString("data"); - } + + if ( !$cs->criteria['data']->isEmpty() ) + $save_criteria = $save_criteria.$cs->criteria['data']->Description(); else $save_criteria = $save_criteria.'    any '; @@ -758,20 +482,13 @@ '
    '; - echo $save_criteria; } /********************************************************************************************/ function ProcessCriteria() { - GLOBAL $db, $time, $time_cnt, $sig, $sig_type, $sig_class, $sensor, $ag, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $save_criteria, + GLOBAL $db, $join_sql, $where_sql, $criteria_sql, $sql, $debug_mode, $caller, $DBtype; @@ -794,10 +511,43 @@ /* ********************** Meta Criteria ******************************************** */ + /* XXX-SEC */ + GLOBAL $cs; + + $sig = $cs->criteria['sig']->criteria; + $sig_type = $cs->criteria['sig']->sig_type; + $sig_class = $cs->criteria['sig_class']->criteria; + $sig_priority = $cs->criteria['sig_priority']->criteria; + $ag = $cs->criteria['ag']->criteria; + $sensor = $cs->criteria['sensor']->criteria; + $time = $cs->criteria['time']->criteria; + $time_cnt = $cs->criteria['time']->GetFormItemCnt(); + $ip_addr = $cs->criteria['ip_addr']->criteria; + $ip_addr_cnt = $cs->criteria['ip_addr']->GetFormItemCnt(); + $layer4 = $cs->criteria['layer4']->criteria; + $ip_field = $cs->criteria['ip_field']->criteria; + $ip_field_cnt = $cs->criteria['ip_field']->GetFormItemCnt(); + $tcp_port = $cs->criteria['tcp_port']->criteria; + $tcp_port_cnt = $cs->criteria['tcp_port']->GetFormItemCnt(); + $tcp_flags = $cs->criteria['tcp_flags']->criteria; + $tcp_field = $cs->criteria['tcp_field']->criteria; + $tcp_field_cnt = $cs->criteria['tcp_field']->GetFormItemCnt(); + $udp_port = $cs->criteria['udp_port']->criteria; + $udp_port_cnt = $cs->criteria['udp_port']->GetFormItemCnt(); + $udp_field = $cs->criteria['udp_field']->criteria; + $udp_field_cnt = $cs->criteria['udp_field']->GetFormItemCnt(); + $icmp_field = $cs->criteria['icmp_field']->criteria; + $icmp_field_cnt= $cs->criteria['icmp_field']->GetFormItemCnt(); + $data = $cs->criteria['data']->criteria; + $data_cnt = $cs->criteria['data']->GetFormItemCnt(); + $data_encode = $cs->criteria['data']->data_encode; + $tmp_meta = ""; /* Sensor */ if ( $sensor != "" && $sensor != " " ) - $tmp_meta = $tmp_meta." AND acid_event.sid=".$sensor; + $tmp_meta = $tmp_meta." AND acid_event.sid='".$sensor."'"; + else + $cs->criteria['sensor']->Set(""); /* Alert Group */ if ( $ag != "" && $ag != " " ) @@ -805,9 +555,11 @@ $tmp_meta = $tmp_meta." AND ag_id =".$ag; $join_sql = $join_sql.$ag_join_sql; } + else + $cs->criteria['ag']->Set(""); /* Signature */ - if ( $sig[0] != " " && $sig[0] != "" && $sig[1] != "" ) + if ( (isset($sig[0]) && $sig[0] != " " && $sig[0] != "") && (isset($sig[1]) && $sig[1] != "") ) { $sig_neg = ""; if ( $sig[2] == "!=" ) @@ -839,35 +591,44 @@ $tmp_meta = $tmp_meta." AND ".$sig_neg." (signature LIKE '%".$sig[1]."%') "; } } + else + $cs->criteria['sig']->Set(""); /* Signature Classification */ if ( $sig_class != " " && $sig_class != "" && $sig_class != "0") { - $tmp_meta = $tmp_meta." AND sig_class_id = ".$sig_class; + $tmp_meta = $tmp_meta." AND sig_class_id = '".$sig_class."'"; } else if ($sig_class == "0") { - $tmp_meta = $tmp_meta." AND (sig_class_id is null OR sig_class_id = 0)"; + $tmp_meta = $tmp_meta." AND (sig_class_id is null OR sig_class_id = '0')"; } + else + $cs->criteria['sig_class']->Set(""); - /* Date/Time */ - DateTimeRows2sql($time, $time_cnt, $tmp_meta); - - if ( $tmp_meta != "" ) + /* Signature Priority */ + if ( $sig_priority[1] != " " && $sig_priority[1] != "" && $sig_priority[1] != "0") + { + $tmp_meta = $tmp_meta." AND sig_priority ".$sig_priority[0]." '".$sig_priority[1]."'"; + } + else if ($sig_priority[1] == "0") { - $have_meta = 1; - $criteria_sql = $criteria_sql.$tmp_meta; + $tmp_meta = $tmp_meta." AND (sig_priority is null OR sig_priority = '0')"; } else - $have_meta = 0; + $cs->criteria['sig_priority']->Set(""); - /* ********************** IP Criteria ********************************************** */ + /* Date/Time */ + if ( DateTimeRows2sql($time, $time_cnt, $tmp_meta) == 0 ) + $cs->criteria['time']->SetFormItemCnt(0); - // $tmp_cnt = strlen($criteria_sql); + $criteria_sql = $criteria_sql.$tmp_meta; + + /* ********************** IP Criteria ********************************************** */ /* IP Addresses */ $tmp2 = ""; - + for ( $i = 0; $i < $ip_addr_cnt; $i++ ) { $tmp = ""; @@ -888,11 +649,11 @@ { if ( $ip_addr[$i][10] == "" ) { - $tmp = $tmp." acid_event.".$ip_addr[$i][1].$ip_addr[$i][2]. + $tmp = $tmp." acid_event.".$ip_addr[$i][1].$ip_addr[$i][2]."'". acidIP2Long($ip_addr[$i][3].".". $ip_addr[$i][4].".". $ip_addr[$i][5].".". - $ip_addr[$i][6])." "; + $ip_addr[$i][6])."' "; } else { @@ -905,10 +666,10 @@ else $tmp_op = ""; - $tmp = $tmp.$tmp_op." (acid_event.".$ip_addr[$i][1].">=". - acidIP2Long($mask[0])." AND ". - "acid_event.".$ip_addr[$i][1]."<=". - acidIP2Long($mask[1]).")"; + $tmp = $tmp.$tmp_op." (acid_event.".$ip_addr[$i][1].">= '". + acidIP2Long($mask[0])."' AND ". + "acid_event.".$ip_addr[$i][1]."<= '". + acidIP2Long($mask[1])."')"; } } } @@ -923,8 +684,9 @@ else $tmp = "(".$tmp_src.') AND ('.$tmp_dst.')'; } - - $tmp = $ip_addr[$i][0]."(".$tmp.")".$ip_addr[$i][8].$ip_addr[$i][9]; + + if ( $tmp != "" ) + $tmp = $ip_addr[$i][0]."(".$tmp.")".$ip_addr[$i][8].$ip_addr[$i][9]; } else if ( (isset($ip_addr[$i][3]) && $ip_addr[$i][3] != "" ) || $ip_addr[$i][1] != " " ) { @@ -959,42 +721,38 @@ if ( $tmp2 != "" ) $criteria_sql = $criteria_sql." AND ( ".$tmp2." )"; - - $tmp_cnt = strlen($criteria_sql); + else + $cs->criteria['ip_addr']->SetFormItemCnt(0); /* IP Fields */ - FieldRows2sql($ip_field, $ip_field_cnt, $criteria_sql); - - if ( $tmp_cnt != strlen($criteria_sql) ) - $have_ip = 1; - else - $have_ip = 0; + if ( FieldRows2sql($ip_field, $ip_field_cnt, $criteria_sql) == 0 ) + $cs->criteria['ip_field']->SetFormItemCnt(0); /* Layer-4 encapsulation */ - /* if ( $caller != "" $caller == "" || - $caller == "last_tcp" || $caller == "last_udp" || $caller == "last_icmp" ) */ - if ( $layer4 == "TCP" ) - $criteria_sql = $criteria_sql." AND acid_event.ip_proto= 6"; - else if ( $layer4 == "UDP" ) - $criteria_sql = $criteria_sql." AND acid_event.ip_proto= 17"; - else if ( $layer4 == "ICMP" ) - $criteria_sql = $criteria_sql." AND acid_event.ip_proto= 1"; + if ( $layer4 == "TCP" ) + $criteria_sql = $criteria_sql." AND acid_event.ip_proto= '6'"; + else if ( $layer4 == "UDP" ) + $criteria_sql = $criteria_sql." AND acid_event.ip_proto= '17'"; + else if ( $layer4 == "ICMP" ) + $criteria_sql = $criteria_sql." AND acid_event.ip_proto= '1'"; + else + $cs->criteria['layer4']->Set(""); - /* Build the final IP criteria */ - if ( $have_ip == 1 ) + /* Join the iphdr table if necessary */ + if ( !$cs->criteria['ip_field']->isEmpty() ) $join_sql = $ip_join_sql.$join_sql; /* ********************** TCP Criteria ********************************************** */ if ( $layer4 == "TCP" ) { - $have_tcp = 0; $proto_tmp = ""; /* TCP Ports */ - FieldRows2sql($tcp_port, $tcp_port_cnt, $proto_tmp); - if ( $proto_tmp != "" ) $have_tcp = 1; + if ( FieldRows2sql($tcp_port, $tcp_port_cnt, $proto_tmp) == 0 ) + $cs->criteria['tcp_port']->SetFormItemCnt(0); + $criteria_sql = $criteria_sql.$proto_tmp; + $proto_tmp = ""; - /* TCP Flags */ if ( isset($tcp_flags) ) { @@ -1012,17 +770,18 @@ } /* TCP Fields */ - FieldRows2sql($tcp_field, $tcp_field_cnt, $proto_tmp); + if ( FieldRows2sql($tcp_field, $tcp_field_cnt, $proto_tmp) == 0 ) + $cs->criteria['tcp_field']->SetFormItemCnt(0); /* TCP Options * - not implemented */ - if ( $proto_tmp != "" ) + if ( !$cs->criteria['tcp_port']->isEmpty() || !$cs->criteria['tcp_flags']->isEmpty() || !$cs->criteria['tcp_field']->isEmpty() ) { - $have_tcp = 1; $criteria_sql = $criteria_sql.$proto_tmp; - $join_sql = $tcp_join_sql.$join_sql; + if ( !$cs->criteria['tcp_flags']->isEmpty() || !$cs->criteria['tcp_field']->isEmpty() ) + $join_sql = $tcp_join_sql.$join_sql; } } @@ -1030,22 +789,23 @@ if ( $layer4 == "UDP" ) { $proto_tmp = ""; - $have_udp = 0; /* UDP Ports */ - FieldRows2sql($udp_port, $udp_port_cnt, $proto_tmp); - if ( $proto_tmp != "" ) $have_udp = 1; + if ( FieldRows2sql($udp_port, $udp_port_cnt, $proto_tmp) == 0 ) + $cs->criteria['udp_port']->SetFormItemCnt(0); + $criteria_sql = $criteria_sql.$proto_tmp; $proto_tmp = ""; /* UDP Fields */ - FieldRows2sql($udp_field, $udp_field_cnt, $proto_tmp); + if ( FieldRows2sql($udp_field, $udp_field_cnt, $proto_tmp) == 0 ) + $cs->criteria['udp_field']->SetFormItemCnt(0); - if ( $proto_tmp != "" ) + if ( !$cs->criteria['udp_port']->isEmpty() || !$cs->criteria['udp_field']->isEmpty() ) { - $have_udp = 1; $criteria_sql = $criteria_sql.$proto_tmp; - $join_sql = $udp_join_sql.$join_sql; + if ( !$cs->criteria['udp_field']->isEmpty() ) + $join_sql = $udp_join_sql.$join_sql; } } @@ -1053,33 +813,30 @@ if ( $layer4 == "ICMP" ) { $proto_tmp = ""; + /* ICMP Fields */ - FieldRows2sql($icmp_field, $icmp_field_cnt, $proto_tmp); + if ( FieldRows2sql($icmp_field, $icmp_field_cnt, $proto_tmp) == 0 ) + $cs->criteria['icmp_field']->SetFormItemCnt(0); - if ( $proto_tmp != "" ) + if ( !$cs->criteria['icmp_field']->isEmpty() ) { - $have_icmp = 1; $criteria_sql = $criteria_sql.$proto_tmp; $join_sql = $icmp_join_sql.$join_sql; } - else - $have_icmp = 0; } /* ********************** Payload Criteria ***************************************** */ $tmp_payload = ""; - DataRows2sql($data, $data_cnt, $data_encode, $tmp_payload); + if ( DataRows2sql($data, $data_cnt, $data_encode, $tmp_payload) == 0 ) + $cs->criteria['data']->SetFormItemCnt(0); - if ( $tmp_payload != "" ) + if ( !$cs->criteria['data']->isEmpty() ) { - $have_data = 1; $criteria_sql = $criteria_sql.$tmp_payload; $join_sql = $data_join_sql.$join_sql; } - else - $have_data = 0; - + $csql[0] = $join_sql; $csql[1] = $criteria_sql; diff -Naur acid/acid_qry_form.php acidfp/acid_qry_form.php --- acid/acid_qry_form.php 2002-03-03 18:02:44.000000000 -0500 +++ acidfp/acid_qry_form.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,40 +4,40 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: renders the HTML form to gather search criteria * */ -if ( $submit == "TCP" ) { $layer4 = "TCP"; } -if ( $submit == "UDP" ) { $layer4 = "UDP"; } -if ( $submit == "ICMP" ) { $layer4 = "ICMP"; } -if ( $submit == "no layer4" ) { $layer4 = ""; } - -if ( $submit == "ADD Time" && $time_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $time_cnt, $time, TIME_CFCNT); -if ( $submit == "ADD Addr" && $ip_addr_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $ip_addr_cnt, $ip_addr, IPADDR_CFCNT); -if ( $submit == "ADD IP Field" && $ip_field_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $ip_field_cnt, $ip_field, PROTO_CFCNT); +if ( $submit == "TCP" ) { $cs->criteria['layer4']->Set("TCP"); } +if ( $submit == "UDP" ) { $cs->criteria['layer4']->Set("UDP"); } +if ( $submit == "ICMP" ) { $cs->criteria['layer4']->Set("ICMP"); } +if ( $submit == "no layer4" ) { $cs->criteria['layer4']->Set(""); } + +if ( $submit == "ADD Time" && $cs->criteria['time']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['time']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD Addr" && $cs->criteria['ip_addr']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['ip_addr']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD IP Field" && $cs->criteria['ip_field']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['ip_field']->AddFormItem($submit, $cs->criteria['layer4']->Get()); /*if ( $submit == "ADD IP Option Field" && $ip_opt_cnt < $MAX_ROWS) { $submit = $layer4; $ip_opt_cnt++; }*/ -if ( $submit == "ADD TCP Port" && $tcp_port_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $tcp_port_cnt, $tcp_port, TCPPORT_CFCNT); -if ( $submit == "ADD TCP Field" && $tcp_field_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $tcp_field_cnt, $tcp_field, PROTO_CFCNT); +if ( $submit == "ADD TCP Port" && $cs->criteria['tcp_port']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['tcp_port']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD TCP Field" && $cs->criteria['tcp_field']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['tcp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get()); /*if ( $submit == "ADD TCP Option Field" && $tcp_opt_cnt < $MAX_ROWS) { $submit = $layer4; $tcp_opt_cnt++; } */ -if ( $submit == "ADD UDP Port" && $udp_port_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $udp_port_cnt, $udp_port, PROTO_CFCNT); -if ( $submit == "ADD UDP Field" && $udp_field_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $udp_field_cnt, $udp_field, PROTO_CFCNT); -if ( $submit == "ADD ICMP Field" && $icmp_field_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $icmp_field_cnt, $icmp_field, PROTO_CFCNT); -if ( $submit == "ADD Payload" && $data_cnt < $MAX_ROWS) - AddCriteriaFormRow($submit, $layer4, $data_cnt, $data, PAYLOAD_CFCNT); +if ( $submit == "ADD UDP Port" && $cs->criteria['udp_port']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['udp_port']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD UDP Field" && $cs->criteria['udp_field']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['udp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD ICMP Field" && $cs->criteria['icmp_field']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['icmp_field']->AddFormItem($submit, $cs->criteria['layer4']->Get()); +if ( $submit == "ADD Payload" && $cs->criteria['data']->GetFormItemCnt() < $MAX_ROWS) + $cs->criteria['data']->AddFormItem($submit, $cs->criteria['layer4']->Get()); echo ' @@ -50,93 +50,25 @@ '; + Sensor: '; + $cs->criteria['sensor']->PrintForm(); + + echo 'Alert Group: '; + $cs->criteria['ag']->PrintForm(); + echo ''; echo ''; @@ -144,55 +76,8 @@ echo '
    - Sensor: -    - Alert Group: -   
    Signature: '; - echo ''; - - echo ' -
    Alert Time: '; - - for ( $i = 0; $i < $time_cnt; $i++ ) - { - echo ''; - echo ''; - - echo ''; - echo ''; - echo ''; - - echo ':'; - echo ':'; - echo ''; - - echo ''; - echo ''; - - - if ( $i == $time_cnt-1 ) - echo ' '; - echo '
    '; - } + $cs->criteria['time']->PrintForm(); + echo '
    '; @@ -208,73 +93,13 @@ '; echo '
    Address:'; echo ' '; - for ( $i = 0; $i < $ip_addr_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' .'; - echo ' .'; - echo ' .'; - echo ' '; - } - echo ' '; - echo ' '; - if ( $i == $ip_addr_cnt-1 ) - echo ' '; - echo '
    '; - } + + $cs->criteria['ip_addr']->PrintForm(); echo '
    Misc:'; echo ' '; - for ( $i = 0; $i < $ip_field_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $ip_field_cnt-1 ) - echo ' '; - echo '
    '; - } + + $cs->criteria['ip_field']->PrintForm(); /* echo '
    Option:'; echo ' '; @@ -306,30 +131,13 @@ echo '
    Layer-4: '; - if ( $layer4 != "" ) - echo '  '; - if ( $layer4 == "TCP" ) - echo ' -   - '; - else if ( $layer4 == "UDP" ) - echo ' -   - '; - else if ( $layer4 == "ICMP" ) - echo ' -   - '; - else - echo ' -   - - '; + + $cs->criteria['layer4']->PrintForm(); echo '
    '; -if ( $layer4 == "TCP" ) +if ( $cs->criteria['layer4']->Get() == "TCP" ) { echo ' @@ -344,79 +152,16 @@ echo '
    Port:'; echo ' '; - for ( $i = 0; $i < $tcp_port_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $tcp_port_cnt-1 ) - echo ' '; - echo '
    '; - } + $cs->criteria['tcp_port']->PrintForm(); echo '
    Flags:'; - echo ''; - echo ' '; - echo ' [RSV1]  '; - echo ' [RSV0]  '; - echo ' [URG]  '; - echo ' [ACK]  '; - echo ' [PSH]  '; - echo ' [RST]  '; - echo ' [SYN]  '; - echo ' [FIN]  '; - echo ' '; + $cs->criteria['tcp_flags']->PrintForm(); echo '
    Misc:'; echo ' '; - for ( $i = 0; $i < $tcp_field_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $tcp_field_cnt-1 ) - echo ' '; - echo '
    '; - } + $cs->criteria['tcp_field']->PrintForm(); /* echo '
    Option:'; echo ' '; @@ -449,7 +194,7 @@
    '; } -if ( $layer4 == "UDP" ) +if ( $cs->criteria['layer4']->Get() == "UDP" ) { echo ' @@ -464,64 +209,17 @@ echo 'Port:'; echo ' '; - for ( $i = 0; $i < $udp_port_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $udp_port_cnt-1 ) - echo ' '; - echo '
    '; - } + $cs->criteria['udp_port']->PrintForm(); echo 'Misc:'; echo ' '; - for ( $i = 0; $i < $udp_field_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $udp_field_cnt-1 ) - echo ' '; - echo '
    '; - } - + $cs->criteria['udp_field']->PrintForm(); echo' '; } -if ( $layer4 == "ICMP" ) +if ( $cs->criteria['layer4']->Get() == "ICMP" ) { echo ' @@ -537,35 +235,7 @@ echo 'Misc:'; echo ' '; - for ( $i = 0; $i < $icmp_field_cnt; $i++ ) - { - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - echo ' '; - if ( $i == $icmp_field_cnt-1 ) - echo ' '; - echo '
    '; - } + $cs->criteria['icmp_field']->PrintForm(); echo ' '; } @@ -581,37 +251,9 @@ -
    Input Criteria Encoding Type:'; - echo ''; - echo 'Convert To (when searching):'; - echo ''; - echo '
    '; - - for ( $i = 0; $i < $data_cnt; $i++ ) - { - echo ''; - echo ''; - - echo ''; - - echo ''; - echo ''; +
    '; + $cs->criteria['data']->PrintForm(); - if ( $i == $data_cnt-1 ) - echo ' '; - echo '
    '; - } echo '
    '; diff -Naur acid/acid_qry_main.php acidfp/acid_qry_main.php --- acid/acid_qry_main.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_qry_main.php 2003-12-17 14:17:10.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: @@ -50,109 +50,6 @@ * * $sort_order: how to sort the output * - * Meta - * ==== - * - * $ag: AG ID - * - * $sensor: sensor ID - * - * $sig[3]: stores signature - * - [0] : exactly, roughly [1] : signature - * - [2] : =, != - * - * $sig_class: signature classification - * - * $time[MAX][10]: stores the date/time of the packet detection - * - [][0] : ( [][5] : hour - * - [][1] : =, !=, <, <=, >, >= [][6] : minute - * - [][2] : month [][7] : second - * - [][3] : day [][8] : (, ) - * - [][4] : year [][9] : AND, OR - * - * $time_cnt : number of rows in the $time[][] structure - * - * IP Variables - * ============ - * - * $ip_addr[MAX][10]: stores an ip address parameters/operators row - * - [][0] : ( [][5] : octet3 of address - * - [][1] : source, dest [][6] : octet4 of address - * - [][2] : =, != [][7] : network mask - * - [][3] : octet1 of address [][8] : (, ) - * - [][4] : octet2 of address [][9] : AND, OR - * - * $ip_addr_cnt: number of rows in the $ip_addr[][] structure - * - * $ip_field[MAX][6]: stores all other ip fields parameters/operators row - * - [][0] : ( [][3] : field value - * - [][1] : TOS, TTL, ID, offset, length [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $ip_field_cnt: number of rows in the $ip_field[][] structure - * - * TCP Variables - * ============= - * - * $tcp_port[MAX][6]: stores all port parameters/operators row - * - [][0] : ( [][3] : port value - * - [][1] : Source Port, Dest Port [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $tcp_port_cnt: number of rows in the $tcp_port[][] structure - * - * $tcp_flags[7]: stores all other tcp flags parameters/operators row - * - [0] : is, contains [4] : 8 (RST) - * - [1] : 1 (FIN) [5] : 16 (ACK) - * - [2] : 2 (SYN) [6] : 32 (URG) - * - [3] : 4 (PUSH) - * - * $tcp_field[MAX][6]: stores all other tcp fields parameters/operators row - * - [][0] : ( [][3] : field value - * - [][1] : windows, URP [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $tcp_field_cnt: number of rows in the $tcp_field[][] structure - * - * UDP Variables - * ============= - * - * $udp_port[MAX][6]: stores all port parameters/operators row - * - [][0] : ( [][3] : port value - * - [][1] : Source Port, Dest Port [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $udp_port_cnt: number of rows in the $udp_port[][] structure - * - * $udp_field[MAX][6]: stores all other udp fields parameters/operators row - * - [][0] : ( [][3] : field value - * - [][1] : length [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $udp_field_cnt: number of rows in the $udp_field[][] structure - * - * ICMP Variables - * ============== - * $icmp_field[MAX][6]: stores all other icmp fields parameters/operators row - * - [][0] : ( [][3] : field value - * - [][1] : code, length [][4] : (, ) - * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR - * - * $icmp_field_cnt: number of rows in the $icmp_field[][] structure - * - * Payload Variables - * ================= - * $data_encode[2]: how the payload should be interpreted and converted - * - [0] : encoding type (hex, ascii) - * - [1] : conversion type (hex, ascii) - * - * $data[MAX][5]: stores all the payload related parameters/operators row - * - [][0] : ( [][3] : (, ) - * - [][1] : =, != [][4] : AND, OR - * - [][2] : field value - * - * $data_cnt: number of rows in the $data[][] structure - * * ----- Search Result Variables ---- * $action_chk_lst[]: array of check boxes to determine if an alert * was selected for action @@ -173,18 +70,16 @@ $et = new EventTiming($debug_time_mode); $cs = new CriteriaState("acid_qry_main.php", "&new=1&submit=Query+DB"); - $new = ImportHTTPVar("new"); + $new = ImportHTTPVar("new", VAR_DIGIT); $submit = ImportHTTPVar("submit"); - $layer4 = ImportHTTPVar("layer4"); -/* Code to correct 'interesting' (read: unexplained) browser behavior - */ +/* Code to correct 'interesting' (read: unexplained) browser behavior */ /* Something with Netscape 4.75 such that the $submit variable is no recognized * under certain circumstances. This one is a result of using HTTPS and * clicking on TCP traffic profile from acid_main.php */ -if ( $layer4 != "" && $submit == "" ) +if ( $cs->criteria['layer4']->Get() != "" && $submit == "" ) $submit = "Query DB"; /* End 'interesting' browser code fixes */ @@ -192,42 +87,10 @@ /* Totally new Search */ if ( ($new == 1) && ($submit == "") ) { - /* Read the state to import the history */ - $cs->ReadState(); - - /* - * Save the variables associated with keeping history, - * or they will be deleted in the InitState() call - */ - $save_back_list = $GLOBALS['back_list']; - $save_back_list_cnt = $GLOBALS['back_list_cnt']; - $cs->InitState(); - - /* Restore the history variables */ - $back_list = $save_back_list; - $back_list_cnt = $save_back_list_cnt; - - $time_cnt = 1; - $ip_addr_cnt = 1; - $ip_field_cnt = 1; - $tcp_port_cnt = 1; - $tcp_field_cnt = 1; - $udp_port_cnt = 1; - $udp_field_cnt = 1; - $icmp_field_cnt = 1; - $data_cnt = 1; - $layer4 = ""; } - /* if scrolling between pages read the session */ - /* if access the first query result page from the criteria specification - * then read the session and migrate the POST variables into the session - */ - else - { - $cs->ReadState(); - } + $cs->ReadState(); $qs = new QueryState(); $qs->AddCannedQuery("last_tcp", $last_num_alerts, "Last TCP", "time_d"); @@ -277,7 +140,7 @@ if ( $submit == "Query DB" || $submit == "Selected" || $submit == "ALL on Screen" || $submit == "Entire Query" || $qs->isCannedQuery() || - $sort_order != "" ) + $qs->GetCurrentSort() != "" ) { /* Init and run the action */ $criteria_clauses = ProcessCriteria(); @@ -287,6 +150,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); @@ -298,13 +162,14 @@ $qs->AddValidActionOp("ALL on Screen"); $qs->AddValidActionOp("Entire Query"); - $qs->SetActionSQL("SELECT acid_event.sid, acid_event.cid $from $where"); + $qs->SetActionSQL("SELECT acid_event.sid, acid_event.cid $from $where"); $et->Mark("Initialization"); $qs->RunAction($submit, PAGE_QRY_ALERTS, $db); $et->Mark("Alert Action"); if ( $debug_mode > 0 ) ErrorMessage("Initial/Canned Query or Sort Clicked"); + include("acid_qry_sqlcalls.php"); } /* Return the input form to get more criteria from user */ @@ -313,32 +178,6 @@ include("acid_qry_form.php"); } -/* Stores the neccessary variables for shared state between calls */ - -/* These variables will ultimately be stored in the session, but are - * temporarily required while criteria is being entered in the form - */ -//if ( ($HTTP_POST_VARS["new"] == 1) || ($HTTP_GET_VARS["new"] == 1) ) -if ( $new == 1 ) -{ - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} - -echo ' - - - - - - '; // $db->acidClose(); $qs->SaveState(); @@ -348,7 +187,6 @@ echo "\n\n"; PrintACIDSubFooter(); - ?> diff -Naur acid/acid_qry_sqlcalls.php acidfp/acid_qry_sqlcalls.php --- acid/acid_qry_sqlcalls.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_qry_sqlcalls.php 2003-12-17 14:16:39.000000000 -0500 @@ -17,10 +17,9 @@ * - imported variables: $sql, $cnt_sql */ - ProcessCriteria(); - if ( $printing_ag ) { + ProcessCriteria(); $page = "acid_ag_main.php"; $tmp_page_get = "&ag_action=view&ag_id=$ag_id&submit=x"; $sql = $save_sql; @@ -65,8 +64,8 @@ "dip_a", " ", " ORDER BY ip_dst ASC", "dip_d", " ", " ORDER BY ip_dst DESC"); $qro->AddTitle("Layer 4
    Proto", - "proto_a", " ", " ORDER BY layer4_proto ASC", - "proto_d", " ", " ORDER BY layer4_proto DESC"); + "proto_a", " ", " ORDER BY ip_proto ASC", + "proto_d", " ", " ORDER BY ip_proto DESC"); if ( !$printing_ag) $sql = $sql.$join_sql.$where_sql.$criteria_sql; @@ -152,7 +151,7 @@ '&sort_order='.$qs->getCurrentSort().'">'. $tmp_rowid. ''); - qroPrintEntry($current_sig); + qroPrintEntry($current_sig, "left"); qroPrintEntry($myrow[3]); $tmp_iplookup = 'acid_qry_main.php?sig%5B0%5D=%3D'. @@ -161,12 +160,9 @@ '&submit=Query+DB¤t_view=-1&ip_addr_cnt=2'; /* TCP or UDP show the associated port # */ - if ( $current_proto == TCP ) - $result4 = $db->acidExecute("SELECT tcp_sport, tcp_dport FROM tcphdr ". - "WHERE sid=".$myrow[0]." AND cid=".$myrow[1]); - else if ( $current_proto == UDP ) - $result4 = $db->acidExecute("SELECT udp_sport, udp_dport FROM udphdr ". - "WHERE sid=".$myrow[0]." AND cid=".$myrow[1]); + if ( ($current_proto == TCP) || ($current_proto == UDP) ) + $result4 = $db->acidExecute("SELECT layer4_sport, layer4_dport FROM acid_event ". + "WHERE sid='".$myrow[0]."' AND cid='".$myrow[1]."'"); if ( ($current_proto == TCP) || ($current_proto == UDP) ) { diff -Naur acid/acid_show_packet.php acidfp/acid_show_packet.php --- acid/acid_show_packet.php 1969-12-31 19:00:00.000000000 -0500 +++ acidfp/acid_show_packet.php 2003-12-17 14:17:10.000000000 -0500 @@ -0,0 +1,630 @@ +, + * + * Copyright (C) 2001,2002 Carnegie Mellon University + * (see the file 'acid_main.php' for license details) + * + * Purpose: displays a single alert + * + * Input GET/POST variables + * - caller + * - submit: + * + */ + + include ("acid_constants.inc"); + include ("acid_conf.php"); + include ("acid_include.inc"); + include_once ("acid_db_common.php"); + include_once ("acid_qry_common.php"); + include_once ("acid_stat_common.php"); + +function PrintPacketLookupBrowseButtons($seq, $save_sql, $db, &$previous_button, &$next_button) +{ + echo "\n\n\n"; + + $result2 = $db->acidExecute($save_sql); + + if ( $seq == 0 ) + $previous_button = '[ First ]'."\n"; + + $i = 0; + while ($i <= $seq+1 ) + { + $myrow2 = $result2->acidFetchRow(); + + if ( $myrow2 == "" ) + $next_button = '[ Last ]'."\n"; + else if ( $i == $seq-1 ) + $previous_button = ''."\n"; + + else if ( $i == $seq+1 ) + $next_button = ''."\n"; + $i++; + } + + $result2->acidFreeRows(); +} + + /* + * Need to import $submit and set the $QUERY_STRING early to support + * the back button. Otherwise, the value of $submit will not be passed + * to the history. + */ + $submit = ImportHTTPVar("submit"); + $HTTP_SERVER_VARS["QUERY_STRING"] = "submit=".rawurlencode($submit); + + $et = new EventTiming($debug_time_mode); + $cs = new CriteriaState("acid_qry_alert.php"); + $cs->ReadState(); + + $qs = new QueryState(); + + $page_title = "Network Fingerprint Packet Detail"; + PrintACIDSubHeader($page_title, $page_title, $cs->GetBackLink()); + + /* Connect to the Alert database */ + $db = NewACIDDBConnection($DBlib_path, $DBtype); + $db->acidDBConnect($db_connect_method, + $alert_dbname, $alert_host, $alert_port, $alert_user, $alert_password); +/* + PrintCriteria(""); +*/ + $criteria_clauses = ProcessCriteria(); + + + $from = " FROM acid_event ".$criteria_clauses[0]; + $where = " WHERE ".$criteria_clauses[1]; + + $qs->AddValidAction("ag_by_id"); + $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); + $qs->AddValidAction("del_alert"); + $qs->AddValidAction("email_alert"); + $qs->AddValidAction("email_alert2"); + $qs->AddValidAction("archive_alert"); + $qs->AddValidAction("archive_alert2"); + + $qs->AddValidActionOp("Selected"); + + $qs->SetActionSQL($from.$where); + + $et->Mark("Initialization"); + + $qs->RunAction($submit, PAGE_ALERT_DISPLAY, $db); + $et->Mark("Alert Action"); + + /* If get a valid (sid,cid) store it in $caller. + * But if $submit is returning from an alert action + * get the (sid,cid) back from $caller + */ + if ( $submit == "Selected" ) + $submit = ImportHTTPVar("caller"); + else + $caller = $submit; + + /* Setup the Query Results Table -- However, this data structure is not + * really used for output. Rather, it duplicates the sort SQL set in + * acid_qry_sqlcalls.php + */ + $qro = new QueryResultsOutput(""); + + $qro->AddTitle("Signature", + "sig_a", " ", " ORDER BY sig_name ASC", + "sig_d", " ", " ORDER BY sig_name DESC"); + $qro->AddTitle("Timestamp", + "time_a", " ", " ORDER BY timestamp ASC ", + "time_d", " ", " ORDER BY timestamp DESC "); + $qro->AddTitle("Source
    Address", + "sip_a", " ", " ORDER BY ip_src ASC", + "sip_d", " ", " ORDER BY ip_src DESC"); + $qro->AddTitle("Dest.
    Address", + "dip_a", " ", " ORDER BY ip_dst ASC", + "dip_d", " ", " ORDER BY ip_dst DESC"); + $qro->AddTitle("Layer 4
    Proto", + "proto_a", " ", " ORDER BY layer4_proto ASC", + "proto_d", " ", " ORDER BY layer4_proto DESC"); + + $sort_sql = $qro->GetSortSQL($qs->GetCurrentSort(), ""); + $save_sql = "SELECT acid_event.sid, acid_event.cid".$sort_sql[0]. + $from.$where.$sort_sql[1]; + + if ( $event_cache_auto_update == 1 ) UpdateAlertCache($db); + + /* GetQueryResultID($submit, $seq, $sid, $cid); */ + $sid = ImportHTTPVar("sid"); + $cid = ImportHTTPVar("cid"); + + if ( $debug_mode > 0 ) + echo "\n====== Alert Lookup =======
    + sid = $sid
    + cid = $cid
    + seq = $seq
    \n". + "===========================
    \n"; + + /* Verify that have extracted (sid, cid) correctly */ + if ( !($sid > 0 && $cid > 0) ) + { + ErrorMessage("Invalid (sid,cid) pair (".$sid.",".$cid.")"); + exit(); + } + +/* + echo "

    \n"; + PrintPacketLookupBrowseButtons($seq, $save_sql, $db, $previous, $next); + echo "
    \nAlert #".($seq+1)."
    \n$previous    \n$next\n
    \n"; + echo "
    \n"; +*/ + + /* Make Selected */ + echo "\n\n"; + + /* Event */ + $sql2 = "SELECT signature, lastseen FROM fpevent WHERE sid='".$sid."' AND cid='".$cid."'"; + $result2 = $db->acidExecute($sql2); + $myrow2 = $result2->acidFetchRow(); + + if ( $myrow2[0] == "" ) + { + echo '
    '; + ErrorMessage("Alert DELETED"); + echo '
    '; + } + + echo ' + + + '; + + $sql4 = "SELECT hostname, interface, filter FROM sensor WHERE sid='".$sid."'"; + $result4 = $db->acidExecute($sql4); + $myrow4 = $result4->acidFetchRow(); + + echo ' + '; + $result4->acidFreeRows(); + + $sql4 = "SELECT acid_ag_alert.ag_id, ag_name, ag_desc ". + "FROM acid_ag_alert LEFT JOIN acid_ag ON acid_ag_alert.ag_id = acid_ag.ag_id ". + "WHERE ag_sid='".$sid."' AND ag_cid='".$cid."'"; + $result4 = $db->acidExecute($sql4); + $num = $result4->acidRecordCount(); + + echo ' + +
    Meta + + + + + + + + +
    ID #TimeTriggered Signature
    '.($sid." - ".$cid).''.$myrow2[1].''.BuildSigByID($myrow2[0], $db).'
    +
    + + + + + + + + + + +
    Sensornameinterfacefilter
    '.$myrow4[0].''.$myrow4[1].''. + ( ($myrow4[2] == "") ? " none " : $myrow4[2] ).'
    +
    + + '; + + if ( $num > 0 ) + echo ' + + '; + else + echo ' '; + + for ($i = 0; $i < $num; $i++) + { + $myrow4 = $result4->acidFetchRow(); + + echo ' + + + '; + } + echo '
    Alert
    Group
    ID #NameDescription
      none 
    '.$myrow4[0].''.$myrow4[1].''.$myrow4[2].'
    '; + $result4->acidFreeRows(); + + echo '
    '; + $result2->acidFreeRows(); + + /* IP */ + $sql2 = "SELECT ip_src, ip_dst, ". + "ip_ver, ip_hlen, ip_tos, ip_len, ip_id, ip_flags, ip_off, ip_ttl, ip_csum, ip_proto". + " FROM iphdr WHERE sid='".$sid."' AND cid='".$cid."'"; + + $result2 = $db->acidExecute($sql2); + $myrow2 = $result2->acidFetchRow(); + + $layer4_proto = -1; + if ( $myrow2[0] != "" ) + { + $sql3 = "SELECT * FROM opt WHERE sid='".$sid."' AND cid='".$cid."' AND opt_proto='0'"; + $result3 = $db->acidExecute($sql3); + $num_opt = $result3->acidRecordCount(); + + echo ' + + + '; + } + + echo ' '; + echo ' '; + + + echo '
    IP'; + echo ' '; + echo ' '; + echo ' + + + + + + + + + + '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '
    source addr  dest addr  VerHdr LenTOSlengthIDflagsoffsetTTLchksum
    + '. + acidLong2IP($myrow2[0]).' + '. + acidLong2IP($myrow2[1]).''.$myrow2[2].''.$myrow2[3].''.$myrow2[4].''.$myrow2[5].''.$myrow2[6].''.$myrow2[7].''.$myrow2[8].''.$myrow2[9].''.$myrow2[10].'
    '; + + if ( $resolve_IP == 1 ) + { + echo '
    + + + + + + + + +
    FQDNSource NameDest. Name
    '. + (acidGetHostByAddr(acidLong2IP($myrow2[0]), + $db, $dns_cache_lifetime)).''. + (acidGetHostByAddr(acidLong2IP($myrow2[1]), + $db, $dns_cache_lifetime)).'
    +
    '; + echo ' '; + echo ' '; + + $layer4_proto = $myrow2[11]; + + if ( $num_opt > 0 ) + { + echo ' + + + '; + + for ( $i = 0; $i < $num_opt; $i++) + { + $myrow3 = $result3->acidFetchRow(); + echo ' '; + echo ' '; + echo ' '; + echo ' '; + } + } + else + { + echo ' '; + } + echo '
    Optionscodelengthdata
    #'.($i+1).''.IPOption2str($myrow3[4]).''.$myrow3[5].''.$myrow3[6].'
        none
    '; + $result3->acidFreeRows(); + } + $result2->acidFreeRows(); + + /* TCP */ + if ( $layer4_proto == "6" ) + { + $sql2 = "SELECT tcp_sport, tcp_dport, tcp_seq, tcp_ack, tcp_off, tcp_res, tcp_flags, tcp_win, ". + " tcp_csum, tcp_urp FROM tcphdr WHERE sid='".$sid."' AND cid='".$cid."'"; + $result2 = $db->acidExecute($sql2); + $myrow2 = $result2->acidFetchRow(); + + $sql3 = "SELECT * FROM opt WHERE sid='".$sid."' AND cid='".$cid."' AND opt_proto='6'"; + $result3 = $db->acidExecute($sql3); + $num_opt = $result3->acidRecordCount(); + + echo ' + + '; + echo ' '; + echo ' '; + + echo '
    TCP'; + echo ' '; + echo ' '; + echo ' + + + + + + + + + + + + + + + + '; + $src_port = $external_port_link.$myrow2[0]; + $dst_port = $external_port_link.$myrow2[1]; + echo ' '; + echo ' '; + echo ' '; + + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '
    source
    port
    dest
      port  
    R
    1
    R
    0
    U
    R
    G
    A
    C
    K
    P
    S
    H
    R
    S
    T
    S
    Y
    N
    F
    I
    N
    seq #ackoffsetreswindowurpchksum
    '.$myrow2[0].''.$myrow2[1].''; + if ( ($myrow2[6] & 128) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 64 ) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 32) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 16 ) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 8) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 4 ) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 2 ) != 0 ) + echo 'X'; + echo ' '; + if ( ($myrow2[6] & 1 ) != 0 ) + echo 'X'; + echo ' '.$myrow2[2].''.$myrow2[3].''.$myrow2[4].''.$myrow2[5].''.$myrow2[7].''.$myrow2[9].''.$myrow2[8].'
    '; + echo ' '; + echo ' '; + + if ( $num_opt != 0) + { + echo ' + + + '; + + for ( $i = 0; $i < $num_opt; $i++) + { + $myrow3 = $result3->acidFetchRow(); + echo ' '; + echo ' '; + echo ' '; + echo ' '; + } + } + else + { + echo ' '; + } + echo '
    Optionscodelengthdata
    #'.($i+1).''.TCPOption2str($myrow3[4]).''.$myrow3[5].''.$myrow3[6].'
        none
    '; + + $result2->acidFreeRows(); + $result3->acidFreeRows(); + } + + /* UDP */ + if ( $layer4_proto == "17" ) + { + + $sql2 = "SELECT * FROM udphdr WHERE sid='".$sid."' AND cid='".$cid."'"; + $result2 = $db->acidExecute($sql2); + $myrow2 = $result2->acidFetchRow(); + + echo ' + + '; + echo ' '; + echo '
    UDP'; + echo ' '; + echo ' + + '; + + $src_port = $external_port_link.$myrow2[2]; + $dst_port = $external_port_link.$myrow2[3]; + + echo ' '; + echo ' '; + echo ' '; + echo '
    source portdest portlength
    '.$myrow2[2].''.$myrow2[3].''.$myrow2[4].'
    '; + + $result2->acidFreeRows(); + } + + /* ICMP */ + if ( $layer4_proto == "1" ) + { + $sql2 = "SELECT icmp_type, icmp_code, icmp_csum, icmp_id, icmp_seq FROM icmphdr ". + "WHERE sid='".$sid."' AND cid='".$cid."'"; + $result2 = $db->acidExecute($sql2); + $myrow2 = $result2->acidFetchRow(); + + echo ' + +
    ICMP'; + echo ' '; + echo ' '; + echo ' + + + + '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '
    typecodechecksumidseq #
    ('.$myrow2[0].') '.ICMPType2str($myrow2[0]).'('.$myrow2[1].') '.ICMPCode2str($myrow2[0],$myrow2[1]).''.$myrow2[2].''.$myrow2[3].''.$myrow2[4].'
    '; + echo '
    '; + + $ICMPitype = $myrow2[0]; + $ICMPicode = $myrow2[1]; + + $result2->acidFreeRows(); + } + + /* Print the Payload */ + $sql2 = "SELECT data_payload FROM data WHERE sid='".$sid."' AND cid='".$cid."'"; + $result2 = $db->acidExecute($sql2); + + /* get encoding information and detail_level on the payload */ + $sql3 = 'SELECT encoding, detail FROM sensor WHERE sid='.$sid; + $result3 = $db->acidExecute($sql3); + $myrow3 = $result3->acidFetchRow(); + + echo ' + +
    Payload'; + echo ' '; + + $myrow2 = $result2->acidFetchRow(); + if ( $myrow2 ) + { + /* print the packet based on encoding type */ + PrintPacketPayload($myrow2[0], $myrow3[0], 1); + + if ( $layer4_proto == "1" ) + { + /* IF ( ICMP destination unreachable OR ICMP time exceeded ) */ + if ( $ICMPitype == "3" || $ICMPitype == "11" ) + { + /* IF ( network, host, port unreachable OR frag needed OR network admin prohibited OR filtered) */ + if ( $ICMPicode == "0" || $ICMPicode == "1" || $ICMPicode == "3" || + $ICMPicode == "4" || + $ICMPicode == "9" || + $ICMPicode == "13" ) + { + $work = str_replace("\n","",$myrow2[0]); + + /* + * - depending on how the packet logged, 32-bits of NULL padding after + * the checksum may still be present. + */ + if ( substr($work, 0, 8) == "00000000" ) + $offset = 8; + /* for dest. unreachable, frag needed and DF bit set indent the padding + * of MTU of next hop + */ + else if ( ($ICMPitype == "3") && ($ICMPicode == "4") ) + $offset += 8; + + $icmp_src = hexdec($work[24+$offset].$work[25+$offset]).".". + hexdec($work[26+$offset].$work[27+$offset]).".". + hexdec($work[28+$offset].$work[29+$offset]).".". + hexdec($work[30+$offset].$work[31+$offset]); + $icmp_dst = hexdec($work[32+$offset].$work[33+$offset]).".". + hexdec($work[34+$offset].$work[35+$offset]).".". + hexdec($work[36+$offset].$work[37+$offset]).".". + hexdec($work[38+$offset].$work[39+$offset]); + $icmp_proto = hexdec($work[18+$offset].$work[19+$offset]); + + $hdr_offset = ($work[$offset+1]) * 8 + $offset; + $icmp_src_port = hexdec($work[$hdr_offset].$work[$hdr_offset+1].$work[$hdr_offset+2].$work[$hdr_offset+3]); + $icmp_dst_port = hexdec($work[$hdr_offset+4].$work[$hdr_offset+5].$work[$hdr_offset+6].$work[$hdr_offset+7]); + + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo ''; + echo '
    ProtocolOrg.Source
    IP
    Org.Source
    Name
    Org.Source
    Port
    Org.Destination
    IP
    Org.Destination
    Name
    Org.Destination
    Port
    '.IPProto2Str($icmp_proto).''; + echo ''.$icmp_src.''.acidGetHostByAddr($icmp_src, $db, $dns_cache_lifetime).''.$icmp_src_port.''; + echo ''.$icmp_dst.''.acidGetHostByAddr($icmp_dst, $db, $dns_cache_lifetime).''.$icmp_dst_port.'
    '; + } + } + } + } + else + { + /* Don't have payload so lets print out why by checking the detail level */ + + /* if have fast detail level */ + if ( $myrow3[1] == "0" ) + echo '
      Fast logging used so payload was discarded
    '; + else + echo '
      none
    '; + } + $result3->acidFreeRows(); + echo '

    '; + + $result2->acidFreeRows(); + + //echo "

    $previous     $next
    "; + + //PrintQueryResultAction($action, $action_arg, 1); + + //$qs->PrintAlertActionButtons(); + $qs->SaveState(); + ExportHTTPVar("caller", $caller); + $et->Mark("Get Query Elements"); + $et->PrintTiming(); + + echo "\n
    \n"; + + PrintACIDSubFooter(); + +?> diff -Naur acid/acid_signature.inc acidfp/acid_signature.inc --- acid/acid_signature.inc 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_signature.inc 2003-12-17 14:16:39.000000000 -0500 @@ -15,7 +15,7 @@ { $name = ""; - $temp_sql = "SELECT sig_name FROM signature WHERE sig_id=$sig_id"; + $temp_sql = "SELECT sig_name FROM signature WHERE sig_id='$sig_id'"; $tmp_result = $db->acidExecute($temp_sql); if ( $tmp_result ) { @@ -29,6 +29,25 @@ return $name; } +function GetSignaturePriority($sig_id, $db) +{ + $priority = ""; + + $temp_sql = "SELECT sig_priority FROM signature WHERE sig_id='$sig_id'"; + $tmp_result = $db->acidExecute($temp_sql); + if ( $tmp_result ) + { + $myrow = $tmp_result->acidFetchRow(); + $priority = $myrow[0]; + + $tmp_result->acidFreeRows(); + } + else + $priority = "[SigPriority unknown]"; + + return $priority; +} + function GetSignatureID($sig_id, $db) { $id = ""; @@ -58,7 +77,7 @@ $ref_system_name = ""; - $tmp_sql = "SELECT ref_system_name FROM reference_system WHERE ref_system_id=".$ref_system_id; + $tmp_sql = "SELECT ref_system_name FROM reference_system WHERE ref_system_id='".$ref_system_id."'"; $tmp_result = $db->acidExecute($tmp_sql); if ( $tmp_result ) { @@ -70,11 +89,32 @@ return $ref_system_name; } +function GetSingleSignatureReference($ref_system, $ref_tag, $style) +{ + $tmp_ref_system_name = strtolower($ref_system); + if ( in_array($tmp_ref_system_name, array_keys($GLOBALS['external_sig_link'])) ) + { + if ( $style == 1 ) + return "[". + "".$ref_system."". + "]"; + else if ( $style == 2 ) + return "[".$ref_system."/$ref_tag] "; + } + else + { + return $ref_system; + } +} + function GetSignatureReference($sig_id, $db, $style) { $ref = ""; - $temp_sql = "SELECT ref_seq, ref_id FROM sig_reference WHERE sig_id=".$sig_id; + $temp_sql = "SELECT ref_seq, ref_id FROM sig_reference WHERE sig_id='".$sig_id."'"; $tmp_sig_ref = $db->acidExecute($temp_sql); if ( $tmp_sig_ref ) @@ -84,7 +124,7 @@ { $mysig_ref = $tmp_sig_ref->acidFetchRow(); - $temp_sql = "SELECT ref_system_id, ref_tag FROM reference WHERE ref_id=".$mysig_ref[1]; + $temp_sql = "SELECT ref_system_id, ref_tag FROM reference WHERE ref_id='".$mysig_ref[1]."'"; $tmp_ref_tag = $db->acidExecute($temp_sql); if ( $tmp_ref_tag ) @@ -94,63 +134,39 @@ $ref_system = GetRefSystemName($myrow[0], $db); } - $href = ""; - if ( strncasecmp($ref_system,"arachNIDS",9) == 0) - { - if ( $style == 1 ) - $href = "arachNIDS"; - else if ( $style == 2 ) - $href = "[arachNIDS/$ref_tag] "; - } - elseif ( strncasecmp($ref_system,"cve",3) == 0) - { - if ( $style == 1 ) - $href = "CVE"; - else if ( $style == 2 ) - $href = "[CVE/$ref_tag] "; - } - elseif ( strncasecmp($ref_system,"bugtraq",7) == 0) - { - if ( $style == 1 ) - $href = "bugtraq"; - else if ( $style == 2 ) - $href = "[Bugtraq/$ref_tag] "; - } - elseif ( strncasecmp($ref_system,"McAfee",6) == 0 ) - { - if ( $style == 1 ) - $href = "McAfee"; - else if ( $style == 2 ) - $href = "[McAfee/$ref_tag] "; - } - elseif ( strncasecmp($ref_system,"url",3) == 0 ) - { - if ( $style == 1 ) - $href = "url"; - else if ( $style == 2 ) - $href = "[url/$ref_tag] "; - - } - else - { - $href = $ref_system; - } + $ref = $ref.GetSingleSignatureReference($ref_system, $ref_tag, $style); - if ( $style == 1 ) - $ref = $ref."[$href] "; - else if ( $style == 2 ) - $ref = $ref.$href; - + /* Automatically add an ICAT reference is a CVE reference exists */ + if ( $ref_system == "cve" ) + $ref = $ref.GetSingleSignatureReference("icat", $ref_tag, $style); + $tmp_ref_tag->acidFreeRows(); } $tmp_sig_ref->acidFreeRows(); } + if ( $db->acidGetDBVersion() >= 103 ) + { + $tmp_sql = "SELECT sig_sid FROM signature WHERE sig_id='".$sig_id."'"; + $tmp_sig_sid = $db->acidExecute($tmp_sql); + + if ( $tmp_sig_sid ) + { + $myrow = $tmp_sig_sid->acidFetchRow(); + $sig_sid = $myrow[0]; + } + } + else + $sig_sid = ""; + + $href = ""; + + /* snort.org should be documenting all official signatures, + * so automatically add a link + */ + if ( $sig_sid != "") + $ref = $ref.GetSingleSignatureReference("snort", $sig_sid, $style); + return $ref; } @@ -171,9 +187,9 @@ $replace=array("\\1\\2", "\\1\\2\\3", - "BUGTRAQ ID \\1", - "MCAFEE ID \\1", - "\\1"); + "BUGTRAQ ID \\1", + "MCAFEE ID \\1", + "\\1"); $msg = preg_replace($pattern, $replace, $signature); @@ -208,7 +224,6 @@ * RETURNS: a formatted signature and the associated references */ { - //echo "sig_id = $sig_id
    "; if ( $db->acidGetDBVersion() >= 100 ) { /* Catch the odd circumstance where $sig_id is still an alert text string @@ -234,7 +249,7 @@ function GetSigClassID($sig_id, $db) { $sql = "SELECT sig_class_id FROM signature ". - "WHERE sig_id = $sig_id"; + "WHERE sig_id = '$sig_id'"; $result = $db->acidExecute($sql); $row = $result->acidFetchRow(); @@ -248,7 +263,7 @@ return "unclassified"; $sql = "SELECT sig_class_name FROM sig_class ". - "WHERE sig_class_id = $class_id"; + "WHERE sig_class_id = '$class_id'"; $result = $db->acidExecute($sql); $row = $result->acidFetchRow(); diff -Naur acid/acid_stat_alerts.php acidfp/acid_stat_alerts.php --- acid/acid_stat_alerts.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_alerts.php 2003-12-17 14:16:39.000000000 -0500 @@ -55,6 +55,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); diff -Naur acid/acid_stat_class.php acidfp/acid_stat_class.php --- acid/acid_stat_class.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_class.php 2003-12-17 14:16:39.000000000 -0500 @@ -53,6 +53,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); diff -Naur acid/acid_stat_common.php acidfp/acid_stat_common.php --- acid/acid_stat_common.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_common.php 2003-12-17 14:16:39.000000000 -0500 @@ -4,10 +4,10 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000 Carnegie Mellon University + * Copyright (C) 2000-2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * - * Purpose: + * Purpose: summary statistics * */ @@ -16,7 +16,7 @@ function SensorCnt($db, $join = "", $where = "") { if ( $join == "" && $where == "" ) - $result = $db->acidExecute("SELECT count(*) FROM sensor"); + $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.sid) FROM acid_event"); else $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.sid) FROM acid_event $join $where"); $myrow = $result->acidFetchRow(); @@ -52,7 +52,7 @@ { /* Calculate the Unique Alerts */ - $query = "SELECT COUNT(DISTINCT signature) FROM acid_event WHERE sid = " . $sensorID . ";"; + $query = "SELECT COUNT(DISTINCT signature) FROM acid_event WHERE sid = '" . $sensorID . "'"; $result = $db->acidExecute($query); if ( $result ) @@ -75,7 +75,7 @@ */ function EventCntBySensor($sensorID, $db) { - $query = "SELECT count(*) FROM acid_event where sid = " .$sensorID. ";"; + $query = "SELECT count(*) FROM acid_event where sid = '" .$sensorID. "'"; $result = $db->acidExecute($query); $myrow = $result->acidFetchRow(); @@ -87,7 +87,7 @@ function MinDateBySensor($sensorID, $db) { - $query = "SELECT min(timestamp) FROM acid_event WHERE sid=" . $sensorID . ";"; + $query = "SELECT min(timestamp) FROM acid_event WHERE sid= '". $sensorID."'"; $result = $db->acidExecute($query); $myrow = $result->acidFetchRow(); @@ -100,7 +100,7 @@ function MaxDateBySensor($sensorID, $db) { - $query = "SELECT max(timestamp) FROM acid_event WHERE sid=" . $sensorID . ";"; + $query = "SELECT max(timestamp) FROM acid_event WHERE sid='".$sensorID."'"; $result = $db->acidExecute($query); $myrow = $result->acidFetchRow(); @@ -112,7 +112,7 @@ function UniqueDestAddrCntBySensor( $sensorID, $db ) { - $query = "SELECT COUNT(DISTINCT ip_dst) from acid_event WHERE sid=" . $sensorID . ";"; + $query = "SELECT COUNT(DISTINCT ip_dst) from acid_event WHERE sid='" . $sensorID . "'"; $result = $db->acidExecute($query); $row = $result->acidFetchRow(); @@ -124,7 +124,7 @@ function UniqueSrcAddrCntBySensor( $sensorID, $db ) { - $query = "SELECT COUNT(DISTINCT ip_src) from acid_event WHERE sid=" . $sensorID . ";"; + $query = "SELECT COUNT(DISTINCT ip_src) from acid_event WHERE sid='" . $sensorID . "'"; $result = $db->acidExecute($query); $row = $result->acidFetchRow(); @@ -136,7 +136,7 @@ function TCPPktCnt($db) { - $result = $db->acidExecute("SELECT count(*) FROM tcphdr;"); + $result = $db->acidExecute("SELECT count(*) FROM acid_event WHERE ip_proto=6"); $myrow = $result->acidFetchRow(); $num = $myrow[0]; $result->acidFreeRows(); @@ -146,7 +146,7 @@ function UDPPktCnt($db) { - $result = $db->acidExecute("SELECT count(*) FROM udphdr;"); + $result = $db->acidExecute("SELECT count(*) FROM acid_event WHERE ip_proto=17"); $myrow = $result->acidFetchRow(); $num = $myrow[0]; $result->acidFreeRows(); @@ -156,7 +156,7 @@ function ICMPPktCnt($db) { - $result = $db->acidExecute("SELECT count(*) FROM icmphdr;"); + $result = $db->acidExecute("SELECT count(*) FROM acid_event WHERE ip_proto=1"); $myrow = $result->acidFetchRow(); $num = $myrow[0]; $result->acidFreeRows(); @@ -273,11 +273,11 @@ if ( $join == "" && $where == "") $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.layer4_sport), ". "COUNT(DISTINCT acid_event.layer4_dport) FROM acid_event ". - "WHERE ip_proto=".TCP); + "WHERE ip_proto='".TCP."'"); else $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.layer4_sport), ". "COUNT(DISTINCT acid_event.layer4_dport) FROM acid_event $join". - " $where AND ip_proto=".TCP); + " $where AND ip_proto='".TCP."'"); $row = $result->acidFetchRow(); $result->acidFreeRows(); @@ -290,11 +290,11 @@ if ( $join == "" && $where == "") $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.layer4_sport), ". "COUNT(DISTINCT acid_event.layer4_dport) FROM acid_event ". - "WHERE ip_proto=".UDP); + "WHERE ip_proto='".UDP."'"); else $result = $db->acidExecute("SELECT COUNT(DISTINCT acid_event.layer4_sport), ". "COUNT(DISTINCT acid_event.layer4_dport) FROM acid_event $join". - " $where AND ip_proto=".UDP); + " $where AND ip_proto='".UDP."'"); $row = $result->acidFetchRow(); $result->acidFreeRows(); diff -Naur acid/acid_state_citems.inc acidfp/acid_state_citems.inc --- acid/acid_state_citems.inc 1969-12-31 19:00:00.000000000 -0500 +++ acidfp/acid_state_citems.inc 2003-12-17 14:16:39.000000000 -0500 @@ -0,0 +1,1462 @@ +, + * + * Copyright (C) 2002 Carnegie Mellon University + * (see the file 'acid_main.php' for license details) + * + * Purpose: individual criteria classes + * + */ + +class BaseCriteria +{ + var $criteria; + var $export_name; + + var $db; + var $cs; + + function BaseCriteria($db, $cs, $name) + { + $this->db = &$db; + $this->cs = &$cs; + + $this->export_name = $name; + $this->criteria = NULL; + } + + function Init() + { + } + + function Import() + { + /* imports criteria from POST, GET, or the session */ + } + + function Clear() + { + /* clears the criteria */ + } + + function Sanitize() + { + /* clean/validate the criteria */ + } + + function SanitizeElement() + { + /* clean/validate the criteria */ + } + + function PrintForm() + { + /* prints the HTML form to input the criteria */ + } + + function AddFormItem() + { + /* adding another item to the HTML form */ + } + + function GetFormItemCnt() + { + /* returns the number of items in this form element */ + } + + function SetFormItemCnt() + { + /* sets the number of items in this form element */ + } + + function Set($value) + { + /* set the value of this criteria */ + } + + function Get() + { + /* returns the value of this criteria */ + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + /* generate human-readable description of this criteria */ + } + + function isEmpty() + { + /* returns if the criteria is empty */ + } +}; + +class SingleElementCriteria extends BaseCriteria +{ + function Import() + { + GLOBAL $HTTP_SESSION_VARS; + + $this->criteria = SetSessionVar($this->export_name); + + $HTTP_SESSION_VARS[$this->export_name] = &$this->criteria; + } + + function Sanitize() + { + $this->SanitizeElement(); + } + + function GetFormItemCnt() + { + return -1; + } + + function Set($value) + { + $this->criteria = $value; + } + + function Get() + { + return $this->criteria; + } + function isEmpty() + { + if ( $this->criteria == "" ) + return true; + else + return false; + } +}; + +class MultipleElementCriteria extends BaseCriteria +{ + var $element_cnt; + var $criteria_cnt; + var $valid_field_list; + + function MultipleElementCriteria($db, $cs, $export_name, $element_cnt, $field_list = NULL) + { + $this->BaseCriteria(&$db, &$cs, $export_name); + + $this->element_cnt = $element_cnt; + $this->criteria_cnt = 0; + $this->valid_field_list = $field_list; + } + + function Init() + { + GLOBAL $HTTP_SESSION_VARS; + + InitArray($this->criteria, $GLOBALS['MAX_ROWS'], $this->element_cnt, ""); + $this->criteria_cnt = 1; + + $HTTP_SESSION_VARS[$this->export_name."_cnt"] = &$this->criteria_cnt; + } + + function Import() + { + GLOBAL $HTTP_SESSION_VARS; + + $this->criteria = SetSessionVar($this->export_name); + $this->criteria_cnt = SetSessionVar($this->export_name."_cnt"); + + $HTTP_SESSION_VARS[$this->export_name] = &$this->criteria; + $HTTP_SESSION_VARS[$this->export_name."_cnt"] = &$this->criteria_cnt; + } + + function Sanitize() + { + if ( in_array("criteria", array_keys(get_object_vars($this))) ) + //if ( isset($this->criteria) ) + { + for($i=0; $i < $this->element_cnt; $i++) + { + if ( isset($this->criteria[$i]) ) + $this->SanitizeElement($i); + } + } + } + + function SanitizeElement($i) + { + } + + function GetFormItemCnt() + { + return $this->criteria_cnt; + } + + function SetFormItemCnt($value) + { + $this->criteria_cnt = $value; + } + + function AddFormItem(&$submit, $submit_value) + { + AddCriteriaFormRow($submit, $submit_value, &$this->criteria_cnt, $this->criteria, $this->element_cnt); + } + + function Set($value) + { + $this->criteria = $value; + } + + function Get() + { + return $this->criteria; + } + + function isEmpty() + { + if ( $this->criteria_cnt == 0 ) + return true; + else + return false; + } + + function PrintForm($field_list, $blank_field_string, $add_button_string) + { + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + echo ' '; + + echo ' '; + + echo ' '; + + echo ' '; + + echo ' '; + + echo ' '; + if ( $i == $this->criteria_cnt-1 ) + echo ' '; + echo '
    '; + } + } + + function Compact() + { + GLOBAL $HTTP_SESSION_VARS; + + if ( $this->isEmpty() ) + { + $this->criteria = ""; + $HTTP_SESSION_VARS[$this->export_name] = &$this->criteria; + } + } +}; + +class ProtocolFieldCriteria extends MultipleElementCriteria +{ + function SanitizeElement($i) + { + $this->criteria[$i][0] = CleanVariable($this->criteria[$i][0], VAR_OPAREN); + $this->criteria[$i][1] = CleanVariable($this->criteria[$i][1], "", array_keys($this->valid_field_list)); + $this->criteria[$i][2] = CleanVariable($this->criteria[$i][2], "", array("=", "!=", "<", "<=", ">", ">=")); + $this->criteria[$i][3] = CleanVariable($this->criteria[$i][3], VAR_DIGIT); + $this->criteria[$i][4] = CleanVariable($this->criteria[$i][4], VAR_OPAREN | VAR_CPAREN); + $this->criteria[$i][5] = CleanVariable($this->criteria[$i][5], "", array("AND", "OR")); + } + + function Description($human_fields) + { + $tmp = ""; + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + if ($this->criteria[$i][1] != " " && $this->criteria[$i][3] != "" ) + $tmp = $tmp.$this->criteria[$i][0].$human_fields[($this->criteria[$i][1])].' '. + $this->criteria[$i][2].' '.$this->criteria[$i][3].$this->criteria[$i][4].' '.$this->criteria[$i][5]; + } + if ( $tmp != "" ) + $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name); + + return $tmp; + } +} + +class SignatureCriteria extends SingleElementCriteria +{ +/* + * $sig[3]: stores signature + * - [0] : exactly, roughly [1] : signature + * - [2] : =, != + */ + + var $sig_type; + + function SignatureCriteria($db, $cs, $export_name) + { + $this->BaseCriteria(&$db, &$cs, $export_name); + + $this->sig_type = ""; + } + + function Init() + { + InitArray($this->criteria, 3, 0, ""); + $this->sig_type = ""; + } + + function Import() + { + GLOBAL $HTTP_SESSION_VARS; + + parent::Import(); + + $this->sig_type = SetSessionVar("sig_type"); + + $HTTP_SESSION_VARS['sig_type'] = &$this->sig_type; + } + + function Clear() + { + } + + function SanitizeElement() + { + $this->criteria[0] = CleanVariable($this->criteria[0], "", array(" ", "=", "LIKE")); + $this->criteria[1] = CleanVariable($this->criteria[1], VAR_ALPHA | VAR_SPACE); + $this->criteria[2] = CleanVariable($this->criteria[2], "", array("=", "!=")); + } + + function PrintForm() + { + echo ''; + + echo ''; + + echo '
    '; + + if ( $GLOBALS['use_sig_list'] > 0) + { + $temp_sql = "SELECT DISTINCT sig_name FROM signature"; + if ($GLOBALS['use_sig_list'] == 1) + { + $temp_sql = $temp_sql." WHERE sig_name NOT LIKE '%SPP\_%'"; + } + + $temp_sql = $temp_sql." ORDER BY sig_name"; + $tmp_result = $this->db->acidExecute($temp_sql); + echo '
    '; + } + } + + function ToSQL() + { + } + + function Description() + { + $tmp = $tmp_human = ""; + + if ( (isset($this->criteria[0])) && ($this->criteria[0] != " ") && + (isset($this->criteria[1])) && ($this->criteria[1] != "") ) + { + if ( $this->criteria[0] == '=' && $this->criteria[2] == '!=' ) + $tmp_human = '!='; + else if ( $this->criteria[0] == '=' && $this->criteria[2] == '=' ) + $tmp_human = '='; + else if ( $this->criteria[0] == 'LIKE' && $this->criteria[2] == '!=' ) + $tmp_human = ' does not contain '; + else if ( $this->criteria[0] == 'LIKE' && $this->criteria[2] == '=' ) + $tmp_human = ' contains '; + + $tmp = $tmp.'Signature '.$tmp_human.' "'; + if ( ($this->db->acidGetDBVersion() >= 100) && $this->sig_type == 1 ) + $tmp = $tmp.BuildSigByID($this->criteria[1], $this->db).'" '.$this->cs->GetClearCriteriaString($this->export_name); + else + $tmp = $tmp.$this->criteria[1].'"'.$this->cs->GetClearCriteriaString($this->export_name); + + $tmp = $tmp.'
    '; + } + + return $tmp; + } +}; /* SignatureCriteria */ + +class SignatureClassificationCriteria extends SingleElementCriteria +{ + function Init() + { + $this->criteria = ""; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria = CleanVariable($this->criteria, VAR_DIGIT, array("null")); + } + + function PrintForm() + { + if ( $this->db->acidGetDBVersion() >= 103 ) + { + echo '  '; + } + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $tmp = ""; + + if ( $this->db->acidGetDBVersion() >= 103 ) + { + if ( $this->criteria != " " && $this->criteria != "" ) + { + if ( $this->criteria == "null") + $tmp = $tmp.'Signature Classification = '. + 'unclassified
    '; + else + $tmp = $tmp.'Signature Classification = '. + GetSigClassName($this->criteria, $this->db). + $this->cs->GetClearCriteriaString($this->export_name).'
    '; + } + } + + return $tmp; + } +}; /* SignatureClassificationCriteria */ + +class SignaturePriorityCriteria extends SingleElementCriteria +{ + function Init() + { + $this->criteria = ""; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria[0] = CleanVariable($this->criteria[0], "", array("=", "!=", "<", "<=", ">", ">=")); + $this->criteria[1] = CleanVariable($this->criteria[1], VAR_DIGIT, array("null")); + } + + function PrintForm() + { + if ( $this->db->acidGetDBVersion() >= 103 ) + { + echo ''; + + echo '  '; + } + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $tmp = ""; + + if ( $this->db->acidGetDBVersion() >= 103 ) + { + if ( $this->criteria[1] != " " && $this->criteria[1] != "" ) + { + if ( $this->criteria[1] == null) + $tmp = $tmp.'Signature Priority = '. + 'none
    '; + else + $tmp = $tmp.'Signature Priority '.$this->criteria[0]." ".$this->criteria[1]. + $this->cs->GetClearCriteriaString($this->export_name).'
    '; + } + } + + return $tmp; + } + }; /* SignaturePriorityCriteria */ + +class AlertGroupCriteria extends SingleElementCriteria +{ + function Init() + { + $this->criteria = ""; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria = CleanVariable($this->criteria, VAR_DIGIT); + } + + function PrintForm() + { + echo '  '; + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $tmp = ""; + + if ( $this->criteria != " " && $this->criteria != "" ) + $tmp = $tmp.'Alert Group = ['.$this->criteria.'] '.GetAGNameByID($this->criteria, $this->db). + $this->cs->GetClearCriteriaString($this->export_name).'
    '; + + return $tmp; + } +}; /* AlertGroupCriteria */ + +class SensorCriteria extends SingleElementCriteria +{ + function Init() + { + $this->criteria = ""; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria = CleanVariable($this->criteria, VAR_DIGIT); + } + + function PrintForm() + { + echo '  '; + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $tmp = ""; + + if ( $this->criteria != " " && $this->criteria != "" ) + $tmp = $tmp.'Sensor = ['.$this->criteria.'] '. + GetSensorName($this->criteria, $this->db). + $this->cs->GetClearCriteriaString($this->export_name).'
    '; + + return $tmp; + } +}; /* SensorCriteria */ + +class TimeCriteria extends MultipleElementCriteria +{ +/* + * $time[MAX][10]: stores the date/time of the packet detection + * - [][0] : ( [][5] : hour + * - [][1] : =, !=, <, <=, >, >= [][6] : minute + * - [][2] : month [][7] : second + * - [][3] : day [][8] : (, ) + * - [][4] : year [][9] : AND, OR + * + * $time_cnt : number of rows in the $time[][] structure + */ + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement($i) + { + $this->criteria[$i][0] = CleanVariable($this->criteria[$i][0], VAR_OPAREN); + $this->criteria[$i][1] = CleanVariable($this->criteria[$i][1], "", array("=", "!=", "<", "<=", ">", ">=")); + $this->criteria[$i][2] = CleanVariable($this->criteria[$i][2], VAR_DIGIT); + $this->criteria[$i][3] = CleanVariable($this->criteria[$i][3], VAR_DIGIT); + $this->criteria[$i][4] = CleanVariable($this->criteria[$i][4], VAR_DIGIT); + $this->criteria[$i][5] = CleanVariable($this->criteria[$i][5], VAR_DIGIT); + $this->criteria[$i][6] = CleanVariable($this->criteria[$i][6], VAR_DIGIT); + $this->criteria[$i][7] = CleanVariable($this->criteria[$i][7], VAR_DIGIT); + $this->criteria[$i][8] = CleanVariable($this->criteria[$i][8], VAR_OPAREN | VAR_CPAREN); + $this->criteria[$i][9] = CleanVariable($this->criteria[$i][9], "", array("AND", "OR")); + } + + function PrintForm() + { + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + echo ''; + echo ''; + + echo ''; + echo ''; + echo ''; + + echo ':'; + echo ':'; + echo ''; + + echo ''; + echo ''; + + if ( $i == $this->criteria_cnt-1 ) + echo ' '; + echo '
    '; + } + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $tmp = ""; + for ($i = 0; $i < $this->criteria_cnt; $i++) + { + if ( isset($this->criteria[$i][1]) && $this->criteria[$i][1] != " " ) + { + $tmp = $tmp.''.$this->criteria[$i][0].' time '.$this->criteria[$i][1].' [ '; + + /* date */ + if ( $this->criteria[$i][2] == " " && $this->criteria[$i][3] == "" && $this->criteria[$i][4] == " " ) + $tmp = $tmp." any date"; + else + $tmp = $tmp.(($this->criteria[$i][2] == " ") ? "* / " : $this->criteria[$i][2]." / "). + (($this->criteria[$i][3] == "" ) ? "* / " : $this->criteria[$i][3]." / "). + (($this->criteria[$i][4] == " ") ? "* " : $this->criteria[$i][4]." "); + $tmp = $tmp.'] [ '; + /* time */ + if ( $this->criteria[$i][5] == "" && $this->criteria[$i][6] == "" && $this->criteria[$i][7] == "" ) + $tmp = $tmp."any time"; + else + $tmp = $tmp.(($this->criteria[$i][5] == "") ? "* : " : $this->criteria[$i][5]." : "). + (($this->criteria[$i][6] == "") ? "* : " : $this->criteria[$i][6]." : "). + (($this->criteria[$i][7] == "") ? "* " : $this->criteria[$i][7]." "); + $tmp = $tmp.$this->criteria[$i][8].'] '.$this->criteria[$i][9]; + $tmp = $tmp.'
    '; + } + } + if ( $tmp != "" ) + $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name); + + return $tmp; + } +}; /* TimeCriteria */ + +class IPAddressCriteria extends MultipleElementCriteria +{ +/* + * $ip_addr[MAX][10]: stores an ip address parameters/operators row + * - [][0] : ( [][5] : octet3 of address + * - [][1] : source, dest [][6] : octet4 of address + * - [][2] : =, != [][7] : network mask + * - [][3] : octet1 of address [][8] : (, ) + * - [][4] : octet2 of address [][9] : AND, OR + * + * $ip_addr_cnt: number of rows in the $ip_addr[][] structure + */ + + function IPAddressCriteria($db, $cs, $export_name, $element_cnt) + { + parent::MultipleElementCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("ip_src" => "Source", + "ip_dst" => "Dest", + "ip_both" => "Src or Dest")); + } + + function Import() + { + GLOBAL $HTTP_SESSION_VARS; + + parent::Import(); + + /* expand IP into octets */ + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + if ( (isset ($this->criteria[$i][3])) && + (ereg("([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)", $this->criteria[$i][3])) ) + { + $tmp_ip_str = $this->criteria[$i][7] = $this->criteria[$i][3]; + $this->criteria[$i][3] = strtok($tmp_ip_str, "."); + $this->criteria[$i][4] = strtok("."); + $this->criteria[$i][5] = strtok("."); + $this->criteria[$i][6] = strtok("/"); + $this->criteria[$i][10] = strtok(""); + } + } + + $HTTP_SESSION_VARS['ip_addr'] = &$this->criteria; + $HTTP_SESSION_VARS['ip_addr_cnt'] = &$this->criteria_cnt; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria[$i][0] = CleanVariable($this->criteria[$i][0], VAR_OPAREN); + $this->criteria[$i][1] = CleanVariable($this->criteria[$i][1], "", array_keys($this->valid_field_list)); + $this->criteria[$i][2] = CleanVariable($this->criteria[$i][2], "", array("=", "!=", "<", "<=", ">", ">=")); + $this->criteria[$i][3] = CleanVariable($this->criteria[$i][3], VAR_DIGIT | VAR_PERIOD | VAR_FSLASH); + $this->criteria[$i][4] = CleanVariable($this->criteria[$i][4], VAR_DIGIT); + $this->criteria[$i][5] = CleanVariable($this->criteria[$i][5], VAR_DIGIT); + $this->criteria[$i][6] = CleanVariable($this->criteria[$i][6], VAR_DIGIT); + $this->criteria[$i][7] = CleanVariable($this->criteria[$i][7], VAR_DIGIT); + $this->criteria[$i][8] = CleanVariable($this->criteria[$i][8], VAR_OPAREN | VAR_CPAREN); + $this->criteria[$i][9] = CleanVariable($this->criteria[$i][9], "", array("AND", "OR")); + } + + function PrintForm() + { + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + echo ' '; + echo ' '; + echo ' '; + + if ( $GLOBALS['ip_address_input'] == 2 ) + echo ' '; + else + { + echo ' .'; + echo ' .'; + echo ' .'; + echo ' '; + } + echo ' '; + echo ' '; + if ( $i == $this->criteria_cnt-1 ) + echo ' '; + echo '
    '; + } + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $human_fields["ip_src"] = "Source Address"; + $human_fields["ip_dst"] = "Dest. Address"; + $human_fields["ip_both"] = "Source or Dest. Address"; + $human_fields[""] = ""; + $human_fields["LIKE"] = "contains"; + $human_fields["="] = "="; + + $tmp2 = ""; + + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + $tmp = ""; + if ( isset($this->criteria[$i][3]) && $this->criteria[$i][3] != "" ) + { + $tmp = $tmp.$this->criteria[$i][3]; + if ( $this->criteria[$i][4] != "" ) + { + $tmp = $tmp.".".$this->criteria[$i][4]; + if ( $this->criteria[$i][5] != "" ) + { + $tmp = $tmp.".".$this->criteria[$i][5]; + if ( $this->criteria[$i][6] != "" ) + { + if ( ($this->criteria[$i][3].".".$this->criteria[$i][4].".". + $this->criteria[$i][5].".".$this->criteria[$i][6]) == NULL_IP) + $tmp = " unknown "; + else + $tmp = $tmp.".".$this->criteria[$i][6]; + } + else + $tmp = $tmp.'.*'; + } + else + $tmp = $tmp.'.*.*'; + } + else + $tmp = $tmp.'.*.*.*'; + } + /* Make sure that the IP isn't blank */ + if ( $tmp != "" ) + { + $mask = ""; + if ( $this->criteria[$i][10] != "" ) + $mask = "/".$this->criteria[$i][10]; + + $tmp2 = $tmp2.$this->criteria[$i][0]. + $human_fields[($this->criteria[$i][1])].' '.$this->criteria[$i][2]. + ' '.$tmp.' '.$this->criteria[$i][8].' '.$this->criteria[$i][9].$mask. + $this->cs->GetClearCriteriaString($this->export_name)."
    "; + } + } + + return $tmp2; + } +}; /* IPAddressCriteria */ + +class IPFieldCriteria extends ProtocolFieldCriteria +{ +/* + * $ip_field[MAX][6]: stores all other ip fields parameters/operators row + * - [][0] : ( [][3] : field value + * - [][1] : TOS, TTL, ID, offset, length [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $ip_field_cnt: number of rows in the $ip_field[][] structure + */ + + function IPFieldCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array("ip_tos" => "TOS", + "ip_ttl" => "TTL", + "ip_id" => "ID", + "ip_off" => "offset", + "ip_csum" => "chksum", + "ip_len" => "length")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ field }", "ADD IP Field"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description( array_merge( array ( "" => "", + "LIKE" => "contains", + "=" => "="), $this->valid_field_list ) ); + } +}; + +class TCPPortCriteria extends ProtocolFieldCriteria +{ +/* + * $tcp_port[MAX][6]: stores all port parameters/operators row + * - [][0] : ( [][3] : port value + * - [][1] : Source Port, Dest Port [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $tcp_port_cnt: number of rows in the $tcp_port[][] structure + */ + + function TCPPortCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("layer4_sport" => "source port", + "layer4_dport" => "dest port")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ port }", "ADD TCP Port"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description(array_merge( array("" => "", + "=" => "="), $this->valid_field_list) ); + } +}; /* TCPPortCriteria */ + +class TCPFieldCriteria extends ProtocolFieldCriteria +{ +/* + * TCP Variables + * ============= + * $tcp_field[MAX][6]: stores all other tcp fields parameters/operators row + * - [][0] : ( [][3] : field value + * - [][1] : windows, URP [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $tcp_field_cnt: number of rows in the $tcp_field[][] structure + */ + + function TCPFieldCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("tcp_win" => "window", + "tcp_urp" => "urp", + "tcp_seq" => "seq #", + "tcp_ack" => "ack", + "tcp_off" => "offset", + "tcp_res" => "res", + "tcp_csum" => "chksum")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ field }", "ADD TCP Field"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) ); + } +}; /* TCPFieldCriteria */ + +class TCPFlagsCriteria extends SingleElementCriteria +{ +/* + * $tcp_flags[7]: stores all other tcp flags parameters/operators row + * - [0] : is, contains [4] : 8 (RST) + * - [1] : 1 (FIN) [5] : 16 (ACK) + * - [2] : 2 (SYN) [6] : 32 (URG) + * - [3] : 4 (PUSH) + */ + + function Init() + { + InitArray($this->criteria, $GLOBALS['MAX_ROWS'], TCPFLAGS_CFCNT, ""); + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria = CleanVariable($this->criteria, VAR_DIGIT); + } + + function PrintForm() + { + echo ''; + echo ' '; + echo ' criteria[8],"128").'> [RSV1]  '; + echo ' criteria[7],"64").'> [RSV0]  '; + echo ' criteria[6],"32").'> [URG]  '; + echo ' criteria[5],"16").'> [ACK]  '; + echo ' criteria[4],"8").'> [PSH]  '; + echo ' criteria[3],"4").'> [RST]  '; + echo ' criteria[2],"2").'> [SYN]  '; + echo ' criteria[1],"1").'> [FIN]  '; + echo ' '; + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $human_fields["1"] = "F"; + $human_fields["2"] = "S"; + $human_fields["4"] = "R"; + $human_fields["8"] = "P"; + $human_fields["16"] = "A"; + $human_fields["32"] = "U"; + $human_fields["64"] = "[R0]"; + $human_fields["128"] = "[R1]"; + $human_fields["LIKE"] = "contains"; + $human_fields["="] = "="; + + $tmp = ""; + + if ( isset($this->criteria[0]) && ($this->criteria[0] != " ") && ($this->criteria[0] != "") ) + { + $tmp = $tmp.'flags '.$this->criteria[0].' '; + for ( $i = 8; $i >=1; $i-- ) + if ( $this->criteria[$i] == "" ) + $tmp = $tmp.'-'; + else + $tmp = $tmp.$human_fields[($this->criteria[$i])]; + + $tmp = $tmp.$this->cs->GetClearCriteriaString("tcp_flags").'
    '; + } + + return $tmp; + } + + function isEmpty() + { + if ( ($this->criteria[0] != "") && ($this->criteria[0] != " ") ) + return false; + else + return true; + } +}; /* TCPFlagCriteria */ + +class UDPPortCriteria extends ProtocolFieldCriteria +{ +/* + * $udp_port[MAX][6]: stores all port parameters/operators row + * - [][0] : ( [][3] : port value + * - [][1] : Source Port, Dest Port [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $udp_port_cnt: number of rows in the $udp_port[][] structure + */ + + function UDPPortCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("layer4_sport" => "source port", + "layer4_dport" => "dest port")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ port }", "ADD UDP Port"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description(array_merge( array("" => "", + "=" => "="), $this->valid_field_list) ); + } +}; /* UDPPortCriteria */ + +class UDPFieldCriteria extends ProtocolFieldCriteria +{ +/* + * $udp_field[MAX][6]: stores all other udp fields parameters/operators row + * - [][0] : ( [][3] : field value + * - [][1] : length [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $udp_field_cnt: number of rows in the $udp_field[][] structure + */ + + function UDPFieldCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("udp_len" => "length", + "udp_csum" => "chksum")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ field }", "ADD UDP Field"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) ); + } +}; /* UDPFieldCriteria */ + +class ICMPFieldCriteria extends ProtocolFieldCriteria +{ +/* + * $icmp_field[MAX][6]: stores all other icmp fields parameters/operators row + * - [][0] : ( [][3] : field value + * - [][1] : code, length [][4] : (, ) + * - [][2] : =, !=, <, <=, >, >= [][5] : AND, OR + * + * $icmp_field_cnt: number of rows in the $icmp_field[][] structure + */ + + function ICMPFieldCriteria($db, $cs, $export_name, $element_cnt) + { + parent::ProtocolFieldCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("icmp_type" => "type", + "icmp_code" => "code", + "icmp_id" => "id", + "icmp_seq" => "seq #", + "icmp_csum" => "chksum")); + } + + function PrintForm() + { + parent::PrintForm($this->valid_field_list, "{ field }", "ADD ICMP Field"); + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + return parent::Description(array_merge ( array("" => ""), $this->valid_field_list) ); + } +}; /* ICMPFieldCriteria */ + +class Layer4Criteria extends SingleElementCriteria +{ + function Init() + { + $this->criteria = ""; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement() + { + $this->criteria = CleanVariable($this->criteria, "", array("UDP", "TCP", "ICMP", "no layer4")); + } + + function PrintForm() + { + if ( $this->criteria != "" ) + echo '  '; + if ( $this->criteria == "TCP" ) + echo ' +   + '; + else if ( $this->criteria == "UDP" ) + echo ' +   + '; + else if ( $this->criteria == "ICMP" ) + echo ' +   + '; + else + echo ' +   + + '; + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + if ( $this->criteria == "TCP" ) + return "TCP Criteria"; + else if ( $this->criteria == "UDP" ) + return "UDP Criteria"; + else if ( $this->criteria == "ICMP" ) + return "ICMP Criteria"; + else + return "Layer 4 Criteria"; + } +}; /* Layer4Criteria */ + +class DataCriteria extends MultipleElementCriteria +{ +/* + * $data_encode[2]: how the payload should be interpreted and converted + * - [0] : encoding type (hex, ascii) + * - [1] : conversion type (hex, ascii) + * + * $data[MAX][5]: stores all the payload related parameters/operators row + * - [][0] : ( [][3] : (, ) + * - [][1] : =, != [][4] : AND, OR + * - [][2] : field value + * + * $data_cnt: number of rows in the $data[][] structure + */ + + var $data_encode; + + function DataCriteria($db, $cs, $export_name, $element_cnt) + { + parent::MultipleElementCriteria(&$db, &$cs, $export_name, $element_cnt, + array ("LIKE" => "has", + "NOT LIKE" => "has NOT" )); + $this->data_encode = array(); + } + + function Init() + { + parent::Init(); + InitArray($this->data_encode, 2, 0, ""); + } + + function Import() + { + GLOBAL $HTTP_SESSION_VARS; + + parent::Import(); + + $this->data_encode = SetSessionVar("data_encode"); + + $HTTP_SESSION_VARS['data_encode'] = &$this->data_encode; + } + + function Clear() + { + /* clears the criteria */ + } + + function SanitizeElement($i) + { + $this->data_encode[0] = CleanVariable($this->data_encode[0], "", array("hex", "ascii")); + $this->data_encode[1] = CleanVariable($this->data_encode[1], "", array("hex", "ascii")); + + $this->criteria[$i][0] = CleanVariable($this->criteria[$i][0], VAR_OPAREN); + $this->criteria[$i][1] = CleanVariable($this->criteria[$i][1], "", array_keys($this->valid_field_list)); + $this->criteria[$i][2] = CleanVariable($this->criteria[$i][2], VAR_ALPHA | VAR_PUNC ); + $this->criteria[$i][3] = CleanVariable($this->criteria[$i][3], VAR_OPAREN | VAR_CPAREN); + $this->criteria[$i][4] = CleanVariable($this->criteria[$i][4], "", array("AND", "OR")); + } + + function PrintForm() + { + echo 'Input Criteria Encoding Type:'; + echo ''; + echo 'Convert To (when searching):'; + echo ''; + echo '
    '; + + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + echo ''; + echo ''; + + echo ''; + + echo ''; + echo ''; + + if ( $i == $this->criteria_cnt-1 ) + echo ' '; + echo '
    '; + } + } + + function ToSQL() + { + /* convert this criteria to SQL */ + } + + function Description() + { + $human_fields["LIKE"] = "contains"; + $human_fields["NOT LIKE"] = "does not contain"; + $human_fields[""] = ""; + + $tmp = ""; + + if ( $this->data_encode[0] != " " && $this->data_encode[1] != " ") + { + $tmp = $tmp.' (data encoded as '.$this->data_encode[0]; + $tmp = $tmp.' => '.$this->data_encode[1]; + $tmp = $tmp.')
    '; + } + else + $tmp = $tmp.' (no data conversion, assuming criteria in DB native encoding)
    '; + + for ( $i = 0; $i < $this->criteria_cnt; $i++ ) + { + if ($this->criteria[$i][1] != " " && $this->criteria[$i][2] != "" ) + $tmp = $tmp.$this->criteria[$i][0].$human_fields[$this->criteria[$i][1]].' "'.$this->criteria[$i][2]. + '" '.$this->criteria[$i][3].' '.$this->criteria[$i][4]; + } + + if ( $tmp != "" ) + $tmp = $tmp.$this->cs->GetClearCriteriaString($this->export_name); + + return $tmp; + } +}; + +?> diff -Naur acid/acid_state_common.inc acidfp/acid_state_common.inc --- acid/acid_state_common.inc 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_state_common.inc 2003-12-17 14:16:39.000000000 -0500 @@ -4,20 +4,30 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000-2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: routines to manipulate shared state (session * information) * */ - +/* *********************************************************************** + * Function: InitArray() + * + * @doc Defines an initializes a 1 or 2 dimensional PHP array. + * + * @param $a (in/out) array to initialize + * @param $dim1 number of elements of first dimension + * @param $dim2 number of elements of second dimension + * @param $value default value + * + ************************************************************************/ function InitArray(&$a, $dim1, $dim2, $value) { $a = ""; /* determine the number of dimensions in the array */ if ( $dim2 == 0 ) /* 1-dim */ - for ( $i = 0; $i < $dim2; $i++ ) + for ( $i = 0; $i < $dim1; $i++ ) $a[$i] = $value; else /* 2-dim */ for ( $i = 0; $i < $dim1; $i++ ) @@ -25,70 +35,16 @@ $a[$i][$j] = $value; } -function InitGlobalState() -{ - GLOBAL $time, $time_cnt, $sig, $sig_class, $sensor, $ag, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $save_criteria, - $join_sql, $where_sql, $criteria_sql, $sql, $debug_mode, - $back_list, $back_list_cnt; - GLOBAL $MAX_ROWS; - - $caller = ""; - $layer4 = ""; - - InitArray($back_list, 1, 3, ""); - $back_list_cnt = 0; - - $ag = ""; - $sensor = ""; - InitArray($sig, 3, 0, ""); - $sig_class = ""; - InitArray($time, $MAX_ROWS, TIME_CFCNT, ""); - $time_cnt = 0; - - InitArray($ip_addr, $MAX_ROWS, IPADDR_CFCNT, ""); - $ip_addr_cnt = 0; - InitArray($ip_field, $MAX_ROWS, PROTO_CFCNT, ""); - $ip_field_cnt = 0; - - InitArray($tcp_port, $MAX_ROWS, PROTO_CFCNT, ""); - $tcp_port_cnt = 0; - InitArray($tcp_flags, $MAX_ROWS, TCPFLAGS_CFCNT, ""); - InitArray($tcp_field, $MAX_ROWS, PROTO_CFCNT, ""); - $tcp_field_cnt = 0; - - InitArray($udp_port, $MAX_ROWS, PROTO_CFCNT, ""); - $udp_port_cnt = 0; - InitArray($udp_field, $MAX_ROWS, PROTO_CFCNT, ""); - $udp_field_cnt = 0; - - InitArray($icmp_field, $MAX_ROWS, PROTO_CFCNT, ""); - $icmp_field_cnt = 0; - - InitArray($data_encode, 2, 0, ""); - InitArray($data, $MAX_ROWS, PAYLOAD_CFCNT, ""); - $data_cnt = 0; -} - +/* *********************************************************************** + * Function: RegisterGlobalState() + * + * @doc Application-specific wrapper for PHP session_start(). It performs + * a couple of additional configuration checks (notably for custom + * PHP session handlers). + * + ************************************************************************/ function RegisterGlobalState() { - GLOBAL $time, $time_cnt, $sig, $sensor, $ag, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $save_criteria, - $join_sql, $where_sql, $criteria_sql, $sql, $debug_mode, - $back_list, $back_list_cnt; - - GLOBAL $MAX_ROWS; - /* Deal with user specified session handlers */ if (session_module_name() == "user" ) { @@ -125,170 +81,199 @@ session_start(); - session_register('back_list'); - session_register('back_list_cnt'); - session_register('layer4'); - - session_register('ag'); - session_register('sig_type'); - session_register('sig'); - session_register('sig_class'); - session_register('sensor'); - session_register('time'); - session_register('time_cnt'); - - session_register('ip_addr'); - session_register('ip_addr_cnt'); - session_register('ip_field'); - session_register('ip_field_cnt'); - - session_register('tcp_port'); - session_register('tcp_port_cnt'); - session_register('tcp_flags'); - session_register('tcp_field'); - session_register('tcp_field_cnt'); - - session_register('udp_port'); - session_register('udp_port_cnt'); - session_register('udp_field'); - session_register('udp_field_cnt'); - - session_register('icmp_field'); - session_register('icmp_field_cnt'); - - session_register('data_encode'); - session_register('data'); - session_register('data_cnt'); - - if ( $debug_mode > 0 ) + if ( $GLOBALS['debug_mode'] > 0 ) echo 'Session Registered
    '; } -function ImportGlobalState() +/* *********************************************************************** + * Function: CleanVariables() + * + * @doc Removes invalid characters/data from a variable based on a + * specified mask of acceptable data or a list of explicit values. + * + * Note: only the mask or explicit list can be used a a time + * + * @param item variable to scrub + * @param valid_data mask of valid characters + * @param exception array with explicit values to match + * + * @return a sanitized version of the passed variable + * + ************************************************************************/ +function CleanVariable($item, $valid_data, $exception = "") { - GLOBAL $time, $time_cnt, $sig, $sig_type, $sig_class, $sensor, $ag, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $save_criteria, - $join_sql, $where_sql, $criteria_sql, $sql, $debug_mode, - $caller, $layer4, $back_list, $back_list_cnt, $HTTP_SESSION_VARS; + return $item; - $ip_addr = SetSessionVar('ip_addr', $ip_addr); - $ip_addr_cnt = SetSessionVar('ip_addr_cnt', $ip_addr_cnt); + /* Check the exception value list first */ + if ( $exception != "" ) + { + if ( in_array($item, $exception) ) + return $item; + else + return ""; + } - /* expand IP into octets */ - for ( $i = 0; $i < $ip_addr_cnt; $i++ ) - { - if ( (isset ($ip_addr[$i][3])) && - (ereg("([0-9]*)\.([0-9]*)\.([0-9]*)\.([0-9]*)", $ip_addr[$i][3])) ) - { - $tmp_ip_str = $ip_addr[$i][7] = $ip_addr[$i][3]; - $ip_addr[$i][3] = strtok($tmp_ip_str, "."); - $ip_addr[$i][4] = strtok("."); - $ip_addr[$i][5] = strtok("."); - $ip_addr[$i][6] = strtok("/"); - $ip_addr[$i][10] = strtok(""); - } - } - - //$back_list = $HTTP_SESSION_VARS["back_list"]; - //$back_list_cnt = $HTTP_SESSION_VARS["back_list_cnt"]; - - $ag = SetSessionVar("ag", $ag); - $sig = SetSessionVar("sig", $sig); - $sig_type = SetSessionVar("sig_type", $sig_type); - $sig_class = SetSessionVar("sig_class", $sig_class); - $sensor = SetSessionVar('sensor', $sensor); - $time = SetSessionVar('time', $time); - $time_cnt = SetSessionVar('time_cnt', $time_cnt); - - $ip_field = SetSessionVar('ip_field', $ip_field); - $ip_field_cnt = SetSessionVar('ip_field_cnt', $ip_field_cnt); - - $tcp_port = SetSessionVar('tcp_port', $tcp_port); - $tcp_port_cnt = SetSessionVar('tcp_port_cnt', $tcp_port_cnt); - $tcp_flags = SetSessionVar('tcp_flags', $tcp_flags); - $tcp_field = SetSessionVar('tcp_field', $tcp_field); - $tcp_field_cnt = SetSessionVar('tcp_field_cnt', $tcp_field_cnt); - - $udp_port = SetSessionVar('udp_port', $udp_port); - $udp_port_cnt = SetSessionVar('udp_port_cnt', $udp_port_cnt); - $udp_field = SetSessionVar('udp_field', $udp_field); - $udp_field_cnt = SetSessionVar('udp_field_cnt', $udp_field_cnt); - - $icmp_field = SetSessionVar('icmp_field', $icmp_field); - $icmp_field_cnt = SetSessionVar('icmp_field_cnt', $icmp_field_cnt); - - $data_encode = SetSessionVar('data_encode', $data_encode); - $data = SetSessionVar('data', $data); - $data_cnt = SetSessionVar('data_cnt', $data_cnt); - - $layer4 = SetSessionVar('layer4', $layer4); - //$caller = SetSessionVar('caller', $caller); - // $sort_order = SetSessionVar('sort_order', $sort_order); -} + if ( $valid_data == "" ) + return $item; -function SanitizeVariable($item, $validchars) -{ - $len = strlen($item); + $regex_mask = ""; - for ( $i = 0; $i < $len; $i++ ); - -} + if ( ($valid_data & VAR_DIGIT) > 0 ) + $regex_mask = $regex_mask . "0-9"; -function CleanVariable($item, $method) -{ - return $item; - switch ($method) - { - case 0: /* only numbers */ - return ereg_replace ("^0123456789", "", $item); + if ( ($valid_data & VAR_LETTER) > 0 ) + $regex_mask = $regex_mask . "A-Za-z"; - case 1: /* IP address */ - return ereg_replace ("^0123456789\.", "", $item); - } + if ( ($valid_data & VAR_ULETTER) > 0 ) + $regex_mask = $regex_mask . "A-Z"; + + if ( ($valid_data & VAR_LLETTER) > 0 ) + $regex_mask = $regex_mask . "a-z"; + + if ( ($valid_data & VAR_ALPHA) > 0 ) + $regex_mask = $regex_mask . "0-9A-Za-z"; + if ( ($valid_data & VAR_SPACE) > 0 ) + $regex_mask = $regex_mask . "\ "; + + if ( ($valid_data & VAR_PERIOD) > 0 ) + $regex_mask = $regex_mask . "\."; + + if ( ($valid_data & VAR_OPAREN) > 0 ) + $regex_mask = $regex_mask . "\("; + + if ( ($valid_data & VAR_CPAREN) > 0 ) + $regex_mask = $regex_mask . "\)"; + + if ( ($valid_data & VAR_BOOLEAN) > 0 ) + $regex_mask = $regex_mask . "\)"; + + if ( ($valid_data & VAR_OPERATOR) > 0 ) + $regex_mask = $regex_mask . "\)"; + + if ( ($valid_data & VAR_PUNC) > 0 ) + $regex_mask = $regex_mask . "\!\#\$\%\^\&\*\_\-\=\+\:\;\,\?\ \(\))"; + + if ( ($valid_data & VAR_USCORE) > 0 ) + $regex_mask = $regex_mask . "\_"; + + if ( ($valid_data & VAR_AT) > 0 ) + $regex_mask = $regex_mask . "\@"; + + return ereg_replace("[^".$regex_mask."]", "", $item); } -function SetSessionVar($var_name, $old_value) +/* *********************************************************************** + * Function: SetSessionVar() + * + * @doc Handles retrieving and updating persistant session (criteria) + * data. This routine handles the details of checking for criteria + * updates passed through POST/GET and resolving this with values + * that may already have been set and stored in the session. + * + * All criteria variables need invoke this function before they are + * used for the first time to extract their previously stored values, + * and process potential updates to their value. + * + * Note: Validation of user input is not performed by this routine. + * + * @param $var_name name of the persistant session variable to retrieve + * + * @return the updated value of the persistant session variable named + * by $var_name + * + ************************************************************************/ +function SetSessionVar($var_name) { - GLOBAL $HTTP_POST_VARS, $HTTP_GET_VARS, $debug_mode; + GLOBAL $HTTP_POST_VARS, $HTTP_GET_VARS, $HTTP_SESSION_VARS; if ( isset($HTTP_POST_VARS[$var_name]) ) { - if ( $debug_mode > 0 ) echo "importing POST var '$var_name'
    "; + if ( $GLOBALS['debug_mode'] > 0 ) echo "importing POST var '$var_name'
    "; return $HTTP_POST_VARS[$var_name]; } else if ( isset($HTTP_GET_VARS[$var_name]) ) { - if ( $debug_mode > 0 ) echo "importing GET var '$var_name'
    "; + if ( $GLOBALS['debug_mode'] > 0 ) echo "importing GET var '$var_name'
    "; return $HTTP_GET_VARS[$var_name]; } + else if ( isset($HTTP_SESSION_VARS[$var_name]) ) + { + if ( $GLOBALS['debug_mode'] > 0 ) echo "importing SESSION var '$var_name'
    "; + return $HTTP_SESSION_VARS[$var_name]; + } else - return $old_value; + return ""; } -function ImportHTTPVar($var_name) +/* *********************************************************************** + * Function: ImportHTTPVar() + * + * @doc Handles retrieving temporary state variables needed to present a + * given set of results (e.g., sort order, current record). The + * values of these variables are never persistantly stored. Rather, + * they are passed as HTTP POST and GET parameters. + * + * All temporary variables need invoke this function before they are + * used for the first time to extract their value. + * + * Optionally, sanitization parameters can be set, ala CleanVariable() + * syntax to validate the user input. + * + * @param $var_name name of the temporary state variable to retrieve + * @param $valid_data (optional) list of valid character types + * (see CleanVariable) + * @param $exception (optional) array of explicit values the imported + * variable must be set to + * + * @see CleanVariable + * + * @return the sanitized value of the temporary state variable named + * by $var_name + * + ************************************************************************/ +function ImportHTTPVar($var_name, $valid_data = "", $exception = "") { GLOBAL $HTTP_POST_VARS, $HTTP_GET_VARS, $debug_mode; + $tmp = ""; + if ( isset($HTTP_POST_VARS[$var_name]) ) { //if ( $debug_mode > 0 ) echo "importing POST var '$var_name'
    "; - return $HTTP_POST_VARS[$var_name]; + $tmp = $HTTP_POST_VARS[$var_name]; } else if ( isset($HTTP_GET_VARS[$var_name]) ) { //if ( $debug_mode > 0 ) echo "importing GET var '$var_name'
    "; - return $HTTP_GET_VARS[$var_name]; + $tmp = $HTTP_GET_VARS[$var_name]; } else - return ""; + $tmp = ""; + + return CleanVariable($tmp, $valid_data, $exception); } +/* *********************************************************************** + * Function: ExportHTTPVar() + * + * @doc Handles export of a temporary state variables needed to present a + * given set of results (e.g., sort order, current record). This + * routine creates a hidden HTML form variable. + * + * Note: The user is responsible for generating the appropriate HTML + * form code. + * + * Security Note: Only, temporary variables should make use of this + * function. These values are exposed in HTML to the + * user; he is free to modify them. + * + * @param $var_name name of the temporary state variable to export + * @param $var_value value of the temporary state variable + * + * @see ImportHTTPVar + * + ************************************************************************/ function ExportHTTPVar ($var_name, $var_value) { echo "\n"; diff -Naur acid/acid_state_criteria.inc acidfp/acid_state_criteria.inc --- acid/acid_state_criteria.inc 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_state_criteria.inc 2003-12-17 14:16:39.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2001 Carnegie Mellon University + * Copyright (C) 2001-2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: routines to manipulate shared state (session @@ -13,65 +13,100 @@ */ include_once("acid_state_common.inc"); +include_once("acid_state_citems.inc"); class CriteriaState { - var $valid_criteria_list = array("layer4", - "ag", - "sig", - "sig_class", - "sensor", - "time", - "ip_addr", - "ip_field", - "tcp_port", - "tcp_flags", - "tcp_field", - "udp_port", - "udp_field", - "icmp_field", - "data"); - var $clear_criteria_name; var $clear_criteria_element; var $clear_url; var $clear_url_params; + var $criteria; + function CriteriaState($url, $params = "") { - $this->clear_url = $url; - $this->clear_url_params = $params; + $this->clear_url = $url; + $this->clear_url_params = $params; + + /* XXX-SEC */ + GLOBAL $db; + + $this->criteria['sig'] = new SignatureCriteria(&$db, &$this, "sig"); + $this->criteria['sig_class'] = new SignatureClassificationCriteria(&$db, &$this, "sig_class"); + $this->criteria['sig_priority'] = new SignaturePriorityCriteria(&$db, &$this, "sig_priority"); + $this->criteria['ag'] = new AlertGroupCriteria(&$db, &$this, "ag"); + $this->criteria['sensor'] = new SensorCriteria(&$db, &$this, "sensor"); + $this->criteria['time'] = new TimeCriteria(&$db, &$this, "time", TIME_CFCNT); + $this->criteria['ip_addr'] = new IPAddressCriteria(&$db, &$this, "ip_addr", IPADDR_CFCNT); + $this->criteria['layer4'] = new Layer4Criteria(&$db, &$this, "layer4"); + $this->criteria['ip_field'] = new IPFieldCriteria(&$db, &$this, "ip_field", PROTO_CFCNT); + $this->criteria['tcp_port'] = new TCPPortCriteria(&$db, &$this, "tcp_port", PROTO_CFCNT); + $this->criteria['tcp_flags'] = new TCPFlagsCriteria(&$db, &$this, "tcp_flags"); + $this->criteria['tcp_field'] = new TCPFieldCriteria(&$db, &$this, "tcp_field", PROTO_CFCNT); + $this->criteria['udp_port'] = new UDPPortCriteria(&$db, &$this, "udp_port", PROTO_CFCNT); + $this->criteria['udp_field'] = new UDPFieldCriteria(&$db, &$this, "udp_field", PROTO_CFCNT); + $this->criteria['icmp_field'] = new ICMPFieldCriteria(&$db, &$this, "icmp_field", PROTO_CFCNT); + $this->criteria['data'] = new DataCriteria(&$db, &$this, "data", PAYLOAD_CFCNT); + + /* + * For new criteria, add a call to the appropriate constructor here, and implement + * the appropriate class in acid_stat_citems.inc. + */ } function InitState() { - RegisterGlobalState(); - InitGlobalState(); + RegisterGlobalState(); + + $valid_criteria_list = array_keys($this->criteria); + + foreach ( $valid_criteria_list as $cname ) + $this->criteria[$cname]->Init(); } function ReadState() { - GLOBAL $time, $time_cnt, $sig, $sig_type, - $sensor, $ag, $sig_class, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode, $QUERY_STRING, $PHP_SELF, $debug_mode, - $back_list, $back_list_cnt; - - RegisterGlobalState(); - ImportGlobalState(); - - $this->clear_criteria_name = ImportHTTPVar("clear_criteria"); - $this->clear_criteria_element = ImportHTTPVar("clear_criteria_element"); - - if ( $this->clear_criteria_name != "" ) - $this->ClearCriteriaStateElement($this->clear_criteria_name, - $this->clear_criteria_element); - if ( $GLOBALS['maintain_history'] == 1 ) - PreserveHistory(); + RegisterGlobalState(); + + /* + * If the BACK button was clicked, shuffle the appropriate + * criteria variables from the $back_list (history) array into + * the current session ($HTTP_SESSION_VARS) + */ + if ( ($GLOBALS['maintain_history'] == 1) && + (ImportHTTPVar("back", VAR_DIGIT) == 1) ) + { + PopHistory(); + } + + /* + * Import, update and sanitize all persistant criteria variables + */ + $valid_criteria_list = array_keys($this->criteria); + foreach ( $valid_criteria_list as $cname ) + { + $this->criteria[$cname]->Import(); + $this->criteria[$cname]->Sanitize(); + } + + /* + * Check whether criteria elements need to be cleared + */ + $this->clear_criteria_name = ImportHTTPVar("clear_criteria", "", + array_keys($this->criteria)); + $this->clear_criteria_element = ImportHTTPVar("clear_criteria_element", "", + array_keys($this->criteria)); + + if ( $this->clear_criteria_name != "" ) + $this->ClearCriteriaStateElement($this->clear_criteria_name, + $this->clear_criteria_element); + + /* + * Save the current criteria into $back_list (history) + */ + if ( $GLOBALS['maintain_history'] == 1 ) + PushHistory(); } function GetBackLink() @@ -87,151 +122,155 @@ function ClearCriteriaStateElement($name, $element) { - GLOBAL $time, $time_cnt, $sig, $sig_type, - $sensor, $ag, $sig_class, - $ip_addr, $ip_addr_cnt, $ip_field, $ip_field_cnt, - $tcp_port, $tcp_port_cnt, $tcp_flags, $tcp_field, $tcp_field_cnt, - $udp_port, $udp_port_cnt, $udp_field, $udp_field_cnt, - $icmp_field, $icmp_field_cnt, - $have_meta, $have_ip, $have_tcp, $have_udp, $have_icmp, $have_data, - $layer4, $data, $data_cnt, $data_encode; + $valid_criteria_list = array_keys($this->criteria); - if ( in_array($name, $this->valid_criteria_list) ) + if ( in_array($name, $valid_criteria_list) ) { ErrorMessage("Removing '$name' from criteria"); - - switch($name) - { - case "sensor": - $sensor = ""; - break; - case "ag": - $ag = ""; - break; - case "sig": - $sig = ""; - break; - case "sig_class": - $sig_class = ""; - break; - case "time": - unset($time); - $time_cnt = 0; - break; - case "ip_addr": - unset($ip_addr); - $ip_addr_cnt = 0; - break; - case "ip_field": - unset($ip_field); - $ip_field_cnt = 0; - break; - case "tcp_port": - unset($tcp_port); - $tcp_port_cnt = 0; - break; - case "tcp_flags": - unset($tcp_flags); - $tcp_flags_cnt = 0; - break; - case "tcp_field": - unset($tcp_field); - $tcp_field_cnt = 0; - break; - case "udp_port": - unset($udp_port); - $udp_port_cnt = 0; - break; - case "udp_field": - unset($udp_field); - $udp_field_cnt = 0; - break; - case "icmp_field": - unset($icmp_field); - $icmp_field_cnt = 0; - break; - case "data": - unset($data); - $data_cnt = 0; - break; - } + + $this->criteria[$name]->Init(); } else ErrorMessage("Invalid criteria element"); } } -function PreserveHistory() +/* *********************************************************************** + * Function: PopHistory() + * + * @doc Remove and restore the last entry of the history list (i.e., + * hit the back button in the browser) + * + * @see PushHistory PrintBackButton + * + ************************************************************************/ +function PopHistory() +{ + GLOBAL $HTTP_SESSION_VARS; + + if ( $HTTP_SESSION_VARS['back_list_cnt'] >= 0 ) + { + /* Remove the state of the page from which the back button was + * just hit + */ + unset($HTTP_SESSION_VARS['back_list'][$HTTP_SESSION_VARS['back_list_cnt']]); + + /* + * save a copy of the $back_list because session_destroy()/session_decode() will + * overwrite it. + */ + $save_back_list = $HTTP_SESSION_VARS['back_list']; + $save_back_list_cnt = $HTTP_SESSION_VARS['back_list_cnt']-1; + + /* Restore the session + * - destroy all variables in the current session + * - restore proper back_list history entry into the current variables (session) + * - but, first delete the currently restored entry and + * decremement the history stack + * - push saved back_list back into session + */ + session_unset(); + + if ( $GLOBALS['debug_mode'] > 2 ) + ErrorMessage("Popping a History Entry from #".$save_back_list_cnt); + + session_decode($save_back_list[$save_back_list_cnt]["session"]); + unset($save_back_list[$save_back_list_cnt]); + --$save_back_list_cnt; + + $HTTP_SESSION_VARS['back_list'] = $save_back_list; + $HTTP_SESSION_VARS['back_list_cnt'] = $save_back_list_cnt; + } +} + +/* *********************************************************************** + * Function: PushHistory() + * + * @doc Save the current criteria into the history list ($back_list, + * $back_list_cnt) in order to support the ACID back button. + * + * @see PopHistory PrintBackButton + * + ************************************************************************/ +function PushHistory() { - GLOBAL $back_list_cnt, $back_list, $PHP_SELF, $QUERY_STRING, $debug_mode; - - /* If the BACK button was clicked, extract the old criteria */ - if ( ImportHTTPVar("back") == 1 ) - { - --$back_list_cnt; - if ( $back_list_cnt >= 0 ) - { - if ( $debug_mode > 0 ) - { - $tmp_num = $back_list_cnt + 1; - ErrorMessage("Back (from ".$back_list[$tmp_num]["PHP_SELF"].")"); - ErrorMessage("Import (historical) state from #".$back_list_cnt); - } - - session_decode($back_list[$back_list_cnt]["session"]); - $back_list = & $GLOBALS['back_list']; - } - } - - /* Save criteria of current page into history - * Note: the $back_list need not be saved - */ - session_unregister('back_list'); - $full_session = session_encode(); - session_register('back_list'); - $back_list_cnt = & $GLOBALS['back_list_cnt']; - - ++$back_list_cnt; - $back_list[$back_list_cnt] = array ("PHP_SELF" => $PHP_SELF, - "QUERY_STRING" => $QUERY_STRING, - "session" => $full_session ); + GLOBAL $HTTP_SERVER_VARS, $HTTP_SESSION_VARS, $HTTP_POST_VARS; + + if ( $GLOBALS['debug_mode'] > 1 ) + { + ErrorMessage("Saving state (into ".$HTTP_SESSION_VARS['back_list_cnt'].")"); + } + + /* save the current session without the $back_list into the history + * - make a temporary copy of the $back_list + * - NULL-out the $back_list in $HTTP_SESSION_VARS (so that + * the current session is serialized without these variables) + * - serialize the current session + * - fix-up the QUERY_STRING + * - make a new QUERY_STRING that includes the temporary QueryState variables + * - remove &back=1 from any QUERY_STRING + * - add the current session into the $back_list (history) + */ + $tmp_back_list = $HTTP_SESSION_VARS['back_list']; + $tmp_back_list_cnt = $HTTP_SESSION_VARS['back_list_cnt']; + + $HTTP_SESSION_VARS['back_list'] = NULL; + $HTTP_SESSION_VARS['back_list_cnt'] = -1; + + $full_session = session_encode(); + $HTTP_SESSION_VARS['back_list'] = $tmp_back_list; + $HTTP_SESSION_VARS['back_list_cnt'] = $tmp_back_list_cnt; + + $query_string = $HTTP_SERVER_VARS["QUERY_STRING"]; + if ( isset($HTTP_POST_VARS['caller']) ) $query_string .= "&caller=".$HTTP_POST_VARS['caller']; + if ( isset($HTTP_POST_VARS['num_result_rows']) ) $query_string .= "&num_result_rows=".$HTTP_POST_VARS['num_result_rows']; + if ( isset($HTTP_POST_VARS['sort_order']) ) $query_string .= "&sort_order=".$HTTP_POST_VARS['sort_order']; + if ( isset($HTTP_POST_VARS['current_view']) ) $query_string .= "¤t_view=".$HTTP_POST_VARS['current_view']; + if ( isset($HTTP_POST_VARS['submit']) ) $query_string .= "&submit=".$HTTP_POST_VARS['submit']; + + $query_string = ereg_replace("back=1&", "", $query_string); + + ++$HTTP_SESSION_VARS['back_list_cnt']; + $HTTP_SESSION_VARS['back_list'][$HTTP_SESSION_VARS['back_list_cnt']] = + array ("PHP_SELF" => $HTTP_SERVER_VARS["PHP_SELF"], + "QUERY_STRING" => $query_string, /*$HTTP_SERVER_VARS["QUERY_STRING"], */ + "session" => $full_session ); - if ( $debug_mode > 0 ) + if ( $GLOBALS['debug_mode'] > 1 ) { - echo "History depth = $back_list_cnt
    "; - /* - ErrorMessage("Saved criteria for ".$back_list[$back_list_cnt]["PHP_SELF"]); - for ( $i = 1; $i <= $back_list_cnt; $i++ ) - echo $back_list[$i]["PHP_SELF"]."    >    "; - echo "
    "; - */ - } - - if ( $debug_mode > 1 ) - { - echo "Back List (Cnt = $back_list_cnt)
    ";
    -    print_r($back_list);
    -    echo "
    "; + ErrorMessage("Insert session into slot #".$HTTP_SESSION_VARS['back_list_cnt']); + + echo "Back List (Cnt = ".$HTTP_SESSION_VARS['back_list_cnt'].")
    ";
    +      print_r($HTTP_SESSION_VARS['back_list']);
    +      echo "
    "; } } +/* *********************************************************************** + * Function: PrintBackButton() + * + * @doc Returns a string with the URL of the previously viewed + * page. Clicking this link is equivalent to using the browser + * back-button, but all the associated ACID meta-information + * propogates correctly. + * + * @see PushHistory PopHistory + * + ************************************************************************/ function PrintBackButton() { - GLOBAL $back_list, $back_list_cnt; + GLOBAL $HTTP_SESSION_VARS; if ( $GLOBALS['maintain_history'] == 0 ) return "Back"; - $back_list = & $GLOBALS['back_list']; - $back_list_cnt = & $GLOBALS['back_list_cnt']; - - $criteria_num = $back_list_cnt - 1; - - if ( isset($back_list[$criteria_num]["PHP_SELF"]) ) + $criteria_num = $HTTP_SESSION_VARS['back_list_cnt'] - 1; + + if ( isset($HTTP_SESSION_VARS['back_list'][$criteria_num]["PHP_SELF"]) ) - return "Back"; + $HTTP_SESSION_VARS['back_list'][$criteria_num]["QUERY_STRING"]."\">Back"; else return "Back"; } diff -Naur acid/acid_state_query.inc acidfp/acid_state_query.inc --- acid/acid_state_query.inc 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_state_query.inc 2003-12-17 14:16:39.000000000 -0500 @@ -120,7 +120,6 @@ function AddValidActionOp($action_op) { $this->valid_action_op_list[ count($this->valid_action_op_list) ] = $action_op; - //array_push($this->valid_action_op_list, $action_op); } function SetActionSQL($sql) @@ -312,30 +311,30 @@ function ReadState() { - $this->current_canned_query = ImportHTTPVar("caller"); - $this->num_result_rows = ImportHTTPVar("num_result_rows"); - $this->current_sort_order = ImportHTTPVar("sort_order"); - $this->current_view = ImportHTTPVar("current_view"); - $this->action_arg = ImportHTTPVar("action_arg"); - $this->action_chk_lst = ImportHTTPVar("action_chk_lst"); - $this->action_lst = ImportHTTPVar("action_lst"); - $this->action = ImportHTTPVar("action"); + $this->current_canned_query = ImportHTTPVar("caller", VAR_LETTER | VAR_USCORE); + $this->num_result_rows = ImportHTTPVar("num_result_rows", VAR_DIGIT); + $this->current_sort_order = ImportHTTPVar("sort_order", VAR_LETTER | VAR_USCORE); + $this->current_view = ImportHTTPVar("current_view", VAR_DIGIT); + $this->action_arg = ImportHTTPVar("action_arg", VAR_ALPHA | VAR_PERIOD | VAR_USCORE | VAR_AT); + $this->action_chk_lst = ImportHTTPVar("action_chk_lst", VAR_DIGIT); + $this->action_lst = ImportHTTPVar("action_lst", VAR_DIGIT); + $this->action = ImportHTTPVar("action", VAR_LETTER | VAR_USCORE); } function SaveState() { - echo "\n"; - ExportHTTPVar("caller", $this->current_canned_query); - ExportHTTPVar("num_result_rows", $this->num_result_rows); - ExportHTTPVar("sort_order", $this->current_sort_order); - ExportHTTPVar("current_view", $this->current_view); + echo "\n"; + ExportHTTPVar("caller", $this->current_canned_query); + ExportHTTPVar("num_result_rows", $this->num_result_rows); + ExportHTTPVar("sort_order", $this->current_sort_order); + ExportHTTPVar("current_view", $this->current_view); } function SaveStateGET() { - return "?caller=".$this->current_canned_query. - "&num_result_rows=".$this->num_result_rows. - "¤t_view=".$this->current_view; + return "?caller=".$this->current_canned_query. + "&num_result_rows=".$this->num_result_rows. + "¤t_view=".$this->current_view; } function DumpState() diff -Naur acid/acid_stat_fingerprints.php acidfp/acid_stat_fingerprints.php --- acid/acid_stat_fingerprints.php 1969-12-31 19:00:00.000000000 -0500 +++ acidfp/acid_stat_fingerprints.php 2004-02-06 11:56:05.000000000 -0500 @@ -0,0 +1,251 @@ +, + * + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University + * (see the file 'acid_main.php' for license details) + * + * Purpose: Displays stats on an individual IP address + * + * Input GET/POST variables + * - action: + * - submit: + * - ip: + * - netmask: + */ + + $start = time(); + + include("acid_constants.inc"); + include("acid_conf.php"); + include("acid_include.inc"); + include_once("acid_db_common.php"); + include_once("acid_common.php"); + + $et = new EventTiming($debug_time_mode); + $cs = new CriteriaState("acid_stat_ipaddr.php"); + $cs->ReadState(); + + $sortby = ImportHTTPVar("sortby"); + $dir = ImportHTTPVar("dir"); + $iddir = $sigdir = $fstdir = $lstdir = $addrdir = $portdir = $protodir = $servdir = $hopsdir = "ASC"; + + if ( $dir == "" ) + { + $dir="ASC"; + } + + if ( $sortby == "" || $sortby == "addr" ) + { + + if ( $dir == "DESC" ) + { + $orderby = "fpevent.ip_src DESC, fpevent.port_src"; + $addrdir = "ASC"; + } + else + { + $orderby = "fpevent.ip_src ASC, fpevent.port_src"; + $addrdir = "DESC"; + } + } + if ( $sortby == "port" ) + { + + if ( $dir == "DESC" ) + { + $orderby = "fpevent.port_src DESC, fpevent.ip_src"; + $portdir = "ASC"; + } + else + { + $orderby = "fpevent.port_src ASC, fpevent.ip_src"; + $portdir = "DESC"; + } + } + if ( $sortby == "fseen" ) + { + + if ( $dir == "DESC" ) + { + $orderby="fpevent.firstseen DESC, fpevent.ip_src"; + $fstdir = "ASC"; + } + else + { + $orderby="fpevent.firstseen ASC, fpevent.ip_src"; + $fstdir = "DESC"; + } + } + if ( $sortby == "lseen" ) + { + if ( $dir == "DESC" ) + { + $orderby="fpevent.lastseen DESC, fpevent.ip_src"; + $lstdir="ASC"; + } + else + { + $orderby="fpevent.lastseen ASC, fpevent.ip_src"; + $lstdir="DESC"; + } + } + if ( $sortby == "sig" ) + { + + if ( $dir == "DESC" ) + { + $orderby="signature.sig_name DESC, fpevent.ip_src"; + $sigdir = "ASC"; + } + else + { + $orderby="signature.sig_name ASC, fpevent.ip_src"; + $sigdir = "DESC"; + } + } + if ( $sortby == "proto" ) + { + + if ( $dir == "DESC" ) + { + $orderby="fpevent.protocol DESC, fpevent.ip_src"; + $protodir = "ASC"; + } + else + { + $orderby="fpevent.protocol ASC, fpevent.ip_src"; + $protodir = "DESC"; + } + } + if ( $sortby == "serv" ) + { + + if ( $dir == "DESC" ) + { + $orderby="services.name DESC, fpevent.ip_src"; + $servdir = "ASC"; + } + else + { + $orderby="services.name ASC, fpevent.ip_src"; + $servdir = "DESC"; + } + } + if ( $sortby == "id" ) + { + + if ( $dir == "DESC" ) + { + $orderby="fpevent.sid DESC, fpevent.cid DESC"; + $iddir = "ASC"; + } + else + { + $orderby="fpevent.sid ASC, fpevent.cid ASC"; + $iddir = "DESC"; + } + } + if ( $sortby == "hops" ) + { + + if ( $dir == "DESC" ) + { + $orderby="fpevent.hopcount DESC, fpevent.ip_src"; + $hopsdir = "ASC"; + } + else + { + $orderby="fpevent.hopcount ASC, fpevent.ip_src"; + $hopsdir = "DESC"; + } + } + + + + $page_title = 'Network Fingerprints'; + PrintACIDSubHeader($page_title, $page_title, $cs->GetBackLink()); + + + /* Connect to the Alert database */ + $db = NewACIDDBConnection($DBlib_path, $DBtype); + $db->acidDBConnect($db_connect_method, + $alert_dbname, $alert_host, $alert_port, $alert_user, $alert_password); + + if ( $event_cache_auto_update == 1 ) UpdateAlertCache($db); + + /* SDR BEGIN */ + echo '
    '; + + $temp = "SELECT fpevent.sid, fpevent.cid, signature.sig_name, fpevent.firstseen, fpevent.lastseen, ". + "fpevent.ip_src, fpevent.port_src, fpevent.protocol, services.name, fpevent.hopcount ". + "FROM fpevent,signature,services ". + "WHERE ( fpevent.signature = signature.sig_id ". + "AND fpevent.port_src = services.port AND fpevent.protocol = services.protocol ) ". + "ORDER BY ".$orderby; +/* + echo "Query is: ".$temp; +*/ + $result2 = $db->acidExecute($temp); + + echo '
    + + + + + + + + + + + + '; + + while ( $row2 = $result2->acidFetchRow() ) + { + if ( $row2[9] == "-1" ) + { + $row2[9] = "N/A"; + } + echo ' + + + + + + + + + + '; + } + $result2->acidFreeRows (); + echo '
    IDSignatureFirst SeenLast SeenAddressPortProtocolHopsService
    + '.$row2[0].'-'.$row2[1].''.$row2[2].''.$row2[3].''.$row2[4].' + + '.acidLong2IP($row2[5]).''.$row2[6].''.$row2[7].''.$row2[9].''.$row2[8].'
    '; + + /* SDR END */ + + + + PrintACIDSubFooter(); +?> + + + + + diff -Naur acid/acid_stat_ipaddr.php acidfp/acid_stat_ipaddr.php --- acid/acid_stat_ipaddr.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_ipaddr.php 2003-12-17 14:17:10.000000000 -0500 @@ -4,7 +4,7 @@ * * Author: Roman Danyliw , * - * Copyright (C) 2000, 2001 Carnegie Mellon University + * Copyright (C) 2000, 2001, 2002 Carnegie Mellon University * (see the file 'acid_main.php' for license details) * * Purpose: Displays stats on an individual IP address @@ -215,8 +215,9 @@ //if ( !VerifySocketSupport() ) echo ' ARIN | - RIPE - APNIC
    '; + RIPE | + APNIC | + LACNIC
    '; echo 'External: '. 'DNS | '. @@ -269,7 +270,7 @@ /* Number of Sensors, First, and Last timestamp */ $temp = "SELECT COUNT(DISTINCT sid), MIN(timestamp), MAX(timestamp) FROM acid_event ". - "WHERE (ip_src = $ip_src32 OR ip_dst = $ip_dst32 )"; + "WHERE (ip_src = '$ip_src32' OR ip_dst = '$ip_dst32' )"; $result2 = $db->acidExecute($temp); $row2 = $result2->acidFetchRow(); @@ -279,14 +280,14 @@ $result2->acidFreeRows(); /* Unique instances as Source Address */ - $temp = "SELECT COUNT(sid) from acid_event WHERE ip_src=$ip_src32"; + $temp = "SELECT COUNT(sid) from acid_event WHERE ip_src='$ip_src32'"; $result2 = $db->acidExecute($temp); $row2 = $result2->acidFetchRow(); $num_src_ip = $row2[0]; $result2->acidFreeRows(); /* Unique instances Dest. Address */ - $temp = "SELECT COUNT(sid) from acid_event WHERE ip_dst=$ip_dst32"; + $temp = "SELECT COUNT(sid) from acid_event WHERE ip_dst='$ip_dst32'"; $result2 = $db->acidExecute($temp); $row2 = $result2->acidFetchRow(); $num_dst_ip = $row2[0]; @@ -309,6 +310,46 @@
    '; + /* SDR BEGIN */ + echo '

    Network Fingerprints
    '; + $temp = "SELECT fpevent.sid, fpevent.cid, signature.sig_name, fpevent.firstseen, fpevent.lastseen, ". + "fpevent.port_src, fpevent.protocol, services.name ". + "FROM fpevent,signature,services ". + "WHERE (fpevent.ip_src = '$ip_src32' AND fpevent.signature = signature.sig_id ". + "AND fpevent.port_src = services.port AND fpevent.protocol = services.protocol )". + "ORDER BY fpevent.port_src ASC"; + $result2 = $db->acidExecute($temp); + + echo '
    + + + + + + + + + + '; + while ( $row2 = $result2->acidFetchRow() ) + { + echo ' + + + + + + + + '; + } + $result2->acidFreeRows(); + echo '
    IDSignatureFirst SeenLast SeenPortProtocolService
    + '.$row2[0].'-'.$row2[1].''.$row2[2].''.$row2[3].''.$row2[4].''.$row2[5].''.$row2[6].''.$row2[7].'
    '; + + /* SDR END */ + if ( $action == "events" ) { echo '
    diff -Naur acid/acid_stat_iplink.php acidfp/acid_stat_iplink.php --- acid/acid_stat_iplink.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_iplink.php 2003-12-17 14:16:39.000000000 -0500 @@ -55,6 +55,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); diff -Naur acid/acid_stat_sensor.php acidfp/acid_stat_sensor.php --- acid/acid_stat_sensor.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_sensor.php 2003-12-17 14:16:39.000000000 -0500 @@ -30,7 +30,7 @@ $qs = new QueryState(); - $submit = ImportHTTPVar("submit"); + $submit = ImportHTTPVar("submit", VAR_DIGIT); $qs->MoveView($submit); /* increment the view if necessary */ $page_title = "Sensor Listing"; @@ -51,6 +51,7 @@ $qs->AddValidAction("ag_by_id"); $qs->AddValidAction("ag_by_name"); + $qs->AddValidAction("add_new_ag"); $qs->AddValidAction("del_alert"); $qs->AddValidAction("email_alert"); $qs->AddValidAction("email_alert2"); diff -Naur acid/acid_stat_time.php acidfp/acid_stat_time.php --- acid/acid_stat_time.php 2002-03-03 18:02:45.000000000 -0500 +++ acidfp/acid_stat_time.php 2003-12-17 14:16:39.000000000 -0500 @@ -67,8 +67,8 @@ if ( $value_lst[$i] > $max_cnt ) $max_cnt = $value_lst[$i]; echo ' - - + + '; @@ -190,6 +190,8 @@
    Time# of Alerts
    Time# of Alerts Alerts