Example #1
0
        static void Udp()
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            socket.Bind(new IPEndPoint(IPAddress.Parse("192.168.1.106"), 5050));

            socket.Connect(new IPEndPoint(IPAddress.Parse("192.168.1.104"), 5050));

            //\\.\pipe\MMYY
            var wir = WiresharkSender.Create("MMYY");

            var read = ReadUDPAndWir(socket, wir);

            //Func<byte[], int,int,int> read = (buffer, offset, count) => socket.Receive(buffer, offset, count, SocketFlags.None);

            var write = WriteUDPAndWir(socket, wir);


            //Action<byte[], int, int> write = (buffer, offset, count) => socket.Send(buffer, offset, count, SocketFlags.None);

            byte[] buffer = new byte[ushort.MaxValue];

            while (true)
            {
                int n = read(buffer, 0, buffer.Length);

                AsTo.As(buffer.AsSpan(0, n), CreateAs(80, 8888));



                write(buffer, 0, n);
            }

            Console.ReadLine();
        }
Example #2
0
 public NamedPipeSniffer(ChromeMonitor chromeMonitor, string wiresharkPipeName, string nameFilter = "", bool recordOnlyNewMojoPipes = false)
 {
     this.wiresharkSender           = new WiresharkSender(wiresharkPipeName, 1);
     this.namedPipeFiles            = new Dictionary <string, NamedPipeInfo>();
     this.destoryedNamedPipes       = new List <string>();
     this.chromeMonitor             = chromeMonitor;
     this.recordingOnlyNewMojoPipes = recordOnlyNewMojoPipes;
     this.pipeNameFilter            = nameFilter;
     this.lastDropTime        = DateTime.Now;
     this.numPacketsProcessed = 0;
 }
Example #3
0
        static Action <byte[], int, int> WriteUDPAndWir(Socket socket, WiresharkSender sender)
        {
            byte[] readArray = new byte[ushort.MaxValue];

            int index = WriteDes(readArray);


            return((buffer, offset, count) =>
            {
                buffer.AsSpan(offset, count).CopyTo(readArray.AsSpan(index));



                sender.SendToWireshark(readArray, 0, index + count);

                socket.Send(readArray, index, count, SocketFlags.None);
            });
        }
Example #4
0
        static Func <byte[], int, int, int> ReadUDPAndWir(Socket socket, WiresharkSender sender)
        {
            byte[] readArray = new byte[ushort.MaxValue];

            int index = WriteSource(readArray);


            return((buffer, offset, count) =>
            {
                int n = socket.Receive(readArray, index, readArray.Length - index, SocketFlags.None);


                sender.SendToWireshark(readArray, 0, n + index);

                readArray.AsSpan(index, n).CopyTo(buffer.AsSpan(offset, count));

                return n;
            });
        }
Example #5
0
        static void Main(string[] args)
        {
            // parse command line options

            string serialPortName = SerialPort.GetPortNames().FirstOrDefault();
            string pipeName       = "conbee";
            byte   zigBeeChannel  = 15;
            string wiresharkExe   = "";

            var options = new OptionSet();

            options.Add(new OptionSet.Category("USAGE: DeConBee2Wireshark [options]"));
            options.Add("p|port=", "Serial Port (e.g. 'COM3', default is first available serial port)", x => serialPortName   = x);
            options.Add("i|pipe=", String.Format(@"Pipe Name (defaults to '{0}' => '\\.\pipe\{0}')", pipeName), x => pipeName = x);
            options.Add("c|channel=", String.Format("ZigBee Channel to Listen on (defaults to {0})", zigBeeChannel), (byte x) => zigBeeChannel = x);
            options.Add("w|wireshark=", "Path to Wireshark.exe", x => wiresharkExe = x);
            options.Add("v|verbose", "Show Verbose Output", x => Verbose           = true);
            options.Add("h|?|help", x => ShowHelpAndExit(options));
            options.Add(new OptionSet.Category(""));
            options.Add(new OptionSet.Category("IMPORTANT: You need a ConBee USB stick from dresden elektronik (www.dresden-elektronik.de) WITH BITCATCHER FIRMWARE for this tool to work!"));

            try
            {
                var unprocessed = options.Parse(args);
                if (unprocessed.Count > 0)
                {
                    throw new ArgumentException(string.Format("Unrecognized command line arguments {0}.",
                                                              String.Join(" ", unprocessed.Select(x => String.Format("'{0}'", x)))
                                                              ));
                }
            }
            catch (Exception e)
            {
                ShowHelpAndExit(options, e.Message);
            }


            // connect to ConBee USB stick

            try
            {
                if (string.IsNullOrWhiteSpace(serialPortName))
                {
                    throw new ApplicationException("No serial port found or provided");
                }

                ComPort = new SerialPort(serialPortName, 38400, Parity.None, 8, StopBits.One);
                ComPort.Open();
            }
            catch (Exception ex)
            {
                throw new ApplicationException("Error opening serial port", ex);
            }


            // open pipe and wait for wireshark to connect

            TextOutput.WriteLine("DeConBee2Wireshark started (port '{0}', pipe '{1}', zigbee channel {2})", serialPortName, pipeName, zigBeeChannel);
            TextOutput.WriteLine();

            var wiresharkSender = new WiresharkSender(pipeName, 0xc3);

            bool wiresharkIsChild = !string.IsNullOrWhiteSpace(wiresharkExe);

            if (wiresharkIsChild)
            {
                try
                {
                    Process.Start(wiresharkExe, String.Format(@"-i\\.\pipe\{0} -k", pipeName));
                }
                catch (Exception ex)
                {
                    throw new ApplicationException("Error starting Wireshark", ex);
                }
            }
            else
            {
                TextOutput.WriteLine(@"Now start Wireshark with command line arguments -i\\.\pipe\{0} -k", pipeName);
                TextOutput.WriteLine();
            }

            TextOutput.Write(@"Waiting for Wireshark to connect to pipe \\.\pipe\{0}: ", pipeName);
            while (!wiresharkSender.isConnected)
            {
                if (!wiresharkIsChild)
                {
                    TextOutput.Write(".");
                }
                Thread.Sleep(500);
            }
            if (!wiresharkIsChild)
            {
                TextOutput.WriteLine();
            }

            TextOutput.WriteLine("Wireshark connected.");
            TextOutput.WriteLine();

            // discard any old frames
            ComPort.DiscardOutBuffer();
            ComPort.DiscardInBuffer();

            // select channel
            ConBeeSendFrame(new byte[] { 0x09, zigBeeChannel, 0x00 });

            // start sniffing
            try
            {
                ConBeeSendFrame(new byte[] { 0x0b });

                ComPort.ReadTimeout = 1000;
                var frameAck = ConBeeReadFrame();
                if (frameAck[0] != 0x0c)
                {
                    throw new InvalidDataException();
                }
            }
            catch (Exception ex)
            {
                throw new ApplicationException(String.Format("None or invalid data received from COM port. Are you sure a dresden elektronik ConBee USB stick WITH BITCATCHER FIRMWARE is connected to port {0}?", serialPortName), ex);
            }

            // read frames and forward to wireshark
            ComPort.ReadTimeout = SerialPort.InfiniteTimeout;
            while (true)
            {
                var payload = ConBeeReadFrame();
                if (payload[0] == 0x50 && payload.Length > 9)
                {
                    var result = wiresharkSender.SendToWireshark(payload, 9, payload.Length - 9);
                    if (!result)
                    {
                        TextOutput.WriteLine();
                        TextOutput.WriteLine("Pipe broken, Wireshark might have exited - exiting as well.");
                        break;
                    }
                }
            }
        }