Linux
18 June 2011 1 Comment

Packet Crafting on Linux Using Scapy

Introduction

Scapy is a powerful interactive packet manipulation tool, packet generator, network scanner, network discovery tool, and packet sniffer. It is written in the Python, and is installed by default on Backtrack 4+. On Ubuntu it can be installed using this command:

sudo apt-get install scapy

The official scapy documentation is located here, and you may also need a Python Cheat Sheet.

Scapy Basics

Execute scapy at the command-line to run the Python interpreter with the scapy libraries loaded.

Start up scapy and run the ls() command. This will list all supported packet types.

$ scapy
Welcome to Scapy (2.0.0.5 beta)
>>> ls()
ARP        : ARP
ASN1_Packet : None
BOOTP      : BOOTP
CookedLinux : cooked linux
DHCP       : DHCP options
...more

List all available functions using lsc():

>>> lsc()
 sr               : Send and receive packets at layer 3
 sr1              : Send packets at layer 3 and return only the first answer
 srp              : Send and receive packets at layer 2
 srp1             : Send and receive packets at layer 2 and return only the first answer
 srloop           : Send a packet at layer 3 in loop and print the answer each time

The ls() command can do much more. Show the contents of the IP structure with ls(IP)

Tags: , , , , lsc, packet crafting, packet generator, , scapy
Linux
1 January 2011 0 Comments

The LS Command: Listing Directories and Other Useful Tricks

The ls command is the bread and butter of the Linux terminal. Have you unlocked its true potential? Probably not.

List Directories Only

You’d think the designers of the ls command would make it trivial to query all subdirectories of the current working directory. It turns out it is a little harder than trivial, but still simple to do.

$ ls -d */

This will list all directories in the working directory. The trick is to use the -d argument, combined with a filter  */ that selects only directories. The -d switch will stop the command  from descending into subdirectories (the man page is not very clear on this, but I’m pretty sure that’s how it works). So, it just prints all entries that end with a / in the current directory, and does not descend into subdirectories.

Note that this relies on your shell interpreter (i.e. bash) to expand the wildcard. If this does not fit your needs, you can find many alternatives here.

Show Type Indicator

If you want to list  both files and directories, but you want to  clearly see if something is a file, a directory, a symlink, etc, then use this:

$ ls -F

This will add a foreslash (/) to the end of every directory name, an asterisk (*) to executable…

Tags: directories, foreslash, , ls -d, wildcard