mirror of
https://github.com/telekom-security/tpotce.git
synced 2025-07-02 01:27:27 -04:00
tweaking
healthcheck, watch pid not cpu cleanup dockerfiles bump dicompot, heralding, elasticpot, endlessh to alpine 3.19 bump dionaea, heralding to latest master
This commit is contained in:
@ -5,11 +5,11 @@ COPY dist/ /root/dist/
|
||||
#
|
||||
# Install packages
|
||||
RUN apk --no-cache -U add \
|
||||
git \
|
||||
procps \
|
||||
py3-psutil \
|
||||
py3-requests \
|
||||
python3 && \
|
||||
git \
|
||||
procps \
|
||||
py3-psutil \
|
||||
py3-requests \
|
||||
python3 && \
|
||||
#
|
||||
# Install adbhoney from git
|
||||
git clone https://github.com/huuck/ADBHoney /opt/adbhoney && \
|
||||
@ -17,7 +17,7 @@ RUN apk --no-cache -U add \
|
||||
# git checkout 2417a7a982f4fd527b3a048048df9a23178767ad && \
|
||||
git checkout 42afd98611724ca3d694a48b694c957e8d953db4 && \
|
||||
cp /root/dist/adbhoney.cfg /opt/adbhoney && \
|
||||
cp /root/dist/cpu_check.py /opt/adbhoney && \
|
||||
cp /root/dist/cpu_check.py / && \
|
||||
sed -i 's/dst_ip/dest_ip/' /opt/adbhoney/adbhoney/core.py && \
|
||||
sed -i 's/dst_port/dest_port/' /opt/adbhoney/adbhoney/core.py && \
|
||||
#
|
||||
@ -32,8 +32,8 @@ RUN apk --no-cache -U add \
|
||||
#
|
||||
# Set workdir and start adbhoney
|
||||
STOPSIGNAL SIGINT
|
||||
# Adbhoney sometimes hangs at 100% CPU usage, if detected process will be killed and container restarts per docker-compose settings
|
||||
HEALTHCHECK --interval=5m --timeout=30s --retries=3 CMD python3 /opt/adbhoney/cpu_check.py
|
||||
# Adbhoney sometimes hangs at 100% CPU usage, if detected container will become unhealthy and restarted by tpotinit
|
||||
HEALTHCHECK --interval=5m --timeout=30s --retries=3 CMD python3 /cpu_check.py $(pgrep -of run.py) 99
|
||||
USER adbhoney:adbhoney
|
||||
WORKDIR /opt/adbhoney/
|
||||
CMD /usr/bin/python3 run.py
|
||||
|
46
docker/adbhoney/dist/cpu_check.py
vendored
46
docker/adbhoney/dist/cpu_check.py
vendored
@ -1,10 +1,42 @@
|
||||
import psutil
|
||||
import sys
|
||||
import time
|
||||
|
||||
# Get the overall CPU usage percentage
|
||||
cpu_usage = psutil.cpu_percent(interval=1)
|
||||
print(cpu_usage)
|
||||
# Check CPU usage threshold
|
||||
if cpu_usage >= 75: # Adjust the threshold as needed
|
||||
exit(1)
|
||||
if len(sys.argv) != 3:
|
||||
print("Usage: script.py <PID> <CPU_USAGE_THRESHOLD>")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
pid = int(sys.argv[1])
|
||||
except ValueError:
|
||||
print("Please provide a valid integer value for the PID.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
cpu_threshold = float(sys.argv[2])
|
||||
except ValueError:
|
||||
print("Please provide a valid number for the CPU usage threshold.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
target_process = psutil.Process(pid)
|
||||
except psutil.NoSuchProcess:
|
||||
print(f"No process with the PID {pid} was found.")
|
||||
sys.exit(1)
|
||||
|
||||
# Prepare to calculate the average CPU usage over 3 intervals of 1 second each
|
||||
cpu_usages = []
|
||||
for _ in range(3):
|
||||
cpu_usages.append(target_process.cpu_percent(interval=1))
|
||||
|
||||
# Calculate the average CPU usage
|
||||
average_cpu_usage = sum(cpu_usages) / len(cpu_usages)
|
||||
print(f"Average CPU Usage of PID {pid} over 3 seconds: {average_cpu_usage}%")
|
||||
|
||||
# Check average CPU usage against the threshold
|
||||
if average_cpu_usage >= cpu_threshold:
|
||||
print(f"Average CPU usage of PID {pid} is above or equal to the threshold of {cpu_threshold}%.")
|
||||
sys.exit(1)
|
||||
else:
|
||||
exit(0)
|
||||
print(f"Average CPU usage of PID {pid} is below the threshold of {cpu_threshold}%. Exiting with code 0.")
|
||||
sys.exit(0)
|
||||
|
Reference in New Issue
Block a user