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
|
# File 'lib/threatexpert/submit.rb', line 11
def submit(filename, email, ={})
uri = URI.parse(@@submiturl)
http = Net::HTTP.new(uri.host, uri.port)
['User-Agent'] ||= "Ruby/#{RUBY_VERSION} threatexpert gem (https://github.com/chrislee35/threatexpert)"
['Referer'] ||= @@submiturl
resp, data = http.get(uri.path, )
cookie = resp.["set-cookie"] if resp.["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
['Referer'] = @@submiturl
request = Net::HTTP::Post::Multipart.new(uri.path, params)
.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
|