Python smb.SMBConnection.SMBConnection() Examples

The following are 9 code examples of smb.SMBConnection.SMBConnection(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module smb.SMBConnection , or try the search function .
Example #1
Source File: crack_smb.py    From xunfengES with GNU General Public License v3.0 7 votes vote down vote up
def check(ip,port,timeout):
    socket.setdefaulttimeout(timeout)
    user_list = ['administrator']
    hostname = ip2hostname(ip)
    PASSWORD_DIC.insert(0,'anonymous')
    if not hostname:return
    for user in user_list:
        for pass_ in PASSWORD_DIC:
            try:
                pass_ = str(pass_.replace('{user}', user))
                conn = SMBConnection(user,pass_,'xunfeng',hostname)
                if conn.connect(ip) == True:
                    if pass_ == 'anonymous':return u"存在匿名共享,请查看是否存在敏感文件。"
                    return u"存在弱口令,用户名:%s 密码:%s"%(user,pass_)
            except Exception,e:
                if "Errno 10061" in str(e) or "timed out" in str(e): return 
Example #2
Source File: crack_smb.py    From xunfengES with GNU General Public License v3.0 7 votes vote down vote up
def check(ip,port,timeout):
    socket.setdefaulttimeout(timeout)
    user_list = ['administrator']
    hostname = ip2hostname(ip)
    PASSWORD_DIC.insert(0,'anonymous')
    if not hostname:return
    for user in user_list:
        for pass_ in PASSWORD_DIC:
            try:
                pass_ = str(pass_.replace('{user}', user))
                conn = SMBConnection(user,pass_,'xunfeng',hostname)
                if conn.connect(ip) == True:
                    if pass_ == 'anonymous':return u"存在匿名共享,请查看是否存在敏感文件。"
                    return u"存在弱口令,用户名:%s 密码:%s"%(user,pass_)
            except Exception,e:
                if "Errno 10061" in str(e) or "timed out" in str(e): return 
Example #3
Source File: samba.py    From jupyter-fs with Apache License 2.0 6 votes vote down vote up
def resource(self):
        kwargs = dict(
            username=smb_user,
            password=smb_passwd,
            my_name=self.my_name,
            remote_name=self.hostname,
            is_direct_tcp=self.direct_tcp,
        )

        conn = SMBConnection(**kwargs)

        # actually connect
        if self.smb_port is not None:
            assert conn.connect(self.host, port=self.smb_port)
        else:
            assert conn.connect(self.host)

        return conn 
Example #4
Source File: SMB.py    From content with MIT License 5 votes vote down vote up
def connect(hostname, domain, user, password, nb_name, port):
    if not domain:
        connection = SMBConnection(user, password, 'Demisto', nb_name, is_direct_tcp=True)
    else:
        connection = SMBConnection(user, password, 'Demisto', nb_name, domain=domain, is_direct_tcp=True)
    if not connection.connect(hostname, port):
        return_error('Authentication failed, verify instance configuration parameters and try again.')
    return connection 
Example #5
Source File: libsmb.py    From addon with GNU General Public License v3.0 5 votes vote down vote up
def connect(url):
    # logger.info("Url: %s" % url)
    global remote
    server_name, server_ip, share_name, path, user, password, domain = parse_url(url)
    
    #Da problemas asumir que la sesión está abierta.  Si se abrió pero ha caducado, dará error.  Mejor conectar siempre
    """
    if not remote or not remote.sock or not server_name == remote.remote_name:
        remote = SMBConnection(user, password, domain, server_name)
        remote.connect(server_ip, 139)
    """
    remote = SMBConnection(user, password, domain, server_name)
    remote.connect(ip=server_ip, timeout=20)

    return remote, share_name, path 
Example #6
Source File: HiddenNetworks.py    From HiddenNetworks-Python with GNU General Public License v3.0 5 votes vote down vote up
def usbfirstconnectremote(usbserial,remotecompname,remoteuser, remotepassword):
    array_dates = []
    array_time = []
    a = 0
    data_folder="C$"
    conn=SMBConnection(remoteuser, remotepassword, "hn", remotecompname,use_ntlm_v2 = True,domain='testdomain')
    conn.connect(remotecompname,139)

    with open('tempohn.tmp','wb') as devlogfile:
        conn.retrieveFile(data_folder, '\Windows\inf\setupapi.dev.log', devlogfile)

        print("CONECTADO")
    print("USBSERIAL:", usbserial)

    devlogfile = open("tempohn.tmp", 'r')

    for line in devlogfile:
        if re.search(usbserial, line):
            line=next(devlogfile)
            # Split text strings to retrive date and time
            for word in line.split():
                if word.find(':')!=-1: # time
                    array_time.append(word)
                    #print(array_time)
                else:
                    array_dates.append(word)

            array_dates.remove('>>>')
            array_dates.remove('Section')
            array_dates.remove('start')

    mindate = min(array_dates)
    mintime = min(array_time)

    devlogfile.close()
    return (mindate, mintime)

# Class definition 
Example #7
Source File: libsmb.py    From pelisalacarta-ce with GNU General Public License v3.0 5 votes vote down vote up
def connect(url):
    #logger.info("Url: %s" % url)
    global remote
    server_name, server_ip, share_name, path, user, password, domain = parse_url(url)
    if not remote or not remote.sock or not server_name == remote.remote_name:
      remote = SMBConnection(user, password, domain, server_name)
      remote.connect(server_ip, 139)
  
    return remote, share_name, path 
Example #8
Source File: smb.py    From ActiveReign with GNU General Public License v3.0 5 votes vote down vote up
def smb_connect(server, user, passwd, domain, timeout):
    # Create SMB Connection using random client string
    client = ''.join([choice(ascii_letters + digits) for x in range(7)])
    con = SMBConnection(user, passwd, client, server, domain=domain, use_ntlm_v2=True, is_direct_tcp=True)
    con.connect(server, 445, timeout=timeout)
    return con 
Example #9
Source File: auth.py    From habu with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def authenticate(self):

        from smb.SMBConnection import SMBConnection

        # There will be some mechanism to capture userID, password, client_machine_name, server_name and server_ip
        # client_machine_name can be an arbitary ASCII string
        # server_name should match the remote machine name, or else the connection will be rejected

        #userID = 'xatportantier'
        userID = 'guest'
        #password = 'SecurFMP_23'
        password = ''
        client_machine_name = 'fmp'
        server_ip = '192.1.3.120'
        server_name = 'Server72'
        server_name = ''

        from nmb.NetBIOS import NetBIOS

        nb = NetBIOS(broadcast=True, listen_port=0)
        #print('ip', nb.queryName(server_name, port=445))
        #print('name', nb.queryIPForName(server_ip))


        conn = SMBConnection(userID, password, client_machine_name, server_name, use_ntlm_v2=True, is_direct_tcp=False)
        from pprint import pprint
        for a in [ 'capabilities', 'domain', 'host_type', 'log', 'my_name', 'remote_name', 'security_mode', 'uid', 'username' ]:
            print(a, getattr(conn, a))
        #print('cap', conn.capabilities)
        #print('domain', conn.domain)

        print('auth', conn.connect(server_ip, 139))
        #print(conn.isUsingSMB2)
        #print(conn.echo('aaaaa'))
        #conn.listShares()