Friday, November 11, 2011

BackTrack 5: Accelerate pyrit with NVIDIA GPU processor

Pyrit is a cryptography tool that may decrypt WPA/WPA2 capture handshake in 802.11 wireless traffic (WIFI) using brute force approach.  The original Pyrit performs calculation using CPU cores.  This article introduces how to compile Pyrit to facilitate NVIDIA GPUs that may boost performance for 10x to 20x or even more depends on GPU cores and models.

Download NVIDIA driver and toolkit

  1. Download NVIDIA drivers according to your CPU architecture:
  2. Next, download the CUDA toolkit, according to your CPU architecture:

Disable Kernel Nouveau

Install NVIDIA display driver may fail if kernel Nouveau is running, the kernel should disable first:

  1. Disable Kernel Nouveau:
    root@bt:~# echo options nouveau modeset=0 | tee -a /etc/modprobe.d/nouveau-kms.conf
    root@bt:~# update-initramfs -u
    update-initramfs: Generating /boot/initrd.img-2.6.39.4
  2. Reboot machine

Install NVIDIA driver

  1. Make sure you are not in an X session (log out to console)
  2. Run Nvidia driver installer:
    root@bt:~/# ./devdriver_4.0_linux_64_270.40.run
    Verifying archive integrity... OK
    Uncompressing NVIDIA Accelerated Graphics Driver for Linux-x86_64 270.40......................................................................................................................................
  3. Follow screen instruction to complete installation

Install NVIDIA CUDA toolkit

root@bt:~/# ./cudatoolkit_4.0.17_linux_64_ubuntu10.10.run
Verifying archive integrity... All good.
Uncompressing NVIDIA CUDA..............................

Enter install path (default /usr/local/cuda, '/cuda' will be appended):

========================================

* Please make sure your PATH includes /usr/local/cuda/bin
* Please make sure your LD_LIBRARY_PATH
* for 32-bit Linux distributions includes /usr/local/cuda/lib
* for 64-bit Linux distributions includes /usr/local/cuda/lib64:/usr/local/cuda/lib
* OR
* for 32-bit Linux distributions add /usr/local/cuda/lib
* for 64-bit Linux distributions add /usr/local/cuda/lib64 and /usr/local/cuda/lib
* to /etc/ld.so.conf and run ldconfig as root

* Please read the release notes in /usr/local/cuda/doc/

* To uninstall CUDA, delete /usr/local/cuda
* Installation Complete

Prepare CUDA for Pyrit

  1. Prepare kernel sources:
    root@bt:~# prepare-kernel-sources
    [*] apt-getting linux-source...
    Reading package lists... Done
    Building dependency tree
    Reading state information... Done
    linux-source is already the newest version.
    The following packages were automatically installed and are no longer required:
    libecryptfs0 libdmraid1.0.0.rc16 libdebconfclient0 ecryptfs-utils cryptsetup
    rdate bogl-bterm libdebian-installer4 reiserfsprogs dmraid python-pyicu
    Use 'apt-get autoremove' to remove them.
    0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
    [*] extracting sources, please wait
    tar: linux-source-2.6.39.4.tar.bz2: Cannot open: No such file or directory
    tar: Error is not recoverable: exiting now
    tar: Child returned status 2
    tar: Exiting with failure status due to previous errors
    [*] doing stuff...
    cp: missing destination file operand after `/boot/'
    Try `cp --help' for more information.
    scripts/kconfig/conf --silentoldconfig Kconfig
    CHK include/linux/version.h
    CHK include/generated/utsrelease.h
    CALL scripts/checksyscalls.sh
    [*] tada!
    root@bt:~# cd /usr/src/linux
    root@bt:/usr/src/linux# cp -rf include/generated/* include/linux/
  2. Set Environment variable
    root@bt:~# vi ~/.bashrc
    PATH=$PATH:/usr/local/cuda/bin
    LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64
    export PATH
    export LD_LIBRARY_PATHroot@bt:~# source /root/.bashrc
    root@bt:~# ldconfig
  3. Check NVIDIA compiler:
    root@bt:~# which nvcc
    /usr/local/cuda/bin/nvcc
    root@bt:~# nvcc -V
    nvcc: NVIDIA (R) Cuda compiler driver
    Copyright (c) 2005-2011 NVIDIA Corporation
    Built on Thu_May_12_11:09:45_PDT_2011
    Cuda compilation tools, release 4.0, V0.2.1221

Setup pyrit

  1. Setup pyrit dependent packages:
    root@bt:~# apt-get install libssl-dev
    root@bt:~# apt-get install scapy
    root@bt:~# apt-get install python-dev
    root@bt:~# apt-get install python-sqlalchemy // optional: if using sqlite database
  2. Check out Pyrit SVN trunk:
    root@bt:~# svn checkout http://pyrit.googlecode.com/svn/trunk/ pyrit
  3. Build Pyrit:
    root@bt:~# cd pyrit/pyrit/
    root@bt:~/pyrit/pyrit# python setup.py build
    root@bt:~/pyrit/pyrit# python setup.py install
  4. Test Pyrit:
    root@bt:~/pyrit/pyrit# pyrit list_cores
    Pyrit 0.4.1-dev (svn r308) (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
    This code is distributed under the GNU General Public License v3+
    
    The following cores seem available...
    #1: 'CPU-Core (SSE2)'
    #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)'

Setup CUDA for Pyrit

  1. Build CUDA for Pyrit:
    root@bt:~/pyrit/pyrit# cd ../cpyrit_cuda/
    root@bt:~/pyrit/cpyrit_cuda# python setup.py build
    root@bt:~/pyrit/cpyrit_cuda# python setup.py install
  2. Test CUDA for Pyrit:
    root@bt:~/pyrit/cpyrit_cuda# pyrit list_cores
    Pyrit 0.4.1-dev (svn r308) (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
    This code is distributed under the GNU General Public License v3+
    
    The following cores seem available...
    #1: 'CUDA-Device #1 'GeForce 8400 GS''
    #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)'
    
    root@bt:~/pyrit/cpyrit_cuda# pyrit benchmark
    Pyrit 0.4.1-dev (svn r308) (C) 2008-2011 Lukas Lueg http://pyrit.googlecode.com
    This code is distributed under the GNU General Public License v3+
    
    Running benchmark (3240.1 PMKs/s)... \
    
    Computed 3240.14 PMKs/s total.
    #1: 'CUDA-Device #1 'GeForce 8400 GS'': 457.5 PMKs/s (RTT 3.2)
    #2: 'CPU-Core (SSE2)': 425.5 PMKs/s (RTT 3.0)
    #3: 'CPU-Core (SSE2)': 425.9 PMKs/s (RTT 3.0)
    #4: 'CPU-Core (SSE2)': 426.2 PMKs/s (RTT 3.0)
    #5: 'CPU-Core (SSE2)': 425.5 PMKs/s (RTT 2.9)
    #6: 'CPU-Core (SSE2)': 425.6 PMKs/s (RTT 3.1)
    #7: 'CPU-Core (SSE2)': 453.3 PMKs/s (RTT 3.0)
    #8: 'CPU-Core (SSE2)': 422.3 PMKs/s (RTT 3.1)
  3. The benchmark for GeForce GPU doesn’t shows much improvement on calculation as the GPU is a low end graphic card.

6 comments:

WhiskeyTangoFoxtrot said...

--==Install NVIDIA Driver==--

Note: chmod +X the .run driver before attempting to install or it won't even list the device when you try and tab out.

Note: When prompted to install 32-bit compatibility libraries choose YES.

--==Install NVIDIA CUDA Toolkit==--

Note: chmod +x the .run file once more

Note: When it asks for installation directory, just hit enter to use default.

--==Prepare CUDE for Pyrit==--

Question: Shouldn't much of this section be highlighted in yellow as we are to amend and type it to the end of .bashrc?

Note: "root@bt:~# source /root/.bashrc" Seems to be a bit jumbled with a line to be typed.

Error: After running source /root/.bashrc I get the following error message: "/dev/mapper/vg-root: Permission denited" Perhaps related to an encrypted persistent USB partition?

**Will update after attempt #2 as my BT5 installation became faulty...

WhiskeyTangoFoxtrot said...

This appears to a very well-written article for the current Back|Track v5. As I attempt this, here's some information and findings along the way...

--==Install NVIDIA Driver==--

Note: chmod +x the .run file before installation.

--==Install NVIDIA CUDA Toolkit==--

Note: chmod +x the .run file again

Note: When it asks for the installation path, just hit ENTER and it will use the default.

--==Prepare for CUDA Pyrit==--

Question: On set environment variable, is the text to be amended or added to the end of the .bashrc file?!

Note: There is meant to be a line break between "LD_LIBRARY_PATH" and "root@bt:~# source /root/.bashrc"


...To be continued...I have not had success yet. I will try again soon.

Xanthes said...

This worked great.
Thanks for making it so easy.

Anonymous said...

Thank you very much for the tutorial, it is great !!! Unfortunately, after i appended the code to the bashrc file i lost color in my shell :-( everything is in white colour. Can you tell me please how to fix that. Thnx in advance

Anonymous said...

These are great instructions, Chau Chee. However, with Backtrack 5 r2 64 bit, there is an issue when you get to 'Set up CUDA for Pyrit': the commands

python setup.py build

and

python setup.py install

will not function properly unless you install openssl-dev, and the command:
apt-get install openssl-dev fails as the package is not in the Backtrack default repository. The solution is to install Synaptic Package Manager:
apt-get install synaptic

Then under preferences, expand your repositories until you can find and install 'openssl-dev' .

After this, the two commands above will build the necessary files and paths, and with hope, your CUDA enabled gpu will appear in the list of cores.

Thanks to this dude, big time:

http://code.google.com/p/pyrit/issues/detail?id=353

Navdeep Singh said...

Sir,

I have dell xps with nVIDIA 540m optimus is there any method by using bumblebee that i can use pyrit?

thanks

Navdeep Singh