본문 바로가기
Security/OverTheWire

Bandit Level 18 → Level 19 (쉘 스크립트 우회)

by curious week 2025. 12. 1.

문제

The password for the next level is stored in a file readme in the homedirectory. Unfortunately, someone has modified .bashrc to log you out when you log in with SSH.

## 문제 요구사항
정상 경로로는 로그인하면 바로 로그아웃됨.
ssh 접속으로는 readme를 읽을 수 없으므로 로컬에서 읽어와야함.

## 내가 사용한 명령어
1.
ssh bandit18@bandit.labs.overthewire.org -p 2220 /bin/sh
cat readme

2.
ssh bandit18@bandit.labs.overthewire.org -p 2220 "bash -c 'cat readme'"

## 왜 이 명령어를 골랐는가
1. ssh bandit18@bandit.labs.overthewire.org -p 2220 /bin/sh
SSH 접속 후 기본 쉘(bash) 대신 /bin/sh를 바로 실행
/bin/sh는 .bashrc를 읽지 않음. 따라서 튕기지 않음

2. ssh bandit18@bandit.labs.overthewire.org -p 2220 "bash -c 'cat readme'"
“로그인 → 명령 하나 수행 → 종료” 구조라 bash가 문제의 .bashrc를 실행할 타이밍이 없음
interactive bash가 아니라 non-interactive command bash로 실행되기 때문에 .bashrc를 읽지 않는다

## 어떤 시행착오를 겪었는가
bandit.labs.overthewire.org의 다른 호스트에서 간접적으로 접근하려고 했지만 룰 때문에 실패했다.

방법 1. 다른 쉘 이용

방법 2. 문자열을 바로 실행