Update RbMysql to the most recent code from this gem https://github.com/tmtm/ruby-mysql
This commit is contained in:
parent
ec37a88a4a
commit
278c56652e
|
@ -35,16 +35,7 @@ module Metasploit
|
|||
disconnect if self.sock
|
||||
connect
|
||||
|
||||
::RbMysql.connect({
|
||||
:host => host,
|
||||
:port => port,
|
||||
:read_timeout => 300,
|
||||
:write_timeout => 300,
|
||||
:socket => sock,
|
||||
:user => credential.public,
|
||||
:password => credential.private,
|
||||
:db => ''
|
||||
})
|
||||
::RbMysql.connect(host, credential.public, credential.private, '', port, sock)
|
||||
|
||||
rescue ::SystemCallError, Rex::ConnectionError => e
|
||||
result_options.merge!({
|
||||
|
|
|
@ -37,16 +37,8 @@ module Exploit::Remote::MYSQL
|
|||
connect
|
||||
|
||||
begin
|
||||
@mysql_handle = ::RbMysql.connect({
|
||||
:host => rhost,
|
||||
:port => rport,
|
||||
:read_timeout => 300,
|
||||
:write_timeout => 300,
|
||||
:socket => sock,
|
||||
:user => user,
|
||||
:password => pass,
|
||||
:db => db
|
||||
})
|
||||
@mysql_handle = ::RbMysql.connect(rhost, user, pass, db, rport, sock)
|
||||
|
||||
rescue Errno::ECONNREFUSED
|
||||
print_error("Connection refused")
|
||||
return false
|
||||
|
|
1432
lib/rbmysql.rb
1432
lib/rbmysql.rb
File diff suppressed because it is too large
Load Diff
|
@ -25,7 +25,7 @@ ALPHA バージョンです。将来のバージョンで互換がない変更
|
|||
|
||||
使用例:
|
||||
|
||||
Mysql.connect("mysql://username:password@hostname:3306/dbname") do |my|
|
||||
RbMysql.connect("mysql://username:password@hostname:3306/dbname") do |my|
|
||||
my.query("select col1, col2 from tblname").each do |col1, col2|
|
||||
p col1, col2
|
||||
end
|
||||
|
|
|
@ -1,161 +1,292 @@
|
|||
# -*- coding: binary -*-
|
||||
# Copyright (C) 2008 TOMITA Masahiro
|
||||
# coding: ascii-8bit
|
||||
# Copyright (C) 2008-2012 TOMITA Masahiro
|
||||
# mailto:tommy@tmtm.org
|
||||
|
||||
require "#{File.dirname __FILE__}/error"
|
||||
|
||||
#
|
||||
class RbMysql
|
||||
# @!attribute [r] number
|
||||
# @private
|
||||
# @!attribute [r] name
|
||||
# @return [String] charset name
|
||||
# @!attribute [r] csname
|
||||
# @return [String] collation name
|
||||
class Charset
|
||||
# @private
|
||||
# @param [Integer] number
|
||||
# @param [String] name
|
||||
# @param [String] csname
|
||||
def initialize(number, name, csname)
|
||||
@number, @name, @csname = number, name, csname
|
||||
@unsafe = false
|
||||
end
|
||||
|
||||
attr_reader :number, :name, :csname
|
||||
|
||||
# @private
|
||||
attr_accessor :unsafe
|
||||
|
||||
# [[charset_number, charset_name, collation_name, default], ...]
|
||||
# @private
|
||||
CHARSETS = [
|
||||
[ 1, "big5", "big5_chinese_ci", true ],
|
||||
[ 2, "latin2", "latin2_czech_cs", false],
|
||||
[ 3, "dec8", "dec8_swedish_ci", true ],
|
||||
[ 4, "cp850", "cp850_general_ci", true ],
|
||||
[ 5, "latin1", "latin1_german1_ci", false],
|
||||
[ 6, "hp8", "hp8_english_ci", true ],
|
||||
[ 7, "koi8r", "koi8r_general_ci", true ],
|
||||
[ 8, "latin1", "latin1_swedish_ci", true ],
|
||||
[ 9, "latin2", "latin2_general_ci", true ],
|
||||
[ 10, "swe7", "swe7_swedish_ci", true ],
|
||||
[ 11, "ascii", "ascii_general_ci", true ],
|
||||
[ 12, "ujis", "ujis_japanese_ci", true ],
|
||||
[ 13, "sjis", "sjis_japanese_ci", true ],
|
||||
[ 14, "cp1251", "cp1251_bulgarian_ci", false],
|
||||
[ 15, "latin1", "latin1_danish_ci", false],
|
||||
[ 16, "hebrew", "hebrew_general_ci", true ],
|
||||
[ 18, "tis620", "tis620_thai_ci", true ],
|
||||
[ 19, "euckr", "euckr_korean_ci", true ],
|
||||
[ 20, "latin7", "latin7_estonian_cs", false],
|
||||
[ 21, "latin2", "latin2_hungarian_ci", false],
|
||||
[ 22, "koi8u", "koi8u_general_ci", true ],
|
||||
[ 23, "cp1251", "cp1251_ukrainian_ci", false],
|
||||
[ 24, "gb2312", "gb2312_chinese_ci", true ],
|
||||
[ 25, "greek", "greek_general_ci", true ],
|
||||
[ 26, "cp1250", "cp1250_general_ci", true ],
|
||||
[ 27, "latin2", "latin2_croatian_ci", false],
|
||||
[ 28, "gbk", "gbk_chinese_ci", true ],
|
||||
[ 29, "cp1257", "cp1257_lithuanian_ci", false],
|
||||
[ 30, "latin5", "latin5_turkish_ci", true ],
|
||||
[ 31, "latin1", "latin1_german2_ci", false],
|
||||
[ 32, "armscii8", "armscii8_general_ci", true ],
|
||||
[ 33, "utf8", "utf8_general_ci", true ],
|
||||
[ 34, "cp1250", "cp1250_czech_cs", false],
|
||||
[ 35, "ucs2", "ucs2_general_ci", true ],
|
||||
[ 36, "cp866", "cp866_general_ci", true ],
|
||||
[ 37, "keybcs2", "keybcs2_general_ci", true ],
|
||||
[ 38, "macce", "macce_general_ci", true ],
|
||||
[ 39, "macroman", "macroman_general_ci", true ],
|
||||
[ 40, "cp852", "cp852_general_ci", true ],
|
||||
[ 41, "latin7", "latin7_general_ci", true ],
|
||||
[ 42, "latin7", "latin7_general_cs", false],
|
||||
[ 43, "macce", "macce_bin", false],
|
||||
[ 44, "cp1250", "cp1250_croatian_ci", false],
|
||||
[ 47, "latin1", "latin1_bin", false],
|
||||
[ 48, "latin1", "latin1_general_ci", false],
|
||||
[ 49, "latin1", "latin1_general_cs", false],
|
||||
[ 50, "cp1251", "cp1251_bin", false],
|
||||
[ 51, "cp1251", "cp1251_general_ci", true ],
|
||||
[ 52, "cp1251", "cp1251_general_cs", false],
|
||||
[ 53, "macroman", "macroman_bin", false],
|
||||
[ 57, "cp1256", "cp1256_general_ci", true ],
|
||||
[ 58, "cp1257", "cp1257_bin", false],
|
||||
[ 59, "cp1257", "cp1257_general_ci", true ],
|
||||
[ 63, "binary", "binary", true ],
|
||||
[ 64, "armscii8", "armscii8_bin", false],
|
||||
[ 65, "ascii", "ascii_bin", false],
|
||||
[ 66, "cp1250", "cp1250_bin", false],
|
||||
[ 67, "cp1256", "cp1256_bin", false],
|
||||
[ 68, "cp866", "cp866_bin", false],
|
||||
[ 69, "dec8", "dec8_bin", false],
|
||||
[ 70, "greek", "greek_bin", false],
|
||||
[ 71, "hebrew", "hebrew_bin", false],
|
||||
[ 72, "hp8", "hp8_bin", false],
|
||||
[ 73, "keybcs2", "keybcs2_bin", false],
|
||||
[ 74, "koi8r", "koi8r_bin", false],
|
||||
[ 75, "koi8u", "koi8u_bin", false],
|
||||
[ 77, "latin2", "latin2_bin", false],
|
||||
[ 78, "latin5", "latin5_bin", false],
|
||||
[ 79, "latin7", "latin7_bin", false],
|
||||
[ 80, "cp850", "cp850_bin", false],
|
||||
[ 81, "cp852", "cp852_bin", false],
|
||||
[ 82, "swe7", "swe7_bin", false],
|
||||
[ 83, "utf8", "utf8_bin", false],
|
||||
[ 84, "big5", "big5_bin", false],
|
||||
[ 85, "euckr", "euckr_bin", false],
|
||||
[ 86, "gb2312", "gb2312_bin", false],
|
||||
[ 87, "gbk", "gbk_bin", false],
|
||||
[ 88, "sjis", "sjis_bin", false],
|
||||
[ 89, "tis620", "tis620_bin", false],
|
||||
[ 90, "ucs2", "ucs2_bin", false],
|
||||
[ 91, "ujis", "ujis_bin", false],
|
||||
[ 92, "geostd8", "geostd8_general_ci", true ],
|
||||
[ 93, "geostd8", "geostd8_bin", false],
|
||||
[ 94, "latin1", "latin1_spanish_ci", false],
|
||||
[ 95, "cp932", "cp932_japanese_ci" , true ],
|
||||
[ 96, "cp932", "cp932_bin" , false],
|
||||
[ 97, "eucjpms", "eucjpms_japanese_ci", true ],
|
||||
[ 98, "eucjpms", "eucjpms_bin", false],
|
||||
[128, "ucs2", "ucs2_unicode_ci", false],
|
||||
[129, "ucs2", "ucs2_icelandic_ci", false],
|
||||
[130, "ucs2", "ucs2_latvian_ci", false],
|
||||
[131, "ucs2", "ucs2_romanian_ci", false],
|
||||
[132, "ucs2", "ucs2_slovenian_ci", false],
|
||||
[133, "ucs2", "ucs2_polish_ci", false],
|
||||
[134, "ucs2", "ucs2_estonian_ci", false],
|
||||
[135, "ucs2", "ucs2_spanish_ci", false],
|
||||
[136, "ucs2", "ucs2_swedish_ci", false],
|
||||
[137, "ucs2", "ucs2_turkish_ci", false],
|
||||
[138, "ucs2", "ucs2_czech_ci", false],
|
||||
[139, "ucs2", "ucs2_danish_ci", false],
|
||||
[140, "ucs2", "ucs2_lithuanian_ci", false],
|
||||
[141, "ucs2", "ucs2_slovak_ci", false],
|
||||
[142, "ucs2", "ucs2_spanish2_ci", false],
|
||||
[143, "ucs2", "ucs2_roman_ci", false],
|
||||
[144, "ucs2", "ucs2_persian_ci", false],
|
||||
[145, "ucs2", "ucs2_esperanto_ci", false],
|
||||
[146, "ucs2", "ucs2_hungarian_ci", false],
|
||||
[192, "utf8", "utf8_unicode_ci", false],
|
||||
[193, "utf8", "utf8_icelandic_ci", false],
|
||||
[194, "utf8", "utf8_latvian_ci", false],
|
||||
[195, "utf8", "utf8_romanian_ci", false],
|
||||
[196, "utf8", "utf8_slovenian_ci", false],
|
||||
[197, "utf8", "utf8_polish_ci", false],
|
||||
[198, "utf8", "utf8_estonian_ci", false],
|
||||
[199, "utf8", "utf8_spanish_ci", false],
|
||||
[200, "utf8", "utf8_swedish_ci", false],
|
||||
[201, "utf8", "utf8_turkish_ci", false],
|
||||
[202, "utf8", "utf8_czech_ci", false],
|
||||
[203, "utf8", "utf8_danish_ci", false],
|
||||
[204, "utf8", "utf8_lithuanian_ci", false],
|
||||
[205, "utf8", "utf8_slovak_ci", false],
|
||||
[206, "utf8", "utf8_spanish2_ci", false],
|
||||
[207, "utf8", "utf8_roman_ci", false],
|
||||
[208, "utf8", "utf8_persian_ci", false],
|
||||
[209, "utf8", "utf8_esperanto_ci", false],
|
||||
[210, "utf8", "utf8_hungarian_ci", false],
|
||||
[ 1, "big5", "big5_chinese_ci", true ],
|
||||
[ 2, "latin2", "latin2_czech_cs", false],
|
||||
[ 3, "dec8", "dec8_swedish_ci", true ],
|
||||
[ 4, "cp850", "cp850_general_ci", true ],
|
||||
[ 5, "latin1", "latin1_german1_ci", false],
|
||||
[ 6, "hp8", "hp8_english_ci", true ],
|
||||
[ 7, "koi8r", "koi8r_general_ci", true ],
|
||||
[ 8, "latin1", "latin1_swedish_ci", true ],
|
||||
[ 9, "latin2", "latin2_general_ci", true ],
|
||||
[ 10, "swe7", "swe7_swedish_ci", true ],
|
||||
[ 11, "ascii", "ascii_general_ci", true ],
|
||||
[ 12, "ujis", "ujis_japanese_ci", true ],
|
||||
[ 13, "sjis", "sjis_japanese_ci", true ],
|
||||
[ 14, "cp1251", "cp1251_bulgarian_ci", false],
|
||||
[ 15, "latin1", "latin1_danish_ci", false],
|
||||
[ 16, "hebrew", "hebrew_general_ci", true ],
|
||||
[ 17, "filename", "filename", true ],
|
||||
[ 18, "tis620", "tis620_thai_ci", true ],
|
||||
[ 19, "euckr", "euckr_korean_ci", true ],
|
||||
[ 20, "latin7", "latin7_estonian_cs", false],
|
||||
[ 21, "latin2", "latin2_hungarian_ci", false],
|
||||
[ 22, "koi8u", "koi8u_general_ci", true ],
|
||||
[ 23, "cp1251", "cp1251_ukrainian_ci", false],
|
||||
[ 24, "gb2312", "gb2312_chinese_ci", true ],
|
||||
[ 25, "greek", "greek_general_ci", true ],
|
||||
[ 26, "cp1250", "cp1250_general_ci", true ],
|
||||
[ 27, "latin2", "latin2_croatian_ci", false],
|
||||
[ 28, "gbk", "gbk_chinese_ci", true ],
|
||||
[ 29, "cp1257", "cp1257_lithuanian_ci", false],
|
||||
[ 30, "latin5", "latin5_turkish_ci", true ],
|
||||
[ 31, "latin1", "latin1_german2_ci", false],
|
||||
[ 32, "armscii8", "armscii8_general_ci", true ],
|
||||
[ 33, "utf8", "utf8_general_ci", true ],
|
||||
[ 34, "cp1250", "cp1250_czech_cs", false],
|
||||
[ 35, "ucs2", "ucs2_general_ci", true ],
|
||||
[ 36, "cp866", "cp866_general_ci", true ],
|
||||
[ 37, "keybcs2", "keybcs2_general_ci", true ],
|
||||
[ 38, "macce", "macce_general_ci", true ],
|
||||
[ 39, "macroman", "macroman_general_ci", true ],
|
||||
[ 40, "cp852", "cp852_general_ci", true ],
|
||||
[ 41, "latin7", "latin7_general_ci", true ],
|
||||
[ 42, "latin7", "latin7_general_cs", false],
|
||||
[ 43, "macce", "macce_bin", false],
|
||||
[ 44, "cp1250", "cp1250_croatian_ci", false],
|
||||
[ 45, "utf8mb4", "utf8mb4_general_ci", true ],
|
||||
[ 46, "utf8mb4", "utf8mb4_bin", false],
|
||||
[ 47, "latin1", "latin1_bin", false],
|
||||
[ 48, "latin1", "latin1_general_ci", false],
|
||||
[ 49, "latin1", "latin1_general_cs", false],
|
||||
[ 50, "cp1251", "cp1251_bin", false],
|
||||
[ 51, "cp1251", "cp1251_general_ci", true ],
|
||||
[ 52, "cp1251", "cp1251_general_cs", false],
|
||||
[ 53, "macroman", "macroman_bin", false],
|
||||
[ 54, "utf16", "utf16_general_ci", true ],
|
||||
[ 55, "utf16", "utf16_bin", false],
|
||||
[ 56, "utf16le", "utf16le_general_ci", true ],
|
||||
[ 57, "cp1256", "cp1256_general_ci", true ],
|
||||
[ 58, "cp1257", "cp1257_bin", false],
|
||||
[ 59, "cp1257", "cp1257_general_ci", true ],
|
||||
[ 60, "utf32", "utf32_general_ci", true ],
|
||||
[ 61, "utf32", "utf32_bin", false],
|
||||
[ 62, "utf16le", "utf16le_bin", false],
|
||||
[ 63, "binary", "binary", true ],
|
||||
[ 64, "armscii8", "armscii8_bin", false],
|
||||
[ 65, "ascii", "ascii_bin", false],
|
||||
[ 66, "cp1250", "cp1250_bin", false],
|
||||
[ 67, "cp1256", "cp1256_bin", false],
|
||||
[ 68, "cp866", "cp866_bin", false],
|
||||
[ 69, "dec8", "dec8_bin", false],
|
||||
[ 70, "greek", "greek_bin", false],
|
||||
[ 71, "hebrew", "hebrew_bin", false],
|
||||
[ 72, "hp8", "hp8_bin", false],
|
||||
[ 73, "keybcs2", "keybcs2_bin", false],
|
||||
[ 74, "koi8r", "koi8r_bin", false],
|
||||
[ 75, "koi8u", "koi8u_bin", false],
|
||||
[ 77, "latin2", "latin2_bin", false],
|
||||
[ 78, "latin5", "latin5_bin", false],
|
||||
[ 79, "latin7", "latin7_bin", false],
|
||||
[ 80, "cp850", "cp850_bin", false],
|
||||
[ 81, "cp852", "cp852_bin", false],
|
||||
[ 82, "swe7", "swe7_bin", false],
|
||||
[ 83, "utf8", "utf8_bin", false],
|
||||
[ 84, "big5", "big5_bin", false],
|
||||
[ 85, "euckr", "euckr_bin", false],
|
||||
[ 86, "gb2312", "gb2312_bin", false],
|
||||
[ 87, "gbk", "gbk_bin", false],
|
||||
[ 88, "sjis", "sjis_bin", false],
|
||||
[ 89, "tis620", "tis620_bin", false],
|
||||
[ 90, "ucs2", "ucs2_bin", false],
|
||||
[ 91, "ujis", "ujis_bin", false],
|
||||
[ 92, "geostd8", "geostd8_general_ci", true ],
|
||||
[ 93, "geostd8", "geostd8_bin", false],
|
||||
[ 94, "latin1", "latin1_spanish_ci", false],
|
||||
[ 95, "cp932", "cp932_japanese_ci", true ],
|
||||
[ 96, "cp932", "cp932_bin", false],
|
||||
[ 97, "eucjpms", "eucjpms_japanese_ci", true ],
|
||||
[ 98, "eucjpms", "eucjpms_bin", false],
|
||||
[ 99, "cp1250", "cp1250_polish_ci", false],
|
||||
[101, "utf16", "utf16_unicode_ci", false],
|
||||
[102, "utf16", "utf16_icelandic_ci", false],
|
||||
[103, "utf16", "utf16_latvian_ci", false],
|
||||
[104, "utf16", "utf16_romanian_ci", false],
|
||||
[105, "utf16", "utf16_slovenian_ci", false],
|
||||
[106, "utf16", "utf16_polish_ci", false],
|
||||
[107, "utf16", "utf16_estonian_ci", false],
|
||||
[108, "utf16", "utf16_spanish_ci", false],
|
||||
[109, "utf16", "utf16_swedish_ci", false],
|
||||
[110, "utf16", "utf16_turkish_ci", false],
|
||||
[111, "utf16", "utf16_czech_ci", false],
|
||||
[112, "utf16", "utf16_danish_ci", false],
|
||||
[113, "utf16", "utf16_lithuanian_ci", false],
|
||||
[114, "utf16", "utf16_slovak_ci", false],
|
||||
[115, "utf16", "utf16_spanish2_ci", false],
|
||||
[116, "utf16", "utf16_roman_ci", false],
|
||||
[117, "utf16", "utf16_persian_ci", false],
|
||||
[118, "utf16", "utf16_esperanto_ci", false],
|
||||
[119, "utf16", "utf16_hungarian_ci", false],
|
||||
[120, "utf16", "utf16_sinhala_ci", false],
|
||||
[121, "utf16", "utf16_german2_ci", false],
|
||||
[122, "utf16", "utf16_croatian_ci", false],
|
||||
[123, "utf16", "utf16_unicode_520_ci", false],
|
||||
[124, "utf16", "utf16_vietnamese_ci", false],
|
||||
[128, "ucs2", "ucs2_unicode_ci", false],
|
||||
[129, "ucs2", "ucs2_icelandic_ci", false],
|
||||
[130, "ucs2", "ucs2_latvian_ci", false],
|
||||
[131, "ucs2", "ucs2_romanian_ci", false],
|
||||
[132, "ucs2", "ucs2_slovenian_ci", false],
|
||||
[133, "ucs2", "ucs2_polish_ci", false],
|
||||
[134, "ucs2", "ucs2_estonian_ci", false],
|
||||
[135, "ucs2", "ucs2_spanish_ci", false],
|
||||
[136, "ucs2", "ucs2_swedish_ci", false],
|
||||
[137, "ucs2", "ucs2_turkish_ci", false],
|
||||
[138, "ucs2", "ucs2_czech_ci", false],
|
||||
[139, "ucs2", "ucs2_danish_ci", false],
|
||||
[140, "ucs2", "ucs2_lithuanian_ci", false],
|
||||
[141, "ucs2", "ucs2_slovak_ci", false],
|
||||
[142, "ucs2", "ucs2_spanish2_ci", false],
|
||||
[143, "ucs2", "ucs2_roman_ci", false],
|
||||
[144, "ucs2", "ucs2_persian_ci", false],
|
||||
[145, "ucs2", "ucs2_esperanto_ci", false],
|
||||
[146, "ucs2", "ucs2_hungarian_ci", false],
|
||||
[147, "ucs2", "ucs2_sinhala_ci", false],
|
||||
[148, "ucs2", "ucs2_german2_ci", false],
|
||||
[149, "ucs2", "ucs2_croatian_ci", false],
|
||||
[150, "ucs2", "ucs2_unicode_520_ci", false],
|
||||
[151, "ucs2", "ucs2_vietnamese_ci", false],
|
||||
[159, "ucs2", "ucs2_general_mysql500_ci", false],
|
||||
[160, "utf32", "utf32_unicode_ci", false],
|
||||
[161, "utf32", "utf32_icelandic_ci", false],
|
||||
[162, "utf32", "utf32_latvian_ci", false],
|
||||
[163, "utf32", "utf32_romanian_ci", false],
|
||||
[164, "utf32", "utf32_slovenian_ci", false],
|
||||
[165, "utf32", "utf32_polish_ci", false],
|
||||
[166, "utf32", "utf32_estonian_ci", false],
|
||||
[167, "utf32", "utf32_spanish_ci", false],
|
||||
[168, "utf32", "utf32_swedish_ci", false],
|
||||
[169, "utf32", "utf32_turkish_ci", false],
|
||||
[170, "utf32", "utf32_czech_ci", false],
|
||||
[171, "utf32", "utf32_danish_ci", false],
|
||||
[172, "utf32", "utf32_lithuanian_ci", false],
|
||||
[173, "utf32", "utf32_slovak_ci", false],
|
||||
[174, "utf32", "utf32_spanish2_ci", false],
|
||||
[175, "utf32", "utf32_roman_ci", false],
|
||||
[176, "utf32", "utf32_persian_ci", false],
|
||||
[177, "utf32", "utf32_esperanto_ci", false],
|
||||
[178, "utf32", "utf32_hungarian_ci", false],
|
||||
[179, "utf32", "utf32_sinhala_ci", false],
|
||||
[180, "utf32", "utf32_german2_ci", false],
|
||||
[181, "utf32", "utf32_croatian_ci", false],
|
||||
[182, "utf32", "utf32_unicode_520_ci", false],
|
||||
[183, "utf32", "utf32_vietnamese_ci", false],
|
||||
[192, "utf8", "utf8_unicode_ci", false],
|
||||
[193, "utf8", "utf8_icelandic_ci", false],
|
||||
[194, "utf8", "utf8_latvian_ci", false],
|
||||
[195, "utf8", "utf8_romanian_ci", false],
|
||||
[196, "utf8", "utf8_slovenian_ci", false],
|
||||
[197, "utf8", "utf8_polish_ci", false],
|
||||
[198, "utf8", "utf8_estonian_ci", false],
|
||||
[199, "utf8", "utf8_spanish_ci", false],
|
||||
[200, "utf8", "utf8_swedish_ci", false],
|
||||
[201, "utf8", "utf8_turkish_ci", false],
|
||||
[202, "utf8", "utf8_czech_ci", false],
|
||||
[203, "utf8", "utf8_danish_ci", false],
|
||||
[204, "utf8", "utf8_lithuanian_ci", false],
|
||||
[205, "utf8", "utf8_slovak_ci", false],
|
||||
[206, "utf8", "utf8_spanish2_ci", false],
|
||||
[207, "utf8", "utf8_roman_ci", false],
|
||||
[208, "utf8", "utf8_persian_ci", false],
|
||||
[209, "utf8", "utf8_esperanto_ci", false],
|
||||
[210, "utf8", "utf8_hungarian_ci", false],
|
||||
[211, "utf8", "utf8_sinhala_ci", false],
|
||||
[212, "utf8", "utf8_german2_ci", false],
|
||||
[213, "utf8", "utf8_croatian_ci", false],
|
||||
[214, "utf8", "utf8_unicode_520_ci", false],
|
||||
[215, "utf8", "utf8_vietnamese_ci", false],
|
||||
[223, "utf8", "utf8_general_mysql500_ci", false],
|
||||
[224, "utf8mb4", "utf8mb4_unicode_ci", false],
|
||||
[225, "utf8mb4", "utf8mb4_icelandic_ci", false],
|
||||
[226, "utf8mb4", "utf8mb4_latvian_ci", false],
|
||||
[227, "utf8mb4", "utf8mb4_romanian_ci", false],
|
||||
[228, "utf8mb4", "utf8mb4_slovenian_ci", false],
|
||||
[229, "utf8mb4", "utf8mb4_polish_ci", false],
|
||||
[230, "utf8mb4", "utf8mb4_estonian_ci", false],
|
||||
[231, "utf8mb4", "utf8mb4_spanish_ci", false],
|
||||
[232, "utf8mb4", "utf8mb4_swedish_ci", false],
|
||||
[233, "utf8mb4", "utf8mb4_turkish_ci", false],
|
||||
[234, "utf8mb4", "utf8mb4_czech_ci", false],
|
||||
[235, "utf8mb4", "utf8mb4_danish_ci", false],
|
||||
[236, "utf8mb4", "utf8mb4_lithuanian_ci", false],
|
||||
[237, "utf8mb4", "utf8mb4_slovak_ci", false],
|
||||
[238, "utf8mb4", "utf8mb4_spanish2_ci", false],
|
||||
[239, "utf8mb4", "utf8mb4_roman_ci", false],
|
||||
[240, "utf8mb4", "utf8mb4_persian_ci", false],
|
||||
[241, "utf8mb4", "utf8mb4_esperanto_ci", false],
|
||||
[242, "utf8mb4", "utf8mb4_hungarian_ci", false],
|
||||
[243, "utf8mb4", "utf8mb4_sinhala_ci", false],
|
||||
[244, "utf8mb4", "utf8mb4_german2_ci", false],
|
||||
[245, "utf8mb4", "utf8mb4_croatian_ci", false],
|
||||
[246, "utf8mb4", "utf8mb4_unicode_520_ci", false],
|
||||
[247, "utf8mb4", "utf8mb4_vietnamese_ci", false],
|
||||
[248, "gb18030", "gb18030_chinese_ci", true ],
|
||||
[249, "gb18030", "gb18030_bin", false],
|
||||
[250, "gb18030", "gb18030_unicode_520_ci", false],
|
||||
[254, "utf8", "utf8_general_cs", false],
|
||||
]
|
||||
|
||||
# @private
|
||||
UNSAFE_CHARSET = [
|
||||
"big5", "sjis", "filename", "gbk", "ucs2", "cp932",
|
||||
]
|
||||
|
||||
# @private
|
||||
NUMBER_TO_CHARSET = {}
|
||||
# @private
|
||||
COLLATION_TO_CHARSET = {}
|
||||
# @private
|
||||
CHARSET_DEFAULT = {}
|
||||
CHARSETS.each do |number, csname, clname, default|
|
||||
cs = Charset.new number, csname, clname
|
||||
cs.unsafe = true if UNSAFE_CHARSET.include? csname
|
||||
NUMBER_TO_CHARSET[number] = cs
|
||||
COLLATION_TO_CHARSET[clname] = cs
|
||||
CHARSET_DEFAULT[csname] = cs if default
|
||||
end
|
||||
|
||||
# @private
|
||||
BINARY_CHARSET_NUMBER = CHARSET_DEFAULT['binary'].number
|
||||
|
||||
# @private
|
||||
# @param [Integer] n
|
||||
# @return [RbMysql::Charset]
|
||||
def self.by_number(n)
|
||||
raise ClientError, "unknown charset number: #{n}" unless NUMBER_TO_CHARSET.key? n
|
||||
NUMBER_TO_CHARSET[n]
|
||||
end
|
||||
|
||||
# @private
|
||||
# @param [String] str
|
||||
# @return [RbMysql::Charset]
|
||||
def self.by_name(str)
|
||||
ret = COLLATION_TO_CHARSET[str] || CHARSET_DEFAULT[str]
|
||||
raise ClientError, "unknown charset: #{str}" unless ret
|
||||
|
@ -164,75 +295,84 @@ class RbMysql
|
|||
|
||||
if defined? Encoding
|
||||
|
||||
# @private
|
||||
# MySQL Charset -> Ruby's Encoding
|
||||
CHARSET_ENCODING = {
|
||||
"armscii8" => nil,
|
||||
"ascii" => ::Encoding::US_ASCII,
|
||||
"big5" => ::Encoding::Big5,
|
||||
"binary" => ::Encoding::ASCII_8BIT,
|
||||
"cp1250" => ::Encoding::Windows_1250,
|
||||
"cp1251" => ::Encoding::Windows_1251,
|
||||
"cp1256" => ::Encoding::Windows_1256,
|
||||
"cp1257" => ::Encoding::Windows_1257,
|
||||
"cp850" => ::Encoding::CP850,
|
||||
"cp852" => ::Encoding::CP852,
|
||||
"cp866" => ::Encoding::IBM866,
|
||||
"cp932" => ::Encoding::Windows_31J,
|
||||
"ascii" => Encoding::US_ASCII,
|
||||
"big5" => Encoding::Big5,
|
||||
"binary" => Encoding::ASCII_8BIT,
|
||||
"cp1250" => Encoding::Windows_1250,
|
||||
"cp1251" => Encoding::Windows_1251,
|
||||
"cp1256" => Encoding::Windows_1256,
|
||||
"cp1257" => Encoding::Windows_1257,
|
||||
"cp850" => Encoding::CP850,
|
||||
"cp852" => Encoding::CP852,
|
||||
"cp866" => Encoding::IBM866,
|
||||
"cp932" => Encoding::Windows_31J,
|
||||
"dec8" => nil,
|
||||
"eucjpms" => ::Encoding::EucJP_ms,
|
||||
"euckr" => ::Encoding::EUC_KR,
|
||||
"gb2312" => ::Encoding::EUC_CN,
|
||||
"gbk" => ::Encoding::GBK,
|
||||
"eucjpms" => Encoding::EucJP_ms,
|
||||
"euckr" => Encoding::EUC_KR,
|
||||
"gb2312" => Encoding::EUC_CN,
|
||||
"gbk" => Encoding::GBK,
|
||||
"geostd8" => nil,
|
||||
"greek" => ::Encoding::ISO_8859_7,
|
||||
"hebrew" => ::Encoding::ISO_8859_8,
|
||||
"greek" => Encoding::ISO_8859_7,
|
||||
"hebrew" => Encoding::ISO_8859_8,
|
||||
"hp8" => nil,
|
||||
"keybcs2" => nil,
|
||||
"koi8r" => ::Encoding::KOI8_R,
|
||||
"koi8u" => ::Encoding::KOI8_U,
|
||||
"latin1" => ::Encoding::ISO_8859_1,
|
||||
"latin2" => ::Encoding::ISO_8859_2,
|
||||
"latin5" => ::Encoding::ISO_8859_9,
|
||||
"latin7" => ::Encoding::ISO_8859_13,
|
||||
"macce" => ::Encoding::MacCentEuro,
|
||||
"macroman" => ::Encoding::MacRoman,
|
||||
"sjis" => ::Encoding::SHIFT_JIS,
|
||||
"koi8r" => Encoding::KOI8_R,
|
||||
"koi8u" => Encoding::KOI8_U,
|
||||
"latin1" => Encoding::ISO_8859_1,
|
||||
"latin2" => Encoding::ISO_8859_2,
|
||||
"latin5" => Encoding::ISO_8859_9,
|
||||
"latin7" => Encoding::ISO_8859_13,
|
||||
"macce" => Encoding::MacCentEuro,
|
||||
"macroman" => Encoding::MacRoman,
|
||||
"sjis" => Encoding::SHIFT_JIS,
|
||||
"swe7" => nil,
|
||||
"tis620" => nil,
|
||||
"ucs2" => ::Encoding::UTF_16BE,
|
||||
"ujis" => ::Encoding::EucJP_ms,
|
||||
"utf8" => ::Encoding::UTF_8,
|
||||
"tis620" => Encoding::TIS_620,
|
||||
"ucs2" => Encoding::UTF_16BE,
|
||||
"ujis" => Encoding::EucJP_ms,
|
||||
"utf8" => Encoding::UTF_8,
|
||||
"utf8mb4" => Encoding::UTF_8,
|
||||
}
|
||||
|
||||
# @private
|
||||
# @param [String] value
|
||||
# @return [String]
|
||||
def self.to_binary(value)
|
||||
value.dup.force_encoding ::Encoding::ASCII_8BIT
|
||||
value.force_encoding Encoding::ASCII_8BIT
|
||||
end
|
||||
|
||||
# return corresponding Ruby encoding
|
||||
# === Return
|
||||
# encoding [Encoding]
|
||||
# @private
|
||||
# convert raw to encoding and convert to Encoding.default_internal
|
||||
# @param [String] raw
|
||||
# @param [Encoding] encoding
|
||||
# @return [String] result
|
||||
def self.convert_encoding(raw, encoding)
|
||||
raw.force_encoding(encoding).encode
|
||||
end
|
||||
|
||||
# @private
|
||||
# retrun corresponding Ruby encoding
|
||||
# @return [Encoding] encoding
|
||||
def encoding
|
||||
enc = CHARSET_ENCODING[@name.downcase]
|
||||
raise RbMysql::ClientError, "unsupported charset: #{@name}" unless enc
|
||||
enc
|
||||
end
|
||||
|
||||
# convert encoding corresponding to MySQL charset
|
||||
# @private
|
||||
# convert encoding to corrensponding to MySQL charset
|
||||
# @param [String] value
|
||||
# @return [String]
|
||||
def convert(value)
|
||||
if value.is_a? String and value.encoding != ::Encoding::ASCII_8BIT
|
||||
if value.is_a? String and value.encoding != Encoding::ASCII_8BIT
|
||||
value = value.encode encoding
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
# convert encoding from MySQL charset to Ruby
|
||||
def force_encoding(value)
|
||||
if value.is_a? String
|
||||
value = value.dup.force_encoding encoding
|
||||
end
|
||||
value
|
||||
end
|
||||
|
||||
else
|
||||
# for Ruby 1.8
|
||||
|
||||
|
@ -240,6 +380,10 @@ class RbMysql
|
|||
value
|
||||
end
|
||||
|
||||
def self.convert_encoding(raw, encoding)
|
||||
raw
|
||||
end
|
||||
|
||||
def encoding
|
||||
nil
|
||||
end
|
||||
|
@ -248,10 +392,6 @@ class RbMysql
|
|||
value
|
||||
end
|
||||
|
||||
def force_encoding(value)
|
||||
value
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,269 +0,0 @@
|
|||
# -*- coding: binary -*-
|
||||
# Copyright (C) 2008 TOMITA Masahiro
|
||||
# mailto:tommy@tmtm.org
|
||||
|
||||
# for compatibility
|
||||
|
||||
class RbMysql
|
||||
class << self
|
||||
|
||||
def connect(*args)
|
||||
my = self.allocate
|
||||
my.instance_eval{initialize}
|
||||
my.connect(*args)
|
||||
my
|
||||
end
|
||||
alias new connect
|
||||
alias real_connect connect
|
||||
|
||||
def init
|
||||
my = self.allocate
|
||||
my.instance_eval{initialize}
|
||||
my
|
||||
end
|
||||
|
||||
def client_version
|
||||
50067
|
||||
end
|
||||
|
||||
def client_info
|
||||
"5.0.67"
|
||||
end
|
||||
alias get_client_info client_info
|
||||
|
||||
def escape_string(str)
|
||||
str.gsub(/[\0\n\r\\\'\"\x1a]/n) do |s|
|
||||
case s
|
||||
when "\0" then "\\0"
|
||||
when "\n" then "\\n"
|
||||
when "\r" then "\\r"
|
||||
when "\x1a" then "\\Z"
|
||||
else "\\#{s}"
|
||||
end
|
||||
end
|
||||
end
|
||||
alias quote escape_string
|
||||
end
|
||||
|
||||
attr_accessor :query_with_result, :reconnect
|
||||
|
||||
alias stmt_init statement
|
||||
alias real_connect connect
|
||||
alias initialize_orig initialize
|
||||
|
||||
def initialize(*args)
|
||||
initialize_orig(*args)
|
||||
@query_with_result = true
|
||||
@reconnect = false
|
||||
end
|
||||
|
||||
def query(str)
|
||||
res = simple_query str
|
||||
if res
|
||||
res.each do |rec|
|
||||
rec.map!{|v| v && v.to_s}
|
||||
rec.each_index do |i|
|
||||
@fields[i].max_length = [rec[i] ? rec[i].length : 0, @fields[i].max_length||0].max
|
||||
end
|
||||
end
|
||||
res.data_seek 0
|
||||
end
|
||||
res
|
||||
end
|
||||
|
||||
def client_version
|
||||
self.class.client_version
|
||||
end
|
||||
|
||||
def options(opt, val=nil)
|
||||
case opt
|
||||
when INIT_COMMAND
|
||||
@init_command = val
|
||||
when OPT_COMPRESS
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_CONNECT_TIMEOUT
|
||||
@connect_timeout = val
|
||||
when OPT_GUESS_CONNECTION
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_LOCAL_INFILE
|
||||
@local_infile = val
|
||||
when OPT_NAMED_PIPE
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_PROTOCOL
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_READ_TIMEOUT
|
||||
@read_timeout = val
|
||||
when OPT_USE_EMBEDDED_CONNECTION
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_USE_REMOTE_CONNECTION
|
||||
raise ClientError, "not implemented"
|
||||
when OPT_WRITE_TIMEOUT
|
||||
@write_timeout = val
|
||||
when READ_DEFAULT_FILE
|
||||
raise ClientError, "not implemented"
|
||||
when READ_DEFAULT_GROUP
|
||||
raise ClientError, "not implemented"
|
||||
when SECURE_AUTH
|
||||
raise ClientError, "not implemented"
|
||||
when SET_CHARSET_DIR
|
||||
raise ClientError, "not implemented"
|
||||
when SET_CHARSET_NAME
|
||||
self.charset = val
|
||||
when SET_CLIENT_IP
|
||||
raise ClientError, "not implemented"
|
||||
when SHARED_MEMORY_BASE_NAME
|
||||
raise ClientError, "not implemented"
|
||||
else
|
||||
raise ClientError, "unknown option: #{opt}"
|
||||
end
|
||||
self
|
||||
end
|
||||
|
||||
def store_result
|
||||
raise ClientError, "no result set" unless @fields
|
||||
Result.new @fields, @stream
|
||||
end
|
||||
|
||||
def use_result
|
||||
raise ClientError, "no result set" unless @fields
|
||||
Result.new @fields, @stream, false
|
||||
end
|
||||
|
||||
class Result
|
||||
alias initialize_orig initialize
|
||||
def initialize(*args)
|
||||
initialize_orig *args
|
||||
@field_index = 0
|
||||
end
|
||||
|
||||
def num_rows
|
||||
@records.length
|
||||
end
|
||||
|
||||
def data_seek(n)
|
||||
@index = n
|
||||
end
|
||||
|
||||
def row_tell
|
||||
@index
|
||||
end
|
||||
|
||||
def row_seek(n)
|
||||
ret = @index
|
||||
@index = n
|
||||
ret
|
||||
end
|
||||
|
||||
def free
|
||||
# do nothing
|
||||
end
|
||||
|
||||
alias fetch_row_orig fetch_row
|
||||
def fetch_row
|
||||
@fetched_record = fetch_row_orig
|
||||
end
|
||||
|
||||
def fetch_field
|
||||
return nil if @field_index >= @fields.length
|
||||
ret = @fields[@field_index]
|
||||
@field_index += 1
|
||||
ret
|
||||
end
|
||||
|
||||
def field_tell
|
||||
@field_index
|
||||
end
|
||||
|
||||
def field_seek(n)
|
||||
@field_index = n
|
||||
end
|
||||
|
||||
def fetch_field_direct(n)
|
||||
raise ClientError, "invalid argument: #{n}" if n < 0 or n >= @fields.length
|
||||
@fields[n]
|
||||
end
|
||||
|
||||
def fetch_fields
|
||||
@fields
|
||||
end
|
||||
|
||||
def fetch_lengths
|
||||
return nil unless @fetched_record
|
||||
@fetched_record.map{|c|c.nil? ? 0 : c.length}
|
||||
end
|
||||
|
||||
def num_fields
|
||||
@fields.length
|
||||
end
|
||||
end
|
||||
|
||||
class Field
|
||||
attr_accessor :max_length
|
||||
def hash
|
||||
{
|
||||
"name" => @name,
|
||||
"table" => @table,
|
||||
"def" => @default,
|
||||
"type" => @type,
|
||||
"length" => @length,
|
||||
"max_length" => @max_length,
|
||||
"flags" => @flags,
|
||||
"decimals" => @decimals
|
||||
}
|
||||
end
|
||||
def inspect
|
||||
"#<RbMysql::Field:#{@name}>"
|
||||
end
|
||||
end
|
||||
|
||||
class Statement
|
||||
alias execute_orig execute
|
||||
def execute(*args)
|
||||
@res = execute_orig *args
|
||||
end
|
||||
|
||||
def fetch
|
||||
@res.fetch
|
||||
end
|
||||
alias fetch_row fetch
|
||||
|
||||
def each(*args, &block)
|
||||
@res.each(*args, &block)
|
||||
end
|
||||
|
||||
def num_rows
|
||||
@res.num_rows
|
||||
end
|
||||
|
||||
def data_seek(n)
|
||||
@res.data_seek(n)
|
||||
end
|
||||
|
||||
def row_tell
|
||||
@res.row_tell
|
||||
end
|
||||
|
||||
def row_seek(n)
|
||||
@res.row_seek(n)
|
||||
end
|
||||
|
||||
def field_count
|
||||
@fields.length
|
||||
end
|
||||
|
||||
def free_result
|
||||
# do nothing
|
||||
end
|
||||
|
||||
def result_metadata
|
||||
return nil if @fields.empty?
|
||||
res = Result.allocate
|
||||
res.instance_variable_set :@mysql, @mysql
|
||||
res.instance_variable_set :@fields, @fields
|
||||
res.instance_variable_set :@records, []
|
||||
res
|
||||
end
|
||||
end
|
||||
Stmt = Statement
|
||||
end
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
# -*- coding: binary -*-
|
||||
# coding: ascii-8bit
|
||||
# Copyright (C) 2003-2008 TOMITA Masahiro
|
||||
# mailto:tommy@tmtm.org
|
||||
|
||||
|
@ -33,26 +33,38 @@ class RbMysql
|
|||
COM_STMT_RESET = 26
|
||||
COM_SET_OPTION = 27
|
||||
COM_STMT_FETCH = 28
|
||||
COM_DAEMON = 29
|
||||
COM_BINLOG_DUMP_GTID = 30
|
||||
COM_RESET_CONNECTION = 31
|
||||
|
||||
# Client flag
|
||||
CLIENT_LONG_PASSWORD = 1 # new more secure passwords
|
||||
CLIENT_FOUND_ROWS = 1 << 1 # Found instead of affected rows
|
||||
CLIENT_LONG_FLAG = 1 << 2 # Get all column flags
|
||||
CLIENT_CONNECT_WITH_DB = 1 << 3 # One can specify db on connect
|
||||
CLIENT_NO_SCHEMA = 1 << 4 # Don't allow database.table.column
|
||||
CLIENT_COMPRESS = 1 << 5 # Can use compression protocol
|
||||
CLIENT_ODBC = 1 << 6 # Odbc client
|
||||
CLIENT_LOCAL_FILES = 1 << 7 # Can use LOAD DATA LOCAL
|
||||
CLIENT_IGNORE_SPACE = 1 << 8 # Ignore spaces before '('
|
||||
CLIENT_PROTOCOL_41 = 1 << 9 # New 4.1 protocol
|
||||
CLIENT_INTERACTIVE = 1 << 10 # This is an interactive client
|
||||
CLIENT_SSL = 1 << 11 # Switch to SSL after handshake
|
||||
CLIENT_IGNORE_SIGPIPE = 1 << 12 # IGNORE sigpipes
|
||||
CLIENT_TRANSACTIONS = 1 << 13 # Client knows about transactions
|
||||
CLIENT_RESERVED = 1 << 14 # Old flag for 4.1 protocol
|
||||
CLIENT_SECURE_CONNECTION = 1 << 15 # New 4.1 authentication
|
||||
CLIENT_MULTI_STATEMENTS = 1 << 16 # Enable/disable multi-stmt support
|
||||
CLIENT_MULTI_RESULTS = 1 << 17 # Enable/disable multi-results
|
||||
CLIENT_LONG_PASSWORD = 1 # new more secure passwords
|
||||
CLIENT_FOUND_ROWS = 1 << 1 # Found instead of affected rows
|
||||
CLIENT_LONG_FLAG = 1 << 2 # Get all column flags
|
||||
CLIENT_CONNECT_WITH_DB = 1 << 3 # One can specify db on connect
|
||||
CLIENT_NO_SCHEMA = 1 << 4 # Don't allow database.table.column
|
||||
CLIENT_COMPRESS = 1 << 5 # Can use compression protocol
|
||||
CLIENT_ODBC = 1 << 6 # Odbc client
|
||||
CLIENT_LOCAL_FILES = 1 << 7 # Can use LOAD DATA LOCAL
|
||||
CLIENT_IGNORE_SPACE = 1 << 8 # Ignore spaces before '('
|
||||
CLIENT_PROTOCOL_41 = 1 << 9 # New 4.1 protocol
|
||||
CLIENT_INTERACTIVE = 1 << 10 # This is an interactive client
|
||||
CLIENT_SSL = 1 << 11 # Switch to SSL after handshake
|
||||
CLIENT_IGNORE_SIGPIPE = 1 << 12 # IGNORE sigpipes
|
||||
CLIENT_TRANSACTIONS = 1 << 13 # Client knows about transactions
|
||||
CLIENT_RESERVED = 1 << 14 # Old flag for 4.1 protocol
|
||||
CLIENT_SECURE_CONNECTION = 1 << 15 # New 4.1 authentication
|
||||
CLIENT_MULTI_STATEMENTS = 1 << 16 # Enable/disable multi-stmt support
|
||||
CLIENT_MULTI_RESULTS = 1 << 17 # Enable/disable multi-results
|
||||
CLIENT_PS_MULTI_RESULTS = 1 << 18 # Multi-results in PS-protocol
|
||||
CLIENT_PLUGIN_AUTH = 1 << 19 # Client supports plugin authentication
|
||||
CLIENT_CONNECT_ATTRS = 1 << 20 # Client supports connection attribute
|
||||
CLIENT_PLUGIN_AUTH_LENENC_CLIENT_DATA = 1 << 21 # Enable authentication response packet to be larger than 255 bytes.
|
||||
CLIENT_CAN_HANDLE_EXPIRED_PASSWORDS = 1 << 22 # Don't close the connection for a connection with expired password.
|
||||
CLIENT_SESSION_TRACK = 1 << 23 # Capable of handling server state change information. Its a hint to the server to include the state change information in Ok packet.
|
||||
CLIENT_DEPRECATE_EOF = 1 << 24 # Client no longer needs EOF packet
|
||||
CLIENT_SSL_VERIFY_SERVER_CERT = 1 << 30
|
||||
CLIENT_REMEMBER_OPTIONS = 1 << 31
|
||||
|
||||
# Connection Option
|
||||
OPT_CONNECT_TIMEOUT = 0
|
||||
|
@ -92,18 +104,35 @@ class RbMysql
|
|||
SERVER_STATUS_LAST_ROW_SENT = 1 << 7
|
||||
SERVER_STATUS_DB_DROPPED = 1 << 8
|
||||
SERVER_STATUS_NO_BACKSLASH_ESCAPES = 1 << 9
|
||||
SERVER_STATUS_METADATA_CHANGED = 1 << 10
|
||||
SERVER_QUERY_WAS_SLOW = 1 << 11
|
||||
SERVER_PS_OUT_PARAMS = 1 << 12
|
||||
SERVER_STATUS_IN_TRANS_READONLY = 1 << 13
|
||||
SERVER_SESSION_STATE_CHANGED = 1 << 14
|
||||
|
||||
# Refresh parameter
|
||||
REFRESH_GRANT = 1
|
||||
REFRESH_LOG = 1 << 1
|
||||
REFRESH_TABLES = 1 << 2
|
||||
REFRESH_HOSTS = 1 << 3
|
||||
REFRESH_STATUS = 1 << 4
|
||||
REFRESH_THREADS = 1 << 5
|
||||
REFRESH_SLAVE = 1 << 6
|
||||
REFRESH_MASTER = 1 << 7
|
||||
REFRESH_READ_LOCK = 1 << 14
|
||||
REFRESH_FAST = 1 << 15
|
||||
REFRESH_GRANT = 1
|
||||
REFRESH_LOG = 1 << 1
|
||||
REFRESH_TABLES = 1 << 2
|
||||
REFRESH_HOSTS = 1 << 3
|
||||
REFRESH_STATUS = 1 << 4
|
||||
REFRESH_THREADS = 1 << 5
|
||||
REFRESH_SLAVE = 1 << 6
|
||||
REFRESH_MASTER = 1 << 7
|
||||
REFRESH_ERROR_LOG = 1 << 8
|
||||
REFRESH_ENGINE_LOG = 1 << 9
|
||||
REFRESH_BINARY_LOG = 1 << 10
|
||||
REFRESH_RELAY_LOG = 1 << 11
|
||||
REFRESH_GENERAL_LOG = 1 << 12
|
||||
REFRESH_SLOW_LOG = 1 << 13
|
||||
REFRESH_READ_LOCK = 1 << 14
|
||||
REFRESH_FAST = 1 << 15
|
||||
REFRESH_QUERY_CACHE = 1 << 16
|
||||
REFRESH_QUERY_CACHE_FREE = 1 << 17
|
||||
REFRESH_DES_KEY_FILE = 1 << 18
|
||||
REFRESH_USER_RESOURCES = 1 << 19
|
||||
REFRESH_FOR_EXPORT = 1 << 20
|
||||
REFRESH_OPTIMIZER_COSTS = 1 << 21
|
||||
|
||||
class Field
|
||||
# Field type
|
||||
|
@ -124,6 +153,10 @@ class RbMysql
|
|||
TYPE_NEWDATE = 14
|
||||
TYPE_VARCHAR = 15
|
||||
TYPE_BIT = 16
|
||||
TYPE_TIMESTAMP2 = 17
|
||||
TYPE_DATETIME2 = 18
|
||||
TYPE_TIME2 = 19
|
||||
TYPE_JSON = 245
|
||||
TYPE_NEWDECIMAL = 246
|
||||
TYPE_ENUM = 247
|
||||
TYPE_SET = 248
|
||||
|
@ -138,29 +171,32 @@ class RbMysql
|
|||
TYPE_INTERVAL = TYPE_ENUM
|
||||
|
||||
# Flag
|
||||
NOT_NULL_FLAG = 1
|
||||
PRI_KEY_FLAG = 2
|
||||
UNIQUE_KEY_FLAG = 4
|
||||
MULTIPLE_KEY_FLAG = 8
|
||||
BLOB_FLAG = 16
|
||||
UNSIGNED_FLAG = 32
|
||||
ZEROFILL_FLAG = 64
|
||||
BINARY_FLAG = 128
|
||||
ENUM_FLAG = 256
|
||||
AUTO_INCREMENT_FLAG = 512
|
||||
TIMESTAMP_FLAG = 1024
|
||||
SET_FLAG = 2048
|
||||
NUM_FLAG = 32768
|
||||
PART_KEY_FLAG = 16384
|
||||
GROUP_FLAG = 32768
|
||||
UNIQUE_FLAG = 65536
|
||||
BINCMP_FLAG = 131072
|
||||
NOT_NULL_FLAG = 1
|
||||
PRI_KEY_FLAG = 2
|
||||
UNIQUE_KEY_FLAG = 4
|
||||
MULTIPLE_KEY_FLAG = 8
|
||||
BLOB_FLAG = 16
|
||||
UNSIGNED_FLAG = 32
|
||||
ZEROFILL_FLAG = 64
|
||||
BINARY_FLAG = 128
|
||||
ENUM_FLAG = 256
|
||||
AUTO_INCREMENT_FLAG = 512
|
||||
TIMESTAMP_FLAG = 1024
|
||||
SET_FLAG = 2048
|
||||
NO_DEFAULT_VALUE_FLAG = 4096
|
||||
ON_UPDATE_NOW_FLAG = 8192
|
||||
NUM_FLAG = 32768
|
||||
PART_KEY_FLAG = 16384
|
||||
GROUP_FLAG = 32768
|
||||
UNIQUE_FLAG = 65536
|
||||
BINCMP_FLAG = 131072
|
||||
end
|
||||
|
||||
class Statement
|
||||
class Stmt
|
||||
# Cursor type
|
||||
CURSOR_TYPE_NO_CURSOR = 0
|
||||
CURSOR_TYPE_READ_ONLY = 1
|
||||
CURSOR_TYPE_NO_CURSOR = 0
|
||||
CURSOR_TYPE_READ_ONLY = 1
|
||||
CURSOR_TYPE_FOR_UPDATE = 2
|
||||
CURSOR_TYPE_SCROLLABLE = 4
|
||||
end
|
||||
end
|
||||
|
||||
end
|
1455
lib/rbmysql/error.rb
1455
lib/rbmysql/error.rb
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,78 @@
|
|||
# coding: ascii-8bit
|
||||
class RbMysql
|
||||
class Packet
|
||||
# convert Numeric to LengthCodedBinary
|
||||
def self.lcb(num)
|
||||
return "\xfb" if num.nil?
|
||||
return [num].pack("C") if num < 251
|
||||
return [252, num].pack("Cv") if num < 65536
|
||||
return [253, num&0xffff, num>>16].pack("CvC") if num < 16777216
|
||||
return [254, num&0xffffffff, num>>32].pack("CVV")
|
||||
end
|
||||
|
||||
# convert String to LengthCodedString
|
||||
def self.lcs(str)
|
||||
str = Charset.to_binary str.dup
|
||||
lcb(str.length)+str
|
||||
end
|
||||
|
||||
def initialize(data)
|
||||
@data = data
|
||||
end
|
||||
|
||||
def lcb
|
||||
return nil if @data.empty?
|
||||
case v = utiny
|
||||
when 0xfb
|
||||
return nil
|
||||
when 0xfc
|
||||
return ushort
|
||||
when 0xfd
|
||||
c, v = utiny, ushort
|
||||
return (v << 8)+c
|
||||
when 0xfe
|
||||
v1, v2 = ulong, ulong
|
||||
return (v2 << 32)+v1
|
||||
else
|
||||
return v
|
||||
end
|
||||
end
|
||||
|
||||
def lcs
|
||||
len = self.lcb
|
||||
return nil unless len
|
||||
@data.slice!(0, len)
|
||||
end
|
||||
|
||||
def read(len)
|
||||
@data.slice!(0, len)
|
||||
end
|
||||
|
||||
def string
|
||||
str = @data.unpack('Z*').first
|
||||
@data.slice!(0, str.length+1)
|
||||
str
|
||||
end
|
||||
|
||||
def utiny
|
||||
@data.slice!(0, 1).unpack('C').first
|
||||
end
|
||||
|
||||
def ushort
|
||||
@data.slice!(0, 2).unpack('v').first
|
||||
end
|
||||
|
||||
def ulong
|
||||
@data.slice!(0, 4).unpack('V').first
|
||||
end
|
||||
|
||||
def eof?
|
||||
@data[0] == ?\xfe && @data.length == 5
|
||||
end
|
||||
|
||||
def to_s
|
||||
@data
|
||||
end
|
||||
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load Diff
|
@ -50,15 +50,7 @@ class MetasploitModule < Msf::Auxiliary
|
|||
|
||||
begin
|
||||
socket = connect(false)
|
||||
x = ::RbMysql.connect({
|
||||
:host => rhost,
|
||||
:port => rport,
|
||||
:user => username,
|
||||
:password => password,
|
||||
:read_timeout => 300,
|
||||
:write_timeout => 300,
|
||||
:socket => socket
|
||||
})
|
||||
x = ::RbMysql.connect(rhost, username, password, nil, rport, socket)
|
||||
x.connect
|
||||
results << x
|
||||
|
||||
|
@ -111,16 +103,7 @@ class MetasploitModule < Msf::Auxiliary
|
|||
begin
|
||||
# Create our socket and make the connection
|
||||
s = connect(false)
|
||||
x = ::RbMysql.connect({
|
||||
:host => rhost,
|
||||
:port => rport,
|
||||
:user => username,
|
||||
:password => password,
|
||||
:read_timeout => 300,
|
||||
:write_timeout => 300,
|
||||
:socket => s,
|
||||
:db => nil
|
||||
})
|
||||
x = ::RbMysql.connect(rhost, username, password, rport, s)
|
||||
print_good "#{rhost}:#{rport} Successfully bypassed authentication after #{count} attempts. URI: mysql://#{username}:#{password}@#{rhost}:#{rport}"
|
||||
results << x
|
||||
rescue RbMysql::AccessDeniedError
|
||||
|
|
|
@ -113,16 +113,11 @@ class MetasploitModule < Msf::Exploit::Remote
|
|||
fail_with(Failure::UnexpectedReply, "The config file did not parse properly")
|
||||
end
|
||||
begin
|
||||
@mysql_handle = ::RbMysql.connect({
|
||||
:host => config['DB_HOST'],
|
||||
:port => config['DB_PORT'],
|
||||
:read_timeout => 300,
|
||||
:write_timeout => 300,
|
||||
:socket => nil,
|
||||
:user => config['DB_USER'],
|
||||
:password => config['DB_PASSWORD'],
|
||||
:db => config['DB_NAME']
|
||||
})
|
||||
@mysql_handle = ::RbMysql.connect(config['DB_HOST'],
|
||||
config['DB_USER'],
|
||||
config['DB_PASSWORD'],
|
||||
config['DB_NAME'],
|
||||
config['DB_PORT'])
|
||||
rescue Errno::ECONNREFUSED,
|
||||
RbMysql::ClientError,
|
||||
Errno::ETIMEDOUT,
|
||||
|
|
Loading…
Reference in New Issue