SlideShare a Scribd company logo
THERE’S GOLD IN 

THEM THAR PACKAGE
MANAGEMENT DATABASES!
Phil Hagen
phil@lewestech.com

@PhilHagen

plus.google.com/+PhilHagen

Image: flickr.com/matthigh
WHY ARE WE HERE?
Goals:	

Describe the value of package management databases during
the course of a Linux system forensic examination	

Provide information with immediate benefit!

2
WHO IS THIS GUY?
Forensic/infosec consultant	

Former DoD/IC contractor, USAF
Comm Officer (USAFA CompSci)	

Course lead, FOR572: Advanced
Network Forensics  Analysis	

Linux guy since Slackware needed
a stack of floppies and an
unsupported SCSI controller
meant bootstrapping a kernel
compilation
3
OPEN SOURCE: INFINITE POWER
	


	


	


	


	


	


	


	


	


(ITTY BITTY LIVING SPACE)

Downloading and compiling source code is an amazingly powerful
aspect of most open-source software	

Not viable for the large scale of a production environment	

Does not address dependencies	

No common install/uninstall process	

Fun for the lab or a hobbyist environment, but a headache in
an operational environment

4
PACKAGE MANAGEMENT
SOFTWARE TO THE RESCUE!
Dependencies, file manifests, install/uninstall/upgrade scripts	

Generally makes software management less of a headache!	

Many solutions in widespread use among various distributions:	

opkg (fork of ipkg): Embedded devices like QNAP NAS, etc.	

dpkg: Debian and Ubuntu	

tgz: Slackware	

RPM: RedHat, CentOS, Fedora,many more

(part of Linux Standard Base)
5
…STILL NOT END-ALL/BE-ALL
Most incorporate higher-layer software to handle automatic
inclusion of dependencies and other “meta” functions and avoid the
much-feared “dependency hell” or “RPM hell”	

apt-get / aptitude	

YUM	

RedHat Network	

Not focusing on this higher-layer software	

Some useful artifacts available - bad guys 

known to “yum install nmap”
6
SCOPE FOR THIS PRESENTATION
Just looking at RPM	

Most concepts apply to other package management standards	

Notably dpkg	

All examples created and tested on CentOS 6.5	

Ideally: Same OS as subject (RPM library versions, etc)	

Technically: Same version of RPM, BDB, related libraries	

May have some success with unmatched versions, but beware!!	

Presentation notes (including all commands) published soon	

http://stuffphilwrites.com
7
SOURCES FOR RPM EVIDENCE
Populates Berkeley database	

Lives in /var/lib/rpm/	

Includes metadata for every
RPM-controlled file	

User/Group ownership	

Mode (aka permissions)	

MD5 (er… SHA256)
checksum	

File size	


Major/minor number (For
entries in /dev/)	

Symbolic link string (aka
“target”) for symlinks	

Modification time	

/var/log/yum.log	

May have useful timestamped
history of install/remove/
upgrade actions	

/var/log/rpmpkgs*
8
PRACTICAL USAGE
1. Mount all partitions from subject filesystem under /mnt/subject/	

$ mount | grep subject

/dev/mapper/vg_centos6vm-lv_root on /mnt/
subject type ext4 (ro,noload)

/dev/mapper/loop0p1 on /mnt/subject/boot type
ext4 (ro,noload)
2. Run RPM commands with “--root /mnt/subject” option	

Don’t trust the rpm(1) binary from a suspect system!	

Note: This performs a chroot(2) for all operations - needs root
user privileges for validation (not query) actions
9
USE CASE:

FILE ORIGIN
$ rpm -qf filename
Identifies what package owns the specified file	

Useful to answer “where did this file come from?” or to identify a file
as package-less	

$ rpm --root /mnt/subject -qf /usr/sbin/sshd

openssh-server-5.3p1-94.el6.x86_64
$ rpm --root /mnt/subject -qf /etc/mail.rc
 Remember	

chroot!
mailx-12.4-7.el6.x86_64
$ rpm --root /mnt/subject -qf /etc/crypttab

file /etc/crypttab is not owned by any package
10
USE CASE:

PACKAGE VALIDATION (1)
$ rpm -V packagename
Verifies contents of specified package	

Compares expected (database) to actual (filesystem)	

Displays files that failed =1 check, noting which checks failed	

