Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/admin/teradata/teradata_odbc_sql.py
Views: 11784
#!/usr/bin/env python31# -*- coding: utf-8 -*-2#2018-05-09 14-1534# Standard Modules5import logging67# Extra Modules8dependencies_missing = False9try:10import teradata11except ImportError:12dependencies_missing = True1314from metasploit import module151617# Metasploit Metadata18metadata = {19'name': 'Teradata ODBC SQL Query Module',20'description': '''21SQL query module for ODBC connections to local Teradata databases.2223Port specification (TCP 1025 by default) is not necessary for ODBC connections.2425Requires ODBC driver and Python Teradata module.26''',27'authors': [28'Ted Raffle (actuated)'29],30'date': '2018-03-29',31'license': 'MSF_LICENSE',32'references': [33{'type': 'url', 'ref': 'https://developer.teradata.com/tools/reference/teradata-python-module'},34{'type': 'url', 'ref': 'https://downloads.teradata.com/download/connectivity/odbc-driver/linux'}35],36'type': 'single_scanner',37'options': {38'rhost': {'type': 'address', 'description': 'Host to target', 'required': True},39'rport': {'type': 'port', 'description': 'Port to target, ignored by the ODBC driver', 'required': True, 'default': 1025},40'username': {'type': 'string', 'description': 'Username', 'required': True, 'default': 'dbc'},41'password': {'type': 'string', 'description': 'Password', 'required': True, 'default': 'dbc'},42'sql': {'type': 'string', 'description': 'SQL query to perform', 'required': True, 'default': 'SELECT DATABASENAME FROM DBC.DATABASES'},43},44'notes': {45'AKA': ['Teradata ODBC Authentication Scanner']46}47}484950# Run function51def run(args):5253# Define UdaExec ODBC connection "application", must be before LogHandler54udaExec = teradata.UdaExec(appName="Auth", version="1.0", logConsole=False, configureLogging=False)5556# Metasploit LogHandler57module.LogHandler.setup(msg_prefix='{} - '.format(args['rhost']))5859# Return error for missing dependency60if dependencies_missing:61logging.error('Python Teradata module missing, cannot continue')62return6364# Set variables to current RHOST, and USERNAME and PASSWORD options65host = args['rhost']66user = args['username']67password = args['password']6869# Perform login attempt70module.log(host + ' - ' + user + ':' + password + ' - Starting')71try:72session = udaExec.connect(method="odbc", system=host, username=user, password=password);73except teradata.api.Error as e:74logging.error(user + ':' + password + ' - ' + format(e))75return76else:77module.log(host + ' - ' + user + ':' + password + ' - Login Successful', level='good')78try:79query = args['sql']80module.log(host + ' - Starting - ' + query)81for row in session.execute(query):82outputRow=str(row)83module.log(host + ' - ' + outputRow, level='good')84except teradata.api.Error as e:85logging.error(format(e))86return878889if __name__ == '__main__':90module.run(metadata, run)919293