Mostrando entradas con la etiqueta C. Mostrar todas las entradas
Mostrando entradas con la etiqueta C. Mostrar todas las entradas

sábado, 25 de noviembre de 2023

What is the tech stack for the shortern future?

Predicting the exact technology stack for the future can be challenging because technology evolves rapidly, and new innovations constantly emerge. However, there are some trends and technologies that have been gaining traction and are likely to play a significant role in the tech stacks of the future. Keep in mind that the specific stack you choose will depend on your project's requirements and goals. Here are some key trends and technologies to consider:


  • Cloud Computing: Cloud platforms like Amazon Web Services (AWS), Microsoft Azure, and Google Cloud are expected to continue dominating the cloud computing landscape. Serverless computing and containerization (using technologies like Docker and Kubernetes) will likely become even more important for scalability and efficiency.

  • Edge Computing: As IoT devices become more prevalent, edge computing will grow in importance. This involves processing data closer to the source (i.e., the "edge" of the network) to reduce latency and improve real-time decision-making.

  • Artificial Intelligence (AI) and Machine Learning (ML): AI and ML will continue to be integrated into various applications and services. Frameworks like TensorFlow and PyTorch will remain important, and AI/ML models will be increasingly deployed at the edge for faster processing.

  • Blockchain: While blockchain technology is primarily associated with cryptocurrencies like Bitcoin, it has applications beyond finance, such as supply chain management, voting systems, and more. Blockchain platforms like Ethereum and Hyperledger are likely to see continued development and adoption.

  • Quantum Computing: Quantum computing is still in its infancy, but it holds great promise for solving complex problems that are currently beyond the capabilities of classical computers. Companies like IBM and Google are actively working on quantum computing research.

  • 5G Technology: The rollout of 5G networks will enable faster and more reliable wireless connectivity. This will impact various industries, including IoT, autonomous vehicles, augmented reality, and virtual reality.

  • Cybersecurity: With the increasing importance of digital data and connectivity, cybersecurity will remain a top concern. Technologies like AI-driven threat detection, zero-trust security models, and encryption will continue to evolve.

  • Web Technologies: JavaScript, HTML, and CSS will remain fundamental for web development, but frameworks like React, Angular, and Vue.js are likely to continue their popularity. Progressive Web Apps (PWAs) and WebAssembly are also promising technologies.

  • DevOps and Automation: DevOps practices, along with tools like Jenkins, Docker, and Ansible, will continue to streamline development, deployment, and operations processes. Automation will be critical for efficiency and reliability.

  • Sustainability: Sustainability considerations will play a larger role in tech stacks. Energy-efficient hardware, green data centers, and eco-friendly software development practices will become more important.

  • AR/VR: Augmented reality (AR) and virtual reality (VR) technologies will continue to advance, with applications in gaming, education, healthcare, and more.

  • Natural Language Processing (NLP): NLP technologies like GPT-4 and beyond will enable more sophisticated conversational AI, language translation, and content generation.

  • Container Orchestration: Technologies like Kubernetes and Docker Swarm will remain crucial for managing and scaling containerized applications.



It's essential to stay up-to-date with emerging technologies and adapt your tech stack based on your project's specific needs and the evolving industry trends. Flexibility and a willingness to learn and experiment will be valuable skills for technology professionals in the future. 

martes, 14 de julio de 2020

Installing, hardening, mod-security and fail2ban for Apache server

The following post is related to computer security, one of my passions as a hobby and what has fed me for several years being my profession a few years ago. The aim of the article is none other than to install and secure a web server, I have chosen Apache.

  1. Installing

If you need something help in order to compiling and installing you apache web server, please find more information in the official documentation.

    2. Hardening


Relatively recently, I found this public project called "Apache Hardening" and was completely delighted. It's not even worth transcribing, the best thing you can do is go to the original link and marvel at it by following the instructions.

    3. Mod-Security

