command-injection-chatgpt

2024. 10. 23. 15:08·DreamHack/WEB

 

 

 

 

 

 

 

 

#!/usr/bin/env python3
import subprocess

from flask import Flask, request, render_template, redirect

from flag import FLAG

APP = Flask(__name__)


@APP.route('/')
def index():
    return render_template('index.html')


@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')


if __name__ == '__main__':
    APP.run(host='0.0.0.0', port=8000)

 

 

        cmd = f'ping -c 3 {host}'

 

 

host를 입력받아 ping을 보내는 cmd 가 있다.

 

실험해 보자.

 

 

 

 

 

 

 

 

 

 

 

 

 

정상 작동되는 걸 볼 수 있다.

 

그러면 AND 연산을 같이 넣어주면 명령어가 실행이 되는지 확인해 보자.

 

 

 

 

 

 

 

 

 

 

 

 

리눅스에서 AND 연산자는 && 를 의미하고 핑을 성공적으로 실행된 경우에 뒤의 명령어인 'ls'가 실행한다.

 

결과를 보면...

 

 

 

 

 

 

바로 나온다.

flag를 보면...

 

 

 

 

 

 

 

잘 나온다.

 

 

 

'DreamHack > WEB' 카테고리의 다른 글

sql injection bypass WAF  (0) 2024.10.29
blind sql injection advanced  (0) 2024.10.23
error based sql injection  (0) 2024.10.18
simple_sqli_chatgpt  (0) 2024.10.17
php-1  (1) 2024.10.16
'DreamHack/WEB' 카테고리의 다른 글
  • sql injection bypass WAF
  • blind sql injection advanced
  • error based sql injection
  • simple_sqli_chatgpt
G_OM
G_OM
최대한 설명 열심히 하려고 합니다. 궁금한 거 있으면 언제든지 물어보셔도 좋습니다.
  • G_OM
    끄적끄적
    G_OM
  • 전체
    오늘
    어제
    • 분류 전체보기 (138)
      • 모의해킹 (7)
      • Wargame (69)
        • Linux_bandit (33)
        • Webhacking.kr (36)
      • DreamHack (52)
        • WEB (14)
        • Reverising (9)
        • System (0)
        • CTF (22)
      • Android_security (5)
      • 정보보안기사 (2)
      • IT? (3)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

    • DreamHack 에 대한 문제들...
  • 인기 글

  • 태그

    리눅스 워게임
    정보보안기사
    Linux
    난독화
    CTF
    webhacking
    워게임
    Linux wargame
    안드로이드
    Cookie
    bandit
    lfi
    Dreamhack
    union
    bandit18
    php
    webhacking.kr
    bandit30
    wargame
    bandit17
    url encode
    sql injection
    bandit20
    리눅스
    php wrapper
    drozer
    Android
    cookies
    insecurebankv2
    overthewire
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
G_OM
command-injection-chatgpt
상단으로

티스토리툴바