Class: ThreatExpert::Submit

Inherits:
Object
  • Object
show all
Defined in:
lib/threatexpert/submit.rb

Constant Summary collapse

@@submiturl =
"http://www.threatexpert.com/submit.aspx"

Instance Method Summary collapse

Instance Method Details

#submit(filename, email, headers = {}) ⇒ Object



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
# File 'lib/threatexpert/submit.rb', line 10

def submit(filename, email, headers={})
	uri = URI.parse(@@submiturl)
	http = Net::HTTP.new(uri.host, uri.port)
	headers['User-Agent'] ||= "Ruby/#{RUBY_VERSION} threatexpert gem version #{ThreatExpert::VERSION} (https://github.com/chrislee35/threatexpert)"
	headers['Referer'] ||= @@submiturl
	resp, data = http.get(uri.path, headers)
	cookie = resp.header["set-cookie"] if resp.header["set-cookie"]
	
	doc = Nokogiri::HTML.parse(data)
	forms = doc.xpath('//form')
	inputs = forms[0].xpath('//input')
	params = {}
	inputs.each do |input|
		name = input['name']
		value = input['value']
		if name =~ /Agree/
			params[name] = 1
		elsif name =~ /Upload/
			file = File.open(filename)
			params[name] = UploadIO.new(file, "application/octet-stream", File.basename(filename))
		elsif name =~ /Email/
			params[name] = email
		elsif name =~ /btnSubmit/
			params[name+".x"] = rand(100)
			params[name+".y"] = rand(27)
		else
			params[name] = value
		end
	end
	
	headers['Referer'] = @@submiturl
	request = Net::HTTP::Post::Multipart.new(uri.path, params)
	headers.each do |name,value|
		request.add_field(name, value)
	end
	response = http.request(request)
	if response.body =~ /The file has been accepted/
		true
	else
		false
	end
end