{"id":59376,"date":"2024-09-01T22:40:00","date_gmt":"2024-09-01T19:40:00","guid":{"rendered":"https:\/\/packetstormsecurity.com\/files\/181213\/ibm_mq_channel_brute.rb.txt"},"modified":"2024-09-01T22:40:00","modified_gmt":"2024-09-01T19:40:00","slug":"ibm-websphere-mq-channel-name-bruteforce","status":"publish","type":"post","link":"https:\/\/afaghhosting.net\/blog\/ibm-websphere-mq-channel-name-bruteforce\/","title":{"rendered":"IBM WebSphere MQ Channel Name Bruteforce"},"content":{"rendered":"<p>##<br \/># This module requires Metasploit: https:\/\/metasploit.com\/download<br \/># Current source: https:\/\/github.com\/rapid7\/metasploit-framework<br \/>##<\/p>\n<p>class MetasploitModule &lt; Msf::Auxiliary<\/p>\n<p>include Msf::Exploit::Remote::Tcp<br \/>include Msf::Auxiliary::Scanner<br \/>include Msf::Auxiliary::Report<\/p>\n<p>def initialize<br \/>super(<br \/>&#8216;Name&#8217; =&gt; &#8216;IBM WebSphere MQ Channel Name Bruteforce&#8217;,<br \/>&#8216;Description&#8217; =&gt; &#8216;This module uses a dictionary to bruteforce MQ channel names. For all identified channels it also returns if SSL is used and whether it is a server-connection channel.&#8217;,<br \/>&#8216;Author&#8217; =&gt; &#8216;Petros Koutroumpis&#8217;,<br \/>&#8216;License&#8217; =&gt; MSF_LICENSE<br \/>)<br \/>register_options([<br \/>Opt::RPORT(1414),<br \/>OptInt.new(&#8216;TIMEOUT&#8217;, [true, &#8220;The socket connect timeout in seconds&#8221;, 10]),<br \/>OptInt.new(&#8216;CONCURRENCY&#8217;, [true, &#8220;The number of concurrent channel names to check&#8221;, 10]),<br \/>OptPath.new(&#8216;CHANNELS_FILE&#8217;,<br \/>[ true, &#8220;The file that contains a list of channel names&#8221;])])<br \/>end<\/p>\n<p>def create_packet(chan)<br \/>packet = &#8220;\\x54\\x53\\x48\\x20&#8243;+ # StructID<br \/>&#8220;\\x00\\x00\\x01\\x0c&#8221;+ # MQSegmLen<br \/>&#8220;\\x02&#8221; + # Byte Order<br \/>&#8220;\\x01&#8221; + # SegmType<br \/>&#8220;\\x01&#8221; + # CtlFlag1<br \/>&#8220;\\x00&#8221; + # CtlFlag2<br \/>&#8220;\\x00\\x00\\x00\\x00\\x00\\x00\\x00\\x00&#8243;+ # LUWIdent<br \/>&#8220;\\x22\\x02\\x00\\x00&#8243;+ # Encoding<br \/>&#8220;\\xb5\\x01&#8221; + # CCSID<br \/>&#8220;\\x00\\x00&#8221; + # Reserved<br \/>&#8220;\\x49\\x44\\x20\\x20&#8221; + # StructID<br \/>&#8220;\\x0d&#8221; + # FAP Level<br \/>&#8220;\\x26&#8221; + # CapFlag1 &#8211; Channel Type<br \/>&#8220;\\x00&#8221; + # ECapFlag1<br \/>&#8220;\\x00&#8221; + # IniErrFlg1<br \/>&#8220;\\x00\\x00&#8221; + # Reserved<br \/>&#8220;\\x32\\x00&#8221; + # MaxMsgBtch<br \/>&#8220;\\xec\\x7f\\x00\\x00&#8221; + # MaxTrSize<br \/>&#8220;\\x00\\x00\\x40\\x00&#8221; + # MaxMsgSize<br \/>&#8220;\\xff\\xc9\\x9a\\x3b&#8221; + # SegWrapVal<br \/>+ chan + # Channel name<br \/>&#8220;\\x20&#8221; + # CapFlag2<br \/>&#8220;\\x20&#8221; + # ECapFlag2<br \/>&#8220;\\x20\\x20&#8221; + # ccsid<br \/>&#8220;QM1&#8221; + &#8220;\\x20&#8243;*45 + # Queue Manager Name<br \/>&#8220;\\x20\\x20\\x20\\x20&#8221; + # HBInterval<br \/>&#8220;\\x20\\x20&#8221; + # EFLLength<br \/>&#8220;\\x20&#8221; + # IniErrFlg2<br \/>&#8220;\\x20&#8221; + # Reserved1<br \/>&#8220;\\x20\\x20&#8221; + # HdrCprLst<br \/>&#8220;\\x20\\x20\\x20\\x20\\x2c\\x01\\x00\\x00&#8243;+ # MSGCprLst1<br \/>&#8220;\\x8a\\x00\\x00\\x55\\x00\\xff\\x00\\xff&#8221;+ # MsgCprLst2<br \/>&#8220;\\xff\\xff&#8221; + # Reserved2<br \/>&#8220;\\xff\\xff\\xff\\xff&#8221; + # SSLKeyRst<br \/>&#8220;\\xff\\xff\\xff\\xff&#8221; + # ConvBySKt<br \/>&#8220;\\xff&#8221; + # CapFlag3<br \/>&#8220;\\xff&#8221; + # ECapFlag3<br \/>&#8220;\\xff\\xff&#8221; + # Reserved3<br \/>&#8220;\\x00\\x00\\x00\\x00&#8221; + # ProcessId<br \/>&#8220;\\x00\\x00\\x00\\x00&#8221; + # ThreadId<br \/>&#8220;\\x00\\x00\\x05\\x00&#8221; + # TraceId<br \/>&#8220;\\x00\\x00\\x10\\x13\\x00\\x00&#8221; + # ProdId<br \/>&#8220;\\x01\\x00\\x00\\x00\\x01\\x00&#8221; + # ProdId<br \/>&#8220;MQMID&#8221; + &#8220;\\x20&#8243;*43 + # MQM Id<br \/>&#8220;\\x20\\x20\\x20\\x20\\x20\\x20\\x20\\x20&#8243;+ # Unknown<br \/>&#8220;\\x20\\x20\\x20\\x20\\x20\\x20\\x00\\x00&#8243;+ # Unknown<br \/>&#8220;\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff&#8221;+ # Unknown<br \/>&#8220;\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff&#8221;+ # Unknown<br \/>&#8220;\\xff\\xff\\x00\\x00\\x00\\x00\\x00\\x00&#8243;+ # Unknown<br \/>&#8220;\\x00\\x00\\x00\\x00\\x00\\x00&#8221; # Unknown<br \/>end<\/p>\n<p>def run_host(ip)<br \/>@channels = []@unencrypted_mqi_channels = []begin<br \/>channel_list<br \/>rescue ::Rex::ConnectionRefused<br \/>fail_with(Failure::Unreachable, &#8220;TCP Port closed.&#8221;)<br \/>rescue ::Rex::ConnectionError, ::IOError, ::Timeout::Error, Errno::ECONNRESET<br \/>fail_with(Failure::Unreachable, &#8220;Connection Failed.&#8221;)<br \/>rescue ::Exception =&gt; e<br \/>fail_with(Failure::Unknown, e)<br \/>end<br \/>if(@channels.empty?)<br \/>print_status(&#8220;#{ip}:#{rport} No channels found.&#8221;)<br \/>else<br \/>print_good(&#8220;Channels found: #{@channels}&#8221;)<br \/>print_good(&#8220;Unencrypted MQI Channels found: #{@unencrypted_mqi_channels}&#8221;)<br \/>report_note(<br \/>:host =&gt; rhost,<br \/>:port =&gt; rport,<br \/>:type =&gt; &#8216;mq.channels&#8217;<br \/>)<br \/>print_line<br \/>end<br \/>end<\/p>\n<p>def channel_list<br \/>channel_data = get_channel_names<br \/>while (channel_data.length &gt; 0)<br \/>t = []r = []begin<br \/>1.upto(datastore[&#8216;CONCURRENCY&#8217;]) do<br \/>this_channel = channel_data.shift<br \/>if this_channel.nil?<br \/>next<br \/>end<br \/>t &lt;&lt; framework.threads.spawn(&#8220;Module(#{self.refname})-#{rhost}:#{rport}&#8221;, false, this_channel) do |channel|<br \/>connect<br \/>vprint_status &#8220;#{rhost}:#{rport} &#8211; Sending request for #{channel}&#8230;&#8221;<br \/>if channel.length.to_i &gt; 20<br \/>print_error(&#8220;Channel names cannot exceed 20 characters. Skipping.&#8221;)<br \/>next<br \/>end<br \/>chan = channel + &#8220;\\x20&#8243;*(20-channel.length.to_i)<br \/>timeout = datastore[&#8216;TIMEOUT&#8217;].to_i<br \/>s = connect(false,<br \/>{<br \/>&#8216;RPORT&#8217; =&gt; rport,<br \/>&#8216;RHOST&#8217; =&gt; rhost,<br \/>}<br \/>)<br \/>s.put(create_packet(chan))<br \/>data = s.get_once(-1,timeout)<br \/>if data.nil?<br \/>print_status(&#8220;No response received. Try increasing timeout.&#8221;)<br \/>next<br \/>end<br \/>if not data[0&#8230;3].include? &#8216;TSH&#8217;<br \/>next<br \/>end<br \/>if data[-4..-1] == &#8220;\\x01\\x00\\x00\\x00&#8221; # NO_CHANNEL code<br \/>next<br \/>end<br \/>if data[-4..-1] == &#8220;\\x18\\x00\\x00\\x00&#8221; # CIPHER_SPEC code<br \/>print_status(&#8220;Found channel: #{channel}, IsEncrypted: True, IsMQI: N\/A&#8221;)<br \/>elsif data[-4..-1] == &#8220;\\x02\\x00\\x00\\x00&#8221; # CHANNEL_WRONG_TYPE code<br \/>print_status(&#8220;Found channel: #{channel}, IsEncrypted: False, IsMQI: False&#8221;)<br \/>else<br \/>print_status(&#8220;Found channel: #{channel}, IsEncrypted: False, IsMQI: True&#8221;)<br \/>@unencrypted_mqi_channels &lt;&lt; channel<br \/>end<br \/>@channels &lt;&lt; channel<br \/>disconnect<br \/>end<br \/>end<br \/>t.each {|x| x.join }<br \/>end<br \/>end<br \/>end<\/p>\n<p>def get_channel_names<br \/>if(! @common)<br \/>File.open(datastore[&#8216;CHANNELS_FILE&#8217;], &#8220;rb&#8221;) do |fd|<br \/>data = fd.read(fd.stat.size)<br \/>@common = data.split(\/\\n\/).compact.uniq<br \/>end<br \/>end<br \/>@common<br \/>end<\/p>\n<p>end<\/p>\n","protected":false},"excerpt":{"rendered":"<p>### This module requires Metasploit: https:\/\/metasploit.com\/download# Current source: https:\/\/github.com\/rapid7\/metasploit-framework## class MetasploitModule &lt; Msf::Auxiliary include Msf::Exploit::Remote::Tcpinclude Msf::Auxiliary::Scannerinclude Msf::Auxiliary::Report def initializesuper(&#8216;Name&#8217; =&gt; &#8216;IBM WebSphere MQ Channel Name Bruteforce&#8217;,&#8216;Description&#8217; =&gt; &#8216;This module uses a dictionary to bruteforce MQ channel names. For all identified channels it also returns if SSL is used and whether it is a server-connection channel.&#8217;,&#8216;Author&#8217; &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26],"tags":[],"class_list":["post-59376","post","type-post","status-publish","format-standard","hentry","category-vulnerability"],"_links":{"self":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59376","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/comments?post=59376"}],"version-history":[{"count":0,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/posts\/59376\/revisions"}],"wp:attachment":[{"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/media?parent=59376"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/categories?post=59376"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/afaghhosting.net\/blog\/wp-json\/wp\/v2\/tags?post=59376"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}