Another important topic related you webserver Apache, is apply the mod-security. Mod-Security is one of the most popular security module for Apache and due MS more than the 85% of the automatics vulnerabilities and exploits are stopped.


On Intenet, normally you can find a lot of valid websites where explain how you need to install the tool but in my opinion one of the best is this.

    4. Fail2ban

Ok, we are very close to conclude this mini tutorial, imagine that all the above fails, what we have left, well, many things, we should be sure that we have secured our operating system, that we do not have unnecessary services published on the Internet and a long etcetera, but ... what if we apply firewall rules dynamically before events recorded in the log? Welcome to Fail2ban.

Let’s assume that you already installed fail2ban, you can check here how to do that: – https://www.ionos.com/community/server-cloud-infrastructure/linux-server/use-fail2ban-on-a-cloud-server-with-linux/

We need to copy this to a file called jail.local for Fail2Ban to find it.

cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Configure defaults in jail.local
Open up the new Fail2Ban configuration file:
You can see the default section below:
[DEFAULT]

# "ignoreip" can be an IP address, a CIDR mask or a DNS host. Fail2ban will not
# ban a host which matches an address in this list. Several addresses can be
# defined using space separator.
ignoreip = 127.0.0.1

# Override /etc/fail2ban/jail.d/00-firewalld.conf:
banaction = iptables-multiport

# "bantime" is the number of seconds that a host is banned.
bantime  = 600

# A host is banned if it has generated "maxretry" during the last "findtime"
# seconds.
findtime  = 600

# "maxretry" is the number of failures before a host get banned.
maxretry = 5

Configure Fail2ban For ssh

Although you can add this parameters in the global jail.local file, it is a good practice to create seperate jail files for each of the services we want to protect with Fail2Ban.
So lets create a new jail for SSH with the vi editor.
vi /etc/fail2ban/jail.d/sshd.local
In the above file, add the following lines of code:
[sshd]
enabled = true
port = ssh
action = iptables-multiport
logpath = /var/log/secure
maxretry = 5
bantime = 600
Restart Fail2Ban
After making any changes to the Fail2Ban config, always be sure to restart Fail2Ban.
systemctl restart fail2ban
You can see the rules that fail2ban puts in effect within the IP table:
iptables -L -n
Check Fail2Ban Status
Use fail2ban-client command to query the overall status of the Fail2Ban jails.
fail2ban-client status
You can also query a specific jail status using the following command:
fail2ban-client status sshd

Configure Fail2ban For Apache

Edit this file:
sudo nano /etc/fail2ban/jail.local
Add the following content. Note: Substitute your own static IP address for the sample address (127.0.0.1) in this example:
# detect password authentication failures
[apache]
enabled  = true
filter   = apache-auth
action   = iptables-multiport[name=auth, port="http,https"]
logpath  = /var/log/httpd/fail2ban_log
bantime  = 3600
maxretry = 3
ignoreip = 127.0.0.1

# detect spammer robots crawling email addresses
[apache-badbots]
enabled  = true
filter   = apache-badbots
action   = iptables-multiport[name=badbots, port="http,https"]
logpath  = /var/log/httpd/fail2ban_log
bantime  = 3600
maxretry = 1
ignoreip = 127.0.0.1

# detect potential search for exploits
[apache-noscript]
enabled  = true
filter   = apache-noscript
action   = iptables-multiport[name=noscript, port="http,https"]
logpath  = /var/log/httpd/fail2ban_log
bantime  = 3600
maxretry = 6
ignoreip = 127.0.0.1

# detect Apache overflow attempts
[apache-overflows]
enabled  = true
filter   = apache-overflows
action   = iptables-multiport[name=overflows, port="http,https"]
logpath  = /var/log/httpd/fail2ban_log
bantime  = 3600
maxretry = 2
ignoreip = 127.0.0.1
Save and close the file, then restart Fail2ban for the changes to take effect:
sudo systemctl restart fail2ban
Now, configure the Fail2ban service to start on boot with the command:
sudo systemctl enable fail2ban
To verify the rules that were added to iptables by Fail2ban, use the following command:
sudo iptables -L



