Welcome, Guest. Please Login or Register.
May 10, 2025, 06:17:35 PM
Home Help Search Log in Register
News: If you are still using YaBB SE, please consider upgrading to SMF as soon as possible.

YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Security Enhancement, Keys For Actions « previous next »
Pages: [1] 2 Reply Ignore Print
Author Topic: Security Enhancement, Keys For Actions  (Read 835 times)
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Security Enhancement, Keys For Actions
« on: March 21, 2003, 02:28:11 AM »
Reply with quote

This is designed to be used as a toolkit to create security mods.  What it allows you todo is instead of like resetting a password instead create a key and e-mail the user a confirmation if they really want to reset their password.  The code has not fully been tested but should work.  I have also provided the schema for the table required for this.  If you make updates to this code please post them in this thread.  Hope someone can make this useful.  This code can only be used in YaBBSE or PfaBB.

CREATE TABLE `yabbse_action_keys` (

`ID_MEMBER` int ( 25 ) NOT NULL UNSIGNED,
`action` VARCHAR( 10 ) NOT NULL ,
`key` VARCHAR( 32 ) NOT NULL ,
`expires` BIGINT( 20 ) NOT NULL ,
`datetime_submitted` BIGINT( 20 ) NOT NULL ,
`ip_submiter` VARCHAR( 15 ) NOT NULL ,
INDEX ( `username` , `action` , `key` )
)

function new_action_key($memid, $action, $expires)
{
   global $db_prefix, $REMOTE_ADDR, $db_passwd, $cleaned_action_keys;

   if($cleaned_action_keys != 1)
      clean_action_keys();
   
   $result = mysql_query('SELECT expires FROM '.$db_prefix.'action_keys WHERE ID_MEMBER='.$memid.' && action=\''.$action.'\' && key=\''.$key.'\'') or database_error(__FILE__, __LINE__);
   if(mysql_num_rows($result) > 0) //Key exists
      return false;
   else
   {
      $key = md5(time().$username.$db_passwd);
      
      mysql_query('INSERT INTO '.$db_prefix.'action_keys VALUES \''.$memid.'\', \''.$action.'\', \''.$key.'\', '.$expires.', '.time().', \''.$REMOTE_ADDR.'\'') or database_error(__FILE__, __LINE__);

      return $key;
   }
}

function check_action_key($memid, $action, $key)
{
   global $db_prefix, $cleaned_action_keys;
   
   if($cleaned_action_keys != 1)
      clean_action_keys();
   
   $result = mysql_query('SELECT expires FROM '.$db_prefix.'action_keys WHERE ID_MEMBER='.$memid.' && action=\''.$action.'\' && key=\''.$key.'\'') or database_error(__FILE__, __LINE__);
   if(mysql_num_rows($result) > 0)
   {
      return true;
   }
   else
      return false;
}

function clean_action_keys()
{
   global $db_prefix, $cleaned_action_keys;
   
   mysql_query('DELETE FROM '.$db_prefix.'action_keys WHERE expires<='.time()) or database_error(__FILE__, __LINE__);
   $cleaned_action_keys = 1;
}
« Last Edit: March 21, 2003, 04:43:57 AM by David » Logged

Chris Cromer
The Strange One
Mod Team
YaBB God
*****
Posts: 3152


I am just a figment of your imagination.

WWW
Re:Security Enhancement, Keys For Actions
« Reply #1 on: March 21, 2003, 02:51:18 AM »
Reply with quote

I don't think the keys need an expire time do they?

After the key expires the user would be able to send another e-mail using the new key system. They just have to wait for it to expire before they could do it again.
Logged

Chris Cromer

I am not suffering from insanity, I am enjoying every minute of it.
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #2 on: March 21, 2003, 02:55:15 AM »
Reply with quote

Quote from: Chris Cromer on March 21, 2003, 02:51:18 AM
I don't think the keys need an expire time do they?

After the key expires the user would be able to send another e-mail using the new key system. They just have to wait for it to expire before they could do it again.
Obviously a few more funtionc need to be written.  My thinking was that if a key existed then a new one could not be added, thus the purpose of the expire time.  Reasoning is to stop someone from sending 100s of password reset requests.
Logged

Chris Cromer
The Strange One
Mod Team
YaBB God
*****
Posts: 3152


I am just a figment of your imagination.

WWW
Re:Security Enhancement, Keys For Actions
« Reply #3 on: March 21, 2003, 03:02:22 AM »
Reply with quote

Yeah, I see the point in having a expiretime now... although after it expires the same problem exists.

So basically the guy causing the problems would be able to still cause problems, he would just have to wait longer between sending each e-mail. So it does pretty much no good... because I could make it send out the e-mails in intervals using a simple php script that refreshed after the expiretime.
Logged

