Esempio n. 1
0
        private static void BroadcastMagicPacket(PhysicalAddress physicalAddress, IPAddress broadcastIPAddress)
        {
            if (physicalAddress == null) throw new ArgumentNullException(nameof(physicalAddress));

            var physicalAddressBytes = physicalAddress.GetAddressBytes();

            var packet = new byte[17 * 6];

            for (var i = 0; i < 6; i++)
            {
                packet[i] = 0xFF;
            }

            for (var i = 1; i <= 16; i++)
            {
                for (var j = 0; j < 6; j++)
                {
                    packet[i * 6 + j] = physicalAddressBytes[j];
                }
            }

            using (var client = new UdpClient())
            {
                client.Connect(broadcastIPAddress ?? IPAddress.Broadcast, 40000);
                client.Send(packet, packet.Length);
            }
        }
Esempio n. 2
0
        public Target(string description)
        {
            this.ip = null;
            this.mac = null;

            this.description = description;
        }
        /// <summary>
        /// Construct a new ethernet packet from source and destination mac addresses
        /// </summary>
        public EthernetPacket(PhysicalAddress SourceHwAddress,
                              PhysicalAddress DestinationHwAddress,
                              EthernetPacketType ethernetPacketType,
                              byte[] EthernetPayload)
        {
            int ethernetPayloadLength = 0;
            if (EthernetPayload != null)
            {
                ethernetPayloadLength = EthernetPayload.Length;
            }

            _bytes = new byte[EthernetFields_Fields.ETH_HEADER_LEN + ethernetPayloadLength];
            _ethernetHeaderLength = EthernetFields_Fields.ETH_HEADER_LEN;
            _ethPayloadOffset = _ethernetHeaderLength;

            // if we have a payload, copy it into the byte array
            if (EthernetPayload != null)
            {
                Array.Copy(EthernetPayload, 0, _bytes, EthernetFields_Fields.ETH_HEADER_LEN, EthernetPayload.Length);
            }

            // set the instance values
            this.SourceHwAddress = SourceHwAddress;
            this.DestinationHwAddress = DestinationHwAddress;
            this.EthernetProtocol = ethernetPacketType;
        }
Esempio n. 4
0
        private static void GetMacAddress(System.Net.IPAddress address, Action<PhysicalAddress> callback)
        {
            new Thread(() =>
            {
                try
                {
                    var destAddr = BitConverter.ToInt32(address.GetAddressBytes(), 0);

                    var srcAddr = BitConverter.ToInt32(System.Net.IPAddress.Any.GetAddressBytes(), 0);

                    var macAddress = new byte[6];

                    var macAddrLen = macAddress.Length;

                    var ret = SendArp(destAddr, srcAddr, macAddress, ref macAddrLen);

                    if (ret != 0)
                    {
                        throw new System.ComponentModel.Win32Exception(ret);
                    }

                    var mac = new PhysicalAddress(macAddress);

                    if (callback != null)
                        callback(mac);
                }
                catch
                {
                    //do nothing
                }
            })
            {
                IsBackground = true
            }.Start();
        }
Esempio n. 5
0
 public ChassisID(PhysicalAddress MACAddress)
 {
     this.EmptyTLVDataInit();
     base.Type = TLVTypes.ChassisID;
     this.SubType = ChassisSubTypes.MACAddress;
     this.SubTypeValue = MACAddress;
 }
        internal NetworkList(NamedKey nk, byte[] bytes)
        {
            WriteTime = nk.WriteTime;

            foreach (ValueKey vk in nk.GetValues(bytes))
            {
                switch (vk.Name)
                {
                    case "ProfileGuid":
                        ProfileGuid = Encoding.Unicode.GetString(vk.GetData(bytes));
                        break;
                    case "Description":
                        Description = Encoding.Unicode.GetString(vk.GetData(bytes));
                        break;
                    case "Source":
                        Source = BitConverter.ToUInt32(vk.GetData(bytes), 0x00);
                        break;
                    case "DnsSuffix":
                        DnsSuffix = Encoding.Unicode.GetString(vk.GetData(bytes));
                        break;
                    case "FirstNetwork":
                        FirstNetwork = Encoding.Unicode.GetString(vk.GetData(bytes));
                        break;
                    case "DefaultGatewayMac":
                        DefaultGatewayMac = new PhysicalAddress(vk.GetData(bytes));
                        break;
                    default:
                        break;
                }
            }
        }
Esempio n. 7
0
        public SlaacMITM(WinPcapDevice device, IList<Data.Attack> attacks)
        {
            this.device = device;
            this.attacks = attacks;

            invalidMac = PhysicalAddress.Parse("00-00-00-00-00-00");
        }
Esempio n. 8
0
 public Connected(string name, string remarks, PhysicalAddress macAddress, IEnumerable<Command.Response.Device> roster)
 {
     Name = name;
     Remarks = remarks;
     MacAddress = macAddress;
     Roster = (roster ?? Enumerable.Empty<Command.Response.Device>()).ToArray();
 }
Esempio n. 9
0
        public FormAddNeighbor()
        {
            ip = null;
            mac = null;

            InitializeComponent();
        }
Esempio n. 10
0
        public CGConnect(byte[] bytes)
        {
            Stream stream = new MemoryStream(bytes);

            // read packet id
            this.ID = (PacketID)ReadUInt16(stream);

            // read size
            this.BodySize = ReadUInt32(stream);

            // read timestamp
            this.TimeStamp = ReadUInt32(stream);

            // check packet id
            if (this.ID == PacketID.CGConnect)
            {
                // read authkey
                this.AuthKey = ReadInt32(stream);

                // read PCType
                this.PCType = (PCType)stream.ReadByte();

                // read szPCName
                this.PCName = ReadString(stream);

                // read MacAddress
                this.MacAddress = ReadMacAddress(stream);

                _binit = true;
            }
        }
Esempio n. 11
0
        static void Main(string[] args)
        {
            try {
                dashMac = PhysicalAddress.Parse(Properties.Settings.Default.DashMac.Replace("-", "").Replace(":", "").ToUpper());
            } catch (Exception e) {
                if (!string.IsNullOrWhiteSpace(Properties.Settings.Default.DashMac)) {
                    Console.WriteLine("Error: Could not parse dash mac address: " + e.Message);
                    return;
                }
            }

            CaptureDeviceList devices = CaptureDeviceList.Instance;

            if (devices.Count < 1) {
                Console.WriteLine("No devices were found on this machine");
                return;
            }

            Console.WriteLine("The following devices are available on this machine:");
            for (int i = 0; i < devices.Count; i++) {
                ICaptureDevice dev = devices[i];
                Console.WriteLine($"{i}: {dev.Description}");
            }

            ICaptureDevice device = devices[Properties.Settings.Default.InterfaceIndex];
            device.OnPacketArrival += device_OnPacketArrival;
            device.Open(DeviceMode.Promiscuous, ReadTimeoutMilliseconds);
            device.StartCapture();
            Console.WriteLine($"-- Listening on {Properties.Settings.Default.InterfaceIndex}, hit 'Enter' to stop...");
            Console.ReadLine();
            device.StopCapture();
            device.Close();
        }
Esempio n. 12
0
        private static void SendResponse(System.Net.NetworkInformation.PhysicalAddress pysSrc,
                                         System.Net.NetworkInformation.PhysicalAddress pysdest,
                                         IPAddress destAddrIp,
                                         IPAddress myAddrIp) //builds arp packed and sends it to poison
        {
            CaptureDeviceList devices = CaptureDeviceList.Instance;

            foreach (ICaptureDevice dev in devices)
            {
                dev.Open();

                //System.Net.NetworkInformation.PhysicalAddress pysSrc = null;
                //System.Net.NetworkInformation.PhysicalAddress pysdest = null;
                //IPAddress destAddrIp = new IPAddress(null);
                //IPAddress myAddrIp = new IPAddress(null);

                try
                {
                    var ethernetPacket = new PacketDotNet.EthernetPacket(pysSrc, pysdest, PacketDotNet.EthernetPacketType.Arp);

                    var arpPacket = new PacketDotNet.ARPPacket(PacketDotNet.ARPOperation.Response, pysdest, destAddrIp, pysSrc, myAddrIp);
                    ethernetPacket.PayloadPacket = arpPacket;

                    dev.SendPacket(ethernetPacket);
                }
                catch (Exception e)
                {
                }
            }
        }
 public InvalidMacSpoofAttackIpv4Attack(Target t1, Target t2, AttackType attackType)
     : base(attackType)
 {
     invalidMac = PhysicalAddress.Parse("FA-BA-DA-FA-BA-DA".ToUpper());
     this.t1 = t1;
     this.t2 = t2;
 }
        public static void LocalMacAndIPAddress( out byte[] ip, out PhysicalAddress mac )
        {
            ip = new byte[4];
            mac = PhysicalAddress.None;
            //get the interface
            NetworkInterface TrueNic = null;
            foreach ( NetworkInterface nic in NetworkInterface.GetAllNetworkInterfaces() )
            {
                if ( nic.OperationalStatus == OperationalStatus.Up )
                {
                    TrueNic = nic;
                    break;
                }
            }

            //get the interface ipv4
            foreach ( IPAddress ips in Dns.GetHostEntry( Environment.MachineName ).AddressList )
            {
                if ( ips.AddressFamily == System.Net.Sockets.AddressFamily.InterNetwork )
                {
                    ip = ips.GetAddressBytes();
                    break;
                }
            }
            //get the interface mac
            try
            {
                mac = PhysicalAddress.Parse(TrueNic.GetPhysicalAddress().ToString());
            }
            catch { }
        }
Esempio n. 15
0
 public MacRule(PacketStatus ps, PhysicalAddress mac, Direction direction, bool log, bool notify)
 {
     this.ps = ps;
     this.mac = mac.GetAddressBytes();
     this.direction = direction;
     this.log = log;
     this.notify = notify;
 }
Esempio n. 16
0
        public Host(PhysicalAddress mac, IPAddress ipAddress)
        {
            _mac = mac;
            _ipAddress = ipAddress;
            _hostname = _ipAddress.ToString();

            DnsRequests.Enqueue(Resolve);
        }
Esempio n. 17
0
 public Registration(Command.Endpoint.IInstance commandEndpoint, Version version, string name, string remarks, PhysicalAddress macAddress)
 {
     CommandEndpoint = commandEndpoint;
     Version = version;
     Name = name;
     Remarks = remarks;
     MacAddress = macAddress;
 }
Esempio n. 18
0
 public Router(WinPcapDevice dev, SynchronizedCollection<Data.Attack> attacks, SynchronizedCollection<string> slaacReqs)
 {
     this.device = dev;
     this.localPhysicalAddress = device.MacAddress;
     this.attacks = attacks;
     //this.slaacReqs = slaacReqs;
     this.dnsHijacking = new DNSHijacking(dev, attacks);
 }
Esempio n. 19
0
			/// <summary>
			/// Initializes a new instance of the <see cref="PacketDotNet.Ieee80211.CtsFrame"/> class.
			/// </summary>
			/// <param name='ReceiverAddress'>
			/// Receiver address.
			/// </param>
			public CtsFrame (PhysicalAddress ReceiverAddress)
			{
				this.FrameControl = new FrameControlField ();
                this.Duration = new DurationField ();
				this.ReceiverAddress = ReceiverAddress;
				
                this.FrameControl.SubType = FrameControlField.FrameSubTypes.ControlCTS;
			}
Esempio n. 20
0
        public BthDevice(IBthDevice device, PhysicalAddress master, byte lsb, byte msb)
            : base(new BthHandle(lsb, msb))
        {
            InitializeComponent();

            BluetoothDevice = device;
            HostAddress = master;
        }
Esempio n. 21
0
        /// <summary>
        /// Sendet ein Wake-On-LAN-Signal an einen Client.
        /// </summary>
        /// <param name="target">Der Ziel-IPEndPoint.</param>
        /// <param name="macAddress">Die MAC-Adresse des Clients.</param>
        /// <exception cref="System.ArgumentNullException">macAddress ist null.</exception>
        /// <exception cref="System.Net.Sockets.SocketException">Fehler beim Zugriff auf den Socket. Weitere Informationen finden Sie im Abschnitt "Hinweise".</exception>
        public static void Send(IPEndPoint target, PhysicalAddress macAddress)
        {
            if (macAddress == null)
                throw new ArgumentNullException("macAddress");

            byte[] packet = GetWolPacket(macAddress.GetAddressBytes());
            SendPacket(target, packet);
        }
Esempio n. 22
0
        /// <summary>Sends a Wake On LAN signal (magic packet) to a client.</summary>
        /// <param name="target">Destination <see cref="IPEndPoint"/>.</param>
        /// <param name="macAddress">The MAC address of the designated client.</param>
        /// <param name="password">The SecureOn password of the client.</param>
        /// <exception cref="ArgumentNullException"><paramref name="macAddress"/> is null.</exception>
        /// <exception cref="SocketException">An error occurred when accessing the socket. See Remarks section of <see cref="UdpClient.Send(byte[], int, IPEndPoint)"/> for more information.</exception>
        public static void Send(IPEndPoint target, PhysicalAddress macAddress, SecureOnPassword password)
        {
            if (macAddress == null)
                throw new ArgumentNullException(nameof(macAddress));

            byte[] passwordBuffer = password?.GetPasswordBytes();
            byte[] packet = GetWolPacket(macAddress.GetAddressBytes(), passwordBuffer);
            SendPacket(target, packet);
        }
Esempio n. 23
0
        public IInstance Create(string name, string remarks, PhysicalAddress macAddress, IEnumerable<Command.Response.Device> roster)
        {
            Instance instance = new Instance(macAddress, name, remarks);

            instance.Observables = roster.SelectMany(device => CreateObservable(instance, device));
            instance.Actionables = roster.SelectMany(device => CreateActionable(instance, device));

            return instance;
        }
Esempio n. 24
0
        public Sockaddr(IntPtr sockaddrPtr)
        {
            // A sockaddr struct. We use this to determine the address family
            PcapUnmanagedStructures.sockaddr saddr;

            // Marshal memory pointer into a struct
            saddr = (PcapUnmanagedStructures.sockaddr)Marshal.PtrToStructure(sockaddrPtr,
                                                     typeof(PcapUnmanagedStructures.sockaddr));

            // record the sa_family for informational purposes
            _sa_family = saddr.sa_family;

            byte[] addressBytes;
            if(saddr.sa_family == Pcap.AF_INET)
            {
                type = Type.AF_INET_AF_INET6;
                PcapUnmanagedStructures.sockaddr_in saddr_in =
                    (PcapUnmanagedStructures.sockaddr_in)Marshal.PtrToStructure(sockaddrPtr,
                                                                                typeof(PcapUnmanagedStructures.sockaddr_in));
                ipAddress = new System.Net.IPAddress(saddr_in.sin_addr.s_addr);
            } else if(saddr.sa_family == Pcap.AF_INET6)
            {
                type = Type.AF_INET_AF_INET6;
                addressBytes = new byte[16];
                PcapUnmanagedStructures.sockaddr_in6 sin6 =
                    (PcapUnmanagedStructures.sockaddr_in6)Marshal.PtrToStructure(sockaddrPtr,
                                                         typeof(PcapUnmanagedStructures.sockaddr_in6));
                Array.Copy(sin6.sin6_addr, addressBytes, addressBytes.Length);
                ipAddress = new System.Net.IPAddress(addressBytes);
            } else if(saddr.sa_family == Pcap.AF_PACKET)
            {
                type = Type.HARDWARE;

                PcapUnmanagedStructures.sockaddr_ll saddr_ll =
                    (PcapUnmanagedStructures.sockaddr_ll)Marshal.PtrToStructure(sockaddrPtr,
                                                      typeof(PcapUnmanagedStructures.sockaddr_ll));

                byte[] hardwareAddressBytes = new byte[saddr_ll.sll_halen];
                for(int x = 0; x < saddr_ll.sll_halen; x++)
                {
                    hardwareAddressBytes[x] = saddr_ll.sll_addr[x];
                }
                hardwareAddress = new PhysicalAddress(hardwareAddressBytes); // copy into the PhysicalAddress class
            } else
            {
                type = Type.UNKNOWN;

                // place the sockaddr.sa_data into the hardware address just in case
                // someone wants access to the bytes
                byte[] hardwareAddressBytes = new byte[saddr.sa_data.Length];
                for(int x = 0; x < saddr.sa_data.Length; x++)
                {
                    hardwareAddressBytes[x] = saddr.sa_data[x];
                }
                hardwareAddress = new PhysicalAddress(hardwareAddressBytes);
            }
        }
 internal NetworkDictionaryItem( IPAddress ipAddress, PingReply pingReply, PhysicalAddress macAddress, IPHostEntry hostEntry, IOS os )
 {
     _ipAddress = ipAddress;
     _pingReply = pingReply;
     _macAddress = macAddress;
     _hostEntry = hostEntry;
     _os = os;
     _ports = new ConcurrentDictionary<ushort,ushort>();
 }
Esempio n. 26
0
		/// <summary>
		/// Creates a string from a Physical address in the format "xx:xx:xx:xx:xx:xx"
		/// </summary>
		/// <param name="address">
		/// A <see cref="PhysicalAddress"/>
		/// </param>
		/// <returns>
		/// A <see cref="System.String"/>
		/// </returns>
		public static string PrintMACAddress(PhysicalAddress address) {
			byte[] bytes = address.GetAddressBytes();
			string output = "";

			for (int i = 0; i < bytes.Length; i++) {
				output += bytes[i].ToString("x").PadLeft(2, '0') + ":";
			}
			return output.TrimEnd(':');
		}
Esempio n. 27
0
        public static EthernetPacket CreateEthernetPacket(PhysicalAddress sourceAddress,
            PhysicalAddress destinationAddress, Packet payloapPacket)
        {
            var result = new EthernetPacket(sourceAddress, destinationAddress, EthernetPacketType.IpV4)
            {
                PayloadPacket = payloapPacket
            };

            return result;
        }
Esempio n. 28
0
 public Values(IPEndPoint localCommandEndpoint, IPEndPoint localPacketEndpoint, string owlCommandKey, PhysicalAddress owlMacAddress, IPEndPoint owlCommandEndpoint, TimeSpan owlCommandResponseTimeout, bool autoConfigurePacketPort)
 {
     LocalCommandEndpoint = localCommandEndpoint;
     LocalPacketEndpoint = localPacketEndpoint;
     OwlCommandKey = owlCommandKey;
     OwlMacAddress = owlMacAddress;
     OwlCommandEndpoint = owlCommandEndpoint;
     OwlCommandResponseTimeout = owlCommandResponseTimeout;
     AutoConfigurePacketPort = autoConfigurePacketPort;
 }
Esempio n. 29
0
 /// <summary>
 /// Assigns the default MAC address of 00-00-00-00-00-00 to all address fields.
 /// </summary>
 protected void AssignDefaultAddresses ()
 {
     PhysicalAddress zeroAddress = PhysicalAddress.Parse ("000000000000");
     
     SourceAddress = zeroAddress;
     DestinationAddress = zeroAddress;
     TransmitterAddress = zeroAddress;
     ReceiverAddress = zeroAddress;
     BssId = zeroAddress;
 }