miércoles, 15 de abril de 2020

Graphviz. Simple solution for recreating graphics

This is the first article that I publish in English, the main reason to do it is because all the documentation related to context maps that I have found so far, are related in English and obviously my way to contribute to the extensive Internet community, is to do it in a universal language, at least for this article.

Well, today I want to talk about two utilities that have helped me a lot, one of them is graphviz.org. Graphviz, which has versions for Windows, Mac or Linux (in my case I have tried in Linux and Mac OS), is a powerful Open Source tool that allows to easily generate almost any graphic, cool stuff like this:



Or simpler things than recreating a binary tree that I explained in the previous section, https://www.larebelion.com/2020/04/arboles-binarios.html

Imagine that in code C, you want to represent the resulting binary tree, with few lines of code you could get something like this:


Let me a simple C function to add to the previous tree and generate this:

static void _generating_graphviz_details(const tree_t node, const void *extra)
{
 FILE *f = (FILE *) extra;

 fprintf(f, " node_%p [label=\"{%p | content: %d | { <izqda> %p | <dcha> %p}\"];\n",
  node, node, node->content, node->left, node->right
 );
 if (node->left != NULL) {
  fprintf(f, " node_%p:left -> node_%p;\n", node, node->left);
 }
 if (node->right != NULL) {
  fprintf(f, " node_%p:dcha -> node_%p;\n", node, node->dcha);
 }
 fprintf(f, "f");
}

Okay, hopefully this tiny contribution will help you in the dynamic generation of your graphics.

domingo, 12 de abril de 2020

Árboles binarios

Ejercicio sencillo para representar un Arbol Binario, funciones básicas:

  • Crear nuevo árbol
  • Insertar hojas
  • Destruir Árbol
  • Imprimir en (Preorden, Postorden e Inorden)
  • Localizar nodos menores a un número, mostrarlos y contarlos.





#include <stdio.h>
#include <stdlib.h>

typedef struct nodo
{
    struct nodo *hizqdo;
    struct nodo *hdrcho;
    int contenido;
} nodo;

typedef struct nodo *arbol;

arbol nuevo_arbol (int contenido);
void destruir_arbol (arbol a);
void insertar_arbol (arbol nuevo, arbol *a);
void encontrar_menores (arbol a, int comparador, int *contador);
void imprimir (arbol a, int modo);

int main (void)
{
    int contenidos[] = {1, 20, 43, 12, 45, 21, 75, 26, 16, 74, 74, 36, 24, 2, 29, 97, -1};
    int *c = contenidos;
    arbol a = NULL;
    int contador = 0;
    while (*c >= 0) {
        arbol nuevo = nuevo_arbol(*c);
        insertar_arbol (nuevo, &a);
        c++;
    }

    printf ("\nPreorden:\n");
    imprimir(a, 1);
    printf ("\nPostorden:\n");
    imprimir(a, 2);
    printf ("\nInorden:\n");
    imprimir(a, 3);

    printf ("\nEncontrar menores de 50:\n");
    encontrar_menores(a, 50, &contador);
    printf ("\nContador: %d", contador);

    destruir_arbol(a);
    return EXIT_SUCCESS;
}

arbol nuevo_arbol (int contenido)
{
    arbol ret;
    if ((ret = calloc(1,sizeof(nodo))) == NULL) {
        return NULL;
    }

    ret->contenido = contenido;

    return ret;
}

void destruir_arbol (arbol a)
{
    if (a == NULL) {
        return;
    }
    destruir_arbol(a->hizqdo);
    destruir_arbol(a->hdrcho);
    free(a);
}

void insertar_arbol (arbol nuevo, arbol *a)
{
    if (*a == NULL) {
        *a = nuevo;
        return;
    }

    if (nuevo->contenido < (*a)->contenido) {
        insertar_arbol(nuevo, &((*a)->hizqdo));
    } else if (nuevo->contenido > (*a)->contenido) {
        insertar_arbol(nuevo, &((*a)->hdrcho));
    }
}

