Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php imap_open RCE #10987

Merged
merged 11 commits into from Nov 27, 2018
Merged

php imap_open RCE #10987

merged 11 commits into from Nov 27, 2018

Conversation

h00die
Copy link
Contributor

@h00die h00die commented Nov 19, 2018

Saw this: https://web.archive.org/web/20181118213536/https://antichat.com/threads/463395

PHP's imap_open call on Debian based systems can potentially be passed a parameter that is given to rsh which is mapped to SSH, which allows for RCE.

I only coded based on the forum, I didn't discover this exploit or conribute to it in any way, all credit goes to twoster

Apps Reported Vulnerable:

Additional Apps Possible Vulnerable:

This is fine to land now, its VERY time consuming to install the CMS, figure out where the vuln is, write the exploit with all the darn nuances of every CMS and no core libraries (not that i think any should be added). When I get time i'll add them to here until it lands. After that i'll just make new PRs.

@todb-r7 I didn't see a CVE, but maybe you have more insight? According to https://danwin1210.me this was leaked on Nov 14th.

Verification

See docs

  • Verify docs are in good working order.

}
})

/form method="post" action="index\.php\?controller=AdminCustomerThreads&amp;token=(?<token>\w{32})/ =~ res.body
Copy link
Contributor

@Green-m Green-m Nov 19, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This way of using regular match seems to confuse me, I am not sure it is better than
res.body =~/form method="post" action="index\.php\?controller=AdminCustomerThreads&amp;token=(?<token>\w{32})/ ?

@bcoles
Copy link
Contributor

bcoles commented Nov 20, 2018

Jenkins test this please

@h00die
Copy link
Contributor Author

h00die commented Nov 20, 2018

Added suiteCRM today. As description update says, this is OK to land now. New PRs can be added as people find time to write in the other systems.

@h00die
Copy link
Contributor Author

h00die commented Nov 24, 2018

e107 is now exploitable. Note it is a special case where $IFS$() was getting encoded, however "\t" (not '\t') will bypass the filters and execute.

@syrius01
Copy link

Great share there @h00die ! I was wondering if there are some 3rd party softwares you've identified that uses php imap_open with no authentication required? This would be very critical.

Thanks

@h00die
Copy link
Contributor Author

h00die commented Nov 24, 2018

There's 108,000 lines of PHP code which reference "imap_open(": https://github.com/search?q=%22imap_open%28%22&type=Code
I have simply been coding what was already identified and have not been looking for new sources. Feel free to fork this PR and submit new exploitable things. I'd like to HIGHLY encourage that.

@h00die
Copy link
Contributor Author

h00die commented Nov 24, 2018

After clicking through all of HostCMS, I'm not seeing where the admin can enter the IMAP info. I believe it has the core plumbing there, simply for use by add-on modules. I'm going to abandon it for now.

@denji denji mentioned this pull request Nov 24, 2018
@h00die
Copy link
Contributor Author

h00die commented Nov 24, 2018

@syrius01 I created a new target "custom" (no docs yet) which can be used similar to web_delivery for exploiting custom targets. I believe I've found a wordpress plugin that i'll be adding shortly, but the list is endless.

@h00die
Copy link
Contributor Author

h00die commented Nov 24, 2018

Looks like freescout-helpdesk only accepts itself, so not exploitable https://github.com/freescout-helpdesk/freescout/blob/52c763849ea1e73ced39b960d1e95fb06d264473/vendor/webklex/laravel-imap/src/IMAP/Client.php#L455

@h00die
Copy link
Contributor Author

h00die commented Nov 25, 2018

Added "Custom" target, and finished documenting it, so you can now get the string to use, and have a listener for attempts to exploit custom apps, similar to web_delivery.

I'm most likely done now. I updated the description to incorporate all the additional findings.

@busterb
Copy link
Member

busterb commented Nov 27, 2018

Wow, this is nice! I'm going to go ahead and get it into master so folks can take advantage of it. Sounds like plenty to add over time.

@busterb busterb self-assigned this Nov 27, 2018
@todb-r7
Copy link

todb-r7 commented Nov 27, 2018

Thanks @h00die ! I'm alerting the DWF right now, they should kick out a CVE for you/twoster.

@busterb busterb merged commit e2d58af into rapid7:master Nov 27, 2018
busterb added a commit that referenced this pull request Nov 27, 2018
@busterb
Copy link
Member

busterb commented Nov 27, 2018

Release Notes

The exploits/linux/http/php_imap_open_rce module has been added to the framework. This exploits the PHP imap_open call against various web apps, allowing for remote code execution.

@todb-r7
Copy link

todb-r7 commented Nov 27, 2018

Based on your notes, @h00die , I am presuming you were testing the very latest PHP, PHP 7.3.0RC6 , or at least something close enough that this functionality is quite likely to be present there. In any event, the 7.3 release branch doesn't mention imap_open at all in the UPGRADING notes, so I'm assuming it's untouched.

@todb-r7 todb-r7 added the hotness Something we're really excited about label Nov 27, 2018
@h00die
Copy link
Contributor Author

h00die commented Nov 27, 2018

@todb-r7 I think I only tested 7.0 but will check a little later and confirm the version and try the latest and post back

@todb-r7
Copy link

todb-r7 commented Nov 27, 2018

And @busterb just found this CVE listing:

https://vulmon.com/vulnerabilitydetails?qid=CVE-2018-19518

Which says the bug is in U of W IMAP Toolkit, whatever that is, not PHP, which seems incorrect. Hmm. Will let DWF sort it out.

@busterb
Copy link
Member

busterb commented Nov 27, 2018

Also original PHP bug report from months ago: https://bugs.php.net/bug.php?id=76428

@h00die
Copy link
Contributor Author

h00die commented Nov 27, 2018

@todb-r7 that reference the original code from @Bo0oM so we can go with that. I'll put in a new PR to update this code w/ the CVE you found (nice find!)

@h00die h00die deleted the php_imap_open_rce branch November 28, 2018 01:28
@h00die h00die mentioned this pull request Nov 28, 2018
@todb-r7
Copy link

todb-r7 commented Dec 6, 2018

Got a CVE from DWF: CVE-2018-1000859

I can edit up the module nowish to mention it.

@h00die
Copy link
Contributor Author

h00die commented Dec 6, 2018

Thanks @todb-r7 that would be great. I think I may have a new target soon but can't start till my laptop gets fixed (hoping to get parts in today).

todb-r7 pushed a commit to todb-r7/metasploit-framework that referenced this pull request Dec 6, 2018
See discussion on rapid7#10987.

Now that I said that out loud, I realize that the original PR for this
module is a really funny PR number.
@todb-r7 todb-r7 mentioned this pull request Dec 6, 2018
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs hotness Something we're really excited about module
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants