Example #1
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

            if (user != null && user.isAuthorized && linuxSystem.IsConnectedTheInternet &&
                linuxSystem != null)
            {
                string[] commandParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                User     victimUser    = await _unitOfWork.UserAccessRepository.GetByLinuxSystemIP(commandParams[1]);

                if (commandParams[0] == Name && victimUser != null)
                {
                    await client.SendTextMessageAsync(chatId, "<code>Поиск пользователей...</code>", ParseMode.Html);

                    await client.SendTextMessageAsync(chatId, $"<code>Login: {victimUser.UserName}</code>", ParseMode.Html);

                    return(true);
                }

                await client.SendTextMessageAsync(chatId, "<code>Неверный ip адрес или название команды.</code>", ParseMode.Html);

                return(false);
            }

            await client.SendTextMessageAsync(chatId, "<code>Произошла ошибка</code>", ParseMode.Html);

            return(false);
        }
Example #2
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null)
                {
                    CurrentDirectory currentDirectory = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                    if (currentDirectory != null)
                    {
                        Directory directory = await _unitOfWork.DirectoryRepository.GetByIdAsync(currentDirectory.DirectoryId);

                        await client.SendTextMessageAsync(chatId, $"<code>{directory.Path}</code>", ParseMode.Html);

                        return(true);
                    }

                    return(false);
                }

                return(false);
            }

            return(false);
        }
Example #3
0
        public async Task <IEnumerable <Directory> > GetDirsOfLinuxSystemId(int id)
        {
            LinuxSystem linuxSystem = await _db.LinuxSystems.Include(s => s.AllDirectories).FirstOrDefaultAsync(s => s.Id == id);

            IEnumerable <Directory> directories = linuxSystem.AllDirectories;

            return(directories);
        }
Example #4
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null)
                {
                    string[] commandParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (commandParams.Length == 2 && commandParams[0] == Name)
                    {
                        LinuxSystem victimSystem = await _unitOfWork.LinuxRepository.GetByIP(commandParams[1]);

                        if (victimSystem != null)
                        {
                            List <Vulnerability> vulnerabilities = _unitOfWork.VulnerabilityRepository.GetVulnerabilitiesByLinuxSystemId(victimSystem.Id);
                            if (vulnerabilities.Count > 0)
                            {
                                StringBuilder nmapInfo = new StringBuilder();

                                nmapInfo.Append("PORT       STATE\n");
                                foreach (var vulnerabiliti in vulnerabilities)
                                {
                                    foreach (var port in vulnerabiliti.Ports)
                                    {
                                        nmapInfo.Append($"{port.TypeOfPort}     {port.PortState}\n");
                                    }
                                }

                                await client.SendTextMessageAsync(chatId, $"<code>{nmapInfo}</code>", ParseMode.Html);

                                return(true);
                            }
                        }

                        await client.SendTextMessageAsync(chatId, "<code>Неверный IP адрес</code>", ParseMode.Html);

                        return(false);
                    }

                    await client.SendTextMessageAsync(chatId, "<code>Неверные параметры команды</code>", ParseMode.Html);

                    return(false);
                }
            }

            await client.SendTextMessageAsync(chatId, "<code>Пользователя не существует</code>", ParseMode.Html);

            return(false);
        }
Example #5
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                string[] parameters = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parameters[0] == "cd")
                {
                    var text = message.Text.Remove(0, 2).Trim();

                    LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                    if (linuxSystem != null)
                    {
                        CurrentDirectory currentDirectory = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                        if (currentDirectory != null)
                        {
                            Directory directory  = _unitOfWork.DirectoryRepository.GetInDirectory(await _unitOfWork.DirectoryRepository.GetByIdAsync(currentDirectory.DirectoryId));
                            Directory changedDir = directory.Directories.FirstOrDefault(d => d.Name == text);

                            if (changedDir != null)
                            {
                                user.LinuxSystem.CurrentDirectory.Directory = changedDir;

                                await _unitOfWork.SaveAsync();


                                await client.SendTextMessageAsync(chatId, "<code>Папка изменена</code>", ParseMode.Html);

                                return(true);
                            }
                            else
                            {
                                await client.SendTextMessageAsync(chatId, "<code>Директории не найдено</code>", ParseMode.Html);

                                return(false);
                            }
                        }

                        return(false);
                    }

                    return(false);
                }
            }

            return(false);
        }
Example #6
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                CurrentDirectory current = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                Directory directory = _unitOfWork.DirectoryRepository.GetInDirectory(await _unitOfWork.DirectoryRepository.GetByIdAsync(current.DirectoryId));

                var searchedDir = directory.Path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).ToList();
                searchedDir.Remove(searchedDir.Last());
                if (searchedDir.Count == 0)
                {
                    await client.SendTextMessageAsync(chatId, "<code>Вы в корне</code>", ParseMode.Html);

                    return(true);
                }

                string dirPath = "";
                foreach (var path in searchedDir)
                {
                    dirPath += path;
                }

                Directory searchedDirectory = await _unitOfWork.DirectoryRepository.GetByPath(dirPath);

                if (searchedDirectory != null)
                {
                    user.LinuxSystem.CurrentDirectory.Directory = searchedDirectory;

                    await _unitOfWork.SaveAsync();

                    await client.SendTextMessageAsync(chatId, "<code>Папка изменена</code>", ParseMode.Html);

                    return(true);
                }

                return(false);
            }

            return(false);
        }
Example #7
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null)
                {
                    WifiModule wifiModule = await _unitOfWork.WifiModuleRepository.GetByIdAsync(linuxSystem.WifiModuleId);

                    if (wifiModule != null)
                    {
                        StringBuilder lanDetails = new StringBuilder();
                        lanDetails.Append("<code>lo: flags=73 UP,LOOPBACK,RUNNING  mtu 1500\n" +
                                          "inet 127.0.0.1  netmask 255.0.0.0\n" +
                                          "inet6::1  prefixlen 128  scopeid 0xfe  compat, link, site, host \n" +
                                          "loop(Local Loopback) </code>");

                        await client.SendTextMessageAsync(chatId, lanDetails.ToString(), ParseMode.Html);

                        lanDetails.Clear();

                        lanDetails.Append($"<code>{wifiModule.Name}: flags=4163 UP,BROADCAST,RUNNING,MULTICAST  mtu 1500\n" +
                                          $"inet {linuxSystem.IP}  netmask 255.255.255.0  broadcast {linuxSystem.IP}\n" +
                                          "inet6 fe80::bd6d:680a: 8ca8: c15f  prefixlen 64  scopeid 0xfd  compat, link, site, host \n" +
                                          $"ether {linuxSystem.MACAddress}(Ethernet)\n" +
                                          $"Mode: {GetWifiMode(wifiModule.ModuleMode)}</code>");

                        await client.SendTextMessageAsync(chatId, lanDetails.ToString(), ParseMode.Html);

                        return(true);
                    }

                    return(false);
                }

                return(false);
            }

            return(false);
        }
Example #8
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null)
                {
                    WifiModule wifiModule = await _unitOfWork.WifiModuleRepository.GetByIdAsync(linuxSystem.WifiModuleId);

                    if (wifiModule != null && user.isAuthorized && wifiModule.ModuleMode == ModuleMode.Monitor)
                    {
                        StringBuilder wifis       = new StringBuilder();
                        List <Wifi>   moduleWifis = _unitOfWork.WifiRepository.GetByWifisModuleId(wifiModule.Id).ToList();

                        foreach (var wifi in moduleWifis)
                        {
                            wifis.Append($"BSSID: {wifi.BSSID}    SPEED: {wifi.Speed}мб/с    CH: {wifi.Channel}    CIP: {GetCipher(wifi.Cipher)}    ENC: {GetEncryption(wifi.EncryptionType)}    ESSID: {wifi.Name}\n");
                        }

                        await client.SendTextMessageAsync(chatId, $"<code>{wifis}</code>", ParseMode.Html);

                        return(true);
                    }

                    return(false);
                }

                return(false);
            }

            return(false);
        }
Example #9
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null)
                {
                    WifiModule wifiModule = await _unitOfWork.WifiModuleRepository.GetByIdAsync(linuxSystem.WifiModuleId);

                    if (wifiModule != null)
                    {
                        if (user.isAuthorized && wifiModule.ModuleMode == ModuleMode.Managed)
                        {
                            wifiModule.ModuleMode = ModuleMode.Monitor;
                            wifiModule.Name       = "wlan0mon";

                            await _unitOfWork.SaveAsync();

                            await client.SendTextMessageAsync(chatId, "<code>Режим изменён</code>", ParseMode.Html);

                            return(true);
                        }
                    }

                    return(false);
                }

                return(false);
            }

            return(false);
        }
Example #10
0
        public async Task <LinuxSystem> GetByIP(string ip)
        {
            LinuxSystem linuxSystem = await _db.LinuxSystems.FirstOrDefaultAsync(s => s.IP == ip);

            return(linuxSystem);
        }
Example #11
0
        public async Task <LinuxSystem> GetByIdAsync(int id)
        {
            LinuxSystem linuxSystem = await _db.LinuxSystems.FirstOrDefaultAsync(s => s.Id == id);

            return(linuxSystem);
        }
Example #12
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                if (linuxSystem != null && linuxSystem.IsConnectedTheInternet)
                {
                    string[] commandParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (commandParams[0] == Name && !string.IsNullOrWhiteSpace(commandParams[1]) &&
                        commandParams[2] == "-P")
                    {
                        File passwordFile = await _unitOfWork.FileRepository.GetByPath(commandParams[3]);

                        if (commandParams.Length == 5)
                        {
                            string[] sshParams = commandParams[4].Split(new string[] { "//" }, StringSplitOptions.RemoveEmptyEntries);
                            if (sshParams.Length == 2)
                            {
                                if (passwordFile != null && sshParams[0] == "ssh:" && !string.IsNullOrWhiteSpace(sshParams[1]))
                                {
                                    LinuxSystem victimSystem = await _unitOfWork.LinuxRepository.GetByIP(sshParams[1]);

                                    if (victimSystem != null)
                                    {
                                        List <Vulnerability> vulnerabilities = _unitOfWork.VulnerabilityRepository.GetVulnerabilitiesByLinuxSystemId(victimSystem.Id);
                                        if (vulnerabilities.Count > 0)
                                        {
                                            foreach (var vuln in vulnerabilities)
                                            {
                                                foreach (var port in vuln.Ports)
                                                {
                                                    await client.SendTextMessageAsync(chatId, "<code>Подбор пароля...</code>", ParseMode.Html);

                                                    if (passwordFile.Text.Contains(port.Password) && commandParams[1] == port.Login)
                                                    {
                                                        await client.SendTextMessageAsync(chatId, $"<code>[22][ssh]  host: {sshParams[1]}   login: {port.Login}   password: {port.Password}</code>", ParseMode.Html);

                                                        return(true);
                                                    }
                                                    else
                                                    {
                                                        await client.SendTextMessageAsync(chatId, "<code>Пароль не найден.</code>", ParseMode.Html);

                                                        return(false);
                                                    }
                                                }
                                            }
                                        }

                                        await client.SendTextMessageAsync(chatId, "<code>В системе нету уязвимостей</code>", ParseMode.Html);

                                        return(false);
                                    }

                                    await client.SendTextMessageAsync(chatId, "<code>Неверный IP адресс.</code>", ParseMode.Html);

                                    return(false);
                                }

                                await client.SendTextMessageAsync(chatId, "<code>Неверный IP адресс.</code>", ParseMode.Html);

                                return(false);
                            }
                        }

                        await client.SendTextMessageAsync(chatId, "<code>Проверьте корректность параметров команды.</code>", ParseMode.Html);

                        return(false);
                    }

                    await client.SendTextMessageAsync(chatId, "<code>Неверная команда.</code>", ParseMode.Html);

                    return(false);
                }

                await client.SendTextMessageAsync(chatId, "<code>Ошибка. Проверьте подключение к интернету.</code>", ParseMode.Html);

                return(false);
            }

            return(false);
        }
Example #13
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            if (user != null && user.isAuthorized)
            {
                string[] parameters = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (parameters[0] == Name && parameters[2] == "-w")
                {
                    LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                    CurrentDirectory currentDirectory = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                    Directory directory     = _unitOfWork.DirectoryRepository.GetInDirectory(await _unitOfWork.DirectoryRepository.GetByIdAsync(currentDirectory.DirectoryId));
                    string    fileExtension = "";
                    string    fileName      = "";

                    if (!parameters[1].Contains("/"))
                    {
                        fileExtension = parameters[1].Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        fileName      = parameters[1];
                    }
                    else
                    {
                        string filePath = parameters[1].Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries).Last();
                        fileExtension = filePath.Split(new char[] { '.' }, StringSplitOptions.RemoveEmptyEntries)[1];
                        fileName      = filePath;
                    }


                    File handShakeFile = directory.Files.FirstOrDefault(f => f.Name == parameters[1]);
                    File passwordFile  = null;
                    if (fileExtension == "cap" && handShakeFile != null)
                    {
                        if (parameters[3].Contains("/"))
                        {
                            passwordFile = await _unitOfWork.FileRepository.GetByPath(parameters[3]);
                        }
                        else
                        {
                            passwordFile = directory.Files.FirstOrDefault(f => f.Name == parameters[3]);
                        }

                        if (passwordFile != null)
                        {
                            WifiModule wifiModule = await _unitOfWork.WifiModuleRepository.GetByIdAsync(linuxSystem.WifiModuleId);

                            IEnumerable <Wifi> wifis = _unitOfWork.WifiRepository.GetByWifisModuleId(wifiModule.Id);

                            if (wifis.Count() > 0)
                            {
                                string password = Encoding.UTF8.GetString(Convert.FromBase64String(handShakeFile.Text));
                                if (passwordFile.Text.Contains(password))
                                {
                                    Wifi attackWifi = null;
                                    foreach (var wifi in wifis)
                                    {
                                        await client.SendTextMessageAsync(chatId, $"<code>[{DateTime.UtcNow}] Подбор пароля...</code>", ParseMode.Html);

                                        if (wifi.Password == password)
                                        {
                                            attackWifi = wifi;
                                            break;
                                        }
                                    }

                                    if (attackWifi != null)
                                    {
                                        linuxSystem.IsConnectedTheInternet = true;
                                        GlobalNetwork globalNetwork = await _unitOfWork.GlobalNetworkRepository.GetByIdAsync(attackWifi.GlobalNetworkId);

                                        if (globalNetwork != null)
                                        {
                                            user.GlobalNetwork = globalNetwork;
                                            await client.SendTextMessageAsync(chatId, $"<code>Пароль успешно найден, вы подсойдены к {attackWifi.Name}\nСкорость: {attackWifi.Speed}мб/с</code>", ParseMode.Html);

                                            wifiModule.ModuleMode = ModuleMode.Managed;
                                            wifiModule.Name       = "wlan0";

                                            await _unitOfWork.SaveAsync();

                                            return(true);
                                        }
                                        else
                                        {
                                            await client.SendTextMessageAsync(chatId, $"<code>Ошибка подлючения...</code>", ParseMode.Html);

                                            return(false);
                                        }
                                    }
                                }

                                await client.SendTextMessageAsync(chatId, "<code>Пароль не найдено</code>", ParseMode.Html);
                            }

                            return(false);
                        }

                        await client.SendTextMessageAsync(chatId, "<code>Файл с паролями не найден. Перейдите в папку с этим файлом или укажите путь.</code>", ParseMode.Html);

                        return(false);
                    }
                    else
                    {
                        await client.SendTextMessageAsync(chatId, "<code>Файл не найден. Перейдите в папку с этим файлом или укажите путь..</code>", ParseMode.Html);

                        return(false);
                    }
                }
                else
                {
                    await client.SendTextMessageAsync(chatId, "<code>Неверная команда</code>", ParseMode.Html);

                    return(false);
                }
            }

            return(false);
        }
