• Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login
Netgate Discussion Forum
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Search
  • Register
  • Login

How does pfsense's web interface run root scripts

Scheduled Pinned Locked Moved General pfSense Questions
11 Posts 4 Posters 5.2k Views
Loading More Posts
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M
    mercutio22
    last edited by Nov 15, 2012, 8:22 PM

    Hi. I am starting work on a project where I'd want to change the IP address of a network card using a django web interface. At first I thought that was something simple to do: I'd call a script with setuid root. Unfortunately I learned that this is a security risk and most unix kernels wont allow execution of interpreted language scripts as root by using setuid 4 (and allow the program to be executed by normal users as root).

    So how does pfsense does it?

    For instance, this script in the pfsense source code seems to need super user permissions: https://github.com/bsdperimeter/pfsense/blob/master/sbin/dhclient-script

    Any clues? Thanks.

    1 Reply Last reply Reply Quote 0
    • J
      jimp Rebel Alliance Developer Netgate
      last edited by Nov 15, 2012, 8:44 PM

      Our scripts all run under the root user. Not really ideal for some things, but ultimately unavoidable for the things we need to do.

      Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

      Need help fast? Netgate Global Support!

      Do not Chat/PM for help!

      1 Reply Last reply Reply Quote 0
      • M
        mercutio22
        last edited by Nov 15, 2012, 10:07 PM

        Interesting. But the webinterface which is PHP itself doesn't run as root or does it? How do you run a root script after a user submits a form?

        I am trying to look at the source code but I am not finding the relevant parts. Perhaps you can point me in the right direction.

        1 Reply Last reply Reply Quote 0
        • J
          jimp Rebel Alliance Developer Netgate
          last edited by Nov 15, 2012, 10:12 PM

          The web server runs as root, and so do all the pages (PHP, etc).

          Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

          Need help fast? Netgate Global Support!

          Do not Chat/PM for help!

          1 Reply Last reply Reply Quote 0
          • M
            mercutio22
            last edited by Nov 15, 2012, 10:19 PM

            Ok I see. I thought that would too vulnerable in case there was some vulnerability in the webinterface itself, allowing for privilege escalation. Do you guys use chroot or freebsd's JAILS as a security measure instead?

            1 Reply Last reply Reply Quote 0
            • J
              jimp Rebel Alliance Developer Netgate
              last edited by Nov 15, 2012, 10:32 PM

              No, it's just the nature of how it has to be in order for it to properly function and do what needs to be done. In part it's that way because we inherited that from m0n0wall, but there's really not a viable way to separate those function and maintain all of required abilities.

              Remember: Upvote with the 👍 button for any user/post you find to be helpful, informative, or deserving of recognition!

              Need help fast? Netgate Global Support!

              Do not Chat/PM for help!

              1 Reply Last reply Reply Quote 0
              • D
                dhatz
                last edited by Nov 15, 2012, 10:47 PM

                @mercutio22:

                Interesting. But the webinterface which is PHP itself doesn't run as root or does it? How do you run a root script after a user submits a form?

                Apart from dnsmasq and dhclient, most processes on pfSense run as roon, including lighthttpd, php, openvpn etc.

                As far as I can tell, to minimize exposure to potential security vulnerabilities in the webGUI, one would have to disallow access to the webGUI from all interfaces except a specific "secure" interface.

                1 Reply Last reply Reply Quote 0
                • M
                  mercutio22
                  last edited by Nov 16, 2012, 1:55 AM

                  What about using sudo?

                  People on the python channel are saying I should not consider running the webserver and django as root. They were surprised to learn pfsense does that.

                  1 Reply Last reply Reply Quote 0
                  • C
                    cmb
                    last edited by Nov 16, 2012, 2:01 AM

                    Ideally, no you don't want to do that. But by the nature of what we do, there is no effective security difference. The front end must have rights to change the config file at a minimum, and anything that has the rights to do that can execute things as root. You could use sudo if you want, but it's basically pointless, if the user running the web server can run sudo it's effectively no different than running it as root. We're considering options going forward to completely separate the front end and back end, which would eliminate that root requirement. But in 10+ years m0n0wall has existed and the 8+ years we've existed, there have been exactly 0 security vulnerabilities caused or worsened by that fact.

                    1 Reply Last reply Reply Quote 0
                    • M
                      mercutio22
                      last edited by Nov 17, 2012, 5:32 PM

                      @cmb:

                      You could use sudo if you want, but it's basically pointless, if the user running the web server can run sudo it's effectively no different than running it as root.

                      Well I am no unix guru, but it seems to me that adding sudo access to a restricted subset of commands would be very different than allowing unrestricted access to all root commands.

                      I mean, you could have /etc/sudoers entry allowing the www user access to scripts that edit the /etc/interfaces, etc:
                      i.e.  www    ALL=(root)  NOPASSWD: /path/to/alter_interfaces.sh

                      Or something like that. I am not very fluent in sudo yet.

                      1 Reply Last reply Reply Quote 0
                      • C
                        cmb
                        last edited by Nov 18, 2012, 3:50 AM

                        You can do that, but we run so many things from the web server that it would be functionally no different to allow everything.

                        1 Reply Last reply Reply Quote 0
                        11 out of 11
                        • First post
                          11/11
                          Last post
                        Copyright 2025 Rubicon Communications LLC (Netgate). All rights reserved.
                          This community forum collects and processes your personal information.
                          consent.not_received