Chris Cromer

I am not suffering from insanity, I am enjoying every minute of it.
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #4 on: March 21, 2003, 03:05:28 AM »
Reply with quote

Quote from: Chris Cromer on March 21, 2003, 03:02:22 AM
So basically the guy causing the problems would be able to still cause problems, he would just have to wait longer between sending each e-mail. So it does pretty much no good... because I could make it send out the e-mails in intervals using a simple php script that refreshed after the expiretime.
But the expire time can be tweaked depending on the call to the new key function.  Thus an admin could choose their own expire time and not tell people what it is.
Logged

Chris Cromer
The Strange One
Mod Team
YaBB God
*****
Posts: 3152


I am just a figment of your imagination.

WWW
Re:Security Enhancement, Keys For Actions
« Reply #5 on: March 21, 2003, 03:10:59 AM »
Reply with quote

Ok well I guess that could be a good temp fix though, although I wouldn't rely on it because most likely the person you built this to stop, would just keep trying till it did go through. ;)
Logged

Chris Cromer

I am not suffering from insanity, I am enjoying every minute of it.
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #6 on: March 21, 2003, 03:12:17 AM »
Reply with quote

Quote from: Chris Cromer on March 21, 2003, 03:10:59 AM
Ok well I guess that could be a good temp fix though, although I wouldn't rely on it because most likely the person you built this to stop, would just keep trying till it did go through. ;)
This is something I have been meaning to write for a while.  I will try and finish off the functions tommorrow.
Logged

Jack.R.Abbit
Mod Team
YaBB God
*****
Posts: 553


RACE FOR SPENT!

Re:Security Enhancement, Keys For Actions
« Reply #7 on: March 21, 2003, 03:17:09 AM »
Reply with quote

So maybe I'm missing something or its not there but how does it work so that you can't create a key if ther is already one?

Maybe I just need a bit more of a walk through on how it would be used.

Sounds like a really nice idea though

-Jack
Logged

<--------  Mods by Jack  -------->
Package Server: http://www.modsbydesign.com/mods.by.jack/yabbse/ (now serving)


|----------------------------------------------|
|                                              |
|          DON'T PM ME FOR SUPPORT!             |
|                                              |
|----------------------------------------------|
Omar Bazavilvazo
YaBB SE Developer
YaBB God
*****
Posts: 2153


I never said I would stay to the end...

WWW
Re:Security Enhancement, Keys For Actions
« Reply #8 on: March 21, 2003, 03:43:00 AM »
Reply with quote

Hmm... I always wondered why we didn't had a mod like this...

Sounds very great, i'll be waiting for it to be finished. :P
I'll give it a try after i finish a mod i'm doing right now.
Logged

Greetings from México!
http://omarbazavilvazo.com
Mi foro Español-Japonés
http://hablajapones.org
http://hablajapones.org/index.php/japones/tutoriales/b16.php

NO me manden IM para soporte o dudas
...Leo los foros como todos...
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #9 on: March 21, 2003, 03:53:00 AM »
Reply with quote

Quote from: Jack.R.Abbit on March 21, 2003, 03:17:09 AM
So maybe I'm missing something or its not there but how does it work so that you can't create a key if ther is already one?

Maybe I just need a bit more of a walk through on how it would be used.

Sounds like a really nice idea though

-Jack
Walkthrough for forgotten password.

User requests a password reminder.

Reminder.php calls new_action_key which either returns a new key or false.  If it returns a new key then reminder.php sends out an e-mail containing this new key.  If it returns false, shows an error message that this action was already requested and the previous key has not expired.

User recieves key in e-mail and a link to the second part of the action.

Reminder.php calls check_action_key, if it returns true then it lets the user choose a new password.  If it returns false then the key is wrong.



A key is bound to an action which allows multiple actions to implement these functions when they are done and they will not conflict with each other.

One more idea I had for the expire time is to make it each time be somewhere between a low number of minutes and high number set by the admin.  Like a range of 30 to 90 minutes then the key could expire anytime during that window.  And since the expire time can be set in the call to new_action_key you could have a shorter time, 15 minutes for a forgotten password, while having a time like a week for activating a new account.
Logged

Jack.R.Abbit
Mod Team
YaBB God
*****
Posts: 553


RACE FOR SPENT!

Re:Security Enhancement, Keys For Actions
« Reply #10 on: March 21, 2003, 04:02:11 AM »
Reply with quote

I see.  So currently the new_action_key function does not have anything to check if should return a key or false.  Thats where I was tripping up.  I understand that it is a work in progress.

And the expire range would mean that each time a new key was generates it would randomly select a time within that range, unless you had explicitly specified an expire time.

One more thing, would it log somewhere the failed attempts to get a new key?

-Jack
Logged

<--------  Mods by Jack  -------->
Package Server: http://www.modsbydesign.com/mods.by.jack/yabbse/ (now serving)


|----------------------------------------------|
|                                              |
|          DON'T PM ME FOR SUPPORT!             |
|                                              |
|----------------------------------------------|
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #11 on: March 21, 2003, 04:05:41 AM »
Reply with quote

Ok, updated it.  new_action_key now checks if there is an existing key for this username and for this action.

new_action_key also now requires an expire time be passed to it.  Thus the range idea would be implemented in the call to that function, not in the function.

The function clean_action_keys was added.  It deletes all expired keys.  It can either be run on every click on the board from like index.php or both new_action_key and check_action_key now check if it has been run on this click and if not then they run it.

I am planning to work on logging next.  How would you want logging to work, what should be logged?  Should any action be taken if there are a lot of errors?
Logged

[Unknown]
Global Moderator
YaBB God
*****
Posts: 7830


ICQ - 179721867unknownbrackets@hotmail.com WWW
Re:Security Enhancement, Keys For Actions
« Reply #12 on: March 21, 2003, 04:08:50 AM »
Reply with quote

Quote from: David on March 21, 2003, 02:28:11 AM
CREATE TABLE `yabbse_action_keys` (

`username` VARCHAR( 25 ) NOT NULL ,
`action` VARCHAR( 10 ) NOT NULL ,
`key` VARCHAR( 32 ) NOT NULL ,
`expires` BIGINT( 20 ) NOT NULL ,
`datetime_submitted` BIGINT( 20 ) NOT NULL ,
`ip_submiter` VARCHAR( 15 ) NOT NULL ,
INDEX ( `username` , `action` , `key` )
)


Why do it by username?  I would do it by ID_MEMBER.

-[Unknown]
Logged
David
Destroyer Dave
Global Moderator
YaBB God
*****
Posts: 5761


I'm not a llama!

WWW
Re:Security Enhancement, Keys For Actions
« Reply #13 on: March 21, 2003, 04:10:32 AM »
Reply with quote

Quote from: [Unknown] on March 21, 2003, 04:08:50 AM
Quote from: David on March 21, 2003, 02:28:11 AM
CREATE TABLE `yabbse_action_keys` (

`username` VARCHAR( 25 ) NOT NULL ,
`action` VARCHAR( 10 ) NOT NULL ,
`key` VARCHAR( 32 ) NOT NULL ,
`expires` BIGINT( 20 ) NOT NULL ,
`datetime_submitted` BIGINT( 20 ) NOT NULL ,
`ip_submiter` VARCHAR( 15 ) NOT NULL ,
INDEX ( `username` , `action` , `key` )
)


Why do it by username?  I would do it by ID_MEMBER.

-[Unknown]
Good idea.  What is the vairable that ID_MEMBER is stored in, like username is $username.

Also is there a function to look up ID_MEMBER given a username?  Like the forgotten password the user inputs the username.
« Last Edit: March 21, 2003, 04:11:20 AM by David » Logged

Jack.R.Abbit
Mod Team
YaBB God
*****
Posts: 553


RACE FOR SPENT!

Re:Security Enhancement, Keys For Actions
« Reply #14 on: March 21, 2003, 04:24:28 AM »
Reply with quote

Quote from: David on March 21, 2003, 04:05:41 AM
I am planning to work on logging next.  How would you want logging to work, what should be logged?  Should any action be taken if there are a lot of errors?

I guess since you won't always have a username for the person requesting the action (maybe never) you can't really do much.  So if the "Key already exists" error gets logged into the normal board error log not much else you can do.  Only thing maybe is to ban that IP after like 10 failed attempts or something but history shows that the bastards doing bad things usually have ways around IP ban so it would not solve anything.

-Jack
Logged

<--------  Mods by Jack  -------->
Package Server: http://www.modsbydesign.com/mods.by.jack/yabbse/ (now serving)


|----------------------------------------------|
|                                              |
|          DON'T PM ME FOR SUPPORT!             |
|                                              |
|----------------------------------------------|
Pages: [1] 2 Reply Ignore Print 
YaBB SE Community  |  Development  |  Mod Ideas and Creation  |  Security Enhancement, Keys For Actions « previous - next »
 


Powered by MySQL Powered by PHP YaBB SE Community | Powered by YaBB SE
© 2001-2003, YaBB SE Dev Team. All Rights Reserved.
SMF 2.1.4 © 2023, Simple Machines
Valid XHTML 1.0! Valid CSS

Page created in 0.037 seconds with 20 queries.