You are not logged in.
ME is required for sure
;-)
Online
#!/usr/bin/python3
import os,subprocess
pid = os.getpid()
while pid > 1:
cmdpath = "/proc/"+str(pid)+"/cmdline"
with open(cmdpath) as f:
line = f.readline()
line = " ".join(line.split('\0'))
subprocess.run(["logger","sudo trace",line])
pidpath = "/proc/"+str(pid)+"/status"
try:
with open(pidpath) as f:
for line in f:
if line.startswith("PPid"):
skip , ppid = line.split()
pid = int(ppid)
break
except:
pass
os.execvp("/usr/bin/sudo.bin",sys.argv)In case it is needed to go any deeper
edit:
missed the call to the real sudo
Last edited by loqs (2018-01-27 22:44:29)
Offline
Python could do, but there was a needless subshell (and useless cat) in the original script that was causing the trouble. `logger` will read from stdin:
logger < /proc/$$/cmdline
logger < /proc/$PPID/cmdlineYou might also want to add a useful tag, e.g.:
logger -t sudo-debug < /proc/$$/cmdlineOr for the full process tree without python:
#!/bin/sh
pid=$$
while [ $pid -gt 0 ]; do
logger -t sudo-debug < /proc/$pid/cmdline
pid=$(sed -n 's/PPid:\t*//p' /proc/$pid/status)
done
exec /usr/bin/sudo.bin "$@"Last edited by Trilby (2018-01-27 22:54:35)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks Trilby. The problem with the while loop code is that sudo never completes the command... for example, `sudo su` returns to the shell. Perhaps append the exec line from the first script.
Last edited by graysky (2018-01-27 22:46:59)
Offline
Yes Trilby's command and my last one before revision both just parse the process tree.
Offline
Yup, I editted to indicate the actual command needs to follow at the end. And also to rewrite it as I was horribly annoyed that I had to rely on a bashism ... until I realized it didn't matter if the sed command was in a subshell.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Thanks for the help so far... now that I have the logger script in place, of course, I am not seeing the error. I'll post back when I eventually do.
Offline
Just happened... guess I need the more advanced code:
Jan 29 15:33:40 radio sudo-debug[1545]: /bin/bash
Jan 29 15:33:40 radio sudo-debug[1546]: /bin/bash
Jan 29 15:33:40 radio sudo[1544]: graysky : TTY=pts/1 ; PWD=/home/graysky ; USER=root ; COMMAND=/bin/chown -R graysky:users /incoming/
Jan 29 15:33:40 radio sudo.bin[1544]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 29 15:33:40 radio sudo.bin[1544]: pam_unix(sudo:session): session closed for user rootLast edited by graysky (2018-01-29 20:35:59)
Offline
Can you correlate the logged time to something you were doing around that time? You should have been asked for your password if you have set sudo to always ask for a password.
You could install psmisc and log the output of pstree for each sudo invocation, it might help to figure out from where sudo is being called. You might want to add a few options such as -a to get the full command line as this should help identify the offending sudo call.
R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K
Offline
@ROOKIE - Doing too many things at that time. I am using the 2nd script now which I probably should have done in the first place. Let's see...
Offline
From the output produced so far "TTY=pts/1" etc looks like it was triggered from something started in a terminal window.
Offline
Finally, something to go on:
Jan 30 17:27:51 radio sudo-debugmore[18133]: /bin/bash
Jan 30 17:27:51 radio sudo-debugmore[18135]: /bin/bash
Jan 30 17:27:51 radio sudo-debugmore[18137]: -zsh
Jan 30 17:27:51 radio sudo-debugmore[18139]: xfce4-terminal
Jan 30 17:27:51 radio sudo-debugmore[18141]: xfsettingsd
Jan 30 17:27:51 radio sudo-debugmore[18143]: /sbin/init
Jan 30 17:27:51 radio sudo[18132]: graysky : TTY=pts/2 ; PWD=/home/graysky ; USER=root ; COMMAND=/bin/chown -R graysky:users /incoming/
Jan 30 17:27:51 radio sudo.bin[18132]: pam_unix(sudo:session): session opened for user root by (uid=0)
Jan 30 17:27:51 radio sudo.bin[18132]: pam_unix(sudo:session): session closed for user root... still no idea wtf is calling the chown.
Last edited by graysky (2018-01-31 00:27:20)
Offline
Can we assume you did in fact have a xcfe4-terminal window open around that time?
Do you run zsh as your interactive shell? If so, it would seem a bash script was run from that shell that included the sudo chmod command. It should be in your zsh history.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
This is just gonna be some speculations since I don't use, nor have I previously used Xfce, but what about Thunar? Thunar interfaces some settings for auto-mounting and bookmarks etc (~/.gtk-bookmarks or something) which could be checked by xfsettingsd? Then if Xfce want's to have it's known location back, it would need to have the permissions changed as to not exceed the context it was spawned in (graysky:users)? I guess this bookmark/path/whatever it can be would be located in some .desktop-file or some xml-file with Thunar settings.
Sorry if this is completely insane and just waste of time, I don't use a DE myself since they are so magic...
Offline
The two bashes make me suspect it is a script (or a subshell?) called from another script which was executed with sudo. The xfsettingsd - xfce4-terminal is normal I believe, if you setup a keyboard shortcut to run xfce4-terminal it will show up like that.
R00KIE
Tm90aGluZyB0byBzZWUgaGVyZSwgbW92ZSBhbG9uZy4K
Offline
Rookie, the first bash is our replacement /usr/bin/sudo itself. So the actual chain is:
xfsettingsd -> xfcr4-terminal -> zsh -> bash -> /usr/bin/sudo
So from an interactive zsh session a script was run (with a bash or sh shebang) and that script included the sudo command.
As any command that was directly typed into an interactive terminal really should be obvious (unless someone else sits at the keyboard while Greysky is away for coffee) then I'd actually revise my previous suspicion that the command must be in the zsh history. I suspect it may actually shell script called from zsh's startup files. The diagnostics for this are relatively simple: 1) do the symptoms occur whenever a xcf4-terminal is launched, 2) are the symptoms prevented by using a clean zsh config and/or using a different shell.
Last edited by Trilby (2018-01-31 13:08:48)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
xfsettingsd -> xfcr4-terminal -> zsh -> bash -> /usr/bin/sudo
So from an interactive zsh session a script was run (with a bash or sh shebang) and that script included the sudo command.
This is not far from what I tried to communicate, any settings daemon wouldn't need to be active until called upon, i.e. when launching the xfce4-terminal, then while/after setting up the shell it would read a change in the dev-tree and run the specified mount. However, some status script or prompt-blingbling would probably be the culprit...
Offline
I doubt it B1omman, as the process change shows it was in a terminal in which zsh was running, and within that a bash shell ran the command with 'sudo'.
Processes spawned from a bound key may also have xfsettingsd as a parent, but not a gui terminal.
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
I don't believe in Magic.
I see...
Jokes aside, you are making sense and I share your doubt. Just hoping for some magic some time so I can feel okay with that I had an empty file named NULL and owned by root:root in my $HOME without being able to find out why for 3 years until I did a fresh install 3 weeks ago on a new disk. Nothing were creating it, but it appeared anyways at random times no matter how many times I deleted it. I gave up.
Offline
Mystery solved... I tracked it down to a call of chown in a backup script I manually call to sync files to my NAS for backup... I defined the sync target with a variable there which is why when I greped for 'incoming', the script did match, but I didn't put 2 and 2 together at the time <<head smack>>.
I knew this was going to end in pilot error; thanks to all for the discussion and the code snips.
Offline