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@IP

Cฦก chแบฟ hoแบกt ฤ‘แป™ng

circle-info

Tรณm tแบฏt: psexec.py sแบฝ sแปญ dแปฅng SMB share ฤ‘แปƒ uplaod RemComSvcarrow-up-right, 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

circle-info

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ร yarrow-up-right. 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

Chแบกy vแป›i Share mode
Chแบกy vแป›i Server mode

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

File output trรชn mรกy victim

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

Log tแบกo service

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

circle-info

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แบฃoarrow-up-right)

Fix

Cฦก chแบฟ hoแบกt ฤ‘แป™ng

circle-info

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ร yarrow-up-right. 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 ฤ‘รขyarrow-up-right)

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