SlideShare a Scribd company logo
Anatomy of
persistence
techniques &
strategies to detect
#whoami
👉 Chirag Savla
👉 Twitter – @chiragsavla94
👉 Interest area – Red
Teaming, Application
Security, Penetration
Testing
2
Blog – https://3xpl01tc0d3r.blogspot.com
“As an offensive researcher, if you can dream
it, someone has likely already done it… and
that someone isn’t the kind of person who
speaks at security cons.
— Matt Graeber
Agenda
▸ Attack Kill Chain
▸ About Persistence
▸ Persistence Techniques
▸ Persistence Leveraging MSSQL
▸ Approach to Detect Persistence
4
Question
▸ Which Team do you belong to ?
- Blue team (The Defenders)
- Red team ( The Offensive Side)
- Management / Executive
- Others
5
6
Attack Kill Chain
Attack Kill Chain
7
8
About Persistence
About Persistence
▸ Persistence is any access, action, or configuration change to a system that
gives an adversary a persistent presence on that system.
▸ Adversaries will often need to maintain access to systems through
interruptions such as system restarts, loss of credentials, or other failures
that would require a remote access tool to restart or alternate backdoor for
them to regain access.
9
Question
▸ Do you think Antivirus (AV) solutions are enough to detect persistent
malwares?
- Yes, I have a next-gen AV
- No
- Don’t know
10
11
Persistence
Techniques
Persistence Techniques
▸ Schedule Task
▸ Registry Run Keys
▸ Startup Folders
▸ DLL Search Order Hijacking
▸ COM Hijacking
▸ Image File Execution Options Injection
▸ Logon Scripts
▸ Windows Management Instrumentation Event Subscription
▸ Account Manipulation
▸ Account Creation
12
13
Persistence
Leveraging MSSQL
▸What & Why MSSQL ?
▸Persistence Opportunities
What & Why MSSQL ?
▸ Microsoft SQL Server is a relational database management system
developed by Microsoft. As a database server, it is a software product with
the primary function of storing and retrieving data as requested by other
software applications — which may run either on the same computer or on
another computer across a network.
▸ SQL server mostly runs with privilege accounts which are useful for
persistence.
14
Persistence Opportunities
▸ Startup Stored Procedures - Stored procedures marked for automatic
execution are executed every time SQL Server starts. Its automatically
executes with the same permissions as members of the sysadmin.
▸ Triggers - A trigger is a special type of stored procedure that automatically
runs when an event occurs in the database server. There are 3 types of
triggers DML, DDL and Logon.
▸ Registry Keys - Undocumented extended procedures allows sysadmins to
read and write the registry keys.
15
Demo Time
This is not rocket science.
16
17
Approach to
Detect Persistence
▸Enable auditing & logging
▸Tips for detecting persistence
Create and enable a SERVER AUDIT
-- Select master database
USE master
-- Setup server audit to log to application log
CREATE SERVER AUDIT Audit_StartUp_Procs
TO APPLICATION_LOG
WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE)
-- Enable server audit
ALTER SERVER AUDIT Audit_StartUp_Procs
WITH (STATE = ON)
18
Create an enabled SERVER AUDIT
SPECIFICATION
-- Create server audit specification
CREATE SERVER AUDIT SPECIFICATION Audit_StartUp_Procs_Server_Spec
FOR SERVER AUDIT Audit_StartUp_Procs
ADD (SERVER_ROLE_MEMBER_CHANGE_GROUP),
-- track group changes
ADD (SERVER_OPERATION_GROUP),
-- track server setting changes
ADD (AUDIT_CHANGE_GROUP)
-- track audit setting changes
WITH (STATE = ON)
19
Create an enabled DATABASE AUDIT
SPECIFICATION
-- Create the database audit specification
CREATE DATABASE AUDIT SPECIFICATION Audit_StartUp_Procs_Database_Spec
FOR SERVER AUDIT Audit_StartUp_Procs
ADD (EXECUTE
ON master..sp_procoption BY public )
-- sp_procoption execution
WITH (STATE = ON)
GO
20
Demo Time
This is not rocket science.
21
Tips for detecting persistence
▸Monitor Registry Changes – Sysmon Event ID 12,13,14
▸Monitor Account Creation – Event ID 4720
▸Monitor File Creations – Sysmon Event ID 11
▸Monitor DLL loading – Sysmon Event ID 7 (ImageLoaded)
▸Monitor Schedule Task – Event ID 4698
22
Question
▸ How many of you are already monitoring these events?
- All of them
- Some of them
- Haven't started yet
23
Credits
Thanks to DNIF for granting me the privilege to
present.
Special thanks to Scott Sutherland for documenting
the amazing ways to get persistence using MSSQL.
24
Reference
▸ https://blog.netspi.com/sql-server-persistence-part-1-startup-stored-procedures/
▸ https://blog.netspi.com/maintaining-persistence-via-sql-server-part-2-triggers/
▸ https://blog.netspi.com/establishing-registry-persistence-via-sql-server-powerupsql/
▸ https://attack.mitre.org/tactics/TA0003/
▸ https://uncoder.io/
▸ https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms191129(v=sql.105)
▸ https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-procoption-transact-
sql?view=sql-server-2017
▸ https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-2017
▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/implement-ddl-triggers?view=sql-server-2017
▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/ddl-event-groups?view=sql-server-2017
▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/create-dml-triggers?view=sql-server-2017
▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/logon-triggers?view=sql-server-2017
▸ https://support.microsoft.com/en-us/help/887165/bug-you-may-receive-an-access-is-denied-error-message-
when-a-query-cal
▸ https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon
25
26
THANKS!
Any questions?
You can find me at @chiragsavla94

More Related Content

PPTX
You need rules? You need PBM!
PPT
Intro to tsql unit 6
PDF
Security 101: IBM i Security Auditing and Reporting
PDF
OER UNIT 5 Audit
PPT
20131003 pizzasessie db-security
PDF
ProxySQL in the Cloud
PPTX
Oracle audit and reporting in one hour or less
PDF
Mysql
You need rules? You need PBM!
Intro to tsql unit 6
Security 101: IBM i Security Auditing and Reporting
OER UNIT 5 Audit
20131003 pizzasessie db-security
ProxySQL in the Cloud
Oracle audit and reporting in one hour or less
Mysql

Similar to Anatomy of Persistence Techniques & Strategies to Detect (20)

PDF
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
PPTX
RVASec AWS Survival Guide 2.0
DOC
Sap Access Risks Procedures
PDF
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
PDF
Up is Down, Black is White: Using SCCM for Wrong and Right
PPTX
Monitoring and Reporting for IBM i Compliance and Security
PPTX
Oracle_Audit_APEX IOUG Collaborate 14
PPT
High Performance Mysql
PDF
Windows logging cheat sheet
PPTX
Mechanisms for Database Intrusion Detection and Response
PDF
MySQL Performance Schema in Action
PDF
Securing your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
PPTX
RACE - Minimal Rights and ACE for Active Directory Dominance
PDF
Practical Approach towards SQLi ppt
PDF
MySQL Enterprise Monitor
PPTX
MySQL Performance Schema : fossasia
PPTX
How to Increase ICS Cybersecurity Return on Investment (ROI)
PPT
DB2 LUW Auditing
PDF
Aspects of 10 Tuning
PDF
Cypress Automation : Increase Reusability with Custom Commands
ProxySQL and the Tricks Up Its Sleeve - Percona Live 2022.pdf
RVASec AWS Survival Guide 2.0
Sap Access Risks Procedures
MySQL-Performance Schema- What's new in MySQL-5.7 DMRs
Up is Down, Black is White: Using SCCM for Wrong and Right
Monitoring and Reporting for IBM i Compliance and Security
Oracle_Audit_APEX IOUG Collaborate 14
High Performance Mysql
Windows logging cheat sheet
Mechanisms for Database Intrusion Detection and Response
MySQL Performance Schema in Action
Securing your Oracle Fusion Middleware Environment, On-Prem and in the Cloud
RACE - Minimal Rights and ACE for Active Directory Dominance
Practical Approach towards SQLi ppt
MySQL Enterprise Monitor
MySQL Performance Schema : fossasia
How to Increase ICS Cybersecurity Return on Investment (ROI)
DB2 LUW Auditing
Aspects of 10 Tuning
Cypress Automation : Increase Reusability with Custom Commands
Ad

More from DNIF (16)

PPTX
Beyond blacklists - A cyber threat intelligence perspective
PPTX
Insight into SOAR
PPTX
A closer look at CTF challenges
PDF
Threat Intelligence and Cyber Security Challenges | KASPERSKY & DNIF INTEGRATION
PPTX
CVE Analysis using vFeed
PDF
Container Security Essentials
PDF
Importance of having a vulnerability management | Vfeed
PPTX
User Behavior Analytics Using Machine Learning
PPTX
Process Whitelisting With VirusTotal
PPTX
VirusTotal Threat Intelligence and DNIF Use Cases
PPTX
Threat hunting and achieving security maturity
PPTX
Kaspersky Threat Intelligence Portal and DNIF Use Cases
PPTX
Data Analytics in Cyber Security
PPTX
Mastering Next Gen SIEM Use Cases (Part 3)
PPTX
Mastering Next Gen SIEM Use Cases (Part 2)
PPTX
Mastering Next Gen SIEM Use Cases (Part 1)
Beyond blacklists - A cyber threat intelligence perspective
Insight into SOAR
A closer look at CTF challenges
Threat Intelligence and Cyber Security Challenges | KASPERSKY & DNIF INTEGRATION
CVE Analysis using vFeed
Container Security Essentials
Importance of having a vulnerability management | Vfeed
User Behavior Analytics Using Machine Learning
Process Whitelisting With VirusTotal
VirusTotal Threat Intelligence and DNIF Use Cases
Threat hunting and achieving security maturity
Kaspersky Threat Intelligence Portal and DNIF Use Cases
Data Analytics in Cyber Security
Mastering Next Gen SIEM Use Cases (Part 3)
Mastering Next Gen SIEM Use Cases (Part 2)
Mastering Next Gen SIEM Use Cases (Part 1)
Ad

Recently uploaded (20)

PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
1 - Historical Antecedents, Social Consideration.pdf
PDF
Enhancing emotion recognition model for a student engagement use case through...
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Approach and Philosophy of On baking technology
PDF
Hybrid model detection and classification of lung cancer
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PPTX
TLE Review Electricity (Electricity).pptx
PDF
A novel scalable deep ensemble learning framework for big data classification...
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PDF
Heart disease approach using modified random forest and particle swarm optimi...
PPTX
A Presentation on Touch Screen Technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PPTX
Chapter 5: Probability Theory and Statistics
PDF
WOOl fibre morphology and structure.pdf for textiles
PPTX
A Presentation on Artificial Intelligence
PDF
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
1 - Historical Antecedents, Social Consideration.pdf
Enhancing emotion recognition model for a student engagement use case through...
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Approach and Philosophy of On baking technology
Hybrid model detection and classification of lung cancer
Assigned Numbers - 2025 - Bluetooth® Document
TLE Review Electricity (Electricity).pptx
A novel scalable deep ensemble learning framework for big data classification...
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Heart disease approach using modified random forest and particle swarm optimi...
A Presentation on Touch Screen Technology
Building Integrated photovoltaic BIPV_UPV.pdf
Group 1 Presentation -Planning and Decision Making .pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
Chapter 5: Probability Theory and Statistics
WOOl fibre morphology and structure.pdf for textiles
A Presentation on Artificial Intelligence
DASA ADMISSION 2024_FirstRound_FirstRank_LastRank.pdf

Anatomy of Persistence Techniques & Strategies to Detect

  • 2. #whoami 👉 Chirag Savla 👉 Twitter – @chiragsavla94 👉 Interest area – Red Teaming, Application Security, Penetration Testing 2 Blog – https://3xpl01tc0d3r.blogspot.com
  • 3. “As an offensive researcher, if you can dream it, someone has likely already done it… and that someone isn’t the kind of person who speaks at security cons. — Matt Graeber
  • 4. Agenda ▸ Attack Kill Chain ▸ About Persistence ▸ Persistence Techniques ▸ Persistence Leveraging MSSQL ▸ Approach to Detect Persistence 4
  • 5. Question ▸ Which Team do you belong to ? - Blue team (The Defenders) - Red team ( The Offensive Side) - Management / Executive - Others 5
  • 9. About Persistence ▸ Persistence is any access, action, or configuration change to a system that gives an adversary a persistent presence on that system. ▸ Adversaries will often need to maintain access to systems through interruptions such as system restarts, loss of credentials, or other failures that would require a remote access tool to restart or alternate backdoor for them to regain access. 9
  • 10. Question ▸ Do you think Antivirus (AV) solutions are enough to detect persistent malwares? - Yes, I have a next-gen AV - No - Don’t know 10
  • 12. Persistence Techniques ▸ Schedule Task ▸ Registry Run Keys ▸ Startup Folders ▸ DLL Search Order Hijacking ▸ COM Hijacking ▸ Image File Execution Options Injection ▸ Logon Scripts ▸ Windows Management Instrumentation Event Subscription ▸ Account Manipulation ▸ Account Creation 12
  • 13. 13 Persistence Leveraging MSSQL ▸What & Why MSSQL ? ▸Persistence Opportunities
  • 14. What & Why MSSQL ? ▸ Microsoft SQL Server is a relational database management system developed by Microsoft. As a database server, it is a software product with the primary function of storing and retrieving data as requested by other software applications — which may run either on the same computer or on another computer across a network. ▸ SQL server mostly runs with privilege accounts which are useful for persistence. 14
  • 15. Persistence Opportunities ▸ Startup Stored Procedures - Stored procedures marked for automatic execution are executed every time SQL Server starts. Its automatically executes with the same permissions as members of the sysadmin. ▸ Triggers - A trigger is a special type of stored procedure that automatically runs when an event occurs in the database server. There are 3 types of triggers DML, DDL and Logon. ▸ Registry Keys - Undocumented extended procedures allows sysadmins to read and write the registry keys. 15
  • 16. Demo Time This is not rocket science. 16
  • 17. 17 Approach to Detect Persistence ▸Enable auditing & logging ▸Tips for detecting persistence
  • 18. Create and enable a SERVER AUDIT -- Select master database USE master -- Setup server audit to log to application log CREATE SERVER AUDIT Audit_StartUp_Procs TO APPLICATION_LOG WITH (QUEUE_DELAY = 1000, ON_FAILURE = CONTINUE) -- Enable server audit ALTER SERVER AUDIT Audit_StartUp_Procs WITH (STATE = ON) 18
  • 19. Create an enabled SERVER AUDIT SPECIFICATION -- Create server audit specification CREATE SERVER AUDIT SPECIFICATION Audit_StartUp_Procs_Server_Spec FOR SERVER AUDIT Audit_StartUp_Procs ADD (SERVER_ROLE_MEMBER_CHANGE_GROUP), -- track group changes ADD (SERVER_OPERATION_GROUP), -- track server setting changes ADD (AUDIT_CHANGE_GROUP) -- track audit setting changes WITH (STATE = ON) 19
  • 20. Create an enabled DATABASE AUDIT SPECIFICATION -- Create the database audit specification CREATE DATABASE AUDIT SPECIFICATION Audit_StartUp_Procs_Database_Spec FOR SERVER AUDIT Audit_StartUp_Procs ADD (EXECUTE ON master..sp_procoption BY public ) -- sp_procoption execution WITH (STATE = ON) GO 20
  • 21. Demo Time This is not rocket science. 21
  • 22. Tips for detecting persistence ▸Monitor Registry Changes – Sysmon Event ID 12,13,14 ▸Monitor Account Creation – Event ID 4720 ▸Monitor File Creations – Sysmon Event ID 11 ▸Monitor DLL loading – Sysmon Event ID 7 (ImageLoaded) ▸Monitor Schedule Task – Event ID 4698 22
  • 23. Question ▸ How many of you are already monitoring these events? - All of them - Some of them - Haven't started yet 23
  • 24. Credits Thanks to DNIF for granting me the privilege to present. Special thanks to Scott Sutherland for documenting the amazing ways to get persistence using MSSQL. 24
  • 25. Reference ▸ https://blog.netspi.com/sql-server-persistence-part-1-startup-stored-procedures/ ▸ https://blog.netspi.com/maintaining-persistence-via-sql-server-part-2-triggers/ ▸ https://blog.netspi.com/establishing-registry-persistence-via-sql-server-powerupsql/ ▸ https://attack.mitre.org/tactics/TA0003/ ▸ https://uncoder.io/ ▸ https://docs.microsoft.com/en-us/previous-versions/sql/sql-server-2008-r2/ms191129(v=sql.105) ▸ https://docs.microsoft.com/en-us/sql/relational-databases/system-stored-procedures/sp-procoption-transact- sql?view=sql-server-2017 ▸ https://docs.microsoft.com/en-us/sql/t-sql/statements/create-trigger-transact-sql?view=sql-server-2017 ▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/implement-ddl-triggers?view=sql-server-2017 ▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/ddl-event-groups?view=sql-server-2017 ▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/create-dml-triggers?view=sql-server-2017 ▸ https://docs.microsoft.com/en-us/sql/relational-databases/triggers/logon-triggers?view=sql-server-2017 ▸ https://support.microsoft.com/en-us/help/887165/bug-you-may-receive-an-access-is-denied-error-message- when-a-query-cal ▸ https://docs.microsoft.com/en-us/sysinternals/downloads/sysmon 25
  • 26. 26 THANKS! Any questions? You can find me at @chiragsavla94