void encontrar_menores (arbol a, int comparador, int *contador)
{
    if (a == NULL) {
        return;
    }

    if (a->contenido < comparador) {
        printf ("%d | ", a->contenido);  
        ++(*contador);
    } 
    encontrar_menores (a->hizqdo, comparador, contador);
    encontrar_menores (a->hdrcho, comparador, contador);
}

void imprimir (arbol a, int modo) 
{
    if (a == NULL) {
        return;
    }

    if (modo == 1) { // Preorden
    printf ("%d | ", a->contenido);
    imprimir(a->hizqdo, 1);
    imprimir(a->hdrcho, 1);
    } else if (modo == 2){ // Postorden
        imprimir(a->hizqdo, 2);
        imprimir(a->hdrcho, 2);
        printf ("%d | ", a->contenido);
        } else if (modo == 3) {// Inorden
            imprimir(a->hizqdo, 3);
            printf ("%d | ", a->contenido);
            imprimir(a->hdrcho, 3);
            }
}

miércoles, 8 de abril de 2020

Matrices dinámicas en C

A continuación un ejercicio, similar a otros que he publicado, pero ésta vez con Matrices de dimensiones dinámicas.




#include <stdio.h>
#include <stdlib.h>


int ** IntroduceMatriz (int *, int *);
void SumaFilas (int **, int, int);
void MultiplicaColumnas (int **, int, int);
void RotaMatrizDerecha (int **, int, int);
void MostrarMatriz (int **, int, int);

int main () 
{
    int **matriz, f ,c;
    int i;

    matriz = IntroduceMatriz(&f, &c);
    MostrarMatriz(matriz,f,c);
    SumaFilas(matriz,f,c);
    MultiplicaColumnas(matriz,f,c);
    RotaMatrizDerecha(matriz,f,c);
    MostrarMatriz(matriz,f,c);
    for (i=0; i<f ; i++) {
        free(matriz[i]);
    }
    free(matriz);
    return EXIT_SUCCESS;
}

int ** IntroduceMatriz (int *f, int *c)
{
    int **matriz;
    int i, j;

    printf ("Indique numero de filas: \n");
    scanf ("%d",f);
    fflush (stdin);  // Limpiar el buffer de entrada
    printf ("Indique numero de columnas: \n");
    scanf ("%d",c);
    fflush (stdin);

    matriz = (int **) calloc (*f,sizeof(int*));

    for (i=0 ; i<*f ; i++) {
            matriz[i] = (int*) calloc (*c,sizeof(int));
    }

    for (i=0 ; i<*f ; i++) {
        for (j=0 ; j<*c ; j++) {
            printf ("\nIntroduzca posición %d - %d: ",i,j);
            scanf("%d",&matriz[i][j]);
            fflush(stdin);
        }
    }
    return matriz;
}

void MostrarMatriz (int **matriz, int f, int c)
{
    int i,j;
    for (i=0 ; i<f ; i++) {
        for (j=0 ; j<c ; j++) {
            printf ("%d ",matriz[i][j]);
        } printf ("\n");
    }
}

void SumaFilas (int **matriz, int f, int c)
{
    int i,j,suma;
    for (i=0 ; i<f ; i++) {
        suma = 0;
        for (j=0 ; j<c ; j++) {
            suma += matriz[i][j];
        } printf ("La fila %d suma: %d \n",f,suma);
    }
}

void MultiplicaColumnas (int **matriz, int f, int c)
{
    int i,j, multiplica;
    for (j=0 ; j<c ; j++) {
        multiplica = 1;
        for (i=0 ; i<f ; i++) {
            multiplica *= matriz[i][j];
        } printf ("La columna %d da: %d \n",j,multiplica);
    }
}

