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:

June 2024

  • Su
  • Mo
  • Tu
  • We
  • Th
  • Fr
  • Sa
  • 1
    Jun 1st
    0 Files
  • 2
    Jun 2nd
    0 Files
  • 3
    Jun 3rd
    18 Files
  • 4
    Jun 4th
    21 Files
  • 5
    Jun 5th
    0 Files
  • 6
    Jun 6th
    57 Files
  • 7
    Jun 7th
    6 Files
  • 8
    Jun 8th
    0 Files
  • 9
    Jun 9th
    0 Files
  • 10
    Jun 10th
    12 Files
  • 11
    Jun 11th
    27 Files
  • 12
    Jun 12th
    38 Files
  • 13
    Jun 13th
    16 Files
  • 14
    Jun 14th
    14 Files
  • 15
    Jun 15th
    0 Files
  • 16
    Jun 16th
    0 Files
  • 17
    Jun 17th
    16 Files
  • 18
    Jun 18th
    26 Files
  • 19
    Jun 19th
    0 Files
  • 20
    Jun 20th
    0 Files
  • 21
    Jun 21st
    0 Files
  • 22
    Jun 22nd
    0 Files
  • 23
    Jun 23rd
    0 Files
  • 24
    Jun 24th
    0 Files
  • 25
    Jun 25th
    0 Files
  • 26
    Jun 26th
    0 Files
  • 27
    Jun 27th
    0 Files
  • 28
    Jun 28th
    0 Files
  • 29
    Jun 29th
    0 Files
  • 30
    Jun 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