Permalink
Browse files

Merge branch 'release/2012032801' into stable

  • Loading branch information...
2 parents f9527d8 + a0f0aad commit ce3899719a99ef1cde8464af29308e9aca1de729 @jcran jcran committed Apr 4, 2012
Showing with 1,737 additions and 348 deletions.
  1. BIN data/armitage/armitage.jar
  2. +31 −0 data/armitage/whatsnew.txt
  3. +11 −4 external/ruby-lorcon2/Lorcon2.c
  4. +1 −1 lib/msf/base/simple/auxiliary.rb
  5. +1 −1 lib/msf/base/simple/exploit.rb
  6. +2 −2 lib/msf/base/simple/framework.rb
  7. +2 −2 lib/msf/base/simple/module.rb
  8. +1 −1 lib/msf/base/simple/post.rb
  9. +7 −4 lib/msf/core/handler/reverse_http.rb
  10. +8 −5 lib/msf/core/handler/reverse_https.rb
  11. +2 −0 lib/msf/core/module.rb
  12. +2 −0 lib/msf/core/module/reference.rb
  13. +2 −1 lib/msf/ui/console/command_dispatcher/core.rb
  14. +79 −1 lib/rex/text.rb
  15. +99 −0 modules/auxiliary/admin/hp/hp_data_protector_cmd.rb
  16. +1 −1 modules/auxiliary/admin/http/trendmicro_dlp_traversal.rb
  17. +1 −1 modules/auxiliary/admin/http/typo3_sa_2009_002.rb
  18. +1 −1 modules/auxiliary/admin/zend/java_bridge.rb
  19. +1 −1 modules/auxiliary/dos/dhcp/isc_dhcpd_clientid.rb
  20. +1 −1 modules/auxiliary/dos/hp/data_protector_rds.rb
  21. +1 −1 modules/auxiliary/dos/http/apache_mod_isapi.rb
  22. +1 −1 modules/auxiliary/dos/http/apache_range_dos.rb
  23. +1 −1 modules/auxiliary/dos/windows/ftp/iis75_ftpd_iac_bof.rb
  24. +1 −1 modules/auxiliary/dos/windows/ftp/solarftp_user.rb
  25. +1 −1 modules/auxiliary/dos/windows/http/ms10_065_ii6_asp_dos.rb
  26. +1 −1 modules/auxiliary/dos/windows/rdp/ms12_020_maxchannelids.rb
  27. +1 −1 modules/auxiliary/dos/windows/smb/ms11_019_electbowser.rb
  28. +1 −1 modules/auxiliary/dos/windows/tftp/solarwinds.rb
  29. +9 −6 modules/auxiliary/gather/checkpoint_hostname.rb
  30. +54 −52 modules/auxiliary/gather/{dns_enum.rb → enum_dns.rb}
  31. +1 −1 modules/auxiliary/scanner/http/axis_local_file_include.rb
  32. +1 −1 modules/auxiliary/scanner/http/barracuda_directory_traversal.rb
  33. +1 −1 modules/auxiliary/scanner/http/litespeed_source_disclosure.rb
  34. +1 −1 modules/auxiliary/scanner/http/majordomo2_directory_traversal.rb
  35. +81 −0 modules/auxiliary/scanner/http/manageengine_traversal.rb
  36. +2 −2 modules/auxiliary/scanner/http/nginx_source_disclosure.rb
  37. +1 −1 modules/auxiliary/scanner/telnet/telnet_encrypt_overflow.rb
  38. +1 −1 modules/auxiliary/scanner/tftp/ipswitch_whatsupgold_tftp.rb
  39. +1 −1 modules/exploits/freebsd/telnet/telnet_encrypt_keyid.rb
  40. +3 −3 modules/exploits/linux/misc/lprng_format_string.rb
  41. +1 −1 modules/exploits/linux/misc/netsupport_manager_agent.rb
  42. +2 −2 modules/exploits/linux/pop3/cyrus_pop3d_popsubfolders.rb
  43. +1 −1 modules/exploits/linux/telnet/telnet_encrypt_keyid.rb
  44. +1 −1 modules/exploits/multi/fileformat/peazip_command_injection.rb
  45. +1 −1 modules/exploits/multi/http/familycms_less_exec.rb
  46. +1 −1 modules/exploits/multi/http/phpldapadmin_query_engine.rb
  47. +1 −1 modules/exploits/multi/http/phpscheduleit_start_date.rb
  48. +1 −1 modules/exploits/multi/http/plone_popen2.rb
  49. +1 −1 modules/exploits/multi/http/pmwiki_pagelist.rb
  50. +2 −2 modules/exploits/multi/http/sit_file_upload.rb
  51. +1 −1 modules/exploits/multi/http/struts_code_exec.rb
  52. +1 −1 modules/exploits/multi/http/traq_plugin_exec.rb
  53. +1 −1 modules/exploits/multi/http/vbseo_proc_deutf.rb
  54. +1 −1 modules/exploits/multi/misc/zend_java_bridge.rb
  55. +1 −1 modules/exploits/osx/http/evocam_webserver.rb
  56. +1 −1 modules/exploits/osx/misc/ufo_ai.rb
  57. +85 −0 modules/exploits/unix/http/freepbx_callmenum.rb
  58. +1 −1 modules/exploits/unix/webapp/awstats_migrate_exec.rb
  59. +1 −1 modules/exploits/unix/webapp/coppermine_piceditor.rb
  60. +1 −1 modules/exploits/unix/webapp/joomla_tinybrowser.rb
  61. +1 −1 modules/exploits/unix/webapp/php_eval.rb
  62. +1 −1 modules/exploits/unix/webapp/sphpblog_file_upload.rb
  63. +1 −1 modules/exploits/unix/webapp/trixbox_langchoice.rb
  64. +1 −1 modules/exploits/windows/browser/baofeng_storm_onbeforevideodownload.rb
  65. +1 −1 modules/exploits/windows/browser/blackice_downloadimagefileurl.rb
  66. +1 −1 modules/exploits/windows/browser/chilkat_crypt_writefile.rb
  67. +1 −1 modules/exploits/windows/browser/communicrypt_mail_activex.rb
  68. +1 −1 modules/exploits/windows/browser/dxstudio_player_exec.rb
  69. +1 −1 modules/exploits/windows/browser/greendam_url.rb
  70. +1 −1 modules/exploits/windows/browser/hyleos_chemviewx_activex.rb
  71. +1 −1 modules/exploits/windows/browser/imgeviewer_tifmergemultifiles.rb
  72. +1 −1 modules/exploits/windows/browser/ms09_043_owc_msdso.rb
  73. +311 −0 modules/exploits/windows/browser/ms10_002_ie_object.rb
  74. +1 −1 modules/exploits/windows/browser/ms10_090_ie_css_clip.rb
  75. +1 −1 modules/exploits/windows/browser/novelliprint_callbackurl.rb
  76. +1 −1 modules/exploits/windows/browser/novelliprint_executerequest_dbg.rb
  77. +1 −1 modules/exploits/windows/browser/novelliprint_getdriversettings_2.rb
  78. +1 −1 modules/exploits/windows/browser/real_arcade_installerdlg.rb
  79. +1 −1 modules/exploits/windows/browser/trendmicro_extsetowner.rb
  80. +1 −1 modules/exploits/windows/browser/ultraoffice_httpupload.rb
  81. +1 −1 modules/exploits/windows/browser/viscom_movieplayer_drawtext.rb
  82. +1 −1 modules/exploits/windows/browser/webex_ucf_newobject.rb
  83. +2 −2 modules/exploits/windows/fileformat/a-pdf_wav_to_mp3.rb
  84. +1 −1 modules/exploits/windows/fileformat/adobe_illustrator_v14_eps.rb
  85. +1 −1 modules/exploits/windows/fileformat/aol_desktop_linktag.rb
  86. +1 −1 modules/exploits/windows/fileformat/aol_phobos_bof.rb
  87. +1 −1 modules/exploits/windows/fileformat/audio_wkstn_pls.rb
  88. +1 −1 modules/exploits/windows/fileformat/audiotran_pls.rb
  89. +1 −1 modules/exploits/windows/fileformat/aviosoft_plf_buf.rb
  90. +1 −1 modules/exploits/windows/fileformat/bsplayer_m3u.rb
  91. +1 −1 modules/exploits/windows/fileformat/ccmplayer_m3u_bof.rb
  92. +1 −1 modules/exploits/windows/fileformat/deepburner_path.rb
  93. +1 −1 modules/exploits/windows/fileformat/digital_music_pad_pls.rb
  94. +1 −1 modules/exploits/windows/fileformat/djstudio_pls_bof.rb
  95. +1 −1 modules/exploits/windows/fileformat/dvdx_plf_bof.rb
  96. +1 −1 modules/exploits/windows/fileformat/esignal_styletemplate_bof.rb
  97. +2 −2 modules/exploits/windows/fileformat/ezip_wizard_bof.rb
  98. +1 −1 modules/exploits/windows/fileformat/fatplayer_wav.rb
  99. +3 −3 modules/exploits/windows/fileformat/feeddemon_opml.rb
  100. +1 −1 modules/exploits/windows/fileformat/foxit_title_bof.rb
  101. +2 −2 modules/exploits/windows/fileformat/free_mp3_ripper_wav.rb
  102. +1 −1 modules/exploits/windows/fileformat/galan_fileformat_bof.rb
  103. +1 −1 modules/exploits/windows/fileformat/gta_samp.rb
  104. +2 −2 modules/exploits/windows/fileformat/hhw_hhp_compiledfile_bof.rb
  105. +2 −2 modules/exploits/windows/fileformat/hhw_hhp_contentfile_bof.rb
  106. +2 −2 modules/exploits/windows/fileformat/hhw_hhp_indexfile_bof.rb
  107. +4 −4 modules/exploits/windows/fileformat/ideal_migration_ipj.rb
  108. +1 −1 modules/exploits/windows/fileformat/microp_mppl.rb
  109. +2 −2 modules/exploits/windows/fileformat/millenium_mp3_pls.rb
  110. +1 −1 modules/exploits/windows/fileformat/mini_stream_pls_bof.rb
  111. +1 −1 modules/exploits/windows/fileformat/mymp3player_m3u.rb
  112. +1 −1 modules/exploits/windows/fileformat/orbital_viewer_orb.rb
  113. +2 −2 modules/exploits/windows/fileformat/proshow_cellimage_bof.rb
  114. +1 −1 modules/exploits/windows/fileformat/real_networks_netzip_bof.rb
  115. +1 −1 modules/exploits/windows/fileformat/scadaphone_zip.rb
  116. +1 −1 modules/exploits/windows/fileformat/somplplayer_m3u.rb
  117. +1 −1 modules/exploits/windows/fileformat/subtitle_processor_m3u_bof.rb
  118. +1 −1 modules/exploits/windows/fileformat/tugzip.rb
  119. +1 −1 modules/exploits/windows/fileformat/ultraiso_ccd.rb
  120. +1 −1 modules/exploits/windows/fileformat/ultraiso_cue.rb
  121. +1 −1 modules/exploits/windows/fileformat/varicad_dwb.rb
  122. +1 −1 modules/exploits/windows/fileformat/vlc_smb_uri.rb
  123. +1 −1 modules/exploits/windows/fileformat/wireshark_packet_dect.rb
  124. +1 −1 modules/exploits/windows/fileformat/wm_downloader_m3u.rb
  125. +1 −1 modules/exploits/windows/fileformat/xenorate_xpl_bof.rb
  126. +3 −3 modules/exploits/windows/fileformat/xion_m3u_sehbof.rb
  127. +34 −7 modules/exploits/windows/ftp/3cdaemon_ftp_user.rb
  128. +1 −1 modules/exploits/windows/ftp/ability_server_stor.rb
  129. +1 −1 modules/exploits/windows/ftp/absolute_ftp_list_bof.rb
  130. +2 −2 modules/exploits/windows/ftp/easyftp_list_fixret.rb
  131. +2 −2 modules/exploits/windows/ftp/easyftp_mkd_fixret.rb
  132. +1 −1 modules/exploits/windows/ftp/goldenftp_pass_bof.rb
  133. +1 −1 modules/exploits/windows/ftp/ms09_053_ftpd_nlst.rb
  134. +123 −0 modules/exploits/windows/ftp/ricoh_dl_bof.rb
  135. +1 −1 modules/exploits/windows/ftp/scriptftp_list.rb
  136. +1 −1 modules/exploits/windows/ftp/trellian_client_pasv.rb
  137. +1 −1 modules/exploits/windows/ftp/vermillion_ftpd_port.rb
  138. +1 −1 modules/exploits/windows/ftp/xftp_client_pwd.rb
  139. +1 −1 modules/exploits/windows/http/ca_arcserve_rpc_authbypass.rb
  140. +1 −1 modules/exploits/windows/http/easyftp_list.rb
  141. +1 −1 modules/exploits/windows/http/kolibri_http.rb
  142. +2 −2 modules/exploits/windows/misc/bigant_server_250.rb
  143. +2 −2 modules/exploits/windows/misc/bigant_server_usv.rb
  144. +1 −1 modules/exploits/windows/misc/eureka_mail_err.rb
  145. +1 −1 modules/exploits/windows/misc/hp_omniinet_4.rb
  146. +1 −1 modules/exploits/windows/misc/mini_stream.rb
  147. +1 −1 modules/exploits/windows/misc/nettransport.rb
  148. +1 −1 modules/exploits/windows/misc/splayer_content_type.rb
  149. +1 −1 modules/exploits/windows/misc/stream_down_bof.rb
  150. +1 −1 modules/exploits/windows/misc/ufo_ai.rb
  151. +1 −1 modules/exploits/windows/misc/wireshark_packet_dect.rb
  152. +1 −1 modules/exploits/windows/scada/codesys_web_server.rb
  153. +1 −1 modules/exploits/windows/scada/iconics_webhmi_setactivexguid.rb
  154. +1 −1 modules/exploits/windows/smtp/njstar_smtp_bof.rb
  155. +1 −1 modules/exploits/windows/ssh/sysax_ssh_username.rb
  156. +1 −1 modules/exploits/windows/tftp/attftp_long_filename.rb
  157. +95 −0 modules/exploits/windows/vnc/ultravnc_viewer_bof.rb
  158. +259 −0 modules/payloads/singles/windows/dns_txt_query_exec.rb
  159. +73 −76 modules/payloads/singles/windows/download_exec_https.rb
  160. +1 −7 modules/payloads/stagers/php/bind_tcp.rb
  161. +2 −10 modules/payloads/stagers/php/reverse_tcp.rb
  162. +73 −0 modules/post/osx/gather/enum_airport.rb
  163. +110 −0 modules/post/osx/gather/enum_chicken_vnc_profile.rb
  164. +1 −1 modules/post/windows/escalate/ms10_073_kbdlayout.rb
  165. +1 −1 modules/post/windows/escalate/ms10_092_schelevator.rb
  166. +1 −1 modules/post/windows/escalate/net_runtime_modify.rb
  167. +1 −1 modules/post/windows/gather/credentials/imail.rb
  168. +17 −6 test/modules/post/test/file.rb
View
Binary file not shown.
View
@@ -1,6 +1,37 @@
Armitage Changelog
==================
+22 Mar 12
+---------
+- Updated Armitage NMap profiles with the following:
+ -T4 (instead of -T5) [wait longer for open services to reply]
+ -n [forces NMap to not resolve the hostname of IP addresses]
+ --min-hostgroup 96 [allows more parallelism when scanning hosts]
+- Armitage now intercepts screenshot and webcam_snap commands from meterpreter
+ shell and performs the appropriate action with them.
+- View -> Creds -> Export button now works in team mode.
+- Doh! Armitage now properly shows VMWare icon when OS is set to a VMWare ESXi
+- Armitage "is command finished?" heuristic now accounts for commands like
+ del /S which prompt with a (Y/N)? - you can safely use these commands again.
+- Armitage now detects whether a client connecting to the team server is out
+ dated or not. It rejects old clients. They will get a message indicating they
+ need to update and then their client won't do anything else. You'll see a
+ message printed to STDOUT where the team server ran about the rejection.
+- Added a * indicator to the active workspace in the workspaces menu.
+- Added Hosts -> DNS Enumerate, this menu launches a Metasploit module that will
+ attempt to discover hosts by querying a name server in different ways.
+- Added a file chooser helper to WORDLIST option.
+- Armitage now displays a pivot relationship between a compromised host and the
+ NAT/proxy device it is connected through.
+- Added a Copy button to services tab. This button copies the highlighted hosts
+ to the clipboard. I found myself needing this several times recently.
+- Improved reverse payload selection logic (now it includes rev php meterpreter)
+- Armitage now sets a different LPORT for each exploit launched with a rev payload
+
+10:30am
+- Changed algorithm for determining which edges to highlight in graph view. If there
+ is a pivot and both sides have a session, then the edge is highlighted.
+
8 Mar 12 1.43-dev
--------
- Armitage now uses session_host to determine which host a session is associated
@@ -127,11 +127,11 @@ static VALUE Lorcon_create(int argc, VALUE *argv, VALUE self) {
if (argc == 2) {
rb_scan_args(argc, argv, "2", &rbintf, &rbdriver);
- intf = STR2CSTR(rbintf);
- driver = STR2CSTR(rbdriver);
+ intf = StringValuePtr(rbintf);
+ driver = StringValuePtr(rbdriver);
} else {
rb_scan_args(argc, argv, "1", &rbintf);
- intf = STR2CSTR(rbintf);
+ intf = StringValuePtr(rbintf);
}
if (driver == NULL) {
@@ -348,10 +348,11 @@ static VALUE Lorcon_packet_get_data(VALUE self) {
static VALUE Lorcon_packet_getdot3(VALUE self) {
struct rlpack *rlp;
- Data_Get_Struct(self, struct rlpack, rlp);
u_char *pdata;
int len;
VALUE ret;
+
+ Data_Get_Struct(self, struct rlpack, rlp);
if (rlp->packet->packet_data == NULL)
return Qnil;
@@ -506,6 +507,11 @@ static VALUE Lorcon_set_channel(VALUE self, VALUE channel) {
return INT2FIX(lorcon_set_channel(rld->context, NUM2INT(channel)));
}
+static VALUE Lorcon_get_channel(VALUE self) {
+ struct rldev *rld;
+ Data_Get_Struct(self, struct rldev, rld);
+ return INT2FIX(lorcon_get_channel(rld->context));
+}
static void rblorcon_pcap_handler(rblorconjob_t *job, struct pcap_pkthdr *hdr, u_char *pkt){
job->pkt = (unsigned char *)pkt;
@@ -631,6 +637,7 @@ void Init_Lorcon2() {
rb_define_method(cDevice, "filter=", Lorcon_set_filter, 1);
rb_define_method(cDevice, "channel=", Lorcon_set_channel, 1);
+ rb_define_method(cDevice, "channel", Lorcon_get_channel, 0);
rb_define_method(cDevice, "loop", Lorcon_capture_loop, -1);
rb_define_method(cDevice, "each", Lorcon_capture_loop, -1);
@@ -44,7 +44,7 @@ def self.run_simple(omod, opts = {})
# Clone the module to prevent changes to the original instance
mod = omod.replicant
- Msf::Simple::Framework.simplify_module(mod)
+ Msf::Simple::Framework.simplify_module( mod, false )
# Import options from the OptionStr or Option hash.
mod._import_extra_options(opts)
@@ -60,7 +60,7 @@ def self.exploit_simple(oexploit, opts)
# Clone the module to prevent changes to the original instance
exploit = oexploit.replicant
- Msf::Simple::Framework.simplify_module( exploit )
+ Msf::Simple::Framework.simplify_module( exploit, false )
# Import options from the OptionStr or Option hash.
@@ -136,12 +136,12 @@ def self.simplify(framework, opts)
# Simplifies a module instance if the type is supported by extending it
# with the simplified module interface.
#
- def self.simplify_module(instance)
+ def self.simplify_module(instance, load_saved_config = true)
if ((ModuleSimplifiers[instance.type]) and
(instance.class.include?(ModuleSimplifiers[instance.type]) == false))
instance.extend(ModuleSimplifiers[instance.type])
- instance.init_simplified
+ instance.init_simplified(load_saved_config)
end
end
@@ -32,8 +32,8 @@ def inspect
#
# Initializes the simplified interface.
#
- def init_simplified
- load_config
+ def init_simplified(load_saved_config=true)
+ load_config if load_saved_config
end
#
@@ -40,7 +40,7 @@ def self.run_simple(omod, opts = {})
# Clone the module to prevent changes to the original instance
mod = omod.replicant
- Msf::Simple::Framework.simplify_module( mod )
+ Msf::Simple::Framework.simplify_module( mod, false )
# Import options from the OptionStr or Option hash.
mod._import_extra_options(opts)
@@ -60,14 +60,17 @@ def process_uri_resource(uri_match)
uri_match
end
-
+
#
# Create a URI that matches a given checksum
#
def generate_uri_checksum(sum)
- 0.upto(1000) do
- uri = Rex::Text.rand_text_alphanumeric(4)
- return uri if Rex::Text.checksum8(uri) == sum
+ chk = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
+ 32.times do
+ uri = Rex::Text.rand_text_alphanumeric(3)
+ chk.sort_by {rand}.each do |x|
+ return(uri + x) if Rex::Text.checksum8(uri + x) == sum
+ end
end
raise RuntimeError, "Unable to generate a string with checksum #{sum}"
end
@@ -61,18 +61,21 @@ def process_uri_resource(uri_match)
uri_match
end
-
+
#
# Create a URI that matches a given checksum
#
def generate_uri_checksum(sum)
- 0.upto(1000) do
- uri = Rex::Text.rand_text_alphanumeric(4)
- return uri if Rex::Text.checksum8(uri) == sum
+ chk = ("a".."z").to_a + ("A".."Z").to_a + ("0".."9").to_a
+ 32.times do
+ uri = Rex::Text.rand_text_alphanumeric(3)
+ chk.sort_by {rand}.each do |x|
+ return(uri + x) if Rex::Text.checksum8(uri + x) == sum
+ end
end
raise RuntimeError, "Unable to generate a string with checksum #{sum}"
end
-
+
#
# Initializes the HTTP SSL tunneling handler.
#
View
@@ -720,6 +720,8 @@ def search_filter(search_string)
match = [t,w] if refs.any? { |ref| ref =~ /^bid\-/i and ref =~ r }
when 'osvdb'
match = [t,w] if refs.any? { |ref| ref =~ /^osvdb\-/i and ref =~ r }
+ when 'edb'
+ match = [t,w] if refs.any? { |ref| ref =~ /^edb\-/i and ref =~ r }
end
break if match
end
@@ -101,6 +101,8 @@ def initialize(in_ctx_id = 'Unknown', in_ctx_val = '')
self.site = 'http://www.microsoft.com/technet/security/bulletin/' + in_ctx_val.to_s + '.mspx'
elsif (in_ctx_id == 'MIL')
self.site = 'http://milw0rm.com/metasploit/' + in_ctx_val.to_s
+ elsif (in_ctx_id == 'EDB')
+ self.site = 'http://www.exploit-db.com/exploits/' + in_ctx_val.to_s
elsif (in_ctx_id == 'WVE')
self.site = 'http://www.wirelessve.org/entries/show/WVE-' + in_ctx_val.to_s
elsif (in_ctx_id == 'US-CERT-VU')
@@ -1303,7 +1303,8 @@ def cmd_search_help
"author" => "Modules written by this author",
"cve" => "Modules with a matching CVE ID",
"bid" => "Modules with a matching Bugtraq ID",
- "osvdb" => "Modules with a matching OSVDB ID"
+ "osvdb" => "Modules with a matching OSVDB ID",
+ "edb" => "Modules with a matching Exploit-DB ID"
}.each_pair do |keyword, description|
print_line " #{keyword.ljust 10}: #{description}"
end
View
@@ -32,6 +32,7 @@ module Text
UpperAlpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
LowerAlpha = "abcdefghijklmnopqrstuvwxyz"
Numerals = "0123456789"
+ Base32 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"
Alpha = UpperAlpha + LowerAlpha
AlphaNumeric = Alpha + Numerals
HighAscii = [*(0x80 .. 0xff)].pack("C*")
@@ -693,6 +694,83 @@ def self.hexify(str, col = DefaultWrap, line_start = '', line_end = '', buf_star
##
#
+ # Base32 code
+ #
+
+ # Based on --> https://github.com/stesla/base32
+
+ # Copyright (c) 2007-2011 Samuel Tesla
+
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
+ # of this software and associated documentation files (the "Software"), to deal
+ # in the Software without restriction, including without limitation the rights
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ # copies of the Software, and to permit persons to whom the Software is
+ # furnished to do so, subject to the following conditions:
+
+ # The above copyright notice and this permission notice shall be included in
+ # all copies or substantial portions of the Software.
+
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ # THE SOFTWARE.
+
+
+ #
+ # Base32 encoder
+ #
+ def self.b32encode(bytes_in)
+ n = (bytes_in.length * 8.0 / 5.0).ceil
+ p = n < 8 ? 5 - (bytes_in.length * 8) % 5 : 0
+ c = bytes_in.inject(0) {|m,o| (m << 8) + o} << p
+ [(0..n-1).to_a.reverse.collect {|i| Base32[(c >> i * 5) & 0x1f].chr},
+ ("=" * (8-n))]
+ end
+
+ def self.encode_base32(str)
+ bytes = str.bytes
+ result = ''
+ size= 5
+ while bytes.any? do
+ bytes.each_slice(size) do |a|
+ bytes_out = b32encode(a).flatten.join
+ result << bytes_out
+ bytes = bytes.drop(size)
+ end
+ end
+ return result
+ end
+
+ #
+ # Base32 decoder
+ #
+ def self.b32decode(bytes_in)
+ bytes = bytes_in.take_while {|c| c != 61} # strip padding
+ n = (bytes.length * 5.0 / 8.0).floor
+ p = bytes.length < 8 ? 5 - (n * 8) % 5 : 0
+ c = bytes.inject(0) {|m,o| (m << 5) + Base32.index(o.chr)} >> p
+ (0..n-1).to_a.reverse.collect {|i| ((c >> i * 8) & 0xff).chr}
+ end
+
+ def self.decode_base32(str)
+ bytes = str.bytes
+ result = ''
+ size= 8
+ while bytes.any? do
+ bytes.each_slice(size) do |a|
+ bytes_out = b32decode(a).flatten.join
+ result << bytes_out
+ bytes = bytes.drop(size)
+ end
+ end
+ return result
+ end
+
+ #
# Base64 encoder
#
def self.encode_base64(str, delim='')
@@ -1217,7 +1295,7 @@ def self.load_codepage()
def self.checksum8(str)
str.unpack("C*").inject(:+) % 0x100
end
-
+
def self.checksum16_le(str)
str.unpack("v*").inject(:+) % 0x10000
end
Oops, something went wrong.

0 comments on commit ce38997

Please sign in to comment.