Ejemplo n.º 1
0
        public async Task <Data.Target> ModifyTarget(Data.Target target)
        {
            try
            {
                Data.Target existTarget =
                    await _dbContext
                    .Targets
                    .SingleOrDefaultAsync(t => t.TargetId.Equals(target.TargetId));

                if (existTarget == null)
                {
                    await _dbContext.Targets.AddAsync(target);
                }
                else
                {
                    _dbContext.Targets.Update(target);
                }

                await _dbContext.SaveChangesAsync();

                return(existTarget ?? target);
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
Ejemplo n.º 2
0
        private void ModifyTable(ICollection <Candidate> candidatesToAssign, Candidate candidate, Target target, DateTime requestTime, DateTime assignedTime, TimeSpan algoExecution, int algo, int maxLoad)
        {
            Data.Candidate modCandidate = _dataBusiness.GetCandidate(candidate.Id);
            modCandidate.TotalTravel += (int)candidate.DistanceToTarget;
            modCandidate.IsAssigned   = true;
            modCandidate.Load++;

            Data.Target modTarget = _dataBusiness.GetTarget(target.Id);
            modTarget.LastRequest = requestTime;

            string transactionId = Guid.NewGuid().ToString();

            Data.Transaction modTransaction = new Data.Transaction
            {
                TransactionId          = transactionId,
                From                   = modTarget,
                To                     = modCandidate,
                RequestAt              = requestTime,
                AssigneeAt             = assignedTime,
                Distance               = candidate.DistanceToTarget,
                AlgorithmExecutionTime = algoExecution,
                Algorithm              = algo == 1 ? "Nearest Neighbor" : "Round Robin",
                Candidates             = Newtonsoft.Json.JsonConvert.SerializeObject(candidatesToAssign),
                MaxLoad                = maxLoad,
            };

            _ = _dataBusiness.ModifyCandidate(modCandidate);
            _ = _dataBusiness.ModifyTarget(modTarget);
            _ = _dataBusiness.ModifyTransaction(modTransaction);
            // _ = _dataBusiness.CreateJsonFile($"Transaction_{transactionId}", candidatesToAssign);
        }
Ejemplo n.º 3
0
 public static Target ToLibTarget(this Data.Target target)
 {
     return new Target
     {
         Id = target.TargetId,
         Location = new Location
         {
             Latitude = target.Latitude,
             Longitude = target.Longitude
         }
     };
 }
Ejemplo n.º 4
0
        private void RoutePacket(Packet p)
        {
            if (p == null)
            {
                return;
            }

            EthernetPacket pEthernet = (EthernetPacket)p;

            if ((pEthernet.PayloadPacket is IPv6Packet) == false && (pEthernet.PayloadPacket is IPv4Packet) == false)
            {
                return;
            }

            IpPacket pIp = (IpPacket)pEthernet.PayloadPacket;

            // Si es IPv6 y va hacia afuera de la red...
            if (((pEthernet.PayloadPacket is IPv6Packet)))
            {
                if (pIp.DestinationAddress.IsIPv6LinkLocal == false &&
                    pIp.DestinationAddress.IsIPv6Multicast == false &&
                    pIp.DestinationAddress.IsIPv6Teredo == false &&
                    pIp.DestinationAddress.IsIPv6SiteLocal == false
                    )
                {
                    // Si ademas viene a mi MAC y no a mi IP ... sera para que lo enrute.
                    // Probablemente venga por un ataque SLAAC MITM
                    if (Program.CurrentProject.data.GetAttacks().Where(A => A.attackType == AttackType.SlaacMitm && A.attackStatus == AttackStatus.Attacking).Count() > 0)
                    {
                        bool needToRoute = !IsGoingToMyIPAddress(p);
                        if (needToRoute && IsGoingToMyMac(p))
                        {
                            Ipv6ToIpv4(pEthernet);

                            return;
                        }
                    }
                }
            }


            // Si es IPv4 o IPv6-LinkLocal
            if ((pEthernet.PayloadPacket is IPv4Packet) ||
                ((pEthernet.PayloadPacket is IPv6Packet) && pIp.DestinationAddress.IsIPv6LinkLocal == true)
                )
            {
                // Si van dirigidos a mi MAC pero no a mi IP, a reenviar
                bool needToRoute = !IsGoingToMyIPAddress(p);


                if (needToRoute && IsGoingToMyMac(p))
                {
                    // Actualizamos el numero de paquetes que está enviando el target
                    Data.Target targetSender   = null;
                    Data.Target targetReceiver = null;

                    foreach (Data.Attack attack in attacks)
                    {
                        if (attack is MitmAttack && attack.attackType != AttackType.SlaacMitm)
                        {
                            if (((MitmAttack)attack).t1.mac.Equals(pEthernet.SourceHwAddress))
                            {
                                targetSender   = ((MitmAttack)attack).t1;
                                targetReceiver = ((MitmAttack)attack).t2;
                                break;
                            }
                            else if (((MitmAttack)attack).t2.mac.Equals(pEthernet.SourceHwAddress))
                            {
                                targetSender   = ((MitmAttack)attack).t2;
                                targetReceiver = ((MitmAttack)attack).t1;
                                break;
                            }
                            else
                            {
                                targetSender   = null;
                                targetReceiver = null;
                            }
                        }
                    }
                    if (targetReceiver == null || targetSender == null)
                    {
                        return;
                    }

                    // Modificamos el paquete para enrutarlo
                    // ...
                    // entra aqui cuando viene desde la red a un equipo local
                    if (targetReceiver.ip.Equals(pIp.DestinationAddress))
                    {
                        PhysicalAddress newDestinationMac = Program.CurrentProject.data.GetNeighborMAC(pIp.DestinationAddress);
                        pEthernet.DestinationHwAddress = newDestinationMac;
                        pEthernet.SourceHwAddress      = localPhysicalAddress;

                        if (pEthernet.PayloadPacket.PayloadPacket is UdpPacket)
                        {
                            ((UdpPacket)pEthernet.PayloadPacket.PayloadPacket).UpdateUDPChecksum();
                        }

                        Program.CurrentProject.data.SendPacket(pEthernet);
                        targetReceiver.packetsSend++;
                    }

                    // Entra aqui cuando va desde el equipo local a la red
                    if (targetSender.ip.Equals(pIp.SourceAddress) && targetSender.mac.Equals(pEthernet.SourceHwAddress))
                    {
                        pEthernet.DestinationHwAddress = targetReceiver.mac;
                        pEthernet.SourceHwAddress      = localPhysicalAddress;

                        if (pEthernet.PayloadPacket.PayloadPacket is UdpPacket)
                        {
                            ((UdpPacket)pEthernet.PayloadPacket.PayloadPacket).UpdateUDPChecksum();
                        }

                        Program.CurrentProject.data.SendPacket(pEthernet);
                        targetReceiver.packetsSend++;
                        //targetSender.packetsSend++;
                    }
                }
            }
        }