溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用

發(fā)布時(shí)間:2021-12-27 14:51:49 來(lái)源:億速云 閱讀:182 作者:小新 欄目:網(wǎng)絡(luò)管理

這篇文章給大家分享的是有關(guān)網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用的內(nèi)容。小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過(guò)來(lái)看看吧。


0x01. 整體簡(jiǎn)介

引言

pentestEr_Fully-automatic-scanner為了省去繁瑣的手工測(cè)試和常用漏洞的搜索工作,提升工作的效率,才有了此工具,工具對(duì)于前期的收集采用了市面上大量的工具集合,不漏掃的原則,最大化的提升工具可用性,可擴(kuò)展性等要求,開(kāi)發(fā)次掃描器。使用方法

可以直接執(zhí)行 python main.py -d cert.org.cn

思維導(dǎo)圖

網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用

目錄結(jié)構(gòu)

|--dict  
|--dns_server.txt 
|--...
|--lib   
|-- __init__.py
|--cmdline.py  
|--...
|--listen  
|--filer.py

|--report  
|--result  
|--rules  
|--wahtweb.json   
|--commom.txt   
|--subbrute  
|--thirdlib  
|--utils   
|--api.keys  
|--BBScan.py
|--bingAPI
|--captcha.py
|--config.py
|--dnsbrute.py
|--gxfr.py
|--import1.php
|--main.py
|--report_all.py
|--subDomainBrute.py
|--sublist3r.py
|--upload.py
|--wahtweb.py
|--wydomain.py
|--啟動(dòng)程序.bat
|--wvs.bat

這個(gè)目錄結(jié)構(gòu)讓我感覺(jué)很亂,尤其后面一大推py文件,缺少點(diǎn)軟件設(shè)計(jì)的思想,感覺(jué)時(shí)即興寫(xiě)出來(lái)的代碼,很多文件還有錯(cuò)誤,注釋很少,很多時(shí)候需要debug才能知道該段代碼實(shí)現(xiàn)的功能。

0x02.信息收集

1.域名信息收集

在進(jìn)行掃描之前,按照慣例需要對(duì)目標(biāo)網(wǎng)站的域名信息進(jìn)行whois查詢,該腳本whois的實(shí)現(xiàn)是通過(guò)第三方網(wǎng)站查詢得到的,不過(guò)原查詢函數(shù)因?yàn)槿掌诰眠h(yuǎn),而網(wǎng)站代碼也已經(jīng)更新了,該函數(shù)已經(jīng)無(wú)法準(zhǔn)確的獲取到目標(biāo)網(wǎng)站域名信息了

def sub_domain_whois(url_domain):
"""
通過(guò)第三方網(wǎng)站查詢得到whois結(jié)果,然后對(duì)網(wǎng)頁(yè)進(jìn)行正則匹配,以獲取到網(wǎng)頁(yè)內(nèi)容中的whois結(jié)果
"""
    um=[]
    a1=requests.get("http://whois.chinaz.com/%s" %(url_domain))

    if 'Registration' not in a1.text:
        print 'whois error'
    else:
        print a1.text
        # 使用正則匹配想要獲取的內(nèi)容,假如目標(biāo)網(wǎng)站的前端代碼改變了,那么該正則就失效了
        out_result=re.findall(r'<pre class="whois-detail">([\s\S]*)</pre>', a1.text.encode("GBK",'ignore'))
        out_result_register=re.findall(r'http://(.*?)"', a1.text.encode("GBK",'ignore'))
        for x in out_result_register:
            if 'reverse_registrant/?query=' in x:
                um.append(x)
                break
        for x in out_result_register:
            if 'reverse_mail/?query=' in x:
                um.append(x)
                break
        print um[0], um[1]
        print out_result[0]
        # 將獲取到的結(jié)果存放在的一個(gè)html文件中,以便最后生成報(bào)告
        with open('report/whois_email_user.html','w') as fwrite:
            fwrite.write('register_user:')
            fwrite.write('<a href="http://' + um[0] + '">注冊(cè)者反查詢</a>')
            fwrite.write('<br>')
            fwrite.write('email:')
            fwrite.write('<a href="http://' + um[1] + '">郵箱反查詢</a>')
            fwrite.write('<br>')
            fwrite.write('<pre>')
            fwrite.write(out_result[0])
            fwrite.write('</pre>')

網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用

def sub_domain_whois(url_domain):
    import json
    a = requests.get("http://api.whoapi.com/?domain={}&r=whois&apikey=demokey".format(url_domain))
    result = a.text
    r = json.loads(result)
    for k,v in r.items():
        print(k,v)

網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用

當(dāng)然如果需要一些詳細(xì)的信息,可能還是需要對(duì)一些網(wǎng)站的內(nèi)容進(jìn)行爬取才行。

2.子域名收集

對(duì)于子域名收集,這個(gè)系統(tǒng)在實(shí)現(xiàn)的時(shí)候,為了收集到盡可能多的代碼,使用了很多第三方腳本,這里就出現(xiàn)了一個(gè)問(wèn)題,這種使用腳本的方法讓代碼可讀性很差,而且維護(hù)困難,很多代碼現(xiàn)在已經(jīng)不適用了。

使用到的腳本名稱與介紹

腳本名稱介紹使用方法返回內(nèi)容
gxfr.py使用高級(jí)搜索引擎(bing,baidu,google)查詢來(lái)枚舉子域并執(zhí)行dns查找,這個(gè)程序使用的是bing的API對(duì)子域名進(jìn)行收集python gxfr.py --bxfr --dns-lookup  -o --domain  url_domain程序會(huì)將結(jié)果保存到一個(gè)domain_gxfr1.txt這樣的文件中,api已經(jīng)不可用
subDomainsBrute.py提供的常用的子域名字符串字典,然后通過(guò)與域名進(jìn)行組合,配合DNS服務(wù)器確定是否存在組合后的子域名python subDomainsBrute.py domain將字典枚舉組合解析成功后的域名存放在domain_jiejie.txt文件中
wydomain.py通過(guò)使用互聯(lián)網(wǎng)上的第三方接口或者爬取查詢結(jié)果來(lái)獲取目標(biāo)的子域名python wydomain domain通過(guò)不同網(wǎng)站獲取的結(jié)果會(huì)存在本地的不同的.json文件中
sublist3r.py使用百度,雅虎,bing等第三方引擎對(duì)目標(biāo)域名進(jìn)行子域名收集,而且還提供字典枚舉的功能和端口掃描的功能python sublist3r -d doamin -o domain_sublistdir.txt將獲取到的子域名結(jié)果存在本地的txt文件中

gxfr.py文件

該py文件是使用bing的API,谷歌的搜索引擎對(duì)目標(biāo)域名的子域名進(jìn)行查詢。主要的兩個(gè)函數(shù)為bxfr函數(shù)和gxfr函數(shù)。

  • bxfr函數(shù),使用Bing的API進(jìn)行子域名解析和查詢,該函數(shù)需要提供Bing相關(guān)功能的API Key。然后訪問(wèn)`        https://api.datamarket.azure.com/Data.ashx/Bing/Search/Web?Query=domain&Misplaced &format=json經(jīng)過(guò)測(cè)試該API接口已經(jīng)不可用。通過(guò)該API獲取子域名結(jié)果后,使用lookup_subs函數(shù)進(jìn)行socket函數(shù)獲取地址并成功后(socket.getaddrinfo(site, 80)`),將結(jié)果存儲(chǔ)在txt文件中中。

  • gxfr函數(shù),使用google搜索引擎的hack語(yǔ)法進(jìn)行查詢(site:baidu.com),然后通過(guò)正則表達(dá)式進(jìn)行匹配pattern = '>([\.\w-]*)\.%s.+?<' % (domain)。然后獲取匹配結(jié)果。最后經(jīng)過(guò)lookkup_subs函數(shù)驗(yàn)證之后寫(xiě)入txt文件中。

subDomainsBrute.py文件

該py文件通過(guò)提供的子域名字典,對(duì)目標(biāo)域名的子域名進(jìn)行枚舉然后解析測(cè)試,最后輸出結(jié)果。這里提供了兩個(gè)字典文件,分別為dict/subnames.txtdict/next_sub.txt。還有一個(gè)dns服務(wù)器列表

.114.114.114
.8.8.8
.76.76.76
.5.5.5
.6.6.6

程序簡(jiǎn)介

 def __init__(self, target, names_file, ignore_intranet, threads_num, output):
        self.target  target.strip() 
        self.names_file  names_file 
        self.ignore_intranet  ignore_intranet 
        self.thread_count  self.threads_num  threads_num 
        self.scan_count  self.found_count   
        self.lock  threading.Lock()
        self.console_width  getTerminalSize()[0]      
        self.resolvers  [dns.resolver.Resolver()  _  range(threads_num)]   
        self._load_dns_servers() 
        self._load_sub_names() 
        self._load_next_sub()  
        outfile  target    not output  output
        self.outfile  open(outfile, )   
        self.ip_dict  {} 
        self.STOP_ME  False

該程序的執(zhí)行流程就是,先從字典中加載字符串,然后將字符串與目標(biāo)域名進(jìn)行拼接得到一個(gè)子域名,通過(guò)第三方模塊dns.resolver對(duì)其進(jìn)行解析,解析成功就保存在txt文件中。關(guān)鍵代碼如下:

cur_sub_domain  sub    self.target

answers  d.resolvers[thread_id].query(cur_sub_domain)
is_wildcard_record  False
 answers:
     answer  answers:
        self.lock.acquire()
         answer.address not  self.ip_dict:
            self.ip_dict[answer.address]  
        :
            self.ip_dict[answer.address]  
             self.ip_dict[answer.address] > :    
                is_wildcard_record  True
        self.lock.release()

wydomain.py文件

該程序是通過(guò)調(diào)用多個(gè)第三方接口對(duì)目標(biāo)域名進(jìn)行子域名查詢,然后將查詢結(jié)果分別存儲(chǔ)在一個(gè)json文件中。

Alexa
  • fetch_chinaz函數(shù)

url  .format(self.domain)
 r  http_request_get(url).content
subs  re.compile(r)
  • fetch_alexa_cn函數(shù)

url  .format(self.domain)
r  http_request_get(url).text
sign  re.compile(r).findall(r)
Threatcrowd
  • class Threatcrowd(object)

url  .format(self.website, self.domain)
content  http_request_get(url).content
 sub  json.loads(content).get():
Threatminer
  • class Threatminer(object)

 url  .format(self.website, self.domain)
content  http_request_get(url).content
 _regex  re.compile(r)
  sub  _regex.findall(content):
Sitedossier
  • class Sitedossier(object)

 url  .format(self.domain)
 r  self.get_content(url)  
 self.parser(r)  


部分代碼如下
npage  re.search(, response)
 npage:
      sub  self.get_subdomain(response):
            self.subset.append(sub)

return list(set(self.subset))
Netcraft
  • class Netcraft(object)

self.site  
self.cookie  self.get_cookie().get()
url  .format(
self.site, self.domain)
r  http_request_get(url, self.cookie)
self.parser(r.text) 

部分代碼信息
npage  re.search(, response)

return list(set(self.subset))
Ilinks
  • class Ilinks(object)

self.url  
payload  {
                : ,
                : ,
                : ,
                : self.domain
            }
 r  http_request_post(self.urlpayload).text
subs  re.compile(r)
Chaxunla
  • class Chaxunla(object)

self.url  
url  .format(
self.url, timestemp, self.domain, timestemp, self.verify)
result  json.loads(req.get(url).content)

