LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 12-26-2022, 09:21 AM   #1
thecowmilk
LQ Newbie
 
Registered: Oct 2019
Posts: 9

Rep: Reputation: Disabled
Intercept executed commands in user space?


Hello, I need to know if it is possible to intercept executed commands at user space. I know that there are some methods like LD_PRELOADING and catching execve() syscall when a binary uses this but I need to know how to do this against the shell a Linux machine is running so I'd be able to intercept the commands and log them.
 
Old 12-26-2022, 09:28 AM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 983

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
man auditd, audit.rules, auditctl... - is this what you are looking for?
 
Old 12-26-2022, 09:46 AM   #3
thecowmilk
LQ Newbie
 
Registered: Oct 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by lvm_ View Post
man auditd, audit.rules, auditctl... - is this what you are looking for?
Yeah but I want to build it myself for educational purposes. To be honest what is the point of learning if you don't make it yourself...
 
Old 12-27-2022, 03:00 AM   #4
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
I see this was also asked on (at least) Linux Foundation.

This has to be done from kernel-space; start your journey by looking up uprobes
 
Old 12-27-2022, 07:41 AM   #5
thecowmilk
LQ Newbie
 
Registered: Oct 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by syg00 View Post
I see this was also asked on (at least) Linux Foundation.

This has to be done from kernel-space; start your journey by looking up uprobes
Correct, I wanted to increase the chances of getting a response. It's not that I value/undervalue a forum or another. Thank for the hint! I will start looking for them
 
Old 12-27-2022, 07:54 AM   #6
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
did you check the command strace?
 
Old 12-27-2022, 04:54 PM   #7
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
I'm guessing the OP wants to trace shell internal commands. Can't be seen from strace AFAIK.
 
Old 12-28-2022, 02:07 AM   #8
thecowmilk
LQ Newbie
 
Registered: Oct 2019
Posts: 9

Original Poster
Rep: Reputation: Disabled
Quote:
When a user opens the terminal or is in the terminal mode(CTRL + ALT + F1) he runs a command like "ls -la". The tool should be able to catch the "ls -la" command and log it as a whole in a file.
This is how the process should happen. But again I want a simple program which knows how to get executed commands by terminal/shell without 3rd-party utilities.
 
Old 12-28-2022, 02:29 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,152

Rep: Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125Reputation: 4125
Quote:
Originally Posted by thecowmilk View Post
I want a simple program which knows how to get executed commands by terminal/shell without 3rd-party utilities.
Ain't going to happen. Without public APIs that provide access to that data, you are going to need to hook something. The tools are there, use them.

What about when the user changes terminal/shell ? - they generally process things differently.
 
Old 12-28-2022, 02:36 AM   #10
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,039

Rep: Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347Reputation: 7347
Quote:
Originally Posted by syg00 View Post
Ain't going to happen. Without public APIs that provide access to that data, you are going to need to hook something. The tools are there, use them.

What about when the user changes terminal/shell ? - they generally process things differently.
if it is about shell, bash -xv <script> will do that. Or at least something similar. If I understand it well.
 
  


Reply

Tags
kernel, shell, syscall



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
ShellScript executed from command prmpt but not executed from crontab or at command BMMadhav Linux - Newbie 1 11-16-2012 07:20 PM
[SOLVED] Configured Cron job executed every hour is instead executed every minute for 10m markings Linux - Software 4 05-13-2012 05:43 PM
Get the IP and commands executed by a user gartura Linux - Server 2 01-04-2011 08:26 AM
[SOLVED] Xwindow's program will not run when executed on boot or when executed remotely richman1234 Programming 2 10-08-2010 01:32 PM
Log all commands executed by any user? Possible helptonewbie Linux - Security 25 09-01-2009 08:34 AM

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

All times are GMT -5. The time now is 02:31 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