Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Challenge for MSNP18

  • Loading branch information...
commit 48f0d2415bff0cb8c1da63f776aa95e79d1f2709 1 parent a8804bb
@asterite asterite authored
View
1  em-msn.gemspec
@@ -17,6 +17,7 @@ Gem::Specification.new do |s|
"lib/msn/message.rb",
"lib/msn/nexus.rb",
"lib/msn/messenger.rb",
+ "lib/msn/challenge.rb",
"lib/msn/notification_server.rb",
"lib/msn/protocol.rb",
"lib/msn/switchboard.rb",
View
1  lib/em-msn.rb
@@ -15,6 +15,7 @@ module Msn
require_relative 'msn/protocol'
require_relative 'msn/message'
require_relative 'msn/nexus'
+require_relative 'msn/challenge'
require_relative 'msn/notification_server'
require_relative 'msn/switchboard'
require_relative 'msn/messenger'
View
53 lib/msn/challenge.rb
@@ -0,0 +1,53 @@
+class Msn::Challenge
+ ProductKey = "RG@XY*28Q5QHS%Q5"
+ ProductId = "PROD0113H11T8$X_"
+ F = "0x7FFFFFFF".to_i(16)
+ E = "0x0E79A9C1".to_i(16)
+
+ class << self
+ def challenge(challenge, product_key = ProductKey, product_id = ProductId)
+ md5hash = Digest::MD5.hexdigest "#{challenge}#{product_key}"
+ md5array = md5hash.scan(/.{8}/)
+ new_hash_parts = md5array.map! { |s| s.scan(/.{2}/).reverse.join.to_i(16) }
+ md5array = new_hash_parts.map { |n| n & F }
+
+ chlstring = "#{challenge}#{product_id}"
+ chlstring = "#{chlstring}#{'0' * (chlstring.length % 8)}"
+
+ chlstring_array = chlstring.scan(/.{4}/)
+ chlstring_array.map! { |str| str.bytes.map { |b| b.to_s(16) }.reverse.join.to_i(16) }
+
+ low = high = 0
+
+ i = 0
+ while i < chlstring_array.length
+ temp = (md5array[0] * (((E * chlstring_array[i]) % F) + high) + md5array[1]) % F
+ high = (md5array[2] * ((chlstring_array[i + 1] + temp) % F) + md5array[3]) % F
+ low = low + high + temp;
+
+ i += 2
+ end
+
+ high = (high + md5array[1]) % F
+ low = (low + md5array[3]) % F
+ key = (high << 32) + low
+
+ new_hash_parts[0] ^= high;
+ new_hash_parts[1] ^= low;
+ new_hash_parts[2] ^= high;
+ new_hash_parts[3] ^= low;
+
+ new_hash_parts.map { |x| x.to_s(16).scan(/.{2}/).reverse.join }.join
+ end
+
+ def split_in_chunks(string, length)
+ array = []
+ i = 0
+ while i < string.length
+ array.push string[i ... i + length]
+ i += length
+ end
+ array
+ end
+ end
+end
View
4 lib/msn/protocol.rb
@@ -50,9 +50,9 @@ def handle_event(header, data = nil)
end
def answer_challenge(challenge_string)
- payload = Digest::MD5.hexdigest "#{challenge_string}Q1P7W2E4J9R8U3S5"
+ payload = Msn::Challenge.challenge(challenge_string)
- send_command_internal "QRY #{@trid} msmsgs@msnmsgr.com 32\r\n#{payload}"
+ send_command_internal "QRY #{@trid} #{Msn::Challenge::ProductId} 32\r\n#{payload}"
end
def send_command(command, *args)
View
11 spec/msn/challenge_spec.rb
@@ -0,0 +1,11 @@
+require 'spec_helper'
+
+describe Challenge do
+ it "replies to challenge for MSNP11" do
+ Challenge.challenge("22210219642164014968", "YMM8C_H7KCQ2S_KL", "PROD0090YUAUV{2B").should eq("85ecb0db8f32113df79ce0892b9a102c")
+ end
+
+ it "replies to challenge for MSNP15" do
+ Challenge.challenge("11533365622852247127").should eq("f086d1ded067186deca8dba2231602cf")
+ end
+end
View
15 spec/msn/nexus_spec.rb
@@ -0,0 +1,15 @@
+require 'spec_helper'
+
+describe Nexus do
+ it "computes return value" do
+ nexus = Nexus.new "MBI_KEY", "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="
+ return_value = nexus.compute_return_value "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=", "#{0.chr * 8}"
+ return_value.should eq("HAAAAAEAAAADZgAABIAAAAgAAAAUAAAASAAAAAAAAAAAAAAA7XgT5ohvaZdoXdrWUUcMF2G8OK2JohyYcK5l5MJSitab33scxJeK/RQXcUr0L+R2ZA9CEAzn0izmUzSMp2LZdxSbHtnuxCmptgtoScHp9E26HjQVkA9YJxgK/HM=")
+ end
+
+ it "computes return value 2" do
+ nexus = Nexus.new "MBI_KEY", "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB="
+ return_value = nexus.compute_return_value "BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB=", "#{0.chr * 8}"
+ return_value.should eq("HAAAAAEAAAADZgAABIAAAAgAAAAUAAAASAAAAAAAAAAAAAAAywfWRZVnRRZTqPkW6HBIrOmPuYiFbzcpvYmP2QzhpH+VdKwtqUTt/gdbDqlMZvR1o7ve9ex44otMOxYtnNYIQ+lfoj+PKcsHT+T7GA1hfMsTVbGqoYYe3B5/WW0=")
+ end
+end
View
4 spec/spec_helper.rb
@@ -0,0 +1,4 @@
+require 'bundler/setup'
+require_relative "../lib/em-msn"
+
+include Msn
Please sign in to comment.
Something went wrong with that request. Please try again.