|
25 Years of Programming
An open source source for C, C++, OWL, BASIC, MDB, XLS, DOT, and more... |
Home Projects Up Sitemap Search Blog Forum+Chat About Us Privacy Terms of Use Feedback FAQ Images Services Payments Humor Music |
Online calculator to identify hack attempts in website access logs
InstructionsPaste into the above box one or more complete lines from your website's HTTP access logs. Click Analyze. The lines you copy and paste should look like the following example of a typical CLF (Combined Log Format) log line. Be sure you are copying from the correct type of log (for example, not an FTP log): 111.222.333.444 - - [01/Nov/2010:02:21:59 -0800] "GET /forum/index.php HTTP/1.1" 200 17637 "http://referersite.com/pagewithlink.html" "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)" Where to find your access logs and how to download and unzip them are described in a related article. There is no set limit to the number of log lines you can paste into the box. The analysis is done by JavaScript in your browser, so the limit is whatever JavaScript is able to handle3. If the calculator identifies hack attempts, they are classified by type and sorted into the text boxes below. For easier viewing, copy and paste the text from each box into (preferably) a plain text editor that does not automatically turn URLs into hyperlinks. If it does create clickable links, don't click them, and don't visit the sites any other way, either. Websites mentioned in hack attempts should be considered potentially dangerous. DescriptionSome of my articles about website security recommend searching your HTTP access logs for "suspicious requests", which raises the questions:
The previous articles had some examples and discussion, but this online calculator takes a different approach: it analyzes real-life data from your own logs and shows you which lines are hack attempts. It even classifies and sorts them by the type of hack attempt they appear to be. Log Analysis ResultsRemote File Inclusion (RFI) AttacksAn RFI attack requests one of
your Defenses against RFI include methods of php.ini, .htaccess, using only the latest versions of applications like WordPress, and being especially careful to avoid RFI security holes when writing your own PHP code. More specifically: your first layer of defense should be that when your site receives an RFI attack, it should refuse to process the request, sending back a 403-Forbidden response instead of the requested page. Your second layer of defense should be to have PHP configured so that allow_url_fopen or allow_url_include are Off so your server will not allow itself to fetch files from remote websites at all. Your third layer of defense should be to have PHP register_globals set to Off so that the variable names passed via the HTTP query string do not automatically become usable by your PHP code. Your fourth layer of defense should be that even if an RFI attack gets past .htaccess, the PHP code it is targeting should not have any RFI vulnerabilities, so that the attack cannot succeed, anyway. Potential false positives:
Local File Inclusion (LFI) AttacksAn LFI attack also targets PHP pages. It tricks your PHP script into fetching important system files from your server and printing them on the output page. If it prints the contents of an encrypted password file, for example, the hacker can use fast offline cracking methods to decrypt it and then gain access to your server as one of its system users. LFI attacks can be blocked at the .htaccess level by banning requests for a) the frequently requested system files, b) the ./ string they often use to try to traverse directories and find the location of the system file they want. At the application level, the defense is much the same as for RFI: if you absolutely must choose which file to reference in an include() command based on input you received from the visitor, don't use the incoming value directly. Instead, make a hard-coded list in your script of the possible legal values for that variable. Compare the incoming value against the list, and if it doesn't exactly match one of the values in the list, do NOT use the user-provided value in the include(). Potential false positives:
SQL Injection AttacksAn SQL Injection attack contains SQL code in the request. SQL is a language for transferring data to and from a database. PHP or ASP code often takes data input provided by the website visitor and combines it with SQL template code to form a database query which it sends to the database. If it uses an insecure method to combine the two, then the input provided by the visitor, instead of being just data, can be interpreted as SQL code. If it actually is SQL code, the commands it contains will be executed on the database. It can corrupt the database, enter malicious data into it, delete it entirely, or dump its contents on the web page. The attacker doesn't need to know the database username/password because the script they are hijacking already knows them. SQL Injection attacks can be blocked at the .htaccess level by banning a) certain SQL keywords or combinations of them that don't occur in your legitimate filenames/URLs, b) punctuation and other special characters common in SQL Injection attacks that don't occur in your legitimate filenames/URLs. Your next, and more common, layer of defense is to keep all your applications such as WordPress updated to their latest versions so that if an SQL Injection vulnerability is found in the code, you receive the improved version as quickly as possible. If you write your own database connection code, it's important to guard against SQL Injection. Log File or Statistics Analyzer AttacksIn contrast to an RFI attack, which contains a reference to an external PHP file on a remote website, these attacks contain actual snippets of PHP or HTML code. The intent is that a program that either handles the request or puts it onto an output page will inadvertently either run the PHP code or place the HTML hyperlink on a report page without sanitizing it to make it plain text. The amount of code they can put in the request is limited, so it usually does something simple like echo a "Success" message so the hacker can tell whether the injection worked or not. Also assigned to this category are lines that contain one or more quotation marks that are escaped with a backslash (example: \"). When a legitimate request contains a quotation mark, it is usually encoded in a way that avoids using an actual quotation mark character. In a CLF log file, quotation marks are the delimiters for some of the fields. When a real quotation mark is received, it is typically escaped in the log with a backslash, which avoids getting that quote confused with the delimiter quotes. However, some people send HTTP requests containing embedded backslashes in carefully chosen locations with the intent of causing the delimiter quotes to be escaped (or internal quotes not to be escaped), thus corrupting the log and making it more difficult to parse or import into a database. Cross-site Scripting (XSS) AttacksIn a cross-site scripting attack, someone creates a hyperlink to one of your pages. In the hyperlink is a snippet of JavaScript. They hope your page will echo the snippet directly to the page without sanitizing it (without converting special characters to HTML entities), in which case the JavaScript will run when someone loads the page. The entries in this box are usually tests to determine whether your page has an XSS vulnerability. When they get the result page, they can see whether their JavaScript snippet was executed. If it was, they will craft and place their malicious link somewhere, and try to get people to click on it. The ways to avoid XSS vulnerabilities are: 1) keep web applications updated to their latest versions, 2) in your own code, whenever you receive text from a user and echo it back onto a page, pass it through the PHP htmlentities() function (or equivalent) first. This will, for example, put "<script" onto a page as "<script". A browser receiving "<script" thinks it is supposed to run the script, but when it receives "<script", it knows without confusion that it's supposed to put the text on the page. Miscellaneous AttacksOther requests that the calculator considers suspicious. Some examples:
Not AttacksThese are the log entries that were not classified as attacks. If any of the lines that land in this box actually are malicious, it means I need to revise the calculator to catch them and assign them an attack type. The reason this box is on the page is to make those types of errors easier to spot. Notes
Bug reports, feature suggestions, comments, questions can be submitted in the discussion forum. Hack Attempt Identifier - Perl scriptFor frequent use or for processing large log files, this Perl script that you run from the command line is faster, easier, and more efficient. It reads one or more log files that you specify and sorts the hack attempts into separate output files. You must have the Perl language installed on your PC to run this script. Perl is useful for utility and text processing tasks like this one. I developed and tested this script with Perl 5.10.0 in Ubuntu Linux and with ActivePerl 5.10.1 in Windows. Example usage: perl -WT HackAttemptIdentifier.pl -x"mysite.com" -n logfile1... Options: -x|--exclude"website.com" Exclude your own website from tests for RFI -n|--shownonmalicious Also write non-hack lines to a file -h|--help Show this help and exit It creates the following plain text output files in the current working directory: Identified-RFI.log Identified-LFI.log Identified-SQLINJECTION.log Identified-XSS.log Identified-LOGPGM.log Identified-MISC.log Identified-NONMALICIOUS.log It uses this Perl module: use Getopt::Long; The program's code structure and formatting is more like typical C++ formatting than typical Perl formatting.
|
||||||||||||
|
|
|
|
|
|
Copyright ©2011 Steven Whitney. Last modified Fri 04/01/2011 13:27:05 -0700. |
||