emonti-rbkb 0.6.1.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/README.rdoc +39 -0
- data/bin/b64 +57 -0
- data/bin/bgrep +91 -0
- data/bin/blit +97 -0
- data/bin/c +14 -0
- data/bin/crc32 +60 -0
- data/bin/d64 +41 -0
- data/bin/dedump +53 -0
- data/bin/hexify +85 -0
- data/bin/len +74 -0
- data/bin/rex +10 -0
- data/bin/rstrings +123 -0
- data/bin/slice +74 -0
- data/bin/telson +109 -0
- data/bin/unhexify +65 -0
- data/bin/urldec +56 -0
- data/bin/urlenc +55 -0
- data/bin/xor +60 -0
- data/lib/rbkb/command_line.rb +41 -0
- data/lib/rbkb/extends.rb +672 -0
- data/lib/rbkb/plug/blit.rb +220 -0
- data/lib/rbkb/plug/peer.rb +64 -0
- data/lib/rbkb/plug/plug.rb +195 -0
- data/lib/rbkb/plug.rb +6 -0
- data/lib/rbkb.rb +6 -0
- data/usage.txt +224 -0
- metadata +109 -0
data/README.rdoc
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
|
2
|
+
= Ruby BlackBag (rbkb)
|
3
|
+
|
4
|
+
A miscellaneous collection of command-line tools and ruby library helpers
|
5
|
+
related to pen-testing and reversing.
|
6
|
+
|
7
|
+
== Rationale
|
8
|
+
|
9
|
+
Disclaimer:
|
10
|
+
Most of what's in the black bag came from a desire to do less typing.
|
11
|
+
But there might be a few clever things that were added by accident.
|
12
|
+
|
13
|
+
|
14
|
+
RBkB is inspired by Matasano BlackBag (a set of similar tools written in C).
|
15
|
+
|
16
|
+
See:
|
17
|
+
* http://www.matasano.com/log/1048/blackbag-091-new-link-and-minor-fixes/
|
18
|
+
* http://www.matasano.com/log/552/code-release-blackbag-09-binary-protocol-reversing-unix-thingies/
|
19
|
+
|
20
|
+
Things go into the black bag as they are stolen (as a compliment!) or dreamed
|
21
|
+
up, usually based on simplifying some repetetive task or desire for a new tool.
|
22
|
+
|
23
|
+
|
24
|
+
Along the way, some of tools in the blackbag spirit make their way into 'rbkb'
|
25
|
+
that may or may not make it to 'bkb' right away (or ever). Similarly some of
|
26
|
+
the things in 'bkb' have not yet made it to 'rbkb' (and may not).
|
27
|
+
|
28
|
+
=== More Info
|
29
|
+
|
30
|
+
See usage.txt
|
31
|
+
|
32
|
+
=== Requirements
|
33
|
+
|
34
|
+
* For the plug based network stuff, you'll need EventMachine >= 0.12.0
|
35
|
+
|
36
|
+
$ gem install eventmachine
|
37
|
+
|
38
|
+
* Some of the plug stuff also requires ruby pcap available from: http://raa.ruby-lang.org/project/pcap
|
39
|
+
|
data/bin/b64
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Author Eric Monti emonti at matasano
|
3
|
+
#
|
4
|
+
# b64 converts strings or raw data to base-64 encoding.
|
5
|
+
#
|
6
|
+
# Usage: b64 -h
|
7
|
+
#
|
8
|
+
require 'rbkb'
|
9
|
+
require 'rbkb/command_line'
|
10
|
+
require 'base64'
|
11
|
+
|
12
|
+
include RBkB::CommandLine
|
13
|
+
|
14
|
+
#-------------------------------------------------------------------------------
|
15
|
+
# Init options and arg parsing
|
16
|
+
OPTS = {}
|
17
|
+
arg = bkb_stdargs(nil, OPTS)
|
18
|
+
arg = bkb_inputargs(arg, OPTS)
|
19
|
+
|
20
|
+
arg.banner += " <data | blank for stdin>"
|
21
|
+
|
22
|
+
#------------------------------------------------------------------------------
|
23
|
+
# Add local options
|
24
|
+
arg.separator ""
|
25
|
+
arg.separator " Output options:"
|
26
|
+
|
27
|
+
arg.on("-l", "--length LEN", Numeric,
|
28
|
+
"Encode in lines of LEN characters") do |l|
|
29
|
+
(OPTS[:len] = l) > 15 or raise "length must be at least 16"
|
30
|
+
end
|
31
|
+
|
32
|
+
#------------------------------------------------------------------------------
|
33
|
+
# Parse arguments
|
34
|
+
arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"
|
35
|
+
|
36
|
+
# default string arg
|
37
|
+
if OPTS[:indat].nil? and a=ARGV.shift
|
38
|
+
OPTS[:indat] = a.dup
|
39
|
+
end
|
40
|
+
|
41
|
+
# catchall
|
42
|
+
if ARGV.length != 0
|
43
|
+
bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
|
44
|
+
end
|
45
|
+
|
46
|
+
OPTS[:indat] ||= STDIN.read()
|
47
|
+
|
48
|
+
#------------------------------------------------------------------------------
|
49
|
+
# Do Stuff
|
50
|
+
|
51
|
+
if OPTS[:len]
|
52
|
+
Base64.b64encode(OPTS[:indat], OPTS[:len])
|
53
|
+
else
|
54
|
+
puts OPTS[:indat].b64
|
55
|
+
end
|
56
|
+
|
57
|
+
|
data/bin/bgrep
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# searches for a binary string in input
|
3
|
+
# string is provided 'hexified'
|
4
|
+
#
|
5
|
+
# usage: bgrep 'deadbeef' file
|
6
|
+
#
|
7
|
+
# use -h for more info
|
8
|
+
|
9
|
+
require 'rbkb'
|
10
|
+
require 'rbkb/command_line'
|
11
|
+
|
12
|
+
include RBkB::CommandLine
|
13
|
+
|
14
|
+
#-------------------------------------------------------------------------------
|
15
|
+
# Init options and arg parsing
|
16
|
+
OPTS = {
|
17
|
+
:start_off => 0,
|
18
|
+
:end_off => -1,
|
19
|
+
:align => nil
|
20
|
+
}
|
21
|
+
|
22
|
+
arg = bkb_stdargs(nil, OPTS)
|
23
|
+
|
24
|
+
arg.banner += " <subject> <file | blank for stdin>"
|
25
|
+
|
26
|
+
arg.on("-x", "--[no-]hex", "Specify subject as hex (default: false)") do |x|
|
27
|
+
OPTS[:hex] = x
|
28
|
+
end
|
29
|
+
|
30
|
+
arg.on("-r", "--[no-]regex", "Specify subject as regex (default: false)") do |r|
|
31
|
+
OPTS[:rx] = r
|
32
|
+
end
|
33
|
+
|
34
|
+
arg.on("-a", "--align=BYTES", Numeric,
|
35
|
+
"Only match on alignment boundary") do |a|
|
36
|
+
OPTS[:align] = a
|
37
|
+
end
|
38
|
+
|
39
|
+
arg.on("-n", "--[no-]filename", "Suppress prefixing of filenames.") do |n|
|
40
|
+
OPTS[:suppress_fname] = n
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#------------------------------------------------------------------------------
|
45
|
+
# Parse arguments
|
46
|
+
begin
|
47
|
+
arg.parse!
|
48
|
+
|
49
|
+
unless find = ARGV.shift
|
50
|
+
raise "need subject argument"
|
51
|
+
end
|
52
|
+
|
53
|
+
if OPTS[:hex] and OPTS[:rx]
|
54
|
+
raise "-r and -x are mutually exclusive"
|
55
|
+
end
|
56
|
+
|
57
|
+
if OPTS[:hex]
|
58
|
+
raise "you specified -x for hex and the subject isn't" unless find.ishex?
|
59
|
+
find = find.unhexify
|
60
|
+
elsif OPTS[:rx]
|
61
|
+
find = Regexp.new(find, Regexp::MULTILINE)
|
62
|
+
end
|
63
|
+
|
64
|
+
align = OPTS[:align]
|
65
|
+
|
66
|
+
if fname=ARGV.shift
|
67
|
+
dat = File.read(fname)
|
68
|
+
fname = nil unless ARGV[0] # only print filename for multiple files
|
69
|
+
else
|
70
|
+
fname = nil
|
71
|
+
dat = STDIN.read
|
72
|
+
end
|
73
|
+
|
74
|
+
loop do
|
75
|
+
dat.bgrep(find, align) do |hit_start, hit_end, match|
|
76
|
+
print "#{fname}:" if fname and not OPTS[:suppress_fname]
|
77
|
+
|
78
|
+
puts("#{(hit_start).to_hex.rjust(8,"0")}:"+
|
79
|
+
"#{(hit_end).to_hex.rjust(8,"0")}:b:"+
|
80
|
+
"#{match.inspect}")
|
81
|
+
end
|
82
|
+
|
83
|
+
break unless fname=ARGV.shift
|
84
|
+
dat = File.read(fname)
|
85
|
+
end
|
86
|
+
|
87
|
+
rescue
|
88
|
+
STDERR.puts $!, " use -h for help"
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
data/bin/blit
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# blit is for use with any of the "plug" tools such as telson, feed, blitplug.
|
4
|
+
# It is used to send data over a socket via their OOB blit listener.
|
5
|
+
#
|
6
|
+
# Usage: blit [options] <data | blank for stdin>
|
7
|
+
# -h, --help Show this message
|
8
|
+
# -v, --version Show version and exit
|
9
|
+
# -f, --file FILENAME Input from FILENAME
|
10
|
+
# -t, --trans-protocol=PROTO Blit transport protocol TCP/UDP
|
11
|
+
# -b, --blitsrv=ADDR:PORT Where to send blit messages
|
12
|
+
# -i, --peer-index=IDX Index for remote peer to receive
|
13
|
+
# -l, --list-peers Lists the peer array for the target
|
14
|
+
# -k, --kill Stops the remote event loop.
|
15
|
+
#
|
16
|
+
|
17
|
+
require 'rbkb'
|
18
|
+
require 'rbkb/plug'
|
19
|
+
require 'rbkb/command_line.rb'
|
20
|
+
|
21
|
+
require 'socket'
|
22
|
+
|
23
|
+
include RBkB::CommandLine
|
24
|
+
|
25
|
+
#------------------------------------------------------------------------------
|
26
|
+
# Init options and arg parsing
|
27
|
+
|
28
|
+
OPTS = {
|
29
|
+
:b_addr => Plug::Blit::DEFAULT_IPADDR,
|
30
|
+
:b_port => Plug::Blit::DEFAULT_PORT,
|
31
|
+
:bp_proto => :TCP,
|
32
|
+
:b_peeridx => 0,
|
33
|
+
}
|
34
|
+
|
35
|
+
blit_msg = nil
|
36
|
+
|
37
|
+
arg = bkb_stdargs(nil, OPTS)
|
38
|
+
arg = bkb_inputargs(arg, OPTS)
|
39
|
+
|
40
|
+
arg.banner += " <data | blank for stdin>"
|
41
|
+
|
42
|
+
|
43
|
+
#------------------------------------------------------------------------------
|
44
|
+
# Add local options here
|
45
|
+
|
46
|
+
arg.on("-t", "--trans-protocol=PROTO", "Blit transport protocol TCP/UDP") do |t|
|
47
|
+
OPTS[:b_proto] = t.upcase.to_sym
|
48
|
+
end
|
49
|
+
|
50
|
+
arg.on("-b", "--blitsrv=ADDR:PORT", "Where to send blit messages") do |b|
|
51
|
+
unless(m=/^(?:([\w\.]+):)?(\d+)$/.match(b))
|
52
|
+
bail "invalid blit address/port"
|
53
|
+
end
|
54
|
+
OPTS[:b_port] = m[2].to_i
|
55
|
+
OPTS[:b_port] = m[1] if m[1]
|
56
|
+
end
|
57
|
+
|
58
|
+
arg.on("-i", "--peer-index=IDX", Numeric, "Index for remote peer to receive") do |i|
|
59
|
+
OPTS[:b_peeridx] = i
|
60
|
+
end
|
61
|
+
|
62
|
+
arg.on("-l", "--list-peers", "Lists the peer array for the target") do
|
63
|
+
blit_msg = Plug::Blit.make_list_peers
|
64
|
+
end
|
65
|
+
|
66
|
+
arg.on("-k", "--kill", "Stops the remote event loop.") do
|
67
|
+
blit_msg = Plug::Blit.make_kill
|
68
|
+
end
|
69
|
+
|
70
|
+
#------------------------------------------------------------------------------
|
71
|
+
# Parse arguments
|
72
|
+
arg.parse!(ARGV) rescue bail "Error: #{$!}\nUse -h|--help for more info."
|
73
|
+
|
74
|
+
unless blit_msg
|
75
|
+
if OPTS[:indat].nil?
|
76
|
+
OPTS[:indat] = (ARGV.length > 0)? ARGV.join(" ") : STDIN.read()
|
77
|
+
end
|
78
|
+
blit_msg = Plug::Blit.make_sendmsg(OPTS[:b_peeridx], OPTS[:indat])
|
79
|
+
end
|
80
|
+
|
81
|
+
#------------------------------------------------------------------------------
|
82
|
+
# Do stuff
|
83
|
+
|
84
|
+
begin
|
85
|
+
Plug::Blit.blit_init(
|
86
|
+
:addr => OPTS[:b_addr],
|
87
|
+
:port => OPTS[:b_port],
|
88
|
+
:protocol => OPTS[:b_proto]
|
89
|
+
)
|
90
|
+
|
91
|
+
Plug::Blit.blit_raw(blit_msg)
|
92
|
+
|
93
|
+
rescue
|
94
|
+
bail $!
|
95
|
+
exit 1
|
96
|
+
end
|
97
|
+
|
data/bin/c
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Author Eric Monti (emonti at matasano)
|
3
|
+
|
4
|
+
require 'rbkb'
|
5
|
+
require 'rbkb/command_line'
|
6
|
+
|
7
|
+
include RBkB::CommandLine
|
8
|
+
|
9
|
+
if ARGV[0] !~ /[1-9][0-9]*/ or ARGV[1].nil? or ARGV.size > 2
|
10
|
+
bail "Usage: #{$0} 100 A; # print 100 A's'\n"
|
11
|
+
end
|
12
|
+
|
13
|
+
print ARGV[1] * ARGV[0].to_i
|
14
|
+
|
data/bin/crc32
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# (emonti at matasano) Matasano Security LLC
|
3
|
+
#
|
4
|
+
# crc32.rb : returns a crc32 checksum in hex from stdin or a file
|
5
|
+
#
|
6
|
+
# Usage: crc32 [options]
|
7
|
+
# -h, --help Show this message
|
8
|
+
# -v, --version Show version and exit
|
9
|
+
# -f, --file FILENAME Input from FILENAME
|
10
|
+
# -r, --range=START[:END] Start and optional end range
|
11
|
+
# -x, --hexrange=START[:END] same, but in hex
|
12
|
+
|
13
|
+
require 'rbkb'
|
14
|
+
require 'rbkb/command_line'
|
15
|
+
|
16
|
+
include RBkB::CommandLine
|
17
|
+
|
18
|
+
OPTS = {:first => 0, :last => -1}
|
19
|
+
arg = bkb_stdargs(nil, OPTS)
|
20
|
+
arg = bkb_inputargs(arg, OPTS)
|
21
|
+
|
22
|
+
arg.on("-r", "--range=START[:END]", "Start and optional end range") do |r|
|
23
|
+
|
24
|
+
raise "-x and -r are mutually exclusive" if OPTS[:first]
|
25
|
+
|
26
|
+
unless m=/^(-?[0-9]+)(?::(-?[0-9]+))?$/.match(r)
|
27
|
+
raise "invalid range #{r.inspect}"
|
28
|
+
end
|
29
|
+
|
30
|
+
OPTS[:first] = $1.to_i
|
31
|
+
OPTS[:last] = $2.to_i if $2
|
32
|
+
end
|
33
|
+
|
34
|
+
arg.on("-x", "--hexrange=START[:END]", "same, but in hex") do |r|
|
35
|
+
|
36
|
+
raise "-x and -r are mutually exclusive" if OPTS[:first]
|
37
|
+
|
38
|
+
unless m=/^(-?[0-9a-f]+)(?::(-?[0-9a-f]+))?$/i.match(r)
|
39
|
+
raise "invalid range #{r.inspect}"
|
40
|
+
end
|
41
|
+
|
42
|
+
OPTS[:first]=($1[0,1] == '-')? ($1[1..-1]).hex_to_num * -1 : $1.hex_to_num
|
43
|
+
if $2
|
44
|
+
OPTS[:last]=($2[0,1] == '-')? ($2[1..-1]).hex_to_num * -1 : $2.hex_to_num
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
begin
|
49
|
+
arg.parse!
|
50
|
+
|
51
|
+
raise "bad arguments #{ARGV.join(" ").inspect}" unless (ARGV.length == 0)
|
52
|
+
|
53
|
+
OPTS[:indat] ||= STDIN.read()
|
54
|
+
|
55
|
+
puts OPTS[:indat][ OPTS[:first] .. OPTS[:last] ].crc32.to_hex
|
56
|
+
|
57
|
+
rescue
|
58
|
+
bail "Error: #{$!}\n#{arg}"
|
59
|
+
end
|
60
|
+
|
data/bin/d64
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Author Eric Monti (emonti at matasano)
|
3
|
+
#
|
4
|
+
# d64 converts a base-64 encoded string back to its orginal form.
|
5
|
+
#
|
6
|
+
# Usage: d64 -h
|
7
|
+
#
|
8
|
+
require 'rbkb'
|
9
|
+
require 'rbkb/command_line'
|
10
|
+
|
11
|
+
include RBkB::CommandLine
|
12
|
+
|
13
|
+
#-------------------------------------------------------------------------------
|
14
|
+
# Init options and arg parsing
|
15
|
+
OPTS = {}
|
16
|
+
arg = bkb_stdargs(nil, OPTS)
|
17
|
+
arg = bkb_inputargs(arg, OPTS)
|
18
|
+
|
19
|
+
arg.banner += " <data | blank for stdin>"
|
20
|
+
|
21
|
+
#------------------------------------------------------------------------------
|
22
|
+
# Parse arguments
|
23
|
+
arg.parse!(ARGV) rescue bail "Error: #{$!}\n#{arg}"
|
24
|
+
|
25
|
+
# default string arg
|
26
|
+
if OPTS[:indat].nil? and a=ARGV.shift
|
27
|
+
OPTS[:indat] = a.dup
|
28
|
+
end
|
29
|
+
|
30
|
+
# catchall
|
31
|
+
if ARGV.length != 0
|
32
|
+
bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
|
33
|
+
end
|
34
|
+
|
35
|
+
OPTS[:indat] ||= STDIN.read()
|
36
|
+
|
37
|
+
#------------------------------------------------------------------------------
|
38
|
+
# Do Stuff
|
39
|
+
|
40
|
+
print OPTS[:indat].d64
|
41
|
+
|
data/bin/dedump
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Author Eric Monti (emonti at matasano)
|
3
|
+
#
|
4
|
+
# Reverses a hexdump back to raw data. Designed to work with hexdumps created
|
5
|
+
# by Unix utilities like 'xxd' as well as 'hexdump -C'.
|
6
|
+
|
7
|
+
require 'rbkb'
|
8
|
+
require 'rbkb/command_line'
|
9
|
+
|
10
|
+
include RBkB::CommandLine
|
11
|
+
|
12
|
+
#------------------------------------------------------------------------------
|
13
|
+
# Init options and arg parsing
|
14
|
+
OPTS = {:len => 16}
|
15
|
+
arg = bkb_stdargs(nil, OPTS)
|
16
|
+
|
17
|
+
arg.banner += " <input-file | blank for stdin>"
|
18
|
+
|
19
|
+
#------------------------------------------------------------------------------
|
20
|
+
# Add local options
|
21
|
+
|
22
|
+
arg.on("-l", "--length LEN", Numeric,
|
23
|
+
"Bytes per line in hexdump (default: #{OPTS[:len]})") do |l|
|
24
|
+
bail("Length must be greater than zero") unless (OPTS[:len] = l) > 0
|
25
|
+
end
|
26
|
+
|
27
|
+
#------------------------------------------------------------------------------
|
28
|
+
# Parse arguments
|
29
|
+
arg.parse!(ARGV) rescue bail "Error: #{$!}\nUse -h|--help for more info."
|
30
|
+
|
31
|
+
if OPTS[:indat].nil? and a=ARGV.shift
|
32
|
+
OPTS[:indat] = File.open(a, "rb") rescue "Error: Can't open file '#{a}'"
|
33
|
+
end
|
34
|
+
|
35
|
+
# catchall
|
36
|
+
if ARGV.length != 0
|
37
|
+
bail "Error: bad arguments - #{ARGV.join(' ')}\n-h|--help for more info."
|
38
|
+
end
|
39
|
+
|
40
|
+
# Default to standard input
|
41
|
+
OPTS[:indat] ||= STDIN.read()
|
42
|
+
|
43
|
+
#------------------------------------------------------------------------------
|
44
|
+
# Do stuff
|
45
|
+
|
46
|
+
exit 1 unless((OPTS[:len] ||= OPTS[:indat].length) > 0)
|
47
|
+
|
48
|
+
OPTS[:indat].dehexdump(
|
49
|
+
:len => OPTS[:len],
|
50
|
+
:out => STDOUT
|
51
|
+
) rescue bail "Error: #{$!}"
|
52
|
+
|
53
|
+
|