Closed Bug 638359 Opened 15 years ago Closed 15 years ago

Arbitrary PHP Execution via preg_replace in getpersonas.com

Categories

(Websites Graveyard :: getpersonas.com, defect)

defect
Not set
critical

Tracking

(Not tracked)

VERIFIED FIXED

People

(Reporter: neal, Assigned: chenba)

Details

(Keywords: reporter-external, Whiteboard: [infrasec:osinject][ws:critical])

Attachments

(2 files, 1 obsolete file)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13 Build Identifier: The following code comes from templates/persona_detail.php: $desc = preg_replace('/(https?\:\/\/[^ ]+[A-Za-z0-9\/])/e', '"<a href=\"".external_link(\'\\1\')."\">\\1</a>"', htmlspecialchars($persona['description'])); There is similar code in template/persona_detail_delete.php: $desc = preg_replace('/(https?\:\/\/[^ ]+[A-Za-z0-9\/])/e', '"<a href=\"".external_link(\'\\1\')."\">\\1</a>"', $persona['description']); Both of these pieces of code are vulnerable to arbitrary code execution. They're vulnerable because the second reference to \\1 is included in double quotes: through a judicious use of braces, it's possible to cause arbitrary functions to be executed when viewing the page. I'll attach a proof of concept that demonstrates what I'm talking about. My suggestion would be to replace these preg_replace calls with calls to preg_replace_callback. Reproducible: Always
This example, when run, will make a call to preg_replace using the code from getpersonas.com on specially formed input. This input will cause PHP to execute the function named in $_GET['cmd'] (defined at the top of the script to be phpinfo).
Attachment #516507 - Attachment mime type: application/octet-stream → text/plain
Nice find. Barry, can you look at this?
Assignee: nobody → chenba
Possible fix would be to remove the /e modifier from the regex then construct the url after the replace.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Whiteboard: [infrasec:osinject][ws:critical]
Attached patch preg_replace_callback patch (obsolete) — — Splinter Review
Proposed patch with Neal's suggestion for preg_replace_callback(). Also added missing htmlspecialchars() to persona_detail_delete
There were a couple of trailing commas in the arguments to create_function(), otherwise dchan's patch worked for me. Thanks, Neal and David.
Attachment #516659 - Attachment is obsolete: true
Attachment #517083 - Flags: review?
Comment on attachment 517083 [details] [diff] [review] dchan's preg_replace_callback patch with trailing commas remove Oh getpersonas. What would we do at 10:30pm on a friday if it weren't for you. Barry - go ahead and land, let's verify on stage.
Attachment #517083 - Flags: review? → review+
It's in r84047.
Status: NEW → RESOLVED
Closed: 15 years ago
Resolution: --- → FIXED
Group: websites-security
Status: RESOLVED → VERIFIED
Product: Websites → Websites Graveyard
Flags: sec-bounty+
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: