05
Thu, Dec
6 New Articles

Exploiting Remote Command Execution Across IBM Operating System Platforms

Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

As more and more organizations include heterogeneous operating systems such as MVS, OS/2, OS/400, UNIX, and NT in their enterprises, the need for communications between those platforms becomes more important. Until recently, intersystem communications have typically been limited to file transfers. Between MVS and a DOS, Windows, or OS/2 workstation, for example, file transfers were traditionally accomplished with IND$FILE GET and PUT. But since the multiplatform acceptance of TCP/IP, file transfers between systems are now frequently accomplished using the protocol’s File Transfer Protocol, more commonly known as FTP. However, cross-platform communications need not be limited to transferring files. Most TCP/IP implementations also permit remote command execution.

Imagine being able to execute a CL command or REXX program on an AS/400 from an OS/2 workstation or an MVS host, or even executing an MVS Time Sharing Option (TSO), OS/2 command, or REXX program from an AS/400. This is all possible now.

This article will introduce the basic TCP/IP functions used to effect remote command execution and the daemons (the service program with which a remote command communicates) necessary to support the execution on the target operating system. Note that this is the same remote command feature discussed in the July/August issue of Client Access/400 Expert, but instead of focusing on the implementation of Incoming Remote Command within Client Access/400, we’ll be looking at the feature from the perspective the AS/400 and other servers in the network.

An Overview of the Available Remote Commands


Before discussing specific operating system implementations, an overview of the remote commands is in order. Remote Execution, REXEC for short, is a TCP/IP function that can execute a command on any remote system running REXECD, the REXEC daemon. This daemon must be started on the target system before it can accept remote commands from another system. For example, before executing a remote command from the AS/400 to an OS/2 workstation, the REXECD daemon would have to already be running on the OS/2 workstation. The same is true for Windows 95/NT or an RS/6000. This is similar to the requirements of FTP: You can only FTP to a system where FTPD, the FTP daemon, is already started. When this REXEC daemon is first started on the target system, a user ID and password are specified. (The actual specification differs slightly from platform to platform. On a Client Access/400 Windows 95/NT workstation, multiple user IDs and passwords can be set up as part of the configuration.) Later, when the remote system sends a command to this daemon using the REXEC command, a matching user ID and password for the target REXEC daemon will be required. These can be passed as part of the REXEBoth MVS TCP/IP and OS/2 TCP/IP support the REXEC client and REXECD daemon, which means they can send and execute remote commands via REXEC command. OS/400, however, implements remote commands a little differently. OS/400 supports the REXEC client, meaning it can initiate a remote command via Run Remote Command (RUNRMTCMD). OS/400 does not support the REXECD daemon program, although IBM has indicated in a statement of direction that the support may be forthcoming in the next release. The current hole in support means that you cannot make an AS/400 the target of an REXEC client call. A diagram of these relationships can be seen in Figure 1. However, the lack of support doesn’t mean you can’t execute a remote command on the AS/400. You can.

The current strategy for executing remote commands on an AS/400 is to exploit the RCMD support provided by the OS/400 TCP/IP FTP server. RCMD can issue a CL command on a remote AS/400, so at first glance it would seem similar to REXEC, but there’s one subtle difference. When using REXEC, you essentially have a remote shell, and you receive the command output as is you were Telneting to the remote machine. Unfortunately, RCMD can not return program or command output. You can get around this shortcoming by coding your CL command or program to write its output to a file. Because you’re already in an FTP stream executing the RCMD, you can follow the execution with an FTP GET statement for the output file. Exploiting a combination of either TCP/IP REXEC or RUNRMTCMD with FTP RCMD and GET will let users remotely execute commands on a target system and receive the output back at the originating system.

Executing a Remote Command from MVS

MVS TCP/IP runs as a started task and supports REXEC and FTP via the TSO READY prompt or batch. From TSO, you can execute commands via REXEC on remote OS/2 workstations running REXECD or other MVS systems running RXSERVE, the Remote Execution Server (its equivalent of REXECD). You can also execute commands on a remote AS/400 using the FTP Server subcommand, RCMD, to pass CL commands to a target system. A sample REXEC invocation specified at the TSO READY prompt looks like this:

rexec -l WSUID -p WSPSWD 111.222.33.444 f:_cmds estrcmd.cmd ‘OS/2’

In this example, -l indicates that the logon ID will follow, while -p indicates that the password follows. Here, the logon ID and password passed to OS/2 for authentication are WSUID and WSPSWD, respectively. (Warning: Case is significant—very significant—to TCP/IP. If the logon ID is WSUID and you type in wsuid, they will not match!) Following the logon ID and password, you see is the target workstation TCP/IP address, in this example 111.222.33.444. The trailing data is sent to the REXECD daemon and is interpreted as the command line to be executed on the remote system. In this example, we’re executing the REXX command TESTRCMD (Figure 2) from the _CMDS directory


on the workstation’s F: drive. We are also passing the parameter OS/2. The output from this execution is illustrated in Figure 3. (You can specify other options on the REXEC invocation, but they’re not relevant to this discussion. However, if you would like to know more about them, just type REXEC by itself on the TSO command line, or refer to the references at the end of this article.)

In order to execute a remote command from MVS to an AS/400, the TSO user would need to first open an FTP connection then issue the RCMD which would take the following format:

