mirror of
https://github.com/autistic-symposium/sec-pentesting-toolkit.git
synced 2025-04-27 19:16:08 -04:00
some small fixes
This commit is contained in:
parent
9cdfa95054
commit
205c732ea0
@ -0,0 +1,93 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
__author__ = "bt3gl"
|
||||
__email__ = "bt3gl@gmail.com"
|
||||
|
||||
import decimal
|
||||
import socket
|
||||
from constants import mod
|
||||
|
||||
def print_hex(secret):
|
||||
|
||||
# cutting L in the end
|
||||
a = hex(secret)[:-1]
|
||||
|
||||
# cutting the \x symbol
|
||||
b = a[2:].decode('hex')
|
||||
|
||||
return b
|
||||
|
||||
|
||||
|
||||
def convolution(e1, e2, m2, mod):
|
||||
|
||||
return (e1 * e2 )%(mod*mod)
|
||||
|
||||
|
||||
|
||||
def nc_paillier(mod):
|
||||
|
||||
# create socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((HOST, PORT))
|
||||
|
||||
|
||||
# answer the initial question
|
||||
s.recv(4096)
|
||||
s.send(b'paillier')
|
||||
s.recv(4096)
|
||||
m = s.recv(4096)
|
||||
m = (m.split(": ")[1]).split('\n')[0]
|
||||
mdec = decimal.Decimal(m)
|
||||
|
||||
|
||||
# encrypt 1
|
||||
e = '1'
|
||||
m2 = decimal.Decimal(e)
|
||||
s.send(b'E')
|
||||
s.recv(4096)
|
||||
s.send(e)
|
||||
e2 = s.recv(4096)
|
||||
e2 = e2.split(": ")[1]
|
||||
e2dec = decimal.Decimal(e2)
|
||||
|
||||
|
||||
|
||||
# convolute the enc messages
|
||||
answer = convolution(mdec, e2dec, m2, mod)
|
||||
|
||||
|
||||
# get the description from the answer
|
||||
s.send(b'D')
|
||||
s.recv(4096)
|
||||
s.recv(4096)
|
||||
s.send(str(answer))
|
||||
md = s.recv(4096)
|
||||
md = md.split(": ")[1].strip()
|
||||
|
||||
|
||||
|
||||
# get the flag, remember to add d(e(1)) = 1
|
||||
secret = long(md) + 1
|
||||
flag = print_hex(secret)
|
||||
print("The flag is: ")
|
||||
print flag
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
# really long numbers
|
||||
decimal.getcontext().prec = 1240
|
||||
|
||||
PORT = 12445
|
||||
HOST = 'asis-ctf.ir'
|
||||
|
||||
nc_paillier(mod)
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
__author__ = "bt3gl"
|
||||
__email__ = "bt3gl@gmail.com"
|
||||
|
||||
|
||||
import decimal
|
||||
import socket
|
||||
|
||||
|
||||
|
||||
|
||||
def bs_paillier(lo, hi, s):
|
||||
if hi < lo: return None
|
||||
mid = (hi + lo) // 2
|
||||
print("We are at: ")
|
||||
print(mid)
|
||||
|
||||
s.send(b'E')
|
||||
s.recv(4096)
|
||||
s.send(str(mid)[:-1])
|
||||
ans = s.recv(4096)
|
||||
|
||||
if 'None' in ans:
|
||||
print "Found it!"
|
||||
return mid + 1
|
||||
elif 'Your secret' in ans:
|
||||
return bs_paillier(lo, mid-1, s)
|
||||
else:
|
||||
return bs_paillier(mid+1, hi, s)
|
||||
|
||||
|
||||
|
||||
|
||||
def get_mod_paillier():
|
||||
|
||||
# create socket, answer first question
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((HOST, PORT))
|
||||
s.recv(4096)
|
||||
s.send(b'paillier')
|
||||
s.recv(4096)
|
||||
|
||||
# start binary search
|
||||
hi = pow(11,307)
|
||||
lo = pow(10,307)
|
||||
mod = bs_paillier(lo, hi, s)
|
||||
print mod
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
PORT = 12445
|
||||
HOST = 'asis-ctf.ir'
|
||||
|
||||
get_mod_paillier()
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,4 @@
|
||||
import decimal
|
||||
|
||||
#mod = decimal.Decimal('28414252178421170251910042147689368446511995764529924640302525001150082023847807850723344018358163485930344707394699713532305322202216635189806057491940857063203918400016948903778913790645080815377317956510275921513980400357522675326929234601338948461475089468134681894547897715946279673410647104276477333937')
|
||||
mod = decimal.Decimal('17671943390317527594740575037779239788090749028363849573873871285525785364877468659238291287413782918855995881353189626069716161186805808731291508724925847487655603905895106750055611619881911787280882269077856999823769344599404478814635216943095238063240285592085964648122007040660676934950342692770738186633')
|
@ -0,0 +1,85 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
__author__ = "bt3gl"
|
||||
__email__ = "bt3gl@gmail.com"
|
||||
|
||||
|
||||
import decimal
|
||||
import socket
|
||||
|
||||
|
||||
def nc_paillier():
|
||||
|
||||
# create socket
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
s.connect((HOST, PORT))
|
||||
|
||||
|
||||
# answer the initial question
|
||||
print s.recv(4096)
|
||||
s.send(b'paillier')
|
||||
|
||||
|
||||
# get the secret
|
||||
print s.recv(4096)
|
||||
m = s.recv(4096)
|
||||
|
||||
# cleaning it
|
||||
m = (m.split(": ")[1]).split('\n')[0]
|
||||
|
||||
# it's good to print (because it changes periodically)
|
||||
print("The secret is: ")
|
||||
print(m)
|
||||
|
||||
# change from str to long decimal
|
||||
mdec = decimal.Decimal(m)
|
||||
|
||||
|
||||
'''
|
||||
From here you can do whatever you want.
|
||||
'''
|
||||
# If you want to encrypt messages
|
||||
|
||||
msg_to_e = '1'
|
||||
|
||||
s.send(b'E')
|
||||
print s.recv(4096)
|
||||
s.send(msg_to_e)
|
||||
me = s.recv(4096)
|
||||
me = me.split(": ")[1]
|
||||
|
||||
print("Secret for %s is:" %(msg_to_e))
|
||||
print(me)
|
||||
|
||||
medec = decimal.Decimal(me)
|
||||
|
||||
|
||||
# If you want to decrypt messages
|
||||
|
||||
msg_to_d = me
|
||||
|
||||
s.send(b'D')
|
||||
s.recv(4096)
|
||||
s.recv(4096)
|
||||
s.send(msg_to_d)
|
||||
md = s.recv(4096)
|
||||
md = md.split(": ")[1].strip()
|
||||
|
||||
print("Decryption is: ")
|
||||
print(md)
|
||||
|
||||
mddec = decimal.Decimal(md)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# really long numbers
|
||||
decimal.getcontext().prec = 1240
|
||||
|
||||
PORT = 12445
|
||||
HOST = 'asis-ctf.ir'
|
||||
|
||||
nc_paillier()
|
||||
|
Loading…
x
Reference in New Issue
Block a user