emonti-rbkb 0.6.2 → 0.6.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +23 -131
- data/bin/plugsrv +60 -27
- data/{usage.txt → cli_usage.rdoc} +20 -2
- data/lib/rbkb/cli/b64.rb +3 -0
- data/lib/rbkb/cli/bgrep.rb +3 -0
- data/lib/rbkb/cli/blit.rb +3 -0
- data/lib/rbkb/cli/chars.rb +3 -0
- data/lib/rbkb/cli/crc32.rb +3 -0
- data/lib/rbkb/cli/d64.rb +3 -0
- data/lib/rbkb/cli/dedump.rb +3 -0
- data/lib/rbkb/cli/hexify.rb +3 -2
- data/lib/rbkb/cli/len.rb +3 -0
- data/lib/rbkb/cli/rstrings.rb +3 -0
- data/lib/rbkb/cli/slice.rb +3 -0
- data/lib/rbkb/cli/telson.rb +4 -2
- data/lib/rbkb/cli/unhexify.rb +3 -2
- data/lib/rbkb/cli/urldec.rb +3 -0
- data/lib/rbkb/cli/urlenc.rb +3 -0
- data/lib/rbkb/cli/xor.rb +3 -0
- data/lib/rbkb/cli.rb +5 -0
- data/lib/rbkb/extends.rb +3 -1
- data/lib/rbkb/plug/blit.rb +3 -1
- data/lib/rbkb/plug/peer.rb +4 -0
- data/lib/rbkb/plug/plug.rb +3 -0
- data/lib/rbkb/plug/proxy.rb +3 -0
- data/lib/rbkb/plug.rb +3 -0
- data/lib_usage.rdoc +176 -0
- metadata +5 -3
data/README.rdoc
CHANGED
@@ -40,145 +40,36 @@ When I get some spare time, I'll try and do up some examples of using all
|
|
40
40
|
the tools.
|
41
41
|
|
42
42
|
|
43
|
-
===
|
44
|
-
|
45
|
-
Most of rbkb is implemented as a bunch of monkeypatches to Array, String,
|
46
|
-
Numeric and other base classes. If this suits your fancy (some people despise
|
47
|
-
monkeypatches, this is not their fancy) then you can 'require "rbkb"' from
|
48
|
-
your irb sessions and own scripts. This will let you do things like the
|
49
|
-
following (just some samples, see rdoc for more).
|
50
|
-
|
51
|
-
My dirty secret: I use IRB for like... everything
|
52
|
-
|
53
|
-
Do stuff with strings:
|
54
|
-
|
55
|
-
## sexify with hexify
|
56
|
-
foo = "helu foo" #=> "helu foo"
|
57
|
-
foo.hexify #=> "68656c7520666f6f"
|
58
|
-
|
59
|
-
## a little easier to read
|
60
|
-
foo.hexify(:delim => ' ') #=> "68 65 6c 75 20 66 6f 6f"
|
61
|
-
|
62
|
-
# and back
|
63
|
-
_.unhexify #=> "helu foo"
|
64
|
-
|
65
|
-
## break out your hexdump -C styles
|
66
|
-
foodump = "helu foo".hexdump(:out => StringIO.new)
|
67
|
-
#=> "00000000 68 65 6c 75 20 66 6f 6f |helu foo|\n00000008\n"
|
68
|
-
puts foodump
|
69
|
-
# 00000000 68 65 6c 75 20 66 6f 6f |helu foo|
|
70
|
-
# 00000008
|
71
|
-
# => nil
|
72
|
-
foo.hexdump(:out => $stdout)
|
73
|
-
# 00000000 68 65 6c 75 20 66 6f 6f |helu foo|
|
74
|
-
# 00000008
|
75
|
-
# => nil
|
76
|
-
|
77
|
-
## reverse a hexdump
|
78
|
-
foodump.dehexdump #=> "helu foo"
|
79
|
-
|
80
|
-
## 'strings' like /usr/bin/strings
|
81
|
-
dat = File.read("/bin/ls")
|
82
|
-
pp dat.strings
|
83
|
-
# [[4132, 4143, :ascii, "__PAGEZERO\000"],
|
84
|
-
# [4188, 4195, :ascii, "__TEXT\000"],
|
85
|
-
# ...
|
86
|
-
# [72427, 72470, :ascii, "*Apple Code Signing Certification Authority"],
|
87
|
-
# [72645, 72652, :ascii, "X[N~EQ "]]
|
88
|
-
|
89
|
-
|
90
|
-
## look for stuff in binaries
|
91
|
-
dat.bgrep("__PAGEZERO") #=> [[4132, 4142, "__PAGEZERO"], [40996, 41006, "__PAGEZERO"]]
|
92
|
-
dat.bgrep(0xCAFEBABE.to_bytes) #=> [[0, 4, "\312\376\272\276"]]
|
93
|
-
|
94
|
-
|
95
|
-
Do stuff with numbers:
|
96
|
-
|
97
|
-
## Do you have an irrational distaste for pack/unpack? I do.
|
98
|
-
0xff.to_bytes #=> "\000\000\000\377"
|
99
|
-
be = 0xff.to_bytes(:big) #=> "\000\000\000\377"
|
100
|
-
le = 0xff.to_bytes(:little) #=> "\377\000\000\000"
|
101
|
-
le16 = 0xff.to_bytes(:little,2) #=> "\377\000"
|
43
|
+
=== Plug
|
102
44
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
[be, le, le16].map {|n| n.dat_to_num(:little) }
|
107
|
-
#=> [4278190080, 255, 255]
|
45
|
+
Black Bag includes several tools for testing network protocols using plugboard
|
46
|
+
proxies. Users of the original Matasano BlackBag may be familiar with the
|
47
|
+
commands 'bkb replug', 'bkb telson', and 'bkb blit'.
|
108
48
|
|
109
|
-
|
110
|
-
10.pad(16) #=> 6
|
111
|
-
16.pad(16) #=> 0
|
112
|
-
30.pad(16) #=> 2
|
113
|
-
32.pad(16) #=> 0
|
49
|
+
Ruby BlackBag has a similar set of network tools:
|
114
50
|
|
51
|
+
* 'blit' : Uses a simple homegrown OOB IPC mechanism (local socket) to
|
52
|
+
communicate with 'blit-capable' tools like telson and plugsrv and send
|
53
|
+
data to network endpoints through them. Use 'blit' to send raw
|
54
|
+
messages to servers or clients then watch how they respond (see below).
|
115
55
|
|
116
|
-
|
56
|
+
* 'telson' : Similar to 'bkb telson'. Opens a TCP or UDP client connection
|
57
|
+
which is little more than a receiver for 'blit' messages. Use this to
|
58
|
+
pretend to be a client and send raw messages to some service while observing
|
59
|
+
raw replies.
|
117
60
|
|
118
|
-
|
61
|
+
* 'plugsrv' : Similar to 'bkb replug'. Sits as a reverse TCP proxy between
|
62
|
+
one or more clients and a server. Accepts 'blit' messages which can be
|
63
|
+
directed at client or server ends of a conversation. The original 'replug'
|
64
|
+
didn't do this, which makes plugsrv kindof neat.
|
119
65
|
|
120
|
-
# URL percent-encode stuff
|
121
|
-
xss.urlenc
|
122
|
-
#=> "%3cscript%3ealert%28%27helu%3a%20%27%20%2b%20document.cookie%29%3c%2fscript%3e"
|
123
66
|
|
124
|
-
|
125
|
-
#=> "JTNjc2NyaXB0JTNlYWxlcnQlMjglMjdoZWx1JTNhJTIwJTI3JTIwJTJiJTIwZG9jdW1lbnQuY29va2llJTI5JTNjJTJmc2NyaXB0JTNl"
|
126
|
-
|
127
|
-
## And back
|
128
|
-
_.d64
|
129
|
-
#=> "%3cscript%3ealert%28%27helu%3a%20%27%20%2b%20document.cookie%29%3c%2fscript%3e"
|
130
|
-
|
131
|
-
_.urldec
|
132
|
-
#=> "<script>alert('helu: ' + document.cookie)</script>"
|
133
|
-
|
134
|
-
|
135
|
-
Miscellaneous stuff:
|
136
|
-
|
137
|
-
# rediculous laziness!
|
138
|
-
0x41.printable? #=> true
|
139
|
-
0x01.printable? #=> false
|
140
|
-
|
141
|
-
# Make random gobbledygook and insults
|
142
|
-
"helu foo".randomize #=> "ouofleh "
|
143
|
-
"helu foo".randomize #=> "foul hoe"
|
144
|
-
|
145
|
-
|
146
|
-
Pretend (badly) to be smart:
|
147
|
-
|
148
|
-
# Cletus say's he's "sneaky"
|
149
|
-
cletus = "my secrets are safe".xor("sneaky")
|
150
|
-
#=> "\036\027E\022\016\032\001\v\021\022K\030\001\vE\022\n\037\026"
|
151
|
-
|
152
|
-
# Only not really so sneaky
|
153
|
-
cletus.xor "my secrets" #=> "sneakysnea&a!x qxzb"
|
154
|
-
cletus.xor "my secrets are" #=> "sneakysneakysn(k*ls"
|
155
|
-
cletus.xor "sneaky" #=> "my secrets are safe"
|
156
|
-
|
157
|
-
# Now make Cletus feel worse. With... MATH!
|
158
|
-
# (ala entropy scores)
|
159
|
-
"A".entropy #=> 0.0
|
160
|
-
"AB".entropy #=> 1.0
|
161
|
-
"BC".entropy #=> 1.0
|
162
|
-
(0..255).map {|x| x.chr}.join.entropy #=> 8.0
|
163
|
-
|
164
|
-
# "You see, Cletus, you might have done this..."
|
165
|
-
sdat = "my secrets are very secret "*60
|
166
|
-
require 'openssl'
|
167
|
-
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
168
|
-
c.encrypt
|
169
|
-
c.key = Digest::SHA1.hexdigest("sneaky")
|
170
|
-
c.iv = c.random_iv
|
67
|
+
=== Monkey Patches
|
171
68
|
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
#=> 3.77687372599433
|
177
|
-
sdat.entropy
|
178
|
-
#=> 3.07487577558377
|
179
|
-
|
180
|
-
I do recommend the rdoc if you're interested in more of these little helpers.
|
181
|
-
I'll to keep the comments useful and up to date.
|
69
|
+
Much of rbkb is implemented as a bunch of monkeypatches to Array, String,
|
70
|
+
Numeric and other base classes. If this suits your fancy (some people despise
|
71
|
+
monkeypatches, this is not their fancy) then you can 'require "rbkb"' from
|
72
|
+
your irb sessions and own scripts. See 'lib_fun.rdoc' for more info.
|
182
73
|
|
183
74
|
|
184
75
|
== REQUIREMENTS:
|
@@ -212,6 +103,7 @@ either add them to your PATH or copy/symlink them somewhere else like
|
|
212
103
|
|
213
104
|
gem contents emonti-rbkb
|
214
105
|
|
106
|
+
|
215
107
|
=== Manual installation:
|
216
108
|
|
217
109
|
... or ... you can also install manually without rubygems.
|
data/bin/plugsrv
CHANGED
@@ -1,18 +1,22 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
-
#
|
2
|
+
# Copyright 2009 emonti at matasano.com
|
3
|
+
# See README.rdoc for license information
|
3
4
|
#
|
5
|
+
# A blit-able reverse TCP proxy. Displays traffic hexdumps. Currently uses
|
6
|
+
# the default blit port for its blit receiver.
|
7
|
+
#
|
8
|
+
# XXX TODO - refactor me!
|
4
9
|
|
10
|
+
begin
|
11
|
+
require 'rubygems'
|
12
|
+
rescue LoadError
|
13
|
+
end
|
5
14
|
require 'eventmachine'
|
6
15
|
require 'socket'
|
7
16
|
require 'optparse'
|
8
|
-
require 'rbkb'
|
9
|
-
|
10
|
-
def bail(*msg)
|
11
|
-
STDERR.puts msg
|
12
|
-
exit 1
|
13
|
-
end
|
17
|
+
require 'rbkb/plug'
|
14
18
|
|
15
|
-
class
|
19
|
+
class BlitPlug
|
16
20
|
module UI
|
17
21
|
def log( *msg )
|
18
22
|
unless PLUG_OPTS[:quiet]
|
@@ -23,16 +27,24 @@ class PlugSrv
|
|
23
27
|
end
|
24
28
|
|
25
29
|
class Controller
|
26
|
-
attr_accessor :tgtaddr, :tgtport, :tgtclient
|
27
|
-
@@
|
30
|
+
attr_accessor :tgtaddr, :tgtport, :tgtclient, :blit, :peers
|
31
|
+
@@controller = nil
|
28
32
|
|
29
33
|
def initialize(tgtaddr, tgtport, tgtclient)
|
30
|
-
|
31
34
|
@tgtaddr = tgtaddr
|
32
35
|
@tgtport = tgtport
|
33
36
|
@tgtclient = tgtclient
|
34
37
|
|
35
|
-
@@
|
38
|
+
@@controller = self
|
39
|
+
|
40
|
+
@peers = Array.new
|
41
|
+
|
42
|
+
## Just tack on a blit server???
|
43
|
+
@blit = EventMachine::start_server(
|
44
|
+
Plug::Blit::DEFAULT_IPADDR, Plug::Blit::DEFAULT_PORT, Plug::Blit,
|
45
|
+
:TCP, self
|
46
|
+
)
|
47
|
+
|
36
48
|
end
|
37
49
|
|
38
50
|
##----------------------------------------
|
@@ -50,7 +62,7 @@ class PlugSrv
|
|
50
62
|
##----------------------------------------
|
51
63
|
|
52
64
|
def self.proxy(cli)
|
53
|
-
unless (ctrl = @@
|
65
|
+
unless (ctrl = @@controller)
|
54
66
|
raise "No controller exists for this connection: #{cli.sock_peername}"
|
55
67
|
end
|
56
68
|
|
@@ -62,9 +74,12 @@ class PlugSrv
|
|
62
74
|
srv.plug_peers.push cli
|
63
75
|
cli.plug_peers.push srv
|
64
76
|
|
77
|
+
ctrl.peers.push srv
|
78
|
+
ctrl.peers.push cli ### I suppose this is probably useful too..
|
79
|
+
|
65
80
|
srv.controller = cli.controller = ctrl
|
66
81
|
end
|
67
|
-
end # class
|
82
|
+
end # class BlitPlug::Controller
|
68
83
|
|
69
84
|
|
70
85
|
module BaseTCP
|
@@ -78,6 +93,14 @@ class PlugSrv
|
|
78
93
|
@kind = :conn # default
|
79
94
|
end
|
80
95
|
|
96
|
+
def name
|
97
|
+
@name
|
98
|
+
end
|
99
|
+
|
100
|
+
def say(data, sender)
|
101
|
+
log "%#{sender.kind.to_s.upcase}-SAYS", data.hexdump(:out => StringIO.new), "%"
|
102
|
+
send_data data
|
103
|
+
end
|
81
104
|
|
82
105
|
def receive_data data
|
83
106
|
log "%#{kind.to_s.upcase}-#{sock_peername}-SAYS", data.hexdump, "%"
|
@@ -89,12 +112,14 @@ class PlugSrv
|
|
89
112
|
|
90
113
|
|
91
114
|
def notify_connection
|
92
|
-
|
115
|
+
@name = "#{kind.to_s.upcase}-#{sock_peername}"
|
116
|
+
log "%#{@name}-CONNECTED"
|
93
117
|
end
|
94
118
|
|
95
119
|
|
96
120
|
def unbind
|
97
|
-
|
121
|
+
@name = "#{kind.to_s.upcase}-#{sock_peername}"
|
122
|
+
log "%#{@name}-CLOSED"
|
98
123
|
|
99
124
|
cret = (@controller and @controller.dispatch_close(self))
|
100
125
|
|
@@ -107,7 +132,7 @@ class PlugSrv
|
|
107
132
|
|
108
133
|
|
109
134
|
module TCPListener
|
110
|
-
include
|
135
|
+
include BlitPlug::BaseTCP
|
111
136
|
attr_accessor :tgtaddr, :tgtport
|
112
137
|
|
113
138
|
def post_init
|
@@ -116,7 +141,7 @@ class PlugSrv
|
|
116
141
|
@sock_peer = Socket.unpack_sockaddr_in(get_peername).reverse
|
117
142
|
@sock_peername = @sock_peer.join(':')
|
118
143
|
|
119
|
-
@controller =
|
144
|
+
@controller = BlitPlug::Controller.proxy(self)
|
120
145
|
|
121
146
|
notify_connection
|
122
147
|
end
|
@@ -125,7 +150,7 @@ class PlugSrv
|
|
125
150
|
|
126
151
|
|
127
152
|
module TCPClient
|
128
|
-
include
|
153
|
+
include BlitPlug::BaseTCP
|
129
154
|
attr_accessor :connected
|
130
155
|
|
131
156
|
def post_init
|
@@ -141,16 +166,22 @@ class PlugSrv
|
|
141
166
|
|
142
167
|
end # module TCPClient
|
143
168
|
|
144
|
-
end # module
|
169
|
+
end # module BlitPlug
|
145
170
|
|
146
171
|
PLUG_OPTS={ :quiet => false, :out => STDOUT }
|
147
172
|
|
173
|
+
def bail(*msg)
|
174
|
+
STDERR.puts msg
|
175
|
+
exit 1
|
176
|
+
end
|
177
|
+
|
178
|
+
|
148
179
|
|
149
180
|
#############################################################################
|
150
181
|
### MAIN
|
151
182
|
#############################################################################
|
152
183
|
#
|
153
|
-
# Get arguments
|
184
|
+
# Get option arguments
|
154
185
|
opts = OptionParser.new do |opts|
|
155
186
|
opts.banner = "Usage: #{$0} [options] target:tport[@[laddr:]lport]\n",
|
156
187
|
" <target:tport> = the address of the target service\n",
|
@@ -203,13 +234,15 @@ PLUG_OPTS[:svraddr] ||= (m[3] || "0.0.0.0")
|
|
203
234
|
PLUG_OPTS[:svrport] ||= (m[4] || PLUG_OPTS[:tgtport]).to_i
|
204
235
|
|
205
236
|
|
206
|
-
|
207
|
-
|
237
|
+
EventMachine::run {
|
238
|
+
# Instantiate controller
|
239
|
+
ctrl = BlitPlug::Controller.new(PLUG_OPTS[:tgtaddr], PLUG_OPTS[:tgtport], BlitPlug::TCPClient)
|
208
240
|
|
209
|
-
# Start event loop
|
210
|
-
|
241
|
+
# Start event loop
|
242
|
+
BlitPlug::UI.log "%Starting TCP PlugServer #{PLUG_OPTS[:svraddr]}:#{PLUG_OPTS[:svrport]} -> #{PLUG_OPTS[:tgtaddr]}:#{PLUG_OPTS[:tgtport]}"
|
211
243
|
|
212
|
-
|
213
|
-
EventMachine::start_server(PLUG_OPTS[:svraddr], PLUG_OPTS[:svrport],
|
244
|
+
|
245
|
+
EventMachine::start_server(PLUG_OPTS[:svraddr], PLUG_OPTS[:svrport], BlitPlug::TCPListener)
|
214
246
|
}
|
215
247
|
|
248
|
+
|
@@ -117,6 +117,23 @@ Takes input from a blob of data and output it with its binary length prepended.
|
|
117
117
|
-l, --length=LEN Ignore all else and use LEN
|
118
118
|
|
119
119
|
|
120
|
+
=== plugsrv
|
121
|
+
|
122
|
+
A blit-able reverse TCP proxy. Displays traffic hexdumps. Currently uses
|
123
|
+
the default blit port for its blit receiver.
|
124
|
+
|
125
|
+
Usage: /usr/bin/plugsrv [options] target:tport[@[laddr:]lport]
|
126
|
+
<target:tport> = the address of the target service
|
127
|
+
<@laddr:lport> = optional address and port to listen on
|
128
|
+
|
129
|
+
Options:
|
130
|
+
-o, --output FILE send output to a file
|
131
|
+
-l, --listen ADDR:PORT optional listener address:port
|
132
|
+
(default: 0.0.0.0:<tport>)
|
133
|
+
-q, --[no-]quiet Suppress/Enable conversation dumps.
|
134
|
+
-h, --help Show this message
|
135
|
+
|
136
|
+
|
120
137
|
=== rex
|
121
138
|
|
122
139
|
Lazy shortcut for ruby -e "..."
|
@@ -157,8 +174,9 @@ eventmachine.
|
|
157
174
|
|
158
175
|
Telson is for doing the following things with minimum fuss:
|
159
176
|
|
160
|
-
* Run as a
|
161
|
-
*
|
177
|
+
* Run as a stubbed network client using UDP or TCP
|
178
|
+
* Use blit to communicate with the other side.
|
179
|
+
* Debug network protocols
|
162
180
|
* Observe client/server behaviors using different messages at various phases
|
163
181
|
of a conversation.
|
164
182
|
|
data/lib/rbkb/cli/b64.rb
CHANGED
data/lib/rbkb/cli/bgrep.rb
CHANGED
data/lib/rbkb/cli/blit.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
require 'rbkb/plug'
|
3
3
|
|
4
|
+
# Copyright 2009 emonti at matasano.com
|
5
|
+
# See README.rdoc for license information
|
6
|
+
#
|
4
7
|
# blit is for use with any of the "plug" tools such as telson, feed, blitplug.
|
5
8
|
# It is used to send data over a socket via their OOB blit listener.
|
6
9
|
class Rbkb::Cli::Blit < Rbkb::Cli::Executable
|
data/lib/rbkb/cli/chars.rb
CHANGED
data/lib/rbkb/cli/crc32.rb
CHANGED
data/lib/rbkb/cli/d64.rb
CHANGED
data/lib/rbkb/cli/dedump.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
|
3
|
+
# Copyright 2009 emonti at matasano.com
|
4
|
+
# See README.rdoc for license information
|
5
|
+
#
|
3
6
|
# Reverses a hexdump back to raw data. Designed to work with hexdumps created
|
4
7
|
# by Unix utilities like 'xxd' as well as 'hexdump -C'.
|
5
8
|
class Rbkb::Cli::Dedump < Rbkb::Cli::Executable
|
data/lib/rbkb/cli/hexify.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'rbkb/cli'
|
4
2
|
|
3
|
+
# Copyright 2009 emonti at matasano.com
|
4
|
+
# See README.rdoc for license information
|
5
|
+
#
|
5
6
|
# The hexify command converts a string or raw data to hex characters.
|
6
7
|
# Input can be supplied via stdin, a string argument, or a file (with -f).
|
7
8
|
class Rbkb::Cli::Hexify < Rbkb::Cli::Executable
|
data/lib/rbkb/cli/len.rb
CHANGED
data/lib/rbkb/cli/rstrings.rb
CHANGED
data/lib/rbkb/cli/slice.rb
CHANGED
data/lib/rbkb/cli/telson.rb
CHANGED
@@ -2,12 +2,14 @@ require 'rbkb/cli'
|
|
2
2
|
require 'rbkb/plug'
|
3
3
|
require 'eventmachine'
|
4
4
|
|
5
|
-
|
5
|
+
# Copyright 2009 emonti at matasano.com
|
6
|
+
# See README.rdoc for license information
|
7
|
+
#
|
6
8
|
# This is an implementation of the original blackbag "telson" around
|
7
9
|
# ruby and eventmachine.
|
8
10
|
#
|
9
11
|
# Telson can do the following things with minimum fuss:
|
10
|
-
# - Run as a
|
12
|
+
# - Run as a "stubbed" network client using UDP or TCP
|
11
13
|
# - Debugging network protocols
|
12
14
|
# - Observe client/server behaviors using different messages at
|
13
15
|
# various phases of a conversation.
|
data/lib/rbkb/cli/unhexify.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
1
|
require 'rbkb/cli'
|
4
2
|
|
3
|
+
# Copyright 2009 emonti at matasano.com
|
4
|
+
# See README.rdoc for license information
|
5
|
+
#
|
5
6
|
# unhexify converts a string of hex bytes back to raw data. Input can be
|
6
7
|
# supplied via stdin, a hex-string argument, or a file containing hex (use -f).
|
7
8
|
class Rbkb::Cli::Unhexify < Rbkb::Cli::Executable
|
data/lib/rbkb/cli/urldec.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
|
3
|
+
# Copyright 2009 emonti at matasano.com
|
4
|
+
# See README.rdoc for license information
|
5
|
+
#
|
3
6
|
# urldec converts a url percent-encoded string back to its raw form.
|
4
7
|
# Input can be supplied via stdin, a string argument, or a file (with -f).
|
5
8
|
# (url percent-encoding is just fancy hex encoding)
|
data/lib/rbkb/cli/urlenc.rb
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
require 'rbkb/cli'
|
2
2
|
|
3
|
+
# Copyright 2009 emonti at matasano.com
|
4
|
+
# See README.rdoc for license information
|
5
|
+
#
|
3
6
|
# urlenc converts a string or raw data to a url percent-encoded string
|
4
7
|
# Input can be supplied via stdin, a string argument, or a file (with -f).
|
5
8
|
# (url percent-encoding is just fancy hex encoding)
|
data/lib/rbkb/cli/xor.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
require 'rbkb/cli'
|
3
3
|
|
4
|
+
# Copyright 2009 emonti at matasano.com
|
5
|
+
# See README.rdoc for license information
|
6
|
+
#
|
4
7
|
# Repeating string xor. Takes input from a string, stdin, or a file (-f).
|
5
8
|
class Rbkb::Cli::Xor < Rbkb::Cli::Executable
|
6
9
|
def make_parser()
|
data/lib/rbkb/cli.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
require 'rbkb'
|
2
2
|
require 'optparse'
|
3
3
|
|
4
|
+
# Copyright 2009 emonti at matasano.com
|
5
|
+
# See README.rdoc for license information
|
6
|
+
#
|
4
7
|
module Rbkb::Cli
|
5
8
|
# Rbkb::Cli::Executable is an abstract class for creating command line
|
6
9
|
# executables using the Ruby Black Bag framework.
|
@@ -11,6 +14,7 @@ module Rbkb::Cli
|
|
11
14
|
end
|
12
15
|
|
13
16
|
attr_accessor :stdout, :stderr, :stdin, :argv, :opts, :oparse
|
17
|
+
attr_reader :exit_status
|
14
18
|
|
15
19
|
# Instantiates a new Executable object.
|
16
20
|
#
|
@@ -39,6 +43,7 @@ module Rbkb::Cli
|
|
39
43
|
|
40
44
|
# Wrapper for Kernel.exit() so we can unit test cli tools
|
41
45
|
def exit(ret)
|
46
|
+
@exit_status = ret
|
42
47
|
if defined? Rbkb::Cli::TESTING
|
43
48
|
raise("Exited with return code: #{ret}") if ret != 0
|
44
49
|
else
|
data/lib/rbkb/extends.rb
CHANGED
data/lib/rbkb/plug/blit.rb
CHANGED
data/lib/rbkb/plug/peer.rb
CHANGED
data/lib/rbkb/plug/plug.rb
CHANGED
data/lib/rbkb/plug/proxy.rb
CHANGED
data/lib/rbkb/plug.rb
CHANGED
data/lib_usage.rdoc
ADDED
@@ -0,0 +1,176 @@
|
|
1
|
+
|
2
|
+
=== Using the rbkb library's Monkey Patches
|
3
|
+
|
4
|
+
Much of rbkb is implemented as a bunch of monkeypatches to Array, String,
|
5
|
+
Numeric and other base classes. If this suits your fancy (some people despise
|
6
|
+
monkeypatches, this is not their fancy) then you can 'require "rbkb"' from
|
7
|
+
your irb sessions and own scripts.
|
8
|
+
|
9
|
+
The monkey-patches were designed to let you approximate use of the rbkb shell
|
10
|
+
commands from IRB or ruby scripts.
|
11
|
+
|
12
|
+
(My dirty secret: I use IRB for like... everything!)
|
13
|
+
|
14
|
+
Using the rbkb library in ruby will let you do things like the following (just
|
15
|
+
some samples, see rdoc for more info).
|
16
|
+
|
17
|
+
|
18
|
+
Do stuff with strings:
|
19
|
+
|
20
|
+
## sexify with hexify
|
21
|
+
foo = "helu foo" #=> "helu foo"
|
22
|
+
foo.hexify #=> "68656c7520666f6f"
|
23
|
+
|
24
|
+
## a little easier to read
|
25
|
+
foo.hexify(:delim => ' ') #=> "68 65 6c 75 20 66 6f 6f"
|
26
|
+
|
27
|
+
# and back
|
28
|
+
_.unhexify #=> "helu foo"
|
29
|
+
|
30
|
+
## break out your hexdump -C styles
|
31
|
+
foodump = "helu foo".hexdump(:out => StringIO.new)
|
32
|
+
#=> "00000000 68 65 6c 75 20 66 6f 6f |helu foo|\n00000008\n"
|
33
|
+
puts foodump
|
34
|
+
# 00000000 68 65 6c 75 20 66 6f 6f |helu foo|
|
35
|
+
# 00000008
|
36
|
+
# => nil
|
37
|
+
foo.hexdump(:out => $stdout)
|
38
|
+
# 00000000 68 65 6c 75 20 66 6f 6f |helu foo|
|
39
|
+
# 00000008
|
40
|
+
# => nil
|
41
|
+
|
42
|
+
## reverse a hexdump
|
43
|
+
foodump.dehexdump #=> "helu foo"
|
44
|
+
|
45
|
+
## 'strings' like /usr/bin/strings
|
46
|
+
dat = File.read("/bin/ls")
|
47
|
+
pp dat.strings
|
48
|
+
# [[4132, 4143, :ascii, "__PAGEZERO\000"],
|
49
|
+
# [4188, 4195, :ascii, "__TEXT\000"],
|
50
|
+
# ...
|
51
|
+
# [72427, 72470, :ascii, "*Apple Code Signing Certification Authority"],
|
52
|
+
# [72645, 72652, :ascii, "X[N~EQ "]]
|
53
|
+
|
54
|
+
## look for stuff in binaries
|
55
|
+
dat.bgrep("__PAGEZERO") #=> [[4132, 4142, "__PAGEZERO"], [40996, 41006, "__PAGEZERO"]]
|
56
|
+
dat.bgrep(0xCAFEBABE.to_bytes) #=> [[0, 4, "\312\376\272\276"]]
|
57
|
+
|
58
|
+
|
59
|
+
Do stuff with numbers:
|
60
|
+
|
61
|
+
## Do you have an irrational distaste for pack/unpack? I do.
|
62
|
+
0xff.to_bytes #=> "\000\000\000\377"
|
63
|
+
be = 0xff.to_bytes(:big) #=> "\000\000\000\377"
|
64
|
+
le = 0xff.to_bytes(:little) #=> "\377\000\000\000"
|
65
|
+
le16 = 0xff.to_bytes(:little,2) #=> "\377\000"
|
66
|
+
|
67
|
+
## Strings can go the other way too
|
68
|
+
[be, le, le16].map {|n| n.dat_to_num(:big) } # default
|
69
|
+
#=> [255, 4278190080, 65280]
|
70
|
+
[be, le, le16].map {|n| n.dat_to_num(:little) }
|
71
|
+
#=> [4278190080, 255, 255]
|
72
|
+
|
73
|
+
## Calculate padding for a given alignment
|
74
|
+
10.pad(16) #=> 6
|
75
|
+
16.pad(16) #=> 0
|
76
|
+
30.pad(16) #=> 2
|
77
|
+
32.pad(16) #=> 0
|
78
|
+
|
79
|
+
|
80
|
+
Interact with 'telson' and 'plugsrv' directly from IRB:
|
81
|
+
|
82
|
+
## In a separate window from your irb session do something like:
|
83
|
+
#
|
84
|
+
# $ telson rubyforge.com:80 -r
|
85
|
+
# ** TELSON-192.168.11.2:58118(TCP) Started
|
86
|
+
# ** BLITSRV-127.0.0.1:25195(TCP) Started
|
87
|
+
# ** TELSON-192.168.11.2:58118(TCP) CONNECTED TO PEER-205.234.109.19:80(TCP)
|
88
|
+
|
89
|
+
## You can blit any string from within IRB!
|
90
|
+
|
91
|
+
## A minor setup step is required... (I put this in my .irbrc)
|
92
|
+
Plug::Blit.blit_init #=> nil
|
93
|
+
|
94
|
+
"GET / HTTP/1.0\r\n\r\n".blit #=> 28
|
95
|
+
## Watch the basic HTTP request get made and responded to in the
|
96
|
+
## other window.
|
97
|
+
|
98
|
+
("GET /"+ "A"*30 +" HTTP/1.0\r\n\r\n").blit #=> 58
|
99
|
+
## Watch the bogus HTTP request get made and responded to in the
|
100
|
+
## other window.
|
101
|
+
|
102
|
+
|
103
|
+
Some simple web encoding stuff:
|
104
|
+
|
105
|
+
xss="<script>alert('helu ' + document.cookie)</script"
|
106
|
+
|
107
|
+
# URL percent-encode stuff
|
108
|
+
xss.urlenc
|
109
|
+
#=> "%3cscript%3ealert%28%27helu%3a%20%27%20%2b%20document.cookie%29%3c%2fscript%3e"
|
110
|
+
|
111
|
+
# Base64 encode stuff
|
112
|
+
_.b64
|
113
|
+
#=> "JTNjc2NyaXB0JTNlYWxlcnQlMjglMjdoZWx1JTNhJTIwJTI3JTIwJTJiJTIwZG9jdW1lbnQuY29va2llJTI5JTNjJTJmc2NyaXB0JTNl"
|
114
|
+
|
115
|
+
## And back
|
116
|
+
_.d64
|
117
|
+
#=> "%3cscript%3ealert%28%27helu%3a%20%27%20%2b%20document.cookie%29%3c%2fscript%3e"
|
118
|
+
|
119
|
+
_.urldec
|
120
|
+
#=> "<script>alert('helu: ' + document.cookie)</script>"
|
121
|
+
|
122
|
+
|
123
|
+
Miscellaneous stuff:
|
124
|
+
|
125
|
+
# rediculous laziness!
|
126
|
+
0x41.printable? #=> true
|
127
|
+
0x01.printable? #=> false
|
128
|
+
|
129
|
+
# Make random gobbledygook and insults
|
130
|
+
"helu foo".randomize #=> "ouofleh "
|
131
|
+
"helu foo".randomize #=> "foul hoe"
|
132
|
+
|
133
|
+
|
134
|
+
Pretend (badly) to be smart:
|
135
|
+
|
136
|
+
# Cletus say's he's "sneaky"
|
137
|
+
cletus = "my secrets are safe".xor("sneaky")
|
138
|
+
#=> "\036\027E\022\016\032\001\v\021\022K\030\001\vE\022\n\037\026"
|
139
|
+
|
140
|
+
# Only not really so sneaky
|
141
|
+
cletus.xor "my secrets" #=> "sneakysnea&a!x qxzb"
|
142
|
+
cletus.xor "my secrets are" #=> "sneakysneakysn(k*ls"
|
143
|
+
cletus.xor "sneaky" #=> "my secrets are safe"
|
144
|
+
|
145
|
+
# Now make Cletus feel worse. With... MATH!
|
146
|
+
# (ala entropy scores)
|
147
|
+
"A".entropy #=> 0.0
|
148
|
+
"AB".entropy #=> 1.0
|
149
|
+
"BC".entropy #=> 1.0
|
150
|
+
(0..255).map {|x| x.chr}.join.entropy #=> 8.0
|
151
|
+
|
152
|
+
# "You see, Cletus, you might have done this..."
|
153
|
+
sdat = "my secrets are very secret "*60
|
154
|
+
require 'openssl'
|
155
|
+
c = OpenSSL::Cipher::Cipher.new("aes-256-cbc")
|
156
|
+
c.encrypt
|
157
|
+
c.key = Digest::SHA1.hexdigest("sneaky")
|
158
|
+
c.iv = c.random_iv
|
159
|
+
|
160
|
+
# "So, Cletus, when you say 'sneaky'... this is exactly how 'sneaky' you are"
|
161
|
+
c.update(sdat).entropy
|
162
|
+
#=> 7.64800383393901
|
163
|
+
sdat.xor("sneaky").entropy
|
164
|
+
#=> 3.77687372599433
|
165
|
+
sdat.entropy
|
166
|
+
#=> 3.07487577558377
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
I recommend reading some of the rdoc if you're interested in more of these
|
171
|
+
little helpers. Time permitting, I'll try to keep the docs useful and up
|
172
|
+
to date.
|
173
|
+
|
174
|
+
Comments are welcome.
|
175
|
+
|
176
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: emonti-rbkb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.2
|
4
|
+
version: 0.6.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Eric Monti
|
@@ -49,7 +49,8 @@ extra_rdoc_files: []
|
|
49
49
|
|
50
50
|
files:
|
51
51
|
- README.rdoc
|
52
|
-
-
|
52
|
+
- cli_usage.rdoc
|
53
|
+
- lib_usage.rdoc
|
53
54
|
- bin/b64
|
54
55
|
- bin/bgrep
|
55
56
|
- bin/blit
|
@@ -102,7 +103,8 @@ rdoc_options:
|
|
102
103
|
- README.rdoc
|
103
104
|
- --line-numbers
|
104
105
|
- README.rdoc
|
105
|
-
-
|
106
|
+
- cli_usage.rdoc
|
107
|
+
- lib_usage.rdoc
|
106
108
|
require_paths:
|
107
109
|
- lib
|
108
110
|
required_ruby_version: !ruby/object:Gem::Requirement
|