Advanced Netcat Commands

Update to post “Netcat Commands – https://kevindicks.co.uk/blog/2017/08/14/netcat-commands/

File transfer between client/server
Server:
#cat file.pdf | nc -l -p 1234

Client:
#nc localhost 1234 > file.pdf

Web server
Server:
#(echo -e “HTTP/1.0 200 Ok”; echo “My HTTP server”;) | nc -q 1 -l -p 8080
Browse to the location – http://localhost:8080

Execute program
Server:
#nc -l -p 123 -e /bin/bash

Client:
#nc <server_ip> 123
#whoami
#pwd

Netcat Commands

connect to somewhere: nc [-options] hostname port[s] [ports] …
listen for inbound: nc -l -p port [-options] [hostname] [port]

Options:
-c shell commands – as `-e’; use /bin/sh to exec [dangerous!!]
-e filename – program to exec after connect [dangerous!!]
-b – allow broadcasts
-g gateway -source-routing hop point[s], up to 8
-G num – source-routing pointer: 4, 8, 12, …
-h – this cruft
-i secs – delay interval for lines sent, ports scanned
-k – set keepalive option on socket
-l – listen mode, for inbound connects
-n – numeric-only IP addresses, no DNS
-o file – hex dump of traffic
-p port – local port number
-r – randomize local and remote ports
-q secs – quit after EOF on stdin and delay of secs
-s addr – local source address
-T tos – set Type Of Service
-t – answer TELNET negotiation
-u – UDP mode
-v – verbose [use twice to be more verbose]
-w secs – timeout for connects and final net reads
-C – Send CRLF as line-ending
-z – zero-I/O mode [used for scanning]

Port numbers can be individual or ranges: lo-hi [inclusive]

Hyphens in port names must be backslash escaped (e.g. ‘ftp\-data’)

Note that Netcat sends/receives data in cleartext. For encrypted data, replace command “nc” with cryptcat”.

Raspberry Pi 3 Setup (Raspbian)

Requirements:

  • Raspberry Pi 3
  • MicroSD card
  • HDMI cable
  • USB keyboard
  • Raspberry Pi 3 case (optional)

Connect USB keyboard, HDMI cable and power supply cable in to Raspberry Pi

Download Raspberry Pi Raspbian or NOOBS O/S (if not pre-installed on MicroSD card) – https://www.raspberrypi.org/downloads/

Format MicroSD card on PC using Etcher – https://etcher.io/ (Raspbian OS used for example)

Remove MicroSD card from PC and insert in to Raspberry Pi

Connect power supply to mains socket to boot the Raspberry Pi (boot process will be displayed to connected HDMI monitor)

Once Raspberry Pi has successfully booted and the login prompt is displayed, input the following credentials to authenticate:

Username: pi
Password: raspberry

To access root account, it must be configured by issuing command – sudo passwd root

Notes
To validate Raspberry Pi operational status, run the following commands to check for any issues:

Check boot logs – cat/var/log/boot.log <syslog/debug> (for system or debugging log)

List processes – ps aux

Check system logs – cat /var/log/messages (append “| tail -10” switch for last 10 log entries)

Basic Vim Commands

Vim has two modes:

1. Insert mode (Where you can just type like normal text editor. Press i for insert mode)

2. Command mode (Where you give commands to the editor to get things done . Press ESC for command mode):

x – to delete the unwanted character

u – to undo the last the command and U to undo the whole line

CTRL-R to redo

A – to append text at the end

:wq – to save and exit

:q! – to trash all changes

dw – move the cursor to the beginning of the word to delete that word

2w – to move the cursor two words forward

3e – to move the cursor to the end of the third word forward

0 (zero) to move to the start of the line

d2w – which deletes 2 words .. number can be changed for deleting the number of consecutive words like d3w

dd  – to delete the line

2dd – to delete to line number. Can be changed for deleting the number of consecutive words

p – puts the previously deleted text after the cursor(Type dd to delete the line and store it in a Vim register. and p to put the line)

r – to replace the letter e.g press re to replace the letter with e

ce – to change until the end of a word (place the cursor on the u in lubw it will delete ubw)

ce – deletes the word and places you in Insert mode

G – to move you to the bottom of the file

gg – to move you to the start of the file. Type the number of the line you were on and then G

% – to find a matching ), ], or }

:s/old/new/g to substitute ‘new’ for ‘old’ where g is globally

/ backward search n to find the next occurrence and N to search in opposite direction

? forward search

:! to run the shell commands like :!dir, :!ls

:w – TEST (where TEST is the filename you chose.) . Save the file

v – starts visual mode for selecting the lines and you can perform operation on that like d delete

:r – Filename will insert the content into the current file

R – to replace more than one character

y – operator to copy text using v visual mode and p to paste it

yw – (copy)yanks one word

o – opens a line below the cursor and start Insert mode

O – opens a line above the cursor

a – inserts text after the cursor

A – inserts text after the end of the line

e – command moves to the end of a word

y – operator yanks (copies) text, p puts (pastes) it

R – enters Replace mode until <ESC> is pressed

ctrl-w – to jump from one window to another