網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用

json_data  read_json(_burte_file)
 json_data:
    subdomains.extend(json_data)
......
subdomains  list(set(subdomains))
_result_file  os.path.join(script_path, outfile)
save_result(_result_file, subdomains)

sublist3r.py文件

該文件使用百度,雅虎,bing等第三方引擎對(duì)目標(biāo)域名進(jìn)行子域名收集,而且還提供字典枚舉的功能和端口掃描的功能在該系統(tǒng)中只用到了該程序的子域名收集功能。使用到的模塊也與之前的wydomain.py文件有很多重復(fù)的地方

enumratorBase基類

該文件的類都是繼承至該類,而這個(gè)基類也是由作者自定義的一個(gè)類。簡(jiǎn)單解釋一下該類的功能

  • print_banner方法子類通過(guò)繼承,可以通過(guò)該函數(shù)打印出該類使用的一些接口的信息

  • send_req方法發(fā)送請(qǐng)求的方法,該方法中自定義了大量的http頭部變量,該方法返回的服務(wù)器回復(fù)的數(shù)據(jù)

  • get_response方法從response對(duì)象中獲取html內(nèi)容,并返回

  • check_max_subdomains方法該方法是用來(lái)設(shè)置尋找子域名最大個(gè)數(shù)的,如果得到子域名的數(shù)量到達(dá)該函數(shù)設(shè)置數(shù)量時(shí),程序就會(huì)停止繼續(xù)尋找子域名

  • check_max_pages方法比如google搜索引擎是需要指定探索的最大頁(yè)數(shù),否則會(huì)無(wú)限制的探索下去。

  • check_response_errors 方法該方法檢查對(duì)服務(wù)器的請(qǐng)求是否成功完成

  • should_sleep方法在進(jìn)行子域名收集的時(shí)候,為了避免類似于google搜索引擎的機(jī)器識(shí)別,應(yīng)該設(shè)置休眠時(shí)間

  • enumerate方法通過(guò)該方法獲取子域名

而以下的子域名檢索方法是由enumratorBase類派生出來(lái)的,然后根據(jù)各自的特點(diǎn)進(jìn)行修改后形成的類,簡(jiǎn)單的介紹一下功能

類名稱實(shí)現(xiàn)的功能
GoogleEnum通過(guò)google搜索引擎檢索目標(biāo)子域名
YahooEnum通過(guò)雅虎搜索引擎檢索目標(biāo)子域名
AskEnum通過(guò)http://www.ask.com/web檢索子域名
BingEnum通過(guò)bing檢索子域名
BaiduEnum通過(guò)百度檢索子域名
NetcraftEnum通過(guò)http://searchdns.netcraft.com/?restriction=site+ends+with&host={domain}檢測(cè)子域名
Virustotal通過(guò)'https://www.virustotal.com/en/domain/{domain}/information/檢索子域名
ThreatCrowdhttps://www.threatcrowd.org/searchApi/v2/domain/report/?domain={domain}檢索子域名
CrtSearch通過(guò)https://crt.sh/?q=%25.{domain}檢索子域名
PassiveDNS通過(guò)http://ptrarchive.com/tools/search.htm?label={domain}檢索子域名

此外該腳本還提供端口掃描功能和字子域名字典枚舉的功能,雖然該項(xiàng)系統(tǒng)并未使用這些功能

  • postscan函數(shù)關(guān)鍵代碼,使用socket模塊去嘗試連接目標(biāo)端口,如果超過(guò)2s目標(biāo)沒(méi)有回復(fù),則判斷目標(biāo)沒(méi)有開(kāi)放該端口

for port in ports:
      try:
           s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
           s.settimeout(2)
           result = s.connect_ex((host, int(port)))
           if result == 0:
               openports.append(port)

對(duì)與子域名枚舉功能,該腳本調(diào)用了subbrute.py中的函數(shù),用于對(duì)字典中字符串拼成的子域名進(jìn)行驗(yàn)證操作。 關(guān)鍵代碼

bruteforce_list  subbrute.print_target(parsed_domain.netloc, record_type, subs, resolvers, process_count, output, json_output, search_list, verbose)

print_target函數(shù)是subbrute文件中的函數(shù),用于驗(yàn)證子域名是否是可用的

最后通過(guò)一個(gè)make_domain函數(shù)將所有的以.txt為后綴名的文件全部復(fù)制到all_reqult.log文件中,通過(guò)讀取后格式化處理,將結(jié)果存儲(chǔ)到report/result.txt文件中關(guān)鍵代碼如下

os.system()
print()
list_domain  []
f  open(, )
......
f.close()
os.system()
list_domain  list(set((list_domain)))
print list_domain, len(list_domain)
with open(, ) as outfile:
    outfile.write(.join(list_domain))
fopen1  open(, )
fopen1.write(.join(list_domain))
fopen1.close()

3.Web信息獲取

對(duì)于獲取Web網(wǎng)頁(yè)的信息,這里主要是獲取網(wǎng)頁(yè)使用的是什么框架或者CMS,通過(guò)本地提供的一個(gè)json規(guī)則檢測(cè)文件,對(duì)目標(biāo)網(wǎng)站進(jìn)行檢測(cè)和指紋識(shí)別json文件中部分規(guī)則如下:

{
    : [
        {
            : ,
            : 
        },
        {
            : ,
            : ,
            : 
        }
    ],
    : [
        {
            : ,
            : 
        },
        {
            : ,
            : 
        }
    ],
    : [
        {
            : ,
            : ,
            : 
        }
    ],
    : [
        {
            : ,
            : [, ]
        }
    ],
    : [
        {
            : ,
            : 
        }
    ],
......

實(shí)現(xiàn)的過(guò)程是將report/result.txt中所有的域名根據(jù)json文件中的規(guī)則進(jìn)行url拼接,然后對(duì)這個(gè)特定URL進(jìn)行訪問(wèn)獲取網(wǎng)頁(yè)內(nèi)容,再將網(wǎng)頁(yè)內(nèi)容與規(guī)則進(jìn)行匹配,最后判斷使用cms或者框架名稱。關(guān)鍵代碼如下

                    r  requests.get(url1 rule[], )
                    r.encoding  r.apparent_encoding
                    r.close()
                       rule and hashlib.md5(r.content).hexdigest()  rule[]:
                        print (url1, cms)

                       rule and rule[]  r.headers and rule[]  r.headers[rule[]]:
                        print (url1, cms)

                       rule:
                         type(rule[]) is list:
                             itext  rule[]:
                                 itext  r.text:
                                    print (url1, cms)
                         rule[]  r.text:
                                print (url1, cms)

                       rule:
                         type(rule[]) is list:
                             reg  rule[]:
                                 re.search(reg, r.text):
                                    print (url1, cms)
                         re.search(rule[], r.text):
                                print (url1, cms)
                        :
                            print

注意該腳本還引入了一個(gè)第三方模塊from thirdlib import threadpool 該threadpool是一個(gè)簡(jiǎn)單的實(shí)現(xiàn)線程池的框架,方便使用腳本使用多線程。腳本中調(diào)用的關(guān)鍵代碼

        pool  threadpool.ThreadPool(self.thread_num)
        reqs  threadpool.makeRequests(self.identify_cms, self.rules, self.log)
         req  reqs:
            pool.putRequest(req)
        pool.wait()

在系統(tǒng)的主函數(shù)中通過(guò)接受該腳本stdout輸出的流數(shù)據(jù),將數(shù)據(jù)寫(xiě)入到一個(gè)列表中,最后將結(jié)果保存到report/whatweb.html。

0x03.漏洞掃描

該系統(tǒng)的漏洞掃描模塊是調(diào)用的第三方腳本BBScan.py,該文件代碼實(shí)現(xiàn)了一個(gè)輕量級(jí)的web漏洞掃描器。使用的規(guī)則庫(kù)為存放在本地的一個(gè)txt文件中rules/commom.txt部分規(guī)則如下:

/admin/    }
/config/   }
/manage/   }
/backup/   }
/backend/  }

/admin.php }   }
/admin.jsp }   }
/admin.do  }   }


/examples           }
/examples/servlets/servlet/SessionExample    }
/manager/html       }


/db/       }
/DB/       }
/data/   }
/sqlnet.log       }       }
/data/user.txt    }       }
/user.txt         }       }
/phpinfo.php   }  }
/mysql/add_user.php   }
/cachemonitor/statistics.jsp    }   }

/jmx-console/    }
/jmx-console/HtmlAdaptor       }
/cacti/          }
/cacti/cacti.sql }  }

/../../../../../../../../../../../../../etc/passwd  }


/config/config_ucenter.php.bak         }


/shell.php              }
/shell.jsp              }
/{hostname}.zip         }    }


/resin-doc/resource/tutorial/jndi-appconfig/test/etc/passwd    }


/WEB-INF/web.xml                             }    }
/WEB-INF/web.xml.bak                         }    }


/.svn/
/.svn/entries         } }


/wp-login.php         } }
/config.inc           }}
/config.ini           }      }

腳本通過(guò)從這個(gè)文件中讀取規(guī)則,對(duì)目標(biāo)進(jìn)行測(cè)試,然后根據(jù)服務(wù)器返回的內(nèi)容進(jìn)行判斷是否存在該類型的漏洞。代碼簡(jiǎn)介

    def __init__(self, url, lock, , ):
        self.START_TIME  time.time() 
        
        self.TIME_OUT  timeout  
        self.LINKS_LIMIT         
        self.final_severity     
        self.schema, self.host, self.path  self._parse_url(url)  
        self.max_depth  self._cal_depth(self.path)[1]  depth     
        self.check_404()           
         self._status  :
            return None
         not self.has_404:
            print  % self.host
        self._init_rules()    
        self.url_queue  Queue.Queue()    
        self.urls_in_queue  []           
        _path, _depth  self._cal_depth(self.path)
        self._enqueue(_path)  
        self.crawl_index(_path)  
        self.lock  threading.Lock()
        self.results  {}

方法簡(jiǎn)介

  • _parse_url方法:解析URL,如果沒(méi)有指定通信協(xié)議,系統(tǒng)自動(dòng)添加為http協(xié)議。然后判斷url中是否存在路徑,如果不存在就返回"/",否則返回協(xié)議,主機(jī)名,和資源路徑

return _.scheme, _.netloc, _.path  _.path
  • _cal_depth:該方法是用于計(jì)算URL的深度,返回一個(gè)元組,url和深度。以//或者javascript開(kāi)頭的URL不做分析,以http開(kāi)頭的URL先對(duì)URL進(jìn)行解析,然后判斷hostnane是否為目標(biāo)的hostname,在判斷path路徑的深度。關(guān)鍵代碼如下

            _  urlparse.urlparse(url, )
             _.netloc  self.host:    
                url  _.path
        。。。。
        url  url[: url.rfind()]
        depth  len(url.split())
  • _init_rules:該方法從文件中加載規(guī)則,使用正則表達(dá)式從文件中的每一行提取數(shù)據(jù),正則表達(dá)式如下

p_severity  re.compile()
p_tag  re.compile()
p_status  re.compile()
p_content_type  re.compile()
p_content_type_no  re.compile()

提取數(shù)據(jù)并進(jìn)行判斷,沒(méi)有的置為空或者0

_  p_severity.search(url)
severity  int(_.group(1))  _  
_  p_tag.search(url)
tag  _.group(1)  _  
_  p_status.search(url)
status  int(_.group(1))  _  
_  p_content_type.search(url)
content_type  _.group(1)  _  
_  p_content_type_no.search(url)
content_type_no  _.group(1)  _

