1 /* @(#) $Id: ./src/analysisd/alerts/exec.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
13 /* Basic e-mailing operations */
20 #include "active-response.h"
22 #include "os_net/os_net.h"
23 #include "os_regex/os_regex.h"
24 #include "os_execd/execd.h"
26 #include "eventinfo.h"
31 void OS_Exec(int *execq, int *arq, Eventinfo *lf, active_response *ar)
33 char exec_msg[OS_SIZE_1024 +1];
39 if(lf->srcip && (ar->ar_cmd->expect & SRCIP))
41 if(strncmp(lf->srcip, "::ffff:", 7) == 0)
50 /* Checking if IP is to ignored */
53 if(OS_IPFoundList(ip, Config.white_list))
59 /* Checking if it is a hostname */
60 if(Config.hostname_white_list)
65 srcip_size = strlen(ip);
67 wl = Config.hostname_white_list;
70 if(OSMatch_Execute(ip, srcip_size, *wl))
82 /* Getting username */
83 if(lf->dstuser && (ar->ar_cmd->expect & USERNAME))
93 /* active response on the server.
94 * The response must be here if the ar->location is set to AS
95 * or the ar->location is set to local (REMOTE_AGENT) and the
96 * event location is from here.
98 if((ar->location & AS_ONLY) ||
99 ((ar->location & REMOTE_AGENT) && (lf->location[0] != '(')) )
101 if(!(Config.ar & LOCAL_AR))
104 snprintf(exec_msg, OS_SIZE_1024,
105 "%s %s %s %d.%ld %d %s",
111 lf->generated_rule->sigid,
114 if(OS_SendUnix(*execq, exec_msg, 0) < 0)
116 merror("%s: Error communicating with execd.", ARGV0);
121 /* Active response to the forwarder */
122 else if((Config.ar & REMOTE_AR))
125 /*If lf->location start with a ( was generated by remote agent and its ID is included in lf->location
126 if missing then it must of been generated by the local analysisd so prepend a false id tag */
127 if(lf->location[0] == '(') {
128 snprintf(exec_msg, OS_SIZE_1024,
129 "%s %c%c%c %s %s %s %s %d.%ld %d",
131 (ar->location & ALL_AGENTS)?ALL_AGENTS_C:NONE_C,
132 (ar->location & REMOTE_AGENT)?REMOTE_AGENT_C:NONE_C,
133 (ar->location & SPECIFIC_AGENT)?SPECIFIC_AGENT_C:NONE_C,
134 ar->agent_id != NULL? ar->agent_id: "(null)",
140 lf->generated_rule->sigid);
142 snprintf(exec_msg, OS_SIZE_1024,
143 "(local_source) %s %c%c%c %s %s %s %s %d.%ld %d",
145 (ar->location & ALL_AGENTS)?ALL_AGENTS_C:NONE_C,
146 (ar->location & REMOTE_AGENT)?REMOTE_AGENT_C:NONE_C,
147 (ar->location & SPECIFIC_AGENT)?SPECIFIC_AGENT_C:NONE_C,
148 ar->agent_id != NULL? ar->agent_id: "(null)",
154 lf->generated_rule->sigid);
157 if((rc = OS_SendUnix(*arq, exec_msg, 0)) < 0)
159 if(rc == OS_SOCKBUSY)
161 merror("%s: AR socket busy.", ARGV0);
165 merror("%s: AR socket error (shutdown?).", ARGV0);
167 merror("%s: Error communicating with ar queue (%d).", ARGV0, rc);