from procamora_utils.ip import IP from procamora_utils.logger import get_logging from requests import exceptions # Importamos la librerÃa Y los tipos especiales de esta from telebot import TeleBot, types, apihelper from telebot.types import InlineKeyboardMarkup, InlineKeyboardButton from terminaltables import AsciiTable from generate_pdf import latex_to_pdf, generate_latex from host import Host from implement_sqlite import select_hosts_online, select_hosts_offline, update_descriptions, check_database from openvas import OpenVas, FULL_FAST from scan_nmap import ScanNmap logger: logging = get_logging(False, 'bot_scan') def get_basic_file_config(): return '''[BASICS] ADMIN = 111111 BOT_TOKEN = 1069111113:AAHOk9K5TAAAAAAAAAAIY1OgA_LNpAAAAA DEBUG = 0 DELAY = 30 [DEBUG] ADMIN = 111111 BOT_TOKEN = 1069111113:AAHOk9K5TAAAAAAAAAAIY1OgA_LNpAAAAA [OPENVAS] IP = 192.168.1.71
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import platform import subprocess from typing import NoReturn, Text, List from procamora_utils.ip import IP from procamora_utils.logger import get_logging, logging logger: logging = get_logging(False, 'ping') def ping(hostname: IP) -> bool: # Posibles opciones: 'Linux', 'Darwin', 'Java', 'Windows' command: Text if platform.uname()[0] == 'Linux': command = f'ping -c 1 {hostname.get_addr()}' elif platform.uname()[0] == 'Windows': command = f'ping -n 1 {hostname.get_addr()}' else: logger.error( f'{platform.uname()[0]} operating system temporarily not supported' ) raise OSError( f'{platform.uname()[0]} operating system temporarily not supported' ) logger.debug(command) a: subprocess.CompletedProcess = subprocess.run(command.split(' '),
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import annotations import re from dataclasses import dataclass from ipaddress import ip_interface from typing import Text, NoReturn from procamora_utils.logger import get_logging, logging logger: logging = get_logging(False, 'ip') @dataclass class IP: REGEX_FQDN: Text = r"(?=^.{4,253}$)(^((?!-)[a-zA-Z0-9-]{0,62}[a-zA-Z0-9]\.)+[a-zA-Z]{2,63}$)" ip: Text = None fqdn: Text = None valid_ip: ip_interface = None def __post_init__(self: IP) -> NoReturn: """ Metodo post_inicio encargado de comprobar que la informacion proporcionada es valida :return: """ bool_fqnd: bool = False bool_ip: bool = False
import random import re import sys from pathlib import Path from typing import NoReturn, Tuple, List, Text, Callable import unidecode from procamora_utils.logger import get_logging from requests import exceptions from telebot import TeleBot, types, apihelper from implement_sqlite import select_all_words, check_database, insert_stat, select_user_stats, get_word, insert_word from stats import Stats from word import Word logger: logging = get_logging(False, 'bot_dictionary') def get_basic_file_config(): return '''[BASICS] ADMIN = 111111 BOT_TOKEN = 1069111113:AAHOk9K5TAAAAAAAAAAIY1OgA_LNpAAAAA DEBUG = 0 LIMIT_STATS = 500 ''' FILE_CONFIG: Path = Path(Path(__file__).resolve().parent, "settings.cfg") if not FILE_CONFIG.exists(): logger.critical(f'File {FILE_CONFIG} not exists and is necesary') FILE_CONFIG.write_text(get_basic_file_config())
from __future__ import annotations import logging import subprocess import sys import tempfile from datetime import datetime from pathlib import Path from typing import Text, Tuple, Any, Optional, List, IO import jinja2 from procamora_utils.logger import get_logging from host import Host logger: logging = get_logging(False, 'pdf') def generate_latex(hosts_online: List[Host], hosts_offline: List[Host], interfaces: Text, arp: Text, routes: Text) \ -> Text: working_path: Path = Path(__file__).resolve().parent # report_path: Path = Path(working_path, 'resources', 'templates', 'report.tex') personal_icon_path: Path = Path(working_path, 'resources', 'images', 'personal.png') proyect_icon_path: Path = Path(working_path, 'resources', 'images', 'logo_transparent.png') template_latex_path: Path = Path('resources/templates/report.tex') latex_jinja_env = jinja2.Environment(block_start_string=r'\BLOCK{', block_end_string='}', variable_start_string=r'\VAR{',
__all__ = ['ClientSSH', 'create_arg_parser'] import argparse # https://docs.python.org/3/library/argparse.html import os import platform import re import sys from dataclasses import dataclass from pathlib import Path from typing import NoReturn, Optional, Tuple import paramiko from procamora_utils.logger import get_logging, logging logger: logging = get_logging(False, 'client_ssh') def create_arg_parser() -> argparse: """ Metodo para establecer los argumentos que necesita la clase :return: """ example = "python3 %(prog)s -i 192.168.1.20 -u ubnt -p ubnt -c w" my_parser = argparse.ArgumentParser( description= '%(prog) a is a script to automate the remote execution of commands through ssh', usage='{}'.format(example)) requiered = my_parser.add_argument_group('requiered arguments')
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from pathlib import Path # nueva forma de trabajar con rutas from threading import Lock from typing import List, Text, NoReturn, Tuple, Any, Dict from procamora_utils.interface_sqlite import conection_sqlite, execute_script_sqlite from procamora_utils.logger import get_logging, logging from host import Host logger: logging = get_logging(False, 'sqlite') # Ruta absoluta de la BD DB: Path = Path(Path(__file__).resolve().parent, "database.db") DB_STRUCTURE: Path = Path(Path(__file__).resolve().parent, "database.db.sql") def get_list_host(response_query_str: List[Dict[Text, Any]]): if response_query_str is None: return list() response_query: List[Host] = list( map( lambda h: Host(h['ip'], h['mac'], h['vendor'], h['date'], h[ 'network'], h['description'], h['id']), response_query_str)) return sorted(list(set(response_query))) # REMOVE DUPLICATES def select_mac_all_hosts(lock: Lock) -> Tuple[Text, ...]: query: Text = "SELECT Hosts.mac FROM Hosts group by Hosts.mac ORDER BY Hosts.mac;"
import logging import subprocess import sys from typing import List, Tuple, Dict, Text, NoReturn from threading import Lock import netifaces import nmap from procamora_utils.ip import IP from procamora_utils.logger import get_logging from procamora_utils.ping import ping from host import Host from implement_sqlite import select_mac_all_hosts, insert_host, update_date, check_database from mac_vendor_lookup_sync import MacLookup logger: logging = get_logging(False, 'scan_nmap') class ScanNmap: def __init__(self: ScanNmap, subnets: ipaddress.ip_interface = None, lock: Lock = None) -> NoReturn: self.nmap_tcp_scan: Text = '--top-ports 1000 --open -T5 -sV -v -n' self.nmap_ping_scan: Text = '-n -sP' self.nmap_tcp_fin_scan: Text = '-n -sF -T5' self._lock: Lock = lock self._local_interfaces: Dict[Text, Text] = dict() self._subnets: List[ipaddress.ip_interface] = list() self._db_mac_hosts: Tuple[Text] = tuple() self._vendor = MacLookup() self._vendor.load_vendors()
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from __future__ import annotations import _io import logging import sys from pathlib import Path from typing import Text, NoReturn, Dict, AnyStr import requests from procamora_utils.logger import get_logging logger: logging = get_logging(False, 'mac_lockup') OUI_URL: Text = "http://standards-oui.ieee.org/oui.txt" class InvalidMacError(Exception): pass class BaseMacLookup(object): cache_path: Path = Path('~/.cache/mac-vendors2.txt').expanduser() @staticmethod def sanitise(_mac: Text) -> Text: mac: Text = _mac.replace(":", "").replace("-", "").upper() try: int(mac, 16)
help - Show help start - Start the bot """ import configparser import re import subprocess import sys from pathlib import Path from typing import NoReturn, Optional, Tuple, Dict, List from telebot import TeleBot, types # Importamos la librerÃa Y los tipos especiales de esta from procamora_utils.logger import get_logging, logging from procamora_utils.client_ssh import ClientSSH logger: logging = get_logging(False, 'bot_proxmox') FILE_CONFIG: Path = Path(Path(__file__).resolve().parent, "settings.cfg") if not FILE_CONFIG.exists(): logger.critical(f'File {FILE_CONFIG} not exists and is necesary') sys.exit(1) config: configparser.ConfigParser = configparser.ConfigParser() config.read(FILE_CONFIG) config_basic: configparser.SectionProxy = config["BASICS"] config_ssh: configparser.SectionProxy = config["SSH"] administrador: int = 33063767 users_permitted: List = [33063767, 40522670]