New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libssh2 + ssh-brute support #910

Closed
wants to merge 34 commits into
base: master
from

Conversation

Projects
None yet
2 participants
@edeirme

edeirme commented Jun 16, 2017

This pull request is a collaborative effort of Devin Bjelland, Sergey Khegay and me. This request introduces the ssh-brute script and various other ssh scripts.

More specifically this pull request includes the following scripts:
ssh-brute
ssh-run
ssh-auth-methods
ssh-publickey-acceptance

The following libraries have been included:

libssh2 1.8.0
zlib 1.2.8

@edeirme edeirme changed the title from ssh to Libssh2 + ssh-brute support Jun 16, 2017

@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 20, 2017

Can you please clean this up by removing the build directories (Debug_lib and Release_lib) from zlib? This is probably easiest done by adding them to the .gitignore file, as we have done with Debug and Release directories throughout. Generally speaking, we would like to reduce the amount of zlib included as much as is allowable by their license. Removing the contrib directory, the documentation, etc. may be possibilities. The same goes for libssh2.

dmiller-nmap commented Jun 20, 2017

Can you please clean this up by removing the build directories (Debug_lib and Release_lib) from zlib? This is probably easiest done by adding them to the .gitignore file, as we have done with Debug and Release directories throughout. Generally speaking, we would like to reduce the amount of zlib included as much as is allowable by their license. Removing the contrib directory, the documentation, etc. may be possibilities. The same goes for libssh2.

@edeirme

This comment has been minimized.

Show comment
Hide comment
@edeirme

edeirme Jun 20, 2017

Removed a lot of files. We are down from 711 to 382 added/changed files.

From libssh2, the directories docs, examples, test were removed.
From libz, the directories Debug_lib, Release_lib, docs, examples were removed.

The .gitignore file was also updated to include the Debug_lib and Release_lib directories.

I cannot remove the contrib directory of libz since the visual studio files are contained in that directory.

I haven't removed the test directory from libz. The compilation was failing without it. More changes will need to be performed to the library in order to exclude that directory.

edeirme commented Jun 20, 2017

Removed a lot of files. We are down from 711 to 382 added/changed files.

From libssh2, the directories docs, examples, test were removed.
From libz, the directories Debug_lib, Release_lib, docs, examples were removed.

The .gitignore file was also updated to include the Debug_lib and Release_lib directories.

I cannot remove the contrib directory of libz since the visual studio files are contained in that directory.

I haven't removed the test directory from libz. The compilation was failing without it. More changes will need to be performed to the library in order to exclude that directory.

@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 20, 2017

Some findings from the check script:

scripts/ssh-brute.nse:61: Found unrequired NSE library "libssh2".
scripts/ssh-brute.nse:86: Found bad indexed global "methods".
scripts/ssh-brute.nse:85: Found bad set global "methods".
scripts/ssh-publickey-acceptance.nse:69: Found unrequired NSE library "string".
scripts/ssh-publickey-acceptance.nse:56: Found bad indexed global "username".
scripts/ssh-run.nse:78: Found unrequired NSE library "table".

The one about "username" is causing a script crash when I try ssh-publickey-acceptance against localhost with a single username and single public key file. More comments coming soon.

dmiller-nmap commented Jun 20, 2017

Some findings from the check script:

scripts/ssh-brute.nse:61: Found unrequired NSE library "libssh2".
scripts/ssh-brute.nse:86: Found bad indexed global "methods".
scripts/ssh-brute.nse:85: Found bad set global "methods".
scripts/ssh-publickey-acceptance.nse:69: Found unrequired NSE library "string".
scripts/ssh-publickey-acceptance.nse:56: Found bad indexed global "username".
scripts/ssh-run.nse:78: Found unrequired NSE library "table".

The one about "username" is causing a script crash when I try ssh-publickey-acceptance against localhost with a single username and single public key file. More comments coming soon.

Show outdated Hide outdated nse_utility.h Outdated
@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 20, 2017

Can we add library version output for libssh2 and zlib just like we do for openssl, libpcre, etc.? See display_nmap_version in nmap.cc. This will make it easier to check whether different configure options are being respected.

dmiller-nmap commented Jun 20, 2017

Can we add library version output for libssh2 and zlib just like we do for openssl, libpcre, etc.? See display_nmap_version in nmap.cc. This will make it easier to check whether different configure options are being respected.

@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 21, 2017

Compiler warning (LLDB on OS X):

nse_libssh2.cc:733:9: warning: variable 'buf' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    if (lua_isstring(L, 3))
        ^~~~~~~~~~~~~~~~~~
nse_libssh2.cc:738:50: note: uninitialized use occurs here
    while ((rc = libssh2_channel_write(*channel, buf, buflen)) == LIBSSH2_ERROR_EAGAIN) {
                                                 ^~~
./libssh2/include/libssh2.h:819:43: note: expanded from macro 'libssh2_channel_write'
  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
                                          ^
nse_libssh2.cc:733:5: note: remove the 'if' if its condition is always true
    if (lua_isstring(L, 3))
    ^~~~~~~~~~~~~~~~~~~~~~~
nse_libssh2.cc:729:20: note: initialize the variable 'buf' to silence this warning
    const char *buf;
                   ^
                    = NULL
1 warning generated.

EDIT: This is caused because clang doesn't know that luaL_error is not a returning function. You can avoid it by using return luaL_error("...") so that the compiler knows that execution will not continue.

dmiller-nmap commented Jun 21, 2017

Compiler warning (LLDB on OS X):

nse_libssh2.cc:733:9: warning: variable 'buf' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
    if (lua_isstring(L, 3))
        ^~~~~~~~~~~~~~~~~~
nse_libssh2.cc:738:50: note: uninitialized use occurs here
    while ((rc = libssh2_channel_write(*channel, buf, buflen)) == LIBSSH2_ERROR_EAGAIN) {
                                                 ^~~
./libssh2/include/libssh2.h:819:43: note: expanded from macro 'libssh2_channel_write'
  libssh2_channel_write_ex((channel), 0, (buf), (buflen))
                                          ^
nse_libssh2.cc:733:5: note: remove the 'if' if its condition is always true
    if (lua_isstring(L, 3))
    ^~~~~~~~~~~~~~~~~~~~~~~
nse_libssh2.cc:729:20: note: initialize the variable 'buf' to silence this warning
    const char *buf;
                   ^
                    = NULL
1 warning generated.

EDIT: This is caused because clang doesn't know that luaL_error is not a returning function. You can avoid it by using return luaL_error("...") so that the compiler knows that execution will not continue.

@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 21, 2017

Breaks on OS X due to libssh2's configure script ignoring the --with-openssl=X option. Its version is --with-libssl-prefix=X. I found this hack to work OK:

diff --git a/configure.ac b/configure.ac
index 5ba1a04..47e98f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -355,6 +355,7 @@ AC_HELP_STRING([--with-openssl=DIR],[Use optional openssl libs and includes from
     ;;
   *)
     specialssldir="$with_openssl"
+    ac_configure_args="$ac_configure_args '--with-libssl-prefix=$with_openssl'"
     CPPFLAGS="$CPPFLAGS -I$with_openssl/include"
     LDFLAGS="$LDFLAGS -L$with_openssl/lib"
     ;;

and of course run autoconf to regenerate configure.

Of note, this is probably the right solution for nmap/ncrack#1, not making modifications to opensshlib as was done to close that issue.

dmiller-nmap commented Jun 21, 2017

Breaks on OS X due to libssh2's configure script ignoring the --with-openssl=X option. Its version is --with-libssl-prefix=X. I found this hack to work OK:

diff --git a/configure.ac b/configure.ac
index 5ba1a04..47e98f0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -355,6 +355,7 @@ AC_HELP_STRING([--with-openssl=DIR],[Use optional openssl libs and includes from
     ;;
   *)
     specialssldir="$with_openssl"
+    ac_configure_args="$ac_configure_args '--with-libssl-prefix=$with_openssl'"
     CPPFLAGS="$CPPFLAGS -I$with_openssl/include"
     LDFLAGS="$LDFLAGS -L$with_openssl/lib"
     ;;

and of course run autoconf to regenerate configure.

Of note, this is probably the right solution for nmap/ncrack#1, not making modifications to opensshlib as was done to close that issue.

@edeirme

This comment has been minimized.

Show comment
Hide comment
@edeirme

edeirme Jun 21, 2017

Fixed the check script warnings.
Added libssh2 and libz versioning (For some reason, the output is in parenthesis, will investigate later e.g. openssl-1.1.0f libssh2-(1.8.0) libz-(1.2.8) nmap-libpcre-7.6 ).
The compiler warning in LLDB OSX should be gone.
Updated the autoconfig file to support your changes for the OSX build.
Added a small fix for ssh-publickey-acceptance.nse

edeirme commented Jun 21, 2017

Fixed the check script warnings.
Added libssh2 and libz versioning (For some reason, the output is in parenthesis, will investigate later e.g. openssl-1.1.0f libssh2-(1.8.0) libz-(1.2.8) nmap-libpcre-7.6 ).
The compiler warning in LLDB OSX should be gone.
Updated the autoconfig file to support your changes for the OSX build.
Added a small fix for ssh-publickey-acceptance.nse

Show outdated Hide outdated nse_libssh2.cc Outdated
@@ -0,0 +1,120 @@
--

This comment has been minimized.

@dmiller-nmap

dmiller-nmap Jun 23, 2017

This needs to be --- (3 hyphens) in order for this block to be parsed as NSEdoc.

@dmiller-nmap

dmiller-nmap Jun 23, 2017

This needs to be --- (3 hyphens) in order for this block to be parsed as NSEdoc.

This comment has been minimized.

@edeirme
@edeirme

edeirme Jun 25, 2017

Done

Show outdated Hide outdated nselib/libssh2.luadoc Outdated
@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 23, 2017

That's all the comments I have. It would be nice to have trailing whitespace cleaned up and check for proper indentation: https://secwiki.org/w/Nmap/Code_Standards

dmiller-nmap commented Jun 23, 2017

That's all the comments I have. It would be nice to have trailing whitespace cleaned up and check for proper indentation: https://secwiki.org/w/Nmap/Code_Standards

@edeirme

This comment has been minimized.

Show comment
Hide comment
@edeirme

edeirme Jun 25, 2017

Made most of the changes.
Added documentation.
Removed buggy/redundant code.
Used the lua-format scripts for the added lua files.

edeirme commented Jun 25, 2017

Made most of the changes.
Added documentation.
Removed buggy/redundant code.
Used the lua-format scripts for the added lua files.

@dmiller-nmap

This comment has been minimized.

Show comment
Hide comment
@dmiller-nmap

dmiller-nmap Jun 26, 2017

I'm satisfied with this. If your mentor agrees, please merge and commit to SVN.

dmiller-nmap commented Jun 26, 2017

I'm satisfied with this. If your mentor agrees, please merge and commit to SVN.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment