Shell

A program used to take user input and pass it on to the OS to perform a certain function/task. Most common one – bash (Bourne Again Shell) – is an enhanced version of the original Unix system’s shell program sh. Others – zsh, tcsh, ksh, Fish shell, etc.

There are three main types of shell connections:

Shell Type Description
Reverse shell Initiates a connection back to a “listener” on our attack box.
Bind shell “Binds” to a specific port on the target host and waits for a connection from our attack box.
Web shell Runs operating system commands via the web browser, typically not interactive or semi-interactive. It can also be used to run single commands (i.e., leveraging a file upload vulnerability and uploading a PHP script to run a single command.

Gaining shell access refers to getting interactive shell-level access on the exploited target.

TCP and UDP

Ports

- https://www.youtube.com/watch?v=g2fT-g9PX9o
- https://www.stationx.net/common-ports-cheat-sheet/
- https://web.archive.org/web/20240315102711/https://packetlife.net/media/library/23/common-ports.pdf
- https://nullsec.us/top-1-000-tcp-and-udp-ports-nmap-default/ Ports are virtual points where network connections begin and end. They are software-based and managed by the host operating system. Ports are associated with a specific process or service and allow computers to differentiate between different traffic types. 

ssh

  1. what is ssh? Secure Shell (SSH) is an excellent tool for securely connecting to a remote machine. It is a network protocol that runs on port 22 by default and provides users such as system administrators a secure way to access a computer remotely. SSH uses a client-server model, connecting a user running an SSH client application such as OpenSSH to an SSH server

  2. how can ssh be configured? – SSH can be configured with password authentication or passwordless using public-key authentication using an SSH public/private key pair.

    if you have the credentials of a user in plaintext, use : ssh username@server – after which you will be prompted for the password of the user. if you get a private ssh key and username, use : ssh '/path/to/private/key/file' username@server

    the server mentioned in the above commands can either be an IP address or a hostname.

Note : It is also possible to read local private keys on a compromised system or add our public key to gain SSH access to a specific user, as we’ll discuss in a later section.

netcat (for windows, unix-like systems)

nc is a tool used to connect to shells. It can be used to connect to any listening port and interact with the service running on that port. For example,
grilledBread@htb[/htb]$ netcat 10.10.10.10 22 SSH-2.0-OpenSSH_8.4p1 Debian-3 Output is a banner which tells us that ssh is running on port 22. This method of collecting information is called banner grabbing.
nc can als9o be used for file transfer.

For Windows systems, an alternative to the nc tool is the PowerCat tool. For unix systems, an alternative to the nc tool is the socat tool – unlike nc, it has features like forwarding ports and connecting to serial devices. Socat can also be used to upgrade a shell to a fully interactive TTY. Shell connections established using socat are more stable.

socat syntax

vim

text editor that can be used for writing code or editing text files on Linux systems. grilledBread@htb[/htb]$ vim /etc/hosts

Command Description
x Cut character
dw Cut word
dd Cut full line
yw Copy word
yy Copy full line
p Paste

We can multiply any command to run multiple times by adding a number before it. For example, ‘4yw’ would copy 4 words instead of one, and so on.

For saving/quitting/naivgating vim, there are several commands we can use:

Command Description
:1 Go to line number 1.
:w Write the file, save
:q Quit
:q! Quit without saving
:wq Write and quit

tmux (Terminal Multiplexer)

Difference between terminal emulators like terminator and tmux?

Imagine a web browser (Terminator):

Use Ctrl+B and then C to open a new tmux window. These windows are indexed at the bottom of the terminal pane. We can switch to each window by hitting the prefix and then inputting the window number, like 0 or 1. We can also split a window vertically into panes by hitting the prefix and then [SHIFT + %]