Multiple channels in a single SSH session - ssh

I am debugging OpenSSH code where it seems multiple channels have been allocated on single SSH session (single connected child server).
My queries could be naive here:
Under what conditions can multiple channels be opened?
What are the SSH message flows which lead to multiple channels? A message flow chart will be very helpful.
Is it correct to free channels[0] in the case below?
(gdb) p channels[0]
$1 = (Channel *) 0xb0f33e20
(gdb) p channels[0]->rfd
$2 = 0xd
(gdb) p channels[0]->efd
$3 = 0xffffffff
(gdb) p channels[0]->wfd
$4 = 0xffffffff
(gdb) p channels[1]->wfd
$5 = 0x9
(gdb) p channels[1]->efd
$6 = 0xffffffff
(gdb) p channels[1]->rfd
$7 = 0x9

Under what conditions can multiple channels be opened?
Every channel is either X11 forwarding, TCP port forwarding (there might be more types), UNIX domain socket forwarding (or ssh-agent socket) or MUX proxy. Consulting source code describing the types is a good start. They are opened, if the client requests them using command-line options (-X, -L, -R, -D, -A, ...) which are described in the manual page for ssh.
What are the SSH message flows which lead to multiple channels? A message flow chart will be very helpful.
If you will run the OpenSSH client and/or server in debug mode (LogLevel DEBUG3), you will get a lot of useful information what messages are being exchanged for various use cases.
Is it correct to free channels[0] in the case below?
Most probably not, but it is not clear what you ask here and what is the context. That is obviously valid channel with read file descriptor pointing to FD 0x0D so you might expect there will be something to read at some point.

Related

Connect to connman service using the first field rather than the second

Given the following table
$ connmanctl services
*AO MyNetwork wifi_dc85de828967_68756773616d_managed_psk
OtherNET wifi_dc85de828967_38303944616e69656c73_managed_psk
AnotherOne wifi_dc85de828967_3257495245363836_managed_wep
FourthNetwork wifi_dc85de828967_4d7572706879_managed_wep
AnOpenNetwork wifi_dc85de828967_4d6568657272696e_managed_none
I'd like to be able to connect to a network, e.g. OtherNET, using the string OtherNET rather than the long wifi_dc85de828967_38303944616e69656c73_managed_psk, as I don't want to count the times I press Tab and/or check that the wifi_ line in the prompt corresponds to the intended network.
Is this possible with connman only? Or do I really have to write a wrapper myself?
The man page of connmanctl contains
services
Shows a list of all available services. This includes the
nearby wifi networks, the wired ethernet connections, blue‐
tooth devices, etc. An asterisk in front of the service
indicates that the service has been connected before.
and
connect service
Connects to the given service. Some services need a so-
called provisioning file in order to connect to them, see
connman-service.config(5).
which both don't say much about the format of the output or the use of the command.
Similarly, the wiki on Arch Linux refers to the last column as the second field beginning with wifi_.
Since nobody has answered yet, I have found some spare time to code the following wrapper, which basically does the following
keeps reading as long as the input is not exit;
when an input is provided which starts with connect, the following word is used to pattern-match one line (only the first matching line) from connman services; the last field of this line (the one which starts with wifi_) is forwarded to connmanctl connect;
any other non-empty input is forwarded to connmanctl as it is.
a certain number (to be passed through the variable NOINPUTS_BEFORE_EXIT whose default is 3) of empty inputs causes the script to exit.
The script is the following
#!/usr/bin/env bash
name=$(basename $0)
noinputs_before_exit=${NOINPUTS_BEFORE_EXIT:=3}
while [[ $cmd != 'exit' ]]; do
echo -n "$name " 1>&2
read cmd
if [[ -z "$cmd" ]]; then
(( --noinputs_before_exit == 0 )) && exit
else
noinputs_before_exit=$NOINPUTS_BEFORE_EXIT
if [[ $cmd =~ ^connect\ ]]; then
connmanctl connect $(connmanctl services | awk '/'"${cmd#* }"'/ { print $NF; exit }')
else
connmanctl $cmd
fi
fi
done
The script limitations are at least the following:
(less importantly, to me) I have no idea whether it meets any security requirements;
it does not allow Tab-completion;
(most importantly, to me) it does not use the readline library, so line editing impossible.

