sarugaku / shellingham

Tool to Detect Surrounding Shell
ISC License
228 stars 33 forks source link

detect_shell fails on IBM i / AIX #21

Open kadler opened 5 years ago

kadler commented 5 years ago
>>> import shellingham
>>> shellingham.detect_shell() 
ps: illegal option -- w
ps: illegal option -- w
Usage: ps [-ANPaedfklmMZ] [-n namelist] [-F Format] [-o specifier[=header],...]
                [-p proclist][-G|-g grouplist] [-t termlist] [-U|-u userlist] [-c classlist] [ -T pid] [ -L pidlist] 
                [-@ [wparname] ]
Usage: ps [aceglnsuvwxX] [t tty] [ProcessNumber]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/QOpenSys/pkgs/lib/python3.6/site-packages/shellingham-1.3.1.dev0-py3.6.egg/shellingham/__init__.py", line 25, in detect_shell
shellingham._core.ShellDetectionFailure

The problem is that the AIX version of ps does not support the -w option. It does support the w option (without the - prefix) in Berkeley mode, but then it doesn't support the -o option. :disappointed:

uranusjr commented 5 years ago

I have absolutely zero experience on IBM systems, but one quick solution would be to look for /proc support, which is used if possible. Try this and see if it works

>>> from shellingham.posix import proc
>>> proc.detect_proc()   # This tries to check whether /proc is available.

If the above passes without exception, we’ll need to check why the proc format cannot be parsed. Otherwise we’ll need to play with ps. The w options are not essential (it isn’t that easy to hit the width limit), so there’re definitely ways to work around it.

If only I can get my hands on an actual IBM machine to play with. That’d be a cool exxperience.

kadler commented 5 years ago

I believe AIX has /proc starting with 7.1, but it's files are binary structures: https://www.ibm.com/support/knowledgecenter/en/ssw_aix_71/com.ibm.aix.files/proc.htm It also has no /proc/<pid>/cmdline

We run a subset of the AIX runtime on top of the IBM i OS and it has no /proc support at all :frowning_face:

uranusjr commented 5 years ago

Why do these UNIX system vendors make things so difficult 😞