Skip to content

Commit

Permalink
make attacker remoter default offline
Browse files Browse the repository at this point in the history
  • Loading branch information
alirezade authored and alirezade committed Jan 8, 2024
1 parent 30dfab4 commit e6f4aee
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ deployments/push-attacker-docker.sh
deployments/push-ics-docker.sh
.idea
.idea/
src/connection.txt
src/logs/*
!src/logs/attack-logs/
src/logs/attack-logs/*
Expand Down
39 changes: 21 additions & 18 deletions src/AttackerRemote.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,13 @@ class AttackerRemote(AttackerBase):

def __init__(self, remote_connection_file):
AttackerBase.__init__(self, 'attacker_remote')
self.remote_connection_file = ""
self.remote_connection_file = remote_connection_file
self.enabled = False
self.applying_attack = False
self.attacksQueue = queue.Queue()
self.client = mqtt.Client()
self.mqtt_thread = False



def setup_mqtt_client(self):
connection_params = read_mqtt_params(self.remote_connection_file)
connection_params['topic'] = connection_params['topic'] + '/#'
Expand Down Expand Up @@ -53,6 +51,7 @@ def on_message(self, client, userdata, msg):
self.attacksQueue.put(msg)

def try_enable(self):

sample = self._make_text("""
type: MQTT
address: <server_address>.com
Expand All @@ -61,27 +60,34 @@ def try_enable(self):
username: <optional username>
password: <optional password>""", Runnable.COLOR_GREEN)

message = """
Do you want to enable attacker_remote? if yes, you have to provide adress of connection file.
Connection file contains text file containing required info for making MQTT connection.
message = f"""
Please make sure you have right configuration in \"{self._make_text(self.remote_connection_file, Runnable.COLOR_GREEN)}\" file, before enabling attacker_remote!.
Connection file must contains text file including of required info for making MQTT connection.
Sample of connection file:
""" + sample + f"""
Please insert a path to connection file. (current directory: {os.getcwd()})
Connection file: """
Do you want to enable attacker_remote (y/n)?: """

response = input(message)
if not os.path.exists(response):
self.report(f'Provided path ({response}) not exists.')
if not (response.lower() == "y" or response.lower() == "yes"):
return

connection_params = read_mqtt_params(response)
if not all(key in connection_params for key in ["type", "address", "port", "topic" ]):
self.report(f'Connection file ({response}) is in wrong format.')
connection_params = read_mqtt_params(self.remote_connection_file)
if not all(key in connection_params for key in ["type", "address", "port", "topic"]):
self.report(f'Connection file ({self.remote_connection_file}) is in wrong format. Not found correct keys!',
logging.ERROR)
return

for value in connection_params.values():
if str(value).startswith("<") or str(value).endswith(">"):
self.report(
f'Connection file ({self.remote_connection_file}) is in wrong format. Not found correct values!',
logging.ERROR)
return

print("connection file compiled!\n")

self.remote_connection_file = response
self.mqtt_thread = threading.Thread(target=self.setup_mqtt_client)
self.mqtt_thread.start()
self.enabled = True
Expand All @@ -96,7 +102,6 @@ def _logic(self):
else:
time.sleep(2)


def process_messages(self, msg):
try:
msg = json.loads(msg.payload.decode("utf-8"))
Expand Down Expand Up @@ -162,8 +167,6 @@ def find_device_address(device_name):
raise Exception(f'target:({device_name}) is not recognized!')




if __name__ == '__main__':
attackerRemote = AttackerRemote("input/sample_mqtt_connection.txt")
attackerRemote = AttackerRemote("AttackerRemoteConnection.txt")
attackerRemote.start()
8 changes: 8 additions & 0 deletions src/AttackerRemoteConnection.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
type: MQTT
address: <sample mqqt broker like: broker.mqttdashboard.com>
port: <1883>
topic: <the sample topic for mqtt messages like testtopic/141>

# it will skipp lines with # signs
# username: <sample username>
# password <sample password>

0 comments on commit e6f4aee

Please sign in to comment.