5 * @author Roland Haeder <webmaster@ship-simu.org>
7 * @copyright Copyright (c) 2009 Cracker Tracker Team
8 * @license GNU GPL 3.0 or any newer version
9 * @link http://www.ship-simu.org
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 // Initializes all detector arrays
26 function initCrackerTrackerArrays () {
27 // Set error_reporting
28 if (isCrackerTrackerDebug()) {
29 // For debugging purposes, this is fine
30 @error_reporting(E_ALL | E_STRICT);
36 // Whitelist some absolute query strings (see below)
37 $GLOBALS['ctracker_whitelist'] = array(
40 'cmd=lostpw' // LinPHA
43 // Attacks we should detect and block
44 $GLOBALS['ctracker_get_blacklist'] = array(
45 'chr(', 'chr=', 'chr%20', '%20chr', 'wget%20', '%20wget', 'wget(',
46 'cmd=', '%20cmd', 'cmd%20', 'rush=', '%20rush', 'rush%20',
47 'union%20', '%20union', 'union(', 'union=', 'echr(', '%20echr', 'echr%20', 'echr=',
48 'esystem(', 'esystem%20', 'cp%20', '%20cp', 'cp(', 'mdir%20', '%20mdir', 'mdir(',
49 'mcd%20', 'mrd%20', 'rm%20', '%20mcd', '%20mrd', '%20rm',
50 'mcd(', 'mrd(', 'rm(', 'mcd=', 'mrd=', 'mv%20', 'rmdir%20', 'mv(', 'rmdir(',
51 'chmod(', 'chmod%20', '%20chmod', 'chmod(', 'chmod=', 'chown%20', 'chgrp%20', 'chown(', 'chgrp(',
52 'locate%20', 'grep%20', 'locate(', 'grep(', 'diff%20', 'kill%20', 'kill(', 'killall',
53 'passwd%20', '%20passwd', 'passwd(', 'telnet%20', 'vi(', 'vi%20', 'cgi-', '.eml',
54 'insert%20into', 'select%20', 'nigga(', '%20nigga', 'nigga%20', 'fopen', 'fwrite', '%20like', 'like%20',
55 '$_request', '$_get', '$request', '$get', '.system', 'HTTP_PHP', '&aim', '%20getenv', 'getenv%20',
56 'new_password', '&icq','/etc/passwd','/etc/shadow', '/etc/groups', '/etc/gshadow',
57 'HTTP_USER_AGENT', 'HTTP_HOST', 'wget%20', 'uname\x20-', 'uname%20-', 'bin/id', '/bin/', '/chgrp',
58 '/chown', '/usr/bin', 'g\+\+', 'bin/python', 'bin/tclsh', 'bin/nasm', 'perl%20', 'traceroute%20',
59 'ping%20', '.pl', 'bin/xterm', 'lsof%20', '.conf', 'motd%20', 'HTTP/1.', '.inc.php', '.lib.php',
60 'config.php', 'file\://', 'window.open', '<SCRIPT>', 'javascript\://', 'img src', 'img%20src', '.jsp',
61 'ftp.exe', 'xp_enumdsn', 'xp_availablemedia', 'xp_filelist', 'xp_cmdshell', 'nc.exe', '.htpasswd',
62 'servlet', '/etc/passwd', 'wwwacl', '~root', '~ftp', '.js', '.jsp', '.history', 'bash_history',
63 '.bash_history', '~nobody', 'server-info', 'server-status', 'reboot%20', 'halt%20',
64 'powerdown%20', '/home/ftp', '/home/www', 'secure_site, ok', 'chunked', 'org.apache', '/servlet/con',
65 '<script', '/robot.txt' ,'/perl' ,'mod_gzip_status', 'db_mysql.inc', '.inc', 'select%20from',
66 'select from', 'drop%20', '.system', 'getenv', 'http_', '_php', 'php_', 'phpinfo()', '\<?php', '?\>', 'sql=',
67 'div style=', 'overflow: auto', 'height: 1px', 'cc%20', 'admin_action=', 'path=', 'action=http',
68 'page=http', 'module=http', 'op=http', 'id=http', 'id%3Dhttp', 'action%3Dhttp', 'page%3Dhttp',
69 'module%3Dhttp', 'op%3Dhttp', 'starhack', '../../','..//', 'directory=http', 'dir=http', 'busca',
70 'uol.com', '=http://', '=https://','=ftp://','=file://','_SESSION','CFG_ROOT','/proc/',',0x5',
74 // Block these words found in POST requests
75 $GLOBALS['ctracker_post_blacklist'] = array(
76 // This line is for detecting hidden link spam in wikis, forums, guestbooks, etc.
77 'div style=', 'overflow:auto', 'height:1px', 'width:1px', 'display:hidden',
78 // "Common" login name from VHCS exploiters ;-)
79 'starhack', 'DeLiMehmet', 'hisset', 'Hisset', 'delimert', 'MecTruy',
84 $GLOBALS['ctracker_header'] = crackerTrackerLoadEmailTemplate('header');
87 $GLOBALS['ctracker_post_track'] = '';
88 $GLOBALS['ctracker_checkworm'] = '';
89 $GLOBALS['ctracker_check_post'] = '';
93 function isCrackerTrackerWormDetected () {
94 // Check against the whole list
95 $GLOBALS['ctracker_checkworm'] = str_replace($GLOBALS['ctracker_get_blacklist'], '*', crackerTrackerQueryString());
97 // If it differs to original and the *whole* request string is not in whitelist
98 // then blog the attempt
99 return ($GLOBALS['ctracker_checkworm'] != crackerTrackerQueryString() && (!in_array(crackerTrackerQueryString(), $GLOBALS['ctracker_whitelist'])));
103 function isCrackerTrackerPostAttackDetected () {
104 // Implode recursive the whole $_POST array
105 $GLOBALS['ctracker_post_track'] = implode_r('', $_POST);
107 // Check for suspicious POST data
108 $GLOBALS['ctracker_check_post'] = str_replace($GLOBALS['ctracker_post_blacklist'], '*', $GLOBALS['ctracker_post_track']);
111 return ((isCrackerTrackerWormDetected()) || ($GLOBALS['ctracker_check_post'] != $GLOBALS['ctracker_post_track']));
114 // Prepares a mail and send it out
115 function sendCrackerTrackerMail () {
117 crackerTrackerLogAttack();
120 $mail = "Attack detected:
121 -----------------------------------------------------
122 Remote-IP : ".determineCrackerTrackerRealRemoteAddress()."
123 User-Agent : ".crackerTrackerUserAgent()."
124 Request-string : ".crackerTrackerQueryString()."
125 Filtered string : ".$GLOBALS['ctracker_checkworm']."
126 Server : ".crackerTrackerServerName()."
127 Script : ".crackerTrackerScriptName()."
128 Referrer : ".crackerTrackerReferer()."
129 -----------------------------------------------------
133 crackerTrackerSendMail($mail);
139 // Sends the ticket emails out
140 function sendCrackerTrackerTicketMails () {
141 // Load user template
142 $mail = crackerTrackerLoadEmailTemplate('user_add_ticket', $GLOBALS['ctracker_last_ticket']);
144 // Send email to the user
145 crackerTrackerSendMail($mail, $GLOBALS['ctracker_last_ticket']['ctracker_ticket_email'], getCrackerTrackerLocalized('user_add_ticket_subject'));
147 // Load webmaster template
148 $mail = crackerTrackerLoadEmailTemplate('webmaster_add_ticket', $GLOBALS['ctracker_last_ticket'], getCrackerTrackerConfig('ctracker_language'));
150 // Send email to the user
151 crackerTrackerSendMail($mail, null, getCrackerTrackerLocalized('webmaster_add_ticket_subject'));
155 function crackerTrackerSendMail ($mail, $recipient = null, $subject = null) {
156 // Construct dummy array
158 'remote_addr' => determineCrackerTrackerRealRemoteAddress(),
159 'check_worm' => $GLOBALS['ctracker_checkworm'],
160 'server_name' => crackerTrackerServerName()
163 // Only send email if not yet found
164 if (!isCrackerTrackerEntryFound($rowData)) {
165 // Send the email out only in non-debug mode
166 if (isCrackerTrackerDebug()) {
168 print 'Recipient=' . $recipient . '<br />Subject=' . $subject . '<br />Text=<pre>' . $mail . '</pre>';
172 } elseif (!is_null($recipient)) {
173 // Recipient specified
174 return mail($recipient, $subject, $mail, $GLOBALS['ctracker_header']);
175 } elseif (isset($GLOBALS['ctracker_email'])) {
177 return mail($GLOBALS['ctracker_email'], 'CTracker: Attack detected!', $mail, $GLOBALS['ctracker_header']);
179 // Send it the deprecated way with constant
180 return mail(constant('__CTRACKER_EMAIL'), 'CTracker: Attack detected!', $mail, $GLOBALS['ctracker_header']);
182 } elseif (isCrackerTrackerDebug()) {
184 print 'Recipient=' . $recipient . '<br />Subject=' . $subject . '<br />Text=<pre>' . $mail . '</pre>';
191 // Sends a detected POST attack mail
192 function sendCrackerTrackerPostMail () {
194 crackerTrackerLogAttack();
197 $mail = "POST-Attack detected:
198 -----------------------------------------------------
199 Remote-IP : ".determineCrackerTrackerRealRemoteAddress()."
200 User-Agent : ".crackerTrackerUserAgent()."
201 Request-string : ".crackerTrackerQueryString()."
202 Filtered string : ".$GLOBALS['ctracker_checkworm']."
203 Server : ".crackerTrackerServerName()."
204 Script : ".crackerTrackerScriptName()."
205 Referrer : ".crackerTrackerReferer()."
206 -----------------------------------------------------
207 POST string : ".$GLOBALS['ctracker_post_track']."
208 Filtered POST string : ".$GLOBALS['ctracker_check_post']."
209 -----------------------------------------------------
213 crackerTrackerSendMail($mail);
219 // Sleeps for a random time and aborts the script
220 function crackerTrackerDie () {
221 // Close database link
222 crackerTrackerCloseDatabaseLink();
224 // Do only sleep if debug/developer mode is not enabled
225 if (!isCrackerTrackerDebug()) {
226 // Sleep a little to waste the attacker's time
227 sleep(mt_rand(10,30));
231 if (isCrackerTrackerDebug()) {
232 // With debug backtrace in debug/developer mode
234 debug_print_backtrace();
242 // Logs the attack attempt
243 function crackerTrackerLogAttack () {
244 // Aquire database link
245 aquireCrackerTrackerDatabaseLink();
247 // By default no proxy is used
250 // Did the attacker use a proxy?
251 if (isCrackerTrackerProxyUsed()) {
256 // Prepare array for database insert
258 'remote_addr' => determineCrackerTrackerRealRemoteAddress(),
259 'user_agent' => crackerTrackerUserAgent(),
260 'get_data' => crackerTrackerQueryString(),
261 'post_data' => $GLOBALS['ctracker_post_track'],
262 'check_worm' => $GLOBALS['ctracker_checkworm'],
263 'check_post' => $GLOBALS['ctracker_check_post'],
264 'server_name' => crackerTrackerServerName(),
265 'script_name' => crackerTrackerScriptName(),
266 'referer' => crackerTrackerReferer(),
267 'proxy_used' => $proxyUsed,
268 'first_attempt' => 'NOW()'
271 // Insert the array in database
272 crackerTrackerInsertArray('ctracker_data', $rowData);
275 // Alerts the current user about malicious/suspicious traffic
276 function crackerTrackerAlertCurrentUser () {
277 // Is there some data?
278 if (isset($GLOBALS['ctracker_last_suspicious_entry'])) {
279 // Does the user have a ticket?
280 if (ifCrackerTrackerIpHasTicket()) {
281 // Should we continue?
282 if (isset($_POST['ctracker_continue'])) {
284 sendCrackerTrackerCookie();
286 // And redirect to same URL
287 crackerTrackerRedirectSameUrl();
288 } elseif (ifCrackerTrackerCookieIsSet()) {
289 // Return here to normal program
292 // Load "Thank you" template
293 crackerTrackerLoadTemplate('add_ticket_thanks');
295 } elseif ((isset($_POST['ctracker_add_ticket'])) && (!empty($_POST['name'])) && (!empty($_POST['email']))) {
297 addCrackerTrackerTicket($_POST);
299 // Send the email out
300 sendCrackerTrackerTicketMails();
302 // Display the form for new ticket
303 crackerTrackerLoadTemplate('add_ticket');