<s> import argparse <EOL> import sys <EOL> import string <EOL> import os <EOL> import logging <EOL> from impacket . examples import logger <EOL> from impacket import version , tds <EOL> if __name__ == '<STR_LIT:__main__>' : <EOL> import cmd <EOL> class SQLSHELL ( cmd . Cmd ) : <EOL> def __init__ ( self , SQL ) : <EOL> cmd . Cmd . __init__ ( self ) <EOL> self . sql = SQL <EOL> self . prompt = '<STR_LIT>' <EOL> self . intro = '<STR_LIT>' <EOL> def do_help ( self , line ) : <EOL> print """<STR_LIT>""" <EOL> def do_shell ( self , s ) : <EOL> os . system ( s ) <EOL> def do_xp_cmdshell ( self , s ) : <EOL> try : <EOL> self . sql . sql_query ( "<STR_LIT>" % s ) <EOL> self . sql . printReplies ( ) <EOL> self . sql . colMeta [ <NUM_LIT:0> ] [ '<STR_LIT>' ] = <NUM_LIT> * <NUM_LIT:2> <EOL> self . sql . printRows ( ) <EOL> except : <EOL> pass <EOL> def do_lcd ( self , s ) : <EOL> if s == '<STR_LIT>' : <EOL> print os . getcwd ( ) <EOL> else : <EOL> os . chdir ( s ) <EOL> def do_enable_xp_cmdshell ( self , line ) : <EOL> try : <EOL> self . sql . sql_query ( "<STR_LIT>" ) <EOL> self . sql . printReplies ( ) <EOL> self . sql . printRows ( ) <EOL> except : <EOL> pass <EOL> def do_disable_xp_cmdshell ( self , line ) : <EOL> try : <EOL> self . sql . sql_query ( "<STR_LIT>" ) <EOL> self . sql . printReplies ( ) <EOL> self . sql . printRows ( ) <EOL> except : <EOL> pass <EOL> def default ( self , line ) : <EOL> try : <EOL> self . sql . sql_query ( line ) <EOL> self . sql . printReplies ( ) <EOL> self . sql . printRows ( ) <EOL> except : <EOL> pass <EOL> def emptyline ( self ) : <EOL> pass <EOL> def do_exit ( self , line ) : <EOL> return True <EOL> logger . init ( ) <EOL> print version . BANNER <EOL> parser = argparse . ArgumentParser ( add_help = True , description = "<STR_LIT>" ) <EOL> parser . add_argument ( '<STR_LIT:target>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , default = '<STR_LIT>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , default = '<STR_LIT:False>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , action = '<STR_LIT:store_true>' , help = '<STR_LIT>' ) <EOL> parser . add_argument ( '<STR_LIT>' , type = argparse . FileType ( '<STR_LIT:r>' ) , help = '<STR_LIT>' ) <EOL> group = parser . add_argument_group ( '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , metavar = "<STR_LIT>" , help = '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , help = '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store_true>" , help = '<STR_LIT>' ) <EOL> group . add_argument ( '<STR_LIT>' , action = "<STR_LIT:store>" , metavar = "<STR_LIT>" , help = '<STR_LIT>' ) <EOL> if len ( sys . argv ) == <NUM_LIT:1> : <EOL> parser . print_help ( ) <EOL> sys . exit ( <NUM_LIT:1> ) <EOL> options = parser . parse_args ( ) <EOL> if options . debug is True : <EOL> logging . getLogger ( ) . setLevel ( logging . DEBUG ) <EOL> else : <EOL> logging . getLogger ( ) . setLevel ( logging . INFO ) <EOL> import re <EOL> domain , username , password , address = re . compile ( '<STR_LIT>' ) . match ( options . target ) . groups ( '<STR_LIT>' ) <EOL> if '<STR_LIT:@>' in address : <EOL> password = password + '<STR_LIT:@>' + address . rpartition ( '<STR_LIT:@>' ) [ <NUM_LIT:0> ] <EOL> address = address . rpartition ( '<STR_LIT:@>' ) [ <NUM_LIT:2> ] <EOL> if domain is None : <EOL> domain = '<STR_LIT>' <EOL> if password == '<STR_LIT>' and username != '<STR_LIT>' and options . hashes is None and options . no_pass is False and options . aesKey is None : <EOL> from getpass import getpass <EOL> password = getpass ( "<STR_LIT>" ) <EOL> if options . aesKey is not None : <EOL> options . k = True <EOL> ms_sql = tds . MSSQL ( address , string . atoi ( options . port ) ) <EOL> ms_sql . connect ( ) <EOL> try : <EOL> if options . k is True : <EOL> res = ms_sql . kerberosLogin ( options . db , username , password , domain , options . hashes , options . aesKey ) <EOL> else : <EOL> res = ms_sql . login ( options . db , username , password , domain , options . hashes , options . windows_auth ) <EOL> ms_sql . printReplies ( ) <EOL> except Exception , e : <EOL> logging . error ( str ( e ) ) <EOL> res = False <EOL> if res is True : <EOL> shell = SQLSHELL ( ms_sql ) <EOL> if options . file is None : <EOL> shell . cmdloop ( ) <EOL> else : <EOL> for line in options . file . readlines ( ) : <EOL> print "<STR_LIT>" % line , <EOL> shell . onecmd ( line ) <EOL> ms_sql . disconnect ( ) </s>
