Saturday, April 9, 2016

C# 7 Features Previewed

Over the last year we've shown you various features that were being considered for C# 7. With the preview of Visual Studio 15, Microsoft has decided to demonstrate the features to make it into the final release of C# 7.
Tuple Value Types
.NET has a tuple type, but in the context of C# there are a lot of problems. Being a reference type, you probably want to avoid using it in performance sensitive code as you have to pay for GC costs. And as they are immutable, while making it safer for sharing across threads, making any changes requires allocating a new object.
C# 7 will address this by offering a tuple as a value type. This will be a mutable type, making it more efficient when performance is essential. And as a value type, it makes a copy on assignment so there is little risk of threading issues.
To create a tuple, you can use this syntax:
var result = (5, 20);
Optionally, you can name the values. This isn't necessary, it just makes the code more readable.
var result = (count: 5, sum: 20);
You may be thinking, "great, but I could have written that myself". But the next bit of news is where this really matters.
Multi-value Returns
Returning two values from one function has always been a pain in C-style languages. You have to either wrap the results in some sort of structure or use output parameters. Like many functional languages, C# 7 will do the first option for you:
(int, int) Tally (IEnumerable<int> list)
Here we see the basic problem with using generic tuples: there is no way to know what each field is for. So C# is offering a compiler trick to name the results:
(int Count, int Sum) Tally (IEnumerable<int> list)
We'd like to stress that C# isn't generating a new anonymous type. You are still getting back a tuple, but the compiler is pretending its properties are Count and Sum instead of Item1 and Item2. Thus these lines of code are equivalent:
var result = Tally(list);
Console.WriteLine(result.Item1);
Console.WriteLine(result.Count);
Note that we do not yet have a syntax for multi-assignment. Presumably when it happens, it will look something like this:
(count, sum) = Tally(list);
Beyond simple utility functions such as this, multi-value returns will be useful for writing asynchronous code, as async functions aren't allowed to use out parameters.
Pattern Matching: Enhanced Switch Blocks
One of the long standing complaints of VB and functional programmers alike is that C#'s switch statement is extremely limited. VB developers want ranges, while those who used to F# or Haskell want decomposition-style pattern matching. C# 7 intends to offer both.
When pattern matching on types, you can create variables to hold the result of the cast. For example, when using a switch on a System.Object you could write:
case int x:
If the object is an integer, the variable x will be populated. Otherwise it will check the next case block in a top to bottom fashion. If you want to be more specific, you can use range checks:
case int x when x > 0:
case int y:
In this example, if the object is a positive integer the x block will be executed. If the object is zero or a negative integer, the y block will be executed.
If you want to check for null, simply use this syntax:
case null;
Pattern Matching: Decomposition
So far we've just seen an incremental improvement over what is available in VB. The real power of pattern matching comes from decomposition, where you can tear apart an object. Consider this syntax:
if (person is Professor {Subject is var s, FirstName is "Scott"})
This does two things:
  1. It creates a local variable named s with the value of((Professor)person).Subject.
  2. It performs the equality check ((Professor)person).FirstName == "Scott".
Translated into C# 6 code:
var temp = person as Professor;
if (temp != null && temp.FirstName == "Scott")
{
    
var s = temp.Subject
Presumably we'll be able to combine enhanced switch blocks in the final release.
Ref Returns
Passing large structures by reference can be significantly faster than passing them by value, as the latter requires copying the whole structure. Likewise, returning a large structure by reference can be faster.
In languages such as C, you return a structure by reference using a pointer. This brings in the usual problems with pointers such as pointing to a piece of memory after it has been recycled for another purpose.
C# avoids this problem by using a reference, which is essentially a pointer with rules. The most important rule is that you can't return a reference to a local variable. If you tried, that variable would be on a portion of the stack that is no longer valid as soon as the function returns.
In the demonstration, they instead returned a reference to a structure inside an array. Since it is effectively a pointer to an element in the array, the array itself can be modified. For example:
var x = ref FirstElement(myArray)
x = 5; //MyArray[0] now equals 5
The use case for this is highly performance sensitive code. You wouldn't use it in most applications.
Binary Literals
A minor feature is the addition of binary literals. The syntax is simple prefix, for example 5 would be "0b0101". The main use cases for this would be setting up flag based enumerations and creating bitmasks for working with C-style interop.
Local Functions
Local functions are functions that you define inside another function. At first glance, local functions look like a slightly nicer syntax for anonymous functions. But they have some advantages.
  • First, they don't require you to allocate a delegate to hold them. Not only does this reduce memory pressure, it also allows the function to be in-lined by the compiler.
  • Secondly, they don't require you to allocate an object when creating a closure. Instead it just has access to the local variables. Again, this improves performance by reducing GC pressure.
Presumably the second rule means that you can't create a delegate that points to a local function. Still, this offers organizational benefits over creating separate private functions to which you pass the current function's state as explicit parameters.
Partial Class Enhancements
The final feature demonstrated was a new way to handle partial classes. In the past, partial classes were based around the concept of code-generation first. The generated code would include a set of partial methods that the developer could implement as needed to refine behavior.
With the new "replace" syntax, you can go the other way. The developer writes code in a straight forward fashion first and then the code generator comes in and rewrites it. Here is a simple example of what the developer may write,
public string FirstName {get; set;}
Simple, clean, and completely wrong for a XAML style application. So here's what the code generator will produce:
private string m_FirstName;
static readonly PropertyChangedEventArgs s_FirstName_EventArgs =new PropertyChangedEventArgs("FirstName")
replace public string FirstName {
    get {
        return m_FirstName;
    }
    set {
        if (m_FirstName == value)
            return;
    m_FirstName = value;
    PropertyChanged?.Invoke(this, m_FirstName_EventArg);
}
By using the "replace" keyword, the generated code can literally replace the hand-written code with the missing functionality. In this example, we can even handle the tedious parts that developers often skip such as caching EventArgs objects.
While the canonical example is property change notifications, this technique could be used for many "Aspect Oriented Programming" scenarios such as injecting logging, security checks, parameter validation, and other tedious boilerplate code.
To see these features in action, watch the Channel 9 video titled The Future of C#.

Hydra: Password Cracking Tool (Summary, Tutorial and Resources)

What is Hydra?
Hydra, now in version 8.1 and last updated December 12th 2014, is a very well-known and respected network log on cracker which can support many different services. (Similar projects and tools include medusa and John The Ripper).
Visit our Hacker Tools Directory for more information on hacking tools – and where we list the best and most commonly used password crackers, IP Scanners, Wireless Hacking Tools and more! Each of the tools contains a video tutorial.
hydra-large
As a password/ log on cracker (hacking tool) – Hydra has been tested on the following protocols:
afpciscocisco-enablecvs
firebirdftphttp-gethttp-head
http-proxyhttps-gethttps-headhttps-form-get
https-form-posticqimapimap-ntlm
ldap2ldap3mssqlmysql
ncpnntporacle-listenerpcanywhere
pcnfspop3pop3-ntlmpostgres
rexecrloginrshsapr3
sipsmbsmbntsmtp-auth
smtp-auth-ntlmsnmpsocks5ssh2
teamspeaktelnetvmauthdvnc
How does Hydra work?
Hydra is a brute force password cracking tool. In information security (IT security), password cracking is the methodology of guessing passwords from databases that have been stored in or are in transit within a computer system or network. A common approach, and the approach used by Hydra and many other similar pentesting tools and programs is referred to as Brute Force. We could easily do a Concise Bytes on ‘Brute Force Hacking’ but since this post is all about Hydra let’s place the brute-force attack concept within this password-guessing tool.
Brute force just means that the program launches a relentless barrage of passwords at a log in to guess the password. As we know, the majority of users have weak passwords and all too often they are easily guessed. A little bit of social engineering and the chances of finding the correct password for a user are multiplied. Most people (especially those non-IT savvy, will base their ‘secret’ passwords on words and nouns that they will not easily forget. These words are commonly: loved ones, children’s names, street addresses, favorite football team, place of birth etc. All of this is easily obtained through social media so as soon as the hacker has compiled this data it can be compiled within a ‘password list’.
Brute force will take the list that the hacker built and will likely combine it with other known (easy passwords, such as ‘password1, password2’ etc) and begin the attack. Depending on the processing speed of the hackers (auditors) computer, Internet connection (and perhaps proxies) the brute force methodology will systematically go through each password until the correct one is discovered.
It is not considered as being very subtle – but hey it works!
Hydra is considered as being one of the better ones out there and it certainly worth your time as a security professional or student to give it a try.
Resources and tutorials
The majority of pentesting/ hacking tools are created and developed from a security perspective, meaning that they are designed to aid the pentester find flaws in their clients systems and take appropriate action. Hydra works by helping the auditor find weak passwords in their clients network. According to the Hydra developers they recommend that the professional do the following when using Hydra:
  • Step 1: Make your network as secure as possible.
  • Step 2: Set up a test network
  • Step 3: Set up a test server
  • Step 4: Configure services
  • Step 5: Configure the ACL
  • Step 6: Choose good passwords
  • Step 7: Use SSL
  • Step 8: Use Cryptography
  • Step 9: Use an IDS
  • Step 10: Throw Hydra against the security and try and crack the logon commands.
The below commands will install Hydra and here is our favorite video tutorial on how to use Hydra.
hydra-install
How do we defend against Hydra and brute force attacks?
There are several ways a system admin or network engineer can defend against brute force attacks. Here are a few methods. If you can think of any others, or disagree with the below, let us know in the comment below!
  • Disable or block access to accounts when a predetermined number of failed authentication attempts has been reached.
  • Consider multi-factor or double opt-in/ log in for users.
  • Consider implementing hardware-based security tokens in place of system-level passwords.
  • Enforce all employees to use generated passwords or phrases and ensure every employee uses symbols whenever possible.
  • And the most simple – remove extremely sensitive data from the network, isolate it!
In Summary
What are your thoughts? Have you used Hydra in any white/ back box pentesting and did it work or fail? Can you think of any particular uses with this program or are there alternatives that we should also share with your community?

Friday, April 8, 2016

Meet Kali Linux 2.0, a distro built to hammer your security



The newest version of Kali Linux is built so you can update its penetration testing tools with less hassle.


The latest release of the immensely popular Linux distribution designed for penetration testing, Kali Linux 2.0 launched at DefCon 23 in Las Vegas last week.
Kali is the successor to BackTrack, and is a Debian-based Linux distribution that includes hundreds of penetration-testing tools pre-installed and ready to go. Just boot it from a USB drive or live DVD and you’ll have a penetration-testing—or “hacking”—environment with all the tools you might want just waiting for you to fire them up.

More frequent updates

The biggest change is the shift to a rolling release model. Now, you can simply install Kali Linux 2.0 on a computer and the latest versions of security tools will be provided to you as normal updates. There’s no need to wait for Kali Linux 2.1 to get the newest stuff. An eventual Kali Linux 2.1 would simply be a snapshot of the current software available, which 2.0 users would already have upgraded to.
The developers also tout a new upstream version-checking system, which will notify them when the various security tools included in Kali are upgraded. This means Kali’s tools will be upgraded more frequently.
Want to stay up to date on Linux, BSD, Chrome OS, and the rest of the World Beyond Windows? Bookmark the World Beyond Windows column page or follow our RSS feed.

A new desktop environment

Kali Linux 2.0 includes a variety of software upgrades. It’s now based on Debian 8 “Jessie”, and that brings the Linux 4.0 kernel along with improved hardware support and, importantly, better wireless driver coverage.
kali linux 2 menu
The main system image has moved to GNOME 3, which is the developer’s favorite desktop environment. But Kali also officially supports KDE, Xfce, MATE, Lxde, e17, and i3wm. The GNOME system means the main Kali system will now take up a bit more RAM—768MB minimum for a full GNOME 3 session. If this is too much for you, there’s now a “Light” version of Kali Linux you can download instead. This includes the lighter Xfce desktop environment and a smaller collection of useful security tools.
The Metasploit Community / Pro package is no longer included in Kali Linux 2.0, but must be downloaded separately from Rapid7.
Kali Linux also provides upgraded ARM images so you can run it on the Raspberry Piand various Chromebooks. Nethunter images for Android devices have been upgraded, and there are also official VirtualBox and VMware images you can download.
Kali Linux 2.0 wasn’t the only security-focused Linux distribution to release a new version timed with DefCon, either. Tails 1.5 just debuted with a variety of fixes, upgrading theanonymity-focused operating system favored by Edward Snowden.

C# new instance Class - Dot Net perls

New instantiates a type. It invokes the type's constructor (with a matching argument signature). After completion, the constructor returns a new instance of the specified type. We can then use the instance.
Example. We use the new operator when instantiating instances of a class. You must combine the new operator with the type name and its constructor arguments to create a new instance of the type. You can use any constructor available.ClassConstructor
Note:The result of the new operator and the constructor invocation is an instance of the type.
Also:This program shows the default constructor that all classes have—unless another constructor is specified.

Based on: .NET 4.5

C# program that uses new operator

using System;

class Perl
{
    public Perl()
    {
 // Public parameterless constructor.
 Console.WriteLine("New Perl()");
    }
    public Perl(int a, int b, int c)
    {
 // Public parameterful constructor.
 Console.WriteLine("New Perl(a, b, c)");
    }
}

class Program
{
    static void Main()
    {
 // Create a new instance of the Perl type.
 // ... Use the new operator.
 // ... Then reassign to another new object instance.
 Perl perl = new Perl();
 perl = new Perl(1, 2, 3);

 // Another Perl instance.
 Perl perl2 = null;
 perl2 = new Perl();

 // Instantiate the Program class.
 // ... No constructor is declared, so there is a default.
 Program program = new Program();
 Console.WriteLine(program != null);
    }
}

Output

New Perl()
New Perl(a, b, c)
New Perl()
True

This program defines two types: Perl and Program. The Perl class contains two user-defined constructors—these are invoked with the new operator. The Program class introduces the Main method and an implicit default constructor.
Tip:To call the constructors in the Perl type, specify the new operator, and then use the Perl() type with a formal parameter list.
Parameter List
Next, the program instantiates the Program class. This may be confusing. The Program type declaration does not have a constructor in the source text. The C# compiler actually inserts one for you, called the implicit default constructor.
Note:This constructor does nothing except set the memory to its default values. The default constructor is public.
Default Constructor
Usage. New has several usages in the C# language. The most common usage is for instantiating new objects. The new keyword can be used as a modifier to indicate that a method is supposed to hide a method from a derived type.New Modifier
Also:When declaring generic classes, you can specify that a type must be a reference type with the new() constraint.
Generic Class
Memory allocation. The new operator always results in an allocation. When you use the new operator, the memory is allocated and initialized to its default value. Then the constructor logic is executed and it can change the values from their defaults.
Reference types, such as classes, are always allocated on the managed heap. And types that inherit from System.ValueType, which are considered structs, are typically allocated on the stack memory.ValueTypeStruct
Summary. New is an operator in the C# language. It instantiates types in a unified way. We saw a user-defined and overloaded constructor, and the default constructor for classes (which has no parameters).

How I Learned A Vital Borland C++ Coding Technique I Couldn't Learn Alone

INTRODUCTION

Back in the late 1990s I was having trouble with a Borland Turbo C++ version 3.1 
programming issue to make a Windows form auto-calculate after tabbing out of a numerical text box. In the early 1990s when I coded MS-DOS based procedural C application development, I could call Borland's technical support line and they would help me out free of charge. By the time I had this particular problem though, everything had changed for the worse. They had a 900 number I had to call for technical support. It was very expensive - $5USD per minute. Ouch! Their technical support people wouldn't even speak to me until I gave them my credit card number and they had authorized it. I sent them one fax about my problem and another and then another after that, because they kept losing them. Not only did they not solve my problem, but they also had the nerve to charge my credit card $92USD just for the time they spent running around trying to find my faxes. I was absolutely livid - this was the high watermark of aggravation for me. 

THE ISSUE I HAD

The custom software work I did typically involved invoicing or order entry. The Windows form had to automatically recalculate the extended prices as well as totals. I knew how to do this with my old MS-DOS based programs. However, I was having a real tough time making this work in the object oriented (OOP) Windows environment. I knew the calculation had to be fired after the operator tabbed out of a numerical text box on the Windows form. I went online spending many hours researching this issue to no avail.

Nearing the end of my rope, I found an online newsgroup for Borland C++ programmers. I saw a post from a coder who was inquiring about a problem he had that was different from mine. I thought there might be a possibility that he could help me out with my problem since he was using Borland C++ version 4.5 software - a newer version than mine. He kindly sent me the code that showed how to fire an event in a Borland C++ version 4.5 Windows form after tabbing out of a text box. I studied it and was able to adapt it for my older Borland Turbo C++ version 3.1 compiler - thank goodness!

THE BORLAND C++ CODE THAT SOLVED IT

I honestly don't know what I would have done next had it not been for his help. It was imperative that I knew how to implement this programming technique. I knew from my days in the MS-DOS based programming world that customers would expect an invoice screen to automatically recalculate after numerical additions and/or changes had been made. Here are some code snippets that facilitate this operation from an actual Borland C++ 5.02 program I made:



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102

// declare the class.
//
// class TCbookDlg
// ~~~~~ ~~~~~~~~~~~~

 class TCbookDlg : public TDialog {

  public:

   TCbookDlg(TWindow* parent, TResId resId, TCbookStruct& transfer);
   TEdit *Edit1,*Edit2,*Edit3,*Edit4,*Edit5,*Edit6,*Edit7,*Edit8;
   TEdit *Edit9,*Edit10,*Edit11,*Edit12,*Edit13,*Edit14,*Edit15;

   // WMTab is the event to process specific math calculations
   // upon receiving the WM_GETDLGCODE message.
   LRESULT WMTab(WPARAM, LPARAM);  
   // WMChar is the event to process specific programming upon
   // receiving inputed keystrokes in the text box.
   LRESULT WMChar(WPARAM, LPARAM);     

  protected:

   // declare member functions of the TCbookDlg class.
   void  CmOk();
   void  Choose();
   void  Delete();
   void  Mchk();
   void  PrnReg();
   void  BalForw();
   void  PrnEnv();
   void  New();
   void  SVendor();
   void  SPaymentDate();
   void  SCheckNo();
   void  Reset();

  private:

   // declare objects of the TCbookDlg class.
   TPrinter* Printer;
   TListBox* ListBox;
   TComboBox* ComboBox;
   TComboBox* ComboBox2;
   TComboBox* ComboBox3;
   TComboBox* ComboBox4;
   TComboBox* ComboBox5;
   TComboBox* ComboBoxV;
   TComboBox* ComboBox6;
   TButtonGadget* G1;
   TButtonGadget* G2;
   TButtonGadgetEnabler* Ge1;
   TButtonGadgetEnabler* Ge2;
   void  SetupWindow();
   // declare the character arrays.
   char  Pdate[MAXDAT];
   char  Pnumber[MAXINVNO];
   char  Paid_amount[MAXSELL];
   char  Pdescr[MAXNOTE2];
   char  Paid_amount_discount[MAXSELL];
   char  Pnetdebit[MAXSELL];
   char  Pcheck[MAXSELL];
   char  Vendor[MAXCOMPANY2];
   char  ExpCode[MAXPAIDDISCOUNTSUMODE];
   char  TranType[MAXSELL];
   char  TranPaid[MAXANS];
   char  Void[MAXANS];
   char  Pcredit[MAXSELL];
   char  Sdt[MAXDAT];
   char  Edt[MAXDAT];
   char  BalUpdated_amount[MAXSELL];
   char  CutOffDate[MAXDAT];
   char  CheckMemo[MAXNOTE];
   char  Paiddate[MAXDAT];
   char  TranCleared[MAXANS];
   char  Rcount[MAXPASS];

  DECLARE_RESPONSE_TABLE(TCbookDlg);

 };

 // connect the TCbookDlg class member functions to their corresponding
 // identifiers as set in the resource file (not included here).
 DEFINE_RESPONSE_TABLE1(TCbookDlg, TDialog)
  EV_COMMAND(IDOK, CmOk),
  EV_COMMAND(IDC_PDELETE, Delete),
  EV_COMMAND(IDC_MCHECK, Mchk),
  EV_COMMAND(IDC_PRNREG, PrnReg),
  EV_COMMAND(IDC_BALFORW, BalForw),
  EV_COMMAND(IDC_PRNENV, PrnEnv),
  EV_COMMAND(IDC_CNEW, New),
  EV_COMMAND(IDC_RESET, Reset),
  EV_COMMAND(IDC_SVENDOR, SVendor),
  EV_COMMAND(IDC_SDATE, SPaymentDate),
  EV_COMMAND(IDC_SCHECKNO, SCheckNo),
  EV_LBN_SELCHANGE(IDC_LISTBOX, Choose),
  // WM_GETDLGCODE fires this event (WMTab) in the class TCbookDlg.
  EV_MESSAGE(WM_GETDLGCODE, WMTab),  
  // WM_CHAR fires this event (WMChar) in the class TCbookDlg.
  EV_MESSAGE(WM_CHAR, WMChar),       
 END_RESPONSE_TABLE;




This programming runs when the operator inputs keystrokes (numbers) into the text box. It screens out non-numeric characters or characters that aren't periods and sets the text box to a numerical zero making the operator start over with valid input.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26

LRESULT
TEdAmt::WMChar(WPARAM cmd, LPARAM cmd2)
{
int  a;

DefaultProcessing();

for(a=0; a<MAXSELL; a++) Amount[a]=32;
GetSubText(Amount, 0, MAXSELL-1);

flag_variable = 1;

for(a=0; a<MAXSELL-1; a++) {
 if( ( Amount[a]<46 || Amount[a]>57 ) && Amount[a]>32 ) {
 Amount[a]=48;
 Amount[MAXSELL-1]=0;
 SetText(Amount);
 SetSelection(0, MAXSELL-1);
 }
}

return TRUE;

}




This code runs when the operator tabs out of a numerical based text box that accepts a dollar amount




LRESULT
TEdAmt::WMTab(WPARAM cmd, LPARAM cmd2)
{
// declare local variables used in the formatting and math processing.
int   r,f,z,a,y;

if ( cmd == VK_TAB && flag_variable == 1 ) {

y=0;
if ( Amount[0]<=57 && Amount[1]<=57 && Amount[2]<=57 && Amount[3]<=57 && Amount[4]<=57 && Amount[5]<=57 && Amount[6]<=57 && Amount[7]<=57 && Amount[8]<=57 && Amount[9]<=57 ) y=1;

 if ( y == 1 ) {

  r=0;
  do {
   if(Amount[9]<46 || Amount[9]>57) {
   for(f=9; f>0; f--) Amount[f]=Amount[f-1];
   Amount[0]=32;
   }
  r++;
  } while(r<10);

  r=0;
  if ( Amount[7]!=46 && Amount[8]!=46 && Amount[9]!=46 ) {
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=46;
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=48;
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=48;
   r=1;
  }

  if ( Amount[9]==46 && r==0 ) {
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=48;
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=48;
   r=1;
  }

  if ( Amount[8]==46 && r==0 ) {
   for(f=0; f<9; f++) Amount[f]=Amount[f+1];
   Amount[9]=48;
  }

  z=0;
  if ( ( Amount[0]<48 || Amount[0]>57 ) && Amount[0]>32 ) z=1;
  if ( ( Amount[1]<48 || Amount[1]>57 ) && Amount[1]>32 ) z=1;
  if ( ( Amount[2]<48 || Amount[2]>57 ) && Amount[2]>32 ) z=1;
  if ( ( Amount[3]<48 || Amount[3]>57 ) && Amount[3]>32 ) z=1;
  if ( ( Amount[4]<48 || Amount[4]>57 ) && Amount[4]>32 ) z=1;
  if ( ( Amount[5]<48 || Amount[5]>57 ) && Amount[5]>32 ) z=1;
  if ( ( Amount[6]<48 || Amount[6]>57 ) && Amount[6]>32 ) z=1;
  if ( Amount[7]!=46 ) z=1;
  if ( ( Amount[8]<48 || Amount[8]>57 ) && Amount[8]>32 ) z=1;
  if ( ( Amount[9]<48 || Amount[9]>57 ) && Amount[9]>32 ) z=1;

  if(z==0) {
  r=0;
   do {
   r++;
   } while(Amount[r]==32 && r<10);
  if(r<10) Amount[r-1]='$';
  }

  if ( z>0 ) {
  for(a=0; a<MAXSELL; a++) Amount[a]=32;
  Amount[6]=48;
  Amount[7]=46;
  Amount[8]=48;
  Amount[9]=48;
  }

Amount[MAXSELL-1]=0;
SetText(Amount);

flag_variable = 0;

Parent->SendMessage(WM_GETDLGCODE, 0, 0);

 }

}

DefaultProcessing();

//return TRUE;

}






This is fired after the WM_GETDLGCODE message reaches the parent window. The math will be performed and the text box will be updated with the calculated result.



LRESULT
TCbookDlg::WMTab(WPARAM cmd, LPARAM cmd2)
{
  int        a,r;
  long int   paidsum,paiddiscountsum,convert_to_integer[10];
  char       Updated_amount[MAXSELL];
  ldiv_t     n;

  streambuf  *inn = cin.rdbuf();

  ifpstream  ivfile;

  for(a=0; a<MAXSELL; a++) Paid_amount[a]=32;
  for(a=0; a<MAXSELL; a++) Paid_amount_discount[a]=32;

  GetDlgItemText(IDC_PAID_AMOUNT, Paid_amount, MAXSELL);
  GetDlgItemText(IDC_PAID_AMOUNT_DISCOUNT, Paid_amount_discount, MAXSELL);

  for(a=0; a<MAXSELL-1; a++) {
  convert_to_integer[a]=0;
  if(Paid_amount[a]==48) convert_to_integer[a]=0;
  if(Paid_amount[a]==49) convert_to_integer[a]=1;
  if(Paid_amount[a]==50) convert_to_integer[a]=2;
  if(Paid_amount[a]==51) convert_to_integer[a]=3;
  if(Paid_amount[a]==52) convert_to_integer[a]=4;
  if(Paid_amount[a]==53) convert_to_integer[a]=5;
  if(Paid_amount[a]==54) convert_to_integer[a]=6;
  if(Paid_amount[a]==55) convert_to_integer[a]=7;
  if(Paid_amount[a]==56) convert_to_integer[a]=8;
  if(Paid_amount[a]==57) convert_to_integer[a]=9;
  }
  paidsum = convert_to_integer[0]*100000000 + convert_to_integer[1]*10000000 + convert_to_integer[2]*1000000 + convert_to_integer[3]*100000 + convert_to_integer[4]*10000 + convert_to_integer[5]*1000 + convert_to_integer[6]*100 + convert_to_integer[8]*10 + convert_to_integer[9]*1;

   for(a=0; a<MAXSELL-1; a++) {
   convert_to_integer[a]=0;
   if(Paid_amount_discount[a]==48) convert_to_integer[a]=0;
   if(Paid_amount_discount[a]==49) convert_to_integer[a]=1;
   if(Paid_amount_discount[a]==50) convert_to_integer[a]=2;
   if(Paid_amount_discount[a]==51) convert_to_integer[a]=3;
   if(Paid_amount_discount[a]==52) convert_to_integer[a]=4;
   if(Paid_amount_discount[a]==53) convert_to_integer[a]=5;
   if(Paid_amount_discount[a]==54) convert_to_integer[a]=6;
   if(Paid_amount_discount[a]==55) convert_to_integer[a]=7;
   if(Paid_amount_discount[a]==56) convert_to_integer[a]=8;
   if(Paid_amount_discount[a]==57) convert_to_integer[a]=9;
   }
   paiddiscountsum = convert_to_integer[0]*100000000 + convert_to_integer[1]*10000000 +  convert_to_integer[2]*1000000 + convert_to_integer[3]*100000 + convert_to_integer[4]*10000 +  convert_to_integer[5]*1000 + convert_to_integer[6]*100 + convert_to_integer[8]*10 +  convert_to_integer[9]*1;

   paidsum = paidsum - paiddiscountsum;

    for(a=0; a<MAXSELL-1; a++) Updated_amount[a]=32;
    Updated_amount[9]=48;
    Updated_amount[8]=48;
    Updated_amount[7]=46;
    Updated_amount[6]=48;
    r=9;
    do {
    n=ldiv(paidsum,10L);
    paidsum=n.quot;
    if(n.rem==0) Updated_amount[r]=48;
    if(n.rem==1) Updated_amount[r]=49;
    if(n.rem==2) Updated_amount[r]=50;
    if(n.rem==3) Updated_amount[r]=51;
    if(n.rem==4) Updated_amount[r]=52;
    if(n.rem==5) Updated_amount[r]=53;
    if(n.rem==6) Updated_amount[r]=54;
    if(n.rem==7) Updated_amount[r]=55;
    if(n.rem==8) Updated_amount[r]=56;
    if(n.rem==9) Updated_amount[r]=57;
    r--;
    if(r==7) r--;
    } while(paidsum>0);

     r=0;
     do {
     r++;
     } while(Updated_amount[r]==32 && r<MAXSELL-1);
     Updated_amount[r-1]='$';

     Updated_amount[MAXSELL-1]=0;
     Edit6->SetText(Updated_amount);

}


CONCLUSION

Just when you think all is lost, you will find an educational resource or a kind soul online to help you out. If you can't resolve it on your own, the internet is filled with nice people who are ready to give you a helping hand. It is by far thebest available resource. What with the problem I had, the internet could not have arrived soon enough to save me from the cost prohibitive (and not always useful) world of paid technical support. Thankfully, that option has gone the way of the typewriter.

Tuesday, March 15, 2016

4th part of wifi password cracking "Connect with a WPA2 wifi adopter"

The 4th and one of the most important part is how to connect with the wifi using c#.
First you need to know what type of security the wifi adopter have , well my adopter have WPA2 security , so i am working with it. you can have your own securities.

Following are some kinds of securities:
WEP.
WPA.
WPA2(enterprise)
WPA2(Home)
ETC.

So Lets start.

First you need a new button and two new text box.
you can add them from tool box as i told you before.

After that. name the textbox1 to SSID_textbox and textbox2 to Password_textbox.

Now double click on the button and past this code there.

WlanClient client = new WlanClient();
            foreach (WlanClient.WlanInterface wlanIface in client.Interfaces)
            {
                try
                {
                    string profilename= SSID_textbox.Text;
                    string key = Password_textbox.Text;
                    string profileXml = string.Format("<?xml version=\"1.0\"?><WLANProfile xmlns=\"http://www.microsoft.com/networking/WLAN/profile/v1\"><name>{0}</name><SSIDConfig><SSID><name>{0}</name></SSID></SSIDConfig><connectionType>ESS</connectionType><connectionMode>auto</connectionMode><autoSwitch>false</autoSwitch><MSM><security><authEncryption><authentication>WPA2PSK</authentication><encryption>AES</encryption><useOneX>false</useOneX></authEncryption><sharedKey><keyType>passPhrase</keyType><protected>false</protected><keyMaterial>{1}</keyMaterial></sharedKey></security></MSM></WLANProfile>", profilename, key);
                    wlanIface.SetProfile(Wlan.WlanProfileFlags.AllUser, profileXml, true);
                    wlanIface.Connect(Wlan.WlanConnectionMode.Profile, Wlan.Dot11BssType.Any, profilename);
                }
                catch(Exception ex)
                {
                    ex.ToString();
                }
            }
           




Now run the project and enter the SSID of Name of wifi in the SSId_textbox and its key into the Password_textbox. and click the connect button. your wifi will be connected .


Thanks for reading.
Keep visiting my bolg to see more stuff and updates.
ALLAH HAFIZ