quote rcmd STRREXPRC+
SRCMBR(TESTRCMD) SRCFILE(CHRISMIK/REXSRC) PARM(‘OS/400 SYS1’)

Quote is an FTP subcommand indicating that the text following it is to be passed to the foreign host uninterpreted. The AS/400 FTP Server, then, recognizes the RCMD subcommand and executes the text that follows it.

In the preceding example, we’re executing the REXX command TESTRCMD (Figure 2) from the source file CHRISMIK/REXSRC passing the parameter OS/400 SYS1. (Remember that the output of the command is not returned, so the program output is not returned to the FTP stream.)

Executing a Remote Command on MVS

When configured to start the RXSERVE, MVS TCP/IP supports REXECD in a manner similar to OS/2, so the syntax described above for executing a remote command from MVS to OS/2 is the same for an invocation from OS/2 to MVS. But, REXEC is implemented a bit differently on the AS/400.

On the AS/400, RUNRMTCMD, not REXEC, is used. In the following example, which executes a REXX program on a remote MVS system, you’ll observe that the same information is passed on this RUNRMTCMD call as on the REXEC example above:

RUNRMTCMD+
CMD(‘ex dataset_name(TESTRCMD) ‘’MVS/TSO’’’) RMTLOCNAME(‘111.222.33.444’ *IP)
RMTUSER(uid) RMTPWD(passwd)

In this example, the REXX program TESTRCMD (Figure 2) found in dataset_name will be executed on the remote MVS machine. You should recognize the other parameters by now. Remember that RUNRMTCMD is really REXEC, so program or command output is returned to the user. However, unlike REXEC, RUNRMTCMD places the data in a spooled file that can be reviewed via the Work with Active Job command (WRKACTJOB), rather than returning it directly to the screen.

Executing a Remote Command from OS/2

The method for executing a command remotely from an OS/2 workstation is similar to the method I’ve already discussed. When executing to MVS or another OS/2 workstation, use REXEC from an OS/2 window. When executing to an AS/400, use the RCMD FTP server subcommand from an open FTP connection.

Executing a Remote Command on OS/2

To execute a command remotely on an OS/2 workstation, you will again use either REXEC or RUNRMTCMD, based on the system you are executing the command from. The only real difference is that OS/2 REXECD must be started instead of RXSERVE. This can be done from an OS/2 window or via the TCP/IP Configuration application. When you start REXECD, you’ll need to supply USER and PASSWD values. This is the login/password pair specified when another system attempts to execute a remote command on that OS/2 workstation. It bears repeating that the login name and password are case- sensitive values.


Executing a Remote Command from OS/400

By now, you should understand that remote command support on the AS/400 is a little different than on MVS and OS/2 machines (and on UNIX and Wintel boxes, for that matter). To execute a remote command from the AS/400 to either MVS or OS/2 requires execution of the AS/400’s equivalent of REXEC, RUNRMTCMD, which does not get program output returned directly to it, but rather to a spooled file. Thus, the output from the following command, which executes a DIR command on a remote OS/2 workstation, will be presented in a file as illustrated in Figure 4.

RUNRMTCMD CMD(‘DIR f:_cmds’) RMTLOCNAME(‘111.222.33.444’ *IP)+ RMTUSER(uid) RMTPWD(passwd)

Executing a Remote Command on OS/400

Executing a remote command from MVS and OS/2 workstation on an AS/400 requires the use of the RCMD FTP Server subcommand. Executing a remote command from another AS/400 also requires the use of RCMD. You may question the use of RCMD for AS/400-to-AS/400 execution because RUNRMTCMD is available on OS/400, but remember that RUNRMTCMD is the client half of the remote command process. It can only send remote commands, not receive them. It’s the equivalent of REXEC, not the REXECD daemon.

Conclusion

Beyond file transfer, a valuable way to communicate across systems and platforms is by executing commands or programs on remote systems. TCP/IP provides REXEC, a flavor of which is implemented on most operating systems, including MVS, OS/2, OS/400, UNIX, and Windows. Remote commands can query system information and affect operations, giving users a high degree of enterprise control, even in heterogeneous environments.

References

AS/400 TCP/IP Configuration and Reference (SC41-3420-x) IBM TCP/IP for MVS, User’s Guide (SC31-7136-x) IBM TCP/IP for OS/2: User’s Guide (SC31-6075-x) OS/400 RQSxxx through WRKxxx Commands (SC41-4726-x)

REXEC vs. RSH

Remote Shell, or RSH, is similar to REXEC. The difference is in the way a user is validated. REXEC passes the USER and PASSWD to the remote system for authentication. RSH uses the originating TCP/IP address that is maintained on the remote systemÕs RHOSTS file. If the TCP/IP address of the origin user is in the remote systemÕs RHOSTS file (or other designated file which performs the same function) the RSH command is executed.

Thus, the command rsh 111.222.33.444 f:_cmds estrcmd.cmd ÔMy OS/2Õ when targeted to a remote system running RSHD (the RSH daemon), will have virtually the same effect as the
following command: rexec -l WSUID -p WSPSWD 111.222.33.444 f:_cmds estrcmd.cmd ÔMy OS/2Õ

You can look at the references included with this article for more information.

NETRC and RHOSTS


BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: