Installing pyautogui on Ubuntu Server

The Issue

I was recently assisting a QA engineer with some #Fun™ problems on Jenkins where tests running pyautogui (running under Python 2.7) were failing because pyautogui was not installed. Every time we attempted to pip install pyautogui it would give an error similar to the following:

Downloading/unpacking pyautogui
Downloading PyAutoGUI-0.9.36.tar.gz (46kB): 46kB downloaded
Running setup.py (path:/tmp/pip-build-tbxln81q/pyautogui/setup.py) egg_info for package pyautogui
Traceback (most recent call last):
File "", line 17, in
File "/tmp/pip-build-tbxln81q/pyautogui/setup.py", line 6, in
version=import('pyautogui').version,
File "/tmp/pip-build-tbxln81q/pyautogui/pyautogui/init.py", line 115, in
from . import _pyautogui_x11 as platformModule
File "/tmp/pip-build-tbxln81q/pyautogui/pyautogui/_pyautogui_x11.py", line 160, in
_display = Display(os.environ['DISPLAY'])
File "/usr/lib/python3.4/os.py", line 633, in getitem
raise KeyError(key) from None
KeyError: 'DISPLAY'
Complete output from command python setup.py egg_info:
Traceback (most recent call last):

File "", line 17, in

File "/tmp/pip-build-tbxln81q/pyautogui/setup.py", line 6, in

The Fix

Ensure you have the following packaged installed: xserver-xorg, python-pip, python-xlib, xfce4 (you can use a different desktop env such as Gnome or KDE), and xauth.
sudo apt-get install -y xserver-xorg python-pip python-xlib xfce4 xauth
Also ensure that once you’ve install pip that you upgrade pip by running the following:
pip install --upgrade pip
Open a GUI session either through xrdp (if installed) or console. Once you are here run the following command:
echo $DISPLAY
Open an SSH connection to the server and set the $DISPLAY environment variable to match the output of the command above, in my case it was :10.0
export DISPLAY=:10.0
You can confirm this value is set by running the echo command again. Once this is in place run the following to install pyautogui
pip install pyautogui

Other Errors
If you receive any other errors around xauth or xserver try purging and reinstalling the packages above. You may also need to install a few other pip packages such as pillow and xlib.

Guacamole Server For Home Labs

So you’re an IT pro with a home lab, that’s awesome! Except when you aren’t at home and you can’t get to all of your machines that you need to. Exposing RDP or SSH without multi-factor auth is certainly not something I’d recommend. This is where Guacamole comes in incredibly handy. Guacamole is a web based client that allows you to establish RDP, SSH, and Telnet sessions from within the local network. Port forwarding 8080 for Guacamole allows for outside access thus giving you SSH, RDP, and Telnet access on your local network without exposing your entire home lab to the outside internet.

Here’s the install process:

-Setup a Centos 6 or 7 VM with at least 2 cores and a good 4gb or RAM and a small 10gb drive
-run the following commands below (leverages the script to complete the install of Guacamole and all of its dependancies)

Install Wget
yum install wget -y

Wget the install script
wget http://sourceforge.net/projects/guacamoleinstallscript/files/CentOS/guacamole-install-script.sh

chmod the script to make it executable
sudo chmod 755 guacamole-install-script.sh

Run the script
sudo ./guacamole-install-script.sh

Open a browser and visit the ip or hostname:8080/guacamole

Screen Shot 2016-10-26 at 10.14.41 AM

Once logged in you can see any node groups you created in a tree along with their connections:
Screen Shot 2016-10-26 at 10.14.55 AM

To add additional connections click your username in the top right, choose settings, and then click the connections tab and choose create new connection and fill out the necessary info:

Screen Shot 2016-10-26 at 10.16.51 AM

I’ve been using Guacamole for about 8 months now and it’s great to be able to make changes to my managed switches and access all of my lab machines. I hope this has been a helpful post and that you enjoy Guacamole server!

Image Magick 0 Day Threat

Vulnerability

Image Magick has a potential vulnerability noted by http://www.openwall.com/lists/oss-security/2016/05/03/18

 

Basically in short the exploit allows commands to be run remotely when passed via curl or a URL. To see if you are vulnerable try running the following command on your server:

convert 'https://example.com"| ls "-la' out.png

If you successfully list the directory then you are vulnerable.

 

The Fix

The quick easy fix for this is to adjust your policy.xml file, which depending on version installed will either be in /etc/ImageMagick/policy.xml (in versions 6.6 and newer of ImageMagick or /usr/lib64/ImageMagick/config/policy.xml in versions 6.5.x and older. Simply paste the following in your policymap section:

<policy domain="coder"rights="none"pattern="EPHEMERAL"/>
<policy domain="coder"rights="none"pattern="URL"/>
<policy domain="coder"rights="none"pattern="HTTPS"/>
<policy domain="coder"rights="none"pattern="MVG"/>
<policy domain="coder"rights="none"pattern="MSL"/>

Once you’ve made the necessary adjustments run the test from above again and it should be denied.

Entire Policy.xml

If you need a better contextual example below is a policy.xml file containing the fix:

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE policymap [
<!ELEMENT policymap (policy)+>
<!ELEMENT policy (#PCDATA)>
<!ATTLIST policy domain (delegate|coder|filter|path|resource) #IMPLIED>
<!ATTLIST policy name CDATA #IMPLIED>
<!ATTLIST policy rights CDATA #IMPLIED>
<!ATTLIST policy pattern CDATA #IMPLIED>
<!ATTLIST policy value CDATA #IMPLIED>
]>
<!--
  Configure ImageMagick policies.
  Domains include system, delegate, coder, filter, path, or resource.
  Rights include none, read, write, and execute.  Use | to combine them,
  for example: "read | write" to permit read from, or write to, a path.
  Use a glob expression as a pattern.
  Suppose we do not want users to process MPEG video images:
    <policy domain="delegate" rights="none" pattern="mpeg:decode" />
  Here we do not want users reading images from HTTP:
    <policy domain="coder" rights="none" pattern="HTTP" />
  Lets prevent users from executing any image filters:
    <policy domain="filter" rights="none" pattern="*" />
  The /repository file system is restricted to read only.  We use a glob
  expression to match all paths that start with /repository:
    <policy domain="path" rights="read" pattern="/repository/*" />
  Any large image is cached to disk rather than memory:
    <policy domain="resource" name="area" value="1gb"/>
  Note, resource policies are maximums for each instance of ImageMagick (e.g.
  policy memory limit 1GB, -limit 2GB exceeds policy maximum so memory limit
  is 1GB).
-->
<policymap>
  <!-- <policy domain="system" name="precision" value="6"/> -->
  <!-- <policy domain="resource" name="temporary-path" value="/tmp"/> -->
  <!-- <policy domain="resource" name="memory" value="2GiB"/> -->
  <!-- <policy domain="resource" name="map" value="4GiB"/> -->
  <!-- <policy domain="resource" name="area" value="1gb"/> -->
  <!-- <policy domain="resource" name="disk" value="16eb"/> -->
  <!-- <policy domain="resource" name="file" value="768"/> -->
  <!-- <policy domain="resource" name="thread" value="4"/> -->
  <!-- <policy domain="resource" name="throttle" value="0"/> -->
  <!-- <policy domain="resource" name="time" value="3600"/> -->
  <policy domain="coder" rights="none" pattern="EPHEMERAL" />
  <policy domain="coder" rights="none" pattern="URL" />
  <policy domain="coder" rights="none" pattern="HTTPS" />
  <policy domain="coder" rights="none" pattern="MVG" />
  <policy domain="coder" rights="none" pattern="MSL" />
</policymap>