Skip to content

Commit bc1518a

Browse files
v2.4.1 (#137)
## Pull Request Template ### Prerequisites <!-- Take a couple of minutes to help our maintainers work faster by checking of the pre-requisites. --> <!-- To tick the checkboxes replace the space with an 'x', so [ ] becomes [x] . --> - [x] I have [searched](https://github.com/DefinetlyNotAI/Logicytics/pulls) for duplicate or closed issues. - [x] I have read the [contributing guidelines](https://github.com/DefinetlyNotAI/Logicytics/blob/main/CONTRIBUTING.md). - [x] I have followed the instructions in the [wiki](https://github.com/DefinetlyNotAI/Logicytics/wiki) about contributions. - [x] I have updated the documentation accordingly, if required. - [x] I have tested my code with the `--dev` flag, if required. ### PR Type <!-- Take a couple of minutes to help our maintainers work faster by telling us what is the PR guided on. --> <!-- To tick the checkboxes replace the space with an 'x', so [ ] becomes [x] . --> - [x] Bug fix <!-- Non-Breaking Bug Fix - Usually relates to fixing an issue --> - [x] New feature <!-- Non-Breaking Change that adds a new feature --> - [x] Refactoring <!-- Non-Breaking Change that modifies existing code to refactor it to become more organised --> - [x] Documentation update <!-- Non-Breaking Change that modifies existing documentation to refactor it or add extra comments - either wiki, md files or code is included here --> - [ ] ⚠️ Breaking change ⚠️ <!-- Breaking Bug Fix / New Addition that changes how Logicytics works --> ### Description <!-- REQUIRED: Provide a summary of the PR and what you expected to happen. --> Ehh, fixed bugs that made half of the program not run ### Motivation and Context <!-- REQUIRED: Why is this PR required? What problem does it solve? Why do you want to do it? --> Many minor and major bugs ### Credit <!-- If this PR is a contribution, please mention the contributors here using the appropriate syntax. --> <!-- ### File-Created/CONTRIBUTION by MAIN-Username What you did, created, removed, refactored, fixed, or discovered. - [Your GitHub Username](https://github.com/YourGitHubLink) - [Your GitHub Username](https://github.com/YourGitHubLink) etc... --> _N/A_ ### Issues Fixed <!-- REQUIRED: What issues will be fixed? (Format: "#50, #23" etc.) if none exist type _N/A_ --> _N/A_
2 parents 0a513da + f714a5b commit bc1518a

File tree

14 files changed

+308
-276
lines changed

14 files changed

+308
-276
lines changed

CODE/Logicytics.py

Lines changed: 232 additions & 189 deletions
Large diffs are not rendered by default.

CODE/__lib_class.py

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
from __future__ import annotations
2+
23
import argparse
4+
import ctypes
35
import json
46
import os
5-
import subprocess
6-
import ctypes
77
import os.path
8+
import subprocess
89
import zipfile
9-
from subprocess import CompletedProcess
1010
from pathlib import Path
11+
from subprocess import CompletedProcess
12+
1113
from __lib_log import Log
1214

1315

@@ -310,7 +312,7 @@ def uac() -> bool:
310312
return int(value.strip("\n")) == 1
311313

312314
@staticmethod
313-
def sys_internal_zip():
315+
def sys_internal_zip() -> str:
314316
"""
315317
Extracts the SysInternal_Suite zip file if it exists and is not ignored.
316318
@@ -331,49 +333,30 @@ def sys_internal_zip():
331333
"SysInternal_Suite/SysInternal_Suite.zip"
332334
) as zip_ref:
333335
zip_ref.extractall("SysInternal_Suite")
334-
if __name__ == "__main__":
335-
Log({"log_level": DEBUG}).debug("SysInternal_Suite zip extracted")
336+
return "SysInternal_Suite zip extracted"
336337

337338
elif ignore_file:
338-
if __name__ == "__main__":
339-
Log({"log_level": DEBUG}).debug(
340-
"Found .sys.ignore file, skipping SysInternal_Suite zip extraction"
341-
)
339+
return "Found .sys.ignore file, skipping SysInternal_Suite zip extraction"
342340

343341
except Exception as err:
344342
exit(f"Failed to unzip SysInternal_Suite: {err}")
345343

346344

347345
class Execute:
348346
@classmethod
349-
def file(cls, execution_list: list, Index: int):
350-
# IT IS USED, DO NOT REMOVE
351-
"""
352-
Executes a file from the execution list at the specified index.
353-
Parameters:
354-
Index (int): The index of the file to be executed in the execution list.
355-
execution_list (list): List to use when indexing
356-
Returns:
357-
None
358-
"""
359-
cls.script(execution_list[Index])
360-
if __name__ == "__main__":
361-
Log().info(f"{execution_list[Index]} executed")
362-
363-
@classmethod
364-
def script(cls, script_path: str):
347+
def script(cls, script_path: str) -> list[list[str]] | None:
365348
"""
366349
Executes a script file and handles its output based on the file extension.
367350
Parameters:
368351
script_path (str): The path of the script file to be executed.
369352
"""
370-
if script_path.endswith(".ps1"):
371-
cls.__unblock_ps1_script(script_path)
372-
cls.__run_other_script(script_path)
373-
elif script_path.endswith(".py"):
353+
if script_path.endswith(".py"):
374354
cls.__run_python_script(script_path)
355+
return None
375356
else:
376-
cls.__run_other_script(script_path)
357+
if script_path.endswith(".ps1"):
358+
cls.__unblock_ps1_script(script_path)
359+
return cls.__run_other_script(script_path)
377360

378361
@staticmethod
379362
def command(command: str) -> str:
@@ -401,8 +384,6 @@ def __unblock_ps1_script(script: str):
401384
try:
402385
unblock_command = f'powershell.exe -Command "Unblock-File -Path {script}"'
403386
subprocess.run(unblock_command, shell=False, check=True)
404-
if __name__ == "__main__":
405-
Log().info("PS1 Script unblocked.")
406387
except Exception as err:
407388
exit(f"Failed to unblock script: {err}")
408389

@@ -421,23 +402,23 @@ def __run_python_script(script: str):
421402
# LEAVE AS PRINT
422403
print(result.decode())
423404

424-
@staticmethod
425-
def __run_other_script(script: str):
405+
@classmethod
406+
def __run_other_script(cls, script: str) -> list[list[str]]:
426407
"""
427408
Runs a script with other extensions and logs output based on its content.
428409
Parameters:
429410
script (str): The path of the script.
430411
Returns:
431412
None
432413
"""
433-
434-
result = subprocess.run(
435-
["powershell.exe", ".\\" + script], capture_output=True, text=True
436-
)
437-
lines = result.stdout.splitlines()
438-
ID = next((line.split(":")[0].strip() for line in lines if ":" in line), None)
439-
if ID and __name__ == "__main__":
440-
Log().string(str(lines), ID)
414+
result = cls.command(f"powershell.exe -File {script}")
415+
lines = result.splitlines()
416+
messages = []
417+
for line in lines:
418+
if ":" in line:
419+
id_part, message_part = line.split(":", 1)
420+
messages.append([message_part.strip(), id_part.strip()])
421+
return messages
441422

442423

443424
class Get:

CODE/__lib_log.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ def __internal(self, message):
221221
if self.color and message != "None" and message is not None:
222222
colorlog.log(self.INTERNAL_LOG_LEVEL, str(message))
223223

224+
def execute_log_parse(self, message_log):
225+
if message_log:
226+
for message_list in message_log:
227+
if len(message_list) == 2:
228+
self.string(message_list[0], message_list[1])
229+
224230

225231
if __name__ == "__main__":
226232
Log().exception(

CODE/_dev.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,7 @@ def dev_checks(self) -> str | None:
6565
("Have you made files you don't want to be run start with '_'?", "."),
6666
("Have you added the file to CODE dir?", "."),
6767
("Have you added docstrings and comments?", "../CONTRIBUTING.md"),
68-
("Is each file containing no more than 1 feature?", "../CONTRIBUTING.md"),
69-
("Have you NOT modified __wrapper__.py without authorization?", "Logicytics.py"),
68+
("Is each file containing around 1 main feature?", "../CONTRIBUTING.md"),
7069
]
7170
try:
7271
for question, file_to_open in checks:

CODE/_zipper.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ class Zip:
3636
@staticmethod
3737
def __get_files_to_zip(path: str) -> list:
3838
"""
39-
Returns a list of files to be zipped, excluding certain file types and names.
39+
Returns a list of files and directories to be zipped, excluding certain file types and names.
4040
4141
Args:
4242
path (str): The directory path to search for files.
4343
4444
Returns:
45-
list: A list of file names to be zipped.
45+
list: A list of file and directory names to be zipped.
4646
"""
4747
return [
4848
f
@@ -66,7 +66,12 @@ def __create_zip_file(path: str, files: list, filename: str):
6666
"""
6767
with zipfile.ZipFile(f"{filename}.zip", "w") as zip_file:
6868
for file in files:
69-
zip_file.write(os.path.join(path, file))
69+
if os.path.isdir(os.path.join(path, file)):
70+
for root, _, files in os.walk(os.path.join(path, file)):
71+
for f in files:
72+
zip_file.write(os.path.join(root, f), os.path.relpath(os.path.join(root, f), path))
73+
else:
74+
zip_file.write(os.path.join(path, file))
7075

7176
@staticmethod
7277
def __remove_files(path: str, files: list):

CODE/browser_miner.ps1

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ $fullSourcePath = $sourcePath -replace '\{\}', $currentUser
4747
# Enhanced error checking for source path existence and accessibility
4848
if (-not (Test-PathAndAccess $fullSourcePath))
4949
{
50-
Write-Host "ERROR: Source path $fullSourcePath does not exist or cannot be accessed."
50+
Write-Host "WARNING: Source path $fullSourcePath does not exist or cannot be accessed."
5151
continue
5252
}
5353

@@ -84,9 +84,7 @@ Write-Host "INFO: Successfully copied $fullSourcePath to $destinationPath"
8484
catch
8585
{
8686
# Detailed error handling
87-
Write-Host "ERROR: An error occurred while copying $fullSourcePath to $destinationPath. Error: $_"
87+
Write-Host "ERROR: An error occurred while copying $fullSourcePath to $destinationPath : $_"
8888
exit
8989
}
9090
}
91-
92-
# TODO Test me

CODE/config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"Log Level Debug?": false,
3-
"VERSION": "2.4.0",
3+
"VERSION": "2.4.1",
44
"CURRENT_FILES": [
55
"browser_miner.ps1",
66
"cmd_commands.py",
@@ -15,7 +15,7 @@
1515
"ssh_miner.py",
1616
"sys_internal.py",
1717
"tasklist.py",
18-
"tree.bat",
18+
"tree.ps1",
1919
"wifi_stealer.py",
2020
"window_feature_miner.ps1",
2121
"wmic.py",

CODE/media_backup.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@ def backup(self):
6060

6161

6262
Media().backup()
63-
# TODO Test me

CODE/registry.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ def backup_registry():
1616
cmd = [reg_path, "export", "HKLM", export_path]
1717

1818
try:
19-
subprocess.run(cmd, check=True)
20-
log.info(f"Registry backed up successfully to {export_path}")
19+
result = subprocess.run(cmd, check=True, capture_output=True, text=True)
20+
log.info(f"Registry backed up successfully to {export_path}. Output: {result.stdout}")
2121
except subprocess.CalledProcessError as e:
22+
log.error(f"Failed to back up the registry: {e}. More details: {result.stderr}")
23+
except Exception as e:
2224
log.error(f"Failed to back up the registry: {e}")
2325

2426

2527
backup_registry()
26-
# TODO Fix the issue of random operation completion message not adhering colorlog

CODE/ssh_miner.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,3 @@ def ssh_miner():
4444

4545

4646
ssh_miner()
47-
# TODO Test me

0 commit comments

Comments
 (0)