Hello all, I’m Soumyanil,(also Reveng/Reveng007 in social media). Today, I’m gonna walk you through a Tryhackme room, Ninja Skills.
In this room, I actually used ‘find’ command and it is the thing that is emphasized the most in this room. OK, Without further delay lets jump right in!!
Answer the questions about the following files:
8V2L
bny0
c4ZX
D8B3
FHl1
oiMO
PFbD
rmfX
SRSq
uqyw
v2Vb
X1Uy
The aim is to answer the questions as efficiently as possible.
1. Which of the above files are owned by the best-group group(enter the answer separated by spaces in alphabetical order)
[new-user@ip-10-10-88-51 ~]$ find / -group best-group 2> /dev/null
2. Which of these files contain an IP address?
For this problem, let's create a bash script…
#!/bin/bash
file_names='8V2L c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy bny0' # All the filename
for name in $file_names
do
direc=$(find / -type f -name $name 2>/dev/null)
grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" $direc && echo $direc
# |____________________________|
# |_________________ ip extraction
done
It will give us the filename.
3. Which file has the SHA1 hash of 9d54da7584015647ba052173b84d45e8007eba94 ?
For this challenge also, I have created a bash script…
I think to handle problems like this best way is to make automating scripts.
#!/bin/bash
file_names='8V2L c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy bny0' # filenames
hash=9d54da7584015647ba052173b84d45e8007eba94 # hash provided
COUNTER=0
for name in $file_names
do
direc=$(find / -type f -name $name 2>/dev/null)#finding file
Grepped=$(grep $hash $direc)# extracting hash from file
if [[ ${10#Grepped} -gt ${10#hash}]]
#checking:hash(provided) = hash(got)
then
echo $direc # If success!!
else
COUNTER=$[COUNTER + 1]
# adding counter to know number of files scanned echo Nope$COUNTER # Nope1 Nope2 ...NopeN
continue
fi
done
This gave me no result ….😕
[new-user@ip-10-10-88-51 ~]$ bash pattern_matching.sh
Nope1
Nope2
Nope3
Nope4
Nope5
Nope6
Nope7
Nope8
Nope9
Nope10
Nope11
^C
[new-user@ip-10-10-88-51 ~]$
I researched a bit on google, that how to pick sha1sum from files along with find command.
#!/bin/bash
hash=9d54da7584015647ba052173b84d45e8007eba94
file_names='8V2L c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy bny0'
COUNTER=0
for name in $file_names
do
value=$(find / -type f -name $name -exec sha1sum {} \; 2>>/dev/null)
# this will produce the output of hash along with file name hashes=$(echo $value | cut -d " " -f 1)
COUNTER=$[COUNTER + 1]
if [[ $hashes == $hash ]]
then
echo $value
else
echo Nope$COUNTER
fi
done
I got this command ➡ -exec sha1sum to use with find to extract sha1 hash from file content.
[new-user@ip-10-10-76-223 ~]$ bash pat.sh
Nope1
9d54da7584015647ba052173b84d45e8007eba94 (REDACTED)
Nope3
Nope4
Nope5
Nope6
Nope7
Nope8
Nope9
Nope10
Nope11
Nope12
Now, We got the result…💯
4. Which file contains 230 lines?
#!/bin/bash
file_names='8V2L bny0 c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy'
for name in $file_names
do
direc=$(find / -type f -name $name 2>/dev/null)
echo $direc
done
But for some reason “bny0” didn’t show up…
#!/bin/bash
file_names='8V2L bny0 c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy'
for name in $file_names
do
direc=$(find / -type f -name $name 2>/dev/null)
value=$(wc -l $direc | cut -d " " -f 1)
# counting lines and then parsing the line and storing the 1st portion =>number of lines if [[ $value -gt 230 ]]
# checking number of lines are equal or not
then
echo $direc
fi
done
Even when I tried to run this script, it didn’t show up anything.
So I made another script (aiming for inverting the logic )
That means: Which will not be shown as output in the terminal are to be considered as the answer and also transferred “bny0” to last in the list to avoid confusion. As whenever the interpreter comes to this word, it gets stuck.
#!/bin/bash
file_names='8V2L c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy bny0'
for name in $file_names
do
direc=$(find / -type f -name $name 2>/dev/null)
wc -l $direc
done
OUTPUT:
[new-user@ip-10-10-88-51 ~]$ bash pattern_matching.sh
209 /etc/8V2L
209 /mnt/c4ZX
209 /mnt/D8B3
209 /var/FHl1
209 /opt/oiMO
209 /opt/PFbD
209 /media/rmfX
209 /etc/ssh/SRSq
209 /var/log/uqyw
209 /home/v2Vb
209 /X1Uy
^C
[new-user@ip-10-10-88-51 ~]$
So, the answer is: You know what am I going to say 😎…
5. Which file’s owner has an ID of 502?
[new-user@ip-10-10-88-51 home]$ grep '502' /etc/passwd
-----> [owner]
[new-user@ip-10-10-88-51 home]$ find / -user [owner] 2> /dev/null
-----> [file]
6. Which file is executable by everyone?
#!/bin/bash
file_names='8V2L bny0 c4ZX D8B3 FHl1 oiMO PFbD rmfX SRSq uqyw v2Vb X1Uy'
for name in $file_names
do
find / -type f -executable -name $name 2> /dev/null
done
NOTE: ‘-executable’ can be used with ‘find’ to find out the files which can be executed by everyone present out there.
So, this is it… We completed all the challenges.
If you liked my content, please share it. If you have any suggestions please let me know on my social media: