Allow passing some configuration for user/password on SSH

With some real integration testing it looks like the "set an environment
variable" approach is not really going to work effectively.

I think the script {} will need to be treated like a template instead, since
different shells require different ways of setting env variables and it doesn't
appear that there's a good ssh2-based way to set these environment variables.
This commit is contained in:
R Tyler Croy 2020-12-30 22:46:29 -08:00
parent 7b9066d096
commit 754fd428f8
4 changed files with 32 additions and 3 deletions

View File

@ -17,11 +17,21 @@ pub struct Group {
pub struct Target {
pub name: String,
pub uri: String,
pub config: Option<Config>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config {
#[serde(default = "default_transport")]
pub transport: Transport,
pub ssh: Option<SshConfig>,
}
fn default_transport() -> Transport { Transport::Ssh }
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SshConfig {
pub user: String,
pub password: String,
}
#[derive(Clone, Debug, Deserialize, Serialize)]

View File

@ -36,8 +36,20 @@ impl Transport for Ssh {
let mut sess = Session::new().unwrap();
sess.set_tcp_stream(tcp);
sess.handshake().unwrap();
sess.userauth_agent(&std::env::var("USER").unwrap())
.unwrap();
let mut authenticated = false;
if let Some(config) = &target.config {
if let Some(sshconfig) = &config.ssh {
// requires PasswordAuthentication yes
sess.userauth_password(&sshconfig.user, &sshconfig.password).unwrap();
authenticated = true;
}
}
if ! authenticated {
sess.userauth_agent(&std::env::var("USER").unwrap())
.unwrap();
}
let mut channel = sess.channel_session().unwrap();
@ -45,6 +57,7 @@ impl Transport for Ssh {
if let Some(env) = env {
for (key, val) in env.iter() {
channel.setenv(key, val);
segments.push(format!("export ZAP_{}=\"{}\"", key.to_uppercase(), val));
}
}

View File

@ -9,6 +9,12 @@ targets:
uri: 192.168.1.41
- name: gopher
uri: 192.168.1.41
- name: zap-freebsd
uri: 192.168.1.224
config:
ssh:
user: root
password: root
config:
transport: ssh

View File

@ -7,6 +7,6 @@ task Echo {
}
}
script {
inline = "echo ${ZAP_MSG}"
inline = "env; echo ${ZAP_MSG}"
}
}