github.com/n00py/Slackor@v0.0.0-20200610224921-d007fcea1740/impacket/examples/mssqlinstance.py (about)

     1  #!/usr/bin/env python
     2  # SECUREAUTH LABS. Copyright 2018 SecureAuth Corporation. All rights reserved.
     3  #
     4  # This software is provided under under a slightly modified version
     5  # of the Apache Software License. See the accompanying LICENSE file
     6  # for more information.
     7  #
     8  # Description: [MC-SQLR] example. Retrieves the instances names from the target host
     9  #
    10  # Author:
    11  #  Alberto Solino (@agsolino)
    12  #
    13  # Reference for:
    14  #  Structure
    15  #
    16  
    17  from __future__ import division
    18  from __future__ import print_function
    19  import argparse
    20  import sys
    21  import logging
    22  
    23  from impacket.examples import logger
    24  from impacket import version, tds
    25  
    26  if __name__ == '__main__':
    27  
    28      print(version.BANNER)
    29      # Init the example's logger theme
    30      logger.init()
    31  
    32      parser = argparse.ArgumentParser(add_help = True, description = "Asks the remote host for its running MSSQL Instances.")
    33  
    34      parser.add_argument('host', action='store', help='target host')
    35      parser.add_argument('-timeout', action='store', default='5', help='timeout to wait for an answer')
    36  
    37      if len(sys.argv)==1:
    38          parser.print_help()
    39          sys.exit(1)
    40   
    41      options = parser.parse_args()
    42  
    43      ms_sql = tds.MSSQL(options.host)
    44      instances = ms_sql.getInstances(int(options.timeout))
    45      if len(instances) == 0:
    46          "No MSSQL Instances found"
    47      else:
    48          for i, instance in enumerate(instances):
    49              logging.info("Instance %d" % i)
    50              for key in list(instance.keys()):
    51                 print(key + ":" + instance[key])