LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-28-2015, 05:47 AM   #1
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Rep: Reputation: Disabled
IO Redirection - Not working properly


Hey Guys,

I have a quick question regarding IO Redirection, or whatever you call it lol..

Basically I'm trying to test the following on a test server (dreamhost)..

Code:
[root@localhost ~]# <&5- ; >&5-
[root@localhost ~]# exec 5<>/dev/tcp/snowstorm.dreamhost.com/22
[root@localhost ~]# echo -e "cat /etc/fstab\n\n" >&5
[root@localhost ~]# cat <&5
SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.4
Protocol mismatch.
[root@localhost ~]#
However as you can see rather than get the result back I get Protocol Mismatch... is this a problem with the way I'm doing it? Or is something being blocked either at my end or their end?

Thanks
Jon
 
Old 07-28-2015, 06:15 AM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
I honestly have no idea of what you are trying to achieve with your examples
Code:
exec 5<>/dev/tcp/snowstorm.dreamhost.com/22 # Eeeh, what!?!
However, here is a link on redirection:
http://www.tldp.org/LDP/abs/html/io-redirection.html

Best regards,
HMW
 
Old 07-28-2015, 06:24 AM   #3
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
The thing is, I think that should work...

I have used this in the past for various tasks..

Code:
exec 5<>/dev/tcp/server/port
....should mean anything redirected into (>&5) should be in turn sent to <b>server</b> via <b>port</b> - In theory, surely I should be able to read that data back with <&5

Although, it looks like nothing is even being passed to the server.. I can see this by:

Code:
[root@localhost ~]# exec 5<>/dev/tcp/snowstorm.dreamhost.com/22
[root@localhost ~]# echo -e "mkdir ~/test\n\n" >&5
[root@localhost ~]# ssh jon_ssh@snowstorm.dreamhost.com
jon_ssh@snowstorm.dreamhost.com's password:

                                      m
  mmm   m mm    mmm  m     m  mmm   mm#mm   mmm    m mm  mmmmm
 #   "  #"  #  #" "# "m m m" #   "    #    #" "#   #"  " # # #
  """m  #   #  #   #  #m#m#   """m    #    #   #   #     # # #
 "mmm"  #   #  "#m#"   # #   "mmm"    "mm  "#m#"   #     # # #


Last login: Tue Jul 28 03:14:46 2015 from
[snowstorm]$ ls -l ~
total 0
drwxr-xr-x 5 jon_ssh pg8407980 52 Feb 14  2014 Maildir
drw-rw---- 2 jon_ssh dhapache  10 Sep 20  2011 logs
As you can see the directory was not created...
 
Old 07-28-2015, 06:29 AM   #4
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by jonnybinthemix View Post
However as you can see rather than get the result back I get Protocol Mismatch...
No, the "Protocol Mismatch..." is the result. So, the redirection is working correctly. The problem is that the data you're sending through do not conform to the SSH protocol.
 
Old 07-28-2015, 06:32 AM   #5
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Hmmm, the plot thickens..

If I test using Google and try to retrieve the HTTP Headers, it works:

Code:
[root@localhost ~]# <&5- ; >&5-
[root@localhost ~]# exec 5<>/dev/tcp/www.google.co.uk/80
[root@localhost ~]# echo -e "GET / HTTP/1.1\n\n" >&5
[root@localhost ~]# cat <&5
HTTP/1.1 302 Found
Cache-Control: private
Content-Type: text/html; charset=UTF-8
Location: http://www.google.co.uk/?gfe_rd=cr&ei=EGi3VajjL7Pj8wfmuK2AAg
Content-Length: 261
Date: Tue, 28 Jul 2015 11:31:28 GMT
Server: GFE/2.0
Alternate-Protocol: 80:quic,p=0

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>302 Moved</TITLE></HEAD><BODY>
<H1>302 Moved</H1>
The document has moved
<A HREF="http://www.google.co.uk/?gfe_rd=cr&amp;ei=EGi3VajjL7Pj8wfmuK2AAg">here</A>.
</BODY></HTML>
 
Old 07-28-2015, 06:38 AM   #6
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Millgates,

Thanks for your reply..

Do you think you could explain your answer a little further? Please excuse my ignorance, but I assumed that if I was passing a single command (mkdir /folder), then the command in plan text should be sent to the server and action'd?

Or can we not pass commands as plain text using this method?

I've used this method before to write a sendmail script.. which worked well for SMTP commands... so I'm confused as to why it wouldn't work for other basic commands.
 
Old 07-28-2015, 06:41 AM   #7
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
Ahhhh, it's just clicked...

I'm sending the data in plain text down port 22... So I get what you mean.

But I thought I could send plain text through any port so long as it was open? But I guess if SSHD is the only thing listening on port 22 then SSH will need to be able to cope with any commands send via that port?
 
Old 07-28-2015, 06:57 AM   #8
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Quote:
Originally Posted by jonnybinthemix View Post
I've used this method before to write a sendmail script.. which worked well for SMTP commands... so I'm confused as to why it wouldn't work for other basic commands.
Yes, but you probably didn't just open tcp to the server, type in the e-mail and press enter. You needed to use, as you mention, the SMTP commands. When you use a web interface or a mail client to send your mails, you don't need to do that, because these higher level applications handle the implementation details of the HTTP, SMTP or whatever protocol for you. It is the same with the ssh protocol. When using ssh, the client handles everything for you, you only need to type in the data you want to send to the other side. However, when you open a plain TCP connection to a ssh server, you need to do the SSH part yourself. So, if you start the session by sending an identification string, such as "SSH-2.0-OpenSSH_5.9p1 Debian-5ubuntu1.4\r\n", followed by authentication keys in the proper format, encrypt the actual data you're sending to the remote server and so on, it should work.

Besides, it wouldn't be much of a Secure Shell if you could open a connection as you attempted in your first post, without any password or authentication key, would it?

Last edited by millgates; 07-28-2015 at 07:00 AM.
 
Old 07-28-2015, 07:08 AM   #9
jonnybinthemix
Member
 
Registered: May 2014
Location: Bristol, United Kingdom
Distribution: RHEL 5 & 6
Posts: 169

Original Poster
Rep: Reputation: Disabled
You sir, make a very valid point.. and the more I think about it, the more I realise that it was never going to work the way I wanted it to.. and if it did, I'd have found a massive weakness in SSH! Which I wasn't going to do, was I?! lol

Hmm, well this just sends me back to the drawing board. I basically want to be able to run a script on loads of remote PCs without setting up SSH keys with every single one (or supplying the password), but in the absence of any management software (RHN or Spacewalk) it's not going to be simple. I guess I could script it to run using the root password, assuming it's the same on all PCs.. There's lots of ways of doing it, but this method aint one! hehe.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Appending files question/working with I/O redirection ffar Linux - Newbie 5 09-14-2009 05:05 PM
Powerdns mail redirection not working centosfan Linux - Server 1 09-05-2009 06:47 PM
Port redirection with iptables not working as expected. Eric-Mtl Linux - Networking 1 08-16-2007 07:42 AM
redirection < operator not working pls help Fond_of_Opensource Linux - Newbie 3 08-25-2006 02:35 AM
IO redirection not working ministre Linux - Newbie 2 11-04-2003 01:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:42 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration