-
大小: 31.46MB文件類型: .zip金幣: 1下載: 0 次發布日期: 2023-06-30
- 語言: 其他
- 標簽: attackgraph??
資源簡介
里面是一個貝葉斯攻擊圖源代碼,內容很全,里面是一個貝葉斯攻擊圖源代碼,內容很全,
代碼片段和文件信息
#-*-?coding:utf-8?-*-
import?xml.etree.ElementTree?as?ET
import?networkx?as?nx
import?json
#讀取xml文件
def?xmlpython(xml1n):
????xml2=open(xml1).read()
????G=create_graph(xml2n)??
????return?G
#This?Place?should?have?any?change
def?create_graph(xml1n):
????G=nx.DiGraph()??????#創建有向圖??????
????H=nx.DiGraph()??????#創建存儲父節點的圖
????root=ET.fromstring(xml1)????#獲取xml的根節點
????G=first_node(Groot)????#存儲第一個點
????i=1
????ip1=G.node[1][‘ip‘]
????com1=G.node[1][‘com‘]
????G=post_node(GHirootn)
????return?G
def?post_node(GHirootn):
????d=i
????ip2=G.node[i][‘ip‘]
????com2=G.node[i][‘com‘]
????H.add_node(iip=ip2com=com2)???????#將自身當做父節點存入H圖中
????for?vid1?in?root.findall(‘./vid‘):??#遍歷vid元素,查找ip
????????lenH=H.nodes()
????????if?len(lenH)==n:????????#判斷父節點個數是否超過限定????
????????????break
????????ip1=vid1.get(‘ip‘)??????#獲取vid的ip
????????for?attack1?in?vid1.findall(‘./attack‘):????#遍歷attack元素,查找攻擊
????????????b=0
????????????c=0
????????????pr1=attack1.find(‘./pr‘).text
????????????post1=attack1.find(‘./post‘).text
????????????for?x?in?H.nodes():?????#如果后果點在父節點中,就返回
????????????????if?H.node[x][‘ip‘]==ip1?and?post1?in?H.node[x][‘com‘]:
????????????????????b=1
????????????????????break
????????????if?b==1:
????????????????continue
????????????for?x?in?G.nodes():?????#如果后果點在G圖中,就直接建立邊
????????????????if?G.node[x][‘ip‘]==ip1?and?post1?in?G.node[x][‘com‘]:
????????????????????G.add_edge(dxpr=pr1)
????????????????????c=1
????????????????????break
????????????if?c==1:
????????????????continue
????????????else:
????????????????if?post1==‘root‘:
????????????????????post2=[‘root‘‘user‘‘login‘‘access‘]
????????????????elif?post1==‘user‘:
????????????????????post2=[‘user‘‘login‘‘access‘]
????????????????elif?post1==‘login‘:
????????????????????post2=[‘login‘‘access‘]
????????????????elif?post1==‘access‘:
????????????????????post2=[‘access‘]
????????????????G.add_node(i+1ip=ip1com=post2)
????????????????G.add_edge(di+1pr=pr1)
????????????????i=i+1
????????????????
????????????????G=post_node(GHirootn)
????????????????????????????????????
????H.remove_node(d)
????return?G
#輸入第一個攻擊點
def?first_node(G1root):
????ip1=‘192.168.1.101‘
????pr1=‘0.5‘
????post1=‘root‘
????#判斷權限包含關系
????if?post1==‘root‘:
????????post1=[‘root‘‘user‘‘login‘‘access‘]
????if?post1==‘user‘:
????????post1=[‘user‘‘login‘‘access‘]
????if?post1==‘login‘:
????????post1=[‘login‘‘access‘]
????if?post1==‘access‘:
????????post1=[‘access‘]
????G1.add_node(1ip=ip1com=post1)
????return?G1
????
if?__name__?==?‘__main__‘:
????n=raw_input(‘輸入單一路徑的最大節點數:‘)
????G=xmlpython(‘exploit.xml‘n)
????
????way1=raw_input(‘輸入生成G.node的json文件的路徑,不包括文件名:‘)
????f=open(way1+‘G.node.json‘‘w‘)
????f.write(json.dumps(G.node))
????f.close()
????way2=raw_input(‘輸入生成G.edge的json文件的路徑,不包括文件名:‘)
????f=open(way2+‘G.edge.json‘‘w‘)
????f.write(json.dumps(G.edge))
????f.close()
????print?“生成的?G.node:“
????print?G.node
????print?“生成的?G.edge:“
????print?G.edge
????
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2014-10-08?07:50??IBAG-master\
?????目錄???????????0??2014-10-08?07:50??IBAG-master\AG_Generation\
?????文件????????3307??2014-10-08?07:50??IBAG-master\AG_Generation\AG-generate.py
?????文件????????6142??2014-10-08?07:50??IBAG-master\AG_Generation\AG-generate_Revised.py
?????文件?????????383??2014-10-08?07:50??IBAG-master\AG_Generation\G.edge.json
?????文件?????????803??2014-10-08?07:50??IBAG-master\AG_Generation\G.node.json
?????文件?????????198??2014-10-08?07:50??IBAG-master\AG_Generation\HostPrilvage.py
?????文件?????????405??2014-10-08?07:50??IBAG-master\AG_Generation\HostPrilvage.pyc
?????目錄???????????0??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????2753??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????3910??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????4648??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????2803??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????2653??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????2640??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????2936??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????3168??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????4249??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????4268??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????5256??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件????????3286??2014-10-08?07:50??IBAG-master\AG_Generation\Nessus?sc
?????文件?????????505??2014-10-08?07:50??IBAG-master\AG_Generation\Network_li
?????文件?????????737??2014-10-08?07:50??IBAG-master\AG_Generation\exploit.xm
?????目錄???????????0??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\
?????文件??????????69??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\INSTALL.txt
?????文件????????1772??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\LICENSE.txt
?????文件?????????777??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\MANIFEST.in
?????文件????????1491??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\PKG-INFO
?????文件?????????389??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\README.txt
?????目錄???????????0??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\build\
?????目錄???????????0??2014-10-08?07:50??IBAG-master\AG_Generation\networkx-1.8.1\build\lib\
............此處省略3494個文件信息
- 上一篇:概率論與數理統計習題全解指南浙大四版
- 下一篇:數據可視化駕駛艙.zip
評論
共有 條評論