complete course

This commit is contained in:
2022-11-06 02:28:14 +02:00
parent e05560f5d3
commit 4bbd21a665
6 changed files with 114 additions and 0 deletions

Binary file not shown.

24
fail2banTest.md Normal file
View File

@@ -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

34
mqtt Normal file
View File

@@ -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/

40
mqtt-single Normal file
View File

@@ -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/

BIN
mqttx-cli-linux-x64 Normal file

Binary file not shown.

16
paho_test.py Normal file
View File

@@ -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()