Scapy常用操作和命令(2)



send方法用来在3层发送报文

>>> send(IP(dst="1.2.3.4")/ICMP())

.

Sent 1 packets.

使用loop参数循环发送(Ctrl+C终止),inter表示发送时间间隔

>>> send(IP()/ICMP(),loop=1,inter=0.5)

......^C

Sent 6 packets.

 

sendp方法用来在2层发送报文

>>> sendp(Ether()/IP(dst="1.2.3.4",ttl=(1,4)), iface="eth1")

....

Sent 4 packets.

>>> sendp("I'm travelling on Ethernet", iface="eth1", loop=1, inter=0.2)

................^C

Sent 16 packets.

 

sr1方法在3层发送报文并返回第一个响应报文

>>> ans=sr1(IP()/ICMP())

Begin emission:

Finished to send 1 packets.

....................................................................................................^C

Received 100 packets, got 0 answers, remaining 1 packets

>>> ans=sr1(IP(dst="www.baidu.com")/ICMP())

Begin emission:

....Finished to send 1 packets.

..*

Received 7 packets, got 1 answers, remaining 0 packets

 

sr方法在3层发送报文并返回所有响应报文

>>> ans, unans=sr(IP(dst="www.baidu.com", src="172.31.100.0/24")/ICMP())

Begin emission:

......................................................................................................................................................................................................................................................................................................*..................................................................*.....................................................................................................................Finished to send 256 packets.

...........................................................................................................................................................................................................................................^C

Received 714 packets, got 2 answers, remaining 254 packets

>>> ans

<Results: TCP:0 UDP:0 ICMP:2 Other:0>

>>> unans

<Unanswered: TCP:0 UDP:0 ICMP:254 Other:0>

 

srpsrp1方法为srsr1方法对应的2层方法

>>> ans, unans=srp(Ether()/IP(dst="www.baidu.com", src="172.31.100.0/24")/ICMP())

.Begin emission:

.......................................................................................................................................................................................................................................................*..Finished to send 256 packets.

.............................................................................................................................................................................................................................................................................................................................^C

Received 568 packets, got 1 answers, remaining 255 packets

 

srloop方法循环发送3层报文并打印结果

>>> ans, unans=srloop(IP(dst="www.baidu.com")/ICMP())

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

RECV 1: IP / ICMP 119.75.218.70 > 172.31.100.222 echo-reply 0 / Padding

^C       

Sent 8 packets, received 8 packets. 100.0% hits.

>>> ans

<Results: TCP:0 UDP:0 ICMP:8 Other:0>

 

srploop方法循环发送2层报文并打印结果

>>> ans, unans=srloop(Ether()/IP(dst="www.baidu.com")/ICMP())

WARNING: Mac address to reach destination not found. Using broadcast.

fail 1: Ether / IP / ICMP 172.31.100.222 > 119.75.217.109 echo-request 0

WARNING: Mac address to reach destination not found. Using broadcast.

fail 1: Ether / IP / ICMP 172.31.100.222 > 119.75.217.109 echo-request 0

WARNING: Mac address to reach destination not found. Using broadcast.

fail 1: Ether / IP / ICMP 172.31.100.222 > 119.75.217.109 echo-request 0

WARNING: Mac address to reach destination not found. Using broadcast.

fail 1: Ether / IP / ICMP 172.31.100.222 > 119.75.217.109 echo-request 0

WARNING: Mac address to reach destination not found. Using broadcast.

fail 1: Ether / IP / ICMP 172.31.100.222 > 119.75.217.109 echo-request 0

WARNING: Mac address to reach destination not found. Using broadcast.

send...  

Sent 5 packets, received 0 packets. 0.0% hits.

 

srflood方法使用flooding的方式快速发包并接收回包

>>> ans, unans=srflood(IP(dst="www.baidu.com")/ICMP())

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

IP / ICMP 119.75.217.109 > 172.31.100.222 echo-reply 0 / Padding

……

>>> ans

<Results: TCP:0 UDP:0 ICMP:1 Other:0>

>>> unans

<Unanswered: TCP:0 UDP:0 ICMP:255 Other:0>

>>> unans.summary()

Ether / IP / ICMP 172.31.100.84 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.78 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.71 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.104 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.98 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.64 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.3 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.36 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.117 > 119.75.218.70 echo-request 0

Ether / IP / ICMP 172.31.100.30 > 119.75.218.70 echo-request 0

……

 

发包的方法可以使用下面的3个参数

inter:定义发包时相邻两个包的时间间隔(单位s

retry:定义重传次数(可正可负,例如3表示重传3次,-3表示scapy会尝试依次重传unanswered直到没有任何新的answer报文,但是最多重试3次)

timeout:定义认为丢包的timeout时间(单位s

>>> ans, unans = sr(IP(src="172.31.100.149/30", dst="www.baidu.com")/TCP(dport=80), inter=0.5, retry=-3, timeout=1)

.Begin emission:

....................................................................................................................................................................................*...............................................................................................................................................................................................................................................................................................Finished to send 4 packets.

..............................................................................................................................................................................................................................Begin emission:

...................................................................................................................................................................................................................................................................................................................................................Finished to send 3 packets.

.......................................................................................................................................................................................................................................Begin emission:

.................................................................................................................................................................................................................................................................................................................................................................................Finished to send 3 packets.

.........................................................................................................................................................................................................................Begin emission:

....................................................................................................................................................................................................................................................................................................................................Finished to send 3 packets.

..............................................................................................................................................................................................................................

Received 2393 packets, got 1 answers, remaining 3 packets

 

 

fuzz方法可以修改对象中不参与计算的属性的默认值(例如校验和)为一个随机值,通过fuzz方法可以在循环中快速构建大量随机报文。

>>> send(IP(dst="target")/fuzz(UDP()/NTP(version=4)),loop=1)

................^C

Sent 16 packets.

  • 88
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值