From 5bf0c136f5a34afab7cc65525702d2e90bf2c778 Mon Sep 17 00:00:00 2001 From: procamora Date: Mon, 20 Apr 2020 20:12:49 +0200 Subject: [PATCH] change own libraries --- README.md | 4 +- generate_pdf.py | 6 +- implement_sqlite.py | 4 +- mac_vendor_lookup_sync.py | 2 +- mio_bot_scan_networks.service | 3 +- requirements.txt | 9 +- resources/{icons => images}/1984.png | Bin .../images/bot_scan_networks.svg | 0 resources/{icons => images}/logo.png | Bin .../{icons => images}/logo_transparent.png | Bin resources/{icons => images}/nmap.png | Bin resources/{icons => images}/personal.png | Bin resources/templates/main.tex | 263 ------------------ scan_nmap.py | 12 +- template.tex | 153 ---------- 15 files changed, 20 insertions(+), 436 deletions(-) rename resources/{icons => images}/1984.png (100%) rename bot_scan_networks.svg => resources/images/bot_scan_networks.svg (100%) rename resources/{icons => images}/logo.png (100%) rename resources/{icons => images}/logo_transparent.png (100%) rename resources/{icons => images}/nmap.png (100%) rename resources/{icons => images}/personal.png (100%) delete mode 100644 resources/templates/main.tex delete mode 100644 template.tex diff --git a/README.md b/README.md index 90c48fe..48aef62 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ It is being designed to be easily extensible through plugins, as it may allow to ![minitrue][minitrue] -[minitrue]: bot_scan_networks.svg +[minitrue]: resources/images/bot_scan_networks.svg # Installation @@ -36,7 +36,7 @@ sudo dnf install nmap texlive-latex-recommended texlive-latex-extra texlive-date -```python +```bash python3 bot_scan.py ``` diff --git a/generate_pdf.py b/generate_pdf.py index 9ab1e2a..3f962d0 100755 --- a/generate_pdf.py +++ b/generate_pdf.py @@ -11,7 +11,7 @@ from typing import Dict, Text, Tuple, Any, Optional import jinja2 -from procamora_logging import get_logging +from procamora_utils.logger import get_logging from host import Host @@ -21,8 +21,8 @@ def generate_latex(hosts: Dict[Text, 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', 'icons', 'personal.png') - proyect_icon_path: Path = Path(working_path, 'resources', 'icons', 'logo_transparent.png') + personal_icon_path: Path = Path(working_path, 'resources', 'images', 'personal.png') + proyect_icon_path: Path = Path(working_path, 'resources', 'images', 'logo_transparent.png') latex_jinja_env = jinja2.Environment( block_start_string='\BLOCK{', diff --git a/implement_sqlite.py b/implement_sqlite.py index 17ef2eb..7296dce 100644 --- a/implement_sqlite.py +++ b/implement_sqlite.py @@ -7,8 +7,8 @@ from pathlib import Path # nueva forma de trabajar con rutas from typing import Dict, Any, List, Text, NoReturn -from procamora_logging import get_logging -from procamora_sqlite3 import conection_sqlite, execute_script_sqlite +from procamora_utils.interface_sqlite import conection_sqlite, execute_script_sqlite +from procamora_utils.logger import get_logging from host import Host diff --git a/mac_vendor_lookup_sync.py b/mac_vendor_lookup_sync.py index be46f2e..eda8d96 100644 --- a/mac_vendor_lookup_sync.py +++ b/mac_vendor_lookup_sync.py @@ -10,7 +10,7 @@ from typing import Text, NoReturn, Dict, AnyStr import requests -from procamora_logging import get_logging +from procamora_utils.logger import get_logging logger: logging = get_logging(False, 'mac_lockup') diff --git a/mio_bot_scan_networks.service b/mio_bot_scan_networks.service index 33bcd5e..89b719a 100644 --- a/mio_bot_scan_networks.service +++ b/mio_bot_scan_networks.service @@ -4,7 +4,8 @@ After=multi-user.target [Service] Type=idle -ExecStart=/usr/bin/python3 /home/pi/bot_scan_networks/bot_scan.py >> /home/pi/bot_scan/tg_bot.log 2>&1 +ExecStart=/usr/bin/python3 /home/pi/minitrue/bot_scan.py >> /home/pi/minitrue/tg_bot.log 2>&1 +ExecStop=killall -9 bot_scan.py User=pi [Install] diff --git a/requirements.txt b/requirements.txt index 4bbec41..6823c13 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,3 +1,5 @@ +beautifulsoup4 +lxml # Obtener interfaces locales y sus MACs netifaces @@ -10,11 +12,8 @@ python-nmap requests -# Libreria propia para gestion de sqlite -procamora-sqlite3 - -# Libreria propia para realizar ping -procamora-ping +# Libreria propia para gestion de sqlite ping +procamora-utils # Telegram Bot pyTelegramBotAPI diff --git a/resources/icons/1984.png b/resources/images/1984.png similarity index 100% rename from resources/icons/1984.png rename to resources/images/1984.png diff --git a/bot_scan_networks.svg b/resources/images/bot_scan_networks.svg similarity index 100% rename from bot_scan_networks.svg rename to resources/images/bot_scan_networks.svg diff --git a/resources/icons/logo.png b/resources/images/logo.png similarity index 100% rename from resources/icons/logo.png rename to resources/images/logo.png diff --git a/resources/icons/logo_transparent.png b/resources/images/logo_transparent.png similarity index 100% rename from resources/icons/logo_transparent.png rename to resources/images/logo_transparent.png diff --git a/resources/icons/nmap.png b/resources/images/nmap.png similarity index 100% rename from resources/icons/nmap.png rename to resources/images/nmap.png diff --git a/resources/icons/personal.png b/resources/images/personal.png similarity index 100% rename from resources/icons/personal.png rename to resources/images/personal.png diff --git a/resources/templates/main.tex b/resources/templates/main.tex deleted file mode 100644 index 16e465f..0000000 --- a/resources/templates/main.tex +++ /dev/null @@ -1,263 +0,0 @@ -\documentclass[a4paper]{article} - -% Paquetes -\usepackage[utf8]{inputenc} -\usepackage[spanish]{babel} -\usepackage[margin=2cm, top=2cm, includefoot]{geometry} -\usepackage{graphicx} % Gestión de imágenes -\usepackage[table,xcdraw]{xcolor} % Gestión colores -\usepackage[most]{tcolorbox} % Inserción de cuadros (portada) -\usepackage{fancyhdr} % Definir estilos de pagina -\usepackage[hidelinks]{hyperref} % Gestión hipervinculos -\usepackage{listings} % Inserción de código -\usepackage{parskip} % Arreglo tabulación automática -\usepackage[figurename=Figura]{caption} % Gestión nombre del caption -\usepackage{smartdiagram} % Inserción de diagramas -\usepackage{zed-csp} % Inserción de esquemas -%\usepackage{mwe} - -% Declaración de variables -\newcommand{\myLogoCover}{personal.png} -\newcommand{\myLogoProyect}{logo_transparent.png} -\newcommand{\myTitle}{Automatic Report} -\newcommand{\mySubtitle}{\href{https://telegram.me/procamora_scan_bot}{@procamora\_scan\_bot}} -\newcommand{\myName}{Pablo Rocamora} -\newcommand{\myMail}{pablojoserocamora@gmail.com} - -% Definicion del mes en el idioma deseado -\newcommand{\myMonth}{% - \ifcase\month % 0 - \or January % 1 - \or February % 2 - \or March % 3 - \or April % 4 - \or May % 5 - \or June % 6 - \or July % 7 - \or August % 8 - \or September % 9 - \or October % 10 - \or November % 11 - \or December % 12 - \fi} -\newcommand{\myDate}{\number\day\space \myMonth \number\year} - - -% Definicion metadados PDF -\hypersetup{ - pdfauthor = {\myName~(\myMail)}, - pdftitle = {\myTitle}, -} - - -% Adicionales -\setlength{\headheight}{40.2pt} -\pagestyle{fancy} -\fancyhf{} -\lhead{\includegraphics[height=1.5cm,keepaspectratio]{\myLogoCover}} -\rhead{\includegraphics[height=1.5cm,keepaspectratio]{\myLogoProyect}} -\renewcommand{\headrulewidth}{3pt} - -\renewcommand{\headrule}{\hbox to\headwidth{\color{greenPortada}\leaders\hrule height \headrulewidth\hfill}} - - -\AtBeginDocument{ % Cambiar nombre de los disitntos - \renewcommand{\tablename}{Table} - \renewcommand{\figurename}{Figure} - \renewcommand{\lstlistingname}{Code} % Cambiar nombre de los codigos - - \renewcommand{\contentsname}{Index} - \renewcommand{\listfigurename}{Index of \figurename s} - \renewcommand{\listtablename}{Index of \tablename s} - \renewcommand{\lstlistlistingname}{Index of \lstlistingname s} -} - - - - - -% Definición de colores -%\definecolor{greenPortada}{HTML} -\definecolor{greenPortada}{RGB}{105, 168, 79} % hex: {69A84F} -\definecolor{codegreen}{rgb}{0,0.6,0} -\definecolor{codegray}{rgb}{0.5,0.5,0.5} -\definecolor{codepurple}{rgb}{0.58,0,0.82} -\definecolor{backcolor}{rgb}{0.95,0.95,0.92} - -% Estilos propios -\lstdefinestyle{mystyle}{ - backgroundcolor=\color{backcolor}, - commentstyle=\color{codegreen}, - keywordstyle=\color{magenta}, - numberstyle=\tiny\color{codegray}, - stringstyle=\color{codepurple}, - basicstyle=\ttfamily\footnotesize, - breakatwhitespace=false, - breaklines=true, - captionpos=b, - keepspaces=true, - numbers=left, - numbersep=5pt, - showspaces=false, - showstringspaces=false, - showtabs=false, - tabsize=2 -} -\lstset{style=mystyle} - - -% Comienzo del documento -\begin{document} -\cfoot{\thepage} -% Inicio Portada -\begin{titlepage} - \centering - %\vspace*{\fill}\includegraphics[height=2cm,keepaspectratio]{\myLogoCover} {\scshape\LARGE \textbf{\myName}\par}\vspace*{\fill} - - \begin{tabular}{ll} - \raisebox{-.4\height}{\includegraphics[height=2cm,keepaspectratio]{\myLogoCover}} & { \hspace{8cm} \scshape\LARGE {\myName}} \\ - \end{tabular} - - \par\vspace{1cm} - \vfill - - {\rule{\linewidth}{0.5mm}\vspace{0.5cm}} % Linea negra 1 - - {\Huge\bfseries\textcolor{greenPortada}{\myTitle}} - \par\vspace{0.5cm} - {\scshape\LARGE \textbf{\mySubtitle}} - - {\vspace{0.5cm}\rule{\linewidth}{0.5mm}} % Linea negra 2 - - \vfill\vfill - \includegraphics[width=\textwidth,height=8cm,keepaspectratio]{\myLogoProyect}\par\vspace{1cm} - \vfill\vfill - - % Cuadrado con disclaimer - \begin{tcolorbox}[colback=red!5!white,colframe=red!75!black] - \centering - This document is confidential and contains sensitive information. - \\ - It should not be printed or shared with third parties. - \end{tcolorbox} - - \vfill\vfill - {\large \myDate \par} - \vfill -\end{titlepage} -% Fin Portada - - - - - -\clearpage -\tableofcontents % Índice -%\listoffigures % Índice de figuras -%\listoftables % Índice de tablas -%\lstlistoflistings % Índice de códigos -\clearpage - - - - - -\section{Hosts} - - - -\subsection{Hosts online} - - -\begin{table}[!hbt] - \centering - \begin{tabular}{|c|c|c|c|c|} - \hline - \textbf{IP} & \textbf{MAC} & \textbf{VENDOR} & \textbf{DESCRIPTION} & \textbf{NETWORK} \\ \hline - - %% for x in hosts - %% if hosts[x].active -% \VAR{hosts[x].ip} & \VAR{hosts[x].mac} & \VAR{hosts[x].vendor} & \VAR{hosts[x].description} & \VAR{hosts[x].network} \\ \hline - %% endif - %% endfor - - \end{tabular} - \caption{Hosts online} - \label{tab:my-table} -\end{table} - - - -\subsection{Hosts offline} - -\begin{table}[!hbt] - \centering - \begin{tabular}{|c|c|c|c|c|} - \hline - \textbf{IP} & \textbf{MAC} & \textbf{VENDOR} & \textbf{DESCRIPTION} & \textbf{NETWORK} \\ \hline - - %% for x in hosts - %% if not hosts[x].active -% \VAR{hosts[x].ip} & \VAR{hosts[x].mac} & \VAR{hosts[x].vendor} & \VAR{hosts[x].description} & \VAR{hosts[x].network} \\ \hline - %% endif - %% endfor - - \end{tabular} - \caption{Hosts offline} - \label{tab:my-table2} -\end{table} - - - - - - - - - - - - - -\clearpage - -\section{Troubleshooting} - - -\begin{center} -\smartdiagram[sequence diagram]{ip address show,ip neigh show,ip route list} -\end{center} - - - -\subsection{Interfaces} - - -\begin{lstlisting}[language=Bash, caption=Network Interfaces] -\VAR{interfaces} -\end{lstlisting} - -\subsection{ARP} - - -\begin{lstlisting}[language=Bash, caption=ARP] -\VAR{arp} -\end{lstlisting} - - -\subsection{Routing} - - -\begin{lstlisting}[language=Bash, caption=TABLE ROUTE] -\VAR{routes} -\end{lstlisting} - - - - - -\end{document} - - - - diff --git a/scan_nmap.py b/scan_nmap.py index 456d6b8..a9b8e5c 100644 --- a/scan_nmap.py +++ b/scan_nmap.py @@ -8,12 +8,12 @@ import subprocess import sys from ipaddress import IPv4Interface, IPv6Interface -from typing import List, Tuple, Union, Dict, Text +from typing import List, Tuple, Union, Dict, Text, NoReturn import netifaces import nmap -from procamora_logging import get_logging -from procamora_ping import ping +from procamora_utils.logger import get_logging +from procamora_utils.ping import ping from host import Host from implement_sqlite import select_all_hosts, insert_host, update_host, update_host_offline @@ -23,7 +23,7 @@ class ScanNmap: - def __init__(self, subnets: List[Union[IPv4Interface, IPv6Interface]] = None): + def __init__(self: ScanNmap, subnets: List[Union[IPv4Interface, IPv6Interface]] = None) -> NoReturn: self.nmap_tcp_scan: Text = '--top-ports 1000 --open -T5 -sV -v -n' self.nmap_ping_scan: Text = '-n -sP' @@ -41,10 +41,10 @@ def __init__(self, subnets: List[Union[IPv4Interface, IPv6Interface]] = None): self.update_db() logger.info(self.subnets) - def update_db(self: ScanNmap): + def update_db(self: ScanNmap) -> NoReturn: self.hosts_db = select_all_hosts() - def set_local_interfaces(self: ScanNmap): + def set_local_interfaces(self: ScanNmap) -> NoReturn: """ Metodo para obtener todas las interfaces del sistema que tienen asignada una direccion IP y enlazarla con su MAC en un diccionario diff --git a/template.tex b/template.tex deleted file mode 100644 index 628fd50..0000000 --- a/template.tex +++ /dev/null @@ -1,153 +0,0 @@ -\documentclass[10pt]{report} -\usepackage[english]{babel} -%\usepackage{natbib} -\usepackage{url} -\usepackage[utf8x]{inputenc} -\usepackage{amsmath} -\usepackage{graphicx} -\graphicspath{{images/}} -\usepackage{parskip} -\usepackage{fancyhdr} -\usepackage{vmargin} -\usepackage{hyperref} -\usepackage{listings} % Insercion de codigo - -\setmarginsrb{1 cm}{1 cm}{2 cm}{2 cm}{1 cm}{1.5 cm}{1 cm}{1.5 cm} - -\title{\VAR{title}} -% Title -\author{\VAR{author}} -% Author -\date{\VAR{date}} -% Date - -%\hypersetup{ -% pdfauthor = {\@author}, -% pdftitle = {@\title}, -%} - - -\makeatletter -\let\thetitle\@title -\let\theauthor\@author -\let\thedate\@date -\makeatother - -\pagestyle{fancy} -\fancyhf{} -\rhead{\theauthor} -\lhead{\thetitle} -\cfoot{\thepage} - -\begin{document} - - - \begin{titlepage} - \centering - \vspace*{0.5 cm} - % \includegraphics[scale = 0.075]{bsulogo.png}\\[1.0 cm] % University Logo - \begin{center} - \textsc{\Large Mathematical Sciences}\\[2.0 cm] - \end{center}% University Name - \rule{\linewidth}{0.2 mm} \\[0.4 cm] - { \huge \bfseries \thetitle}\\ - \rule{\linewidth}{0.2 mm} \\[1.5 cm] - - \begin{minipage}{0.4\textwidth} - \begin{flushleft} - \large - % \emph{Submitted To:}\\ - % Name\\ - % Affiliation\\ - %contact info\\ - \end{flushleft} - \end{minipage}~ - - \begin{minipage}{0.4\textwidth} - - \begin{flushright} - \large - \emph{\@procamora\_scan\_bot} - \end{flushright} - \end{minipage}\\[2 cm] - - \includegraphics[width=5cm]{\VAR{icon}} - \end{titlepage} - - - - %\tableofcontents - %\pagebreak - - - %\renewcommand{\thesection}{\arabic{section}} - - - - - - - - - - - \section{Report} - - - \begin{table}[!hbt] - \centering - \begin{tabular}{|c|c|c|c|c|} - \hline - \textbf{IP} & \textbf{MAC} & \textbf{VENDOR} & \textbf{DESCRIPTION} & \textbf{NETWORK} \\ \hline - - %% for x in hosts - %% if hosts[x].active - \VAR{hosts[x].ip} & \VAR{hosts[x].mac} & \VAR{hosts[x].vendor} & \VAR{hosts[x].description} & \VAR{hosts[x].network} \\ \hline - %% endif - %% endfor - - \end{tabular} - \caption{Hosts online} - \label{tab:my-table} - \end{table} - - - - - - \begin{table}[!hbt] - \centering - \begin{tabular}{|c|c|c|c|c|} - \hline - \textbf{IP} & \textbf{MAC} & \textbf{VENDOR} & \textbf{DESCRIPTION} & \textbf{NETWORK} \\ \hline - - %% for x in hosts - %% if not hosts[x].active - \VAR{hosts[x].ip} & \VAR{hosts[x].mac} & \VAR{hosts[x].vendor} & \VAR{hosts[x].description} & \VAR{hosts[x].network} \\ \hline - %% endif - %% endfor - - \end{tabular} - \caption{Hosts offline} - \label{tab:my-table2} - \end{table} - - - \begin{lstlisting}[caption=Script personalizado para la enumeracion de puertos] - \VAR{interfaces} - \end{lstlisting} - - - \begin{lstlisting}[caption=Script personalizado para la enumeracion de puertos] - \VAR{arp} - \end{lstlisting} - - - \begin{lstlisting}[caption=Script personalizado para la enumeracion de puertos] - \VAR{routes} - \end{lstlisting} - - -\end{document} - -%This template was created by Roza Aceska.