Usando wpa supplicant no Ubuntu

De gutocarvalho.net

Ubuntu, Wifi com chaves WPA/WPA2


Meu Hardware:

Notebook HP Pavillion dv4275

Adaptador Wifi: Centrino ipw2200

Distro: Ubuntu 6.06 LTS (dapper)


Roteador Wifi

Linksys WRT54G v6.0

Firmware: 1.00.9

Modo de segurança: WPA

Algoritmo: TKIP


Eu sou um cara fã de carteirinha do aplicativo WIFI-RADAR, porém infelizmente não consegui fazê-lo funcionar em redes que utilizam chaves WPA ou WPA2, outro aplicativo interessante é o SWScanner, porém ele também só tem suporte WEP.


Para resolver este problemas utilizaremos o wpa_supplicant e a wpa_gui


Conteúdo

[editar] Instalando os pacotes necessários

gutera@defiant:~$ sudo -s -H
root@defiant:/home/gutera# apt-get install wpa_supplicant wpa_gui

[editar] Criando arquivo de configuração

Vamos criar um arquivo contendo as configurações da rede que vamos utilizar.

root@defiant:/home/gutera# vi /etc/wpa_supplicant/wpa_supplicant.conf.local
ctrl_interface=/var/run/wpa_supplicant

network={
ssid="rede escritorio"
scan_ssid=1
proto=WPA
key_mgmt=WPA-PSK
psk=32531769fe4ab149b5fd092c4b54ae938ee02de79e93b88288ce3c31a15a1071
}

[editar] Gerando chaves

Como gero as chaves?

root@defiant:/home/gutera# wpa_passphrase "rede escritorio" "minha senha"
network={
ssid="rede escritorio"
#psk="minha senha"
psk=32531769fe4ab149b5fd092c4b54ae938ee02de79e93b88288ce3c31a15a1071
}


[editar] Rodando o wpa_supplicant

root@defiant:/home/gutera# wpa_supplicant
wpa_supplicant v0.4.8
Copyright (c) 2003-2006, Jouni Malinen and contributors 

This program is free software. You can distribute it and/or modify it
under the terms of the GNU General Public License version 2.

Alternatively, this software may be distributed under the terms of the
BSD license. See README and COPYING for more details.

This product includes software developed by the OpenSSL Project
for use in the OpenSSL Toolkit (http://www.openssl.org/)

usage:
wpa_supplicant [-BddehLqqvwW] [-P] [-g] \
-i -c [-C] [-D] [-p] \
[-N -i -c [-C] [-D] [-p] ...]

drivers:
hostap = Host AP driver (Intersil Prism2/2.5/3)
madwifi = MADWIFI 802.11 support (Atheros, etc.)
atmel = ATMEL AT76C5XXx (USB, PCMCIA)
wext = Linux wireless extensions (generic)
ndiswrapper = Linux ndiswrapper
ipw = Intel ipw2100/2200 driver
wired = wpa_supplicant wired Ethernet driver
test = wpa_supplicant test driver
options:
-B = run daemon in the background
-c = Configuration file
-C = ctrl_interface parameter (only used if -c is not)
-i = interface name
-d = increase debugging verbosity (-dd even more)
-D = driver name
-g = global ctrl_interface
-K = include keys (passwords, etc.) in debug output
-t = include timestamp in debug messages
-h = show this help text
-L = show license (GPL and BSD)
-p = driver parameters
-P = PID file
-q = decrease debugging verbosity (-qq even less)
-v = show version
-w = wait for interface to be added, if needed
-W = wait for a control interface monitor before starting
-N = start describing new interface
example:
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf

Temos as opções acima e um exemplo muito bom no final.

No meu caso minha interface é uma ipw2200, porém vou usar o driver generico.

root@defiant:/home/gutera# wpa_supplicant -D wext -i eth1 -c /etc/wpa_supplicant/wpa_supplicant.conf.local
Trying to associate with 00:16:b6:c7:49:38 (SSID='rede escritorio' freq=0 MHz)
Associated with 00:16:b6:c7:49:38
WPA: Key negotiation completed with 00:16:b6:c7:49:38 [PTK=TKIP GTK=TKIP]
CTRL-EVENT-CONNECTED - Connection to 00:16:b6:c7:49:38 completed (auth)

[editar] Obtendo endereço IP através de DHCP

Em outro terminal

root@defiant:/home/gutera# dhclient eth1
Internet Systems Consortium DHCP Client V3.0.3
Copyright 2004-2005 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/products/DHCP

Listening on LPF/eth1/00:15:00:24:ba:81
Sending on LPF/eth1/00:15:00:24:ba:81
Sending on Socket/fallback
DHCPDISCOVER on eth1 to 255.255.255.255 port 67 interval 4
DHCPOFFER from 192.168.1.1
DHCPREQUEST on eth1 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.100 -- renewal in 37307 seconds.
root@defiant:/home/gutera#

[editar] Automatizando as coisas

Primeiro se fizer manualmente para não deixar o terminal preso, utilize a opção -B no wpa_supplicant que ele se torna um daemon e vai rodar em background.

root@defiant:/home/gutera# wpa_supplicant -D wext -i eth1 -c /etc/wpa_supplicant/wpa_supplicant.conf.local -B

Para subir estas chaves assim que seu sistema iniciar vamos colocar algumas linhas no /etc/network/interfaces

root@defiant:/home/gutera# vi /etc/network/interfaces
auto lo
iface lo inet loopback
# wired adapter
auto eth0
iface eth0 inet dhcp
post-down dhclient -r eth0
# wireless adapter
auto eth1
iface eth1 inet dhcp
pre-up /sbin/wpa_supplicant -i eth1 -c /etc/wpa_supplicant/wpa_supplicant.conf.local -D wext -Bw
post-down killall wpa_supplicant; dhclient -r eth1

Pronto, agora ele carregará o wpa_supplicant antes de chamar o dhclient.

Você pode também usar o WPA_GUI para fazer isto via ambiente gráfico, mas não é tão gostoso quanto o console.

[]'s Guto

Ferramentas pessoais