pentex 0.1.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.
- data/lib/README.txt +2 -0
- data/lib/irb/irbrc.rb +38 -0
- data/lib/pentex.rb +1 -0
- data/lib/pentex/core.rb +221 -0
- metadata +59 -0
data/lib/README.txt
ADDED
data/lib/irb/irbrc.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
#
|
2
|
+
# I R B - Limit Return Values
|
3
|
+
# http://www.ruby-forum.com/topic/107929
|
4
|
+
# Note: This solution is more complicated than just using conf.return_format but the output is nicer,
|
5
|
+
# because you know if it has been truncated or not.
|
6
|
+
|
7
|
+
#:nodoc:
|
8
|
+
|
9
|
+
IRB.conf[:PROMPT_MODE] = :SIMPLE
|
10
|
+
IRB.conf[:MAX_OUTPUT_SIZE] = 100
|
11
|
+
|
12
|
+
class IRB::Context
|
13
|
+
attr_accessor :max_output_size
|
14
|
+
|
15
|
+
alias initialize_before_max_output_size initialize
|
16
|
+
def initialize(*args)
|
17
|
+
initialize_before_max_output_size(*args)
|
18
|
+
@max_output_size = (IRB.conf[:MAX_OUTPUT_SIZE] ? IRB.conf[:MAX_OUTPUT_SIZE] : 500)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
#:nodoc:
|
23
|
+
class IRB::Irb
|
24
|
+
def output_value
|
25
|
+
text =
|
26
|
+
if @context.inspect?
|
27
|
+
sprintf @context.return_format, @context.last_value.inspect
|
28
|
+
else
|
29
|
+
sprintf @context.return_format, @context.last_value
|
30
|
+
end
|
31
|
+
max = @context.max_output_size
|
32
|
+
if text.size < max
|
33
|
+
puts text
|
34
|
+
else
|
35
|
+
puts text[0..@context.max_output_size-1] + " ..." + text[-2..-1]
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/lib/pentex.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'pentex/core'
|
data/lib/pentex/core.rb
ADDED
@@ -0,0 +1,221 @@
|
|
1
|
+
# :title: IRB Hacking Extensions
|
2
|
+
# Author:: Andreas Schmidt
|
3
|
+
|
4
|
+
# Version: 0.3
|
5
|
+
# Date:
|
6
|
+
#
|
7
|
+
# * added decode_hex
|
8
|
+
# - - -
|
9
|
+
# Version: 0.2
|
10
|
+
# Date:
|
11
|
+
#
|
12
|
+
# * added to_hex
|
13
|
+
# - - -
|
14
|
+
# Version: 0.1 (First Shot)
|
15
|
+
# Date: 29.02.2012
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
puts "== HACKING EXTENSIONS =="
|
20
|
+
puts ">> loading additional libs "
|
21
|
+
[ 'irb/completion', 'yaml', 'base64', 'digest/md5', 'digest/sha1', 'zlib', 'cgi', 'uri', 'awesome_print' ].each do |lib|
|
22
|
+
begin
|
23
|
+
require lib
|
24
|
+
print "."
|
25
|
+
rescue LoadError => bang
|
26
|
+
puts "Could not load #{lib}, you may fix it by installing the gem."
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
puts
|
31
|
+
puts ">> monkey patching ..."
|
32
|
+
|
33
|
+
# ==Hacking Extensions For The String Class
|
34
|
+
class String
|
35
|
+
def to_md5(format = :hex)
|
36
|
+
Digest::MD5.hexdigest(self)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_sha1(format = :hex)
|
40
|
+
Digest::SHA1.hexdigest(self)
|
41
|
+
end
|
42
|
+
|
43
|
+
def decode_b64
|
44
|
+
Base64.decode64(self)
|
45
|
+
end
|
46
|
+
|
47
|
+
def encode_b64
|
48
|
+
Base64.encode64(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def decode_url
|
52
|
+
CGI.unescape(self)
|
53
|
+
end
|
54
|
+
|
55
|
+
def encode_url
|
56
|
+
CGI.escape(self)
|
57
|
+
end
|
58
|
+
|
59
|
+
def encode_uri
|
60
|
+
URI.escape(self)
|
61
|
+
end
|
62
|
+
|
63
|
+
def decode_uri
|
64
|
+
URI.unescape(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def decode_hex
|
68
|
+
# first normalize hex-string
|
69
|
+
s = self.gsub(/\\x/,'')
|
70
|
+
s.gsub!(/0x/,'')
|
71
|
+
s.gsub!(/\W/,'')
|
72
|
+
r = ''
|
73
|
+
0.step(s.length-1,2) do |x|
|
74
|
+
r << s.slice(x,2).hex.chr
|
75
|
+
end
|
76
|
+
r
|
77
|
+
end
|
78
|
+
|
79
|
+
# converts string to hex format
|
80
|
+
# <br>
|
81
|
+
# style: let's you choose between different formats
|
82
|
+
# :plain (default) -> "61624358"
|
83
|
+
# :c (c++ style) -> "\\x61\\x62\\x43\\x58"
|
84
|
+
# :r (ruby style) -> "\\x61\\x62\\x43\\x58"
|
85
|
+
# <br><br>
|
86
|
+
# Example:
|
87
|
+
# >> "abCX".to_hex :c
|
88
|
+
# => "\\x61\\x62\\x43\\x58"
|
89
|
+
|
90
|
+
def to_hex( style = :plain )
|
91
|
+
x = self.unpack("H*")[0]
|
92
|
+
h = case style.to_s
|
93
|
+
when /plain/i
|
94
|
+
x
|
95
|
+
when /^c/i
|
96
|
+
x.gsub(/(..)/,'\x\1')
|
97
|
+
when /^r/i
|
98
|
+
x.gsub(/(..)/,'\x\1')
|
99
|
+
end
|
100
|
+
h
|
101
|
+
end
|
102
|
+
|
103
|
+
# decodes cisco 7 passwords which can be found in IOS/CatOS configs.
|
104
|
+
# <br>
|
105
|
+
# e.g., password 7 07362E590E1B1C041B1E124C0A2F2E206832752E1A01134D
|
106
|
+
def decode_cisco7
|
107
|
+
|
108
|
+
xlat = %w( 64 73 66 64 3b 6b 66 6f 41 2c 2e 69 79 65 77 72 6b 6c 64 4a 4b 44 48 53 55 42 73 67 76 63 )
|
109
|
+
|
110
|
+
ep = self.strip
|
111
|
+
# sample: "07362E590E1B1C041B1E124C0A2F2E206832752E1A01134D" # -> "You really need a life."
|
112
|
+
dp = ""
|
113
|
+
if ep =~ /^(..)(.*)/o
|
114
|
+
s = $1.to_i
|
115
|
+
e = $2
|
116
|
+
i = 0
|
117
|
+
0.step(e.length-1, 2) do |x|
|
118
|
+
dp += ( e.slice(x,2).hex ^ xlat[s].hex ).chr;
|
119
|
+
s+=1
|
120
|
+
break if s >= xlat.length
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
dp
|
125
|
+
end
|
126
|
+
|
127
|
+
# shows (binary) string in a readable format.
|
128
|
+
# <br>
|
129
|
+
# <b>Options:</b>
|
130
|
+
# :bytes => 16; the maximum number of bytes per line
|
131
|
+
# :offset => 0; not supported yet
|
132
|
+
# :max_bytes => 0; the max number of bytes to be processed
|
133
|
+
# :chunksize => 8; splitted by "-"
|
134
|
+
# :range => nil; use this to define the range to be displayes, e.g. "(10..20)" must be a Range-Object!
|
135
|
+
# :format => :simple; this is the only format supported yet
|
136
|
+
# :max_lines => 40; number of lines before stopping output
|
137
|
+
# <br><br>
|
138
|
+
# <b>Example 1:</b>
|
139
|
+
# >> "\x02:this is a string with some binary data\xff".hexdump
|
140
|
+
# 000000: 02 3A 74 68 69 73 20 69 - 73 20 61 20 73 74 72 69 :.:this is a stri
|
141
|
+
# 000010: 6E 67 20 77 69 74 68 20 - 73 6F 6D 65 20 62 69 6E :ng with some bin
|
142
|
+
# 000020: 61 72 79 20 64 61 74 61 - FF :ary data.
|
143
|
+
# => true
|
144
|
+
# <br><br>
|
145
|
+
# <b>Example 2:</b> giving a range with int and hex value calculation
|
146
|
+
# "\x02:this is a string with some binary data\xff".hexdump :range => (16...0x10+0x10)
|
147
|
+
# 000010: 6E 67 20 77 69 74 68 20 - 73 6F 6D 65 20 62 69 :ng with some bi
|
148
|
+
# => true
|
149
|
+
|
150
|
+
def hexdump( opts = {} )
|
151
|
+
copts = {
|
152
|
+
:bytes => 16,
|
153
|
+
:offset => 0,
|
154
|
+
:max_bytes => 0,
|
155
|
+
:chunksize => 8,
|
156
|
+
:range => nil,
|
157
|
+
:format => :simple,
|
158
|
+
:max_lines => 40
|
159
|
+
}
|
160
|
+
# lame kind of implementing a command help, anyway better than opening source file ;)
|
161
|
+
unless opts.is_a? Hash
|
162
|
+
puts "[options]"
|
163
|
+
puts copts.to_yaml
|
164
|
+
puts
|
165
|
+
puts "[example]\n>>'this is a string'.hexdump :max_bytes => 8"
|
166
|
+
puts
|
167
|
+
return true
|
168
|
+
end
|
169
|
+
|
170
|
+
copts.update opts
|
171
|
+
|
172
|
+
dump = ""
|
173
|
+
offset = 0
|
174
|
+
linecount = 0
|
175
|
+
max_bytes = copts[:max_bytes] > 0 ? copts[:max_bytes] : self.length
|
176
|
+
if copts[:range].is_a? Range
|
177
|
+
offset = copts[:range].min
|
178
|
+
max_bytes = copts[:range].max
|
179
|
+
end
|
180
|
+
|
181
|
+
counter = offset
|
182
|
+
|
183
|
+
while counter < max_bytes
|
184
|
+
|
185
|
+
pos = sprintf("%06X", counter)
|
186
|
+
|
187
|
+
linelen = (counter < max_bytes - copts[:bytes] ) ? copts[:bytes] : (max_bytes - counter)
|
188
|
+
bytes = ""
|
189
|
+
linelen.times do |i|
|
190
|
+
bytes << "%02X" % self[counter + i].ord
|
191
|
+
bytes << " " unless (i+1) % copts[:bytes] == 0
|
192
|
+
bytes << "- " if ( i+1) % copts[:chunksize] == 0 && (i+1) < linelen
|
193
|
+
end
|
194
|
+
|
195
|
+
maxlen = ( copts[:bytes] * 2 + copts[:bytes] - 1 + copts[:bytes] / copts[:chunksize] )
|
196
|
+
bytes << " " * (maxlen - bytes.length) if maxlen > bytes.length
|
197
|
+
ascii = self[counter, linelen].printable
|
198
|
+
line = "#{pos}: #{bytes} :#{ascii}\n"
|
199
|
+
puts line
|
200
|
+
linecount += 1
|
201
|
+
if linecount >= copts[:max_lines]
|
202
|
+
puts "<Enter>, [qQ]uit"
|
203
|
+
c = gets
|
204
|
+
return false if c =~ /^q/i
|
205
|
+
linecount = 0
|
206
|
+
end
|
207
|
+
dump << line
|
208
|
+
counter += copts[:bytes]
|
209
|
+
end
|
210
|
+
|
211
|
+
return dump unless copts[:format] == :simple
|
212
|
+
|
213
|
+
return true
|
214
|
+
end
|
215
|
+
|
216
|
+
def printable( non_print_char = "." )
|
217
|
+
x = self.gsub(/[^[:print:]]/, non_print_char )
|
218
|
+
end
|
219
|
+
|
220
|
+
end
|
221
|
+
|
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pentex
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Andreas Schmidt
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-02 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: awesome_print
|
16
|
+
requirement: &28640940 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *28640940
|
25
|
+
description: blablabla
|
26
|
+
email: watobo@siberas.de
|
27
|
+
executables: []
|
28
|
+
extensions: []
|
29
|
+
extra_rdoc_files: []
|
30
|
+
files:
|
31
|
+
- lib/irb/irbrc.rb
|
32
|
+
- lib/pentex/core.rb
|
33
|
+
- lib/pentex.rb
|
34
|
+
- lib/README.txt
|
35
|
+
homepage: http://www.siberas.de
|
36
|
+
licenses: []
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
require_paths:
|
40
|
+
- lib
|
41
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubyforge_project:
|
55
|
+
rubygems_version: 1.7.2
|
56
|
+
signing_key:
|
57
|
+
specification_version: 3
|
58
|
+
summary: PENTEX - Pentesting Extensions
|
59
|
+
test_files: []
|