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