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

mssqlclient.py crashes right after connection is made and doesn't say error or anything #1670

Closed
StopCamping opened this issue Dec 26, 2023 · 6 comments · Fixed by #1795
Closed
Assignees
Labels
medium Medium priority item

Comments

@StopCamping
Copy link

StopCamping commented Dec 26, 2023

Configuration

impacket version: impacket-0.12.0.dev1+20231114.165227.4b56c18a-py3.11.egg
Python version: python 3.11
Target OS: Microsoft

mssqlclient.py -windows-auth ARCHETYPE/sql_avc:[email protected] -debug
Impacket v0.12.0.dev1+20231114.165227.4b56c18a - Copyright 2023 Fortra

[+] Impacket Library Installation Path: /usr/local/lib/python3.11/dist-packages/impacket-0.12.0.dev1+20231114.165227.4b56c18a-py3.11.egg/impacket
[*] Encryption required, switching to TLS
                                            
kali@kali:~/impacket/examples$ 

This is the first time I ever do a discussion so I apologies if I don't make sense,
I'm trying to pwn a HTB machine (ARCHETYPE) and so far, I've been stuck with this problem for days, when using mssqlclient.py with the correct syntax and pressing enter, it shows the { [*] Encryption required, switching to TLS } and then goes back to normal terminal which doesn't make any sense.

I've changed the configuration in the tds.py file which was about the TLS configuration, here's what it looks like rn:

 if resp['Encryption'] == TDS_ENCRYPT_REQ or resp['Encryption'] == TDS_ENCRYPT_OFF:
            LOG.info("Encryption required, switching to TLS")

            # Switching to TLS now
            ctx = SSL.Context(SSL.TLSv1_METHO)
            ctx = SSL.Context(SSL.TLSv1_2_METHOD)
            ctx.set_cipher_list('RC4, AES256')
            tls = SSL.Connection(ctx,None)
            tls.set_connect_state()
            while True:
                try:
                    tls.do_handshake()
                except SSL.WantReadError:
                    data = tls.bio_read(4096)
                    self.sendTDS(TDS_PRE_LOGIN, data,0)
                    tds = self.recvTDS()
                    tls.bio_write(tds['Data'])
                else:
                    break

            # SSL and TLS limitation: Secure Socket Layer (SSL) and its replacement,
            # Transport Layer Security(TLS), limit data fragments to 16k in size.
            self.packetSize = 16*1024-1
            self.tlsSocket = tls

Looking at videos and other peoples discussions never talk about this problem, could this be a problem in my device or something in Impacket? I didn't want to skip this pen testing method because I don't want to do things without knowing whats going on so yeah.

one final thing to mention is that I tried entering the password after it connects:

mssqlclient.py -windows-auth ARCHETYPE/[email protected] -debug
Impacket v0.12.0.dev1+20231114.165227.4b56c18a - Copyright 2023 Fortra

[+] Impacket Library Installation Path: /usr/local/lib/python3.11/dist-packages/impacket-0.12.0.dev1+20231114.165227.4b56c18a-py3.11.egg/impacket
Password:
[*] Encryption required, switching to TLS
                                                                                                                                                                                                              
kali@kali:~/impacket/examples$ 

Tell me if there's anything I missed.

@dkjajhqu2h3j
Copy link

I also get this all the time using Impacket main v0.12.0.dev1+20231114.165227.4b56c18a. If I switch to the Impacket version that comes by default in Kali 2023.4, v0.11.0, this works.

@gabrielg5
Copy link
Collaborator

Hi,
linking this issue with #1356, to take into account when analyzing it. In the context of that PR the SSL connection set up has been changed.
however that code is the same both in v0.11 and in current master

@gabrielg5 gabrielg5 added the medium Medium priority item label Jan 4, 2024
@StopCamping
Copy link
Author

Hey, Sorry for replying late, I haven't done any training ever since I made this discussion.
I actually used both v11 and v12, but I had the same response, I was going to show that I get the same response using the pre built version, but when I did, it actually worked, I'm losing my mind, I literally used both version to which never worked and now after all this time, it finally worked when I wanted to proof something.

Thank you again for helping, I actually bamboozled that it worked rn.

@pyrexfm
Copy link

pyrexfm commented Jan 30, 2024

Facing the same issue in Ubuntu. Fixed by downgrading to v0.11

@FoxSca
Copy link

FoxSca commented May 31, 2024

same issue on kali
some suggestion how fix it?
Impacket v0.12.0.dev1 - Copyright 2023 Fortra Password: [*] Encryption required, switching to TLS

@gabrielg5
Copy link
Collaborator

gabrielg5 commented Aug 22, 2024

Hey hello,

Finally found the changeset (72d3d15) and PR (#1617) in the context the change was introduced.
Will be working now in a new PR to better handling both scenarios

Just to validate, this is happening to you only when login fails right? If login goes ok, I'm receiving the SQLShell prompt as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
medium Medium priority item
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants