-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquery.py
71 lines (63 loc) · 2.22 KB
/
query.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
68
69
70
71
#!/usr/bin/python
"""
Author : Saikiranuppu
Version: 1.0.0
Created: 2017-11-27
"""
import MySQLdb
import argparse
"""
Database Variables
"""
mysql_host = ""
mysql_user = "root"
mysql_pass = "toor"
mysql_database = "malware"
def query(mime,source,severity,author,tags,size_low,size_high):
try:
connection = MySQLdb.connect(mysql_host,mysql_user,mysql_pass,mysql_database)
cursor = connection.cursor()
sql = "SELECT * from `file_meta` where `mime` = %s and `file_source` = %s and `severity` =%s and `author` = %s and `file_size` BETWEEN %s and %s"
cursor.execute(sql,(mime,source,severity,author,size_low,size_high))
rows = cursor.fetchall()
for row in rows:
print row[8]
except Exception as e:
print str(e)
import traceback
traceback.print_exc()
def main():
parser = argparse.ArgumentParser(formatter_class=argparse.RawTextHelpFormatter)
parser.add_argument("-m" ,
"--mime",
required=True,
help="Mime Type of Files for query")
parser.add_argument("-s",
"--size",type=str,
help="Size query of files (Specify Range in MB like 1,2 or 1 )")
parser.add_argument("-src","--source",required=True,
help="Source from which malware is downloaded")
parser.add_argument("-sev","--severity",required=True,
choices=set(('clean','malicious')),
help="Benign or Malicious")
parser.add_argument("-a","--author",required=True,
help="Author name")
parser.add_argument("-t","--tags",default='',
help="Tags to classify the samples")
args = parser.parse_args()
source = args.source
severity = args.severity
author = args.author
tags = args.tags
mime = args.mime
my_list = [float(item) for item in args.size.split(',')]
try:
if not my_list[1]:
pass
except:
my_list.append(999999999)
size_low = my_list[0]*1024*1024
size_high = my_list[-1]*1024*1024
query(mime,source,severity,author,tags,size_low,size_high)
if __name__ == '__main__':
main()