Skip to content
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

Improves handling of dying SMB and SQL sessions #18960

Conversation

cgranleese-r7
Copy link
Contributor

@cgranleese-r7 cgranleese-r7 commented Mar 13, 2024

Note

This PR is in conjunction with a PR in ruby_smb . This PR will need to be landed before the framework PR.

This PR improves the handling of dying SMB and SQL sessions. Previously when a session was killed, then interacting with it would return errors but not exit the session. Now the session will close as expected.

MSSQL

image

SMB

image

Targets for testing

PostgreSQL

Docker command:

docker run -it -p 5432:5432 -e POSTGRES_PASSWORD=password postgres:16.1

Module commands:

use postgres_login
run rhost=127.0.0.1 rport=5432 username=postgres password=password database=template1 createsession=true

MSSQL

Docker command:

docker run -e "ACCEPT_EULA=Y" -e "MSSQL_SA_PASSWORD=MyMSSQLServerPassword__<>" -p 1433:1433 mcr.microsoft.com/mssql/server:2022-preview-ubuntu-22.04

Module commands:

use mssql_login
run rhost=127.0.0.1 rport=1433 username=sa password=MyMSSQLServerPassword__<> use_windows_authent=false createsession=true

MySQL

Docker command:

MariaDB:

docker run -it --rm -e MYSQL_ROOT_PASSWORD='password' -p 4306:3306 mariadb:11.2.2

MySQL:

docker run -it --rm -e MYSQL_ROOT_PASSWORD='password' -p 3306:3306 mysql:8.3.0

Module commands:

MariaDB:

use mysql_login
run rhost=127.0.0.1 rport=4306 username=root password=password createsession=true

MySQL

use mysql_login
run rhost=127.0.0.1 rport=3306 username=root password=password createsession=true

Verification

  • Start msfconsole
  • Run use smb_login, use mysql_login, use mssql_login, use postgres_login
  • Run sessions -i -1
  • Run a remote command (query/share interactions)
  • Kill the session - restart docker container or disconnect VM network adapter
  • Verify when running the same command the session now exits

@cgranleese-r7 cgranleese-r7 added the rn-enhancement release notes enhancement label Mar 13, 2024
@cgranleese-r7 cgranleese-r7 force-pushed the improves-handling-of-dying-smb-and-sql-sessions branch from 0da6866 to 8690dc2 Compare March 13, 2024 13:53
@cgranleese-r7 cgranleese-r7 marked this pull request as draft March 14, 2024 13:46
@cgranleese-r7 cgranleese-r7 force-pushed the improves-handling-of-dying-smb-and-sql-sessions branch from 8690dc2 to a1a9055 Compare March 15, 2024 11:56
@cgranleese-r7 cgranleese-r7 force-pushed the improves-handling-of-dying-smb-and-sql-sessions branch from a1a9055 to 9975fcd Compare March 19, 2024 13:15
@cgranleese-r7 cgranleese-r7 marked this pull request as ready for review March 19, 2024 15:32
@cgranleese-r7 cgranleese-r7 force-pushed the improves-handling-of-dying-smb-and-sql-sessions branch 2 times, most recently from 33ad5f6 to 91a73f6 Compare March 20, 2024 14:13
@cgranleese-r7 cgranleese-r7 force-pushed the improves-handling-of-dying-smb-and-sql-sessions branch from 91a73f6 to 961a072 Compare March 20, 2024 14:16
@adfoster-r7
Copy link
Contributor

adfoster-r7 commented Mar 20, 2024

sql

msf6 auxiliary(scanner/mysql/mysql_login) > sessions -i -1
[*] Starting interaction with 3...

mysql @ 127.0.0.1:3306 () > query select 1
[-] Query has failed. Reasons: Lost connection to server during query

[*] 127.0.0.1 - MySQL session 3 closed.  Reason: User exit
msf6 auxiliary(scanner/mysql/mysql_login) > 

smb (Better, but still not perfect 😄)

msf6 auxiliary(scanner/smb/smb_login) > sessions -i -1
[*] Starting interaction with 4...

SMB (192.168.123.133) > shares

[-] Error running command shares: RubySMB::Error::CommunicationError Communication error with the remote host: Read timeout expired when reading from the Socket (timeout=30). The server supports encryption and this error may have been caused by encryption issues, but not always.

[*] 192.168.123.133 - SMB session 4 closed.  Reason: Died
SMB (192.168.123.133) > 

postgres

msf6 auxiliary(scanner/postgres/postgres_login) > sessions

Active sessions
===============

  Id  Name  Type        Information                           Connection
  --  ----  ----        -----------                           ----------
  5         postgresql  PostgreSQL postgres @ 127.0.0.1:9000  127.0.0.1:55125 -> 127.0.0.1:9000 (127.0.0.1)

msf6 auxiliary(scanner/postgres/postgres_login) > sessions -i -1
[*] Starting interaction with 5...

postgresql @ 127.0.0.1:9000 (template1) > query select 1;
[-] Query has failed. Reasons: EOFError

[*] 127.0.0.1 - PostgreSQL session 5 closed.  Reason: Died

mssql

smsf6 auxiliary(scanner/mssql/mssql_login) > sessions -i -1
[*] Starting interaction with 6...

mssql @ 127.0.0.1:1433 (master) > query_interactive
[*] Starting interactive SQL shell for mssql @ 127.0.0.1:1433 (master)
[*] SQL commands ending with ; will be executed on the remote server. Use the exit command to exit.

SQL >> select 123;

[*] Executing query: select 123;
[-] Query has failed. Reasons: EOFError

[*] 127.0.0.1 - MSSQL session 6 closed.  Reason: Died
mssql @ 127.0.0.1:1433 (master) > 
msf6 auxiliary(scanner/mssql/mssql_login) >

@adfoster-r7 adfoster-r7 merged commit d4cb976 into rapid7:master Mar 20, 2024
51 checks passed
@adfoster-r7
Copy link
Contributor

Release Notes

This PR improves the handling of dying SMB and SQL sessions. Previously when a session was killed, then interacting with it would return errors but not exit the session. Now the session will close as expected.

@cgranleese-r7 cgranleese-r7 deleted the improves-handling-of-dying-smb-and-sql-sessions branch March 20, 2024 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rn-enhancement release notes enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants