-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
152 lines (125 loc) · 6.98 KB
/
main.py
File metadata and controls
152 lines (125 loc) · 6.98 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import argparse
import sys
import os
from colorama import Fore, Style, init
# Inicializa colorama para funcionar em diferentes terminais
init(autoreset=True)
# Adiciona o diretório atual ao PATH para importação dos módulos
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
try:
from network_scanner import arp_scan, port_scan
from info_analysis import calculate_file_hash, whois_lookup, dns_lookup
from sniffer import start_sniffer
except ImportError as e:
print(f"{Fore.RED}Erro ao importar módulos: {e}{Style.RESET_ALL}")
print(f"{Fore.RED}Certifique-se de que todos os arquivos (network_scanner.py, info_analysis.py, sniffer.py) estão no mesmo diretório e as dependências estão instaladas.{Style.RESET_ALL}")
sys.exit(1)
def print_banner():
"""Imprime o banner da aplicação."""
banner = f"""
{Fore.RED}
____ _ _ ____ _____ _____ _____ _ _ _____ _____
| _ \| \ | | _ \| ____| ____|_ _| \ | | ____|_ _|
| |_) | \| | |_) | _| | _| | | | \| | _| | |
| __/| |\ | _ <| |___| |___ | | | |\ | |___ | |
|_| |_| \_|_| \_\_____|_____| |_| |_| \_|_____| |_|
{Style.RESET_ALL}
{Fore.GREEN} Toolkit de Pentest em Python - Manus AI{Style.RESET_ALL}
"""
print(banner)
def display_results(title, data):
"""Exibe os resultados de forma formatada."""
print(f"\n{Fore.BLUE}--- {title} ---{Style.RESET_ALL}")
if isinstance(data, list):
if not data:
print(f"{Fore.YELLOW}Nenhum resultado encontrado.{Style.RESET_ALL}")
return
# Exibição de lista de hosts (ARP Scan)
if all(isinstance(d, dict) and 'ip' in d and 'mac' in d for d in data):
print(f"{Fore.CYAN}{'IP Address':<18}{'MAC Address':<18}{Style.RESET_ALL}")
print("-" * 36)
for item in data:
print(f"{item['ip']:<18}{item['mac']:<18}")
else:
for item in data:
print(item)
elif isinstance(data, dict):
# Exibição de Port Scan
for host, info in data.items():
print(f"{Fore.CYAN}Host: {host} ({info.get('status', 'Desconhecido')}){Style.RESET_ALL}")
if 'ports' in info:
print(f"{Fore.MAGENTA}{'Porta':<8}{'Estado':<12}{'Serviço':<15}{'Versão'}{Style.RESET_ALL}")
print("-" * 50)
for port, p_info in info['ports'].items():
print(f"{port:<8}{p_info['state']:<12}{p_info['name']:<15}{p_info['product']} {p_info['version']}")
else:
print(f"{Fore.YELLOW}Nenhuma porta TCP encontrada.{Style.RESET_ALL}")
elif data is not None:
# Exibição de Whois/DNS/Hash
if isinstance(data, whois.parser.WhoisEntry):
print(f"{Fore.MAGENTA}Registrante:{Style.RESET_ALL} {data.registrar}")
print(f"{Fore.MAGENTA}Data de Criação:{Style.RESET_ALL} {data.creation_date}")
print(f"{Fore.MAGENTA}Data de Expiração:{Style.RESET_ALL} {data.expiration_date}")
print(f"{Fore.MAGENTA}Servidores de Nome:{Style.RESET_ALL} {', '.join(data.name_servers) if data.name_servers else 'N/A'}")
# print(str(data)) # Para ver todos os dados brutos
else:
print(data)
else:
print(f"{Fore.YELLOW}A operação não retornou dados ou falhou.{Style.RESET_ALL}")
def main():
print_banner()
parser = argparse.ArgumentParser(description="Toolkit de Pentest em Python com funcionalidades de Rede, Arquivos e Sniffer.")
subparsers = parser.add_subparsers(dest='command', help='Comandos disponíveis')
# --- Subparser para Network Scan ---
net_parser = subparsers.add_parser('net', help='Comandos de Análise de Rede')
net_subparsers = net_parser.add_subparsers(dest='net_command', required=True)
# ARP Scan
arp_parser = net_subparsers.add_parser('arp', help='Realiza um ARP Scan para descoberta de hosts (Requer sudo)')
arp_parser.add_argument('ip_range', help='Faixa de IP (ex: 192.168.1.1/24)')
# Port Scan
port_parser = net_subparsers.add_parser('port', help='Realiza um Port Scan TCP (usando nmap)')
port_parser.add_argument('target', help='IP ou Domínio alvo')
port_parser.add_argument('-p', '--ports', default='1-1024', help='Portas a escanear (ex: 22,80,443 ou 1-100)')
# --- Subparser para Info Analysis ---
info_parser = subparsers.add_parser('info', help='Comandos de Análise de Arquivos e Informações')
info_subparsers = info_parser.add_subparsers(dest='info_command', required=True)
# File Hash
hash_parser = info_subparsers.add_parser('hash', help='Calcula o hash de um arquivo')
hash_parser.add_argument('file_path', help='Caminho para o arquivo')
hash_parser.add_argument('-a', '--algorithm', default='sha256', choices=['md5', 'sha1', 'sha256', 'sha512'], help='Algoritmo de hash (padrão: sha256)')
# Whois Lookup
whois_parser = info_subparsers.add_parser('whois', help='Realiza uma consulta Whois para um domínio')
whois_parser.add_argument('domain', help='Domínio alvo (ex: google.com)')
# DNS Lookup
dns_parser = info_subparsers.add_parser('dns', help='Realiza uma consulta DNS para um domínio')
dns_parser.add_argument('domain', help='Domínio alvo (ex: github.com)')
# --- Subparser para Sniffer ---
sniff_parser = subparsers.add_parser('sniff', help='Inicia o Sniffer de Pacotes (Requer sudo)')
sniff_parser.add_argument('-i', '--interface', default=None, help='Interface de rede para capturar (ex: eth0)')
sniff_parser.add_argument('-c', '--count', type=int, default=0, help='Número de pacotes a capturar (0 para ilimitado)')
sniff_parser.add_argument('-t', '--timeout', type=int, default=None, help='Tempo máximo de captura em segundos')
args = parser.parse_args()
if args.command == 'net':
if args.net_command == 'arp':
results = arp_scan(args.ip_range)
display_results(f"Resultados do ARP Scan em {args.ip_range}", results)
elif args.net_command == 'port':
results = port_scan(args.target, args.ports)
display_results(f"Resultados do Port Scan em {args.target}", results)
elif args.command == 'info':
if args.info_command == 'hash':
file_hash = calculate_file_hash(args.file_path, args.algorithm)
display_results(f"Hash {args.algorithm.upper()} do Arquivo", file_hash)
elif args.info_command == 'whois':
whois_info = whois_lookup(args.domain)
display_results(f"Whois Lookup para {args.domain}", whois_info)
elif args.info_command == 'dns':
ip = dns_lookup(args.domain)
display_results(f"DNS Lookup para {args.domain}", ip)
elif args.command == 'sniff':
print(f"{Fore.YELLOW}Atenção: O Sniffer de Pacotes requer privilégios de root (sudo) para funcionar corretamente.{Style.RESET_ALL}")
start_sniffer(args.interface, args.count, args.timeout)
elif args.command is None:
parser.print_help()
if __name__ == '__main__':
main()