最后將重組的規(guī)則存放在一個(gè)元組中,最后將這個(gè)元組追加到一個(gè)列表中

self.url_dict.append((url, severity, tag, status, content_type, content_type_no))
  • _http_request方法:通過(guò)該方法獲取訪問(wèn)目標(biāo)url的狀態(tài)碼,返回http頭部和html內(nèi)容部分代碼如下

conn.request, url,
{: }
)
resp  conn.getresponse()
resp_headers  dict(resp.getheaders())
status  resp.status
  • _decode_response_text方法:該方法對(duì)服務(wù)器返回的頁(yè)面進(jìn)行解碼操作,如果用戶沒(méi)有指定charset類型,那么該方法就會(huì)嘗試使用'UTF-8', 'GB2312', 'GBK', 'iso-8859-1', 'big5'編碼對(duì)目標(biāo)返回的內(nèi)容進(jìn)行解碼,并將解碼后的內(nèi)容返回部分代碼

encodings  [, , , , ]
 _  encodings:
    try:
        return rtxt.decode(_)
    except:
        pass
  • check_404方法:檢查目標(biāo)返回的頁(yè)面的狀態(tài)碼是否為404部分代碼如下

self._status, headers, html_doc  self._http_request()
 self._status  :
    print  % self.host
self.has_404  (self._status  )
return self.has_404
  • _enqueue方法:該方法是判斷爬取的URL是否是已經(jīng)爬取的,如果是一個(gè)新的鏈接就傳入隊(duì)列中,該隊(duì)列用于爬蟲(chóng)部分代碼

 url  self.urls_in_queue:
    return False
 len(self.urls_in_queue) > self.LINKS_LIMIT:
    return False
:
    self.urls_in_queue.append(url)

還通過(guò)該方法將漏洞檢測(cè)規(guī)則對(duì)應(yīng)到URL上,然后組成一個(gè)元組,將這個(gè)元組傳入一個(gè)用于掃描漏洞的隊(duì)列中,代碼如下

 _  self.url_dict:   
    full_url  url.rstrip()  _[0]  
    url_description  {: url.rstrip(), : full_url}  
    item  (url_description, _[1], _[2], _[3], _[4], _[5])   
    self.url_queue.put(item)
  • crawl_index方法:該方法使用beautifulSoup4爬取頁(yè)面中的url鏈接。部分代碼如下

soup  BeautifulSoup(html_doc, )
links  soup.find_all()
 l  links:
    url  l.get(, )
    url, depth  self._cal_depth(url)
     depth < self.max_depth:
        self._enqueue(url)
  • _update_severity方法:該方法用于更新serverity,如果規(guī)則中存在serverty字段,那么就將默認(rèn)的final_serverity進(jìn)行修改

 severity > self.final_severity:
    self.final_severity  severity
  • _scan_worker方法:該方法是用于執(zhí)行漏洞掃描的關(guān)鍵代碼如下

try:
   
    item  self.url_queue.get.0)
except:
    return
try:
    url_description, severity, tag, code, content_type, content_type_no  item
    url  url_description[]
    prefix  url_description[]
except Exception, e:
    logging.error( % e)
    continue
 not item or not url:
    break

。。。。

status, headers, html_doc  self._http_request(url)
 (status  [200, , , ]) and (self.has_404 or status!self._status):
     code and status ! code:
        continue
     not tag or html_doc.find(tag) > :
         content_type and headers.get(, ).find(content_type) <  or \
            content_type_no and headers.get(, ).find(content_type_no) >:
            continue
        self.lock.acquire()
        
         not prefix  self.results:
            self.results[prefix] []
       
        self.results[prefix].append({:status, :  % (self.schema, self.host, url)} )
        self._update_severity(severity)
        self.lock.release()
  • scan方法:這是一個(gè)多線程啟動(dòng)器,用來(lái)啟動(dòng)_scan_worker方法,最后返回測(cè)試的主機(jī)名,測(cè)試的結(jié)果和嚴(yán)重程度代碼如下

 i  range(threads):
    t  threading.Threadself._scan_worker)
    threads_list.append(t)
    t.start()
 t  threads_list:
    t.join()
 key  self.results.keys():
     len(self.results[key]) > :
        del self.results[key]
