16 Star 44 Fork 45

现任明教教主-乾颐堂 / qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.04.20 检查收到的TTL与测试的TTL是否匹配 2.21 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-04-20 14:45 . new file
#!/usr/bin/python3.4
# -*- coding=utf-8 -*-
#本脚由亁颐堂现任明教教主编写,用于乾颐盾Python课程!
#教主QQ:605658506
#亁颐堂官网www.qytang.com
#乾颐盾是由亁颐堂现任明教教主开发的综合性安全课程
#包括传统网络安全(防火墙,IPS...)与Python语言和黑客渗透课程!
import logging
logging.getLogger("scapy.runtime").setLevel(logging.ERROR)
from scapy.all import *
import time
import optparse
from IPy import IP as IPTEST
ttlValues = {}
THRESH = 5
def checkTTL(ipsrc, ttl):
if IPTEST(ipsrc).iptype() == 'PRIVATE':
return
if not ipsrc in ttlValues:
pkt = sr1(IP(dst=ipsrc)/ICMP(), retry=0, timeout=1, verbose=0, iface='eno33554944')
ttlValues[ipsrc] = pkt[0].fields['ttl']
if abs(int(ttl) - int(ttlValues[ipsrc])) > THRESH:
print('\n[!] 检查到可能的欺骗攻击,来至于:' + ipsrc)
print('[!] TTL: ' + ttl + ' , 真实的TTL为: ' + str(ttlValues[ipsrc]))
def testTTL(pkt):
try:
if pkt.haslayer(IP):
ipsrc = pkt.getlayer(IP).src
ttl = str(pkt.ttl)
checkTTL(ipsrc, ttl)
except:
pass
def main():
parser = optparse.OptionParser('程序使用方法: -i<interface> -t<thresh>')
parser.add_option('-i', dest = 'iface', type = 'string', help = '指定网络接口')
parser.add_option('-t', dest = 'thresh', type = 'int', help = '指定TTL误差的阈值')
(options, args) = parser.parse_args()
if options.iface == None:
use_iface = 'eno33554944'
else:
use_iface = options.iface
if options.thresh != None:
THRESH = options.thresh
else:
THRESH = 5
sniff(prn = testTTL, store = 0, iface=use_iface)
if __name__ == '__main__':
main()
################################################################################
[root@Fedora hacker]# ./检查收到的TTL与测试的TTL是否匹配.py
[!] 检查到可能的欺骗攻击来至于:202.100.1.139
[!] TTL: 16 , 真实的TTL为: 64
[!] 检查到可能的欺骗攻击来至于:202.100.1.139
[!] TTL: 16 , 真实的TTL为: 64
[!] 检查到可能的欺骗攻击来至于:202.100.1.139
[!] TTL: 16 , 真实的TTL为: 64
[!] 检查到可能的欺骗攻击来至于:202.100.1.139
[!] TTL: 16 , 真实的TTL为: 64
Python
1
https://gitee.com/qytang/qytang_Python.git
git@gitee.com:qytang/qytang_Python.git
qytang
qytang_Python
qytang_Python
master

搜索帮助