Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/smbRpc/updateString/to_des_ecb_lm.rb,
lib/smbRpc/updateString/raise_not_error_success.rb
Instance Method Summary collapse
-
#genKeys(sevenByteStr) ⇒ Object
- MS-SAMR
-
2.2.11.1.4.
- #raise_not_error_success(funcName) ⇒ Object
- #to_des_ecb_lm(key) ⇒ Object
Instance Method Details
#genKeys(sevenByteStr) ⇒ Object
- MS-SAMR
-
2.2.11.1.4
2 3 4 5 6 7 8 9 10 11 12 |
# File 'lib/smbRpc/updateString/to_des_ecb_lm.rb', line 2 def genKeys(sevenByteStr) #[MS-SAMR] 2.2.11.1.4 sevenBitsArray = sevenByteStr.unpack("B*")[0].scan(/......./) #grab each 7 bits into array eightBitsStr = "" #[MS-SAMR]2.2.11.1.2 Encrypting a 64-Bit Block with a 7-Byte Key sevenBitsArray.each do |e| count = 0 e.split("").each{ |i| count += 1 if i == "1" } #add parity bit to each chunks (1 if sum of bits even) eightBitsStr << e eightBitsStr << (count % 2 == 0? "0" : "1") #MS-SAMR 2.2.11.1.2 says if odd use 0??? end return [eightBitsStr].pack("B*") #pack back to 8 bytes key end |
#raise_not_error_success(funcName) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/smbRpc/updateString/raise_not_error_success.rb', line 3 def raise_not_error_success(funcName) winError = self[-4,4].unpack("V")[0] error = WindowsError::Win32.find_by_retval(winError)[0] error = WindowsError::NTStatus.find_by_retval(winError)[0] if error.nil? raise "%s Fail, WinError: %s 0x%08x"%[funcName, "UNKNOWN ERROR CODE", winError ] if error.nil? error.value == 0? error.value : (raise "%s Fail, WinError: %s %s"%[funcName, error.name, error.description]) end |
#to_des_ecb_lm(key) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/smbRpc/updateString/to_des_ecb_lm.rb', line 14 def to_des_ecb_lm(key) #keys key1 = genKeys(key[0,7]) key2 = genKeys(key[7,7]) #hash hash1 = self[0,8] hash2 = self[8,8] #encrypt #[MS-SAMR]2.2.11 Common Algorithms #2.2.11.1 DES-ECB-LM #2.2.11.1.1 Encrypting an NT or LM Hash Value with a Specified Key out = "" desEcb = OpenSSL::Cipher.new("DES-ECB") desEcb.encrypt desEcb.key = key1 out << desEcb.update(hash1) desEcb.key = key2 out << desEcb.update(hash2) return out end |