Saturday, December 7, 2013

Follow this simple advice to never get hacked again

The story began last Friday when friend of mine called on the phone stressed from the fact his sites were down. It turns out his shared hosting provider shutdown the sites because of multiple hacking attempts the putted too much load on the servers. 

Without adding too much details in the story, the problem was two sites php-fusion and joomla based. Both sites are legacy sites, which nobody support, but serve some purpose on the web. After couple of minute to asses the situation and considering the sites don't need to be super dynamic. We decided to go with static HTML files and I had to come up with quick solution.

The solution I came is fairly simple, my plan was to use wget to crow the site and then publish the generated files. I have to say not many people know how many useful features wget have. The plan worked like a charm.

Read on for details on how I did the trick.


The first site I converted to static HTML pages had less pages, but surely more difficult. I needed to convert download.php?cat=[:digit]&download_id=[:digit] to the real name of the file. The good news is wget parameters that can do that for me.





‘--trust-server-names’

If this is set to on, on a redirect the last component of the redirection URL will be used as the local file name. By default it is used the last component in the original URL.



‘--content-disposition’

If this is set to on, experimental (not fully-functional) support for Content-Disposition headers is enabled. This can currently result in extra round-trips to the server for a HEAD request, and is known to suffer from a few bugs, which is why it is not currently enabled by default.
This option is useful for some file-downloading CGI programs that use Content-Disposition headers to describe what the name of a downloaded file should be. 

The final command looked something like that:

$ wget --recursive --no-clobber --page-requisites --adjust-extension --convert-links --restrict-file-names=windows --domains {$domain.com} --trust-server-names --content-disposition --no-parent {$domain.com}

Of course there were some adjustments later, but the wget did the difficult part. Finally we have two static sites, and the complains from the shared hosting provider should stop because they the are impossible to hack again.

No comments:

Post a Comment