Impacket
psexec.py
ฤiแปu kiแปn sแปญ dแปฅng
Port
445
Credentials
Cleartext hoแบทc hash
Share
Cแบงn writable share
Sแปญ dแปฅng cฦก bแบฃn:
python /usr/share/doc/python3-impacket/examples/psexec.py domain/user:password@IPCฦก chแบฟ hoแบกt ฤแปng
Tรณm tแบฏt: psexec.py sแบฝ sแปญ dแปฅng SMB share ฤแป uplaod RemComSvc, sau ฤรณ dรนng name pipe \svcctl ฤแป remote tแบกo service run RemComSvc binary, RemComSvc sแบฝ tแบกo cรกc name pipe cho phรฉp psexec.py thแปฑc thi cรขu lแปnh
Chi tiแบฟt cฦก chแบฟ hoแบกt ฤแปng cแปงa psexec.py sแบฝ nhฦฐ sau:
ฤแบงu tiรชn thแปฑc hiแปn kแบฟt nแปi SMB vแปi target ฤแป giao tiแบฟp vแปi name pipe \svcctl

Sau ฤรณ tแบกo object installService vร gแปi installService.install()

Ta ฤแป รฝ phแบงn remcomsvc.RemComSvc() chรญnh lร binary cแปงa RecomSvc

Cรฒn phแบงn service name vร remote binary name nแบฟu ta khรดng truyแปn vร o qua cรขu lแปnh thรฌ sแบฝ random nhฦฐ sau

ฤi vร o hร m installService.install() ฤแบงu tiรชn dรนng name pipe \srvsvc ฤแป enum share vร tรฌm writeable share (1), sau ฤรณ copy Recom binary vร o writeable share (2), cuแปi cรนng dรนng SvcManager qua name pipe \svcctl ฤแป tแบกo service vร khแปi chแบกy service

Khi RecomSvc chแบกy sแบฝ tแบกo cรกc name pipe, psexec.py sแบฝ giao tiแบฟp vแปi cรกc name pipe nร y thรดng qua IPC$ share ฤแป thแปฑc thi command tแปซ xa

Cแปฅ thแป RecomSvc hoแบกt ฤแปng nhฦฐ thแบฟ nร o thรฌ mรฌnh sแบฝ khรดng nรณi ฤแบฟn, vรฌ RecomSvc bแป detect bแปi Win defender nรชn thรดng thฦฐแปng khi tรกc chiแบฟn mรฌnh sแบฝ thay thแบฟ bแบฑng binary khรกc (con hร ng nร o ฤรณ bypass ฤฦฐแปฃc AV vร call vแป C2 luรดn)
Kแบฟt quแบฃ khi ta chแบกy thร nh cรดng

Trรชn mรกy victim ta sแบฝ thแบฅy file exe tรชn QIpJyqwh vร service GTew


Dรนng sysinternal handle ta sแบฝ thแบฅy ฤฦฐแปฃc cรกc name pipe cแปงa RemCom ฤang chแบกy trรชn mรกy victim

Vร cuแปi cรนng vรฌ psexec.py chแป kแบฟt nแปi 1 chiแปu ฤแบฟn victim, nรชn cho dรน victim cรณ block out bound TCP chแป cho phรฉp inbound thรฌ ta cลฉng cรณ thแป remote access.
smbexec.py
ฤiแปu kiแปn sแปญ dแปฅng
Port
445
Credentials
Cleartext hoแบทc hash
Share
Khรดng cแบงn writable share (SERVER mode)
Sแปญ dแปฅng cฦก bแบฃn:
smbexec sแบฝ cรณ 2 mode lร SERVER vร SHARE. Mแบทc ฤแปnh sแบฝ dรนng mode SHARE, cรฒn trong trฦฐแปng hแปฃp khรดng cรณ writeable share ta sแบฝ dรนng mode SERVER. Cแปฅ thแป tแปซng mode thรฌ mรฌnh sแบฝ nรณi แป phแบงn cฦก chแบฟ hoแบกt ฤแปng
Cฦก chแบฟ hoแบกt ฤแปng
Tรณm tแบฏt: Vแป cฦก bแบฃn cฦก chแบฟ giแปng nhฦฐ smbexec nhฦฐng khรดng dรนng ฤแบฟn RemComSvc mร sแบฝ thแปฑc thi cmd qua file batch rแปi lฦฐu output แป 1 file khรกc, sau ฤรณ qua SMB share ฤแปc output tแปซ file ฤรณ
Nhรฌn vร o phแบงn description trong code ta cลฉng biแบฟt ฤฦฐแปฃc 1 phแบงn cฦก chแบฟ cแปงa smbexec

