Bugs (2) Install (3) Linux (22) Python (10) Raspberry Pi (4)

Monday, 19 September 2016

5 commands you should NOT run.

If you do want to test them out you can check out this tutorial on installing vmware and run them inside a VM just for fun.

A list from this reddit post for people to post the most dangerous/annoying commands they can come up with.

The Classic Fork bomb:
Posted by cuba200611
This line crashes your system as it uses up all the resources. It works by creating a function which calls its self twice and has no way of terminating it's self. This quickly uses up all the resources and crashes your PC.

:(){ :|: & };:

Delete your whole hard drive:
This line deletes everything from the hard-drive when run as root.

rm -fr /

Break your CD drive:
This line constantly ejects your CD drive not allowing it to shut.
Posted by wee0x1b

while true; do eject; done

Overwrite you hard drive:
This line writes zeros to your hard drive
Posted by Celtore

dd if=/dev/zero of=/dev/sda

Chmod killer:
Posted by: therancor91
Explanation from gigolo_daniel:
For those wondering why this breaks your entire system giving you execution permission errors everywhere while prima facie it merely seems to add permissions, the primary reason is that it removes setuid and setgid bits on executables if you change permissions like that. These mode bits when an executable is ran run it under the permission of the owning user and owning group respectively, not the user who executes it. This is typically used with a lot of executables to allow a temporary elevation of privileges which is needed for a surprisingly large number of operations.

You can no longer normally become root after you done this because both sudo and su use the setuid bit to enable a login as root.

chmod 777 /

All of these commands show the true power of a one line command which could destroy your system, be careful when copying commands.

Saturday, 17 September 2016

Simulating your mouse

Sometimes you just want to automate tasks but the program only has a GUI. Simulating mouse clicks can make this job a lot easier and this is were xdotool comes in.

Installing xdotool:

Debian systems:

sudo apt-get install xdotool


sudo yum install xdotool

Arch linux:

sudo pacman -S xdotool

Simulating mouse movements and clicks

Left click

xdotool click 1

Right click

xdotool click 2

Mouse move

xdotool XXX YYY (XXX,YYY Being the coordinates)

A basic example where this can be used is a online dogeminer click game.

#Simple Auto clicker
while [ 1 ];do
  xdotool mousemove XXX YYY click 1
  sleep 5

How to send email in Python

We are going to be using the yagmail library to send a email using python.

To start of we will need to install the yagmail python library.
pip install yagmail

If you don't have pip installed you can install using the following commands depending on your OS.

Debian systems:
sudo apt-get install python-pip

sudo yum upgrade python-setuptools
sudo yum install python-pip python-wheel

Arch Linux:
sudo pacman -s python2-pip

sudo zypper install python-pip python-setuptools python-wheel

Now we will test that the library has been installed with a simple python script.

import yagmail

Run this script and if it produces no errors you are good to go.

Now we can get started sending emails.

First we need to import the necessary libraries(yagmail, time).
import yagmail
import time

Now lets setup the variables that are going to be sent in the email
subject = "Sent from Python at " + time.strftime("%D:%M:%Y")
message = "Hello, World!"
sender_email = "YOUR_EMAIL"
sender_password = "YOUR_PASSWORD"
recipient_email = "RECIPIENT_EMAIL"

Now lets send the email
yag = yagmail.SMTP(sender_email, sender_password)
yag.send(recipient_email, subject, message)

Putting all of that together we get:
import yagmail
import time

subject = "Sent from Python at " + time.strftime("%D:%M:%Y")
message = "Hello, World!"
sender_email = "YOUR_EMAIL"
sender_password = "YOUR_PASSWORD"
recipient_email = "RECIPIENT_EMAIL"

yag = yagmail.SMTP(sender_email, sender_password)
yag.send(recipient_email, subject, message)

If we run this script you should have a sent a email using less than 10 lines of python.

Link to yagmail GitHub

Friday, 1 July 2016

Python3:Lesson 3 If statments

If you are new to python you can check out my other lessons to get up to speed.
  1. Lesson 1
  2. Lesson 2
An If statement is used to decision in the program depending on different variables, it allows selection to take place.

First off lets get some input from the user that we can use in the if statement. I will do it in the context of test grades.
score = int(input("Please enter your score out of 100: "))

We now have the user score stored in the variable "score" as an integer.

Now lets look at the operators for a if statement.
  • == Is used for equal to.
  • <= Is used for less than or equal to.
  • >= Is used for greater than or equal to.
  • != Is used for not equal to.
  • and can be used for 2 comparisions.
We now need to create our if/elif statement.
if ( score >= 90 ):
elif ( score >= 80 and score < 90 ):
elif ( score >= 70 and score < 80 ):
elif ( score < 70 ):

Now if we run this code with the score as 85 it should print out a "B" to the screen.

Wednesday, 29 June 2016

How to install android studio

Android studio is a development environment for creating android apps.

To install it you first will need to download it from here. After you have downloaded it you will have a file called something like "". You need to unzip this file to be able to use it.

To do this run:

You should now have a directory that looks something like this:
You now need to enter the "bin" folder and run the script  "". If you are unsure how to run the script:
Now complete the setup following the instructions it gives you, once you are done close the program down, we can now start installing the program.
Do this after you have completed all of the other steps as you will have to reconfigure it so it will waste your time otherwise.

Steps to install:
  1. Locate where your android studio bin folder is located.
  2. Add this to your PATH variable.
  3. Rename to studio.
Step 1:
First you need to cd to the unzipped android studio folder as shown in the picture earlier on. You then need to cd to the bin folder. You can now rename to studio.
mv studio

You can now run the pwd command to get the full location of your directory.

You can now see that the directory is located at "/home/matty/Downloads/android-studio/bin"

We now need to add this path to your PATH variable. We do this so that you can type studio and open up the android studio from the terminal.


Note: YOUR PATH TO THE DIRECTORY is what we have just got from the pwd command, this should be added without the quotes for the above command.

You should now be able to type "android" into your terminal and it will open the android studio.

Are you vulnerable to the bash bug?

The Bash bug or shell shock as it is also known, is a bug in the bash shell. It allows code to be remotely executed on your server. This could lead to malicious code being installed to your server and it no longer being your server.(CVE-2014-6271)

How to test if you are vulnerable:
First you will need to open a terminal on your server/PC.
You now need to enter this command:
env x='() { :;}; echo this text should not be seen' bash -c 'echo This text should be seen'
If you get the message "this text should not be seen" then you are vulnerable.

How to patch this vulnerability:
To patch this vulnerability we need to update bash.
This is a simple task that can be solved in a few commands.

Debian systems patch:
Run these commands.
sudo apt-get update
sudo apt-get install bash

Fedora systems patch:
Run these commands.  
sudo yum update -y bash

You have now updated your bash shell and will no longer be vulnerable.

Sunday, 26 June 2016

Python 3: Lesson 2 Basics

This lesson will include:
  • Input
  • Output
  • Storing values in variables
  • A combination of the above.
Variables are used to hold data within the program. In python you do not need to assign it to a certain data type as this is done automatically.
Example Use:
a = 5                 #This would be defined as an integer
b = "Hello, World"    #This would be defined as a string
c = 5.000             #This would be defined as a float

To allow the users to input data into the program we use the input() function. Most of the time this will be paired up with assigning it to a variable to store the data.
Example Use:

name = input("Please enter your name: ")

The "Please enter your name: " is the prompt that tells the user what the program is asking for.

To allow the program to output data from the program.
Example Use:

print("Hello, World!")
print(name) In this case the contents of the variable "name" will be printed to the screen

Combination of all three
We will now create a program that uses variables input and output.
First off we will get the user to input some data.

name = input("Please enter your name: ")
age = input("How old are you?: ")

We have now got two things from them, their name(stored in the variable "name") and their age(stored in the variable "age").

We can now print this variables out with a print statement.
print("Hello",name,"you are",age, "years old")

You now have a program that will ask the user their name and age and print out the output of both of these in a sentence.

Saturday, 25 June 2016

Python3: Lesson 1 Installing Python

Python is a high level interpreted programming language. It's user friendly code allows anyone to start learning it at home.

Installing Python
Most Linux distributions come with python installed out of the box. Open up a terminal and type python3 to check. If you don't get any errors then you are ready to go.

Installing on Debian systems:
sudo apt-get install python3

Installing from source:
wget --no-check-certificate
tar xvf Python-3.4.3.tgz
cd Python-3.4.3
sudo make install

Now when you type the command python3 It should open up a python terminal.

Sunday, 10 April 2016

Ceaser cipher in Python

A Ceaser cipher is a basic encryption originating from the 1st century, invented by Julius Ceaser. It works by moving each letter a fixed position down or up the alphabet.
Here it is better explained by a diagram:

Now for the code in python 2.7, Firstly we will create a function for encoding so open a new file:
def encode(text)

Create an array to hold the new characters:
new_text = []

Now we need to loop through each character in the input text the user will give us:
for char in text:

ord converts a character to its numbered value in ascii.
In this case we will shift all the letters by 3 forward in the ascii table however you can use whatever number you want as long as it lower than 127:
char = ord(char) + 3

To make sure that we stay in the range of ASCII values we need to implement an if statement
if(char > 127):
    char = char - 127

Now to convert the value back to a character:
char = chr(char)

Then add this character to the array:

We have reached the end of this function and now have to return the array to the program:
return new_array

You should now have your first function, which put together look like this:
def encode(text):
        new_text = []
        for char in text:
                char = ord(char) + 3
                if(char > 127):
                        char = char - 127
                char = chr(char)
        return new_text

The decode function works the same you just need to the opposite to decode instead of encode. I have made the changes in bold below.
def decode(text):
        new_text = []
        for char in text:
                char = ord(char) - 3
                if(char < 0):
                        char = char + 127
                char = chr(char)
        return new_text

We now need to allow the user to input some text and decide to encode or decode.
This can be done with a simple while loop and if/elif statment:

choice = 0
while choice != 3:
        choice = raw_input("1:Encode, 2:Decode, 3:Exit ")
        if(choice == "1"):
                user_input = raw_input("Enter a word: ")
                new_text = encode(user_input)
                print ''.join(new_text)
        elif(choice == "2"):
                user_input = raw_input("Enter a word: ")
                new_text = decode(user_input)
                print ''.join(new_text) 
        elif(choice == "3"):
                print "Goodbye"
                print "Please enter a correct choice"

Now lets see if it works

Checking the encoding works:
Choose 1 for encode then enter "hello, world" it should give the output of "khoor/#zruog"

Checking the decoding works:
Choose 2 for decode then enter "khoor/#zruog" it should give the output of "hello, world"

Sunday, 21 February 2016

How to fix the "Firefox already running" problem on Linux

After creating a script which included closing a firefox tab and hiding the window I realised I could not open firefox and just got a "Firefox is already running" error every time after running this script once.

I tried running the command
sudo killall firefox
As there may have been some hidden windows however this didn't work.

Then I tried reinstalling firefox
sudo apt-get install --reinstall firefox
This didn't seem to work either.

Note this command will remove all personal data from firefox, run at your own risk.

After some research I found this
sudo rm -fr /home/"USERNAME"/.mozilla
This worked and I could open firefox again however I don't believe its the best way of solving this problem.

I'm open to any better ways so post in the comments if you have any.