OS detection using nmap for a particular IP address - nmap

I am trying to determine the OS of a particular IP address using nmap. Here is my code so far:
import java.io.*;
public class NmapFlags {
public static void main(String[] args) throws Exception {
try {
String[] cmdarray = { "nmap", "-O", "66.110.59.130" };//
// example trying to find the OS or device detials of this Ip address//
Process process = Runtime.getRuntime().exec(cmdarray);
BufferedReader r = new BufferedReader(new InputStreamReader(
process.getInputStream()));
String s;
while ((s = r.readLine()) != null) {
System.out.println(s);
}
r.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
After running this code output I got is:
All 1000 scanned ports on 66.110.59.130 are filtered
All 1000 scanned ports on 66.110.59.130 are filtered
Too many fingerprints match this host to give specific OS details
Too many fingerprints match this host to give specific OS details
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 246.06 seconds
Nmap done: 1 IP address (1 host up) scanned in 246.06 seconds**
Are there any other nmap flags I can use to detect the device type? I tried -A option. I need to find the device details at each hop of trace route.

Nmap performs “active fingerprinting” (it sends packets then analyse the response) to guess what the remote Operating System is. These probes are quite intrusive and I‘d recommend reading more about it (http://nmap.org/book/osdetect-fingerprint-format.html).
"Too many fingerprints match this host to give specific OS details" means that the probes are contradictory or too broad.
For example in a NAT scenario, some port scans return the router information (e.q. Cisco iOS), some other probes return the real host specifications (e.q. Windows).
The best way to understand how the network is designed is to rely on your own judgment based on different probes and output.
IP ID sequence, fingerprint analysis and service detection (-sV) can help:
e.q. If 3389 is open, then the OS running is a Windows.
e.q. if IP ID sequence varies then the target might be multiple (Load balanced).
Your analysis of the network traffic will always be more accurate than what nmap attempt to guess in an automated way.

Related

In QT how can I detect when a USB port switches from serial mode to DFU when connected to an STM32

I have a Qt5.12.4 MinGw64 app where I want to catch a USB event. In Windows 10 the MS driver for STM/USB emits error messages and I can use that as a trigger. Inelegant but it works, until I try to run it in a Win7-8.1 app where the driver is a third party STM driver with a VCP wrapper. I am thinking I need to adopt libusb to try and catch the ports change of state, but I am at a loss as how to proceed. I can see the port info in Device Manager, I just dont know how to get to it. Some of the questions going through my head....
1) Can I just make an OS call to read the port info? (if so, how?)
2) Can libusb and QSerialport co-exist on the same port?
3) What calls to LibUSB1.0 do I make to query the port status?
4) Is there a Windows cli utility like lsusb (wmic??) where I could scrape the data?
5) Which solution is likely to be the best cross platform solution?
I am using this trigger to start dfuse as a process that does a firmware update automatically on my STM board.
I have looked over the libusb1.0 docs but I do not understand just how I can use it. If that is correct solution, an example of how to query the Com port data and state would be most appreciated.
I tried using qDebug() to print out all of the serialportInfo data, while in serial or DFU state, but there is nothing there that is useful that I can use as a trigger.
USB serial mode = Serial port info is: ("COM3", "USB Serial Device", "Microsoft", "00000000001A", "\\.\COM3", "483", "5740", "1", " no data", "1")
USB DFU mode = Serial port info is: ("COM3", "N/A", "N/A", "N/A", "\\.\COM3", "N/A", "N/A", "no data", " no data", "no data")
I need some direction as to how to grab this port info so I dont really have any code that matters, but I am including an excerpt of my working process function.
This code works just fine to actually perform the firmware load. I just need a way to actually trigger it from a USB port change of state
void updateDevice_Dialog::update_firmware(QString fileName)
{
qDebug() << "Updating firmware: " << fileName ;
QDir dir;
ui->progress_label->setText("Preparing to update Firmware .....");
if(dir.setCurrent(QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware"))
{
QSettings settings;
QString comPort = settings.value("USBPort").toString();
ui->progress_label->setText("Setting port to: "+comPort+" and starting download .....");
ui->avr_progressBar->setValue(0);
ui->avr_progressBar->setRange(0,100);
ui->avr_progressBar->setHidden(false);
progress_steps = 0; //reset avrProcess line output counter;
qDebug() << "Starting process for stm-dfu on serial port: " << comPort;
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),this,SLOT(process_error(QProcess::ProcessError)));
connect(avr_Process,SIGNAL(finished(int,QProcess::ExitStatus)),this,SLOT(process_finished(int,QProcess::ExitStatus)));
connect(avr_Process,SIGNAL(readyReadStandardOutput()),this,SLOT(process_readLine()));
connect(avr_Process,SIGNAL(errorOccurred(QProcess::ProcessError)),avr_Process,SLOT(kill()));
connect(avr_Process,SIGNAL(error(QProcess::ProcessError)),ui->avr_progressBar,SLOT(close()));
QString dfu_command = "\""+QCoreApplication::applicationDirPath()+"/Tools/\"dfusecommand -c -d --v --fn "
"\""+QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation)+"/firmware/\""+fileName;
qDebug().noquote() << "dfu command string is: "<< dfu_command << " Current dir is: " << dir.currentPath();
avr_Process->start(dfu_command);
avr_Process->waitForFinished(20000);
}
}
From the perspective of the host system, rebooting the microcontroller into DFU will look like the original device was disconnected, and a completely different device was plugged in shortly afterwards.
If you need to watch for this, set up a libusb hotplug callback so that you'll be notified when the DFU device is attached.

Erlang Jinterface node nameserver problems on windows

I am trying to implement an interface for my erlang program using jinterface. When I call the command OtpNode otpNode = new OtpNode(nodeName, cookie); java throws an IOException with
java.io.IOException: Nameserver not responding on DESKTOP-GIR29G3 when publishing javanode.
It doesn't seem to be common problem for people as I couldn't find anything similar online. It's a local node with the node name being "javanode" with no fullstops or dashes. Why would there be a DNS issue on a local node?
I have tried starting an erlang node in the directory the java program is started as well as starting the erlang console on my pc, but I'm very new to erlang so those were just wild guesses that some erlang VM must be running.
Here is the code that may help:
public Erlterface()
{
Thread t = new Thread(new Runnable() {
public void run() {
setupMBox();
}
});
t.start();
}
private void setupMBox()
{
try {
String nodeName = "javanode";
String cookie = "jinterface";
//String[] names = OtpEpmd.lookupNames();
OtpNode otpNode = new OtpNode(nodeName, cookie); //CRASH HAPPENS HERE
OtpMbox Mbox = otpNode.createMbox("javaserver");
The error from the console:
Connected to the target VM, address: '127.0.0.1:54025', transport: 'socket'
java.io.IOException: Nameserver not responding on DESKTOP-GIR29G3 when publishing javanode
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpEpmd.r4_publish(OtpEpmd.java:344)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpEpmd.publishPort(OtpEpmd.java:141)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode$Acceptor.publishPort(OtpNode.java:784)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode$Acceptor.<init>(OtpNode.java:776)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.init(OtpNode.java:232)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:196)
at com.stellar.base.schedule.com.ericsson.otp.erlang.OtpNode.<init>(OtpNode.java:149)
at com.stellar.base.schedule.Erlterface.setupMBox(Erlterface.java:40)
at com.stellar.base.schedule.Erlterface.access$000(Erlterface.java:16)
at com.stellar.base.schedule.Erlterface$1.run(Erlterface.java:26)
at java.lang.Thread.run(Thread.java:745)
Thanks in advance
Dale
UPDATE ADDITIONAL INFORMATION:
I went into a dive to try and figure out where exactly the train leaves the rails but I'm taking wild guesses as to what I should flag as potential issues. I just want to add some additional information here to help:
In OptEpmd the following is caught before the io exception is thrown
java.net.ConnectException: Connection refused: connect
The final source is the native DeulSocketImpl class that I suppose calls on windows to do the final connection thingamabob ad it fails:
static native int connect0(int var0, InetAddress var1, int var2) throws IOException;
Am I missing something in setting up the erlang node? I surely don't have to start it manually? I've diabled my firewall completely to test it. How do I figure out why the connection was refused?

how can I make large number of connections without error at client side

I have written a program in golang to make request about 2000qps to different remote ip with local port randomly selected by linux, and close request immediately after connection established, but still encounter bind: address already in use error periodically
what I have done:
net.ipv4.ip_local_port_range is 15000-65535
net.ipv4.tcp_tw_recycle=1 net.ipv4.tcp_tw_reuse=1 net.ipv4.tcp_fin_timeout=30
above is sockstat:
sockets: used 1200 TCP: inuse 2302 orphan 1603 tw 40940 alloc 2325 mem 201
I don't figure it out why this error still there with kernel selecting available local port,will kernel return a port in use ?
This is a good answer from 2012:
https://serverfault.com/questions/342741/what-are-the-ramifications-of-setting-tcp-tw-recycle-reuse-to-1#434669
As of 2018, tcp_tw_recycle exists only in the sysctl binary, is otherwise gone from the kernel:
https://github.com/torvalds/linux/search?utf8=%E2%9C%93&q=tcp_tw_recycle&type=
tcp_tw_reuse is still in use as described in the above answer:
https://github.com/torvalds/linux/blob/master/net/ipv4/tcp_ipv4.c#L128
However, while a TCP_TIMEWAIT_LEN is in use:
https://github.com/torvalds/linux/search?utf8=%E2%9C%93&q=TCP_TIMEWAIT_LEN&type=
the value is hardcoded:
https://github.com/torvalds/linux/blob/master/include/net/tcp.h#L120
and tcp_fin_timeout refers to a different state:
https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.txt#L294
One can relatively safely change the local port range to 1025-65535.
For kicks, if there were a situation where this client was talking to servers and network under my control, I would build a new kernel with a not-to-spec TCP_TIMEWAIT_LEN, and perhaps also fiddle with tcp_max_tw_buckets:
https://github.com/torvalds/linux/blob/master/Documentation/networking/ip-sysctl.txt#L379
But doing so in other circumstances- if this client is behind a NAT and talking to common public servers- will likely be disruptive.

The port 'COM11' does not exist. Specified port is not open

I have been using Unity and teensy to perform serial communication for quite some time. And it has been working fine.
Now I changed my teensy board and thus the COM Port has changed on it.
Teensy is communicating perfectly in arduino and sending all the right signals when checked in serial monitor. But I am getting this error in unity.
> IOException: The port `COM11' does not exist.
System.IO.Ports.WinSerialStream.ReportIOError (System.String optional_arg)
System.IO.Ports.WinSerialStream..ctor (System.String port_name, Int32
baud_rate, Int32 data_bits, Parity parity, StopBits sb, Boolean dtr_enable, Boolean rts_enable, Handshake hs, Int32 read_timeout, Int32 write_timeout, Int32 read_buffer_size, Int32 write_buffer_size)
(wrapper remoting-invoke-with-check) System.IO.Ports.WinSerialStream:.ctor (string,int,int,System.IO.Ports.Parity,System.IO.Ports.StopBits,bool,bool,System.IO.Ports.Handshake,int,int,int,int)
System.IO.Ports.SerialPort.Open ()
Initially the com ports were single digit values such as COM4 or COM8 etc. But since I started getting twodigit COM Ports I started facing this problem. If I connect a teensy again with a single digit com port it works fine but does not detect COM50 etc.
How do I solve this?
If this is Windows OS then try to specify the COM port name as \\.\COM11
myPort= new SerialPort("\\\\.\\COM11",9600);
NOTES: This syntax also works for ports COM1 through COM9. Certain boards will let you choose the port names yourself. This syntax works for those names as well.
Use System.IO.Ports.SerialPort.GetPortNames() to see what names does the OS use for current COM ports. (I'm not sure if you're talking about .NET, but if you do this helps)
Use
foreach(string str in SerialPort.GetPortNames())
{
Debug.WriteLine(string.Format("Existing COM port: {0}", str));
}
For know the ports available

MongoDB connection refused to local node when connecting to replica set

I have a replica set consisting of four nodes (ux002, ux009, ux019, ux020). I have a program that I'd like to run in parallel on each of the same four nodes which connects to this replica set using the Mongo Java driver.
Examining the status of the replica set shows that all four nodes are operating fine, however the program throws the following warning message on all four nodes:
Nov 12, 2014 2:34:40 PM com.mongodb.ConnectionStatus$UpdatableNode update
WARNING: Server seen down: ux009/127.0.1.1:27017 - java.io.IOException - message: couldn't connect to [ux009/127.0.1.1:27017] bc:java.net.ConnectException: Connection refused
However, on each node, the server which is seen down is the one the program is running on. I.e. I run the program on ux009, and it tells me ux009 is down. I run it on ux002, it tells me ux002 is down.
I made a stupidly simple program to test whether there was something wrong with my original code, but the same warning persists:
public static void main(String[] args) throws Exception {
List<ServerAddress> addrs = new ArrayList<>();
if (args.length == 0) {
addrs.add(new ServerAddress("localhost", 27017));
} else {
for (String a : args) {
String[] host = a.split(":");
addrs.add(new ServerAddress(host[0], Integer.valueOf(host[1])));
}
}
mongo = new Mongo(addrs);
Thread.sleep(5000); // Sleep to give it time to print messages
mongo.close();
}
And I run it as follows:
java -jar mongo-test.jar ux002:27017 ux009:27017 ux019:27017 ux020:27017
Could it be that mongod isn't configured correctly? Or perhaps I am misusing the Java API?
The Mongo Java driver is version 2.9.3, and mongod is version 2.6.5.
Many thanks in advance!
-Jim
The IP is a little strange for the local host:
ux009/127.0.1.1:27017
I would have expected that to be:
ux009/127.0.0.1:27017
Most likely someone fat fingered the ip address in the /etc/hosts on each machine.
Posting the answer here for completeness. The issue was that the bind_ip parameter in the mongod configuration file had been set to the IP address of only one of the nodes. Thanks to helmy for spotting that.