-
Notifications
You must be signed in to change notification settings - Fork 1
/
crack.py
54 lines (46 loc) · 16.4 KB
/
crack.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
testpem = bytes.fromhex('308209280201000282020100c34a105f3fec00045b03e2566b8b047c65548eb64a66f100a86e3c394db1ae97b114cdb2d2b12e33f6a9728c46dd70d9c34077dd2a69dd6488ee4bc62b5ef4292e4b1a08d285ca132c013ee1d8e88bcaf3f3a8585365c71f423b5a942881f406b040a64237575c0c72b339f5040c6c3a797cea626e7cbf1effc230074071ef4c2d6c54ebad80cf89a46a319a084e0798efc8453466a00ef15bf9d31657f5fdde608ca78f9253db4b2a67134b12968ee1c3f745f3b0d711b5630bf18f9ab2cba8c5af9308c493da6cb138e8028c8c8d4f6b64bedc449e9359cbe2d645929760c2575ee523148e1c062e91c654380161640137d5cd53adaa6501b7d6bba8da00a8d0e3accae4118d8f215d36b7279cc1c3768a148efa1d8014d8c87a91b87d180b0d7e9a8057ec8fb0f8d6d1893df461cc1bac86464c04e593259ac23bd6add0119dc77c0e973f83dfa961cbe3a3fe5d42617824803fc74ff29f6690b744f138c1bde434363695458285443cf2f22e28117f4c2f1b162d35c322be64565f97772b52170d1692d131847f77ca6634727e6927e032336b4c7a2f348bf9f65a45784c7a318f06790e3747ab02bd8e2060a0ac61886a63b45da95d9abfa508d779dcc9e4ee1ff0f0661ddd37ccef92a214bccbcd3f1f16527bc9fce609b74e33c0b086b075dd9ce1379be5d6226822e41fe769a11cbf23cf7a5928dce6b8ff78b06b8f02030100010282020100c0feade563e79830b5bdc5edc00437dfb3c877ed20e450e26491e484810acacf709a6d9a7eebc90c63851c0613767e3346e9ac4b6ec206a0774e80a60c709f7d1f19eb55b2afb37f74ea9a395a429efc6850711b30f8116c0be95a5fb7148e9419951a79aff56eab82a32af0c01a82cedb071f1f3daf9cb546eea2c657e30129586e8a120b7a941fa3d3aac75dd3b76065ff969ced9ada899e6aeb38569f6d4f5a3d46cef53e582715759e347fdf38bf570a45204ab090f8a034ca7a2fd8e8ba16fba7a46f98eab0a607e609b6daa4404b92d9a8174c5bb4cf70926f592aaede00b8705c55d10752f8ace9c28b4299fbd9d4533fc2a58b129d3b10448edf3aebdf8d7eec14c5afafbd3332f72c2d8e66c95aa3214570580aca6d3ded6303cc11ffe418dce30ee5afbd8f0522a2f3c85e176edc83251015180558902cadf013453f4af4a74b299fd63dd8fd69e20fb83adf83f21b7c530f679ac6b4655b44c9f45817f8450171b91770c41eba6564fb4057ff714ba5339df68139603abc1747a99f7ddfa57e86a795b07b9209c1af1074a17ca4003d652643d5c90cf0c94cba23a082d2d059b64f384cefc53e1323f2d07f2bf279fe3ca3c7045d1bed6d19a2f24eae796cfae76decd62306026a681a327f2d75dec58847027f68ccc9d05cd4036f40f360eed89ead0631b9501be9e10f5655a299dda316d6b394eee747d2fe590282010100f1e4a29cf8ea8a35446e7cb3dc50cfa8c5282ae5ebb76708607045a130ef699b8fe11bae1153bd6a14a8ac2cee16a84c82fd8b9ea041a1ffae28b8a026ef444027295d38c47937f51377be025e045479a8ddce5ae7c6bf9f810a865b97acd273053d210184c2c32442016960c5232db4a93dd799686bbc268691ab1f2baf4d1e6dd2acc4ed4a74cd2c5d37b90b3736c1bb871d57ef9fb107920f7a7a6252dfcd49ffda36485bbf7ef85dea7c3aec9025b630713924b7ae7b62afb1bcfb02365ed06c9ee1c66b0a2534db8c5fa84c2b601febd463da8824d08503d2825912462fb93ebb0605ce3139e937ec766b8d1c65ffda26df01cc198e3b86664a71e9d2730282010100ceada73a190b190994e35fbec44db5d3471a3bdc110f7a5eadd2d1e7683556fafcb01cfe6d4d4daef488821b415ab6a21d933852e994bba509ca0e7d1ac446d2e3557db797243f2252a8cb96432d04a4b09f8c2d373788b89d0f53bf112953c2e0868918da79e6a95f05a854c577779bbcc18e8ef628b48a819b081e1b32ede241088a70cef60dfe20b8f8f91fb1cf92021394985082bc2dab90e30114900a00cbdfe7c412c5eb4807fc1c166390df1ac43a4751618bdc6905dc0502892d644e8b282381afaa3e11f717eed7011802739cc9a835220d907d79343bcc96bcaccc56860c001e6209fcda2456f65c4de30d9fe380af75d465b9593af80360678f750282010047ae8655d819c0dd2a2b47bf1111cd87e8ed0f515539e3498332a21fb35daf410f31193fcb18b2afe5f15a1c726dba6ff9fd62cb9e17f506ccb87a85d323e268d472189302fe1d0bfe39e4cfd4c699b5f7c9cb25fb3b557bd204a96e291368c5f70e776278d2327be32781efd05bad66b52483688d9e27828f2c49b691fe7feefd8289fa4d8b5bf3952b06a14a66914e75e1035c14c190f77a5c25e27092b889a05d3670119f46af3cb0b015226d0a0672e8061576010caeb9bef0ffdcae7a283cc1838fca79dbe6ccb426f40dee8c880ecd97020437861958e19a175087eecea3a9a8488f9ddbce9a831d0ab6b27970ec91dc2507e650c86a71588cc517126b028201003e0dbb80e11608ed6c8b9c2aadcbdb44d53b562fabdba6d518818cce5ae670f828b843ec4c2b02a0fe00a277c676931137aa052637c59555670c08af9d42c334fc56a5c96292da75d6b5a172bb36a007469490c4dea848df8d2095f76f12a678836b416c79e451d2169a9f40dc8d13176a63ff0683781344e6c70277ef98a9fddda2cfd630fd859400852913bb656aba1eef7c15034f4d6ab4f16a86df82a3ce3b683db10c25ea8f94fe27fcbce6396652f6608559b1617b12ec4d80c6691f8dc99042a0e47a4bea9ef2cb9e3850da239636a1cf5a2b126fe9dd39fb226301cad44ba8fcbc2299771694049c31789d2c710e208c0de7b8a71ed86ab0b0d84725028201004272283a5481269c3eee8d91d6e466c4a540e76ed8cc44e327b7cd2f81711aa1cd880357256dcc22848e4be508242d7851f4ca4963b32a900e5dc28353579d8358ddca0f5cc072fb93ade0432ea7d650ae06a83a18be07d738ea1b71a17e5890bc843f0f37652fceaf12edf45e5161d71f7fc581d4c23ba00539c9fe34e79b04f138894cdf071cf159498fdc97e880149b29eb73b442cd8dbac2e0f64b5a6e2fb8566cc5c6f1cb1c47871faa19edec5a5b3be501e1a2818bde856d381e64c380638e068be05b28f20c50add3a298c69971e9c85c98b63a7437a761b9b6f63d1a05c8060b39e43936841d82af808a7665f08d23713d55a3be83b6f8be7e035a08')
pem = bytes.fromhex('3082092802010002820201009ca79d2d2b5cb6b06536fe2b0fe606a8e9676a78627354c4ec671f0b9c6c5e171988d827b6ff8ceab2b8d7de96c84ccc4711a4665538c93afdf038ffdce0eb6a1d75322abd1432aa5b0c729cafb79e18540cc833f6d441beb536718162612727de29dc71d827c14aff67ea82d8b0b6fabb385fec83e3fb33f1143ee4ecfccebaf1757fe1148a53ec9ce5c431eab23064d1a1bc3b6e48ccdca4431bcad0a9cbcd480e63d9d89213bfe7ce83ce0c557574ab8526faf61a5bf067d433495d2cb05f2b50f8d4f5e59cda5698b1024ba58e33d106fa2edfd80987c466071c068e30ee3d15e6fc1cb242931770de36bdd42b937eada4e804fe5e9b1aac6c42adae0c18d583a513e7203b9f6f2a8cda100ce81032511b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dd8c516b1906ebc550f0930282010100c2c95e64c853063d982ae13287bbe747db57e803bae644ecf195cf75d465f8bed187986358601ff6c241944bc8336980a0cb3549b325f4115ea7bc504139873f5415651eb5785e6bd05c945c87916ba21e133ac2c45158f229a333b0ead5ec68bcfa55e8c4128a4c4dd062edde5d24d6f35200188a1350abc9917622612d5eab0d80b4fabec99c7a093f21eb36783bc6488da3ed5b641a24c86490ebf72628dc3a78fc82f1d22964a4cb2f65b4d7077e2b512d90f5908eb0ec70d6a559ce8661bdd29f007ba522ff06efe6d9fa6ac0d940531eeea2541025ca4300be6a63ca79daa26db53fee8b7832cc04fc16ab92f152cc563fd1091d7350ab15b0bdd8eeef028201007beaacf420ed84b2553e7bf620d1231c56bc767476fa74fc2b4ec8fd63c2c15498c695851ff8bb3c8e049a3fcbc421ca48fd3e5261acb7a04171f1418099978c30b797a4809a9ab28bada43812dbdff65907c73416f31e3cf2a42c2bab34d87f6659a311e4b7acae034bb57c72505355ebe4fe31f079bbec52eaa89567707e8508c157e81b0ef5d83d26b878d5b9890d67884cd5b3fecdbade29db3d4aa37dbe5b58884e80f4010855b831760cd9bcabc25edbfeacc4328d24525461feafc61f3cb6b23aa9f9e10b4cfd766dd0bdf352a298974b38dcd6e1b688eb2f843f1ad3748f35a1f0bdc4c14b11619fad9bd8d169ab2ed0df08bb8cc18e15a950608ffb028201004ea1ab9153acf05ffd0592532ba816fd52f6719acfe01502f1a3605458a1b1809664fe875c2db1b9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
chunks = []
i = 0
while i < len(testpem):
if testpem[i] == 0x02:
hl = 0
length = 0
if (testpem[i+1] & 0x80) > 0:
hl = testpem[i+1] & 0x3F
length = int.from_bytes(testpem[i+2:i+hl+2], byteorder='big')
else:
length = testpem[i+1] & 0x3F
chunks.append((i+2+hl, i+2+hl+length))
print(testpem[i+2+hl:i+2+hl+length].hex())
print()
i += hl + length + 2
else:
i += 1
print(chunks)
pem = bytes.fromhex('3082092802010002820201009ca79d2d2b5cb6b06536fe2b0fe606a8e9676a78627354c4ec671f0b9c6c5e171988d827b6ff8ceab2b8d7de96c84ccc4711a4665538c93afdf038ffdce0eb6a1d75322abd1432aa5b0c729cafb79e18540cc833f6d441beb536718162612727de29dc71d827c14aff67ea82d8b0b6fabb385fec83e3fb33f1143ee4ecfccebaf1757fe1148a53ec9ce5c431eab23064d1a1bc3b6e48ccdca4431bcad0a9cbcd480e63d9d89213bfe7ce83ce0c557574ab8526faf61a5bf067d433495d2cb05f2b50f8d4f5e59cda5698b1024ba58e33d106fa2edfd80987c466071c068e30ee3d15e6fc1cb242931770de36bdd42b937eada4e804fe5e9b1aac6c42adae0c18d583a513e7203b9f6f2a8cda100ce81032511b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000dd8c516b1906ebc550f0930282010100c2c95e64c853063d982ae13287bbe747db57e803bae644ecf195cf75d465f8bed187986358601ff6c241944bc8336980a0cb3549b325f4115ea7bc504139873f5415651eb5785e6bd05c945c87916ba21e133ac2c45158f229a333b0ead5ec68bcfa55e8c4128a4c4dd062edde5d24d6f35200188a1350abc9917622612d5eab0d80b4fabec99c7a093f21eb36783bc6488da3ed5b641a24c86490ebf72628dc3a78fc82f1d22964a4cb2f65b4d7077e2b512d90f5908eb0ec70d6a559ce8661bdd29f007ba522ff06efe6d9fa6ac0d940531eeea2541025ca4300be6a63ca79daa26db53fee8b7832cc04fc16ab92f152cc563fd1091d7350ab15b0bdd8eeef028201007beaacf420ed84b2553e7bf620d1231c56bc767476fa74fc2b4ec8fd63c2c15498c695851ff8bb3c8e049a3fcbc421ca48fd3e5261acb7a04171f1418099978c30b797a4809a9ab28bada43812dbdff65907c73416f31e3cf2a42c2bab34d87f6659a311e4b7acae034bb57c72505355ebe4fe31f079bbec52eaa89567707e8508c157e81b0ef5d83d26b878d5b9890d67884cd5b3fecdbade29db3d4aa37dbe5b58884e80f4010855b831760cd9bcabc25edbfeacc4328d24525461feafc61f3cb6b23aa9f9e10b4cfd766dd0bdf352a298974b38dcd6e1b688eb2f843f1ad3748f35a1f0bdc4c14b11619fad9bd8d169ab2ed0df08bb8cc18e15a950608ffb028201004ea1ab9153acf05ffd0592532ba816fd52f6719acfe01502f1a3605458a1b1809664fe875c2db1b9000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
for chunk in chunks:
print(pem[chunk[0]:chunk[1]].hex())
print()
import sympy
e = 65537
upper_n = 0x009ca79d2d2b5cb6b06536fe2b0fe606a8e9676a78627354c4ec671f0b9c6c5e171988d827b6ff8ceab2b8d7de96c84ccc4711a4665538c93afdf038ffdce0eb6a1d75322abd1432aa5b0c729cafb79e18540cc833f6d441beb536718162612727de29dc71d827c14aff67ea82d8b0b6fabb385fec83e3fb33f1143ee4ecfccebaf1757fe1148a53ec9ce5c431eab23064d1a1bc3b6e48ccdca4431bcad0a9cbcd480e63d9d89213bfe7ce83ce0c557574ab8526faf61a5bf067d433495d2cb05f2b50f8d4f5e59cda5698b1024ba58e33d106fa2edfd80987c466071c068e30ee3d15e6fc1cb242931770de36bdd42b937eada4e804fe5e9b1aac6c42adae0c18d583a513e7203b9f6f2a8cda100ce81032511b
lower_p = 0xdd8c516b1906ebc550f093
q = 0x00c2c95e64c853063d982ae13287bbe747db57e803bae644ecf195cf75d465f8bed187986358601ff6c241944bc8336980a0cb3549b325f4115ea7bc504139873f5415651eb5785e6bd05c945c87916ba21e133ac2c45158f229a333b0ead5ec68bcfa55e8c4128a4c4dd062edde5d24d6f35200188a1350abc9917622612d5eab0d80b4fabec99c7a093f21eb36783bc6488da3ed5b641a24c86490ebf72628dc3a78fc82f1d22964a4cb2f65b4d7077e2b512d90f5908eb0ec70d6a559ce8661bdd29f007ba522ff06efe6d9fa6ac0d940531eeea2541025ca4300be6a63ca79daa26db53fee8b7832cc04fc16ab92f152cc563fd1091d7350ab15b0bdd8eeef
dp = 0x7beaacf420ed84b2553e7bf620d1231c56bc767476fa74fc2b4ec8fd63c2c15498c695851ff8bb3c8e049a3fcbc421ca48fd3e5261acb7a04171f1418099978c30b797a4809a9ab28bada43812dbdff65907c73416f31e3cf2a42c2bab34d87f6659a311e4b7acae034bb57c72505355ebe4fe31f079bbec52eaa89567707e8508c157e81b0ef5d83d26b878d5b9890d67884cd5b3fecdbade29db3d4aa37dbe5b58884e80f4010855b831760cd9bcabc25edbfeacc4328d24525461feafc61f3cb6b23aa9f9e10b4cfd766dd0bdf352a298974b38dcd6e1b688eb2f843f1ad3748f35a1f0bdc4c14b11619fad9bd8d169ab2ed0df08bb8cc18e15a950608ffb
p = 0
for kp in range(3, e):
p_mul = dp * e - 1
# Only need to continue if p_mul is divisible by kp
if p_mul % kp == 0:
p = (p_mul // kp) + 1
# Check if number is prime and ends with our known lower bits
if sympy.isprime(p) and hex(p).endswith(hex(lower_p)[2:]):
print(hex(p))
n = p * q
phi = (p-1)*(q-1)
d = pow(e,-1,phi)
from Crypto.PublicKey import RSA
key = RSA.construct((n,e,d,p,q))
pem = key.exportKey(format='PEM')
print(pem.decode())