From 5a309b62ee931874a05b3ee0637a02a6b1d13a96 Mon Sep 17 00:00:00 2001 From: ithilgore Date: Wed, 6 May 2009 19:00:16 +0000 Subject: [PATCH] -iL and --exclude options working --- Makefile | 2 +- Makefile.in | 2 +- NcrackOps.h | 1 + TargetGroup.cc | 14 +- TargetGroup.h | 6 +- config.log | 506 ++++++++++++++++++++--------------------------- config.status | 5 +- configure | 205 +------------------ configure.ac | 61 +----- nbase/config.log | 4 +- ncrack.cc | 202 ++++++++++++++----- ncrack_config.h | 6 +- targets.cc | 12 +- targets.h | 3 +- 14 files changed, 401 insertions(+), 628 deletions(-) diff --git a/Makefile b/Makefile index 0da73f79..83acd51f 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ export NSOCKDIR=nsock DEFS = -DHAVE_CONFIG_H DEFS += -D_FORTIFY_SOURCE=2 -CXXFLAGS = -g -O2 -Wall -fno-strict-aliasing $(DBGFLAGS) $(CCOPT) $(DEFS) +CXXFLAGS = -O0 -Wall -fno-strict-aliasing $(DBGFLAGS) $(DEFS) CPPFLAGS = -Inbase -Insock/include export CFLAGS = $(CXXFLAGS) STATIC = diff --git a/Makefile.in b/Makefile.in index 8036a050..23d97cf5 100644 --- a/Makefile.in +++ b/Makefile.in @@ -3,7 +3,7 @@ export NSOCKDIR=@NSOCKDIR@ DEFS = @DEFS@ DEFS += -D_FORTIFY_SOURCE=2 -CXXFLAGS = @CXXFLAGS@ $(DBGFLAGS) $(CCOPT) $(DEFS) +CXXFLAGS = @CXXFLAGS@ $(DBGFLAGS) $(DEFS) CPPFLAGS = @CPPFLAGS@ export CFLAGS = $(CXXFLAGS) STATIC = diff --git a/NcrackOps.h b/NcrackOps.h index 3e838d6b..198e99e0 100644 --- a/NcrackOps.h +++ b/NcrackOps.h @@ -11,6 +11,7 @@ class NcrackOps { int debugging; int verbose; int numhosts_scanned; + int max_group_size; private: int addressfamily; /* Address family: AF_INET or AF_INET6 */ diff --git a/TargetGroup.cc b/TargetGroup.cc index d14a4275..dc3dabc0 100644 --- a/TargetGroup.cc +++ b/TargetGroup.cc @@ -92,9 +92,12 @@ /* $Id: TargetGroup.cc 12955 2009-04-15 00:37:03Z fyodor $ */ +#include "NcrackOps.h" #include "TargetGroup.h" #include "utils.h" +extern NcrackOps o; + TargetGroup::TargetGroup() { Initialize(); @@ -407,9 +410,9 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) { #if HAVE_SOCKADDR_SA_LEN sin->sin_len = *sslen; #endif - // if (o.debugging > 2) { - printf("doing %d.%d.%d.%d = %d.%d.%d.%d\n", current[0], current[1], current[2], current[3], addresses[0][current[0]],addresses[1][current[1]],addresses[2][current[2]],addresses[3][current[3]]); - // } + if (o.debugging > 2) { + printf("doing %d.%d.%d.%d = %d.%d.%d.%d\n", current[0], current[1], current[2], current[3], addresses[0][current[0]],addresses[1][current[1]],addresses[2][current[2]],addresses[3][current[3]]); + } /* Set the IP to the current value of everything */ sin->sin_addr.s_addr = htonl(addresses[0][current[0]] << 24 | addresses[1][current[1]] << 16 | @@ -455,6 +458,7 @@ int TargetGroup::get_next_host(struct sockaddr_storage *ss, size_t *sslen) { } ipsleft--; + /* NCRACK-TODO: use this for restore procedure */ /* If we are resuming from a previous scan, we have already finished scans up to o.resume_ip. */ //if (sin->sin_family == AF_INET && o.resume_ip.s_addr) { @@ -502,14 +506,12 @@ int TargetGroup::return_last_host() { The target_expressions array MUST REMAIN VALID IN MEMORY as long as this class instance is used -- the array is NOT copied. */ -HostGroupState::HostGroupState(int lookahead, int rnd, - char *expr[], int numexpr) { +HostGroupState::HostGroupState(int lookahead, char *expr[], int numexpr) { assert(lookahead > 0); hostbatch = (Target **) safe_zalloc(sizeof(Target *) * lookahead); max_batch_sz = lookahead; current_batch_sz = 0; next_batch_no = 0; - randomize = rnd; target_expressions = expr; num_expressions = numexpr; next_expression = 0; diff --git a/TargetGroup.h b/TargetGroup.h index 879e42ad..3639bffa 100644 --- a/TargetGroup.h +++ b/TargetGroup.h @@ -162,17 +162,13 @@ class TargetGroup { class HostGroupState { public: - HostGroupState(int lookahead, int randomize, char *target_expressions[], - int num_expressions); + HostGroupState(int lookahead, char *target_expressions[], int num_expressions); ~HostGroupState(); Target **hostbatch; int max_batch_sz; /* The size of the hostbatch[] array */ int current_batch_sz; /* The number of VALID members of hostbatch[] */ int next_batch_no; /* The index of the next hostbatch[] member to be given back to the user */ - int randomize; /* Whether each batch should be "shuffled" prior to the ping - scan (they will also be out of order when given back one - at a time to the client program */ char **target_expressions; /* An array of target expression strings, passed to us by the client (client is also in charge of deleting it AFTER it is done with the diff --git a/config.log b/config.log index 179d9eea..caac3ced 100644 --- a/config.log +++ b/config.log @@ -46,134 +46,134 @@ PATH: /usr/local/bin ## Core tests. ## ## ----------- ## -configure:1886: checking build system type -configure:1904: result: x86_64-unknown-linux-gnu -configure:1926: checking host system type -configure:1941: result: x86_64-unknown-linux-gnu -configure:2011: checking for gcc -configure:2027: found /usr/bin/gcc -configure:2038: result: gcc -configure:2270: checking for C compiler version -configure:2278: gcc --version >&5 +configure:1887: checking build system type +configure:1905: result: x86_64-unknown-linux-gnu +configure:1927: checking host system type +configure:1942: result: x86_64-unknown-linux-gnu +configure:2012: checking for gcc +configure:2028: found /usr/bin/gcc +configure:2039: result: gcc +configure:2271: checking for C compiler version +configure:2279: gcc --version >&5 gcc (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -configure:2282: $? = 0 -configure:2289: gcc -v >&5 +configure:2283: $? = 0 +configure:2290: gcc -v >&5 Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic Thread model: posix gcc version 4.3.3 (GCC) -configure:2293: $? = 0 -configure:2300: gcc -V >&5 +configure:2294: $? = 0 +configure:2301: gcc -V >&5 gcc: '-V' option must have argument -configure:2304: $? = 1 -configure:2327: checking for C compiler default output file name -configure:2349: gcc conftest.c >&5 -configure:2353: $? = 0 -configure:2391: result: a.out -configure:2410: checking whether the C compiler works -configure:2420: ./a.out -configure:2424: $? = 0 -configure:2443: result: yes -configure:2450: checking whether we are cross compiling -configure:2452: result: no -configure:2455: checking for suffix of executables -configure:2462: gcc -o conftest conftest.c >&5 -configure:2466: $? = 0 -configure:2492: result: -configure:2498: checking for suffix of object files -configure:2524: gcc -c conftest.c >&5 -configure:2528: $? = 0 -configure:2553: result: o -configure:2557: checking whether we are using the GNU C compiler -configure:2586: gcc -c conftest.c >&5 -configure:2593: $? = 0 -configure:2610: result: yes -configure:2619: checking whether gcc accepts -g -configure:2649: gcc -c -g conftest.c >&5 -configure:2656: $? = 0 -configure:2757: result: yes -configure:2774: checking for gcc option to accept ISO C89 -configure:2848: gcc -c -g -O2 conftest.c >&5 -configure:2855: $? = 0 -configure:2878: result: none needed -configure:2897: checking for inline -configure:2923: gcc -c -g -O2 conftest.c >&5 -configure:2930: $? = 0 -configure:2948: result: inline -configure:3016: checking for gcc -configure:3043: result: gcc -configure:3275: checking for C compiler version -configure:3283: gcc --version >&5 +configure:2305: $? = 1 +configure:2328: checking for C compiler default output file name +configure:2350: gcc conftest.c >&5 +configure:2354: $? = 0 +configure:2392: result: a.out +configure:2411: checking whether the C compiler works +configure:2421: ./a.out +configure:2425: $? = 0 +configure:2444: result: yes +configure:2451: checking whether we are cross compiling +configure:2453: result: no +configure:2456: checking for suffix of executables +configure:2463: gcc -o conftest conftest.c >&5 +configure:2467: $? = 0 +configure:2493: result: +configure:2499: checking for suffix of object files +configure:2525: gcc -c conftest.c >&5 +configure:2529: $? = 0 +configure:2554: result: o +configure:2558: checking whether we are using the GNU C compiler +configure:2587: gcc -c conftest.c >&5 +configure:2594: $? = 0 +configure:2611: result: yes +configure:2620: checking whether gcc accepts -g +configure:2650: gcc -c -g conftest.c >&5 +configure:2657: $? = 0 +configure:2758: result: yes +configure:2775: checking for gcc option to accept ISO C89 +configure:2849: gcc -c -g -O2 conftest.c >&5 +configure:2856: $? = 0 +configure:2879: result: none needed +configure:2898: checking for inline +configure:2924: gcc -c -g -O2 conftest.c >&5 +configure:2931: $? = 0 +configure:2949: result: inline +configure:3017: checking for gcc +configure:3044: result: gcc +configure:3276: checking for C compiler version +configure:3284: gcc --version >&5 gcc (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -configure:3287: $? = 0 -configure:3294: gcc -v >&5 +configure:3288: $? = 0 +configure:3295: gcc -v >&5 Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic Thread model: posix gcc version 4.3.3 (GCC) -configure:3298: $? = 0 -configure:3305: gcc -V >&5 +configure:3299: $? = 0 +configure:3306: gcc -V >&5 gcc: '-V' option must have argument -configure:3309: $? = 1 -configure:3312: checking whether we are using the GNU C compiler -configure:3365: result: yes -configure:3374: checking whether gcc accepts -g -configure:3512: result: yes -configure:3529: checking for gcc option to accept ISO C89 -configure:3633: result: none needed -configure:3709: checking for g++ -configure:3725: found /usr/bin/g++ -configure:3736: result: g++ -configure:3763: checking for C++ compiler version -configure:3771: g++ --version >&5 +configure:3310: $? = 1 +configure:3313: checking whether we are using the GNU C compiler +configure:3366: result: yes +configure:3375: checking whether gcc accepts -g +configure:3513: result: yes +configure:3530: checking for gcc option to accept ISO C89 +configure:3634: result: none needed +configure:3710: checking for g++ +configure:3726: found /usr/bin/g++ +configure:3737: result: g++ +configure:3764: checking for C++ compiler version +configure:3772: g++ --version >&5 g++ (GCC) 4.3.3 Copyright (C) 2008 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -configure:3775: $? = 0 -configure:3782: g++ -v >&5 +configure:3776: $? = 0 +configure:3783: g++ -v >&5 Using built-in specs. Target: x86_64-unknown-linux-gnu Configured with: ../configure --prefix=/usr --enable-shared --enable-languages=c,c++,fortran,objc,obj-c++,treelang --enable-threads=posix --mandir=/usr/share/man --infodir=/usr/share/info --enable-__cxa_atexit --disable-multilib --libdir=/usr/lib --libexecdir=/usr/lib --enable-clocale=gnu --disable-libstdcxx-pch --with-tune=generic Thread model: posix gcc version 4.3.3 (GCC) -configure:3786: $? = 0 -configure:3793: g++ -V >&5 +configure:3787: $? = 0 +configure:3794: g++ -V >&5 g++: '-V' option must have argument -configure:3797: $? = 1 -configure:3800: checking whether we are using the GNU C++ compiler -configure:3829: g++ -c conftest.cpp >&5 -configure:3836: $? = 0 -configure:3853: result: yes -configure:3862: checking whether g++ accepts -g -configure:3892: g++ -c -g conftest.cpp >&5 -configure:3899: $? = 0 -configure:4000: result: yes -configure:4037: checking for a BSD-compatible install -configure:4105: result: /bin/install -c -configure:4121: checking whether the compiler is gcc 4 or greater -configure:4142: result: yes -configure:4154: checking for __func__ -configure:4179: gcc -c -g -O2 conftest.c >&5 -configure:4186: $? = 0 -configure:4201: result: yes -configure:4275: checking how to run the C preprocessor -configure:4315: gcc -E conftest.c -configure:4322: $? = 0 -configure:4353: gcc -E conftest.c +configure:3798: $? = 1 +configure:3801: checking whether we are using the GNU C++ compiler +configure:3830: g++ -c -O0 conftest.cpp >&5 +configure:3837: $? = 0 +configure:3854: result: yes +configure:3863: checking whether g++ accepts -g +configure:3893: g++ -c -g conftest.cpp >&5 +configure:3900: $? = 0 +configure:4001: result: yes +configure:4038: checking for a BSD-compatible install +configure:4106: result: /bin/install -c +configure:4122: checking whether the compiler is gcc 4 or greater +configure:4143: result: yes +configure:4155: checking for __func__ +configure:4180: gcc -c -g -O2 conftest.c >&5 +configure:4187: $? = 0 +configure:4202: result: yes +configure:4276: checking how to run the C preprocessor +configure:4316: gcc -E conftest.c +configure:4323: $? = 0 +configure:4354: gcc -E conftest.c conftest.c:8:28: error: ac_nonexistent.h: No such file or directory -configure:4360: $? = 1 +configure:4361: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -183,12 +183,12 @@ configure: failed program was: | #define PACKAGE_BUGREPORT "" | /* end confdefs.h. */ | #include -configure:4393: result: gcc -E -configure:4422: gcc -E conftest.c -configure:4429: $? = 0 -configure:4460: gcc -E conftest.c +configure:4394: result: gcc -E +configure:4423: gcc -E conftest.c +configure:4430: $? = 0 +configure:4461: gcc -E conftest.c conftest.c:8:28: error: ac_nonexistent.h: No such file or directory -configure:4467: $? = 1 +configure:4468: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -198,78 +198,78 @@ configure: failed program was: | #define PACKAGE_BUGREPORT "" | /* end confdefs.h. */ | #include -configure:4507: checking for grep that handles long lines and -e -configure:4567: result: /bin/grep -configure:4572: checking for egrep -configure:4636: result: /bin/grep -E -configure:4641: checking for ANSI C header files -configure:4671: gcc -c -g -O2 conftest.c >&5 -configure:4678: $? = 0 -configure:4777: gcc -o conftest -g -O2 conftest.c >&5 -configure:4781: $? = 0 -configure:4787: ./conftest -configure:4791: $? = 0 -configure:4809: result: yes -configure:4833: checking for sys/types.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for sys/stat.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for stdlib.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for string.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for memory.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for strings.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for inttypes.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for stdint.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4833: checking for unistd.h -configure:4854: gcc -c -g -O2 conftest.c >&5 -configure:4861: $? = 0 -configure:4878: result: yes -configure:4910: checking pwd.h usability -configure:4927: gcc -c -g -O2 conftest.c >&5 -configure:4934: $? = 0 -configure:4948: result: yes -configure:4952: checking pwd.h presence -configure:4967: gcc -E conftest.c -configure:4974: $? = 0 -configure:4988: result: yes -configure:5016: checking for pwd.h -configure:5025: result: yes -configure:4910: checking termios.h usability -configure:4927: gcc -c -g -O2 conftest.c >&5 -configure:4934: $? = 0 -configure:4948: result: yes -configure:4952: checking termios.h presence -configure:4967: gcc -E conftest.c -configure:4974: $? = 0 -configure:4988: result: yes -configure:5016: checking for termios.h -configure:5025: result: yes -configure:4910: checking sys/sockio.h usability -configure:4927: gcc -c -g -O2 conftest.c >&5 +configure:4508: checking for grep that handles long lines and -e +configure:4568: result: /bin/grep +configure:4573: checking for egrep +configure:4637: result: /bin/grep -E +configure:4642: checking for ANSI C header files +configure:4672: gcc -c -g -O2 conftest.c >&5 +configure:4679: $? = 0 +configure:4778: gcc -o conftest -g -O2 conftest.c >&5 +configure:4782: $? = 0 +configure:4788: ./conftest +configure:4792: $? = 0 +configure:4810: result: yes +configure:4834: checking for sys/types.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for sys/stat.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for stdlib.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for string.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for memory.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for strings.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for inttypes.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for stdint.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4834: checking for unistd.h +configure:4855: gcc -c -g -O2 conftest.c >&5 +configure:4862: $? = 0 +configure:4879: result: yes +configure:4911: checking pwd.h usability +configure:4928: gcc -c -g -O2 conftest.c >&5 +configure:4935: $? = 0 +configure:4949: result: yes +configure:4953: checking pwd.h presence +configure:4968: gcc -E conftest.c +configure:4975: $? = 0 +configure:4989: result: yes +configure:5017: checking for pwd.h +configure:5026: result: yes +configure:4911: checking termios.h usability +configure:4928: gcc -c -g -O2 conftest.c >&5 +configure:4935: $? = 0 +configure:4949: result: yes +configure:4953: checking termios.h presence +configure:4968: gcc -E conftest.c +configure:4975: $? = 0 +configure:4989: result: yes +configure:5017: checking for termios.h +configure:5026: result: yes +configure:4911: checking sys/sockio.h usability +configure:4928: gcc -c -g -O2 conftest.c >&5 conftest.c:53:24: error: sys/sockio.h: No such file or directory -configure:4934: $? = 1 +configure:4935: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -324,11 +324,11 @@ configure: failed program was: | # include | #endif | #include -configure:4948: result: no -configure:4952: checking sys/sockio.h presence -configure:4967: gcc -E conftest.c +configure:4949: result: no +configure:4953: checking sys/sockio.h presence +configure:4968: gcc -E conftest.c conftest.c:20:24: error: sys/sockio.h: No such file or directory -configure:4974: $? = 1 +configure:4975: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -350,22 +350,22 @@ configure: failed program was: | #define HAVE_TERMIOS_H 1 | /* end confdefs.h. */ | #include -configure:4988: result: no -configure:5016: checking for sys/sockio.h -configure:5025: result: no -configure:5041: checking for library containing setsockopt -configure:5082: gcc -o conftest -g -O2 conftest.c >&5 -configure:5089: $? = 0 -configure:5120: result: none required -configure:5128: checking for library containing gethostbyname -configure:5169: gcc -o conftest -g -O2 conftest.c >&5 -configure:5176: $? = 0 -configure:5207: result: none required -configure:5218: checking if sockaddr{} has sa_len member -configure:5246: gcc -c -g -O2 conftest.c >&5 +configure:4989: result: no +configure:5017: checking for sys/sockio.h +configure:5026: result: no +configure:5042: checking for library containing setsockopt +configure:5083: gcc -o conftest -g -O2 conftest.c >&5 +configure:5090: $? = 0 +configure:5121: result: none required +configure:5129: checking for library containing gethostbyname +configure:5170: gcc -o conftest -g -O2 conftest.c >&5 +configure:5177: $? = 0 +configure:5208: result: none required +configure:5219: checking if sockaddr{} has sa_len member +configure:5247: gcc -c -g -O2 conftest.c >&5 conftest.c: In function 'main': conftest.c:26: error: 'struct sockaddr' has no member named 'sa_len' -configure:5253: $? = 1 +configure:5254: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -396,11 +396,11 @@ configure: failed program was: | ; | return 0; | } -configure:5268: result: no -configure:5279: checking whether byte ordering is bigendian -configure:5304: gcc -c -g -O2 conftest.c >&5 +configure:5269: result: no +configure:5280: checking whether byte ordering is bigendian +configure:5305: gcc -c -g -O2 conftest.c >&5 conftest.c:21: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'a' -configure:5311: $? = 1 +configure:5312: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -426,15 +426,15 @@ configure: failed program was: | #endif | typedef int dummy; | -configure:5361: gcc -c -g -O2 conftest.c >&5 -configure:5368: $? = 0 -configure:5400: gcc -c -g -O2 conftest.c >&5 +configure:5362: gcc -c -g -O2 conftest.c >&5 +configure:5369: $? = 0 +configure:5401: gcc -c -g -O2 conftest.c >&5 conftest.c: In function 'main': conftest.c:27: error: 'not' undeclared (first use in this function) conftest.c:27: error: (Each undeclared identifier is reported only once conftest.c:27: error: for each function it appears in.) conftest.c:27: error: expected ';' before 'big' -configure:5407: $? = 1 +configure:5408: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -468,12 +468,12 @@ configure: failed program was: | ; | return 0; | } -configure:5659: result: no -configure:5685: checking if struct in_addr is a wacky huge structure (some Sun boxes) -configure:5709: gcc -c -g -O2 conftest.c >&5 +configure:5660: result: no +configure:5686: checking if struct in_addr is a wacky huge structure (some Sun boxes) +configure:5710: gcc -c -g -O2 conftest.c >&5 conftest.c: In function 'main': conftest.c:24: error: 'struct in_addr' has no member named '_S_un' -configure:5716: $? = 1 +configure:5717: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -502,10 +502,10 @@ configure: failed program was: | ; | return 0; | } -configure:5755: gcc -c -g -O2 conftest.c >&5 +configure:5756: gcc -c -g -O2 conftest.c >&5 conftest.c: In function 'main': conftest.c:25: error: 'struct in_addr' has no member named 'S_un' -configure:5762: $? = 1 +configure:5763: $? = 1 configure: failed program was: | /* confdefs.h. */ | #define PACKAGE_NAME "" @@ -535,42 +535,12 @@ configure: failed program was: | ; | return 0; | } -configure:5779: result: no -configure:5788: checking if struct icmp exists -configure:5823: gcc -c -g -O2 conftest.c >&5 -conftest.c:25:1: warning: "__USE_BSD" redefined -In file included from /usr/include/sys/types.h:27, - from conftest.c:21: -/usr/include/features.h:265:1: warning: this is the location of the previous definition -conftest.c:27:1: warning: "_BSD_SOURCE" redefined -/usr/include/features.h:176:1: warning: this is the location of the previous definition -configure:5830: $? = 0 -configure:5845: result: yes -configure:5854: checking if struct ip exists -configure:5888: gcc -c -g -O2 conftest.c >&5 -conftest.c:26:1: warning: "__USE_BSD" redefined -In file included from /usr/include/sys/types.h:27, - from conftest.c:22: -/usr/include/features.h:265:1: warning: this is the location of the previous definition -conftest.c:28:1: warning: "_BSD_SOURCE" redefined -/usr/include/features.h:176:1: warning: this is the location of the previous definition -configure:5895: $? = 0 -configure:5910: result: yes -configure:5919: checking if struct ip has ip_sum member -configure:5954: gcc -c -g -O2 conftest.c >&5 -conftest.c:27:1: warning: "__USE_BSD" redefined -In file included from /usr/include/sys/types.h:27, - from conftest.c:23: -/usr/include/features.h:265:1: warning: this is the location of the previous definition -conftest.c:29:1: warning: "_BSD_SOURCE" redefined -/usr/include/features.h:176:1: warning: this is the location of the previous definition -configure:5961: $? = 0 -configure:5976: result: yes -configure:5989: checking for strerror -configure:6045: gcc -o conftest -g -O2 conftest.c >&5 -configure:6052: $? = 0 -configure:6074: result: yes -configure:6266: creating ./config.status +configure:5780: result: no +configure:5794: checking for strerror +configure:5850: gcc -o conftest -g -O2 conftest.c >&5 +configure:5857: $? = 0 +configure:5879: result: yes +configure:6069: creating ./config.status ## ---------------------- ## ## Running config.status. ## @@ -587,13 +557,13 @@ generated by GNU Autoconf 2.63. Invocation command line was on bahamut -config.status:751: creating Makefile -config.status:751: creating ncrack_config.h -config.status:967: ncrack_config.h is unchanged -configure:7474: === configuring in nbase (/home/ithilgore/ncrack/ncrack-working/ncrack/nbase) -configure:7577: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=. -configure:7474: === configuring in nsock/src (/home/ithilgore/ncrack/ncrack-working/ncrack/nsock/src) -configure:7577: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=. +config.status:748: creating Makefile +config.status:748: creating ncrack_config.h +config.status:964: ncrack_config.h is unchanged +configure:7277: === configuring in nbase (/home/ithilgore/ncrack/ncrack-working/ncrack/nbase) +configure:7380: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=. +configure:7277: === configuring in nsock/src (/home/ithilgore/ncrack/ncrack-working/ncrack/nsock/src) +configure:7380: running /bin/sh ./configure --disable-option-checking '--prefix=/usr/local' --cache-file=/dev/null --srcdir=. ## ---------------- ## ## Cache variables. ## @@ -643,7 +613,6 @@ ac_cv_header_sys_types_h=yes ac_cv_header_termios_h=yes ac_cv_header_unistd_h=yes ac_cv_host=x86_64-unknown-linux-gnu -ac_cv_ip_has_ip_sum=yes ac_cv_objext=o ac_cv_path_EGREP='/bin/grep -E' ac_cv_path_GREP=/bin/grep @@ -657,8 +626,6 @@ ac_cv_prog_cxx_g=yes ac_cv_search_gethostbyname='none required' ac_cv_search_setsockopt='none required' ac_cv_sockaddr_has_sa_len=no -ac_cv_struct_icmp_exists=yes -ac_cv_struct_ip_exists=yes ## ----------------- ## ## Output variables. ## @@ -669,7 +636,7 @@ CFLAGS='-g -O2' CPP='gcc -E' CPPFLAGS=' -Inbase -Insock/include' CXX='g++' -CXXFLAGS='-g -O2 -Wall -fno-strict-aliasing' +CXXFLAGS='-O0 -Wall -fno-strict-aliasing' DEFS='-DHAVE_CONFIG_H' ECHO_C='' ECHO_N='-n' @@ -758,47 +725,6 @@ target_alias='' #define HAVE_UNISTD_H 1 #define HAVE_PWD_H 1 #define HAVE_TERMIOS_H 1 -#define HAVE_STRUCT_ICMP 1 -#define HAVE_STRUCT_IP 1 -#define HAVE_IP_IP_SUM 1 #define HAVE_STRERROR 1 configure: exit 0 - -## ---------------------- ## -## Running config.status. ## -## ---------------------- ## - -This file was extended by config.status, which was -generated by GNU Autoconf 2.63. Invocation command line was - - CONFIG_FILES = - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on bahamut - -config.status:751: creating Makefile -config.status:751: creating ncrack_config.h -config.status:967: ncrack_config.h is unchanged - -## ---------------------- ## -## Running config.status. ## -## ---------------------- ## - -This file was extended by config.status, which was -generated by GNU Autoconf 2.63. Invocation command line was - - CONFIG_FILES = - CONFIG_HEADERS = - CONFIG_LINKS = - CONFIG_COMMANDS = - $ ./config.status - -on bahamut - -config.status:751: creating Makefile -config.status:751: creating ncrack_config.h -config.status:967: ncrack_config.h is unchanged diff --git a/config.status b/config.status index b02d8c0c..c8517dd5 100755 --- a/config.status +++ b/config.status @@ -537,7 +537,7 @@ S["INSTALL_DATA"]="${INSTALL} -m 644" S["INSTALL_SCRIPT"]="${INSTALL}" S["INSTALL_PROGRAM"]="${INSTALL}" S["ac_ct_CXX"]="g++" -S["CXXFLAGS"]="-g -O2 -Wall -fno-strict-aliasing" +S["CXXFLAGS"]="-O0 -Wall -fno-strict-aliasing" S["CXX"]="g++" S["OBJEXT"]="o" S["EXEEXT"]="" @@ -651,9 +651,6 @@ D["HAVE_STDINT_H"]=" 1" D["HAVE_UNISTD_H"]=" 1" D["HAVE_PWD_H"]=" 1" D["HAVE_TERMIOS_H"]=" 1" -D["HAVE_STRUCT_ICMP"]=" 1" -D["HAVE_STRUCT_IP"]=" 1" -D["HAVE_IP_IP_SUM"]=" 1" D["HAVE_STRERROR"]=" 1" for (key in D) D_is_set[key] = 1 FS = "" diff --git a/configure b/configure index a12f7fae..883eda24 100755 --- a/configure +++ b/configure @@ -1808,6 +1808,7 @@ ac_compiler_gnu=$ac_cv_c_compiler_gnu +CXXFLAGS="-O0" LIBPCAP_LIBS="-lpcap" LIBSSL_LIBS="-lssl" @@ -4131,14 +4132,14 @@ else our_gcc="$ac_cv_prog_CC" fi - nmap_gcc_major_version=0 + ncrack_gcc_major_version=0 case `$our_gcc --version | sed -e 's,\..*,.,' -e q` in *4.) - nmap_gcc_major_version=4 + ncrack_gcc_major_version=4 ;; esac - if test 4 -ge $nmap_gcc_major_version; then + if test 4 -ge $ncrack_gcc_major_version; then { $as_echo "$as_me:$LINENO: result: yes" >&5 $as_echo "yes" >&6; } CXXFLAGS="$CXXFLAGS -fno-strict-aliasing" @@ -5785,202 +5786,6 @@ fi rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -{ $as_echo "$as_me:$LINENO: checking if struct icmp exists" >&5 -$as_echo_n "checking if struct icmp exists... " >&6; } -if test "${ac_cv_struct_icmp_exists+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include - #include -int -main () -{ -unsigned int i = sizeof(struct icmp) - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_struct_icmp_exists=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_struct_icmp_exists=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_struct_icmp_exists" >&5 -$as_echo "$ac_cv_struct_icmp_exists" >&6; } -if test $ac_cv_struct_icmp_exists = yes ; then - cat >>confdefs.h <<\_ACEOF -#define HAVE_STRUCT_ICMP 1 -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking if struct ip exists" >&5 -$as_echo_n "checking if struct ip exists... " >&6; } -if test "${ac_cv_struct_ip_exists+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include -int -main () -{ -unsigned int i = sizeof(struct ip) - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_struct_ip_exists=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_struct_ip_exists=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_struct_ip_exists" >&5 -$as_echo "$ac_cv_struct_ip_exists" >&6; } -if test $ac_cv_struct_ip_exists = yes ; then - cat >>confdefs.h <<\_ACEOF -#define HAVE_STRUCT_IP 1 -_ACEOF - -fi - -{ $as_echo "$as_me:$LINENO: checking if struct ip has ip_sum member" >&5 -$as_echo_n "checking if struct ip has ip_sum member... " >&6; } -if test "${ac_cv_ip_has_ip_sum+set}" = set; then - $as_echo_n "(cached) " >&6 -else - cat >conftest.$ac_ext <<_ACEOF -/* confdefs.h. */ -_ACEOF -cat confdefs.h >>conftest.$ac_ext -cat >>conftest.$ac_ext <<_ACEOF -/* end confdefs.h. */ - - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include - #include -int -main () -{ -unsigned int i = sizeof(((struct ip *)0)->ip_sum) - ; - return 0; -} -_ACEOF -rm -f conftest.$ac_objext -if { (ac_try="$ac_compile" -case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:$LINENO: $ac_try_echo\"" -$as_echo "$ac_try_echo") >&5 - (eval "$ac_compile") 2>conftest.er1 - ac_status=$? - grep -v '^ *+' conftest.er1 >conftest.err - rm -f conftest.er1 - cat conftest.err >&5 - $as_echo "$as_me:$LINENO: \$? = $ac_status" >&5 - (exit $ac_status); } && { - test -z "$ac_c_werror_flag" || - test ! -s conftest.err - } && test -s conftest.$ac_objext; then - ac_cv_ip_has_ip_sum=yes -else - $as_echo "$as_me: failed program was:" >&5 -sed 's/^/| /' conftest.$ac_ext >&5 - - ac_cv_ip_has_ip_sum=no -fi - -rm -f core conftest.err conftest.$ac_objext conftest.$ac_ext -fi -{ $as_echo "$as_me:$LINENO: result: $ac_cv_ip_has_ip_sum" >&5 -$as_echo "$ac_cv_ip_has_ip_sum" >&6; } -if test $ac_cv_ip_has_ip_sum = yes ; then - cat >>confdefs.h <<\_ACEOF -#define HAVE_IP_IP_SUM 1 -_ACEOF - -fi for ac_func in strerror @@ -6087,8 +5892,6 @@ RECVFROM_ARG6_TYPE - - # NBASE # Check whether --with-libnbase was given. diff --git a/configure.ac b/configure.ac index 22173ed1..21503254 100644 --- a/configure.ac +++ b/configure.ac @@ -5,6 +5,7 @@ dnl Process this file with autoconf to produce a configure script. AC_INIT(ncrack.cc) +CXXFLAGS="-O0" LIBPCAP_LIBS="-lpcap" LIBSSL_LIBS="-lssl" @@ -63,14 +64,14 @@ else our_gcc="$ac_cv_prog_CC" fi - nmap_gcc_major_version=0 + ncrack_gcc_major_version=0 case `$our_gcc --version | sed -e 's,\..*,.,' -e q` in *4.) - nmap_gcc_major_version=4 + ncrack_gcc_major_version=4 ;; esac - if test 4 -ge $nmap_gcc_major_version; then + if test 4 -ge $ncrack_gcc_major_version; then AC_MSG_RESULT([yes]) CXXFLAGS="$CXXFLAGS -fno-strict-aliasing" else @@ -143,58 +144,6 @@ AC_TRY_COMPILE([#include ], struct in_addr i; i._S_un._S_addr;, \ AC_MSG_RESULT(yes) , \ AC_MSG_RESULT(no);)) -AC_CACHE_CHECK(if struct icmp exists, ac_cv_struct_icmp_exists, - AC_TRY_COMPILE([ - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include - #include ], - [unsigned int i = sizeof(struct icmp)], - ac_cv_struct_icmp_exists=yes, - ac_cv_struct_icmp_exists=no)) -if test $ac_cv_struct_icmp_exists = yes ; then - AC_DEFINE(HAVE_STRUCT_ICMP) -fi - -AC_CACHE_CHECK(if struct ip exists, ac_cv_struct_ip_exists, - AC_TRY_COMPILE([ - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include ], - [unsigned int i = sizeof(struct ip)], - ac_cv_struct_ip_exists=yes, - ac_cv_struct_ip_exists=no)) -if test $ac_cv_struct_ip_exists = yes ; then - AC_DEFINE(HAVE_STRUCT_IP) -fi - -AC_CACHE_CHECK(if struct ip has ip_sum member, ac_cv_ip_has_ip_sum, - AC_TRY_COMPILE([ - #include - #include - #include - #include - #define __USE_BSD - #define __FAVOR_BSD - #define _BSD_SOURCE - #include - #include ], - [unsigned int i = sizeof(((struct ip *)0)->ip_sum)], - ac_cv_ip_has_ip_sum=yes, - ac_cv_ip_has_ip_sum=no)) -if test $ac_cv_ip_has_ip_sum = yes ; then - AC_DEFINE(HAVE_IP_IP_SUM) -fi dnl Checks for library functions. AC_CHECK_FUNCS(strerror) @@ -202,8 +151,6 @@ RECVFROM_ARG6_TYPE - - # NBASE AC_ARG_WITH(libnbase, AC_HELP_STRING([--with-libnbase=DIR], [Look for nbase include/libs in DIR]), diff --git a/nbase/config.log b/nbase/config.log index 3483a3ef..68aa451d 100644 --- a/nbase/config.log +++ b/nbase/config.log @@ -804,7 +804,7 @@ configure:5046: $? = 0 configure:5064: result: yes configure:4984: checking for asnprintf configure:5040: gcc -o conftest -g -O2 -Wall conftest.c >&5 -/tmp/ccCi20qk.o: In function `main': +/tmp/cc0X0iKQ.o: In function `main': /home/ithilgore/ncrack/ncrack-working/ncrack/nbase/conftest.c:82: undefined reference to `asnprintf' collect2: ld returned 1 exit status configure:5046: $? = 1 @@ -901,7 +901,7 @@ configure:5046: $? = 0 configure:5064: result: yes configure:4984: checking for vasnprintf configure:5040: gcc -o conftest -g -O2 -Wall conftest.c >&5 -/tmp/cc8yPJtz.o: In function `main': +/tmp/ccEIzM86.o: In function `main': /home/ithilgore/ncrack/ncrack-working/ncrack/nbase/conftest.c:83: undefined reference to `vasnprintf' collect2: ld returned 1 exit status configure:5046: $? = 1 diff --git a/ncrack.cc b/ncrack.cc index 8ef0f2fe..575aa369 100644 --- a/ncrack.cc +++ b/ncrack.cc @@ -6,6 +6,7 @@ #include "nsock.h" #include "global_structures.h" +#include extern NcrackOps o; using namespace std; @@ -19,7 +20,7 @@ void ncrack_connect_handler(nsock_pool nsp, nsock_event nse, void *mydata); void ncrack_module_end(nsock_pool nsp, nsock_iod nsi, void *mydata); static void printusage(void); - +static char *grab_next_host_spec(FILE *inputfd, int argc, char **argv); static void @@ -27,7 +28,7 @@ printusage(void) { printf("%s %s ( %s )\n" "Usage: ncrack [service name/port] [Options] {target specification}\n" - "TARGET SPECIFICATION:\n" + "TARGET SPECIFICATION:\n" " Can pass hostnames, IP addresses, networks, etc.\n" " Ex: scanme.nmap.org, microsoft.com/24, 192.168.0.1; 10.0.0-255.1-254\n" " -iL : Input from list of hosts/networks\n" @@ -53,11 +54,11 @@ printusage(void) void ncrack_module_end(nsock_pool nsp, nsock_iod nsi, void *mydata) { - m_data *mdata = (m_data *) mydata; - - if (mdata->attempts < mdata->max_attempts) { - call_module(mdata); - } + m_data *mdata = (m_data *) mydata; + + if (mdata->attempts < mdata->max_attempts) { + call_module(mdata); + } } @@ -123,13 +124,44 @@ ncrack_connect_handler(nsock_pool nsp, nsock_event nse, void *mydata) } + + +static char * +grab_next_host_spec(FILE *inputfd, int argc, char **argv) { + static char host_spec[1024]; + unsigned int host_spec_index; + int ch; + + if (!inputfd) { + return( (optind < argc)? argv[optind++] : NULL); + } else { + host_spec_index = 0; + while((ch = getc(inputfd)) != EOF) { + if (ch == ' ' || ch == '\r' || ch == '\n' || ch == '\t' || ch == '\0') { + if (host_spec_index == 0) + continue; + host_spec[host_spec_index] = '\0'; + return host_spec; + } else if (host_spec_index < sizeof(host_spec) / sizeof(char) -1) { + host_spec[host_spec_index++] = (char) ch; + } else fatal("One of the host_specifications from your input file" + "is too long (> %d chars)", (int) sizeof(host_spec)); + } + host_spec[host_spec_index] = '\0'; + } + if (!*host_spec) + return NULL; + return host_spec; +} + + int main(int argc, char **argv) { - socklen_t addrlen; struct in_addr target; uint16_t port; struct sockaddr_in taddr; struct timeval now; + FILE *inputfd = NULL; /* exclude-specific variables */ FILE *excludefd = NULL; @@ -163,6 +195,7 @@ int main(int argc, char **argv) {"min-parallelism", required_argument, 0, 0}, {"excludefile", required_argument, 0, 0}, {"exclude", required_argument, 0, 0}, + {"iL", required_argument, 0, 'i'}, {"max_hostgroup", required_argument, 0, 0}, {"max-hostgroup", required_argument, 0, 0}, {"min_hostgroup", required_argument, 0, 0}, @@ -176,11 +209,12 @@ int main(int argc, char **argv) {0, 0, 0, 0} }; - + if (argc < 2) + printusage(); /* Argument parsing */ optind = 1; - while((arg = getopt_long_only(argc, argv, "p:hvV", long_options, &option_index)) != EOF) { + while((arg = getopt_long_only(argc, argv, "hd::i:p:vV", long_options, &option_index)) != EOF) { switch(arg) { case 0: if (strcmp(long_options[option_index].name, "excludefile") == 0) { @@ -195,38 +229,56 @@ int main(int argc, char **argv) exclude_spec = strdup(optarg); } break; + case 'd': + if (optarg) + o.debugging = o.verbose = atoi(optarg); + else + o.debugging++; o.verbose++; + break; + case 'h': /* help */ + printusage(); + break; + case 'i': + if (inputfd) + fatal("Only one input filename allowed"); + if (!strcmp(optarg, "-")) + inputfd = stdin; + else { + inputfd = fopen(optarg, "r"); + if (!inputfd) + fatal("Failed to open input file %s for reading", optarg); + } + break; case 'p': /* service port */ port = atoi(optarg); break; case 'V': printf("\n%s version %s ( %s )\n", NCRACK_NAME, NCRACK_VERSION, NCRACK_URL); break; - case 'h': /* help */ - printusage(); + case 'v': + o.verbose++; break; case '?': /* error */ - (void) fprintf(stderr, "option inconsistency: -%c\n", optopt); + fprintf(stderr, "option inconsistency: -%c\n", optopt); printusage(); - } } - o.setaf(AF_INET); - - - - - //if (argc - optind <= 0 || argc - optind > 2) - // printusage(); - + o.setaf(AF_INET); + char **host_exp_group; + HostGroupState *hstate; + Target *currenths; + int num_host_exp_groups; + char *host_spec = NULL; + vector Targets; /* lets load our exclude list */ if ((NULL != excludefd) || (NULL != exclude_spec)) { exclude_group = load_exclude(excludefd, exclude_spec); - //if (o.debugging > 3) + if (o.debugging > 3) dumpExclude(exclude_group); if ((FILE *)NULL != excludefd) @@ -237,6 +289,62 @@ int main(int argc, char **argv) + host_exp_group = (char **) safe_malloc(o.max_group_size * sizeof(char *)); + num_host_exp_groups = 0; + + o.max_group_size = 4096; + unsigned int ideal_scan_group_size = o.max_group_size; + + hstate = new HostGroupState(o.max_group_size, host_exp_group, num_host_exp_groups); + + + do { + while(Targets.size() < ideal_scan_group_size) { + currenths = nexthost(hstate, exclude_group); + if (!currenths) { + /* Try to refill with any remaining expressions */ + /* First free the old ones */ + for(int i = 0; i < num_host_exp_groups; i++) + free(host_exp_group[i]); + + num_host_exp_groups = 0; + /* Now grab any new expressions */ + while(num_host_exp_groups < o.max_group_size && + (host_spec = grab_next_host_spec(inputfd, argc, argv))) { + // For purposes of random scan - TODO: see this + host_exp_group[num_host_exp_groups++] = strdup(host_spec); + } + + if (num_host_exp_groups == 0) + break; + delete hstate; + hstate = new HostGroupState(o.max_group_size, host_exp_group, num_host_exp_groups); + + /* Try one last time -- with new expressions */ + currenths = nexthost(hstate, exclude_group); + if (!currenths) + break; + } + Targets.push_back(currenths); + } + + if (Targets.size() == 0) + break; + + for (unsigned int i = 0; i < Targets.size(); i++) { + printf("%s\n", Targets[i]->NameIP()); + } + + /* Free all of the Targets */ + while(!Targets.empty()) { + currenths = Targets.back(); + delete currenths; + Targets.pop_back(); + } + + } while (1); + + exit(-1); @@ -247,37 +355,37 @@ int main(int argc, char **argv) - if (!inet_pton(AF_INET, argv[optind], &target)) - fatal("inet_pton\n"); - // BEGIN MAIN + if (!inet_pton(AF_INET, argv[optind], &target)) + fatal("inet_pton\n"); + // BEGIN MAIN - /* create nsock p00l */ - if (!(nsp = nsp_new(NULL))) - fatal("Can't create nsock pool.\n"); + /* create nsock p00l */ + if (!(nsp = nsp_new(NULL))) + fatal("Can't create nsock pool.\n"); - gettimeofday(&now, NULL); - nsp_settrace(nsp, tracelevel, &now); + gettimeofday(&now, NULL); + nsp_settrace(nsp, tracelevel, &now); - if ((tcp_nsi = nsi_new(nsp, NULL)) == NULL) - fatal("Failed to create new nsock_iod. QUITTING.\n"); + if ((tcp_nsi = nsi_new(nsp, NULL)) == NULL) + fatal("Failed to create new nsock_iod. QUITTING.\n"); - taddr.sin_family = AF_INET; - taddr.sin_addr = target; - taddr.sin_port = port; + taddr.sin_family = AF_INET; + taddr.sin_addr = target; + taddr.sin_port = port; - memset(&mdata, 0, sizeof(mdata)); - mdata.nsp = nsp; - mdata.nsi = tcp_nsi; - mdata.max_attempts = 4; + memset(&mdata, 0, sizeof(mdata)); + mdata.nsp = nsp; + mdata.nsi = tcp_nsi; + mdata.max_attempts = 4; - ev = nsock_connect_tcp(nsp, tcp_nsi, ncrack_connect_handler, 10000, &mdata, - (struct sockaddr *) &taddr, sizeof taddr, port); + ev = nsock_connect_tcp(nsp, tcp_nsi, ncrack_connect_handler, 10000, &mdata, + (struct sockaddr *) &taddr, sizeof taddr, port); - /* nsock loop */ - loopret = nsock_loop(nsp, -1); + /* nsock loop */ + loopret = nsock_loop(nsp, -1); - printf("nsock_loop returned %d\n", loopret); + printf("nsock_loop returned %d\n", loopret); - return 0; - } + return 0; +} diff --git a/ncrack_config.h b/ncrack_config.h index 45e895c4..8d53bfdf 100644 --- a/ncrack_config.h +++ b/ncrack_config.h @@ -96,13 +96,13 @@ /* #undef PCAP_TIMEOUT_IGNORED */ -#define HAVE_STRUCT_IP 1 +/* #undef HAVE_STRUCT_IP */ /* #undef HAVE_NANOSLEEP */ -#define HAVE_STRUCT_ICMP 1 +/* #undef HAVE_STRUCT_ICMP */ -#define HAVE_IP_IP_SUM 1 +/* #undef HAVE_IP_IP_SUM */ /* #undef inline */ diff --git a/targets.cc b/targets.cc index c2a03269..dace0a96 100644 --- a/targets.cc +++ b/targets.cc @@ -362,15 +362,12 @@ int dumpExclude(TargetGroup *exclude_group) { } -Target *nexthost(HostGroupState *hs, TargetGroup *exclude_group, - struct scan_lists *ports, int pingtype) { +Target * +nexthost(HostGroupState *hs, TargetGroup *exclude_group) +{ int hidx = 0; - int i; struct sockaddr_storage ss; size_t sslen; - uint32_t ifbuf[200] ; - struct timeval now; - if (hs->next_batch_no < hs->current_batch_sz) { /* Woop! This is easy -- we just pass back the next host struct */ @@ -409,11 +406,8 @@ Target *nexthost(HostGroupState *hs, TargetGroup *exclude_group, } else break; } while(1); -batchfull: - if (hs->current_batch_sz == 0) return NULL; - return hs->hostbatch[hs->next_batch_no++]; } diff --git a/targets.h b/targets.h index ec8f30de..297bb915 100644 --- a/targets.h +++ b/targets.h @@ -117,8 +117,7 @@ class HostGroupState; /* Ports is the list of ports the user asked to be scanned (0 terminated), you can just pass NULL (it is only a stupid optimization that needs it) */ -Target *nexthost(HostGroupState *hs, TargetGroup *exclude_group, - struct scan_lists *ports, int pingtype); +Target *nexthost(HostGroupState *hs, TargetGroup *exclude_group); /* loads an exclude file into a excluded target list */ TargetGroup* load_exclude(FILE *fExclude, char *szExclude); /* a debugging routine to dump an exclude list to stdout. */