Modem escape sequence (+++) passed as data

one question regarding modem, Hayes escape sequence.
First to explain what is happening:
==> ATD 123\r\n
<== +CR: REL ASYNC\r\n
<== CONNECT 9600\r\n
After this moment I have online session. When I want to hangup, I am doing next.
< no data 1.5 seconds >
==> +++ (no \r\n)
**+++ is received on destination side (why?)**
<== OK
< no data 1.5 seconds >
==> ATH\r\n
<== OK
Destination side gets NO CARRIER.
The problem for me is that escape sequence is received as regular data on destination side.
Does anyone have an idea what should I do? Some modem configuration tweak?
Thanks!
I will answer my question.
I did not find the way to do that.
Instead, in order to hangup I use DTR (Data Terminal Ready) signal. After switching from active to inactive, the other side determines that as hangup (if modem is configured with AT&D2).

From Node Red to Pure Data with UDP

I want to send UDP from Node Red to Pure Data. In NR, I have a UDP output node set to 127.0.0.1:3001 and a Pd netreceive object set to 3001 1 (the 1 sets the object to UDP rather than TCP). No message is received in the Pd patch.
To thicken the plot, a Node Red UDP output node set to 127.0.0.1:1881 does successfully send to Node Red UDP input node set to 1881. Also, a TCP object set to 127.0.0.1:3000 does connect with d netreceive object set to 3000, reported by the Pd console as "EOF on socket 12".
As the Node Red UDP output node is sending within the flow and Pd can report a TCP connection, I suspect there's something I have to do to format the message for PD. Any ideas?
netreceive expects messages to be FUDI-formatted. Basically, this means messages are terminated with a semicolon. Until a ';' is received, [netreceive] won't output anything.
Read more here: https://en.wikipedia.org/wiki/FUDI
Please check out my git repo for a solution.
https://github.com/sylatupa/Digital-Culture-Sound-Client/issues/1
Node Red was used to receive MQTT on particular topics.
I route the topics to the appropriate shell command that runs the locally installed pdsend executable.
I take the MQTT payload and pipe '|' two strings to the pdsend executable.
Left 3 is relieved by the execution of pdsend
The puredata patch receives and routes the 'Left 3' message
Node-Red is running on a raspberry pi, along side the mqtt broker.
I am testing with a MQTT client written in python.
See the github for the code and pure data patch, and maybe the node-red flow if that can be exported.
What is lacking is more complex messages, json encoded strings, and larger hierarchy topics, /pi/sensor1.

How to craft specific packets on the host of Mininet to generate massive Packet-In messages

I am wondering that how to generate massive packet-in messages to the controller to test the response time of SDN controller in the environment of Mininet.
Can you give me some advice on it?
You could use iperf to send packets, like this:
$ iperf -c -F
You could specify the amount of time:
$IPERF_TIME (-t, --time)
The time in seconds to transmit for. Iperf normally works by repeatedly sending an array of len bytes for time seconds. Default is 10 seconds. See also the -l and -n options.
Here is a nice reference for iperf: https://iperf.fr/.
If you would like to use Scapy, try this:
from scapy.all import IP, TCP, send
data = "University of Network blah blah"
a = IP(dst="129.132.2.21")/TCP()/data
send(a)

How to redirect the output of redis subscription

I am exploring redis to do pub/sub. I wanted to write a script that uses redis-cli to subscribe to a channel and dump whatever is published to a file. What I notice however is that redis-cli subscripe channel > output does not quite work.
This is because there is no automatic flush of stdout when redis-cli displays the messages associated to the subscription. So the last messages before stopping redis-cli do not appear in the output file.
There is no option you can use to enforce a systematic flush, redis-cli.c needs to be patched. In Redis source code, edit src/redis-cli.c, and find the following piece of code. Add the missing fflush line.
if (config.pubsub_mode) {
if (config.output != OUTPUT_RAW)
printf("Reading messages... (press Ctrl-C to quit)\n");
while (1) {
if (cliReadReply(output_raw) != REDIS_OK) exit(1);
// The following line must be added
fflush(stdout);
}
}
Once redis-cli has been compiled again, it should work as expected.