##// END OF EJS Templates
ssh: quote parameters using shellquote (SEC)...
Jun Wu -
r33732:8cb9e921 stable
parent child Browse files
Show More
@@ -92,10 +92,13 b' def parsepatchoutput(output_line):'
92 92 def sshargs(sshcmd, host, user, port):
93 93 '''Build argument list for ssh'''
94 94 args = user and ("%s@%s" % (user, host)) or host
95 if '-' in args[:2]:
95 if '-' in args[:1]:
96 96 raise error.Abort(
97 97 _('illegal ssh hostname or username starting with -: %s') % args)
98 return port and ("%s -p %s" % (args, port)) or args
98 args = shellquote(args)
99 if port:
100 args = '-p %s %s' % (shellquote(port), args)
101 return args
99 102
100 103 def isexec(f):
101 104 """check whether a file is executable"""
@@ -151,10 +151,7 b' class sshpeer(wireproto.wirepeer):'
151 151 sshcmd = self.ui.config("ui", "ssh")
152 152 remotecmd = self.ui.config("ui", "remotecmd")
153 153
154 args = util.sshargs(sshcmd,
155 _serverquote(self.host),
156 _serverquote(self.user),
157 _serverquote(self.port))
154 args = util.sshargs(sshcmd, self.host, self.user, self.port)
158 155
159 156 if create:
160 157 cmd = '%s %s %s' % (sshcmd, args,
@@ -208,7 +208,10 b' def sshargs(sshcmd, host, user, port):'
208 208 raise error.Abort(
209 209 _('illegal ssh hostname or username starting with - or /: %s') %
210 210 args)
211 return port and ("%s %s %s" % (args, pflag, port)) or args
211 args = shellquote(args)
212 if port:
213 args = '%s %s %s' % (pflag, shellquote(port), args)
214 return args
212 215
213 216 def setflags(f, l, x):
214 217 pass
@@ -1100,6 +1100,11 b' pooled".'
1100 1100
1101 1101 SEC: check for unsafe ssh url
1102 1102
1103 $ cat >> $HGRCPATH << EOF
1104 > [ui]
1105 > ssh = sh -c "read l; read l; read l"
1106 > EOF
1107
1103 1108 $ hg clone 'ssh://-oProxyCommand=touch${IFS}owned/path'
1104 1109 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch${IFS}owned/path'
1105 1110 [255]
@@ -1116,6 +1121,42 b' SEC: check for unsafe ssh url'
1116 1121 $ hg clone 'ssh://-oProxyCommand=touch owned%20foo@example.com/nonexistent/path'
1117 1122 abort: potentially unsafe url: 'ssh://-oProxyCommand=touch owned foo@example.com/nonexistent/path'
1118 1123 [255]
1124
1125 #if windows
1126 $ hg clone "ssh://%26touch%20owned%20/" --debug
1127 running sh -c "read l; read l; read l" "&touch owned " "hg -R . serve --stdio"
1128 sending hello command
1129 sending between command
1130 abort: no suitable response from remote hg!
1131 [255]
1132 $ hg clone "ssh://example.com:%26touch%20owned%20/" --debug
1133 running sh -c "read l; read l; read l" -p "&touch owned " example.com "hg -R . serve --stdio"
1134 sending hello command
1135 sending between command
1136 abort: no suitable response from remote hg!
1137 [255]
1138 #else
1139 $ hg clone "ssh://%3btouch%20owned%20/" --debug
1140 running sh -c "read l; read l; read l" ';touch owned ' 'hg -R . serve --stdio'
1141 sending hello command
1142 sending between command
1143 abort: no suitable response from remote hg!
1144 [255]
1145 $ hg clone "ssh://example.com:%3btouch%20owned%20/" --debug
1146 running sh -c "read l; read l; read l" -p ';touch owned ' example.com 'hg -R . serve --stdio'
1147 sending hello command
1148 sending between command
1149 abort: no suitable response from remote hg!
1150 [255]
1151 #endif
1152
1153 $ hg clone "ssh://v-alid.example.com/" --debug
1154 running sh -c "read l; read l; read l" v-alid\.example\.com ['"]hg -R \. serve --stdio['"] (re)
1155 sending hello command
1156 sending between command
1157 abort: no suitable response from remote hg!
1158 [255]
1159
1119 1160 We should not have created a file named owned - if it exists, the
1120 1161 attack succeeded.
1121 1162 $ if test -f owned; then echo 'you got owned'; fi
@@ -461,7 +461,7 b' debug output'
461 461
462 462 $ hg pull --debug ssh://user@dummy/remote
463 463 pulling from ssh://user@dummy/remote
464 running .* ".*/dummyssh" user@dummy ('|")hg -R remote serve --stdio('|") (re)
464 running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
465 465 sending hello command
466 466 sending between command
467 467 remote: 355
@@ -477,7 +477,7 b' debug output'
477 477
478 478 $ hg pull --debug ssh://user@dummy/remote
479 479 pulling from ssh://user@dummy/remote
480 running .* ".*/dummyssh" user@dummy ('|")hg -R remote serve --stdio('|") (re)
480 running .* ".*/dummyssh" ['"]user@dummy['"] ('|")hg -R remote serve --stdio('|") (re)
481 481 sending hello command
482 482 sending between command
483 483 remote: 355
General Comments 0
You need to be logged in to leave comments. Login now