rex 2.0.8 → 2.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (151) hide show
  1. checksums.yaml +4 -4
  2. data/lib/rex.rb +1 -0
  3. data/lib/rex/arch.rb +5 -0
  4. data/lib/rex/arch/x86.rb +19 -5
  5. data/lib/rex/arch/zarch.rb +17 -0
  6. data/lib/rex/compat.rb +5 -4
  7. data/lib/rex/constants.rb +3 -1
  8. data/lib/rex/encoder/alpha2/alpha_mixed.rb +70 -9
  9. data/lib/rex/encoder/alpha2/alpha_upper.rb +67 -8
  10. data/lib/rex/exploitation/cmdstager.rb +1 -0
  11. data/lib/rex/exploitation/cmdstager/certutil.rb +115 -0
  12. data/lib/rex/exploitation/cmdstager/echo.rb +6 -3
  13. data/lib/rex/exploitation/egghunter.rb +1 -1
  14. data/lib/rex/google/geolocation.rb +68 -0
  15. data/lib/rex/io/bidirectional_pipe.rb +0 -4
  16. data/lib/rex/java/serialization.rb +2 -0
  17. data/lib/rex/java/serialization/decode_error.rb +11 -0
  18. data/lib/rex/java/serialization/encode_error.rb +11 -0
  19. data/lib/rex/java/serialization/model.rb +2 -0
  20. data/lib/rex/java/serialization/model/annotation.rb +3 -3
  21. data/lib/rex/java/serialization/model/block_data.rb +3 -3
  22. data/lib/rex/java/serialization/model/block_data_long.rb +3 -3
  23. data/lib/rex/java/serialization/model/class_desc.rb +6 -6
  24. data/lib/rex/java/serialization/model/contents.rb +17 -10
  25. data/lib/rex/java/serialization/model/field.rb +12 -11
  26. data/lib/rex/java/serialization/model/long_utf.rb +3 -3
  27. data/lib/rex/java/serialization/model/new_array.rb +22 -23
  28. data/lib/rex/java/serialization/model/new_class.rb +57 -0
  29. data/lib/rex/java/serialization/model/new_class_desc.rb +15 -16
  30. data/lib/rex/java/serialization/model/new_enum.rb +5 -5
  31. data/lib/rex/java/serialization/model/new_object.rb +22 -17
  32. data/lib/rex/java/serialization/model/proxy_class_desc.rb +109 -0
  33. data/lib/rex/java/serialization/model/reference.rb +4 -4
  34. data/lib/rex/java/serialization/model/stream.rb +7 -7
  35. data/lib/rex/java/serialization/model/utf.rb +3 -3
  36. data/lib/rex/json_hash_file.rb +94 -0
  37. data/lib/rex/logging/log_sink.rb +1 -0
  38. data/lib/rex/logging/sinks/timestamp_flatfile.rb +21 -0
  39. data/lib/rex/parser/appscan_nokogiri.rb +13 -23
  40. data/lib/rex/parser/fs/ntfs.rb +10 -5
  41. data/lib/rex/parser/nmap_nokogiri.rb +3 -1
  42. data/lib/rex/parser/openvas_nokogiri.rb +70 -73
  43. data/lib/rex/parser/winscp.rb +108 -0
  44. data/lib/rex/parser/x509_certificate.rb +92 -0
  45. data/lib/rex/payloads.rb +0 -1
  46. data/lib/rex/payloads/meterpreter/config.rb +154 -0
  47. data/lib/rex/payloads/meterpreter/uri_checksum.rb +136 -0
  48. data/lib/rex/post/meterpreter.rb +1 -1
  49. data/lib/rex/post/meterpreter/client.rb +26 -3
  50. data/lib/rex/post/meterpreter/client_core.rb +387 -75
  51. data/lib/rex/post/meterpreter/extensions/android/android.rb +127 -37
  52. data/lib/rex/post/meterpreter/extensions/android/tlv.rb +46 -25
  53. data/lib/rex/post/meterpreter/extensions/extapi/extapi.rb +4 -0
  54. data/lib/rex/post/meterpreter/extensions/extapi/ntds/ntds.rb +39 -0
  55. data/lib/rex/post/meterpreter/extensions/extapi/pageant/pageant.rb +44 -0
  56. data/lib/rex/post/meterpreter/extensions/extapi/tlv.rb +9 -0
  57. data/lib/rex/post/meterpreter/extensions/kiwi/kiwi.rb +16 -1
  58. data/lib/rex/post/meterpreter/extensions/priv/priv.rb +1 -1
  59. data/lib/rex/post/meterpreter/extensions/python/python.rb +114 -0
  60. data/lib/rex/post/meterpreter/extensions/python/tlv.rb +21 -0
  61. data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +17 -14
  62. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +33 -12
  63. data/lib/rex/post/meterpreter/extensions/stdapi/fs/mount.rb +57 -0
  64. data/lib/rex/post/meterpreter/extensions/stdapi/railgun/def/def_kernel32.rb +3 -3
  65. data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +3 -1
  66. data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +2 -0
  67. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +16 -3
  68. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +29 -6
  69. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +5 -1
  70. data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +18 -6
  71. data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +2 -2
  72. data/lib/rex/post/meterpreter/extensions/stdapi/webcam/webcam.rb +34 -36
  73. data/lib/rex/post/meterpreter/packet.rb +29 -0
  74. data/lib/rex/post/meterpreter/packet_dispatcher.rb +20 -7
  75. data/lib/rex/post/meterpreter/ui/console.rb +1 -0
  76. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/android.rb +230 -72
  77. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +544 -34
  78. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/extapi/adsi.rb +188 -57
  79. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/kiwi.rb +115 -93
  80. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/lanattacks/dhcp.rb +1 -1
  81. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/mimikatz.rb +1 -1
  82. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +49 -15
  83. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +11 -2
  84. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/python.rb +187 -0
  85. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +324 -133
  86. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +52 -2
  87. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +68 -65
  88. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +9 -1
  89. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/webcam.rb +113 -118
  90. data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +3 -0
  91. data/lib/rex/powershell.rb +62 -0
  92. data/lib/rex/powershell/command.rb +359 -0
  93. data/lib/rex/{exploitation/powershell → powershell}/function.rb +0 -2
  94. data/lib/rex/{exploitation/powershell → powershell}/obfu.rb +0 -2
  95. data/lib/rex/{exploitation/powershell → powershell}/output.rb +11 -5
  96. data/lib/rex/{exploitation/powershell → powershell}/param.rb +0 -2
  97. data/lib/rex/powershell/parser.rb +182 -0
  98. data/lib/rex/powershell/payload.rb +78 -0
  99. data/lib/rex/{exploitation/powershell → powershell}/psh_methods.rb +16 -2
  100. data/lib/rex/{exploitation/powershell → powershell}/script.rb +2 -4
  101. data/lib/rex/proto/dcerpc/client.rb +6 -6
  102. data/lib/rex/proto/dcerpc/exceptions.rb +26 -0
  103. data/lib/rex/proto/http/client.rb +3 -3
  104. data/lib/rex/proto/http/client_request.rb +0 -5
  105. data/lib/rex/proto/http/response.rb +86 -0
  106. data/lib/rex/proto/ipmi/utils.rb +30 -26
  107. data/lib/rex/proto/kerberos/client.rb +1 -1
  108. data/lib/rex/proto/kerberos/model/kdc_request.rb +2 -2
  109. data/lib/rex/proto/rfb/client.rb +8 -3
  110. data/lib/rex/proto/rfb/constants.rb +1 -1
  111. data/lib/rex/proto/rmi.rb +2 -0
  112. data/lib/rex/proto/rmi/decode_error.rb +10 -0
  113. data/lib/rex/proto/rmi/exception.rb +10 -0
  114. data/lib/rex/proto/rmi/model.rb +5 -0
  115. data/lib/rex/proto/rmi/model/call.rb +4 -4
  116. data/lib/rex/proto/rmi/model/call_data.rb +137 -0
  117. data/lib/rex/proto/rmi/model/dgc_ack.rb +2 -2
  118. data/lib/rex/proto/rmi/model/element.rb +26 -11
  119. data/lib/rex/proto/rmi/model/output_header.rb +4 -4
  120. data/lib/rex/proto/rmi/model/ping.rb +2 -2
  121. data/lib/rex/proto/rmi/model/ping_ack.rb +2 -2
  122. data/lib/rex/proto/rmi/model/protocol_ack.rb +2 -2
  123. data/lib/rex/proto/rmi/model/return_data.rb +5 -5
  124. data/lib/rex/proto/rmi/model/return_value.rb +124 -0
  125. data/lib/rex/proto/rmi/model/unique_identifier.rb +77 -0
  126. data/lib/rex/proto/steam.rb +3 -0
  127. data/lib/rex/proto/steam/message.rb +125 -0
  128. data/lib/rex/proto/tftp/client.rb +35 -14
  129. data/lib/rex/random_identifier_generator.rb +2 -0
  130. data/lib/rex/ropbuilder.rb +1 -1
  131. data/lib/rex/socket/parameters.rb +9 -0
  132. data/lib/rex/socket/ssl_tcp.rb +25 -41
  133. data/lib/rex/socket/ssl_tcp_server.rb +10 -21
  134. data/lib/rex/sslscan/result.rb +20 -1
  135. data/lib/rex/text.rb +241 -55
  136. data/lib/rex/ui/output.rb +0 -3
  137. data/lib/rex/ui/subscriber.rb +0 -10
  138. data/lib/rex/ui/text/color.rb +9 -0
  139. data/lib/rex/ui/text/dispatcher_shell.rb +1 -0
  140. data/lib/rex/ui/text/output.rb +15 -4
  141. data/lib/rex/ui/text/output/file.rb +1 -0
  142. data/lib/rex/ui/text/output/stdio.rb +0 -16
  143. data/lib/rex/ui/text/shell.rb +3 -0
  144. data/lib/rex/ui/text/table.rb +85 -19
  145. data/lib/rex/user_agent.rb +118 -0
  146. data/rex.gemspec +2 -2
  147. metadata +41 -14
  148. data/lib/rex/exploitation/powershell.rb +0 -62
  149. data/lib/rex/exploitation/powershell/parser.rb +0 -183
  150. data/lib/rex/payloads/meterpreter.rb +0 -2
  151. data/lib/rex/payloads/meterpreter/patch.rb +0 -136
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rex
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.8
4
+ version: 2.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - HD Moore
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-03-05 00:00:00.000000000 Z
12
+ date: 2015-11-22 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Rex provides a variety of classes useful for security testing and exploit
15
15
  development.
16
16
  email:
17
- - hd_moore@rapid7.com
17
+ - x@hdm.io
18
18
  - jacob.hammack@hammackj.com
19
19
  executables: []
20
20
  extensions: []
@@ -28,6 +28,7 @@ files:
28
28
  - lib/rex/arch.rb
29
29
  - lib/rex/arch/sparc.rb
30
30
  - lib/rex/arch/x86.rb
31
+ - lib/rex/arch/zarch.rb
31
32
  - lib/rex/assembly/nasm.rb
32
33
  - lib/rex/codepage.map
33
34
  - lib/rex/compat.rb
@@ -68,6 +69,7 @@ files:
68
69
  - lib/rex/exploitation/cmdstager.rb
69
70
  - lib/rex/exploitation/cmdstager/base.rb
70
71
  - lib/rex/exploitation/cmdstager/bourne.rb
72
+ - lib/rex/exploitation/cmdstager/certutil.rb
71
73
  - lib/rex/exploitation/cmdstager/debug_asm.rb
72
74
  - lib/rex/exploitation/cmdstager/debug_write.rb
73
75
  - lib/rex/exploitation/cmdstager/echo.rb
@@ -87,17 +89,10 @@ files:
87
89
  - lib/rex/exploitation/obfuscatejs.rb
88
90
  - lib/rex/exploitation/omelet.rb
