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

# Linux Ninja Skills - TryHackMe

#### Room Link : [Ninja Skills ](https://tryhackme.com/room/ninjaskills)

<figure><img src="https://images.unsplash.com/photo-1640552435388-a54879e72b28?crop=entropy&#x26;cs=srgb&#x26;fm=jpg&#x26;ixid=M3wxOTcwMjR8MHwxfHNlYXJjaHw1fHxsaW51eHxlbnwwfHx8fDE2OTg3NzA3ODd8MA&#x26;ixlib=rb-4.0.3&#x26;q=85" alt=""><figcaption><p>Sharpen your ninja skills on linux</p></figcaption></figure>

## Initial Access

SSH Credentials

```bash
username: new-user
password: new-user
```

## Preparation

First get the list of files that are available to us

```bash
cd files && touch thm-files.txt
## copy and paste the file names into something like, thm-files.txt
```

The list should look something like this

```bash
8V2L
bny0
c4ZX
D8B3
FHl1
oiMO
PFbD
rmfX
SRSq
uqyw
v2Vb
X1Uy
```

Next get the paths of the files which we can later use for reference purpose

```bash
cat thm-files.txt | while IFS= read line; do find / -name "$line" -type f 2>/dev/null; done | tee files.txt
```

## Tasks

#### Question 1 : Which of the above files are owned by the best-group group(enter the answer separated by spaces in alphabetical order)

```bash
cat files.txt | while IFS= read line; do ls -laSh $line; done | grep "best-group"
```

#### Question 2 : Which of these files contain an IP address?

```bash
# Get the IP address along with the file name
cat files.txt| while IFS= read -r line; do grep -E -o '([0-9]{1,3}\.){3}[0-9]{1,3}' "$line" 2>/dev/null && echo "$line"; done
```

#### Question 3 : Which file has the SHA1 hash of 9d54da7584015647ba052173b84d45e8007eba94 ?

```bash
cat files.txt | while IFS= read -r line; do sha1sum $line; done | grep "9d54da7584015647ba052173b84d45e8007eba94"
```

#### Question 4 : Which file contains 230 lines?

```bash
cat files.txt | awk -F/ '{print $NF}' | sort -u > a.txt
cat thm-files.txt | sort -u > b.txt
diff a.txt b.txt
## the one file that is missing is marked with >
```

#### Question 5 : Which file's owner has an ID of 502?

```bash
cat files.txt | while IFS= read -r line; do ls -ln $line; done
# check the 3rd column which has all the IDs
# -rw-rw-r-- 1 502 501 14K Oct 23  2019
```

#### Question 6: Which file is executable by everyone?

```bash
cat files.txt | while IFS= read -r line; do ls -ln $line; done
### Look for -rwxrwxr-x 
```

Thank You for reading :heart: Happy Hunting :sunglasses:
