-
Notifications
You must be signed in to change notification settings - Fork 1
/
splitter.py
67 lines (57 loc) · 2.15 KB
/
splitter.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# -*- coding: utf-8 -*-
"""
Created on Tue Oct 18 19:35:04 2022
@author: Arman Hossain
"""
import re
def split_cpe(cpe):
'''
cpe:: cpe:2.3:o:juniper:junos:16.1:r1:*:*:*:*:*:*
0 1 2 3 4 5 6 7 8 9 10 11,12 -->(index)
return (cpe,2.3,o,juniper,junos,16.1,r1,*,*,*,*,*,*)
'''
# https://cpe.mitre.org/specification/
if(not isinstance(cpe, str)):
print("--- cpe1: ",cpe, " ----")
print("Error from spliter.py split_cpe(): cpe syntax is not string")
return ("cpe_idx1","cpe_idx2","cpe_idx3","cpe_idx4","cpe_idx5","cpe_idx6","cpe_idx7","cpe_idx8","cpe_idx9","cpe_idx10","cpe_idx11","cpe_idx12")
cpe = cpe.replace("\:","-")
cpe = re.sub("[-]+","-",cpe)
'''
parsing needed for this type of cpe [here net\:\ part is vendor and net\:\:netmask part is product]
cpe:2.3:a:net\:\:netmask_project:net\:\:netmask:*:*:*:*:*:perl:*:*
'''
splited = cpe.split(':')
if(len(splited)!=13):
print("cpe2: ",cpe)
print("Error from spliter.py split_cpe(): cpe syntax is not recognized")
return splited
def split_date(date):
'''
date: 2019-01-15T21:29Z
return: (2019,01,15,T21,29Z)
'''
if(not isinstance(date, str)):
print("--- date1: ",date," ----")
print("Error from spliter.py date(): date syntax is not recognized")
return (0000,00,00,"T00","00Z")
# sdate = dates[0]
tz = date.split("T")
time = tz[0].split("-")
if len(time)!=3:
print("--- date2: ",date," ----")
print("Error from spliter.py date(): date syntax is not recognized")
return (0000,00,00,"T00","00Z")
yy = int(time[0])
mm = int(time[1])
dd = int(time[2])
if(len(tz)!=2 or mm>12):
print("--- date3: ",date," ----")
print("Error from spliter.py date(): date syntax is not recognized")
return (yy,mm,dd,"T00","00Z")
time = tz[1].split(":")
if len(time)!=2:
print("--- date4: ",date," ----")
print("Error from spliter.py date(): date syntax is not recognized")
return (yy,mm,dd,"T00","00Z")
return (yy,mm,dd,"T"+time[0],time[1])