Example #14
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            User user = await _unitOfWork.UserAccessRepository.GetUserByChatId(message.Chat.Id);

            if (user.isAuthorized)
            {
                StringBuilder dirs        = new StringBuilder();
                LinuxSystem   linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

                CurrentDirectory currentDirectory = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                Directory directory = _unitOfWork.DirectoryRepository.GetInDirectory
                                          (await _unitOfWork.DirectoryRepository.GetByIdAsync(currentDirectory.DirectoryId));

                IEnumerable <Directory> directories = directory.Directories;
                IEnumerable <File>      files       = directory.Files;

                if (directories.Count() == 0 &&
                    files.Count() == 0)
                {
                    dirs.Append("<code>Папка пустая</code>");
                    await client.SendTextMessageAsync(message.Chat.Id, dirs.ToString(), ParseMode.Html);

                    return(true);
                }
                if (message.Text == Name)
                {
                    foreach (var dir in directories)
                    {
                        dirs.Append($"<code>{dir.Name}</code>\n");
                    }

                    foreach (var file in files)
                    {
                        dirs.Append($"<code>{file.Name}</code>\n");
                    }

                    await client.SendTextMessageAsync(message.Chat.Id, dirs.ToString(), ParseMode.Html);

                    return(true);
                }
                else
                {
                    string[] showDirsParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                    if (showDirsParams[0] == Name && showDirsParams[1] == "-la")
                    {
                        List <int> ids = directories.Select(d => d.Id).ToList();
                        Dictionary <int, List <File> > dirFiles = _unitOfWork.FileRepository.GetFilesOfSomeDirs(ids);
                        foreach (var dir in directories)
                        {
                            dirs.Append($"<code>{dir.GetSizeOfDir(dirFiles[dir.Id])}\t{dir.TimeOfCreating.ToString("MMM", CultureInfo.InvariantCulture)}\t{dir.TimeOfCreating.Day}\t{dir.Name}</code>\n");
                        }
                        foreach (var file in files)
                        {
                            dirs.Append($"<code>{file.Size}\t{file.TimeOfCreating.ToString("MMM", CultureInfo.InvariantCulture)}\t{file.TimeOfCreating.Day}\t{file.Name}</code>\n");
                        }

                        await client.SendTextMessageAsync(message.Chat.Id, dirs.ToString(), ParseMode.Html);

                        return(true);
                    }

                    return(false);
                }
            }

            return(false);
        }
