DEV Community

Cover image for We've Been Hacked!
Stéphan Zych
Stéphan Zych

Posted on

We've Been Hacked!

Billions of blistering barnacles! One of our ships has been boarded.

Follow these steps to quarantine, cleanse, and restore your project before the kraken strikes again!


Quick Checklist

  1. Quarantine files and database.
  2. Backup everything (files + DB).
  3. Scan for suspicious files and keywords.
  4. Reset all credentials (DB, admin, server).
  5. Restore from Git or a clean backup.
  6. Reapply client modifications/uploads.
  7. Scan, verify, and test thoroughly.

Step 1: Quarantine & Backup

# Archive the project
tar -zcf hacked-project.tar.gz /home/project/web/staging/

# Move project to quarantine (safe harbor)
mkdir -p /home/_quarantine/project
mv /home/project/* /home/_quarantine/project/

# Backup database
mysqldump --add-drop-table -u "<DB_USER>" -p"<DB_PASSWORD>" projectdb \
  > /home/_quarantine/project/hacked-project.sql
Enter fullscreen mode Exit fullscreen mode

Step 2: Cleanse the Wounded Ship

Restore any client-uploaded files or DB entries (if we don’t have a clean backup).
Scan for suspicious code:

   clamscan -ri --log=last-scan.txt /home/_quarantine/project/web/staging
Enter fullscreen mode Exit fullscreen mode

Search for sketchy keywords:

   # If ack isn’t installed: apt-get install ack-grep
   ack suspiciouskeyword
Enter fullscreen mode Exit fullscreen mode

Reset all passwords:

   mysql -u root -p -e \
   "ALTER USER '<DB_USER>'@'localhost' IDENTIFIED BY '<NEW_PASSWORD>'; FLUSH PRIVILEGES;"
Enter fullscreen mode Exit fullscreen mode

Update all software (WordPress, plugins, Composer deps, system packages).


Step 3: Restore & Reboard the Ship

# Clean Git working tree
git clean -n    # Preview
git clean -f    # Execute if safe
git reset --hard && git pull

# Clear caches
rm -rf storage/framework/cache/* tmp/*

# Reinstall dependencies
composer install

# Move project back to production
mv /home/_quarantine/project/* /home/project
chown -R www-data:www-data /home/project
Enter fullscreen mode Exit fullscreen mode

Step 4: Final Checks

Scan again:

   clamscan -ri --log=last-scan.txt /home/project/web/staging
   ack suspiciouskeyword
Enter fullscreen mode Exit fullscreen mode

Test all functionality.
Check logs for suspicious requests.
Celebrate with a liter of rum. 🥃

Top comments (0)