计算机网络实验:MiniSniff

Lab 6  Lab: MiniSniff

Part I: Understanding minisniff:

1)      What library does minisniff use to capture packets? Where in the web can you find more information about this library?

Minisniff use “pcap.h” library to capture packets. I can find more information about this library in these webs:

http://en.wikipedia.org/wiki/Pcap#libpcap

https://wiki.wireshark.org/libpcap

http://www.turbolinux.com.cn/turbo/wiki/doku.php?id=libpcap%E5%87%BD%E6%95%B0%E5%BA%93

http://blog.chinaunix.net/uid-21556133-id-120228.html

http://blog.csdn.net/htttw/article/details/7521053

and so on.

2)      Do some research and describe the advantages/disadvantage of using this library? Do not blindly copy and past material from the web. Try to understand the material you find and write what you understood.

  Advantages: it is open source. I can download it free and use it for my purpose. I can change it if I want to do that. It provides many useful functions. The API is very clear and easy to understand. So it is easy if you want to learn how to use it.

  Disadvantage: This library still have some bugs, it is still developing.

3)      Are there any alternative libraries available to capture packets? (Open source only)

Yes, there is. Such as Winpcap. It is open source. It works for windows system. It is free and public.

4)      Explain the purpose of the following functions:

a. pcap_lookupdev

b. pcap_open_live

c. pcap_lookupnet

d. pcap_compile

e. pcap_setfilter

f. pcap_next

g. pcap_loop

h. pcap_dispatch

    a:  locate the network card

b:  open the network card to sniff

c:  determine the network number and the mask associated with the network device.

d:  compile the string str into a filter program

e;  specify a filter

f:  reads the next packet and returns a u_char pointer to the data in that packet.

g:  read the network card and capture the packet, then it can process them.

h:  read the network card and capture the packet, then it can process them.

5)      There are five layers in the TCP/IP stack (application, transport, network, link, and physical). Up to what layer can minisniff decode data from the captured packets? Justify your answer using the code.

    Application. Just as the code in Patr II. In there we can decode the telnet username and the password, which is application data. So that means we can decode data from the captured packets up to application

Part II: Extending minisniff

1)      Modify minisniff to capture, decode and display the password from a telnet session.

2)      Provide new code and screenshots.

 I changed two file to finish this lab, one is “buffer.h”, I add a struct definition. Just as P1 shows.

                          P1   

   The other one is in “main.c”.  In this file, I changed a lot. Mostly I add an analysis of TCP header and decode the data in telnet so I can get the username and the password.

I add another three functions to help me finish the job. int bumatchmess(char* mes,char* tomatch) and int matchmess(char* mes,char* tomatch) are match functions. But they have some differences. I will give the code just as P2 and P3 shows. Both of them are easy to understand. The last function is void charAdd(char* p,char c). It just like strcat(), but another parameter is a char type. The code is in P4.

  The code of analysis of TCP header and decode the data in telnet is too long, so I send all the code file after I changed to you. You can get the detail in my code file.

 

P2

                              P3

                              P4

Let’s see the result. I opened two Virtual computer. Both of them run Ubuntu system. And they are in the same network. Just as P5 and P6 shows.

                              P5

                           P6

One of them will minisniff and be the telnet server, the other one will be the telnet client.

In the client, we can see the result in P7. In there, I input “hello” as the login name. The password I input is “nopass2”.

                          P7

  Let’s see what happened to the minisniff. Just as the P8、P9 and P10 shows. In P10, we can see that we get the username of “hello” and the password of “nopass2”. So it decode successful.

 So we finished the lab.

                           P8

                          P9

                          P10

  At last, again, the detail of code is in the code file, I send them with this report.

 

第二篇:计算机网络实验题目

实验一 TCP协议的模拟

1、实验目的:

要求学生掌握Socket编程 及滑动窗口协议

2、实验内容:

i. 实现滑动窗口协议,窗口大小为5

ii. 必须采用应答机制、超时计数器技术、帧编号盘

重技术、重传技术

iii. 校验和技术

a) 校验和s的计算:设要发送n字节,bi为第i个字,s=(b0+b1+…+bn) mod 256

iv. 在接收端,设置随机数,根据随机数执行相关操

作,0代表正常,1代表帧丢失,2代表帧出错,3代表应答帧丢失(即不发生应答帧) v. 必须使用图形界面,

a) 按批次(发送端一次发送的报文)显示相关内容

b) 发送端:显示发送的数据、是否重传、本次帧序号、接收到的应答帧的序号

c) 接收端:显示接收到的数据、本次帧序号、本次随机选择的出错情况、发送应答帧的序号、是否重复

实验二 截获IP数据包并加以分析

1、实验目的:

要求学生掌握Socket编程中原始套接字的技术

2、实验内容:

i. 使用两种方式,一种是采用现有的工具和API(选

作),一种是自己做

ii. 要求学生掌握截获报文的技术

iii. 分析是UDP还是TCP报文

iv. 分析程序收、发双方的:端口号、IP地址

v. 分析IP数据报的总长度、标识、片偏移量、生

存时间

vi. 必须使用图形界面,显示第ii、iii条要求的信息 vii. 不能使用现成控件

实验三 建立聊天工具

1、实验目的:

要求学生掌握Socket编程中流套接字的技术

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术 ii. 必须掌握多线程技术,保证双方可以同时发送 iii. 建立聊天工具

iv. 可以打开多个窗口和多个人同时进行聊天 v. 必须使用图形界面,显示双方的语录

实验四 传输文件

1、实验目的:

要求学生掌握Socket编程中流套接字的技术

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术

ii. 对文件进行分割(每片256字节),分别打包传

a) 发送前,通过协商,发送端告诉接收端发送片数

b) 报头为学号、姓名、本次分片在整个文件中的位置

c) 报尾为校验和:校验和s的计算:设要发送n字节,bi为第i个字,s=(b0+b1+…+bn) mod 256 iii. 接收方进行合并

iv. 必须采用图形界面

a) 发送端可以选择文件,本次片数

b) 接收端显示总共的片数,目前已经接收到的文件片数,收完提示完全收到

实验五 发送邮件

1、实验目的:

要求学生掌握Socket编程中流套接字的技术,以及邮件的发送

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术

ii. 不能采用现有的工具,必须自己一步一步,根据

协议进行操作

iii. 了解邮件发送格式

iv. 必须采用图形界面,可以编辑发送内容 v. 可选,建立自己的邮件服务器

vi. 发送邮件可以发给自己的邮件服务器,也可以发

给已知邮件服务器

vii. 要求可以查看得到发送的邮件

实验六 实现ping命令

1、实验目的:

要求学生掌握Socket编程技术,以及ICMP协议

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术

ii. 不能采用现有的工具,必须自己一步一步,根据

协议进行操作

iii. 了解ping报文的格式和步骤,要求符合ICMP

协议并组建报文

iv. 在一秒钟内,如果收到,则为成功,如果收不到,

则失败

v. 必须采用图形界面,查看收到回应的结果

vi. 可以通过程序,查看子网中有哪些主机可以ping

实验七 实现TRACEROUTE命令

1、实验目的:

要求学生掌握Socket编程技术,以及ICMP协议

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术

ii. 不能采用现有的工具,必须自己一步一步,根据

协议进行操作

iii. 了解Traceroute报文的格式和步骤,要求符合

ICMP协议并组建报文

iv. 在一秒钟内,如果收到,则为成功,如果收不到,

则失败

v. 必须采用图形界面,查看每次收到回应的结果 vi. 可以通过程序,查看经过了哪些节点

实验八 解析DNS

1、实验目的:

要求学生掌握Socket编程技术,以及DNS协议

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术 ii. 不能采用现有的工具,必须自己一步一步,

协议进行操作

iii. 了解DNS报文的格式和步骤

iv. 必须采用图形界面,查看收到回应的结果 根据

实验九 仿真telnet

1、实验目的:

要求学生掌握Socket编程技术

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术 ii. 客户端敲的字符,必须在服务器端即使显示 iii. 远程连接一台计算机,把要求对方执行的程序

(自己准备加减乘除四则运算的程序)、参数传给对方,然后执行完毕,把运行结果传回 iv. 必须采用图形界面,查看收到回应的结果

实验十 发送Ethernet ARP包

1、实验目的:

要求学生掌握Socket编程技术及ARP协议

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术

ii. 构造ARP包:获取自己的MAC地址(可以手工

输入)和IP地址,根据输入的目的IP地址(add),组成ARP包并发送;

iii. 本机安装一个抓包软件(也可以自己利用Socket

写),运行该软件检查是否能收到目的主机发出的ARP地址解析请求与应答。

iv. 必须采用图形界面,查看收到回应的结果

v. 提示:IP报文的目的地址为add,帧的目的MAC

地址为广播地址(自己把帧组好,用raw直接传)

实验十一 模拟CSMA/CD协议

1、实验目的:

要求学生掌握Socket编程技术及CSMA/CD协议工作过程

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术 ii. 程序模拟主机随机发送(6秒内选择随机数) iii. 8台主机(程序),主机号为1-8

iv. 发送前,查看当前是否有其它程序在发送; v. 如果没有其它程序发送,则发送自己的数据内容

(内容格式为:源目主机号+“:”+目的主机号+“:”+Hello Baby,发送3秒钟,),进行广播(也可以采用点对点发给每一个其它程序) vi. 假定数据传输过程为1秒(即接收端延迟一秒才

能感知到有数据传输。相应的,前面的探测过程是指在接到数据一秒前,均认为没有其它节点发送)

vii. 发送过程中,如果发现碰撞(即,在收到其它

程序发送的数据一秒之前,自己已经发送数据了),则停止重发

viii. 等待一个随机时间(4秒)重新开始

ix. 必须采用图形界面,每个程序可以设置自己的主

机号,查看运行过程

实验十二 模拟令牌总线协议

1、实验目的:

要求学生掌握Socket编程技术及令牌总线协议工作过程

2、实验内容:

i. 要求学生掌握利用Socket进行编程的技术 ii. 8台主机(程序),主机号为1-8

iii. 产生一个令牌,绕着8台主机依照主机号进行轮

转(即1号发给2号,2号发给3号,...,8号发给1号),一秒钟转移一次

iv. 程序模拟主机随机发送(6秒内选择随机数)(内,

容格式为:源目主机号+“:”+目的主机号+“:”+Hello Baby)

v. 发送前,查看当前是否有有令牌,如果没有令牌,

则等待

vi. 如果有令牌,可以发送数据(目的主机号随机产

生),假定数据传输过程为2秒,此时不再发送令牌,只发送数据

vii. 数据依然按照主机号发送

viii. 接收方接受后,显示内容

ix. 发送主机最后收到自己的数据,重新发送令牌 x. 必须采用图形界面,每个程序可以设置自己的主

机号,查看运行过程

相关推荐