summaryrefslogtreecommitdiffstats
path: root/runtime/tests/shellsnoop/README
blob: ce37a2db8e7a2f89ff49014a9cc486dd84525680 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
Sample probe.

To build, edit the path in buildit and the addresses in struct dtr_probes
in dtr.c Then "source buildit"

This is a translation of on an old dtr probe:

# shellsnoop.probe - snoop shell execution as it occurs.
# clone of dtrace shellsnoop example

global {
  long @pids[long];
}

probe do_execve:entry {
  char __user *vstr;
  char str[256];
  int len;

  /* watch shells only */
  /* FIXME: detect more shells, like csh, tcsh, zsh */

  if (!strcmp(current->comm,"bash") || !strcmp(current->comm,"sh") || !strcmp(current->comm, "zsh")
      || !strcmp(current->comm, "tcsh") || !strcmp(current->comm, "pdksh"))
    {
      dlog ("%d\t%d\t%d\t%s ", current->uid, current->pid, current->parent->pid, filename);
      @pids[current->pid] = 1;

      /* print out argv, ignoring argv[0] */
      if (argv) argv++;
      while (argv != NULL)
        {
          if (get_user (vstr, argv))
            break;
          if (!vstr)
            break;
          len = dtr_strncpy_from_user(str, vstr, 256);
          str[len] = 0;
          printk ("%s ", str);
          argv++;
        }
      printk ("\n");
    }
}

# use filp_open because copy_from_user not needed there
probe filp_open:entry {
  if (@pids[current->pid])
    dlog ("%d\t%d\t%s\tO %s\n", current->pid, current->parent->pid, current->comm, filename);
}

probe sys_read:entry {
  if (@pids[current->pid])
    dlog ("%d\t%d\t%s\tR %d\n", current->pid, current->parent->pid, current->comm, fd);
}

probe sys_write:entry {
  size_t len;
  char str[256];
  if (@pids[current->pid])
    {
      if (count < 64) len = count;
      else len = 64;
      if (len = dtr_strncpy_from_user(str, buf, len)) {
        str[len] = 0;
        dlog ("%d\t%d\t%s\tW %s\n", current->pid, current->parent->pid, current->comm, str);
        }
    }
}