SM5DLUGT (Size, mode, MD5 (or SHA256!), major/minor nos,
link target, user, group, mtime)	

Shows “?” in output if user running command lacks
permission to check (e.g. read access to generate checksums)
11
USE CASE:

PACKAGE VALIDATION (2)
WARNING!!!
Packages can include “verification scripts” which will execute
when the “-V” option is used!	

You’re not planning to run arbitrary, unknown code on your
forensic workstation/VM, are you?	

The chroot action needs root - these will execute as a
child to the sudo process!	

Use the “--noscripts option with “-V” to prevent this
12
USE CASE:	

PACKAGE VALIDATION (3)
Some files are expected to change after installation: config files!	

Still show changes after installation, but denoted with a “c”
character	

Missing files also noted in output as such	

$ sudo rpm --root /mnt/subject 

-V openssh-server --noscripts

no output
$ sudo rpm --root /mnt/subject 

-V sudo --noscripts

S.5....T. c /etc/sudoers
13
USE CASE:	

PACKAGE VALIDATION (4)
$ sudo rpm
S.5....T.
.M.......
S.5....T.
....L....
....L....
....L....
....L....
..5....T.

--root /mnt/subject -Va --noscripts

c /etc/sudoers

/proc

c /etc/maven/maven2-depmap.xml

c /etc/pam.d/fingerprint-auth

c /etc/pam.d/password-auth

c /etc/pam.d/smartcard-auth

c /etc/pam.d/system-auth

c /usr/lib64/security/

classpath.security

$ rpm -root /mnt/subject —V postfix --noscripts

missing
c /etc/postfix/master.cf
14
COOL FEATURE ALERT!
Many packages are GPG-signed	

Independently verify package
without using compromised or
untrusted system	

However: RPM database contents
not signed: Trojaned RPM package
reports no anomalies!	

How can we use this great
feature to our advantage?
15
VALIDATE FILESYSTEM

AGAINST A PACKAGE FILE (1)
The “-p” option runs validation checks between filesystem contents and
RPM package file contents	

Signed package files can be GPG-verified!	

Avoids an untrusted RPM database entirely	

Prevents false negative validation from compromised RPM installations	

Relatively simple process:	

1. Download trusted binary RPM file	

2. Validate RPM file using GPG	

3. Validate filesystem contents against package contents
16
VALIDATE FILESYSTEM

AGAINST A PACKAGE FILE (2)
Consider a system with a compromised RPM database, or a trojaned
installation of the Apache web server software	

$ rpm --root /mnt/subject -V httpd --noscripts

S.5....T c /etc/httpd/conf/httpd.conf
$ wget http://mirror.centos.org/centos-5/5.10/os/
x86_64/CentOS/httpd-2.2.3-82.el5.centos.x86_64.rpm

$ rpm -K httpd-2.2.3-82.el5.centos.x86_64.rpm

httpd-2.2.3-82.el5.centos.x86_64.rpm: (sha1) dsa sha1
md5 gpg OK

$ rpm --root /mnt/subject -Vp
httpd-2.2.3-82.el5.centos.x86_64.rpm --noscripts

S.5....T c /etc/httpd/conf/httpd.conf

S.5....T
/usr/sbin/httpd
17
REAL-WORLD USE CASES (1)
Find all non-config files owned by an RPM that fails a verification check	

$ sudo rpm --root /mnt/subject -Va --noscripts | 

grep -v  c 

...

S.5....T
/var/www/awstats/lang/awstats-tt-tr.txt

S.5....T
/var/www/awstats/lang/awstats-tt-tw.txt

S.5....T
/var/www/awstats/lang/awstats-tt-ua.txt

.......T
/var/www/awstats/lib/blacklist.txt

S.5....T
/var/www/awstats/lib/browsers.pm

S.5....T
/var/www/awstats/lib/browsers_phone.pm

...

18
REAL-WORLD USE CASES (2)
File only config files owned by an RPM, which fail checksum verification	

$ sudo rpm --root /mnt/subject -Va --noscripts | 

grep ^..5..... c 

S.5....T c /etc/pam.d/sshd

S.5....T c /etc/ssh/sshd_config

S.5....T c /etc/openldap/slapd.conf

S.5....T c /etc/sysconfig/ldap

S.5..... c /etc/sysconfig/saslauthd

S.5..... c /etc/security/limits.conf

S.5....T c /etc/logrotate.conf

SM5....T c /etc/snmp/snmpd.conf

S.5....T c /etc/sysconfig/snmpd.options

...
19
REAL-WORLD USE CASES (3A)
Find all files not owned by an RPM (This is going to be slow!)	

$ cat find_orphans.sh

for file in $( sudo find /mnt/subject/etc -type f ); do

file=$( echo $file | sed -e 's//mnt/subject//' )

rpm --root /mnt/subject -qf $file 21 | 

grep 'package$|directory$' | 

sed -E 's/^(error: )?file (.*)(: No such file or
directory| is not owned by any package)/2/'

done
$ ./find_orphans.sh

/etc/crypttab

/etc/sysconfig/network

/etc/sysconfig/keyboard

/etc/sysconfig/iptables

...
20
REAL-WORLD USE CASES (3B)
Find all files not owned by an RPM (This is going to be slow!)	

$ ./find_orphans.sh

/etc/crypttab

/etc/sysconfig/network

/etc/sysconfig/keyboard

/etc/sysconfig/iptables

...

21
COOL PARTY TRICK (1)
!

Use the “--queryformat” option to output only relevant/useful fields
from the RPM database	

Provides 150 different tags that can be output for package or for each file
in a package	

Available tags vary by version - online documentation is terrible	

Use “--querytags” for listing specific to your version of RPM	

!

Consider “RPMDBtoTimeline”…
22
COOL PARTY TRICK (2)*
$ for pkg in $( rpm --root /mnt/subject -qa ) ; do

rpm --root /mnt/subject -q $pkg --queryformat 

[%{FILEDIGESTS}|%{FILENAMES}|0|%{FILEMODES:perms}|

%{FILEUSERNAME}|%{FILEGROUPNAME}|%{FILESIZES}|0|

%{FILEMTIMES}|0|0n] | sed -e 's/^|/0|/' 

-e 's/|0|d/|0|d/d/' -e ’s/|0|-/|0|r/r/' 

done

...

4398551f...a13988cf|/usr/share/doc/gamin-0.1.10/
callbacks.gif|0|r/rrw-r—r—|root|root|4514|0|1183556209|0|0

0|/usr/lib64/libmenuw.so.5|0|lrwxrwxrwx|root|root|15|0|
1282146079|0|0

0|/usr/share/cracklib|0|d/drwxr-xr-x|root|root|4096|0|
1308983949|0|0

...

* “Cool” claim not valid at all parties. YMMV.

23
IN CONCLUSION
RPM is a pretty cool way to eliminate known files from a Linux
system examination	

Know the shortcomings in the RPM package database so you can
mitigate them	

With a little shell scripting,

you can develop useful tools to

quickly and consistently

minimize input data
SANS @Night There's Gold in Them Thar Package Management Databases

More Related Content

What's hot

DevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
DevOps Fest 2020. Philipp Krenn. Scale Your Auditing EventsDevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
DevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
DevOps_Fest
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Valeriy Kravchuk
 
Kdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisKdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysis
Buland Singh
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
Alessandro Selli
 
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
NETWAYS
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
LGS, GBHS&IC, University Of South-Asia, TARA-Technologies
 
2009-08-24 The Linux Audit Subsystem Deep Dive
2009-08-24 The Linux Audit Subsystem Deep Dive2009-08-24 The Linux Audit Subsystem Deep Dive
2009-08-24 The Linux Audit Subsystem Deep Dive
Shawn Wells
 
Ansible ex407 and EX 294
Ansible ex407 and EX 294Ansible ex407 and EX 294
Ansible ex407 and EX 294
IkiArif1
 
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
Satpal Parmar
 
aptly: Debian repository management tool
aptly: Debian repository management toolaptly: Debian repository management tool
aptly: Debian repository management tool
Andrey Smirnov
 
Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPM
Alexander Shopov
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
Robert Postill
 
Windows persistence presentation
Windows persistence presentationWindows persistence presentation
Windows persistence presentation
OlehLevytskyi1
 
Samba 4 - debian instalacao
Samba 4 - debian instalacaoSamba 4 - debian instalacao
Samba 4 - debian instalacao
Eduardo Charquero
 
Audit commands by shift
Audit commands by shiftAudit commands by shift
Audit commands by shift
Gary Smith
 
The Linux Audit Framework
The Linux Audit FrameworkThe Linux Audit Framework
The Linux Audit Framework
Gary Smith
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationMohammed Farrag
 
Crash_Report_Mechanism_In_Tizen
Crash_Report_Mechanism_In_TizenCrash_Report_Mechanism_In_Tizen
Crash_Report_Mechanism_In_TizenLex Yu
 

What's hot (20)

DevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
DevOps Fest 2020. Philipp Krenn. Scale Your Auditing EventsDevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
DevOps Fest 2020. Philipp Krenn. Scale Your Auditing Events
 
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
Tracing MariaDB server with bpftrace - MariaDB Server Fest 2021
 
Kdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysisKdump and the kernel crash dump analysis
Kdump and the kernel crash dump analysis
 
Linux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compactLinux Capabilities - eng - v2.1.5, compact
Linux Capabilities - eng - v2.1.5, compact
 
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
OSBConf 2015 | Backups with rdiff backup and rsnapshot by christoph mitasch &...
 
50 Most Frequently Used UNIX Linux Commands -hmftj
50 Most Frequently Used UNIX  Linux Commands -hmftj50 Most Frequently Used UNIX  Linux Commands -hmftj
50 Most Frequently Used UNIX Linux Commands -hmftj
 
2009-08-24 The Linux Audit Subsystem Deep Dive
2009-08-24 The Linux Audit Subsystem Deep Dive2009-08-24 The Linux Audit Subsystem Deep Dive
2009-08-24 The Linux Audit Subsystem Deep Dive
 
Ansible ex407 and EX 294
Ansible ex407 and EX 294Ansible ex407 and EX 294
Ansible ex407 and EX 294
 
50 most frequently used unix
50 most frequently used unix50 most frequently used unix
50 most frequently used unix
 
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
 
aptly: Debian repository management tool
aptly: Debian repository management toolaptly: Debian repository management tool
aptly: Debian repository management tool
 
Bundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPMBundling Packages and Deploying Applications with RPM
Bundling Packages and Deploying Applications with RPM
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
Windows persistence presentation
Windows persistence presentationWindows persistence presentation
Windows persistence presentation
 
Samba 4 - debian instalacao
Samba 4 - debian instalacaoSamba 4 - debian instalacao
Samba 4 - debian instalacao
 
Audit
AuditAudit
Audit
 
Audit commands by shift
Audit commands by shiftAudit commands by shift
Audit commands by shift
 
The Linux Audit Framework
The Linux Audit FrameworkThe Linux Audit Framework
The Linux Audit Framework
 
Lecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administrationLecture 3 Perl & FreeBSD administration
Lecture 3 Perl & FreeBSD administration
 
Crash_Report_Mechanism_In_Tizen
Crash_Report_Mechanism_In_TizenCrash_Report_Mechanism_In_Tizen
Crash_Report_Mechanism_In_Tizen
 

Viewers also liked

Logs, Logs, Every Where, Nor Any Byte to Grok
Logs, Logs, Every Where, Nor Any Byte to GrokLogs, Logs, Every Where, Nor Any Byte to Grok
Logs, Logs, Every Where, Nor Any Byte to Grok
Phil Hagen
 
(Fios#02) 2. elk 포렌식 분석
(Fios#02) 2. elk 포렌식 분석(Fios#02) 2. elk 포렌식 분석
(Fios#02) 2. elk 포렌식 분석
INSIGHT FORENSIC
 
WMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARESWMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARES
Santhosh Kumar
 
Windows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIWindows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMI
junichi anno
 
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin FalckLuncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
North Texas Chapter of the ISSA
 
SOC2016 - The Investigation Labyrinth
SOC2016 - The Investigation LabyrinthSOC2016 - The Investigation Labyrinth
SOC2016 - The Investigation Labyrinth
chrissanders88
 
Abstract Tools for Effective Threat Hunting
Abstract Tools for Effective Threat HuntingAbstract Tools for Effective Threat Hunting
Abstract Tools for Effective Threat Hunting
chrissanders88
 

Viewers also liked (8)

Logs, Logs, Every Where, Nor Any Byte to Grok
Logs, Logs, Every Where, Nor Any Byte to GrokLogs, Logs, Every Where, Nor Any Byte to Grok
Logs, Logs, Every Where, Nor Any Byte to Grok
 
(Fios#02) 2. elk 포렌식 분석
(Fios#02) 2. elk 포렌식 분석(Fios#02) 2. elk 포렌식 분석
(Fios#02) 2. elk 포렌식 분석
 
WMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARESWMI - A FRONT DOOR FOR MALWARES
WMI - A FRONT DOOR FOR MALWARES
 
Windows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMIWindows スクリプトセミナー WMI編 VBScript&WMI
Windows スクリプトセミナー WMI編 VBScript&WMI
 
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin FalckLuncheon 2016-07-16 -  Topic 2 - Advanced Threat Hunting by Justin Falck
Luncheon 2016-07-16 - Topic 2 - Advanced Threat Hunting by Justin Falck
 
SOC2016 - The Investigation Labyrinth
SOC2016 - The Investigation LabyrinthSOC2016 - The Investigation Labyrinth
SOC2016 - The Investigation Labyrinth
 
Abstract Tools for Effective Threat Hunting
Abstract Tools for Effective Threat HuntingAbstract Tools for Effective Threat Hunting
Abstract Tools for Effective Threat Hunting
 
Computer forensics ppt
Computer forensics pptComputer forensics ppt
Computer forensics ppt
 

Similar to SANS @Night There's Gold in Them Thar Package Management Databases

Install tomcat 5.5 in debian os and deploy war file
Install tomcat 5.5 in debian os and deploy war fileInstall tomcat 5.5 in debian os and deploy war file
Install tomcat 5.5 in debian os and deploy war file
Nguyen Cao Hung
 
Slackware Demystified [SELF 2011]
Slackware Demystified [SELF 2011]Slackware Demystified [SELF 2011]
Slackware Demystified [SELF 2011]
Vincent Batts
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
Information Technology
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
Jameel Nabbo
 
Andresen 8 21 02
Andresen 8 21 02Andresen 8 21 02
Andresen 8 21 02
FNian
 
Linux security quick reference guide
Linux security quick reference guideLinux security quick reference guide
Linux security quick reference guideCraig Cannon
 
Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)
Ata Rehman
 
Introduction to JumpStart
Introduction to JumpStartIntroduction to JumpStart
Introduction to JumpStart
Scott McDermott
 
MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)
Masami Hiramatsu
 
FreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleFreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleMohammed Farrag
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
Keith Wright
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
Hazel Smith
 
Linux Common Command
Linux Common CommandLinux Common Command
Linux Common Command
Jeff Yang
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
Michael J Geiser
 
Rpm Introduction
Rpm IntroductionRpm Introduction
Rpm Introduction
Shrinivasan T
 
Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Prague
tomasbart
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
Carlos Sanchez
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologist
Ajay Murali
 

Similar to SANS @Night There's Gold in Them Thar Package Management Databases (20)

Install tomcat 5.5 in debian os and deploy war file
Install tomcat 5.5 in debian os and deploy war fileInstall tomcat 5.5 in debian os and deploy war file
Install tomcat 5.5 in debian os and deploy war file
 
Slackware Demystified [SELF 2011]
Slackware Demystified [SELF 2011]Slackware Demystified [SELF 2011]
Slackware Demystified [SELF 2011]
 
Unix Administration 2
Unix Administration 2Unix Administration 2
Unix Administration 2
 
Linux advanced privilege escalation
Linux advanced privilege escalationLinux advanced privilege escalation
Linux advanced privilege escalation
 
Andresen 8 21 02
Andresen 8 21 02Andresen 8 21 02
Andresen 8 21 02
 
Ch23 system administration
Ch23 system administration Ch23 system administration
Ch23 system administration
 
Linux filesystemhierarchy
Linux filesystemhierarchyLinux filesystemhierarchy
Linux filesystemhierarchy
 
Linux security quick reference guide
Linux security quick reference guideLinux security quick reference guide
Linux security quick reference guide
 
Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)Advanced Level Training on Koha / TLS (ToT)
Advanced Level Training on Koha / TLS (ToT)
 
Introduction to JumpStart
Introduction to JumpStartIntroduction to JumpStart
Introduction to JumpStart
 
MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)MINCS - containers in the shell script (Eng. ver.)
MINCS - containers in the shell script (Eng. ver.)
 
FreeBSD Jail Complete Example
FreeBSD Jail Complete ExampleFreeBSD Jail Complete Example
FreeBSD Jail Complete Example
 
Linux Troubleshooting
Linux TroubleshootingLinux Troubleshooting
Linux Troubleshooting
 
Using filesystem capabilities with rsync
Using filesystem capabilities with rsyncUsing filesystem capabilities with rsync
Using filesystem capabilities with rsync
 
Linux Common Command
Linux Common CommandLinux Common Command
Linux Common Command
 
Really useful linux commands
Really useful linux commandsReally useful linux commands
Really useful linux commands
 
Rpm Introduction
Rpm IntroductionRpm Introduction
Rpm Introduction
 
Docker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in PragueDocker and friends at Linux Days 2014 in Prague
Docker and friends at Linux Days 2014 in Prague
 
Continuous Delivery: The Next Frontier
Continuous Delivery: The Next FrontierContinuous Delivery: The Next Frontier
Continuous Delivery: The Next Frontier
 
Linux basic for CADD biologist
Linux basic for CADD biologistLinux basic for CADD biologist
Linux basic for CADD biologist
 

Recently uploaded

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
Abida Shariff
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Thierry Lestable
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptxIOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
IOS-PENTESTING-BEGINNERS-PRACTICAL-GUIDE-.pptx
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
Empowering NextGen Mobility via Large Action Model Infrastructure (LAMI): pav...
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 

SANS @Night There's Gold in Them Thar Package Management Databases

  • 1. THERE’S GOLD IN 
 THEM THAR PACKAGE MANAGEMENT DATABASES! Phil Hagen phil@lewestech.com
 @PhilHagen
 plus.google.com/+PhilHagen Image: flickr.com/matthigh
  • 2. WHY ARE WE HERE? Goals: Describe the value of package management databases during the course of a Linux system forensic examination Provide information with immediate benefit! 2
  • 3. WHO IS THIS GUY? Forensic/infosec consultant Former DoD/IC contractor, USAF Comm Officer (USAFA CompSci) Course lead, FOR572: Advanced Network Forensics Analysis Linux guy since Slackware needed a stack of floppies and an unsupported SCSI controller meant bootstrapping a kernel compilation 3
  • 4. OPEN SOURCE: INFINITE POWER (ITTY BITTY LIVING SPACE) Downloading and compiling source code is an amazingly powerful aspect of most open-source software Not viable for the large scale of a production environment Does not address dependencies No common install/uninstall process Fun for the lab or a hobbyist environment, but a headache in an operational environment 4
  • 5. PACKAGE MANAGEMENT SOFTWARE TO THE RESCUE! Dependencies, file manifests, install/uninstall/upgrade scripts Generally makes software management less of a headache! Many solutions in widespread use among various distributions: opkg (fork of ipkg): Embedded devices like QNAP NAS, etc. dpkg: Debian and Ubuntu tgz: Slackware RPM: RedHat, CentOS, Fedora,many more
 (part of Linux Standard Base) 5
  • 6. …STILL NOT END-ALL/BE-ALL Most incorporate higher-layer software to handle automatic inclusion of dependencies and other “meta” functions and avoid the much-feared “dependency hell” or “RPM hell” apt-get / aptitude YUM RedHat Network Not focusing on this higher-layer software Some useful artifacts available - bad guys 
 known to “yum install nmap” 6
  • 7. SCOPE FOR THIS PRESENTATION Just looking at RPM Most concepts apply to other package management standards Notably dpkg All examples created and tested on CentOS 6.5 Ideally: Same OS as subject (RPM library versions, etc) Technically: Same version of RPM, BDB, related libraries May have some success with unmatched versions, but beware!! Presentation notes (including all commands) published soon http://stuffphilwrites.com 7
  • 8. SOURCES FOR RPM EVIDENCE Populates Berkeley database Lives in /var/lib/rpm/ Includes metadata for every RPM-controlled file User/Group ownership Mode (aka permissions) MD5 (er… SHA256) checksum File size Major/minor number (For entries in /dev/) Symbolic link string (aka “target”) for symlinks Modification time /var/log/yum.log May have useful timestamped history of install/remove/ upgrade actions /var/log/rpmpkgs* 8
  • 9. PRACTICAL USAGE 1. Mount all partitions from subject filesystem under /mnt/subject/ $ mount | grep subject
 /dev/mapper/vg_centos6vm-lv_root on /mnt/ subject type ext4 (ro,noload)
 /dev/mapper/loop0p1 on /mnt/subject/boot type ext4 (ro,noload) 2. Run RPM commands with “--root /mnt/subject” option Don’t trust the rpm(1) binary from a suspect system! Note: This performs a chroot(2) for all operations - needs root user privileges for validation (not query) actions 9
  • 10. USE CASE:
 FILE ORIGIN $ rpm -qf filename Identifies what package owns the specified file Useful to answer “where did this file come from?” or to identify a file as package-less $ rpm --root /mnt/subject -qf /usr/sbin/sshd
 openssh-server-5.3p1-94.el6.x86_64 $ rpm --root /mnt/subject -qf /etc/mail.rc
 Remember chroot! mailx-12.4-7.el6.x86_64 $ rpm --root /mnt/subject -qf /etc/crypttab
 file /etc/crypttab is not owned by any package 10
  • 11. USE CASE:
 PACKAGE VALIDATION (1) $ rpm -V packagename Verifies contents of specified package Compares expected (database) to actual (filesystem) Displays files that failed =1 check, noting which checks failed SM5DLUGT (Size, mode, MD5 (or SHA256!), major/minor nos, link target, user, group, mtime) Shows “?” in output if user running command lacks permission to check (e.g. read access to generate checksums) 11
  • 12. USE CASE:
 PACKAGE VALIDATION (2) WARNING!!! Packages can include “verification scripts” which will execute when the “-V” option is used! You’re not planning to run arbitrary, unknown code on your forensic workstation/VM, are you? The chroot action needs root - these will execute as a child to the sudo process! Use the “--noscripts option with “-V” to prevent this 12
  • 13. USE CASE: PACKAGE VALIDATION (3) Some files are expected to change after installation: config files! Still show changes after installation, but denoted with a “c” character Missing files also noted in output as such $ sudo rpm --root /mnt/subject 
 -V openssh-server --noscripts
 no output $ sudo rpm --root /mnt/subject 
 -V sudo --noscripts
 S.5....T. c /etc/sudoers 13
  • 14. USE CASE: PACKAGE VALIDATION (4) $ sudo rpm S.5....T. .M....... S.5....T. ....L.... ....L.... ....L.... ....L.... ..5....T. --root /mnt/subject -Va --noscripts
 c /etc/sudoers
 /proc
 c /etc/maven/maven2-depmap.xml
 c /etc/pam.d/fingerprint-auth
 c /etc/pam.d/password-auth
 c /etc/pam.d/smartcard-auth
 c /etc/pam.d/system-auth
 c /usr/lib64/security/
 classpath.security $ rpm -root /mnt/subject —V postfix --noscripts
 missing c /etc/postfix/master.cf 14
  • 15. COOL FEATURE ALERT! Many packages are GPG-signed Independently verify package without using compromised or untrusted system However: RPM database contents not signed: Trojaned RPM package reports no anomalies! How can we use this great feature to our advantage? 15
  • 16. VALIDATE FILESYSTEM
 AGAINST A PACKAGE FILE (1) The “-p” option runs validation checks between filesystem contents and RPM package file contents Signed package files can be GPG-verified! Avoids an untrusted RPM database entirely Prevents false negative validation from compromised RPM installations Relatively simple process: 1. Download trusted binary RPM file 2. Validate RPM file using GPG 3. Validate filesystem contents against package contents 16
  • 17. VALIDATE FILESYSTEM
 AGAINST A PACKAGE FILE (2) Consider a system with a compromised RPM database, or a trojaned installation of the Apache web server software $ rpm --root /mnt/subject -V httpd --noscripts
 S.5....T c /etc/httpd/conf/httpd.conf $ wget http://mirror.centos.org/centos-5/5.10/os/ x86_64/CentOS/httpd-2.2.3-82.el5.centos.x86_64.rpm
 $ rpm -K httpd-2.2.3-82.el5.centos.x86_64.rpm
 httpd-2.2.3-82.el5.centos.x86_64.rpm: (sha1) dsa sha1 md5 gpg OK
 $ rpm --root /mnt/subject -Vp httpd-2.2.3-82.el5.centos.x86_64.rpm --noscripts
 S.5....T c /etc/httpd/conf/httpd.conf
 S.5....T /usr/sbin/httpd 17
  • 18. REAL-WORLD USE CASES (1) Find all non-config files owned by an RPM that fails a verification check $ sudo rpm --root /mnt/subject -Va --noscripts | 
 grep -v c 
 ...
 S.5....T /var/www/awstats/lang/awstats-tt-tr.txt
 S.5....T /var/www/awstats/lang/awstats-tt-tw.txt
 S.5....T /var/www/awstats/lang/awstats-tt-ua.txt
 .......T /var/www/awstats/lib/blacklist.txt
 S.5....T /var/www/awstats/lib/browsers.pm
 S.5....T /var/www/awstats/lib/browsers_phone.pm
 ... 18
  • 19. REAL-WORLD USE CASES (2) File only config files owned by an RPM, which fail checksum verification $ sudo rpm --root /mnt/subject -Va --noscripts | 
 grep ^..5..... c 
 S.5....T c /etc/pam.d/sshd
 S.5....T c /etc/ssh/sshd_config
 S.5....T c /etc/openldap/slapd.conf
 S.5....T c /etc/sysconfig/ldap
 S.5..... c /etc/sysconfig/saslauthd
 S.5..... c /etc/security/limits.conf
 S.5....T c /etc/logrotate.conf
 SM5....T c /etc/snmp/snmpd.conf
 S.5....T c /etc/sysconfig/snmpd.options
 ... 19
  • 20. REAL-WORLD USE CASES (3A) Find all files not owned by an RPM (This is going to be slow!) $ cat find_orphans.sh
 for file in $( sudo find /mnt/subject/etc -type f ); do
 file=$( echo $file | sed -e 's//mnt/subject//' )
 rpm --root /mnt/subject -qf $file 21 | 
 grep 'package$|directory$' | 
 sed -E 's/^(error: )?file (.*)(: No such file or directory| is not owned by any package)/2/'
 done $ ./find_orphans.sh
 /etc/crypttab
 /etc/sysconfig/network
 /etc/sysconfig/keyboard
 /etc/sysconfig/iptables
 ... 20
  • 21. REAL-WORLD USE CASES (3B) Find all files not owned by an RPM (This is going to be slow!) $ ./find_orphans.sh
 /etc/crypttab
 /etc/sysconfig/network
 /etc/sysconfig/keyboard
 /etc/sysconfig/iptables
 ... 21
  • 22. COOL PARTY TRICK (1) ! Use the “--queryformat” option to output only relevant/useful fields from the RPM database Provides 150 different tags that can be output for package or for each file in a package Available tags vary by version - online documentation is terrible Use “--querytags” for listing specific to your version of RPM ! Consider “RPMDBtoTimeline”… 22
  • 23. COOL PARTY TRICK (2)* $ for pkg in $( rpm --root /mnt/subject -qa ) ; do
 rpm --root /mnt/subject -q $pkg --queryformat 
 [%{FILEDIGESTS}|%{FILENAMES}|0|%{FILEMODES:perms}|
 %{FILEUSERNAME}|%{FILEGROUPNAME}|%{FILESIZES}|0|
 %{FILEMTIMES}|0|0n] | sed -e 's/^|/0|/' 
 -e 's/|0|d/|0|d/d/' -e ’s/|0|-/|0|r/r/' 
 done
 ...
 4398551f...a13988cf|/usr/share/doc/gamin-0.1.10/ callbacks.gif|0|r/rrw-r—r—|root|root|4514|0|1183556209|0|0
 0|/usr/lib64/libmenuw.so.5|0|lrwxrwxrwx|root|root|15|0| 1282146079|0|0
 0|/usr/share/cracklib|0|d/drwxr-xr-x|root|root|4096|0| 1308983949|0|0
 ... * “Cool” claim not valid at all parties. YMMV. 23
  • 24. IN CONCLUSION RPM is a pretty cool way to eliminate known files from a Linux system examination Know the shortcomings in the RPM package database so you can mitigate them With a little shell scripting,
 you can develop useful tools to
 quickly and consistently
 minimize input data