溫馨提示×

溫馨提示×

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

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

Batea是一款什么工具

發(fā)布時間:2021-12-24 17:13:06 來源:億速云 閱讀:92 作者:小新 欄目:網(wǎng)絡(luò)安全

這篇文章主要介紹Batea是一款什么工具,文中介紹的非常詳細(xì),具有一定的參考價值,感興趣的小伙伴們一定要看完!

Batea

Batea是一款基于機(jī)器學(xué)習(xí)算法異常檢測分支的上下文驅(qū)動的網(wǎng)絡(luò)設(shè)備排序框架,而Batea的主要目標(biāo)是允許并幫助安全團(tuán)隊使用nmap掃描報告自動過濾大型網(wǎng)絡(luò)中感興趣的網(wǎng)絡(luò)資產(chǎn)。

Batea工作機(jī)制

Batea的工作原理是從nmap報告(XML)中構(gòu)造所有設(shè)備的數(shù)字表示(numpy),然后應(yīng)用異常檢測方法來發(fā)現(xiàn)感興趣或有價值的網(wǎng)絡(luò)資產(chǎn)。我們還可以通過向網(wǎng)絡(luò)資產(chǎn)元素的數(shù)字表示中添加特定的字符來擴(kuò)展其功能。

網(wǎng)絡(luò)資產(chǎn)元素的數(shù)字表示是使用特征構(gòu)建的,這些特征受到安全社區(qū)專業(yè)知識的啟發(fā),而無人管理的異常檢測方法將允許工具將網(wǎng)絡(luò)資產(chǎn)上下文或網(wǎng)絡(luò)的整體描述用作排序算法的核心構(gòu)建塊。這里所使用的準(zhǔn)確算法為Isolation Forest算法。

機(jī)器學(xué)習(xí)模型是Batea的核心。模型是在整個數(shù)據(jù)集上訓(xùn)練的算法,用于預(yù)測相同(和其他)數(shù)據(jù)點(diǎn)(網(wǎng)絡(luò)設(shè)備)的得分。除此之外,Batea還允許模型持久化。也就是說,我們可以重用預(yù)先訓(xùn)練的模型,并導(dǎo)出在大型數(shù)據(jù)集上訓(xùn)練的模型以供進(jìn)一步使用。

工具安裝

$ git clone git@github.com:delvelabs/batea.git

$ cd batea

$ python3 setup.py sdist

$ pip3 install -r requirements.txt

$ pip3 install -e .

開發(fā)者安裝

$ git clone git@github.com:delvelabs/batea.git

$ cd batea

$ python3 -m venv batea/

$ source batea/bin/activate

$ python3 setup.py sdist

$ pip3 install -r requirements-dev.txt

$ pip3 install -e .

$ pytest

工具使用

# 完整信息

$ sudo nmap -A 192.168.0.0/16 -oX output.xml

 

# 部分信息

$ sudo nmap -O -sV 192.168.0.0/16 -oX output.xml

 

 

$ batea -v output.xml

工具使用樣例

# 簡單使用(以默認(rèn)格式輸出排名前五的資產(chǎn))

$ batea nmap_report.xml

# 輸出前三

$ batea -n 3 nmap_report.xml

# 輸出所有資產(chǎn)

$ batea -A nmap_report.xml

# 使用多個輸入文件

$ batea -A nmap_report1.xml nmap_report2.xml

# 使用通配符

$ batea ./nmap*.xml

$ batea -f csv ./assets*.csv

# 你可以在預(yù)訓(xùn)練模型和導(dǎo)出訓(xùn)練模型上使用batea。

# 持久性的訓(xùn)練、輸出和轉(zhuǎn)儲模型

$ batea -D mymodel.batea nmap_report.xml

# 使用預(yù)訓(xùn)練模型

$ batea -L mymodel.batea nmap_report.xml

# 使用預(yù)格式化CSV和XML文件

