03.09.2013 Views

Implementation of data collection tools using NetFlow for statistical ...

Implementation of data collection tools using NetFlow for statistical ...

Implementation of data collection tools using NetFlow for statistical ...

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Basic level CDT307<br />

<strong>Implementation</strong> <strong>of</strong> <strong>data</strong> <strong>collection</strong> <strong>tools</strong> <strong>using</strong> <strong>NetFlow</strong><br />

<strong>for</strong> <strong>statistical</strong> analysis at the ISP level<br />

Bachelor's Thesis in Computer Science<br />

by<br />

Daniel Karlström<br />

Department <strong>of</strong> Innovation, Design and Engineering Akademin för Innovation, Design och Teknik<br />

Mälardalen University Mälardalens Högskola<br />

SE-722 18 Västerås, Sweden 722 18 Västerås


<strong>Implementation</strong> <strong>of</strong> <strong>data</strong> <strong>collection</strong> <strong>tools</strong> <strong>using</strong> <strong>NetFlow</strong><br />

<strong>for</strong> <strong>statistical</strong> analysis at the ISP level<br />

by<br />

Daniel Karlström<br />

Supervisors: Stefan Löfgren<br />

Mälardalen University, IDT<br />

Fredrik Holmqvist<br />

Examiner: Mats Björkman<br />

Västerås, May 23 rd , 2012<br />

Internet 2 Business KB


Abstract<br />

Defending against Dos- and DDoS attacks is difficult to accomplish; finding and filtering out<br />

illegitimate traffic from the legitimate flow is near impossible. Taking steps to mitigate or even<br />

block the traffic can only be done once the IP addresses <strong>of</strong> the attackers are known. This is<br />

achievable by monitoring the flows to- and from the target and identifying the attacker's IP<br />

addresses, allowing the company or their ISP to block the addresses itself by blackholing them (also<br />

known as a null route).<br />

Using the IP accounting and monitoring tool “pmacct”, this thesis aims to investigate whether or not<br />

the pmacct suite is suited <strong>for</strong> larger installations when tracking and mitigating DDoS-attacks, such<br />

at an Internet Service Provider (ISP). Potential problems are the amount <strong>of</strong> traffic that need to be<br />

analyzed and the computational power required to do it. This thesis also provide in<strong>for</strong>mation about<br />

the pmacct suite at large.<br />

The conclusions are positive, indicating it does scale up to handle larger installations when given<br />

careful consideration and planning.<br />

1


Sammanfattning<br />

Att försvara sig mot DoS-och DDoS-attacker är svårt att åstadkomma; att hitta och filtrera ut<br />

illegitim trafik från det legitima flödet är nästan omöjligt. Att vidta åtgärder när en sådan attack<br />

upptäcks kan endast göras när IP-adresserna från angriparna är kända. Detta kan uppnås genom att<br />

man övervakar trafikflödet mellan målet för attacken och angriparna och ser vilka som sänder mest<br />

<strong>data</strong> och på så sätt identifierar angriparna.. Detta tillåter företaget eller dess ISP att blockera trafiken<br />

ifrån dessa IP-adresser genom att sända trafiken vidare till ingenstans. Detta kallas blackholerouting<br />

eller null-routing.<br />

Genom att använda redovisnings- och övervakningsprogrammet pmacct syftar denna uppsats på att<br />

undersöka hurvida pmacct-sviten är lämpad för större installationer när det gäller att spåra och<br />

förhindra DDoS-attacker, såsom hos en Internetleverantör eller dylikt. Potentialla problem som kan<br />

uppstå är att mängden trafik som måste analyserar blir för stor och för krävande. Denna avhandling<br />

går även igenom pmacct-verktyget i sig.<br />

Slutsatserna är lovande, vilket indikerar att den har potential av att kunna hantera sådana stora<br />

miljöer med noggrann planering.<br />

2


Acknowledgments<br />

I would like to thank Fredrik Holmqvist, Internet 2 Business KB, who was my supervisor at the<br />

company, and also to thank the company at large <strong>for</strong> creating the opportunity <strong>for</strong> me to make this<br />

bachelor's thesis. Fredrik, and others at the company, were always been willing to <strong>of</strong>fer a helping<br />

hand and provide in<strong>for</strong>mation when needed.<br />

Many thanks as well to my supervisor Stefan Löfgren at the Department <strong>of</strong> Innovation, Design and<br />

Engineering at Mälardalen University. His guidance helped shape this report, vastly improving it<br />

into what you now see be<strong>for</strong>e you.<br />

Last but not least, I would like to reach out and thank Paolo Lucente, the creator <strong>of</strong> the pmacct suite,<br />

upon which this thesis is based. His advice over continuous mail correspondence regarding<br />

configuration issues were essential and his eagerness to help people should be recognized.<br />

3


Table <strong>of</strong> Contents<br />

Abstract..............................................................................................................................................1<br />

Sammanfattning................................................................................................................................2<br />

Acknowledgments..............................................................................................................................3<br />

1 Introduction....................................................................................................................................11<br />

1.1 Thesis background...................................................................................................................11<br />

1.2 Related work............................................................................................................................12<br />

1.3 Problem <strong>for</strong>mulation................................................................................................................12<br />

1.4 Purpose.....................................................................................................................................12<br />

1.5 S<strong>of</strong>tware used...........................................................................................................................12<br />

1.6 Organization.............................................................................................................................13<br />

1.7 Limitations...............................................................................................................................13<br />

2 Theoretical background................................................................................................................15<br />

2.1 Internet Protocol......................................................................................................................15<br />

2.2 Apache HTTP Server ..............................................................................................................16<br />

2.3 Autonomous Systems...............................................................................................................16<br />

2.4 <strong>NetFlow</strong>...................................................................................................................................18<br />

2.5 sFlow........................................................................................................................................19<br />

2.6 IPFIX.......................................................................................................................................19<br />

2.7 Linux........................................................................................................................................20<br />

2.7.1 Ubuntu.............................................................................................................................20<br />

2.7.2 Cron.................................................................................................................................20<br />

2.7.3 Scripting..........................................................................................................................21<br />

2.7.4 Libpcap............................................................................................................................22<br />

2.8 Quagga.....................................................................................................................................22<br />

2.9 MRTG......................................................................................................................................23<br />

2.10 pmacct....................................................................................................................................24<br />

2.11 Baselining..............................................................................................................................24<br />

3 Problem analysis............................................................................................................................25<br />

3.1 Collecting the <strong>data</strong>...................................................................................................................25<br />

3.1.1 Protocol decision.............................................................................................................25<br />

3.1.2 Choice <strong>of</strong> <strong>NetFlow</strong>-collector...........................................................................................25<br />

3.1.3 Network configuration....................................................................................................25<br />

3.2 Storing the <strong>data</strong> .......................................................................................................................25<br />

3.3 Displaying the <strong>data</strong> .................................................................................................................26<br />

4 <strong>Implementation</strong>..............................................................................................................................27<br />

4.1 Choice <strong>of</strong> method.....................................................................................................................27<br />

4.1.1 Collecting the <strong>data</strong>..........................................................................................................27<br />

4.1.2 Storing the <strong>data</strong> ..............................................................................................................29<br />

4.1.3 Displaying the <strong>data</strong>..........................................................................................................29<br />

4.2 Method criticism......................................................................................................................29<br />

4.3 Solution....................................................................................................................................30<br />

4.3.1 Collecting the <strong>data</strong> - solution..........................................................................................30<br />

4.3.2 Storing the <strong>data</strong> – solution..............................................................................................33<br />

4.3.3 Displaying the <strong>data</strong> – solution.........................................................................................35<br />

4.4 Problems .................................................................................................................................36<br />

4.4.1 Problem with collecting the <strong>data</strong> ....................................................................................36<br />

4


4.4.2 Problems with storing the <strong>data</strong> .......................................................................................37<br />

4.4.2.1 pmacct .....................................................................................................................38<br />

4.4.2.2 MySQL.....................................................................................................................38<br />

4.4.2.3 Execution time <strong>of</strong> said custom-made script.............................................................38<br />

4.4.3 Problems with displaying the <strong>data</strong>..................................................................................39<br />

4.4.3.1 MRTG graphing incorrectly.....................................................................................39<br />

5 Results.............................................................................................................................................42<br />

5.1 Analysis <strong>of</strong> results....................................................................................................................42<br />

5.2 Recommendations....................................................................................................................43<br />

5.3 Future work..............................................................................................................................43<br />

6 Summary and conclusions............................................................................................................44<br />

7 References.......................................................................................................................................45<br />

8 Appendix.........................................................................................................................................51<br />

8.1 E-mail conversation with Paolo Lucente.................................................................................51<br />

8.2 Enabling <strong>NetFlow</strong> on Cisco devices........................................................................................52<br />

8.3 Configuration <strong>of</strong> <strong>NetFlow</strong> on the small router.........................................................................52<br />

8.4 Configuration <strong>of</strong> Quagga.........................................................................................................52<br />

8.5 Configuration <strong>of</strong> pmacct..........................................................................................................53<br />

8.5.1 agent.map........................................................................................................................54<br />

8.5.2 pretag.map.......................................................................................................................54<br />

8.6 Bash Script...............................................................................................................................54<br />

8.7 Python Script............................................................................................................................54<br />

8.8 Script <strong>for</strong> MRTG......................................................................................................................55<br />

8.9 Custom-made script to push the <strong>data</strong> into the <strong>data</strong>base...........................................................56<br />

8.10 RRDTOOL-script (rrdtool.sh)..............................................................................................58<br />

5


6<br />

Listen to the music, not the song


Definitions & Terminology<br />

AS / ASn Autonomous System Number, a unique identifier which every organization<br />

must have in order to be part <strong>of</strong> the Internet. Prominently used by Internet<br />

Service Providers (ISPs)<br />

BGP Border Gateway Protocol (BGP) is the routing protocol used between<br />

Internet Service Providers and similar large installations.<br />

Cacti Cacti is an open source web-based network monitoring and graphing tool.<br />

Datagram Blocks <strong>of</strong> <strong>data</strong>.<br />

Default route A default route is a term <strong>for</strong> a packet <strong>for</strong>warding rule which occurs when no<br />

other route can be determined <strong>for</strong> a particular address. Also called a gateway.<br />

DoS Denial <strong>of</strong> Service, an attack that consists <strong>of</strong> overwhelming the target with<br />

in<strong>for</strong>mation.<br />

DDoS Distributed Denial <strong>of</strong> Service, an escalated version <strong>of</strong> DoS-attacks that<br />

utilizes several computers working in unison to attack a target.<br />

GNS3 An add-on <strong>for</strong> Dynamips, which emulates Cisco routers.<br />

Header The part <strong>of</strong> an IP packet which contains routing-relevant in<strong>for</strong>mation, such as<br />

protocol version, time to live be<strong>for</strong>e it gets discarded, source- and destination<br />

address<br />

HTTP Hypertext Transfer Protocol, the protocol used <strong>for</strong> browsing web pages when<br />

surfing on the web.<br />

HTTPS A derivative <strong>of</strong> the HTTP protocol, the HTTPS adds a layer <strong>of</strong> security by<br />

encrypting traffic between the sender and receiver.<br />

IETF Internet Engineering Task Force.<br />

IGP An interior gateway protocol (IGP) is a routing term regarding protocols that<br />

is used to exchange routing in<strong>for</strong>mation within an autonomous system.<br />

Examples <strong>of</strong> these are RIP, OSPF, IS-IS.<br />

IPFIX A network protocol developed <strong>for</strong> collecting IP traffic in<strong>for</strong>mation, created<br />

by the IEFF in an attempt to unite the different flow protocols into a universal<br />

united standard.<br />

ISP Internet Service Provider.<br />

Layer 3 routing Routing on layer 3 <strong>of</strong> the OSI model means that the routing decisions use IP<br />

addresses to reach the desired networks.<br />

MySQL Open source <strong>data</strong>base system.<br />

MRTG Monitoring tool <strong>for</strong> the traffic load (usage) on network links.<br />

7


MySQL A relational <strong>data</strong>base management system; currently the world's most used<br />

RDBMS.<br />

<strong>NetFlow</strong> A network protocol developed <strong>for</strong> collecting IP traffic in<strong>for</strong>mation. Only<br />

available on Cisco devices.<br />

Null route Also called a blackhole route, a null route is a route that goes nowhere, in<br />

effect discarding packets from a particular network. An example <strong>of</strong> discarding<br />

traffic from the network 192.168.1.0 / 24 on Cisco IOS is as follows:<br />

ip route 192.168.1.0 255.255.255.0 null0<br />

OSI model A standardized method <strong>of</strong> viewing the functions <strong>of</strong> a communications system<br />

by separating them into different layers.<br />

IPv4 Internet Protocol version 4, the most commonly used inter-networking<br />

method <strong>of</strong> communicating on the Internet.<br />

IPv6 Internet Protocol version 6, the next step up from IPv4.<br />

pmacct The name <strong>of</strong> the program suite as well as a tool in the suite itself. Other<br />

included <strong>tools</strong> are nfacct, IPFIX, sfacct and uacct.<br />

Quagga An open source network routing s<strong>of</strong>tware suite providing implementations <strong>of</strong><br />

OSPF, RIP, BGP and IS-IS <strong>for</strong> Unix-like systems.<br />

Route A route is used by routers and contain the best road <strong>for</strong> traffic to take in order<br />

to get from network A to network B.<br />

Router A device that <strong>for</strong>wards <strong>data</strong> packets between computer networks.<br />

Router, core A core router is a router that is designed to operate in the network's backbone,<br />

or core. All the traffic from the network will flow through here, with the core<br />

router sending the packets to their destination.<br />

RRDtool Being an acronym <strong>for</strong> round-robin <strong>data</strong>base tool, RRDtool is designed to be a<br />

tool used <strong>for</strong> handling time-sensitive <strong>data</strong> such as bandwidth-<strong>data</strong>,<br />

temperatures and so on. Stores in<strong>for</strong>mation in a round-robin <strong>data</strong>base.<br />

sFlow A network protocol developed <strong>for</strong> collecting IP traffic in<strong>for</strong>mation. Unlike<br />

<strong>NetFlow</strong>, sFlow is available on a multitude <strong>of</strong> device manufacturers.<br />

SQL Structured Query Language. A programming language designed <strong>for</strong> managing<br />

<strong>data</strong> in an RDBMS.<br />

TCP Transmission Control Protocol.<br />

Tier 2 Carrier An ISP who peers with some networks but still purchase IP transit from<br />

others to reach the rest <strong>of</strong> the Internet.<br />

TOS Type <strong>of</strong> Service, a field in the header <strong>of</strong> an IPv4 packet.<br />

UDP User Datagram Protocol.<br />

8


VirtualBox Virtualization s<strong>of</strong>tware <strong>for</strong> Operating Systems.<br />

VMware Virtualization s<strong>of</strong>tware <strong>for</strong> Operating Systems.<br />

9


1 Introduction<br />

1 Introduction<br />

This introductory chapter will describe the background <strong>of</strong> this thesis, as well what earlier work has<br />

been made in this area. The problem will be <strong>for</strong>mulated followed by the objectives <strong>of</strong> the thesis<br />

