Looking for "hung socket simulator" for testing socket timeouts - sockets

I am testing handling for socket timeout conditions - for example, connection timeout, connect but no accept, accept but won't read, etc.
I'm looking for a program/script that will act as a server socket producing these effects.
This "hung socket simulator" needs to run on Mac OS (or Linux).

I found one called Bane: https://github.com/danielwellman/bane.

I think the powerful tool socat might be helpful here, it can redirect the request to the real endpoint and thus, you can have full control to the socat process itself to simulate what you want (like suspending the process at certain phase by kill -stop or so)
one of my use cases is that I just want my client app to finish the handshake with the remote service but read no more data:
socat -d -d -d TCP-LISTEN:22181,fork SYSTEM:'socat - "TCP:the-remote-host:2181" \| dd bs=1 count=50' &
the above example only send the first 50 bytes of the response back.

Why don't you just start your client program on your dev machine and when you want the TimeOut to appear, just unplug your network cable.

Related

TCP/IP Establish socket from app command to device

Question related to the best practices/patterns of socket.
Scenario: Send command from the app to the device
Communication used: TCP/IP
What should be done when sending a command from app to device?
Is that necessary to open a new socket (with the last ip/port establish by the device) ~ which I think the answer is no
or
should I get access to the server - find the specific thread which has the socket open (at least ideally) and use that socket to request information? What probably I thought here is to have a docker-compose (with two dockers within) and communicate from the first docker (which will be basically an API controller with GET route) to the second docker (server that handle the socket connections).
Any tips would be welcome for the clarification on App -> Device socket command.

LTTng live view with port forwarding / tunneling

I have a PC A where LTTng tracing is running with live view
lttng create trace-session --live
# Traces will be output to tcp4://127.0.0.1:5342/ [data: 5343]
Another PC B is directly connected with A with a Ethernet cable. At the same time, B is connected to a local network.
Now how can I view the live trace events from a third PC C, which is in the same local network as B, for example with
babeltrace2 "net://${B_IP}/host/${B_HOSTNAME}/trace-session"
I ran the following command on PC C, to make a tunnel to PC *A.
ssh -L 5342:${A_IP}:5342 -N user_name#${B_IP}
However, it seems not to have worked. I would like to ask:
What have I done wrong here?
What is the standard way to "forward" LTTng live tracing events to be viewed by babeltrace2?
Babeltrace2 connects to lttng-relayd using the live port of the lttng-relayd process not the data and control ports.
When the command line report the following:
# Traces will be output to tcp4://127.0.0.1:5342/ [data: 5343]
It means that the lttng-sessiond and lttng-consumerd process will communicate with a lttng-relayd process listening on the 127.0.0.1:5342 for control message and 127.0.0.1:5343 for trace data exchange. A viewer, in this case Babeltrace2 can connect to the live port of a lttng-relayd process to stream live session. You can take a deeper look at the component graph here.
The default live port is 5344 and the default behavior for the lttng-relayd process is to bind on all interfaces to listen. Naturally Babeltrace2 also default on using that port if none is specified to communicate with the lttng-relayd process.
See the man page of lttng-relayd for more details.
What have I done wrong here?
In your scenario you need to tunnel the 5344 port. Note that I'm not versed in ssh tunneling so I cannot validate the ssh approach here.
ssh -L 5344:${A_IP}:5344 -N user_name#${B_IP}
What is the standard way to "forward" LTTng live tracing events to be viewed by babeltrace2?
Babeltrace2 and lttng-relayd use TCP for communication. Hence, all TCP "forwarding" methods are acceptable here. As you probably noticed, LTTng does not encrypt communication and trace data in any way. I would say that using a ssh tunnel is appropriate here if you need to move data across non-trusted network.

NMAP -PS, -PA options

I'm beginner in using map and I read reference guide in nmap homepage. When I read host discovery with -P* options I suddenly had question about it.
There are -PS option in nmap and it sends syn packet to server to determine server is turned on or not. If nmap gets ACK/SYN packet for three-way handshake then it means server is turned on. If nmap get RST then it means that server is shut down. If timeout occur then firewall is exist between server and user computer...
Nmap homepage guide book saids they give -PA option to give more change for bypassing firewall. I thought if we send ACK packet instead of SYN then server will send RST packet for response in both case. Server is turned on or not. If timeout occur then we can determine firewall is exist. So I think usage of -PA is check firewall instead of check server is turned on or not.
My question is that I'm not sure about above things. Because I'm not good at network yet and beginner in this area. Did I understand correctly?
For the -P* options, Nmap considers any response from the server to be an indication that the server is up. Both SYN/ACK and RST packets count, as do several types of ICMP response like Port Unreachable. The specific type of response may indicate the state of the port, and would be analyzed by the port scan (-s* options), but for host discovery, any response is as good as another.

Is it possible to make a relay agent (application layer) of a server (service)? Any example? C will be better

I'm trying everything to NAT traversal to make a HTTP(or others) server be accessible from internet.
this is the previous question but with no luck.
HTTP Server behind NATs
So I'm trying to do the following
IE <--> agentC <---------NAT/Internet/.....----------->agentS<------->Apache Server
the scenario might be...
1.User input address in IE like "localhost:9999" (agentC)
2.agentC connect with agentS with Stun/TURN/ICE
3.agentS relay data to Apache Server and then reply to client.
I also refer to the following:
Is it possible to 'relay' a socket?
but the problem is:
1.the connection between agentC to agentS might be UDP, however the Http is on TCP, is it possible to "relay socket or packet"
2.I'm coding test code of agentS<---->Apache part,
((pp = popen("echo -e \"GET / HTTP/1.0\\n\\n\\n\"| nc localhost 80", "r")) == NULL)
.........
But the out put always "400 Bad Request".
(while type "echo -e "GET / HTTP/1.0\n\n\n"| nc localhost 80" in console will be successful)
3.I will modify a simple console chatroom to be agentS and agentC, is it possible to carry the http data (like pic,download...etc)?
Thank you for your patience
You don't really relay the socket, instead you relay the data. For example, "agentS" in your example opens a listening socket where it accepts connections from "agentC". When it gets a new connection from "agentC" then "agentS" connects to the web-server and enters a loop where where all it reads from either connection ("agentC" or web server) is sent to the other connection.
Since the two connections are independent it doesn't matter if one is TCP and the other UDP.
Also, if you need to do some processing on the data in "agentS" it's easy, as you actually have the data. The protocol between "agentC" and "agentS" doesn't even have to be HTTP, it can be whatever you want, as the programs can do protocol translation.
As a side note, when sending data to a web-server you end the lines with "\r\n", and the header is terminated by a single "\r\n" on its own line. So you only need to send "\r\n\r\n" after the GET request.

Sockets on a webhost

If you telnet to the ip address 192.43.244.18 port 13, you'll get the current time.
well, if I'm not wrong, this is simply a server socket. But there's one thing strange: how's this socket always listening?
If I take a PHP page and program sockets in there, I still have to request for the page first in order to activate the server socket, but this one isn't associated with any pages, and even if a make a perl script, I still have to request for that in order to run the server socket!
My question is: how can I make such a thing - an always listening socket - on a webhost (any language will do)?
You can run the process that's listening on the socket as a daemon (Linux) or service (Windows), or just a regular program really (although that's less elegant).
A simple place to begin would be http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html which teaches you how to make a simple serversocket in Java that listens for a connection on a specific port. The program created will have to be run at all times to be able to accept the connections.