Python Forum
Script Conversion 2.7 to 3 (sockets)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Script Conversion 2.7 to 3 (sockets)
#1
Hey all,

I'm trying to convert a script written in python2.7 to python3.
The first hurdle is how byte strings are handled between the two, which I believe I've worked around.

#python3
s.send(packet.encode('utf-8'))
#python2.7
s.send(packet)
The next issue seems to be around the implementation of sockets.

for n in list(enc_protocols.keys()):
    packet = X224_CONNECTION_REQUEST % n
    #TODO: need to convert to bytes-like object here
    print(binascii.hexlify(n.encode('utf-8')))

    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.connect((host, port))
    #s.sendall(packet.encode('utf-8'))
    s.send(packet.encode('utf-8'))
    #s.send(packet)
    response = s.recv(1024)
    #response = s.recv(4096)

    if (response[3] == "\x0b"):
        enc_protocols["\x00"][1] = True
        break
    else:
        if (response[11] == "\x02"):
            enc_protocols[n][1] = True
        else:
            errors[response[15]] = True
    
    #print binascii.hexlify(response)
    
    s.close()
Specifically line 11 above:
response = s.recv(1024)
Throws the error "Traceback (most recent call last):
File "rdp_check_ciphers.py", line 81, in <module>
response = s.recv(1024)
ConnectionResetError: [Errno 104] Connection reset by peer"

I'm just after some pointers as to what is likely the problem if anyone has experienced this sort of issue themselves.

The script I'm looking at is this one: https://labs.mwrinfosecurity.com/tools/r...r-checker/

Thanks in advance,

Pumpernickel
Reply


Messages In This Thread
Script Conversion 2.7 to 3 (sockets) - by Pumpernickel - Apr-10-2019, 10:17 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sockets interferring with USB ? epif18 0 2,741 Mar-19-2021, 07:45 PM
Last Post: epif18
  Just learning sockets etc... floatingshed 2 2,430 May-06-2020, 09:37 PM
Last Post: floatingshed
  Quick sockets question... ptrivino 2 2,332 Sep-26-2019, 08:51 PM
Last Post: ptrivino
  Sockets and Sendmail taintedsushi 2 2,435 Sep-02-2019, 12:51 PM
Last Post: venquessa
  What sort of things can I write to learn about sockets marienbad 2 2,788 Oct-16-2018, 04:02 PM
Last Post: buran
  unix domain sockets Skaperen 8 5,160 Sep-02-2018, 07:02 PM
Last Post: Skaperen
  file transfer with sockets sinister88 1 6,537 Nov-11-2017, 03:29 PM
Last Post: heiner55
  Trouble with sending raw sockets IronReign 2 4,290 Jun-01-2017, 08:26 AM
Last Post: camp0
  Silly Sockets Jarvis 2 4,297 Feb-20-2017, 01:43 PM
Last Post: Jarvis

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020