Commit graph

84 commits

Author SHA1 Message Date
Lorenz Kästle
2757550558 clang-format 2025-08-01 14:35:23 +02:00
Lorenz Kästle
a69dff1522 check_ssh: Put variable in the correct scope 2025-08-01 14:35:13 +02:00
Lorenz Kästle
3c53bf623d check_ssh: Fix format expression 2025-08-01 14:34:29 +02:00
Lorenz Kästle
69925c782b check_ssh: fix data type to allow for error checking 2025-08-01 14:34:01 +02:00
Richard Laager
1f2acfd1c6 check_ssh: Correct type on len variable
strlen() returns a size_t.

Signed-off-by: Richard Laager <rlaager@wiktel.com>
2025-07-11 18:44:03 -05:00
Richard Laager
661ecff45c check_ssh: Fix buffer overflow
A buffer overflow was occurring when the server responded with:
Exceeded MaxStartups\r\n

glibc would then abort() with the following output:
*** buffer overflow detected ***: terminated

It was the memset() that was overflowing the buffer.  But the memmove()
needed fixing too.

First off, there was an off-by-one error in both the memmove() and
memset().  byte_offset was already set to the start of the data _past_
the newline (i.e. len + 1).  For the memmove(), incrementing that by 1
again lost the first character of the additional output.  For the
memset(), this causes a buffer overflow.

Second, the memset() has multiple issues.  The comment claims that it
was NULing (sic "null") the "rest".  However, it has no idea how long
the "rest" is, at this point.  It was NULing BUFF_SZ - byte_offset + 1.
After fixing the off-by-one / buffer overflow, it would be NULing
BUFF_SZ - byte_offset.  But that doesn't make any sense.  The length of
the first line has no relation to the length of the second line.

For a quick-and-dirty test, add something like this just inside the
while loop:
memcpy(output,
  "Exceeded MaxStartups\r\nnext blah1 blah2 blah3 blah4\0",
  sizeof("Exceeded MaxStartups\r\nnext blah1 blah2 blah3 blah4\0"));

And, after the memmove(), add:
  printf("output='%s'\n", output);

If you fix the memset() buffer overflow, it will output:
output='ext blah1 blah2 blah3 '

As you can see, the first character is lost.

If you then fix the memmove(), it will output:
output='next blah1 blah2 blah3'

Note that this is still losing the "blah4".

After moving the memset() after byte_offset is set to the new strlen()
of output, then it works correctly:
output='next blah1 blah2 blah3 blah4'

Signed-off-by: Richard Laager <rlaager@wiktel.com>
2025-07-11 18:43:59 -05:00
Lorenz Kästle
72fd885f4f Transform output format to a global state
This commit removes the format parameter from the mp_check
object and creates a module global variable instead.
This prevents thread safe usage of different mp_check objects
which should likely not present a big problem for now.
The reason for this change is effectively the very same,
the format was lost if an exit was triggered by a signal
handler (timeout in this example).
2025-03-07 23:38:50 +01:00
Lorenz Kästle
2e9f9ebf7d check_ssh.c: clang-format 2025-03-07 23:38:50 +01:00
Lorenz Kästle
6428696f31 check_ssh: exit properly if TCP connection fails 2025-03-07 23:38:50 +01:00
Lorenz Kästle
92fb0ec662 check_ssh: add missing break statement 2025-03-07 23:38:50 +01:00
Lorenz Kästle
46683da7b7 check_ssh: fix typo 2025-03-07 23:38:50 +01:00
Lorenz Kästle
ce3eff0908 check_ssh: no more implicit conversion 2025-03-07 23:38:50 +01:00
Lorenz Kästle
b48ec884be check_ssh: Verify that timeout is a positive integer 2025-03-07 23:38:50 +01:00
Lorenz Kästle
9ea4dbc253 check_ssh: move only time relevant stuff in timeout area 2025-03-07 23:38:50 +01:00
Lorenz Kästle
add5bfb1e4 check_ssh: Move default SSH constant around a bit 2025-03-07 23:38:50 +01:00
Lorenz Kästle
5ee9a5eadd check_ssh: modify usage string to avoid old call syntax 2025-03-07 23:38:50 +01:00
Lorenz Kästle
ed06df7f34 check_ssh: Migrate to new output infrastructure 2025-03-07 23:38:50 +01:00
Lorenz Kästle
c87bc7eee4 check_ssh: centralize configuration in external header 2025-03-07 23:38:50 +01:00
Lorenz Kästle
665e2f9130 clang-format 2025-03-07 23:38:50 +01:00
Lorenz Kästle
42ef1fa2fa check_ssh: linter + style fixes 2024-10-31 16:00:41 +01:00
Lorenz Kästle
78258c4cd0 check_ssh: do not export local variables 2024-10-31 15:55:40 +01:00
Lorenz Kästle
6410ef8acb check_ssh: clang-format 2024-10-31 15:55:04 +01:00
Lorenz Kästle
fa15fdcf5d Merge branch 'master' into fix/check_ssh-variable-stuff 2024-10-31 15:27:01 +01:00
Lorenz Kästle
611b33a30e check_ssh: update copyright 2024-10-31 14:47:49 +01:00
RincewindsHat
0fd0421052 check_ssh: set elapsed time properly
Previous to this commit, `elapsed_time` was only set after being read,
which was quite likely wrong and a bug.
This commit actually set the value before it is being read again.
2024-09-06 01:53:47 +02:00
RincewindsHat
829ec76f00 check_ssh: Remove unused variable iteration 2024-08-28 23:40:22 +02:00
RincewindsHat
04115904ad check_ssh: Always initialize elapsed_time 2024-08-28 23:39:57 +02:00
Lorenz Kästle
66f62dd336
check_ssh: patches from op5 (#1738)
* check_ssh: properly parse a delayed version control string

This resolves an issue with SSH servers which do not respond with their
version control string as the first thing in the SSH protocol version
exchange phase after connection establishment.

This patch also makes sure that we disregard a potential comment in the
version exchange string to avoid nonsense mismatches. In the future, we
might want to add the capability to match against a user specified comment.

In addition, the patch largely improves the communication towards the
server, which adds better protocol adherence.

Of course, new test cases are added to support the trigger and guard
against regressions of the bugs solved by this patch.

This fixes op5#7945 (https://bugs.op5.com/view.php?id=7945)

Signed-off-by: Anton Lofgren <alofgren@op5.com>

* check_ssh.t: Fix a few typos

Signed-off-by: Anton Lofgren <alofgren@op5.com>

* check_ssh: Handle non-alpha software versions

This patch fixes a bug where we would reject version control strings
that do not contain letters, because the assumption is made that they
always do. This is not required by the RFC however, and there exist
implementations that do not contain letters.

I've also added a few references to the RFC to make the process of
parsing the control string more apparent.

This fixes op5#8716 (https://bugs.op5.com/view.php?id=8716)

Signed-off-by: Anton Lofgren <alofgren@op5.com>

* check_ssh: Fix a typo in "remote-protocol parameter

remote-protcol -> remote-protocol

Signed-off-by: Anton Lofgren <alofgren@op5.com>

* Remove unused variable

* Formating fixes

* Update translations

* Remove merge conflict artefact from previous merge

* Set fixed include paths

* Improve code style to be slightly more readable

* Update test cases for different netcat behaviour and reduce sleep time

---------

Signed-off-by: Anton Lofgren <alofgren@op5.com>
Co-authored-by: Anton Lofgren <alofgren@op5.com>
2024-03-27 00:35:16 +01:00
RincewindsHat
51db32cc1d check_ssh: Use C99 booleans 2023-10-18 20:24:13 +02:00
Sven Nierlein
edca257e20 use unknown exit code for help/version in plugins
Signed-off-by: Sven Nierlein <sven@nierlein.de>
2015-10-04 19:24:30 +02:00
Sven Nierlein
a7d7992777 check_ssh: change warning to critical for protocal/version errors
It makes more sense to exit critical if a explicit version/protocol is requested. This
would also be more consistent with other plugins. Other string matching plugins like
check_snmp or check_http exit critical if the result does not match.

Signed-off-by: Sven Nierlein <sven@nierlein.de>

Closes #1268
2014-11-28 14:35:03 +01:00
Sven Nierlein
ed914472e9 Merge pull request #1190 from waja/github780
check_ssh: check protocol
2014-06-30 13:42:02 +02:00
Jan Wagner
4f5e20187f check_ssh: Reverting a387120
This seems to result into more problems in the wild then before 'fixing' it

Closes Debian #739254
Reopen Debian #734811
2014-02-17 12:18:17 +01:00
Holger Weiss
7ee3525423 Merge branch 'maint'
* maint:
  check_ssh: Get rid of sshd: Read from socket failed: Connection reset by peer
  fixed tests when there is no direct internet connection
  NEWS: Mention fix for check_http's -S option
  Fix for SSL Versioning when multiple options are used.
  Fix #1217 spec file fails to build due to duplicate files and unused files
  check_http: Don't let "-N" expect an argument
  README: Change GitHub URL
  README: Clarify license notice
  Update URLs and mailing list addresses
  Just using the posix conform extended regular expression grep
  check_oracle: --db +ASM bad string matching check_oracle doesn't correctly check for pmon +ASM instance from at least Oracle 11 as the pmon proces was renamed from ora_pmon_.* to asm_pmon_.*. -- Just turning attached patch of github issue #1207 into a push request. (Closes #1207)
  Update web site URLs

Conflicts:
	FAQ
	NEWS
	README
	SUPPORT
	configure.in
	monitoring-plugins.spec.in
	pkg/solaris/pkginfo.in
	plugins-root/check_dhcp.c
	plugins-root/check_icmp.c
	plugins-scripts/check_ifoperstatus.pl
	plugins-scripts/check_mssql.pl
	plugins/check_apt.c
	plugins/check_by_ssh.c
	plugins/check_cluster.c
	plugins/check_dbi.c
	plugins/check_dig.c
	plugins/check_disk.c
	plugins/check_dns.c
	plugins/check_dummy.c
	plugins/check_fping.c
	plugins/check_game.c
	plugins/check_hpjd.c
	plugins/check_http.c
	plugins/check_ide_smart.c
	plugins/check_ldap.c
	plugins/check_load.c
	plugins/check_mrtg.c
	plugins/check_mrtgtraf.c
	plugins/check_mysql.c
	plugins/check_mysql_query.c
	plugins/check_nagios.c
	plugins/check_nt.c
	plugins/check_ntp.c
	plugins/check_ntp_peer.c
	plugins/check_ntp_time.c
	plugins/check_nwstat.c
	plugins/check_overcr.c
	plugins/check_pgsql.c
	plugins/check_ping.c
	plugins/check_procs.c
	plugins/check_radius.c
	plugins/check_real.c
	plugins/check_smtp.c
	plugins/check_snmp.c
	plugins/check_ssh.c
	plugins/check_swap.c
	plugins/check_tcp.c
	plugins/check_time.c
	plugins/check_ups.c
	plugins/check_users.c
	plugins/negate.c
	plugins/urlize.c
	plugins/utils.h
	po/Makevars
	po/de.po
	po/fr.po
	po/monitoring-plugins.pot
2014-01-21 16:07:38 +01:00
Thomas Guyot-Sionnest
11cf54ca78 Merge branch 'rename' 2014-01-21 07:59:07 -05:00
Spenser Reinhardt
212575b858 plugins/*.c: Alterations for timeout messages.
.c file changes for misleading timeout messages in help functions. Solution to pull request #1209 tracker by awiddersheim.

Files: plugins/check_apt.c, plugins/check_by_ssh.c, plugins/check_dbi.c, plugins/check_dig.c, plugins/check_disk.c, plugins/check_dns.c, plugins/check_game.c, plugins/check_http.c, plugins/check_ldap.c, plugins/check_ntp.c, plugins/check_ntp_peer.c, plugins/check_ntp_time.c, plugins/check_nwstat.c, plugins/check_overcr.c, plugins/check_pgsql.c, plugins/check_ping.c, plugins/check_procs.c, plugins/check_radius.c, plugins/check_real.c, plugins/check_smtp.c, plugins/check_snmp.c, plugins/check_ssh.c, plugins/check_tcp.c, plugins/check_time.c, plugins/check_ups.c, plugins/negate.c
2014-01-21 11:33:45 +01:00
Holger Weiss
c3e756a855 Capitalize "Monitoring" when it's the first word 2014-01-20 03:12:50 +01:00
Monitoring Plugins Development Team
63734f52ab Project rename initial commit.
This is an initial take at renaming the project to Monitoring Plugins.
It's not expected to be fully complete, and it is expected to break
things (The perl module for instance). More testing will be required
before this goes mainline.
2014-01-19 14:18:47 -05:00
Jan Wagner
a387120182 check_ssh: Get rid of sshd: Read from socket failed: Connection reset by peer
This fix was grabbed from FreeBSD downstream and provided by Dmitry Sivachenko.
Fixes Debian Bug #734811
2014-01-10 15:56:30 +01:00
Holger Weiss
3c90a370ea Update URLs and mailing list addresses
Now that we moved our infrastructure away from SourceForge, update the
URLs and mailing list addresses accordingly.
2013-10-28 23:58:36 +01:00
Jan Wagner
97349ae13d check_ssh: check protocol
It would be useful to be able to detect the protocols supported by the remote
ssh server to locate any using the insecure ssh v1 protocol. This patch
attempts to match against the protocol string in the ssh response.

Example:

check_ssh -H my.host.com -P 2.0
--
Just turning attached patch of github issue #780 into a push request.
(Closes #780)
2013-10-01 14:50:04 +02:00
Sven Nierlein
24772e755e unified ipv4/6 usage and help text 2012-11-28 11:03:11 +01:00
Anders Kaseorg
028d50d6f9 Die when asprintf fails
Fixes many instances of
warning: ignoring return value of 'asprintf', declared with attribute warn_unused_result [-Wunused-result]

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
2012-06-29 13:39:11 +02:00
Thomas Guyot-Sionnest
1bc7a4a198 Add perfdata to check_ssh (#3244097 - Marco Beck) 2011-03-26 15:44:38 -04:00
Thomas Guyot-Sionnest
eaf3cb27f4 Add newline after "Usage:" in --help 2010-04-22 08:57:14 -04:00
Thomas Guyot-Sionnest
884aee0667 Standardize the extra-opts notes 2010-04-21 23:29:18 -04:00
Thomas Guyot-Sionnest
25d1ee331d Fix translations when extra-opts aren't enabled
Bug #2832884 reported problem with translations outputting pot file
headers. This is caused by "" matching the header of the translation
files.

This patch moves gettext macros inside utils macros and update some
french translations.
2010-04-14 08:33:06 -04:00
Thomas Guyot-Sionnest
6fbd14fea5 Removing CVS/SVN tags and replacing with git-based versioning
For contrib/, full tags have been imported from subversion


git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2091 f882894a-f735-0410-b71e-b25c423dba1c
2008-11-23 05:38:47 +00:00
Thomas Guyot-Sionnest
caa8bd6423 Bulk EOL cleanup
$ git diff --ignore-space-change|diffstat
 0 files changed


git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@2087 f882894a-f735-0410-b71e-b25c423dba1c
2008-11-19 06:45:18 +00:00
Thomas Guyot-Sionnest
44f8455b2c Added support for --extra-opts in all C plugins (disabled by default, see configure --help)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1991 f882894a-f735-0410-b71e-b25c423dba1c
2008-05-07 10:02:42 +00:00