tcptracerte参数_scapy学习笔记(3)发送包,SYN及TCP traceroute 扫描
转载请注明:@小五义:http://www.cnblogs/xiaowuyi
在安装完scapy(前两篇笔记有介绍)后,linux环境下,执行sudo scapy运行scapy。
一、简单的发送包
1、send()在第三层发送数据包,但没有接收功能。如:
>>> send(IP(dst="www.baidu.com",ttl=1)/ICMP())
.
Sent1 packets.
这里相当于ping了下百度,ttl=1
2、sendp(),在第二层发送数据包,同样没有接收功能。如:
>>> sendp(Ether()/IP(dst="www.baidu.com",ttl=1)/ICMP())
WARNING: Mac address to reach destination not found. Using broadcast.
.
Sent1packets.>>> sendp(Ether()/IP(dst="127.0.0.1",ttl=1)/ICMP())
.
Sent1 packets.
3、sr(),在第三层发送数据包,有接收功能。如:
>>> p=sr(IP(dst="www.baidu.com",ttl=1)/ICMP())
Begin emission:
..Finished to send1packets.
.*Received4 packets, got 1 answers, remaining 0packets>>>p
(, )>>> p[0]
>>> p[0].show()0000 IP / ICMP 27.214.222.160 > 61.135.169.105 echo-request 0 ==> IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror / ICMPerror
再比如,连续发送ttl=1,2,3,4四个包的情况
>>> p=sr(IP(dst="www.baidu.com",ttl=(1,4))/ICMP())
Begin emission:
Finished to send4packets.
.*.*.*.*Received8 packets, got 4 answers, remaining 0packets>>>p
(, )>>> p[0].show()0000 IP / ICMP 27.214.222.160 > 61.135.169.125 echo-request 0 ==> IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror0001 IP / ICMP 27.214.222.160 > 61.135.169.125 echo-request 0 ==> IP / ICMP 222.132.4.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror0002 IP / ICMP 27.214.222.160 > 61.135.169.125 echo-request 0 ==> IP / ICMP 119.190.5.126 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror0003 IP / ICMP 27.214.222.160 > 61.135.169.125 echo-request 0 ==> IP / ICMP 112.253.4.197 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror>>>
4、sr1(),在第三层发送数据包,有接收功能,但只接收第一个包。以上面的发送四个包为例:
>>> q=sr1(IP(dst="www.baidu.com",ttl=(1,4))/ICMP())
Begin emission:
Finished to send4packets.
.*.*.*.*Received8 packets, got 4 answers, remaining 0packets>>>q>>>
>>>q.show()
###[ IP ]###
version= 4Lihl= 5Ltos= 0xc0len= 56id= 4773flags=frag= 0Lttl= 255proto=icmp
chksum= 0xb611src= 27.214.220.1dst= 27.214.222.160\options\
###[ ICMP ]###
type= time-exceeded
code= ttl-zero-during-transit
chksum= 0xf4ffunused= 0###[ IPinICMP ]###
version= 4Lihl= 5Ltos= 0x0len= 28id= 1flags=frag= 0Lttl= 1proto=icmp
chksum= 0xd879src= 27.214.222.160dst= 61.135.169.105\options\
###[ ICMPinICMP ]###
type= echo-request
code= 0chksum= 0xf7ffid= 0x0seq= 0x0
5、srloop(),在第三层工作,如下:
>>> p=srloop(IP(dst="www.baidu.com",ttl=1)/ICMP())
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror^C
Sent5 packets, received 5 packets. 100.0%hits.>>> p=srloop(IP(dst="www.baidu.com",ttl=1)/ICMP(),inter=3,count=2)
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
RECV1: IP / ICMP 27.214.220.1 > 27.214.222.160 time-exceeded ttl-zero-during-transit / IPerror /ICMPerror
Sent2 packets, received 2 packets. 100.0% hits.
这里第一条语句在执行时,将会不停的ping百度,第二条执行时每隔3秒ping一次,一共执行两次。inter表示间隔,count记录次数。
6、srp()、srp1()、srploop()与上面3、4、5相同,只是工作在第二层。
二、SYN扫描
SYN扫描:也叫“半开式扫描”(half-open scanning),因为它没有完成一个完整的TCP连接。这种方法向目标端口发送一个SYN分组(packet),如果目标端口返回SYN/ACK,那么可以肯定该端口处于检听状态;否则,返回的是RST/ACK。
>>> sr1(IP(dst="61.135.169.105")/TCP(dport=80,flags="S"))
Begin emission:
Finished to send1packets.
.*Received2 packets, got 1 answers, remaining 0packets>
>>> sr1(IP(dst="61.135.169.105")/TCP(dport=81,flags="S"))
Begin emission:
Finished to send1packets.
.*Received2 packets, got 1 answers, remaining 0packets>>>
从结果看,当扫描百度(61.135.169.105)的80端口时,返回的包中ACK=1或者flags=SA,说明该端口处于监听状态,当扫描81端口时,无ACK=1,或者flags=,说明其未处于监听状态。
如果要扫描多个端口,可以使用以下语句,如扫描百度的80-83端口:
>>>sr(IP(dst="www.baidu.com")/TCP(dport=(80,83),flags="S"))
如要扫描21,80,3389等端口:
>>>sr(IP(dst="www.baidu.com")/TCP(dport=[21,80,3389],flags="S"))
简单要显示结果:
>>>ans,unans=_>>>ans.summary(lambda(s,r):r.sprintf("%TCP.sport% \t %TCP.flags%"))
http SA81RA82RA83 RA
这里我在扫描80-83时,总是在不停的扫,用ctrl+C停止后,只能得到两个结果,目前没搞明白是什么原因。如下:
>>> sr(IP(dst="www.baidu.com",ttl=56)/TCP(dport=(80,83),flags="S"))
Begin emission:
Finished to send4packets.
.*.*.................................................................................^C
Received85 packets, got 2 answers, remaining 2packets
(, )>>> ans,unans=_>>>ans.summary()
IP/ TCP 27.214.134.124:ftp_data > 61.135.169.105:http S ==> IP / TCP 61.135.169.105:http > 27.214.134.124:ftp_data SA
IP/ TCP 27.214.134.124:ftp_data > 61.135.169.105:82 S ==> IP / ICMP 123.125.248.42 > 27.214.134.124 dest-unreach communication-prohibited / IPerror /TCPerror>>> ans.summary(lambda(s,r):r.sprintf("%TCP.sport% \t %TCP.flags%"))
http SA?? ??
三、TCP traceroute
traceroute:用来追踪出发点到目的地所经过的路径,通过Traceroute我们可以知道信息从你的计算机到互联网另一端的主机是走的什么路径。当然每次数据包由某一同样的出发点(source)到达某一同样的目的地(destination)走的路径可能会不一样,但基本上来说大部分时候所走的路由是相同的。
>>> ans,unans=sr(IP(dst="www.baidu.com",ttl=(4,25),id=RandShort())/TCP(flags=0x2))
Begin emission:
...*.*.*.*.*.*.*.*.*.*.*Finished to send 22packets.
.*.*.*.*.*.*.*.*.*.*....^C
Received48 packets, got 21 answers, remaining 1packets>>> for snd,rcv inans:
... print snd.ttl,rcv.src,isinstance(rcv.payload,TCP)
...4 112.253.4.177False5 219.158.98.221False6 124.65.194.22False7 124.65.58.182False8 123.125.248.42False9 61.135.169.105True10 61.135.169.105True11 61.135.169.105True12 61.135.169.105True13 61.135.169.105True14 61.135.169.105True15 61.135.169.105True16 61.135.169.105True17 61.135.169.105True18 61.135.169.105True19 61.135.169.105True20 61.135.169.105True21 61.135.169.105True22 61.135.169.105True23 61.135.169.105True24 61.135.169.105 True
tcptracerte参数_scapy学习笔记(3)发送包,SYN及TCP traceroute 扫描相关推荐
- 《Go语言圣经》学习笔记 第十章 包和工具
<Go语言圣经>学习笔记 第十章 包和工具 目录 包简介 导入路径 包声明 导入声明 包的匿名导入 包和命名 工具 注:学习<Go语言圣经>笔记,PDF点击下载,建议看书. G ...
- R语言可视化学习笔记之ggridges包绘制山峦图
作者:严涛 浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源. 严涛老师的绘图教程还有: gganimate |诺奖文章里面的动图绘制教程来了!! ggplot2学习笔记之 ...
- 【转】:TCP/IP详解学习笔记(4)-ICMP协议,ping和Traceroute
TCP/IP详解学习笔记(4)-ICMP协议,ping和Traceroute 分类: TCP/IP详解学习笔记计算机网络2006-04-20 18:147970人阅读评论(1)收 ...
- R语言可视化学习笔记之ggridges包
作者:严涛 浙江大学作物遗传育种在读研究生(生物信息学方向)伪码农,R语言爱好者,爱开源. 严涛老师的绘图教程还有: gganimate |诺奖文章里面的动图绘制教程来了!! ggplot2学习笔记之 ...
- 影像组学视频学习笔记(27)-SimpleITK包介绍、Li‘s have a solution and plan.
本笔记来源于B站Up主: 有Li 的影像组学的系列教学视频 本节(27)主要讲解: 功能强大的图像处理工具SimpleITK包 视频中李博士演示了SimpleITK的两个基本功能:图像格式转换以及图像 ...
- Python数据分析三剑客学习笔记Day6——matplotlib包的使用:数据可视化,简单绘制柱状图、曲线图、饼图、频率分布直方图
本文是视频Python数据分析三剑客 数学建模基础 numpy.pandas.matplotlib的学习笔记. -------------------------------------------- ...
- Python数据分析三剑客学习笔记Day3——pandas包的使用:认识series类型,DataFrame类型,读取excel表格数据及数据操作
本文是视频Python数据分析三剑客 数学建模基础 numpy.pandas.matplotlib的学习笔记. -------------------------------------------- ...
- oracle修改asm参数文件,学习笔记:Oracle RAC参数文件管理 修改创建asm中的spfile文件...
天萃荷净 Oracle rac创建修改asm中的spfile文件内容 create spfile to asm --查看sid SQL> show parameter instance_name ...
- ROS学习笔记之——robot_localization包
之前博客已经介绍过robot_pose_ekf功能包以及(extended)kalman滤波的原理< ROS学习笔记之--EKF (Extended Kalman Filter) node 扩展 ...
最新文章
- Copy复制命令兼容各种浏览器(等同于触发Ctrl+C或者Command⌘+C)
- java在网页填写集数据,java网页数据采集(中篇-数据存储)
- python程序设计实验教程 翟萍 第五章答案_Python程序设计实验教程
- 赶集网人事调整:三月内两副总离职
- C++ 虚函数和虚表
- C++是什么?怎么学?学完了能得到什么?
- xfce 双击窗口标题栏无法最大化解决办法
- SpringBoot 实现Session共享
- GoogLeNet网络的Pytorch实现
- Javascript第三章循环最后一种方法for..in与for区别第二课
- Android信鸽推送全解
- Echarts实现柱状图下钻功能
- office新建文件打开提示文件格式或扩展名无效
- 深度学习之卷积神经网络CNN详解
- C++语言Switch函数使用小贴士
- Win10打开软件提示comdlg32.ocx文件丢失?
- java-通信-ip-1
- 制作MacOS U盘安装盘教程
- Android 布局优化小结
- 科研实验如何起草一份通俗易懂的SOP?
热门文章
- (毕设1)爬虫+mysql+flask+echarts实现网站数据可视化(附源码)
- c语言-循环打印星号图形*
- Vue.js学习的第一天
- centos7 安装haproxy+rabbitmq高可用集群
- HTML5期末大作业:简单的学生网页作业源码 基于 html css js仿腾讯课堂首页
- 强化学习系列之Policy Gradient算法
- python代码没有反应_Python代码不执行。没有显示错误
- 通过制造奶茶来深入浅说模板方法-设计模式-java实现
- mysql8.0 服务移除_MySQL8.0中已移除的特性,功能
- php日历类 农历,PHP完整的日历类(CLASS)