what you don't know can hurt you
Home Files News &[SERVICES_TAB]About Contact Add New

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
SHA-256 | e7f2e3bc323b328a675b4a4435ca103b1eb24ea40133b716e01a44446063df6e

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);
Login or Register to add favorites

File Archive:

April 2024

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

Top Authors In Last 30 Days

File Tags

Systems

packet storm

© 2022 Packet Storm. All rights reserved.

Services
Security Services
Hosting By
Rokasec
close