Installing TensorFlow on Kali (Rolling Base) CPU Mode

Virtual Security Labs
2 min readJan 12, 2017

--

TensorFlow — An open-source software library for Machine Intelligence.

In the following articles, we will use TensorFlow for Pentests.

Installing

Step 1:

root@kali:~# apt-get install python-pip python-dev -y
Reading package lists… Done
Building dependency tree
Reading state information… Done
python-dev is already the newest version (2.7.13–1).
python-dev set to manually installed.
python-pip is already the newest version (9.0.1–1).
python-pip set to manually installed.
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

Step 2:

root@kali:~# export TF_BINARY_URL=https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl

Step 3:

root@kali:~# pip install — upgrade $TF_BINARY_URL
Collecting tensorflow==0.12.1 from https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl
Downloading https://storage.googleapis.com/tensorflow/linux/cpu/tensorflow-0.12.1-cp27-none-linux_x86_64.whl (43.1MB)
100% |████████████████████████████████| 43.1MB 31kB/s
Collecting mock>=2.0.0 (from tensorflow==0.12.1)
Downloading mock-2.0.0-py2.py3-none-any.whl (56kB)
100% |████████████████████████████████| 61kB 1.7MB/s
Requirement already up-to-date: numpy>=1.11.0 in /usr/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Collecting protobuf>=3.1.0 (from tensorflow==0.12.1)
Downloading protobuf-3.1.0.post1-py2.py3-none-any.whl (347kB)
100% |████████████████████████████████| 348kB 2.6MB/s
Requirement already up-to-date: wheel in /usr/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Requirement already up-to-date: six>=1.10.0 in /usr/lib/python2.7/dist-packages (from tensorflow==0.12.1)
Collecting funcsigs>=1; python_version < “3.3” (from mock>=2.0.0->tensorflow==0.12.1)
Downloading funcsigs-1.0.2-py2.py3-none-any.whl
Collecting pbr>=0.11 (from mock>=2.0.0->tensorflow==0.12.1)
Downloading pbr-1.10.0-py2.py3-none-any.whl (96kB)
100% |████████████████████████████████| 102kB 3.4MB/s
Collecting setuptools (from protobuf>=3.1.0->tensorflow==0.12.1)
Downloading setuptools-32.3.1-py2.py3-none-any.whl (479kB)
100% |████████████████████████████████| 481kB 1.9MB/s
Installing collected packages: funcsigs, pbr, mock, setuptools, protobuf, tensorflow
Found existing installation: setuptools 32.0.0
Not uninstalling setuptools at /usr/lib/python2.7/dist-packages, outside environment /usr
Successfully installed funcsigs-1.0.2 mock-2.0.0 pbr-1.10.0 protobuf-3.1.0.post1 setuptools-32.3.1 tensorflow-0.12.1

Run TensorFlow from the Command Line

Open a terminal and type the following:

$ python
...
>>> import tensorflow as tf
>>> hello = tf.constant('Hello, TensorFlow!')
>>> sess = tf.Session()
>>> print(sess.run(hello))
Hello, TensorFlow!
>>> a = tf.constant(10)
>>> b = tf.constant(32)
>>> print(sess.run(a + b))
42
>>>

Run a TensorFlow demo model

All TensorFlow packages, including the demo models, are installed in the Python library. The exact location of the Python library depends on your system, but is usually one of:

/usr/local/lib/python2.7/dist-packages/tensorflow
/usr/local/lib/python2.7/site-packages/tensorflow

You can find out the directory with the following command (make sure to use the Python you installed TensorFlow to, for example, use python3 instead of python if you installed for Python 3):

$ python -c 'import os; import inspect; import tensorflow; print(os.path.dirname(inspect.getfile(tensorflow)))'

The simple demo model for classifying handwritten digits from the MNIST dataset is in the sub-directory models/image/mnist/convolutional.py. You can run it from the command line as follows (make sure to use the Python you installed TensorFlow with):

# Using 'python -m' to find the program in the python search path:
$ python -m tensorflow.models.image.mnist.convolutional
Extracting data/train-images-idx3-ubyte.gz
Extracting data/train-labels-idx1-ubyte.gz
Extracting data/t10k-images-idx3-ubyte.gz
Extracting data/t10k-labels-idx1-ubyte.gz
...etc...
# You can alternatively pass the path to the model program file to the python
# interpreter (make sure to use the python distribution you installed
# TensorFlow to, for example, .../python3.X/... for Python 3).
$ python /usr/local/lib/python2.7/dist-packages/tensorflow/models/image/mnist/convolutional.py
...

References:

https://www.tensorflow.org/
https://www.tensorflow.org/get_started/os_setup#pip_installation

--

--