So I'm working on a coding challenge now where I have to send a command over API. It's pretty simple, but I'm struggling to work out how you format it. The challenge is:
# Write a script that connects to 'localhost' port 10000
# You then need to send a command to list the files in the /tmp directory
The code I have so far:
Code:
import os
import socket
#import urllib2
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('127.0.0.1', 10000))
cmd = "os.listdir('/tmp')"
clientsocket.send(cmd)
This produces no output or flag. To complete the challenge i have to
send a command to list the files in the /tmp directory. The flag will be sent when you send the correct command.
I also tried this code:
Code:
import os
import socket
#import urllib2
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('127.0.0.1', 10000))
cmd = os.listdir("/tmp")
clientsocket.send(cmd)
but the output error is:
Traceback (most recent call last):
File "/tmp/usercode.py", line 12, in <module>
clientsocket.send(cmd)
TypeError: send() argument 1 must be string or buffer, not list
I understand this error, but don't know how to fix it. How do i send a command over API socket in order to list the files in a directory? Thanks