1、Network(网络)

Scapy

  • 一款强大的交互式数据报分析工具,可用作发送、嗅探、解析和伪造网络数据包(有线 or 无线) ```python

    scan.py

    — coding: utf-8 —

import logging logging.getLogger(“scapy.runtime”).setLevel(logging.ERROR) from scapy.all import *

def TCP_connect_scan(dst_ip,src_port,dst_port): tcp_pkt=IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags=’S’)#’S’:SYN,发送方请求建立连接 tcp_resp = sr1(tcp_pkt,iface=’eth1’,timeout=3,verbose=0)#verbose=0:不打印反馈信息

  1. if tcp_resp==None:#无回应
  2. print('Port %d Filtered' % dst_port)
  3. elif tcp_resp.haslayer(TCP):#有回应
  4. if tcp_resp.getlayer(TCP).flags==0x12:#接收方回应为SYN/ACK
  5. tcp_pkt_tmp=IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags='AR')#'AR':发送方将ACKRST同时发送给接收方
  6. tcp_resp_tmp=sr(tcp_pkt_tmp,iface='eth1',timeout=3,verbose=0)
  7. print('Port %d Open' % dst_port)
  8. elif (tcp_resp.getlayer(TCP).flags == 0x14):#回应为RST
  9. print('Port %d Closed' % dst_port)

def TCP_stealth_scan(dst_ip,src_port,dst_port): steal_pkt=IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags=’S’)#’S’:SYN,发送方请求建立连接 steal_resp = sr1(steal_pkt,iface=’eth1’,timeout=3,verbose=0)

  1. if steal_resp==None:#无回应
  2. print('Port %d Filtered' % dst_port)
  3. elif steal_resp.haslayer(TCP):#有回应
  4. if steal_resp.getlayer(TCP).flags==0x12:#接收方回应为SYN/ACK
  5. steal_pkt_tmp=IP(dst=dst_ip)/TCP(sport=src_port,dport=dst_port,flags='R')#'R':发送方将RST发送给接收方
  6. steal_resp_tmp=sr(steal_pkt_tmp,timeout=3,verbose=0)
  7. print('Port %d Open' % dst_port)
  8. elif (steal_resp.getlayer(TCP).flags == 0x14):#接收方回应为RST
  9. print('Port %d Closed' % dst_port)
  10. elif steal_resp.haslayer(ICMP):
  11. if int(steal_resp.getlayer(ICMP).type)==3 and int(steal_resp.getlayer(ICMP).code) in [1,2,3,9,10,13]:#目的结点不可达
  12. print('Port %d Filtered' % dst_port)

def TCP_XMAS_scan(dst_ip,src_port,dst_port): xmas_pkt = IP(dst=dst_ip)/TCP(dport=dst_port,flags=”FPU”)#FIN - 结束; 结束会话;P : PUSH - 推送; 数据包立即发送;U : URG - 紧急 xmas_resp = sr1(xmas_pkt,timeout=3,verbose=0) if xmas_resp==None:#无回应 print(‘Port %d Filtered or Open’ % dst_port) elif xmas_resp.haslayer(TCP):#有回应 if (xmas_resp.getlayer(TCP).flags == 0x14):#RST print(‘Port %d Closed’ % dst_port) elif xmas_resp.haslayer(ICMP): if(int(xmas_resp.getlayer(ICMP).type)==3 and int(xmas_resp.getlayer(ICMP).code) in [1,2,3,9,10,13]):#目的结点不可达 print(‘Port %d Filtered’ % dst_port)

def UDP_scan(dst_ip,src_port,dst_port): udp_resp = sr1(IP(dst=dst_ip)/UDP(dport=dst_port),timeout=3,verbose=0,iface=’eth1’) print str(type(udp_resp)) if udp_resp==None: retrans = [] for count in range(0,3): retrans.append(sr1(IP(dst=dst_ip)/UDP(dport=dst_port),timeout=3,verbose=0)) for item in retrans: if (item!=None): UDP_scan(dst_ip,dst_port) print (‘Port %d Filtered or Open’ % dst_port) elif udp_resp.haslayer(UDP): print (‘Port %d Open’ % dst_port) elif udp_resp.haslayer(ICMP): if int(udp_resp.getlayer(ICMP).type)==3 and int(udp_resp.getlayer(ICMP).code)==3: print (‘Port %d Closed’ % dst_port) elif int(udp_resp.getlayer(ICMP).type)==3 and int(udp_resp.getlayer(ICMP).code) in [1,2,9,10,13]: print (‘Port %d Filtered’ % dst_port)

def Help(): print ‘’’ PORT SCAN 1.0 Usage:[Scan Type][Destination Ip][Destination Port] Scan Type: Choose the scan type. tcs : TCP connect scan tss : TCP stealth scan txs : TCP XMAS scan us : UDP scan Default: The default destination IP address is 127.0.0.1 The default port is 80 ‘’’

if name == ‘main‘:

  1. print '''
  2. -------------------------------------------------
  3. | |
  4. | |
  5. | 欢迎使用扫描工具PORT SCAN,需要帮助请输入help |
  6. | |
  7. | |
  8. -------------------------------------------------
  9. '''
  10. print ">> ",
  11. input=raw_input()
  12. while input!='exit':
  13. if input == 'help':
  14. Help()
  15. else:
  16. s2=['','','']
  17. s=input.split(' ')
  18. for i in range(len(s)):
  19. s2[i]=s[i]
  20. scan_type=s2[0]
  21. dst_ip=s2[1]
  22. dst_port=s2[2]
  23. dst_ip = dst_ip if dst_ip !='' else '127.0.0.1'
  24. src_port = RandShort()
  25. dst_port=int(dst_port) if dst_port!='' else 80
  26. if scan_type=='tcs':
  27. TCP_connect_scan(dst_ip,src_port,dst_port)
  28. elif scan_type=='tss':
  29. TCP_stealth_scan(dst_ip,src_port,dst_port)
  30. elif scan_type=='txs':
  31. TCP_XMAS_scan(dst_ip,src_port,dst_port)
  32. elif scan_type=='us':
  33. UDP_scan(dst_ip,src_port,dst_port)
  34. else:
  35. print "Please input the correct scan type.More information please input 'help'."
  36. print ">> ",
  37. input=raw_input()
  1. <a name="EnD9e"></a>
  2. # 2、Debugging and Reverse Engineering(调试和逆向工程分析)
  3. <a name="BXtrR"></a>
  4. ## r2pipe
  5. - Radare2的python接口
  6. - 反汇编、分析数据、打补丁、比较数据、搜索、替换、虚拟化等等,同时具备超强的脚本加载能力,它可以运行在几乎所有主流的平台(GNU/Linux, .Windows *BSD, iOS, OSX, Solaris…)并且支持很多的cpu架构以及文件格式。
  7. <a name="UKmMp"></a>
  8. ## IDAPython
  9. - IDA Pro插件,整合了Python编程语言,并支持在IDA Pro中运行脚本<br />
  10. <a name="MEDY9"></a>
  11. ## pefile
  12. - 读取并操作PE文件
  13. <a name="ImGnZ"></a>
  14. ## Web
  15. l Requests:一个简单友好的HTTP库<br />l HTTPie:有好的类cURL命令行HTTP客户端<br />l ProxMon:处理代理日志,报告发现的问题<br />l WSMap:寻找Web服务节点,扫描文件<br />l Twill:通过命令行接口浏览Web,支持自动化Web测试<br />l Ghost.py:Webkit Web客户端<br />l Windmill:允许我们自动化测试和调试Web应用的Web测试工具<br />l FunkLoad:该工具允许加载多功能的Web应用测试组件<br />l spynner:支持Javascript/AJAX的可编程Web浏览模块<br />l python-spidermonkey:桥接Mozilla SpiderMonkeyJavaScript引擎,允许对JavaScript脚本和函数进行测试和调用<br />l mitmproxy:支持SSL的HTTP代理,可通过命令行接口实时拦截和编辑网络流量<br />l pathod / pathoc:可向HTTP客户端和服务求提供畸形测试用例
  16. <a name="q5trq"></a>
  17. # 3、Forensics(信息取证)
  18. l Volatility:从RAM样本中提取数据
  19. <a name="ePOb9"></a>
  20. # 4、Malware Analysis(恶意软件分析)
  21. l pyew:命令行十六进制编辑器和反汇编工具,主要用于分析恶意软件<br />l Exefilter:过滤邮件、Web页面或文件中的文件格式,检测常见文件格式并能移除活动内容<br />l pyClamAV:向Python软件中添加病毒检测功能<br />l jsunpack-n:通用的JavaScript拆包工具,可枚举浏览器功能并检测漏洞,针对的是浏览器和浏览器插件漏洞<br />l yara-python:识别和分类恶意软件样本<br />l phoneyc:纯蜜罐系统
  22. <a name="p3K5F"></a>
  23. # 5、PDF
  24. l Didier Stevens’ PDF tools: 分析、识别和创建PDF文件,包括PDFiD、pdf-parser、make-pdf和mPDF<br />l Opaf:开源PDF分析框架,可将PDF转换成可分析和修改的XML树<br />l Origapy:封装了Origami Ruby模块,可对PDF文件进行安全审查<br />l pyPDF:纯PDF工具,可提取、合并、加密和解密PDF内容<br />l PDFMiner:从PDF文件中提取文字内容<br />l python-poppler-qt4:绑定了Poppler PDF库,支持Qt4
  25. <a name="n8byE"></a>
  26. # 6、杂项
  27. l InlineEgg:Python工具箱,可用于编写小型汇编程序<br />l Exomind:开发开源智能模块的框架,以社交网络服务、搜索引擎和即时消息为中心<br />l RevHosts:根据给定IP地址枚举出虚拟主机<br />l simplejson:使用了 Google AJAX API的JSON解码/编码器<br />l PyMangle:用于创建渗透测试工具所用字典(Wordlist)的命令行工具/代码库<br />l Hachoir:查看和编辑代码流中的数据域<br />l py-mangle:另一款用于创建渗透测试工具所用字典(Wordlist)的命令行工具/代码库
  28. <a name="4c7c1424"></a>
  29. # 7、其他有用的库和工具
  30. l IPython:多功能增强型交互式Python Shell<br />l Beautiful Soup:爬虫可能会用到的HTML解析器<br />l Mayavi:3D科学数据虚拟化工具<br />l RTGraph3D:创建3D动态图像<br />l Twisted:事件驱动型网络引擎<br />l Suds:用于Web服务的轻量级SOAP客户端<br />l M2Crypto:最完整的OpenSSL封装器<br />l NetworkX:图形库<br />l Pandas:可提供高性能数据结构的数据分析工具<br />l pyparsing:通用解析模块<br />l lxml:采用Python编写的功能丰富且易于使用的XML和HTML工具<br />l Whoosh:纯Python实现的全功能文本索引、搜索库<br />l Pexpect:控制或实现其他程序的自动化,类似Don Libes `Expect` system<br />l Sikuli:虚拟化技术,通过截图实现搜索和自动化GUI,可利用Jython进行脚本扩展<br />l PyQt + PySide:Qt应用框架和GUI库所需模块
  31. pillow
  32. ```python
  33. from PIL import Image
  34. width = 200
  35. height = 150
  36. fp = open('/Users/biancaguo/Desktop/学习笔记/reverse/111', 'rb') #按二进制读
  37. data = fp.read()
  38. im = Image.frombytes('RGB', (width, height), data)
  39. # im = im.transpose(Image.FLIP_TOP_BOTTOM)
  40. im.show()
  41. im.save('result.bmp')