6 ms·
Pi-hole Remote Code Execution
- jrwr 7y ago1) You have be be logged into the pi-hole 2) Requires the user to post into a MAC Address field While I agree this should be fixed. This is a pretty low issue
- userbinator 7y agoAFAIK Pi-holes are almost always going to be sitting inside a LAN and owned by whoever owns the other devices on the network too, so the risk is quite low.
- bubblethink 7y agoIn general, yes, but this is how real issues start. Look at all the bmc software written in the world. It's utter horseshit. You are supposed to use a dedicated vlan for accessing the bmc. Everyone is still fighting the bmc software and it is routinely accessed over the open internet.
- jimmySixDOF 7y agothey should remedy that ;}
- rany_ 7y agoWhat is bmc software?
- bubblethink 7y agoidrac, ilo, etc.
- bitten 7y agoYes definitely. My ISP does not allow me to expose a DNS server to the internet, they told me it was against the law. So it seems you'd have to break the law in my country in order to be vulnerable to this!
- dbrgn 7y agoHuh, really? Against the law, or against the contract? In what country do you live?
- paddlesteamer 7y agoI think it's more than 'pretty low issue'. Someone already connected to the LAN may just sniff the login credentials since the Pi-hole web interface doesn't use https and then gain root access where all LAN clients trust with their DNS queries.
- peter_d_sherman 7y agoThe root of this issue seems to be a regexp function (preg_match()) in PHP coupled with an exec() of a variable that was not properly screened, coupled with an 'sudo' inside of the exec(), e.g.: exec("sudo pihole -a addstaticdhcp ".$mac." ".$ip." ".$hostname); and/or exec("sudo pihole -a removestaticdhcp ".$mac); So three places to audit: 1) Regexp's and related complex high-level functions; 2) Calls to exec() 3) Uses of sudo within an exec()
- kpcyrd 7y agoThe problem is that php expects a string that is then passed to sh -c, which is then parsed by a shell. Instead php should have an interface that accepts: exec(["sudo", "pihole", "-a", "addstaticdhcp", $mac, $ip, $hostname]); without any shell trickery. If there's a sudo in this specific like doesn't matter, your reverse shell is going to run as a regular user and after that it only matters low locked down the sudoers configuration is.
- kilburn 7y agoDefinitely not ideal, but php provides the escapeshellarg [1] function you are supposed to use in these situations. You can even implement a "safe" exec function like so: function safe_exec(array $args, array &$output = null, int &$return_var = 0) : string { return exec( implode(' ', array_map('escapeshellarg', $args) ), $output, $return_var ); } // Example usage $output = []; $return_var = 0; echo safe_exec(['ls', '/tmp'], $output, $return_var); var_export($output); echo "Exit code: $return_var\n"; [1] https://www.php.net/manual/en/function.escapeshellarg.php https://www.php.net/manual/en/function.escapeshellarg.php
- droithomme 7y ago> exec("sudo ... " . $user_input_string ...) Wow, this is always a mistake and a huge one. exec() is dangerous, exec calling with sudo more so, and should never be used in conjunction with unprivileged user input like this. Granted a weak attempt was made to sanitize the user string, but so weak one might wonder if it is Underhanded Code at play here. The big problem with this sort of issue is that it indicates that there almost certainly are massive security problems elsewhere in this code base since this one is low hanging fruit that never should have made it past even rudimentary code review by anyone with a bare minimum knowledge of security.
- jrwr 7y agoCode review on a open source project.... Mind you they trusted a regex that looks pretty sane (A preg_replace might of been better)
- deleted 7y ago[deleted]
- corndoge 7y agoSo find the rest and fix them
- droithomme 7y agoI'd be happy to help you with this. My rate is $235/hr, minimum 30 hours. When can I expect your deposit so we can get started?
- deleted 7y ago[deleted]
- Disposition 7y agoYes, how dare he ask you to donate some of your time to contribute back to the open source community, tsk.
- 7y ago
- 0x0 7y agoDoes this pihole admin interface perform any kind of CSRF protection, or can this be exploites by any random website as long as the victim has a browser tab with a valid session?
- jrwr 7y agoRequires a POST that would hit CORS pretty hard
- py3001 7y agodns rebinding could make it work, thats not the question
- deathanatos 7y agoNot all POST requests require a CORS preflight. In particular, "normal" form submissions, like the type that are accessed via $_POST in the article, do not. Specifically, "simple requests" do not, covered here[1]. This case is POST, with a Content-Type of application/x-www-form-urlencoded. (The rule of thumb you can use is that these were all essentially possible to send prior to CORS even existing. To send a POST, you would construct a form tag with the inputs filled in with the desired values, set the target URL to the "victim" site, and have JS submit the form.) [1]: https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simple_requests https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#Simpl...
- itsnotlupus 7y agoThere's a csrf token set in a php session that's hard to guess that needs to be provided in form data, yes. Probably difficult to exploit that way without first finding another bug to retrieve that token from a random origin.
- Gravyness 7y agoThe dev trusted a regexp to 'validate' user input for a _privileged_ command execution, a function which fails at validating a constant-sized, colon-separated sequence of hex numbers in a string, everything about the input screams structure, and yet it was still half-assed! Although this requires you to authenticate at the web portal, so 'some' sort of trust is necessary to gain this level of access. I believe they even have some plan of letting authenticated users update the pi-hole code from the web interface by the wording on this issue: https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249 https://discourse.pi-hole.net/t/how-do-i-update-pi-hole/249. A funny thought: you can create a script (that uses the default password) to inject a code to schedule an update to the pi-hole (and revert the changed permissions) which fixes the vulnerability and leaves no trace! These possibilities reminds me of a hacker series!
- ct520 7y agoHmm, wonder if this is the type of stuff a static code analysis would pick up like (veracode)
- deleted 7y ago[deleted]
- eswat 7y agoLikely would. The `validMAC` function doesn’t just fail silently if the regex fails, which would get past naive signature detections. Oh and feeding user input directly into `exec`…
- deleted 7y ago[deleted]
- mappu 7y agoThe crazy thing is that there is a correct escaping available: `escapeshellarg()`. With correct escaping, you don't even need to sanitize the user input here - the target command will parse the MAC address itself and report any errors. The existing code is analogous to building SQL queries using string concatenation and forgetting the mysqli_real_escape_string() call. Really the solution is to use a parameterized interface (e.g. by calling pcntl_fork() + pcntl_exec(), that accepts an array of arguments instead of a string command-line). Pcntl doesn't seem to have a wrapper for the posix_spawn syscall.
- kpcyrd 7y agoescapeshellarg is an ugly hack, php is passing everything through `sh -c` for no reason. The pcntl_exec function is the only one that has a reasonable interface, but is way too low level. php should simply accept this as a valid function call: exec(["sudo", "pihole", "-a", "addstaticdhcp", $mac, $ip, $hostname]);
- solarkraft 7y agoYou have to be an authenticated user on the admin portal. Doesn't this already come with the expectation of being able to fully control the device?
- scaglio 7y agoNot necessarily, web GUI password and user/root ones can be different. From an attacker's point of view: he just needs to crack the Wi-fi (e.g. aircrack-ng), join the LAN an then bruteforce the Pi-Hole webadmin password.
- vgb2k18 7y agoI read further up [1] that Pi-Hole auth is http not https, so if you cracked the WiFi aready, sniffing the webadmin password might yield a quicker return than brute-forcing (depending on strength of password, and owner's login frequency). Assuming the maximum password length of PiHoles is not < 20 chars. [1] https://news.ycombinator.com/item?id=22717938 https://news.ycombinator.com/item?id=22717938
- needle0 7y agoWhy the sudden use of the "Black Jack ni Yoroshiku" manga comic art? I know the author released the entire thing with permissions to freely use the art anywhere, but still.
- quickthrowman 7y agoA family member of mine was the original author of pi-hope. He sold the company to his partner last year, so any changes in aesthetics would be due to the change in ownership.
- promofaux 7y agoOne of the Pi-hole dev's here. The comment you are replying to is talking about the blog post about this CVE, not Pi-hole's aesthetics. (Which haven't changed, btw) Say hi to J from me.
- quickthrowman 7y agoAhh, my mistake. I will say hi for you :)
- mg794613 7y agoWhy is it that, instead of just forking and making a patch is nowadays replaced with a CVE focus. Are CVE's the new big thing on your CV?
- scaglio 7y agoThe patch has been released the day after the issue was being noticed to Pi-hole, as you can read at the bottom of the article. This is just an informative article and, as a pentester, I find it very interesting.
- INTPenis 7y agoThis is justification for people like me who rolled our own using the lists from pihole and a tiny bit of shell script. No need for a web gui.
- mro_name 7y agoself-hosting and remote code execution don't go well together. In that very moment it's not apt for non-tech users which is the main target group AFAIK. Very sad. Just too much complexity.