Questions about this topic? Sign up to ask in the talk tab.

Mass assignment

From NetSec
Jump to: navigation, search
   Value overwrite by mass assignment
     These are rare scenarios caused by mass object property assignment from HTTP parameters.  Many web applications do this on one level or another to simplify form generation.  Advanced ORM's are usually (but not always) involved in this sort of problem, so be on the lookout for PHP's "Doctrine", Ruby's "ActiveRecord", or Python's "sqlAlchemy".  
     
     Suppose when a signup form post occurs, an ajax request is sent to:
       /users/signup/?username=newguy&password1=crackme&password2=crackme&[email protected]
     
     And our SQL table creation statement looked something like:
     
     create table user (id int auto_increment primary key, group_id int foreign key not null default 1, username varchar(24), password varchar(512), activated timestamp, email varchar(256)) foreign key (group_id) references group(id);
    
    The target software will automatically put new users in group 1 (non-activated users list) on registration.  Perhaps on update it would update us to group 2, and additional groups became available for further permissions.  
    
    Suppose the "administrators group" for the web application is group id 5.  When unchecked mass assignment is in place, the following signup URI would make user `superhacker' an admin:
       /users/signup/?username=superhacker&password=1337&[email protected]&group_id=5
     

Examples

 
          <?php
             foreach ($_GET as $property => $value) { 
               $user->$property = $value; 
             }
             $user->save();
          ?>
 
         for param in request.GET:
           user.__dict__[param] = request.GET[param]
  • Ruby on Rails (ActiveRecord):

{{source lang="ruby">

         user = User.new(params[:user])</source>}}
         

Mitigation


Auditing: