Tools and Security awareness

This is paper 4 of 4 of the server series.

The topics we will be covering are in today's paper are:

3. Tools
3.1. TCPdump
3.2. Nessus
3.3. lsof
3.4. stack smashing
3.5. tunneling
4. Conclusion


3. Tools

We will lean on certain Tools more or less in direct connection with the system but who are not inevitably available by defect or then by the ports but not up to date, or which is caracteristic quite specific system. Thus we here will decouvrir some Tools allowing to reinforce our safety as well proactive manner as reactive.

3.1. TCPdump

TCPdump is the ultimate tool for sniffer the traffic of a network in order to carry out its debugging. It will enable us to capture whole or part of the traffic local area network in order to enable us to analyze it in order to check the correct operation of our configurations network. With this intention TCPdump bases itself on the layer system BPF for Berkeley Packet Filter in order to intercept the Ethernet screens and packages IP forwarding by the machine in promiscuous mode (mode where Network Interface Card or NIC can see the whole of the traffic network) according to expressions' bpf similar to the concepts of expressions regulières. This method of capture by BPF east provides by the bookshop libpcap facilitating the development of sniffers enormously advanced.

TCPdump provides a number of options impressive of which we will approach most useful here. First of all with each capture we recommend following syntax to you:

($:~)=> tcpdump -X -s 1500 -e -n -i fxp0

This line of order makes it possible to obtain a dump at the same time in hexa and ASCII, a length of 1500 bytes, posting information of heading on the level of the connection layer which will be generally Ethernet, we do not carry out a resolution of names in order to gain in speed, discretion and facilitated of analysis; and finally we specify the NIC on which to listen what can avèrer useful when the console admin has several interfaces or is used as footbridge.

The exit as for it is appeared - in the case of a package TCP here - as a timestamp, then Initial the Number Sequence followed by the number of sequence of the package, the size of the package between brackets, flags TCP, the number of acknowledgment, the window size, flag IP informing about the state of fragmentation and finally options TCP. The exit can of course vary if one captures a package UDP or ICMP (with in this last case type ICMP). With the options already presented, we also obtain in the dump the headers layer connection, you can of course remove this option for more simplicity.

A combination of also interesting options and if required to use with the options already seen, is as follows:

($:~)=> tcpdump -i fxp0 -l > file && tail -f file

This entry enables us to redirect the traffic captured on the interface specified towards a file ' file' that we will be able to then see to be brought up to date by group of 10 lines using tail. This allows a monitoring

Of course, we do not need to capture the totality of the packages when we seek only one particular transmission in order to carry out debugging or other analyzes. For that we have the possibility of using expressions BPF introduced higher. They enable us to test a given byte of a package IP or even of its part TCP/UDP/ICMP. It is also possible, thanks to expressions boolénnes to test one or more bits of each byte. Expressions BPF are placed simply at the end of the options of the line of TCPdump order. Traditional expressions BPF are subdivided in 3 groups which can be combined between them to carry out any (or almost:) matching.

The first group is consisted of the ' types' which can be host for matcher an address IP or a field, Net for matcher a class network - this field can be refined by specifying a mask with its continuation - and port for matcher a port. These types are the core operators of the capture. We have then the ' dir' which specifies the direction to be sought. We have here at our disposal the key words src for the origin and dst for the destination. Lastly, we have the group ' proto' which makes it possible to seek corresponding packages. We find there ether or FDDI for the layers Ethernet connections and assimilated, arp and RARP for the protocols of the same name, IP and ip6 for the versions of IP v4 and v6, ICMP and icmp6 in a similar way and finally TCP and UDP. With these 3 groups, it is necessary for us to add several additional expressions to knowing gateway which allows matcher a package whose Ethernet address corresponds to the expression but not address IP source nor destination and thus to obtain the packages coming from a certain router. We also have less and greater in order to capture the packages lower or higher than a given length. Finally we have the traditional logical operators but, and and not representing inclusion, the concatenation or exclusion.

ping of death
($:~)=> tcpdump -Xni fxp0 icmp greater 65535

traffic HTTPS and IRCS
($:~)=> tcpdump -Xni fxp0 (tcp port 443) or (tcp port 994)

There are also advanced expressions making it possible to carry out finer operations of capture on the packages. The syntax of an expression BPF is as follows

proto[offset:longuor ] logical operation

where proto is similar to one of the fields of the group ' proto' referred to above, offset indicates the shift of the field to be tested, the length indicates the length of the field to be intended and the logical operation the test itself. This requires a precise knowledge of the fields of the various protocols what can be done after a study of the RFC corresponding. To seek a precise field, it is wise to point out the structure of a datagram IP and a segment TCP by considering the dump according to:


4500 003c 0a66 4000 4006 a320 c0a8 0001
c0a8 0002 04c5 0016 801e 78e3 0000 0000
a002 3fc4 fe70 0000 0204 05cc 0402 080a
0014 7e59 0000 0000 0103 0300

4 = IP Version
5 = IP header length
003c = IP total length
0a66 = IP ID
4000 = IP fragmentation (flags then multiple offset of 8)
40 = IP TTL
06 = IP Protocol
a320 = IP checksum
c0a8 0001 = IP source
c0a8 0002 = IP destination
04c5 = TCP source port
0016 = TCP destination port
801e 78e3 = TCP sequence number
a = TCP data offset
002 = TCP Control bits (flags, ici SYN)
3fc4 = TCP Window Size
fe70 = TCP Checksum
0000 = Urgent Pointer
0204 05cc = TCP Maximum Segment Size (only with SYN)
0402 = TCP SackOK Permitted (only with SYN)
080a 0014 7e59 0000 0000 = TCP Timestamp (field reply to 0, since SYN)
0103 = Padding
0300 = TCP Window Scale (only with SYN)


Not to have to retain this heavy diagram (who is right that of a traditional flow), you can carry out following your order tcpdump and after a Unix pipe, tcpdumpx writes by Wietse Venema which precisely comments on the dumpées data. You will be able to find this prorgramme with .ftp://ftp.porcupine.org/pub/debugging/.

Above a series of filters ready with employment.


* paquets TCP avec flags
   SYN : tcp[13] & 2 != 0
   ACK : tcp[13] & 16 != 0
   FIN : tcp[13] & 1 != 0
   RST : tcp[13] & 4 != 0
   PSH : tcp[13] & 8 != 0
   URG : tcp[13] & 32 != 0

* Christmas Tree Scan
   ($:~)=> tcpdump -Xni ed0 '(tcp[13] & 1 != 0) and (tcp[13] & 8 != 0) and
            (tcp[13] & 32 != 0)'

* capture ICMP echo request and fold up
   ($:~)=> tcpdump -Xni ed0 '(icmp[0] = 8) or (icmp[0] = 0)'

* fragmented packages IP
   MF : ip[6] & 32 != 0
   DF : ip[6] & 64 != 0
   offset : ip[6:2] & 0x1fff != 0



In margin of TCPdump, we recommend to you to throw an eye with the following programs inspired, based on TCPdump or being used as extensions:

By syncro
10 Dec 2003