sexta-feira, 7 de novembro de 2014

Sniffer de pacotes Zigbee ou IEEE 802.15.4 com o Wireshark

Para análise da troca de mensagens de redes de sensores sem fio, especialmente 6LowPAN, a melhor forma é através de um sniffer wireless, que capturasse pacotes IEEE 802.15.4 . Para isso adquiri no dx.com um dongle USB com o chip CC2531 da Texas Instruments. Primeiro tentei utilizar o software disponível pela Texas, mas percebi que era muito ruim, muito inferior ao que normalmente utilizamos, o Wireshark.
Encontrei um projeto muito interessante, para Linux (embora pusesse ser usado no Windows, com muito trabalho), chamado ccsniffpiper. É um programa em Python, que cria um "pipe" entre o dongle USB e o Wireshark. Inicialmente não funcionou com o dongle do dx.com (provavelmente um problema de versão de firmware), mas o Andrew, autor do ccsniffpiper, rapidamente me deu uma dica valiosa e ele funcionou muito bem.
O uso do dongle no Linux me criou um certo transtorno, por ter de rodar o ccsniffpiper e o Wireshark em uma máquina separada (um Raspberry Pi). Ontem encontrei, por acaso uma solução. A Texas Instruments incluiu no pacote  TIMAC 1.5.1 o software TiWsPc, TI Wireshark Packet Converter. Ele faz o mesma função do ccsniffpiper, para Windows. Testei no meu Windows 7 64 Bits e funcionou perfeitamente.
Para configurar, basta rodar o programa TiWsPc com o dongle instalado, e configurar o device com o número do canal:


Em seguida configure o Wireshark para inserir o pipe como uma nova interface em Capture -> Options:


Em seguida, configure em Edit -> Preferences -> Protocols -> IEEE 802.15.4 o FCS para o chip TI CC2531:


E está pronto, basta iniciar a captura.


quarta-feira, 18 de junho de 2014

DDOS com o Pyresonance

Alterei o exemplo IDS do Pyresonance para receber eventos JSON para bloquear um fluxo ou liberá-lo. O comportamento inicial da FSM é liberar todos os fluxos.O programa e o globals estão no Gist.

Os eventos JSON para bloquear o host e liberá-lo são:
python ~/pyretic/pyretic/pyresonance/json_sender.py --flow='{srcip=10.0.0.1}' -e ids -s attack -a 127.0.0.1 -p 50003
python ~/pyretic/pyretic/pyresonance/json_sender.py --flow='{srcip=10.0.0.1}' -e ids -s clean -a 127.0.0.1 -p 50003

Agora, para verificar os fluxos instalados no mininet:
sudo mn --topo=single,3 --controller=remote
cd ~mininet/pyretic
./pyretic.py pyretic.pyresonance.main --config=./pyretic/pyresonance/global.config.dos_external --mode=manual

mininet: h1 ping h2

[mininet@mininet-vm:~]$sudo ovs-appctl bridge/dump-flows s1
duration=56s, priority=0, n_packets=1, n_bytes=42, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,arp_op=1,actions=output:2,output:1
duration=61s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,arp_op=2,actions=output:2,output:1
duration=56s, priority=0, n_packets=1, n_bytes=42, priority=0,arp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,arp_op=2,actions=output:3,output:2
duration=61s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=ff:ff:ff:ff:ff:ff,nw_src=10.0.0.1,nw_dst=10.0.0.2,arp_op=1,actions=output:2,output:3
duration=61s, priority=0, n_packets=60, n_bytes=5880, priority=0,icmp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0,actions=output:2,output:3
duration=61s, priority=0, n_packets=60, n_bytes=5880, priority=0,icmp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0,actions=output:1,output:2
duration=62s, priority=0, n_packets=15, n_bytes=1054, priority=0,actions=CONTROLLER:65535

[mininet@mininet-vm:~]$python ~/pyretic/pyretic/pyresonance/json_sender.py --flow='{srcip=10.0.0.1}' -e ids -s attack -a 127.0.0.1 -p 50003

