TCP/IP default port for sending console messages? - sockets

Is there a dedicated port (lower than 1024) specifically for clients to send text based console output to a server? I've googled extensively but to no avail. What's the best port (lower than 1024) for sending text based console output if any?

A port is just a number. You can see well known port assignments in /etc/services.
You need a server application to be listening on the given port to accept your input. There are number of remote terminal protocols and their implementations, among which are Telnet (port 23) and Secure Shell, or SSH (port 22).
The simplest way to test your socket client is to setup netcat on the server to listen on whatever port you want (port is 777 in the example bellow), and then try to connect to it from somewhere else:
server:~# nc -l -p 777
then
client:~$ nc server 777
Note that on Unix you normally need super-user (root) rights to bind "privileged", i.e. bellow 1024, ports.

I'm going to use telnet (port 23) since that's closest to what I want. Sending console messages to a server from a client. okey dokey thanks!

Related

How can I check a socket from a webserver?

Im doing a challenge (CTF style) and everyting we got is an IP.
Scanning that IP only one port is open.
If I connect to that IP and port using netcat, I got a kind of "dance" doing in CMD, with a message at the end that says "Check socket 12345".
I need to understand again what truly a socket is because im not getting anywhere trying to connect to that socket.
Its possible to connect to a socket from a specific port? or I only can make a connection from a open port and there the web servers redirect my connection automatically to a socket?
You can use netcat nc and its -p option to set the source port.
Netcat man page say:
-p port
local port number (port numbers can be individual or ranges: lo-hi [inclusive])
Try "nc -p 12345 dest_IP dest_port"

How to sniff PostgreSQL network traffic?

I want to see what my PostgreSQL database server (postgres) is sending in response to my client (a Ruby application server using the pg gem). Both the server & client are running locally, and their connection is unencrypted.
Use tcpdump to display packets sent between your client & server.
How? Enter the following command in Terminal on macOS:
sudo tcpdump -A -i any port 5432
Then, trigger your application server (for example, by sending it a curl request from another Terminal window) to send a command to postgres.
Finally, view the output of tcpdump.
Note: tcpdump doesn't show packets sent between psql & postgres since they communicate over a Unix domain socket. See: Can I monitor a local unix domain socket like tcpdump?
Since tcpdump is already mentioned, I'd want to list another tool that can be used for this purpose with a less verbose output: ngrep
Usage:
ngrep -d lo port 5432
lo is the network interface to listen to. This can be found out using ifconfig. port 5432 is the pcap filter.
This can also be used to search for specific SQL statements if the aim is to capture SQL statements submitted by your application. For a detailed explanation, refer here.

Bi-directional communication using sockets via ssh tunnel

I have a server host (S) and a bunch of clients (C1, C2, C3, ...). I would like to open connection between S and C1, C2, C3 respectively for bi-directional communication. Ideally using sockets. SSH for authorisation purposes is preferred.
Ideally:
Client C1 creates SSH reverse tunnel to S, forwarding C1's port so it is accessible on S as it's own port.
Client program running on C1 creates a socket and binds to forwarded port.
Server program running on S creates a socket and binds to forwarded port.
Client and server can exchange data.
Is something like that possible? I tried coding up a draft using Python but to no avail:
Firstly, I run on C1: ssh -N -R 9999:localhost:15432 root#example.com - OK
Secondly, on server I run:
import socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serversocket.bind(('localhost', 9999))
serversocket.listen(5)
while True:
connection, address = serversocket.accept()
buf = connection.recv(64)
if len(buf) > 0:
print buf
break
Thirdly, on client I run:
import socket
clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
clientsocket.connect(('localhost', 15432))
clientsocket.send('hello')
But I'm getting socket.error: [Errno 111] Connection refused on client. Also if I set up tunnel first and then launch server program, I'm getting [Errno 98] Address already in use. It only works when I first start the program, then set up a tunnel.
If aforementioned concept does not make sense, what would you suggest to create sort of synchronisation tool so any client listens for queries from the server and can respond with data? (preferrably in Python).
Thanks in advance.
-N doesn't do what you seem to think it does: it's intended for the ssh-destination to be able to connect back to the originator. But that would make the originating side the server.
It sounds like you should be using -L to simply create a connection from the client through the ssh tunnel to the server.
To demonstrate: I have a local server named 'bree'. On that machine, I execute (this could also be your python server listening on port 9999):
nc -l 9999
Now on my client machine, I execute this in one window (or could put it in the background):
ssh -N -L 9999:bree:9999 bree
This says: listen on the local (client) machine to port 9999, and when a connection to it is made, forward the request through the tunnel, and connect to port 9999 on bree.
Now, in a second window on the client machine, I execute:
nc localhost 9999
The two nc instances are connected.

error in connecting irc through xchat

I installed X-chat on Ubuntu 14.04.
in the first step I enter all the details (nickname, realname etc) and choose freenode as server and click Connect.
But I see the following error:
Looking up irc.freenode.net
* Connecting to chat.freenode.net (94.125.182.252) port 8001...
and nothing happens and there is a timeout error.
and when I type:
/join #python
I see the following:
Not connected. Try /server <host> [<port>]
You aren't connecting to the IRC port. Your client is specifying port 8001 but you need to connect to 6667
Check that you and your provider are not blocking port 6667.
To test this, fire up a terminal and type:
telnet chat.freenode.net 6667
Examine the output to see if the command succeeds (if it does, you'll be presented with freenode's welcome banner):
$ telnet chat.freenode.net 6667
Trying 35.156.219.172...
Connected to chat.freenode.net.
Escape character is '^]'.
:jackson.freenode.net NOTICE * :*** Looking up your hostname...
:jackson.freenode.net NOTICE * :*** Checking Ident
:jackson.freenode.net NOTICE * :*** Found your hostname
If it does not, examine your network configuration, firewall, router and anything at your provider that may block that outbound port.
Some providers, especially schools and colleges, block port 6667 for security and you should try one of freenode's many other ports instead: https://freenode.net/kb/answer/chat

Cannot get irssi to work on Bluehost dedicated IP address

I am trying to get irssi to work over SSH on my Bluehost dedicated IP server.
Bluehost support says port 6667 is open, but you have to have an app listening to it, so running nc -l on the server and then telnet'ing in works, but if I run irssi on the server then it can't connect to freenode.net - it says the connection timed out.
If you do nmap -v -sT then you see the 6667/TCP port, but it's listed as closed.
How can get irssi to run using an ssh shell on Bluehost?
It Would be great to have under a Screen session you could re-login to from anywhere.
Make sure that you ask them if 6667 is open outbound TCP and UDP.
Sometimes they can mistake it for inbound or only open TCP for example. You can telnet to your IRC host on port 6667 even if something is not listening on the Bluehost side, assuming IRC is up and accepting connections, and Bluehost has the port opened, a telnet from your Bluehost account to the IRC server will work fine.