Install PowerShell on Kali Linux

I tried to install PowerShell on Kali Linux Rolling by following instructions on the GitHub page as well as other articles I found online and none of them worked. I’m going to tell you what worked for me.

In the past I’ve stuck to Bash and Python for all of my scripting needs because they work cross platform. My work issued laptop runs Windows 10 and I use Git Bash to run my simple shell scripts that I use mainly to slice, dice, and reformat data, and Python for everything else. I’m a big fan of using one cross platform scripting language when possible.

Lately I’ve found a need to dive into PowerShell to be able to understand a complex script that I took over from a departing coworker. I was really surprised at how easy it is to work with XML using PowerShell after struggling to read XML with Python and xmlstarlet. Add in some Unicode and dependency problems while switching back and forth between Python 2.7 and 3.5 and I knew is was time to give PowerShell a chance. This had me thinking about starting a personal project to create a cross platform script in PowerShell to manage pentests and reporting.

Let’s get started installing PowerShell on Kali.

Edit: Updated 9/25/2018

apt -y install apt-transport-https curl gnupg
curl | apt-key add -
dpkg -i libicu57_57.1-6_amd64.deb
echo "deb [arch=amd64] stretch main" > /etc/apt/sources.list.d/powershell.list
apt-get update && apt -y install powershell

Now start PowerShell:

If you get any errors when using certain PowerShell commands, like curl for example, check your aliases. Some common aliases that work by default on Windows aren’t set here. You’ll need to either use the expanded name or set a new alias.

Using Python for IP addresses

Part of the day to day tasks of any Information Security professional may include transforming system input and output text and calculating IP addresses. In this article I demonstrate how use Python to work with IP addresses and transform system input/output.

A system that I manage at work doesn’t allow you to enter networks in CIDR notation like, it requires starting and ending IP addresses in a range like In the past I’ve used ipcalc on Linux to calculate IP addresses when I have something other than a simple netmask to calculate. Today I had a list of IP subnets of various netmasks that I needed to transform into a comma separated list in the format of,…

I’m going to use the ipcalc module for Python to demonstrate how to do this. You can install it from an administrator cmd prompt or using root or sudo in a Linux terminal with the following command:

pip install ipcalc

Pretty simple to install. Now lets move on to a demonstration of how to use it. After importing the ipcalc module, I created a new object and attempted to output the first and last host on the network but it didn’t work quite as expected until I cast the output to string.

Python 2.7.12 (v2.7.12:d33e0cf91556, Jun 27 2016, 15:19:22) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> import ipcalc
>>> subnet = ipcalc.Network('')
>>> print subnet.host_first
<bound method Network.host_first of Network('')>
>>> print str(subnet.host_first)
<bound method Network.host_first of Network('')>
>>> print(str(subnet.host_first()))
>>> print str(subnet.host_first())
>>> print str(subnet.host_last())
>>> print str(subnet.broadcast())
>>> print str(
>>> print str(subnet.to_ipv6())
>>> print str(subnet.size())
>>> ipaddress = ipcalc.IP('')
>>> print str(ipaddress.subnet())
>>> print str(
>>> print str(ipaddress.guess_network())

Now I’m going to take an input file with a network name followed by network address in CIDR format on each line, cut out just the subnet, and output the networks in firsthost-lasthost,firsthost-lasthost,…” format.

>>> with open('ips.txt') as f:
    content = f.readlines()

>>> content = [x.strip() for x in content]

>>> import sys
>>> for x in content:
    subnet = x.split(' ')[-1]
    networkobj = ipcalc.Network(subnet)
    sys.stdout.write("%s-%s," % (str(networkobj.host_first()),str(networkobj.host_last())))

In the code above, I loop through each line of the file and get the last word in the string which is the subnet address. It was necessary to use sys.stdout.write() to get rid of the space between each network start and end addresses using Python 2.7. I’m not going to show you the output. If you want to know my public IP addresses then you’ll have to work to find them yourself. 🙂

I’m sure that there are more than one way to write the code for this exercise. If you have any constructive feedback please leave a comment. Thanks for visiting!