LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-10-2014, 07:56 AM   #1
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Rep: Reputation: 25
How to make apt-get execute a script?


Yes sir!

When using a debian-based distro with the apt package manager, how can I make the package manager execute a certain script of my choice, if the package manager modifies at least one file in a given folder? For example I would like to have it use a script to automatically update a list of file hashes inside the /boot folder, and sign the hash list file with gpg when updating the distro with "apt-get upgrade" command. But this should only happen when at least one of the files inside the /boot folder has been modified, deleted, added, updated, etc.

Is this possible?
 
Old 01-10-2014, 08:18 AM   #2
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
Taken from /etc/apt/apt.conf.d/05etckeeper

Code:
DPkg::Pre-Invoke       { "if [ -x /usr/sbin/etckeeper ]; then etckeeper pre-install; fi"; };
DPkg::Post-Invoke      { "if [ -x /usr/sbin/etckeeper ]; then etckeeper post-install; fi"; };

RPM::Pre-Invoke       { "if [ -x /usr/sbin/etckeeper ]; then etckeeper pre-install; fi"; };
RPM::Post-Invoke      { "if [ -x /usr/sbin/etckeeper ]; then etckeeper post-install; fi"; };
So you would write a shell script that would do your logic and have that called by apt.

How to find out if file in boot are altered could pose a challenge. Also you could pre-invoke'd md5sum all and post-invoke'd md5sum all within /boot. Compare the two list and you should be set.
 
Old 01-10-2014, 08:59 AM   #3
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
If you only want to monitor file changes in /boot I wouldn't do it with apt-get, but with inotify, a kernel subsystem to monitor file changes.
 
Old 01-10-2014, 12:29 PM   #4
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Hmm, thank you for the suggestions. Personally I wanted to know whether the apt has a feature that can signal whether files in a certain folder have been modified. From the looks of your answers I take it that it doesn't. I'm already aware of the pre-invoke and post-invoke hooks, and using them to pre/post compare was my fall-back idea. I wanted to use this to detect whether somebody has tampered with files on the boot partition i.e. evil maid since I use full disk encryption on my linux box. Obviously I would have to run a verification script in pre-invoke to see whether the files are still clean (abort, if they're not), perform an upgrade, and verify again. If the second verification fails then the hashes need to be updated. Since apt is pretty much the only thing modifying files on the /boot partition I thought it would be wise to run the update script within a apt-get hook. I'll also be executing the verify script on each boot to see, if all the files are still intact. And P.S. I use sha256sum at least

The inotify sounds like an interesting idea, but it does not detect modifications done from outside the OS i.e. an adversary boots a live image and modifies the files on /dev/sda1. BTW, can the apt-get upgrade be stopped somehow from the pre-invoke script i.e. the script returns 0?
 
Old 01-13-2014, 02:55 AM   #5
zhjim
Senior Member
 
Registered: Oct 2004
Distribution: Debian Squeeze x86_64
Posts: 1,748
Blog Entries: 11

Rep: Reputation: 233Reputation: 233Reputation: 233
To stop apt-get upgrade:
From etckeeper it seems to be enough if one of the hooks does not return 0. Or maybe some calls to db_subst (seems to be a debconf thingy). I guess man apt should shed some better light.


Quote:
Originally Posted by displace View Post
The inotify sounds like an interesting idea, but it does not detect modifications done from outside the OS i.e. an adversary boots a live image and modifies the files on /dev/sda1.
Also then he could change your checksum database. Reboot with different media should be taken as a breach and is quite hard to detect. He could even enable an virtual enviroment, replace md5sum with his own binary to return the right values etc. Hard thing to tackle completly.
 
Old 01-13-2014, 02:59 PM   #6
displace
Member
 
Registered: Jan 2013
Location: EU
Distribution: Debian
Posts: 269

Original Poster
Rep: Reputation: 25
Did I mention the database will be signed with gpg? Though there's even no need for the database to reside on the unencrypted /boot partition, it might as well sit inside the encrypted LVM container. However that would make it harder to verify files from outside...

Yes, this does have its flaws i.e. it will not be able to verify the signatures until after the rootfs has been decrypted, so I might as well get owned first, but at least I'll have an indication of it. Do you think it's possible to move the verification into initramfs itself? Though I'm unsire what benefits (if any) that would offer. An attacker could simply replace initramfs image with his own...

Regards!
 
Old 01-13-2014, 03:13 PM   #7
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
The only somewhat secure approach to this I know of: Do not have /boot on your harddisk. Use a removable medium that is always by your side or in a secure place, for example a safe.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Is it posable to make a deb, with a bash script to execute? Droa Linux - Software 2 09-10-2012 11:52 AM
How to make Logon Script execute??? dpoggi Linux - Server 2 09-16-2011 02:19 PM
LXer: Make apt-get Installations and Upgrades 26x faster with apt-fast LXer Syndicated Linux News 1 10-25-2010 05:14 PM
[SOLVED] [Ubuntu] apt libxml-sax-perl "unable to execute installed post-installation script" XXLRay Linux - Software 1 07-17-2010 09:20 AM
My iptables script is /etc/sysconfig/iptables. How do i make this baby execute on boo ForumKid Linux - General 3 01-22-2002 07:36 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration