You are not logged in.
Here's a fun one - a while ago, I noticed a directory called `~` in my home dir. I don't mean the shell token. It's literally `/home/lfitzgerald/~/` and it's empty.
This is obviously a misconfiguration and 99% my fault - I must have intended to provide my home dir path but ended up with it not being expanded.
The problem is that when I delete it, a while later it comes back. So it must be some periodic process. After that, I'm stumped.
How can I figure out what is creating this directory? I use symlinks to manage my dotfiles, and the repo is huge, so a simple search for "~" is not going to work. Also, the dotfiles are too complex for me to attempt git bisect.
Offline
Offline
Neat! But I think I'm missing something after skimming that page.
I did "sudo auditctl -w ~/'~/' -p rwax" which appears to have added the right rule (I see it in "sudo auditctl -l"). But:
$ sudo aureport -n
Anomaly Report
=========================================
# date time type exe term host auid event
=========================================
Error opening /var/log/audit/audit.log (No such file or directory)I delete the ~/'~' dir, and did aureport again, figuring I should at least see my own delete event, but I still get the same output. The files hasn't been re-created yet, it may be a per-boot thing.
How do I see the audit events?
Offline
The first rule keeps track of every read r , write w , execution x , attribute change a to the file /etc/passwd. The second one keeps track of any access to the /etc/security/ folder.
Which one do you think you want here?
(Deleting a file specifically does nothing to that file, it alters the parent directory)
it may be a per-boot thing.
https://wiki.archlinux.org/title/Audit_ … stallation
/etc/audit/audit.rules
-w '/home/lfitzgerald/~'Though I guess you can just add that rule transiently and then log into your session (to get the bogus directory created)
Offline
Which one do you think you want here?
Well, I figure all of them. There's probably not going to be that many events anyway, but I want to make sure I don't miss any. Although I'm guessing the event is directory creation.
(Deleting a file specifically does nothing to that file, it alters the parent directory)
D'oh! That's right... Hmm, well in that case what about creation? Do I need to set the watch on ~ instead of ~/'~'? That probably *would* be a lot of events, but I guess I can grep them out anyhow.
I see - the service was actually disabled, so that explains it. I enabled it now.
/etc/audit/audit.rules
-w '/home/lfitzgerald/~'Though I guess you can just add that rule transiently and then log into your session (to get the bogus directory created)
Nah, I figure I can just add the rule normally and remember to remove later. I assumed the auditctl command would persist to that rules file, but surprisingly no. That file also said it's randomly generated, so I put the rule in "/etc/audit/rules.d/mystery_tilde".
So in sum:
* I enabled/started auditd
* I deleted the mystery ~/'~' dir
* I add a watch for ~/'~' to rules.d
* I also created a watch with auditctl, but I figure that won't persist after a boot
I expect that if I reboot now I will see that the mystery dir is back. Is the above enough to ensure I'll see the audit events for it, or is there more?
Last edited by lfitzgerald (2023-06-07 06:00:01)
Offline
I'd omit -p rwxa and log everything. As with deletion, I'm not sure creating a file does anything to the file.
I also think that it does not understand ~ for /home/currentuser correctly, as the audit message is being generated at a lower level, so as seth suggested, try the full path.
Edit: I bet this is something you can find manually by grepping through your dotfiles. There aught to be some "mkdir -p ~ /foldername", where you've added a rogue whitespace between the tilde and the path separator slash.
Last edited by Awebb (2023-06-07 06:09:21)
Offline
I'd omit -p rwxa and log everything
Oh - I thought it was mandatory! Sounds good.
As with deletion, I'm not sure creating a file does anything to the file.
If that is the case, what do I do? Should I watch the parent dir instead?
I also think that it does not understand ~ for /home/currentuser correctly,
I get that - I was just using shorthand. It's the full expanded path in my actual files.
Offline
Watching the parent dir is a good idea!
Also see my edit above.
Offline
Edit: I bet this is something you can find manually by grepping through your dotfiles. There aught to be some "mkdir -p ~ /foldername", where you've added a rogue whitespace between the tilde and the path separator slash.
That would be nice, but "$ rg '~' | wc" gives 9k results
And it may be some services or something I created outside the dotfiles as a one off, as well, so it would be hard to narrow down the 9k.
Offline
It must be something that creates a directory. Try '~ ' or '~ /' or some regex with mkdir and a tilde followed by a blank.
...or a tilde followed by a variable that is empty at the time, so ~/$, or ~/"$.
Last edited by Awebb (2023-06-07 07:32:36)
Offline
If that is the case, what do I do? Should I watch the parent dir instead?
I'd just try and see, the offender might actually want to do something with it.
Otherwise you can https://wiki.archlinux.org/title/Audit_ … t_syscalls for mkdir and mkdirat, but if, as Awebb suspects, this results in a call to /usr/bin/mkdir that won't tell you much either.
You could then replace /usr/bin/mkdir w/ a script that checks the parameters, logs "ps fax | grep -C8 $PPID" and then "exec /usr/bin/mkdir.bin "$@""
#!/bin/bash
if [[ "$@" =~ '~' ]]; then
ps fax | grep -C8 $PPID >> /tmp/mkdir.log
fi
exec /usr/bin/mkdir.bin "$@"Offline