diff --git a/__pycache__/paho.cpython-310.pyc b/__pycache__/paho.cpython-310.pyc new file mode 100644 index 0000000..d8c12dd Binary files /dev/null and b/__pycache__/paho.cpython-310.pyc differ diff --git a/fail2banTest.md b/fail2banTest.md new file mode 100644 index 0000000..fbe4213 --- /dev/null +++ b/fail2banTest.md @@ -0,0 +1,24 @@ +fail2ban-client status sshd + +cat /var/log/fail2ban.log + +systemctl status fail2ban + +systemctl status sshd + +python /etc/fail2ban/scripts/mqtt.py 186.237.58.214 + +fail2ban-client set sshd unbanip 186.237.58.214 +fail2ban-client set sshd banip 101.43.32.151 + +sudo dnf install python3-paho-mqtt + + + +to release SELINUX to acess port and others + +audit2allow -w -a +audit2allow -a +audit2allow -a -M fail2ban_t +semodule -i fail2ban_t.pp + diff --git a/mqtt b/mqtt new file mode 100644 index 0000000..af15cd3 --- /dev/null +++ b/mqtt @@ -0,0 +1,34 @@ +#!/usr/bin/env python + +import requests, sys +import paho.mqtt.publish as publish + + +#print(sys.argv[1]) +res = requests.get('http://ipwho.is/'+ sys.argv[1]).json() +# print(res) +print(res['ip']) +print(res['latitude']) +print(res['longitude']) + +msgs = [ {"topic": "name", "payload": res['ip'] }, + {"topic": "lat", "payload": res['latitude'] }, + {"topic": "lon", "payload": res['longitude'] } ] + +print(msgs) +publish.multiple(msgs, hostname="mqtt.33co.de", port=8883, tls={'ca_certs':"/etc/ssl/certs/ca-certificates.crt"}) + +# in case of problem check SELinux +# many t=runs to release ports, access +# audit2allow -w -a +# audit2allow -a +# audit2allow -a -M fail2ban_t +# semodule -i fail2ban_t.pp + +# or just run setsebool 0 + + +# to get the location curl http://ipwho.is/197.26.19.254 +# curl http://ipwho.is/197.26.19.254 | jq -r '.latitude, .longitude' +# guide to create custom action +# https://webcp.io/custom-fail2ban-action/ diff --git a/mqtt-single b/mqtt-single new file mode 100644 index 0000000..987478c --- /dev/null +++ b/mqtt-single @@ -0,0 +1,40 @@ +#!/usr/bin/env python + +import requests, sys, time +import paho.mqtt.client as mqtt + + +# set connection to broker +mqttBroker ="mqtt.33co.de" +client = mqtt.Client (client_id="", clean_session=True) +client.tls_set() +client.connect(mqttBroker, port=8883) + +# get ip location +#print(sys.argv[1]) +res = requests.get('http://ipwho.is/'+ sys.argv[1]).json() +# print(res) +print(res['ip']) +print(res['latitude']) +print(res['longitude']) + +servername = "satelite" + +client.publish("Attacker/"+ servername+"/location", "{\"iconColor\":\"#0434F2\",\"time\":\""+str(time.ctime())+"\",\"lat\":"+str(res['latitude'])+",\"lon\":"+str(res['longitude'])+",\"name\":\""+str(res['ip'])+"\"}") + +client.disconnect() + +# in case of problem check SELinux +# many t=runs to release ports, access +# audit2allow -w -a +# audit2allow -a +# audit2allow -a -M fail2ban_t +# semodule -i fail2ban_t.pp + +# or just run setsebool 0 + + +# to get the location curl http://ipwho.is/197.26.19.254 +# curl http://ipwho.is/197.26.19.254 | jq -r '.latitude, .longitude' +# guide to create custom action +# https://webcp.io/custom-fail2ban-action/ diff --git a/mqttx-cli-linux-x64 b/mqttx-cli-linux-x64 new file mode 100644 index 0000000..40f331e Binary files /dev/null and b/mqttx-cli-linux-x64 differ diff --git a/paho_test.py b/paho_test.py new file mode 100644 index 0000000..22a6b0a --- /dev/null +++ b/paho_test.py @@ -0,0 +1,16 @@ +import paho.mqtt.client as mqtt +import paho.mqtt.publish as publish +import time, random +import psutil + +# mqttBroker ="mqtt.33co.de" +#client = mqtt.Client (client_id="", clean_session=True) +#client.tls_set() +#client.connect(mqttBroker, port=8883) +i = 1 +while i < 10: + msgs = [{"topic": "cpu_percent", "payload": psutil.cpu_percent() }, {"topic": "memory", "payload": psutil.virtual_memory().percent }] + print(msgs) + publish.multiple(msgs, hostname="mqtt.33co.de", port=8883, tls={'ca_certs':"/etc/ssl/certs/ca-certificates.crt"}) + time.sleep(3) +client.disconnect()