-
Notifications
You must be signed in to change notification settings - Fork 10
/
3_RSA.py
131 lines (107 loc) · 8.95 KB
/
3_RSA.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
"""
Problem:
Crack the decryption exponent d
-----BEGIN PUBLIC KEY-----
MIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIICCgKCAQEB+34C7GuhHbhLHus9oqCf
HR5N2e6WlnXb+MP5qCbY9fbjoWmgVqKTRu8Zv81KjjlQ531oc8x4tf0H4kyuPjng
AI0UjWdEcNnNWy7ErnJzdwW8jGrZSpj7BZe9eoPdo3l16lnTDQCxTnm/1YF+crA1
Ek7wIQG5S0fguTGebiwLX79qVFcCRvCccSQKhiuJiZjK0MOrWYlnm8O518tw0ZUu
aFhgtFaBJyTI04aN5oTZF3gyuPDZ8MCTp7wYoJ4CvcONlUpobAqSZ1/VIqDxlYM2
Yo6h101wGzW/jucsg+8Np+V+4vHXaSLpz6DOhA7TZIAozzL+4I5SfL0lzzfXSQB8
CQKCAQEBHvBcAbNv9v7I/ZieaKjZxEclI5AXjA/igQcW4sz7uHPyt0/5aX5TGEkr
fROs9renIw7JTkXeo9uArubEIcp47g4346dg5i0tmxbUzF/Pzz3JJGqygmhbVnIl
MP93Iwm2VUOMuTSffK01NdmyysC7xy0OudHb+GtzUv40H2rcTe6VqPuV0pVY5qiv
njPeBKl5TVsxrwbyVXdj+1hjh2pwc2fUZY1LZUAhybrxK/9d2LcZeidUK8IWV92z
gE/AYbNDsbwruLR91iO9DTEH99z0OIjMj/xnIkY/kb8j5lCdIITsU8VxAdzkx05I
Ia54t6o2+2vXKYfQgSwjeXRBywgglQ==
-----END PUBLIC KEY-----
Use Wiener's Attack
"""
"""
Extract n and e from the Public Key
RSA Public-Key: (2049 bit)
Modulus:
01:fb:7e:02:ec:6b:a1:1d:b8:4b:1e:eb:3d:a2:a0:
9f:1d:1e:4d:d9:ee:96:96:75:db:f8:c3:f9:a8:26:
d8:f5:f6:e3:a1:69:a0:56:a2:93:46:ef:19:bf:cd:
4a:8e:39:50:e7:7d:68:73:cc:78:b5:fd:07:e2:4c:
ae:3e:39:e0:00:8d:14:8d:67:44:70:d9:cd:5b:2e:
c4:ae:72:73:77:05:bc:8c:6a:d9:4a:98:fb:05:97:
bd:7a:83:dd:a3:79:75:ea:59:d3:0d:00:b1:4e:79:
bf:d5:81:7e:72:b0:35:12:4e:f0:21:01:b9:4b:47:
e0:b9:31:9e:6e:2c:0b:5f:bf:6a:54:57:02:46:f0:
9c:71:24:0a:86:2b:89:89:98:ca:d0:c3:ab:59:89:
67:9b:c3:b9:d7:cb:70:d1:95:2e:68:58:60:b4:56:
81:27:24:c8:d3:86:8d:e6:84:d9:17:78:32:b8:f0:
d9:f0:c0:93:a7:bc:18:a0:9e:02:bd:c3:8d:95:4a:
68:6c:0a:92:67:5f:d5:22:a0:f1:95:83:36:62:8e:
a1:d7:4d:70:1b:35:bf:8e:e7:2c:83:ef:0d:a7:e5:
7e:e2:f1:d7:69:22:e9:cf:a0:ce:84:0e:d3:64:80:
28:cf:32:fe:e0:8e:52:7c:bd:25:cf:37:d7:49:00:
7c:09
Exponent:
01:1e:f0:5c:01:b3:6f:f6:fe:c8:fd:98:9e:68:a8:
d9:c4:47:25:23:90:17:8c:0f:e2:81:07:16:e2:cc:
fb:b8:73:f2:b7:4f:f9:69:7e:53:18:49:2b:7d:13:
ac:f6:b7:a7:23:0e:c9:4e:45:de:a3:db:80:ae:e6:
c4:21:ca:78:ee:0e:37:e3:a7:60:e6:2d:2d:9b:16:
d4:cc:5f:cf:cf:3d:c9:24:6a:b2:82:68:5b:56:72:
25:30:ff:77:23:09:b6:55:43:8c:b9:34:9f:7c:ad:
35:35:d9:b2:ca:c0:bb:c7:2d:0e:b9:d1:db:f8:6b:
73:52:fe:34:1f:6a:dc:4d:ee:95:a8:fb:95:d2:95:
58:e6:a8:af:9e:33:de:04:a9:79:4d:5b:31:af:06:
f2:55:77:63:fb:58:63:87:6a:70:73:67:d4:65:8d:
4b:65:40:21:c9:ba:f1:2b:ff:5d:d8:b7:19:7a:27:
54:2b:c2:16:57:dd:b3:80:4f:c0:61:b3:43:b1:bc:
2b:b8:b4:7d:d6:23:bd:0d:31:07:f7:dc:f4:38:88:
cc:8f:fc:67:22:46:3f:91:bf:23:e6:50:9d:20:84:
ec:53:c5:71:01:dc:e4:c7:4e:48:21:ae:78:b7:aa:
36:fb:6b:d7:29:87:d0:81:2c:23:79:74:41:cb:08:
20:95
"""
modulus = "01:fb:7e:02:ec:6b:a1:1d:b8:4b:1e:eb:3d:a2:a0:9f:1d:1e:4d:d9:ee:96:96:75:db:f8:c3:f9:a8:26:d8:f5:f6:e3:a1:69:a0:56:a2:93:46:ef:19:bf:cd:4a:8e:39:50:e7:7d:68:73:cc:78:b5:fd:07:e2:4c:ae:3e:39:e0:00:8d:14:8d:67:44:70:d9:cd:5b:2e:c4:ae:72:73:77:05:bc:8c:6a:d9:4a:98:fb:05:97:bd:7a:83:dd:a3:79:75:ea:59:d3:0d:00:b1:4e:79:bf:d5:81:7e:72:b0:35:12:4e:f0:21:01:b9:4b:47:e0:b9:31:9e:6e:2c:0b:5f:bf:6a:54:57:02:46:f0:9c:71:24:0a:86:2b:89:89:98:ca:d0:c3:ab:59:89:67:9b:c3:b9:d7:cb:70:d1:95:2e:68:58:60:b4:56:81:27:24:c8:d3:86:8d:e6:84:d9:17:78:32:b8:f0:d9:f0:c0:93:a7:bc:18:a0:9e:02:bd:c3:8d:95:4a:68:6c:0a:92:67:5f:d5:22:a0:f1:95:83:36:62:8e:a1:d7:4d:70:1b:35:bf:8e:e7:2c:83:ef:0d:a7:e5:7e:e2:f1:d7:69:22:e9:cf:a0:ce:84:0e:d3:64:80:28:cf:32:fe:e0:8e:52:7c:bd:25:cf:37:d7:49:00:7c:09"
newM = ""
for i in modulus:
if i != ":":
newM += i
modulus = newM
print(modulus)
# 01fb7e02ec6ba11db84b1eeb3da2a09f1d1e4dd9ee969675dbf8c3f9a826d8f5f6e3a169a056a29346ef19bfcd4a8e3950e77d6873cc78b5fd07e24cae3e39e0008d148d674470d9cd5b2ec4ae72737705bc8c6ad94a98fb0597bd7a83dda37975ea59d30d00b14e79bfd5817e72b035124ef02101b94b47e0b9319e6e2c0b5fbf6a54570246f09c71240a862b898998cad0c3ab5989679bc3b9d7cb70d1952e685860b456812724c8d3868de684d9177832b8f0d9f0c093a7bc18a09e02bdc38d954a686c0a92675fd522a0f1958336628ea1d74d701b35bf8ee72c83ef0da7e57ee2f1d76922e9cfa0ce840ed3648028cf32fee08e527cbd25cf37d749007c09
modulus = int(modulus,16)
print(modulus)
e = "01:1e:f0:5c:01:b3:6f:f6:fe:c8:fd:98:9e:68:a8:d9:c4:47:25:23:90:17:8c:0f:e2:81:07:16:e2:cc:fb:b8:73:f2:b7:4f:f9:69:7e:53:18:49:2b:7d:13:ac:f6:b7:a7:23:0e:c9:4e:45:de:a3:db:80:ae:e6:c4:21:ca:78:ee:0e:37:e3:a7:60:e6:2d:2d:9b:16:d4:cc:5f:cf:cf:3d:c9:24:6a:b2:82:68:5b:56:72:25:30:ff:77:23:09:b6:55:43:8c:b9:34:9f:7c:ad:35:35:d9:b2:ca:c0:bb:c7:2d:0e:b9:d1:db:f8:6b:73:52:fe:34:1f:6a:dc:4d:ee:95:a8:fb:95:d2:95:58:e6:a8:af:9e:33:de:04:a9:79:4d:5b:31:af:06:f2:55:77:63:fb:58:63:87:6a:70:73:67:d4:65:8d:4b:65:40:21:c9:ba:f1:2b:ff:5d:d8:b7:19:7a:27:54:2b:c2:16:57:dd:b3:80:4f:c0:61:b3:43:b1:bc:2b:b8:b4:7d:d6:23:bd:0d:31:07:f7:dc:f4:38:88:cc:8f:fc:67:22:46:3f:91:bf:23:e6:50:9d:20:84:ec:53:c5:71:01:dc:e4:c7:4e:48:21:ae:78:b7:aa:36:fb:6b:d7:29:87:d0:81:2c:23:79:74:41:cb:08:20:95"
newE = ""
for i in e:
if i != ":":
newE += i
e = newE
# 011ef05c01b36ff6fec8fd989e68a8d9c447252390178c0fe2810716e2ccfbb873f2b74ff9697e5318492b7d13acf6b7a7230ec94e45dea3db80aee6c421ca78ee0e37e3a760e62d2d9b16d4cc5fcfcf3dc9246ab282685b56722530ff772309b655438cb9349f7cad3535d9b2cac0bbc72d0eb9d1dbf86b7352fe341f6adc4dee95a8fb95d29558e6a8af9e33de04a9794d5b31af06f2557763fb5863876a707367d4658d4b654021c9baf12bff5dd8b7197a27542bc21657ddb3804fc061b343b1bc2bb8b47dd623bd0d3107f7dcf43888cc8ffc6722463f91bf23e6509d2084ec53c57101dce4c74e4821ae78b7aa36fb6bd72987d0812c23797441cb082095
e = int(e,16)
print("e:\n",e)
print("\n")
"""
e is:
36222680858414256161375884602150640809062958718117141382923099494341733093172587117165920097285523276338274750598022486976083511178091392849986039384975758609343597548039166024042264614496506087597114091663955133779956176941325431822684716988128271384410010471755324833136859652978240297120618458534306923558546176110055737233883129780378153307730890915697357455996361736492022695824172516806204252765904924281272883818154621932085365817823019773860783687666788095035790491006333432295698178378520444810813882117817329847874531809530929345430796600870728736678389479159328119322587647856274762262358880664585675219093
n is:
64064959164923876064874945473407049985543119992992738119252749231253142464203647518777455475109972581684732621072998898066728303433300585291527582979430276357787634026869116095391514311111174206395195817672737320837240364944609979844601986221462845364070396665723029902932653368943452652854174197070747631242101084260912287849286644699582292473152660004035330616149016496957012948833038931711943984563035784805193474921164625068468842927905314268942153720078680937345365121129404384633019183060347129778296640500935382186867850407893387920482141216498339346081106433144352485571795405717793040441238659925857198439433
"""
"""
RUN:
lynx --dump http://www.factordb.com/index.php?query=64064959164923876064874945473407049985543119992992738119252749231253142464203647518777455475109972581684732621072998898066728303433300585291527582979430276357787634026869116095391514311111174206395195817672737320837240364944609979844601986221462845364070396665723029902932653368943452652854174197070747631242101084260912287849286644699582292473152660004035330616149016496957012948833038931711943984563035784805193474921164625068468842927905314268942153720078680937345365121129404384633019183060347129778296640500935382186867850407893387920482141216498339346081106433144352485571795405717793040441238659925857198439433 | head | tail -n 2
OUTPUT:
FF 617 [9](show) [10]6406495916...33[<617>] =
[11]1862466482...47[<309>]· [12]3439791253...39[<309>]
P = 186246648244859911607711264996090931472855888819671042195031912614949637606087847869985018786102702075677574757904065755347302795775592228331239337528300940615230331822790830533866239838132543271015473522200950110622128503105755908781817068494167073494343838131720577929427076318200884590552419145720643388247
Q = 343979125362283985018448529279849717865226132571940753531472371147063833056052296996560621963391117972766695130913691200805933469450333065947100791572361583779489645096118775405521473386236447881145306226283269737222216027483772716038172843353831106671840432335901895809418592551312176873714872038511716417439
"""
P = 186246648244859911607711264996090931472855888819671042195031912614949637606087847869985018786102702075677574757904065755347302795775592228331239337528300940615230331822790830533866239838132543271015473522200950110622128503105755908781817068494167073494343838131720577929427076318200884590552419145720643388247
Q = 343979125362283985018448529279849717865226132571940753531472371147063833056052296996560621963391117972766695130913691200805933469450333065947100791572361583779489645096118775405521473386236447881145306226283269737222216027483772716038172843353831106671840432335901895809418592551312176873714872038511716417439
n = P * Q
import owiener
d = owiener.attack(e, n)
if d is None:
print("Failed")
else:
print("Hacked d={}".format(d))
# dsc{6393313697836242618414301946448995659516429576261871356767102021920538052481829568588047189447471873340140537810769433878383029164089236876209147584435733}
# :)