> For the complete documentation index, see [llms.txt](https://meowsec.gitbook.io/w1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://meowsec.gitbook.io/w1/tryhackme/thmw/linux-local-enumeration.md).

# Linux: Local Enumeration

This room from [tryHackMe](https://tryhackme.com/room/lle) describes some technique to enumerate and escalate privilege after getting a shell in a Linux machine.&#x20;

Target website shows the way to connect and get a reverse shell:&#x20;

![](/files/-Mb1smj1e9skb2QhwGlr)

### Unit 1: tty

Reverse shell -&#x20;

* netcat shell can be broken often
* stable shell is needed
* Some commands like  **`su`** and **`ssh`** needs proper terminal to run
* Python one liner for a stable shell: **`python3 -c 'import pty; pty.spawn("/bin/bash")'`**
* Upgrading shell to interactive shell: [blog post](https://blog.ropnop.com/upgrading-simple-shells-to-fully-interactive-ttys)
* Curated list of privesc command: [GTFOBins](https://gtfobins.github.io/)

The command from GTFOBins gives us shell but as we want to execute bash, we need to modify it: **`perl -e 'exec "/bin/sh";'`**

![](/files/-Mb1twP9VtxI6dE1qMw4)

### Unit 1: ssh

SSH -&#x20;

* SSH can give us stable reverse connection
* Usually located in **`.ssh`** file
* If I get the private key, **`id_rsa`** :
  * Download it to my own machine
  * Give permission: **`chmod 600`**
  * Connect ssh: **`ssh -i id_rsa [user]@[IP]`**
* If private key isn't there or inaccessible:
  * Generate own ssh key in attacker machine: **`ssh-keygen`**
  * Copy the **`id_rsa.pub`** to the target machine's **`authorized_keys`** file. This file will be inside the **`.ssh`** file
  * Connect ssh from attacker machine using own **`id_rsa`** file

![](/files/-Mb1yM8pX-pBYmcPq7mr)

### Unit 2: Basic enumeration

Quick methodology -&#x20;

* get system info: **`uname -a`**&#x20;
* User command history can be here: **`.bash_history`**
* These two file contains shell command that run when bash executed: **`.bash_profile`** and **`.bashrc`**
* Check sudo version: **`sudo -v`**
* User list with sudo access: **`sudo -l`**

![](/files/-Mb26bX_e2eAX4Z87BMS)

### Unit 3: /etc

/etc/passwd file -&#x20;

* This file contains essential information
* Format of /passwd file -&#x20;

![](/files/-Mb29yv-FsPhyy5rQ-9X)

/etc/shadow file -

* This file contains hashed password&#x20;

/etc/hosts file -&#x20;

* This file assigns hostname to IP address

![](/files/-Mb2BB14XPzCrQ9lVxH_)

### Unit 4: Find command

Find command -&#x20;

* Most important switch : **`-type`** and **`-name`**
* Look for interesting log (.log) and configuration (.conf) file. There can be a backup (.bak) file too

Task -&#x20;

* Found password in backup file: **`find -type f -name "*.bak" 2>/dev/null`**
* Found flag in a .conf file: **`find -type f -name "*.conf" 2>/dev/null`**

![](/files/-Mb2N-HmjtUc___cjH3H)

### Unit 4: SUID

SUID bit -&#x20;

* If this bit is set, anyone can run the file with the owner level access
* Find command: find / -type f -perm -u=s 2>/dev/null
* GTFOBins shows good payload for grep

![](/files/-Mb2Ptqvf0EWl4cL6C_4)

### Unit 5:

SSH tunnelling -&#x20;

* Three types of ssh tunnel (with example):
  * Forward tunnel: this will connect from office to home using a ssh tunnel
  * Reverse tunnel: this tunnel will connect from home to office
  * Dynamic tunnel: this will use sock proxy and divert all traffic to specified address
* Explained video: [YouTube](https://youtu.be/AtuAdk4MwWw)

SSH tunnelling **command** -&#x20;

* Forward tunnel : map port from remote machine/network to local machine

```
ssh -L $LOCAL_PORT:$REMOTE_IP:$REMOTE_PORT $USER@$SERVER
```

* Reverse tunnel : make local port accessible to remote machine

```
ssh -R $REMOTE_PORT:$LOCAL_IP:$LOCAL_PORT $USER@$SERVER
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://meowsec.gitbook.io/w1/tryhackme/thmw/linux-local-enumeration.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
