Why is the command not gettng the input with pipe in bash? - bash

I am trying to do something simple in bash but I cannot get it to work. I have defined the variable:
export devcluster2="10.122.22.22"
in my .bashrc. When I type:
echo $devcluster2 I get as expected:
10.122.22.22
now I want to do:
echo '$devcluster2' | ssh
but I get
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user#]hostname [command]
I want to understand why the ssh doesn't get the output of echo as an input? and how can I get it to work?

To ssh to a host, you use:
ssh 10.122.22.22
If you want to ssh to a host in a variable, you therefore use:
ssh "$devcluster2"
Meanwhile, echo text | command is like running command and then typing in "text". If you to run ssh by itself and wait for an opportunity to enter text, it fails just like it does in your script:
$ ssh
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-E log_file] [-e escape_char]
[-F configfile] [-I pkcs11] [-i identity_file]
...

Related

Why does this simple Hydra command not work despite the writeup specifying the exact same syntax?

So lately I have been trying to learn hydra from tryhackme, and tried to use this simple command
hydra -l molly -P /Users/root/Desktop/ctf/rockyou.txt 10.10.161.247 http-form-post "/:username=^USER^&password=^PASS^:F=incorrect" -V
But it does not work and shows
Syntax: hydra [[[-l LOGIN|-L FILE] [-p PASS|-P FILE]] | [-C FILE]] [-e nsr] [-o FILE] [-t TASKS]
[-M FILE [-T TASKS]] [-w TIME] [-W TIME] [-f] [-s PORT] [-x MIN:MAX:CHARSET] [-c TIME]
[ISOuvVd46] [service://server[:PORT][/OPT]]
What am i doing wrong?
I am using Hydra V9.0 on MacOS Mojave.
This is the writeup I am talking about.
You have to specify the directory for the login form.
Try this instead:
hydra -l molly -P [wordlist directory] [IP] http-form-post "login/:username=^USER^&password=^PASS^:F=incorrect" -V
This shall work.

How to run scp on ec2

I'm trying to copy file from server to server by running scp command on ec2.
**My command:**
[ec2-user#ip-xx-xx-xx-xxx ~]$ scp -P 51865 user#207.154.xx.xx:/home/yakir/tr/tracker-2019-12-12.tar.gz ec2-user#ec2-3-xxx-xxx-xxx.compute-1.amazonaws.com:/home/ec2-user/tracker-2019-12-12.tar.gz
The error is:
usage: scp [-12346BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]
[-l limit] [-o ssh_option] [-P port] [-S program]
[[user#]host1:]file1 ... [[user#]host2:]file2
What should i do to get it works?
Thanks!
ssh to server and run scp
ssh -P 51865 user#207.154.xx.xx "scp /home/yakir/tr/tracker-2019-12-12.tar.gz ec2-user#ec2-3-xxx-xxx-xxx.compute-1.amazonaws.com:/home/ec2-user/tracker-2019-12-12.tar.gz"

Packer shell-local post-processor permissions

I am using Packer to create a custom Virtual Machine. I would like to use the post-processor after the build is finished. I am trying to keep it simple, using inline commands. However, some of them require sudo. This is the problem I am facing - I can't seem to make the execute_command work properly.
Currently what I have is:
"post-processors": [
{
"type":"shell-local",
"execute_command": "echo 'password' | sudo",
"inline": ["command 1", "command 2", "sudo command 3"]
}
]
This results in:
==> vmware-iso: Running post-processor: shell-local
==> vmware-iso (shell-local): Post processing with local shell script: /tmp/packer-shell867480064
vmware-iso (shell-local): usage: sudo -h | -K | -k | -V
vmware-iso (shell-local): usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
vmware-iso (shell-local): usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user]
vmware-iso (shell-local): [command]
vmware-iso (shell-local): usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
vmware-iso (shell-local): prompt] [-u user] [VAR=value] [-i|-s] [<command>]
vmware-iso (shell-local): usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p
vmware-iso (shell-local): prompt] [-u user] file ...
Does anyone have an idea how I should implement the execute_command to make it work?
You shouldn't pipe your PASSWORD to sudo!
Instead if you need to run passwordless (NOPASSWD) sudo configure sudo to allow it. Also verify if you need !requiretty. See sudoers.conf.

zsh run script without sudo

I made a bash script helpme that contains help configurations tasks that I use daily.
I would like to use it everywhere (even in other machines) with simple running:
$ helpme
I made this for that:(MAC OS)
$ sudo chmod +x helpme
$ sudo mv helpme /usr/local/bin/helpme
If I use bash terminal works correctly but now I'm using oh-my-zsh terminal and it shows me this message:
usage: sudo -h | -K | -k | -L | -V
usage: sudo -v [-AknS] [-g groupname|#gid] [-p prompt] [-u user name|#uid]
usage: sudo -l[l] [-AknS] [-g groupname|#gid] [-p prompt] [-U username] [-u user name|#uid] [-g groupname|#gid] [command]
usage: sudo [-AbEHknPS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user name|#uid] [-g groupname|#gid] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C fd] [-g groupname|#gid] [-p prompt] [-u user name|#uid] file ...
If I run with sudo works, but I don't want to use sudo
$ sudo helpme
Edited:
This is an example:
#!/bin/bash
main(){
echo invalid option
}
if [[ "${BASH_SOURCE[0]}" = "${0}" ]]; then
main "$#"
fi
Any idea?

OSX Terminal.app SSH port

I feel like a complete dunce - but I cannot seem to connect with Terminal.app and SSH to a non-standard SSH port. I'm on Mountain Lion.
I've tried all of the following:
$ ssh myuser#mysite.com -p 42586
$ ssh myuser#mysite.com -p42586
$ ssh -p 42586 myuser#mysite.com
$ ssh -p42586 myuser#mysite.com
I cannot seem to get the syntax right, all of the above produce an error. What is the correct order of flags? I have checked the man page and it shows it as preceding the [user]#[domain] section, however, this throws an error as well.
Edit:
More information and raw terminal output:
$ ssh mysite.com -p42586
--hangs--
$ ssh mysite.com -p 42586
--hangs--
$ ssh -p42586 mysite.com
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user#]hostname [command]
$ ssh -p 42586 mysite.com
usage: grep [-abcDEFGHhIiJLlmnOoPqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
/usr/bin/ssh: option requires an argument -- p
usage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c cipher_spec]
[-D [bind_address:]port] [-e escape_char] [-F configfile]
[-I pkcs11] [-i identity_file]
[-L [bind_address:]port:host:hostport]
[-l login_name] [-m mac_spec] [-O ctl_cmd] [-o option] [-p port]
[-R [bind_address:]port:host:hostport] [-S ctl_path]
[-W host:port] [-w local_tun[:remote_tun]]
[user#]hostname [command]
Examples 1 and 2 hang until timeout. 3 and 4 produce a grep usage echo as well as an ssh usage echo.
Edit 2:
Thanks for the suggestion #topguncoder my original attempt was the colon notation - but that produces a different error:
$ ssh myuser#mysite.com:42586
ssh: Could not resolve hostname mysite:42586: nodename nor servname provided, or not known
Try
"ssh" -p 42586 mysite.com
to ignore your alias settings. It looks like you might have ssh aliased to something else. If this works, you should check your .profile for any ssh aliases.
I believe that on your system, the ssh command somehow was redefined as the grep command. Try this:
alias | /usr/bin/grep ssh
What do you see? Also, try this:
/usr/bin/ssh -p 42586 myuser#mysite.com
Do you have a success connection? If ssh was aliased into something else. Check the following files:
~/.bash_profile
~/.bashrc
~/.profile
You can then remove the alias, or use the absolute path (e.g /usr/bin/ssh)

Resources