SlideShare a Scribd company logo
1 of 44
Download to read offline
INELUCTABLE MODALITY
OF LINUX AUDIT
A story of hate and delectation
Faster & Smarter IR
SUMUS
Mark Ellzey
@strcpy - @threatstack
Software for down there.
!! WARNING !!
If you are a current employee of RedHat (specifically on
the auditd codebase), and have an extensive
background in martial arts, please leave the room now.
I would rather not spend the night in a hospital.
BLATANT MARKETING SLIDE
The contents within are the result of making this product a reality.
• Provides information to a user which, in most
cases, only the kernel is privy to.
• A passive mechanism only; no alteration or
control over the data that is being emitted.
• Simplistic filtering using boolean logic over a linked
list of comparison operations.
• Can easily be extended by other kernel APIs,
including loadable modules.
The Linux Audit System
EXORDIUM
WRONG!
Wait for the din of shocked gasps to become quiescent, then proceed
AUDITD & AUDIT ARE MUTUALLY
EXCLUSIVE
AUDIT IS NOT MAGICAL
#define SYSCALL_DEFINEx(x, sname, ...) 
     SYSCALL_METADATA(sname, x, __VA_ARGS__);
!
#define SYSCALL_METADATA(sname, nb, ...)  
SYSCALL_TRACE_ENTER_EVENT(sname); 
       SYSCALL_TRACE_EXIT_EVENT(sname);
!
!
auditsys:
  movq %r10,%r9
  movq %rdx,%r8
  movq %rsi,%rcx
  movq %rdi,%rdx
  movq %rax,%rsi
  call __audit_syscall_entry
 
sysret_audit:
  call __audit_syscall_exit
code is generated for all syscall entry and exit points
audit_syscall_entry audit_syscall_exit
• Determines if the syscall
should be audited.
• Initializes underlying
audit_context structure from
the current task_struct.
• Emits several messages with
data associated with the
syscall over the netlink socket.
• The last message is always of
type “AUDIT_EOE”
AUDIT IS NOT MAGICAL
what is the meaning of this?
• return status
• execve
• sockaddrs
• fd pairs
• pid / auid / uid / sessionid
• current working directories
• path information
AUDIT IS NOT MAGICAL
some various data which is logged at exit
CAN’T STOP HERE,THIS
IS BAT COUNTRY
FEAR AND LOATHING IN KERNEL/AUDIT.C
there can be only one
Only one process can read from the audit netlink socket
this is a good thing - the kernel only has to maintain one buffer
Creating a second reader will hijack the first and will not be restored on exit
I get it, otherwise the kernel would be required to keep a backlog stack of processes
FEAR AND LOATHING IN KERNEL/AUDIT.C
debugging is impossible
Prior to linux 3.8, when the audit backlog was hit, and audit_log_start was
called during schedule_timeout : a deadlock would occur and fuck you
so if you’re in gdb and hit a breakpoint, it was a raging race to disable audit
I always forgot. The holes in the walls are a testament to that
FORMAT DISAPPROBATION :(
The kernel is to blame for this shameful log format!
audit_log_format(ab,"a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
" ppid=%d pid=%d auid=%u uid=%u gid=%u"
" euid=%u suid=%u fsuid=%u"
  " egid=%u sgid=%u fsgid=%u tty=%s ses=%u",
   context->argv[0], context->argv[1], ...);
b u t w h a t i s t h e a l t e r n a t i v e ?
You’re insane. A JSON encoder in the kernel?
You’re insane.
An overly complex binary
message format?
How about this JSON thing I’ve
been hearing so much about?
• Everything that comes from the kernel
is a key value pair, treat it like so.
• Unquoted values are (usually) deemed
as “untrusted” strings, encoded as
ascii-hex.
• The “serial number” is the kernel’s way
of designating multiple messages into
a single group. It is up to the user-land
application to reassemble.
• User-land sourced messages are
always encapsulated in a key of “msg”
• If you were like me, stop bitching and
deal with it.
Just follow these simple rules
FORMAT APPROBATION :)
• Performance problems under load.
• Limited output format.
• Difficult to extend.
• Impossible to read.
• Poorly designed (opinion).
• Did I mention performance issues?
• I’ve seen better code in openssl.
THINE ENEMY LIES WITHIN LEGACY
AUDITING AUDITD
The mere presence of a comment
containing “Global” is a good sign
that the rest will be, in all probability,
terrible.
Is this what I think it is? Every single
message from the kernel is inserted
into a thread queue.
!
Also: “FIXME” in production code will
always induce cringe.
THINE ENEMY LIES WITHIN LEGACY
GOALS
• Lower resource utilization
under high load
• Extend (or create) logging
and filtering capabilities
• Keep some backwards
compatibility with auditd
• Don’t reinvent the wheel, if
the wheel isn’t broken
• Abstract EVERYTHING
• Follow all of the rules in the
next slide.
DEPRECATION
RULE ONE THROUGH ∞
An afterthought in auditd.
LIBEV FOR NETWORK AND SIGNAL IO
MANUAL NETLINK SOCKET HANDLING
LIBEVENT FOR NETWORK AND SIGNAL IO
LIBMNL FOR NETLINK SOCKET HANDLING
LOW LEVEL PROCESSING
THE AUDITD METHOD
OUR METHOD
!! WARNING !!
No statements about how libev is faster than libevent.
These comments are usually some variant of
regurgitated information based on the flawed
performance comparisons found on the libev website.
“It’s only cheating if you do it on purpose.”
PROCESSING : LIBMNL
creating the socket and registering with the kernel
PROCESSING : RAW NETLINK
creating the socket and registering with the kernel
thereisactuallymore
PROCESSING : LIBMNL
receiving a message from the netlink socket
libmnl does all the ugly work
PROCESSING : RAW NETLINK
receiving a message from the netlink socket
thereisactuallymore
PROCESSING : MESSAGES
post processing runtime grouping
The method used by auditd
requiring an external application to
parse and join multiple messages
using the “serial number” as a
grouping key.
dealing with the raw data
The method used by our
system which appends data
received from the kernel to a list
until the final AUDIT_EOE packet
has been processed.
PROCESSING : MESSAGE GROUPS
an abstract example; executing “tail -f tsaudit.log”
- serial=43480, type=SYSCALL, syscall=“sys_execve”, exe=“/usr/bin/tail”
- serial=43480, type=EXECVE, argc=2, a0=“tail”, a1=“tsaudit.log”
- serial=43480, type=CWD, cwd=“/var/log”
- serial=43480, type=PATH, name=“/usr/bin/tail”
- serial=43480, type=EOE
ungrouped
grouped
[	
{	
“type" : "SYSCALL",	
“syscall" : "execve",	
“exe" : "/usr/bin/tail"	
},	
{	
“type" : "EXECVE",	
“argc" : 2,	
“argv” : [ “tail”, “tsaudit.log” ],	
},	
{	
“type" : "CWD",	
“cwd" : "/var/log"	
},	
{	
"type": "PATH",	
"name": "/usr/bin/tail"	
}	
]
PROCESSING : MESSAGE GROUPSA few more fun examples of grouping.
[	
{	
"exe": "/bin/cat",	
"comm": "cat",	
"ses": 10,	
"auid": 4294967295,	
"pid": 31335,	
"ppid": 31334,	
"items": 2,	
"exit": 0,	
"success": "yes",	
"syscall": "execve",	
"epoch": 1399248110,	
"serial": 855516,	
"type": "SYSCALL"	
},	
{	
"a1": "eth0.dhclient",	
"a0": "cat",	
"argc": 2,	
"epoch": 1399248110,	
"type": "EXECVE"	
},	
{	
"cwd": "/run/resolvconf/interface",	
"epoch": 1399248110,	
"type": "CWD"	
},	
{	
"name": "/bin/cat",	
"epoch": 1399248110,	
"type": "PATH"	
}	
]
[	
{	
"res": "success",	
"terminal": "ssh",	
"addr": "192.168.56.1",	
"hostname": "babby.local",	
"exe": "/usr/sbin/sshd",	
"acct": "mthomas",	
"op": "PAM:session_open",	
"ses": 24,	
"auid": 1000,	
"uid": 0,	
"pid": 10469,	
"epoch": 1393886985,	
"serial": 3393,	
"type": "USER_START"	
}	
]
[	
{	
"exe": "/usr/sbin/nginx",	
"comm": "nginx",	
"ses": 238,	
"pid": 966,	
"ppid": 965,	
"items": 1,	
"a3": "fffffffffffffffb",	
"a2": 0,	
"a1": "800",	
"a0": "ee7c05",	
"exit": 13,	
"success": "yes",	
"syscall": "open",	
"epoch": 1392316421,	
"serial": 301316,	
"type": "SYSCALL"	
},	
{	
"cwd": "/",	
"type": "CWD"	
},	
{	
"ogid": 0,	
"name": "/www/index.html",	
"type": "PATH"	
}	
]
[	
{	
"exe": "/usr/sbin/nginx",	
"comm": "nginx",	
"ses": 238,	
"pid": 966,	
"ppid": 965,	
"items": 0,	
"a3": "800",	
"a2": "7fff8afba6cc",	
"a1": "7fff8afba6d0",	
"a0": 0,	
"exit": 12,	
"success": "yes",	
"syscall": "accept4",	
"epoch": 1392316421,	
"serial": 301314,	
"type": "SYSCALL"	
},	
{	
"saddr": "192.168.56.1",	
"port": 51997,	
"prot": "ipv4",	
"type": "SOCKADDR"	
}	
]
/var/resolvconf/interface$ cat eth0.dhclient nginx: int fd = open(“/www/index.html”); // fd == 13 fd = accept(“192.168.56.1:51997”); user “mthomas” started a pam session
PARSING
“Every year, one out of ten programmers will commit suicide due to
maintaining parsers written in C”
Every C developer who has had to maintain a parser in C
PARSING AUDIT MESSAGES
you be the judge
type=SYSCALL msg=audit(1386803107.182:7960575): arch=c000003e syscall=288 success=yes exit=26 a0=7
a1=7fff986ec590 a2=7fff986ec58c a3=800 items=0 ppid=952 pid=956 auid=4294967295 uid=33 gid=33 euid=33 suid=33
fsuid=33 egid=33 sgid=33 fsgid=33 ses=4294967295 tty=(none) comm="nginx" exe="/usr/sbin/nginx" key=(null)
BRUTE FORCE
~/Code/auditd$ egrep '(strstr|strchr|strtok|strcmp|strcasecmp|strdup|strcat|sprintf|snprintf)' auparse/*.c | wc -l
448
STATE DRIVEN
~/Code/tsaudit$ egrep '(strstr|strchr|strtok|strcmp|strcasecmp|strdup|strcat|sprintf|snprintf)' auparser/*.c | wc -l
4
AUDITD METHOD
OUR METHOD
PARSING : BRUTE FORCE
oneofmanyhorriblethingsyouwillencounter
PARSING : STATE DRIVEN
switch/casegenerateslookuptables-faster
PARSING AUDIT MESSAGES
taking things to the next level
TURBO BOOSTING CONDITIONAL LOGIC
- Generate a perfect hash table
using “gperf”.
- Assign “known” keys and values
to an enumerable type.
- Filter out keys and values which
we deemed unnecessary for
further processing
- Add validation and auto-parsers
for specific key values.
- Determine if the value of a key
can be treated as a different data
type, such as an integer or
boolean.
SO WE CAN DO STUFF LIKE THIS
with perfect hash tables - lookups are O(1)
AND THIS
FILTERING
optionally preprocess data before it is logged
-Load per-instance or per-output LUA script during
startup.
-Convert the grouped messages to a native LUA table.
-Call a pre-defined LUA function.
-A non-zero return will drop the message.
-A zero return will continue processing the message
-If a LUA table is returned, it is converted to JSON and
used as the output.
FILTERING
Example : simple boolean filter
FILTERING
Example : return a table which is converted to JSON on output
function find_set(k, set)	
for _,v in pairs(set) do	
if k == v then	
return 1	
end	
end	
return 0	
end	
!
!
function tsaudit_filter(data)	
local ret = {}	
local comms = { 'irqbalance', 'whoopsie', 'top', 'dhclient' }	
!
for k,ent in pairs(data) do	
if find_set(ent['comm'], comms) == 1 then	
-- if any of the keys are found, return this table which will be	
-- transformed into the JSON { "this" : "filtered", "dont" : "log" }	
ret = {this="filtered", dont="log" }	
end	
!
if ent['success'] == 'no' then	
-- if the syscall did not succeed, then return 1 which will not generate a	
-- log.	
ret = 1	
end	
end	
!
return ret	
end
LOGGING : AUDITD
1. File
2. There is no 2
OUTPUT TYPES
Don’t worry, auditd can be extended with “audispd” plugins!
AUDISPD : A MONUMENTAL HACK
For each plugin, audispd will fork,
execve, and send audit messages
to stdout.
A plugin just has to have the ability
to read from stdin.
if this design seems sane to you, keep it a secret, and start sharpening that programming knife
new term : “infinite noose”
LOGGING : OUR WAY
1. ZeroMQ
2. Syslog
3. Audit Emulator
4. AIO
5. Raw
6. Nanomsg
jsonpluggable chained inlined
OUTPUT TYPES
as of right now
ACCESSION
meticulous attention to abstraction enhances creativity
A fully functional auditd’esque
application can be written in under
50 lines of C.
Introduced many other autonomous
inputs which can be integrated
seamlessly.
• rtnetlink
• netlink connector
• netlink inet diag
• netlink task stats
• pcap data
• userland audit
consummation
I am your typical developer. “I can do better than that!”
Usually a dumb statement to make, so was it worth it?
Running apache bench (ab) at 10,000 requests per second
AUDITD 120% CPU
OUR REWRITE 10% CPU
I think that’s better.
• Additional methods for grouping related
data, further reducing overhead.
• Add simple analysis and statistical
gathering functionality.
• Continue abstractions to avoid the
potential bloat that comes with feature-
creep
CEREBRATION
COME WORK WITH
US
@threatstack

More Related Content

What's hot

Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
James Hsieh
 
JConrad_Mod11_FinalProject_031816
JConrad_Mod11_FinalProject_031816JConrad_Mod11_FinalProject_031816
JConrad_Mod11_FinalProject_031816
Jeff Conrad
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
Silvio Cesare
 
Алексей Старов - Как проводить киберраследования?
Алексей Старов - Как проводить киберраследования?Алексей Старов - Как проводить киберраследования?
Алексей Старов - Как проводить киберраследования?
HackIT Ukraine
 
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Rob Fuller
 

What's hot (20)

When is something overflowing
When is something overflowingWhen is something overflowing
When is something overflowing
 
Crash dump analysis - experience sharing
Crash dump analysis - experience sharingCrash dump analysis - experience sharing
Crash dump analysis - experience sharing
 
Penetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utilityPenetrating Windows 8 with syringe utility
Penetrating Windows 8 with syringe utility
 
JConrad_Mod11_FinalProject_031816
JConrad_Mod11_FinalProject_031816JConrad_Mod11_FinalProject_031816
JConrad_Mod11_FinalProject_031816
 
How Safe is your Link ?
How Safe is your Link ?How Safe is your Link ?
How Safe is your Link ?
 
Vulnerability desing patterns
Vulnerability desing patternsVulnerability desing patterns
Vulnerability desing patterns
 
'Malware Analysis' by PP Singh
'Malware Analysis' by PP Singh'Malware Analysis' by PP Singh
'Malware Analysis' by PP Singh
 
Использование KASan для автономного гипервизора
Использование KASan для автономного гипервизораИспользование KASan для автономного гипервизора
Использование KASan для автономного гипервизора
 
Auditing the Opensource Kernels
Auditing the Opensource KernelsAuditing the Opensource Kernels
Auditing the Opensource Kernels
 
How to drive a malware analyst crazy
How to drive a malware analyst crazyHow to drive a malware analyst crazy
How to drive a malware analyst crazy
 
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
DARPA CGC and DEFCON CTF: Automatic Attack and Defense TechniqueDARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
DARPA CGC and DEFCON CTF: Automatic Attack and Defense Technique
 
Алексей Старов - Как проводить киберраследования?
Алексей Старов - Как проводить киберраследования?Алексей Старов - Как проводить киберраследования?
Алексей Старов - Как проводить киберраследования?
 
Vulnerability, exploit to metasploit
Vulnerability, exploit to metasploitVulnerability, exploit to metasploit
Vulnerability, exploit to metasploit
 
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
Attacker Ghost Stories (CarolinaCon / Area41 / RVASec)
 
Reverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande ModemReverse engineering Swisscom's Centro Grande Modem
Reverse engineering Swisscom's Centro Grande Modem
 
CrySys guest-lecture: Virtual machine introspection on modern hardware
CrySys guest-lecture: Virtual machine introspection on modern hardwareCrySys guest-lecture: Virtual machine introspection on modern hardware
CrySys guest-lecture: Virtual machine introspection on modern hardware
 
C# to python
C# to pythonC# to python
C# to python
 
Incident Resolution as Code
Incident Resolution as CodeIncident Resolution as Code
Incident Resolution as Code
 
Эксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAPЭксплуатируем неэксплуатируемые уязвимости SAP
Эксплуатируем неэксплуатируемые уязвимости SAP
 
Back to the CORE
Back to the COREBack to the CORE
Back to the CORE
 

Viewers also liked

Protecting confidential files using SE-Linux
Protecting confidential files using SE-LinuxProtecting confidential files using SE-Linux
Protecting confidential files using SE-Linux
Giuseppe Paterno'
 

Viewers also liked (20)

SHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditDSHOWDOWN: Threat Stack vs. Red Hat AuditD
SHOWDOWN: Threat Stack vs. Red Hat AuditD
 
Protecting confidential files using SE-Linux
Protecting confidential files using SE-LinuxProtecting confidential files using SE-Linux
Protecting confidential files using SE-Linux
 
Open Audit
Open AuditOpen Audit
Open Audit
 
How To Train Your Python
How To Train Your PythonHow To Train Your Python
How To Train Your Python
 
Linux audit framework
Linux audit frameworkLinux audit framework
Linux audit framework
 
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete CheslockBringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
Bringing Infosec Into The Devops Tribe: Q&A With Gene Kim and Pete Cheslock
 
Dealing with Linux Malware
Dealing with Linux MalwareDealing with Linux Malware
Dealing with Linux Malware
 
Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014Everyone Matters In Infosec 2014
Everyone Matters In Infosec 2014
 
Whitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and SolarisWhitepaper: User Audit Options for Linux and Solaris
Whitepaper: User Audit Options for Linux and Solaris
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
MySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise EditionMySQL Day Paris 2016 - MySQL Enterprise Edition
MySQL Day Paris 2016 - MySQL Enterprise Edition
 
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
2009-08-11 IBM Teach the Teachers (IBM T3), Linux Security Overview
 
Network Security and Analysis with Python
Network Security and Analysis with PythonNetwork Security and Analysis with Python
Network Security and Analysis with Python
 
Linux Security Scanning with Lynis
Linux Security Scanning with LynisLinux Security Scanning with Lynis
Linux Security Scanning with Lynis
 
Handling of compromised Linux systems
Handling of compromised Linux systemsHandling of compromised Linux systems
Handling of compromised Linux systems
 
Linux Hardening
Linux HardeningLinux Hardening
Linux Hardening
 
PowerShell for Penetration Testers
PowerShell for Penetration TestersPowerShell for Penetration Testers
PowerShell for Penetration Testers
 
Linux Security for Developers
Linux Security for DevelopersLinux Security for Developers
Linux Security for Developers
 
PowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege EscalationPowerUp - Automating Windows Privilege Escalation
PowerUp - Automating Windows Privilege Escalation
 
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does ItAMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
AMSI: How Windows 10 Plans to Stop Script-Based Attacks and How Well It Does It
 

Similar to Audit

Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Jagadisha Maiya
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
RootedCON
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Camilo Alvarez Rivera
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
Kan-Ru Chen
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
Ajin Abraham
 

Similar to Audit (20)

Techno-Fest-15nov16
Techno-Fest-15nov16Techno-Fest-15nov16
Techno-Fest-15nov16
 
Os Selbak
Os SelbakOs Selbak
Os Selbak
 
Code quality par Simone Civetta
Code quality par Simone CivettaCode quality par Simone Civetta
Code quality par Simone Civetta
 
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the CoreNSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
NSC #2 - D3 02 - Peter Hlavaty - Attack on the Core
 
Troubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device DriversTroubleshooting Linux Kernel Modules And Device Drivers
Troubleshooting Linux Kernel Modules And Device Drivers
 
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
Troubleshooting linux-kernel-modules-and-device-drivers-1233050713693744-1
 
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
Introduction to Industrial Control Systems : Pentesting PLCs 101 (BlackHat Eu...
 
Being HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on PurposeBeing HAPI! Reverse Proxying on Purpose
Being HAPI! Reverse Proxying on Purpose
 
Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]Joxean Koret - Database Security Paradise [Rooted CON 2011]
Joxean Koret - Database Security Paradise [Rooted CON 2011]
 
PVS-Studio and static code analysis technique
PVS-Studio and static code analysis techniquePVS-Studio and static code analysis technique
PVS-Studio and static code analysis technique
 
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01Introductiontoasp netwindbgdebugging-100506045407-phpapp01
Introductiontoasp netwindbgdebugging-100506045407-phpapp01
 
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
[CB20] Vulnerabilities of Machine Learning Infrastructure by Sergey Gordeychik
 
Attack on the Core
Attack on the CoreAttack on the Core
Attack on the Core
 
Hotsos Advanced Linux Tools
Hotsos Advanced Linux ToolsHotsos Advanced Linux Tools
Hotsos Advanced Linux Tools
 
Production Debugging at Code Camp Philly
Production Debugging at Code Camp PhillyProduction Debugging at Code Camp Philly
Production Debugging at Code Camp Philly
 
Android Boot Time Optimization
Android Boot Time OptimizationAndroid Boot Time Optimization
Android Boot Time Optimization
 
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
[HES2013] Virtually secure, analysis to remote root 0day on an industry leadi...
 
Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph Ceph Day Melbourne - Troubleshooting Ceph
Ceph Day Melbourne - Troubleshooting Ceph
 
Shellcoding in linux
Shellcoding in linuxShellcoding in linux
Shellcoding in linux
 
Debugging Python with gdb
Debugging Python with gdbDebugging Python with gdb
Debugging Python with gdb
 

Recently uploaded

The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
davew9
 
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
akbard9823
 
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men 🔝manali🔝 Escorts S...
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men  🔝manali🔝   Escorts S...➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men  🔝manali🔝   Escorts S...
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men 🔝manali🔝 Escorts S...
nirzagarg
 

Recently uploaded (20)

VIP Model Call Girls Sangvi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Sangvi ( Pune ) Call ON 8005736733 Starting From 5K to 2...VIP Model Call Girls Sangvi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
VIP Model Call Girls Sangvi ( Pune ) Call ON 8005736733 Starting From 5K to 2...
 
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance BookingCall Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
Call Girls Sb Road Call Me 7737669865 Budget Friendly No Advance Booking
 
Budhwar Peth { Russian Call Girls Pune (Adult Only) 8005736733 Escort Servic...
Budhwar Peth { Russian Call Girls Pune  (Adult Only) 8005736733 Escort Servic...Budhwar Peth { Russian Call Girls Pune  (Adult Only) 8005736733 Escort Servic...
Budhwar Peth { Russian Call Girls Pune (Adult Only) 8005736733 Escort Servic...
 
VIP Model Call Girls Wakad ( Pune ) Call ON 8005736733 Starting From 5K to 25...
VIP Model Call Girls Wakad ( Pune ) Call ON 8005736733 Starting From 5K to 25...VIP Model Call Girls Wakad ( Pune ) Call ON 8005736733 Starting From 5K to 25...
VIP Model Call Girls Wakad ( Pune ) Call ON 8005736733 Starting From 5K to 25...
 
(ISHITA) Call Girls Service Malegaon Call Now 8250077686 Malegaon Escorts 24x7
(ISHITA) Call Girls Service Malegaon Call Now 8250077686 Malegaon Escorts 24x7(ISHITA) Call Girls Service Malegaon Call Now 8250077686 Malegaon Escorts 24x7
(ISHITA) Call Girls Service Malegaon Call Now 8250077686 Malegaon Escorts 24x7
 
Hadapsar ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For...
Hadapsar ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For...Hadapsar ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For...
Hadapsar ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For...
 
VVIP Pune Call Girls Viman Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Viman Nagar (7001035870) Pune Escorts Nearby with Comple...VVIP Pune Call Girls Viman Nagar (7001035870) Pune Escorts Nearby with Comple...
VVIP Pune Call Girls Viman Nagar (7001035870) Pune Escorts Nearby with Comple...
 
The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1The Billo Photo Gallery - Cultivated Cuisine T1
The Billo Photo Gallery - Cultivated Cuisine T1
 
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
VIP Model Call Girls Mundhwa ( Pune ) Call ON 8005736733 Starting From 5K to ...
 
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
(ISHITA) Call Girls Service Navi Mumbai Call Now 8250077686 Navi Mumbai Escor...
 
The Most Attractive Pune Call Girls Shikrapur 8250192130 Will You Miss This C...
The Most Attractive Pune Call Girls Shikrapur 8250192130 Will You Miss This C...The Most Attractive Pune Call Girls Shikrapur 8250192130 Will You Miss This C...
The Most Attractive Pune Call Girls Shikrapur 8250192130 Will You Miss This C...
 
Shake Shack: A Sustainable Burger Strategy
Shake Shack: A Sustainable Burger StrategyShake Shack: A Sustainable Burger Strategy
Shake Shack: A Sustainable Burger Strategy
 
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
Lucknow 💋 Cheap Call Girls In Lucknow Get 50% Off On VIP Escorts Service 8923...
 
WhatsApp Chat: 📞 8617697112 Call Girl Reasi is experienced
WhatsApp Chat: 📞 8617697112 Call Girl Reasi is experiencedWhatsApp Chat: 📞 8617697112 Call Girl Reasi is experienced
WhatsApp Chat: 📞 8617697112 Call Girl Reasi is experienced
 
Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)Food & Nutrition Strategy Baseline (FNS.pdf)
Food & Nutrition Strategy Baseline (FNS.pdf)
 
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men 🔝manali🔝 Escorts S...
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men  🔝manali🔝   Escorts S...➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men  🔝manali🔝   Escorts S...
➥🔝 7737669865 🔝▻ manali Call-girls in Women Seeking Men 🔝manali🔝 Escorts S...
 
THE PROCESS OF SALTING AND CURING...pptx
THE PROCESS OF SALTING AND CURING...pptxTHE PROCESS OF SALTING AND CURING...pptx
THE PROCESS OF SALTING AND CURING...pptx
 
Baner Pashan Link Road [ Escorts in Pune ₹7.5k Pick Up & Drop With Cash Payme...
Baner Pashan Link Road [ Escorts in Pune ₹7.5k Pick Up & Drop With Cash Payme...Baner Pashan Link Road [ Escorts in Pune ₹7.5k Pick Up & Drop With Cash Payme...
Baner Pashan Link Road [ Escorts in Pune ₹7.5k Pick Up & Drop With Cash Payme...
 
The Most Attractive Pune Call Girls Sanghavi 8250192130 Will You Miss This Ch...
The Most Attractive Pune Call Girls Sanghavi 8250192130 Will You Miss This Ch...The Most Attractive Pune Call Girls Sanghavi 8250192130 Will You Miss This Ch...
The Most Attractive Pune Call Girls Sanghavi 8250192130 Will You Miss This Ch...
 
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...Katraj ( Call Girls ) Pune  6297143586  Hot Model With Sexy Bhabi Ready For S...
Katraj ( Call Girls ) Pune 6297143586 Hot Model With Sexy Bhabi Ready For S...
 

Audit

  • 1. INELUCTABLE MODALITY OF LINUX AUDIT A story of hate and delectation Faster & Smarter IR
  • 2. SUMUS Mark Ellzey @strcpy - @threatstack Software for down there.
  • 3. !! WARNING !! If you are a current employee of RedHat (specifically on the auditd codebase), and have an extensive background in martial arts, please leave the room now. I would rather not spend the night in a hospital.
  • 4. BLATANT MARKETING SLIDE The contents within are the result of making this product a reality.
  • 5. • Provides information to a user which, in most cases, only the kernel is privy to. • A passive mechanism only; no alteration or control over the data that is being emitted. • Simplistic filtering using boolean logic over a linked list of comparison operations. • Can easily be extended by other kernel APIs, including loadable modules. The Linux Audit System EXORDIUM
  • 6. WRONG! Wait for the din of shocked gasps to become quiescent, then proceed AUDITD & AUDIT ARE MUTUALLY EXCLUSIVE
  • 7. AUDIT IS NOT MAGICAL #define SYSCALL_DEFINEx(x, sname, ...)      SYSCALL_METADATA(sname, x, __VA_ARGS__); ! #define SYSCALL_METADATA(sname, nb, ...)   SYSCALL_TRACE_ENTER_EVENT(sname);        SYSCALL_TRACE_EXIT_EVENT(sname); ! ! auditsys:   movq %r10,%r9   movq %rdx,%r8   movq %rsi,%rcx   movq %rdi,%rdx   movq %rax,%rsi   call __audit_syscall_entry   sysret_audit:   call __audit_syscall_exit code is generated for all syscall entry and exit points
  • 8. audit_syscall_entry audit_syscall_exit • Determines if the syscall should be audited. • Initializes underlying audit_context structure from the current task_struct. • Emits several messages with data associated with the syscall over the netlink socket. • The last message is always of type “AUDIT_EOE” AUDIT IS NOT MAGICAL what is the meaning of this?
  • 9. • return status • execve • sockaddrs • fd pairs • pid / auid / uid / sessionid • current working directories • path information AUDIT IS NOT MAGICAL some various data which is logged at exit
  • 11. FEAR AND LOATHING IN KERNEL/AUDIT.C there can be only one Only one process can read from the audit netlink socket this is a good thing - the kernel only has to maintain one buffer Creating a second reader will hijack the first and will not be restored on exit I get it, otherwise the kernel would be required to keep a backlog stack of processes
  • 12. FEAR AND LOATHING IN KERNEL/AUDIT.C debugging is impossible Prior to linux 3.8, when the audit backlog was hit, and audit_log_start was called during schedule_timeout : a deadlock would occur and fuck you so if you’re in gdb and hit a breakpoint, it was a raging race to disable audit I always forgot. The holes in the walls are a testament to that
  • 13. FORMAT DISAPPROBATION :( The kernel is to blame for this shameful log format! audit_log_format(ab,"a0=%lx a1=%lx a2=%lx a3=%lx items=%d" " ppid=%d pid=%d auid=%u uid=%u gid=%u" " euid=%u suid=%u fsuid=%u"   " egid=%u sgid=%u fsgid=%u tty=%s ses=%u",    context->argv[0], context->argv[1], ...); b u t w h a t i s t h e a l t e r n a t i v e ? You’re insane. A JSON encoder in the kernel? You’re insane. An overly complex binary message format? How about this JSON thing I’ve been hearing so much about?
  • 14. • Everything that comes from the kernel is a key value pair, treat it like so. • Unquoted values are (usually) deemed as “untrusted” strings, encoded as ascii-hex. • The “serial number” is the kernel’s way of designating multiple messages into a single group. It is up to the user-land application to reassemble. • User-land sourced messages are always encapsulated in a key of “msg” • If you were like me, stop bitching and deal with it. Just follow these simple rules FORMAT APPROBATION :)
  • 15. • Performance problems under load. • Limited output format. • Difficult to extend. • Impossible to read. • Poorly designed (opinion). • Did I mention performance issues? • I’ve seen better code in openssl. THINE ENEMY LIES WITHIN LEGACY AUDITING AUDITD
  • 16. The mere presence of a comment containing “Global” is a good sign that the rest will be, in all probability, terrible. Is this what I think it is? Every single message from the kernel is inserted into a thread queue. ! Also: “FIXME” in production code will always induce cringe. THINE ENEMY LIES WITHIN LEGACY
  • 17. GOALS • Lower resource utilization under high load • Extend (or create) logging and filtering capabilities • Keep some backwards compatibility with auditd • Don’t reinvent the wheel, if the wheel isn’t broken • Abstract EVERYTHING • Follow all of the rules in the next slide. DEPRECATION
  • 18. RULE ONE THROUGH ∞ An afterthought in auditd.
  • 19. LIBEV FOR NETWORK AND SIGNAL IO MANUAL NETLINK SOCKET HANDLING LIBEVENT FOR NETWORK AND SIGNAL IO LIBMNL FOR NETLINK SOCKET HANDLING LOW LEVEL PROCESSING THE AUDITD METHOD OUR METHOD
  • 20. !! WARNING !! No statements about how libev is faster than libevent. These comments are usually some variant of regurgitated information based on the flawed performance comparisons found on the libev website. “It’s only cheating if you do it on purpose.”
  • 21. PROCESSING : LIBMNL creating the socket and registering with the kernel
  • 22. PROCESSING : RAW NETLINK creating the socket and registering with the kernel thereisactuallymore
  • 23. PROCESSING : LIBMNL receiving a message from the netlink socket libmnl does all the ugly work
  • 24. PROCESSING : RAW NETLINK receiving a message from the netlink socket thereisactuallymore
  • 25. PROCESSING : MESSAGES post processing runtime grouping The method used by auditd requiring an external application to parse and join multiple messages using the “serial number” as a grouping key. dealing with the raw data The method used by our system which appends data received from the kernel to a list until the final AUDIT_EOE packet has been processed.
  • 26. PROCESSING : MESSAGE GROUPS an abstract example; executing “tail -f tsaudit.log” - serial=43480, type=SYSCALL, syscall=“sys_execve”, exe=“/usr/bin/tail” - serial=43480, type=EXECVE, argc=2, a0=“tail”, a1=“tsaudit.log” - serial=43480, type=CWD, cwd=“/var/log” - serial=43480, type=PATH, name=“/usr/bin/tail” - serial=43480, type=EOE ungrouped grouped [ { “type" : "SYSCALL", “syscall" : "execve", “exe" : "/usr/bin/tail" }, { “type" : "EXECVE", “argc" : 2, “argv” : [ “tail”, “tsaudit.log” ], }, { “type" : "CWD", “cwd" : "/var/log" }, { "type": "PATH", "name": "/usr/bin/tail" } ]
  • 27. PROCESSING : MESSAGE GROUPSA few more fun examples of grouping. [ { "exe": "/bin/cat", "comm": "cat", "ses": 10, "auid": 4294967295, "pid": 31335, "ppid": 31334, "items": 2, "exit": 0, "success": "yes", "syscall": "execve", "epoch": 1399248110, "serial": 855516, "type": "SYSCALL" }, { "a1": "eth0.dhclient", "a0": "cat", "argc": 2, "epoch": 1399248110, "type": "EXECVE" }, { "cwd": "/run/resolvconf/interface", "epoch": 1399248110, "type": "CWD" }, { "name": "/bin/cat", "epoch": 1399248110, "type": "PATH" } ] [ { "res": "success", "terminal": "ssh", "addr": "192.168.56.1", "hostname": "babby.local", "exe": "/usr/sbin/sshd", "acct": "mthomas", "op": "PAM:session_open", "ses": 24, "auid": 1000, "uid": 0, "pid": 10469, "epoch": 1393886985, "serial": 3393, "type": "USER_START" } ] [ { "exe": "/usr/sbin/nginx", "comm": "nginx", "ses": 238, "pid": 966, "ppid": 965, "items": 1, "a3": "fffffffffffffffb", "a2": 0, "a1": "800", "a0": "ee7c05", "exit": 13, "success": "yes", "syscall": "open", "epoch": 1392316421, "serial": 301316, "type": "SYSCALL" }, { "cwd": "/", "type": "CWD" }, { "ogid": 0, "name": "/www/index.html", "type": "PATH" } ] [ { "exe": "/usr/sbin/nginx", "comm": "nginx", "ses": 238, "pid": 966, "ppid": 965, "items": 0, "a3": "800", "a2": "7fff8afba6cc", "a1": "7fff8afba6d0", "a0": 0, "exit": 12, "success": "yes", "syscall": "accept4", "epoch": 1392316421, "serial": 301314, "type": "SYSCALL" }, { "saddr": "192.168.56.1", "port": 51997, "prot": "ipv4", "type": "SOCKADDR" } ] /var/resolvconf/interface$ cat eth0.dhclient nginx: int fd = open(“/www/index.html”); // fd == 13 fd = accept(“192.168.56.1:51997”); user “mthomas” started a pam session
  • 28. PARSING “Every year, one out of ten programmers will commit suicide due to maintaining parsers written in C” Every C developer who has had to maintain a parser in C
  • 29. PARSING AUDIT MESSAGES you be the judge type=SYSCALL msg=audit(1386803107.182:7960575): arch=c000003e syscall=288 success=yes exit=26 a0=7 a1=7fff986ec590 a2=7fff986ec58c a3=800 items=0 ppid=952 pid=956 auid=4294967295 uid=33 gid=33 euid=33 suid=33 fsuid=33 egid=33 sgid=33 fsgid=33 ses=4294967295 tty=(none) comm="nginx" exe="/usr/sbin/nginx" key=(null) BRUTE FORCE ~/Code/auditd$ egrep '(strstr|strchr|strtok|strcmp|strcasecmp|strdup|strcat|sprintf|snprintf)' auparse/*.c | wc -l 448 STATE DRIVEN ~/Code/tsaudit$ egrep '(strstr|strchr|strtok|strcmp|strcasecmp|strdup|strcat|sprintf|snprintf)' auparser/*.c | wc -l 4 AUDITD METHOD OUR METHOD
  • 30. PARSING : BRUTE FORCE oneofmanyhorriblethingsyouwillencounter
  • 31. PARSING : STATE DRIVEN switch/casegenerateslookuptables-faster
  • 32. PARSING AUDIT MESSAGES taking things to the next level TURBO BOOSTING CONDITIONAL LOGIC - Generate a perfect hash table using “gperf”. - Assign “known” keys and values to an enumerable type. - Filter out keys and values which we deemed unnecessary for further processing - Add validation and auto-parsers for specific key values. - Determine if the value of a key can be treated as a different data type, such as an integer or boolean.
  • 33. SO WE CAN DO STUFF LIKE THIS with perfect hash tables - lookups are O(1)
  • 35. FILTERING optionally preprocess data before it is logged -Load per-instance or per-output LUA script during startup. -Convert the grouped messages to a native LUA table. -Call a pre-defined LUA function. -A non-zero return will drop the message. -A zero return will continue processing the message -If a LUA table is returned, it is converted to JSON and used as the output.
  • 36. FILTERING Example : simple boolean filter
  • 37. FILTERING Example : return a table which is converted to JSON on output function find_set(k, set) for _,v in pairs(set) do if k == v then return 1 end end return 0 end ! ! function tsaudit_filter(data) local ret = {} local comms = { 'irqbalance', 'whoopsie', 'top', 'dhclient' } ! for k,ent in pairs(data) do if find_set(ent['comm'], comms) == 1 then -- if any of the keys are found, return this table which will be -- transformed into the JSON { "this" : "filtered", "dont" : "log" } ret = {this="filtered", dont="log" } end ! if ent['success'] == 'no' then -- if the syscall did not succeed, then return 1 which will not generate a -- log. ret = 1 end end ! return ret end
  • 38. LOGGING : AUDITD 1. File 2. There is no 2 OUTPUT TYPES Don’t worry, auditd can be extended with “audispd” plugins!
  • 39. AUDISPD : A MONUMENTAL HACK For each plugin, audispd will fork, execve, and send audit messages to stdout. A plugin just has to have the ability to read from stdin. if this design seems sane to you, keep it a secret, and start sharpening that programming knife new term : “infinite noose”
  • 40. LOGGING : OUR WAY 1. ZeroMQ 2. Syslog 3. Audit Emulator 4. AIO 5. Raw 6. Nanomsg jsonpluggable chained inlined OUTPUT TYPES as of right now
  • 41. ACCESSION meticulous attention to abstraction enhances creativity A fully functional auditd’esque application can be written in under 50 lines of C. Introduced many other autonomous inputs which can be integrated seamlessly. • rtnetlink • netlink connector • netlink inet diag • netlink task stats • pcap data • userland audit
  • 42. consummation I am your typical developer. “I can do better than that!” Usually a dumb statement to make, so was it worth it? Running apache bench (ab) at 10,000 requests per second AUDITD 120% CPU OUR REWRITE 10% CPU I think that’s better.
  • 43. • Additional methods for grouping related data, further reducing overhead. • Add simple analysis and statistical gathering functionality. • Continue abstractions to avoid the potential bloat that comes with feature- creep CEREBRATION