Temporary Advertisements:
Ad
Ad
Ad
Need help to find the flag.
by terminaluzer1 - Friday June 7, 2024 at 06:47 PM
#1
Can someone help me with what this is

chall.py
```
from random import getrandbits
from Crypto.Util.number import getPrime, bytes_to_long
from SECRET import FLAG
e = 2
p = getPrime(256)
q = getPrime(256)
n = p * q
m = bytes_to_long(FLAG)
cor_m = m - getrandbits(160)
if __name__ == "__main__":
    c = pow(m, e, n)
    print("n = {}\nc = {}\ncor_m = {}".format(n, c, cor_m))
```

out.txt
```
n = 5113166966960118603250666870544315753374750136060769465485822149528706374700934720443689630473991177661169179462100732951725871457633686010946951736764639
c = 329402637167950119278220170950190680807120980712143610290182242567212843996710001488280098771626903975534140478814872389359418514658167263670496584963653
cor_m = 724154397787031699242933363312913323086319394176220093419616667612889538090840511507392245976984201647543870740055095781645802588721
```
Reply
#2
what is the name of the machine

This forum account is currently banned. Ban Length: Permanent (N/A Remaining)
Ban Reason: Advertising Telegram in Stealer Logs
Reply
#3
crypto RSA challenge with very small public exponent e = 2
find appropriate attack on RSA crypto where public exponent is too small.
Reply
#4
from Crypto.Util.number import bytes_to_long, long_to_bytes, getPrime
from sympy import mod_sqrt
from random import getrandbits

# Given values (these would be the actual output from the script)
n = <value_of_n>
c = <value_of_c>
cor_m = <value_of_cor_m>

# Function to find square root modulo n
def modular_sqrt(a, p):
""" Find a quadratic residue (mod p) of 'a'. """
return mod_sqrt(a, p)

# Calculate possible m values
possible_m = modular_sqrt(c, n)
if possible_m is None:
print("No solution exists")
else:
# Since e=2, there might be two solutions
m1 = possible_m
m2 = n - possible_m

# Check which one matches the range for cor_m
if cor_m <= m1 < cor_m + (1 << 160):
recovered_m = m1
else:
recovered_m = m2

# Convert back to bytes
recovered_flag = long_to_bytes(recovered_m)
print("Recovered FLAG:", recovered_flag)
Reply
#5
thanks so much i was hoping to get pointed in the right or any direction.
Reply
#6
(Jun 07, 2024, 08:25 PM)tenebrae Wrote: from Crypto.Util.number import bytes_to_long, long_to_bytes, getPrime
from sympy import mod_sqrt
from random import getrandbits

# Given values (these would be the actual output from the script)
n = <value_of_n>
c = <value_of_c>
cor_m = <value_of_cor_m>

# Function to find square root modulo n
def modular_sqrt(a, p):
    """ Find a quadratic residue (mod p) of 'a'. """
    return mod_sqrt(a, p)

# Calculate possible m values
possible_m = modular_sqrt(c, n)
if possible_m is None:
    print("No solution exists")
else:
    # Since e=2, there might be two solutions
    m1 = possible_m
    m2 = n - possible_m

    # Check which one matches the range for cor_m
    if cor_m <= m1 < cor_m + (1 << 160):
        recovered_m = m1
    else:
        recovered_m = m2

    # Convert back to bytes
    recovered_flag = long_to_bytes(recovered_m)
    print("Recovered FLAG:", recovered_flag)

Thanks, can you tell me what is the name of the chall ?
Reply
#7
from Crypto.Util.number import bytes_to_long, long_to_bytes, getPrime
from sympy import mod_sqrt
from random import getrandbits

# Given values (these would be the actual output from the script)
n = <value_of_n>
c = <value_of_c>
cor_m = <value_of_cor_m>

# Function to find square root modulo n
def modular_sqrt(a, p):
""" Find a quadratic residue (mod p) of 'a'. """
return mod_sqrt(a, p)

# Calculate possible m values
possible_m = modular_sqrt(c, n)
if possible_m is None:
print("No solution exists")
else:
# Since e=2, there might be two solutions
m1 = possible_m
m2 = n - possible_m

# Check which one matches the range for cor_m
if cor_m <= m1 < cor_m + (1 << 160):
recovered_m = m1
else:
recovered_m = m2

# Convert back to bytes
recovered_flag = long_to_bytes(recovered_m)
print("Recovered FLAG:", recovered_flag)

This forum account is currently banned. Ban Length: Permanent (N/A Remaining)
Ban Reason: Reposting hidden content for free
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [FREE] HackTheBox Academy - CBBH CDSA CPTS All Modules Flags Techtom 110 14,218 3 hours ago
Last Post: Kazahk
Heart [FREE] HackTheBox All Cheatsheets Tamarisk 85 11,225 3 hours ago
Last Post: Kazahk
  [MEGALEAK] HackTheBox ProLabs, Fortress, Endgame - Alchemy, 250 Flags, leak htb-bot htb-bot 165 34,710 Today, 08:27 AM
Last Post: groningen1981
  Finding solutions/flags/writeups for challenges meomeothantai 0 161 Today, 04:13 AM
Last Post: meomeothantai
  [FREE] HackTheBox Dante - complete writeup written by Tamarisk Tamarisk 625 115,378 Today, 03:26 AM
Last Post: kevin25hxl

Forum Jump:


 Users browsing this forum: 1 Guest(s)