$ batea -x nmap_report.xml -c portscan_data.csv

# Verbose模式

$ batea -vv nmap_report.xml

如何添加新的特性

Batea的工作原理是將數(shù)字特征分配給報告(或一系列報告)中的每一臺主機(jī)。這里的主機(jī)指的是從nmap報告派生的python對象,它們由以下屬性列表組成:[ipv4, hostname, os_info, ports],其中的ports是端口對象的列表。每一個端口都有以下屬性:[port, protocol, state, service, software, version, cpe, scripts],所有屬性值默認(rèn)為None。

Features是從FeatureBase類繼承的對象,它實(shí)例化了一個特定的_transform方法。這個方法始終將所有主機(jī)的列表作為輸入,并返回一個lambda函數(shù),該函數(shù)將每個主機(jī)映射到數(shù)值的numpy列(主機(jī)順序是守恒的),然后將該列附加到掃描報告的矩陣表示形式中。Features必須輸出正確的數(shù)值(浮點(diǎn)或整數(shù)),而不能輸出其他值。

大多數(shù)特征轉(zhuǎn)換都是使用簡單的lambda函數(shù)實(shí)現(xiàn)的,只需確保為每個主機(jī)默認(rèn)一個數(shù)值,以實(shí)現(xiàn)模型兼容性。

具體樣例如下:

class CustomInterestingPorts(FeatureBase):

    def __init__(self):

        super().__init__(name="some_custom_interesting_ports")

 

    def _transform(self, hosts):

      """This method takes a list of hosts and returns a function that counts the number

      of host ports member from a predefined list of "interesting" ports, defaulting to 0.

 

      Parameters

      ----------

      hosts : list

          The list of all hosts

 

      Returns

      -------

      f : lambda function

          Counts the number of ports in the defined list.

      """

        member_ports = [21, 22, 25, 8080, 8081, 1234]

        f = lambda host: len([port for port in host.ports if port.port in member_ports])

        return f

接下來,我們可以使用batea/__init__.py中的NmapReport.add_feature方法來向報告中添加新的特性:

from .features.basic_features import CustomInterestingPorts

 

def build_report():

    report = NmapReport()

    #[...]

    report.add_feature(CustomInterestingPorts())

 

return report

使用預(yù)計算表格數(shù)據(jù)(CSV)

我們還可以使用預(yù)處理的數(shù)據(jù)來訓(xùn)練模型或進(jìn)行預(yù)測。數(shù)據(jù)必須按(ipv4,port)索引,每行有一個唯一的組合。列必須使用以下名稱之一,但不必全部使用。如果缺少列,則解析器默認(rèn)為空值。

'ipv4',

  'hostname',

  'os_name',

  'port',

  'state',

  'protocol',

  'service',

  'software_banner',

  'version',

  'cpe',

  'other_info'

樣例:

ipv4,hostname,os_name,port,state,protocol,service,software_banner

10.251.53.100,internal.delvesecurity.com,Linux,110,open,tcp,rpcbind,"program version   port/proto  service100000  2,3,4        111/tcp  rpcbind100000  2,3,4    "

10.251.53.100,internal.delvesecurity.com,Linux,111,open,tcp,rpcbind,

10.251.53.188,serious.delvesecurity.com,Linux,6000,open,tcp,X11,"X11Probe: CentOS"

輸出數(shù)值表示

我們還可以輸出數(shù)值矩陣和分?jǐn)?shù)列,而不是常規(guī)輸出,這對于進(jìn)一步的數(shù)據(jù)分析和調(diào)試非常有用。

$ batea -oM network_matrix nmap_report.xml

以上是“Batea是一款什么工具”這篇文章的所有內(nèi)容,感謝各位的閱讀!希望分享的內(nèi)容對大家有幫助,更多相關(guān)知識,歡迎關(guān)注億速云行業(yè)資訊頻道!

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

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

AI