Esempio n. 30
0
        public static String FormatMacAddress(PhysicalAddress macAddress)
        {
            String str = String.Empty;

            if (macAddress != null) {
                str = BitConverter.ToString (macAddress.GetAddressBytes ()).Replace ('-', ':');
            }

            return str;
        }
Esempio n. 31
0
 public EthernetPacket(PhysicalAddress SourceHwAddress, PhysicalAddress DestinationHwAddress, EthernetPacketType ethernetPacketType)
     : base(new PosixTimeval())
 {
     int offset = 0;
     int headerLength = EthernetFields.HeaderLength;
     byte[] bytes = new byte[headerLength];
     base.header = new ByteArraySegment(bytes, offset, headerLength);
     this.SourceHwAddress = SourceHwAddress;
     this.DestinationHwAddress = DestinationHwAddress;
     this.Type = ethernetPacketType;
 }
Esempio n. 32
0
        private static string formatMac(System.Net.NetworkInformation.PhysicalAddress resolvedMacAddress)
        {
            string          m     = resolvedMacAddress.ToString();
            MatchCollection split = Regex.Matches(m, @"\w{2}");
            string          mac   = "";

            foreach (Match item in split)
            {
                mac += item.Value + ":";
            }

            return(mac.Remove(mac.Length - 1));
        }
Esempio n. 33
0
        private string Show_Mac_Address()
        {
            string MacAddress = "";

            // 현재 연결된 네트워크 장비의 정보를 들고 옴
            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();

            foreach (NetworkInterface adapter in adapters)
            {
                System.Net.NetworkInformation.PhysicalAddress pa = adapter.GetPhysicalAddress();

                if (pa != null && !pa.ToString().Equals(""))
                {
                    MacAddress = pa.ToString(); // 맥 어드레스 출력 해 줌
                    break;
                }
            }
            return(MacAddress);
        }
Esempio n. 34
0
        public Form1()
        {
            InitializeComponent();



            //========== IPv4 (Internal IP) ==========
            string      localIP = "Not available, please check your network seetings!";
            IPHostEntry host    = Dns.GetHostEntry(Dns.GetHostName());

            foreach (IPAddress ip in host.AddressList)
            {
                if (ip.AddressFamily == AddressFamily.InterNetwork)
                {
                    localIP            = ip.ToString();
                    this.textBox1.Text = ip.ToString();
                }
            }
            //========== IPv4 (Internal IP) ==========


            //========== External IP ==========
            string externalip = new WebClient().DownloadString("http://ipinfo.io/ip").Trim(); //http://icanhazip.com

            if (String.IsNullOrWhiteSpace(externalip))
            {
                externalip = null;//null경우 Get Internal IP를 가져오게 한다.
            }
            this.textBox2.Text = externalip;
            //return externalip;
            //========== External IP ==========


            //========== MAC ===========
            string MacAddress = "";

            NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces();
            foreach (NetworkInterface adapter in adapters)
            {
                System.Net.NetworkInformation.PhysicalAddress pa = adapter.GetPhysicalAddress();
                if (pa != null && !pa.ToString().Equals(""))
                {
                    MacAddress = pa.ToString();
                    break;
                }
            }
            //return MacAddress;
            this.textBox3.Text = MacAddress;
            //========== MAC ===========



            //========== User name ==========
            var input = WindowsIdentity.GetCurrent().Name;

            string[] tab    = input.Split('\\');
            var      result = tab[1];          //var result = tab[1] + "@" + tab[0];

            this.textBox4.Text = result;
            //========== User name ==========



            //========== Host name ==========
            String hostName = Dns.GetHostName();

            Console.WriteLine("Computer name :" + hostName);
            this.textBox5.Text = hostName;
            //========== Host name ==========
        }