Flow = {srcip=10.0.0.1}
Data Payload = {'dstip': None, 'protocol': None, 'srcmac': None, 'tos': None, 'vlan_pcp': None, 'dstmac': None, 'inport': None, 'ethtype': None, 'srcip': '10.0.0.1', 'dstport': None, 'srcport': None, 'vlan_id': None}
ok

[mininet@mininet-vm:~]$sudo ovs-appctl bridge/dump-flows s1

duration=13s, priority=0, n_packets=12, n_bytes=1176, priority=0,icmp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0,drop
duration=14s, priority=0, n_packets=1, n_bytes=98, priority=0,actions=CONTROLLER:65535

h2 ping h3

[mininet@mininet-vm:~]$sudo ovs-appctl bridge/dump-flows s1
duration=10s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=ff:ff:ff:ff:ff:ff,nw_src=10.0.0.2,nw_dst=10.0.0.3,arp_op=1,actions=output:1,output:2
duration=5s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=aa:b5:d9:88:c5:ba,nw_src=10.0.0.2,nw_dst=10.0.0.3,arp_op=2,actions=output:2,output:1
duration=10s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=2,dl_src=aa:b5:d9:88:c5:ba,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.3,nw_dst=10.0.0.2,arp_op=2,actions=output:3,output:1
duration=5s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=2,dl_src=aa:b5:d9:88:c5:ba,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.3,nw_dst=10.0.0.2,arp_op=1,actions=output:3,output:1
duration=46s, priority=0, n_packets=25, n_bytes=2450, priority=0,icmp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0,drop
duration=10s, priority=0, n_packets=10, n_bytes=980, priority=0,icmp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=aa:b5:d9:88:c5:ba,nw_src=10.0.0.2,nw_dst=10.0.0.3,nw_tos=0,icmp_type=8,icmp_code=0,actions=output:1,output:2
duration=10s, priority=0, n_packets=10, n_bytes=980, priority=0,icmp,in_port=2,dl_src=aa:b5:d9:88:c5:ba,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.3,nw_dst=10.0.0.2,nw_tos=0,icmp_type=0,icmp_code=0,actions=output:3,output:1
duration=47s, priority=0, n_packets=7, n_bytes=462, priority=0,actions=CONTROLLER:65535

[mininet@mininet-vm:~]$python ~/pyretic/pyretic/pyresonance/json_sender.py --flow='{srcip=10.0.0.1}' -e ids -s clean -a 127.0.0.1 -p 50003

[mininet@mininet-vm:~]$sudo ovs-appctl bridge/dump-flows s1                                                              duration=925s, priority=0, n_packets=28, n_bytes=1176, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,arp_op=1,actions=output:2,output:1
duration=930s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,arp_op=2,actions=output:2,output:1
duration=925s, priority=0, n_packets=28, n_bytes=1176, priority=0,arp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,arp_op=2,actions=output:3,output:2
duration=930s, priority=0, n_packets=0, n_bytes=0, priority=0,arp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=ff:ff:ff:ff:ff:ff,nw_src=10.0.0.1,nw_dst=10.0.0.2,arp_op=1,actions=output:2,output:3
duration=930s, priority=0, n_packets=930, n_bytes=91140, priority=0,icmp,in_port=1,dl_src=8a:3a:15:ce:f1:17,dl_dst=aa:d0:ed:f7:e4:83,nw_src=10.0.0.1,nw_dst=10.0.0.2,nw_tos=0,icmp_type=8,icmp_code=0,actions=output:3,output:2
duration=930s, priority=0, n_packets=930, n_bytes=91140, priority=0,icmp,in_port=3,dl_src=aa:d0:ed:f7:e4:83,dl_dst=8a:3a:15:ce:f1:17,nw_src=10.0.0.2,nw_dst=10.0.0.1,nw_tos=0,icmp_type=0,icmp_code=0,actions=output:2,output:1
duration=931s, priority=0, n_packets=10, n_bytes=756, priority=0,actions=CONTROLLER:65535

segunda-feira, 2 de junho de 2014

Sobre o LXC

Copiado do Blog do Danny

# Install LXC
sudo apt-get install lxc

# Create a Linux Container named base ( -t: template, -n: namespace )
sudo lxc-create -t ubuntu -n base

# Start the Linux Container ( -d: daemon )
sudo lxc-start -n base -d

# Stop the Linux Container
sudo lxc-stop -n base

# List Linux Containers
lxc-ls --fancy

# Clone the Linux Container
lxc-clone -o base -n newvm1

# Access the container
lxc-console -n newvm1

# Shudown
lxc-shutdown -n test-container

# Destroy
lxc-destroy -n test-container


LXC can be controlled via Libvirt:
http://blog.scottlowe.org/2013/11/27/linux-containers-via-lxc-and-libvirt/

Exploring LXC Networking:

Autostart
By default, containers will not be started after a reboot, even if they were running prior to the shutdown.
To make a container autostart, you simply need to symlink its config file into the /etc/lxc/auto directory:
ln -s /var/lib/lxc/test-container/config /etc/lxc/auto/test-container.conf

sexta-feira, 2 de maio de 2014

Kernel-based Openflow OpenVSwitch on TP-Link WR-1043nd with OpenWRT

I spent a couple days compiling the OpenVswitch 2.0 (and 2.1.2) for my TP-Link WR-1043ND V1.8. I tried at first the Open WRT "trunk" version, but due some errors regarding the "PKG_USE_MIPS16:=0" parameters, I gave up and I decided to use the stable 12.10 Attitude Adjustment, r40431. Later, I found the solution for this MIPS16 issue in the menuconfig "Target Options", but I still with the 12.10 stable version.

The result was amazing, much better than the results with Pantou or CPQD's user-mode switches. I obtained 92 Mbps of throughput instead of the 29 Mbps in user-mode switches. Probably I can get more, but my computer interfaces negociated only at 100 Mbps for the Iperf test.
There is also a user-mode option on OpenVSwitch, but is very slow, with 4 Mbps of throughput.
I'll try to figure out the differences in features between the two modes later.

The steps to compile the OVS are the following, using a Linux machine (either virtual or real) with Ubuntu 12.19, 7 GB free space, 1,5 Gb RAM.

apt-get install git quilt build-essential binutils flex bison autoconf gettext texinfo sharutils subversion libncurses5-dev ncurses-term zlib1g-dev gawk

git clone git://git.openwrt.org/12.09/openwrt.git cd openwrt
./scripts/feeds update -a
./scripts/feeds install -a
The next step is choosing the feed location. For the 2.0 OVS version:
echo 'src-git openvswitch git://github.com/alexanderplatz1999/openvswitch.git' >> feeds.conf
or 2.1.2 OVS version:
echo 'src-git openvswitch git://github.com/pichuang/openvwrt.git' >> feeds.conf

./scripts/feeds update openvswitch
./scripts/feeds install -a -p openvswitch
make menuconfig
Select Target Profile (TP-LINK TL-WR1043N/ND)
<*> iperf
-*- openvswitch-common
<*> openvswitch-controller
<*> openvswitch-ipsec
<*> openvswitch-switch
<*> tcpdump
Kernel modules ---> Network Support ---> <*> kmod-tun
Save and Exit
make kernel_menuconfig
> Networking support > Networking options > <*> Open vSwitch
> Networking support > Networking options > <*> Hierarchical Token Bucket (HTB)
Save and Exit
echo '# CONFIG_KERNEL_BRIDGE is not set' >> .config

     You can do the "make" command right now, but the image will be generated without the configuration files. The image will be in the openwrt/bin/ar71xx/openwrt-ar71xx-generic-tl-wr1043nd-v1-squashfs-factory.bin file.The IP address for telnet access using a LAN port is 192.168.1.1, no login and password.
Transfer the image to the router using the Web GUI if you are using the original TP-Link firmware or WINSCP
BusyBox v1.19.4 (2014-04-08 13:48:14 PDT) built-in shell (ash)
Enter 'help' for a list of built-in commands.

  _______                     ________        __
 |       |.-----.-----.-----.|  |  |  |.----.|  |_
 |   -   ||  _  |  -__|     ||  |  |  ||   _||   _|
 |_______||   __|_____|__|__||________||__|  |____|
          |__| W I R E L E S S   F R E E D O M
 -----------------------------------------------------
 ATTITUDE ADJUSTMENT (Attitude Adjustment, r40431)
 -----------------------------------------------------
  * 1/4 oz Vodka      Pour all ingredients into mixing
  * 1/4 oz Gin        tin with ice, strain into glass.
  * 1/4 oz Amaretto
  * 1/4 oz Triple sec
  * 1/4 oz Peach schnapps
  * 1/4 oz Sour mix
  * 1 splash Cranberry juice
 -----------------------------------------------------
root@OpenWrt:~#

    If you want to include the configuration files before the "make", follow this steps in the Linux machine (not the router):
mkdir files
mkdir files/etc
mkdir files/etc/config
mkdir files/etc/rc.d
   Copy the files from this Gist location. The S99ovsboot (adapted from a  script used  in NZNOG SDN workshop) must be saved in the files/etc/rc.d, and the "network", "firewall" and "wireless" in the files/etc/config directory.
With these configuration files, the IP address to access the router is 192.168.1.112 on the WAN port and the openflow controller address is 192.168.1.130.
   You can try the compiled image (tested on a TP-Link WR-1043 V1.8). The IP address of WAN interface is 192.168.1.112 and the controller is 192.168.1.130, but you can change them editing the files /etc/config/network and /etc/rc.d/S99bootovs.

Update:
During the tests I obtained more than 500 Mbps. Is much more than the user space switch (29 Mbps). The results of IPERF test for upload and WGET download of a 400 MB file are the following. Without the DUT (the TP-Link), the performance was about 1 Gbps.

IPERF:
------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54581 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   611 MBytes   513 Mbits/sec

------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54584 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   594 MBytes   498 Mbits/sec

------------------------------------------------------------
Client connecting to 200.x.x.x, TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  3] local 100.64.0.1 port 54587 connected with 200.x.x.x port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   590 MBytes   495 Mbits/sec

WGET (HTTP)
...
410250K .......... .......... .......... .......... ....      100% 89,1M=6,7s
2014-05-19 13:22:36 (60,2 MB/s) - /dev/null

60,2 MB/s = 481,6 Mbps

sábado, 15 de março de 2014

Webservices no POX

Para o suporte de Webservices no POX, o módulo openflow.webservice deve ser carregado junto do controlador:
./pox.py log.level --DEBUG  web.webcore openflow.webservice samples.pretty_log
Note que neste exemplo o módulo forwarding.l2_learning não foi carregado, ou seja, o POX não instalará fluxos no switches OF automaticamente para eles se comportarem como "switches"
Se você rodar o mininet em uma outra janela, os hosts não irão se pingar, pois não existem fluxos instalados no controlador:
sudo mn --controller remote  (um switch e dois hosts)
Para instalar um fluxo no switch, envie via curl (em outra janela) o seguinte comando para o controlador, que transformará o switch OF  em um HUB, permitindo a comunicação entre os hosts:
curl -i -X POST -d '{"method":"set_table","params":{"dpid":"00-00-00-00-00-01","flows":[{"actions":[{"type":"OFPAT_OUTPUT","port":"OFPP_ALL"}],"match":{}}]},"id":0}' http://127.0.0.1:8000/OF/
Agora o pingall do mininet deverá funcionar.
Para verificar os fluxos instalados no switch 1:
curl -i -X POST -d '{"method":"get_flow_stats","params":{"dpid":"00-00-00-00-00-01"},"id":0}' http://127.0.0.1:8000/OF/

Um outro exemplo é

./pox.py log.level --DEBUG forwarding.l2_learning web.webcore openflow.webservice
Note que o módulo forwarding.l2_learning também foi carregado, ou seja, não será necessário instalar fluxos via curl.

Rode o mininet em outra janela:
sudo mn --topo linear,4 --controller remote (quatro switches em linha, 1 host por switch)

Por exemplo, para ver os fluxos instalados no switch 4 após um pingall no mn, o comando é:
curl -i -X POST -d '{"method":"get_flow_stats","params":{"dpid":"00-00-00-00-00-04"},"id":0}' http://127.0.0.1:8000/OF/

Para listar os switches instalados no controlador:
curl -i -X POST -d '{"method":"get_switches", "id":0}' http://127.0.0.1:8000/OF/

Este post abaixo, do site http://www.noxrepo.org/2012/09/pox-web-interfaces/  diz que o melhor modo de se utilizar webservices é com o módulo ajax_transport, pois a comunicação do POX com a aplicação é bidirecional, avisando a aplicação quando há a entrada de um pacote no switch :
"The other major way to work with OpenFlow over the web is via the OpenFlow messenger service (openflow.of_service) coupled with one of the messenger’s web transports (e.g., ajax_transport). This is what POXDesk does — you can use it as an example if you want to check it out. As far as I recall, the only real reason to do this now is that it supports notifications like packet_ins."

quarta-feira, 12 de março de 2014

Evolução do Openflow

Alguns temas importantes para o Openflow já estão sendo explorados por diversos pesquisadores.
A mitigação de DDOS está com um um trabalho muito bom do Peter Phaal
http://blog.sflow.com/2013/08/frenetic-pyretic-and-resonance.html Outro link sobre DDOS: http://packetpushers.net/openflow-1-0-actual-use-case-rtbh-of-ddos-traffic-while-keeping-the-target-online/
No ONS (Open Network Summit) da semana passada, o Yiannis (doutorando de Stanford), que trabalhou no projeto Pantou, que permitiu o uso do Openflow nos switches TP-Link que tenho em casa e que estou utilizando para os experimentos, apresentou um trabalho bem interessante sobre o controle total de uma rede Wi-Fi via Openflow: http://cio.com.br/tecnologia/2014/03/06/stanford-experimenta-gestao-da-rede-wifi-com-sdn
Na SIGCOMM do ano passado encontrei vários papers interessantes: http://conferences.sigcomm.org/sigcomm/2013/hotsdn.php
Agora é esperar os vídeos da ONS no Youtube.

sábado, 8 de fevereiro de 2014

Experiências com SDR (Software Definied Radio)

Nos dias de hoje, hardware é "commodity", e a mágica está no software. Penso assim com as SDN (Software Definied Networks), tema de meu estudo. Na área de radioamadorismo, que tenho um pezinho, com indicativo PY5 apesar de não ser ativo, existe a área de SDR (Softare Definied Radio). O hardware básico, que é um "dongle" USB é muito barato na DX.com (para variar), menos de US$ 15,00 com frete zero. Originalmente é um receptor de TV digital e ráio FM, mas o chipset RTL2832U+R820T é muito versatil e com o software certo, pode receber sinais de RF desde alguns Mhz até mais de 1,2 GHz.

Testei vários softwares , como o HDSDR, mas não gostei por não receber Wide FM das rádios comerciais:
O melhor para mim foi o SDRSharp ou SDR#. Nestas últimas versões, por problemas com direitos de distribuição da  biblioteca RTLSDR.DLL a instalação ficou mais chata, mas é só seguir os forums. Algumas dicas:
  • Não instale os drivers que vem com a placa.
  • Siga este tutorial
  • Use o Zadix para instalar o driver no micro
  • Copie o arquivo rtlsdr.dll para a pasta SdrSharp
  • Retire os comentários sobre a placa RTL USB no arquivo SDRSharp.exe.Config
Com estas modificações, a opção RTL-SDR / USB deve aparecer no Menu:


terça-feira, 4 de fevereiro de 2014

Adaptando o Arduino Mini Pró para alimentar módulos 3,3V

Um pequeno mod para que o Arduino pró mini alimente módulos que tem alimentação 3,3V, como o radio Nrf24L01. Usei os reguladores de tensão AMS1117 da dx.com com os módulos Funduino da dx.com também (de US$ 5,83).
Para fazer a adapatação, apenas cortei com um estilete a trilha da ilha de um dos pinos de GND do módulo e soldei um regulador (com a identificação para trás) nos três pinos da barra, como na foto abaixo.Assim, ficou apenas o GND da ponta, o segundo pino ficou com 3,3V e o terceiro permaneceu como Vin.