89
91
  - lib/rex/exploitation/opcodedb.rb
90
- - lib/rex/exploitation/powershell.rb
91
- - lib/rex/exploitation/powershell/function.rb
92
- - lib/rex/exploitation/powershell/obfu.rb
93
- - lib/rex/exploitation/powershell/output.rb
94
- - lib/rex/exploitation/powershell/param.rb
95
- - lib/rex/exploitation/powershell/parser.rb
96
- - lib/rex/exploitation/powershell/psh_methods.rb
97
- - lib/rex/exploitation/powershell/script.rb
98
92
  - lib/rex/exploitation/ropdb.rb
99
93
  - lib/rex/exploitation/seh.rb
100
94
  - lib/rex/file.rb
95
+ - lib/rex/google/geolocation.rb
101
96
  - lib/rex/image_source.rb
102
97
  - lib/rex/image_source/disk.rb
103
98
  - lib/rex/image_source/image_source.rb
@@ -111,6 +106,8 @@ files:
111
106
  - lib/rex/java.rb
112
107
  - lib/rex/java/serialization.rb
113
108
  - lib/rex/java/serialization/builder.rb
109
+ - lib/rex/java/serialization/decode_error.rb
110
+ - lib/rex/java/serialization/encode_error.rb
114
111
  - lib/rex/java/serialization/model.rb
115
112
  - lib/rex/java/serialization/model/annotation.rb
116
113
  - lib/rex/java/serialization/model/block_data.rb
@@ -122,20 +119,24 @@ files:
122
119
  - lib/rex/java/serialization/model/field.rb
123
120
  - lib/rex/java/serialization/model/long_utf.rb
124
121
  - lib/rex/java/serialization/model/new_array.rb
122
+ - lib/rex/java/serialization/model/new_class.rb
125
123
  - lib/rex/java/serialization/model/new_class_desc.rb
126
124
  - lib/rex/java/serialization/model/new_enum.rb
127
125
  - lib/rex/java/serialization/model/new_object.rb
128
126
  - lib/rex/java/serialization/model/null_reference.rb
127
+ - lib/rex/java/serialization/model/proxy_class_desc.rb
129
128
  - lib/rex/java/serialization/model/reference.rb
130
129
  - lib/rex/java/serialization/model/reset.rb
131
130
  - lib/rex/java/serialization/model/stream.rb
132
131
  - lib/rex/java/serialization/model/utf.rb
133
132
  - lib/rex/job_container.rb
133
+ - lib/rex/json_hash_file.rb
134
134
  - lib/rex/logging.rb
135
135
  - lib/rex/logging/log_dispatcher.rb
136
136
  - lib/rex/logging/log_sink.rb
137
137
  - lib/rex/logging/sinks/flatfile.rb
138
138
  - lib/rex/logging/sinks/stderr.rb
139
+ - lib/rex/logging/sinks/timestamp_flatfile.rb
139
140
  - lib/rex/mac_oui.rb
140
141
  - lib/rex/machparsey.rb
141
142
  - lib/rex/machparsey/exceptions.rb
@@ -196,9 +197,11 @@ files:
196
197
  - lib/rex/parser/retina_xml.rb
197
198
  - lib/rex/parser/unattend.rb
198
199
  - lib/rex/parser/wapiti_nokogiri.rb
200
+ - lib/rex/parser/winscp.rb
201
+ - lib/rex/parser/x509_certificate.rb
199
202
  - lib/rex/payloads.rb
200
- - lib/rex/payloads/meterpreter.rb
201
- - lib/rex/payloads/meterpreter/patch.rb
203
+ - lib/rex/payloads/meterpreter/config.rb
204
+ - lib/rex/payloads/meterpreter/uri_checksum.rb
202
205
  - lib/rex/payloads/win32.rb
203
206
  - lib/rex/payloads/win32/common.rb
204
207
  - lib/rex/payloads/win32/kernel.rb
@@ -249,6 +252,8 @@ files:
249
252
  - lib/rex/post/meterpreter/extensions/extapi/adsi/adsi.rb
250
253
  - lib/rex/post/meterpreter/extensions/extapi/clipboard/clipboard.rb
251
254
  - lib/rex/post/meterpreter/extensions/extapi/extapi.rb
255
+ - lib/rex/post/meterpreter/extensions/extapi/ntds/ntds.rb
256
+ - lib/rex/post/meterpreter/extensions/extapi/pageant/pageant.rb
252
257
  - lib/rex/post/meterpreter/extensions/extapi/service/service.rb
253
258
  - lib/rex/post/meterpreter/extensions/extapi/tlv.rb
254
259
  - lib/rex/post/meterpreter/extensions/extapi/window/window.rb
@@ -269,6 +274,8 @@ files:
269
274
  - lib/rex/post/meterpreter/extensions/priv/passwd.rb
270
275
  - lib/rex/post/meterpreter/extensions/priv/priv.rb
271
276
  - lib/rex/post/meterpreter/extensions/priv/tlv.rb
277
+ - lib/rex/post/meterpreter/extensions/python/python.rb
278
+ - lib/rex/post/meterpreter/extensions/python/tlv.rb
272
279
  - lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb
273
280
  - lib/rex/post/meterpreter/extensions/sniffer/tlv.rb
274
281
  - lib/rex/post/meterpreter/extensions/stdapi/constants.rb
@@ -276,6 +283,7 @@ files:
276
283
  - lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb
277
284
  - lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb
278
285
  - lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb
286
+ - lib/rex/post/meterpreter/extensions/stdapi/fs/mount.rb
279
287
  - lib/rex/post/meterpreter/extensions/stdapi/net/arp.rb
280
288
  - lib/rex/post/meterpreter/extensions/stdapi/net/config.rb
281
289
  - lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb
@@ -359,6 +367,7 @@ files:
359
367
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb
360
368
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb
361
369
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb
370
+ - lib/rex/post/meterpreter/ui/console/command_dispatcher/python.rb
362
371
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb
363
372
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb
364
373
  - lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb
@@ -371,6 +380,16 @@ files:
371
380
  - lib/rex/post/process.rb
372
381
  - lib/rex/post/thread.rb
373
382
  - lib/rex/post/ui.rb
383
+ - lib/rex/powershell.rb
384
+ - lib/rex/powershell/command.rb
385
+ - lib/rex/powershell/function.rb
386
+ - lib/rex/powershell/obfu.rb
387
+ - lib/rex/powershell/output.rb
388
+ - lib/rex/powershell/param.rb
389
+ - lib/rex/powershell/parser.rb
390
+ - lib/rex/powershell/payload.rb
391
+ - lib/rex/powershell/psh_methods.rb
392
+ - lib/rex/powershell/script.rb
374
393
  - lib/rex/proto.rb
375
394
  - lib/rex/proto/acpp.rb
376
395
  - lib/rex/proto/acpp/client.rb
@@ -488,8 +507,11 @@ files:
488
507
  - lib/rex/proto/rfb/client.rb
489
508
  - lib/rex/proto/rfb/constants.rb
490
509
  - lib/rex/proto/rmi.rb
510
+ - lib/rex/proto/rmi/decode_error.rb
511
+ - lib/rex/proto/rmi/exception.rb
491
512
  - lib/rex/proto/rmi/model.rb
492
513
  - lib/rex/proto/rmi/model/call.rb
514
+ - lib/rex/proto/rmi/model/call_data.rb
493
515
  - lib/rex/proto/rmi/model/continuation.rb
494
516
  - lib/rex/proto/rmi/model/dgc_ack.rb
495
517
  - lib/rex/proto/rmi/model/element.rb
@@ -498,6 +520,8 @@ files:
498
520
  - lib/rex/proto/rmi/model/ping_ack.rb
499
521
  - lib/rex/proto/rmi/model/protocol_ack.rb
500
522
  - lib/rex/proto/rmi/model/return_data.rb
523
+ - lib/rex/proto/rmi/model/return_value.rb
524
+ - lib/rex/proto/rmi/model/unique_identifier.rb
501
525
  - lib/rex/proto/sip.rb
502
526
  - lib/rex/proto/sip/response.rb
503
527
  - lib/rex/proto/smb.rb
@@ -510,6 +534,8 @@ files:
510
534
  - lib/rex/proto/smb/simpleclient/open_file.rb
511
535
  - lib/rex/proto/smb/simpleclient/open_pipe.rb
512
536
  - lib/rex/proto/smb/utils.rb
537
+ - lib/rex/proto/steam.rb
538
+ - lib/rex/proto/steam/message.rb
513
539
  - lib/rex/proto/sunrpc.rb
514
540
  - lib/rex/proto/sunrpc/client.rb
515
541
  - lib/rex/proto/tftp.rb
@@ -590,6 +616,7 @@ files:
590
616
  - lib/rex/ui/text/progress_tracker.rb
591
617
  - lib/rex/ui/text/shell.rb
592
618
  - lib/rex/ui/text/table.rb
619
+ - lib/rex/user_agent.rb
593
620
  - lib/rex/zip.rb
594
621
  - lib/rex/zip/archive.rb
595
622
  - lib/rex/zip/blocks.rb
@@ -620,7 +647,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
620
647
  version: '0'
621
648
  requirements: []
622
649
  rubyforge_project:
623
- rubygems_version: 2.4.3
650
+ rubygems_version: 2.4.8
624
651
  signing_key:
625
652
  specification_version: 4
626
653
  summary: Ruby Exploitation Library
@@ -1,62 +0,0 @@
1
- # -*- coding: binary -*-
2
-
3
- require 'rex/exploitation/powershell/output'
4
- require 'rex/exploitation/powershell/parser'
5
- require 'rex/exploitation/powershell/obfu'
6
- require 'rex/exploitation/powershell/param'
7
- require 'rex/exploitation/powershell/function'
8
- require 'rex/exploitation/powershell/script'
9
- require 'rex/exploitation/powershell/psh_methods'
10
-
11
- module Rex
12
- module Exploitation
13
- module Powershell
14
- #
15
- # Reads script into a PowershellScript
16
- #
17
- # @param script_path [String] Path to the Script File
18
- #
19
- # @return [Script] Powershell Script object
20
- def self.read_script(script_path)
21
- Rex::Exploitation::Powershell::Script.new(script_path)
22
- end
23
-
24
- #
25
- # Insert substitutions into the powershell script
26
- # If script is a path to a file then read the file
27
- # otherwise treat it as the contents of a file
28
- #
29
- # @param script [String] Script file or path to script
30
- # @param subs [Array] Substitutions to insert
31
- #
32
- # @return [String] Modified script file
33
- def self.make_subs(script, subs)
34
- if ::File.file?(script)
35
- script = ::File.read(script)
36
- end
37
-
38
- subs.each do |set|
39
- script.gsub!(set[0], set[1])
40
- end
41
-
42
- script
43
- end
44
-
45
- #
46
- # Return an array of substitutions for use in make_subs
47
- #
48
- # @param subs [String] A ; seperated list of substitutions
49
- #
50
- # @return [Array] An array of substitutions
51
- def self.process_subs(subs)
52
- return [] if subs.nil? or subs.empty?
53
- new_subs = []
54
- subs.split(';').each do |set|
55
- new_subs << set.split(',', 2)
56
- end
57
-
58
- new_subs
59
- end
60
- end
61
- end
62
- end
@@ -1,183 +0,0 @@
1
- # -*- coding: binary -*-
2
-
3
- module Rex
4
- module Exploitation
5
- module Powershell
6
- module Parser
7
- # Reserved special variables
8
- # Acquired with: Get-Variable | Format-Table name, value -auto
9
- RESERVED_VARIABLE_NAMES = [
10
- '$$',
11
- '$?',
12
- '$^',
13
- '$_',
14
- '$args',
15
- '$ConfirmPreference',
16
- '$ConsoleFileName',
17
- '$DebugPreference',
18
- '$Env',
19
- '$Error',
20
- '$ErrorActionPreference',
21
- '$ErrorView',
22
- '$ExecutionContext',
23
- '$false',
24
- '$FormatEnumerationLimit',
25
- '$HOME',
26
- '$Host',
27
- '$input',
28
- '$LASTEXITCODE',
29
- '$MaximumAliasCount',
30
- '$MaximumDriveCount',
31
- '$MaximumErrorCount',
32
- '$MaximumFunctionCount',
33
- '$MaximumHistoryCount',
34
- '$MaximumVariableCount',
35
- '$MyInvocation',
36
- '$NestedPromptLevel',
37
- '$null',
38
- '$OutputEncoding',
39
- '$PID',
40
- '$PROFILE',
41
- '$ProgressPreference',
42
- '$PSBoundParameters',
43
- '$PSCulture',
44
- '$PSEmailServer',
45
- '$PSHOME',
46
- '$PSSessionApplicationName',
47
- '$PSSessionConfigurationName',
48
- '$PSSessionOption',
49
- '$PSUICulture',
50
- '$PSVersionTable',
51
- '$PWD',
52
- '$ReportErrorShowExceptionClass',
53
- '$ReportErrorShowInnerException',
54
- '$ReportErrorShowSource',
55
- '$ReportErrorShowStackTrace',
56
- '$ShellId',
57
- '$StackTrace',
58
- '$true',
59
- '$VerbosePreference',
60
- '$WarningPreference',
61
- '$WhatIfPreference'
62
- ].map(&:downcase).freeze
63
-
64
- #
65
- # Get variable names from code, removes reserved names from return
66
- #
67
- # @return [Array] variable names
68
- def get_var_names
69
- our_vars = code.scan(/\$[a-zA-Z\-\_0-9]+/).uniq.flatten.map(&:strip)
70
- our_vars.select { |v| !RESERVED_VARIABLE_NAMES.include?(v.downcase) }
71
- end
72
-
73
- #
74
- # Get function names from code
75
- #
76
- # @return [Array] function names
77
- def get_func_names
78
- code.scan(/function\s([a-zA-Z\-\_0-9]+)/).uniq.flatten
79
- end
80
-
81
- #
82
- # Attempt to find string literals in PSH expression
83
- #
84
- # @return [Array] string literals
85
- def get_string_literals
86
- code.scan(/@"(.+?)"@|@'(.+?)'@/m)
87
- end
88
-
89
- #
90
- # Scan code and return matches with index
91
- #
92
- # @param str [String] string to match in code
93
- # @param source [String] source code to match, defaults to @code
94
- #
95
- # @return [Array[String,Integer]] matched items with index
96
- def scan_with_index(str, source = code)
97
- ::Enumerator.new do |y|
98
- source.scan(str) do
99
- y << ::Regexp.last_match
100
- end
101
- end.map { |m| [m.to_s, m.offset(0)[0]] }
102
- end
103
-
104
- #
105
- # Return matching bracket type
106
- #
107
- # @param char [String] opening bracket character
108
- #
109
- # @return [String] matching closing bracket
110
- def match_start(char)
111
- case char
112
- when '{'
113
- '}'
114
- when '('
115
- ')'
116
- when '['
117
- ']'
118
- when '<'
119
- '>'
120
- else
121
- fail ArgumentError, 'Unknown starting bracket'
122
- end
123
- end
124
-
125
- #
126
- # Extract block of code inside brackets/parenthesis
127
- #
128
- # Attempts to match the bracket at idx, handling nesting manually
129
- # Once the balanced matching bracket is found, all script content
130
- # between idx and the index of the matching bracket is returned
131
- #
132
- # @param idx [Integer] index of opening bracket
133
- #
134
- # @return [String] content between matching brackets
135
- def block_extract(idx)
136
- fail ArgumentError unless idx
137
-
138
- if idx < 0 || idx >= code.length
139
- fail ArgumentError, 'Invalid index'
140
- end
141
-
142
- start = code[idx]
143
- stop = match_start(start)
144
- delims = scan_with_index(/#{Regexp.escape(start)}|#{Regexp.escape(stop)}/, code[idx + 1..-1])
145
- delims.map { |x| x[1] = x[1] + idx + 1 }
146
- c = 1
147
- sidx = nil
148
- # Go through delims till we balance, get idx
149
- while (c != 0) && (x = delims.shift)
150
- sidx = x[1]
151
- x[0] == stop ? c -= 1 : c += 1
152
- end
153
-
154
- code[idx..sidx]
155
- end
156
-
157
- #
158
- # Extract a block of function code
159
- #
160
- # @param func_name [String] function name
161
- # @param delete [Boolean] delete the function from the code
162
- #
163
- # @return [String] function block
164
- def get_func(func_name, delete = false)
165
- start = code.index(func_name)
166
-
167
- return nil unless start
168
-
169
- idx = code[start..-1].index('{') + start
170
- func_txt = block_extract(idx)
171
-
172
- if delete
173
- delete_code = code[0..idx]
174
- delete_code << code[(idx + func_txt.length)..-1]
175
- @code = delete_code
176
- end
177
-
178
- Function.new(func_name, func_txt)
179
- end
180
- end # Parser
181
- end
182
- end
183
- end
@@ -1,2 +0,0 @@
1
- # -*- coding: binary -*-
2
- require 'rex/payloads/meterpreter/patch'
@@ -1,136 +0,0 @@
1
- # -*- coding: binary -*-
2
-
3
- module Rex
4
- module Payloads
5
- module Meterpreter
6
- ###
7
- #
8
- # Provides methods to patch options into metsrv stagers
9
- #
10
- ###
11
- module Patch
12
-
13
- # Replace the transport string
14
- def self.patch_transport! blob, ssl
15
-
16
- i = blob.index("METERPRETER_TRANSPORT_SSL")
17
- if i
18
- str = ssl ? "METERPRETER_TRANSPORT_HTTPS\x00" : "METERPRETER_TRANSPORT_HTTP\x00"
19
- blob[i, str.length] = str
20
- end
21
-
22
- end
23
-
24
- # Replace the URL
25
- def self.patch_url! blob, url
26
-
27
- i = blob.index("https://" + ("X" * 256))
28
- if i
29
- str = url
30
- blob[i, str.length] = str
31
- end
32
-
33
- end
34
-
35
- # Replace the session expiration timeout
36
- def self.patch_expiration! blob, expiration
37
-
38
- i = blob.index([0xb64be661].pack("V"))
39
- if i
40
- str = [ expiration ].pack("V")
41
- blob[i, str.length] = str
42
- end
43
-
44
- end
45
-
46
- # Replace the session communication timeout
47
- def self.patch_comm_timeout! blob, comm_timeout
48
-
49
- i = blob.index([0xaf79257f].pack("V"))
50
- if i
51
- str = [ comm_timeout ].pack("V")
52
- blob[i, str.length] = str
53
- end
54
-
55
- end
56
-
57
- # Replace the user agent string with our option
58
- def self.patch_ua! blob, ua
59
-
60
- ua = ua[0,255] + "\x00"
61
- i = blob.index("METERPRETER_UA\x00")
62
- if i
63
- blob[i, ua.length] = ua
64
- end
65
-
66
- end
67
-
68
- # Activate a custom proxy
69
- def self.patch_proxy! blob, proxyhost, proxyport, proxy_type
70
-
71
- i = blob.index("METERPRETER_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
72
- if i
73
- if proxyhost
74
- if proxyhost.to_s != ""
75
- proxyhost = proxyhost.to_s
76
- proxyport = proxyport.to_s || "8080"
77
- proxyinfo = proxyhost + ":" + proxyport
78
- if proxyport == "80"
79
- proxyinfo = proxyhost
80
- end
81
- if proxy_type.to_s == 'HTTP'
82
- proxyinfo = 'http://' + proxyinfo
83
- else #socks
84
- proxyinfo = 'socks=' + proxyinfo
85
- end
86
- proxyinfo << "\x00"
87
- blob[i, proxyinfo.length] = proxyinfo
88
- end
89
- end
90
- end
91
-
92
- end
93
-
94
- # Proxy authentification
95
- def self.patch_proxy_auth! blob, proxy_username, proxy_password, proxy_type
96
-
97
- unless (proxy_username.nil? or proxy_username.empty?) or
98
- (proxy_password.nil? or proxy_password.empty?) or
99
- proxy_type == 'SOCKS'
100
-
101
- proxy_username_loc = blob.index("METERPRETER_USERNAME_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
102
- proxy_username = proxy_username << "\x00"
103
- blob[proxy_username_loc, proxy_username.length] = proxy_username
104
-
105
- proxy_password_loc = blob.index("METERPRETER_PASSWORD_PROXY\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00")
106
- proxy_password = proxy_password << "\x00"
107
- blob[proxy_password_loc, proxy_password.length] = proxy_password
108
- end
109
-
110
- end
111
-
112
- # Patch options into metsrv for reverse HTTP payloads
113
- def self.patch_passive_service! blob, options
114
-
115
- patch_transport! blob, options[:ssl]
116
- patch_url! blob, options[:url]
117
- patch_expiration! blob, options[:expiration]
118
- patch_comm_timeout! blob, options[:comm_timeout]
119
- patch_ua! blob, options[:ua]
120
- patch_proxy!(blob,
121
- options[:proxyhost],
122
- options[:proxyport],
123
- options[:proxy_type]
124
- )
125
- patch_proxy_auth!(blob,
126
- options[:proxy_username],
127
- options[:proxy_password],
128
- options[:proxy_type]
129
- )
130
-
131
- end
132
-
133
- end
134
- end
135
- end
136
- end