You are missing our premiere tool bar navigation system! Register and use it for FREE!

NukeCops  
•  Home •  Downloads •  Gallery •  Your Account •  Forums • 
Readme First
- Readme First! -

Read and follow the rules, otherwise your posts will be closed
Modules
· Home
· FAQ
· Buy a Theme
· Advertising
· AvantGo
· Bookmarks
· Columbia
· Community
· Donations
· Downloads
· Feedback
· Forums
· PHP-Nuke HOWTO
· Private Messages
· Search
· Statistics
· Stories Archive
· Submit News
· Surveys
· Theme Gallery
· Top
· Topics
· Your Account
Who's Online
There are currently, 118 guest(s) and 0 member(s) that are online.

You are Anonymous user. You can register for free by clicking here
Nuke Cops :: View topic - Making PHPNuke more secure:A Way Forward [ ]
 Forum FAQ  •  Search  •   •  Memberlist  •  Usergroups   •  Register  •  Profile •    •  Log in to check your private messages  •  Log in

 
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
Author Message
bauhaus6970
Nuke Cadet
Nuke Cadet


Joined: Feb 05, 2004
Posts: 1


PostPosted: Thu Feb 05, 2004 4:42 am Reply with quoteBack to top

1) Nukecops should set up a default install of PHPNuke 6.5 and the latest release.

2) People should be invited to test security issues on those default installs.

3) First person to find security holes and report them responsibly should be rewarded in some way.

Basically a competiton for 'white hat' hackers.

I think this a lot better way forward than taking direct action against FB to make him listen.
Find all posts by bauhaus6970View user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Thu Feb 05, 2004 1:20 pm Reply with quoteBack to top

It's a damn pain in the arse to fix the bugs over and over again in each new PHP-Nuke release.
It's better to check what FB has changed and then merge that into the old one, cos that is faster.

I don't like the points system so i stick to my heavily secured Nuke, it even has a speed increase with about 300%.

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
PoC2
Corporal
Corporal


Joined: Jul 18, 2003
Posts: 61


PostPosted: Fri Feb 06, 2004 12:38 pm Reply with quoteBack to top

How did you manage the acceleration?

BTW, good work on Protector, appreciated.
Find all posts by PoC2View user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Fri Feb 06, 2004 4:00 pm Reply with quoteBack to top

The speedup is mostly realised by decreasing the SQL queries.

I modified the mysql.php to generate a list queries of the page and echo that list in the footer.

Then i noticed a few things like:

30x SELECT user_password FROM nuke_users WHERE user_id='$uid'
10x SELECT * FROM nuke_users WHERE username='$user1[1]' AND user_password='$user1[2]'
8x SELECT pwd FROM nuke_authors WHERE aid='$aid'

The function in order:

is_user()
getusrinfo()
is_admin()

I just changed those functions to only 1 call to DB because why ask 30x is_user() when it has been asked already ?

So for example i did this:

Code:
function is_user($user) {
    global $prefix, $db, $user_prefix;
    if (!$user) { return 0; }
    if(!is_array($user)) {
        $user1 = base64_decode($user);
        $user1 = explode(":", $user1);
        $uid = "$user1[0]";
        $pwd = "$user1[2]";
    } else {
        $uid = "$user[0]";
        $pwd = "$user[2]";
    }
    if (defined("isuser")) {
        if (isuser == $pwd) {
            return 1;
        }
    }
    $uid = addslashes($uid);
    $uid = intval($uid);
    if ($uid != "" AND $pwd != "") {
        $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE user_id='$uid'";
        $result = $db->sql_query($sql);
        $row = $db->sql_fetchrow($result);
        $pass = $row['user_password'];
        if($pass == $pwd && $pass != "") {
            define("isuser", $pwd);
            return 1;
        }
    }
    return 0;
}


explain:

define("isuser", $pwd); if it's a user set a define with his encrypted password, because defines can't be edited and are available all over the place.

