-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fail2ban support #1976
Fail2ban support #1976
Conversation
Example output string from sesman. This is an IPV6 development build.
|
BTW, is it possible to log port knocking to RDP port? Port knocking I mean here is a little bit different from the common use. I meant just connecting to 3389/tcp and disconnecting quickly without sending any credentials. |
I'm fine with this log format but I'm also fine with a more machine-friendly format. Because the log is intended to be parsed by fail2ban, right? For example:
|
These log entries should go out to syslog, right? So I don't think a datestamp is required. syslog will datestamp them. A short version would be nice. This should suffice as neither username nor address should contain spaces. [Date] hostname xrdp[process id]: AUTHFAIL user=%s ip=%s The message could come from xrdp, or sessman or wherever it's detected. These might warrant separate tickets, or perhaps there already are tickets: It would be nice to only get the setup stuff like cert and cipher information on first startup, not for every connection: Using default X.509 certificate: /etc/xrdp/cert.pem It would be nice to log the username here: [20211022-12:17:15] [INFO ] xrdp_wm_log_msg: login successful for display 10 or here: [20211022-12:17:17] [INFO ] lib_mod_log_peer: xrdp_pid=2924488 connected to X11rdp_pid=2924505 X11rdp_uid= X11rdp_gid= client_ip= client_port=1053 The uid will suffice, but the username would be nice. Thanks! |
df6ef26
to
0b28fe0
Compare
Thanks @metalefty, @timriker I've attempted to address the above with an additional commit. Log message is now as follows. This is from a development build, so there's additional info on the function raising the error whoich wouldn't be in a production build:- xrdp-sesman.log
syslog
I've added the UNIX time as @metalefty suggests. I take your @timriker that the message is timestamped, but that's in local time, whereas the timestamp is in UTC. My system is currently one hour ahead of UTC :-
The cert connection stuff is left on every connection for the simple reason that if xrdp is running for days, the required information for the connection could be challenging to find. I like the suggestion of adding the username to the log message for login success or failure as suggested. Since I'm there, I've also removed a display of 0, as this has proved to be confusing to user in the past fail message (display and xrdp log)
success message (xrdp.log)
@metalefty - I've looked into your port knocking issue. It can be done, but it would be logged in the xrdp.log rather than the sesman.log. Also, determining whether any data has been sent on the connection is going to need a few other changes. Maybe logging a total incoming PDU count could be useful information. What do you think? |
Seems to me that if a user wants timezone info in their logs, they should add it in syslog and not configure every application to also log timestamps. What error message is shown on dropped connections when no username has been sent? |
If you want to rely on Syslog timestamp, you can do that. Simply ignore the timestamp. I think the UNIX timestamp is easier to convert sometimes. The timestamp is for development / debug purposes. |
The UNIX time is also consistent between systems which is important if you're trying to work out exactly when something happened to your network, and you don't have centralised logging. Also, but less importantly, for one hour each year, a local timestamp is ambiguous and cannot be used for this purpose. @timriker - nothing that useful is logged at the moment if a connection is lost before the initial negotiation is completed. Here are the current messages geneated in the xrdp log for an unprivileged nmap port scan:-
|
The traditional syslog has these issues. Fortunately, this is easily remedied. As documented in rsyslog.conf for example, just comment out the indicated line to get output like this: 2021-10-26T10:46:38.267926-06:00 A-LE2009442 postfix/master[737]: terminating on signal 15 Human readable, unambiguous AND more precise than a unix timestamp.
It would be nice to have something logged at the same level as a login failure to indicate a dropped connection and the client IP. The client port might be useful in some cases. Thanks! |
I don't think either of us is arguing that syslog can't be configured to do what you want. Provided, of course, that you've actually configured it to do so before the event. In which case you can simply ignore the timestamp provided in the message. It's hardly an expensive addition. As regards the logging improvement, this could do with a bit more analysis as it's more work than it appears to be at first. Surprisingly, the Microsoft client also drops the connection mid-way through a startup if it feels the need to prompt the user regarding a TLS certificate or similar. If the user is happy to proceed a new connection attempt is started. So we'd need to determine that as a special case as I'd certainly regard that as normal operation. Another issue of course, is that this logging will only detect a rudimentary TCP port scan where the initial SYN-SYN-ACK handshake completes. More sophisticated scans cannot be detected at the application level at all. This nmap command produces no xrdp logging on my test system, nor would I be able to make it do so from within the application:-
I'll move this to a separate issue I think, and we can keep this PR focussed on the changes it currently contains. |
Is there anything to do on this? |
This follows on from conversations with @MikoyChinese in #1946 and @hubeny in #1973. Both of these users want the IP address of a failed login logged for use with fail2ban, which seems to make sense to me.
The stumbling block I had with this, is that the
client_ip
string fromg_write_ip_address()
contains more than just an IP address, so just logging that may introduce a dependency on the form of the output from that function. It seems to make sense to me to just log the IP address, and mark the log message as being a potential external dependency with a comment.This PR makes the following changes over two commits.
The first commit renames
g_write_ip_address()
asg_write_client_description()
and changes all the member variables using this value fromclient_ip
toconnection_description
. This makes maintainers less likely to trip overclient_ip
not being an IP address at all (which I've done myself in the past).The second commit adds a function to extract the IP address from the connection description for places where an actual IP address is required. These are:-
There's a change to xrdp_client_info here (member rename), but AFAICT there's no impact on xorgxrdp.
@MikoyChinese, @hubeny - if any of you are in a position to test this, please do.