return self.host, self.results, self.final_severity

1.nmap掃描

通過(guò)直接調(diào)用nmap對(duì)目標(biāo)進(jìn)行掃描,掃描結(jié)果儲(chǔ)存在nmap_port_services.xml中,啟動(dòng)的命令為

nmap   banner,http-headers,http-title         nmap_port_services.xml

2.AWVS掃描

使用命令行調(diào)用AWVS對(duì)目標(biāo)網(wǎng)站進(jìn)行掃描,并在系統(tǒng)中啟用一個(gè)線程去監(jiān)測(cè)該進(jìn)程的運(yùn)行情況,代碼如下

 not os.path.exists():
time.sleep(20)
print 
print 

popen  subprocess.Popen(  , subprocess.PIPE, subprocess.STDOUT)
 True:
next_line  popen.stdout.readline()
 next_line   and popen.poll() ! None:
break
sys.stdout.write(next_line)

wvs.bat的代碼如下:

@echo off
 /p please input wvs path,eg: [D:\Program Files (x86)\Web Vulnerability Scanner ]::
 /f %%i  (result.txt)  (
 %%i
 running   %%i ......
 /scan %%i /Profile default /SaveFolder d:\wwwscanresult\%pp%\ /save /Verbose    
)

0x04.報(bào)告生成

首先是將nmap生成的XML文件通過(guò)import1.php腳本進(jìn)行格式化后重新輸出,核心代碼如下:

@file_put_contents(, .., FILE_APPEND);
print .;
foreach (>port as ){
[];
(int)[];

>script[];
>service[];
;
..................;
    print ;
    @file_put_contents(, , FILE_APPEND);
}

最后將所有的結(jié)果通過(guò)repoert_all函數(shù)將結(jié)果進(jìn)行整合,將這些文件的路徑匯總到left,html中。代碼如下:

html_doc  left_html.substitute({: , : ,
                                 : , : ,
                                 : })
with open(, ) as outFile:
    outFile.write(html_doc)

0x05.總結(jié)

對(duì)于該系統(tǒng)而言只能說(shuō)是能夠滿足個(gè)人的使用,且后期代碼維護(hù)難度過(guò)大,不易進(jìn)行擴(kuò)展,使用第三方腳本時(shí),直接是使用命令執(zhí)行來(lái)獲取數(shù)據(jù),而不是通過(guò)導(dǎo)入模塊的方式。不過(guò)系統(tǒng)的思路是值得借鑒的,尤其是在前期搜集子域名信息的時(shí)候是花了大功夫的,調(diào)用了很多第三方腳本,為的是盡可能的將目標(biāo)的域名下的子域名收集完整,值得學(xué)習(xí)。而對(duì)于漏洞掃描模塊而言,即使用了第三方腳本,也是用的AWVS對(duì)目標(biāo)進(jìn)行掃描,對(duì)于BBScan這個(gè)掃描儲(chǔ)程序的規(guī)則設(shè)計(jì)值得學(xué)習(xí),自定義化程度很高。總體來(lái)說(shuō)整個(gè)掃描器的設(shè)計(jì)還是不錯(cuò)的,只是將這些第三方腳本進(jìn)行整合時(shí)就顯得有點(diǎn)倉(cāng)促了。

感謝各位的閱讀!關(guān)于“網(wǎng)絡(luò)安全中漏洞自動(dòng)化分析工具怎么用”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,讓大家可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),可以把它分享出去讓更多的人看到吧!

向AI問(wèn)一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI