[KAPDA::#6] Punbb SQL Injection Vulnerability Punbb search.php SQL Injection Vulnerability KAPDA New advisory Vulnerable products : Punbb ( V 1.2.8 and 1.2.7 are tested,Hopefully all other versions) Vendor: http://www.punbb.org/ Vulnerability: Sql injection About Punbb -------------------- PunBB is a fast and lightweight PHP-powered discussion board. It is released under the GNU General Public License. Its primary goals are to be faster, smaller and less graphically intensive as compared to other discussion boards. PunBB has fewer features than many other discussion boards, but is generally faster and outputs smaller, semantically correct XHTML-compliant pages. Vendor`s description : http://punbb.org/about.php Discussion : ---------------- Scripts in page "Search.php" do not properly validate user-supplied input. A remote user can create specially crafted parameter values that will execute SQL commands on the underlying database. While "Global_register" of php.ini is set ON ,Remote user can poison local variables of PHP pages to take control of web application or change its logical flow. Vulnerabilities: -------------------- In Search.php : .......... start ........... if ($db->num_rows($result)) { while ($row = $db->fetch_row($result)) $old_searches[] = '\''.$db->escape($row[0]).'\''; $db->query('DELETE FROM '.$db->prefix.'search_cache WHERE ident NOT IN(' .implode(',', $old_searches).')') or error('Unable to delete search results' , __FILE__, __LINE__, $db->error()); } .......... end ........... The 4th line of pasted code sets old_searches[] (array) to carefully validated data, returned from database and then at next line it sends another query containing old_searches[]. If "Global_register" of php.ini is set ON and there is no SQL injection filters ( or magic_quotes) then poisoning old_searches can let remote users directly execute SQL commands. Proof of Concepts: -------------------- http://[site]/search.php?action=search&keywords=&author=d3vilbox& forum=-1&search_in=all&sort_by=0&sort_dir=DESC&show_as=topics &search=Submit&old_searches[]=[sql injection] Solution: -------------------- find : .......... Start ........... if ($db->num_rows($result)) { while ($row = $db->fetch_row($result)) $old_searches[] = '\''.$db->escape($row[0]).'\''; .......... End ........... and add "$old_searches=array();" before beginning of "While" to clear old_searches. it should looks like : .......... Start ........... $old_searches = array(); if ($db->num_rows($result)) { while ($row = $db->fetch_row($result)) $old_searches[] = '\''.$db->escape($row[0]).'\''; .......... End ........... More Detail: -------------------- http://www.kapda.ir/advisory-91.html Visit above link for more details. Credit : -------------------- Devil_box of KAPDA devil_box [at} kapda.ir Kapda - Security Science Researchers Insitute of Iran http://www.KAPDA.ir (PersianHacker.NET) Original Advisory : http://www.kapda.ir/advisory-91.html Special thanks to : Trueend and Irannetjob