Selenium Nodes as a Windows Service remotely started via telnet.

Hello User!

In this use case, I want to simulate a user testing a website and i want to do this using selenium grid and selenium node. The basic approach is to write a selenium script at the grid server for testing my website and make the nodes walk these tests. There is one problem though, the Selenium Node needs a jar file to be running in the context of a user in a windows node. This may seem as a one time manual task, but somehow i found it difficult to allow a jar file running forever in my windows nodes for a long time as a concern that it could hog my test systems extremely precious memory and CPU or if my previous test was abrupt had un handled exception cases that could corrupt my next run and requires sanitation.

So here is how i managed to control this requirement.

Step 1: Getting a Remote Handle on a Windows Controller (Telnet service!, very insecure). Running telnet server on windows 7.

      Never run telnet in your Production environment, it not secure and is an easy backdoor. Having said that, my tests are just experiments. So i preferred enabling telnet as it is a windows system defaults free feature. To enable this on a windows 7 machine, navigate to
      1. Control Panel > Programs > Turn On/Off Windows Features and then select and start the Telnet Server.

DoNotEnable

This however only installs the service and we will need to ensure that the service is running. So start run -> Services.msc -> Telnet Server -> Start Automatically.

Screen Shot 2015-08-21 at 11.06.22 pm

Now that this is done, Telnet will still be restricted for logon. Windows is trying to protect you :), you will need to explicitly add a specific user that you need to test within the Group allocated for Telnet Users. Start -> Right Click on “My Computer” -> Manage -> Local Users and Groups -> Groups -> TelnetClients -> Add User and add your user with which you will use to login remotely via Telnet.

Screen Shot 2015-08-21 at 11.09.04 pm

Validate that now telnet is up and running which is accessible on your client machine by running this command on the windows 7 machine -> netstat -ano | find “:23” You should see something like “0.0.0.0:23” in LISTENING State. Now you can log into a windows machine via a Linux machine using telnet.

Step 2: Preparing a Windows Service! for running the java jar file on demand.

We will next create a script with *.bat extension. it is easy as these are just the same commands that one would type on the command prompt. Please make sure you have the selenium jar file in the same folder as the commands included in the bat script file.Screen Shot 2015-08-22 at 12.57.24 am

Example-> SecretAgent.bat:

Note: I’m purposely including “VERSION=RAMNATH” to identify my windows node, so that my grid server can identify my specific windows client using the desired capability “version”.

Now that this is done, if we need to execute this bat file on demand. It can only be done using a task with appropriate windows rights. To create a windows task we need to do the following,

  1. Start -> Run  -> “Task”, Right click on “Task Scheduler”
  2. Create a Basic Task , add Name and description as it fits your requirement. -> Next
  3. Trigger -> “When the computer Starts”
  4. What Action to perform -> “Start a program”
  5. Path of Program/Script -> C:\SecretAgent.bat & start in -> C:\
  6. Next and Finish

This will ensure that the Task is ready. However you will need to modify some rights so that this functions correctly. Hence, click on Task Schedule again -> Click on the task that is now added and change the General Setting to “Run whether user is logged on or not” and “Run with highest privileges”. Screen Shot 2015-08-22 at 12.22.10 amAdditionally, verify that this task can also be run on-demand. This will ensure that now you can start a task via telnet remotely from your test controller.

Screen Shot 2015-08-22 at 12.23.51 am

So from a Linux Terminal we can now start or stop this service on demand. Which Actually connects your selenium node to selenium hub on demand &  java to run on demand.

Screen Shot 2015-08-22 at 12.40.33 am

Screen Shot 2015-08-22 at 1.08.08 am

In the grid now you have the node ready to simulate user.

Screen Shot 2015-08-22 at 1.09.27 am

Published by Ramnath Shenoy

I work a penetration tester, this blog is just some of my personal notes!

Leave a comment

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: