librex 0.0.1

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.
Files changed (370) hide show
  1. data/README +4 -0
  2. data/lib/rex.rb +101 -0
  3. data/lib/rex.rb.ts.rb +70 -0
  4. data/lib/rex/LICENSE +29 -0
  5. data/lib/rex/arch.rb +103 -0
  6. data/lib/rex/arch/sparc.rb +75 -0
  7. data/lib/rex/arch/sparc.rb.ut.rb +18 -0
  8. data/lib/rex/arch/x86.rb +513 -0
  9. data/lib/rex/arch/x86.rb.ut.rb +93 -0
  10. data/lib/rex/assembly/nasm.rb +100 -0
  11. data/lib/rex/assembly/nasm.rb.ut.rb +22 -0
  12. data/lib/rex/codepage.map +104 -0
  13. data/lib/rex/compat.rb +281 -0
  14. data/lib/rex/constants.rb +113 -0
  15. data/lib/rex/elfparsey.rb +11 -0
  16. data/lib/rex/elfparsey/elf.rb +123 -0
  17. data/lib/rex/elfparsey/elfbase.rb +260 -0
  18. data/lib/rex/elfparsey/exceptions.rb +27 -0
  19. data/lib/rex/elfscan.rb +12 -0
  20. data/lib/rex/elfscan/scanner.rb +207 -0
  21. data/lib/rex/elfscan/search.rb +46 -0
  22. data/lib/rex/encoder/alpha2.rb +31 -0
  23. data/lib/rex/encoder/alpha2/alpha_mixed.rb +68 -0
  24. data/lib/rex/encoder/alpha2/alpha_upper.rb +79 -0
  25. data/lib/rex/encoder/alpha2/generic.rb +113 -0
  26. data/lib/rex/encoder/alpha2/unicode_mixed.rb +117 -0
  27. data/lib/rex/encoder/alpha2/unicode_upper.rb +129 -0
  28. data/lib/rex/encoder/ndr.rb +89 -0
  29. data/lib/rex/encoder/ndr.rb.ut.rb +44 -0
  30. data/lib/rex/encoder/nonalpha.rb +61 -0
  31. data/lib/rex/encoder/nonupper.rb +64 -0
  32. data/lib/rex/encoder/xdr.rb +106 -0
  33. data/lib/rex/encoder/xdr.rb.ut.rb +29 -0
  34. data/lib/rex/encoder/xor.rb +69 -0
  35. data/lib/rex/encoder/xor/dword.rb +13 -0
  36. data/lib/rex/encoder/xor/dword_additive.rb +13 -0
  37. data/lib/rex/encoders/xor_dword.rb +35 -0
  38. data/lib/rex/encoders/xor_dword_additive.rb +53 -0
  39. data/lib/rex/encoders/xor_dword_additive.rb.ut.rb +12 -0
  40. data/lib/rex/encoding/xor.rb +20 -0
  41. data/lib/rex/encoding/xor.rb.ts.rb +14 -0
  42. data/lib/rex/encoding/xor/byte.rb +15 -0
  43. data/lib/rex/encoding/xor/byte.rb.ut.rb +21 -0
  44. data/lib/rex/encoding/xor/dword.rb +21 -0
  45. data/lib/rex/encoding/xor/dword.rb.ut.rb +15 -0
  46. data/lib/rex/encoding/xor/dword_additive.rb +92 -0
  47. data/lib/rex/encoding/xor/dword_additive.rb.ut.rb +15 -0
  48. data/lib/rex/encoding/xor/exceptions.rb +17 -0
  49. data/lib/rex/encoding/xor/generic.rb +146 -0
  50. data/lib/rex/encoding/xor/generic.rb.ut.rb +120 -0
  51. data/lib/rex/encoding/xor/qword.rb +15 -0
  52. data/lib/rex/encoding/xor/word.rb +21 -0
  53. data/lib/rex/encoding/xor/word.rb.ut.rb +13 -0
  54. data/lib/rex/exceptions.rb +275 -0
  55. data/lib/rex/exceptions.rb.ut.rb +44 -0
  56. data/lib/rex/exploitation/cmdstager.rb +133 -0
  57. data/lib/rex/exploitation/egghunter.rb +143 -0
  58. data/lib/rex/exploitation/egghunter.rb.ut.rb +25 -0
  59. data/lib/rex/exploitation/encryptjs.rb +77 -0
  60. data/lib/rex/exploitation/heaplib.js.b64 +331 -0
  61. data/lib/rex/exploitation/heaplib.rb +94 -0
  62. data/lib/rex/exploitation/javascriptosdetect.rb +735 -0
  63. data/lib/rex/exploitation/obfuscatejs.rb +335 -0
  64. data/lib/rex/exploitation/opcodedb.rb +818 -0
  65. data/lib/rex/exploitation/opcodedb.rb.ut.rb +279 -0
  66. data/lib/rex/exploitation/seh.rb +92 -0
  67. data/lib/rex/exploitation/seh.rb.ut.rb +19 -0
  68. data/lib/rex/file.rb +84 -0
  69. data/lib/rex/file.rb.ut.rb +16 -0
  70. data/lib/rex/image_source.rb +12 -0
  71. data/lib/rex/image_source/disk.rb +60 -0
  72. data/lib/rex/image_source/image_source.rb +46 -0
  73. data/lib/rex/image_source/memory.rb +37 -0
  74. data/lib/rex/io/bidirectional_pipe.rb +157 -0
  75. data/lib/rex/io/datagram_abstraction.rb +35 -0
  76. data/lib/rex/io/stream.rb +313 -0
  77. data/lib/rex/io/stream_abstraction.rb +186 -0
  78. data/lib/rex/io/stream_server.rb +211 -0
  79. data/lib/rex/job_container.rb +202 -0
  80. data/lib/rex/logging.rb +4 -0
  81. data/lib/rex/logging/log_dispatcher.rb +179 -0
  82. data/lib/rex/logging/log_sink.rb +42 -0
  83. data/lib/rex/logging/sinks/flatfile.rb +55 -0
  84. data/lib/rex/logging/sinks/stderr.rb +43 -0
  85. data/lib/rex/machparsey.rb +9 -0
  86. data/lib/rex/machparsey/exceptions.rb +34 -0
  87. data/lib/rex/machparsey/mach.rb +209 -0
  88. data/lib/rex/machparsey/machbase.rb +408 -0
  89. data/lib/rex/machscan.rb +9 -0
  90. data/lib/rex/machscan/scanner.rb +217 -0
  91. data/lib/rex/mime.rb +9 -0
  92. data/lib/rex/mime/header.rb +75 -0
  93. data/lib/rex/mime/message.rb +112 -0
  94. data/lib/rex/mime/part.rb +20 -0
  95. data/lib/rex/nop/opty2.rb +108 -0
  96. data/lib/rex/nop/opty2.rb.ut.rb +23 -0
  97. data/lib/rex/nop/opty2_tables.rb +300 -0
  98. data/lib/rex/ole.rb +128 -0
  99. data/lib/rex/ole/clsid.rb +47 -0
  100. data/lib/rex/ole/difat.rb +141 -0
  101. data/lib/rex/ole/directory.rb +230 -0
  102. data/lib/rex/ole/direntry.rb +240 -0
  103. data/lib/rex/ole/fat.rb +99 -0
  104. data/lib/rex/ole/header.rb +204 -0
  105. data/lib/rex/ole/minifat.rb +77 -0
  106. data/lib/rex/ole/samples/create_ole.rb +27 -0
  107. data/lib/rex/ole/samples/dir.rb +35 -0
  108. data/lib/rex/ole/samples/dump_stream.rb +34 -0
  109. data/lib/rex/ole/samples/ole_info.rb +23 -0
  110. data/lib/rex/ole/storage.rb +395 -0
  111. data/lib/rex/ole/stream.rb +53 -0
  112. data/lib/rex/ole/substorage.rb +49 -0
  113. data/lib/rex/ole/util.rb +157 -0
  114. data/lib/rex/parser/arguments.rb +97 -0
  115. data/lib/rex/parser/arguments.rb.ut.rb +67 -0
  116. data/lib/rex/parser/ini.rb +185 -0
  117. data/lib/rex/parser/ini.rb.ut.rb +29 -0
  118. data/lib/rex/parser/nmap_xml.rb +111 -0
  119. data/lib/rex/payloads.rb +1 -0
  120. data/lib/rex/payloads/win32.rb +2 -0
  121. data/lib/rex/payloads/win32/common.rb +26 -0
  122. data/lib/rex/payloads/win32/kernel.rb +53 -0
  123. data/lib/rex/payloads/win32/kernel/common.rb +54 -0
  124. data/lib/rex/payloads/win32/kernel/migration.rb +12 -0
  125. data/lib/rex/payloads/win32/kernel/recovery.rb +50 -0
  126. data/lib/rex/payloads/win32/kernel/stager.rb +171 -0
  127. data/lib/rex/peparsey.rb +12 -0
  128. data/lib/rex/peparsey/exceptions.rb +32 -0
  129. data/lib/rex/peparsey/pe.rb +188 -0
  130. data/lib/rex/peparsey/pe_memdump.rb +63 -0
  131. data/lib/rex/peparsey/pebase.rb +1655 -0
  132. data/lib/rex/peparsey/section.rb +136 -0
  133. data/lib/rex/pescan.rb +13 -0
  134. data/lib/rex/pescan/analyze.rb +309 -0
  135. data/lib/rex/pescan/scanner.rb +206 -0
  136. data/lib/rex/pescan/search.rb +56 -0
  137. data/lib/rex/platforms.rb +1 -0
  138. data/lib/rex/platforms/windows.rb +51 -0
  139. data/lib/rex/poly.rb +132 -0
  140. data/lib/rex/poly/block.rb +468 -0
  141. data/lib/rex/poly/register.rb +100 -0
  142. data/lib/rex/poly/register/x86.rb +40 -0
  143. data/lib/rex/post.rb +8 -0
  144. data/lib/rex/post/dir.rb +51 -0
  145. data/lib/rex/post/file.rb +172 -0
  146. data/lib/rex/post/file_stat.rb +220 -0
  147. data/lib/rex/post/gen.pl +13 -0
  148. data/lib/rex/post/io.rb +182 -0
  149. data/lib/rex/post/meterpreter.rb +4 -0
  150. data/lib/rex/post/meterpreter/channel.rb +438 -0
  151. data/lib/rex/post/meterpreter/channel_container.rb +54 -0
  152. data/lib/rex/post/meterpreter/channels/pool.rb +160 -0
  153. data/lib/rex/post/meterpreter/channels/pools/file.rb +62 -0
  154. data/lib/rex/post/meterpreter/channels/pools/stream_pool.rb +103 -0
  155. data/lib/rex/post/meterpreter/channels/stream.rb +87 -0
  156. data/lib/rex/post/meterpreter/client.rb +335 -0
  157. data/lib/rex/post/meterpreter/client_core.rb +274 -0
  158. data/lib/rex/post/meterpreter/dependencies.rb +3 -0
  159. data/lib/rex/post/meterpreter/extension.rb +32 -0
  160. data/lib/rex/post/meterpreter/extensions/espia/espia.rb +58 -0
  161. data/lib/rex/post/meterpreter/extensions/espia/tlv.rb +16 -0
  162. data/lib/rex/post/meterpreter/extensions/incognito/incognito.rb +94 -0
  163. data/lib/rex/post/meterpreter/extensions/incognito/tlv.rb +21 -0
  164. data/lib/rex/post/meterpreter/extensions/priv/fs.rb +118 -0
  165. data/lib/rex/post/meterpreter/extensions/priv/passwd.rb +61 -0
  166. data/lib/rex/post/meterpreter/extensions/priv/priv.rb +104 -0
  167. data/lib/rex/post/meterpreter/extensions/priv/tlv.rb +28 -0
  168. data/lib/rex/post/meterpreter/extensions/sniffer/sniffer.rb +100 -0
  169. data/lib/rex/post/meterpreter/extensions/sniffer/tlv.rb +24 -0
  170. data/lib/rex/post/meterpreter/extensions/stdapi/constants.rb +333 -0
  171. data/lib/rex/post/meterpreter/extensions/stdapi/fs/dir.rb +273 -0
  172. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file.rb +235 -0
  173. data/lib/rex/post/meterpreter/extensions/stdapi/fs/file_stat.rb +103 -0
  174. data/lib/rex/post/meterpreter/extensions/stdapi/fs/io.rb +48 -0
  175. data/lib/rex/post/meterpreter/extensions/stdapi/net/config.rb +144 -0
  176. data/lib/rex/post/meterpreter/extensions/stdapi/net/interface.rb +73 -0
  177. data/lib/rex/post/meterpreter/extensions/stdapi/net/route.rb +56 -0
  178. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket.rb +137 -0
  179. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_client_channel.rb +167 -0
  180. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/tcp_server_channel.rb +167 -0
  181. data/lib/rex/post/meterpreter/extensions/stdapi/net/socket_subsystem/udp_channel.rb +192 -0
  182. data/lib/rex/post/meterpreter/extensions/stdapi/stdapi.rb +139 -0
  183. data/lib/rex/post/meterpreter/extensions/stdapi/sys/config.rb +97 -0
  184. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log.rb +184 -0
  185. data/lib/rex/post/meterpreter/extensions/stdapi/sys/event_log_subsystem/event_record.rb +41 -0
  186. data/lib/rex/post/meterpreter/extensions/stdapi/sys/power.rb +61 -0
  187. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process.rb +361 -0
  188. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/image.rb +129 -0
  189. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/io.rb +55 -0
  190. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/memory.rb +336 -0
  191. data/lib/rex/post/meterpreter/extensions/stdapi/sys/process_subsystem/thread.rb +141 -0
  192. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry.rb +279 -0
  193. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_key.rb +182 -0
  194. data/lib/rex/post/meterpreter/extensions/stdapi/sys/registry_subsystem/registry_value.rb +102 -0
  195. data/lib/rex/post/meterpreter/extensions/stdapi/sys/thread.rb +174 -0
  196. data/lib/rex/post/meterpreter/extensions/stdapi/tlv.rb +185 -0
  197. data/lib/rex/post/meterpreter/extensions/stdapi/ui.rb +227 -0
  198. data/lib/rex/post/meterpreter/inbound_packet_handler.rb +30 -0
  199. data/lib/rex/post/meterpreter/object_aliases.rb +83 -0
  200. data/lib/rex/post/meterpreter/packet.rb +596 -0
  201. data/lib/rex/post/meterpreter/packet_dispatcher.rb +409 -0
  202. data/lib/rex/post/meterpreter/packet_parser.rb +94 -0
  203. data/lib/rex/post/meterpreter/packet_response_waiter.rb +83 -0
  204. data/lib/rex/post/meterpreter/ui/console.rb +135 -0
  205. data/lib/rex/post/meterpreter/ui/console/command_dispatcher.rb +62 -0
  206. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/core.rb +595 -0
  207. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/espia.rb +108 -0
  208. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/incognito.rb +241 -0
  209. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv.rb +61 -0
  210. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/elevate.rb +98 -0
  211. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/passwd.rb +51 -0
  212. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/priv/timestomp.rb +132 -0
  213. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/sniffer.rb +187 -0
  214. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi.rb +63 -0
  215. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/fs.rb +376 -0
  216. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/net.rb +270 -0
  217. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/sys.rb +484 -0
  218. data/lib/rex/post/meterpreter/ui/console/command_dispatcher/stdapi/ui.rb +315 -0
  219. data/lib/rex/post/meterpreter/ui/console/interactive_channel.rb +95 -0
  220. data/lib/rex/post/permission.rb +26 -0
  221. data/lib/rex/post/process.rb +57 -0
  222. data/lib/rex/post/thread.rb +57 -0
  223. data/lib/rex/post/ui.rb +52 -0
  224. data/lib/rex/proto.rb +12 -0
  225. data/lib/rex/proto.rb.ts.rb +8 -0
  226. data/lib/rex/proto/dcerpc.rb +6 -0
  227. data/lib/rex/proto/dcerpc.rb.ts.rb +9 -0
  228. data/lib/rex/proto/dcerpc/client.rb +358 -0
  229. data/lib/rex/proto/dcerpc/client.rb.ut.rb +491 -0
  230. data/lib/rex/proto/dcerpc/exceptions.rb +150 -0
  231. data/lib/rex/proto/dcerpc/handle.rb +47 -0
  232. data/lib/rex/proto/dcerpc/handle.rb.ut.rb +85 -0
  233. data/lib/rex/proto/dcerpc/ndr.rb +72 -0
  234. data/lib/rex/proto/dcerpc/ndr.rb.ut.rb +41 -0
  235. data/lib/rex/proto/dcerpc/packet.rb +253 -0
  236. data/lib/rex/proto/dcerpc/packet.rb.ut.rb +56 -0
  237. data/lib/rex/proto/dcerpc/response.rb +186 -0
  238. data/lib/rex/proto/dcerpc/response.rb.ut.rb +15 -0
  239. data/lib/rex/proto/dcerpc/uuid.rb +84 -0
  240. data/lib/rex/proto/dcerpc/uuid.rb.ut.rb +46 -0
  241. data/lib/rex/proto/drda.rb +5 -0
  242. data/lib/rex/proto/drda.rb.ts.rb +17 -0
  243. data/lib/rex/proto/drda/constants.rb +49 -0
  244. data/lib/rex/proto/drda/constants.rb.ut.rb +23 -0
  245. data/lib/rex/proto/drda/packet.rb +252 -0
  246. data/lib/rex/proto/drda/packet.rb.ut.rb +109 -0
  247. data/lib/rex/proto/drda/utils.rb +123 -0
  248. data/lib/rex/proto/drda/utils.rb.ut.rb +84 -0
  249. data/lib/rex/proto/http.rb +5 -0
  250. data/lib/rex/proto/http.rb.ts.rb +12 -0
  251. data/lib/rex/proto/http/client.rb +817 -0
  252. data/lib/rex/proto/http/client.rb.ut.rb +93 -0
  253. data/lib/rex/proto/http/handler.rb +46 -0
  254. data/lib/rex/proto/http/handler/erb.rb +128 -0
  255. data/lib/rex/proto/http/handler/erb.rb.ut.rb +21 -0
  256. data/lib/rex/proto/http/handler/erb.rb.ut.rb.rhtml +1 -0
  257. data/lib/rex/proto/http/handler/proc.rb +54 -0
  258. data/lib/rex/proto/http/handler/proc.rb.ut.rb +24 -0
  259. data/lib/rex/proto/http/header.rb +161 -0
  260. data/lib/rex/proto/http/header.rb.ut.rb +46 -0
  261. data/lib/rex/proto/http/packet.rb +394 -0
  262. data/lib/rex/proto/http/packet.rb.ut.rb +165 -0
  263. data/lib/rex/proto/http/request.rb +356 -0
  264. data/lib/rex/proto/http/request.rb.ut.rb +214 -0
  265. data/lib/rex/proto/http/response.rb +85 -0
  266. data/lib/rex/proto/http/response.rb.ut.rb +149 -0
  267. data/lib/rex/proto/http/server.rb +367 -0
  268. data/lib/rex/proto/http/server.rb.ut.rb +79 -0
  269. data/lib/rex/proto/smb.rb +7 -0
  270. data/lib/rex/proto/smb.rb.ts.rb +8 -0
  271. data/lib/rex/proto/smb/client.rb +1733 -0
  272. data/lib/rex/proto/smb/client.rb.ut.rb +223 -0
  273. data/lib/rex/proto/smb/constants.rb +1062 -0
  274. data/lib/rex/proto/smb/constants.rb.ut.rb +18 -0
  275. data/lib/rex/proto/smb/crypt.rb +95 -0
  276. data/lib/rex/proto/smb/crypt.rb.ut.rb +20 -0
  277. data/lib/rex/proto/smb/evasions.rb +65 -0
  278. data/lib/rex/proto/smb/exceptions.rb +846 -0
  279. data/lib/rex/proto/smb/simpleclient.rb +292 -0
  280. data/lib/rex/proto/smb/simpleclient.rb.ut.rb +128 -0
  281. data/lib/rex/proto/smb/utils.rb +514 -0
  282. data/lib/rex/proto/smb/utils.rb.ut.rb +20 -0
  283. data/lib/rex/proto/sunrpc.rb +1 -0
  284. data/lib/rex/proto/sunrpc/client.rb +195 -0
  285. data/lib/rex/script.rb +42 -0
  286. data/lib/rex/script/base.rb +59 -0
  287. data/lib/rex/script/meterpreter.rb +9 -0
  288. data/lib/rex/script/shell.rb +9 -0
  289. data/lib/rex/service.rb +48 -0
  290. data/lib/rex/service_manager.rb +141 -0
  291. data/lib/rex/service_manager.rb.ut.rb +32 -0
  292. data/lib/rex/services/local_relay.rb +423 -0
  293. data/lib/rex/socket.rb +586 -0
  294. data/lib/rex/socket.rb.ut.rb +86 -0
  295. data/lib/rex/socket/comm.rb +119 -0
  296. data/lib/rex/socket/comm/local.rb +409 -0
  297. data/lib/rex/socket/comm/local.rb.ut.rb +75 -0
  298. data/lib/rex/socket/ip.rb +129 -0
  299. data/lib/rex/socket/parameters.rb +345 -0
  300. data/lib/rex/socket/parameters.rb.ut.rb +51 -0
  301. data/lib/rex/socket/range_walker.rb +295 -0
  302. data/lib/rex/socket/range_walker.rb.ut.rb +55 -0
  303. data/lib/rex/socket/ssl_tcp.rb +184 -0
  304. data/lib/rex/socket/ssl_tcp.rb.ut.rb +39 -0
  305. data/lib/rex/socket/ssl_tcp_server.rb +122 -0
  306. data/lib/rex/socket/ssl_tcp_server.rb.ut.rb +51 -0
  307. data/lib/rex/socket/subnet_walker.rb +75 -0
  308. data/lib/rex/socket/subnet_walker.rb.ut.rb +28 -0
  309. data/lib/rex/socket/switch_board.rb +272 -0
  310. data/lib/rex/socket/switch_board.rb.ut.rb +52 -0
  311. data/lib/rex/socket/tcp.rb +76 -0
  312. data/lib/rex/socket/tcp.rb.ut.rb +64 -0
  313. data/lib/rex/socket/tcp_server.rb +67 -0
  314. data/lib/rex/socket/tcp_server.rb.ut.rb +44 -0
  315. data/lib/rex/socket/udp.rb +157 -0
  316. data/lib/rex/socket/udp.rb.ut.rb +44 -0
  317. data/lib/rex/struct2.rb +5 -0
  318. data/lib/rex/struct2/c_struct.rb +181 -0
  319. data/lib/rex/struct2/c_struct_template.rb +39 -0
  320. data/lib/rex/struct2/constant.rb +26 -0
  321. data/lib/rex/struct2/element.rb +44 -0
  322. data/lib/rex/struct2/generic.rb +73 -0
  323. data/lib/rex/struct2/restraint.rb +54 -0
  324. data/lib/rex/struct2/s_string.rb +72 -0
  325. data/lib/rex/struct2/s_struct.rb +111 -0
  326. data/lib/rex/sync.rb +6 -0
  327. data/lib/rex/sync/event.rb +94 -0
  328. data/lib/rex/sync/read_write_lock.rb +176 -0
  329. data/lib/rex/sync/ref.rb +57 -0
  330. data/lib/rex/sync/thread_safe.rb +82 -0
  331. data/lib/rex/test.rb +35 -0
  332. data/lib/rex/text.rb +1029 -0
  333. data/lib/rex/text.rb.ut.rb +168 -0
  334. data/lib/rex/time.rb +65 -0
  335. data/lib/rex/transformer.rb +115 -0
  336. data/lib/rex/transformer.rb.ut.rb +38 -0
  337. data/lib/rex/ui.rb +21 -0
  338. data/lib/rex/ui/interactive.rb +252 -0
  339. data/lib/rex/ui/output.rb +80 -0
  340. data/lib/rex/ui/output/none.rb +18 -0
  341. data/lib/rex/ui/progress_tracker.rb +96 -0
  342. data/lib/rex/ui/subscriber.rb +149 -0
  343. data/lib/rex/ui/text/color.rb +97 -0
  344. data/lib/rex/ui/text/color.rb.ut.rb +18 -0
  345. data/lib/rex/ui/text/dispatcher_shell.rb +382 -0
  346. data/lib/rex/ui/text/input.rb +117 -0
  347. data/lib/rex/ui/text/input/buffer.rb +75 -0
  348. data/lib/rex/ui/text/input/readline.rb +129 -0
  349. data/lib/rex/ui/text/input/socket.rb +95 -0
  350. data/lib/rex/ui/text/input/stdio.rb +45 -0
  351. data/lib/rex/ui/text/irb_shell.rb +55 -0
  352. data/lib/rex/ui/text/output.rb +80 -0
  353. data/lib/rex/ui/text/output/buffer.rb +65 -0
  354. data/lib/rex/ui/text/output/file.rb +37 -0
  355. data/lib/rex/ui/text/output/socket.rb +43 -0
  356. data/lib/rex/ui/text/output/stdio.rb +40 -0
  357. data/lib/rex/ui/text/progress_tracker.rb +56 -0
  358. data/lib/rex/ui/text/progress_tracker.rb.ut.rb +34 -0
  359. data/lib/rex/ui/text/shell.rb +321 -0
  360. data/lib/rex/ui/text/table.rb +254 -0
  361. data/lib/rex/ui/text/table.rb.ut.rb +55 -0
  362. data/lib/rex/zip.rb +93 -0
  363. data/lib/rex/zip/archive.rb +91 -0
  364. data/lib/rex/zip/blocks.rb +182 -0
  365. data/lib/rex/zip/entry.rb +95 -0
  366. data/lib/rex/zip/samples/comment.rb +32 -0
  367. data/lib/rex/zip/samples/mkwar.rb +138 -0
  368. data/lib/rex/zip/samples/mkzip.rb +19 -0
  369. data/lib/rex/zip/samples/recursive.rb +58 -0
  370. metadata +435 -0
@@ -0,0 +1,84 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), '..', '..', '..'))
4
+
5
+ require 'rex/test'
6
+ require 'rex/proto/drda/utils'
7
+ require 'rex/socket'
8
+
9
+ class Rex::Proto::DRDA::Utils::UnitTest < Test::Unit::TestCase
10
+
11
+ Klass = Rex::Proto::DRDA
12
+
13
+ def test_socket_connectivity
14
+ assert_nothing_raised do
15
+ socket = Rex::Socket.create_tcp(
16
+ 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s, # PeerHost can be nil!
17
+ 'PeerPort' => 50000
18
+ )
19
+ assert_kind_of Socket, socket
20
+ assert !socket.closed?
21
+ socket.close
22
+ assert socket.closed?
23
+ end
24
+ end
25
+
26
+ def test_client_probe_create
27
+ probe_pkt = Klass::Utils.client_probe
28
+ assert_equal 54, probe_pkt.size
29
+ end
30
+
31
+ def test_client_probe
32
+ probe_pkt = Klass::Utils.client_probe('toolsdb')
33
+ begin
34
+ Timeout.timeout($_REX_TEST_TIMEOUT) do
35
+ socket = Rex::Socket.create_tcp(
36
+ 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s,
37
+ 'PeerPort' => 50000
38
+ )
39
+ sent = socket.put probe_pkt
40
+ assert_equal 76, sent
41
+ probe_reply = socket.get_once
42
+ assert_operator probe_reply.size, :>=, 10
43
+ parsed_reply = Klass::SERVER_PACKET.new.read probe_reply
44
+ assert_kind_of Array, parsed_reply
45
+ assert_equal parsed_reply[0].codepoint, Klass::Constants::EXCSATRD
46
+ socket.close
47
+ end
48
+ rescue Timeout::Error
49
+ flunk("Timed out")
50
+ end
51
+ end
52
+
53
+ # Client auth requires a successful probe. This is a complete authentication
54
+ # sequence, culminating in info[:db_login_sucess] returning either true or
55
+ # false.
56
+ def test_client_auth
57
+ probe_pkt = Klass::Utils.client_probe('toolsdb')
58
+ auth_pkt = Klass::Utils.client_auth(:dbname => 'toolsdb',
59
+ :dbuser => $_REX_TEST_DRDA_USER.to_s,
60
+ :dbpass => $_REX_TEST_DRDA_PASS.to_s
61
+ )
62
+ begin
63
+ Timeout.timeout($_REX_TEST_TIMEOUT) do
64
+ socket = Rex::Socket.create_tcp(
65
+ 'PeerHost' => $_REX_TEST_DRDA_HOST.to_s,
66
+ 'PeerPort' => 50000
67
+ )
68
+ sent = socket.put probe_pkt
69
+ probe_reply = socket.get_once
70
+ sent = socket.put auth_pkt
71
+ assert_equal(75, sent)
72
+ auth_reply = socket.get_once
73
+ parsed_auth_reply = Klass::SERVER_PACKET.new.read auth_reply
74
+ info = Klass::Utils.server_packet_info(parsed_auth_reply)
75
+ assert info[:db_login_success]
76
+ socket.close
77
+ end
78
+ rescue Timeout::Error
79
+ flunk("Timed out")
80
+ end
81
+ end
82
+
83
+ end
84
+
@@ -0,0 +1,5 @@
1
+ require 'rex/proto/http/packet'
2
+ require 'rex/proto/http/request'
3
+ require 'rex/proto/http/response'
4
+ require 'rex/proto/http/client'
5
+ require 'rex/proto/http/server'
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'test/unit'
4
+
5
+ require 'rex/proto/http/client.rb.ut'
6
+ require 'rex/proto/http/server.rb.ut'
7
+ require 'rex/proto/http/packet.rb.ut'
8
+ require 'rex/proto/http/header.rb.ut'
9
+ require 'rex/proto/http/request.rb.ut'
10
+ require 'rex/proto/http/response.rb.ut'
11
+ require 'rex/proto/http/handler/erb.rb.ut'
12
+ require 'rex/proto/http/handler/proc.rb.ut'
@@ -0,0 +1,817 @@
1
+ require 'rex/socket'
2
+ require 'rex/proto/http'
3
+ require 'rex/text'
4
+
5
+ module Rex
6
+ module Proto
7
+ module Http
8
+
9
+ ###
10
+ #
11
+ # Acts as a client to an HTTP server, sending requests and receiving
12
+ # responses.
13
+ #
14
+ ###
15
+ class Client
16
+
17
+ #
18
+ # Creates a new client instance
19
+ #
20
+ def initialize(host, port = 80, context = {}, ssl = nil, ssl_version = nil, proxies = nil)
21
+ self.hostname = host
22
+ self.port = port.to_i
23
+ self.context = context
24
+ self.ssl = ssl
25
+ self.ssl_version = ssl_version
26
+ self.proxies = proxies
27
+ self.config = {
28
+ 'read_max_data' => (1024*1024*1),
29
+ 'vhost' => self.hostname,
30
+ 'version' => '1.1',
31
+ 'agent' => "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)",
32
+ #
33
+ # Evasion options
34
+ #
35
+ 'uri_encode_mode' => 'hex-normal', # hex-all, hex-random, u-normal, u-random, u-all
36
+ 'uri_encode_count' => 1, # integer
37
+ 'uri_full_url' => false, # bool
38
+ 'pad_method_uri_count' => 1, # integer
39
+ 'pad_uri_version_count' => 1, # integer
40
+ 'pad_method_uri_type' => 'space', # space, tab, apache
41
+ 'pad_uri_version_type' => 'space', # space, tab, apache
42
+ 'method_random_valid' => false, # bool
43
+ 'method_random_invalid' => false, # bool
44
+ 'method_random_case' => false, # bool
45
+ 'version_random_valid' => false, # bool
46
+ 'version_random_invalid' => false, # bool
47
+ 'version_random_case' => false, # bool
48
+ 'uri_dir_self_reference' => false, # bool
49
+ 'uri_dir_fake_relative' => false, # bool
50
+ 'uri_use_backslashes' => false, # bool
51
+ 'pad_fake_headers' => false, # bool
52
+ 'pad_fake_headers_count' => 16, # integer
53
+ 'pad_get_params' => false, # bool
54
+ 'pad_get_params_count' => 8, # integer
55
+ 'pad_post_params' => false, # bool
56
+ 'pad_post_params_count' => 8, # integer
57
+ 'uri_fake_end' => false, # bool
58
+ 'uri_fake_params_start' => false, # bool
59
+ 'header_folding' => false, # bool
60
+ 'chunked_size' => 0 # integer
61
+ }
62
+
63
+ # This is not used right now...
64
+ self.config_types = {
65
+ 'uri_encode_mode' => ['hex-normal', 'hex-all', 'hex-random', 'u-normal', 'u-random', 'u-all'],
66
+ 'uri_encode_count' => 'integer',
67
+ 'uri_full_url' => 'bool',
68
+ 'pad_method_uri_count' => 'integer',
69
+ 'pad_uri_version_count' => 'integer',
70
+ 'pad_method_uri_type' => ['space', 'tab', 'apache'],
71
+ 'pad_uri_version_type' => ['space', 'tab', 'apache'],
72
+ 'method_random_valid' => 'bool',
73
+ 'method_random_invalid' => 'bool',
74
+ 'method_random_case' => 'bool',
75
+ 'version_random_valid' => 'bool',
76
+ 'version_random_invalid' => 'bool',
77
+ 'version_random_case' => 'bool',
78
+ 'uri_dir_self_reference' => 'bool',
79
+ 'uri_dir_fake_relative' => 'bool',
80
+ 'uri_use_backslashes' => 'bool',
81
+ 'pad_fake_headers' => 'bool',
82
+ 'pad_fake_headers_count' => 'integer',
83
+ 'pad_get_params' => 'bool',
84
+ 'pad_get_params_count' => 'integer',
85
+ 'pad_post_params' => 'bool',
86
+ 'pad_post_params_count' => 'integer',
87
+ 'uri_fake_end' => 'bool',
88
+ 'uri_fake_params_start' => 'bool',
89
+ 'header_folding' => 'bool',
90
+ 'chunked_size' => 'integer'
91
+ }
92
+ end
93
+
94
+ #
95
+ # Set configuration options
96
+ #
97
+ def set_config(opts = {})
98
+ opts.each_pair do |var,val|
99
+ typ = self.config_types[var] || 'string'
100
+
101
+ if(typ.class.to_s == 'Array')
102
+ if not typ.include?(val)
103
+ raise RuntimeError, "The specified value for #{var} is not one of the valid choices"
104
+ end
105
+ end
106
+
107
+ if(typ == 'bool')
108
+ val = (val =~ /^(t|y|1)$/i ? true : false)
109
+ end
110
+
111
+ if(typ == 'integer')
112
+ val = val.to_i
113
+ end
114
+
115
+ self.config[var]=val
116
+ end
117
+
118
+ end
119
+
120
+ #
121
+ # Create an arbitrary HTTP request
122
+ #
123
+ def request_raw(opts={})
124
+ c_enc = opts['encode'] || false
125
+ c_uri = opts['uri'] || '/'
126
+ c_body = opts['data'] || ''
127
+ c_meth = opts['method'] || 'GET'
128
+ c_prot = opts['proto'] || 'HTTP'
129
+ c_vers = opts['version'] || config['version'] || '1.1'
130
+ c_qs = opts['query']
131
+ c_ag = opts['agent'] || config['agent']
132
+ c_cook = opts['cookie'] || config['cookie']
133
+ c_host = opts['vhost'] || config['vhost'] || self.hostname
134
+ c_head = opts['headers'] || config['headers'] || {}
135
+ c_rawh = opts['raw_headers']|| config['raw_headers'] || ''
136
+ c_conn = opts['connection']
137
+ c_auth = opts['basic_auth'] || config['basic_auth'] || ''
138
+
139
+ uri = set_uri(c_uri)
140
+
141
+ req = ''
142
+ req << set_method(c_meth)
143
+ req << set_method_uri_spacer()
144
+ req << set_uri_prepend()
145
+ req << (c_enc ? set_encode_uri(uri) : uri)
146
+
147
+ if (c_qs)
148
+ req << '?'
149
+ req << (c_enc ? set_encode_qs(c_qs) : c_qs)
150
+ end
151
+
152
+ req << set_uri_append()
153
+ req << set_uri_version_spacer()
154
+ req << set_version(c_prot, c_vers)
155
+ req << set_host_header(c_host)
156
+ req << set_agent_header(c_ag)
157
+
158
+ if (c_auth.length > 0)
159
+ req << set_basic_auth_header(c_auth)
160
+ end
161
+
162
+ req << set_cookie_header(c_cook)
163
+ req << set_connection_header(c_conn)
164
+ req << set_extra_headers(c_head)
165
+ req << set_raw_headers(c_rawh)
166
+ req << set_body(c_body)
167
+
168
+ req
169
+ end
170
+
171
+
172
+ #
173
+ # Create a CGI compatible request
174
+ #
175
+ def request_cgi(opts={})
176
+ c_enc = opts['encode'] || false
177
+ c_cgi = opts['uri'] || '/'
178
+ c_body = opts['data'] || ''
179
+ c_meth = opts['method'] || 'GET'
180
+ c_prot = opts['proto'] || 'HTTP'
181
+ c_vers = opts['version'] || config['version'] || '1.1'
182
+ c_qs = opts['query'] || ''
183
+ c_varg = opts['vars_get'] || {}
184
+ c_varp = opts['vars_post'] || {}
185
+ c_head = opts['headers'] || config['headers'] || {}
186
+ c_rawh = opts['raw_headers']|| config['raw_headers'] || ''
187
+ c_type = opts['ctype'] || 'application/x-www-form-urlencoded'
188
+ c_ag = opts['agent'] || config['agent']
189
+ c_cook = opts['cookie'] || config['cookie']
190
+ c_host = opts['vhost'] || config['vhost']
191
+ c_conn = opts['connection']
192
+ c_path = opts['path_info']
193
+ c_auth = opts['basic_auth'] || config['basic_auth'] || ''
194
+
195
+ uri = set_cgi(c_cgi)
196
+ qstr = c_qs
197
+ pstr = c_body
198
+
199
+ if (config['pad_get_params'])
200
+ 1.upto(config['pad_get_params_count'].to_i) do |i|
201
+ qstr << '&' if qstr.length > 0
202
+ qstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
203
+ qstr << '='
204
+ qstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
205
+ end
206
+ end
207
+
208
+ c_varg.each_pair do |var,val|
209
+ qstr << '&' if qstr.length > 0
210
+ qstr << set_encode_uri(var)
211
+ qstr << '='
212
+ qstr << set_encode_uri(val)
213
+ end
214
+
215
+ if (config['pad_post_params'])
216
+ 1.upto(config['pad_post_params_count'].to_i) do |i|
217
+ pstr << '&' if qstr.length > 0
218
+ pstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
219
+ pstr << '='
220
+ pstr << set_encode_uri(Rex::Text.rand_text_alphanumeric(rand(32)+1))
221
+ end
222
+ end
223
+
224
+ c_varp.each_pair do |var,val|
225
+ pstr << '&' if pstr.length > 0
226
+ pstr << set_encode_uri(var)
227
+ pstr << '='
228
+ pstr << set_encode_uri(val)
229
+ end
230
+
231
+ req = ''
232
+ req << set_method(c_meth)
233
+ req << set_method_uri_spacer()
234
+ req << set_uri_prepend()
235
+ req << (c_enc ? set_encode_uri(uri):uri)
236
+
237
+ if (qstr.length > 0)
238
+ req << '?'
239
+ req << qstr
240
+ end
241
+
242
+ req << set_path_info(c_path)
243
+ req << set_uri_append()
244
+ req << set_uri_version_spacer()
245
+ req << set_version(c_prot, c_vers)
246
+ req << set_host_header(c_host)
247
+ req << set_agent_header(c_ag)
248
+
249
+ if (c_auth.length > 0)
250
+ req << set_basic_auth_header(c_auth)
251
+ end
252
+
253
+ req << set_cookie_header(c_cook)
254
+ req << set_connection_header(c_conn)
255
+ req << set_extra_headers(c_head)
256
+
257
+ req << set_content_type_header(c_type)
258
+ req << set_content_len_header(pstr.length)
259
+ req << set_chunked_header()
260
+ req << set_raw_headers(c_rawh)
261
+ req << set_body(pstr)
262
+
263
+ req
264
+ end
265
+
266
+ #
267
+ # Connects to the remote server if possible.
268
+ #
269
+ def connect
270
+ # If we already have a connection and we aren't pipelining, close it.
271
+ if (self.conn)
272
+ if !pipelining?
273
+ close
274
+ else
275
+ return self.conn
276
+ end
277
+ end
278
+
279
+ self.conn = Rex::Socket::Tcp.create(
280
+ 'PeerHost' => self.hostname,
281
+ 'PeerPort' => self.port.to_i,
282
+ 'LocalHost' => self.local_host,
283
+ 'LocalPort' => self.local_port,
284
+ 'Context' => self.context,
285
+ 'SSL' => self.ssl,
286
+ 'SSLVersion'=> self.ssl_version,
287
+ 'Proxies' => self.proxies
288
+ )
289
+ end
290
+
291
+ #
292
+ # Closes the connection to the remote server.
293
+ #
294
+ def close
295
+ if (self.conn)
296
+ self.conn.shutdown
297
+ self.conn.close
298
+ end
299
+
300
+ self.conn = nil
301
+ end
302
+
303
+ #
304
+ # Transmit a HTTP request and receive the response
305
+ #
306
+ def send_recv(req, t = -1)
307
+ send_request(req)
308
+ read_response(t)
309
+ end
310
+
311
+ #
312
+ # Send a HTTP request to the server
313
+ #
314
+ def send_request(req)
315
+ connect
316
+ conn.put(req.to_s)
317
+ end
318
+
319
+ #
320
+ # Read a response from the server
321
+ #
322
+ def read_response(t = -1)
323
+
324
+ resp = Response.new
325
+ resp.max_data = config['read_max_data']
326
+
327
+ # Wait at most t seconds for the full response to be read in. We only
328
+ # do this if t was specified as a negative value indicating an infinite
329
+ # wait cycle. If t were specified as nil it would indicate that no
330
+ # response parsing is required.
331
+
332
+ return resp if not t
333
+
334
+ Timeout.timeout((t < 0) ? nil : t) do
335
+
336
+ rv = nil
337
+ while (
338
+ rv != Packet::ParseCode::Completed and
339
+ rv != Packet::ParseCode::Error
340
+ )
341
+ begin
342
+ buff = conn.get_once(-1, 1)
343
+ rv = resp.parse( buff || '')
344
+
345
+ # Handle unexpected disconnects
346
+ rescue ::Errno::EPIPE, ::EOFError, ::IOError
347
+ case resp.state
348
+ when Packet::ParseState::ProcessingHeader
349
+ resp = nil
350
+ when Packet::ParseState::ProcessingBody
351
+ # truncated request, good enough
352
+ resp.error = :truncated
353
+ end
354
+ break
355
+ end
356
+
357
+ # This is a dirty hack for broken HTTP servers
358
+ if rv == Packet::ParseCode::Completed
359
+ rbody = resp.body
360
+ rbufq = resp.bufq
361
+
362
+ rblob = rbody.to_s + rbufq.to_s
363
+ tries = 0
364
+ begin
365
+ while tries < 20 and resp.headers["Content-Type"]== "text/html" and rblob !~ /<\/html>/i
366
+ buff = conn.get_once(-1, 0.05)
367
+ break if not buff
368
+ rblob += buff
369
+ end
370
+ rescue ::Errno::EPIPE, ::EOFError, ::IOError
371
+ end
372
+
373
+ resp.bufq = ""
374
+ resp.body = rblob
375
+ end
376
+ end
377
+ end
378
+ resp
379
+ end
380
+
381
+ #
382
+ # Read a response from the server (starting with existing data)
383
+ #
384
+ def reread_response(resp, t = -1)
385
+
386
+ resp.max_data = config['read_max_data']
387
+ resp.reset_except_queue
388
+ resp.parse('')
389
+
390
+ # Wait at most t seconds for the full response to be read in. We only
391
+ # do this if t was specified as a negative value indicating an infinite
392
+ # wait cycle. If t were specified as nil it would indicate that no
393
+ # response parsing is required.
394
+
395
+ return resp if not t
396
+
397
+ Timeout.timeout((t < 0) ? nil : t) do
398
+
399
+ rv = resp.state
400
+
401
+ while (
402
+ rv != Packet::ParseCode::Completed and
403
+ rv != Packet::ParseCode::Error
404
+ )
405
+ begin
406
+ buff = conn.get
407
+ rv = resp.parse( buff || '')
408
+
409
+ # Handle unexpected disconnects
410
+ rescue ::Errno::EPIPE, ::EOFError, ::IOError
411
+ case resp.state
412
+ when Packet::ParseState::ProcessingHeader
413
+ resp = nil
414
+ when Packet::ParseState::ProcessingBody
415
+ # truncated request, good enough
416
+ resp.error = :truncated
417
+ end
418
+ break
419
+ end
420
+ end
421
+ end
422
+ resp
423
+ end
424
+
425
+ #
426
+ # Cleans up any outstanding connections and other resources.
427
+ #
428
+ def stop
429
+ close
430
+ end
431
+
432
+ #
433
+ # Returns whether or not the conn is valid.
434
+ #
435
+ def conn?
436
+ conn != nil
437
+ end
438
+
439
+ #
440
+ # Whether or not connections should be pipelined.
441
+ #
442
+ def pipelining?
443
+ pipeline
444
+ end
445
+
446
+ #
447
+ # Return the encoded URI
448
+ # ['none','hex-normal', 'hex-all', 'u-normal', 'u-all']
449
+ def set_encode_uri(uri)
450
+ a = uri
451
+ self.config['uri_encode_count'].times {
452
+ a = Rex::Text.uri_encode(a, self.config['uri_encode_mode'])
453
+ }
454
+ return a
455
+ end
456
+
457
+ #
458
+ # Return the encoded query string
459
+ #
460
+ def set_encode_qs(qs)
461
+ a = qs
462
+ self.config['uri_encode_count'].times {
463
+ a = Rex::Text.uri_encode(a, self.config['uri_encode_mode'])
464
+ }
465
+ return a
466
+ end
467
+
468
+ #
469
+ # Return the uri
470
+ #
471
+ def set_uri(uri)
472
+
473
+ if (self.config['uri_dir_self_reference'])
474
+ uri.gsub!('/', '/./')
475
+ end
476
+
477
+ if (self.config['uri_dir_fake_relative'])
478
+ buf = ""
479
+ uri.split('/').each do |part|
480
+ cnt = rand(8)+2
481
+ 1.upto(cnt) { |idx|
482
+ buf << "/" + Rex::Text.rand_text_alphanumeric(rand(32)+1)
483
+ }
484
+ buf << ("/.." * cnt)
485
+ buf << "/" + part
486
+ end
487
+ uri = buf
488
+ end
489
+
490
+ if (self.config['uri_full_url'])
491
+ url = self.ssl ? "https" : "http"
492
+ url << self.config['vhost']
493
+ url << ((self.port == 80) ? "" : ":#{self.port}")
494
+ url << uri
495
+ url
496
+ else
497
+ uri
498
+ end
499
+ end
500
+
501
+ #
502
+ # Return the cgi
503
+ #
504
+ def set_cgi(uri)
505
+
506
+ if (self.config['uri_dir_self_reference'])
507
+ uri.gsub!('/', '/./')
508
+ end
509
+
510
+ if (self.config['uri_dir_fake_relative'])
511
+ buf = ""
512
+ uri.split('/').each do |part|
513
+ cnt = rand(8)+2
514
+ 1.upto(cnt) { |idx|
515
+ buf << "/" + Rex::Text.rand_text_alphanumeric(rand(32)+1)
516
+ }
517
+ buf << ("/.." * cnt)
518
+ buf << "/" + part
519
+ end
520
+ uri = buf
521
+ end
522
+
523
+ url = uri
524
+
525
+ if (self.config['uri_full_url'])
526
+ url = self.ssl ? "https" : "http"
527
+ url << self.config['vhost']
528
+ url << (self.port == 80) ? "" : ":#{self.port}"
529
+ url << uri
530
+ end
531
+
532
+ url
533
+ end
534
+
535
+ #
536
+ # Return the HTTP method string
537
+ #
538
+ def set_method(method)
539
+ ret = method
540
+
541
+ if (self.config['method_random_valid'])
542
+ ret = ['GET', 'POST', 'HEAD'][rand(3)]
543
+ end
544
+
545
+ if (self.config['method_random_invalid'])
546
+ ret = Rex::Text.rand_text_alpha(rand(20)+1)
547
+ end
548
+
549
+ if (self.config['method_random_case'])
550
+ ret = Rex::Text.to_rand_case(ret)
551
+ end
552
+
553
+ ret
554
+ end
555
+
556
+ #
557
+ # Return the HTTP version string
558
+ #
559
+ def set_version(protocol, version)
560
+ ret = protocol + "/" + version
561
+
562
+ if (self.config['version_random_valid'])
563
+ ret = protocol + "/" + ['1.0', '1.1'][rand(2)]
564
+ end
565
+
566
+ if (self.config['version_random_invalid'])
567
+ ret = Rex::Text.rand_text_alphanumeric(rand(20)+1)
568
+ end
569
+
570
+ if (self.config['version_random_case'])
571
+ ret = Rex::Text.to_rand_case(ret)
572
+ end
573
+
574
+ ret << "\r\n"
575
+ end
576
+
577
+ #
578
+ # Return the HTTP seperator and body string
579
+ #
580
+ def set_body(data)
581
+ return "\r\n" + data if self.config['chunked_size'] == 0
582
+ str = data.dup
583
+ chunked = ''
584
+ while str.size > 0
585
+ chunk = str.slice!(0,rand(self.config['chunked_size']) + 1)
586
+ chunked << sprintf("%x", chunk.size) + "\r\n" + chunk + "\r\n"
587
+ end
588
+ "\r\n" + chunked + "0\r\n\r\n"
589
+ end
590
+
591
+ #
592
+ # Return the HTTP path info
593
+ # TODO:
594
+ # * Encode path information
595
+ def set_path_info(path)
596
+ path ? path : ''
597
+ end
598
+
599
+ #
600
+ # Return the spacing between the method and uri
601
+ #
602
+ def set_method_uri_spacer
603
+ len = self.config['pad_method_uri_count'].to_i
604
+ set = " "
605
+ buf = ""
606
+
607
+ case self.config['pad_method_uri_type']
608
+ when 'tab'
609
+ set = "\t"
610
+ when 'apache'
611
+ set = "\t \x0b\x0c\x0d"
612
+ end
613
+
614
+ while(buf.length < len)
615
+ buf << set[ rand(set.length) ]
616
+ end
617
+
618
+ return buf
619
+ end
620
+
621
+ #
622
+ # Return the spacing between the uri and the version
623
+ #
624
+ def set_uri_version_spacer
625
+ len = self.config['pad_uri_version_count'].to_i
626
+ set = " "
627
+ buf = ""
628
+
629
+ case self.config['pad_uri_version_type']
630
+ when 'tab'
631
+ set = "\t"
632
+ when 'apache'
633
+ set = "\t \x0b\x0c\x0d"
634
+ end
635
+
636
+ while(buf.length < len)
637
+ buf << set[ rand(set.length) ]
638
+ end
639
+
640
+ return buf
641
+ end
642
+
643
+ #
644
+ # Return the padding to place before the uri
645
+ #
646
+ def set_uri_prepend
647
+ prefix = ""
648
+
649
+ if (self.config['uri_fake_params_start'])
650
+ prefix << '/%3fa=b/../'
651
+ end
652
+
653
+ if (self.config['uri_fake_end'])
654
+ prefix << '/%20HTTP/1.0/../../'
655
+ end
656
+
657
+ prefix
658
+ end
659
+
660
+ #
661
+ # Return the padding to place before the uri
662
+ #
663
+ def set_uri_append
664
+ # TODO:
665
+ # * Support different padding types
666
+ ""
667
+ end
668
+
669
+ #
670
+ # Return the HTTP Host header
671
+ #
672
+ def set_host_header(host)
673
+ return "" if self.config['uri_full_url']
674
+ host ||= self.config['vhost']
675
+ set_formatted_header("Host", host)
676
+ end
677
+
678
+ #
679
+ # Return the HTTP agent header
680
+ #
681
+ def set_agent_header(agent)
682
+ agent ? set_formatted_header("User-Agent", agent) : ""
683
+ end
684
+
685
+ #
686
+ # Return the HTTP cookie header
687
+ #
688
+ def set_cookie_header(cookie)
689
+ cookie ? set_formatted_header("Cookie", cookie) : ""
690
+ end
691
+
692
+ #
693
+ # Return the HTTP connection header
694
+ #
695
+ def set_connection_header(conn)
696
+ conn ? set_formatted_header("Connection", conn) : ""
697
+ end
698
+
699
+ #
700
+ # Return the content type header
701
+ #
702
+ def set_content_type_header(ctype)
703
+ set_formatted_header("Content-Type", ctype)
704
+ end
705
+
706
+ #
707
+ # Return the content length header
708
+ def set_content_len_header(clen)
709
+ return "" if self.config['chunked_size'] > 0
710
+ set_formatted_header("Content-Length", clen)
711
+ end
712
+
713
+ #
714
+ # Return the Authorization basic-auth header
715
+ #
716
+ def set_basic_auth_header(auth)
717
+ auth ? set_formatted_header("Authorization", "Basic " + Rex::Text.encode_base64(auth)) : ""
718
+ end
719
+
720
+ #
721
+ # Return a string of formatted extra headers
722
+ #
723
+ def set_extra_headers(headers)
724
+ buf = ''
725
+
726
+ if (self.config['pad_fake_headers'])
727
+ 1.upto(self.config['pad_fake_headers_count'].to_i) do |i|
728
+ buf << set_formatted_header(
729
+ Rex::Text.rand_text_alphanumeric(rand(32)+1),
730
+ Rex::Text.rand_text_alphanumeric(rand(32)+1)
731
+ )
732
+ end
733
+ end
734
+
735
+ headers.each_pair do |var,val|
736
+ buf << set_formatted_header(var, val)
737
+ end
738
+
739
+ buf
740
+ end
741
+
742
+ def set_chunked_header()
743
+ return "" if self.config['chunked_size'] == 0
744
+ set_formatted_header('Transfer-Encoding', 'chunked')
745
+ end
746
+
747
+ #
748
+ # Return a string of raw header data
749
+ #
750
+ def set_raw_headers(data)
751
+ data
752
+ end
753
+
754
+ #
755
+ # Return a formatted header string
756
+ #
757
+ def set_formatted_header(var, val)
758
+ if (self.config['header_folding'])
759
+ "#{var}:\r\n\t#{val}\r\n"
760
+ else
761
+ "#{var}: #{val}\r\n"
762
+ end
763
+ end
764
+
765
+
766
+
767
+ #
768
+ # The client request configuration
769
+ #
770
+ attr_accessor :config
771
+ #
772
+ # The client request configuration classes
773
+ #
774
+ attr_accessor :config_types
775
+ #
776
+ # Whether or not pipelining is in use.
777
+ #
778
+ attr_accessor :pipeline
779
+ #
780
+ # The local host of the client.
781
+ #
782
+ attr_accessor :local_host
783
+ #
784
+ # The local port of the client.
785
+ #
786
+ attr_accessor :local_port
787
+ #
788
+ # The underlying connection.
789
+ #
790
+ attr_accessor :conn
791
+ #
792
+ # The calling context to pass to the socket
793
+ #
794
+ attr_accessor :context
795
+ #
796
+ # The proxy list
797
+ #
798
+ attr_accessor :proxies
799
+
800
+
801
+ # When parsing the request, thunk off the first response from the server, since junk
802
+ attr_accessor :junk_pipeline
803
+
804
+ protected
805
+
806
+ # https
807
+ attr_accessor :ssl, :ssl_version # :nodoc:
808
+
809
+ attr_accessor :hostname, :port # :nodoc:
810
+
811
+
812
+ end
813
+
814
+ end
815
+ end
816
+ end
817
+