torstai 10. joulukuuta 2015

Shellscripting like a boss

It is good idea to put all your shell script commands in a directory and export it to the path. In order to do this open up your .bashrc file of .profile

nano ~/.bashrc

Add this line to it 

export PATH=$PATH:~/scripts

It means in your home folder there should be a folder named scripts. Like /home/username/scripts.

Then reload your bashrc file 

source ~/.bashrc

And now you are ready for scripting. Add new file named hello to the script folder. 

Add this

#!/bin/bash 
echo My first program

Then in any directory type hello and your script executes.

Adding parameters to script:

#!/bin/bash

function echoshit() {
    echo "No parameter found or wrong parameter"
}

if [[ $1 == --trolli ]];
then
  echo "trolli echoed"
else
  echoshit;
fi


Read more: http://www.bashguru.com/2009/11/how-to-pass-arguments-to-shell-script.html

keskiviikko 21. lokakuuta 2015

Hacking with Kali Linux

I was curious about hacking things and the so called "dark side of the internet" so I installed Kali linux to my virtualbox and checked out few things.

Finding website admin panel with dictionary scan


So first thing I wanted to check is how you can find admin panels. In every content management systems (CMS) there must be admin panel to login and maintain it. So I found perl script that scans target site with different admin panel names. Unfortunately this is so called dictionary attack and if the name doesnt happen to be in the list, it wont find anything.

Open up your Kali linux and download this file: http://www.2shared.com/complete/R1eEFhs3/def_adminfinder.html

CD to your download folder and just run:

perl def_adminfinder.pl 

and it will launch. Then the script will ask the target site, type your site and enter.


Then we can see the script checking possible admin panel locations.


You have to wait for the script to finish to see the results unless you can spot status: found from the output stream. This is very simple tool to find admin panel, but it is a weak dictionary tool. This is not even hacking, cracking what so ever. I would say it is a tool.

How to generate a password list


When hacker is bruteforcing in to a system, it basically means to try every possible combination of numbers, letters and special marks that are defined. For that we need to create a list of those words. Linux can generate these files with a tool called crunch. 

type in: crunch 4 4 123456 > passwords.lst

The first number means how long the password should be atleast (minimum). Second number is how long it should (maximum) and then I have defined combinations with numbers 123456 and put them to a file called passwords.lst. Now this command will create every single possible combination of 123456 length of four. 





As you can see we have different combinations in a list. Try next crunch 2 2 abcd > passwords2.lst
to explore how this works.


Then we have all the combinations with abcd length minimum and maximum 2

Crunch is a tool to create password lists for bruteforce attacks which can take very long time. You can also download most used password lists by googling a little bit.

Password attack with Hydra to basic authentication


Now if you have website which has basic authentication you could create a massive list of words and then "bruteforce" yourself in to that site. Other way is to download ready made password list to speed up things a little bit, you can find some here: https://github.com/danielmiessler/SecLists/tree/master/Passwords

Basic authentication box will look like this:



Give command:

hydra -L accounts.txt -P passwords.txt http://www.yoursite.com

-L gives account list as parameter and -P option gives the password list. Then hydra will try every combination with the words in the lists. 


And the account + password combination in my list matched. I have successfully logged in.


SQLmap injection tool

if PHP page url looks like this: page.php?id=1 you can try if the page is vulnerable to sql attacks by adding ' to the end of url like www.yourpage.com/page.php?id=1'

If the answer you get is: "You have error in your sql syntax" the page is vulnerable to attacks. 

Simple command to find out databases is: sqlmap -u www.yoursite.com --dbs 
This will try different sql injections and list all the databases available.  


And as you can see, I found vulnerable website. Now I know their technology and what databases they have. This is just short demonstration what you can do with this tool.

To continue checking what is inside this table use command:

sqlmap -u www.yoursite.com/ -D information_schema --tables

This will check what is inside information_schema table.

Scanning email addresses with harvester

If you want to do email scan using search engines there is a tool called "theharvester". Fire up your Kali Linux and type theharvester to get information about the app.

You can scan emails with command theharvester -d www.nikiahlskog.com -l 50 -b all

From the information we can find that -d is the url we are searching. -l is the amount of results we look and -b is the search engine if I understood this correctly. After scannin my own site I have found 3 email addresses, but none of them is real. 





Using Hydra to hack login form


To attack login form you need: passwordlist and usernames list. User command:

hydra -L usernames.txt -P passwords.txt testsite.com http-get-form "/index.php:admin_username=^USER^&passwordfield=^PASS^:Denied"

-L is the usernamelist, -P is password list. http-get gets the right page, then comes the username field we try to hack, then password field and after : we put a word that hydra will be looking if the login is denid. 

Cracking Wlan passwords with reaver

Will continue this later probably...

airmon-ng start/check/stop
airodump-ng wlan0mon
wash -i wlan0mon -C
reaver -i wlan0mon -b BSSID --fail-wait=360

airodump-ng -bssid -c 6 --write/root/Desktop/crack-wpa wlan0mon

Free VPN with vpnbook and openvpn, how to use with Linux

VPN the tool for everyone who wants to be anonymous on the internet! I am happy that there is a place called http://www.vpnbook.com/ which is 100% free.

Start by surfing to http://www.vpnbook.com/freevpn and download for example  Euro1 OpenVPN Certificate Bundle to your Linux computer. It will be a zip file, so extract it somewhere in your system.

Next install openvpn client. sudo apt-get update && sudo apt-get install openvpn 

This will update your repositories and install openvpn client. Then CD to the folder where you have extracted the certificate bundle. To start VPN use command:

sudo openvpn --config vpnbook-euro1-tcp443.ovpn for example. It will ask username and password which you can find here: http://www.vpnbook.com/freevpn

Then just type in the credentials and wait few seconds. After that try geolocation finder and you can see your IP and country has changed! Notice that the command needs to be run with sudo in order to work.


You need to leave terminal open as long as you want to run the VPN. To close connection hit
CTRL + C

I am originally from finland, but after VPN tunnel my location is:


Also notice that the certifications and passwords may change occasionally, so always keep them updated.

Backup your home server to usb hdd

I needed to take backup of my server and wanted to take whole disk. I found this useful tool called dd packed out of the box in linux debian server.

Check which one you want to put in image file: sudo fdisk -l


Here we can see that I have /dev/sda as my main partition. Then to backup it on usb HDD find where your usb device is located. Usually it is under /media

Then just give simple DD command:

sudo dd if=/dev/sda of=/media/usb0/backup.img

This will create .img file as big as your hard drive is, so for example my dev/sda is 120gb so it will create 120gb .img file. So make sure your usb hdd has enough free disk space.

Second thing to note is that the program will run as long as it takes, for example 160gb hdd backup took 80 minutes for me. You need to leave the terminal open for that time. You can monitor the progress by checking the file size with: ls -l /media/usb0/ and spamming that command you can see how big the file is. There is no verbose option as far as I know.

tiistai 9. kesäkuuta 2015

Testlink for testcase management

To get TestLink to work, do virtualhost file which allows override.

<VirtualHost *:8010>

        ServerAdmin Niki
        ServerName testlink
        ServerAlias testlink
        DocumentRoot /home/shnigi/public_html/testlink/

        <Directory /home/shnigi/public_html/testlink/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Order allow,deny
                Allow from all
        </Directory>

</VirtualHost>

maanantai 8. kesäkuuta 2015

Frontend stuff Node.js, NPM, Bower & Gulp

NodeJS


On the latest version of Ubuntu, you can simply:

sudo apt-get install nodejs nodejs-dev npm which will install nodejs and npm to your computer.

Create new folder to play with. CD to that folder

Create file named: "hello_node.js"

insert:

// hello_node.js
var http = require('http');
http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello Node.js\n');
}).listen(8124, "127.0.0.1");
console.log('Server running at http://127.0.0.1:8124/');

Run the command by typing node hello_node.js in your terminal and leave it open.

Now, if you navigate to http://127.0.0.1:8124/ in your browser, you should see the helloworld message.


Bower init & NPM init


Install bower and gulp globally with command:

npm install -g bower
npm install -g gulp

Now we have bower and gulp globally installed. Make a new folder for your project and go in to that folder. Then do

npm init

Which will launch generator for package.json. When you have set all stuff correctly accept it. Now you can use

npm install command which will install all the required modules. To get more modules do

npm install bower --save-dev which will install bower to your project and --save-dev will put bower to package.json file as dev dependency. You can also use bare --save which will then appear as dependency. 

After you have install bower, run command bower init which will trigger bower.json file to be created. Now you can install bower components by running command bower install bootstrap --save which will install bootstrap under bower components folder. 


Flags --save means that the module is a dependecy for your project. Without that, it can't work. Or may work but not correctly. Setting flag --save-dev means that the module is critical for developer but not necessary in production version.



Gulp


Gulp is meant to automate and enhance you workflow. You can basically set tasks for gulp and it will do all the things for you automatically. First add some dev dependencies for our project.

$ npm install gulp-ruby-sass gulp-autoprefixer gulp-minify-css gulp-jshint gulp-concat gulp-uglify gulp-imagemin gulp-notify gulp-rename gulp-livereload gulp-cache del --save-dev

Then create empty file named gulpfile.js

And now for the lazy part. Head over here to read about the gulpfile. Very well explained: http://www.sitepoint.com/introduction-gulp-js/

torstai 7. toukokuuta 2015

SSH Git-repository

On ssh-server install git:

$ sudo apt-get install git
Create empty folder for git:
$mkdir gitkansio && cd gitkansio
Initialize git repository
$git --bare init

On local machine:

Create Git folder with Git:
$mkdir gittest && cd gittest
$sudo apt-get install git
$git init
Create some files
$ echo "lol" >> test.txt
Commit to Git
$git add .
$git commit -m "testing git"
Add remote repository
$git remote add origin ssh://username@server.com:1234/home/user/gitkansio
Push to remote
$git push origin master
$ git branch --set-upstream master origin/master

Clone the repository:
$ git clone ssh://gitmies@www.nikiahlskog.com:4242/home/gitmies/gitkansio

to remove: $ git remote rm origin

Check remotes with command: git remote -v 
Set new remote: git remote set-url origin ssh://gitman@365rent.fi:2222/home/gitman/365rentrepo