Smbexec dแปฑa trรชn kแปน thuแบญt nร y. Lแปฃi dแปฅng \svcctl ฤแป thแปฑc thi cmd bแบฑng remote service rแปi lฦฐu vร o file output. Nแบฟu แป SHARE mode (tแปฉc lร cรณ writeable share) thรฌ sแบฝ write vร ฤแปc output trแปฑc tiแบฟp vร o share trรชn victim. Nแบฟu แป SERVER mode (tแปฉc lร khรดng cรณ writeable share) thรฌ sแบฝ open SMB share แป mรกy attacker ฤแป ฤแปc output. ฤรขy cลฉng chรญnh lร ฤiแปm khรกc biแปt vแปi psexec vร lรฝ do tแบกi sao shell trong smbexec ฤฦฐแปฃc gแปi lร semi-interactive.
Sau khi thแปฑc hiแปn kแบฟt nแปi SMB vแปi victim smbexec.py gแปi ฤแบฟn object RemoteShell

Khi init Object sแบฝ khai bรกo mแปt sแป thรดng tin nhฦฐ sau:

%COMSPEC% lร biแบฟn mรดi trฦฐแปng trแป ฤแบฟn con shell (thฦฐแปng lร cmd). Ta cรณ thแป chแปn shell type lร cmd hoแบทc powershell thรดng qua options -shell-type
Tiแบฟp theo mแปi lแบงn ta gรต command smbexec sแบฝ tแบกo service vแปi binpath nhฦฐ sau

Chแบกy smbexec vแปi options debug ta sแบฝ thแบฅy ฤฦฐแปฃc full HD binpath lร nhฦฐ thแบฟ nร y


Ta sแบฝ thแบฅy smbexec thแปฑc thi command vร lฦฐu output vร o file __output. ฤoแบกn command thแปฑc thi vร lแบฅy output ฤฦฐแปฃc lฦฐu vร o file batch vแปi tรชn random, sau khi file batch thแปฑc thi thรฌ sแบฝ tแปฑ ฤแปng ฤฦฐแปฃc xรณa.
Nแบฟu run แป Share mode thรฌ smbexec sแบฝ ฤแปc output tแปซ file __output vร xรณa file ฤi, cรฒn run แป Server mode thรฌ sแบฝ copy file __output vแป SMB share cแปงa attacker

ฤiแปu nร y dแบซn ฤแบฟn 1 hแบกn chแบฟ nแบฟu attacker run Server mode thรฌ file output sแบฝ tแปn tแบกi ฤแบฟn khi nร o attacker exit session mแปi thรดi

Vแปi cฦก chแบฟ nhฦฐ trรชn thรฌ dแป thแบฅy smbexec bypass ฤฦฐแปฃc trฦฐแปng hแปฃp khรดng cรณ writeable share nhฦฐng lแบกi rแบฅt noise vแปi viแปc create service, xรณa service, create file vร xรณa file liรชn tแปฅc

Ngoร i ra smbexec do khรดng drop RecomSVC mร chแป ghi file batch nรชn sแบฝ bypass ฤฦฐแปฃc WinDef vร mแปt sแป AV
atexec.py
ฤiแปu kiแปn sแปญ dแปฅng
Port
445
Credentials
Cleartext hoแบทc hash
Share
Access ฤฦฐแปฃc ADMIN$ share (chแป cแบงn quyแปn read)
Sแปญ dแปฅng cฦก bแบฃn:
atexec.py chแป thแปฑc thi command vร cho ta output chแปฉ khรดng tแบกo interactive shell nhฦฐ psexec.py hay smbexec.py
Cฦก chแบฟ hoแบกt ฤแปng
Tรณm tแบฏt: Atexec sแบฝ lแปฃi dแปฅng name pipe \atsvc ฤแป remote tแบกo schedule task thแปฑc thi command, output sแบฝ ฤฦฐแปฃc lฦฐu trong file temp
Kแบฟt nแปi vแปi victim ฤแป dรนng name pipe \atsvc

Command sแบฝ ฤฦฐแปฃc write dฦฐแปi format xml nhฦฐ sau

Ta thแบฅy kแบฟt quแบฃ output sแบฝ ฤฦฐแปฃc lฦฐu vร o %windir%\Temp\<random>.tmp. Tiแบฟp theo atexec.py dรนng SchRpcRegisterTask ฤแป tแบกo, start vร xรณa schedule task sau khi thแปฑc thi xong

Kแบฟt quแบฃ sแบฝ ฤฦฐแปฃc ฤแปc thรดng qua $ADMIN share, sau khi kแบฟt thรบc thรฌ ฤฦฐแปฃc tแปฑ ฤแปng xรณa

Kแบฟt quแบฃ thแปฑc thi thร nh cรดng

Ta cรณ thแป thay ฤแปi share muแปn lแบฅy output trong source code chแปฉ atexec.py khรดng hแป trแปฃ options nร o thay ฤแปi share. Cuแปi cรนng vรฌ khรดng drop binary nรชn khรดng bแป detect bแปi windef vร mแปt sแป AV
Log create, start vร delete task

