Study/Security

[워게임] Rcity 11 - SSH 개인키 복호화하기(john)

NOredstone 2023. 11. 28. 15:57

1. 문제 상황

 

 

2. 해결 과정

john 에서 사용하는 워드리스트 파일은 각각 문자열이 줄넘김되어 있어야 john에서 크래킹할 수 있다.
이번 문제에서 wordlist.txt가 줄넘김되어 있지 않아서 계속 실패했었다 ㅠ.ㅠ

 

그리고 더욱 중요한 점!!! 현재 칼리 리눅스에 기본 설치되어 있는 john은 John the Ripper 1.9.0-jumbo-1+bleeding-aec1328d6c 버전인데, 이 버전에 버그가 있어서 정상적으로 SSH 개인키 복호화가 되지 않는다.

 

그래서 다른 버전의 john을 설치하고 진행해야 문제가 풀린다(버그 있는걸 몰라서 시간 많이 소요됨ㅜㅜ)

설치 방법: https://github.com/openwall/john/blob/bleeding-jumbo/doc/INSTALL-UBUNTU

# 원격서버로부터 파일 다운받기 (원격서버에서는 john 사용 불가하여 로컬에서 실행)
scp -P [port_number] -r [username]@[hostname]:/home/rcity11/ /home/kali/wargame/

# 파일 유형 확인
file id_rsa
file wordlist.txt

# wordlist 만들기 - 1
touch sort.py  # 파이썬 코드 작성 (해당 코드는 밑에 있습니다.)
python3 sort.py

# wordlist 만들기 - 2
awk -F ',' '{ for(i=1; i<=NF; i++) print $i }' wordlist.txt | tr -s '\n' > output_file.txt

# ssh 개인 키를 JtR에서 사용할 수 있는 형식으로 변환 (새로 설치한 버전의 JtR 사용!)
ssh2john id_rsa > id_rsa.hash

# 크래킹 및 결과 확인 (새로 설치한 버전의 JtR 사용!)
john --wordlist=output.txt id_rsa.hash
john --show id_rsa.hash

# 얻은 키와 비밀번호로 접속
ssh -i id_rsa [username]@[hostname]

 

 

wordlist 정렬을 위한 파이썬 코드 (그냥 chat gpt 사용하였습니다!)

def process_file(input_file, output_file):
    with open(input_file, 'r') as f:
        lines = f.read().split(',')

    cleaned_lines = [line.strip() for line in lines]

    with open(output_file, 'w') as f:
        f.write('\n'.join(cleaned_lines))

if __name__ == "__main__":
    input_file = input("Enter the input file name: ")
    output_file = input("Enter the output file name: ")

    process_file(input_file, output_file)
    print("File processed successfully!")