home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / c / cops_104.zip / cops_104 / perl / prl.patch < prev    next >
Text File  |  1992-03-10  |  10KB  |  314 lines

  1. > > The 4.0.3 patch was, as far as I know, never released, and it certainly wasn't
  2. > > rolled into 4.1.1. The above was the last I heard about the bug until I
  3. > > complained again after we installed 4.1.1.
  4.  
  5. >   Hmm.  I looked up the bug, and found some proposed fixes by dan
  6. > trinkle of purdue, but I'm not sure that they really do anything but
  7. > slow the attackers down.  Again, I'll look at this and get back to you.
  8.  
  9. There's a bug in Dan's patch which allows a cracker to get the maps iff the last
  10. legitimate request to ypserv was to the same map as the map the cracker is
  11. requesting. I understand from a dark hint in one of Brad Powell's messages that
  12. this problem was discovered by Sun Engineering.
  13.  
  14. Apart from that, Dan's patch should block any attacks apart from
  15. host spoofing ones. Of course, if the attacker is clever enough to spoof hosts,
  16. you will have to `take up arms against a sea of troubles'.
  17.  
  18. >   Indeed.  It's unbelievable that you can write to the things so easily
  19. > and make the machine forget it's identity or something equally obnoxious.
  20. > It's interesting to me that the system crackers seem to be getting
  21. > more sophisticated; I'm wondering what, if anything, computer manufacturers
  22. > will be doing with this?  I suppose that there will always be hosts that
  23. > are poorly set up regardless of what you do.  I'd like to see something
  24. > like the self-cleaning oven paridigm -- the more you use your system,
  25. > the more secure it gets :-)
  26.  
  27. The getty hack was demonstrated to us by a student here (a German). I don't
  28. know how well-know the problem is in German {h,cr}acker circles. As far as
  29. self-cleaning goes, I think systems are more like colour CRT's than
  30. self-cleaning ovens. They positively *attract* dirt and grime.
  31.  
  32. A small bunch of patches for pcops are attached.
  33.  
  34. The things changed are:
  35.     1) '_' added to the allowed characters in login names & group names
  36.     2) The pattern for allowed login and group names made the same
  37.     3) Search for rexd rather than rexecd in /etc/inetd.conf. Perhaps
  38.        rexecd is also a security hole, but rexd(8)/on(1) is a gaping
  39.        cavernous one.
  40.     4) Assorted hacking to get suid checking to work sort-of portably.
  41.        The test for NFS fs's is:
  42.                ($dev < 0 || $dev >= 16384)
  43.        Ultrix and AIX use large, rather than -'ve major devs for NFS mounts.
  44.        Apart from the added test and the argument parsing, the code in
  45.        suidfind.pl was generated by find2perl.
  46.        Using the -xdev test, and a list of the local mounts in /etc/fstab
  47.        is probably a better strategy than the above hack. Ultrix find
  48.        doesn't have -xdev, either, so I think find2perl is the way to go
  49.        on this.
  50.  
  51. regards,
  52.  
  53. peter
  54.  
  55. *** group.chk.orig    Sun Jun 23 15:35:27 1991
  56. --- group.chk    Fri Dec  6 13:42:55 1991
  57. ***************
  58. *** 92,98 ****
  59.       $groups{$group}++;   # keep track of dups
  60.       print "$W line $., does not have 4 fields:\n\t$_" if (@_ != 4);
  61.       print "$W line $., nonalphanumeric group name:\n\t$_"
  62. !         if $group !~ /^[A-Za-z0-9-]+$/;
  63.       if ($pass && $pass ne '*') {
  64.           if ( ! $C2 || $yp ) {
  65.           print "$W line $., group has password:\n\t$_"
  66. --- 92,98 ----
  67.       $groups{$group}++;   # keep track of dups
  68.       print "$W line $., does not have 4 fields:\n\t$_" if (@_ != 4);
  69.       print "$W line $., nonalphanumeric group name:\n\t$_"
  70. !         if $group !~ /^[_A-Za-z0-9-]+$/;
  71.       if ($pass && $pass ne '*') {
  72.           if ( ! $C2 || $yp ) {
  73.           print "$W line $., group has password:\n\t$_"
  74. *** passwd.chk.orig    Sun Jun 23 15:35:45 1991
  75. --- passwd.chk    Fri Dec  6 13:42:53 1991
  76. ***************
  77. *** 93,99 ****
  78.       $users{$user}++;    # keep track of dups
  79.       print "$W line $., does not have 7 fields:\n\t$_" if (@_ != 7);
  80.       print "$W line $., nonalphanumeric username:\n\t$_"
  81. !         if $user !~ /^[A-Za-z0-9]+$/;
  82.       print "$W line $., numeric username:\n\t$_"
  83.           if $user =~ /^\d+$/;
  84.       print "$W line $., login name > 8 characters:\n\t$_"
  85. --- 93,99 ----
  86.       $users{$user}++;    # keep track of dups
  87.       print "$W line $., does not have 7 fields:\n\t$_" if (@_ != 7);
  88.       print "$W line $., nonalphanumeric username:\n\t$_"
  89. !         if $user !~ /^[_A-Za-z0-9-]+$/;
  90.       print "$W line $., numeric username:\n\t$_"
  91.           if $user =~ /^\d+$/;
  92.       print "$W line $., login name > 8 characters:\n\t$_"
  93. *** misc.chk.orig    Sun Jun 23 15:35:35 1991
  94. --- misc.chk    Tue Dec  3 14:09:43 1991
  95. ***************
  96. *** 58,64 ****
  97.            ( -f '/etc/servers' && '/etc/servers') ||
  98.            'BOGUS';
  99.       }
  100. ! $rexd="rexecd";
  101.   
  102.   # tmp and target file (for tftp test)
  103.   $target="/etc/motd";
  104. --- 58,64 ----
  105.            ( -f '/etc/servers' && '/etc/servers') ||
  106.            'BOGUS';
  107.       }
  108. ! $rexd="rexd";
  109.   
  110.   # tmp and target file (for tftp test)
  111.   $target="/etc/motd";
  112. *** suid.chk.orig    Fri Aug 30 17:17:49 1991
  113. --- suid.chk    Tue Dec  3 16:51:41 1991
  114. ***************
  115. *** 43,55 ****
  116.   $usage = "Usage: $0 [-n] [-s secure_dir] [starting_directory]\n";
  117.   require 'getopts.pl';
  118.   # Process the command args; Either specify verbose or an alternate config file:
  119. ! die $usage unless &`Getopts('ns:');
  120.   
  121.   $suid_dir = $'SECURE || '.';
  122. ! if (defined($opt_s)) { $suid_dir = $opt_s; }
  123.   
  124.   # Do NFS stuff?  Yes unless opt:
  125. ! if (defined($opt_n)) { $skip_nfs = $opt_n; }
  126.   else { $skip_nfs = 0; }
  127.   
  128.   $STOP="$suid_dir/suid.stop";
  129. --- 43,55 ----
  130.   $usage = "Usage: $0 [-n] [-s secure_dir] [starting_directory]\n";
  131.   require 'getopts.pl';
  132.   # Process the command args; Either specify verbose or an alternate config file:
  133. ! die $usage unless &'Getopts('ns:');
  134.   
  135.   $suid_dir = $'SECURE || '.';
  136. ! if (defined($'opt_s)) { $suid_dir = $'opt_s; }
  137.   
  138.   # Do NFS stuff?  Yes unless opt:
  139. ! if (defined($'opt_n)) { $skip_nfs = $'opt_n; }
  140.   else { $skip_nfs = 0; }
  141.   
  142.   $STOP="$suid_dir/suid.stop";
  143. ***************
  144. *** 64,83 ****
  145.   
  146.   # these may be terribly rash assumptions....
  147.   $start_dir="/" unless defined $start_dir;
  148. - $find_can_ls = 1 unless defined $find_can_ls;
  149.   
  150. - $NONFS = '-type d \( -fstype nfs -prune \) -o' if $skip_nfs;  
  151. - $find_ls = $find_can_ls ? '-ls' : "-exec $'LS -gilds {} \\;";
  152.   die "Error -- Security directory $suid_dir doesn't exist\n"
  153.       unless -d $suid_dir;
  154.   unless (-d $suid_dir) {
  155.       mkdir($suid_dir, 0700) || die "can't mkdir $suid_dir: $!";
  156. ! } 
  157.   chdir $suid_dir || die "can't chdir $suid_dir: $!\n";
  158.   
  159.   # find the setuid programs and sort
  160. ! &run("$'FIND $start_dir $NONFS -type f \\( -perm -4000 -o -perm -2000
  161. \\) $find_ls | $'SORT > $TEMPCUR");
  162.   
  163.   # compare with the sorted stop list
  164.   # create stop file if needed
  165. --- 64,82 ----
  166.   
  167.   # these may be terribly rash assumptions....
  168.   $start_dir="/" unless defined $start_dir;
  169.   
  170.   die "Error -- Security directory $suid_dir doesn't exist\n"
  171.       unless -d $suid_dir;
  172.   unless (-d $suid_dir) {
  173.       mkdir($suid_dir, 0700) || die "can't mkdir $suid_dir: $!";
  174. ! }
  175.   chdir $suid_dir || die "can't chdir $suid_dir: $!\n";
  176.   
  177.   # find the setuid programs and sort
  178. ! &run("$suid_dir/suidfind.pl".($skip_nfs ? " -n " : " ").$start_dir
  179. !     . "| $'SORT > $TEMPCUR");
  180.   
  181.   # compare with the sorted stop list
  182.   # create stop file if needed
  183. *** /dev/null    Mon Dec 23 11:46:59 1991
  184. --- suidfind.pl    Tue Dec  3 10:39:42 1991
  185. ***************
  186. *** 0 ****
  187. --- 1,123 ----
  188. + #!/bin/sh -- need to mention perl here to avoid recursion
  189. + 'true' || eval 'exec perl -S $0 $argv:q';
  190. + eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}'
  191. + & eval 'exec /usr/local/bin/perl -S $0 $argv:q'
  192. +         if 0;
  193. + #
  194. + #  Usage: suidfind.pl [-n] [-s secure_dir] [search_starting_directory]
  195. + #
  196. + require "getopts.pl";
  197. + die $usage unless &Getopts('n');
  198. + # Do NFS stuff?  Yes unless opt:
  199. + if (defined($opt_n)) { $skip_nfs = $opt_n; }
  200. + else { $skip_nfs = 0; }
  201. + if (@ARGV > 1) { die $usage; }
  202. + elsif (@ARGV == 1) { $start_dir = shift; }
  203. + # these may be terribly rash assumptions....
  204. + $start_dir="/" unless defined $start_dir;
  205. + @rwx = ('---','--x','-w-','-wx','r--','r-x','rw-','rwx');
  206. + @moname = (Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec);
  207. + while (($name, $pw, $uid) = getpwent) {
  208. +     $user{$uid} = $name unless $user{$uid};
  209. + }
  210. + while (($name, $pw, $gid) = getgrent) {
  211. +     $group{$gid} = $name unless $group{$gid};
  212. + }
  213. + require "find.pl";
  214. + # Traverse desired filesystems
  215. + &find($start_dir);
  216. + exit;
  217. + sub wanted {
  218. +     (($dev,$ino,$mode,$nlink,$uid,$gid) = lstat($_)) &&
  219. +     -d _ &&
  220. +     (    $skip_nfs &&
  221. +     ($dev < 0 || $dev >= 16384) &&
  222. +     ($prune = 1)
  223. +     )
  224. +     ||
  225. +     -f _ &&
  226. +     (
  227. +     ($mode & 04000) == 04000
  228. +     ||
  229. +     ($mode & 02000) == 02000
  230. +     ) &&
  231. +     &ls;
  232. + }
  233. + sub ls {
  234. +     ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$sizemm,
  235. +       $atime,$mtime,$ctime,$blksize,$blocks) = lstat(_);
  236. +     $pname = $name;
  237. +     if (defined $blocks) {
  238. +     $blocks = int(($blocks + 1) / 2);
  239. +     }
  240. +     else {
  241. +     $blocks = int(($size + 1023) / 1024);
  242. +     }
  243. +     if    (-f _) { $perms = '-'; }
  244. +     elsif (-d _) { $perms = 'd'; }
  245. +     elsif (-c _) { $perms = 'c'; $sizemm = &sizemm; }
  246. +     elsif (-b _) { $perms = 'b'; $sizemm = &sizemm; }
  247. +     elsif (-p _) { $perms = 'p'; }
  248. +     elsif (-S _) { $perms = 's'; }
  249. +     else         { $perms = 'l'; $pname .= ' -> ' . readlink($_); }
  250. +     $tmpmode = $mode;
  251. +     $tmp = $rwx[$tmpmode & 7];
  252. +     $tmpmode >>= 3;
  253. +     $tmp = $rwx[$tmpmode & 7] . $tmp;
  254. +     $tmpmode >>= 3;
  255. +     $tmp = $rwx[$tmpmode & 7] . $tmp;
  256. +     substr($tmp,2,1) =~ tr/-x/Ss/ if -u _;
  257. +     substr($tmp,5,1) =~ tr/-x/Ss/ if -g _;
  258. +     substr($tmp,8,1) =~ tr/-x/Tt/ if -k _;
  259. +     $perms .= $tmp;
  260. +     $user = $user{$uid} || $uid;
  261. +     $group = $group{$gid} || $gid;
  262. +     ($sec,$min,$hour,$mday,$mon,$year) = localtime($mtime);
  263. +     $moname = $moname[$mon];
  264. +     if (-M _ > 365.25 / 2) {
  265. +     $timeyear = '19' . $year;
  266. +     }
  267. +     else {
  268. +     $timeyear = sprintf("%02d:%02d", $hour, $min);
  269. +     }
  270. +     printf "%5lu %4ld %-10s %2d %-8s %-8s %8s %s %2d %5s %s\n",
  271. +         $ino,
  272. +          $blocks,
  273. +               $perms,
  274. +                 $nlink,
  275. +                 $user,
  276. +                      $group,
  277. +                       $sizemm,
  278. +                           $moname,
  279. +                          $mday,
  280. +                              $timeyear,
  281. +                              $pname;
  282. +     1;
  283. + }
  284. + sub sizemm {
  285. +     sprintf("%3d, %3d", ($rdev >> 8) & 255, $rdev & 255);
  286. + }
  287.