crypto-toolbox 0.1.13 → 0.1.14
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5728516f47174d06b0901a72afa8a499ee5f0662
|
4
|
+
data.tar.gz: 9d83b1da078d82ba3345fb4b8aca1f860aaf1eb5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21c9a10d814988c289b578850e1b769c817e086cd47a369578a01bdd8f5058ea6e1ef0573d311ab4ee6b3ee54f038ddc043475af83ae8f8a5112c02e126351af
|
7
|
+
data.tar.gz: 81601d2d3376c364ef5437b6d5af7c33bd4b3e47658eda3fa68a220439f4a6580fe0e20b3a6030909b9a52c89ad2e8026cb383dd7d2a7f6ebbd1eea84ee521c1
|
@@ -23,34 +23,43 @@ module Analyzers
|
|
23
23
|
def analyze(target_message)
|
24
24
|
@oracle.connect
|
25
25
|
|
26
|
-
#
|
26
|
+
# split the target message into chunks of size N (e.g. 32)
|
27
27
|
target_bufs = CryptBuffer(target_message).chunks_of(32)
|
28
28
|
|
29
|
-
#
|
30
|
-
|
29
|
+
# receive the valid mac for the first chunk of the target message
|
30
|
+
tag1 = CryptBuffer(@oracle.mac(target_bufs[0]))
|
31
31
|
|
32
|
-
|
33
|
-
|
34
|
-
msg2 = CryptBuffer((m2_blocks[0].xor(target_tag1)).bytes + m2_blocks[1].bytes)
|
32
|
+
attack_message = assemble_malicious_message(target_bufs,tag1)
|
33
|
+
forged_tag = @oracle.mac(attack_message)
|
35
34
|
|
36
|
-
|
37
|
-
forge_tag = @oracle.mac(msg2.chars,msg2.length)
|
38
|
-
|
39
|
-
# @oracle.verify(target_msg.chars, target_msg.length, forge_tag)
|
40
|
-
ret = @oracle.verify(target_message.chars, target_message.length, forge_tag)
|
35
|
+
ret = @oracle.verify(target_message, forged_tag)
|
41
36
|
|
37
|
+
report_result(ret,forged_tag)
|
42
38
|
|
39
|
+
@oracle.disconnect
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
# Create a message that consists of
|
44
|
+
# 1) the first n byte of the second message xored with tag t from the first message
|
45
|
+
# 2) the remaining blocks of the second message
|
46
|
+
# short: t'' = (m'_0 xor t ) ||m'_1 ||...||m'_n]
|
47
|
+
def assemble_malicious_message(target_bufs,tag1)
|
48
|
+
|
49
|
+
# split the second chunk into blocks of the size of the tag
|
50
|
+
m2_blocks = target_bufs[1].chunks_of(tag1.length)
|
51
|
+
|
52
|
+
CryptBuffer((m2_blocks[0].xor(tag1)).bytes + m2_blocks[1].bytes)
|
53
|
+
end
|
54
|
+
|
55
|
+
def report_result(ret,tag)
|
43
56
|
if forge_successfull?(ret)
|
44
|
-
puts "
|
45
|
-
puts "Message verified successfully!"
|
57
|
+
puts "[Success] Resulting tag is: #{CryptBuffer(tag).pretty_hexstring}"
|
46
58
|
else
|
47
|
-
puts "Message verification failed."
|
59
|
+
puts "[Failure] Message verification failed."
|
48
60
|
end
|
49
|
-
@oracle.disconnect
|
50
61
|
end
|
51
62
|
|
52
|
-
private
|
53
|
-
|
54
63
|
def forge_successfull?(retval)
|
55
64
|
retval == 1
|
56
65
|
end
|
@@ -23,20 +23,20 @@ module Analyzers
|
|
23
23
|
@mac_socket.close if @mac_socket
|
24
24
|
end
|
25
25
|
|
26
|
-
def mac(message
|
26
|
+
def mac(message)
|
27
27
|
connect unless @mac_socket
|
28
28
|
|
29
|
-
packet = ([message.length] + message + [0]).map(&:chr).join("")
|
29
|
+
packet = ([message.length] + message.bytes + [0]).map(&:chr).join("")
|
30
30
|
|
31
31
|
@mac_socket.write(packet)
|
32
32
|
@mac_socket.read(16)
|
33
33
|
end
|
34
34
|
|
35
|
-
def verify(message,
|
35
|
+
def verify(message,tag)
|
36
36
|
connect unless @verify_socket
|
37
37
|
|
38
38
|
# Message-length + message-chars + tag-chars + 0
|
39
|
-
packet = ([message.length] + message + tag.split("") + [0]).map(&:chr).join("")
|
39
|
+
packet = ([message.length] + message.bytes + tag.split("") + [0]).map(&:chr).join("")
|
40
40
|
|
41
41
|
@verify_socket.write(packet)
|
42
42
|
@verify_socket.read(2).to_i
|