Tuesday, April 17, 2012

Hosting Operating Systems

A simple and easy way to host an operating system is using virtualbox. Its a program that lets you host Windows/Linux over Windows/Linux. Basically it supports more OS but i have used only these.

Host -> Ubuntu

How to Install Guest Applications

Here you basically using Ubuntu and via virtualbox you have installed Windows. You can install some app (lets you see in full screen) by going to your virtual windows window and click on Devices(at the top) / Install Guest Applications. It will mount a disk there and you only have ti accept and install this. Reboot your system and you can see a full screen window.

Host -> Windows


How to Install Guest Applications

Sunday, April 8, 2012

OSI model

Basics about OSI model

Osi model is the current model that almost every PC uses to connect to the internet(another computer). It consists of 7 layers which are shown in the image below


  • The layer closer to the user is the first one at the top(Application layer). For example user can open an application like firefox or outlook etc. These applications are included in Application layer or (layer 7 in the OSI model).
  • After this we go to the Presentation layer whre basically we have our operating system. Everything that our operating system does for a connection in the internet its all done here.
  • In the Session layer according to the OSI model a session bettween our computer and server is created. Imagine a client and a server making a socket.
  • In the next layer named Transport layer its all about windowing. Information and packets sending to server etc.
  • In the Network layer there is everything our router do. Everything about our IP etc.
  • In the Data link layer there is our MAC address and maybe a switcher if we have) :)
  • Finally, in the physical layer there are all the parts we use to connect physically to the internet. This includes wiring router(as a device) etc.



















                                                                                                                  (image from wikipedia)


Further Connections

Rememeber that if for exemple you want to connect two computers in the same network(eg. les say in your home) you dont care about MAC address or router's address. You only need the IPv4 address of the two computers. The connection can established via SSH access, FTP or something else. It's on you! If you want to transfer files(eg. 4GB) and you dont have a good connection then its crap. This method dont work very well and its bery slow! On the other hand you can use a crosssover cable to transfer your data. Search in your local electronics shop for "crossover cable".

Change your DNS(local)

It's good sometimes to change your DNS hosts file so "noone" can go in AND out from your PC. What i mean is, when some bad guy wants to hack your PC and send info back to him. Well, this is not gonna happen if you hack your PC too with the following things. In Linux hosts file is located in /etc/hosts. So try open a terminal and cd to /etc. Then open with an editor, for example vim the file "hosts". Remember you need sudo password. You will see some addresses basically the loopback 127.0.0.1. You can add and edit this file with everything you want according to the following: DO NOT DELETE ANYTHING. Just add :)


<ip_address> <website>


for example you can write: 195.130.121.44 www.facebook.com. This part says everytime you write in your browser "www.facebook.com" it goes STRAIGHT to the address without looking anywhere else.


What we will do here is placing some website where we mostly go giving the loopback address. For example you can write:


127.0.0.1 www.facebook.com
127.0.0.1 www.google.gr
127.0.0.1 www.google.com
127.0.0.1 blah blah...


That was an easy way to protect a little more yourself!


Have fun :)

Collecting IP Addresses

With the following command you can output your Ipv4 protocol address(Linux-FreeBSD-Sunos):

#!/bin/sh
# Shell script scripts to read ip address
# -------------------------------------------------------------------------
# Copyright (c) 2005 nixCraft project <http://cyberciti.biz/fb/>
# This script is licensed under GNU GPL version 2.0 or above
# -------------------------------------------------------------------------
# This script is part of nixCraft shell script collection (NSSC)
# Visit http://bash.cyberciti.biz/ for more information.
# -------------------------------------------------------------------------
# Get OS name
OS=`uname`
IO="" # store IP
case $OS in
Linux) IP=`ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'`;;
FreeBSD|OpenBSD) IP=`ifconfig | grep -E 'inet.[0-9]' | grep -v '127.0.0.1' | awk '{ print $2}'` ;;
SunOS) IP=`ifconfig -a | grep inet | grep -v '127.0.0.1' | awk '{ print $2} '` ;;
*) IP="Unknown";;
esac
echo "$IP"

Saturday, April 7, 2012

Terminal Commands

System

  • uname -a            -- print system information
  • cat /etc/issue      -– current distribution and version
  • lsb_release -a      -– prints version information for the Linux release
  • date                -– shows the date
  • cal                 -– calculator 
  • fsck                -– File System Check

    Hardware

    • lshw                -- list hardware
    • lspci               -- list all PCI devices 
    • lspci | grep VGA    –- specific graphics card model 
    • hwinfo              -- short overview of all hardware & more detailed info 
    • lsusb               -- USB buses and attached devices

    Processor

    • cat /proc/cpuinfo   -– all processors, clock speeds, flags...
    • cat /proc/loadavg   –- processor load average for the last 1, 5, and 15 min 
    • top                 –- display Linux tasks 
    • uptime              –- current time elapsed since last reboot, users, and load average

      Memory

      • df -h               –- report file system disk space
      • du -sh <path>       –- estimate file space usage
      • cat /proc/meminfo   –- amount of RAM and swap, and how much is being used for what
      • free -m             –- total, used, and free memory shown in MB 
      • df -H               –- partitions, as well as their mount-points and usage in GB

        Drivers & Format

        • sudo fdisk -l       –- all partitions, their device names, and positions on disk

         
        * mount - Mount a Drive
        * umount - Unmount Drive
        * fdisk - Format Disk
        * dd - Dupliate Disk
        * df - Disk Free Space

        Networking

        • ifconfig            –- configure a network interface
        • iwconfig            –- configure a wireless network interface
        • ip addr             –- show / manipulate routing, devices, policy routing and tunnels
        • w                   –- output all currently logged in users and what they’re doing
        chkconfig - Check Activated Services
        * ping - Test Network Connections
        * ftp - file Transfer Protocol
        * host - Check IP of Domain
        * ifconfig - Configure Network Devices
        * netstat - Display Routing Table
        * route - Set Routes
        * telnet - Connect to telnet
        * traceroute - Display Route

        Packages

        • apt-get install/remove          –- install or remove a package
        • aptitude search <packagename>   –-search for a package similar to packagename
        • apt-cache showpkg <packagename> –- packagename’s version and dependencies


            Managing files

            • cp <file> <dest>    –- Copy
            • ls                  –- List
            • mkdir <foldername>  –- Make Directory 
            • mv                  –- Move
            • rm                  –- Remove
            • grep                –- Search for Text Strings
            • head                –- Display Start of File
            • less                –- Display Part of File
            • more                –- Display Part of File
            • tail                –- View the End of a File


            Users

            •  chgroup            –- change a user group

              chmod - Change Mode
              * su - Switch User

            passwd - Create Password
            * groupadd - Add a Group
            * groupmod - Modify a Group
            * chgrp - Change Group
            * groupdel - Delete Group
             

            Other

            • awk                 –- pattern scanning and processing language
            • alias               –- declare symbolic aliases for perl data
            • lshal -m            –- monitor for hardware changes

            Tips

            • sudo lshw -html > your-file-name.html
            • man everything :)

            file - typechecking of one or more ps - the ultimate system monitor for command line - also good for scripts
            * cat - print out a file in the command line

                Format your PC and start using Linux

                Below there is a list of nesessary programs need to be installed after a "fresh" format into Linux(eg. Ubuntu/Linux distribution).

                • Open Office (installed)
                • Libre Office (not installed)

                • Ssh (installed)
                • Xampp Server (not installed)
                • Filezilla (not installed)

                File permmissions

                You must keep in mind Linux is designed to be a multi-user environment. In an environment with more than one users(like Linux), it is crucial to have a secure system for deciding which files are yours and who can fiddle with them. So, file permissions are defined separately for users, groups, and others as following:

                User: The username of the person who owns the file. By default, the user who creates the file will become its owner.

                Group: The usergroup that owns the file. All users who belong into the group that owns the file will have the same access permissions to the file. This is useful if, for example, you have a project that requires a bunch of different users to be able to access certain files, while others can't. In that case, you'll add all the users into the same group, make sure the required files are owned by that group, and set the file's group permissions accordingly.

                Other: A user who isn't the owner of the file and doesn't belong in the same group the file does. In other words, if you set a permission for the "other" category, it will affect everyone else by default. For this reason, people often talk about setting the "world" permission bit when they mean setting the permissions for "other."

                That was the categories where you set permissions. The following are THE permissions and they are defined separately for the file's owner, group and all other users.

                Read permission. On a regular file, the read permission bit means the file can be opened and read. On a directory, the read permission means you can list the contents of the directory.

                Write permission. On a regular file, this means you can modify the file, and write new data to the file. In the case of a directory, the write permission means you can add, remove, and rename files in the directory. This means that if a file has the write permission bit, you are allowed to modify the file's contents, but you're allowed to rename or delete the file only if the permissions of the file's directory allow you to do so.

                Execute permission. In the case of a regular file, this means you can execute the file as a program or a shell script. On a directory, the execute permission (also called the "search bit") allows you to access files in the directory and enter it, with the cd command, for example. However, note that although the execute bit lets you enter the directory, you're not allowed to list its contents, unless you also have the read permissions to that directory.

                You can view the access permissions of a file by doing the long directory listing with the ls -l command.

                $ ls -l 
                The first character can be any of these(type of file):
                d = directory
                - = regular file
                l = symbolic link
                s = Unix domain socket
                p = named pipe
                c = character device file
                b = block device file

                For each file you can add the following:
                r = read permission
                w = write permission
                x = execute permission
                - = no permission

                Friday, April 6, 2012

                Ubuntu/Linux filesystem

                Ubuntu (like all UNIX-like systems) organizes files in a hierarchical tree, where relationships are thought of in teams of children and parent. Directories can contain other directories as well. Also, in every directory, there are two special directories called . and .., which refer respectively to the directory itself, and to its parent directory.

                /bin is a place for most commonly used terminal commands, like ls, mount, rm, etc.
                /boot contains files needed to start up the system, including the Linux kernel, a RAM disk image and bootloader configuration files.
                /dev contains all device files, which are not regular files but instead refer to various hardware devices on the system, including hard drives.
                /etc contains system-global configuration files, which affect the system's behavior for all users.
                /home home sweet home, this is the place for users' home directories.
                /lib contains very important dynamic libraries and kernel modules
                /media is intended as a mount point for external devices, such as hard drives or removable media (floppies, CDs, DVDs).
                /mnt is also a place for mount points, but dedicated specifically to "temporarily mounted" devices, such as network filesystems.
                /opt can be used to store addition software for your system, which is not handled by the package manager.
                /proc is a virtual filesystem that provides a mechanism for kernel to send information to processes.
                /root is the superuser's home directory, not in /home/ to allow for booting the system even if /home is not available.
                /sbin contains important administrative commands that should generally only be employed by the superuser.
                /srv can contain data directories of services such as HTTP (/srv/www/) or FTP.
                /sys is a virtual filesystem that can be accessed to set or obtain information about the kernel's view of the system.
                /tmp is a place for temporary files used by applications.
                /usr contains the majority of user utilities and applications, and partly replicates the root directory structure, containing for instance, among others, /usr/bin/ and /usr/lib.
                /var is dedicated variable data that potentially changes rapidly; a notable directory it contains is /var/log where system log files are kept.

                The root partition / must always physically contain /etc, /bin, /sbin, /lib and /dev, otherwise you won't be able to boot. Typically 150–250MB is needed for the root partition. 



                What about the others directories shown above? Read...
                /usr: contains all user programs (/usr/bin), libraries (/usr/lib), documentation (/usr/share/doc), etc. This is the part of the file system that generally takes up most space. You should provide at least 500MB of disk space. This amount should be increased depending on the number and type of packages you plan to install. A standard Ubuntu desktop requires a minimum of 1.5GB here. A generous workstation or server installation should allow 4–6GB.
                /var: variable data like news articles, e-mails, web sites, databases, the packaging system cache, etc. will be placed under this directory. The size of this directory depends greatly on the usage of your system, but for most people will be dictated by the package management tool's overhead. If you are going to do a full installation of just about everything Ubuntu has to offer, all in one session, setting aside 2 or 3 GB of space for /var should be sufficient. If you are going to install in pieces (that is to say, install services and utilities, followed by text stuff, then X, ...), you can get away with 300–500 MB. If hard drive space is at a premium and you don't plan on doing major system updates, you can get by with as little as 30 or 40 MB.
                /tmp: temporary data created by programs will most likely go in this directory. 40–100MB should usually be enough. Some applications — including archive manipulators, CD/DVD authoring tools, and multimedia software — may use/tmp to temporarily store image files. If you plan to use such applications, you should adjust the space available in /tmpaccordingly.
                /home: every user will put his personal data into a subdirectory of this directory. Its size depends on how many users will be using the system and what files are to be stored in their directories. Depending on your planned usage you should reserve about 100MB for each user, but adapt this value to your needs. Reserve a lot more space if you plan to save a lot of multimedia files (pictures, MP3, movies) in your home directory.



                based on ubuntu wiki

                Make a Simple Webpage

                Someday you may want to program a simple webpage. Not something awesome but a simple HTML and maybe CSS code whre you can tell readers some information, status etc. Its very easy to do this.


                Below you will see some HTML code where you can write anything. Google "HTML tutorial" to learn more. An HTML page can be shown in any browser though CSS make it beautifull! For example if you have a personal webpage you can add some CSS code and make things better. Let' s start! :)


                Organise your files
                An important thing is to always organise your files else you' ll get lost. That' s sure! So for the sake of this simple tutorial let's make a folder named "mysite" and two files named "index.html", "mystyle.css" (inside the folder). Remember the file "mystyle.css" is optional as you don't need necessary to have any CSS code. It always depends of you.


                HTML Programming
                So, the second thing we will do is add some code in the "index.html" file. This is the file which you will later see in your browser. HTML is quite easy language to learn and i can say quite funny too. Copy & paste the code bellow and i will explain this.


                index.html

                <html>
                <head>
                {!-- Place you meta tags here --}
                {!-- Link you index.html(this file) with your CSS file(mystyle.css). Its placed into commends as its optional. --}
                {!-- <link rel="stylesheet" type="text/css" href="mystyle.css" /> --}


                {!-- You can add your local language adding the following code(only change the 'charset' to your local). Remove commends again if you want this. --}
                {!-- <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> --}
                </head>


                <body>
                {!-- You can place a title bellow --}
                <h2>News of the day...</h2>

                {!-- Your can place a paragraph bellow --}
                <p>You have been hacked! Remember hacking is just POWER...its up to you how to use it!</p>
                </body>
                </html>


                In HTML you always write tags (<tag> </tag>). This is the way you are coding :) Let' s see what we have here...every HTML page start with <html> </html> tag and it must have a head and a body tag too. Only the body tag is shown in browser so the head tag is used to link this file with your CSS(give the path so it can be found), to use your native language instead of the default, for google searches etc. I explain some things in the code above. In the body part there are many things you can white and as we see above we have an h2 tag which is a header level 2. There are 6 levels(try them)! After this there is a p tag which means paragraph. And this is how it ends. Its very simple code which makes a webpage(probably not useful for personal webpage) and if you google some things you will easily modify this to your own.


                CSS Programming
                CSS programming is a method so you can have a better, maybe more beautiful webpage. Coding in CSS is simple and easier! The idea is to make some identities in your HTML code and in the CSS file for each element(identities) specify some characteristics. eg. in body id(entity) you can say the following (body is the only tag that dont need # or .).


                mystyle.css

                body {
                background-color: black;
                font-size: 16px;
                font-color: green;
                }

                p {
                font-family: Arial;
                font-size: 14px;
                color: green;
                }

                So, finally you have many id's like, body, main_id, content_id, header_id etc and for each one you specify some beautiful things like above. The way you can add id's in your HTML code is again so simple.
                • id
                • class
                you can access 'id' in your CSS file adding befre the name a '#' and you can also access 'class' adding before the name a '.'.

                So let's see an example, in which i modify the body tag in my HTML code like this:
                <body>
                {!-- You can place a title bellow --}
                <h2 id="first_header">News of the day...</h2>

                {!-- Your can place a paragraph bellow --}
                <p>You have been hacked! Remember hacking is just POWER...its up to you how to use it!</p>
                </body>

                then you could have a CSS code like the following:

                mystyle.css
                body {
                background-color: black;
                font-size: 16px;
                font-color: green;
                }

                p {
                font-family: Arial;
                font-size: 14px;
                color: green;
                }

                #first_header {
                font-size: 22px;
                color: purple;
                }

                Hello World

                Hello world program writen in C language

                #include  

                int main(void) {
                printf("Hello world!\n");
                return 0;
                }