Skip to content

Commit

Permalink
added session to the syslog output
Browse files Browse the repository at this point in the history
  • Loading branch information
mike authored and mzupan committed Oct 4, 2010
1 parent 8a4b244 commit 185af50
Showing 1 changed file with 29 additions and 22 deletions.
51 changes: 29 additions & 22 deletions bash-paranoia-curl.patch
@@ -1,6 +1,6 @@
diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
--- bash-3.2/bashhist.c 2010-04-20 15:11:37.000000000 -0400
+++ bash-3.2-curl/bashhist.c 2010-04-20 15:10:47.000000000 -0400
--- bash-3.2/bashhist.c 2010-10-04 13:23:59.489836206 -0400
+++ bash-3.2-curl/bashhist.c 2010-10-04 13:19:34.962930127 -0400
@@ -50,6 +50,12 @@
#include <glob/glob.h>
#include <glob/strmatch.h>
Expand All @@ -14,9 +14,27 @@ diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
#if defined (READLINE)
# include "bashline.h"
extern int rl_done, rl_dispatching; /* should really include readline.h */
@@ -864,6 +870,50 @@ int paranoia_log_through_utmp(const char
@@ -860,10 +866,56 @@ int paranoia_log_through_utmp(const char
strncpy(ut->ut_host, "system", 7);

ut->ut_host[sizeof(ut->ut_host) - 1] = '\0';
+
+ // get a random session
+ if (strlen(sessionStr) == 0) {
+ srand(time(0));
+ static const char text[] = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ int i, len = 81;
+ for ( i = 0; i < len; ++i ) {
+ sessionStr[i] = text[rand() % (sizeof text - 1)];
+ }
+ sessionStr[80] = '\0';
+ }

openlog("bash", LOG_NDELAY, LOG_DAEMON);
syslog(LOG_NOTICE, "user: %s as %s from ip: %s:%s execs: '%s'\n", ut->ut_user,pw->pw_name, ut->ut_host, ut->ut_line,line);
- syslog(LOG_NOTICE, "user: %s as %s from ip: %s:%s execs: '%s'\n", ut->ut_user,pw->pw_name, ut->ut_host, ut->ut_line,line);
+ syslog(LOG_NOTICE, "user: %s as %s from ip: %s:%s session: %s execs: '%s'\n", ut->ut_user,pw->pw_name, ut->ut_host, ut->ut_line, sessionStr, line);
closelog();
+
+ // do the curl thing now
Expand All @@ -34,18 +52,6 @@ diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
+ char hostname[256];
+ gethostname (hostname, 255);
+
+ if (strlen(sessionStr) == 0) {
+ srand(time(0));
+ static const char text[] = "abcdefghijklmnopqrstuvwxyz"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
+
+ int i, len = 81;
+ for ( i = 0; i < len; ++i ) {
+ sessionStr[i] = text[rand() % (sizeof text - 1)];
+ }
+ sessionStr[80] = '\0';
+ }
+
+ // doing the postfield now
+ char postfield[5000] = "";
+ sprintf(&postfield[strlen(postfield)], "user_login=%s&user_run=%s&ip=%s&session=%s&command=%s", ut->ut_user,pw->pw_name,ut->ut_host,sessionStr,line);
Expand All @@ -54,7 +60,8 @@ diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postfield);
+ curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, (long)strlen(postfield));
+ curl_easy_setopt(curl, CURLOPT_TIMEOUT, (long)2);
+
+ curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, NULL);
+
+ // if you want to check response code
+ res = curl_easy_perform(curl);
+
Expand All @@ -65,7 +72,7 @@ diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
return 0;
}

@@ -881,4 +931,48 @@ int paranoia_log (const char *line)
@@ -881,4 +933,48 @@ int paranoia_log (const char *line)
return 0;
}
#endif
Expand Down Expand Up @@ -115,8 +122,8 @@ diff -rupN bash-3.2/bashhist.c bash-3.2-curl/bashhist.c
+
#endif /* HISTORY */
diff -rupN bash-3.2/bashhist.h bash-3.2-curl/bashhist.h
--- bash-3.2/bashhist.h 2010-04-20 15:11:37.000000000 -0400
+++ bash-3.2-curl/bashhist.h 2010-03-08 12:44:34.000000000 -0500
--- bash-3.2/bashhist.h 2010-10-04 13:23:59.491837735 -0400
+++ bash-3.2-curl/bashhist.h 2010-10-03 22:41:21.763444166 -0400
@@ -76,4 +76,10 @@ int paranoia_log_through_utmp(const char
int paranoia_log (const char *line);
#endif
Expand All @@ -130,7 +137,7 @@ diff -rupN bash-3.2/bashhist.h bash-3.2-curl/bashhist.h
#endif /* _BASHHIST_H_ */
diff -rupN bash-3.2/externs.h bash-3.2-curl/externs.h
--- bash-3.2/externs.h 2006-07-27 21:40:49.000000000 -0400
+++ bash-3.2-curl/externs.h 2010-03-08 12:44:40.000000000 -0500
+++ bash-3.2-curl/externs.h 2010-10-03 22:41:21.765444509 -0400
@@ -119,12 +119,12 @@ extern char *mk_msgstr __P((char *, int
extern char *localeexpand __P((char *, int, int, int, int *));

Expand All @@ -151,7 +158,7 @@ diff -rupN bash-3.2/externs.h bash-3.2-curl/externs.h
extern int find_string_in_alist __P((char *, STRING_INT_ALIST *, int));
diff -rupN bash-3.2/Makefile.in bash-3.2-curl/Makefile.in
--- bash-3.2/Makefile.in 2006-08-17 14:03:35.000000000 -0400
+++ bash-3.2-curl/Makefile.in 2010-03-08 13:24:15.000000000 -0500
+++ bash-3.2-curl/Makefile.in 2010-10-03 22:41:21.766442341 -0400
@@ -433,7 +433,7 @@ OBJECTS = shell.o eval.o y.tab.o genera
trap.o input.o unwind_prot.o pathexp.o sig.o test.o version.o \
alias.o array.o arrayfunc.o braces.o bracecomp.o bashhist.o \
Expand Down

0 comments on commit 185af50

Please sign in to comment.