Counting IP’s on system logs with Python

This is an example script on how to count IP’s on any log.

from collections import defaultdict
import re
import sys

d= defaultdict(int)

    with open(sys.argv[1], 'r') as f:
        for row in f:
            ip=re.findall("((?:[0-9]{1,3}\.){3}[0-9]{1,3})", row)
            for i in ip:
                d[i] += 1
except IOError as error:

for key, value in sorted(d.items(), key=lambda x: x[1], reverse=True):
    print('IP: %s COUNT: %s' % (key,value))

This should be run like : python /path/to/log and the output will be like:

IP: – COUNT: 63
IP: – COUNT: 54
IP: – COUNT: 45

Posted in Misc | Tagged , , , , , , , , , | Leave a comment

Apache cookie authentication

There’s a module that let’s you authenticate via any auth method (basic auth, ldap, etc…) to specific locations, you can also set an expiration time on the cookie, so when the time expire the user will be redirected to the login page.

In this post we’ll install it on a Centos 7 server.

Continue reading

Posted in Apache, Linux, Misc, PHP, Security | Leave a comment

Installing ModSecurity with Nginx and OWASP CRS on Debian Stretch

First we have to install all dependencies including ModSecurity and Nginx.

It’s recommended to install Nginx from the stable branch of the official repositories, this way you can update nginx without compiling it everytime however we’ll need to compile the module for ModSecurity.

Continue reading

Posted in Debian, Linux, ModSecurity, Nginx, Proxy, Security, Unix | Tagged , , , , , , | Leave a comment

Docker save, load, import, export, commit.

When I came across with the command docker export/import I was really confused as of what is it for. I usually just save my images with docker save.

The documentation just says

docker-export - Export a container's filesystem as a tar archive

and nothing more.

So after running some tests this is what I found:
Continue reading

Posted in Containers, Docker, Unix, Virtualization | 2 Comments

Percona XtraDB Cluster in Docker Swarm.

I have the next scenario where I needed to setup a MySQL Percona XtraDB Cluster on containers on 3 different servers.

Continue reading

Posted in Cluster, Containers, Databases, Docker, HA, Linux, Misc, MySQL, Percona, Percona XtraDB | Leave a comment

Incorrect definition of table mysql.proc

I recently upgraded my server from Debian 8 to Debian 9, I also upgraded MySQL5.5 (Percona)  to MariaDB 10, everything seemed fine until I noticed the database was down, and i just couldn’t bring it up, it just kept dying, after some research into the logs I found the next error:

Continue reading

Posted in Databases, Debian, Linux, MySQL, Systemd, Unix | 4 Comments

Proxmox 3, starting worker failed: Unable to parse worker upid error

This is a bug in Proxmox 3, when you have a high uptime, usually more than 365 days, and you want to initiate an instance (VM), you get the error:

Continue reading

Posted in Misc | Leave a comment

Installing HaProxy in Debian 8

there’s a package in debian 8 repository however it’s not the newest version (1.5), so in order to have the most recent release (1.6.5) we are going to compile it from source.

You can download it from the official page

Continue reading

Posted in Debian, HaProxy, Linux, Load balancing, Systemd, Unix | Leave a comment

Extract key from tomcat keystore

If you have several flavours of web servers (tomcat, apache, nginx), and want to add SSL Certificates to them you might have noticed that you need different kind of certificates for your web servers, you can however, add SSL Certificates to all of your web servers with just one.

We’ll extract the key from the tomcat keystore so you can use the same certs on apache or nginx.
Continue reading

Posted in Apache, Nginx, SSL, tomcat | Leave a comment

Generate SSL Certificate for Tomcat 6.X, 7.X, 8.X

There are two ways of configuring tomcat, depending on the connector you are using, in this case we’ll configure tomcat with the default connector which needs a keystore for the certs.

You’ll need to have Java installed.

The steps to generate a CSR for tomcat are as follow:
Continue reading

Posted in SSL, tomcat | Leave a comment