Issue with lsof command - shell

I have a service account executing below command on a solaris server
lsof -iTCP -n -P -F pcnfT -z$1
But I receive below error message as response
lsof: illegal option character: z
lsof 4.80 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/ latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
usage: [-?abChlnNoOPRstUvV] [+|-c c] [+|-d s] [+|-D D] [+|-f[cfgGn]] [-F [f]] [-g [s]] [-i [i]] [-k k] [+|-L [l]] [-m m] [+|-M] [-o [o]] [-p s] [+|-r [t]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.
What can probably cause this issue? And what are potential solutions?

delete -z parameter as below;
lsof -iTCP -n -P -F pcnfT
-z [z] specifies how Solaris 10 and higher zone information is to be
handled.
Without a following argument - e.g., NO z - the option speci-
fies that zone names are to be listed in the ZONE output col-
umn.

Related

Docker Run executing shell command can't access PATH environment variable

I'm using an official image from Microsoft which contains SQL tools used to interact with Microsoft SQL Servers. If I run the container interactively, I can run sqlcmd at the command line without any issue, because it is in the PATH variable:
$ docker run --rm -it -v $(pwd):/var/update/ -w /var/update mcr.microsoft.com/mssql-tools:latest
root#df20bd19b982:/var/update# sqlcmd
Microsoft (R) SQL Server Command Line Tool
Version 13.1.0007.0 Linux
Copyright (c) 2012 Microsoft. All rights reserved.
usage: sqlcmd [-U login id] [-P password]
[-S server or Dsn if -D is provided]
[-H hostname] [-E trusted connection]
[-N Encrypt Connection][-C Trust Server Certificate]
[-d use database name] [-l login timeout] [-t query timeout]
[-h headers] [-s colseparator] [-w screen width]
[-a packetsize] [-e echo input] [-I Enable Quoted Identifiers]
[-c cmdend]
[-q "cmdline query"] [-Q "cmdline query" and exit]
[-m errorlevel] [-V severitylevel] [-W remove trailing spaces]
[-u unicode output] [-r[0|1] msgs to stderr]
[-i inputfile] [-o outputfile]
[-k[1|2] remove[replace] control characters]
[-y variable length type display width]
[-Y fixed length type display width]
[-p[1] print statistics[colon format]]
[-R use client regional setting]
[-K application intent]
[-M multisubnet failover]
[-b On error batch abort]
[-D Dsn flag, indicate -S is Dsn]
[-X[1] disable commands, startup script, environment variables [and exit]]
[-x disable variable substitution]
[-? show syntax summary]
root#b33a916d4230:/var/update# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/mssql-tools/bin
root#b33a916d4230:/var/update#
sqlcmd is present in /opt/mssql-tools/bin/ folder which is part of the PATH env. variable.
but If I try to execute the sqlcmd command at the docker run... bash -c 'sqlcmd', it won't find it. I echoed PATH environment variable at the same command line and found that its path i.e /opt/mssql-tools/bin is already in the PATH.
$ docker run --rm -it -v $(pwd):/var/update/ -w /var/update mcr.microsoft.com/mssql-tools:latest bash -c "sqlcmd"
bash: sqlcmd: command not found
And to see the PATH env. variable, I did the following:
$docker run --rm -it -v $(pwd):/var/update/ -w /var/update mcr.microsoft.com/mssql-tools:latest bash -c 'echo $PATH'
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Question 1: Why Path Variable is different in case we use bash -c 'commands'?
Question 2: If bash -c or sh -c creates a new shell, how to execute shell commands with the container's environment variables especially the PATH environment variable.
When you run an interactive shell as root, it runs the commands from /root/.bashrc, which (in this particular image) include
export PATH="$PATH:/opt/mssql-tools/bin"
A better Docker image would have that setting in the Dockerfile itself, which exports it to all users of the image. You can build an image like that yourself easily.
FROM mcr.microsoft.com/mssql-tools:latest
ENV PATH="$PATH:/opt/mssql-tools/bin"
(Also, the export is superfluous; the variable is already exported by the shell.)
If you don't want to mess with the image, try
docker run --rm -it -v $(pwd):/var/update/ -w /var/update \
mcr.microsoft.com/mssql-tools:latest \
bash -c 'PATH=$PATH:/opt/mssql/bin sqlcmd'

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.

This is nc from the netcat-openbsd package. An alternative nc is available

I am using following piece of code on Ubuntu 14.4 to check whether ssh port in my remote machine is open or not
$PROXY_SERVER_IP=192.168.1.40
$LOGGER "Waiting for Proxy-VM ssh port to become active.."
while ! nc -z $PROXY_SERVER_IP 22; do
sleep 10s
done
Above code works some time but other time it result in infinite loop with following message
This is nc from the netcat-openbsd package. An alternative nc is available
in the netcat-traditional package.
usage: nc [-46DdhklnrStUuvzC] [-i interval] [-P proxy_username] [-p source_port]
[-s source_ip_address] [-T ToS] [-w timeout] [-X proxy_protocol]
[-x proxy_address[:port]] [hostname] [port[s]]
Is there any other way to to know whether port is open or not ?

Regarding synopsis of commands

I was playing with CHPASS command on my Mac OS X. I found the synopsis of CHPASS command on my bash shell and online is very different.
On my bash shell: chpass [-l location] [-u authname] [-s newshell] [user]
On google: chpass [-a list] [-p encpass] [-e expiretime] [-s newshell] [user]
chpass [-oly] [-a list] [-p encpass] [-e expiretime] [-s newshell]
[-d domain] [-h host] [user]
I didn't get why both synopsis are different. If I am right, do I need to update anything to get full synopsis? If yes, how do I do it?
There's no reason to think that the version of the chpass command you have on OS X is the same version of the command for which you found the synopsis online. You didn't provide any links so it's hard to know for sure, but it looks like you found online the documentation for the FreeBSD version version of the chpass command.
The man page for the OS X version of the command shows the same synopsis you found on your computer.
These are different implementations of the chpass command.

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