Presentation is loading. Please wait.

Presentation is loading. Please wait.

Network Administration Homework1 Perl Programming Exercises

Similar presentations


Presentation on theme: "Network Administration Homework1 Perl Programming Exercises"— Presentation transcript:

1 Network Administration Homework1 Perl Programming Exercises

2 Analysis Ethereal Output (1)
A tool that can be used to analysis network traffic passed through your network interface

3 Analysis Ethereal Output (2)
Network Monitoring Turn on the “promiscuous mode” of your NIC Normal mode NIC will collect those packets that destined to your computer That is, destination IP = My IP / Broadcast IP Otherwise, NIC will drop it. Promiscuous mode NIC will collect “all” packets Turning on the promiscuous mode needs Root privilege Tools that can do this: tcpdump, ssldump, Ethereal

4 Analysis Ethereal Output (3)
To install ethereal, you can use this URL: Download and execute it To begin monitoring your network, you can: Ctrl + K Choose your interface Specify filter Man tcpdump Ex: Host dst port 22 Check Update list of packets in real time Start capture

5 Analysis Ethereal Output (4)
After you have captured packets Spend some time to investigate the content of each packet Frame header IP header TCP/UDP header Application data

6 Analysis Ethereal Output (5)
Purpose of this first exercise: Learn how to use ethereal Learn how to use ethereal to inspect TCP/IP that we have taught Learn how to use Perl built-in function “pack” and “unpack” Learn how to use Perl Curses::UI CPAN Works you have to do in this exercise Install and user ethereal Install /usr/ports/devel/p5-Curses-UI Spend some time to investigate packets content that you have captured How TCP/IP headers looks like Write a Perl script that satisfies those requirements in next slide

7 Analysis Ethereal Output (6)
Requirements of the first exercise Input: One Ethereal output Output: One curses window that lists packets found in Ethereal-output file Each line represents one packet Each line should have the following fields SrcMac: Source MAC of that packet DstMac: destination MAC of that packet SrcIP: Source IP of that packet DstIP: destination IP of that packet SrcPort: source port of that packet DstPort: destination port of that packet Timestamp: the “captured” timestamp add by ethereal List 10 lines at most in one window Use “Curses:UI:ButtonBox” to list remain 10s’ packets Like: Provide “sort-by” functionality Sorting by the above 7 fields

8 Supplement Information

9 Ethereal Output Format
One single Ethereal output file 24bytes-Ethereal-Header Packets-with 16 bytes added information 4bytes time stamp (captured) 4bytes length of packet 4bytes actual packet length 4bytes timestamp (micro-) 4bytes Magic (0xa1b2c3d4) 2bytes major version number 2bytes minor version number 4bytes time zone offset 4bytes time stamp accuracy 4bytes snapshot length 4bytes Link-Layer Type (1) 4bytes time stamp (captured) 4bytes length of packet 4bytes actual packet length 4bytes timestamp (micro-) Ethereal Dump Header (24bytes) 4bytes time stamp (captured) 4bytes length of packet 4bytes actual packet length 4bytes timestamp (micro-)

10 CPAN (1) CPAN Search what you may like Install in your BSD
Comprehensive Perl Archive Network Collection of Perl software modules that are developed and upload by Perl enthusiasts Search what you may like Install in your BSD /usr/ports/devel/p5-* # /usr/ports/devel/p5-Curses-UI

11 CPAN (2) #!/usr/bin/perl use strict; use Curses::UI;
my $cui = new Curses::UI; $cui->dialog("Hello, world\n");

12 CPAN (3) use strict; use Curses::UI;
my $cui = new Curses::UI(-color_support => 1); my $mainWin = $cui->add( undef, 'Window', -border => 1, -padtop => 1, -padright => 2, -padbottom => 1, -padleft => 1, -titlereverse => 0, -title => 'My Main Window' ); my $settingViewer = $mainWin->add( undef, 'TextViewer', -padright => 1, -padbottom => 10, -focusable => 0, -x => 1, -y => 1, -text => ‘這樣呢?' $cui->dialog(‘test’);

13 CPAN (4) … sub sayhello $mainWin->add( { undef, 'Buttonbox',
-buttons => [ { -label => "sayhello", -shortcut => 1, -onpress => \&sayhello }, -label => "saybye", -shortcut => 2, -onpress => \&saybye } ] ); sub sayhello { $cui->dialog('Hello'); } sub saybye my $choice = $cui->dialog( -message => 'Are you going to leave?', -buttons => ['yes','no'] ); exit(0) if $choice; $cui->mainloop();

14 CPAN (5)

15 pack and unpack (1) Usage Ex: pack TEMPLATE, LIST
Takes a LIST of values and Converts it into a string using the rules Ex: $foo = pack("CCCC", 65, 66, 67, 68); // $foo = “ABCD” $foo = pack("C4", 65, 66, 67, 68); // $foo = “ABCD” ($a, $b, $c, $d) = unpack(“CCCC”, $foo); // $a = 66 C means unsigned char value (c means signed) 4 means repeat 4 times

16 pack and unpack (2) open (FD, "ethereal_example") || die "Can't open file:$!"; binmode(FD); read(FD, $buffer, 24); while( read(FD, $buffer, 12) != 0){ read(FD, $buffer, 4); $length = unpack("l", $buffer); read(FD, $buffer, 6); $dstMAC = unpack("H*", $buffer); $srcMAC = unpack("H*", $buffer); printf("length is $length\n"); printf("dstMAC is $dstMAC, srcMAC is $srcMAC\n"); read(FD, $buffer, $length - 12); } close(FD); length is 74 dstMAC is 00d0b7177b07, srcMAC is 000fea86ddd0 dstMAC is 000fea86ddd0, srcMAC is 00d0b7177b07 length is 82 length is 202


Download ppt "Network Administration Homework1 Perl Programming Exercises"

Similar presentations


Ads by Google