Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
dmdhrumilmistry committed Aug 3, 2024
1 parent 77cb80b commit df9a689
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 85 deletions.
178 changes: 94 additions & 84 deletions pyhtools/UI/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,28 @@

from asyncio.exceptions import CancelledError
from prettytable import PrettyTable
from pyhtools.UI.colors import BRIGHT_RED, BRIGHT_WHITE, BRIGHT_YELLOW, RESET_COLORS
try:
from pyhtools_evil_files.malwares.utils import send_mail
from pyhtools_evil_files.malwares.reverse_backdoor.TCP.listener import Listener
except ModuleNotFoundError:
print(BRIGHT_RED + '[!] evil module not found. Install using command: pip install git+https://github.com/dmdhrumilmistry/pyhtools-evil-files.git')
exit(-1)
from pyfiglet import figlet_format

from pyhtools_evil_files.malwares.utils import send_mail
from pyhtools_evil_files.malwares.reverse_backdoor.TCP.listener import Listener

from pyhtools.UI.colors import BRIGHT_RED, BRIGHT_WHITE, BRIGHT_YELLOW, RESET_COLORS
# TODO: remove pyhtools/attackers/attackers.py and add it to pyhtools/attackers/__init__.py
from pyhtools.attackers.attackers import (
mac_changer,
arpspoofer,
nw_scan,
webspider,
webcrawldirs,
webcrawlsubdom,
brute_login,
webvulnscan,
)

import pyfiglet
import pyhtools.attackers.attackers as attacker

def clrscr():
'''Clears UI screen
Args:
None
Expand All @@ -39,9 +46,9 @@ def banner():
None
'''
clrscr()
print(BRIGHT_YELLOW + pyfiglet.figlet_format('PyHTools'))
print(BRIGHT_YELLOW + figlet_format('PyHTools'))
print(BRIGHT_YELLOW + '+' + '-'*42 + '+')
print(BRIGHT_WHITE + f'| written by dmdhrumilmistry |')
print(BRIGHT_WHITE + '| written by dmdhrumilmistry |')
print(BRIGHT_YELLOW + '+' + '-'*42 + '+')


Expand All @@ -51,43 +58,43 @@ def print_help():
Args:
None
Returns:
None
'''
print(BRIGHT_WHITE + 'Python Hacking Tools (PyHTools) (pht)')

help = PrettyTable(['Command', 'Description'])
help.align['Command'] = 'c'
help.align['Description'] = 'l'
# help.add_row(['',''])
help_table = PrettyTable(['Command', 'Description'])
help_table.align['Command'] = 'c'
help_table.align['Description'] = 'l'
# help_table.add_row(['',''])

help.add_row(['clear', 'clear console'])
help.add_row(['help', 'display help table'])
help.add_row(['close', 'exit PyHackingTools'])
help_table.add_row(['clear', 'clear console'])
help_table.add_row(['help_table', 'display help_table table'])
help_table.add_row(['close', 'exit PyHackingTools'])

help.add_row(['machngr', 'change mac address of the network interface'])
help.add_row(['arpspoofer', 'spoof the target by arp poisoning'])
help.add_row(['nwscan', 'scan for ip range in the network'])
help_table.add_row(['machngr', 'change mac address of the network interface'])
help_table.add_row(['arpspoofer', 'spoof the target by arp poisoning'])
help_table.add_row(['nwscan', 'scan for ip range in the network'])

help.add_row(
help_table.add_row(
['webspider', 'maps all the links which are related to root url on the website'])
help.add_row(
help_table.add_row(
['webcrawldirs', 'scan for valid directories of the website using a wordlist'])
help.add_row(
help_table.add_row(
['webcrawlsubdom', 'scan for valid subdomains of the website using a wordlist'])
help.add_row(['weblogin', 'bruteforce webpage login'])
help.add_row(['webvulnscan', 'scan for vulnerabilities on the website'])
help_table.add_row(['weblogin', 'bruteforce webpage login'])
help_table.add_row(['webvulnscan', 'scan for vulnerabilities on the website'])

# help.add_row(['',''])
# help_table.add_row(['',''])

help.add_row(['listener', 'start reverse TCP listener on specific LHOST and LPORT'])
help.add_row(['sendmail', 'send mail to specific email address'])
help_table.add_row(['listener', 'start reverse TCP listener on specific LHOST and LPORT'])
help_table.add_row(['sendmail', 'send mail to specific email address'])

help.add_row(
help_table.add_row(
['gen exe', 'generate executables of reverse backdoor, keylogger, etc.'])

print(help)
print(help_table)


def send_mail_to(email, password, receiver, subject, body) -> bool:
Expand All @@ -107,8 +114,10 @@ def send_mail_to(email, password, receiver, subject, body) -> bool:
msg = f'Subject: {subject}\n{body}'
if send_mail(email, receiver, password, msg):
print(BRIGHT_YELLOW + '[\u2714] Mail Sent')
else:
print(BRIGHT_RED + '[\u274c] Unable to send mail.')
return True

print(BRIGHT_RED + '[\u274c] Unable to send mail.')
return False


def listener_option():
Expand Down Expand Up @@ -148,14 +157,14 @@ def sendmail_option():

def machngr_option():
'''executes commands to change mac address
Args:
None
Returns:
None
'''
attacker.mac_changer()
mac_changer()


def generate_executable():
Expand All @@ -173,70 +182,71 @@ def generate_executable():
'[*] You can use scripts from malwares to manually generate evil files...')


async def run():
'''starts PyHTools UI, interacts with user and executes appropriate
functions based on command
async def run_command(cmd: str):
# BASIC UI COMMANDS
match cmd:
case 'clear':
clrscr()

Args:
None
case 'help_table':
print_help()

Returns:
None
'''
try:
while True:
cmd = input(BRIGHT_RED + 'pyhtools >>' +
RESET_COLORS + ' ').lower().strip()
# MALWARES
case 'listener':
listener_option()

# BASIC UI COMMANDS
if cmd == 'close':
break
case 'sendmail':
sendmail_option()

elif cmd == 'clear':
clrscr()
case 'gen exe':
generate_executable()

elif cmd == 'help':
print_help()
# NETWORK ATTACKERS
case 'machngr':
machngr_option()

# MALWARES
elif cmd == 'listener':
listener_option()
case 'arpspoofer':
arpspoofer()

elif cmd == 'sendmail':
sendmail_option()
case 'nwscan':
nw_scan()

elif cmd == 'gen exe':
generate_executable()
# WEB ATTACKERS
case 'webspider':
await webspider()

# NETWORK ATTACKERS
elif cmd == 'machngr':
machngr_option()
case 'webcrawldirs':
await webcrawldirs()

elif cmd == 'arpspoofer':
attacker.arpspoofer()
case 'webcrawlsubdom':
await webcrawlsubdom()

elif cmd == 'nwscan':
attacker.nw_scan()
case 'weblogin':
brute_login()

# WEB ATTACKERS
elif cmd == 'webspider':
await attacker.webspider()
case 'webvulnscan':
webvulnscan()

elif cmd == 'webcrawldirs':
await attacker.webcrawldirs()
case _:
print(BRIGHT_RED + '[-] Unknown command, use help_table to view valid commands')

elif cmd == 'webcrawlsubdom':
await attacker.webcrawlsubdom()

elif cmd == 'weblogin':
attacker.brute_login()
async def run():
'''starts PyHTools UI, interacts with user and executes appropriate
functions based on command
elif cmd == 'webvulnscan':
attacker.webvulnscan()
Args:
None
else:
print(BRIGHT_RED +
'[-] Unknown command, use help to view valid commands')
Returns:
None
'''
try:
while True:
cmd = input(BRIGHT_RED + 'pyhtools >>' + RESET_COLORS + ' ').lower().strip()
if cmd == 'close':
break
await run_command(cmd)

except (EOFError, KeyboardInterrupt, CancelledError):
print()
Expand Down
1 change: 0 additions & 1 deletion pyhtools/attackers/attackers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from asyncio import run
from pyhtools.UI.colors import BRIGHT_YELLOW, BRIGHT_WHITE
from pyhtools.attackers.web.vuln_scanner.scanner import Scanner
from pyhtools.attackers.web.spider import Spider
Expand Down

0 comments on commit df9a689

Please sign in to comment.