Last active
December 11, 2015 18:38
-
-
Save wuyongzheng/4642619 to your computer and use it in GitHub Desktop.
Log bash commands in another file. Used for my honeypot. Remember to pre-create the file and chown. Better yet, set append-only.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/bashhist.c b/bashhist.c | |
index 7240a5b..63ec12a 100644 | |
--- a/bashhist.c | |
+++ b/bashhist.c | |
@@ -792,6 +792,26 @@ static void | |
really_add_history (line) | |
char *line; | |
{ | |
+ static int inited = 0; | |
+ static FILE *mylogfile = NULL; | |
+ | |
+ if (!inited) { | |
+ char buff[256]; | |
+ inited = 1; | |
+ snprintf(buff, sizeof(buff), "/var/log/bashhist/%s.log", getenv("USER")); | |
+ mylogfile = fopen(buff, "a"); | |
+ } | |
+ if (mylogfile != NULL) { | |
+ time_t t1; | |
+ struct tm t2; | |
+ char buff[16]; | |
+ | |
+ time(&t1); | |
+ localtime_r(&t1, &t2); | |
+ strftime(buff, sizeof(buff), "%y%m%d-%H%M%S", &t2); | |
+ fprintf(mylogfile, "%d\t%s\t%s\n", getpid(), buff, line); | |
+ fflush(mylogfile); | |
+ } | |
+ | |
hist_last_line_added = 1; | |
hist_last_line_pushed = 0; | |
add_history (line); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment