Re: Remote server OS identification
by hardburn (Abbot) on Jun 18, 2003 at 14:49 UTC
|
Use nmap. It might not be pure-Perl, but it'll work. Usually, I don't like relying on external programs from my Perl code, but I don't know of any module that comes close to the functionality of nmap.
---- I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer
Note: All code is untested, unless otherwise stated
| [reply] |
Re: Remote server OS identification
by gellyfish (Monsignor) on Jun 18, 2003 at 14:58 UTC
|
#!/usr/bin/perl -w
use strict;
my @hosts = qw(localhost);
HOST:
foreach my $host (@hosts )
{
open(NMAP, "nmap -O $host |") || next;
while(<NMAP>)
{
chomp;
if(/Remote operating system guess: (.*)/)
{
print "$host $1\n";
next HOST;
}
}
}
You will need to run this as root and update the value of @hosts appropriately.
/J\
| [reply] [d/l] [select] |
Re: Remote server OS identification
by ScooterQ (Pilgrim) on Jun 18, 2003 at 15:09 UTC
|
The reason people are suggesting nmap, by the way, is because is uses TCP fingerprinting to provide a "best guess" at an operating system. The fingerprinting tends to be pretty accurate - just make sure you have an up-to-date version of nmap.
I seem to remember this same question coming up the other day from someone trying to identify machines via various banners, which is a **VERY BAD IDEA INDEED**. The others are right - use nmap. | [reply] |
|
|
Just for reference, that discussion is here.
| [reply] |
Re: Remote server OS identification
by ScooterQ (Pilgrim) on Jun 18, 2003 at 16:35 UTC
|
I should have done this before posting earlier... There's a CPAN module that wraps nmap, making it possible to use nmap from within your Perl program. I've not used it, but it looks pretty staightforward. | [reply] |
Re: Remote server OS identification
by theorbtwo (Prior) on Jun 18, 2003 at 17:28 UTC
|
I can think of two basic ways, with a large number of variations on each of them. The first is to use somthing like nmap to analize the remote box and guess the OS. The second is to ask it. There's many variations on that, from looking at the telnet banner, through telneting in, to SSHing with the command-to-run being uname -a. I'd recommend either ssh/uname -a (or not -a, depending on exactly what you want, of course), or using nmap. Which depends on if you have ssh access to the box, and if your project spec and sense of elegance will let you run nmap. (I'd be very surprised if nmap is standard on prety much anything, with the possible exception of forensic kits, because it's often considered a "hackers tool" (and by "hacker", such people mean "cracker").)
Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).
| [reply] |
Re: Remote server OS identification
by castaway (Parson) on Jun 18, 2003 at 16:26 UTC
|
Thats an interesting question, as I'm currently trying to 'improve' a script which also does that. Its technique is unix-only though, as it uses Net::Telnet to login to the remote machine, and run 'uname -s' to get the operating system.
I wonder if nmap would be any faster, and if its installed as standard on things like AIX and HP-UX on which my script is running.. (I somehow doubt it though)
Any other ideas, perchance?
C. | [reply] |
|
|
Unfortunately, the problem with using telnet to connect is that A) you are transmitting a password in clear text across the network and B) you are relying on the telnet service to be running on the remote host. This typically would work fine for all flavours of *nix but not necessarally for WinNT-based systems, IIRC, telnet services need to be turned on explicitly on an NT/2000 server (but I'm not an NT admin so I'm not 100% sure of that). Using nmap() is probably a better solution.
Just my $.02 :-)
"Ex libris un peut de tout"
| [reply] [d/l] |
|
|
A) doesn't matter at all, since its a user/pass just for ftp with a specific directory, and an internal network. As to B), we are requiring it to be for this very reason.
Tho whether I require that, or nmap to be installed, is probably just the same..
Yes I know it doesn't on Win, I said that :) (Which is the other problem, since we now to support ftp servers on Win too.. so I'll need another solution sometime soon anyway..)
C.
| [reply] |
|
|
|
|
you are relying on the telnet service to be running on the remote host. This typically would work fine for all flavours of *nix
Not while I'm in charge of the *nix machines! (But normaly nmap wont detect the os-type on these either, thanks grsecurity, Update: though this is likely to change, as far as I know nmap, it will be able soon).
regards,
tomte
Hlade's Law:
If you have a difficult task, give it to a lazy person --
they will find an easier way to do it.
| [reply] |
|
|