Wednesday, January 26, 2011

802.11 WEP Wireless Hacking

Introduction to WEP and the IV vulnerability

Wired Equivalent Privacy (WEP) is a wireless security protocol, providing both encryption and authentication.

The encryption method used is RSA's RC4 stream cipher. The RC4 algorithm operates on a 'seed' consisting of an initialization vector (IV) and a secret shared key to create a keystream which is XORed with plaintext to create ciphertext.

When connecting to a WEP secured network you are asked for the secret shared key which is used to authenticate clients to the network and also encrypt the traffic.

The vulnerability in the WEP protocol is the transit of the IV in plaintext. This allows an attacker to eavesdrop on wireless traffic and collect enough IVs to bruteforce the secret shared authentication key. Once the key is obtained the attacker uses it to connect to the target wireless network.
Note: A standard WEP implementation uses a 40 bit key and a 24 bit IV, resulting in a 64 bit keystream. Because of this, WEP is sometimes referred to as 40 bit WEP or 64 bit WEP.

Cracking a WEP Key

The purpose of this article is for education and security auditing only. Anyone using this for any other reason are liable for their own actions. 

To see this vulnerability work and to actually crack a WEP key in a test environment you need some tools.
  • A test network using an 802.11 wireless router with WEP enabled and a 40 bit key created. 
  • A linux machine with a wireless card. In this example Back Track 4 r2 is the operating system used. Download a live DVD if you don't have a dedicated machine.
  • macchanger, airmon-ng, airdump-ng, and aircrack-ng. These tools are all included in Back Track 4. 

    The following example is a passive WEP attack that observes traffic and collects IVs. In comparison, an active attack involves packet injection to get the access point (AP) to generate more traffic and in turn more IVs; resulting in a faster crack. The passive attack takes significantly longer depending on the traffic volume on the target network. 


    Assuming the wireless interface is wlan0, disable the interface. 
    ifconfig wlan0 down

    Use macchanger to change the MAC address of the wlan0 interface. 
    macchanger --mac 00:11:22:33:44:55 wlan0

    Bring the wlan0 interface back up.
    ifconfig wlan0 up

    Use airmon to create a monitor mode interface for wlan0. The new monitoring interface is called mon0.
    airmon-ng start wlan0

    Run airodump to observe target networks and gather MAC (BSSID), channel and ESSID.
    airodump-ng mon0

    Run airodump again this time specifying the target channel, BSSID, and file to dump the output to. This step is where the IVs are collected for analysis later. Again, since this is a passive attack it may take a while to collect enough IVs. Leave the machine on overnight collecting data if needed.

    airodump-ng --ivs -w /root/dumpfile --bssid mon0

    Keep an eye on the above command. One column is called #Data. This is the actual number of IVs collected from the network. If there is no traffic on the network this number will slowly increase. Once you have about 20,000 IVs, run the following command.
    aircrack-ng /root/dumpfile.cap

    aircrack will report back if it has successfully cracked the WEP key or if you need to continue to collect more IVs and try again. The number of IVs needed to crack a key varies, but it can be done in less than 20,000 IVs.

    Enjoy.

    Saturday, December 25, 2010

    Linux RAM Drive

    While developing software I occasionally have the need for a RAM drive. There are many reasons and situations where this comes in handy. Usually I use it to store temporary data files, that I can read/write to much faster since they now reside in RAM instead of on the hard drive. The reason is physics. Its faster to read and work on files stored in RAM than it is for a seek/read on the hard drive.

    The way it works is simple. You create a folder to be your "RAM drive" - this is the directory that will be stored in RAM. Then you mount the directory as a "tmpfs" and specify the amount of system memory this new RAM drive will occupy. If you want to copy a file or work with a data file from a script in the RAM drive, place it in this directory and work with it the same way you would normally.

    Here's the commands to create a directory, then mount it as a tmpfs (RAM drive).

    mkdir -p /home/user/Desktop/ramdrive
    mount -t tmpfs -o size=500M,mode=0777 tmpfs /home/user/Desktop/ramdrive


    As you can see, the mounted RAM drive is 500Mb, and set to 777 mode (accessable and executable by anyone) - once the RAM drive is dismounted, all files within it are gone. Make sure to copy them out when you're done using it.


    You can also drastically increase the speed at which Apache serves up your web pages using this method.

    To test this on your LAMP create the RAM drive inside /var/www and test the speed of loading those pages as compared to files read from the hard disk.



    Computer Biology

    MySQL Commands

    Some useful MySQL commands:

    Alter a table to create a fulltext index of the columns specified..
    ALTER TABLE tablename ADD FULLTEXT(column1, column2);


    Search a fulltext index, using query expansion which increases relevancy but decreases the speed of the query. Further speed up the query by limiting the result set to 10 results.
    SELECT * FROM tablename WHERE MATCH(column1,column2,column3) AGAINST('Search Phrase' WITH QUERY EXPANSION) LIMIT 10;


    To import data from a text file into a MySQL database, assuming the text file is a list with each new record on a new line. For example:
    Number One
    Thing number 2
    and a Third
    Use the following MySQL command:
    LOAD DATA INFILE '/home/user/Desktop/file.txt' INTO TABLE tablename (column1);
    This import will only work on a database that is already setup with the proper column settings and data type.


    Execute MySQL query from a bash shell script:

    #!/bin/bash
    TABLE_NAME=testtable
    USER_NAME=root
    IP_ADDR=localhost
    PASSWD=Secret

    somevar=`echo "select column1 from testtable where idkey='5'" | mysql -h $IP_ADDR -u $USER_NAME -p$PASSWD $TABLE_NAME `

    echo $somevar


    Notes on the above bash script: You can replace the MySQL query in the script with any MySQL command.

    Dont forget about the ticks ( ` ` ) that encapsulate the commands inside. This is a useful trick that took me a while to research and figure out. I wanted to set a variable to the results of some commands and found that you need to use the ` ` , not the ' (single quote) this tick shares the same key as the tilde key, to the left of the 1 key.



    To view any query that may be hung up or taking a long time to execute:

    show full processlist

    This will display a table of the MySQL processes running, the process ID, and the Status.

    If you find a rogue or otherwise not needed query you can kill that process ID using:

    kill 1234
    Where 1234 is the process ID that you want to end.



    More coming soon.

    Friday, December 10, 2010

    LAMP Server Stack

    Setting up a Linux Apache MySQL PHP (LAMP) server requires a few commands to get you up and running.

    If you run Ubuntu or Debain - this is how I got started (Ubuntu 10.04) ; Open a terminal and run:
    sudo apt-get install php5 php5-mysql mysql-server mysql-client mysql-query-browser apache2

    As you can see from the list above, this command will install the following programs:
    • PHP ver 5
    • PHP MySQL Module
    • MySQL Server
    • MySQL Client
    • MySQL Query Browser GUI
    • Apache 2 Web server

    During the MySQL install you will be asked to create a password for the MySQL root user. Remember this username/password.


    Verify Apache is Operational

    When the install finishes; Browse to http://localhost/ and look for the infamous  

    "It Works!"

    message. If you see this, Apache is up and running properly.


    Verify PHP is Operational

    Build yourself a file called test.php with the following code in it:
    <?
    phpinfo();
    ?>
    Save the file test.php in /var/www/ - this is the default local directory where Apache serves up your web documents.

    Open a browser and enter the address: http://localhost/test.php

    This should display a long page containing version information and current configuration of PHP.

    This means that the file was executed properly and PHP is working.


    Verify MySQL Server is Operational

    From the terminal type:
    mysql -u root -p
    This command runs mysql as user (-u) root with a password of...(-p) You will be prompted to enter a password. This is the root MySQL password created when installing MySQL.

    If you correctly enter the password you will be taken to the mysql> command prompt.

    MySQL is working. Type: quit

    Congratulations, you now have a LAMP server stack at your service!

    Enjoy. 

    Saturday, July 3, 2010

    FTP - Packet Sniffing and Wireshark Analysis

    FTP (File Transfer Protocol) as the name implies, is a protocol to transfer files from one computer to another. The protocol operates on TCP ports 20 for data transfer and 21 for control. The authentication, communication, and file data are all communicated in plain text; meaning *no* encryption is used.

    The most common implementation of FTP is establishing a connection and transferring files with a web server. I configured Wireshark to monitor my wireless connection and then made an FTP connection to my web site.






    The screenshot above shows the resulting packets that were transmitted. Here is what actually happened:
    • I execute the command to start the connection, and immediately a DNS query goes out to find the IP address of the host name I provided.
    • DNS responds with the proper IP address and TCP takes over to initiate communication with the server using a series of SYN and ACK transmissions. (TCP Three-way handshake)
    • FTP server says "Welcome" and my host transmits the user name to authenticate. (the username is transmitted in plain text)
    • FTP server responds saying the user name is OK but needs a password.
    • My client transmits the password across the Internet **in unencrypted text** readable to anyone
    • FTP server accepted the user name and password and grants the user access permissions.
    • Client sends the command "PWD" - and the server replies by Printing the Working Directory.
    • The communication ends with another series of SYN and ACK transmissions.

    Do not use FTP to transmit anything confidential. This simple analysis shows that in 17 captured packets your server and files can be compromised.


    The best alternative is FTPS (FTP and SSL) - from the wikipedia page:
    FTPS (also known as FTP Secure and FTP-SSL) is an extension to the commonly used File Transfer Protocol (FTP) that adds support for the Transport Layer Security (TLS) and the Secure Sockets Layer (SSL) cryptographic protocols.
    FTPS should not be confused with the SSH File Transfer Protocol (SFTP), an incompatible secure file transfer subsystem for the Secure Shell (SSH) protocol. It is also different from Secure FTP, the practice of tunneling FTP through an SSH connection.



    Computer Biology