Hide keyboard shortcuts

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 

16 

17 

18# Regular expression to parse target information 

19target_regex = re.compile(r"(?:(?:([^/@:]*)/)?([^@:]*)(?::([^@]*))?@)?(.*)") 

20 

21 

22# Regular expression to parse credentials information 

23credential_regex = re.compile(r"(?:(?:([^/:]*)/)?([^:]*)(?::(.*))?)?") 

24 

25 

26def parse_target(target): 

27 """ Helper function to parse target information. The expected format is: 

28 

29 <DOMAIN></USERNAME><:PASSWORD>@HOSTNAME 

30 

31 :param target: target to parse 

32 :type target: string 

33 

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('') 

38 

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] 

43 

44 return domain, username, password, remote_name 

45 

46 

47def parse_credentials(credentials): 

48 """ Helper function to parse credentials information. The expected format is: 

49 

50 <DOMAIN></USERNAME><:PASSWORD> 

51 

52 :param credentials: credentials to parse 

53 :type credentials: string 

54 

55 :return: tuple of domain, username and password 

56 :rtype: (string, string, string) 

57 """ 

58 domain, username, password = credential_regex.match(credentials).groups('') 

59 

60 return domain, username, password