Score:0

How to configure SELinux such that it will not block the execution of endlessh

nf flag
j j

I was prompted an execution error when I check on endlessh status, I believe SELinux is blocking that execution, how to let SELinux allow that execution?

[root@fedora endlessh]# systemctl status endlessh.service
× endlessh.service - Endlessh SSH Tarpit
     Loaded: loaded (/etc/systemd/system/endlessh.service; enabled; preset: disabled)
     Active: failed (Result: exit-code) since Tue 2023-01-03 19:17:46 +08; 12s ago
   Duration: 110ms
       Docs: man:endlessh(1)
    Process: 4331 ExecStart=/usr/local/bin/endlessh (code=exited, status=203/EXEC)
   Main PID: 4331 (code=exited, status=203/EXEC)
        CPU: 95ms

How it looks like in my configuration file:

[root@fedora endlessh]# sudo nano /etc/systemd/system/endlessh.service
[Unit]
Description=Endlessh SSH Tarpit
Documentation=man:endlessh(1)
Requires=network-online.target

[Service]
Type=simple
Restart=always
RestartSec=30sec
ExecStart=/usr/local/bin/endlessh      
KillSignal=SIGTERM

# Stop trying to restart the service if it restarts too many times in a row
StartLimitInterval=5min
StartLimitBurst=4

StandardOutput=journal
StandardError=journal
StandardInput=null

PrivateTmp=true
PrivateDevices=true
ProtectSystem=full
ProtectHome=true

#InaccessiblePaths=/run /var

## If you want Endlessh to bind on ports < 1024
## 1) run: 
##     setcap 'cap_net_bind_service=+ep' /usr/local/bin/endlessh
## 2) uncomment following line
AmbientCapabilities=CAP_NET_BIND_SERVICE
## 3) comment following line
#PrivateUsers=true

NoNewPrivileges=true
ConfigurationDirectory=endlessh
ProtectKernelTunables=true
ProtectKernelModules=true
ProtectControlGroups=true
MemoryDenyWriteExecute=true

[Install]
WantedBy=multi-user.target

asktyagi avatar
in flag
Update your question with `journalctl -u endlessh.service -l` output, specifically errors.
Score:0
cl flag

First off, you don't know at all if it's SELinux, you just suspect something. Second, SELinux isn't as simple as "it allows x process to run or not", it's much more than that. There's source context, target context, and action, among others.

First you need to collect the denied actions. Start logging actions denied by SELinux:

tail -f /var/log/audit/audit.log | grep denied

Then start endlessh and see if anything comes up. If not, then it's not SELinux. If yes, then save those denied actions into a textfile, e.g. endlessh.log.

Now tell SELinux to allow those actions:

audit2allow -i endlessh.log -M endlessh
semodule -i endlessh.pp

Now here comes the tricky part: SELinux will allow the specific action(s) found in the log file, but other, different actions might follow. Because an executable may do thousands of different things. It may wanna do things A, B, and C, but if SELinux blocks even action A, it won't even reach B and C, since it's already failed. So you need to keep iterating and adding those new denied actions, then restarting endlessh, until it finally works, and there's no new "denied" lines appearing in the audit log whatsoever, when you start endlessh.


Your other, probably more efficient option is to set SELinux to permissive, in which case it logs the denied actions, but doesn't actually deny them. In this case you can be sure that all actions you need to allow will appear in the log in just one run. To do this, edit /etc/selinux/config:

SELINUX=permissive

Reboot, then do the log collecting and SELinux module installation, as explained above. Once all done, set SELinux back to enforcing:

SELINUX=enforcing

Reboot, and you're good to go.

More details: SELinux Crash Course

Score:-1
fi flag

if you installed endlessh from source you need to remove it and install it as an rpm package and then reconfigure it, it is supposed to work

jm flag
I do find it interesting that, since the user is suspecting a problem with selinux, the source rpm does not mention any change to selinux policies. Is it "supposed to work" or does it work without system changes? Source rpm just builds and installs in `/usr/local/bin`.. Also, the OP did not specify whether he installed from rpm or source.
abdus avatar
fi flag
i had a similar problem and the only difference is that i use almalinux, i looked for the solution and in github they suggested using the rpm package, i tried it and it worked, without needing to change any selinux parameters, and my selinux is enabled with the default alma settings as well as i installed endlessh from the source at the beginning. you are right though but there is a sign that he installed endlessh from souce if you look at the location in his shell you will find endlessh directory, you never switch to that directory when installing an rpm if i am not mistaken
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.