Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
313 changes: 0 additions & 313 deletions README

This file was deleted.

21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,26 @@
[![Build Status](https://travis-ci.org/tomac/yersinia.svg?branch=master)](https://travis-ci.org/tomac/yersinia)

How to Install
-------------

Clone this repo inside `/opt/yersinia`.
Install the dependencies:
```
sudo apt install autoconf libgtk-3-dev libnet1-dev libgtk2.0-dev libpcap-dev -y
```
Then go inside `/opt/yersinia` and execute:
```
./autogen.sh
./configure --with-gtk # flag required to compile with GUI support
make
make install
```

And that's it, you can now start it with:
```
yersinia -G
```

Spanning Tree
-------------

Expand Down
14 changes: 8 additions & 6 deletions src/admin.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>
* Copyright 2005-2017 Alfredo Andres and David Barroso
*
* << Code amended by Nicolae Mercore - 11.2024 >>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
Expand Down Expand Up @@ -232,7 +234,7 @@ admin_th_listen(void *arg)
else
{
write_log(0,"\n Connection accepted for %s\n", inet_ntoa(*ip_addr));
if ( pthread_create( &tid, NULL, &admin_th_network_peer, (void *)sock2 ) < 0)
if ( pthread_create( &tid, NULL, &admin_th_network_peer, (void *)(intptr_t)sock2 ) < 0)
{
n=errno;
thread_error("pthread_create admin_th_listen",n);
Expand Down Expand Up @@ -330,13 +332,13 @@ admin_th_network_peer(void *sock)
if (pthread_mutex_lock(&terms->mutex) != 0)
thread_error("th_network_peer pthread_mutex_lock",errno);

fail = term_add_node(&term_node, TERM_VTY, sock, pthread_self());
fail = term_add_node(&term_node, TERM_VTY, (int)sock, pthread_self());

if (fail == -1)
{
if (pthread_mutex_unlock(&terms->mutex) != 0)
thread_error("th_network_peer pthread_mutex_unlock",errno);
admin_th_network_peer_exit(term_node, sock);
admin_th_network_peer_exit(term_node, (int)(intptr_t)sock);
}

if (term_node == NULL)
Expand All @@ -346,7 +348,7 @@ admin_th_network_peer(void *sock)

if (pthread_mutex_unlock(&terms->mutex) != 0)
thread_error("th_network_peer pthread_mutex_unlock",errno);
admin_th_network_peer_exit(term_node, sock);
admin_th_network_peer_exit(term_node, (int)(intptr_t)sock);
}

pthread_mutex_lock(&term_node->thread.finished);
Expand Down Expand Up @@ -377,14 +379,14 @@ admin_th_network_peer(void *sock)
thread_error("getpeername",errno);
if (pthread_mutex_unlock(&terms->mutex) != 0)
thread_error("th_vty_peer pthread_mutex_unlock",errno);
admin_th_network_peer_exit(term_node, sock);
admin_th_network_peer_exit(term_node, (int)(intptr_t)sock);
}

if (init_attribs(term_node) < 0)
{
if (pthread_mutex_unlock(&terms->mutex) != 0)
thread_error("th_vty_peer pthread_mutex_unlock",errno);
admin_th_network_peer_exit(term_node, sock);
admin_th_network_peer_exit(term_node, (int)(intptr_t)sock);
}

term_node->from_port = ntohs(name.sin_port);
Expand Down
4 changes: 3 additions & 1 deletion src/admin.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
* By David Barroso <tomac@yersinia.net> and Alfredo Andres <aandreswork@hotmail.com>
* Copyright 2005-2017 Alfredo Andres and David Barroso
*
* << Code amended by Nicolae Mercore - 11.2024 >>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
Expand Down Expand Up @@ -48,7 +50,7 @@ extern int8_t bin_data[];
/* Extern functions...*/
extern void write_log( u_int16_t mode, char *msg, ... );
extern int8_t attack_kill_th(struct term_node *, pthread_t);
extern int8_t term_add_node(struct term_node **, int8_t, int32_t, pthread_t);
extern int8_t term_add_node(struct term_node **, int8_t, int, pthread_t);
extern int8_t term_write(struct term_node *, char *, u_int16_t);
extern void term_delete_all(void);
extern void term_delete_node(struct term_node *, int8_t);
Expand Down
158 changes: 76 additions & 82 deletions src/gtk-callbacks.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <gtk/gtk.h>

#include "gtk-callbacks.h"
#include "gtk-interface.h"

#define GLADE_HOOKUP_OBJECT(component,widget,name) \
g_object_set_data_full (G_OBJECT (component), name, \
Expand Down Expand Up @@ -765,13 +766,18 @@ gtk_c_clock_update(GtkWidget *clock)


void
gtk_c_tree_update( GtkWidget *tree_model )
gtk_c_tree_update( GtkListStore *tree_model )
{
u_int8_t i, j;
GtkTreeIter iter;
GtkTreePath *path;
char tmp[3];

if (!GTK_IS_LIST_STORE(tree_model)) {
write_log(0, "Error: tree_model is not a valid GtkListStore\n");
return;
}

j = 0;
for( i=0; i < MAX_PROTOCOLS; i++ )
{
Expand All @@ -782,8 +788,9 @@ gtk_c_tree_update( GtkWidget *tree_model )
path = gtk_tree_path_new_from_string( tmp );
if ( path )
{
gtk_tree_model_get_iter( GTK_TREE_MODEL( tree_model ), &iter, path );
gtk_list_store_set( GTK_LIST_STORE( tree_model ), &iter, 1, protocols[i].packets, -1 );
if (gtk_tree_model_get_iter( GTK_TREE_MODEL( tree_model ), &iter, path )) {
gtk_list_store_set( tree_model, &iter, 1, protocols[i].packets, -1 );
}
gtk_tree_path_free( path );
}
j++;
Expand All @@ -794,8 +801,9 @@ gtk_c_tree_update( GtkWidget *tree_model )
path = gtk_tree_path_new_from_string( tmp );
if ( path )
{
gtk_tree_model_get_iter( GTK_TREE_MODEL( tree_model ), &iter, path );
gtk_list_store_set( GTK_LIST_STORE( tree_model ), &iter, 1, packet_stats.global_counter.total_packets, -1 );
if (gtk_tree_model_get_iter( GTK_TREE_MODEL( tree_model ), &iter, path )) {
gtk_list_store_set( tree_model, &iter, 1, packet_stats.global_counter.total_packets, -1 );
}
gtk_tree_path_free( path );
}
}
Expand Down Expand Up @@ -840,14 +848,28 @@ gtk_c_refresh_mwindow(gpointer userdata)
values = NULL;

/* Check if it is Yersinia log */
if ( ! helper->mode || ( helper->mode >= MAX_PROTOCOLS ) )
if ( ! helper->mode || ( helper->mode >= MAX_PROTOCOLS ) ) {
return TRUE;
}

/* Get the protocol tree using access function */
GtkWidget *protocol_tree = gtk_i_get_protocol_tree(helper->mode);
if (!protocol_tree || !GTK_IS_TREE_VIEW(protocol_tree)) {
return TRUE;
}

params = protocols[helper->mode].parameters;
extra_params = protocols[helper->mode].extra_parameters;

if ((tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(protocols_tree[helper->mode])))) == NULL)
if ((tree_model = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(protocol_tree)))) == NULL) {
write_log(0, "Error in gtk_tree_view_get_model\n");
return TRUE;
}

