Hints and Tips for PythonChallenge level 0

This is a page of hints for the Pythonchallenge.com level 0 challenge

It does not contain the answer so you can use as many hints as you want but still have to put everything together yourself to complete it

Note: A lot of these challenges have multiple different ways of solving them, the hints here might not match to what you have found already.

Expand for hint 1

Numbering in python starts at 0 and goes up.

Expand for hint 2

The URL bar is normally shown at the top of your browser, can you manually edit it?

Expand for hint 3

The aim is to get to page for the next level.

Expand for hint 4

Python has many mathematical operators.

Expand for hint 5

a single * is for multiplication, a double ** is for something else.

Expand for hint 6

If you think your maths has worked, try editing the URL once again

Installing netfilterqueue in Kali

I had some trouble recently trying to install the python library netfilterqueue onto my Kali box as the usual pip or pip3 commands didn’t seem to work.

both python 2 and python 3 brought back a similiar error:

1

Command “/usr/bin/python3 -u -c “import setuptools, tokenize;__file__=’/tmp/pip-install-8l8q2wql/netfilterqueue/setup.py’;f=getattr(tokenize, ‘open’, open)(__file__);code=f.read().replace(‘\r\n’, ‘\n’);f.close();exec(compile(code, __file__, ‘exec’))” install –record /tmp/pip-record-sk6qu_jn/install-record.txt –single-version-externally-managed –compile” failed with error code 1 in /tmp/pip-install-8l8q2wql/netfilterqueue/

One method to get around it is to try and install it on a different flavour of Linux, but after a bit of trial and error I found that you can get it onto Kali using:

sudo apt-get install python-netfilterqueue

2

This gets it onto your machine for python 2:

3.png

 

port scanner python script

Python port scanner – raw code with explanation

If you ever find yourself without access to Nmap here is some quick python code for testing the up/down status of 1000 TCP ports on a target host. The code is explained at the bottom:

#!/usr/bin/python

import socket
from termcolor import colored

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)

host = input(“Enter the target host: “)

def portscanner(port):
if sock.connect_ex((host,port)):
print(colored(“Port %d is closed” % (port), ‘red’))
else:
print(colored(“port %d is open” % (port), ‘green’))

for port in range(1,1000):
portscanner(port)

Explanation:

import socket
from termcolor import colored

These 2 libraries are responsible for creating the connection to the target and for allowing us to add colour to the output

sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
socket.setdefaulttimeout(1)

Sets the connection to use IP4 and sets the timeout to 1 second so you don’t get stuck waiting for connection requests to time out

host = input(“Enter the target host: “)

This is the prompt which you see when you run the code, it adds the input to the ‘host’ variable

def portscanner(port):
if sock.connect_ex((host,port)):
print(colored(“Port %d is closed” % (port), ‘red’))
else:
print(colored(“port %d is open” % (port), ‘green’))

Here is the main function. Instead of testing for a successful connection it looks for a failure, if so it reports that the port is closed. If anything else comes back it assumes the port is open and reports that.

for port in range(1,1000):

Sets the script to scan ports 1- 1000, you can change this to specific numbers or increase the range up to 65535