From 301048b51990573e58a30dc4a5bb4ec285cad554 Mon Sep 17 00:00:00 2001 From: Dinko Korunic Date: Thu, 24 Feb 2011 20:08:44 +0100 Subject: [PATCH] Imported Upstream version 2.5.1 --- .hg_archival.txt | 5 + .hgignore | 62 ++ .hgtags | 6 + BUGS | 4 +- CONFIG | 4 +- CONTRIB => CONTRIBUTORS | 5 +- INSTALL | 2 +- LICENSE | 913 ++++++-------------- README | 4 +- active-response/firewall-drop.sh | 3 + active-response/win/netsh.cmd | 33 + active-response/win/route-null.cmd | 2 +- contrib/ossec-batch-manager.pl | 4 +- contrib/ossec-testing/runtests.py | 81 ++ contrib/ossec-testing/tests/named.ini | 10 + contrib/ossec2mysql.pl | 2 +- contrib/ossec2mysqld.pl | 4 +- etc/decoder.xml | 76 +- etc/ossec-local.conf | 46 +- etc/ossec-server.conf | 47 +- etc/rules/apache_rules.xml | 9 +- etc/rules/arpwatch_rules.xml | 4 +- etc/rules/asterisk_rules.xml | 4 +- etc/rules/attack_rules.xml | 10 +- etc/rules/cimserver_rules.xml | 35 + etc/rules/cisco-ios_rules.xml | 4 +- etc/rules/courier_rules.xml | 10 +- etc/rules/firewall_rules.xml | 4 +- etc/rules/ftpd_rules.xml | 9 +- etc/rules/hordeimp_rules.xml | 4 +- etc/rules/ids_rules.xml | 4 +- etc/rules/imapd_rules.xml | 4 +- etc/rules/local_rules.xml | 4 +- etc/rules/mailscanner_rules.xml | 4 +- etc/rules/mcafee_av_rules.xml | 2 +- etc/rules/ms-exchange_rules.xml | 4 +- etc/rules/ms-se_rules.xml | 73 ++ etc/rules/ms_dhcp_rules.xml | 2 +- etc/rules/ms_ftpd_rules.xml | 4 +- etc/rules/msauth_rules.xml | 505 ++++++++++- etc/rules/mysql_rules.xml | 4 +- etc/rules/named_rules.xml | 10 +- etc/rules/netscreenfw_rules.xml | 4 +- etc/rules/nginx_rules.xml | 4 +- etc/rules/ossec_rules.xml | 4 +- etc/rules/pam_rules.xml | 6 +- etc/rules/php_rules.xml | 4 +- etc/rules/pix_rules.xml | 4 +- etc/rules/policy_rules.xml | 4 +- etc/rules/postfix_rules.xml | 17 +- etc/rules/postgresql_rules.xml | 4 +- etc/rules/proftpd_rules.xml | 7 +- etc/rules/pure-ftpd_rules.xml | 2 +- etc/rules/racoon_rules.xml | 2 +- etc/rules/roundcube_rules.xml | 2 +- etc/rules/rules_config.xml | 4 +- etc/rules/sendmail_rules.xml | 2 +- etc/rules/smbd_rules.xml | 6 +- etc/rules/solaris_bsm_rules.xml | 4 +- etc/rules/sonicwall_rules.xml | 4 +- etc/rules/spamd_rules.xml | 2 +- etc/rules/squid_rules.xml | 10 +- etc/rules/sshd_rules.xml | 11 +- etc/rules/symantec-av_rules.xml | 4 +- etc/rules/symantec-ws_rules.xml | 4 +- etc/rules/syslog_rules.xml | 29 +- etc/rules/telnetd_rules.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_da.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_de.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_en.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_es.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_fr.xml | 2 +- .../pure_ftpd/pure-ftpd_rules_fr_funny.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_it.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_nl.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_no.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_pt_br.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_ro.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_sk.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_sv.xml | 2 +- .../translated/pure_ftpd/pure-ftpd_rules_tr.xml | 2 +- etc/rules/trend-osce_rules.xml | 4 +- etc/rules/vmpop3d_rules.xml | 2 +- etc/rules/vmware_rules.xml | 4 +- etc/rules/vpn_concentrator_rules.xml | 4 +- etc/rules/vpopmail_rules.xml | 2 +- etc/rules/vsftpd_rules.xml | 2 +- etc/rules/web_rules.xml | 42 +- etc/rules/wordpress_rules.xml | 2 +- etc/rules/zeus_rules.xml | 4 +- etc/templates/config/rules.template | 2 + install.sh | 2 + src/Config.Make | 1 + src/InstallAgent.sh | 7 +- src/InstallServer.sh | 1 + src/LOCATION | 2 + src/Makefile | 11 + src/VERSION | 2 +- src/addagent/b64.c | 4 +- src/addagent/main.c | 4 +- src/addagent/manage_agents.c | 4 +- src/addagent/manage_agents.h | 4 +- src/addagent/manage_keys.c | 4 +- src/addagent/read_from_user.c | 4 +- src/addagent/validate.c | 4 +- src/agentlessd/agentlessd.c | 34 +- src/agentlessd/agentlessd.h | 4 +- src/agentlessd/main.c | 4 +- src/agentlessd/scripts/main.exp | 4 +- src/agentlessd/scripts/register_host.sh | 4 +- src/agentlessd/scripts/ssh.exp | 4 +- src/agentlessd/scripts/ssh_asa-fwsmconfig_diff | 4 +- src/agentlessd/scripts/ssh_foundry_diff | 4 +- src/agentlessd/scripts/ssh_generic_diff | 4 +- src/agentlessd/scripts/ssh_integrity_check_bsd | 4 +- src/agentlessd/scripts/ssh_integrity_check_linux | 4 +- src/agentlessd/scripts/ssh_nopass.exp | 4 +- src/agentlessd/scripts/ssh_pixconfig_diff | 4 +- src/agentlessd/scripts/sshlogin.exp | 4 +- src/agentlessd/scripts/su.exp | 4 +- src/analysisd/Makefile | 17 +- src/analysisd/active-response.c | 4 +- src/analysisd/active-response.h | 4 +- src/analysisd/alerts/alerts.h | 4 +- src/analysisd/alerts/exec.c | 4 +- src/analysisd/alerts/exec.h | 4 +- src/analysisd/alerts/getloglocation.c | 4 +- src/analysisd/alerts/getloglocation.h | 4 +- src/analysisd/alerts/log.c | 50 +- src/analysisd/alerts/log.h | 5 +- src/analysisd/alerts/mail.c | 2 +- src/analysisd/analysisd.c | 281 ++++-- src/analysisd/analysisd.h | 8 +- src/analysisd/cdb/Makefile | 22 + src/analysisd/cdb/cdb.c | 141 +++ src/analysisd/cdb/cdb.h | 38 + src/analysisd/cdb/cdb_hash.c | 22 + src/analysisd/cdb/cdb_make.c | 180 ++++ src/analysisd/cdb/cdb_make.h | 41 + src/analysisd/cdb/uint32.h | 11 + src/analysisd/cdb/uint32_pack.c | 11 + src/analysisd/cdb/uint32_unpack.c | 11 + src/analysisd/cleanevent.c | 17 +- src/analysisd/compiled_rules/.function_list | 2 + src/analysisd/compiled_rules/generic_samples.c | 53 +- src/analysisd/config.c | 6 +- src/analysisd/config.h | 4 +- src/analysisd/decoders/decode-xml.c | 5 +- src/analysisd/decoders/decoder.c | 42 +- src/analysisd/decoders/decoder.h | 4 +- src/analysisd/decoders/decoders_list.c | 4 +- src/analysisd/decoders/hostinfo.c | 4 +- src/analysisd/decoders/plugin_decoders.h | 4 +- .../decoders/plugins/ossecalert_decoder.c | 4 +- src/analysisd/decoders/plugins/pf_decoder.c | 4 +- src/analysisd/decoders/plugins/sonicwall_decoder.c | 4 +- .../decoders/plugins/symantecws_decoder.c | 4 +- src/analysisd/decoders/rootcheck.c | 4 +- src/analysisd/decoders/syscheck.c | 73 +- src/analysisd/dodiff.c | 213 +++++ src/analysisd/eventinfo.c | 46 +- src/analysisd/eventinfo.h | 30 +- src/analysisd/eventinfo_list.c | 4 +- src/analysisd/fts.c | 33 +- src/analysisd/fts.h | 4 +- src/analysisd/lists.c | 63 ++ src/analysisd/lists.h | 57 ++ src/analysisd/lists_list.c | 319 +++++++ src/analysisd/lists_make.c | 98 +++ src/analysisd/lists_make.h | 15 + src/analysisd/makelists.c | 190 ++++ src/analysisd/picviz.c | 4 +- src/analysisd/picviz.h | 4 +- src/analysisd/prelude.c | 444 ++++++++-- src/analysisd/prelude.h | 4 +- src/analysisd/rules.c | 323 ++++++- src/analysisd/rules.h | 41 +- src/analysisd/rules_list.c | 5 +- src/analysisd/stats.c | 4 +- src/analysisd/testrule.c | 256 +++++- src/client-agent/COPYRIGHT | 2 +- src/client-agent/agentd.c | 4 +- src/client-agent/agentd.h | 4 +- src/client-agent/config.c | 4 +- src/client-agent/event-forward.c | 4 +- src/client-agent/intcheck_op.c | 4 +- src/client-agent/main.c | 4 +- src/client-agent/notify.c | 6 +- src/client-agent/receiver-win.c | 4 +- src/client-agent/receiver.c | 4 +- src/client-agent/sendmsg.c | 4 +- src/client-agent/start_agent.c | 11 +- src/config/active-response.c | 4 +- src/config/active-response.h | 4 +- src/config/agentlessd-config.c | 4 +- src/config/agentlessd-config.h | 4 +- src/config/alerts-config.c | 2 +- src/config/client-config.c | 2 +- src/config/client-config.h | 2 +- src/config/config.c | 21 +- src/config/config.h | 6 +- src/config/csyslogd-config.c | 4 +- src/config/csyslogd-config.h | 4 +- src/config/dbd-config.c | 4 +- src/config/dbd-config.h | 4 +- src/config/email-alerts-config.c | 4 +- src/config/global-config.c | 4 +- src/config/global-config.h | 10 +- src/config/localfile-config.c | 69 +- src/config/localfile-config.h | 5 +- src/config/mail-config.h | 2 +- src/config/remote-config.c | 2 +- src/config/remote-config.h | 2 +- src/config/reports-config.c | 246 ++++++ src/config/reports-config.h | 47 + src/config/rootcheck-config.c | 2 +- src/config/rootcheck-config.h | 2 +- src/config/rules-config.c | 241 +++++- src/config/syscheck-config.c | 70 +- src/config/syscheck-config.h | 8 +- src/error_messages/error_messages.h | 7 +- src/external/zlib-1.2.3/adler32.c | 2 +- src/external/zlib-1.2.3/compress.c | 2 +- src/external/zlib-1.2.3/crc32.c | 2 +- src/external/zlib-1.2.3/deflate.c | 2 +- src/external/zlib-1.2.3/deflate.h | 2 +- src/external/zlib-1.2.3/gzio.c | 2 +- src/external/zlib-1.2.3/trees.c | 2 +- src/external/zlib-1.2.3/uncompr.c | 2 +- src/external/zlib-1.2.3/zconf.h | 2 +- src/external/zlib-1.2.3/zconf.in.h | 2 +- src/external/zlib-1.2.3/zutil.c | 2 +- src/external/zlib-1.2.3/zutil.h | 2 +- src/headers/agent_op.h | 4 +- src/headers/ar.h | 4 +- src/headers/debug_op.h | 4 +- src/headers/defs.h | 8 +- src/headers/dirtree_op.h | 4 +- src/headers/file-queue.h | 4 +- src/headers/file_op.h | 4 +- src/headers/hash_op.h | 5 +- src/headers/help.h | 4 +- src/headers/list_op.h | 4 +- src/headers/math_op.h | 4 +- src/headers/mem_op.h | 6 +- src/headers/mq_op.h | 4 +- src/headers/os_err.h | 4 +- src/headers/privsep_op.h | 4 +- src/headers/pthreads_op.h | 4 +- src/headers/rc.h | 4 +- src/headers/read-agents.h | 4 +- src/headers/read-alert.h | 4 +- src/headers/regex_op.h | 4 +- src/headers/report_op.h | 12 +- src/headers/rules_op.h | 6 +- src/headers/sec.h | 4 +- src/headers/shared.h | 13 +- src/headers/sig_op.h | 4 +- src/headers/store_op.h | 4 +- src/headers/validate_op.h | 4 +- src/headers/wait_op.h | 4 +- src/init/ossec-client.sh | 25 +- src/init/ossec-hids-gentoo.init | 2 +- src/init/ossec-local.sh | 53 +- src/init/ossec-server.sh | 51 +- src/logcollector/COPYRIGHT | 2 +- src/logcollector/config.c | 4 +- src/logcollector/logcollector.c | 82 +- src/logcollector/logcollector.h | 8 +- src/logcollector/main.c | 15 +- src/logcollector/read_command.c | 25 +- src/logcollector/read_djb_multilog.c | 4 +- src/logcollector/read_fullcommand.c | 112 +++ src/logcollector/read_mssql_log.c | 4 +- src/logcollector/read_multiline.c | 135 +++ src/logcollector/read_mysql_log.c | 4 +- src/logcollector/read_nmapg.c | 4 +- src/logcollector/read_postgresql_log.c | 4 +- src/logcollector/read_snortfull.c | 4 +- src/logcollector/read_syslog.c | 4 +- src/logcollector/read_win_el.c | 4 +- src/monitord/Makefile | 4 +- src/monitord/compress_log.c | 4 +- src/monitord/generate_reports.c | 141 +++ src/monitord/main.c | 57 +- src/monitord/manage_files.c | 4 +- src/monitord/monitor_agents.c | 4 +- src/monitord/monitord.c | 7 +- src/monitord/monitord.h | 19 +- src/monitord/report.c | 12 +- src/monitord/sign_log.c | 4 +- src/os_crypto/blowfish/bf_op.c | 2 +- src/os_crypto/blowfish/bf_op.h | 2 +- src/os_crypto/md5/md5_op.c | 2 +- src/os_crypto/md5/md5_op.h | 2 +- src/os_crypto/md5_sha1/md5_sha1_op.c | 4 +- src/os_crypto/md5_sha1/md5_sha1_op.h | 4 +- src/os_crypto/sha1/Makefile | 1 + src/os_crypto/sha1/md32_common.h | 2 +- src/os_crypto/sha1/sha.h | 2 +- src/os_crypto/sha1/sha1_op.c | 4 +- src/os_crypto/sha1/sha1_op.h | 4 +- src/os_crypto/sha1/sha_locl.h | 2 +- src/os_crypto/shared/keys.c | 4 +- src/os_crypto/shared/msgs.c | 4 +- src/os_csyslogd/alert.c | 4 +- src/os_csyslogd/config.c | 4 +- src/os_csyslogd/csyslogd.c | 4 +- src/os_csyslogd/csyslogd.h | 4 +- src/os_csyslogd/main.c | 4 +- src/os_dbd/alert.c | 34 +- src/os_dbd/config.c | 4 +- src/os_dbd/db_op.c | 4 +- src/os_dbd/db_op.h | 4 +- src/os_dbd/dbd.c | 4 +- src/os_dbd/dbd.h | 4 +- src/os_dbd/main.c | 4 +- src/os_dbd/mysql.schema | 9 +- src/os_dbd/postgresql.schema | 4 +- src/os_dbd/rules.c | 4 +- src/os_dbd/server.c | 4 +- src/os_execd/config.c | 4 +- src/os_execd/exec.c | 4 +- src/os_execd/execd.c | 4 +- src/os_execd/execd.h | 4 +- src/os_execd/win_execd.c | 4 +- src/os_maild/config.c | 4 +- src/os_maild/mail_list.c | 4 +- src/os_maild/mail_list.h | 4 +- src/os_maild/maild.c | 4 +- src/os_maild/maild.h | 5 +- src/os_maild/os_maild_client.c | 4 +- src/os_maild/sendcustomemail.c | 280 ++++++ src/os_maild/sendmail.c | 4 +- src/os_net/COPYRIGHT | 2 +- src/os_net/os_err.h | 4 +- src/os_net/os_net.c | 4 +- src/os_net/os_net.h | 4 +- src/os_regex/COPYRIGHT | 2 +- src/os_regex/os_match.c | 2 +- src/os_regex/os_match_compile.c | 18 +- src/os_regex/os_match_execute.c | 11 +- src/os_regex/os_match_free_pattern.c | 2 +- src/os_regex/os_regex.c | 2 +- src/os_regex/os_regex.h | 2 +- src/os_regex/os_regex_compile.c | 2 +- src/os_regex/os_regex_execute.c | 2 +- src/os_regex/os_regex_free_pattern.c | 2 +- src/os_regex/os_regex_free_substrings.c | 2 +- src/os_regex/os_regex_internal.h | 2 +- src/os_regex/os_regex_maps.h | 4 +- src/os_regex/os_regex_match.c | 2 +- src/os_regex/os_regex_str.c | 2 +- src/os_regex/os_regex_strbreak.c | 2 +- src/os_xml/COPYRIGHT | 2 +- src/os_xml/os_xml.c | 2 +- src/os_xml/os_xml.h | 4 +- src/os_xml/os_xml_access.c | 2 +- src/os_xml/os_xml_node_access.c | 8 +- src/os_xml/os_xml_variables.c | 2 +- src/os_xml/os_xml_writer.c | 4 +- src/os_xml/os_xml_writer.h | 4 +- src/os_zlib/os_zlib.c | 4 +- src/os_zlib/os_zlib.h | 4 +- src/os_zlib/zlib-test.c | 4 +- src/remoted/COPYRIGHT | 2 +- src/remoted/ar-forward.c | 4 +- src/remoted/config.c | 4 +- src/remoted/main.c | 4 +- src/remoted/manager.c | 4 +- src/remoted/remoted.c | 4 +- src/remoted/remoted.h | 4 +- src/remoted/secure.c | 4 +- src/remoted/sendmsg.c | 4 +- src/remoted/syslog.c | 4 +- src/remoted/syslogtcp.c | 4 +- src/rootcheck/check_open_ports.c | 4 +- src/rootcheck/check_rc_dev.c | 4 +- src/rootcheck/check_rc_files.c | 4 +- src/rootcheck/check_rc_if.c | 4 +- src/rootcheck/check_rc_pids.c | 4 +- src/rootcheck/check_rc_policy.c | 4 +- src/rootcheck/check_rc_ports.c | 4 +- src/rootcheck/check_rc_readproc.c | 4 +- src/rootcheck/check_rc_sys.c | 4 +- src/rootcheck/check_rc_trojans.c | 4 +- src/rootcheck/common.c | 96 +- src/rootcheck/common_rcl.c | 4 +- src/rootcheck/config.c | 4 +- src/rootcheck/db/cis_debian_linux_rcl.txt | 2 +- src/rootcheck/db/cis_rhel5_linux_rcl.txt | 2 +- src/rootcheck/db/cis_rhel_linux_rcl.txt | 2 +- src/rootcheck/db/rootkit_files.txt | 3 +- src/rootcheck/db/rootkit_trojans.txt | 10 +- src/rootcheck/db/system_audit_rcl.txt | 5 +- src/rootcheck/db/win_applications_rcl.txt | 2 +- src/rootcheck/db/win_audit_rcl.txt | 2 +- src/rootcheck/db/win_malware_rcl.txt | 2 +- src/rootcheck/os_string.c | 2 +- src/rootcheck/rootcheck-config.c | 4 +- src/rootcheck/rootcheck.c | 4 +- src/rootcheck/rootcheck.h | 7 +- src/rootcheck/run_rk_check.c | 4 +- src/rootcheck/unix-process.c | 4 +- src/rootcheck/util/ads_dump.c | 4 +- src/rootcheck/win-common.c | 4 +- src/rootcheck/win-process.c | 4 +- src/shared/agent_op.c | 5 +- src/shared/debug_op.c | 4 +- src/shared/dirtree_op.c | 4 +- src/shared/file-queue.c | 4 +- src/shared/file_op.c | 4 +- src/shared/hash_op.c | 4 +- src/shared/help.c | 4 +- src/shared/list_op.c | 4 +- src/shared/math_op.c | 4 +- src/shared/mem_op.c | 89 +- src/shared/mq_op.c | 4 +- src/shared/privsep_op.c | 2 +- src/shared/pthreads_op.c | 4 +- src/shared/read-agents.c | 4 +- src/shared/read-alert.c | 6 +- src/shared/regex_op.c | 4 +- src/shared/report_op.c | 207 ++++- src/shared/rules_op.c | 60 +- src/shared/sig_op.c | 4 +- src/shared/store_op.c | 4 +- src/shared/validate_op.c | 4 +- src/shared/wait_op.c | 4 +- src/syscheckd/Makefile | 6 +- src/syscheckd/config.c | 4 +- src/syscheckd/create_db.c | 267 +++--- src/syscheckd/run_check.c | 184 +--- src/syscheckd/run_realtime.c | 111 ++- src/syscheckd/seechanges.c | 271 ++++++ src/syscheckd/syscheck-baseline.c | 4 +- src/syscheckd/syscheck.c | 29 +- src/syscheckd/syscheck.h | 16 +- src/syscheckd/win-registry.c | 4 +- src/util/Makefile | 6 +- src/util/agent_control.c | 4 +- src/util/clear_stats.c | 4 +- src/util/list_agents.c | 4 +- src/util/ossec-regex.c | 102 +++ src/util/rootcheck_control.c | 4 +- src/util/syscheck_control.c | 4 +- src/util/syscheck_update.c | 4 +- src/util/verify-agent-conf.c | 50 ++ src/win32/add-localfile.c | 33 +- src/win32/doc.html | 4 +- src/win32/extract-win-el.c | 4 +- src/win32/gen_win.cmd | 56 ++ src/win32/help.txt | 30 +- src/win32/os_win.h | 4 +- src/win32/ossec-installer.nsi | 155 ++-- src/win32/service-start.c | 4 +- src/win32/service-stop.c | 4 +- src/win32/setup-iis.c | 4 +- src/win32/setup-shared.c | 4 +- src/win32/setup-shared.h | 4 +- src/win32/setup-syscheck.c | 4 +- src/win32/setup-win.c | 4 +- src/win32/ui.nsi | 4 +- src/win32/ui/common.c | 4 +- src/win32/ui/os_win32ui.c | 4 +- src/win32/ui/os_win32ui.h | 4 +- src/win32/ui/win32ui.rc | 8 +- src/win32/win-files.txt | 3 + src/win32/win_agent.c | 12 +- src/win32/win_service.c | 4 +- 470 files changed, 7846 insertions(+), 2335 deletions(-) create mode 100644 .hg_archival.txt create mode 100644 .hgignore create mode 100644 .hgtags rename CONTRIB => CONTRIBUTORS (95%) create mode 100644 active-response/win/netsh.cmd create mode 100644 contrib/ossec-testing/runtests.py create mode 100644 contrib/ossec-testing/tests/named.ini create mode 100755 etc/rules/cimserver_rules.xml create mode 100755 etc/rules/ms-se_rules.xml create mode 100644 src/analysisd/cdb/Makefile create mode 100644 src/analysisd/cdb/cdb.c create mode 100644 src/analysisd/cdb/cdb.h create mode 100644 src/analysisd/cdb/cdb_hash.c create mode 100644 src/analysisd/cdb/cdb_make.c create mode 100644 src/analysisd/cdb/cdb_make.h create mode 100644 src/analysisd/cdb/uint32.h create mode 100644 src/analysisd/cdb/uint32_pack.c create mode 100644 src/analysisd/cdb/uint32_unpack.c create mode 100755 src/analysisd/dodiff.c create mode 100644 src/analysisd/lists.c create mode 100644 src/analysisd/lists.h create mode 100644 src/analysisd/lists_list.c create mode 100644 src/analysisd/lists_make.c create mode 100644 src/analysisd/lists_make.h create mode 100644 src/analysisd/makelists.c create mode 100644 src/analysisd/makelists.h create mode 100644 src/config/reports-config.c create mode 100755 src/config/reports-config.h create mode 100755 src/logcollector/read_fullcommand.c create mode 100755 src/logcollector/read_multiline.c create mode 100755 src/monitord/generate_reports.c create mode 100755 src/os_maild/sendcustomemail.c create mode 100755 src/syscheckd/seechanges.c create mode 100644 src/util/ossec-regex.c create mode 100755 src/util/verify-agent-conf.c create mode 100644 src/win32/gen_win.cmd diff --git a/.hg_archival.txt b/.hg_archival.txt new file mode 100644 index 0000000..acdd63e --- /dev/null +++ b/.hg_archival.txt @@ -0,0 +1,5 @@ +repo: b55c69ab0638427c3307fb169a767b950530ce4a +node: 5afbec313087627a125241c880b8a03f819f714f +branch: default +latesttag: v2.5.0-beta1 +latesttagdistance: 21 diff --git a/.hgignore b/.hgignore new file mode 100644 index 0000000..3605c11 --- /dev/null +++ b/.hgignore @@ -0,0 +1,62 @@ + +syntax: glob + +*.so +*.o +*.a +*.dSYM +.hgignore + +# Auto generated build files +src/Config.OS +src/headers/zconf.h +src/headers/zlib.h +src/isbigendian.c +src/analysisd/compiled_rules/compiled_rules.h + +# Compiled programs +bin/agent_control +bin/clear_stats +bin/list_agents +bin/manage_agents +bin/ossec-agentd +bin/ossec-agentlessd +bin/ossec-analysisd +bin/ossec-csyslogd +bin/ossec-dbd +bin/ossec-execd +bin/ossec-logcollector +bin/ossec-logtest +bin/ossec-maild +bin/ossec-monitord +bin/ossec-remoted +bin/ossec-reportd +bin/ossec-syscheckd +bin/rootcheck_control +bin/syscheck_control +bin/syscheck_update +bin/ +src/addagent/manage_agents +src/agentlessd/ossec-agentlessd +src/analysisd/ossec-analysisd +src/analysisd/ossec-logtest +src/client-agent/ossec-agentd +src/logcollector/ossec-logcollector +src/monitord/ossec-monitord +src/monitord/ossec-reportd +src/os_csyslogd/ossec-csyslogd +src/os_dbd/ossec-dbd +src/os_execd/ossec-execd +src/os_maild/ossec-maild +src/remoted/ossec-remoted +src/syscheckd/ossec-syscheckd +src/util/agent_control +src/util/clear_stats +src/util/list_agents +src/util/rootcheck_control +src/util/syscheck_control +src/util/syscheck_update +src/analysisd/ossec-makelists +src/isbigendian +src/util/ossec-regex +src/util/verify-agent-conf diff --git a/.hgtags b/.hgtags new file mode 100644 index 0000000..f3a3aa6 --- /dev/null +++ b/.hgtags @@ -0,0 +1,6 @@ +08e342871614314bce5004348e0fb4afe1ca29d0 OSSEC_HIDS_0_3 +4fa9b5d98615125f4e8ef879c95978d23031a64d v_09 +5b120f348f051e599539b68e57fae94abfe42f83 v_0_8 +7550abc82f5402592a646615f02fd698686de7bd OSSEC_HIDS_0_4 +946d14c2b5ba7c21cd6eefe5f56f136df93f28a6 v1_1_0 +8b7a8120903fe0e18fcd9a29897919669c46adfc v2.5.0-beta1 diff --git a/BUGS b/BUGS index e56b3cc..9cfc42a 100755 --- a/BUGS +++ b/BUGS @@ -1,5 +1,5 @@ -OSSEC v2.3 -Copyright (C) 2009 Trend Micro Inc. +OSSEC v2.5.1 +Copyright (C) 2010 Trend Micro Inc. ** Reporting bugs ** diff --git a/CONFIG b/CONFIG index ada35a5..69a2c0a 100755 --- a/CONFIG +++ b/CONFIG @@ -1,5 +1,5 @@ -OSSEC v2.3 -Copyright (C) 2009 Trend Micro Inc. +OSSEC v2.5.1 +Copyright (C) 2010 Trend Micro Inc. = Information about OSSEC = diff --git a/CONTRIB b/CONTRIBUTORS similarity index 95% rename from CONTRIB rename to CONTRIBUTORS index a4fdee5..3f20e2a 100755 --- a/CONTRIB +++ b/CONTRIBUTORS @@ -1,4 +1,4 @@ -# @(#) $Id: CONTRIB,v 1.26 2009/11/23 18:52:44 dcid Exp $ +# @(#) $Id$ # Many thanks to everyone who contributed and helped with @@ -8,9 +8,10 @@ who helped us since our first release (0.1). -Development - Daniel B. Cid + - Jeremy Rossi + - Stephen Kreusch - Meir Michanie - Slava Semushin - - Jeremy Rossi - Ahmet Ozturk diff --git a/INSTALL b/INSTALL index 0752e89..ffbb4f8 100755 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,4 @@ -OSSEC v2.3 +OSSEC v2.5.1 Copyright (C) 2009 Trend Micro Inc. diff --git a/LICENSE b/LICENSE index 179b7ad..b20bf9c 100755 --- a/LICENSE +++ b/LICENSE @@ -1,8 +1,8 @@ - Copyright (C) 2009 Trend Micro Inc. All rights reserved. + Copyright (C) 2010 Trend Micro Inc. All rights reserved. OSSEC HIDS is a free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License (version 3) as + it under the terms of the GNU General Public License (version 2) as published by the FSF - Free Software Foundation. Note that this license applies to the source code, as well as @@ -36,677 +36,284 @@ ----------------------------------------------------------------------------- - GNU GENERAL PUBLIC LICENSE - Version 3, 29 June 2007 + GNU GENERAL PUBLIC LICENSE + Version 2, June 1991 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 1989, 1991 Free Software Foundation, Inc., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. - Preamble + Preamble - The GNU General Public License is a free, copyleft license for -software and other kinds of works. - - The licenses for most software and other practical works are designed -to take away your freedom to share and change the works. By contrast, -the GNU General Public License is intended to guarantee your freedom to -share and change all versions of a program--to make sure it remains free -software for all its users. We, the Free Software Foundation, use the -GNU General Public License for most of our software; it applies also to -any other work released this way by its authors. You can apply it to + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +License is intended to guarantee your freedom to share and change free +software--to make sure the software is free for all its users. This +General Public License applies to most of the Free Software +Foundation's software and to any other program whose authors commit to +using it. (Some other Free Software Foundation software is covered by +the GNU Lesser General Public License instead.) You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for -them if you wish), that you receive source code or can get it if you -want it, that you can change the software or use pieces of it in new -free programs, and that you know you can do these things. +this service if you wish), that you receive source code or can get it +if you want it, that you can change the software or use pieces of it +in new free programs; and that you know you can do these things. - To protect your rights, we need to prevent others from denying you -these rights or asking you to surrender the rights. Therefore, you have -certain responsibilities if you distribute copies of the software, or if -you modify it: responsibilities to respect the freedom of others. + To protect your rights, we need to make restrictions that forbid +anyone to deny you these rights or to ask you to surrender the rights. +These restrictions translate to certain responsibilities for you if you +distribute copies of the software, or if you modify it. For example, if you distribute copies of such a program, whether -gratis or for a fee, you must pass on to the recipients the same -freedoms that you received. You must make sure that they, too, receive -or can get the source code. And you must show them these terms so they -know their rights. - - Developers that use the GNU GPL protect your rights with two steps: -(1) assert copyright on the software, and (2) offer you this License -giving you legal permission to copy, distribute and/or modify it. - - For the developers' and authors' protection, the GPL clearly explains -that there is no warranty for this free software. For both users' and -authors' sake, the GPL requires that modified versions be marked as -changed, so that their problems will not be attributed erroneously to -authors of previous versions. - - Some devices are designed to deny users access to install or run -modified versions of the software inside them, although the manufacturer -can do so. This is fundamentally incompatible with the aim of -protecting users' freedom to change the software. The systematic -pattern of such abuse occurs in the area of products for individuals to -use, which is precisely where it is most unacceptable. Therefore, we -have designed this version of the GPL to prohibit the practice for those -products. If such problems arise substantially in other domains, we -stand ready to extend this provision to those domains in future versions -of the GPL, as needed to protect the freedom of users. - - Finally, every program is threatened constantly by software patents. -States should not allow patents to restrict development and use of -software on general-purpose computers, but in those that do, we wish to -avoid the special danger that patents applied to a free program could -make it effectively proprietary. To prevent this, the GPL assures that -patents cannot be used to render the program non-free. +gratis or for a fee, you must give the recipients all the rights that +you have. You must make sure that they, too, receive or can get the +source code. And you must show them these terms so they know their +rights. + + We protect your rights with two steps: (1) copyright the software, and +(2) offer you this license which gives you legal permission to copy, +distribute and/or modify the software. + + Also, for each author's protection and ours, we want to make certain +that everyone understands that there is no warranty for this free +software. If the software is modified by someone else and passed on, we +want its recipients to know that what they have is not the original, so +that any problems introduced by others will not reflect on the original +authors' reputations. + + Finally, any free program is threatened constantly by software +patents. We wish to avoid the danger that redistributors of a free +program will individually obtain patent licenses, in effect making the +program proprietary. To prevent this, we have made it clear that any +patent must be licensed for everyone's free use or not licensed at all. The precise terms and conditions for copying, distribution and modification follow. - TERMS AND CONDITIONS - - 0. Definitions. - - "This License" refers to version 3 of the GNU General Public License. - - "Copyright" also means copyright-like laws that apply to other kinds of -works, such as semiconductor masks. - - "The Program" refers to any copyrightable work licensed under this -License. Each licensee is addressed as "you". "Licensees" and -"recipients" may be individuals or organizations. - - To "modify" a work means to copy from or adapt all or part of the work -in a fashion requiring copyright permission, other than the making of an -exact copy. The resulting work is called a "modified version" of the -earlier work or a work "based on" the earlier work. - - A "covered work" means either the unmodified Program or a work based -on the Program. - - To "propagate" a work means to do anything with it that, without -permission, would make you directly or secondarily liable for -infringement under applicable copyright law, except executing it on a -computer or modifying a private copy. Propagation includes copying, -distribution (with or without modification), making available to the -public, and in some countries other activities as well. - - To "convey" a work means any kind of propagation that enables other -parties to make or receive copies. Mere interaction with a user through -a computer network, with no transfer of a copy, is not conveying. - - An interactive user interface displays "Appropriate Legal Notices" -to the extent that it includes a convenient and prominently visible -feature that (1) displays an appropriate copyright notice, and (2) -tells the user that there is no warranty for the work (except to the -extent that warranties are provided), that licensees may convey the -work under this License, and how to view a copy of this License. If -the interface presents a list of user commands or options, such as a -menu, a prominent item in the list meets this criterion. - - 1. Source Code. - - The "source code" for a work means the preferred form of the work -for making modifications to it. "Object code" means any non-source -form of a work. - - A "Standard Interface" means an interface that either is an official -standard defined by a recognized standards body, or, in the case of -interfaces specified for a particular programming language, one that -is widely used among developers working in that language. - - The "System Libraries" of an executable work include anything, other -than the work as a whole, that (a) is included in the normal form of -packaging a Major Component, but which is not part of that Major -Component, and (b) serves only to enable use of the work with that -Major Component, or to implement a Standard Interface for which an -implementation is available to the public in source code form. A -"Major Component", in this context, means a major essential component -(kernel, window system, and so on) of the specific operating system -(if any) on which the executable work runs, or a compiler used to -produce the work, or an object code interpreter used to run it. - - The "Corresponding Source" for a work in object code form means all -the source code needed to generate, install, and (for an executable -work) run the object code and to modify the work, including scripts to -control those activities. However, it does not include the work's -System Libraries, or general-purpose tools or generally available free -programs which are used unmodified in performing those activities but -which are not part of the work. For example, Corresponding Source -includes interface definition files associated with source files for -the work, and the source code for shared libraries and dynamically -linked subprograms that the work is specifically designed to require, -such as by intimate data communication or control flow between those -subprograms and other parts of the work. - - The Corresponding Source need not include anything that users -can regenerate automatically from other parts of the Corresponding -Source. - - The Corresponding Source for a work in source code form is that -same work. - - 2. Basic Permissions. - - All rights granted under this License are granted for the term of -copyright on the Program, and are irrevocable provided the stated -conditions are met. This License explicitly affirms your unlimited -permission to run the unmodified Program. The output from running a -covered work is covered by this License only if the output, given its -content, constitutes a covered work. This License acknowledges your -rights of fair use or other equivalent, as provided by copyright law. - - You may make, run and propagate covered works that you do not -convey, without conditions so long as your license otherwise remains -in force. You may convey covered works to others for the sole purpose -of having them make modifications exclusively for you, or provide you -with facilities for running those works, provided that you comply with -the terms of this License in conveying all material for which you do -not control copyright. Those thus making or running the covered works -for you must do so exclusively on your behalf, under your direction -and control, on terms that prohibit them from making any copies of -your copyrighted material outside their relationship with you. - - Conveying under any other circumstances is permitted solely under -the conditions stated below. Sublicensing is not allowed; section 10 -makes it unnecessary. - - 3. Protecting Users' Legal Rights From Anti-Circumvention Law. - - No covered work shall be deemed part of an effective technological -measure under any applicable law fulfilling obligations under article -11 of the WIPO copyright treaty adopted on 20 December 1996, or -similar laws prohibiting or restricting circumvention of such -measures. - - When you convey a covered work, you waive any legal power to forbid -circumvention of technological measures to the extent such circumvention -is effected by exercising rights under this License with respect to -the covered work, and you disclaim any intention to limit operation or -modification of the work as a means of enforcing, against the work's -users, your or third parties' legal rights to forbid circumvention of -technological measures. - - 4. Conveying Verbatim Copies. - - You may convey verbatim copies of the Program's source code as you -receive it, in any medium, provided that you conspicuously and -appropriately publish on each copy an appropriate copyright notice; -keep intact all notices stating that this License and any -non-permissive terms added in accord with section 7 apply to the code; -keep intact all notices of the absence of any warranty; and give all -recipients a copy of this License along with the Program. - - You may charge any price or no price for each copy that you convey, -and you may offer support or warranty protection for a fee. - - 5. Conveying Modified Source Versions. - - You may convey a work based on the Program, or the modifications to -produce it from the Program, in the form of source code under the -terms of section 4, provided that you also meet all of these conditions: - - a) The work must carry prominent notices stating that you modified - it, and giving a relevant date. - - b) The work must carry prominent notices stating that it is - released under this License and any conditions added under section - 7. This requirement modifies the requirement in section 4 to - "keep intact all notices". - - c) You must license the entire work, as a whole, under this - License to anyone who comes into possession of a copy. This - License will therefore apply, along with any applicable section 7 - additional terms, to the whole of the work, and all its parts, - regardless of how they are packaged. This License gives no - permission to license the work in any other way, but it does not - invalidate such permission if you have separately received it. - - d) If the work has interactive user interfaces, each must display - Appropriate Legal Notices; however, if the Program has interactive - interfaces that do not display Appropriate Legal Notices, your - work need not make them do so. - - A compilation of a covered work with other separate and independent -works, which are not by their nature extensions of the covered work, -and which are not combined with it such as to form a larger program, -in or on a volume of a storage or distribution medium, is called an -"aggregate" if the compilation and its resulting copyright are not -used to limit the access or legal rights of the compilation's users -beyond what the individual works permit. Inclusion of a covered work -in an aggregate does not cause this License to apply to the other -parts of the aggregate. - - 6. Conveying Non-Source Forms. - - You may convey a covered work in object code form under the terms -of sections 4 and 5, provided that you also convey the -machine-readable Corresponding Source under the terms of this License, -in one of these ways: - - a) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by the - Corresponding Source fixed on a durable physical medium - customarily used for software interchange. - - b) Convey the object code in, or embodied in, a physical product - (including a physical distribution medium), accompanied by a - written offer, valid for at least three years and valid for as - long as you offer spare parts or customer support for that product - model, to give anyone who possesses the object code either (1) a - copy of the Corresponding Source for all the software in the - product that is covered by this License, on a durable physical - medium customarily used for software interchange, for a price no - more than your reasonable cost of physically performing this - conveying of source, or (2) access to copy the - Corresponding Source from a network server at no charge. - - c) Convey individual copies of the object code with a copy of the - written offer to provide the Corresponding Source. This - alternative is allowed only occasionally and noncommercially, and - only if you received the object code with such an offer, in accord - with subsection 6b. - - d) Convey the object code by offering access from a designated - place (gratis or for a charge), and offer equivalent access to the - Corresponding Source in the same way through the same place at no - further charge. You need not require recipients to copy the - Corresponding Source along with the object code. If the place to - copy the object code is a network server, the Corresponding Source - may be on a different server (operated by you or a third party) - that supports equivalent copying facilities, provided you maintain - clear directions next to the object code saying where to find the - Corresponding Source. Regardless of what server hosts the - Corresponding Source, you remain obligated to ensure that it is - available for as long as needed to satisfy these requirements. - - e) Convey the object code using peer-to-peer transmission, provided - you inform other peers where the object code and Corresponding - Source of the work are being offered to the general public at no - charge under subsection 6d. - - A separable portion of the object code, whose source code is excluded -from the Corresponding Source as a System Library, need not be -included in conveying the object code work. - - A "User Product" is either (1) a "consumer product", which means any -tangible personal property which is normally used for personal, family, -or household purposes, or (2) anything designed or sold for incorporation -into a dwelling. In determining whether a product is a consumer product, -doubtful cases shall be resolved in favor of coverage. For a particular -product received by a particular user, "normally used" refers to a -typical or common use of that class of product, regardless of the status -of the particular user or of the way in which the particular user -actually uses, or expects or is expected to use, the product. A product -is a consumer product regardless of whether the product has substantial -commercial, industrial or non-consumer uses, unless such uses represent -the only significant mode of use of the product. - - "Installation Information" for a User Product means any methods, -procedures, authorization keys, or other information required to install -and execute modified versions of a covered work in that User Product from -a modified version of its Corresponding Source. The information must -suffice to ensure that the continued functioning of the modified object -code is in no case prevented or interfered with solely because -modification has been made. - - If you convey an object code work under this section in, or with, or -specifically for use in, a User Product, and the conveying occurs as -part of a transaction in which the right of possession and use of the -User Product is transferred to the recipient in perpetuity or for a -fixed term (regardless of how the transaction is characterized), the -Corresponding Source conveyed under this section must be accompanied -by the Installation Information. But this requirement does not apply -if neither you nor any third party retains the ability to install -modified object code on the User Product (for example, the work has -been installed in ROM). - - The requirement to provide Installation Information does not include a -requirement to continue to provide support service, warranty, or updates -for a work that has been modified or installed by the recipient, or for -the User Product in which it has been modified or installed. Access to a -network may be denied when the modification itself materially and -adversely affects the operation of the network or violates the rules and -protocols for communication across the network. - - Corresponding Source conveyed, and Installation Information provided, -in accord with this section must be in a format that is publicly -documented (and with an implementation available to the public in -source code form), and must require no special password or key for -unpacking, reading or copying. - - 7. Additional Terms. - - "Additional permissions" are terms that supplement the terms of this -License by making exceptions from one or more of its conditions. -Additional permissions that are applicable to the entire Program shall -be treated as though they were included in this License, to the extent -that they are valid under applicable law. If additional permissions -apply only to part of the Program, that part may be used separately -under those permissions, but the entire Program remains governed by -this License without regard to the additional permissions. - - When you convey a copy of a covered work, you may at your option -remove any additional permissions from that copy, or from any part of -it. (Additional permissions may be written to require their own -removal in certain cases when you modify the work.) You may place -additional permissions on material, added by you to a covered work, -for which you have or can give appropriate copyright permission. - - Notwithstanding any other provision of this License, for material you -add to a covered work, you may (if authorized by the copyright holders of -that material) supplement the terms of this License with terms: - - a) Disclaiming warranty or limiting liability differently from the - terms of sections 15 and 16 of this License; or - - b) Requiring preservation of specified reasonable legal notices or - author attributions in that material or in the Appropriate Legal - Notices displayed by works containing it; or - - c) Prohibiting misrepresentation of the origin of that material, or - requiring that modified versions of such material be marked in - reasonable ways as different from the original version; or - - d) Limiting the use for publicity purposes of names of licensors or - authors of the material; or - - e) Declining to grant rights under trademark law for use of some - trade names, trademarks, or service marks; or - - f) Requiring indemnification of licensors and authors of that - material by anyone who conveys the material (or modified versions of - it) with contractual assumptions of liability to the recipient, for - any liability that these contractual assumptions directly impose on - those licensors and authors. - - All other non-permissive additional terms are considered "further -restrictions" within the meaning of section 10. If the Program as you -received it, or any part of it, contains a notice stating that it is -governed by this License along with a term that is a further -restriction, you may remove that term. If a license document contains -a further restriction but permits relicensing or conveying under this -License, you may add to a covered work material governed by the terms -of that license document, provided that the further restriction does -not survive such relicensing or conveying. - - If you add terms to a covered work in accord with this section, you -must place, in the relevant source files, a statement of the -additional terms that apply to those files, or a notice indicating -where to find the applicable terms. - - Additional terms, permissive or non-permissive, may be stated in the -form of a separately written license, or stated as exceptions; -the above requirements apply either way. - - 8. Termination. - - You may not propagate or modify a covered work except as expressly -provided under this License. Any attempt otherwise to propagate or -modify it is void, and will automatically terminate your rights under -this License (including any patent licenses granted under the third -paragraph of section 11). - - However, if you cease all violation of this License, then your -license from a particular copyright holder is reinstated (a) -provisionally, unless and until the copyright holder explicitly and -finally terminates your license, and (b) permanently, if the copyright -holder fails to notify you of the violation by some reasonable means -prior to 60 days after the cessation. - - Moreover, your license from a particular copyright holder is -reinstated permanently if the copyright holder notifies you of the -violation by some reasonable means, this is the first time you have -received notice of violation of this License (for any work) from that -copyright holder, and you cure the violation prior to 30 days after -your receipt of the notice. - - Termination of your rights under this section does not terminate the -licenses of parties who have received copies or rights from you under -this License. If your rights have been terminated and not permanently -reinstated, you do not qualify to receive new licenses for the same -material under section 10. - - 9. Acceptance Not Required for Having Copies. - - You are not required to accept this License in order to receive or -run a copy of the Program. Ancillary propagation of a covered work -occurring solely as a consequence of using peer-to-peer transmission -to receive a copy likewise does not require acceptance. However, -nothing other than this License grants you permission to propagate or -modify any covered work. These actions infringe copyright if you do -not accept this License. Therefore, by modifying or propagating a -covered work, you indicate your acceptance of this License to do so. - - 10. Automatic Licensing of Downstream Recipients. - - Each time you convey a covered work, the recipient automatically -receives a license from the original licensors, to run, modify and -propagate that work, subject to this License. You are not responsible -for enforcing compliance by third parties with this License. - - An "entity transaction" is a transaction transferring control of an -organization, or substantially all assets of one, or subdividing an -organization, or merging organizations. If propagation of a covered -work results from an entity transaction, each party to that -transaction who receives a copy of the work also receives whatever -licenses to the work the party's predecessor in interest had or could -give under the previous paragraph, plus a right to possession of the -Corresponding Source of the work from the predecessor in interest, if -the predecessor has it or can get it with reasonable efforts. - - You may not impose any further restrictions on the exercise of the -rights granted or affirmed under this License. For example, you may -not impose a license fee, royalty, or other charge for exercise of -rights granted under this License, and you may not initiate litigation -(including a cross-claim or counterclaim in a lawsuit) alleging that -any patent claim is infringed by making, using, selling, offering for -sale, or importing the Program or any portion of it. - - 11. Patents. - - A "contributor" is a copyright holder who authorizes use under this -License of the Program or a work on which the Program is based. The -work thus licensed is called the contributor's "contributor version". - - A contributor's "essential patent claims" are all patent claims -owned or controlled by the contributor, whether already acquired or -hereafter acquired, that would be infringed by some manner, permitted -by this License, of making, using, or selling its contributor version, -but do not include claims that would be infringed only as a -consequence of further modification of the contributor version. For -purposes of this definition, "control" includes the right to grant -patent sublicenses in a manner consistent with the requirements of + GNU GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License applies to any program or other work which contains +a notice placed by the copyright holder saying it may be distributed +under the terms of this General Public License. The "Program", below, +refers to any such program or work, and a "work based on the Program" +means either the Program or any derivative work under copyright law: +that is to say, a work containing the Program or a portion of it, +either verbatim or with modifications and/or translated into another +language. (Hereinafter, translation is included without limitation in +the term "modification".) Each licensee is addressed as "you". + +Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running the Program is not restricted, and the output from the Program +is covered only if its contents constitute a work based on the +Program (independent of having been made by running the Program). +Whether that is true depends on what the Program does. + + 1. You may copy and distribute verbatim copies of the Program's +source code as you receive it, in any medium, provided that you +conspicuously and appropriately publish on each copy an appropriate +copyright notice and disclaimer of warranty; keep intact all the +notices that refer to this License and to the absence of any warranty; +and give any other recipients of the Program a copy of this License +along with the Program. + +You may charge a fee for the physical act of transferring a copy, and +you may at your option offer warranty protection in exchange for a fee. + + 2. You may modify your copy or copies of the Program or any portion +of it, thus forming a work based on the Program, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) You must cause the modified files to carry prominent notices + stating that you changed the files and the date of any change. + + b) You must cause any work that you distribute or publish, that in + whole or in part contains or is derived from the Program or any + part thereof, to be licensed as a whole at no charge to all third + parties under the terms of this License. + + c) If the modified program normally reads commands interactively + when run, you must cause it, when started running for such + interactive use in the most ordinary way, to print or display an + announcement including an appropriate copyright notice and a + notice that there is no warranty (or else, saying that you provide + a warranty) and that users may redistribute the program under + these conditions, and telling the user how to view a copy of this + License. (Exception: if the Program itself is interactive but + does not normally print such an announcement, your work based on + the Program is not required to print an announcement.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Program, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Program, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Program. + +In addition, mere aggregation of another work not based on the Program +with the Program (or with a work based on the Program) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may copy and distribute the Program (or a work based on it, +under Section 2) in object code or executable form under the terms of +Sections 1 and 2 above provided that you also do one of the following: + + a) Accompany it with the complete corresponding machine-readable + source code, which must be distributed under the terms of Sections + 1 and 2 above on a medium customarily used for software interchange; or, + + b) Accompany it with a written offer, valid for at least three + years, to give any third party, for a charge no more than your + cost of physically performing source distribution, a complete + machine-readable copy of the corresponding source code, to be + distributed under the terms of Sections 1 and 2 above on a medium + customarily used for software interchange; or, + + c) Accompany it with the information you received as to the offer + to distribute corresponding source code. (This alternative is + allowed only for noncommercial distribution and only if you + received the program in object code or executable form with such + an offer, in accord with Subsection b above.) + +The source code for a work means the preferred form of the work for +making modifications to it. For an executable work, complete source +code means all the source code for all modules it contains, plus any +associated interface definition files, plus the scripts used to +control compilation and installation of the executable. However, as a +special exception, the source code distributed need not include +anything that is normally distributed (in either source or binary +form) with the major components (compiler, kernel, and so on) of the +operating system on which the executable runs, unless that component +itself accompanies the executable. + +If distribution of executable or object code is made by offering +access to copy from a designated place, then offering equivalent +access to copy the source code from the same place counts as +distribution of the source code, even though third parties are not +compelled to copy the source along with the object code. + + 4. You may not copy, modify, sublicense, or distribute the Program +except as expressly provided under this License. Any attempt +otherwise to copy, modify, sublicense or distribute the Program is +void, and will automatically terminate your rights under this License. +However, parties who have received copies, or rights, from you under +this License will not have their licenses terminated so long as such +parties remain in full compliance. + + 5. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Program or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Program (or any work based on the +Program), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Program or works based on it. + + 6. Each time you redistribute the Program (or any work based on the +Program), the recipient automatically receives a license from the +original licensor to copy, distribute or modify the Program subject to +these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties to this License. - Each contributor grants you a non-exclusive, worldwide, royalty-free -patent license under the contributor's essential patent claims, to -make, use, sell, offer for sale, import and otherwise run, modify and -propagate the contents of its contributor version. - - In the following three paragraphs, a "patent license" is any express -agreement or commitment, however denominated, not to enforce a patent -(such as an express permission to practice a patent or covenant not to -sue for patent infringement). To "grant" such a patent license to a -party means to make such an agreement or commitment not to enforce a -patent against the party. - - If you convey a covered work, knowingly relying on a patent license, -and the Corresponding Source of the work is not available for anyone -to copy, free of charge and under the terms of this License, through a -publicly available network server or other readily accessible means, -then you must either (1) cause the Corresponding Source to be so -available, or (2) arrange to deprive yourself of the benefit of the -patent license for this particular work, or (3) arrange, in a manner -consistent with the requirements of this License, to extend the patent -license to downstream recipients. "Knowingly relying" means you have -actual knowledge that, but for the patent license, your conveying the -covered work in a country, or your recipient's use of the covered work -in a country, would infringe one or more identifiable patents in that -country that you have reason to believe are valid. - - If, pursuant to or in connection with a single transaction or -arrangement, you convey, or propagate by procuring conveyance of, a -covered work, and grant a patent license to some of the parties -receiving the covered work authorizing them to use, propagate, modify -or convey a specific copy of the covered work, then the patent license -you grant is automatically extended to all recipients of the covered -work and works based on it. - - A patent license is "discriminatory" if it does not include within -the scope of its coverage, prohibits the exercise of, or is -conditioned on the non-exercise of one or more of the rights that are -specifically granted under this License. You may not convey a covered -work if you are a party to an arrangement with a third party that is -in the business of distributing software, under which you make payment -to the third party based on the extent of your activity of conveying -the work, and under which the third party grants, to any of the -parties who would receive the covered work from you, a discriminatory -patent license (a) in connection with copies of the covered work -conveyed by you (or copies made from those copies), or (b) primarily -for and in connection with specific products or compilations that -contain the covered work, unless you entered into that arrangement, -or that patent license was granted, prior to 28 March 2007. - - Nothing in this License shall be construed as excluding or limiting -any implied license or other defenses to infringement that may -otherwise be available to you under applicable patent law. - - 12. No Surrender of Others' Freedom. - - If conditions are imposed on you (whether by court order, agreement or + 7. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot convey a -covered work so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you may -not convey it at all. For example, if you agree to terms that obligate you -to collect a royalty for further conveying from those to whom you convey -the Program, the only way you could satisfy both those terms and this -License would be to refrain entirely from conveying the Program. - - 13. Use with the GNU Affero General Public License. - - Notwithstanding any other provision of this License, you have -permission to link or combine any covered work with a work licensed -under version 3 of the GNU Affero General Public License into a single -combined work, and to convey the resulting work. The terms of this -License will continue to apply to the part which is the covered work, -but the special requirements of the GNU Affero General Public License, -section 13, concerning interaction through a network will apply to the -combination as such. - - 14. Revised Versions of this License. - - The Free Software Foundation may publish revised and/or new versions of -the GNU General Public License from time to time. Such new versions will +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Program at all. For example, if a patent +license would not permit royalty-free redistribution of the Program by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Program. + +If any portion of this section is held invalid or unenforceable under +any particular circumstance, the balance of the section is intended to +apply and the section as a whole is intended to apply in other +circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system, which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 8. If the distribution and/or use of the Program is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Program under this License +may add an explicit geographical distribution limitation excluding +those countries, so that distribution is permitted only in or among +countries not thus excluded. In such case, this License incorporates +the limitation as if written in the body of this License. + + 9. The Free Software Foundation may publish revised and/or new versions +of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. - Each version is given a distinguishing version number. If the -Program specifies that a certain numbered version of the GNU General -Public License "or any later version" applies to it, you have the -option of following the terms and conditions either of that numbered -version or of any later version published by the Free Software -Foundation. If the Program does not specify a version number of the -GNU General Public License, you may choose any version ever published -by the Free Software Foundation. - - If the Program specifies that a proxy can decide which future -versions of the GNU General Public License can be used, that proxy's -public statement of acceptance of a version permanently authorizes you -to choose that version for the Program. - - Later license versions may give you additional or different -permissions. However, no additional obligations are imposed on any -author or copyright holder as a result of your choosing to follow a -later version. - - 15. Disclaimer of Warranty. - - THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY -APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT -HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY -OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, -THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM -IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF -ALL NECESSARY SERVICING, REPAIR OR CORRECTION. - - 16. Limitation of Liability. - - IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS -THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY -GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE -USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF -DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD -PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), -EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF -SUCH DAMAGES. - - 17. Interpretation of Sections 15 and 16. - - If the disclaimer of warranty and limitation of liability provided -above cannot be given local legal effect according to their terms, -reviewing courts shall apply local law that most closely approximates -an absolute waiver of all civil liability in connection with the -Program, unless a warranty or assumption of liability accompanies a -copy of the Program in return for a fee. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -state the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - - Copyright (C) - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program. If not, see . - -Also add information on how to contact you by electronic and paper mail. - - If the program does terminal interaction, make it output a short -notice like this when it starts in an interactive mode: - - Copyright (C) - This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, your program's commands -might be different; for a GUI interface, you would use an "about box". - - You should also get your employer (if you work as a programmer) or school, -if any, to sign a "copyright disclaimer" for the program, if necessary. -For more information on this, and how to apply and follow the GNU GPL, see -. - - The GNU General Public License does not permit incorporating your program -into proprietary programs. If your program is a subroutine library, you -may consider it more useful to permit linking proprietary applications with -the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. But first, please read -. +Each version is given a distinguishing version number. If the Program +specifies a version number of this License which applies to it and "any +later version", you have the option of following the terms and conditions +either of that version or of any later version published by the Free +Software Foundation. If the Program does not specify a version number of +this License, you may choose any version ever published by the Free Software +Foundation. + + 10. If you wish to incorporate parts of the Program into other free +programs whose distribution conditions are different, write to the author +to ask for permission. For software which is copyrighted by the Free +Software Foundation, write to the Free Software Foundation; we sometimes +make exceptions for this. Our decision will be guided by the two goals +of preserving the free status of all derivatives of our free software and +of promoting the sharing and reuse of software generally. + + NO WARRANTY + + 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY +FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN +OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES +PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED +OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF +MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS +TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE +PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, +REPAIR OR CORRECTION. + + 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR +REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, +INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING +OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED +TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY +YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER +PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE +POSSIBILITY OF SUCH DAMAGES. + + END OF TERMS AND CONDITIONS + diff --git a/README b/README index 039389a..2d643ec 100755 --- a/README +++ b/README @@ -1,5 +1,5 @@ -OSSEC v2.3 -Copyright (C) 2009 Trend Micro Inc. +OSSEC v2.5.1 +Copyright (C) 2010 Trend Micro Inc. = Information about OSSEC = diff --git a/active-response/firewall-drop.sh b/active-response/firewall-drop.sh index 6d726a2..65b1dbd 100755 --- a/active-response/firewall-drop.sh +++ b/active-response/firewall-drop.sh @@ -13,6 +13,9 @@ ECHO="/bin/echo" GREP="/bin/grep" IPTABLES="/sbin/iptables" IPFILTER="/sbin/ipf" +if [ "X$UNAME" = "XSunOS" ]; then + IPFILTER="/usr/sbin/ipf" +fi GENFILT="/usr/sbin/genfilt" LSFILT="/usr/sbin/lsfilt" MKFILT="/usr/sbin/mkfilt" diff --git a/active-response/win/netsh.cmd b/active-response/win/netsh.cmd new file mode 100644 index 0000000..66cc27d --- /dev/null +++ b/active-response/win/netsh.cmd @@ -0,0 +1,33 @@ +:: Simple script to block an ip using netsh. Commands from http://windowsnerd.com/ +@ECHO OFF +ECHO. + + +:: Logging it all +FOR /F "TOKENS=1* DELIMS= " %%A IN ('DATE/T') DO SET DATE=%%B +FOR /F "TOKENS=1* DELIMS= " %%A IN ('TIME/T') DO SET TIME=%%A +ECHO %DATE% %TIME% %0 %1 %2 %3 %4 %5 %6 %7 %8 %9 >> active-response/active-responses.log + + +IF "%1"=="add" GOTO ADD +IF "%1"=="delete" GOTO DEL +:ERROR + +ECHO "Invalid argument. %1" +GOTO Exit; + + +:: Adding to the blocked. + +:ADD +:: Extracts last ip address from ipconfig. +netsh ipsec static add policy description="ossec block list" +netsh ipsec static add filter filterlist="ossecfilter" srcaddr=%3 dstaddr=me protocol=tcp mirrored=yes +netsh ipsec static add rule policy="ossec" filterlist="ossecfilter" filteraction="block" desc="list of blocked ips" +netsh ipsec static set policy assign=y +GOTO Exit; + +:DEL +netsh ipsec static delete filter filterlist="ossecfilter" srcaddr=%3 dstaddr=me protocol=tcp mirrored=yes + +:Exit diff --git a/active-response/win/route-null.cmd b/active-response/win/route-null.cmd index ffacc29..3960e31 100644 --- a/active-response/win/route-null.cmd +++ b/active-response/win/route-null.cmd @@ -21,7 +21,7 @@ GOTO Exit; :ADD :: Extracts last ip address from ipconfig. -FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG /ALL ^| FIND "IP Address"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B +FOR /F "TOKENS=2* DELIMS=:" %%A IN ('IPCONFIG ^| FIND "IP"') DO FOR %%B IN (%%A) DO SET IPADDR=%%B route add %3 mask 255.255.255.255 %IPADDR% GOTO Exit; diff --git a/contrib/ossec-batch-manager.pl b/contrib/ossec-batch-manager.pl index dbd5988..6564298 100755 --- a/contrib/ossec-batch-manager.pl +++ b/contrib/ossec-batch-manager.pl @@ -12,7 +12,7 @@ # # # ########################################################## -#$Id: ossec-batch-manager.pl,v 1.4 2007/11/05 21:05:39 jeff Exp $ +#$Id$ # TODO: # - Add check for ossec 1.4 and support longer agent names # - Add in eval so that older version of perl without @@ -185,7 +185,7 @@ sub extract_key { my ($id, $name, $ip, $key) = split; if ($id == $extractid) { # Newlines are valid base64 characters so use '' instead for \n - $decoded = MIME::Base64::encode($key, ''); + $decoded = MIME::Base64::encode($_, ''); print "$decoded\n"; exit 0; } diff --git a/contrib/ossec-testing/runtests.py b/contrib/ossec-testing/runtests.py new file mode 100644 index 0000000..3508e9d --- /dev/null +++ b/contrib/ossec-testing/runtests.py @@ -0,0 +1,81 @@ +import ConfigParser +import subprocess +import os +import sys +import os.path + +class OssecTester(object): + def __init__(self): + self._debug = False + self._quiet = False + self._ossec_conf = "/var/ossec/etc/ossec.conf" + self._base_dir = "/var/ossec/" + self._ossec_path = "/var/ossec/bin/" + self._test_path = "./tests" + + def buildCmd(self, rule, alert, decoder): + cmd = ['%s/ossec-logtest'%(self._ossec_path),] + if self._ossec_conf: cmd += ["-c",self._ossec_conf] + if self._base_dir: cmd += ["-D", self._base_dir] + cmd += ['-U', "%s:%s:%s"%(rule,alert,decoder)] + return cmd + + def runTest(self, log, rule, alert, decoder, section, name, negate=False): + print self.buildCmd(rule, alert, decoder) + p = subprocess.Popen(self.buildCmd(rule, alert, decoder), + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + stdin=subprocess.PIPE, + shell=False) + std_out = p.communicate(log)[0] + if (p.returncode != 0 and not negate) or (p.returncode == 0 and negate): + print "" + print "-" * 60 + print "Failed: Exit code = %s"%(p.returncode) + print " Alert = %s"%(alert) + print " Rule = %s"%(rule) + print " Decoder = %s"%(decoder) + print " Section = %s"%(section) + print " line name = %s"%(name) + print " " + print std_out + elif self._debug: + print "Exit code= %s"%(p.returncode) + print std_out + else: + sys.stdout.write(".") + + def run(self): + for aFile in os.listdir(self._test_path): + aFile = os.path.join(self._test_path, aFile) + print "- [ File = %s ] ---------"%(aFile) + if aFile.endswith(".ini"): + tGroup = ConfigParser.ConfigParser() + tGroup.read([aFile]) + tSections = tGroup.sections() + for t in tSections: + rule = tGroup.get(t, "rule") + alert = tGroup.get(t, "alert") + decoder = tGroup.get(t, "decoder") + for (name, value) in tGroup.items(t): + if name.startswith("log "): + if self._debug: + print "-"* 60 + if name.endswith("pass"): + neg = False + elif name.endswith("fail"): + neg = True + else: + neg = False + self.runTest(value, rule, alert, decoder, t, name, negate=neg) + print "" + +if __name__ == "__main__": + OT = OssecTester() + OT.run() + + + + + + diff --git a/contrib/ossec-testing/tests/named.ini b/contrib/ossec-testing/tests/named.ini new file mode 100644 index 0000000..591897d --- /dev/null +++ b/contrib/ossec-testing/tests/named.ini @@ -0,0 +1,10 @@ +[Query cache denied] +log 1 pass = Aug 29 15:33:13 ns3 named[464]: client 217.148.39.3#1036: query (cache) denied +log 2 pass = Aug 29 15:33:13 ns3 named[464]: client 217.148.39.4#32769: query (cache) denied +log 3 pass = Aug 29 15:33:13 ns3 named[464]: client 217.148.39.3#1036: query (cache) denied +log 4 fail = Aug 29 15:33:13 ns3 name[464]: client 217.148.39.4#32769: query (cache) denied +log 5 pass = Aug 29 15:33:13 ns3 named[464]: client 217.148.39.3#1036: query (cache) + +rule = 12108 +alert = 4 +decoder = named diff --git a/contrib/ossec2mysql.pl b/contrib/ossec2mysql.pl index 17acb4c..ddf3571 100755 --- a/contrib/ossec2mysql.pl +++ b/contrib/ossec2mysql.pl @@ -5,7 +5,7 @@ use strict; # --------------------------------------------------------------------------- # Author: Meir Michanie (meirm@riunx.com) # Co-Author: J.A.Senger (jorge@br10.com.br) -# $Id: ossec2mysql.pl,v 1.13 2007/09/05 00:38:26 dcid Exp $ +# $Id$ # --------------------------------------------------------------------------- # http://www.riunx.com/ # --------------------------------------------------------------------------- diff --git a/contrib/ossec2mysqld.pl b/contrib/ossec2mysqld.pl index c2b61c7..1d966e0 100755 --- a/contrib/ossec2mysqld.pl +++ b/contrib/ossec2mysqld.pl @@ -5,8 +5,8 @@ use POSIX 'setsid'; # --------------------------------------------------------------------------- # Author: Meir Michanie (meirm@riunx.com) # Co-Author: J.A.Senger (jorge@br10.com.br) -# $Id: ossec2mysqld.pl,v 1.11 2007/09/05 00:38:26 dcid Exp $ -# $Revision: 1.11 $ +# $Id$ +# $Revision$ ## --------------------------------------------------------------------------- # http://www.riunx.com/ # --------------------------------------------------------------------------- diff --git a/etc/decoder.xml b/etc/decoder.xml index c809108..cb07a93 100755 --- a/etc/decoder.xml +++ b/etc/decoder.xml @@ -1,4 +1,4 @@ - + + ^rshd$ + + + + rshd + ^Connection from (\S+) on illegal port$ + srcip + + + + + + + ^cimserver$ + + + + cimserver + ^\w+: Authentication failed for user + ^(\S+).$ + user + + + + + ^ftpd|^in.ftpd @@ -415,6 +459,13 @@ srcip + + ftpd + ^login \S+ from \S+ failed. + ^login (\S+) from (\S+) failed.$ + user, srcip + + windows - ^MSWinEventLog\t\d\t\.+\t\d+\t\w\w\w \w\w\w \d\d \d\d + ^MSWinEventLog\t\d\t\.+\t\d+\t\w\w\S+ \w\w\w \d\d \d\d ^:\d\d:\d\d \d\d\d\d\t(\d+)\t(\.+) \t(\.+)\t\.+\t(\.+)\t(\.+)\t id, extra_data, user, status, system_name diff --git a/etc/ossec-local.conf b/etc/ossec-local.conf index 1816a69..f800f48 100755 --- a/etc/ossec-local.conf +++ b/etc/ossec-local.conf @@ -10,27 +10,67 @@ rules_config.xml + pam_rules.xml sshd_rules.xml + telnetd_rules.xml syslog_rules.xml + arpwatch_rules.xml + symantec-av_rules.xml + symantec-ws_rules.xml pix_rules.xml named_rules.xml + smbd_rules.xml + vsftpd_rules.xml pure-ftpd_rules.xml proftpd_rules.xml + ms_ftpd_rules.xml + ftpd_rules.xml + hordeimp_rules.xml + roundcube_rules.xml + wordpress_rules.xml + cimserver_rules.xml + vpopmail_rules.xml + vmpop3d_rules.xml + courier_rules.xml web_rules.xml apache_rules.xml + nginx_rules.xml + php_rules.xml + mysql_rules.xml + postgresql_rules.xml ids_rules.xml squid_rules.xml firewall_rules.xml + cisco-ios_rules.xml + netscreenfw_rules.xml + sonicwall_rules.xml postfix_rules.xml sendmail_rules.xml + imapd_rules.xml + mailscanner_rules.xml + dovecot_rules.xml + ms-exchange_rules.xml + racoon_rules.xml + vpn_concentrator_rules.xml spamd_rules.xml msauth_rules.xml + mcafee_av_rules.xml + trend-osce_rules.xml + ms-se_rules.xml + + zeus_rules.xml + solaris_bsm_rules.xml + vmware_rules.xml + ms_dhcp_rules.xml + asterisk_rules.xml + ossec_rules.xml attack_rules.xml - + local_rules.xml + - - 7200 + + 17200 /etc,/usr/bin,/usr/sbin diff --git a/etc/ossec-server.conf b/etc/ossec-server.conf index 6b67971..4703df8 100755 --- a/etc/ossec-server.conf +++ b/etc/ossec-server.conf @@ -10,27 +10,68 @@ rules_config.xml + pam_rules.xml sshd_rules.xml + telnetd_rules.xml syslog_rules.xml + arpwatch_rules.xml + symantec-av_rules.xml + symantec-ws_rules.xml pix_rules.xml named_rules.xml + smbd_rules.xml + vsftpd_rules.xml pure-ftpd_rules.xml proftpd_rules.xml + ms_ftpd_rules.xml + ftpd_rules.xml + hordeimp_rules.xml + roundcube_rules.xml + wordpress_rules.xml + cimserver_rules.xml + vpopmail_rules.xml + vmpop3d_rules.xml + courier_rules.xml web_rules.xml apache_rules.xml + nginx_rules.xml + php_rules.xml + mysql_rules.xml + postgresql_rules.xml ids_rules.xml squid_rules.xml firewall_rules.xml + cisco-ios_rules.xml + netscreenfw_rules.xml + sonicwall_rules.xml postfix_rules.xml sendmail_rules.xml + imapd_rules.xml + mailscanner_rules.xml + dovecot_rules.xml + ms-exchange_rules.xml + racoon_rules.xml + vpn_concentrator_rules.xml spamd_rules.xml msauth_rules.xml + mcafee_av_rules.xml + trend-osce_rules.xml + ms-se_rules.xml + + zeus_rules.xml + solaris_bsm_rules.xml + vmware_rules.xml + ms_dhcp_rules.xml + asterisk_rules.xml + ossec_rules.xml attack_rules.xml - + local_rules.xml + + - - 7200 + + 72000 /etc,/usr/bin,/usr/sbin diff --git a/etc/rules/apache_rules.xml b/etc/rules/apache_rules.xml index 1a723dc..f823886 100755 --- a/etc/rules/apache_rules.xml +++ b/etc/rules/apache_rules.xml @@ -1,4 +1,4 @@ - diff --git a/etc/rules/cimserver_rules.xml b/etc/rules/cimserver_rules.xml new file mode 100755 index 0000000..0cc1dde --- /dev/null +++ b/etc/rules/cimserver_rules.xml @@ -0,0 +1,35 @@ + + + + + cimserver + cimserver messages grouped. + + + + 9600 + Authentication failed + Compaq Insight Manager authentication failure. + authentication_failed, + + + + 9600 + Server stopped + Compaq Insight Manager stopped. + service_availability, + + + + diff --git a/etc/rules/cisco-ios_rules.xml b/etc/rules/cisco-ios_rules.xml index bbb9993..f30074c 100755 --- a/etc/rules/cisco-ios_rules.xml +++ b/etc/rules/cisco-ios_rules.xml @@ -1,4 +1,4 @@ - diff --git a/etc/rules/hordeimp_rules.xml b/etc/rules/hordeimp_rules.xml index cbefa50..a6c2555 100755 --- a/etc/rules/hordeimp_rules.xml +++ b/etc/rules/hordeimp_rules.xml @@ -1,4 +1,4 @@ - + + + + + + + windows + ^Microsoft Antimalware + Grouping of Microsoft Security Essentials rules. + + + + 7701 + ^1008$ + virus + Microsoft Security Essentials - Virus detected, but unable to remove. + + + + 7701 + ^1007$ + virus + Microsoft Security Essentials - Virus detected and properly removed. + + + + 7701 + ^1015$|^1006$ + virus + Microsoft Security Essentials - Virus detected. + + + + 7701 + ^5007$ + Microsoft Security Essentials - Configuration changed. + policy_changed, + + + + 7711, 7712 + Virus:DOS/EICAR_Test_File + alert_by_email + Microsoft Security Essentials - EICAR test file detected. + + + + + 7711 + Multiple Microsoft Security Essentials AV warnings detected. + + + + 7712 + Multiple Microsoft Security Essentials AV warnings detected. + + + + + diff --git a/etc/rules/ms_dhcp_rules.xml b/etc/rules/ms_dhcp_rules.xml index 6e25158..fee7783 100644 --- a/etc/rules/ms_dhcp_rules.xml +++ b/etc/rules/ms_dhcp_rules.xml @@ -1,5 +1,5 @@ - + ^65xxx Group account added/changed/deleted. + This rule has been deprecated account_changed, @@ -198,7 +203,7 @@ 18106 ^529 Logon Failure - Unknown user or bad password. - http://www.ultimatewindowssecurity.com/events/com190.html + http://www.ultimatewindowssecurity.com/events/com190.html win_authentication_failed, @@ -207,7 +212,7 @@ ^530 Logon Failure - Account logon time restriction violation. - http://www.ultimatewindowssecurity.com/events/com191.html + http://www.ultimatewindowssecurity.com/events/com191.html win_authentication_failed,login_denied, @@ -215,7 +220,7 @@ 18106 ^531 Logon Failure - Account currently disabled. - http://www.ultimatewindowssecurity.com/events/com192.html + http://www.ultimatewindowssecurity.com/events/com192.html win_authentication_failed,login_denied, @@ -223,7 +228,7 @@ 18106 ^532 Logon Failure - Specified account expired. - http://www.ultimatewindowssecurity.com/events/com193.html + http://www.ultimatewindowssecurity.com/events/com193.html win_authentication_failed,login_denied, @@ -232,7 +237,7 @@ ^533 Logon Failure - User not allowed to login at this computer. - http://www.ultimatewindowssecurity.com/events/com194.html + http://www.ultimatewindowssecurity.com/events/com194.html win_authentication_failed,login_denied, @@ -240,7 +245,7 @@ 18106 ^534 Logon Failure - User not granted logon type. - http://www.ultimatewindowssecurity.com/events/com195.html + http://www.ultimatewindowssecurity.com/events/com195.html win_authentication_failed, @@ -248,7 +253,7 @@ 18106 ^535 Logon Failure - Account's password expired. - http://www.ultimatewindowssecurity.com/events/com196.html + http://www.ultimatewindowssecurity.com/events/com196.html win_authentication_failed, @@ -292,7 +297,7 @@ 18104 ^671|^4767 User account unlocked. - http://www.ultimatewindowssecurity.com/events/com291.html + http://www.ultimatewindowssecurity.com/events/com291.html account_changed, @@ -316,7 +321,7 @@ ^7040 policy_changed, Service startup type was changed. - This does not appear to be logged on Windows 2000. + This does not appear to be logged on Windows 2000. @@ -345,6 +350,462 @@ Windows User Logoff. + + + + 18104 + ^631$|^4727$|^635$|^4731$|^658$|^4754$|^648$|^4744$|^653$|^4749$| + ^663$|^4759$ + Group Account Created + group_created,win_group_created, + + + + 18104 + ^634$|^4730$|^638$|^4734$|^662$|^4758$|^652$|^4748$|^657$|^4753$| + ^667$|^4763$ + Group Account Deleted + group_deleted,win_group_deleted, + + + + 18200 + ^631$|^4727$ + Security Enabled Global Group Created + group_created,win_group_created, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=631 + + + + 18114 + ^632$|^4728$ + Security Enabled Global Group Member Added + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=632 + + + + 18114 + ^633$|^4729$ + Security Enabled Global Group Member Removed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=633 + + + + 18201 + ^634$|^4730$ + Security Enabled Global Group Deleted + group_deleted,win_group_deleted, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=634 + + + + 18200 + ^635$|^4731$ + Security Enabled Local Group Created + group_created,win_group_created, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=635 + + + + 18114 + ^636$|^4732$ + Security Enabled Local Group Member Added + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=636 + + + + 18114 + ^637$|^4733$ + Security Enabled Local Group Member Removed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=637 + + + + 18201 + ^638$|^4734$ + Security Enabled Local Group Deleted + group_deleted,win_group_deleted, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=638 + + + + 18114 + ^639$|^4735$ + Security Enabled Local Group Changed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=639 + + + + 18114 + ^641$|^4737$ + Security Enabled Global Group Changed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=641 + + + + 18200 + ^658$|^4754$ + Security Enabled Universal Group Created + group_created,win_group_created, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=658 + + + + 18114 + ^659$|^4755$ + Security Enabled Universal Group Changed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=659 + + + + 18114 + ^660$|^4756$ + Security Enabled Universal Group Member Added + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=660 + + + + 18114 + ^661$|^4757$ + Security Enabled Universal Group Member Removed + group_changed,win_group_changed, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=661 + + + + 18201 + ^662$|^4758$ + Security Enabled Universal Group Deleted + group_deleted,win_group_deleted, + http://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=662 + + + + 18207,18208 + ID:\s+\p*S-1-5-32-544\p* + Administrators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-1-0} + Everyone Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-9} + Enterprise Domain Controllers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-11} + Authenticated Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-13} + Terminal Server Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-512} + Domain Admins Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-513} + Domain Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18223,18203 + Target Account Name: None + Local User Group NONE + Bogus group user added to upon creation + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-514} + Domain Guests Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-515} + Domain Computers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-516} + Domain Controllers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-21\S+-517} + Cert Publishers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\.+-518} + Schema Admins Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-519} + Enterprise Admins Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18203,18204 + ID:\s+%{S-1-5-21\S+-520} + Group Policy Creator Owners Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + \w* ID:\s+%{S-1-5-21\S+-553} + RAS and IAS Servers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-545} + Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-546} + Guests Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-547} + Power Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-548} + Account Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-549} + Server Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + \w* ID:\s+%{S-1-5-32-550} + Print Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-551} + Backup Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-552} + Replicators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-554} + Pre-Windows 2000 Compatible Access Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-555} + Remote Desktop Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-556} + Network Configuration Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-557} + Incoming Forest Trust Builders Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-558} + Performance Monitor Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-559} + Performance Log Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-560} + Windows Authorization Access Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-561} + Terminal Server License Servers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-562} + Distributed COM Users Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-\s*21\.+\s*-498} + Enterprise Read-only Domain Controllers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-\s*21\.+\s*-529} + Read-only Domain Controllers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-569} + Cryptographic Operators Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-\s*21\.+\s*-571} + Allowed RODC Password Replication Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-\s*21\.+\s*-572} + Denied RODC Password Replication Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-573} + Event Log Readers Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + + + + 18207,18208 + ID:\s+%{S-1-5-32-574} + Certificate Service DCOM Access Group Changed + group_changed,win_group_changed, + http://support.microsoft.com/kb/243330 + 12100 query (cache) denied Query cache denied (maybe config error). - http://www.reedmedia.net/misc/dns/errors.html + http://www.reedmedia.net/misc/dns/errors.html diff --git a/etc/rules/netscreenfw_rules.xml b/etc/rules/netscreenfw_rules.xml index 839c917..88749c1 100755 --- a/etc/rules/netscreenfw_rules.xml +++ b/etc/rules/netscreenfw_rules.xml @@ -1,4 +1,4 @@ - @@ -152,6 +158,23 @@ + + + + rshd + rshd messages grouped. + + + + 2550 + ^Connection from \S+ on illegal port$ + Connection to rshd from unprivileged port. Possible network scan. + connection_attempt, + + + + + @@ -458,7 +481,7 @@ 9100 ^GRE: \S+ from \S+ failed: status = -1 PPTPD failed message (communication error) - poptop.sourceforge.net/dox/gre-protocol-unavailable.phtml + http://poptop.sourceforge.net/dox/gre-protocol-unavailable.phtml diff --git a/etc/rules/telnetd_rules.xml b/etc/rules/telnetd_rules.xml index 661f61a..17f2088 100755 --- a/etc/rules/telnetd_rules.xml +++ b/etc/rules/telnetd_rules.xml @@ -1,4 +1,4 @@ - - + .jpg$|.gif$|favicon.ico$|.png$|robots.txt$|.css$|.js$ + is_simple_http_request Ignored extensions on 400 error codes. @@ -52,23 +53,23 @@ - %027|%00|%01|%7f|%2E%2E|%0A|%0D|../..|..\..|echo;|.. + %027|%00|%01|%7f|%2E%2E|%0A|%0D|../..|..\..|echo;|..| cmd.exe|root.exe|_mem_bin|msadc|/winnt/| - /x90/|default.ida|/sumthin|nsiislog.dll|chmod%|wget%|cd%| - cat%|exec%|rm%20 + /x90/|default.ida|/sumthin|nsiislog.dll|chmod%|wget%|cd%20| + cat%20|exec%20|rm%20 Common web attack. attack, 31100 - %3Cscript|%2Fscript|script>|script%3E|SRC=javascript|IMG%20| + %3Cscript|%3C%2Fscript|script>|script%3E|SRC=javascript|IMG%20| %20ONLOAD=|INPUT%20|iframe%20 XSS (Cross Site Scripting) attempt. attack, - + 31103, 31104, 31105 ^200 A web attack returned code 200 (success). @@ -80,7 +81,7 @@ --> 31103, 31104, 31105 - ^/search.php?search=|^index.php?searchword= + ^/search.php?search=|^/index.php?searchword= Ignored URLs for the web attacks @@ -120,6 +121,15 @@ alert_by_email Web server 503 error code (Service unavailable). + + + + + 31101 + is_valid_crawler + Ignoring google/msn/yahoo bots. + + 31101 diff --git a/etc/rules/wordpress_rules.xml b/etc/rules/wordpress_rules.xml index 7009d3d..0561aab 100755 --- a/etc/rules/wordpress_rules.xml +++ b/etc/rules/wordpress_rules.xml @@ -1,4 +1,4 @@ - zeus_rules.xml solaris_bsm_rules.xml diff --git a/install.sh b/install.sh index 9fc0e94..a133c80 100755 --- a/install.sh +++ b/install.sh @@ -66,6 +66,8 @@ Install() echo "DIR=\"${INSTALLDIR}\"" > ${LOCATION} echo "CC=${CC}" >> ${LOCATION} + echo "GCC=${CC}" >> ${LOCATION} + echo "CLANG=clang" >> ${LOCATION} # Changing Config.OS with the new C flags # Checking if debug is enabled diff --git a/src/Config.Make b/src/Config.Make index 8fe97b7..a0e4e89 100755 --- a/src/Config.Make +++ b/src/Config.Make @@ -24,3 +24,4 @@ OS_ROOTCHECK = ${PT}rootcheck/rootcheck_lib.a OS_CONFIG = ${PT}config/lib_config.a OS_ZLIB = ${PT}os_zlib/os_zlib.c ${PT}external/libz.a OS_LINK = ${IEXTRA} +DBS = cdb/cdb.a diff --git a/src/InstallAgent.sh b/src/InstallAgent.sh index 6ee67e5..5747929 100755 --- a/src/InstallAgent.sh +++ b/src/InstallAgent.sh @@ -15,7 +15,7 @@ UNAME=`uname`; DIR=`grep DIR ${LOCATION} | cut -f2 -d\"` GROUP="ossec" USER="ossec" -subdirs="logs bin queue queue/ossec queue/alerts queue/syscheck queue/rids var var/run etc etc/shared active-response active-response/bin agentless .ssh" +subdirs="logs bin queue queue/ossec queue/alerts queue/syscheck queue/rids queue/diff var var/run etc etc/shared active-response active-response/bin agentless .ssh" # ${DIR} must be set @@ -120,6 +120,11 @@ touch ${DIR}/logs/ossec.log chown ${USER}:${GROUP} ${DIR}/logs/ossec.log chmod 664 ${DIR}/logs/ossec.log +chown -R ${USER}:${GROUP} ${DIR}/queue/diff +chmod -R 750 ${DIR}/queue/diff +chmod 740 ${DIR}/queue/diff/* > /dev/null 2>&1 + + # For the etc dir diff --git a/src/InstallServer.sh b/src/InstallServer.sh index 7393513..c9f15ff 100755 --- a/src/InstallServer.sh +++ b/src/InstallServer.sh @@ -232,6 +232,7 @@ chown root:${GROUP} ${DIR}/var/run cp -pr ../bin/ossec* ${DIR}/bin/ cp -pr ../bin/manage_agents ${DIR}/bin/ cp -pr ../bin/syscheck_update ${DIR}/bin/ +cp -pr ../bin/verify-agent-conf ${DIR}/bin/ cp -pr ../bin/clear_stats ${DIR}/bin/ cp -pr ../bin/list_agents ${DIR}/bin/ cp -pr ../bin/agent_control ${DIR}/bin/ diff --git a/src/LOCATION b/src/LOCATION index 4145da3..8a53a03 100755 --- a/src/LOCATION +++ b/src/LOCATION @@ -1,2 +1,4 @@ DIR="/var/ossec" CC=gcc +GCC=gcc +CLANG=clang diff --git a/src/Makefile b/src/Makefile index e971e17..976c594 100755 --- a/src/Makefile +++ b/src/Makefile @@ -12,9 +12,12 @@ none: @echo "\"make clean\" to clean anything built." @echo "\"make setagent\" to set agent install." @echo "\"make setlocal\" to set local install." + @echo "\"make setclang\" to use clang for building ossec." + @echo "\"make unsetclang\" to use gcc for building ossec." @echo "\"make setprelude\" to enable prelude output." @echo "\"make setdb\" to enable database support." @echo "\"make unsetdb\" to disable database support." + @echo "\"make setoneway\" to enable one-way connection to the manager." clean: @/bin/sh ./Makeall clean @@ -42,6 +45,12 @@ agent: setagent: @echo "CEXTRA=-DCLIENT" >> ./Config.OS +setclang: + @sed -i '' -e "s/^CC=.*/CC=clang/g" LOCATION + +unsetclang: + @sed -i '' -e "s/^CC=.*/CC=gcc/g" LOCATION + setprelude: @echo "CPRELUDE=-DPRELUDE -lprelude `libprelude-config --pthread-cflags` `libprelude-config --libs`" >> ./Config.OS @@ -56,3 +65,5 @@ setlocal: setfullsubject: @echo "FEXTRA=-DCLEANFULL" >> ./Config.OS +setoneway: + @echo "FEXTRA=-DONEWAY" >> ./Config.OS diff --git a/src/VERSION b/src/VERSION index e70ef1d..2c3fc41 100755 --- a/src/VERSION +++ b/src/VERSION @@ -1 +1 @@ -v2.3 +v2.5.1 diff --git a/src/addagent/b64.c b/src/addagent/b64.c index 754e891..00c0d05 100755 --- a/src/addagent/b64.c +++ b/src/addagent/b64.c @@ -1,4 +1,4 @@ -/* @(#) $Id: b64.c,v 1.2 2006/06/21 00:18:21 dcid Exp $ */ +/* @(#) $Id$ */ /* * Copyright (C), 2000-2004 by the monit project group. * All Rights Reserved. @@ -39,7 +39,7 @@ static unsigned char decode(char c); * * @author Jan-Henrik Haukeland, * - * @version \$Id: b64.c,v 1.2 2006/06/21 00:18:21 dcid Exp $ + * @version \$Id$ * * @file */ diff --git a/src/addagent/main.c b/src/addagent/main.c index 334932d..ad6b8ba 100755 --- a/src/addagent/main.c +++ b/src/addagent/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.15 2009/08/05 18:02:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/addagent/manage_agents.c b/src/addagent/manage_agents.c index f9b7ba9..504ffeb 100755 --- a/src/addagent/manage_agents.c +++ b/src/addagent/manage_agents.c @@ -1,11 +1,11 @@ -/* @(#) $Id: manage_agents.c,v 1.33 2009/08/19 18:35:57 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/addagent/manage_agents.h b/src/addagent/manage_agents.h index 54e9e97..e9ba6fc 100755 --- a/src/addagent/manage_agents.h +++ b/src/addagent/manage_agents.h @@ -1,11 +1,11 @@ -/* @(#) $Id: manage_agents.h,v 1.20 2009/08/05 18:02:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/addagent/manage_keys.c b/src/addagent/manage_keys.c index bc2bb02..8f250ff 100755 --- a/src/addagent/manage_keys.c +++ b/src/addagent/manage_keys.c @@ -1,11 +1,11 @@ -/* @(#) $Id: manage_keys.c,v 1.20 2009/08/05 18:02:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/addagent/read_from_user.c b/src/addagent/read_from_user.c index 9b84c76..13ccca5 100755 --- a/src/addagent/read_from_user.c +++ b/src/addagent/read_from_user.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_from_user.c,v 1.6 2009/06/24 17:06:20 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/addagent/validate.c b/src/addagent/validate.c index 91c48f6..344e4ee 100755 --- a/src/addagent/validate.c +++ b/src/addagent/validate.c @@ -1,11 +1,11 @@ -/* @(#) $Id: validate.c,v 1.19 2009/06/24 17:06:20 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/agentlessd/agentlessd.c b/src/agentlessd/agentlessd.c index 6e6bd2e..2db347f 100755 --- a/src/agentlessd/agentlessd.c +++ b/src/agentlessd/agentlessd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: agentlessd.c,v 1.13 2009/06/24 17:06:20 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -69,6 +69,30 @@ int send_intcheck_msg(char *script, char *host, char *msg) +/* Send generic log message. */ +int send_log_msg(char *script, char *host, char *msg) +{ + char sys_location[1024 +1]; + + sys_location[1024] = '\0'; + snprintf(sys_location, 1024, "(%s) %s->%s", script, host, SYSCHECK); + + if(SendMSG(lessdc.queue, msg, sys_location, LOCALFILE_MQ) < 0) + { + merror(QUEUE_SEND, ARGV0); + if((lessdc.queue = StartMQ(DEFAULTQPATH, WRITE)) < 0) + { + ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH); + } + + /* If we reach here, we can try to send it again */ + SendMSG(lessdc.queue, msg, sys_location, LOCALFILE_MQ); + } + return(0); +} + + + /* Generate diffs alerts. */ int gen_diff_alert(char *host, char *script, int alert_diff_time) { @@ -392,6 +416,12 @@ int run_periodic_cmd(agentlessd_entries *entry, int test_it) send_intcheck_msg(entry->type, entry->server[i]+1, tmp_str); } + else if(strncmp(buf, "LOG: ", 4) == 0) + { + tmp_str = buf + 5; + send_log_msg(entry->type, entry->server[i]+1, + tmp_str); + } else if((entry->state & LESSD_STATE_DIFF) && (strncmp(buf, "STORE: ", 7) == 0)) { diff --git a/src/agentlessd/agentlessd.h b/src/agentlessd/agentlessd.h index 3f75bb0..7fd6f2e 100755 --- a/src/agentlessd/agentlessd.h +++ b/src/agentlessd/agentlessd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: agentlessd.h,v 1.2 2009/06/24 17:06:21 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/agentlessd/main.c b/src/agentlessd/main.c index 71a3daf..f970cc5 100755 --- a/src/agentlessd/main.c +++ b/src/agentlessd/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.3 2009/11/18 19:07:39 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/agentlessd/scripts/main.exp b/src/agentlessd/scripts/main.exp index b7ea020..f8ac1f9 100755 --- a/src/agentlessd/scripts/main.exp +++ b/src/agentlessd/scripts/main.exp @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: main.exp,v 1.5 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/register_host.sh b/src/agentlessd/scripts/register_host.sh index 0984e76..edc503d 100755 --- a/src/agentlessd/scripts/register_host.sh +++ b/src/agentlessd/scripts/register_host.sh @@ -1,6 +1,6 @@ #!/bin/sh -# @(#) $Id: register_host.sh,v 1.5 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh.exp b/src/agentlessd/scripts/ssh.exp index 238e373..33bca80 100755 --- a/src/agentlessd/scripts/ssh.exp +++ b/src/agentlessd/scripts/ssh.exp @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh.exp,v 1.4 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_asa-fwsmconfig_diff b/src/agentlessd/scripts/ssh_asa-fwsmconfig_diff index 3d661c2..a62eead 100755 --- a/src/agentlessd/scripts/ssh_asa-fwsmconfig_diff +++ b/src/agentlessd/scripts/ssh_asa-fwsmconfig_diff @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_asa-fwsmconfig_diff,v 1.2 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_foundry_diff b/src/agentlessd/scripts/ssh_foundry_diff index ece1288..3b845bf 100755 --- a/src/agentlessd/scripts/ssh_foundry_diff +++ b/src/agentlessd/scripts/ssh_foundry_diff @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_foundry_diff,v 1.2 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_generic_diff b/src/agentlessd/scripts/ssh_generic_diff index d63a9af..363d031 100755 --- a/src/agentlessd/scripts/ssh_generic_diff +++ b/src/agentlessd/scripts/ssh_generic_diff @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_generic_diff,v 1.10 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_integrity_check_bsd b/src/agentlessd/scripts/ssh_integrity_check_bsd index cbda255..ee273cc 100755 --- a/src/agentlessd/scripts/ssh_integrity_check_bsd +++ b/src/agentlessd/scripts/ssh_integrity_check_bsd @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_integrity_check_bsd,v 1.10 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_integrity_check_linux b/src/agentlessd/scripts/ssh_integrity_check_linux index df69215..faa0e6d 100755 --- a/src/agentlessd/scripts/ssh_integrity_check_linux +++ b/src/agentlessd/scripts/ssh_integrity_check_linux @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_integrity_check_linux,v 1.11 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/ssh_nopass.exp b/src/agentlessd/scripts/ssh_nopass.exp index 62b7b6f..03dd300 100755 --- a/src/agentlessd/scripts/ssh_nopass.exp +++ b/src/agentlessd/scripts/ssh_nopass.exp @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_nopass.exp,v 1.3 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. expect { diff --git a/src/agentlessd/scripts/ssh_pixconfig_diff b/src/agentlessd/scripts/ssh_pixconfig_diff index 9968432..9f130c9 100755 --- a/src/agentlessd/scripts/ssh_pixconfig_diff +++ b/src/agentlessd/scripts/ssh_pixconfig_diff @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: ssh_pixconfig_diff,v 1.6 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/sshlogin.exp b/src/agentlessd/scripts/sshlogin.exp index 6335e27..e9fc839 100755 --- a/src/agentlessd/scripts/sshlogin.exp +++ b/src/agentlessd/scripts/sshlogin.exp @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: sshlogin.exp,v 1.5 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/agentlessd/scripts/su.exp b/src/agentlessd/scripts/su.exp index 7f9c0cf..7fb22e2 100755 --- a/src/agentlessd/scripts/su.exp +++ b/src/agentlessd/scripts/su.exp @@ -1,6 +1,6 @@ #!/usr/bin/env expect -# @(#) $Id: su.exp,v 1.5 2009/06/24 17:06:21 dcid Exp $ +# @(#) $Id$ # Agentless monitoring # # Copyright (C) 2009 Trend Micro Inc. @@ -8,7 +8,7 @@ # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. diff --git a/src/analysisd/Makefile b/src/analysisd/Makefile index c5a7c3f..b57bb1f 100755 --- a/src/analysisd/Makefile +++ b/src/analysisd/Makefile @@ -7,26 +7,36 @@ NAME=ossec-analysisd include ../Config.Make -LOCAL= analysisd.c stats.c rules.c rules_list.c config.c fts.c eventinfo.c eventinfo_list.c cleanevent.c active-response.c picviz.c prelude.c compiled_rules/*.o ${OS_CONFIG} +OTHER = stats.c lists.c lists_list.c rules.c rules_list.c config.c fts.c dodiff.c eventinfo.c eventinfo_list.c cleanevent.c active-response.c picviz.c prelude.c compiled_rules/*.o ${OS_CONFIG} +LOCAL = analysisd.c ${OTHER} PLUGINS = decoders/decoders.a ALERTS = alerts/alerts.a +DBS = cdb/cdb.a cdb/cdb_make.a -loga_OBJS = ${LOCAL} ${PLUGINS} ${ALERTS} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_SHARED} ${OS_ZLIB} ${CPRELUDE} +loga_OBJS = ${LOCAL} ${PLUGINS} ${DBS} ${ALERTS} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_SHARED} ${OS_ZLIB} ${CPRELUDE} +lists_OBJS = lists_make.c ${OTHER} ${PLUGINS} ${DBS} ${ALERTS} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_SHARED} ${OS_ZLIB} ${CPRELUDE} +all: logaudit logtest makelists logaudit: + cd ./cdb; make cd ./alerts; make cd ./decoders; make cd ./compiled_rules; make; $(CC) $(CFLAGS) ${OS_LINK} -I./ ${loga_OBJS} -o ${NAME} - make logtest logtest: + cd ./cdb; make cd ./decoders; make logtest cd ./compiled_rules; make; $(CC) $(CFLAGS) ${OS_LINK} -DTESTRULE -I./ testrule.c ${loga_OBJS} -o ossec-logtest +makelists: + cd ./cdb; make + $(CC) $(CFLAGS) ${OS_LINK} -DTESTRULE -I./ makelists.c ${lists_OBJS} -o ossec-makelists + clean: + cd ./cdb; make clean cd ./alerts; make clean cd ./decoders; make clean cd ./compiled_rules; make clean @@ -35,3 +45,4 @@ clean: build: ${BUILD} cp -pr ossec-logtest ${PT}../bin + cp -pr ossec-makelists ${PT}../bin diff --git a/src/analysisd/active-response.c b/src/analysisd/active-response.c index 5827ad9..5c3d779 100755 --- a/src/analysisd/active-response.c +++ b/src/analysisd/active-response.c @@ -1,11 +1,11 @@ -/* @(#) $Id: active-response.c,v 1.26 2009/06/24 17:06:21 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/active-response.h b/src/analysisd/active-response.h index 0bbb1e6..64cd2fd 100755 --- a/src/analysisd/active-response.h +++ b/src/analysisd/active-response.h @@ -1,11 +1,11 @@ -/* @(#) $Id: active-response.h,v 1.13 2009/06/24 17:06:21 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/alerts.h b/src/analysisd/alerts/alerts.h index 8c99c6f..0b5d473 100755 --- a/src/analysisd/alerts/alerts.h +++ b/src/analysisd/alerts/alerts.h @@ -1,11 +1,11 @@ -/* @(#) $Id: alerts.h,v 1.6 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/exec.c b/src/analysisd/alerts/exec.c index a5c07ce..46bf4ac 100755 --- a/src/analysisd/alerts/exec.c +++ b/src/analysisd/alerts/exec.c @@ -1,11 +1,11 @@ -/* @(#) $Id: exec.c,v 1.39 2009/11/20 15:38:28 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/exec.h b/src/analysisd/alerts/exec.h index 09577db..70e45e1 100755 --- a/src/analysisd/alerts/exec.h +++ b/src/analysisd/alerts/exec.h @@ -1,11 +1,11 @@ -/* @(#) $Id: exec.h,v 1.7 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/getloglocation.c b/src/analysisd/alerts/getloglocation.c index 2f12488..0a99251 100755 --- a/src/analysisd/alerts/getloglocation.c +++ b/src/analysisd/alerts/getloglocation.c @@ -1,11 +1,11 @@ -/* @(#) $Id: getloglocation.c,v 1.14 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/getloglocation.h b/src/analysisd/alerts/getloglocation.h index 3b431c4..90bef61 100755 --- a/src/analysisd/alerts/getloglocation.h +++ b/src/analysisd/alerts/getloglocation.h @@ -1,11 +1,11 @@ -/* @(#) $Id: getloglocation.h,v 1.10 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/alerts/log.c b/src/analysisd/alerts/log.c index 2686620..4095b61 100755 --- a/src/analysisd/alerts/log.c +++ b/src/analysisd/alerts/log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: log.c,v 1.33 2009/11/20 15:38:28 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -48,6 +48,52 @@ void OS_Store(Eventinfo *lf) } + +void OS_LogOutput(Eventinfo *lf) +{ + printf( + "** Alert %d.%ld:%s - %s\n" + "%d %s %02d %s %s%s%s\nRule: %d (level %d) -> '%s'\n" + "Src IP: %s\nUser: %s\n%.1256s\n", + lf->time, + __crt_ftell, + lf->generated_rule->alert_opts & DO_MAILALERT?" mail ":"", + lf->generated_rule->group, + lf->year, + lf->mon, + lf->day, + lf->hour, + lf->hostname != lf->location?lf->hostname:"", + lf->hostname != lf->location?"->":"", + lf->location, + lf->generated_rule->sigid, + lf->generated_rule->level, + lf->generated_rule->comment, + lf->srcip == NULL?"(none)":lf->srcip, + lf->dstuser == NULL?"(none)":lf->dstuser, + lf->full_log); + + + /* Printing the last events if present */ + if(lf->generated_rule->last_events) + { + char **lasts = lf->generated_rule->last_events; + while(*lasts) + { + printf("%.1256s\n",*lasts); + lasts++; + } + lf->generated_rule->last_events[0] = NULL; + } + + printf("\n"); + + fflush(stdout); + return; +} + + + /* OS_Log: v0.3, 2006/03/04 */ /* _writefile: v0.2, 2005/02/09 */ void OS_Log(Eventinfo *lf) diff --git a/src/analysisd/alerts/log.h b/src/analysisd/alerts/log.h index 78b7e82..b8ea56f 100755 --- a/src/analysisd/alerts/log.h +++ b/src/analysisd/alerts/log.h @@ -1,11 +1,11 @@ -/* @(#) $Id: log.h,v 1.8 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -19,6 +19,7 @@ #define FWDROP "drop" #define FWALLOW "accept" +void OS_LogOutput(Eventinfo *lf); void OS_Log(Eventinfo *lf); void OS_Store(Eventinfo *lf); int FW_Log(Eventinfo *lf); diff --git a/src/analysisd/alerts/mail.c b/src/analysisd/alerts/mail.c index a198c02..7f22d6e 100755 --- a/src/analysisd/alerts/mail.c +++ b/src/analysisd/alerts/mail.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/analysisd.c b/src/analysisd/analysisd.c index 25f8e18..8119c22 100755 --- a/src/analysisd/analysisd.c +++ b/src/analysisd/analysisd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: analysisd.c,v 1.149 2009/11/20 16:11:46 dcid Exp $ */ +/* @(#) $Id$ */ -/* Copyright (C) 2009 Trend Micro Inc. +/* Copyright (C) 2010 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -41,6 +41,7 @@ #include "config.h" #include "rules.h" #include "stats.h" + #include "eventinfo.h" #include "analysisd.h" @@ -73,6 +74,7 @@ int GlobalConf(char * cfgfile); /* For rules */ void Rules_OP_CreateRules(); +void Lists_OP_CreateLists(); int Rules_OP_ReadRules(char * cfgfile); int _setlevels(RuleNode *node, int nnode); int AddHash_Rule(RuleNode *node); @@ -87,6 +89,7 @@ int FTS_Init(); int FTS(Eventinfo *lf); int AddtoIGnore(Eventinfo *lf); int IGnore(Eventinfo *lf); +int doDiff(RuleInfo *currently_rule, Eventinfo *lf); /* For decoders */ @@ -271,8 +274,7 @@ int main_analysisd(int argc, char **argv) OS_PicvizOpen(Config.picviz_socket); chown(Config.picviz_socket, uid, gid); } - - + /* Setting the group */ if(Privsep_SetGroup(gid) < 0) ErrorExit(SETGID_ERROR,ARGV0,group); @@ -286,54 +288,109 @@ int main_analysisd(int argc, char **argv) - /* Initializing the list */ - OS_CreateOSDecoderList(); - - - /* Reading decoders */ - if(!ReadDecodeXML(XML_DECODER)) + /* + * Anonymous Section: Load rules, decoders, and lists + * + * As lists require two pass loading of rules that make use of list lookups + * are created with blank database structs, and need to be filled in after + * completion of all rules and lists. + */ { - ErrorExit(CONFIG_ERROR, ARGV0, XML_DECODER); - } + { + /* Initializing the decoders list */ + OS_CreateOSDecoderList(); - /* Reading local ones. */ - c = ReadDecodeXML(XML_LDECODER); - if(!c) - { - if((c != -2)) - ErrorExit(CONFIG_ERROR, ARGV0, XML_LDECODER); - } - else - { - if(!test_config) - verbose("%s: INFO: Reading local decoder file.", ARGV0); - } - SetDecodeXML(); + if(!Config.decoders) + { /* Legacy loading */ + /* Reading decoders */ + if(!ReadDecodeXML(XML_DECODER)) + { + ErrorExit(CONFIG_ERROR, ARGV0, XML_DECODER); + } - - /* Creating the rules list */ - Rules_OP_CreateRules(); + /* Reading local ones. */ + c = ReadDecodeXML(XML_LDECODER); + if(!c) + { + if((c != -2)) + ErrorExit(CONFIG_ERROR, ARGV0, XML_LDECODER); + } + else + { + if(!test_config) + verbose("%s: INFO: Reading local decoder file.", ARGV0); + } + } + else + { /* New loaded based on file speified in ossec.conf */ + char **decodersfiles; + decodersfiles = Config.decoders; + while( decodersfiles && *decodersfiles) + { + if(!test_config) + verbose("%s: INFO: Reading decoder file %s.", ARGV0, *decodersfiles); + if(!ReadDecodeXML(*decodersfiles)) + ErrorExit(CONFIG_ERROR, ARGV0, *decodersfiles); + + free(*decodersfiles); + decodersfiles++; + } + } - - /* Reading the rules */ - { - char **rulesfiles; - rulesfiles = Config.includes; - while(rulesfiles && *rulesfiles) - { - if(!test_config) - verbose("%s: INFO: Reading rules file: '%s'", ARGV0, *rulesfiles); - if(Rules_OP_ReadRules(*rulesfiles) < 0) - ErrorExit(RULES_ERROR, ARGV0, *rulesfiles); - - free(*rulesfiles); - rulesfiles++; + /* Load decoders */ + SetDecodeXML(); } + { /* Load Lists */ + /* Initializing the lists of list struct */ + Lists_OP_CreateLists(); + /* Load each list into list struct */ + { + char **listfiles; + listfiles = Config.lists; + while(listfiles && *listfiles) + { + if(!test_config) + verbose("%s: INFO: Reading loading the lists file: '%s'", ARGV0, *listfiles); + if(Lists_OP_LoadList(*listfiles) < 0) + ErrorExit(LISTS_ERROR, ARGV0, *listfiles); + free(*listfiles); + listfiles++; + } + free(Config.lists); + Config.lists = NULL; + } + } + { /* Load Rules */ + /* Creating the rules list */ + Rules_OP_CreateRules(); - free(Config.includes); - Config.includes = NULL; + /* Reading the rules */ + { + char **rulesfiles; + rulesfiles = Config.includes; + while(rulesfiles && *rulesfiles) + { + if(!test_config) + verbose("%s: INFO: Reading rules file: '%s'", ARGV0, *rulesfiles); + if(Rules_OP_ReadRules(*rulesfiles) < 0) + ErrorExit(RULES_ERROR, ARGV0, *rulesfiles); + + free(*rulesfiles); + rulesfiles++; + } + + free(Config.includes); + Config.includes = NULL; + } + + /* Find all rules with that require list lookups and attache the + * the correct list struct to the rule. This keeps rules from having to + * search thought the list of lists for the correct file during rule evaluation. + */ + OS_ListLoadRules(); + } } - + /* Fixing the levels/accuracy */ { @@ -1109,7 +1166,7 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) #ifdef TESTRULE - if(full_output) + if(full_output && !alert_only) print_out(" Trying rule: %d - %s", currently_rule->sigid, currently_rule->comment); #endif @@ -1123,7 +1180,6 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) } - /* Checking program name */ if(currently_rule->program_name) { @@ -1149,6 +1205,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) strlen(lf->id), currently_rule->id)) return(NULL); + #ifdef CDBLOOKUP + + #endif } @@ -1192,6 +1251,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) { return(NULL); } + #ifdef CDBLOOKUP + + #endif } @@ -1211,6 +1273,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) { return(NULL); } + #ifdef CDBLOOKUP + + #endif } /* Checking for the dstip */ @@ -1225,6 +1290,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) { return(NULL); } + #ifdef CDBLOOKUP + + #endif } if(currently_rule->srcport) @@ -1240,6 +1308,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) { return(NULL); } + #ifdef CDBLOOKUP + + #endif } if(currently_rule->dstport) { @@ -1254,6 +1325,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) { return(NULL); } + #ifdef CDBLOOKUP + + #endif } } /* END PACKET_INFO */ @@ -1289,6 +1363,9 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) return(NULL); } else + #ifdef CDBLOOKUP + + #endif { /* no user set */ return(NULL); @@ -1361,9 +1438,18 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) currently_rule->status)) return(NULL); } + + + /* Do diff check. */ + if(currently_rule->context_opts & SAME_DODIFF) + { + if(!doDiff(currently_rule, lf)) + { + return(NULL); + } + } } - /* Checking for the FTS flag */ if(currently_rule->alert_opts & DO_FTS) { @@ -1385,6 +1471,98 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) } } + /* List lookups */ + if(currently_rule->lists != NULL) + { + ListRule *list_holder=currently_rule->lists; + while(list_holder) + { + switch(list_holder->field) + { + case RULE_SRCIP: + if(!lf->srcip) + return(NULL); + if(!OS_DBSearch(list_holder,lf->srcip)) + return(NULL); + break; + case RULE_SRCPORT: + if(!lf->srcport) + return(NULL); + if(!OS_DBSearch(list_holder,lf->srcport)) + return(NULL); + break; + case RULE_DSTIP: + if(!lf->dstip) + return(NULL); + if(!OS_DBSearch(list_holder,lf->dstip)) + return(NULL); + break; + case RULE_DSTPORT: + if(!lf->dstport) + return(NULL); + if(!OS_DBSearch(list_holder,lf->dstport)) + return(NULL); + break; + case RULE_USER: + if(lf->srcuser) + { + if(!OS_DBSearch(list_holder,lf->srcuser)) + return(NULL); + } + else if(lf->dstuser) + { + if(!OS_DBSearch(list_holder,lf->dstuser)) + return(NULL); + } + else + { + return(NULL); + } + break; + case RULE_URL: + if(!lf->url) + return(NULL); + if(!OS_DBSearch(list_holder,lf->url)) + return(NULL); + break; + case RULE_ID: + if(!lf->id) + return(NULL); + if(!OS_DBSearch(list_holder,lf->id)) + return(NULL); + break; + case RULE_HOSTNAME: + if(!lf->hostname) + return(NULL); + if(!OS_DBSearch(list_holder,lf->hostname)) + return(NULL); + break; + case RULE_PROGRAM_NAME: + if(!lf->program_name) + return(NULL); + if(!OS_DBSearch(list_holder,lf->program_name)) + return(NULL); + break; + case RULE_STATUS: + if(!lf->status) + return(NULL); + if(!OS_DBSearch(list_holder,lf->status)) + return(NULL); + break; + case RULE_ACTION: + if(!lf->action) + return(NULL); + if(!OS_DBSearch(list_holder,lf->action)) + return(NULL); + break; + default: + return(NULL); + } + + list_holder = list_holder->next; + } + } + /* If it is a context rule, search for it */ if(currently_rule->context == 1) @@ -1394,7 +1572,7 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) } #ifdef TESTRULE - if(full_output) + if(full_output && !alert_only) print_out(" *Rule %d matched.", currently_rule->sigid); #endif @@ -1406,7 +1584,7 @@ RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node) RuleInfo *child_rule = NULL; #ifdef TESTRULE - if(full_output) + if(full_output && !alert_only) print_out(" *Trying child rules."); #endif @@ -1539,3 +1717,4 @@ void DumpLogstats() /* EOF */ + diff --git a/src/analysisd/analysisd.h b/src/analysisd/analysisd.h index 6175ebf..fe580d4 100755 --- a/src/analysisd/analysisd.h +++ b/src/analysisd/analysisd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: analysisd.h,v 1.10 2009/06/24 17:06:21 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -32,10 +32,6 @@ int __crt_hour; int __crt_wday; -/* For test rule only. */ -#ifdef TESTRULE -int full_output; -#endif time_t c_time; /* Current time of event. Used everywhere */ diff --git a/src/analysisd/cdb/Makefile b/src/analysisd/cdb/Makefile new file mode 100644 index 0000000..a43784a --- /dev/null +++ b/src/analysisd/cdb/Makefile @@ -0,0 +1,22 @@ +# Makefile for analysisd alerts +# Daniel B. Cid || +# http://www.ossec.net/hids/ + +PT=../../ +NAME=cdb + +include ../../Config.Make + +SRCS = cdb.c cdb_hash.c cdb_make.c uint32_pack.c uint32_unpack.c +OBJS = cdb.o cdb_hash.o cdb_make.o uint32_pack.o uint32_unpack.o + + +response: + $(CC) -I../ $(CFLAGS) -c $(SRCS) + ar cru cdb.a $(OBJS) + ar cru cdb_make.a $(OBJS) + ranlib cdb.a + ranlib cdb_make.a + +clean: + ${CLEAN} diff --git a/src/analysisd/cdb/cdb.c b/src/analysisd/cdb/cdb.c new file mode 100644 index 0000000..1e0c9aa --- /dev/null +++ b/src/analysisd/cdb/cdb.c @@ -0,0 +1,141 @@ +/* Public domain. */ +/* Adapted from DJB's original cdb-0.75 package */ + +#include +#include +#include +#include +#include +#include +#include "cdb.h" + +#ifndef EPROTO +#define EPROTO -15 /* cdb 0.75's default for PROTOless systems */ +#endif + +void cdb_free(struct cdb *c) +{ + if (c->map) { + munmap(c->map,c->size); + c->map = 0; + } +} + +void cdb_findstart(struct cdb *c) +{ + c->loop = 0; +} + +void cdb_init(struct cdb *c,int fd) +{ + struct stat st; + char *x; + + cdb_free(c); + cdb_findstart(c); + c->fd = fd; + + if (fstat(fd,&st) == 0) + if (st.st_size <= 0xffffffff) { + x = mmap(0,st.st_size,PROT_READ,MAP_SHARED,fd,0); + if (x + 1) { + c->size = st.st_size; + c->map = x; + } + } +} + +int cdb_read(struct cdb *c,char *buf,unsigned int len,uint32 pos) +{ + if (c->map) { + if ((pos > c->size) || (c->size - pos < len)) goto FORMAT; + memcpy(buf,c->map + pos,len); + } + else { + if (lseek(c->fd,pos,SEEK_SET) == -1) return -1; + /* if (seek_set(c->fd,pos) == -1) return -1; */ + while (len > 0) { + int r; + do + r = read(c->fd,buf,len); + while ((r == -1) && (errno == EINTR)); + if (r == -1) return -1; + if (r == 0) goto FORMAT; + buf += r; + len -= r; + } + } + return 0; + + FORMAT: + errno = EPROTO; + return -1; +} + +static int match(struct cdb *c,char *key,unsigned int len,uint32 pos) +{ + char buf[32]; + int n; + + while (len > 0) { + n = sizeof buf; + if (n > len) n = len; + if (cdb_read(c,buf,n,pos) == -1) return -1; + if (memcmp(buf,key,n)) return 0; + pos += n; + key += n; + len -= n; + } + return 1; +} + +int cdb_findnext(struct cdb *c,char *key,unsigned int len) +{ + char buf[8]; + uint32 pos; + uint32 u; + + if (!c->loop) { + u = cdb_hash(key,len); + if (cdb_read(c,buf,8,(u << 3) & 2047) == -1) return -1; + uint32_unpack(buf + 4,&c->hslots); + if (!c->hslots) return 0; + uint32_unpack(buf,&c->hpos); + c->khash = u; + u >>= 8; + u %= c->hslots; + u <<= 3; + c->kpos = c->hpos + u; + } + + while (c->loop < c->hslots) { + if (cdb_read(c,buf,8,c->kpos) == -1) return -1; + uint32_unpack(buf + 4,&pos); + if (!pos) return 0; + c->loop += 1; + c->kpos += 8; + if (c->kpos == c->hpos + (c->hslots << 3)) c->kpos = c->hpos; + uint32_unpack(buf,&u); + if (u == c->khash) { + if (cdb_read(c,buf,8,pos) == -1) return -1; + uint32_unpack(buf,&u); + if (u == len) + switch(match(c,key,len,pos + 8)) { + case -1: + return -1; + case 1: + uint32_unpack(buf + 4,&c->dlen); + c->dpos = pos + 8 + len; + return 1; + } + } + } + + return 0; +} + +int cdb_find(struct cdb *c,char *key,unsigned int len) +{ + cdb_findstart(c); + return cdb_findnext(c,key,len); +} diff --git a/src/analysisd/cdb/cdb.h b/src/analysisd/cdb/cdb.h new file mode 100644 index 0000000..d244789 --- /dev/null +++ b/src/analysisd/cdb/cdb.h @@ -0,0 +1,38 @@ +/* Public domain. */ +/* Adapted from DJB's original cdb-0.75 package */ + +#ifndef CDB_H +#define CDB_H + +#include "uint32.h" + +#define CDB_HASHSTART 5381 +extern uint32 cdb_hashadd(uint32,unsigned char); +extern uint32 cdb_hash(char *,unsigned int); + +struct cdb { + char *map; /* 0 if no map is available */ + int fd; + uint32 size; /* initialized if map is nonzero */ + uint32 loop; /* number of hash slots searched under this key */ + uint32 khash; /* initialized if loop is nonzero */ + uint32 kpos; /* initialized if loop is nonzero */ + uint32 hpos; /* initialized if loop is nonzero */ + uint32 hslots; /* initialized if loop is nonzero */ + uint32 dpos; /* initialized if cdb_findnext() returns 1 */ + uint32 dlen; /* initialized if cdb_findnext() returns 1 */ +} ; + +extern void cdb_free(struct cdb *); +extern void cdb_init(struct cdb *,int fd); + +extern int cdb_read(struct cdb *,char *,unsigned int,uint32); + +extern void cdb_findstart(struct cdb *); +extern int cdb_findnext(struct cdb *,char *,unsigned int); +extern int cdb_find(struct cdb *,char *,unsigned int); + +#define cdb_datapos(c) ((c)->dpos) +#define cdb_datalen(c) ((c)->dlen) + +#endif diff --git a/src/analysisd/cdb/cdb_hash.c b/src/analysisd/cdb/cdb_hash.c new file mode 100644 index 0000000..551b3a3 --- /dev/null +++ b/src/analysisd/cdb/cdb_hash.c @@ -0,0 +1,22 @@ +/* Public domain. */ +/* Adapted from DJB's original cdb-0.75 package */ + +#include "cdb.h" + +uint32 cdb_hashadd(uint32 h,unsigned char c) +{ + h += (h << 5); + return h ^ c; +} + +uint32 cdb_hash(char *buf,unsigned int len) +{ + uint32 h; + + h = CDB_HASHSTART; + while (len) { + h = cdb_hashadd(h,*buf++); + --len; + } + return h; +} diff --git a/src/analysisd/cdb/cdb_make.c b/src/analysisd/cdb/cdb_make.c new file mode 100644 index 0000000..bbfdfbc --- /dev/null +++ b/src/analysisd/cdb/cdb_make.c @@ -0,0 +1,180 @@ +/* Public domain. */ +/* Adapted from DJB's original cdb-0.75 package */ + +#include +#include +#include +#include +#include +#include "cdb.h" +#include "cdb_make.h" +#include "uint32.h" + +static int cdb_make_write(struct cdb_make *c, char *buf, uint32 sz) { + fwrite(buf, sz, 1, c->fp); + return ferror(c->fp); +} + +int cdb_make_start(struct cdb_make *c, FILE * f) +{ + c->head = 0; + c->split = 0; + c->hash = 0; + c->numentries = 0; + c->fp = f; + c->pos = sizeof c->final; + if (fseek(f,c->pos,SEEK_SET) == -1) { + perror("fseek failed"); + return -1; + } + return ftell(c->fp); +} + +static int posplus(struct cdb_make *c,uint32 len) +{ + uint32 newpos = c->pos + len; + if (newpos < len) { errno = ENOMEM; return -1; } + c->pos = newpos; + return 0; +} + +int cdb_make_addend(struct cdb_make *c,unsigned int keylen,unsigned int datalen,uint32 h) +{ + struct cdb_hplist *head; + + head = c->head; + if (!head || (head->num >= CDB_HPLIST)) { + head = (struct cdb_hplist *) malloc(sizeof(struct cdb_hplist)); + if (!head) return -1; + head->num = 0; + head->next = c->head; + c->head = head; + } + head->hp[head->num].h = h; + head->hp[head->num].p = c->pos; + ++head->num; + ++c->numentries; + if (posplus(c,8) == -1) return -1; + if (posplus(c,keylen) == -1) return -1; + if (posplus(c,datalen) == -1) return -1; + return 0; +} + +int cdb_make_addbegin(struct cdb_make *c,unsigned int keylen,unsigned int datalen) +{ + char buf[8]; + + if (keylen > 0xffffffff) { errno = ENOMEM; return -1; } + if (datalen > 0xffffffff) { errno = ENOMEM; return -1; } + + uint32_pack(buf,keylen); + uint32_pack(buf + 4,datalen); + if (cdb_make_write(c,buf,8) != 0) return -1; + /* if (buffer_putalign(&c->b,buf,8) == -1) return -1; */ + return 0; +} + +int cdb_make_add(struct cdb_make *c,char *key,unsigned int keylen,char *data,unsigned int datalen) +{ + if (cdb_make_addbegin(c,keylen,datalen) == -1) return -1; + if (cdb_make_write(c,key,keylen) != 0) return -1; + if (cdb_make_write(c,data,datalen) != 0) return -1; + /* if (buffer_putalign(&c->b,key,keylen) == -1) return -1; */ + /* if (buffer_putalign(&c->b,data,datalen) == -1) return -1; */ + return cdb_make_addend(c,keylen,datalen,cdb_hash(key,keylen)); +} + +int cdb_make_finish(struct cdb_make *c) +{ + char buf[8]; + int i; + uint32 len; + uint32 u; + uint32 memsize; + uint32 count; + uint32 where; + struct cdb_hplist *x; + struct cdb_hp *hp; + + for (i = 0;i < 256;++i) + c->count[i] = 0; + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + ++c->count[255 & x->hp[i].h]; + } + + memsize = 1; + for (i = 0;i < 256;++i) { + u = c->count[i] * 2; + if (u > memsize) + memsize = u; + } + + memsize += c->numentries; /* no overflow possible up to now */ + u = (uint32) 0 - (uint32) 1; + u /= sizeof(struct cdb_hp); + if (memsize > u) { errno = ENOMEM; return -1; } + + c->split = (struct cdb_hp *) malloc(memsize * sizeof(struct cdb_hp)); + if (!c->split) return -1; + + c->hash = c->split + c->numentries; + + u = 0; + for (i = 0;i < 256;++i) { + u += c->count[i]; /* bounded by numentries, so no overflow */ + c->start[i] = u; + } + + for (x = c->head;x;x = x->next) { + i = x->num; + while (i--) + c->split[--c->start[255 & x->hp[i].h]] = x->hp[i]; + } + + for (i = 0;i < 256;++i) { + count = c->count[i]; + + len = count + count; /* no overflow possible */ + uint32_pack(c->final + 8 * i,c->pos); + uint32_pack(c->final + 8 * i + 4,len); + + for (u = 0;u < len;++u) + c->hash[u].h = c->hash[u].p = 0; + + hp = c->split + c->start[i]; + for (u = 0;u < count;++u) { + where = (hp->h >> 8) % len; + while (c->hash[where].p) + if (++where == len) + where = 0; + c->hash[where] = *hp++; + } + + for (u = 0;u < len;++u) { + uint32_pack(buf,c->hash[u].h); + uint32_pack(buf + 4,c->hash[u].p); + if (cdb_make_write(c,buf,8) != 0) return -1; + /* if (buffer_putalign(&c->b,buf,8) == -1) return -1; */ + if (posplus(c,8) == -1) return -1; + } + } + + if (c->split) free(c->split); + + for (x = c->head;x;c->head = x) { + x = x->next; + free(c->head); + } + + if (fflush(c->fp) != 0) return -1; + /* if (buffer_flush(&c->b) == -1) return -1; */ + rewind(c->fp); + if (ftell(c->fp) != 0) return -1; + /* if (seek_begin(c->fd) == -1) return -1; */ + if (cdb_make_write(c,c->final,sizeof c->final) != 0) return -1; + return fflush(c->fp); + /* return buffer_putflush(&c->b,c->final,sizeof c->final); */ +} diff --git a/src/analysisd/cdb/cdb_make.h b/src/analysisd/cdb/cdb_make.h new file mode 100644 index 0000000..a7757bb --- /dev/null +++ b/src/analysisd/cdb/cdb_make.h @@ -0,0 +1,41 @@ +/* Public domain. */ +/* Adapted from DJB's original cdb-0.75 package */ + +#ifndef CDB_MAKE_H +#define CDB_MAKE_H + +#include +#include "uint32.h" + +#define CDB_HPLIST 1000 + +struct cdb_hp { uint32 h; uint32 p; } ; + +struct cdb_hplist { + struct cdb_hp hp[CDB_HPLIST]; + struct cdb_hplist *next; + int num; +} ; + +struct cdb_make { + /* char bspace[8192]; */ + char final[2048]; + uint32 count[256]; + uint32 start[256]; + struct cdb_hplist *head; + struct cdb_hp *split; /* includes space for hash */ + struct cdb_hp *hash; + uint32 numentries; + /* buffer b; */ + uint32 pos; + /* int fd; */ + FILE * fp; +} ; + +extern int cdb_make_start(struct cdb_make *, FILE *); +extern int cdb_make_addbegin(struct cdb_make *,unsigned int,unsigned int); +extern int cdb_make_addend(struct cdb_make *,unsigned int,unsigned int,uint32); +extern int cdb_make_add(struct cdb_make *,char *,unsigned int,char *,unsigned int); +extern int cdb_make_finish(struct cdb_make *); + +#endif diff --git a/src/analysisd/cdb/uint32.h b/src/analysisd/cdb/uint32.h new file mode 100644 index 0000000..4d96f1a --- /dev/null +++ b/src/analysisd/cdb/uint32.h @@ -0,0 +1,11 @@ +#ifndef UINT32_H +#define UINT32_H + +/* adopted from libowfat 0.9 (GPL) */ + +typedef unsigned int uint32; + +extern void uint32_pack(char *out,uint32 in); +extern void uint32_unpack(const char *in,uint32 *out); + +#endif diff --git a/src/analysisd/cdb/uint32_pack.c b/src/analysisd/cdb/uint32_pack.c new file mode 100644 index 0000000..fd2641e --- /dev/null +++ b/src/analysisd/cdb/uint32_pack.c @@ -0,0 +1,11 @@ +#define NO_UINT32_MACROS +#include "uint32.h" + +/* adopted from libowfat 0.9 (GPL) */ + +void uint32_pack(char *out,uint32 in) { + *out=in&0xff; in>>=8; + *++out=in&0xff; in>>=8; + *++out=in&0xff; in>>=8; + *++out=in&0xff; +} diff --git a/src/analysisd/cdb/uint32_unpack.c b/src/analysisd/cdb/uint32_unpack.c new file mode 100644 index 0000000..4bd7829 --- /dev/null +++ b/src/analysisd/cdb/uint32_unpack.c @@ -0,0 +1,11 @@ +#define NO_UINT32_MACROS +#include "uint32.h" + +/* adopted from libowfat 0.9 (GPL) */ + +void uint32_unpack(const char *in,uint32 *out) { + *out = (((uint32)(unsigned char)in[3])<<24) | + (((uint32)(unsigned char)in[2])<<16) | + (((uint32)(unsigned char)in[1])<<8) | + (uint32)(unsigned char)in[0]; +} diff --git a/src/analysisd/cleanevent.c b/src/analysisd/cleanevent.c index 6bfef2f..f830438 100755 --- a/src/analysisd/cleanevent.c +++ b/src/analysisd/cleanevent.c @@ -1,11 +1,11 @@ -/* @(#) $Id: cleanevent.c,v 1.42 2009/06/24 17:06:21 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -549,11 +549,14 @@ int OS_CleanMSG(char *msg, Eventinfo *lf) #ifdef TESTRULE - print_out("**Phase 1: Completed pre-decoding."); - print_out(" full event: '%s'", lf->full_log); - print_out(" hostname: '%s'", lf->hostname); - print_out(" program_name: '%s'", lf->program_name); - print_out(" log: '%s'", lf->log); + if(!alert_only) + { + print_out("**Phase 1: Completed pre-decoding."); + print_out(" full event: '%s'", lf->full_log); + print_out(" hostname: '%s'", lf->hostname); + print_out(" program_name: '%s'", lf->program_name); + print_out(" log: '%s'", lf->log); + } #endif return(0); diff --git a/src/analysisd/compiled_rules/.function_list b/src/analysisd/compiled_rules/.function_list index 3bd3d7d..e25c103 100644 --- a/src/analysisd/compiled_rules/.function_list +++ b/src/analysisd/compiled_rules/.function_list @@ -1,3 +1,5 @@ check_id_size comp_srcuser_dstuser comp_mswin_targetuser_calleruser_diff +is_simple_http_request +is_valid_crawler diff --git a/src/analysisd/compiled_rules/generic_samples.c b/src/analysisd/compiled_rules/generic_samples.c index 8e05341..9aae6be 100644 --- a/src/analysisd/compiled_rules/generic_samples.c +++ b/src/analysisd/compiled_rules/generic_samples.c @@ -1,11 +1,11 @@ -/* @(#) $Id: generic_samples.c,v 1.2 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -129,5 +129,54 @@ void *comp_mswin_targetuser_calleruser_diff(Eventinfo *lf) } +/* Example 4: + * Checks if a HTTP request is a simple GET/POST without a query. + * This avoid that we call the attack rules for no reason. + */ +void *is_simple_http_request(Eventinfo *lf) +{ + + /* Simple GET / request. */ + if(strcmp(lf->url,"/") == 0) + { + return(lf); + } + + + /* Simple request, no query. */ + if(!strchr(lf->url,'?')) + { + return(lf); + } + + + /* In here, we have an additional query to be checked. */ + return(NULL); +} + + +/* Example 5: + * Checks if the source ip is from a valid bot. + */ +void *is_valid_crawler(Eventinfo *lf) +{ + if((strncmp(lf->log, "66.249.",7) == 0)|| /* Google bot */ + (strncmp(lf->log, "72.14.",6) == 0)|| /* Feedfetcher-Google */ + (strncmp(lf->log, "209.85.",7) == 0)|| /* Feedfetcher-Google */ + (strncmp(lf->log, "65.55.",6) == 0)|| /* MSN/Bing */ + (strncmp(lf->log, "207.46.",7) == 0)|| /* MSN/Bing */ + (strncmp(lf->log, "74.6.",5) == 0)|| /* Yahoo */ + (strncmp(lf->log, "72.30.",6) == 0)|| /* Yahoo */ + (strncmp(lf->log, "67.195.",7) == 0) /* Yahoo */ + ) + { + return(lf); + } + + return(NULL); +} + + + /* END generic samples. */ diff --git a/src/analysisd/config.c b/src/analysisd/config.c index b833278..132dce7 100755 --- a/src/analysisd/config.c +++ b/src/analysisd/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.32 2009/11/04 15:18:59 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -58,6 +58,8 @@ int GlobalConf(char * cfgfile) Config.logbylevel = 1; Config.includes = NULL; + Config.lists = NULL; + Config.decoders = NULL; modules|= CGLOBAL; modules|= CRULES; diff --git a/src/analysisd/config.h b/src/analysisd/config.h index da73d3a..d3bb44a 100755 --- a/src/analysisd/config.h +++ b/src/analysisd/config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: config.h,v 1.19 2009/11/20 15:38:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/decoders/decode-xml.c b/src/analysisd/decoders/decode-xml.c index bbb5e13..6840ec8 100755 --- a/src/analysisd/decoders/decode-xml.c +++ b/src/analysisd/decoders/decode-xml.c @@ -1,11 +1,11 @@ -/* @(#) $Id: decode-xml.c,v 1.47 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -195,6 +195,7 @@ int ReadDecodeAttrs(char **names, char **values) int ReadDecodeXML(char *file) { + debug1("ReadDecoderXML File = %s", file); OS_XML xml; XML_NODE node = NULL; diff --git a/src/analysisd/decoders/decoder.c b/src/analysisd/decoders/decoder.c index 6587817..70ac4cc 100755 --- a/src/analysisd/decoders/decoder.c +++ b/src/analysisd/decoders/decoder.c @@ -1,11 +1,11 @@ -/* @(#) $Id: decoder.c,v 1.42 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -49,7 +49,10 @@ void DecodeEvent(Eventinfo *lf) #ifdef TESTRULE - print_out("\n**Phase 2: Completed decoding."); + if(!alert_only) + { + print_out("\n**Phase 2: Completed decoding."); + } #endif do @@ -84,7 +87,7 @@ void DecodeEvent(Eventinfo *lf) #ifdef TESTRULE - print_out(" decoder: '%s'", nnode->name); + if(!alert_only)print_out(" decoder: '%s'", nnode->name); #endif @@ -273,7 +276,10 @@ void DecodeEvent(Eventinfo *lf) }while((node=node->next) != NULL); #ifdef TESTRULE - print_out(" No decoder matched."); + if(!alert_only) + { + print_out(" No decoder matched."); + } #endif } @@ -283,7 +289,7 @@ void DecodeEvent(Eventinfo *lf) void *DstUser_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" dstuser: '%s'", field); + if(!alert_only)print_out(" dstuser: '%s'", field); #endif lf->dstuser = field; @@ -292,7 +298,7 @@ void *DstUser_FP(Eventinfo *lf, char *field) void *SrcUser_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" srcuser: '%s'", field); + if(!alert_only)print_out(" srcuser: '%s'", field); #endif lf->srcuser = field; @@ -301,7 +307,7 @@ void *SrcUser_FP(Eventinfo *lf, char *field) void *SrcIP_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" srcip: '%s'", field); + if(!alert_only)print_out(" srcip: '%s'", field); #endif lf->srcip = field; @@ -310,7 +316,7 @@ void *SrcIP_FP(Eventinfo *lf, char *field) void *DstIP_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" dstip: '%s'", field); + if(!alert_only)print_out(" dstip: '%s'", field); #endif lf->dstip = field; @@ -319,7 +325,7 @@ void *DstIP_FP(Eventinfo *lf, char *field) void *SrcPort_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" srcport: '%s'", field); + if(!alert_only)print_out(" srcport: '%s'", field); #endif lf->srcport = field; @@ -328,7 +334,7 @@ void *SrcPort_FP(Eventinfo *lf, char *field) void *DstPort_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" dstport: '%s'", field); + if(!alert_only)print_out(" dstport: '%s'", field); #endif lf->dstport = field; @@ -337,7 +343,7 @@ void *DstPort_FP(Eventinfo *lf, char *field) void *Protocol_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" proto: '%s'", field); + if(!alert_only)print_out(" proto: '%s'", field); #endif lf->protocol = field; @@ -346,7 +352,7 @@ void *Protocol_FP(Eventinfo *lf, char *field) void *Action_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" action: '%s'", field); + if(!alert_only)print_out(" action: '%s'", field); #endif lf->action = field; @@ -355,7 +361,7 @@ void *Action_FP(Eventinfo *lf, char *field) void *ID_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" id: '%s'", field); + if(!alert_only)print_out(" id: '%s'", field); #endif lf->id = field; @@ -364,7 +370,7 @@ void *ID_FP(Eventinfo *lf, char *field) void *Url_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" url: '%s'", field); + if(!alert_only)print_out(" url: '%s'", field); #endif lf->url = field; @@ -373,7 +379,7 @@ void *Url_FP(Eventinfo *lf, char *field) void *Data_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" extra_data: '%s'", field); + if(!alert_only)print_out(" extra_data: '%s'", field); #endif lf->data = field; @@ -382,7 +388,7 @@ void *Data_FP(Eventinfo *lf, char *field) void *Status_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" status: '%s'", field); + if(!alert_only)print_out(" status: '%s'", field); #endif lf->status = field; @@ -391,7 +397,7 @@ void *Status_FP(Eventinfo *lf, char *field) void *SystemName_FP(Eventinfo *lf, char *field) { #ifdef TESTRULE - print_out(" system_name: '%s'", field); + if(!alert_only)print_out(" system_name: '%s'", field); #endif lf->systemname = field; diff --git a/src/analysisd/decoders/decoder.h b/src/analysisd/decoders/decoder.h index 68a3339..021f9ec 100755 --- a/src/analysisd/decoders/decoder.h +++ b/src/analysisd/decoders/decoder.h @@ -1,11 +1,11 @@ -/* @(#) $Id: decoder.h,v 1.20 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/decoders_list.c b/src/analysisd/decoders/decoders_list.c index 7fe23b6..5cbe9a8 100755 --- a/src/analysisd/decoders/decoders_list.c +++ b/src/analysisd/decoders/decoders_list.c @@ -1,11 +1,11 @@ -/* @(#) $Id: decoders_list.c,v 1.7 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/hostinfo.c b/src/analysisd/decoders/hostinfo.c index dccee36..086964d 100755 --- a/src/analysisd/decoders/hostinfo.c +++ b/src/analysisd/decoders/hostinfo.c @@ -1,11 +1,11 @@ -/* @(#) $Id: hostinfo.c,v 1.14 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/decoders/plugin_decoders.h b/src/analysisd/decoders/plugin_decoders.h index dea9161..239549f 100755 --- a/src/analysisd/decoders/plugin_decoders.h +++ b/src/analysisd/decoders/plugin_decoders.h @@ -1,11 +1,11 @@ -/* @(#) $Id: plugin_decoders.h,v 1.7 2009/06/24 17:06:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/plugins/ossecalert_decoder.c b/src/analysisd/decoders/plugins/ossecalert_decoder.c index 2514d48..d0f642a 100644 --- a/src/analysisd/decoders/plugins/ossecalert_decoder.c +++ b/src/analysisd/decoders/plugins/ossecalert_decoder.c @@ -1,11 +1,11 @@ -/* @(#) $Id: ossecalert_decoder.c,v 1.3 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/plugins/pf_decoder.c b/src/analysisd/decoders/plugins/pf_decoder.c index 9457ae3..3eb6fc6 100644 --- a/src/analysisd/decoders/plugins/pf_decoder.c +++ b/src/analysisd/decoders/plugins/pf_decoder.c @@ -1,11 +1,11 @@ -/* @(#) $Id: pf_decoder.c,v 1.5 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/plugins/sonicwall_decoder.c b/src/analysisd/decoders/plugins/sonicwall_decoder.c index d513c29..56c41a4 100644 --- a/src/analysisd/decoders/plugins/sonicwall_decoder.c +++ b/src/analysisd/decoders/plugins/sonicwall_decoder.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sonicwall_decoder.c,v 1.5 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/plugins/symantecws_decoder.c b/src/analysisd/decoders/plugins/symantecws_decoder.c index cfb99a8..f958f2e 100644 --- a/src/analysisd/decoders/plugins/symantecws_decoder.c +++ b/src/analysisd/decoders/plugins/symantecws_decoder.c @@ -1,11 +1,11 @@ -/* @(#) $Id: symantecws_decoder.c,v 1.5 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/decoders/rootcheck.c b/src/analysisd/decoders/rootcheck.c index d134ae2..0fc7e04 100755 --- a/src/analysisd/decoders/rootcheck.c +++ b/src/analysisd/decoders/rootcheck.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rootcheck.c,v 1.26 2009/07/24 18:34:11 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/decoders/syscheck.c b/src/analysisd/decoders/syscheck.c index b8c4a89..840ed9d 100755 --- a/src/analysisd/decoders/syscheck.c +++ b/src/analysisd/decoders/syscheck.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck.c,v 1.53 2009/11/04 18:45:38 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -265,6 +265,7 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) { merror("%s: Error handling integrity database.",ARGV0); sdb.db_err++; /* Increment db error */ + lf->data = NULL; return(0); } @@ -341,7 +342,10 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) /* checksum match, we can just return and keep going */ if(strcmp(saved_sum, c_sum) == 0) + { + lf->data = NULL; return(0); + } /* If we reached here, the checksum of the file has changed */ @@ -381,6 +385,7 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) break; default: + lf->data = NULL; return(0); break; } @@ -519,6 +524,11 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) snprintf(sdb.size, OS_FLSIZE, "Size changed from '%s' to '%s'\n", oldsize, newsize); + + #ifdef PRELUDE + os_strdup(oldsize, lf->size_before); + os_strdup(newsize, lf->size_after); + #endif } /* Permission message */ @@ -528,6 +538,7 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) } else if(oldperm > 0 && newperm > 0) { + snprintf(sdb.perm, OS_FLSIZE, "Permissions changed from " "'%c%c%c%c%c%c%c%c%c' " "to '%c%c%c%c%c%c%c%c%c'\n", @@ -569,6 +580,11 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) (newperm & S_ISVTX)? 't' : (newperm & S_IXOTH)? 'x' : '-'); + + #ifdef PRELUDE + lf->perm_before = oldperm; + lf->perm_after = newperm; + #endif } /* Ownership message */ @@ -581,6 +597,12 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) snprintf(sdb.owner, OS_FLSIZE, "Ownership was '%s', " "now it is '%s'\n", olduid, newuid); + + + #ifdef PRELUDE + os_strdup(olduid, lf->owner_before); + os_strdup(newuid, lf->owner_after); + #endif } /* group ownership message */ @@ -593,6 +615,10 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) snprintf(sdb.gowner, OS_FLSIZE,"Group ownership was '%s', " "now it is '%s'\n", oldgid, newgid); + #ifdef PRELUDE + os_strdup(oldgid, lf->gowner_before); + os_strdup(newgid, lf->gowner_after); + #endif } /* md5 message */ @@ -605,6 +631,10 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) snprintf(sdb.md5, OS_FLSIZE, "Old md5sum was: '%s'\n" "New md5sum is : '%s'\n", oldmd5, newmd5); + #ifdef PRELUDE + os_strdup(oldmd5, lf->md5_before); + os_strdup(newmd5, lf->md5_after); + #endif } /* sha1 */ @@ -617,25 +647,36 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) snprintf(sdb.sha1, OS_FLSIZE, "Old sha1sum was: '%s'\n" "New sha1sum is : '%s'\n", oldsha1, newsha1); + #ifdef PRELUDE + os_strdup(oldsha1, lf->sha1_before); + os_strdup(newsha1, lf->sha1_after); + #endif } + #ifdef PRELUDE + os_strdup(f_name, lf->filename); + #endif /* Provide information about the file */ - snprintf(sdb.comment, 512, "Integrity checksum changed for: " + snprintf(sdb.comment, OS_MAXSTR, "Integrity checksum changed for: " "'%.756s'\n" "%s" "%s" "%s" "%s" "%s" - "%s", + "%s" + "%s%s", f_name, sdb.size, sdb.perm, sdb.owner, sdb.gowner, sdb.md5, - sdb.sha1); + sdb.sha1, + lf->data == NULL?"":"What changed:\n", + lf->data == NULL?"":lf->data + ); } @@ -643,6 +684,7 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) free(lf->full_log); os_strdup(sdb.comment, lf->full_log); lf->log = lf->full_log; + lf->data = NULL; /* Setting decoder */ @@ -679,10 +721,12 @@ int DB_Search(char *f_name, char *c_sum, Eventinfo *lf) /* Setting decoder */ lf->decoder_info = sdb.syscheck_dec; + lf->data = NULL; return(1); } + lf->data = NULL; return(0); } @@ -715,13 +759,27 @@ int DecodeSyscheck(Eventinfo *lf) merror(SK_INV_MSG, ARGV0); return(0); } - - + + /* Zeroing to get the check sum */ *f_name = '\0'; f_name++; + /* Getting diff. */ + lf->data = strchr(f_name, '\n'); + if(lf->data) + { + *lf->data = '\0'; + lf->data++; + } + else + { + lf->data = NULL; + } + + + /* Checking if file is supposed to be ignored */ if(Config.syscheck_ignore) { @@ -731,6 +789,7 @@ int DecodeSyscheck(Eventinfo *lf) { if(strncasecmp(*ff_ig, f_name, strlen(*ff_ig)) == 0) { + lf->data = NULL; return(0); } diff --git a/src/analysisd/dodiff.c b/src/analysisd/dodiff.c new file mode 100755 index 0000000..c17de31 --- /dev/null +++ b/src/analysisd/dodiff.c @@ -0,0 +1,213 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation. + * + * License details at the LICENSE file included with OSSEC or + * online at: http://www.ossec.net/en/licensing.html + */ + + + +#include "eventinfo.h" +#include "shared.h" + +char flastcontent[OS_SIZE_8192 +1]; +char *fmsglast = "Previous output:"; + +static int _add2last(char *str, int strsize, char *file) +{ + FILE *fp; + + fp = fopen(file, "w"); + if(!fp) + { + /* Try to create the directories. */ + char *dirrule = NULL; + char *diragent = NULL; + + dirrule = strrchr(file, '/'); + if(!dirrule) + { + merror("%s: ERROR: Invalid file name to diff: %s", + ARGV0, file); + return(0); + } + *dirrule = '\0'; + + diragent = strrchr(file, '/'); + if(!diragent) + { + merror("%s: ERROR: Invalid file name to diff (2): %s", + ARGV0, file); + return(0); + } + *diragent = '\0'; + + /* Checking if the diragent exists. */ + if(IsDir(file) != 0) + { + if(mkdir(file, 0770) == -1) + { + merror(MKDIR_ERROR, ARGV0, file); + return(0); + } + } + *diragent = '/'; + + if(IsDir(file) != 0) + { + if(mkdir(file, 0770) == -1) + { + merror(MKDIR_ERROR, ARGV0, file); + return(0); + } + } + *dirrule = '/'; + + fp = fopen(file, "w"); + if(!fp) + { + merror(FOPEN_ERROR, ARGV0, file); + return(0); + } + } + + fwrite(str, strsize + 1, 1, fp); + fclose(fp); + return(1); +} + + +int doDiff(RuleInfo *currently_rule, Eventinfo *lf) +{ + int date_of_change; + char *htpt = NULL; + char flastfile[OS_SIZE_2048 +1]; + char fdifffile[OS_SIZE_2048 +1]; + char flastcontent[OS_SIZE_8192 +1]; + + + /* Cleaning up global. */ + flastcontent[0] = '\0'; + flastcontent[OS_SIZE_8192] = '\0'; + currently_rule->last_events[0] = NULL; + + + if(lf->hostname[0] == '(') + { + htpt = strchr(lf->hostname, ')'); + if(htpt) + { + *htpt = '\0'; + } + snprintf(flastfile, OS_SIZE_2048, "%s/%s/%d/%s", DIFF_DIR, lf->hostname+1, + currently_rule->sigid, DIFF_LAST_FILE); + + if(htpt) + { + *htpt = ')'; + } + htpt = NULL; + } + else + { + snprintf(flastfile, OS_SIZE_2048, "%s/%s/%d/%s", DIFF_DIR, lf->hostname, + currently_rule->sigid, DIFF_LAST_FILE); + } + + /* lf->size can't be too long. */ + if(lf->size >= OS_SIZE_8192) + { + merror("%s: ERROR: event size (%d) too long for diff.", ARGV0, lf->size); + return(0); + } + + + /* Checking if last diff exists. */ + date_of_change = File_DateofChange(flastfile); + if(date_of_change <= 0) + { + merror("last file: %s",flastfile); + if(!_add2last(lf->log, lf->size, flastfile)) + { + merror("%s: ERROR: unable to create last file: %s", ARGV0, flastfile); + return(0); + } + return(0); + } + else + { + FILE *fp; + int n; + fp = fopen(flastfile,"r"); + if(!fp) + { + merror(FOPEN_ERROR, ARGV0, flastfile); + return(0); + } + + n = fread(flastcontent, 1, OS_SIZE_8192, fp); + if(n > 0) + { + flastcontent[n] = '\0'; + } + else + { + merror("%s: ERROR: read error on %s", ARGV0, flastfile); + fclose(fp); + return(0); + } + fclose(fp); + } + + /* Nothing changed. */ + if(strcmp(flastcontent, lf->log) == 0) + { + return(0); + } + + + /* File was modified. */ + if(lf->hostname[0] == '(') + { + htpt = strchr(lf->hostname, ')'); + if(htpt) + { + *htpt = '\0'; + } + snprintf(fdifffile, OS_SIZE_2048, "%s/%s/%d/state.%d", DIFF_DIR, lf->hostname+1, + currently_rule->sigid, date_of_change); + + if(htpt) + { + *htpt = ')'; + } + htpt = NULL; + } + else + { + snprintf(fdifffile, OS_SIZE_2048, "%s/%s/%d/state.%d", DIFF_DIR, lf->hostname, + currently_rule->sigid, date_of_change); + } + + rename(flastfile, fdifffile); + if(!_add2last(lf->log, lf->size, flastfile)) + { + merror("%s: ERROR: unable to create last file: %s", ARGV0, flastfile); + } + + currently_rule->last_events[0] = fmsglast; + currently_rule->last_events[1] = flastcontent; + return(1); + +} + + + +/* EOF */ diff --git a/src/analysisd/eventinfo.c b/src/analysisd/eventinfo.c index e3a77b2..9cfa45c 100755 --- a/src/analysisd/eventinfo.c +++ b/src/analysisd/eventinfo.c @@ -1,11 +1,11 @@ -/* @(#) $Id: eventinfo.c,v 1.41 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -517,7 +517,23 @@ void Zero_Eventinfo(Eventinfo *lf) lf->generated_rule = NULL; lf->sid_node_to_delete = NULL; lf->decoder_info = NULL_Decoder; - + + #ifdef PRELUDE + lf->filename = NULL; + lf->perm_before = 0; + lf->perm_after = 0; + lf->md5_before = NULL; + lf->md5_after = NULL; + lf->sha1_before = NULL; + lf->sha1_after = NULL; + lf->size_before = NULL; + lf->size_after = NULL; + lf->owner_before = NULL; + lf->owner_after = NULL; + lf->gowner_before = NULL; + lf->gowner_after = NULL; + #endif + return; } @@ -565,6 +581,30 @@ void Free_Eventinfo(Eventinfo *lf) if(lf->systemname) free(lf->systemname); + #ifdef PRELUDE + if(lf->filename) + free(lf->filename); + if (lf->md5_before) + free(lf->md5_before); + if (lf->md5_after) + free(lf->md5_after); + if (lf->sha1_before) + free(lf->sha1_before); + if (lf->sha1_after) + free(lf->sha1_after); + if (lf->size_before) + free(lf->size_before); + if (lf->size_after) + free(lf->size_after); + if (lf->owner_before) + free(lf->owner_before); + if (lf->owner_after) + free(lf->owner_after); + if (lf->gowner_before) + free(lf->gowner_before); + if (lf->gowner_after) + free(lf->gowner_after); + #endif /* Freeing node to delete */ if(lf->sid_node_to_delete) diff --git a/src/analysisd/eventinfo.h b/src/analysisd/eventinfo.h index dcfeb93..3129630 100755 --- a/src/analysisd/eventinfo.h +++ b/src/analysisd/eventinfo.h @@ -1,11 +1,11 @@ -/* @(#) $Id: eventinfo.h,v 1.37 2009/07/24 18:34:11 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -67,8 +67,25 @@ typedef struct _Eventinfo int time; int day; int year; - char hour[9]; + char hour[10]; char mon[4]; + + /* SYSCHECK Results variables -- only used by prelude for now */ + #ifdef PRELUDE + char *filename; + int perm_before; + int perm_after; + char *md5_before; + char *md5_after; + char *sha1_before; + char *sha1_after; + char *size_before; + char *size_after; + char *owner_before; + char *owner_after; + char *gowner_before; + char *gowner_after; + #endif }Eventinfo; @@ -82,6 +99,13 @@ typedef struct _EventNode +/* For test rule only. */ +#ifdef TESTRULE +int full_output; +int alert_only; +#endif + + /** Types of events (from decoders) **/ #define UNKNOWN 0 /* Unkown */ #define SYSLOG 1 /* syslog messages */ diff --git a/src/analysisd/eventinfo_list.c b/src/analysisd/eventinfo_list.c index a98d455..282212d 100755 --- a/src/analysisd/eventinfo_list.c +++ b/src/analysisd/eventinfo_list.c @@ -1,11 +1,11 @@ -/* @(#) $Id: eventinfo_list.c,v 1.7 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/fts.c b/src/analysisd/fts.c index 34eecbd..2f155bf 100755 --- a/src/analysisd/fts.c +++ b/src/analysisd/fts.c @@ -1,11 +1,11 @@ -/* @(#) $Id: fts.c,v 1.34 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -23,7 +23,7 @@ int fts_minsize_for_str = 0; OSList *fts_list = NULL; -OSStore *fts_store = NULL; +OSHash *fts_store = NULL; FILE *fp_list = NULL; FILE *fp_ignore = NULL; @@ -48,13 +48,19 @@ int FTS_Init() } /* Creating store data */ - fts_store = OSStore_Create(); + fts_store = OSHash_Create(); if(!fts_store) { merror(LIST_ERROR, ARGV0); return(0); } + if(!OSHash_setSize(fts_store, 2048)) + { + merror(LIST_ERROR, ARGV0); + return(0); + } + /* Getting default list size */ fts_list_size = getDefine_Int("analysisd", "fts_list_size", @@ -105,8 +111,9 @@ int FTS_Init() os_strdup(_line, tmp_s); - if(!OSStore_Put(fts_store, tmp_s, NULL)) + if(OSHash_Add(fts_store, tmp_s, tmp_s) <= 0) { + free(tmp_s); merror(LIST_ADD_ERROR, ARGV0); } } @@ -246,18 +253,10 @@ int FTS(Eventinfo *lf) /** Checking if FTS is already present **/ - if(lf->decoder_info->type == WINDOWS) - { - /* Windows is case insensitive */ - if(OSStore_NCaseCheck(fts_store, _line)) - { - return(0); - } - } - else if(OSStore_NCheck(fts_store, _line)) + if(OSHash_Get(fts_store, _line)) { return(0); - } + } /* Checking if from the last FTS events, we had @@ -296,9 +295,9 @@ int FTS(Eventinfo *lf) os_strdup(_line, line_for_list); } - if(!OSStore_Put(fts_store, line_for_list, NULL)) + if(OSHash_Add(fts_store, line_for_list, line_for_list) <= 1) { - merror(LIST_ADD_ERROR, ARGV0); + return(0); } diff --git a/src/analysisd/fts.h b/src/analysisd/fts.h index 8fbb9f9..67daee8 100755 --- a/src/analysisd/fts.h +++ b/src/analysisd/fts.h @@ -1,11 +1,11 @@ -/* @(#) $Id: fts.h,v 1.8 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/lists.c b/src/analysisd/lists.c new file mode 100644 index 0000000..4c0b2c4 --- /dev/null +++ b/src/analysisd/lists.c @@ -0,0 +1,63 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 3) as published by the FSF - Free Software + * Foundation. + * + * License details at the LICENSE file included with OSSEC or + * online at: http://www.ossec.net/en/licensing.html + */ + + + +#include "config.h" +#include "eventinfo.h" + + + +/* Lists_OP_CreateLists, v0.1, 2010/01/08 + * Will initilalize the cdb lookup lists + */ +void Lists_OP_CreateLists() +{ + OS_CreateListsList(); + return; +} + +int Lists_OP_LoadList(char * listfile) +{ + /* XXX Jeremy: I hate this. I think I'm missing something dumb here */ + char *holder; + char a_filename[OS_MAXSTR]; + a_filename[OS_MAXSTR - 2] = '\0'; + char b_filename[OS_MAXSTR]; + b_filename[OS_MAXSTR - 2] = '\0'; + + ListNode *tmp_listnode_pt = NULL; + tmp_listnode_pt = (ListNode *)calloc(1,sizeof(ListNode)); + debug1("crated new listnode for %s\n", listfile); + if (tmp_listnode_pt == NULL) + ErrorExit(MEM_ERROR,ARGV0); + snprintf(a_filename, OS_MAXSTR-1, "%s", listfile); + if((strchr(a_filename, '/') == NULL)) + { + /* default to rules/ if a path is not given */ + snprintf(b_filename, OS_MAXSTR-1, "rules/%s", a_filename); + snprintf(a_filename, OS_MAXSTR-1, "%s", b_filename); + } + if((holder = strstr(a_filename, ".cdb"))) + { + snprintf(b_filename, (int)(holder - a_filename) + 1, "%s", a_filename); + snprintf(a_filename, OS_MAXSTR-1, "%s", b_filename); + } + snprintf(b_filename, OS_MAXSTR-1, "%s.cdb", a_filename); + os_strdup(a_filename, tmp_listnode_pt->txt_filename); + os_strdup(b_filename, tmp_listnode_pt->cdb_filename); + tmp_listnode_pt->loaded = 0; + OS_AddList(tmp_listnode_pt); + return 0; +} diff --git a/src/analysisd/lists.h b/src/analysisd/lists.h new file mode 100644 index 0000000..a17cbe7 --- /dev/null +++ b/src/analysisd/lists.h @@ -0,0 +1,57 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 3) as published by the FSF - Free Software + * Foundation + */ + + +/* Rules are needed for lists */ + +#include "cdb/cdb.h" +#include "cdb/uint32.h" + +#define LR_STRING_MATCH 0 +#define LR_STRING_NOT_MATCH 1 +#define LR_STRING_MATCH_VALUE 2 + +#define LR_ADDRESS_MATCH 10 +#define LR_ADDRESS_NOT_MATCH 11 +#define LR_ADDRESS_MATCH_VALUE 12 + + +typedef struct ListNode +{ + int loaded; + char *cdb_filename; + char *txt_filename; + struct cdb cdb; + struct ListNode *next; +}ListNode; + +typedef struct ListRule +{ + int loaded; + int field; + int lookup_type; + OSMatch *matcher; + char *filename; + ListNode *db; + struct ListRule *next; +}ListRule; + +/* create the rule list */ +void OS_CreateListsList(); +/* Add rule information to the list */ +int OS_AddList( ListNode *new_listnode ); +int Lists_OP_LoadList(char *listfile); +int OS_DBSearchKey(ListRule *lrule, char *key); +int OS_DBSearch(ListRule *lrule, char *key); +void OS_ListLoadRules(); +ListRule *OS_AddListRule(ListRule *first_rule_list, int lookup_type, int field, char *listname, OSMatch *matcher); +ListNode *OS_GetFirstList(); +ListNode *OS_FindList(char *listname); diff --git a/src/analysisd/lists_list.c b/src/analysisd/lists_list.c new file mode 100644 index 0000000..1078e55 --- /dev/null +++ b/src/analysisd/lists_list.c @@ -0,0 +1,319 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 3) as published by the FSF - Free Software + * Foundation + */ + + +#include "shared.h" +#include "rules.h" +#include "cdb/cdb.h" +#include +#include +#include +#include + +/* Global */ +ListNode *global_listnode; +ListRule *global_listrule; + +/* + */ +ListNode *_OS_AddList(ListNode *new_listnode); + + +/* Create the ListRule */ +void OS_CreateListsList() +{ + global_listnode = NULL; + global_listrule = NULL; + + return; +} + +/* Get first listnode */ +ListNode *OS_GetFirstList() +{ + ListNode *listnode_pt = global_listnode; + + return(listnode_pt); +} + +ListRule *OS_GetFirstListRule() +{ + ListRule *listrule_pt = global_listrule; + return listrule_pt; +} + +void OS_ListLoadRules() +{ + ListRule *lrule = global_listrule; + while(lrule != NULL) + { + if(!lrule->loaded) + { + lrule->db = OS_FindList(lrule->filename); + lrule->loaded=1; + } + lrule = lrule->next; + } +} + +ListRule *_OS_AddListRule(ListRule *new_listrule) +{ + + if(global_listrule == NULL) + { + global_listrule = new_listrule; + } + else + { + ListRule *last_list_rule = global_listrule; + while(last_list_rule->next != NULL) + { + last_list_rule = last_list_rule->next; + } + last_list_rule->next = new_listrule; + } + return(global_listrule); +} + + + +/* Add a list in the chain */ +ListNode *_OS_AddList(ListNode *new_listnode) +{ + if(global_listnode == NULL) + { + /* First list */ + global_listnode = new_listnode; + } + else + { + /* Adding new list to the end */ + ListNode *last_list_node = global_listnode; + + while(last_list_node->next != NULL) + { + last_list_node = last_list_node->next; + } + last_list_node->next = new_listnode; + + } + return(global_listnode); +} + +/* External AddList */ +int OS_AddList(ListNode *new_listnode) +{ + _OS_AddList(new_listnode); + return(0); +} + +ListNode *_OS_FindList(ListNode *_listnode, char *listname) +{ + ListNode *last_list_node = OS_GetFirstList(); + if (last_list_node != NULL) { + do + { + if (strcmp(last_list_node->txt_filename, listname) == 0 || + strcmp(last_list_node->cdb_filename, listname) == 0) + { + /* Found first match returning */ + return(last_list_node); + } + last_list_node = last_list_node->next; + } while (last_list_node != NULL); + } + return(NULL); +} + +ListNode *OS_FindList(char *listname) +{ + ListNode *matched = NULL; + matched = _OS_FindList(global_listnode, listname); + return matched; +} + +ListRule *OS_AddListRule(ListRule *first_rule_list, + int lookup_type, + int field, + char *listname, + OSMatch *matcher) +{ + ListRule *new_rulelist_pt = NULL; + new_rulelist_pt = (ListRule *)calloc(1,sizeof(ListRule)); + new_rulelist_pt->field = field; + new_rulelist_pt->next = NULL; + new_rulelist_pt->matcher = matcher; + new_rulelist_pt->lookup_type = lookup_type; + new_rulelist_pt->filename = listname; + if((new_rulelist_pt->db = OS_FindList(listname)) == NULL) + new_rulelist_pt->loaded = 0; + else + new_rulelist_pt->loaded = 1; + if(first_rule_list == NULL) + { + debug1("Adding First rulelist item: filename: %s field: %d lookup_type: %d", + new_rulelist_pt->filename, + new_rulelist_pt->field, + new_rulelist_pt->lookup_type); + first_rule_list = new_rulelist_pt; + } + else + { + while(first_rule_list->next) + { + first_rule_list = first_rule_list->next; + } + debug1("Adding rulelist item: filename: %s field: %d lookup_type: %d", + new_rulelist_pt->filename, + new_rulelist_pt->field, + new_rulelist_pt->lookup_type); + first_rule_list->next = new_rulelist_pt; + } + return first_rule_list; +} + +int _OS_CDBOpen(ListNode *lnode) +{ + int fd; + if (lnode->loaded != 1) + { + if((fd = open(lnode->cdb_filename, O_RDONLY)) == -1) + { + merror(OPEN_ERROR, ARGV0, lnode->cdb_filename, strerror (errno)); + return -1; + } + cdb_init(&lnode->cdb, fd); + lnode->loaded = 1; + } + return 0; +} + +int OS_DBSearchKeyValue(ListRule *lrule, char *key) +{ + int result=-1; + char *val; + unsigned vlen, vpos; + if (lrule->db!= NULL) + { + if(_OS_CDBOpen(lrule->db) == -1) return 0; + if(cdb_find(&lrule->db->cdb, key, strlen(key)) > 0 ) { + vpos = cdb_datapos(&lrule->db->cdb); + vlen = cdb_datalen(&lrule->db->cdb); + val = malloc(vlen); + cdb_read(&lrule->db->cdb, val, vlen, vpos); + result = OSMatch_Execute(val, vlen, lrule->matcher); + free(val); + return result; + } else { + return 0; + } + } + return 0; +} + + + +int OS_DBSeachKey(ListRule *lrule, char *key) +{ + if (lrule->db != NULL) + { + if(_OS_CDBOpen(lrule->db) == -1) return -1; + if( cdb_find(&lrule->db->cdb, key, strlen(key)) > 0 ) return 1; + } + return 0; +} + +int OS_DBSeachKeyAddress(ListRule *lrule, char *key) +{ + //char _ip[128]; + //_ip[127] = "\0"; + if (lrule->db != NULL) + { + if(_OS_CDBOpen(lrule->db) == -1) return -1; + //snprintf(_ip,128,"%s",key); + //XXX Breka apart string on the . boundtrys a loop over to longest match. + + if( cdb_find(&lrule->db->cdb, key, strlen(key)) > 0 ) { + return 1; + } + else + { + char *tmpkey; + os_strdup(key, tmpkey); + while(strlen(tmpkey) > 0) + { + if(tmpkey[strlen(tmpkey) - 1] == '.') + { + if( cdb_find(&lrule->db->cdb, tmpkey, strlen(tmpkey)) > 0 ) { + free(tmpkey); + return 1; + } + } + tmpkey[strlen(tmpkey) - 1] = '\0'; + } + free(tmpkey); + } + } + return 0; +} + +int OS_DBSearch(ListRule *lrule, char *key) +{ + //XXX - god damn hack!!! Jeremy Rossi + if (lrule->loaded == 0) + { + lrule->db = OS_FindList(lrule->filename); + lrule->loaded = 1; + } + switch(lrule->lookup_type) + { + case LR_STRING_MATCH: + //debug1("LR_STRING_MATCH"); + if(OS_DBSeachKey(lrule, key) == 1) + return 1; + else + return 0; + break; + case LR_STRING_NOT_MATCH: + //debug1("LR_STRING_NOT_MATCH"); + if(OS_DBSeachKey(lrule, key) == 1) + return 0; + else + return 1; + break; + case LR_STRING_MATCH_VALUE: + //debug1("LR_STRING_MATCH_VALUE"); + // XXX TODO + return 0; + break; + case LR_ADDRESS_MATCH: + //debug1("LR_ADDRESS_MATCH"); + return OS_DBSeachKeyAddress(lrule, key); + break; + case LR_ADDRESS_NOT_MATCH: + //debug1("LR_ADDRESS_NOT_MATCH"); + if(OS_DBSeachKeyAddress(lrule, key) == 0) + return 1; + else + return 0; + break; + case LR_ADDRESS_MATCH_VALUE: + //debug1("LR_ADDRESS_MATCH_VALUE"); + // XXX TODO + return 0; + break; + default: + debug1("lists_list.c::OS_DBSearch should never hit default"); + return 0; + } + return 0; +} + diff --git a/src/analysisd/lists_make.c b/src/analysisd/lists_make.c new file mode 100644 index 0000000..3448916 --- /dev/null +++ b/src/analysisd/lists_make.c @@ -0,0 +1,98 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 3) as published by the FSF - Free Software + * Foundation + */ + +#include "shared.h" +#include "rules.h" +#include "cdb/cdb.h" +#include "cdb/cdb_make.h" +#include +#include +#include +#include +#include "lists_make.h" + +void Lists_OP_MakeAll(int force) +{ + ListNode *lnode = OS_GetFirstList(); + while(lnode) + { + Lists_OP_MakeCDB(lnode->txt_filename, + lnode->cdb_filename, + force); + lnode = lnode->next; + } +} + +void Lists_OP_MakeCDB(char *txt_filename, char *cdb_filename, int force) +{ + /* + struct stat cdb_stat; + struct stat txt_stat; + */ + struct cdb_make cdbm; + FILE *tmp_fd; + FILE *txt_fd; + char *tmp_str; + char *key, *val; + char str[OS_MAXSTR+1]; + + str[OS_MAXSTR]= '\0'; + char tmp_filename[OS_MAXSTR]; + tmp_filename[OS_MAXSTR - 2] = '\0'; + snprintf(tmp_filename, OS_MAXSTR - 2, "%s.tmp", txt_filename); + + /* + if((stat(txt_filename, &txt_stat)) == -1) + debug1("%s: stat of file %s failed", ARGV0, txt_filename); + if((stat(cdb_filename, &cdb_stat)) == -1) + debug1("%s: stat of file %s failed", ARGV0, cdb_filename); + */ + if(File_DateofChange(txt_filename) > File_DateofChange(cdb_filename) || + force) + { + printf(" * File %s need to be updated\n", cdb_filename); + tmp_fd = fopen(tmp_filename, "w+"); + cdb_make_start(&cdbm, tmp_fd); + if(!(txt_fd = fopen(txt_filename, "r"))) + { + merror(FOPEN_ERROR, ARGV0, txt_filename); + return; + } + while((fgets(str, OS_MAXSTR-1,txt_fd)) != NULL) + { + /* Removing new lines or carriage returns. */ + tmp_str = strchr(str, '\r'); + if(tmp_str) + *tmp_str = '\0'; + tmp_str = strchr(str, '\n'); + if(tmp_str) + *tmp_str = '\0'; + if((val = strchr(str, ':'))) + { + *val = '\0'; + val++; + } + else + { + continue; + } + key = str; + cdb_make_add(&cdbm, key, strlen(key), val, strlen(val)); + if(force) print_out(" * adding - key: %s value: %s",key,val); + } + cdb_make_finish(&cdbm); + rename(tmp_filename,cdb_filename); + } + else + { + printf(" * File %s does not need to be compiled\n", cdb_filename); + } +} diff --git a/src/analysisd/lists_make.h b/src/analysisd/lists_make.h new file mode 100644 index 0000000..4a22e4d --- /dev/null +++ b/src/analysisd/lists_make.h @@ -0,0 +1,15 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 3) as published by the FSF - Free Software + * Foundation + */ + + +void makelist_help(const char *prog); +void Lists_OP_MakeCDB(char *txt_filename, char *cdb_filename, int force); +void Lists_OP_MakeAll(int force); diff --git a/src/analysisd/makelists.c b/src/analysisd/makelists.c new file mode 100644 index 0000000..9299592 --- /dev/null +++ b/src/analysisd/makelists.c @@ -0,0 +1,190 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation. + * + * License details at the LICENSE file included with OSSEC or + * online at: http://www.ossec.net/en/licensing.html + */ + + +/* Part of the OSSEC + * Available at http://www.ossec.net + */ + + +/* ossec-analysisd. + * Responsible for correlation and log decoding. + */ +#ifdef ARGV0 + #undef ARGV0 + #define ARGV0 "ossec-testrule" +#endif + +#include "shared.h" + + +/** Local headers **/ +#include "active-response.h" +#include "config.h" +#include "rules.h" +#include "stats.h" +#include "lists_make.h" + +#include "eventinfo.h" +#include "analysisd.h" + +#include "picviz.h" + + + +/** External functions prototypes (only called here) **/ + +/* For config */ +int GlobalConf(char * cfgfile); + + +/* For Lists */ +void Lists_OP_CreateLists(); + +void makelist_help(const char *prog) +{ + print_out(" "); + print_out("%s %s - %s (%s)", __name, __version, __author, __contact); + print_out("%s", __site); + print_out(" "); + print_out(" %s: -[Vhdt] [-u user] [-g group] [-c config] [-D dir]", prog); + print_out(" -V Version and license message"); + print_out(" -h This help message"); + print_out(" -d Execute in debug mode"); + print_out(" -f Force rebuild of all databases"); + print_out(" -u Run as 'user'"); + print_out(" -g Run as 'group'"); + print_out(" -c Read the 'config' file"); + print_out(" -D Chroot to 'dir'"); + print_out(" "); + exit(1); +} + +/** int main(int argc, char **argv) + */ +int main(int argc, char **argv) +{ + int c = 0; + char *dir = DEFAULTDIR; + char *user = USER; + char *group = GROUPGLOBAL; + int uid = 0,gid = 0; + int force = 0; + + char *cfg = DEFAULTCPATH; + + /* Setting the name */ + OS_SetName(ARGV0); + + thishour = 0; + today = 0; + prev_year = 0; + memset(prev_month, '\0', 4); + + while((c = getopt(argc, argv, "Vdhfu:g:D:c:")) != -1){ + switch(c){ + case 'V': + print_version(); + break; + case 'h': + makelist_help(ARGV0); + break; + case 'd': + nowDebug(); + break; + case 'u': + if(!optarg) + ErrorExit("%s: -u needs an argument",ARGV0); + user = optarg; + break; + case 'g': + if(!optarg) + ErrorExit("%s: -g needs an argument",ARGV0); + group = optarg; + break; + case 'D': + if(!optarg) + ErrorExit("%s: -D needs an argument",ARGV0); + dir = optarg; + case 'c': + if(!optarg) + ErrorExit("%s: -c needs an argument",ARGV0); + cfg = optarg; + break; + case 'f': + force = 1; + break; + default: + help(ARGV0); + break; + } + + } + + + /*Check if the user/group given are valid */ + uid = Privsep_GetUser(user); + gid = Privsep_GetGroup(group); + if((uid < 0)||(gid < 0)) + ErrorExit(USER_ERROR,ARGV0,user,group); + + + /* Found user */ + debug1(FOUND_USER, ARGV0); + + + /* Reading configuration file */ + if(GlobalConf(cfg) < 0) + { + ErrorExit(CONFIG_ERROR,ARGV0, cfg); + } + + debug1(READ_CONFIG, ARGV0); + + /* Setting the group */ + if(Privsep_SetGroup(gid) < 0) + ErrorExit(SETGID_ERROR,ARGV0,group); + + /* Chrooting */ + if(Privsep_Chroot(dir) < 0) + ErrorExit(CHROOT_ERROR,ARGV0,dir); + + nowChroot(); + + + + /* Createing the lists for use in rules */ + Lists_OP_CreateLists(); + + /* Reading the lists */ + { + char **listfiles; + listfiles = Config.lists; + while(listfiles && *listfiles) + { + if(Lists_OP_LoadList(*listfiles) < 0) + ErrorExit(LISTS_ERROR, ARGV0, *listfiles); + free(*listfiles); + listfiles++; + } + free(Config.lists); + Config.lists = NULL; + } + + Lists_OP_MakeAll(force); + + exit(0); +} + +/* EOF */ diff --git a/src/analysisd/makelists.h b/src/analysisd/makelists.h new file mode 100644 index 0000000..e69de29 diff --git a/src/analysisd/picviz.c b/src/analysisd/picviz.c index 8f9a320..960bcad 100644 --- a/src/analysisd/picviz.c +++ b/src/analysisd/picviz.c @@ -1,4 +1,4 @@ -/* @(#) $Id: picviz.c,v 1.2 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Sebastien Tricaud * Copyright (C) 2009 Trend Micro Inc. @@ -6,7 +6,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/picviz.h b/src/analysisd/picviz.h index 89c6501..2e71f84 100644 --- a/src/analysisd/picviz.h +++ b/src/analysisd/picviz.h @@ -1,4 +1,4 @@ -/* @(#) $Id: picviz.h,v 1.2 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Sebastien Tricaud * Copyright (C) 2009 Trend Micro Inc. @@ -6,7 +6,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/prelude.c b/src/analysisd/prelude.c index 39f8e85..1dfcf2c 100644 --- a/src/analysisd/prelude.c +++ b/src/analysisd/prelude.c @@ -1,11 +1,11 @@ -/* @(#) $Id: prelude.c,v 1.14 2009/11/09 20:18:52 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -19,13 +19,16 @@ #include "prelude.h" #include "shared.h" #include "eventinfo.h" +#include "rules.h" #define DEFAULT_ANALYZER_NAME "OSSEC" #define ANALYZER_CLASS "Host IDS, File Integrity Checker, Log Analyzer" #define ANALYZER_MODEL "Ossec" #define ANALYZER_MANUFACTURER __site #define ANALYZER_VERSION __version - +#define FILE_USER 0 +#define FILE_GROUP 1 +#define FILE_OTHER 2 /* * Ossec to Prelude @@ -205,18 +208,140 @@ void prelude_start(char *profile, int argc, char **argv) } +void FileAccess_PreludeLog(idmef_message_t *idmef, + int filenum, + char *filename, + char *md5, + char *sha1, + char *owner, + char *gowner, + int perm) { + + int _checksum_counter = 0; + char _prelude_section[128]; + _prelude_section[127] = '\0'; + + debug1("%s: DEBUG: filename = %s.", ARGV0, filename); + debug1("%s: DEBUG: filenum = %d.", ARGV0, filenum); + if (filenum == 0) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).name",filenum); + add_idmef_object(idmef, _prelude_section, filename); + snprintf(_prelude_section,128,"alert.target(0).file(%d).category",filenum); + add_idmef_object(idmef, _prelude_section, "original"); + } else if (filenum == 1) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).name",filenum); + add_idmef_object(idmef, _prelude_section, filename); + snprintf(_prelude_section,128,"alert.target(0).file(%d).category",filenum); + add_idmef_object(idmef, _prelude_section, "current"); + } else { + return; + } + + + /* Add the hashs */ + if (md5) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).checksum(%d).algorithm",filenum, _checksum_counter); + add_idmef_object(idmef, _prelude_section, "MD5"); + snprintf(_prelude_section,128,"alert.target(0).file(%d).checksum(%d).value",filenum, _checksum_counter); + add_idmef_object(idmef, _prelude_section, md5); + _checksum_counter++; + } + if (sha1) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).checksum(%d).algorithm",filenum, _checksum_counter); + add_idmef_object(idmef, _prelude_section, "SHA1"); + snprintf(_prelude_section,128,"alert.target(0).file(%d).checksum(%d).value",filenum, _checksum_counter); + add_idmef_object(idmef, _prelude_section, sha1); + _checksum_counter++; + } + + /* add the owner */ + if (owner) { + debug1("%s: DEBUG: owner = %s.", ARGV0, owner); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).user_id.number",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,owner); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).user_id.type",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section, "user-privs"); + } + /*add the group owner */ + if (gowner) { + debug1("%s: DEBUG: gowner = %s.", ARGV0, gowner); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).user_id.number",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,gowner); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).user_id.type",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section, "group-privs"); + } + /*add the permissions */ + if (perm) { + if (perm & S_IWUSR) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(0)",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,"write"); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(1)",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,"delete"); + } + if (perm & S_IXUSR) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(2)",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,"execute"); + } + if (perm & S_IRUSR ) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(3)",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,"read"); + } + if (perm & S_ISUID) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(4)",filenum,FILE_USER); + add_idmef_object(idmef, _prelude_section,"executeAs"); + } + + if (perm & S_IWGRP) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(0)",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,"write"); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(1)",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,"delete"); + } + if (perm & S_IXGRP) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(2)",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,"execute"); + } + if (perm & S_IRGRP ) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(3)",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,"read"); + } + if (perm & S_ISGID) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(4)",filenum,FILE_GROUP); + add_idmef_object(idmef, _prelude_section,"executeAs"); + } + if (perm & S_IWOTH) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(0)",filenum,FILE_OTHER); + add_idmef_object(idmef, _prelude_section,"write"); + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(1)",filenum,FILE_OTHER); + add_idmef_object(idmef, _prelude_section,"delete"); + } + if (perm & S_IXOTH) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(2)",filenum,FILE_OTHER); + add_idmef_object(idmef, _prelude_section,"execute"); + } + if (perm & S_IROTH ) { + snprintf(_prelude_section,128,"alert.target(0).file(%d).File_Access(%d).permission(3)",filenum,FILE_OTHER); + add_idmef_object(idmef, _prelude_section,"read"); + } + } + return; +} void OS_PreludeLog(Eventinfo *lf) { int ret; + int classification_counter = 0; + int additional_data_counter = 0; + char _prelude_section[128]; + char _prelude_data[256]; idmef_message_t *idmef; + RuleInfoDetail *last_info_detail; /* Generate prelude alert */ ret = idmef_message_new(&idmef); - if ( ret < 0 ) - { + if ( ret < 0 ) { merror("%s: OSSEC2Prelude: Cannot create IDMEF message", ARGV0); return; } @@ -224,86 +349,307 @@ void OS_PreludeLog(Eventinfo *lf) add_idmef_object(idmef, "alert.assessment.impact.description", lf->generated_rule->comment); - + add_idmef_object(idmef, "alert.assessment.impact.severity", (lf->generated_rule->level > 15) ? "high": ossec2prelude_sev[lf->generated_rule->level]); - + add_idmef_object(idmef, "alert.assessment.impact.completion", "succeeded"); - - add_idmef_object(idmef, "alert.classification.text", - lf->generated_rule->comment); - - - /* Setting source info. */ - add_idmef_object(idmef, "alert.source(0).Spoofed", "no"); - add_idmef_object(idmef, "alert.source(0).Node.Address(0).address", - lf->srcip); - add_idmef_object(idmef, "alert.source(0).Service.port", lf->srcport); - if(lf->srcuser) + if (lf->action) { - add_idmef_object(idmef, "alert.source(0).User.UserId(0).name", lf->srcuser); + switch(*lf->action) + { + /* discard, drop, deny, */ + case 'd': + case 'D': + /* reject, */ + case 'r': + case 'R': + /* block */ + case 'b': + case 'B': + snprintf(_prelude_data,256,"DROP: %s", lf->action); + break; + /* Closed */ + case 'c': + case 'C': + /* Teardown */ + case 't': + case 'T': + snprintf(_prelude_data,256,"CLOSED: %s", lf->action); + break; + /* allow, accept, */ + case 'a': + case 'A': + /* pass/permitted */ + case 'p': + case 'P': + /* open */ + case 'o': + case 'O': + snprintf(_prelude_data,256,"ALLOW: %s", lf->action); + break; + default: + snprintf(_prelude_data,256,"%s", lf->action); + break; + } + add_idmef_object(idmef, "alert.assessment.action(0).category", "3"); + add_idmef_object(idmef, "alert.assessment.action(0).description", _prelude_data); } - /* Setting target */ - add_idmef_object(idmef, "alert.target(0).Service.name", lf->program_name); - add_idmef_object(idmef, "alert.target(0).Spoofed", "no"); - if(lf->dstip) - { - add_idmef_object(idmef, "alert.target(0).Node.Address(0).address", - lf->dstip); - } - else + + + + /* Begin Classification Infomations */ { - char *tmp_str; - char new_prelude_target[256]; + add_idmef_object(idmef, "alert.classification.text", + lf->generated_rule->comment); - new_prelude_target[255] = '\0'; - strncpy(new_prelude_target, lf->hostname, 255); - /* The messages can have the file, so we need to remove it. - * formats can be: - * enigma->/var/log/authlog - * (esqueleto2) 192.168.2.99->/var/log/squid/access.log + /* The Common Vulnerabilities and Exposures (CVE) (http://www.cve.mitre.org/) + * infomation if present in the triggering rule */ - tmp_str = strstr(new_prelude_target, "->"); - if(tmp_str) + if(lf->generated_rule->cve) { - *tmp_str = '\0'; + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + add_idmef_object(idmef, _prelude_section, "cve"); + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + add_idmef_object(idmef, _prelude_section, lf->generated_rule->cve); + snprintf(_prelude_section,128,"alert.classification.reference(%d).meaning", + classification_counter); + snprintf(_prelude_data,256,"CVE:%s", lf->generated_rule->cve); + add_idmef_object(idmef, _prelude_section, _prelude_data); + classification_counter++; } - add_idmef_object(idmef, "alert.target(0).Node.Address(0).address", - new_prelude_target); - } - add_idmef_object(idmef, "alert.target(0).Service.name", lf->hostname); - add_idmef_object(idmef, "alert.target(0).Service.port", lf->dstport); - if(lf->dstuser) - { - add_idmef_object(idmef, "alert.target(0).User.category", "2"); - add_idmef_object(idmef, "alert.target(0).User.UserId(0).name", lf->dstuser); - } + /* Rule sid is used to create a link to the rule on the OSSEC wiki */ + if(lf->generated_rule->sigid) + { + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + add_idmef_object(idmef, _prelude_section, "vendor-specific"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + snprintf(_prelude_data,256,"Rule:%d",lf->generated_rule->sigid); + add_idmef_object(idmef, _prelude_section, _prelude_data); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).meaning", + classification_counter); + add_idmef_object(idmef, _prelude_section, "OSSEC Rule Wiki Documentation"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).url", + classification_counter); + snprintf(_prelude_data, 256,"http://www.ossec.net/wiki/Rule:%d", + lf->generated_rule->sigid); + add_idmef_object(idmef, _prelude_section, _prelude_data); + + classification_counter++; + } + + /* Extended Info Details */ + for (last_info_detail = lf->generated_rule->info_details; + last_info_detail != NULL; + last_info_detail = last_info_detail->next) + { + if (last_info_detail->type == RULEINFODETAIL_LINK) + { + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + add_idmef_object(idmef, _prelude_section, "vendor-specific"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + snprintf(_prelude_data,256,"Rule:%d link",lf->generated_rule->sigid); + add_idmef_object(idmef, _prelude_section, _prelude_data); + snprintf(_prelude_section,128,"alert.classification.reference(%d).url", + classification_counter); + add_idmef_object(idmef, _prelude_section, last_info_detail->data); + + classification_counter++; + } + else if(last_info_detail->type == RULEINFODETAIL_TEXT) + { + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + add_idmef_object(idmef, _prelude_section, "vendor-specific"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + snprintf(_prelude_data,256,"Rule:%d info",lf->generated_rule->sigid); + add_idmef_object(idmef, _prelude_section, _prelude_data); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).meaning", + classification_counter); + add_idmef_object(idmef, _prelude_section, last_info_detail->data); + classification_counter++; + } + else + { + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + switch(last_info_detail->type) + { + case RULEINFODETAIL_CVE: + add_idmef_object(idmef, _prelude_section, "cve"); + break; + case RULEINFODETAIL_OSVDB: + add_idmef_object(idmef, _prelude_section, "osvdb"); + break; + case RULEINFODETAIL_BUGTRACK: + add_idmef_object(idmef, _prelude_section, "bugtraqid"); + break; + default: + add_idmef_object(idmef, _prelude_section, "vendor-specific"); + break; + } + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + add_idmef_object(idmef, _prelude_section, last_info_detail->data); + } + } + /* Break ok the list of groups on the "," boundry + * For each section create a prelude reference classification + * that points back to the the OSSEC wiki for more infomation. + */ + if(lf->generated_rule->group) + { + char *copy_group; + char new_generated_rule_group[256]; + new_generated_rule_group[255] = '\0'; + strncpy(new_generated_rule_group, lf->generated_rule->group, 255); + copy_group = strtok(new_generated_rule_group, ","); + while (copy_group) { + snprintf(_prelude_section,128,"alert.classification.reference(%d).origin", + classification_counter); + add_idmef_object(idmef, _prelude_section, "vendor-specific"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).name", + classification_counter); + snprintf(_prelude_data,256,"Group:%s",copy_group); + add_idmef_object(idmef, _prelude_section, _prelude_data); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).meaning", + classification_counter); + add_idmef_object(idmef, _prelude_section, "OSSEC Group Wiki Documenation"); + + snprintf(_prelude_section,128,"alert.classification.reference(%d).url", + classification_counter); + snprintf(_prelude_data,256,"http://www.ossec.net/wiki/Group:%s", + copy_group); + add_idmef_object(idmef, _prelude_section, _prelude_data); + + classification_counter++; + copy_group = strtok(NULL, ","); + } + } + } /* end classification block */ + + + + /* Begin Node infomation block */ + { + /* Setting source info. */ + add_idmef_object(idmef, "alert.source(0).Spoofed", "no"); + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address", + lf->srcip); + add_idmef_object(idmef, "alert.source(0).Service.port", lf->srcport); + + if(lf->srcuser) + { + add_idmef_object(idmef, "alert.source(0).User.UserId(0).name", lf->srcuser); + } + + + /* Setting target */ + add_idmef_object(idmef, "alert.target(0).Service.name", lf->program_name); + add_idmef_object(idmef, "alert.target(0).Spoofed", "no"); + + if(lf->dstip) + { + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address", + lf->dstip); + } + else + { + char *tmp_str; + char new_prelude_target[256]; + + new_prelude_target[255] = '\0'; + strncpy(new_prelude_target, lf->hostname, 255); + + /* The messages can have the file, so we need to remove it. + * formats can be: + * enigma->/var/log/authlog + * (esqueleto2) 192.168.2.99->/var/log/squid/access.log + */ + tmp_str = strstr(new_prelude_target, "->"); + if(tmp_str) + { + *tmp_str = '\0'; + } + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address", + new_prelude_target); + } + add_idmef_object(idmef, "alert.target(0).Service.name", lf->hostname); + add_idmef_object(idmef, "alert.target(0).Service.port", lf->dstport); + + if(lf->dstuser) + { + add_idmef_object(idmef, "alert.target(0).User.category", "2"); + add_idmef_object(idmef, "alert.target(0).User.UserId(0).name", lf->dstuser); + } + } /* end Node infomation block */ + + /* Setting source file. */ add_idmef_object(idmef, "alert.additional_data(0).type", "string"); add_idmef_object(idmef, "alert.additional_data(0).meaning", "Source file"); add_idmef_object(idmef, "alert.additional_data(0).data", lf->location); + additional_data_counter++; /* Setting full log. */ add_idmef_object(idmef, "alert.additional_data(1).type", "string"); add_idmef_object(idmef, "alert.additional_data(1).meaning", "Full Log"); add_idmef_object(idmef, "alert.additional_data(1).data", lf->full_log); + additional_data_counter++; idmef_alert_set_analyzer(idmef_message_get_alert(idmef), idmef_analyzer_ref (prelude_client_get_analyzer(prelude_client)), IDMEF_LIST_PREPEND); + debug1("%s: DEBUG: lf->filename = %s.", ARGV0, lf->filename); + if (lf->filename) { + FileAccess_PreludeLog(idmef, + 0, + lf->filename, + lf->md5_before, + lf->sha1_before, + lf->owner_before, + lf->gowner_before, + lf->perm_before); + FileAccess_PreludeLog(idmef, + 1, + lf->filename, + lf->md5_after, + lf->sha1_after, + lf->owner_after, + lf->gowner_after, + lf->perm_after); + debug1("%s: DEBUG: done with alert.target(0).file(1)", ARGV0); + } + debug1("%s: DEBUG: Sending IDMEF alert", ARGV0); prelude_client_send_idmef(prelude_client, idmef); + debug1("%s: DEBUG: destroying IDMEF alert", ARGV0); idmef_message_destroy(idmef); } diff --git a/src/analysisd/prelude.h b/src/analysisd/prelude.h index 8ea6a7d..d898718 100644 --- a/src/analysisd/prelude.h +++ b/src/analysisd/prelude.h @@ -1,11 +1,11 @@ -/* $Id: prelude.h,v 1.6 2009/06/24 17:06:22 dcid Exp $ */ +/* $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * More details at the LICENSE file included with OSSEC or diff --git a/src/analysisd/rules.c b/src/analysisd/rules.c index 8c97197..8ce5f8d 100755 --- a/src/analysisd/rules.c +++ b/src/analysisd/rules.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rules.c,v 1.79 2009/11/04 18:45:37 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -57,8 +57,6 @@ void Rules_OP_CreateRules() return; } - - /* Rules_OP_ReadRules, v0.3, 2005/03/21 * Read the log rules. * v0.3: Fixed many memory problems. @@ -99,7 +97,18 @@ int Rules_OP_ReadRules(char * rulefile) char *xml_status = "status"; char *xml_action = "action"; char *xml_compiled = "compiled_rule"; - + + char *xml_list = "list"; + char *xml_list_lookup = "lookup"; + char *xml_list_field = "field"; + char *xml_list_cvalue = "check_value"; + char *xml_match_key = "match_key"; + char *xml_not_match_key = "not_match_key"; + char *xml_match_key_value = "match_key_value"; + char *xml_address_key = "address_match_key"; + char *xml_not_address_key = "not_address_match_key"; + char *xml_address_key_value = "address_match_key_value"; + char *xml_if_sid = "if_sid"; char *xml_if_group = "if_group"; char *xml_if_level = "if_level"; @@ -115,6 +124,7 @@ int Rules_OP_ReadRules(char * rulefile) char *xml_same_user = "same_user"; char *xml_same_location = "same_location"; char *xml_same_id = "same_id"; + char *xml_dodiff = "check_diff"; char *xml_different_url = "different_url"; @@ -131,15 +141,25 @@ int Rules_OP_ReadRules(char * rulefile) int default_timeframe = 360; - /* Building the rule file name + path */ - i = strlen(RULEPATH) + strlen(rulefile) + 2; - rulepath = (char *)calloc(i,sizeof(char)); - if(!rulepath) + /* If no directory in the rulefile add the default */ + if((strchr(rulefile, '/')) == NULL) { - ErrorExit(MEM_ERROR,ARGV0); + /* Building the rule file name + path */ + i = strlen(RULEPATH) + strlen(rulefile) + 2; + rulepath = (char *)calloc(i,sizeof(char)); + if(!rulepath) + { + ErrorExit(MEM_ERROR,ARGV0); + } + snprintf(rulepath,i,"%s/%s",RULEPATH,rulefile); + } + else + { + os_strdup(rulefile, rulepath); + debug1("%s is the rulefile", rulefile); + debug1("Not modifing the rule path"); } - snprintf(rulepath,i,"%s/%s",RULEPATH,rulefile); i = 0; @@ -338,6 +358,9 @@ int Rules_OP_ReadRules(char * rulefile) /* Rule elements block */ { int k = 0; + int info_type = 0; + int count_info_detail = 0; + RuleInfoDetail *last_info_detail = NULL; char *regex = NULL; char *match = NULL; char *url = NULL; @@ -393,8 +416,61 @@ int Rules_OP_ReadRules(char * rulefile) return(-1); } } + else if(strcasecmp(rule_opt[k]->element,xml_cve)==0) + { + if(config_ruleinfo->info_details == NULL) + { + config_ruleinfo->info_details = zeroinfodetails(RULEINFODETAIL_CVE, + rule_opt[k]->content); + } + else + { + for (last_info_detail = config_ruleinfo->info_details; + last_info_detail->next != NULL; + last_info_detail = last_info_detail->next) + { + count_info_detail++; + } + /* Silently Drop info messages if their are more then MAX_RULEINFODETAIL */ + if (count_info_detail <= MAX_RULEINFODETAIL) + { + last_info_detail->next = zeroinfodetails(RULEINFODETAIL_CVE, + rule_opt[k]->content); + } + } + + /* keep old methods for now */ + config_ruleinfo->cve= + loadmemory(config_ruleinfo->cve, + rule_opt[k]->content); + } else if(strcasecmp(rule_opt[k]->element,xml_info)==0) { + + info_type = get_info_attributes(rule_opt[k]->attributes, + rule_opt[k]->values); + debug1("info_type = %d", info_type); + + if(config_ruleinfo->info_details == NULL) + { + config_ruleinfo->info_details = zeroinfodetails(info_type, + rule_opt[k]->content); + } + else + { + for (last_info_detail = config_ruleinfo->info_details; + last_info_detail->next != NULL; + last_info_detail = last_info_detail->next) { + count_info_detail++; + } + /* Silently Drop info messages if their are more then MAX_RULEINFODETAIL */ + if (count_info_detail <= MAX_RULEINFODETAIL) { + last_info_detail->next = zeroinfodetails(info_type, rule_opt[k]->content); + } + } + + + /* keep old methods for now */ config_ruleinfo->info= loadmemory(config_ruleinfo->info, rule_opt[k]->content); @@ -435,12 +511,6 @@ int Rules_OP_ReadRules(char * rulefile) loadmemory(config_ruleinfo->group, rule_opt[k]->content); } - else if(strcasecmp(rule_opt[k]->element,xml_cve)==0) - { - config_ruleinfo->cve= - loadmemory(config_ruleinfo->cve, - rule_opt[k]->content); - } else if(strcasecmp(rule_opt[k]->element,xml_comment)==0) { char *newline; @@ -593,6 +663,132 @@ int Rules_OP_ReadRules(char * rulefile) loadmemory(config_ruleinfo->action, rule_opt[k]->content); } + else if(strcasecmp(rule_opt[k]->element,xml_list)==0) + { + debug1("-> %s == %s",rule_opt[k]->element, xml_list); + if (rule_opt[k]->attributes && rule_opt[k]->values && rule_opt[k]->content) + { + int list_att_num=0; + int rule_type=0; + OSMatch *matcher=NULL; + int lookup_type = LR_STRING_MATCH; + while(rule_opt[k]->attributes[list_att_num]) + { + if(strcasecmp(rule_opt[k]->attributes[list_att_num], xml_list_lookup) == 0) + { + if(strcasecmp(rule_opt[k]->values[list_att_num],xml_match_key) == 0) + lookup_type = LR_STRING_MATCH; + else if(strcasecmp(rule_opt[k]->values[list_att_num],xml_not_match_key)==0) + lookup_type = LR_STRING_NOT_MATCH; + else if(strcasecmp(rule_opt[k]->values[list_att_num],xml_match_key_value)==0) + lookup_type = LR_STRING_MATCH_VALUE; + else if(strcasecmp(rule_opt[k]->values[list_att_num],xml_address_key)==0) + lookup_type = LR_ADDRESS_MATCH; + else if(strcasecmp(rule_opt[k]->values[list_att_num],xml_not_address_key)==0) + lookup_type = LR_ADDRESS_NOT_MATCH; + else if(strcasecmp(rule_opt[k]->values[list_att_num],xml_address_key_value)==0) + lookup_type = LR_ADDRESS_MATCH_VALUE; + else + { + merror(INVALID_CONFIG, ARGV0, + rule_opt[k]->element, + rule_opt[k]->content); + merror("%s: List match lookup=\"%s\" is not valid.", + ARGV0,rule_opt[k]->values[list_att_num]); + return(-1); + } + } + else if(strcasecmp(rule_opt[k]->attributes[list_att_num], xml_list_field)==0) + { + if(strcasecmp(rule_opt[k]->values[list_att_num],xml_srcip)==0) + rule_type = RULE_SRCIP; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_srcport)==0) + rule_type = RULE_SRCPORT; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_dstip)==0) + rule_type = RULE_DSTIP; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_dstport)==0) + rule_type = RULE_DSTPORT; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_user)==0) + rule_type = RULE_USER; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_url)==0) + rule_type = RULE_URL; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_id)==0) + rule_type = RULE_ID; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_hostname)==0) + rule_type = RULE_HOSTNAME; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_program_name)==0) + rule_type = RULE_PROGRAM_NAME; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_status)==0) + rule_type = RULE_STATUS; + else if (strcasecmp(rule_opt[k]->values[list_att_num],xml_action)==0) + rule_type = RULE_ACTION; + else + { + merror(INVALID_CONFIG, ARGV0, + rule_opt[k]->element, + rule_opt[k]->content); + merror("%s: List match field=\"%s\" is not valid.", + ARGV0,rule_opt[k]->values[list_att_num]); + return(-1); + } + } + else if(strcasecmp(rule_opt[k]->attributes[list_att_num], xml_list_cvalue)==0) + { + os_calloc(1, sizeof(OSMatch), matcher); + if(!OSMatch_Compile(rule_opt[k]->values[list_att_num], matcher, 0)) + { + merror(INVALID_CONFIG, ARGV0, + rule_opt[k]->element, + rule_opt[k]->content); + merror(REGEX_COMPILE, + ARGV0, + rule_opt[k]->values[list_att_num], + matcher->error); + return(-1); + } + } + else + { + merror("%s:List feild=\"%s\" is not valid",ARGV0, + rule_opt[k]->values[list_att_num]); + merror(INVALID_CONFIG, ARGV0, + rule_opt[k]->element, rule_opt[k]->content); + return(-1); + } + list_att_num++; + } + if(rule_type == 0) + { + merror("%s:List requires the field=\"\" Attrubute",ARGV0); + merror(INVALID_CONFIG, ARGV0, + rule_opt[k]->element, rule_opt[k]->content); + return(-1); + } + + /* Wow it's all ready - this seams too complex to get to this point */ + config_ruleinfo->lists = OS_AddListRule(config_ruleinfo->lists, + lookup_type, + rule_type, + rule_opt[k]->content, + matcher); + if (config_ruleinfo->lists == NULL) + { + merror("%s: List error: Could not load %s", ARGV0, rule_opt[k]->content); + return(-1); + } + } + else + { + merror("%s:List must have a correctly formatted feild attribute", + ARGV0); + merror(INVALID_CONFIG, + ARGV0, + rule_opt[k]->element, + rule_opt[k]->content); + return(-1); + } + /* xml_list eval is done */ + } else if(strcasecmp(rule_opt[k]->element,xml_url)==0) { url= @@ -735,6 +931,14 @@ int Rules_OP_ReadRules(char * rulefile) config_ruleinfo->alert_opts |= SAME_EXTRAINFO; } else if(strcasecmp(rule_opt[k]->element, + xml_dodiff)==0) + { + config_ruleinfo->context++; + config_ruleinfo->context_opts|= SAME_DODIFF; + if(!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) + config_ruleinfo->alert_opts |= DO_EXTRAINFO; + } + else if(strcasecmp(rule_opt[k]->element, xml_same_dst_port) == 0) { config_ruleinfo->context_opts|= SAME_DSTPORT; @@ -827,6 +1031,13 @@ int Rules_OP_ReadRules(char * rulefile) config_ruleinfo->alert_opts &=0xfff-DO_LOGALERT; } } + else if(strcmp("no_ar", rule_opt[k]->content) == 0) + { + if(!(config_ruleinfo->alert_opts & NO_AR)) + { + config_ruleinfo->alert_opts|= NO_AR; + } + } else { merror(XML_VALUEERR, ARGV0, xml_options, @@ -1238,8 +1449,16 @@ int Rules_OP_ReadRules(char * rulefile) } else if(config_ruleinfo->context) { - config_ruleinfo->event_search = + if((config_ruleinfo->context == 1) && + (config_ruleinfo->context_opts & SAME_DODIFF)) + { + config_ruleinfo->context = 0; + } + else + { + config_ruleinfo->event_search = (void *)Search_LastEvents; + } } } /* while(rule[j]) */ @@ -1335,6 +1554,29 @@ char *loadmemory(char *at, char *str) } +RuleInfoDetail *zeroinfodetails(int type, char *data) +{ + RuleInfoDetail *info_details_pt = NULL; + + info_details_pt = (RuleInfoDetail *)calloc(1,sizeof(RuleInfoDetail)); + + if (info_details_pt == NULL) + { + ErrorExit(MEM_ERROR,ARGV0); + } + /* type */ + info_details_pt->type = type; + + /* data */ + os_strdup(data, info_details_pt->data); + + info_details_pt->next = NULL; + + + return(info_details_pt); +} + + RuleInfo *zerorulemember(int id, int level, int maxsize, int frequency, int timeframe, int noalert, @@ -1403,6 +1645,7 @@ RuleInfo *zerorulemember(int id, int level, ruleinfo_pt->comment = NULL; ruleinfo_pt->info = NULL; ruleinfo_pt->cve = NULL; + ruleinfo_pt->info_details = NULL; ruleinfo_pt->if_sid = NULL; ruleinfo_pt->if_group = NULL; @@ -1437,10 +1680,48 @@ RuleInfo *zerorulemember(int id, int level, ruleinfo_pt->event_search = NULL; ruleinfo_pt->compiled_rule = NULL; + ruleinfo_pt->lists = NULL; return(ruleinfo_pt); } +int get_info_attributes(char **attributes, char **values) +{ + char *xml_type = "type"; + int k=0; + if(!attributes) + return(RULEINFODETAIL_TEXT); + + while(attributes[k]) + { + if (!values[k]) + { + merror("rules_op: Entry info type \"%s\" does not have a value", + attributes[k]); + return (-1); + } + else if(strcasecmp(attributes[k],xml_type) == 0) + { + if(strcmp(values[k], "text") == 0) + { + return(RULEINFODETAIL_TEXT); + } + else if(strcmp(values[k], "link") == 0) + { + return(RULEINFODETAIL_LINK); + } + else if(strcmp(values[k], "cve") == 0) + { + return(RULEINFODETAIL_CVE); + } + else if(strcmp(values[k], "osvdb") == 0) + { + return(RULEINFODETAIL_OSVDB); + } + } + } + return(RULEINFODETAIL_TEXT); +} /* Get the attributes */ int getattributes(char **attributes, char **values, @@ -1641,6 +1922,12 @@ void Rule_AddAR(RuleInfo *rule_config) return; } + /* No AR when options no_ar is set */ + if(rule_config->alert_opts & NO_AR) + { + return; + } + if(!active_responses) { return; diff --git a/src/analysisd/rules.h b/src/analysisd/rules.h index c61df28..0f77df4 100755 --- a/src/analysisd/rules.h +++ b/src/analysisd/rules.h @@ -1,11 +1,11 @@ -/* @(#) $Id: rules.h,v 1.41 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -18,6 +18,8 @@ #include "shared.h" #include "active-response.h" +#include "lists.h" + /* Event context - stored on a uint8 */ #define SAME_USER 0x001 /* 1 */ @@ -27,6 +29,7 @@ #define DIFFERENT_URL 0x010 /* */ #define SAME_SRCPORT 0x020 #define SAME_DSTPORT 0x040 +#define SAME_DODIFF 0x100 #define NOT_SAME_USER 0xffe /* 0xfff - 0x001 */ #define NOT_SAME_SRCIP 0xffd /* 0xfff - 0x002 */ #define NOT_SAME_ID 0xffb /* 0xfff - 0x004 */ @@ -36,12 +39,41 @@ #define DO_FTS 0x001 #define DO_MAILALERT 0x002 #define DO_LOGALERT 0x004 +#define NO_AR 0x008 #define NO_ALERT 0x010 #define DO_OVERWRITE 0x020 #define DO_PACKETINFO 0x040 #define DO_EXTRAINFO 0x100 #define SAME_EXTRAINFO 0x200 +#define RULE_MASTER 1 +#define RULE_SRCIP 2 +#define RULE_SRCPORT 4 +#define RULE_DSTIP 8 +#define RULE_DSTPORT 16 +#define RULE_USER 32 +#define RULE_URL 64 +#define RULE_ID 128 +#define RULE_HOSTNAME 256 +#define RULE_PROGRAM_NAME 512 +#define RULE_STATUS 1024 +#define RULE_ACTION 2048 + + +#define RULEINFODETAIL_TEXT 0 +#define RULEINFODETAIL_LINK 1 +#define RULEINFODETAIL_CVE 2 +#define RULEINFODETAIL_OSVDB 3 +#define RULEINFODETAIL_BUGTRACK 4 + +#define MAX_RULEINFODETAIL 32 + +typedef struct _RuleInfoDetail +{ + int type; + char *data; + struct _RuleInfoDetail *next; +}RuleInfoDetail; typedef struct _RuleInfo { @@ -120,6 +152,8 @@ typedef struct _RuleInfo char *comment; /* description in the xml */ char *info; char *cve; + RuleInfoDetail *info_details; + ListRule *lists; char *if_sid; char *if_level; @@ -145,6 +179,9 @@ typedef struct _RuleNode RuleInfo *currently_rule; /* */ +RuleInfoDetail *zeroinfodetails(int type, char *data); +int get_info_attributes(char **attributes, char **values); + /* RuleInfo functions */ RuleInfo *zerorulemember(int id, int level, diff --git a/src/analysisd/rules_list.c b/src/analysisd/rules_list.c index 4597b1f..c8613fa 100755 --- a/src/analysisd/rules_list.c +++ b/src/analysisd/rules_list.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rules_list.c,v 1.28 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -344,6 +344,7 @@ int OS_AddRuleInfo(RuleNode *r_node, RuleInfo *newrule, int sid) r_node->ruleinfo->maxsize = newrule->maxsize; r_node->ruleinfo->frequency = newrule->frequency; r_node->ruleinfo->timeframe = newrule->timeframe; + r_node->ruleinfo->ignore_time = newrule->ignore_time; r_node->ruleinfo->group = newrule->group; r_node->ruleinfo->match = newrule->match; diff --git a/src/analysisd/stats.c b/src/analysisd/stats.c index ceb7912..2e2420a 100755 --- a/src/analysisd/stats.c +++ b/src/analysisd/stats.c @@ -1,11 +1,11 @@ -/* @(#) $Id: stats.c,v 1.30 2009/06/24 17:06:22 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/analysisd/testrule.c b/src/analysisd/testrule.c index db769f7..c36d8ec 100755 --- a/src/analysisd/testrule.c +++ b/src/analysisd/testrule.c @@ -1,11 +1,11 @@ -/* @(#) $Id: testrule.c,v 1.7 2009/08/25 11:30:57 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -27,6 +27,8 @@ #define ARGV0 "ossec-testrule" #endif + + #include "shared.h" #include "alerts/alerts.h" @@ -42,13 +44,14 @@ #include "config.h" #include "rules.h" #include "stats.h" + #include "eventinfo.h" #include "analysisd.h" /** Internal Functions **/ -void OS_ReadMSG(int m_queue); +void OS_ReadMSG(int m_queue, char *ut_str); RuleInfo *OS_CheckIfRuleMatch(Eventinfo *lf, RuleNode *curr_node); @@ -60,6 +63,7 @@ int GlobalConf(char * cfgfile); /* For rules */ void Rules_OP_CreateRules(); +void Lists_OP_CreateLists(); int Rules_OP_ReadRules(char * cfgfile); int _setlevels(RuleNode *node, int nnode); int AddHash_Rule(RuleNode *node); @@ -94,7 +98,10 @@ int SetDecodeXML(); */ int main(int argc, char **argv) { + int t_config = 0; int c = 0, m_queue = 0; + char *ut_str = NULL; + char *dir = DEFAULTDIR; char *user = USER; char *group = GROUPGLOBAL; @@ -108,20 +115,30 @@ int main(int argc, char **argv) today = 0; prev_year = 0; full_output = 0; + alert_only = 0; + active_responses = NULL; memset(prev_month, '\0', 4); - while((c = getopt(argc, argv, "Vfdhu:g:D:c:")) != -1){ + while((c = getopt(argc, argv, "VatfdhU:u:g:D:c:")) != -1){ switch(c){ case 'V': print_version(); break; + case 't': + t_config = 1; + break; case 'h': help(ARGV0); break; case 'd': nowDebug(); break; + case 'U': + if(!optarg) + ErrorExit("%s: -U needs an argument",ARGV0); + ut_str = optarg; + break; case 'u': if(!optarg) ErrorExit("%s: -u needs an argument",ARGV0); @@ -141,6 +158,9 @@ int main(int argc, char **argv) ErrorExit("%s: -c needs an argument",ARGV0); cfg = optarg; break; + case 'a': + alert_only = 1; + break; case 'f': full_output = 1; break; @@ -152,6 +172,8 @@ int main(int argc, char **argv) } + + /* Reading configuration file */ if(GlobalConf(cfg) < 0) { @@ -184,45 +206,106 @@ int main(int argc, char **argv) ErrorExit(CHROOT_ERROR,ARGV0,dir); - - /* Reading decoders */ - OS_CreateOSDecoderList(); - if(!ReadDecodeXML("etc/decoder.xml")) + /* + * Anonymous Section: Load rules, decoders, and lists + * + * As lists require two pass loading of rules that make use of list lookups + * are created with blank database structs, and need to be filled in after + * completion of all rules and lists. + */ { - ErrorExit(CONFIG_ERROR, ARGV0, XML_DECODER); - } + { /* Lad decders */ + /* Initializing the decoders list */ + OS_CreateOSDecoderList(); + + if(!Config.decoders) + { /* Legacy loading */ + /* Reading decoders */ + if(!ReadDecodeXML("etc/decoder.xml")) + { + ErrorExit(CONFIG_ERROR, ARGV0, XML_DECODER); + } - c = ReadDecodeXML("etc/local_decoder.xml"); - if(!c) - { - if((c != -2)) - ErrorExit(CONFIG_ERROR, ARGV0, XML_LDECODER); - } - SetDecodeXML(); + /* Reading local ones. */ + c = ReadDecodeXML("etc/local_decoder.xml"); + if(!c) + { + if((c != -2)) + ErrorExit(CONFIG_ERROR, ARGV0, XML_LDECODER); + } + else + { + verbose("%s: INFO: Reading local decoder file.", ARGV0); + } + } + else + { /* New loaded based on file speified in ossec.conf */ + char **decodersfiles; + decodersfiles = Config.decoders; + while( decodersfiles && *decodersfiles) + { - - /* Creating the rules list */ - Rules_OP_CreateRules(); + verbose("%s: INFO: Reading decoder file %s.", ARGV0, *decodersfiles); + if(!ReadDecodeXML(*decodersfiles)) + ErrorExit(CONFIG_ERROR, ARGV0, *decodersfiles); + + free(*decodersfiles); + decodersfiles++; + } + } - - /* Reading the rules */ - { - char **rulesfiles; - rulesfiles = Config.includes; - while(rulesfiles && *rulesfiles) - { - debug1("%s: INFO: Reading rules file: '%s'", ARGV0, *rulesfiles); - if(Rules_OP_ReadRules(*rulesfiles) < 0) - ErrorExit(RULES_ERROR, ARGV0, *rulesfiles); - - free(*rulesfiles); - rulesfiles++; + /* Load decoders */ + SetDecodeXML(); + } + { /* Load Lists */ + /* Initializing the lists of list struct */ + Lists_OP_CreateLists(); + /* Load each list into list struct */ + { + char **listfiles; + listfiles = Config.lists; + while(listfiles && *listfiles) + { + verbose("%s: INFO: Reading loading the lists file: '%s'", ARGV0, *listfiles); + if(Lists_OP_LoadList(*listfiles) < 0) + ErrorExit(LISTS_ERROR, ARGV0, *listfiles); + free(*listfiles); + listfiles++; + } + free(Config.lists); + Config.lists = NULL; + } } + { /* Load Rules */ + /* Creating the rules list */ + Rules_OP_CreateRules(); + + /* Reading the rules */ + { + char **rulesfiles; + rulesfiles = Config.includes; + while(rulesfiles && *rulesfiles) + { + debug1("%s: INFO: Reading rules file: '%s'", ARGV0, *rulesfiles); + if(Rules_OP_ReadRules(*rulesfiles) < 0) + ErrorExit(RULES_ERROR, ARGV0, *rulesfiles); + + free(*rulesfiles); + rulesfiles++; + } - free(Config.includes); - Config.includes = NULL; + free(Config.includes); + Config.includes = NULL; + } + + /* Find all rules with that require list lookups and attache the + * the correct list struct to the rule. This keeps rules from having to + * search thought the list of lists for the correct file during rule evaluation. + */ + OS_ListLoadRules(); + } } - + /* Fixing the levels/accuracy */ { @@ -246,13 +329,18 @@ int main(int argc, char **argv) } + if(t_config == 1) + { + exit(0); + } + /* Start up message */ verbose(STARTUP_MSG, ARGV0, getpid()); /* Going to main loop */ - OS_ReadMSG(m_queue); + OS_ReadMSG(m_queue, ut_str); exit(0); @@ -265,10 +353,44 @@ int main(int argc, char **argv) * Main function. Receives the messages(events) * and analyze them all. */ -void OS_ReadMSG(int m_queue) +void OS_ReadMSG(int m_queue, char *ut_str) { int i; char msg[OS_MAXSTR +1]; + int exit_code = 0; + char *ut_alertlevel = NULL; + char *ut_rulelevel = NULL; + char *ut_decoder_name = NULL; + + if(ut_str) + { + /* XXX Break apart string */ + ut_rulelevel = ut_str; + ut_alertlevel = strchr(ut_rulelevel, ':'); + if(!ut_alertlevel) + { + ErrorExit("%s: -U requires the matching format to be " + "\"::\"", ARGV0); + } + else + { + *ut_alertlevel = '\0'; + ut_alertlevel++; + } + ut_decoder_name = strchr(ut_alertlevel, ':'); + if(!ut_decoder_name) + { + ErrorExit("%s: -U requires the matching format to be " + "\"::\"", ARGV0); + } + else + { + *ut_decoder_name = '\0'; + ut_decoder_name++; + } + } + + RuleInfoDetail *last_info_detail; Eventinfo *lf; @@ -287,6 +409,8 @@ void OS_ReadMSG(int m_queue) } + __crt_ftell = 1; + /* Getting currently time before starting */ c_time = time(NULL); @@ -296,6 +420,7 @@ void OS_ReadMSG(int m_queue) memset(msg, '\0', OS_MAXSTR +1); + if(!alert_only) print_out("%s: Type one log per line.\n", ARGV0); @@ -312,12 +437,12 @@ void OS_ReadMSG(int m_queue) /* Fixing the msg. */ - strncpy(msg, "1:a:", 5); + snprintf(msg, 15, "1:stdin:"); /* Receive message from queue */ - if(fgets(msg +4, OS_MAXSTR, stdin)) + if(fgets(msg +8, OS_MAXSTR, stdin)) { RuleNode *rulenode_pt; @@ -331,13 +456,13 @@ void OS_ReadMSG(int m_queue) /* Make sure we ignore blank lines. */ - if(strlen(msg) < 6) + if(strlen(msg) < 10) { continue; } - print_out("\n"); + if(!alert_only)print_out("\n"); /* Default values for the log info */ @@ -379,7 +504,7 @@ void OS_ReadMSG(int m_queue) #ifdef TESTRULE - if(full_output) + if(full_output && !alert_only) print_out("\n**Rule debugging:"); #endif @@ -413,10 +538,18 @@ void OS_ReadMSG(int m_queue) } #ifdef TESTRULE + if(!alert_only) + { + char *(ruleinfodetail_text[])={"Text","Link","CVE","OSVDB","BUGTRACKID"}; print_out("\n**Phase 3: Completed filtering (rules)."); print_out(" Rule id: '%d'", currently_rule->sigid); print_out(" Level: '%d'", currently_rule->level); print_out(" Description: '%s'",currently_rule->comment); + for (last_info_detail = currently_rule->info_details; last_info_detail != NULL; last_info_detail = last_info_detail->next) + { + print_out(" Info - %s: '%s'", ruleinfodetail_text[last_info_detail->type], last_info_detail->data); + } + } #endif @@ -472,7 +605,15 @@ void OS_ReadMSG(int m_queue) /* Log the alert if configured to ... */ if(currently_rule->alert_opts & DO_LOGALERT) { - print_out("**Alert to be generated.\n\n"); + if(alert_only) + { + OS_LogOutput(lf); + __crt_ftell++; + } + else + { + print_out("**Alert to be generated.\n\n"); + } } @@ -512,6 +653,29 @@ void OS_ReadMSG(int m_queue) }while((rulenode_pt = rulenode_pt->next) != NULL); + if(ut_str) + { + /*setup exit code if we are doing unit testing*/ + char holder[1024]; + holder[1] = '\0'; + exit_code = 3; + if(strcasecmp(ut_decoder_name, lf->decoder_info->name) == 0) + { + exit_code--; + snprintf(holder, 1023, "%d", currently_rule->sigid); + if(strcasecmp(ut_rulelevel, holder) == 0) + { + exit_code--; + snprintf(holder, 1023, "%d", currently_rule->level); + if(strcasecmp(ut_alertlevel, holder) == 0) + { + exit_code--; + printf("%d\n",exit_code); + } + } + } + } + /* Only clear the memory if the eventinfo was not * added to the stateful memory @@ -523,12 +687,14 @@ void OS_ReadMSG(int m_queue) } else { - exit(0); + exit(exit_code); } } + exit(exit_code); return; } /* EOF */ + diff --git a/src/client-agent/COPYRIGHT b/src/client-agent/COPYRIGHT index e857c2b..d691656 100755 --- a/src/client-agent/COPYRIGHT +++ b/src/client-agent/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All rights reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation OSSEC HIDS, ossec-agent diff --git a/src/client-agent/agentd.c b/src/client-agent/agentd.c index e21316e..bcb2686 100755 --- a/src/client-agent/agentd.c +++ b/src/client-agent/agentd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: agentd.c,v 1.44 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/agentd.h b/src/client-agent/agentd.h index c2b9dd1..dfd220c 100755 --- a/src/client-agent/agentd.h +++ b/src/client-agent/agentd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: agentd.h,v 1.26 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/config.c b/src/client-agent/config.c index 4025554..312eb70 100755 --- a/src/client-agent/config.c +++ b/src/client-agent/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.15 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/event-forward.c b/src/client-agent/event-forward.c index 8cafd1c..5e1f920 100755 --- a/src/client-agent/event-forward.c +++ b/src/client-agent/event-forward.c @@ -1,11 +1,11 @@ -/* @(#) $Id: event-forward.c,v 1.14 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/intcheck_op.c b/src/client-agent/intcheck_op.c index deab8ba..8137d53 100755 --- a/src/client-agent/intcheck_op.c +++ b/src/client-agent/intcheck_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: intcheck_op.c,v 1.4 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/main.c b/src/client-agent/main.c index d35a1bd..b78cd09 100755 --- a/src/client-agent/main.c +++ b/src/client-agent/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.16 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/notify.c b/src/client-agent/notify.c index 373dd66..39c332c 100755 --- a/src/client-agent/notify.c +++ b/src/client-agent/notify.c @@ -1,11 +1,11 @@ -/* @(#) $Id: notify.c,v 1.23 2009/06/26 13:50:02 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -68,6 +68,7 @@ void run_notify() curr_time = time(0); + #ifndef ONEWAY /* Check if the server has responded */ if((curr_time - available_server) > (3*NOTIFY_TIME)) { @@ -83,6 +84,7 @@ void run_notify() verbose(SERVER_UP, ARGV0); os_delwait(); } + #endif /* Check if time has elapsed */ diff --git a/src/client-agent/receiver-win.c b/src/client-agent/receiver-win.c index cd66a86..73456df 100755 --- a/src/client-agent/receiver-win.c +++ b/src/client-agent/receiver-win.c @@ -1,11 +1,11 @@ -/* @(#) $Id: receiver-win.c,v 1.8 2009/12/01 15:40:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/receiver.c b/src/client-agent/receiver.c index 35b7d7e..b9ab116 100755 --- a/src/client-agent/receiver.c +++ b/src/client-agent/receiver.c @@ -1,11 +1,11 @@ -/* @(#) $Id: receiver.c,v 1.28 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/sendmsg.c b/src/client-agent/sendmsg.c index 3c36063..438e848 100755 --- a/src/client-agent/sendmsg.c +++ b/src/client-agent/sendmsg.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sendmsg.c,v 1.7 2009/12/01 20:27:00 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/client-agent/start_agent.c b/src/client-agent/start_agent.c index 45fbf97..c27dc2e 100755 --- a/src/client-agent/start_agent.c +++ b/src/client-agent/start_agent.c @@ -1,11 +1,11 @@ -/* @(#) $Id: start_agent.c,v 1.17 2009/12/01 15:40:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -39,7 +39,7 @@ int connect_server(int initial_id) if(logr->sock >= 0) { sleep(1); - close(logr->sock); + CloseSocket(logr->sock); logr->sock = -1; if(logr->rip[1]) @@ -159,6 +159,11 @@ void start_agent(int is_startup) memset(cleartext, '\0', OS_MAXSTR +1); memset(fmsg, '\0', OS_MAXSTR +1); snprintf(msg, OS_MAXSTR, "%s%s", CONTROL_HEADER, HC_STARTUP); + + + #ifdef ONEWAY + return; + #endif /* Sending start message and waiting for the ack */ diff --git a/src/config/active-response.c b/src/config/active-response.c index fad1f45..20e0cf6 100755 --- a/src/config/active-response.c +++ b/src/config/active-response.c @@ -1,11 +1,11 @@ -/* @(#) $Id: active-response.c,v 1.15 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/active-response.h b/src/config/active-response.h index 277891a..0e821ab 100755 --- a/src/config/active-response.h +++ b/src/config/active-response.h @@ -1,11 +1,11 @@ -/* @(#) $Id: active-response.h,v 1.5 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/agentlessd-config.c b/src/config/agentlessd-config.c index 7157091..e0c76da 100644 --- a/src/config/agentlessd-config.c +++ b/src/config/agentlessd-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: agentlessd-config.c,v 1.6 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/agentlessd-config.h b/src/config/agentlessd-config.h index 3348d8c..9d522b3 100755 --- a/src/config/agentlessd-config.h +++ b/src/config/agentlessd-config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: agentlessd-config.h,v 1.4 2009/06/24 17:06:24 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/alerts-config.c b/src/config/alerts-config.c index 72edcad..85efc95 100755 --- a/src/config/alerts-config.c +++ b/src/config/alerts-config.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/client-config.c b/src/config/client-config.c index cc776c9..3eddfc3 100755 --- a/src/config/client-config.c +++ b/src/config/client-config.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/client-config.h b/src/config/client-config.h index fe8b906..5049a9d 100755 --- a/src/config/client-config.h +++ b/src/config/client-config.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/config.c b/src/config/config.c index c707e0f..c0cda89 100755 --- a/src/config/config.c +++ b/src/config/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.25 2009/08/27 18:17:41 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -40,6 +40,7 @@ int read_main_elements(OS_XML xml, int modules, char *osremote = "remote"; char *osclient = "client"; char *oscommand = "command"; + char *osreports = "reports"; char *osactive_response = "active-response"; @@ -48,7 +49,7 @@ int read_main_elements(OS_XML xml, int modules, XML_NODE chld_node = NULL; chld_node = OS_GetElementsbyNode(&xml,node[i]); - + if(!node[i]->element) { merror(XML_ELEMNULL, ARGV0); @@ -132,13 +133,20 @@ int read_main_elements(OS_XML xml, int modules, if((modules & CAR)&&(ReadActiveResponses(chld_node, d1, d2)<0)) return(OS_INVALID); } + else if(strcmp(node[i]->element, osreports) == 0) + { + if((modules & CREPORTS)&&(Read_CReports(chld_node, d1, d2)<0)) + return(OS_INVALID); + } else { merror(XML_INVELEM, ARGV0, node[i]->element); return(OS_INVALID); } + //printf("before\n"); OS_ClearNode(chld_node); + //printf("after\n"); i++; } @@ -170,6 +178,9 @@ int ReadConfig(int modules, char *cfgfile, void *d1, void *d2) { if(modules & CAGENT_CONFIG) { + #ifndef CLIENT + merror(XML_ERROR, ARGV0, cfgfile, xml.err, xml.err_line); + #endif } else { @@ -229,6 +240,7 @@ int ReadConfig(int modules, char *cfgfile, void *d1, void *d2) { if(strcmp(xml_agent_name, node[i]->attributes[attrs]) == 0) { + #ifdef CLIENT char *agentname = os_read_agent_name(); if(!agentname) @@ -243,9 +255,11 @@ int ReadConfig(int modules, char *cfgfile, void *d1, void *d2) } free(agentname); } + #endif } else if(strcmp(xml_agent_os, node[i]->attributes[attrs]) == 0) { + #ifdef CLIENT char *agentos = getuname(); if(agentos) @@ -261,6 +275,7 @@ int ReadConfig(int modules, char *cfgfile, void *d1, void *d2) passed_agent_test = 0; merror("%s: ERROR: Unable to retrieve uname.", ARGV0); } + #endif } else if(strcmp(xml_agent_overwrite, node[i]->attributes[attrs]) == 0) { diff --git a/src/config/config.h b/src/config/config.h index 55a2dfb..af1eb7e 100755 --- a/src/config/config.h +++ b/src/config/config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: config.h,v 1.14 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or @@ -30,6 +30,7 @@ #define CDBD 0002000 #define CSYSLOGD 0004000 #define CAGENTLESS 0020000 +#define CREPORTS 0040000 #define CAGENT_CONFIG 0010000 @@ -54,6 +55,7 @@ int Read_Remote(XML_NODE node, void *d1, void *d2); int Read_Client(XML_NODE node, void *d1, void *d2); int ReadActiveResponses(XML_NODE node, void *d1, void *d2); int ReadActiveCommands(XML_NODE node, void *d1, void *d2); +int Read_CReports(XML_NODE node, void *config1, void *config2); void AssignIgnore_Global(char **ignores, void *configp); diff --git a/src/config/csyslogd-config.c b/src/config/csyslogd-config.c index 15dd486..1ce6082 100644 --- a/src/config/csyslogd-config.c +++ b/src/config/csyslogd-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: csyslogd-config.c,v 1.3 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/csyslogd-config.h b/src/config/csyslogd-config.h index 182d975..08ed723 100755 --- a/src/config/csyslogd-config.h +++ b/src/config/csyslogd-config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: csyslogd-config.h,v 1.3 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/dbd-config.c b/src/config/dbd-config.c index 17a8249..4537306 100644 --- a/src/config/dbd-config.c +++ b/src/config/dbd-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: dbd-config.c,v 1.7 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/dbd-config.h b/src/config/dbd-config.h index 786561f..51c0af4 100755 --- a/src/config/dbd-config.h +++ b/src/config/dbd-config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: dbd-config.h,v 1.9 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/email-alerts-config.c b/src/config/email-alerts-config.c index ee5d7f3..4b63608 100644 --- a/src/config/email-alerts-config.c +++ b/src/config/email-alerts-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: email-alerts-config.c,v 1.10 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/global-config.c b/src/config/global-config.c index a3ded2e..9380308 100755 --- a/src/config/global-config.c +++ b/src/config/global-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: global-config.c,v 1.24 2009/07/23 19:31:35 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/global-config.h b/src/config/global-config.h index b8fcbbc..57dcf6b 100755 --- a/src/config/global-config.h +++ b/src/config/global-config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: global-config.h,v 1.16 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -65,6 +65,12 @@ typedef struct __Config /* List of rules */ char **includes; + /* List of Lists */ + char **lists; + + /* List of decoders */ + char **decoders; + /* Global rule hash. */ void *g_rules_hash; diff --git a/src/config/localfile-config.c b/src/config/localfile-config.c index dd523e8..6f53bff 100755 --- a/src/config/localfile-config.c +++ b/src/config/localfile-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: localfile-config.c,v 1.25 2009/11/03 21:07:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -31,7 +31,8 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) char *xml_localfile_location = "location"; char *xml_localfile_command = "command"; char *xml_localfile_logformat = "log_format"; - + char *xml_localfile_frequency = "frequency"; + char *xml_localfile_alias = "alias"; logreader *logf; logreader_config *log_config; @@ -46,9 +47,11 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) logf = log_config->config; logf[0].file = NULL; logf[0].command = NULL; + logf[0].alias = NULL; logf[0].logformat = NULL; logf[1].file = NULL; logf[1].command = NULL; + logf[1].alias = NULL; logf[1].logformat = NULL; } else @@ -64,16 +67,19 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) logf = log_config->config; logf[pl +1].file = NULL; logf[pl +1].command = NULL; + logf[pl +1].alias = NULL; logf[pl +1].logformat = NULL; } logf[pl].file = NULL; logf[pl].command = NULL; + logf[pl].alias = NULL; logf[pl].logformat = NULL; logf[pl].fp = NULL; logf[pl].ffile = NULL; logf[pl].djb_program_name = NULL; - + logf[pl].ign = 360; + /* Searching for entries related to files */ i = 0; @@ -94,6 +100,16 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) os_strdup(node[i]->content, logf[pl].file); logf[pl].command = logf[pl].file; } + else if(strcmp(node[i]->element,xml_localfile_frequency) == 0) + { + if(!OS_StrIsNum(node[i]->content)) + { + merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content); + return(OS_INVALID); + } + + logf[pl].ign = atoi(node[i]->content); + } else if(strcmp(node[i]->element,xml_localfile_location) == 0) { #ifdef WIN32 @@ -190,11 +206,13 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) logf = log_config->config; logf[pl].file = NULL; + logf[pl].alias = NULL; logf[pl].logformat = NULL; logf[pl].fp = NULL; logf[pl].ffile = NULL; logf[pl +1].file = NULL; + logf[pl +1].alias = NULL; logf[pl +1].logformat = NULL; /* We can not increment the file count in here */ @@ -242,6 +260,9 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) if(strcmp(logf[pl].logformat, "syslog") == 0) { } + else if(strcmp(logf[pl].logformat, "generic") == 0) + { + } else if(strcmp(logf[pl].logformat, "snort-full") == 0) { } @@ -278,6 +299,39 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) else if(strcmp(logf[pl].logformat, "command") == 0) { } + else if(strcmp(logf[pl].logformat, "full_command") == 0) + { + } + else if(strncmp(logf[pl].logformat, "multi-line", 10) == 0) + { + int x = 0; + logf[pl].logformat+=10; + + while(logf[pl].logformat[0] == ' ') + logf[pl].logformat++; + + if(logf[pl].logformat[0] != ':') + { + merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content); + return(OS_INVALID); + } + logf[pl].logformat++; + + while(*logf[pl].logformat == ' ') + logf[pl].logformat++; + + while(logf[pl].logformat[x] >= '0' && logf[pl].logformat[x] <= '9') + x++; + + while(logf[pl].logformat[x] == ' ') + x++; + + if(logf[pl].logformat[x] != '\0') + { + merror(XML_VALUEERR,ARGV0,node[i]->element,node[i]->content); + return(OS_INVALID); + } + } else if(strcmp(logf[pl].logformat, EVENTLOG) == 0) { } @@ -287,6 +341,10 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) return(OS_INVALID); } } + else if(strcasecmp(node[i]->element,xml_localfile_alias) == 0) + { + os_strdup(node[i]->content, logf[pl].alias); + } else { merror(XML_INVELEM, ARGV0, node[i]->element); @@ -366,7 +424,8 @@ int Read_Localfile(XML_NODE node, void *d1, void *d2) } } - if(strcmp(logf[pl].logformat, "command") == 0) + if((strcmp(logf[pl].logformat, "command") == 0)|| + (strcmp(logf[pl].logformat, "full_command") == 0)) { if(!logf[pl].command) { diff --git a/src/config/localfile-config.h b/src/config/localfile-config.h index 2714799..821c3e2 100755 --- a/src/config/localfile-config.h +++ b/src/config/localfile-config.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -47,7 +47,8 @@ typedef struct _logreader char *logformat; char *djb_program_name; char *command; - + char *alias; + void (*read)(int i, int *rc, int drop_it); FILE *fp; diff --git a/src/config/mail-config.h b/src/config/mail-config.h index 92cc81f..45276dc 100755 --- a/src/config/mail-config.h +++ b/src/config/mail-config.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/remote-config.c b/src/config/remote-config.c index 9a41089..6627813 100755 --- a/src/config/remote-config.c +++ b/src/config/remote-config.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/remote-config.h b/src/config/remote-config.h index 65bf8d7..a043078 100755 --- a/src/config/remote-config.h +++ b/src/config/remote-config.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/reports-config.c b/src/config/reports-config.c new file mode 100644 index 0000000..2f5ce66 --- /dev/null +++ b/src/config/reports-config.c @@ -0,0 +1,246 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + +/* Functions to handle the configuration files + */ + + +#include "shared.h" +#include "reports-config.h" + + +/* Filter argument. */ +static int _filter_arg(char *mystr) +{ + if(!mystr) + { + return(0); + } + + while(*mystr) + { + if((*mystr >= 'a' && *mystr <= 'z') || + (*mystr >= 'A' && *mystr <= 'Z') || + (*mystr >= '0' && *mystr <= '9') || + *mystr == '-' || *mystr == '_') + { + mystr++; + } + else + { + *mystr = '-'; + mystr++; + } + } + + return(1); +} + + +int Read_CReports(XML_NODE node, void *config, void *config2) +{ + int i = 0,s = 0; + + /* XML definitions */ + char *xml_title = "title"; + char *xml_type = "type"; + char *xml_categories = "category"; + char *xml_group = "group"; + char *xml_rule = "rule"; + char *xml_level = "level"; + char *xml_location = "location"; + char *xml_showlogs = "showlogs"; + char *xml_srcip = "srcip"; + char *xml_user = "user"; + char *xml_frequency = "frequency"; + char *xml_email = "email_to"; + + + monitor_config *mon_config = (monitor_config *)config; + + + /* Getting any configured entry. */ + if(mon_config->reports) + { + while(mon_config->reports[s]) + s++; + } + + + /* Allocating the memory for the config. */ + os_realloc(mon_config->reports, (s + 2) * sizeof(report_config *), + mon_config->reports); + os_calloc(1, sizeof(report_config), mon_config->reports[s]); + mon_config->reports[s + 1] = NULL; + + + /* Zeroing the elements. */ + mon_config->reports[s]->title = NULL; + mon_config->reports[s]->args = NULL; + mon_config->reports[s]->relations = NULL; + mon_config->reports[s]->type = NULL; + mon_config->reports[s]->emailto = NULL; + + mon_config->reports[s]->r_filter.group = NULL; + mon_config->reports[s]->r_filter.rule = NULL; + mon_config->reports[s]->r_filter.level = NULL; + mon_config->reports[s]->r_filter.location = NULL; + mon_config->reports[s]->r_filter.srcip = NULL; + mon_config->reports[s]->r_filter.user = NULL; + mon_config->reports[s]->r_filter.related_group = 0; + mon_config->reports[s]->r_filter.related_rule = 0; + mon_config->reports[s]->r_filter.related_level = 0; + mon_config->reports[s]->r_filter.related_location = 0; + mon_config->reports[s]->r_filter.related_srcip = 0; + mon_config->reports[s]->r_filter.related_user = 0; + mon_config->reports[s]->r_filter.report_name = NULL; + mon_config->reports[s]->r_filter.show_alerts = 0; + + + + /* Reading the XML. */ + while(node[i]) + { + if(!node[i]->element) + { + merror(XML_ELEMNULL, __local_name); + return(OS_INVALID); + } + else if(!node[i]->content) + { + merror(XML_VALUENULL, __local_name, node[i]->element); + return(OS_INVALID); + } + else if(strcmp(node[i]->element, xml_title) == 0) + { + if(!mon_config->reports[s]->title) + { + os_strdup(node[i]->content, mon_config->reports[s]->title); + } + } + else if(strcmp(node[i]->element, xml_type) == 0) + { + if(strcmp(node[i]->content, "email") == 0) + { + if(!mon_config->reports[s]->type) + { + os_strdup(node[i]->content, mon_config->reports[s]->type); + } + } + else + { + merror(XML_VALUEERR, __local_name,node[i]->element,node[i]->content); + } + } + else if(strcmp(node[i]->element, xml_frequency) == 0) + { + } + else if(strcmp(node[i]->element, xml_showlogs) == 0) + { + if(strcasecmp(node[i]->content, "yes") == 0) + { + mon_config->reports[s]->r_filter.show_alerts = 1; + } + } + else if(strcmp(node[i]->element, xml_categories) == 0) + { + char *ncat = NULL; + _filter_arg(node[i]->content); + + + os_strdup(node[i]->content, ncat); + + if(os_report_configfilter("group", ncat, + &mon_config->reports[s]->r_filter, REPORT_FILTER) < 0) + { + merror(CONFIG_ERROR, __local_name, "user argument"); + } + } + else if((strcmp(node[i]->element, xml_group) == 0)|| + (strcmp(node[i]->element, xml_rule) == 0)|| + (strcmp(node[i]->element, xml_level) == 0)|| + (strcmp(node[i]->element, xml_location) == 0)|| + (strcmp(node[i]->element, xml_srcip) == 0)|| + (strcmp(node[i]->element, xml_user) == 0)) + { + int reportf = REPORT_FILTER; + char *ncat = NULL; + _filter_arg(node[i]->content); + + if(node[i]->attributes && node[i]->values) + { + if(node[i]->attributes[0] && node[i]->values[0]) + { + if(strcmp(node[i]->attributes[0], "type") == 0) + { + if(strcmp(node[i]->values[0], "relation") == 0) + { + reportf = REPORT_RELATED; + } + else + { + merror("%s: WARN: Invalid value for 'relation' attribute: '%s'. (ignored).", __local_name, node[i]->values[0]); + i++; + continue; + } + } + else + { + merror("%s: WARN: Invalid attribute: %s (ignored). ", __local_name, node[i]->attributes[0]); + i++; + continue; + } + } + } + + os_strdup(node[i]->content, ncat); + + if(os_report_configfilter(node[i]->element, ncat, + &mon_config->reports[s]->r_filter, reportf) < 0) + { + merror("%s: Invalid filter: %s:%s (ignored).", __local_name, node[i]->element, node[i]->content); + } + } + else if(strcmp(node[i]->element, xml_email) == 0) + { + mon_config->reports[s]->emailto = os_AddStrArray(node[i]->content, mon_config->reports[s]->emailto); + } + else + { + merror(XML_INVELEM, __local_name, node[i]->element); + return(OS_INVALID); + } + i++; + } + + + /* Setting proper report type. */ + mon_config->reports[s]->r_filter.report_type = REPORT_TYPE_DAILY; + + if(mon_config->reports[s]->emailto == NULL) + { + if(mon_config->reports[s]->title) + merror("%s: No \"email to\" configured for the report '%s'. Ignoring it.", __local_name, mon_config->reports[s]->title); + else + merror("%s: No \"email to\" and title configured for report. Ignoring it.", __local_name); + } + + if(!mon_config->reports[s]->title) + { + os_strdup("OSSEC Report (unnamed)", mon_config->reports[s]->title); + } + mon_config->reports[s]->r_filter.report_name = mon_config->reports[s]->title; + + return(0); +} + + +/* EOF */ diff --git a/src/config/reports-config.h b/src/config/reports-config.h new file mode 100755 index 0000000..4b37a8d --- /dev/null +++ b/src/config/reports-config.h @@ -0,0 +1,47 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + +#ifndef _REPORTSCONFIG_H +#define _REPORTSCONFIG_H + +#include "report_op.h" + + +/* Structure for the report. */ +typedef struct _report_config +{ + char *title; + char *args; + char *relations; + char *type; + char **emailto; + report_filter r_filter; +}report_config; + +typedef struct _monitor_config +{ + short int day_wait; + short int compress; + short int sign; + short int monitor_agents; + int a_queue; + + char *smtpserver; + char *emailfrom; + + char **agents; + report_config **reports; +}monitor_config; + + + +#endif diff --git a/src/config/rootcheck-config.c b/src/config/rootcheck-config.c index dceb6a8..79a3cec 100755 --- a/src/config/rootcheck-config.c +++ b/src/config/rootcheck-config.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/rootcheck-config.h b/src/config/rootcheck-config.h index 988be6c..7e82693 100755 --- a/src/config/rootcheck-config.h +++ b/src/config/rootcheck-config.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/config/rules-config.c b/src/config/rules-config.c index f9da8f3..4801386 100755 --- a/src/config/rules-config.c +++ b/src/config/rules-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rules-config.c,v 1.5 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -17,16 +17,51 @@ #include "global-config.h" + +static int cmpr(const void *a, const void *b) { + /*printf("%s - %s\n", *(char **)a, *(char **)b);*/ + return strcmp(*(char **)a, *(char **)b); +} + +static int file_in_list(int list_size, char *f_name, char *d_name, char **alist) +{ + int i = 0; + for(i=0; i<(list_size-1); i++) + { + if((strcmp(alist[i], f_name) == 0 || strcmp(alist[i], d_name) == 0)) + { + return(1); + } + } + return(0); +} + int Read_Rules(XML_NODE node, void *configp, void *mailp) { int i = 0; - /* White list size */ int rules_size = 1; + int lists_size = 1; + int decoders_size = 1; + + + char path[PATH_MAX +2]; + char f_name[PATH_MAX +2]; + int start_point = 0; + int att_count = 0; + struct dirent *entry; + DIR *dfd; + OSRegex regex; /* XML definitions */ char *xml_rules_include = "include"; + char *xml_rules_rule = "rule"; + char *xml_rules_rules_dir = "rule_dir"; + char *xml_rules_lists = "list"; + char *xml_rules_lists_dir = "list_dir"; + char *xml_rules_decoders = "decoder"; + char *xml_rules_decoders_dir = "decoder_dir"; _Config *Config; @@ -45,7 +80,8 @@ int Read_Rules(XML_NODE node, void *configp, void *mailp) return(OS_INVALID); } /* Mail notification */ - else if(strcmp(node[i]->element, xml_rules_include) == 0) + else if((strcmp(node[i]->element, xml_rules_include) == 0) || + (strcmp(node[i]->element, xml_rules_rule) == 0)) { rules_size++; Config->includes = realloc(Config->includes, @@ -58,6 +94,203 @@ int Read_Rules(XML_NODE node, void *configp, void *mailp) os_strdup(node[i]->content,Config->includes[rules_size -2]); Config->includes[rules_size -1] = NULL; + debug1("adding rule: %s", node[i]->content); + } + else if(strcmp(node[i]->element, xml_rules_decoders) == 0) + { + decoders_size++; + Config->decoders = realloc(Config->decoders, + sizeof(char *)*decoders_size); + if(!Config->decoders) + { + merror(MEM_ERROR, ARGV0); + return(OS_INVALID); + } + + os_strdup(node[i]->content,Config->decoders[decoders_size -2]); + Config->decoders[decoders_size -1] = NULL; + debug1("adding decoder: %s", node[i]->content); + } + else if(strcmp(node[i]->element, xml_rules_lists) == 0) + { + lists_size++; + Config->lists = realloc(Config->lists, + sizeof(char *)*lists_size); + if(!Config->lists) + { + merror(MEM_ERROR, ARGV0); + return(OS_INVALID); + } + os_strdup(node[i]->content,Config->lists[lists_size -2]); + Config->lists[lists_size -1] = NULL; + + } + else if(strcmp(node[i]->element, xml_rules_lists) == 0) + { + lists_size++; + Config->lists = realloc(Config->lists, + sizeof(char *)*lists_size); + if(!Config->lists) + { + merror(MEM_ERROR, ARGV0); + return(OS_INVALID); + } + os_strdup(node[i]->content,Config->lists[lists_size -2]); + Config->lists[lists_size -1] = NULL; + + } + else if(strcmp(node[i]->element, xml_rules_decoders_dir) == 0) + { + + if(node[i]->attributes && node[i]->values) + { + while(node[i]->attributes[att_count]) + { + if((strcasecmp(node[i]->attributes[att_count], "pattern") == 0)) + { + if(node[i]->values[att_count]) + { + if(!OSRegex_Compile(node[i]->values[att_count], ®ex, 0)) + { + merror(CONFIG_ERROR, ARGV0, "pattern in decoders_dir does not compile"); + merror("%s: ERROR: Regex would not compile", ARGV0); + return(-1); + } + } + } + att_count++; + } + } + else + { + OSRegex_Compile(".xml$", ®ex, 0); + } + + #ifdef TESTRULE + snprintf(path,PATH_MAX +1,"%s", node[i]->content); + #else + snprintf(path,PATH_MAX +1,"%s/%s", DEFAULTDIR, node[i]->content); + #endif + + f_name[PATH_MAX +1] = '\0'; + dfd = opendir(path); + + if(dfd != NULL) { + start_point = decoders_size- 1; + while((entry = readdir(dfd)) != NULL) + { + snprintf(f_name, PATH_MAX +1, "%s/%s", node[i]->content, entry->d_name); + + /* Just ignore . and .. */ + if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0)) + continue; + + /* no dups allowed */ + if(file_in_list(decoders_size, f_name, entry->d_name, Config->decoders)) + continue; + + if(OSRegex_Execute(f_name, ®ex)) + { + decoders_size++; + Config->decoders= realloc(Config->decoders, sizeof(char *)*decoders_size); + if(!Config->decoders) + { + merror(MEM_ERROR, ARGV0); + return(-1); + } + + os_strdup(f_name, Config->decoders[decoders_size -2]); + Config->decoders[decoders_size -1] = NULL; + debug1("adding decoder: %s", f_name); + } + else + { + debug1("Regex does not match \"%s\"", f_name); + } + } + + closedir(dfd); + /* Sort just then newly added items */ + qsort(Config->decoders + start_point , decoders_size- start_point -1, sizeof(char *), cmpr); + } + int ii=0; + debug1("decoders_size %d", decoders_size); + for(ii=0;iidecoders[ii]); + } + else if(strcmp(node[i]->element, xml_rules_rules_dir) == 0) + { + if(node[i]->attributes && node[i]->values) + { + while(node[i]->attributes[att_count]) + { + if((strcasecmp(node[i]->attributes[att_count], "pattern") == 0)) + { + if(node[i]->values[att_count]) + { + if(!OSRegex_Compile(node[i]->values[att_count], ®ex, 0)) + { + merror(CONFIG_ERROR, ARGV0, "pattern in rules_dir does not compile"); + merror("%s: ERROR: Regex would not compile", ARGV0); + return(-1); + } + } + } + att_count++; + } + } + else + { + OSRegex_Compile(".xml$", ®ex, 0); + } + + #ifdef TESTRULE + snprintf(path,PATH_MAX +1,"%s", node[i]->content); + #else + snprintf(path,PATH_MAX +1,"%s/%s", DEFAULTDIR, node[i]->content); + #endif + + f_name[PATH_MAX +1] = '\0'; + dfd = opendir(path); + + if(dfd != NULL) { + start_point = rules_size - 1; + while((entry = readdir(dfd)) != NULL) + { + snprintf(f_name, PATH_MAX +1, "%s/%s", node[i]->content, entry->d_name); + + /* Just ignore . and .. */ + if((strcmp(entry->d_name,".") == 0) || (strcmp(entry->d_name,"..") == 0)) + continue; + + /* no dups allowed */ + if(file_in_list(rules_size, f_name, entry->d_name, Config->includes)) + continue; + + if(OSRegex_Execute(f_name, ®ex)) + { + rules_size++; + Config->includes = realloc(Config->includes, sizeof(char *)*rules_size); + if(!Config->includes) + { + merror(MEM_ERROR, ARGV0); + return(-1); + } + + os_strdup(f_name, Config->includes[rules_size -2]); + Config->includes[rules_size -1] = NULL; + debug1("adding rule: %s", f_name); + } + else + { + debug1("Regex does not match \"%s\"", f_name); + } + } + + closedir(dfd); + /* Sort just then newly added items */ + qsort(Config->includes + start_point , rules_size - start_point -1, sizeof(char *), cmpr); + } } else { diff --git a/src/config/syscheck-config.c b/src/config/syscheck-config.c index 92e538d..08fe42a 100755 --- a/src/config/syscheck-config.c +++ b/src/config/syscheck-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck-config.c,v 1.25 2009/11/04 15:18:59 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -16,7 +16,7 @@ -int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg) +int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg, char *restrictfile) { int pl = 0; @@ -55,7 +55,11 @@ int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg) os_calloc(2, sizeof(int), syscheck->opts); syscheck->opts[pl + 1] = 0; - syscheck->opts[pl] = vals; + syscheck->opts[pl] = vals; + + os_calloc(2, sizeof(OSMatch *), syscheck->filerestrict); + syscheck->filerestrict[pl] = NULL; + syscheck->filerestrict[pl + 1] = NULL; } else { @@ -72,6 +76,26 @@ int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg) syscheck->opts); syscheck->opts[pl + 1] = 0; syscheck->opts[pl] = vals; + + os_realloc(syscheck->filerestrict, (pl +2) * sizeof(char *), + syscheck->filerestrict); + syscheck->filerestrict[pl] = NULL; + syscheck->filerestrict[pl + 1] = NULL; + } + if(restrictfile) + { + os_calloc(1, sizeof(OSMatch), syscheck->filerestrict[pl]); + if(!OSMatch_Compile(restrictfile, syscheck->filerestrict[pl], 0)) + { + OSMatch *ptm; + + ptm = syscheck->filerestrict[pl]; + + merror(REGEX_COMPILE, ARGV0, restrictfile, + ptm->error); + free(syscheck->filerestrict[pl]); + syscheck->filerestrict[pl] = NULL; + } } } @@ -153,7 +177,7 @@ int read_reg(config *syscheck, char *entries) } /* Adding new entry */ - dump_syscheck_entry(syscheck, tmp_entry, 0, 1); + dump_syscheck_entry(syscheck, tmp_entry, 0, 1, NULL); /* Next entry */ @@ -179,7 +203,10 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) char *xml_check_group = "check_group"; char *xml_check_perm = "check_perm"; char *xml_real_time = "realtime"; + char *xml_report_changes = "report_changes"; + char *xml_restrict = "restrict"; + char *restrictfile = NULL; char **dir; char *tmp_str; dir = OS_StrBreak(',', dirs, MAX_DIR_SIZE); /* Max number */ @@ -202,6 +229,7 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) char **values = NULL; tmp_dir = *dir; + restrictfile = NULL; /* Removing spaces at the beginning */ while(*tmp_dir == ' ') @@ -385,6 +413,25 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) return(0); } } + else if(strcmp(*attrs, xml_report_changes) == 0) + { + if(strcmp(*values, "yes") == 0) + { + opts|=CHECK_SEECHANGES; + } + else if(strcmp(*values, "no") == 0) + { + } + else + { + merror(SK_INV_OPT, ARGV0, *values, *attrs); + return(0); + } + } + else if(strcmp(*attrs, xml_restrict) == 0) + { + os_strdup(*values, restrictfile); + } else { merror(SK_INV_ATTR, ARGV0, *attrs); @@ -398,6 +445,7 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) if(opts == 0) { merror(SYSCHECK_NO_OPT, ARGV0, dirs); + if(restrictfile) free(restrictfile); return(0); } @@ -451,7 +499,7 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) while(g.gl_pathv[gindex]) { - dump_syscheck_entry(syscheck, g.gl_pathv[gindex], opts, 0); + dump_syscheck_entry(syscheck, g.gl_pathv[gindex], opts, 0, restrictfile); gindex++; } @@ -460,11 +508,17 @@ int read_attr(config *syscheck, char *dirs, char **g_attrs, char **g_values) else { - dump_syscheck_entry(syscheck, tmp_dir, opts, 0); + dump_syscheck_entry(syscheck, tmp_dir, opts, 0, restrictfile); } #else - dump_syscheck_entry(syscheck, tmp_dir, opts, 0); + dump_syscheck_entry(syscheck, tmp_dir, opts, 0, restrictfile); #endif + + if(restrictfile) + { + free(restrictfile); + restrictfile = NULL; + } /* Next entry */ diff --git a/src/config/syscheck-config.h b/src/config/syscheck-config.h index 816ed11..b380e8b 100755 --- a/src/config/syscheck-config.h +++ b/src/config/syscheck-config.h @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck-config.h,v 1.20 2009/10/02 19:28:34 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -27,6 +27,7 @@ #define CHECK_GROUP 0000020 #define CHECK_SHA1SUM 0000040 #define CHECK_REALTIME 0000100 +#define CHECK_SEECHANGES 0000200 #include @@ -64,6 +65,7 @@ typedef struct _config void **ignore_regex; char **dir; + void **filerestrict; /* Windows only registry checking */ #ifdef WIN32 @@ -73,7 +75,7 @@ typedef struct _config FILE *reg_fp; #endif - FILE *fp; + void *fp; rtfim *realtime; diff --git a/src/error_messages/error_messages.h b/src/error_messages/error_messages.h index d1e0ab7..eb1bd14 100755 --- a/src/error_messages/error_messages.h +++ b/src/error_messages/error_messages.h @@ -1,11 +1,11 @@ -/* @(#) $Id: error_messages.h,v 1.88 2009/06/24 17:06:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -48,6 +48,7 @@ #define UNLINK_ERROR "%s(1123): ERROR: Unable to delete file: '%s'." #define RENAME_ERROR "%s(1124): ERROR: Unable to rename file: '%s'." #define INT_ERROR "%s(1125): ERROR: Internal error (undefined)." +#define OPEN_ERROR "%s(1126): ERROR: Unable to open file '%s' reason '%s'" /* COMMON ERRORS */ @@ -72,6 +73,7 @@ #define SEND_ERROR "%s(1218): ERROR: Unable to send message to %s." #define RULESLOAD_ERROR "%s(1219): ERROR: Unable to access the rules directory." #define RULES_ERROR "%s(1220): ERROR: Error loading the rules: '%s'." +#define LISTS_ERROR "%s(1221): ERROR: Error loading the list: '%s'." #define QUEUE_SEND "%s(1224): ERROR: Error sending message to queue." #define SIGNAL_RECV "%s(1225): INFO: SIGNAL Received. Exit Cleaning..." #define XML_ERROR "%s(1226): ERROR: Error reading XML file '%s': %s (line %d)." @@ -302,7 +304,6 @@ #define SERVER_UNAV "%s: WARN: Server unavailable. Setting lock." #define SERVER_UP "%s: INFO: Server responded. Releasing lock." - /* Ossec alert messages */ #define OS_AD_STARTED "ossec: Ossec started." #define OS_AG_STARTED "ossec: Agent started: '%s->%s'." diff --git a/src/external/zlib-1.2.3/adler32.c b/src/external/zlib-1.2.3/adler32.c index 66a70a8..007ba26 100755 --- a/src/external/zlib-1.2.3/adler32.c +++ b/src/external/zlib-1.2.3/adler32.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: adler32.c,v 1.1 2006/06/13 16:50:58 dcid Exp $ */ +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/src/external/zlib-1.2.3/compress.c b/src/external/zlib-1.2.3/compress.c index c71d987..ea739e0 100755 --- a/src/external/zlib-1.2.3/compress.c +++ b/src/external/zlib-1.2.3/compress.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: compress.c,v 1.2 2006/08/11 14:49:04 dcid Exp $ */ +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/src/external/zlib-1.2.3/crc32.c b/src/external/zlib-1.2.3/crc32.c index d02c797..f658a9e 100755 --- a/src/external/zlib-1.2.3/crc32.c +++ b/src/external/zlib-1.2.3/crc32.c @@ -9,7 +9,7 @@ * factor of two increase in speed on a Power PC G4 (PPC7455) using gcc -O3. */ -/* @(#) $Id: crc32.c,v 1.1 2006/06/13 16:50:58 dcid Exp $ */ +/* @(#) $Id$ */ /* Note on the use of DYNAMIC_CRC_TABLE: there is no mutex or semaphore diff --git a/src/external/zlib-1.2.3/deflate.c b/src/external/zlib-1.2.3/deflate.c index bc23f1d..29ce1f6 100755 --- a/src/external/zlib-1.2.3/deflate.c +++ b/src/external/zlib-1.2.3/deflate.c @@ -47,7 +47,7 @@ * */ -/* @(#) $Id: deflate.c,v 1.1 2006/06/13 16:50:58 dcid Exp $ */ +/* @(#) $Id$ */ #include "deflate.h" diff --git a/src/external/zlib-1.2.3/deflate.h b/src/external/zlib-1.2.3/deflate.h index 0cc7e6b..05a5ab3 100755 --- a/src/external/zlib-1.2.3/deflate.h +++ b/src/external/zlib-1.2.3/deflate.h @@ -8,7 +8,7 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $Id: deflate.h,v 1.1 2006/06/13 16:50:58 dcid Exp $ */ +/* @(#) $Id$ */ #ifndef DEFLATE_H #define DEFLATE_H diff --git a/src/external/zlib-1.2.3/gzio.c b/src/external/zlib-1.2.3/gzio.c index 025bc54..7a664fc 100755 --- a/src/external/zlib-1.2.3/gzio.c +++ b/src/external/zlib-1.2.3/gzio.c @@ -5,7 +5,7 @@ * Compile this file with -DNO_GZCOMPRESS to avoid the compression code. */ -/* @(#) $Id: gzio.c,v 1.2 2006/08/09 00:42:42 dcid Exp $ */ +/* @(#) $Id$ */ #include diff --git a/src/external/zlib-1.2.3/trees.c b/src/external/zlib-1.2.3/trees.c index 1028562..395e4e1 100755 --- a/src/external/zlib-1.2.3/trees.c +++ b/src/external/zlib-1.2.3/trees.c @@ -29,7 +29,7 @@ * Addison-Wesley, 1983. ISBN 0-201-06672-6. */ -/* @(#) $Id: trees.c,v 1.1 2006/06/13 16:50:59 dcid Exp $ */ +/* @(#) $Id$ */ /* #define GEN_TREES_H */ diff --git a/src/external/zlib-1.2.3/uncompr.c b/src/external/zlib-1.2.3/uncompr.c index c6a290e..41b78f7 100755 --- a/src/external/zlib-1.2.3/uncompr.c +++ b/src/external/zlib-1.2.3/uncompr.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: uncompr.c,v 1.2 2006/08/17 00:41:20 dcid Exp $ */ +/* @(#) $Id$ */ #define ZLIB_INTERNAL #include "zlib.h" diff --git a/src/external/zlib-1.2.3/zconf.h b/src/external/zlib-1.2.3/zconf.h index 2b25598..03a9431 100755 --- a/src/external/zlib-1.2.3/zconf.h +++ b/src/external/zlib-1.2.3/zconf.h @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: zconf.h,v 1.1 2006/06/13 16:50:59 dcid Exp $ */ +/* @(#) $Id$ */ #ifndef ZCONF_H #define ZCONF_H diff --git a/src/external/zlib-1.2.3/zconf.in.h b/src/external/zlib-1.2.3/zconf.in.h index 476550a..03a9431 100755 --- a/src/external/zlib-1.2.3/zconf.in.h +++ b/src/external/zlib-1.2.3/zconf.in.h @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: zconf.in.h,v 1.1 2006/06/13 16:50:59 dcid Exp $ */ +/* @(#) $Id$ */ #ifndef ZCONF_H #define ZCONF_H diff --git a/src/external/zlib-1.2.3/zutil.c b/src/external/zlib-1.2.3/zutil.c index 2c43306..d55f594 100755 --- a/src/external/zlib-1.2.3/zutil.c +++ b/src/external/zlib-1.2.3/zutil.c @@ -3,7 +3,7 @@ * For conditions of distribution and use, see copyright notice in zlib.h */ -/* @(#) $Id: zutil.c,v 1.1 2006/06/13 16:51:00 dcid Exp $ */ +/* @(#) $Id$ */ #include "zutil.h" diff --git a/src/external/zlib-1.2.3/zutil.h b/src/external/zlib-1.2.3/zutil.h index 00ea89b..b7d5eff 100755 --- a/src/external/zlib-1.2.3/zutil.h +++ b/src/external/zlib-1.2.3/zutil.h @@ -8,7 +8,7 @@ subject to change. Applications should only use zlib.h. */ -/* @(#) $Id: zutil.h,v 1.1 2006/06/13 16:51:00 dcid Exp $ */ +/* @(#) $Id$ */ #ifndef ZUTIL_H #define ZUTIL_H diff --git a/src/headers/agent_op.h b/src/headers/agent_op.h index 9da70c2..9b53ea4 100755 --- a/src/headers/agent_op.h +++ b/src/headers/agent_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: agent_op.h,v 1.3 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/ar.h b/src/headers/ar.h index 6f950c3..03b61a1 100755 --- a/src/headers/ar.h +++ b/src/headers/ar.h @@ -1,11 +1,11 @@ -/* @(#) $Id: ar.h,v 1.7 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/debug_op.h b/src/headers/debug_op.h index 71e4920..b35e73d 100755 --- a/src/headers/debug_op.h +++ b/src/headers/debug_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: debug_op.h,v 1.10 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/defs.h b/src/headers/defs.h index 47a8d72..9a9e5c4 100755 --- a/src/headers/defs.h +++ b/src/headers/defs.h @@ -1,11 +1,11 @@ -/* @(#) $Id: defs.h,v 1.77 2009/11/23 18:52:44 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -46,13 +46,13 @@ /* Some Global names */ #define __name "OSSEC HIDS" -#define __version "v2.3" +#define __version "v2.5.1" #define __author "Trend Micro Inc." #define __contact "contact@ossec.net" #define __site "http://www.ossec.net" #define __license "\ This program is free software; you can redistribute it and/or modify\n\ -it under the terms of the GNU General Public License (version 3) as \n\ +it under the terms of the GNU General Public License (version 2) as \n\ published by the Free Software Foundation. For more details, go to \n\ http://www.ossec.net/main/license/\n" diff --git a/src/headers/dirtree_op.h b/src/headers/dirtree_op.h index 50e9aed..c154982 100755 --- a/src/headers/dirtree_op.h +++ b/src/headers/dirtree_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: dirtree_op.h,v 1.3 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/headers/file-queue.h b/src/headers/file-queue.h index eabea60..b3f85e4 100755 --- a/src/headers/file-queue.h +++ b/src/headers/file-queue.h @@ -1,11 +1,11 @@ -/* @(#) $Id: file-queue.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/file_op.h b/src/headers/file_op.h index 921b46d..7d03cf1 100755 --- a/src/headers/file_op.h +++ b/src/headers/file_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: file_op.h,v 1.14 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/hash_op.h b/src/headers/hash_op.h index fd3d842..0ea3fe9 100755 --- a/src/headers/hash_op.h +++ b/src/headers/hash_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: hash_op.h,v 1.4 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -73,6 +73,7 @@ int OSHash_Add(OSHash *hash, char *key, void *data); */ void *OSHash_Get(OSHash *self, char *key); +int OSHash_setSize(OSHash *self, int new_size); #endif diff --git a/src/headers/help.h b/src/headers/help.h index 1312387..19a4cd1 100755 --- a/src/headers/help.h +++ b/src/headers/help.h @@ -1,11 +1,11 @@ -/* @(#) $Id: help.h,v 1.7 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/list_op.h b/src/headers/list_op.h index 536e06c..d93c554 100755 --- a/src/headers/list_op.h +++ b/src/headers/list_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: list_op.h,v 1.12 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/math_op.h b/src/headers/math_op.h index bfc460f..7654aba 100755 --- a/src/headers/math_op.h +++ b/src/headers/math_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: math_op.h,v 1.3 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/headers/mem_op.h b/src/headers/mem_op.h index 7e2db48..d135fbe 100755 --- a/src/headers/mem_op.h +++ b/src/headers/mem_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: mem_op.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -16,6 +16,8 @@ #include "shared.h" +void **os_AddPtArray(void *pt, void **array); +char **os_AddStrArray(char *str, char **array); void os_FreeArray(char *ch1, char **ch2); int os_IsStrOnArray(char *str, char **array); char *os_LoadString(char *at, char *str); diff --git a/src/headers/mq_op.h b/src/headers/mq_op.h index e4407c9..c7ef5ad 100755 --- a/src/headers/mq_op.h +++ b/src/headers/mq_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: mq_op.h,v 1.10 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/os_err.h b/src/headers/os_err.h index 4f0e47d..65f287c 100755 --- a/src/headers/os_err.h +++ b/src/headers/os_err.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_err.h,v 1.7 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/privsep_op.h b/src/headers/privsep_op.h index b3e8683..eb29313 100755 --- a/src/headers/privsep_op.h +++ b/src/headers/privsep_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: privsep_op.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/pthreads_op.h b/src/headers/pthreads_op.h index 53cf4c4..cdb4026 100755 --- a/src/headers/pthreads_op.h +++ b/src/headers/pthreads_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: pthreads_op.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/rc.h b/src/headers/rc.h index 409aa1b..61e67d0 100755 --- a/src/headers/rc.h +++ b/src/headers/rc.h @@ -1,11 +1,11 @@ -/* @(#) $Id: rc.h,v 1.10 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/read-agents.h b/src/headers/read-agents.h index d6e9547..a0a26c3 100755 --- a/src/headers/read-agents.h +++ b/src/headers/read-agents.h @@ -1,11 +1,11 @@ -/* @(#) $Id: read-agents.h,v 1.12 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/read-alert.h b/src/headers/read-alert.h index 1455e08..83bcd26 100755 --- a/src/headers/read-alert.h +++ b/src/headers/read-alert.h @@ -1,11 +1,11 @@ -/* @(#) $Id: read-alert.h,v 1.7 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/regex_op.h b/src/headers/regex_op.h index 1c2cbf2..05cca8f 100755 --- a/src/headers/regex_op.h +++ b/src/headers/regex_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: regex_op.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/report_op.h b/src/headers/report_op.h index 41711cc..9218e2f 100755 --- a/src/headers/report_op.h +++ b/src/headers/report_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: report_op.h,v 1.2 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -24,6 +24,7 @@ #define REPORT_REL_RULE 0x010 #define REPORT_REL_GROUP 0x020 #define REPORT_REL_LOCATION 0x040 +#define REPORT_TYPE_DAILY 0x100 @@ -35,6 +36,9 @@ typedef struct _report_filter char *rule; char *level; char *location; + char *user; + char *srcip; + char *filename; void *top_user; void *top_srcip; @@ -49,6 +53,10 @@ typedef struct _report_filter int related_rule; int related_group; int related_location; + + int report_type; + int show_alerts; + void *fp; }report_filter; diff --git a/src/headers/rules_op.h b/src/headers/rules_op.h index 3adc5c3..dd03e63 100755 --- a/src/headers/rules_op.h +++ b/src/headers/rules_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: rules_op.h,v 1.3 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -29,6 +29,7 @@ #define DIFFERENT_URL 0x010 /* */ #define SAME_SRCPORT 0x020 #define SAME_DSTPORT 0x040 +#define SAME_DODIFF 0x100 #define NOT_SAME_USER 0xffe /* 0xfff - 0x001 */ #define NOT_SAME_SRCIP 0xffd /* 0xfff - 0x002 */ #define NOT_SAME_ID 0xffb /* 0xfff - 0x004 */ @@ -39,6 +40,7 @@ #define DO_FTS 0x001 #define DO_MAILALERT 0x002 #define DO_LOGALERT 0x004 +#define NO_AR 0x008 #define NO_ALERT 0x010 #define DO_OVERWRITE 0x020 #define DO_PACKETINFO 0x040 diff --git a/src/headers/sec.h b/src/headers/sec.h index 290cc3e..4c59c7d 100755 --- a/src/headers/sec.h +++ b/src/headers/sec.h @@ -1,11 +1,11 @@ -/* @(#) $Id: sec.h,v 1.20 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/shared.h b/src/headers/shared.h index d3e019b..4165c5b 100755 --- a/src/headers/shared.h +++ b/src/headers/shared.h @@ -1,11 +1,11 @@ -/* @(#) $Id: shared.h,v 1.47 2009/09/17 18:47:23 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -132,7 +132,13 @@ typedef uint8_t u_int8_t; typedef int sock2len_t; #endif -/* For Windows (so high maintenance :)) */ + +#ifndef WIN32 +#define CloseSocket(x) close(x) +#endif + + +/* For Windows */ #ifdef WIN32 typedef int uid_t; typedef int gid_t; @@ -141,6 +147,7 @@ typedef int socklen_t; #define srandom(x) srand(x) #define random(x) rand(x) #define lstat(x,y) stat(x,y) +#define CloseSocket(x) closesocket(x) void WinSetError(); typedef unsigned short int u_int16_t; typedef unsigned char u_int8_t; diff --git a/src/headers/sig_op.h b/src/headers/sig_op.h index 508fbb6..d2ce0f8 100755 --- a/src/headers/sig_op.h +++ b/src/headers/sig_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: sig_op.h,v 1.6 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/store_op.h b/src/headers/store_op.h index 73b6b17..4ae7d3a 100755 --- a/src/headers/store_op.h +++ b/src/headers/store_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: store_op.h,v 1.8 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/validate_op.h b/src/headers/validate_op.h index 6aafdfe..e8e7094 100755 --- a/src/headers/validate_op.h +++ b/src/headers/validate_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: validate_op.h,v 1.13 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/headers/wait_op.h b/src/headers/wait_op.h index 315909f..1755b8f 100755 --- a/src/headers/wait_op.h +++ b/src/headers/wait_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: wait_op.h,v 1.4 2009/06/24 17:06:26 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/init/ossec-client.sh b/src/init/ossec-client.sh index e05d615..f8d6159 100755 --- a/src/init/ossec-client.sh +++ b/src/init/ossec-client.sh @@ -11,7 +11,7 @@ DIR=`dirname $PWD`; ### Do not modify bellow here ### NAME="OSSEC HIDS" -VERSION="v2.3" +VERSION="v2.5.1" AUTHOR="Trend Micro Inc." DAEMONS="ossec-logcollector ossec-syscheckd ossec-agentd ossec-execd" @@ -111,16 +111,8 @@ status() done } - -# Start function -start() +testconfig() { - SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd" - - echo "Starting $NAME $VERSION (by $AUTHOR)..." - lock; - checkpid; - # We first loop to check the config. for i in ${SDAEMONS}; do ${DIR}/bin/${i} -t; @@ -130,6 +122,17 @@ start() exit 1; fi done +} + +# Start function +start() +{ + SDAEMONS="ossec-execd ossec-agentd ossec-logcollector ossec-syscheckd" + + echo "Starting $NAME $VERSION (by $AUTHOR)..." + lock; + checkpid; + # We actually start them now. for i in ${SDAEMONS}; do @@ -214,12 +217,14 @@ stopa() case "$1" in start) + testconfig start ;; stop) stopa ;; restart) + testconfig stopa start ;; diff --git a/src/init/ossec-hids-gentoo.init b/src/init/ossec-hids-gentoo.init index c2d06f6..a579603 100755 --- a/src/init/ossec-hids-gentoo.init +++ b/src/init/ossec-hids-gentoo.init @@ -26,7 +26,7 @@ configtest() { checkconfig() { - CONFIGFILE="${CONFIGFILE:-/var/ossec/etc/ossec.conf}" + CONFIGFILE="${CONFIGFILE:-${DIRECTORY}/etc/ossec.conf}" if [ ! -r "${CONFIGFILE}" ]; then eerror "Unable to read configuration file: ${CONFIGFILE}" return 1 diff --git a/src/init/ossec-local.sh b/src/init/ossec-local.sh index 259bd5d..12f5196 100755 --- a/src/init/ossec-local.sh +++ b/src/init/ossec-local.sh @@ -22,7 +22,7 @@ fi NAME="OSSEC HIDS" -VERSION="v2.3" +VERSION="v2.5.1" AUTHOR="Trend Micro Inc." DAEMONS="ossec-monitord ossec-logcollector ossec-syscheckd ossec-analysisd ossec-maild ossec-execd ${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON}" @@ -115,8 +115,8 @@ enable() { if [ "X$2" = "X" ]; then echo "" - echo "Enable options: database, client-syslog, agentless" - echo "Usage: $0 enable [database|client-syslog|agentless]" + echo "Enable options: database, client-syslog, agentless, debug" + echo "Usage: $0 enable [database|client-syslog|agentless|debug]" exit 1; fi @@ -126,12 +126,14 @@ enable() echo "CSYSLOG_DAEMON=ossec-csyslogd" >> ${PLIST}; elif [ "X$2" = "Xagentless" ]; then echo "AGENTLESS_DAEMON=ossec-agentlessd" >> ${PLIST}; + elif [ "X$2" = "Xdebug" ]; then + echo "DEBUG_CLI=\"-d\"" >> ${PLIST}; else echo "" echo "Invalid enable option." echo "" - echo "Enable options: database, client-syslog, agentless" - echo "Usage: $0 enable [database|client-syslog|agentless]" + echo "Enable options: database, client-syslog, agentless, debug" + echo "Usage: $0 enable [database|client-syslog|agentless|debug]" exit 1; fi @@ -145,8 +147,8 @@ disable() { if [ "X$2" = "X" ]; then echo "" - echo "Disable options: database, client-syslog, agentless" - echo "Usage: $0 disable [database|client-syslog|agentless]" + echo "Disable options: database, client-syslog, agentless, debug" + echo "Usage: $0 disable [database|client-syslog|agentless,debug]" exit 1; fi @@ -156,12 +158,14 @@ disable() echo "CSYSLOG_DAEMON=\"\"" >> ${PLIST}; elif [ "X$2" = "Xagentless" ]; then echo "AGENTLESS_DAEMON=\"\"" >> ${PLIST}; + elif [ "X$2" = "Xdebug" ]; then + echo "DEBUG_CLI=\"\"" >> ${PLIST}; else echo "" echo "Invalid disable option." echo "" - echo "Disable options: database, client-syslog, agentless" - echo "Usage: $0 disable [database|client-syslog|agentless]" + echo "Disable options: database, client-syslog, agentless, debug" + echo "Usage: $0 disable [database|client-syslog|agentless|debug]" exit 1; fi @@ -183,6 +187,19 @@ status() done } +testconfig() +{ + # We first loop to check the config. + for i in ${SDAEMONS}; do + ${DIR}/bin/${i} -t ${DEBUG_CLI}; + if [ $? != 0 ]; then + echo "${i}: Configuration error. Exiting" + unlock; + exit 1; + fi + done +} + # Start function start() @@ -190,24 +207,20 @@ start() SDAEMONS="${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON} ossec-maild ossec-execd ossec-analysisd ossec-logcollector ossec-syscheckd ossec-monitord" echo "Starting $NAME $VERSION (by $AUTHOR)..." + ${DIR}/bin/ossec-logtest -t + if [ ! $? = 0 ]; then + echo "ossec-analysisd: Configuration error. Exiting." + fi + lock; checkpid; - # We first loop to check the config. - for i in ${SDAEMONS}; do - ${DIR}/bin/${i} -t; - if [ $? != 0 ]; then - echo "${i}: Configuration error. Exiting" - unlock; - exit 1; - fi - done # We actually start them now. for i in ${SDAEMONS}; do pstatus ${i}; if [ $? = 0 ]; then - ${DIR}/bin/${i}; + ${DIR}/bin/${i} ${DEBUG_CLI}; if [ $? != 0 ]; then unlock; exit 1; @@ -286,12 +299,14 @@ stopa() case "$1" in start) + testconfig start ;; stop) stopa ;; restart) + testconfig stopa start ;; diff --git a/src/init/ossec-server.sh b/src/init/ossec-server.sh index 307502d..c7f34f9 100755 --- a/src/init/ossec-server.sh +++ b/src/init/ossec-server.sh @@ -22,7 +22,7 @@ fi NAME="OSSEC HIDS" -VERSION="v2.3" +VERSION="v2.5.1" AUTHOR="Trend Micro Inc." DAEMONS="ossec-monitord ossec-logcollector ossec-remoted ossec-syscheckd ossec-analysisd ossec-maild ossec-execd ${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON}" @@ -115,8 +115,8 @@ enable() { if [ "X$2" = "X" ]; then echo "" - echo "Enable options: database, client-syslog, agentless" - echo "Usage: $0 enable [database|client-syslog|agentless]" + echo "Enable options: database, client-syslog, agentless, debug" + echo "Usage: $0 enable [database|client-syslog|agentless|debug]" exit 1; fi @@ -126,12 +126,14 @@ enable() echo "CSYSLOG_DAEMON=ossec-csyslogd" >> ${PLIST}; elif [ "X$2" = "Xagentless" ]; then echo "AGENTLESS_DAEMON=ossec-agentlessd" >> ${PLIST}; + elif [ "X$2" = "Xdebug" ]; then + echo "DEBUG_CLI=\"-d\"" >> ${PLIST}; else echo "" echo "Invalid enable option." echo "" - echo "Enable options: database, client-syslog, agentless" - echo "Usage: $0 enable [database|client-syslog|agentless]" + echo "Enable options: database, client-syslog, agentless, debug" + echo "Usage: $0 enable [database|client-syslog|agentless|debug]" exit 1; fi @@ -145,8 +147,8 @@ disable() { if [ "X$2" = "X" ]; then echo "" - echo "Disable options: database, client-syslog, agentless" - echo "Usage: $0 disable [database|client-syslog|agentless]" + echo "Disable options: database, client-syslog, agentless, debug" + echo "Usage: $0 disable [database|client-syslog|agentless|debug]" exit 1; fi @@ -156,12 +158,14 @@ disable() echo "CSYSLOG_DAEMON=\"\"" >> ${PLIST}; elif [ "X$2" = "Xagentless" ]; then echo "AGENTLESS_DAEMON=\"\"" >> ${PLIST}; + elif [ "X$2" = "Xdebug" ]; then + echo "DEBUG_CLI=\"\"" >> ${PLIST}; else echo "" echo "Invalid disable option." echo "" - echo "Disable options: database, client-syslog, agentless" - echo "Usage: $0 disable [database|client-syslog|agentless]" + echo "Disable options: database, client-syslog, agentless, debug" + echo "Usage: $0 disable [database|client-syslog|agentless|debug]" exit 1; fi @@ -183,6 +187,18 @@ status() done } +testconfig() +{ + # We first loop to check the config. + for i in ${SDAEMONS}; do + ${DIR}/bin/${i} -t ${DEBUG_CLI}; + if [ $? != 0 ]; then + echo "${i}: Configuration error. Exiting" + unlock; + exit 1; + fi + done +} # Start function start() @@ -190,24 +206,19 @@ start() SDAEMONS="${DB_DAEMON} ${CSYSLOG_DAEMON} ${AGENTLESS_DAEMON} ossec-maild ossec-execd ossec-analysisd ossec-logcollector ossec-remoted ossec-syscheckd ossec-monitord" echo "Starting $NAME $VERSION (by $AUTHOR)..." + ${DIR}/bin/ossec-logtest -t + if [ ! $? = 0 ]; then + echo "ossec-analysisd: Configuration error. Exiting." + fi lock; checkpid; - # We first loop to check the config. - for i in ${SDAEMONS}; do - ${DIR}/bin/${i} -t; - if [ $? != 0 ]; then - echo "${i}: Configuration error. Exiting" - unlock; - exit 1; - fi - done # We actually start them now. for i in ${SDAEMONS}; do pstatus ${i}; if [ $? = 0 ]; then - ${DIR}/bin/${i}; + ${DIR}/bin/${i} ${DEBUG_CLI}; if [ $? != 0 ]; then unlock; exit 1; @@ -286,12 +297,14 @@ stopa() case "$1" in start) + testconfig start ;; stop) stopa ;; restart) + testconfig stopa start ;; diff --git a/src/logcollector/COPYRIGHT b/src/logcollector/COPYRIGHT index cd65eb1..a79c2af 100755 --- a/src/logcollector/COPYRIGHT +++ b/src/logcollector/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All right reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation OSSEC, logcollector. diff --git a/src/logcollector/config.c b/src/logcollector/config.c index 67ed253..33d64ab 100755 --- a/src/logcollector/config.c +++ b/src/logcollector/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.20 2009/06/24 18:52:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/logcollector/logcollector.c b/src/logcollector/logcollector.c index f14f007..5e3e3a2 100755 --- a/src/logcollector/logcollector.c +++ b/src/logcollector/logcollector.c @@ -1,11 +1,11 @@ -/* @(#) $Id: logcollector.c,v 1.59 2009/11/03 21:07:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -20,6 +20,22 @@ int _cday = 0; int update_fname(int i); +char *rand_keepalive_str(char *dst, int size) +{ + static const char text[] = "abcdefghijklmnopqrstuvwxyz" + "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + "0123456789" + "!@#$%^&*()_+-=;'[],./?"; + int i, len = rand() % (size - 10); + strncpy(dst, "--MARK--: ", 12); + for ( i = 10; i < len; ++i ) + { + dst[i] = text[rand() % (sizeof text - 1)]; + } + dst[i] = '\0'; + return dst; +} + /** void LogCollectorStart() v0.4 * Handle file management. */ @@ -28,6 +44,10 @@ void LogCollectorStart() int i = 0, r = 0; int max_file = 0; int f_check = 0; + int curr_time = 0; + char keepalive[1024]; + + /* To check for inode changes */ struct stat tmp_stat; @@ -99,10 +119,18 @@ void LogCollectorStart() { logff[i].file = NULL; logff[i].fp = NULL; + logff[i].size = 0; if(logff[i].command) { logff[i].read = (void *)read_command; + + verbose("%s: INFO: Monitoring output of command(%d): %s", ARGV0, logff[i].ign, logff[i].command); + + if(!logff[i].alias) + { + os_strdup(logff[i].command, logff[i].alias); + } } else { @@ -110,6 +138,26 @@ void LogCollectorStart() ARGV0); } } + else if(strcmp(logff[i].logformat, "full_command") == 0) + { + logff[i].file = NULL; + logff[i].fp = NULL; + logff[i].size = 0; + if(logff[i].command) + { + logff[i].read = (void *)read_fullcommand; + + verbose("%s: INFO: Monitoring full output of command(%d): %s", ARGV0, logff[i].ign, logff[i].command); + + if(!logff[i].alias) + os_strdup(logff[i].command, logff[i].alias); + } + else + { + merror("%s: ERROR: Missing command argument. Ignoring it.", + ARGV0); + } + } else { @@ -173,6 +221,10 @@ void LogCollectorStart() } logff[i].read = (void *)read_djbmultilog; } + else if(logff[i].logformat[0] >= '0' && logff[i].logformat[0] <= '9') + { + logff[i].read = (void *)read_multiline; + } else { logff[i].read = (void *)read_syslog; @@ -189,6 +241,19 @@ void LogCollectorStart() } #endif } + + if(logff[i].alias) + { + int ii = 0; + while(logff[i].alias[ii] != '\0') + { + if(logff[i].alias[ii] == ':') + { + logff[i].alias[ii] = '\\'; + } + ii++; + } + } } @@ -243,9 +308,14 @@ void LogCollectorStart() if(!logff[i].fp) { /* Run the command. */ - if((f_check == VCHECK_FILES) && logff[i].command) + if(logff[i].command && (f_check %2)) { - logff[i].read(i, &r, 0); + curr_time = time(0); + if((curr_time - logff[i].size) >= logff[i].ign) + { + logff[i].size = curr_time; + logff[i].read(i, &r, 0); + } } continue; } @@ -338,7 +408,9 @@ void LogCollectorStart() /* Send keep alive message */ - SendMSG(logr_queue, "--MARK--", "ossec-keepalive", LOCALFILE_MQ); + + rand_keepalive_str(keepalive, 700); + SendMSG(logr_queue, keepalive, "ossec-keepalive", LOCALFILE_MQ); /* Zeroing f_check */ diff --git a/src/logcollector/logcollector.h b/src/logcollector/logcollector.h index 143bcac..6117b64 100755 --- a/src/logcollector/logcollector.h +++ b/src/logcollector/logcollector.h @@ -1,11 +1,11 @@ -/* @(#) $Id: logcollector.h,v 1.28 2009/11/03 21:07:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -57,6 +57,9 @@ void *read_mssql_log(int pos, int *rc, int drop_it); /* Read postgresql log format */ void *read_postgresql_log(int pos, int *rc, int drop_it); +/* read multi line logs. */ +void *read_multiline(int pos, int *rc, int drop_it); + /* Read DJB multilog format */ /* Initializes multilog. */ int init_djbmultilog(int pos); @@ -65,6 +68,7 @@ void *read_djbmultilog(int pos, int *rc, int drop_it); /* Read events from output of command */ void *read_command(int pos, int *rc, int drop_it); +void *read_fullcommand(int pos, int *rc, int drop_it); #ifdef WIN32 diff --git a/src/logcollector/main.c b/src/logcollector/main.c index 5340c85..8608a58 100755 --- a/src/logcollector/main.c +++ b/src/logcollector/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.27 2009/11/18 19:07:40 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -45,6 +45,17 @@ int main(int argc, char **argv) char *dir = DEFAULTDIR; + /* Setuping up random */ + #ifndef WIN32 + #ifdef __OpenBSD__ + srandomdev(); + #else + srandom(time(0)); + #endif + #else + srandom(time(0)) + #endif + /* Setting the name */ OS_SetName(ARGV0); diff --git a/src/logcollector/read_command.c b/src/logcollector/read_command.c index 9c1f7ca..a6c413f 100755 --- a/src/logcollector/read_command.c +++ b/src/logcollector/read_command.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_command.c,v 1.3 2009/11/05 19:55:34 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -43,7 +43,10 @@ void *read_command(int pos, int *rc, int drop_it) } - snprintf(str, 256, "ossec: output: '%s': ", logff[pos].command); + snprintf(str, 256, "ossec: output: '%s': ", + (NULL != logff[pos].alias) + ? logff[pos].alias + : logff[pos].command); cmd_size = strlen(str); @@ -54,6 +57,19 @@ void *read_command(int pos, int *rc, int drop_it) { *p = '\0'; } + + /* Removing empty lines. */ + #ifdef WIN32 + if(str[0] == '\r' && str[1] == '\0') + { + continue; + } + #endif + if(str[0] == '\0') + { + continue; + } + debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str); @@ -61,7 +77,8 @@ void *read_command(int pos, int *rc, int drop_it) /* Sending message to queue */ if(drop_it == 0) { - if(SendMSG(logr_queue,str,logff[pos].command, + if(SendMSG(logr_queue,str, + (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command, LOCALFILE_MQ) < 0) { merror(QUEUE_SEND, ARGV0); diff --git a/src/logcollector/read_djb_multilog.c b/src/logcollector/read_djb_multilog.c index 8a6ceec..18a2001 100755 --- a/src/logcollector/read_djb_multilog.c +++ b/src/logcollector/read_djb_multilog.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_djb_multilog.c,v 1.4 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/logcollector/read_fullcommand.c b/src/logcollector/read_fullcommand.c new file mode 100755 index 0000000..11d256b --- /dev/null +++ b/src/logcollector/read_fullcommand.c @@ -0,0 +1,112 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + +/* Read the syslog */ + + +#include "shared.h" +#include "logcollector.h" + + + +/* Read Output of commands */ +void *read_fullcommand(int pos, int *rc, int drop_it) +{ + int n = 0; + int cmd_size = 0; + char *p; + char str[OS_MAXSTR+1]; + char strfinal[OS_MAXSTR+1]; + + FILE *cmd_output; + + str[OS_MAXSTR]= '\0'; + strfinal[OS_MAXSTR]= '\0'; + *rc = 0; + + + debug2("%s: DEBUG: Running full command '%s'", ARGV0, logff[pos].command); + + + cmd_output = popen(logff[pos].command, "r"); + if(!cmd_output) + { + merror("%s: ERROR: Unable to execute command: '%s'.", + ARGV0, logff[pos].command); + + logff[pos].command = NULL; + } + + + snprintf(str, 256, "ossec: output: '%s':\n", + (NULL != logff[pos].alias) + ? logff[pos].alias + : logff[pos].command); + cmd_size = strlen(str); + + n = fread(str + cmd_size, 1, OS_MAXSTR - OS_LOG_HEADER - 256, cmd_output); + if(n > 0) + { + str[cmd_size +n] = '\0'; + + /* Getting the last occurence of \n */ + if ((p = strrchr(str, '\n')) != NULL) + { + *p = '\0'; + } + + + debug2("%s: DEBUG: Reading command message: '%s'", ARGV0, str); + + /* Removing empty lines. */ + n = 0; + p = str; + while(*p != '\0') + { + if(p[0] == '\r') + { + p++; + continue; + } + + if(p[0] == '\n' && p[1] == '\n') + { + p++; + } + strfinal[n] = *p; + n++; + p++; + } + strfinal[n] = '\0'; + + + /* Sending message to queue */ + if(drop_it == 0) + { + if(SendMSG(logr_queue,strfinal, + (NULL != logff[pos].alias) ? logff[pos].alias : logff[pos].command, + LOCALFILE_MQ) < 0) + { + merror(QUEUE_SEND, ARGV0); + if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0) + { + ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH); + } + } + } + } + + pclose(cmd_output); + + return(NULL); +} + +/* EOF */ diff --git a/src/logcollector/read_mssql_log.c b/src/logcollector/read_mssql_log.c index 025a7cd..41ad273 100755 --- a/src/logcollector/read_mssql_log.c +++ b/src/logcollector/read_mssql_log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_mssql_log.c,v 1.2 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/logcollector/read_multiline.c b/src/logcollector/read_multiline.c new file mode 100755 index 0000000..29a565d --- /dev/null +++ b/src/logcollector/read_multiline.c @@ -0,0 +1,135 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + +/* Read the syslog */ + + +#include "shared.h" +#include "logcollector.h" + + + +/* Read multiline logs. */ +void *read_multiline(int pos, int *rc, int drop_it) +{ + int __ms = 0; + int linecount; + int linesgot = 0; + int buffer_size = 0; + char *p; + char str[OS_MAXSTR + 1]; + char buffer[OS_MAXSTR +1]; + + fpos_t fp_pos; + + buffer[0] = '\0'; + buffer[OS_MAXSTR] = '\0'; + str[OS_MAXSTR]= '\0'; + *rc = 0; + + linecount = atoi(logff[pos].logformat); + + /* Getting initial file location */ + fgetpos(logff[pos].fp, &fp_pos); + + while(fgets(str, OS_MAXSTR - OS_LOG_HEADER, logff[pos].fp) != NULL) + { + linesgot++; + + /* Getting the last occurence of \n */ + if ((p = strrchr(str, '\n')) != NULL) + { + *p = '\0'; + } + + /* If we didn't get the new line, because the + * size is large, send what we got so far. + */ + else if(strlen(str) >= (OS_MAXSTR - OS_LOG_HEADER - 2)) + { + /* Message size > maximum allowed */ + __ms = 1; + } + else + { + /* Message not complete. Return. */ + debug1("%s: Message not complete. Trying again: '%s'", ARGV0,str); + fsetpos(logff[pos].fp, &fp_pos); + break; + } + + #ifdef WIN32 + if ((p = strrchr(str, '\r')) != NULL) + { + *p = '\0'; + } + #endif + + debug2("%s: DEBUG: Reading message: '%s'", ARGV0, str); + + + /* Adding to buffer. */ + buffer_size = strlen(buffer); + if(buffer[0] != '\0') + { + buffer[buffer_size] = ' '; + buffer_size++; + } + + strncpy(buffer + buffer_size, str, OS_MAXSTR - buffer_size -2); + + + if(linesgot < linecount) + { + continue; + } + + + /* Sending message to queue */ + if(drop_it == 0) + { + if(SendMSG(logr_queue, buffer, logff[pos].file, + LOCALFILE_MQ) < 0) + { + merror(QUEUE_SEND, ARGV0); + if((logr_queue = StartMQ(DEFAULTQPATH,WRITE)) < 0) + { + ErrorExit(QUEUE_FATAL, ARGV0, DEFAULTQPATH); + } + } + } + + buffer[0] = '\0'; + + + /* Incorrectly message size */ + if(__ms) + { + merror("%s: Large message size: '%s'", ARGV0, str); + while(fgets(str, OS_MAXSTR - 2, logff[pos].fp) != NULL) + { + /* Getting the last occurence of \n */ + if ((p = strrchr(str, '\n')) != NULL) + { + break; + } + } + __ms = 0; + } + + fgetpos(logff[pos].fp, &fp_pos); + continue; + } + + return(NULL); +} + +/* EOF */ diff --git a/src/logcollector/read_mysql_log.c b/src/logcollector/read_mysql_log.c index 926a760..68dafc9 100755 --- a/src/logcollector/read_mysql_log.c +++ b/src/logcollector/read_mysql_log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_mysql_log.c,v 1.5 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/logcollector/read_nmapg.c b/src/logcollector/read_nmapg.c index d06648a..da32d18 100755 --- a/src/logcollector/read_nmapg.c +++ b/src/logcollector/read_nmapg.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_nmapg.c,v 1.11 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/logcollector/read_postgresql_log.c b/src/logcollector/read_postgresql_log.c index d2262d5..6fea175 100755 --- a/src/logcollector/read_postgresql_log.c +++ b/src/logcollector/read_postgresql_log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_postgresql_log.c,v 1.5 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/logcollector/read_snortfull.c b/src/logcollector/read_snortfull.c index 56d09c5..951b2d8 100755 --- a/src/logcollector/read_snortfull.c +++ b/src/logcollector/read_snortfull.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_snortfull.c,v 1.19 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/logcollector/read_syslog.c b/src/logcollector/read_syslog.c index 5f0bd69..f01c3f7 100755 --- a/src/logcollector/read_syslog.c +++ b/src/logcollector/read_syslog.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_syslog.c,v 1.24 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/logcollector/read_win_el.c b/src/logcollector/read_win_el.c index a0d077f..7eeda3d 100755 --- a/src/logcollector/read_win_el.c +++ b/src/logcollector/read_win_el.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read_win_el.c,v 1.21 2009/09/04 19:23:11 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/monitord/Makefile b/src/monitord/Makefile index 4834978..56f7348 100755 --- a/src/monitord/Makefile +++ b/src/monitord/Makefile @@ -6,9 +6,9 @@ NAME=ossec-monitord include ../Config.Make -LOCAL = compress_log.c main.c manage_files.c monitor_agents.c monitord.c sign_log.c +LOCAL = compress_log.c main.c manage_files.c monitor_agents.c monitord.c sign_log.c generate_reports.c ../os_maild/sendcustomemail.c -OBJS = ${OS_SHARED} ${OS_NET} ${OS_REGEX} ${OS_CRYPTO} ${OS_ZLIB} +OBJS = ${OS_CONFIG} ${OS_SHARED} ${OS_NET} ${OS_REGEX} ${OS_XML} ${OS_CRYPTO} ${OS_ZLIB} mmonitor: ${CC} ${CFLAGS} ${OS_LINK} ${LOCAL} ${OBJS} -o ${NAME} diff --git a/src/monitord/compress_log.c b/src/monitord/compress_log.c index 7cf11bd..9f2fa10 100755 --- a/src/monitord/compress_log.c +++ b/src/monitord/compress_log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: compress_log.c,v 1.4 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/monitord/generate_reports.c b/src/monitord/generate_reports.c new file mode 100755 index 0000000..6e076c4 --- /dev/null +++ b/src/monitord/generate_reports.c @@ -0,0 +1,141 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + +#include "shared.h" +#include "monitord.h" +int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, FILE *fp, struct tm *p); +char *(monthss[])={"Jan","Feb","Mar","Apr","May","Jun","Jul","Aug", + "Sep","Oct","Nov","Dec"}; + + +void generate_reports(int cday, int cmon, int cyear,struct tm *p) +{ + int s = 0; + + if(!mond.smtpserver) + { + return; + } + + if(mond.reports) + { + int twait = 0; + int childcount = 0; + while(mond.reports[s]) + { + pid_t pid; + if(mond.reports[s]->emailto == NULL) + { + s++; + continue; + } + + /* We create a new process to run the report and send the email. + * To avoid crashing monitord if something goes wrong. + */ + pid = fork(); + if(pid < 0) + { + merror("%s: ERROR: Fork failed. cause: %d - %s", ARGV0, errno, strerror(errno)); + s++; + continue; + } + else if(pid == 0) + { + char fname[256]; + char aname[256]; + fname[255] = '\0'; + aname[255] = '\0'; + snprintf(fname, 255, "/logs/.report-%d.log", getpid()); + + merror("%s: INFO: Starting daily reporting for '%s'", ARGV0, mond.reports[s]->title); + mond.reports[s]->r_filter.fp = fopen(fname, "w+"); + if(!mond.reports[s]->r_filter.fp) + { + merror("%s: ERROR: Unable to open temporary reports file.", ARGV0); + s++; + continue; + } + + + /* Opening the log file. */ + snprintf(aname, 255, "%s/%d/%s/ossec-%s-%02d.log", + ALERTS, cyear, monthss[cmon], "alerts", cday); + os_strdup(aname, mond.reports[s]->r_filter.filename); + + + /* Starting report */ + os_ReportdStart(&mond.reports[s]->r_filter); + fflush(mond.reports[s]->r_filter.fp); + + if(ftell(mond.reports[s]->r_filter.fp) < 10) + { + merror("%s: INFO: Report '%s' empty.", ARGV0, mond.reports[s]->title); + } + else if(OS_SendCustomEmail(mond.reports[s]->emailto, mond.reports[s]->title, + mond.smtpserver, mond.emailfrom, mond.reports[s]->r_filter.fp, p) != 0) + { + merror("%s: WARN: Unable to send report email.", ARGV0); + } + fclose(mond.reports[s]->r_filter.fp); + unlink(fname); + free(mond.reports[s]->r_filter.filename); + mond.reports[s]->r_filter.filename = NULL; + + exit(0); + } + else + { + /* Sleep between each report. Time is not important in here. */ + sleep(20); + childcount++; + } + + s++; + } + + + while (childcount) + { + int wp; + wp = waitpid((pid_t) -1, NULL, WNOHANG); + if (wp < 0) + { + merror(WAITPID_ERROR, ARGV0); + } + else if(wp == 0) + { + /* If there is still any report left, sleep 5 and try again.*/ + sleep(5); + twait++; + + if(twait > 2) + { + merror("%s: WARN: Report taking too long to complete. Waiting for it to finish...", ARGV0); + sleep(10); + if(twait > 10) + { + merror("%s: WARN: Report took too long. Moving on...", ARGV0); + break; + } + } + } + else + { + childcount--; + } + } + } + return; +} + +/* EOF */ diff --git a/src/monitord/main.c b/src/monitord/main.c index 0eee48b..a491529 100755 --- a/src/monitord/main.c +++ b/src/monitord/main.c @@ -1,17 +1,19 @@ -/* @(#) $Id: main.c,v 1.9 2009/11/18 19:07:40 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ #include "shared.h" +#include "config/config.h" #include "monitord.h" +#include "os_net/os_net.h" int main(int argc, char **argv) @@ -95,6 +97,57 @@ int main(int argc, char **argv) mond.monitor_agents = getDefine_Int("monitord","monitor_agents",0,1); mond.agents = NULL; + mond.smtpserver = NULL; + mond.emailfrom = NULL; + + + c = 0; + c|= CREPORTS; + if(ReadConfig(c, cfg, &mond, NULL) < 0) + { + ErrorExit(CONFIG_ERROR, ARGV0, cfg); + } + + /* If we have any reports configured, read smtp/emailfrom */ + if(mond.reports) + { + OS_XML xml; + char *tmpsmtp; + + char *(xml_smtp[])={"ossec_config", "global", "smtp_server", NULL}; + char *(xml_from[])={"ossec_config", "global", "email_from", NULL}; + + if(OS_ReadXML(cfg, &xml) < 0) + { + ErrorExit(CONFIG_ERROR, ARGV0, cfg); + } + + tmpsmtp = OS_GetOneContentforElement(&xml,xml_smtp); + mond.emailfrom = OS_GetOneContentforElement(&xml,xml_from); + + if(tmpsmtp && mond.emailfrom) + { + mond.smtpserver = OS_GetHost(tmpsmtp, 5); + if(!mond.smtpserver) + { + merror(INVALID_SMTP, ARGV0, tmpsmtp); + if(mond.emailfrom) free(mond.emailfrom); + mond.emailfrom = NULL; + merror("%s: Invalid SMTP server. Disabling email reports.", ARGV0); + } + } + else + { + if(tmpsmtp) free(tmpsmtp); + if(mond.emailfrom) free(mond.emailfrom); + + mond.emailfrom = NULL; + + merror("%s: SMTP server or 'email from' missing. Disabling email reports.", ARGV0); + } + + OS_ClearXML(&xml); + } /* Exit here if test config is set */ diff --git a/src/monitord/manage_files.c b/src/monitord/manage_files.c index 2c1d492..7ba33fc 100755 --- a/src/monitord/manage_files.c +++ b/src/monitord/manage_files.c @@ -1,11 +1,11 @@ -/* @(#) $Id: manage_files.c,v 1.10 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/monitord/monitor_agents.c b/src/monitord/monitor_agents.c index 66c1587..133d31f 100755 --- a/src/monitord/monitor_agents.c +++ b/src/monitord/monitor_agents.c @@ -1,11 +1,11 @@ -/* @(#) $Id: monitor_agents.c,v 1.5 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/monitord/monitord.c b/src/monitord/monitord.c index b68d984..33ab59d 100755 --- a/src/monitord/monitord.c +++ b/src/monitord/monitord.c @@ -1,11 +1,11 @@ -/* @(#) $Id: monitord.c,v 1.9 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -77,6 +77,9 @@ void Monitord() /* Day changed, deal with log files */ if(today != p->tm_mday) { + /* Generate reports. */ + generate_reports(today, thismonth, thisyear, p); + manage_files(today, thismonth, thisyear); today = p->tm_mday; diff --git a/src/monitord/monitord.h b/src/monitord/monitord.h index 18e97e5..7a9c7a7 100755 --- a/src/monitord/monitord.h +++ b/src/monitord/monitord.h @@ -1,11 +1,11 @@ -/* @(#) $Id: monitord.h,v 1.7 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -16,17 +16,9 @@ #ifndef ARGV0 #define ARGV0 "ossec-monitord" #endif - -typedef struct _monitor_config -{ - short int day_wait; - short int compress; - short int sign; - short int monitor_agents; - int a_queue; - char **agents; -}monitor_config; +#include "config/reports-config.h" + /** Prototypes **/ @@ -37,6 +29,9 @@ void Monitord(); /*manage_files */ void manage_files(int cday, int cmon, int cyear); +/* generate reports. */ +void generate_reports(int cday, int cmon, int cyear, struct tm *p); + /* monitor_agents */ void monitor_agents(); diff --git a/src/monitord/report.c b/src/monitord/report.c index bddeb89..0494132 100755 --- a/src/monitord/report.c +++ b/src/monitord/report.c @@ -1,11 +1,11 @@ -/* @(#) $Id: report.c,v 1.4 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ -/* Copyright (C) 2009 Trend Micro Inc. +/* Copyright (C) 2010 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -56,6 +56,8 @@ int main(int argc, char **argv) r_filter.rule = NULL; r_filter.level = NULL; r_filter.location = NULL; + r_filter.srcip = NULL; + r_filter.user = NULL; r_filter.related_group = 0; r_filter.related_rule = 0; @@ -73,7 +75,7 @@ int main(int argc, char **argv) print_version(); break; case 'h': - report_help(ARGV0); + report_help(); break; case 'd': nowDebug(); @@ -132,7 +134,7 @@ int main(int argc, char **argv) test_config = 1; break; default: - report_help(ARGV0); + report_help(); break; } diff --git a/src/monitord/sign_log.c b/src/monitord/sign_log.c index 27adb2f..bbe1574 100755 --- a/src/monitord/sign_log.c +++ b/src/monitord/sign_log.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sign_log.c,v 1.8 2009/06/24 17:06:27 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/blowfish/bf_op.c b/src/os_crypto/blowfish/bf_op.c index fe81831..6cbff2f 100755 --- a/src/os_crypto/blowfish/bf_op.c +++ b/src/os_crypto/blowfish/bf_op.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/blowfish/bf_op.h b/src/os_crypto/blowfish/bf_op.h index 13b9518..58e98ab 100755 --- a/src/os_crypto/blowfish/bf_op.h +++ b/src/os_crypto/blowfish/bf_op.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/md5/md5_op.c b/src/os_crypto/md5/md5_op.c index fdd9958..9e3dc5d 100755 --- a/src/os_crypto/md5/md5_op.c +++ b/src/os_crypto/md5/md5_op.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/md5/md5_op.h b/src/os_crypto/md5/md5_op.h index 3af94d7..c4b07f1 100755 --- a/src/os_crypto/md5/md5_op.h +++ b/src/os_crypto/md5/md5_op.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/md5_sha1/md5_sha1_op.c b/src/os_crypto/md5_sha1/md5_sha1_op.c index d38e542..c2a168a 100755 --- a/src/os_crypto/md5_sha1/md5_sha1_op.c +++ b/src/os_crypto/md5_sha1/md5_sha1_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: md5_sha1_op.c,v 1.3 2009/06/24 17:06:28 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/md5_sha1/md5_sha1_op.h b/src/os_crypto/md5_sha1/md5_sha1_op.h index 05ccb93..1e2b725 100755 --- a/src/os_crypto/md5_sha1/md5_sha1_op.h +++ b/src/os_crypto/md5_sha1/md5_sha1_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: md5_sha1_op.h,v 1.3 2009/06/24 17:06:28 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/sha1/Makefile b/src/os_crypto/sha1/Makefile index 40b5f1f..28e5ac4 100755 --- a/src/os_crypto/sha1/Makefile +++ b/src/os_crypto/sha1/Makefile @@ -9,6 +9,7 @@ include ../../Config.Make SRCS = sha1_op.c sha1_OBJS = sha1_op.o +CC=$(GCC) sha1: diff --git a/src/os_crypto/sha1/md32_common.h b/src/os_crypto/sha1/md32_common.h index 0081ec5..abb9c78 100755 --- a/src/os_crypto/sha1/md32_common.h +++ b/src/os_crypto/sha1/md32_common.h @@ -1,4 +1,4 @@ -/* @(#) $Id: md32_common.h,v 1.2 2007/09/22 03:29:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Included on ossec */ /* crypto/md32_common.h */ diff --git a/src/os_crypto/sha1/sha.h b/src/os_crypto/sha1/sha.h index 4079cb4..86f4162 100755 --- a/src/os_crypto/sha1/sha.h +++ b/src/os_crypto/sha1/sha.h @@ -1,4 +1,4 @@ -/* @(#) $Id: sha.h,v 1.1 2006/07/12 18:28:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Included on ossec */ diff --git a/src/os_crypto/sha1/sha1_op.c b/src/os_crypto/sha1/sha1_op.c index 3b1ad04..159c3cf 100755 --- a/src/os_crypto/sha1/sha1_op.c +++ b/src/os_crypto/sha1/sha1_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sha1_op.c,v 1.7 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/sha1/sha1_op.h b/src/os_crypto/sha1/sha1_op.h index 4fa20f2..65abe70 100755 --- a/src/os_crypto/sha1/sha1_op.h +++ b/src/os_crypto/sha1/sha1_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: sha1_op.h,v 1.4 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_crypto/sha1/sha_locl.h b/src/os_crypto/sha1/sha_locl.h index 599a054..d5eba2e 100755 --- a/src/os_crypto/sha1/sha_locl.h +++ b/src/os_crypto/sha1/sha_locl.h @@ -1,4 +1,4 @@ -/* @(#) $Id: sha_locl.h,v 1.2 2007/09/22 03:29:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Included on ossec */ diff --git a/src/os_crypto/shared/keys.c b/src/os_crypto/shared/keys.c index 9e6d7e7..d70aab5 100755 --- a/src/os_crypto/shared/keys.c +++ b/src/os_crypto/shared/keys.c @@ -1,11 +1,11 @@ -/* @(#) $Id: keys.c,v 1.10 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_crypto/shared/msgs.c b/src/os_crypto/shared/msgs.c index 6d22a09..c15297e 100755 --- a/src/os_crypto/shared/msgs.c +++ b/src/os_crypto/shared/msgs.c @@ -1,11 +1,11 @@ -/* @(#) $Id: msgs.c,v 1.10 2009/08/10 14:27:37 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_csyslogd/alert.c b/src/os_csyslogd/alert.c index 6d38990..cef1454 100755 --- a/src/os_csyslogd/alert.c +++ b/src/os_csyslogd/alert.c @@ -1,11 +1,11 @@ -/* @(#) $Id: alert.c,v 1.5 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_csyslogd/config.c b/src/os_csyslogd/config.c index fbeb54e..c087754 100755 --- a/src/os_csyslogd/config.c +++ b/src/os_csyslogd/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.2 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_csyslogd/csyslogd.c b/src/os_csyslogd/csyslogd.c index 7622133..97d7ff9 100755 --- a/src/os_csyslogd/csyslogd.c +++ b/src/os_csyslogd/csyslogd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: csyslogd.c,v 1.3 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_csyslogd/csyslogd.h b/src/os_csyslogd/csyslogd.h index 08bb9b9..87bfc40 100755 --- a/src/os_csyslogd/csyslogd.h +++ b/src/os_csyslogd/csyslogd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: csyslogd.h,v 1.2 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_csyslogd/main.c b/src/os_csyslogd/main.c index 1f9f420..1d8a11f 100755 --- a/src/os_csyslogd/main.c +++ b/src/os_csyslogd/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.4 2009/11/18 19:07:40 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/alert.c b/src/os_dbd/alert.c index 56fd1a3..517b65c 100755 --- a/src/os_dbd/alert.c +++ b/src/os_dbd/alert.c @@ -1,11 +1,11 @@ -/* @(#) $Id: alert.c,v 1.8 2009/06/24 17:06:29 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or @@ -106,13 +106,16 @@ int __DBInsertLocation(char *location, DBConfig *db_config) */ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config) { + int i; unsigned int s_ip = 0, d_ip = 0, location_id = 0; int *loc_id; - char sql_query[OS_SIZE_2048 +1]; + char sql_query[OS_SIZE_8192 +1]; + char *fulllog = NULL; /* Clearing the memory before insert */ - memset(sql_query, '\0', OS_SIZE_2048 +1); + sql_query[0] = '\0'; + sql_query[OS_SIZE_8192] = '\0'; /* Converting srcip to int */ @@ -131,7 +134,6 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config) /* Escaping strings */ osdb_escapestr(al_data->user); - osdb_escapestr(al_data->log[0]); /* We first need to insert the location */ @@ -164,26 +166,38 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config) } + i = 0; + while(al_data->log[i]) + { + fulllog = os_LoadString(fulllog, al_data->log[i]); + i++; + } + osdb_escapestr(fulllog); + + /* Inserting data */ if(db_config->db_type == POSTGDB) { /* On postgres we need to escape the user field. */ - snprintf(sql_query, OS_SIZE_2048, + snprintf(sql_query, OS_SIZE_8192, "INSERT INTO " "data(id, server_id, \"user\", full_log) " "VALUES ('%u', '%u', '%s', '%s') ", db_config->alert_id, db_config->server_id, - al_data->user, al_data->log[0]); + al_data->user, fulllog); } else { - snprintf(sql_query, OS_SIZE_2048, + snprintf(sql_query, OS_SIZE_8192, "INSERT INTO " "data(id, server_id, user, full_log) " "VALUES ('%u', '%u', '%s', '%s') ", db_config->alert_id, db_config->server_id, - al_data->user, al_data->log[0]); + al_data->user, fulllog); } + + free(fulllog); + fulllog = NULL; /* Inserting into the db */ @@ -195,7 +209,7 @@ int OS_Alert_InsertDB(alert_data *al_data, DBConfig *db_config) /* Generating final SQL */ - snprintf(sql_query, OS_SIZE_2048, + snprintf(sql_query, OS_SIZE_8192, "INSERT INTO " "alert(id,server_id,rule_id,timestamp,location_id,src_ip) " "VALUES ('%u', '%u', '%u','%u', '%u', '%lu')", diff --git a/src/os_dbd/config.c b/src/os_dbd/config.c index fed44dd..ee422b6 100755 --- a/src/os_dbd/config.c +++ b/src/os_dbd/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.9 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/db_op.c b/src/os_dbd/db_op.c index 81eb76b..f5ff2f6 100755 --- a/src/os_dbd/db_op.c +++ b/src/os_dbd/db_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: db_op.c,v 1.17 2009/12/01 01:49:55 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/db_op.h b/src/os_dbd/db_op.h index e8b3552..fdbe101 100755 --- a/src/os_dbd/db_op.h +++ b/src/os_dbd/db_op.h @@ -1,11 +1,11 @@ -/* @(#) $Id: db_op.h,v 1.7 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/dbd.c b/src/os_dbd/dbd.c index c62c0ac..925e01b 100755 --- a/src/os_dbd/dbd.c +++ b/src/os_dbd/dbd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: dbd.c,v 1.6 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/dbd.h b/src/os_dbd/dbd.h index 17d7150..dc4a329 100755 --- a/src/os_dbd/dbd.h +++ b/src/os_dbd/dbd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: dbd.h,v 1.6 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/main.c b/src/os_dbd/main.c index d674e33..613ef50 100755 --- a/src/os_dbd/main.c +++ b/src/os_dbd/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.17 2009/11/18 19:07:40 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/mysql.schema b/src/os_dbd/mysql.schema index c8fa067..b95ff77 100644 --- a/src/os_dbd/mysql.schema +++ b/src/os_dbd/mysql.schema @@ -1,11 +1,11 @@ -# @(#) $Id: mysql.schema,v 1.8 2009/06/24 17:06:30 dcid Exp $ */ +# @(#) $Id$ */ # # Copyright (C) 2009 Trend Micro Inc. # All rights reserved. # # This program is a free software; you can redistribute it # and/or modify it under the terms of the GNU General Public -# License (version 3) as published by the FSF - Free Software +# License (version 2) as published by the FSF - Free Software # Foundation. # # License details at the LICENSE file included with OSSEC or @@ -75,8 +75,11 @@ CREATE TABLE data server_id SMALLINT UNSIGNED NOT NULL, user TEXT NOT NULL, full_log TEXT NOT NULL, - PRIMARY KEY (id, server_id) + timestamp TIMESTAMP NOT NULL, + PRIMARY KEY (id, server_id), + INDEX time (timestamp) ); + CREATE TABLE alert ( diff --git a/src/os_dbd/postgresql.schema b/src/os_dbd/postgresql.schema index 6544d95..ea098e0 100644 --- a/src/os_dbd/postgresql.schema +++ b/src/os_dbd/postgresql.schema @@ -1,11 +1,11 @@ --- @(#) $Id: postgresql.schema,v 1.4 2009/06/24 17:06:30 dcid Exp $ */ +-- @(#) $Id$ */ -- -- Copyright (C) 2009 Trend Micro Inc. -- All rights reserved. -- -- This program is a free software; you can redistribute it -- and/or modify it under the terms of the GNU General Public --- License (version 3) as published by the FSF - Free Software +-- License (version 2) as published by the FSF - Free Software -- Foundation. -- -- License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/rules.c b/src/os_dbd/rules.c index a451423..e1fc23d 100755 --- a/src/os_dbd/rules.c +++ b/src/os_dbd/rules.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rules.c,v 1.9 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_dbd/server.c b/src/os_dbd/server.c index 79b5037..8a418b9 100755 --- a/src/os_dbd/server.c +++ b/src/os_dbd/server.c @@ -1,11 +1,11 @@ -/* @(#) $Id: server.c,v 1.7 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_execd/config.c b/src/os_execd/config.c index c49ba78..f275217 100755 --- a/src/os_execd/config.c +++ b/src/os_execd/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.14 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_execd/exec.c b/src/os_execd/exec.c index 8f033f5..b90bb40 100755 --- a/src/os_execd/exec.c +++ b/src/os_execd/exec.c @@ -1,11 +1,11 @@ -/* @(#) $Id: exec.c,v 1.20 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_execd/execd.c b/src/os_execd/execd.c index e84b68b..d1b637c 100755 --- a/src/os_execd/execd.c +++ b/src/os_execd/execd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: execd.c,v 1.39 2009/11/18 19:07:41 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_execd/execd.h b/src/os_execd/execd.h index e26bb5c..ddc20fa 100755 --- a/src/os_execd/execd.h +++ b/src/os_execd/execd.h @@ -1,11 +1,11 @@ -/* @(#) $Id: execd.h,v 1.12 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * More details at the LICENSE file included with OSSEC or diff --git a/src/os_execd/win_execd.c b/src/os_execd/win_execd.c index 3a02ffe..c3203af 100755 --- a/src/os_execd/win_execd.c +++ b/src/os_execd/win_execd.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win_execd.c,v 1.4 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_maild/config.c b/src/os_maild/config.c index 6a0194e..311a87e 100755 --- a/src/os_maild/config.c +++ b/src/os_maild/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.13 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_maild/mail_list.c b/src/os_maild/mail_list.c index 7537428..1e70a9e 100755 --- a/src/os_maild/mail_list.c +++ b/src/os_maild/mail_list.c @@ -1,11 +1,11 @@ -/* @(#) $Id: mail_list.c,v 1.6 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_maild/mail_list.h b/src/os_maild/mail_list.h index 4e62132..fde0381 100755 --- a/src/os_maild/mail_list.h +++ b/src/os_maild/mail_list.h @@ -1,11 +1,11 @@ -/* @(#) $Id: mail_list.h,v 1.6 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_maild/maild.c b/src/os_maild/maild.c index 0e2a506..0f6501a 100755 --- a/src/os_maild/maild.c +++ b/src/os_maild/maild.c @@ -1,11 +1,11 @@ -/* @(#) $Id: maild.c,v 1.34 2009/11/18 19:07:41 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_maild/maild.h b/src/os_maild/maild.h index 43a5709..e11a48d 100755 --- a/src/os_maild/maild.h +++ b/src/os_maild/maild.h @@ -1,11 +1,11 @@ -/* @(#) $Id: maild.h,v 1.23 2009/06/24 17:06:30 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -66,6 +66,7 @@ MailMsg *OS_RecvMailQ(file_queue *fileq, struct tm *p, MailConfig *mail, /* Sends an email */ int OS_Sendmail(MailConfig *mail, struct tm *p); int OS_Sendsms(MailConfig *mail, struct tm *p, MailMsg *sms_msg); +int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, FILE *fp, struct tm *p); /* Mail timeout used by the file-queue */ diff --git a/src/os_maild/os_maild_client.c b/src/os_maild/os_maild_client.c index 118d2e6..99a1fb7 100755 --- a/src/os_maild/os_maild_client.c +++ b/src/os_maild/os_maild_client.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_maild_client.c,v 1.22 2009/06/24 17:06:31 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_maild/sendcustomemail.c b/src/os_maild/sendcustomemail.c new file mode 100755 index 0000000..ea2b203 --- /dev/null +++ b/src/os_maild/sendcustomemail.c @@ -0,0 +1,280 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + +/* Basic e-mailing operations */ + + +#include "shared.h" +#include "os_net/os_net.h" +#include "maild.h" + + +/* Return codes (from SMTP server) */ +#define VALIDBANNER "220" +#define VALIDMAIL "250" +#define VALIDDATA "354" + + +/* Default values use to connect */ +#define SMTP_DEFAULT_PORT 25 +#define HELOMSG "Helo notify.ossec.net\r\n" +#define MAILFROM "Mail From: <%s>\r\n" +#define RCPTTO "Rcpt To: <%s>\r\n" +#define DATAMSG "DATA\r\n" +#define FROM "From: OSSEC HIDS <%s>\r\n" +#define TO "To: <%s>\r\n" +#define CC "Cc: <%s>\r\n" +#define SUBJECT "Subject: %s\r\n" +#define ENDDATA "\r\n.\r\n" +#define QUITMSG "QUIT\r\n" + + +/* Error messages - Can be translated */ +#define INTERNAL_ERROR "os_maild (1760): ERROR: Memory/configuration error" +#define BANNER_ERROR "os_sendmail(1762): WARN: Banner not received from server" +#define HELO_ERROR "os_sendmail(1763): WARN: Hello not accepted by server" +#define FROM_ERROR "os_sendmail(1764): WARN: Mail from not accepted by server" +#define TO_ERROR "os_sendmail(1765): WARN: RCPT TO not accepted by server - '%s'." +#define DATA_ERROR "os_sendmail(1766): WARN: DATA not accepted by server" +#define END_DATA_ERROR "os_sendmail(1767): WARN: End of DATA not accepted by server" + + +#define MAIL_DEBUG_FLAG 0 +#define MAIL_DEBUG(x,y,z) if(MAIL_DEBUG_FLAG) merror(x,y,z) + + + +/* OS_SendCustomEmail + */ +int OS_SendCustomEmail(char **to, char *subject, char *smtpserver, char *from, FILE *fp, struct tm *p) +{ + int socket,i = 0; + char *msg; + + char snd_msg[128]; + char buffer[2049]; + + buffer[2048] = '\0'; + + + /* Connecting to the smtp server */ + socket = OS_ConnectTCP(SMTP_DEFAULT_PORT, smtpserver); + if(socket < 0) + { + return(socket); + } + + + /* Receiving the banner */ + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDBANNER, msg))) + { + merror(BANNER_ERROR); + if(msg) + free(msg); + close(socket); + return(OS_INVALID); + } + MAIL_DEBUG("DEBUG: Received banner: '%s' %s", msg, ""); + free(msg); + + + + /* Sending HELO message */ + OS_SendTCP(socket,HELOMSG); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDMAIL, msg))) + { + if(msg) + { + /* Ugly fix warning :) */ + /* In some cases (with virus scans in the middle) + * we may get two banners. Check for that in here. + */ + if(OS_Match(VALIDBANNER, msg)) + { + free(msg); + + /* Try again */ + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDMAIL, msg))) + { + merror("%s:%s",HELO_ERROR,msg!= NULL?msg:"null"); + if(msg) + free(msg); + close(socket); + return(OS_INVALID); + } + } + else + { + merror("%s:%s",HELO_ERROR,msg); + free(msg); + close(socket); + return(OS_INVALID); + } + } + else + { + merror("%s:%s",HELO_ERROR,"null"); + close(socket); + return(OS_INVALID); + } + } + + MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", HELOMSG, msg); + free(msg); + + + /* Building "Mail from" msg */ + memset(snd_msg,'\0',128); + snprintf(snd_msg,127, MAILFROM, from); + OS_SendTCP(socket, snd_msg); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDMAIL, msg))) + { + merror(FROM_ERROR); + if(msg) + free(msg); + close(socket); + return(OS_INVALID); + } + MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg); + free(msg); + + + /* Building "RCPT TO" msg */ + while(to[i]) + { + memset(snd_msg,'\0',128); + snprintf(snd_msg,127,RCPTTO, to[i]); + OS_SendTCP(socket,snd_msg); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDMAIL, msg))) + { + merror(TO_ERROR, to[i]); + if(msg) + free(msg); + close(socket); + return(OS_INVALID); + } + MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", snd_msg, msg); + free(msg); + + i++; + } + + + /* Sending the "DATA" msg */ + OS_SendTCP(socket,DATAMSG); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + if((msg == NULL)||(!OS_Match(VALIDDATA, msg))) + { + merror(DATA_ERROR); + if(msg) + free(msg); + close(socket); + return(OS_INVALID); + } + MAIL_DEBUG("DEBUG: Sent '%s', received: '%s'", DATAMSG, msg); + free(msg); + + + /* Building "From" and "To" in the e-mail header */ + memset(snd_msg,'\0',128); + snprintf(snd_msg,127, TO, to[0]); + OS_SendTCP(socket, snd_msg); + + memset(snd_msg,'\0',128); + snprintf(snd_msg,127, FROM, from); + OS_SendTCP(socket, snd_msg); + + + /* Adding CCs */ + if(to[1]) + { + i = 1; + while(1) + { + if(to[i] == NULL) + { + break; + } + + memset(snd_msg,'\0',128); + snprintf(snd_msg,127, TO, to[i]); + OS_SendTCP(socket,snd_msg); + + i++; + } + } + + + /* Sending date */ + memset(snd_msg,'\0',128); + + + /* Solaris doesn't have the "%z", so we set the timezone to 0. */ + #ifdef SOLARIS + strftime(snd_msg, 127, "Date: %a, %d %b %Y %T -0000\r\n",p); + #else + strftime(snd_msg, 127, "Date: %a, %d %b %Y %T %z\r\n",p); + #endif + + OS_SendTCP(socket,snd_msg); + + + /* Sending subject */ + memset(snd_msg, '\0', 128); + snprintf(snd_msg, 127, SUBJECT, subject); + + OS_SendTCP(socket, snd_msg); + + + + /* Sending body */ + fseek(fp, 0, SEEK_SET); + while(fgets(buffer, 2048, fp) != NULL) + { + OS_SendTCP(socket,buffer); + } + + + /* Sending end of data \r\n.\r\n */ + OS_SendTCP(socket,ENDDATA); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + + + /* Checking msg in here, since it may be null */ + if(msg) + free(msg); + + + /* quitting and closing socket */ + OS_SendTCP(socket,QUITMSG); + msg = OS_RecvTCP(socket, OS_SIZE_1024); + + if(msg) + free(msg); + + memset(snd_msg,'\0',128); + + + /* Returning 0 (success) */ + close(socket); + + return(0); +} + + + +/* EOF */ diff --git a/src/os_maild/sendmail.c b/src/os_maild/sendmail.c index 39c5d8b..92157a7 100755 --- a/src/os_maild/sendmail.c +++ b/src/os_maild/sendmail.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sendmail.c,v 1.30 2009/06/24 17:06:31 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_net/COPYRIGHT b/src/os_net/COPYRIGHT index 8e92190..bfe1e9d 100755 --- a/src/os_net/COPYRIGHT +++ b/src/os_net/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All rights reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation OSSEC, os_net library. diff --git a/src/os_net/os_err.h b/src/os_net/os_err.h index 36964e1..85a2798 100755 --- a/src/os_net/os_err.h +++ b/src/os_net/os_err.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_err.h,v 1.7 2009/06/24 17:06:31 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_net/os_net.c b/src/os_net/os_net.c index 7ec960f..1921609 100755 --- a/src/os_net/os_net.c +++ b/src/os_net/os_net.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_net.c,v 1.34 2009/06/24 17:06:31 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/os_net/os_net.h b/src/os_net/os_net.h index 68da2eb..88c2b80 100755 --- a/src/os_net/os_net.h +++ b/src/os_net/os_net.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_net.h,v 1.12 2009/06/24 17:06:31 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/COPYRIGHT b/src/os_regex/COPYRIGHT index 4394e65..e8ce40a 100755 --- a/src/os_regex/COPYRIGHT +++ b/src/os_regex/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All right reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation OSSEC, os_regex library. diff --git a/src/os_regex/os_match.c b/src/os_regex/os_match.c index 4de0e75..cd40136 100755 --- a/src/os_regex/os_match.c +++ b/src/os_regex/os_match.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_match_compile.c b/src/os_regex/os_match_compile.c index 8521b3f..366e79e 100755 --- a/src/os_regex/os_match_compile.c +++ b/src/os_regex/os_match_compile.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -24,6 +24,7 @@ int _os_strncmp(char *pattern, char *str, int str_len, int size); int _os_strcmp_last(char *pattern, char *str, int str_len, int size); int _os_strcmp(char *pattern, char *str, int str_len, int size); int _os_strmatch(char *pattern, char *str, int str_len, int size); +int _os_strstr(char *pattern, char *str, int str_len, int size); /** int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) v0.1 @@ -35,6 +36,7 @@ int _os_strmatch(char *pattern, char *str, int str_len, int size); */ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) { + int usstrstr = 0; int i = 0; int count = 0; int end_of_string = 0; @@ -83,6 +85,7 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) new_str_free = new_str; pt = new_str; + /* Getting the number of sub patterns */ while(*pt != '\0') @@ -100,6 +103,10 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) { count++; } + else if(*pt == -29) + { + usstrstr = 1; + } pt++; } @@ -179,13 +186,20 @@ int OSMatch_Compile(char *pattern, OSMatch *reg, int flags) reg->size[i] = strlen(reg->patterns[i]) -1; reg->patterns[i][reg->size[i]] = '\0'; } - + /* If string starts with ^, use strncmp */ else if(*new_str == BEGINREGEX) { reg->match_fp[i] = _os_strncmp; reg->size[i] = strlen(reg->patterns[i]); } + + else if(usstrstr == 1) + { + reg->match_fp[i] = _os_strstr; + reg->size[i] = strlen(reg->patterns[i]); + } + else { reg->match_fp[i] = _OS_Match; diff --git a/src/os_regex/os_match_execute.c b/src/os_regex/os_match_execute.c index 70f3184..d61f0cb 100755 --- a/src/os_regex/os_match_execute.c +++ b/src/os_regex/os_match_execute.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -80,6 +80,15 @@ int _os_strmatch(char *pattern, char *str, int str_len, int size) return(TRUE); } +int _os_strstr(char *pattern, char *str, int str_len, int size) +{ + if(strstr(str, pattern) != NULL) + { + return(TRUE); + } + return(FALSE); +} + /** Internal matching **/ int _os_strcmp_last(char *pattern, char *str, int str_len, int size) diff --git a/src/os_regex/os_match_free_pattern.c b/src/os_regex/os_match_free_pattern.c index 095f8c9..7131f08 100755 --- a/src/os_regex/os_match_free_pattern.c +++ b/src/os_regex/os_match_free_pattern.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex.c b/src/os_regex/os_regex.c index 2e89fab..c429271 100755 --- a/src/os_regex/os_regex.c +++ b/src/os_regex/os_regex.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex.h b/src/os_regex/os_regex.h index 71e17af..24a600f 100755 --- a/src/os_regex/os_regex.h +++ b/src/os_regex/os_regex.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_compile.c b/src/os_regex/os_regex_compile.c index c5f1ea5..12b04cd 100755 --- a/src/os_regex/os_regex_compile.c +++ b/src/os_regex/os_regex_compile.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_execute.c b/src/os_regex/os_regex_execute.c index 0839493..03277a9 100755 --- a/src/os_regex/os_regex_execute.c +++ b/src/os_regex/os_regex_execute.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_free_pattern.c b/src/os_regex/os_regex_free_pattern.c index 2cfa00e..305dde3 100755 --- a/src/os_regex/os_regex_free_pattern.c +++ b/src/os_regex/os_regex_free_pattern.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_free_substrings.c b/src/os_regex/os_regex_free_substrings.c index e2cfcd2..b96a58b 100755 --- a/src/os_regex/os_regex_free_substrings.c +++ b/src/os_regex/os_regex_free_substrings.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_internal.h b/src/os_regex/os_regex_internal.h index 0186950..dde3ac3 100755 --- a/src/os_regex/os_regex_internal.h +++ b/src/os_regex/os_regex_internal.h @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. */ diff --git a/src/os_regex/os_regex_maps.h b/src/os_regex/os_regex_maps.h index 117332d..9396637 100644 --- a/src/os_regex/os_regex_maps.h +++ b/src/os_regex/os_regex_maps.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_regex_maps.h,v 1.6 2009/06/24 17:06:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. */ diff --git a/src/os_regex/os_regex_match.c b/src/os_regex/os_regex_match.c index 8094133..8932cff 100755 --- a/src/os_regex/os_regex_match.c +++ b/src/os_regex/os_regex_match.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_str.c b/src/os_regex/os_regex_str.c index 13b46ca..4b5ddbc 100755 --- a/src/os_regex/os_regex_str.c +++ b/src/os_regex/os_regex_str.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_regex/os_regex_strbreak.c b/src/os_regex/os_regex_strbreak.c index e8a4228..2294c2c 100755 --- a/src/os_regex/os_regex_strbreak.c +++ b/src/os_regex/os_regex_strbreak.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/COPYRIGHT b/src/os_xml/COPYRIGHT index 764fbc6..2a1ca20 100755 --- a/src/os_xml/COPYRIGHT +++ b/src/os_xml/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All rights reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation OSSEC, os_xml library. diff --git a/src/os_xml/os_xml.c b/src/os_xml/os_xml.c index befa457..c370d58 100755 --- a/src/os_xml/os_xml.c +++ b/src/os_xml/os_xml.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/os_xml.h b/src/os_xml/os_xml.h index cb2d466..f0099b0 100755 --- a/src/os_xml/os_xml.h +++ b/src/os_xml/os_xml.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_xml.h,v 1.8 2009/06/24 17:06:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/os_xml_access.c b/src/os_xml/os_xml_access.c index be5741f..61ed5cd 100755 --- a/src/os_xml/os_xml_access.c +++ b/src/os_xml/os_xml_access.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/os_xml_node_access.c b/src/os_xml/os_xml_node_access.c index 7d986ca..dc71798 100755 --- a/src/os_xml/os_xml_node_access.c +++ b/src/os_xml/os_xml_node_access.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_xml_node_access.c,v 1.6 2009/06/24 17:06:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -32,9 +32,13 @@ void OS_ClearNode(xml_node **node) while(node[i]) { if(node[i]->element) + { free(node[i]->element); + } if(node[i]->content) + { free(node[i]->content); + } if(node[i]->attributes) { int j=0; diff --git a/src/os_xml/os_xml_variables.c b/src/os_xml/os_xml_variables.c index e474cda..b5a7e09 100755 --- a/src/os_xml/os_xml_variables.c +++ b/src/os_xml/os_xml_variables.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/os_xml_writer.c b/src/os_xml/os_xml_writer.c index 939ca24..45d3f25 100755 --- a/src/os_xml/os_xml_writer.c +++ b/src/os_xml/os_xml_writer.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_xml_writer.c,v 1.5 2009/06/24 17:06:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_xml/os_xml_writer.h b/src/os_xml/os_xml_writer.h index 5e3e938..bd4b81a 100755 --- a/src/os_xml/os_xml_writer.h +++ b/src/os_xml/os_xml_writer.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_xml_writer.h,v 1.4 2009/06/24 17:06:32 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_zlib/os_zlib.c b/src/os_zlib/os_zlib.c index 9ad9516..21b1784 100755 --- a/src/os_zlib/os_zlib.c +++ b/src/os_zlib/os_zlib.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_zlib.c,v 1.7 2009/06/24 18:53:06 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_zlib/os_zlib.h b/src/os_zlib/os_zlib.h index 1f84568..a24205e 100755 --- a/src/os_zlib/os_zlib.h +++ b/src/os_zlib/os_zlib.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_zlib.h,v 1.5 2009/06/24 18:53:06 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/os_zlib/zlib-test.c b/src/os_zlib/zlib-test.c index 6957eed..587d56b 100755 --- a/src/os_zlib/zlib-test.c +++ b/src/os_zlib/zlib-test.c @@ -1,11 +1,11 @@ -/* @(#) $Id: zlib-test.c,v 1.5 2009/06/24 18:53:06 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/COPYRIGHT b/src/remoted/COPYRIGHT index ea4845c..3b5657a 100755 --- a/src/remoted/COPYRIGHT +++ b/src/remoted/COPYRIGHT @@ -2,7 +2,7 @@ Copyright (C) 2009 Trend Micro Inc. All rights reserved. This program is a free software; you can redistribute it and/or modify it under the terms of the GNU General Public - License (version 3) as published by the FSF - Free Software + License (version 2) as published by the FSF - Free Software Foundation. License details at the LICENSE file included with OSSEC or diff --git a/src/remoted/ar-forward.c b/src/remoted/ar-forward.c index c2035f3..1e6bc1c 100755 --- a/src/remoted/ar-forward.c +++ b/src/remoted/ar-forward.c @@ -1,11 +1,11 @@ -/* @(#) $Id: ar-forward.c,v 1.27 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/config.c b/src/remoted/config.c index 5b96b7d..59c2717 100755 --- a/src/remoted/config.c +++ b/src/remoted/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.12 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/main.c b/src/remoted/main.c index 14708ba..2f83a8d 100755 --- a/src/remoted/main.c +++ b/src/remoted/main.c @@ -1,11 +1,11 @@ -/* @(#) $Id: main.c,v 1.23 2009/11/18 19:07:41 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/manager.c b/src/remoted/manager.c index 38c92cd..d5f9e2d 100755 --- a/src/remoted/manager.c +++ b/src/remoted/manager.c @@ -1,11 +1,11 @@ -/* @(#) $Id: manager.c,v 1.47 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/remoted.c b/src/remoted/remoted.c index 559b8b4..4930aba 100755 --- a/src/remoted/remoted.c +++ b/src/remoted/remoted.c @@ -1,11 +1,11 @@ -/* @(#) $Id: remoted.c,v 1.34 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/remoted/remoted.h b/src/remoted/remoted.h index 2ebc56b..5666d0c 100755 --- a/src/remoted/remoted.h +++ b/src/remoted/remoted.h @@ -1,11 +1,11 @@ -/* @(#) $Id: remoted.h,v 1.18 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/secure.c b/src/remoted/secure.c index f9e9ec7..9f40f12 100755 --- a/src/remoted/secure.c +++ b/src/remoted/secure.c @@ -1,11 +1,11 @@ -/* @(#) $Id: secure.c,v 1.29 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/sendmsg.c b/src/remoted/sendmsg.c index 16a50b2..12556db 100755 --- a/src/remoted/sendmsg.c +++ b/src/remoted/sendmsg.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sendmsg.c,v 1.4 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/syslog.c b/src/remoted/syslog.c index bbd0522..fd08c35 100755 --- a/src/remoted/syslog.c +++ b/src/remoted/syslog.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syslog.c,v 1.17 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/remoted/syslogtcp.c b/src/remoted/syslogtcp.c index c0efcd5..46b2ead 100755 --- a/src/remoted/syslogtcp.c +++ b/src/remoted/syslogtcp.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syslogtcp.c,v 1.8 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_open_ports.c b/src/rootcheck/check_open_ports.c index bbe2fc5..37ead35 100755 --- a/src/rootcheck/check_open_ports.c +++ b/src/rootcheck/check_open_ports.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_open_ports.c,v 1.8 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_dev.c b/src/rootcheck/check_rc_dev.c index 5fb8503..09f6cf6 100755 --- a/src/rootcheck/check_rc_dev.c +++ b/src/rootcheck/check_rc_dev.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_dev.c,v 1.24 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_files.c b/src/rootcheck/check_rc_files.c index a83f89c..5d60a82 100755 --- a/src/rootcheck/check_rc_files.c +++ b/src/rootcheck/check_rc_files.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_files.c,v 1.12 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_if.c b/src/rootcheck/check_rc_if.c index 3415861..096aa4e 100755 --- a/src/rootcheck/check_rc_if.c +++ b/src/rootcheck/check_rc_if.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_if.c,v 1.10 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_pids.c b/src/rootcheck/check_rc_pids.c index 982cc6c..a2868e3 100755 --- a/src/rootcheck/check_rc_pids.c +++ b/src/rootcheck/check_rc_pids.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_pids.c,v 1.29 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_policy.c b/src/rootcheck/check_rc_policy.c index c7b96e5..f10708e 100755 --- a/src/rootcheck/check_rc_policy.c +++ b/src/rootcheck/check_rc_policy.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_policy.c,v 1.3 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_ports.c b/src/rootcheck/check_rc_ports.c index 57cc3d5..890407c 100755 --- a/src/rootcheck/check_rc_ports.c +++ b/src/rootcheck/check_rc_ports.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_ports.c,v 1.21 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_readproc.c b/src/rootcheck/check_rc_readproc.c index d086b38..d136d6e 100755 --- a/src/rootcheck/check_rc_readproc.c +++ b/src/rootcheck/check_rc_readproc.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_readproc.c,v 1.8 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_sys.c b/src/rootcheck/check_rc_sys.c index 68e56fb..b7b34ef 100755 --- a/src/rootcheck/check_rc_sys.c +++ b/src/rootcheck/check_rc_sys.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_sys.c,v 1.42 2009/09/29 19:52:25 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/check_rc_trojans.c b/src/rootcheck/check_rc_trojans.c index e30cd80..40b16ed 100755 --- a/src/rootcheck/check_rc_trojans.c +++ b/src/rootcheck/check_rc_trojans.c @@ -1,11 +1,11 @@ -/* @(#) $Id: check_rc_trojans.c,v 1.12 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/common.c b/src/rootcheck/common.c index 67ae180..f5d6589 100755 --- a/src/rootcheck/common.c +++ b/src/rootcheck/common.c @@ -1,11 +1,11 @@ -/* @(#) $Id: common.c,v 1.25 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or @@ -119,6 +119,8 @@ int rk_check_dir(char *dir, char *file, char *pattern) int rk_check_file(char *file, char *pattern) { char *split_file; + int full_negate = 0; + int pt_result = 0; FILE *fp; char buf[OS_SIZE_2048 +1]; @@ -175,11 +177,14 @@ int rk_check_file(char *file, char *pattern) else { + full_negate = pt_check_negate(pattern); /* Checking for a content in the file */ + debug1("checking file: %s", file); fp = fopen(file, "r"); if(fp) { + debug1(" starting new file: %s", file); buf[OS_SIZE_2048] = '\0'; while(fgets(buf, OS_SIZE_2048, fp) != NULL) { @@ -204,8 +209,13 @@ int rk_check_file(char *file, char *pattern) /* Matched */ - if(pt_matches(buf, pattern)) + pt_result = pt_matches(buf, pattern); + debug1("Buf == \"%s\"", buf); + debug1("Pattern == \"%s\"", pattern); + debug1("pt_result == %d and full_negate == %d", pt_result, full_negate); + if((pt_result == 1 && full_negate == 0) ) { + debug1("alerting file %s on line %s", file, buf); int i = 0; char _b_msg[OS_SIZE_1024 +1]; @@ -232,9 +242,45 @@ int rk_check_file(char *file, char *pattern) return(1); } + else if((pt_result == 0 && full_negate == 1) ) + { + /* found a full+negate match so no longer need to search + * break out of loop and amke sure the full negate does + * not alertin + */ + debug1("found a complete match for full_negate"); + full_negate = 0; + break; + } } fclose(fp); + + if(full_negate == 1) + { + debug1("full_negate alerting - file %s",file); + int i = 0; + char _b_msg[OS_SIZE_1024 +1]; + + /* Generating the alert itself. */ + _b_msg[OS_SIZE_1024] = '\0'; + snprintf(_b_msg, OS_SIZE_1024, " File: %s.", + file); + + /* Already present. */ + if(_is_str_in_array(rootcheck.alert_msg, _b_msg)) + { + return(1); + } + + while(rootcheck.alert_msg[i] && (i < 255)) + i++; + + if(!rootcheck.alert_msg[i]) + os_strdup(_b_msg, rootcheck.alert_msg[i]); + + return(1); + } } } @@ -256,6 +302,49 @@ int rk_check_file(char *file, char *pattern) } +/** int pt_check_negate(char *pattern) + * Checks if the patterns is all negate values and if so returns 1 + * else return 0 + */ +int pt_check_negate(char *pattern) +{ + char *mypattern = NULL; + os_strdup(pattern, mypattern); + char *tmp_pt = mypattern; + char *tmp_pattern = mypattern; + char *tmp_ret = NULL; + + + while(tmp_pt != NULL) + { + /* We first look for " && " */ + tmp_pt = strchr(tmp_pattern, ' '); + if(tmp_pt && tmp_pt[1] == '&' && tmp_pt[2] == '&' && tmp_pt[3] == ' ') + { + /* Marking pointer to clean it up */ + tmp_ret = tmp_pt; + + *tmp_pt = '\0'; + tmp_pt += 4; + } + else + { + tmp_pt = NULL; + } + + if(*tmp_pattern != '!') + { + free(mypattern); + return 0; + } + + tmp_pattern = tmp_pt; + } + + debug1("pattern: %s is fill_negate",pattern); + free(mypattern); + return(1); +} /** int pt_matches(char *str, char *pattern) * Checks if the specific pattern is present on str. @@ -324,6 +413,7 @@ int pt_matches(char *str, char *pattern) pattern += 2; if(OS_Regex(pattern, str)) { + debug1("pattern: %s matches %s.",pattern, str); ret_code = 1; } } diff --git a/src/rootcheck/common_rcl.c b/src/rootcheck/common_rcl.c index ede727a..ec72472 100755 --- a/src/rootcheck/common_rcl.c +++ b/src/rootcheck/common_rcl.c @@ -1,11 +1,11 @@ -/* @(#) $Id: common_rcl.c,v 1.17 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/rootcheck/config.c b/src/rootcheck/config.c index cf085dc..b04d492 100755 --- a/src/rootcheck/config.c +++ b/src/rootcheck/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.18 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/db/cis_debian_linux_rcl.txt b/src/rootcheck/db/cis_debian_linux_rcl.txt index 6d6d524..9c87619 100644 --- a/src/rootcheck/db/cis_debian_linux_rcl.txt +++ b/src/rootcheck/db/cis_debian_linux_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: cis_debian_linux_rcl.txt,v 1.2 2008/07/10 18:03:00 dcid Exp $ +# @(#) $Id$ # # OSSEC Linux Audit - (C) 2008 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/db/cis_rhel5_linux_rcl.txt b/src/rootcheck/db/cis_rhel5_linux_rcl.txt index a252d98..75c6b3e 100644 --- a/src/rootcheck/db/cis_rhel5_linux_rcl.txt +++ b/src/rootcheck/db/cis_rhel5_linux_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: cis_rhel5_linux_rcl.txt,v 1.5 2009/02/20 15:33:25 dcid Exp $ +# @(#) $Id$ # # OSSEC Linux Audit - (C) 2008 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/db/cis_rhel_linux_rcl.txt b/src/rootcheck/db/cis_rhel_linux_rcl.txt index a4cb1f5..976ee6f 100644 --- a/src/rootcheck/db/cis_rhel_linux_rcl.txt +++ b/src/rootcheck/db/cis_rhel_linux_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: cis_rhel_linux_rcl.txt,v 1.5 2008/08/28 12:07:35 dcid Exp $ +# @(#) $Id$ # # OSSEC Linux Audit - (C) 2008 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/db/rootkit_files.txt b/src/rootcheck/db/rootkit_files.txt index 624c4fe..efdbd21 100755 --- a/src/rootcheck/db/rootkit_files.txt +++ b/src/rootcheck/db/rootkit_files.txt @@ -1,4 +1,4 @@ -# @(#) $Id: rootkit_files.txt,v 1.21 2009/01/29 16:53:37 dcid Exp $ +# @(#) $Id$ # # rootkit_files.txt, (C) Daniel B. Cid # Imported from the rootcheck project. @@ -353,7 +353,6 @@ etc/.bmbl/sk ! BMBL rootkit # Cback Linux worm tmp/cback ! cback worm ::/rootkits/cback.php tmp/derfiq ! cback worm ::/rootkits/cback.php -*/cback ! cback worm ::/rootkits/cback.php # aPa Kit (from rkhunter) diff --git a/src/rootcheck/db/rootkit_trojans.txt b/src/rootcheck/db/rootkit_trojans.txt index d133e16..b2cfa86 100755 --- a/src/rootcheck/db/rootkit_trojans.txt +++ b/src/rootcheck/db/rootkit_trojans.txt @@ -1,4 +1,4 @@ -# @(#) $Id: rootkit_trojans.txt,v 1.20 2009/06/03 19:18:32 dcid Exp $ +# @(#) $Id$ # # rootkit_trojans.txt, (C) Daniel B. Cid # Imported from the rootcheck project. @@ -22,16 +22,16 @@ bash !proc\.h|/dev/[0-9]|/dev/[hijkz]! sh !proc\.h|/dev/[0-9]|/dev/[hijkz]! uname !bash|^/bin/sh|file\.h|proc\.h|^/bin/.*sh! date !bash|^/bin/sh|file\.h|proc\.h|/dev/[^cln]|^/bin/.*sh! -du !/dev|w0rm|/prof|file\.h! +du !w0rm|/prof|file\.h! df !bash|^/bin/sh|file\.h|proc\.h|/dev/[^clurdv]|^/bin/.*sh! -login !bash|elite|SucKIT|xlogin|vejeta|porcao|lets_log|sukasuk! +login !elite|SucKIT|xlogin|vejeta|porcao|lets_log|sukasuk! passwd !bash|file\.h|proc\.h|/dev/ttyo|/dev/[A-Z]|/dev/[b-s,uvxz]! mingetty !bash|Dimensioni|pacchetto! chfn !bash|file\.h|proc\.h|/dev/ttyo|/dev/[A-Z]|/dev/[a-s,uvxz]! chsh !bash|file\.h|proc\.h|/dev/ttyo|/dev/[A-Z]|/dev/[a-s,uvxz]! mail !bash|file\.h|proc\.h|/dev/[^nu]! -su !bash|/dev/[d-s,abuvxz]|/dev/[A-D]|/dev/[F-Z]|/dev/[0-9]|satori|vejeta|conf\.inv! -sudo !bash|satori|vejeta|conf\.inv! +su !/dev/[d-s,abuvxz]|/dev/[A-D]|/dev/[F-Z]|/dev/[0-9]|satori|vejeta|conf\.inv! +sudo !satori|vejeta|conf\.inv! crond !/dev/[^nt]|bash! gpm !bash|mingetty! ifconfig !bash|^/bin/sh|/dev/tux|session.null|/dev/[^cludisopt]! diff --git a/src/rootcheck/db/system_audit_rcl.txt b/src/rootcheck/db/system_audit_rcl.txt index 82efb69..a0c6810 100644 --- a/src/rootcheck/db/system_audit_rcl.txt +++ b/src/rootcheck/db/system_audit_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: system_audit_rcl.txt,v 1.3 2008/04/14 18:30:07 dcid Exp $ +# @(#) $Id$ # # OSSEC Linux Audit - (C) 2007 Daniel B. Cid - dcid@ossec.net # @@ -26,8 +26,7 @@ # Multiple patterns can be specified by using " && " between them. # (All of them must match for it to return true). - -$php.ini=/var/www/conf/php.ini,/etc/php5/apache2/php.ini; +$php.ini=/etc/php.ini,/var/www/conf/php.ini,/etc/php5/apache2/php.ini; $web_dirs=/var/www,/var/htdocs,/home/httpd,/usr/local/apache,/usr/local/apache2,/usr/local/www; diff --git a/src/rootcheck/db/win_applications_rcl.txt b/src/rootcheck/db/win_applications_rcl.txt index 5b06d69..f4892b7 100644 --- a/src/rootcheck/db/win_applications_rcl.txt +++ b/src/rootcheck/db/win_applications_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: win_applications_rcl.txt,v 1.3 2007/08/18 01:07:50 dcid Exp $ +# @(#) $Id$ # # OSSEC Application detection - (C) 2007 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/db/win_audit_rcl.txt b/src/rootcheck/db/win_audit_rcl.txt index 17b0b86..d9a165f 100644 --- a/src/rootcheck/db/win_audit_rcl.txt +++ b/src/rootcheck/db/win_audit_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: win_audit_rcl.txt,v 1.2 2009/03/26 15:01:32 dcid Exp $ +# @(#) $Id$ # # OSSEC Windows Audit - (C) 2007 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/db/win_malware_rcl.txt b/src/rootcheck/db/win_malware_rcl.txt index 8a6cb13..7b8a768 100644 --- a/src/rootcheck/db/win_malware_rcl.txt +++ b/src/rootcheck/db/win_malware_rcl.txt @@ -1,4 +1,4 @@ -# @(#) $Id: win_malware_rcl.txt,v 1.5 2008/07/21 18:33:20 dcid Exp $ +# @(#) $Id$ # # OSSEC Windows Malware list - (C) 2007 Daniel B. Cid - dcid@ossec.net # diff --git a/src/rootcheck/os_string.c b/src/rootcheck/os_string.c index 64cf643..a3ad59a 100755 --- a/src/rootcheck/os_string.c +++ b/src/rootcheck/os_string.c @@ -1,4 +1,4 @@ -/* @(#) $Id: os_string.c,v 1.12 2007/04/18 02:04:58 dcid Exp $ */ +/* @(#) $Id$ */ /* Included and modified strings.c from the OpenBSD project. * Copyright bellow. diff --git a/src/rootcheck/rootcheck-config.c b/src/rootcheck/rootcheck-config.c index 9b7bc5f..5553471 100755 --- a/src/rootcheck/rootcheck-config.c +++ b/src/rootcheck/rootcheck-config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rootcheck-config.c,v 1.11 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/rootcheck.c b/src/rootcheck/rootcheck.c index 38b52f2..83dfb5b 100755 --- a/src/rootcheck/rootcheck.c +++ b/src/rootcheck/rootcheck.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rootcheck.c,v 1.33 2009/07/23 19:31:35 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/rootcheck.h b/src/rootcheck/rootcheck.h index 5aa42fa..3d9af73 100755 --- a/src/rootcheck/rootcheck.h +++ b/src/rootcheck/rootcheck.h @@ -1,11 +1,11 @@ -/* @(#) $Id: rootcheck.h,v 1.34 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -55,6 +55,9 @@ int rk_check_dir(char *dir, char *file, char *pattern); /* pt_matches: Checks if pattern is present on string */ int pt_matches(char *str, char *pattern); +/* pt_check_negate: checks if the patterns is made up + * completely of negate matches */ +int pt_check_negate(char *pattern); /* common is_file: Check if a file exist (using stat, fopen and opendir) */ int is_file(char *file_name); diff --git a/src/rootcheck/run_rk_check.c b/src/rootcheck/run_rk_check.c index 8ce7b7a..b209b95 100755 --- a/src/rootcheck/run_rk_check.c +++ b/src/rootcheck/run_rk_check.c @@ -1,11 +1,11 @@ -/* @(#) $Id: run_rk_check.c,v 1.41 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/unix-process.c b/src/rootcheck/unix-process.c index 43a3e71..072964e 100755 --- a/src/rootcheck/unix-process.c +++ b/src/rootcheck/unix-process.c @@ -1,11 +1,11 @@ -/* @(#) $Id: unix-process.c,v 1.5 2009/06/24 18:53:07 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/rootcheck/util/ads_dump.c b/src/rootcheck/util/ads_dump.c index 43ecd58..f27d4cd 100644 --- a/src/rootcheck/util/ads_dump.c +++ b/src/rootcheck/util/ads_dump.c @@ -1,11 +1,11 @@ -/* @(#) $Id: ads_dump.c,v 1.4 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/win-common.c b/src/rootcheck/win-common.c index 1d6b602..3e9e26d 100644 --- a/src/rootcheck/win-common.c +++ b/src/rootcheck/win-common.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win-common.c,v 1.15 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/rootcheck/win-process.c b/src/rootcheck/win-process.c index f71f9bd..1d9075d 100644 --- a/src/rootcheck/win-process.c +++ b/src/rootcheck/win-process.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win-process.c,v 1.5 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/agent_op.c b/src/shared/agent_op.c index beeb361..2ff49b7 100755 --- a/src/shared/agent_op.c +++ b/src/shared/agent_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: agent_op.c,v 1.8 2009/12/01 20:27:01 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -74,7 +74,6 @@ int os_set_restart_syscheck() */ char* os_read_agent_name() { - int i = 0; char buf[1024 + 1]; FILE *fp = NULL; diff --git a/src/shared/debug_op.c b/src/shared/debug_op.c index 9c2ac06..1c8343a 100755 --- a/src/shared/debug_op.c +++ b/src/shared/debug_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: debug_op.c,v 1.15 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/dirtree_op.c b/src/shared/dirtree_op.c index 5d469b5..10199ad 100755 --- a/src/shared/dirtree_op.c +++ b/src/shared/dirtree_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: dirtree_op.c,v 1.4 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/shared/file-queue.c b/src/shared/file-queue.c index 4245817..17ef8c9 100755 --- a/src/shared/file-queue.c +++ b/src/shared/file-queue.c @@ -1,11 +1,11 @@ -/* @(#) $Id: file-queue.c,v 1.11 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/shared/file_op.c b/src/shared/file_op.c index be8754f..f97597a 100755 --- a/src/shared/file_op.c +++ b/src/shared/file_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: file_op.c,v 1.32 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/hash_op.c b/src/shared/hash_op.c index 1ef278d..322fb1c 100755 --- a/src/shared/hash_op.c +++ b/src/shared/hash_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: hash_op.c,v 1.5 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/shared/help.c b/src/shared/help.c index 6e141b8..96c2a7c 100755 --- a/src/shared/help.c +++ b/src/shared/help.c @@ -1,11 +1,11 @@ -/* @(#) $Id: help.c,v 1.10 2009/11/18 19:07:42 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/list_op.c b/src/shared/list_op.c index e98b712..19e5e46 100755 --- a/src/shared/list_op.c +++ b/src/shared/list_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: list_op.c,v 1.17 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/math_op.c b/src/shared/math_op.c index 3130013..21ef109 100755 --- a/src/shared/math_op.c +++ b/src/shared/math_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: math_op.c,v 1.3 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or diff --git a/src/shared/mem_op.c b/src/shared/mem_op.c index b58385d..d54bc02 100755 --- a/src/shared/mem_op.c +++ b/src/shared/mem_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: mem_op.c,v 1.7 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -13,6 +13,49 @@ #include "mem_op.h" +/* Add pointer to array. */ +void **os_AddPtArray(void *pt, void **array) +{ + int i = 0; + void **ret = NULL; + + if(array) + { + while(array[i]) + { + i++; + } + } + + os_realloc(array, (i + 2)*sizeof(char *), ret); + ret[i] = pt; + ret[i + 1] = NULL; + + return(ret); +} + + +/* Add a string to an array. */ +char **os_AddStrArray(char *str, char **array) +{ + int i = 0; + char **ret = NULL; + if(array) + { + while(array[i]) + { + i++; + } + } + + os_realloc(array, (i + 2)*sizeof(char *), ret); + os_strdup(str, ret[i]); + ret[i + 1] = NULL; + + return(ret); +} + + /* Check if String is on array (Must be NULL terminated) */ int os_IsStrOnArray(char *str, char **array) { @@ -72,50 +115,34 @@ char *os_LoadString(char *at, char *str) { if(at == NULL) { - int strsize = 0; - if((strsize = strlen(str)) < OS_SIZE_2048) + at = strdup(str); + if(!at) { - at = calloc(strsize+1,sizeof(char)); - if(at == NULL) - { - merror(MEM_ERROR,ARGV0); - return(NULL); - } - strncpy(at, str, strsize); - return(at); - } - else - { - merror(SIZE_ERROR,ARGV0,str); - return(NULL); + merror(MEM_ERROR,ARGV0); } + return(at); } else /*at is not null. Need to reallocat its memory and copy str to it*/ { + char *newat; int strsize = strlen(str); - int atsize = strlen(at); - int finalsize = atsize+strsize+1; - - if((atsize > OS_SIZE_2048) || (strsize > OS_SIZE_2048)) - { - merror(SIZE_ERROR,ARGV0,str); - return(NULL); - } - - at = realloc(at, (finalsize)*sizeof(char)); + int finalsize = strsize + strlen(at) + 1; - if(at == NULL) + newat = realloc(at, finalsize*sizeof(char)); + if(newat == NULL) { + free(at); merror(MEM_ERROR,ARGV0); return(NULL); } + at = newat; - strncat(at,str,strsize); - - at[finalsize-1] = '\0'; + strncat(at, str, strsize); + at[finalsize -1] = '\0'; return(at); } + return(NULL); } diff --git a/src/shared/mq_op.c b/src/shared/mq_op.c index c7f124b..81c2772 100755 --- a/src/shared/mq_op.c +++ b/src/shared/mq_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: mq_op.c,v 1.25 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/privsep_op.c b/src/shared/privsep_op.c index 58fe566..1e0ce18 100755 --- a/src/shared/privsep_op.c +++ b/src/shared/privsep_op.c @@ -5,7 +5,7 @@ * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/pthreads_op.c b/src/shared/pthreads_op.c index 0262110..f88dcc1 100755 --- a/src/shared/pthreads_op.c +++ b/src/shared/pthreads_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: pthreads_op.c,v 1.8 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/read-agents.c b/src/shared/read-agents.c index c3323a2..37e8bd4 100755 --- a/src/shared/read-agents.c +++ b/src/shared/read-agents.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read-agents.c,v 1.19 2009/08/19 18:35:57 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/read-alert.c b/src/shared/read-alert.c index ff18f85..b9553b6 100755 --- a/src/shared/read-alert.c +++ b/src/shared/read-alert.c @@ -1,11 +1,11 @@ -/* @(#) $Id: read-alert.c,v 1.10 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or @@ -266,7 +266,7 @@ alert_data *GetAlertData(int flag, FILE *fp) os_strdup(p, user); } /* It is a log message */ - else if(log_size < 10) + else if(log_size < 20) { os_clearnl(str,p); diff --git a/src/shared/regex_op.c b/src/shared/regex_op.c index cf4db77..7478c31 100755 --- a/src/shared/regex_op.c +++ b/src/shared/regex_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: regex_op.c,v 1.12 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/report_op.c b/src/shared/report_op.c index cc51737..06dc8b4 100755 --- a/src/shared/report_op.c +++ b/src/shared/report_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: report_op.c,v 1.2 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -14,6 +14,25 @@ /** Helper functions. */ +FILE *__g_rtype = NULL; +void l_print_out(const char *msg, ...) +{ + va_list args; + va_start(args, msg); + + if(__g_rtype) + { + (void)vfprintf(__g_rtype, msg, args); + (void)fprintf(__g_rtype, "\n"); + } + else + { + (void)vfprintf(stderr, msg, args); + (void)fprintf(stderr, "\n"); + } + va_end(args); +} + /* Sort function used by OSStore sort. * Returns if d1 > d2. @@ -32,6 +51,22 @@ void *_os_report_sort_compare(void *d1, void *d2) } +/* Print output header. */ +void _os_header_print(int t, char *hname) +{ + if(!t) + { + l_print_out("Top entries for '%s':", hname); + l_print_out("------------------------------------------------"); + } + else + { + l_print_out("Related entries for '%s':", hname); + l_print_out("------------------------------------------------"); + } +} + + /* Compares if the id is present in the string. */ int _os_report_str_int_compare(char *str, int id) { @@ -90,7 +125,7 @@ int _os_report_check_filters(alert_data *al_data, report_filter *r_filter) } if(r_filter->location) { - if(!OS_Match2(r_filter->location, al_data->location)) + if(!OS_Match(r_filter->location, al_data->location)) { return(0); } @@ -102,7 +137,20 @@ int _os_report_check_filters(alert_data *al_data, report_filter *r_filter) return(0); } } - + if(r_filter->srcip) + { + if(!strstr(al_data->srcip, r_filter->srcip)) + { + return(0); + } + } + if(r_filter->user) + { + if(!strstr(al_data->user, r_filter->user)) + { + return(0); + } + } return(1); } @@ -161,7 +209,7 @@ int _report_filter_value(char *filter_by, int prev_filter) } else { - merror("%s: ERROR: Invalid relation '%s'.", ARGV0, filter_by); + merror("%s: ERROR: Invalid relation '%s'.", __local_name, filter_by); return(-1); } } @@ -244,17 +292,17 @@ int _os_report_print_related(int print_related, OSList *st_data) if(!list_entry) { if(print_related & REPORT_REL_LOCATION) - print_out(" location: '%s'", saved_aldata->location); + l_print_out(" location: '%s'", saved_aldata->location); else if(print_related & REPORT_REL_GROUP) - print_out(" group: '%s'", saved_aldata->group); + l_print_out(" group: '%s'", saved_aldata->group); else if(print_related & REPORT_REL_RULE) - print_out(" rule: '%d'", saved_aldata->rule); + l_print_out(" rule: '%d'", saved_aldata->rule); else if(print_related & REPORT_REL_SRCIP) - print_out(" srcip: '%s'", saved_aldata->srcip); + l_print_out(" srcip: '%s'", saved_aldata->srcip); else if(print_related & REPORT_REL_USER) - print_out(" user: '%s'", saved_aldata->user); + l_print_out(" user: '%s'", saved_aldata->user); else if(print_related & REPORT_REL_LEVEL) - print_out(" level: '%d'", saved_aldata->level); + l_print_out(" level: '%d'", saved_aldata->level); } list_entry = OSList_GetNextNode(st_data); @@ -281,7 +329,7 @@ int _os_report_add_tostore(char *key, OSStore *top, void *data) top_list = OSList_Create(); if(!top_list) { - merror(MEM_ERROR, ARGV0); + merror(MEM_ERROR, __local_name); return(0); } OSList_AddData(top_list, data); @@ -296,21 +344,10 @@ int _os_report_add_tostore(char *key, OSStore *top, void *data) void os_report_printtop(void *topstore_pt, char *hname, int print_related) { + int dopdout = 0; OSStore *topstore = (OSStore *)topstore_pt; OSStoreNode *next_node; - if(!print_related) - { - print_out("Top entries for '%s':", hname); - print_out("------------------------------------------------"); - } - else - { - print_out("Related entries for '%s':", hname); - print_out("------------------------------------------------"); - } - - next_node = OSStore_GetFirstNode(topstore); while(next_node) { @@ -328,14 +365,24 @@ void os_report_printtop(void *topstore_pt, char *hname, int print_related) lkey[46] = '\0'; } - print_out("%-48s|%-8d|", (char *)next_node->key, st_data->currently_size); + if(!dopdout) + { + _os_header_print(print_related, hname); + dopdout = 1; + } + l_print_out("%-48s|%-8d|", (char *)next_node->key, st_data->currently_size); } /* Print each destination. */ else { - print_out("%-48s|%-8d|", (char *)next_node->key, st_data->currently_size); + if(!dopdout) + { + _os_header_print(print_related, hname); + dopdout = 1; + } + l_print_out("%-48s|%-8d|", (char *)next_node->key, st_data->currently_size); if(print_related & REPORT_REL_LOCATION) _os_report_print_related(REPORT_REL_LOCATION, st_data); @@ -356,8 +403,11 @@ void os_report_printtop(void *topstore_pt, char *hname, int print_related) } - print_out(" "); - print_out(" "); + if(dopdout == 1) + { + l_print_out(" "); + l_print_out(" "); + } return; } @@ -369,6 +419,7 @@ void os_ReportdStart(report_filter *r_filter) int alerts_filtered = 0; char *first_alert = NULL; char *last_alert = NULL; + void **data_to_clean = NULL; time_t tm; @@ -385,6 +436,29 @@ void os_ReportdStart(report_filter *r_filter) + + /* Initating file queue - to read the alerts */ + os_calloc(1, sizeof(file_queue), fileq); + + if(r_filter->report_type == REPORT_TYPE_DAILY && r_filter->filename) + { + fileq->fp = fopen(r_filter->filename, "r"); + if(!fileq->fp) + { + merror("%s: ERROR: Unable to open alerts file to generate report.", __local_name); + return; + } + if(r_filter->fp) + { + __g_rtype = r_filter->fp; + } + } + else + { + fileq->fp = stdin; + } + + /* Creating top hashes. */ r_filter->top_user = OSStore_Create(); r_filter->top_srcip = OSStore_Create(); @@ -392,12 +466,7 @@ void os_ReportdStart(report_filter *r_filter) r_filter->top_rule = OSStore_Create(); r_filter->top_group = OSStore_Create(); r_filter->top_location = OSStore_Create(); - - - /* Initating file queue - to read the alerts */ - os_calloc(1, sizeof(file_queue), fileq); - fileq->fp = stdin; Init_FileQueue(fileq, p, CRALERT_READ_ALL|CRALERT_FP_SET); @@ -408,7 +477,6 @@ void os_ReportdStart(report_filter *r_filter) al_data = Read_FileMon(fileq, p, 1); if(!al_data) { - verbose("%s: Report completed. Creating output...", ARGV0); break; } @@ -424,6 +492,7 @@ void os_ReportdStart(report_filter *r_filter) alerts_filtered++; + data_to_clean = os_AddPtArray(al_data, data_to_clean); /* Setting first and last alert for summary. */ @@ -499,21 +568,36 @@ void os_ReportdStart(report_filter *r_filter) al_data); } + /* No report available */ + if(alerts_filtered == 0) + { + if(!r_filter->report_name) + merror("%s: INFO: Report completed and zero alerts post-filter.", __local_name); + else + merror("%s: INFO: Report '%s' completed and zero alerts post-filter.", __local_name, r_filter->report_name); + return; + } + + + if(r_filter->report_name) + verbose("%s: INFO: Report '%s' completed. Creating output...", __local_name, r_filter->report_name); + else + verbose("%s: INFO: Report completed. Creating output...", __local_name); - print_out(" "); + l_print_out(" "); if(r_filter->report_name) - print_out("Report '%s' completed.", r_filter->report_name); + l_print_out("Report '%s' completed.", r_filter->report_name); else - print_out("Report completed. =="); - print_out("------------------------------------------------"); + l_print_out("Report completed. =="); + l_print_out("------------------------------------------------"); - print_out("->Processed alerts: %d", alerts_processed); - print_out("->Post-filtering alerts: %d", alerts_filtered); - print_out("->First alert: %s", first_alert); - print_out("->Last alert: %s", last_alert); - print_out(" "); - print_out(" "); + l_print_out("->Processed alerts: %d", alerts_processed); + l_print_out("->Post-filtering alerts: %d", alerts_filtered); + l_print_out("->First alert: %s", first_alert); + l_print_out("->Last alert: %s", last_alert); + l_print_out(" "); + l_print_out(" "); OSStore_Sort(r_filter->top_srcip, _os_report_sort_compare); OSStore_Sort(r_filter->top_user, _os_report_sort_compare); @@ -565,6 +649,29 @@ void os_ReportdStart(report_filter *r_filter) if(r_filter->related_rule) os_report_printtop(r_filter->top_rule, "Rule", r_filter->related_rule); + + + /* If we have to dump the alerts. */ + if(data_to_clean) + { + int i = 0; + + if(r_filter->show_alerts) + { + l_print_out("Log dump:"); + l_print_out("------------------------------------------------"); + } + while(data_to_clean[i]) + { + alert_data *md = data_to_clean[i]; + if(r_filter->show_alerts) + l_print_out("%s %s\nRule: %d (level %d) -> '%s'\n%s\n\n", md->date, md->location, md->rule, md->level, md->comment, md->log[0]); + FreeAlertData(md); + i++; + } + free(data_to_clean); + data_to_clean = NULL; + } } @@ -601,9 +708,17 @@ int os_report_configfilter(char *filter_by, char *filter_value, { r_filter->location = filter_value; } + else if(strcmp(filter_by, "user") == 0) + { + r_filter->user = filter_value; + } + else if(strcmp(filter_by, "srcip") == 0) + { + r_filter->srcip = filter_value; + } else { - merror("%s: ERROR: Invalid filter '%s'.", ARGV0, filter_by); + merror("%s: ERROR: Invalid filter '%s'.", __local_name, filter_by); return(-1); } } @@ -659,7 +774,7 @@ int os_report_configfilter(char *filter_by, char *filter_value, } else { - merror("%s: ERROR: Invalid related entry '%s'.", ARGV0, filter_by); + merror("%s: ERROR: Invalid related entry '%s'.", __local_name, filter_by); return(-1); } } diff --git a/src/shared/rules_op.c b/src/shared/rules_op.c index 203b3ba..58481ec 100755 --- a/src/shared/rules_op.c +++ b/src/shared/rules_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rules_op.c,v 1.6 2009/06/24 18:53:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -16,6 +16,12 @@ #include "rules_op.h" +/* Chaging path for test rule. */ +#ifdef TESTRULE + #undef RULEPATH + #define RULEPATH "rules/" +#endif + /** Prototypes **/ int _OS_GetRulesAttributes(char **attributes, @@ -85,6 +91,7 @@ int OS_ReadXMLRules(char *rulefile, char *xml_same_user = "same_user"; char *xml_same_location = "same_location"; char *xml_same_id = "same_id"; + char *xml_dodiff = "check_diff"; char *xml_different_url = "different_url"; @@ -100,14 +107,24 @@ int OS_ReadXMLRules(char *rulefile, int i; - /* Building the rule file name + path */ - i = strlen(RULEPATH) + strlen(rulefile) + 2; - rulepath = (char *)calloc(i,sizeof(char)); - if(!rulepath) + /* If no directory in the rulefile add the default */ + if((strchr(rulefile, '/')) == NULL) { - ErrorExit(MEM_ERROR,__local_name); + /* Building the rule file name + path */ + i = strlen(RULEPATH) + strlen(rulefile) + 2; + rulepath = (char *)calloc(i,sizeof(char)); + if(!rulepath) + { + ErrorExit(MEM_ERROR,ARGV0); + } + snprintf(rulepath,i,"%s/%s",RULEPATH,rulefile); + } + else + { + os_strdup(rulefile, rulepath); + debug1("%s is the rulefile", rulefile); + debug1("Not modifing the rule path"); } - snprintf(rulepath,i,"%s/%s",RULEPATH,rulefile); /* Reading the XML */ @@ -595,6 +612,16 @@ int OS_ReadXMLRules(char *rulefile, config_ruleinfo->alert_opts |= SAME_EXTRAINFO; } else if(strcasecmp(rule_opt[k]->element, + xml_dodiff)==0) + { + config_ruleinfo->context++; + config_ruleinfo->context_opts|= SAME_DODIFF; + if(!(config_ruleinfo->alert_opts & DO_EXTRAINFO)) + { + config_ruleinfo->alert_opts |= DO_EXTRAINFO; + } + } + else if(strcasecmp(rule_opt[k]->element, xml_same_dst_port) == 0) { config_ruleinfo->context_opts|= SAME_DSTPORT; @@ -687,6 +714,13 @@ int OS_ReadXMLRules(char *rulefile, config_ruleinfo->alert_opts &=0xfff-DO_LOGALERT; } } + else if(strcmp("no_ar", rule_opt[k]->content) == 0) + { + if(!(config_ruleinfo->alert_opts & NO_AR)) + { + config_ruleinfo->alert_opts|= NO_AR; + } + } else { merror(XML_VALUEERR, __local_name, xml_options, @@ -781,12 +815,22 @@ int OS_ReadXMLRules(char *rulefile, return(-1); } } + /* XXX As new features are added into ../analysisd/rules.c + * This code needs to be updated to match, but is out of date + * it's become a nightmare to correct with out just make the + * problem for someone later. + * + * This hack will allow any crap xml to pass without an + * error. The correct fix is to refactor the code so that + * ../analysisd/rules* and this code are not duplicates + * else { merror(XML_INVELEM, __local_name, rule_opt[k]->element); OS_ClearXML(&xml); return(-1); } + */ k++; } diff --git a/src/shared/sig_op.c b/src/shared/sig_op.c index 7820f21..bde3a72 100755 --- a/src/shared/sig_op.c +++ b/src/shared/sig_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: sig_op.c,v 1.8 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/store_op.c b/src/shared/store_op.c index 8566a2e..6794f8f 100644 --- a/src/shared/store_op.c +++ b/src/shared/store_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: store_op.c,v 1.11 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/validate_op.c b/src/shared/validate_op.c index 98e94fb..226bd33 100755 --- a/src/shared/validate_op.c +++ b/src/shared/validate_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: validate_op.c,v 1.28 2009/08/05 18:02:13 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/shared/wait_op.c b/src/shared/wait_op.c index 5c59205..3e98d05 100755 --- a/src/shared/wait_op.c +++ b/src/shared/wait_op.c @@ -1,11 +1,11 @@ -/* @(#) $Id: wait_op.c,v 1.5 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/syscheckd/Makefile b/src/syscheckd/Makefile index 162edca..b65f768 100755 --- a/src/syscheckd/Makefile +++ b/src/syscheckd/Makefile @@ -8,15 +8,11 @@ NAME=ossec-syscheckd include ../Config.Make -OBJS = syscheck.c config.c run_realtime.c create_db.c run_check.c ${OS_CONFIG} ${OS_ROOTCHECK} ${OS_SHARED} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_CRYPTO} +OBJS = syscheck.c config.c seechanges.c run_realtime.c create_db.c run_check.c ${OS_CONFIG} ${OS_ROOTCHECK} ${OS_SHARED} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_CRYPTO} OBJS2 = syscheck-baseline.c config.c create_db.c run_check.c ${OS_CONFIG} ${OS_ROOTCHECK} ${OS_SHARED} ${OS_XML} ${OS_REGEX} ${OS_NET} ${OS_CRYPTO} syscheck: $(CC) $(CFLAGS) ${OS_LINK} $(OBJS) -o ${NAME} - -baseline: - $(CC) $(CFLAGS) ${OS_LINK} $(OBJS2) -o syscheck-baseline - clean: ${CLEAN} build: diff --git a/src/syscheckd/config.c b/src/syscheckd/config.c index 9b57837..500c612 100755 --- a/src/syscheckd/config.c +++ b/src/syscheckd/config.c @@ -1,11 +1,11 @@ -/* @(#) $Id: config.c,v 1.32 2009/11/04 15:19:00 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/syscheckd/create_db.c b/src/syscheckd/create_db.c index 63610ba..ff2a72b 100755 --- a/src/syscheckd/create_db.c +++ b/src/syscheckd/create_db.c @@ -1,11 +1,11 @@ -/* @(#) $Id: create_db.c,v 1.28 2009/10/02 19:28:34 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation * * License details at the LICENSE file included with OSSEC or @@ -20,14 +20,11 @@ #include "os_crypto/md5_sha1/md5_sha1_op.h" -/* flags for read_dir and read_file */ -#define CREATE_DB 1 -#define CHECK_DB 2 int __counter = 0; /** Prototypes **/ -int read_dir(char *dir_name, int opts, int flag); +int read_dir(char *dir_name, int opts, OSMatch *restriction); /* int check_file(char *file_name) @@ -35,37 +32,9 @@ int read_dir(char *dir_name, int opts, int flag); */ int check_file(char *file_name) { - char buf[MAX_LINE +2]; - buf[MAX_LINE +1] = '\0'; - - while(fgets(buf, MAX_LINE, syscheck.fp) != NULL) + if(OSHash_Get(syscheck.fp, file_name)) { - if((buf[0] != '#') && (buf[0] != ' ') && (buf[0] != '\n')) - { - char *n_buf; - - /* Removing the new line */ - n_buf = strchr(buf,'\n'); - if(n_buf == NULL) - continue; - - *n_buf = '\0'; - - - /* First 6 characters are for internal use */ - n_buf = buf; - n_buf+=6; - - n_buf = strchr(n_buf, ' '); - if(n_buf) - { - n_buf++; - - /* Checking if name matches */ - if(strcmp(n_buf, file_name) == 0) - return(1); - } - } + return(1); } /* New file */ @@ -80,11 +49,13 @@ int check_file(char *file_name) /* int read_file(char *file_name, int opts, int flag) * Reads and generates the integrity data of a file. */ -int read_file(char *file_name, int opts, int flag) +int read_file(char *file_name, int opts, OSMatch *restriction) { - int check_file_new = 0; + char *buf; + char sha1s = '+'; struct stat statbuf; + /* Checking if file is to be ignored */ if(syscheck.ignore) { @@ -134,7 +105,18 @@ int read_file(char *file_name, int opts, int flag) verbose("%s: Reading dir: %s\n",ARGV0, file_name); #endif - return(read_dir(file_name, opts, flag)); + return(read_dir(file_name, opts, restriction)); + } + + + /* restricting file types. */ + if(restriction) + { + if(!OSMatch_Execute(file_name, strlen(file_name), + restriction)) + { + return(0); + } } @@ -147,39 +129,15 @@ int read_file(char *file_name, int opts, int flag) { os_md5 mf_sum; os_sha1 sf_sum; - - - /* If check_db, we just need to verify that the file is - * already present. If not, we add it. - */ - if(flag == CHECK_DB) - { - /* File in the database already */ - fseek(syscheck.fp, 0, SEEK_SET); - if(check_file(file_name)) - { - /* Sleeping in here too */ - #ifndef WIN32 - if(__counter >= (3 * syscheck.sleep_after)) - #else - if(__counter >= (syscheck.sleep_after)) - #endif - { - sleep(syscheck.tsleep); - __counter = 0; - } - __counter++; - - return(0); - } - fseek(syscheck.fp, 0, SEEK_END); - check_file_new = 1; - } + os_sha1 sf_sum2; + os_sha1 sf_sum3; /* Cleaning sums */ strncpy(mf_sum, "xxx", 4); strncpy(sf_sum, "xxx", 4); + strncpy(sf_sum2, "xxx", 4); + strncpy(sf_sum3, "xxx", 4); /* Generating checksums. */ @@ -211,31 +169,60 @@ int read_file(char *file_name, int opts, int flag) { strncpy(mf_sum, "xxx", 4); strncpy(sf_sum, "xxx", 4); + + } + + if(opts & CHECK_SEECHANGES) + { + sha1s = 's'; } } + else + { + if(opts & CHECK_SEECHANGES) + sha1s = 'n'; + else + sha1s = '-'; + } - /* Adding file */ - fprintf(syscheck.fp,"%c%c%c%c%c%c%d:%d:%d:%d:%s:%s %s\n", + buf = OSHash_Get(syscheck.fp, file_name); + if(!buf) + { + char alert_msg[912 +1]; + + alert_msg[912] = '\0'; + + if(opts & CHECK_SEECHANGES) + { + char *alertdump = seechanges_addfile(file_name); + if(alertdump) + { + free(alertdump); + alertdump = NULL; + } + } + + + snprintf(alert_msg, 912, "%c%c%c%c%c%c%d:%d:%d:%d:%s:%s", opts & CHECK_SIZE?'+':'-', opts & CHECK_PERM?'+':'-', opts & CHECK_OWNER?'+':'-', opts & CHECK_GROUP?'+':'-', opts & CHECK_MD5SUM?'+':'-', - opts & CHECK_SHA1SUM?'+':'-', + sha1s, opts & CHECK_SIZE?(int)statbuf.st_size:0, opts & CHECK_PERM?(int)statbuf.st_mode:0, opts & CHECK_OWNER?(int)statbuf.st_uid:0, opts & CHECK_GROUP?(int)statbuf.st_gid:0, opts & CHECK_MD5SUM?mf_sum:"xxx", - opts & CHECK_SHA1SUM?sf_sum:"xxx", - file_name); + opts & CHECK_SHA1SUM?sf_sum:"xxx"); + if(OSHash_Add(syscheck.fp, strdup(file_name), strdup(alert_msg)) <= 0) + { + merror("%s: ERROR: Unable to add file to db: %s", ARGV0, file_name); + } - /* Send new file */ - if(check_file_new) - { - char alert_msg[912 +2]; /* Sending the new checksum to the analysis server */ alert_msg[912 +1] = '\0'; @@ -249,14 +236,50 @@ int read_file(char *file_name, int opts, int flag) file_name); send_syscheck_msg(alert_msg); } + else + { + char alert_msg[OS_MAXSTR +1]; + char c_sum[256 +2]; + + c_sum[0] = '\0'; + c_sum[256] = '\0'; + alert_msg[0] = '\0'; + alert_msg[OS_MAXSTR] = '\0'; + + /* If it returns < 0, we will already have alerted. */ + if(c_read_file(file_name, buf, c_sum) < 0) + return(0); + + if(strcmp(c_sum, buf+6) != 0) + { + /* Sending the new checksum to the analysis server */ + char *fullalert = NULL; + alert_msg[OS_MAXSTR] = '\0'; + if(buf[5] == 's' || buf[5] == 'n') + { + fullalert = seechanges_addfile(file_name); + if(fullalert) + { + snprintf(alert_msg, OS_MAXSTR, "%s %s\n%s", c_sum, file_name, fullalert); + free(fullalert); + fullalert = NULL; + } + else + { + snprintf(alert_msg, 912, "%s %s", c_sum, file_name); + } + } + else + { + snprintf(alert_msg, 912, "%s %s", c_sum, file_name); + } + send_syscheck_msg(alert_msg); + } + } /* Sleeping in here too */ - #ifndef WIN32 - if(__counter >= (3 * syscheck.sleep_after)) - #else - if(__counter >= (2 * syscheck.sleep_after)) - #endif + if(__counter >= (syscheck.sleep_after)) { sleep(syscheck.tsleep); __counter = 0; @@ -282,7 +305,7 @@ int read_file(char *file_name, int opts, int flag) /* read_dir v0.1 * */ -int read_dir(char *dir_name, int opts, int flag) +int read_dir(char *dir_name, int opts, OSMatch *restriction) { int dir_size; @@ -297,8 +320,7 @@ int read_dir(char *dir_name, int opts, int flag) /* Directory should be valid */ if((dir_name == NULL)||((dir_size = strlen(dir_name)) > PATH_MAX)) { - if(flag == CREATE_DB) - merror(NULL_ERROR, ARGV0); + merror(NULL_ERROR, ARGV0); return(-1); } @@ -310,15 +332,13 @@ int read_dir(char *dir_name, int opts, int flag) { if(errno == ENOTDIR) { - if(read_file(dir_name, opts, flag) == 0) + if(read_file(dir_name, opts, restriction) == 0) return(0); } - if(flag == CREATE_DB) - { - #ifdef WIN32 - int di = 0; - char *(defaultfilesn[])= { + #ifdef WIN32 + int di = 0; + char *(defaultfilesn[])= { "C:\\autoexec.bat", "C:\\config.sys", "C:\\WINDOWS/System32/eventcreate.exe", @@ -327,29 +347,28 @@ int read_dir(char *dir_name, int opts, int flag) "C:\\WINDOWS/System32/Tasks", NULL }; - while(defaultfilesn[di] != NULL) + while(defaultfilesn[di] != NULL) + { + if(strcmp(defaultfilesn[di], dir_name) == 0) { - if(strcmp(defaultfilesn[di], dir_name) == 0) - { - break; - } - di++; + break; } + di++; + } - if(defaultfilesn[di] == NULL) - { - merror("%s: WARN: Error opening directory: '%s': %s ", - ARGV0, dir_name, strerror(errno)); - } - - #else - + if(defaultfilesn[di] == NULL) + { merror("%s: WARN: Error opening directory: '%s': %s ", - ARGV0, - dir_name, - strerror(errno)); - #endif + ARGV0, dir_name, strerror(errno)); } + + #else + + merror("%s: WARN: Error opening directory: '%s': %s ", + ARGV0, + dir_name, + strerror(errno)); + #endif return(-1); } @@ -387,7 +406,7 @@ int read_dir(char *dir_name, int opts, int flag) *s_name = '\0'; strncpy(s_name, entry->d_name, PATH_MAX - dir_size -2); - read_file(f_name, opts, flag); + read_file(f_name, opts, restriction); } closedir(dp); @@ -395,18 +414,15 @@ int read_dir(char *dir_name, int opts, int flag) } -/* int check_db() - * Checks database for new files. - */ -int check_db() +/* int run_dbcheck */ +int run_dbcheck() { int i = 0; - /* Read all available directories */ __counter = 0; do { - read_dir(syscheck.dir[i], syscheck.opts[i], CHECK_DB); + read_dir(syscheck.dir[i], syscheck.opts[i], syscheck.filerestrict[i]); i++; }while(syscheck.dir[i] != NULL); @@ -414,27 +430,26 @@ int check_db() } - /* int create_db * Creates the file database. */ -int create_db(int delete_db) +int create_db() { int i = 0; - - syscheck.fp = fopen(syscheck.db, "w+"); /* Read and write */ + + /* Creating store data */ + syscheck.fp = OSHash_Create(); if(!syscheck.fp) { - ErrorExit("%s: Unable to create syscheck database " - "at '%s'. Exiting.",ARGV0,syscheck.db); + ErrorExit("%s: Unable to create syscheck database." + ". Exiting.",ARGV0); return(0); } - - /* Creating a local fp only */ - if(delete_db) + if(!OSHash_setSize(syscheck.fp, 2048)) { - unlink(syscheck.db); + merror(LIST_ERROR, ARGV0); + return(0); } @@ -453,7 +468,7 @@ int create_db(int delete_db) __counter = 0; do { - if(read_dir(syscheck.dir[i], syscheck.opts[i], CREATE_DB) == 0) + if(read_dir(syscheck.dir[i], syscheck.opts[i], syscheck.filerestrict[i]) == 0) { #ifdef WIN32 if(syscheck.opts[i] & CHECK_REALTIME) diff --git a/src/syscheckd/run_check.c b/src/syscheckd/run_check.c index 26c5a93..12a364c 100755 --- a/src/syscheckd/run_check.c +++ b/src/syscheckd/run_check.c @@ -1,11 +1,11 @@ -/* @(#) $Id: run_check.c,v 1.49 2009/11/05 15:15:14 dcid Exp $ */ +/* @(#) $Id$ */ -/* Copyright (C) 2009 Trend Micro Inc. +/* Copyright (C) 2010 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -78,17 +78,6 @@ int send_rootcheck_msg(char *msg) */ void send_sk_db() { - char buf[MAX_LINE +1]; - int file_count = 0; - - buf[MAX_LINE] = '\0'; - - if(fseek(syscheck.fp, 0, SEEK_SET) == -1) - { - ErrorExit(FSEEK_ERROR, ARGV0, "syscheck_db"); - } - - /* Sending scan start message */ if(syscheck.dir[0]) { @@ -100,45 +89,9 @@ void send_sk_db() sleep(syscheck.tsleep +10); return; } - - - - while(fgets(buf,MAX_LINE, syscheck.fp) != NULL) - { - if((buf[0] != '#') && (buf[0] != ' ') && (buf[0] != '\n')) - { - char *n_buf; - - /* Removing the \n before sending to the analysis server */ - n_buf = strchr(buf,'\n'); - if(n_buf == NULL) - continue; - - *n_buf = '\0'; - - - /* First 6 characters are for internal use */ - n_buf = buf; - n_buf+=6; - - send_syscheck_msg(n_buf); - - - /* A count and a sleep to avoid flooding the server. - * Time or speed are not requirements in here - */ - file_count++; - - - /* sleep X every Y files */ - if(file_count >= syscheck.sleep_after) - { - sleep(syscheck.tsleep); - file_count = 0; - } - } - } + create_db(1); + /* Sending scan ending message */ sleep(syscheck.tsleep +10); @@ -222,10 +175,7 @@ void start_daemon() /* Will create the db to store syscheck data */ if(syscheck.scan_on_start) { - create_db(1); - fflush(syscheck.fp); - - sleep(syscheck.tsleep * 60); + sleep(syscheck.tsleep * 15); send_sk_db(); } else @@ -375,9 +325,6 @@ void start_daemon() /* We need to create the db, if scan on start is not set. */ if(syscheck.scan_on_start == 0) { - create_db(1); - fflush(syscheck.fp); - sleep(syscheck.tsleep * 10); send_sk_db(); sleep(syscheck.tsleep * 10); @@ -402,15 +349,8 @@ void start_daemon() #endif - check_db(); - - - /* Set syscheck.fp to the begining of the file */ - fseek(syscheck.fp, 0, SEEK_SET); - - /* Checking for changes */ - run_check(); + run_dbcheck(); } @@ -492,103 +432,6 @@ void start_daemon() } -/* run_check: v0.1 - * Read the database and check if the binary has changed - */ -void run_check() -{ - char c_sum[256 +2]; - char alert_msg[912 +2]; - char buf[MAX_LINE +2]; - int file_count = 0; - - - /* Cleaning buffer */ - memset(buf, '\0', MAX_LINE +1); - memset(alert_msg, '\0', 912 +1); - memset(c_sum, '\0', 256 +1); - - /* fgets garantee the null termination */ - while(fgets(buf, MAX_LINE, syscheck.fp) != NULL) - { - /* Buf should be in the following format: - * header checksum file_name (checksum space filename) - */ - char *n_file; /* file read from the db */ - char *n_sum; /* md5sum read from the db */ - char *tmp_c; /* tmp_char */ - - - /* Avoiding wrong formats in the database. Alert about them */ - if(buf[0] == '#' || buf[0] == ' ' || buf[0] == '\n') - { - merror("%s: Invalid entry in the integrity database: '%s'", - ARGV0, buf); - continue; - } - - /* Adding a sleep in here -- avoid floods and extreme CPU usage - * on the client side -- speed not necessary - */ - file_count++; - if(file_count >= (syscheck.sleep_after)) - { - sleep(syscheck.tsleep); - file_count = 0; - } - - - /* Finding the file name */ - n_file = strchr(buf, ' '); - if(n_file == NULL) - { - merror("%s: Invalid entry in the integrity check database.",ARGV0); - continue; - } - - /* Zeroing the ' ' and messing up with buf */ - *n_file = '\0'; - - - /* Setting n_file to the begining of the file name */ - n_file++; - - - /* Removing the '\n' if present and setting it to \0 */ - tmp_c = strchr(n_file,'\n'); - if(tmp_c) - { - *tmp_c = '\0'; - } - - - /* Setting n_sum to the begining of buf */ - n_sum = buf; - - - /* Cleaning up c_sum */ - memset(c_sum, '\0', 16); - c_sum[255] = '\0'; - - - /* If it returns < 0, we will already have alerted. */ - if(c_read_file(n_file, n_sum, c_sum) < 0) - continue; - - - if(strcmp(c_sum, n_sum+6) != 0) - { - /* Sending the new checksum to the analysis server */ - alert_msg[912 +1] = '\0'; - snprintf(alert_msg, 912, "%s %s", c_sum, n_file); - send_syscheck_msg(alert_msg); - - continue; - } - - /* FILE OK if reached here */ - } -} /* c_read_file @@ -597,7 +440,7 @@ void run_check() */ int c_read_file(char *file_name, char *oldsum, char *newsum) { - int size = 0, perm = 0, owner = 0, group = 0, md5sum = 0, sha1sum = 0; + int size = 0, perm = 0, owner = 0, group = 0, md5sum = 0, sha1sum = 0, seechanges = 0; struct stat statbuf; @@ -652,6 +495,17 @@ int c_read_file(char *file_name, char *oldsum, char *newsum) /* sha1 sum */ if(oldsum[5] == '+') sha1sum = 1; + + else if(oldsum[5] == 's') + { + sha1sum = 1; + seechanges = 1; + } + else if(oldsum[5] == 'n') + { + sha1sum = 0; + seechanges = 1; + } /* Generating new checksum */ diff --git a/src/syscheckd/run_realtime.c b/src/syscheckd/run_realtime.c index efae806..19f7c7b 100755 --- a/src/syscheckd/run_realtime.c +++ b/src/syscheckd/run_realtime.c @@ -1,11 +1,11 @@ -/* @(#) $Id: run_realtime.c,v 1.12 2009/12/01 15:40:08 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -38,6 +38,10 @@ #ifdef USEINOTIFY #include +#define OS_SIZE_6144 6144 +#define OS_MAXSTR OS_SIZE_6144 /* Size for logs, sockets, etc */ +#else +#include "shared.h" #endif @@ -49,69 +53,56 @@ int c_read_file(char *file_name, char *oldsum, char *newsum); /* Checking sum of the realtime file being monitored. */ int realtime_checksumfile(char *file_name) { - char buf[MAX_LINE +2]; - buf[MAX_LINE +1] = '\0'; - + char *buf; - fseek(syscheck.fp, 0, SEEK_SET); - while(fgets(buf, MAX_LINE, syscheck.fp) != NULL) + buf = OSHash_Get(syscheck.fp, file_name); + if(buf != NULL) { - if((buf[0] != '#') && (buf[0] != ' ') && (buf[0] != '\n')) - { - char *n_buf; - - /* Removing the new line */ - n_buf = strchr(buf,'\n'); - if(n_buf == NULL) - continue; - - *n_buf = '\0'; - - - /* First 6 characters are for internal use */ - n_buf = buf; - n_buf+=6; - - n_buf = strchr(n_buf, ' '); - if(n_buf) - { - n_buf++; - - /* Checking if name matches */ - if(strcmp(n_buf, file_name) == 0) - { - char c_sum[256 +2]; - c_sum[0] = '\0'; - c_sum[255] = '\0'; + char c_sum[256 +2]; + + c_sum[0] = '\0'; + c_sum[255] = '\0'; + + + /* If it returns < 0, we will already have alerted. */ + if(c_read_file(file_name, buf, c_sum) < 0) + { + return(0); + } + + + if(strcmp(c_sum, buf+6) != 0) + { + char *fullalert = NULL; + char alert_msg[OS_MAXSTR +1]; + alert_msg[OS_MAXSTR] = '\0'; + if(buf[5] == 's' || buf[5] == 'n') + { + fullalert = seechanges_addfile(file_name); + if(fullalert) + { + snprintf(alert_msg, OS_MAXSTR, "%s %s\n%s", c_sum, file_name, fullalert); + free(fullalert); + fullalert = NULL; + } + else + { + snprintf(alert_msg, 912, "%s %s", c_sum, file_name); + } + } + else + { + snprintf(alert_msg, 912, "%s %s", c_sum, file_name); + } + send_syscheck_msg(alert_msg); + + return(1); + } + + return(0); - - /* If it returns < 0, we will already have alerted. */ - if(c_read_file(file_name, buf, c_sum) < 0) - continue; - - - if(strcmp(c_sum, buf+6) != 0) - { - char alert_msg[912 +2]; - - /* Sending the new checksum to the analysis server */ - alert_msg[912 +1] = '\0'; - snprintf(alert_msg, 912, "%s %s", c_sum, file_name); - send_syscheck_msg(alert_msg); - - return(1); - } - - return(0); - - } - } - } } - - /* Adding entry if not in there. */ - fseek(syscheck.fp, 0, SEEK_END); return(0); } diff --git a/src/syscheckd/seechanges.c b/src/syscheckd/seechanges.c new file mode 100755 index 0000000..39ee33f --- /dev/null +++ b/src/syscheckd/seechanges.c @@ -0,0 +1,271 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All rights reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + + +#include "shared.h" +#include "os_crypto/md5/md5_op.h" + + + +/* Generate diffs alerts. */ +char *gen_diff_alert(char *filename, int alert_diff_time) +{ + int n = 0; + FILE *fp; + char *tmp_str; + char buf[OS_MAXSTR +1]; + char diff_alert[OS_MAXSTR +1]; + + buf[OS_MAXSTR] = '\0'; + diff_alert[OS_MAXSTR] = '\0'; + + snprintf(buf, OS_MAXSTR, "%s/local/%s/diff.%d", + DIFF_DIR_PATH, filename, alert_diff_time); + + fp = fopen(buf, "r"); + if(!fp) + { + merror("%s: ERROR: Unable to generate diff alert.", ARGV0); + return(NULL); + } + + n = fread(buf, 1, 4096 -1, fp); + if(n <= 0) + { + merror("%s: ERROR: Unable to generate diff alert (fread).", ARGV0); + fclose(fp); + return(NULL); + } + else if(n >= 4000) + { + /* We need to clear the last new line. */ + buf[n] = '\0'; + tmp_str = strrchr(buf, '\n'); + if(tmp_str) + *tmp_str = '\0'; + else + { + /* Weird diff with only one large line. */ + buf[256] = '\0'; + } + } + else + { + buf[n] = '\0'; + } + + n = 0; + + + /* Getting up to 20 line changes. */ + tmp_str = buf; + + + while(tmp_str && (*tmp_str != '\0')) + { + tmp_str = strchr(tmp_str, '\n'); + if(!tmp_str) + break; + else if(n >= 19) + { + *tmp_str = '\0'; + break; + } + n++; + tmp_str++; + } + + + /* Creating alert. */ + snprintf(diff_alert, 4096 -1, "%s%s", + buf, n>=19? + "\nMore changes..": + ""); + + + fclose(fp); + return(strdup(diff_alert)); +} + + +int seechanges_dupfile(char *old, char *new) +{ + int n; + FILE *fpr; + FILE *fpw; + unsigned char buf[2048 +1]; + + buf[2048] = '\0'; + + fpr = fopen(old,"r"); + fpw = fopen(new,"w"); + + if(!fpr || !fpw) + { + return(0); + } + + while((n = fread(buf, 1, 2048, fpr)) > 0) + { + buf[n] = '\0'; + fwrite(buf, n, 1, fpw); + + } + + fclose(fpr); + fclose(fpw); + return(1); +} + + +int seechanges_createpath(char *filename) +{ + char *buffer = NULL; + char *tmpstr = NULL; + char *newdir = NULL; + + + os_strdup(filename, buffer); + newdir = buffer; + tmpstr = strchr(buffer +1, '/'); + if(!tmpstr) + { + merror("%s: ERROR: Invalid path name: '%s'", ARGV0, filename); + free(buffer); + return(0); + } + *tmpstr = '\0'; + tmpstr++; + + + while(1) + { + if(IsDir(newdir) != 0) + { + #ifndef WIN32 + if(mkdir(newdir, 0770) == -1) + #else + if(mkdir(newdir) == -1) + #endif + { + merror(MKDIR_ERROR, ARGV0, newdir); + free(buffer); + return(0); + } + } + + if(*tmpstr == '\0') + { + break; + } + + tmpstr[-1] = '/'; + tmpstr = strchr(tmpstr, '/'); + if(!tmpstr) + { + break; + } + *tmpstr = '\0'; + tmpstr++; + } + + free(buffer); + return(1); +} + + +/* Checks if the file has changed */ +char *seechanges_addfile(char *filename) +{ + int date_of_change; + char old_location[OS_MAXSTR +1]; + char tmp_location[OS_MAXSTR +1]; + char diff_cmd[OS_MAXSTR +1]; + + os_md5 md5sum_old; + os_md5 md5sum_new; + + old_location[OS_MAXSTR] = '\0'; + tmp_location[OS_MAXSTR] = '\0'; + diff_cmd[OS_MAXSTR] = '\0'; + md5sum_new[0] = '\0'; + md5sum_old[0] = '\0'; + + + snprintf(old_location, OS_MAXSTR, "%s/local/%s/%s", DIFF_DIR_PATH, filename +1, + DIFF_LAST_FILE); + + + /* If the file is not there, rename new location to last location. */ + if(OS_MD5_File(old_location, md5sum_old) != 0) + { + seechanges_createpath(old_location); + if(seechanges_dupfile(filename, old_location) != 1) + { + merror(RENAME_ERROR, ARGV0, filename); + } + return(NULL); + } + + + /* Get md5sum of the new file. */ + if(OS_MD5_File(filename, md5sum_new) != 0) + { + //merror("%s: ERROR: Invalid internal state (missing '%s').", + // ARGV0, filename); + return(NULL); + } + + + /* If they match, keep the old file and remove the new. */ + if(strcmp(md5sum_new, md5sum_old) == 0) + { + return(NULL); + } + + + /* Saving the old file at timestamp and renaming new to last. */ + date_of_change = File_DateofChange(old_location); + snprintf(tmp_location, OS_MAXSTR, "%s/local/%s/state.%d", DIFF_DIR_PATH, filename +1, + date_of_change); + rename(old_location, tmp_location); + if(seechanges_dupfile(filename, old_location) != 1) + { + merror("%s: ERROR: Unable to create snapshot for %s",ARGV0, filename); + return(NULL); + } + + + /* Run diff. */ + date_of_change = File_DateofChange(old_location); + snprintf(diff_cmd, 2048, "diff \"%s\" \"%s\" > \"%s/local/%s/diff.%d\" " + "2>/dev/null", + tmp_location, old_location, + DIFF_DIR_PATH, filename +1, date_of_change); + if(system(diff_cmd) != 256) + { + merror("%s: ERROR: Unable to run diff for %s", + ARGV0, filename); + return(NULL); + } + + + /* Generate alert. */ + return(gen_diff_alert(filename, date_of_change)); + + + return(NULL); +} + + + +/* EOF */ diff --git a/src/syscheckd/syscheck-baseline.c b/src/syscheckd/syscheck-baseline.c index ea755b8..2a77eb1 100755 --- a/src/syscheckd/syscheck-baseline.c +++ b/src/syscheckd/syscheck-baseline.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck-baseline.c,v 1.2 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/syscheckd/syscheck.c b/src/syscheckd/syscheck.c index ff88da4..67a5879 100755 --- a/src/syscheckd/syscheck.c +++ b/src/syscheckd/syscheck.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck.c,v 1.49 2009/11/18 19:07:42 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -29,10 +29,6 @@ #include "rootcheck/rootcheck.h" -/* Definitions only used in here. */ -#define SYSCHECK_DB SYSCHECK_DIR "/syschecklocal.db" -#define SYS_WIN_DB "syscheck/syschecklocal.db" - int dump_syscheck_entry(config *syscheck, char *entry, int vals, int reg); @@ -114,11 +110,6 @@ int Start_win32_Syscheck() - /* Opening syscheck db file */ - os_calloc(1024,sizeof(char), syscheck.db); - snprintf(syscheck.db,1023,"%s",SYS_WIN_DB); - - /* Printing options */ r = 0; while(syscheck.registry[r] != NULL) @@ -150,7 +141,6 @@ int Start_win32_Syscheck() os_wait(); - /* Start the daemon checking against the syscheck.db */ start_daemon(); @@ -273,20 +263,7 @@ int main(int argc, char **argv) syscheck.workdir = DEFAULTDIR; - /* Creating a temporary fp */ - syscheck.db = (char *)calloc(1024,sizeof(char)); - if(syscheck.db == NULL) - ErrorExit(MEM_ERROR,ARGV0); - - snprintf(syscheck.db,1023,"%s%s-%d%d.tmp", - syscheck.workdir, - SYSCHECK_DB, - (int)time(NULL), - (int)getpid()); - - - - if (!run_foreground) + if(!run_foreground) { nowDaemon(); goDaemon(); diff --git a/src/syscheckd/syscheck.h b/src/syscheckd/syscheck.h index 53f5989..1827b83 100755 --- a/src/syscheckd/syscheck.h +++ b/src/syscheckd/syscheck.h @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck.h,v 1.16 2009/06/30 17:08:19 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -46,10 +46,10 @@ int Read_Syscheck_Config(char * cfgfile); int create_db(); -/* int check_db() - * Checks database for new files. +/* int run_dbcheck() + * Checks database for changes. */ -int check_db(); +int run_dbcheck(); /** void os_winreg_check() * Checks the registry for changes. @@ -65,6 +65,12 @@ int realtime_adddir(char *dir); /* Process real time queue. */ int realtime_process(); +/* Process the content of the file changes. */ +char *seechanges_addfile(char *filename); + +/* get checksum changes. */ +int c_read_file(char *file_name, char *oldsum, char *newsum); + /** Sends syscheck message. */ int send_syscheck_msg(char *msg); diff --git a/src/syscheckd/win-registry.c b/src/syscheckd/win-registry.c index 0031ab4..b0e6bd3 100644 --- a/src/syscheckd/win-registry.c +++ b/src/syscheckd/win-registry.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win-registry.c,v 1.15 2009/08/31 18:26:04 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/util/Makefile b/src/util/Makefile index 36205f2..dac3c18 100755 --- a/src/util/Makefile +++ b/src/util/Makefile @@ -14,10 +14,12 @@ me: $(CC) $(CFLAGS) ${OS_LINK} ${SUP} syscheck_update.c $(OBJS) -o syscheck_update $(CC) $(CFLAGS) ${OS_LINK} clear_stats.c $(OBJS) -o clear_stats $(CC) $(CFLAGS) ${OS_LINK} list_agents.c $(OBJS) -o list_agents + $(CC) $(CFLAGS) ${OS_LINK} verify-agent-conf.c $(OS_CONFIG) $(OBJS) ${OS_XML} -o verify-agent-conf $(CC) $(CFLAGS) ${OS_LINK} ${SUP} agent_control.c $(OBJS) -o agent_control $(CC) $(CFLAGS) ${OS_LINK} ${SUP} syscheck_control.c $(OBJS) -o syscheck_control $(CC) $(CFLAGS) ${OS_LINK} ${SUP} rootcheck_control.c $(OBJS) -o rootcheck_control + $(CC) $(CFLAGS) ${OS_LINK} ossec-regex.c $(OBJS) -o ossec-regex clean: - $(CLEAN) syscheck_update clear_stats list_agents agent_control syscheck_control rootcheck_control + $(CLEAN) syscheck_update clear_stats list_agents agent_control syscheck_control rootcheck_control verify-agent-conf ossec-regex build: - cp -pr syscheck_update clear_stats list_agents syscheck_control rootcheck_control agent_control ${PT}../bin + cp -pr syscheck_update clear_stats list_agents syscheck_control rootcheck_control agent_control verify-agent-conf ossec-regex ${PT}../bin diff --git a/src/util/agent_control.c b/src/util/agent_control.c index d81355b..3937fc3 100755 --- a/src/util/agent_control.c +++ b/src/util/agent_control.c @@ -1,11 +1,11 @@ -/* @(#) $Id: agent_control.c,v 1.11 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/clear_stats.c b/src/util/clear_stats.c index 662375b..6060159 100755 --- a/src/util/clear_stats.c +++ b/src/util/clear_stats.c @@ -1,11 +1,11 @@ -/* @(#) $Id: clear_stats.c,v 1.6 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/list_agents.c b/src/util/list_agents.c index a3624ce..f1781b1 100755 --- a/src/util/list_agents.c +++ b/src/util/list_agents.c @@ -1,11 +1,11 @@ -/* @(#) $Id: list_agents.c,v 1.7 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/ossec-regex.c b/src/util/ossec-regex.c new file mode 100644 index 0000000..70df990 --- /dev/null +++ b/src/util/ossec-regex.c @@ -0,0 +1,102 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2009 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + +/* This tool will clear the project statistics */ + +#include "shared.h" + +#undef ARGV0 +#define ARGV0 "ossec-regex" + + +/** help **/ +void helpmsg() +{ + printf("\nOSSEC HIDS %s: ossec-regex pattern\n", ARGV0); + exit(1); +} + + +/** main **/ +int main(int argc, char **argv) +{ + char *pattern; + + char msg[OS_MAXSTR +1]; + memset(msg, '\0', OS_MAXSTR +1); + OSRegex regex; + OSMatch matcher; + + OS_SetName(ARGV0); + + + /* user arguments */ + if(argc != 2) + { + helpmsg(); + return(-1); + } + + /* User options */ + if(strcmp(argv[1], "-h") == 0) + { + helpmsg(); + return(-1); + } + + os_strdup(argv[1], pattern); + if(!OSRegex_Compile(pattern, ®ex, 0)) + { + printf("pattern does not compile with OSRegex_Compile\n"); + return(-1); + } + if(!OSMatch_Compile(pattern, &matcher, 0)) + { + printf("pattern does not compile with OSMatch_Compile\n"); + return(-1); + } + + + while((fgets(msg, OS_MAXSTR, stdin)) != NULL) + { + /* Removing new line. */ + if(msg[strlen(msg) -1] == '\n') + msg[strlen(msg) -1] = '\0'; + + /* Make sure we ignore blank lines. */ + if(strlen(msg) < 2) { continue; } + + if(OSRegex_Execute(msg, ®ex)) + printf("+OSRegex_Execute: %s\n",msg); + /* + else + printf("-OSRegex_Execute: \n"); + */ + + if(OS_Regex(pattern, msg)) + printf("+OS_Regex : %s\n", msg); + /* + else + printf("-OS_Regex: \n"); + */ + + if(OSMatch_Execute(msg, strlen(msg), &matcher)) + printf("+OSMatch_Compile: %s\n", msg); + + if(OS_Match2(pattern, msg)) + printf("+OS_Match2 : %s\n", msg); + } + return(0); +} + + +/* EOF */ diff --git a/src/util/rootcheck_control.c b/src/util/rootcheck_control.c index 5387914..fff7a55 100755 --- a/src/util/rootcheck_control.c +++ b/src/util/rootcheck_control.c @@ -1,11 +1,11 @@ -/* @(#) $Id: rootcheck_control.c,v 1.5 2009/06/24 18:53:09 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/syscheck_control.c b/src/util/syscheck_control.c index 8fc66e9..7f7a7e7 100755 --- a/src/util/syscheck_control.c +++ b/src/util/syscheck_control.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck_control.c,v 1.5 2009/08/05 18:02:14 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/syscheck_update.c b/src/util/syscheck_update.c index ce58d45..1a7f25a 100755 --- a/src/util/syscheck_update.c +++ b/src/util/syscheck_update.c @@ -1,11 +1,11 @@ -/* @(#) $Id: syscheck_update.c,v 1.16 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/util/verify-agent-conf.c b/src/util/verify-agent-conf.c new file mode 100755 index 0000000..ee684d0 --- /dev/null +++ b/src/util/verify-agent-conf.c @@ -0,0 +1,50 @@ +/* @(#) $Id$ */ + +/* Copyright (C) 2010 Trend Micro Inc. + * All right reserved. + * + * This program is a free software; you can redistribute it + * and/or modify it under the terms of the GNU General Public + * License (version 2) as published by the FSF - Free Software + * Foundation + */ + + +#include "shared.h" +#include "config/localfile-config.h" +#include "config/config.h" +#include "logcollector/logcollector.h" + + +#undef ARGV0 +#define ARGV0 "verify-agent-conf" + + + +/* main: v0.3: 2005/04/04 */ +int main(int argc, char **argv) +{ + int modules = 0; + logreader_config log_config; + + + /* Setting the name */ + OS_SetName(ARGV0); + + + modules|= CLOCALFILE; + modules|= CAGENT_CONFIG; + log_config.config = NULL; + if(ReadConfig(modules, AGENTCONFIG, &log_config, NULL) < 0) + { + return(OS_INVALID); + } + + logff = log_config.config; + + return(0); + + +} + +/* EOF */ diff --git a/src/win32/add-localfile.c b/src/win32/add-localfile.c index f62342c..afba5b6 100755 --- a/src/win32/add-localfile.c +++ b/src/win32/add-localfile.c @@ -1,11 +1,11 @@ -/* @(#) $Id: add-localfile.c,v 1.13 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ @@ -122,35 +122,6 @@ int config_file(char *name, char *file, int quiet) } printf("%s: Adding log file to be monitored: '%s'.\n", name,file); - printf("%s: Continue? (y/n):", name); - while(1) - { - char u_buffer[256]; - memset(u_buffer, '\0', 256); - if((fgets(u_buffer, 254, stdin) != NULL) && - (strlen(u_buffer) < 250)) - { - if((u_buffer[0] == 'y') || (u_buffer[0] == 'Y')) - { - add = 1; - break; - } - else if((u_buffer[0] == 'n') || (u_buffer[0] == 'N')) - { - add = 0; - break; - } - } - printf("%s: Continue? (y/n):", name); - } - - if(add == 0) - { - printf("%s: Action not taken.\n", name); - fclose(fp); - return(0); - } - fprintf(fp, "\r\n" "\r\n" "\r\n" diff --git a/src/win32/doc.html b/src/win32/doc.html index 98a349b..0595360 100644 --- a/src/win32/doc.html +++ b/src/win32/doc.html @@ -1,9 +1,9 @@ - + - Redirecting to the online documentation at http://www.ossec.net/en/win.html...
+ Redirecting to the online documentation at http://www.ossec.net/doc/index.html...
diff --git a/src/win32/extract-win-el.c b/src/win32/extract-win-el.c index 037e4e9..53ba5aa 100755 --- a/src/win32/extract-win-el.c +++ b/src/win32/extract-win-el.c @@ -1,11 +1,11 @@ -/* @(#) $Id: extract-win-el.c,v 1.7 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/gen_win.cmd b/src/win32/gen_win.cmd new file mode 100644 index 0000000..ef17291 --- /dev/null +++ b/src/win32/gen_win.cmd @@ -0,0 +1,56 @@ +REM Generate windows packages +REM Author: Michael Starks +REM Based on gen_win.sh by Daniel Cid + +REM This program is a free software; you can redistribute it +REM and/or modify it under the terms of the GNU General Public +REM License (version 2) as published by the FSF - Free Software +REM Foundation + +REM Enable delayed variable expansion +SETLOCAL ENABLEDELAYEDEXPANSION +SET FILE=win-files.txt +SET WINPKG=win-pkg + +REM Check for public domain unix2dos.exe. It can be found here: http://www.efgh.com/software/unix2dos.htm +IF NOT EXIST unix2dos.exe echo unix2dos.exe not found, exiting... && EXIT 1 + +REM Generating configs +unix2dos.exe ossec.conf +type ossec.conf > ossec-win.conf +unix2dos.exe help.txt +type help.txt > help_win.txt +unix2dos.exe ..\..\etc\internal_options.conf +type ..\..\etc\internal_options.conf > internal_options-win.conf +unix2dos.exe ..\..\LICENSE +type ..\..\LICENSE > LICENSE.txt +unix2dos.exe ..\..\active-response\win\route-null.cmd +type ..\..\active-response\win\route-null.cmd > route-null.cmd +unix2dos.exe ..\..\active-response\win\restart-ossec.cmd +type ..\..\active-response\win\restart-ossec.cmd > restart-ossec.cmd + +REM Going to the source dir +cd .. +IF NOT EXIST %WINPKG%\setup mkdir %WINPKG%\setup + +FOR /F "tokens=1,2 delims= " %%i in (Win32\%FILE%) DO ( + REM Fix the slash + SET FS1=%%i + SET FS1=!FS1:/=\! + SET FS2=%%j + SET FS2=!FS2:/=\! + IF EXIST !FS1!\NUL ( + xcopy "!FS1!" "%WINPKG%\!FS2!" /E /I /F /Y || echo Error copying !FS1! to "%WINPKG%\!FS2!" && EXIT 1 + ) ELSE ( + copy !FS1! "%WINPKG%\!FS2!" || echo Error copying !FS1! to "%WINPKG%\!FS2!" EXIT 1 + ) +) + +REM Final cleanup +del %WINPKG%\os_crypto\md5\main.c +del %WINPKG%\os_crypto\blowfish\main.c +del %WINPKG%\os_crypto\sha1\main.c +del %WINPKG%\os_crypto\md5_sha1\main.c +del %WINPKG%\shared\rules_op.c + +ENDLOCAL diff --git a/src/win32/help.txt b/src/win32/help.txt index 19663b5..71eb11e 100755 --- a/src/win32/help.txt +++ b/src/win32/help.txt @@ -1,50 +1,50 @@ -** OSSEC Windows Agent v2.3 ** -** Copyright (C) 2009 Trend Micro Inc. ** +** OSSEC Windows Agent v2.5.1 ** +** Copyright (C) 2010 Trend Micro Inc. ** -Thanks for installing 'OSSEC Windows Agent version 1.6'. Before you continue, +Thanks for installing 'OSSEC Windows Agent version 2.5.1'. Before you continue, make sure that you have an instance of the OSSEC server running and configured to accept this system as an agent. For more information on how to install the server version of OSSEC, look at: -http://www.ossec.net/main/manual/#installtypes +http://www.ossec.net/doc/manual/installation/index.html http://www.ossec.net/wiki/index.php/InstallGuides ** Table of contents ** -1- How to obtain more information? -2- What this agent does? -3- Questions/Support? +1- How to obtain more information +2- What this agent does +3- Questions/Support ** Responses ** -1- How to obtain more information? +1- How to obtain more information You can obtain more information about OSSEC on the following links: -http://www.ossec.net/main/manual/ (Manual) -http://www.ossec.net/wiki/index.php/FAQ (FAQ) +http://www.ossec.net/doc/manual/index.html +http://www.ossec.net/doc/faq/index.html (FAQ) http://www.ossec.net (OSSEC site) http://www.ossec.net/dcid/ (OSSEC blog) -2- What this agent does? +2- What this agent does The Windows agent does the following tasks: --Monitors the Windows event log on real time. +-Monitors the Windows event log in real time. -Monitors IIS logs (Web, FTP, SMTP) and any other logs present on your - system (including Symantec Anti-Virus, MySQL, Apache, etc) on real time. + system (including Symantec Anti-Virus, MySQL, Apache, etc) in real time. -Periodically checks the Windows Registry for changes. --Periodically checks your Windows folders for changes. +-Periodically, or in real-time, checks your Windows folders for changes. -Periodically does policy verifications to make sure your system is configured properly. -3- Questions/Support? +3- Questions/Support Visit the following link for information on how to get help or support for OSSEC: diff --git a/src/win32/os_win.h b/src/win32/os_win.h index a84e445..ab5d4dd 100755 --- a/src/win32/os_win.h +++ b/src/win32/os_win.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_win.h,v 1.8 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/ossec-installer.nsi b/src/win32/ossec-installer.nsi index 4597860..bd1e48c 100755 --- a/src/win32/ossec-installer.nsi +++ b/src/win32/ossec-installer.nsi @@ -6,19 +6,18 @@ ;-------------------------------- ;General -!define VERSION "2.3" -!define NAME "Ossec HIDS" +!define MUI_ICON favicon.ico +!define MUI_UNICON ossec-uninstall.ico +!define VERSION "2.5.1" +!define NAME "OSSEC HIDS" !define /date CDATE "%b %d %Y at %H:%M:%S" - Name "${NAME} Windows Agent v${VERSION}" -BrandingText "Copyright (C) 2009 Trend Micro Inc." +BrandingText "Copyright (C) 2010 Trend Micro Inc." OutFile "ossec-win32-agent.exe" - -InstallDir $PROGRAMFILES\ossec-agent -InstallDirRegKey HKLM "ossec" "Install_Dir" - +InstallDir "$PROGRAMFILES\ossec-agent" +InstallDirRegKey HKLM Software\OSSEC "" ;-------------------------------- ;Interface Settings @@ -27,21 +26,14 @@ InstallDirRegKey HKLM "ossec" "Install_Dir" ;-------------------------------- ;Pages - !define MUI_ICON favicon.ico - !define MUI_UNICON ossec-uninstall.ico + !define MUI_WELCOMEPAGE_TITLE_3LINES !define MUI_WELCOMEPAGE_TEXT "This wizard will guide you through the install of ${Name}.\r\n\r\nClick next to continue." - + !define MUI_FINISHPAGE_TITLE_3LINES + !define MUI_FINISHPAGE_RUN "$INSTDIR\win32ui.exe" + !define MUI_FINISHPAGE_RUN_TEXT "Run OSSEC Agent Manager" + ; Page for choosing components. !define MUI_COMPONENTSPAGE_TEXT_TOP "Select the options you want to be executed. Click next to continue." - - ;!define MUI_COMPONENTSPAGE_TEXT_COMPLIST "text complist" - - ;!define MUI_COMPONENTSPAGE_TEXT_INSTTYPE "Select components to install:" - - ;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_TITLE "text abac" - - ;!define MUI_COMPONENTSPAGE_TEXT_DESCRIPTION_INFO "text info oi" - !define MUI_COMPONENTSPAGE_NODESC !insertmacro MUI_PAGE_WELCOME @@ -51,6 +43,9 @@ InstallDirRegKey HKLM "ossec" "Install_Dir" !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH + ; These have to be defined again to work with the uninstall pages + !define MUI_WELCOMEPAGE_TITLE_3LINES + !define MUI_FINISHPAGE_TITLE_3LINES !insertmacro MUI_UNPAGE_WELCOME !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES @@ -62,37 +57,65 @@ InstallDirRegKey HKLM "ossec" "Install_Dir" !insertmacro MUI_LANGUAGE "English" ;-------------------------------- +; Function to stop OSSEC service if running Function .onInit - SetOutPath $INSTDIR IfFileExists $INSTDIR\ossec.conf 0 +3 - MessageBox MB_OKCANCEL "${NAME} is already installed. We will stop it before continuing." IDOK NoAbort + MessageBox MB_OKCANCEL "${NAME} is already installed. It will be stopped before continuing." /SD IDOK IDOK NoAbort Abort NoAbort: - ;; Stopping ossec service. - ExecWait '"net" "stop" "OssecSvc"' + ;; Stopping ossec service. + nsExec::ExecToStack '"net" "stop" "OssecSvc"' FunctionEnd +;-------------------------------- +;Main install section Section "OSSEC Agent (required)" MainSec -;Required section. SectionIn RO SetOutPath $INSTDIR ClearErrors -File ossec-agent.exe default-ossec.conf manage_agents.exe os_win32ui.exe win32ui.exe ossec-rootcheck.exe internal_options.conf setup-windows.exe setup-syscheck.exe setup-iis.exe service-start.exe service-stop.exe doc.html rootkit_trojans.txt rootkit_files.txt add-localfile.exe LICENSE.txt rootcheck\rootcheck.conf rootcheck\db\win_applications_rcl.txt rootcheck\db\win_malware_rcl.txt rootcheck\db\win_audit_rcl.txt help.txt vista_sec.csv route-null.cmd restart-ossec.cmd -WriteRegStr HKLM SOFTWARE\ossec "Install_Dir" "$INSTDIR" +File \ +ossec-agent.exe \ +default-ossec.conf \ +manage_agents.exe \ +os_win32ui.exe \ +ossec-rootcheck.exe \ +internal_options.conf \ +setup-windows.exe \ +setup-syscheck.exe \ +setup-iis.exe \ +service-start.exe \ +service-stop.exe \ +doc.html \ +rootkit_trojans.txt \ +rootkit_files.txt \ +add-localfile.exe \ +LICENSE.txt \ +rootcheck\rootcheck.conf \ +rootcheck\db\win_applications_rcl.txt \ +rootcheck\db\win_malware_rcl.txt \ +rootcheck\db\win_audit_rcl.txt \ +help.txt \ +vista_sec.csv \ +route-null.cmd \ +restart-ossec.cmd -WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ossec" "DisplayName" "OSSEC Hids Agent" +WriteRegStr HKLM SOFTWARE\ossec "Install_Dir" "$INSTDIR" +WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" "DisplayName" "${NAME} ${VERSION}" +WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" "DisplayVersion" "${VERSION}" +WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" "DisplayIcon" "${MUI_ICON}" +WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" "HelpLink" "http://www.ossec.net/main/support/" +WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" "URLInfoAbout" "http://www.ossec.net" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ossec" "UninstallString" '"$INSTDIR\uninstall.exe"' WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ossec" "NoModify" 1 WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ossec" "NoRepair" 1 WriteUninstaller "uninstall.exe" - ; Writing version and install information FileOpen $0 $INSTDIR\VERSION.txt w IfErrors done @@ -101,7 +124,6 @@ FileWrite $0 "Installed on ${CDATE}" FileClose $0 done: - CreateDirectory "$INSTDIR\rids" CreateDirectory "$INSTDIR\syscheck" CreateDirectory "$INSTDIR\shared" @@ -116,58 +138,60 @@ Rename "$INSTDIR\win_audit_rcl.txt" "$INSTDIR\shared\win_audit_rcl.txt" Rename "$INSTDIR\win_applications_rcl.txt" "$INSTDIR\shared\win_applications_rcl.txt" Rename "$INSTDIR\route-null.cmd" "$INSTDIR\active-response\bin\route-null.cmd" Rename "$INSTDIR\restart-ossec.cmd" "$INSTDIR\active-response\bin\restart-ossec.cmd" -Delete "$SMPROGRAMS\ossec\Edit.lnk" -Delete "$SMPROGRAMS\ossec\Uninstall.lnk" -Delete "$SMPROGRAMS\ossec\Documentation.lnk" -Delete "$SMPROGRAMS\ossec\Edit Config.lnk" -Delete "$SMPROGRAMS\ossec\*.*" - -; Remove directories used -RMDir "$SMPROGRAMS\ossec" - -; Creating SMS directory -CreateDirectory "$SMPROGRAMS\ossec" - -CreateShortCut "$SMPROGRAMS\ossec\Manage Agent.lnk" "$INSTDIR\win32ui.exe" "" "$INSTDIR\win32ui.exe" 0 -CreateShortCut "$SMPROGRAMS\ossec\Documentation.lnk" "$INSTDIR\doc.html" "" "$INSTDIR\doc.html" 0 -CreateShortCut "$SMPROGRAMS\ossec\Edit Config.lnk" "$INSTDIR\ossec.conf" "" "$INSTDIR\ossec.conf" 0 -CreateShortCut "$SMPROGRAMS\ossec\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 - - -; Install in the services +Rename "$INSTDIR\os_win32ui.exe" "$INSTDIR\win32ui.exe" +Delete "$SMPROGRAMS\OSSEC\Edit.lnk" +Delete "$SMPROGRAMS\OSSEC\Uninstall.lnk" +Delete "$SMPROGRAMS\OSSEC\Documentation.lnk" +Delete "$SMPROGRAMS\OSSEC\Edit Config.lnk" +Delete "$SMPROGRAMS\OSSEC\*.*" + +; Remove start menu entry. +RMDir "$SMPROGRAMS\OSSEC" + +; Creating start menu directory +CreateDirectory "$SMPROGRAMS\OSSEC" +CreateShortCut "$SMPROGRAMS\OSSEC\Manage Agent.lnk" "$INSTDIR\win32ui.exe" "" "$INSTDIR\win32ui.exe" 0 +CreateShortCut "$SMPROGRAMS\OSSEC\Documentation.lnk" "$INSTDIR\doc.html" "" "$INSTDIR\doc.html" 0 +CreateShortCut "$SMPROGRAMS\OSSEC\Edit Config.lnk" "$INSTDIR\ossec.conf" "" "$INSTDIR\ossec.conf" 0 +CreateShortCut "$SMPROGRAMS\OSSEC\Uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0 + +; Install in the services (perhaps it would be better to use a plug-in here?) +;nsExec::ExecToStack '"$INSTDIR\ossec-agent.exe" install-service' ExecWait '"$INSTDIR\ossec-agent.exe" install-service' -ExecWait '"$INSTDIR\setup-windows.exe" "$INSTDIR"' -Exec '"$INSTDIR\os_win32ui.exe" "$INSTDIR"' +;nsExec::ExecToStack '"$INSTDIR\setup-windows.exe" "$INSTDIR"' +ExecWait '"$INSTDIR\setup-windows.exe" "$INSTDIR"' SectionEnd Section "Scan and monitor IIS logs (recommended)" IISLogs -ExecWait '"$INSTDIR\setup-iis.exe" "$INSTDIR"' +nsExec::ExecToStack '"$INSTDIR\setup-iis.exe" "$INSTDIR"' SectionEnd Section "Enable integrity checking (recommended)" IntChecking -ExecWait '"$INSTDIR\setup-syscheck.exe" "$INSTDIR" "enable"' +nsExec::ExecToStack '"$INSTDIR\setup-syscheck.exe" "$INSTDIR" "enable"' SectionEnd - - +;-------------------------------- +;Uninstall section Section "Uninstall" - ; Stop ossec - ExecWait '"net" "stop" "OssecSvc"' + ;Need a step to check for a running agent manager, otherwise it and the INSTDIR directory will not be removed. + + ; Stop ossec. Perhaps we should look for an exit status here. Also, may be a good place to use a plug-in. + nsExec::ExecToStack '"net" "stop" "OssecSvc"' - ; Uninstall from the services - Exec '"$INSTDIR\ossec-agent.exe" uninstall-service' + ; Uninstall from the services. Again, maybe use a plugin here. + nsExec::ExecToStack '"$INSTDIR\ossec-agent.exe" uninstall-service' ; Remove registry keys - DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\ossec" - DeleteRegKey HKLM SOFTWARE\ossec + DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\OSSEC" + DeleteRegKey HKLM SOFTWARE\OSSEC - ; Remove files and uninstaller + ; Remove files and uninstaller. There have been instances where the ossec-agent directory and executable is left. Why? Delete "$INSTDIR\ossec-agent.exe" Delete "$INSTDIR\manage_agents.exe" Delete "$INSTDIR\ossec.conf" @@ -181,11 +205,11 @@ Section "Uninstall" Delete "$INSTDIR" ; Remove shortcuts, if any - Delete "$SMPROGRAMS\ossec\*.*" - Delete "$SMPROGRAMS\ossec\*" + Delete "$SMPROGRAMS\OSSEC\*.*" + Delete "$SMPROGRAMS\OSSEC\*" ; Remove directories used - RMDir "$SMPROGRAMS\ossec" + RMDir "$SMPROGRAMS\OSSEC" RMDir "$INSTDIR\shared" RMDir "$INSTDIR\syscheck" RMDir "$INSTDIR\rids" @@ -194,4 +218,3 @@ Section "Uninstall" RMDir "$INSTDIR" SectionEnd - diff --git a/src/win32/service-start.c b/src/win32/service-start.c index a804b06..24d30e2 100644 --- a/src/win32/service-start.c +++ b/src/win32/service-start.c @@ -1,11 +1,11 @@ -/* @(#) $Id: service-start.c,v 1.5 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/service-stop.c b/src/win32/service-stop.c index 6db442b..37c0a2d 100644 --- a/src/win32/service-stop.c +++ b/src/win32/service-stop.c @@ -1,11 +1,11 @@ -/* @(#) $Id: service-stop.c,v 1.4 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/setup-iis.c b/src/win32/setup-iis.c index 9874b45..7cdd1cf 100755 --- a/src/win32/setup-iis.c +++ b/src/win32/setup-iis.c @@ -1,11 +1,11 @@ -/* @(#) $Id: setup-iis.c,v 1.16 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/setup-shared.c b/src/win32/setup-shared.c index 837768a..081beaa 100755 --- a/src/win32/setup-shared.c +++ b/src/win32/setup-shared.c @@ -1,11 +1,11 @@ -/* @(#) $Id: setup-shared.c,v 1.3 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/setup-shared.h b/src/win32/setup-shared.h index 581a893..5801f42 100755 --- a/src/win32/setup-shared.h +++ b/src/win32/setup-shared.h @@ -1,11 +1,11 @@ -/* @(#) $Id: setup-shared.h,v 1.4 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/setup-syscheck.c b/src/win32/setup-syscheck.c index 47f4347..f27804d 100755 --- a/src/win32/setup-syscheck.c +++ b/src/win32/setup-syscheck.c @@ -1,11 +1,11 @@ -/* @(#) $Id: setup-syscheck.c,v 1.5 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/setup-win.c b/src/win32/setup-win.c index ed54ee1..cee17ab 100755 --- a/src/win32/setup-win.c +++ b/src/win32/setup-win.c @@ -1,11 +1,11 @@ -/* @(#) $Id: setup-win.c,v 1.42 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation */ diff --git a/src/win32/ui.nsi b/src/win32/ui.nsi index 4073b59..277b96f 100644 --- a/src/win32/ui.nsi +++ b/src/win32/ui.nsi @@ -2,13 +2,13 @@ ; my template correctly. !include "MUI.nsh" -!define VERSION "1.5.1" +!define VERSION "2.5.1" !define NAME "Ossec HIDS" !define /date CDATE "%b %d %Y at %H:%M:%S" Name "${NAME} Windows Agent v${VERSION}" -BrandingText "Copyright (C) 2009 Trend Micro Inc." +BrandingText "Copyright (C) 2010 Trend Micro Inc." OutFile "win32ui.exe" diff --git a/src/win32/ui/common.c b/src/win32/ui/common.c index 7b16451..e385a36 100644 --- a/src/win32/ui/common.c +++ b/src/win32/ui/common.c @@ -1,11 +1,11 @@ -/* @(#) $Id: common.c,v 1.13 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/win32/ui/os_win32ui.c b/src/win32/ui/os_win32ui.c index 62a8e87..84f5010 100644 --- a/src/win32/ui/os_win32ui.c +++ b/src/win32/ui/os_win32ui.c @@ -1,11 +1,11 @@ -/* @(#) $Id: os_win32ui.c,v 1.10 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/win32/ui/os_win32ui.h b/src/win32/ui/os_win32ui.h index d7a7208..5bd608f 100644 --- a/src/win32/ui/os_win32ui.h +++ b/src/win32/ui/os_win32ui.h @@ -1,11 +1,11 @@ -/* @(#) $Id: os_win32ui.h,v 1.8 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or diff --git a/src/win32/ui/win32ui.rc b/src/win32/ui/win32ui.rc index e6cace7..5f49da6 100644 --- a/src/win32/ui/win32ui.rc +++ b/src/win32/ui/win32ui.rc @@ -1,11 +1,11 @@ -/* @(#) $Id: win32ui.rc,v 1.7 2009/06/24 18:53:11 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -28,11 +28,11 @@ CAPTION "About OSSEC" FONT 8, "MS Sans Serif" BEGIN DEFPUSHBUTTON "&Close",UI_ID_CLOSE,90,90,50,14 - GROUPBOX " Copyright (C) 2009 Trend Micro Inc.", + GROUPBOX " Copyright (C) 2010 Trend Micro Inc.", IDC_STATIC,7,7,245,82 CTEXT "This program is a free software; you can redistribute it" \ " and/or modify it under the terms of the GNU General" \ - " Public License (GPL) version 3 as published by the FSF" \ + " Public License (GPL) version 2 as published by the FSF" \ " - Free Software Foundation\r\n\r\n" \ "For more information, visit us online at http://www.ossec.net", IDC_STATIC,16,18,200,63 diff --git a/src/win32/win-files.txt b/src/win32/win-files.txt index c997258..530daa6 100755 --- a/src/win32/win-files.txt +++ b/src/win32/win-files.txt @@ -32,6 +32,8 @@ logcollector/read_mssql_log.c read_mssql_log.c logcollector/read_postgresql_log.c read_postgresql_log.c logcollector/read_djb_multilog.c read_djb_multilog.c logcollector/read_command.c read_command.c +logcollector/read_fullcommand.c read_fullcommand.c +logcollector/read_multiline.c read_multiline.c syscheckd/config.c syscheckd-config.c syscheckd/create_db.c create_db.c syscheckd/run_check.c run_check.c @@ -39,6 +41,7 @@ syscheckd/run_realtime.c run_realtime.c syscheckd/syscheck.c syscheck.c syscheckd/syscheck.h syscheck.h syscheckd/win-registry.c win-registry.c +syscheckd/seechanges.c seechanges.c rootcheck rootcheck external/zlib-1.2.3/zlib.h zlib.h external/zlib-1.2.3/zconf.h zconf.h diff --git a/src/win32/win_agent.c b/src/win32/win_agent.c index b631a9c..0c01224 100755 --- a/src/win32/win_agent.c +++ b/src/win32/win_agent.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win_agent.c,v 1.56 2009/12/01 20:27:01 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or @@ -361,6 +361,7 @@ int SendMSG(int queue, char *message, char *locmsg, char loc) cu_time = time(0); + #ifndef ONEWAY /* Check if the server has responded */ if((cu_time - available_server) > (NOTIFY_TIME - 180)) { @@ -479,7 +480,12 @@ int SendMSG(int queue, char *message, char *locmsg, char loc) } } } - + #else + if(0) + { + } + #endif + /* Send notification */ else if((cu_time - __win32_curr_time) > (NOTIFY_TIME - 200)) diff --git a/src/win32/win_service.c b/src/win32/win_service.c index 749abad..d17d7b8 100755 --- a/src/win32/win_service.c +++ b/src/win32/win_service.c @@ -1,11 +1,11 @@ -/* @(#) $Id: win_service.c,v 1.13 2009/06/24 18:53:10 dcid Exp $ */ +/* @(#) $Id$ */ /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * * This program is a free software; you can redistribute it * and/or modify it under the terms of the GNU General Public - * License (version 3) as published by the FSF - Free Software + * License (version 2) as published by the FSF - Free Software * Foundation. * * License details at the LICENSE file included with OSSEC or -- 1.7.10.4