Skip to contentSkip to conversation

Support for auditing on the actions of a not-yet-executed process.

PATCH In review Peter Moody 3 participants 4 messages Aug 23, 2012 – May 2, 2014

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Support for auditing on the actions of a not-yet-executed process.

eg:

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe=/bin/bash -F success=1

to see instances of /bin/bash opening a non-local socket. Or

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe_children=/bin/bash -F success=1

to instances of /bin/bash, and any descendant processes, opening a non local socket.

proposed https://www.redhat.com/archives/linux-audit/2012-June/msg00002.html
and it seemed like there was interest.

---
 trunk/lib/errormsg.h |    2 +-
 trunk/lib/fieldtab.h |    2 ++
 trunk/lib/libaudit.c |   11 +++++++++++
 trunk/lib/libaudit.h |    7 ++++++-
 4 files changed, 20 insertions(+), 2 deletions(-)
trunk/lib/errormsg.h +1 -1
index 4d996d5..cd595ec 100644
@@ -51,7 +51,7 @@ static const struct msg_tab err_msgtab[] = {
     { -15,    2,    "-F unknown errno -"},
     { -16,    2,    "-F unknown file type - " },
     { -17,    1,    "can only be used with exit and entry filter list" },
-    { -18,    1,    "" }, // Unused
+    { -18,    1,    "only takes = operator" },
     { -19,    0,    "Key field needs a watch or syscall given prior to it" },
     { -20,    2,    "-F missing value after operation for" },
     { -21,    2,    "-F value should be number for" },
trunk/lib/fieldtab.h +2 -0
index c0432cc..245b541 100644
@@ -66,3 +66,5 @@ _S(AUDIT_ARG3,         "a3"           )
 _S(AUDIT_FILTERKEY,    "key"          )
 
 _S(AUDIT_FIELD_COMPARE, "field_compare" )
+_S(AUDIT_EXE,          "exe"          )
+_S(AUDIT_EXE_CHILDREN, "exe_children" )
trunk/lib/libaudit.c +11 -0
index 20eaf5f..06eed86 100644
@@ -1400,6 +1400,17 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,
 			else 
 				return -21;
 			break;
+		case AUDIT_EXE_CHILDREN:
+		case AUDIT_EXE:
+		{
+			struct stat buf;
+			if ((stat(v, &buf)) < 0)
+				return -2;
+			if (op != AUDIT_EQUAL)
+				return -18;
+			rule->values[rule->field_count] = (unsigned long)buf.st_ino;
+		}
+			break;
 		case AUDIT_DEVMAJOR...AUDIT_INODE:
 		case AUDIT_SUCCESS:
 			if (flags != AUDIT_FILTER_EXIT)
trunk/lib/libaudit.h +6 -1
index 89dd588..2c8a802 100644
@@ -243,6 +243,12 @@ extern "C" {
 #ifndef AUDIT_FIELD_COMPARE
 #define AUDIT_FIELD_COMPARE 111
 #endif
+#ifndef AUDIT_EXE
+#define AUDIT_EXE 112
+#endif
+#ifndef AUDIT_EXE_CHILDREN
+#define AUDIT_EXE_CHILDREN 113
+#endif
 
 #ifndef AUDIT_COMPARE_UID_TO_OBJ_UID
 #define AUDIT_COMPARE_UID_TO_OBJ_UID   1
@@ -524,4 +530,3 @@ extern void audit_rule_free_data(struct audit_rule_data *rule);
 #endif
 
 #endif
-
Signature · 1 line
1.7.7.3
#1 lore raw
Quoted 5 lines · Peter Moody

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe=/bin/bash -F success=1

to see instances of /bin/bash opening a non-local socket. Or

Quoted 8 lines

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe_children=/bin/bash -F success=1

to instances of /bin/bash, and any descendant processes, opening a non local socket.

proposed https://www.redhat.com/archives/linux-audit/2012-June/msg00002.html
and it seemed like there was interest.

Yeah, another use case might be:

-a always,exit -F dir=/watched-dir -F perms=r -F exe=/usr/bin/scp

So that you can see files being transferred away from a directory that you care about. Of course you wouldn't have the address unless you also catch the connect or maybe execve.

I'll merge the user space code when this is accepted into the kernel.

Thanks,
-Steve

#2 lore raw
In reply to Peter Moody
Quoted 9 lines · Peter Moody

eg:

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe=/bin/bash -F success=1

to see instances of /bin/bash opening a non-local socket. Or

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe_children=/bin/bash -F success=1

to instances of /bin/bash, and any descendant processes, opening a non local socket.

In addition to these sample rules, do you have a command or script to trigger it?

Quoted 80 lines

proposed https://www.redhat.com/archives/linux-audit/2012-June/msg00002.html
and it seemed like there was interest.

---
 trunk/lib/errormsg.h |    2 +-
 trunk/lib/fieldtab.h |    2 ++
 trunk/lib/libaudit.c |   11 +++++++++++
 trunk/lib/libaudit.h |    7 ++++++-
 4 files changed, 20 insertions(+), 2 deletions(-)
trunk/lib/errormsg.h +1 -1
index 4d996d5..cd595ec 100644
@@ -51,7 +51,7 @@ static const struct msg_tab err_msgtab[] = {
     { -15,    2,    "-F unknown errno -"},
     { -16,    2,    "-F unknown file type - " },
     { -17,    1,    "can only be used with exit and entry filter list" },
-    { -18,    1,    "" }, // Unused
+    { -18,    1,    "only takes = operator" },
     { -19,    0,    "Key field needs a watch or syscall given prior to it" },
     { -20,    2,    "-F missing value after operation for" },
     { -21,    2,    "-F value should be number for" },
trunk/lib/fieldtab.h +2 -0
index c0432cc..245b541 100644
@@ -66,3 +66,5 @@ _S(AUDIT_ARG3,         "a3"           )
 _S(AUDIT_FILTERKEY,    "key"          )
 
 _S(AUDIT_FIELD_COMPARE, "field_compare" )
+_S(AUDIT_EXE,          "exe"          )
+_S(AUDIT_EXE_CHILDREN, "exe_children" )
trunk/lib/libaudit.c +11 -0
index 20eaf5f..06eed86 100644
@@ -1400,6 +1400,17 @@ int audit_rule_fieldpair_data(struct audit_rule_data **rulep, const char *pair,
 			else 
 				return -21;
 			break;
+		case AUDIT_EXE_CHILDREN:
+		case AUDIT_EXE:
+		{
+			struct stat buf;
+			if ((stat(v, &buf)) < 0)
+				return -2;
+			if (op != AUDIT_EQUAL)
+				return -18;
+			rule->values[rule->field_count] = (unsigned long)buf.st_ino;
+		}
+			break;
 		case AUDIT_DEVMAJOR...AUDIT_INODE:
 		case AUDIT_SUCCESS:
 			if (flags != AUDIT_FILTER_EXIT)
trunk/lib/libaudit.h +6 -1
index 89dd588..2c8a802 100644
@@ -243,6 +243,12 @@ extern "C" {
 #ifndef AUDIT_FIELD_COMPARE
 #define AUDIT_FIELD_COMPARE 111
 #endif
+#ifndef AUDIT_EXE
+#define AUDIT_EXE 112
+#endif
+#ifndef AUDIT_EXE_CHILDREN
+#define AUDIT_EXE_CHILDREN 113
+#endif
 
 #ifndef AUDIT_COMPARE_UID_TO_OBJ_UID
 #define AUDIT_COMPARE_UID_TO_OBJ_UID   1
@@ -524,4 +530,3 @@ extern void audit_rule_free_data(struct audit_rule_data *rule);
 #endif
 
 #endif
-
Signature · 1 line
1.7.7.3

- RGB

--
Richard Guy Briggs <[email protected]>
Senior Software Engineer, Kernel Security, AMER ENG Base Operating Systems, Red Hat Remote, Ottawa, Canada
Voice: +1.647.777.2635, Internal: (81) 32635, Alt: +1.613.693.0684x3545

#3 lore raw
Quoted 5 lines · On Fri, 2 May 2014 10:49:56 -0400 Richard Guy Briggs <[email protected]> wrote:
Quoted 5 lines

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe=/bin/bash -F success=1

to see instances of /bin/bash opening a non-local socket. Or

Quoted 8 lines
Quoted 5 lines

-a exit,always -F arch=b64 -S socket -F 'a0!=1' -F exe_children=/bin/bash -F success=1

to instances of /bin/bash, and any descendant processes, opening a non local socket.

In addition to these sample rules, do you have a command or script to trigger it?

You should be able to load a rule like this:

-a always,exit -F dir=/tmp -F exe=/usr/sbin/touch -F key=test

Then run

touch /tmp/test

then ausearch --start recent -k test

-Steve