Skip to content

Commit

Permalink
fix verbose condition
Browse files Browse the repository at this point in the history
  • Loading branch information
Ali Razmjoo committed Jul 28, 2021
1 parent 61889c6 commit 7f7d553
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 72 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ pcapfiles/*
results.*
*.DS_Store
*.swp
venv/*

# codacy
.coverage
Expand Down
26 changes: 14 additions & 12 deletions core/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from core import color
from core.log import get_logger
from core.time_helper import now
from core.compatible import is_verbose_mode

logger = get_logger("ohp_core")

Expand Down Expand Up @@ -102,19 +103,20 @@ def verbose_info(content):
Returns:
None
"""
logger.info(content)
sys.stdout.buffer.write(
bytes(
color.color_cmd("cyan")
+ "[v] [{0}] ".format(now())
+ color.color_cmd("grey")
+ content
+ color.color_cmd("reset")
+ "\n",
"utf8"
if is_verbose_mode():
logger.info(content)
sys.stdout.buffer.write(
bytes(
color.color_cmd("cyan")
+ "[v] [{0}] ".format(now())
+ color.color_cmd("grey")
+ content
+ color.color_cmd("reset")
+ "\n",
"utf8"
)
)
)
sys.stdout.flush()
sys.stdout.flush()
return


Expand Down
112 changes: 52 additions & 60 deletions database/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

from config import api_configuration, network_configuration
from core.alert import verbose_info
from core.compatible import byte_to_str, is_verbose_mode
from core.compatible import byte_to_str
from database.datatypes import (CredentialEvent,
HoneypotEvent,
EventData,
Expand Down Expand Up @@ -75,18 +75,17 @@ def insert_to_honeypot_events_queue(honeypot_event: HoneypotEvent, honeypot_even
Returns:
None
"""
if is_verbose_mode():
verbose_info(
"Received honeypot event, ip_dest:{0}, port_dest:{1}, "
"ip_src:{2}, port_src:{3}, module_name:{4}, machine_name:{5}".format(
honeypot_event.ip_dest,
honeypot_event.port_dest,
honeypot_event.ip_src,
honeypot_event.port_src,
honeypot_event.module_name,
honeypot_event.machine_name
)
verbose_info(
"Received honeypot event, ip_dest:{0}, port_dest:{1}, "
"ip_src:{2}, port_src:{3}, module_name:{4}, machine_name:{5}".format(
honeypot_event.ip_dest,
honeypot_event.port_dest,
honeypot_event.ip_src,
honeypot_event.port_src,
honeypot_event.module_name,
honeypot_event.machine_name
)
)

# Get country of the source IP Address
honeypot_event.country_ip_src = byte_to_str(
Expand Down Expand Up @@ -117,17 +116,16 @@ def insert_to_network_events_queue(network_event: NetworkEvent, network_events_q
Returns:
None
"""
if is_verbose_mode():
verbose_info(
"Received network event, ip_dest:{0}, port_dest:{1}, "
"ip_src:{2}, port_src:{3}, machine_name:{4}".format(
network_event.ip_dest,
network_event.port_dest,
network_event.ip_src,
network_event.port_src,
network_event.machine_name
)
verbose_info(
"Received network event, ip_dest:{0}, port_dest:{1}, "
"ip_src:{2}, port_src:{3}, machine_name:{4}".format(
network_event.ip_dest,
network_event.port_dest,
network_event.ip_src,
network_event.port_src,
network_event.machine_name
)
)

# Get country of the source IP Address
network_event.country_ip_src = byte_to_str(
Expand Down Expand Up @@ -162,10 +160,8 @@ def push_events_queues_to_database(honeypot_events_queue, network_events_queue):
"""

if is_verbose_mode() and (honeypot_events_queue or network_events_queue) \
and (honeypot_events_queue or network_events_queue):
if honeypot_events_queue or network_events_queue:
verbose_info("Submitting new events to database")

# Insert all honeypot events to database (honeypot_events collection)
while not honeypot_events_queue.empty():
new_event = honeypot_events_queue.get()
Expand Down Expand Up @@ -218,17 +214,16 @@ def insert_to_credential_events_collection(credential_event: CredentialEvent):

credential_event.machine_name = network_config["real_machine_identifier_name"]

if is_verbose_mode():
verbose_info(
"Received honeypot credential event, ip_dest:{0}, username:{1}, "
"password:{2}, module_name:{3}, machine_name:{4}".format(
credential_event.ip_src,
credential_event.username,
credential_event.password,
credential_event.module_name,
credential_event.machine_name
)
verbose_info(
"Received honeypot credential event, ip_dest:{0}, username:{1}, "
"password:{2}, module_name:{3}, machine_name:{4}".format(
credential_event.ip_src,
credential_event.username,
credential_event.password,
credential_event.module_name,
credential_event.machine_name
)
)
return elasticsearch_events.index(index='credential_events', body=credential_event.__dict__)


Expand All @@ -250,16 +245,15 @@ def insert_to_file_change_events_collection(file_change_event_data: FileEventsDa
'rb'
).read()).decode() if not file_change_event_data.is_directory and file_change_event_data.status != "deleted" else ""

if is_verbose_mode():
verbose_info(
"Received honeypot file change event, file_path:{0}, status:{1}, "
"module_name:{2}, module_name:{3}, machine_name:{3}".format(
file_change_event_data.file_path,
file_change_event_data.status,
file_change_event_data.module_name,
file_change_event_data.machine_name,
)
verbose_info(
"Received honeypot file change event, file_path:{0}, status:{1}, "
"module_name:{2}, module_name:{3}, machine_name:{3}".format(
file_change_event_data.file_path,
file_change_event_data.status,
file_change_event_data.module_name,
file_change_event_data.machine_name,
)
)
return elasticsearch_events.index(index='file_change_events', body=file_change_event_data.__dict__)


Expand All @@ -282,16 +276,15 @@ def insert_to_events_data_collection(event_data: EventData):
)
)

if is_verbose_mode():
verbose_info(
"Received honeypot data event, ip_dest:{0}, module_name:{1}, "
"machine_name:{2}, data:{3}".format(
event_data.ip_src,
event_data.module_name,
event_data.machine_name,
event_data.data
)
verbose_info(
"Received honeypot data event, ip_dest:{0}, module_name:{1}, "
"machine_name:{2}, data:{3}".format(
event_data.ip_src,
event_data.module_name,
event_data.machine_name,
event_data.data
)
)

return elasticsearch_events.index(index='data_events', body=event_data.__dict__)

Expand All @@ -307,14 +300,13 @@ def insert_pcap_files_to_collection(file_archive: FileArchive):
Returns:
file_id
"""
if is_verbose_mode():
verbose_info(
"Received network traffic file:{0}, date:{1}. "
"Inserting it in the File Archive".format(
file_archive.file_path,
file_archive.date
)
verbose_info(
"Received network traffic file:{0}, date:{1}. "
"Inserting it in the File Archive".format(
file_archive.file_path,
file_archive.date
)
)
file_content = binascii.b2a_base64(open(file_archive.file_path, "rb").read()).decode()
file_md5 = hashlib.md5(file_content.encode()).hexdigest()
return elasticsearch_events.index(
Expand Down

0 comments on commit 7f7d553

Please sign in to comment.