dshield-parser 0.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,204 @@
1
+ import logging
2
+ import sqlite3
3
+ from io import StringIO
4
+ import pandas as pd
5
+ from sqlalchemy import create_engine, select
6
+
7
+ def initialize_database(filename, table_name, column_names, column_types):
8
+ incrementer = 0
9
+ columns = ""
10
+ while incrementer < len(column_names):
11
+ columns += column_names[incrementer] + " " + column_types[incrementer]
12
+ incrementer += 1
13
+ if incrementer != len(column_names):
14
+ columns += ", "
15
+
16
+ con = sqlite3.connect(filename)
17
+ cur = con.cursor()
18
+ sql = f"CREATE TABLE IF NOT EXISTS {table_name}({columns})"
19
+ logging.debug(sql)
20
+ logging.info(f"Creating table {table_name} in {filename} with columns {columns}")
21
+
22
+ cur.execute(sql)
23
+ con.commit()
24
+ con.close()
25
+
26
+ def select(filename, columns, tables, conditionals=None):
27
+ con = sqlite3.connect(filename)
28
+ df = pd.read_sql_query(f'''SELECT {columns} from {tables}''', con)
29
+ logging.debug(df.head())
30
+ con.close()
31
+ return df
32
+
33
+ def insert(filename, table_name, column_names, values):
34
+ if isinstance(column_names, list):
35
+ incrementer = 0
36
+ field_names = ""
37
+ value_placeholders
38
+ while incrementer < len(column_names):
39
+ field_names += column_names[incrementer]
40
+ value_placeholders += "?"
41
+ incrementer += 1
42
+ if incrementer != len(column_names):
43
+ field_names += ", "
44
+ value_placeholders += ", "
45
+ else:
46
+ columns = column_names
47
+ values = [values]
48
+ value_placeholders = "?"
49
+
50
+ con = sqlite3.connect(filename)
51
+ cur = con.cursor()
52
+
53
+ #create table if it doesn't exist
54
+ sql = f"CREATE TABLE IF NOT EXISTS {table_name} ({columns})"
55
+ logging.debug(sql)
56
+ logging.debug(f"Creating table {table_name} in {filename} with columns {columns}")
57
+ try:
58
+ cur.execute(sql)
59
+ except Exception as e:
60
+ logging.error(f"Issue with SQL statement '{sql}': {e}")
61
+ con.commit()
62
+
63
+ sql = f"INSERT INTO {table_name} ({columns}) VALUES ({value_placeholders})"
64
+ try:
65
+ cur.execute(sql, tuple(values))
66
+ except Exception as e:
67
+ logging.error(f"Issue with SQL statement '{sql}': {e}")
68
+ if "no column named" in e:
69
+ add_column(filename, table_name, columns)
70
+ con.commit()
71
+
72
+ def insert_dict(filename, dict, table_name):
73
+ df = pd.DataFrame(dict)
74
+ engine = create_engine(f'sqlite:///{filename}')
75
+ logging.info(f"Starting insert of dictionary into '{filename}'")
76
+
77
+ try:
78
+ df.to_sql(table_name, con=engine, if_exists='append')
79
+
80
+ except Exception as e:
81
+ logging.error(f"Issue while attempting to insert dictionary into database: {e}")
82
+ if "no column named" in str(e):
83
+ pass
84
+ #add_column(filename, table_name, column_name)
85
+ #df.to_sql(table_name, con=engine, if_exists='append')
86
+ logging.info(f"Completed insert of dictionary into '{filename}'")
87
+
88
+ def insert_list(filename, dict, table_name):
89
+ df = pd.DataFrame(dict)
90
+ engine = create_engine(f'sqlite:///{filename}')
91
+ logging.info(f"Starting insert of dictionary into '{filename}'")
92
+
93
+ try:
94
+ df.to_sql(table_name, con=engine, if_exists='append')
95
+
96
+ except Exception as e:
97
+ logging.error(f"Issue while attempting to insert dictionary into database: {e}")
98
+ if "no column named" in str(e):
99
+ pass
100
+ #add_column(filename, table_name, column_name)
101
+ #df.to_sql(table_name, con=engine, if_exists='append')
102
+ logging.info(f"Completed insert of dictionary into '{filename}'")
103
+
104
+ def insert_df(filename, df, table_name):
105
+ engine = create_engine(f'sqlite:///{filename}')
106
+ logging.info(f"Starting insert of dictionary into '{filename}'")
107
+
108
+ try:
109
+ df.to_sql(table_name, con=engine, if_exists='append', index=False)
110
+
111
+ except Exception as e:
112
+ logging.error(f"Issue while attempting to insert dictionary into database: {e}")
113
+ if "no column named" in str(e):
114
+ pass
115
+ logging.info(f"Completed insert of dictionary into '{filename}'")
116
+
117
+
118
+ def update(filename, table_name, column_name, value):
119
+
120
+ #sql = '''UPDATE commands SET azurehp2=? WHERE command=? and quantity=?'''
121
+ #sql = f'''UPDATE malware SET {honeypot[incrementer]}_quantity=?, {honeypot[incrementer]}=? WHERE hash=?'''
122
+ #
123
+ pass
124
+
125
+ #def select(filename, table_names, column_names, value_comparisons=None):
126
+ # incrementer = 0
127
+ # columns = ""
128
+ # while incrementer < len(column_names):
129
+ # columns += column_names[incrementer] + " " + column_names[incrementer]
130
+ # incrementer += 1
131
+ # if incrementer != len(column_names):
132
+ # columns += ", "
133
+ #
134
+ # incrementer = 0
135
+ # tables = ""
136
+ # while incrementer < len(table_names):
137
+ # tables += table_names[incrementer] + " " + table_names[incrementer]
138
+ # incrementer += 1
139
+ # if incrementer != len(table_names):
140
+ # table += ", "
141
+
142
+ # con = sqlite3.connect(filename)
143
+ # cur = con.cursor()
144
+ # sql = f"SELECT {columns} from {tables}"
145
+ # if value_comparisons is not None:
146
+ # sql += "where {value_comparisons}"
147
+ # cur.execute(sql)
148
+ # con.commit()
149
+ # return cur.fetchall() # return rows of data
150
+
151
+ def add_column(filename, table_name, column_name, column_type):
152
+ con = sqlite3.connect(filename)
153
+ cur = con.cursor()
154
+ sql = f"ALTER TABLE {table_name} ADD COLUMN {column_name} {column_type}"
155
+ cur.execute(sql)
156
+ con.commit()
157
+
158
+ def value_exists(filename, table_names, column_names, value_comparisons):
159
+ incrementer = 0
160
+ columns = ""
161
+ while incrementer < len(column_names):
162
+ columns += column_names[incrementer] + " " + column_names[incrementer]
163
+ incrementer += 1
164
+ if incrementer != len(column_names):
165
+ columns += ", "
166
+
167
+ incrementer = 0
168
+ tables = ""
169
+ while incrementer < len(table_names):
170
+ tables += table_names[incrementer] + " " + table_names[incrementer]
171
+ incrementer += 1
172
+ if incrementer != len(table_names):
173
+ table += ", "
174
+
175
+ con = sqlite3.connect(filename)
176
+ cur = con.cursor()
177
+ sql = f"SELECT {columns} from {tables} where {value_comparisons}"
178
+ try:
179
+ cur.execute(sql)
180
+ rows = cur.fetchall()
181
+ except Exception as e:
182
+ logging.error(f"Issue running query '{sql}': {e}")
183
+ return False
184
+
185
+ if len(rows) > 0:
186
+ return True
187
+ else:
188
+ return False
189
+
190
+ def add_table(filename, table_name, columns):
191
+ con = sqlite3.connect(filename)
192
+ cur = con.cursor()
193
+ sql = f"CREATE TABLE IF NOT EXISTS {table_name}({columns})"
194
+ logging.debug(sql)
195
+ logging.info(f"Creating table {table_name} in {filename} with columns {columns}")
196
+ cur.execute(sql)
197
+ con.commit()
198
+
199
+ def drop_table(filename, table_name):
200
+ con = sqlite3.connect(filename)
201
+ cur = con.cursor()
202
+ sql = f"DROP TABLE {table_name}"
203
+ cur.execute(sql)
204
+ con.commit()
File without changes
@@ -0,0 +1 @@
1
+ from dshield_parser.web_processor import *
File without changes
@@ -0,0 +1,76 @@
1
+ from dshield_parser.utils import json as dshield_json
2
+ import itertools
3
+
4
+ default_datespan = {'start_date': '1970-01-01', 'end_date': '3000-01-01'}
5
+
6
+ def get_top_10_ips(json_data, datespan=default_datespan):
7
+ return dshield_json.get_top_10("sip", json_data, datespan)
8
+
9
+ def get_summary_ips(json_data, datespan=default_datespan, exclusions=None):
10
+ return dshield_json.get_summary_values("sip", json_data, datespan, exclusions)
11
+
12
+ def get_top_10_headers(json_data, datespan=default_datespan):
13
+ return dshield_json.get_top_10("headers", json_data, datespan)
14
+
15
+ def get_summary_headers(json_data, datespan=default_datespan, exclusions=None):
16
+ return dshield_json.get_summary_values("headers", json_data, datespan, exclusions)
17
+
18
+ def get_top_10_method(json_data, datespan=default_datespan):
19
+ return dshield_json.get_top_10("method", json_data, datespan)
20
+
21
+ def get_summary_methods(json_data, datespan=default_datespan, exclusions=None):
22
+ return dshield_json.get_summary_values("method", json_data, datespan, exclusions)
23
+
24
+ def get_top_10_url(json_data, datespan=default_datespan):
25
+ return dshield_json.get_top_10("url", json_data, datespan)
26
+
27
+ def get_summary_urls(json_data, datespan=default_datespan, exclusions=None):
28
+ return dshield_json.get_summary_values("url", json_data, datespan, exclusions)
29
+
30
+ def get_all_urls(json_data, datespan=default_datespan, exclusions=None):
31
+ return dshield_json.get_json_values("url", json_data, datespan, exclusions)
32
+
33
+ def get_top_10_data(json_data, datespan=default_datespan):
34
+ return dshield_json.get_top_10("data", json_data, datespan)
35
+
36
+ def get_summary_data(json_data, datespan=default_datespan, exclusions=None):
37
+ return dshield_json.get_summary_values("data", json_data, datespan, exclusions)
38
+
39
+ def get_top_10_useragent(json_data, datespan=default_datespan):
40
+ return dshield_json.get_top_10("useragent", json_data, datespan)
41
+
42
+ def get_summary_useragents(json_data, datespan=default_datespan, exclusions=None):
43
+ return dshield_json.get_summary_values("useragent", json_data, datespan, exclusions)
44
+
45
+ def get_top_10_version(json_data, datespan=default_datespan):
46
+ return dshield_json.get_top_10("version", json_data, datespan)
47
+
48
+ def get_summary_versions(json_data, datespan=default_datespan, exclusions=None):
49
+ return dshield_json.get_summary_values("version", json_data, datespan, exclusions)
50
+
51
+ def get_top_10_responseid(json_data, datespan=default_datespan):
52
+ return dshield_json.get_top_10("response_id", json_data, datespan)
53
+
54
+ def get_summary_responseids(json_data, datespan=default_datespan, exclusions=None):
55
+ return dshield_json.get_summary_values("response_id", json_data, datespan, exclusions)
56
+
57
+ def get_top_10_signatureid(json_data, datespan=default_datespan):
58
+ return dshield_json.get_top_10("signature_id", json_data, datespan)
59
+
60
+ def get_summary_signatureids(json_data, datespan=default_datespan, exclusions=None):
61
+ return dshield_json.get_summary_values("signature_id", json_data, datespan, exclusions)
62
+
63
+ def get_top_10_multiple(fields, json_data, datespan=default_datespan):
64
+ return dshield_json.get_top_10(fields, json_data, datespan)
65
+
66
+ def get_summary_multiple(fields, json_data, datespan=default_datespan, exclusions=None):
67
+ return dshield_json.get_summary_values(fields, json_data, datespan, exclusions)
68
+
69
+ def get_summary_all(json_data, datespan=default_datespan, exclusions=None):
70
+ keys = dshield_json.get_json_keys(json_data)
71
+ return keys, dshield_json.get_summary_values(keys, json_data, datespan, exclusions)
72
+
73
+ def get_volume_over_time(json_data, datespan=None):
74
+ if datespan is None:
75
+ datespan = default_datespan
76
+ return dshield_json.get_summary_values("time", json_data, datespan)
@@ -0,0 +1,3 @@
1
+ Metadata-Version: 2.4
2
+ Name: dshield_parser
3
+ Version: 0.0.0
@@ -0,0 +1,26 @@
1
+ dshield_parser/__init__.py,sha256=YvdQXG5JCiwHZ-vGJR4xkb8AMTBT5sqnpXSCIOlumJk,21
2
+ dshield_parser/__main__.py,sha256=KS8XiLyk1SPk7fvSgTiFg2rphSBR3lOg3r09CIHRh2o,651
3
+ dshield_parser/cowrie_processor/__init__.py,sha256=5Il9wz4Tp-ROf9RYO6vO6nbTRfUvUfxUwtLOgQz7aGk,45
4
+ dshield_parser/cowrie_processor/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
+ dshield_parser/cowrie_processor/reports.py,sha256=-ImDweafXxUJLsTRkTRT7poAEhQ8Xw8wc3DTfBR8o5o,3895
6
+ dshield_parser/firewall_processor/__init__.py,sha256=RvVuspWYcMlOk3586rzlmloni2-vByAK9MCam6ExOl4,47
7
+ dshield_parser/firewall_processor/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
8
+ dshield_parser/firewall_processor/reports.py,sha256=kE1Vn9i0e9_kL0IL4jh7oN38Jl1NxSfznco6uDDGuv4,3571
9
+ dshield_parser/test/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
10
+ dshield_parser/test/test_json.py,sha256=Fi-IfrZwgRwG-S6JHZlyW8CqgN8qxQMEOCitto890tw,19041
11
+ dshield_parser/utils/__init__.py,sha256=5xDI_zLzsLufARfazcSBdnTqzlwxVzaWB2p8k-Qi3LY,34
12
+ dshield_parser/utils/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
13
+ dshield_parser/utils/enrichment.py,sha256=IEsj8LuV-8f0jr-xMuu4m_dKSY3xya0X9BYMFegW4JE,16274
14
+ dshield_parser/utils/file_io.py,sha256=vinxM70ZVawA0Pm2nEFLGa89mc8LHACS9AMI4PLnJLI,3911
15
+ dshield_parser/utils/graphs.py,sha256=_Qoj0hevZOyFJXa5WmJpu-X1PARb8RuBSEjNy-Jkvwo,4474
16
+ dshield_parser/utils/json.py,sha256=fA_VNKvgvlQcLvVcdb-ahYmyDOoYVaQ_pPwuV97ANjk,27959
17
+ dshield_parser/utils/ml.py,sha256=LrmUbyDqn_L-k5M2JOjryQ9_Y1HLNY4hegCZUqsG0L8,3235
18
+ dshield_parser/utils/sql.py,sha256=hr-WcGwL816Nla3hLckjJ7p0xsELD-bjEyWY0Aco_Fc,7117
19
+ dshield_parser/utils/ssh.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
20
+ dshield_parser/web_processor/__init__.py,sha256=ib_dZ4okzZzvre7FY9JKUsFGuF2IqNAB3C3Udk22szg,42
21
+ dshield_parser/web_processor/__main__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
22
+ dshield_parser/web_processor/reports.py,sha256=P6bKqZTm3ndcduSmwvSK7xB81LIu5zua0ZD6891St88,3768
23
+ dshield_parser-0.0.0.dist-info/METADATA,sha256=xEDT6-9HZFEgkyZITn_9xBAfBlJ_0iSZh6-HA69G0S8,58
24
+ dshield_parser-0.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
25
+ dshield_parser-0.0.0.dist-info/top_level.txt,sha256=5fVrWGx44ZfX9aV-bPlXsKvwBhNm701Z27I7Baz71n0,15
26
+ dshield_parser-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ dshield_parser