Tuesday, 6 August 2013

Google's Hacking Incidence

Google's is one of the most popular and high traffic web search engines that happen to be a victim of hacking last year when some mathematician attempted to hack Google's 256-bit SSL encryption key. The mathematican is said to have no malicious intent who instead contacted Google on its weakly encrypted system. Google is said to have admitted about the incidence but didn't notice it until the hacker notified them.

Java Native Interface


A programming interface where java programming language interacts with native programming languages such as C/C++. As a programmer I found it hard to resolve away to communicate with native languages especially C which java derives much of its syntax. The following sample code worked well with C and C++ on windows platform and may also work well on other platforms like UNIX.
I'll give first C sample code which you must have the compilers configured before doing any of these procedures.

Using C language;

First open your editor and save the code below in a java source file (.java extension), that is, "HelloWorld.java".

class HelloWorld {
private native void print();
public static void main(String[] args) {
new HelloWorld().print();
}
static {
System.loadLibrary("HelloWorld"); // loads HelloWorld.dll library file
}
}


then save the code below in a C source file (.c extension), that is, "HelloWorld.c".

#include <jni.h>
#include <stdio.h>
#include "HelloWorld.h"
JNIEXPORT void JNICALL
Java_HelloWorld_print(JNIEnv *env, jobject obj)
{
printf("Welcome to JNI using C!\n");
return;
}


Lastly you should have a batch script to execute your commands so save the following contents in "build.bat" file.

javac HelloWorld.java
javah HelloWorld
cl /I"C:\Program Files\Java\jdk1.7.0_01\include" /I"C:\Program Files\Java\jdk1.7.0_01\include\win32" /I"C:\Program Files\Microsoft Visual Studio\VC98\Include" /I"C:\Program Files\Microsoft Visual Studio\VC98\Lib" HelloWorld.c /Fe"HelloWorld.dll" /LD
java HelloWorld


You should have a similar output.



Using C++ language;
Open your text editor and save the following contents in a .java file, that is, "JNIPrintWrapper.java".


// File: JNIPrintWrapper.java
// Allows access to native methods

public class JNIPrintWrapper
{
    // load library JNIPrintLibrary into JVM
    static
    {
        System.loadLibrary( "JNIPrintWrapper" );
    }
    // native C++ method
    public native void printMessage( String message );
 }


save the following in a java source file, that is, "JNIPrintMain.java".

// File: JNIPrintMain.java
// Creates a new instance of the Java wrapper class,
// and calls the native methods.

public class JNIPrintMain{

// uses JNI to print a message
 public static void main( String args[] )
{
 JNIPrintWrapper wrapper = new JNIPrintWrapper();

 // call to native methods through JNIWrapper
 wrapper.printMessage( "Welcome to JNI using C++!\n" );
 }
}


save the following in a C++ source file, that is, "JNIPrintWrapperImpl.cpp".

// File: JNIPrintWrapperImpl.cpp
 // Implements the header created by Java
 // to integrate with JNI.

// C++ core header
 #include <iostream.h>

// header produced by javah
 #include "JNIPrintWrapper.h"

 // prints string provided by Java application
 JNIEXPORT void JNICALL Java_JNIPrintWrapper_printMessage
 ( JNIEnv * env, jobject thisObject, jstring message )
 {
 // boolean to determine if string is copied
 jboolean copied;

 // call JNI method to convert jstring to cstring
 const char* charMessage =
 env->GetStringUTFChars( message, &copied );

 // print message
 cout << charMessage;

// release string to prevent memory leak
env->ReleaseStringUTFChars( message, charMessage );
}



You should have a similar output as shown below.



Java Networking


Java is notably known to have good network capabilities that make the java programming world fun especially when it comes to communication. Here is a sample program code to show Client-Server and Server-Client communications using java networking capabilities.

Here is the Client source code.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.*;
import java.util.Scanner;

/*

 * A simple demonstration of setting up a Java network client.

 */

public class Client
{
    static Scanner scanner = new Scanner(System.in);
//    static ServerSocket server;
    static Socket sock;

    public static void main(String[] argv) {

        String server_name = "localhost";
        String client_msg = null;

        try {

            sock = new Socket(server_name, 14323);
            /* Finally, we can read and write on the socket. */           

            System.out.println(" *** Connecting to " +
                sock.getInetAddress().getHostName() + ":" +
                sock.getLocalPort()  + " ***\n");
            while(sock.isConnected())
            {
//                System.out.println(" *** Connected ***\n");
                System.out.print("Enter message:");
                client_msg = scanner.nextLine();
                //send message to server
                sendMessage(client_msg);
                // wait for server's message
               
                // display new message from server
                receiveMessage();
                // handle connections
                //                handle(sock);
            }
            /* . do the I/O here .. */
            if(!sock.isClosed())
            {
                sock.close( );
                System.out.println("\nSocket closed\n");
            }

        } catch (java.io.IOException e) {

            System.err.println("error connecting to " +

                server_name + ": " + e);

            return;
        }
    }

    protected static void sendMessage(String msg) throws IOException
    {
        if(msg == "" || msg == null)
            return; // exit method
        sock.getOutputStream().write(msg.getBytes());
        System.out.println("\nMessage sent.");
    }

    protected static void receiveMessage() throws IOException
    {
        String recvmsg = "";
        int size = 256;
        byte[] buff = new byte[size];
        sock.getInputStream().read(buff);
        for(int i = 0; i < buff.length; i++)
        {
            if(buff[i] != buff[255])
                recvmsg += (char)buff[i];
        }
        System.out.println("\nServer: " + recvmsg);
    }

}


Here is the Server source code.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

/**

 * Listen -- make a ServerSocket and wait for connections.

 */

public class Server {

    /** The TCP port for the service. */

    public static final short PORT = 14323;

    protected static ServerSocket sock;
    protected static Socket clientSock;
    protected static Scanner scanner;

    public static void main(String[] args) throws IOException
    {
        scanner = new Scanner(System.in);
        String servermsg;
        try {
            sock = new ServerSocket(PORT);

            System.out.println("\nListening on port " +
                    sock.getLocalPort());
                   
            // receive first message
            clientSock = sock.accept();
            while ((clientSock.isConnected()))
            {
//                System.out.println("Accepting from client " +
//                      clientSock.getInetAddress().getHostName() +
//                      ":" + clientSock.getLocalPort() + "\n");
                // wait for client's message first
               
                // display new client's message
                receiveMessage();
                // get server's message from standard input
                System.out.print("Enter message: ");
                servermsg = scanner.nextLine();
                // send server's message
                sendMessage(servermsg);               
               
            }
        }
        catch (IOException e)
        {
            System.err.println(e);
        }
        finally
        {
            sock.close();
            clientSock.close();
        }
    }  

    static void receiveMessage() throws IOException
    {
        int size = 256;
        byte[] recvbuff = new byte[size];
        clientSock.getInputStream().read(recvbuff);
        System.out.print("Client: ");
        for(int i = 0; i < recvbuff.length; i++)
        {
            if(recvbuff[i] != recvbuff[255])
                System.out.print("" + (char)recvbuff[i]);
        }
        System.out.println();
    }

    static void sendMessage(String msg) throws IOException
    {
        if(msg == "" || msg == null)
            return; // exit method
        int size = msg.getBytes().length;
        byte[] sendbuff = new byte[size];
        sendbuff = msg.getBytes();
        clientSock.getOutputStream().write(sendbuff);
        System.out.println("\nMessage sent.\n");
    }  

}



Here is the impressive output I heard you should have something similar on windows.




Qt 4 Software Development


Qt 4 is a C++ Application Framework that is mostly deployed in making of Graphical User Interface Software Applications e.g., VLC Media PLayer is a good example of Qt Software. First, I would want you to know how to configure windows environment for Qt Applications. Download latest Qt creator which may also be shipped together with Qt SDK but you should download latest Qt SDK and also MinGW compiler. Follow setup and install simply as you do with other software but after you install you must configure the environment before development.
  •  You will need an Internet connection to install MinGW compiler.
  • Before Qt installation you should have MinGW installed and MinGW\bin folder in your PATH.
  • After installation navigate to Qt\<sdk version> folder and look for "configure.exe" file.
  • Open that file and choose Open Source Edition where prompted to, that is, type "o" on the shell.
  • Accept license by typing 'yes' and wait for it to finish executing.
  • Make sure your Qt\<sdk version>\bin is in your PATH.
  • Note that you should download Qt SDK that supports MinGW compiler.
 A Hello World sample program is shown below.

#include <QApplication.h>
#include <QPushButton.h>

int main( int argc, char **argv )
{
QApplication a( argc, argv );
QPushButton hello( "Hello World!");
hello.show();
return a.exec();
}


Save the source code into a file "main.cpp".
Create a new file using your notepad or any text editor program and enter the following commands in it.

qmake -project
qmake
make
cd debug
qt

save it as batch script file, that is, "<file name>.bat" file should have a .bat extension.
Open your command line program or double click on the batch script to execute when on the command line drag the batch script file and drop it to the command line program and then press Enter to execute file. You should have an execution similar as below.



You should have some files created such as qt project file, Makefile file and other folders debug, release, etc in that folder that main.cpp file resides. The output should be similar to that below.




Note: You can navigate to the debug folder where you'll find an executable which when you open should give you a GUI window.
Download Available:  Click here

Tuesday, 23 July 2013

BIG DATA


 

A Technical term to explain Tremendous Volumes of Data stored that becomes complicated and sophisticated to visualize, share, search, analyze or transfer Data using Traditional Application means or even on-hand Database Management Applications but can only be handled be Extremely-fast Paralleled Software Applications running on many Massively High-speed Servers.Finally, Big Data somehow explains or theorizes the future of Internet and major firms that handle massive amounts of Information or Data daily.

Tuesday, 14 May 2013

GIS

GIS, Geographical Information System is an Integration of systems designed to capture/collect, store, manipulate, analyze, manage, and display all types of geographical data such as Geo-spatial data.
GeoJSON ;-
An open format for encoding a collection of geographic data structures and more compact data structure to store geographical co-ordinates, that is, Spatial data format types supported in GeoJSON include points, polygons, multi-polygons, features, geometry collections, and bounding boxes, which are stored along with feature information and attributes. It borrows format from JavaScript's JSON(JavaScript Object Notation).

PostGIS ; -
An open source software that adds support for geographic objects to the PostgreSQL database and just like GeoJSON, PostGIS follows the simple features for SQL specification from the Open Geospatial Consortium (OGC).

CartoDB ;-
A Geospatial database used to create data driven maps, or dynamic maps, analyze and build location aware and geospatial applications with your data using the power using the power of PostGIS.

Hacking

Hacker
A person who intents or seeks to intrude into the system without owner's consent through the network or system thus exploiting the weaknesses of the system or network. Hackers aim more at security breaches to infiltrate to owner's system or network and one of the most malicious types hackers are Black Hats, but contrasts the ethical hackers, that is, White Hats. They use sophisticated hack tools probably made by them or other people, or malicious software applications, e.g., Rootkit, Backdoor, Trojan horse, Virus, Worm, Spyware, Botnet, Keystroke logging, Antivirus software,Firewall, IDS(Intrusion Detection Systems).





 Classifications of hackers ; -
  • White hat
  • Black hat
  • Grey hat
  • Elite hacker
  • Script kiddie
  • Neophyte
  • Blue hat
  • Hacktivist
  • Nation state
  • Organized criminal gangs
  • Bots
Ways you can use to intrude into a system; -
  • SQL(Structured Query Language) injection. 
Hiding code snippets inside a page request to a web server, especially SQL commands which compromise the security of the website or server. Mostly, PHP or any other suitable scripting languages would be suitable to be deployed in such a scenario. This is mostly for any scripting languages that run on the web server using SQL such as PHP.
  • XSS(Cross-Site Scripting).
 This would be the accessing information of web pages using scripts that access the data(variables) exposed when the web page is running on the client-side. Mostly, Javascript language may be deployed for such a scenario because it runs best on client machines. This is mostly for Javascript Hackers.
  • Brute-Force Computing.
Mostly deployed any where you have software programming is involved especially the desktop software applications which involve very fast vigorous processes that may compromise data as well. This kind of computing may be very malicious when well-used on an attack of a system. Learned in advanced Computer science courses and examples of brute-force techniques are recursion and iteration.