I've moved this blog to GitHub Pages.
The RSS feed is here.
Friday, September 18, 2015
Wednesday, July 15, 2015
Installing netmiko on Windows
Netmiko is a Python module by Kirk Byers that provides a wrapper around the Paramiko SSH module for doing screen scraping and CLI automation on network devices.
Paramiko has some dependencies that make installation on Windows a tad tricky. Here's a quick way to get it done:
Paramiko has some dependencies that make installation on Windows a tad tricky. Here's a quick way to get it done:
- Install Anaconda.
- From the Anaconda shell, run "conda install paramiko".
- From the Anaconda shell, run "pip install scp".
- Install git for Windows.
- Clone netmiko with "git clone https://github.com/ktbyers/netmiko"
- cd into the netmiko directory and run "python setup.py install".
Tuesday, July 14, 2015
Extracting Traffic from Rolling Capture Files
Every so often I need to extract a subset of traffic from a set of rolling timestamped pcap files. One common place I do this is with Security Onion; one of the great features of SO is its full-packet-capture feature: you can easily pivot from Snort, Suricata, or Bro logs to a full packet capture view, or download the associated pcap file.
But what if you don't have an associated alert or Bro log entry? Or if you're doing pcap on some system that's not as user-friendly as Security Onion, but nonetheless supports rolling captures?
The way I usually do this is with find and xargs. Here's an example of my most common workflow, using timestamps as the filtering criteria for find:
> find . -newerct "16:07" ! -newerct "16:10" | xargs -I {} tcpdump -r {} -w /tmp/{} host 8.8.8.8
> cd /tmp
> mergecap -w merged.pcap *.pcap
Translated:
But what if you don't have an associated alert or Bro log entry? Or if you're doing pcap on some system that's not as user-friendly as Security Onion, but nonetheless supports rolling captures?
The way I usually do this is with find and xargs. Here's an example of my most common workflow, using timestamps as the filtering criteria for find:
> find . -newerct "16:07" ! -newerct "16:10" | xargs -I {} tcpdump -r {} -w /tmp/{} host 8.8.8.8
> cd /tmp
> mergecap -w merged.pcap *.pcap
Translated:
- Find all files in the current directory created after 16:07 but not created after 16:10. This requires GNU find 4.3.3 or later. It supports many different time and date formats.
- Using xargs, filter each file with the "host 8.8.8.8" BPF expression and write it to /tmp with the same filename.
- Merge all the .pcap files in /tmp into merged.pcap.
Friday, May 15, 2015
More ADN (Awk Defined Networking)
Want to know how many IPv4 nodes are in each of your VLANs? Use ADN:
ssh myswitch 'sh arp | i Vlan' | awk '{print $NF}' | sort | uniq -c | sort -rn
79 Vlan38
65 Vlan42
58 Vlan34
22 Vlan36
21 Vlan32
20 Vlan40
9 Vlan3
7 Vlan8
5 Vlan6
5 Vlan204
5 Vlan203
5 Vlan2
4 Vlan74
3 Vlan82
3 Vlan4
ssh myswitch 'sh arp | i Vlan' | awk '{print $NF}' | sort | uniq -c | sort -rn
79 Vlan38
65 Vlan42
58 Vlan34
22 Vlan36
21 Vlan32
20 Vlan40
9 Vlan3
7 Vlan8
5 Vlan6
5 Vlan204
5 Vlan203
5 Vlan2
4 Vlan74
3 Vlan82
3 Vlan4
Friday, April 24, 2015
ADN - Awk Defined Networking
Because I have yet to transition to a completely software-defined network in which everything configures itself (wink wink), I still have to do tasks like bulk VLAN changes.
Thanks to a recent innovation called ADN, or "AWK Defined Networking", I can do this in a shorter time window that the average bathroom break. For example, I just had a request to change all ports on a large access switch stack that are currently in VLAN 76 to VLAN 64:
# ssh switch_name.foo.com 'show int status | i _76_' | grep Gi | awk '{print "int ",$1,"\n","description PC/Phone","\n","switchport access vlan 64"}'
Password: ***
int Gi1/0/25
description PC/Phone
switchport access vlan 64
int Gi1/0/26
description PC/Phone
switchport access vlan 64
[many more deleted]
Then I copied and pasted the results into config mode. Back to lounging on the beach.
Not even any Python skills required!
Thanks to a recent innovation called ADN, or "AWK Defined Networking", I can do this in a shorter time window that the average bathroom break. For example, I just had a request to change all ports on a large access switch stack that are currently in VLAN 76 to VLAN 64:
# ssh switch_name.foo.com 'show int status | i _76_' | grep Gi | awk '{print "int ",$1,"\n","description PC/Phone","\n","switchport access vlan 64"}'
Password: ***
int Gi1/0/25
description PC/Phone
switchport access vlan 64
int Gi1/0/26
description PC/Phone
switchport access vlan 64
[many more deleted]
Then I copied and pasted the results into config mode. Back to lounging on the beach.
Not even any Python skills required!
Thursday, March 26, 2015
Quick Example: Elasticsearch Bulk Index API with Python
A quick example that shows how to use Elasticsearch bulk indexing from the Python client. This is dramatically faster than indexing documents one at a time in a loop with the index() method.
Saturday, February 28, 2015
Filtering .raw fields with Python Elasticsearch DSL High-Level Client
It took me a while to figure out how to search the not_analyzed ".raw" fields created by Logstash in Elasticsearch indices, using the high-level Python Elasticsearch client. Because keyword arguments can't have attributes, Python throws an error if you try it the intuitive way (this assumes you've already set up a client as es and an index as i, as shown in the docs):
Instead, you create a dictionary with your parameters and unpack it using the ** operator:
This produces the Elasticsearch query we want:
Instead, you create a dictionary with your parameters and unpack it using the ** operator:
This produces the Elasticsearch query we want:
Thursday, January 15, 2015
Pleasing terminal colors on Security Onion
To get the lovely Solarized theme working in Security Onion:
- sudo apt-get install gnome-terminal
- I'm sure there's a way to get in working in the default xfce4 terminal, but I couldn't figure it out.
- Follow instructions here: http://stackoverflow.com/questions/23118916/configuring-solarized-colorscheme-in-gnome-terminal-tmux-and-vim
Thursday, January 8, 2015
Problems with kvm-ok in VIRL with VMWare Player
I'm installing Cisco VIRL, and despite following the instructions regarding nested virtualization settings, the kvm-ok command was still complaining. I needed to edit the .vmx file for the VIRL VM and add/edit the following:
monitor.virtual_mmu = "hardware"
monitor.virtual_exec = "hardware"
vhv.enable = "TRUE"
monitor_control.restrict_backdoor = "true"
Friday, January 2, 2015
My Network Toolkit
A while back, Chris Marget of Fragmentation Needed posted a run-down of his comprehensive and extremely clever network toolkit. Because I'm something of a weight weenie, mine is a lot more slimmed down. I thought I'd post it here:
The contents:
The Fenix AA light and Leatherman Skeletool CX almost always live in a pocket rather than the kit and go with me everywhere. The kit all fits into a small zippered case that used to hold a Dell laptop power supply.
My main goal here was to have all the hard-to-find professional stuff in one small package. I have a separate "personal" kit that contains stuff like headphones, USB cables, and chargers for personal electronics.
The contents:
- Two random USB drives (in case I need to leave one with somebody).
- Single-mode and multi-mode LC fiber loopback plugs.
- Rack PDU plug adapter.
- Awesome PicQuic compact screwdriver (thanks to Chris's post).
- T1 loopback plug (red) (because we still have T1s out here in the boonies).
- Cat-6 pass-through plug (white).
- Crossover adapter (orange).
- Sharpie.
- Console setup:
- USB-to-DB9 adapter.
- DB9-to-RJ45 adapter.
- Flat Cat-6 cable.
- Rollover adapter.
- Velcro tie
- Flat Cat-6 cable with velcro tie.
The Fenix AA light and Leatherman Skeletool CX almost always live in a pocket rather than the kit and go with me everywhere. The kit all fits into a small zippered case that used to hold a Dell laptop power supply.
My main goal here was to have all the hard-to-find professional stuff in one small package. I have a separate "personal" kit that contains stuff like headphones, USB cables, and chargers for personal electronics.
Subscribe to:
Posts (Atom)