-
Notifications
You must be signed in to change notification settings - Fork 5
/
search-stuffs.py
80 lines (72 loc) · 2.53 KB
/
search-stuffs.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
#!/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']
rules_dir = config['rules_dir']
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
## testing