diff --git a/Nighthawk/Main.cs b/Nighthawk/Main.cs index 0a2e0d3..4aea6ee 100644 --- a/Nighthawk/Main.cs +++ b/Nighthawk/Main.cs @@ -106,8 +106,8 @@ public List GetInterfaces() if (addr.Addr.ipAddress.AddressFamily == AddressFamily.InterNetwork) { address = addr.Addr.ipAddress.ToString(); - subnet = addr.Netmask.ipAddress.ToString(); - broadcast = addr.Broadaddr.ipAddress.ToString(); + subnet = (addr.Netmask.ipAddress != null)? addr.Netmask.ipAddress.ToString() : "0.0.0.0"; + broadcast = addr.Broadaddr.ipAddress != null ? addr.Broadaddr.ipAddress.ToString() : "0.0.0.0"; } // get IPv6 addresses @@ -144,7 +144,19 @@ public List GetInterfaces() } // parse interface ID from WinPcap device "Name" - var id = Regex.Split(device.Name, "NPF_")[1]; + string id; + try + { + id = Regex.Split(device.Name, "NPF_")[1]; + } + catch + { + //System.Uri uri = new System.Uri(device.Name); + //id = uri.Host; + // Copying and pasting from stackOverflow, o`rally.. ^_^ https://stackoverflow.com/questions/2245442/c-sharp-split-a-string-by-another-string + id = device.Name.Split(new string[] { "//" }, StringSplitOptions.None)[1]; + ///id = String.Split(device.Name, "//")[1]; + } // get and set mac address, gateway and windows name (DeviceInfo) foreach (var iface in NetworkInterface.GetAllNetworkInterfaces()) diff --git a/Nighthawk/MainWindow.xaml.cs b/Nighthawk/MainWindow.xaml.cs index eee928a..1962f22 100644 --- a/Nighthawk/MainWindow.xaml.cs +++ b/Nighthawk/MainWindow.xaml.cs @@ -232,7 +232,8 @@ private void BScanNetwork_Click(object sender, RoutedEventArgs e) Nighthawk.StartDevice(CInterface.SelectedIndex); } - TargetList.Clear(); + //Sometimes there's losses in the scan, multiple scans can increase number of detected hosts + //TargetList.Clear(); // reset lists and clear filters LArpTargets1List.ItemsSource = TargetList; diff --git a/Nighthawk/Nighthawk.csproj b/Nighthawk/Nighthawk.csproj index ba00ef7..84b3eb6 100644 --- a/Nighthawk/Nighthawk.csproj +++ b/Nighthawk/Nighthawk.csproj @@ -79,8 +79,10 @@ + + diff --git a/Nighthawk/Scanner.cs b/Nighthawk/Scanner.cs index 7bf5712..3086941 100644 --- a/Nighthawk/Scanner.cs +++ b/Nighthawk/Scanner.cs @@ -11,6 +11,7 @@ using PacketDotNet; using PacketDotNet.Utils; using SharpPcap.WinPcap; +using System.Windows.Forms; /** Nighthawk - ARP/ND spoofing, simple SSL stripping and password sniffing for Windows @@ -144,35 +145,86 @@ private EthernetPacket GenerateIpv6Ping() return ethernetPacket; } - + private static DialogResult ShowInputDialog(ref string input) + { + System.Drawing.Size size = new System.Drawing.Size(200, 70); + Form inputBox = new Form(); + + inputBox.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + inputBox.ClientSize = size; + inputBox.Text = "Name"; + + System.Windows.Forms.TextBox textBox = new TextBox(); + textBox.Size = new System.Drawing.Size(size.Width - 10, 23); + textBox.Location = new System.Drawing.Point(5, 5); + textBox.Text = input; + inputBox.Controls.Add(textBox); + + Button okButton = new Button(); + okButton.DialogResult = System.Windows.Forms.DialogResult.OK; + okButton.Name = "okButton"; + okButton.Size = new System.Drawing.Size(75, 23); + okButton.Text = "&OK"; + okButton.Location = new System.Drawing.Point(size.Width - 80 - 80, 39); + inputBox.Controls.Add(okButton); + + Button cancelButton = new Button(); + cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; + cancelButton.Name = "cancelButton"; + cancelButton.Size = new System.Drawing.Size(75, 23); + cancelButton.Text = "&Cancel"; + cancelButton.Location = new System.Drawing.Point(size.Width - 80, 39); + inputBox.Controls.Add(cancelButton); + + inputBox.AcceptButton = okButton; + inputBox.CancelButton = cancelButton; + + DialogResult result = inputBox.ShowDialog(); + input = textBox.Text; + return result; + } // worker function for sending ARP requests private void WorkerSender() { // get start/end IP + if(deviceInfo.Mask=="0.0.0.0") + { + deviceInfo.Mask = "255.255.255.0"; + ShowInputDialog(ref deviceInfo.Mask); + } long[] range = Network.MaskToStartEnd(deviceInfo.IP, deviceInfo.Mask); long startIP = range[0]; - long endIP = range[1]; + long tot_endIP = range[1]; long currentIP = startIP; + int chunkSize = 16; - var possibilities = (int)endIP - (int)startIP; + while (currentIP <= tot_endIP) + { + var possibilities = Math.Min((int)tot_endIP - (int)currentIP, chunkSize); + var endIP = currentIP + possibilities; + var sendQueue = new SendQueue(possibilities * 80); - var sendQueue = new SendQueue(possibilities * 80); - var deviceIP = IPAddress.Parse(deviceInfo.IP); + // There are still losses in arp, try to send packet in chunks - // create ARP requests for all the hosts in our subnet); - while (currentIP <= endIP) - { - sendQueue.Add(GenerateARPRequest(Network.LongToIP(currentIP), deviceIP).Bytes); + var deviceIP = IPAddress.Parse(deviceInfo.IP); - currentIP++; - } + // create ARP requests for all the hosts in our subnet); + while (currentIP <= endIP) + { + sendQueue.Add(GenerateARPRequest(Network.LongToIP(currentIP), deviceIP).Bytes); + + currentIP++; + } - // send our queue - sendQueue.Transmit(device, SendQueueTransmitModes.Normal); + // send our queue + //sendQueue.Transmit(device, SendQueueTransmitModes.Normal); + // There are losses in ARP part, not sure why, try different timing for better accuracy + sendQueue.Transmit(device, SendQueueTransmitModes.Synchronized); + Thread.Sleep(1000); + } Thread.Sleep(3000); - // stop other threads and stop scanning Started = false;