nmapfe_sig.c

来自「Ubuntu packages of security software。 相」· C语言 代码 · 共 1,309 行 · 第 1/3 页

C
1,309
字号
/*************************************************************************** * nmapfe_sig.c -- Signal handlers for NmapFE                              * *                                                                         * ***********************IMPORTANT NMAP LICENSE TERMS************************ *                                                                         * * The Nmap Security Scanner is (C) 1996-2006 Insecure.Com LLC. Nmap is    * * also a registered trademark of Insecure.Com LLC.  This program is free  * * software; you may redistribute and/or modify it under the terms of the  * * GNU General Public License as published by the Free Software            * * Foundation; Version 2 with the clarifications and exceptions described  * * below.  This guarantees your right to use, modify, and redistribute     * * this software under certain conditions.  If you wish to embed Nmap      * * technology into proprietary software, we sell alternative licenses      * * (contact sales@insecure.com).  Dozens of software vendors already       * * license Nmap technology such as host discovery, port scanning, OS       * * detection, and version detection.                                       * *                                                                         * * Note that the GPL places important restrictions on "derived works", yet * * it does not provide a detailed definition of that term.  To avoid       * * misunderstandings, we consider an application to constitute a           * * "derivative work" for the purpose of this license if it does any of the * * following:                                                              * * o Integrates source code from Nmap                                      * * o Reads or includes Nmap copyrighted data files, such as                * *   nmap-os-fingerprints or nmap-service-probes.                          * * o Executes Nmap and parses the results (as opposed to typical shell or  * *   execution-menu apps, which simply display raw Nmap output and so are  * *   not derivative works.)                                                *  * o Integrates/includes/aggregates Nmap into a proprietary executable     * *   installer, such as those produced by InstallShield.                   * * o Links to a library or executes a program that does any of the above   * *                                                                         * * The term "Nmap" should be taken to also include any portions or derived * * works of Nmap.  This list is not exclusive, but is just meant to        * * clarify our interpretation of derived works with some common examples.  * * These restrictions only apply when you actually redistribute Nmap.  For * * example, nothing stops you from writing and selling a proprietary       * * front-end to Nmap.  Just distribute it by itself, and point people to   * * http://insecure.org/nmap/ to download Nmap.                             * *                                                                         * * We don't consider these to be added restrictions on top of the GPL, but * * just a clarification of how we interpret "derived works" as it applies  * * to our GPL-licensed Nmap product.  This is similar to the way Linus     * * Torvalds has announced his interpretation of how "derived works"        * * applies to Linux kernel modules.  Our interpretation refers only to     * * Nmap - we don't speak for any other GPL products.                       * *                                                                         * * If you have any questions about the GPL licensing restrictions on using * * Nmap in non-GPL works, we would be happy to help.  As mentioned above,  * * we also offer alternative license to integrate Nmap into proprietary    * * applications and appliances.  These contracts have been sold to dozens  * * of software vendors, and generally include a perpetual license as well  * * as providing for priority support and updates as well as helping to     * * fund the continued development of Nmap technology.  Please email        * * sales@insecure.com for further information.                             * *                                                                         * * As a special exception to the GPL terms, Insecure.Com LLC grants        * * permission to link the code of this program with any version of the     * * OpenSSL library which is distributed under a license identical to that  * * listed in the included Copying.OpenSSL file, and distribute linked      * * combinations including the two. You must obey the GNU GPL in all        * * respects for all of the code used other than OpenSSL.  If you modify    * * this file, you may extend this exception to your version of the file,   * * but you are not obligated to do so.                                     * *                                                                         * * If you received these files with a written license agreement or         * * contract stating terms other than the terms above, then that            * * alternative license agreement takes precedence over these comments.     * *                                                                         * * Source is provided to this software because we believe users have a     * * right to know exactly what a program is going to do before they run it. * * This also allows you to audit the software for security holes (none     * * have been found so far).                                                * *                                                                         * * Source code also allows you to port Nmap to new platforms, fix bugs,    * * and add new features.  You are highly encouraged to send your changes   * * to fyodor@insecure.org for possible incorporation into the main         * * distribution.  By sending these changes to Fyodor or one the            * * Insecure.Org development mailing lists, it is assumed that you are      * * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right * * to reuse, modify, and relicense the code.  Nmap will always be          * * available Open Source, but this is important because the inability to   * * relicense code has caused devastating problems for other Free Software  * * projects (such as KDE and NASM).  We also occasionally relicense the    * * code to third parties as discussed above.  If you wish to specify       * * special license conditions of your contributions, just say so when you  * * send them.                                                              * *                                                                         * * This program is distributed in the hope that it will be useful, but     * * WITHOUT ANY WARRANTY; without even the implied warranty of              * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       * * General Public License for more details at                              * * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included  * * with Nmap.                                                              * *                                                                         * ***************************************************************************//* $Id: nmapfe_sig.c 4123 2006-11-03 05:36:41Z fyodor $ *//* Original Author: Zach * Mail: key@aye.net * IRC: EFNet as zach` or key in #bastards or #neatoelito * AIM (Aol): GoldMatrix * * Change the source as you wish, but leave these comments.. * * Long live Aol and pr: Phreak. <grins> */#ifndef MAX_PARSE_ARGS#define MAX_PARSE_ARGS 512#endif#if MISSING_GTK/* Do nothing, nmapfe.c will spit out an error */#else#include <nbase.h>#include <gtk/gtk.h>#include <stdio.h>#include <signal.h>#include <stdlib.h>#if HAVE_UNISTD_H#include <unistd.h>#endif#include <string.h>#include <sys/types.h>#include <sys/stat.h>#if HAVE_SYS_WAIT_H#include <sys/wait.h>#endif#include <fcntl.h>#if HAVE_STRINGS_H#include <strings.h>#endif#include <assert.h>#include <ctype.h>#include <errno.h>#ifdef WIN32#include <windows.h>#endif#include "nmapfe.h"#include "nmapfe_sig.h"#ifndef BUFSIZ#define BUFSIZ  8192#endifextern struct NmapFEoptions opt;/* Variables for piping *//* FIXME: All this should be redone in a much more elegant manner <sigh> */int nmap_pid = 0;#ifdef WIN32HANDLE NmapHandle;#endifint pid;#ifdef WIN32HANDLE pipes[2]; /* 0 == read; 1 == write */#elseint pipes[2] = {-1,-1};#endifint verb = 0;int main (int   argc,       char *argv[]){    GtkWidget *main_win;    GtkTextIter iter;    gtk_set_locale();    gtk_init(&argc, &argv);#ifndef WIN32    signal(SIGPIPE, SIG_IGN);    opt.isr00t = !geteuid();#else    opt.isr00t = 1; /* With Windows (in general), every user is a Super User! */#endif    main_win = create_main_win();    gtk_widget_show(main_win);    gtk_text_buffer_get_end_iter (opt.buffer, &iter);    gtk_text_buffer_insert_with_tags_by_name (opt.buffer, &iter,             (opt.isr00t)            ? "You are root - All options granted."            : "You are *NOT* root - Some options aren't available.", -1,             "normal", NULL);    gtk_main();    return 0;}// tokensz is the total size of token in charactersstatic char *next_token(char *buf, char *token, int tokensz){  if ((buf != NULL) && (token != NULL)) {  int count = (strchr("\t ", *buf) != NULL)              ? strspn(buf, "\t ")              : strcspn(buf, "\t ");    if (count > 0) {      char *bol = buf;    char *eol;      count = MIN(count, tokensz - 1);      eol = buf+count;      /* copy token  */      memcpy(token, buf, count);      token[count] = '\0';      /* remove token from str */      while (*eol != '\0')        *bol++ = *eol++;      *bol = '\0';      return(token);    }    return(buf);  }  return(NULL);}static char *build_command(){static char *command = NULL;int command_size = 2560;  /* Find how much to malloc() */  // size = strlen(gtk_entry_get_text(GTK_ENTRY(opt.range_text))) +  //   strlen(gtk_entry_get_text(GTK_ENTRY(opt.Decoy))) +  //   strlen(gtk_entry_get_text(GTK_ENTRY(opt.inputFilename))) +  //   strlen(gtk_entry_get_text(GTK_ENTRY(opt.SourceDevice)))+  //   strlen(gtk_entry_get_text(GTK_ENTRY(opt.scanRelay)))+  //   strlen(gtk_entry_get_text(GTK_ENTRY(opt.targetHost))) +  //   2560;  /* We get 60 from the chars required for each option */  if (!command)    command = safe_malloc(command_size);  strcpy(command, "nmap ");   /* select the scan type */  if (opt.scanValue == CONNECT_SCAN) {    strcat(command, "-sT ");  } else if (opt.scanValue == PING_SCAN) {    strcat(command, "-sP ");  } else if (opt.scanValue == LIST_SCAN) {    strcat(command, "-sL ");  } else if (opt.scanValue == UDP_SCAN) {    strcat(command, "-sU ");  } else if (opt.scanValue == FIN_SCAN) {    strcat(command, "-sF ");  } else if (opt.scanValue == NULL_SCAN) {    strcat(command, "-sN ");  } else if (opt.scanValue == XMAS_SCAN) {    strcat(command, "-sX ");  } else if (opt.scanValue == ACK_SCAN) {    strcat(command, "-sA ");  } else if (opt.scanValue == WIN_SCAN) {    strcat(command, "-sW ");  } else if (opt.scanValue == MAIMON_SCAN) {    strcat(command, "-sM ");  } else if (opt.scanValue == PROT_SCAN) {    strcat(command, "-sO ");  } else if (opt.scanValue == SYN_SCAN) {    strcat(command, "-sS ");  } else if ((opt.scanValue == BOUNCE_SCAN) || (opt.scanValue == IDLE_SCAN)) {  const char *val = gtk_entry_get_text(GTK_ENTRY(opt.scanRelay));    if (val) {         strcat(command, (opt.scanValue == IDLE_SCAN) ? "-sI " : "-b ");      strcat(command, (*val) ? val : "127.0.0.1");      strcat(command, " ");    }  }   if (GTK_WIDGET_SENSITIVE(opt.RPCInfo) &&      GTK_TOGGLE_BUTTON(opt.RPCInfo)->active)    strcat(command, "-sR ");     if (GTK_WIDGET_SENSITIVE(opt.VersionInfo) &&      GTK_TOGGLE_BUTTON(opt.VersionInfo)->active)    strcat(command, "-sV ");  if (GTK_WIDGET_SENSITIVE(opt.OSInfo) &&      GTK_TOGGLE_BUTTON(opt.OSInfo)->active)    strcat(command, "-O ");  if (GTK_WIDGET_SENSITIVE(opt.protportType)) {    if (opt.protportValue == FAST_PROTPORT)      strcat(command, "-F ");    else if (opt.protportValue == ALL_PROTPORT)      strcat(command, "-p- ");    else if (opt.protportValue == GIVEN_PROTPORT) {    const char *val = gtk_entry_get_text(GTK_ENTRY(opt.protportRange));    if (val && *val) {           strcat(command, "-p ");      strcat(command, val);        strcat(command, " ");      }    }  }  if (GTK_TOGGLE_BUTTON(opt.dontPing)->active)    strcat(command, "-P0 ");  else {    if (GTK_WIDGET_SENSITIVE(opt.icmpechoPing) &&         GTK_TOGGLE_BUTTON(opt.icmpechoPing)->active)      strcat(command, "-PI ");    if (GTK_WIDGET_SENSITIVE(opt.icmptimePing) &&        GTK_TOGGLE_BUTTON(opt.icmptimePing)->active)      strcat(command, "-PP ");    if (GTK_WIDGET_SENSITIVE(opt.icmpmaskPing) &&        GTK_TOGGLE_BUTTON(opt.icmpmaskPing)->active)      strcat(command, "-PM ");    if (GTK_WIDGET_SENSITIVE(opt.tcpPing) &&        GTK_TOGGLE_BUTTON(opt.tcpPing)->active) {    const char *val = gtk_entry_get_text(GTK_ENTRY(opt.tcpPingPorts));      strcat(command, "-PT");      if (val && *val)    strcat(command, val);      strcat(command, " ");  }    if (GTK_WIDGET_SENSITIVE(opt.synPing) &&        GTK_TOGGLE_BUTTON(opt.synPing)->active) {    const char *val = gtk_entry_get_text(GTK_ENTRY(opt.synPingPorts));      strcat(command, "-PS");      if (val && *val)        strcat(command, val);      strcat(command, " ");    }    if (GTK_WIDGET_SENSITIVE(opt.udpPing) &&        GTK_TOGGLE_BUTTON(opt.udpPing)->active) {    const char *val = gtk_entry_get_text(GTK_ENTRY(opt.udpPingPorts));      strcat(command, "-PU");      if (val && *val)         strcat(command, val);      strcat(command, " ");    }  }  if ((opt.throttleValue != NO_THROTTLE) && (opt.throttleValue != NORMAL_THROTTLE))    sprintf(command+strlen(command), "-T%u ", opt.throttleValue);  if (GTK_TOGGLE_BUTTON(opt.startRtt)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.startRttTime));    sprintf(command+strlen(command), "--initial-rtt-timeout %d ", val);  }  if (GTK_TOGGLE_BUTTON(opt.minRtt)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.minRttTime));    sprintf(command+strlen(command), "--min-rtt-timeout %d ", val);    }  if (GTK_TOGGLE_BUTTON(opt.maxRtt)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.maxRttTime));    sprintf(command+strlen(command), "--max-rtt-timeout %d ", val);  }  if (GTK_TOGGLE_BUTTON(opt.hostTimeout)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.hostTimeoutTime));    sprintf(command+strlen(command), "--host-timeout %d ", val);    }  if (GTK_TOGGLE_BUTTON(opt.scanDelay)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.scanDelayTime));    sprintf(command+strlen(command), "--scan-delay %d ", val);  }  if (GTK_TOGGLE_BUTTON(opt.ipv4Ttl)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.ipv4TtlValue));    sprintf(command+strlen(command), "--ttl %d ", val);  }  if (GTK_TOGGLE_BUTTON(opt.minPar)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.minParSocks));    sprintf(command+strlen(command), "--min-parallelism %d ", val);    }  if (GTK_TOGGLE_BUTTON(opt.maxPar)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.maxParSocks));    sprintf(command+strlen(command), "-M %d ", val);  }  if (opt.resolveValue == ALWAYS_RESOLVE)    strcat(command, "-R ");		  else if (opt.resolveValue == NEVER_RESOLVE)    strcat(command, "-n ");		  if (GTK_TOGGLE_BUTTON(opt.verbose)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.verboseValue));    if (val == 1)      strcat(command, "-v ");    else if (val == 2)      strcat(command, "-vv ");  }  if (GTK_TOGGLE_BUTTON(opt.debug)->active) {  int val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(opt.debugValue));    if (val > 0) {      strcat(command, "-d");      if (val > 1)        sprintf(command+strlen(command), "%d", val);      strcat(command, " ");    }

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?