yara 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,22 @@
1
+ /*
2
+ * yara-ruby - Ruby bindings for the yara malware analysis library.
3
+ * Eric Monti
4
+ * Copyright (C) 2011 Trustwave Holdings
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify it
7
+ * under the terms of the GNU General Public License as published by the
8
+ * Free Software Foundation, either version 3 of the License, or (at your
9
+ * option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful, but
12
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ * for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along
17
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
1
20
 
2
21
  #ifndef RB_RULES_H_GUARD
3
22
  #define RB_RULES_H_GUARD
@@ -5,8 +24,6 @@
5
24
  #include <yara.h>
6
25
  #include "ruby.h"
7
26
 
8
- static VALUE class_Rules;
9
-
10
- void init_rules(VALUE ruby_namespace);
27
+ void init_Rules();
11
28
 
12
29
  #endif
@@ -1,19 +1,44 @@
1
+ /*
2
+ * yara-ruby - Ruby bindings for the yara malware analysis library.
3
+ * Eric Monti
4
+ * Copyright (C) 2011 Trustwave Holdings
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify it
7
+ * under the terms of the GNU General Public License as published by the
8
+ * Free Software Foundation, either version 3 of the License, or (at your
9
+ * option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful, but
12
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ * for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along
17
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
20
+
1
21
  #include "ruby.h"
2
22
  #include <yara.h>
3
-
4
- #include "Yara_native.h"
5
23
  #include "Rules.h"
6
- #include "errors.h"
24
+ #include "Match.h"
7
25
 
8
- static VALUE module_Yara = Qnil;
26
+ VALUE module_Yara = Qnil;
27
+ VALUE error_CompileError = Qnil;
28
+ VALUE error_ScanError = Qnil;
9
29
 
10
30
  void Init_yara_native() {
11
31
  yr_init();
12
32
 
13
33
  module_Yara = rb_define_module("Yara");
14
34
 
15
- init_errors(module_Yara);
16
- init_rules(module_Yara);
35
+ /* Class Yara::CompileError */
36
+ error_CompileError = rb_define_class_under(module_Yara, "CompileError", rb_eStandardError);
37
+ /* Class Yara::ScanError */
38
+ error_ScanError = rb_define_class_under(module_Yara, "ScanError", rb_eStandardError);
39
+
40
+ init_Rules();
41
+ init_Match();
17
42
  }
18
43
 
19
44
 
@@ -1,9 +1,30 @@
1
+ /*
2
+ * yara-ruby - Ruby bindings for the yara malware analysis library.
3
+ * Eric Monti
4
+ * Copyright (C) 2011 Trustwave Holdings
5
+ *
6
+ * This program is free software: you can redistribute it and/or modify it
7
+ * under the terms of the GNU General Public License as published by the
8
+ * Free Software Foundation, either version 3 of the License, or (at your
9
+ * option) any later version.
10
+ *
11
+ * This program is distributed in the hope that it will be useful, but
12
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ * for more details.
15
+ *
16
+ * You should have received a copy of the GNU General Public License along
17
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ *
19
+ */
20
+
1
21
  #ifndef RB_YARA_H_GUARD
2
22
  #define RB_YARA_H_GUARD
3
23
 
4
24
  #include "ruby.h"
5
25
  #include <yara.h>
6
26
 
7
- static VALUE module_Yara;
27
+ extern VALUE error_CompileError;
28
+ extern VALUE error_ScanError;
8
29
 
9
30
  #endif
@@ -1,3 +1,21 @@
1
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
2
+ # Eric Monti
3
+ # Copyright (C) 2011 Trustwave Holdings
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the
7
+ # Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
18
+
1
19
  require 'mkmf'
2
20
  require 'rbconfig'
3
21
 
@@ -10,5 +28,6 @@ unless have_library("yara") and
10
28
  raise "You must install the yara library"
11
29
  end
12
30
 
31
+ create_header
13
32
  create_makefile(extension_name)
14
33
 
@@ -1,4 +1,20 @@
1
-
1
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
2
+ # Eric Monti
3
+ # Copyright (C) 2011 Trustwave Holdings
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the
7
+ # Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
2
18
  require 'yara_native'
3
19
 
4
20
  module Yara
@@ -3,6 +3,23 @@
3
3
  # Usage example:
4
4
  # ruby ispe.rb /win_c/windows/system32/*.???
5
5
  #
6
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
7
+ # Eric Monti
8
+ # Copyright (C) 2011 Trustwave Holdings
9
+ #
10
+ # This program is free software: you can redistribute it and/or modify it
11
+ # under the terms of the GNU General Public License as published by the
12
+ # Free Software Foundation, either version 3 of the License, or (at your
13
+ # option) any later version.
14
+ #
15
+ # This program is distributed in the hope that it will be useful, but
16
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18
+ # for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License along
21
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
6
23
  $: << File.join(File.dirname(__FILE__), '..', 'lib')
7
24
  require 'yara'
8
25
 
@@ -0,0 +1,73 @@
1
+ #!/usr/bin/env ruby
2
+ # Simple yara-ruby script to extract RSA private keys and certificates
3
+ # based on http://www.trapkit.de/research/sslkeyfinder
4
+ # and http://www.kyprizel.net/work/ida/getkeys.py
5
+ #
6
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
7
+ # Eric Monti
8
+ # Copyright (C) 2011 Trustwave Holdings
9
+ #
10
+ # This program is free software: you can redistribute it and/or modify it
11
+ # under the terms of the GNU General Public License as published by the
12
+ # Free Software Foundation, either version 3 of the License, or (at your
13
+ # option) any later version.
14
+ #
15
+ # This program is distributed in the hope that it will be useful, but
16
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18
+ # for more details.
19
+ #
20
+ # You should have received a copy of the GNU General Public License along
21
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
22
+ #
23
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
24
+ require 'yara'
25
+ require 'pp'
26
+
27
+ ctx = Yara::Rules.new
28
+ ctx.compile_string <<_EOF_
29
+ rule x509_public_key_infrastructure_cert
30
+ {
31
+ meta:
32
+ desc = "X.509 PKI Certificate"
33
+ ext = "crt"
34
+ strings: $a = {30 82 ?? ?? 30 82 ?? ??}
35
+ condition: $a
36
+ }
37
+
38
+ rule pkcs8_private_key_information_syntax_standard
39
+ {
40
+ meta:
41
+ desc = "Found PKCS #8: Private-Key"
42
+ ext = "key"
43
+
44
+ strings: $a = {30 82 ?? ?? 02 01 00}
45
+ condition: $a
46
+ }
47
+ _EOF_
48
+
49
+
50
+ ARGV.each do |fname|
51
+ begin
52
+ file = File.new(fname, 'rb')
53
+ ctx.scan_file(fname).each do |match|
54
+ match.strings.each do |string|
55
+ file.pos = string.offset
56
+ hdr = file.read(4)
57
+ magic, len = hdr.unpack("nn")
58
+
59
+ next unless magic == 0x3082
60
+
61
+ outf = "#{fname}_%0.8x.#{match.meta['ext']}" % string.offset
62
+ STDERR.puts "Found #{match.meta['desc']} in #{fname.inspect} - writing to #{outf.inspect}"
63
+
64
+ File.open(outf, 'wb') do |out|
65
+ out.write hdr
66
+ out.write file.read(len)
67
+ end
68
+ end
69
+ end
70
+ ensure
71
+ file.close if file
72
+ end
73
+ end
@@ -1,5 +1,21 @@
1
1
  #!/usr/bin/env ruby
2
-
2
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
3
+ # Eric Monti
4
+ # Copyright (C) 2011 Trustwave Holdings
5
+ #
6
+ # This program is free software: you can redistribute it and/or modify it
7
+ # under the terms of the GNU General Public License as published by the
8
+ # Free Software Foundation, either version 3 of the License, or (at your
9
+ # option) any later version.
10
+ #
11
+ # This program is distributed in the hope that it will be useful, but
12
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
+ # for more details.
15
+ #
16
+ # You should have received a copy of the GNU General Public License along
17
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
18
+ #
3
19
  $: << 'lib'
4
20
  require 'yara'
5
21
  require 'pp'
@@ -1,3 +1,20 @@
1
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
2
+ # Eric Monti
3
+ # Copyright (C) 2011 Trustwave Holdings
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the
7
+ # Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
1
18
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
19
 
3
20
  describe Yara::Rules do
@@ -1,3 +1,20 @@
1
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
2
+ # Eric Monti
3
+ # Copyright (C) 2011 Trustwave Holdings
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the
7
+ # Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
1
18
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
19
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
20
  require 'rspec'
@@ -1,3 +1,20 @@
1
+ # yara-ruby - Ruby bindings for the yara malware analysis library.
2
+ # Eric Monti
3
+ # Copyright (C) 2011 Trustwave Holdings
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify it
6
+ # under the terms of the GNU General Public License as published by the
7
+ # Free Software Foundation, either version 3 of the License, or (at your
8
+ # option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful, but
11
+ # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12
+ # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13
+ # for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License along
16
+ # with this program. If not, see <http://www.gnu.org/licenses/>.
17
+ #
1
18
  require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
19
 
3
20
  describe Yara do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 4
8
- - 1
9
- version: 1.4.1
8
+ - 2
9
+ version: 1.4.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Eric Monti
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-01-11 00:00:00 -06:00
17
+ date: 2011-02-17 00:00:00 -06:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -97,7 +97,7 @@ dependencies:
97
97
  version: "0"
98
98
  type: :development
99
99
  version_requirements: *id006
100
- description: Ruby Bindings for the yara malware analysis library
100
+ description: Ruby bindings for the yara malware analysis library
101
101
  email: emonti@trustwave.com
102
102
  executables: []
103
103
 
@@ -121,11 +121,10 @@ files:
121
121
  - ext/yara_native/Rules.h
122
122
  - ext/yara_native/Yara_native.c
123
123
  - ext/yara_native/Yara_native.h
124
- - ext/yara_native/errors.c
125
- - ext/yara_native/errors.h
126
124
  - ext/yara_native/extconf.rb
127
125
  - lib/yara.rb
128
126
  - samples/ispe.rb
127
+ - samples/sslkeyfinder
129
128
  - samples/upx.rb
130
129
  - spec/rules_spec.rb
131
130
  - spec/samples/DumpMem.exe
@@ -162,7 +161,7 @@ rubyforge_project:
162
161
  rubygems_version: 1.3.6
163
162
  signing_key:
164
163
  specification_version: 3
165
- summary: Ruby Bindings for libyara
164
+ summary: Ruby bindings for libyara
166
165
  test_files:
167
166
  - spec/rules_spec.rb
168
167
  - spec/spec_helper.rb
@@ -1,11 +0,0 @@
1
- #include "errors.h"
2
- #include "ruby.h"
3
-
4
- VALUE error_CompileError = Qnil;
5
- VALUE error_ScanError = Qnil;
6
-
7
- void
8
- init_errors(VALUE rb_ns) {
9
- error_CompileError = rb_define_class_under(rb_ns, "CompileError", rb_eStandardError);
10
- error_ScanError = rb_define_class_under(rb_ns, "ScanError", rb_eStandardError);
11
- }
@@ -1,9 +0,0 @@
1
- #ifndef RB_YARA_ERR_H_GUARD
2
- #define RB_YARA_ERR_H_GUARD
3
-
4
- #include "ruby.h"
5
-
6
- extern VALUE error_CompileError;
7
- extern VALUE error_ScanError;
8
-
9
- #endif