work. With this defined, the different methods will be presented and evaluated. Towards the end <strong>of</strong><br />

the chapter the structure <strong>of</strong> the project such as organization, limitations and the outline <strong>of</strong> the rest <strong>of</strong><br />

the report will be described.<br />

1.1 Thesis background<br />

The need <strong>for</strong> protection against cyber attacks increase every day with more and more companies<br />

tied to the Internet even tighter than be<strong>for</strong>e [1]. Internet has become a reliable medium in which one<br />

needs to be seen in able to compete. Various security measures exists today to secure and harden a<br />

company network and its perimeter to the outside world, in case <strong>of</strong> an attack. These attacks vary<br />

both in difficulty and execution time. Attacks might start with reconnaissance, which could be as<br />

simple as dropping a few infected USB memory sticks on the parking lot in an attempt to get an<br />

inside look <strong>of</strong> the network. Attacks in particular that are hard to protect oneself against however, are<br />

the so called Denial <strong>of</strong> Service (DoS) or Distributed Denial <strong>of</strong> Service (DDoS) attacks [3]. These<br />

types <strong>of</strong> attacks aim to flood the targeted server(s) with bogus traffic in an attempt to overwhelm its<br />

resources. If an attacker simultaneously sends a large amount <strong>of</strong> requests to a web server, it has to<br />

respond to all those requests. This <strong>for</strong>ces legitimate requests to be put on hold, as the server is busy<br />

handling a massive amount <strong>of</strong> fake requests. If the stream <strong>of</strong> requests from the attacker does not<br />

cease and the server is kept busy the users would experience the site as slow or unresponsive.<br />

Another type <strong>of</strong> attack involves starting a connection and not completing it, leaving it in a half-open<br />

state. When a TCP connection is made, the client start by sending a SYN (synchronize) packet to<br />

the server. The server respond with a SYN-ACK (synchronize acknowledgment), confirming the<br />

request. Finally the client sends its own ACK, confirming the connection. The server waits until it<br />

receives the final acknowledgment, however if a client omits to send it the server will in turn be<br />

kept in a waiting state <strong>for</strong>ever, and thereby tying up resources. If enough connections are made, its<br />

resources will be exhausted and unable to process legitimate requests. [24]<br />

One method <strong>of</strong> mitigating the effects from these type <strong>of</strong> attacks is to identify the IP addresses <strong>of</strong> the<br />

attackers involved and block them from the network. In order to accomplish this one needs to<br />

collect traffic in<strong>for</strong>mation from the network, separating bogus traffic from legitimate traffic and act<br />

accordingly.<br />

One suite <strong>of</strong> such <strong>data</strong> collecting <strong>tools</strong> is called pmacct [4], which is a collector <strong>for</strong> network traffic<br />

in<strong>for</strong>mation. It works by collecting in<strong>for</strong>mation from senders and recipients throughout the network,<br />

including the source- and destination address. With the added feature <strong>of</strong> being able to track BGP<br />

AS-numbers, aggregating all flows from a particular ISP would effectively monitor traffic sent to-<br />

and from that ISP. The pmacct suite will be evaluated at an Internet Service Provider <strong>for</strong> testing and<br />

evaluation. It will first be implemented and configured on a small scale in their network and then<br />

evaluated. If the results are positive, pmacct will then be implemented throughout their entire core<br />

network.<br />

The testing will take place in Stockholm, at an Internet Service Provider called Internet 2 Business<br />

KB (I2B). Internet 2 Business Sverige KB was founded at the second half <strong>of</strong> 2009 by Fredrik<br />

11


1 Introduction<br />

Holmqvist, who still remain at the company as its CEO at present date. Situated in Stockholm,<br />

Sweden, their network consist <strong>of</strong> about 120 devices (switches / routers) in several different<br />

countries including Norway, Denmark, England, Germany and Holland. Their primary clients<br />

consist <strong>of</strong> corporations, other ISP's and organizations.<br />

1.2 Related work<br />

There are instances <strong>of</strong> pmacct being used by individual people or small businesses. There are<br />

however fewer instances <strong>of</strong> pmacct being implemented in larger installations, although it has been<br />

successfully done. As mentioned by the creator <strong>of</strong> pmacct, Paolo Lucente, once such a case study<br />

has been done the results are usually kept secret by the company in question. A company might not<br />

want to expose the topology <strong>of</strong> their network since it poses a security risk (see the appendix, chapter<br />

8.1).<br />

Chris Wilson wrote a report about bandwidth management <strong>for</strong> AfNOG in 2010<br />

(https://nsrc.org/workshops/2010/nsrc-unan-leon/raw-attachment/wiki/Agenda/afnog-bmopresentation-2010.pdf)<br />

in which he displayed a working configuration.<br />

1.3 Problem <strong>for</strong>mulation<br />

The issue at hand is to determine whether or not pmacct is suitable <strong>for</strong> larger installations when it<br />

comes to collecting network traffic in<strong>for</strong>mation aimed towards mitigating DDoS attacks. It will<br />

investigate if it scales with the company as it grows and if the hardware requirements scale at the<br />

same pace. This thesis will also provide in<strong>for</strong>mation about the pmacct suite at large.<br />

1.4 Purpose<br />

The purpose <strong>of</strong> this thesis is to investigate whether or not pmacct is a viable option <strong>for</strong> gathering<br />

network traffic on larger installations, i.e, at an Internet Service Provider (ISP). <strong>Implementation</strong> <strong>of</strong><br />

both IPv4 and IPv6 is desired, with IPv4 having higher priority. Additionally, the pmacct tool as a<br />

<strong>NetFlow</strong>-collector in junction with MRTG will be implemented <strong>for</strong> visual presentation <strong>of</strong> the <strong>data</strong>.<br />

Choosing to implement this at an ISP is ideal both due to its size and its complexity and will<br />

hopefully provide a definitive resolution to the question at hand.<br />

1.5 S<strong>of</strong>tware used<br />

The following s<strong>of</strong>tware <strong>tools</strong> was used in this thesis; <strong>tools</strong> chosen <strong>for</strong> their ease <strong>of</strong> use and<br />

familiarity.<br />

12<br />

S<strong>of</strong>tware Purpose<br />

Bash Scripting language<br />

GNS3 Router emulator s<strong>of</strong>tware<br />

Linux (Ubuntu) Operating System


1 Introduction<br />

1.6 Organization<br />

MRTG Load monitoring and<br />

graphing s<strong>of</strong>tware<br />

OpenOffice Word processing<br />

pmacct Network traffic collector<br />

PuTTY SSH client<br />

Python Scripting language<br />

Quagga Routing s<strong>of</strong>tware suite<br />

RRDTOOL Creating files <strong>for</strong> MRTG<br />

VMware OS Virtualization s<strong>of</strong>tware<br />

TShark Network protocol analyzer<br />

phpMyAdmin Web-based MySQL<br />

administration<br />

This bachelor's thesis was made <strong>for</strong> Internet 2 Business KB (simply referred to as as I2B in this<br />

thesis), from which much guidance has been provided. Theoretical knowledge and experience have<br />

<strong>for</strong>emost been provided by the division <strong>of</strong> Innovation, Design and Engineering at Mälardalen<br />

University.<br />

1.7 Limitations<br />

Network monitoring s<strong>of</strong>tware is a large chapter in itself, touching many aspects <strong>of</strong> computer<br />

science. It is because <strong>of</strong> this a set <strong>of</strong> limitations must be en<strong>for</strong>ced; the project is limited to a total <strong>of</strong><br />

10 weeks <strong>of</strong> full-time work, with a few set aside <strong>for</strong> the report itself.<br />

• This thesis will focus primarily on IPv4 while only grazing the subject <strong>of</strong> IPv6; there was<br />

not enough time to complete both.<br />

• This thesis will implement a 'pro<strong>of</strong> <strong>of</strong> concept'-solution on a small router and then migrate<br />

this configuration to the core router, should it scale appropriately.<br />

13


1 Introduction<br />

14


2 Theoretical background<br />

2 Theoretical background<br />

In this chapter, the various technologies used in the implementation section <strong>of</strong> this thesis will be<br />

described.<br />

2.1 Internet Protocol<br />

The Internet Protocol (IP) is the most commonly used protocol <strong>for</strong> sending <strong>data</strong>grams from, to and<br />

between networks. IP addresses are used by routers and routing protocols to send traffic from the<br />

source host to the destination host, <strong>using</strong> the best path available.<br />

Illustration 1: IP traffic overview - sending <strong>data</strong> from host A to host B<br />

IPv4<br />

As specified by the IETF in 1981 in RFC791 [16], the IPv4 protocol is the fourth revision <strong>of</strong> the<br />

Internet Protocol and was drafted in 1981. It is still the most commonly used Internet Layer<br />

protocol as <strong>of</strong> 2012. Based on a 32-bit addressing scheme, IPv4 allows <strong>for</strong> a maximum <strong>of</strong> 2 32<br />

(4,294,967,296) unique addresses. An address is divided into four sections, each dot-separated, with<br />

each section containing an 8-digit number. This is the reason a section is also referred to as an octet.<br />

These numbers are in turn in the range <strong>of</strong> 0 to 255, or written in binary, 00000000 to 11111111.<br />

The header <strong>of</strong> an IPv4 packet is embedded in every packet sent and received; even if several<br />

packets are destined <strong>for</strong> the same host. This help to decrease the chances <strong>of</strong> packet loss due to a<br />

downed router along the way, as the packets will just take another route and be inspected <strong>for</strong> their<br />

destination. Below is a graphical display <strong>of</strong> the different fields that make up the IPv4 header, with<br />

in<strong>for</strong>mation relevant to <strong>NetFlow</strong> color coded:<br />

Version IHL DSCP ECN Total length<br />

Identification Flags Fragment Offset<br />

Time To Live Protocol Header Checksum<br />

Source IP address<br />

Destination IP address<br />

Options (rarely used)<br />

Due to its limitations in itself and the massive increase in network-capable devices, i.e. laptops and<br />

15


2 Theoretical background<br />

hand held devices, the number <strong>of</strong> allocated IP address blocks reached it peak in 2011 when the last<br />

free block was allocated [17][18].<br />

IPv6<br />

Continuing the specifications by IETF, Internet Protocol revision six was drafted in the year 1998, a<br />

full 17 years after its predecessor's creation date. Now based on a 128-bit addressing scheme, IPv6<br />

allows <strong>for</strong> a maximum <strong>of</strong> 2 128 (3.4⋅10 38 ) addresses [19]. An address is divided into 8 sections by<br />

a colon, with a four-digit hexadecimal number in each section. These addresses can be shortened by<br />

reducing groups <strong>of</strong> four-digit zeroes to a single zero or removed altogether.<br />

2.2 Apache HTTP Server<br />

The Apache HTTP Server is a web server application, serving users web pages over HTTP. It is<br />

released free <strong>of</strong> charge and is developed and maintained by the Apache S<strong>of</strong>tware Foundation. The<br />

Apache server itself runs on most operating systems, including Unix- and Linux variants as well as<br />

Micros<strong>of</strong>t Windows. It contains a core program which handles the requests and extends features by<br />

<strong>using</strong> modules, and is as such both memory efficient and modular. [31]<br />

The Apache web server is used in over 448 million sites all over the world with a market share <strong>of</strong><br />

over 64% as <strong>of</strong> March 2012 according to the site Netcraft.com [32].<br />

2.3 Autonomous Systems<br />

An ISP must have at least one Autonomous System (AS) in order to be part <strong>of</strong> the Internet. Some<br />

larger ISP's even have several. These ASes are used to mark the boundaries <strong>of</strong> any particular ISP;<br />

which networks fall under a particular ISP's administration and which does not, what the routing<br />

policy is <strong>for</strong> the networks in question and so on [20]. Routing between different ASes is done with a<br />

Exterior Gateway Protocol (EGP) while the internal traffic within an AS is routed by <strong>using</strong> an<br />

Interior Gateway Protocol (IGP). The most prominent EGP protocol is the Border Gateway<br />

Protocol, or BGP <strong>for</strong> short [21][22]. Despite BGP being able to route traffic between ASes, it is also<br />

capable <strong>of</strong> routing inside the AS itself. It is in these situations called External BGP (EBGP) and<br />

Internal BGP (IBGP), respectively. Routing IGP traffic is however usually left to other protocols<br />

partly due to faster convergence, such as OSPF [23] or IS-IS [25].<br />

16<br />

Illustration 2: Shortening an address by removing zeroes


2 Theoretical background<br />

RFC 1930 provide guidelines in the decision-making <strong>of</strong> whether or not one would need an own<br />

public AS. In essence, it is only needed if the AS is connected to other ASes (i.e. multi-homed) or if<br />

the routing policy differs from the service provider. If not, the AS should be placed in an AS <strong>of</strong> the<br />

provider. [20]<br />

“An AS is a connected group <strong>of</strong> one or more IP prefixes run by one or more network operators<br />

which has a SINGLE and CLEARLY DEFINED routing policy.” [20]<br />

BGP<br />

BGP is the primary routing protocol on the Internet and the most commonly used <strong>for</strong> EGP routing.<br />

It became the most prominent protocol partly <strong>for</strong> being a very reliable protocol as well as being<br />

very scalable. As <strong>of</strong> this thesis, the BGP routing table consists <strong>of</strong> just above 400.000 routes (see<br />

illustration 14). BGP is also able to merge several routes into one or more routes in a process called<br />

supernetting, which saves memory by keeping the size <strong>of</strong> the routing table down.<br />

As an EGP routes between ASes, the amount <strong>of</strong> network chatter must be kept to a minimum to<br />

allow <strong>for</strong> better use <strong>of</strong> the available bandwidth. This is why BGP, unlike some protocols, do not<br />

send periodic updates about the network topology. BGP instead notifies its neighbors about a<br />

downed network when the event occurs. This method <strong>of</strong> updating the network topology is known as<br />

triggered updates.<br />

BGP works by establishing connections to other BGP neighbors, called peers, on TCP port 179.<br />

Once successful, BGP begins by transmitting its entire routing table to its neighbor, unless stated<br />

otherwise. Any further updates will be by triggered events only. It sends a keep-alive message every<br />

30 seconds to ensure the connectivity <strong>of</strong> its neighbors. If the timers expire and no connection to a<br />

neighbor is re-established, the route is marked as down and removed from the routing table<br />

followed by a triggered update to its neighbors.<br />

BGP differs from the other routing protocols by neither being classified as a distance-vector<br />

protocol or a link state-protocol. BGP bases its routing decisions on attributes instead. These<br />

attributes are divided into groups <strong>of</strong> well known mandatory and discretionary [54][55]:<br />

• Well known mandatory<br />

Must appear in every UPDATE message and must be supported by every BGP s<strong>of</strong>tware<br />

implementation.<br />

• AS_PATH: The AS_PATH attribute is a list <strong>of</strong> all the ASes a particular route has to take<br />

to reach its destination. Separated by spaces, this list can contain several ASes if the<br />

distance is big enough.<br />

• ORIGIN: The origin attribute indicates how BGP learned about a particular route.<br />

Allowed values are IGP, EGP or Incomplete.<br />

• NEXT-HOP: The EBGP next-hop attribute is the IP address that is used to reach the<br />

advertising router.<br />

17


2 Theoretical background<br />

• Well known discretionary<br />

May or may not appear in every UPDATE message, but must nonetheless be supported.<br />

• LOCAL_PREF: Used by a BGP peer to prefer a specific exit point from the local AS if<br />

there are several to choose from. This in<strong>for</strong>mation is propagated to peers in the UPDATE<br />

message.<br />

• ATOMIC_AGGREGATE: Alerts BGP speakers along the path that some in<strong>for</strong>mation<br />

have been lost due to route aggregation (supernetting).<br />

The most commonly used version is version 4, which added support <strong>for</strong> supernetting and CIDR.<br />

Support <strong>for</strong> IPv6 exists as well. [22]<br />

2.4 <strong>NetFlow</strong><br />

<strong>NetFlow</strong> was a protocol originally developed by Cisco Systems® in 1996 to collect IP traffic<br />

in<strong>for</strong>mation. It can answer questions such as who the top bandwidth users are, what applications<br />

they use and what percentage <strong>of</strong> traffic they use by sending the in<strong>for</strong>mation to a collector [26] [45].<br />

<strong>NetFlow</strong> is a tool which can be used <strong>for</strong> mitigating DoS attacks since the traffic is actively being<br />

monitored. <strong>NetFlow</strong> does this by recording IP traffic statistics and exporting them as flows to a<br />

collector <strong>for</strong> analysis. A flow is a set <strong>of</strong> <strong>data</strong> packets which share common characteristics, such as<br />

packets coming from the same source and heading <strong>for</strong> the same destination. Cisco deem that the<br />

following characteristics must match in order <strong>for</strong> it to be classified as a flow [2]:<br />

18<br />

1. Ingress interface<br />

2. Source IP address<br />

3. Destination IP address<br />

4. IP protocol<br />

5. Source port <strong>for</strong> UDP or TCP protocols, 0 <strong>for</strong> other protocols<br />

6. Destination port <strong>for</strong> UDP or TCP protocols, 0 <strong>for</strong> other protocols<br />

7. IP Type <strong>of</strong> Service (TOS)


2 Theoretical background<br />

Illustration 3: <strong>NetFlow</strong> overview<br />

It is worth mentioning that a TCP header is only 20 bytes in size [51].<br />

See appendix 8.2 <strong>for</strong> in<strong>for</strong>mation on how to configure <strong>NetFlow</strong> on Cisco devices.<br />

2.5 sFlow<br />

Much like <strong>NetFlow</strong>, sFlow collects network traffic in<strong>for</strong>mation <strong>for</strong> use in monitoring the network. It<br />

is an industry standard, which means it is supported on a majority <strong>of</strong> devices. It too sends network<br />

traffic in<strong>for</strong>mation to a collector <strong>for</strong> further analysis. This collector is a computer running any <strong>of</strong> the<br />

many available programs <strong>for</strong> gathering flow-<strong>data</strong>. It works by sampling the network traffic – that is,<br />

it tags packets, one out <strong>of</strong> every N packets, and send it to the collector. The marked packet's header<br />

in<strong>for</strong>mation is saved into a new packet and sent to the collector once it reaches 1500 bytes (the<br />

maximum size <strong>for</strong> a packet). Along with the header in<strong>for</strong>mation from packets, in<strong>for</strong>mation about the<br />

sampling rates and interface id are also included. This type <strong>of</strong> sampling is called random sampling.<br />

The other type <strong>of</strong> sampling method involves basing the samples on a time-based polling interval<br />

and is called counter sampling. [39] [40] [41] [42] [43][46]<br />

2.6 IPFIX<br />

Internet Protocol Flow In<strong>for</strong>mation Export (IPFIX) is a protocol created by the IETF in an attempt<br />

to create a common universal standard <strong>for</strong> flow in<strong>for</strong>mation from routers and other devices,<br />

eliminating the need <strong>for</strong> a specific vendor to create a version <strong>of</strong> its own [44]. Being based on Cisco's<br />

<strong>NetFlow</strong> version 9, the characteristics <strong>for</strong> defining a flow are the same - same source, same<br />

19


2 Theoretical background<br />

destination and so on.<br />

2.7 Linux<br />

Linux is a Unix-like kernel originally developed by Linus Torvalds while he was a student at the<br />

University <strong>of</strong> Helsinki. It was <strong>of</strong>ficially released on October 5 th , 1991 as open source s<strong>of</strong>tware.<br />

Linux teamed up with the GNU system which supplied programs such as the X Window System,<br />

the BASH shell and other various programs. Together they <strong>for</strong>med a complete Operating System<br />

with Linux as the underlying kernel. Linux is licensed under the GNU General Public License and<br />

are together called GNU/Linux. [29]<br />

There are several different distributions <strong>of</strong> GNU/Linux available, each aimed <strong>for</strong> their specific<br />

market. One distribution might be optimized <strong>for</strong> size and may not include the X Window System or<br />

advanced word processors. One distribution might be aimed toward the server market and focus<br />

their applications toward server-based programs and services. What they all share in common is the<br />

underlying system - the kernel. Regardless <strong>of</strong> distribution, the kernel is the same in every one.<br />

Illustration 4: Components <strong>of</strong> a Linux distribution. Image courtesy <strong>of</strong> Erik Streb<br />

2.7.1 Ubuntu<br />

Ubuntu Server is a distribution released by Canonical Ltd., aimed towards server use. It does not<br />

come with a graphical user interface, such as the X Window System, and is thus purely text-based.<br />

Ubuntu Server's package manager is dpkg, the same as Debian uses, which is another popular<br />

distribution. Graphical front ends such as Synaptic are available.<br />

2.7.2 Cron<br />

Cron is a program which allows automatic execution <strong>of</strong> commands or scripts based on a schedule. It<br />

runs as a daemon to ensure its availability and is the default scheduler in Linux systems, while at<br />

20


2 Theoretical background<br />

the same time being easy to manage. There are several paths available in implementing a scheduled<br />

command / script execution; the first simply being to put the script in question in the correct folder<br />

in the /etc directory. There are five folders specifically targeted <strong>for</strong> cron jobs, each folder running<br />

at specific intervals. The contents <strong>of</strong> the folder /etc/cron.hourly runs every hour, and so on.<br />

Furthermore, each user account have their own crontab file <strong>for</strong> personal use. They can schedule<br />

program executions themselves without administrative rights, if the program in question does not<br />

require it.<br />

Another way to implement a scheduled execution is to edit cron's configuration file directly, usually<br />

located at /etc/crontab.<br />

One script per line, with its execution time in the following <strong>for</strong>mat:<br />

* * * * * /path-to-script<br />

Each field, denoted by an asterisk, are minute, hour, day <strong>of</strong> month, month and day <strong>of</strong> week.<br />

Replacing each field with an appropriate number tells cron to execute the script at that specified<br />

time. An example <strong>of</strong> * * * * * /path-to-script tells cron to execute the script at one<br />

minute past <strong>of</strong> every hour. Keeping the asterisks implies an “always” solution, hence the first<br />

example would execute every minute <strong>of</strong> every hour <strong>of</strong> every day <strong>of</strong> the month, every month and<br />

every day <strong>of</strong> the week. [30]<br />

2.7.3 Scripting<br />

A very basic script is a set <strong>of</strong> commands which aim to automate certain tasks and are executed from<br />

a top-to-bottom hierarchy. Such tasks can be anything from going through log files and alert the<br />

administrator if an error has occurred, or simply taking a backup <strong>of</strong> old logs by compressing them to<br />

an archive, move them to another folder and delete the old logs. Being able to automate such tasks<br />

help the administration enormously, enabling them to focus on more important tasks.<br />

The most commonly used scripting languages today have evolved to support more complex<br />

methods, such as conditional execution (i.e. if...else and looping), variable creation and evaluation.<br />

A script differs from a program in the sense that scripts does not need to be compiled or linked<br />

be<strong>for</strong>e being able to run; the code is not compiled into machine code but rather interpreted. This<br />

allows <strong>for</strong> immediate execution once the script is finished. [33]<br />

Bash scripting<br />

A Bash-script must start with the line #!/bin/bash, also known as “shebang”. This tells the<br />

system which program will be used to run the file. In this case, the Bash-shell.<br />

Bash-scripts support the use <strong>of</strong> variables within them but lack support <strong>for</strong> <strong>data</strong> types. Thus, any<br />

variable can contain numbers, strings, or any mix there<strong>of</strong>. These variables do not need to be<br />

declared be<strong>for</strong>ehand, simply assigning a value to it will create it. Blocks used <strong>for</strong> evaluation or<br />

conditional execution starts with “if..” and end with “fi” (“if” backwards). Loops starts with the<br />

appropriate loop being either “<strong>for</strong>”, “while” and “until”, and end with “done”. [34]<br />

21


2 Theoretical background<br />

A simple Bash-script utilizing variables and evaluation can be found in the appendix, section 3.<br />

Python scripting<br />

A Python-script must start with the “shebang”-line as well, albeit this time telling the system to use<br />

Python instead: #!/usr/bin/env python.<br />

Python is a high-level language which have grown in popularity in recent years, partly due to it<br />

being extensively documented as well as having a clean syntax. Being more strict than Bash,<br />

Python use whitespace indention to mark where blocks start and where blocks end. A block in this<br />

sense refer to evaluation or conditional execution, i.e. if...else and looping. A simple Python-script<br />

utilizing variables and evaluation can be found in the appendix, section 4.<br />

2.7.4 Libpcap<br />

Libpcap is an open source-framework written in C and designed <strong>for</strong> low-level network in<strong>for</strong>mation<br />

capturing as well as manipulation. Commonly used “packet sniffers” such as tcpdump, Snort and<br />

Wireshark all use Libpcap. A framework <strong>for</strong> Micros<strong>of</strong>t Windows is also available, under the name<br />

WinPcap. [38]<br />

2.8 Quagga<br />

Quagga is a s<strong>of</strong>tware suite designed <strong>for</strong> routing traffic much like a real router would. Originally a<br />

spin-<strong>of</strong>f from the GNU Zebra project, another s<strong>of</strong>tware routing suite which became commercialized<br />

and no longer supported, Quagga was created in an ef<strong>for</strong>t to fix the many bugs throughout the<br />

s<strong>of</strong>tware suite as well as keeping it free. [56] It is capable <strong>of</strong> running multiple routing protocols<br />

such as OSPF, RIP and BGP <strong>for</strong> both versions <strong>of</strong> the Internet Protocols, namely IPv4 and IPv6. It<br />

runs on most Unix plat<strong>for</strong>ms such as FreeBSD, Linux, Solaris and NetBSD. Quagga consists <strong>of</strong> a<br />

core process, Zebra, which acts as an underlying layer to the Unix kernel, utilizing its own API to<br />

send TCP streams to the Quagga routing protocols. In essence, the core process is simply passing<br />

<strong>data</strong> to- and from the routing processes, and it is these processes that do the majority <strong>of</strong> the work.<br />

Quagga make use <strong>of</strong> select(2) system calls instead <strong>of</strong> multi-threading due to the problems with the<br />

thread library in GNU/Linux and FreeBSD systems.<br />

Quagga was originally a split from the GNU Zebra project, another s<strong>of</strong>tware routing suite which<br />

went inactive in 2005. It is released under the GNU General Public License. [35]<br />

22


2 Theoretical background<br />

2.9 MRTG<br />

Illustration 5: Illustration depicting the Quagga processes and<br />

roles<br />

MRTG is a graphical tool used to monitor the amount <strong>of</strong> traffic passing through a network link,<br />

such as a router, switch or server. Being written in Perl, it has successfully been ported to most Unix<br />

plat<strong>for</strong>ms as well as Micros<strong>of</strong>t Windows. MRTG use <strong>data</strong> obtained from either <strong>using</strong> SNMP to poll<br />

the devices in question, or by a third-party script. Once the <strong>data</strong> is obtained it generates HTML<br />

pages containing images based on the traffic load, allowing a graphical view <strong>of</strong> the traffic load<br />

complete with timestamps and history.<br />

Illustration 6: Example MRTG graph. Image courtesy <strong>of</strong> Tobias Oetiker<br />

23


2 Theoretical background<br />

As derived from the example illustration above, traffic in is plotted as a full green area while traffic<br />

out is plotted as a blue line. It displays the maximum recorded value, average- and current value.<br />

[36]<br />

MRTG can be used in conjunction with RRDTOOL, a s<strong>of</strong>tware suite designed to log and analyze<br />

collected <strong>data</strong>. It does this by storing the <strong>data</strong> in a custom <strong>data</strong>base file that end in .rrd <strong>for</strong>mat. These<br />

files contain historical <strong>data</strong> over a definable time period. Using the RRDTOOL program, graphs can<br />

be generated from the <strong>data</strong>base. These graphs are pure image files, enabling them to easily be<br />

incorporated into web pages <strong>for</strong> viewing. [37]<br />

2.10pmacct<br />

pmacct is a network monitoring suite designed to run on Unix systems with the aim to classify,<br />

measure and export real-time traffic <strong>data</strong>.<br />

pmacct <strong>of</strong>fers finer granularity than <strong>using</strong> SNMP <strong>for</strong> collecting traffic in<strong>for</strong>mation, <strong>of</strong> which it is<br />

capable <strong>of</strong> getting from several sources including <strong>NetFlow</strong>, sFlow and IPFIX. It can then take this<br />

in<strong>for</strong>mation and tag it in order <strong>for</strong> it to be in line with the company policy or just a way <strong>of</strong><br />

distinguishing important traffic be<strong>for</strong>e exporting it. pmacct can export the <strong>data</strong> in many ways,<br />

including several different types <strong>of</strong> <strong>data</strong>bases, memory tables or even files on the hard drive.<br />

2.11 Baselining<br />

In order to distinguish potential harmful traffic from the ordinary day-to-day traffic throughout the<br />

network, a method <strong>of</strong> baselining can be implemented. Having a baseline <strong>of</strong> the traffic means to<br />

know how much traffic normally pass through and at what time during the day certain drops or<br />

spikes occur. A prime example <strong>of</strong> this would be seeing a drop in traffic during lunch hours when<br />

employees are away from their computers. There might be a cause <strong>for</strong> alarm if the drop doesn't<br />

occur when it should, or when any deviation from the norm is observed. Investigating the issue<br />

might show a high amount <strong>of</strong> connections <strong>of</strong> the same type to a specific IP address, which could<br />

indicate a potential DoS attack in progress.<br />

Likewise if an alarm goes <strong>of</strong>f indicating more than the usual number <strong>of</strong> open connections on a<br />

device, server or router, might indicate a SYN Flood-attack in progress.<br />

24


3 Problem analysis<br />

3 Problem analysis<br />

The assignment revolves around the pmacct s<strong>of</strong>tware suite. Hence, obtaining and configuring a<br />

working Linux machine with the appropriate s<strong>of</strong>tware is required. The machine itself should<br />

preferably be plugged in to the network close to the core router in order to avoid unnecessary<br />

overhead by having the <strong>NetFlow</strong> traffic passing through multiple switches and routers, as the<br />

amount <strong>of</strong> <strong>data</strong> will probably be significant.<br />

3.1 Collecting the <strong>data</strong><br />

Collecting all traffic from every entry-point at I2B could generate an unnecessary load on the<br />

network and its devices. A way <strong>of</strong> lessening or compressing the <strong>data</strong> might be required. The file size<br />

<strong>of</strong> the logs may grow up to a point <strong>of</strong> not becoming manageable, since the entire BGP routing table<br />

will be logged. The hardware on the computer must also be taken into consideration, such as the<br />

amount <strong>of</strong> CPU cores and the amount <strong>of</strong> RAM available. Tools <strong>for</strong> monitoring disk I/O may be<br />

needed in order to find -and assess- certain bottlenecks such as the file containing the routing table.<br />

If the disk I/O is too intense and begin to affect normal computer operations, keeping the logs on<br />

another drive might be needed.<br />

3.1.1 Protocol decision<br />

Decision about which flow-protocol to use must be decided; <strong>NetFlow</strong>, sFlow or IPFIX are the most<br />

prevalent; each protocol presents its own benefits and drawbacks. These protocols must be<br />

examined and evaluated and a conclusion must be made as to which will be used. A balance must<br />

there<strong>for</strong>e be reached between operability <strong>of</strong> the protocols and the current topology in use by the<br />

service provider.<br />

3.1.2 Choice <strong>of</strong> <strong>NetFlow</strong>-collector<br />

Configuration <strong>of</strong> the chosen <strong>NetFlow</strong>-collector would be needed in order to tag and save the desired<br />

in<strong>for</strong>mation, as well as to implement a feasible method <strong>for</strong> mitigating DDoS attacks. Since the<br />

company wanted to evaluate pmacct, the choice has already been made. A brief summary <strong>of</strong> the<br />

different programs available should nonetheless be mentioned. See chapter 4.1.1 <strong>for</strong> more<br />

in<strong>for</strong>mation.<br />

3.1.3 Network configuration<br />

BGP peering between the core router and the s<strong>of</strong>tware router, Quagga, need to be configured and<br />

established since Quagga provides the pmacct suite with a routing table as well as BGP AS<br />

in<strong>for</strong>mation. Extra thought and careful planning need to be given to the configuration between the<br />

two as this will be done live. Wrongful configuration could end up interrupting the traffic <strong>for</strong> the<br />

company's customers and steps need to be taken to minimize any such damage, should it occur.<br />

3.2 Storing the <strong>data</strong><br />

The collected <strong>data</strong> need to be stored to allow <strong>for</strong> a historical view. This can be a either long-term<br />

25


3 Problem analysis<br />

solution or something smaller such as the time frame <strong>of</strong> the historical <strong>data</strong>. That is, if the company<br />

graphs one day worth <strong>of</strong> <strong>data</strong>, should <strong>data</strong> further back be available? Saving <strong>data</strong> longer than that<br />

might be counterproductive, given the increasing amount <strong>of</strong> hard disk space needed by the log files.<br />

3.3 Displaying the <strong>data</strong><br />

A graphing tool is required <strong>for</strong> taking our collected <strong>data</strong> and creating historical graphs, presenting a<br />

clean overview <strong>for</strong> easy viewing. The requirements would be finding a tool which can draw <strong>data</strong><br />

from multiple sources, allowing <strong>for</strong> more compatibility with the chosen storage method.<br />

26


4 <strong>Implementation</strong><br />

4 <strong>Implementation</strong><br />

This chapter will describe the different methods available, as well as which methods were chosen<br />

and more importantly, why they were chosen.<br />

4.1 Choice <strong>of</strong> method<br />

This chapter will present the chosen method to solve each problem, explaining why a certain<br />

solution was chosen over the others.<br />

4.1.1 Collecting the <strong>data</strong><br />

Protocol decision<br />

Several widely used protocols are available today, all <strong>of</strong> which gather network traffic in their own<br />

way. The most prominently used protocols are <strong>NetFlow</strong>, sFlow and IPFIX.<br />

All Cisco devices which support flow accounting only support <strong>NetFlow</strong>, which is their own<br />

solution. One benefit <strong>for</strong> <strong>using</strong> <strong>NetFlow</strong> is that it captures all <strong>of</strong> the IP traffic without missing<br />

anything – every packet it accounted <strong>for</strong>. This needs especially to be taken into consideration if one<br />

is <strong>using</strong> IP billing, i.e. charging customers <strong>for</strong> the amount <strong>of</strong> traffic they use. Furthermore, it might<br />

be advisable to utilize <strong>NetFlow</strong> if the network already consists <strong>of</strong> Cisco devices, as it is the only<br />

supported flow-protocol.<br />

Another protocol is sFlow, which is based on sampling. Due to the nature <strong>of</strong> sampling it is very<br />

probable <strong>for</strong> sFlow to miss some <strong>of</strong> the packets, since only one in every N packets are <strong>for</strong>warded to<br />

a collector <strong>for</strong> actual analysis. However, the greatest benefit sFlow have is its ability to be protocolindependent.<br />

Whereas <strong>NetFlow</strong> can only account <strong>for</strong> IP traffic, sFlow can gather any protocol such<br />

as IPX and AppleTalk. It is also capable <strong>of</strong> operating on Layer 2 and as such does not require Layer<br />

3 routing like its peers. Thus, sFlow is a strong competitor in an environment running multiple<br />

protocols.<br />

In the end, <strong>NetFlow</strong> was chosen as the protocol <strong>of</strong> choice <strong>for</strong> several reasons; the company utilizes<br />

Cisco devices throughout their network, and it allows <strong>for</strong> the capture <strong>of</strong> smaller flows since every<br />

flow is accounted <strong>for</strong>. This was decided primarily <strong>for</strong> DDoS-attacks in mind in which attackers<br />

might try to avoid detection by creating smaller flows but with an increased numbers <strong>of</strong> hosts. This<br />

rules out sFlow since it is not supported on Cisco devices. IPFIX was rejected since <strong>NetFlow</strong> would<br />

suffice <strong>for</strong> the company's needs and the ease <strong>of</strong> configuring – it works by just enabling a few<br />

commands in an already running device.<br />

Program decision<br />

Although the choice <strong>of</strong> s<strong>of</strong>tware was already decided upon by the company, several <strong>tools</strong> exist:<br />

• <strong>NetFlow</strong> Analyzer by ManageEngine [6] is such a tool. It comes in three editions, with<br />

prices varying from $795 up to $9995 as <strong>of</strong> June 2012. Understands IPv4 as well as IPv6.<br />

27


4 <strong>Implementation</strong><br />

• Peakflow by Arbor Networks [7] is another commercial product worth mentioning as they<br />

provide several solutions suited <strong>for</strong> different scenarios, in addition to having teamed up with<br />

Cisco Systems to provide additional features and <strong>tools</strong> to mitigate DDoS attacks.<br />

Understands IPv4 as well as IPv6.<br />

• Flowc [8] by Uninet Ltd. is tool which is open source but only works with Cisco devices,<br />

<strong>using</strong> <strong>NetFlow</strong> version 5 only. Documented configuration and explanation is available,<br />

although the site was has not been updated since 2006. Status <strong>of</strong> IPv6 support is unknown.<br />

• Flowd [50] is a another <strong>NetFlow</strong>-only suite, understanding all versions <strong>of</strong> <strong>NetFlow</strong> as well<br />

as support IPv4 and IPv6.<br />

• NFDUMP, a small tool distributed under the BSD license, works by collecting <strong>NetFlow</strong> <strong>data</strong><br />

(v5, v7 and v9) and writing it to disk. Combined with the graphical web-based front end<br />

NfSen, the suite collects and graphs the <strong>data</strong>. Understands IPv4 as well as IPv6. [48] [49]<br />

• The last tool to be mentioned is pmacct, by Paulo Lucente [4]. It is also the s<strong>of</strong>tware <strong>of</strong><br />

choice by Internet 2 Business, and hence this thesis. It is also free and extended<br />

documentation is available, as well as support from other uses via mailing lists. Understands<br />

IPv4 as well as IPv6.<br />

For a more comprehensive list <strong>of</strong> programs related to flows, see the appendix “List <strong>of</strong> s<strong>of</strong>tware<br />

related to flow accounting” [5].<br />

Routing plat<strong>for</strong>m decision<br />

Although Quagga was the chosen s<strong>of</strong>tware by the company, several other <strong>tools</strong> exist:<br />

• Bird Internet routing daemon [57] is an open source routing daemon <strong>for</strong> Unix systems and<br />

support the BGP, RIP and OSPF routing protocols on both IPv4 and IPv6. Already in use in<br />

internet exchanges [58] where it came to replace Quagga <strong>for</strong> scalability issues [59], it is<br />

again in active development as <strong>of</strong> 2008. Editions <strong>for</strong> Ubuntu and Debian exist [60][61].<br />

• OpenBGPD [62] was developed as an alternative to Quagga when it became apparent that<br />

Quagga did not fit the requirements and quality standards <strong>for</strong> BSD [63]. It runs on Unix<br />

systems and supports BGP v4 only. It is licensed under a BSD license and the latest version,<br />

4.6, was released in 2009.<br />

• Vyatta is a s<strong>of</strong>tware-based virtual router as well as the name <strong>of</strong> the company itself [64].<br />

Although commercialized, a free open source version exists which support OSPF- and BGP<br />

routing. The full commercial version adds support <strong>for</strong> a web GUI, dashboard, technical<br />

support 24 / 7 as well as access to the API itself [65].<br />

The decision to use Quagga <strong>for</strong> peering with the routers was in majority due to the company's<br />

wishes to implement it, possibly <strong>for</strong> a pro<strong>of</strong> <strong>of</strong> concept <strong>for</strong> future work.<br />

28


4 <strong>Implementation</strong><br />

4.1.2 Storing the <strong>data</strong><br />

Having the <strong>data</strong> stored in a <strong>data</strong>base had numerable advantages over keeping the <strong>data</strong> as flat files on<br />

the hard drive; complex queries to determine which IP address or AS are the top talkers, how many<br />

different flows a client was <strong>using</strong> or even which port was used the most. Accomplishing the same<br />

thing with the <strong>data</strong> in flat files would require a script, which would undoubtedly be slower. Thus, a<br />

<strong>data</strong>base solution was determined from the start. The available <strong>data</strong>bases suited to the task was<br />

MySQL and PostgreSQL, with MS SQL being removed from the list due to its inability to work<br />

under Unix systems. Oracle was likewise removed due to its commercial cost and with the free<br />

version being too limited.<br />

While PostgreSQL have under many years been considered more robust and better suited <strong>for</strong> heavy<br />

load systems than MySQL, the difference between the two have shrunk in recent years <strong>of</strong><br />

development. MySQL have, on the other hand, been gaining popularity by the ease <strong>of</strong> install and<br />

speed <strong>of</strong> use, although improvements have been made on both sides in this regard as well. It was in<br />

the end decided that MySQL would be the <strong>data</strong>base system used; the <strong>data</strong>base load would be low<br />

and the queries simple enough <strong>for</strong> both solutions, with MySQL being the more familiar system.<br />

4.1.3 Displaying the <strong>data</strong><br />

Two solutions <strong>for</strong> displaying graphed <strong>data</strong> from network links were investigated.<br />

• Cacti [13]<br />

• MRTG [14]<br />

Although both <strong>tools</strong> support the utilization <strong>of</strong> RRDtool, there are vast differences in their ease <strong>of</strong><br />

use and configuration. Cacti was first considered since it supported more features, although this was<br />

discarded as these features didn't benefit graphing bandwidth-<strong>data</strong>. It is however complex and<br />

support a wide range <strong>of</strong> items to graph, allowing <strong>for</strong> great customization. MRTG is also<br />

customizable and very easy to set up. Both Cacti and MRTG support third party scripts, allowing it<br />

to feed them <strong>data</strong> to graph. This allows both to graph almost anything. This feature is especially<br />

easy to set up with MRTG; it is a bit more complex and more time-consuming to accomplish the<br />

same with Cacti.<br />

In the end, MRTG was chosen. This is partly due to Internet 2 Business already use it internally, as<br />

well as the ease <strong>of</strong> use.<br />

4.2 Method criticism<br />

The choice <strong>of</strong> s<strong>of</strong>tware suites could be investigated further. Which would suit the task better, and<br />

which would be the easiest to configure? The primary reason <strong>for</strong> choosing pmacct was due to<br />

Internet 2 Business already having decided upon it. More people would benefit from this thesis if<br />

the same conclusion could be reached by a thorough investigation <strong>of</strong> the available s<strong>of</strong>tware<br />

applications, not just because it was a favorite.<br />

The same thought goes <strong>for</strong> the graphing s<strong>of</strong>tware used, namely MRTG. A thorough investigation<br />

and comparison between the two would have been preferred, although MRTG proved to be the<br />

correct method since it was the easiest to configure. A third graphing s<strong>of</strong>tware worth taking a look<br />

29


4 <strong>Implementation</strong><br />

at is Munin [15], as it seem to updated regularly and is gaining traction in the community.<br />

However, the point was not to investigate if a certain graphing tool is better than another. The tool is<br />

just that; a tool about graphing collected <strong>data</strong> into an easy to read, comprehensible way. Both Cacti<br />

and MRTG accomplishes this.<br />

4.3 Solution<br />

The main purpose to use pmacct was as a helpful tool in mitigating DDoS attacks. Detecting them<br />

quickly would allow I2B to take appropriate action, such as blackholing the addresses itself (also<br />

known as a null route) as well as in<strong>for</strong>ming the ISP from where the attack originated. As mentioned,<br />

the faster they could identify the IP addresses the faster the threat would be contained.<br />

The first approach to avoid wrongful configuration which might end up disrupting customer traffic<br />

was to do everything in a virtual environment; <strong>using</strong> the free GNS3 framework which emulates<br />

routers from different brands, including Cisco and Juniper. This would emulate any number <strong>of</strong><br />

routers with the added advantage <strong>of</strong> not having to worry about configuration mistakes. Once the<br />

configuration and environment would be set up, it could either be migrated directly to the live<br />

routers since the configuration would be exactly the same, or even continue running virtually. GNS3<br />

supports bridged networking which allows <strong>for</strong> communication with the outside world, much like<br />

any OS virtualization s<strong>of</strong>tware like VMware or VirtualBox do. The idea was later discarded <strong>for</strong><br />

several reasons; it was felt that creating and configuring the virtual environment would be too timeconsuming<br />

considering what would be gained. Spending this time double-checking the<br />

configuration seemed like a better use <strong>of</strong> the already diminishing timetable.<br />

One other reason <strong>for</strong> not implementing a virtual environment was due to the fact that GNS3 requires<br />

a real operating system <strong>of</strong> the router it is emulating. Thus, emulating a Cisco Catalyst 6500 like the<br />

small router would require obtaining a Cisco IOS license <strong>for</strong> the 6500. Even if that was achieved,<br />

generating traffic to capture with <strong>NetFlow</strong> would take additional time to set up. It was however<br />

possible to use virtual machines with VMware or VirtualBox to create hosts and link that universe<br />

with GNS3 and its virtual routers. In essence, bridging two virtual environments together, either<br />

alone or connected to the real network as well. It was either that or yet another license would need<br />

to be obtained, this one <strong>for</strong> traffic generation (TGN <strong>for</strong> instance). The whole idea was discarded<br />

after a few days when the amounting time <strong>for</strong> configuration became apparent. It was then decided<br />

that a live environment would be used instead, with extra care given to the configuration. The<br />

problem actually solved itself when configuring Quagga, the s<strong>of</strong>tware router (see below).<br />

The Linux distribution used was Ubuntu Server 11.10 (Oneiric) 64 bit with 8 GB RAM and 4 CPU<br />

cores (1 physical).<br />

4.3.1 Collecting the <strong>data</strong> - solution<br />

In order to collect the desired <strong>data</strong> the small router was configured to send <strong>NetFlow</strong>-traffic to the<br />

Linux machine as well as configuration <strong>of</strong> the s<strong>of</strong>tware router, Quagga, to send BGP in<strong>for</strong>mation.<br />

See appendix 8.3 and 8.4 <strong>for</strong> configuration.<br />

30


4 <strong>Implementation</strong><br />

Verifying the <strong>NetFlow</strong>-<strong>data</strong><br />

Once the router configuration <strong>of</strong> sending <strong>NetFlow</strong>-<strong>data</strong> to the Linux machine was completed, it had<br />

to be verified that the computer actually got the flow-<strong>data</strong>. This was done by <strong>using</strong> a terminal-based<br />

version <strong>of</strong> the popular packet analyzer Wireshark named TShark [52].<br />

The following syntax was used in order to make TShark focus on port 2100, the default port <strong>for</strong><br />

<strong>NetFlow</strong>-<strong>data</strong> and save the results to a file:<br />

tshark -ni eth0 -R udp.port==2100 -d udp.port==2100,cflow -V ><br />

tshark.cap<br />

The file rapidly grew in size and after viewing the contents it was concluded that the router was<br />

correctly configured to send <strong>NetFlow</strong>-<strong>data</strong> to the computer. Below are two excerpts from the<br />

captured traffic, each displaying the duration <strong>of</strong> the flow and other relevant in<strong>for</strong>mation.<br />

Illustration 8: Captured flow between two<br />

parties<br />

Quagga<br />

Illustration 7: Traffic destined <strong>for</strong> port 80,<br />

HTTP<br />

Configuring Quagga to exchange neighbor traffic with the small router turned out to be very easy<br />

and was done fairly quickly. It turned out to be Quagga that had the solution to avoid disrupting<br />

customer traffic by a wrongful configuration; in order to disrupt the customer traffic, it would have<br />

been mandatory that Quagga be configured with networks it could advertise as its own to other<br />

routers. If the same network(s) also existed on the real router, it would cause an interruption in<br />

traffic as both routers would claim ownership over the same networks. It is possible, however<br />

unlikely, that this new in<strong>for</strong>mation would be propagated further out on the Internet as well. ISP's are<br />

generally very careful with advertising networks and usually have some sort <strong>of</strong> filter to only allow<br />

routing updates containing their own networks to be sent out. Since Quagga did not have any<br />

networks it could advertise to other router(s), wrongful configuration could not occur as it only<br />

listened to routing updates; it never sent any <strong>of</strong> its own. It was also one <strong>of</strong> the things that “just<br />

worked” and did not need any special attention once it was set up.<br />

31


4 <strong>Implementation</strong><br />

Illustration 9: Quagga successfully peering with the small router and seeing over 48.000 routes<br />

Illustration 10: Quagga later successfully peering with the core router and seeing over 400.000<br />

routes<br />

pmacct<br />

Since pmacct is capturing flows between IP addresses, the amount <strong>of</strong> flows grow rapidly. Sending<br />

an e-mail to a friend might not generate many flows, but a server answering to requests might.<br />

Every user connecting to it would be a flow, with the return traffic being another flow (since the<br />

destination- and source-fields are reversed, they do not match and a new flow is instead created).<br />

The torrent protocol is an excellent example <strong>of</strong> creating many flows; every connected user is<br />

sending <strong>data</strong> to all the other connected users. In order to avoid saving all this unnecessary <strong>data</strong> and<br />

keeping the load on the <strong>NetFlow</strong>-generated traffic low, it was decided up to configure pmacct in the<br />

following way:<br />

32<br />

• Since pmacct supports filtering, tagging certain traffic would split up the <strong>data</strong> and allow <strong>for</strong><br />

easier management.<br />

• The pmacct s<strong>of</strong>tware would record and tag traffic based upon the direction from the other<br />

ASes, i.e. traffic going in to I2B from other ASes and traffic going out to them from I2B.<br />

These would be tagged as [in] and [out].


4 <strong>Implementation</strong><br />

• Once an attack was in place from another AS, the amount <strong>of</strong> flows, packets and bytes<br />

received would increase rapidly and cause a spike in the graphed <strong>data</strong> <strong>for</strong> that particular AS,<br />

indicating there might be a problem.<br />

• Foc<strong>using</strong> on that particular AS with a new tag, named [attack] would yield the wanted<br />

detailed in<strong>for</strong>mation such as IP addresses <strong>of</strong> the sender and receiver, bytes sent and received<br />

as well the number <strong>of</strong> packets sent.<br />

With this in mind, the pmacct configuration took place and divided the traffic accordingly. The<br />

configuration used several individual configuration files in order to accomplish the tagging<br />

procedure. The main configuration was done in the regular configuration file with the BGP peering<br />

being done in the configuration file agent.map, which was referenced to from the main<br />

configuration. The act <strong>of</strong> tagging traffic was done in pretag.map, in which I2B would change the<br />

configuration and focus on the attacking AS and thus give them the detailed in<strong>for</strong>mation they would<br />

require.<br />

See the appendix, chapter 8.5 and it's sub-chapters <strong>for</strong> the configuration.<br />

The amount <strong>of</strong> traffic sent to the Linux machine from the small router turned out to be more than<br />

estimated, however very manageable. Observation showed that close to 20gb <strong>data</strong> was sent per day,<br />

all <strong>of</strong> it being flow <strong>data</strong>. Considering that the only thing being sent is the header in<strong>for</strong>mation itself<br />

and that a TCP header is only 20 bytes in size, this amounts to quite a lot <strong>of</strong> <strong>data</strong>.<br />

4.3.2 Storing the <strong>data</strong> – solution<br />

MySQL was configured with a default configuration with the decision that a default configuration<br />

would suffice, given the approximated small load. Fine-tuning <strong>for</strong> optimal per<strong>for</strong>mance was<br />

there<strong>for</strong>e not necessary. A graphical front end called phpMyAdmin was however installed to help<br />

visualize the collected <strong>data</strong>.<br />

The computer hardware turned out to be more than sufficient, after both testing and hearing about a<br />

case-study peering at AS286 in which pmacct was running on a dual-core CPU with 4GB RAM and<br />

collecting <strong>data</strong> from a 250+ Gbps routing-domain [53].<br />

33


4 <strong>Implementation</strong><br />

Illustration 11: Saved <strong>data</strong> viewed raw with the text editor Nano under Linux<br />

Illustration 12: Excerpt from the <strong>data</strong>base containing traffic bound <strong>for</strong> I2B from other ASes <strong>using</strong><br />

phpMyADmin. Notice AS 0<br />

AS 0 would appear in the <strong>data</strong>base regularly, which at first seemed odd since AS 0 is reserved and<br />

34


4 <strong>Implementation</strong><br />

there<strong>for</strong>e not in use. After speaking with the creator <strong>of</strong> pmacct, AS 0 <strong>of</strong>ten meant that the route<br />

exported by <strong>NetFlow</strong>, as source or destination <strong>of</strong> the traffic, was not in the BGP routing table. This<br />

typically meant an internal route to the network, advertised by an IGP or similar.<br />

Doing a simulation <strong>of</strong> a pretended attack where one <strong>of</strong> I2B's own customers started to DDoS one <strong>of</strong><br />

IP Only's customers (a Swedish ISP mainly aimed towards businesses), the configuration in<br />

pretag.map was changed to IP Only's AS. This told pmacct to tag traffic originating from I2B<br />

destined <strong>for</strong> IP Only. This tagged traffic was then saved in a special file in which the contents was<br />

pushed into the <strong>data</strong>base.<br />

Illustration 13: phpMyAdmin displaying detailed in<strong>for</strong>mation between I2B and IP Only, simulating<br />

an attack. Notice the amount <strong>of</strong> rows in the <strong>data</strong>base – this is only traffic going to IP Only and from<br />

the small small router at that<br />

4.3.3 Displaying the <strong>data</strong> – solution<br />

MRTG need to be fed <strong>data</strong> in order to create graphs; thus a third-party script was written (see the<br />

35


4 <strong>Implementation</strong><br />

appendix, chapter 8.8) to print the <strong>data</strong> sent in- and out from the requested AS, which in turn was<br />

stored in a <strong>data</strong>base. The following is the output from the script:<br />

MRTG would then take over and store those numbers in at <strong>data</strong>base-<strong>for</strong>mat <strong>of</strong> its own, round-robin<br />

<strong>data</strong>base or rrd <strong>for</strong> short, which save <strong>data</strong> historically. The configuration <strong>for</strong> MRTG to graph <strong>data</strong><br />

from a third-party script turned out to be easily achieved. Adding a target to graph in the<br />

configuration file, usually located at /etc/mrtg.cfg, takes no more than a few lines to achieve.<br />

# Global configuration<br />

WorkDir: /var/www/mrtg<br />

WriteExpires: Yes<br />

Interval: 1<br />

LogFormat: rrdtool<br />

PathAdd: /usr/bin<br />

LibAdd: /usr/lib<br />

Target[BB2]: `/var/www/mrtg/pmacct_get_traffic.sh 29518`<br />

#Above: Path to the script which print in- and out-<strong>data</strong>.<br />

MaxBytes[BB2]: 1000000000<br />

Title[BB2]: Bredband2 bytes<br />

Options[BB2]: gauge<br />

The above last five lines in the configuration creates a graph <strong>for</strong> the Swedish ISP Bredband2,<br />

showing traffic in and out between them and I2B.<br />

4.4 Problems<br />

This section discusses the different problems that manifested during the implementation and how<br />

these were dealt with. Some problems were small and easily solved while others required a whole<br />

different approach.<br />

4.4.1 Problem with collecting the <strong>data</strong><br />

Configuring pmacct to combine the <strong>data</strong> from <strong>NetFlow</strong> and Quagga was the sole most difficult task.<br />

Despite well-documented commands and a mailing list, things still went very slow. This was<br />

attributed to the unfamiliarity with the s<strong>of</strong>tware suite and its way <strong>of</strong> operation, as making one<br />

correct line <strong>of</strong> configuration did not give any hint <strong>of</strong> things moving in the right direction. The<br />

majority <strong>of</strong> the configuration had to be correct be<strong>for</strong>e any indicators were noticed at all.<br />

One other collector-related problem, which was only partially resolved, was the move from the<br />

36<br />

Illustration 14: Collected traffic from AS 29518 (Bredband2). Given the small<br />

amount, the counters had been reset prior to polling


4 <strong>Implementation</strong><br />

small router to the core router. Copying the configuration to the core router was per<strong>for</strong>med and<br />

achieved without incident. The Quagga transition went smoothly as it began peering almost<br />

instantly with the new router, however the flow-<strong>data</strong> stopped after only a few minutes. Capturing<br />

the traffic on the wire <strong>using</strong> TShark showed basically no flows at all. Instead <strong>of</strong> several megabytes<br />

<strong>of</strong> captured <strong>NetFlow</strong>-<strong>data</strong> from under a minute's capture to getting one or two flows every other<br />

minute. Restarting did un<strong>for</strong>tunately not resolve the issue. A buffer overflow was first thought <strong>of</strong> as<br />

the culprit, however this idea was moot since the <strong>data</strong> <strong>collection</strong> didn't even begin after the system<br />

reboot. Data should have started to fill up the buffers, until the point that they would overflow. That<br />

means at least some <strong>data</strong> should have been gathered.<br />

The culprit was later decided to be different versions <strong>of</strong> the operating system – the core router was<br />

running a newer IOS version and the configuration to enable <strong>NetFlow</strong> was apparently different.<br />

This was later confirmed when the small router received the same IOS upgrade and had its<br />

configuration restored. Although the router accepted the configuration, no <strong>NetFlow</strong> <strong>data</strong> were<br />

collected. BGP routing in<strong>for</strong>mation was however received from both routers, which indicated that<br />

Quagga was correctly configured. The reason <strong>for</strong> seeing normal traffic at first and then have it drop<br />

was due to pmacct restarting after a configuration change. It is a probable assumption that the <strong>data</strong><br />

being graphed meanwhile this change occurred was a mix <strong>of</strong> cached <strong>data</strong>, as it is saved up to 60<br />

seconds in the <strong>data</strong>base as well as the graphing s<strong>of</strong>tware only polling at the same interval. As such,<br />

this gave the false impression <strong>of</strong> <strong>data</strong> suddenly dropping out as it the graphing takes a while to<br />

properly update.<br />

The potential problem with large log files remained and careful observation was being done right<br />

after the migration, with extra care given to the file containing the routing table. The following are<br />

the sizes <strong>of</strong> the files which store traffic in- and out from I2B to other ASes, as well as the log file.<br />

The log file contains BGP routing in<strong>for</strong>mation and is thus directly related to the number <strong>of</strong> routes<br />

being seen. The file containing attacks is not included since its size greatly varies between which<br />

AS is being focused, making it impossible to give an estimate. It is also worth noting that it did not<br />

increase in size after the switch to the core router; this is because all routes from and to that<br />

particular AS was already being monitored.<br />

File Approximated size be<strong>for</strong>e<br />

migration (small router)<br />

nfacctd.in 157kb 750kb<br />

nfacctd.out 150kb 740kb<br />

nfacctd.log 7mbyte 77mbyte<br />

Approximated size after migration<br />

(core router)<br />

As seen in the table, the estimated worst-case scenario <strong>of</strong> a 9-10x increase in size did not happen. It<br />

was instead a 4x to 5x increase, despite the number <strong>of</strong> routes being 9-10 times more on the core<br />

router.<br />

4.4.2 Problems with storing the <strong>data</strong><br />

Several issues regarding the storing <strong>of</strong> the <strong>data</strong> were encountered, with some due to unexplainable<br />

reasons despite investigations into the issue. Those problems were not solved, they were avoided<br />

altogether with different approaches instead.<br />

37


4 <strong>Implementation</strong><br />

4.4.2.1 pmacct<br />

Problems arose when trying to save the <strong>data</strong> from pmacct directly to the <strong>data</strong>base and letting pmacct<br />

connect to the <strong>data</strong>base itself. Data was not saved <strong>for</strong> some reason. An investigation did not find the<br />

issue, but it was clear that the user had the correct privileges.<br />

Solution:<br />

Saving the <strong>data</strong> as <strong>for</strong>matted files, i.e. CSV-files, and then <strong>using</strong> a custom-made script written in<br />

Python to manually push the <strong>data</strong> into the <strong>data</strong>base instead. See the appendix, chapter 8.9 <strong>for</strong> the<br />

script.<br />

4.4.2.2 MySQL<br />

Several per<strong>for</strong>mance issues were discovered during the implementation process. One such concern<br />

regarding load and per<strong>for</strong>mance was when the pmacct script emptied its tables into the <strong>data</strong>base.<br />

Since the ISP wanted as close to a real time-analysis as possible, a 60 second refresh timer was set.<br />

This meant pmacct was emptying its buffers into a <strong>data</strong>base every 60 seconds and thus keeping the<br />

in<strong>for</strong>mation up to date, while discarding with the old <strong>data</strong> first. The default configuration was 300<br />

seconds (5 minutes).<br />

This caused a much more heavier load than anticipated, with CPU utilization peaking over 90%<br />

load during these pushes. The entire machine became sluggish and almost non-responsive <strong>for</strong> a few<br />

seconds. The reason <strong>for</strong> the sluggish behavior was discovered by inspecting the <strong>data</strong>base after such<br />

a push – Over 70.000 entries had been created in just a few seconds. Increasing the system<br />

specifications would unlikely produce sufficient results as it was taxed over 90% with just the ~48k<br />

routes from the test bench. Scaling up to their core router with ~400k routes would scale the<br />

requirements up as well. Comparing cost versus per<strong>for</strong>mance, it was decided that increasing the<br />

specifications <strong>of</strong> the system to handle the increased load would be a sub-optimal solution.<br />

Solution:<br />

The configuration was instead changed to allow the <strong>data</strong> to be stored on the hard drive as individual<br />

files, where a custom-made script took over and manually read them into the <strong>data</strong>base instead. This<br />

vastly reduced the CPU load and made the system feel responsive during pushes.<br />

4.4.2.3 Execution time <strong>of</strong> said custom-made script<br />

Another potential problem was discovered with the addition <strong>of</strong> the script; namely its execution time.<br />

Working with <strong>data</strong> on the test bench which contains ~48k routes, the execution time was between 5<br />

and 7 seconds long. This posed a potential problem <strong>for</strong> the day when implementing it on their core<br />

routers would take place. The reason <strong>for</strong> the long execution time was determined to be the way the<br />

script handled the <strong>data</strong>. To understand why this was the case, and what the solution was, requires a<br />

brief explanation <strong>of</strong> the script itself and the reasoning behind it. Since the output files sometimes<br />

contained traffic in<strong>for</strong>mation about the same source / destination but with different bytes and<br />

packets, this was decided to be solved right away <strong>using</strong> the script. As the script looped through each<br />

file and each row, it would do a <strong>data</strong>base query to see if the AS already existed in the <strong>data</strong>base or<br />

not.<br />

38


4 <strong>Implementation</strong><br />

This was what turned out to be the source <strong>of</strong> the long execution time; the query back to the<br />

<strong>data</strong>base. Although each file ([in], [out] and [attack]) only contained ~1100 rows each <strong>for</strong> a total <strong>of</strong><br />

little over 3330 entries, it also meant that the script had to send a query to the <strong>data</strong>base and check its<br />

reply 3300 times be<strong>for</strong>e it was done.<br />

Pseudo-code <strong>for</strong> the relevant section <strong>of</strong> the script:<br />

1. Loop through every line in every text file.<br />

2. For each row, take the AS and make a query back to the <strong>data</strong>base: Does this ISP already<br />

exist in the <strong>data</strong>base?<br />

3. If YES, there is an entry with the same AS – update the AS in question and sum together the<br />

values from the file and the value already present.<br />

4. If NO, there is no such record – create a new entry with the relevant in<strong>for</strong>mation about that<br />

particular ISP.<br />

Solution:<br />

Once the safety check to avoid duplicate ISP's was removed, the script executed in less than a<br />

second. Even if the scale up from ~48k routes to ~400k, almost ten times more routes, is linear it<br />

shouldn't pose a problem. Worst case scenario would be that the script would take ten times longer<br />

to execute, finishing in at about 10 seconds. Considering the <strong>data</strong> is refreshed every 60 seconds,<br />

there is plenty <strong>of</strong> time to spare.<br />

This is the preferred solution, despite there now being some duplicate ISP's in the <strong>data</strong>base. The<br />

solution to this is simply to let MySQL sum it together when the query <strong>for</strong> that in<strong>for</strong>mation is made.<br />

This meant changing the MRTG-script as follows:<br />

Old query New query<br />

SELECT bytes FROM.. SELECT SUM(bytes) FROM..<br />

4.4.3 Problems with displaying the <strong>data</strong><br />

4.4.3.1 MRTG graphing incorrectly<br />

Once the graphing was achieved, it appeared that the numbers were far too big to be trusted. Graphs<br />

were showing in excess <strong>of</strong> 50+ times more traffic than was actually flowing through to other ASes.<br />

Some testing showed that MRTG took the script's printed <strong>data</strong> and changing the in-<strong>data</strong> to out-<strong>data</strong><br />

and vice versa. In effect, if I2B were sending 10 mbit to any other ISP and receiving 20 mbit worth<br />

<strong>of</strong> traffic, MRTG would graph it as I2B were receiving 10 mbit and not 20 mbit like it should. This<br />

was despite the configuration saying that when two values are printed out, the first one would<br />

automatically be tagged as “in” and the other as “out”.<br />

39


4 <strong>Implementation</strong><br />

After several days <strong>of</strong> researching the issue, it was also determined that MRTG likes its <strong>data</strong> “as-is”<br />

and not aggregated over a period <strong>of</strong> time, like pmacct does. pmacct saves the <strong>data</strong> in memory until<br />

the configured time as <strong>of</strong> which it dumps the <strong>data</strong> to be saved. MRTG and pmacct were both<br />

configured to poll or save <strong>data</strong> every 60 seconds. In the case <strong>of</strong> pmacct, it was 60 seconds <strong>of</strong><br />

aggregated <strong>data</strong>.<br />

A small script was set up and configured in MRTG to be graphed . This would print out the values<br />

100 and 50 on different lines, simulating traffic in and traffic out. It would then be graphed,<br />

allowing <strong>for</strong> consistency in debugging as finding errors when graphing static <strong>data</strong> would help track<br />

down the problem. Manually creating images <strong>of</strong> the <strong>data</strong> <strong>using</strong> a script which called upon the<br />

rrdtool command directly (see the appendix, chapter 8.10) showed that MRTG was working as<br />

intended, except <strong>for</strong> the values switching place.<br />

Solution:<br />

Switching in- and out-traffic <strong>for</strong> MRTG as well as dividing the printed <strong>data</strong> by 60 in the custommade<br />

script showed values closer to what was expected.<br />

40<br />

Illustration 15: Static graph created <strong>for</strong> debugging purposes, graphing 100 bytes in and 50<br />

bytes out, in bits. Notice the switched values


4 <strong>Implementation</strong><br />

41


5 Results<br />

5 Results<br />

Several conclusions can be made after investigation <strong>of</strong> the s<strong>of</strong>tware suite pmacct. The pmacct suite<br />

<strong>of</strong>fers strong indication <strong>for</strong> being able to scale up as the traffic load increase, as long as careful<br />

consideration and planning is done. Since this particular solution only involved getting detailed<br />

traffic in<strong>for</strong>mation from the attacking AS, it is uncertain if this level <strong>of</strong> IP accounting is feasible in<br />

gathering the same in<strong>for</strong>mation from every connected AS in real-time. Every flow from all <strong>of</strong> their<br />

customers connected to each other by said flows, from every connected ISP. It seems unlikely <strong>for</strong><br />

one machine to handle. However, pmacct is able to solve this by splitting the <strong>data</strong> between several<br />

machines; one machine only focuses on one or a few ASes, as much as deemed safe and within<br />

margins.<br />

The solution used in this thesis, namely only collecting the number <strong>of</strong> bytes sent and received as<br />

well as the number <strong>of</strong> packets from every AS, while only foc<strong>using</strong> on the one attacking or being<br />

attacked seemed to work very well. It did seem strange that pmacct and MySQL would not<br />

communicate directly, since it worked <strong>for</strong> other people according to the mailing lists. This was<br />

however easily circumnavigated by the custom-made script.<br />

Another odd event was MRTG and its switched values, where traffic in was being graphed as traffic<br />

out. An explanation to why this happened is still sought. One thing that was easy to explain was<br />

why the <strong>data</strong> appeared so much bigger than it actually was, as this was a configuration mishap<br />

between MRTG and pmacct.<br />

The move from the small router to the core router turned out to be a real mystery and a lot <strong>of</strong> time<br />

was spent trying to figure out the reason. This un<strong>for</strong>tunately meant the IPv6 implementation had to<br />

be scrubbed. The <strong>data</strong> that was collected from the core router was very promising however – since<br />

the scale up from about 50k routes to over 400k routes (a factor <strong>of</strong> 8) only increased the sizes <strong>of</strong> the<br />

files by a factor <strong>of</strong> 4, it would indicate that the per<strong>for</strong>mance impact from scaling up would be<br />

negligible. The script which read the files and pushed the <strong>data</strong> into the <strong>data</strong>base executed in about<br />

14 seconds, which meant there was plenty <strong>of</strong> time to spare.<br />

5.1 Analysis <strong>of</strong> results<br />

IPv6 would have been implemented if the configuration <strong>of</strong> pmacct was done faster. There was<br />

un<strong>for</strong>tunately not enough time <strong>for</strong> both IPv4 and IPv6, and thus one had to be scrubbed. The MRTG<br />

incident with the <strong>data</strong> being switched could perhaps have been solved faster if contact had been<br />

made with its creator directly and asking why. The fact that MRTG graphed them vastly too big was<br />

one thing that could have been avoided if the whole documentation would have been read; pmacct<br />

was aggregating one minute worth <strong>of</strong> <strong>data</strong> and MRTG wanting it in another way.<br />

The script which pushed <strong>data</strong> from the files to the <strong>data</strong>base could have been written more<br />

efficiently, such as moving from a script to a fully fledged program which may have handled the<br />

<strong>data</strong>base queries faster.<br />

Detecting DoS attacks turned out to be easier with the solution <strong>of</strong> storing the <strong>data</strong> in a <strong>data</strong>base. As<br />

mentioned above, in addition to graph traffic from different ASes, the <strong>collection</strong> <strong>of</strong> detailed<br />

in<strong>for</strong>mation from a particular AS would also start once an attack is detected. Identifying the top<br />

talkers is done quickly as it only involves an SQL-query. A customer might make a ticket about<br />

42


5 Results<br />

their router feeling slow or unresponsive altogether; a simple SQL-query written to list the number<br />

<strong>of</strong> connections to that particular router's IP would display the culprits. Ordering the results by most<br />

packets sent or most bytes sent is also done within the same query. Due to MRTG being able to<br />

graph basically everything and thanks to the <strong>data</strong>base solution, graphing the number <strong>of</strong> connections<br />

on a device can be done with extreme ease as well.<br />

5.2 Recommendations<br />

It might be advisable to put the pmacct-collector on several different machines and thus splitting up<br />

the workload. The first machine would accept <strong>NetFlow</strong> <strong>data</strong> from a router and just focus on one or<br />

two ASes and then move the flow onward to the next machine which handles the rest. One other<br />

solution is to have dedicated machines <strong>for</strong> each router sending <strong>NetFlow</strong>-<strong>data</strong> in the network. This<br />

has the benefit <strong>of</strong> each router sending flows to its own collector instead <strong>of</strong> having one collector<br />

getting all the <strong>data</strong>. The workload on the hard drives should also be monitored, as the amount <strong>of</strong><br />

flow-<strong>data</strong> sent from just the small router averaged about 20 gigabyte per day.<br />

If Quagga is to be taking a more direct role, such as actively participating in the routing process,<br />

extra observation should be made due to it being single-threaded and might not scale with the<br />

increased load.<br />

5.3 Future work<br />

Manual vs. automated<br />

As it stands, all the graphs have to be created individually, i.e create graphs <strong>for</strong> one particular AS,<br />

and another and so on. This poses a daunting challenge when considering the amount <strong>of</strong> ISP's that<br />

exists. There are several tens <strong>of</strong> thousands ISP's on the Internet as <strong>of</strong> today and creating a graph <strong>for</strong><br />

each and every one isn't feasible. In addition, one would need to actually be watching the graphs in<br />

order to see the attack take place and take appropriate action. One solution to this is to automate the<br />

process <strong>using</strong> s<strong>of</strong>tware either made by custom scripts or already available products, to monitor the<br />

traffic and send an alarm if it reaches a certain threshold. It would sample the traffic flow to find the<br />

norm and send an alert if it spots an abnormal amount <strong>of</strong> traffic, <strong>using</strong> the norm as a template <strong>for</strong><br />

normal traffic.<br />

One could further develop this idea to automatically graph said ISP's network traffic in order to be<br />

ready if it turns out to be an actual attack. The alert message would contain enough in<strong>for</strong>mation <strong>for</strong><br />

the receiving script to automatically start graphing that particular ISP and display it on a web page<br />

containing potential threats. This would ensure a significantly lower workload <strong>for</strong> the employees as<br />

well as eliminating the human error.<br />

Using the <strong>tools</strong> used in this thesis to additionally graph the number <strong>of</strong> active connections on devices<br />

is something that could be implemented <strong>for</strong> greater observation.<br />

43


6 Summary and conclusions<br />

6 Summary and conclusions<br />

The issue was to determine whether or not pmacct scaled well with larger installations, as it had<br />

been proven to work well with smaller ones. Investigation showed it would scale well as the<br />

company would grow. Both IPv4 and IPv6 was to be monitored, however the time only allowed <strong>for</strong><br />

one. IPv4 was there<strong>for</strong>e chosen <strong>for</strong> monitoring as it is more commonly used throughout the world<br />

today. Graphing the <strong>data</strong> was successfully done with MRTG and RRDTOOL. Previous concerns<br />

regarding the hardware specifications turned out to be moot as pmacct doesn't appear to need much<br />

at all in that regard. It runs well on normal computers one would expect to find at home. However,<br />

the amount <strong>of</strong> <strong>NetFlow</strong>-<strong>data</strong> sent to the collector turned out to be greater than anticipated.<br />

Considering the averaged amount <strong>of</strong> flow-<strong>data</strong> turned out to be 20 gigabyte per day from the small<br />

router, the workload on the hard drives over a sustained time period should be taken into<br />

consideration.<br />

The project was not without problems however, with some still being unresolved.<br />

Once the small router's flows were being graphed it would be migrated to the core router. It all<br />

started well with the s<strong>of</strong>tware router instantly peering with the core router, however the flow <strong>of</strong> <strong>data</strong><br />

stopped after a few minutes. A buffer overflow problem was discarded as a restart did not help; if it<br />

was a buffer overflow problem, some <strong>data</strong> should have been gathered be<strong>for</strong>e the buffers got full<br />

again. The only conclusion is a wrongly configured <strong>NetFlow</strong> configuration, since the routers were<br />

running different versions <strong>of</strong> the operating system.<br />

More problems did un<strong>for</strong>tunately arise with storing as well as displaying the <strong>data</strong>.<br />

The <strong>data</strong>base, MySQL and pmacct did not want to communicate with each other, which meant that<br />

pmacct could not store its <strong>data</strong>. The issue was resolved with a small configuration change;<br />

temporarily storing the <strong>data</strong> as CSV-<strong>for</strong>matted files and then writing a custom script to read through<br />

the files and manually push the <strong>data</strong> into MySQL. Fine-tuning the script itself turned out to be<br />

necessary as its execution time was far to long. This was due to the script making a query back to<br />

the <strong>data</strong>base to see if the AS already existed or not. This turned out to be over 3000 sql-queries,<br />

with <strong>data</strong> from just the small router. Once the correction was made the script executed within 1/8 th<br />

<strong>of</strong> the time.<br />

The graphing issue turned out to be an problem with pmacct and MRTG itself. Apart from graphing<br />

too big in- and out-numbers to be real, they had as well swapped place with each other. Thus, the<br />

amount <strong>of</strong> <strong>data</strong> sent in to I2B was being graphed as <strong>data</strong> going out from them instead. The solution<br />

to this was just to switch the numbers ourselves, but the reason remains unknown. The reason <strong>for</strong><br />

graphing far too big values was due to pmacct holding the <strong>data</strong> <strong>for</strong> the configured 60 seconds be<strong>for</strong>e<br />

storing it, while MRTG wanted the <strong>data</strong> differently. Numbers came closer to reality once division by<br />

60 was made be<strong>for</strong>e passing the <strong>data</strong> to MRTG.<br />

The results were especially promising since interesting in<strong>for</strong>mation had been received during the<br />

few minutes <strong>of</strong> operation after the migration. It showed that the per<strong>for</strong>mance hit when switching to<br />

the core router, an increase <strong>of</strong> routes by a factor <strong>of</strong> ten, was in fact negligible. The files grew to a<br />

manageable size with the script finishing in at about 14 seconds, having plenty <strong>of</strong> time to spare<br />

be<strong>for</strong>e the next update.<br />

44


7 References<br />

7 References<br />

[1] “Cyber Attacks Now 2nd Most Common Economic Crime”<br />

http://www.securitiestechnologymonitor.com/news/cyber-attacks-economic-crime-big-30254-1.html<br />

Article publication date: March 27, 2012. Accessed May 23 rd , 2012.<br />

[2] “Introduction to Cisco IOS <strong>NetFlow</strong> - A Technical Overview”, figure 1.<br />

http://www.cisco.com/en/US/prod/collateral/iosswrel/ps6537/ps6555/ps6601/prod_white_paper090<br />

0aecd80406232.html<br />

Article publication date: October 2007. Accessed May 23 rd , 2012.<br />

[3] “Understanding Denial-<strong>of</strong>-Service Attacks”<br />

http://www.us-cert.gov/cas/tips/ST04-015.html<br />

Article publication date: Aug 11, 2004. Accessed May 23 rd , 2012.<br />

[4] “pmacct homepage”<br />

http://www.pmacct.net/<br />

[5] “List <strong>of</strong> s<strong>of</strong>tware related to flow accounting”<br />

http://www.switch.ch/network/projects/completed/TF-NGN/floma/s<strong>of</strong>tware.html<br />

Page last updated: March 3 rd , 2012. Accessed May 23 rd , 2012.<br />

[6] “<strong>NetFlow</strong> Analyzer by ManageEngine”<br />

http://www.manageengine.com/<br />

Accessed May 23 rd , 2012.<br />

[7] “Arbor Peakflow”<br />

http://www.arbornetworks.com/arbor-peakflow-ip-traffic-flow-monitoring-system.html<br />

Accessed May 23 rd , 2012.<br />

[8] “Flowc”<br />

http://netacad.kiev.ua/flowc/index.php?id=4<br />

Page last updated: Jul 8 th , 2006. Accessed May 23 rd , 2012.<br />

[9] “MariaDB”<br />

http://mariadb.org/<br />

Accessed May 23 rd , 2012.<br />

[10] “MySQL”<br />

http://mysql.com/<br />

Page last updated: April 10 th , 2012. Accessed May 23 rd , 2012.<br />

[11] “Microsft SQL Server”<br />

http://www.micros<strong>of</strong>t.com/sqlserver/en/us/default.aspx<br />

Accessed May 23 rd , 2012.<br />

[12] “PostgreSQL”<br />

http://www.postgresql.org/<br />

Page last updated: May 14 th , 2012. Accessed May 23 rd , 2012.<br />

45


7 References<br />

[13] “Cacti”<br />

http://cacti.net/<br />

Page last updated: April 29 th , 2012. Accessed May 23 rd , 2012.<br />

[14] “MRTG”<br />

http://oss.oetiker.ch/mrtg/<br />

Page last updated: Feb 18 th , 2012. Accessed May 23 rd , 2012.<br />

[15] “Munin”<br />

http://munin-monitoring.org/<br />

Page last updated: May 5 th , 2012. Accessed May 23 rd , 2012.<br />

[16] “RFC 791 – DARPA Internet Program Protocol Specification”<br />

http://<strong>tools</strong>.ietf.org/html/rfc791<br />

Page created: Sept 1981. Accessed May 24 th , 2012.<br />

[17] ”The IANA IPv4 Address Free Pool is Now Depleted”<br />

https://www.arin.net/announcements/2011/20110203.html<br />

Article publication date: Feb 3 rd , 2011. Accessed May 25 th , 2012.<br />

[18] "Free Pool <strong>of</strong> IPv4 Address Space Depleted”<br />

http://www.nro.net/news/ipv4-free-pool-depleted<br />

Article publication date: Feb 3 rd , 2011. Accessed May 25 th , 2012.<br />

[19] “RFC 2460 – Internet Protocol version 6”<br />

http://www.ietf.org/rfc/rfc2460.txt<br />

Page created: Dec 1998. Accessed May 25 th , 2012.<br />

[20] “RFC 1930 - Guidelines <strong>for</strong> creation, selection, and registration <strong>of</strong> an Autonomous System<br />

(AS)”<br />

http://<strong>tools</strong>.ietf.org/html/rfc1930<br />

Page created: Mar 1996. Accessed May 25 th , 2012.<br />

[21] “RFC 4271 - A Border Gateway Protocol 4 (BGP-4)”<br />

http://www.ietf.org/rfc/rfc4271<br />

Page created: Jan 2006. Accessed May 25 th , 2012.<br />

[22] “RFC 1771 - A Border Gateway Protocol 4 (BGP-4)”<br />

http://www.ietf.org/rfc/rfc1771.txt<br />

Page created: Mar 1995. Accessed May 25 th , 2012.<br />

[23] “RFC 2328 – OSPF Version 2”<br />

http://<strong>tools</strong>.ietf.org/html/rfc2328<br />

Page created: April 2008. Accessed May 25 th , 2012.<br />

[24] “TCP SYN Flooding and IP Spo<strong>of</strong>ing Attacks”<br />

http://www.cert.org/advisories/CA-1996-21.html<br />

Article publication date: Sep 19 , 1996. Accessed Aug 11 th 2012.<br />

[25] “RFC 1142 – OSI IS-IS Intra-domain Routing Protocol”<br />

46


7 References<br />

http://<strong>tools</strong>.ietf.org/html/rfc1142<br />

Page created: Feb 1990. Accessed May 25 th , 2012.<br />

[26] “CISCO IOS NETFLOW OVERVIEW”<br />

http://www.cisco.com/en/US/prod/collateral/iosswrel/ps6537/ps6555/ps6601/prod_presentation090<br />

0aecd80311f57.pdf<br />

Article publication date: Feb 2004. Accessed May 26 th , 2012.<br />

[27] “What is Linux”<br />

http://www.linux.org/article/view/what-is-linux<br />

Page created: March 5 th 2012. Page last updated: May 25 th , 2012. Accessed May 26 th , 2012.<br />

[28] “RFC1918 – Address Allocation <strong>for</strong> Private Internets”<br />

http://<strong>tools</strong>.ietf.org/html/rfc1918<br />

Page created: Feb 1996. Accessed May 29 th , 2012.<br />

[29] “GNU and Linux”<br />

http://www.gnu.org/gnu/linux-and-gnu.html<br />

Page last updated: May 18 th , 2012. Accessed June 1 st , 2012.<br />

[30] “Newbie: Intro to cron”<br />

http://www.unixgeeks.org/security/newbie/unix/cron-1.html<br />

Page created: Dec 30 th 1999. Accessed June 1 st , 2012.<br />

[31] “Apache Frequently Asked Questions”<br />

http://wiki.apache.org/httpd/FAQ<br />

Page last updated: Jan 17 th , 2012. Accessed June 1 st , 2012.<br />

[32] “March 2012 Web Server Survey”<br />

http://news.netcraft.com/archives/2012/03/05/march-2012-web-server-survey.html<br />

Page created: March 5 th 2012. Accessed June 1 st , 2012.<br />

[33] “Scripting Languages” - Rich Morin and Vicki Brown<br />

http://www.mactech.com/articles/mactech/Vol.15/15.09/ScriptingLanguages/index.html<br />

Page created: 1999. Accessed June 1 st , 2012.<br />

[34] “Introduction to Bash-scripting” - Mike G Mikkey<br />

http://www.linuxdoc.org/HOWTO/Bash-Prog-Intro-HOWTO.html<br />

Article publication date: Jul 27 th 2000. Accessed June 4 th , 2012.<br />

[35] “Quagga”<br />

http://www.nongnu.org/quagga/docs/docs-info.html<br />

Page created: July 28 th 2006. Page last updated: April 1 st , 2011. Accessed June 8 th , 2012.<br />

[36] “MRTG” - Tobias Oetiker<br />

http://oss.oetiker.ch/mrtg/doc/mrtg.en.html<br />

Page last updated: Jan 13 th 2012. Accessed June 8 th , 2012.<br />

[37] “RRDTOOL - Tobias Oetiker”<br />

http://oss.oetiker.ch/rrdtool/doc/rrdtool.en.html<br />

47


7 References<br />

Page last updated: Jan 6 th 2011. Accessed June 8 th , 2012.<br />

[38] “Libpcap framework”<br />

http://www.tldp.org/LDP/Linux-Dictionary/html/l.html<br />

Accessed June 12 th , 2012.<br />

[39] “sFlow Version 5 specifications”<br />

http://www.sflow.org/sflow_version_5.txt<br />

Page created: July 2004. Accessed June 17 th , 2012.<br />

[40] “Closer look: sFlow better than <strong>NetFlow</strong>?” - Brad Reese<br />

http://www.networkworld.com/community/node/29117<br />

Page created: Jun 20 th 2008. Accessed June 18 th , 2012.<br />

[41] “<strong>NetFlow</strong> Vs. sFlow – It may matter to you” - Michael Pattersen, Plixer International<br />

http://www.plixer.com/blog/general/netflow-vs-sflow-it-may-matter-to-you/<br />

Page created: Jan 21 st 2009. Accessed June 20 th , 2012.<br />

[42] “Cisco's <strong>NetFlow</strong> vs. Inmon's sFlow: Which will prevail?” - Brad Reese<br />

http://www.networkworld.com/community/node/22667<br />

Page created: Dec 5 th 2007. Accessed June 20 th , 2012.<br />

[43] “An Introduction to sFlow technology and a brief on sFlow vs <strong>NetFlow</strong> technology” - Arun<br />

Karthik Asokan, ManageEngine<br />

http://blogs.manageengine.com/netflowanalyzer/2011/03/11/netflow-vs-sflow/<br />

Page created: Mar 11 th 2009. Accessed June 21 th , 2012.<br />

[44] “IPFIX fine-tunes traffic analysis” - Paul Kohler and Benoit Claise, Network World<br />

http://www.networkworld.com/news/tech/2003/0811techupdate.html<br />

Page created: Aug 11 th 2003. Accessed June 21 th , 2012.<br />

[45] “<strong>NetFlow</strong> Switching Enhancements Feature Module”<br />

http://www.cisco.com/en/US/docs/ios/11_2/feature/guide/netflow.html<br />

Accessed June 21 th , 2012.<br />

[46] “sFlow”<br />

http://www.sflow.org/<br />

Accessed June 22 nd , 2012.<br />

[47] “IPFIX”<br />

http://<strong>tools</strong>.ietf.org/wg/ipfix/<br />

Accessed June 23 rd , 2012.<br />

[48] “NFDUMP”<br />

http://nfdump.source<strong>for</strong>ge.net/<br />

Page last updated: Dec 31 st 2011. Accessed June 25 th , 2012.<br />

[49] “NfSen”<br />

http://source<strong>for</strong>ge.net/projects/nfsen/<br />

Page last updated: Jan 24 th 2012. Accessed June 26 th , 2012.<br />

48


7 References<br />

[50] “Flowd”<br />

http://code.google.com/p/flowd/<br />

Page last updated: Nov 2 nd 2010. Accessed June 26 th , 2012.<br />

[51] “TRANSMISSION CONTROL PROTOCOL”<br />

http://<strong>tools</strong>.ietf.org/html/rfc793#page-15<br />

Page created: Sept 1981. Accessed June 30 th , 2012.<br />

[52] “TShark man-pages”<br />

http://www.wireshark.org/docs/man-pages/tshark.html<br />

Accessed July 2 nd , 2012.<br />

[53] Case-study, peering at AS286 – Paolo Lucente<br />

http://www.pmacct.net/pmacct_peering_epf5.pdf (the bottom <strong>of</strong> the presentation)<br />

Presentation published Sept 2010. Accessed July 5 th , 2012.<br />

[54] Border Gateway Protocol, Cisco Wiki<br />

http://docwiki.cisco.com/wiki/Border_Gateway_Protocol<br />

Page last updated: Dec 17 th 2009. Accessed July 3 rd , 2012.<br />

[55] BGP AS PATH Attributes<br />

http://www.inetdaemon.com/tutorials/internet/ip/routing/bgp/operation/messages/update/attributes/i<br />

ndex.shtml#wkd<br />

Page last updated: Aug 10 th 2012. Accessed Aug 11 th 2012.<br />

[56] BGP – Existing <strong>Implementation</strong>s<br />

http://www.openbsd.org/papers/bgpd_sucon04/mgp00006.html<br />

Accessed Aug 11 th 2012.<br />

[57] “Bird Internet routing daemon”<br />

http://bird.network.cz/<br />

Page last updated: Mar 2 nd 2012. Accessed Aug 11 th 2012.<br />

[58] “LONAP's Route Servers”, Davidson, Andy<br />

http://www.ukn<strong>of</strong>.org.uk/ukn<strong>of</strong>13/Davidson-LONAP_routeservers.pdf<br />

Presentation published May 28 th 2009. Accessed Aug 11 th 2012.<br />

[59] “BIRD Route Server and Linx”, Preston, Tim<br />

http://www.ukn<strong>of</strong>.org.uk/ukn<strong>of</strong>15/Preston-Routeserver.pdf<br />

Presentation published Jan 21 st 2010. Accessed Aug 11 th 2012.<br />

[60] “BIRD package <strong>for</strong> Debian”<br />

http://packages.debian.org/squeeze/bird<br />

Accessed Aug 11 th 2012.<br />

[61] “BIRD package <strong>for</strong> Ubuntu”<br />

http://packages.ubuntu.com/hardy/bird<br />

Accessed Aug 11 th 2012.<br />

[62] “OpenBGPD”<br />

49


7 References<br />

http://www.openbgpd.org/<br />

Page last updated: Mar 25 th 2012. Accessed Aug 11 th 2012.<br />

[63] “A Secure BGP <strong>Implementation</strong>”, Henning Brauer<br />

http://www.openbsd.org/papers/bgpd_sucon04/mgp00006.html<br />

Accessed Aug 11 th 2012.<br />

[64] “Vyatta”<br />

http://www.vyatta.com/<br />

Accessed Aug 11 th 2012.<br />

[65] “Vyatta Commercial Evaluation Request”<br />

http://www.vyatta.com/product/vyatta-network-os/get-started<br />

Accessed Aug 11 th 2012.<br />

50


8 Appendix<br />

8 Appendix<br />

This appendix includes deep technical in<strong>for</strong>mation, such as the source code <strong>for</strong> scripts and<br />

configuration files <strong>for</strong> related programs.<br />

8.1 E-mail conversation with Paolo Lucente.<br />

pmacct Case Studies<br />

From:Paolo Lucente (paolo@pmacct.net)<br />

Sent: Thursday, April 4, 2012 2:06:21 AM<br />

To: Daniel Karlström (dkm07001@student.mdh.se)<br />

Hi Daniel,<br />

Thanks <strong>for</strong> your interest in pmacct.<br />

There have indeed been implementations <strong>of</strong> pmacct on such a scale be<strong>for</strong>e.<br />

Un<strong>for</strong>tunately, once the implementation is finished the ISP's usually wrap<br />

it up in an NDAs (Non-Disclosure Agreements), making me unavailable to<br />

reveal the in<strong>for</strong>mation to anyone else. This is due to security reasons,<br />

as such case studies would undoubtedly contain in<strong>for</strong>mation about their<br />

internal network and they don't want that getting out.<br />

The only thing i can point you is at the end <strong>of</strong> this presentation:<br />

http://www.pmacct.net/pmacct_peering_epf5.pdf<br />

A few slides on the case-study <strong>of</strong> AS286, <strong>using</strong> pmacct <strong>for</strong> their peering<br />

purposes. AS286 is a reputable IP carrier (tier 2) in Europe.<br />

Regards,<br />

Paolo<br />

On Wed, April 3, 2012 at 10:22:49PM +0200, Daniel Karlström wrote:<br />

><br />

> Greetings Paolo,<br />

><br />

> My name is Daniel Karlström and I am doing a thesis on pmacct <strong>for</strong> Mälardalen<br />

University, Sweden.<br />

> The thesis is investing whether or not pmacct is suitable <strong>for</strong> larger<br />

installations, at the ISP<br />

> level <strong>for</strong> instance. I have not come across any prior work in this field and<br />

was wondering if they exist.<br />

> Are there any existing case studies I might use and reference to?<br />

><br />

> Regards,<br />

><br />

> Daniel Karlström, Mälardalen University, Sweden.<br />

51


8 Appendix<br />

8.2 Enabling <strong>NetFlow</strong> on Cisco devices<br />

Example configuration <strong>of</strong> a Cisco router sending incoming and outgoing traffic in<strong>for</strong>mation <strong>using</strong><br />

<strong>NetFlow</strong>, sourced from its own fastEthernet 0/0-interface to a collector residing at the IP address<br />

192.168.0.10 on port 2055<br />

Router>enable<br />

Router#conf t<br />

Router(config)#ip flow-export source fastEthernet 0/0<br />

Router(config)#ip flow-export version 5<br />

Router(config)#ip flow-export destination 192.168.0.10 2055<br />

Router(config)#interface fastEthernet 0/0<br />

Router(config)#ip flow ingress<br />

Router(config)#ip flow egress<br />

Router(config-if)#ip route-cache flow<br />

8.3 Configuration <strong>of</strong> <strong>NetFlow</strong> on the small router<br />

ip flow-cache timeout inactive 10<br />

ip flow-cache timeout active 5<br />

mls flow ip full<br />

interface xx x/x<br />

ip flow ingress<br />

ip flow-export source Loopback0<br />

ip flow-export version 9<br />

ip flow-export destination x.x.x.x 2100<br />

8.4 Configuration <strong>of</strong> Quagga<br />

router bgp wwwww<br />

52<br />

bgp router-id x.x.x.x<br />

bgp en<strong>for</strong>ce-first-as


8 Appendix<br />

!<br />

neighbor y.y.y.y remote-as zzzzz<br />

neighbor y.y.y.y update-source x.x.x.x<br />

neighbor y.y.y.y default-originate<br />

neighbor y.y.y.y s<strong>of</strong>t-reconfiguration inbound<br />

neighbor y.y.y.y prefix-list deny-all out<br />

neighbor 127.0.0.1 remote-as zzzzz<br />

neighbor 127.0.0.1 port 17917<br />

neighbor 127.0.0.1 update-source 127.0.0.1<br />

neighbor 127.0.0.1 route-reflector-client<br />

ip prefix-list deny-all seq 5 deny 0.0.0.0/0 le 32<br />

8.5 Configuration <strong>of</strong> pmacct<br />

daemonize: true<br />

pidfile: /var/run/nfacctd.pid<br />

logfile: /usr/local/etc/pmacct/nfacctd.log<br />

!<br />

interface: eth0<br />

nfacctd_ip: x.x.x.x<br />

nfacctd_port: 2100<br />

nfacctd_renormalize: true<br />

!<br />

aggregate[out]: dst_as,peer_src_as,peer_dst_as<br />

aggregate[in]: src_as,peer_src_as<br />

aggregate[attack]:dst_as,src_host,dst_host,src_port,dst_port,proto<br />

,tos<br />

!<br />

pre_tag_filter[attack]: 100<br />

pre_tag_map: /usr/local/etc/pmacct/pretag.map<br />

!<br />

refresh_maps: true<br />

!<br />

bgp_daemon: true<br />

bgp_daemon_ip: 127.0.0.1<br />

bgp_daemon_port: 17917<br />

bgp_daemon_msglog: true<br />

bgp_agent_map: /usr/local/etc/pmacct/agent.map<br />

53


8 Appendix<br />

nfacctd_as_new: bgp<br />

!<br />

pmacctd_<strong>for</strong>ce_frag_handling: true<br />

plugin_buffer_size: 990480000<br />

plugin_pipe_size: 904800000<br />

plugins: print[ut],print[in],print[attack]<br />

print_output_file[out]: /usr/local/etc/pmacct/nfacctd.out<br />

print_output_file[in]: /usr/local/etc/pmacct/nfacctd.in<br />

print_output_file[attack]: /usr/local/etc/pmacct/nfacctd.attack<br />

print_output: csv<br />

print_refresh_time: 60<br />

8.5.1 agent.map<br />

id=x.x.x.x ip=y.y.y.y<br />

8.5.2 pretag.map<br />

id=100 ip=y.y.y.y dst_as=zzzzz<br />

8.6 Bash Script<br />

#!/bin/bash<br />

color="blue"<br />

if [ "@color" = "blue" ]; then<br />

else<br />

fi<br />

echo "Blue is a very nice color!"<br />

echo "Not as good as blue, but.."<br />

echo "Program complete."<br />

8.7 Python Script<br />

#!/usr/bin/env python<br />

# -*- coding: utf-8 -*-<br />

54


8 Appendix<br />

color="blue"<br />

if color == "blue":<br />

else:<br />

print("Blue is a very nice color!")<br />

print("Not as good as blue, but..")<br />

print("Program complete.")<br />

8.8 Script <strong>for</strong> MRTG<br />

#!/bin/sh<br />

# This script takes only one input variable, namely<br />

# the AS one want traffic in<strong>for</strong>mation about.<br />

# Example: ./pmacct_get_traffic 29518 would<br />

# give in- and out-<strong>data</strong> from AS 29518 (Bredband2)<br />

# <strong>for</strong> the last 60 seconds.<br />

AS=$1<br />

unset IN<br />

unset OUT<br />

IN=`/usr/bin/mysql -e "select sum(bytes) from AS_in_v4 where<br />

src_as='$AS'" pmacct`<br />

OUT=`/usr/bin/mysql -e "select sum(bytes) from AS_out_v4 where<br />

dst_as='$AS'" pmacct`<br />

# Our variables now contain junk letters along with<br />

# the actual numbers in the <strong>for</strong>m <strong>of</strong> "bytes 164277.<br />

# These should be removed as we only want the numbers.<br />

# We are also dividing the numbers by 60, which equals<br />

# one minute. This is due to MRTG wanting live <strong>data</strong><br />

# and not historical. pmacct's timer is set to 60 seconds<br />

# and hence the division by 60 is necessary.<br />

IN=$(echo $IN |sed s/'sum(bytes) '//)<br />

IN=$(($IN/60))<br />

55


8 Appendix<br />

echo $IN<br />

OUT=$(echo $OUT |sed s/'sum(bytes) '//)<br />

OUT=$(($OUT/60))<br />

echo $OUT<br />

8.9 Custom-made script to push the <strong>data</strong> into the <strong>data</strong>base<br />

#!/usr/bin/env python<br />

# -*- coding: utf-8 -*-<br />

# Importing various required libraries.<br />

import MySQLdb<br />

import sys<br />

import csv<br />

import time<br />

import os<br />

# Declaring variables.<br />

script_exec_time = time.asctime( time.localtime(time.time()) )<br />

query = ""<br />

# TIMER START<br />

startTime=time.clock()<br />

# DATABASE INFORMATION<br />

# host, user, passwd, db<br />

db = MySQLdb.connect("localhost", "user", "password", "pmacct")<br />

cursor = db.cursor()<br />

# Opening <strong>of</strong> the files <strong>for</strong> reading.<br />

file_out = csv.reader(open('/usr/local/etc/pmacct/nfacctd.out',<br />

'rb'), delimiter=',', quotechar='|')<br />

file_in = csv.reader(open('/usr/local/etc/pmacct/nfacctd.in',<br />

'rb'), delimiter=',', quotechar='|')<br />

file_attack =<br />

csv.reader(open('/usr/local/etc/pmacct/nfacctd.attack', 'rb'),<br />

delimiter=',', quotechar='|')<br />

# Creating lists to temporarily store the<br />

# <strong>data</strong> be<strong>for</strong>e it is pushed into SQL.<br />

v4_out = []<br />

v4_in = []<br />

v4_attack = []<br />

# Populating the lists with the files' contents.<br />

v4_out.extend(file_out)<br />

v4_in.extend(file_in)<br />

v4_attack.extend(file_attack)<br />

56


8 Appendix<br />

# Remove the first line from the lists, as these contain the<br />

# actual name <strong>of</strong> the fields such as PROTO, BYTE and PACKETS<br />

# instead <strong>of</strong> the values itself. MySQL doesn't like doing<br />

# numerical calculations on fields containing text, <strong>for</strong> instance.<br />

v4_out.pop(0)<br />

v4_in.pop(0)<br />

v4_attack.pop(0)<br />

# Emptying the <strong>data</strong>base be<strong>for</strong>e new values are inserted.<br />

cursor.execute("TRUNCATE TABLE AS_in_v4")<br />

cursor.execute("TRUNCATE TABLE AS_out_v4")<br />

cursor.execute("TRUNCATE TABLE AS_attack_v4")<br />

# Looping through each list and inserting the values<br />

# into MySQL.<br />

# Traffic going OUT from I2B<br />

<strong>for</strong> kolumn in v4_out:<br />

cursor.execute("""INSERT INTO AS_out_v4 (DST_AS, packets,<br />

bytes) VALUES (%s, %s, %s)""", (kolumn[9], kolumn[30],<br />

kolumn[32]))<br />

# Note:<br />

# kolumn 9, 30 and 32 are the delimited fields which<br />

# contain the <strong>data</strong> we want to save. In this case, the<br />

# destination AS, the number <strong>of</strong> packets and bytes sent.<br />

# Traffic going IN to I2B<br />

<strong>for</strong> kolumn in v4_in:<br />

cursor.execute("INSERT INTO AS_in_v4 (SRC_AS, packets, bytes)<br />

VALUES (%s, %s, %s)", (kolumn[8], kolumn[30], kolumn[32]))<br />

# Note:<br />

# kolumn 8, 30 and 32 are the delimited fields which<br />

# contain the <strong>data</strong> we want to save. In this case, the<br />

# source AS, the number <strong>of</strong> packets and bytes received.<br />

# Attacking AS<br />

<strong>for</strong> kolumn in v4_attack:<br />

cursor.execute("INSERT INTO AS_attack_v4 (DST_AS, SRC_IP,<br />

DST_IP, DST_PORT, proto, packets, bytes) VALUES (%s, %s, %s, %s,<br />

%s, %s, %s)", (kolumn[9], kolumn[21], kolumn[22], kolumn[26],<br />

kolumn[28], kolumn[30], kolumn[32]))<br />

# Note:<br />

# kolumn 9, 21, 22, 26, 28, 30 and 32 are the delimited fields<br />

57


8 Appendix<br />

which<br />

# contain the <strong>data</strong> we want to save. In this case, the<br />

# destination AS, source IP, destination IP, destination port,<br />

protocol<br />

# and the number <strong>of</strong> packets and bytes sent.<br />

# Close the open handles be<strong>for</strong>e exiting.<br />

cursor.close()<br />

db.close()<br />

# Print the execution time <strong>of</strong> the script.<br />

print ("%s: Execution time: %s seconds." % (script_exec_time,<br />

(time.clock() - startTime)))<br />

8.10 RRDTOOL-script (rrdtool.sh)<br />

/usr/bin/rrdtool graph $1.png \<br />

--img<strong>for</strong>mat=PNG \<br />

--start=-7200 \<br />

--end=-60 \<br />

--title='Pmacct Graph' \<br />

--rigid \<br />

--base=1000 \<br />

--height=120 \<br />

--width=500 \<br />

--alt-autoscale-max \<br />

--lower-limit=0 \<br />

--vertical-label='bits/s' \<br />

--slope-mode \<br />

--font TITLE:12: \<br />

--font AXIS:8: \<br />

--font LEGEND:8: \<br />

--font UNIT:8: \<br />

DEF:a="/var/www/mrtg/$1.rrd":ds0:AVERAGE \<br />

CDEF:cdefa=a,8,* \<br />

DEF:b="/var/www/mrtg/$1.rrd":ds1:AVERAGE \<br />

CDEF:cdefb=b,8,* \<br />

AREA:cdefa#0000ffff:"Out Traffic" \<br />

GPRINT:cdefa:LAST:"Current\:%8.2lf %s" \<br />

GPRINT:cdefa:AVERAGE:"Average\:%8.2lf %s" \<br />

GPRINT:cdefa:MAX:"Maximum\:%8.2lf %s\n" \<br />

AREA:cdefb#00ff0099:"In traffic" \<br />

58


8 Appendix<br />

GPRINT:cdefb:LAST:"Current\:%8.2lf %s" \<br />

GPRINT:cdefb:AVERAGE:"Average\:%8.2lf %s" \<br />

GPRINT:cdefb:MAX:"Maximum\:%8.2lf %s\n"<br />

AREA:cdefb#FFC73BFF:"In traffic":STACK \<br />

59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!