-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsubmit_sample.py
More file actions
137 lines (100 loc) · 4.9 KB
/
Copy pathsubmit_sample.py
File metadata and controls
137 lines (100 loc) · 4.9 KB
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
127
128
129
130
131
132
133
134
135
136
137
#!/usr/bin/env python
#
# submit_sample.py - Script that sends a file of suspected malware for
# analysis to Symantec. Requires a Business Critical Support ID Number.
#
# USAGE: ./submit_sample.py [-u URL | -f FILE]
#
# All code Copyright (c) 2013, Ben Jackson and Mayhemic Labs -
# bbj@mayhemiclabs.com. All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author nor the names of contributors may be
# used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os, requests, argparse, random, hashlib, cStringIO, sys
from ConfigParser import SafeConfigParser
#Read the configuration file
config = SafeConfigParser()
config.read('config.ini')
#Read the command line arguments
parser = argparse.ArgumentParser()
#The user needs to specify iether a URL or a filename
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('-u', '--url', action='store')
group.add_argument('-f', '--file', action='store')
parser.add_argument("-v", "--verbose", help="Increase logging verbosity", action="store_true")
parser.add_argument("-s", "--severe", help="Flag Submission as High Severity", action="store_true", default=0)
parser.add_argument("-c", "--comments", help="Comments to Send With File", action="store", default='')
parser.add_argument('args', nargs=argparse.REMAINDER)
args = parser.parse_args()
if args.file is None:
#If user has told us it's a URL download it
print "Downloading " + args.url + "..."
#Set up some random User Agents and choose one...
useragent_list = (
'Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Firefox/17.0',
'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/17.0 Firefox/17.0',
'Mozilla/5.0 (Windows NT 6.2; Win64; x64; rv:16.0.1) Gecko/20121011 Firefox/16.0.1',
'Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.1; WOW64; Trident/6.0)',
'Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 7.1; Trident/5.0)'
)
req_headers = {
'User-Agent': random.choice(useragent_list),
'Referer': 'http://www.google.com/trends/hottrends'
}
#Make the request
sample_request = requests.get(args.url, headers=req_headers)
if sample_request.status_code == 200:
#If we grabbed it, dump it into a StringIO object so we can use it
holdingfile = cStringIO.StringIO()
holdingfile.write(sample_request.content)
#Put the file into the variable and generate a hash for the filename
file = sample_request.content
filename = hashlib.sha256(sample_request.content).hexdigest()
else:
#If it doesn't return a 200, abort....
print args.url + " did not return HTTP 200..."
sys.exit(1)
else:
#If it's a file read it in and
file = open(args.file, 'rb')
filename = os.path.basename(args.file)
#OK, let's submit this bad mamma jamma
print "Submitting File..."
#Symantec BCS URL
submission_url = "https://submit.symantec.com/websubmit/bcs.cgi"
#Generate the payload of the POST request from the config.ini settings
payload = {'mode' : '2',
'fname' : config.get('symantec_bcs', 'first_name'),
'lname' : config.get('symantec_bcs', 'last_name'),
'cname' : config.get('symantec_bcs', 'company_name'),
'email' : config.get('symantec_bcs', 'email_address'),
'email2' : config.get('symantec_bcs', 'email_address'),
'pin' : config.get('symantec_bcs', 'bcs_id'),
'critical' : args.severe,
'comments' : args.comments
}
#...and attach the file
files = {'upfile' : (filename, file)}
#Submit the request
r = requests.post(submission_url, payload, files=files)
#FIXME: Print out the Page
print r.text