Skip to content

New function to retrieve pre-auth server banner - #274

Closed
dmiller-nmap wants to merge 1 commit into
libssh2:masterfrom
dmiller-nmap:userauth_banner
Closed

dmiller-nmap wants to merge 1 commit into
libssh2:masterfrom
dmiller-nmap:userauth_banner

Conversation

@dmiller-nmap

Copy link
Copy Markdown

This is currently working privately to collect SSH_MSG_USERAUTH_BANNER contents via a NSE script for Nmap.

Reference: RFC 4252, section 5.4

@dmiller-nmap

Copy link
Copy Markdown
Author

I had to guess on an upper safe limit for how much memory to allocate for this banner (LIBSSH2_USERAUTH_MAX_BANNER), since we obviously shouldn't just trust the server not to spoof a huge number (4-byte length = 4.3GB). US Dept of Defense standard warning banner is probably about the longest you'll see at 1484 bytes, so 2KB is probably plenty.

@sbredahl

Copy link
Copy Markdown
Contributor

That could prove useful, thanks!

@MOJNICK

MOJNICK commented Feb 13, 2019

Copy link
Copy Markdown

I think this functionality should be moved from userauth_list() and added to every authentication method (password, publickey, hostbased) instead. btw. is the do-while necessary?

@dmiller-nmap

Copy link
Copy Markdown
Author

It would be nice to be able to have the banner available no matter what auth was attempted, since the spec says:

The SSH server may send an SSH_MSG_USERAUTH_BANNER message at any
time after this authentication protocol starts and before
authentication is successful.

I chose to implement it most simply as part of userauth_list since that's a common way that SSH clients open a connection. I don't know if putting it into every userauth attempt would have made the change more difficult to review (it's been a while since I looked at the code now!).

The do/while loop is used in order to handle the possibility of multiple banners sent in one reply, as well as to loop back and grab the next message (userauth success or failure) after the banner. There's probably a better way to do this like dispatching based on the type of message extracted, but this worked at the moment.

Comment thread src/userauth.c
session->userauth_list_state = libssh2_NB_state_idle;
return NULL;
}
if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_BANNER) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not check userauth_list_data_len before accessing first byte of data.

Comment thread src/userauth.c
return NULL;
}
if (session->userauth_list_data[0] == SSH_MSG_USERAUTH_BANNER) {
methods_len = _libssh2_ntohu32(session->userauth_list_data + 1);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does not check to see if length is > 5 before accessing next 4 bytes.

@willco007

Copy link
Copy Markdown
Member

I've added a couple comments to this code. There is a PR coming which resolves both of these issues but you'll need to rebase this feature after that fix is landed.

@stale

stale Bot commented Jun 3, 2019

Copy link
Copy Markdown

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale Bot added the stale label Jun 3, 2019
@stale stale Bot closed this Jun 24, 2019
@thesubtlety

Copy link
Copy Markdown

This feature is just what I'm looking for. Are there any plans to revisit this issue? Thanks!

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants