2024-05-25 10:37:17 +02:00
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import base64
|
|
|
|
import os.path as path
|
|
|
|
|
|
|
|
|
|
|
|
class Module:
|
|
|
|
def __init__(self, incoming=False, verbose=False, options=None):
|
|
|
|
# extract the file name from __file__. __file__ is proxymodules/name.py
|
|
|
|
self.name = path.splitext(path.basename(__file__))[0]
|
|
|
|
self.description = 'Simply print the received data as text'
|
|
|
|
self.incoming = incoming # incoming means module is on -im chain
|
|
|
|
self.find = None # if find is not None, this text will be highlighted
|
|
|
|
|
2024-05-27 12:54:09 +02:00
|
|
|
# protocol 1: flag{m4n_1n_th3_m1ddl3_w0w}
|
2024-05-25 10:37:17 +02:00
|
|
|
def execute(self, data):
|
|
|
|
print(f"Incoming data: {data}")
|
|
|
|
data_json = json.loads(data)
|
|
|
|
|
2024-05-27 12:54:09 +02:00
|
|
|
# return handshake messages without modification
|
2024-05-25 10:37:17 +02:00
|
|
|
if data_json.get("type") == "HANDSHAKE":
|
|
|
|
return data
|
|
|
|
|
2024-05-27 12:54:09 +02:00
|
|
|
# replace "Bob" with "Eve" in the first protocol message
|
2024-05-25 10:37:17 +02:00
|
|
|
elif data_json.get("id") == 1:
|
|
|
|
data_json["content"] = data_json["content"].replace("Bob","Eve")
|
|
|
|
|
2024-05-27 12:54:09 +02:00
|
|
|
# if message 3 received, build valid message 4
|
|
|
|
# instead of {Hello Alice!}_K use arbitary data
|
2024-05-25 10:37:17 +02:00
|
|
|
elif data_json.get("id") == 3:
|
|
|
|
data_json["id"] = 4
|
|
|
|
data_json["sender"] = "Bob"
|
|
|
|
data_json["receiver"] = "Alice"
|
|
|
|
data_json["content"] = str(base64.b64encode(os.urandom(16)))
|
|
|
|
|
2024-05-27 12:54:09 +02:00
|
|
|
# dump message
|
2024-05-25 10:37:17 +02:00
|
|
|
data = json.dumps(data_json) + "\n"
|
|
|
|
print(f"Outgoing data: {data}")
|
2024-05-27 12:54:09 +02:00
|
|
|
|
|
|
|
# return crafted message to proxy
|
2024-05-25 10:37:17 +02:00
|
|
|
return data
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print('This module is not supposed to be executed alone!')
|