ronin-payloads 0.1.0.beta1 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (248) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +16 -1
  3. data/.rubocop.yml +37 -0
  4. data/.yardopts +1 -1
  5. data/ChangeLog.md +13 -1
  6. data/Gemfile +5 -2
  7. data/README.md +4 -3
  8. data/Rakefile +3 -1
  9. data/bin/ronin-payloads +7 -8
  10. data/examples/bin_sh.rb +4 -0
  11. data/gemspec.yml +8 -7
  12. data/lib/ronin/payloads/asm_payload.rb +2 -2
  13. data/lib/ronin/payloads/binary_payload.rb +1 -1
  14. data/lib/ronin/payloads/builtin/cmd/awk/reverse_shell.rb +1 -1
  15. data/lib/ronin/payloads/builtin/cmd/bash/reverse_shell.rb +1 -1
  16. data/lib/ronin/payloads/builtin/cmd/lua/reverse_shell.rb +1 -1
  17. data/lib/ronin/payloads/builtin/cmd/node/reverse_shell.rb +1 -1
  18. data/lib/ronin/payloads/builtin/cmd/openssl/reverse_shell.rb +1 -1
  19. data/lib/ronin/payloads/builtin/cmd/perl/reverse_shell.rb +1 -1
  20. data/lib/ronin/payloads/builtin/cmd/php/reverse_shell.rb +1 -1
  21. data/lib/ronin/payloads/builtin/cmd/powershell/reverse_shell.rb +1 -1
  22. data/lib/ronin/payloads/builtin/cmd/python/reverse_shell.rb +1 -1
  23. data/lib/ronin/payloads/builtin/cmd/ruby/reverse_shell.rb +1 -1
  24. data/lib/ronin/payloads/builtin/java/reverse_shell.rb +1 -1
  25. data/lib/ronin/payloads/builtin/php/cmd_exec.rb +5 -4
  26. data/lib/ronin/payloads/builtin/shellcode/freebsd/x86/bind_shell.rb +2 -2
  27. data/lib/ronin/payloads/builtin/shellcode/freebsd/x86/exec_shell.rb +2 -2
  28. data/lib/ronin/payloads/builtin/shellcode/freebsd/x86/reverse_shell.rb +2 -2
  29. data/lib/ronin/payloads/builtin/shellcode/freebsd/x86_64/exec_shell.rb +2 -2
  30. data/lib/ronin/payloads/builtin/shellcode/linux/arm/bind_shell.rb +2 -2
  31. data/lib/ronin/payloads/builtin/shellcode/linux/arm/exec_shell.rb +2 -2
  32. data/lib/ronin/payloads/builtin/shellcode/linux/arm/reverse_shell.rb +2 -2
  33. data/lib/ronin/payloads/builtin/shellcode/linux/mips/bind_shell.rb +2 -2
  34. data/lib/ronin/payloads/builtin/shellcode/linux/mips/exec_shell.rb +2 -2
  35. data/lib/ronin/payloads/builtin/shellcode/linux/mips/reverse_shell.rb +2 -2
  36. data/lib/ronin/payloads/builtin/shellcode/linux/ppc/exec_shell.rb +2 -2
  37. data/lib/ronin/payloads/builtin/shellcode/linux/ppc/reverse_shell.rb +3 -3
  38. data/lib/ronin/payloads/builtin/shellcode/linux/x86/bind_shell.rb +3 -3
  39. data/lib/ronin/payloads/builtin/shellcode/linux/x86/exec_shell.rb +2 -2
  40. data/lib/ronin/payloads/builtin/shellcode/linux/x86/reverse_shell.rb +2 -2
  41. data/lib/ronin/payloads/builtin/shellcode/linux/x86_64/bind_shell.rb +3 -3
  42. data/lib/ronin/payloads/builtin/shellcode/linux/x86_64/exec_shell.rb +2 -2
  43. data/lib/ronin/payloads/builtin/shellcode/linux/x86_64/reverse_shell.rb +2 -2
  44. data/lib/ronin/payloads/builtin/shellcode/macos/x86_64/exec_shell.rb +2 -2
  45. data/lib/ronin/payloads/builtin/shellcode/macos/x86_64/reverse_shell.rb +2 -2
  46. data/lib/ronin/payloads/builtin/shellcode/netbsd/x86/exec_shell.rb +2 -2
  47. data/lib/ronin/payloads/builtin/shellcode/netbsd/x86/reverse_shell.rb +2 -2
  48. data/lib/ronin/payloads/builtin/shellcode/openbsd/x86/bind_shell.rb +2 -2
  49. data/lib/ronin/payloads/builtin/shellcode/openbsd/x86/exec_shell.rb +2 -2
  50. data/lib/ronin/payloads/builtin/shellcode/windows/x86_64/cmd.rb +3 -3
  51. data/lib/ronin/payloads/builtin/test/open_redirect.rb +4 -4
  52. data/lib/ronin/payloads/builtin/test/xss.rb +4 -4
  53. data/lib/ronin/payloads/c_payload.rb +2 -2
  54. data/lib/ronin/payloads/cli/command.rb +1 -1
  55. data/lib/ronin/payloads/cli/commands/build.rb +11 -13
  56. data/lib/ronin/payloads/cli/commands/encode.rb +17 -21
  57. data/lib/ronin/payloads/cli/commands/encoder.rb +1 -1
  58. data/lib/ronin/payloads/cli/commands/encoders.rb +2 -2
  59. data/lib/ronin/payloads/cli/commands/irb.rb +1 -1
  60. data/lib/ronin/payloads/cli/commands/launch.rb +3 -3
  61. data/lib/ronin/payloads/cli/commands/list.rb +1 -1
  62. data/lib/ronin/payloads/cli/commands/new.rb +4 -4
  63. data/lib/ronin/payloads/cli/commands/show.rb +3 -2
  64. data/lib/ronin/payloads/cli/encoder_methods.rb +2 -1
  65. data/lib/ronin/payloads/cli/format_option.rb +1 -1
  66. data/lib/ronin/payloads/cli/generator/payload_types.rb +4 -3
  67. data/lib/ronin/payloads/cli/payload_command.rb +1 -1
  68. data/lib/ronin/payloads/cli/payload_methods.rb +1 -1
  69. data/lib/ronin/payloads/cli/printing.rb +1 -1
  70. data/lib/ronin/payloads/cli/ruby_shell.rb +1 -1
  71. data/lib/ronin/payloads/cli.rb +6 -1
  72. data/lib/ronin/payloads/coldfusion_payload.rb +1 -1
  73. data/lib/ronin/payloads/command_payload.rb +1 -1
  74. data/lib/ronin/payloads/encoders/builtin/html/encode.rb +2 -1
  75. data/lib/ronin/payloads/encoders/builtin/js/encode.rb +2 -1
  76. data/lib/ronin/payloads/encoders/builtin/powershell/encode.rb +2 -1
  77. data/lib/ronin/payloads/encoders/builtin/shell/encode.rb +2 -1
  78. data/lib/ronin/payloads/encoders/builtin/sql/encode.rb +2 -1
  79. data/lib/ronin/payloads/encoders/builtin/xml/encode.rb +2 -1
  80. data/lib/ronin/payloads/encoders/encoder.rb +3 -2
  81. data/lib/ronin/payloads/encoders/exceptions.rb +2 -1
  82. data/lib/ronin/payloads/encoders/html_encoder.rb +2 -1
  83. data/lib/ronin/payloads/encoders/javascript_encoder.rb +2 -1
  84. data/lib/ronin/payloads/encoders/pipeline.rb +3 -2
  85. data/lib/ronin/payloads/encoders/powershell_encoder.rb +2 -1
  86. data/lib/ronin/payloads/encoders/registry.rb +5 -1
  87. data/lib/ronin/payloads/encoders/shell_encoder.rb +2 -1
  88. data/lib/ronin/payloads/encoders/sql_encoder.rb +2 -1
  89. data/lib/ronin/payloads/encoders/xml_encoder.rb +2 -1
  90. data/lib/ronin/payloads/encoders.rb +1 -1
  91. data/lib/ronin/payloads/exceptions.rb +2 -1
  92. data/lib/ronin/payloads/go_payload.rb +2 -2
  93. data/lib/ronin/payloads/html_payload.rb +1 -1
  94. data/lib/ronin/payloads/java_payload.rb +2 -2
  95. data/lib/ronin/payloads/javascript_payload.rb +1 -1
  96. data/lib/ronin/payloads/jsp_payload.rb +1 -1
  97. data/lib/ronin/payloads/metadata/arch.rb +2 -1
  98. data/lib/ronin/payloads/metadata/os.rb +2 -1
  99. data/lib/ronin/payloads/mixins/binary.rb +1 -1
  100. data/lib/ronin/payloads/mixins/bind_shell.rb +3 -3
  101. data/lib/ronin/payloads/mixins/build_dir.rb +1 -1
  102. data/lib/ronin/payloads/mixins/erb.rb +1 -1
  103. data/lib/ronin/payloads/mixins/network.rb +1 -1
  104. data/lib/ronin/payloads/mixins/post_ex.rb +1 -2
  105. data/lib/ronin/payloads/mixins/resolve_host.rb +1 -1
  106. data/lib/ronin/payloads/mixins/reverse_shell.rb +1 -2
  107. data/lib/ronin/payloads/mixins/tempfile.rb +1 -1
  108. data/lib/ronin/payloads/mixins/typescript.rb +2 -3
  109. data/lib/ronin/payloads/node_js_payload.rb +1 -1
  110. data/lib/ronin/payloads/payload.rb +8 -8
  111. data/lib/ronin/payloads/php_payload.rb +1 -1
  112. data/lib/ronin/payloads/powershell_payload.rb +1 -1
  113. data/lib/ronin/payloads/python_payload.rb +1 -1
  114. data/lib/ronin/payloads/registry.rb +4 -1
  115. data/lib/ronin/payloads/root.rb +1 -1
  116. data/lib/ronin/payloads/ruby_payload.rb +1 -1
  117. data/lib/ronin/payloads/rust_payload.rb +2 -2
  118. data/lib/ronin/payloads/shell_payload.rb +1 -1
  119. data/lib/ronin/payloads/shellcode/bind_shell_payload.rb +1 -1
  120. data/lib/ronin/payloads/shellcode/exec_shell_payload.rb +1 -1
  121. data/lib/ronin/payloads/shellcode/reverse_shell_payload.rb +1 -1
  122. data/lib/ronin/payloads/shellcode_payload.rb +9 -9
  123. data/lib/ronin/payloads/sql_payload.rb +1 -1
  124. data/lib/ronin/payloads/url_payload.rb +3 -3
  125. data/lib/ronin/payloads/version.rb +2 -2
  126. data/lib/ronin/payloads/xml_payload.rb +1 -1
  127. data/lib/ronin/payloads.rb +2 -1
  128. data/man/ronin-payloads-build.1 +1 -1
  129. data/man/ronin-payloads-build.1.md +1 -1
  130. data/man/ronin-payloads-encode.1 +1 -1
  131. data/man/ronin-payloads-encode.1.md +1 -1
  132. data/man/ronin-payloads-encoder.1 +1 -1
  133. data/man/ronin-payloads-encoder.1.md +1 -1
  134. data/man/ronin-payloads-encoders.1 +1 -1
  135. data/man/ronin-payloads-encoders.1.md +1 -1
  136. data/man/ronin-payloads-irb.1 +1 -1
  137. data/man/ronin-payloads-irb.1.md +1 -1
  138. data/man/ronin-payloads-launch.1 +1 -1
  139. data/man/ronin-payloads-launch.1.md +1 -1
  140. data/man/ronin-payloads-list.1 +1 -1
  141. data/man/ronin-payloads-list.1.md +1 -1
  142. data/man/ronin-payloads.1 +1 -1
  143. data/man/ronin-payloads.1.md +1 -1
  144. data/ronin-payloads.gemspec +5 -5
  145. metadata +17 -215
  146. data/spec/asm_payload_spec.rb +0 -114
  147. data/spec/binary_payload_spec.rb +0 -8
  148. data/spec/builtin/cmd/awk/reverse_shell_spec.rb +0 -38
  149. data/spec/builtin/cmd/bash/reverse_shell_spec.rb +0 -36
  150. data/spec/builtin/cmd/lua/reverse_shell_spec.rb +0 -38
  151. data/spec/builtin/cmd/node/reverse_shell_spec.rb +0 -36
  152. data/spec/builtin/cmd/openssl/reverse_shell_spec.rb +0 -38
  153. data/spec/builtin/cmd/perl/reverse_shell_spec.rb +0 -38
  154. data/spec/builtin/cmd/php/reverse_shell_spec.rb +0 -38
  155. data/spec/builtin/cmd/powershell/reverse_shell_spec.rb +0 -38
  156. data/spec/builtin/cmd/python/reverse_shell_spec.rb +0 -38
  157. data/spec/builtin/cmd/ruby/reverse_shell_spec.rb +0 -38
  158. data/spec/builtin/java/reverse_shell_spec.rb +0 -103
  159. data/spec/builtin/php/cmd_exec.rb +0 -52
  160. data/spec/builtin/shellcode/freebsd/x86/bind_shell_spec.rb +0 -58
  161. data/spec/builtin/shellcode/freebsd/x86/exec_shell_spec.rb +0 -46
  162. data/spec/builtin/shellcode/freebsd/x86/reverse_shell_spec.rb +0 -63
  163. data/spec/builtin/shellcode/freebsd/x86_64/exec_shell_spec.rb +0 -46
  164. data/spec/builtin/shellcode/linux/arm/bind_shell_spec.rb +0 -62
  165. data/spec/builtin/shellcode/linux/arm/exec_shell_spec.rb +0 -46
  166. data/spec/builtin/shellcode/linux/arm/reverse_shell_spec.rb +0 -58
  167. data/spec/builtin/shellcode/linux/mips/bind_shell_spec.rb +0 -60
  168. data/spec/builtin/shellcode/linux/mips/exec_shell_spec.rb +0 -46
  169. data/spec/builtin/shellcode/linux/mips/reverse_shell_spec.rb +0 -58
  170. data/spec/builtin/shellcode/linux/ppc/exec_shell_spec.rb +0 -46
  171. data/spec/builtin/shellcode/linux/ppc/reverse_shell_spec.rb +0 -87
  172. data/spec/builtin/shellcode/linux/x86/bind_shell_spec.rb +0 -60
  173. data/spec/builtin/shellcode/linux/x86/exec_shell_spec.rb +0 -46
  174. data/spec/builtin/shellcode/linux/x86/reverse_shell_spec.rb +0 -58
  175. data/spec/builtin/shellcode/linux/x86_64/bind_shell_spec.rb +0 -60
  176. data/spec/builtin/shellcode/linux/x86_64/exec_shell_spec.rb +0 -46
  177. data/spec/builtin/shellcode/linux/x86_64/reverse_shell_spec.rb +0 -58
  178. data/spec/builtin/shellcode/macos/x86_64/exec_shell_spec.rb +0 -46
  179. data/spec/builtin/shellcode/macos/x86_64/reverse_shell_spec.rb +0 -58
  180. data/spec/builtin/shellcode/netbsd/x86/exec_shell_spec.rb +0 -46
  181. data/spec/builtin/shellcode/netbsd/x86/reverse_shell_spec.rb +0 -63
  182. data/spec/builtin/shellcode/openbsd/x86/bind_shell_spec.rb +0 -58
  183. data/spec/builtin/shellcode/openbsd/x86/exec_shell_spec.rb +0 -46
  184. data/spec/builtin/shellcode/windows/x86_64/cmd_spec.rb +0 -54
  185. data/spec/builtin/test/open_redirect_spec.rb +0 -24
  186. data/spec/builtin/test/xss_spec.rb +0 -24
  187. data/spec/c_payload_spec.rb +0 -139
  188. data/spec/cli/commands/show_spec.rb +0 -21
  189. data/spec/cli/encoder_methods_spec.rb +0 -275
  190. data/spec/cli/format_option_spec.rb +0 -187
  191. data/spec/cli/payload_command_spec.rb +0 -68
  192. data/spec/cli/payload_methods_spec.rb +0 -208
  193. data/spec/cli/printing_spec.rb +0 -65
  194. data/spec/cli/ruby_shell_spec.rb +0 -14
  195. data/spec/coldfusion_payload_spec.rb +0 -8
  196. data/spec/command_payload_spec.rb +0 -8
  197. data/spec/encoders/builtin/html/encode_spec.rb +0 -17
  198. data/spec/encoders/builtin/js/encode_spec.rb +0 -17
  199. data/spec/encoders/builtin/powershell/encode_spec.rb +0 -17
  200. data/spec/encoders/builtin/shell/encode_spec.rb +0 -17
  201. data/spec/encoders/builtin/sql/encode_spec.rb +0 -17
  202. data/spec/encoders/builtin/xml/encode_spec.rb +0 -17
  203. data/spec/encoders/encoder_spec.rb +0 -62
  204. data/spec/encoders/html_encoder_spec.rb +0 -8
  205. data/spec/encoders/javascript_encoder_spec.rb +0 -8
  206. data/spec/encoders/pipeline_spec.rb +0 -153
  207. data/spec/encoders/powershell_encoder_spec.rb +0 -8
  208. data/spec/encoders/shell_encoder_spec.rb +0 -8
  209. data/spec/encoders/sql_encoder_spec.rb +0 -8
  210. data/spec/encoders/xml_encoder_spec.rb +0 -8
  211. data/spec/encoders_spec.rb +0 -25
  212. data/spec/go_payload_spec.rb +0 -56
  213. data/spec/helpers/encoders.rb +0 -9
  214. data/spec/helpers/payloads.rb +0 -9
  215. data/spec/helpers/scripts/payloads/simple.rb +0 -22
  216. data/spec/html_payload_spec.rb +0 -12
  217. data/spec/java_payload_spec.rb +0 -97
  218. data/spec/javascript_payload_spec.rb +0 -12
  219. data/spec/jsp_payload_spec.rb +0 -8
  220. data/spec/metadata/arch_spec.rb +0 -82
  221. data/spec/metadata/os_spec.rb +0 -164
  222. data/spec/mixins/binary_spec.rb +0 -129
  223. data/spec/mixins/bind_shell_spec.rb +0 -73
  224. data/spec/mixins/build_dir.rb +0 -64
  225. data/spec/mixins/erb_spec.rb +0 -19
  226. data/spec/mixins/network_spec.rb +0 -75
  227. data/spec/mixins/post_ex_spec.rb +0 -40
  228. data/spec/mixins/resolve_host_spec.rb +0 -322
  229. data/spec/mixins/reverse_shell_spec.rb +0 -103
  230. data/spec/mixins/tempfile_spec.rb +0 -97
  231. data/spec/mixins/typescript_spec.rb +0 -92
  232. data/spec/node_js_payload_spec.rb +0 -8
  233. data/spec/payload_spec.rb +0 -288
  234. data/spec/payloads_spec.rb +0 -29
  235. data/spec/php_payload_spec.rb +0 -8
  236. data/spec/powershell_payload_spec.rb +0 -16
  237. data/spec/python_payload_spec.rb +0 -8
  238. data/spec/ruby_payload_spec.rb +0 -8
  239. data/spec/rust_payload_spec.rb +0 -116
  240. data/spec/shell_payload_spec.rb +0 -16
  241. data/spec/shellcode/bind_shell_payload_spec.rb +0 -42
  242. data/spec/shellcode/exec_shell_payload_spec.rb +0 -8
  243. data/spec/shellcode/reverse_shell_payload_spec.rb +0 -136
  244. data/spec/shellcode_payload_spec.rb +0 -38
  245. data/spec/spec_helper.rb +0 -7
  246. data/spec/sql_payload_spec.rb +0 -12
  247. data/spec/url_payload_spec.rb +0 -72
  248. data/spec/xml_payload_spec.rb +0 -12
@@ -1,275 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/payloads/cli/encoder_methods'
3
- require 'ronin/payloads/cli/command'
4
-
5
- describe Ronin::Payloads::CLI::EncoderMethods do
6
- module TestEncoderMethods
7
- class TestCommand < Ronin::Payloads::CLI::Command
8
- include Ronin::Payloads::CLI::EncoderMethods
9
- end
10
- end
11
-
12
- let(:command_class) { TestEncoderMethods::TestCommand }
13
- subject { command_class.new }
14
-
15
- describe "#encoder_type" do
16
- context "when given a HTMLEncoder class" do
17
- module TestEncoderMethods
18
- class TestHTMLEncoder < Ronin::Payloads::Encoders::HTMLEncoder
19
- end
20
- end
21
-
22
- let(:klass) { TestEncoderMethods::TestHTMLEncoder }
23
-
24
- it "must return 'html'" do
25
- expect(subject.encoder_type(klass)).to eq('html')
26
- end
27
- end
28
-
29
- context "when given a JavaScriptEncoder class" do
30
- module TestEncoderMethods
31
- class TestJavaScriptEncoder < Ronin::Payloads::Encoders::JavaScriptEncoder
32
- end
33
- end
34
-
35
- let(:klass) { TestEncoderMethods::TestJavaScriptEncoder }
36
-
37
- it "must return 'javascript'" do
38
- expect(subject.encoder_type(klass)).to eq('javascript')
39
- end
40
- end
41
-
42
- context "when given a ShellEncoder class" do
43
- module TestEncoderMethods
44
- class TestShellEncoder < Ronin::Payloads::Encoders::ShellEncoder
45
- end
46
- end
47
-
48
- let(:klass) { TestEncoderMethods::TestShellEncoder }
49
-
50
- it "must return 'shell'" do
51
- expect(subject.encoder_type(klass)).to eq('shell')
52
- end
53
- end
54
-
55
- context "when given a PowerShellEncoder class" do
56
- module TestEncoderMethods
57
- class TestPowerShellEncoder < Ronin::Payloads::Encoders::PowerShellEncoder
58
- end
59
- end
60
-
61
- let(:klass) { TestEncoderMethods::TestPowerShellEncoder }
62
-
63
- it "must return 'powershell'" do
64
- expect(subject.encoder_type(klass)).to eq('powershell')
65
- end
66
- end
67
-
68
- context "when given a SQLgEncoder class" do
69
- module TestEncoderMethods
70
- class TestSQLgEncoder < Ronin::Payloads::Encoders::SQLEncoder
71
- end
72
- end
73
-
74
- let(:klass) { TestEncoderMethods::TestSQLgEncoder }
75
-
76
- it "must return 'sql'" do
77
- expect(subject.encoder_type(klass)).to eq('sql')
78
- end
79
- end
80
- end
81
-
82
- describe "#load_encoder" do
83
- let(:encoder_id) { 'html/encode' }
84
-
85
- it "must call Encoders.load_class with the given ID" do
86
- expect(Ronin::Payloads::Encoders).to receive(:load_class).with(encoder_id)
87
- expect(subject).to_not receive(:exit)
88
-
89
- subject.load_encoder(encoder_id)
90
- end
91
-
92
- context "when Ronin::Payloads::Encoders::ClassNotfound is raised" do
93
- let(:message) { "class not found" }
94
- let(:exception) do
95
- Ronin::Payloads::Encoders::ClassNotFound.new(message)
96
- end
97
-
98
- it "must print an error message and exit with an error code" do
99
- expect(Ronin::Payloads::Encoders).to receive(:load_class).with(encoder_id).and_raise(exception)
100
- expect(subject).to receive(:exit).with(1)
101
-
102
- expect {
103
- subject.load_encoder(encoder_id)
104
- }.to output("#{subject.command_name}: #{message}#{$/}").to_stderr
105
- end
106
- end
107
-
108
- context "when another type of exception is raised" do
109
- let(:message) { "unexpected error" }
110
- let(:exception) { RuntimeError.new(message) }
111
-
112
- it "must print the exception, an error message, and exit with -1" do
113
- expect(Ronin::Payloads::Encoders).to receive(:load_class).with(encoder_id).and_raise(exception)
114
- expect(subject).to receive(:print_exception).with(exception)
115
- expect(subject).to receive(:exit).with(-1)
116
-
117
- expect {
118
- subject.load_encoder(encoder_id)
119
- }.to output("#{subject.command_name}: an unhandled exception occurred while loading encoder #{encoder_id}#{$/}").to_stderr
120
- end
121
- end
122
- end
123
-
124
- describe "#load_encoder_from" do
125
- let(:file) { '/path/to/html/encode.rb' }
126
-
127
- it "must call Payloads.load_class with the given ID and file" do
128
- expect(Ronin::Payloads::Encoders).to receive(:load_class_from_file).with(file)
129
- expect(subject).to_not receive(:exit)
130
-
131
- subject.load_encoder_from(file)
132
- end
133
-
134
- context "when Ronin::Payloads::ClassNotfound is raised" do
135
- let(:message) { "class not found" }
136
- let(:exception) do
137
- Ronin::Payloads::ClassNotFound.new(message)
138
- end
139
-
140
- it "must print an error message and exit with an error code" do
141
- expect(Ronin::Payloads::Encoders).to receive(:load_class_from_file).with(file).and_raise(exception)
142
- expect(subject).to receive(:exit).with(1)
143
-
144
- expect {
145
- subject.load_encoder_from(file)
146
- }.to output("#{subject.command_name}: #{message}#{$/}").to_stderr
147
- end
148
- end
149
-
150
- context "when another type of exception is raised" do
151
- let(:message) { "unexpected error" }
152
- let(:exception) { RuntimeError.new(message) }
153
-
154
- it "must print the exception, an error message, and exit with -1" do
155
- expect(Ronin::Payloads::Encoders).to receive(:load_class_from_file).with(file).and_raise(exception)
156
- expect(subject).to receive(:print_exception).with(exception)
157
- expect(subject).to receive(:exit).with(-1)
158
-
159
- expect {
160
- subject.load_encoder_from(file)
161
- }.to output(
162
- "#{subject.command_name}: an unhandled exception occurred while loading encoder from file #{file}#{$/}"
163
- ).to_stderr
164
- end
165
- end
166
- end
167
-
168
- describe "#initialie_encoder" do
169
- let(:encoder_id) { 'test' }
170
- let(:encoder_class) { double('Encoder class', id: encoder_id) }
171
-
172
- it "must return a new instance of the given encoder class" do
173
- expect(encoder_class).to receive(:new)
174
-
175
- subject.initialize_encoder(encoder_class)
176
- end
177
-
178
- context "when additional keyword arguments are given" do
179
- let(:kwargs) do
180
- {foo: 1, bar: 2}
181
- end
182
-
183
- it "must pass them to new()" do
184
- expect(encoder_class).to receive(:new).with(**kwargs)
185
-
186
- subject.initialize_encoder(encoder_class,**kwargs)
187
- end
188
- end
189
-
190
- context "when a Core::Params::ParamError is raised" do
191
- let(:message) { "param foo was not set" }
192
- let(:exception) { Ronin::Core::Params::RequiredParam.new(message) }
193
-
194
- it "must print an error message and exit with 1" do
195
- expect(encoder_class).to receive(:new).and_raise(exception)
196
- expect(subject).to receive(:exit).with(1)
197
-
198
- expect {
199
- subject.initialize_encoder(encoder_class)
200
- }.to output("#{subject.command_name}: #{message}#{$/}").to_stderr
201
- end
202
- end
203
-
204
- context "when another type of exception is raised" do
205
- let(:message) { "unexpected error" }
206
- let(:exception) { RuntimeError.new(message) }
207
-
208
- it "must print the exception, an error message, and exit with -1" do
209
- expect(encoder_class).to receive(:new).and_raise(exception)
210
- expect(subject).to receive(:print_exception).with(exception)
211
- expect(subject).to receive(:exit).with(-1)
212
-
213
- expect {
214
- subject.initialize_encoder(encoder_class)
215
- }.to output("#{subject.command_name}: an unhandled exception occurred while initializing encoder #{encoder_id}#{$/}").to_stderr
216
- end
217
- end
218
- end
219
-
220
- describe "#validate_encoder" do
221
- let(:encoder_id) { 'test' }
222
- let(:encoder) { double('Encoder instance', class_id: encoder_id) }
223
-
224
- it "must return a new instance of the given encoder class" do
225
- expect(encoder).to receive(:validate)
226
-
227
- subject.validate_encoder(encoder)
228
- end
229
-
230
- context "when a Core::Params::ParamError is raised" do
231
- let(:message) { "param foo was not set" }
232
- let(:exception) { Ronin::Core::Params::RequiredParam.new(message) }
233
-
234
- it "must print an error message and exit with 1" do
235
- expect(encoder).to receive(:validate).and_raise(exception)
236
- expect(subject).to receive(:exit).with(1)
237
-
238
- expect {
239
- subject.validate_encoder(encoder)
240
- }.to output("#{subject.command_name}: failed to validate the encoder #{encoder_id}: #{message}#{$/}").to_stderr
241
- end
242
- end
243
-
244
- context "when a Ronin::Payloads::Encoders::ValidationError is raised" do
245
- let(:message) { "param foo was not set" }
246
- let(:exception) do
247
- Ronin::Payloads::Encoders::ValidationError.new(message)
248
- end
249
-
250
- it "must print an error message and exit with 1" do
251
- expect(encoder).to receive(:validate).and_raise(exception)
252
- expect(subject).to receive(:exit).with(1)
253
-
254
- expect {
255
- subject.validate_encoder(encoder)
256
- }.to output("#{subject.command_name}: failed to validate the encoder #{encoder_id}: #{message}#{$/}").to_stderr
257
- end
258
- end
259
-
260
- context "when another type of exception is raised" do
261
- let(:message) { "unexpected error" }
262
- let(:exception) { RuntimeError.new(message) }
263
-
264
- it "must print the exception, an error message, and exit with -1" do
265
- expect(encoder).to receive(:validate).and_raise(exception)
266
- expect(subject).to receive(:print_exception).with(exception)
267
- expect(subject).to receive(:exit).with(-1)
268
-
269
- expect {
270
- subject.validate_encoder(encoder)
271
- }.to output("#{subject.command_name}: an unhandled exception occurred while validating the encoder #{encoder_id}#{$/}").to_stderr
272
- end
273
- end
274
- end
275
- end
@@ -1,187 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/payloads/cli/format_option'
3
- require 'ronin/payloads/cli/command'
4
-
5
- require 'stringio'
6
-
7
- describe Ronin::Payloads::CLI::FormatOption do
8
- module TestFormatOption
9
- class TestCommand < Ronin::Payloads::CLI::Command
10
- include Ronin::Payloads::CLI::FormatOption
11
- end
12
- end
13
-
14
- let(:command_class) { TestFormatOption::TestCommand }
15
- subject { command_class.new }
16
-
17
- describe ".included" do
18
- subject { command_class }
19
-
20
- it "must add a -F,--format c|shell|js|ruby option" do
21
- expect(subject.options[:format]).to_not be(nil)
22
- expect(subject.options[:format].short).to eq('-F')
23
- expect(subject.options[:format].value).to_not be(nil)
24
- expect(subject.options[:format].value.type).to eq(
25
- [:hex, :c, :shell, :powershell, :xml, :html, :js, :ruby]
26
- )
27
- expect(subject.options[:format].desc).to eq('Formats the outputed data')
28
- end
29
- end
30
-
31
- describe "parse_options" do
32
- context "when given '--format hex'" do
33
- before { subject.parse_options(%w[--format hex]) }
34
-
35
- it "must set #format to Ronin::Support::Encoding::Hex.escape" do
36
- expect(subject.format).to eq(
37
- Ronin::Support::Encoding::Hex.method(:escape)
38
- )
39
- end
40
- end
41
-
42
- context "when given '--format c'" do
43
- before { subject.parse_options(%w[--format c]) }
44
-
45
- it "must set #format to Ronin::Support::Encoding::C.quote" do
46
- expect(subject.format).to eq(
47
- Ronin::Support::Encoding::C.method(:quote)
48
- )
49
- end
50
- end
51
-
52
- context "when given '--format shell'" do
53
- before { subject.parse_options(%w[--format shell]) }
54
-
55
- it "must set #format to Ronin::Support::Encoding::Shell.quote" do
56
- expect(subject.format).to eq(
57
- Ronin::Support::Encoding::Shell.method(:quote)
58
- )
59
- end
60
- end
61
-
62
- context "when given '--format powershell'" do
63
- before { subject.parse_options(%w[--format powershell]) }
64
-
65
- it "must set #format to Ronin::Support::Encoding::PowerShell.quote" do
66
- expect(subject.format).to eq(
67
- Ronin::Support::Encoding::PowerShell.method(:quote)
68
- )
69
- end
70
- end
71
-
72
- context "when given '--format xml'" do
73
- before { subject.parse_options(%w[--format xml]) }
74
-
75
- it "must set #format to Ronin::Support::Encoding::XML.escape" do
76
- expect(subject.format).to eq(
77
- Ronin::Support::Encoding::XML.method(:escape)
78
- )
79
- end
80
- end
81
-
82
- context "when given '--format html'" do
83
- before { subject.parse_options(%w[--format html]) }
84
-
85
- it "must set #format to Ronin::Support::Encoding::HTML.escape" do
86
- expect(subject.format).to eq(
87
- Ronin::Support::Encoding::HTML.method(:escape)
88
- )
89
- end
90
- end
91
-
92
- context "when given '--format js'" do
93
- before { subject.parse_options(%w[--format js]) }
94
-
95
- it "must set #format to Ronin::Support::Encoding::JS.quote" do
96
- expect(subject.format).to eq(
97
- Ronin::Support::Encoding::JS.method(:quote)
98
- )
99
- end
100
- end
101
-
102
- context "when given '--format ruby'" do
103
- before { subject.parse_options(%w[--format ruby]) }
104
-
105
- it "must set #format to Ronin::Support::Encoding::Ruby.quote" do
106
- expect(subject.format).to eq(
107
- Ronin::Support::Encoding::Ruby.method(:quote)
108
- )
109
- end
110
- end
111
- end
112
-
113
- describe "#format_data" do
114
- let(:data) { "hello world" }
115
-
116
- context "when #format is set" do
117
- before { subject.parse_options(%w[--format html]) }
118
-
119
- it "must call #encode on the #format" do
120
- expect(subject.format_data(data)).to eq(
121
- Ronin::Support::Encoding::HTML.escape(data)
122
- )
123
- end
124
- end
125
-
126
- context "when #format is not set" do
127
- it "must return the data" do
128
- expect(subject.format_data(data)).to eq(data)
129
- end
130
- end
131
- end
132
-
133
- describe "#print_data" do
134
- let(:data) { "hello world" }
135
-
136
- let(:stdout) { StringIO.new }
137
- subject { command_class.new(stdout: stdout) }
138
-
139
- context "when stdout is a TTY" do
140
- before { expect(stdout).to receive(:tty?).and_return(true) }
141
-
142
- context "when #format is set" do
143
- before { subject.parse_options(%w[--format html]) }
144
-
145
- it "must print the formatted data" do
146
- subject.print_data(data)
147
-
148
- expect(stdout.string).to eq(
149
- "#{Ronin::Support::Encoding::HTML.escape(data)}#{$/}"
150
- )
151
- end
152
- end
153
-
154
- context "when #format is not set" do
155
- it "must print the unformatted data" do
156
- subject.print_data(data)
157
-
158
- expect(stdout.string).to eq("#{data}#{$/}")
159
- end
160
- end
161
- end
162
-
163
- context "when stdout not is a TTY" do
164
- before { expect(stdout).to receive(:tty?).and_return(false) }
165
-
166
- context "when #format is set" do
167
- before { subject.parse_options(%w[--format html]) }
168
-
169
- it "must print the formatted data without a newline" do
170
- subject.print_data(data)
171
-
172
- expect(stdout.string).to eq(
173
- "#{Ronin::Support::Encoding::HTML.escape(data)}"
174
- )
175
- end
176
- end
177
-
178
- context "when #format is not set" do
179
- it "must print the unformatted data without a newline" do
180
- subject.print_data(data)
181
-
182
- expect(stdout.string).to eq(data)
183
- end
184
- end
185
- end
186
- end
187
- end
@@ -1,68 +0,0 @@
1
- require 'spec_helper'
2
- require 'ronin/payloads/cli/payload_command'
3
- require 'ronin/payloads/payload'
4
-
5
- describe Ronin::Payloads::CLI::PayloadCommand do
6
- module TestPayloadCommand
7
- class TestPayload < Ronin::Payloads::Payload
8
- register 'test_payload_command'
9
- end
10
-
11
- class TestCommand < Ronin::Payloads::CLI::PayloadCommand
12
- end
13
- end
14
-
15
- let(:payload_class) { TestPayloadCommand::TestPayload }
16
- let(:command_class) { TestPayloadCommand::TestCommand }
17
- subject { command_class.new }
18
-
19
- describe "#load_payload" do
20
- let(:id) { payload_class.id }
21
-
22
- before do
23
- expect(Ronin::Payloads).to receive(:load_class).with(id).and_return(payload_class)
24
- end
25
-
26
- it "must load the payload class and return the payload class" do
27
- expect(subject.load_payload(id)).to be(payload_class)
28
- end
29
-
30
- it "must also set #payload_class" do
31
- subject.load_payload(id)
32
-
33
- expect(subject.payload_class).to be(payload_class)
34
- end
35
- end
36
-
37
- describe "#load_payload_from" do
38
- let(:file) { "path/to/payload/file.rb" }
39
-
40
- before do
41
- expect(Ronin::Payloads).to receive(:load_class_from_file).with(file).and_return(payload_class)
42
- end
43
-
44
- it "must load the payload class and return the payload class" do
45
- expect(subject.load_payload_from(file)).to be(payload_class)
46
- end
47
-
48
- it "must also set #payload_class" do
49
- subject.load_payload_from(file)
50
-
51
- expect(subject.payload_class).to be(payload_class)
52
- end
53
- end
54
-
55
- describe "#initialize_payload" do
56
- before { subject.load_payload(payload_class.id) }
57
-
58
- it "must initialize a new payload object using #payload_class" do
59
- expect(subject.initialize_payload).to be_kind_of(payload_class)
60
- end
61
-
62
- it "must also set #payload" do
63
- subject.initialize_payload
64
-
65
- expect(subject.payload).to be_kind_of(payload_class)
66
- end
67
- end
68
- end