mirror of
https://github.com/autistic-symposium/sec-pentesting-toolkit.git
synced 2025-08-01 19:26:16 -04:00
some small fixes
This commit is contained in:
parent
9cdfa95054
commit
205c732ea0
5 changed files with 244 additions and 0 deletions
|
@ -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)
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue