Cracking Drupal - leaking data http://crackingdrupal.com/taxonomy/term/50/0 en Creating a sanitized Drupal database dump http://crackingdrupal.com/blog/greggles/creating-sanitized-drupal-database-dump <p>People often want to create a backup copy of their site database and give it to someone else to create an environment similar to the live environment for testing or development. However, doing so exposes all of your site data being leaked if that backup copy is ever placed on a CD that gets lost or a harddrive which is not destroyed at the end of its life or a laptop which is stolen.</p> <p>I blogged about one solution to this problem earlier with <a href="http://crackingdrupal.com/blog/greggles/easier-and-safer-drupal-development-virtualbox-virtualization">using Virtualbox and an encrypted disk image on Mac</a> for easier and more secure development. However, another simple solution exists: munge the data.</p> <h3>Sanitizing a Drupal database export</h3> <p>The basic idea of this strategy is five easy steps:</p> <ol> <li>Export your database</li> <li>Import it into a new temporary place</li> <li>Overwrite sensitive information with dummy data</li> <li>Export from the temporary place</li> <li>Share this new export</li> </ol> <p><code><br /> -- CAUTION: DO NOT RUN THIS ON DATABASE WHERE YOU CARE ABOUT THE INFORMATION!!!</code></p> <p>-- Munge emails for security.<br /> UPDATE users SET mail = CONCAT(name, '@localhost'), init = CONCAT(name, '@localhost'), pass = MD5(CONCAT('MILDSECRET', name));<br /> UPDATE comments SET mail = CONCAT(name, '@localhost');<br /> UPDATE directory SET mail = CONCAT(name, '@localhost');<br /> UPDATE authmap SET authname = CONCAT(aid, '@localhost');<br /> UPDATE client SET mail = CONCAT(cid, '@localhost');<br /> -- Only important if you use project and project_issue module<br /> UPDATE project_issue_projects SET mail_digest = 'foo@localhost', mail_copy = 'foo@localhost';<br /> UPDATE projects SET mail = CONCAT("empty", '@localhost');<br /> -- Only important if you use simplenews module<br /> UPDATE simplenews_subscriptions SET mail = CONCAT(snid, '@localhost');</p> <p>-- Clear out old webform entries which likely include e-mails<br /> UPDATE webform_submitted_data set data='<em>scrubbed</em>';</p> <p>-- Get rid of irrelevant data it contains IP addresses and bulks up the database<br /> TRUNCATE accesslog;<br /> TRUNCATE access;<br /> TRUNCATE cache;<br /> TRUNCATE cache_filter;<br /> TRUNCATE cache_menu;<br /> TRUNCATE cache_page;<br /> TRUNCATE devel_queries;<br /> TRUNCATE devel_times;<br /> TRUNCATE flood;<br /> TRUNCATE history;<br /> TRUNCATE search_dataset;<br /> TRUNCATE search_index;<br /> TRUNCATE search_total;<br /> TRUNCATE sessions;<br /> TRUNCATE watchdog;</p> <p>-- Alter sensitive entries in the Variable table<br /> update variable set value = 's:4:"fake";' where name = 'smtp_password';<br /> </p> <p>The above script is a slightly modified version of a fairly specific script that works for one specific database: drupal.org. However, you can see the techniques used here and imagine how to adapt them for other sites.</p> <h3>Modify the script to protect data for your specific site</h3> <p>One important step that I take when adapting this to a new site is to make my export from step 4 above and then do a search through the text of the export for common e-mail providers like yahoo or gmail to see if any more addresses exist. If you find one then you figure out which column they are in and use a similar "munge" process on the column updating it to null.</p> <p>Take special care with some modules like <a href="http://drupal.org/project/twitter">twitter</a> that may store account credentials (twitter usernames and passwords) in a database table.</p> <p>And take extra special care with modules like <a href="http://drupal.org/project/smtp">smtp</a> or <a href="http://drupal.org/project/mailhandler">mailhandler</a> which store credentials for important email accounts in the variable table or other locations in the database.</p> <p>Once you've got this script tuned for your site you may need to update it as you add new modules or upgrade existing modules.</p> <p>And that's it - now you can share copies of your database with greater confidence that your site won't be the source of a data leak.</p> <p><em>Edit: Updated to include webform example based on <a href="http://joshuabrauer.com/2010/11/scrubbing-drupal-databases-development">jbrauer's similar blog post.</a></em></p> http://crackingdrupal.com/blog/greggles/creating-sanitized-drupal-database-dump#comments leaking data Planet Drupal Sat, 27 Mar 2010 15:06:55 +0000 greggles 53 at http://crackingdrupal.com