Tuesday, March 30, 2010

htaccess file to help prevent sql injection attempts

I use the text below in a .htaccess file to help prevent sql injection attacks that seem to crop up from time to time.

This will look for common attack methods and redirect them to a page called hack.cfm which I will commonly just leave as a blank page while recording the type of attack.

RewriteEngine On

Options +FollowSymLinks
ServerSignature Off

RewriteCond %{REQUEST_METHOD} ^(HEAD|TRACE|DELETE|TRACK) [NC,OR]
RewriteCond %{THE_REQUEST} ^.*(\\r|\\n|%0A|%0D).* [NC,OR]

RewriteCond %{HTTP_REFERER} ^(.*)(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC,OR]
RewriteCond %{REQUEST_URI} ^/(,|;|:|<|>|">|"<|/|\\\.\.\\).{0,9999}.* [NC,OR]

RewriteCond %{HTTP_USER_AGENT} ^$ [OR]
RewriteCond %{HTTP_USER_AGENT} ^(java|curl|wget).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(libwww-perl|curl|wget|python|nikto|scan).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC,OR]

RewriteCond %{QUERY_STRING} ^.*(;|<|>|'|"|\)|%0A|%0D|%22|%27|%3C|%3E|).*(/\*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127\.0\.0\.1).* [NC,OR]
#RewriteCond %{QUERY_STRING} ^.*\.[A-Za-z0-9].* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(<|>|'|%0A|%0D|%27|%3C|%3E|).* [NC]

RewriteRule ^(.*)$ hack.cfm

Wednesday, July 29, 2009

Backup FTP/SFTP settings in Aptana/Coldfusion Builder

I have had a problem with Aptana in the past and also with Coldfusion Builder now (it appears to use Aptana used under the hood). The problem is if Eclipse/Computer freezes up and you have to restart the computer with Eclipse still open. This process seems to corrupt the workspace and you tend to lose all your settings (incl FTP/SFTP settings). So here is how you back them up.

1. Goto 'File' then 'Export'
2. Select 'Coldfusion' then select 'Syncing Settings'
3. Name the file and save somewhere

these can be imported in the same way. Hope this saves some time for people.

Wednesday, April 8, 2009

Changing the user of Coldfusion on Linux

I made the mistake of setting up Coldfusion 8 on a linux system (centOS) with the user set as 'nobody'. This proved to be a big mistake when it came to using tags like cffile to write to the filesystem. I had a hunt around for some info on how to do this with Adobe suggesting a reinstall of coldfusion

To change the user running coldfusion to the same as the owner of the web directory I completed the following steps.

1. vi /etc/init.d/coldfusion_8 then change the runtime user to the same as the user of your web folder
2. vi /etc/init.d/cfsearch8 then change the runtime user to the same as the user of your web folder
3. vi /opt/coldfusion8/bin/coldfusion then change the runtime user to the same as the user of your web folder
4. chown -R /opt/coldfusion8 name_of_new_runtimeuser

This allowed me to then use cffile to copy files to my server, however I was still running into a minor problem with the image functions of Coldfusion. Thanks to Ben Nadal who has a note on installing a hot fix to solve this problem.

Friday, March 13, 2009

Forbidden 403 Error after installing phpMyAdmin

After I had installed phpMyAdmin (in my case centos, using YUM) I received a 403 forbidden error. By default phpmyadmin installed path is /usr/share/phpmyadmin and the apache configuration file is located in /etc/httpd/conf.d/phpmyadmin.conf.

To fix:

vi /etc/httpd/conf.d/phpmyadmin.conf

Remove or comment these lines

#Order Allow,Deny
#Deny from all
Allow from 127.0.0.1

Restart the apache server.

/etc/init.d/httpd restart

You should be able to see phpmyadmin working by going to http://ipaddress/phpmyadmin

Tuesday, March 10, 2009

Resizing a Amazon EBS Volume

I struggled to find the answer to resizing an existing Amazon Elastic Block Store Volume.

Here is how I resolved this

1. Created a snapshot of the existing volume (log into Amazons Console for this https://console.aws.amazon.com)

2. Create a new volume based on the snapshot

3. Attach this new volume to my Amazon Instance (after detaching the other volume)

4. SSH into my Amazon Instance

5. Enter the following, this checks the integrity of the disk 'e2fsck -f /dev/sdf'

6. Enter the following 'resize2fs /dev/sdf'

7. Mount the volume 'mount /dev/sdf /mnt/data-store'

Friday, February 20, 2009

Arrow and delete keys not working in VMWare on Ubuntu

Browse to the hidden directory inside your home directory

.vmware

then create the following file

config

and copy the following info into the file

xkeymap.keycode.108 = 0x138 # Alt_R
xkeymap.keycode.106 = 0x135 # KP_Divide
xkeymap.keycode.104 = 0x11c # KP_Enter
xkeymap.keycode.111 = 0x148 # Up
xkeymap.keycode.116 = 0x150 # Down
xkeymap.keycode.113 = 0x14b # Left
xkeymap.keycode.114 = 0x14d # Right
xkeymap.keycode.105 = 0x11d # Control_R
xkeymap.keycode.118 = 0x152 # Insert
xkeymap.keycode.119 = 0x153 # Delete
xkeymap.keycode.110 = 0x147 # Home
xkeymap.keycode.115 = 0x14f # End
xkeymap.keycode.112 = 0x149 # Prior
xkeymap.keycode.117 = 0x151 # Next
xkeymap.keycode.78 = 0x46 # Scroll_Lock
xkeymap.keycode.127 = 0x100 # Pause
xkeymap.keycode.133 = 0x15b # Meta_L
xkeymap.keycode.134 = 0x15c # Meta_R
xkeymap.keycode.135 = 0x15d # Menu

Subclipse and Eclipse on Ubuntu

Install libsvn-java

The package libsvn-java contains JavaHL.

Install libsvn-java by typing the following into a command line:

sudo apt-get install libsvn-java

then make sure you add the following to your Eclipse launcher parameters (ie add it to the end of the shortcut to eclipse):

-vmargs -Djava.library.path=/usr/lib/jni


Restart Eclipse.