Call: +44 (0)1904 557620 Call
Forum

Welcome, Guest. Please Login.
Mar 29th, 2024, 7:00am
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 5632 times)
Pete Finnigan
PeteFinnigan.com Administrator
*****




Oracle Security is easier if you design for it

   
View Profile | WWW | Email

Gender: male
Posts: 309
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

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
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
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 #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 (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
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
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 #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 (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
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
  • PFCLScan PFCLScan

    Simply connect PFCLScan to your Oracle database and it will automatically discover the security issues that could make your Oracle database vulnerable to attack and to the potential loss of your data.

  • PFCL Obfuscate PFCLObfuscate

    PFCLObfuscate is the only tool available that can automatically add license controls to your PL/SQL code. PFCLObfuscate protects your Intellectual Property invested in your PL/SQL database code.

  • PFCLCode PFCLCode

    PFCLCode is a tool to allow you to analyse your PL/SQL code for many different types of security issues. PFCLCode gives you a detailed review and reports and includes a powerful colour syntax highlighting code editor

  • PFCLForensics PFCLForensics

    PFCLForensics is the only tool available to allow you to do a detailed live response of a breached Oracle database and to then go on and do a detailed forensic analysis of the data gathered.

  • Products We resell PFCLReselling

    PeteFinnigan.com Limited has partnered with a small number of relevant companies to resell their products where they enhance or compliment what we do

  • PFCLATK PFCLATK

    PFCLATK is a toolkit that allows detailed pre-defined policy driven audit trails for your Oracle database. The toolkit also provides for a centralised audit trail and centralised activity reporting

  • PFCLCookie PFCLCookie

    PFCLCookie is a useful tool to use to audit your websites for tracking cookies. Scan websites in a natural way using powerful browser driven scanner

  • PFCL Training PFCLTraining

    PFCLTraining is a set of expert training classes for you, aimed at teaching how to audit your own Oracle database, design audit trails, secure code in PL/SQL and secure and lock down your Oracle database.

  • PFCL Services PFCLServices

    Choose PFCLServices to add PeteFinnigan.com Ltd to your team for your Oracle Security needs. We are experts in performing detailed security audits, data security design work and policy creation

  • PFCLConsulting PFCLConsulting

    Choose PFCLConsulting to ask PeteFinnigan.com Limited to set up and use our products on your behalf

  • PFCLCustom PFCLCustom

    All of our software products can be customised at a number of levels. Choose this to see how our products can be part of your products and services

  • PFCLCloud PFCLCloud

    Private cloud, public cloud, hybrid cloud or no cloud. Learn how all of our services, trainings and products will work in the cloud

  • PFCLUserRights PFCLUserRights

    PFCLUserRights allows you to create a very detailed view of database users rights. The focus of the reports is to allow you to decide what privileges and accounts to keep and which to remove.

  • PFCLSTK PFCLSTK

    PFCLSTK is a toolkit application that allows you to provide database security easily to an existing database. PFCLSTK is a policy driven toolkit of PL/SQL that creates your security

  • PFCLSFTK PFCLSFTK

    PFCLSFTK is a toolkit that solves the problem of securing third party applications written in PL/SQL. It does this by creating a thin layer between the application and database and this traps SQL Injection attempts. This is a static firewall.

  • PFCLSEO PFCLSEO

    PFCLSEO is a web scanner based on the PFCLScan technology so that a user can easily scan a website for technical SEO issues