Archive

Articles taggués ‘scripting’

Emergency DOS or DDOS stopping script

27/09/2023 Comments off

If you are under a DOS or DDOS attack and running out of your mind or don’t know what to do, use this script to get ride of this panic situation.

DoS or DDoS is an attempt to make a victim website unavailable by creating hundreds to hundreds thousands of established connections that overflow victim resources and makes a website unavailable to the genuine users/visitors.

Short and useful slide that definite this script can be view on slideshare

You can run script to mitigate a low level ddos attack some how while and can stop DOS attack completely. This script is available under GPL license from the author.

How to mitigate DoS or DDoS attack?

Stop or flush other rules for now :

service apf stop
iptables -F
wget http://www.hackersgarage.com/wp-content/uploads/2011/08/antiDDoS.txt
mv antiDDoS.txt antiDDoS.sh
chmod u+x antiDDoS.sh
./antiDDoS.sh

Some other useful commands to analyze the type of attacks :

netstat -antp | grep ESTABLISHED
netstat -antp | grep -i sync
netstat --help

Source: hackersgarage.com

Using Bash Arrays with Examples

12/08/2021 Comments off

bash-scripting-32-638Arrays can be a useful tool when coding your bash scripts.  The simplest way that I can define an array is to state that an array is a variable for a multi-instance dataset.

For example, a variable is used when there is a single value from a dataset like the IP Address of a server.  However, an array can be used to store all of the IP Addresses in your server room.

Speaking of IP Addresses and bash arrays, my last article (Detect and Block WordPress Brute Force Login Attacks) includes a script which is an example of how an array can be used in bash scripting.

Because arrays can be so useful in bash scripting, I thought that I would put together the following article detailing ways of Using Bash Arrays with Examples.

Initializing Bash Arrays or Assigning Values to Arrays

For arrays to be useful, we need to be able to assign values to them.  We assign values to an array by listing the array along with its instance number as shown below.  This method will assign each instance of the array one by one.

#!/bin/bash
myarray[0]=Hello
myarray[1]=World,
myarray[3]=Happy
myarray[4]=Friday

# Display all instances of the array
echo ${myarray[*]}

We can see above that in addition to being able to assign the values one by one, we can reference all array instances with an asterisk (*).  Another way to display all instances of the array is to use the following “echo ${myarray[@]}”

We run the script and get:

$ ./arrays.sh
Hello World, Happy Friday

We can also retrieve individual instances of an array by specifying the individual array instance number.  We modify the above script slightly to retrieve a couple of the instances.

#!/bin/bash
myarray[0]=Hello
myarray[1]=World,
myarray[3]=Happy
myarray[4]=Friday

# Display all instances of the array
echo ${myarray[0]} ${myarray[4]}

We run the script again and we get:

$ ./arrays.sh
Hello Friday

Lire la suite…

Categories: Système, Tutoriel Tags: , , ,

Un petit script de sauvegarde en shell pour vos machines Linux

23/05/2021 Comments off

On ne le répétera jamais assez : faites des sauvegardes ! Et non, ça n’est pas compliqué, oui il existe des dizaines et des dizaines de solutions possibles, donc vous n’avez pas d’excuse pour ne pas le faire.

disque-dur

Si vous utilisez WordPress, vous avez peut-être déjà installé l’extension BackWPUp qui fonctionne à merveille. Si ça n’est pas le cas, ou si vous souhaitez sauvegarder d’autres projets en même temps, je vous propose ce petit script de sauvegarde en shell (pour Ubuntu par exemple) qui vous permettra de :

  • sauvegarder tous les fichiers d’un répertoire ;
  • mettre à jour votre répertoire à partir d’un serveur distant ;
  • créer un dump de vos bases de données, une par une ;
  • mettre à jour vos bases de de données à partir d’un serveur distant ;
  • créer une archive gzippée de votre sauvegarde.

Et tout ça en moins de 50 lignes, commentaires compris.

Ainsi vous n’aurez qu’à planifier un lancement de ce script à la fréquence qui vous convient pour ne pas avoir à vous soucier de vos backups. Lire la suite…

Categories: Système, Tutoriel Tags: , , ,

Howto: Geolocation for Fail2ban

14/03/2021 Comments off

source: fail2ban.org

 

Using geolocation to locate your attackers.

I use fail2ban on my servers to protect them from would-be attackers, if you don’t your either insanely nieve to the fact that somebody wants in your system, or your just wanting to see if you can get hacked. Most of the attackers I would assume are just after another « bot » in their « net », or maybe a place to host files.

Durzo hosts a script that allows you to log the attacks on you into a mysql database with geocoding, I thought this would be cool to use as I could see from where I was being attacked. I then got this working and another script to display the table in a web page so I could view the data easily.

I then found some scripts from Google to pull data from MySQL in a geolocation table and generate an XML file used to import into Google Maps. With some tweaking and customizing, I now have a map with the geolocation data as markers on the map. Not all the markers are right on a building, but they are close enough for me to see the areas from which attacks are coming.

Now on to the good stuff… Lire la suite…