OverTheWire/bandit

Bandit Level 5 → Level 6

보름달빵 2025. 1. 11. 00:29

📌 문제

 

찾는 비밀번호는 inhere 디렉터리 아래의 어떤 파일에 저장되어있다. 그리고 그 파일은 아래의 특징들을 전부가지고 있는 파일이다. 

  • human-readable
  • 1033 bytes in size
  • not executable

 

 

📌 풀이

 

이 문제는 특정한 조건을 가지고 있는 파일을 찾는 문제이다. 

 

 

find 명령어: find [경로] [표현식 1] [표현식 2] ...

 

먼저 find 명령어의 옵션들을 이용하여 조건에 맞는 파일들을 검색한다. 

  • '-type f'로 일반 파일을 검색한 후 grep 명령어를 이용해 파일의 확장자가 .text인 파일을 다시 찾는다. 
  • '-size 1033c'로 1033 바이트 크기의 파일을 찾는다. 
  • '! -executable'로 실행 가능하지 않은 파일을 찾는다.

 

$ find inhere -type f -size 1033c ! -executable -exec file {} + | grep text
find inhere -type f -size 1033c ! -executable -exec file {} \; | grep text

 

 

 -exec  {} \; 와 -exec  {} + 의 차이점 

 

위의 두 명령어의 차이점은 첫번째의 경우, 조건에 따라 검색된 여러개의 파일에 대하여 명령이 각각 한번씩 수행된다는 점이다. 

반대로 두번째 + 명령어를 사용하면, 찾아낸 여러개의 파일을 하나로 생각하여 명령이 한번만 수행된다. 

 

 

실행결과

bandit5@bandit:~/inhere$ find -type f -size 1033c ! -executable -exec file {} \; | grep text
./maybehere07/.file2: ASCII text, with very long lines (1000)

bandit5@bandit:~/inhere$ find -type f -size 1033c ! -executable -exec file {} + | grep text
./maybehere07/.file2: ASCII text, with very long lines (1000)

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

 

 

이제 파일의 내용을 읽고 정답을 제출해주면 된다. 

 

 

 

📌 정리

조건에 맞는 파일을 검색하고 싶다면 find 명령어를 사용하자

 

 

 

 

 

 

📌 참고자료 

 

find 명령어 옵션들 

https://m.blog.naver.com/tmk0429/222301447297


find 옵션으로 실행가능한 파일인지 아닌지 확인하는 방법 

https://stackoverflow.com/questions/70539901/how-can-i-find-all-non-executable-files-in-a-directory-in-linux

https://stackoverflow.com/questions/4458120/search-for-executable-files-using-find-command