test: update files
This commit is contained in:
@@ -7,6 +7,7 @@ from Crypto.Util.Padding import pad,unpad
|
||||
context.log_level = 'debug'
|
||||
|
||||
conn = remote("localhost",10001)
|
||||
# conn = remote("172.20.14.117", 15503)
|
||||
|
||||
def encrypt(plain_text:bytes, key:bytes)->bytes:
|
||||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
|
15
crypto/easy_dhke/dockerfile
Normal file
15
crypto/easy_dhke/dockerfile
Normal file
@@ -0,0 +1,15 @@
|
||||
FROM python:3.11
|
||||
|
||||
COPY requirements.txt /app/
|
||||
|
||||
COPY flag.py /app/
|
||||
|
||||
COPY easy_dhke.py /app/
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN pip install -r requirements.txt -i https://mirrors.ustc.edu.cn/pypi/web/simple
|
||||
|
||||
EXPOSE 10001
|
||||
|
||||
CMD [ "python", "easy_dhke.py" ]
|
@@ -6,6 +6,7 @@ import signal
|
||||
import string
|
||||
import random
|
||||
import os
|
||||
from flag import flag
|
||||
|
||||
|
||||
class Task(socketserver.BaseRequestHandler):
|
||||
@@ -32,17 +33,28 @@ class Task(socketserver.BaseRequestHandler):
|
||||
return self._recvall()
|
||||
|
||||
def dhke(self):
|
||||
# p is a large prime number used for modulo operations in the Diffie-Hellman key exchange
|
||||
p = 327824197795087630552811243153730025469
|
||||
# g is the base used for generating public keys in the Diffie-Hellman key exchange
|
||||
g = 5
|
||||
# alice is Alice's private key, an integer chosen by Alice
|
||||
alice = 22751
|
||||
# bob is Bob's private key, an integer chosen by Bob
|
||||
bob = 39494
|
||||
# Bob calculates his public key as g^bob mod p and assigns it to Bob (uppercase to distinguish from private key)
|
||||
Bob = pow(g, bob, p)
|
||||
# The shared secret key is calculated by Alice using Bob's public key, raised to the power of Alice's private key mod p
|
||||
key = long_to_bytes(pow(Bob, alice, p))
|
||||
# The random seed is initialized with 8 bytes of random data from the OS's cryptographically secure random generator
|
||||
random.seed(os.urandom(8))
|
||||
# secret is a random string consisting of 20 alphanumeric characters, used as the secret message
|
||||
secret = ''.join(
|
||||
[random.choice(string.ascii_letters+string.digits) for _ in range(20)])
|
||||
|
||||
self.send(b"[+] Alice said :")
|
||||
self.send(self.encrypt(secret.encode(),key))
|
||||
|
||||
self.send(self.encrypt(secret.encode(), key))
|
||||
|
||||
message = self.recv(b"[+] Now tell me what are they talking about: ")
|
||||
if message != secret.encode():
|
||||
return False
|
||||
@@ -51,8 +63,10 @@ class Task(socketserver.BaseRequestHandler):
|
||||
hacked = self.recv(b"[+] Tell me the cipher:")
|
||||
if self.decrypt(hacked, key) != b"HackedBy0xfa":
|
||||
return False
|
||||
# If all checks pass, return True indicating the exchange was successful and not intercepted
|
||||
return True
|
||||
|
||||
|
||||
def encrypt(self, plain_text:bytes, key:bytes)->bytes:
|
||||
cipher = AES.new(key, AES.MODE_ECB)
|
||||
cipher_text = cipher.encrypt(pad(plain_text, AES.block_size))
|
||||
@@ -82,8 +96,6 @@ class ForkedServer(socketserver.ForkingMixIn, socketserver.TCPServer):
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# flag = bytes(os.getenv("FLAG"),"utf-8")
|
||||
flag = b"flag{coooloooool}"
|
||||
HOST, PORT = '0.0.0.0', 10001
|
||||
server = ForkedServer((HOST, PORT), Task)
|
||||
server.allow_reuse_address = True
|
||||
|
1
crypto/easy_dhke/flag.py
Normal file
1
crypto/easy_dhke/flag.py
Normal file
@@ -0,0 +1 @@
|
||||
flag = b"0xFA{DHKE_is_a_simple_Discrete_logarithm_Problem}"
|
1
crypto/easy_dhke/requirements.txt
Normal file
1
crypto/easy_dhke/requirements.txt
Normal file
@@ -0,0 +1 @@
|
||||
pycryptodome
|
9
crypto/easy_pow/dockerfile
Normal file
9
crypto/easy_pow/dockerfile
Normal file
@@ -0,0 +1,9 @@
|
||||
FROM python:3.11
|
||||
|
||||
COPY easy_pow.py /app/
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
EXPOSE 10001
|
||||
|
||||
CMD [ "python", "easy_pow.py" ]
|
Reference in New Issue
Block a user