if (!GTK_IS_LIST_STORE(tree_model)) {
write_log(0, "Error: tree_model is not a valid GtkListStore\n");
return TRUE;
}

valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(tree_model), &iter);

Expand Down Expand Up @@ -971,6 +993,21 @@ gtk_c_refresh_mwindow(gpointer userdata)
}
}

/* Auto-select first row with data to trigger detail display */
if (helper->mode < MAX_PROTOCOLS && protocols[helper->mode].stats[0].header->ts.tv_sec > 0) {
GtkWidget *protocol_tree = gtk_i_get_protocol_tree(helper->mode);
if (protocol_tree) {
GtkTreeSelection *selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(protocol_tree));
if (selection) {
GtkTreePath *path = gtk_tree_path_new_from_string("0");
if (path) {
gtk_tree_selection_select_path(selection, path);
gtk_tree_path_free(path);
}
}
}
}

return TRUE;
}

Expand All @@ -979,99 +1016,56 @@ void gtk_c_tree_selection_changed_cb( GtkTreeSelection *selection, gpointer user
{
GtkTreeIter iter;
GtkTreeModel *model;
GtkWidget *tree;
GtkListStore *tree_model;
u_int8_t row = 0;
u_int8_t j, k, mode;
char **values = NULL, *ptrtlv;
struct commands_param *params;
char *protocol_name = NULL;
int protocol_index = -1;
struct gtk_s_helper *helper = (struct gtk_s_helper *) userdata;

if ( gtk_tree_selection_get_selected( selection, &model, &iter ) )
gtk_tree_model_get(model, &iter, 0, &row, -1);

mode = gtk_notebook_get_current_page(GTK_NOTEBOOK(helper->notebook));
params = (struct commands_param *)protocols[mode].parameters;

if ( protocols[mode].stats[row].header->ts.tv_sec <= 0)
{
/* write_log(0, "Ohhh no hay paquetes del modo %d, fila %d :(\n", mode, row); */
/* Basic validation */
if (!helper) {
return;
}

tree = lookup_widget(GTK_WIDGET(helper->notebook), "main_vhvvs_tree");

if ((tree_model = (GtkListStore *)gtk_tree_view_get_model(GTK_TREE_VIEW(tree))) == NULL)
{
write_log(0, "Error in gtk_tree_view_get_model\n");
if (!selection) {
return;
}

gtk_list_store_clear(tree_model);

if (protocols[mode].get_printable_packet)
{
values = (*protocols[mode].get_printable_packet)(&protocols[mode].stats[row]);

if ( ! values )
{
write_log(0, "Error in get_printable_packet (mode %d)\n", mode);
return ;
}
}
else
{
write_log(0, "Warning: there is no get_printable_packet for protocol %d\n", mode);
return ;
if (!gtk_tree_selection_get_selected(selection, &model, &iter)) {
return;
}

j = 0;
k = 0;

/* Normal parameters (-2 for the interface and defaults) */
while (j < protocols[mode].nparams)
{
if ((params[j].type != FIELD_IFACE) && (params[j].type != FIELD_DEFAULT) && (params[j].type != FIELD_EXTRA))
{
gtk_list_store_append(GTK_LIST_STORE(tree_model), &iter);
gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter, 0, params[j].ldesc, -1);
gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter, 1, values[k], -1);
if (params[j].meaning)
gtk_list_store_set( GTK_LIST_STORE( tree_model ), &iter, 2, parser_get_meaning( values[k], params[j].meaning ), -1 );
k++;
}
j++;
/* Get the protocol name from the first column */
gtk_tree_model_get(model, &iter, 0, &protocol_name, -1);

if (!protocol_name) {
return;
}

ptrtlv = values[k];
if (protocols[mode].extra_nparams > 0)
{
while( ptrtlv && strlen( ptrtlv ) )
{
gtk_list_store_append(GTK_LIST_STORE(tree_model), &iter);
gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter, 0, ptrtlv, -1);
ptrtlv += strlen( ptrtlv ) + 1;
if (ptrtlv)
{
gtk_list_store_set(GTK_LIST_STORE(tree_model), &iter, 1, ptrtlv, -1);
ptrtlv += strlen( ptrtlv ) + 1;
}
/* Find the protocol index */
for (int i = 0; i < MAX_PROTOCOLS; i++) {
if (protocols[i].visible && protocols[i].namep &&
strcmp(protocols[i].namep, protocol_name) == 0) {
protocol_index = i;
break;
}
}

gtk_list_store_append (GTK_LIST_STORE (tree_model), &iter);
gtk_list_store_set (GTK_LIST_STORE(tree_model), &iter, 0, "Interface", -1);
gtk_list_store_set (GTK_LIST_STORE(tree_model), &iter, 1, protocols[mode].stats[row].iface, -1);

k = 0;
if (protocol_index == -1) {
g_free(protocol_name);
return;
}

while( values[k] )
{
free((void *)values[k]);
k++;
/* Switch to the corresponding notebook tab */
if (helper->notebook) {
gtk_notebook_set_current_page(GTK_NOTEBOOK(helper->notebook), protocol_index);

/* Update helper->mode to match the new tab */
helper->mode = protocol_index;

/* Refresh the TreeView for this protocol to show packet data */
gtk_c_refresh_mwindow(helper);
}

free(values);
g_free(protocol_name);
}


Expand Down
2 changes: 1 addition & 1 deletion src/gtk-callbacks.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void gtk_c_attackparams_ok_click( GtkWidget *, gpointer );
gboolean gtk_c_attackparams_delete_event( GtkWidget *, GdkEvent *, gpointer );
void gtk_c_update_hexview(GtkTreeSelection *, gpointer);
void gtk_c_clock_update(GtkWidget *);
void gtk_c_tree_update(GtkWidget *);
void gtk_c_tree_update( GtkListStore * );
void gtk_c_refresh_mwindow_notebook(GtkNotebook *, GtkNotebookPage *, guint, gpointer);
gboolean gtk_c_refresh_mwindow(gpointer);
void gtk_c_tree_selection_changed_cb (GtkTreeSelection *, gpointer);
Expand Down
Loading