Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 15 additions & 3 deletions Nighthawk/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ public List<string> 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
Expand Down Expand Up @@ -144,7 +144,19 @@ public List<string> 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())
Expand Down
3 changes: 2 additions & 1 deletion Nighthawk/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions Nighthawk/Nighthawk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,10 @@
</Reference>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.ServiceModel.Discovery" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Core" />
Expand Down
80 changes: 66 additions & 14 deletions Nighthawk/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down