iocparser 0.0.1
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.
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +1 -0
- data/bin/iocparser +60 -0
- data/iocparser.gemspec +23 -0
- data/lib/iocparser.rb +6 -0
- data/lib/iocparser/iocparser.rb +51 -0
- data/lib/iocparser/version.rb +3 -0
- metadata +88 -0
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Matteo Michelini - cor3ngine
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Iocparser
|
|
2
|
+
|
|
3
|
+
iocparser is a command line utility to parse and query Mandiant Indicator of Compromise (IOC) XML files.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
Download and unzip the master zip from github and execute the following into the iocparser directory
|
|
8
|
+
|
|
9
|
+
$ gem build ./iocparser.gemspec
|
|
10
|
+
# gem install iocparser-0.0.1.gem
|
|
11
|
+
|
|
12
|
+
Or install it yourself as:
|
|
13
|
+
|
|
14
|
+
$ gem install iocparser
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
Print the structure of the IOC file with the number of items embedded into it
|
|
19
|
+
|
|
20
|
+
$ iocparser -f test.ioc
|
|
21
|
+
+++ IOC Items +++
|
|
22
|
+
Network => 3
|
|
23
|
+
PortItem => 2
|
|
24
|
+
UrlHistoryItem => 3
|
|
25
|
+
FileItem => 246
|
|
26
|
+
ProcessItem => 2
|
|
27
|
+
+++ END +++
|
|
28
|
+
|
|
29
|
+
Print the type of an IOC item
|
|
30
|
+
|
|
31
|
+
$ iocparser -f test.ioc -t Network
|
|
32
|
+
Network/DNS
|
|
33
|
+
|
|
34
|
+
Print the values embedded into an IOC type
|
|
35
|
+
|
|
36
|
+
$ iocparser -f test.ioc -v Network/DNS
|
|
37
|
+
maliciousdomain1.com
|
|
38
|
+
maliciousdomain2.net
|
|
39
|
+
maliciousdomain3.org
|
|
40
|
+
|
|
41
|
+
## Contributing
|
|
42
|
+
|
|
43
|
+
1. Fork it
|
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/iocparser
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
$:.unshift File.join(File.dirname(File.dirname(__FILE__)), 'lib')
|
|
3
|
+
|
|
4
|
+
require 'iocparser'
|
|
5
|
+
require 'optparse'
|
|
6
|
+
|
|
7
|
+
options = {}
|
|
8
|
+
|
|
9
|
+
optparse = OptionParser.new do |opts|
|
|
10
|
+
|
|
11
|
+
opts.banner = "Usage: iocparser -f IOC_FILE [...]\n" \
|
|
12
|
+
"Example: ioccmd -f myindicator.ioc -t Network\n"
|
|
13
|
+
opts.on('-h', '--help', 'Display this menu') do
|
|
14
|
+
puts opts
|
|
15
|
+
exit
|
|
16
|
+
end
|
|
17
|
+
opts.on('-f', '--f FILE', 'IOC XML File') do |f|
|
|
18
|
+
options[:file] = f
|
|
19
|
+
end
|
|
20
|
+
# options[:extract] = []
|
|
21
|
+
# opts.on('-e', '--extract [OBJECT,...]',Array, 'Extract OBJECT in plain text') do |f|
|
|
22
|
+
# options[:extract] = f
|
|
23
|
+
# end
|
|
24
|
+
opts.on('-t', '--type ATTRIBUTE', 'Extract TYPE of ATTRIBUTE') do |f|
|
|
25
|
+
options[:type] = f
|
|
26
|
+
end
|
|
27
|
+
opts.on('-v', '--value TYPE', 'Extract VALUE for TYPE of ATTRIBUTE') do |f|
|
|
28
|
+
options[:value] = f
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
optparse.parse!
|
|
33
|
+
|
|
34
|
+
if options[:file].nil?
|
|
35
|
+
puts "[-] Missing argument try `iocparser -h`"
|
|
36
|
+
exit
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
ioc = IOCParser.new("#{options[:file]}")
|
|
40
|
+
attribute = ioc.node_list
|
|
41
|
+
if !options[:file].nil? && options[:type].nil? && options[:value].nil?
|
|
42
|
+
puts "+++ IOC Items +++"
|
|
43
|
+
attribute.uniq.each do |item|
|
|
44
|
+
puts "#{item} => #{attribute.select {|a| a === "#{item}"}.count} "
|
|
45
|
+
end
|
|
46
|
+
puts "+++ END +++"
|
|
47
|
+
exit
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
if !options[:type].nil?
|
|
51
|
+
type = ioc.type(options[:type])
|
|
52
|
+
puts type
|
|
53
|
+
exit
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
if !options[:value].nil?
|
|
57
|
+
value = ioc.value(options[:value])
|
|
58
|
+
puts value
|
|
59
|
+
exit
|
|
60
|
+
end
|
data/iocparser.gemspec
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'iocparser/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "iocparser"
|
|
8
|
+
spec.version = Iocparser::VERSION
|
|
9
|
+
spec.authors = ["Matteo Michelini"]
|
|
10
|
+
spec.email = ["matteo.michelini@gmail.com"]
|
|
11
|
+
spec.description = %q{Command line utility to query Mandiant IOC files}
|
|
12
|
+
spec.summary = %q{Command line utility to query Mandiant IOC files}
|
|
13
|
+
spec.homepage = "https://github.com/cor3ngine/iocparser"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files`.split($/)
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
|
22
|
+
spec.add_development_dependency "rake"
|
|
23
|
+
end
|
data/lib/iocparser.rb
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require 'rexml/document'
|
|
4
|
+
include REXML
|
|
5
|
+
|
|
6
|
+
class IOCParser
|
|
7
|
+
attr_reader :node_list
|
|
8
|
+
|
|
9
|
+
def initialize(xmlfile)
|
|
10
|
+
@xmlioc = init_xml(xmlfile)
|
|
11
|
+
@node_list = nodes
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
public
|
|
15
|
+
def type(attribute)
|
|
16
|
+
arr_type = []
|
|
17
|
+
|
|
18
|
+
XPath.each(@xmlioc, "//Context[@document='#{attribute}']") do |item|
|
|
19
|
+
arr_type << item.attribute("search").value
|
|
20
|
+
end
|
|
21
|
+
return arr_type.uniq.sort
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def value(type)
|
|
25
|
+
arr_value = []
|
|
26
|
+
|
|
27
|
+
XPath.each(@xmlioc, "//Context[@search='#{type}']/ancestor::IndicatorItem") do |item|
|
|
28
|
+
value = item.attribute("id").value
|
|
29
|
+
arr_value << XPath.match(@xmlioc, "//IndicatorItem[@id='#{value}']/Content").map {|el| el.text}
|
|
30
|
+
end
|
|
31
|
+
return arr_value
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
private
|
|
35
|
+
def init_xml(file)
|
|
36
|
+
iocfile = File.new(file)
|
|
37
|
+
xmlfile = Document.new(iocfile)
|
|
38
|
+
return xmlfile
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def nodes
|
|
42
|
+
arr_node = []
|
|
43
|
+
|
|
44
|
+
XPath.each(@xmlioc, "//Context") do |item|
|
|
45
|
+
arr_node << item.attribute("document").value
|
|
46
|
+
end
|
|
47
|
+
return arr_node
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
metadata
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: iocparser
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Matteo Michelini
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-08-11 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: bundler
|
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
|
17
|
+
none: false
|
|
18
|
+
requirements:
|
|
19
|
+
- - ~>
|
|
20
|
+
- !ruby/object:Gem::Version
|
|
21
|
+
version: '1.3'
|
|
22
|
+
type: :development
|
|
23
|
+
prerelease: false
|
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
25
|
+
none: false
|
|
26
|
+
requirements:
|
|
27
|
+
- - ~>
|
|
28
|
+
- !ruby/object:Gem::Version
|
|
29
|
+
version: '1.3'
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rake
|
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
|
33
|
+
none: false
|
|
34
|
+
requirements:
|
|
35
|
+
- - ! '>='
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
type: :development
|
|
39
|
+
prerelease: false
|
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
description: Command line utility to query Mandiant IOC files
|
|
47
|
+
email:
|
|
48
|
+
- matteo.michelini@gmail.com
|
|
49
|
+
executables:
|
|
50
|
+
- iocparser
|
|
51
|
+
extensions: []
|
|
52
|
+
extra_rdoc_files: []
|
|
53
|
+
files:
|
|
54
|
+
- Gemfile
|
|
55
|
+
- LICENSE.txt
|
|
56
|
+
- README.md
|
|
57
|
+
- Rakefile
|
|
58
|
+
- bin/iocparser
|
|
59
|
+
- iocparser.gemspec
|
|
60
|
+
- lib/iocparser.rb
|
|
61
|
+
- lib/iocparser/iocparser.rb
|
|
62
|
+
- lib/iocparser/version.rb
|
|
63
|
+
homepage: https://github.com/cor3ngine/iocparser
|
|
64
|
+
licenses:
|
|
65
|
+
- MIT
|
|
66
|
+
post_install_message:
|
|
67
|
+
rdoc_options: []
|
|
68
|
+
require_paths:
|
|
69
|
+
- lib
|
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
71
|
+
none: false
|
|
72
|
+
requirements:
|
|
73
|
+
- - ! '>='
|
|
74
|
+
- !ruby/object:Gem::Version
|
|
75
|
+
version: '0'
|
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
|
+
none: false
|
|
78
|
+
requirements:
|
|
79
|
+
- - ! '>='
|
|
80
|
+
- !ruby/object:Gem::Version
|
|
81
|
+
version: '0'
|
|
82
|
+
requirements: []
|
|
83
|
+
rubyforge_project:
|
|
84
|
+
rubygems_version: 1.8.23
|
|
85
|
+
signing_key:
|
|
86
|
+
specification_version: 3
|
|
87
|
+
summary: Command line utility to query Mandiant IOC files
|
|
88
|
+
test_files: []
|