Category Archives: Linux/Unix

Hacking with Python #0

Its been a while since ive posted anything, and for that I apologise.

Typically, my programming experience is derived from what ive been taught, as opposed to what language I found best for the job. In school, I was taught Visual Basic, in Uni I was taught C#. However, as most hackers do I taught myself C (well, enough C to explore stack based attacks) and what little assembly I could understand before my brain melted. However, the past two months I have programmed solely in Python, and by god, what an experience.

Python has so many fantastic things associated with it, that I hardly know where to begin. To start with the most obvious Python code is generally substantially shorter than any of the 3rd/4th generation languages. This is in part thanks to the massive  range of libraries associated with it. Though this does bring in the disadvantage that if an application requires a specific 3rd party library to run, you must first install it before you can run the application. However, Python is still cross platform, and extremely easy to develop in. In addition, Python is also an Object Orientated language, though it is worth noting that Python is extremely strict on indentation, and all python indents should be 4 character space in length.

Python development is as easy as typing python into your terminal (Linux/Unix boxes utilise python scripts, therefore some version of python will already by installed on them)

rorie@boo:~$ python
Python 2.6.5 (r265:79063, Apr 16 2010, 13:09:56)
[GCC 4.4.3] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.

this is the python interpreter, we can run commands straight from here, or we can save them with the .py extension and run it as a script

>>>print “hello”


Ok, so that was easy. It was also pretty boring…

The really amazing thing about python is the amount of different frameworks and API’s built on top of it. I want to show you some of the cross platform frameworks built on top of python, and just how easy they are to use thanks to awesome pythonic coding.

Scapy – Scapy is a packet manipulation tool. It allows you to literally build a packet from the ground up, as well as send an receive them. If installed from the Ubuntu repository the set-up of the environment variables is done for you and we can jump right in.

rorie@boo:~$ sudo scapy
[sudo] password for rorie:
INFO: Can’t import python gnuplot wrapper . Won’t be able to plot.
INFO: Can’t import PyX. Won’t be able to use psdump() or pdfdump().
WARNING: No route found for IPv6 destination :: (no default route?)
Welcome to Scapy (2.0.1)
>>> IP(dst=”″, src=”″/TCP(dport=[80

We can ignore the info messages as what we are using scapy for does not require the additional packages. We can easily create a ping packet as follows:

>>>packet = IP(dst=”″, src=”″)/TCP(dport=[80])

and we can send it with

<IP  version=4L ihl=5L tos=0x0 len=44 id=0 flags=DF frag=0L ttl=64 proto=tcp chksum=0xb619 src= dst= options=” |<TCP  sport=www dport=ftp_data seq=4256930905L ack=1 dataofs=6L reserved=0L flags=SA window=5840 chksum=0x6219 urgptr=0 options=[(‘MSS’, 1460)] |>>

You need to remembers that packets are build out of headers. Since TCP and IP are actually different headers, we need to create them separately and put them together. The source is the local machines IP, and in this case the destination is the local router.

Scapy’s sr (send an receive) function sends your packet, the waits for a reply.

Lets take a look at doing this again, but for IPv6.

>>> a = IPv6(dst=”fe80::20c:29ff:fe5f:f12″,src=”fe80::20c:29ff:fe51:5e07″)/ICMPv6EchoRequest()
>>> sr1(a)
Begin emission:
*Finished to send 1 packets.

Received 1 packets, got 1 answers, remaining 0 packets
<IPv6  version=6L tc=0L fl=0L plen=8 nh=ICMPv6 hlim=64 src=fe80::20c:29ff:fe5f:f12 dst=fe80::20c:29ff:fe51:5e07 |<ICMPv6EchoReply  type=Echo Reply code=0 cksum=0xbfd9 id=0x0 seq=0x0 |>>

This demonstration is by no means a detailed description of what scapy, or indeed python can do. But I hope it has been a nice little last of it. This is the first, in what will be a serious of tutorials I will release involving the use of python.

P.S – I am no way near done with Scapy, and there is alot more coming shortly!



Recently I have ventured out into the abyss of Operating system. Normally I run Ubuntu  Linux, and i really only ever use Windows for Microsoft Office (I find it better than OpenOffice). My new toy is OpenBSD, though I have also played around with FreeBSD. There are three main BSD distributions; OpenBSD, FreeBSD and NetBSD. BSD distributions are Unix-like operating system that are well known for security (arguably because no knows or uses them except geeks). Bsd distributions feature a fantastic system known as the ports collection. Each ports collection is a set of 3rd party application selected for BSD by the distributions developers. A directory in the file-system hierarchy is created for every application in the ports collection. These directory’s do not initially contain the applications, but instead it contains a makefile that stores information on where the binary can be found, and the configuration data. By switching to the pre-made directory of an application you want but do not yet have, and issuing the Unix “make” command, the application is automatically downloaded and installed for you in the directory. Thinking about it, i cant say that it is any better than the package manager in Ubuntu, though it does feel alot more fluent. More to come on my BSD experience as it happens.

Just what is it about Linux?

So Ryan and I were touring around prospective students today, and I couldn’t help but find myself preaching to them. In the end all it would do is benefit them (I guess that what all preachers say). Never the less it seems safe to say that Hackers love Linux. Thinking back to it I’m not sure that most of them will even knew what Linux is. When is was in that position, I knew what it was, though beyond that it was an operating system my knowledge was shamefully bare. But why do we like Linux? Yes it is open, and yes it is free, but so are most UNIX distribution. Surely it has to be more than that? Personally I enjoy the ease of it. The idea behind it makes sense; a system that I can change and redistribute till my heart is content. Having played about with the kernel components of Linux for a time now, I can honestly say that I actually enjoy the kernel. All of the header files are easily accessible (and alterable), and including your own headers is easy once you know what you are doing. Kernel modules are an excellent way of loading in drivers, or other software that you need running in the kernel (rootkits anyone?) Linux just ticks all of my boxes, and while I don’t dislike Windows, I find it a system that I use on a less frequent basis (avoiding proprietary format that force you to use Windows.) I guess the fact stands, penguins rock.