void RotaMatrizDerecha (int **matriz, int f, int c)
{
    int i,j;
    int **matrizt;

 
    matrizt = (int**) calloc (f,sizeof(int*));
    for (i=0; i<f ; i++) {
        matrizt[i] = (int*) calloc (c,sizeof(int));
    }

    for (i=0 ; i<f ; i++) {
        for (j=0 ; j<c ; j++) {
            if (j == c-1) {
                matrizt[i][0] = matriz[i][j]; 
            } else {
                matrizt[i][j+1] = matriz[i][j];
            }     
        } 
    }

    for (i=0 ; i<f ; i++) {
        for (j=0 ; j<c ; j++) {
            matriz[i][j] = matrizt[i][j];
        } 
    }

}

lunes, 6 de enero de 2020

Programa en C que genere 6 hilos y estos se identifiquen

Generemos un programa en lenguaje C que lance o genere 6 hilos y estos se identifiquen con un identificador.





#include <stdio.h>
#include <pthread.h>
#include <unistd.h>

#define NUMERO 6

int contador;
static void *saluda (void *);

int main (void)
{
 int i;
 pthread_t hilo[NUMERO];

 for (i = 0; i < NUMERO ; i++) {
  sleep(1);
  pthread_create (&hilo[i],NULL,saluda,NULL);
 }

 for (i = 0; i < NUMERO ; i++) {

  pthread_join (hilo[i],NULL);
 }

 return 0;
}

static void *saluda (void *args) 
{
 contador += 1;
 printf ("Soy el thread %d y tengo el id %d\n",contador,(int) pthread_self());
 return NULL;
}

Memoria compartida, semáforos y procesos

Generar una aplicación multiproceso controlada por un semáforo.

 


#include <stdio.h>
#include <sys/ipc.h>
#include <sys/sem.h>
#include <sys/shm.h>
#include <stdlib.h>
#include <unistd.h>


int main (void)
{
 // 1. Generamos la estructura
 struct sembuf op;

 // 2. Memoria compartida
 int id_mem;
 int *var;
 if ((id_mem = shmget(IPC_PRIVATE,sizeof(int), IPC_CREAT | 0600)) == -1){
  perror("shmget");
  exit(1);
 }

 var = shmat(id_mem,0,0);
 (*var) = 0;

 // 3. Generación del semáforo
 int id_sem;
 if ((id_sem = semget(IPC_PRIVATE,1,0777)) == -1) {
  perror("semget");
  exit(1);
 }

 // 4. Inicialización del semáforo
 semctl(id_sem,0,SETVAL,1);
 op.sem_num = 0;
 op.sem_flg = 0;

 // 5. Lanzamos los procesos fork()
 fork(); fork(); fork(); 

 // 6. Pasamos los procesos por el semáforo
 for (int i = 0; i < 10 ; i++) {
  op.sem_op = -1;
  semop(id_sem,&op,1);
  (*var)++;
  printf ("El valor de var: %d \n",*var);
  op.sem_op = 1;
  semop(id_sem,&op,1);
 }

 // 7. Eliminamos la memoria compartida así como el semáforo
 semctl(id_sem,0,IPC_RMID);
 shmdt(var);
 shmctl(id_mem,IPC_RMID,0);

 return 0;
}

lunes, 3 de junio de 2019

Ejemplo completo de Matrices en C

A continuación, os pongo el ejemplo que se me ha ocurrido más completo sobre gestión de Matrices en C que reúne los ejemplos que he ido poniendo anteriormente.




#include <stdio.h>;
#include <stdlib.h>;


void Ingresa_Matriz (int m[3][3], int f, int c);
void Utiliza_Matriz (int m[3][3], int f, int c);
void Visualiza_Matriz (int m[3][3], int f, int c);
void Rota_Matriz_D (int m[3][3], int f, int c);
void Rota_Matriz_I (int m[3][3], int f, int c);
void Multiplica_Matriz (int m[3][3], int f, int c, int cf, int *m0, int *m1, int *m2);