wmiexec.py
ฤiแปu kiแปn sแปญ dแปฅng
Port
135, 4915x/TCP (cแบงn thรชm port 445 - nแบฟu muแปn output)
Credentials
Cleartext hoแบทc hash
Share
Khรดng cแบงn
Sแปญ dแปฅng cฦก bแบฃn:
Trong trฦฐแปng hแปฃp target cรณ mแป SMB thรฌ wmiexec.py cรณ thแป thแปฑc thi command vร cho ta output thรดng qua share theo cฦก chแบฟ semi-interactive shell
Cรฒn trong trฦฐแปng hแปฃp khรดng mแป SMB ta vแบซn cรณ thแป remote execute thรดng qua port 135 vร 4915x vแปi option -nooutput
Trong trฦฐแปng hแปฃp nแบฟu khรดng chแบกy ฤฦฐแปฃc thรฌ lรฝ do lร bแป dรญnh UAC vแปi mรกy khรดng join domain (tham khแบฃo)
Fix
Cฦก chแบฟ hoแบกt ฤแปng
Tรณm tแบฏt: wmiexec sแบฝ lแปฃi dแปฅng wmi trรชn nแปn DCOM ฤแป remote thแปฑc thi command, trong trฦฐแปng hแปฃp victim cรณ mแป SMB thรฌ output ฤฦฐแปฃc write vร ฤแปc qua share, cรฒn nแบฟu khรดng mแป SMB share thรฌ chแป thแปฑc thi command
Phแบงn wmiexec nร y cรณ nhiแปu ฤoแบกn trong code mรฌnh khรดng hiแปu lแบฏm nรชn mรฌnh chแป tรณm tแบฏt flow chรญnh cแปงa nรณ.
ฤแบงu tiรชn trฦฐแปc khi thแปฑc hiแปn kแบฟt nแปi qua RPC thรฌ nรณ test kแบฟt nแปi SMB ฤแป handle viแปc xuแบฅt output, nแบฟu khรดng cรณ thรฌ smbConnection lร None.

Tiแบฟp theo tแบกo DCOMConnection vร gแปi ฤแบฟn method CoCreateInstanceEx ฤแป kแบฟt nแปi vแปi victim qua RPC vร tแบกo interface ฤแบกi diแปn cho DCOM object

ฤoแบกn code trong CoCreateInstanceEx mรฌnh khรดng hiแปu lแบฏm nhฦฐng tรณm tแบฏt lร sแบฝ tแบกo kแบฟt nแปi qua RPC ฤแบฟn victim vร get DCOM object rแปi store vร o python interface.
Tiแบฟp theo authen bแบฑng NTML vแปi name pipe /root/cimv2
Code cแปงa method NTMLogin lร implement lแบกi method nร y. Tแปซ DCOM object ฤรฃ get แป trรชn ta tiแบฟn hร nh authen ฤแป lแบฅy IWbemServices object mร associated vแปi name space cho phรฉp tฦฐฦกng tรกc vแปi computer hardware vร configuration tแปซ name pipe /root/cimv2 (tham khแบฃo tแบกi ฤรขy)

Khi nhแบฃy vร o method request ta sแบฝ cรณ ฤoแบกn code sau:

Tแบกi method get_dce_rpc chรญnh lร lแบฅy ra DCOM object

Dแปซng mแปt xรญu tแบกi chแป nร y thรฌ khi thแปฑc hiแปn kแบฟt nแปi get DCOM object thร nh cรดng code gแปi vแป class "รดng" cแปงa nรณ ฤแป lฦฐu interface ฤแบกi diแปn cho DCOM object vร o list CONNECTIONS

Do ฤรณ vแป sau ta chแป cแบงn gแปi vแป list CONNECTIONS nแบฟu muแปn giao tiแบฟp vแปi DCOM object.
Sau khi cรณ ฤฦฐแปฃc IWbemServices object, release DCOM object vร get Win32_Process ฤแป thแปฑc hiแปn cรกc thao tรกc liรชn quan remote access

ฤoแบกn execute command thรฌ ฤฦกn giแบฃn nhฦฐ cรกc tools trฦฐแปc

Nแบฟu target cรณ SMB thรฌ output ฤฦฐแปฃc save vร o ADMIN$ share vร get thรดng qua SMB

Cuแปi cรนng vรฌ khรดng drop binary nร o hแบฟt nรชn sแบฝ bypass ฤฦฐแปฃc WinDef vร mแปt sแป AV. Ngoร i ra khi chแบกy options nooutput chแป remote access qua RPC cลฉng giแบฃm ฤฦฐแปฃc 1 phแบงn malicous ฤแปi vแปi EDR/XDR.
Last updated