yara-normalize 0.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data.tar.gz.sig +0 -0
- data/.document +5 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +48 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/lib/yara-normalize.rb +1 -0
- data/lib/yara-normalize/yara-normalize.rb +84 -0
- data/test/helper.rb +18 -0
- data/test/test_yara-normalize.rb +172 -0
- data/yara-normalize.gemspec +66 -0
- metadata +160 -0
- metadata.gz.sig +0 -0
data.tar.gz.sig
ADDED
Binary file
|
data/.document
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "shoulda", ">= 0"
|
10
|
+
gem "rdoc", "~> 3.12"
|
11
|
+
gem "bundler", "~> 1.1.5"
|
12
|
+
gem "jeweler", "~> 1.8.4"
|
13
|
+
gem "rcov", ">= 0"
|
14
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
activesupport (3.2.8)
|
5
|
+
i18n (~> 0.6)
|
6
|
+
multi_json (~> 1.0)
|
7
|
+
git (1.2.5)
|
8
|
+
i18n (0.6.0)
|
9
|
+
jeweler (1.8.4)
|
10
|
+
bundler (~> 1.0)
|
11
|
+
git (>= 1.2.5)
|
12
|
+
rake
|
13
|
+
rdoc
|
14
|
+
json (1.7.5)
|
15
|
+
multi_json (1.3.6)
|
16
|
+
rake (0.9.2.2)
|
17
|
+
rcov (1.0.0)
|
18
|
+
rdoc (3.12)
|
19
|
+
json (~> 1.4)
|
20
|
+
shoulda (3.1.1)
|
21
|
+
shoulda-context (~> 1.0)
|
22
|
+
shoulda-matchers (~> 1.2)
|
23
|
+
shoulda-context (1.0.0)
|
24
|
+
shoulda-matchers (1.2.0)
|
25
|
+
activesupport (>= 3.0.0)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.1.5)
|
32
|
+
jeweler (~> 1.8.4)
|
33
|
+
rcov
|
34
|
+
rdoc (~> 3.12)
|
35
|
+
shoulda
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012 chrislee35
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= yara-normalize
|
2
|
+
|
3
|
+
Normalizes Yara Signatures into a repeatable hash even when non-transforming changes are made}
|
4
|
+
To enable consistent comparisons between yara rules (signature), a uniform hashing standard was needed.
|
5
|
+
|
6
|
+
This modules takes just the strings from the strings section, sorts them, then generate a sha1 hash.
|
7
|
+
Then, in the conditions section, reorder the boolean expression to make groups first and then replace all variables
|
8
|
+
with $a $b $c, etc. Then hash the result of this.
|
9
|
+
|
10
|
+
Then, the signature ID is the concatenation of the sha1 sum of the sorted strings and the sha1 sum of the normalized conditions.
|
11
|
+
|
12
|
+
== Usage
|
13
|
+
|
14
|
+
See test cases.
|
15
|
+
|
16
|
+
require 'yara-normalize'
|
17
|
+
sig =<<EOS
|
18
|
+
rule DataConversion__wide : IntegerParsing DataConversion {
|
19
|
+
meta:
|
20
|
+
weight = 1
|
21
|
+
strings:
|
22
|
+
$ = "wtoi" nocase
|
23
|
+
$ = "wtol" nocase
|
24
|
+
$ = "wtof" nocase
|
25
|
+
$ = "wtodb" nocase
|
26
|
+
condition:
|
27
|
+
any of them
|
28
|
+
}
|
29
|
+
EOS
|
30
|
+
yn = Yara::Normalizer.new
|
31
|
+
nrm = yn.normalize(sig)
|
32
|
+
puts nrm.hash_code # => dacfb7f79e2ad96cb66c4784323d91e09e8ad2f8c214c8ea0a52e3a3bda71e6612f02361609e0f7a
|
33
|
+
|
34
|
+
== Contributing to yara-normalize
|
35
|
+
|
36
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
37
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
38
|
+
* Fork the project.
|
39
|
+
* Start a feature/bugfix branch.
|
40
|
+
* Commit and push until you are happy with your contribution.
|
41
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
42
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
43
|
+
|
44
|
+
== Copyright
|
45
|
+
|
46
|
+
Copyright (c) 2012 chrislee35. See LICENSE.txt for
|
47
|
+
further details.
|
48
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "yara-normalize"
|
18
|
+
gem.homepage = "http://github.com/chrislee35/yara-normalize"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Normalizes Yara Signatures into a repeatable hash even when non-transforming changes are made}
|
21
|
+
gem.description = %Q{To enable consistent comparisons between yara rules (signature), a uniform hashing standard was needed.}
|
22
|
+
gem.email = "rubygems@chrislee.dhs.org"
|
23
|
+
gem.authors = ["chrislee35"]
|
24
|
+
gem.signing_key = "#{File.dirname(__FILE__)}/../gem-private_key.pem"
|
25
|
+
gem.cert_chain = ["#{File.dirname(__FILE__)}/../gem-public_cert.pem"]
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
Rake::TestTask.new(:test) do |test|
|
31
|
+
test.libs << 'lib' << 'test'
|
32
|
+
test.pattern = 'test/**/test_*.rb'
|
33
|
+
test.verbose = true
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'rcov/rcovtask'
|
37
|
+
Rcov::RcovTask.new do |test|
|
38
|
+
test.libs << 'test'
|
39
|
+
test.pattern = 'test/**/test_*.rb'
|
40
|
+
test.verbose = true
|
41
|
+
test.rcov_opts << '--exclude "gems/*"'
|
42
|
+
end
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rdoc/task'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "yara-normalize #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.0.0
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'yara-normalize/yara-normalize'
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'digest/sha1'
|
2
|
+
|
3
|
+
module Yara
|
4
|
+
class Rule < Struct.new(:name, :tags, :meta, :strings, :condition)
|
5
|
+
def hash_code
|
6
|
+
normalized_strings = strings.map{|x| x.gsub(/^\s*\$\w+\s*=\s*/,'')}.sort.join("%")
|
7
|
+
strings_hash = Digest::SHA1.hexdigest(normalized_strings)
|
8
|
+
condition_hash = Digest::SHA1.hexdigest(normalized_condition)
|
9
|
+
#pp normalized_strings
|
10
|
+
#pp normalized_condition
|
11
|
+
"#{strings_hash}#{condition_hash}"
|
12
|
+
end
|
13
|
+
|
14
|
+
def condition_var_replace(condition)
|
15
|
+
vars = {}
|
16
|
+
nextvar = 'a'
|
17
|
+
condition.gsub(/\$\w+/) do |x|
|
18
|
+
unless vars[x]
|
19
|
+
vars[x] = "\$#{nextvar}"
|
20
|
+
nextvar = (nextvar[0] + 1).chr
|
21
|
+
end
|
22
|
+
vars[x]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
# ($a and $b) or ($c and $d and ($e or $f)) => (($e or $f) and $c and $d) or ($a and $b)
|
27
|
+
# [['$a','and','$b'],'or',['$c','and','$d','and',['$e','or','$f']]]
|
28
|
+
def normalized_condition
|
29
|
+
return condition if condition =~ /(any of them|all of them|any \d+ of them)/i
|
30
|
+
condition_var_replace(condition_rearrange(condition_var_replace(self.condition)).join(","))
|
31
|
+
end
|
32
|
+
|
33
|
+
def condition_rearrange(condition)
|
34
|
+
c = condition.gsub(/\(/,'[').gsub(/\)/,'],').gsub(/((\$\w+|and|or|not))/) do |x| "'#{x}',"; end.gsub(/,\]/,']').gsub(/,\s*$/,'')
|
35
|
+
arr = eval("[#{c}]")
|
36
|
+
condition_rearrange2(arr)
|
37
|
+
end
|
38
|
+
|
39
|
+
def condition_rearrange2(subpart)
|
40
|
+
if subpart.is_a? Array
|
41
|
+
subpart.sort {|a,b|
|
42
|
+
if a.is_a? Array and b.is_a? Array
|
43
|
+
b.flatten.length <=> a.flatten.length
|
44
|
+
elsif a.is_a? Array
|
45
|
+
-1
|
46
|
+
elsif b.is_a? Array
|
47
|
+
1
|
48
|
+
else
|
49
|
+
b.length <=> a.length
|
50
|
+
end
|
51
|
+
}.map{ |sp|
|
52
|
+
condition_rearrange2(sp)
|
53
|
+
}
|
54
|
+
else
|
55
|
+
subpart
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class Normalizer
|
61
|
+
def initialize
|
62
|
+
end
|
63
|
+
|
64
|
+
def normalize(rule)
|
65
|
+
raise "Invalid rule: rules must begin with the word 'rule'" unless rule =~ /^\s*rule\s/
|
66
|
+
raise "Invalid rule: rules must end with a closing bracket, }" unless rule =~ /\}\s*$/
|
67
|
+
if rule =~ /^\s*rule\s+(\w+)(\s*:\s*(\w[\w\s]+\w))?\s*\{\s*meta:\s*(.*?)\s*strings:\s*(.*?)\s*condition:\s*(.*?)\s*\}\s*$/m
|
68
|
+
#pp $~.captures
|
69
|
+
name,_,tags,meta,strings,condition = $~.captures
|
70
|
+
tags = tags.split(/\s+/) if tags
|
71
|
+
metatags = {}
|
72
|
+
meta.split(/\n+/).each do |x|
|
73
|
+
a,b = x.split(/\s*=\s*/)
|
74
|
+
metatags[a.strip] = b.strip
|
75
|
+
end
|
76
|
+
strings = strings.split(/\n+/).map{|x| x.strip}
|
77
|
+
condition = condition.strip
|
78
|
+
Rule.new(name,tags,metatags,strings,condition)
|
79
|
+
else
|
80
|
+
nil
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'test/unit'
|
11
|
+
require 'shoulda'
|
12
|
+
|
13
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
14
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
15
|
+
require 'yara-normalize'
|
16
|
+
|
17
|
+
class Test::Unit::TestCase
|
18
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require 'helper'
|
2
|
+
class TestYaraNormalize < Test::Unit::TestCase
|
3
|
+
should "normalize a simple signature" do
|
4
|
+
sig =<<EOS
|
5
|
+
rule newIE0daymshtmlExec
|
6
|
+
{
|
7
|
+
meta:
|
8
|
+
author = "adnan.shukor@gmail.com"
|
9
|
+
ref = "http://blog.vulnhunt.com/index.php/2012/09/17/ie-execcommand-fuction-use-after-free-vulnerability-0day_en/"
|
10
|
+
description = "Internet Explorer CMshtmlEd::Exec() 0day"
|
11
|
+
cve = "CVE-2012-XXXX"
|
12
|
+
version = "1"
|
13
|
+
impact = 4
|
14
|
+
hide = false
|
15
|
+
strings:
|
16
|
+
$mshtmlExec_1 = /document\.execCommand\(['"]selectAll['"]\)/ nocase fullword
|
17
|
+
$mshtmlExec_2 = /YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH/ nocase fullword
|
18
|
+
$mshtmlExec_3 = /\<body\son(load|select)=['"]\w*?\(\)\;['"]\son(load|select)=['"]\w*?\(\)['"]/ nocase
|
19
|
+
$mshtmlExec_4 = /var\s\w{1,}\s=\snew\sArray\(\)/ nocase
|
20
|
+
$mshtmlExec_5 = /window\.document\.createElement\(['"]img['"]\)/ nocase
|
21
|
+
$mshtmlExec_6 = /\w{1,}\[0\]\[['"]src['"]\]\s\=\s['"]\w{1,}['"]/ nocase
|
22
|
+
$mshtmlExec_7 = /\<iframe\ssrc=['"].*?['"]/ nocase
|
23
|
+
condition:
|
24
|
+
($mshtmlExec_1 and $mshtmlExec_2 and $mshtmlExec_3) or ($mshtmlExec_4 and $mshtmlExec_5 and ($mshtmlExec_6 or $mshtmlExec_7))
|
25
|
+
}
|
26
|
+
EOS
|
27
|
+
yn = Yara::Normalizer.new
|
28
|
+
nrm = yn.normalize(sig)
|
29
|
+
hash = {}
|
30
|
+
nrm.members.sort.each do |member|
|
31
|
+
hash[member] = nrm[member]
|
32
|
+
end
|
33
|
+
assert_equal({"condition"=>
|
34
|
+
"($mshtmlExec_1 and $mshtmlExec_2 and $mshtmlExec_3) or ($mshtmlExec_4 and $mshtmlExec_5 and ($mshtmlExec_6 or $mshtmlExec_7))",
|
35
|
+
"tags"=>nil,
|
36
|
+
"name"=>"newIE0daymshtmlExec",
|
37
|
+
"strings"=>
|
38
|
+
["$mshtmlExec_1 = /document.execCommand(['\"]selectAll['\"])/ nocase fullword",
|
39
|
+
"$mshtmlExec_2 = /YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH/ nocase fullword",
|
40
|
+
"$mshtmlExec_3 = /<body on(load|select)=['\"]w*?();['\"] on(load|select)=['\"]w*?()['\"]/ nocase",
|
41
|
+
"$mshtmlExec_4 = /var w{1,} = new Array()/ nocase",
|
42
|
+
"$mshtmlExec_5 = /window.document.createElement(['\"]img['\"])/ nocase",
|
43
|
+
"$mshtmlExec_6 = /w{1,}[0][['\"]src['\"]] = ['\"]w{1,}['\"]/ nocase",
|
44
|
+
"$mshtmlExec_7 = /<iframe src=['\"].*?['\"]/ nocase"],
|
45
|
+
"meta"=>
|
46
|
+
{"author"=>"\"adnan.shukor@gmail.com\"",
|
47
|
+
"description"=>"\"Internet Explorer CMshtmlEd::Exec() 0day\"",
|
48
|
+
"ref"=>
|
49
|
+
"\"http://blog.vulnhunt.com/index.php/2012/09/17/ie-execcommand-fuction-use-after-free-vulnerability-0day_en/\"",
|
50
|
+
"impact"=>"4",
|
51
|
+
"hide"=>"false",
|
52
|
+
"cve"=>"\"CVE-2012-XXXX\"",
|
53
|
+
"version"=>"\"1\""}}, hash)
|
54
|
+
assert_equal("ee2e32d623a0debca271cada22b35b3b904d6abd678cf2a48a87b43cd6302e73f67510c19ffe2f1a", nrm.hash_code)
|
55
|
+
end
|
56
|
+
|
57
|
+
should "normalize a simple signature with tags and spaces instead of tabs" do
|
58
|
+
sig =<<EOS
|
59
|
+
rule newIE0daymshtmlExec : tag1 tag2 tag3
|
60
|
+
{
|
61
|
+
meta:
|
62
|
+
author = "adnan.shukor@gmail.com"
|
63
|
+
ref = "http://blog.vulnhunt.com/index.php/2012/09/17/ie-execcommand-fuction-use-after-free-vulnerability-0day_en/"
|
64
|
+
description = "Internet Explorer CMshtmlEd::Exec() 0day"
|
65
|
+
cve = "CVE-2012-XXXX"
|
66
|
+
version = "1"
|
67
|
+
impact = 4
|
68
|
+
hide = false
|
69
|
+
strings:
|
70
|
+
$mshtmlExec_1 = /document\.execCommand\(['"]selectAll['"]\)/ nocase fullword
|
71
|
+
$mshtmlExec_2 = /YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH/ nocase fullword
|
72
|
+
$mshtmlExec_3 = /\<body\son(load|select)=['"]\w*?\(\)\;['"]\son(load|select)=['"]\w*?\(\)['"]/ nocase
|
73
|
+
$mshtmlExec_4 = /var\s\w{1,}\s=\snew\sArray\(\)/ nocase
|
74
|
+
$mshtmlExec_5 = /window\.document\.createElement\(['"]img['"]\)/ nocase
|
75
|
+
$mshtmlExec_6 = /\w{1,}\[0\]\[['"]src['"]\]\s\=\s['"]\w{1,}['"]/ nocase
|
76
|
+
$mshtmlExec_7 = /\<iframe\ssrc=['"].*?['"]/ nocase
|
77
|
+
condition:
|
78
|
+
($mshtmlExec_1 and $mshtmlExec_2 and $mshtmlExec_3) or ($mshtmlExec_4 and $mshtmlExec_5 and ($mshtmlExec_6 or $mshtmlExec_7))
|
79
|
+
}
|
80
|
+
EOS
|
81
|
+
yn = Yara::Normalizer.new
|
82
|
+
nrm = yn.normalize(sig)
|
83
|
+
hash = {}
|
84
|
+
nrm.members.sort.each do |member|
|
85
|
+
hash[member] = nrm[member]
|
86
|
+
end
|
87
|
+
assert_equal({"condition"=>
|
88
|
+
"($mshtmlExec_1 and $mshtmlExec_2 and $mshtmlExec_3) or ($mshtmlExec_4 and $mshtmlExec_5 and ($mshtmlExec_6 or $mshtmlExec_7))",
|
89
|
+
"tags"=>["tag1","tag2","tag3"],
|
90
|
+
"name"=>"newIE0daymshtmlExec",
|
91
|
+
"strings"=>
|
92
|
+
["$mshtmlExec_1 = /document.execCommand(['\"]selectAll['\"])/ nocase fullword",
|
93
|
+
"$mshtmlExec_2 = /YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH/ nocase fullword",
|
94
|
+
"$mshtmlExec_3 = /<body on(load|select)=['\"]w*?();['\"] on(load|select)=['\"]w*?()['\"]/ nocase",
|
95
|
+
"$mshtmlExec_4 = /var w{1,} = new Array()/ nocase",
|
96
|
+
"$mshtmlExec_5 = /window.document.createElement(['\"]img['\"])/ nocase",
|
97
|
+
"$mshtmlExec_6 = /w{1,}[0][['\"]src['\"]] = ['\"]w{1,}['\"]/ nocase",
|
98
|
+
"$mshtmlExec_7 = /<iframe src=['\"].*?['\"]/ nocase"],
|
99
|
+
"meta"=>
|
100
|
+
{"author"=>"\"adnan.shukor@gmail.com\"",
|
101
|
+
"description"=>"\"Internet Explorer CMshtmlEd::Exec() 0day\"",
|
102
|
+
"ref"=>
|
103
|
+
"\"http://blog.vulnhunt.com/index.php/2012/09/17/ie-execcommand-fuction-use-after-free-vulnerability-0day_en/\"",
|
104
|
+
"impact"=>"4",
|
105
|
+
"hide"=>"false",
|
106
|
+
"cve"=>"\"CVE-2012-XXXX\"",
|
107
|
+
"version"=>"\"1\""}}, hash)
|
108
|
+
assert_equal("ee2e32d623a0debca271cada22b35b3b904d6abd678cf2a48a87b43cd6302e73f67510c19ffe2f1a", nrm.hash_code)
|
109
|
+
end
|
110
|
+
|
111
|
+
should "normalize a simple signature that has been rearranged" do
|
112
|
+
sig =<<EOS
|
113
|
+
rule newIE0daymshtmlExec
|
114
|
+
{
|
115
|
+
meta:
|
116
|
+
author = "adnan.shukor@gmail.com"
|
117
|
+
ref = "http://blog.vulnhunt.com/index.php/2012/09/17/ie-execcommand-fuction-use-after-free-vulnerability-0day_en/"
|
118
|
+
description = "Internet Explorer CMshtmlEd::Exec() 0day"
|
119
|
+
cve = "CVE-2012-XXXX"
|
120
|
+
version = "1"
|
121
|
+
impact = 4
|
122
|
+
hide = false
|
123
|
+
strings:
|
124
|
+
$mshtmlExec_3 = /\<body\son(load|select)=['"]\w*?\(\)\;['"]\son(load|select)=['"]\w*?\(\)['"]/ nocase
|
125
|
+
$mshtmlExec_5 = /window\.document\.createElement\(['"]img['"]\)/ nocase
|
126
|
+
$mshtmlExec_6 = /\w{1,}\[0\]\[['"]src['"]\]\s\=\s['"]\w{1,}['"]/ nocase
|
127
|
+
$mshtmlExec_4 = /var\s\w{1,}\s=\snew\sArray\(\)/ nocase
|
128
|
+
$mshtmlExec_1 = /document\.execCommand\(['"]selectAll['"]\)/ nocase fullword
|
129
|
+
$mshtmlExec_7 = /\<iframe\ssrc=['"].*?['"]/ nocase
|
130
|
+
$mshtmlExec_2 = /YMjf\\u0c08\\u0c0cKDogjsiIejengNEkoPDjfiJDIWUAzdfghjAAuUFGGBSIPPPUDFJKSOQJGH/ nocase fullword
|
131
|
+
condition:
|
132
|
+
($mshtmlExec_4 and ($mshtmlExec_6 or $mshtmlExec_7) and $mshtmlExec_5) or ($mshtmlExec_1 and $mshtmlExec_2 and $mshtmlExec_3)
|
133
|
+
}
|
134
|
+
EOS
|
135
|
+
yn = Yara::Normalizer.new
|
136
|
+
nrm = yn.normalize(sig)
|
137
|
+
assert_equal("ee2e32d623a0debca271cada22b35b3b904d6abd678cf2a48a87b43cd6302e73f67510c19ffe2f1a", nrm.hash_code)
|
138
|
+
end
|
139
|
+
|
140
|
+
should "normalize a simple signature that has been rearranged" do
|
141
|
+
sig =<<EOS
|
142
|
+
rule DataConversion__wide : IntegerParsing DataConversion {
|
143
|
+
meta:
|
144
|
+
weight = 1
|
145
|
+
strings:
|
146
|
+
$ = "wtoi" nocase
|
147
|
+
$ = "wtol" nocase
|
148
|
+
$ = "wtof" nocase
|
149
|
+
$ = "wtodb" nocase
|
150
|
+
condition:
|
151
|
+
any of them
|
152
|
+
}
|
153
|
+
EOS
|
154
|
+
yn = Yara::Normalizer.new
|
155
|
+
nrm = yn.normalize(sig)
|
156
|
+
hash = {}
|
157
|
+
nrm.members.sort.each do |member|
|
158
|
+
hash[member] = nrm[member]
|
159
|
+
end
|
160
|
+
assert_equal({"tags"=>["IntegerParsing", "DataConversion"],
|
161
|
+
"name"=>"DataConversion__wide",
|
162
|
+
"condition"=>"any of them",
|
163
|
+
"strings"=>
|
164
|
+
["$ = \"wtoi\" nocase",
|
165
|
+
"$ = \"wtol\" nocase",
|
166
|
+
"$ = \"wtof\" nocase",
|
167
|
+
"$ = \"wtodb\" nocase"],
|
168
|
+
"meta"=>{"weight"=>"1"}},hash)
|
169
|
+
assert_equal("dacfb7f79e2ad96cb66c4784323d91e09e8ad2f8c214c8ea0a52e3a3bda71e6612f02361609e0f7a", nrm.hash_code)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
@@ -0,0 +1,66 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{yara-normalize}
|
8
|
+
s.version = "0.0.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["chrislee35"]
|
12
|
+
s.cert_chain = ["/Users/chris/Documents/projects/rubygems/yara-normalize/../gem-public_cert.pem"]
|
13
|
+
s.date = %q{2012-09-30}
|
14
|
+
s.description = %q{To enable consistent comparisons between yara rules (signature), a uniform hashing standard was needed.}
|
15
|
+
s.email = %q{rubygems@chrislee.dhs.org}
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE.txt",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"lib/yara-normalize.rb",
|
29
|
+
"lib/yara-normalize/yara-normalize.rb",
|
30
|
+
"test/helper.rb",
|
31
|
+
"test/test_yara-normalize.rb",
|
32
|
+
"yara-normalize.gemspec"
|
33
|
+
]
|
34
|
+
s.homepage = %q{http://github.com/chrislee35/yara-normalize}
|
35
|
+
s.licenses = ["MIT"]
|
36
|
+
s.require_paths = ["lib"]
|
37
|
+
s.rubygems_version = %q{1.3.6}
|
38
|
+
s.signing_key = %q{/Users/chris/Documents/projects/rubygems/yara-normalize/../gem-private_key.pem}
|
39
|
+
s.summary = %q{Normalizes Yara Signatures into a repeatable hash even when non-transforming changes are made}
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
43
|
+
s.specification_version = 3
|
44
|
+
|
45
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
46
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
47
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
48
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.1.5"])
|
49
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
50
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.5"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
56
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
61
|
+
s.add_dependency(%q<bundler>, ["~> 1.1.5"])
|
62
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
63
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yara-normalize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 0.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- chrislee35
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain:
|
16
|
+
- |
|
17
|
+
-----BEGIN CERTIFICATE-----
|
18
|
+
MIIDYjCCAkqgAwIBAgIBADANBgkqhkiG9w0BAQUFADBXMREwDwYDVQQDDAhydWJ5
|
19
|
+
Z2VtczEYMBYGCgmSJomT8ixkARkWCGNocmlzbGVlMRMwEQYKCZImiZPyLGQBGRYD
|
20
|
+
ZGhzMRMwEQYKCZImiZPyLGQBGRYDb3JnMB4XDTExMDIyNzE1MzAxOVoXDTEyMDIy
|
21
|
+
NzE1MzAxOVowVzERMA8GA1UEAwwIcnVieWdlbXMxGDAWBgoJkiaJk/IsZAEZFghj
|
22
|
+
aHJpc2xlZTETMBEGCgmSJomT8ixkARkWA2RoczETMBEGCgmSJomT8ixkARkWA29y
|
23
|
+
ZzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALNM1Hjs6q58sf7Jp64A
|
24
|
+
vEY2cnRWDdFpD8UWpwaJK5kgSHOVgs+0mtszn+YlYjmx8kpmuYpyU4g9mNMImMQe
|
25
|
+
ow8pVsL4QBBK/1Ozgdxrsptk3IiTozMYA+g2I/+WvZSEDu9uHkKe8pvMBEMrg7RJ
|
26
|
+
IN7+jWaPnSzg3DbFwxwOdi+QRw33DjK7oFWcOaaBqWTUpI4epdi/c/FE1I6UWULJ
|
27
|
+
ZF/Uso0Sc2Pp/YuVhuMHGrUbn7zrWWo76nnK4DTLfXFDbZF5lIXT1w6BtIiN6Ho9
|
28
|
+
Rdr/W6663hYUo3WMsUSa3I5+PJXEBKmGHIZ2TNFnoFIRHha2fmm1HC9+BTaKwcO9
|
29
|
+
PLcCAwEAAaM5MDcwCQYDVR0TBAIwADAdBgNVHQ4EFgQURzsNkZo2rv86Ftc+hVww
|
30
|
+
RNICMrwwCwYDVR0PBAQDAgSwMA0GCSqGSIb3DQEBBQUAA4IBAQBRRw/iNA/PdnvW
|
31
|
+
OBoNCSr/IiHOGZqMHgPJwyWs68FhThnLc2EyIkuLTQf98ms1/D3p0XX9JsxazvKT
|
32
|
+
W/in8Mm/R2fkVziSdzqChtw/4Z4bW3c+RF7TgX6SP5cKxNAfKmAPuItcs2Y+7bdS
|
33
|
+
hr/FktVtT2iAmISRnlEbdaTpfl6N2ZWNT83khV6iOs5xRkX/+0e+GgAv9mE6nqr1
|
34
|
+
AkuDXMhposxcnFZUrZ3UtMPEe/JnyP7Vv6pvr3qtZm8FidFZU91+rX/fwdyBU8RP
|
35
|
+
/5l8uLWXXNt1wEbtu4N1I66LwTK2iRrQZE8XtlgZGbxYDFUkiurq3OafF2YwRs6W
|
36
|
+
6yhklP75
|
37
|
+
-----END CERTIFICATE-----
|
38
|
+
|
39
|
+
date: 2012-09-30 00:00:00 -04:00
|
40
|
+
default_executable:
|
41
|
+
dependencies:
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
prerelease: false
|
44
|
+
type: :development
|
45
|
+
name: shoulda
|
46
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
segments:
|
51
|
+
- 0
|
52
|
+
version: "0"
|
53
|
+
requirement: *id001
|
54
|
+
- !ruby/object:Gem::Dependency
|
55
|
+
prerelease: false
|
56
|
+
type: :development
|
57
|
+
name: rdoc
|
58
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
segments:
|
63
|
+
- 3
|
64
|
+
- 12
|
65
|
+
version: "3.12"
|
66
|
+
requirement: *id002
|
67
|
+
- !ruby/object:Gem::Dependency
|
68
|
+
prerelease: false
|
69
|
+
type: :development
|
70
|
+
name: bundler
|
71
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
segments:
|
76
|
+
- 1
|
77
|
+
- 1
|
78
|
+
- 5
|
79
|
+
version: 1.1.5
|
80
|
+
requirement: *id003
|
81
|
+
- !ruby/object:Gem::Dependency
|
82
|
+
prerelease: false
|
83
|
+
type: :development
|
84
|
+
name: jeweler
|
85
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 1
|
91
|
+
- 8
|
92
|
+
- 4
|
93
|
+
version: 1.8.4
|
94
|
+
requirement: *id004
|
95
|
+
- !ruby/object:Gem::Dependency
|
96
|
+
prerelease: false
|
97
|
+
type: :development
|
98
|
+
name: rcov
|
99
|
+
version_requirements: &id005 !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
segments:
|
104
|
+
- 0
|
105
|
+
version: "0"
|
106
|
+
requirement: *id005
|
107
|
+
description: To enable consistent comparisons between yara rules (signature), a uniform hashing standard was needed.
|
108
|
+
email: rubygems@chrislee.dhs.org
|
109
|
+
executables: []
|
110
|
+
|
111
|
+
extensions: []
|
112
|
+
|
113
|
+
extra_rdoc_files:
|
114
|
+
- LICENSE.txt
|
115
|
+
- README.rdoc
|
116
|
+
files:
|
117
|
+
- .document
|
118
|
+
- Gemfile
|
119
|
+
- Gemfile.lock
|
120
|
+
- LICENSE.txt
|
121
|
+
- README.rdoc
|
122
|
+
- Rakefile
|
123
|
+
- VERSION
|
124
|
+
- lib/yara-normalize.rb
|
125
|
+
- lib/yara-normalize/yara-normalize.rb
|
126
|
+
- test/helper.rb
|
127
|
+
- test/test_yara-normalize.rb
|
128
|
+
- yara-normalize.gemspec
|
129
|
+
has_rdoc: true
|
130
|
+
homepage: http://github.com/chrislee35/yara-normalize
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - ">="
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
segments:
|
143
|
+
- 0
|
144
|
+
version: "0"
|
145
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
|
+
requirements:
|
147
|
+
- - ">="
|
148
|
+
- !ruby/object:Gem::Version
|
149
|
+
segments:
|
150
|
+
- 0
|
151
|
+
version: "0"
|
152
|
+
requirements: []
|
153
|
+
|
154
|
+
rubyforge_project:
|
155
|
+
rubygems_version: 1.3.6
|
156
|
+
signing_key:
|
157
|
+
specification_version: 3
|
158
|
+
summary: Normalizes Yara Signatures into a repeatable hash even when non-transforming changes are made
|
159
|
+
test_files: []
|
160
|
+
|
metadata.gz.sig
ADDED
Binary file
|