Coverage for /root/GitHubProjects/impacket/impacket/examples/utils.py : 100%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Impacket - Collection of Python classes for working with network protocols.
2#
3# SECUREAUTH LABS. Copyright (C) 2021 SecureAuth Corporation. All rights reserved.
4#
5# This software is provided under a slightly modified version
6# of the Apache Software License. See the accompanying LICENSE file
7# for more information.
8#
9# Description:
10# Utility and helper functions for the example scripts
11#
12# Author:
13# Martin Gallo (@martingalloar)
14#
15import re
18# Regular expression to parse target information
19target_regex = re.compile(r"(?:(?:([^/@:]*)/)?([^@:]*)(?::([^@]*))?@)?(.*)")
22# Regular expression to parse credentials information
23credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?")
26def parse_target(target):
27 """ Helper function to parse target information. The expected format is:
29 <DOMAIN></USERNAME><:PASSWORD>@HOSTNAME
31 :param target: target to parse
32 :type target: string
34 :return: tuple of domain, username, password and remote name or IP address
35 :rtype: (string, string, string, string)
36 """
37 domain, username, password, remote_name = target_regex.match(target).groups('')
39 # In case the password contains '@'
40 if '@' in remote_name:
41 password = password + '@' + remote_name.rpartition('@')[0]
42 remote_name = remote_name.rpartition('@')[2]
44 return domain, username, password, remote_name
47def parse_credentials(credentials):
48 """ Helper function to parse credentials information. The expected format is:
50 <DOMAIN></USERNAME><:PASSWORD>
52 :param credentials: credentials to parse
53 :type credentials: string
55 :return: tuple of domain, username and password
56 :rtype: (string, string, string)
57 """
58 domain, username, password = credential_regex.match(credentials).groups('')
60 return domain, username, password