리눅스/bandit

[bandit] bandit5 -> bandit6

해공학(해킹을 공부하는 학생) 2023. 4. 23. 09:22

우선 overthewire 페이지를 해석 해보겠습니다.

"inhere 폴더안에 사람이 읽을수 있고 파일의 크기가 1033bytes인 파일안에 비번이 있어" 라고 말하고 있습니다.

첫번째로, 진짜 bandit5안에 inhere 폴더가 있는지 ls명령어로 확인해 보겠습니다.

bandit5@bandit:~$ ls
inhere

이런식으로 inhere 폴더가 있습니다. 

두번째로 cd명령어로 inhere 폴더로 들어가고, inhere 폴더안에 어떤 파일이 있는지 확인해 보겠습니다.

bandit5@bandit:~$ cd inhere
bandit5@bandit:~/inhere$ ls
maybehere00  maybehere04  maybehere08  maybehere12  maybehere16
maybehere01  maybehere05  maybehere09  maybehere13  maybehere17
maybehere02  maybehere06  maybehere10  maybehere14  maybehere18
maybehere03  maybehere07  maybehere11  maybehere15  maybehere19

inhere 폴더안에는 19개의 폴더가 있습니다. 그중 maybehere00으로 한번들어가 보겠습니다.

bandit5@bandit:~/inhere$ cd maybehere00
bandit5@bandit:~/inhere/maybehere00$ ls
-file1  -file2  -file3  spaces file1  spaces file2  spaces file3

이런식으로, 이 bandit5의 구조를 설명하면 inhere 폴더안에는 19개의 폴더가 있고, 그안에 또 파일이 있습니다. 

근데 저희 한테는 고맙게도 주어진 조건이 있죠? 사람이 읽을수 있는 파일을 찾는거랑 크기가 1033byte 인 파일을 찾는것,

그중 저는 크기가 1033byte 인 파일찾는 방법으로 찾겠습니다. 

그 크기가 1033byte 인 파일을 찾으려면 find 명령어를 알아야 합니다. 

 

find

find는 파일 시스템에서 파일과 폴더를 찾을 때 사용됩니다.

이 find 명령어를 쓰는 구조는 배웠던거랑은 조금 다른데...

find [경로] [옵션] [조건] 이런식으로 쓰입니다.

 

find 경로,옵션,조건 설명 :

  • [경로]: 찾을 파일 또는 디렉토리가 있는 위치를 지정합니다. 생략할 경우 현재 디렉토리에서 시작합니다.
  • [옵션]: 명령 실행에 대한 옵션을 설정합니다.
    • -name [파일명]: 지정한 파일명과 일치하는 파일을 찾습니다.
    • -type [타입]: 지정한 파일 타입과 일치하는 파일을 찾습니다. 타입에는 f (일반 파일), d (디렉토리), l (심볼릭 링크), c (문자 장치 파일), b (블록 장치 파일) 등이 있습니다.
    • -mtime [시간]: 지정한 시간 이전에 수정된 파일을 찾습니다. 시간은 일(day) 단위로 지정하며, + 또는 - 기호를 사용하여 현재 시간을 기준으로 이전(-) 또는 이후(+)의 파일을 찾을 수 있습니다.
  • [조건]: 찾을 파일 또는 디렉토리에 대한 추가적인 조건을 지정합니다.

본론으로 돌아가겠습니다.

 

그럼 find를 이용해서 옵션은 -size 이고, 크기는 1033byte 이니까 리눅스 사용법에 따라

find -size 1033c 이런식으로 하겠습니다. (이 c는 나중에 설명하겠습니다.)

bandit5@bandit:~/inhere$ find -size 1033c
./maybehere07/.file2

이런식으로 뜨네요 그럼 cat을 통해 읽겠습니다.

bandit5@bandit:~/inhere$ cat ./maybehere07/.file2
P4L4vucdmLnm8I7Vl7jG1ApGSfjYKqJU

잘 되네요. 비번은 P4L4vucdmLnm8I7Vl7jG1ApGSfjYKqJU 입니다.

 

쓴 코드 :

bandit5@bandit:~$ ls
inhere
bandit5@bandit:~$ cd inhere/
bandit5@bandit:~/inhere$ ls
maybehere00  maybehere04  maybehere08  maybehere12  maybehere16
maybehere01  maybehere05  maybehere09  maybehere13  maybehere17
maybehere02  maybehere06  maybehere10  maybehere14  maybehere18
maybehere03  maybehere07  maybehere11  maybehere15  maybehere19
bandit5@bandit:~/inhere$ cd maybehere00
bandit5@bandit:~/inhere/maybehere00$ ls
-file1  -file2  -file3  spaces file1  spaces file2  spaces file3
bandit5@bandit:~/inhere/maybehere00$ cd ../
bandit5@bandit:~/inhere$ find -size 1033c
./maybehere07/.file2
bandit5@bandit:~/inhere$ cat ./maybehere07/.file2
P4L4vucdmLnm8I7Vl7jG1ApGSfjYKqJU

정리 

find 명령어는 파일이나 폴더를 찾을때 쓰인다.