int main () {
    char ingresa;
    int m[3][3], cf = 0, direccion = 0, f = 0, c = 0;
    int m0, m1, m2;
    printf ("Deseas ingresar Matriz o utiliza la maqueta &lt;I/M&gt;: ");
    scanf ("%c",&amp;ingresa);
    if (ingresa == 'i') {
        Ingresa_Matriz(m, f, c);
    } else {
        Utiliza_Matriz(m, f, c);
    }
    Visualiza_Matriz(m, f, c);
    printf ("\nDeseas rotar la matriz a la derecha &lt;1&gt; o a la izquierda &lt;0&gt;: ");
    scanf ("%d",&amp;direccion);
    if (direccion == 1) {
        Rota_Matriz_D (m, f, c);
    } else {
        Rota_Matriz_I (m, f, c);
    }
    Visualiza_Matriz(m, f, c);
    printf ("\n¿Quieres multiplicar las filas (1) o las columnas (0)?: ");
    scanf ("%d",&amp;cf);
    Multiplica_Matriz(m, f, c, cf, &amp;m0, &amp;m1, &amp;m2);
    if (cf == 1) {
        printf ("\nMultiplicacion Fila 0: %d",m0);
        printf ("\nMultiplicacion Fila 1: %d",m1);
        printf ("\nMultiplicacion Fila 2: %d",m2);
    } else {
        printf ("\nMultiplicacion Columna 0: %d",m0);
        printf ("\nMultiplicacion Columna 1: %d",m1);
        printf ("\nMultiplicacion Columna 2: %d",m2);
    }
    return 0;
}

void Ingresa_Matriz (int m[3][3], int f, int c) {
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            printf ("\nIntroduce posicion [%d][%d]: ",f,c);
            scanf ("%d",&amp;m[f][c]);
        }
    }
}

void Utiliza_Matriz (int m[3][3], int f, int c) {
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            m[f][c]=rand()%50+1;
        }
    }
}

void Visualiza_Matriz (int m[3][3], int f, int c) {
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            printf ("[%d] ",m[f][c]);
        } printf ("\n");
    }
}
void Rota_Matriz_D (int m[3][3], int f, int c) {
    int tmp[3][3];
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
                if (c == 2) {
                    tmp[f][0]=m[f][c];
                } else {
                    tmp[f][c+1]=m[f][c];
                }
            }
        }
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            m[f][c]=tmp[f][c];
        }
    }
}

void Rota_Matriz_I (int m[3][3], int f, int c) {
    int tmp[3][3];
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            if (c == 0) {
                tmp[f][2]=m[f][c];
            } else {
                tmp[f][c-1]=m[f][c];
            }
        }
    }
    
    for (f=0;f&lt;3;++f) {
        for (c=0;c&lt;3;++c) {
            m[f][c]=tmp[f][c];
        }
    }
}

void Multiplica_Matriz (int m[3][3], int f, int c, int cf, int *m0, int *m1, int *m2) {
    // 1 Multiplica filas
    // 0 Multiplica columnas
    int c0[3], c1[3], c2[3];
    
    if (cf == 0) {
        printf ("\nMultiplicando columnas...\n\n");
        for (f=0;f&lt;3;++f) {
            for (c=0;c&lt;3;++c) {
                if (c == 0)
                    c0[f]=m[f][c];
                if (c == 1)
                    c1[f]=m[f][c];
                if (c == 2)
                    c2[f]=m[f][c];
            }
        }
    } else {
        printf ("\nMultiplicando filas...\n\n");
        for (f=0;f&lt;3;++f) {
            for (c=0;c&lt;3;++c) {
                if (f == 0)
                    c0[c]=m[f][c];
                if (f == 1)
                    c1[c]=m[f][c];
                if (f == 2)
                    c2[c]=m[f][c];
            }
        }
    }
    *m0=c0[0]*c0[1]*c0[2];
    *m1=c1[0]*c1[1]*c1[2];
    *m2=c2[0]*c2[1]*c2[2];
}