CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

CoCalc provides the best real-time collaborative environment for Jupyter Notebooks, LaTeX documents, and SageMath, scalable from individual users to large groups and classes!

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/msf/ui/console/command_dispatcher/nop.rb
Views: 1904
1
# -*- coding: binary -*-
2
3
module Msf
4
module Ui
5
module Console
6
module CommandDispatcher
7
8
###
9
#
10
# NOP module command dispatcher.
11
#
12
###
13
class Nop
14
15
include Msf::Ui::Console::ModuleCommandDispatcher
16
17
@@generate_opts = Rex::Parser::Arguments.new(
18
"-b" => [ true, "The list of characters to avoid: '\\x00\\xff'" ],
19
"-h" => [ false, "Help banner." ],
20
"-s" => [ true, "The comma separated list of registers to save." ],
21
"-t" => [ true, "The output type: ruby, perl, c, or raw." ])
22
23
#
24
# Returns the hash of supported commands.
25
#
26
def commands
27
super.update({
28
"generate" => "Generates a NOP sled",
29
})
30
end
31
32
#
33
# Returns the name of the command dispatcher.
34
#
35
def name
36
"Nop"
37
end
38
39
#
40
# Generates a NOP sled.
41
#
42
def cmd_generate(*args)
43
44
# No arguments? Tell them how to use it.
45
if (args.length == 0)
46
args << "-h"
47
end
48
49
# Parse the arguments
50
badchars = nil
51
saveregs = nil
52
type = "ruby"
53
length = 200
54
55
@@generate_opts.parse(args) { |opt, idx, val|
56
case opt
57
when nil
58
length = val.to_i
59
when '-b'
60
badchars = Rex::Text.dehex(val)
61
when "-s", "-c" # 'c' is deprecated; remove later
62
saveregs = val.split(/,\s?/)
63
saveregs = val.split(/,\s?/)
64
when '-t'
65
type = val
66
when '-h'
67
print(
68
"Usage: generate [options] length\n\n" +
69
"Generates a NOP sled of a given length.\n" +
70
@@generate_opts.usage)
71
return false
72
end
73
}
74
75
# Generate the sled
76
begin
77
sled = mod.generate_simple(
78
length,
79
'BadChars' => badchars,
80
'SaveRegisters' => saveregs,
81
'Format' => type)
82
rescue
83
log_error("Sled generation failed: #{$!}.")
84
return false
85
end
86
87
# Display generated sled
88
print(sled)
89
90
return true
91
end
92
93
end
94
95
end end end end
96
97