⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 its a full portscan... it works for all type of scanning. here we use libcap
💻 C
字号:
/*
 * Dynamic Port Scanner (DPS)
 * main.c -- Main function
 *
 * Copyright (c) 2006 - 2008 AR Samhuri <ar@securebits.org>
 * ALL RIGHTS RESERVED.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 */

/*
 * My Include
 */
#include "./dps.h"

/*
 * Main Function
 */
int main( int argc, char **argv )
{
    char        option;
    extern char	*optarg;
    extern int  optind;

    cfg.scan_type    = NULL;
    cfg.port_list    = NULL;
    cfg.source_ports = NULL;
    cfg.source_ips   = NULL;
    cfg.device       = NULL;
    cfg.timeout      = SCAN_TIMEOUT;
    cfg.resolve      = 1;
    cfg.ping         = 1;
    cfg.windows      = 0;
    cfg.verbosity    = 0;
    cfg.target_ips   = NULL;

    while( ( option = getopt( argc, argv, "t:p:i:T:s:S:P:dwvh" ) ) != EOF )
    {
        switch( option )
        {
            case 't':
                cfg.scan_type = ( char * ) malloc( strlen( optarg ) + 1 );
                strncpy( cfg.scan_type, optarg, strlen ( optarg ) );
                if( strcmp( cfg.scan_type, "N" ) == 0 )
                {
                    tcp_control = SCAN_NULL;
                    strcpy( scan_type_str, "TCP NULL Scan [______]" );
                }
                else if( strcmp( cfg.scan_type, "F" ) == 0 )
                {
                    tcp_control = SCAN_FIN;
                    strcpy( scan_type_str, "TCP FIN Scan [_____F]" );
                }
                else if( strcmp( cfg.scan_type, "S" ) == 0 )
                {
                    tcp_control = SCAN_SYN;
                    strcpy( scan_type_str, "TCP SYN Scan [____S_]" );
                }
                else if( strcmp( cfg.scan_type, "P" ) == 0 )
                {
                    tcp_control = SCAN_PSH;
                    strcpy( scan_type_str, "TCP PSH Scan [__P___]" );
                }
                else if( strcmp( cfg.scan_type, "A" ) == 0 )
                {
                    tcp_control = SCAN_ACK;
                    strcpy( scan_type_str, "TCP ACK Scan [_A____]" );
                }
                else if( strcmp( cfg.scan_type, "U" ) == 0 )
                {
                    tcp_control = SCAN_URG;
                    strcpy( scan_type_str, "TCP URG Scan [U_____]" );
                }
                else if( strcmp( cfg.scan_type, "X" ) == 0 )
                {
                    tcp_control = SCAN_XMAS;
                    strcpy( scan_type_str, "TCP XMAS Scan [U_P__F]" );
                }
                else if( strcmp( cfg.scan_type, "X1" ) == 0 )
                {
                    tcp_control = SCAN_XMAS1;
                    strcpy( scan_type_str, "TCP XMAS1 Scan [__P__F]" );
                }
                else if( strcmp( cfg.scan_type, "X2" ) == 0 )
                {
                    tcp_control = SCAN_XMAS2;
                    strcpy( scan_type_str, "TCP XMAS2 Scan [U____F]" );
                }
                else if( strcmp( cfg.scan_type, "X3" ) == 0 )
                {
                    tcp_control = SCAN_XMAS3;
                    strcpy( scan_type_str, "TCP XMAS3 Scan [U_P___]" );
                }
                else if( strcmp( cfg.scan_type, "UDP" ) == 0 )
                {
                    strcpy( scan_type_str, "TCP UDP Scan" );
                }
                else
                {
                    dps_usage( argv[ 0 ] );
                    exit( EXIT_FAILURE );
                }
                break;
            case 'p':
                cfg.port_list = ( char * ) malloc( strlen( optarg ) + 1 );
                strncpy( cfg.port_list, optarg, strlen( optarg ) );
                break;
            case 'i':
                cfg.device = ( char * ) malloc( strlen( optarg ) + 1 );
                strncpy( cfg.device, optarg, strlen( optarg ) );
                break;
            case 'T':
                cfg.timeout = atoi( optarg );
                break;
            case 's':
                cfg.source_ports = ( char * ) malloc( strlen( optarg ) + 1 );
                strncpy( cfg.source_ports, optarg, strlen( optarg ) );
                break;
            case 'S':
                cfg.source_ips = ( char * ) malloc( strlen( optarg ) + 1 );
                strncpy( cfg.source_ips, optarg, strlen( optarg ) );
                break;
            case 'P':
                cfg.ping = atoi( optarg );
                break;
            case 'd':
                cfg.resolve = 0;
                break;
            case 'w':
                cfg.windows = 1;
                break;
            case 'v':
                cfg.verbosity++;
                break;
            case 'h':
                dps_usage( argv[ 0 ] );
                exit( EXIT_SUCCESS );
                break;
            default:
                dps_usage( argv[ 0 ] );
                exit( EXIT_FAILURE );
        }
    }

    if( argc - optind != 1 )
    {
        dps_usage( argv[ 0 ] );
        exit( EXIT_FAILURE );
    }
    else
    {	
        /* Copy the target ip/hostname */
        cfg.target_ips = ( char * ) malloc( strlen( argv[ optind ] + 1 ) );
        strncpy( cfg.target_ips, argv[ optind ], strlen( argv[ optind ] ) );
    }

    if( !cfg.device )
    {
        cfg.device = ( char * ) malloc( strlen( "eth0" ) + 1 );
        strncpy( cfg.device, "eth0", strlen( "eth0" ) );
    }

    /* Initialize the Dynamic Port Scanner [DPS] */
    dps_init();

    /* Start scanning */
    dps_scan();

    /* Print the results */
    dps_print();

    /* Clean-up */
    dps_cleanup();

    return 0;
}

/* EOF */

⌨️ 快捷键说明

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