Example #15
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

            WifiModule wifiModule = await _unitOfWork.WifiModuleRepository.GetByIdAsync(linuxSystem.WifiModuleId);

            if (user != null && user.isAuthorized && wifiModule.ModuleMode == ModuleMode.Monitor)
            {
                string[]           commandParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                IEnumerable <Wifi> wifis         = _unitOfWork.WifiRepository.GetByWifisModuleId(wifiModule.Id);
                bool isExist = wifis.Any(w => w.BSSID == commandParams[4]);

                if (commandParams[1] == "--deauth" && commandParams[3] == "-a" &&
                    isExist && commandParams[5] == wifiModule.Name)
                {
                    for (int i = 0; i < 8; i++)
                    {
                        await client.SendTextMessageAsync(chatId, $"<code>{DateTime.UtcNow.ToString("HH:mm:ss")}  Sending DeAuth to broadcast -- BSSID: [{commandParams[4]}]</code>", ParseMode.Html);

                        Thread.Sleep(1000);
                    }

                    user.CountOfCrackWifi++;
                    await _unitOfWork.SaveAsync();

                    Wifi wifi = wifis.FirstOrDefault(w => w.BSSID == commandParams[4]);

                    if (wifi != null)
                    {
                        CurrentDirectory currentDirectory = await _unitOfWork.CurrentDirectoryRepository.GetByIdAsync(linuxSystem.CurrentDirectoryId);

                        if (currentDirectory != null)
                        {
                            Directory directory = _unitOfWork.DirectoryRepository.GetInDirectory
                                                      (await _unitOfWork.DirectoryRepository.GetByIdAsync(currentDirectory.DirectoryId));
                            List <File> curDirFiles = directory.Files.ToList();

                            File file = new File()
                            {
                                Name           = $"Wifi-Crack{user.CountOfCrackWifi}.cap",
                                Size           = new Random().Next(100, 500),
                                TimeOfCreating = DateTime.UtcNow,
                                Text           = Convert.ToBase64String(Encoding.UTF8.GetBytes(wifi.Password))
                            };

                            directory.Files.Add(file);

                            await _unitOfWork.SaveAsync();

                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }

                    return(false);
                }
                else
                {
                    await client.SendTextMessageAsync(chatId, "<code>Неверные данные</code>", ParseMode.Html);

                    return(false);
                }
            }

            return(false);
        }
Example #16
0
        public async Task <bool> Execute(Message message, TelegramBotClient client)
        {
            long chatId = message.Chat.Id;
            User user   = await _unitOfWork.UserAccessRepository.GetUserByChatId(chatId);

            LinuxSystem linuxSystem = await _unitOfWork.LinuxRepository.GetByIdAsync(user.Id);

            if (user != null && linuxSystem != null && user.isAuthorized && linuxSystem.IsConnectedTheInternet)
            {
                string[] commandParams = message.Text.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (commandParams.Length == 3 && commandParams[0] == Name)
                {
                    string[] connectParams = commandParams[1].Split(new char[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
                    if (connectParams.Length == 2)
                    {
                        LinuxSystem victimSystem = await _unitOfWork.LinuxRepository.GetByIP(connectParams[0]);

                        if (victimSystem != null)
                        {
                            List <Vulnerability> vulnerabilities = _unitOfWork.VulnerabilityRepository.GetVulnerabilitiesByLinuxSystemId(victimSystem.Id);
                            if (vulnerabilities.Count > 0)
                            {
                                foreach (var vuln in vulnerabilities)
                                {
                                    foreach (var port in vuln.Ports)
                                    {
                                        if (port.Password == commandParams[2] && port.Login == connectParams[1])
                                        {
                                            await client.SendTextMessageAsync(chatId, $"<code>Вы подлючены к {victimSystem.IP}\nПоздравляем!Вы пройшли игру, подключение к чужому ПК - это был флаг\nУспехов вам в жизни!</code>", ParseMode.Html);

                                            return(true);
                                        }
                                    }
                                }

                                await client.SendTextMessageAsync(chatId, "<code>Порты либо закрыты, либо неверный пароль.</code>", ParseMode.Html);

                                return(false);
                            }

                            await client.SendTextMessageAsync(chatId, "<code>Все порты закрыты.</code>", ParseMode.Html);

                            return(false);
                        }

                        await client.SendTextMessageAsync(chatId, "<code>Системы по такому адресу не существует.</code>", ParseMode.Html);

                        return(false);
                    }

                    await client.SendTextMessageAsync(chatId, "<code>Неверные параметры команды.</code>", ParseMode.Html);

                    return(false);
                }

                await client.SendTextMessageAsync(chatId, "<code>Неверные параметры команды.</code>", ParseMode.Html);

                return(false);
            }

            return(false);
        }