Auditing an Oracle database for security issues is very important. PeteFinnigan.com provides all of the information and tools that you will need Click here for details of PeteFinnigan.com Limited's detailed Oracle database security audit service Click here for details of PeteFinnigan.com Limited's Oracle Security Training Courses
Cookie Policy:We only use essential cookies on small sections of this website. For details see here.

Welcome, Guest. Please Login.
Nov 17th, 2017, 9:21pm
News: Welcome to Pete Finnigan's Oracle security forum
Home | Help | Search | Members | Login
   Pete Finnigan's Oracle Security Forum
   Oracle Security
   Oracle Security
(Moderator: Pete Finnigan)
   Detecting brute forcing listener password
« Previous topic | Next topic »
Pages: 1  Reply | Notify of replies | Send Topic | Print
   Author  Topic: Detecting brute forcing listener password  (Read 3996 times)
isaez
PeteFinnigan.com Junior Member
**



Ivan

   
View Profile |

Gender: male
Posts: 76
Detecting brute forcing listener password
« on: Dec 9th, 2005, 2:32pm »
Quote | Modify

Hi,
 
Pete and others have talked about the listener security. It has no features like lock out after x failures, no password aging/management, etc. So the password can be brute forced. I have written a perl script that continuously scans the listener log file for tns-01169 errors. Tns-01169 is not necessarily  a synonym for a bad password but IMHO it is a valid assumption that a tns-01169 error will follow after a wrong password. A hacker would try a password and then (eg.) a status command to see if he has guessed the correct password. In case he chooses a wrong password this would generate the tns-01169 error. In case he guesses the correct password we are in trouble Sad
My perl script checks the listener log for the tns-01169 every minute and email the administrator in case it founds an tns-01169 in the log for the scan period. Tns-01169 previously found are not emaild again. The scan period is one minute. It is a very simple script that can be easily converted to a Shell script. It can be easily improved: for example instead of emailing an alert it could be programmed to stop the listener after x attempts (=tns-01169).
Anyway I'm posting the script and use it at your own risk.
You have to enable the listener logging.
 
Ivan
 
-------------------- perl script --------------------
Code:

#!/usr/bin/perl
 
# Function: scans continuously every minute the Oracle
#      listener-log file for tns-1169. If such an event occurs then
#      email the administrator.
# Author  : I.A. Saez Scheihing (saezscheihing@gmail.com)
# Version : 1.0.x.x.
# Date    : 09-Dec-2005
# Run     : To have it active day & night : nohup perl ./scan_listener_log.pl &
 
my $command,$commandcode,$tmp1,$tmp2,$tmp3,$tmp4;
my $listener_log = "$ENV{'ORACLE_HOME'}".'/network/log/listener.log';
my $scan_debug   = 0;     # change to 1 to see  debug information
my $search_for   = '\* 1169';  # tns-01169 means: The listener has
      # not recognized the password
my $date_time    = '';
my $email   = 'youremail\@yours.com';  # email-address administrator
 
print "$listener_log\n" if $scan_debug;
 
while (1==1) {  # while forever
   $date_time  = &datum;
   print "$date_time\n" if $scan_debug;
   #
   # open log file and start searching for $search_for in $date_time period
 
   open(LOG, $listener_log) || die "Can't open listener log: $listener_log\n";
   print "scanning for $date_time and $search_for\n" if $scan_debug;
   while (<LOG>) {
    chop;
    if (/$date_time/ && /$search_for/) {
     # in this period ($date_time) some tried  an unauthorized command and
     # got a tns-01169 error
     ($tmp1,$tmp2,$tmp3,$command,$tmp4,$commandcode) = split(/ /);
     $message = "At $date_time someone issued an unauthorized $command command(TNS-$commandcode)";
     &email_admin;        # email alert message to admin
     print "Alert!! $message\n" if $scan_debug;
    }      # if (/$date_time/ && /$search_for/) {
   }       # while (<LOG>) {
   close(LOG);
   sleep 60;  # sleep 1 minute
}      # while (1==1)
 
exit;
 
sub datum {
 my $sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst;
 
 ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
 $mon  = (JAN,FEB,MAR,APR,MEI,JUN,JUL,AUG,SEP,OCT,NOV,DEC)[$mon];
 $mday  = sprintf("%02d",$mday);  #leftpad day if necessary: 9 gets converted to 09
 $hour  = sprintf("%02d",$hour);
 $min   = sprintf("%02d",$min);
 $year = $year+1900;
 return ($mday . "-" . $mon . "-" . $year . " " .$hour.":".$min);
}
 
sub email_admin {
my $sendmail = '/usr/lib/sendmail -t -oi';
 
my $fromname = "Oracle";
open(MAIL,"| $sendmail") || die "Could not fork sendmail: $!";
 
print MAIL <<EOM;
Subject: Alert! Unauthorized listener commands!
From: $fromname
To: $email
 
 
 $message
EOM
 
close(MAIL);
}
 
IP Logged

regards,

Ivan
Pete Finnigan
PeteFinnigan.com Administrator
*****




Oracle Security is easier if you design for it

   
View Profile | WWW | Email

