private async Task CheckEvent(IProcessExpectedEvent expectedEvent, IProcessSystemMessage message)
        {
            //todo: good implimentation of Railway pattern chain execution with error handling
            if (!expectedEvent.EventPredicate.Invoke(message))
            {
                return;
            }
            expectedEvent.Validate(message);
            InMessages.AddOrUpdate(expectedEvent.Key, message, (k, v) => message);
            if (ComplexEventAction.ActionTrigger != ActionTrigger.Any && InMessages.Count() != ComplexEventAction.Events.Count)
            {
                return;
            }
            await ExecuteAction(InMessages.ToImmutableDictionary(x => x.Key, x => x.Value as object)).ConfigureAwait(false);

            if (ComplexEventAction.ActionTrigger == ActionTrigger.All)
            {
                InMessages.Clear();
            }
            else
            {
                IProcessSystemMessage msg;
                InMessages.TryRemove(expectedEvent.Key, out msg);
            }
        }
Beispiel #2
0
        public void Receive()
        {
            ArrayList read_socket = new ArrayList();

            Byte[] recvbuff;
            string recv_data;
            int    recvbuflen = 1024;

            while (true)
            {
                for (int i = 0; i < Honeypots.Count; i++)
                {
                    read_socket.Clear();
                    if (Honeypots[i] != null)
                    {
                        read_socket.Add(Honeypots[i].Client);
                        try
                        {
                            Socket.Select(read_socket, null, null, 500000);
                            if (read_socket.Count > 0)
                            {
                                recvbuff = new Byte[recvbuflen];
                                Honeypots[i].Client.Receive(recvbuff);
                                recv_data = Encoding.ASCII.GetString(recvbuff);
                                if (!string.IsNullOrEmpty(recv_data))
                                {
                                    if (recv_data != "-1")
                                    {
                                        Console.WriteLine("Incoming message, IP: " + ((IPEndPoint)Honeypots[i].Client.RemoteEndPoint).Address);
                                        InMessages.Enqueue(new Message(recv_data, Honeypots[i].Client));
                                        recv_data = "-1";       // "-1" is a special string, used to tell if the buffer was read in the current iteration.
                                    }
                                }
                                else
                                {
                                    Honeypots[i].Client.Close();
                                    Honeypots[i].Close();
                                    Honeypots.RemoveAt(i);    // remove the problematic socket from the clients list
                                    break;                    // break from the current for, so the loop would initiate according to the removal of the socket
                                }
                            }
                        }
                        catch (Exception)
                        {
                            Honeypots[i].Client.Close();
                            Honeypots[i].Close();
                            Honeypots.RemoveAt(i);    // remove the problematic socket from the clients list
                            break;                    // break from the current for, so the loop would initiate according to the removal of the socket
                        }
                    }
                }
            }
        }
        private void handleComplexEventLogRequest()
        {
            var xlogs = ComplexEventAction.Events.CreatEventLogs(InMessages.ToDictionary(x => x.Key, x => x.Value), Source);
            var ologs = OutMessages.CreatEventLogs(Source);
            var res   = new List <IComplexEventLog>();

            res.AddRange(xlogs);
            res.AddRange(ologs);

            var msg = new ComplexEventLogCreated(res, new StateEventInfo(Process.Id, RevolutionData.Context.Process.Events.ComplexEventLogCreated), Process, Source);

            Publish(msg);
        }
Beispiel #4
0
 public void CallHandlers()
 {
     while (true)
     {
         if (InMessages.Count > 0 && HandleThreadsCurrentlyRunning < MAX_HANDLE_THREADS)
         {
             Message msg;
             lock (InMessages)
             {
                 msg = InMessages.Dequeue();
             }
             var thread = new Thread(() => HandleMessage(msg));
             thread.Start();
         }
     }
 }
        public void Receive()
        {
            string raw_message;

            Byte[] buffer = new Byte[1024];
            while (true)
            {
                try
                {
                    if (Client.Connected)
                    {
                        Client.Client.Receive(buffer);
                        raw_message = Encoding.ASCII.GetString(buffer);
                        raw_message = raw_message.Substring(0, raw_message.IndexOf("||") + 2);
                        InMessages.Enqueue(raw_message);
                    }
                }
                catch (Exception)
                {
                    Console.WriteLine("Connection is down, exiting program.");
                    Process.GetCurrentProcess().Kill();
                }
            }
        }