if (defined("isuser")) { Check if define exists due to a previous call
if (isuser == $pwd) { return 1; Ok the define matches the cookie password and it should be ok so return, no need to check the pwd against the database cos it's in the define.

Well you can figure out the rest or just download mainfile.php from the CPG-Nuke source.

Note: I even managed to decrease the SQL queries from 180 to 13 on a few occasions

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
PoC2
Corporal
Corporal


Joined: Jul 18, 2003
Posts: 61


PostPosted: Sat Feb 07, 2004 5:50 am Reply with quoteBack to top

This would suggest FB's code could be a lot tighter and cleaner.

Of course the usual thing is, like Microsoft, people follow the big names even if they're bad because they believe they will have large and on-going support.

Would it be a good idea to work with NukeCops to produce a super version of PHPNuke? I'm guessing NC has the big support.
Find all posts by PoC2View user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Sat Feb 07, 2004 9:15 am Reply with quoteBack to top

PoC2 wrote:
This would suggest FB's code could be a lot tighter and cleaner.

Of course the usual thing is, like Microsoft, people follow the big names even if they're bad because they believe they will have large and on-going support.

Would it be a good idea to work with NukeCops to produce a super version of PHPNuke? I'm guessing NC has the big support.


PoC i already headed my own direction with a copy of PHP-Nuke 6.5 and already modified it heavily in just one month.
I named it CPG-Nuke and a first release is available soon.
The CVS is always available to everyone so FB and NC can grab code from it.
It isn't hold back for "Club" members as FB does.

NC also has a CVS where you can get the latest file releases.

So NC and CPG are doing the right ways to give support in the best way we can.

If the first release is out (which has to much fixes and upgrades to mention anywhere) i will contact NC if they want to incorporate.

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Fri Feb 20, 2004 10:07 am Reply with quoteBack to top

Hi djmaze,

Just a quick thing--since you do so many valuable patches....

I would rather use "static" variables inside a function to "remember" the state from one call to the other, vs. using a global constant.

Although constants in PHP are interpretively bound (late bound), I think we are getting away from the "spirit" of constants, and there are no guarantees, IMHO, that future versions of PHP would work this way (?).

I am going to implement your patch Razz Thanks.

steve
Find all posts by steven111View user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Fri Feb 20, 2004 10:15 am Reply with quoteBack to top

implementation using "static"

Code:
function is_user($user) {
    global $prefix, $db, $user_prefix;
    static $userSave; //save from one call to the other
    if (isset($userSave)) return ($userSave);
    if(!is_array($user)) {
   $user = base64_decode($user);
   $user = explode(":", $user);
        $uid = "$user[0]";
   $pwd = "$user[2]";
    } else {
        $uid = "$user[0]";
   $pwd = "$user[2]";
    }
    $uid = addslashes($uid);
        $uid = intval($uid);
    if ($uid != "" AND $pwd != "") {
   $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE user_id='$uid'";
   $result = $db->sql_query($sql);
   $row = $db->sql_fetchrow($result);
   $pass = $row[user_password];
   if($pass == $pwd && $pass != "") {
      $userSave = 1;
       return 1;
   }
    }
    $userSave = 0;
    return 0;
}
Find all posts by steven111View user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Fri Feb 20, 2004 10:26 am Reply with quoteBack to top

optimizing function is_admin (in mainfile.php on Nuke7.0)

Code:
function is_admin($admin) {
    global $prefix, $db;
    static $adminSave;  //maintain state from one call to next
    if (isset($adminSave)) return ($adminSave); //steve
   
    if(!is_array($admin)) {
   $admin = base64_decode($admin);
   $admin = explode(":", $admin);
        $aid = "$admin[0]";
   $pwd = "$admin[1]";
    } else {
        $aid = "$admin[0]";
   $pwd = "$admin[1]";
    }
    if ($aid != "" AND $pwd != "") {
        $aid = trim($aid);
   $sql = "SELECT pwd FROM ".$prefix."_authors WHERE aid='$aid'";
   $result = $db->sql_query($sql);
   $row = $db->sql_fetchrow($result);
   $pass = $row[pwd];
   if($pass == $pwd && $pass != "") {
      $adminSave = 1;
       return 1;
   }
    }
    $adminSave = 0;
    return 0;
}
Find all posts by steven111View user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Fri Feb 20, 2004 10:44 am Reply with quoteBack to top

this is called a few times too, mainfile.php (Nuke7.0) djmaze, you are great!!

Code:
function cookiedecode($user) {
    global $cookie, $prefix, $db, $user_prefix;
    static $cookieSave;
    $user = base64_decode($user);
    $cookie = explode(":", $user);
   
    if (!isset($cookieSave)) {
       $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE username='$cookie[1]'";
       $result = $db->sql_query($sql);
       $row = $db->sql_fetchrow($result);
       $cookieSave = $row;
    }
    else {
       $row = $cookieSave;   
    }
   
    $pass = $row[user_password];
    if ($cookie[2] == $pass && $pass != "") {
   return $cookie;
    } else {
   unset($user);
   unset($cookie);
    }
}
Find all posts by steven111View user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Fri Feb 20, 2004 10:56 am Reply with quoteBack to top

Themes are read from the directory 4 times Shocked

So, in mainfile.php, make the following change:
Code:
function get_theme() {
    global $user, $cookie, $Default_Theme;
    static $ThemeSelSave;  //save from one call to another
    if (isset($ThemeSelSave)) return ($ThemeSelSave);
   
    if(is_user($user)) {
   $user2 = base64_decode($user);
   $t_cookie = explode(":", $user2);
   if($t_cookie[9]=="") $t_cookie[9]=$Default_Theme;
   if(isset($theme)) $t_cookie[9]=$theme;
   if(!$tfile=@opendir("themes/$t_cookie[9]")) {
       $ThemeSel = $Default_Theme;
   } else {
       $ThemeSel = $t_cookie[9];
   }
    } else {
   $ThemeSel = $Default_Theme;
    }
    $ThemeSelSave = $ThemeSel;
    return($ThemeSel);
}
Find all posts by steven111View user's profileSend private messageVisit poster's website
Paul_k
Nuke Soldier
Nuke Soldier


Joined: Jul 07, 2003
Posts: 31

Location: England

PostPosted: Sun Feb 22, 2004 4:44 am Reply with quoteBack to top

Hi,

This is great stuff! Changed my mainfile.php to match the changes above and knocked my page generation time from 2.99 seconds to 1.04 Smile

Cheers, Paul K
Find all posts by Paul_kView user's profileSend private message
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Sun Feb 22, 2004 7:17 am Reply with quoteBack to top

Steven thanks for your "static" option i will merge it into CPG-Nuke

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
djmaze
Captain
Captain


Joined: Nov 29, 2003
Posts: 566

Location: Netherlands

PostPosted: Sun Feb 22, 2004 7:32 am Reply with quoteBack to top

I noticed a bug in your cookiedecode function so here's the correct one
Code:
function cookiedecode($user) {
    global $cookie, $db, $user_prefix;
    static $pass;
    if(!is_array($user)) {
        $user1 = base64_decode($user);
        $cookie = explode(":", $user1);
    } else {
        $cookie = $user;
    }
    if (!isset($pass)) {
       $sql = "SELECT user_password FROM ".$user_prefix."_users WHERE username='$cookie[1]'";
       $result = $db->sql_query($sql);
       list($pass) = $db->sql_fetchrow($result);
    }
    if ($cookie[2] == $pass && $pass != "") {
       return $cookie;
    } else {
       unset($user);
       unset($cookie);
    }
}

_________________
Famous people never give their signature Rolling Eyes
http://www.cpgnuke.com <- back online thanks to dedicatednow.com
Don't ask me to be admin on your site please Exclamation
Find all posts by djmazeView user's profileSend private messageVisit poster's website
steven111
Lieutenant
Lieutenant


Joined: Dec 30, 2003
Posts: 283


PostPosted: Sun Feb 22, 2004 12:22 pm Reply with quoteBack to top

Paul_k wrote:
This is great stuff! Changed my mainfile.php to match the changes above and knocked my page generation time from 2.99 seconds to 1.04 Smile


Paul, glad to have helped Very Happy If you want to get more into optimization, check out the following links:

http://www.karakas-online.de/forum/viewtopic.php?t=130&highlight=accelerate
http://www.ravenphpscripts.com/posts1033-highlightsteven.html

steve
Find all posts by steven111View user's profileSend private messageVisit poster's website
Display posts from previous:      
Post new topic  Reply to topicprinter-friendly view
View previous topic Log in to check your private messages View next topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



Powered by phpBB © 2001, 2005 phpBB Group

Ported by Nuke Cops © 2003 www.nukecops.com
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::
Powered by · TOGETHER TEAM srl ITALY http://www.togetherteam.it · DONDELEO E-COMMERCE http://www.DonDeLeo.com
Web site engine's code is Copyright © 2002 by PHP-Nuke. All Rights Reserved. PHP-Nuke is Free Software released under the GNU/GPL license.
Page Generation: 0.248 Seconds - 299 pages served in past 5 minutes. Nuke Cops Founded by Paul Laudanski (Zhen-Xjell)
:: FI Theme :: PHP-Nuke theme by coldblooded (www.nukemods.com) ::