Gender: male
Posts: 309
Re: Detecting brute forcing listener password
« Reply #1 on: Dec 10th, 2005, 9:53pm »
Quote | Modify

Hi Ivan,
 
Thanks very much for this script. It will prove useful as a starting point for people who want to monitor their listener logs.
 
Great!
 
cheers
 
Pete
IP Logged

Pete Finnigan (email:pete@petefinnigan.com)
Oracle Security Web site: http://www.petefinnigan.com
Forum: http://www.petefinnigan.com/forum/yabb/YaBB.cgi
Oracle security blog: http://www.petefinnigan.com/weblog/entries/index.html
stone
PeteFinnigan.com Newbie
*



I love YaBB 1G - SP1!

   
View Profile |

Posts: 1
Re: Detecting brute forcing listener password
« Reply #2 on: Dec 12th, 2005, 5:53pm »
Quote | Modify

Hey, I have a smiliar script I use to monitor my listener log file.  The only caveat is if you rotate your logs then you'll have to restart it.  I keep a file pointer open to the logfile and just scan what has changed since the last round.  I have a similiar script I use to monitor the alert log.
 
Code:
#!/usr/bin/perl -w
 
if ($#ARGV !=1) {
  die "Usage:  check_alert.pl <hostname> <path_to_listener_log> ex.  MyHost /var/opt/oracle/listener.log.\n";
}
sleep 2;
 
$interval=1200;   # How many seconds before we check to see if data has been written to the logfile;
$email_threshold=5;  # How many errors within the interval before an email gets sent;
$hostname=$ARGV[0];
$file=$ARGV[1];
open(filePtr, $file) or die "Can't find $file\n";
 
 
for (;;) {
  @errors=("Subject: Listener Password  Errors for $hostname\n");
  $currTime = localtime(time);
  push(@errors,"Here are some errors found at $currTime for $hostname.\n");
 
  while (<filePtr>) {
   chop $_;
   if (/TNS-01169/) {
  push(@errors, "$_\n");
   }
  }
 
  if ($#errors > $email_threshold)  {
   $rndExt = time;
   $rndFile = "alert_errors_$rndExt";
   open (TMPFILE, ">/tmp/$rndFile");
 
   foreach $error (@errors) {
   print TMPFILE $error;
   }
   close(TMPFILE);
   system ("mail user\@mycompany.com < /tmp/$rndFile");
   system ("rm /tmp/$rndFile");
  }
 
  sleep $interval;
  seek filePtr, 0, 1;
}
IP Logged
Pete Finnigan
PeteFinnigan.com Administrator
*****




Oracle Security is easier if you design for it

   
View Profile | WWW | Email

Gender: male
Posts: 309
Re: Detecting brute forcing listener password
« Reply #3 on: Dec 14th, 2005, 6:26pm »
Quote | Modify

Thanks a lot for this script.
 
cheers
 
Pete
IP Logged

Pete Finnigan (email:pete@petefinnigan.com)
Oracle Security Web site: http://www.petefinnigan.com
Forum: http://www.petefinnigan.com/forum/yabb/YaBB.cgi
Oracle security blog: http://www.petefinnigan.com/weblog/entries/index.html
rereidy
PeteFinnigan.com Newbie
*



I love YaBB 1G - SP1!

   
View Profile |

Posts: 8
Re: Detecting brute forcing listener password
« Reply #4 on: Dec 15th, 2005, 11:45pm »
Quote | Modify

Pete,
 
I use swatch (http://swatch.sourceforge.net/) for the listeners at my site.  I have a config file which I use to notify us when there are issues:
 
watchfor /TNS\-01169:.* not recognized the password/
  mail=it-help@here,subject=TNS password failure
  throttle 01:00:00
 
Fortunately, I have had not atttempts to hack the listener.
 
It does present an issue for log rotation, but I have overcome this by stopping the listener and then the swatch process, move the log file, and then restart the processes.
 
I could have rolled my own Perl solution, but this looked interesting and we use swatch now for many other log file watching.
 
Ron Reidy
IP Logged
Pete Finnigan
PeteFinnigan.com Administrator
*****




Oracle Security is easier if you design for it

   
View Profile | WWW | Email

Gender: male
Posts: 309
Re: Detecting brute forcing listener password
« Reply #5 on: Dec 16th, 2005, 9:30pm »
Quote | Modify

Thanks very much for this Ron, this is a very simple solution to the issue of monitoring the listener log. This method as can be seen would be very easy to apply to other logs and easy to configure to watch for anything in them. I recommend the use of swatch in the SANS course and the book. This is a great, simple example.
 
thanks
 
Pete
IP Logged

Pete Finnigan (email:pete@petefinnigan.com)
Oracle Security Web site: http://www.petefinnigan.com
Forum: http://www.petefinnigan.com/forum/yabb/YaBB.cgi
Oracle security blog: http://www.petefinnigan.com/weblog/entries/index.html
Pages: 1  Reply | Notify of replies | Send Topic | Print

« Previous topic | Next topic »

Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright 2000-2004 Yet another Bulletin Board