Skip to content

Commit 3c1ddb4

Browse files
committedJan 3, 2025
Added 2023 Crypto challenges, will start 2022 next week!
1 parent e7dde35 commit 3c1ddb4

File tree

24 files changed

+579
-37
lines changed

24 files changed

+579
-37
lines changed
 

‎2023/crypto/Keyless/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Title
2+
3+
Keyless
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
CryptoCat
12+
13+
# Difficulty
14+
15+
Easy
16+
17+
# Description
18+
19+
My friend made a new encryption algorithm. Apparently it's so advanced, you don't even need a key!
20+
21+
# Flag
22+
23+
`INTIGRITI{m4yb3_4_k3y_w0uld_b3_b3773r_4f73r_4ll}`

‎2023/crypto/Keyless/keyless.zip

618 Bytes
Binary file not shown.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[FULL VIDEO WRITEUP](https://youtu.be/CsyQFzTJ09w?t=600)
2+
3+
#### solve.py
4+
5+
```py
6+
def decrypt(encrypted_message):
7+
decrypted_message = ""
8+
for char in encrypted_message:
9+
c_reverse = ord(char) ^ 23
10+
b_reverse = (c_reverse + 7) // 3
11+
a_reverse = (b_reverse - 5) ^ 42
12+
decrypted_char = (a_reverse - 10) // 2
13+
decrypted_message += chr(decrypted_char)
14+
return decrypted_message
15+
16+
with open("flag.txt.enc", "r") as file:
17+
encrypted_flag = file.read()
18+
19+
decrypted_flag = decrypt(encrypted_flag)
20+
print(decrypted_flag)
21+
```

‎2023/crypto/NotSoSmooth/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Title
2+
3+
Not So Smooth
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
ConnorM
12+
13+
# Difficulty
14+
15+
Easy
16+
17+
# Description
18+
19+
TODO
20+
21+
# Flag
22+
23+
`INTIGRITI{1e863724be1ea6d3e}`
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from Crypto.Util.number import long_to_bytes
2+
from Crypto.Util.strxor import strxor
3+
from random import randint
4+
from flag import FLAG
5+
6+
def f(x, n):
7+
return (pow(u,n,p)*x + v*(1-pow(u,n,p))*pow(1-u, -1, p)) % p
8+
9+
p = 97201997431130462639713476119411091922677381239967611061717766639853376871260165905989218335681560177626304205941143288128749532327607316527719299945637260643711897738116821179208534292854942631428531228316344113303402450588666012800739695018334321748049518585617428717505851025279186520225325765864212731597
10+
u = 14011530787746260724685809284106528245188320623672333581950055679051366424425259006994945665868546765648275822501035229606171697373122374288934559593175958252416643298136731105775907857798815936190074350794406666922357841091849449562922724459876362600203284195621546769313749721476449207319566681142955460891977927184371401451946649848065952527323468939007868874410618846898618148752279316070498097254384228565132693552949206926391461108714034141321700284318834819732949544823937032615318011463993204345644038210938407875147446570896826729265366024224612406740371824999201173579640264979086368843819069035017648357042
11+
v = 16560637729264127314502582188855146263038095275553321912067588804088156431664370603746929023264744622682435376065011098909463163865218610904571775751705336266271206718700427773757241393847274601309127403955317959981271158685681135990095066557078560050980575698278958401980987514566688310172721963092100285717921465575782434632190913355536291988686994429739581469633462010143996998589435537178075521590880467628369030177392034117774853431604525531066071844562073814187461299329339694285509725214674761990940902460186665127466202741989052293452290042871514149972640901432877318075354158973805495004367245286709191395753
12+
w = 30714296289538837760400431621661767909419746909959905820574067592409316977551664652203146506867115455464665524418603262821119202980897986798059489126166547078057148348119365709992892615014626003313040730934533283339617856938614948620116906770806796378275546490794161777851252745862081462799572448648587153412425374338967601487603800379070501278705056791472269999767679535887678042527423534392867454254712641029797659150392148648565421400107500607994226410206105774620083214215531253544274444448346065590895353139670885420838370607181375842930315910289979440845957719622069769102831263579510660283634808483329218819353
13+
a = randint(0, 2**2048)
14+
b = randint(0, 2**2048)
15+
A = f(w, a)
16+
B = f(w, b)
17+
key = long_to_bytes(f(B, a))[:len(FLAG)]
18+
enc = strxor(FLAG, key)
19+
print(f"{A = }")
20+
print(f"{B = }")
21+
print(f"{enc = }")
22+
23+
"""
24+
A = 7393401480034113709683683682039780458211722756040975666277858366986963864147091724359492764726999692812421940595309756560491142512219957986281425163574890752574157617546760386852366936945888357800966704941013951530688031419816817272581287237223765833452303447283089906937413964658335387593899889933721262202
25+
B = 6919381992041136573008188094979879971060160509085428532054694712745921654244468113796582501225839242977870949915769181804595896718922228206397860738237256125972615830799470450058633231003927061049289907097099916321068776956652172887225970642896455423957706532253349472544176183473470843719479781727784095989
26+
enc = b'\xcfW\x85\x8d\xedU\xdd\xd9`\x16f\xb8j(\xeb9-\x1b\xb8\x18 0av\xe5\xabK\xc6'
27+
"""
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[COMMUNITY WRITEUP](https://berliangabriel.github.io/post/1337up-ctf-2023/)
2+
3+
#### solve.py
4+
5+
```py
6+
from Crypto.Util.number import long_to_bytes
7+
from Crypto.Util.strxor import strxor
8+
9+
p = 97201997431130462639713476119411091922677381239967611061717766639853376871260165905989218335681560177626304205941143288128749532327607316527719299945637260643711897738116821179208534292854942631428531228316344113303402450588666012800739695018334321748049518585617428717505851025279186520225325765864212731597
10+
u = 14011530787746260724685809284106528245188320623672333581950055679051366424425259006994945665868546765648275822501035229606171697373122374288934559593175958252416643298136731105775907857798815936190074350794406666922357841091849449562922724459876362600203284195621546769313749721476449207319566681142955460891977927184371401451946649848065952527323468939007868874410618846898618148752279316070498097254384228565132693552949206926391461108714034141321700284318834819732949544823937032615318011463993204345644038210938407875147446570896826729265366024224612406740371824999201173579640264979086368843819069035017648357042
11+
v = 16560637729264127314502582188855146263038095275553321912067588804088156431664370603746929023264744622682435376065011098909463163865218610904571775751705336266271206718700427773757241393847274601309127403955317959981271158685681135990095066557078560050980575698278958401980987514566688310172721963092100285717921465575782434632190913355536291988686994429739581469633462010143996998589435537178075521590880467628369030177392034117774853431604525531066071844562073814187461299329339694285509725214674761990940902460186665127466202741989052293452290042871514149972640901432877318075354158973805495004367245286709191395753
12+
w = 30714296289538837760400431621661767909419746909959905820574067592409316977551664652203146506867115455464665524418603262821119202980897986798059489126166547078057148348119365709992892615014626003313040730934533283339617856938614948620116906770806796378275546490794161777851252745862081462799572448648587153412425374338967601487603800379070501278705056791472269999767679535887678042527423534392867454254712641029797659150392148648565421400107500607994226410206105774620083214215531253544274444448346065590895353139670885420838370607181375842930315910289979440845957719622069769102831263579510660283634808483329218819353
13+
A = 7393401480034113709683683682039780458211722756040975666277858366986963864147091724359492764726999692812421940595309756560491142512219957986281425163574890752574157617546760386852366936945888357800966704941013951530688031419816817272581287237223765833452303447283089906937413964658335387593899889933721262202
14+
B = 6919381992041136573008188094979879971060160509085428532054694712745921654244468113796582501225839242977870949915769181804595896718922228206397860738237256125972615830799470450058633231003927061049289907097099916321068776956652172887225970642896455423957706532253349472544176183473470843719479781727784095989
15+
enc = b'\xcfW\x85\x8d\xedU\xdd\xd9`\x16f\xb8j(\xeb9-\x1b\xb8\x18 0av\xe5\xabK\xc6'
16+
17+
k = v * pow(1-u, -1, p)
18+
ua = (k-A) * pow(k-w, -1, p)
19+
key = (ua*B + v*(1-ua)*pow(1-u, -1, p)) % p
20+
key = long_to_bytes(key)[:len(enc)]
21+
print(strxor(enc, key).decode())
22+
```

‎2023/crypto/OneEquation/README.md

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Title
2+
3+
One equation, ten unknowns?
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
ConnorM
12+
13+
# Difficulty
14+
15+
Medium
16+
17+
# Flag
18+
19+
`INTIGRITI{3a8a32c7f6}`
2.08 KB
Binary file not shown.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[COMMUNITY WRITEUP](https://berliangabriel.github.io/post/1337up-ctf-2023/)
2+
3+
#### solve.sage
4+
5+
```py
6+
from out import cs, s
7+
8+
vrs = [var(f'x_{i}') for i in range(10)]
9+
equation = sum(c*v for c, v in zip(cs, vrs)) - s
10+
coeffs = equation.polynomial(ZZ).coefficients()
11+
M = Matrix(coeffs).transpose()
12+
M = M.augment(identity_matrix(M.nrows()))
13+
M[-1, -1] = 0
14+
M = M.LLL()
15+
flag = ""
16+
for i in M[0][1:-1]:
17+
flag += chr(i % 1000)
18+
print("INTIGRITI{%s}" % flag)
19+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Title
2+
3+
Really Secure Apparently
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
CryptoCat
12+
13+
# Difficulty
14+
15+
Easy
16+
17+
# Description
18+
19+
Apparently this encryption is "really secure" and I don't need to worry about sharing the ciphertext, or even these values..
20+
21+
n = 689061037339483636851744871564868379980061151991904073814057216873412583484720768694905841053416938972235588548525570270575285633894975913717130070544407480547826227398039831409929129742007101671851757453656032161443946817685708282221883187089692065998793742064551244403369599965441075497085384181772038720949
22+
e = 98161001623245946455371459972270637048947096740867123960987426843075734419854169415217693040603943985614577854750928453684840929755254248201161248375350238628917413291201125030514500977409961838501076015838508082749034318410808298025858181711613372870289482890074072555265382600388541381732534018133370862587
23+
24+
# Flag
25+
26+
`INTIGRITI{0r_n07_50_53cur3_m4yb3}`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tʁ���Q����gb7]]�����G]~U[7�%̍9�zV��A[�]�g*��e�<�U:�ϗZ�FGU1=S �U��0��ġ�>���m'R0�8��H#�E�O�,BwoZy��cîp��&Xb �J֫ov�
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import rsa
2+
3+
e = 98161001623245946455371459972270637048947096740867123960987426843075734419854169415217693040603943985614577854750928453684840929755254248201161248375350238628917413291201125030514500977409961838501076015838508082749034318410808298025858181711613372870289482890074072555265382600388541381732534018133370862587
4+
n = 689061037339483636851744871564868379980061151991904073814057216873412583484720768694905841053416938972235588548525570270575285633894975913717130070544407480547826227398039831409929129742007101671851757453656032161443946817685708282221883187089692065998793742064551244403369599965441075497085384181772038720949
5+
d = 65399441570747996612246087958644390242089073014389060882369755525057949069503
6+
7+
# Generate an RSA public key with the specified values
8+
pub_key = rsa.PublicKey(n, e)
9+
10+
# Save the public key (n, e) to a file
11+
with open('public_key.pem', 'wb') as f:
12+
f.write(pub_key.save_pkcs1(format='PEM'))
13+
14+
# Encrypt a message using the public key
15+
message = b'Well done! Here is your flag: INTIGRITI{0r_n07_50_53cur3_m4yb3}'
16+
ciphertext = rsa.encrypt(message, pub_key)
17+
18+
# Convert the ciphertext to an integer
19+
ciphertext_int = int.from_bytes(ciphertext, byteorder='big')
20+
21+
# Save the ciphertext as an integer to a binary file
22+
with open('ciphertext', 'wb') as f:
23+
f.write(ciphertext_int.to_bytes((ciphertext_int.bit_length() + 7) // 8, byteorder='big'))
24+
25+
# Provide participants with the public key (n, e) and ciphertext
26+
print(f"n = {n}")
27+
print(f"e = {e}")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
"""
2+
The MIT License (MIT)
3+
Copyright (c) 2019-2023 Nao Yonashiro
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19+
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21+
OR OTHER DEALINGS IN THE SOFTWARE.
22+
"""
23+
from typing import Tuple, Iterator, Iterable, Optional
24+
25+
26+
def isqrt(n: int) -> int:
27+
"""
28+
ref: https://en.wikipedia.org/wiki/Integer_square_root
29+
30+
>>> isqrt(289)
31+
17
32+
>>> isqrt(2)
33+
1
34+
>>> isqrt(1000000 ** 2)
35+
1000000
36+
"""
37+
if n == 0:
38+
return 0
39+
40+
# ref: https://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Rough_estimation
41+
x = 2 ** ((n.bit_length() + 1) // 2)
42+
while True:
43+
y = (x + n // x) // 2
44+
if y >= x:
45+
return x
46+
x = y
47+
48+
49+
def is_perfect_square(n: int) -> bool:
50+
"""
51+
ref: https://hnw.hatenablog.com/entry/20140503
52+
53+
>>> is_perfect_square(100)
54+
True
55+
56+
>>> is_perfect_square(2000000000000000000000000000 ** 2)
57+
True
58+
59+
>>> is_perfect_square(2000000000000000000000000000 ** 2 + 1)
60+
False
61+
"""
62+
sq_mod256 = (1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,1,0,0,0,0,0,0)
63+
if sq_mod256[n & 0xff] == 0:
64+
return False
65+
66+
mt = (
67+
(9, (1,1,0,0,1,0,0,1,0)),
68+
(5, (1,1,0,0,1)),
69+
(7, (1,1,1,0,1,0,0)),
70+
(13, (1,1,0,1,1,0,0,0,0,1,1,0,1)),
71+
(17, (1,1,1,0,1,0,0,0,1,1,0,0,0,1,0,1,1))
72+
)
73+
a = n % (9 * 5 * 7 * 13 * 17)
74+
if any(t[a % m] == 0 for m, t in mt):
75+
return False
76+
77+
return isqrt(n) ** 2 == n
78+
79+
80+
def rational_to_contfrac(x: int, y: int) -> Iterator[int]:
81+
"""
82+
ref: https://en.wikipedia.org/wiki/Euclidean_algorithm#Continued_fractions
83+
84+
>>> list(rational_to_contfrac(4, 11))
85+
[0, 2, 1, 3]
86+
"""
87+
while y:
88+
a = x // y
89+
yield a
90+
x, y = y, x - a * y
91+
92+
93+
def contfrac_to_rational_iter(contfrac: Iterable[int]) -> Iterator[Tuple[int, int]]:
94+
"""
95+
ref: https://www.cits.ruhr-uni-bochum.de/imperia/md/content/may/krypto2ss08/shortsecretexponents.pdf (6)
96+
"""
97+
n0, d0 = 0, 1
98+
n1, d1 = 1, 0
99+
for q in contfrac:
100+
n = q * n1 + n0
101+
d = q * d1 + d0
102+
yield n, d
103+
n0, d0 = n1, d1
104+
n1, d1 = n, d
105+
106+
107+
def convergents_from_contfrac(contfrac: Iterable[int]) -> Iterator[Tuple[int, int]]:
108+
"""
109+
ref: https://www.cits.ruhr-uni-bochum.de/imperia/md/content/may/krypto2ss08/shortsecretexponents.pdf Section.3
110+
"""
111+
n_, d_ = 1, 0
112+
for i, (n, d) in enumerate(contfrac_to_rational_iter(contfrac)):
113+
if i % 2 == 0:
114+
yield n + n_, d + d_
115+
else:
116+
yield n, d
117+
n_, d_ = n, d
118+
119+
120+
def attack(e: int, n: int) -> Optional[int]:
121+
"""
122+
ref: https://www.cits.ruhr-uni-bochum.de/imperia/md/content/may/krypto2ss08/shortsecretexponents.pdf Section.4
123+
124+
>>> attack(2621, 8927)
125+
5
126+
>>> attack(6792605526025, 9449868410449)
127+
569
128+
>>> attack(30749686305802061816334591167284030734478031427751495527922388099381921172620569310945418007467306454160014597828390709770861577479329793948103408489494025272834473555854835044153374978554414416305012267643957838998648651100705446875979573675767605387333733876537528353237076626094553367977134079292593746416875606876735717905892280664538346000950343671655257046364067221469807138232820446015769882472160551840052921930357988334306659120253114790638496480092361951536576427295789429197483597859657977832368912534761100269065509351345050758943674651053419982561094432258103614830448382949765459939698951824447818497599, 109966163992903243770643456296093759130737510333736483352345488643432614201030629970207047930115652268531222079508230987041869779760776072105738457123387124961036111210544028669181361694095594938869077306417325203381820822917059651429857093388618818437282624857927551285811542685269229705594166370426152128895901914709902037365652575730201897361139518816164746228733410283595236405985958414491372301878718635708605256444921222945267625853091126691358833453283744166617463257821375566155675868452032401961727814314481343467702299949407935602389342183536222842556906657001984320973035314726867840698884052182976760066141)
129+
4221909016509078129201801236879446760697885220928506696150646938237440992746683409881141451831939190609743447676525325543963362353923989076199470515758399
130+
"""
131+
f_ = rational_to_contfrac(e, n)
132+
for k, dg in convergents_from_contfrac(f_):
133+
edg = e * dg
134+
phi = edg // k
135+
136+
x = n - phi + 1
137+
if x % 2 == 0 and is_perfect_square((x // 2) ** 2 - n):
138+
g = edg - phi * k
139+
return dg // g
140+
return None
141+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN RSA PRIVATE KEY-----
2+
MIICNQIBAAKBgBwDydG/EOPewhzKQpHUR9XVdGL3JZAAymVGGlZvweGuuBEneqYj
3+
cnigg4a7GccQt4+0qR0CfYnMk0WzqwdrfhY16frMZpeAxSZ8AfbzmdZqsAXQuq02
4+
PKjToaz18Ss1PvjQ2SRR9RG9oQ6qJ3XqOlpe9N5fnhriNkeixVGDuHQtAoGAGq8E
5+
x2Csh6cezdqtPy5WiVvUBBTiAGNr1qv8lJZhJAms1HFTlGfFfV9vq+3HJQl8ealT
6+
Ka559DjhYSulsn6XenPpsbA1Pph+f10tLKBDYIu5JwOilaYQt5dL6X+d2C32kjnx
7+
phJbWfydw0DvrGSm4+wu7lAJGrrQfOwliVMcfBsCIBVZYC9iSJJ/3Lvse81d4KAb
8+
p5ooOoDxxW23ogpcHVv/AkBolqQqBt1Fsxzn3ngntfP4969ouCljF1BwLrNbdukJ
9+
yuMQY/OuIafhS3U6GmPmChrysTJvZIPOyUqUQ6/8LdqfAkBEkk8P1uBqkd69W5Mj
10+
vh2IBQX1P0JoGpZY+sprur/lLVlR6dfwBE6trhlgGldBaVxceO4hNJtgDRQj98RD
11+
ZwmzAiAVWWAvYkiSf9y77HvNXeCgG6eaKDqA8cVtt6IKXB1b/wIgFVlgL2JIkn/c
12+
u+x7zV3goBunmig6gPHFbbeiClwdW/8CQFy081xzAYF20FVTr16Sj8Kxdq/s0Edb
13+
3rg7LzNb+8ETslCRh20nYHZYE47ANVu68v82SHMljF2mBtwBmA7OHQI=
14+
-----END RSA PRIVATE KEY-----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-----BEGIN RSA PUBLIC KEY-----
2+
MIIBCAKBgQPVQWe1LALvFgGiY3q0emUfGgZ+c6mNET/QfITxKaJcIGXw3InihAg8
3+
U2uDnhcqGeKMfqOIAOYgGAwOr9dFYaz88uezNsUTNBQAO7aSltv/X7NagSgfu7ao
4+
eVYyfPouxnPLlFY0v93UAe+2rrDR2c2bVxVLRed0B8aHGtaYH2BNtQKBgQCLyTEo
5+
NndMpuOU9pCrO9N52QuLsHDTR0358Sn4oYSrnSUDkP89yUcj9QOIQFWk3m/ovyGx
6+
HDWSKTJ3yT3913xqNr46OBkTW/o16jLekXN4z1Uf+DOAgMpBq5GMGXRz88dpemP/
7+
Q98f/ueYMwsU93EEahYiEv9JkD5GBrNXij/7+w==
8+
-----END RSA PUBLIC KEY-----
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
[COMMUNITY WRITEUP](https://meashiri.github.io/ctf-writeups/posts/202311-1337up/#really-secure-apparently)
2+
3+
#### solve.py
4+
5+
```py
6+
import owiener
7+
import binascii
8+
9+
e = 98161001623245946455371459972270637048947096740867123960987426843075734419854169415217693040603943985614577854750928453684840929755254248201161248375350238628917413291201125030514500977409961838501076015838508082749034318410808298025858181711613372870289482890074072555265382600388541381732534018133370862587
10+
n = 689061037339483636851744871564868379980061151991904073814057216873412583484720768694905841053416938972235588548525570270575285633894975913717130070544407480547826227398039831409929129742007101671851757453656032161443946817685708282221883187089692065998793742064551244403369599965441075497085384181772038720949
11+
12+
# Load the ciphertext as an integer from a binary file (adjust the file path accordingly)
13+
with open('ciphertext', 'rb') as f:
14+
ciphertext_int = int.from_bytes(f.read(), byteorder='big')
15+
16+
# Use the Wiener's Attack to recover the private exponent (d)
17+
d = owiener.attack(e, n)
18+
19+
# Decrypt the ciphertext and convert it to plaintext
20+
flag = pow(ciphertext_int, d, n).to_bytes((ciphertext_int.bit_length() + 7) // 8, byteorder='big')
21+
print(f"Flag: {flag}")
22+
```

‎2023/crypto/ShareIt1/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Title
2+
3+
Share It (part 1)
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
holmesec
12+
13+
# Difficulty
14+
15+
Easy
16+
17+
# Description
18+
19+
Check out my new cool platform for sharing your thoughts. I used my 1337 crypto skills to craft session tokens 🔐
20+
21+
# Flag
22+
23+
`INTIGRITI{1v_1ike_t0_fl1p_bit5}`

‎2023/crypto/ShareIt1/shareit1.zip

16 KB
Binary file not shown.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[COMMUNITY WRITEUP](https://github.com/Franc-Zar/CTFsWriteups/blob/main/1337-Intigriti-CTF/crypto/share-it-part-1/share_it.md)
2+
3+
#### solve.py
4+
5+
```py
6+
import base64
7+
from pwn import xor
8+
import json
9+
10+
token = json.loads(base64.b64decode(input("Paste token: ")))
11+
iv = base64.b64decode(token['iv'])
12+
13+
new_iv = xor(xor(b'{"admin": false,', b'{"admin": true, '), iv)
14+
15+
token['iv'] = base64.b64encode(new_iv).decode()
16+
17+
print('New token with modified IV:', base64.b64encode(
18+
json.dumps(token).encode()).decode())
19+
```

‎2023/crypto/ShareIt2/README.md

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Title
2+
3+
Share It (part 2)
4+
5+
# Category
6+
7+
🔐 Crypto
8+
9+
# Author
10+
11+
holmesec
12+
13+
# Difficulty
14+
15+
Medium
16+
17+
# Description
18+
19+
I heard some people were able to tamper with the IV, so I removed it from the cookie. I even did some debug testing and discovered that even if the IV could be modified it is not enough to set the admin attribute of the new tokens!
20+
21+
# Flag
22+
23+
`INTIGRITI{b10ck_by_3lock}`

‎2023/crypto/ShareIt2/shareit2.zip

16.3 KB
Binary file not shown.
+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
[COMMUNITY WRITEUP](https://github.com/Franc-Zar/CTFsWriteups/blob/main/1337-Intigriti-CTF/crypto/share-it-part-2/share_it.md)
2+
3+
#### solve.py
4+
5+
```py
6+
import requests
7+
import base64
8+
import json
9+
from pwn import xor
10+
import binascii
11+
12+
host = 'http://localhost:1337'
13+
14+
orig_pt = b'{"username": "012", "first_name": "345", "last_name": "6789abc", "admin": false}'
15+
16+
r = requests.post(f'{host}/register', data={"username": "bla",
17+
"first_name": "lel", "last_name": "hihi123"}, allow_redirects=False)
18+
19+
token = json.loads(base64.b64decode(r.cookies['token']))
20+
c = base64.b64decode(token['user_dict'])
21+
22+
# extra space since "true" is one char less than "false"
23+
c_new_bytes = xor(xor(orig_pt[-16:], b' "admin": true }'), c[-16*3:-16*2])
24+
c_new = c[:-16*3] + c_new_bytes + c[-16*2:]
25+
token['user_dict'] = base64.b64encode(c_new).decode()
26+
27+
token_cookie = base64.b64encode(json.dumps(
28+
token).encode()).decode()
29+
r = requests.get(f'{host}', cookies={'token': token_cookie})
30+
31+
mod_pt = r.text[16:-1].encode().decode(
32+
'unicode_escape').encode('raw_unicode_escape')
33+
34+
c_new_bytes = xor(
35+
xor(mod_pt[-16*2:-16*1], orig_pt[-16*2:-16*1]), c_new[-16*4:-16*3])
36+
c_new = c_new[:-16*4] + c_new_bytes + c_new[-16*3:]
37+
token['user_dict'] = base64.b64encode(c_new).decode()
38+
39+
token_cookie = base64.b64encode(json.dumps(
40+
token).encode()).decode()
41+
r = requests.get(f'{host}', cookies={'token': token_cookie})
42+
43+
mod_pt = r.text[16:-1].encode().decode(
44+
'unicode_escape').encode('raw_unicode_escape')
45+
46+
c_new_bytes = xor(
47+
xor(mod_pt[-16*3:-16*2], orig_pt[-16*3:-16*2]), c_new[-16*5:-16*4])
48+
c_new = c_new[:-16*5] + c_new_bytes + c_new[-16*4:]
49+
token['user_dict'] = base64.b64encode(c_new).decode()
50+
51+
token_cookie = base64.b64encode(json.dumps(
52+
token).encode()).decode()
53+
r = requests.get(f'{host}', cookies={'token': token_cookie})
54+
55+
mod_pt = r.text[16:-1].encode().decode(
56+
'unicode_escape').encode('raw_unicode_escape')
57+
58+
c_new_bytes = xor(
59+
xor(mod_pt[-16*4:-16*3], orig_pt[-16*4:-16*3]), c_new[-16*6:-16*5])
60+
c_new = c_new[:-16*6] + c_new_bytes + c_new[-16*5:]
61+
token['user_dict'] = base64.b64encode(c_new).decode()
62+
63+
64+
print("Calculating IV...")
65+
66+
token_cookie = base64.b64encode(json.dumps(
67+
token).encode()).decode()
68+
r = requests.get(f'{host}?debug_iv={"0"*32}', cookies={'token': token_cookie})
69+
70+
mod_pt = r.text[16:-1].encode().decode(
71+
'unicode_escape').encode('raw_unicode_escape')
72+
73+
target = b'{"username":"AAA'
74+
75+
iv = xor(mod_pt[:16], target)
76+
77+
print("token:", token_cookie)
78+
print("IV:", binascii.hexlify(iv))
79+
```
Original file line numberDiff line numberDiff line change
@@ -1 +1,43 @@
11
[FULL OFFICIAL WRITEUP](https://github.com/D13David/ctf-writeups/tree/main/1337uplive/pwn/retro_as_as_service)
2+
3+
#### solve.py
4+
5+
```py
6+
from pwn import *
7+
8+
def start(argv=[], *a, **kw):
9+
if args.GDB:
10+
return gdb.debug([exe] + argv, gdbscript=gdbscript, *a, **kw)
11+
elif args.REMOTE:
12+
return remote(sys.argv[1], sys.argv[2], *a, **kw)
13+
else:
14+
return process([exe] + argv, *a, **kw)
15+
16+
gdbscript = '''
17+
'''.format(**locals())
18+
19+
exe = './runtime'
20+
exe_args = ['payload.prg']
21+
elf = context.binary = ELF(exe, checksec=False)
22+
context.log_level = 'info'
23+
context(terminal=['tmux', 'split-window', '-h'])
24+
25+
def file_to_hex(filename):
26+
try:
27+
with open(filename, 'rb') as file:
28+
file_data = file.read()
29+
hex_data = file_data.hex()
30+
return hex_data
31+
except FileNotFoundError:
32+
print(f"File '{filename}' not found.")
33+
34+
REMOTE = True
35+
36+
if REMOTE == False:
37+
io = start(exe_args)
38+
else:
39+
io = start()
40+
hex_data = file_to_hex("payload.prg")
41+
io.sendline(hex_data.encode())
42+
print(io.recvall())
43+
```

‎2023/pwn/RetroAsAService/solution/solve.py

-37
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.