Files
fortra-impacket/impacket/examples/utils.py
T
Martin Gallo cd4fe47cfc Arrange tagline, copyright and license notes across all source files
This was a pending change to:
- Use the same tagline, copyright and license notice across files.
- Remove authors' contacts that are no longer valid (due to affiliation changes).
- Update repository location.
- Update license file with missing licenses (althought those were already in source files).

This doesn't include any change on the source code, nor any change on current copyright or licenses. Just formatting and phrasing to make our and distro's maintainers life easier.
2021-07-20 10:04:27 -03:00

61 lines
1.8 KiB
Python

# Impacket - Collection of Python classes for working with network protocols.
#
# SECUREAUTH LABS. Copyright (C) 2021 SecureAuth Corporation. All rights reserved.
#
# This software is provided under a slightly modified version
# of the Apache Software License. See the accompanying LICENSE file
# for more information.
#
# Description:
# Utility and helper functions for the example scripts
#
# Author:
# Martin Gallo (@martingalloar)
#
import re
# Regular expression to parse target information
target_regex = re.compile(r"(?:(?:([^/@:]*)/)?([^@:]*)(?::([^@]*))?@)?(.*)")
# Regular expression to parse credentials information
credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?")
def parse_target(target):
""" Helper function to parse target information. The expected format is:
<DOMAIN></USERNAME><:PASSWORD>@HOSTNAME
:param target: target to parse
:type target: string
:return: tuple of domain, username, password and remote name or IP address
:rtype: (string, string, string, string)
"""
domain, username, password, remote_name = target_regex.match(target).groups('')
# In case the password contains '@'
if '@' in remote_name:
password = password + '@' + remote_name.rpartition('@')[0]
remote_name = remote_name.rpartition('@')[2]
return domain, username, password, remote_name
def parse_credentials(credentials):
""" Helper function to parse credentials information. The expected format is:
<DOMAIN></USERNAME><:PASSWORD>
:param credentials: credentials to parse
:type credentials: string
:return: tuple of domain, username and password
:rtype: (string, string, string)
"""
domain, username, password = credential_regex.match(credentials).groups('')
return domain, username, password