-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsearchstuffs.py
126 lines (113 loc) · 4.08 KB
/
searchstuffs.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env python
import yara
import re
import sys
import json
import os
import argparse
import time
import common
from check_base64 import extract_base64_strings
#load config file
config=common.config()
#load needed params
samples_dir = config['samples_dir']
json_db = config['json_db']
rules_dir = config['rules_dir']
with open(json_db, 'r') as db_file:
db = json.load(db_file)
def xmrig(sha256):
sample_path = samples_dir + sha256
Xmrig_rule = yara.compile(filepath = rules_dir + './xmrig.yara')
matches = Xmrig_rule.match(sample_path)
if len(matches) != 0:
return True
else:
return False
#look for wget/curl
def wget_curl(sha256):
sample_path = samples_dir + sha256
wgetcurl_rule = yara.compile(filepath = rules_dir + './wget_curl.yara')
matches = wgetcurl_rule.match(sample_path)
filtered_matches = []
if matches != []:
for match in matches[0].strings:
tmp=''
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str(match[2]))
for url in urls:
if "\\" in url or len(url) < 20:
tmp = ''
elif ";" in url:
tmp = url.split(";")[0]
elif "'" in url:
tmp = url.split("'")[0]
elif ")" in url:
tmp = url.split(")")[0]
else:
tmp = url
if tmp != '' and tmp not in filtered_matches:
filtered_matches.append(tmp)
return filtered_matches
def powershell_url_param(sha256):
sample_path = samples_dir + sha256
powershell_url_rule = yara.compile(filepath = rules_dir + './powershell_url.yara')
matches = powershell_url_rule.match(sample_path)
filtered_matches = []
if matches != []:
for match in matches[0].strings:
tmp=''
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str(match[2]))
for url in urls:
if "\\" in url or len(url) < 20:
tmp = ''
elif ";" in url:
tmp = url.split(";")[0]
elif "'" in url:
tmp = url.split("'")[0]
elif ")" in url:
tmp = url.split(")")[0]
else:
tmp = url
if tmp != '' and tmp not in filtered_matches:
filtered_matches.append(tmp)
return filtered_matches
def http_ext(sha256):
sample_path = samples_dir + sha256
http_ext_rule = yara.compile(filepath = rules_dir + './http_ext.yara')
matches = http_ext_rule.match(sample_path)
filtered_matches = []
if matches != []:
for match in matches[0].strings:
tmp=''
urls = re.findall('http[s]?://(?:[a-zA-Z]|[0-9]|[$-_@.&+]|[!*\(\),]|(?:%[0-9a-fA-F][0-9a-fA-F]))+', str(match[2]))
for url in urls:
if url.count("/") < 3:
tmp = ''
elif "'" in url:
tmp = url.split("'")[0]
else:
tmp = url
if tmp != '' and tmp not in filtered_matches:
filtered_matches.append(tmp)
return filtered_matches
#def
## testing
def urls(sample):
urls=[]
#search for urls
powershell_urls = powershell_url_param(sample['sha256'])
urls += powershell_urls
wget_curl_urls = wget_curl(sample['sha256'])
urls += wget_curl_urls
http_ext_urls = http_ext(sample['sha256'])
urls += http_ext_urls
#removing duplicates
urls = list(set(urls))
sample['urls']=urls
return sample
def test():
for sample in db['samples']:
if sample['sha256'] == '38c381e1f0d8db27082d5809b70fc73d5c7137e266bc22b4301dd4bbd5e79637':
print(urls(sample))
#test()
#print(http_ext("38c381e1f0d8db27082d5809b70fc73d5c7137e266bc22b4301dd4bbd5e79637"))