Skip to content

Commit

Permalink
add TNS ping, status and version
Browse files Browse the repository at this point in the history
  • Loading branch information
bobsecurity authored and bobsecurity committed Oct 7, 2014
1 parent d2df822 commit 7ea88d5
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 21 deletions.
58 changes: 37 additions & 21 deletions Tnscmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ def __init__(self,args):
self.args = args
self.recvdata = ""
self.alias = []

def resetAlias (self):
self.version = ""

def getRecvData(self):
'''
reset alias
return a representation of received data
'''
logging.info ("alias list emptied")
self.alias = []
return repr(self.recvdata)

def getInformation(self,cmd='ping'):
'''
Get information about the oracle database service
'''
self.resetAlias()
logging.info ("alias list emptied")
self.recvdata = ""
command = "(CONNECT_DATA=(COMMAND={0}))".format(cmd)
commandlen = len(command)
#logging.info("Sending {0} to {1}:{2} in order to get ALIAS".format(command,self.args['server'],self.args['port']))
Expand Down Expand Up @@ -70,37 +71,52 @@ def getInformation(self,cmd='ping'):
except Exception,e:
logging.critical("Connection Error: {0}".format(e))
# 1st 12 bytes have some meaning which so far eludes me
logging.info('Data received thanks to the {1} cmd: {0}'.format(repr(self.recvdata),cmd))
self.__getAliasStrg__()

def __getAliasStrg__(self):
'''
load aliasstring from self.recvdata
'''
alias = re.findall(r'(?<=ALIAS).+?(?=\))', self.recvdata, flags=re.IGNORECASE)
for anAlias in alias : self.alias.append(anAlias.replace('\n','').replace(' ','').replace('\t','').replace('=',''))
#logging.info("Alias found: {0}".format(self.alias))
logging.info("Data received thanks to the '{1}' cmd: {0}".format(repr(self.recvdata),cmd))

def getAlias(self):
'''
return alias list
'''
self.getInformation()
self.alias = []
self.getInformation(cmd='ping')
alias = re.findall(r'(?<=ALIAS=).+?(?=\))', self.recvdata, flags=re.IGNORECASE)
for anAlias in alias : self.alias.append(anAlias.replace('\n','').replace(' ','').replace('\t',''))
return self.alias

def getVersion(self):
'''
return version from VSNNUM
'''
self.version = ""
self.getInformation(cmd='version')
vsnnum = re.findall(r'(?<=VSNNUM=).+?(?=\))', self.recvdata, flags=re.IGNORECASE)
hexversion = str(hex(int(vsnnum[0])))[2:]
if len(hexversion)%2 !=0 : hexversion='0'+hexversion
versionList = re.findall('..?',hexversion)
for v in versionList : self.version += str(int(v,16)) + '.'
return self.version


def runTnsCmdModule(args):
'''
run the TNS cmd module
'''
if args['ping'] == False :
logging.critical("You must choose the --ping option")
if args['ping'] == False and args['version'] == False and args['status'] == False:
logging.critical("You must choose --ping or/and --version or/and --status")
return EXIT_MISS_ARGUMENT
args['print'].title("Searching ALIAS on the {0} server, port {1}".format(args['server'],args['port']))
tnscmd = Tnscmd(args)
if args['ping'] == True:
args['print'].title("Searching ALIAS on the {0} server, port {1}".format(args['server'],args['port']))
alias = tnscmd.getAlias()
args['print'].goodNews("{0} ALIAS received: {1}. You should use this alias (more or less) as Oracle SID.".format(len(alias),alias))
#print alias
if args['version'] == True:
args['print'].title("Searching the version of the Oracle database server ({0}) listening on the port {1}".format(args['server'],args['port']))
version = tnscmd.getVersion()
args['print'].goodNews("The remote database version is: '{0}'".format(version))
if args['status'] == True:
args['print'].title("Searching the server status of the Oracle database server ({0}) listening on the port {1}".format(args['server'],args['port']))
tnscmd.getInformation(cmd='status')
args['print'].goodNews("Data received by the database server: '{0}'".format(tnscmd.getRecvData()))



Expand Down
2 changes: 2 additions & 0 deletions odat.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ def main():
PPTnsCmd = argparse.ArgumentParser(add_help=False,formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=MAX_HELP_POSITION))
PPTnsCmd._optionals.title = "TNS cmd options"
PPTnsCmd.add_argument('--ping', dest='ping', action='store_true', required=False, default=False, help='send a TNS ping command to get alias')
PPTnsCmd.add_argument('--version', dest='version', action='store_true', required=False, default=False, help='send a TNS version command to try to get verion')
PPTnsCmd.add_argument('--status', dest='status', action='store_true', required=False, default=False, help='send a TNS status command to get the status')
#1.3- Parent parser: SID Guesser
PPsidguesser = argparse.ArgumentParser(add_help=False,formatter_class=lambda prog: argparse.HelpFormatter(prog, max_help_position=MAX_HELP_POSITION))
PPsidguesser._optionals.title = "SID guesser options"
Expand Down

0 comments on commit 7ea88d5

Please sign in to comment.