Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • when reading a critical file (config files, modules, etc) you should always check the file permissions to be sure that nobody could possibly have modified it.

    How does that help? If an attacker has permission to change the contents of a config file then they may well have permission to chmod it back to 644 afterwards, surely?

    Further, checking the permissions with stat() and then reading the file introduces a race condition, and so does reading it first and then statting.

    Some programs like OpenSSH or Apa

    --
    -- Ed Avis ed@membled.com
    • > How does that help? If an attacker has permission to change the contents of a config file then they may well have permission to chmod it back to 644 afterwards, surely?

      No, they can't.

      (Unless the attacker has root in which case the security of your program is irrelevant anyway)


      adam@svn:~$ sudo vi tmp.pl
      adam@svn:~$ sudo chmod 666 tmp.pl
      adam@svn:~$ vi tmp.pl
      adam@svn:~$ chmod 644 tmp.pl
      chmod: changing permissions of `tmp.pl': Operation not permitted

      > Further, checking the permissions with stat() and the

      • No, they can't.
        (Unless the attacker has root in which case the security of your program is irrelevant anyway)

        Well, quite. To change files in /etc you need to be root, and if you are root then you can make it appear that the files have not been altered. There are conceivable cases where by some freak event a config file was set up as o+w but the directory was not writable, but I have a hard time believing it's the application's job to check for that, any more than I think applications should be constantl

        --
        -- Ed Avis ed@membled.com
        • > So why is that case any more worth checking for?

          We don't always only read files that were created at the time a program was installed?

          Plugins appear afterwards, config files get backed up and restored. Who's to say the program hasn't been upgraded since you last ran?

          There's a range of cases where this problem could appear from and not all of them would be a problem during the race window. But I agree some might, so it probably does makes sense to check both initially and then on the opened file handle.

    • > Further, checking the permissions with stat() and then reading the file introduces a race condition, and so does reading it first and then statting.

      You can open a file, and then stat the file handle...

      • You can open a file, and then stat the file handle...

        Doesn't help. The permissions can be changed after you stat and while you still have the file open.

        --
        -- Ed Avis ed@membled.com
        • It closes, not the case of its permissions changing, but of statting and reading different files, because the file (in a writable directory, like /tmp) got renamed in the interim.

          A tighter permission check, reasonably cheap: fstat, read, fstat again and check nothing but access time has changed.

  • Well, the thing that always irked me, is how templates can be "compiled" (= converted to perl code which, when executed, produces the desired output from the template) and stored to disk, for simply reloading and running later. The compiled templates must be writable by the program that compiles and uses them, in order to be able to recompile them on the fly, if necessary; and which may running under the same under-privileged user as all other users are using; for example, when running as a CGI script.

    That