what you don't know can hurt you

sh-log+access.patch

sh-log+access.patch
Posted Jan 21, 2000
Authored by Omachonu Ogali | Site tribune.intranova.net

Patch to sh(1) that adds denying and logging features (user ID, username, process ID, parent process ID, parent process name, login name). Checks against /etc/sh.deny and if the parent/calling program is listed then execution is halted and logged.

systems | unix
MD5 | 7a86e69eb161d68e9db98b7e90b253de

sh-log+access.patch

Change Mirror Download
--- main.c.orig  Wed Jan 19 08:25:24 2000
+++ main.c Wed Jan 19 08:28:20 2000
@@ -54,7 +54,10 @@
#include <unistd.h>
#include <fcntl.h>
#include <locale.h>
-
+#include <syslog.h>
+#include <string.h>
+#include <pwd.h>
+#include <sys/types.h>

#include "shell.h"
#include "main.h"
@@ -107,6 +110,141 @@
struct stackmark smark;
volatile int state;
char *shinit;
+ char pidfile[256];
+ char pidname[256];
+ char accessline[4096];
+ char *username;
+ int ppid;
+ int fd;
+ int uid;
+ FILE *flist;
+ struct passwd *pw;
+
+ /*
+ * Start of sh-log+access patch
+ * - Deny list is hardcoded to /etc/sh.deny
+ * - Logs process ID, parent process ID, parent process name,
+ * user ID, username, and login name to syslog.
+ * - Omachonu Ogali <oogali@tribune.intranova.net>
+ */
+
+ /*
+ * Start of pid resolving code.
+ * - Omachonu Ogali <oogali@tribune.intranova.net>
+ */
+
+ if (!(ppid = getppid())) {
+ perror("getppid()");
+ return -1;
+ }
+
+ fd = 0;
+ bzero(pidfile, sizeof(pidfile));
+
+ snprintf(pidfile, sizeof(pidfile), "/proc/%d/cmdline", ppid);
+ if ((fd = open(pidfile, O_RDONLY)) == -1) {
+ /*
+ * We can't return an error and die because we
+ * essentially break /bin/sh until /proc is mounted,
+ * so we're just going to copy 'unknown' and get over
+ * with it. (Still have to let the user know what's
+ * going on though).
+ */
+
+ perror("open()");
+ strncpy(pidname, "UNKNOWN", sizeof(pidname));
+ } else {
+ read(fd, pidname, sizeof(pidname));
+ close(fd);
+
+ /*
+ * Workaround for certain BSD procfs filesystems.
+ */
+
+ if (pidname[strlen(pidname) - 1] == 0x0a) {
+ pidname[strlen(pidname) - 1] = NULL;
+ }
+ }
+
+ /*
+ * End of pid resolving code.
+ */
+
+ openlog("sh", LOG_CONS || LOG_PID, LOG_AUTH);
+
+ /*
+ * Start of uid resolving code.
+ */
+
+ if ((uid = getuid()) < 0) {
+ perror("getuid()");
+ return -1;
+ }
+
+ if ((pw = getpwuid(uid)) == NULL) {
+ perror("getpwuid()");
+ return -1;
+ }
+
+ /*
+ * End of uid resolving code
+ */
+
+ if ((username = getlogin()) == NULL) {
+ perror("getlogin()");
+ return -1;
+ }
+
+ /* Access list to prevent unwanted execution of sh, yes we could
+ * use permissions, but that wouldn't help against compromises,
+ * since most of the times root access is gained.
+ * - Omachonu Ogali <oogali@tribune.intranova.net>
+ */
+
+ if ((flist = fopen("/etc/sh.deny", "r")) == NULL) {
+ perror("fopen(/etc/sh.deny)");
+ return -1;
+ }
+
+ while (fgets(accessline, sizeof(accessline), flist) != NULL) {
+ if (accessline[strlen(accessline) - 1] == 0x0a) {
+ accessline[strlen(accessline) - 1] = NULL;
+ }
+
+ if (strcmp(accessline, pidname) == 0) {
+ syslog(LOG_WARNING || LOG_ERR, "rejected pid %d (%s), uid %d (%s/%s)\n", ppid, pidname, uid, pw->pw_name, username);
+ printf("rejected pid %d (%s), uid %d (%s/%s)\n", ppid, pidname, uid, pw->pw_name, username);
+ closelog();
+ return -1;
+ }
+ }
+
+ if (fclose(flist) < 0) {
+ perror("fclose(/etc/sh.deny)");
+ return -1;
+ }
+
+ /*
+ * End of access list code
+ */
+
+ /*
+ * When spawned, we log our pid and parent pid to syslog
+ * in case we need it to find the origin of an intrusion.
+ * - Omachonu Ogali <oogali@tribune.intranova.net>
+ */
+
+ syslog(LOG_WARNING, "spawned by pid %d (%s), uid %d (%s/%s)\n", ppid,
+pidname, uid, pw->pw_name, username);
+ closelog();
+
+ /*
+ * End of parent logging code
+ */
+
+ /*
+ * End of sh-log+access patch
+ */

#if PROFILE
monitor(4, etext, profile_buf, sizeof profile_buf, 50);

Comments

RSS Feed Subscribe to this comment feed

No comments yet, be the first!

Login or Register to post a comment

File Archive:

March 2019

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Mar 1st
    15 Files
  • 2
    Mar 2nd
    5 Files
  • 3
    Mar 3rd
    3 Files
  • 4
    Mar 4th
    25 Files
  • 5
    Mar 5th
    20 Files
  • 6
    Mar 6th
    16 Files
  • 7
    Mar 7th
    17 Files
  • 8
    Mar 8th
    12 Files
  • 9
    Mar 9th
    3 Files
  • 10
    Mar 10th
    4 Files
  • 11
    Mar 11th
    23 Files
  • 12
    Mar 12th
    12 Files
  • 13
    Mar 13th
    12 Files
  • 14
    Mar 14th
    19 Files
  • 15
    Mar 15th
    12 Files
  • 16
    Mar 16th
    3 Files
  • 17
    Mar 17th
    1 Files
  • 18
    Mar 18th
    15 Files
  • 19
    Mar 19th
    22 Files
  • 20
    Mar 20th
    14 Files
  • 21
    Mar 21st
    16 Files
  • 22
    Mar 22nd
    17 Files
  • 23
    Mar 23rd
    1 Files
  • 24
    Mar 24th
    1 Files
  • 25
    Mar 25th
    16 Files
  • 26
    Mar 26th
    21 Files
  • 27
    Mar 27th
    0 Files
  • 28
    Mar 28th
    0 Files
  • 29
    Mar 29th
    0 Files
  • 30
    Mar 30th
    0 Files
  • 31
    Mar 31st
    0 Files

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2019 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close